ai 5.0.249 → 5.0.251
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/index.d.mts +9 -17
- package/dist/index.d.ts +9 -17
- package/dist/index.js +87 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -22
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +4 -3
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +4 -3
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 5.0.251
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [78a29c2]
|
|
8
|
+
- @ai-sdk/gateway@2.0.145
|
|
9
|
+
|
|
10
|
+
## 5.0.250
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 4e3f54b: Validate persisted typed tool calls against current input and output schemas.
|
|
15
|
+
Schema-incompatible empty or error inputs and completed or failed history from
|
|
16
|
+
unavailable tools remain loadable as dynamic tool parts instead of exposing
|
|
17
|
+
unvalidated values under current static tool types.
|
|
18
|
+
- 26165ee: Mark transient network errors that occur while reading successful response bodies as retryable, including AI Gateway responses.
|
|
19
|
+
- Updated dependencies [810dc70]
|
|
20
|
+
- Updated dependencies [7a926ba]
|
|
21
|
+
- Updated dependencies [25c1956]
|
|
22
|
+
- Updated dependencies [26165ee]
|
|
23
|
+
- @ai-sdk/gateway@2.0.144
|
|
24
|
+
- @ai-sdk/provider-utils@3.0.36
|
|
25
|
+
|
|
3
26
|
## 5.0.249
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -4481,12 +4481,7 @@ type SafeValidateUIMessagesResult<UI_MESSAGE extends UIMessage> = {
|
|
|
4481
4481
|
success: false;
|
|
4482
4482
|
error: Error;
|
|
4483
4483
|
};
|
|
4484
|
-
|
|
4485
|
-
* Validates a list of UI messages like `validateUIMessages`,
|
|
4486
|
-
* but instead of throwing it returns `{ success: true, data }`
|
|
4487
|
-
* or `{ success: false, error }`.
|
|
4488
|
-
*/
|
|
4489
|
-
declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages, metadataSchema, dataSchemas, tools, }: {
|
|
4484
|
+
type ValidateUIMessagesOptions<UI_MESSAGE extends UIMessage> = {
|
|
4490
4485
|
messages: unknown;
|
|
4491
4486
|
metadataSchema?: Validator<UIMessage['metadata']> | StandardSchemaV1<unknown, UI_MESSAGE['metadata']>;
|
|
4492
4487
|
dataSchemas?: {
|
|
@@ -4495,7 +4490,13 @@ declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages
|
|
|
4495
4490
|
tools?: {
|
|
4496
4491
|
[NAME in keyof InferUIMessageTools<UI_MESSAGE> & string]?: Tool<InferUIMessageTools<UI_MESSAGE>[NAME]['input'], InferUIMessageTools<UI_MESSAGE>[NAME]['output']>;
|
|
4497
4492
|
};
|
|
4498
|
-
}
|
|
4493
|
+
};
|
|
4494
|
+
/**
|
|
4495
|
+
* Validates a list of UI messages like `validateUIMessages`,
|
|
4496
|
+
* but instead of throwing it returns `{ success: true, data }`
|
|
4497
|
+
* or `{ success: false, error }`.
|
|
4498
|
+
*/
|
|
4499
|
+
declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages, metadataSchema, dataSchemas, tools, }: ValidateUIMessagesOptions<UI_MESSAGE>): Promise<SafeValidateUIMessagesResult<UI_MESSAGE>>;
|
|
4499
4500
|
/**
|
|
4500
4501
|
* Validates a list of UI messages.
|
|
4501
4502
|
*
|
|
@@ -4503,15 +4504,6 @@ declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages
|
|
|
4503
4504
|
* the corresponding schemas are provided. Otherwise, they are assumed to be
|
|
4504
4505
|
* valid.
|
|
4505
4506
|
*/
|
|
4506
|
-
declare function validateUIMessages<UI_MESSAGE extends UIMessage>(
|
|
4507
|
-
messages: unknown;
|
|
4508
|
-
metadataSchema?: Validator<UIMessage['metadata']> | StandardSchemaV1<unknown, UI_MESSAGE['metadata']>;
|
|
4509
|
-
dataSchemas?: {
|
|
4510
|
-
[NAME in keyof InferUIMessageData<UI_MESSAGE> & string]?: Validator<InferUIMessageData<UI_MESSAGE>[NAME]> | StandardSchemaV1<unknown, InferUIMessageData<UI_MESSAGE>[NAME]>;
|
|
4511
|
-
};
|
|
4512
|
-
tools?: {
|
|
4513
|
-
[NAME in keyof InferUIMessageTools<UI_MESSAGE> & string]?: Tool<InferUIMessageTools<UI_MESSAGE>[NAME]['input'], InferUIMessageTools<UI_MESSAGE>[NAME]['output']>;
|
|
4514
|
-
};
|
|
4515
|
-
}): Promise<Array<UI_MESSAGE>>;
|
|
4507
|
+
declare function validateUIMessages<UI_MESSAGE extends UIMessage>(options: ValidateUIMessagesOptions<UI_MESSAGE>): Promise<Array<UI_MESSAGE>>;
|
|
4516
4508
|
|
|
4517
4509
|
export { AbstractChat, AsyncIterableStream, CallSettings, CallWarning, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, ErrorHandler, Agent as Experimental_Agent, AgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, Warning as Experimental_Warning, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoOutputSpecifiedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Output as OutputInterface, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StaticToolCall, StaticToolError, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, TypedToolCall, TypedToolError, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamOnFinishCallback, UIMessageStreamOptions, UIMessageStreamOutcome, UIMessageStreamWriter, UIMessageStreamWriterWithOutcome, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapLanguageModel, wrapProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -4481,12 +4481,7 @@ type SafeValidateUIMessagesResult<UI_MESSAGE extends UIMessage> = {
|
|
|
4481
4481
|
success: false;
|
|
4482
4482
|
error: Error;
|
|
4483
4483
|
};
|
|
4484
|
-
|
|
4485
|
-
* Validates a list of UI messages like `validateUIMessages`,
|
|
4486
|
-
* but instead of throwing it returns `{ success: true, data }`
|
|
4487
|
-
* or `{ success: false, error }`.
|
|
4488
|
-
*/
|
|
4489
|
-
declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages, metadataSchema, dataSchemas, tools, }: {
|
|
4484
|
+
type ValidateUIMessagesOptions<UI_MESSAGE extends UIMessage> = {
|
|
4490
4485
|
messages: unknown;
|
|
4491
4486
|
metadataSchema?: Validator<UIMessage['metadata']> | StandardSchemaV1<unknown, UI_MESSAGE['metadata']>;
|
|
4492
4487
|
dataSchemas?: {
|
|
@@ -4495,7 +4490,13 @@ declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages
|
|
|
4495
4490
|
tools?: {
|
|
4496
4491
|
[NAME in keyof InferUIMessageTools<UI_MESSAGE> & string]?: Tool<InferUIMessageTools<UI_MESSAGE>[NAME]['input'], InferUIMessageTools<UI_MESSAGE>[NAME]['output']>;
|
|
4497
4492
|
};
|
|
4498
|
-
}
|
|
4493
|
+
};
|
|
4494
|
+
/**
|
|
4495
|
+
* Validates a list of UI messages like `validateUIMessages`,
|
|
4496
|
+
* but instead of throwing it returns `{ success: true, data }`
|
|
4497
|
+
* or `{ success: false, error }`.
|
|
4498
|
+
*/
|
|
4499
|
+
declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages, metadataSchema, dataSchemas, tools, }: ValidateUIMessagesOptions<UI_MESSAGE>): Promise<SafeValidateUIMessagesResult<UI_MESSAGE>>;
|
|
4499
4500
|
/**
|
|
4500
4501
|
* Validates a list of UI messages.
|
|
4501
4502
|
*
|
|
@@ -4503,15 +4504,6 @@ declare function safeValidateUIMessages<UI_MESSAGE extends UIMessage>({ messages
|
|
|
4503
4504
|
* the corresponding schemas are provided. Otherwise, they are assumed to be
|
|
4504
4505
|
* valid.
|
|
4505
4506
|
*/
|
|
4506
|
-
declare function validateUIMessages<UI_MESSAGE extends UIMessage>(
|
|
4507
|
-
messages: unknown;
|
|
4508
|
-
metadataSchema?: Validator<UIMessage['metadata']> | StandardSchemaV1<unknown, UI_MESSAGE['metadata']>;
|
|
4509
|
-
dataSchemas?: {
|
|
4510
|
-
[NAME in keyof InferUIMessageData<UI_MESSAGE> & string]?: Validator<InferUIMessageData<UI_MESSAGE>[NAME]> | StandardSchemaV1<unknown, InferUIMessageData<UI_MESSAGE>[NAME]>;
|
|
4511
|
-
};
|
|
4512
|
-
tools?: {
|
|
4513
|
-
[NAME in keyof InferUIMessageTools<UI_MESSAGE> & string]?: Tool<InferUIMessageTools<UI_MESSAGE>[NAME]['input'], InferUIMessageTools<UI_MESSAGE>[NAME]['output']>;
|
|
4514
|
-
};
|
|
4515
|
-
}): Promise<Array<UI_MESSAGE>>;
|
|
4507
|
+
declare function validateUIMessages<UI_MESSAGE extends UIMessage>(options: ValidateUIMessagesOptions<UI_MESSAGE>): Promise<Array<UI_MESSAGE>>;
|
|
4516
4508
|
|
|
4517
4509
|
export { AbstractChat, AsyncIterableStream, CallSettings, CallWarning, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, ErrorHandler, Agent as Experimental_Agent, AgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, Warning as Experimental_Warning, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoOutputSpecifiedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Output as OutputInterface, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StaticToolCall, StaticToolError, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, TypedToolCall, TypedToolError, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamOnFinishCallback, UIMessageStreamOptions, UIMessageStreamOutcome, UIMessageStreamWriter, UIMessageStreamWriterWithOutcome, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapLanguageModel, wrapProvider };
|
package/dist/index.js
CHANGED
|
@@ -73,7 +73,7 @@ __export(src_exports, {
|
|
|
73
73
|
coreUserMessageSchema: () => coreUserMessageSchema,
|
|
74
74
|
cosineSimilarity: () => cosineSimilarity,
|
|
75
75
|
createDownload: () => createDownload,
|
|
76
|
-
createGateway: () =>
|
|
76
|
+
createGateway: () => import_gateway4.createGateway,
|
|
77
77
|
createIdGenerator: () => import_provider_utils35.createIdGenerator,
|
|
78
78
|
createProviderRegistry: () => createProviderRegistry,
|
|
79
79
|
createTextStreamResponse: () => createTextStreamResponse,
|
|
@@ -90,7 +90,7 @@ __export(src_exports, {
|
|
|
90
90
|
experimental_generateSpeech: () => generateSpeech,
|
|
91
91
|
experimental_transcribe: () => transcribe,
|
|
92
92
|
extractReasoningMiddleware: () => extractReasoningMiddleware,
|
|
93
|
-
gateway: () =>
|
|
93
|
+
gateway: () => import_gateway4.gateway,
|
|
94
94
|
generateId: () => import_provider_utils35.generateId,
|
|
95
95
|
generateObject: () => generateObject,
|
|
96
96
|
generateText: () => generateText,
|
|
@@ -132,7 +132,7 @@ __export(src_exports, {
|
|
|
132
132
|
zodSchema: () => import_provider_utils35.zodSchema
|
|
133
133
|
});
|
|
134
134
|
module.exports = __toCommonJS(src_exports);
|
|
135
|
-
var
|
|
135
|
+
var import_gateway4 = require("@ai-sdk/gateway");
|
|
136
136
|
var import_provider_utils35 = require("@ai-sdk/provider-utils");
|
|
137
137
|
|
|
138
138
|
// src/generate-text/generate-text.ts
|
|
@@ -816,7 +816,7 @@ function detectMediaType({
|
|
|
816
816
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
817
817
|
|
|
818
818
|
// src/version.ts
|
|
819
|
-
var VERSION = true ? "5.0.
|
|
819
|
+
var VERSION = true ? "5.0.251" : "0.0.0-test";
|
|
820
820
|
|
|
821
821
|
// src/util/download/download.ts
|
|
822
822
|
var download = async ({
|
|
@@ -1828,12 +1828,13 @@ function asArray(value) {
|
|
|
1828
1828
|
|
|
1829
1829
|
// src/util/retry-with-exponential-backoff.ts
|
|
1830
1830
|
var import_provider21 = require("@ai-sdk/provider");
|
|
1831
|
+
var import_gateway3 = require("@ai-sdk/gateway");
|
|
1831
1832
|
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1832
1833
|
function getRetryDelayInMs({
|
|
1833
1834
|
error,
|
|
1834
1835
|
exponentialBackoffDelay
|
|
1835
1836
|
}) {
|
|
1836
|
-
const headers = error.responseHeaders;
|
|
1837
|
+
const headers = import_provider21.APICallError.isInstance(error) ? error.responseHeaders : import_provider21.APICallError.isInstance(error.cause) ? error.cause.responseHeaders : void 0;
|
|
1837
1838
|
if (!headers)
|
|
1838
1839
|
return exponentialBackoffDelay;
|
|
1839
1840
|
let ms;
|
|
@@ -1894,7 +1895,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
|
1894
1895
|
errors: newErrors
|
|
1895
1896
|
});
|
|
1896
1897
|
}
|
|
1897
|
-
if (error instanceof Error && import_provider21.APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
|
1898
|
+
if (error instanceof Error && (import_provider21.APICallError.isInstance(error) && error.isRetryable === true || import_gateway3.GatewayError.isInstance(error) && error.isRetryable === true) && tryNumber <= maxRetries) {
|
|
1898
1899
|
await (0, import_provider_utils7.delay)(
|
|
1899
1900
|
getRetryDelayInMs({
|
|
1900
1901
|
error,
|
|
@@ -10105,6 +10106,33 @@ var TextStreamChatTransport = class extends HttpChatTransport {
|
|
|
10105
10106
|
var import_provider30 = require("@ai-sdk/provider");
|
|
10106
10107
|
var import_provider_utils33 = require("@ai-sdk/provider-utils");
|
|
10107
10108
|
var import_v48 = require("zod/v4");
|
|
10109
|
+
function isEmptyObject(value) {
|
|
10110
|
+
return value != null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
|
|
10111
|
+
}
|
|
10112
|
+
function asDynamicToolPart(toolPart) {
|
|
10113
|
+
const common = {
|
|
10114
|
+
type: "dynamic-tool",
|
|
10115
|
+
toolName: toolPart.type.slice(5),
|
|
10116
|
+
toolCallId: toolPart.toolCallId,
|
|
10117
|
+
...toolPart.providerExecuted === void 0 ? {} : { providerExecuted: toolPart.providerExecuted },
|
|
10118
|
+
...toolPart.callProviderMetadata === void 0 ? {} : { callProviderMetadata: toolPart.callProviderMetadata }
|
|
10119
|
+
};
|
|
10120
|
+
if (toolPart.state === "output-available") {
|
|
10121
|
+
return {
|
|
10122
|
+
...common,
|
|
10123
|
+
state: "output-available",
|
|
10124
|
+
input: toolPart.input,
|
|
10125
|
+
output: toolPart.output,
|
|
10126
|
+
...toolPart.preliminary === void 0 ? {} : { preliminary: toolPart.preliminary }
|
|
10127
|
+
};
|
|
10128
|
+
}
|
|
10129
|
+
return {
|
|
10130
|
+
...common,
|
|
10131
|
+
state: "output-error",
|
|
10132
|
+
input: toolPart.input,
|
|
10133
|
+
errorText: toolPart.errorText
|
|
10134
|
+
};
|
|
10135
|
+
}
|
|
10108
10136
|
var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
|
|
10109
10137
|
() => (0, import_provider_utils33.zodSchema)(
|
|
10110
10138
|
import_v48.z.array(
|
|
@@ -10195,7 +10223,8 @@ var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
|
|
|
10195
10223
|
toolName: import_v48.z.string(),
|
|
10196
10224
|
toolCallId: import_v48.z.string(),
|
|
10197
10225
|
state: import_v48.z.literal("output-error"),
|
|
10198
|
-
input: import_v48.z.unknown(),
|
|
10226
|
+
input: import_v48.z.unknown().optional(),
|
|
10227
|
+
rawInput: import_v48.z.unknown().optional(),
|
|
10199
10228
|
providerExecuted: import_v48.z.boolean().optional(),
|
|
10200
10229
|
output: import_v48.z.never().optional(),
|
|
10201
10230
|
errorText: import_v48.z.string(),
|
|
@@ -10273,7 +10302,8 @@ var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
|
|
|
10273
10302
|
toolCallId: import_v48.z.string(),
|
|
10274
10303
|
state: import_v48.z.literal("output-error"),
|
|
10275
10304
|
providerExecuted: import_v48.z.boolean().optional(),
|
|
10276
|
-
input: import_v48.z.unknown(),
|
|
10305
|
+
input: import_v48.z.unknown().optional(),
|
|
10306
|
+
rawInput: import_v48.z.unknown().optional(),
|
|
10277
10307
|
output: import_v48.z.never().optional(),
|
|
10278
10308
|
errorText: import_v48.z.string(),
|
|
10279
10309
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
@@ -10337,6 +10367,17 @@ async function safeValidateUIMessages({
|
|
|
10337
10367
|
value: messages,
|
|
10338
10368
|
schema: uiMessagesSchema
|
|
10339
10369
|
});
|
|
10370
|
+
for (const message of validatedMessages) {
|
|
10371
|
+
for (const part of message.parts) {
|
|
10372
|
+
if (part.type !== "dynamic-tool" && !part.type.startsWith("tool-")) {
|
|
10373
|
+
continue;
|
|
10374
|
+
}
|
|
10375
|
+
const toolPart = part;
|
|
10376
|
+
if (toolPart.state === "output-error" && !("input" in toolPart)) {
|
|
10377
|
+
toolPart.input = void 0;
|
|
10378
|
+
}
|
|
10379
|
+
}
|
|
10380
|
+
}
|
|
10340
10381
|
if (metadataSchema) {
|
|
10341
10382
|
for (const message of validatedMessages) {
|
|
10342
10383
|
await (0, import_provider_utils33.validateTypes)({
|
|
@@ -10371,12 +10412,17 @@ async function safeValidateUIMessages({
|
|
|
10371
10412
|
}
|
|
10372
10413
|
if (tools) {
|
|
10373
10414
|
for (const message of validatedMessages) {
|
|
10374
|
-
const
|
|
10375
|
-
(part
|
|
10376
|
-
|
|
10377
|
-
|
|
10415
|
+
for (const [partIdx, part] of message.parts.entries()) {
|
|
10416
|
+
if (!part.type.startsWith("tool-")) {
|
|
10417
|
+
continue;
|
|
10418
|
+
}
|
|
10419
|
+
const toolPart = part;
|
|
10378
10420
|
const toolName = toolPart.type.slice(5);
|
|
10379
10421
|
const tool2 = tools[toolName];
|
|
10422
|
+
if (!tool2 && (toolPart.state === "output-available" || toolPart.state === "output-error")) {
|
|
10423
|
+
message.parts[partIdx] = asDynamicToolPart(toolPart);
|
|
10424
|
+
continue;
|
|
10425
|
+
}
|
|
10380
10426
|
if (!tool2) {
|
|
10381
10427
|
return {
|
|
10382
10428
|
success: false,
|
|
@@ -10386,7 +10432,30 @@ async function safeValidateUIMessages({
|
|
|
10386
10432
|
})
|
|
10387
10433
|
};
|
|
10388
10434
|
}
|
|
10389
|
-
|
|
10435
|
+
let dynamicToolPart;
|
|
10436
|
+
if (toolPart.state === "output-error") {
|
|
10437
|
+
if (toolPart.input !== void 0) {
|
|
10438
|
+
const result = await (0, import_provider_utils33.safeValidateTypes)({
|
|
10439
|
+
value: toolPart.input,
|
|
10440
|
+
schema: tool2.inputSchema
|
|
10441
|
+
});
|
|
10442
|
+
if (!result.success) {
|
|
10443
|
+
dynamicToolPart = asDynamicToolPart(toolPart);
|
|
10444
|
+
}
|
|
10445
|
+
}
|
|
10446
|
+
} else if (toolPart.state === "output-available") {
|
|
10447
|
+
const result = await (0, import_provider_utils33.safeValidateTypes)({
|
|
10448
|
+
value: toolPart.input,
|
|
10449
|
+
schema: tool2.inputSchema
|
|
10450
|
+
});
|
|
10451
|
+
if (!result.success) {
|
|
10452
|
+
if (isEmptyObject(toolPart.input)) {
|
|
10453
|
+
dynamicToolPart = asDynamicToolPart(toolPart);
|
|
10454
|
+
} else {
|
|
10455
|
+
throw result.error;
|
|
10456
|
+
}
|
|
10457
|
+
}
|
|
10458
|
+
} else if (toolPart.state === "input-available") {
|
|
10390
10459
|
await (0, import_provider_utils33.validateTypes)({
|
|
10391
10460
|
value: toolPart.input,
|
|
10392
10461
|
schema: tool2.inputSchema
|
|
@@ -10398,6 +10467,9 @@ async function safeValidateUIMessages({
|
|
|
10398
10467
|
schema: tool2.outputSchema
|
|
10399
10468
|
});
|
|
10400
10469
|
}
|
|
10470
|
+
if (dynamicToolPart) {
|
|
10471
|
+
message.parts[partIdx] = dynamicToolPart;
|
|
10472
|
+
}
|
|
10401
10473
|
}
|
|
10402
10474
|
}
|
|
10403
10475
|
}
|
|
@@ -10413,18 +10485,8 @@ async function safeValidateUIMessages({
|
|
|
10413
10485
|
};
|
|
10414
10486
|
}
|
|
10415
10487
|
}
|
|
10416
|
-
async function validateUIMessages({
|
|
10417
|
-
|
|
10418
|
-
metadataSchema,
|
|
10419
|
-
dataSchemas,
|
|
10420
|
-
tools
|
|
10421
|
-
}) {
|
|
10422
|
-
const response = await safeValidateUIMessages({
|
|
10423
|
-
messages,
|
|
10424
|
-
metadataSchema,
|
|
10425
|
-
dataSchemas,
|
|
10426
|
-
tools
|
|
10427
|
-
});
|
|
10488
|
+
async function validateUIMessages(options) {
|
|
10489
|
+
const response = await safeValidateUIMessages(options);
|
|
10428
10490
|
if (!response.success)
|
|
10429
10491
|
throw response.error;
|
|
10430
10492
|
return response.data;
|