@ai-sdk/provider-utils 5.0.47 → 5.0.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 CHANGED
@@ -1,5 +1,28 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 5.0.49
4
+
5
+ ### Patch Changes
6
+
7
+ - af9597b: Compile packages for ES2022 runtime target
8
+ - bc49f78: Preserve original opaque URI strings in tagged file URLs during prompt conversion. Match explicit supported URL MIME types exactly so unsupported subtypes are not forwarded to providers.
9
+
10
+ ## 5.0.48
11
+
12
+ ### Patch Changes
13
+
14
+ - be877ff: Add `fetchUntrustedUrl`, an opt-in fetch helper that withholds credentials and
15
+ unknown custom headers from untrusted first-hop URLs. A matching configured
16
+ `credentialedOrigin` (or `trustedOrigin` when omitted) allows sanitized caller
17
+ headers. Otherwise only allowlisted metadata is sent; callers can explicitly
18
+ allow additional non-credential metadata with `untrustedFirstHopHeaders`.
19
+
20
+ The helper shares URL validation, DNS pinning, and redirect protection with
21
+ `fetchWithValidatedRedirects`, and is now used by `downloadBlob`.
22
+ `fetchWithValidatedRedirects` and `getFromApi` retain their existing behavior.
23
+ Direct callers must opt into the new helper for first-hop credential isolation;
24
+ existing authenticated and custom-header requests are not silently changed.
25
+
3
26
  ## 5.0.47
4
27
 
5
28
  ### Patch Changes
