@ai-sdk/provider-utils 5.0.0-beta.4 → 5.0.0-beta.49
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 +373 -11
- package/dist/index.d.ts +1460 -553
- package/dist/index.js +1044 -361
- 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 +16 -16
- package/src/add-additional-properties-to-json-schema.ts +1 -1
- package/src/as-array.ts +12 -0
- package/src/cancel-response-body.ts +19 -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/download-blob.ts +8 -9
- package/src/extract-lines.ts +31 -0
- package/src/fetch-with-validated-redirects.ts +87 -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 +47 -12
- package/src/inject-json-instruction.ts +1 -1
- package/src/is-browser-runtime.ts +13 -0
- 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-same-origin.ts +19 -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 +108 -0
- 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-defined-tool-factory.ts +129 -0
- package/src/provider-executed-tool-factory.ts +69 -0
- package/src/read-response-with-size-limit.ts +4 -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 +11 -4
- 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 +10 -8
- 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 +5 -3
- package/src/types/content-part.ts +158 -19
- package/src/types/context.ts +4 -0
- package/src/types/executable-tool.ts +17 -0
- package/src/types/execute-tool.ts +29 -9
- package/src/types/file-data.ts +48 -0
- package/src/types/index.ts +29 -11
- package/src/types/infer-tool-context.ts +41 -0
- package/src/types/infer-tool-input.ts +7 -0
- package/src/types/infer-tool-output.ts +7 -0
- package/src/types/infer-tool-set-context.ts +44 -0
- 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/sandbox.ts +217 -0
- package/src/types/system-model-message.ts +1 -1
- package/src/types/tool-approval-request.ts +13 -0
- package/src/types/tool-execute-function.ts +56 -0
- package/src/types/tool-model-message.ts +3 -3
- package/src/types/tool-needs-approval-function.ts +39 -0
- package/src/types/tool-set.ts +22 -0
- package/src/types/tool.ts +278 -225
- package/src/types/user-model-message.ts +2 -2
- package/src/validate-download-url.ts +120 -33
- package/src/validate-types.ts +5 -3
- package/dist/index.d.mts +0 -1455
- package/dist/index.mjs +0 -2754
- 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/provider-tool-factory.ts +0 -125
package/dist/index.js
CHANGED
|
@@ -1,98 +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
|
-
isNonNullable: () => isNonNullable,
|
|
67
|
-
isParsableJson: () => isParsableJson,
|
|
68
|
-
isUrlSupported: () => isUrlSupported,
|
|
69
|
-
jsonSchema: () => jsonSchema,
|
|
70
|
-
lazySchema: () => lazySchema,
|
|
71
|
-
loadApiKey: () => loadApiKey,
|
|
72
|
-
loadOptionalSetting: () => loadOptionalSetting,
|
|
73
|
-
loadSetting: () => loadSetting,
|
|
74
|
-
mediaTypeToExtension: () => mediaTypeToExtension,
|
|
75
|
-
normalizeHeaders: () => normalizeHeaders,
|
|
76
|
-
parseJSON: () => parseJSON,
|
|
77
|
-
parseJsonEventStream: () => parseJsonEventStream,
|
|
78
|
-
parseProviderOptions: () => parseProviderOptions,
|
|
79
|
-
postFormDataToApi: () => postFormDataToApi,
|
|
80
|
-
postJsonToApi: () => postJsonToApi,
|
|
81
|
-
postToApi: () => postToApi,
|
|
82
|
-
readResponseWithSizeLimit: () => readResponseWithSizeLimit,
|
|
83
|
-
removeUndefinedEntries: () => removeUndefinedEntries,
|
|
84
|
-
resolve: () => resolve,
|
|
85
|
-
safeParseJSON: () => safeParseJSON,
|
|
86
|
-
safeValidateTypes: () => safeValidateTypes,
|
|
87
|
-
stripFileExtension: () => stripFileExtension,
|
|
88
|
-
tool: () => tool,
|
|
89
|
-
validateDownloadUrl: () => validateDownloadUrl,
|
|
90
|
-
validateTypes: () => validateTypes,
|
|
91
|
-
withUserAgentSuffix: () => withUserAgentSuffix,
|
|
92
|
-
withoutTrailingSlash: () => withoutTrailingSlash,
|
|
93
|
-
zodSchema: () => zodSchema
|
|
94
|
-
});
|
|
95
|
-
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
|
+
}
|
|
96
5
|
|
|
97
6
|
// src/combine-headers.ts
|
|
98
7
|
function combineHeaders(...headers) {
|
|
@@ -143,6 +52,68 @@ function convertAsyncIteratorToReadableStream(iterator) {
|
|
|
143
52
|
});
|
|
144
53
|
}
|
|
145
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
|
+
|
|
146
117
|
// src/create-tool-name-mapping.ts
|
|
147
118
|
function createToolNameMapping({
|
|
148
119
|
tools = [],
|
|
@@ -246,66 +217,294 @@ var DelayedPromise = class {
|
|
|
246
217
|
}
|
|
247
218
|
};
|
|
248
219
|
|
|
249
|
-
// src/
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
//
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
+
]
|
|
265
302
|
}
|
|
266
|
-
|
|
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 });
|
|
267
478
|
}
|
|
268
|
-
function
|
|
269
|
-
|
|
479
|
+
function getTopLevelMediaType(mediaType) {
|
|
480
|
+
const slashIndex = mediaType.indexOf("/");
|
|
481
|
+
return slashIndex === -1 ? mediaType : mediaType.substring(0, slashIndex);
|
|
270
482
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
483
|
+
function isFullMediaType(mediaType) {
|
|
484
|
+
const slashIndex = mediaType.indexOf("/");
|
|
485
|
+
if (slashIndex === -1) {
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
const subtype = mediaType.substring(slashIndex + 1);
|
|
489
|
+
return subtype.length > 0 && subtype !== "*";
|
|
276
490
|
}
|
|
277
491
|
|
|
278
|
-
// src/
|
|
279
|
-
function
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
continue;
|
|
285
|
-
}
|
|
286
|
-
if (Array.isArray(value)) {
|
|
287
|
-
if (value.length === 1) {
|
|
288
|
-
formData.append(key, value[0]);
|
|
289
|
-
continue;
|
|
290
|
-
}
|
|
291
|
-
const arrayKey = useArrayBrackets ? `${key}[]` : key;
|
|
292
|
-
for (const item of value) {
|
|
293
|
-
formData.append(arrayKey, item);
|
|
294
|
-
}
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
formData.append(key, value);
|
|
492
|
+
// src/cancel-response-body.ts
|
|
493
|
+
async function cancelResponseBody(response) {
|
|
494
|
+
var _a2;
|
|
495
|
+
try {
|
|
496
|
+
await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
|
|
497
|
+
} catch (e) {
|
|
298
498
|
}
|
|
299
|
-
return formData;
|
|
300
499
|
}
|
|
301
500
|
|
|
302
501
|
// src/download-error.ts
|
|
303
|
-
|
|
502
|
+
import { AISDKError } from "@ai-sdk/provider";
|
|
304
503
|
var name = "AI_DownloadError";
|
|
305
504
|
var marker = `vercel.ai.error.${name}`;
|
|
306
505
|
var symbol = Symbol.for(marker);
|
|
307
506
|
var _a, _b;
|
|
308
|
-
var DownloadError = class extends (_b =
|
|
507
|
+
var DownloadError = class extends (_b = AISDKError, _a = symbol, _b) {
|
|
309
508
|
constructor({
|
|
310
509
|
url,
|
|
311
510
|
statusCode,
|
|
@@ -320,63 +519,13 @@ var DownloadError = class extends (_b = import_provider.AISDKError, _a = symbol,
|
|
|
320
519
|
this.statusText = statusText;
|
|
321
520
|
}
|
|
322
521
|
static isInstance(error) {
|
|
323
|
-
return
|
|
522
|
+
return AISDKError.hasMarker(error, marker);
|
|
324
523
|
}
|
|
325
524
|
};
|
|
326
525
|
|
|
327
|
-
// src/
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
response,
|
|
331
|
-
url,
|
|
332
|
-
maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE
|
|
333
|
-
}) {
|
|
334
|
-
const contentLength = response.headers.get("content-length");
|
|
335
|
-
if (contentLength != null) {
|
|
336
|
-
const length = parseInt(contentLength, 10);
|
|
337
|
-
if (!isNaN(length) && length > maxBytes) {
|
|
338
|
-
throw new DownloadError({
|
|
339
|
-
url,
|
|
340
|
-
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
const body = response.body;
|
|
345
|
-
if (body == null) {
|
|
346
|
-
return new Uint8Array(0);
|
|
347
|
-
}
|
|
348
|
-
const reader = body.getReader();
|
|
349
|
-
const chunks = [];
|
|
350
|
-
let totalBytes = 0;
|
|
351
|
-
try {
|
|
352
|
-
while (true) {
|
|
353
|
-
const { done, value } = await reader.read();
|
|
354
|
-
if (done) {
|
|
355
|
-
break;
|
|
356
|
-
}
|
|
357
|
-
totalBytes += value.length;
|
|
358
|
-
if (totalBytes > maxBytes) {
|
|
359
|
-
throw new DownloadError({
|
|
360
|
-
url,
|
|
361
|
-
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
chunks.push(value);
|
|
365
|
-
}
|
|
366
|
-
} finally {
|
|
367
|
-
try {
|
|
368
|
-
await reader.cancel();
|
|
369
|
-
} finally {
|
|
370
|
-
reader.releaseLock();
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
const result = new Uint8Array(totalBytes);
|
|
374
|
-
let offset = 0;
|
|
375
|
-
for (const chunk of chunks) {
|
|
376
|
-
result.set(chunk, offset);
|
|
377
|
-
offset += chunk.length;
|
|
378
|
-
}
|
|
379
|
-
return result;
|
|
526
|
+
// src/is-browser-runtime.ts
|
|
527
|
+
function isBrowserRuntime(globalThisAny = globalThis) {
|
|
528
|
+
return globalThisAny.window != null;
|
|
380
529
|
}
|
|
381
530
|
|
|
382
531
|
// src/validate-download-url.ts
|
|
@@ -390,13 +539,16 @@ function validateDownloadUrl(url) {
|
|
|
390
539
|
message: `Invalid URL: ${url}`
|
|
391
540
|
});
|
|
392
541
|
}
|
|
542
|
+
if (parsed.protocol === "data:") {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
393
545
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
394
546
|
throw new DownloadError({
|
|
395
547
|
url,
|
|
396
|
-
message: `URL scheme must be http or
|
|
548
|
+
message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
|
|
397
549
|
});
|
|
398
550
|
}
|
|
399
|
-
const hostname = parsed.hostname;
|
|
551
|
+
const hostname = parsed.hostname.toLowerCase().replace(/\.+$/, "");
|
|
400
552
|
if (!hostname) {
|
|
401
553
|
throw new DownloadError({
|
|
402
554
|
url,
|
|
@@ -439,54 +591,190 @@ function isIPv4(hostname) {
|
|
|
439
591
|
}
|
|
440
592
|
function isPrivateIPv4(ip) {
|
|
441
593
|
const parts = ip.split(".").map(Number);
|
|
442
|
-
const [a, b] = parts;
|
|
594
|
+
const [a, b, c] = parts;
|
|
443
595
|
if (a === 0) return true;
|
|
444
596
|
if (a === 10) return true;
|
|
597
|
+
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
445
598
|
if (a === 127) return true;
|
|
446
599
|
if (a === 169 && b === 254) return true;
|
|
447
600
|
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
601
|
+
if (a === 192 && b === 0 && c === 0) return true;
|
|
448
602
|
if (a === 192 && b === 168) return true;
|
|
603
|
+
if (a === 198 && (b === 18 || b === 19)) return true;
|
|
604
|
+
if (a >= 240) return true;
|
|
449
605
|
return false;
|
|
450
606
|
}
|
|
451
|
-
function
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
if (
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
|
|
607
|
+
function parseIPv6(ip) {
|
|
608
|
+
let address = ip.toLowerCase();
|
|
609
|
+
const zoneIndex = address.indexOf("%");
|
|
610
|
+
if (zoneIndex !== -1) {
|
|
611
|
+
address = address.slice(0, zoneIndex);
|
|
612
|
+
}
|
|
613
|
+
const halves = address.split("::");
|
|
614
|
+
if (halves.length > 2) return null;
|
|
615
|
+
const toGroups = (segment) => {
|
|
616
|
+
if (segment === "") return [];
|
|
617
|
+
const groups = [];
|
|
618
|
+
const parts = segment.split(":");
|
|
619
|
+
for (let i = 0; i < parts.length; i++) {
|
|
620
|
+
const part = parts[i];
|
|
621
|
+
if (part.includes(".")) {
|
|
622
|
+
if (i !== parts.length - 1 || !isIPv4(part)) return null;
|
|
623
|
+
const [a, b, c, d] = part.split(".").map(Number);
|
|
624
|
+
groups.push(a << 8 | b, c << 8 | d);
|
|
625
|
+
continue;
|
|
470
626
|
}
|
|
627
|
+
if (!/^[0-9a-f]{1,4}$/.test(part)) return null;
|
|
628
|
+
groups.push(parseInt(part, 16));
|
|
471
629
|
}
|
|
630
|
+
return groups;
|
|
631
|
+
};
|
|
632
|
+
const head = toGroups(halves[0]);
|
|
633
|
+
if (head === null) return null;
|
|
634
|
+
if (halves.length === 2) {
|
|
635
|
+
const tail = toGroups(halves[1]);
|
|
636
|
+
if (tail === null) return null;
|
|
637
|
+
const fill = 8 - head.length - tail.length;
|
|
638
|
+
if (fill < 0) return null;
|
|
639
|
+
return [...head, ...new Array(fill).fill(0), ...tail];
|
|
640
|
+
}
|
|
641
|
+
return head.length === 8 ? head : null;
|
|
642
|
+
}
|
|
643
|
+
function isPrivateIPv6(ip) {
|
|
644
|
+
const groups = parseIPv6(ip);
|
|
645
|
+
if (groups === null) return true;
|
|
646
|
+
const topZero = (count) => groups.slice(0, count).every((group) => group === 0);
|
|
647
|
+
if (topZero(7) && (groups[7] === 0 || groups[7] === 1)) return true;
|
|
648
|
+
if ((groups[0] & 65024) === 64512) return true;
|
|
649
|
+
if ((groups[0] & 65472) === 65152) return true;
|
|
650
|
+
if ((groups[0] & 65472) === 65216) return true;
|
|
651
|
+
if ((groups[0] & 65280) === 65280) return true;
|
|
652
|
+
const embedsIPv4 = (
|
|
653
|
+
// ::/96 — IPv4-compatible (deprecated)
|
|
654
|
+
topZero(6) || // ::ffff:0:0/96 — IPv4-mapped (ffff in group 5)
|
|
655
|
+
topZero(5) && groups[5] === 65535 || // ::ffff:0:0/96 — IPv4-translated form (ffff in group 4, group 5 zero)
|
|
656
|
+
topZero(4) && groups[4] === 65535 && groups[5] === 0 || // 64:ff9b::/96 — NAT64 well-known prefix
|
|
657
|
+
groups[0] === 100 && groups[1] === 65435 && groups[2] === 0 && groups[3] === 0 && groups[4] === 0 && groups[5] === 0 || // 64:ff9b:1::/48 — NAT64 local-use prefix
|
|
658
|
+
groups[0] === 100 && groups[1] === 65435 && groups[2] === 1
|
|
659
|
+
);
|
|
660
|
+
if (embedsIPv4) {
|
|
661
|
+
const a = groups[6] >> 8 & 255;
|
|
662
|
+
const b = groups[6] & 255;
|
|
663
|
+
const c = groups[7] >> 8 & 255;
|
|
664
|
+
const d = groups[7] & 255;
|
|
665
|
+
return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
|
|
472
666
|
}
|
|
473
|
-
if (normalized.startsWith("fc") || normalized.startsWith("fd")) return true;
|
|
474
|
-
if (normalized.startsWith("fe80")) return true;
|
|
475
667
|
return false;
|
|
476
668
|
}
|
|
477
669
|
|
|
670
|
+
// src/fetch-with-validated-redirects.ts
|
|
671
|
+
var MAX_DOWNLOAD_REDIRECTS = 10;
|
|
672
|
+
async function fetchWithValidatedRedirects({
|
|
673
|
+
url,
|
|
674
|
+
headers,
|
|
675
|
+
abortSignal,
|
|
676
|
+
maxRedirects = MAX_DOWNLOAD_REDIRECTS
|
|
677
|
+
}) {
|
|
678
|
+
const baseInit = { signal: abortSignal };
|
|
679
|
+
if (headers !== void 0) {
|
|
680
|
+
baseInit.headers = headers;
|
|
681
|
+
}
|
|
682
|
+
let currentUrl = url;
|
|
683
|
+
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
684
|
+
validateDownloadUrl(currentUrl);
|
|
685
|
+
const response = await fetch(currentUrl, {
|
|
686
|
+
...baseInit,
|
|
687
|
+
redirect: "manual"
|
|
688
|
+
});
|
|
689
|
+
if (response.type === "opaqueredirect") {
|
|
690
|
+
if (!isBrowserRuntime()) {
|
|
691
|
+
throw new DownloadError({
|
|
692
|
+
url,
|
|
693
|
+
message: `Redirect from ${currentUrl} could not be validated and was blocked`
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
return await fetch(currentUrl, { ...baseInit, redirect: "follow" });
|
|
697
|
+
}
|
|
698
|
+
const location = response.headers.get("location");
|
|
699
|
+
if (response.status >= 300 && response.status < 400 && location) {
|
|
700
|
+
await cancelResponseBody(response);
|
|
701
|
+
currentUrl = new URL(location, currentUrl).toString();
|
|
702
|
+
continue;
|
|
703
|
+
}
|
|
704
|
+
return response;
|
|
705
|
+
}
|
|
706
|
+
throw new DownloadError({
|
|
707
|
+
url,
|
|
708
|
+
message: `Too many redirects (max ${maxRedirects})`
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
// src/read-response-with-size-limit.ts
|
|
713
|
+
var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
|
|
714
|
+
async function readResponseWithSizeLimit({
|
|
715
|
+
response,
|
|
716
|
+
url,
|
|
717
|
+
maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE
|
|
718
|
+
}) {
|
|
719
|
+
const contentLength = response.headers.get("content-length");
|
|
720
|
+
if (contentLength != null) {
|
|
721
|
+
const length = parseInt(contentLength, 10);
|
|
722
|
+
if (!isNaN(length) && length > maxBytes) {
|
|
723
|
+
await cancelResponseBody(response);
|
|
724
|
+
throw new DownloadError({
|
|
725
|
+
url,
|
|
726
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
const body = response.body;
|
|
731
|
+
if (body == null) {
|
|
732
|
+
return new Uint8Array(0);
|
|
733
|
+
}
|
|
734
|
+
const reader = body.getReader();
|
|
735
|
+
const chunks = [];
|
|
736
|
+
let totalBytes = 0;
|
|
737
|
+
try {
|
|
738
|
+
while (true) {
|
|
739
|
+
const { done, value } = await reader.read();
|
|
740
|
+
if (done) {
|
|
741
|
+
break;
|
|
742
|
+
}
|
|
743
|
+
totalBytes += value.length;
|
|
744
|
+
if (totalBytes > maxBytes) {
|
|
745
|
+
throw new DownloadError({
|
|
746
|
+
url,
|
|
747
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
chunks.push(value);
|
|
751
|
+
}
|
|
752
|
+
} finally {
|
|
753
|
+
try {
|
|
754
|
+
await reader.cancel();
|
|
755
|
+
} finally {
|
|
756
|
+
reader.releaseLock();
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
const result = new Uint8Array(totalBytes);
|
|
760
|
+
let offset = 0;
|
|
761
|
+
for (const chunk of chunks) {
|
|
762
|
+
result.set(chunk, offset);
|
|
763
|
+
offset += chunk.length;
|
|
764
|
+
}
|
|
765
|
+
return result;
|
|
766
|
+
}
|
|
767
|
+
|
|
478
768
|
// src/download-blob.ts
|
|
479
769
|
async function downloadBlob(url, options) {
|
|
480
770
|
var _a2, _b2;
|
|
481
|
-
validateDownloadUrl(url);
|
|
482
771
|
try {
|
|
483
|
-
const response = await
|
|
484
|
-
|
|
772
|
+
const response = await fetchWithValidatedRedirects({
|
|
773
|
+
url,
|
|
774
|
+
abortSignal: options == null ? void 0 : options.abortSignal
|
|
485
775
|
});
|
|
486
|
-
if (response.redirected) {
|
|
487
|
-
validateDownloadUrl(response.url);
|
|
488
|
-
}
|
|
489
776
|
if (!response.ok) {
|
|
777
|
+
await cancelResponseBody(response);
|
|
490
778
|
throw new DownloadError({
|
|
491
779
|
url,
|
|
492
780
|
statusCode: response.status,
|
|
@@ -508,8 +796,32 @@ async function downloadBlob(url, options) {
|
|
|
508
796
|
}
|
|
509
797
|
}
|
|
510
798
|
|
|
799
|
+
// src/extract-lines.ts
|
|
800
|
+
function extractLines({
|
|
801
|
+
text,
|
|
802
|
+
startLine,
|
|
803
|
+
endLine
|
|
804
|
+
}) {
|
|
805
|
+
if (startLine == null && endLine == null) return text;
|
|
806
|
+
const lineEnding = text.includes("\r\n") ? "\r\n" : text.includes("\n") ? "\n" : text.includes("\r") ? "\r" : "\n";
|
|
807
|
+
const lines = text.split(lineEnding);
|
|
808
|
+
const start = Math.max(1, startLine != null ? startLine : 1) - 1;
|
|
809
|
+
const end = Math.min(lines.length, endLine != null ? endLine : lines.length);
|
|
810
|
+
return lines.slice(start, end).join(lineEnding);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// src/extract-response-headers.ts
|
|
814
|
+
function extractResponseHeaders(response) {
|
|
815
|
+
return Object.fromEntries([...response.headers]);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// src/filter-nullable.ts
|
|
819
|
+
function filterNullable(...values) {
|
|
820
|
+
return values.filter((value) => value != null);
|
|
821
|
+
}
|
|
822
|
+
|
|
511
823
|
// src/generate-id.ts
|
|
512
|
-
|
|
824
|
+
import { InvalidArgumentError } from "@ai-sdk/provider";
|
|
513
825
|
var createIdGenerator = ({
|
|
514
826
|
prefix,
|
|
515
827
|
size = 16,
|
|
@@ -528,7 +840,7 @@ var createIdGenerator = ({
|
|
|
528
840
|
return generator;
|
|
529
841
|
}
|
|
530
842
|
if (alphabet.includes(separator)) {
|
|
531
|
-
throw new
|
|
843
|
+
throw new InvalidArgumentError({
|
|
532
844
|
argument: "separator",
|
|
533
845
|
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
534
846
|
});
|
|
@@ -538,24 +850,13 @@ var createIdGenerator = ({
|
|
|
538
850
|
var generateId = createIdGenerator();
|
|
539
851
|
|
|
540
852
|
// src/get-error-message.ts
|
|
541
|
-
|
|
542
|
-
if (error == null) {
|
|
543
|
-
return "unknown error";
|
|
544
|
-
}
|
|
545
|
-
if (typeof error === "string") {
|
|
546
|
-
return error;
|
|
547
|
-
}
|
|
548
|
-
if (error instanceof Error) {
|
|
549
|
-
return error.message;
|
|
550
|
-
}
|
|
551
|
-
return JSON.stringify(error);
|
|
552
|
-
}
|
|
853
|
+
import { getErrorMessage } from "@ai-sdk/provider";
|
|
553
854
|
|
|
554
855
|
// src/get-from-api.ts
|
|
555
|
-
|
|
856
|
+
import { APICallError as APICallError2 } from "@ai-sdk/provider";
|
|
556
857
|
|
|
557
858
|
// src/handle-fetch-error.ts
|
|
558
|
-
|
|
859
|
+
import { APICallError } from "@ai-sdk/provider";
|
|
559
860
|
|
|
560
861
|
// src/is-abort-error.ts
|
|
561
862
|
function isAbortError(error) {
|
|
@@ -595,7 +896,7 @@ function handleFetchError({
|
|
|
595
896
|
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES.includes(error.message.toLowerCase())) {
|
|
596
897
|
const cause = error.cause;
|
|
597
898
|
if (cause != null) {
|
|
598
|
-
return new
|
|
899
|
+
return new APICallError({
|
|
599
900
|
message: `Cannot connect to API: ${cause.message}`,
|
|
600
901
|
cause,
|
|
601
902
|
url,
|
|
@@ -606,7 +907,7 @@ function handleFetchError({
|
|
|
606
907
|
}
|
|
607
908
|
}
|
|
608
909
|
if (isBunNetworkError(error)) {
|
|
609
|
-
return new
|
|
910
|
+
return new APICallError({
|
|
610
911
|
message: `Cannot connect to API: ${error.message}`,
|
|
611
912
|
cause: error,
|
|
612
913
|
url,
|
|
@@ -670,7 +971,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
670
971
|
}
|
|
671
972
|
|
|
672
973
|
// src/version.ts
|
|
673
|
-
var VERSION = true ? "5.0.0-beta.
|
|
974
|
+
var VERSION = true ? "5.0.0-beta.49" : "0.0.0-test";
|
|
674
975
|
|
|
675
976
|
// src/get-from-api.ts
|
|
676
977
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -702,10 +1003,10 @@ var getFromApi = async ({
|
|
|
702
1003
|
requestBodyValues: {}
|
|
703
1004
|
});
|
|
704
1005
|
} catch (error) {
|
|
705
|
-
if (isAbortError(error) ||
|
|
1006
|
+
if (isAbortError(error) || APICallError2.isInstance(error)) {
|
|
706
1007
|
throw error;
|
|
707
1008
|
}
|
|
708
|
-
throw new
|
|
1009
|
+
throw new APICallError2({
|
|
709
1010
|
message: "Failed to process error response",
|
|
710
1011
|
cause: error,
|
|
711
1012
|
statusCode: response.status,
|
|
@@ -724,11 +1025,11 @@ var getFromApi = async ({
|
|
|
724
1025
|
});
|
|
725
1026
|
} catch (error) {
|
|
726
1027
|
if (error instanceof Error) {
|
|
727
|
-
if (isAbortError(error) ||
|
|
1028
|
+
if (isAbortError(error) || APICallError2.isInstance(error)) {
|
|
728
1029
|
throw error;
|
|
729
1030
|
}
|
|
730
1031
|
}
|
|
731
|
-
throw new
|
|
1032
|
+
throw new APICallError2({
|
|
732
1033
|
message: "Failed to process successful response",
|
|
733
1034
|
cause: error,
|
|
734
1035
|
statusCode: response.status,
|
|
@@ -781,11 +1082,31 @@ function injectJsonInstructionIntoMessages({
|
|
|
781
1082
|
];
|
|
782
1083
|
}
|
|
783
1084
|
|
|
1085
|
+
// src/is-buffer.ts
|
|
1086
|
+
function isBuffer(value) {
|
|
1087
|
+
var _a2, _b2;
|
|
1088
|
+
return (_b2 = (_a2 = globalThis.Buffer) == null ? void 0 : _a2.isBuffer(value)) != null ? _b2 : false;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
// src/is-same-origin.ts
|
|
1092
|
+
function isSameOrigin(url, baseUrl) {
|
|
1093
|
+
try {
|
|
1094
|
+
return new URL(url).origin === new URL(baseUrl).origin;
|
|
1095
|
+
} catch (e) {
|
|
1096
|
+
return false;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
|
|
784
1100
|
// src/is-non-nullable.ts
|
|
785
1101
|
function isNonNullable(value) {
|
|
786
1102
|
return value != null;
|
|
787
1103
|
}
|
|
788
1104
|
|
|
1105
|
+
// src/is-provider-reference.ts
|
|
1106
|
+
function isProviderReference(data) {
|
|
1107
|
+
return typeof data === "object" && data !== null && !(data instanceof Uint8Array) && !(data instanceof URL) && !(data instanceof ArrayBuffer) && !isBuffer(data) && !("type" in data);
|
|
1108
|
+
}
|
|
1109
|
+
|
|
789
1110
|
// src/is-url-supported.ts
|
|
790
1111
|
function isUrlSupported({
|
|
791
1112
|
mediaType,
|
|
@@ -794,14 +1115,23 @@ function isUrlSupported({
|
|
|
794
1115
|
}) {
|
|
795
1116
|
url = url.toLowerCase();
|
|
796
1117
|
mediaType = mediaType.toLowerCase();
|
|
1118
|
+
const isTopLevelOnly = !mediaType.includes("/");
|
|
797
1119
|
return Object.entries(supportedUrls).map(([key, value]) => {
|
|
798
1120
|
const mediaType2 = key.toLowerCase();
|
|
799
1121
|
return mediaType2 === "*" || mediaType2 === "*/*" ? { mediaTypePrefix: "", regexes: value } : { mediaTypePrefix: mediaType2.replace(/\*/, ""), regexes: value };
|
|
800
|
-
}).filter(({ mediaTypePrefix }) =>
|
|
1122
|
+
}).filter(({ mediaTypePrefix }) => {
|
|
1123
|
+
if (mediaTypePrefix === "") {
|
|
1124
|
+
return true;
|
|
1125
|
+
}
|
|
1126
|
+
if (isTopLevelOnly) {
|
|
1127
|
+
return `${mediaType}/` === mediaTypePrefix;
|
|
1128
|
+
}
|
|
1129
|
+
return mediaType.startsWith(mediaTypePrefix);
|
|
1130
|
+
}).flatMap(({ regexes }) => regexes).some((pattern) => pattern.test(url));
|
|
801
1131
|
}
|
|
802
1132
|
|
|
803
1133
|
// src/load-api-key.ts
|
|
804
|
-
|
|
1134
|
+
import { LoadAPIKeyError } from "@ai-sdk/provider";
|
|
805
1135
|
function loadApiKey({
|
|
806
1136
|
apiKey,
|
|
807
1137
|
environmentVariableName,
|
|
@@ -812,23 +1142,23 @@ function loadApiKey({
|
|
|
812
1142
|
return apiKey;
|
|
813
1143
|
}
|
|
814
1144
|
if (apiKey != null) {
|
|
815
|
-
throw new
|
|
1145
|
+
throw new LoadAPIKeyError({
|
|
816
1146
|
message: `${description} API key must be a string.`
|
|
817
1147
|
});
|
|
818
1148
|
}
|
|
819
1149
|
if (typeof process === "undefined") {
|
|
820
|
-
throw new
|
|
821
|
-
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables
|
|
1150
|
+
throw new LoadAPIKeyError({
|
|
1151
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables are not supported in this environment.`
|
|
822
1152
|
});
|
|
823
1153
|
}
|
|
824
1154
|
apiKey = process.env[environmentVariableName];
|
|
825
1155
|
if (apiKey == null) {
|
|
826
|
-
throw new
|
|
1156
|
+
throw new LoadAPIKeyError({
|
|
827
1157
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
828
1158
|
});
|
|
829
1159
|
}
|
|
830
1160
|
if (typeof apiKey !== "string") {
|
|
831
|
-
throw new
|
|
1161
|
+
throw new LoadAPIKeyError({
|
|
832
1162
|
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
833
1163
|
});
|
|
834
1164
|
}
|
|
@@ -854,7 +1184,7 @@ function loadOptionalSetting({
|
|
|
854
1184
|
}
|
|
855
1185
|
|
|
856
1186
|
// src/load-setting.ts
|
|
857
|
-
|
|
1187
|
+
import { LoadSettingError } from "@ai-sdk/provider";
|
|
858
1188
|
function loadSetting({
|
|
859
1189
|
settingValue,
|
|
860
1190
|
environmentVariableName,
|
|
@@ -865,29 +1195,86 @@ function loadSetting({
|
|
|
865
1195
|
return settingValue;
|
|
866
1196
|
}
|
|
867
1197
|
if (settingValue != null) {
|
|
868
|
-
throw new
|
|
1198
|
+
throw new LoadSettingError({
|
|
869
1199
|
message: `${description} setting must be a string.`
|
|
870
1200
|
});
|
|
871
1201
|
}
|
|
872
1202
|
if (typeof process === "undefined") {
|
|
873
|
-
throw new
|
|
874
|
-
message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables
|
|
1203
|
+
throw new LoadSettingError({
|
|
1204
|
+
message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables are not supported in this environment.`
|
|
875
1205
|
});
|
|
876
1206
|
}
|
|
877
1207
|
settingValue = process.env[environmentVariableName];
|
|
878
1208
|
if (settingValue == null) {
|
|
879
|
-
throw new
|
|
1209
|
+
throw new LoadSettingError({
|
|
880
1210
|
message: `${description} setting is missing. Pass it using the '${settingName}' parameter or the ${environmentVariableName} environment variable.`
|
|
881
1211
|
});
|
|
882
1212
|
}
|
|
883
1213
|
if (typeof settingValue !== "string") {
|
|
884
|
-
throw new
|
|
1214
|
+
throw new LoadSettingError({
|
|
885
1215
|
message: `${description} setting must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
886
1216
|
});
|
|
887
1217
|
}
|
|
888
1218
|
return settingValue;
|
|
889
1219
|
}
|
|
890
1220
|
|
|
1221
|
+
// src/map-reasoning-to-provider.ts
|
|
1222
|
+
function isCustomReasoning(reasoning) {
|
|
1223
|
+
return reasoning !== void 0 && reasoning !== "provider-default";
|
|
1224
|
+
}
|
|
1225
|
+
function mapReasoningToProviderEffort({
|
|
1226
|
+
reasoning,
|
|
1227
|
+
effortMap,
|
|
1228
|
+
warnings
|
|
1229
|
+
}) {
|
|
1230
|
+
const mapped = effortMap[reasoning];
|
|
1231
|
+
if (mapped == null) {
|
|
1232
|
+
warnings.push({
|
|
1233
|
+
type: "unsupported",
|
|
1234
|
+
feature: "reasoning",
|
|
1235
|
+
details: `reasoning "${reasoning}" is not supported by this model.`
|
|
1236
|
+
});
|
|
1237
|
+
return void 0;
|
|
1238
|
+
}
|
|
1239
|
+
if (mapped !== reasoning) {
|
|
1240
|
+
warnings.push({
|
|
1241
|
+
type: "compatibility",
|
|
1242
|
+
feature: "reasoning",
|
|
1243
|
+
details: `reasoning "${reasoning}" is not directly supported by this model. mapped to effort "${mapped}".`
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
return mapped;
|
|
1247
|
+
}
|
|
1248
|
+
var DEFAULT_REASONING_BUDGET_PERCENTAGES = {
|
|
1249
|
+
minimal: 0.02,
|
|
1250
|
+
low: 0.1,
|
|
1251
|
+
medium: 0.3,
|
|
1252
|
+
high: 0.6,
|
|
1253
|
+
xhigh: 0.9
|
|
1254
|
+
};
|
|
1255
|
+
function mapReasoningToProviderBudget({
|
|
1256
|
+
reasoning,
|
|
1257
|
+
maxOutputTokens,
|
|
1258
|
+
maxReasoningBudget,
|
|
1259
|
+
minReasoningBudget = 1024,
|
|
1260
|
+
budgetPercentages = DEFAULT_REASONING_BUDGET_PERCENTAGES,
|
|
1261
|
+
warnings
|
|
1262
|
+
}) {
|
|
1263
|
+
const pct = budgetPercentages[reasoning];
|
|
1264
|
+
if (pct == null) {
|
|
1265
|
+
warnings.push({
|
|
1266
|
+
type: "unsupported",
|
|
1267
|
+
feature: "reasoning",
|
|
1268
|
+
details: `reasoning "${reasoning}" is not supported by this model.`
|
|
1269
|
+
});
|
|
1270
|
+
return void 0;
|
|
1271
|
+
}
|
|
1272
|
+
return Math.min(
|
|
1273
|
+
maxReasoningBudget,
|
|
1274
|
+
Math.max(minReasoningBudget, Math.round(maxOutputTokens * pct))
|
|
1275
|
+
);
|
|
1276
|
+
}
|
|
1277
|
+
|
|
891
1278
|
// src/media-type-to-extension.ts
|
|
892
1279
|
function mediaTypeToExtension(mediaType) {
|
|
893
1280
|
var _a2;
|
|
@@ -902,7 +1289,10 @@ function mediaTypeToExtension(mediaType) {
|
|
|
902
1289
|
}
|
|
903
1290
|
|
|
904
1291
|
// src/parse-json.ts
|
|
905
|
-
|
|
1292
|
+
import {
|
|
1293
|
+
JSONParseError,
|
|
1294
|
+
TypeValidationError as TypeValidationError3
|
|
1295
|
+
} from "@ai-sdk/provider";
|
|
906
1296
|
|
|
907
1297
|
// src/secure-json-parse.ts
|
|
908
1298
|
var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
@@ -954,11 +1344,13 @@ function secureJsonParse(text) {
|
|
|
954
1344
|
}
|
|
955
1345
|
|
|
956
1346
|
// src/validate-types.ts
|
|
957
|
-
|
|
1347
|
+
import {
|
|
1348
|
+
TypeValidationError as TypeValidationError2
|
|
1349
|
+
} from "@ai-sdk/provider";
|
|
958
1350
|
|
|
959
1351
|
// src/schema.ts
|
|
960
|
-
|
|
961
|
-
|
|
1352
|
+
import { TypeValidationError } from "@ai-sdk/provider";
|
|
1353
|
+
import * as z4 from "zod/v4";
|
|
962
1354
|
|
|
963
1355
|
// src/add-additional-properties-to-json-schema.ts
|
|
964
1356
|
function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
|
|
@@ -1030,7 +1422,7 @@ var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
|
1030
1422
|
};
|
|
1031
1423
|
|
|
1032
1424
|
// src/to-json-schema/zod3-to-json-schema/select-parser.ts
|
|
1033
|
-
|
|
1425
|
+
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod/v3";
|
|
1034
1426
|
|
|
1035
1427
|
// src/to-json-schema/zod3-to-json-schema/parsers/any.ts
|
|
1036
1428
|
function parseAnyDef() {
|
|
@@ -1038,13 +1430,13 @@ function parseAnyDef() {
|
|
|
1038
1430
|
}
|
|
1039
1431
|
|
|
1040
1432
|
// src/to-json-schema/zod3-to-json-schema/parsers/array.ts
|
|
1041
|
-
|
|
1433
|
+
import { ZodFirstPartyTypeKind } from "zod/v3";
|
|
1042
1434
|
function parseArrayDef(def, refs) {
|
|
1043
1435
|
var _a2, _b2, _c;
|
|
1044
1436
|
const res = {
|
|
1045
1437
|
type: "array"
|
|
1046
1438
|
};
|
|
1047
|
-
if (((_a2 = def.type) == null ? void 0 : _a2._def) && ((_c = (_b2 = def.type) == null ? void 0 : _b2._def) == null ? void 0 : _c.typeName) !==
|
|
1439
|
+
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) {
|
|
1048
1440
|
res.items = parseDef(def.type._def, {
|
|
1049
1441
|
...refs,
|
|
1050
1442
|
currentPath: [...refs.currentPath, "items"]
|
|
@@ -1114,7 +1506,7 @@ function parseDateDef(def, refs, overrideDateStrategy) {
|
|
|
1114
1506
|
const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
|
|
1115
1507
|
if (Array.isArray(strategy)) {
|
|
1116
1508
|
return {
|
|
1117
|
-
anyOf: strategy.map((item
|
|
1509
|
+
anyOf: strategy.map((item) => parseDateDef(def, refs, item))
|
|
1118
1510
|
};
|
|
1119
1511
|
}
|
|
1120
1512
|
switch (strategy) {
|
|
@@ -1195,7 +1587,7 @@ function parseIntersectionDef(def, refs) {
|
|
|
1195
1587
|
} else {
|
|
1196
1588
|
let nestedSchema = schema;
|
|
1197
1589
|
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
1198
|
-
const { additionalProperties, ...rest } = schema;
|
|
1590
|
+
const { additionalProperties: _additionalProperties, ...rest } = schema;
|
|
1199
1591
|
nestedSchema = rest;
|
|
1200
1592
|
}
|
|
1201
1593
|
mergedAllOf.push(nestedSchema);
|
|
@@ -1219,7 +1611,9 @@ function parseLiteralDef(def) {
|
|
|
1219
1611
|
}
|
|
1220
1612
|
|
|
1221
1613
|
// src/to-json-schema/zod3-to-json-schema/parsers/record.ts
|
|
1222
|
-
|
|
1614
|
+
import {
|
|
1615
|
+
ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2
|
|
1616
|
+
} from "zod/v3";
|
|
1223
1617
|
|
|
1224
1618
|
// src/to-json-schema/zod3-to-json-schema/parsers/string.ts
|
|
1225
1619
|
var emojiRegex = void 0;
|
|
@@ -1567,21 +1961,21 @@ function parseRecordDef(def, refs) {
|
|
|
1567
1961
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1568
1962
|
})) != null ? _a2 : refs.allowedAdditionalProperties
|
|
1569
1963
|
};
|
|
1570
|
-
if (((_b2 = def.keyType) == null ? void 0 : _b2._def.typeName) ===
|
|
1571
|
-
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
1964
|
+
if (((_b2 = def.keyType) == null ? void 0 : _b2._def.typeName) === ZodFirstPartyTypeKind2.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1965
|
+
const { type: _type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
1572
1966
|
return {
|
|
1573
1967
|
...schema,
|
|
1574
1968
|
propertyNames: keyType
|
|
1575
1969
|
};
|
|
1576
|
-
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) ===
|
|
1970
|
+
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
1577
1971
|
return {
|
|
1578
1972
|
...schema,
|
|
1579
1973
|
propertyNames: {
|
|
1580
1974
|
enum: def.keyType._def.values
|
|
1581
1975
|
}
|
|
1582
1976
|
};
|
|
1583
|
-
} else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) ===
|
|
1584
|
-
const { type, ...keyType } = parseBrandedDef(
|
|
1977
|
+
} 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)) {
|
|
1978
|
+
const { type: _type, ...keyType } = parseBrandedDef(
|
|
1585
1979
|
def.keyType._def,
|
|
1586
1980
|
refs
|
|
1587
1981
|
);
|
|
@@ -1858,16 +2252,18 @@ var parsePipelineDef = (def, refs) => {
|
|
|
1858
2252
|
} else if (refs.pipeStrategy === "output") {
|
|
1859
2253
|
return parseDef(def.out._def, refs);
|
|
1860
2254
|
}
|
|
1861
|
-
const
|
|
2255
|
+
const inputSchema = parseDef(def.in._def, {
|
|
1862
2256
|
...refs,
|
|
1863
2257
|
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1864
2258
|
});
|
|
1865
|
-
const
|
|
2259
|
+
const outputSchema = parseDef(def.out._def, {
|
|
1866
2260
|
...refs,
|
|
1867
|
-
currentPath: [...refs.currentPath, "allOf",
|
|
2261
|
+
currentPath: [...refs.currentPath, "allOf", inputSchema ? "1" : "0"]
|
|
1868
2262
|
});
|
|
1869
2263
|
return {
|
|
1870
|
-
allOf: [
|
|
2264
|
+
allOf: [inputSchema, outputSchema].filter(
|
|
2265
|
+
(schema) => schema !== void 0
|
|
2266
|
+
)
|
|
1871
2267
|
};
|
|
1872
2268
|
};
|
|
1873
2269
|
|
|
@@ -1954,73 +2350,73 @@ var parseReadonlyDef = (def, refs) => {
|
|
|
1954
2350
|
// src/to-json-schema/zod3-to-json-schema/select-parser.ts
|
|
1955
2351
|
var selectParser = (def, typeName, refs) => {
|
|
1956
2352
|
switch (typeName) {
|
|
1957
|
-
case
|
|
2353
|
+
case ZodFirstPartyTypeKind3.ZodString:
|
|
1958
2354
|
return parseStringDef(def, refs);
|
|
1959
|
-
case
|
|
2355
|
+
case ZodFirstPartyTypeKind3.ZodNumber:
|
|
1960
2356
|
return parseNumberDef(def);
|
|
1961
|
-
case
|
|
2357
|
+
case ZodFirstPartyTypeKind3.ZodObject:
|
|
1962
2358
|
return parseObjectDef(def, refs);
|
|
1963
|
-
case
|
|
2359
|
+
case ZodFirstPartyTypeKind3.ZodBigInt:
|
|
1964
2360
|
return parseBigintDef(def);
|
|
1965
|
-
case
|
|
2361
|
+
case ZodFirstPartyTypeKind3.ZodBoolean:
|
|
1966
2362
|
return parseBooleanDef();
|
|
1967
|
-
case
|
|
2363
|
+
case ZodFirstPartyTypeKind3.ZodDate:
|
|
1968
2364
|
return parseDateDef(def, refs);
|
|
1969
|
-
case
|
|
2365
|
+
case ZodFirstPartyTypeKind3.ZodUndefined:
|
|
1970
2366
|
return parseUndefinedDef();
|
|
1971
|
-
case
|
|
2367
|
+
case ZodFirstPartyTypeKind3.ZodNull:
|
|
1972
2368
|
return parseNullDef();
|
|
1973
|
-
case
|
|
2369
|
+
case ZodFirstPartyTypeKind3.ZodArray:
|
|
1974
2370
|
return parseArrayDef(def, refs);
|
|
1975
|
-
case
|
|
1976
|
-
case
|
|
2371
|
+
case ZodFirstPartyTypeKind3.ZodUnion:
|
|
2372
|
+
case ZodFirstPartyTypeKind3.ZodDiscriminatedUnion:
|
|
1977
2373
|
return parseUnionDef(def, refs);
|
|
1978
|
-
case
|
|
2374
|
+
case ZodFirstPartyTypeKind3.ZodIntersection:
|
|
1979
2375
|
return parseIntersectionDef(def, refs);
|
|
1980
|
-
case
|
|
2376
|
+
case ZodFirstPartyTypeKind3.ZodTuple:
|
|
1981
2377
|
return parseTupleDef(def, refs);
|
|
1982
|
-
case
|
|
2378
|
+
case ZodFirstPartyTypeKind3.ZodRecord:
|
|
1983
2379
|
return parseRecordDef(def, refs);
|
|
1984
|
-
case
|
|
2380
|
+
case ZodFirstPartyTypeKind3.ZodLiteral:
|
|
1985
2381
|
return parseLiteralDef(def);
|
|
1986
|
-
case
|
|
2382
|
+
case ZodFirstPartyTypeKind3.ZodEnum:
|
|
1987
2383
|
return parseEnumDef(def);
|
|
1988
|
-
case
|
|
2384
|
+
case ZodFirstPartyTypeKind3.ZodNativeEnum:
|
|
1989
2385
|
return parseNativeEnumDef(def);
|
|
1990
|
-
case
|
|
2386
|
+
case ZodFirstPartyTypeKind3.ZodNullable:
|
|
1991
2387
|
return parseNullableDef(def, refs);
|
|
1992
|
-
case
|
|
2388
|
+
case ZodFirstPartyTypeKind3.ZodOptional:
|
|
1993
2389
|
return parseOptionalDef(def, refs);
|
|
1994
|
-
case
|
|
2390
|
+
case ZodFirstPartyTypeKind3.ZodMap:
|
|
1995
2391
|
return parseMapDef(def, refs);
|
|
1996
|
-
case
|
|
2392
|
+
case ZodFirstPartyTypeKind3.ZodSet:
|
|
1997
2393
|
return parseSetDef(def, refs);
|
|
1998
|
-
case
|
|
2394
|
+
case ZodFirstPartyTypeKind3.ZodLazy:
|
|
1999
2395
|
return () => def.getter()._def;
|
|
2000
|
-
case
|
|
2396
|
+
case ZodFirstPartyTypeKind3.ZodPromise:
|
|
2001
2397
|
return parsePromiseDef(def, refs);
|
|
2002
|
-
case
|
|
2003
|
-
case
|
|
2398
|
+
case ZodFirstPartyTypeKind3.ZodNaN:
|
|
2399
|
+
case ZodFirstPartyTypeKind3.ZodNever:
|
|
2004
2400
|
return parseNeverDef();
|
|
2005
|
-
case
|
|
2401
|
+
case ZodFirstPartyTypeKind3.ZodEffects:
|
|
2006
2402
|
return parseEffectsDef(def, refs);
|
|
2007
|
-
case
|
|
2403
|
+
case ZodFirstPartyTypeKind3.ZodAny:
|
|
2008
2404
|
return parseAnyDef();
|
|
2009
|
-
case
|
|
2405
|
+
case ZodFirstPartyTypeKind3.ZodUnknown:
|
|
2010
2406
|
return parseUnknownDef();
|
|
2011
|
-
case
|
|
2407
|
+
case ZodFirstPartyTypeKind3.ZodDefault:
|
|
2012
2408
|
return parseDefaultDef(def, refs);
|
|
2013
|
-
case
|
|
2409
|
+
case ZodFirstPartyTypeKind3.ZodBranded:
|
|
2014
2410
|
return parseBrandedDef(def, refs);
|
|
2015
|
-
case
|
|
2411
|
+
case ZodFirstPartyTypeKind3.ZodReadonly:
|
|
2016
2412
|
return parseReadonlyDef(def, refs);
|
|
2017
|
-
case
|
|
2413
|
+
case ZodFirstPartyTypeKind3.ZodCatch:
|
|
2018
2414
|
return parseCatchDef(def, refs);
|
|
2019
|
-
case
|
|
2415
|
+
case ZodFirstPartyTypeKind3.ZodPipeline:
|
|
2020
2416
|
return parsePipelineDef(def, refs);
|
|
2021
|
-
case
|
|
2022
|
-
case
|
|
2023
|
-
case
|
|
2417
|
+
case ZodFirstPartyTypeKind3.ZodFunction:
|
|
2418
|
+
case ZodFirstPartyTypeKind3.ZodVoid:
|
|
2419
|
+
case ZodFirstPartyTypeKind3.ZodSymbol:
|
|
2024
2420
|
return void 0;
|
|
2025
2421
|
default:
|
|
2026
2422
|
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
@@ -2205,7 +2601,11 @@ function isSchema(value) {
|
|
|
2205
2601
|
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
|
2206
2602
|
}
|
|
2207
2603
|
function asSchema(schema) {
|
|
2208
|
-
return schema == null ? jsonSchema({
|
|
2604
|
+
return schema == null ? jsonSchema({
|
|
2605
|
+
type: "object",
|
|
2606
|
+
properties: {},
|
|
2607
|
+
additionalProperties: false
|
|
2608
|
+
}) : isSchema(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema(schema) : standardSchema(schema) : schema();
|
|
2209
2609
|
}
|
|
2210
2610
|
function standardSchema(standardSchema2) {
|
|
2211
2611
|
return jsonSchema(
|
|
@@ -2219,7 +2619,7 @@ function standardSchema(standardSchema2) {
|
|
|
2219
2619
|
const result = await standardSchema2["~standard"].validate(value);
|
|
2220
2620
|
return "value" in result ? { success: true, value: result.value } : {
|
|
2221
2621
|
success: false,
|
|
2222
|
-
error: new
|
|
2622
|
+
error: new TypeValidationError({
|
|
2223
2623
|
value,
|
|
2224
2624
|
cause: result.issues
|
|
2225
2625
|
})
|
|
@@ -2283,7 +2683,7 @@ async function validateTypes({
|
|
|
2283
2683
|
}) {
|
|
2284
2684
|
const result = await safeValidateTypes({ value, schema, context });
|
|
2285
2685
|
if (!result.success) {
|
|
2286
|
-
throw
|
|
2686
|
+
throw TypeValidationError2.wrap({ value, cause: result.error, context });
|
|
2287
2687
|
}
|
|
2288
2688
|
return result.value;
|
|
2289
2689
|
}
|
|
@@ -2303,13 +2703,13 @@ async function safeValidateTypes({
|
|
|
2303
2703
|
}
|
|
2304
2704
|
return {
|
|
2305
2705
|
success: false,
|
|
2306
|
-
error:
|
|
2706
|
+
error: TypeValidationError2.wrap({ value, cause: result.error, context }),
|
|
2307
2707
|
rawValue: value
|
|
2308
2708
|
};
|
|
2309
2709
|
} catch (error) {
|
|
2310
2710
|
return {
|
|
2311
2711
|
success: false,
|
|
2312
|
-
error:
|
|
2712
|
+
error: TypeValidationError2.wrap({ value, cause: error, context }),
|
|
2313
2713
|
rawValue: value
|
|
2314
2714
|
};
|
|
2315
2715
|
}
|
|
@@ -2325,12 +2725,12 @@ async function parseJSON({
|
|
|
2325
2725
|
if (schema == null) {
|
|
2326
2726
|
return value;
|
|
2327
2727
|
}
|
|
2328
|
-
return validateTypes({ value, schema });
|
|
2728
|
+
return await validateTypes({ value, schema });
|
|
2329
2729
|
} catch (error) {
|
|
2330
|
-
if (
|
|
2730
|
+
if (JSONParseError.isInstance(error) || TypeValidationError3.isInstance(error)) {
|
|
2331
2731
|
throw error;
|
|
2332
2732
|
}
|
|
2333
|
-
throw new
|
|
2733
|
+
throw new JSONParseError({ text, cause: error });
|
|
2334
2734
|
}
|
|
2335
2735
|
}
|
|
2336
2736
|
async function safeParseJSON({
|
|
@@ -2346,7 +2746,7 @@ async function safeParseJSON({
|
|
|
2346
2746
|
} catch (error) {
|
|
2347
2747
|
return {
|
|
2348
2748
|
success: false,
|
|
2349
|
-
error:
|
|
2749
|
+
error: JSONParseError.isInstance(error) ? error : new JSONParseError({ text, cause: error }),
|
|
2350
2750
|
rawValue: void 0
|
|
2351
2751
|
};
|
|
2352
2752
|
}
|
|
@@ -2361,12 +2761,14 @@ function isParsableJson(input) {
|
|
|
2361
2761
|
}
|
|
2362
2762
|
|
|
2363
2763
|
// src/parse-json-event-stream.ts
|
|
2364
|
-
|
|
2764
|
+
import {
|
|
2765
|
+
EventSourceParserStream
|
|
2766
|
+
} from "eventsource-parser/stream";
|
|
2365
2767
|
function parseJsonEventStream({
|
|
2366
2768
|
stream,
|
|
2367
2769
|
schema
|
|
2368
2770
|
}) {
|
|
2369
|
-
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new
|
|
2771
|
+
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).pipeThrough(
|
|
2370
2772
|
new TransformStream({
|
|
2371
2773
|
async transform({ data }, controller) {
|
|
2372
2774
|
if (data === "[DONE]") {
|
|
@@ -2379,7 +2781,7 @@ function parseJsonEventStream({
|
|
|
2379
2781
|
}
|
|
2380
2782
|
|
|
2381
2783
|
// src/parse-provider-options.ts
|
|
2382
|
-
|
|
2784
|
+
import { InvalidArgumentError as InvalidArgumentError2 } from "@ai-sdk/provider";
|
|
2383
2785
|
async function parseProviderOptions({
|
|
2384
2786
|
provider,
|
|
2385
2787
|
providerOptions,
|
|
@@ -2393,7 +2795,7 @@ async function parseProviderOptions({
|
|
|
2393
2795
|
schema
|
|
2394
2796
|
});
|
|
2395
2797
|
if (!parsedProviderOptions.success) {
|
|
2396
|
-
throw new
|
|
2798
|
+
throw new InvalidArgumentError2({
|
|
2397
2799
|
argument: "providerOptions",
|
|
2398
2800
|
message: `invalid ${provider} provider options`,
|
|
2399
2801
|
cause: parsedProviderOptions.error
|
|
@@ -2403,7 +2805,7 @@ async function parseProviderOptions({
|
|
|
2403
2805
|
}
|
|
2404
2806
|
|
|
2405
2807
|
// src/post-to-api.ts
|
|
2406
|
-
|
|
2808
|
+
import { APICallError as APICallError3 } from "@ai-sdk/provider";
|
|
2407
2809
|
var getOriginalFetch2 = () => globalThis.fetch;
|
|
2408
2810
|
var postJsonToApi = async ({
|
|
2409
2811
|
url,
|
|
@@ -2413,7 +2815,7 @@ var postJsonToApi = async ({
|
|
|
2413
2815
|
successfulResponseHandler,
|
|
2414
2816
|
abortSignal,
|
|
2415
2817
|
fetch: fetch2
|
|
2416
|
-
}) => postToApi({
|
|
2818
|
+
}) => await postToApi({
|
|
2417
2819
|
url,
|
|
2418
2820
|
headers: {
|
|
2419
2821
|
"Content-Type": "application/json",
|
|
@@ -2436,7 +2838,7 @@ var postFormDataToApi = async ({
|
|
|
2436
2838
|
successfulResponseHandler,
|
|
2437
2839
|
abortSignal,
|
|
2438
2840
|
fetch: fetch2
|
|
2439
|
-
}) => postToApi({
|
|
2841
|
+
}) => await postToApi({
|
|
2440
2842
|
url,
|
|
2441
2843
|
headers,
|
|
2442
2844
|
body: {
|
|
@@ -2478,10 +2880,10 @@ var postToApi = async ({
|
|
|
2478
2880
|
requestBodyValues: body.values
|
|
2479
2881
|
});
|
|
2480
2882
|
} catch (error) {
|
|
2481
|
-
if (isAbortError(error) ||
|
|
2883
|
+
if (isAbortError(error) || APICallError3.isInstance(error)) {
|
|
2482
2884
|
throw error;
|
|
2483
2885
|
}
|
|
2484
|
-
throw new
|
|
2886
|
+
throw new APICallError3({
|
|
2485
2887
|
message: "Failed to process error response",
|
|
2486
2888
|
cause: error,
|
|
2487
2889
|
statusCode: response.status,
|
|
@@ -2500,11 +2902,11 @@ var postToApi = async ({
|
|
|
2500
2902
|
});
|
|
2501
2903
|
} catch (error) {
|
|
2502
2904
|
if (error instanceof Error) {
|
|
2503
|
-
if (isAbortError(error) ||
|
|
2905
|
+
if (isAbortError(error) || APICallError3.isInstance(error)) {
|
|
2504
2906
|
throw error;
|
|
2505
2907
|
}
|
|
2506
2908
|
}
|
|
2507
|
-
throw new
|
|
2909
|
+
throw new APICallError3({
|
|
2508
2910
|
message: "Failed to process successful response",
|
|
2509
2911
|
cause: error,
|
|
2510
2912
|
statusCode: response.status,
|
|
@@ -2526,8 +2928,8 @@ function dynamicTool(tool2) {
|
|
|
2526
2928
|
return { ...tool2, type: "dynamic" };
|
|
2527
2929
|
}
|
|
2528
2930
|
|
|
2529
|
-
// src/provider-tool-factory.ts
|
|
2530
|
-
function
|
|
2931
|
+
// src/provider-defined-tool-factory.ts
|
|
2932
|
+
function createProviderDefinedToolFactory({
|
|
2531
2933
|
id,
|
|
2532
2934
|
inputSchema
|
|
2533
2935
|
}) {
|
|
@@ -2542,6 +2944,7 @@ function createProviderToolFactory({
|
|
|
2542
2944
|
...args
|
|
2543
2945
|
}) => tool({
|
|
2544
2946
|
type: "provider",
|
|
2947
|
+
isProviderExecuted: false,
|
|
2545
2948
|
id,
|
|
2546
2949
|
args,
|
|
2547
2950
|
inputSchema,
|
|
@@ -2554,11 +2957,10 @@ function createProviderToolFactory({
|
|
|
2554
2957
|
onInputAvailable
|
|
2555
2958
|
});
|
|
2556
2959
|
}
|
|
2557
|
-
function
|
|
2960
|
+
function createProviderDefinedToolFactoryWithOutputSchema({
|
|
2558
2961
|
id,
|
|
2559
2962
|
inputSchema,
|
|
2560
|
-
outputSchema
|
|
2561
|
-
supportsDeferredResults
|
|
2963
|
+
outputSchema
|
|
2562
2964
|
}) {
|
|
2563
2965
|
return ({
|
|
2564
2966
|
execute,
|
|
@@ -2570,6 +2972,7 @@ function createProviderToolFactoryWithOutputSchema({
|
|
|
2570
2972
|
...args
|
|
2571
2973
|
}) => tool({
|
|
2572
2974
|
type: "provider",
|
|
2975
|
+
isProviderExecuted: false,
|
|
2573
2976
|
id,
|
|
2574
2977
|
args,
|
|
2575
2978
|
inputSchema,
|
|
@@ -2579,6 +2982,31 @@ function createProviderToolFactoryWithOutputSchema({
|
|
|
2579
2982
|
toModelOutput,
|
|
2580
2983
|
onInputStart,
|
|
2581
2984
|
onInputDelta,
|
|
2985
|
+
onInputAvailable
|
|
2986
|
+
});
|
|
2987
|
+
}
|
|
2988
|
+
|
|
2989
|
+
// src/provider-executed-tool-factory.ts
|
|
2990
|
+
function createProviderExecutedToolFactory({
|
|
2991
|
+
id,
|
|
2992
|
+
inputSchema,
|
|
2993
|
+
outputSchema,
|
|
2994
|
+
supportsDeferredResults
|
|
2995
|
+
}) {
|
|
2996
|
+
return ({
|
|
2997
|
+
onInputStart,
|
|
2998
|
+
onInputDelta,
|
|
2999
|
+
onInputAvailable,
|
|
3000
|
+
...args
|
|
3001
|
+
}) => tool({
|
|
3002
|
+
type: "provider",
|
|
3003
|
+
isProviderExecuted: true,
|
|
3004
|
+
id,
|
|
3005
|
+
args,
|
|
3006
|
+
inputSchema,
|
|
3007
|
+
outputSchema,
|
|
3008
|
+
onInputStart,
|
|
3009
|
+
onInputDelta,
|
|
2582
3010
|
onInputAvailable,
|
|
2583
3011
|
supportsDeferredResults
|
|
2584
3012
|
});
|
|
@@ -2599,8 +3027,53 @@ async function resolve(value) {
|
|
|
2599
3027
|
return Promise.resolve(value);
|
|
2600
3028
|
}
|
|
2601
3029
|
|
|
3030
|
+
// src/resolve-full-media-type.ts
|
|
3031
|
+
import {
|
|
3032
|
+
UnsupportedFunctionalityError
|
|
3033
|
+
} from "@ai-sdk/provider";
|
|
3034
|
+
function resolveFullMediaType({
|
|
3035
|
+
part
|
|
3036
|
+
}) {
|
|
3037
|
+
if (isFullMediaType(part.mediaType)) {
|
|
3038
|
+
return part.mediaType;
|
|
3039
|
+
}
|
|
3040
|
+
if (part.data.type === "data") {
|
|
3041
|
+
const detected = detectMediaType({
|
|
3042
|
+
data: part.data.data,
|
|
3043
|
+
topLevelType: getTopLevelMediaType(part.mediaType)
|
|
3044
|
+
});
|
|
3045
|
+
if (detected) {
|
|
3046
|
+
return detected;
|
|
3047
|
+
}
|
|
3048
|
+
throw new UnsupportedFunctionalityError({
|
|
3049
|
+
functionality: `file of media type "${part.mediaType}" must specify subtype since it could not be auto-detected`
|
|
3050
|
+
});
|
|
3051
|
+
}
|
|
3052
|
+
throw new UnsupportedFunctionalityError({
|
|
3053
|
+
functionality: `file of media type "${part.mediaType}" must specify subtype since it is not passed as inline bytes`
|
|
3054
|
+
});
|
|
3055
|
+
}
|
|
3056
|
+
|
|
3057
|
+
// src/resolve-provider-reference.ts
|
|
3058
|
+
import {
|
|
3059
|
+
NoSuchProviderReferenceError
|
|
3060
|
+
} from "@ai-sdk/provider";
|
|
3061
|
+
function resolveProviderReference({
|
|
3062
|
+
reference,
|
|
3063
|
+
provider
|
|
3064
|
+
}) {
|
|
3065
|
+
const id = reference[provider];
|
|
3066
|
+
if (id != null) {
|
|
3067
|
+
return id;
|
|
3068
|
+
}
|
|
3069
|
+
throw new NoSuchProviderReferenceError({
|
|
3070
|
+
provider,
|
|
3071
|
+
reference
|
|
3072
|
+
});
|
|
3073
|
+
}
|
|
3074
|
+
|
|
2602
3075
|
// src/response-handler.ts
|
|
2603
|
-
|
|
3076
|
+
import { APICallError as APICallError4, EmptyResponseBodyError } from "@ai-sdk/provider";
|
|
2604
3077
|
var createJsonErrorResponseHandler = ({
|
|
2605
3078
|
errorSchema,
|
|
2606
3079
|
errorToMessage,
|
|
@@ -2611,7 +3084,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
2611
3084
|
if (responseBody.trim() === "") {
|
|
2612
3085
|
return {
|
|
2613
3086
|
responseHeaders,
|
|
2614
|
-
value: new
|
|
3087
|
+
value: new APICallError4({
|
|
2615
3088
|
message: response.statusText,
|
|
2616
3089
|
url,
|
|
2617
3090
|
requestBodyValues,
|
|
@@ -2629,7 +3102,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
2629
3102
|
});
|
|
2630
3103
|
return {
|
|
2631
3104
|
responseHeaders,
|
|
2632
|
-
value: new
|
|
3105
|
+
value: new APICallError4({
|
|
2633
3106
|
message: errorToMessage(parsedError),
|
|
2634
3107
|
url,
|
|
2635
3108
|
requestBodyValues,
|
|
@@ -2640,10 +3113,10 @@ var createJsonErrorResponseHandler = ({
|
|
|
2640
3113
|
isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
|
|
2641
3114
|
})
|
|
2642
3115
|
};
|
|
2643
|
-
} catch (
|
|
3116
|
+
} catch (e) {
|
|
2644
3117
|
return {
|
|
2645
3118
|
responseHeaders,
|
|
2646
|
-
value: new
|
|
3119
|
+
value: new APICallError4({
|
|
2647
3120
|
message: response.statusText,
|
|
2648
3121
|
url,
|
|
2649
3122
|
requestBodyValues,
|
|
@@ -2658,7 +3131,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
2658
3131
|
var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
2659
3132
|
const responseHeaders = extractResponseHeaders(response);
|
|
2660
3133
|
if (response.body == null) {
|
|
2661
|
-
throw new
|
|
3134
|
+
throw new EmptyResponseBodyError({});
|
|
2662
3135
|
}
|
|
2663
3136
|
return {
|
|
2664
3137
|
responseHeaders,
|
|
@@ -2676,7 +3149,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
2676
3149
|
});
|
|
2677
3150
|
const responseHeaders = extractResponseHeaders(response);
|
|
2678
3151
|
if (!parsedResult.success) {
|
|
2679
|
-
throw new
|
|
3152
|
+
throw new APICallError4({
|
|
2680
3153
|
message: "Invalid JSON response",
|
|
2681
3154
|
cause: parsedResult.error,
|
|
2682
3155
|
statusCode: response.status,
|
|
@@ -2695,7 +3168,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
2695
3168
|
var createBinaryResponseHandler = () => async ({ response, url, requestBodyValues }) => {
|
|
2696
3169
|
const responseHeaders = extractResponseHeaders(response);
|
|
2697
3170
|
if (!response.body) {
|
|
2698
|
-
throw new
|
|
3171
|
+
throw new APICallError4({
|
|
2699
3172
|
message: "Response body is empty",
|
|
2700
3173
|
url,
|
|
2701
3174
|
requestBodyValues,
|
|
@@ -2711,7 +3184,7 @@ var createBinaryResponseHandler = () => async ({ response, url, requestBodyValue
|
|
|
2711
3184
|
value: new Uint8Array(buffer)
|
|
2712
3185
|
};
|
|
2713
3186
|
} catch (error) {
|
|
2714
|
-
throw new
|
|
3187
|
+
throw new APICallError4({
|
|
2715
3188
|
message: "Failed to read response as array buffer",
|
|
2716
3189
|
url,
|
|
2717
3190
|
requestBodyValues,
|
|
@@ -2727,7 +3200,7 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
|
|
|
2727
3200
|
const responseBody = await response.text();
|
|
2728
3201
|
return {
|
|
2729
3202
|
responseHeaders,
|
|
2730
|
-
value: new
|
|
3203
|
+
value: new APICallError4({
|
|
2731
3204
|
message: response.statusText,
|
|
2732
3205
|
url,
|
|
2733
3206
|
requestBodyValues,
|
|
@@ -2738,6 +3211,185 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
|
|
|
2738
3211
|
};
|
|
2739
3212
|
};
|
|
2740
3213
|
|
|
3214
|
+
// src/is-json-serializable.ts
|
|
3215
|
+
function isJSONSerializable(value) {
|
|
3216
|
+
if (value === null || value === void 0) return true;
|
|
3217
|
+
const type = typeof value;
|
|
3218
|
+
if (type === "string" || type === "number" || type === "boolean") return true;
|
|
3219
|
+
if (type === "function" || type === "symbol" || type === "bigint")
|
|
3220
|
+
return false;
|
|
3221
|
+
if (Array.isArray(value)) {
|
|
3222
|
+
return value.every(isJSONSerializable);
|
|
3223
|
+
}
|
|
3224
|
+
if (Object.getPrototypeOf(value) === Object.prototype) {
|
|
3225
|
+
return Object.values(value).every(
|
|
3226
|
+
isJSONSerializable
|
|
3227
|
+
);
|
|
3228
|
+
}
|
|
3229
|
+
return false;
|
|
3230
|
+
}
|
|
3231
|
+
|
|
3232
|
+
// src/serialize-model-options.ts
|
|
3233
|
+
function serializeModelOptions(options) {
|
|
3234
|
+
const serializableConfig = {};
|
|
3235
|
+
for (const [key, value] of Object.entries(options.config)) {
|
|
3236
|
+
if (key === "headers") {
|
|
3237
|
+
const resolvedHeaders = resolveSync(value);
|
|
3238
|
+
if (isJSONSerializable(resolvedHeaders)) {
|
|
3239
|
+
serializableConfig[key] = resolvedHeaders;
|
|
3240
|
+
}
|
|
3241
|
+
} else if (isJSONSerializable(value)) {
|
|
3242
|
+
serializableConfig[key] = value;
|
|
3243
|
+
}
|
|
3244
|
+
}
|
|
3245
|
+
return { modelId: options.modelId, config: serializableConfig };
|
|
3246
|
+
}
|
|
3247
|
+
function resolveSync(value) {
|
|
3248
|
+
let next = value;
|
|
3249
|
+
if (typeof value === "function") {
|
|
3250
|
+
next = value();
|
|
3251
|
+
}
|
|
3252
|
+
if (next instanceof Promise) {
|
|
3253
|
+
throw new Error("Promise returned from resolveSync");
|
|
3254
|
+
}
|
|
3255
|
+
return next;
|
|
3256
|
+
}
|
|
3257
|
+
|
|
3258
|
+
// src/streaming-tool-call-tracker.ts
|
|
3259
|
+
import {
|
|
3260
|
+
InvalidResponseDataError
|
|
3261
|
+
} from "@ai-sdk/provider";
|
|
3262
|
+
var StreamingToolCallTracker = class {
|
|
3263
|
+
constructor(controller, options = {}) {
|
|
3264
|
+
this.toolCalls = [];
|
|
3265
|
+
var _a2, _b2;
|
|
3266
|
+
this.controller = controller;
|
|
3267
|
+
this._generateId = (_a2 = options.generateId) != null ? _a2 : generateId;
|
|
3268
|
+
this.typeValidation = (_b2 = options.typeValidation) != null ? _b2 : "none";
|
|
3269
|
+
this.extractMetadata = options.extractMetadata;
|
|
3270
|
+
this.buildToolCallProviderMetadata = options.buildToolCallProviderMetadata;
|
|
3271
|
+
}
|
|
3272
|
+
/**
|
|
3273
|
+
* Process a tool call delta from a streaming response chunk.
|
|
3274
|
+
* Emits tool-input-start, tool-input-delta, tool-input-end, and tool-call
|
|
3275
|
+
* events as appropriate.
|
|
3276
|
+
*/
|
|
3277
|
+
processDelta(toolCallDelta) {
|
|
3278
|
+
var _a2;
|
|
3279
|
+
const index = (_a2 = toolCallDelta.index) != null ? _a2 : this.toolCalls.length;
|
|
3280
|
+
if (this.toolCalls[index] == null) {
|
|
3281
|
+
this.processNewToolCall(index, toolCallDelta);
|
|
3282
|
+
} else {
|
|
3283
|
+
this.processExistingToolCall(index, toolCallDelta);
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
/**
|
|
3287
|
+
* Finalize any unfinished tool calls. Should be called during the stream's
|
|
3288
|
+
* flush handler to ensure all tool calls are properly completed.
|
|
3289
|
+
*/
|
|
3290
|
+
flush() {
|
|
3291
|
+
for (const toolCall of this.toolCalls) {
|
|
3292
|
+
if (!toolCall.hasFinished) {
|
|
3293
|
+
this.finishToolCall(toolCall);
|
|
3294
|
+
}
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
processNewToolCall(index, toolCallDelta) {
|
|
3298
|
+
var _a2, _b2, _c;
|
|
3299
|
+
if (this.typeValidation === "required") {
|
|
3300
|
+
if (toolCallDelta.type !== "function") {
|
|
3301
|
+
throw new InvalidResponseDataError({
|
|
3302
|
+
data: toolCallDelta,
|
|
3303
|
+
message: `Expected 'function' type.`
|
|
3304
|
+
});
|
|
3305
|
+
}
|
|
3306
|
+
} else if (this.typeValidation === "if-present") {
|
|
3307
|
+
if (toolCallDelta.type != null && toolCallDelta.type !== "function") {
|
|
3308
|
+
throw new InvalidResponseDataError({
|
|
3309
|
+
data: toolCallDelta,
|
|
3310
|
+
message: `Expected 'function' type.`
|
|
3311
|
+
});
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
if (toolCallDelta.id == null) {
|
|
3315
|
+
throw new InvalidResponseDataError({
|
|
3316
|
+
data: toolCallDelta,
|
|
3317
|
+
message: `Expected 'id' to be a string.`
|
|
3318
|
+
});
|
|
3319
|
+
}
|
|
3320
|
+
if (((_a2 = toolCallDelta.function) == null ? void 0 : _a2.name) == null) {
|
|
3321
|
+
throw new InvalidResponseDataError({
|
|
3322
|
+
data: toolCallDelta,
|
|
3323
|
+
message: `Expected 'function.name' to be a string.`
|
|
3324
|
+
});
|
|
3325
|
+
}
|
|
3326
|
+
this.controller.enqueue({
|
|
3327
|
+
type: "tool-input-start",
|
|
3328
|
+
id: toolCallDelta.id,
|
|
3329
|
+
toolName: toolCallDelta.function.name
|
|
3330
|
+
});
|
|
3331
|
+
const metadata = (_b2 = this.extractMetadata) == null ? void 0 : _b2.call(this, toolCallDelta);
|
|
3332
|
+
this.toolCalls[index] = {
|
|
3333
|
+
id: toolCallDelta.id,
|
|
3334
|
+
type: "function",
|
|
3335
|
+
function: {
|
|
3336
|
+
name: toolCallDelta.function.name,
|
|
3337
|
+
arguments: (_c = toolCallDelta.function.arguments) != null ? _c : ""
|
|
3338
|
+
},
|
|
3339
|
+
hasFinished: false,
|
|
3340
|
+
metadata
|
|
3341
|
+
};
|
|
3342
|
+
const toolCall = this.toolCalls[index];
|
|
3343
|
+
if (toolCall.function.arguments.length > 0) {
|
|
3344
|
+
this.controller.enqueue({
|
|
3345
|
+
type: "tool-input-delta",
|
|
3346
|
+
id: toolCall.id,
|
|
3347
|
+
delta: toolCall.function.arguments
|
|
3348
|
+
});
|
|
3349
|
+
}
|
|
3350
|
+
if (isParsableJson(toolCall.function.arguments)) {
|
|
3351
|
+
this.finishToolCall(toolCall);
|
|
3352
|
+
}
|
|
3353
|
+
}
|
|
3354
|
+
processExistingToolCall(index, toolCallDelta) {
|
|
3355
|
+
var _a2;
|
|
3356
|
+
const toolCall = this.toolCalls[index];
|
|
3357
|
+
if (toolCall.hasFinished) {
|
|
3358
|
+
return;
|
|
3359
|
+
}
|
|
3360
|
+
if (((_a2 = toolCallDelta.function) == null ? void 0 : _a2.arguments) != null) {
|
|
3361
|
+
toolCall.function.arguments += toolCallDelta.function.arguments;
|
|
3362
|
+
this.controller.enqueue({
|
|
3363
|
+
type: "tool-input-delta",
|
|
3364
|
+
id: toolCall.id,
|
|
3365
|
+
delta: toolCallDelta.function.arguments
|
|
3366
|
+
});
|
|
3367
|
+
}
|
|
3368
|
+
if (isParsableJson(toolCall.function.arguments)) {
|
|
3369
|
+
this.finishToolCall(toolCall);
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
finishToolCall(toolCall) {
|
|
3373
|
+
var _a2, _b2;
|
|
3374
|
+
this.controller.enqueue({
|
|
3375
|
+
type: "tool-input-end",
|
|
3376
|
+
id: toolCall.id
|
|
3377
|
+
});
|
|
3378
|
+
const providerMetadata = (_a2 = this.buildToolCallProviderMetadata) == null ? void 0 : _a2.call(
|
|
3379
|
+
this,
|
|
3380
|
+
toolCall.metadata
|
|
3381
|
+
);
|
|
3382
|
+
this.controller.enqueue({
|
|
3383
|
+
type: "tool-call",
|
|
3384
|
+
toolCallId: (_b2 = toolCall.id) != null ? _b2 : this._generateId(),
|
|
3385
|
+
toolName: toolCall.function.name,
|
|
3386
|
+
input: toolCall.function.arguments,
|
|
3387
|
+
...providerMetadata ? { providerMetadata } : {}
|
|
3388
|
+
});
|
|
3389
|
+
toolCall.hasFinished = true;
|
|
3390
|
+
}
|
|
3391
|
+
};
|
|
3392
|
+
|
|
2741
3393
|
// src/strip-file-extension.ts
|
|
2742
3394
|
function stripFileExtension(filename) {
|
|
2743
3395
|
const firstDotIndex = filename.indexOf(".");
|
|
@@ -2749,6 +3401,11 @@ function withoutTrailingSlash(url) {
|
|
|
2749
3401
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
2750
3402
|
}
|
|
2751
3403
|
|
|
3404
|
+
// src/types/executable-tool.ts
|
|
3405
|
+
function isExecutableTool(tool2) {
|
|
3406
|
+
return tool2 != null && typeof tool2.execute === "function";
|
|
3407
|
+
}
|
|
3408
|
+
|
|
2752
3409
|
// src/is-async-iterable.ts
|
|
2753
3410
|
function isAsyncIterable(obj) {
|
|
2754
3411
|
return obj != null && typeof obj[Symbol.asyncIterator] === "function";
|
|
@@ -2756,11 +3413,11 @@ function isAsyncIterable(obj) {
|
|
|
2756
3413
|
|
|
2757
3414
|
// src/types/execute-tool.ts
|
|
2758
3415
|
async function* executeTool({
|
|
2759
|
-
|
|
3416
|
+
tool: tool2,
|
|
2760
3417
|
input,
|
|
2761
3418
|
options
|
|
2762
3419
|
}) {
|
|
2763
|
-
const result = execute(input, options);
|
|
3420
|
+
const result = tool2.execute(input, options);
|
|
2764
3421
|
if (isAsyncIterable(result)) {
|
|
2765
3422
|
let lastOutput;
|
|
2766
3423
|
for await (const output of result) {
|
|
@@ -2774,19 +3431,27 @@ async function* executeTool({
|
|
|
2774
3431
|
}
|
|
2775
3432
|
|
|
2776
3433
|
// src/index.ts
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
3434
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
|
|
3435
|
+
import {
|
|
3436
|
+
EventSourceParserStream as EventSourceParserStream2
|
|
3437
|
+
} from "eventsource-parser/stream";
|
|
3438
|
+
export {
|
|
2780
3439
|
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
2781
3440
|
DelayedPromise,
|
|
2782
3441
|
DownloadError,
|
|
2783
|
-
EventSourceParserStream,
|
|
3442
|
+
EventSourceParserStream2 as EventSourceParserStream,
|
|
3443
|
+
StreamingToolCallTracker,
|
|
2784
3444
|
VERSION,
|
|
3445
|
+
WORKFLOW_DESERIALIZE,
|
|
3446
|
+
WORKFLOW_SERIALIZE,
|
|
3447
|
+
asArray,
|
|
2785
3448
|
asSchema,
|
|
3449
|
+
cancelResponseBody,
|
|
2786
3450
|
combineHeaders,
|
|
2787
3451
|
convertAsyncIteratorToReadableStream,
|
|
2788
3452
|
convertBase64ToUint8Array,
|
|
2789
3453
|
convertImageModelFileToDataUri,
|
|
3454
|
+
convertInlineFileDataToUint8Array,
|
|
2790
3455
|
convertToBase64,
|
|
2791
3456
|
convertToFormData,
|
|
2792
3457
|
convertUint8ArrayToBase64,
|
|
@@ -2795,29 +3460,44 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2795
3460
|
createIdGenerator,
|
|
2796
3461
|
createJsonErrorResponseHandler,
|
|
2797
3462
|
createJsonResponseHandler,
|
|
2798
|
-
|
|
2799
|
-
|
|
3463
|
+
createProviderDefinedToolFactory,
|
|
3464
|
+
createProviderDefinedToolFactoryWithOutputSchema,
|
|
3465
|
+
createProviderExecutedToolFactory,
|
|
2800
3466
|
createStatusCodeErrorResponseHandler,
|
|
2801
3467
|
createToolNameMapping,
|
|
2802
3468
|
delay,
|
|
3469
|
+
detectMediaType,
|
|
2803
3470
|
downloadBlob,
|
|
2804
3471
|
dynamicTool,
|
|
2805
3472
|
executeTool,
|
|
3473
|
+
extractLines,
|
|
2806
3474
|
extractResponseHeaders,
|
|
3475
|
+
fetchWithValidatedRedirects,
|
|
3476
|
+
filterNullable,
|
|
2807
3477
|
generateId,
|
|
2808
3478
|
getErrorMessage,
|
|
2809
3479
|
getFromApi,
|
|
2810
3480
|
getRuntimeEnvironmentUserAgent,
|
|
3481
|
+
getTopLevelMediaType,
|
|
2811
3482
|
injectJsonInstructionIntoMessages,
|
|
2812
3483
|
isAbortError,
|
|
3484
|
+
isBrowserRuntime,
|
|
3485
|
+
isBuffer,
|
|
3486
|
+
isCustomReasoning,
|
|
3487
|
+
isExecutableTool,
|
|
3488
|
+
isFullMediaType,
|
|
2813
3489
|
isNonNullable,
|
|
2814
3490
|
isParsableJson,
|
|
3491
|
+
isProviderReference,
|
|
3492
|
+
isSameOrigin,
|
|
2815
3493
|
isUrlSupported,
|
|
2816
3494
|
jsonSchema,
|
|
2817
3495
|
lazySchema,
|
|
2818
3496
|
loadApiKey,
|
|
2819
3497
|
loadOptionalSetting,
|
|
2820
3498
|
loadSetting,
|
|
3499
|
+
mapReasoningToProviderBudget,
|
|
3500
|
+
mapReasoningToProviderEffort,
|
|
2821
3501
|
mediaTypeToExtension,
|
|
2822
3502
|
normalizeHeaders,
|
|
2823
3503
|
parseJSON,
|
|
@@ -2829,8 +3509,11 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2829
3509
|
readResponseWithSizeLimit,
|
|
2830
3510
|
removeUndefinedEntries,
|
|
2831
3511
|
resolve,
|
|
3512
|
+
resolveFullMediaType,
|
|
3513
|
+
resolveProviderReference,
|
|
2832
3514
|
safeParseJSON,
|
|
2833
3515
|
safeValidateTypes,
|
|
3516
|
+
serializeModelOptions,
|
|
2834
3517
|
stripFileExtension,
|
|
2835
3518
|
tool,
|
|
2836
3519
|
validateDownloadUrl,
|
|
@@ -2838,5 +3521,5 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2838
3521
|
withUserAgentSuffix,
|
|
2839
3522
|
withoutTrailingSlash,
|
|
2840
3523
|
zodSchema
|
|
2841
|
-
}
|
|
3524
|
+
};
|
|
2842
3525
|
//# sourceMappingURL=index.js.map
|