ai 6.0.306 → 6.0.308
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 +19 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +24 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -4
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/04-ai-sdk-ui/50-stream-protocol.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +18 -6
- package/package.json +5 -5
- package/src/generate-text/stream-text-result.ts +2 -0
- package/src/generate-text/stream-text.ts +3 -0
- package/src/ui/process-ui-message-stream.ts +29 -3
- package/src/ui/ui-messages.ts +4 -0
- package/src/ui/validate-ui-messages.ts +2 -0
- package/src/ui-message-stream/ui-message-chunks.ts +3 -0
package/dist/internal/index.js
CHANGED
|
@@ -164,7 +164,7 @@ function detectMediaType({
|
|
|
164
164
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
165
165
|
|
|
166
166
|
// src/version.ts
|
|
167
|
-
var VERSION = true ? "6.0.
|
|
167
|
+
var VERSION = true ? "6.0.308" : "0.0.0-test";
|
|
168
168
|
|
|
169
169
|
// src/util/download/download.ts
|
|
170
170
|
var download = async ({
|
package/dist/internal/index.mjs
CHANGED
|
@@ -289,6 +289,13 @@ data: {"type":"error","errorText":"error message"}
|
|
|
289
289
|
|
|
290
290
|
Indicates the beginning of tool input streaming.
|
|
291
291
|
|
|
292
|
+
The optional `inputEncoding` field specifies how to interpret subsequent input
|
|
293
|
+
deltas. When omitted or set to `'json'`, the UI parses the accumulated text as
|
|
294
|
+
partial JSON. With `'text'`, the UI uses the accumulated text directly as the
|
|
295
|
+
string input. Use `'text'` for raw custom-tool input such as code or HTML.
|
|
296
|
+
The encoding is also retained on persisted `input-streaming` tool parts so
|
|
297
|
+
streaming can resume correctly.
|
|
298
|
+
|
|
292
299
|
Format: Server-Sent Event with JSON object
|
|
293
300
|
|
|
294
301
|
Example:
|
|
@@ -912,12 +912,18 @@ To see `streamText` in action, check out [these examples](#examples).
|
|
|
912
912
|
parameters: [
|
|
913
913
|
{
|
|
914
914
|
name: 'type',
|
|
915
|
-
type: "'tool-
|
|
915
|
+
type: "'tool-input-start'",
|
|
916
|
+
description: 'Indicates the start of streamed tool input.',
|
|
917
|
+
},
|
|
918
|
+
{
|
|
919
|
+
name: 'inputEncoding',
|
|
920
|
+
type: "'json' | 'text'",
|
|
921
|
+
isOptional: true,
|
|
916
922
|
description:
|
|
917
|
-
'
|
|
923
|
+
'Encoding of subsequent tool-input-delta events. Defaults to json when omitted. Text deltas contain raw string input, such as OpenAI custom-tool code or HTML.',
|
|
918
924
|
},
|
|
919
925
|
{
|
|
920
|
-
name: '
|
|
926
|
+
name: 'id',
|
|
921
927
|
type: 'string',
|
|
922
928
|
description: 'The id of the tool call.',
|
|
923
929
|
},
|
|
@@ -3034,12 +3040,18 @@ To see `streamText` in action, check out [these examples](#examples).
|
|
|
3034
3040
|
parameters: [
|
|
3035
3041
|
{
|
|
3036
3042
|
name: 'type',
|
|
3037
|
-
type: "'tool-
|
|
3043
|
+
type: "'tool-input-start'",
|
|
3044
|
+
description: 'Indicates the start of streamed tool input.',
|
|
3045
|
+
},
|
|
3046
|
+
{
|
|
3047
|
+
name: 'inputEncoding',
|
|
3048
|
+
type: "'json' | 'text'",
|
|
3049
|
+
isOptional: true,
|
|
3038
3050
|
description:
|
|
3039
|
-
'
|
|
3051
|
+
'Encoding of subsequent tool-input-delta events. Defaults to json when omitted. Text deltas contain raw string input, such as OpenAI custom-tool code or HTML.',
|
|
3040
3052
|
},
|
|
3041
3053
|
{
|
|
3042
|
-
name: '
|
|
3054
|
+
name: 'id',
|
|
3043
3055
|
type: 'string',
|
|
3044
3056
|
description: 'The id of the tool call.',
|
|
3045
3057
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.308",
|
|
4
4
|
"description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@opentelemetry/api": "^1.9.0",
|
|
48
|
-
"@ai-sdk/gateway": "3.0.
|
|
49
|
-
"@ai-sdk/provider": "3.0.
|
|
50
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
48
|
+
"@ai-sdk/gateway": "3.0.216",
|
|
49
|
+
"@ai-sdk/provider": "3.0.19",
|
|
50
|
+
"@ai-sdk/provider-utils": "4.0.60"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@edge-runtime/vm": "^5.0.0",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"tsx": "^4.19.2",
|
|
59
59
|
"typescript": "5.8.3",
|
|
60
60
|
"zod": "3.25.76",
|
|
61
|
-
"@ai-sdk/google": "3.0.
|
|
61
|
+
"@ai-sdk/google": "3.0.134",
|
|
62
62
|
"@ai-sdk/test-server": "1.0.6",
|
|
63
63
|
"@vercel/ai-tsconfig": "0.0.0"
|
|
64
64
|
},
|
|
@@ -418,6 +418,8 @@ export type TextStreamPart<TOOLS extends ToolSet> =
|
|
|
418
418
|
type: 'tool-input-start';
|
|
419
419
|
id: string;
|
|
420
420
|
toolName: string;
|
|
421
|
+
/** Encoding of the input deltas. Defaults to JSON when omitted. */
|
|
422
|
+
inputEncoding?: 'json' | 'text';
|
|
421
423
|
providerMetadata?: ProviderMetadata;
|
|
422
424
|
toolMetadata?: JSONObject;
|
|
423
425
|
providerExecuted?: boolean;
|
|
@@ -2915,6 +2915,9 @@ class DefaultStreamTextResult<
|
|
|
2915
2915
|
type: 'tool-input-start',
|
|
2916
2916
|
toolCallId: part.id,
|
|
2917
2917
|
toolName: part.toolName,
|
|
2918
|
+
...(part.inputEncoding != null
|
|
2919
|
+
? { inputEncoding: part.inputEncoding }
|
|
2920
|
+
: {}),
|
|
2918
2921
|
...(part.providerExecuted != null
|
|
2919
2922
|
? { providerExecuted: part.providerExecuted }
|
|
2920
2923
|
: {}),
|
|
@@ -39,6 +39,7 @@ export type StreamingUIMessageState<UI_MESSAGE extends UIMessage> = {
|
|
|
39
39
|
string,
|
|
40
40
|
{
|
|
41
41
|
text: string;
|
|
42
|
+
inputEncoding?: 'json' | 'text';
|
|
42
43
|
index: number;
|
|
43
44
|
toolName: string;
|
|
44
45
|
dynamic?: boolean;
|
|
@@ -95,6 +96,7 @@ export function createStreamingUIMessageState<UI_MESSAGE extends UIMessage>({
|
|
|
95
96
|
|
|
96
97
|
partialToolCalls[part.toolCallId] = {
|
|
97
98
|
text: part.rawInput ?? '',
|
|
99
|
+
inputEncoding: part.inputEncoding,
|
|
98
100
|
index,
|
|
99
101
|
toolName:
|
|
100
102
|
part.type === 'dynamic-tool' ? part.toolName : getStaticToolName(part),
|
|
@@ -209,6 +211,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
209
211
|
state: 'input-streaming';
|
|
210
212
|
input: unknown;
|
|
211
213
|
rawInput?: string;
|
|
214
|
+
inputEncoding?: 'json' | 'text';
|
|
212
215
|
providerExecuted?: boolean;
|
|
213
216
|
providerMetadata?: ProviderMetadata;
|
|
214
217
|
}
|
|
@@ -254,6 +257,11 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
254
257
|
anyPart.output = anyOptions.output;
|
|
255
258
|
anyPart.errorText = anyOptions.errorText;
|
|
256
259
|
anyPart.rawInput = anyOptions.rawInput;
|
|
260
|
+
if (anyOptions.inputEncoding != null) {
|
|
261
|
+
anyPart.inputEncoding = anyOptions.inputEncoding;
|
|
262
|
+
} else {
|
|
263
|
+
delete anyPart.inputEncoding;
|
|
264
|
+
}
|
|
257
265
|
anyPart.preliminary = anyOptions.preliminary;
|
|
258
266
|
if (options.title !== undefined) {
|
|
259
267
|
anyPart.title = options.title;
|
|
@@ -292,6 +300,9 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
292
300
|
? { toolMetadata: options.toolMetadata }
|
|
293
301
|
: {}),
|
|
294
302
|
input: anyOptions.input,
|
|
303
|
+
...(anyOptions.inputEncoding != null
|
|
304
|
+
? { inputEncoding: anyOptions.inputEncoding }
|
|
305
|
+
: {}),
|
|
295
306
|
output: anyOptions.output,
|
|
296
307
|
rawInput: anyOptions.rawInput,
|
|
297
308
|
errorText: anyOptions.errorText,
|
|
@@ -325,6 +336,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
325
336
|
state: 'input-streaming';
|
|
326
337
|
input: unknown;
|
|
327
338
|
rawInput?: string;
|
|
339
|
+
inputEncoding?: 'json' | 'text';
|
|
328
340
|
providerMetadata?: ProviderMetadata;
|
|
329
341
|
}
|
|
330
342
|
| {
|
|
@@ -366,6 +378,11 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
366
378
|
anyPart.output = anyOptions.output;
|
|
367
379
|
anyPart.errorText = anyOptions.errorText;
|
|
368
380
|
anyPart.rawInput = anyOptions.rawInput;
|
|
381
|
+
if (anyOptions.inputEncoding != null) {
|
|
382
|
+
anyPart.inputEncoding = anyOptions.inputEncoding;
|
|
383
|
+
} else {
|
|
384
|
+
delete anyPart.inputEncoding;
|
|
385
|
+
}
|
|
369
386
|
anyPart.preliminary = anyOptions.preliminary;
|
|
370
387
|
if (options.title !== undefined) {
|
|
371
388
|
anyPart.title = options.title;
|
|
@@ -401,6 +418,9 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
401
418
|
toolCallId: options.toolCallId,
|
|
402
419
|
state: options.state,
|
|
403
420
|
input: anyOptions.input,
|
|
421
|
+
...(anyOptions.inputEncoding != null
|
|
422
|
+
? { inputEncoding: anyOptions.inputEncoding }
|
|
423
|
+
: {}),
|
|
404
424
|
output: anyOptions.output,
|
|
405
425
|
errorText: anyOptions.errorText,
|
|
406
426
|
preliminary: anyOptions.preliminary,
|
|
@@ -599,6 +619,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
599
619
|
// add the partial tool call to the map
|
|
600
620
|
state.partialToolCalls[chunk.toolCallId] = {
|
|
601
621
|
text: '',
|
|
622
|
+
inputEncoding: chunk.inputEncoding,
|
|
602
623
|
toolName: chunk.toolName,
|
|
603
624
|
index: toolInvocations.length,
|
|
604
625
|
dynamic: chunk.dynamic,
|
|
@@ -611,6 +632,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
611
632
|
toolCallId: chunk.toolCallId,
|
|
612
633
|
toolName: chunk.toolName,
|
|
613
634
|
state: 'input-streaming',
|
|
635
|
+
inputEncoding: chunk.inputEncoding,
|
|
614
636
|
input: undefined,
|
|
615
637
|
providerExecuted: chunk.providerExecuted,
|
|
616
638
|
title: chunk.title,
|
|
@@ -622,6 +644,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
622
644
|
toolCallId: chunk.toolCallId,
|
|
623
645
|
toolName: chunk.toolName,
|
|
624
646
|
state: 'input-streaming',
|
|
647
|
+
inputEncoding: chunk.inputEncoding,
|
|
625
648
|
input: undefined,
|
|
626
649
|
providerExecuted: chunk.providerExecuted,
|
|
627
650
|
title: chunk.title,
|
|
@@ -648,15 +671,17 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
648
671
|
|
|
649
672
|
partialToolCall.text += chunk.inputTextDelta;
|
|
650
673
|
|
|
651
|
-
const
|
|
652
|
-
partialToolCall.text
|
|
653
|
-
|
|
674
|
+
const partialArgs =
|
|
675
|
+
partialToolCall.inputEncoding === 'text'
|
|
676
|
+
? partialToolCall.text
|
|
677
|
+
: (await parsePartialJson(partialToolCall.text)).value;
|
|
654
678
|
|
|
655
679
|
if (partialToolCall.dynamic) {
|
|
656
680
|
updateDynamicToolPart({
|
|
657
681
|
toolCallId: chunk.toolCallId,
|
|
658
682
|
toolName: partialToolCall.toolName,
|
|
659
683
|
state: 'input-streaming',
|
|
684
|
+
inputEncoding: partialToolCall.inputEncoding,
|
|
660
685
|
input: partialArgs,
|
|
661
686
|
rawInput: partialToolCall.text,
|
|
662
687
|
title: partialToolCall.title,
|
|
@@ -667,6 +692,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
667
692
|
toolCallId: chunk.toolCallId,
|
|
668
693
|
toolName: partialToolCall.toolName,
|
|
669
694
|
state: 'input-streaming',
|
|
695
|
+
inputEncoding: partialToolCall.inputEncoding,
|
|
670
696
|
input: partialArgs,
|
|
671
697
|
rawInput: partialToolCall.text,
|
|
672
698
|
title: partialToolCall.title,
|
package/src/ui/ui-messages.ts
CHANGED
|
@@ -245,6 +245,8 @@ export type UIToolInvocation<TOOL extends UITool | Tool> = {
|
|
|
245
245
|
* and later resumed.
|
|
246
246
|
*/
|
|
247
247
|
rawInput?: string;
|
|
248
|
+
/** Encoding of `rawInput`. Defaults to JSON when omitted. */
|
|
249
|
+
inputEncoding?: 'json' | 'text';
|
|
248
250
|
output?: never;
|
|
249
251
|
errorText?: never;
|
|
250
252
|
callProviderMetadata?: ProviderMetadata;
|
|
@@ -383,6 +385,8 @@ export type DynamicToolUIPart = {
|
|
|
383
385
|
* and later resumed.
|
|
384
386
|
*/
|
|
385
387
|
rawInput?: string;
|
|
388
|
+
/** Encoding of `rawInput`. Defaults to JSON when omitted. */
|
|
389
|
+
inputEncoding?: 'json' | 'text';
|
|
386
390
|
output?: never;
|
|
387
391
|
errorText?: never;
|
|
388
392
|
callProviderMetadata?: ProviderMetadata;
|
|
@@ -143,6 +143,7 @@ const uiMessagesSchema = lazySchema(() => {
|
|
|
143
143
|
state: z.literal('input-streaming'),
|
|
144
144
|
input: z.unknown().optional(),
|
|
145
145
|
rawInput: z.string().optional(),
|
|
146
|
+
inputEncoding: z.enum(['json', 'text']).optional(),
|
|
146
147
|
providerExecuted: z.boolean().optional(),
|
|
147
148
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
148
149
|
output: z.never().optional(),
|
|
@@ -246,6 +247,7 @@ const uiMessagesSchema = lazySchema(() => {
|
|
|
246
247
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
247
248
|
input: z.unknown().optional(),
|
|
248
249
|
rawInput: z.string().optional(),
|
|
250
|
+
inputEncoding: z.enum(['json', 'text']).optional(),
|
|
249
251
|
output: z.never().optional(),
|
|
250
252
|
errorText: z.never().optional(),
|
|
251
253
|
approval: z.never().optional(),
|
|
@@ -47,6 +47,7 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
47
47
|
type: z.literal('tool-input-start'),
|
|
48
48
|
toolCallId: z.string(),
|
|
49
49
|
toolName: z.string(),
|
|
50
|
+
inputEncoding: z.enum(['json', 'text']).optional(),
|
|
50
51
|
providerExecuted: z.boolean().optional(),
|
|
51
52
|
providerMetadata: providerMetadataSchema.optional(),
|
|
52
53
|
toolMetadata: toolMetadataSchema.optional(),
|
|
@@ -303,6 +304,8 @@ export type UIMessageChunk<
|
|
|
303
304
|
type: 'tool-input-start';
|
|
304
305
|
toolCallId: string;
|
|
305
306
|
toolName: string;
|
|
307
|
+
/** Encoding of the input deltas. Defaults to JSON when omitted. */
|
|
308
|
+
inputEncoding?: 'json' | 'text';
|
|
306
309
|
providerExecuted?: boolean;
|
|
307
310
|
providerMetadata?: ProviderMetadata;
|
|
308
311
|
toolMetadata?: JSONObject;
|