@@ -51,7 +51,7 @@ function secureJsonParse(text) {
51
51
  const { stackTraceLimit } = Error;
52
52
  try {
53
53
  Error.stackTraceLimit = 0;
54
- } catch (e) {
54
+ } catch {
55
55
  return _parse(text);
56
56
  }
57
57
  try {
@@ -148,11 +148,10 @@ function parseAnyDef() {
148
148
 
149
149
  // src/to-json-schema/zod3-to-json-schema/parsers/array.ts
150
150
  function parseArrayDef(def, refs) {
151
- var _a, _b, _c;
152
151
  const res = {
153
152
  type: "array"
154
153
  };
155
- if (((_a = def.type) == null ? void 0 : _a._def) && ((_c = (_b = def.type) == null ? void 0 : _b._def) == null ? void 0 : _c.typeName) !== "ZodAny") {
154
+ if (def.type?._def && def.type?._def?.typeName !== "ZodAny") {
156
155
  res.items = parseDef(def.type._def, {
157
156
  ...refs,
158
157
  currentPath: [...refs.currentPath, "items"]
@@ -219,7 +218,7 @@ var parseCatchDef = (def, refs) => {
219
218
 
220
219
  // src/to-json-schema/zod3-to-json-schema/parsers/date.ts
221
220
  function parseDateDef(def, refs, overrideDateStrategy) {
222
- const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
221
+ const strategy = overrideDateStrategy ?? refs.dateStrategy;
223
222
  if (Array.isArray(strategy)) {
224
223
  return {
225
224
  anyOf: strategy.map((item) => parseDateDef(def, refs, item))
@@ -540,8 +539,7 @@ function escapeNonAlphaNumeric(source) {
540
539
  return result;
541
540
  }
542
541
  function addFormat(schema, value, message, refs) {
543
- var _a;
544
- if (schema.format || ((_a = schema.anyOf) == null ? void 0 : _a.some((x) => x.format))) {
542
+ if (schema.format || schema.anyOf?.some((x) => x.format)) {
545
543
  if (!schema.anyOf) {
546
544
  schema.anyOf = [];
547
545
  }
@@ -560,8 +558,7 @@ function addFormat(schema, value, message, refs) {
560
558
  }
561
559
  }
562
560
  function addPattern(schema, regex, message, refs) {
563
- var _a;
564
- if (schema.pattern || ((_a = schema.allOf) == null ? void 0 : _a.some((x) => x.pattern))) {
561
+ if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
565
562
  if (!schema.allOf) {
566
563
  schema.allOf = [];
567
564
  }
@@ -580,7 +577,6 @@ function addPattern(schema, regex, message, refs) {
580
577
  }
581
578
  }
582
579
  function stringifyRegExpWithFlags(regex, refs) {
583
- var _a;
584
580
  if (!refs.applyRegexFlags || !regex.flags) {
585
581
  return regex.source;
586
582
  }
@@ -610,7 +606,7 @@ function stringifyRegExpWithFlags(regex, refs) {
610
606
  pattern += source[i];
611
607
  pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
612
608
  inCharRange = false;
613
- } else if (source[i + 1] === "-" && ((_a = source[i + 2]) == null ? void 0 : _a.match(/[a-z]/))) {
609
+ } else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
614
610
  pattern += source[i];
615
611
  inCharRange = true;
616
612
  } else {
@@ -651,7 +647,7 @@ function stringifyRegExpWithFlags(regex, refs) {
651
647
  }
652
648
  try {
653
649
  new RegExp(pattern);
654
- } catch (e) {
650
+ } catch {
655
651
  console.warn(
656
652
  `Could not convert regex pattern at ${refs.currentPath.join(
657
653
  "/"
@@ -664,28 +660,27 @@ function stringifyRegExpWithFlags(regex, refs) {
664
660
 
665
661
  // src/to-json-schema/zod3-to-json-schema/parsers/record.ts
666
662
  function parseRecordDef(def, refs) {
667
- var _a, _b, _c, _d, _e, _f;
668
663
  const schema = {
669
664
  type: "object",
670
- additionalProperties: (_a = parseDef(def.valueType._def, {
665
+ additionalProperties: parseDef(def.valueType._def, {
671
666
  ...refs,
672
667
  currentPath: [...refs.currentPath, "additionalProperties"]
673
- })) != null ? _a : refs.allowedAdditionalProperties
668
+ }) ?? refs.allowedAdditionalProperties
674
669
  };
675
- if (((_b = def.keyType) == null ? void 0 : _b._def.typeName) === "ZodString" && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
670
+ if (def.keyType?._def.typeName === "ZodString" && def.keyType._def.checks?.length) {
676
671
  const { type: _type, ...keyType } = parseStringDef(def.keyType._def, refs);
677
672
  return {
678
673
  ...schema,
679
674
  propertyNames: keyType
680
675
  };
681
- } else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === "ZodEnum") {
676
+ } else if (def.keyType?._def.typeName === "ZodEnum") {
682
677
  return {
683
678
  ...schema,
684
679
  propertyNames: {
685
680
  enum: def.keyType._def.values
686
681
  }
687
682
  };
688
- } else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) === "ZodBranded" && def.keyType._def.type._def.typeName === "ZodString" && ((_f = def.keyType._def.type._def.checks) == null ? void 0 : _f.length)) {
683
+ } else if (def.keyType?._def.typeName === "ZodBranded" && def.keyType._def.type._def.typeName === "ZodString" && def.keyType._def.type._def.checks?.length) {
689
684
  const { type: _type, ...keyType } = parseBrandedDef(
690
685
  def.keyType._def,
691
686
  refs
@@ -938,15 +933,14 @@ function decideAdditionalProperties(def, refs) {
938
933
  function safeIsOptional(schema) {
939
934
  try {
940
935
  return schema.isOptional();
941
- } catch (e) {
936
+ } catch {
942
937
  return true;
943
938
  }
944
939
  }
945
940
 
946
941
  // src/to-json-schema/zod3-to-json-schema/parsers/optional.ts
947
942
  var parseOptionalDef = (def, refs) => {
948
- var _a;
949
- if (refs.currentPath.toString() === ((_a = refs.propertyPath) == null ? void 0 : _a.toString())) {
943
+ if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
950
944
  return parseDef(def.innerType._def, refs);
951
945
  }
952
946
  const innerSchema = parseDef(def.innerType._def, {
@@ -1145,11 +1139,9 @@ var getRelativePath = (pathA, pathB) => {
1145
1139
 
1146
1140
  // src/to-json-schema/zod3-to-json-schema/parse-def.ts
1147
1141
  function parseDef(def, refs, forceResolution = false) {
1148
- var _a;
1149
1142
  const seenItem = refs.seen.get(def);
1150
1143
  if (refs.override) {
1151
- const overrideResult = (_a = refs.override) == null ? void 0 : _a.call(
1152
- refs,
1144
+ const overrideResult = refs.override?.(
1153
1145
  def,
1154
1146
  refs,
1155
1147
  seenItem,
@@ -1231,34 +1223,30 @@ var getRefs = (options) => {
1231
1223
 
1232
1224
  // src/to-json-schema/zod3-to-json-schema/zod3-to-json-schema.ts
1233
1225
  var zod3ToJsonSchema = (schema, options) => {
1234
- var _a;
1235
1226
  const refs = getRefs(options);
1236
1227
  let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
1237
- (acc, [name2, schema2]) => {
1238
- var _a2;
1239
- return {
1240
- ...acc,
1241
- [name2]: (_a2 = parseDef(
1242
- schema2._def,
1243
- {
1244
- ...refs,
1245
- currentPath: [...refs.basePath, refs.definitionPath, name2]
1246
- },
1247
- true
1248
- )) != null ? _a2 : parseAnyDef()
1249
- };
1250
- },
1228
+ (acc, [name2, schema2]) => ({
1229
+ ...acc,
1230
+ [name2]: parseDef(
1231
+ schema2._def,
1232
+ {
1233
+ ...refs,
1234
+ currentPath: [...refs.basePath, refs.definitionPath, name2]
1235
+ },
1236
+ true
1237
+ ) ?? parseAnyDef()
1238
+ }),
1251
1239
  {}
1252
1240
  ) : void 0;
1253
- const name = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
1254
- const main = (_a = parseDef(
1241
+ const name = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
1242
+ const main = parseDef(
1255
1243
  schema._def,
1256
1244
  name === void 0 ? refs : {
1257
1245
  ...refs,
1258
1246
  currentPath: [...refs.basePath, refs.definitionPath, name]
1259
1247
  },
1260
1248
  false
1261
- )) != null ? _a : parseAnyDef();
1249
+ ) ?? parseAnyDef();
1262
1250
  const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
1263
1251
  if (title !== void 0) {
1264
1252
  main.title = title;
@@ -1341,8 +1329,7 @@ function hasStandardJsonSchema(schema) {
1341
1329
  return schema["~standard"].jsonSchema != null;
1342
1330
  }
1343
1331
  function zod3Schema(zodSchema2, options) {
1344
- var _a;
1345
- const useReferences = (_a = options == null ? void 0 : options.useReferences) != null ? _a : false;
1332
+ const useReferences = options?.useReferences ?? false;
1346
1333
  return jsonSchema(
1347
1334
  // defer json schema creation to avoid unnecessary computation when only validation is needed
1348
1335
  () => zod3ToJsonSchema(zodSchema2, {
@@ -1357,8 +1344,7 @@ function zod3Schema(zodSchema2, options) {
1357
1344
  );
1358
1345
  }
1359
1346
  function zod4Schema(zodSchema2, options) {
1360
- var _a;
1361
- const useReferences = (_a = options == null ? void 0 : options.useReferences) != null ? _a : false;
1347
+ const useReferences = options?.useReferences ?? false;
1362
1348
  return jsonSchema(
1363
1349
  // defer json schema creation to avoid unnecessary computation when only validation is needed
1364
1350
  () => addAdditionalPropertiesToJsonSchema(
@@ -1469,7 +1455,7 @@ var EvaluationLanguageModel = class _EvaluationLanguageModel {
1469
1455
  headers,
1470
1456
  providerOptions
1471
1457
  }) {
1472
- abortSignal == null ? void 0 : abortSignal.throwIfAborted();
1458
+ abortSignal?.throwIfAborted();
1473
1459
  const entries = Object.entries(questions).map(([id, question]) => {
1474
1460
  if (!this.supportedQuestionTypes.includes(question.type)) {
1475
1461
  throw new EvaluationUnsupportedQuestionTypeError({
@@ -1556,7 +1542,7 @@ var EvaluationLanguageModel = class _EvaluationLanguageModel {
1556
1542
  headers,
1557
1543
  providerOptions
1558
1544
  });
1559
- abortSignal == null ? void 0 : abortSignal.throwIfAborted();
1545
+ abortSignal?.throwIfAborted();
1560
1546
  if (result.finishReason.unified !== "stop") {
1561
1547
  throw new InvalidResponseDataError({
1562
1548
  data: result,