ai 7.0.83 → 7.0.84

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # ai
2
2
 
3
+ ## 7.0.84
4
+
5
+ ### Patch Changes
6
+
7
+ - 6669d69: Expose parsed structured output in `streamText` end callbacks.
8
+ - a6463ca: fix(ai): allow tool approval secrets in ToolLoopAgent settings and prepareCall
9
+ - e604532: fix(ai): handle stateful and empty-match regular expressions in smoothStream
10
+ - Updated dependencies [805bbfc]
11
+ - Updated dependencies [90192f1]
12
+ - @ai-sdk/gateway@4.0.68
13
+ - @ai-sdk/provider-utils@5.0.33
14
+
3
15
  ## 7.0.83
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1612,6 +1612,19 @@ type OnLanguageModelCallStartCallback = Callback<LanguageModelCallStartEvent>;
1612
1612
  */
1613
1613
  type OnLanguageModelCallEndCallback<TOOLS extends ToolSet = ToolSet> = Callback<LanguageModelCallEndEvent<TOOLS>>;
1614
1614
 
1615
+ /**
1616
+ * Infers the complete output type from the output specification.
1617
+ */
1618
+ type InferCompleteOutput<OUTPUT extends Output> = OUTPUT extends Output<infer COMPLETE_OUTPUT, any, any> ? COMPLETE_OUTPUT : never;
1619
+ /**
1620
+ * Infers the partial output type from the output specification.
1621
+ */
1622
+ type InferPartialOutput<OUTPUT extends Output> = OUTPUT extends Output<any, infer PARTIAL_OUTPUT, any> ? PARTIAL_OUTPUT : never;
1623
+ /**
1624
+ * Infers the element type from an array output specification.
1625
+ */
1626
+ type InferElementOutput<OUTPUT extends Output> = OUTPUT extends Output<any, any, infer ELEMENT> ? ELEMENT : never;
1627
+
1615
1628
  /**
1616
1629
  * Tool names that define the order in which tools are sent to the provider.
1617
1630
  *
@@ -2511,19 +2524,6 @@ type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
2511
2524
 
2512
2525
  type ErrorHandler = (error: unknown) => void;
2513
2526
 
2514
- /**
2515
- * Infers the complete output type from the output specification.
2516
- */
2517
- type InferCompleteOutput<OUTPUT extends Output> = OUTPUT extends Output<infer COMPLETE_OUTPUT, any, any> ? COMPLETE_OUTPUT : never;
2518
- /**
2519
- * Infers the partial output type from the output specification.
2520
- */
2521
- type InferPartialOutput<OUTPUT extends Output> = OUTPUT extends Output<any, infer PARTIAL_OUTPUT, any> ? PARTIAL_OUTPUT : never;
2522
- /**
2523
- * Infers the element type from an array output specification.
2524
- */
2525
- type InferElementOutput<OUTPUT extends Output> = OUTPUT extends Output<any, any, infer ELEMENT> ? ELEMENT : never;
2526
-
2527
2527
  /**
2528
2528
  * Tool output when the tool execution has been denied (for static tools).
2529
2529
  */
@@ -3356,6 +3356,14 @@ type StreamTextOnErrorCallback = Callback<{
3356
3356
  type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
3357
3357
  chunk: TextStreamPart<TOOLS>;
3358
3358
  }) => PromiseLike<void> | void;
3359
+ type StreamTextEndEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = GenerateTextEndEvent<TOOLS, RUNTIME_CONTEXT> & {
3360
+ /**
3361
+ * The parsed output when an output setting was provided and parsing
3362
+ * succeeded.
3363
+ */
3364
+ readonly output?: InferCompleteOutput<OUTPUT>;
3365
+ };
3366
+ type StreamTextOnEndCallback<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends Output = Output> = Callback<StreamTextEndEvent<TOOLS, RUNTIME_CONTEXT, OUTPUT>>;
3359
3367
  /**
3360
3368
  * Callback that is set using the `onAbort` option.
3361
3369
  *
@@ -3574,7 +3582,7 @@ declare function streamText<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Conte
3574
3582
  *
3575
3583
  * The usage is the combined usage of all steps.
3576
3584
  */
