ai 5.0.22 → 5.0.23
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 +10 -0
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +65 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
@@ -3267,9 +3267,18 @@ async function parsePartialJson(jsonText) {
|
|
3267
3267
|
function isToolUIPart(part) {
|
3268
3268
|
return part.type.startsWith("tool-");
|
3269
3269
|
}
|
3270
|
+
function isDynamicToolUIPart(part) {
|
3271
|
+
return part.type === "dynamic-tool";
|
3272
|
+
}
|
3273
|
+
function isToolOrDynamicToolUIPart(part) {
|
3274
|
+
return isToolUIPart(part) || isDynamicToolUIPart(part);
|
3275
|
+
}
|
3270
3276
|
function getToolName(part) {
|
3271
3277
|
return part.type.split("-").slice(1).join("-");
|
3272
3278
|
}
|
3279
|
+
function getToolOrDynamicToolName(part) {
|
3280
|
+
return isDynamicToolUIPart(part) ? part.toolName : getToolName(part);
|
3281
|
+
}
|
3273
3282
|
|
3274
3283
|
// src/ui/process-ui-message-stream.ts
|
3275
3284
|
function createStreamingUIMessageState({
|
@@ -3816,12 +3825,57 @@ function pipeUIMessageStreamToResponse({
|
|
3816
3825
|
// src/util/async-iterable-stream.ts
|
3817
3826
|
function createAsyncIterableStream(source) {
|
3818
3827
|
const stream = source.pipeThrough(new TransformStream());
|
3819
|
-
stream[Symbol.asyncIterator] = ()
|
3820
|
-
const reader =
|
3828
|
+
stream[Symbol.asyncIterator] = function() {
|
3829
|
+
const reader = this.getReader();
|
3830
|
+
let finished = false;
|
3831
|
+
async function cleanup(cancelStream) {
|
3832
|
+
var _a17;
|
3833
|
+
finished = true;
|
3834
|
+
try {
|
3835
|
+
if (cancelStream) {
|
3836
|
+
await ((_a17 = reader.cancel) == null ? void 0 : _a17.call(reader));
|
3837
|
+
}
|
3838
|
+
} finally {
|
3839
|
+
try {
|
3840
|
+
reader.releaseLock();
|
3841
|
+
} catch (e) {
|
3842
|
+
}
|
3843
|
+
}
|
3844
|
+
}
|
3821
3845
|
return {
|
3846
|
+
/**
|
3847
|
+
* Reads the next chunk from the stream.
|
3848
|
+
* @returns A promise resolving to the next IteratorResult.
|
3849
|
+
*/
|
3822
3850
|
async next() {
|
3851
|
+
if (finished) {
|
3852
|
+
return { done: true, value: void 0 };
|
3853
|
+
}
|
3823
3854
|
const { done, value } = await reader.read();
|
3824
|
-
|
3855
|
+
if (done) {
|
3856
|
+
await cleanup(true);
|
3857
|
+
return { done: true, value: void 0 };
|
3858
|
+
}
|
3859
|
+
return { done: false, value };
|
3860
|
+
},
|
3861
|
+
/**
|
3862
|
+
* Called on early exit (e.g., break from for-await).
|
3863
|
+
* Ensures the stream is cancelled and resources are released.
|
3864
|
+
* @returns A promise resolving to a completed IteratorResult.
|
3865
|
+
*/
|
3866
|
+
async return() {
|
3867
|
+
await cleanup(true);
|
3868
|
+
return { done: true, value: void 0 };
|
3869
|
+
},
|
3870
|
+
/**
|
3871
|
+
* Called on early exit with error.
|
3872
|
+
* Ensures the stream is cancelled and resources are released, then rethrows the error.
|
3873
|
+
* @param err The error to throw.
|
3874
|
+
* @returns A promise that rejects with the provided error.
|
3875
|
+
*/
|
3876
|
+
async throw(err) {
|
3877
|
+
await cleanup(true);
|
3878
|
+
throw err;
|
3825
3879
|
}
|
3826
3880
|
};
|
3827
3881
|
};
|
@@ -9250,12 +9304,12 @@ var AbstractChat = class {
|
|
9250
9304
|
this.state.replaceMessage(messages.length - 1, {
|
9251
9305
|
...lastMessage,
|
9252
9306
|
parts: lastMessage.parts.map(
|
9253
|
-
(part) =>
|
9307
|
+
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state: "output-available", output } : part
|
9254
9308
|
)
|
9255
9309
|
});
|
9256
9310
|
if (this.activeResponse) {
|
9257
9311
|
this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(
|
9258
|
-
(part) =>
|
9312
|
+
(part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? {
|
9259
9313
|
...part,
|
9260
9314
|
state: "output-available",
|
9261
9315
|
output,
|
@@ -9439,7 +9493,7 @@ function convertToModelMessages(messages, options) {
|
|
9439
9493
|
messages = messages.map((message) => ({
|
9440
9494
|
...message,
|
9441
9495
|
parts: message.parts.filter(
|
9442
|
-
(part) => !
|
9496
|
+
(part) => !isToolOrDynamicToolUIPart(part) || part.state !== "input-streaming" && part.state !== "input-available"
|
9443
9497
|
)
|
9444
9498
|
}));
|
9445
9499
|
}
|
@@ -9646,7 +9700,7 @@ function lastAssistantMessageIsCompleteWithToolCalls({
|
|
9646
9700
|
const lastStepStartIndex = message.parts.reduce((lastIndex, part, index) => {
|
9647
9701
|
return part.type === "step-start" ? index : lastIndex;
|
9648
9702
|
}, -1);
|
9649
|
-
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(
|
9703
|
+
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolOrDynamicToolUIPart);
|
9650
9704
|
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => part.state === "output-available");
|
9651
9705
|
}
|
9652
9706
|
|
@@ -10111,8 +10165,10 @@ export {
|
|
10111
10165
|
generateText,
|
10112
10166
|
getTextFromDataUrl,
|
10113
10167
|
getToolName,
|
10168
|
+
getToolOrDynamicToolName,
|
10114
10169
|
hasToolCall,
|
10115
10170
|
isDeepEqualData,
|
10171
|
+
isToolOrDynamicToolUIPart,
|
10116
10172
|
isToolUIPart,
|
10117
10173
|
jsonSchema2 as jsonSchema,
|
10118
10174
|
lastAssistantMessageIsCompleteWithToolCalls,
|