ai 6.0.214 → 6.0.216

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,21 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.216
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [f6689df]
8
+ - Updated dependencies [13b6a72]
9
+ - @ai-sdk/gateway@3.0.140
10
+
11
+ ## 6.0.215
12
+
13
+ ### Patch Changes
14
+
15
+ - f66ac32: fix(ai): prune orphaned tool-approval responses in `pruneMessages`
16
+
17
+ When pruning a specific tool by name (`toolCalls: [{ type, tools: [...] }]`), `pruneMessages` left the tool's `tool-approval-response` in place while removing its `tool-approval-request` and `tool-call`. The tool name of an approval response was resolved per-message, but approval responses live in a separate `tool` message from their approval request, so the name could never be resolved and the response was always kept. Tool name resolution is now done across all messages, so approval requests and responses are pruned together.
18
+
3
19
  ## 6.0.214
4
20
 
5
21
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1281,7 +1281,7 @@ function detectMediaType({
1281
1281
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
1282
1282
 
1283
1283
  // src/version.ts
1284
- var VERSION = true ? "6.0.214" : "0.0.0-test";
1284
+ var VERSION = true ? "6.0.216" : "0.0.0-test";
1285
1285
 
1286
1286
  // src/util/download/download.ts
1287
1287
  var download = async ({
@@ -11733,29 +11733,44 @@ function pruneMessages({
11733
11733
  }
11734
11734
  }
11735
11735
  }
11736
+ const toolCallIdToToolName = /* @__PURE__ */ new Map();
11737
+ for (const message of messages) {
11738
+ if ((message.role === "assistant" || message.role === "tool") && typeof message.content !== "string") {
11739
+ for (const part of message.content) {
11740
+ if (part.type === "tool-call" || part.type === "tool-result") {
11741
+ toolCallIdToToolName.set(part.toolCallId, part.toolName);
11742
+ }
11743
+ }
11744
+ }
11745
+ }
11746
+ const approvalIdToToolName = /* @__PURE__ */ new Map();
11747
+ for (const message of messages) {
11748
+ if ((message.role === "assistant" || message.role === "tool") && typeof message.content !== "string") {
11749
+ for (const part of message.content) {
11750
+ if (part.type === "tool-approval-request") {
11751
+ const toolName = toolCallIdToToolName.get(part.toolCallId);
11752
+ if (toolName != null) {
11753
+ approvalIdToToolName.set(part.approvalId, toolName);
11754
+ }
11755
+ }
11756
+ }
11757
+ }
11758
+ }
11736
11759
  messages = messages.map((message, messageIndex) => {
11737
11760
  if (message.role !== "assistant" && message.role !== "tool" || typeof message.content === "string" || keepLastMessagesCount && messageIndex >= messages.length - keepLastMessagesCount) {
11738
11761
  return message;
11739
11762
  }
11740
- const toolCallIdToToolName = {};
11741
- const approvalIdToToolName = {};
11742
11763
  return {
11743
11764
  ...message,
11744
11765
  content: message.content.filter((part) => {
11745
11766
  if (part.type !== "tool-call" && part.type !== "tool-result" && part.type !== "tool-approval-request" && part.type !== "tool-approval-response") {
11746
11767
  return true;
11747
11768
  }
11748
- if (part.type === "tool-call") {
11749
- toolCallIdToToolName[part.toolCallId] = part.toolName;
11750
- } else if (part.type === "tool-approval-request") {
11751
- approvalIdToToolName[part.approvalId] = toolCallIdToToolName[part.toolCallId];
11752
- }
11753
11769
  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)) {
11754
11770
  return true;
11755
11771
  }
11756
- return toolCall.tools != null && !toolCall.tools.includes(
11757
- part.type === "tool-call" || part.type === "tool-result" ? part.toolName : approvalIdToToolName[part.approvalId]
11758
- );
11772
+ const partToolName = part.type === "tool-call" || part.type === "tool-result" ? part.toolName : approvalIdToToolName.get(part.approvalId);
11773
+ return toolCall.tools != null && partToolName != null && !toolCall.tools.includes(partToolName);
11759
11774
  })
11760
11775
  };
11761
11776
  });