3577
- onEnd?: GenerateTextOnEndCallback<NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>>;
3585
+ onEnd?: StreamTextOnEndCallback<NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>, NoInfer<OUTPUT>>;
3578
3586
  /**
3579
3587
  * Callback that is called when the LLM response and all request tool executions
3580
3588
  * (for tools that have an `execute` function) are finished.
@@ -3583,7 +3591,7 @@ declare function streamText<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Conte
3583
3591
  *
3584
3592
  * @deprecated Use `onEnd` instead.
3585
3593
  */
3586
- onFinish?: GenerateTextOnEndCallback<NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>>;
3594
+ onFinish?: StreamTextOnEndCallback<NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>, NoInfer<OUTPUT>>;
3587
3595
  onAbort?: StreamTextOnAbortCallback<NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>>;
3588
3596
  /**
3589
3597
  * Callback that is called when each step (LLM call) ends, including intermediate steps.
@@ -5058,6 +5066,12 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, RUN
5058
5066
  * Configures which caller tools may invoke each tool.
5059
5067
  */
5060
5068
  experimental_toolCallers?: Experimental_ToolCallers<NoInfer<TOOLS>>;
5069
+ /**
5070
+ * Secret for HMAC-signing tool approval requests. When set, the server
5071
+ * signs each approval request at issuance and verifies the signature when
5072
+ * the approval is replayed, preventing client-forged approvals.
5073
+ */
5074
+ experimental_toolApprovalSecret?: string | Uint8Array;
5061
5075
  /**
5062
5076
  * Optional function that you can use to provide different settings for a step.
5063
5077
  */
@@ -5174,9 +5188,9 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, RUN
5174
5188
  * }),
