@ai-sdk/provider-utils 5.0.19 → 5.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 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +61 -61
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/streaming-tool-call-tracker.ts +31 -13
- package/src/to-json-schema/zod3-to-json-schema/parsers/array.ts +2 -5
- package/src/to-json-schema/zod3-to-json-schema/parsers/record.ts +5 -10
- package/src/to-json-schema/zod3-to-json-schema/select-parser.ts +40 -38
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 5.0.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1bec07d: Fix streamed tool calls with non-zero, non-contiguous, reused, or missing indexes.
|
|
8
|
+
|
|
9
|
+
## 5.0.20
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 160ccdb: Reduce bundle size by removing the runtime Zod 3 dependency.
|
|
14
|
+
|
|
3
15
|
## 5.0.19
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -2303,6 +2303,9 @@ type StreamingToolCallTrackerController = Pick<TransformStreamDefaultController<
|
|
|
2303
2303
|
*/
|
|
2304
2304
|
declare class StreamingToolCallTracker<DELTA extends StreamingToolCallDelta = StreamingToolCallDelta> {
|
|
2305
2305
|
private toolCalls;
|
|
2306
|
+
private toolCallsById;
|
|
2307
|
+
private toolCallsByIndex;
|
|
2308
|
+
private latestToolCall;
|
|
2306
2309
|
private readonly controller;
|
|
2307
2310
|
private readonly _generateId;
|
|
2308
2311
|
private readonly typeValidation;
|
package/dist/index.js
CHANGED
|
@@ -1325,7 +1325,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
1325
1325
|
}
|
|
1326
1326
|
|
|
1327
1327
|
// src/version.ts
|
|
1328
|
-
var VERSION = true ? "5.0.
|
|
1328
|
+
var VERSION = true ? "5.0.21" : "0.0.0-test";
|
|
1329
1329
|
|
|
1330
1330
|
// src/get-from-api.ts
|
|
1331
1331
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -1783,22 +1783,18 @@ var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
|
1783
1783
|
...options
|
|
1784
1784
|
};
|
|
1785
1785
|
|
|
1786
|
-
// src/to-json-schema/zod3-to-json-schema/select-parser.ts
|
|
1787
|
-
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod/v3";
|
|
1788
|
-
|
|
1789
1786
|
// src/to-json-schema/zod3-to-json-schema/parsers/any.ts
|
|
1790
1787
|
function parseAnyDef() {
|
|
1791
1788
|
return {};
|
|
1792
1789
|
}
|
|
1793
1790
|
|
|
1794
1791
|
// src/to-json-schema/zod3-to-json-schema/parsers/array.ts
|
|
1795
|
-
import { ZodFirstPartyTypeKind } from "zod/v3";
|
|
1796
1792
|
function parseArrayDef(def, refs) {
|
|
1797
1793
|
var _a3, _b3, _c;
|
|
1798
1794
|
const res = {
|
|
1799
1795
|
type: "array"
|
|
1800
1796
|
};
|
|
1801
|
-
if (((_a3 = def.type) == null ? void 0 : _a3._def) && ((_c = (_b3 = def.type) == null ? void 0 : _b3._def) == null ? void 0 : _c.typeName) !==
|
|
1797
|
+
if (((_a3 = def.type) == null ? void 0 : _a3._def) && ((_c = (_b3 = def.type) == null ? void 0 : _b3._def) == null ? void 0 : _c.typeName) !== "ZodAny") {
|
|
1802
1798
|
res.items = parseDef(def.type._def, {
|
|
1803
1799
|
...refs,
|
|
1804
1800
|
currentPath: [...refs.currentPath, "items"]
|
|
@@ -1972,11 +1968,6 @@ function parseLiteralDef(def) {
|
|
|
1972
1968
|
};
|
|
1973
1969
|
}
|
|
1974
1970
|
|
|
1975
|
-
// src/to-json-schema/zod3-to-json-schema/parsers/record.ts
|
|
1976
|
-
import {
|
|
1977
|
-
ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2
|
|
1978
|
-
} from "zod/v3";
|
|
1979
|
-
|
|
1980
1971
|
// src/to-json-schema/zod3-to-json-schema/parsers/string.ts
|
|
1981
1972
|
var emojiRegex = void 0;
|
|
1982
1973
|
var zodPatterns = {
|
|
@@ -2323,20 +2314,20 @@ function parseRecordDef(def, refs) {
|
|
|
2323
2314
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
2324
2315
|
})) != null ? _a3 : refs.allowedAdditionalProperties
|
|
2325
2316
|
};
|
|
2326
|
-
if (((_b3 = def.keyType) == null ? void 0 : _b3._def.typeName) ===
|
|
2317
|
+
if (((_b3 = def.keyType) == null ? void 0 : _b3._def.typeName) === "ZodString" && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
2327
2318
|
const { type: _type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
2328
2319
|
return {
|
|
2329
2320
|
...schema,
|
|
2330
2321
|
propertyNames: keyType
|
|
2331
2322
|
};
|
|
2332
|
-
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) ===
|
|
2323
|
+
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === "ZodEnum") {
|
|
2333
2324
|
return {
|
|
2334
2325
|
...schema,
|
|
2335
2326
|
propertyNames: {
|
|
2336
2327
|
enum: def.keyType._def.values
|
|
2337
2328
|
}
|
|
2338
2329
|
};
|
|
2339
|
-
} else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) ===
|
|
2330
|
+
} 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)) {
|
|
2340
2331
|
const { type: _type, ...keyType } = parseBrandedDef(
|
|
2341
2332
|
def.keyType._def,
|
|
2342
2333
|
refs
|
|
@@ -2712,73 +2703,73 @@ var parseReadonlyDef = (def, refs) => {
|
|
|
2712
2703
|
// src/to-json-schema/zod3-to-json-schema/select-parser.ts
|
|
2713
2704
|
var selectParser = (def, typeName, refs) => {
|
|
2714
2705
|
switch (typeName) {
|
|
2715
|
-
case
|
|
2706
|
+
case "ZodString":
|
|
2716
2707
|
return parseStringDef(def, refs);
|
|
2717
|
-
case
|
|
2708
|
+
case "ZodNumber":
|
|
2718
2709
|
return parseNumberDef(def);
|
|
2719
|
-
case
|
|
2710
|
+
case "ZodObject":
|
|
2720
2711
|
return parseObjectDef(def, refs);
|
|
2721
|
-
case
|
|
2712
|
+
case "ZodBigInt":
|
|
2722
2713
|
return parseBigintDef(def);
|
|
2723
|
-
case
|
|
2714
|
+
case "ZodBoolean":
|
|
2724
2715
|
return parseBooleanDef();
|
|
2725
|
-
case
|
|
2716
|
+
case "ZodDate":
|
|
2726
2717
|
return parseDateDef(def, refs);
|
|
2727
|
-
case
|
|
2718
|
+
case "ZodUndefined":
|
|
2728
2719
|
return parseUndefinedDef();
|
|
2729
|
-
case
|
|
2720
|
+
case "ZodNull":
|
|
2730
2721
|
return parseNullDef();
|
|
2731
|
-
case
|
|
2722
|
+
case "ZodArray":
|
|
2732
2723
|
return parseArrayDef(def, refs);
|
|
2733
|
-
case
|
|
2734
|
-
case
|
|
2724
|
+
case "ZodUnion":
|
|
2725
|
+
case "ZodDiscriminatedUnion":
|
|
2735
2726
|
return parseUnionDef(def, refs);
|
|
2736
|
-
case
|
|
2727
|
+
case "ZodIntersection":
|
|
2737
2728
|
return parseIntersectionDef(def, refs);
|
|
2738
|
-
case
|
|
2729
|
+
case "ZodTuple":
|
|
2739
2730
|
return parseTupleDef(def, refs);
|
|
2740
|
-
case
|
|
2731
|
+
case "ZodRecord":
|
|
2741
2732
|
return parseRecordDef(def, refs);
|
|
2742
|
-
case
|
|
2733
|
+
case "ZodLiteral":
|
|
2743
2734
|
return parseLiteralDef(def);
|
|
2744
|
-
case
|
|
2735
|
+
case "ZodEnum":
|
|
2745
2736
|
return parseEnumDef(def);
|
|
2746
|
-
case
|
|
2737
|
+
case "ZodNativeEnum":
|
|
2747
2738
|
return parseNativeEnumDef(def);
|
|
2748
|
-
case
|
|
2739
|
+
case "ZodNullable":
|
|
2749
2740
|
return parseNullableDef(def, refs);
|
|
2750
|
-
case
|
|
2741
|
+
case "ZodOptional":
|
|
2751
2742
|
return parseOptionalDef(def, refs);
|
|
2752
|
-
case
|
|
2743
|
+
case "ZodMap":
|
|
2753
2744
|
return parseMapDef(def, refs);
|
|
2754
|
-
case
|
|
2745
|
+
case "ZodSet":
|
|
2755
2746
|
return parseSetDef(def, refs);
|
|
2756
|
-
case
|
|
2747
|
+
case "ZodLazy":
|
|
2757
2748
|
return () => def.getter()._def;
|
|
2758
|
-
case
|
|
2749
|
+
case "ZodPromise":
|
|
2759
2750
|
return parsePromiseDef(def, refs);
|
|
2760
|
-
case
|
|
2761
|
-
case
|
|
2751
|
+
case "ZodNaN":
|
|
2752
|
+
case "ZodNever":
|
|
2762
2753
|
return parseNeverDef();
|
|
2763
|
-
case
|
|
2754
|
+
case "ZodEffects":
|
|
2764
2755
|
return parseEffectsDef(def, refs);
|
|
2765
|
-
case
|
|
2756
|
+
case "ZodAny":
|
|
2766
2757
|
return parseAnyDef();
|
|
2767
|
-
case
|
|
2758
|
+
case "ZodUnknown":
|
|
2768
2759
|
return parseUnknownDef();
|
|
2769
|
-
case
|
|
2760
|
+
case "ZodDefault":
|
|
2770
2761
|
return parseDefaultDef(def, refs);
|
|
2771
|
-
case
|
|
2762
|
+
case "ZodBranded":
|
|
2772
2763
|
return parseBrandedDef(def, refs);
|
|
2773
|
-
case
|
|
2764
|
+
case "ZodReadonly":
|
|
2774
2765
|
return parseReadonlyDef(def, refs);
|
|
2775
|
-
case
|
|
2766
|
+
case "ZodCatch":
|
|
2776
2767
|
return parseCatchDef(def, refs);
|
|
2777
|
-
case
|
|
2768
|
+
case "ZodPipeline":
|
|
2778
2769
|
return parsePipelineDef(def, refs);
|
|
2779
|
-
case
|
|
2780
|
-
case
|
|
2781
|
-
case
|
|
2770
|
+
case "ZodFunction":
|
|
2771
|
+
case "ZodVoid":
|
|
2772
|
+
case "ZodSymbol":
|
|
2782
2773
|
return void 0;
|
|
2783
2774
|
default:
|
|
2784
2775
|
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
@@ -3739,7 +3730,9 @@ import {
|
|
|
3739
3730
|
} from "@ai-sdk/provider";
|
|
3740
3731
|
var StreamingToolCallTracker = class {
|
|
3741
3732
|
constructor(controller, options = {}) {
|
|
3742
|
-
this.toolCalls =
|
|
3733
|
+
this.toolCalls = /* @__PURE__ */ new Set();
|
|
3734
|
+
this.toolCallsById = /* @__PURE__ */ new Map();
|
|
3735
|
+
this.toolCallsByIndex = /* @__PURE__ */ new Map();
|
|
3743
3736
|
var _a3, _b3;
|
|
3744
3737
|
this.controller = controller;
|
|
3745
3738
|
this._generateId = (_a3 = options.generateId) != null ? _a3 : generateId;
|
|
@@ -3753,13 +3746,17 @@ var StreamingToolCallTracker = class {
|
|
|
3753
3746
|
* events as appropriate.
|
|
3754
3747
|
*/
|
|
3755
3748
|
processDelta(toolCallDelta) {
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
if (
|
|
3759
|
-
this.processNewToolCall(
|
|
3749
|
+
const { id, index } = toolCallDelta;
|
|
3750
|
+
let toolCall = id != null && id.length > 0 ? this.toolCallsById.get(id) : index != null ? this.toolCallsByIndex.get(index) : this.latestToolCall;
|
|
3751
|
+
if (toolCall == null) {
|
|
3752
|
+
toolCall = this.processNewToolCall(toolCallDelta);
|
|
3760
3753
|
} else {
|
|
3761
|
-
this.processExistingToolCall(
|
|
3754
|
+
this.processExistingToolCall(toolCall, toolCallDelta);
|
|
3762
3755
|
}
|
|
3756
|
+
if (index != null) {
|
|
3757
|
+
this.toolCallsByIndex.set(index, toolCall);
|
|
3758
|
+
}
|
|
3759
|
+
this.latestToolCall = toolCall;
|
|
3763
3760
|
}
|
|
3764
3761
|
/**
|
|
3765
3762
|
* Finalize any unfinished tool calls. Should be called during the stream's
|
|
@@ -3772,7 +3769,7 @@ var StreamingToolCallTracker = class {
|
|
|
3772
3769
|
}
|
|
3773
3770
|
}
|
|
3774
3771
|
}
|
|
3775
|
-
processNewToolCall(
|
|
3772
|
+
processNewToolCall(toolCallDelta) {
|
|
3776
3773
|
var _a3, _b3, _c;
|
|
3777
3774
|
if (this.typeValidation === "required") {
|
|
3778
3775
|
if (toolCallDelta.type !== "function") {
|
|
@@ -3807,7 +3804,7 @@ var StreamingToolCallTracker = class {
|
|
|
3807
3804
|
toolName: toolCallDelta.function.name
|
|
3808
3805
|
});
|
|
3809
3806
|
const metadata = (_b3 = this.extractMetadata) == null ? void 0 : _b3.call(this, toolCallDelta);
|
|
3810
|
-
|
|
3807
|
+
const toolCall = {
|
|
3811
3808
|
id: toolCallDelta.id,
|
|
3812
3809
|
type: "function",
|
|
3813
3810
|
function: {
|
|
@@ -3817,7 +3814,10 @@ var StreamingToolCallTracker = class {
|
|
|
3817
3814
|
hasFinished: false,
|
|
3818
3815
|
metadata
|
|
3819
3816
|
};
|
|
3820
|
-
|
|
3817
|
+
this.toolCalls.add(toolCall);
|
|
3818
|
+
if (toolCall.id.length > 0) {
|
|
3819
|
+
this.toolCallsById.set(toolCall.id, toolCall);
|
|
3820
|
+
}
|
|
3821
3821
|
if (toolCall.function.arguments.length > 0) {
|
|
3822
3822
|
this.controller.enqueue({
|
|
3823
3823
|
type: "tool-input-delta",
|
|
@@ -3825,10 +3825,10 @@ var StreamingToolCallTracker = class {
|
|
|
3825
3825
|
delta: toolCall.function.arguments
|
|
3826
3826
|
});
|
|
3827
3827
|
}
|
|
3828
|
+
return toolCall;
|
|
3828
3829
|
}
|
|
3829
|
-
processExistingToolCall(
|
|
3830
|
+
processExistingToolCall(toolCall, toolCallDelta) {
|
|
3830
3831
|
var _a3;
|
|
3831
|
-
const toolCall = this.toolCalls[index];
|
|
3832
3832
|
if (toolCall.hasFinished) {
|
|
3833
3833
|
return;
|
|
3834
3834
|
}
|