ai 6.0.268 → 6.0.271

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 (35) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/index.d.mts +48 -21
  3. package/dist/index.d.ts +48 -21
  4. package/dist/index.js +378 -130
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +317 -68
  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/dist/test/index.d.mts +4 -1
  11. package/dist/test/index.d.ts +4 -1
  12. package/dist/test/index.js +6 -0
  13. package/dist/test/index.js.map +1 -1
  14. package/dist/test/index.mjs +6 -0
  15. package/dist/test/index.mjs.map +1 -1
  16. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +2 -2
  17. package/docs/07-reference/01-ai-sdk-core/06-embed-many.mdx +6 -2
  18. package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +33 -5
  19. package/package.json +3 -3
  20. package/src/agent/create-agent-ui-stream.ts +2 -2
  21. package/src/embed/embed-many.ts +75 -6
  22. package/src/generate-text/stream-text.ts +84 -1
  23. package/src/middleware/wrap-embedding-model.ts +8 -1
  24. package/src/model/get-embedding-model-max-input-bytes-per-call.ts +15 -0
  25. package/src/test/mock-embedding-model-v3.ts +9 -0
  26. package/src/ui/direct-chat-transport.ts +2 -2
  27. package/src/ui/last-assistant-message-is-complete-with-approval-responses.ts +1 -0
  28. package/src/ui/validate-ui-messages.ts +136 -55
  29. package/src/ui-message-stream/create-ui-message-stream.ts +47 -17
  30. package/src/ui-message-stream/handle-ui-message-stream-finish.ts +58 -15
  31. package/src/ui-message-stream/index.ts +5 -1
  32. package/src/ui-message-stream/ui-message-stream-on-finish-callback.ts +7 -0
  33. package/src/ui-message-stream/ui-message-stream-outcome.ts +12 -0
  34. package/src/ui-message-stream/ui-message-stream-writer.ts +15 -0
  35. package/src/util/create-stitchable-stream.ts +35 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.271
4
+
5
+ ### Patch Changes
6
+
7
+ - 9310140: Validate persisted typed tool calls against current input and output schemas.
8
+ Schema-incompatible empty or error inputs and terminal history from unavailable
9
+ tools remain loadable as dynamic tool parts instead of exposing unvalidated
10
+ values under current static tool types.
11
+ - b503790: add operation-level outcomes to UI message stream end callbacks
12
+
13
+ ## 6.0.270
14
+
15
+ ### Patch Changes
16
+
17
+ - 8bc01a1: Allow chats to continue automatically after tool approval denials reach the `output-denied` state.
18
+ - fa01949: Handle stitchable stream cancellation before an inner stream is registered.
19
+
20
+ ## 6.0.269
21
+
22
+ ### Patch Changes
23
+
24
+ - 9a521b9: Split OpenAI and Azure OpenAI embedding requests by a conservative UTF-8 byte budget derived from their aggregate token limit, in addition to input count limits.
25
+ - Updated dependencies [8ddf255]
26
+ - Updated dependencies [9a521b9]
27
+ - @ai-sdk/gateway@3.0.184
28
+ - @ai-sdk/provider-utils@4.0.49
29
+
3
30
  ## 6.0.268
4
31
 
5
32
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -2113,6 +2113,24 @@ type UIMessageChunk<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataT
2113
2113
  };
2114
2114
  type InferUIMessageChunk<T extends UIMessage> = UIMessageChunk<InferUIMessageMetadata<T>, InferUIMessageData<T>>;
2115
2115
 
