@ai-sdk/provider-utils 5.0.0-beta.9 → 5.0.0-canary.32
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 +184 -0
- package/dist/index.d.ts +1346 -878
- package/dist/index.js +813 -325
- package/dist/index.js.map +1 -1
- package/dist/test/index.d.ts +2 -1
- package/dist/test/index.js +18 -37
- package/dist/test/index.js.map +1 -1
- package/package.json +13 -11
- package/src/add-additional-properties-to-json-schema.ts +1 -1
- package/src/as-array.ts +12 -0
- package/src/convert-image-model-file-to-data-uri.ts +1 -1
- package/src/convert-inline-file-data-to-uint8-array.ts +30 -0
- package/src/create-tool-name-mapping.ts +1 -1
- package/src/detect-media-type.ts +312 -0
- package/src/filter-nullable.ts +11 -0
- package/src/get-error-message.ts +1 -15
- package/src/get-from-api.ts +2 -2
- package/src/has-required-key.ts +6 -0
- package/src/index.ts +39 -14
- package/src/inject-json-instruction.ts +1 -1
- package/src/is-buffer.ts +9 -0
- package/src/is-json-serializable.ts +29 -0
- package/src/is-provider-reference.ts +21 -0
- package/src/is-url-supported.ts +17 -2
- package/src/load-api-key.ts +1 -1
- package/src/load-setting.ts +1 -1
- package/src/map-reasoning-to-provider.ts +4 -1
- package/src/maybe-promise-like.ts +3 -0
- package/src/parse-json-event-stream.ts +3 -3
- package/src/parse-json.ts +3 -3
- package/src/parse-provider-options.ts +1 -1
- package/src/post-to-api.ts +4 -4
- package/src/{provider-tool-factory.ts → provider-defined-tool-factory.ts} +22 -29
- package/src/provider-executed-tool-factory.ts +69 -0
- package/src/resolve-full-media-type.ts +49 -0
- package/src/resolve-provider-reference.ts +26 -0
- package/src/resolve.ts +16 -1
- package/src/response-handler.ts +3 -3
- package/src/schema.ts +6 -3
- package/src/secure-json-parse.ts +1 -1
- package/src/serialize-model-options.ts +63 -0
- package/src/streaming-tool-call-tracker.ts +241 -0
- package/src/test/convert-response-stream-to-array.ts +1 -1
- package/src/test/is-node-version.ts +22 -1
- package/src/to-json-schema/zod3-to-json-schema/options.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parse-def.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parse-types.ts +22 -22
- package/src/to-json-schema/zod3-to-json-schema/parsers/array.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/bigint.ts +1 -1
- package/src/to-json-schema/zod3-to-json-schema/parsers/branded.ts +2 -2
- package/src/to-json-schema/zod3-to-json-schema/parsers/catch.ts +2 -2
- package/src/to-json-schema/zod3-to-json-schema/parsers/date.ts +4 -4
- package/src/to-json-schema/zod3-to-json-schema/parsers/default.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/effects.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/enum.ts +1 -1
- package/src/to-json-schema/zod3-to-json-schema/parsers/intersection.ts +5 -5
- package/src/to-json-schema/zod3-to-json-schema/parsers/literal.ts +1 -1
- package/src/to-json-schema/zod3-to-json-schema/parsers/map.ts +4 -5
- package/src/to-json-schema/zod3-to-json-schema/parsers/native-enum.ts +1 -1
- package/src/to-json-schema/zod3-to-json-schema/parsers/never.ts +1 -2
- package/src/to-json-schema/zod3-to-json-schema/parsers/nullable.ts +4 -4
- package/src/to-json-schema/zod3-to-json-schema/parsers/number.ts +1 -1
- package/src/to-json-schema/zod3-to-json-schema/parsers/object.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/optional.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/pipeline.ts +4 -4
- package/src/to-json-schema/zod3-to-json-schema/parsers/promise.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/readonly.ts +2 -2
- package/src/to-json-schema/zod3-to-json-schema/parsers/record.ts +9 -10
- package/src/to-json-schema/zod3-to-json-schema/parsers/set.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/string.ts +2 -2
- package/src/to-json-schema/zod3-to-json-schema/parsers/tuple.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/undefined.ts +1 -2
- package/src/to-json-schema/zod3-to-json-schema/parsers/union.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/parsers/unknown.ts +1 -2
- package/src/to-json-schema/zod3-to-json-schema/refs.ts +3 -3
- package/src/to-json-schema/zod3-to-json-schema/select-parser.ts +2 -2
- package/src/to-json-schema/zod3-to-json-schema/zod3-to-json-schema.ts +3 -3
- package/src/types/assistant-model-message.ts +3 -3
- package/src/types/content-part.ts +138 -19
- package/src/types/executable-tool.ts +17 -0
- package/src/types/execute-tool.ts +23 -23
- package/src/types/file-data.ts +48 -0
- package/src/types/index.ts +19 -3
- package/src/types/infer-tool-context.ts +7 -2
- package/src/types/infer-tool-set-context.ts +7 -9
- package/src/types/model-message.ts +4 -4
- package/src/types/never-optional.ts +7 -0
- package/src/types/provider-options.ts +1 -1
- package/src/types/provider-reference.ts +10 -0
- package/src/types/sensitive-context.ts +9 -0
- package/src/types/system-model-message.ts +1 -1
- package/src/types/tool-approval-request.ts +7 -0
- package/src/types/tool-execute-function.ts +50 -0
- package/src/types/tool-model-message.ts +3 -3
- package/src/types/tool-needs-approval-function.ts +39 -0
- package/src/types/tool.ts +236 -223
- package/src/types/user-model-message.ts +2 -2
- package/src/validate-types.ts +5 -3
- package/dist/index.d.mts +0 -1578
- package/dist/index.mjs +0 -2817
- package/dist/index.mjs.map +0 -1
- package/dist/test/index.d.mts +0 -17
- package/dist/test/index.mjs +0 -77
- package/dist/test/index.mjs.map +0 -1
- package/src/types/union-to-intersection.ts +0 -17
package/dist/index.js
CHANGED
|
@@ -1,101 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name2 in all)
|
|
10
|
-
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
DEFAULT_MAX_DOWNLOAD_SIZE: () => DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
34
|
-
DelayedPromise: () => DelayedPromise,
|
|
35
|
-
DownloadError: () => DownloadError,
|
|
36
|
-
EventSourceParserStream: () => import_stream2.EventSourceParserStream,
|
|
37
|
-
VERSION: () => VERSION,
|
|
38
|
-
asSchema: () => asSchema,
|
|
39
|
-
combineHeaders: () => combineHeaders,
|
|
40
|
-
convertAsyncIteratorToReadableStream: () => convertAsyncIteratorToReadableStream,
|
|
41
|
-
convertBase64ToUint8Array: () => convertBase64ToUint8Array,
|
|
42
|
-
convertImageModelFileToDataUri: () => convertImageModelFileToDataUri,
|
|
43
|
-
convertToBase64: () => convertToBase64,
|
|
44
|
-
convertToFormData: () => convertToFormData,
|
|
45
|
-
convertUint8ArrayToBase64: () => convertUint8ArrayToBase64,
|
|
46
|
-
createBinaryResponseHandler: () => createBinaryResponseHandler,
|
|
47
|
-
createEventSourceResponseHandler: () => createEventSourceResponseHandler,
|
|
48
|
-
createIdGenerator: () => createIdGenerator,
|
|
49
|
-
createJsonErrorResponseHandler: () => createJsonErrorResponseHandler,
|
|
50
|
-
createJsonResponseHandler: () => createJsonResponseHandler,
|
|
51
|
-
createProviderToolFactory: () => createProviderToolFactory,
|
|
52
|
-
createProviderToolFactoryWithOutputSchema: () => createProviderToolFactoryWithOutputSchema,
|
|
53
|
-
createStatusCodeErrorResponseHandler: () => createStatusCodeErrorResponseHandler,
|
|
54
|
-
createToolNameMapping: () => createToolNameMapping,
|
|
55
|
-
delay: () => delay,
|
|
56
|
-
downloadBlob: () => downloadBlob,
|
|
57
|
-
dynamicTool: () => dynamicTool,
|
|
58
|
-
executeTool: () => executeTool,
|
|
59
|
-
extractResponseHeaders: () => extractResponseHeaders,
|
|
60
|
-
generateId: () => generateId,
|
|
61
|
-
getErrorMessage: () => getErrorMessage,
|
|
62
|
-
getFromApi: () => getFromApi,
|
|
63
|
-
getRuntimeEnvironmentUserAgent: () => getRuntimeEnvironmentUserAgent,
|
|
64
|
-
injectJsonInstructionIntoMessages: () => injectJsonInstructionIntoMessages,
|
|
65
|
-
isAbortError: () => isAbortError,
|
|
66
|
-
isCustomReasoning: () => isCustomReasoning,
|
|
67
|
-
isNonNullable: () => isNonNullable,
|
|
68
|
-
isParsableJson: () => isParsableJson,
|
|
69
|
-
isUrlSupported: () => isUrlSupported,
|
|
70
|
-
jsonSchema: () => jsonSchema,
|
|
71
|
-
lazySchema: () => lazySchema,
|
|
72
|
-
loadApiKey: () => loadApiKey,
|
|
73
|
-
loadOptionalSetting: () => loadOptionalSetting,
|
|
74
|
-
loadSetting: () => loadSetting,
|
|
75
|
-
mapReasoningToProviderBudget: () => mapReasoningToProviderBudget,
|
|
76
|
-
mapReasoningToProviderEffort: () => mapReasoningToProviderEffort,
|
|
77
|
-
mediaTypeToExtension: () => mediaTypeToExtension,
|
|
78
|
-
normalizeHeaders: () => normalizeHeaders,
|
|
79
|
-
parseJSON: () => parseJSON,
|
|
80
|
-
parseJsonEventStream: () => parseJsonEventStream,
|
|
81
|
-
parseProviderOptions: () => parseProviderOptions,
|
|
82
|
-
postFormDataToApi: () => postFormDataToApi,
|
|
83
|
-
postJsonToApi: () => postJsonToApi,
|
|
84
|
-
postToApi: () => postToApi,
|
|
85
|
-
readResponseWithSizeLimit: () => readResponseWithSizeLimit,
|
|
86
|
-
removeUndefinedEntries: () => removeUndefinedEntries,
|
|
87
|
-
resolve: () => resolve,
|
|
88
|
-
safeParseJSON: () => safeParseJSON,
|
|
89
|
-
safeValidateTypes: () => safeValidateTypes,
|
|
90
|
-
stripFileExtension: () => stripFileExtension,
|
|
91
|
-
tool: () => tool,
|
|
92
|
-
validateDownloadUrl: () => validateDownloadUrl,
|
|
93
|
-
validateTypes: () => validateTypes,
|
|
94
|
-
withUserAgentSuffix: () => withUserAgentSuffix,
|
|
95
|
-
withoutTrailingSlash: () => withoutTrailingSlash,
|
|
96
|
-
zodSchema: () => zodSchema
|
|
97
|
-
});
|
|
98
|
-
module.exports = __toCommonJS(index_exports);
|
|
1
|
+
// src/as-array.ts
|
|
2
|
+
function asArray(value) {
|
|
3
|
+
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
|
4
|
+
}
|
|
99
5
|
|
|
100
6
|
// src/combine-headers.ts
|
|
101
7
|
function combineHeaders(...headers) {
|
|
@@ -146,6 +52,68 @@ function convertAsyncIteratorToReadableStream(iterator) {
|
|
|
146
52
|
});
|
|
147
53
|
}
|
|
148
54
|
|
|
55
|
+
// src/uint8-utils.ts
|
|
56
|
+
var { btoa, atob } = globalThis;
|
|
57
|
+
function convertBase64ToUint8Array(base64String) {
|
|
58
|
+
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
59
|
+
const latin1string = atob(base64Url);
|
|
60
|
+
return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
|
|
61
|
+
}
|
|
62
|
+
function convertUint8ArrayToBase64(array) {
|
|
63
|
+
let latin1string = "";
|
|
64
|
+
for (let i = 0; i < array.length; i++) {
|
|
65
|
+
latin1string += String.fromCodePoint(array[i]);
|
|
66
|
+
}
|
|
67
|
+
return btoa(latin1string);
|
|
68
|
+
}
|
|
69
|
+
function convertToBase64(value) {
|
|
70
|
+
return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/convert-inline-file-data-to-uint8-array.ts
|
|
74
|
+
function convertInlineFileDataToUint8Array(data) {
|
|
75
|
+
if (data.type === "text") {
|
|
76
|
+
return new TextEncoder().encode(data.text);
|
|
77
|
+
}
|
|
78
|
+
if (data.data instanceof Uint8Array) {
|
|
79
|
+
return data.data;
|
|
80
|
+
}
|
|
81
|
+
if (data.data instanceof ArrayBuffer) {
|
|
82
|
+
return new Uint8Array(data.data);
|
|
83
|
+
}
|
|
84
|
+
return convertBase64ToUint8Array(data.data);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/convert-image-model-file-to-data-uri.ts
|
|
88
|
+
function convertImageModelFileToDataUri(file) {
|
|
89
|
+
if (file.type === "url") return file.url;
|
|
90
|
+
return `data:${file.mediaType};base64,${typeof file.data === "string" ? file.data : convertUint8ArrayToBase64(file.data)}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/convert-to-form-data.ts
|
|
94
|
+
function convertToFormData(input, options = {}) {
|
|
95
|
+
const { useArrayBrackets = true } = options;
|
|
96
|
+
const formData = new FormData();
|
|
97
|
+
for (const [key, value] of Object.entries(input)) {
|
|
98
|
+
if (value == null) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (Array.isArray(value)) {
|
|
102
|
+
if (value.length === 1) {
|
|
103
|
+
formData.append(key, value[0]);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const arrayKey = useArrayBrackets ? `${key}[]` : key;
|
|
107
|
+
for (const item of value) {
|
|
108
|
+
formData.append(arrayKey, item);
|
|
109
|
+
}
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
formData.append(key, value);
|
|
113
|
+
}
|
|
114
|
+
return formData;
|
|
115
|
+
}
|
|
116
|
+
|
|
149
117
|
// src/create-tool-name-mapping.ts
|
|
150
118
|
function createToolNameMapping({
|
|
151
119
|
tools = [],
|
|
@@ -249,66 +217,285 @@ var DelayedPromise = class {
|
|
|
249
217
|
}
|
|
250
218
|
};
|
|
251
219
|
|
|
252
|
-
// src/
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
//
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
220
|
+
// src/detect-media-type.ts
|
|
221
|
+
var imageMediaTypeSignatures = [
|
|
222
|
+
{
|
|
223
|
+
mediaType: "image/gif",
|
|
224
|
+
bytesPrefix: [71, 73, 70]
|
|
225
|
+
// GIF
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
mediaType: "image/png",
|
|
229
|
+
bytesPrefix: [137, 80, 78, 71]
|
|
230
|
+
// PNG
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
mediaType: "image/jpeg",
|
|
234
|
+
bytesPrefix: [255, 216]
|
|
235
|
+
// JPEG
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
mediaType: "image/webp",
|
|
239
|
+
bytesPrefix: [
|
|
240
|
+
82,
|
|
241
|
+
73,
|
|
242
|
+
70,
|
|
243
|
+
70,
|
|
244
|
+
// "RIFF"
|
|
245
|
+
null,
|
|
246
|
+
null,
|
|
247
|
+
null,
|
|
248
|
+
null,
|
|
249
|
+
// file size (variable)
|
|
250
|
+
87,
|
|
251
|
+
69,
|
|
252
|
+
66,
|
|
253
|
+
80
|
|
254
|
+
// "WEBP"
|
|
255
|
+
]
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
mediaType: "image/bmp",
|
|
259
|
+
bytesPrefix: [66, 77]
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
mediaType: "image/tiff",
|
|
263
|
+
bytesPrefix: [73, 73, 42, 0]
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
mediaType: "image/tiff",
|
|
267
|
+
bytesPrefix: [77, 77, 0, 42]
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
mediaType: "image/avif",
|
|
271
|
+
bytesPrefix: [
|
|
272
|
+
0,
|
|
273
|
+
0,
|
|
274
|
+
0,
|
|
275
|
+
32,
|
|
276
|
+
102,
|
|
277
|
+
116,
|
|
278
|
+
121,
|
|
279
|
+
112,
|
|
280
|
+
97,
|
|
281
|
+
118,
|
|
282
|
+
105,
|
|
283
|
+
102
|
|
284
|
+
]
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
mediaType: "image/heic",
|
|
288
|
+
bytesPrefix: [
|
|
289
|
+
0,
|
|
290
|
+
0,
|
|
291
|
+
0,
|
|
292
|
+
32,
|
|
293
|
+
102,
|
|
294
|
+
116,
|
|
295
|
+
121,
|
|
296
|
+
112,
|
|
297
|
+
104,
|
|
298
|
+
101,
|
|
299
|
+
105,
|
|
300
|
+
99
|
|
301
|
+
]
|
|
268
302
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
303
|
+
];
|
|
304
|
+
var documentMediaTypeSignatures = [
|
|
305
|
+
{
|
|
306
|
+
mediaType: "application/pdf",
|
|
307
|
+
bytesPrefix: [37, 80, 68, 70]
|
|
308
|
+
// %PDF
|
|
309
|
+
}
|
|
310
|
+
];
|
|
311
|
+
var audioMediaTypeSignatures = [
|
|
312
|
+
{
|
|
313
|
+
mediaType: "audio/mpeg",
|
|
314
|
+
bytesPrefix: [255, 251]
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
mediaType: "audio/mpeg",
|
|
318
|
+
bytesPrefix: [255, 250]
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
mediaType: "audio/mpeg",
|
|
322
|
+
bytesPrefix: [255, 243]
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
mediaType: "audio/mpeg",
|
|
326
|
+
bytesPrefix: [255, 242]
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
mediaType: "audio/mpeg",
|
|
330
|
+
bytesPrefix: [255, 227]
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
mediaType: "audio/mpeg",
|
|
334
|
+
bytesPrefix: [255, 226]
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
mediaType: "audio/wav",
|
|
338
|
+
bytesPrefix: [
|
|
339
|
+
82,
|
|
340
|
+
// R
|
|
341
|
+
73,
|
|
342
|
+
// I
|
|
343
|
+
70,
|
|
344
|
+
// F
|
|
345
|
+
70,
|
|
346
|
+
// F
|
|
347
|
+
null,
|
|
348
|
+
null,
|
|
349
|
+
null,
|
|
350
|
+
null,
|
|
351
|
+
87,
|
|
352
|
+
// W
|
|
353
|
+
65,
|
|
354
|
+
// A
|
|
355
|
+
86,
|
|
356
|
+
// V
|
|
357
|
+
69
|
|
358
|
+
// E
|
|
359
|
+
]
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
mediaType: "audio/ogg",
|
|
363
|
+
bytesPrefix: [79, 103, 103, 83]
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
mediaType: "audio/flac",
|
|
367
|
+
bytesPrefix: [102, 76, 97, 67]
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
mediaType: "audio/aac",
|
|
371
|
+
bytesPrefix: [64, 21, 0, 0]
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
mediaType: "audio/mp4",
|
|
375
|
+
bytesPrefix: [102, 116, 121, 112]
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
mediaType: "audio/webm",
|
|
379
|
+
bytesPrefix: [26, 69, 223, 163]
|
|
380
|
+
}
|
|
381
|
+
];
|
|
382
|
+
var videoMediaTypeSignatures = [
|
|
383
|
+
{
|
|
384
|
+
mediaType: "video/mp4",
|
|
385
|
+
bytesPrefix: [
|
|
386
|
+
0,
|
|
387
|
+
0,
|
|
388
|
+
0,
|
|
389
|
+
null,
|
|
390
|
+
102,
|
|
391
|
+
116,
|
|
392
|
+
121,
|
|
393
|
+
112
|
|
394
|
+
// ftyp
|
|
395
|
+
]
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
mediaType: "video/webm",
|
|
399
|
+
bytesPrefix: [26, 69, 223, 163]
|
|
400
|
+
// EBML
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
mediaType: "video/quicktime",
|
|
404
|
+
bytesPrefix: [
|
|
405
|
+
0,
|
|
406
|
+
0,
|
|
407
|
+
0,
|
|
408
|
+
20,
|
|
409
|
+
102,
|
|
410
|
+
116,
|
|
411
|
+
121,
|
|
412
|
+
112,
|
|
413
|
+
113,
|
|
414
|
+
116
|
|
415
|
+
// ftypqt
|
|
416
|
+
]
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
mediaType: "video/x-msvideo",
|
|
420
|
+
bytesPrefix: [82, 73, 70, 70]
|
|
421
|
+
// RIFF (AVI)
|
|
422
|
+
}
|
|
423
|
+
];
|
|
424
|
+
var stripID3 = (data) => {
|
|
425
|
+
const bytes = typeof data === "string" ? convertBase64ToUint8Array(data) : data;
|
|
426
|
+
const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
|
|
427
|
+
return bytes.slice(id3Size + 10);
|
|
428
|
+
};
|
|
429
|
+
function stripID3TagsIfPresent(data) {
|
|
430
|
+
const hasId3 = typeof data === "string" && data.startsWith("SUQz") || typeof data !== "string" && data.length > 10 && data[0] === 73 && // 'I'
|
|
431
|
+
data[1] === 68 && // 'D'
|
|
432
|
+
data[2] === 51;
|
|
433
|
+
return hasId3 ? stripID3(data) : data;
|
|
434
|
+
}
|
|
435
|
+
function detectMediaTypeBySignatures({
|
|
436
|
+
data,
|
|
437
|
+
signatures
|
|
438
|
+
}) {
|
|
439
|
+
const processedData = stripID3TagsIfPresent(data);
|
|
440
|
+
const bytes = typeof processedData === "string" ? convertBase64ToUint8Array(
|
|
441
|
+
processedData.substring(0, Math.min(processedData.length, 24))
|
|
442
|
+
) : processedData;
|
|
443
|
+
for (const signature of signatures) {
|
|
444
|
+
if (bytes.length >= signature.bytesPrefix.length && signature.bytesPrefix.every(
|
|
445
|
+
(byte, index) => byte === null || bytes[index] === byte
|
|
446
|
+
)) {
|
|
447
|
+
return signature.mediaType;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return void 0;
|
|
451
|
+
}
|
|
452
|
+
var topLevelSignatureTables = {
|
|
453
|
+
image: imageMediaTypeSignatures,
|
|
454
|
+
audio: audioMediaTypeSignatures,
|
|
455
|
+
video: videoMediaTypeSignatures,
|
|
456
|
+
application: documentMediaTypeSignatures
|
|
457
|
+
};
|
|
458
|
+
function detectMediaType({
|
|
459
|
+
data,
|
|
460
|
+
topLevelType
|
|
461
|
+
}) {
|
|
462
|
+
if (topLevelType === void 0) {
|
|
463
|
+
return detectMediaTypeBySignatures({
|
|
464
|
+
data,
|
|
465
|
+
signatures: [
|
|
466
|
+
...imageMediaTypeSignatures,
|
|
467
|
+
...documentMediaTypeSignatures,
|
|
468
|
+
...audioMediaTypeSignatures,
|
|
469
|
+
...videoMediaTypeSignatures
|
|
470
|
+
]
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
const signatures = topLevelSignatureTables[topLevelType];
|
|
474
|
+
if (signatures === void 0) {
|
|
475
|
+
return void 0;
|
|
476
|
+
}
|
|
477
|
+
return detectMediaTypeBySignatures({ data, signatures });
|
|
273
478
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (file.type === "url") return file.url;
|
|
278
|
-
return `data:${file.mediaType};base64,${typeof file.data === "string" ? file.data : convertUint8ArrayToBase64(file.data)}`;
|
|
479
|
+
function getTopLevelMediaType(mediaType) {
|
|
480
|
+
const slashIndex = mediaType.indexOf("/");
|
|
481
|
+
return slashIndex === -1 ? mediaType : mediaType.substring(0, slashIndex);
|
|
279
482
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const formData = new FormData();
|
|
285
|
-
for (const [key, value] of Object.entries(input)) {
|
|
286
|
-
if (value == null) {
|
|
287
|
-
continue;
|
|
288
|
-
}
|
|
289
|
-
if (Array.isArray(value)) {
|
|
290
|
-
if (value.length === 1) {
|
|
291
|
-
formData.append(key, value[0]);
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
const arrayKey = useArrayBrackets ? `${key}[]` : key;
|
|
295
|
-
for (const item of value) {
|
|
296
|
-
formData.append(arrayKey, item);
|
|
297
|
-
}
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
formData.append(key, value);
|
|
483
|
+
function isFullMediaType(mediaType) {
|
|
484
|
+
const slashIndex = mediaType.indexOf("/");
|
|
485
|
+
if (slashIndex === -1) {
|
|
486
|
+
return false;
|
|
301
487
|
}
|
|
302
|
-
|
|
488
|
+
const subtype = mediaType.substring(slashIndex + 1);
|
|
489
|
+
return subtype.length > 0 && subtype !== "*";
|
|
303
490
|
}
|
|
304
491
|
|
|
305
492
|
// src/download-error.ts
|
|
306
|
-
|
|
493
|
+
import { AISDKError } from "@ai-sdk/provider";
|
|
307
494
|
var name = "AI_DownloadError";
|
|
308
495
|
var marker = `vercel.ai.error.${name}`;
|
|
309
496
|
var symbol = Symbol.for(marker);
|
|
310
497
|
var _a, _b;
|
|
311
|
-
var DownloadError = class extends (_b =
|
|
498
|
+
var DownloadError = class extends (_b = AISDKError, _a = symbol, _b) {
|
|
312
499
|
constructor({
|
|
313
500
|
url,
|
|
314
501
|
statusCode,
|
|
@@ -323,7 +510,7 @@ var DownloadError = class extends (_b = import_provider.AISDKError, _a = symbol,
|
|
|
323
510
|
this.statusText = statusText;
|
|
324
511
|
}
|
|
325
512
|
static isInstance(error) {
|
|
326
|
-
return
|
|
513
|
+
return AISDKError.hasMarker(error, marker);
|
|
327
514
|
}
|
|
328
515
|
};
|
|
329
516
|
|
|
@@ -514,8 +701,18 @@ async function downloadBlob(url, options) {
|
|
|
514
701
|
}
|
|
515
702
|
}
|
|
516
703
|
|
|
704
|
+
// src/extract-response-headers.ts
|
|
705
|
+
function extractResponseHeaders(response) {
|
|
706
|
+
return Object.fromEntries([...response.headers]);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// src/filter-nullable.ts
|
|
710
|
+
function filterNullable(...values) {
|
|
711
|
+
return values.filter((value) => value != null);
|
|
712
|
+
}
|
|
713
|
+
|
|
517
714
|
// src/generate-id.ts
|
|
518
|
-
|
|
715
|
+
import { InvalidArgumentError } from "@ai-sdk/provider";
|
|
519
716
|
var createIdGenerator = ({
|
|
520
717
|
prefix,
|
|
521
718
|
size = 16,
|
|
@@ -534,7 +731,7 @@ var createIdGenerator = ({
|
|
|
534
731
|
return generator;
|
|
535
732
|
}
|
|
536
733
|
if (alphabet.includes(separator)) {
|
|
537
|
-
throw new
|
|
734
|
+
throw new InvalidArgumentError({
|
|
538
735
|
argument: "separator",
|
|
539
736
|
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
540
737
|
});
|
|
@@ -544,24 +741,13 @@ var createIdGenerator = ({
|
|
|
544
741
|
var generateId = createIdGenerator();
|
|
545
742
|
|
|
546
743
|
// src/get-error-message.ts
|
|
547
|
-
|
|
548
|
-
if (error == null) {
|
|
549
|
-
return "unknown error";
|
|
550
|
-
}
|
|
551
|
-
if (typeof error === "string") {
|
|
552
|
-
return error;
|
|
553
|
-
}
|
|
554
|
-
if (error instanceof Error) {
|
|
555
|
-
return error.message;
|
|
556
|
-
}
|
|
557
|
-
return JSON.stringify(error);
|
|
558
|
-
}
|
|
744
|
+
import { getErrorMessage } from "@ai-sdk/provider";
|
|
559
745
|
|
|
560
746
|
// src/get-from-api.ts
|
|
561
|
-
|
|
747
|
+
import { APICallError as APICallError2 } from "@ai-sdk/provider";
|
|
562
748
|
|
|
563
749
|
// src/handle-fetch-error.ts
|
|
564
|
-
|
|
750
|
+
import { APICallError } from "@ai-sdk/provider";
|
|
565
751
|
|
|
566
752
|
// src/is-abort-error.ts
|
|
567
753
|
function isAbortError(error) {
|
|
@@ -601,7 +787,7 @@ function handleFetchError({
|
|
|
601
787
|
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES.includes(error.message.toLowerCase())) {
|
|
602
788
|
const cause = error.cause;
|
|
603
789
|
if (cause != null) {
|
|
604
|
-
return new
|
|
790
|
+
return new APICallError({
|
|
605
791
|
message: `Cannot connect to API: ${cause.message}`,
|
|
606
792
|
cause,
|
|
607
793
|
url,
|
|
@@ -612,7 +798,7 @@ function handleFetchError({
|
|
|
612
798
|
}
|
|
613
799
|
}
|
|
614
800
|
if (isBunNetworkError(error)) {
|
|
615
|
-
return new
|
|
801
|
+
return new APICallError({
|
|
616
802
|
message: `Cannot connect to API: ${error.message}`,
|
|
617
803
|
cause: error,
|
|
618
804
|
url,
|
|
@@ -676,7 +862,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
676
862
|
}
|
|
677
863
|
|
|
678
864
|
// src/version.ts
|
|
679
|
-
var VERSION = true ? "5.0.0-
|
|
865
|
+
var VERSION = true ? "5.0.0-canary.32" : "0.0.0-test";
|
|
680
866
|
|
|
681
867
|
// src/get-from-api.ts
|
|
682
868
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -708,10 +894,10 @@ var getFromApi = async ({
|
|
|
708
894
|
requestBodyValues: {}
|
|
709
895
|
});
|
|
710
896
|
} catch (error) {
|
|
711
|
-
if (isAbortError(error) ||
|
|
897
|
+
if (isAbortError(error) || APICallError2.isInstance(error)) {
|
|
712
898
|
throw error;
|
|
713
899
|
}
|
|
714
|
-
throw new
|
|
900
|
+
throw new APICallError2({
|
|
715
901
|
message: "Failed to process error response",
|
|
716
902
|
cause: error,
|
|
717
903
|
statusCode: response.status,
|
|
@@ -730,11 +916,11 @@ var getFromApi = async ({
|
|
|
730
916
|
});
|
|
731
917
|
} catch (error) {
|
|
732
918
|
if (error instanceof Error) {
|
|
733
|
-
if (isAbortError(error) ||
|
|
919
|
+
if (isAbortError(error) || APICallError2.isInstance(error)) {
|
|
734
920
|
throw error;
|
|
735
921
|
}
|
|
736
922
|
}
|
|
737
|
-
throw new
|
|
923
|
+
throw new APICallError2({
|
|
738
924
|
message: "Failed to process successful response",
|
|
739
925
|
cause: error,
|
|
740
926
|
statusCode: response.status,
|
|
@@ -787,11 +973,22 @@ function injectJsonInstructionIntoMessages({
|
|
|
787
973
|
];
|
|
788
974
|
}
|
|
789
975
|
|
|
976
|
+
// src/is-buffer.ts
|
|
977
|
+
function isBuffer(value) {
|
|
978
|
+
var _a2, _b2;
|
|
979
|
+
return (_b2 = (_a2 = globalThis.Buffer) == null ? void 0 : _a2.isBuffer(value)) != null ? _b2 : false;
|
|
980
|
+
}
|
|
981
|
+
|
|
790
982
|
// src/is-non-nullable.ts
|
|
791
983
|
function isNonNullable(value) {
|
|
792
984
|
return value != null;
|
|
793
985
|
}
|
|
794
986
|
|
|
987
|
+
// src/is-provider-reference.ts
|
|
988
|
+
function isProviderReference(data) {
|
|
989
|
+
return typeof data === "object" && data !== null && !(data instanceof Uint8Array) && !(data instanceof URL) && !(data instanceof ArrayBuffer) && !isBuffer(data) && !("type" in data);
|
|
990
|
+
}
|
|
991
|
+
|
|
795
992
|
// src/is-url-supported.ts
|
|
796
993
|
function isUrlSupported({
|
|
797
994
|
mediaType,
|
|
@@ -800,14 +997,23 @@ function isUrlSupported({
|
|
|
800
997
|
}) {
|
|
801
998
|
url = url.toLowerCase();
|
|
802
999
|
mediaType = mediaType.toLowerCase();
|
|
1000
|
+
const isTopLevelOnly = !mediaType.includes("/");
|
|
803
1001
|
return Object.entries(supportedUrls).map(([key, value]) => {
|
|
804
1002
|
const mediaType2 = key.toLowerCase();
|
|
805
1003
|
return mediaType2 === "*" || mediaType2 === "*/*" ? { mediaTypePrefix: "", regexes: value } : { mediaTypePrefix: mediaType2.replace(/\*/, ""), regexes: value };
|
|
806
|
-
}).filter(({ mediaTypePrefix }) =>
|
|
1004
|
+
}).filter(({ mediaTypePrefix }) => {
|
|
1005
|
+
if (mediaTypePrefix === "") {
|
|
1006
|
+
return true;
|
|
1007
|
+
}
|
|
1008
|
+
if (isTopLevelOnly) {
|
|
1009
|
+
return `${mediaType}/` === mediaTypePrefix;
|
|
1010
|
+
}
|
|
1011
|
+
return mediaType.startsWith(mediaTypePrefix);
|
|
1012
|
+
}).flatMap(({ regexes }) => regexes).some((pattern) => pattern.test(url));
|
|
807
1013
|
}
|
|
808
1014
|
|
|
809
1015
|
// src/load-api-key.ts
|
|
810
|
-
|
|
1016
|
+
import { LoadAPIKeyError } from "@ai-sdk/provider";
|
|
811
1017
|
function loadApiKey({
|
|
812
1018
|
apiKey,
|
|
813
1019
|
environmentVariableName,
|
|
@@ -818,29 +1024,82 @@ function loadApiKey({
|
|
|
818
1024
|
return apiKey;
|
|
819
1025
|
}
|
|
820
1026
|
if (apiKey != null) {
|
|
821
|
-
throw new
|
|
1027
|
+
throw new LoadAPIKeyError({
|
|
822
1028
|
message: `${description} API key must be a string.`
|
|
823
1029
|
});
|
|
824
1030
|
}
|
|
825
1031
|
if (typeof process === "undefined") {
|
|
826
|
-
throw new
|
|
827
|
-
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables
|
|
1032
|
+
throw new LoadAPIKeyError({
|
|
1033
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables are not supported in this environment.`
|
|
828
1034
|
});
|
|
829
1035
|
}
|
|
830
1036
|
apiKey = process.env[environmentVariableName];
|
|
831
1037
|
if (apiKey == null) {
|
|
832
|
-
throw new
|
|
1038
|
+
throw new LoadAPIKeyError({
|
|
833
1039
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
834
1040
|
});
|
|
835
1041
|
}
|
|
836
1042
|
if (typeof apiKey !== "string") {
|
|
837
|
-
throw new
|
|
1043
|
+
throw new LoadAPIKeyError({
|
|
838
1044
|
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
839
1045
|
});
|
|
840
1046
|
}
|
|
841
1047
|
return apiKey;
|
|
842
1048
|
}
|
|
843
1049
|
|
|
1050
|
+
// src/load-optional-setting.ts
|
|
1051
|
+
function loadOptionalSetting({
|
|
1052
|
+
settingValue,
|
|
1053
|
+
environmentVariableName
|
|
1054
|
+
}) {
|
|
1055
|
+
if (typeof settingValue === "string") {
|
|
1056
|
+
return settingValue;
|
|
1057
|
+
}
|
|
1058
|
+
if (settingValue != null || typeof process === "undefined") {
|
|
1059
|
+
return void 0;
|
|
1060
|
+
}
|
|
1061
|
+
settingValue = process.env[environmentVariableName];
|
|
1062
|
+
if (settingValue == null || typeof settingValue !== "string") {
|
|
1063
|
+
return void 0;
|
|
1064
|
+
}
|
|
1065
|
+
return settingValue;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
// src/load-setting.ts
|
|
1069
|
+
import { LoadSettingError } from "@ai-sdk/provider";
|
|
1070
|
+
function loadSetting({
|
|
1071
|
+
settingValue,
|
|
1072
|
+
environmentVariableName,
|
|
1073
|
+
settingName,
|
|
1074
|
+
description
|
|
1075
|
+
}) {
|
|
1076
|
+
if (typeof settingValue === "string") {
|
|
1077
|
+
return settingValue;
|
|
1078
|
+
}
|
|
1079
|
+
if (settingValue != null) {
|
|
1080
|
+
throw new LoadSettingError({
|
|
1081
|
+
message: `${description} setting must be a string.`
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
if (typeof process === "undefined") {
|
|
1085
|
+
throw new LoadSettingError({
|
|
1086
|
+
message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables are not supported in this environment.`
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
settingValue = process.env[environmentVariableName];
|
|
1090
|
+
if (settingValue == null) {
|
|
1091
|
+
throw new LoadSettingError({
|
|
1092
|
+
message: `${description} setting is missing. Pass it using the '${settingName}' parameter or the ${environmentVariableName} environment variable.`
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
if (typeof settingValue !== "string") {
|
|
1096
|
+
throw new LoadSettingError({
|
|
1097
|
+
message: `${description} setting must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
return settingValue;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
844
1103
|
// src/map-reasoning-to-provider.ts
|
|
845
1104
|
function isCustomReasoning(reasoning) {
|
|
846
1105
|
return reasoning !== void 0 && reasoning !== "provider-default";
|
|
@@ -898,59 +1157,6 @@ function mapReasoningToProviderBudget({
|
|
|
898
1157
|
);
|
|
899
1158
|
}
|
|
900
1159
|
|
|
901
|
-
// src/load-optional-setting.ts
|
|
902
|
-
function loadOptionalSetting({
|
|
903
|
-
settingValue,
|
|
904
|
-
environmentVariableName
|
|
905
|
-
}) {
|
|
906
|
-
if (typeof settingValue === "string") {
|
|
907
|
-
return settingValue;
|
|
908
|
-
}
|
|
909
|
-
if (settingValue != null || typeof process === "undefined") {
|
|
910
|
-
return void 0;
|
|
911
|
-
}
|
|
912
|
-
settingValue = process.env[environmentVariableName];
|
|
913
|
-
if (settingValue == null || typeof settingValue !== "string") {
|
|
914
|
-
return void 0;
|
|
915
|
-
}
|
|
916
|
-
return settingValue;
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
// src/load-setting.ts
|
|
920
|
-
var import_provider6 = require("@ai-sdk/provider");
|
|
921
|
-
function loadSetting({
|
|
922
|
-
settingValue,
|
|
923
|
-
environmentVariableName,
|
|
924
|
-
settingName,
|
|
925
|
-
description
|
|
926
|
-
}) {
|
|
927
|
-
if (typeof settingValue === "string") {
|
|
928
|
-
return settingValue;
|
|
929
|
-
}
|
|
930
|
-
if (settingValue != null) {
|
|
931
|
-
throw new import_provider6.LoadSettingError({
|
|
932
|
-
message: `${description} setting must be a string.`
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
if (typeof process === "undefined") {
|
|
936
|
-
throw new import_provider6.LoadSettingError({
|
|
937
|
-
message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables is not supported in this environment.`
|
|
938
|
-
});
|
|
939
|
-
}
|
|
940
|
-
settingValue = process.env[environmentVariableName];
|
|
941
|
-
if (settingValue == null) {
|
|
942
|
-
throw new import_provider6.LoadSettingError({
|
|
943
|
-
message: `${description} setting is missing. Pass it using the '${settingName}' parameter or the ${environmentVariableName} environment variable.`
|
|
944
|
-
});
|
|
945
|
-
}
|
|
946
|
-
if (typeof settingValue !== "string") {
|
|
947
|
-
throw new import_provider6.LoadSettingError({
|
|
948
|
-
message: `${description} setting must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
return settingValue;
|
|
952
|
-
}
|
|
953
|
-
|
|
954
1160
|
// src/media-type-to-extension.ts
|
|
955
1161
|
function mediaTypeToExtension(mediaType) {
|
|
956
1162
|
var _a2;
|
|
@@ -965,7 +1171,10 @@ function mediaTypeToExtension(mediaType) {
|
|
|
965
1171
|
}
|
|
966
1172
|
|
|
967
1173
|
// src/parse-json.ts
|
|
968
|
-
|
|
1174
|
+
import {
|
|
1175
|
+
JSONParseError,
|
|
1176
|
+
TypeValidationError as TypeValidationError3
|
|
1177
|
+
} from "@ai-sdk/provider";
|
|
969
1178
|
|
|
970
1179
|
// src/secure-json-parse.ts
|
|
971
1180
|
var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
@@ -1017,11 +1226,13 @@ function secureJsonParse(text) {
|
|
|
1017
1226
|
}
|
|
1018
1227
|
|
|
1019
1228
|
// src/validate-types.ts
|
|
1020
|
-
|
|
1229
|
+
import {
|
|
1230
|
+
TypeValidationError as TypeValidationError2
|
|
1231
|
+
} from "@ai-sdk/provider";
|
|
1021
1232
|
|
|
1022
1233
|
// src/schema.ts
|
|
1023
|
-
|
|
1024
|
-
|
|
1234
|
+
import { TypeValidationError } from "@ai-sdk/provider";
|
|
1235
|
+
import * as z4 from "zod/v4";
|
|
1025
1236
|
|
|
1026
1237
|
// src/add-additional-properties-to-json-schema.ts
|
|
1027
1238
|
function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
|
|
@@ -1093,7 +1304,7 @@ var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
|
1093
1304
|
};
|
|
1094
1305
|
|
|
1095
1306
|
// src/to-json-schema/zod3-to-json-schema/select-parser.ts
|
|
1096
|
-
|
|
1307
|
+
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod/v3";
|
|
1097
1308
|
|
|
1098
1309
|
// src/to-json-schema/zod3-to-json-schema/parsers/any.ts
|
|
1099
1310
|
function parseAnyDef() {
|
|
@@ -1101,13 +1312,13 @@ function parseAnyDef() {
|
|
|
1101
1312
|
}
|
|
1102
1313
|
|
|
1103
1314
|
// src/to-json-schema/zod3-to-json-schema/parsers/array.ts
|
|
1104
|
-
|
|
1315
|
+
import { ZodFirstPartyTypeKind } from "zod/v3";
|
|
1105
1316
|
function parseArrayDef(def, refs) {
|
|
1106
1317
|
var _a2, _b2, _c;
|
|
1107
1318
|
const res = {
|
|
1108
1319
|
type: "array"
|
|
1109
1320
|
};
|
|
1110
|
-
if (((_a2 = def.type) == null ? void 0 : _a2._def) && ((_c = (_b2 = def.type) == null ? void 0 : _b2._def) == null ? void 0 : _c.typeName) !==
|
|
1321
|
+
if (((_a2 = def.type) == null ? void 0 : _a2._def) && ((_c = (_b2 = def.type) == null ? void 0 : _b2._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
|
|
1111
1322
|
res.items = parseDef(def.type._def, {
|
|
1112
1323
|
...refs,
|
|
1113
1324
|
currentPath: [...refs.currentPath, "items"]
|
|
@@ -1177,7 +1388,7 @@ function parseDateDef(def, refs, overrideDateStrategy) {
|
|
|
1177
1388
|
const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
|
|
1178
1389
|
if (Array.isArray(strategy)) {
|
|
1179
1390
|
return {
|
|
1180
|
-
anyOf: strategy.map((item
|
|
1391
|
+
anyOf: strategy.map((item) => parseDateDef(def, refs, item))
|
|
1181
1392
|
};
|
|
1182
1393
|
}
|
|
1183
1394
|
switch (strategy) {
|
|
@@ -1258,7 +1469,7 @@ function parseIntersectionDef(def, refs) {
|
|
|
1258
1469
|
} else {
|
|
1259
1470
|
let nestedSchema = schema;
|
|
1260
1471
|
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
1261
|
-
const { additionalProperties, ...rest } = schema;
|
|
1472
|
+
const { additionalProperties: _additionalProperties, ...rest } = schema;
|
|
1262
1473
|
nestedSchema = rest;
|
|
1263
1474
|
}
|
|
1264
1475
|
mergedAllOf.push(nestedSchema);
|
|
@@ -1282,7 +1493,9 @@ function parseLiteralDef(def) {
|
|
|
1282
1493
|
}
|
|
1283
1494
|
|
|
1284
1495
|
// src/to-json-schema/zod3-to-json-schema/parsers/record.ts
|
|
1285
|
-
|
|
1496
|
+
import {
|
|
1497
|
+
ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2
|
|
1498
|
+
} from "zod/v3";
|
|
1286
1499
|
|
|
1287
1500
|
// src/to-json-schema/zod3-to-json-schema/parsers/string.ts
|
|
1288
1501
|
var emojiRegex = void 0;
|
|
@@ -1630,21 +1843,21 @@ function parseRecordDef(def, refs) {
|
|
|
1630
1843
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1631
1844
|
})) != null ? _a2 : refs.allowedAdditionalProperties
|
|
1632
1845
|
};
|
|
1633
|
-
if (((_b2 = def.keyType) == null ? void 0 : _b2._def.typeName) ===
|
|
1634
|
-
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
1846
|
+
if (((_b2 = def.keyType) == null ? void 0 : _b2._def.typeName) === ZodFirstPartyTypeKind2.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1847
|
+
const { type: _type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
1635
1848
|
return {
|
|
1636
1849
|
...schema,
|
|
1637
1850
|
propertyNames: keyType
|
|
1638
1851
|
};
|
|
1639
|
-
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) ===
|
|
1852
|
+
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
1640
1853
|
return {
|
|
1641
1854
|
...schema,
|
|
1642
1855
|
propertyNames: {
|
|
1643
1856
|
enum: def.keyType._def.values
|
|
1644
1857
|
}
|
|
1645
1858
|
};
|
|
1646
|
-
} else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) ===
|
|
1647
|
-
const { type, ...keyType } = parseBrandedDef(
|
|
1859
|
+
} else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) === ZodFirstPartyTypeKind2.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind2.ZodString && ((_f = def.keyType._def.type._def.checks) == null ? void 0 : _f.length)) {
|
|
1860
|
+
const { type: _type, ...keyType } = parseBrandedDef(
|
|
1648
1861
|
def.keyType._def,
|
|
1649
1862
|
refs
|
|
1650
1863
|
);
|
|
@@ -2017,73 +2230,73 @@ var parseReadonlyDef = (def, refs) => {
|
|
|
2017
2230
|
// src/to-json-schema/zod3-to-json-schema/select-parser.ts
|
|
2018
2231
|
var selectParser = (def, typeName, refs) => {
|
|
2019
2232
|
switch (typeName) {
|
|
2020
|
-
case
|
|
2233
|
+
case ZodFirstPartyTypeKind3.ZodString:
|
|
2021
2234
|
return parseStringDef(def, refs);
|
|
2022
|
-
case
|
|
2235
|
+
case ZodFirstPartyTypeKind3.ZodNumber:
|
|
2023
2236
|
return parseNumberDef(def);
|
|
2024
|
-
case
|
|
2237
|
+
case ZodFirstPartyTypeKind3.ZodObject:
|
|
2025
2238
|
return parseObjectDef(def, refs);
|
|
2026
|
-
case
|
|
2239
|
+
case ZodFirstPartyTypeKind3.ZodBigInt:
|
|
2027
2240
|
return parseBigintDef(def);
|
|
2028
|
-
case
|
|
2241
|
+
case ZodFirstPartyTypeKind3.ZodBoolean:
|
|
2029
2242
|
return parseBooleanDef();
|
|
2030
|
-
case
|
|
2243
|
+
case ZodFirstPartyTypeKind3.ZodDate:
|
|
2031
2244
|
return parseDateDef(def, refs);
|
|
2032
|
-
case
|
|
2245
|
+
case ZodFirstPartyTypeKind3.ZodUndefined:
|
|
2033
2246
|
return parseUndefinedDef();
|
|
2034
|
-
case
|
|
2247
|
+
case ZodFirstPartyTypeKind3.ZodNull:
|
|
2035
2248
|
return parseNullDef();
|
|
2036
|
-
case
|
|
2249
|
+
case ZodFirstPartyTypeKind3.ZodArray:
|
|
2037
2250
|
return parseArrayDef(def, refs);
|
|
2038
|
-
case
|
|
2039
|
-
case
|
|
2251
|
+
case ZodFirstPartyTypeKind3.ZodUnion:
|
|
2252
|
+
case ZodFirstPartyTypeKind3.ZodDiscriminatedUnion:
|
|
2040
2253
|
return parseUnionDef(def, refs);
|
|
2041
|
-
case
|
|
2254
|
+
case ZodFirstPartyTypeKind3.ZodIntersection:
|
|
2042
2255
|
return parseIntersectionDef(def, refs);
|
|
2043
|
-
case
|
|
2256
|
+
case ZodFirstPartyTypeKind3.ZodTuple:
|
|
2044
2257
|
return parseTupleDef(def, refs);
|
|
2045
|
-
case
|
|
2258
|
+
case ZodFirstPartyTypeKind3.ZodRecord:
|
|
2046
2259
|
return parseRecordDef(def, refs);
|
|
2047
|
-
case
|
|
2260
|
+
case ZodFirstPartyTypeKind3.ZodLiteral:
|
|
2048
2261
|
return parseLiteralDef(def);
|
|
2049
|
-
case
|
|
2262
|
+
case ZodFirstPartyTypeKind3.ZodEnum:
|
|
2050
2263
|
return parseEnumDef(def);
|
|
2051
|
-
case
|
|
2264
|
+
case ZodFirstPartyTypeKind3.ZodNativeEnum:
|
|
2052
2265
|
return parseNativeEnumDef(def);
|
|
2053
|
-
case
|
|
2266
|
+
case ZodFirstPartyTypeKind3.ZodNullable:
|
|
2054
2267
|
return parseNullableDef(def, refs);
|
|
2055
|
-
case
|
|
2268
|
+
case ZodFirstPartyTypeKind3.ZodOptional:
|
|
2056
2269
|
return parseOptionalDef(def, refs);
|
|
2057
|
-
case
|
|
2270
|
+
case ZodFirstPartyTypeKind3.ZodMap:
|
|
2058
2271
|
return parseMapDef(def, refs);
|
|
2059
|
-
case
|
|
2272
|
+
case ZodFirstPartyTypeKind3.ZodSet:
|
|
2060
2273
|
return parseSetDef(def, refs);
|
|
2061
|
-
case
|
|
2274
|
+
case ZodFirstPartyTypeKind3.ZodLazy:
|
|
2062
2275
|
return () => def.getter()._def;
|
|
2063
|
-
case
|
|
2276
|
+
case ZodFirstPartyTypeKind3.ZodPromise:
|
|
2064
2277
|
return parsePromiseDef(def, refs);
|
|
2065
|
-
case
|
|
2066
|
-
case
|
|
2278
|
+
case ZodFirstPartyTypeKind3.ZodNaN:
|
|
2279
|
+
case ZodFirstPartyTypeKind3.ZodNever:
|
|
2067
2280
|
return parseNeverDef();
|
|
2068
|
-
case
|
|
2281
|
+
case ZodFirstPartyTypeKind3.ZodEffects:
|
|
2069
2282
|
return parseEffectsDef(def, refs);
|
|
2070
|
-
case
|
|
2283
|
+
case ZodFirstPartyTypeKind3.ZodAny:
|
|
2071
2284
|
return parseAnyDef();
|
|
2072
|
-
case
|
|
2285
|
+
case ZodFirstPartyTypeKind3.ZodUnknown:
|
|
2073
2286
|
return parseUnknownDef();
|
|
2074
|
-
case
|
|
2287
|
+
case ZodFirstPartyTypeKind3.ZodDefault:
|
|
2075
2288
|
return parseDefaultDef(def, refs);
|
|
2076
|
-
case
|
|
2289
|
+
case ZodFirstPartyTypeKind3.ZodBranded:
|
|
2077
2290
|
return parseBrandedDef(def, refs);
|
|
2078
|
-
case
|
|
2291
|
+
case ZodFirstPartyTypeKind3.ZodReadonly:
|
|
2079
2292
|
return parseReadonlyDef(def, refs);
|
|
2080
|
-
case
|
|
2293
|
+
case ZodFirstPartyTypeKind3.ZodCatch:
|
|
2081
2294
|
return parseCatchDef(def, refs);
|
|
2082
|
-
case
|
|
2295
|
+
case ZodFirstPartyTypeKind3.ZodPipeline:
|
|
2083
2296
|
return parsePipelineDef(def, refs);
|
|
2084
|
-
case
|
|
2085
|
-
case
|
|
2086
|
-
case
|
|
2297
|
+
case ZodFirstPartyTypeKind3.ZodFunction:
|
|
2298
|
+
case ZodFirstPartyTypeKind3.ZodVoid:
|
|
2299
|
+
case ZodFirstPartyTypeKind3.ZodSymbol:
|
|
2087
2300
|
return void 0;
|
|
2088
2301
|
default:
|
|
2089
2302
|
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
@@ -2282,7 +2495,7 @@ function standardSchema(standardSchema2) {
|
|
|
2282
2495
|
const result = await standardSchema2["~standard"].validate(value);
|
|
2283
2496
|
return "value" in result ? { success: true, value: result.value } : {
|
|
2284
2497
|
success: false,
|
|
2285
|
-
error: new
|
|
2498
|
+
error: new TypeValidationError({
|
|
2286
2499
|
value,
|
|
2287
2500
|
cause: result.issues
|
|
2288
2501
|
})
|
|
@@ -2346,7 +2559,7 @@ async function validateTypes({
|
|
|
2346
2559
|
}) {
|
|
2347
2560
|
const result = await safeValidateTypes({ value, schema, context });
|
|
2348
2561
|
if (!result.success) {
|
|
2349
|
-
throw
|
|
2562
|
+
throw TypeValidationError2.wrap({ value, cause: result.error, context });
|
|
2350
2563
|
}
|
|
2351
2564
|
return result.value;
|
|
2352
2565
|
}
|
|
@@ -2366,13 +2579,13 @@ async function safeValidateTypes({
|
|
|
2366
2579
|
}
|
|
2367
2580
|
return {
|
|
2368
2581
|
success: false,
|
|
2369
|
-
error:
|
|
2582
|
+
error: TypeValidationError2.wrap({ value, cause: result.error, context }),
|
|
2370
2583
|
rawValue: value
|
|
2371
2584
|
};
|
|
2372
2585
|
} catch (error) {
|
|
2373
2586
|
return {
|
|
2374
2587
|
success: false,
|
|
2375
|
-
error:
|
|
2588
|
+
error: TypeValidationError2.wrap({ value, cause: error, context }),
|
|
2376
2589
|
rawValue: value
|
|
2377
2590
|
};
|
|
2378
2591
|
}
|
|
@@ -2388,12 +2601,12 @@ async function parseJSON({
|
|
|
2388
2601
|
if (schema == null) {
|
|
2389
2602
|
return value;
|
|
2390
2603
|
}
|
|
2391
|
-
return validateTypes({ value, schema });
|
|
2604
|
+
return await validateTypes({ value, schema });
|
|
2392
2605
|
} catch (error) {
|
|
2393
|
-
if (
|
|
2606
|
+
if (JSONParseError.isInstance(error) || TypeValidationError3.isInstance(error)) {
|
|
2394
2607
|
throw error;
|
|
2395
2608
|
}
|
|
2396
|
-
throw new
|
|
2609
|
+
throw new JSONParseError({ text, cause: error });
|
|
2397
2610
|
}
|
|
2398
2611
|
}
|
|
2399
2612
|
async function safeParseJSON({
|
|
@@ -2409,7 +2622,7 @@ async function safeParseJSON({
|
|
|
2409
2622
|
} catch (error) {
|
|
2410
2623
|
return {
|
|
2411
2624
|
success: false,
|
|
2412
|
-
error:
|
|
2625
|
+
error: JSONParseError.isInstance(error) ? error : new JSONParseError({ text, cause: error }),
|
|
2413
2626
|
rawValue: void 0
|
|
2414
2627
|
};
|
|
2415
2628
|
}
|
|
@@ -2424,12 +2637,14 @@ function isParsableJson(input) {
|
|
|
2424
2637
|
}
|
|
2425
2638
|
|
|
2426
2639
|
// src/parse-json-event-stream.ts
|
|
2427
|
-
|
|
2640
|
+
import {
|
|
2641
|
+
EventSourceParserStream
|
|
2642
|
+
} from "eventsource-parser/stream";
|
|
2428
2643
|
function parseJsonEventStream({
|
|
2429
2644
|
stream,
|
|
2430
2645
|
schema
|
|
2431
2646
|
}) {
|
|
2432
|
-
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new
|
|
2647
|
+
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).pipeThrough(
|
|
2433
2648
|
new TransformStream({
|
|
2434
2649
|
async transform({ data }, controller) {
|
|
2435
2650
|
if (data === "[DONE]") {
|
|
@@ -2442,7 +2657,7 @@ function parseJsonEventStream({
|
|
|
2442
2657
|
}
|
|
2443
2658
|
|
|
2444
2659
|
// src/parse-provider-options.ts
|
|
2445
|
-
|
|
2660
|
+
import { InvalidArgumentError as InvalidArgumentError2 } from "@ai-sdk/provider";
|
|
2446
2661
|
async function parseProviderOptions({
|
|
2447
2662
|
provider,
|
|
2448
2663
|
providerOptions,
|
|
@@ -2456,7 +2671,7 @@ async function parseProviderOptions({
|
|
|
2456
2671
|
schema
|
|
2457
2672
|
});
|
|
2458
2673
|
if (!parsedProviderOptions.success) {
|
|
2459
|
-
throw new
|
|
2674
|
+
throw new InvalidArgumentError2({
|
|
2460
2675
|
argument: "providerOptions",
|
|
2461
2676
|
message: `invalid ${provider} provider options`,
|
|
2462
2677
|
cause: parsedProviderOptions.error
|
|
@@ -2466,7 +2681,7 @@ async function parseProviderOptions({
|
|
|
2466
2681
|
}
|
|
2467
2682
|
|
|
2468
2683
|
// src/post-to-api.ts
|
|
2469
|
-
|
|
2684
|
+
import { APICallError as APICallError3 } from "@ai-sdk/provider";
|
|
2470
2685
|
var getOriginalFetch2 = () => globalThis.fetch;
|
|
2471
2686
|
var postJsonToApi = async ({
|
|
2472
2687
|
url,
|
|
@@ -2476,7 +2691,7 @@ var postJsonToApi = async ({
|
|
|
2476
2691
|
successfulResponseHandler,
|
|
2477
2692
|
abortSignal,
|
|
2478
2693
|
fetch: fetch2
|
|
2479
|
-
}) => postToApi({
|
|
2694
|
+
}) => await postToApi({
|
|
2480
2695
|
url,
|
|
2481
2696
|
headers: {
|
|
2482
2697
|
"Content-Type": "application/json",
|
|
@@ -2499,7 +2714,7 @@ var postFormDataToApi = async ({
|
|
|
2499
2714
|
successfulResponseHandler,
|
|
2500
2715
|
abortSignal,
|
|
2501
2716
|
fetch: fetch2
|
|
2502
|
-
}) => postToApi({
|
|
2717
|
+
}) => await postToApi({
|
|
2503
2718
|
url,
|
|
2504
2719
|
headers,
|
|
2505
2720
|
body: {
|
|
@@ -2541,10 +2756,10 @@ var postToApi = async ({
|
|
|
2541
2756
|
requestBodyValues: body.values
|
|
2542
2757
|
});
|
|
2543
2758
|
} catch (error) {
|
|
2544
|
-
if (isAbortError(error) ||
|
|
2759
|
+
if (isAbortError(error) || APICallError3.isInstance(error)) {
|
|
2545
2760
|
throw error;
|
|
2546
2761
|
}
|
|
2547
|
-
throw new
|
|
2762
|
+
throw new APICallError3({
|
|
2548
2763
|
message: "Failed to process error response",
|
|
2549
2764
|
cause: error,
|
|
2550
2765
|
statusCode: response.status,
|
|
@@ -2563,11 +2778,11 @@ var postToApi = async ({
|
|
|
2563
2778
|
});
|
|
2564
2779
|
} catch (error) {
|
|
2565
2780
|
if (error instanceof Error) {
|
|
2566
|
-
if (isAbortError(error) ||
|
|
2781
|
+
if (isAbortError(error) || APICallError3.isInstance(error)) {
|
|
2567
2782
|
throw error;
|
|
2568
2783
|
}
|
|
2569
2784
|
}
|
|
2570
|
-
throw new
|
|
2785
|
+
throw new APICallError3({
|
|
2571
2786
|
message: "Failed to process successful response",
|
|
2572
2787
|
cause: error,
|
|
2573
2788
|
statusCode: response.status,
|
|
@@ -2589,8 +2804,8 @@ function dynamicTool(tool2) {
|
|
|
2589
2804
|
return { ...tool2, type: "dynamic" };
|
|
2590
2805
|
}
|
|
2591
2806
|
|
|
2592
|
-
// src/provider-tool-factory.ts
|
|
2593
|
-
function
|
|
2807
|
+
// src/provider-defined-tool-factory.ts
|
|
2808
|
+
function createProviderDefinedToolFactory({
|
|
2594
2809
|
id,
|
|
2595
2810
|
inputSchema
|
|
2596
2811
|
}) {
|
|
@@ -2605,6 +2820,7 @@ function createProviderToolFactory({
|
|
|
2605
2820
|
...args
|
|
2606
2821
|
}) => tool({
|
|
2607
2822
|
type: "provider",
|
|
2823
|
+
isProviderExecuted: false,
|
|
2608
2824
|
id,
|
|
2609
2825
|
args,
|
|
2610
2826
|
inputSchema,
|
|
@@ -2617,11 +2833,10 @@ function createProviderToolFactory({
|
|
|
2617
2833
|
onInputAvailable
|
|
2618
2834
|
});
|
|
2619
2835
|
}
|
|
2620
|
-
function
|
|
2836
|
+
function createProviderDefinedToolFactoryWithOutputSchema({
|
|
2621
2837
|
id,
|
|
2622
2838
|
inputSchema,
|
|
2623
|
-
outputSchema
|
|
2624
|
-
supportsDeferredResults
|
|
2839
|
+
outputSchema
|
|
2625
2840
|
}) {
|
|
2626
2841
|
return ({
|
|
2627
2842
|
execute,
|
|
@@ -2633,6 +2848,7 @@ function createProviderToolFactoryWithOutputSchema({
|
|
|
2633
2848
|
...args
|
|
2634
2849
|
}) => tool({
|
|
2635
2850
|
type: "provider",
|
|
2851
|
+
isProviderExecuted: false,
|
|
2636
2852
|
id,
|
|
2637
2853
|
args,
|
|
2638
2854
|
inputSchema,
|
|
@@ -2642,6 +2858,31 @@ function createProviderToolFactoryWithOutputSchema({
|
|
|
2642
2858
|
toModelOutput,
|
|
2643
2859
|
onInputStart,
|
|
2644
2860
|
onInputDelta,
|
|
2861
|
+
onInputAvailable
|
|
2862
|
+
});
|
|
2863
|
+
}
|
|
2864
|
+
|
|
2865
|
+
// src/provider-executed-tool-factory.ts
|
|
2866
|
+
function createProviderExecutedToolFactory({
|
|
2867
|
+
id,
|
|
2868
|
+
inputSchema,
|
|
2869
|
+
outputSchema,
|
|
2870
|
+
supportsDeferredResults
|
|
2871
|
+
}) {
|
|
2872
|
+
return ({
|
|
2873
|
+
onInputStart,
|
|
2874
|
+
onInputDelta,
|
|
2875
|
+
onInputAvailable,
|
|
2876
|
+
...args
|
|
2877
|
+
}) => tool({
|
|
2878
|
+
type: "provider",
|
|
2879
|
+
isProviderExecuted: true,
|
|
2880
|
+
id,
|
|
2881
|
+
args,
|
|
2882
|
+
inputSchema,
|
|
2883
|
+
outputSchema,
|
|
2884
|
+
onInputStart,
|
|
2885
|
+
onInputDelta,
|
|
2645
2886
|
onInputAvailable,
|
|
2646
2887
|
supportsDeferredResults
|
|
2647
2888
|
});
|
|
@@ -2662,8 +2903,53 @@ async function resolve(value) {
|
|
|
2662
2903
|
return Promise.resolve(value);
|
|
2663
2904
|
}
|
|
2664
2905
|
|
|
2906
|
+
// src/resolve-full-media-type.ts
|
|
2907
|
+
import {
|
|
2908
|
+
UnsupportedFunctionalityError
|
|
2909
|
+
} from "@ai-sdk/provider";
|
|
2910
|
+
function resolveFullMediaType({
|
|
2911
|
+
part
|
|
2912
|
+
}) {
|
|
2913
|
+
if (isFullMediaType(part.mediaType)) {
|
|
2914
|
+
return part.mediaType;
|
|
2915
|
+
}
|
|
2916
|
+
if (part.data.type === "data") {
|
|
2917
|
+
const detected = detectMediaType({
|
|
2918
|
+
data: part.data.data,
|
|
2919
|
+
topLevelType: getTopLevelMediaType(part.mediaType)
|
|
2920
|
+
});
|
|
2921
|
+
if (detected) {
|
|
2922
|
+
return detected;
|
|
2923
|
+
}
|
|
2924
|
+
throw new UnsupportedFunctionalityError({
|
|
2925
|
+
functionality: `file of media type "${part.mediaType}" must specify subtype since it could not be auto-detected`
|
|
2926
|
+
});
|
|
2927
|
+
}
|
|
2928
|
+
throw new UnsupportedFunctionalityError({
|
|
2929
|
+
functionality: `file of media type "${part.mediaType}" must specify subtype since it is not passed as inline bytes`
|
|
2930
|
+
});
|
|
2931
|
+
}
|
|
2932
|
+
|
|
2933
|
+
// src/resolve-provider-reference.ts
|
|
2934
|
+
import {
|
|
2935
|
+
NoSuchProviderReferenceError
|
|
2936
|
+
} from "@ai-sdk/provider";
|
|
2937
|
+
function resolveProviderReference({
|
|
2938
|
+
reference,
|
|
2939
|
+
provider
|
|
2940
|
+
}) {
|
|
2941
|
+
const id = reference[provider];
|
|
2942
|
+
if (id != null) {
|
|
2943
|
+
return id;
|
|
2944
|
+
}
|
|
2945
|
+
throw new NoSuchProviderReferenceError({
|
|
2946
|
+
provider,
|
|
2947
|
+
reference
|
|
2948
|
+
});
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2665
2951
|
// src/response-handler.ts
|
|
2666
|
-
|
|
2952
|
+
import { APICallError as APICallError4, EmptyResponseBodyError } from "@ai-sdk/provider";
|
|
2667
2953
|
var createJsonErrorResponseHandler = ({
|
|
2668
2954
|
errorSchema,
|
|
2669
2955
|
errorToMessage,
|
|
@@ -2674,7 +2960,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
2674
2960
|
if (responseBody.trim() === "") {
|
|
2675
2961
|
return {
|
|
2676
2962
|
responseHeaders,
|
|
2677
|
-
value: new
|
|
2963
|
+
value: new APICallError4({
|
|
2678
2964
|
message: response.statusText,
|
|
2679
2965
|
url,
|
|
2680
2966
|
requestBodyValues,
|
|
@@ -2692,7 +2978,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
2692
2978
|
});
|
|
2693
2979
|
return {
|
|
2694
2980
|
responseHeaders,
|
|
2695
|
-
value: new
|
|
2981
|
+
value: new APICallError4({
|
|
2696
2982
|
message: errorToMessage(parsedError),
|
|
2697
2983
|
url,
|
|
2698
2984
|
requestBodyValues,
|
|
@@ -2703,10 +2989,10 @@ var createJsonErrorResponseHandler = ({
|
|
|
2703
2989
|
isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
|
|
2704
2990
|
})
|
|
2705
2991
|
};
|
|
2706
|
-
} catch (
|
|
2992
|
+
} catch (e) {
|
|
2707
2993
|
return {
|
|
2708
2994
|
responseHeaders,
|
|
2709
|
-
value: new
|
|
2995
|
+
value: new APICallError4({
|
|
2710
2996
|
message: response.statusText,
|
|
2711
2997
|
url,
|
|
2712
2998
|
requestBodyValues,
|
|
@@ -2721,7 +3007,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
2721
3007
|
var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
2722
3008
|
const responseHeaders = extractResponseHeaders(response);
|
|
2723
3009
|
if (response.body == null) {
|
|
2724
|
-
throw new
|
|
3010
|
+
throw new EmptyResponseBodyError({});
|
|
2725
3011
|
}
|
|
2726
3012
|
return {
|
|
2727
3013
|
responseHeaders,
|
|
@@ -2739,7 +3025,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
2739
3025
|
});
|
|
2740
3026
|
const responseHeaders = extractResponseHeaders(response);
|
|
2741
3027
|
if (!parsedResult.success) {
|
|
2742
|
-
throw new
|
|
3028
|
+
throw new APICallError4({
|
|
2743
3029
|
message: "Invalid JSON response",
|
|
2744
3030
|
cause: parsedResult.error,
|
|
2745
3031
|
statusCode: response.status,
|
|
@@ -2758,7 +3044,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
2758
3044
|
var createBinaryResponseHandler = () => async ({ response, url, requestBodyValues }) => {
|
|
2759
3045
|
const responseHeaders = extractResponseHeaders(response);
|
|
2760
3046
|
if (!response.body) {
|
|
2761
|
-
throw new
|
|
3047
|
+
throw new APICallError4({
|
|
2762
3048
|
message: "Response body is empty",
|
|
2763
3049
|
url,
|
|
2764
3050
|
requestBodyValues,
|
|
@@ -2774,7 +3060,7 @@ var createBinaryResponseHandler = () => async ({ response, url, requestBodyValue
|
|
|
2774
3060
|
value: new Uint8Array(buffer)
|
|
2775
3061
|
};
|
|
2776
3062
|
} catch (error) {
|
|
2777
|
-
throw new
|
|
3063
|
+
throw new APICallError4({
|
|
2778
3064
|
message: "Failed to read response as array buffer",
|
|
2779
3065
|
url,
|
|
2780
3066
|
requestBodyValues,
|
|
@@ -2790,7 +3076,7 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
|
|
|
2790
3076
|
const responseBody = await response.text();
|
|
2791
3077
|
return {
|
|
2792
3078
|
responseHeaders,
|
|
2793
|
-
value: new
|
|
3079
|
+
value: new APICallError4({
|
|
2794
3080
|
message: response.statusText,
|
|
2795
3081
|
url,
|
|
2796
3082
|
requestBodyValues,
|
|
@@ -2801,6 +3087,185 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
|
|
|
2801
3087
|
};
|
|
2802
3088
|
};
|
|
2803
3089
|
|
|
3090
|
+
// src/is-json-serializable.ts
|
|
3091
|
+
function isJSONSerializable(value) {
|
|
3092
|
+
if (value === null || value === void 0) return true;
|
|
3093
|
+
const type = typeof value;
|
|
3094
|
+
if (type === "string" || type === "number" || type === "boolean") return true;
|
|
3095
|
+
if (type === "function" || type === "symbol" || type === "bigint")
|
|
3096
|
+
return false;
|
|
3097
|
+
if (Array.isArray(value)) {
|
|
3098
|
+
return value.every(isJSONSerializable);
|
|
3099
|
+
}
|
|
3100
|
+
if (Object.getPrototypeOf(value) === Object.prototype) {
|
|
3101
|
+
return Object.values(value).every(
|
|
3102
|
+
isJSONSerializable
|
|
3103
|
+
);
|
|
3104
|
+
}
|
|
3105
|
+
return false;
|
|
3106
|
+
}
|
|
3107
|
+
|
|
3108
|
+
// src/serialize-model-options.ts
|
|
3109
|
+
function serializeModelOptions(options) {
|
|
3110
|
+
const serializableConfig = {};
|
|
3111
|
+
for (const [key, value] of Object.entries(options.config)) {
|
|
3112
|
+
if (key === "headers") {
|
|
3113
|
+
const resolvedHeaders = resolveSync(value);
|
|
3114
|
+
if (isJSONSerializable(resolvedHeaders)) {
|
|
3115
|
+
serializableConfig[key] = resolvedHeaders;
|
|
3116
|
+
}
|
|
3117
|
+
} else if (isJSONSerializable(value)) {
|
|
3118
|
+
serializableConfig[key] = value;
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
return { modelId: options.modelId, config: serializableConfig };
|
|
3122
|
+
}
|
|
3123
|
+
function resolveSync(value) {
|
|
3124
|
+
let next = value;
|
|
3125
|
+
if (typeof value === "function") {
|
|
3126
|
+
next = value();
|
|
3127
|
+
}
|
|
3128
|
+
if (next instanceof Promise) {
|
|
3129
|
+
throw new Error("Promise returned from resolveSync");
|
|
3130
|
+
}
|
|
3131
|
+
return next;
|
|
3132
|
+
}
|
|
3133
|
+
|
|
3134
|
+
// src/streaming-tool-call-tracker.ts
|
|
3135
|
+
import {
|
|
3136
|
+
InvalidResponseDataError
|
|
3137
|
+
} from "@ai-sdk/provider";
|
|
3138
|
+
var StreamingToolCallTracker = class {
|
|
3139
|
+
constructor(controller, options = {}) {
|
|
3140
|
+
this.toolCalls = [];
|
|
3141
|
+
var _a2, _b2;
|
|
3142
|
+
this.controller = controller;
|
|
3143
|
+
this._generateId = (_a2 = options.generateId) != null ? _a2 : generateId;
|
|
3144
|
+
this.typeValidation = (_b2 = options.typeValidation) != null ? _b2 : "none";
|
|
3145
|
+
this.extractMetadata = options.extractMetadata;
|
|
3146
|
+
this.buildToolCallProviderMetadata = options.buildToolCallProviderMetadata;
|
|
3147
|
+
}
|
|
3148
|
+
/**
|
|
3149
|
+
* Process a tool call delta from a streaming response chunk.
|
|
3150
|
+
* Emits tool-input-start, tool-input-delta, tool-input-end, and tool-call
|
|
3151
|
+
* events as appropriate.
|
|
3152
|
+
*/
|
|
3153
|
+
processDelta(toolCallDelta) {
|
|
3154
|
+
var _a2;
|
|
3155
|
+
const index = (_a2 = toolCallDelta.index) != null ? _a2 : this.toolCalls.length;
|
|
3156
|
+
if (this.toolCalls[index] == null) {
|
|
3157
|
+
this.processNewToolCall(index, toolCallDelta);
|
|
3158
|
+
} else {
|
|
3159
|
+
this.processExistingToolCall(index, toolCallDelta);
|
|
3160
|
+
}
|
|
3161
|
+
}
|
|
3162
|
+
/**
|
|
3163
|
+
* Finalize any unfinished tool calls. Should be called during the stream's
|
|
3164
|
+
* flush handler to ensure all tool calls are properly completed.
|
|
3165
|
+
*/
|
|
3166
|
+
flush() {
|
|
3167
|
+
for (const toolCall of this.toolCalls) {
|
|
3168
|
+
if (!toolCall.hasFinished) {
|
|
3169
|
+
this.finishToolCall(toolCall);
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
processNewToolCall(index, toolCallDelta) {
|
|
3174
|
+
var _a2, _b2, _c;
|
|
3175
|
+
if (this.typeValidation === "required") {
|
|
3176
|
+
if (toolCallDelta.type !== "function") {
|
|
3177
|
+
throw new InvalidResponseDataError({
|
|
3178
|
+
data: toolCallDelta,
|
|
3179
|
+
message: `Expected 'function' type.`
|
|
3180
|
+
});
|
|
3181
|
+
}
|
|
3182
|
+
} else if (this.typeValidation === "if-present") {
|
|
3183
|
+
if (toolCallDelta.type != null && toolCallDelta.type !== "function") {
|
|
3184
|
+
throw new InvalidResponseDataError({
|
|
3185
|
+
data: toolCallDelta,
|
|
3186
|
+
message: `Expected 'function' type.`
|
|
3187
|
+
});
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
if (toolCallDelta.id == null) {
|
|
3191
|
+
throw new InvalidResponseDataError({
|
|
3192
|
+
data: toolCallDelta,
|
|
3193
|
+
message: `Expected 'id' to be a string.`
|
|
3194
|
+
});
|
|
3195
|
+
}
|
|
3196
|
+
if (((_a2 = toolCallDelta.function) == null ? void 0 : _a2.name) == null) {
|
|
3197
|
+
throw new InvalidResponseDataError({
|
|
3198
|
+
data: toolCallDelta,
|
|
3199
|
+
message: `Expected 'function.name' to be a string.`
|
|
3200
|
+
});
|
|
3201
|
+
}
|
|
3202
|
+
this.controller.enqueue({
|
|
3203
|
+
type: "tool-input-start",
|
|
3204
|
+
id: toolCallDelta.id,
|
|
3205
|
+
toolName: toolCallDelta.function.name
|
|
3206
|
+
});
|
|
3207
|
+
const metadata = (_b2 = this.extractMetadata) == null ? void 0 : _b2.call(this, toolCallDelta);
|
|
3208
|
+
this.toolCalls[index] = {
|
|
3209
|
+
id: toolCallDelta.id,
|
|
3210
|
+
type: "function",
|
|
3211
|
+
function: {
|
|
3212
|
+
name: toolCallDelta.function.name,
|
|
3213
|
+
arguments: (_c = toolCallDelta.function.arguments) != null ? _c : ""
|
|
3214
|
+
},
|
|
3215
|
+
hasFinished: false,
|
|
3216
|
+
metadata
|
|
3217
|
+
};
|
|
3218
|
+
const toolCall = this.toolCalls[index];
|
|
3219
|
+
if (toolCall.function.arguments.length > 0) {
|
|
3220
|
+
this.controller.enqueue({
|
|
3221
|
+
type: "tool-input-delta",
|
|
3222
|
+
id: toolCall.id,
|
|
3223
|
+
delta: toolCall.function.arguments
|
|
3224
|
+
});
|
|
3225
|
+
}
|
|
3226
|
+
if (isParsableJson(toolCall.function.arguments)) {
|
|
3227
|
+
this.finishToolCall(toolCall);
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
processExistingToolCall(index, toolCallDelta) {
|
|
3231
|
+
var _a2;
|
|
3232
|
+
const toolCall = this.toolCalls[index];
|
|
3233
|
+
if (toolCall.hasFinished) {
|
|
3234
|
+
return;
|
|
3235
|
+
}
|
|
3236
|
+
if (((_a2 = toolCallDelta.function) == null ? void 0 : _a2.arguments) != null) {
|
|
3237
|
+
toolCall.function.arguments += toolCallDelta.function.arguments;
|
|
3238
|
+
this.controller.enqueue({
|
|
3239
|
+
type: "tool-input-delta",
|
|
3240
|
+
id: toolCall.id,
|
|
3241
|
+
delta: toolCallDelta.function.arguments
|
|
3242
|
+
});
|
|
3243
|
+
}
|
|
3244
|
+
if (isParsableJson(toolCall.function.arguments)) {
|
|
3245
|
+
this.finishToolCall(toolCall);
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3248
|
+
finishToolCall(toolCall) {
|
|
3249
|
+
var _a2, _b2;
|
|
3250
|
+
this.controller.enqueue({
|
|
3251
|
+
type: "tool-input-end",
|
|
3252
|
+
id: toolCall.id
|
|
3253
|
+
});
|
|
3254
|
+
const providerMetadata = (_a2 = this.buildToolCallProviderMetadata) == null ? void 0 : _a2.call(
|
|
3255
|
+
this,
|
|
3256
|
+
toolCall.metadata
|
|
3257
|
+
);
|
|
3258
|
+
this.controller.enqueue({
|
|
3259
|
+
type: "tool-call",
|
|
3260
|
+
toolCallId: (_b2 = toolCall.id) != null ? _b2 : this._generateId(),
|
|
3261
|
+
toolName: toolCall.function.name,
|
|
3262
|
+
input: toolCall.function.arguments,
|
|
3263
|
+
...providerMetadata ? { providerMetadata } : {}
|
|
3264
|
+
});
|
|
3265
|
+
toolCall.hasFinished = true;
|
|
3266
|
+
}
|
|
3267
|
+
};
|
|
3268
|
+
|
|
2804
3269
|
// src/strip-file-extension.ts
|
|
2805
3270
|
function stripFileExtension(filename) {
|
|
2806
3271
|
const firstDotIndex = filename.indexOf(".");
|
|
@@ -2819,11 +3284,11 @@ function isAsyncIterable(obj) {
|
|
|
2819
3284
|
|
|
2820
3285
|
// src/types/execute-tool.ts
|
|
2821
3286
|
async function* executeTool({
|
|
2822
|
-
|
|
3287
|
+
tool: tool2,
|
|
2823
3288
|
input,
|
|
2824
3289
|
options
|
|
2825
3290
|
}) {
|
|
2826
|
-
const result = execute(input, options);
|
|
3291
|
+
const result = tool2.execute(input, options);
|
|
2827
3292
|
if (isAsyncIterable(result)) {
|
|
2828
3293
|
let lastOutput;
|
|
2829
3294
|
for await (const output of result) {
|
|
@@ -2836,20 +3301,32 @@ async function* executeTool({
|
|
|
2836
3301
|
}
|
|
2837
3302
|
}
|
|
2838
3303
|
|
|
3304
|
+
// src/types/executable-tool.ts
|
|
3305
|
+
function isExecutableTool(tool2) {
|
|
3306
|
+
return tool2 != null && typeof tool2.execute === "function";
|
|
3307
|
+
}
|
|
3308
|
+
|
|
2839
3309
|
// src/index.ts
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
3310
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
|
|
3311
|
+
import {
|
|
3312
|
+
EventSourceParserStream as EventSourceParserStream2
|
|
3313
|
+
} from "eventsource-parser/stream";
|
|
3314
|
+
export {
|
|
2843
3315
|
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
2844
3316
|
DelayedPromise,
|
|
2845
3317
|
DownloadError,
|
|
2846
|
-
EventSourceParserStream,
|
|
3318
|
+
EventSourceParserStream2 as EventSourceParserStream,
|
|
3319
|
+
StreamingToolCallTracker,
|
|
2847
3320
|
VERSION,
|
|
3321
|
+
WORKFLOW_DESERIALIZE,
|
|
3322
|
+
WORKFLOW_SERIALIZE,
|
|
3323
|
+
asArray,
|
|
2848
3324
|
asSchema,
|
|
2849
3325
|
combineHeaders,
|
|
2850
3326
|
convertAsyncIteratorToReadableStream,
|
|
2851
3327
|
convertBase64ToUint8Array,
|
|
2852
3328
|
convertImageModelFileToDataUri,
|
|
3329
|
+
convertInlineFileDataToUint8Array,
|
|
2853
3330
|
convertToBase64,
|
|
2854
3331
|
convertToFormData,
|
|
2855
3332
|
convertUint8ArrayToBase64,
|
|
@@ -2858,24 +3335,32 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2858
3335
|
createIdGenerator,
|
|
2859
3336
|
createJsonErrorResponseHandler,
|
|
2860
3337
|
createJsonResponseHandler,
|
|
2861
|
-
|
|
2862
|
-
|
|
3338
|
+
createProviderDefinedToolFactory,
|
|
3339
|
+
createProviderDefinedToolFactoryWithOutputSchema,
|
|
3340
|
+
createProviderExecutedToolFactory,
|
|
2863
3341
|
createStatusCodeErrorResponseHandler,
|
|
2864
3342
|
createToolNameMapping,
|
|
2865
3343
|
delay,
|
|
3344
|
+
detectMediaType,
|
|
2866
3345
|
downloadBlob,
|
|
2867
3346
|
dynamicTool,
|
|
2868
3347
|
executeTool,
|
|
2869
3348
|
extractResponseHeaders,
|
|
3349
|
+
filterNullable,
|
|
2870
3350
|
generateId,
|
|
2871
3351
|
getErrorMessage,
|
|
2872
3352
|
getFromApi,
|
|
2873
3353
|
getRuntimeEnvironmentUserAgent,
|
|
3354
|
+
getTopLevelMediaType,
|
|
2874
3355
|
injectJsonInstructionIntoMessages,
|
|
2875
3356
|
isAbortError,
|
|
3357
|
+
isBuffer,
|
|
2876
3358
|
isCustomReasoning,
|
|
3359
|
+
isExecutableTool,
|
|
3360
|
+
isFullMediaType,
|
|
2877
3361
|
isNonNullable,
|
|
2878
3362
|
isParsableJson,
|
|
3363
|
+
isProviderReference,
|
|
2879
3364
|
isUrlSupported,
|
|
2880
3365
|
jsonSchema,
|
|
2881
3366
|
lazySchema,
|
|
@@ -2895,8 +3380,11 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2895
3380
|
readResponseWithSizeLimit,
|
|
2896
3381
|
removeUndefinedEntries,
|
|
2897
3382
|
resolve,
|
|
3383
|
+
resolveFullMediaType,
|
|
3384
|
+
resolveProviderReference,
|
|
2898
3385
|
safeParseJSON,
|
|
2899
3386
|
safeValidateTypes,
|
|
3387
|
+
serializeModelOptions,
|
|
2900
3388
|
stripFileExtension,
|
|
2901
3389
|
tool,
|
|
2902
3390
|
validateDownloadUrl,
|
|
@@ -2904,5 +3392,5 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2904
3392
|
withUserAgentSuffix,
|
|
2905
3393
|
withoutTrailingSlash,
|
|
2906
3394
|
zodSchema
|
|
2907
|
-
}
|
|
3395
|
+
};
|
|
2908
3396
|
//# sourceMappingURL=index.js.map
|