ai 7.0.172 → 7.0.173

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.
@@ -1,6 +1,33 @@
1
1
  import { logWarnings } from '../logger/log-warnings';
2
2
  import type { StopCondition } from '../generate-text/stop-condition';
3
3
 
4
+ /**
5
+ * Logs the warning for the default stopWhen condition.
6
+ */
7
+ export function logDefaultStopConditionWarning({
8
+ stepCount,
9
+ provider,
10
+ modelId,
11
+ }: {
12
+ stepCount: number;
13
+ provider: string;
14
+ modelId: string;
15
+ }): void {
16
+ logWarnings({
17
+ provider,
18
+ model: modelId,
19
+ warnings: [
20
+ {
21
+ type: 'other',
22
+ message:
23
+ `The tool loop stopped because it reached the default stopWhen condition, isStepCount(${stepCount}). ` +
24
+ 'To allow more steps, set stopWhen to isStepCount(...) with a higher limit or provide a custom stop condition. ' +
25
+ 'Learn more: https://ai-sdk.dev/docs/agents/loop-control',
26
+ },
27
+ ],
28
+ });
29
+ }
30
+
4
31
  /**
5
32
  * Stop conditions are only evaluated when the tool loop can otherwise continue,
6
33
  * so logging here avoids warning when a call finishes naturally at the limit.
@@ -14,19 +41,7 @@ export function createDefaultStopCondition(
14
41
  }
15
42
 
16
43
  const { provider, modelId } = steps[steps.length - 1].model;
17
- logWarnings({
18
- provider,
19
- model: modelId,
20
- warnings: [
21
- {
22
- type: 'other',
23
- message:
24
- `The tool loop stopped because it reached the default stopWhen condition, isStepCount(${stepCount}). ` +
25
- 'To allow more steps, set stopWhen to isStepCount(...) with a higher limit or provide a custom stop condition. ' +
26
- 'Learn more: https://ai-sdk.dev/docs/agents/loop-control',
27
- },
28
- ],
29
- });
44
+ logDefaultStopConditionWarning({ stepCount, provider, modelId });
30
45
 
31
46
  return true;
32
47
  };
@@ -111,22 +111,27 @@ export async function validateApprovedToolApprovals<
111
111
  }
112
112
 
113
113
  if (isExecutableTool(tool) && tool.inputSchema != null) {
114
- const hasInputSchemaInput = Object.prototype.hasOwnProperty.call(
115
- approvalRequest,
116
- 'inputSchemaInput',
117
- );
118
- const validation = await safeValidateTypes({
119
- value: hasInputSchemaInput
120
- ? approvalRequest.inputSchemaInput
121
- : toolCall.input,
122
- schema: asSchema(tool.inputSchema),
123
- });
124
-
125
114
  let validationError: unknown;
126
- if (!validation.success) {
127
- validationError = validation.error;
128
- } else {
129
- try {
115
+ try {
116
+ // Preserve the approved input before validators or refiners can mutate
117
+ // it, and give them an independent copy of the schema input.
118
+ const approvedInput = structuredClone(toolCall.input);
119
+ const hasInputSchemaInput = Object.prototype.hasOwnProperty.call(
120
+ approvalRequest,
121
+ 'inputSchemaInput',
122
+ );
123
+ const validation = await safeValidateTypes({
124
+ value: structuredClone(
125
+ hasInputSchemaInput
126
+ ? approvalRequest.inputSchemaInput
127
+ : toolCall.input,
128
+ ),
129
+ schema: asSchema(tool.inputSchema),
130
+ });
131
+
132
+ if (!validation.success) {
133
+ validationError = validation.error;
134
+ } else {
130
135
  const revalidatedToolCall = await refineParsedToolCallInput({
131
136
  toolCall: {
132
137
  ...toolCall,
@@ -135,9 +140,8 @@ export async function validateApprovedToolApprovals<
135
140
  refineToolInput,
136
141
  });
137
142
 
138
- // Clone both inputs into the current realm before comparing them.
143
+ // Normalize the revalidated input to the snapshot's realm.
139
144
  const revalidatedInput = structuredClone(revalidatedToolCall.input);
140
- const approvedInput = structuredClone(toolCall.input);
141
145
 
142
146
  // Revalidation must never change the operation that was approved,
143
147
  // including when older or projected history omits the schema input.
@@ -146,9 +150,9 @@ export async function validateApprovedToolApprovals<
146
150
  'Approved tool input does not match the validated schema output.',
147
151
  );
148
152
  }
149
- } catch (error) {
150
- validationError = error;
151
153
  }
154
+ } catch (error) {
155
+ validationError = error;
152
156
  }
153
157
 
154
158
  if (validationError != null) {