ai 6.0.311 → 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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.313
4
+
5
+ ### Patch Changes
6
+
7
+ - 52803fb: fix(ai): process only the first approval response per tool call, so repeated or conflicting responses in the final tool message no longer execute a tool twice or both execute and deny it
8
+ - a0f7494: fix(ai): remove orphaned reasoning, including consecutive reasoning parts, when pruning tool calls
9
+ - a48e8a9: fix(ai): preserve repaired tool names in streamed UI message parts
10
+ - Updated dependencies [fa49238]
11
+ - Updated dependencies [d301a16]
12
+ - Updated dependencies [965effe]
13
+ - Updated dependencies [4f82ab0]
14
+ - @ai-sdk/gateway@3.0.220
15
+
16
+ ## 6.0.312
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [1183cc4]
21
+ - Updated dependencies [ae8a8d4]
22
+ - Updated dependencies [93e9720]
23
+ - Updated dependencies [d726591]
24
+ - @ai-sdk/provider-utils@4.0.62
25
+ - @ai-sdk/gateway@3.0.219
26
+
3
27
  ## 6.0.311
4
28
 
5
29
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1335,7 +1335,7 @@ function detectMediaType({
1335
1335
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
1336
1336
 
1337
1337
  // src/version.ts
1338
- var VERSION = true ? "6.0.311" : "0.0.0-test";
1338
+ var VERSION = true ? "6.0.313" : "0.0.0-test";
1339
1339
 
1340
1340
  // src/util/download/download.ts
1341
1341
  var download = async ({
@@ -2976,6 +2976,7 @@ function collectToolApprovals({
2976
2976
  }
2977
2977
  const approvedToolApprovals = [];
2978
2978
  const deniedToolApprovals = [];
2979
+ const collectedToolCallIds = /* @__PURE__ */ new Set();
2979
2980
  const approvalResponses = lastMessage.content.filter(
2980
2981
  (part) => part.type === "tool-approval-response"
2981
2982
  );
@@ -2996,6 +2997,10 @@ function collectToolApprovals({
2996
2997
  approvalId: approvalRequest.approvalId
2997
2998
  });
2998
2999
  }
3000
+ if (collectedToolCallIds.has(toolCall.toolCallId)) {
3001
+ continue;
3002
+ }
3003
+ collectedToolCallIds.add(toolCall.toolCallId);
2999
3004
  const approval = {
3000
3005
  approvalRequest,
3001
3006
  approvalResponse,
@@ -6148,6 +6153,7 @@ function processUIMessageStream({
6148
6153
  const anyPart = part;
6149
6154
  if (part != null) {
6150
6155
  part.state = options.state;
6156
+ anyPart.type = `tool-${options.toolName}`;
6151
6157
  anyPart.input = anyOptions.input;
6152
6158
  anyPart.output = anyOptions.output;
6153
6159
  anyPart.errorText = anyOptions.errorText;
@@ -12840,18 +12846,53 @@ function pruneMessages({
12840
12846
  if (message.role !== "assistant" && message.role !== "tool" || typeof message.content === "string" || keepLastMessagesCount && messageIndex >= messages.length - keepLastMessagesCount) {
12841
12847
  return message;
12842
12848
  }
12843
- return {
12844
- ...message,
12845
- content: message.content.filter((part) => {
12846
- if (part.type !== "tool-call" && part.type !== "tool-result" && part.type !== "tool-approval-request" && part.type !== "tool-approval-response") {
12847
- return true;
12849
+ const keepParts = message.content.map((part) => {
12850
+ if (part.type !== "tool-call" && part.type !== "tool-result" && part.type !== "tool-approval-request" && part.type !== "tool-approval-response") {
12851
+ return true;
12852
+ }
12853
+ 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)) {
12854
+ return true;
12855
+ }
12856
+ const partToolName = part.type === "tool-call" || part.type === "tool-result" ? part.toolName : approvalIdToToolName.get(part.approvalId);
12857
+ return toolCall.tools != null && partToolName != null && !toolCall.tools.includes(partToolName);
12858
+ });
12859
+ if (message.role === "assistant") {
12860
+ for (let reasoningIndex = 0; reasoningIndex < message.content.length; reasoningIndex++) {
12861
+ const part = message.content[reasoningIndex];
12862
+ if (part.type !== "reasoning") {
12863
+ continue;
12864
+ }
12865
+ let reasoningEndIndex = reasoningIndex + 1;
12866
+ while (reasoningEndIndex < message.content.length) {
12867
+ const nextPart = message.content[reasoningEndIndex];
12868
+ if (nextPart.type !== "reasoning") {
12869
+ break;
12870
+ }
12871
+ reasoningEndIndex++;
12848
12872
  }
12849
- 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)) {
12850
- return true;
12873
+ let followingPartIndex = reasoningEndIndex;
12874
+ let hasFollowingPart = false;
12875
+ let hasKeptFollowingPart = false;
12876
+ while (followingPartIndex < message.content.length) {
12877
+ const followingPart = message.content[followingPartIndex];
12878
+ if (followingPart.type === "reasoning") {
12879
+ break;
12880
+ }
12881
+ hasFollowingPart = true;
12882
+ hasKeptFollowingPart || (hasKeptFollowingPart = keepParts[followingPartIndex]);
12883
+ followingPartIndex++;
12851
12884
  }
12852
- const partToolName = part.type === "tool-call" || part.type === "tool-result" ? part.toolName : approvalIdToToolName.get(part.approvalId);
12853
- return toolCall.tools != null && partToolName != null && !toolCall.tools.includes(partToolName);
12854
- })
12885
+ if (hasFollowingPart && !hasKeptFollowingPart) {
12886
+ for (let index = reasoningIndex; index < reasoningEndIndex; index++) {
12887
+ keepParts[index] = false;
12888
+ }
12889
+ }
12890
+ reasoningIndex = followingPartIndex - 1;
12891
+ }
12892
+ }
12893
+ return {
12894
+ ...message,
12895
+ content: message.content.filter((_, index) => keepParts[index])
12855
12896
  };
12856
12897
  });
12857
12898
  }