@ai-sdk/provider-utils 5.0.20 → 5.0.22
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 +4 -1
- package/dist/index.js +21 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/post-to-api.ts +1 -1
- package/src/streaming-tool-call-tracker.ts +31 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 5.0.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2b60826: feat(provider-utils): support Blob request bodies in postToApi
|
|
8
|
+
|
|
9
|
+
## 5.0.21
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 1bec07d: Fix streamed tool calls with non-zero, non-contiguous, reused, or missing indexes.
|
|
14
|
+
|
|
3
15
|
## 5.0.20
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1369,7 +1369,7 @@ declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, fa
|
|
|
1369
1369
|
url: string;
|
|
1370
1370
|
headers?: Record<string, string | undefined>;
|
|
1371
1371
|
body: {
|
|
1372
|
-
content: string | FormData | Uint8Array;
|
|
1372
|
+
content: string | FormData | Uint8Array | Blob;
|
|
1373
1373
|
values: unknown;
|
|
1374
1374
|
};
|
|
1375
1375
|
failedResponseHandler: ResponseHandler<Error>;
|
|
@@ -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.22" : "0.0.0-test";
|
|
1329
1329
|
|
|
1330
1330
|
// src/get-from-api.ts
|
|
1331
1331
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -3730,7 +3730,9 @@ import {
|
|
|
3730
3730
|
} from "@ai-sdk/provider";
|
|
3731
3731
|
var StreamingToolCallTracker = class {
|
|
3732
3732
|
constructor(controller, options = {}) {
|
|
3733
|
-
this.toolCalls =
|
|
3733
|
+
this.toolCalls = /* @__PURE__ */ new Set();
|
|
3734
|
+
this.toolCallsById = /* @__PURE__ */ new Map();
|
|
3735
|
+
this.toolCallsByIndex = /* @__PURE__ */ new Map();
|
|
3734
3736
|
var _a3, _b3;
|
|
3735
3737
|
this.controller = controller;
|
|
3736
3738
|
this._generateId = (_a3 = options.generateId) != null ? _a3 : generateId;
|
|
@@ -3744,13 +3746,17 @@ var StreamingToolCallTracker = class {
|
|
|
3744
3746
|
* events as appropriate.
|
|
3745
3747
|
*/
|
|
3746
3748
|
processDelta(toolCallDelta) {
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
if (
|
|
3750
|
-
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);
|
|
3751
3753
|
} else {
|
|
3752
|
-
this.processExistingToolCall(
|
|
3754
|
+
this.processExistingToolCall(toolCall, toolCallDelta);
|
|
3755
|
+
}
|
|
3756
|
+
if (index != null) {
|
|
3757
|
+
this.toolCallsByIndex.set(index, toolCall);
|
|
3753
3758
|
}
|
|
3759
|
+
this.latestToolCall = toolCall;
|
|
3754
3760
|
}
|
|
3755
3761
|
/**
|
|
3756
3762
|
* Finalize any unfinished tool calls. Should be called during the stream's
|
|
@@ -3763,7 +3769,7 @@ var StreamingToolCallTracker = class {
|
|
|
3763
3769
|
}
|
|
3764
3770
|
}
|
|
3765
3771
|
}
|
|
3766
|
-
processNewToolCall(
|
|
3772
|
+
processNewToolCall(toolCallDelta) {
|
|
3767
3773
|
var _a3, _b3, _c;
|
|
3768
3774
|
if (this.typeValidation === "required") {
|
|
3769
3775
|
if (toolCallDelta.type !== "function") {
|
|
@@ -3798,7 +3804,7 @@ var StreamingToolCallTracker = class {
|
|
|
3798
3804
|
toolName: toolCallDelta.function.name
|
|
3799
3805
|
});
|
|
3800
3806
|
const metadata = (_b3 = this.extractMetadata) == null ? void 0 : _b3.call(this, toolCallDelta);
|
|
3801
|
-
|
|
3807
|
+
const toolCall = {
|
|
3802
3808
|
id: toolCallDelta.id,
|
|
3803
3809
|
type: "function",
|
|
3804
3810
|
function: {
|
|
@@ -3808,7 +3814,10 @@ var StreamingToolCallTracker = class {
|
|
|
3808
3814
|
hasFinished: false,
|
|
3809
3815
|
metadata
|
|
3810
3816
|
};
|
|
3811
|
-
|
|
3817
|
+
this.toolCalls.add(toolCall);
|
|
3818
|
+
if (toolCall.id.length > 0) {
|
|
3819
|
+
this.toolCallsById.set(toolCall.id, toolCall);
|
|
3820
|
+
}
|
|
3812
3821
|
if (toolCall.function.arguments.length > 0) {
|
|
3813
3822
|
this.controller.enqueue({
|
|
3814
3823
|
type: "tool-input-delta",
|
|
@@ -3816,10 +3825,10 @@ var StreamingToolCallTracker = class {
|
|
|
3816
3825
|
delta: toolCall.function.arguments
|
|
3817
3826
|
});
|
|
3818
3827
|
}
|
|
3828
|
+
return toolCall;
|
|
3819
3829
|
}
|
|
3820
|
-
processExistingToolCall(
|
|
3830
|
+
processExistingToolCall(toolCall, toolCallDelta) {
|
|
3821
3831
|
var _a3;
|
|
3822
|
-
const toolCall = this.toolCalls[index];
|
|
3823
3832
|
if (toolCall.hasFinished) {
|
|
3824
3833
|
return;
|
|
3825
3834
|
}
|