@ai-sdk/provider-utils 2.2.8 → 3.0.0-alpha.10

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/dist/index.js CHANGED
@@ -17,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
17
17
  }
18
18
  return to;
19
19
  };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
21
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
22
  // If the importer is in node compatibility mode or this is not an ESM
22
23
  // file that has been converted to a CommonJS file using a Babel-
@@ -30,10 +31,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
31
  // src/index.ts
31
32
  var src_exports = {};
32
33
  __export(src_exports, {
34
+ asSchema: () => asSchema,
33
35
  asValidator: () => asValidator,
34
36
  combineHeaders: () => combineHeaders,
35
37
  convertAsyncIteratorToReadableStream: () => convertAsyncIteratorToReadableStream,
36
38
  convertBase64ToUint8Array: () => convertBase64ToUint8Array,
39
+ convertToBase64: () => convertToBase64,
37
40
  convertUint8ArrayToBase64: () => convertUint8ArrayToBase64,
38
41
  createBinaryResponseHandler: () => createBinaryResponseHandler,
39
42
  createEventSourceParserStream: () => createEventSourceParserStream,
@@ -50,11 +53,14 @@ __export(src_exports, {
50
53
  getFromApi: () => getFromApi,
51
54
  isAbortError: () => isAbortError,
52
55
  isParsableJson: () => isParsableJson,
56
+ isUrlSupported: () => isUrlSupported,
53
57
  isValidator: () => isValidator,
58
+ jsonSchema: () => jsonSchema,
54
59
  loadApiKey: () => loadApiKey,
55
60
  loadOptionalSetting: () => loadOptionalSetting,
56
61
  loadSetting: () => loadSetting,
57
62
  parseJSON: () => parseJSON,
63
+ parseJsonEventStream: () => parseJsonEventStream,
58
64
  parseProviderOptions: () => parseProviderOptions,
59
65
  postFormDataToApi: () => postFormDataToApi,
60
66
  postJsonToApi: () => postJsonToApi,
@@ -63,11 +69,12 @@ __export(src_exports, {
63
69
  resolve: () => resolve,
64
70
  safeParseJSON: () => safeParseJSON,
65
71
  safeValidateTypes: () => safeValidateTypes,
72
+ standardSchemaValidator: () => standardSchemaValidator,
66
73
  validateTypes: () => validateTypes,
67
74
  validator: () => validator,
68
75
  validatorSymbol: () => validatorSymbol,
69
76
  withoutTrailingSlash: () => withoutTrailingSlash,
70
- zodValidator: () => zodValidator
77
+ zodSchema: () => zodSchema
71
78
  });
72
79
  module.exports = __toCommonJS(src_exports);
73
80
 
@@ -210,23 +217,25 @@ function splitLines(buffer, chunk) {
210
217
 
211
218
  // src/extract-response-headers.ts
212
219
  function extractResponseHeaders(response) {
213
- const headers = {};
214
- response.headers.forEach((value, key) => {
215
- headers[key] = value;
216
- });
217
- return headers;
220
+ return Object.fromEntries([...response.headers]);
218
221
  }
219
222
 
220
223
  // src/generate-id.ts
221
224
  var import_provider = require("@ai-sdk/provider");
222
- var import_non_secure = require("nanoid/non-secure");
223
225
  var createIdGenerator = ({
224
226
  prefix,
225
- size: defaultSize = 16,
227
+ size = 16,
226
228
  alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
227
229
  separator = "-"
228
230
  } = {}) => {
229
- const generator = (0, import_non_secure.customAlphabet)(alphabet, defaultSize);
231
+ const generator = () => {
232
+ const alphabetLength = alphabet.length;
233
+ const chars = new Array(size);
234
+ for (let i = 0; i < size; i++) {
235
+ chars[i] = alphabet[Math.random() * alphabetLength | 0];
236
+ }
237
+ return chars.join("");
238
+ };
230
239
  if (prefix == null) {
231
240
  return generator;
232
241
  }
@@ -236,7 +245,7 @@ var createIdGenerator = ({
236
245
  message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
237
246
  });
238
247
  }
239
- return (size) => `${prefix}${separator}${generator(size)}`;
248
+ return () => `${prefix}${separator}${generator()}`;
240
249
  };
241
250
  var generateId = createIdGenerator();
242
251
 
@@ -350,6 +359,20 @@ var getFromApi = async ({
350
359
  }
351
360
  };
352
361
 
362
+ // src/is-url-supported.ts
363
+ function isUrlSupported({
364
+ mediaType,
365
+ url,
366
+ supportedUrls
367
+ }) {
368
+ url = url.toLowerCase();
369
+ mediaType = mediaType.toLowerCase();
370
+ return Object.entries(supportedUrls).map(([key, value]) => {
371
+ const mediaType2 = key.toLowerCase();
372
+ return mediaType2 === "*" || mediaType2 === "*/*" ? { mediaTypePrefix: "", regexes: value } : { mediaTypePrefix: mediaType2.replace(/\*/, ""), regexes: value };
373
+ }).filter(({ mediaTypePrefix }) => mediaType.startsWith(mediaTypePrefix)).flatMap(({ regexes }) => regexes).some((pattern) => pattern.test(url));
374
+ }
375
+
353
376
  // src/load-api-key.ts
354
377
  var import_provider3 = require("@ai-sdk/provider");
355
378
  function loadApiKey({
@@ -439,13 +462,58 @@ function loadSetting({
439
462
  }
440
463
 
441
464
  // src/parse-json.ts
442
- var import_provider6 = require("@ai-sdk/provider");
443
- var import_secure_json_parse = __toESM(require("secure-json-parse"));
465
+ var import_provider7 = require("@ai-sdk/provider");
466
+
467
+ // src/secure-json-parse.ts
468
+ var suspectProtoRx = /"__proto__"\s*:/;
469
+ var suspectConstructorRx = /"constructor"\s*:/;
470
+ function _parse(text) {
471
+ const obj = JSON.parse(text);
472
+ if (obj === null || typeof obj !== "object") {
473
+ return obj;
474
+ }
475
+ if (suspectProtoRx.test(text) === false && suspectConstructorRx.test(text) === false) {
476
+ return obj;
477
+ }
478
+ return filter(obj);
479
+ }
480
+ function filter(obj) {
481
+ let next = [obj];
482
+ while (next.length) {
483
+ const nodes = next;
484
+ next = [];
485
+ for (const node of nodes) {
486
+ if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
487
+ throw new SyntaxError("Object contains forbidden prototype property");
488
+ }
489
+ if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
490
+ throw new SyntaxError("Object contains forbidden prototype property");
491
+ }
492
+ for (const key in node) {
493
+ const value = node[key];
494
+ if (value && typeof value === "object") {
495
+ next.push(value);
496
+ }
497
+ }
498
+ }
499
+ }
500
+ return obj;
501
+ }
502
+ function secureJsonParse(text) {
503
+ const { stackTraceLimit } = Error;
504
+ Error.stackTraceLimit = 0;
505
+ try {
506
+ return _parse(text);
507
+ } finally {
508
+ Error.stackTraceLimit = stackTraceLimit;
509
+ }
510
+ }
444
511
 
445
512
  // src/validate-types.ts
446
- var import_provider5 = require("@ai-sdk/provider");
513
+ var import_provider6 = require("@ai-sdk/provider");
447
514
 
448
515
  // src/validator.ts
516
+ var import_provider5 = require("@ai-sdk/provider");
449
517
  var validatorSymbol = Symbol.for("vercel.ai.validator");
450
518
  function validator(validate) {
451
519
  return { [validatorSymbol]: true, validate };
@@ -454,99 +522,121 @@ function isValidator(value) {
454
522
  return typeof value === "object" && value !== null && validatorSymbol in value && value[validatorSymbol] === true && "validate" in value;
455
523
  }
456
524
  function asValidator(value) {
457
- return isValidator(value) ? value : zodValidator(value);
525
+ return isValidator(value) ? value : standardSchemaValidator(value);
458
526
  }
459
- function zodValidator(zodSchema) {
460
- return validator((value) => {
461
- const result = zodSchema.safeParse(value);
462
- return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
527
+ function standardSchemaValidator(standardSchema) {
528
+ return validator(async (value) => {
529
+ const result = await standardSchema["~standard"].validate(value);
530
+ return result.issues == null ? { success: true, value: result.value } : {
531
+ success: false,
532
+ error: new import_provider5.TypeValidationError({
533
+ value,
534
+ cause: result.issues
535
+ })
536
+ };
463
537
  });
464
538
  }
465
539
 
466
540
  // src/validate-types.ts
467
- function validateTypes({
541
+ async function validateTypes({
468
542
  value,
469
- schema: inputSchema
543
+ schema
470
544
  }) {
471
- const result = safeValidateTypes({ value, schema: inputSchema });
545
+ const result = await safeValidateTypes({ value, schema });
472
546
  if (!result.success) {
473
- throw import_provider5.TypeValidationError.wrap({ value, cause: result.error });
547
+ throw import_provider6.TypeValidationError.wrap({ value, cause: result.error });
474
548
  }
475
549
  return result.value;
476
550
  }
477
- function safeValidateTypes({
551
+ async function safeValidateTypes({
478
552
  value,
479
553
  schema
480
554
  }) {
481
555
  const validator2 = asValidator(schema);
482
556
  try {
483
557
  if (validator2.validate == null) {
484
- return { success: true, value };
558
+ return { success: true, value, rawValue: value };
485
559
  }
486
- const result = validator2.validate(value);
560
+ const result = await validator2.validate(value);
487
561
  if (result.success) {
488
- return result;
562
+ return { success: true, value: result.value, rawValue: value };
489
563
  }
490
564
  return {
491
565
  success: false,
492
- error: import_provider5.TypeValidationError.wrap({ value, cause: result.error })
566
+ error: import_provider6.TypeValidationError.wrap({ value, cause: result.error }),
567
+ rawValue: value
493
568
  };
494
569
  } catch (error) {
495
570
  return {
496
571
  success: false,
497
- error: import_provider5.TypeValidationError.wrap({ value, cause: error })
572
+ error: import_provider6.TypeValidationError.wrap({ value, cause: error }),
573
+ rawValue: value
498
574
  };
499
575
  }
500
576
  }
501
577
 
502
578
  // src/parse-json.ts
503
- function parseJSON({
504
- text,
505
- schema
506
- }) {
579
+ async function parseJSON({ text, schema }) {
507
580
  try {
508
- const value = import_secure_json_parse.default.parse(text);
581
+ const value = secureJsonParse(text);
509
582
  if (schema == null) {
510
583
  return value;
511
584
  }
512
585
  return validateTypes({ value, schema });
513
586
  } catch (error) {
514
- if (import_provider6.JSONParseError.isInstance(error) || import_provider6.TypeValidationError.isInstance(error)) {
587
+ if (import_provider7.JSONParseError.isInstance(error) || import_provider7.TypeValidationError.isInstance(error)) {
515
588
  throw error;
516
589
  }
517
- throw new import_provider6.JSONParseError({ text, cause: error });
590
+ throw new import_provider7.JSONParseError({ text, cause: error });
518
591
  }
519
592
  }
520
- function safeParseJSON({
593
+ async function safeParseJSON({
521
594
  text,
522
595
  schema
523
596
  }) {
524
597
  try {
525
- const value = import_secure_json_parse.default.parse(text);
598
+ const value = secureJsonParse(text);
526
599
  if (schema == null) {
527
600
  return { success: true, value, rawValue: value };
528
601
  }
529
- const validationResult = safeValidateTypes({ value, schema });
530
- return validationResult.success ? { ...validationResult, rawValue: value } : validationResult;
602
+ return await safeValidateTypes({ value, schema });
531
603
  } catch (error) {
532
604
  return {
533
605
  success: false,
534
- error: import_provider6.JSONParseError.isInstance(error) ? error : new import_provider6.JSONParseError({ text, cause: error })
606
+ error: import_provider7.JSONParseError.isInstance(error) ? error : new import_provider7.JSONParseError({ text, cause: error }),
607
+ rawValue: void 0
535
608
  };
536
609
  }
537
610
  }
538
611
  function isParsableJson(input) {
539
612
  try {
540
- import_secure_json_parse.default.parse(input);
613
+ secureJsonParse(input);
541
614
  return true;
542
615
  } catch (e) {
543
616
  return false;
544
617
  }
545
618
  }
546
619
 
620
+ // src/parse-json-event-stream.ts
621
+ function parseJsonEventStream({
622
+ stream,
623
+ schema
624
+ }) {
625
+ return stream.pipeThrough(new TextDecoderStream()).pipeThrough(createEventSourceParserStream()).pipeThrough(
626
+ new TransformStream({
627
+ async transform({ data }, controller) {
628
+ if (data === "[DONE]") {
629
+ return;
630
+ }
631
+ controller.enqueue(await safeParseJSON({ text: data, schema }));
632
+ }
633
+ })
634
+ );
635
+ }
636
+
547
637
  // src/parse-provider-options.ts
548
- var import_provider7 = require("@ai-sdk/provider");
549
- function parseProviderOptions({
638
+ var import_provider8 = require("@ai-sdk/provider");
639
+ async function parseProviderOptions({
550
640
  provider,
551
641
  providerOptions,
552
642
  schema
@@ -554,12 +644,12 @@ function parseProviderOptions({
554
644
  if ((providerOptions == null ? void 0 : providerOptions[provider]) == null) {
555
645
  return void 0;
556
646
  }
557
- const parsedProviderOptions = safeValidateTypes({
647
+ const parsedProviderOptions = await safeValidateTypes({
558
648
  value: providerOptions[provider],
559
649
  schema
560
650
  });
561
651
  if (!parsedProviderOptions.success) {
562
- throw new import_provider7.InvalidArgumentError({
652
+ throw new import_provider8.InvalidArgumentError({
563
653
  argument: "providerOptions",
564
654
  message: `invalid ${provider} provider options`,
565
655
  cause: parsedProviderOptions.error
@@ -569,7 +659,7 @@ function parseProviderOptions({
569
659
  }
570
660
 
571
661
  // src/post-to-api.ts
572
- var import_provider8 = require("@ai-sdk/provider");
662
+ var import_provider9 = require("@ai-sdk/provider");
573
663
  var getOriginalFetch2 = () => globalThis.fetch;
574
664
  var postJsonToApi = async ({
575
665
  url,
@@ -640,10 +730,10 @@ var postToApi = async ({
640
730
  requestBodyValues: body.values
641
731
  });
642
732
  } catch (error) {
643
- if (isAbortError(error) || import_provider8.APICallError.isInstance(error)) {
733
+ if (isAbortError(error) || import_provider9.APICallError.isInstance(error)) {
644
734
  throw error;
645
735
  }
646
- throw new import_provider8.APICallError({
736
+ throw new import_provider9.APICallError({
647
737
  message: "Failed to process error response",
648
738
  cause: error,
649
739
  statusCode: response.status,
@@ -662,11 +752,11 @@ var postToApi = async ({
662
752
  });
663
753
  } catch (error) {
664
754
  if (error instanceof Error) {
665
- if (isAbortError(error) || import_provider8.APICallError.isInstance(error)) {
755
+ if (isAbortError(error) || import_provider9.APICallError.isInstance(error)) {
666
756
  throw error;
667
757
  }
668
758
  }
669
- throw new import_provider8.APICallError({
759
+ throw new import_provider9.APICallError({
670
760
  message: "Failed to process successful response",
671
761
  cause: error,
672
762
  statusCode: response.status,
@@ -682,7 +772,7 @@ var postToApi = async ({
682
772
  if (error instanceof TypeError && error.message === "fetch failed") {
683
773
  const cause = error.cause;
684
774
  if (cause != null) {
685
- throw new import_provider8.APICallError({
775
+ throw new import_provider9.APICallError({
686
776
  message: `Cannot connect to API: ${cause.message}`,
687
777
  cause,
688
778
  url,
@@ -705,7 +795,7 @@ async function resolve(value) {
705
795
  }
706
796
 
707
797
  // src/response-handler.ts
708
- var import_provider9 = require("@ai-sdk/provider");
798
+ var import_provider10 = require("@ai-sdk/provider");
709
799
  var createJsonErrorResponseHandler = ({
710
800
  errorSchema,
711
801
  errorToMessage,
@@ -716,7 +806,7 @@ var createJsonErrorResponseHandler = ({
716
806
  if (responseBody.trim() === "") {
717
807
  return {
718
808
  responseHeaders,
719
- value: new import_provider9.APICallError({
809
+ value: new import_provider10.APICallError({
720
810
  message: response.statusText,
721
811
  url,
722
812
  requestBodyValues,
@@ -728,13 +818,13 @@ var createJsonErrorResponseHandler = ({
728
818
  };
729
819
  }
730
820
  try {
731
- const parsedError = parseJSON({
821
+ const parsedError = await parseJSON({
732
822
  text: responseBody,
733
823
  schema: errorSchema
734
824
  });
735
825
  return {
736
826
  responseHeaders,
737
- value: new import_provider9.APICallError({
827
+ value: new import_provider10.APICallError({
738
828
  message: errorToMessage(parsedError),
739
829
  url,
740
830
  requestBodyValues,
@@ -748,7 +838,7 @@ var createJsonErrorResponseHandler = ({
748
838
  } catch (parseError) {
749
839
  return {
750
840
  responseHeaders,
751
- value: new import_provider9.APICallError({
841
+ value: new import_provider10.APICallError({
752
842
  message: response.statusText,
753
843
  url,
754
844
  requestBodyValues,
@@ -763,41 +853,30 @@ var createJsonErrorResponseHandler = ({
763
853
  var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
764
854
  const responseHeaders = extractResponseHeaders(response);
765
855
  if (response.body == null) {
766
- throw new import_provider9.EmptyResponseBodyError({});
856
+ throw new import_provider10.EmptyResponseBodyError({});
767
857
  }
768
858
  return {
769
859
  responseHeaders,
770
- value: response.body.pipeThrough(new TextDecoderStream()).pipeThrough(createEventSourceParserStream()).pipeThrough(
771
- new TransformStream({
772
- transform({ data }, controller) {
773
- if (data === "[DONE]") {
774
- return;
775
- }
776
- controller.enqueue(
777
- safeParseJSON({
778
- text: data,
779
- schema: chunkSchema
780
- })
781
- );
782
- }
783
- })
784
- )
860
+ value: parseJsonEventStream({
861
+ stream: response.body,
862
+ schema: chunkSchema
863
+ })
785
864
  };
786
865
  };
787
866
  var createJsonStreamResponseHandler = (chunkSchema) => async ({ response }) => {
788
867
  const responseHeaders = extractResponseHeaders(response);
789
868
  if (response.body == null) {
790
- throw new import_provider9.EmptyResponseBodyError({});
869
+ throw new import_provider10.EmptyResponseBodyError({});
791
870
  }
792
871
  let buffer = "";
793
872
  return {
794
873
  responseHeaders,
795
874
  value: response.body.pipeThrough(new TextDecoderStream()).pipeThrough(
796
875
  new TransformStream({
797
- transform(chunkText, controller) {
876
+ async transform(chunkText, controller) {
798
877
  if (chunkText.endsWith("\n")) {
799
878
  controller.enqueue(
800
- safeParseJSON({
879
+ await safeParseJSON({
801
880
  text: buffer + chunkText,
802
881
  schema: chunkSchema
803
882
  })
@@ -813,13 +892,13 @@ var createJsonStreamResponseHandler = (chunkSchema) => async ({ response }) => {
813
892
  };
814
893
  var createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
815
894
  const responseBody = await response.text();
816
- const parsedResult = safeParseJSON({
895
+ const parsedResult = await safeParseJSON({
817
896
  text: responseBody,
818
897
  schema: responseSchema
819
898
  });
820
899
  const responseHeaders = extractResponseHeaders(response);
821
900
  if (!parsedResult.success) {
822
- throw new import_provider9.APICallError({
901
+ throw new import_provider10.APICallError({
823
902
  message: "Invalid JSON response",
824
903
  cause: parsedResult.error,
825
904
  statusCode: response.status,
@@ -838,7 +917,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
838
917
  var createBinaryResponseHandler = () => async ({ response, url, requestBodyValues }) => {
839
918
  const responseHeaders = extractResponseHeaders(response);
840
919
  if (!response.body) {
841
- throw new import_provider9.APICallError({
920
+ throw new import_provider10.APICallError({
842
921
  message: "Response body is empty",
843
922
  url,
844
923
  requestBodyValues,
@@ -854,7 +933,7 @@ var createBinaryResponseHandler = () => async ({ response, url, requestBodyValue
854
933
  value: new Uint8Array(buffer)
855
934
  };
856
935
  } catch (error) {
857
- throw new import_provider9.APICallError({
936
+ throw new import_provider10.APICallError({
858
937
  message: "Failed to read response as array buffer",
859
938
  url,
860
939
  requestBodyValues,
@@ -870,7 +949,7 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
870
949
  const responseBody = await response.text();
871
950
  return {
872
951
  responseHeaders,
873
- value: new import_provider9.APICallError({
952
+ value: new import_provider10.APICallError({
874
953
  message: response.statusText,
875
954
  url,
876
955
  requestBodyValues,
@@ -881,6 +960,76 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
881
960
  };
882
961
  };
883
962
 
963
+ // src/zod-schema.ts
964
+ var z4 = __toESM(require("zod/v4/core"));
965
+ var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
966
+ function zod3Schema(zodSchema2, options) {
967
+ var _a;
968
+ const useReferences = (_a = options == null ? void 0 : options.useReferences) != null ? _a : false;
969
+ return jsonSchema(
970
+ (0, import_zod_to_json_schema.default)(zodSchema2, {
971
+ $refStrategy: useReferences ? "root" : "none",
972
+ target: "jsonSchema7"
973
+ // note: openai mode breaks various gemini conversions
974
+ }),
975
+ {
976
+ validate: (value) => {
977
+ const result = zodSchema2.safeParse(value);
978
+ return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
979
+ }
980
+ }
981
+ );
982
+ }
983
+ function zod4Schema(zodSchema2, options) {
984
+ var _a;
985
+ const useReferences = (_a = options == null ? void 0 : options.useReferences) != null ? _a : false;
986
+ const z4JSONSchema = z4.toJSONSchema(zodSchema2, {
987
+ target: "draft-7",
988
+ io: "output",
989
+ reused: useReferences ? "ref" : "inline"
990
+ });
991
+ return jsonSchema(z4JSONSchema, {
992
+ validate: (value) => {
993
+ const result = z4.safeParse(zodSchema2, value);
994
+ return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
995
+ }
996
+ });
997
+ }
998
+ function isZod4Schema(zodSchema2) {
999
+ return "_zod" in zodSchema2;
1000
+ }
1001
+ function zodSchema(zodSchema2, options) {
1002
+ if (isZod4Schema(zodSchema2)) {
1003
+ return zod4Schema(zodSchema2, options);
1004
+ } else {
1005
+ return zod3Schema(zodSchema2, options);
1006
+ }
1007
+ }
1008
+
1009
+ // src/schema.ts
1010
+ var schemaSymbol = Symbol.for("vercel.ai.schema");
1011
+ function jsonSchema(jsonSchema2, {
1012
+ validate
1013
+ } = {}) {
1014
+ return {
1015
+ [schemaSymbol]: true,
1016
+ _type: void 0,
1017
+ // should never be used directly
1018
+ [validatorSymbol]: true,
1019
+ jsonSchema: jsonSchema2,
1020
+ validate
1021
+ };
1022
+ }
1023
+ function isSchema(value) {
1024
+ return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
1025
+ }
1026
+ function asSchema(schema) {
1027
+ return schema == null ? jsonSchema({
1028
+ properties: {},
1029
+ additionalProperties: false
1030
+ }) : isSchema(schema) ? schema : zodSchema(schema);
1031
+ }
1032
+
884
1033
  // src/uint8-utils.ts
885
1034
  var { btoa, atob } = globalThis;
886
1035
  function convertBase64ToUint8Array(base64String) {
@@ -895,17 +1044,25 @@ function convertUint8ArrayToBase64(array) {
895
1044
  }
896
1045
  return btoa(latin1string);
897
1046
  }
1047
+ function convertToBase64(value) {
1048
+ return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
1049
+ }
898
1050
 
899
1051
  // src/without-trailing-slash.ts
900
1052
  function withoutTrailingSlash(url) {
901
1053
  return url == null ? void 0 : url.replace(/\/$/, "");
902
1054
  }
1055
+
1056
+ // src/index.ts
1057
+ __reExport(src_exports, require("@standard-schema/spec"), module.exports);
903
1058
  // Annotate the CommonJS export names for ESM import in node:
904
1059
  0 && (module.exports = {
1060
+ asSchema,
905
1061
  asValidator,
906
1062
  combineHeaders,
907
1063
  convertAsyncIteratorToReadableStream,
908
1064
  convertBase64ToUint8Array,
1065
+ convertToBase64,
909
1066
  convertUint8ArrayToBase64,
910
1067
  createBinaryResponseHandler,
911
1068
  createEventSourceParserStream,
@@ -922,11 +1079,14 @@ function withoutTrailingSlash(url) {
922
1079
  getFromApi,
923
1080
  isAbortError,
924
1081
  isParsableJson,
1082
+ isUrlSupported,
925
1083
  isValidator,
1084
+ jsonSchema,
926
1085
  loadApiKey,
927
1086
  loadOptionalSetting,
928
1087
  loadSetting,
929
1088
  parseJSON,
1089
+ parseJsonEventStream,
930
1090
  parseProviderOptions,
931
1091
  postFormDataToApi,
932
1092
  postJsonToApi,
@@ -935,10 +1095,12 @@ function withoutTrailingSlash(url) {
935
1095
  resolve,
936
1096
  safeParseJSON,
937
1097
  safeValidateTypes,
1098
+ standardSchemaValidator,
938
1099
  validateTypes,
939
1100
  validator,
940
1101
  validatorSymbol,
941
1102
  withoutTrailingSlash,
942
- zodValidator
1103
+ zodSchema,
1104
+ ...require("@standard-schema/spec")
943
1105
  });
944
1106
  //# sourceMappingURL=index.js.map