ai 5.0.0-canary.17 → 5.0.0-canary.19
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 +36 -0
- package/README.md +4 -4
- package/dist/index.d.mts +747 -510
- package/dist/index.d.ts +747 -510
- package/dist/index.js +3345 -3688
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3349 -3690
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +441 -214
- package/dist/internal/index.d.ts +441 -214
- package/dist/internal/index.js +911 -1360
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +911 -1355
- package/dist/internal/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.d.mts +2 -2
- package/dist/mcp-stdio/index.d.ts +2 -2
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
@@ -1,12 +1,47 @@
|
|
1
|
-
import { ToolCall, ToolResult, FetchFunction,
|
2
|
-
export {
|
3
|
-
import * as _ai_sdk_provider from '@ai-sdk/provider';
|
4
|
-
import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SharedV2ProviderOptions, SpeechModelV1, SpeechModelV1CallWarning, TranscriptionModelV1, TranscriptionModelV1CallWarning, JSONObject, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
5
|
-
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
6
|
-
import { ServerResponse } from 'node:http';
|
1
|
+
import { ToolCall, ToolResult, IdGenerator, FetchFunction, ToolResultContent, Schema } from '@ai-sdk/provider-utils';
|
2
|
+
export { IdGenerator, Schema, ToolCall, ToolResult, asSchema, createIdGenerator, generateId, jsonSchema } from '@ai-sdk/provider-utils';
|
7
3
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
4
|
+
import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SharedV2ProviderOptions, SpeechModelV1, SpeechModelV1CallWarning, TranscriptionModelV1, TranscriptionModelV1CallWarning, LanguageModelV2Usage, JSONObject, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
5
|
+
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
8
6
|
import { z } from 'zod';
|
9
7
|
import { ServerResponse as ServerResponse$1 } from 'http';
|
8
|
+
import { ServerResponse } from 'node:http';
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Telemetry configuration.
|
12
|
+
*/
|
13
|
+
type TelemetrySettings = {
|
14
|
+
/**
|
15
|
+
* Enable or disable telemetry. Disabled by default while experimental.
|
16
|
+
*/
|
17
|
+
isEnabled?: boolean;
|
18
|
+
/**
|
19
|
+
* Enable or disable input recording. Enabled by default.
|
20
|
+
*
|
21
|
+
* You might want to disable input recording to avoid recording sensitive
|
22
|
+
* information, to reduce data transfers, or to increase performance.
|
23
|
+
*/
|
24
|
+
recordInputs?: boolean;
|
25
|
+
/**
|
26
|
+
* Enable or disable output recording. Enabled by default.
|
27
|
+
*
|
28
|
+
* You might want to disable output recording to avoid recording sensitive
|
29
|
+
* information, to reduce data transfers, or to increase performance.
|
30
|
+
*/
|
31
|
+
recordOutputs?: boolean;
|
32
|
+
/**
|
33
|
+
* Identifier for this function. Used to group telemetry data by function.
|
34
|
+
*/
|
35
|
+
functionId?: string;
|
36
|
+
/**
|
37
|
+
* Additional information to include in the telemetry data.
|
38
|
+
*/
|
39
|
+
metadata?: Record<string, AttributeValue>;
|
40
|
+
/**
|
41
|
+
* A custom tracer to use for the telemetry data.
|
42
|
+
*/
|
43
|
+
tracer?: Tracer;
|
44
|
+
};
|
10
45
|
|
11
46
|
/**
|
12
47
|
Embedding model that is used by the AI SDK Core functions.
|
@@ -221,22 +256,17 @@ type TranscriptionModelResponseMetadata = {
|
|
221
256
|
/**
|
222
257
|
Represents the number of tokens used in a prompt and completion.
|
223
258
|
*/
|
224
|
-
type LanguageModelUsage
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
/**
|
230
|
-
The number of tokens used in the completion.
|
231
|
-
*/
|
232
|
-
completionTokens: number;
|
259
|
+
type LanguageModelUsage = LanguageModelV2Usage;
|
260
|
+
/**
|
261
|
+
Represents the number of tokens used in an embedding.
|
262
|
+
*/
|
263
|
+
type EmbeddingModelUsage = {
|
233
264
|
/**
|
234
|
-
The
|
265
|
+
The number of tokens used in the embedding.
|
235
266
|
*/
|
236
|
-
|
267
|
+
tokens: number;
|
237
268
|
};
|
238
269
|
|
239
|
-
type IdGenerator = () => string;
|
240
270
|
/**
|
241
271
|
Tool invocations are either tool calls or tool results. For each assistant tool call,
|
242
272
|
there is one tool invocation. While the call is in progress, the invocation is a tool call.
|
@@ -269,10 +299,6 @@ interface UIMessage {
|
|
269
299
|
*/
|
270
300
|
createdAt?: Date;
|
271
301
|
/**
|
272
|
-
Text content of the message. Use parts when possible.
|
273
|
-
*/
|
274
|
-
content: string;
|
275
|
-
/**
|
276
302
|
The role of the message.
|
277
303
|
*/
|
278
304
|
role: 'system' | 'user' | 'assistant';
|
@@ -415,12 +441,6 @@ type ChatRequestOptions = {
|
|
415
441
|
};
|
416
442
|
type UseChatOptions = {
|
417
443
|
/**
|
418
|
-
Keeps the last message when an error happens. Defaults to `true`.
|
419
|
-
|
420
|
-
@deprecated This option will be removed in the next major release.
|
421
|
-
*/
|
422
|
-
keepLastMessageOnError?: boolean;
|
423
|
-
/**
|
424
444
|
* The API endpoint that accepts a `{ messages: Message[] }` object and returns
|
425
445
|
* a stream of tokens of the AI chat response. Defaults to `/api/chat`.
|
426
446
|
*/
|
@@ -461,7 +481,7 @@ type UseChatOptions = {
|
|
461
481
|
* @param options.finishReason The finish reason of the message.
|
462
482
|
*/
|
463
483
|
onFinish?: (message: UIMessage, options: {
|
464
|
-
usage: LanguageModelUsage
|
484
|
+
usage: LanguageModelUsage;
|
465
485
|
finishReason: LanguageModelV2FinishReason;
|
466
486
|
}) => void;
|
467
487
|
/**
|
@@ -497,12 +517,6 @@ type UseChatOptions = {
|
|
497
517
|
*/
|
498
518
|
body?: object;
|
499
519
|
/**
|
500
|
-
* Whether to send extra message fields such as `message.id` and `message.createdAt` to the API.
|
501
|
-
* Defaults to `false`. When set to `true`, the API endpoint might need to
|
502
|
-
* handle the extra fields before forwarding the request to the AI service.
|
503
|
-
*/
|
504
|
-
sendExtraMessageFields?: boolean;
|
505
|
-
/**
|
506
520
|
Streaming protocol that is used. Defaults to `data`.
|
507
521
|
*/
|
508
522
|
streamProtocol?: 'data' | 'text';
|
@@ -511,6 +525,15 @@ type UseChatOptions = {
|
|
511
525
|
or to provide a custom fetch implementation for e.g. testing.
|
512
526
|
*/
|
513
527
|
fetch?: FetchFunction;
|
528
|
+
/**
|
529
|
+
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
530
|
+
Must be at least 1.
|
531
|
+
|
532
|
+
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
533
|
+
|
534
|
+
By default, it's set to 1, which means that only a single LLM call is made.
|
535
|
+
*/
|
536
|
+
maxSteps?: number;
|
514
537
|
};
|
515
538
|
type UseCompletionOptions = {
|
516
539
|
/**
|
@@ -578,364 +601,6 @@ type UseCompletionOptions = {
|
|
578
601
|
fetch?: FetchFunction;
|
579
602
|
};
|
580
603
|
|
581
|
-
/**
|
582
|
-
Represents the number of tokens used in a prompt and completion.
|
583
|
-
*/
|
584
|
-
type LanguageModelUsage = {
|
585
|
-
/**
|
586
|
-
The number of tokens used in the prompt.
|
587
|
-
*/
|
588
|
-
promptTokens: number;
|
589
|
-
/**
|
590
|
-
The number of tokens used in the completion.
|
591
|
-
*/
|
592
|
-
completionTokens: number;
|
593
|
-
/**
|
594
|
-
The total number of tokens used (promptTokens + completionTokens).
|
595
|
-
*/
|
596
|
-
totalTokens: number;
|
597
|
-
};
|
598
|
-
/**
|
599
|
-
Represents the number of tokens used in an embedding.
|
600
|
-
*/
|
601
|
-
type EmbeddingModelUsage = {
|
602
|
-
/**
|
603
|
-
The number of tokens used in the embedding.
|
604
|
-
*/
|
605
|
-
tokens: number;
|
606
|
-
};
|
607
|
-
|
608
|
-
declare const getOriginalFetch$1: () => typeof fetch;
|
609
|
-
declare function callChatApi({ api, body, streamProtocol, credentials, headers, abortController, restoreMessagesOnFailure, onResponse, onUpdate, onFinish, onToolCall, generateId, fetch, lastMessage, getCurrentDate, requestType, }: {
|
610
|
-
api: string;
|
611
|
-
body: Record<string, any>;
|
612
|
-
streamProtocol: 'data' | 'text' | undefined;
|
613
|
-
credentials: RequestCredentials | undefined;
|
614
|
-
headers: HeadersInit | undefined;
|
615
|
-
abortController: (() => AbortController | null) | undefined;
|
616
|
-
restoreMessagesOnFailure: () => void;
|
617
|
-
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
618
|
-
onUpdate: (options: {
|
619
|
-
message: UIMessage;
|
620
|
-
data: JSONValue$1[] | undefined;
|
621
|
-
replaceLastMessage: boolean;
|
622
|
-
}) => void;
|
623
|
-
onFinish: UseChatOptions['onFinish'];
|
624
|
-
onToolCall: UseChatOptions['onToolCall'];
|
625
|
-
generateId: IdGenerator;
|
626
|
-
fetch: ReturnType<typeof getOriginalFetch$1> | undefined;
|
627
|
-
lastMessage: UIMessage | undefined;
|
628
|
-
getCurrentDate: () => Date;
|
629
|
-
requestType?: 'generate' | 'resume';
|
630
|
-
}): Promise<void>;
|
631
|
-
|
632
|
-
declare const getOriginalFetch: () => typeof fetch;
|
633
|
-
declare function callCompletionApi({ api, prompt, credentials, headers, body, streamProtocol, setCompletion, setLoading, setError, setAbortController, onResponse, onFinish, onError, onData, fetch, }: {
|
634
|
-
api: string;
|
635
|
-
prompt: string;
|
636
|
-
credentials: RequestCredentials | undefined;
|
637
|
-
headers: HeadersInit | undefined;
|
638
|
-
body: Record<string, any>;
|
639
|
-
streamProtocol: 'data' | 'text' | undefined;
|
640
|
-
setCompletion: (completion: string) => void;
|
641
|
-
setLoading: (loading: boolean) => void;
|
642
|
-
setError: (error: Error | undefined) => void;
|
643
|
-
setAbortController: (abortController: AbortController | null) => void;
|
644
|
-
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
645
|
-
onFinish: ((prompt: string, completion: string) => void) | undefined;
|
646
|
-
onError: ((error: Error) => void) | undefined;
|
647
|
-
onData: ((data: JSONValue[]) => void) | undefined;
|
648
|
-
fetch: ReturnType<typeof getOriginalFetch> | undefined;
|
649
|
-
}): Promise<string | null | undefined>;
|
650
|
-
|
651
|
-
declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
|
652
|
-
|
653
|
-
type DataStreamString = `${(typeof DataStreamStringPrefixes)[keyof typeof DataStreamStringPrefixes]}:${string}\n`;
|
654
|
-
interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
|
655
|
-
code: CODE;
|
656
|
-
name: NAME;
|
657
|
-
parse: (value: JSONValue) => {
|
658
|
-
type: NAME;
|
659
|
-
value: TYPE;
|
660
|
-
};
|
661
|
-
}
|
662
|
-
declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "args" | "toolName">>, DataStreamPart<"b", "tool_call_streaming_start", {
|
663
|
-
toolCallId: string;
|
664
|
-
toolName: string;
|
665
|
-
}>, DataStreamPart<"c", "tool_call_delta", {
|
666
|
-
toolCallId: string;
|
667
|
-
argsTextDelta: string;
|
668
|
-
}>, DataStreamPart<"d", "finish_message", {
|
669
|
-
finishReason: LanguageModelV2FinishReason;
|
670
|
-
usage?: {
|
671
|
-
promptTokens: number;
|
672
|
-
completionTokens: number;
|
673
|
-
};
|
674
|
-
}>, DataStreamPart<"e", "finish_step", {
|
675
|
-
isContinued: boolean;
|
676
|
-
finishReason: LanguageModelV2FinishReason;
|
677
|
-
usage?: {
|
678
|
-
promptTokens: number;
|
679
|
-
completionTokens: number;
|
680
|
-
};
|
681
|
-
}>, DataStreamPart<"f", "start_step", {
|
682
|
-
messageId: string;
|
683
|
-
}>, DataStreamPart<"g", "reasoning", {
|
684
|
-
text: string;
|
685
|
-
providerMetadata?: Record<string, any> | undefined;
|
686
|
-
}>, DataStreamPart<"h", "source", LanguageModelV2Source>, DataStreamPart<"l", "reasoning_part_finish", {}>, DataStreamPart<"k", "file", {
|
687
|
-
url: string;
|
688
|
-
mediaType: string;
|
689
|
-
}>];
|
690
|
-
type DataStreamParts = (typeof dataStreamParts)[number];
|
691
|
-
/**
|
692
|
-
* Maps the type of a stream part to its value type.
|
693
|
-
*/
|
694
|
-
type DataStreamPartValueType = {
|
695
|
-
[P in DataStreamParts as P['name']]: ReturnType<P['parse']>['value'];
|
696
|
-
};
|
697
|
-
type DataStreamPartType = ReturnType<DataStreamParts['parse']>;
|
698
|
-
/**
|
699
|
-
* The map of prefixes for data in the stream
|
700
|
-
*
|
701
|
-
* - 0: Text from the LLM response
|
702
|
-
* - 1: (OpenAI) function_call responses
|
703
|
-
* - 2: custom JSON added by the user using `Data`
|
704
|
-
* - 6: (OpenAI) tool_call responses
|
705
|
-
*
|
706
|
-
* Example:
|
707
|
-
* ```
|
708
|
-
* 0:Vercel
|
709
|
-
* 0:'s
|
710
|
-
* 0: AI
|
711
|
-
* 0: AI
|
712
|
-
* 0: SDK
|
713
|
-
* 0: is great
|
714
|
-
* 0:!
|
715
|
-
* 2: { "someJson": "value" }
|
716
|
-
* 1: {"function_call": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}
|
717
|
-
* 6: {"tool_call": {"id": "tool_0", "type": "function", "function": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}}
|
718
|
-
*```
|
719
|
-
*/
|
720
|
-
declare const DataStreamStringPrefixes: { [K in DataStreamParts["name"]]: (typeof dataStreamParts)[number]["code"]; };
|
721
|
-
/**
|
722
|
-
Parses a stream part from a string.
|
723
|
-
|
724
|
-
@param line The string to parse.
|
725
|
-
@returns The parsed stream part.
|
726
|
-
@throws An error if the string cannot be parsed.
|
727
|
-
*/
|
728
|
-
declare const parseDataStreamPart: (line: string) => DataStreamPartType;
|
729
|
-
/**
|
730
|
-
Prepends a string with a prefix from the `StreamChunkPrefixes`, converts it to JSON,
|
731
|
-
and appends a new line.
|
732
|
-
|
733
|
-
It ensures type-safety for the part type and value.
|
734
|
-
*/
|
735
|
-
declare function formatDataStreamPart<T extends keyof DataStreamPartValueType>(type: T, value: DataStreamPartValueType[T]): DataStreamString;
|
736
|
-
|
737
|
-
/**
|
738
|
-
* Converts a data URL of type text/* to a text string.
|
739
|
-
*/
|
740
|
-
declare function getTextFromDataUrl(dataUrl: string): string;
|
741
|
-
|
742
|
-
/**
|
743
|
-
Create a type from an object with all keys and nested keys set to optional.
|
744
|
-
The helper supports normal objects and Zod schemas (which are resolved automatically).
|
745
|
-
It always recurses into arrays.
|
746
|
-
|
747
|
-
Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
|
748
|
-
*/
|
749
|
-
type DeepPartial<T> = T extends z.ZodTypeAny ? DeepPartialInternal<z.infer<T>> : DeepPartialInternal<T>;
|
750
|
-
type DeepPartialInternal<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartialInternal<ItemType | undefined>> : Array<DeepPartialInternal<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
|
751
|
-
type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
752
|
-
type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
|
753
|
-
type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
754
|
-
type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartialInternal<T>>;
|
755
|
-
type PartialObject<ObjectType extends object> = {
|
756
|
-
[KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
|
757
|
-
};
|
758
|
-
|
759
|
-
declare function extractMaxToolInvocationStep(toolInvocations: ToolInvocation[] | undefined): number | undefined;
|
760
|
-
|
761
|
-
/**
|
762
|
-
* Performs a deep-equal comparison of two parsed JSON objects.
|
763
|
-
*
|
764
|
-
* @param {any} obj1 - The first object to compare.
|
765
|
-
* @param {any} obj2 - The second object to compare.
|
766
|
-
* @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
|
767
|
-
*/
|
768
|
-
declare function isDeepEqualData(obj1: any, obj2: any): boolean;
|
769
|
-
|
770
|
-
declare function parsePartialJson(jsonText: string | undefined): Promise<{
|
771
|
-
value: JSONValue$1 | undefined;
|
772
|
-
state: 'undefined-input' | 'successful-parse' | 'repaired-parse' | 'failed-parse';
|
773
|
-
}>;
|
774
|
-
|
775
|
-
declare function processDataStream({ stream, onTextPart, onReasoningPart, onReasoningPartFinish, onSourcePart, onFilePart, onDataPart, onErrorPart, onToolCallStreamingStartPart, onToolCallDeltaPart, onToolCallPart, onToolResultPart, onMessageAnnotationsPart, onFinishMessagePart, onFinishStepPart, onStartStepPart, }: {
|
776
|
-
stream: ReadableStream<Uint8Array>;
|
777
|
-
onTextPart?: (streamPart: (DataStreamPartType & {
|
778
|
-
type: 'text';
|
779
|
-
})['value']) => Promise<void> | void;
|
780
|
-
onReasoningPart?: (streamPart: (DataStreamPartType & {
|
781
|
-
type: 'reasoning';
|
782
|
-
})['value']) => Promise<void> | void;
|
783
|
-
onReasoningPartFinish?: (streamPart: (DataStreamPartType & {
|
784
|
-
type: 'reasoning_part_finish';
|
785
|
-
})['value']) => Promise<void> | void;
|
786
|
-
onFilePart?: (streamPart: (DataStreamPartType & {
|
787
|
-
type: 'file';
|
788
|
-
})['value']) => Promise<void> | void;
|
789
|
-
onSourcePart?: (streamPart: (DataStreamPartType & {
|
790
|
-
type: 'source';
|
791
|
-
})['value']) => Promise<void> | void;
|
792
|
-
onDataPart?: (streamPart: (DataStreamPartType & {
|
793
|
-
type: 'data';
|
794
|
-
})['value']) => Promise<void> | void;
|
795
|
-
onErrorPart?: (streamPart: (DataStreamPartType & {
|
796
|
-
type: 'error';
|
797
|
-
})['value']) => Promise<void> | void;
|
798
|
-
onToolCallStreamingStartPart?: (streamPart: (DataStreamPartType & {
|
799
|
-
type: 'tool_call_streaming_start';
|
800
|
-
})['value']) => Promise<void> | void;
|
801
|
-
onToolCallDeltaPart?: (streamPart: (DataStreamPartType & {
|
802
|
-
type: 'tool_call_delta';
|
803
|
-
})['value']) => Promise<void> | void;
|
804
|
-
onToolCallPart?: (streamPart: (DataStreamPartType & {
|
805
|
-
type: 'tool_call';
|
806
|
-
})['value']) => Promise<void> | void;
|
807
|
-
onToolResultPart?: (streamPart: (DataStreamPartType & {
|
808
|
-
type: 'tool_result';
|
809
|
-
})['value']) => Promise<void> | void;
|
810
|
-
onMessageAnnotationsPart?: (streamPart: (DataStreamPartType & {
|
811
|
-
type: 'message_annotations';
|
812
|
-
})['value']) => Promise<void> | void;
|
813
|
-
onFinishMessagePart?: (streamPart: (DataStreamPartType & {
|
814
|
-
type: 'finish_message';
|
815
|
-
})['value']) => Promise<void> | void;
|
816
|
-
onFinishStepPart?: (streamPart: (DataStreamPartType & {
|
817
|
-
type: 'finish_step';
|
818
|
-
})['value']) => Promise<void> | void;
|
819
|
-
onStartStepPart?: (streamPart: (DataStreamPartType & {
|
820
|
-
type: 'start_step';
|
821
|
-
})['value']) => Promise<void> | void;
|
822
|
-
}): Promise<void>;
|
823
|
-
|
824
|
-
declare function processTextStream({ stream, onTextPart, }: {
|
825
|
-
stream: ReadableStream<Uint8Array>;
|
826
|
-
onTextPart: (chunk: string) => Promise<void> | void;
|
827
|
-
}): Promise<void>;
|
828
|
-
|
829
|
-
declare function shouldResubmitMessages({ originalMaxToolInvocationStep, originalMessageCount, maxSteps, messages, }: {
|
830
|
-
originalMaxToolInvocationStep: number | undefined;
|
831
|
-
originalMessageCount: number;
|
832
|
-
maxSteps: number;
|
833
|
-
messages: UIMessage[];
|
834
|
-
}): boolean;
|
835
|
-
/**
|
836
|
-
Check if the message is an assistant message with completed tool calls.
|
837
|
-
The last step of the message must have at least one tool invocation and
|
838
|
-
all tool invocations must have a result.
|
839
|
-
*/
|
840
|
-
declare function isAssistantMessageWithCompletedToolCalls(message: UIMessage): message is UIMessage & {
|
841
|
-
role: 'assistant';
|
842
|
-
};
|
843
|
-
|
844
|
-
/**
|
845
|
-
* Updates the result of a specific tool invocation in the last message of the given messages array.
|
846
|
-
*
|
847
|
-
* @param {object} params - The parameters object.
|
848
|
-
* @param {UIMessage[]} params.messages - An array of messages, from which the last one is updated.
|
849
|
-
* @param {string} params.toolCallId - The unique identifier for the tool invocation to update.
|
850
|
-
* @param {unknown} params.toolResult - The result object to attach to the tool invocation.
|
851
|
-
* @returns {void} This function does not return anything.
|
852
|
-
*/
|
853
|
-
declare function updateToolCallResult({ messages, toolCallId, toolResult: result, }: {
|
854
|
-
messages: UIMessage[];
|
855
|
-
toolCallId: string;
|
856
|
-
toolResult: unknown;
|
857
|
-
}): void;
|
858
|
-
|
859
|
-
interface DataStreamWriter {
|
860
|
-
/**
|
861
|
-
* Appends a data part to the stream.
|
862
|
-
*/
|
863
|
-
write(data: DataStreamString): void;
|
864
|
-
/**
|
865
|
-
* Appends a data part to the stream.
|
866
|
-
*/
|
867
|
-
writeData(value: JSONValue$1): void;
|
868
|
-
/**
|
869
|
-
* Appends a message annotation to the stream.
|
870
|
-
*/
|
871
|
-
writeMessageAnnotation(value: JSONValue$1): void;
|
872
|
-
/**
|
873
|
-
* Appends a source part to the stream.
|
874
|
-
*/
|
875
|
-
writeSource(source: Source): void;
|
876
|
-
/**
|
877
|
-
* Merges the contents of another stream to this stream.
|
878
|
-
*/
|
879
|
-
merge(stream: ReadableStream<DataStreamString>): void;
|
880
|
-
/**
|
881
|
-
* Error handler that is used by the data stream writer.
|
882
|
-
* This is intended for forwarding when merging streams
|
883
|
-
* to prevent duplicated error masking.
|
884
|
-
*/
|
885
|
-
onError: ((error: unknown) => string) | undefined;
|
886
|
-
}
|
887
|
-
|
888
|
-
declare function createDataStream({ execute, onError, }: {
|
889
|
-
execute: (dataStream: DataStreamWriter) => Promise<void> | void;
|
890
|
-
onError?: (error: unknown) => string;
|
891
|
-
}): ReadableStream<DataStreamString>;
|
892
|
-
|
893
|
-
declare function createDataStreamResponse({ status, statusText, headers, execute, onError, }: ResponseInit & {
|
894
|
-
execute: (dataStream: DataStreamWriter) => Promise<void> | void;
|
895
|
-
onError?: (error: unknown) => string;
|
896
|
-
}): Response;
|
897
|
-
|
898
|
-
declare function pipeDataStreamToResponse(response: ServerResponse, { status, statusText, headers, execute, onError, }: ResponseInit & {
|
899
|
-
execute: (writer: DataStreamWriter) => Promise<void> | void;
|
900
|
-
onError?: (error: unknown) => string;
|
901
|
-
}): void;
|
902
|
-
|
903
|
-
/**
|
904
|
-
* Telemetry configuration.
|
905
|
-
*/
|
906
|
-
type TelemetrySettings = {
|
907
|
-
/**
|
908
|
-
* Enable or disable telemetry. Disabled by default while experimental.
|
909
|
-
*/
|
910
|
-
isEnabled?: boolean;
|
911
|
-
/**
|
912
|
-
* Enable or disable input recording. Enabled by default.
|
913
|
-
*
|
914
|
-
* You might want to disable input recording to avoid recording sensitive
|
915
|
-
* information, to reduce data transfers, or to increase performance.
|
916
|
-
*/
|
917
|
-
recordInputs?: boolean;
|
918
|
-
/**
|
919
|
-
* Enable or disable output recording. Enabled by default.
|
920
|
-
*
|
921
|
-
* You might want to disable output recording to avoid recording sensitive
|
922
|
-
* information, to reduce data transfers, or to increase performance.
|
923
|
-
*/
|
924
|
-
recordOutputs?: boolean;
|
925
|
-
/**
|
926
|
-
* Identifier for this function. Used to group telemetry data by function.
|
927
|
-
*/
|
928
|
-
functionId?: string;
|
929
|
-
/**
|
930
|
-
* Additional information to include in the telemetry data.
|
931
|
-
*/
|
932
|
-
metadata?: Record<string, AttributeValue>;
|
933
|
-
/**
|
934
|
-
* A custom tracer to use for the telemetry data.
|
935
|
-
*/
|
936
|
-
tracer?: Tracer;
|
937
|
-
};
|
938
|
-
|
939
604
|
/**
|
940
605
|
The result of an `embed` call.
|
941
606
|
It contains the embedding, the value, and additional information.
|
@@ -1064,7 +729,7 @@ has a limit on how many embeddings can be generated in a single call.
|
|
1064
729
|
|
1065
730
|
@returns A result object that contains the embeddings, the value, and additional information.
|
1066
731
|
*/
|
1067
|
-
declare function embedMany<VALUE>({ model, values, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
|
732
|
+
declare function embedMany<VALUE>({ model, values, maxParallelCalls, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
|
1068
733
|
/**
|
1069
734
|
The embedding model to use.
|
1070
735
|
*/
|
@@ -1098,6 +763,12 @@ declare function embedMany<VALUE>({ model, values, maxRetries: maxRetriesArg, ab
|
|
1098
763
|
functionality that can be fully encapsulated in the provider.
|
1099
764
|
*/
|
1100
765
|
providerOptions?: ProviderOptions;
|
766
|
+
/**
|
767
|
+
* Maximum number of concurrent requests.
|
768
|
+
*
|
769
|
+
* @default Infinity
|
770
|
+
*/
|
771
|
+
maxParallelCalls?: number;
|
1101
772
|
}): Promise<EmbedManyResult<VALUE>>;
|
1102
773
|
|
1103
774
|
type CallSettings = {
|
@@ -1180,19 +851,6 @@ Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffe
|
|
1180
851
|
*/
|
1181
852
|
type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
1182
853
|
|
1183
|
-
type ToolResultContent = Array<{
|
1184
|
-
type: 'text';
|
1185
|
-
text: string;
|
1186
|
-
} | {
|
1187
|
-
type: 'image';
|
1188
|
-
data: string;
|
1189
|
-
mediaType?: string;
|
1190
|
-
/**
|
1191
|
-
* @deprecated Use `mediaType` instead.
|
1192
|
-
*/
|
1193
|
-
mimeType?: string;
|
1194
|
-
}>;
|
1195
|
-
|
1196
854
|
/**
|
1197
855
|
Text content part of a prompt. It contains a string of text.
|
1198
856
|
*/
|
@@ -1559,29 +1217,29 @@ declare const JSONRPCErrorSchema: z.ZodObject<{
|
|
1559
1217
|
message: z.ZodString;
|
1560
1218
|
data: z.ZodOptional<z.ZodUnknown>;
|
1561
1219
|
}, "strip", z.ZodTypeAny, {
|
1562
|
-
code: number;
|
1563
1220
|
message: string;
|
1221
|
+
code: number;
|
1564
1222
|
data?: unknown;
|
1565
1223
|
}, {
|
1566
|
-
code: number;
|
1567
1224
|
message: string;
|
1225
|
+
code: number;
|
1568
1226
|
data?: unknown;
|
1569
1227
|
}>;
|
1570
1228
|
}, "strict", z.ZodTypeAny, {
|
1571
|
-
id: string | number;
|
1572
1229
|
error: {
|
1573
|
-
code: number;
|
1574
1230
|
message: string;
|
1231
|
+
code: number;
|
1575
1232
|
data?: unknown;
|
1576
1233
|
};
|
1234
|
+
id: string | number;
|
1577
1235
|
jsonrpc: "2.0";
|
1578
1236
|
}, {
|
1579
|
-
id: string | number;
|
1580
1237
|
error: {
|
1581
|
-
code: number;
|
1582
1238
|
message: string;
|
1239
|
+
code: number;
|
1583
1240
|
data?: unknown;
|
1584
1241
|
};
|
1242
|
+
id: string | number;
|
1585
1243
|
jsonrpc: "2.0";
|
1586
1244
|
}>;
|
1587
1245
|
type JSONRPCError = z.infer<typeof JSONRPCErrorSchema>;
|
@@ -1693,76 +1351,193 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
|
|
1693
1351
|
message: z.ZodString;
|
1694
1352
|
data: z.ZodOptional<z.ZodUnknown>;
|
1695
1353
|
}, "strip", z.ZodTypeAny, {
|
1696
|
-
code: number;
|
1697
1354
|
message: string;
|
1355
|
+
code: number;
|
1698
1356
|
data?: unknown;
|
1699
1357
|
}, {
|
1700
|
-
code: number;
|
1701
1358
|
message: string;
|
1359
|
+
code: number;
|
1702
1360
|
data?: unknown;
|
1703
1361
|
}>;
|
1704
1362
|
}, "strict", z.ZodTypeAny, {
|
1705
|
-
id: string | number;
|
1706
1363
|
error: {
|
1707
|
-
code: number;
|
1708
1364
|
message: string;
|
1365
|
+
code: number;
|
1709
1366
|
data?: unknown;
|
1710
1367
|
};
|
1368
|
+
id: string | number;
|
1711
1369
|
jsonrpc: "2.0";
|
1712
1370
|
}, {
|
1713
|
-
id: string | number;
|
1714
1371
|
error: {
|
1715
|
-
code: number;
|
1716
1372
|
message: string;
|
1373
|
+
code: number;
|
1717
1374
|
data?: unknown;
|
1718
1375
|
};
|
1376
|
+
id: string | number;
|
1719
1377
|
jsonrpc: "2.0";
|
1720
1378
|
}>]>;
|
1721
1379
|
type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
|
1722
1380
|
|
1723
1381
|
/**
|
1724
|
-
* Transport interface for MCP (Model Context Protocol) communication.
|
1725
|
-
* Maps to the `Transport` interface in the MCP spec.
|
1382
|
+
* Transport interface for MCP (Model Context Protocol) communication.
|
1383
|
+
* Maps to the `Transport` interface in the MCP spec.
|
1384
|
+
*/
|
1385
|
+
interface MCPTransport {
|
1386
|
+
/**
|
1387
|
+
* Initialize and start the transport
|
1388
|
+
*/
|
1389
|
+
start(): Promise<void>;
|
1390
|
+
/**
|
1391
|
+
* Send a JSON-RPC message through the transport
|
1392
|
+
* @param message The JSON-RPC message to send
|
1393
|
+
*/
|
1394
|
+
send(message: JSONRPCMessage): Promise<void>;
|
1395
|
+
/**
|
1396
|
+
* Clean up and close the transport
|
1397
|
+
*/
|
1398
|
+
close(): Promise<void>;
|
1399
|
+
/**
|
1400
|
+
* Event handler for transport closure
|
1401
|
+
*/
|
1402
|
+
onclose?: () => void;
|
1403
|
+
/**
|
1404
|
+
* Event handler for transport errors
|
1405
|
+
*/
|
1406
|
+
onerror?: (error: Error) => void;
|
1407
|
+
/**
|
1408
|
+
* Event handler for received messages
|
1409
|
+
*/
|
1410
|
+
onmessage?: (message: JSONRPCMessage) => void;
|
1411
|
+
}
|
1412
|
+
type MCPTransportConfig = {
|
1413
|
+
type: 'sse';
|
1414
|
+
/**
|
1415
|
+
* The URL of the MCP server.
|
1416
|
+
*/
|
1417
|
+
url: string;
|
1418
|
+
/**
|
1419
|
+
* Additional HTTP headers to be sent with requests.
|
1420
|
+
*/
|
1421
|
+
headers?: Record<string, string>;
|
1422
|
+
};
|
1423
|
+
|
1424
|
+
declare const getOriginalFetch$1: () => typeof fetch;
|
1425
|
+
declare function callChatApi({ api, body, streamProtocol, credentials, headers, abortController, onResponse, onUpdate, onFinish, onToolCall, generateId, fetch, lastMessage, getCurrentDate, requestType, }: {
|
1426
|
+
api: string;
|
1427
|
+
body: Record<string, any>;
|
1428
|
+
streamProtocol: 'data' | 'text' | undefined;
|
1429
|
+
credentials: RequestCredentials | undefined;
|
1430
|
+
headers: HeadersInit | undefined;
|
1431
|
+
abortController: (() => AbortController | null) | undefined;
|
1432
|
+
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
1433
|
+
onUpdate: (options: {
|
1434
|
+
message: UIMessage;
|
1435
|
+
data: JSONValue$1[] | undefined;
|
1436
|
+
replaceLastMessage: boolean;
|
1437
|
+
}) => void;
|
1438
|
+
onFinish: UseChatOptions['onFinish'];
|
1439
|
+
onToolCall: UseChatOptions['onToolCall'];
|
1440
|
+
generateId: IdGenerator;
|
1441
|
+
fetch: ReturnType<typeof getOriginalFetch$1> | undefined;
|
1442
|
+
lastMessage: UIMessage | undefined;
|
1443
|
+
getCurrentDate: () => Date;
|
1444
|
+
requestType?: 'generate' | 'resume';
|
1445
|
+
}): Promise<void>;
|
1446
|
+
|
1447
|
+
declare const getOriginalFetch: () => typeof fetch;
|
1448
|
+
declare function callCompletionApi({ api, prompt, credentials, headers, body, streamProtocol, setCompletion, setLoading, setError, setAbortController, onResponse, onFinish, onError, onData, fetch, }: {
|
1449
|
+
api: string;
|
1450
|
+
prompt: string;
|
1451
|
+
credentials: RequestCredentials | undefined;
|
1452
|
+
headers: HeadersInit | undefined;
|
1453
|
+
body: Record<string, any>;
|
1454
|
+
streamProtocol: 'data' | 'text' | undefined;
|
1455
|
+
setCompletion: (completion: string) => void;
|
1456
|
+
setLoading: (loading: boolean) => void;
|
1457
|
+
setError: (error: Error | undefined) => void;
|
1458
|
+
setAbortController: (abortController: AbortController | null) => void;
|
1459
|
+
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
1460
|
+
onFinish: ((prompt: string, completion: string) => void) | undefined;
|
1461
|
+
onError: ((error: Error) => void) | undefined;
|
1462
|
+
onData: ((data: JSONValue$1[]) => void) | undefined;
|
1463
|
+
fetch: ReturnType<typeof getOriginalFetch> | undefined;
|
1464
|
+
}): Promise<string | null | undefined>;
|
1465
|
+
|
1466
|
+
declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
|
1467
|
+
|
1468
|
+
/**
|
1469
|
+
* Converts a data URL of type text/* to a text string.
|
1470
|
+
*/
|
1471
|
+
declare function getTextFromDataUrl(dataUrl: string): string;
|
1472
|
+
|
1473
|
+
/**
|
1474
|
+
Create a type from an object with all keys and nested keys set to optional.
|
1475
|
+
The helper supports normal objects and Zod schemas (which are resolved automatically).
|
1476
|
+
It always recurses into arrays.
|
1477
|
+
|
1478
|
+
Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
|
1479
|
+
*/
|
1480
|
+
type DeepPartial<T> = T extends z.ZodTypeAny ? DeepPartialInternal<z.infer<T>> : DeepPartialInternal<T>;
|
1481
|
+
type DeepPartialInternal<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartialInternal<ItemType | undefined>> : Array<DeepPartialInternal<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
|
1482
|
+
type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
1483
|
+
type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
|
1484
|
+
type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
1485
|
+
type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartialInternal<T>>;
|
1486
|
+
type PartialObject<ObjectType extends object> = {
|
1487
|
+
[KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
|
1488
|
+
};
|
1489
|
+
|
1490
|
+
declare function extractMaxToolInvocationStep(toolInvocations: ToolInvocation[] | undefined): number | undefined;
|
1491
|
+
|
1492
|
+
/**
|
1493
|
+
* Performs a deep-equal comparison of two parsed JSON objects.
|
1494
|
+
*
|
1495
|
+
* @param {any} obj1 - The first object to compare.
|
1496
|
+
* @param {any} obj2 - The second object to compare.
|
1497
|
+
* @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
|
1498
|
+
*/
|
1499
|
+
declare function isDeepEqualData(obj1: any, obj2: any): boolean;
|
1500
|
+
|
1501
|
+
declare function parsePartialJson(jsonText: string | undefined): Promise<{
|
1502
|
+
value: JSONValue$1 | undefined;
|
1503
|
+
state: 'undefined-input' | 'successful-parse' | 'repaired-parse' | 'failed-parse';
|
1504
|
+
}>;
|
1505
|
+
|
1506
|
+
declare function processTextStream({ stream, onTextPart, }: {
|
1507
|
+
stream: ReadableStream<Uint8Array>;
|
1508
|
+
onTextPart: (chunk: string) => Promise<void> | void;
|
1509
|
+
}): Promise<void>;
|
1510
|
+
|
1511
|
+
declare function shouldResubmitMessages({ originalMaxToolInvocationStep, originalMessageCount, maxSteps, messages, }: {
|
1512
|
+
originalMaxToolInvocationStep: number | undefined;
|
1513
|
+
originalMessageCount: number;
|
1514
|
+
maxSteps: number;
|
1515
|
+
messages: UIMessage[];
|
1516
|
+
}): boolean;
|
1517
|
+
/**
|
1518
|
+
Check if the message is an assistant message with completed tool calls.
|
1519
|
+
The last step of the message must have at least one tool invocation and
|
1520
|
+
all tool invocations must have a result.
|
1726
1521
|
*/
|
1727
|
-
|
1728
|
-
|
1729
|
-
* Initialize and start the transport
|
1730
|
-
*/
|
1731
|
-
start(): Promise<void>;
|
1732
|
-
/**
|
1733
|
-
* Send a JSON-RPC message through the transport
|
1734
|
-
* @param message The JSON-RPC message to send
|
1735
|
-
*/
|
1736
|
-
send(message: JSONRPCMessage): Promise<void>;
|
1737
|
-
/**
|
1738
|
-
* Clean up and close the transport
|
1739
|
-
*/
|
1740
|
-
close(): Promise<void>;
|
1741
|
-
/**
|
1742
|
-
* Event handler for transport closure
|
1743
|
-
*/
|
1744
|
-
onclose?: () => void;
|
1745
|
-
/**
|
1746
|
-
* Event handler for transport errors
|
1747
|
-
*/
|
1748
|
-
onerror?: (error: Error) => void;
|
1749
|
-
/**
|
1750
|
-
* Event handler for received messages
|
1751
|
-
*/
|
1752
|
-
onmessage?: (message: JSONRPCMessage) => void;
|
1753
|
-
}
|
1754
|
-
type MCPTransportConfig = {
|
1755
|
-
type: 'sse';
|
1756
|
-
/**
|
1757
|
-
* The URL of the MCP server.
|
1758
|
-
*/
|
1759
|
-
url: string;
|
1760
|
-
/**
|
1761
|
-
* Additional HTTP headers to be sent with requests.
|
1762
|
-
*/
|
1763
|
-
headers?: Record<string, string>;
|
1522
|
+
declare function isAssistantMessageWithCompletedToolCalls(message: UIMessage): message is UIMessage & {
|
1523
|
+
role: 'assistant';
|
1764
1524
|
};
|
1765
1525
|
|
1526
|
+
/**
|
1527
|
+
* Updates the result of a specific tool invocation in the last message of the given messages array.
|
1528
|
+
*
|
1529
|
+
* @param {object} params - The parameters object.
|
1530
|
+
* @param {UIMessage[]} params.messages - An array of messages, from which the last one is updated.
|
1531
|
+
* @param {string} params.toolCallId - The unique identifier for the tool invocation to update.
|
1532
|
+
* @param {unknown} params.toolResult - The result object to attach to the tool invocation.
|
1533
|
+
* @returns {void} This function does not return anything.
|
1534
|
+
*/
|
1535
|
+
declare function updateToolCallResult({ messages, toolCallId, toolResult: result, }: {
|
1536
|
+
messages: UIMessage[];
|
1537
|
+
toolCallId: string;
|
1538
|
+
toolResult: unknown;
|
1539
|
+
}): void;
|
1540
|
+
|
1766
1541
|
type ToolParameters<T = JSONObject> = z.Schema<T> | Schema<T>;
|
1767
1542
|
interface ToolExecutionOptions {
|
1768
1543
|
/**
|
@@ -2692,7 +2467,7 @@ type ToolResultArray<TOOLS extends ToolSet> = Array<ToolResultUnion<TOOLS>>;
|
|
2692
2467
|
A message that was generated during the generation process.
|
2693
2468
|
It can be either an assistant message or a tool message.
|
2694
2469
|
*/
|
2695
|
-
type ResponseMessage = (
|
2470
|
+
type ResponseMessage = (AssistantModelMessage | ToolModelMessage) & {
|
2696
2471
|
/**
|
2697
2472
|
Message ID generated by the AI SDK.
|
2698
2473
|
*/
|
@@ -3065,7 +2840,7 @@ By default, it's set to 1, which means that only a single LLM call is made.
|
|
3065
2840
|
/**
|
3066
2841
|
Generate a unique ID for each message.
|
3067
2842
|
*/
|
3068
|
-
experimental_generateMessageId?:
|
2843
|
+
experimental_generateMessageId?: IdGenerator;
|
3069
2844
|
/**
|
3070
2845
|
When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
|
3071
2846
|
|
@@ -3125,31 +2900,422 @@ A function that attempts to repair a tool call that failed to parse.
|
|
3125
2900
|
* Internal. For test use only. May change without notice.
|
3126
2901
|
*/
|
3127
2902
|
_internal?: {
|
3128
|
-
generateId?:
|
2903
|
+
generateId?: IdGenerator;
|
3129
2904
|
currentDate?: () => Date;
|
3130
2905
|
};
|
3131
2906
|
}): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
3132
2907
|
|
3133
|
-
|
3134
|
-
|
3135
|
-
|
3136
|
-
|
3137
|
-
|
3138
|
-
|
3139
|
-
|
3140
|
-
|
3141
|
-
|
3142
|
-
|
3143
|
-
|
3144
|
-
|
3145
|
-
|
3146
|
-
|
3147
|
-
|
3148
|
-
}
|
2908
|
+
declare const dataStreamPartSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
2909
|
+
type: z.ZodLiteral<"text">;
|
2910
|
+
value: z.ZodString;
|
2911
|
+
}, "strip", z.ZodTypeAny, {
|
2912
|
+
value: string;
|
2913
|
+
type: "text";
|
2914
|
+
}, {
|
2915
|
+
value: string;
|
2916
|
+
type: "text";
|
2917
|
+
}>, z.ZodObject<{
|
2918
|
+
type: z.ZodLiteral<"data">;
|
2919
|
+
value: z.ZodArray<z.ZodAny, "many">;
|
2920
|
+
}, "strip", z.ZodTypeAny, {
|
2921
|
+
value: any[];
|
2922
|
+
type: "data";
|
2923
|
+
}, {
|
2924
|
+
value: any[];
|
2925
|
+
type: "data";
|
2926
|
+
}>, z.ZodObject<{
|
2927
|
+
type: z.ZodLiteral<"error">;
|
2928
|
+
value: z.ZodString;
|
2929
|
+
}, "strip", z.ZodTypeAny, {
|
2930
|
+
value: string;
|
2931
|
+
type: "error";
|
2932
|
+
}, {
|
2933
|
+
value: string;
|
2934
|
+
type: "error";
|
2935
|
+
}>, z.ZodObject<{
|
2936
|
+
type: z.ZodLiteral<"message-annotations">;
|
2937
|
+
value: z.ZodArray<z.ZodAny, "many">;
|
2938
|
+
}, "strip", z.ZodTypeAny, {
|
2939
|
+
value: any[];
|
2940
|
+
type: "message-annotations";
|
2941
|
+
}, {
|
2942
|
+
value: any[];
|
2943
|
+
type: "message-annotations";
|
2944
|
+
}>, z.ZodObject<{
|
2945
|
+
type: z.ZodLiteral<"tool-call">;
|
2946
|
+
value: z.ZodObject<{
|
2947
|
+
toolCallId: z.ZodString;
|
2948
|
+
toolName: z.ZodString;
|
2949
|
+
args: z.ZodUnknown;
|
2950
|
+
}, "strip", z.ZodTypeAny, {
|
2951
|
+
toolName: string;
|
2952
|
+
toolCallId: string;
|
2953
|
+
args?: unknown;
|
2954
|
+
}, {
|
2955
|
+
toolName: string;
|
2956
|
+
toolCallId: string;
|
2957
|
+
args?: unknown;
|
2958
|
+
}>;
|
2959
|
+
}, "strip", z.ZodTypeAny, {
|
2960
|
+
value: {
|
2961
|
+
toolName: string;
|
2962
|
+
toolCallId: string;
|
2963
|
+
args?: unknown;
|
2964
|
+
};
|
2965
|
+
type: "tool-call";
|
2966
|
+
}, {
|
2967
|
+
value: {
|
2968
|
+
toolName: string;
|
2969
|
+
toolCallId: string;
|
2970
|
+
args?: unknown;
|
2971
|
+
};
|
2972
|
+
type: "tool-call";
|
2973
|
+
}>, z.ZodObject<{
|
2974
|
+
type: z.ZodLiteral<"tool-result">;
|
2975
|
+
value: z.ZodObject<{
|
2976
|
+
toolCallId: z.ZodString;
|
2977
|
+
result: z.ZodUnknown;
|
2978
|
+
providerMetadata: z.ZodOptional<z.ZodAny>;
|
2979
|
+
}, "strip", z.ZodTypeAny, {
|
2980
|
+
toolCallId: string;
|
2981
|
+
result?: unknown;
|
2982
|
+
providerMetadata?: any;
|
2983
|
+
}, {
|
2984
|
+
toolCallId: string;
|
2985
|
+
result?: unknown;
|
2986
|
+
providerMetadata?: any;
|
2987
|
+
}>;
|
2988
|
+
}, "strip", z.ZodTypeAny, {
|
2989
|
+
value: {
|
2990
|
+
toolCallId: string;
|
2991
|
+
result?: unknown;
|
2992
|
+
providerMetadata?: any;
|
2993
|
+
};
|
2994
|
+
type: "tool-result";
|
2995
|
+
}, {
|
2996
|
+
value: {
|
2997
|
+
toolCallId: string;
|
2998
|
+
result?: unknown;
|
2999
|
+
providerMetadata?: any;
|
3000
|
+
};
|
3001
|
+
type: "tool-result";
|
3002
|
+
}>, z.ZodObject<{
|
3003
|
+
type: z.ZodLiteral<"tool-call-streaming-start">;
|
3004
|
+
value: z.ZodObject<{
|
3005
|
+
toolCallId: z.ZodString;
|
3006
|
+
toolName: z.ZodString;
|
3007
|
+
}, "strip", z.ZodTypeAny, {
|
3008
|
+
toolName: string;
|
3009
|
+
toolCallId: string;
|
3010
|
+
}, {
|
3011
|
+
toolName: string;
|
3012
|
+
toolCallId: string;
|
3013
|
+
}>;
|
3014
|
+
}, "strip", z.ZodTypeAny, {
|
3015
|
+
value: {
|
3016
|
+
toolName: string;
|
3017
|
+
toolCallId: string;
|
3018
|
+
};
|
3019
|
+
type: "tool-call-streaming-start";
|
3020
|
+
}, {
|
3021
|
+
value: {
|
3022
|
+
toolName: string;
|
3023
|
+
toolCallId: string;
|
3024
|
+
};
|
3025
|
+
type: "tool-call-streaming-start";
|
3026
|
+
}>, z.ZodObject<{
|
3027
|
+
type: z.ZodLiteral<"tool-call-delta">;
|
3028
|
+
value: z.ZodObject<{
|
3029
|
+
toolCallId: z.ZodString;
|
3030
|
+
argsTextDelta: z.ZodString;
|
3031
|
+
}, "strip", z.ZodTypeAny, {
|
3032
|
+
toolCallId: string;
|
3033
|
+
argsTextDelta: string;
|
3034
|
+
}, {
|
3035
|
+
toolCallId: string;
|
3036
|
+
argsTextDelta: string;
|
3037
|
+
}>;
|
3038
|
+
}, "strip", z.ZodTypeAny, {
|
3039
|
+
value: {
|
3040
|
+
toolCallId: string;
|
3041
|
+
argsTextDelta: string;
|
3042
|
+
};
|
3043
|
+
type: "tool-call-delta";
|
3044
|
+
}, {
|
3045
|
+
value: {
|
3046
|
+
toolCallId: string;
|
3047
|
+
argsTextDelta: string;
|
3048
|
+
};
|
3049
|
+
type: "tool-call-delta";
|
3050
|
+
}>, z.ZodObject<{
|
3051
|
+
type: z.ZodLiteral<"finish-message">;
|
3052
|
+
value: z.ZodObject<{
|
3053
|
+
finishReason: z.ZodEnum<["stop", "length", "tool-calls", "content-filter", "other", "error", "unknown"]>;
|
3054
|
+
usage: z.ZodOptional<z.ZodObject<{
|
3055
|
+
inputTokens: z.ZodOptional<z.ZodNumber>;
|
3056
|
+
outputTokens: z.ZodOptional<z.ZodNumber>;
|
3057
|
+
totalTokens: z.ZodOptional<z.ZodNumber>;
|
3058
|
+
reasoningTokens: z.ZodOptional<z.ZodNumber>;
|
3059
|
+
cachedInputTokens: z.ZodOptional<z.ZodNumber>;
|
3060
|
+
}, "strip", z.ZodTypeAny, {
|
3061
|
+
inputTokens?: number | undefined;
|
3062
|
+
outputTokens?: number | undefined;
|
3063
|
+
totalTokens?: number | undefined;
|
3064
|
+
reasoningTokens?: number | undefined;
|
3065
|
+
cachedInputTokens?: number | undefined;
|
3066
|
+
}, {
|
3067
|
+
inputTokens?: number | undefined;
|
3068
|
+
outputTokens?: number | undefined;
|
3069
|
+
totalTokens?: number | undefined;
|
3070
|
+
reasoningTokens?: number | undefined;
|
3071
|
+
cachedInputTokens?: number | undefined;
|
3072
|
+
}>>;
|
3073
|
+
}, "strip", z.ZodTypeAny, {
|
3074
|
+
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3075
|
+
usage?: {
|
3076
|
+
inputTokens?: number | undefined;
|
3077
|
+
outputTokens?: number | undefined;
|
3078
|
+
totalTokens?: number | undefined;
|
3079
|
+
reasoningTokens?: number | undefined;
|
3080
|
+
cachedInputTokens?: number | undefined;
|
3081
|
+
} | undefined;
|
3082
|
+
}, {
|
3083
|
+
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3084
|
+
usage?: {
|
3085
|
+
inputTokens?: number | undefined;
|
3086
|
+
outputTokens?: number | undefined;
|
3087
|
+
totalTokens?: number | undefined;
|
3088
|
+
reasoningTokens?: number | undefined;
|
3089
|
+
cachedInputTokens?: number | undefined;
|
3090
|
+
} | undefined;
|
3091
|
+
}>;
|
3092
|
+
}, "strip", z.ZodTypeAny, {
|
3093
|
+
value: {
|
3094
|
+
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3095
|
+
usage?: {
|
3096
|
+
inputTokens?: number | undefined;
|
3097
|
+
outputTokens?: number | undefined;
|
3098
|
+
totalTokens?: number | undefined;
|
3099
|
+
reasoningTokens?: number | undefined;
|
3100
|
+
cachedInputTokens?: number | undefined;
|
3101
|
+
} | undefined;
|
3102
|
+
};
|
3103
|
+
type: "finish-message";
|
3104
|
+
}, {
|
3105
|
+
value: {
|
3106
|
+
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3107
|
+
usage?: {
|
3108
|
+
inputTokens?: number | undefined;
|
3109
|
+
outputTokens?: number | undefined;
|
3110
|
+
totalTokens?: number | undefined;
|
3111
|
+
reasoningTokens?: number | undefined;
|
3112
|
+
cachedInputTokens?: number | undefined;
|
3113
|
+
} | undefined;
|
3114
|
+
};
|
3115
|
+
type: "finish-message";
|
3116
|
+
}>, z.ZodObject<{
|
3117
|
+
type: z.ZodLiteral<"finish-step">;
|
3118
|
+
value: z.ZodObject<{
|
3119
|
+
isContinued: z.ZodBoolean;
|
3120
|
+
finishReason: z.ZodEnum<["stop", "length", "tool-calls", "content-filter", "other", "error", "unknown"]>;
|
3121
|
+
usage: z.ZodOptional<z.ZodObject<{
|
3122
|
+
inputTokens: z.ZodOptional<z.ZodNumber>;
|
3123
|
+
outputTokens: z.ZodOptional<z.ZodNumber>;
|
3124
|
+
totalTokens: z.ZodOptional<z.ZodNumber>;
|
3125
|
+
reasoningTokens: z.ZodOptional<z.ZodNumber>;
|
3126
|
+
cachedInputTokens: z.ZodOptional<z.ZodNumber>;
|
3127
|
+
}, "strip", z.ZodTypeAny, {
|
3128
|
+
inputTokens?: number | undefined;
|
3129
|
+
outputTokens?: number | undefined;
|
3130
|
+
totalTokens?: number | undefined;
|
3131
|
+
reasoningTokens?: number | undefined;
|
3132
|
+
cachedInputTokens?: number | undefined;
|
3133
|
+
}, {
|
3134
|
+
inputTokens?: number | undefined;
|
3135
|
+
outputTokens?: number | undefined;
|
3136
|
+
totalTokens?: number | undefined;
|
3137
|
+
reasoningTokens?: number | undefined;
|
3138
|
+
cachedInputTokens?: number | undefined;
|
3139
|
+
}>>;
|
3140
|
+
}, "strip", z.ZodTypeAny, {
|
3141
|
+
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3142
|
+
isContinued: boolean;
|
3143
|
+
usage?: {
|
3144
|
+
inputTokens?: number | undefined;
|
3145
|
+
outputTokens?: number | undefined;
|
3146
|
+
totalTokens?: number | undefined;
|
3147
|
+
reasoningTokens?: number | undefined;
|
3148
|
+
cachedInputTokens?: number | undefined;
|
3149
|
+
} | undefined;
|
3150
|
+
}, {
|
3151
|
+
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3152
|
+
isContinued: boolean;
|
3153
|
+
usage?: {
|
3154
|
+
inputTokens?: number | undefined;
|
3155
|
+
outputTokens?: number | undefined;
|
3156
|
+
totalTokens?: number | undefined;
|
3157
|
+
reasoningTokens?: number | undefined;
|
3158
|
+
cachedInputTokens?: number | undefined;
|
3159
|
+
} | undefined;
|
3160
|
+
}>;
|
3161
|
+
}, "strip", z.ZodTypeAny, {
|
3162
|
+
value: {
|
3163
|
+
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3164
|
+
isContinued: boolean;
|
3165
|
+
usage?: {
|
3166
|
+
inputTokens?: number | undefined;
|
3167
|
+
outputTokens?: number | undefined;
|
3168
|
+
totalTokens?: number | undefined;
|
3169
|
+
reasoningTokens?: number | undefined;
|
3170
|
+
cachedInputTokens?: number | undefined;
|
3171
|
+
} | undefined;
|
3172
|
+
};
|
3173
|
+
type: "finish-step";
|
3174
|
+
}, {
|
3175
|
+
value: {
|
3176
|
+
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3177
|
+
isContinued: boolean;
|
3178
|
+
usage?: {
|
3179
|
+
inputTokens?: number | undefined;
|
3180
|
+
outputTokens?: number | undefined;
|
3181
|
+
totalTokens?: number | undefined;
|
3182
|
+
reasoningTokens?: number | undefined;
|
3183
|
+
cachedInputTokens?: number | undefined;
|
3184
|
+
} | undefined;
|
3185
|
+
};
|
3186
|
+
type: "finish-step";
|
3187
|
+
}>, z.ZodObject<{
|
3188
|
+
type: z.ZodLiteral<"start-step">;
|
3189
|
+
value: z.ZodObject<{
|
3190
|
+
messageId: z.ZodString;
|
3191
|
+
}, "strip", z.ZodTypeAny, {
|
3192
|
+
messageId: string;
|
3193
|
+
}, {
|
3194
|
+
messageId: string;
|
3195
|
+
}>;
|
3196
|
+
}, "strip", z.ZodTypeAny, {
|
3197
|
+
value: {
|
3198
|
+
messageId: string;
|
3199
|
+
};
|
3200
|
+
type: "start-step";
|
3201
|
+
}, {
|
3202
|
+
value: {
|
3203
|
+
messageId: string;
|
3204
|
+
};
|
3205
|
+
type: "start-step";
|
3206
|
+
}>, z.ZodObject<{
|
3207
|
+
type: z.ZodLiteral<"reasoning">;
|
3208
|
+
value: z.ZodObject<{
|
3209
|
+
text: z.ZodString;
|
3210
|
+
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
3211
|
+
}, "strip", z.ZodTypeAny, {
|
3212
|
+
text: string;
|
3213
|
+
providerMetadata?: Record<string, any> | undefined;
|
3214
|
+
}, {
|
3215
|
+
text: string;
|
3216
|
+
providerMetadata?: Record<string, any> | undefined;
|
3217
|
+
}>;
|
3218
|
+
}, "strip", z.ZodTypeAny, {
|
3219
|
+
value: {
|
3220
|
+
text: string;
|
3221
|
+
providerMetadata?: Record<string, any> | undefined;
|
3222
|
+
};
|
3223
|
+
type: "reasoning";
|
3224
|
+
}, {
|
3225
|
+
value: {
|
3226
|
+
text: string;
|
3227
|
+
providerMetadata?: Record<string, any> | undefined;
|
3228
|
+
};
|
3229
|
+
type: "reasoning";
|
3230
|
+
}>, z.ZodObject<{
|
3231
|
+
type: z.ZodLiteral<"source">;
|
3232
|
+
value: z.ZodObject<{
|
3233
|
+
type: z.ZodLiteral<"source">;
|
3234
|
+
sourceType: z.ZodLiteral<"url">;
|
3235
|
+
id: z.ZodString;
|
3236
|
+
url: z.ZodString;
|
3237
|
+
title: z.ZodOptional<z.ZodString>;
|
3238
|
+
providerMetadata: z.ZodOptional<z.ZodAny>;
|
3239
|
+
}, "strip", z.ZodTypeAny, {
|
3240
|
+
type: "source";
|
3241
|
+
id: string;
|
3242
|
+
sourceType: "url";
|
3243
|
+
url: string;
|
3244
|
+
providerMetadata?: any;
|
3245
|
+
title?: string | undefined;
|
3246
|
+
}, {
|
3247
|
+
type: "source";
|
3248
|
+
id: string;
|
3249
|
+
sourceType: "url";
|
3250
|
+
url: string;
|
3251
|
+
providerMetadata?: any;
|
3252
|
+
title?: string | undefined;
|
3253
|
+
}>;
|
3254
|
+
}, "strip", z.ZodTypeAny, {
|
3255
|
+
value: {
|
3256
|
+
type: "source";
|
3257
|
+
id: string;
|
3258
|
+
sourceType: "url";
|
3259
|
+
url: string;
|
3260
|
+
providerMetadata?: any;
|
3261
|
+
title?: string | undefined;
|
3262
|
+
};
|
3263
|
+
type: "source";
|
3264
|
+
}, {
|
3265
|
+
value: {
|
3266
|
+
type: "source";
|
3267
|
+
id: string;
|
3268
|
+
sourceType: "url";
|
3269
|
+
url: string;
|
3270
|
+
providerMetadata?: any;
|
3271
|
+
title?: string | undefined;
|
3272
|
+
};
|
3273
|
+
type: "source";
|
3274
|
+
}>, z.ZodObject<{
|
3275
|
+
type: z.ZodLiteral<"file">;
|
3276
|
+
value: z.ZodObject<{
|
3277
|
+
url: z.ZodString;
|
3278
|
+
mediaType: z.ZodString;
|
3279
|
+
}, "strip", z.ZodTypeAny, {
|
3280
|
+
mediaType: string;
|
3281
|
+
url: string;
|
3282
|
+
}, {
|
3283
|
+
mediaType: string;
|
3284
|
+
url: string;
|
3285
|
+
}>;
|
3286
|
+
}, "strip", z.ZodTypeAny, {
|
3287
|
+
value: {
|
3288
|
+
mediaType: string;
|
3289
|
+
url: string;
|
3290
|
+
};
|
3291
|
+
type: "file";
|
3292
|
+
}, {
|
3293
|
+
value: {
|
3294
|
+
mediaType: string;
|
3295
|
+
url: string;
|
3296
|
+
};
|
3297
|
+
type: "file";
|
3298
|
+
}>, z.ZodObject<{
|
3299
|
+
type: z.ZodLiteral<"reasoning-part-finish">;
|
3300
|
+
value: z.ZodNull;
|
3301
|
+
}, "strip", z.ZodTypeAny, {
|
3302
|
+
value: null;
|
3303
|
+
type: "reasoning-part-finish";
|
3304
|
+
}, {
|
3305
|
+
value: null;
|
3306
|
+
type: "reasoning-part-finish";
|
3307
|
+
}>]>;
|
3308
|
+
type DataStreamPart = z.infer<typeof dataStreamPartSchema>;
|
3149
3309
|
|
3150
3310
|
type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
|
3151
3311
|
|
3152
3312
|
type DataStreamOptions = {
|
3313
|
+
/**
|
3314
|
+
* Process an error, e.g. to log it. Default to `() => 'An error occurred.'`.
|
3315
|
+
*
|
3316
|
+
* @return error message to include in the data stream.
|
3317
|
+
*/
|
3318
|
+
onError?: (error: unknown) => string;
|
3153
3319
|
/**
|
3154
3320
|
* Send usage parts to the client.
|
3155
3321
|
* Default to true.
|
@@ -3311,45 +3477,31 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3311
3477
|
/**
|
3312
3478
|
Converts the result to a data stream.
|
3313
3479
|
|
3314
|
-
@param
|
3315
|
-
@param
|
3316
|
-
@param
|
3317
|
-
@param
|
3480
|
+
@param options.getErrorMessage an optional function that converts an error to an error message.
|
3481
|
+
@param options.sendUsage whether to send the usage information to the client. Defaults to true.
|
3482
|
+
@param options.sendReasoning whether to send the reasoning information to the client. Defaults to false.
|
3483
|
+
@param options.sendSources whether to send the sources information to the client. Defaults to false.
|
3484
|
+
@param options.experimental_sendFinish whether to send the finish information to the client. Defaults to true.
|
3485
|
+
@param options.experimental_sendStart whether to send the start information to the client. Defaults to true.
|
3486
|
+
|
3318
3487
|
@return A data stream.
|
3319
3488
|
*/
|
3320
|
-
toDataStream(options?:
|
3321
|
-
data?: StreamData;
|
3322
|
-
getErrorMessage?: (error: unknown) => string;
|
3323
|
-
} & DataStreamOptions): ReadableStream<Uint8Array>;
|
3324
|
-
/**
|
3325
|
-
* Merges the result as a data stream into another data stream.
|
3326
|
-
*
|
3327
|
-
* @param dataStream A data stream writer.
|
3328
|
-
* @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
3329
|
-
* @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
3330
|
-
*/
|
3331
|
-
mergeIntoDataStream(dataStream: DataStreamWriter, options?: DataStreamOptions): void;
|
3489
|
+
toDataStream(options?: DataStreamOptions): ReadableStream<DataStreamPart>;
|
3332
3490
|
/**
|
3333
3491
|
Writes data stream output to a Node.js response-like object.
|
3334
|
-
|
3335
3492
|
@param response A Node.js response-like object (ServerResponse).
|
3336
3493
|
@param options.status The status code.
|
3337
3494
|
@param options.statusText The status text.
|
3338
3495
|
@param options.headers The headers.
|
3339
|
-
@param options.data The stream data.
|
3340
3496
|
@param options.getErrorMessage An optional function that converts an error to an error message.
|
3341
3497
|
@param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
3342
3498
|
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
3343
3499
|
*/
|
3344
|
-
pipeDataStreamToResponse(response: ServerResponse, options?: ResponseInit &
|
3345
|
-
data?: StreamData;
|
3346
|
-
getErrorMessage?: (error: unknown) => string;
|
3347
|
-
} & DataStreamOptions): void;
|
3500
|
+
pipeDataStreamToResponse(response: ServerResponse, options?: ResponseInit & DataStreamOptions): void;
|
3348
3501
|
/**
|
3349
3502
|
Writes text delta output to a Node.js response-like object.
|
3350
3503
|
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
3351
3504
|
writes each text delta as a separate chunk.
|
3352
|
-
|
3353
3505
|
@param response A Node.js response-like object (ServerResponse).
|
3354
3506
|
@param init Optional headers, status code, and status text.
|
3355
3507
|
*/
|
@@ -3357,7 +3509,6 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3357
3509
|
/**
|
3358
3510
|
Converts the result to a streamed response object with a stream data part stream.
|
3359
3511
|
It can be used with the `useChat` and `useCompletion` hooks.
|
3360
|
-
|
3361
3512
|
@param options.status The status code.
|
3362
3513
|
@param options.statusText The status text.
|
3363
3514
|
@param options.headers The headers.
|
@@ -3365,18 +3516,13 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3365
3516
|
@param options.getErrorMessage An optional function that converts an error to an error message.
|
3366
3517
|
@param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
3367
3518
|
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
3368
|
-
|
3369
3519
|
@return A response object.
|
3370
3520
|
*/
|
3371
|
-
toDataStreamResponse(options?: ResponseInit &
|
3372
|
-
data?: StreamData;
|
3373
|
-
getErrorMessage?: (error: unknown) => string;
|
3374
|
-
} & DataStreamOptions): Response;
|
3521
|
+
toDataStreamResponse(options?: ResponseInit & DataStreamOptions): Response;
|
3375
3522
|
/**
|
3376
3523
|
Creates a simple text stream response.
|
3377
3524
|
Each text delta is encoded as UTF-8 and sent as a separate chunk.
|
3378
3525
|
Non-text-delta events are ignored.
|
3379
|
-
|
3380
3526
|
@param init Optional headers, status code, and status text.
|
3381
3527
|
*/
|
3382
3528
|
toTextStreamResponse(init?: ResponseInit): Response;
|
@@ -3584,7 +3730,7 @@ By default, it's set to 1, which means that only a single LLM call is made.
|
|
3584
3730
|
/**
|
3585
3731
|
Generate a unique ID for each message.
|
3586
3732
|
*/
|
3587
|
-
experimental_generateMessageId?:
|
3733
|
+
experimental_generateMessageId?: IdGenerator;
|
3588
3734
|
/**
|
3589
3735
|
When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
|
3590
3736
|
|
@@ -3655,7 +3801,7 @@ Internal. For test use only. May change without notice.
|
|
3655
3801
|
*/
|
3656
3802
|
_internal?: {
|
3657
3803
|
now?: () => number;
|
3658
|
-
generateId?:
|
3804
|
+
generateId?: IdGenerator;
|
3659
3805
|
currentDate?: () => Date;
|
3660
3806
|
};
|
3661
3807
|
}): StreamTextResult<TOOLS, PARTIAL_OUTPUT>;
|
@@ -4436,6 +4582,8 @@ declare const experimental_createProviderRegistry: typeof createProviderRegistry
|
|
4436
4582
|
|
4437
4583
|
declare function getToolInvocations(message: UIMessage): ToolInvocation[];
|
4438
4584
|
|
4585
|
+
declare function getUIText(parts: UIMessagePart[]): string;
|
4586
|
+
|
4439
4587
|
/**
|
4440
4588
|
* Calculates the cosine similarity between two vectors. This is a useful metric for
|
4441
4589
|
* comparing the similarity of two vectors such as embeddings.
|
@@ -4468,6 +4616,95 @@ declare function simulateReadableStream<T>({ chunks, initialDelayInMs, chunkDela
|
|
4468
4616
|
};
|
4469
4617
|
}): ReadableStream<T>;
|
4470
4618
|
|
4619
|
+
interface DataStreamWriter {
|
4620
|
+
/**
|
4621
|
+
* Appends a data stream part to the stream.
|
4622
|
+
*/
|
4623
|
+
write(part: DataStreamPart): void;
|
4624
|
+
/**
|
4625
|
+
* Merges the contents of another stream to this stream.
|
4626
|
+
*/
|
4627
|
+
merge(stream: ReadableStream<DataStreamPart>): void;
|
4628
|
+
/**
|
4629
|
+
* Error handler that is used by the data stream writer.
|
4630
|
+
* This is intended for forwarding when merging streams
|
4631
|
+
* to prevent duplicated error masking.
|
4632
|
+
*/
|
4633
|
+
onError: ((error: unknown) => string) | undefined;
|
4634
|
+
}
|
4635
|
+
|
4636
|
+
declare function createDataStream({ execute, onError, }: {
|
4637
|
+
execute: (writer: DataStreamWriter) => Promise<void> | void;
|
4638
|
+
onError?: (error: unknown) => string;
|
4639
|
+
}): ReadableStream<DataStreamPart>;
|
4640
|
+
|
4641
|
+
declare function createDataStreamResponse({ status, statusText, headers, dataStream, }: ResponseInit & {
|
4642
|
+
dataStream: ReadableStream<DataStreamPart>;
|
4643
|
+
}): Response;
|
4644
|
+
|
4645
|
+
declare function pipeDataStreamToResponse({ response, status, statusText, headers, dataStream, }: {
|
4646
|
+
response: ServerResponse;
|
4647
|
+
dataStream: ReadableStream<DataStreamPart>;
|
4648
|
+
} & ResponseInit): void;
|
4649
|
+
|
4650
|
+
declare function processDataStream({ stream, onTextPart, onReasoningPart, onReasoningPartFinish, onSourcePart, onFilePart, onDataPart, onErrorPart, onToolCallStreamingStartPart, onToolCallDeltaPart, onToolCallPart, onToolResultPart, onMessageAnnotationsPart, onFinishMessagePart, onFinishStepPart, onStartStepPart, }: {
|
4651
|
+
stream: ReadableStream<Uint8Array>;
|
4652
|
+
onTextPart?: (streamPart: (DataStreamPart & {
|
4653
|
+
type: 'text';
|
4654
|
+
})['value']) => Promise<void> | void;
|
4655
|
+
onReasoningPart?: (streamPart: (DataStreamPart & {
|
4656
|
+
type: 'reasoning';
|
4657
|
+
})['value']) => Promise<void> | void;
|
4658
|
+
onReasoningPartFinish?: (streamPart: (DataStreamPart & {
|
4659
|
+
type: 'reasoning-part-finish';
|
4660
|
+
})['value']) => Promise<void> | void;
|
4661
|
+
onFilePart?: (streamPart: (DataStreamPart & {
|
4662
|
+
type: 'file';
|
4663
|
+
})['value']) => Promise<void> | void;
|
4664
|
+
onSourcePart?: (streamPart: (DataStreamPart & {
|
4665
|
+
type: 'source';
|
4666
|
+
})['value']) => Promise<void> | void;
|
4667
|
+
onDataPart?: (streamPart: (DataStreamPart & {
|
4668
|
+
type: 'data';
|
4669
|
+
})['value']) => Promise<void> | void;
|
4670
|
+
onErrorPart?: (streamPart: (DataStreamPart & {
|
4671
|
+
type: 'error';
|
4672
|
+
})['value']) => Promise<void> | void;
|
4673
|
+
onToolCallStreamingStartPart?: (streamPart: (DataStreamPart & {
|
4674
|
+
type: 'tool-call-streaming-start';
|
4675
|
+
})['value']) => Promise<void> | void;
|
4676
|
+
onToolCallDeltaPart?: (streamPart: (DataStreamPart & {
|
4677
|
+
type: 'tool-call-delta';
|
4678
|
+
})['value']) => Promise<void> | void;
|
4679
|
+
onToolCallPart?: (streamPart: ToolCall<string, any>) => Promise<void> | void;
|
4680
|
+
onToolResultPart?: (streamPart: ToolResult<string, any, any>) => Promise<void> | void;
|
4681
|
+
onMessageAnnotationsPart?: (streamPart: (DataStreamPart & {
|
4682
|
+
type: 'message-annotations';
|
4683
|
+
})['value']) => Promise<void> | void;
|
4684
|
+
onFinishMessagePart?: (streamPart: (DataStreamPart & {
|
4685
|
+
type: 'finish-message';
|
4686
|
+
})['value']) => Promise<void> | void;
|
4687
|
+
onFinishStepPart?: (streamPart: (DataStreamPart & {
|
4688
|
+
type: 'finish-step';
|
4689
|
+
})['value']) => Promise<void> | void;
|
4690
|
+
onStartStepPart?: (streamPart: (DataStreamPart & {
|
4691
|
+
type: 'start-step';
|
4692
|
+
})['value']) => Promise<void> | void;
|
4693
|
+
}): Promise<void>;
|
4694
|
+
|
4695
|
+
declare class DataStreamToSSETransformStream extends TransformStream<DataStreamPart, string> {
|
4696
|
+
constructor();
|
4697
|
+
}
|
4698
|
+
|
4699
|
+
declare function createTextStreamResponse({ status, statusText, headers, textStream, }: ResponseInit & {
|
4700
|
+
textStream: ReadableStream<string>;
|
4701
|
+
}): Response;
|
4702
|
+
|
4703
|
+
declare function pipeTextStreamToResponse({ response, status, statusText, headers, textStream, }: {
|
4704
|
+
response: ServerResponse;
|
4705
|
+
textStream: ReadableStream<string>;
|
4706
|
+
} & ResponseInit): void;
|
4707
|
+
|
4471
4708
|
declare const symbol$c: unique symbol;
|
4472
4709
|
declare class InvalidArgumentError extends AISDKError {
|
4473
4710
|
private readonly [symbol$c];
|
@@ -4718,4 +4955,4 @@ declare class RetryError extends AISDKError {
|
|
4718
4955
|
static isInstance(error: unknown): error is RetryError;
|
4719
4956
|
}
|
4720
4957
|
|
4721
|
-
export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequest, ChatRequestOptions, ChunkDetector, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DataStreamOptions, DataStreamPart,
|
4958
|
+
export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequest, ChatRequestOptions, ChunkDetector, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DataStreamOptions, DataStreamPart, DataStreamToSSETransformStream, DataStreamWriter, DeepPartial, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, ModelMessage, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RequestOptions, RetryError, SourceUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIMessage, UIMessagePart, UseChatOptions, UseCompletionOptions, UserContent, UserModelMessage, appendClientMessage, appendResponseMessages, assistantModelMessageSchema, callChatApi, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDataStream, createDataStreamResponse, createProviderRegistry, createTextStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractMaxToolInvocationStep, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolInvocations, getUIText, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, modelMessageSchema, parsePartialJson, pipeDataStreamToResponse, pipeTextStreamToResponse, processDataStream, processTextStream, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, updateToolCallResult, userModelMessageSchema, wrapLanguageModel };
|