ai 5.0.0-beta.21 → 5.0.0-beta.22
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 +14 -0
- package/dist/bin/ai.js +103 -101
- package/dist/bin/ai.js.map +1 -1
- package/dist/bin/ai.min.js +12 -13
- package/dist/index.d.mts +39 -14
- package/dist/index.d.ts +39 -14
- package/dist/index.js +137 -98
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +135 -97
- package/dist/index.mjs.map +1 -1
- package/dist/test/index.d.mts +17 -2
- package/dist/test/index.d.ts +17 -2
- package/dist/test/index.js +51 -0
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +52 -0
- package/dist/test/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
@@ -4,9 +4,8 @@ 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';
|
5
5
|
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
6
6
|
import * as z3 from 'zod/v3';
|
7
|
-
import * as z4
|
7
|
+
import * as z4 from 'zod/v4';
|
8
8
|
import { z } from 'zod/v4';
|
9
|
-
import * as z4 from 'zod/v4/core';
|
10
9
|
import { ServerResponse } from 'node:http';
|
11
10
|
import { ServerResponse as ServerResponse$1 } from 'http';
|
12
11
|
|
@@ -669,7 +668,7 @@ It always recurses into arrays.
|
|
669
668
|
|
670
669
|
Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
|
671
670
|
*/
|
672
|
-
type DeepPartial<T> = T extends z3.ZodTypeAny ? DeepPartialInternal<z3.infer<T>> : T extends z4.$ZodType ? DeepPartialInternal<z4.infer<T>> : DeepPartialInternal<T>;
|
671
|
+
type DeepPartial<T> = T extends z3.ZodTypeAny ? DeepPartialInternal<z3.infer<T>> : T extends z4.core.$ZodType ? DeepPartialInternal<z4.infer<T>> : DeepPartialInternal<T>;
|
673
672
|
type DeepPartialInternal<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartialInternal<ItemType | undefined>> : Array<DeepPartialInternal<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
|
674
673
|
type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
675
674
|
type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
|
@@ -697,7 +696,7 @@ interface Output<OUTPUT, PARTIAL> {
|
|
697
696
|
}
|
698
697
|
declare const text: () => Output<string, string>;
|
699
698
|
declare const object: <OUTPUT>({ schema: inputSchema, }: {
|
700
|
-
schema: z4
|
699
|
+
schema: z4.core.$ZodType<OUTPUT, any> | z3.Schema<OUTPUT, z3.ZodTypeDef, any> | Schema<OUTPUT>;
|
701
700
|
}) => Output<OUTPUT, DeepPartial<OUTPUT>>;
|
702
701
|
|
703
702
|
type output_Output<OUTPUT, PARTIAL> = Output<OUTPUT, PARTIAL>;
|
@@ -777,7 +776,7 @@ declare const systemModelMessageSchema: z.ZodType<SystemModelMessage>;
|
|
777
776
|
/**
|
778
777
|
@deprecated Use `systemModelMessageSchema` instead.
|
779
778
|
*/
|
780
|
-
declare const coreSystemMessageSchema: z.ZodType<SystemModelMessage, unknown
|
779
|
+
declare const coreSystemMessageSchema: z.ZodType<SystemModelMessage, unknown, z.core.$ZodTypeInternals<SystemModelMessage, unknown>>;
|
781
780
|
/**
|
782
781
|
@deprecated Use `UserModelMessage` instead.
|
783
782
|
*/
|
@@ -786,7 +785,7 @@ declare const userModelMessageSchema: z.ZodType<UserModelMessage>;
|
|
786
785
|
/**
|
787
786
|
@deprecated Use `userModelMessageSchema` instead.
|
788
787
|
*/
|
789
|
-
declare const coreUserMessageSchema: z.ZodType<UserModelMessage, unknown
|
788
|
+
declare const coreUserMessageSchema: z.ZodType<UserModelMessage, unknown, z.core.$ZodTypeInternals<UserModelMessage, unknown>>;
|
790
789
|
/**
|
791
790
|
@deprecated Use `AssistantModelMessage` instead.
|
792
791
|
*/
|
@@ -795,7 +794,7 @@ declare const assistantModelMessageSchema: z.ZodType<AssistantModelMessage>;
|
|
795
794
|
/**
|
796
795
|
@deprecated Use `assistantModelMessageSchema` instead.
|
797
796
|
*/
|
798
|
-
declare const coreAssistantMessageSchema: z.ZodType<AssistantModelMessage, unknown
|
797
|
+
declare const coreAssistantMessageSchema: z.ZodType<AssistantModelMessage, unknown, z.core.$ZodTypeInternals<AssistantModelMessage, unknown>>;
|
799
798
|
/**
|
800
799
|
@deprecated Use `ToolModelMessage` instead.
|
801
800
|
*/
|
@@ -804,7 +803,7 @@ declare const toolModelMessageSchema: z.ZodType<ToolModelMessage>;
|
|
804
803
|
/**
|
805
804
|
@deprecated Use `toolModelMessageSchema` instead.
|
806
805
|
*/
|
807
|
-
declare const coreToolMessageSchema: z.ZodType<ToolModelMessage, unknown
|
806
|
+
declare const coreToolMessageSchema: z.ZodType<ToolModelMessage, unknown, z.core.$ZodTypeInternals<ToolModelMessage, unknown>>;
|
808
807
|
/**
|
809
808
|
@deprecated Use `ModelMessage` instead.
|
810
809
|
*/
|
@@ -2571,7 +2570,7 @@ functionality that can be fully encapsulated in the provider.
|
|
2571
2570
|
@returns
|
2572
2571
|
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
2573
2572
|
*/
|
2574
|
-
declare function generateObject<SCHEMA extends z3.Schema | z4
|
2573
|
+
declare function generateObject<SCHEMA extends z3.Schema | z4.core.$ZodType | Schema = z4.core.$ZodType<JSONValue$1>, OUTPUT extends 'object' | 'array' | 'enum' | 'no-schema' = InferSchema<SCHEMA> extends string ? 'enum' : 'object', RESULT = OUTPUT extends 'array' ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (OUTPUT extends 'enum' ? {
|
2575
2574
|
/**
|
2576
2575
|
The enum values that the model should use.
|
2577
2576
|
*/
|
@@ -2888,7 +2887,7 @@ functionality that can be fully encapsulated in the provider.
|
|
2888
2887
|
@returns
|
2889
2888
|
A result object for accessing the partial object stream and additional information.
|
2890
2889
|
*/
|
2891
|
-
declare function streamObject<SCHEMA extends z3.Schema | z4
|
2890
|
+
declare function streamObject<SCHEMA extends z3.Schema | z4.core.$ZodType | Schema = z4.core.$ZodType<JSONValue$1>, OUTPUT extends 'object' | 'array' | 'enum' | 'no-schema' = InferSchema<SCHEMA> extends string ? 'enum' : 'object', RESULT = OUTPUT extends 'array' ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (OUTPUT extends 'enum' ? {
|
2892
2891
|
/**
|
2893
2892
|
The enum values that the model should use.
|
2894
2893
|
*/
|
@@ -3121,7 +3120,7 @@ declare function simulateStreamingMiddleware(): LanguageModelV2Middleware;
|
|
3121
3120
|
* @param options.model - The original LanguageModelV2 instance to be wrapped.
|
3122
3121
|
* @param options.middleware - The middleware to be applied to the language model. When multiple middlewares are provided, the first middleware will transform the input first, and the last middleware will be wrapped directly around the model.
|
3123
3122
|
* @param options.modelId - Optional custom model ID to override the original model's ID.
|
3124
|
-
* @param options.providerId - Optional custom provider ID to override the original model's provider.
|
3123
|
+
* @param options.providerId - Optional custom provider ID to override the original model's provider ID.
|
3125
3124
|
* @returns A new LanguageModelV2 instance with middleware applied.
|
3126
3125
|
*/
|
3127
3126
|
declare const wrapLanguageModel: ({ model, middleware: middlewareArg, modelId, providerId, }: {
|
@@ -3131,6 +3130,22 @@ declare const wrapLanguageModel: ({ model, middleware: middlewareArg, modelId, p
|
|
3131
3130
|
providerId?: string;
|
3132
3131
|
}) => LanguageModelV2;
|
3133
3132
|
|
3133
|
+
/**
|
3134
|
+
* Wraps a ProviderV2 instance with middleware functionality.
|
3135
|
+
* This function allows you to apply middleware to all language models
|
3136
|
+
* from the provider, enabling you to transform parameters, wrap generate
|
3137
|
+
* operations, and wrap stream operations for every language model.
|
3138
|
+
*
|
3139
|
+
* @param options - Configuration options for wrapping the provider.
|
3140
|
+
* @param options.provider - The original ProviderV2 instance to be wrapped.
|
3141
|
+
* @param options.languageModelMiddleware - The middleware to be applied to all language models from the provider. When multiple middlewares are provided, the first middleware will transform the input first, and the last middleware will be wrapped directly around the model.
|
3142
|
+
* @returns A new ProviderV2 instance with middleware applied to all language models.
|
3143
|
+
*/
|
3144
|
+
declare function wrapProvider({ provider, languageModelMiddleware, }: {
|
3145
|
+
provider: ProviderV2;
|
3146
|
+
languageModelMiddleware: LanguageModelV2Middleware | LanguageModelV2Middleware[];
|
3147
|
+
}): ProviderV2;
|
3148
|
+
|
3134
3149
|
/**
|
3135
3150
|
* Creates a custom provider with specified language models, text embedding models, image models, transcription models, speech models, and an optional fallback provider.
|
3136
3151
|
*
|
@@ -3194,10 +3209,20 @@ interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV2>
|
|
3194
3209
|
speechModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): SpeechModelV2;
|
3195
3210
|
}
|
3196
3211
|
/**
|
3197
|
-
* Creates a registry for the given providers.
|
3212
|
+
* Creates a registry for the given providers with optional middleware functionality.
|
3213
|
+
* This function allows you to register multiple providers and optionally apply middleware
|
3214
|
+
* to all language models from the registry, enabling you to transform parameters, wrap generate
|
3215
|
+
* operations, and wrap stream operations for every language model accessed through the registry.
|
3216
|
+
*
|
3217
|
+
* @param providers - A record of provider instances to be registered in the registry.
|
3218
|
+
* @param options - Configuration options for the provider registry.
|
3219
|
+
* @param options.separator - The separator used between provider ID and model ID in the combined identifier. Defaults to ':'.
|
3220
|
+
* @param options.languageModelMiddleware - Optional middleware to be applied to all language models from the registry. When multiple middlewares are provided, the first middleware will transform the input first, and the last middleware will be wrapped directly around the model.
|
3221
|
+
* @returns A new ProviderRegistryProvider instance that provides access to all registered providers with optional middleware applied to language models.
|
3198
3222
|
*/
|
3199
|
-
declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV2>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, }?: {
|
3223
|
+
declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV2>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, languageModelMiddleware, }?: {
|
3200
3224
|
separator?: SEPARATOR;
|
3225
|
+
languageModelMiddleware?: LanguageModelV2Middleware | LanguageModelV2Middleware[];
|
3201
3226
|
}): ProviderRegistryProvider<PROVIDERS, SEPARATOR>;
|
3202
3227
|
/**
|
3203
3228
|
* @deprecated Use `createProviderRegistry` instead.
|
@@ -4007,4 +4032,4 @@ declare global {
|
|
4007
4032
|
var AI_SDK_DEFAULT_PROVIDER: ProviderV2 | undefined;
|
4008
4033
|
}
|
4009
4034
|
|
4010
|
-
export { AbstractChat, 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, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, 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 };
|
4035
|
+
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, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, 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 };
|
package/dist/index.js
CHANGED
@@ -108,7 +108,8 @@ __export(src_exports, {
|
|
108
108
|
tool: () => import_provider_utils23.tool,
|
109
109
|
toolModelMessageSchema: () => toolModelMessageSchema,
|
110
110
|
userModelMessageSchema: () => userModelMessageSchema,
|
111
|
-
wrapLanguageModel: () => wrapLanguageModel
|
111
|
+
wrapLanguageModel: () => wrapLanguageModel,
|
112
|
+
wrapProvider: () => wrapProvider
|
112
113
|
});
|
113
114
|
module.exports = __toCommonJS(src_exports);
|
114
115
|
var import_provider_utils29 = require("@ai-sdk/provider-utils");
|
@@ -3150,24 +3151,24 @@ function processUIMessageStream({
|
|
3150
3151
|
}) {
|
3151
3152
|
return stream.pipeThrough(
|
3152
3153
|
new TransformStream({
|
3153
|
-
async transform(
|
3154
|
+
async transform(chunk, controller) {
|
3154
3155
|
await runUpdateMessageJob(async ({ state, write }) => {
|
3155
3156
|
var _a16, _b, _c, _d;
|
3156
3157
|
function updateToolInvocationPart(options) {
|
3157
3158
|
var _a17;
|
3158
|
-
const
|
3159
|
-
(
|
3159
|
+
const part = state.message.parts.find(
|
3160
|
+
(part2) => isToolUIPart(part2) && part2.toolCallId === options.toolCallId
|
3160
3161
|
);
|
3161
3162
|
const anyOptions = options;
|
3162
|
-
const anyPart =
|
3163
|
-
if (
|
3164
|
-
|
3163
|
+
const anyPart = part;
|
3164
|
+
if (part != null) {
|
3165
|
+
part.state = options.state;
|
3165
3166
|
anyPart.input = anyOptions.input;
|
3166
3167
|
anyPart.output = anyOptions.output;
|
3167
3168
|
anyPart.errorText = anyOptions.errorText;
|
3168
|
-
anyPart.providerExecuted = (_a17 = anyOptions.providerExecuted) != null ? _a17 :
|
3169
|
-
if (anyOptions.providerMetadata != null &&
|
3170
|
-
|
3169
|
+
anyPart.providerExecuted = (_a17 = anyOptions.providerExecuted) != null ? _a17 : part.providerExecuted;
|
3170
|
+
if (anyOptions.providerMetadata != null && part.state === "input-available") {
|
3171
|
+
part.callProviderMetadata = anyOptions.providerMetadata;
|
3171
3172
|
}
|
3172
3173
|
} else {
|
3173
3174
|
state.message.parts.push({
|
@@ -3194,31 +3195,31 @@ function processUIMessageStream({
|
|
3194
3195
|
state.message.metadata = mergedMetadata;
|
3195
3196
|
}
|
3196
3197
|
}
|
3197
|
-
switch (
|
3198
|
+
switch (chunk.type) {
|
3198
3199
|
case "text-start": {
|
3199
3200
|
const textPart = {
|
3200
3201
|
type: "text",
|
3201
3202
|
text: "",
|
3202
|
-
providerMetadata:
|
3203
|
+
providerMetadata: chunk.providerMetadata,
|
3203
3204
|
state: "streaming"
|
3204
3205
|
};
|
3205
|
-
state.activeTextParts[
|
3206
|
+
state.activeTextParts[chunk.id] = textPart;
|
3206
3207
|
state.message.parts.push(textPart);
|
3207
3208
|
write();
|
3208
3209
|
break;
|
3209
3210
|
}
|
3210
3211
|
case "text-delta": {
|
3211
|
-
const textPart = state.activeTextParts[
|
3212
|
-
textPart.text +=
|
3213
|
-
textPart.providerMetadata = (_a16 =
|
3212
|
+
const textPart = state.activeTextParts[chunk.id];
|
3213
|
+
textPart.text += chunk.delta;
|
3214
|
+
textPart.providerMetadata = (_a16 = chunk.providerMetadata) != null ? _a16 : textPart.providerMetadata;
|
3214
3215
|
write();
|
3215
3216
|
break;
|
3216
3217
|
}
|
3217
3218
|
case "text-end": {
|
3218
|
-
const textPart = state.activeTextParts[
|
3219
|
+
const textPart = state.activeTextParts[chunk.id];
|
3219
3220
|
textPart.state = "done";
|
3220
|
-
textPart.providerMetadata = (_b =
|
3221
|
-
delete state.activeTextParts[
|
3221
|
+
textPart.providerMetadata = (_b = chunk.providerMetadata) != null ? _b : textPart.providerMetadata;
|
3222
|
+
delete state.activeTextParts[chunk.id];
|
3222
3223
|
write();
|
3223
3224
|
break;
|
3224
3225
|
}
|
@@ -3226,34 +3227,34 @@ function processUIMessageStream({
|
|
3226
3227
|
const reasoningPart = {
|
3227
3228
|
type: "reasoning",
|
3228
3229
|
text: "",
|
3229
|
-
providerMetadata:
|
3230
|
+
providerMetadata: chunk.providerMetadata,
|
3230
3231
|
state: "streaming"
|
3231
3232
|
};
|
3232
|
-
state.activeReasoningParts[
|
3233
|
+
state.activeReasoningParts[chunk.id] = reasoningPart;
|
3233
3234
|
state.message.parts.push(reasoningPart);
|
3234
3235
|
write();
|
3235
3236
|
break;
|
3236
3237
|
}
|
3237
3238
|
case "reasoning-delta": {
|
3238
|
-
const reasoningPart = state.activeReasoningParts[
|
3239
|
-
reasoningPart.text +=
|
3240
|
-
reasoningPart.providerMetadata = (_c =
|
3239
|
+
const reasoningPart = state.activeReasoningParts[chunk.id];
|
3240
|
+
reasoningPart.text += chunk.delta;
|
3241
|
+
reasoningPart.providerMetadata = (_c = chunk.providerMetadata) != null ? _c : reasoningPart.providerMetadata;
|
3241
3242
|
write();
|
3242
3243
|
break;
|
3243
3244
|
}
|
3244
3245
|
case "reasoning-end": {
|
3245
|
-
const reasoningPart = state.activeReasoningParts[
|
3246
|
-
reasoningPart.providerMetadata = (_d =
|
3246
|
+
const reasoningPart = state.activeReasoningParts[chunk.id];
|
3247
|
+
reasoningPart.providerMetadata = (_d = chunk.providerMetadata) != null ? _d : reasoningPart.providerMetadata;
|
3247
3248
|
reasoningPart.state = "done";
|
3248
|
-
delete state.activeReasoningParts[
|
3249
|
+
delete state.activeReasoningParts[chunk.id];
|
3249
3250
|
write();
|
3250
3251
|
break;
|
3251
3252
|
}
|
3252
3253
|
case "file": {
|
3253
3254
|
state.message.parts.push({
|
3254
3255
|
type: "file",
|
3255
|
-
mediaType:
|
3256
|
-
url:
|
3256
|
+
mediaType: chunk.mediaType,
|
3257
|
+
url: chunk.url
|
3257
3258
|
});
|
3258
3259
|
write();
|
3259
3260
|
break;
|
@@ -3261,10 +3262,10 @@ function processUIMessageStream({
|
|
3261
3262
|
case "source-url": {
|
3262
3263
|
state.message.parts.push({
|
3263
3264
|
type: "source-url",
|
3264
|
-
sourceId:
|
3265
|
-
url:
|
3266
|
-
title:
|
3267
|
-
providerMetadata:
|
3265
|
+
sourceId: chunk.sourceId,
|
3266
|
+
url: chunk.url,
|
3267
|
+
title: chunk.title,
|
3268
|
+
providerMetadata: chunk.providerMetadata
|
3268
3269
|
});
|
3269
3270
|
write();
|
3270
3271
|
break;
|
@@ -3272,40 +3273,40 @@ function processUIMessageStream({
|
|
3272
3273
|
case "source-document": {
|
3273
3274
|
state.message.parts.push({
|
3274
3275
|
type: "source-document",
|
3275
|
-
sourceId:
|
3276
|
-
mediaType:
|
3277
|
-
title:
|
3278
|
-
filename:
|
3279
|
-
providerMetadata:
|
3276
|
+
sourceId: chunk.sourceId,
|
3277
|
+
mediaType: chunk.mediaType,
|
3278
|
+
title: chunk.title,
|
3279
|
+
filename: chunk.filename,
|
3280
|
+
providerMetadata: chunk.providerMetadata
|
3280
3281
|
});
|
3281
3282
|
write();
|
3282
3283
|
break;
|
3283
3284
|
}
|
3284
3285
|
case "tool-input-start": {
|
3285
3286
|
const toolInvocations = state.message.parts.filter(isToolUIPart);
|
3286
|
-
state.partialToolCalls[
|
3287
|
+
state.partialToolCalls[chunk.toolCallId] = {
|
3287
3288
|
text: "",
|
3288
|
-
toolName:
|
3289
|
+
toolName: chunk.toolName,
|
3289
3290
|
index: toolInvocations.length
|
3290
3291
|
};
|
3291
3292
|
updateToolInvocationPart({
|
3292
|
-
toolCallId:
|
3293
|
-
toolName:
|
3293
|
+
toolCallId: chunk.toolCallId,
|
3294
|
+
toolName: chunk.toolName,
|
3294
3295
|
state: "input-streaming",
|
3295
3296
|
input: void 0,
|
3296
|
-
providerExecuted:
|
3297
|
+
providerExecuted: chunk.providerExecuted
|
3297
3298
|
});
|
3298
3299
|
write();
|
3299
3300
|
break;
|
3300
3301
|
}
|
3301
3302
|
case "tool-input-delta": {
|
3302
|
-
const partialToolCall = state.partialToolCalls[
|
3303
|
-
partialToolCall.text +=
|
3303
|
+
const partialToolCall = state.partialToolCalls[chunk.toolCallId];
|
3304
|
+
partialToolCall.text += chunk.inputTextDelta;
|
3304
3305
|
const { value: partialArgs } = await parsePartialJson(
|
3305
3306
|
partialToolCall.text
|
3306
3307
|
);
|
3307
3308
|
updateToolInvocationPart({
|
3308
|
-
toolCallId:
|
3309
|
+
toolCallId: chunk.toolCallId,
|
3309
3310
|
toolName: partialToolCall.toolName,
|
3310
3311
|
state: "input-streaming",
|
3311
3312
|
input: partialArgs
|
@@ -3315,24 +3316,24 @@ function processUIMessageStream({
|
|
3315
3316
|
}
|
3316
3317
|
case "tool-input-available": {
|
3317
3318
|
updateToolInvocationPart({
|
3318
|
-
toolCallId:
|
3319
|
-
toolName:
|
3319
|
+
toolCallId: chunk.toolCallId,
|
3320
|
+
toolName: chunk.toolName,
|
3320
3321
|
state: "input-available",
|
3321
|
-
input:
|
3322
|
-
providerExecuted:
|
3323
|
-
providerMetadata:
|
3322
|
+
input: chunk.input,
|
3323
|
+
providerExecuted: chunk.providerExecuted,
|
3324
|
+
providerMetadata: chunk.providerMetadata
|
3324
3325
|
});
|
3325
3326
|
write();
|
3326
|
-
if (onToolCall && !
|
3327
|
+
if (onToolCall && !chunk.providerExecuted) {
|
3327
3328
|
const result = await onToolCall({
|
3328
|
-
toolCall:
|
3329
|
+
toolCall: chunk
|
3329
3330
|
});
|
3330
3331
|
if (result != null) {
|
3331
3332
|
updateToolInvocationPart({
|
3332
|
-
toolCallId:
|
3333
|
-
toolName:
|
3333
|
+
toolCallId: chunk.toolCallId,
|
3334
|
+
toolName: chunk.toolName,
|
3334
3335
|
state: "output-available",
|
3335
|
-
input:
|
3336
|
+
input: chunk.input,
|
3336
3337
|
output: result
|
3337
3338
|
});
|
3338
3339
|
write();
|
@@ -3346,7 +3347,7 @@ function processUIMessageStream({
|
|
3346
3347
|
throw new Error("tool_result must be preceded by a tool_call");
|
3347
3348
|
}
|
3348
3349
|
const toolInvocationIndex = toolInvocations.findIndex(
|
3349
|
-
(invocation) => invocation.toolCallId ===
|
3350
|
+
(invocation) => invocation.toolCallId === chunk.toolCallId
|
3350
3351
|
);
|
3351
3352
|
if (toolInvocationIndex === -1) {
|
3352
3353
|
throw new Error(
|
@@ -3357,12 +3358,12 @@ function processUIMessageStream({
|
|
3357
3358
|
toolInvocations[toolInvocationIndex]
|
3358
3359
|
);
|
3359
3360
|
updateToolInvocationPart({
|
3360
|
-
toolCallId:
|
3361
|
+
toolCallId: chunk.toolCallId,
|
3361
3362
|
toolName,
|
3362
3363
|
state: "output-available",
|
3363
3364
|
input: toolInvocations[toolInvocationIndex].input,
|
3364
|
-
output:
|
3365
|
-
providerExecuted:
|
3365
|
+
output: chunk.output,
|
3366
|
+
providerExecuted: chunk.providerExecuted
|
3366
3367
|
});
|
3367
3368
|
write();
|
3368
3369
|
break;
|
@@ -3373,7 +3374,7 @@ function processUIMessageStream({
|
|
3373
3374
|
throw new Error("tool_result must be preceded by a tool_call");
|
3374
3375
|
}
|
3375
3376
|
const toolInvocationIndex = toolInvocations.findIndex(
|
3376
|
-
(invocation) => invocation.toolCallId ===
|
3377
|
+
(invocation) => invocation.toolCallId === chunk.toolCallId
|
3377
3378
|
);
|
3378
3379
|
if (toolInvocationIndex === -1) {
|
3379
3380
|
throw new Error(
|
@@ -3384,12 +3385,12 @@ function processUIMessageStream({
|
|
3384
3385
|
toolInvocations[toolInvocationIndex]
|
3385
3386
|
);
|
3386
3387
|
updateToolInvocationPart({
|
3387
|
-
toolCallId:
|
3388
|
+
toolCallId: chunk.toolCallId,
|
3388
3389
|
toolName,
|
3389
3390
|
state: "output-error",
|
3390
3391
|
input: toolInvocations[toolInvocationIndex].input,
|
3391
|
-
errorText:
|
3392
|
-
providerExecuted:
|
3392
|
+
errorText: chunk.errorText,
|
3393
|
+
providerExecuted: chunk.providerExecuted
|
3393
3394
|
});
|
3394
3395
|
write();
|
3395
3396
|
break;
|
@@ -3404,62 +3405,65 @@ function processUIMessageStream({
|
|
3404
3405
|
break;
|
3405
3406
|
}
|
3406
3407
|
case "start": {
|
3407
|
-
if (
|
3408
|
-
state.message.id =
|
3408
|
+
if (chunk.messageId != null) {
|
3409
|
+
state.message.id = chunk.messageId;
|
3409
3410
|
}
|
3410
|
-
await updateMessageMetadata(
|
3411
|
-
if (
|
3411
|
+
await updateMessageMetadata(chunk.messageMetadata);
|
3412
|
+
if (chunk.messageId != null || chunk.messageMetadata != null) {
|
3412
3413
|
write();
|
3413
3414
|
}
|
3414
3415
|
break;
|
3415
3416
|
}
|
3416
3417
|
case "finish": {
|
3417
|
-
await updateMessageMetadata(
|
3418
|
-
if (
|
3418
|
+
await updateMessageMetadata(chunk.messageMetadata);
|
3419
|
+
if (chunk.messageMetadata != null) {
|
3419
3420
|
write();
|
3420
3421
|
}
|
3421
3422
|
break;
|
3422
3423
|
}
|
3423
3424
|
case "message-metadata": {
|
3424
|
-
await updateMessageMetadata(
|
3425
|
-
if (
|
3425
|
+
await updateMessageMetadata(chunk.messageMetadata);
|
3426
|
+
if (chunk.messageMetadata != null) {
|
3426
3427
|
write();
|
3427
3428
|
}
|
3428
3429
|
break;
|
3429
3430
|
}
|
3430
3431
|
case "error": {
|
3431
|
-
onError == null ? void 0 : onError(new Error(
|
3432
|
+
onError == null ? void 0 : onError(new Error(chunk.errorText));
|
3432
3433
|
break;
|
3433
3434
|
}
|
3434
3435
|
default: {
|
3435
|
-
if (isDataUIMessageChunk(
|
3436
|
-
|
3437
|
-
|
3438
|
-
|
3436
|
+
if (isDataUIMessageChunk(chunk)) {
|
3437
|
+
if ((dataPartSchemas == null ? void 0 : dataPartSchemas[chunk.type]) != null) {
|
3438
|
+
await (0, import_provider_utils11.validateTypes)({
|
3439
|
+
value: chunk.data,
|
3440
|
+
schema: dataPartSchemas[chunk.type]
|
3441
|
+
});
|
3442
|
+
}
|
3443
|
+
const dataChunk = chunk;
|
3444
|
+
if (dataChunk.transient) {
|
3445
|
+
onData == null ? void 0 : onData(dataChunk);
|
3439
3446
|
break;
|
3440
3447
|
}
|
3441
|
-
const
|
3442
|
-
(
|
3448
|
+
const existingUIPart = dataChunk.id != null ? state.message.parts.find(
|
3449
|
+
(chunkArg) => dataChunk.type === chunkArg.type && dataChunk.id === chunkArg.id
|
3443
3450
|
) : void 0;
|
3444
|
-
if (
|
3445
|
-
|
3451
|
+
if (existingUIPart != null) {
|
3452
|
+
existingUIPart.data = dataChunk.data;
|
3446
3453
|
} else {
|
3447
|
-
state.message.parts.push(
|
3454
|
+
state.message.parts.push(dataChunk);
|
3448
3455
|
}
|
3449
|
-
onData == null ? void 0 : onData(
|
3456
|
+
onData == null ? void 0 : onData(dataChunk);
|
3450
3457
|
write();
|
3451
3458
|
}
|
3452
3459
|
}
|
3453
3460
|
}
|
3454
|
-
controller.enqueue(
|
3461
|
+
controller.enqueue(chunk);
|
3455
3462
|
});
|
3456
3463
|
}
|
3457
3464
|
})
|
3458
3465
|
);
|
3459
3466
|
}
|
3460
|
-
function isObject(value) {
|
3461
|
-
return typeof value === "object" && value !== null;
|
3462
|
-
}
|
3463
3467
|
|
3464
3468
|
// src/ui-message-stream/handle-ui-message-stream-finish.ts
|
3465
3469
|
function handleUIMessageStreamFinish({
|
@@ -4882,10 +4886,10 @@ var DefaultStreamTextResult = class {
|
|
4882
4886
|
sendFinish = true,
|
4883
4887
|
onError = import_provider22.getErrorMessage
|
4884
4888
|
} = {}) {
|
4885
|
-
const responseMessageId = getResponseUIMessageId({
|
4889
|
+
const responseMessageId = generateMessageId != null ? getResponseUIMessageId({
|
4886
4890
|
originalMessages,
|
4887
|
-
responseMessageId:
|
4888
|
-
});
|
4891
|
+
responseMessageId: generateMessageId
|
4892
|
+
}) : void 0;
|
4889
4893
|
const baseStream = this.fullStream.pipeThrough(
|
4890
4894
|
new TransformStream({
|
4891
4895
|
transform: async (part, controller) => {
|
@@ -5039,8 +5043,8 @@ var DefaultStreamTextResult = class {
|
|
5039
5043
|
if (sendStart) {
|
5040
5044
|
controller.enqueue({
|
5041
5045
|
type: "start",
|
5042
|
-
|
5043
|
-
|
5046
|
+
...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {},
|
5047
|
+
...responseMessageId != null ? { messageId: responseMessageId } : {}
|
5044
5048
|
});
|
5045
5049
|
}
|
5046
5050
|
break;
|
@@ -5049,7 +5053,7 @@ var DefaultStreamTextResult = class {
|
|
5049
5053
|
if (sendFinish) {
|
5050
5054
|
controller.enqueue({
|
5051
5055
|
type: "finish",
|
5052
|
-
messageMetadata: messageMetadataValue
|
5056
|
+
...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {}
|
5053
5057
|
});
|
5054
5058
|
}
|
5055
5059
|
break;
|
@@ -7456,6 +7460,28 @@ var doWrap = ({
|
|
7456
7460
|
};
|
7457
7461
|
};
|
7458
7462
|
|
7463
|
+
// src/middleware/wrap-provider.ts
|
7464
|
+
function wrapProvider({
|
7465
|
+
provider,
|
7466
|
+
languageModelMiddleware
|
7467
|
+
}) {
|
7468
|
+
const wrappedProvider = {
|
7469
|
+
languageModel(modelId) {
|
7470
|
+
let model = provider.languageModel(modelId);
|
7471
|
+
model = wrapLanguageModel({
|
7472
|
+
model,
|
7473
|
+
middleware: languageModelMiddleware
|
7474
|
+
});
|
7475
|
+
return model;
|
7476
|
+
},
|
7477
|
+
textEmbeddingModel: provider.textEmbeddingModel,
|
7478
|
+
imageModel: provider.imageModel,
|
7479
|
+
transcriptionModel: provider.transcriptionModel,
|
7480
|
+
speechModel: provider.speechModel
|
7481
|
+
};
|
7482
|
+
return wrappedProvider;
|
7483
|
+
}
|
7484
|
+
|
7459
7485
|
// src/registry/custom-provider.ts
|
7460
7486
|
var import_provider27 = require("@ai-sdk/provider");
|
7461
7487
|
function customProvider({
|
@@ -7544,10 +7570,12 @@ _a15 = symbol15;
|
|
7544
7570
|
// src/registry/provider-registry.ts
|
7545
7571
|
var import_provider29 = require("@ai-sdk/provider");
|
7546
7572
|
function createProviderRegistry(providers, {
|
7547
|
-
separator = ":"
|
7573
|
+
separator = ":",
|
7574
|
+
languageModelMiddleware
|
7548
7575
|
} = {}) {
|
7549
7576
|
const registry = new DefaultProviderRegistry({
|
7550
|
-
separator
|
7577
|
+
separator,
|
7578
|
+
languageModelMiddleware
|
7551
7579
|
});
|
7552
7580
|
for (const [id, provider] of Object.entries(providers)) {
|
7553
7581
|
registry.registerProvider({ id, provider });
|
@@ -7556,9 +7584,13 @@ function createProviderRegistry(providers, {
|
|
7556
7584
|
}
|
7557
7585
|
var experimental_createProviderRegistry = createProviderRegistry;
|
7558
7586
|
var DefaultProviderRegistry = class {
|
7559
|
-
constructor({
|
7587
|
+
constructor({
|
7588
|
+
separator,
|
7589
|
+
languageModelMiddleware
|
7590
|
+
}) {
|
7560
7591
|
this.providers = {};
|
7561
7592
|
this.separator = separator;
|
7593
|
+
this.languageModelMiddleware = languageModelMiddleware;
|
7562
7594
|
}
|
7563
7595
|
registerProvider({
|
7564
7596
|
id,
|
@@ -7592,13 +7624,19 @@ var DefaultProviderRegistry = class {
|
|
7592
7624
|
languageModel(id) {
|
7593
7625
|
var _a16, _b;
|
7594
7626
|
const [providerId, modelId] = this.splitId(id, "languageModel");
|
7595
|
-
|
7627
|
+
let model = (_b = (_a16 = this.getProvider(providerId, "languageModel")).languageModel) == null ? void 0 : _b.call(
|
7596
7628
|
_a16,
|
7597
7629
|
modelId
|
7598
7630
|
);
|
7599
7631
|
if (model == null) {
|
7600
7632
|
throw new import_provider29.NoSuchModelError({ modelId: id, modelType: "languageModel" });
|
7601
7633
|
}
|
7634
|
+
if (this.languageModelMiddleware != null) {
|
7635
|
+
model = wrapLanguageModel({
|
7636
|
+
model,
|
7637
|
+
middleware: this.languageModelMiddleware
|
7638
|
+
});
|
7639
|
+
}
|
7602
7640
|
return model;
|
7603
7641
|
}
|
7604
7642
|
textEmbeddingModel(id) {
|
@@ -9337,6 +9375,7 @@ function readUIMessageStream({
|
|
9337
9375
|
tool,
|
9338
9376
|
toolModelMessageSchema,
|
9339
9377
|
userModelMessageSchema,
|
9340
|
-
wrapLanguageModel
|
9378
|
+
wrapLanguageModel,
|
9379
|
+
wrapProvider
|
9341
9380
|
});
|
9342
9381
|
//# sourceMappingURL=index.js.map
|