ai 5.0.0-beta.25 → 5.0.0-beta.27
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 +23 -0
- package/dist/bin/ai.min.js +74 -12
- package/dist/index.d.mts +44 -18
- package/dist/index.d.ts +44 -18
- package/dist/index.js +104 -122
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +103 -122
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/bin/ai.js +0 -4736
- package/dist/bin/ai.js.map +0 -1
package/dist/index.d.mts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ModelMessage, Tool, InferToolInput, InferToolOutput, AssistantModelMessage, ToolModelMessage, ReasoningPart, Schema, SystemModelMessage, UserModelMessage, ProviderOptions, IdGenerator, InferSchema, FlexibleSchema, DataContent, Validator, StandardSchemaV1,
|
1
|
+
import { ModelMessage, Tool, InferToolInput, InferToolOutput, AssistantModelMessage, ToolModelMessage, ReasoningPart, Schema, SystemModelMessage, UserModelMessage, ProviderOptions, IdGenerator, ToolCall, InferSchema, FlexibleSchema, DataContent, Validator, StandardSchemaV1, Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
2
2
|
export { AssistantContent, AssistantModelMessage, DataContent, FilePart, IdGenerator, ImagePart, InferToolInput, InferToolOutput, ModelMessage, Schema, SystemModelMessage, TextPart, Tool, ToolCallOptions, ToolCallPart, ToolContent, ToolExecuteFunction, ToolModelMessage, ToolResultPart, UserContent, UserModelMessage, asSchema, createIdGenerator, generateId, jsonSchema, tool } from '@ai-sdk/provider-utils';
|
3
3
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
4
4
|
import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SpeechModelV2, SpeechModelV2CallWarning, TranscriptionModelV2, TranscriptionModelV2CallWarning, LanguageModelV2Usage, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError, JSONObject } from '@ai-sdk/provider';
|
@@ -1018,7 +1018,7 @@ Callback that is set using the `onChunk` option.
|
|
1018
1018
|
*/
|
1019
1019
|
type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
|
1020
1020
|
chunk: Extract<TextStreamPart<TOOLS>, {
|
1021
|
-
type: 'text' | 'reasoning' | 'source' | 'tool-call' | 'tool-input-start' | 'tool-input-delta' | 'tool-result' | 'raw';
|
1021
|
+
type: 'text-delta' | 'reasoning-delta' | 'source' | 'tool-call' | 'tool-input-start' | 'tool-input-delta' | 'tool-result' | 'raw';
|
1022
1022
|
}>;
|
1023
1023
|
}) => PromiseLike<void> | void;
|
1024
1024
|
/**
|
@@ -1383,6 +1383,12 @@ declare function isToolUIPart<TOOLS extends UITools>(part: UIMessagePart<UIDataT
|
|
1383
1383
|
declare function getToolName<TOOLS extends UITools>(part: ToolUIPart<TOOLS>): keyof TOOLS;
|
1384
1384
|
type InferUIMessageMetadata<T extends UIMessage> = T extends UIMessage<infer METADATA> ? METADATA : unknown;
|
1385
1385
|
type InferUIMessageData<T extends UIMessage> = T extends UIMessage<unknown, infer DATA_TYPES> ? DATA_TYPES : UIDataTypes;
|
1386
|
+
type InferUIMessageTools<T extends UIMessage> = T extends UIMessage<unknown, UIDataTypes, infer TOOLS> ? TOOLS : UITools;
|
1387
|
+
type InferUIMessageToolCall<UI_MESSAGE extends UIMessage> = ValueOf<{
|
1388
|
+
[NAME in keyof InferUIMessageTools<UI_MESSAGE>]: ToolCall<NAME & string, InferUIMessageTools<UI_MESSAGE>[NAME] extends {
|
1389
|
+
input: infer INPUT;
|
1390
|
+
} ? INPUT : never>;
|
1391
|
+
}>;
|
1386
1392
|
|
1387
1393
|
type DataUIMessageChunk<DATA_TYPES extends UIDataTypes> = ValueOf<{
|
1388
1394
|
[NAME in keyof DATA_TYPES & string]: {
|
@@ -1767,7 +1773,7 @@ type TextStreamPart<TOOLS extends ToolSet> = {
|
|
1767
1773
|
id: string;
|
1768
1774
|
providerMetadata?: ProviderMetadata;
|
1769
1775
|
} | {
|
1770
|
-
type: 'text';
|
1776
|
+
type: 'text-delta';
|
1771
1777
|
id: string;
|
1772
1778
|
providerMetadata?: ProviderMetadata;
|
1773
1779
|
text: string;
|
@@ -1780,7 +1786,7 @@ type TextStreamPart<TOOLS extends ToolSet> = {
|
|
1780
1786
|
id: string;
|
1781
1787
|
providerMetadata?: ProviderMetadata;
|
1782
1788
|
} | {
|
1783
|
-
type: 'reasoning';
|
1789
|
+
type: 'reasoning-delta';
|
1784
1790
|
providerMetadata?: ProviderMetadata;
|
1785
1791
|
id: string;
|
1786
1792
|
text: string;
|
@@ -3647,13 +3653,17 @@ declare function pipeUIMessageStreamToResponse({ response, status, statusText, h
|
|
3647
3653
|
*
|
3648
3654
|
* @param options.message - The last assistant message to use as a starting point when the conversation is resumed. Otherwise undefined.
|
3649
3655
|
* @param options.stream - The stream of `UIMessageChunk`s to read.
|
3656
|
+
* @param options.terminateOnError - Whether to terminate the stream if an error occurs.
|
3657
|
+
* @param options.onError - A function that is called when an error occurs.
|
3650
3658
|
*
|
3651
3659
|
* @returns An `AsyncIterableStream` of `UIMessage`s. Each stream part is a different state of the same message
|
3652
3660
|
* as it is being completed.
|
3653
3661
|
*/
|
3654
|
-
declare function readUIMessageStream<UI_MESSAGE extends UIMessage>({ message, stream, }: {
|
3662
|
+
declare function readUIMessageStream<UI_MESSAGE extends UIMessage>({ message, stream, onError, terminateOnError, }: {
|
3655
3663
|
message?: UI_MESSAGE;
|
3656
3664
|
stream: ReadableStream<UIMessageChunk>;
|
3665
|
+
onError?: (error: unknown) => void;
|
3666
|
+
terminateOnError?: boolean;
|
3657
3667
|
}): AsyncIterableStream<UI_MESSAGE>;
|
3658
3668
|
|
3659
3669
|
declare const UI_MESSAGE_STREAM_HEADERS: {
|
@@ -3670,7 +3680,7 @@ interface ChatTransport<UI_MESSAGE extends UIMessage> {
|
|
3670
3680
|
messages: UI_MESSAGE[];
|
3671
3681
|
abortSignal: AbortSignal | undefined;
|
3672
3682
|
} & {
|
3673
|
-
trigger: 'submit-
|
3683
|
+
trigger: 'submit-message' | 'regenerate-message';
|
3674
3684
|
messageId: string | undefined;
|
3675
3685
|
} & ChatRequestOptions) => Promise<ReadableStream<UIMessageChunk>>;
|
3676
3686
|
reconnectToStream: (options: {
|
@@ -3711,9 +3721,9 @@ interface ChatState<UI_MESSAGE extends UIMessage> {
|
|
3711
3721
|
snapshot: <T>(thing: T) => T;
|
3712
3722
|
}
|
3713
3723
|
type ChatOnErrorCallback = (error: Error) => void;
|
3714
|
-
type ChatOnToolCallCallback =
|
3715
|
-
toolCall:
|
3716
|
-
}) => void |
|
3724
|
+
type ChatOnToolCallCallback<UI_MESSAGE extends UIMessage = UIMessage> = (options: {
|
3725
|
+
toolCall: InferUIMessageToolCall<UI_MESSAGE>;
|
3726
|
+
}) => void | PromiseLike<void>;
|
3717
3727
|
type ChatOnDataCallback<UI_MESSAGE extends UIMessage> = (dataPart: DataUIPart<InferUIMessageData<UI_MESSAGE>>) => void;
|
3718
3728
|
type ChatOnFinishCallback<UI_MESSAGE extends UIMessage> = (options: {
|
3719
3729
|
message: UI_MESSAGE;
|
@@ -3733,7 +3743,6 @@ interface ChatInit<UI_MESSAGE extends UIMessage> {
|
|
3733
3743
|
*/
|
3734
3744
|
generateId?: IdGenerator;
|
3735
3745
|
transport?: ChatTransport<UI_MESSAGE>;
|
3736
|
-
maxSteps?: number;
|
3737
3746
|
/**
|
3738
3747
|
* Callback function to be called when an error is encountered.
|
3739
3748
|
*/
|
@@ -3745,7 +3754,7 @@ interface ChatInit<UI_MESSAGE extends UIMessage> {
|
|
3745
3754
|
You can optionally return a result for the tool call,
|
3746
3755
|
either synchronously or asynchronously.
|
3747
3756
|
*/
|
3748
|
-
onToolCall?: ChatOnToolCallCallback
|
3757
|
+
onToolCall?: ChatOnToolCallCallback<UI_MESSAGE>;
|
3749
3758
|
/**
|
3750
3759
|
* Optional callback function that is called when the assistant message is finished streaming.
|
3751
3760
|
*
|
@@ -3758,6 +3767,13 @@ interface ChatInit<UI_MESSAGE extends UIMessage> {
|
|
3758
3767
|
* @param data The data part that was received.
|
3759
3768
|
*/
|
3760
3769
|
onData?: ChatOnDataCallback<UI_MESSAGE>;
|
3770
|
+
/**
|
3771
|
+
* When provided, this function will be called when the stream is finished or a tool call is added
|
3772
|
+
* to determine if the current messages should be resubmitted.
|
3773
|
+
*/
|
3774
|
+
sendAutomaticallyWhen?: (options: {
|
3775
|
+
messages: UI_MESSAGE[];
|
3776
|
+
}) => boolean | PromiseLike<boolean>;
|
3761
3777
|
}
|
3762
3778
|
declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
3763
3779
|
readonly id: string;
|
@@ -3766,14 +3782,14 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
|
3766
3782
|
private messageMetadataSchema;
|
3767
3783
|
private dataPartSchemas;
|
3768
3784
|
private readonly transport;
|
3769
|
-
private maxSteps;
|
3770
3785
|
private onError?;
|
3771
3786
|
private onToolCall?;
|
3772
3787
|
private onFinish?;
|
3773
3788
|
private onData?;
|
3789
|
+
private sendAutomaticallyWhen?;
|
3774
3790
|
private activeResponse;
|
3775
3791
|
private jobExecutor;
|
3776
|
-
constructor({ generateId, id, transport,
|
3792
|
+
constructor({ generateId, id, transport, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, onData, sendAutomaticallyWhen, }: Omit<ChatInit<UI_MESSAGE>, 'messages'> & {
|
3777
3793
|
state: ChatState<UI_MESSAGE>;
|
3778
3794
|
});
|
3779
3795
|
/**
|
@@ -3799,7 +3815,7 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
|
3799
3815
|
*
|
3800
3816
|
* If a messageId is provided, the message will be replaced.
|
3801
3817
|
*/
|
3802
|
-
sendMessage: (message
|
3818
|
+
sendMessage: (message?: (CreateUIMessage<UI_MESSAGE> & {
|
3803
3819
|
text?: never;
|
3804
3820
|
files?: never;
|
3805
3821
|
messageId?: string;
|
@@ -3826,9 +3842,10 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
|
3826
3842
|
* Attempt to resume an ongoing streaming response.
|
3827
3843
|
*/
|
3828
3844
|
resumeStream: (options?: ChatRequestOptions) => Promise<void>;
|
3829
|
-
addToolResult: ({ toolCallId, output, }: {
|
3845
|
+
addToolResult: <TOOL extends keyof InferUIMessageTools<UI_MESSAGE>>({ tool, toolCallId, output, }: {
|
3846
|
+
tool: TOOL;
|
3830
3847
|
toolCallId: string;
|
3831
|
-
output:
|
3848
|
+
output: InferUIMessageTools<UI_MESSAGE>[TOOL]["output"];
|
3832
3849
|
}) => Promise<void>;
|
3833
3850
|
/**
|
3834
3851
|
* Abort the current request immediately, keep the generated tokens if any.
|
@@ -3865,7 +3882,7 @@ type PrepareSendMessagesRequest<UI_MESSAGE extends UIMessage> = (options: {
|
|
3865
3882
|
headers: HeadersInit | undefined;
|
3866
3883
|
api: string;
|
3867
3884
|
} & {
|
3868
|
-
trigger: 'submit-
|
3885
|
+
trigger: 'submit-message' | 'regenerate-message';
|
3869
3886
|
messageId: string | undefined;
|
3870
3887
|
}) => {
|
3871
3888
|
body: object;
|
@@ -3973,6 +3990,15 @@ declare class DefaultChatTransport<UI_MESSAGE extends UIMessage> extends HttpCha
|
|
3973
3990
|
protected processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageChunk>;
|
3974
3991
|
}
|
3975
3992
|
|
3993
|
+
/**
|
3994
|
+
Check if the message is an assistant message with completed tool calls.
|
3995
|
+
The last step of the message must have at least one tool invocation and
|
3996
|
+
all tool invocations must have a result.
|
3997
|
+
*/
|
3998
|
+
declare function lastAssistantMessageIsCompleteWithToolCalls({ messages, }: {
|
3999
|
+
messages: UIMessage[];
|
4000
|
+
}): boolean;
|
4001
|
+
|
3976
4002
|
declare class TextStreamChatTransport<UI_MESSAGE extends UIMessage> extends HttpChatTransport<UI_MESSAGE> {
|
3977
4003
|
constructor(options?: HttpChatTransportInitOptions<UI_MESSAGE>);
|
3978
4004
|
protected processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageChunk>;
|
@@ -4054,4 +4080,4 @@ declare global {
|
|
4054
4080
|
var AI_SDK_DEFAULT_PROVIDER: ProviderV2 | undefined;
|
4055
4081
|
}
|
4056
4082
|
|
4057
|
-
export { AbstractChat, AsyncIterableStream, CallSettings, CallWarning, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, ErrorHandler, Agent as Experimental_Agent, AgentSettings as Experimental_AgentSettings, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolErrorUnion, ToolResultUnion, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamOnFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolName, hasToolCall, isDeepEqualData, isToolUIPart, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, readUIMessageStream, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, userModelMessageSchema, wrapLanguageModel, wrapProvider };
|
4083
|
+
export { AbstractChat, AsyncIterableStream, CallSettings, CallWarning, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, ErrorHandler, Agent as Experimental_Agent, AgentSettings as Experimental_AgentSettings, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolErrorUnion, ToolResultUnion, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamOnFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolName, hasToolCall, isDeepEqualData, isToolUIPart, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, readUIMessageStream, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, userModelMessageSchema, wrapLanguageModel, wrapProvider };
|
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ModelMessage, Tool, InferToolInput, InferToolOutput, AssistantModelMessage, ToolModelMessage, ReasoningPart, Schema, SystemModelMessage, UserModelMessage, ProviderOptions, IdGenerator, InferSchema, FlexibleSchema, DataContent, Validator, StandardSchemaV1,
|
1
|
+
import { ModelMessage, Tool, InferToolInput, InferToolOutput, AssistantModelMessage, ToolModelMessage, ReasoningPart, Schema, SystemModelMessage, UserModelMessage, ProviderOptions, IdGenerator, ToolCall, InferSchema, FlexibleSchema, DataContent, Validator, StandardSchemaV1, Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
2
2
|
export { AssistantContent, AssistantModelMessage, DataContent, FilePart, IdGenerator, ImagePart, InferToolInput, InferToolOutput, ModelMessage, Schema, SystemModelMessage, TextPart, Tool, ToolCallOptions, ToolCallPart, ToolContent, ToolExecuteFunction, ToolModelMessage, ToolResultPart, UserContent, UserModelMessage, asSchema, createIdGenerator, generateId, jsonSchema, tool } from '@ai-sdk/provider-utils';
|
3
3
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
4
4
|
import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SpeechModelV2, SpeechModelV2CallWarning, TranscriptionModelV2, TranscriptionModelV2CallWarning, LanguageModelV2Usage, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError, JSONObject } from '@ai-sdk/provider';
|
@@ -1018,7 +1018,7 @@ Callback that is set using the `onChunk` option.
|
|
1018
1018
|
*/
|
1019
1019
|
type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
|
1020
1020
|
chunk: Extract<TextStreamPart<TOOLS>, {
|
1021
|
-
type: 'text' | 'reasoning' | 'source' | 'tool-call' | 'tool-input-start' | 'tool-input-delta' | 'tool-result' | 'raw';
|
1021
|
+
type: 'text-delta' | 'reasoning-delta' | 'source' | 'tool-call' | 'tool-input-start' | 'tool-input-delta' | 'tool-result' | 'raw';
|
1022
1022
|
}>;
|
1023
1023
|
}) => PromiseLike<void> | void;
|
1024
1024
|
/**
|
@@ -1383,6 +1383,12 @@ declare function isToolUIPart<TOOLS extends UITools>(part: UIMessagePart<UIDataT
|
|
1383
1383
|
declare function getToolName<TOOLS extends UITools>(part: ToolUIPart<TOOLS>): keyof TOOLS;
|
1384
1384
|
type InferUIMessageMetadata<T extends UIMessage> = T extends UIMessage<infer METADATA> ? METADATA : unknown;
|
1385
1385
|
type InferUIMessageData<T extends UIMessage> = T extends UIMessage<unknown, infer DATA_TYPES> ? DATA_TYPES : UIDataTypes;
|
1386
|
+
type InferUIMessageTools<T extends UIMessage> = T extends UIMessage<unknown, UIDataTypes, infer TOOLS> ? TOOLS : UITools;
|
1387
|
+
type InferUIMessageToolCall<UI_MESSAGE extends UIMessage> = ValueOf<{
|
1388
|
+
[NAME in keyof InferUIMessageTools<UI_MESSAGE>]: ToolCall<NAME & string, InferUIMessageTools<UI_MESSAGE>[NAME] extends {
|
1389
|
+
input: infer INPUT;
|
1390
|
+
} ? INPUT : never>;
|
1391
|
+
}>;
|
1386
1392
|
|
1387
1393
|
type DataUIMessageChunk<DATA_TYPES extends UIDataTypes> = ValueOf<{
|
1388
1394
|
[NAME in keyof DATA_TYPES & string]: {
|
@@ -1767,7 +1773,7 @@ type TextStreamPart<TOOLS extends ToolSet> = {
|
|
1767
1773
|
id: string;
|
1768
1774
|
providerMetadata?: ProviderMetadata;
|
1769
1775
|
} | {
|
1770
|
-
type: 'text';
|
1776
|
+
type: 'text-delta';
|
1771
1777
|
id: string;
|
1772
1778
|
providerMetadata?: ProviderMetadata;
|
1773
1779
|
text: string;
|
@@ -1780,7 +1786,7 @@ type TextStreamPart<TOOLS extends ToolSet> = {
|
|
1780
1786
|
id: string;
|
1781
1787
|
providerMetadata?: ProviderMetadata;
|
1782
1788
|
} | {
|
1783
|
-
type: 'reasoning';
|
1789
|
+
type: 'reasoning-delta';
|
1784
1790
|
providerMetadata?: ProviderMetadata;
|
1785
1791
|
id: string;
|
1786
1792
|
text: string;
|
@@ -3647,13 +3653,17 @@ declare function pipeUIMessageStreamToResponse({ response, status, statusText, h
|
|
3647
3653
|
*
|
3648
3654
|
* @param options.message - The last assistant message to use as a starting point when the conversation is resumed. Otherwise undefined.
|
3649
3655
|
* @param options.stream - The stream of `UIMessageChunk`s to read.
|
3656
|
+
* @param options.terminateOnError - Whether to terminate the stream if an error occurs.
|
3657
|
+
* @param options.onError - A function that is called when an error occurs.
|
3650
3658
|
*
|
3651
3659
|
* @returns An `AsyncIterableStream` of `UIMessage`s. Each stream part is a different state of the same message
|
3652
3660
|
* as it is being completed.
|
3653
3661
|
*/
|
3654
|
-
declare function readUIMessageStream<UI_MESSAGE extends UIMessage>({ message, stream, }: {
|
3662
|
+
declare function readUIMessageStream<UI_MESSAGE extends UIMessage>({ message, stream, onError, terminateOnError, }: {
|
3655
3663
|
message?: UI_MESSAGE;
|
3656
3664
|
stream: ReadableStream<UIMessageChunk>;
|
3665
|
+
onError?: (error: unknown) => void;
|
3666
|
+
terminateOnError?: boolean;
|
3657
3667
|
}): AsyncIterableStream<UI_MESSAGE>;
|
3658
3668
|
|
3659
3669
|
declare const UI_MESSAGE_STREAM_HEADERS: {
|
@@ -3670,7 +3680,7 @@ interface ChatTransport<UI_MESSAGE extends UIMessage> {
|
|
3670
3680
|
messages: UI_MESSAGE[];
|
3671
3681
|
abortSignal: AbortSignal | undefined;
|
3672
3682
|
} & {
|
3673
|
-
trigger: 'submit-
|
3683
|
+
trigger: 'submit-message' | 'regenerate-message';
|
3674
3684
|
messageId: string | undefined;
|
3675
3685
|
} & ChatRequestOptions) => Promise<ReadableStream<UIMessageChunk>>;
|
3676
3686
|
reconnectToStream: (options: {
|
@@ -3711,9 +3721,9 @@ interface ChatState<UI_MESSAGE extends UIMessage> {
|
|
3711
3721
|
snapshot: <T>(thing: T) => T;
|
3712
3722
|
}
|
3713
3723
|
type ChatOnErrorCallback = (error: Error) => void;
|
3714
|
-
type ChatOnToolCallCallback =
|
3715
|
-
toolCall:
|
3716
|
-
}) => void |
|
3724
|
+
type ChatOnToolCallCallback<UI_MESSAGE extends UIMessage = UIMessage> = (options: {
|
3725
|
+
toolCall: InferUIMessageToolCall<UI_MESSAGE>;
|
3726
|
+
}) => void | PromiseLike<void>;
|
3717
3727
|
type ChatOnDataCallback<UI_MESSAGE extends UIMessage> = (dataPart: DataUIPart<InferUIMessageData<UI_MESSAGE>>) => void;
|
3718
3728
|
type ChatOnFinishCallback<UI_MESSAGE extends UIMessage> = (options: {
|
3719
3729
|
message: UI_MESSAGE;
|
@@ -3733,7 +3743,6 @@ interface ChatInit<UI_MESSAGE extends UIMessage> {
|
|
3733
3743
|
*/
|
3734
3744
|
generateId?: IdGenerator;
|
3735
3745
|
transport?: ChatTransport<UI_MESSAGE>;
|
3736
|
-
maxSteps?: number;
|
3737
3746
|
/**
|
3738
3747
|
* Callback function to be called when an error is encountered.
|
3739
3748
|
*/
|
@@ -3745,7 +3754,7 @@ interface ChatInit<UI_MESSAGE extends UIMessage> {
|
|
3745
3754
|
You can optionally return a result for the tool call,
|
3746
3755
|
either synchronously or asynchronously.
|
3747
3756
|
*/
|
3748
|
-
onToolCall?: ChatOnToolCallCallback
|
3757
|
+
onToolCall?: ChatOnToolCallCallback<UI_MESSAGE>;
|
3749
3758
|
/**
|
3750
3759
|
* Optional callback function that is called when the assistant message is finished streaming.
|
3751
3760
|
*
|
@@ -3758,6 +3767,13 @@ interface ChatInit<UI_MESSAGE extends UIMessage> {
|
|
3758
3767
|
* @param data The data part that was received.
|
3759
3768
|
*/
|
3760
3769
|
onData?: ChatOnDataCallback<UI_MESSAGE>;
|
3770
|
+
/**
|
3771
|
+
* When provided, this function will be called when the stream is finished or a tool call is added
|
3772
|
+
* to determine if the current messages should be resubmitted.
|
3773
|
+
*/
|
3774
|
+
sendAutomaticallyWhen?: (options: {
|
3775
|
+
messages: UI_MESSAGE[];
|
3776
|
+
}) => boolean | PromiseLike<boolean>;
|
3761
3777
|
}
|
3762
3778
|
declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
3763
3779
|
readonly id: string;
|
@@ -3766,14 +3782,14 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
|
3766
3782
|
private messageMetadataSchema;
|
3767
3783
|
private dataPartSchemas;
|
3768
3784
|
private readonly transport;
|
3769
|
-
private maxSteps;
|
3770
3785
|
private onError?;
|
3771
3786
|
private onToolCall?;
|
3772
3787
|
private onFinish?;
|
3773
3788
|
private onData?;
|
3789
|
+
private sendAutomaticallyWhen?;
|
3774
3790
|
private activeResponse;
|
3775
3791
|
private jobExecutor;
|
3776
|
-
constructor({ generateId, id, transport,
|
3792
|
+
constructor({ generateId, id, transport, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, onData, sendAutomaticallyWhen, }: Omit<ChatInit<UI_MESSAGE>, 'messages'> & {
|
3777
3793
|
state: ChatState<UI_MESSAGE>;
|
3778
3794
|
});
|
3779
3795
|
/**
|
@@ -3799,7 +3815,7 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
|
3799
3815
|
*
|
3800
3816
|
* If a messageId is provided, the message will be replaced.
|
3801
3817
|
*/
|
3802
|
-
sendMessage: (message
|
3818
|
+
sendMessage: (message?: (CreateUIMessage<UI_MESSAGE> & {
|
3803
3819
|
text?: never;
|
3804
3820
|
files?: never;
|
3805
3821
|
messageId?: string;
|
@@ -3826,9 +3842,10 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
|
3826
3842
|
* Attempt to resume an ongoing streaming response.
|
3827
3843
|
*/
|
3828
3844
|
resumeStream: (options?: ChatRequestOptions) => Promise<void>;
|
3829
|
-
addToolResult: ({ toolCallId, output, }: {
|
3845
|
+
addToolResult: <TOOL extends keyof InferUIMessageTools<UI_MESSAGE>>({ tool, toolCallId, output, }: {
|
3846
|
+
tool: TOOL;
|
3830
3847
|
toolCallId: string;
|
3831
|
-
output:
|
3848
|
+
output: InferUIMessageTools<UI_MESSAGE>[TOOL]["output"];
|
3832
3849
|
}) => Promise<void>;
|
3833
3850
|
/**
|
3834
3851
|
* Abort the current request immediately, keep the generated tokens if any.
|
@@ -3865,7 +3882,7 @@ type PrepareSendMessagesRequest<UI_MESSAGE extends UIMessage> = (options: {
|
|
3865
3882
|
headers: HeadersInit | undefined;
|
3866
3883
|
api: string;
|
3867
3884
|
} & {
|
3868
|
-
trigger: 'submit-
|
3885
|
+
trigger: 'submit-message' | 'regenerate-message';
|
3869
3886
|
messageId: string | undefined;
|
3870
3887
|
}) => {
|
3871
3888
|
body: object;
|
@@ -3973,6 +3990,15 @@ declare class DefaultChatTransport<UI_MESSAGE extends UIMessage> extends HttpCha
|
|
3973
3990
|
protected processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageChunk>;
|
3974
3991
|
}
|
3975
3992
|
|
3993
|
+
/**
|
3994
|
+
Check if the message is an assistant message with completed tool calls.
|
3995
|
+
The last step of the message must have at least one tool invocation and
|
3996
|
+
all tool invocations must have a result.
|
3997
|
+
*/
|
3998
|
+
declare function lastAssistantMessageIsCompleteWithToolCalls({ messages, }: {
|
3999
|
+
messages: UIMessage[];
|
4000
|
+
}): boolean;
|
4001
|
+
|
3976
4002
|
declare class TextStreamChatTransport<UI_MESSAGE extends UIMessage> extends HttpChatTransport<UI_MESSAGE> {
|
3977
4003
|
constructor(options?: HttpChatTransportInitOptions<UI_MESSAGE>);
|
3978
4004
|
protected processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageChunk>;
|
@@ -4054,4 +4080,4 @@ declare global {
|
|
4054
4080
|
var AI_SDK_DEFAULT_PROVIDER: ProviderV2 | undefined;
|
4055
4081
|
}
|
4056
4082
|
|
4057
|
-
export { AbstractChat, AsyncIterableStream, CallSettings, CallWarning, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, ErrorHandler, Agent as Experimental_Agent, AgentSettings as Experimental_AgentSettings, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolErrorUnion, ToolResultUnion, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamOnFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolName, hasToolCall, isDeepEqualData, isToolUIPart, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, readUIMessageStream, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, userModelMessageSchema, wrapLanguageModel, wrapProvider };
|
4083
|
+
export { AbstractChat, AsyncIterableStream, CallSettings, CallWarning, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, ErrorHandler, Agent as Experimental_Agent, AgentSettings as Experimental_AgentSettings, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolErrorUnion, ToolResultUnion, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamOnFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolName, hasToolCall, isDeepEqualData, isToolUIPart, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, readUIMessageStream, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, userModelMessageSchema, wrapLanguageModel, wrapProvider };
|