ai 6.0.296 → 6.0.298

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/index.d.mts +36 -5
  3. package/dist/index.d.ts +36 -5
  4. package/dist/index.js +187 -32
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +187 -32
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/internal/index.js +1 -1
  9. package/dist/internal/index.mjs +1 -1
  10. package/docs/04-ai-sdk-ui/02-chatbot.mdx +10 -1
  11. package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +8 -0
  12. package/docs/04-ai-sdk-ui/03-chatbot-resume-streams.mdx +10 -3
  13. package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +10 -1
  14. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +1 -1
  15. package/docs/07-reference/02-ai-sdk-ui/41-create-ui-message-stream-response.mdx +7 -0
  16. package/docs/07-reference/02-ai-sdk-ui/42-pipe-ui-message-stream-to-response.mdx +7 -0
  17. package/package.json +4 -4
  18. package/src/agent/create-agent-ui-stream-response.ts +3 -0
  19. package/src/agent/pipe-agent-ui-stream-to-response.ts +3 -0
  20. package/src/embed/embed-many.ts +5 -3
  21. package/src/generate-image/generate-image.ts +7 -2
  22. package/src/generate-text/stream-text-result.ts +5 -0
  23. package/src/generate-text/stream-text.ts +4 -1
  24. package/src/generate-video/generate-video.ts +6 -4
  25. package/src/registry/provider-registry.ts +1 -1
  26. package/src/ui/chat.ts +13 -4
  27. package/src/ui/http-chat-transport.ts +27 -1
  28. package/src/ui/last-assistant-message-is-complete-with-tool-calls.ts +15 -3
  29. package/src/ui/process-ui-message-stream.ts +51 -14
  30. package/src/ui/ui-messages.ts +14 -0
  31. package/src/ui/validate-ui-messages.ts +2 -0
  32. package/src/ui-message-stream/create-sse-stream-with-keep-alive.ts +89 -0
  33. package/src/ui-message-stream/create-ui-message-stream-response.ts +7 -1
  34. package/src/ui-message-stream/pipe-ui-message-stream-to-response.ts +7 -1
  35. package/src/ui-message-stream/ui-message-stream-response-init.ts +7 -0
  36. package/src/util/get-own.ts +18 -0
  37. package/src/util/set-own.ts +16 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.298
4
+
5
+ ### Patch Changes
6
+
7
+ - a9cea74: Keep default Node.js downloads protected by DNS validation and connection pinning when frameworks or instrumentation wrap global fetch before or after the SDK loads.
8
+ - Updated dependencies [a9cea74]
9
+ - Updated dependencies [a9cea74]
10
+ - Updated dependencies [a9cea74]
11
+ - @ai-sdk/provider-utils@4.0.57
12
+ - @ai-sdk/gateway@3.0.207
13
+
14
+ ## 6.0.297
15
+
16
+ ### Patch Changes
17
+
18
+ - 8349396: fix(ai): preserve hydrated partial static tool input across stream resumptions
19
+ - ab0b94b: fix(ai): keep idle UI message streams open with optional SSE heartbeats
20
+ - ce660b0: Clarify that provider-executed tool execution errors bypass the UI stream's `onError` callback to preserve provider error data. Stream errors and invalid tool calls still use the callback. Runtime behavior is unchanged.
21
+ - 850d4d5: Encode chat IDs in default stream reconnection URLs so slashes, query delimiters, and fragments stay within the ID. Reject standalone `.` and `..` IDs before fetching. Custom URLs returned by `prepareReconnectToStreamRequest` remain unchanged.
22
+ - cdc5b56: Preserve prototype-named tools, providers, and provider metadata as own properties without changing lookup object prototypes. Prevent inherited names from resolving as registered providers or causing image metadata aggregation to fail.
23
+ - d4203d2: Prevent automatic chat resumption when completed tool output is followed by terminal text without a completed stream state, while preserving resumption after completed model text.
24
+ - Updated dependencies [4972874]
25
+ - Updated dependencies [03e5a25]
26
+ - @ai-sdk/gateway@3.0.206
27
+
3
28
  ## 6.0.296
4
29
 
