Minor Changes
-
#1922
cb4c1c7Thanks @cjol! - Support both AI SDK v6 and v7.The
aipeer range isai@^6 || ^7(and@ai-sdk/reactis@^3 || ^4) across
agents,@cloudflare/ai-chat,@cloudflare/codemode, and@cloudflare/think.
Consumers can adopt AI SDK v7 or stay on v6 — no forced AI SDK upgrade when
bumping these packages.Only the current implementations are covered. New optimisations and APIs made
available by AI SDK v7 (broader result-shape audits, stream helper migrations,
etc.) are intentionally out of scope.How dual-version support works —
@cloudflare/thinkcalls the AI SDK through the
option names present in both majors (v7 keeps the v6 names as aliases), and
normalizes the genuine divergences at the boundary:-
Uses
stepCountIs,system,experimental_telemetry,onStepFinish, and
experimental_onToolCallFinish(in v7 this alias resolves to
onToolExecutionEndand fires once). -
The tool-execution-finished event is normalized across majors: v6's
{ success, output, error, durationMs, stepNumber }and v7's
{ toolOutput, toolExecutionMs }collapse to oneToolCallResultContext.
stepNumberisundefinedunder v7 (the v7 event no longer provides it). -
The UI message stream is built via the result's
toUIMessageStream()method
(present in both majors); the standalonetoUIMessageStream({ stream })
helper andresult.streamare v7-only. -
The workspace read tool emits
{ type: "file-data", data, mediaType, filename }
model output, accepted by both majors (v7's newer{ type: "file", data: { type: "data", data } }shape does not exist in v6).Public API notes:
-
@cloudflare/thinkkeepssystem,onStepFinish, andexperimental_telemetry
where callers already use them, and also acceptsTurnConfig.telemetry
(forwarded ahead ofexperimental_telemetrywhen present). -
@cloudflare/ai-chatupdates theAIChatAgent.onChatMessagecallback type
fromStreamTextOnFinishCallbacktoGenerateTextOnFinishCallback.Verified against both
ai@6andai@7:@cloudflare/thinktype-checks with
zero errors and its full workers test suite passes under each major.Known limitations:
-
workers-ai-provider(Think's default model provider) is fixed at v4 for AI
SDK v7. Consumers onai@6who rely on Think's built-in default model may hit
a provider-version mismatch; passing their ownLanguageModelavoids this. -
chat@4.31.0currently declares anai@^6peer and does not yet advertise
v7 support; tracked separately. -
CI should exercise both an
ai@6and anai@7resolution to guard the matrix.
-