5175
5189
  * ```
5176
5190
  */
5177
- prepareCall?: (options: Omit<AgentCallParameters<CALL_OPTIONS, NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>>, 'abortSignal' | 'timeout' | 'onStart' | 'experimental_onStart' | 'onStepStart' | 'experimental_onStepStart' | 'onToolExecutionStart' | 'onToolExecutionEnd' | 'onStepEnd' | 'onStepFinish' | 'onEnd' | 'onFinish'> & Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, RUNTIME_CONTEXT, NoInfer<OUTPUT>>, 'model' | 'tools' | 'toolChoice' | 'maxRetries' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'reasoning' | 'headers' | 'instructions' | 'allowSystemInMessages' | 'stopWhen' | 'telemetry' | 'experimental_telemetry' | 'activeTools' | 'toolOrder' | 'toolApproval' | 'experimental_toolCallers' | 'prepareStep' | 'repairToolCall' | 'experimental_repairToolCall' | 'providerOptions' | 'experimental_download' | 'experimental_refineToolInput' | 'include' | 'runtimeContext' | '_internal'> & {
5191
+ prepareCall?: (options: Omit<AgentCallParameters<CALL_OPTIONS, NoInfer<TOOLS>, NoInfer<RUNTIME_CONTEXT>>, 'abortSignal' | 'timeout' | 'onStart' | 'experimental_onStart' | 'onStepStart' | 'experimental_onStepStart' | 'onToolExecutionStart' | 'onToolExecutionEnd' | 'onStepEnd' | 'onStepFinish' | 'onEnd' | 'onFinish'> & Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, RUNTIME_CONTEXT, NoInfer<OUTPUT>>, 'model' | 'tools' | 'toolChoice' | 'maxRetries' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'reasoning' | 'headers' | 'instructions' | 'allowSystemInMessages' | 'stopWhen' | 'telemetry' | 'experimental_telemetry' | 'activeTools' | 'toolOrder' | 'toolApproval' | 'experimental_toolCallers' | 'experimental_toolApprovalSecret' | 'prepareStep' | 'repairToolCall' | 'experimental_repairToolCall' | 'providerOptions' | 'experimental_download' | 'experimental_refineToolInput' | 'include' | 'runtimeContext' | '_internal'> & {
5178
5192
  toolsContext: InferToolSetContext<TOOLS>;
5179
- }) => MaybePromiseLike<Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, RUNTIME_CONTEXT, NoInfer<OUTPUT>>, 'model' | 'tools' | 'toolChoice' | 'maxRetries' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'reasoning' | 'headers' | 'instructions' | 'allowSystemInMessages' | 'stopWhen' | 'telemetry' | 'experimental_telemetry' | 'activeTools' | 'toolOrder' | 'toolApproval' | 'experimental_toolCallers' | 'prepareStep' | 'repairToolCall' | 'experimental_repairToolCall' | 'providerOptions' | 'experimental_download' | 'experimental_refineToolInput' | 'include' | 'runtimeContext' | '_internal'> & Omit<Prompt, 'system'> & {
5193
+ }) => MaybePromiseLike<Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, RUNTIME_CONTEXT, NoInfer<OUTPUT>>, 'model' | 'tools' | 'toolChoice' | 'maxRetries' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'reasoning' | 'headers' | 'instructions' | 'allowSystemInMessages' | 'stopWhen' | 'telemetry' | 'experimental_telemetry' | 'activeTools' | 'toolOrder' | 'toolApproval' | 'experimental_toolCallers' | 'experimental_toolApprovalSecret' | 'prepareStep' | 'repairToolCall' | 'experimental_repairToolCall' | 'providerOptions' | 'experimental_download' | 'experimental_refineToolInput' | 'include' | 'runtimeContext' | '_internal'> & Omit<Prompt, 'system'> & {
5180
5194
  toolsContext: InferToolSetContext<TOOLS>;
5181
5195
  }>;
5182
5196
  };
@@ -7127,7 +7141,7 @@ type ChunkDetector = (buffer: string) => string | undefined | null;
7127
7141
  * Smooths text and reasoning streaming output.
7128
7142
  *
7129
7143
  * @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
7130
- * @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, provide a custom RegExp pattern for custom chunking, provide an Intl.Segmenter for locale-aware word segmentation (recommended for CJK languages), or provide a custom ChunkDetector function.
7144
+ * @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, provide a custom RegExp pattern that does not match the empty string for custom chunking, provide an Intl.Segmenter for locale-aware word segmentation (recommended for CJK languages), or provide a custom ChunkDetector function.
7131
7145
  *
7132
7146
  * @returns A transform stream that smooths text streaming output.
7133
7147
  */
@@ -9531,4 +9545,4 @@ declare function uploadSkill({ api, files, displayTitle, providerOptions, }: {
9531
9545
  files: UploadSkillFile[];
9532
9546
  }): Promise<UploadSkillResult>;
9533
9547
 
9534
- export { AI_SDK_TELEMETRY_TRACING_CHANNEL, AbstractChat, ActiveTools, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatAddToolOutputFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, CustomContentUIPart, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedEndEvent, EmbedManyResult, EmbedResult, EmbedStartEvent, Embedding, EmbeddingModel, EmbeddingModelCallEndEvent, EmbeddingModelCallStartEvent, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, AbstractRealtimeSession as Experimental_AbstractRealtimeSession, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, BatchError as Experimental_BatchError, BatchLanguageModel as Experimental_BatchLanguageModel, BatchOperationOptions as Experimental_BatchOperationOptions, BatchReference as Experimental_BatchReference, BatchStatus as Experimental_BatchStatus, DownloadFunction as Experimental_DownloadFunction, Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LanguageModelStreamPart as Experimental_LanguageModelStreamPart, LogWarningsFunction as Experimental_LogWarningsFunction, RealtimeClientEvent as Experimental_RealtimeClientEvent, RealtimeFactory as Experimental_RealtimeFactory, RealtimeFactoryGetTokenOptions as Experimental_RealtimeFactoryGetTokenOptions, RealtimeFactoryGetTokenResult as Experimental_RealtimeFactoryGetTokenResult, RealtimeModel as Experimental_RealtimeModel, RealtimeServerEvent as Experimental_RealtimeServerEvent, RealtimeSessionConfig as Experimental_RealtimeSessionConfig, RealtimeSessionOptions as Experimental_RealtimeSessionOptions, RealtimeSetupResponse as Experimental_RealtimeSetupResponse, RealtimeState as Experimental_RealtimeState, RealtimeStatus as Experimental_RealtimeStatus, RealtimeToolDefinition as Experimental_RealtimeToolDefinition, Experimental_SpeechResult, StartTextBatchOptions as Experimental_StartTextBatchOptions, StartTextBatchResult as Experimental_StartTextBatchResult, StreamTranslationResult as Experimental_StreamTranslationResult, TextBatch as Experimental_TextBatch, TextBatchGenerationResult as Experimental_TextBatchGenerationResult, TextBatchItemResult as Experimental_TextBatchItemResult, TextBatchReference as Experimental_TextBatchReference, TextBatchRequest as Experimental_TextBatchRequest, Experimental_ToolCallers, Experimental_TranscriptionResult, TranslationStreamPart as Experimental_TranslationStreamPart, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectEndEvent, GenerateObjectResult, GenerateObjectStartEvent, GenerateObjectStepEndEvent, GenerateObjectStepStartEvent, GenerateTextAbortEvent, GenerateTextEndEvent, GenerateTextInclude, GenerateTextOnAbortCallback, GenerateTextOnEndCallback, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepEndCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextResult, GenerateTextStartEvent, GenerateTextStepEndEvent, GenerateTextStepStartEvent, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, GenericToolApprovalFunction, GetVideoStatusResult, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferTelemetryEvent, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, Instructions, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolApprovalSignatureError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelCallEndEvent, LanguageModelCallOptions, LanguageModelCallStartEvent, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, ModelInfo, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoTranslationGeneratedError, NoVideoGeneratedError, ObjectStreamPart, OnFinishEvent, OnLanguageModelCallEndCallback, OnLanguageModelCallStartCallback, OnStartEvent, OnStepFinishEvent, OnStepStartEvent, OnToolCallFinishEvent, OnToolCallStartEvent, OnToolExecutionEndCallback, OnToolExecutionStartCallback, output as Output, OutputChunkTimingStats, Output as OutputInterface, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderReference, ProviderRegistryProvider, ReasoningFileOutput, ReasoningFileUIPart, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RequestOptions, RerankEndEvent, RerankResult, RerankStartEvent, RerankingModel, RerankingModelCallEndEvent, RerankingModelCallStartEvent, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SingleToolApprovalFunction, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechResult, StartVideoResult, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepResultPerformance, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamProviderError, StreamTextInclude, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextResult, StreamTextTransform, StreamTranscriptionResult, Telemetry, TelemetryOptions, TelemetryTracingChannelMessage, TelemetryTracingEventType, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToUIMessageChunkOptions, ToolApprovalConfiguration, ToolApprovalRequestOutput, ToolApprovalResponseOutput, ToolApprovalStatus, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolExecutionEndEvent, ToolExecutionStartEvent, ToolInputRefinement, ToolLoopAgent, ToolLoopAgentSettings, ToolOrder, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionResult, TranscriptionStreamPart, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnEndCallback, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepEndCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamOutcome, UIMessageStreamWriter, UIMessageStreamWriterWithOutcome, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UploadFileResult, UploadSkillResult, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertDataContentToBase64String, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultInstructionsMiddleware, defaultSettingsMiddleware, detectToolDrift, embed, embedMany, experimental_createProviderRegistry, decodeRealtimeAudio as experimental_decodeRealtimeAudio, encodeRealtimeAudio as experimental_encodeRealtimeAudio, filterActiveTools as experimental_filterActiveTools, experimental_generateSpeech, experimental_generateVideo, getBatchResults as experimental_getBatchResults, getBatchStatus as experimental_getBatchStatus, getRealtimeToolDefinitions as experimental_getRealtimeToolDefinitions, experimental_getVideoStatus, resampleAudio as experimental_resampleAudio, startTextBatch as experimental_startTextBatch, experimental_startVideo, streamLanguageModelCall as experimental_streamLanguageModelCall, streamTranscribe as experimental_streamTranscribe, streamTranslate as experimental_streamTranslate, experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, fingerprintTools, generateImage, generateObject, generateSpeech, generateText, getChunkTimeoutMs, getFirstChunkTimeoutMs, getStaticToolName, getStepTimeoutMs, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, getToolTimeoutMs, getTotalTimeoutMs, hasToolCall, isCustomContentUIPart, isDataUIPart, isDeepEqualData, isDynamicToolUIPart, isFileUIPart, isLoopFinished, isReasoningFileUIPart, isReasoningUIPart, isStaticToolUIPart, isStepCount, isTextUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, registerTelemetry, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, isStepCount as stepCountIs, streamObject, streamText, systemModelMessageSchema, toTextStream, toUIMessageChunk, toUIMessageStream, toolModelMessageSchema, transcribe, uiMessageChunkSchema, uploadFile, uploadSkill, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
9548
+ export { AI_SDK_TELEMETRY_TRACING_CHANNEL, AbstractChat, ActiveTools, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatAddToolOutputFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, CustomContentUIPart, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedEndEvent, EmbedManyResult, EmbedResult, EmbedStartEvent, Embedding, EmbeddingModel, EmbeddingModelCallEndEvent, EmbeddingModelCallStartEvent, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, AbstractRealtimeSession as Experimental_AbstractRealtimeSession, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, BatchError as Experimental_BatchError, BatchLanguageModel as Experimental_BatchLanguageModel, BatchOperationOptions as Experimental_BatchOperationOptions, BatchReference as Experimental_BatchReference, BatchStatus as Experimental_BatchStatus, DownloadFunction as Experimental_DownloadFunction, Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LanguageModelStreamPart as Experimental_LanguageModelStreamPart, LogWarningsFunction as Experimental_LogWarningsFunction, RealtimeClientEvent as Experimental_RealtimeClientEvent, RealtimeFactory as Experimental_RealtimeFactory, RealtimeFactoryGetTokenOptions as Experimental_RealtimeFactoryGetTokenOptions, RealtimeFactoryGetTokenResult as Experimental_RealtimeFactoryGetTokenResult, RealtimeModel as Experimental_RealtimeModel, RealtimeServerEvent as Experimental_RealtimeServerEvent, RealtimeSessionConfig as Experimental_RealtimeSessionConfig, RealtimeSessionOptions as Experimental_RealtimeSessionOptions, RealtimeSetupResponse as Experimental_RealtimeSetupResponse, RealtimeState as Experimental_RealtimeState, RealtimeStatus as Experimental_RealtimeStatus, RealtimeToolDefinition as Experimental_RealtimeToolDefinition, Experimental_SpeechResult, StartTextBatchOptions as Experimental_StartTextBatchOptions, StartTextBatchResult as Experimental_StartTextBatchResult, StreamTranslationResult as Experimental_StreamTranslationResult, TextBatch as Experimental_TextBatch, TextBatchGenerationResult as Experimental_TextBatchGenerationResult, TextBatchItemResult as Experimental_TextBatchItemResult, TextBatchReference as Experimental_TextBatchReference, TextBatchRequest as Experimental_TextBatchRequest, Experimental_ToolCallers, Experimental_TranscriptionResult, TranslationStreamPart as Experimental_TranslationStreamPart, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectEndEvent, GenerateObjectResult, GenerateObjectStartEvent, GenerateObjectStepEndEvent, GenerateObjectStepStartEvent, GenerateTextAbortEvent, GenerateTextEndEvent, GenerateTextInclude, GenerateTextOnAbortCallback, GenerateTextOnEndCallback, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepEndCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextResult, GenerateTextStartEvent, GenerateTextStepEndEvent, GenerateTextStepStartEvent, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, GenericToolApprovalFunction, GetVideoStatusResult, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferTelemetryEvent, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, Instructions, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolApprovalSignatureError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelCallEndEvent, LanguageModelCallOptions, LanguageModelCallStartEvent, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, ModelInfo, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoTranslationGeneratedError, NoVideoGeneratedError, ObjectStreamPart, OnFinishEvent, OnLanguageModelCallEndCallback, OnLanguageModelCallStartCallback, OnStartEvent, OnStepFinishEvent, OnStepStartEvent, OnToolCallFinishEvent, OnToolCallStartEvent, OnToolExecutionEndCallback, OnToolExecutionStartCallback, output as Output, OutputChunkTimingStats, Output as OutputInterface, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderReference, ProviderRegistryProvider, ReasoningFileOutput, ReasoningFileUIPart, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RequestOptions, RerankEndEvent, RerankResult, RerankStartEvent, RerankingModel, RerankingModelCallEndEvent, RerankingModelCallStartEvent, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SingleToolApprovalFunction, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechResult, StartVideoResult, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepResultPerformance, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamProviderError, StreamTextEndEvent, StreamTextInclude, StreamTextOnChunkCallback, StreamTextOnEndCallback, StreamTextOnErrorCallback, StreamTextResult, StreamTextTransform, StreamTranscriptionResult, Telemetry, TelemetryOptions, TelemetryTracingChannelMessage, TelemetryTracingEventType, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToUIMessageChunkOptions, ToolApprovalConfiguration, ToolApprovalRequestOutput, ToolApprovalResponseOutput, ToolApprovalStatus, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolExecutionEndEvent, ToolExecutionStartEvent, ToolInputRefinement, ToolLoopAgent, ToolLoopAgentSettings, ToolOrder, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionResult, TranscriptionStreamPart, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnEndCallback, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepEndCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamOutcome, UIMessageStreamWriter, UIMessageStreamWriterWithOutcome, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UploadFileResult, UploadSkillResult, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertDataContentToBase64String, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultInstructionsMiddleware, defaultSettingsMiddleware, detectToolDrift, embed, embedMany, experimental_createProviderRegistry, decodeRealtimeAudio as experimental_decodeRealtimeAudio, encodeRealtimeAudio as experimental_encodeRealtimeAudio, filterActiveTools as experimental_filterActiveTools, experimental_generateSpeech, experimental_generateVideo, getBatchResults as experimental_getBatchResults, getBatchStatus as experimental_getBatchStatus, getRealtimeToolDefinitions as experimental_getRealtimeToolDefinitions, experimental_getVideoStatus, resampleAudio as experimental_resampleAudio, startTextBatch as experimental_startTextBatch, experimental_startVideo, streamLanguageModelCall as experimental_streamLanguageModelCall, streamTranscribe as experimental_streamTranscribe, streamTranslate as experimental_streamTranslate, experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, fingerprintTools, generateImage, generateObject, generateSpeech, generateText, getChunkTimeoutMs, getFirstChunkTimeoutMs, getStaticToolName, getStepTimeoutMs, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, getToolTimeoutMs, getTotalTimeoutMs, hasToolCall, isCustomContentUIPart, isDataUIPart, isDeepEqualData, isDynamicToolUIPart, isFileUIPart, isLoopFinished, isReasoningFileUIPart, isReasoningUIPart, isStaticToolUIPart, isStepCount, isTextUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, registerTelemetry, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, isStepCount as stepCountIs, streamObject, streamText, systemModelMessageSchema, toTextStream, toUIMessageChunk, toUIMessageStream, toolModelMessageSchema, transcribe, uiMessageChunkSchema, uploadFile, uploadSkill, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
package/dist/index.js CHANGED
@@ -1179,7 +1179,7 @@ import {
1179
1179
  } from "@ai-sdk/provider-utils";
1180
1180
 
1181
1181
  // src/version.ts
1182
- var VERSION = true ? "7.0.83" : "0.0.0-test";
1182
+ var VERSION = true ? "7.0.84" : "0.0.0-test";
1183
1183
 
1184
1184
  // src/util/download/download.ts
1185
1185
  var download = async ({
@@ -9612,42 +9612,56 @@ var DefaultStreamTextResult = class {
9612
9612
  var _a24;
9613
9613
  return (_a24 = step.warnings) != null ? _a24 : [];
9614
9614
  });
9615
- await notify({
9616
- event: {
9617
- callId,
9618
- toolsContext: finalStep.toolsContext,
9619
- stepNumber: finalStep.stepNumber,
9620
- model: finalStep.model,
9621
- runtimeContext: finalStep.runtimeContext,
9622
- finishReason: finalStep.finishReason,
9623
- rawFinishReason: finalStep.rawFinishReason,
9624
- usage: totalUsage,
9625
- totalUsage,
9626
- content,
9627
- text: finalStep.text,
9628
- reasoning: finalStep.reasoning,
9629
- reasoningText: finalStep.reasoningText,
9630
- files,
9631
- sources,
9632
- toolCalls,
9633
- staticToolCalls,
9634
- dynamicToolCalls,
9635
- toolResults,
9636
- staticToolResults,
9637
- dynamicToolResults,
9638
- responseMessages: [
9639
- ...initialResponseMessages,
9640
- ...recordedSteps.flatMap((step) => step.response.messages)
9641
- ],
9642
- warnings,
9643
- request: finalStep.request,
9644
- response: finalStep.response,
9645
- providerMetadata: finalStep.providerMetadata,
9646
- steps: recordedSteps,
9647
- finalStep
9648
- },
9649
- callbacks: [onEnd, telemetryDispatcher.onEnd]
9650
- });
9615
+ const onEndWithOutput = onEnd == null ? void 0 : async (event) => {
9616
+ const parsedOutput = output == null ? void 0 : await self.getOutputPromise().catch(() => void 0);
9617
+ await onEnd({
9618
+ ...event,
9619
+ ...output != null ? { output: parsedOutput } : {}
9620
+ });
9621
+ };
9622
+ const onEndEvent = {
9623
+ callId,
9624
+ toolsContext: finalStep.toolsContext,
9625
+ stepNumber: finalStep.stepNumber,
9626
+ model: finalStep.model,
9627
+ runtimeContext: finalStep.runtimeContext,
9628
+ finishReason: finalStep.finishReason,
9629
+ rawFinishReason: finalStep.rawFinishReason,
9630
+ usage: totalUsage,
9631
+ totalUsage,
9632
+ content,
9633
+ text: finalStep.text,
9634
+ reasoning: finalStep.reasoning,
9635
+ reasoningText: finalStep.reasoningText,
9636
+ files,
9637
+ sources,
9638
+ toolCalls,
9639
+ staticToolCalls,
9640
+ dynamicToolCalls,
9641
+ toolResults,
9642
+ staticToolResults,
9643
+ dynamicToolResults,
9644
+ responseMessages: [
9645
+ ...initialResponseMessages,
9646
+ ...recordedSteps.flatMap((step) => step.response.messages)
9647
+ ],
9648
+ warnings,
9649
+ request: finalStep.request,
9650
+ response: finalStep.response,
9651
+ providerMetadata: finalStep.providerMetadata,
9652
+ steps: recordedSteps,
9653
+ finalStep
9654
+ };
9655
+ await Promise.all([
9656
+ notify({
9657
+ event: onEndEvent,
9658
+ callbacks: onEndWithOutput
9659
+ }),
9660
+ notify({
9661
+ event: onEndEvent,
9662
+ callbacks: telemetryDispatcher.onEnd
9663
+ })
9664
+ ]);
9651
9665
  } catch (error) {
9652
9666
  controller.error(error);
9653
9667
  }
@@ -10666,19 +10680,25 @@ var DefaultStreamTextResult = class {
10666
10680
  }
10667
10681
  return createAsyncIterableStream(this.teeStream().pipeThrough(transform));
10668
10682
  }
10683
+ getOutputPromise() {
10684
+ if (this.outputPromise == null) {
10685
+ this.outputPromise = this.finalStep.then((step) => {
10686
+ var _a24;
10687
+ const output = (_a24 = this.outputSpecification) != null ? _a24 : text();
10688
+ return output.parseCompleteOutput(
10689
+ { text: step.text },
10690
+ {
10691
+ response: step.response,
10692
+ usage: step.usage,
10693
+ finishReason: step.finishReason
10694
+ }
10695
+ );
10696
+ });
10697
+ }
10698
+ return this.outputPromise;
10699
+ }
10669
10700
  get output() {
10670
- return this.finalStep.then((step) => {
10671
- var _a24;
10672
- const output = (_a24 = this.outputSpecification) != null ? _a24 : text();
10673
- return output.parseCompleteOutput(
10674
- { text: step.text },
10675
- {
10676
- response: step.response,
10677
- usage: step.usage,
10678
- finishReason: step.finishReason
10679
- }
10680
- );
10681
- });
10701
+ return this.getOutputPromise();
10682
10702
  }
10683
10703
  toUIMessageStream({
10684
10704
  originalMessages,
@@ -14680,11 +14700,21 @@ function smoothStream({
14680
14700
  });
14681
14701
  }
14682
14702
  detectChunk = (buffer) => {
14683
- const match = chunkingRegex.exec(buffer);
14703
+ const lastIndex = chunkingRegex.lastIndex;
14704
+ chunkingRegex.lastIndex = 0;
14705
+ let match;
14706
+ try {
14707
+ match = chunkingRegex.exec(buffer);
14708
+ } finally {
14709
+ chunkingRegex.lastIndex = lastIndex;
14710
+ }
14684
14711
  if (!match) {
14685
14712
  return null;
14686
14713
  }
14687
- return buffer.slice(0, match.index) + (match == null ? void 0 : match[0]);
14714
+ if (!match[0].length) {
14715
+ throw new Error(`Chunking RegExp must not match an empty string.`);
14716
+ }
14717
+ return buffer.slice(0, match.index) + match[0];
14688
14718
  };
14689
14719
  }
14690
14720
  return () => {