ai 7.0.141 → 7.0.143

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 (31) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/index.d.ts +256 -203
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +220 -123
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +28 -16
  7. package/dist/internal/index.d.ts.map +1 -1
  8. package/dist/internal/index.js +1 -1
  9. package/docs/03-ai-sdk-core/17-mcp-events.mdx +50 -0
  10. package/docs/03-ai-sdk-core/32-decisions.mdx +2 -1
  11. package/docs/03-ai-sdk-harnesses/05-harness-adapters.mdx +1 -1
  12. package/docs/04-ai-sdk-ui/50-stream-protocol.mdx +7 -0
  13. package/docs/07-reference/01-ai-sdk-core/02-stream-text-low-memory.mdx +107 -0
  14. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +13 -0
  15. package/docs/07-reference/01-ai-sdk-core/14-decide.mdx +1 -1
  16. package/docs/07-reference/01-ai-sdk-core/24-mcp-events.mdx +9 -8
  17. package/docs/07-reference/02-ai-sdk-ui/01-use-chat.mdx +1 -1
  18. package/package.json +12 -12
  19. package/src/agent/tool-loop-agent.ts +7 -4
  20. package/src/decide/decision-result.ts +6 -1
  21. package/src/decide/validate-decision.ts +21 -1
  22. package/src/generate-text/stream-language-model-call.ts +32 -16
  23. package/src/generate-text/stream-text-result.ts +2 -0
  24. package/src/generate-text/stream-text-single-consumer-result.ts +75 -0
  25. package/src/generate-text/stream-text.ts +250 -37
  26. package/src/ui/chat.ts +9 -4
  27. package/src/ui/process-ui-message-stream.ts +29 -3
  28. package/src/ui/ui-messages.ts +4 -0
  29. package/src/ui/validate-ui-messages.ts +2 -0
  30. package/src/ui-message-stream/to-ui-message-chunk.ts +3 -0
  31. package/src/ui-message-stream/ui-message-chunks.ts +3 -0
package/dist/index.js CHANGED
@@ -1174,7 +1174,7 @@ function cloneValue(value) {
1174
1174
  }
1175
1175
  //#endregion
1176
1176
  //#region src/version.ts
1177
- const VERSION = "7.0.141";
1177
+ const VERSION = "7.0.143";
1178
1178
  //#endregion
1179
1179
  //#region src/util/download/download.ts
