ai 7.0.29 → 7.0.31

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,23 @@
1
1
  # ai
2
2
 
3
+ ## 7.0.31
4
+
5
+ ### Patch Changes
6
+
7
+ - 70f18c3: fix(ai): emit denied tool output state for client-rejected approvals
8
+ - cd06458: fix(ai): call `onInputStart` before `onInputAvailable` during non-streaming tool calls
9
+ - Updated dependencies [cd06458]
10
+ - @ai-sdk/provider-utils@5.0.11
11
+ - @ai-sdk/gateway@4.0.23
12
+
13
+ ## 7.0.30
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [341616a]
18
+ - Updated dependencies [70fc45c]
19
+ - @ai-sdk/gateway@4.0.22
20
+
3
21
  ## 7.0.29
4
22
 
5
23
  ### Patch Changes
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.29" : "0.0.0-test";
1092
+ var VERSION = true ? "7.0.31" : "0.0.0-test";
1093
1093
 
1094
1094
  // src/util/download/download.ts
1095
1095
  var download = async ({
@@ -2787,9 +2787,7 @@ function collectToolApprovals({
2787
2787
  }
2788
2788
  }
2789
2789
  }
2790
- const toolResults = /* @__PURE__ */ Object.create(
2791
- null
2792
- );
2790
+ const toolResults = /* @__PURE__ */ Object.create(null);
2793
2791
  for (const part of lastMessage.content) {
2794
2792
  if (part.type === "tool-result") {
2795
2793
  toolResults[part.toolCallId] = part;
@@ -2807,7 +2805,8 @@ function collectToolApprovals({
2807
2805
  approvalId: approvalResponse.approvalId
2808
2806
  });
2809
2807
  }
2810
- if (toolResults[approvalRequest.toolCallId] != null) {
2808
+ const existingToolResult = toolResults[approvalRequest.toolCallId];
2809
+ if (existingToolResult != null && (approvalResponse.approved || existingToolResult.output.type !== "execution-denied")) {
2811
2810
  continue;
2812
2811
  }
2813
2812
  const toolCall = toolCallsByToolCallId[approvalRequest.toolCallId];
@@ -2820,7 +2819,8 @@ function collectToolApprovals({
2820
2819
  const approval = {
2821
2820
  approvalRequest,
2822
2821
  approvalResponse,
2823
- toolCall
2822
+ toolCall,
2823
+ ...existingToolResult != null ? { existingToolResult } : {}
2824
2824
  };
2825
2825
  if (approvalResponse.approved) {
2826
2826
  approvedToolApprovals.push(approval);
@@ -5136,7 +5136,10 @@ async function generateText({
5136
5136
  ...collectedDeniedToolApprovals,
5137
5137
  ...revalidationDeniedToolApprovals
5138
5138
  ];
5139
- if (deniedToolApprovals.length > 0 || localApprovedToolApprovals.length > 0) {
5139
+ const deniedToolApprovalsWithoutResults = deniedToolApprovals.filter(
5140
+ (toolApproval2) => toolApproval2.existingToolResult == null
5141
+ );
5142
+ if (deniedToolApprovalsWithoutResults.length > 0 || localApprovedToolApprovals.length > 0) {
5140
5143
  const toolResults2 = await executeTools({
5141
5144
  toolCalls: localApprovedToolApprovals.map(
5142
5145
  (toolApproval2) => toolApproval2.toolCall
@@ -5182,7 +5185,7 @@ async function generateText({
5182
5185
  output: modelOutput
5183
5186
  });
5184
5187
  }
5185
- for (const toolApproval2 of deniedToolApprovals) {
5188
+ for (const toolApproval2 of deniedToolApprovalsWithoutResults) {
5186
5189
  toolContent.push({
5187
5190
  type: "tool-result",
5188
5191
  toolCallId: toolApproval2.toolCall.toolCallId,
@@ -5428,6 +5431,14 @@ async function generateText({
5428
5431
  if (tool2 == null) {
5429
5432
  continue;
5430
5433
  }
5434
+ if (tool2.onInputStart != null) {
5435
+ await tool2.onInputStart({
5436
+ toolCallId: toolCall.toolCallId,
5437
+ messages: stepMessages,
5438
+ abortSignal: mergedAbortSignal,
5439
+ context: runtimeContext
5440
+ });
5441
+ }
5431
5442
  if ((tool2 == null ? void 0 : tool2.onInputAvailable) != null) {
5432
5443
  await tool2.onInputAvailable({
5433
5444
  input: toolCall.input,
@@ -9088,6 +9099,9 @@ var DefaultStreamTextResult = class {
9088
9099
  ),
9089
9100
  ...revalidationDeniedToolApprovals
9090
9101
  ];
9102
+ const localDeniedToolApprovalsWithoutResults = localDeniedToolApprovals.filter(
9103
+ (toolApproval2) => toolApproval2.existingToolResult == null
9104
+ );
9091
9105
  const deniedProviderExecutedToolApprovals = deniedToolApprovals.filter(
9092
9106
  (toolApproval2) => toolApproval2.toolCall.providerExecuted
9093
9107
  );
@@ -9141,7 +9155,7 @@ var DefaultStreamTextResult = class {
9141
9155
  }
9142
9156
  })
9143
9157
  );
9144
- if (toolOutputs.length > 0 || localDeniedToolApprovals.length > 0) {
9158
+ if (toolOutputs.length > 0 || localDeniedToolApprovalsWithoutResults.length > 0) {
9145
9159
  const localToolContent = [];
9146
9160
  for (const output2 of toolOutputs) {
9147
9161
  localToolContent.push({
@@ -9157,7 +9171,7 @@ var DefaultStreamTextResult = class {
9157
9171
  })
9158
9172
  });
9159
9173
  }
9160
- for (const toolApproval2 of localDeniedToolApprovals) {
9174
+ for (const toolApproval2 of localDeniedToolApprovalsWithoutResults) {
9161
9175
  localToolContent.push({
9162
9176
  type: "tool-result",
9163
9177
  toolCallId: toolApproval2.toolCall.toolCallId,