ai 7.0.141 → 7.0.143
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 +23 -0
- package/dist/index.d.ts +256 -203
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +220 -123
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +28 -16
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +1 -1
- package/docs/03-ai-sdk-core/17-mcp-events.mdx +50 -0
- package/docs/03-ai-sdk-core/32-decisions.mdx +2 -1
- package/docs/03-ai-sdk-harnesses/05-harness-adapters.mdx +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-low-memory.mdx +107 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +13 -0
- package/docs/07-reference/01-ai-sdk-core/14-decide.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/24-mcp-events.mdx +9 -8
- package/docs/07-reference/02-ai-sdk-ui/01-use-chat.mdx +1 -1
- package/package.json +12 -12
- package/src/agent/tool-loop-agent.ts +7 -4
- package/src/decide/decision-result.ts +6 -1
- package/src/decide/validate-decision.ts +21 -1
- package/src/generate-text/stream-language-model-call.ts +32 -16
- package/src/generate-text/stream-text-result.ts +2 -0
- package/src/generate-text/stream-text-single-consumer-result.ts +75 -0
- package/src/generate-text/stream-text.ts +250 -37
- package/src/ui/chat.ts +9 -4
- 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/to-ui-message-chunk.ts +3 -0
- package/src/ui-message-stream/ui-message-chunks.ts +3 -0
|
@@ -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),
|
|
@@ -227,6 +229,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
227
229
|
state: 'input-streaming';
|
|
228
230
|
input: unknown;
|
|
229
231
|
rawInput?: string;
|
|
232
|
+
inputEncoding?: 'json' | 'text';
|
|
230
233
|
providerExecuted?: boolean;
|
|
231
234
|
providerMetadata?: ProviderMetadata;
|
|
232
235
|
}
|
|
@@ -272,6 +275,11 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
272
275
|
anyPart.output = anyOptions.output;
|
|
273
276
|
anyPart.errorText = anyOptions.errorText;
|
|
274
277
|
anyPart.rawInput = anyOptions.rawInput;
|
|
278
|
+
if (anyOptions.inputEncoding != null) {
|
|
279
|
+
anyPart.inputEncoding = anyOptions.inputEncoding;
|
|
280
|
+
} else {
|
|
281
|
+
delete anyPart.inputEncoding;
|
|
282
|
+
}
|
|
275
283
|
anyPart.preliminary = anyOptions.preliminary;
|
|
276
284
|
if (options.title !== undefined) {
|
|
277
285
|
anyPart.title = options.title;
|
|
@@ -310,6 +318,9 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
310
318
|
? { toolMetadata: options.toolMetadata }
|
|
311
319
|
: {}),
|
|
312
320
|
input: anyOptions.input,
|
|
321
|
+
...(anyOptions.inputEncoding != null
|
|
322
|
+
? { inputEncoding: anyOptions.inputEncoding }
|
|
323
|
+
: {}),
|
|
313
324
|
output: anyOptions.output,
|
|
314
325
|
rawInput: anyOptions.rawInput,
|
|
315
326
|
errorText: anyOptions.errorText,
|
|
@@ -343,6 +354,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
343
354
|
state: 'input-streaming';
|
|
344
355
|
input: unknown;
|
|
345
356
|
rawInput?: string;
|
|
357
|
+
inputEncoding?: 'json' | 'text';
|
|
346
358
|
providerMetadata?: ProviderMetadata;
|
|
347
359
|
}
|
|
348
360
|
| {
|
|
@@ -384,6 +396,11 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
384
396
|
anyPart.output = anyOptions.output;
|
|
385
397
|
anyPart.errorText = anyOptions.errorText;
|
|
386
398
|
anyPart.rawInput = anyOptions.rawInput;
|
|
399
|
+
if (anyOptions.inputEncoding != null) {
|
|
400
|
+
anyPart.inputEncoding = anyOptions.inputEncoding;
|
|
401
|
+
} else {
|
|
402
|
+
delete anyPart.inputEncoding;
|
|
403
|
+
}
|
|
387
404
|
anyPart.preliminary = anyOptions.preliminary;
|
|
388
405
|
if (options.title !== undefined) {
|
|
389
406
|
anyPart.title = options.title;
|
|
@@ -419,6 +436,9 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
419
436
|
toolCallId: options.toolCallId,
|
|
420
437
|
state: options.state,
|
|
421
438
|
input: anyOptions.input,
|
|
439
|
+
...(anyOptions.inputEncoding != null
|
|
440
|
+
? { inputEncoding: anyOptions.inputEncoding }
|
|
441
|
+
: {}),
|
|
422
442
|
output: anyOptions.output,
|
|
423
443
|
errorText: anyOptions.errorText,
|
|
424
444
|
preliminary: anyOptions.preliminary,
|
|
@@ -632,6 +652,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
632
652
|
// add the partial tool call to the map
|
|
633
653
|
state.partialToolCalls[chunk.toolCallId] = {
|
|
634
654
|
text: '',
|
|
655
|
+
inputEncoding: chunk.inputEncoding,
|
|
635
656
|
toolName: chunk.toolName,
|
|
636
657
|
index: toolInvocations.length,
|
|
637
658
|
dynamic: chunk.dynamic,
|
|
@@ -644,6 +665,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
644
665
|
toolCallId: chunk.toolCallId,
|
|
645
666
|
toolName: chunk.toolName,
|
|
646
667
|
state: 'input-streaming',
|
|
668
|
+
inputEncoding: chunk.inputEncoding,
|
|
647
669
|
input: undefined,
|
|
648
670
|
providerExecuted: chunk.providerExecuted,
|
|
649
671
|
title: chunk.title,
|
|
@@ -655,6 +677,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
655
677
|
toolCallId: chunk.toolCallId,
|
|
656
678
|
toolName: chunk.toolName,
|
|
657
679
|
state: 'input-streaming',
|
|
680
|
+
inputEncoding: chunk.inputEncoding,
|
|
658
681
|
input: undefined,
|
|
659
682
|
providerExecuted: chunk.providerExecuted,
|
|
660
683
|
title: chunk.title,
|
|
@@ -681,15 +704,17 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
681
704
|
|
|
682
705
|
partialToolCall.text += chunk.inputTextDelta;
|
|
683
706
|
|
|
684
|
-
const
|
|
685
|
-
partialToolCall.text
|
|
686
|
-
|
|
707
|
+
const partialArgs =
|
|
708
|
+
partialToolCall.inputEncoding === 'text'
|
|
709
|
+
? partialToolCall.text
|
|
710
|
+
: (await parsePartialJson(partialToolCall.text)).value;
|
|
687
711
|
|
|
688
712
|
if (partialToolCall.dynamic) {
|
|
689
713
|
updateDynamicToolPart({
|
|
690
714
|
toolCallId: chunk.toolCallId,
|
|
691
715
|
toolName: partialToolCall.toolName,
|
|
692
716
|
state: 'input-streaming',
|
|
717
|
+
inputEncoding: partialToolCall.inputEncoding,
|
|
693
718
|
input: partialArgs,
|
|
694
719
|
rawInput: partialToolCall.text,
|
|
695
720
|
title: partialToolCall.title,
|
|
@@ -700,6 +725,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
700
725
|
toolCallId: chunk.toolCallId,
|
|
701
726
|
toolName: partialToolCall.toolName,
|
|
702
727
|
state: 'input-streaming',
|
|
728
|
+
inputEncoding: partialToolCall.inputEncoding,
|
|
703
729
|
input: partialArgs,
|
|
704
730
|
rawInput: partialToolCall.text,
|
|
705
731
|
title: partialToolCall.title,
|
package/src/ui/ui-messages.ts
CHANGED
|
@@ -308,6 +308,8 @@ export type UIToolInvocation<TOOL extends UITool | Tool> = {
|
|
|
308
308
|
* and later resumed.
|
|
309
309
|
*/
|
|
310
310
|
rawInput?: string;
|
|
311
|
+
/** Encoding of `rawInput`. Defaults to JSON when omitted. */
|
|
312
|
+
inputEncoding?: 'json' | 'text';
|
|
311
313
|
output?: never;
|
|
312
314
|
errorText?: never;
|
|
313
315
|
callProviderMetadata?: ProviderMetadata;
|
|
@@ -460,6 +462,8 @@ export type DynamicToolUIPart = {
|
|
|
460
462
|
* and later resumed.
|
|
461
463
|
*/
|
|
462
464
|
rawInput?: string;
|
|
465
|
+
/** Encoding of `rawInput`. Defaults to JSON when omitted. */
|
|
466
|
+
inputEncoding?: 'json' | 'text';
|
|
463
467
|
output?: never;
|
|
464
468
|
errorText?: never;
|
|
465
469
|
callProviderMetadata?: ProviderMetadata;
|
|
@@ -159,6 +159,7 @@ const uiMessagesSchema = lazySchema(() => {
|
|
|
159
159
|
state: z.literal('input-streaming'),
|
|
160
160
|
input: z.unknown().optional(),
|
|
161
161
|
rawInput: z.string().optional(),
|
|
162
|
+
inputEncoding: z.enum(['json', 'text']).optional(),
|
|
162
163
|
providerExecuted: z.boolean().optional(),
|
|
163
164
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
164
165
|
output: z.never().optional(),
|
|
@@ -269,6 +270,7 @@ const uiMessagesSchema = lazySchema(() => {
|
|
|
269
270
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
270
271
|
input: z.unknown().optional(),
|
|
271
272
|
rawInput: z.string().optional(),
|
|
273
|
+
inputEncoding: z.enum(['json', 'text']).optional(),
|
|
272
274
|
output: z.never().optional(),
|
|
273
275
|
errorText: z.never().optional(),
|
|
274
276
|
approval: z.never().optional(),
|
|
@@ -192,6 +192,9 @@ export function toUIMessageChunk<
|
|
|
192
192
|
type: 'tool-input-start',
|
|
193
193
|
toolCallId: part.id,
|
|
194
194
|
toolName: part.toolName,
|
|
195
|
+
...(part.inputEncoding != null
|
|
196
|
+
? { inputEncoding: part.inputEncoding }
|
|
197
|
+
: {}),
|
|
195
198
|
...(part.providerExecuted != null
|
|
196
199
|
? { providerExecuted: part.providerExecuted }
|
|
197
200
|
: {}),
|
|
@@ -49,6 +49,7 @@ export const uiMessageChunkSchema = lazySchema(() =>
|
|
|
49
49
|
type: z.literal('tool-input-start'),
|
|
50
50
|
toolCallId: z.string(),
|
|
51
51
|
toolName: z.string(),
|
|
52
|
+
inputEncoding: z.enum(['json', 'text']).optional(),
|
|
52
53
|
providerExecuted: z.boolean().optional(),
|
|
53
54
|
providerMetadata: providerMetadataSchema.optional(),
|
|
54
55
|
toolMetadata: toolMetadataSchema.optional(),
|
|
@@ -345,6 +346,8 @@ export type UIMessageChunk<
|
|
|
345
346
|
type: 'tool-input-start';
|
|
346
347
|
toolCallId: string;
|
|
347
348
|
toolName: string;
|
|
349
|
+
/** Encoding of the input deltas. Defaults to JSON when omitted. */
|
|
350
|
+
inputEncoding?: 'json' | 'text';
|
|
348
351
|
providerExecuted?: boolean;
|
|
349
352
|
providerMetadata?: ProviderMetadata;
|
|
350
353
|
toolMetadata?: JSONObject;
|