1180
1180
  /**
@@ -6374,6 +6374,7 @@ const uiMessageChunkSchema = lazySchema(() => zodSchema$1(z.union([
6374
6374
  type: z.literal("tool-input-start"),
6375
6375
  toolCallId: z.string(),
6376
6376
  toolName: z.string(),
6377
+ inputEncoding: z.enum(["json", "text"]).optional(),
6377
6378
  providerExecuted: z.boolean().optional(),
6378
6379
  providerMetadata: providerMetadataSchema.optional(),
6379
6380
  toolMetadata: toolMetadataSchema$1.optional(),
@@ -6660,6 +6661,7 @@ function createStreamingUIMessageState({ lastMessage, messageId }) {
6660
6661
  if (part.state !== "input-streaming") continue;
6661
6662
  partialToolCalls[part.toolCallId] = {
6662
6663
  text: part.rawInput ?? "",
6664
+ inputEncoding: part.inputEncoding,
6663
6665
  index,
6664
6666
  toolName: part.type === "dynamic-tool" ? part.toolName : getStaticToolName(part),
6665
6667
  dynamic: part.type === "dynamic-tool",
@@ -6725,6 +6727,8 @@ function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas
6725
6727
  anyPart.output = anyOptions.output;
6726
6728
  anyPart.errorText = anyOptions.errorText;
6727
6729
  anyPart.rawInput = anyOptions.rawInput;
6730
+ if (anyOptions.inputEncoding != null) anyPart.inputEncoding = anyOptions.inputEncoding;
6731
+ else delete anyPart.inputEncoding;
6728
6732
  anyPart.preliminary = anyOptions.preliminary;
6729
6733
  if (options.title !== void 0) anyPart.title = options.title;
6730
6734
  if (options.toolMetadata !== void 0) anyPart.toolMetadata = options.toolMetadata;
@@ -6743,6 +6747,7 @@ function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas
6743
6747
  title: options.title,
6744
6748
  ...options.toolMetadata !== void 0 ? { toolMetadata: options.toolMetadata } : {},
6745
6749
  input: anyOptions.input,
6750
+ ...anyOptions.inputEncoding != null ? { inputEncoding: anyOptions.inputEncoding } : {},
6746
6751
  output: anyOptions.output,
6747
6752
  rawInput: anyOptions.rawInput,
6748
6753
  errorText: anyOptions.errorText,
@@ -6763,6 +6768,8 @@ function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas
6763
6768
  anyPart.output = anyOptions.output;
6764
6769
  anyPart.errorText = anyOptions.errorText;
6765
6770
  anyPart.rawInput = anyOptions.rawInput;
6771
+ if (anyOptions.inputEncoding != null) anyPart.inputEncoding = anyOptions.inputEncoding;
6772
+ else delete anyPart.inputEncoding;
6766
6773
  anyPart.preliminary = anyOptions.preliminary;
6767
6774
  if (options.title !== void 0) anyPart.title = options.title;
6768
6775
  if (options.toolMetadata !== void 0) anyPart.toolMetadata = options.toolMetadata;
@@ -6780,6 +6787,7 @@ function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas
6780
6787
  toolCallId: options.toolCallId,
6781
6788
  state: options.state,
6782
6789
  input: anyOptions.input,
6790
+ ...anyOptions.inputEncoding != null ? { inputEncoding: anyOptions.inputEncoding } : {},
6783
6791
  output: anyOptions.output,
6784
6792
  errorText: anyOptions.errorText,
6785
6793
  preliminary: anyOptions.preliminary,
@@ -6926,6 +6934,7 @@ function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas
6926
6934
  const toolInvocations = getCurrentStepParts().filter(isStaticToolUIPart);
6927
6935
  state.partialToolCalls[chunk.toolCallId] = {
6928
6936
  text: "",
6937
+ inputEncoding: chunk.inputEncoding,
6929
6938
  toolName: chunk.toolName,
6930
6939
  index: toolInvocations.length,
6931
6940
  dynamic: chunk.dynamic,
@@ -6936,6 +6945,7 @@ function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas
6936
6945
  toolCallId: chunk.toolCallId,
6937
6946
  toolName: chunk.toolName,
6938
6947
  state: "input-streaming",
6948
+ inputEncoding: chunk.inputEncoding,
6939
6949
  input: void 0,
6940
6950
  providerExecuted: chunk.providerExecuted,
6941
6951
  title: chunk.title,
@@ -6946,6 +6956,7 @@ function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas
6946
6956
  toolCallId: chunk.toolCallId,
6947
6957
  toolName: chunk.toolName,
6948
6958
  state: "input-streaming",
6959
+ inputEncoding: chunk.inputEncoding,
6949
6960
  input: void 0,
6950
6961
  providerExecuted: chunk.providerExecuted,
6951
6962
  title: chunk.title,
@@ -6963,11 +6974,12 @@ function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas
6963
6974
  message: `Received tool-input-delta for missing tool call with ID "${chunk.toolCallId}". Ensure a "tool-input-start" chunk is sent before any "tool-input-delta" chunks.`
6964
6975
  });
6965
6976
  partialToolCall.text += chunk.inputTextDelta;
6966
- const { value: partialArgs } = await parsePartialJson(partialToolCall.text);
6977
+ const partialArgs = partialToolCall.inputEncoding === "text" ? partialToolCall.text : (await parsePartialJson(partialToolCall.text)).value;
6967
6978
  if (partialToolCall.dynamic) updateDynamicToolPart({
6968
6979
  toolCallId: chunk.toolCallId,
6969
6980
  toolName: partialToolCall.toolName,
6970
6981
  state: "input-streaming",
6982
+ inputEncoding: partialToolCall.inputEncoding,
6971
6983
  input: partialArgs,
6972
6984
  rawInput: partialToolCall.text,
6973
6985
  title: partialToolCall.title,
@@ -6977,6 +6989,7 @@ function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas
6977
6989
  toolCallId: chunk.toolCallId,
6978
6990
  toolName: partialToolCall.toolName,
6979
6991
  state: "input-streaming",
6992
+ inputEncoding: partialToolCall.inputEncoding,
6980
6993
  input: partialArgs,
6981
6994
  rawInput: partialToolCall.text,
6982
6995
  title: partialToolCall.title,
@@ -7381,6 +7394,7 @@ function toUIMessageChunk(part, { tools, sendReasoning = true, sendSources = fal
7381
7394
  type: "tool-input-start",
7382
7395
  toolCallId: part.id,
7383
7396
  toolName: part.toolName,
7397
+ ...part.inputEncoding != null ? { inputEncoding: part.inputEncoding } : {},
7384
7398
  ...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
7385
7399
  ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
7386
7400
  ...part.toolMetadata != null ? { toolMetadata: part.toolMetadata } : {},
@@ -8118,6 +8132,46 @@ function invokeToolCallbacksFromStream({ stream, tools, stepInputMessages, abort
8118
8132
  } }));
8119
8133
  }
8120
8134
  //#endregion
8135
+ //#region src/generate-text/stream-text-single-consumer-result.ts
8136
+ /** Expose only the stream and completion metadata for a single consumer. */
8137
+ function createSingleConsumerStreamTextResult(result) {
8138
+ return {
8139
+ get textStream() {
8140
+ return result.textStream;
8141
+ },
8142
+ get stream() {
8143
+ return result.stream;
8144
+ },
8145
+ get fullStream() {
8146
+ return result.fullStream;
8147
+ },
8148
+ get partialOutputStream() {
8149
+ return result.partialOutputStream;
8150
+ },
8151
+ get elementStream() {
8152
+ return result.elementStream;
8153
+ },
8154
+ get totalUsage() {
8155
+ return result.totalUsage;
8156
+ },
8157
+ get usage() {
8158
+ return result.usage;
8159
+ },
8160
+ get finishReason() {
8161
+ return result.finishReason;
8162
+ },
8163
+ get rawFinishReason() {
8164
+ return result.rawFinishReason;
8165
+ },
8166
+ consumeStream: result.consumeStream.bind(result),
8167
+ toUIMessageStream: result.toUIMessageStream.bind(result),
8168
+ toUIMessageStreamResponse: result.toUIMessageStreamResponse.bind(result),
8169
+ toTextStreamResponse: result.toTextStreamResponse.bind(result),
8170
+ pipeUIMessageStreamToResponse: result.pipeUIMessageStreamToResponse.bind(result),
8171
+ pipeTextStreamToResponse: result.pipeTextStreamToResponse.bind(result)
8172
+ };
8173
+ }
8174
+ //#endregion
8121
8175
  //#region src/prompt/normalize-stream-provider-error.ts
8122
8176
  /**
8123
8177
  * Normalizes well-formed provider error payloads without changing existing
@@ -8245,7 +8299,7 @@ const originalGenerateCallId$8 = createIdGenerator$1({
8245
8299
  *
8246
8300
  * @returns A stream of model call parts together with request and response metadata when available.
8247
8301
  */
8248
- async function streamLanguageModelCall({ model, tools, toolOrder, output, toolChoice, prompt, system, instructions, messages, allowSystemInMessages, download, abortSignal, headers, includeRawChunks, providerOptions, repairToolCall, refineToolInput, executeLanguageModelCallInTelemetryContext = async ({ execute }) => await execute(), callId, toolsContext, experimental_sandbox: sandbox, _internal: { generateId = originalGenerateId$3, generateCallId = originalGenerateCallId$8, now: now$3 = now } = {}, onStart, onLanguageModelCallStart, onLanguageModelCallEnd, ...callSettings }) {
8302
+ async function streamLanguageModelCall({ model, tools, toolOrder, output, toolChoice, prompt, system, instructions, messages, allowSystemInMessages, download, abortSignal, headers, includeRawChunks, providerOptions, repairToolCall, refineToolInput, executeLanguageModelCallInTelemetryContext = async ({ execute }) => await execute(), callId, toolsContext, experimental_sandbox: sandbox, _internal: { generateId = originalGenerateId$3, generateCallId = originalGenerateCallId$8, now: now$3 = now, collectContent = true } = {}, onStart, onLanguageModelCallStart, onLanguageModelCallEnd, ...callSettings }) {
8249
8303
  const resolvedModel = resolveLanguageModel(model);
8250
8304
  const effectiveCallId = callId ?? generateCallId();
8251
8305
  const standardizedPrompt = await standardizePrompt({
@@ -8319,13 +8373,14 @@ async function streamLanguageModelCall({ model, tools, toolOrder, output, toolCh
8319
8373
  generateId,
8320
8374
  now: now$3,
8321
8375
  callStartTimestampMs,
8322
- onLanguageModelCallEnd
8376
+ onLanguageModelCallEnd,
8377
+ collectContent
8323
8378
  }))),
8324
8379
  response,
8325
8380
  request
8326
8381
  };
8327
8382
  }
