feat: support both AI SDK v6 and v7 in Think and its dependencies#1940
Draft
cjol wants to merge 1 commit into
Draft
feat: support both AI SDK v6 and v7 in Think and its dependencies#1940cjol wants to merge 1 commit into
cjol wants to merge 1 commit into
Conversation
|
| Name | Type |
|---|---|
| agents | Minor |
| @cloudflare/ai-chat | Minor |
| @cloudflare/codemode | Minor |
| @cloudflare/think | Minor |
| @cloudflare/agent-think | Patch |
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
455de86 to
93144a0
Compare
Widen the "ai" peer range to "^6 || ^7" (and "@ai-sdk/react" to "^3 || ^4") across agents, @cloudflare/ai-chat, @cloudflare/codemode, and @cloudflare/think, so consumers can upgrade these packages without being forced onto AI SDK v7. Think now calls the AI SDK through the option names present in both majors (stepCountIs, system, experimental_telemetry, onStepFinish, experimental_onToolCallFinish) and normalizes the genuine divergences at the boundary: - normalizeToolFinishEvent collapses the v6 and v7 tool-execution-finished event shapes into one ToolCallResultContext. - The UI message stream uses the result's toUIMessageStream() method (present in both majors) instead of the v7-only standalone helper + result.stream. - The workspace read tool emits the "file-data" model output content part, which both majors accept (v7's newer "file" shape does not exist in v6). Also fix a v7-migration test regression: a test helper called getReader() on toUIMessageStream()'s result, which became a pure async iterable when readableStreamToAsyncIterable was introduced, masking the intended error and failing 17 error-handling tests. It now consumes the async iterator. Drop the v7-only telemetry test that froze telemetry.integrations behavior (v6 has no such API). Add an ai@6 / ai@7 CI matrix (.github/workflows/ai-sdk-compat.yml + scripts/use-ai-sdk-major.mjs) that type-checks and runs Think's workers tests under each major. Verified: 0 typecheck errors and full workers suite passing on both. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
93144a0 to
4c92b98
Compare
agents
@cloudflare/ai-chat
@cloudflare/codemode
create-think
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
Do not merge until cloudflare/ai#601 (
workers-ai-providerAI SDK v7 support) is released.agent-thinkdepends on apkg.pr.newpreview build ofworkers-ai-provider(inherited from the base branchfix/jul9-ai-sdk-v7). Thepkg.pr.newURL must be replaced with the publishedworkers-ai-providerrelease before this reachesmain.This PR makes
@cloudflare/think,agents,@cloudflare/ai-chat, and@cloudflare/codemodesupport both AI SDK v6 and v7, rather than the v7-only cutover in #1922. It stacks on #1922 (base branchfix/jul9-ai-sdk-v7) and is offered as an alternative: take #1922 for a clean v7-only move, or this PR to keep v6 working too.Why
aiand@ai-sdk/*majors in lockstep.@cloudflare/ai-chatand@cloudflare/thinkdeclareaias a required peer, so on npm 7+ a consumer staying on v6 hits anERESOLVEinstall failure, not a warning.system,stepCountIs,experimental_telemetry,onStepFinish,experimental_onToolCallFinish), so calling the SDK through the shared names lets one code path serve both majors without a compile-time fork..d.tsis compiled against one major; consumers get correct types for whicheveraithey install, and the runtime is correct for both.Public API Surface
aipeer range^7.0.0to^6.0.0 || ^7.0.0onagents,@cloudflare/ai-chat,@cloudflare/codemode,@cloudflare/think. Additive: v7 consumers unaffected.@ai-sdk/reactpeer range^4.0.0to^3.0.0 || ^4.0.0onagents,@cloudflare/ai-chat,@cloudflare/think.No exported symbols are added or removed. The change is to peer acceptance ranges only.
Code Changes
@cloudflare/thinkcallsstreamTextthrough the names present in both majors:system,stepCountIs,experimental_telemetry,onStepFinish, andexperimental_onToolCallFinish. In v7 the last resolves internally toonToolExecutionEndand fires once, so there is no double dispatch.normalizeToolFinishEventcollapses the two tool-execution-finished event shapes ({ success, output, error, durationMs, stepNumber }in v6,{ toolOutput, toolExecutionMs }in v7) into oneToolCallResultContextsoafterToolCalland extensions are version-agnostic.toUIMessageStream()method, which exists in both majors. The standalonetoUIMessageStream({ stream })helper andresult.streamare v7-only.file-datamodel-output content part, accepted by both majors. v7's newer{ type: "file", data: { type: "data", data } }shape does not exist in v6..getReader()ontoUIMessageStream()'s result, which became a pure async iterable whenreadableStreamToAsyncIterablewas introduced in the v7 migration. The resulting throw masked the intended error and failed 17 error-handling tests. It now consumes the async iterator.telemetry.integrationscallback API, which does not exist in v6, to avoid freezing v7-only behaviour..github/workflows/ai-sdk-compat.ymlandscripts/use-ai-sdk-major.mjs: a matrix that installs eachaimajor and runs@cloudflare/think's typecheck and workers tests under both.Compatibility
ai@6/@ai-sdk/*@3or move toai@7/@ai-sdk/*@4. Bumping these packages no longer forces an AI SDK major upgrade.workers-ai-provider(Think's default model provider) has no v7 release yet, so a consumer onai@6who relies on Think's built-in default model may hit a provider-version mismatch. Passing an explicitLanguageModelavoids this.agent-think(private, not published) uses theworkers-ai-providerv7 preview from Add support for AI SDK 7 ai#601 and must be repointed at the release before merge, per the warning above.