ai 7.0.4 → 7.0.6

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
+ ## 7.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 989402d: Add ToolLoopAgent types for deprecated tool call callback aliases.
8
+ - Updated dependencies [7e3c99e]
9
+ - @ai-sdk/gateway@4.0.5
10
+
11
+ ## 7.0.5
12
+
13
+ ### Patch Changes
14
+
15
+ - a2750db: 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
  ## 7.0.4
4
20
 
5
21
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -4642,10 +4642,22 @@ type AgentCallParameters<CALL_OPTIONS, TOOLS extends ToolSet = {}, RUNTIME_CONTE
4642
4642
  * Callback that is called before each tool execution begins.
4643
4643
  */
4644
4644
  onToolExecutionStart?: OnToolExecutionStartCallback<TOOLS>;
4645
+ /**
4646
+ * Callback that is called before each tool execution begins.
4647
+ *
4648
+ * @deprecated Use `onToolExecutionStart` instead.
4649
+ */
4650
+ experimental_onToolCallStart?: OnToolExecutionStartCallback<TOOLS>;
4645
4651
  /**
4646
4652
  * Callback that is called after each tool execution completes.
4647
4653
  */
4648
4654
  onToolExecutionEnd?: OnToolExecutionEndCallback<TOOLS>;
4655
+ /**
4656
+ * Callback that is called after each tool execution completes.
4657
+ *
4658
+ * @deprecated Use `onToolExecutionEnd` instead.
4659
+ */
4660
+ experimental_onToolCallFinish?: OnToolExecutionEndCallback<TOOLS>;
4649
4661
  /**
4650
4662
  * Callback that is called when each step (LLM call) ends, including intermediate steps.
4651
4663
  */
package/dist/index.js CHANGED
@@ -1089,7 +1089,7 @@ import {
1089
1089
  } from "@ai-sdk/provider-utils";
1090
1090
 
1091
1091
  // src/version.ts
1092
- var VERSION = true ? "7.0.4" : "0.0.0-test";
1092
+ var VERSION = true ? "7.0.6" : "0.0.0-test";
1093
1093
 
1094
1094
  // src/util/download/download.ts
1095
1095
  var download = async ({
@@ -13262,29 +13262,44 @@ function pruneMessages({
13262
13262
  }
13263
13263
  }
13264
13264
  }
13265
+ const toolCallIdToToolName = /* @__PURE__ */ new Map();
13266
+ for (const message of messages) {
13267
+ if ((message.role === "assistant" || message.role === "tool") && typeof message.content !== "string") {
13268
+ for (const part of message.content) {
13269
+ if (part.type === "tool-call" || part.type === "tool-result") {
13270
+ toolCallIdToToolName.set(part.toolCallId, part.toolName);
13271
+ }
13272
+ }
13273
+ }
13274
+ }
13275
+ const approvalIdToToolName = /* @__PURE__ */ new Map();
13276
+ for (const message of messages) {
13277
+ if ((message.role === "assistant" || message.role === "tool") && typeof message.content !== "string") {
13278
+ for (const part of message.content) {
13279
+ if (part.type === "tool-approval-request") {
13280
+ const toolName = toolCallIdToToolName.get(part.toolCallId);
13281
+ if (toolName != null) {
13282
+ approvalIdToToolName.set(part.approvalId, toolName);
13283
+ }
13284
+ }
13285
+ }
13286
+ }
13287
+ }
13265
13288
  messages = messages.map((message, messageIndex) => {
13266
13289
  if (message.role !== "assistant" && message.role !== "tool" || typeof message.content === "string" || keepLastMessagesCount && messageIndex >= messages.length - keepLastMessagesCount) {
13267
13290
  return message;
13268
13291
  }
13269
- const toolCallIdToToolName = {};
13270
- const approvalIdToToolName = {};
13271
13292
  return {
13272
13293
  ...message,
13273
13294
  content: message.content.filter((part) => {
13274
13295
  if (part.type !== "tool-call" && part.type !== "tool-result" && part.type !== "tool-approval-request" && part.type !== "tool-approval-response") {
13275
13296
  return true;
13276
13297
  }
13277
- if (part.type === "tool-call") {
13278
- toolCallIdToToolName[part.toolCallId] = part.toolName;
13279
- } else if (part.type === "tool-approval-request") {
13280
- approvalIdToToolName[part.approvalId] = toolCallIdToToolName[part.toolCallId];
13281
- }
13282
13298
  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)) {
13283
13299
  return true;
13284
13300
  }
13285
- return toolCall.tools != null && !toolCall.tools.includes(
13286
- part.type === "tool-call" || part.type === "tool-result" ? part.toolName : approvalIdToToolName[part.approvalId]
13287
- );
13301
+ const partToolName = part.type === "tool-call" || part.type === "tool-result" ? part.toolName : approvalIdToToolName.get(part.approvalId);
13302
+ return toolCall.tools != null && partToolName != null && !toolCall.tools.includes(partToolName);
13288
13303
  })
13289
13304
  };
13290
13305
  });