5
30
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1736,6 +1736,13 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1736
1736
  } & ({
1737
1737
  state: 'input-streaming';
1738
1738
  input?: DeepPartial<asUITool<TOOL>['input']> | undefined;
1739
+ /**
1740
+ * The raw tool input text received so far.
1741
+ *
1742
+ * This is used to continue input streaming when a message is persisted
1743
+ * and later resumed.
1744
+ */
1745
+ rawInput?: string;
1739
1746
  output?: never;
1740
1747
  errorText?: never;
1741
1748
  callProviderMetadata?: ProviderMetadata;
@@ -1846,6 +1853,13 @@ type DynamicToolUIPart = {
1846
1853
  } & ({
1847
1854
  state: 'input-streaming';
1848
1855
  input?: unknown;
1856
+ /**
1857
+ * The raw tool input text received so far.
1858
+ *
1859
+ * This is used to continue input streaming when a message is persisted
1860
+ * and later resumed.
1861
+ */
1862
+ rawInput?: string;
1849
1863
  output?: never;
1850
1864
  errorText?: never;
1851
1865
  callProviderMetadata?: ProviderMetadata;
@@ -2188,6 +2202,12 @@ type UIMessageStreamOnFinishCallback<UI_MESSAGE extends UIMessage> = (event: {
2188
2202
  * Extends the standard `ResponseInit` with additional streaming options.
2189
2203
  */
2190
2204
  type UIMessageStreamResponseInit = ResponseInit & {
2205
+ /**
2206
+ * Optional interval in milliseconds for sending SSE keep-alive comments.
2207
+ * When set, an opening comment is sent immediately and additional comments
2208
+ * are sent after the stream has been idle for the configured interval.
2209
+ */
2210
+ keepAliveMs?: number;
2191
2211
  /**
2192
2212
  * Optional callback to consume a copy of the SSE stream independently.
2193
2213
  * This is useful for logging, debugging, or processing the stream in parallel.
@@ -2255,6 +2275,11 @@ type UIMessageStreamOptions<UI_MESSAGE extends UIMessage> = {
2255
2275
  /**
2256
2276
  * Process an error, e.g. to log it. Default to `() => 'An error occurred.'`.
2257
2277
  *
2278
+ * Tool execution errors marked `providerExecuted: true` bypass this callback.
2279
+ * Their strings pass through unchanged; other values are JSON-stringified to
2280
+ * preserve provider error data for model-message round trips. Stream errors
2281
+ * and invalid tool calls still use it.
2282
+ *
2258
2283
  * @returns error message to include in the data stream.
2259
2284
  */
2260
2285
  onError?: (error: unknown) => string;
@@ -3573,11 +3598,12 @@ type InferAgentUIMessage<AGENT, MESSAGE_METADATA = unknown> = UIMessage<MESSAGE_
3573
3598
  * @param headers - Additional headers for the response. Optional.
3574
3599
  * @param status - The status code for the response. Optional.
3575
3600
  * @param statusText - The status text for the response. Optional.
3601
+ * @param keepAliveMs - Optional interval for sending SSE keep-alive comments.
3576
3602
  * @param consumeSseStream - Whether to consume the SSE stream. Optional.
3577
3603
  *
3578
3604
  * @returns The response object.
3579
3605
  */
3580
- declare function createAgentUIStreamResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ headers, status, statusText, consumeSseStream, ...options }: {
3606
+ declare function createAgentUIStreamResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ headers, status, statusText, keepAliveMs, consumeSseStream, ...options }: {
3581
3607
  agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
3582
3608
  uiMessages?: unknown[];
3583
3609
  abortSignal?: AbortSignal;
@@ -4120,7 +4146,9 @@ declare function lastAssistantMessageIsCompleteWithApprovalResponses({ messages,
4120
4146
  /**
4121
4147
  * Check if the last message is an assistant message with completed tool calls.
4122
4148
  * The last step of the message must have at least one tool invocation and
4123
- * all tool invocations must have a result.
4149
+ * all tool invocations must have a result. Completed model text may follow
4150
+ * the tool invocation because client-side tool results update parts in place,
4151
+ * but trailing text without a completed stream state prevents resubmission.
4124
4152
  */
4125
4153
  declare function lastAssistantMessageIsCompleteWithToolCalls({ messages, }: {
4126
4154
  messages: UIMessage[];
@@ -4303,11 +4331,12 @@ originalMessages, onStepFinish, onFinish, generateId, }: {
4303
4331
  * @param options.statusText - The HTTP status text for the response.
4304
4332
  * @param options.headers - Additional HTTP headers to include in the response.
4305
4333
  * @param options.stream - The UI message chunk stream to send.
4334
+ * @param options.keepAliveMs - Optional interval for sending SSE keep-alive comments.
4306
4335
  * @param options.consumeSseStream - Optional callback to consume a copy of the SSE stream independently.
4307
4336
  *
4308
4337
  * @returns A `Response` object with the UI message stream as the body.
4309
4338
  */
4310
- declare function createUIMessageStreamResponse({ status, statusText, headers, stream, consumeSseStream, }: UIMessageStreamResponseInit & {
4339
+ declare function createUIMessageStreamResponse({ status, statusText, headers, stream, keepAliveMs, consumeSseStream, }: UIMessageStreamResponseInit & {
4311
4340
  stream: ReadableStream<UIMessageChunk>;
4312
4341
  }): Response;
4313
4342
 
@@ -4329,10 +4358,11 @@ declare class JsonToSseTransformStream extends TransformStream<unknown, string>
4329
4358
  * @param options.statusText - The HTTP status text for the response.
4330
4359
  * @param options.headers - Additional HTTP headers to include in the response.
4331
4360
  * @param options.stream - The UI message chunk stream to send.
4361
+ * @param options.keepAliveMs - Optional interval for sending SSE keep-alive comments.
4332
4362
  * @param options.consumeSseStream - Optional callback to consume a copy of the SSE stream independently.
4333
4363
  * @returns A promise that resolves when the stream has been written.
4334
4364
  */
4335
- declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, consumeSseStream, }: {
4365
+ declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, keepAliveMs, consumeSseStream, }: {
4336
4366
  response: ServerResponse;
4337
4367
  stream: ReadableStream<UIMessageChunk>;
4338
4368
  } & UIMessageStreamResponseInit): Promise<void>;
@@ -4400,9 +4430,10 @@ declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet
4400
4430
  * @param headers - Additional headers for the response. Optional.
4401
4431
  * @param status - The status code for the response. Optional.
4402
4432
  * @param statusText - The status text for the response. Optional.
4433
+ * @param keepAliveMs - Optional interval for sending SSE keep-alive comments.
4403
4434
  * @param consumeSseStream - Whether to consume the SSE stream. Optional.
4404
4435
  */
4405
- declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ response, headers, status, statusText, consumeSseStream, ...options }: {
4436
+ declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ response, headers, status, statusText, keepAliveMs, consumeSseStream, ...options }: {
4406
4437
  response: ServerResponse;
4407
4438
  agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
4408
4439
  uiMessages?: unknown[];
package/dist/index.d.ts CHANGED
@@ -1736,6 +1736,13 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1736
1736
  } & ({
1737
1737
  state: 'input-streaming';
1738
1738
  input?: DeepPartial<asUITool<TOOL>['input']> | undefined;
1739
+ /**
1740
+ * The raw tool input text received so far.
1741
+ *
1742
+ * This is used to continue input streaming when a message is persisted
1743
+ * and later resumed.
1744
+ */
1745
+ rawInput?: string;
1739
1746
  output?: never;
1740
1747
  errorText?: never;
1741
1748
  callProviderMetadata?: ProviderMetadata;
@@ -1846,6 +1853,13 @@ type DynamicToolUIPart = {
1846
1853
  } & ({
1847
1854
  state: 'input-streaming';
1848
1855
  input?: unknown;
1856
+ /**
1857
+ * The raw tool input text received so far.
1858
+ *
1859
+ * This is used to continue input streaming when a message is persisted
1860
+ * and later resumed.
1861
+ */
1862
+ rawInput?: string;
1849
1863
  output?: never;
1850
1864
  errorText?: never;
1851
1865
  callProviderMetadata?: ProviderMetadata;
@@ -2188,6 +2202,12 @@ type UIMessageStreamOnFinishCallback<UI_MESSAGE extends UIMessage> = (event: {
2188
2202
  * Extends the standard `ResponseInit` with additional streaming options.
2189
2203
  */
2190
2204
  type UIMessageStreamResponseInit = ResponseInit & {
2205
+ /**
2206
+ * Optional interval in milliseconds for sending SSE keep-alive comments.
2207
+ * When set, an opening comment is sent immediately and additional comments
2208
+ * are sent after the stream has been idle for the configured interval.
2209
+ */
2210
+ keepAliveMs?: number;
2191
2211
  /**
2192
2212
  * Optional callback to consume a copy of the SSE stream independently.
2193
2213
  * This is useful for logging, debugging, or processing the stream in parallel.
@@ -2255,6 +2275,11 @@ type UIMessageStreamOptions<UI_MESSAGE extends UIMessage> = {
2255
2275
  /**
2256
2276
  * Process an error, e.g. to log it. Default to `() => 'An error occurred.'`.
2257
2277
  *
2278
+ * Tool execution errors marked `providerExecuted: true` bypass this callback.
2279
+ * Their strings pass through unchanged; other values are JSON-stringified to
2280
+ * preserve provider error data for model-message round trips. Stream errors
2281
+ * and invalid tool calls still use it.
2282
+ *
2258
2283
  * @returns error message to include in the data stream.
2259
2284
  */
2260
2285
  onError?: (error: unknown) => string;
@@ -3573,11 +3598,12 @@ type InferAgentUIMessage<AGENT, MESSAGE_METADATA = unknown> = UIMessage<MESSAGE_
3573
3598
  * @param headers - Additional headers for the response. Optional.
3574
3599
  * @param status - The status code for the response. Optional.
3575
3600
  * @param statusText - The status text for the response. Optional.
3601
+ * @param keepAliveMs - Optional interval for sending SSE keep-alive comments.
3576
3602
  * @param consumeSseStream - Whether to consume the SSE stream. Optional.
3577
3603
  *
3578
3604
  * @returns The response object.
3579
3605
  */
3580
- declare function createAgentUIStreamResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ headers, status, statusText, consumeSseStream, ...options }: {
3606
+ declare function createAgentUIStreamResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ headers, status, statusText, keepAliveMs, consumeSseStream, ...options }: {
3581
3607
  agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
3582
3608
  uiMessages?: unknown[];
3583
3609
  abortSignal?: AbortSignal;
@@ -4120,7 +4146,9 @@ declare function lastAssistantMessageIsCompleteWithApprovalResponses({ messages,
4120
4146
  /**
4121
4147
  * Check if the last message is an assistant message with completed tool calls.
4122
4148
  * The last step of the message must have at least one tool invocation and
4123
- * all tool invocations must have a result.
4149
+ * all tool invocations must have a result. Completed model text may follow
4150
+ * the tool invocation because client-side tool results update parts in place,
4151
+ * but trailing text without a completed stream state prevents resubmission.
4124
4152
  */
4125
4153
  declare function lastAssistantMessageIsCompleteWithToolCalls({ messages, }: {
4126
4154
  messages: UIMessage[];
@@ -4303,11 +4331,12 @@ originalMessages, onStepFinish, onFinish, generateId, }: {
4303
4331
  * @param options.statusText - The HTTP status text for the response.
4304
4332
  * @param options.headers - Additional HTTP headers to include in the response.
4305
4333
  * @param options.stream - The UI message chunk stream to send.
4334
+ * @param options.keepAliveMs - Optional interval for sending SSE keep-alive comments.
4306
4335
  * @param options.consumeSseStream - Optional callback to consume a copy of the SSE stream independently.
4307
4336
  *
4308
4337
  * @returns A `Response` object with the UI message stream as the body.
4309
4338
  */
4310
- declare function createUIMessageStreamResponse({ status, statusText, headers, stream, consumeSseStream, }: UIMessageStreamResponseInit & {
4339
+ declare function createUIMessageStreamResponse({ status, statusText, headers, stream, keepAliveMs, consumeSseStream, }: UIMessageStreamResponseInit & {
4311
4340
  stream: ReadableStream<UIMessageChunk>;
4312
4341
  }): Response;
4313
4342
 
@@ -4329,10 +4358,11 @@ declare class JsonToSseTransformStream extends TransformStream<unknown, string>
4329
4358
  * @param options.statusText - The HTTP status text for the response.
4330
4359
  * @param options.headers - Additional HTTP headers to include in the response.
4331
4360
  * @param options.stream - The UI message chunk stream to send.
4361
+ * @param options.keepAliveMs - Optional interval for sending SSE keep-alive comments.
4332
4362
  * @param options.consumeSseStream - Optional callback to consume a copy of the SSE stream independently.
4333
4363
  * @returns A promise that resolves when the stream has been written.
4334
4364
  */
4335
- declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, consumeSseStream, }: {
4365
+ declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, keepAliveMs, consumeSseStream, }: {
4336
4366
  response: ServerResponse;
4337
4367
  stream: ReadableStream<UIMessageChunk>;
4338
4368
  } & UIMessageStreamResponseInit): Promise<void>;
@@ -4400,9 +4430,10 @@ declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet
4400
4430
  * @param headers - Additional headers for the response. Optional.
4401
4431
  * @param status - The status code for the response. Optional.
4402
4432
  * @param statusText - The status text for the response. Optional.
4433
+ * @param keepAliveMs - Optional interval for sending SSE keep-alive comments.
4403
4434
  * @param consumeSseStream - Whether to consume the SSE stream. Optional.
4404
4435
  */
4405
- declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ response, headers, status, statusText, consumeSseStream, ...options }: {
4436
+ declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ response, headers, status, statusText, keepAliveMs, consumeSseStream, ...options }: {
4406
4437
  response: ServerResponse;
4407
4438
  agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
4408
4439
  uiMessages?: unknown[];