8328
- function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ tools, instructions, messages, repairToolCall, refineToolInput, abortSignal, callId, provider, modelId, toolChoice, generateId, now, callStartTimestampMs, onLanguageModelCallEnd }) {
8383
+ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ tools, instructions, messages, repairToolCall, refineToolInput, abortSignal, callId, provider, modelId, toolChoice, generateId, now, callStartTimestampMs, onLanguageModelCallEnd, collectContent }) {
8329
8384
  const toolCallsByToolCallId = /* @__PURE__ */ new Map();
8330
8385
  const modelCallContent = [];
8331
8386
  const rawModelCallContent = [];
@@ -8354,6 +8409,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
8354
8409
  break;
8355
8410
  case "text-start":
8356
8411
  upsertTextContentPart({
8412
+ enabled: collectContent,
8357
8413
  content: modelCallContent,
8358
8414
  rawContent: rawModelCallContent,
8359
8415
  partIndexes: textPartIndexes,
@@ -8366,6 +8422,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
8366
8422
  break;
8367
8423
  case "text-delta":
8368
8424
  upsertTextContentPart({
8425
+ enabled: collectContent,
8369
8426
  content: modelCallContent,
8370
8427
  rawContent: rawModelCallContent,
8371
8428
  partIndexes: textPartIndexes,
@@ -8384,6 +8441,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
8384
8441
  break;
8385
8442
  case "text-end":
8386
8443
  upsertTextContentPart({
8444
+ enabled: collectContent,
8387
8445
  content: modelCallContent,
8388
8446
  rawContent: rawModelCallContent,
8389
8447
  partIndexes: textPartIndexes,
@@ -8398,6 +8456,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
8398
8456
  break;
8399
8457
  case "reasoning-start":
8400
8458
  upsertTextContentPart({
8459
+ enabled: collectContent,
8401
8460
  content: modelCallContent,
8402
8461
  rawContent: rawModelCallContent,
8403
8462
  partIndexes: reasoningPartIndexes,
@@ -8410,6 +8469,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
8410
8469
  break;
8411
8470
  case "reasoning-delta":
8412
8471
  upsertTextContentPart({
8472
+ enabled: collectContent,
8413
8473
  content: modelCallContent,
8414
8474
  rawContent: rawModelCallContent,
8415
8475
  partIndexes: reasoningPartIndexes,
@@ -8428,6 +8488,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
8428
8488
  break;
8429
8489
  case "reasoning-end":
8430
8490
  upsertTextContentPart({
8491
+ enabled: collectContent,
8431
8492
  content: modelCallContent,
8432
8493
  rawContent: rawModelCallContent,
8433
8494
  partIndexes: reasoningPartIndexes,
@@ -8449,12 +8510,12 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
8449
8510
  }),
8450
8511
  mediaType: chunk.mediaType
8451
8512
  });
8452
- modelCallContent.push({
8513
+ if (collectContent) modelCallContent.push({
8453
8514
  type: chunk.type,
8454
8515
  file,
8455
8516
  ...chunk.providerMetadata != null ? { providerMetadata: chunk.providerMetadata } : {}
8456
8517
  });
8457
- rawModelCallContent.push(chunk);
8518
+ if (collectContent) rawModelCallContent.push(chunk);
8458
8519
  controller.enqueue({
8459
8520
  type: chunk.type,
8460
8521
  file,
@@ -8526,7 +8587,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
8526
8587
  break;
8527
8588
  }
8528
8589
  case "tool-call":
8529
- rawModelCallContent.push(chunk);
8590
+ if (collectContent) rawModelCallContent.push(chunk);
8530
8591
  try {
8531
8592
  const toolCall = await parseToolCall({
8532
8593
  toolCall: chunk,
@@ -8539,7 +8600,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
8539
8600
  });
8540
8601
  toolCallsByToolCallId.set(toolCall.toolCallId, toolCall);
8541
8602
  controller.enqueue(toolCall);
8542
- modelCallContent.push(toolCall);
8603
+ if (collectContent) modelCallContent.push(toolCall);
8543
8604
  if (toolCall.invalid) {
8544
8605
  if (!toolCall.providerExecuted) controller.enqueue({
8545
8606
  type: "tool-error",
@@ -8561,7 +8622,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
8561
8622
  }
8562
8623
  break;
8563
8624
  case "tool-approval-request": {
8564
- rawModelCallContent.push(chunk);
8625
+ if (collectContent) rawModelCallContent.push(chunk);
8565
8626
  const toolCall = toolCallsByToolCallId.get(chunk.toolCallId);
8566
8627
  if (toolCall == null) {
8567
8628
  controller.enqueue({
@@ -8579,11 +8640,11 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
8579
8640
  toolCall
8580
8641
  };
8581
8642
  controller.enqueue(toolApprovalRequest);
8582
- modelCallContent.push(toolApprovalRequest);
8643
+ if (collectContent) modelCallContent.push(toolApprovalRequest);
8583
8644
  break;
8584
8645
  }
8585
8646
  case "tool-result": {
8586
- rawModelCallContent.push(chunk);
8647
+ if (collectContent) rawModelCallContent.push(chunk);
8587
8648
  const toolName = chunk.toolName;
8588
8649
  const toolCall = toolCallsByToolCallId.get(chunk.toolCallId);
8589
8650
  const toolResultPart = chunk.isError ? {
@@ -8608,7 +8669,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
8608
8669
  ...toolCall?.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
8609
8670
  };
8610
8671
  controller.enqueue(toolResultPart);
8611
- modelCallContent.push(toolResultPart);
8672
+ if (collectContent) modelCallContent.push(toolResultPart);
8612
8673
  break;
8613
8674
  }
8614
8675
  case "tool-input-start": {
@@ -8639,8 +8700,8 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
8639
8700
  break;
8640
8701
  default:
8641
8702
  if (chunk.type === "custom" || chunk.type === "source") {
8642
- modelCallContent.push(chunk);
8643
- rawModelCallContent.push(chunk);
8703
+ if (collectContent) modelCallContent.push(chunk);
8704
+ if (collectContent) rawModelCallContent.push(chunk);
8644
8705
  }
8645
8706
  controller.enqueue(chunk);
8646
8707
  }
@@ -8672,7 +8733,8 @@ function calculateNearestRankPercentile(sortedValues, percentile) {
8672
8733
  /**
8673
8734
  * Appends a text or reasoning content part into the content array and updates the part indexes.
8674
8735
  */
8675
- function upsertTextContentPart({ content, rawContent, partIndexes, rawPartIndexes, id, type, textDelta, providerMetadata }) {
8736
+ function upsertTextContentPart({ enabled, content, rawContent, partIndexes, rawPartIndexes, id, type, textDelta, providerMetadata }) {
8737
+ if (!enabled) return;
8676
8738
  let partIndex = partIndexes.get(id);
8677
8739
  if (partIndex == null) {
8678
8740
  partIndex = content.push({
@@ -8712,75 +8774,26 @@ const originalGenerateCallId$7 = createIdGenerator$1({
8712
8774
  prefix: "call",
8713
8775
  size: 24
8714
8776
  });
8715
- /**
8716
- * Generate a text and call tools for a given prompt using a language model.
8717
- *
8718
- * This function streams the output. If you do not want to stream the output, use `generateText` instead.
8719
- *
8720
- * @param model - The language model to use.
8721
- * @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
8722
- * @param toolOrder - Controls the order in which tools are sent to the provider. Tools not listed are appended alphabetically.
8723
- * @param toolCallConcurrency - Maximum number of tool calls that may execute concurrently within a step. Set to 1 for sequential execution. Default: unlimited.
8724
- *
8725
- * @param system - A system message that will be part of the prompt.
8726
- * @param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
8727
- * @param messages - A list of messages. You can either use `prompt` or `messages` but not both.
8728
- * @param allowSystemInMessages - Whether system messages are allowed in the `prompt` or `messages` fields. Default: false.
8729
- *
8730
- * @param maxOutputTokens - Maximum number of tokens to generate.
8731
- * @param temperature - Temperature setting.
8732
- * The value is passed through to the provider. The range depends on the provider and model.
8733
- * It is recommended to set either `temperature` or `topP`, but not both.
8734
- * @param topP - Nucleus sampling.
8735
- * The value is passed through to the provider. The range depends on the provider and model.
8736
- * It is recommended to set either `temperature` or `topP`, but not both.
8737
- * @param topK - Only sample from the top K options for each subsequent token.
8738
- * Used to remove "long tail" low probability responses.
8739
- * Recommended for advanced use cases only. You usually only need to use temperature.
8740
- * @param presencePenalty - Presence penalty setting.
8741
- * It affects the likelihood of the model to repeat information that is already in the prompt.
8742
- * The value is passed through to the provider. The range depends on the provider and model.
8743
- * @param frequencyPenalty - Frequency penalty setting.
8744
- * It affects the likelihood of the model to repeatedly use the same words or phrases.
8745
- * The value is passed through to the provider. The range depends on the provider and model.
8746
- * @param stopSequences - Stop sequences.
8747
- * If set, the model will stop generating text when one of the stop sequences is generated.
8748
- * @param seed - The seed (integer) to use for random sampling.
8749
- * If set and supported by the model, calls will generate deterministic results.
8750
- *
8751
- * @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
8752
- * @param streamRetries - Maximum number of retries for provider errors received after streaming starts. Set to 0 to disable automatic stream retries while allowing `onError` to request retries. Omit to disable all stream retry behavior. Default: 0.
8753
- * @param abortSignal - An optional abort signal that can be used to cancel the call.
8754
- * @param timeout - An optional timeout in milliseconds. The call will be aborted if it takes longer than the specified timeout.
8755
- * @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
8756
- *
8757
- * @param experimental_sandbox - The sandbox environment that is passed through to tool execution.
8758
- * @param runtimeContext - User-defined runtime context that flows through the entire generation lifecycle.
8759
- * @param experimental_refineToolInput - Optional mapping of tool names to functions that refine parsed tool inputs before tools are executed and before outputs, callbacks, and telemetry are recorded.
8760
- *
8761
- * @param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
8762
- * @param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
8763
- * @param onStart - Callback invoked when generation begins, before any LLM calls.
8764
- * @param experimental_onStart - Deprecated alias for `onStart`.
8765
- * @param onStepStart - Callback invoked when each step begins, before the provider is called.
8766
- * @param experimental_onStepStart - Deprecated alias for `onStepStart`.
8767
- * @param onLanguageModelCallStart - Callback invoked immediately before each provider model call begins.
8768
- * @param experimental_onLanguageModelCallStart - Deprecated alias for `onLanguageModelCallStart`.
8769
- * @param onLanguageModelCallEnd - Callback invoked after each provider model call response is normalized and parsed.
8770
- * @param experimental_onLanguageModelCallEnd - Deprecated alias for `onLanguageModelCallEnd`.
8771
- * @param onToolExecutionStart - Callback invoked before each tool execution begins.
8772
- * @param experimental_onToolCallStart - Deprecated alias for `onToolExecutionStart`.
8773
- * @param onToolExecutionEnd - Callback invoked after each tool execution completes.
8774
- * @param experimental_onToolCallFinish - Deprecated alias for `onToolExecutionEnd`.
8775
- * @param onStepEnd - Callback that is called when each step (LLM call) ends, including intermediate steps.
8776
- * @param onStepFinish - Deprecated alias for `onStepEnd`.
8777
- * @param onEnd - Callback that is called when all steps are finished and the response is complete.
8778
- * @param onFinish - Deprecated alias for `onEnd`.
8779
- *
8780
- * @returns
8781
- * A result object for accessing different stream types and additional information.
8782
- */
8783
- function streamText({ model, tools, toolChoice, instructions, system, prompt, messages, allowSystemInMessages, maxRetries, streamRetries, abortSignal, timeout, headers, stopWhen = isStepCount(1), experimental_sandbox: sandbox, output, toolApproval, experimental_toolCallers, experimental_toolApprovalSecret, experimental_telemetry, telemetry = experimental_telemetry, prepareStep, providerOptions, activeTools, toolOrder, toolCallConcurrency, experimental_repairToolCall, repairToolCall = experimental_repairToolCall, experimental_refineToolInput: refineToolInput, experimental_transform: transform, experimental_download: download, includeRawChunks, onChunk, onError: onErrorArg, onFinish, onEnd = onFinish, onAbort, onStepEnd, onStepFinish, onStart, experimental_onStart, onStepStart, experimental_onStepStart, onLanguageModelCallStart, experimental_onLanguageModelCallStart, onLanguageModelCallEnd, experimental_onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, experimental_onToolCallStart, experimental_onToolCallFinish, runtimeContext = {}, toolsContext = {}, experimental_include, include = experimental_include, _internal: { now: now$2 = now, generateId = originalGenerateId$2, generateCallId = originalGenerateCallId$7 } = {}, ...settings }) {
8777
+ function streamText({ experimental_lowMemory = false, ...options }) {
8778
+ if (!experimental_lowMemory) return streamTextInternal({ ...options });
8779
+ const telemetry = options.telemetry ?? options.experimental_telemetry;
8780
+ const integrations = telemetry?.integrations != null ? asArray(telemetry.integrations) : getGlobalTelemetryIntegrations();
8781
+ const collectContent = options.tools != null && Object.keys(options.tools).length > 0 || options.toolChoice != null || options.output != null || options.prepareStep != null || options.stopWhen != null || options.onEnd != null || options.onFinish != null || options.onStepEnd != null || options.onStepFinish != null || options.onAbort != null || options.onLanguageModelCallEnd != null || options.experimental_onLanguageModelCallEnd != null || telemetry?.isEnabled !== false && integrations.length > 0;
8782
+ return createSingleConsumerStreamTextResult(streamTextInternal({
8783
+ ...options,
8784
+ _internal: {
8785
+ ...options._internal,
8786
+ retention: {
8787
+ replay: false,
8788
+ collectContent
8789
+ }
8790
+ }
8791
+ }));
8792
+ }
8793
+ function streamTextInternal({ model, tools, toolChoice, instructions, system, prompt, messages, allowSystemInMessages, maxRetries, streamRetries, abortSignal, timeout, headers, stopWhen = isStepCount(1), experimental_sandbox: sandbox, output, toolApproval, experimental_toolCallers, experimental_toolApprovalSecret, experimental_telemetry, telemetry = experimental_telemetry, prepareStep, providerOptions, activeTools, toolOrder, toolCallConcurrency, experimental_repairToolCall, repairToolCall = experimental_repairToolCall, experimental_refineToolInput: refineToolInput, experimental_transform: transform, experimental_download: download, includeRawChunks, onChunk, onError: onErrorArg, onFinish, onEnd = onFinish, onAbort, onStepEnd, onStepFinish, onStart, experimental_onStart, onStepStart, experimental_onStepStart, onLanguageModelCallStart, experimental_onLanguageModelCallStart, onLanguageModelCallEnd, experimental_onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, experimental_onToolCallStart, experimental_onToolCallFinish, runtimeContext = {}, toolsContext = {}, experimental_include, include = experimental_include, _internal: { now: now$2 = now, generateId = originalGenerateId$2, generateCallId = originalGenerateCallId$7, retention = {
8794
+ replay: true,
8795
+ collectContent: true
8796
+ } } = {}, ...settings }) {
8784
8797
  const resolvedToolCallConcurrency = prepareToolCallConcurrency(toolCallConcurrency);
8785
8798
  const totalTimeoutMs = getTotalTimeoutMs(timeout);
8786
8799
  const stepTimeoutMs = getStepTimeoutMs(timeout);
@@ -8800,6 +8813,7 @@ function streamText({ model, tools, toolChoice, instructions, system, prompt, me
8800
8813
  const resolvedOnToolExecutionEnd = onToolExecutionEnd ?? experimental_onToolCallFinish;
8801
8814
  const resolvedOnStepEnd = onStepEnd ?? onStepFinish;
8802
8815
  return new DefaultStreamTextResult({
8816
+ retention,
8803
8817
  model: resolveLanguageModel(model),
8804
8818
  telemetry,
8805
8819
  headers,
@@ -8869,7 +8883,7 @@ async function markPromiseAsHandled$1(promise) {
8869
8883
  await promise;
8870
8884
  } catch {}
8871
8885
  }
8872
- function createOutputTransformStream(output) {
8886
+ function createOutputTransformStream(output, collectOutput = true) {
8873
8887
  let firstTextChunkId = void 0;
8874
8888
  let text = "";
8875
8889
  let textChunk = "";
@@ -8903,6 +8917,13 @@ function createOutputTransformStream(output) {
8903
8917
  textChunk = "";
8904
8918
  }
8905
8919
  return new TransformStream({ async transform(chunk, controller) {
8920
+ if (!collectOutput) {
8921
+ controller.enqueue(isStreamRetryBoundaryPart(chunk) ? chunk : {
8922
+ part: chunk,
8923
+ partialOutput: void 0
8924
+ });
8925
+ return;
8926
+ }
8906
8927
  if (isStreamRetryBoundaryPart(chunk)) {
8907
8928
  resetOutputState();
8908
8929
  controller.enqueue(chunk);
@@ -9033,12 +9054,14 @@ function applyStreamTextTransforms({ stream, transforms, tools, stopStream }) {
9033
9054
  });
9034
9055
  }
9035
9056
  var DefaultStreamTextResult = class {
9036
- constructor({ model, telemetry, headers, settings, maxRetries: maxRetriesArg, streamRetries: streamRetriesArg, abortSignal, stepTimeoutMs, stepAbortController, firstChunkTimeoutMs, firstChunkAbortController, chunkTimeoutMs, chunkAbortController, instructions, system, prompt, messages, allowSystemInMessages, experimental_sandbox: sandbox, tools, toolChoice, transforms, activeTools, toolOrder, toolCallConcurrency, repairToolCall, refineToolInput, stopConditions, output, toolApproval, experimental_toolCallers, experimental_toolApprovalSecret, providerOptions, prepareStep, now, generateId, generateCallId, timeout, onChunk, onError, canRetryStreamViaOnError, onEnd, onAbort, onStepFinish, onStart, onStepStart, onLanguageModelCallStart, onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, runtimeContext, toolsContext, download, include }) {
9057
+ constructor({ retention, model, telemetry, headers, settings, maxRetries: maxRetriesArg, streamRetries: streamRetriesArg, abortSignal, stepTimeoutMs, stepAbortController, firstChunkTimeoutMs, firstChunkAbortController, chunkTimeoutMs, chunkAbortController, instructions, system, prompt, messages, allowSystemInMessages, experimental_sandbox: sandbox, tools, toolChoice, transforms, activeTools, toolOrder, toolCallConcurrency, repairToolCall, refineToolInput, stopConditions, output, toolApproval, experimental_toolCallers, experimental_toolApprovalSecret, providerOptions, prepareStep, now, generateId, generateCallId, timeout, onChunk, onError, canRetryStreamViaOnError, onEnd, onAbort, onStepFinish, onStart, onStepStart, onLanguageModelCallStart, onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, runtimeContext, toolsContext, download, include }) {
9037
9058
  this._totalUsage = new DelayedPromise();
9038
9059
  this._finishReason = new DelayedPromise();
9039
9060
  this._rawFinishReason = new DelayedPromise();
9040
9061
  this._steps = new DelayedPromise();
9041
9062
  this._initialResponseMessages = new DelayedPromise();
9063
+ this.streamClaimed = false;
9064
+ this.retention = retention;
9042
9065
  this.outputSpecification = output;
9043
9066
  this.tools = tools;
9044
9067
  const resolvedToolCallers = resolveToolCallerConfiguration({
@@ -9062,7 +9085,7 @@ var DefaultStreamTextResult = class {
9062
9085
  let recordedRequest = {};
9063
9086
  let recordedRequestMessages = [];
9064
9087
  let recordedWarnings = [];
9065
- const recordedSteps = [];
9088
+ let recordedSteps = [];
9066
9089
  const initialResponseMessages = [];
9067
9090
  let stepMessagesForNextStep;
9068
9091
  let currentStepMessages = [];
@@ -9120,14 +9143,16 @@ var DefaultStreamTextResult = class {
9120
9143
  }
9121
9144
  });
9122
9145
  }
9123
- if (part.type === "custom" || part.type === "source" || part.type === "tool-call" || part.type === "tool-approval-request" || part.type === "tool-approval-response" || part.type === "tool-error") recordedContent.push(part);
9146
+ if (part.type === "custom" || part.type === "source" || part.type === "tool-call" || part.type === "tool-approval-request" || part.type === "tool-approval-response" || part.type === "tool-error") {
9147
+ if (retention.collectContent) recordedContent.push(part);
9148
+ }
9124
9149
  if (part.type === "text-start") {
9125
9150
  activeTextContent[part.id] = {
9126
9151
  type: "text",
9127
9152
  text: "",
9128
9153
  providerMetadata: part.providerMetadata
9129
9154
  };
9130
- recordedContent.push(activeTextContent[part.id]);
9155
+ if (retention.collectContent) recordedContent.push(activeTextContent[part.id]);
9131
9156
  }
9132
9157
  if (part.type === "text-delta") {
9133
9158
  const activeText = activeTextContent[part.id];
@@ -9141,7 +9166,7 @@ var DefaultStreamTextResult = class {
9141
9166
  });
9142
9167
  return;
9143
9168
  }
9144
- activeText.text += part.text;
9169
+ if (retention.collectContent) activeText.text += part.text;
9145
9170
  activeText.providerMetadata = part.providerMetadata ?? activeText.providerMetadata;
9146
9171
  }
9147
9172
  if (part.type === "text-end") {
@@ -9166,7 +9191,7 @@ var DefaultStreamTextResult = class {
9166
9191
  text: "",
9167
9192
  providerMetadata: part.providerMetadata
9168
9193
  };
9169
- recordedContent.push(activeReasoningContent[part.id]);
9194
+ if (retention.collectContent) recordedContent.push(activeReasoningContent[part.id]);
9170
9195
  }
9171
9196
  if (part.type === "reasoning-delta") {
9172
9197
  const activeReasoning = activeReasoningContent[part.id];
@@ -9180,7 +9205,7 @@ var DefaultStreamTextResult = class {
9180
9205
  });
9181
9206
  return;
9182
9207
  }
9183
- activeReasoning.text += part.text;
9208
+ if (retention.collectContent) activeReasoning.text += part.text;
9184
9209
  activeReasoning.providerMetadata = part.providerMetadata ?? activeReasoning.providerMetadata;
9185
9210
  }
9186
9211
  if (part.type === "reasoning-end") {
@@ -9198,12 +9223,16 @@ var DefaultStreamTextResult = class {
9198
9223
  activeReasoning.providerMetadata = part.providerMetadata ?? activeReasoning.providerMetadata;
9199
9224
  delete activeReasoningContent[part.id];
9200
9225
  }
9201
- if (part.type === "file" || part.type === "reasoning-file") recordedContent.push({
9202
- type: part.type,
9203
- file: part.file,
9204
- ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
9205
- });
9206
- if (part.type === "tool-result" && !part.preliminary) recordedContent.push(part);
9226
+ if (part.type === "file" || part.type === "reasoning-file") {
9227
+ if (retention.collectContent) recordedContent.push({
9228
+ type: part.type,
9229
+ file: part.file,
9230
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
9231
+ });
9232
+ }
9233
+ if (part.type === "tool-result" && !part.preliminary) {
9234
+ if (retention.collectContent) recordedContent.push(part);
9235
+ }
9207
9236
  if (part.type === "start-step") {
9208
9237
  recordedContent = [];
9209
9238
  activeReasoningContent = createIdMap();
@@ -9270,7 +9299,7 @@ var DefaultStreamTextResult = class {
9270
9299
  self._finishReason.resolve(finishReason);
9271
9300
  self._rawFinishReason.resolve(recordedRawFinishReason);
9272
9301
  self._totalUsage.resolve(totalUsage);
9273
- self._steps.resolve(recordedSteps);
9302
+ self._steps.resolve(retention.replay ? recordedSteps : []);
9274
9303
  if (isAborted) return;
9275
9304
  const finalStep = recordedSteps[recordedSteps.length - 1];
9276
9305
  const content = recordedSteps.flatMap((step) => step.content);
@@ -9284,7 +9313,7 @@ var DefaultStreamTextResult = class {
9284
9313
  const dynamicToolResults = recordedSteps.flatMap((step) => step.dynamicToolResults);
9285
9314
  const warnings = recordedSteps.flatMap((step) => step.warnings ?? []);
9286
9315
  const onEndWithOutput = onEnd == null ? void 0 : async (event) => {
9287
- const parsedOutput = output == null ? void 0 : await self.getOutputPromise().catch(() => void 0);
9316
+ const parsedOutput = output == null ? void 0 : await (retention.replay ? self.getOutputPromise() : self.parseOutput(finalStep)).catch(() => void 0);
9288
9317
  await onEnd({
9289
9318
  ...event,
9290
9319
  ...output != null ? { output: parsedOutput } : {}
@@ -9329,6 +9358,16 @@ var DefaultStreamTextResult = class {
9329
9358
  })]);
9330
9359
  } catch (error) {
9331
9360
  controller.error(error);
9361
+ } finally {
9362
+ if (!retention.replay) {
9363
+ recordedSteps = [];
9364
+ recordedContent = [];
9365
+ recordedRequestMessages = [];
9366
+ currentStepMessages = [];
9367
+ stepMessagesForNextStep = void 0;
9368
+ activeTextContent = createIdMap();
9369
+ activeReasoningContent = createIdMap();
9370
+ }
9332
9371
  }
9333
9372
  }
9334
9373
  });
@@ -9407,7 +9446,7 @@ var DefaultStreamTextResult = class {
9407
9446
  isRunning = false;
9408
9447
  }
9409
9448
  });
9410
- this.baseStream = stream.pipeThrough(createOutputTransformStream(output ?? text())).pipeThrough(eventProcessor);
9449
+ this.baseStream = stream.pipeThrough(createOutputTransformStream(output ?? text(), retention.replay || output != null)).pipeThrough(eventProcessor);
9411
9450
  const { maxRetries } = prepareRetries({
9412
9451
  maxRetries: maxRetriesArg,
9413
9452
  abortSignal
@@ -9751,7 +9790,10 @@ var DefaultStreamTextResult = class {
9751
9790
  callbacks: [onStepStart, telemetryDispatcher.onStepStart]
9752
9791
  });
9753
9792
  },
9754
- _internal: { now },
9793
+ _internal: {
9794
+ now,
9795
+ collectContent: retention.collectContent
9796
+ },
9755
9797
  ...stepCallSettings
9756
9798
  })));
9757
9799
  const initialLanguageModelCall = await callLanguageModel();
@@ -10183,7 +10225,7 @@ var DefaultStreamTextResult = class {
10183
10225
  });
10184
10226
  }
10185
10227
  get steps() {
10186
- this.consumeStream();
10228
+ if (this.retention.replay) this.consumeStream();
10187
10229
  return this._steps.promise;
10188
10230
  }
10189
10231
  get finalStep() {
@@ -10244,15 +10286,15 @@ var DefaultStreamTextResult = class {
10244
10286
  return Promise.all([this._initialResponseMessages.promise, this.steps]).then(([initialResponseMessages, steps]) => [...initialResponseMessages, ...steps.flatMap((step) => step.response.messages)]);
10245
10287
  }
10246
10288
  get totalUsage() {
10247
- this.consumeStream();
10289
+ if (this.retention.replay) this.consumeStream();
10248
10290
  return this._totalUsage.promise;
10249
10291
  }
10250
10292
  get finishReason() {
10251
- this.consumeStream();
10293
+ if (this.retention.replay) this.consumeStream();
10252
10294
  return this._finishReason.promise;
10253
10295
  }
10254
10296
  get rawFinishReason() {
10255
- this.consumeStream();
10297
+ if (this.retention.replay) this.consumeStream();
10256
10298
  return this._rawFinishReason.promise;
10257
10299
  }
10258
10300
  /**
@@ -10264,15 +10306,50 @@ var DefaultStreamTextResult = class {
10264
10306
  * However, the LLM results are expected to be small enough to not cause issues.
10265
10307
  */
10266
10308
  teeStream() {
10309
+ if (!this.retention.replay) {
10310
+ if (this.streamClaimed) throw new AISDKError$1({
10311
+ name: "AI_StreamAlreadyConsumedError",
10312
+ message: "This result supports one stream consumer. Choose one stream projection or response helper."
10313
+ });
10314
+ this.streamClaimed = true;
10315
+ const reader = this.baseStream.getReader();
10316
+ const rejectResults = (error) => this.rejectResultPromises(error);
10317
+ return new ReadableStream({
10318
+ async pull(controller) {
10319
+ try {
10320
+ const { done, value } = await reader.read();
10321
+ if (done) {
10322
+ reader.releaseLock();
10323
+ controller.close();
10324
+ } else controller.enqueue(value);
10325
+ } catch (error) {
10326
+ rejectResults(error);
10327
+ reader.releaseLock();
10328
+ controller.error(error);
10329
+ }
10330
+ },
10331
+ async cancel(reason) {
10332
+ rejectResults(reason ?? new DOMException("The stream was cancelled.", "AbortError"));
10333
+ try {
10334
+ await reader.cancel(reason);
10335
+ } finally {
10336
+ reader.releaseLock();
10337
+ }
10338
+ }
10339
+ }, { highWaterMark: 0 });
10340
+ }
10267
10341
  const [stream1, stream2] = this.baseStream.tee();
10268
10342
  this.baseStream = stream2;
10269
10343
  return stream1;
10270
10344
  }
10271
10345
  get textStream() {
10272
- return createAsyncIterableStream(toTextStream({ stream: this.stream }));
10346
+ return this.asIterableStream(toTextStream({ stream: this.stream }));
10347
+ }
10348
+ asIterableStream(stream) {
10349
+ return this.retention.replay ? createAsyncIterableStream(stream) : asAsyncIterableStream(stream);
10273
10350
  }
10274
10351
  get stream() {
10275
- return createAsyncIterableStream(this.teeStream().pipeThrough(new TransformStream({ transform({ part }, controller) {
10352
+ return this.asIterableStream(this.teeStream().pipeThrough(new TransformStream({ transform({ part }, controller) {
10276
10353
  controller.enqueue(part);
10277
10354
  } })));
10278
10355
  }
@@ -10308,9 +10385,10 @@ var DefaultStreamTextResult = class {
10308
10385
  }
10309
10386
  }
10310
10387
  async consumeStream(options) {
10388
+ const stream = this.stream;
10311
10389
  try {
10312
10390
  await consumeStream({
10313
- stream: this.stream,
10391
+ stream,
10314
10392
  onError: (error) => {
10315
10393
  this.rejectResultPromises(error);
10316
10394
  options?.onError?.(error);
@@ -10325,25 +10403,27 @@ var DefaultStreamTextResult = class {
10325
10403
  return this.partialOutputStream;
10326
10404
  }
10327
10405
  get partialOutputStream() {
10328
- return createAsyncIterableStream(this.teeStream().pipeThrough(new TransformStream({ transform({ partialOutput }, controller) {
10406
+ if (!this.retention.replay && this.outputSpecification == null) throw new UnsupportedFunctionalityError$1({ functionality: "partialOutputStream without an explicit output specification with experimental_lowMemory enabled" });
10407
+ return this.asIterableStream(this.teeStream().pipeThrough(new TransformStream({ transform({ partialOutput }, controller) {
10329
10408
  if (partialOutput !== void 0) controller.enqueue(partialOutput);
10330
10409
  } })));
10331
10410
  }
10332
10411
  get elementStream() {
10333
10412
  const transform = this.outputSpecification?.createElementStreamTransform();
10334
10413
  if (transform == null) throw new UnsupportedFunctionalityError$1({ functionality: `element streams in ${this.outputSpecification?.name ?? "text"} mode` });
10335
- return createAsyncIterableStream(this.teeStream().pipeThrough(transform));
10414
+ return this.asIterableStream(this.teeStream().pipeThrough(transform));
10336
10415
  }
10337
10416
  getOutputPromise() {
10338
- if (this.outputPromise == null) this.outputPromise = this.finalStep.then((step) => {
10339
- return (this.outputSpecification ?? text()).parseCompleteOutput({ text: step.text }, {
10340
- response: step.response,
10341
- usage: step.usage,
10342
- finishReason: step.finishReason
10343
- });
10344
- });
10417
+ if (this.outputPromise == null) this.outputPromise = this.finalStep.then((step) => this.parseOutput(step));
10345
10418
  return this.outputPromise;
10346
10419
  }
10420
+ parseOutput(step) {
10421
+ return (this.outputSpecification ?? text()).parseCompleteOutput({ text: step.text }, {
10422
+ response: step.response,
10423
+ usage: step.usage,
10424
+ finishReason: step.finishReason
10425
+ });
10426
+ }
10347
10427
  get output() {
10348
10428
  return this.getOutputPromise();
10349
10429
  }
@@ -10560,7 +10640,8 @@ var ToolLoopAgent = class {
10560
10640
  return await stream({
10561
10641
  ...preparedCall,
10562
10642
  ...callbackArgs,
10563
- headers: this.agentHeaders(preparedCall)
10643
+ headers: this.agentHeaders(preparedCall),
10644
+ experimental_lowMemory: false
10564
10645
  });
10565
10646
  }
10566
10647
  };
@@ -11136,6 +11217,7 @@ const uiMessagesSchema = lazySchema(() => {
11136
11217
  state: z.literal("input-streaming"),
11137
11218
  input: z.unknown().optional(),
11138
11219
  rawInput: z.string().optional(),
11220
+ inputEncoding: z.enum(["json", "text"]).optional(),
11139
11221
  providerExecuted: z.boolean().optional(),
11140
11222
  callProviderMetadata: providerMetadataSchema.optional(),
11141
11223
  output: z.never().optional(),
@@ -11246,6 +11328,7 @@ const uiMessagesSchema = lazySchema(() => {
11246
11328
  callProviderMetadata: providerMetadataSchema.optional(),
11247
11329
  input: z.unknown().optional(),
11248
11330
  rawInput: z.string().optional(),
11331
+ inputEncoding: z.enum(["json", "text"]).optional(),
11249
11332
  output: z.never().optional(),
11250
11333
  errorText: z.never().optional(),
11251
11334
  approval: z.never().optional()
@@ -12921,6 +13004,7 @@ function validateDecisionInput({ state, questions }) {
12921
13004
  for (const [id, question] of Object.entries(questions)) {
12922
13005
  const parameter = `questions.${id}`;
12923
13006
  if (!isRecord$1(question) || !isInput(question.instructions)) invalidInput(parameter, question, "instructions must be a JSON-compatible string, object, or array");
13007
+ if (question.type === "box") continue;
12924
13008
  const criteria = question.criteria;
12925
13009
  switch (question.type) {
12926
13010
  case "choice":
@@ -12933,7 +13017,7 @@ function validateDecisionInput({ state, questions }) {
12933
13017
  if (criteria === void 0) continue;
12934
13018
  if (!isRecord$1(criteria) || Object.keys(criteria).some((key) => key !== "true" && key !== "false")) invalidInput(parameter, question, "boolean criteria may only describe true and false");
12935
13019
  break;
12936
- default: invalidInput(parameter, question, "question type must be choice, score, or boolean");
13020
+ default: invalidInput(parameter, question, "question type must be choice, score, boolean, or box");
12937
13021
  }
12938
13022
  if (!isJSON(criteria) || Object.values(criteria).some((value) => value !== null && !isInput(value))) invalidInput(parameter, question, "criteria descriptions must be JSON-compatible strings, objects, arrays, or null");
12939
13023
  }
@@ -12987,6 +13071,16 @@ function validateDecisionAnswers({ questions, answers, rounding }) {
12987
13071
  if (Math.abs(mean - answer.score) > tolerance + meanRoundingError + scoreError) invalidAnswer(answers, `Question "${id}" score must equal the probability-weighted mean within the declared rounding precision.`);
12988
13072
  }
12989
13073
  break;
13074
+ case "box": {
13075
+ const box = answer.box;
13076
+ if (!isRecord$1(box) || !hasExactKeys(box, [
13077
+ "top",
13078
+ "bottom",
13079
+ "left",
13080
+ "right"
13081
+ ]) || !isProbability(box.left) || !isProbability(box.right) || !isProbability(box.top) || !isProbability(box.bottom) || !(box.left < box.right) || !(box.top < box.bottom)) invalidAnswer(answers, `Question "${id}" must return box edges in [0, 1] with left < right and top < bottom.`);
13082
+ break;
13083
+ }
12990
13084
  case "boolean": if (!isProbability(answer.probability)) invalidAnswer(answers, `Question "${id}" must return P(true) as a finite probability in [0, 1].`);
12991
13085
  }
12992
13086
  }
@@ -19833,7 +19927,10 @@ var DefaultChatTransport = class extends HttpChatTransport {
19833
19927
  //#endregion
19834
19928
  //#region src/ui/chat.ts
19835
19929
  var AbstractChat = class {
19836
- constructor({ generateId = generateId$1, id = generateId(), transport = new DefaultChatTransport(), messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, onData, sendAutomaticallyWhen }) {
19930
+ get id() {
19931
+ return this._id ??= this.generateId();
19932
+ }
19933
+ constructor({ generateId = generateId$1, id, transport = new DefaultChatTransport(), messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, onData, sendAutomaticallyWhen }) {
19837
19934
  this.pendingMessagePreparations = /* @__PURE__ */ new Set();
19838
19935
  this.activeResponse = void 0;
19839
19936
  this.activeResumeRequest = void 0;
@@ -20040,7 +20137,7 @@ var AbstractChat = class {
20040
20137
  await this.stop();
20041
20138
  this.transport.close?.();
20042
20139
  };
20043
- this.id = id;
20140
+ this._id = id;
20044
20141
  this.transport = transport;
20045
20142
  this.generateId = generateId;
20046
20143
  this.messageMetadataSchema = messageMetadataSchema;