ai 6.0.312 → 6.0.313
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 +13 -0
- package/dist/index.js +52 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -11
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/03-ai-sdk-core/37-speech.mdx +1 -0
- package/package.json +2 -2
- package/src/generate-text/collect-tool-approvals.ts +10 -0
- package/src/generate-text/prune-messages.ts +85 -32
- package/src/ui/process-ui-message-stream.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -1225,7 +1225,7 @@ import {
|
|
|
1225
1225
|
} from "@ai-sdk/provider-utils";
|
|
1226
1226
|
|
|
1227
1227
|
// src/version.ts
|
|
1228
|
-
var VERSION = true ? "6.0.
|
|
1228
|
+
var VERSION = true ? "6.0.313" : "0.0.0-test";
|
|
1229
1229
|
|
|
1230
1230
|
// src/util/download/download.ts
|
|
1231
1231
|
var download = async ({
|
|
@@ -2876,6 +2876,7 @@ function collectToolApprovals({
|
|
|
2876
2876
|
}
|
|
2877
2877
|
const approvedToolApprovals = [];
|
|
2878
2878
|
const deniedToolApprovals = [];
|
|
2879
|
+
const collectedToolCallIds = /* @__PURE__ */ new Set();
|
|
2879
2880
|
const approvalResponses = lastMessage.content.filter(
|
|
2880
2881
|
(part) => part.type === "tool-approval-response"
|
|
2881
2882
|
);
|
|
@@ -2896,6 +2897,10 @@ function collectToolApprovals({
|
|
|
2896
2897
|
approvalId: approvalRequest.approvalId
|
|
2897
2898
|
});
|
|
2898
2899
|
}
|
|
2900
|
+
if (collectedToolCallIds.has(toolCall.toolCallId)) {
|
|
2901
|
+
continue;
|
|
2902
|
+
}
|
|
2903
|
+
collectedToolCallIds.add(toolCall.toolCallId);
|
|
2899
2904
|
const approval = {
|
|
2900
2905
|
approvalRequest,
|
|
2901
2906
|
approvalResponse,
|
|
@@ -6075,6 +6080,7 @@ function processUIMessageStream({
|
|
|
6075
6080
|
const anyPart = part;
|
|
6076
6081
|
if (part != null) {
|
|
6077
6082
|
part.state = options.state;
|
|
6083
|
+
anyPart.type = `tool-${options.toolName}`;
|
|
6078
6084
|
anyPart.input = anyOptions.input;
|
|
6079
6085
|
anyPart.output = anyOptions.output;
|
|
6080
6086
|
anyPart.errorText = anyOptions.errorText;
|
|
@@ -12805,18 +12811,53 @@ function pruneMessages({
|
|
|
12805
12811
|
if (message.role !== "assistant" && message.role !== "tool" || typeof message.content === "string" || keepLastMessagesCount && messageIndex >= messages.length - keepLastMessagesCount) {
|
|
12806
12812
|
return message;
|
|
12807
12813
|
}
|
|
12808
|
-
|
|
12809
|
-
|
|
12810
|
-
|
|
12811
|
-
|
|
12812
|
-
|
|
12814
|
+
const keepParts = message.content.map((part) => {
|
|
12815
|
+
if (part.type !== "tool-call" && part.type !== "tool-result" && part.type !== "tool-approval-request" && part.type !== "tool-approval-response") {
|
|
12816
|
+
return true;
|
|
12817
|
+
}
|
|
12818
|
+
if ((part.type === "tool-call" || part.type === "tool-result") && keptToolCallIds.has(part.toolCallId) || (part.type === "tool-approval-request" || part.type === "tool-approval-response") && keptApprovalIds.has(part.approvalId)) {
|
|
12819
|
+
return true;
|
|
12820
|
+
}
|
|
12821
|
+
const partToolName = part.type === "tool-call" || part.type === "tool-result" ? part.toolName : approvalIdToToolName.get(part.approvalId);
|
|
12822
|
+
return toolCall.tools != null && partToolName != null && !toolCall.tools.includes(partToolName);
|
|
12823
|
+
});
|
|
12824
|
+
if (message.role === "assistant") {
|
|
12825
|
+
for (let reasoningIndex = 0; reasoningIndex < message.content.length; reasoningIndex++) {
|
|
12826
|
+
const part = message.content[reasoningIndex];
|
|
12827
|
+
if (part.type !== "reasoning") {
|
|
12828
|
+
continue;
|
|
12829
|
+
}
|
|
12830
|
+
let reasoningEndIndex = reasoningIndex + 1;
|
|
12831
|
+
while (reasoningEndIndex < message.content.length) {
|
|
12832
|
+
const nextPart = message.content[reasoningEndIndex];
|
|
12833
|
+
if (nextPart.type !== "reasoning") {
|
|
12834
|
+
break;
|
|
12835
|
+
}
|
|
12836
|
+
reasoningEndIndex++;
|
|
12813
12837
|
}
|
|
12814
|
-
|
|
12815
|
-
|
|
12838
|
+
let followingPartIndex = reasoningEndIndex;
|
|
12839
|
+
let hasFollowingPart = false;
|
|
12840
|
+
let hasKeptFollowingPart = false;
|
|
12841
|
+
while (followingPartIndex < message.content.length) {
|
|
12842
|
+
const followingPart = message.content[followingPartIndex];
|
|
12843
|
+
if (followingPart.type === "reasoning") {
|
|
12844
|
+
break;
|
|
12845
|
+
}
|
|
12846
|
+
hasFollowingPart = true;
|
|
12847
|
+
hasKeptFollowingPart || (hasKeptFollowingPart = keepParts[followingPartIndex]);
|
|
12848
|
+
followingPartIndex++;
|
|
12816
12849
|
}
|
|
12817
|
-
|
|
12818
|
-
|
|
12819
|
-
|
|
12850
|
+
if (hasFollowingPart && !hasKeptFollowingPart) {
|
|
12851
|
+
for (let index = reasoningIndex; index < reasoningEndIndex; index++) {
|
|
12852
|
+
keepParts[index] = false;
|
|
12853
|
+
}
|
|
12854
|
+
}
|
|
12855
|
+
reasoningIndex = followingPartIndex - 1;
|
|
12856
|
+
}
|
|
12857
|
+
}
|
|
12858
|
+
return {
|
|
12859
|
+
...message,
|
|
12860
|
+
content: message.content.filter((_, index) => keepParts[index])
|
|
12820
12861
|
};
|
|
12821
12862
|
});
|
|
12822
12863
|
}
|