ai 6.0.174 → 6.0.176
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 +16 -0
- package/dist/index.d.mts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +92 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -43
- 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/02-providers-and-models.mdx +3 -0
- package/docs/07-reference/01-ai-sdk-core/20-tool.mdx +3 -3
- package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +3 -3
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +9 -1
- package/package.json +3 -3
- package/src/generate-text/execute-tool-call.ts +6 -0
- package/src/generate-text/generate-text.ts +12 -0
- package/src/generate-text/parse-tool-call.ts +8 -33
- package/src/generate-text/run-tools-transformation.ts +10 -0
- package/src/generate-text/stream-text-result.ts +2 -0
- package/src/generate-text/stream-text.ts +15 -0
- package/src/generate-text/tool-call.ts +2 -0
- package/src/generate-text/tool-error.ts +3 -0
- package/src/generate-text/tool-result.ts +3 -0
- package/src/ui/process-ui-message-stream.ts +29 -1
- package/src/ui/ui-messages.ts +3 -0
- package/src/ui/validate-ui-messages.ts +25 -1
- package/src/ui-message-stream/ui-message-chunks.ts +17 -0
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
TypeValidationContext,
|
|
3
|
+
TypeValidationError,
|
|
4
|
+
type JSONObject,
|
|
5
|
+
} from '@ai-sdk/provider';
|
|
2
6
|
import {
|
|
3
7
|
lazySchema,
|
|
4
8
|
StandardSchemaV1,
|
|
@@ -9,6 +13,7 @@ import {
|
|
|
9
13
|
} from '@ai-sdk/provider-utils';
|
|
10
14
|
import { z } from 'zod/v4';
|
|
11
15
|
import { InvalidArgumentError } from '../error';
|
|
16
|
+
import { jsonValueSchema } from '../types/json-value';
|
|
12
17
|
import { providerMetadataSchema } from '../types/provider-metadata';
|
|
13
18
|
import type {
|
|
14
19
|
DataUIPart,
|
|
@@ -18,6 +23,11 @@ import type {
|
|
|
18
23
|
UIMessage,
|
|
19
24
|
} from './ui-messages';
|
|
20
25
|
|
|
26
|
+
const toolMetadataSchema: z.ZodType<JSONObject> = z.record(
|
|
27
|
+
z.string(),
|
|
28
|
+
jsonValueSchema.optional(),
|
|
29
|
+
);
|
|
30
|
+
|
|
21
31
|
const uiMessagesSchema = lazySchema(() =>
|
|
22
32
|
zodSchema(
|
|
23
33
|
z
|
|
@@ -75,6 +85,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
75
85
|
type: z.literal('dynamic-tool'),
|
|
76
86
|
toolName: z.string(),
|
|
77
87
|
toolCallId: z.string(),
|
|
88
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
78
89
|
state: z.literal('input-streaming'),
|
|
79
90
|
input: z.unknown().optional(),
|
|
80
91
|
providerExecuted: z.boolean().optional(),
|
|
@@ -87,6 +98,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
87
98
|
type: z.literal('dynamic-tool'),
|
|
88
99
|
toolName: z.string(),
|
|
89
100
|
toolCallId: z.string(),
|
|
101
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
90
102
|
state: z.literal('input-available'),
|
|
91
103
|
input: z.unknown(),
|
|
92
104
|
providerExecuted: z.boolean().optional(),
|
|
@@ -99,6 +111,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
99
111
|
type: z.literal('dynamic-tool'),
|
|
100
112
|
toolName: z.string(),
|
|
101
113
|
toolCallId: z.string(),
|
|
114
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
102
115
|
state: z.literal('approval-requested'),
|
|
103
116
|
input: z.unknown(),
|
|
104
117
|
providerExecuted: z.boolean().optional(),
|
|
@@ -115,6 +128,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
115
128
|
type: z.literal('dynamic-tool'),
|
|
116
129
|
toolName: z.string(),
|
|
117
130
|
toolCallId: z.string(),
|
|
131
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
118
132
|
state: z.literal('approval-responded'),
|
|
119
133
|
input: z.unknown(),
|
|
120
134
|
providerExecuted: z.boolean().optional(),
|
|
@@ -131,6 +145,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
131
145
|
type: z.literal('dynamic-tool'),
|
|
132
146
|
toolName: z.string(),
|
|
133
147
|
toolCallId: z.string(),
|
|
148
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
134
149
|
state: z.literal('output-available'),
|
|
135
150
|
input: z.unknown(),
|
|
136
151
|
providerExecuted: z.boolean().optional(),
|
|
@@ -151,6 +166,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
151
166
|
type: z.literal('dynamic-tool'),
|
|
152
167
|
toolName: z.string(),
|
|
153
168
|
toolCallId: z.string(),
|
|
169
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
154
170
|
state: z.literal('output-error'),
|
|
155
171
|
input: z.unknown(),
|
|
156
172
|
rawInput: z.unknown().optional(),
|
|
@@ -171,6 +187,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
171
187
|
type: z.literal('dynamic-tool'),
|
|
172
188
|
toolName: z.string(),
|
|
173
189
|
toolCallId: z.string(),
|
|
190
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
174
191
|
state: z.literal('output-denied'),
|
|
175
192
|
input: z.unknown(),
|
|
176
193
|
providerExecuted: z.boolean().optional(),
|
|
@@ -186,6 +203,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
186
203
|
z.object({
|
|
187
204
|
type: z.string().startsWith('tool-'),
|
|
188
205
|
toolCallId: z.string(),
|
|
206
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
189
207
|
state: z.literal('input-streaming'),
|
|
190
208
|
providerExecuted: z.boolean().optional(),
|
|
191
209
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
@@ -197,6 +215,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
197
215
|
z.object({
|
|
198
216
|
type: z.string().startsWith('tool-'),
|
|
199
217
|
toolCallId: z.string(),
|
|
218
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
200
219
|
state: z.literal('input-available'),
|
|
201
220
|
providerExecuted: z.boolean().optional(),
|
|
202
221
|
input: z.unknown(),
|
|
@@ -208,6 +227,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
208
227
|
z.object({
|
|
209
228
|
type: z.string().startsWith('tool-'),
|
|
210
229
|
toolCallId: z.string(),
|
|
230
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
211
231
|
state: z.literal('approval-requested'),
|
|
212
232
|
input: z.unknown(),
|
|
213
233
|
providerExecuted: z.boolean().optional(),
|
|
@@ -223,6 +243,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
223
243
|
z.object({
|
|
224
244
|
type: z.string().startsWith('tool-'),
|
|
225
245
|
toolCallId: z.string(),
|
|
246
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
226
247
|
state: z.literal('approval-responded'),
|
|
227
248
|
input: z.unknown(),
|
|
228
249
|
providerExecuted: z.boolean().optional(),
|
|
@@ -238,6 +259,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
238
259
|
z.object({
|
|
239
260
|
type: z.string().startsWith('tool-'),
|
|
240
261
|
toolCallId: z.string(),
|
|
262
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
241
263
|
state: z.literal('output-available'),
|
|
242
264
|
providerExecuted: z.boolean().optional(),
|
|
243
265
|
input: z.unknown(),
|
|
@@ -257,6 +279,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
257
279
|
z.object({
|
|
258
280
|
type: z.string().startsWith('tool-'),
|
|
259
281
|
toolCallId: z.string(),
|
|
282
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
260
283
|
state: z.literal('output-error'),
|
|
261
284
|
providerExecuted: z.boolean().optional(),
|
|
262
285
|
input: z.unknown(),
|
|
@@ -276,6 +299,7 @@ const uiMessagesSchema = lazySchema(() =>
|
|
|
276
299
|
z.object({
|
|
277
300
|
type: z.string().startsWith('tool-'),
|
|
278
301
|
toolCallId: z.string(),
|
|
302
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
279
303
|
state: z.literal('output-denied'),
|
|
280
304
|
providerExecuted: z.boolean().optional(),
|
|
281
305
|
input: z.unknown(),
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { JSONObject } from '@ai-sdk/provider';
|
|
1
2
|
import { z } from 'zod/v4';
|
|
2
3
|
import {
|
|
3
4
|
providerMetadataSchema,
|
|
4
5
|
type ProviderMetadata,
|
|
5
6
|
} from '../types/provider-metadata';
|
|
7
|
+
import { jsonValueSchema } from '../types/json-value';
|
|
6
8
|
import type { FinishReason } from '../types/language-model';
|
|
7
9
|
import type {
|
|
8
10
|
InferUIMessageData,
|
|
@@ -13,6 +15,11 @@ import type {
|
|
|
13
15
|
import type { ValueOf } from '../util/value-of';
|
|
14
16
|
import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
15
17
|
|
|
18
|
+
const toolMetadataSchema: z.ZodType<JSONObject> = z.record(
|
|
19
|
+
z.string(),
|
|
20
|
+
jsonValueSchema.optional(),
|
|
21
|
+
);
|
|
22
|
+
|
|
16
23
|
export const uiMessageChunkSchema = lazySchema(() =>
|
|
17
24
|
zodSchema(
|
|
18
25
|
z.union([
|
|
@@ -42,6 +49,7 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
42
49
|
toolName: z.string(),
|
|
43
50
|
providerExecuted: z.boolean().optional(),
|
|
44
51
|
providerMetadata: providerMetadataSchema.optional(),
|
|
52
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
45
53
|
dynamic: z.boolean().optional(),
|
|
46
54
|
title: z.string().optional(),
|
|
47
55
|
}),
|
|
@@ -57,6 +65,7 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
57
65
|
input: z.unknown(),
|
|
58
66
|
providerExecuted: z.boolean().optional(),
|
|
59
67
|
providerMetadata: providerMetadataSchema.optional(),
|
|
68
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
60
69
|
dynamic: z.boolean().optional(),
|
|
61
70
|
title: z.string().optional(),
|
|
62
71
|
}),
|
|
@@ -67,6 +76,7 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
67
76
|
input: z.unknown(),
|
|
68
77
|
providerExecuted: z.boolean().optional(),
|
|
69
78
|
providerMetadata: providerMetadataSchema.optional(),
|
|
79
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
70
80
|
dynamic: z.boolean().optional(),
|
|
71
81
|
errorText: z.string(),
|
|
72
82
|
title: z.string().optional(),
|
|
@@ -82,6 +92,7 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
82
92
|
output: z.unknown(),
|
|
83
93
|
providerExecuted: z.boolean().optional(),
|
|
84
94
|
providerMetadata: providerMetadataSchema.optional(),
|
|
95
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
85
96
|
dynamic: z.boolean().optional(),
|
|
86
97
|
preliminary: z.boolean().optional(),
|
|
87
98
|
}),
|
|
@@ -91,6 +102,7 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
91
102
|
errorText: z.string(),
|
|
92
103
|
providerExecuted: z.boolean().optional(),
|
|
93
104
|
providerMetadata: providerMetadataSchema.optional(),
|
|
105
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
94
106
|
dynamic: z.boolean().optional(),
|
|
95
107
|
}),
|
|
96
108
|
z.strictObject({
|
|
@@ -237,6 +249,7 @@ export type UIMessageChunk<
|
|
|
237
249
|
input: unknown;
|
|
238
250
|
providerExecuted?: boolean;
|
|
239
251
|
providerMetadata?: ProviderMetadata;
|
|
252
|
+
toolMetadata?: JSONObject;
|
|
240
253
|
dynamic?: boolean;
|
|
241
254
|
title?: string;
|
|
242
255
|
}
|
|
@@ -247,6 +260,7 @@ export type UIMessageChunk<
|
|
|
247
260
|
input: unknown;
|
|
248
261
|
providerExecuted?: boolean;
|
|
249
262
|
providerMetadata?: ProviderMetadata;
|
|
263
|
+
toolMetadata?: JSONObject;
|
|
250
264
|
dynamic?: boolean;
|
|
251
265
|
errorText: string;
|
|
252
266
|
title?: string;
|
|
@@ -262,6 +276,7 @@ export type UIMessageChunk<
|
|
|
262
276
|
output: unknown;
|
|
263
277
|
providerExecuted?: boolean;
|
|
264
278
|
providerMetadata?: ProviderMetadata;
|
|
279
|
+
toolMetadata?: JSONObject;
|
|
265
280
|
dynamic?: boolean;
|
|
266
281
|
preliminary?: boolean;
|
|
267
282
|
}
|
|
@@ -271,6 +286,7 @@ export type UIMessageChunk<
|
|
|
271
286
|
errorText: string;
|
|
272
287
|
providerExecuted?: boolean;
|
|
273
288
|
providerMetadata?: ProviderMetadata;
|
|
289
|
+
toolMetadata?: JSONObject;
|
|
274
290
|
dynamic?: boolean;
|
|
275
291
|
}
|
|
276
292
|
| {
|
|
@@ -283,6 +299,7 @@ export type UIMessageChunk<
|
|
|
283
299
|
toolName: string;
|
|
284
300
|
providerExecuted?: boolean;
|
|
285
301
|
providerMetadata?: ProviderMetadata;
|
|
302
|
+
toolMetadata?: JSONObject;
|
|
286
303
|
dynamic?: boolean;
|
|
287
304
|
title?: string;
|
|
288
305
|
}
|