ai 6.0.92 → 6.0.94
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 +13 -0
- package/dist/index.d.mts +357 -13
- package/dist/index.d.ts +357 -13
- package/dist/index.js +198 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +198 -26
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/02-foundations/03-prompts.mdx +1 -1
- package/docs/02-getting-started/01-navigating-the-library.mdx +1 -1
- package/docs/03-agents/02-building-agents.mdx +8 -7
- package/docs/03-agents/03-workflows.mdx +71 -55
- package/docs/03-ai-sdk-core/01-overview.mdx +2 -4
- package/docs/03-ai-sdk-core/05-generating-text.mdx +54 -0
- package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +8 -172
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +48 -6
- package/docs/03-ai-sdk-core/20-prompt-engineering.mdx +14 -12
- package/docs/03-ai-sdk-core/55-testing.mdx +8 -8
- package/docs/03-ai-sdk-core/60-telemetry.mdx +13 -53
- package/docs/05-ai-sdk-rsc/02-streaming-react-components.mdx +1 -1
- package/docs/05-ai-sdk-rsc/05-streaming-values.mdx +2 -3
- package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +9 -9
- package/docs/06-advanced/04-caching.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +667 -146
- package/docs/07-reference/01-ai-sdk-core/index.mdx +3 -8
- package/docs/07-reference/05-ai-sdk-errors/ai-no-object-generated-error.mdx +2 -2
- package/docs/09-troubleshooting/09-client-stream-error.mdx +1 -1
- package/docs/09-troubleshooting/14-tool-calling-with-structured-outputs.mdx +4 -4
- package/docs/09-troubleshooting/20-no-object-generated-content-filter.mdx +18 -14
- package/package.json +2 -2
- package/src/generate-text/execute-tool-call.ts +83 -0
- package/src/generate-text/generate-text.ts +534 -11
- package/src/generate-text/index.ts +4 -0
- package/src/generate-text/step-result.ts +52 -0
- package/src/generate-text/stream-text.ts +15 -1
- package/docs/07-reference/01-ai-sdk-core/03-generate-object.mdx +0 -780
- package/docs/07-reference/01-ai-sdk-core/04-stream-object.mdx +0 -1152
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export {
|
|
2
2
|
generateText,
|
|
3
3
|
type GenerateTextOnFinishCallback,
|
|
4
|
+
type GenerateTextOnStartCallback,
|
|
5
|
+
type GenerateTextOnStepStartCallback,
|
|
4
6
|
type GenerateTextOnStepFinishCallback,
|
|
7
|
+
type GenerateTextOnToolCallStartCallback,
|
|
8
|
+
type GenerateTextOnToolCallFinishCallback,
|
|
5
9
|
} from './generate-text';
|
|
6
10
|
export type { ContentPart } from './content-part';
|
|
7
11
|
export type { GenerateTextResult } from './generate-text-result';
|
|
@@ -23,6 +23,38 @@ import { ToolSet } from './tool-set';
|
|
|
23
23
|
* The result of a single step in the generation process.
|
|
24
24
|
*/
|
|
25
25
|
export type StepResult<TOOLS extends ToolSet> = {
|
|
26
|
+
/**
|
|
27
|
+
* Zero-based index of this step.
|
|
28
|
+
*/
|
|
29
|
+
readonly stepNumber: number;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Information about the model that produced this step.
|
|
33
|
+
*/
|
|
34
|
+
readonly model: {
|
|
35
|
+
/** The provider of the model. */
|
|
36
|
+
readonly provider: string;
|
|
37
|
+
/** The ID of the model. */
|
|
38
|
+
readonly modelId: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Identifier from telemetry settings for grouping related operations.
|
|
43
|
+
*/
|
|
44
|
+
readonly functionId: string | undefined;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Additional metadata from telemetry settings.
|
|
48
|
+
*/
|
|
49
|
+
readonly metadata: Record<string, unknown> | undefined;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* User-defined context object flowing through the generation.
|
|
53
|
+
*
|
|
54
|
+
* Experimental (can break in patch releases).
|
|
55
|
+
*/
|
|
56
|
+
readonly experimental_context: unknown;
|
|
57
|
+
|
|
26
58
|
/**
|
|
27
59
|
* The content that was generated in the last step.
|
|
28
60
|
*/
|
|
@@ -136,6 +168,11 @@ export type StepResult<TOOLS extends ToolSet> = {
|
|
|
136
168
|
export class DefaultStepResult<TOOLS extends ToolSet>
|
|
137
169
|
implements StepResult<TOOLS>
|
|
138
170
|
{
|
|
171
|
+
readonly stepNumber: StepResult<TOOLS>['stepNumber'];
|
|
172
|
+
readonly model: StepResult<TOOLS>['model'];
|
|
173
|
+
readonly functionId: StepResult<TOOLS>['functionId'];
|
|
174
|
+
readonly metadata: StepResult<TOOLS>['metadata'];
|
|
175
|
+
readonly experimental_context: StepResult<TOOLS>['experimental_context'];
|
|
139
176
|
readonly content: StepResult<TOOLS>['content'];
|
|
140
177
|
readonly finishReason: StepResult<TOOLS>['finishReason'];
|
|
141
178
|
readonly rawFinishReason: StepResult<TOOLS>['rawFinishReason'];
|
|
@@ -146,6 +183,11 @@ export class DefaultStepResult<TOOLS extends ToolSet>
|
|
|
146
183
|
readonly providerMetadata: StepResult<TOOLS>['providerMetadata'];
|
|
147
184
|
|
|
148
185
|
constructor({
|
|
186
|
+
stepNumber,
|
|
187
|
+
model,
|
|
188
|
+
functionId,
|
|
189
|
+
metadata,
|
|
190
|
+
experimental_context,
|
|
149
191
|
content,
|
|
150
192
|
finishReason,
|
|
151
193
|
rawFinishReason,
|
|
@@ -155,6 +197,11 @@ export class DefaultStepResult<TOOLS extends ToolSet>
|
|
|
155
197
|
response,
|
|
156
198
|
providerMetadata,
|
|
157
199
|
}: {
|
|
200
|
+
stepNumber: StepResult<TOOLS>['stepNumber'];
|
|
201
|
+
model: StepResult<TOOLS>['model'];
|
|
202
|
+
functionId: StepResult<TOOLS>['functionId'];
|
|
203
|
+
metadata: StepResult<TOOLS>['metadata'];
|
|
204
|
+
experimental_context: StepResult<TOOLS>['experimental_context'];
|
|
158
205
|
content: StepResult<TOOLS>['content'];
|
|
159
206
|
finishReason: StepResult<TOOLS>['finishReason'];
|
|
160
207
|
rawFinishReason: StepResult<TOOLS>['rawFinishReason'];
|
|
@@ -164,6 +211,11 @@ export class DefaultStepResult<TOOLS extends ToolSet>
|
|
|
164
211
|
response: StepResult<TOOLS>['response'];
|
|
165
212
|
providerMetadata: StepResult<TOOLS>['providerMetadata'];
|
|
166
213
|
}) {
|
|
214
|
+
this.stepNumber = stepNumber;
|
|
215
|
+
this.model = model;
|
|
216
|
+
this.functionId = functionId;
|
|
217
|
+
this.metadata = metadata;
|
|
218
|
+
this.experimental_context = experimental_context;
|
|
167
219
|
this.content = content;
|
|
168
220
|
this.finishReason = finishReason;
|
|
169
221
|
this.rawFinishReason = rawFinishReason;
|
|
@@ -917,6 +917,16 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output>
|
|
|
917
917
|
|
|
918
918
|
// Add step information (after response messages are updated):
|
|
919
919
|
const currentStepResult: StepResult<TOOLS> = new DefaultStepResult({
|
|
920
|
+
stepNumber: recordedSteps.length,
|
|
921
|
+
model: {
|
|
922
|
+
provider: model.provider,
|
|
923
|
+
modelId: model.modelId,
|
|
924
|
+
},
|
|
925
|
+
functionId: telemetry?.functionId,
|
|
926
|
+
metadata: telemetry?.metadata as
|
|
927
|
+
| Record<string, unknown>
|
|
928
|
+
| undefined,
|
|
929
|
+
experimental_context,
|
|
920
930
|
content: recordedContent,
|
|
921
931
|
finishReason: part.finishReason,
|
|
922
932
|
rawFinishReason: part.rawFinishReason,
|
|
@@ -987,6 +997,11 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output>
|
|
|
987
997
|
// call onFinish callback:
|
|
988
998
|
const finalStep = recordedSteps[recordedSteps.length - 1];
|
|
989
999
|
await onFinish?.({
|
|
1000
|
+
stepNumber: finalStep.stepNumber,
|
|
1001
|
+
model: finalStep.model,
|
|
1002
|
+
functionId: finalStep.functionId,
|
|
1003
|
+
metadata: finalStep.metadata,
|
|
1004
|
+
experimental_context: finalStep.experimental_context,
|
|
990
1005
|
finishReason: finalStep.finishReason,
|
|
991
1006
|
rawFinishReason: finalStep.rawFinishReason,
|
|
992
1007
|
totalUsage,
|
|
@@ -1008,7 +1023,6 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output>
|
|
|
1008
1023
|
warnings: finalStep.warnings,
|
|
1009
1024
|
providerMetadata: finalStep.providerMetadata,
|
|
1010
1025
|
steps: recordedSteps,
|
|
1011
|
-
experimental_context,
|
|
1012
1026
|
});
|
|
1013
1027
|
|
|
1014
1028
|
// Add response information to the root span:
|