2116
+ /**
2117
+ * The operation-level outcome of a UI message stream.
2118
+ *
2119
+ * This is separate from model finish reasons and individual stream chunks.
2120
+ * Fatal stream-processing failures override outcomes declared by the stream
2121
+ * owner.
2122
+ */
2123
+ type UIMessageStreamOutcome = {
2124
+ status: 'completed';
2125
+ } | {
2126
+ status: 'failed';
2127
+ error?: unknown;
2128
+ } | {
2129
+ status: 'aborted';
2130
+ } | {
2131
+ status: 'unknown';
2132
+ };
2133
+
2116
2134
  type UIMessageStreamOnFinishCallback<UI_MESSAGE extends UIMessage> = (event: {
2117
2135
  /**
2118
2136
  * The updated list of UI messages.
@@ -2127,6 +2145,11 @@ type UIMessageStreamOnFinishCallback<UI_MESSAGE extends UIMessage> = (event: {
2127
2145
  * Indicates whether the stream was aborted.
2128
2146
  */
2129
2147
  isAborted: boolean;
2148
+ /**
2149
+ * The operation-level outcome of the stream. Fatal stream-processing
2150
+ * failures override outcomes declared by the stream owner.
2151
+ */
2152
+ outcome: UIMessageStreamOutcome;
2130
2153
  /**
2131
2154
  * The message that was sent to the client as a response
2132
2155
  * (including the original message if it was extended).
@@ -4148,12 +4171,7 @@ type SafeValidateUIMessagesResult<UI_MESSAGE extends UIMessage> = {
4148
4171
  success: false;
4149
4172
  error: Error;
4150
4173
  };
4151
- /**
4152
- * Validates a list of UI messages like `validateUIMessages`,
4153
- * but instead of throwing it returns `{ success: true, data }`
4154
- * or `{ success: false, error }`.
4155
- */
4156
- declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages, metadataSchema, dataSchemas, tools, }: {
4174
+ type ValidateUIMessagesOptions<UI_MESSAGE extends UIMessage> = {
4157
4175
  messages: unknown;
4158
4176
  metadataSchema?: FlexibleSchema<UIMessage['metadata']>;
4159
4177
  dataSchemas?: {
@@ -4162,7 +4180,13 @@ declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages
4162
4180
  tools?: {
4163
4181
  [NAME in keyof InferUIMessageTools<UI_MESSAGE> & string]?: Tool<InferUIMessageTools<UI_MESSAGE>[NAME]['input'], InferUIMessageTools<UI_MESSAGE>[NAME]['output']>;
4164
4182
  };
4165
- }): Promise<SafeValidateUIMessagesResult<UI_MESSAGE>>;
4183
+ };
4184
+ /**
4185
+ * Validates a list of UI messages like `validateUIMessages`,
4186
+ * but instead of throwing it returns `{ success: true, data }`
4187
+ * or `{ success: false, error }`.
4188
+ */
4189
+ declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>(options: ValidateUIMessagesOptions<UI_MESSAGE>): Promise<SafeValidateUIMessagesResult<UI_MESSAGE>>;
4166
4190
  /**
4167
4191
  * Validates a list of UI messages.
4168
4192
  *
@@ -4170,16 +4194,7 @@ declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages
4170
4194
  * the corresponding schemas are provided. Otherwise, they are assumed to be
4171
4195
  * valid.
4172
4196
  */
4173
- declare function validateUIMessages<UI_MESSAGE extends UIMessage>({ messages, metadataSchema, dataSchemas, tools, }: {
4174
- messages: unknown;
4175
- metadataSchema?: FlexibleSchema<UIMessage['metadata']>;
4176
- dataSchemas?: {
4177
- [NAME in keyof InferUIMessageData<UI_MESSAGE> & string]?: FlexibleSchema<InferUIMessageData<UI_MESSAGE>[NAME]>;
4178
- };
4179
- tools?: {
4180
- [NAME in keyof InferUIMessageTools<UI_MESSAGE> & string]?: Tool<InferUIMessageTools<UI_MESSAGE>[NAME]['input'], InferUIMessageTools<UI_MESSAGE>[NAME]['output']>;
4181
- };
4182
- }): Promise<Array<UI_MESSAGE>>;
4197
+ declare function validateUIMessages<UI_MESSAGE extends UIMessage>(options: ValidateUIMessagesOptions<UI_MESSAGE>): Promise<Array<UI_MESSAGE>>;
4183
4198
 
4184
4199
  interface UIMessageStreamWriter<UI_MESSAGE extends UIMessage = UIMessage> {
4185
4200
  /**
@@ -4197,6 +4212,17 @@ interface UIMessageStreamWriter<UI_MESSAGE extends UIMessage = UIMessage> {
4197
4212
  */
4198
4213
  onError: ErrorHandler | undefined;
4199
4214
  }
4215
+ interface UIMessageStreamWriterWithOutcome<UI_MESSAGE extends UIMessage = UIMessage> extends UIMessageStreamWriter<UI_MESSAGE> {
4216
+ /**
4217
+ * Declares the operation-level outcome of the composed stream.
4218
+ *
4219
+ * The first outcome declared through this method is retained. Fatal
4220
+ * execution, merge, error-handling, or downstream processing failures
4221
+ * override declared outcomes. Declaring an outcome does not write a chunk or
4222
+ * close the stream.
4223
+ */
4224
+ setOutcome(outcome: UIMessageStreamOutcome): void;
4225
+ }
4200
4226
 
4201
4227
  /**
4202
4228
  * Creates a UI message stream that can be used to send messages to the client.
@@ -4214,7 +4240,7 @@ interface UIMessageStreamWriter<UI_MESSAGE extends UIMessage = UIMessage> {
4214
4240
  declare function createUIMessageStream<UI_MESSAGE extends UIMessage>({ execute, onError, // prevent leaking server error details to the client by default
4215
4241
  originalMessages, onStepFinish, onFinish, generateId, }: {
4216
4242
  execute: (options: {
4217
- writer: UIMessageStreamWriter<UI_MESSAGE>;
4243
+ writer: UIMessageStreamWriterWithOutcome<UI_MESSAGE>;
4218
4244
  }) => Promise<void> | void;
4219
4245
  onError?: (error: unknown) => string;
4220
4246
  /**
@@ -4486,8 +4512,9 @@ interface EmbedManyResult {
4486
4512
  * Embed several values using an embedding model. The type of the value is defined
4487
4513
  * by the embedding model.
4488
4514
  *
4489
- * `embedMany` automatically splits large requests into smaller chunks if the model
4490
- * has a limit on how many embeddings can be generated in a single call.
4515
+ * `embedMany` automatically splits large requests into smaller chunks when the
4516
+ * model has a limit on either the number of embeddings or the UTF-8 input bytes
4517
+ * that can be processed in a single call.
4491
4518
  *
4492
4519
  * @param model - The embedding model to use.
4493
4520
  * @param values - The values that should be embedded.
@@ -6430,4 +6457,4 @@ declare function bindTelemetryIntegration(integration: TelemetryIntegration): Te
6430
6457
  */
6431
6458
  declare function registerTelemetryIntegration(integration: TelemetryIntegration): void;
6432
6459
 
6433
- export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatAddToolOutputFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextOnToolCallFinishCallback, GenerateTextOnToolCallStartCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolApprovalSignatureError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, OnFinishEvent, OnStartEvent, OnStepFinishEvent, OnStepStartEvent, OnToolCallFinishEvent, OnToolCallStartEvent, output as Output, Output as OutputInterface, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStartCallback, StreamTextOnStepFinishCallback, StreamTextOnStepStartCallback, StreamTextOnToolCallFinishCallback, StreamTextOnToolCallStartCallback, StreamTextResult, StreamTextTransform, TelemetryIntegration, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, bindTelemetryIntegration, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isDynamicToolUIPart, isFileUIPart, isLoopFinished, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, registerTelemetryIntegration, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
6460
+ export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatAddToolOutputFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextOnToolCallFinishCallback, GenerateTextOnToolCallStartCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolApprovalSignatureError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, OnFinishEvent, OnStartEvent, OnStepFinishEvent, OnStepStartEvent, OnToolCallFinishEvent, OnToolCallStartEvent, output as Output, Output as OutputInterface, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStartCallback, StreamTextOnStepFinishCallback, StreamTextOnStepStartCallback, StreamTextOnToolCallFinishCallback, StreamTextOnToolCallStartCallback, StreamTextResult, StreamTextTransform, TelemetryIntegration, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamOutcome, UIMessageStreamWriter, UIMessageStreamWriterWithOutcome, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, bindTelemetryIntegration, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isDynamicToolUIPart, isFileUIPart, isLoopFinished, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, registerTelemetryIntegration, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
package/dist/index.d.ts CHANGED
@@ -2113,6 +2113,24 @@ type UIMessageChunk<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataT
2113
2113
  };
