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.
- package/CHANGELOG.md +22 -0
- package/dist/index.js +34 -21
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +98 -0
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +53 -16
- package/dist/internal/index.js.map +1 -1
- package/docs/02-foundations/03-prompts.mdx +1 -1
- package/docs/03-agents/04-loop-control.mdx +1 -1
- package/docs/03-agents/06-tool-approvals.mdx +1 -1
- package/docs/03-agents/07-workflow-agent.mdx +87 -34
- package/docs/03-ai-sdk-core/05-generating-text.mdx +7 -2
- package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +4 -0
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +3 -0
- package/docs/03-ai-sdk-core/26-reasoning.mdx +3 -3
- package/docs/03-ai-sdk-core/32-decisions.mdx +4 -0
- package/docs/03-ai-sdk-core/33-extractions.mdx +1 -1
- package/docs/03-ai-sdk-core/35-image-generation.mdx +2 -0
- package/docs/03-ai-sdk-core/36-transcription.mdx +3 -0
- package/docs/03-ai-sdk-core/37-speech.mdx +3 -0
- package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +6 -0
- package/docs/07-reference/01-ai-sdk-core/33-safe-validate-ui-messages.mdx +3 -0
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +62 -5
- package/package.json +10 -10
- package/src/agent/default-stop-condition.ts +28 -13
- package/src/generate-text/validate-tool-approvals.ts +23 -19
|
@@ -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
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
//
|
|
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) {
|