@ai-sdk/provider-utils 3.0.20 → 3.0.21
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 +12 -2
- package/dist/index.d.mts +49 -2
- package/dist/index.d.ts +49 -2
- package/dist/index.js +188 -102
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +137 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,8 +6,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __export = (target, all) => {
|
|
9
|
-
for (var
|
|
10
|
-
__defProp(target,
|
|
9
|
+
for (var name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
11
|
};
|
|
12
12
|
var __copyProps = (to, from, except, desc) => {
|
|
13
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -31,7 +31,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var src_exports = {};
|
|
33
33
|
__export(src_exports, {
|
|
34
|
+
DEFAULT_MAX_DOWNLOAD_SIZE: () => DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
34
35
|
DelayedPromise: () => DelayedPromise,
|
|
36
|
+
DownloadError: () => DownloadError,
|
|
35
37
|
EventSourceParserStream: () => import_stream2.EventSourceParserStream,
|
|
36
38
|
VERSION: () => VERSION,
|
|
37
39
|
asSchema: () => asSchema,
|
|
@@ -77,6 +79,7 @@ __export(src_exports, {
|
|
|
77
79
|
postFormDataToApi: () => postFormDataToApi,
|
|
78
80
|
postJsonToApi: () => postJsonToApi,
|
|
79
81
|
postToApi: () => postToApi,
|
|
82
|
+
readResponseWithSizeLimit: () => readResponseWithSizeLimit,
|
|
80
83
|
removeUndefinedEntries: () => removeUndefinedEntries,
|
|
81
84
|
resolve: () => resolve,
|
|
82
85
|
safeParseJSON: () => safeParseJSON,
|
|
@@ -193,17 +196,17 @@ var DelayedPromise = class {
|
|
|
193
196
|
return this._promise;
|
|
194
197
|
}
|
|
195
198
|
resolve(value) {
|
|
196
|
-
var
|
|
199
|
+
var _a2;
|
|
197
200
|
this.status = { type: "resolved", value };
|
|
198
201
|
if (this._promise) {
|
|
199
|
-
(
|
|
202
|
+
(_a2 = this._resolve) == null ? void 0 : _a2.call(this, value);
|
|
200
203
|
}
|
|
201
204
|
}
|
|
202
205
|
reject(error) {
|
|
203
|
-
var
|
|
206
|
+
var _a2;
|
|
204
207
|
this.status = { type: "rejected", error };
|
|
205
208
|
if (this._promise) {
|
|
206
|
-
(
|
|
209
|
+
(_a2 = this._reject) == null ? void 0 : _a2.call(this, error);
|
|
207
210
|
}
|
|
208
211
|
}
|
|
209
212
|
isResolved() {
|
|
@@ -222,8 +225,88 @@ function extractResponseHeaders(response) {
|
|
|
222
225
|
return Object.fromEntries([...response.headers]);
|
|
223
226
|
}
|
|
224
227
|
|
|
225
|
-
// src/
|
|
228
|
+
// src/download-error.ts
|
|
226
229
|
var import_provider = require("@ai-sdk/provider");
|
|
230
|
+
var name = "AI_DownloadError";
|
|
231
|
+
var marker = `vercel.ai.error.${name}`;
|
|
232
|
+
var symbol = Symbol.for(marker);
|
|
233
|
+
var _a, _b;
|
|
234
|
+
var DownloadError = class extends (_b = import_provider.AISDKError, _a = symbol, _b) {
|
|
235
|
+
constructor({
|
|
236
|
+
url,
|
|
237
|
+
statusCode,
|
|
238
|
+
statusText,
|
|
239
|
+
cause,
|
|
240
|
+
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
|
241
|
+
}) {
|
|
242
|
+
super({ name, message, cause });
|
|
243
|
+
this[_a] = true;
|
|
244
|
+
this.url = url;
|
|
245
|
+
this.statusCode = statusCode;
|
|
246
|
+
this.statusText = statusText;
|
|
247
|
+
}
|
|
248
|
+
static isInstance(error) {
|
|
249
|
+
return import_provider.AISDKError.hasMarker(error, marker);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// src/read-response-with-size-limit.ts
|
|
254
|
+
var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
|
|
255
|
+
async function readResponseWithSizeLimit({
|
|
256
|
+
response,
|
|
257
|
+
url,
|
|
258
|
+
maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE
|
|
259
|
+
}) {
|
|
260
|
+
const contentLength = response.headers.get("content-length");
|
|
261
|
+
if (contentLength != null) {
|
|
262
|
+
const length = parseInt(contentLength, 10);
|
|
263
|
+
if (!isNaN(length) && length > maxBytes) {
|
|
264
|
+
throw new DownloadError({
|
|
265
|
+
url,
|
|
266
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const body = response.body;
|
|
271
|
+
if (body == null) {
|
|
272
|
+
return new Uint8Array(0);
|
|
273
|
+
}
|
|
274
|
+
const reader = body.getReader();
|
|
275
|
+
const chunks = [];
|
|
276
|
+
let totalBytes = 0;
|
|
277
|
+
try {
|
|
278
|
+
while (true) {
|
|
279
|
+
const { done, value } = await reader.read();
|
|
280
|
+
if (done) {
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
totalBytes += value.length;
|
|
284
|
+
if (totalBytes > maxBytes) {
|
|
285
|
+
throw new DownloadError({
|
|
286
|
+
url,
|
|
287
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
chunks.push(value);
|
|
291
|
+
}
|
|
292
|
+
} finally {
|
|
293
|
+
try {
|
|
294
|
+
await reader.cancel();
|
|
295
|
+
} finally {
|
|
296
|
+
reader.releaseLock();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const result = new Uint8Array(totalBytes);
|
|
300
|
+
let offset = 0;
|
|
301
|
+
for (const chunk of chunks) {
|
|
302
|
+
result.set(chunk, offset);
|
|
303
|
+
offset += chunk.length;
|
|
304
|
+
}
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/generate-id.ts
|
|
309
|
+
var import_provider2 = require("@ai-sdk/provider");
|
|
227
310
|
var createIdGenerator = ({
|
|
228
311
|
prefix,
|
|
229
312
|
size = 16,
|
|
@@ -242,7 +325,7 @@ var createIdGenerator = ({
|
|
|
242
325
|
return generator;
|
|
243
326
|
}
|
|
244
327
|
if (alphabet.includes(separator)) {
|
|
245
|
-
throw new
|
|
328
|
+
throw new import_provider2.InvalidArgumentError({
|
|
246
329
|
argument: "separator",
|
|
247
330
|
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
248
331
|
});
|
|
@@ -266,10 +349,10 @@ function getErrorMessage(error) {
|
|
|
266
349
|
}
|
|
267
350
|
|
|
268
351
|
// src/get-from-api.ts
|
|
269
|
-
var
|
|
352
|
+
var import_provider4 = require("@ai-sdk/provider");
|
|
270
353
|
|
|
271
354
|
// src/handle-fetch-error.ts
|
|
272
|
-
var
|
|
355
|
+
var import_provider3 = require("@ai-sdk/provider");
|
|
273
356
|
|
|
274
357
|
// src/is-abort-error.ts
|
|
275
358
|
function isAbortError(error) {
|
|
@@ -290,7 +373,7 @@ function handleFetchError({
|
|
|
290
373
|
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES.includes(error.message.toLowerCase())) {
|
|
291
374
|
const cause = error.cause;
|
|
292
375
|
if (cause != null) {
|
|
293
|
-
return new
|
|
376
|
+
return new import_provider3.APICallError({
|
|
294
377
|
message: `Cannot connect to API: ${cause.message}`,
|
|
295
378
|
cause,
|
|
296
379
|
url,
|
|
@@ -305,14 +388,14 @@ function handleFetchError({
|
|
|
305
388
|
|
|
306
389
|
// src/get-runtime-environment-user-agent.ts
|
|
307
390
|
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
308
|
-
var
|
|
391
|
+
var _a2, _b2, _c;
|
|
309
392
|
if (globalThisAny.window) {
|
|
310
393
|
return `runtime/browser`;
|
|
311
394
|
}
|
|
312
|
-
if ((
|
|
395
|
+
if ((_a2 = globalThisAny.navigator) == null ? void 0 : _a2.userAgent) {
|
|
313
396
|
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
314
397
|
}
|
|
315
|
-
if ((_c = (
|
|
398
|
+
if ((_c = (_b2 = globalThisAny.process) == null ? void 0 : _b2.versions) == null ? void 0 : _c.node) {
|
|
316
399
|
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
317
400
|
}
|
|
318
401
|
if (globalThisAny.EdgeRuntime) {
|
|
@@ -356,7 +439,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
356
439
|
}
|
|
357
440
|
|
|
358
441
|
// src/version.ts
|
|
359
|
-
var VERSION = true ? "3.0.
|
|
442
|
+
var VERSION = true ? "3.0.21" : "0.0.0-test";
|
|
360
443
|
|
|
361
444
|
// src/get-from-api.ts
|
|
362
445
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -388,10 +471,10 @@ var getFromApi = async ({
|
|
|
388
471
|
requestBodyValues: {}
|
|
389
472
|
});
|
|
390
473
|
} catch (error) {
|
|
391
|
-
if (isAbortError(error) ||
|
|
474
|
+
if (isAbortError(error) || import_provider4.APICallError.isInstance(error)) {
|
|
392
475
|
throw error;
|
|
393
476
|
}
|
|
394
|
-
throw new
|
|
477
|
+
throw new import_provider4.APICallError({
|
|
395
478
|
message: "Failed to process error response",
|
|
396
479
|
cause: error,
|
|
397
480
|
statusCode: response.status,
|
|
@@ -410,11 +493,11 @@ var getFromApi = async ({
|
|
|
410
493
|
});
|
|
411
494
|
} catch (error) {
|
|
412
495
|
if (error instanceof Error) {
|
|
413
|
-
if (isAbortError(error) ||
|
|
496
|
+
if (isAbortError(error) || import_provider4.APICallError.isInstance(error)) {
|
|
414
497
|
throw error;
|
|
415
498
|
}
|
|
416
499
|
}
|
|
417
|
-
throw new
|
|
500
|
+
throw new import_provider4.APICallError({
|
|
418
501
|
message: "Failed to process successful response",
|
|
419
502
|
cause: error,
|
|
420
503
|
statusCode: response.status,
|
|
@@ -453,8 +536,8 @@ function injectJsonInstructionIntoMessages({
|
|
|
453
536
|
schemaPrefix,
|
|
454
537
|
schemaSuffix
|
|
455
538
|
}) {
|
|
456
|
-
var
|
|
457
|
-
const systemMessage = ((
|
|
539
|
+
var _a2, _b2;
|
|
540
|
+
const systemMessage = ((_a2 = messages[0]) == null ? void 0 : _a2.role) === "system" ? { ...messages[0] } : { role: "system", content: "" };
|
|
458
541
|
systemMessage.content = injectJsonInstruction({
|
|
459
542
|
prompt: systemMessage.content,
|
|
460
543
|
schema,
|
|
@@ -463,7 +546,7 @@ function injectJsonInstructionIntoMessages({
|
|
|
463
546
|
});
|
|
464
547
|
return [
|
|
465
548
|
systemMessage,
|
|
466
|
-
...((
|
|
549
|
+
...((_b2 = messages[0]) == null ? void 0 : _b2.role) === "system" ? messages.slice(1) : messages
|
|
467
550
|
];
|
|
468
551
|
}
|
|
469
552
|
|
|
@@ -482,7 +565,7 @@ function isUrlSupported({
|
|
|
482
565
|
}
|
|
483
566
|
|
|
484
567
|
// src/load-api-key.ts
|
|
485
|
-
var
|
|
568
|
+
var import_provider5 = require("@ai-sdk/provider");
|
|
486
569
|
function loadApiKey({
|
|
487
570
|
apiKey,
|
|
488
571
|
environmentVariableName,
|
|
@@ -493,23 +576,23 @@ function loadApiKey({
|
|
|
493
576
|
return apiKey;
|
|
494
577
|
}
|
|
495
578
|
if (apiKey != null) {
|
|
496
|
-
throw new
|
|
579
|
+
throw new import_provider5.LoadAPIKeyError({
|
|
497
580
|
message: `${description} API key must be a string.`
|
|
498
581
|
});
|
|
499
582
|
}
|
|
500
583
|
if (typeof process === "undefined") {
|
|
501
|
-
throw new
|
|
584
|
+
throw new import_provider5.LoadAPIKeyError({
|
|
502
585
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
|
|
503
586
|
});
|
|
504
587
|
}
|
|
505
588
|
apiKey = process.env[environmentVariableName];
|
|
506
589
|
if (apiKey == null) {
|
|
507
|
-
throw new
|
|
590
|
+
throw new import_provider5.LoadAPIKeyError({
|
|
508
591
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
509
592
|
});
|
|
510
593
|
}
|
|
511
594
|
if (typeof apiKey !== "string") {
|
|
512
|
-
throw new
|
|
595
|
+
throw new import_provider5.LoadAPIKeyError({
|
|
513
596
|
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
514
597
|
});
|
|
515
598
|
}
|
|
@@ -535,7 +618,7 @@ function loadOptionalSetting({
|
|
|
535
618
|
}
|
|
536
619
|
|
|
537
620
|
// src/load-setting.ts
|
|
538
|
-
var
|
|
621
|
+
var import_provider6 = require("@ai-sdk/provider");
|
|
539
622
|
function loadSetting({
|
|
540
623
|
settingValue,
|
|
541
624
|
environmentVariableName,
|
|
@@ -546,23 +629,23 @@ function loadSetting({
|
|
|
546
629
|
return settingValue;
|
|
547
630
|
}
|
|
548
631
|
if (settingValue != null) {
|
|
549
|
-
throw new
|
|
632
|
+
throw new import_provider6.LoadSettingError({
|
|
550
633
|
message: `${description} setting must be a string.`
|
|
551
634
|
});
|
|
552
635
|
}
|
|
553
636
|
if (typeof process === "undefined") {
|
|
554
|
-
throw new
|
|
637
|
+
throw new import_provider6.LoadSettingError({
|
|
555
638
|
message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables is not supported in this environment.`
|
|
556
639
|
});
|
|
557
640
|
}
|
|
558
641
|
settingValue = process.env[environmentVariableName];
|
|
559
642
|
if (settingValue == null) {
|
|
560
|
-
throw new
|
|
643
|
+
throw new import_provider6.LoadSettingError({
|
|
561
644
|
message: `${description} setting is missing. Pass it using the '${settingName}' parameter or the ${environmentVariableName} environment variable.`
|
|
562
645
|
});
|
|
563
646
|
}
|
|
564
647
|
if (typeof settingValue !== "string") {
|
|
565
|
-
throw new
|
|
648
|
+
throw new import_provider6.LoadSettingError({
|
|
566
649
|
message: `${description} setting must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
567
650
|
});
|
|
568
651
|
}
|
|
@@ -571,19 +654,19 @@ function loadSetting({
|
|
|
571
654
|
|
|
572
655
|
// src/media-type-to-extension.ts
|
|
573
656
|
function mediaTypeToExtension(mediaType) {
|
|
574
|
-
var
|
|
657
|
+
var _a2;
|
|
575
658
|
const [_type, subtype = ""] = mediaType.toLowerCase().split("/");
|
|
576
|
-
return (
|
|
659
|
+
return (_a2 = {
|
|
577
660
|
mpeg: "mp3",
|
|
578
661
|
"x-wav": "wav",
|
|
579
662
|
opus: "ogg",
|
|
580
663
|
mp4: "m4a",
|
|
581
664
|
"x-m4a": "m4a"
|
|
582
|
-
}[subtype]) != null ?
|
|
665
|
+
}[subtype]) != null ? _a2 : subtype;
|
|
583
666
|
}
|
|
584
667
|
|
|
585
668
|
// src/parse-json.ts
|
|
586
|
-
var
|
|
669
|
+
var import_provider9 = require("@ai-sdk/provider");
|
|
587
670
|
|
|
588
671
|
// src/secure-json-parse.ts
|
|
589
672
|
var suspectProtoRx = /"__proto__"\s*:/;
|
|
@@ -635,10 +718,10 @@ function secureJsonParse(text) {
|
|
|
635
718
|
}
|
|
636
719
|
|
|
637
720
|
// src/validate-types.ts
|
|
638
|
-
var
|
|
721
|
+
var import_provider8 = require("@ai-sdk/provider");
|
|
639
722
|
|
|
640
723
|
// src/validator.ts
|
|
641
|
-
var
|
|
724
|
+
var import_provider7 = require("@ai-sdk/provider");
|
|
642
725
|
var validatorSymbol = Symbol.for("vercel.ai.validator");
|
|
643
726
|
function validator(validate) {
|
|
644
727
|
return { [validatorSymbol]: true, validate };
|
|
@@ -663,7 +746,7 @@ function standardSchemaValidator(standardSchema) {
|
|
|
663
746
|
const result = await standardSchema["~standard"].validate(value);
|
|
664
747
|
return result.issues == null ? { success: true, value: result.value } : {
|
|
665
748
|
success: false,
|
|
666
|
-
error: new
|
|
749
|
+
error: new import_provider7.TypeValidationError({
|
|
667
750
|
value,
|
|
668
751
|
cause: result.issues
|
|
669
752
|
})
|
|
@@ -678,7 +761,7 @@ async function validateTypes({
|
|
|
678
761
|
}) {
|
|
679
762
|
const result = await safeValidateTypes({ value, schema });
|
|
680
763
|
if (!result.success) {
|
|
681
|
-
throw
|
|
764
|
+
throw import_provider8.TypeValidationError.wrap({ value, cause: result.error });
|
|
682
765
|
}
|
|
683
766
|
return result.value;
|
|
684
767
|
}
|
|
@@ -697,13 +780,13 @@ async function safeValidateTypes({
|
|
|
697
780
|
}
|
|
698
781
|
return {
|
|
699
782
|
success: false,
|
|
700
|
-
error:
|
|
783
|
+
error: import_provider8.TypeValidationError.wrap({ value, cause: result.error }),
|
|
701
784
|
rawValue: value
|
|
702
785
|
};
|
|
703
786
|
} catch (error) {
|
|
704
787
|
return {
|
|
705
788
|
success: false,
|
|
706
|
-
error:
|
|
789
|
+
error: import_provider8.TypeValidationError.wrap({ value, cause: error }),
|
|
707
790
|
rawValue: value
|
|
708
791
|
};
|
|
709
792
|
}
|
|
@@ -721,10 +804,10 @@ async function parseJSON({
|
|
|
721
804
|
}
|
|
722
805
|
return validateTypes({ value, schema });
|
|
723
806
|
} catch (error) {
|
|
724
|
-
if (
|
|
807
|
+
if (import_provider9.JSONParseError.isInstance(error) || import_provider9.TypeValidationError.isInstance(error)) {
|
|
725
808
|
throw error;
|
|
726
809
|
}
|
|
727
|
-
throw new
|
|
810
|
+
throw new import_provider9.JSONParseError({ text, cause: error });
|
|
728
811
|
}
|
|
729
812
|
}
|
|
730
813
|
async function safeParseJSON({
|
|
@@ -740,7 +823,7 @@ async function safeParseJSON({
|
|
|
740
823
|
} catch (error) {
|
|
741
824
|
return {
|
|
742
825
|
success: false,
|
|
743
|
-
error:
|
|
826
|
+
error: import_provider9.JSONParseError.isInstance(error) ? error : new import_provider9.JSONParseError({ text, cause: error }),
|
|
744
827
|
rawValue: void 0
|
|
745
828
|
};
|
|
746
829
|
}
|
|
@@ -773,7 +856,7 @@ function parseJsonEventStream({
|
|
|
773
856
|
}
|
|
774
857
|
|
|
775
858
|
// src/parse-provider-options.ts
|
|
776
|
-
var
|
|
859
|
+
var import_provider10 = require("@ai-sdk/provider");
|
|
777
860
|
async function parseProviderOptions({
|
|
778
861
|
provider,
|
|
779
862
|
providerOptions,
|
|
@@ -787,7 +870,7 @@ async function parseProviderOptions({
|
|
|
787
870
|
schema
|
|
788
871
|
});
|
|
789
872
|
if (!parsedProviderOptions.success) {
|
|
790
|
-
throw new
|
|
873
|
+
throw new import_provider10.InvalidArgumentError({
|
|
791
874
|
argument: "providerOptions",
|
|
792
875
|
message: `invalid ${provider} provider options`,
|
|
793
876
|
cause: parsedProviderOptions.error
|
|
@@ -797,7 +880,7 @@ async function parseProviderOptions({
|
|
|
797
880
|
}
|
|
798
881
|
|
|
799
882
|
// src/post-to-api.ts
|
|
800
|
-
var
|
|
883
|
+
var import_provider11 = require("@ai-sdk/provider");
|
|
801
884
|
var getOriginalFetch2 = () => globalThis.fetch;
|
|
802
885
|
var postJsonToApi = async ({
|
|
803
886
|
url,
|
|
@@ -872,10 +955,10 @@ var postToApi = async ({
|
|
|
872
955
|
requestBodyValues: body.values
|
|
873
956
|
});
|
|
874
957
|
} catch (error) {
|
|
875
|
-
if (isAbortError(error) ||
|
|
958
|
+
if (isAbortError(error) || import_provider11.APICallError.isInstance(error)) {
|
|
876
959
|
throw error;
|
|
877
960
|
}
|
|
878
|
-
throw new
|
|
961
|
+
throw new import_provider11.APICallError({
|
|
879
962
|
message: "Failed to process error response",
|
|
880
963
|
cause: error,
|
|
881
964
|
statusCode: response.status,
|
|
@@ -894,11 +977,11 @@ var postToApi = async ({
|
|
|
894
977
|
});
|
|
895
978
|
} catch (error) {
|
|
896
979
|
if (error instanceof Error) {
|
|
897
|
-
if (isAbortError(error) ||
|
|
980
|
+
if (isAbortError(error) || import_provider11.APICallError.isInstance(error)) {
|
|
898
981
|
throw error;
|
|
899
982
|
}
|
|
900
983
|
}
|
|
901
|
-
throw new
|
|
984
|
+
throw new import_provider11.APICallError({
|
|
902
985
|
message: "Failed to process successful response",
|
|
903
986
|
cause: error,
|
|
904
987
|
statusCode: response.status,
|
|
@@ -923,7 +1006,7 @@ function dynamicTool(tool2) {
|
|
|
923
1006
|
// src/provider-defined-tool-factory.ts
|
|
924
1007
|
function createProviderDefinedToolFactory({
|
|
925
1008
|
id,
|
|
926
|
-
name,
|
|
1009
|
+
name: name2,
|
|
927
1010
|
inputSchema
|
|
928
1011
|
}) {
|
|
929
1012
|
return ({
|
|
@@ -937,7 +1020,7 @@ function createProviderDefinedToolFactory({
|
|
|
937
1020
|
}) => tool({
|
|
938
1021
|
type: "provider-defined",
|
|
939
1022
|
id,
|
|
940
|
-
name,
|
|
1023
|
+
name: name2,
|
|
941
1024
|
args,
|
|
942
1025
|
inputSchema,
|
|
943
1026
|
outputSchema,
|
|
@@ -950,7 +1033,7 @@ function createProviderDefinedToolFactory({
|
|
|
950
1033
|
}
|
|
951
1034
|
function createProviderDefinedToolFactoryWithOutputSchema({
|
|
952
1035
|
id,
|
|
953
|
-
name,
|
|
1036
|
+
name: name2,
|
|
954
1037
|
inputSchema,
|
|
955
1038
|
outputSchema
|
|
956
1039
|
}) {
|
|
@@ -964,7 +1047,7 @@ function createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
964
1047
|
}) => tool({
|
|
965
1048
|
type: "provider-defined",
|
|
966
1049
|
id,
|
|
967
|
-
name,
|
|
1050
|
+
name: name2,
|
|
968
1051
|
args,
|
|
969
1052
|
inputSchema,
|
|
970
1053
|
outputSchema,
|
|
@@ -992,7 +1075,7 @@ async function resolve(value) {
|
|
|
992
1075
|
}
|
|
993
1076
|
|
|
994
1077
|
// src/response-handler.ts
|
|
995
|
-
var
|
|
1078
|
+
var import_provider12 = require("@ai-sdk/provider");
|
|
996
1079
|
var createJsonErrorResponseHandler = ({
|
|
997
1080
|
errorSchema,
|
|
998
1081
|
errorToMessage,
|
|
@@ -1003,7 +1086,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
1003
1086
|
if (responseBody.trim() === "") {
|
|
1004
1087
|
return {
|
|
1005
1088
|
responseHeaders,
|
|
1006
|
-
value: new
|
|
1089
|
+
value: new import_provider12.APICallError({
|
|
1007
1090
|
message: response.statusText,
|
|
1008
1091
|
url,
|
|
1009
1092
|
requestBodyValues,
|
|
@@ -1021,7 +1104,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
1021
1104
|
});
|
|
1022
1105
|
return {
|
|
1023
1106
|
responseHeaders,
|
|
1024
|
-
value: new
|
|
1107
|
+
value: new import_provider12.APICallError({
|
|
1025
1108
|
message: errorToMessage(parsedError),
|
|
1026
1109
|
url,
|
|
1027
1110
|
requestBodyValues,
|
|
@@ -1035,7 +1118,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
1035
1118
|
} catch (parseError) {
|
|
1036
1119
|
return {
|
|
1037
1120
|
responseHeaders,
|
|
1038
|
-
value: new
|
|
1121
|
+
value: new import_provider12.APICallError({
|
|
1039
1122
|
message: response.statusText,
|
|
1040
1123
|
url,
|
|
1041
1124
|
requestBodyValues,
|
|
@@ -1050,7 +1133,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
1050
1133
|
var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
1051
1134
|
const responseHeaders = extractResponseHeaders(response);
|
|
1052
1135
|
if (response.body == null) {
|
|
1053
|
-
throw new
|
|
1136
|
+
throw new import_provider12.EmptyResponseBodyError({});
|
|
1054
1137
|
}
|
|
1055
1138
|
return {
|
|
1056
1139
|
responseHeaders,
|
|
@@ -1063,7 +1146,7 @@ var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) =>
|
|
|
1063
1146
|
var createJsonStreamResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
1064
1147
|
const responseHeaders = extractResponseHeaders(response);
|
|
1065
1148
|
if (response.body == null) {
|
|
1066
|
-
throw new
|
|
1149
|
+
throw new import_provider12.EmptyResponseBodyError({});
|
|
1067
1150
|
}
|
|
1068
1151
|
let buffer = "";
|
|
1069
1152
|
return {
|
|
@@ -1095,7 +1178,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
1095
1178
|
});
|
|
1096
1179
|
const responseHeaders = extractResponseHeaders(response);
|
|
1097
1180
|
if (!parsedResult.success) {
|
|
1098
|
-
throw new
|
|
1181
|
+
throw new import_provider12.APICallError({
|
|
1099
1182
|
message: "Invalid JSON response",
|
|
1100
1183
|
cause: parsedResult.error,
|
|
1101
1184
|
statusCode: response.status,
|
|
@@ -1114,7 +1197,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
1114
1197
|
var createBinaryResponseHandler = () => async ({ response, url, requestBodyValues }) => {
|
|
1115
1198
|
const responseHeaders = extractResponseHeaders(response);
|
|
1116
1199
|
if (!response.body) {
|
|
1117
|
-
throw new
|
|
1200
|
+
throw new import_provider12.APICallError({
|
|
1118
1201
|
message: "Response body is empty",
|
|
1119
1202
|
url,
|
|
1120
1203
|
requestBodyValues,
|
|
@@ -1130,7 +1213,7 @@ var createBinaryResponseHandler = () => async ({ response, url, requestBodyValue
|
|
|
1130
1213
|
value: new Uint8Array(buffer)
|
|
1131
1214
|
};
|
|
1132
1215
|
} catch (error) {
|
|
1133
|
-
throw new
|
|
1216
|
+
throw new import_provider12.APICallError({
|
|
1134
1217
|
message: "Failed to read response as array buffer",
|
|
1135
1218
|
url,
|
|
1136
1219
|
requestBodyValues,
|
|
@@ -1146,7 +1229,7 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
|
|
|
1146
1229
|
const responseBody = await response.text();
|
|
1147
1230
|
return {
|
|
1148
1231
|
responseHeaders,
|
|
1149
|
-
value: new
|
|
1232
|
+
value: new import_provider12.APICallError({
|
|
1150
1233
|
message: response.statusText,
|
|
1151
1234
|
url,
|
|
1152
1235
|
requestBodyValues,
|
|
@@ -1240,11 +1323,11 @@ function parseAnyDef() {
|
|
|
1240
1323
|
// src/zod-to-json-schema/parsers/array.ts
|
|
1241
1324
|
var import_v3 = require("zod/v3");
|
|
1242
1325
|
function parseArrayDef(def, refs) {
|
|
1243
|
-
var
|
|
1326
|
+
var _a2, _b2, _c;
|
|
1244
1327
|
const res = {
|
|
1245
1328
|
type: "array"
|
|
1246
1329
|
};
|
|
1247
|
-
if (((
|
|
1330
|
+
if (((_a2 = def.type) == null ? void 0 : _a2._def) && ((_c = (_b2 = def.type) == null ? void 0 : _b2._def) == null ? void 0 : _c.typeName) !== import_v3.ZodFirstPartyTypeKind.ZodAny) {
|
|
1248
1331
|
res.items = parseDef(def.type._def, {
|
|
1249
1332
|
...refs,
|
|
1250
1333
|
currentPath: [...refs.currentPath, "items"]
|
|
@@ -1635,8 +1718,8 @@ function escapeNonAlphaNumeric(source) {
|
|
|
1635
1718
|
return result;
|
|
1636
1719
|
}
|
|
1637
1720
|
function addFormat(schema, value, message, refs) {
|
|
1638
|
-
var
|
|
1639
|
-
if (schema.format || ((
|
|
1721
|
+
var _a2;
|
|
1722
|
+
if (schema.format || ((_a2 = schema.anyOf) == null ? void 0 : _a2.some((x) => x.format))) {
|
|
1640
1723
|
if (!schema.anyOf) {
|
|
1641
1724
|
schema.anyOf = [];
|
|
1642
1725
|
}
|
|
@@ -1655,8 +1738,8 @@ function addFormat(schema, value, message, refs) {
|
|
|
1655
1738
|
}
|
|
1656
1739
|
}
|
|
1657
1740
|
function addPattern(schema, regex, message, refs) {
|
|
1658
|
-
var
|
|
1659
|
-
if (schema.pattern || ((
|
|
1741
|
+
var _a2;
|
|
1742
|
+
if (schema.pattern || ((_a2 = schema.allOf) == null ? void 0 : _a2.some((x) => x.pattern))) {
|
|
1660
1743
|
if (!schema.allOf) {
|
|
1661
1744
|
schema.allOf = [];
|
|
1662
1745
|
}
|
|
@@ -1675,7 +1758,7 @@ function addPattern(schema, regex, message, refs) {
|
|
|
1675
1758
|
}
|
|
1676
1759
|
}
|
|
1677
1760
|
function stringifyRegExpWithFlags(regex, refs) {
|
|
1678
|
-
var
|
|
1761
|
+
var _a2;
|
|
1679
1762
|
if (!refs.applyRegexFlags || !regex.flags) {
|
|
1680
1763
|
return regex.source;
|
|
1681
1764
|
}
|
|
@@ -1705,7 +1788,7 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
1705
1788
|
pattern += source[i];
|
|
1706
1789
|
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
1707
1790
|
inCharRange = false;
|
|
1708
|
-
} else if (source[i + 1] === "-" && ((
|
|
1791
|
+
} else if (source[i + 1] === "-" && ((_a2 = source[i + 2]) == null ? void 0 : _a2.match(/[a-z]/))) {
|
|
1709
1792
|
pattern += source[i];
|
|
1710
1793
|
inCharRange = true;
|
|
1711
1794
|
} else {
|
|
@@ -1759,15 +1842,15 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
1759
1842
|
|
|
1760
1843
|
// src/zod-to-json-schema/parsers/record.ts
|
|
1761
1844
|
function parseRecordDef(def, refs) {
|
|
1762
|
-
var
|
|
1845
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
1763
1846
|
const schema = {
|
|
1764
1847
|
type: "object",
|
|
1765
|
-
additionalProperties: (
|
|
1848
|
+
additionalProperties: (_a2 = parseDef(def.valueType._def, {
|
|
1766
1849
|
...refs,
|
|
1767
1850
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1768
|
-
})) != null ?
|
|
1851
|
+
})) != null ? _a2 : refs.allowedAdditionalProperties
|
|
1769
1852
|
};
|
|
1770
|
-
if (((
|
|
1853
|
+
if (((_b2 = def.keyType) == null ? void 0 : _b2._def.typeName) === import_v32.ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1771
1854
|
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
1772
1855
|
return {
|
|
1773
1856
|
...schema,
|
|
@@ -2040,8 +2123,8 @@ function safeIsOptional(schema) {
|
|
|
2040
2123
|
|
|
2041
2124
|
// src/zod-to-json-schema/parsers/optional.ts
|
|
2042
2125
|
var parseOptionalDef = (def, refs) => {
|
|
2043
|
-
var
|
|
2044
|
-
if (refs.currentPath.toString() === ((
|
|
2126
|
+
var _a2;
|
|
2127
|
+
if (refs.currentPath.toString() === ((_a2 = refs.propertyPath) == null ? void 0 : _a2.toString())) {
|
|
2045
2128
|
return parseDef(def.innerType._def, refs);
|
|
2046
2129
|
}
|
|
2047
2130
|
const innerSchema = parseDef(def.innerType._def, {
|
|
@@ -2229,10 +2312,10 @@ var selectParser = (def, typeName, refs) => {
|
|
|
2229
2312
|
|
|
2230
2313
|
// src/zod-to-json-schema/parse-def.ts
|
|
2231
2314
|
function parseDef(def, refs, forceResolution = false) {
|
|
2232
|
-
var
|
|
2315
|
+
var _a2;
|
|
2233
2316
|
const seenItem = refs.seen.get(def);
|
|
2234
2317
|
if (refs.override) {
|
|
2235
|
-
const overrideResult = (
|
|
2318
|
+
const overrideResult = (_a2 = refs.override) == null ? void 0 : _a2.call(
|
|
2236
2319
|
refs,
|
|
2237
2320
|
def,
|
|
2238
2321
|
refs,
|
|
@@ -2300,11 +2383,11 @@ var getRefs = (options) => {
|
|
|
2300
2383
|
currentPath,
|
|
2301
2384
|
propertyPath: void 0,
|
|
2302
2385
|
seen: new Map(
|
|
2303
|
-
Object.entries(_options.definitions).map(([
|
|
2386
|
+
Object.entries(_options.definitions).map(([name2, def]) => [
|
|
2304
2387
|
def._def,
|
|
2305
2388
|
{
|
|
2306
2389
|
def: def._def,
|
|
2307
|
-
path: [..._options.basePath, _options.definitionPath,
|
|
2390
|
+
path: [..._options.basePath, _options.definitionPath, name2],
|
|
2308
2391
|
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
2309
2392
|
jsonSchema: void 0
|
|
2310
2393
|
}
|
|
@@ -2315,50 +2398,50 @@ var getRefs = (options) => {
|
|
|
2315
2398
|
|
|
2316
2399
|
// src/zod-to-json-schema/zod-to-json-schema.ts
|
|
2317
2400
|
var zodToJsonSchema = (schema, options) => {
|
|
2318
|
-
var
|
|
2401
|
+
var _a2;
|
|
2319
2402
|
const refs = getRefs(options);
|
|
2320
2403
|
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
2321
|
-
(acc, [
|
|
2322
|
-
var
|
|
2404
|
+
(acc, [name3, schema2]) => {
|
|
2405
|
+
var _a3;
|
|
2323
2406
|
return {
|
|
2324
2407
|
...acc,
|
|
2325
|
-
[
|
|
2408
|
+
[name3]: (_a3 = parseDef(
|
|
2326
2409
|
schema2._def,
|
|
2327
2410
|
{
|
|
2328
2411
|
...refs,
|
|
2329
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
2412
|
+
currentPath: [...refs.basePath, refs.definitionPath, name3]
|
|
2330
2413
|
},
|
|
2331
2414
|
true
|
|
2332
|
-
)) != null ?
|
|
2415
|
+
)) != null ? _a3 : parseAnyDef()
|
|
2333
2416
|
};
|
|
2334
2417
|
},
|
|
2335
2418
|
{}
|
|
2336
2419
|
) : void 0;
|
|
2337
|
-
const
|
|
2338
|
-
const main = (
|
|
2420
|
+
const name2 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
2421
|
+
const main = (_a2 = parseDef(
|
|
2339
2422
|
schema._def,
|
|
2340
|
-
|
|
2423
|
+
name2 === void 0 ? refs : {
|
|
2341
2424
|
...refs,
|
|
2342
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
2425
|
+
currentPath: [...refs.basePath, refs.definitionPath, name2]
|
|
2343
2426
|
},
|
|
2344
2427
|
false
|
|
2345
|
-
)) != null ?
|
|
2428
|
+
)) != null ? _a2 : parseAnyDef();
|
|
2346
2429
|
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
2347
2430
|
if (title !== void 0) {
|
|
2348
2431
|
main.title = title;
|
|
2349
2432
|
}
|
|
2350
|
-
const combined =
|
|
2433
|
+
const combined = name2 === void 0 ? definitions ? {
|
|
2351
2434
|
...main,
|
|
2352
2435
|
[refs.definitionPath]: definitions
|
|
2353
2436
|
} : main : {
|
|
2354
2437
|
$ref: [
|
|
2355
2438
|
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
2356
2439
|
refs.definitionPath,
|
|
2357
|
-
|
|
2440
|
+
name2
|
|
2358
2441
|
].join("/"),
|
|
2359
2442
|
[refs.definitionPath]: {
|
|
2360
2443
|
...definitions,
|
|
2361
|
-
[
|
|
2444
|
+
[name2]: main
|
|
2362
2445
|
}
|
|
2363
2446
|
};
|
|
2364
2447
|
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
@@ -2370,8 +2453,8 @@ var zod_to_json_schema_default = zodToJsonSchema;
|
|
|
2370
2453
|
|
|
2371
2454
|
// src/zod-schema.ts
|
|
2372
2455
|
function zod3Schema(zodSchema2, options) {
|
|
2373
|
-
var
|
|
2374
|
-
const useReferences = (
|
|
2456
|
+
var _a2;
|
|
2457
|
+
const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
|
|
2375
2458
|
return jsonSchema(
|
|
2376
2459
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
2377
2460
|
() => zod_to_json_schema_default(zodSchema2, {
|
|
@@ -2386,8 +2469,8 @@ function zod3Schema(zodSchema2, options) {
|
|
|
2386
2469
|
);
|
|
2387
2470
|
}
|
|
2388
2471
|
function zod4Schema(zodSchema2, options) {
|
|
2389
|
-
var
|
|
2390
|
-
const useReferences = (
|
|
2472
|
+
var _a2;
|
|
2473
|
+
const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
|
|
2391
2474
|
return jsonSchema(
|
|
2392
2475
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
2393
2476
|
() => addAdditionalPropertiesToJsonSchema(
|
|
@@ -2506,7 +2589,9 @@ __reExport(src_exports, require("@standard-schema/spec"), module.exports);
|
|
|
2506
2589
|
var import_stream2 = require("eventsource-parser/stream");
|
|
2507
2590
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2508
2591
|
0 && (module.exports = {
|
|
2592
|
+
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
2509
2593
|
DelayedPromise,
|
|
2594
|
+
DownloadError,
|
|
2510
2595
|
EventSourceParserStream,
|
|
2511
2596
|
VERSION,
|
|
2512
2597
|
asSchema,
|
|
@@ -2552,6 +2637,7 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2552
2637
|
postFormDataToApi,
|
|
2553
2638
|
postJsonToApi,
|
|
2554
2639
|
postToApi,
|
|
2640
|
+
readResponseWithSizeLimit,
|
|
2555
2641
|
removeUndefinedEntries,
|
|
2556
2642
|
resolve,
|
|
2557
2643
|
safeParseJSON,
|