@ai-sdk/provider-utils 5.0.47 → 5.0.50
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 +31 -0
- package/dist/experimental-evaluation/index.js +33 -47
- package/dist/experimental-evaluation/index.js.map +1 -1
- package/dist/index.d.ts +66 -5
- package/dist/index.js +424 -176
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/download-blob.ts +2 -2
- package/src/fetch-untrusted-url.ts +86 -0
- package/src/fetch-with-validated-redirects.ts +3 -0
- package/src/index.ts +1 -0
- package/src/is-url-supported.ts +5 -3
- package/src/sanitize-request-headers.ts +5 -3
- package/src/streaming-tool-call-argument-state.ts +100 -0
- package/src/streaming-tool-call-tracker.ts +313 -36
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 5.0.50
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e3605f6: Fix streamed tool calls with missing, blank, or repeated IDs.
|
|
8
|
+
- Updated dependencies [525efc5]
|
|
9
|
+
- @ai-sdk/provider@4.0.19
|
|
10
|
+
|
|
11
|
+
## 5.0.49
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- af9597b: Compile packages for ES2022 runtime target
|
|
16
|
+
- 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.
|
|
17
|
+
|
|
18
|
+
## 5.0.48
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- be877ff: Add `fetchUntrustedUrl`, an opt-in fetch helper that withholds credentials and
|
|
23
|
+
unknown custom headers from untrusted first-hop URLs. A matching configured
|
|
24
|
+
`credentialedOrigin` (or `trustedOrigin` when omitted) allows sanitized caller
|
|
25
|
+
headers. Otherwise only allowlisted metadata is sent; callers can explicitly
|
|
26
|
+
allow additional non-credential metadata with `untrustedFirstHopHeaders`.
|
|
27
|
+
|
|
28
|
+
The helper shares URL validation, DNS pinning, and redirect protection with
|
|
29
|
+
`fetchWithValidatedRedirects`, and is now used by `downloadBlob`.
|
|
30
|
+
`fetchWithValidatedRedirects` and `getFromApi` retain their existing behavior.
|
|
31
|
+
Direct callers must opt into the new helper for first-hop credential isolation;
|
|
32
|
+
existing authenticated and custom-header requests are not silently changed.
|
|
33
|
+
|
|
3
34
|
## 5.0.47
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
|
@@ -51,7 +51,7 @@ function secureJsonParse(text) {
|
|
|
51
51
|
const { stackTraceLimit } = Error;
|
|
52
52
|
try {
|
|
53
53
|
Error.stackTraceLimit = 0;
|
|
54
|
-
} catch
|
|
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 (
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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] === "-" &&
|
|
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
|
|
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:
|
|
665
|
+
additionalProperties: parseDef(def.valueType._def, {
|
|
671
666
|
...refs,
|
|
672
667
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
673
|
-
})
|
|
668
|
+
}) ?? refs.allowedAdditionalProperties
|
|
674
669
|
};
|
|
675
|
-
if (
|
|
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 (
|
|
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 (
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
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 :
|
|
1254
|
-
const main =
|
|
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
|
-
)
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
1545
|
+
abortSignal?.throwIfAborted();
|
|
1560
1546
|
if (result.finishReason.unified !== "stop") {
|
|
1561
1547
|
throw new InvalidResponseDataError({
|
|
1562
1548
|
data: result,
|