ai 7.0.0-beta.113 → 7.0.0-beta.115
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 +32 -0
- package/dist/index.d.ts +1506 -1468
- package/dist/index.js +889 -979
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +273 -273
- package/dist/internal/index.js +367 -405
- package/dist/internal/index.js.map +1 -1
- package/dist/test/index.d.ts +18 -18
- package/dist/test/index.js +22 -22
- package/dist/test/index.js.map +1 -1
- package/docs/02-foundations/03-prompts.mdx +13 -11
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +2 -1
- package/docs/03-ai-sdk-core/39-file-uploads.mdx +1 -1
- package/docs/03-ai-sdk-core/45-provider-management.mdx +1 -1
- package/docs/03-ai-sdk-core/60-telemetry.mdx +87 -13
- package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/20-tool.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/30-model-message.mdx +9 -1
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +104 -0
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +56 -10
- package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +1 -1
- package/docs/08-migration-guides/23-migration-guide-7-0.mdx +42 -0
- package/docs/09-troubleshooting/70-high-memory-usage-with-images.mdx +2 -2
- package/package.json +5 -5
- package/src/agent/agent.ts +13 -9
- package/src/agent/create-agent-ui-stream-response.ts +8 -8
- package/src/agent/create-agent-ui-stream.ts +9 -9
- package/src/agent/infer-agent-tools.ts +1 -1
- package/src/agent/infer-agent-ui-message.ts +2 -2
- package/src/agent/pipe-agent-ui-stream-to-response.ts +9 -9
- package/src/agent/tool-loop-agent-settings.ts +17 -19
- package/src/agent/tool-loop-agent.ts +16 -8
- package/src/embed/embed-many-result.ts +3 -4
- package/src/embed/embed-many.ts +5 -5
- package/src/embed/embed-result.ts +3 -4
- package/src/embed/embed.ts +4 -4
- package/src/error/invalid-stream-part-error.ts +1 -1
- package/src/error/no-image-generated-error.ts +1 -1
- package/src/error/no-object-generated-error.ts +3 -3
- package/src/error/no-speech-generated-error.ts +1 -1
- package/src/error/no-transcript-generated-error.ts +1 -1
- package/src/error/no-video-generated-error.ts +1 -1
- package/src/error/tool-call-repair-error.ts +2 -2
- package/src/error/verify-no-object-generated-error.ts +1 -1
- package/src/generate-image/generate-image-result.ts +5 -5
- package/src/generate-image/generate-image.ts +12 -15
- package/src/generate-image/index.ts +3 -2
- package/src/generate-object/generate-object-result.ts +2 -2
- package/src/generate-object/generate-object.ts +14 -14
- package/src/generate-object/inject-json-instruction.ts +1 -1
- package/src/generate-object/output-strategy.ts +10 -10
- package/src/generate-object/parse-and-validate-object-result.ts +1 -1
- package/src/generate-object/repair-text.ts +1 -1
- package/src/generate-object/stream-object-result.ts +4 -4
- package/src/generate-object/stream-object.ts +22 -19
- package/src/generate-object/validate-object-generation-input.ts +1 -1
- package/src/generate-speech/generate-speech-result.ts +4 -4
- package/src/generate-speech/generate-speech.ts +12 -13
- package/src/generate-speech/generated-audio-file.ts +1 -2
- package/src/generate-text/collect-tool-approvals.ts +4 -4
- package/src/generate-text/content-part.ts +9 -9
- package/src/generate-text/create-execute-tools-transformation.ts +9 -7
- package/src/generate-text/execute-tool-call.ts +11 -13
- package/src/generate-text/extract-reasoning-content.ts +1 -1
- package/src/generate-text/extract-text-content.ts +4 -1
- package/src/generate-text/generate-text-events.ts +2 -2
- package/src/generate-text/generate-text-result.ts +18 -14
- package/src/generate-text/generate-text.ts +42 -38
- package/src/generate-text/invoke-tool-callbacks-from-stream.ts +2 -3
- package/src/generate-text/output-utils.ts +1 -1
- package/src/generate-text/output.ts +8 -8
- package/src/generate-text/parse-tool-call.ts +36 -9
- package/src/generate-text/prepare-step.ts +3 -5
- package/src/generate-text/prune-messages.ts +1 -1
- package/src/generate-text/reasoning-output.ts +26 -9
- package/src/generate-text/reasoning.ts +1 -1
- package/src/generate-text/resolve-tool-approval.ts +3 -3
- package/src/generate-text/response-message.ts +1 -1
- package/src/generate-text/restricted-telemetry-dispatcher.ts +1 -1
- package/src/generate-text/smooth-stream.ts +6 -5
- package/src/generate-text/step-result.ts +16 -11
- package/src/generate-text/stop-condition.ts +1 -1
- package/src/generate-text/stream-language-model-call.ts +26 -21
- package/src/generate-text/stream-text-result.ts +29 -26
- package/src/generate-text/stream-text.ts +48 -46
- package/src/generate-text/to-response-messages.ts +2 -2
- package/src/generate-text/tool-approval-configuration.ts +2 -2
- package/src/generate-text/tool-approval-request-output.ts +1 -1
- package/src/generate-text/tool-approval-response-output.ts +1 -1
- package/src/generate-text/tool-call-repair-function.ts +4 -4
- package/src/generate-text/tool-call.ts +3 -4
- package/src/generate-text/tool-error.ts +3 -4
- package/src/generate-text/tool-execution-events.ts +2 -2
- package/src/generate-text/tool-output-denied.ts +1 -1
- package/src/generate-text/tool-output.ts +2 -2
- package/src/generate-text/tool-result.ts +7 -4
- package/src/generate-text/tools-context-parameter.ts +1 -1
- package/src/generate-text/validate-tool-context.ts +1 -2
- package/src/generate-video/generate-video-result.ts +4 -4
- package/src/generate-video/generate-video.ts +6 -10
- package/src/global.ts +2 -2
- package/src/index.ts +3 -3
- package/src/logger/log-warnings.ts +1 -1
- package/src/middleware/add-tool-input-examples-middleware.ts +2 -2
- package/src/middleware/default-embedding-settings-middleware.ts +2 -2
- package/src/middleware/default-settings-middleware.ts +2 -2
- package/src/middleware/extract-json-middleware.ts +1 -1
- package/src/middleware/extract-reasoning-middleware.ts +1 -1
- package/src/middleware/simulate-streaming-middleware.ts +1 -1
- package/src/middleware/wrap-embedding-model.ts +2 -2
- package/src/middleware/wrap-image-model.ts +2 -2
- package/src/middleware/wrap-language-model.ts +2 -2
- package/src/middleware/wrap-provider.ts +2 -2
- package/src/model/as-embedding-model-v3.ts +1 -1
- package/src/model/as-embedding-model-v4.ts +1 -1
- package/src/model/as-image-model-v3.ts +1 -1
- package/src/model/as-image-model-v4.ts +5 -1
- package/src/model/as-language-model-v3.ts +1 -1
- package/src/model/as-language-model-v4.ts +1 -1
- package/src/model/as-provider-v3.ts +1 -1
- package/src/model/as-provider-v4.ts +1 -1
- package/src/model/as-reranking-model-v4.ts +1 -1
- package/src/model/as-speech-model-v3.ts +1 -1
- package/src/model/as-speech-model-v4.ts +5 -1
- package/src/model/as-transcription-model-v3.ts +4 -1
- package/src/model/as-transcription-model-v4.ts +1 -1
- package/src/model/as-video-model-v4.ts +1 -1
- package/src/model/resolve-model.ts +8 -8
- package/src/prompt/content-part.ts +45 -15
- package/src/prompt/convert-to-language-model-prompt.ts +108 -122
- package/src/prompt/create-tool-model-output.ts +2 -2
- package/src/prompt/data-content.ts +1 -78
- package/src/prompt/file-part-data.ts +125 -0
- package/src/prompt/index.ts +3 -2
- package/src/prompt/language-model-call-options.ts +1 -1
- package/src/prompt/message-conversion-error.ts +1 -1
- package/src/prompt/message.ts +1 -1
- package/src/prompt/prepare-language-model-call-options.ts +1 -1
- package/src/prompt/prepare-tool-choice.ts +2 -2
- package/src/prompt/prepare-tools.ts +2 -2
- package/src/prompt/prompt.ts +1 -1
- package/src/prompt/standardize-prompt.ts +3 -3
- package/src/registry/custom-provider.ts +127 -92
- package/src/registry/index.ts +1 -1
- package/src/registry/provider-registry.ts +91 -87
- package/src/rerank/rerank-result.ts +1 -1
- package/src/rerank/rerank.ts +8 -5
- package/src/telemetry/create-telemetry-dispatcher.ts +11 -1
- package/src/telemetry/diagnostic-channel-publisher.ts +50 -0
- package/src/telemetry/diagnostic-channel.ts +24 -0
- package/src/telemetry/index.ts +5 -0
- package/src/telemetry/telemetry.ts +1 -1
- package/src/test/mock-embedding-model-v2.ts +1 -1
- package/src/test/mock-embedding-model-v3.ts +1 -1
- package/src/test/mock-embedding-model-v4.ts +1 -1
- package/src/test/mock-image-model-v2.ts +1 -1
- package/src/test/mock-image-model-v3.ts +1 -1
- package/src/test/mock-image-model-v4.ts +1 -1
- package/src/test/mock-language-model-v2.ts +1 -1
- package/src/test/mock-language-model-v3.ts +1 -1
- package/src/test/mock-language-model-v4.ts +1 -1
- package/src/test/mock-provider-v2.ts +6 -7
- package/src/test/mock-provider-v3.ts +7 -8
- package/src/test/mock-provider-v4.ts +7 -8
- package/src/test/mock-reranking-model-v3.ts +1 -1
- package/src/test/mock-reranking-model-v4.ts +1 -1
- package/src/test/mock-server-response.ts +1 -1
- package/src/test/mock-speech-model-v2.ts +1 -1
- package/src/test/mock-speech-model-v3.ts +1 -1
- package/src/test/mock-speech-model-v4.ts +1 -1
- package/src/test/mock-transcription-model-v2.ts +1 -1
- package/src/test/mock-transcription-model-v3.ts +1 -1
- package/src/test/mock-transcription-model-v4.ts +1 -1
- package/src/test/mock-video-model-v3.ts +1 -1
- package/src/test/mock-video-model-v4.ts +1 -1
- package/src/text-stream/pipe-text-stream-to-response.ts +1 -1
- package/src/transcribe/transcribe-result.ts +3 -3
- package/src/transcribe/transcribe.ts +12 -12
- package/src/types/embedding-model-middleware.ts +1 -1
- package/src/types/embedding-model.ts +1 -1
- package/src/types/image-model-middleware.ts +1 -1
- package/src/types/image-model.ts +1 -1
- package/src/types/json-value.ts +1 -1
- package/src/types/language-model-middleware.ts +1 -1
- package/src/types/language-model.ts +2 -2
- package/src/types/provider-metadata.ts +1 -1
- package/src/types/provider-reference.ts +1 -1
- package/src/types/provider.ts +4 -4
- package/src/types/reranking-model.ts +1 -1
- package/src/types/speech-model.ts +5 -1
- package/src/types/transcription-model.ts +1 -1
- package/src/types/usage.ts +1 -1
- package/src/types/video-model.ts +1 -1
- package/src/types/warning.ts +1 -1
- package/src/ui/call-completion-api.ts +2 -2
- package/src/ui/chat-transport.ts +3 -3
- package/src/ui/chat.ts +10 -11
- package/src/ui/convert-file-list-to-file-ui-parts.ts +1 -1
- package/src/ui/convert-to-model-messages.ts +34 -23
- package/src/ui/default-chat-transport.ts +4 -4
- package/src/ui/direct-chat-transport.ts +6 -6
- package/src/ui/http-chat-transport.ts +5 -5
- package/src/ui/last-assistant-message-is-complete-with-approval-responses.ts +0 -1
- package/src/ui/last-assistant-message-is-complete-with-tool-calls.ts +0 -1
- package/src/ui/process-ui-message-stream.ts +20 -21
- package/src/ui/text-stream-chat-transport.ts +3 -3
- package/src/ui/transform-text-to-ui-message-stream.ts +1 -1
- package/src/ui/ui-messages.ts +13 -6
- package/src/ui/use-completion.ts +1 -1
- package/src/ui/validate-ui-messages.ts +3 -3
- package/src/ui-message-stream/create-ui-message-stream-response.ts +2 -2
- package/src/ui-message-stream/create-ui-message-stream.ts +6 -6
- package/src/ui-message-stream/get-response-ui-message-id.ts +2 -2
- package/src/ui-message-stream/handle-ui-message-stream-finish.ts +6 -6
- package/src/ui-message-stream/pipe-ui-message-stream-to-response.ts +3 -3
- package/src/ui-message-stream/read-ui-message-stream.ts +4 -4
- package/src/ui-message-stream/ui-message-chunks.ts +4 -4
- package/src/ui-message-stream/ui-message-stream-on-finish-callback.ts +2 -2
- package/src/ui-message-stream/ui-message-stream-on-step-finish-callback.ts +1 -1
- package/src/ui-message-stream/ui-message-stream-writer.ts +3 -3
- package/src/upload-file/upload-file-result.ts +3 -3
- package/src/upload-file/upload-file.ts +34 -56
- package/src/upload-skill/upload-skill-result.ts +3 -3
- package/src/upload-skill/upload-skill.ts +27 -8
- package/src/util/create-resolvable-promise.ts +1 -1
- package/src/util/deep-partial.ts +1 -1
- package/src/util/download/download.ts +0 -2
- package/src/util/extract-literal-union.ts +18 -0
- package/src/util/is-node-runtime.ts +3 -0
- package/src/util/notify.ts +1 -1
- package/src/util/parse-partial-json.ts +1 -1
- package/src/util/prepare-retries.ts +1 -2
- package/src/util/serial-job-executor.ts +1 -1
- package/src/util/write-to-server-response.ts +1 -1
- package/src/util/detect-media-type.ts +0 -235
package/dist/internal/index.js
CHANGED
|
@@ -8,13 +8,13 @@ function createAsyncIterableStream(source) {
|
|
|
8
8
|
const reader = this.getReader();
|
|
9
9
|
let finished = false;
|
|
10
10
|
async function cleanup(cancelStream) {
|
|
11
|
-
var
|
|
11
|
+
var _a6;
|
|
12
12
|
if (finished)
|
|
13
13
|
return;
|
|
14
14
|
finished = true;
|
|
15
15
|
try {
|
|
16
16
|
if (cancelStream) {
|
|
17
|
-
await ((
|
|
17
|
+
await ((_a6 = reader.cancel) == null ? void 0 : _a6.call(reader));
|
|
18
18
|
}
|
|
19
19
|
} finally {
|
|
20
20
|
try {
|
|
@@ -66,138 +66,23 @@ function createAsyncIterableStream(source) {
|
|
|
66
66
|
// src/prompt/convert-to-language-model-prompt.ts
|
|
67
67
|
import {
|
|
68
68
|
asArray,
|
|
69
|
-
|
|
69
|
+
detectMediaType,
|
|
70
|
+
isFullMediaType,
|
|
70
71
|
isUrlSupported
|
|
71
72
|
} from "@ai-sdk/provider-utils";
|
|
72
73
|
|
|
73
|
-
// src/util/detect-media-type.ts
|
|
74
|
-
import { convertBase64ToUint8Array } from "@ai-sdk/provider-utils";
|
|
75
|
-
var imageMediaTypeSignatures = [
|
|
76
|
-
{
|
|
77
|
-
mediaType: "image/gif",
|
|
78
|
-
bytesPrefix: [71, 73, 70]
|
|
79
|
-
// GIF
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
mediaType: "image/png",
|
|
83
|
-
bytesPrefix: [137, 80, 78, 71]
|
|
84
|
-
// PNG
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
mediaType: "image/jpeg",
|
|
88
|
-
bytesPrefix: [255, 216]
|
|
89
|
-
// JPEG
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
mediaType: "image/webp",
|
|
93
|
-
bytesPrefix: [
|
|
94
|
-
82,
|
|
95
|
-
73,
|
|
96
|
-
70,
|
|
97
|
-
70,
|
|
98
|
-
// "RIFF"
|
|
99
|
-
null,
|
|
100
|
-
null,
|
|
101
|
-
null,
|
|
102
|
-
null,
|
|
103
|
-
// file size (variable)
|
|
104
|
-
87,
|
|
105
|
-
69,
|
|
106
|
-
66,
|
|
107
|
-
80
|
|
108
|
-
// "WEBP"
|
|
109
|
-
]
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
mediaType: "image/bmp",
|
|
113
|
-
bytesPrefix: [66, 77]
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
mediaType: "image/tiff",
|
|
117
|
-
bytesPrefix: [73, 73, 42, 0]
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
mediaType: "image/tiff",
|
|
121
|
-
bytesPrefix: [77, 77, 0, 42]
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
mediaType: "image/avif",
|
|
125
|
-
bytesPrefix: [
|
|
126
|
-
0,
|
|
127
|
-
0,
|
|
128
|
-
0,
|
|
129
|
-
32,
|
|
130
|
-
102,
|
|
131
|
-
116,
|
|
132
|
-
121,
|
|
133
|
-
112,
|
|
134
|
-
97,
|
|
135
|
-
118,
|
|
136
|
-
105,
|
|
137
|
-
102
|
|
138
|
-
]
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
mediaType: "image/heic",
|
|
142
|
-
bytesPrefix: [
|
|
143
|
-
0,
|
|
144
|
-
0,
|
|
145
|
-
0,
|
|
146
|
-
32,
|
|
147
|
-
102,
|
|
148
|
-
116,
|
|
149
|
-
121,
|
|
150
|
-
112,
|
|
151
|
-
104,
|
|
152
|
-
101,
|
|
153
|
-
105,
|
|
154
|
-
99
|
|
155
|
-
]
|
|
156
|
-
}
|
|
157
|
-
];
|
|
158
|
-
var stripID3 = (data) => {
|
|
159
|
-
const bytes = typeof data === "string" ? convertBase64ToUint8Array(data) : data;
|
|
160
|
-
const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
|
|
161
|
-
return bytes.slice(id3Size + 10);
|
|
162
|
-
};
|
|
163
|
-
function stripID3TagsIfPresent(data) {
|
|
164
|
-
const hasId3 = typeof data === "string" && data.startsWith("SUQz") || typeof data !== "string" && data.length > 10 && data[0] === 73 && // 'I'
|
|
165
|
-
data[1] === 68 && // 'D'
|
|
166
|
-
data[2] === 51;
|
|
167
|
-
return hasId3 ? stripID3(data) : data;
|
|
168
|
-
}
|
|
169
|
-
function detectMediaType({
|
|
170
|
-
data,
|
|
171
|
-
signatures
|
|
172
|
-
}) {
|
|
173
|
-
const processedData = stripID3TagsIfPresent(data);
|
|
174
|
-
const bytes = typeof processedData === "string" ? convertBase64ToUint8Array(
|
|
175
|
-
processedData.substring(0, Math.min(processedData.length, 24))
|
|
176
|
-
) : processedData;
|
|
177
|
-
for (const signature of signatures) {
|
|
178
|
-
if (bytes.length >= signature.bytesPrefix.length && signature.bytesPrefix.every(
|
|
179
|
-
(byte, index) => byte === null || bytes[index] === byte
|
|
180
|
-
)) {
|
|
181
|
-
return signature.mediaType;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return void 0;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
74
|
// src/util/download/download.ts
|
|
188
75
|
import {
|
|
189
76
|
DownloadError,
|
|
190
77
|
readResponseWithSizeLimit,
|
|
191
78
|
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
192
|
-
validateDownloadUrl
|
|
193
|
-
} from "@ai-sdk/provider-utils";
|
|
194
|
-
import {
|
|
79
|
+
validateDownloadUrl,
|
|
195
80
|
withUserAgentSuffix,
|
|
196
81
|
getRuntimeEnvironmentUserAgent
|
|
197
82
|
} from "@ai-sdk/provider-utils";
|
|
198
83
|
|
|
199
84
|
// src/version.ts
|
|
200
|
-
var VERSION = true ? "7.0.0-beta.
|
|
85
|
+
var VERSION = true ? "7.0.0-beta.115" : "0.0.0-test";
|
|
201
86
|
|
|
202
87
|
// src/util/download/download.ts
|
|
203
88
|
var download = async ({
|
|
@@ -205,7 +90,7 @@ var download = async ({
|
|
|
205
90
|
maxBytes,
|
|
206
91
|
abortSignal
|
|
207
92
|
}) => {
|
|
208
|
-
var
|
|
93
|
+
var _a6;
|
|
209
94
|
const urlText = url.toString();
|
|
210
95
|
validateDownloadUrl(urlText);
|
|
211
96
|
try {
|
|
@@ -234,7 +119,7 @@ var download = async ({
|
|
|
234
119
|
});
|
|
235
120
|
return {
|
|
236
121
|
data,
|
|
237
|
-
mediaType: (
|
|
122
|
+
mediaType: (_a6 = response.headers.get("content-type")) != null ? _a6 : void 0
|
|
238
123
|
};
|
|
239
124
|
} catch (error) {
|
|
240
125
|
if (DownloadError.isInstance(error)) {
|
|
@@ -251,13 +136,33 @@ var createDefaultDownloadFunction = (download2 = download) => (requestedDownload
|
|
|
251
136
|
)
|
|
252
137
|
);
|
|
253
138
|
|
|
254
|
-
// src/prompt/data
|
|
255
|
-
import { AISDKError } from "@ai-sdk/provider";
|
|
139
|
+
// src/prompt/file-part-data.ts
|
|
256
140
|
import {
|
|
257
|
-
|
|
258
|
-
|
|
141
|
+
isBuffer,
|
|
142
|
+
isProviderReference
|
|
259
143
|
} from "@ai-sdk/provider-utils";
|
|
260
|
-
|
|
144
|
+
|
|
145
|
+
// src/prompt/invalid-data-content-error.ts
|
|
146
|
+
import { AISDKError } from "@ai-sdk/provider";
|
|
147
|
+
var name = "AI_InvalidDataContentError";
|
|
148
|
+
var marker = `vercel.ai.error.${name}`;
|
|
149
|
+
var symbol = Symbol.for(marker);
|
|
150
|
+
var _a;
|
|
151
|
+
var InvalidDataContentError = class extends AISDKError {
|
|
152
|
+
constructor({
|
|
153
|
+
content,
|
|
154
|
+
cause,
|
|
155
|
+
message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
|
|
156
|
+
}) {
|
|
157
|
+
super({ name, message, cause });
|
|
158
|
+
this[_a] = true;
|
|
159
|
+
this.content = content;
|
|
160
|
+
}
|
|
161
|
+
static isInstance(error) {
|
|
162
|
+
return AISDKError.hasMarker(error, marker);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
_a = symbol;
|
|
261
166
|
|
|
262
167
|
// src/prompt/split-data-url.ts
|
|
263
168
|
function splitDataUrl(dataUrl) {
|
|
@@ -275,46 +180,89 @@ function splitDataUrl(dataUrl) {
|
|
|
275
180
|
}
|
|
276
181
|
}
|
|
277
182
|
|
|
278
|
-
// src/prompt/data
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
183
|
+
// src/prompt/file-part-data.ts
|
|
184
|
+
function isTaggedFileData(value) {
|
|
185
|
+
if (typeof value !== "object" || value === null)
|
|
186
|
+
return false;
|
|
187
|
+
const type = value.type;
|
|
188
|
+
return type === "data" || type === "url" || type === "reference" || type === "text";
|
|
189
|
+
}
|
|
190
|
+
function convertUrlToFilePartData(url) {
|
|
191
|
+
if (url.protocol === "data:") {
|
|
192
|
+
const { mediaType, base64Content } = splitDataUrl(url.toString());
|
|
193
|
+
if (mediaType == null || base64Content == null) {
|
|
194
|
+
throw new InvalidDataContentError({
|
|
195
|
+
content: url,
|
|
196
|
+
message: `Invalid data URL format in content ${url.toString()}`
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
return { data: { type: "data", data: base64Content }, mediaType };
|
|
200
|
+
}
|
|
201
|
+
return { data: { type: "url", url }, mediaType: void 0 };
|
|
202
|
+
}
|
|
203
|
+
function convertInlineDataToFilePartData(content) {
|
|
293
204
|
if (content instanceof Uint8Array) {
|
|
294
|
-
return { data: content, mediaType: void 0 };
|
|
205
|
+
return { data: { type: "data", data: content }, mediaType: void 0 };
|
|
295
206
|
}
|
|
296
207
|
if (content instanceof ArrayBuffer) {
|
|
297
|
-
return {
|
|
208
|
+
return {
|
|
209
|
+
data: { type: "data", data: new Uint8Array(content) },
|
|
210
|
+
mediaType: void 0
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
if (isBuffer(content)) {
|
|
214
|
+
return {
|
|
215
|
+
data: { type: "data", data: new Uint8Array(content) },
|
|
216
|
+
mediaType: void 0
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
data: { type: "data", data: content },
|
|
221
|
+
mediaType: void 0
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function convertToLanguageModelV4FilePart(content) {
|
|
225
|
+
if (isTaggedFileData(content)) {
|
|
226
|
+
switch (content.type) {
|
|
227
|
+
case "data":
|
|
228
|
+
if (typeof content.data === "string" && content.data.startsWith("data:")) {
|
|
229
|
+
throw new InvalidDataContentError({
|
|
230
|
+
content: content.data,
|
|
231
|
+
message: 'Data URLs are not valid inline data. Pass them as { type: "url", url } instead.'
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
return convertInlineDataToFilePartData(content.data);
|
|
235
|
+
case "url":
|
|
236
|
+
return convertUrlToFilePartData(content.url);
|
|
237
|
+
case "reference":
|
|
238
|
+
return {
|
|
239
|
+
data: { type: "reference", reference: content.reference },
|
|
240
|
+
mediaType: void 0
|
|
241
|
+
};
|
|
242
|
+
case "text":
|
|
243
|
+
return {
|
|
244
|
+
data: { type: "text", text: content.text },
|
|
245
|
+
mediaType: void 0
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (content instanceof URL) {
|
|
250
|
+
return convertUrlToFilePartData(content);
|
|
298
251
|
}
|
|
299
252
|
if (typeof content === "string") {
|
|
300
253
|
try {
|
|
301
|
-
|
|
254
|
+
return convertUrlToFilePartData(new URL(content));
|
|
302
255
|
} catch (e) {
|
|
256
|
+
return convertInlineDataToFilePartData(content);
|
|
303
257
|
}
|
|
304
258
|
}
|
|
305
|
-
if (content
|
|
306
|
-
|
|
307
|
-
content
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
throw new AISDKError({
|
|
311
|
-
name: "InvalidDataContentError",
|
|
312
|
-
message: `Invalid data URL format in content ${content.toString()}`
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
return { data: base64Content, mediaType: dataUrlMediaType };
|
|
259
|
+
if (isProviderReference(content)) {
|
|
260
|
+
return {
|
|
261
|
+
data: { type: "reference", reference: content },
|
|
262
|
+
mediaType: void 0
|
|
263
|
+
};
|
|
316
264
|
}
|
|
317
|
-
return
|
|
265
|
+
return convertInlineDataToFilePartData(content);
|
|
318
266
|
}
|
|
319
267
|
|
|
320
268
|
// src/logger/log-warnings.ts
|
|
@@ -387,47 +335,47 @@ var logWarnings = (options) => {
|
|
|
387
335
|
|
|
388
336
|
// src/prompt/invalid-message-role-error.ts
|
|
389
337
|
import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
|
|
390
|
-
var
|
|
391
|
-
var
|
|
392
|
-
var
|
|
393
|
-
var
|
|
338
|
+
var name2 = "AI_InvalidMessageRoleError";
|
|
339
|
+
var marker2 = `vercel.ai.error.${name2}`;
|
|
340
|
+
var symbol2 = Symbol.for(marker2);
|
|
341
|
+
var _a2;
|
|
394
342
|
var InvalidMessageRoleError = class extends AISDKError2 {
|
|
395
343
|
constructor({
|
|
396
344
|
role,
|
|
397
345
|
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
|
398
346
|
}) {
|
|
399
|
-
super({ name, message });
|
|
400
|
-
this[
|
|
347
|
+
super({ name: name2, message });
|
|
348
|
+
this[_a2] = true;
|
|
401
349
|
this.role = role;
|
|
402
350
|
}
|
|
403
351
|
static isInstance(error) {
|
|
404
|
-
return AISDKError2.hasMarker(error,
|
|
352
|
+
return AISDKError2.hasMarker(error, marker2);
|
|
405
353
|
}
|
|
406
354
|
};
|
|
407
|
-
|
|
355
|
+
_a2 = symbol2;
|
|
408
356
|
|
|
409
357
|
// src/error/missing-tool-result-error.ts
|
|
410
358
|
import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
|
|
411
|
-
var
|
|
412
|
-
var
|
|
413
|
-
var
|
|
414
|
-
var
|
|
359
|
+
var name3 = "AI_MissingToolResultsError";
|
|
360
|
+
var marker3 = `vercel.ai.error.${name3}`;
|
|
361
|
+
var symbol3 = Symbol.for(marker3);
|
|
362
|
+
var _a3;
|
|
415
363
|
var MissingToolResultsError = class extends AISDKError3 {
|
|
416
364
|
constructor({ toolCallIds }) {
|
|
417
365
|
super({
|
|
418
|
-
name:
|
|
366
|
+
name: name3,
|
|
419
367
|
message: `Tool result${toolCallIds.length > 1 ? "s are" : " is"} missing for tool call${toolCallIds.length > 1 ? "s" : ""} ${toolCallIds.join(
|
|
420
368
|
", "
|
|
421
369
|
)}.`
|
|
422
370
|
});
|
|
423
|
-
this[
|
|
371
|
+
this[_a3] = true;
|
|
424
372
|
this.toolCallIds = toolCallIds;
|
|
425
373
|
}
|
|
426
374
|
static isInstance(error) {
|
|
427
|
-
return AISDKError3.hasMarker(error,
|
|
375
|
+
return AISDKError3.hasMarker(error, marker3);
|
|
428
376
|
}
|
|
429
377
|
};
|
|
430
|
-
|
|
378
|
+
_a3 = symbol3;
|
|
431
379
|
|
|
432
380
|
// src/prompt/convert-to-language-model-prompt.ts
|
|
433
381
|
async function convertToLanguageModelPrompt({
|
|
@@ -565,7 +513,16 @@ function convertToLanguageModelMessage({
|
|
|
565
513
|
}
|
|
566
514
|
const converted = {
|
|
567
515
|
role: "user",
|
|
568
|
-
content: message.content.map((part) =>
|
|
516
|
+
content: message.content.map((part) => {
|
|
517
|
+
if (part.type === "image") {
|
|
518
|
+
warnings.push({
|
|
519
|
+
type: "deprecated",
|
|
520
|
+
setting: '"image" content part',
|
|
521
|
+
message: `The "image" content part type is deprecated. Use a "file" part with mediaType: 'image' (or a more specific image/* subtype) instead.`
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
return convertImagePartToFilePart(part);
|
|
525
|
+
}).map((part) => convertPartToLanguageModelPart(part, downloadedAssets)).filter((part) => part.type !== "text" || part.text !== ""),
|
|
569
526
|
providerOptions: message.providerOptions
|
|
570
527
|
};
|
|
571
528
|
if (warnings.length > 0) {
|
|
@@ -599,16 +556,7 @@ function convertToLanguageModelMessage({
|
|
|
599
556
|
};
|
|
600
557
|
}
|
|
601
558
|
case "file": {
|
|
602
|
-
|
|
603
|
-
return {
|
|
604
|
-
type: "file",
|
|
605
|
-
data: part.data,
|
|
606
|
-
filename: part.filename,
|
|
607
|
-
mediaType: part.mediaType,
|
|
608
|
-
providerOptions
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
const { data, mediaType } = convertToLanguageModelV4DataContent(
|
|
559
|
+
const { data, mediaType } = convertToLanguageModelV4FilePart(
|
|
612
560
|
part.data
|
|
613
561
|
);
|
|
614
562
|
return {
|
|
@@ -627,9 +575,14 @@ function convertToLanguageModelMessage({
|
|
|
627
575
|
};
|
|
628
576
|
}
|
|
629
577
|
case "reasoning-file": {
|
|
630
|
-
const { data, mediaType } =
|
|
578
|
+
const { data, mediaType } = convertToLanguageModelV4FilePart(
|
|
631
579
|
part.data
|
|
632
580
|
);
|
|
581
|
+
if (data.type !== "data" && data.type !== "url") {
|
|
582
|
+
throw new Error(
|
|
583
|
+
`Unsupported reasoning-file data type: ${data.type}`
|
|
584
|
+
);
|
|
585
|
+
}
|
|
633
586
|
return {
|
|
634
587
|
type: "reasoning-file",
|
|
635
588
|
data,
|
|
@@ -720,28 +673,29 @@ function convertToLanguageModelMessage({
|
|
|
720
673
|
}
|
|
721
674
|
}
|
|
722
675
|
}
|
|
676
|
+
function convertImagePartToFilePart(part) {
|
|
677
|
+
var _a6;
|
|
678
|
+
if (part.type !== "image") {
|
|
679
|
+
return part;
|
|
680
|
+
}
|
|
681
|
+
return {
|
|
682
|
+
type: "file",
|
|
683
|
+
data: part.image,
|
|
684
|
+
mediaType: (_a6 = part.mediaType) != null ? _a6 : "image",
|
|
685
|
+
providerOptions: part.providerOptions
|
|
686
|
+
};
|
|
687
|
+
}
|
|
723
688
|
async function downloadAssets(messages, download2, supportedUrls) {
|
|
724
689
|
const plannedDownloads = messages.filter((message) => message.role === "user").map((message) => message.content).filter(
|
|
725
690
|
(content) => Array.isArray(content)
|
|
726
|
-
).flat().filter(
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
var _a5;
|
|
730
|
-
const mediaType = (_a5 = part.mediaType) != null ? _a5 : part.type === "image" ? "image/*" : void 0;
|
|
731
|
-
let data = part.type === "image" ? part.image : part.data;
|
|
732
|
-
if (typeof data === "string") {
|
|
733
|
-
try {
|
|
734
|
-
data = new URL(data);
|
|
735
|
-
} catch (e) {
|
|
736
|
-
}
|
|
737
|
-
}
|
|
691
|
+
).flat().map((part) => convertImagePartToFilePart(part)).filter((part) => part.type === "file").map((part) => {
|
|
692
|
+
const mediaType = part.mediaType;
|
|
693
|
+
const { data } = convertToLanguageModelV4FilePart(part.data);
|
|
738
694
|
return { mediaType, data };
|
|
739
|
-
}).filter(
|
|
740
|
-
|
|
741
|
-
).map((part) => ({
|
|
742
|
-
url: part.data,
|
|
695
|
+
}).filter((part) => part.data.type === "url").map((part) => ({
|
|
696
|
+
url: part.data.url,
|
|
743
697
|
isUrlSupportedByModel: part.mediaType != null && isUrlSupported({
|
|
744
|
-
url: part.data.toString(),
|
|
698
|
+
url: part.data.url.toString(),
|
|
745
699
|
mediaType: part.mediaType,
|
|
746
700
|
supportedUrls
|
|
747
701
|
})
|
|
@@ -757,7 +711,6 @@ async function downloadAssets(messages, download2, supportedUrls) {
|
|
|
757
711
|
);
|
|
758
712
|
}
|
|
759
713
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
760
|
-
var _a5, _b;
|
|
761
714
|
if (part.type === "text") {
|
|
762
715
|
return {
|
|
763
716
|
type: "text",
|
|
@@ -765,55 +718,37 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
765
718
|
providerOptions: part.providerOptions
|
|
766
719
|
};
|
|
767
720
|
}
|
|
768
|
-
const
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
mediaType: (_a5 = part.mediaType) != null ? _a5 : type === "image" ? "image/*" : "",
|
|
774
|
-
filename: type === "file" ? part.filename : void 0,
|
|
775
|
-
data: rawData,
|
|
776
|
-
providerOptions: part.providerOptions
|
|
777
|
-
};
|
|
778
|
-
}
|
|
779
|
-
const originalData = rawData;
|
|
780
|
-
const { data: convertedData, mediaType: convertedMediaType } = convertToLanguageModelV4DataContent(originalData);
|
|
781
|
-
let mediaType = convertedMediaType != null ? convertedMediaType : part.mediaType;
|
|
782
|
-
let data = convertedData;
|
|
783
|
-
if (data instanceof URL) {
|
|
784
|
-
const downloadedFile = downloadedAssets[data.toString()];
|
|
721
|
+
const { data: normalizedData, mediaType: dataUrlMediaType } = convertToLanguageModelV4FilePart(part.data);
|
|
722
|
+
let mediaType = dataUrlMediaType != null ? dataUrlMediaType : part.mediaType;
|
|
723
|
+
let data = normalizedData;
|
|
724
|
+
if (data.type === "url") {
|
|
725
|
+
const downloadedFile = downloadedAssets[data.url.toString()];
|
|
785
726
|
if (downloadedFile) {
|
|
786
|
-
data = downloadedFile.data;
|
|
787
|
-
mediaType != null
|
|
788
|
-
|
|
789
|
-
}
|
|
790
|
-
switch (type) {
|
|
791
|
-
case "image": {
|
|
792
|
-
if (data instanceof Uint8Array || typeof data === "string") {
|
|
793
|
-
mediaType = (_b = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _b : mediaType;
|
|
727
|
+
data = { type: "data", data: downloadedFile.data };
|
|
728
|
+
if (downloadedFile.mediaType != null && (mediaType == null || !isFullMediaType(mediaType))) {
|
|
729
|
+
mediaType = downloadedFile.mediaType;
|
|
794
730
|
}
|
|
795
|
-
return {
|
|
796
|
-
type: "file",
|
|
797
|
-
mediaType: mediaType != null ? mediaType : "image/*",
|
|
798
|
-
// any image
|
|
799
|
-
filename: void 0,
|
|
800
|
-
data,
|
|
801
|
-
providerOptions: part.providerOptions
|
|
802
|
-
};
|
|
803
731
|
}
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
data,
|
|
813
|
-
providerOptions: part.providerOptions
|
|
814
|
-
};
|
|
732
|
+
}
|
|
733
|
+
if (data.type === "data" && (data.data instanceof Uint8Array || typeof data.data === "string")) {
|
|
734
|
+
const imageMediaType = detectMediaType({
|
|
735
|
+
data: data.data,
|
|
736
|
+
topLevelType: "image"
|
|
737
|
+
});
|
|
738
|
+
if (imageMediaType != null) {
|
|
739
|
+
mediaType = imageMediaType;
|
|
815
740
|
}
|
|
816
741
|
}
|
|
742
|
+
if (mediaType == null) {
|
|
743
|
+
throw new Error(`Media type is missing for file part`);
|
|
744
|
+
}
|
|
745
|
+
return {
|
|
746
|
+
type: "file",
|
|
747
|
+
mediaType,
|
|
748
|
+
filename: part.filename,
|
|
749
|
+
data,
|
|
750
|
+
providerOptions: part.providerOptions
|
|
751
|
+
};
|
|
817
752
|
}
|
|
818
753
|
function mapToolResultOutput({
|
|
819
754
|
output,
|
|
@@ -828,7 +763,7 @@ function mapToolResultOutput({
|
|
|
828
763
|
return {
|
|
829
764
|
type: "content",
|
|
830
765
|
value: output.value.map((item) => {
|
|
831
|
-
var
|
|
766
|
+
var _a6;
|
|
832
767
|
switch (item.type) {
|
|
833
768
|
case "image-data": {
|
|
834
769
|
warnings.push({
|
|
@@ -899,7 +834,7 @@ function mapToolResultOutput({
|
|
|
899
834
|
};
|
|
900
835
|
}
|
|
901
836
|
case "file-url": {
|
|
902
|
-
const mediaType = (
|
|
837
|
+
const mediaType = (_a6 = item.mediaType) != null ? _a6 : getMediaTypeFromUrl(item.url);
|
|
903
838
|
if (!item.mediaType) {
|
|
904
839
|
const messageSuffix = mediaType === "application/octet-stream" ? `Unable to infer media type from URL. Defaulting to 'application/octet-stream'.` : `Inferred media type '${mediaType}' from URL.`;
|
|
905
840
|
warnings.push({
|
|
@@ -955,10 +890,10 @@ var URL_EXTENSION_TO_MEDIA_TYPE = {
|
|
|
955
890
|
ogg: "audio/ogg"
|
|
956
891
|
};
|
|
957
892
|
function getMediaTypeFromUrl(url, fallbackMediaType = "application/octet-stream") {
|
|
958
|
-
var
|
|
893
|
+
var _a6;
|
|
959
894
|
try {
|
|
960
895
|
const pathname = new URL(url).pathname;
|
|
961
|
-
const ext = (
|
|
896
|
+
const ext = (_a6 = pathname.split(".").pop()) == null ? void 0 : _a6.toLowerCase();
|
|
962
897
|
if (ext && Object.hasOwn(URL_EXTENSION_TO_MEDIA_TYPE, ext)) {
|
|
963
898
|
return URL_EXTENSION_TO_MEDIA_TYPE[ext];
|
|
964
899
|
}
|
|
@@ -990,7 +925,7 @@ async function prepareTools({
|
|
|
990
925
|
return void 0;
|
|
991
926
|
}
|
|
992
927
|
const languageModelTools = [];
|
|
993
|
-
for (const [
|
|
928
|
+
for (const [name6, tool] of Object.entries(tools)) {
|
|
994
929
|
const toolType = tool.type;
|
|
995
930
|
switch (toolType) {
|
|
996
931
|
case void 0:
|
|
@@ -998,7 +933,7 @@ async function prepareTools({
|
|
|
998
933
|
case "function":
|
|
999
934
|
languageModelTools.push({
|
|
1000
935
|
type: "function",
|
|
1001
|
-
name:
|
|
936
|
+
name: name6,
|
|
1002
937
|
description: tool.description,
|
|
1003
938
|
inputSchema: await asSchema(tool.inputSchema).jsonSchema,
|
|
1004
939
|
...tool.inputExamples != null ? { inputExamples: tool.inputExamples } : {},
|
|
@@ -1009,7 +944,7 @@ async function prepareTools({
|
|
|
1009
944
|
case "provider":
|
|
1010
945
|
languageModelTools.push({
|
|
1011
946
|
type: "provider",
|
|
1012
|
-
name:
|
|
947
|
+
name: name6,
|
|
1013
948
|
id: tool.id,
|
|
1014
949
|
args: tool.args
|
|
1015
950
|
});
|
|
@@ -1029,170 +964,197 @@ import {
|
|
|
1029
964
|
asArray as asArray2,
|
|
1030
965
|
safeValidateTypes
|
|
1031
966
|
} from "@ai-sdk/provider-utils";
|
|
1032
|
-
import { z as
|
|
967
|
+
import { z as z5 } from "zod/v4";
|
|
1033
968
|
|
|
1034
969
|
// src/prompt/message.ts
|
|
1035
|
-
import { z as
|
|
970
|
+
import { z as z4 } from "zod/v4";
|
|
1036
971
|
|
|
1037
972
|
// src/types/provider-metadata.ts
|
|
1038
|
-
import { z as
|
|
973
|
+
import { z as z2 } from "zod/v4";
|
|
1039
974
|
|
|
1040
975
|
// src/types/json-value.ts
|
|
1041
|
-
import { z
|
|
1042
|
-
var jsonValueSchema =
|
|
1043
|
-
() =>
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
976
|
+
import { z } from "zod/v4";
|
|
977
|
+
var jsonValueSchema = z.lazy(
|
|
978
|
+
() => z.union([
|
|
979
|
+
z.null(),
|
|
980
|
+
z.string(),
|
|
981
|
+
z.number(),
|
|
982
|
+
z.boolean(),
|
|
983
|
+
z.record(z.string(), jsonValueSchema.optional()),
|
|
984
|
+
z.array(jsonValueSchema)
|
|
1050
985
|
])
|
|
1051
986
|
);
|
|
1052
987
|
|
|
1053
988
|
// src/types/provider-metadata.ts
|
|
1054
|
-
var providerMetadataSchema =
|
|
1055
|
-
|
|
1056
|
-
|
|
989
|
+
var providerMetadataSchema = z2.record(
|
|
990
|
+
z2.string(),
|
|
991
|
+
z2.record(z2.string(), jsonValueSchema.optional())
|
|
1057
992
|
);
|
|
1058
993
|
|
|
1059
994
|
// src/prompt/content-part.ts
|
|
1060
|
-
import {
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
995
|
+
import {
|
|
996
|
+
isBuffer as isBuffer2
|
|
997
|
+
} from "@ai-sdk/provider-utils";
|
|
998
|
+
import { z as z3 } from "zod/v4";
|
|
999
|
+
var fileInlineDataSchema = z3.union([
|
|
1000
|
+
z3.string(),
|
|
1001
|
+
z3.instanceof(Uint8Array),
|
|
1002
|
+
z3.instanceof(ArrayBuffer),
|
|
1003
|
+
z3.custom(isBuffer2, { message: "Must be a Buffer" })
|
|
1004
|
+
]);
|
|
1005
|
+
var providerReferenceSchema = z3.record(z3.string(), z3.string());
|
|
1006
|
+
var textPartSchema = z3.object({
|
|
1007
|
+
type: z3.literal("text"),
|
|
1008
|
+
text: z3.string(),
|
|
1065
1009
|
providerOptions: providerMetadataSchema.optional()
|
|
1066
1010
|
});
|
|
1067
|
-
var imagePartSchema =
|
|
1068
|
-
type:
|
|
1069
|
-
image:
|
|
1070
|
-
|
|
1071
|
-
|
|
1011
|
+
var imagePartSchema = z3.object({
|
|
1012
|
+
type: z3.literal("image"),
|
|
1013
|
+
image: z3.union([
|
|
1014
|
+
fileInlineDataSchema,
|
|
1015
|
+
z3.instanceof(URL),
|
|
1072
1016
|
providerReferenceSchema
|
|
1073
1017
|
]),
|
|
1074
|
-
mediaType:
|
|
1018
|
+
mediaType: z3.string().optional(),
|
|
1075
1019
|
providerOptions: providerMetadataSchema.optional()
|
|
1076
1020
|
});
|
|
1077
|
-
var
|
|
1078
|
-
type:
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1021
|
+
var taggedFileDataSchema = z3.discriminatedUnion("type", [
|
|
1022
|
+
z3.object({ type: z3.literal("data"), data: fileInlineDataSchema }),
|
|
1023
|
+
z3.object({ type: z3.literal("url"), url: z3.instanceof(URL) }),
|
|
1024
|
+
z3.object({
|
|
1025
|
+
type: z3.literal("reference"),
|
|
1026
|
+
reference: providerReferenceSchema
|
|
1027
|
+
}),
|
|
1028
|
+
z3.object({ type: z3.literal("text"), text: z3.string() })
|
|
1029
|
+
]);
|
|
1030
|
+
var taggedReasoningFileDataSchema = z3.discriminatedUnion("type", [
|
|
1031
|
+
z3.object({ type: z3.literal("data"), data: fileInlineDataSchema }),
|
|
1032
|
+
z3.object({ type: z3.literal("url"), url: z3.instanceof(URL) })
|
|
1033
|
+
]);
|
|
1034
|
+
var filePartSchema = z3.object({
|
|
1035
|
+
type: z3.literal("file"),
|
|
1036
|
+
data: z3.union([
|
|
1037
|
+
taggedFileDataSchema,
|
|
1038
|
+
fileInlineDataSchema,
|
|
1039
|
+
z3.instanceof(URL),
|
|
1082
1040
|
providerReferenceSchema
|
|
1083
1041
|
]),
|
|
1084
|
-
filename:
|
|
1085
|
-
mediaType:
|
|
1042
|
+
filename: z3.string().optional(),
|
|
1043
|
+
mediaType: z3.string(),
|
|
1086
1044
|
providerOptions: providerMetadataSchema.optional()
|
|
1087
1045
|
});
|
|
1088
|
-
var reasoningPartSchema =
|
|
1089
|
-
type:
|
|
1090
|
-
text:
|
|
1046
|
+
var reasoningPartSchema = z3.object({
|
|
1047
|
+
type: z3.literal("reasoning"),
|
|
1048
|
+
text: z3.string(),
|
|
1091
1049
|
providerOptions: providerMetadataSchema.optional()
|
|
1092
1050
|
});
|
|
1093
|
-
var customPartSchema =
|
|
1094
|
-
type:
|
|
1095
|
-
kind:
|
|
1051
|
+
var customPartSchema = z3.object({
|
|
1052
|
+
type: z3.literal("custom"),
|
|
1053
|
+
kind: z3.string().transform((value) => value),
|
|
1096
1054
|
providerOptions: providerMetadataSchema.optional()
|
|
1097
1055
|
});
|
|
1098
|
-
var reasoningFilePartSchema =
|
|
1099
|
-
type:
|
|
1100
|
-
data:
|
|
1101
|
-
|
|
1056
|
+
var reasoningFilePartSchema = z3.object({
|
|
1057
|
+
type: z3.literal("reasoning-file"),
|
|
1058
|
+
data: z3.union([
|
|
1059
|
+
taggedReasoningFileDataSchema,
|
|
1060
|
+
fileInlineDataSchema,
|
|
1061
|
+
z3.instanceof(URL)
|
|
1062
|
+
]),
|
|
1063
|
+
mediaType: z3.string(),
|
|
1102
1064
|
providerOptions: providerMetadataSchema.optional()
|
|
1103
1065
|
});
|
|
1104
|
-
var toolCallPartSchema =
|
|
1105
|
-
type:
|
|
1106
|
-
toolCallId:
|
|
1107
|
-
toolName:
|
|
1108
|
-
input:
|
|
1066
|
+
var toolCallPartSchema = z3.object({
|
|
1067
|
+
type: z3.literal("tool-call"),
|
|
1068
|
+
toolCallId: z3.string(),
|
|
1069
|
+
toolName: z3.string(),
|
|
1070
|
+
input: z3.unknown(),
|
|
1109
1071
|
providerOptions: providerMetadataSchema.optional(),
|
|
1110
|
-
providerExecuted:
|
|
1072
|
+
providerExecuted: z3.boolean().optional()
|
|
1111
1073
|
});
|
|
1112
|
-
var outputSchema =
|
|
1074
|
+
var outputSchema = z3.discriminatedUnion(
|
|
1113
1075
|
"type",
|
|
1114
1076
|
[
|
|
1115
|
-
|
|
1116
|
-
type:
|
|
1117
|
-
value:
|
|
1077
|
+
z3.object({
|
|
1078
|
+
type: z3.literal("text"),
|
|
1079
|
+
value: z3.string(),
|
|
1118
1080
|
providerOptions: providerMetadataSchema.optional()
|
|
1119
1081
|
}),
|
|
1120
|
-
|
|
1121
|
-
type:
|
|
1082
|
+
z3.object({
|
|
1083
|
+
type: z3.literal("json"),
|
|
1122
1084
|
value: jsonValueSchema,
|
|
1123
1085
|
providerOptions: providerMetadataSchema.optional()
|
|
1124
1086
|
}),
|
|
1125
|
-
|
|
1126
|
-
type:
|
|
1127
|
-
reason:
|
|
1087
|
+
z3.object({
|
|
1088
|
+
type: z3.literal("execution-denied"),
|
|
1089
|
+
reason: z3.string().optional(),
|
|
1128
1090
|
providerOptions: providerMetadataSchema.optional()
|
|
1129
1091
|
}),
|
|
1130
|
-
|
|
1131
|
-
type:
|
|
1132
|
-
value:
|
|
1092
|
+
z3.object({
|
|
1093
|
+
type: z3.literal("error-text"),
|
|
1094
|
+
value: z3.string(),
|
|
1133
1095
|
providerOptions: providerMetadataSchema.optional()
|
|
1134
1096
|
}),
|
|
1135
|
-
|
|
1136
|
-
type:
|
|
1097
|
+
z3.object({
|
|
1098
|
+
type: z3.literal("error-json"),
|
|
1137
1099
|
value: jsonValueSchema,
|
|
1138
1100
|
providerOptions: providerMetadataSchema.optional()
|
|
1139
1101
|
}),
|
|
1140
|
-
|
|
1141
|
-
type:
|
|
1142
|
-
value:
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
type:
|
|
1146
|
-
text:
|
|
1102
|
+
z3.object({
|
|
1103
|
+
type: z3.literal("content"),
|
|
1104
|
+
value: z3.array(
|
|
1105
|
+
z3.union([
|
|
1106
|
+
z3.object({
|
|
1107
|
+
type: z3.literal("text"),
|
|
1108
|
+
text: z3.string(),
|
|
1147
1109
|
providerOptions: providerMetadataSchema.optional()
|
|
1148
1110
|
}),
|
|
1149
|
-
|
|
1150
|
-
type:
|
|
1151
|
-
data:
|
|
1152
|
-
mediaType:
|
|
1153
|
-
filename:
|
|
1111
|
+
z3.object({
|
|
1112
|
+
type: z3.literal("file-data"),
|
|
1113
|
+
data: z3.string(),
|
|
1114
|
+
mediaType: z3.string(),
|
|
1115
|
+
filename: z3.string().optional(),
|
|
1154
1116
|
providerOptions: providerMetadataSchema.optional()
|
|
1155
1117
|
}),
|
|
1156
|
-
|
|
1157
|
-
type:
|
|
1158
|
-
url:
|
|
1118
|
+
z3.object({
|
|
1119
|
+
type: z3.literal("file-url"),
|
|
1120
|
+
url: z3.string(),
|
|
1159
1121
|
// Temporarily optional. TODO: make required in v8, after migration period.
|
|
1160
|
-
mediaType:
|
|
1122
|
+
mediaType: z3.string().optional(),
|
|
1161
1123
|
providerOptions: providerMetadataSchema.optional()
|
|
1162
1124
|
}),
|
|
1163
|
-
|
|
1164
|
-
type:
|
|
1165
|
-
fileId:
|
|
1125
|
+
z3.object({
|
|
1126
|
+
type: z3.literal("file-id"),
|
|
1127
|
+
fileId: z3.union([z3.string(), z3.record(z3.string(), z3.string())]),
|
|
1166
1128
|
providerOptions: providerMetadataSchema.optional()
|
|
1167
1129
|
}),
|
|
1168
|
-
|
|
1169
|
-
type:
|
|
1170
|
-
providerReference:
|
|
1130
|
+
z3.object({
|
|
1131
|
+
type: z3.literal("file-reference"),
|
|
1132
|
+
providerReference: z3.record(z3.string(), z3.string()),
|
|
1171
1133
|
providerOptions: providerMetadataSchema.optional()
|
|
1172
1134
|
}),
|
|
1173
|
-
|
|
1174
|
-
type:
|
|
1175
|
-
data:
|
|
1176
|
-
mediaType:
|
|
1135
|
+
z3.object({
|
|
1136
|
+
type: z3.literal("image-data"),
|
|
1137
|
+
data: z3.string(),
|
|
1138
|
+
mediaType: z3.string(),
|
|
1177
1139
|
providerOptions: providerMetadataSchema.optional()
|
|
1178
1140
|
}),
|
|
1179
|
-
|
|
1180
|
-
type:
|
|
1181
|
-
url:
|
|
1141
|
+
z3.object({
|
|
1142
|
+
type: z3.literal("image-url"),
|
|
1143
|
+
url: z3.string(),
|
|
1182
1144
|
providerOptions: providerMetadataSchema.optional()
|
|
1183
1145
|
}),
|
|
1184
|
-
|
|
1185
|
-
type:
|
|
1186
|
-
fileId:
|
|
1146
|
+
z3.object({
|
|
1147
|
+
type: z3.literal("image-file-id"),
|
|
1148
|
+
fileId: z3.union([z3.string(), z3.record(z3.string(), z3.string())]),
|
|
1187
1149
|
providerOptions: providerMetadataSchema.optional()
|
|
1188
1150
|
}),
|
|
1189
|
-
|
|
1190
|
-
type:
|
|
1191
|
-
providerReference:
|
|
1151
|
+
z3.object({
|
|
1152
|
+
type: z3.literal("image-file-reference"),
|
|
1153
|
+
providerReference: z3.record(z3.string(), z3.string()),
|
|
1192
1154
|
providerOptions: providerMetadataSchema.optional()
|
|
1193
1155
|
}),
|
|
1194
|
-
|
|
1195
|
-
type:
|
|
1156
|
+
z3.object({
|
|
1157
|
+
type: z3.literal("custom"),
|
|
1196
1158
|
providerOptions: providerMetadataSchema.optional()
|
|
1197
1159
|
})
|
|
1198
1160
|
])
|
|
@@ -1200,47 +1162,47 @@ var outputSchema = z4.discriminatedUnion(
|
|
|
1200
1162
|
})
|
|
1201
1163
|
]
|
|
1202
1164
|
);
|
|
1203
|
-
var toolResultPartSchema =
|
|
1204
|
-
type:
|
|
1205
|
-
toolCallId:
|
|
1206
|
-
toolName:
|
|
1165
|
+
var toolResultPartSchema = z3.object({
|
|
1166
|
+
type: z3.literal("tool-result"),
|
|
1167
|
+
toolCallId: z3.string(),
|
|
1168
|
+
toolName: z3.string(),
|
|
1207
1169
|
output: outputSchema,
|
|
1208
1170
|
providerOptions: providerMetadataSchema.optional()
|
|
1209
1171
|
});
|
|
1210
|
-
var toolApprovalRequestSchema =
|
|
1211
|
-
type:
|
|
1212
|
-
approvalId:
|
|
1213
|
-
toolCallId:
|
|
1172
|
+
var toolApprovalRequestSchema = z3.object({
|
|
1173
|
+
type: z3.literal("tool-approval-request"),
|
|
1174
|
+
approvalId: z3.string(),
|
|
1175
|
+
toolCallId: z3.string()
|
|
1214
1176
|
});
|
|
1215
|
-
var toolApprovalResponseSchema =
|
|
1216
|
-
type:
|
|
1217
|
-
approvalId:
|
|
1218
|
-
approved:
|
|
1219
|
-
reason:
|
|
1177
|
+
var toolApprovalResponseSchema = z3.object({
|
|
1178
|
+
type: z3.literal("tool-approval-response"),
|
|
1179
|
+
approvalId: z3.string(),
|
|
1180
|
+
approved: z3.boolean(),
|
|
1181
|
+
reason: z3.string().optional()
|
|
1220
1182
|
});
|
|
1221
1183
|
|
|
1222
1184
|
// src/prompt/message.ts
|
|
1223
|
-
var systemModelMessageSchema =
|
|
1185
|
+
var systemModelMessageSchema = z4.object(
|
|
1224
1186
|
{
|
|
1225
|
-
role:
|
|
1226
|
-
content:
|
|
1187
|
+
role: z4.literal("system"),
|
|
1188
|
+
content: z4.string(),
|
|
1227
1189
|
providerOptions: providerMetadataSchema.optional()
|
|
1228
1190
|
}
|
|
1229
1191
|
);
|
|
1230
|
-
var userModelMessageSchema =
|
|
1231
|
-
role:
|
|
1232
|
-
content:
|
|
1233
|
-
|
|
1234
|
-
|
|
1192
|
+
var userModelMessageSchema = z4.object({
|
|
1193
|
+
role: z4.literal("user"),
|
|
1194
|
+
content: z4.union([
|
|
1195
|
+
z4.string(),
|
|
1196
|
+
z4.array(z4.union([textPartSchema, imagePartSchema, filePartSchema]))
|
|
1235
1197
|
]),
|
|
1236
1198
|
providerOptions: providerMetadataSchema.optional()
|
|
1237
1199
|
});
|
|
1238
|
-
var assistantModelMessageSchema =
|
|
1239
|
-
role:
|
|
1240
|
-
content:
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1200
|
+
var assistantModelMessageSchema = z4.object({
|
|
1201
|
+
role: z4.literal("assistant"),
|
|
1202
|
+
content: z4.union([
|
|
1203
|
+
z4.string(),
|
|
1204
|
+
z4.array(
|
|
1205
|
+
z4.union([
|
|
1244
1206
|
textPartSchema,
|
|
1245
1207
|
customPartSchema,
|
|
1246
1208
|
filePartSchema,
|
|
@@ -1254,12 +1216,12 @@ var assistantModelMessageSchema = z5.object({
|
|
|
1254
1216
|
]),
|
|
1255
1217
|
providerOptions: providerMetadataSchema.optional()
|
|
1256
1218
|
});
|
|
1257
|
-
var toolModelMessageSchema =
|
|
1258
|
-
role:
|
|
1259
|
-
content:
|
|
1219
|
+
var toolModelMessageSchema = z4.object({
|
|
1220
|
+
role: z4.literal("tool"),
|
|
1221
|
+
content: z4.array(z4.union([toolResultPartSchema, toolApprovalResponseSchema])),
|
|
1260
1222
|
providerOptions: providerMetadataSchema.optional()
|
|
1261
1223
|
});
|
|
1262
|
-
var modelMessageSchema =
|
|
1224
|
+
var modelMessageSchema = z4.union([
|
|
1263
1225
|
systemModelMessageSchema,
|
|
1264
1226
|
userModelMessageSchema,
|
|
1265
1227
|
assistantModelMessageSchema,
|
|
@@ -1315,7 +1277,7 @@ async function standardizePrompt({
|
|
|
1315
1277
|
}
|
|
1316
1278
|
const validationResult = await safeValidateTypes({
|
|
1317
1279
|
value: messages,
|
|
1318
|
-
schema:
|
|
1280
|
+
schema: z5.array(modelMessageSchema)
|
|
1319
1281
|
});
|
|
1320
1282
|
if (!validationResult.success) {
|
|
1321
1283
|
throw new InvalidPromptError({
|
|
@@ -1329,10 +1291,10 @@ async function standardizePrompt({
|
|
|
1329
1291
|
|
|
1330
1292
|
// src/error/invalid-argument-error.ts
|
|
1331
1293
|
import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
|
|
1332
|
-
var
|
|
1333
|
-
var
|
|
1334
|
-
var
|
|
1335
|
-
var
|
|
1294
|
+
var name4 = "AI_InvalidArgumentError";
|
|
1295
|
+
var marker4 = `vercel.ai.error.${name4}`;
|
|
1296
|
+
var symbol4 = Symbol.for(marker4);
|
|
1297
|
+
var _a4;
|
|
1336
1298
|
var InvalidArgumentError = class extends AISDKError4 {
|
|
1337
1299
|
constructor({
|
|
1338
1300
|
parameter,
|
|
@@ -1340,18 +1302,18 @@ var InvalidArgumentError = class extends AISDKError4 {
|
|
|
1340
1302
|
message
|
|
1341
1303
|
}) {
|
|
1342
1304
|
super({
|
|
1343
|
-
name:
|
|
1305
|
+
name: name4,
|
|
1344
1306
|
message: `Invalid argument for parameter ${parameter}: ${message}`
|
|
1345
1307
|
});
|
|
1346
|
-
this[
|
|
1308
|
+
this[_a4] = true;
|
|
1347
1309
|
this.parameter = parameter;
|
|
1348
1310
|
this.value = value;
|
|
1349
1311
|
}
|
|
1350
1312
|
static isInstance(error) {
|
|
1351
|
-
return AISDKError4.hasMarker(error,
|
|
1313
|
+
return AISDKError4.hasMarker(error, marker4);
|
|
1352
1314
|
}
|
|
1353
1315
|
};
|
|
1354
|
-
|
|
1316
|
+
_a4 = symbol4;
|
|
1355
1317
|
|
|
1356
1318
|
// src/prompt/prepare-language-model-call-options.ts
|
|
1357
1319
|
function prepareLanguageModelCallOptions({
|
|
@@ -1454,27 +1416,27 @@ import { delay, getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
|
|
|
1454
1416
|
|
|
1455
1417
|
// src/util/retry-error.ts
|
|
1456
1418
|
import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
|
|
1457
|
-
var
|
|
1458
|
-
var
|
|
1459
|
-
var
|
|
1460
|
-
var
|
|
1419
|
+
var name5 = "AI_RetryError";
|
|
1420
|
+
var marker5 = `vercel.ai.error.${name5}`;
|
|
1421
|
+
var symbol5 = Symbol.for(marker5);
|
|
1422
|
+
var _a5;
|
|
1461
1423
|
var RetryError = class extends AISDKError5 {
|
|
1462
1424
|
constructor({
|
|
1463
1425
|
message,
|
|
1464
1426
|
reason,
|
|
1465
1427
|
errors
|
|
1466
1428
|
}) {
|
|
1467
|
-
super({ name:
|
|
1468
|
-
this[
|
|
1429
|
+
super({ name: name5, message });
|
|
1430
|
+
this[_a5] = true;
|
|
1469
1431
|
this.reason = reason;
|
|
1470
1432
|
this.errors = errors;
|
|
1471
1433
|
this.lastError = errors[errors.length - 1];
|
|
1472
1434
|
}
|
|
1473
1435
|
static isInstance(error) {
|
|
1474
|
-
return AISDKError5.hasMarker(error,
|
|
1436
|
+
return AISDKError5.hasMarker(error, marker5);
|
|
1475
1437
|
}
|
|
1476
1438
|
};
|
|
1477
|
-
|
|
1439
|
+
_a5 = symbol5;
|
|
1478
1440
|
|
|
1479
1441
|
// src/util/retry-with-exponential-backoff.ts
|
|
1480
1442
|
function getRetryDelayInMs({
|
|
@@ -1977,8 +1939,8 @@ function resolveLanguageModel(model) {
|
|
|
1977
1939
|
return asLanguageModelV4(model);
|
|
1978
1940
|
}
|
|
1979
1941
|
function getGlobalProvider() {
|
|
1980
|
-
var
|
|
1981
|
-
const provider = (
|
|
1942
|
+
var _a6;
|
|
1943
|
+
const provider = (_a6 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a6 : gateway;
|
|
1982
1944
|
return asProviderV4(provider);
|
|
1983
1945
|
}
|
|
1984
1946
|
|