2114
2114
  type InferUIMessageChunk<T extends UIMessage> = UIMessageChunk<InferUIMessageMetadata<T>, InferUIMessageData<T>>;
2115
2115
 
2116
+ /**
2117
+ * The operation-level outcome of a UI message stream.
2118
+ *
2119
+ * This is separate from model finish reasons and individual stream chunks.
2120
+ * Fatal stream-processing failures override outcomes declared by the stream
2121
+ * owner.
2122
+ */
2123
+ type UIMessageStreamOutcome = {
2124
+ status: 'completed';
2125
+ } | {
2126
+ status: 'failed';
2127
+ error?: unknown;
2128
+ } | {
2129
+ status: 'aborted';
2130
+ } | {
2131
+ status: 'unknown';
2132
+ };
2133
+
2116
2134
  type UIMessageStreamOnFinishCallback<UI_MESSAGE extends UIMessage> = (event: {
2117
2135
  /**
2118
2136
  * The updated list of UI messages.
@@ -2127,6 +2145,11 @@ type UIMessageStreamOnFinishCallback<UI_MESSAGE extends UIMessage> = (event: {
2127
2145
  * Indicates whether the stream was aborted.
2128
2146
  */
2129
2147
  isAborted: boolean;
2148
+ /**
2149
+ * The operation-level outcome of the stream. Fatal stream-processing
2150
+ * failures override outcomes declared by the stream owner.
2151
+ */
2152
+ outcome: UIMessageStreamOutcome;
2130
2153
  /**
2131
2154
  * The message that was sent to the client as a response
2132
2155
  * (including the original message if it was extended).
@@ -4148,12 +4171,7 @@ type SafeValidateUIMessagesResult<UI_MESSAGE extends UIMessage> = {
4148
4171
  success: false;
4149
4172
  error: Error;
4150
4173
  };
4151
- /**
4152
- * Validates a list of UI messages like `validateUIMessages`,
4153
- * but instead of throwing it returns `{ success: true, data }`
4154
- * or `{ success: false, error }`.
4155
- */
4156
- declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages, metadataSchema, dataSchemas, tools, }: {
4174
+ type ValidateUIMessagesOptions<UI_MESSAGE extends UIMessage> = {
4157
4175
  messages: unknown;
4158
4176
  metadataSchema?: FlexibleSchema<UIMessage['metadata']>;
4159
4177
  dataSchemas?: {
@@ -4162,7 +4180,13 @@ declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages
4162
4180
  tools?: {
4163
4181
  [NAME in keyof InferUIMessageTools<UI_MESSAGE> & string]?: Tool<InferUIMessageTools<UI_MESSAGE>[NAME]['input'], InferUIMessageTools<UI_MESSAGE>[NAME]['output']>;
4164
4182
  };
4165
- }): Promise<SafeValidateUIMessagesResult<UI_MESSAGE>>;
4183
+ };
4184
+ /**
4185
+ * Validates a list of UI messages like `validateUIMessages`,
4186
+ * but instead of throwing it returns `{ success: true, data }`
4187
+ * or `{ success: false, error }`.
4188
+ */
4189
+ declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>(options: ValidateUIMessagesOptions<UI_MESSAGE>): Promise<SafeValidateUIMessagesResult<UI_MESSAGE>>;
4166
4190
  /**
4167
4191
  * Validates a list of UI messages.
4168
4192
  *
@@ -4170,16 +4194,7 @@ declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages
4170
4194
  * the corresponding schemas are provided. Otherwise, they are assumed to be
4171
4195
  * valid.
4172
4196
  */
4173
- declare function validateUIMessages<UI_MESSAGE extends UIMessage>({ messages, metadataSchema, dataSchemas, tools, }: {
4174
- messages: unknown;
4175
- metadataSchema?: FlexibleSchema<UIMessage['metadata']>;
4176
- dataSchemas?: {
4177
- [NAME in keyof InferUIMessageData<UI_MESSAGE> & string]?: FlexibleSchema<InferUIMessageData<UI_MESSAGE>[NAME]>;
4178
- };
4179
- tools?: {
4180
- [NAME in keyof InferUIMessageTools<UI_MESSAGE> & string]?: Tool<InferUIMessageTools<UI_MESSAGE>[NAME]['input'], InferUIMessageTools<UI_MESSAGE>[NAME]['output']>;
4181
- };
4182
- }): Promise<Array<UI_MESSAGE>>;
4197
+ declare function validateUIMessages<UI_MESSAGE extends UIMessage>(options: ValidateUIMessagesOptions<UI_MESSAGE>): Promise<Array<UI_MESSAGE>>;
4183
4198
 
4184
4199
  interface UIMessageStreamWriter<UI_MESSAGE extends UIMessage = UIMessage> {
4185
4200
  /**
@@ -4197,6 +4212,17 @@ interface UIMessageStreamWriter<UI_MESSAGE extends UIMessage = UIMessage> {
4197
4212
  */
4198
4213
  onError: ErrorHandler | undefined;
4199
4214
  }
4215
+ interface UIMessageStreamWriterWithOutcome<UI_MESSAGE extends UIMessage = UIMessage> extends UIMessageStreamWriter<UI_MESSAGE> {
4216
+ /**
4217
+ * Declares the operation-level outcome of the composed stream.
4218
+ *
4219
+ * The first outcome declared through this method is retained. Fatal
4220
+ * execution, merge, error-handling, or downstream processing failures
4221
+ * override declared outcomes. Declaring an outcome does not write a chunk or
4222
+ * close the stream.
4223
+ */
4224
+ setOutcome(outcome: UIMessageStreamOutcome): void;
4225
+ }
4200
4226
 
4201
4227
  /**
4202
4228
  * Creates a UI message stream that can be used to send messages to the client.
@@ -4214,7 +4240,7 @@ interface UIMessageStreamWriter<UI_MESSAGE extends UIMessage = UIMessage> {
4214
4240
  declare function createUIMessageStream<UI_MESSAGE extends UIMessage>({ execute, onError, // prevent leaking server error details to the client by default
4215
4241
  originalMessages, onStepFinish, onFinish, generateId, }: {
4216
4242
  execute: (options: {
4217
- writer: UIMessageStreamWriter<UI_MESSAGE>;
4243
+ writer: UIMessageStreamWriterWithOutcome<UI_MESSAGE>;
4218
4244
  }) => Promise<void> | void;
4219
4245
  onError?: (error: unknown) => string;
4220
4246
  /**
@@ -4486,8 +4512,9 @@ interface EmbedManyResult {
4486
4512
  * Embed several values using an embedding model. The type of the value is defined
4487
4513
  * by the embedding model.
4488
4514
  *
4489
- * `embedMany` automatically splits large requests into smaller chunks if the model
4490
- * has a limit on how many embeddings can be generated in a single call.
4515
+ * `embedMany` automatically splits large requests into smaller chunks when the
4516
+ * model has a limit on either the number of embeddings or the UTF-8 input bytes
4517
+ * that can be processed in a single call.
4491
4518
  *
4492
4519
  * @param model - The embedding model to use.
4493
4520
  * @param values - The values that should be embedded.
@@ -6430,4 +6457,4 @@ declare function bindTelemetryIntegration(integration: TelemetryIntegration): Te
6430
6457
  */
6431
6458
  declare function registerTelemetryIntegration(integration: TelemetryIntegration): void;
6432
6459
 
6433
- export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatAddToolOutputFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextOnToolCallFinishCallback, GenerateTextOnToolCallStartCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolApprovalSignatureError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, OnFinishEvent, OnStartEvent, OnStepFinishEvent, OnStepStartEvent, OnToolCallFinishEvent, OnToolCallStartEvent, output as Output, Output as OutputInterface, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStartCallback, StreamTextOnStepFinishCallback, StreamTextOnStepStartCallback, StreamTextOnToolCallFinishCallback, StreamTextOnToolCallStartCallback, StreamTextResult, StreamTextTransform, TelemetryIntegration, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, bindTelemetryIntegration, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isDynamicToolUIPart, isFileUIPart, isLoopFinished, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, registerTelemetryIntegration, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
6460
+ export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatAddToolOutputFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextOnToolCallFinishCallback, GenerateTextOnToolCallStartCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolApprovalSignatureError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, OnFinishEvent, OnStartEvent, OnStepFinishEvent, OnStepStartEvent, OnToolCallFinishEvent, OnToolCallStartEvent, output as Output, Output as OutputInterface, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStartCallback, StreamTextOnStepFinishCallback, StreamTextOnStepStartCallback, StreamTextOnToolCallFinishCallback, StreamTextOnToolCallStartCallback, StreamTextResult, StreamTextTransform, TelemetryIntegration, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamOutcome, UIMessageStreamWriter, UIMessageStreamWriterWithOutcome, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, bindTelemetryIntegration, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isDynamicToolUIPart, isFileUIPart, isLoopFinished, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, registerTelemetryIntegration, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };