ai 5.0.0-beta.11 → 5.0.0-beta.12
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 +8 -0
- package/dist/index.d.mts +1698 -1669
- package/dist/index.d.ts +1698 -1669
- package/dist/index.js +3928 -3917
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3941 -3930
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +17 -17
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +17 -17
- package/dist/internal/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.js +3 -3
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs +3 -3
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/dist/test/index.js +4 -4
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +4 -4
- package/dist/test/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ModelMessage, Tool, InferToolInput, InferToolOutput, AssistantModelMessage, ToolModelMessage, ReasoningPart, Schema, SystemModelMessage, UserModelMessage, ProviderOptions, IdGenerator,
|
1
|
+
import { ModelMessage, Tool, InferToolInput, InferToolOutput, AssistantModelMessage, ToolModelMessage, ReasoningPart, Schema, SystemModelMessage, UserModelMessage, ProviderOptions, IdGenerator, InferSchema, FlexibleSchema, DataContent, Validator, StandardSchemaV1, ToolCall, Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
2
2
|
export { AssistantContent, AssistantModelMessage, DataContent, FilePart, IdGenerator, ImagePart, InferToolInput, InferToolOutput, ModelMessage, Schema, SystemModelMessage, TextPart, Tool, ToolCallOptions, ToolCallPart, ToolContent, ToolExecuteFunction, ToolModelMessage, ToolResultPart, UserContent, UserModelMessage, asSchema, createIdGenerator, generateId, jsonSchema, tool } from '@ai-sdk/provider-utils';
|
3
3
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
4
4
|
import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SpeechModelV2, SpeechModelV2CallWarning, TranscriptionModelV2, TranscriptionModelV2CallWarning, LanguageModelV2Usage, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError, JSONObject } from '@ai-sdk/provider';
|
@@ -717,12 +717,14 @@ type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Too
|
|
717
717
|
steps: Array<StepResult<NoInfer<TOOLS>>>;
|
718
718
|
stepNumber: number;
|
719
719
|
model: LanguageModel;
|
720
|
+
messages: Array<ModelMessage>;
|
720
721
|
}) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
|
721
722
|
type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
722
723
|
model?: LanguageModel;
|
723
724
|
toolChoice?: ToolChoice<NoInfer<TOOLS>>;
|
724
725
|
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
725
726
|
system?: string;
|
727
|
+
messages?: Array<ModelMessage>;
|
726
728
|
} | undefined;
|
727
729
|
|
728
730
|
type StopCondition<TOOLS extends ToolSet> = (options: {
|
@@ -948,6 +950,236 @@ A function that attempts to repair a tool call that failed to parse.
|
|
948
950
|
};
|
949
951
|
}): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
950
952
|
|
953
|
+
/**
|
954
|
+
* Detects the first chunk in a buffer.
|
955
|
+
*
|
956
|
+
* @param buffer - The buffer to detect the first chunk in.
|
957
|
+
*
|
958
|
+
* @returns The first detected chunk, or `undefined` if no chunk was detected.
|
959
|
+
*/
|
960
|
+
type ChunkDetector = (buffer: string) => string | undefined | null;
|
961
|
+
/**
|
962
|
+
* Smooths text streaming output.
|
963
|
+
*
|
964
|
+
* @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
|
965
|
+
* @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, or provide a custom RegExp pattern for custom chunking.
|
966
|
+
*
|
967
|
+
* @returns A transform stream that smooths text streaming output.
|
968
|
+
*/
|
969
|
+
declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _internal: { delay }, }?: {
|
970
|
+
delayInMs?: number | null;
|
971
|
+
chunking?: 'word' | 'line' | RegExp | ChunkDetector;
|
972
|
+
/**
|
973
|
+
* Internal. For test use only. May change without notice.
|
974
|
+
*/
|
975
|
+
_internal?: {
|
976
|
+
delay?: (delayInMs: number | null) => Promise<void>;
|
977
|
+
};
|
978
|
+
}): (options: {
|
979
|
+
tools: TOOLS;
|
980
|
+
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
981
|
+
|
982
|
+
/**
|
983
|
+
A transformation that is applied to the stream.
|
984
|
+
|
985
|
+
@param stopStream - A function that stops the source stream.
|
986
|
+
@param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
987
|
+
*/
|
988
|
+
type StreamTextTransform<TOOLS extends ToolSet> = (options: {
|
989
|
+
tools: TOOLS;
|
990
|
+
stopStream: () => void;
|
991
|
+
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
992
|
+
/**
|
993
|
+
Callback that is set using the `onError` option.
|
994
|
+
|
995
|
+
@param event - The event that is passed to the callback.
|
996
|
+
*/
|
997
|
+
type StreamTextOnErrorCallback = (event: {
|
998
|
+
error: unknown;
|
999
|
+
}) => Promise<void> | void;
|
1000
|
+
/**
|
1001
|
+
Callback that is set using the `onStepFinish` option.
|
1002
|
+
|
1003
|
+
@param stepResult - The result of the step.
|
1004
|
+
*/
|
1005
|
+
type StreamTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
|
1006
|
+
/**
|
1007
|
+
Callback that is set using the `onChunk` option.
|
1008
|
+
|
1009
|
+
@param event - The event that is passed to the callback.
|
1010
|
+
*/
|
1011
|
+
type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
|
1012
|
+
chunk: Extract<TextStreamPart<TOOLS>, {
|
1013
|
+
type: 'text' | 'reasoning' | 'source' | 'tool-call' | 'tool-input-start' | 'tool-input-delta' | 'tool-result' | 'raw';
|
1014
|
+
}>;
|
1015
|
+
}) => Promise<void> | void;
|
1016
|
+
/**
|
1017
|
+
Callback that is set using the `onFinish` option.
|
1018
|
+
|
1019
|
+
@param event - The event that is passed to the callback.
|
1020
|
+
*/
|
1021
|
+
type StreamTextOnFinishCallback<TOOLS extends ToolSet> = (event: StepResult<TOOLS> & {
|
1022
|
+
/**
|
1023
|
+
Details for all steps.
|
1024
|
+
*/
|
1025
|
+
readonly steps: StepResult<TOOLS>[];
|
1026
|
+
/**
|
1027
|
+
Total usage for all steps. This is the sum of the usage of all steps.
|
1028
|
+
*/
|
1029
|
+
readonly totalUsage: LanguageModelUsage;
|
1030
|
+
}) => Promise<void> | void;
|
1031
|
+
/**
|
1032
|
+
Generate a text and call tools for a given prompt using a language model.
|
1033
|
+
|
1034
|
+
This function streams the output. If you do not want to stream the output, use `generateText` instead.
|
1035
|
+
|
1036
|
+
@param model - The language model to use.
|
1037
|
+
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
1038
|
+
|
1039
|
+
@param system - A system message that will be part of the prompt.
|
1040
|
+
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
1041
|
+
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
1042
|
+
|
1043
|
+
@param maxOutputTokens - Maximum number of tokens to generate.
|
1044
|
+
@param temperature - Temperature setting.
|
1045
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
1046
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
1047
|
+
@param topP - Nucleus sampling.
|
1048
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
1049
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
1050
|
+
@param topK - Only sample from the top K options for each subsequent token.
|
1051
|
+
Used to remove "long tail" low probability responses.
|
1052
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
1053
|
+
@param presencePenalty - Presence penalty setting.
|
1054
|
+
It affects the likelihood of the model to repeat information that is already in the prompt.
|
1055
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
1056
|
+
@param frequencyPenalty - Frequency penalty setting.
|
1057
|
+
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
1058
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
1059
|
+
@param stopSequences - Stop sequences.
|
1060
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
1061
|
+
@param seed - The seed (integer) to use for random sampling.
|
1062
|
+
If set and supported by the model, calls will generate deterministic results.
|
1063
|
+
|
1064
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
1065
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
1066
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
1067
|
+
|
1068
|
+
@param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
1069
|
+
|
1070
|
+
@param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
|
1071
|
+
@param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
|
1072
|
+
@param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
1073
|
+
@param onFinish - Callback that is called when the LLM response and all request tool executions
|
1074
|
+
(for tools that have an `execute` function) are finished.
|
1075
|
+
|
1076
|
+
@return
|
1077
|
+
A result object for accessing different stream types and additional information.
|
1078
|
+
*/
|
1079
|
+
declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, includeRawChunks, onChunk, onError, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
|
1080
|
+
/**
|
1081
|
+
The language model to use.
|
1082
|
+
*/
|
1083
|
+
model: LanguageModel;
|
1084
|
+
/**
|
1085
|
+
The tools that the model can call. The model needs to support calling tools.
|
1086
|
+
*/
|
1087
|
+
tools?: TOOLS;
|
1088
|
+
/**
|
1089
|
+
The tool choice strategy. Default: 'auto'.
|
1090
|
+
*/
|
1091
|
+
toolChoice?: ToolChoice<TOOLS>;
|
1092
|
+
/**
|
1093
|
+
Condition for stopping the generation when there are tool results in the last step.
|
1094
|
+
When the condition is an array, any of the conditions can be met to stop the generation.
|
1095
|
+
|
1096
|
+
@default stepCountIs(1)
|
1097
|
+
*/
|
1098
|
+
stopWhen?: StopCondition<NoInfer<TOOLS>> | Array<StopCondition<NoInfer<TOOLS>>>;
|
1099
|
+
/**
|
1100
|
+
Optional telemetry configuration (experimental).
|
1101
|
+
*/
|
1102
|
+
experimental_telemetry?: TelemetrySettings;
|
1103
|
+
/**
|
1104
|
+
Additional provider-specific options. They are passed through
|
1105
|
+
to the provider from the AI SDK and enable provider-specific
|
1106
|
+
functionality that can be fully encapsulated in the provider.
|
1107
|
+
*/
|
1108
|
+
providerOptions?: ProviderOptions;
|
1109
|
+
/**
|
1110
|
+
* @deprecated Use `activeTools` instead.
|
1111
|
+
*/
|
1112
|
+
experimental_activeTools?: Array<keyof NoInfer<TOOLS>>;
|
1113
|
+
/**
|
1114
|
+
Limits the tools that are available for the model to call without
|
1115
|
+
changing the tool call and result types in the result.
|
1116
|
+
*/
|
1117
|
+
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
1118
|
+
/**
|
1119
|
+
Optional specification for parsing structured outputs from the LLM response.
|
1120
|
+
*/
|
1121
|
+
experimental_output?: Output<OUTPUT, PARTIAL_OUTPUT>;
|
1122
|
+
/**
|
1123
|
+
Optional function that you can use to provide different settings for a step.
|
1124
|
+
|
1125
|
+
@param options - The options for the step.
|
1126
|
+
@param options.steps - The steps that have been executed so far.
|
1127
|
+
@param options.stepNumber - The number of the step that is being executed.
|
1128
|
+
@param options.model - The model that is being used.
|
1129
|
+
|
1130
|
+
@returns An object that contains the settings for the step.
|
1131
|
+
If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
1132
|
+
*/
|
1133
|
+
prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
|
1134
|
+
/**
|
1135
|
+
A function that attempts to repair a tool call that failed to parse.
|
1136
|
+
*/
|
1137
|
+
experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
|
1138
|
+
/**
|
1139
|
+
Optional stream transformations.
|
1140
|
+
They are applied in the order they are provided.
|
1141
|
+
The stream transformations must maintain the stream structure for streamText to work correctly.
|
1142
|
+
*/
|
1143
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
1144
|
+
/**
|
1145
|
+
Whether to include raw chunks from the provider in the stream.
|
1146
|
+
When enabled, you will receive raw chunks with type 'raw' that contain the unprocessed data from the provider.
|
1147
|
+
This allows access to cutting-edge provider features not yet wrapped by the AI SDK.
|
1148
|
+
Defaults to false.
|
1149
|
+
*/
|
1150
|
+
includeRawChunks?: boolean;
|
1151
|
+
/**
|
1152
|
+
Callback that is called for each chunk of the stream.
|
1153
|
+
The stream processing will pause until the callback promise is resolved.
|
1154
|
+
*/
|
1155
|
+
onChunk?: StreamTextOnChunkCallback<TOOLS>;
|
1156
|
+
/**
|
1157
|
+
Callback that is invoked when an error occurs during streaming.
|
1158
|
+
You can use it to log errors.
|
1159
|
+
The stream processing will pause until the callback promise is resolved.
|
1160
|
+
*/
|
1161
|
+
onError?: StreamTextOnErrorCallback;
|
1162
|
+
/**
|
1163
|
+
Callback that is called when the LLM response and all request tool executions
|
1164
|
+
(for tools that have an `execute` function) are finished.
|
1165
|
+
|
1166
|
+
The usage is the combined usage of all steps.
|
1167
|
+
*/
|
1168
|
+
onFinish?: StreamTextOnFinishCallback<TOOLS>;
|
1169
|
+
/**
|
1170
|
+
Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
1171
|
+
*/
|
1172
|
+
onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
|
1173
|
+
/**
|
1174
|
+
Internal. For test use only. May change without notice.
|
1175
|
+
*/
|
1176
|
+
_internal?: {
|
1177
|
+
now?: () => number;
|
1178
|
+
generateId?: IdGenerator;
|
1179
|
+
currentDate?: () => Date;
|
1180
|
+
};
|
1181
|
+
}): StreamTextResult<TOOLS, PARTIAL_OUTPUT>;
|
1182
|
+
|
951
1183
|
/**
|
952
1184
|
The data types that can be used in the UI message for the UI message data parts.
|
953
1185
|
*/
|
@@ -956,10 +1188,19 @@ type UITool = {
|
|
956
1188
|
input: unknown;
|
957
1189
|
output: unknown | undefined;
|
958
1190
|
};
|
1191
|
+
/**
|
1192
|
+
* Infer the input and output types of a tool so it can be used as a UI tool.
|
1193
|
+
*/
|
959
1194
|
type InferUITool<TOOL extends Tool> = {
|
960
1195
|
input: InferToolInput<TOOL>;
|
961
1196
|
output: InferToolOutput<TOOL>;
|
962
1197
|
};
|
1198
|
+
/**
|
1199
|
+
* Infer the input and output types of a tool set so it can be used as a UI tool set.
|
1200
|
+
*/
|
1201
|
+
type InferUITools<TOOLS extends ToolSet> = {
|
1202
|
+
[NAME in keyof TOOLS & string]: InferUITool<TOOLS[NAME]>;
|
1203
|
+
};
|
963
1204
|
type UITools = Record<string, UITool>;
|
964
1205
|
/**
|
965
1206
|
AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
@@ -1625,26 +1866,196 @@ declare class Agent<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = neve
|
|
1625
1866
|
}): StreamTextResult<TOOLS, OUTPUT_PARTIAL>;
|
1626
1867
|
}
|
1627
1868
|
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1869
|
+
/**
|
1870
|
+
The result of an `embed` call.
|
1871
|
+
It contains the embedding, the value, and additional information.
|
1872
|
+
*/
|
1873
|
+
interface EmbedResult<VALUE> {
|
1874
|
+
/**
|
1875
|
+
The value that was embedded.
|
1876
|
+
*/
|
1877
|
+
readonly value: VALUE;
|
1878
|
+
/**
|
1879
|
+
The embedding of the value.
|
1880
|
+
*/
|
1881
|
+
readonly embedding: Embedding;
|
1882
|
+
/**
|
1883
|
+
The embedding token usage.
|
1884
|
+
*/
|
1885
|
+
readonly usage: EmbeddingModelUsage;
|
1886
|
+
/**
|
1887
|
+
Optional response data.
|
1888
|
+
*/
|
1889
|
+
readonly response?: {
|
1890
|
+
/**
|
1891
|
+
Response headers.
|
1892
|
+
*/
|
1893
|
+
headers?: Record<string, string>;
|
1894
|
+
/**
|
1895
|
+
The response body.
|
1896
|
+
*/
|
1897
|
+
body?: unknown;
|
1898
|
+
};
|
1899
|
+
}
|
1900
|
+
|
1901
|
+
/**
|
1902
|
+
Embed a value using an embedding model. The type of the value is defined by the embedding model.
|
1903
|
+
|
1904
|
+
@param model - The embedding model to use.
|
1905
|
+
@param value - The value that should be embedded.
|
1906
|
+
|
1907
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
1908
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
1909
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
1910
|
+
|
1911
|
+
@returns A result object that contains the embedding, the value, and additional information.
|
1912
|
+
*/
|
1913
|
+
declare function embed<VALUE>({ model, value, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
|
1914
|
+
/**
|
1915
|
+
The embedding model to use.
|
1916
|
+
*/
|
1917
|
+
model: EmbeddingModel<VALUE>;
|
1918
|
+
/**
|
1919
|
+
The value that should be embedded.
|
1920
|
+
*/
|
1921
|
+
value: VALUE;
|
1922
|
+
/**
|
1923
|
+
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
1924
|
+
|
1925
|
+
@default 2
|
1926
|
+
*/
|
1927
|
+
maxRetries?: number;
|
1928
|
+
/**
|
1929
|
+
Abort signal.
|
1930
|
+
*/
|
1931
|
+
abortSignal?: AbortSignal;
|
1932
|
+
/**
|
1933
|
+
Additional headers to include in the request.
|
1934
|
+
Only applicable for HTTP-based providers.
|
1935
|
+
*/
|
1936
|
+
headers?: Record<string, string>;
|
1937
|
+
/**
|
1938
|
+
Additional provider-specific options. They are passed through
|
1939
|
+
to the provider from the AI SDK and enable provider-specific
|
1940
|
+
functionality that can be fully encapsulated in the provider.
|
1941
|
+
*/
|
1942
|
+
providerOptions?: ProviderOptions;
|
1943
|
+
/**
|
1944
|
+
* Optional telemetry configuration (experimental).
|
1945
|
+
*/
|
1946
|
+
experimental_telemetry?: TelemetrySettings;
|
1947
|
+
}): Promise<EmbedResult<VALUE>>;
|
1948
|
+
|
1949
|
+
/**
|
1950
|
+
The result of a `embedMany` call.
|
1951
|
+
It contains the embeddings, the values, and additional information.
|
1952
|
+
*/
|
1953
|
+
interface EmbedManyResult<VALUE> {
|
1954
|
+
/**
|
1955
|
+
The values that were embedded.
|
1956
|
+
*/
|
1957
|
+
readonly values: Array<VALUE>;
|
1958
|
+
/**
|
1959
|
+
The embeddings. They are in the same order as the values.
|
1960
|
+
*/
|
1961
|
+
readonly embeddings: Array<Embedding>;
|
1962
|
+
/**
|
1963
|
+
The embedding token usage.
|
1964
|
+
*/
|
1965
|
+
readonly usage: EmbeddingModelUsage;
|
1966
|
+
/**
|
1967
|
+
Optional raw response data.
|
1968
|
+
*/
|
1969
|
+
readonly responses?: Array<{
|
1970
|
+
/**
|
1971
|
+
Response headers.
|
1972
|
+
*/
|
1973
|
+
headers?: Record<string, string>;
|
1974
|
+
/**
|
1975
|
+
The response body.
|
1976
|
+
*/
|
1977
|
+
body?: unknown;
|
1978
|
+
} | undefined>;
|
1979
|
+
}
|
1980
|
+
|
1981
|
+
/**
|
1982
|
+
Embed several values using an embedding model. The type of the value is defined
|
1983
|
+
by the embedding model.
|
1984
|
+
|
1985
|
+
`embedMany` automatically splits large requests into smaller chunks if the model
|
1986
|
+
has a limit on how many embeddings can be generated in a single call.
|
1987
|
+
|
1988
|
+
@param model - The embedding model to use.
|
1989
|
+
@param values - The values that should be embedded.
|
1990
|
+
|
1991
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
1992
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
1993
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
1994
|
+
|
1995
|
+
@returns A result object that contains the embeddings, the value, and additional information.
|
1996
|
+
*/
|
1997
|
+
declare function embedMany<VALUE>({ model, values, maxParallelCalls, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
|
1998
|
+
/**
|
1999
|
+
The embedding model to use.
|
2000
|
+
*/
|
2001
|
+
model: EmbeddingModel<VALUE>;
|
2002
|
+
/**
|
2003
|
+
The values that should be embedded.
|
2004
|
+
*/
|
2005
|
+
values: Array<VALUE>;
|
2006
|
+
/**
|
2007
|
+
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
2008
|
+
|
2009
|
+
@default 2
|
2010
|
+
*/
|
2011
|
+
maxRetries?: number;
|
2012
|
+
/**
|
2013
|
+
Abort signal.
|
2014
|
+
*/
|
2015
|
+
abortSignal?: AbortSignal;
|
2016
|
+
/**
|
2017
|
+
Additional headers to include in the request.
|
2018
|
+
Only applicable for HTTP-based providers.
|
2019
|
+
*/
|
2020
|
+
headers?: Record<string, string>;
|
2021
|
+
/**
|
2022
|
+
* Optional telemetry configuration (experimental).
|
2023
|
+
*/
|
2024
|
+
experimental_telemetry?: TelemetrySettings;
|
2025
|
+
/**
|
2026
|
+
Additional provider-specific options. They are passed through
|
2027
|
+
to the provider from the AI SDK and enable provider-specific
|
2028
|
+
functionality that can be fully encapsulated in the provider.
|
2029
|
+
*/
|
2030
|
+
providerOptions?: ProviderOptions;
|
2031
|
+
/**
|
2032
|
+
* Maximum number of concurrent requests.
|
2033
|
+
*
|
2034
|
+
* @default Infinity
|
2035
|
+
*/
|
2036
|
+
maxParallelCalls?: number;
|
2037
|
+
}): Promise<EmbedManyResult<VALUE>>;
|
2038
|
+
|
2039
|
+
declare const symbol$c: unique symbol;
|
2040
|
+
declare class InvalidArgumentError extends AISDKError {
|
2041
|
+
private readonly [symbol$c];
|
2042
|
+
readonly parameter: string;
|
2043
|
+
readonly value: unknown;
|
2044
|
+
constructor({ parameter, value, message, }: {
|
2045
|
+
parameter: string;
|
2046
|
+
value: unknown;
|
2047
|
+
message: string;
|
2048
|
+
});
|
2049
|
+
static isInstance(error: unknown): error is InvalidArgumentError;
|
2050
|
+
}
|
2051
|
+
|
2052
|
+
type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
|
2053
|
+
type: 'text-start';
|
2054
|
+
providerMetadata?: ProviderMetadata;
|
2055
|
+
id: string;
|
2056
|
+
} | {
|
2057
|
+
type: 'text-delta';
|
2058
|
+
id: string;
|
1648
2059
|
providerMetadata?: ProviderMetadata;
|
1649
2060
|
delta: string;
|
1650
2061
|
} | {
|
@@ -1889,480 +2300,299 @@ declare class RetryError extends AISDKError {
|
|
1889
2300
|
static isInstance(error: unknown): error is RetryError;
|
1890
2301
|
}
|
1891
2302
|
|
1892
|
-
|
1893
|
-
|
1894
|
-
|
1895
|
-
|
1896
|
-
|
1897
|
-
response: ServerResponse;
|
1898
|
-
textStream: ReadableStream<string>;
|
1899
|
-
} & ResponseInit): void;
|
1900
|
-
|
1901
|
-
declare const getOriginalFetch: () => typeof fetch;
|
1902
|
-
declare function callCompletionApi({ api, prompt, credentials, headers, body, streamProtocol, setCompletion, setLoading, setError, setAbortController, onFinish, onError, fetch, }: {
|
1903
|
-
api: string;
|
1904
|
-
prompt: string;
|
1905
|
-
credentials: RequestCredentials | undefined;
|
1906
|
-
headers: HeadersInit | undefined;
|
1907
|
-
body: Record<string, any>;
|
1908
|
-
streamProtocol: 'data' | 'text' | undefined;
|
1909
|
-
setCompletion: (completion: string) => void;
|
1910
|
-
setLoading: (loading: boolean) => void;
|
1911
|
-
setError: (error: Error | undefined) => void;
|
1912
|
-
setAbortController: (abortController: AbortController | null) => void;
|
1913
|
-
onFinish: ((prompt: string, completion: string) => void) | undefined;
|
1914
|
-
onError: ((error: Error) => void) | undefined;
|
1915
|
-
fetch: ReturnType<typeof getOriginalFetch> | undefined;
|
1916
|
-
}): Promise<string | null | undefined>;
|
1917
|
-
|
1918
|
-
interface UIMessageStreamWriter<UI_MESSAGE extends UIMessage = UIMessage> {
|
2303
|
+
/**
|
2304
|
+
The result of a `generateImage` call.
|
2305
|
+
It contains the images and additional information.
|
2306
|
+
*/
|
2307
|
+
interface GenerateImageResult {
|
1919
2308
|
/**
|
1920
|
-
|
2309
|
+
The first image that was generated.
|
1921
2310
|
*/
|
1922
|
-
|
2311
|
+
readonly image: GeneratedFile;
|
1923
2312
|
/**
|
1924
|
-
|
2313
|
+
The images that were generated.
|
2314
|
+
*/
|
2315
|
+
readonly images: Array<GeneratedFile>;
|
2316
|
+
/**
|
2317
|
+
Warnings for the call, e.g. unsupported settings.
|
2318
|
+
*/
|
2319
|
+
readonly warnings: Array<ImageGenerationWarning>;
|
2320
|
+
/**
|
2321
|
+
Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
1925
2322
|
*/
|
1926
|
-
|
2323
|
+
readonly responses: Array<ImageModelResponseMetadata>;
|
1927
2324
|
/**
|
1928
|
-
*
|
1929
|
-
*
|
1930
|
-
* to prevent duplicated error masking.
|
2325
|
+
* Provider-specific metadata. They are passed through from the provider to the AI SDK and enable provider-specific
|
2326
|
+
* results that can be fully encapsulated in the provider.
|
1931
2327
|
*/
|
1932
|
-
|
2328
|
+
readonly providerMetadata: ImageModelProviderMetadata;
|
1933
2329
|
}
|
1934
2330
|
|
1935
|
-
declare function createUIMessageStream<UI_MESSAGE extends UIMessage>({ execute, onError, originalMessages, onFinish, generateId, }: {
|
1936
|
-
execute: (options: {
|
1937
|
-
writer: UIMessageStreamWriter<UI_MESSAGE>;
|
1938
|
-
}) => Promise<void> | void;
|
1939
|
-
onError?: (error: unknown) => string;
|
1940
|
-
/**
|
1941
|
-
* The original messages. If they are provided, persistence mode is assumed,
|
1942
|
-
* and a message ID is provided for the response message.
|
1943
|
-
*/
|
1944
|
-
originalMessages?: UI_MESSAGE[];
|
1945
|
-
onFinish?: (options: {
|
1946
|
-
/**
|
1947
|
-
* The updates list of UI messages.
|
1948
|
-
*/
|
1949
|
-
messages: UI_MESSAGE[];
|
1950
|
-
/**
|
1951
|
-
* Indicates whether the response message is a continuation of the last original message,
|
1952
|
-
* or if a new message was created.
|
1953
|
-
*/
|
1954
|
-
isContinuation: boolean;
|
1955
|
-
/**
|
1956
|
-
* The message that was sent to the client as a response
|
1957
|
-
* (including the original message if it was extended).
|
1958
|
-
*/
|
1959
|
-
responseMessage: UI_MESSAGE;
|
1960
|
-
}) => void;
|
1961
|
-
generateId?: IdGenerator;
|
1962
|
-
}): ReadableStream<InferUIMessageChunk<UI_MESSAGE>>;
|
1963
|
-
|
1964
|
-
declare function createUIMessageStreamResponse({ status, statusText, headers, stream, consumeSseStream, }: UIMessageStreamResponseInit & {
|
1965
|
-
stream: ReadableStream<UIMessageChunk>;
|
1966
|
-
}): Response;
|
1967
|
-
|
1968
|
-
declare class JsonToSseTransformStream extends TransformStream<unknown, string> {
|
1969
|
-
constructor();
|
1970
|
-
}
|
1971
|
-
|
1972
|
-
declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, consumeSseStream, }: {
|
1973
|
-
response: ServerResponse;
|
1974
|
-
stream: ReadableStream<UIMessageChunk>;
|
1975
|
-
} & UIMessageStreamResponseInit): void;
|
1976
|
-
|
1977
2331
|
/**
|
1978
|
-
|
1979
|
-
*
|
1980
|
-
* @param options.message - The last assistant message to use as a starting point when the conversation is resumed. Otherwise undefined.
|
1981
|
-
* @param options.stream - The stream of `UIMessageChunk`s to read.
|
1982
|
-
*
|
1983
|
-
* @returns An `AsyncIterableStream` of `UIMessage`s. Each stream part is a different state of the same message
|
1984
|
-
* as it is being completed.
|
1985
|
-
*/
|
1986
|
-
declare function readUIMessageStream<UI_MESSAGE extends UIMessage>({ message, stream, }: {
|
1987
|
-
message?: UI_MESSAGE;
|
1988
|
-
stream: ReadableStream<UIMessageChunk>;
|
1989
|
-
}): AsyncIterableStream<UI_MESSAGE>;
|
1990
|
-
|
1991
|
-
declare const UI_MESSAGE_STREAM_HEADERS: {
|
1992
|
-
'content-type': string;
|
1993
|
-
'cache-control': string;
|
1994
|
-
connection: string;
|
1995
|
-
'x-vercel-ai-ui-message-stream': string;
|
1996
|
-
'x-accel-buffering': string;
|
1997
|
-
};
|
2332
|
+
Generates images using an image model.
|
1998
2333
|
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
} & ChatRequestOptions) => Promise<ReadableStream<UIMessageChunk> | null>;
|
2011
|
-
}
|
2334
|
+
@param model - The image model to use.
|
2335
|
+
@param prompt - The prompt that should be used to generate the image.
|
2336
|
+
@param n - Number of images to generate. Default: 1.
|
2337
|
+
@param size - Size of the images to generate. Must have the format `{width}x{height}`.
|
2338
|
+
@param aspectRatio - Aspect ratio of the images to generate. Must have the format `{width}:{height}`.
|
2339
|
+
@param seed - Seed for the image generation.
|
2340
|
+
@param providerOptions - Additional provider-specific options that are passed through to the provider
|
2341
|
+
as body parameters.
|
2342
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
2343
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
2344
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
2012
2345
|
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
2016
|
-
};
|
2017
|
-
type UIDataPartSchemas = Record<string, Validator<any> | StandardSchemaV1<any>>;
|
2018
|
-
type UIDataTypesToSchemas<T extends UIDataTypes> = {
|
2019
|
-
[K in keyof T]: Validator<T[K]> | StandardSchemaV1<T[K]>;
|
2020
|
-
};
|
2021
|
-
type InferUIDataParts<T extends UIDataPartSchemas> = {
|
2022
|
-
[K in keyof T]: T[K] extends Validator<infer U> ? U : T[K] extends StandardSchemaV1<infer U> ? U : unknown;
|
2023
|
-
};
|
2024
|
-
type ChatRequestOptions = {
|
2346
|
+
@returns A result object that contains the generated images.
|
2347
|
+
*/
|
2348
|
+
declare function generateImage({ model, prompt, n, maxImagesPerCall, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
|
2025
2349
|
/**
|
2026
|
-
|
2350
|
+
The image model to use.
|
2351
|
+
*/
|
2352
|
+
model: ImageModelV2;
|
2353
|
+
/**
|
2354
|
+
The prompt that should be used to generate the image.
|
2027
2355
|
*/
|
2028
|
-
|
2356
|
+
prompt: string;
|
2029
2357
|
/**
|
2030
|
-
|
2358
|
+
Number of images to generate.
|
2031
2359
|
*/
|
2032
|
-
|
2033
|
-
metadata?: unknown;
|
2034
|
-
};
|
2035
|
-
type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
|
2036
|
-
interface ChatState<UI_MESSAGE extends UIMessage> {
|
2037
|
-
status: ChatStatus;
|
2038
|
-
error: Error | undefined;
|
2039
|
-
messages: UI_MESSAGE[];
|
2040
|
-
pushMessage: (message: UI_MESSAGE) => void;
|
2041
|
-
popMessage: () => void;
|
2042
|
-
replaceMessage: (index: number, message: UI_MESSAGE) => void;
|
2043
|
-
snapshot: <T>(thing: T) => T;
|
2044
|
-
}
|
2045
|
-
type ChatOnErrorCallback = (error: Error) => void;
|
2046
|
-
type ChatOnToolCallCallback = ({ toolCall, }: {
|
2047
|
-
toolCall: ToolCall<string, unknown>;
|
2048
|
-
}) => void | Promise<unknown> | unknown;
|
2049
|
-
type ChatOnDataCallback<UI_MESSAGE extends UIMessage> = (dataPart: DataUIPart<InferUIMessageData<UI_MESSAGE>>) => void;
|
2050
|
-
type ChatOnFinishCallback<UI_MESSAGE extends UIMessage> = (options: {
|
2051
|
-
message: UI_MESSAGE;
|
2052
|
-
}) => void;
|
2053
|
-
interface ChatInit<UI_MESSAGE extends UIMessage> {
|
2360
|
+
n?: number;
|
2054
2361
|
/**
|
2055
|
-
|
2056
|
-
* generated.
|
2362
|
+
Number of images to generate.
|
2057
2363
|
*/
|
2058
|
-
|
2059
|
-
messageMetadataSchema?: Validator<InferUIMessageMetadata<UI_MESSAGE>> | StandardSchemaV1<InferUIMessageMetadata<UI_MESSAGE>>;
|
2060
|
-
dataPartSchemas?: UIDataTypesToSchemas<InferUIMessageData<UI_MESSAGE>>;
|
2061
|
-
messages?: UI_MESSAGE[];
|
2364
|
+
maxImagesPerCall?: number;
|
2062
2365
|
/**
|
2063
|
-
|
2064
|
-
* If not provided the default AI SDK `generateId` is used.
|
2366
|
+
Size of the images to generate. Must have the format `{width}x{height}`. If not provided, the default size will be used.
|
2065
2367
|
*/
|
2066
|
-
|
2067
|
-
transport?: ChatTransport<UI_MESSAGE>;
|
2068
|
-
maxSteps?: number;
|
2368
|
+
size?: `${number}x${number}`;
|
2069
2369
|
/**
|
2070
|
-
|
2370
|
+
Aspect ratio of the images to generate. Must have the format `{width}:{height}`. If not provided, the default aspect ratio will be used.
|
2071
2371
|
*/
|
2072
|
-
|
2372
|
+
aspectRatio?: `${number}:${number}`;
|
2073
2373
|
/**
|
2074
|
-
|
2075
|
-
|
2374
|
+
Seed for the image generation. If not provided, the default seed will be used.
|
2375
|
+
*/
|
2376
|
+
seed?: number;
|
2377
|
+
/**
|
2378
|
+
Additional provider-specific options that are passed through to the provider
|
2379
|
+
as body parameters.
|
2076
2380
|
|
2077
|
-
|
2078
|
-
|
2381
|
+
The outer record is keyed by the provider name, and the inner
|
2382
|
+
record is keyed by the provider-specific metadata key.
|
2383
|
+
```ts
|
2384
|
+
{
|
2385
|
+
"openai": {
|
2386
|
+
"style": "vivid"
|
2387
|
+
}
|
2388
|
+
}
|
2389
|
+
```
|
2079
2390
|
*/
|
2080
|
-
|
2391
|
+
providerOptions?: ProviderOptions;
|
2081
2392
|
/**
|
2082
|
-
|
2083
|
-
|
2084
|
-
|
2393
|
+
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
2394
|
+
|
2395
|
+
@default 2
|
2085
2396
|
*/
|
2086
|
-
|
2397
|
+
maxRetries?: number;
|
2087
2398
|
/**
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2399
|
+
Abort signal.
|
2400
|
+
*/
|
2401
|
+
abortSignal?: AbortSignal;
|
2402
|
+
/**
|
2403
|
+
Additional headers to include in the request.
|
2404
|
+
Only applicable for HTTP-based providers.
|
2405
|
+
*/
|
2406
|
+
headers?: Record<string, string>;
|
2407
|
+
}): Promise<GenerateImageResult>;
|
2408
|
+
|
2409
|
+
/**
|
2410
|
+
The result of a `generateObject` call.
|
2411
|
+
*/
|
2412
|
+
interface GenerateObjectResult<OBJECT> {
|
2413
|
+
/**
|
2414
|
+
The generated object (typed according to the schema).
|
2415
|
+
*/
|
2416
|
+
readonly object: OBJECT;
|
2417
|
+
/**
|
2418
|
+
The reason why the generation finished.
|
2419
|
+
*/
|
2420
|
+
readonly finishReason: FinishReason;
|
2421
|
+
/**
|
2422
|
+
The token usage of the generated text.
|
2423
|
+
*/
|
2424
|
+
readonly usage: LanguageModelUsage;
|
2425
|
+
/**
|
2426
|
+
Warnings from the model provider (e.g. unsupported settings).
|
2427
|
+
*/
|
2428
|
+
readonly warnings: CallWarning[] | undefined;
|
2429
|
+
/**
|
2430
|
+
Additional request information.
|
2091
2431
|
*/
|
2092
|
-
|
2093
|
-
}
|
2094
|
-
declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
2095
|
-
readonly id: string;
|
2096
|
-
readonly generateId: IdGenerator;
|
2097
|
-
protected state: ChatState<UI_MESSAGE>;
|
2098
|
-
private messageMetadataSchema;
|
2099
|
-
private dataPartSchemas;
|
2100
|
-
private readonly transport;
|
2101
|
-
private maxSteps;
|
2102
|
-
private onError?;
|
2103
|
-
private onToolCall?;
|
2104
|
-
private onFinish?;
|
2105
|
-
private onData?;
|
2106
|
-
private activeResponse;
|
2107
|
-
private jobExecutor;
|
2108
|
-
constructor({ generateId, id, transport, maxSteps, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, onData, }: Omit<ChatInit<UI_MESSAGE>, 'messages'> & {
|
2109
|
-
state: ChatState<UI_MESSAGE>;
|
2110
|
-
});
|
2432
|
+
readonly request: LanguageModelRequestMetadata;
|
2111
2433
|
/**
|
2112
|
-
|
2113
|
-
*
|
2114
|
-
* - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.
|
2115
|
-
* - `streaming`: The response is actively streaming in from the API, receiving chunks of data.
|
2116
|
-
* - `ready`: The full response has been received and processed; a new user message can be submitted.
|
2117
|
-
* - `error`: An error occurred during the API request, preventing successful completion.
|
2434
|
+
Additional response information.
|
2118
2435
|
*/
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2123
|
-
|
2124
|
-
|
2125
|
-
get messages(): UI_MESSAGE[];
|
2126
|
-
get lastMessage(): UI_MESSAGE | undefined;
|
2127
|
-
set messages(messages: UI_MESSAGE[]);
|
2436
|
+
readonly response: LanguageModelResponseMetadata & {
|
2437
|
+
/**
|
2438
|
+
Response body (available only for providers that use HTTP requests).
|
2439
|
+
*/
|
2440
|
+
body?: unknown;
|
2441
|
+
};
|
2128
2442
|
/**
|
2129
|
-
|
2130
|
-
|
2131
|
-
|
2132
|
-
* If a messageId is provided, the message will be replaced.
|
2443
|
+
Additional provider-specific metadata. They are passed through
|
2444
|
+
from the provider to the AI SDK and enable provider-specific
|
2445
|
+
results that can be fully encapsulated in the provider.
|
2133
2446
|
*/
|
2134
|
-
|
2135
|
-
text?: never;
|
2136
|
-
files?: never;
|
2137
|
-
messageId?: string;
|
2138
|
-
}) | {
|
2139
|
-
text: string;
|
2140
|
-
files?: FileList | FileUIPart[];
|
2141
|
-
metadata?: InferUIMessageMetadata<UI_MESSAGE>;
|
2142
|
-
parts?: never;
|
2143
|
-
messageId?: string;
|
2144
|
-
} | {
|
2145
|
-
files: FileList | FileUIPart[];
|
2146
|
-
metadata?: InferUIMessageMetadata<UI_MESSAGE>;
|
2147
|
-
parts?: never;
|
2148
|
-
messageId?: string;
|
2149
|
-
}, options?: ChatRequestOptions) => Promise<void>;
|
2150
|
-
/**
|
2151
|
-
* Regenerate the assistant message with the provided message id.
|
2152
|
-
* If no message id is provided, the last assistant message will be regenerated.
|
2153
|
-
*/
|
2154
|
-
regenerate: ({ messageId, ...options }?: {
|
2155
|
-
messageId?: string;
|
2156
|
-
} & ChatRequestOptions) => Promise<void>;
|
2157
|
-
/**
|
2158
|
-
* Attempt to resume an ongoing streaming response.
|
2159
|
-
*/
|
2160
|
-
resumeStream: (options?: ChatRequestOptions) => Promise<void>;
|
2161
|
-
addToolResult: ({ toolCallId, output, }: {
|
2162
|
-
toolCallId: string;
|
2163
|
-
output: unknown;
|
2164
|
-
}) => Promise<void>;
|
2447
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
2165
2448
|
/**
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2449
|
+
Converts the object to a JSON response.
|
2450
|
+
The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
|
2451
|
+
*/
|
2452
|
+
toJsonResponse(init?: ResponseInit): Response;
|
2170
2453
|
}
|
2171
2454
|
|
2172
|
-
declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
|
2173
|
-
|
2174
2455
|
/**
|
2175
|
-
|
2176
|
-
|
2456
|
+
A function that attempts to repair the raw output of the mode
|
2457
|
+
to enable JSON parsing.
|
2177
2458
|
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
ignoreIncompleteToolCalls?: boolean;
|
2185
|
-
}): ModelMessage[];
|
2459
|
+
Should return the repaired text or null if the text cannot be repaired.
|
2460
|
+
*/
|
2461
|
+
type RepairTextFunction = (options: {
|
2462
|
+
text: string;
|
2463
|
+
error: JSONParseError | TypeValidationError;
|
2464
|
+
}) => Promise<string | null>;
|
2186
2465
|
/**
|
2187
|
-
|
2188
|
-
*/
|
2189
|
-
declare const convertToCoreMessages: typeof convertToModelMessages;
|
2466
|
+
Generate a structured, typed object for a given prompt and schema using a language model.
|
2190
2467
|
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
|
2202
|
-
|
2203
|
-
|
2204
|
-
|
2205
|
-
|
2206
|
-
|
2207
|
-
|
2208
|
-
|
2209
|
-
|
2210
|
-
|
2211
|
-
|
2212
|
-
|
2213
|
-
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2468
|
+
This function does not stream the output. If you want to stream the output, use `streamObject` instead.
|
2469
|
+
|
2470
|
+
@param model - The language model to use.
|
2471
|
+
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
2472
|
+
|
2473
|
+
@param system - A system message that will be part of the prompt.
|
2474
|
+
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
2475
|
+
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
2476
|
+
|
2477
|
+
@param maxOutputTokens - Maximum number of tokens to generate.
|
2478
|
+
@param temperature - Temperature setting.
|
2479
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
2480
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
2481
|
+
@param topP - Nucleus sampling.
|
2482
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
2483
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
2484
|
+
@param topK - Only sample from the top K options for each subsequent token.
|
2485
|
+
Used to remove "long tail" low probability responses.
|
2486
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
2487
|
+
@param presencePenalty - Presence penalty setting.
|
2488
|
+
It affects the likelihood of the model to repeat information that is already in the prompt.
|
2489
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
2490
|
+
@param frequencyPenalty - Frequency penalty setting.
|
2491
|
+
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
2492
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
2493
|
+
@param stopSequences - Stop sequences.
|
2494
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
2495
|
+
@param seed - The seed (integer) to use for random sampling.
|
2496
|
+
If set and supported by the model, calls will generate deterministic results.
|
2497
|
+
|
2498
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
2499
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
2500
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
2501
|
+
|
2502
|
+
@param schema - The schema of the object that the model should generate.
|
2503
|
+
@param schemaName - Optional name of the output that should be generated.
|
2504
|
+
Used by some providers for additional LLM guidance, e.g.
|
2505
|
+
via tool or schema name.
|
2506
|
+
@param schemaDescription - Optional description of the output that should be generated.
|
2507
|
+
Used by some providers for additional LLM guidance, e.g.
|
2508
|
+
via tool or schema description.
|
2509
|
+
|
2510
|
+
@param output - The type of the output.
|
2511
|
+
|
2512
|
+
- 'object': The output is an object.
|
2513
|
+
- 'array': The output is an array.
|
2514
|
+
- 'enum': The output is an enum.
|
2515
|
+
- 'no-schema': The output is not a schema.
|
2516
|
+
|
2517
|
+
@param experimental_repairText - A function that attempts to repair the raw output of the mode
|
2518
|
+
to enable JSON parsing.
|
2519
|
+
|
2520
|
+
@param experimental_telemetry - Optional telemetry configuration (experimental).
|
2521
|
+
|
2522
|
+
@param providerOptions - Additional provider-specific options. They are passed through
|
2523
|
+
to the provider from the AI SDK and enable provider-specific
|
2524
|
+
functionality that can be fully encapsulated in the provider.
|
2525
|
+
|
2526
|
+
@returns
|
2527
|
+
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
2528
|
+
*/
|
2529
|
+
declare function generateObject<SCHEMA extends z3.Schema | z4$1.ZodType | Schema = z4$1.ZodType<JSONValue$1>, OUTPUT extends 'object' | 'array' | 'enum' | 'no-schema' = InferSchema<SCHEMA> extends string ? 'enum' : 'object', RESULT = OUTPUT extends 'array' ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (OUTPUT extends 'enum' ? {
|
2231
2530
|
/**
|
2232
|
-
|
2233
|
-
|
2234
|
-
|
2235
|
-
|
2236
|
-
|
2531
|
+
The enum values that the model should use.
|
2532
|
+
*/
|
2533
|
+
enum: Array<RESULT>;
|
2534
|
+
mode?: 'json';
|
2535
|
+
output: 'enum';
|
2536
|
+
} : OUTPUT extends 'no-schema' ? {} : {
|
2237
2537
|
/**
|
2238
|
-
|
2239
|
-
|
2240
|
-
|
2538
|
+
The schema of the object that the model should generate.
|
2539
|
+
*/
|
2540
|
+
schema: SCHEMA;
|
2241
2541
|
/**
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2246
|
-
|
2247
|
-
* body: {
|
2248
|
-
* sessionId: '123',
|
2249
|
-
* }
|
2250
|
-
* })
|
2251
|
-
* ```
|
2252
|
-
*/
|
2253
|
-
body?: object;
|
2542
|
+
Optional name of the output that should be generated.
|
2543
|
+
Used by some providers for additional LLM guidance, e.g.
|
2544
|
+
via tool or schema name.
|
2545
|
+
*/
|
2546
|
+
schemaName?: string;
|
2254
2547
|
/**
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
2258
|
-
|
2548
|
+
Optional description of the output that should be generated.
|
2549
|
+
Used by some providers for additional LLM guidance, e.g.
|
2550
|
+
via tool or schema description.
|
2551
|
+
*/
|
2552
|
+
schemaDescription?: string;
|
2259
2553
|
/**
|
2260
|
-
|
2261
|
-
* to prepare the request body for the chat API. This can be useful for
|
2262
|
-
* customizing the request body based on the messages and data in the chat.
|
2263
|
-
*
|
2264
|
-
* @param id The id of the chat.
|
2265
|
-
* @param messages The current messages in the chat.
|
2266
|
-
* @param requestBody The request body object passed in the chat request.
|
2267
|
-
*/
|
2268
|
-
prepareSendMessagesRequest?: PrepareSendMessagesRequest<UI_MESSAGE>;
|
2269
|
-
prepareReconnectToStreamRequest?: PrepareReconnectToStreamRequest;
|
2270
|
-
};
|
2271
|
-
declare abstract class HttpChatTransport<UI_MESSAGE extends UIMessage> implements ChatTransport<UI_MESSAGE> {
|
2272
|
-
protected api: string;
|
2273
|
-
protected credentials?: RequestCredentials;
|
2274
|
-
protected headers?: Record<string, string> | Headers;
|
2275
|
-
protected body?: object;
|
2276
|
-
protected fetch?: FetchFunction;
|
2277
|
-
protected prepareSendMessagesRequest?: PrepareSendMessagesRequest<UI_MESSAGE>;
|
2278
|
-
protected prepareReconnectToStreamRequest?: PrepareReconnectToStreamRequest;
|
2279
|
-
constructor({ api, credentials, headers, body, fetch, prepareSendMessagesRequest, prepareReconnectToStreamRequest, }: HttpChatTransportInitOptions<UI_MESSAGE>);
|
2280
|
-
sendMessages({ abortSignal, ...options }: Parameters<ChatTransport<UI_MESSAGE>['sendMessages']>[0]): Promise<ReadableStream<UIMessageChunk>>;
|
2281
|
-
reconnectToStream(options: Parameters<ChatTransport<UI_MESSAGE>['reconnectToStream']>[0]): Promise<ReadableStream<UIMessageChunk> | null>;
|
2282
|
-
protected abstract processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageChunk>;
|
2283
|
-
}
|
2554
|
+
The mode to use for object generation.
|
2284
2555
|
|
2285
|
-
|
2286
|
-
constructor(options?: HttpChatTransportInitOptions<UI_MESSAGE>);
|
2287
|
-
protected processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageChunk>;
|
2288
|
-
}
|
2556
|
+
The schema is converted into a JSON schema and used in one of the following ways
|
2289
2557
|
|
2290
|
-
|
2291
|
-
|
2292
|
-
|
2293
|
-
}
|
2558
|
+
- 'auto': The provider will choose the best mode for the model.
|
2559
|
+
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
2560
|
+
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
2294
2561
|
|
2295
|
-
|
2562
|
+
Please note that most providers do not support all modes.
|
2563
|
+
|
2564
|
+
Default and recommended: 'auto' (best mode for the model).
|
2565
|
+
*/
|
2566
|
+
mode?: 'auto' | 'json' | 'tool';
|
2567
|
+
}) & {
|
2568
|
+
output?: OUTPUT;
|
2296
2569
|
/**
|
2297
|
-
|
2570
|
+
The language model to use.
|
2298
2571
|
*/
|
2299
|
-
|
2572
|
+
model: LanguageModel;
|
2300
2573
|
/**
|
2301
|
-
|
2302
|
-
|
2303
|
-
body?: object;
|
2304
|
-
};
|
2305
|
-
type UseCompletionOptions = {
|
2306
|
-
/**
|
2307
|
-
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
2308
|
-
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
2309
|
-
*/
|
2310
|
-
api?: string;
|
2311
|
-
/**
|
2312
|
-
* An unique identifier for the chat. If not provided, a random one will be
|
2313
|
-
* generated. When provided, the `useChat` hook with the same `id` will
|
2314
|
-
* have shared states across components.
|
2315
|
-
*/
|
2316
|
-
id?: string;
|
2317
|
-
/**
|
2318
|
-
* Initial prompt input of the completion.
|
2319
|
-
*/
|
2320
|
-
initialInput?: string;
|
2321
|
-
/**
|
2322
|
-
* Initial completion result. Useful to load an existing history.
|
2323
|
-
*/
|
2324
|
-
initialCompletion?: string;
|
2325
|
-
/**
|
2326
|
-
* Callback function to be called when the completion is finished streaming.
|
2327
|
-
*/
|
2328
|
-
onFinish?: (prompt: string, completion: string) => void;
|
2329
|
-
/**
|
2330
|
-
* Callback function to be called when an error is encountered.
|
2574
|
+
A function that attempts to repair the raw output of the mode
|
2575
|
+
to enable JSON parsing.
|
2331
2576
|
*/
|
2332
|
-
|
2577
|
+
experimental_repairText?: RepairTextFunction;
|
2333
2578
|
/**
|
2334
|
-
|
2335
|
-
|
2336
|
-
|
2337
|
-
*/
|
2338
|
-
credentials?: RequestCredentials;
|
2579
|
+
Optional telemetry configuration (experimental).
|
2580
|
+
*/
|
2581
|
+
experimental_telemetry?: TelemetrySettings;
|
2339
2582
|
/**
|
2340
|
-
|
2341
|
-
|
2342
|
-
|
2583
|
+
Additional provider-specific options. They are passed through
|
2584
|
+
to the provider from the AI SDK and enable provider-specific
|
2585
|
+
functionality that can be fully encapsulated in the provider.
|
2586
|
+
*/
|
2587
|
+
providerOptions?: ProviderOptions;
|
2343
2588
|
/**
|
2344
|
-
*
|
2345
|
-
* @example
|
2346
|
-
* Send a `sessionId` to the API along with the prompt.
|
2347
|
-
* ```js
|
2348
|
-
* useChat({
|
2349
|
-
* body: {
|
2350
|
-
* sessionId: '123',
|
2351
|
-
* }
|
2352
|
-
* })
|
2353
|
-
* ```
|
2589
|
+
* Internal. For test use only. May change without notice.
|
2354
2590
|
*/
|
2355
|
-
|
2356
|
-
|
2357
|
-
|
2358
|
-
|
2359
|
-
|
2360
|
-
/**
|
2361
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
2362
|
-
or to provide a custom fetch implementation for e.g. testing.
|
2363
|
-
*/
|
2364
|
-
fetch?: FetchFunction;
|
2365
|
-
};
|
2591
|
+
_internal?: {
|
2592
|
+
generateId?: () => string;
|
2593
|
+
currentDate?: () => Date;
|
2594
|
+
};
|
2595
|
+
}): Promise<GenerateObjectResult<RESULT>>;
|
2366
2596
|
|
2367
2597
|
/**
|
2368
2598
|
* Calculates the cosine similarity between two vectors. This is a useful metric for
|
@@ -2425,257 +2655,137 @@ declare function simulateReadableStream<T>({ chunks, initialDelayInMs, chunkDela
|
|
2425
2655
|
}): ReadableStream<T>;
|
2426
2656
|
|
2427
2657
|
/**
|
2428
|
-
The result of
|
2429
|
-
It contains the embedding, the value, and additional information.
|
2658
|
+
The result of a `streamObject` call that contains the partial object stream and additional information.
|
2430
2659
|
*/
|
2431
|
-
interface
|
2432
|
-
/**
|
2433
|
-
The value that was embedded.
|
2434
|
-
*/
|
2435
|
-
readonly value: VALUE;
|
2436
|
-
/**
|
2437
|
-
The embedding of the value.
|
2438
|
-
*/
|
2439
|
-
readonly embedding: Embedding;
|
2440
|
-
/**
|
2441
|
-
The embedding token usage.
|
2442
|
-
*/
|
2443
|
-
readonly usage: EmbeddingModelUsage;
|
2660
|
+
interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
|
2444
2661
|
/**
|
2445
|
-
|
2662
|
+
Warnings from the model provider (e.g. unsupported settings)
|
2446
2663
|
*/
|
2447
|
-
readonly
|
2448
|
-
/**
|
2449
|
-
Response headers.
|
2450
|
-
*/
|
2451
|
-
headers?: Record<string, string>;
|
2452
|
-
/**
|
2453
|
-
The response body.
|
2454
|
-
*/
|
2455
|
-
body?: unknown;
|
2456
|
-
};
|
2457
|
-
}
|
2458
|
-
|
2459
|
-
/**
|
2460
|
-
Embed a value using an embedding model. The type of the value is defined by the embedding model.
|
2461
|
-
|
2462
|
-
@param model - The embedding model to use.
|
2463
|
-
@param value - The value that should be embedded.
|
2464
|
-
|
2465
|
-
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
2466
|
-
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
2467
|
-
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
2468
|
-
|
2469
|
-
@returns A result object that contains the embedding, the value, and additional information.
|
2470
|
-
*/
|
2471
|
-
declare function embed<VALUE>({ model, value, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
|
2664
|
+
readonly warnings: Promise<CallWarning[] | undefined>;
|
2472
2665
|
/**
|
2473
|
-
|
2666
|
+
The token usage of the generated response. Resolved when the response is finished.
|
2474
2667
|
*/
|
2475
|
-
|
2476
|
-
/**
|
2477
|
-
The value that should be embedded.
|
2478
|
-
*/
|
2479
|
-
value: VALUE;
|
2668
|
+
readonly usage: Promise<LanguageModelUsage>;
|
2480
2669
|
/**
|
2481
|
-
|
2482
|
-
|
2483
|
-
|
2670
|
+
Additional provider-specific metadata. They are passed through
|
2671
|
+
from the provider to the AI SDK and enable provider-specific
|
2672
|
+
results that can be fully encapsulated in the provider.
|
2484
2673
|
*/
|
2485
|
-
|
2674
|
+
readonly providerMetadata: Promise<ProviderMetadata | undefined>;
|
2486
2675
|
/**
|
2487
|
-
|
2676
|
+
Additional request information from the last step.
|
2488
2677
|
*/
|
2489
|
-
|
2678
|
+
readonly request: Promise<LanguageModelRequestMetadata>;
|
2490
2679
|
/**
|
2491
|
-
Additional
|
2492
|
-
Only applicable for HTTP-based providers.
|
2680
|
+
Additional response information.
|
2493
2681
|
*/
|
2494
|
-
|
2682
|
+
readonly response: Promise<LanguageModelResponseMetadata>;
|
2495
2683
|
/**
|
2496
|
-
|
2497
|
-
|
2498
|
-
|
2499
|
-
*/
|
2500
|
-
providerOptions?: ProviderOptions;
|
2684
|
+
The generated object (typed according to the schema). Resolved when the response is finished.
|
2685
|
+
*/
|
2686
|
+
readonly object: Promise<RESULT>;
|
2501
2687
|
/**
|
2502
|
-
|
2688
|
+
Stream of partial objects. It gets more complete as the stream progresses.
|
2689
|
+
|
2690
|
+
Note that the partial object is not validated.
|
2691
|
+
If you want to be certain that the actual content matches your schema, you need to implement your own validation for partial results.
|
2692
|
+
*/
|
2693
|
+
readonly partialObjectStream: AsyncIterableStream<PARTIAL>;
|
2694
|
+
/**
|
2695
|
+
* Stream over complete array elements. Only available if the output strategy is set to `array`.
|
2503
2696
|
*/
|
2504
|
-
|
2505
|
-
}): Promise<EmbedResult<VALUE>>;
|
2506
|
-
|
2507
|
-
/**
|
2508
|
-
The result of a `embedMany` call.
|
2509
|
-
It contains the embeddings, the values, and additional information.
|
2510
|
-
*/
|
2511
|
-
interface EmbedManyResult<VALUE> {
|
2697
|
+
readonly elementStream: ELEMENT_STREAM;
|
2512
2698
|
/**
|
2513
|
-
|
2699
|
+
Text stream of the JSON representation of the generated object. It contains text chunks.
|
2700
|
+
When the stream is finished, the object is valid JSON that can be parsed.
|
2514
2701
|
*/
|
2515
|
-
readonly
|
2516
|
-
/**
|
2517
|
-
The embeddings. They are in the same order as the values.
|
2518
|
-
*/
|
2519
|
-
readonly embeddings: Array<Embedding>;
|
2702
|
+
readonly textStream: AsyncIterableStream<string>;
|
2520
2703
|
/**
|
2521
|
-
|
2522
|
-
|
2523
|
-
|
2704
|
+
Stream of different types of events, including partial objects, errors, and finish events.
|
2705
|
+
Only errors that stop the stream, such as network errors, are thrown.
|
2706
|
+
*/
|
2707
|
+
readonly fullStream: AsyncIterableStream<ObjectStreamPart<PARTIAL>>;
|
2524
2708
|
/**
|
2525
|
-
|
2709
|
+
Writes text delta output to a Node.js response-like object.
|
2710
|
+
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
2711
|
+
writes each text delta as a separate chunk.
|
2712
|
+
|
2713
|
+
@param response A Node.js response-like object (ServerResponse).
|
2714
|
+
@param init Optional headers, status code, and status text.
|
2526
2715
|
*/
|
2527
|
-
|
2528
|
-
|
2529
|
-
|
2716
|
+
pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): void;
|
2717
|
+
/**
|
2718
|
+
Creates a simple text stream response.
|
2719
|
+
The response has a `Content-Type` header set to `text/plain; charset=utf-8`.
|
2720
|
+
Each text delta is encoded as UTF-8 and sent as a separate chunk.
|
2721
|
+
Non-text-delta events are ignored.
|
2722
|
+
|
2723
|
+
@param init Optional headers, status code, and status text.
|
2530
2724
|
*/
|
2531
|
-
|
2532
|
-
/**
|
2533
|
-
The response body.
|
2534
|
-
*/
|
2535
|
-
body?: unknown;
|
2536
|
-
} | undefined>;
|
2725
|
+
toTextStreamResponse(init?: ResponseInit): Response;
|
2537
2726
|
}
|
2727
|
+
type ObjectStreamPart<PARTIAL> = {
|
2728
|
+
type: 'object';
|
2729
|
+
object: PARTIAL;
|
2730
|
+
} | {
|
2731
|
+
type: 'text-delta';
|
2732
|
+
textDelta: string;
|
2733
|
+
} | {
|
2734
|
+
type: 'error';
|
2735
|
+
error: unknown;
|
2736
|
+
} | {
|
2737
|
+
type: 'finish';
|
2738
|
+
finishReason: FinishReason;
|
2739
|
+
usage: LanguageModelUsage;
|
2740
|
+
response: LanguageModelResponseMetadata;
|
2741
|
+
providerMetadata?: ProviderMetadata;
|
2742
|
+
};
|
2538
2743
|
|
2539
2744
|
/**
|
2540
|
-
|
2541
|
-
by the embedding model.
|
2542
|
-
|
2543
|
-
`embedMany` automatically splits large requests into smaller chunks if the model
|
2544
|
-
has a limit on how many embeddings can be generated in a single call.
|
2545
|
-
|
2546
|
-
@param model - The embedding model to use.
|
2547
|
-
@param values - The values that should be embedded.
|
2745
|
+
Callback that is set using the `onError` option.
|
2548
2746
|
|
2549
|
-
@param
|
2550
|
-
|
2551
|
-
|
2747
|
+
@param event - The event that is passed to the callback.
|
2748
|
+
*/
|
2749
|
+
type StreamObjectOnErrorCallback = (event: {
|
2750
|
+
error: unknown;
|
2751
|
+
}) => Promise<void> | void;
|
2752
|
+
/**
|
2753
|
+
Callback that is set using the `onFinish` option.
|
2552
2754
|
|
2553
|
-
@
|
2755
|
+
@param event - The event that is passed to the callback.
|
2554
2756
|
*/
|
2555
|
-
|
2556
|
-
/**
|
2557
|
-
The embedding model to use.
|
2558
|
-
*/
|
2559
|
-
model: EmbeddingModel<VALUE>;
|
2757
|
+
type StreamObjectOnFinishCallback<RESULT> = (event: {
|
2560
2758
|
/**
|
2561
|
-
The
|
2562
|
-
|
2563
|
-
|
2759
|
+
The token usage of the generated response.
|
2760
|
+
*/
|
2761
|
+
usage: LanguageModelUsage;
|
2564
2762
|
/**
|
2565
|
-
|
2566
|
-
|
2567
|
-
|
2568
|
-
*/
|
2569
|
-
maxRetries?: number;
|
2763
|
+
The generated object. Can be undefined if the final object does not match the schema.
|
2764
|
+
*/
|
2765
|
+
object: RESULT | undefined;
|
2570
2766
|
/**
|
2571
|
-
|
2572
|
-
|
2573
|
-
|
2767
|
+
Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema.
|
2768
|
+
*/
|
2769
|
+
error: unknown | undefined;
|
2574
2770
|
/**
|
2575
|
-
|
2576
|
-
Only applicable for HTTP-based providers.
|
2771
|
+
Response metadata.
|
2577
2772
|
*/
|
2578
|
-
|
2579
|
-
/**
|
2580
|
-
* Optional telemetry configuration (experimental).
|
2581
|
-
*/
|
2582
|
-
experimental_telemetry?: TelemetrySettings;
|
2583
|
-
/**
|
2584
|
-
Additional provider-specific options. They are passed through
|
2585
|
-
to the provider from the AI SDK and enable provider-specific
|
2586
|
-
functionality that can be fully encapsulated in the provider.
|
2587
|
-
*/
|
2588
|
-
providerOptions?: ProviderOptions;
|
2589
|
-
/**
|
2590
|
-
* Maximum number of concurrent requests.
|
2591
|
-
*
|
2592
|
-
* @default Infinity
|
2593
|
-
*/
|
2594
|
-
maxParallelCalls?: number;
|
2595
|
-
}): Promise<EmbedManyResult<VALUE>>;
|
2596
|
-
|
2597
|
-
/**
|
2598
|
-
* Detects the first chunk in a buffer.
|
2599
|
-
*
|
2600
|
-
* @param buffer - The buffer to detect the first chunk in.
|
2601
|
-
*
|
2602
|
-
* @returns The first detected chunk, or `undefined` if no chunk was detected.
|
2603
|
-
*/
|
2604
|
-
type ChunkDetector = (buffer: string) => string | undefined | null;
|
2605
|
-
/**
|
2606
|
-
* Smooths text streaming output.
|
2607
|
-
*
|
2608
|
-
* @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
|
2609
|
-
* @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, or provide a custom RegExp pattern for custom chunking.
|
2610
|
-
*
|
2611
|
-
* @returns A transform stream that smooths text streaming output.
|
2612
|
-
*/
|
2613
|
-
declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _internal: { delay }, }?: {
|
2614
|
-
delayInMs?: number | null;
|
2615
|
-
chunking?: 'word' | 'line' | RegExp | ChunkDetector;
|
2616
|
-
/**
|
2617
|
-
* Internal. For test use only. May change without notice.
|
2618
|
-
*/
|
2619
|
-
_internal?: {
|
2620
|
-
delay?: (delayInMs: number | null) => Promise<void>;
|
2621
|
-
};
|
2622
|
-
}): (options: {
|
2623
|
-
tools: TOOLS;
|
2624
|
-
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
2625
|
-
|
2626
|
-
/**
|
2627
|
-
A transformation that is applied to the stream.
|
2628
|
-
|
2629
|
-
@param stopStream - A function that stops the source stream.
|
2630
|
-
@param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
2631
|
-
*/
|
2632
|
-
type StreamTextTransform<TOOLS extends ToolSet> = (options: {
|
2633
|
-
tools: TOOLS;
|
2634
|
-
stopStream: () => void;
|
2635
|
-
}) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
|
2636
|
-
/**
|
2637
|
-
Callback that is set using the `onError` option.
|
2638
|
-
|
2639
|
-
@param event - The event that is passed to the callback.
|
2640
|
-
*/
|
2641
|
-
type StreamTextOnErrorCallback = (event: {
|
2642
|
-
error: unknown;
|
2643
|
-
}) => Promise<void> | void;
|
2644
|
-
/**
|
2645
|
-
Callback that is set using the `onStepFinish` option.
|
2646
|
-
|
2647
|
-
@param stepResult - The result of the step.
|
2648
|
-
*/
|
2649
|
-
type StreamTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
|
2650
|
-
/**
|
2651
|
-
Callback that is set using the `onChunk` option.
|
2652
|
-
|
2653
|
-
@param event - The event that is passed to the callback.
|
2654
|
-
*/
|
2655
|
-
type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
|
2656
|
-
chunk: Extract<TextStreamPart<TOOLS>, {
|
2657
|
-
type: 'text' | 'reasoning' | 'source' | 'tool-call' | 'tool-input-start' | 'tool-input-delta' | 'tool-result' | 'raw';
|
2658
|
-
}>;
|
2659
|
-
}) => Promise<void> | void;
|
2660
|
-
/**
|
2661
|
-
Callback that is set using the `onFinish` option.
|
2662
|
-
|
2663
|
-
@param event - The event that is passed to the callback.
|
2664
|
-
*/
|
2665
|
-
type StreamTextOnFinishCallback<TOOLS extends ToolSet> = (event: StepResult<TOOLS> & {
|
2773
|
+
response: LanguageModelResponseMetadata;
|
2666
2774
|
/**
|
2667
|
-
|
2668
|
-
|
2669
|
-
|
2775
|
+
Warnings from the model provider (e.g. unsupported settings).
|
2776
|
+
*/
|
2777
|
+
warnings?: CallWarning[];
|
2670
2778
|
/**
|
2671
|
-
|
2672
|
-
|
2673
|
-
|
2779
|
+
Additional provider-specific metadata. They are passed through
|
2780
|
+
to the provider from the AI SDK and enable provider-specific
|
2781
|
+
functionality that can be fully encapsulated in the provider.
|
2782
|
+
*/
|
2783
|
+
providerMetadata: ProviderMetadata | undefined;
|
2674
2784
|
}) => Promise<void> | void;
|
2675
2785
|
/**
|
2676
|
-
Generate a
|
2786
|
+
Generate a structured, typed object for a given prompt and schema using a language model.
|
2677
2787
|
|
2678
|
-
This function streams the output. If you do not want to stream the output, use `
|
2788
|
+
This function streams the output. If you do not want to stream the output, use `generateObject` instead.
|
2679
2789
|
|
2680
2790
|
@param model - The language model to use.
|
2681
2791
|
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
@@ -2709,37 +2819,74 @@ If set and supported by the model, calls will generate deterministic results.
|
|
2709
2819
|
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
2710
2820
|
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
2711
2821
|
|
2712
|
-
@param
|
2822
|
+
@param schema - The schema of the object that the model should generate.
|
2823
|
+
@param schemaName - Optional name of the output that should be generated.
|
2824
|
+
Used by some providers for additional LLM guidance, e.g.
|
2825
|
+
via tool or schema name.
|
2826
|
+
@param schemaDescription - Optional description of the output that should be generated.
|
2827
|
+
Used by some providers for additional LLM guidance, e.g.
|
2828
|
+
via tool or schema description.
|
2713
2829
|
|
2714
|
-
@param
|
2715
|
-
@param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
|
2716
|
-
@param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
2717
|
-
@param onFinish - Callback that is called when the LLM response and all request tool executions
|
2718
|
-
(for tools that have an `execute` function) are finished.
|
2830
|
+
@param output - The type of the output.
|
2719
2831
|
|
2720
|
-
|
2721
|
-
|
2832
|
+
- 'object': The output is an object.
|
2833
|
+
- 'array': The output is an array.
|
2834
|
+
- 'enum': The output is an enum.
|
2835
|
+
- 'no-schema': The output is not a schema.
|
2836
|
+
|
2837
|
+
@param experimental_telemetry - Optional telemetry configuration (experimental).
|
2838
|
+
|
2839
|
+
@param providerOptions - Additional provider-specific options. They are passed through
|
2840
|
+
to the provider from the AI SDK and enable provider-specific
|
2841
|
+
functionality that can be fully encapsulated in the provider.
|
2842
|
+
|
2843
|
+
@returns
|
2844
|
+
A result object for accessing the partial object stream and additional information.
|
2722
2845
|
*/
|
2723
|
-
declare function
|
2846
|
+
declare function streamObject<SCHEMA extends z3.Schema | z4$1.ZodType | Schema = z4$1.ZodType<JSONValue$1>, OUTPUT extends 'object' | 'array' | 'enum' | 'no-schema' = InferSchema<SCHEMA> extends string ? 'enum' : 'object', RESULT = OUTPUT extends 'array' ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (OUTPUT extends 'enum' ? {
|
2724
2847
|
/**
|
2725
|
-
The
|
2726
|
-
|
2727
|
-
|
2848
|
+
The enum values that the model should use.
|
2849
|
+
*/
|
2850
|
+
enum: Array<RESULT>;
|
2851
|
+
mode?: 'json';
|
2852
|
+
output: 'enum';
|
2853
|
+
} : OUTPUT extends 'no-schema' ? {} : {
|
2728
2854
|
/**
|
2729
|
-
The
|
2730
|
-
|
2731
|
-
|
2855
|
+
The schema of the object that the model should generate.
|
2856
|
+
*/
|
2857
|
+
schema: SCHEMA;
|
2732
2858
|
/**
|
2733
|
-
|
2734
|
-
|
2735
|
-
|
2859
|
+
Optional name of the output that should be generated.
|
2860
|
+
Used by some providers for additional LLM guidance, e.g.
|
2861
|
+
via tool or schema name.
|
2862
|
+
*/
|
2863
|
+
schemaName?: string;
|
2736
2864
|
/**
|
2737
|
-
|
2738
|
-
|
2865
|
+
Optional description of the output that should be generated.
|
2866
|
+
Used by some providers for additional LLM guidance, e.g.
|
2867
|
+
via tool or schema description.
|
2868
|
+
*/
|
2869
|
+
schemaDescription?: string;
|
2870
|
+
/**
|
2871
|
+
The mode to use for object generation.
|
2739
2872
|
|
2740
|
-
|
2741
|
-
|
2742
|
-
|
2873
|
+
The schema is converted into a JSON schema and used in one of the following ways
|
2874
|
+
|
2875
|
+
- 'auto': The provider will choose the best mode for the model.
|
2876
|
+
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
2877
|
+
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
2878
|
+
|
2879
|
+
Please note that most providers do not support all modes.
|
2880
|
+
|
2881
|
+
Default and recommended: 'auto' (best mode for the model).
|
2882
|
+
*/
|
2883
|
+
mode?: 'auto' | 'json' | 'tool';
|
2884
|
+
}) & {
|
2885
|
+
output?: OUTPUT;
|
2886
|
+
/**
|
2887
|
+
The language model to use.
|
2888
|
+
*/
|
2889
|
+
model: LanguageModel;
|
2743
2890
|
/**
|
2744
2891
|
Optional telemetry configuration (experimental).
|
2745
2892
|
*/
|
@@ -2748,156 +2895,108 @@ Optional telemetry configuration (experimental).
|
|
2748
2895
|
Additional provider-specific options. They are passed through
|
2749
2896
|
to the provider from the AI SDK and enable provider-specific
|
2750
2897
|
functionality that can be fully encapsulated in the provider.
|
2751
|
-
|
2898
|
+
*/
|
2752
2899
|
providerOptions?: ProviderOptions;
|
2753
2900
|
/**
|
2754
|
-
|
2755
|
-
|
2756
|
-
|
2901
|
+
Callback that is invoked when an error occurs during streaming.
|
2902
|
+
You can use it to log errors.
|
2903
|
+
The stream processing will pause until the callback promise is resolved.
|
2904
|
+
*/
|
2905
|
+
onError?: StreamObjectOnErrorCallback;
|
2757
2906
|
/**
|
2758
|
-
|
2759
|
-
|
2760
|
-
|
2761
|
-
activeTools?: Array<keyof NoInfer<TOOLS>>;
|
2907
|
+
Callback that is called when the LLM response and the final object validation are finished.
|
2908
|
+
*/
|
2909
|
+
onFinish?: StreamObjectOnFinishCallback<RESULT>;
|
2762
2910
|
/**
|
2763
|
-
|
2911
|
+
* Internal. For test use only. May change without notice.
|
2764
2912
|
*/
|
2765
|
-
|
2766
|
-
|
2767
|
-
|
2768
|
-
|
2769
|
-
|
2770
|
-
|
2771
|
-
@param options.stepNumber - The number of the step that is being executed.
|
2772
|
-
@param options.model - The model that is being used.
|
2913
|
+
_internal?: {
|
2914
|
+
generateId?: () => string;
|
2915
|
+
currentDate?: () => Date;
|
2916
|
+
now?: () => number;
|
2917
|
+
};
|
2918
|
+
}): StreamObjectResult<OUTPUT extends 'enum' ? string : OUTPUT extends 'array' ? RESULT : DeepPartial<RESULT>, OUTPUT extends 'array' ? RESULT : RESULT, OUTPUT extends 'array' ? RESULT extends Array<infer U> ? AsyncIterableStream<U> : never : never>;
|
2773
2919
|
|
2774
|
-
|
2775
|
-
|
2776
|
-
|
2777
|
-
|
2920
|
+
/**
|
2921
|
+
* A generated audio file.
|
2922
|
+
*/
|
2923
|
+
interface GeneratedAudioFile extends GeneratedFile {
|
2778
2924
|
/**
|
2779
|
-
|
2925
|
+
* Audio format of the file (e.g., 'mp3', 'wav', etc.)
|
2780
2926
|
*/
|
2781
|
-
|
2782
|
-
|
2783
|
-
Optional stream transformations.
|
2784
|
-
They are applied in the order they are provided.
|
2785
|
-
The stream transformations must maintain the stream structure for streamText to work correctly.
|
2786
|
-
*/
|
2787
|
-
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
2788
|
-
/**
|
2789
|
-
Whether to include raw chunks from the provider in the stream.
|
2790
|
-
When enabled, you will receive raw chunks with type 'raw' that contain the unprocessed data from the provider.
|
2791
|
-
This allows access to cutting-edge provider features not yet wrapped by the AI SDK.
|
2792
|
-
Defaults to false.
|
2793
|
-
*/
|
2794
|
-
includeRawChunks?: boolean;
|
2795
|
-
/**
|
2796
|
-
Callback that is called for each chunk of the stream.
|
2797
|
-
The stream processing will pause until the callback promise is resolved.
|
2798
|
-
*/
|
2799
|
-
onChunk?: StreamTextOnChunkCallback<TOOLS>;
|
2800
|
-
/**
|
2801
|
-
Callback that is invoked when an error occurs during streaming.
|
2802
|
-
You can use it to log errors.
|
2803
|
-
The stream processing will pause until the callback promise is resolved.
|
2804
|
-
*/
|
2805
|
-
onError?: StreamTextOnErrorCallback;
|
2806
|
-
/**
|
2807
|
-
Callback that is called when the LLM response and all request tool executions
|
2808
|
-
(for tools that have an `execute` function) are finished.
|
2809
|
-
|
2810
|
-
The usage is the combined usage of all steps.
|
2811
|
-
*/
|
2812
|
-
onFinish?: StreamTextOnFinishCallback<TOOLS>;
|
2813
|
-
/**
|
2814
|
-
Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
2815
|
-
*/
|
2816
|
-
onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
|
2817
|
-
/**
|
2818
|
-
Internal. For test use only. May change without notice.
|
2819
|
-
*/
|
2820
|
-
_internal?: {
|
2821
|
-
now?: () => number;
|
2822
|
-
generateId?: IdGenerator;
|
2823
|
-
currentDate?: () => Date;
|
2824
|
-
};
|
2825
|
-
}): StreamTextResult<TOOLS, PARTIAL_OUTPUT>;
|
2927
|
+
readonly format: string;
|
2928
|
+
}
|
2826
2929
|
|
2827
2930
|
/**
|
2828
|
-
The result of a `
|
2829
|
-
It contains the
|
2931
|
+
The result of a `generateSpeech` call.
|
2932
|
+
It contains the audio data and additional information.
|
2830
2933
|
*/
|
2831
|
-
interface
|
2934
|
+
interface SpeechResult {
|
2832
2935
|
/**
|
2833
|
-
|
2936
|
+
* The audio data as a base64 encoded string or binary data.
|
2834
2937
|
*/
|
2835
|
-
readonly
|
2836
|
-
/**
|
2837
|
-
The images that were generated.
|
2838
|
-
*/
|
2839
|
-
readonly images: Array<GeneratedFile>;
|
2938
|
+
readonly audio: GeneratedAudioFile;
|
2840
2939
|
/**
|
2841
|
-
|
2940
|
+
Warnings for the call, e.g. unsupported settings.
|
2842
2941
|
*/
|
2843
|
-
readonly warnings: Array<
|
2942
|
+
readonly warnings: Array<SpeechWarning>;
|
2844
2943
|
/**
|
2845
|
-
|
2944
|
+
Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
2846
2945
|
*/
|
2847
|
-
readonly responses: Array<
|
2946
|
+
readonly responses: Array<SpeechModelResponseMetadata>;
|
2848
2947
|
/**
|
2849
|
-
|
2850
|
-
* results that can be fully encapsulated in the provider.
|
2948
|
+
Provider metadata from the provider.
|
2851
2949
|
*/
|
2852
|
-
readonly providerMetadata:
|
2950
|
+
readonly providerMetadata: Record<string, Record<string, JSONValue$1>>;
|
2853
2951
|
}
|
2854
2952
|
|
2855
2953
|
/**
|
2856
|
-
Generates
|
2954
|
+
Generates speech audio using a speech model.
|
2857
2955
|
|
2858
|
-
@param model - The
|
2859
|
-
@param
|
2860
|
-
@param
|
2861
|
-
@param
|
2862
|
-
@param
|
2863
|
-
@param
|
2956
|
+
@param model - The speech model to use.
|
2957
|
+
@param text - The text to convert to speech.
|
2958
|
+
@param voice - The voice to use for speech generation.
|
2959
|
+
@param outputFormat - The output format to use for speech generation e.g. "mp3", "wav", etc.
|
2960
|
+
@param instructions - Instructions for the speech generation e.g. "Speak in a slow and steady tone".
|
2961
|
+
@param speed - The speed of the speech generation.
|
2864
2962
|
@param providerOptions - Additional provider-specific options that are passed through to the provider
|
2865
2963
|
as body parameters.
|
2866
2964
|
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
2867
2965
|
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
2868
2966
|
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
2869
2967
|
|
2870
|
-
@returns A result object that contains the generated
|
2968
|
+
@returns A result object that contains the generated audio data.
|
2871
2969
|
*/
|
2872
|
-
declare function
|
2970
|
+
declare function generateSpeech({ model, text, voice, outputFormat, instructions, speed, language, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
|
2873
2971
|
/**
|
2874
|
-
The
|
2972
|
+
The speech model to use.
|
2875
2973
|
*/
|
2876
|
-
model:
|
2974
|
+
model: SpeechModelV2;
|
2877
2975
|
/**
|
2878
|
-
The
|
2976
|
+
The text to convert to speech.
|
2879
2977
|
*/
|
2880
|
-
|
2978
|
+
text: string;
|
2881
2979
|
/**
|
2882
|
-
|
2980
|
+
The voice to use for speech generation.
|
2883
2981
|
*/
|
2884
|
-
|
2982
|
+
voice?: string;
|
2885
2983
|
/**
|
2886
|
-
|
2984
|
+
* The desired output format for the audio e.g. "mp3", "wav", etc.
|
2887
2985
|
*/
|
2888
|
-
|
2986
|
+
outputFormat?: 'mp3' | 'wav' | (string & {});
|
2889
2987
|
/**
|
2890
|
-
|
2891
|
-
|
2892
|
-
|
2988
|
+
Instructions for the speech generation e.g. "Speak in a slow and steady tone".
|
2989
|
+
*/
|
2990
|
+
instructions?: string;
|
2893
2991
|
/**
|
2894
|
-
|
2992
|
+
The speed of the speech generation.
|
2895
2993
|
*/
|
2896
|
-
|
2994
|
+
speed?: number;
|
2897
2995
|
/**
|
2898
|
-
|
2996
|
+
The language for speech generation. This should be an ISO 639-1 language code (e.g. "en", "es", "fr")
|
2997
|
+
or "auto" for automatic language detection. Provider support varies.
|
2899
2998
|
*/
|
2900
|
-
|
2999
|
+
language?: string;
|
2901
3000
|
/**
|
2902
3001
|
Additional provider-specific options that are passed through to the provider
|
2903
3002
|
as body parameters.
|
@@ -2906,15 +3005,13 @@ declare function generateImage({ model, prompt, n, maxImagesPerCall, size, aspec
|
|
2906
3005
|
record is keyed by the provider-specific metadata key.
|
2907
3006
|
```ts
|
2908
3007
|
{
|
2909
|
-
"openai": {
|
2910
|
-
"style": "vivid"
|
2911
|
-
}
|
3008
|
+
"openai": {}
|
2912
3009
|
}
|
2913
3010
|
```
|
2914
3011
|
*/
|
2915
3012
|
providerOptions?: ProviderOptions;
|
2916
3013
|
/**
|
2917
|
-
Maximum number of retries per
|
3014
|
+
Maximum number of retries per speech model call. Set to 0 to disable retries.
|
2918
3015
|
|
2919
3016
|
@default 2
|
2920
3017
|
*/
|
@@ -2928,1009 +3025,941 @@ declare function generateImage({ model, prompt, n, maxImagesPerCall, size, aspec
|
|
2928
3025
|
Only applicable for HTTP-based providers.
|
2929
3026
|
*/
|
2930
3027
|
headers?: Record<string, string>;
|
2931
|
-
}): Promise<
|
3028
|
+
}): Promise<SpeechResult>;
|
2932
3029
|
|
2933
3030
|
/**
|
2934
|
-
|
3031
|
+
* Applies default settings for a language model.
|
2935
3032
|
*/
|
2936
|
-
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
|
2943
|
-
|
2944
|
-
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
2951
|
-
|
2952
|
-
|
2953
|
-
/**
|
2954
|
-
Additional request information.
|
2955
|
-
*/
|
2956
|
-
readonly request: LanguageModelRequestMetadata;
|
2957
|
-
/**
|
2958
|
-
Additional response information.
|
2959
|
-
*/
|
2960
|
-
readonly response: LanguageModelResponseMetadata & {
|
2961
|
-
/**
|
2962
|
-
Response body (available only for providers that use HTTP requests).
|
2963
|
-
*/
|
2964
|
-
body?: unknown;
|
2965
|
-
};
|
2966
|
-
/**
|
2967
|
-
Additional provider-specific metadata. They are passed through
|
2968
|
-
from the provider to the AI SDK and enable provider-specific
|
2969
|
-
results that can be fully encapsulated in the provider.
|
2970
|
-
*/
|
2971
|
-
readonly providerMetadata: ProviderMetadata | undefined;
|
2972
|
-
/**
|
2973
|
-
Converts the object to a JSON response.
|
2974
|
-
The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
|
2975
|
-
*/
|
2976
|
-
toJsonResponse(init?: ResponseInit): Response;
|
2977
|
-
}
|
3033
|
+
declare function defaultSettingsMiddleware({ settings, }: {
|
3034
|
+
settings: Partial<{
|
3035
|
+
maxOutputTokens?: LanguageModelV2CallOptions['maxOutputTokens'];
|
3036
|
+
temperature?: LanguageModelV2CallOptions['temperature'];
|
3037
|
+
stopSequences?: LanguageModelV2CallOptions['stopSequences'];
|
3038
|
+
topP?: LanguageModelV2CallOptions['topP'];
|
3039
|
+
topK?: LanguageModelV2CallOptions['topK'];
|
3040
|
+
presencePenalty?: LanguageModelV2CallOptions['presencePenalty'];
|
3041
|
+
frequencyPenalty?: LanguageModelV2CallOptions['frequencyPenalty'];
|
3042
|
+
responseFormat?: LanguageModelV2CallOptions['responseFormat'];
|
3043
|
+
seed?: LanguageModelV2CallOptions['seed'];
|
3044
|
+
tools?: LanguageModelV2CallOptions['tools'];
|
3045
|
+
toolChoice?: LanguageModelV2CallOptions['toolChoice'];
|
3046
|
+
headers?: LanguageModelV2CallOptions['headers'];
|
3047
|
+
providerOptions?: LanguageModelV2CallOptions['providerOptions'];
|
3048
|
+
}>;
|
3049
|
+
}): LanguageModelV2Middleware;
|
2978
3050
|
|
2979
3051
|
/**
|
2980
|
-
|
2981
|
-
|
3052
|
+
* Extract an XML-tagged reasoning section from the generated text and exposes it
|
3053
|
+
* as a `reasoning` property on the result.
|
3054
|
+
*
|
3055
|
+
* @param tagName - The name of the XML tag to extract reasoning from.
|
3056
|
+
* @param separator - The separator to use between reasoning and text sections.
|
3057
|
+
* @param startWithReasoning - Whether to start with reasoning tokens.
|
3058
|
+
*/
|
3059
|
+
declare function extractReasoningMiddleware({ tagName, separator, startWithReasoning, }: {
|
3060
|
+
tagName: string;
|
3061
|
+
separator?: string;
|
3062
|
+
startWithReasoning?: boolean;
|
3063
|
+
}): LanguageModelV2Middleware;
|
2982
3064
|
|
2983
|
-
Should return the repaired text or null if the text cannot be repaired.
|
2984
|
-
*/
|
2985
|
-
type RepairTextFunction = (options: {
|
2986
|
-
text: string;
|
2987
|
-
error: JSONParseError | TypeValidationError;
|
2988
|
-
}) => Promise<string | null>;
|
2989
3065
|
/**
|
2990
|
-
|
2991
|
-
|
2992
|
-
|
2993
|
-
|
2994
|
-
@param model - The language model to use.
|
2995
|
-
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
3066
|
+
* Simulates streaming chunks with the response from a generate call.
|
3067
|
+
*/
|
3068
|
+
declare function simulateStreamingMiddleware(): LanguageModelV2Middleware;
|
2996
3069
|
|
2997
|
-
|
2998
|
-
|
2999
|
-
|
3070
|
+
/**
|
3071
|
+
* Wraps a LanguageModelV2 instance with middleware functionality.
|
3072
|
+
* This function allows you to apply middleware to transform parameters,
|
3073
|
+
* wrap generate operations, and wrap stream operations of a language model.
|
3074
|
+
*
|
3075
|
+
* @param options - Configuration options for wrapping the language model.
|
3076
|
+
* @param options.model - The original LanguageModelV2 instance to be wrapped.
|
3077
|
+
* @param options.middleware - The middleware to be applied to the language model. When multiple middlewares are provided, the first middleware will transform the input first, and the last middleware will be wrapped directly around the model.
|
3078
|
+
* @param options.modelId - Optional custom model ID to override the original model's ID.
|
3079
|
+
* @param options.providerId - Optional custom provider ID to override the original model's provider.
|
3080
|
+
* @returns A new LanguageModelV2 instance with middleware applied.
|
3081
|
+
*/
|
3082
|
+
declare const wrapLanguageModel: ({ model, middleware: middlewareArg, modelId, providerId, }: {
|
3083
|
+
model: LanguageModelV2;
|
3084
|
+
middleware: LanguageModelV2Middleware | LanguageModelV2Middleware[];
|
3085
|
+
modelId?: string;
|
3086
|
+
providerId?: string;
|
3087
|
+
}) => LanguageModelV2;
|
3000
3088
|
|
3001
|
-
|
3002
|
-
|
3003
|
-
|
3004
|
-
|
3005
|
-
@param
|
3006
|
-
|
3007
|
-
|
3008
|
-
@param
|
3009
|
-
|
3010
|
-
|
3011
|
-
@
|
3012
|
-
|
3013
|
-
|
3014
|
-
|
3015
|
-
|
3016
|
-
|
3017
|
-
|
3018
|
-
|
3019
|
-
|
3020
|
-
|
3021
|
-
|
3022
|
-
|
3023
|
-
|
3024
|
-
|
3025
|
-
|
3026
|
-
|
3027
|
-
|
3028
|
-
|
3029
|
-
|
3030
|
-
|
3031
|
-
|
3032
|
-
|
3089
|
+
/**
|
3090
|
+
* Creates a custom provider with specified language models, text embedding models, image models, transcription models, speech models, and an optional fallback provider.
|
3091
|
+
*
|
3092
|
+
* @param {Object} options - The options for creating the custom provider.
|
3093
|
+
* @param {Record<string, LanguageModel>} [options.languageModels] - A record of language models, where keys are model IDs and values are LanguageModel instances.
|
3094
|
+
* @param {Record<string, EmbeddingModel<string>>} [options.textEmbeddingModels] - A record of text embedding models, where keys are model IDs and values are EmbeddingModel<string> instances.
|
3095
|
+
* @param {Record<string, ImageModel>} [options.imageModels] - A record of image models, where keys are model IDs and values are ImageModel instances.
|
3096
|
+
* @param {Record<string, TranscriptionModel>} [options.transcriptionModels] - A record of transcription models, where keys are model IDs and values are TranscriptionModel instances.
|
3097
|
+
* @param {Record<string, SpeechModel>} [options.speechModels] - A record of speech models, where keys are model IDs and values are SpeechModel instances.
|
3098
|
+
* @param {Provider} [options.fallbackProvider] - An optional fallback provider to use when a requested model is not found in the custom provider.
|
3099
|
+
* @returns {Provider} A Provider object with languageModel, textEmbeddingModel, imageModel, transcriptionModel, and speechModel methods.
|
3100
|
+
*
|
3101
|
+
* @throws {NoSuchModelError} Throws when a requested model is not found and no fallback provider is available.
|
3102
|
+
*/
|
3103
|
+
declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageModelV2>, EMBEDDING_MODELS extends Record<string, EmbeddingModelV2<string>>, IMAGE_MODELS extends Record<string, ImageModelV2>, TRANSCRIPTION_MODELS extends Record<string, TranscriptionModelV2>, SPEECH_MODELS extends Record<string, SpeechModelV2>>({ languageModels, textEmbeddingModels, imageModels, transcriptionModels, speechModels, fallbackProvider, }: {
|
3104
|
+
languageModels?: LANGUAGE_MODELS;
|
3105
|
+
textEmbeddingModels?: EMBEDDING_MODELS;
|
3106
|
+
imageModels?: IMAGE_MODELS;
|
3107
|
+
transcriptionModels?: TRANSCRIPTION_MODELS;
|
3108
|
+
speechModels?: SPEECH_MODELS;
|
3109
|
+
fallbackProvider?: ProviderV2;
|
3110
|
+
}): ProviderV2 & {
|
3111
|
+
languageModel(modelId: ExtractModelId<LANGUAGE_MODELS>): LanguageModelV2;
|
3112
|
+
textEmbeddingModel(modelId: ExtractModelId<EMBEDDING_MODELS>): EmbeddingModelV2<string>;
|
3113
|
+
imageModel(modelId: ExtractModelId<IMAGE_MODELS>): ImageModelV2;
|
3114
|
+
transcriptionModel(modelId: ExtractModelId<TRANSCRIPTION_MODELS>): TranscriptionModelV2;
|
3115
|
+
speechModel(modelId: ExtractModelId<SPEECH_MODELS>): SpeechModelV2;
|
3116
|
+
};
|
3117
|
+
/**
|
3118
|
+
* @deprecated Use `customProvider` instead.
|
3119
|
+
*/
|
3120
|
+
declare const experimental_customProvider: typeof customProvider;
|
3121
|
+
type ExtractModelId<MODELS extends Record<string, unknown>> = Extract<keyof MODELS, string>;
|
3033
3122
|
|
3034
|
-
|
3123
|
+
declare const symbol: unique symbol;
|
3124
|
+
declare class NoSuchProviderError extends NoSuchModelError {
|
3125
|
+
private readonly [symbol];
|
3126
|
+
readonly providerId: string;
|
3127
|
+
readonly availableProviders: string[];
|
3128
|
+
constructor({ modelId, modelType, providerId, availableProviders, message, }: {
|
3129
|
+
modelId: string;
|
3130
|
+
modelType: 'languageModel' | 'textEmbeddingModel' | 'imageModel' | 'transcriptionModel' | 'speechModel';
|
3131
|
+
providerId: string;
|
3132
|
+
availableProviders: string[];
|
3133
|
+
message?: string;
|
3134
|
+
});
|
3135
|
+
static isInstance(error: unknown): error is NoSuchProviderError;
|
3136
|
+
}
|
3035
3137
|
|
3036
|
-
|
3037
|
-
|
3038
|
-
|
3039
|
-
|
3138
|
+
type ExtractLiteralUnion<T> = T extends string ? string extends T ? never : T : never;
|
3139
|
+
interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV2> = Record<string, ProviderV2>, SEPARATOR extends string = ':'> {
|
3140
|
+
languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['languageModel']>>[0]>}` : never): LanguageModelV2;
|
3141
|
+
languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): LanguageModelV2;
|
3142
|
+
textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['textEmbeddingModel']>>[0]>}` : never): EmbeddingModelV2<string>;
|
3143
|
+
textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): EmbeddingModelV2<string>;
|
3144
|
+
imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['imageModel']>>[0]>}` : never): ImageModelV2;
|
3145
|
+
imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): ImageModelV2;
|
3146
|
+
transcriptionModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['transcriptionModel']>>[0]>}` : never): TranscriptionModelV2;
|
3147
|
+
transcriptionModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): TranscriptionModelV2;
|
3148
|
+
speechModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['speechModel']>>[0]>}` : never): SpeechModelV2;
|
3149
|
+
speechModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): SpeechModelV2;
|
3150
|
+
}
|
3151
|
+
/**
|
3152
|
+
* Creates a registry for the given providers.
|
3153
|
+
*/
|
3154
|
+
declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV2>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, }?: {
|
3155
|
+
separator?: SEPARATOR;
|
3156
|
+
}): ProviderRegistryProvider<PROVIDERS, SEPARATOR>;
|
3157
|
+
/**
|
3158
|
+
* @deprecated Use `createProviderRegistry` instead.
|
3159
|
+
*/
|
3160
|
+
declare const experimental_createProviderRegistry: typeof createProviderRegistry;
|
3040
3161
|
|
3041
|
-
|
3042
|
-
|
3162
|
+
declare function createTextStreamResponse({ status, statusText, headers, textStream, }: ResponseInit & {
|
3163
|
+
textStream: ReadableStream<string>;
|
3164
|
+
}): Response;
|
3043
3165
|
|
3044
|
-
|
3166
|
+
declare function pipeTextStreamToResponse({ response, status, statusText, headers, textStream, }: {
|
3167
|
+
response: ServerResponse;
|
3168
|
+
textStream: ReadableStream<string>;
|
3169
|
+
} & ResponseInit): void;
|
3045
3170
|
|
3046
|
-
|
3047
|
-
|
3048
|
-
|
3171
|
+
declare const JSONRPCRequestSchema: z.ZodObject<{
|
3172
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
3173
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
3174
|
+
method: z.ZodString;
|
3175
|
+
params: z.ZodOptional<z.ZodObject<{
|
3176
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3177
|
+
}, z.core.$loose>>;
|
3178
|
+
}, z.core.$strict>;
|
3179
|
+
type JSONRPCRequest = z.infer<typeof JSONRPCRequestSchema>;
|
3180
|
+
declare const JSONRPCResponseSchema: z.ZodObject<{
|
3181
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
3182
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
3183
|
+
result: z.ZodObject<{
|
3184
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3185
|
+
}, z.core.$loose>;
|
3186
|
+
}, z.core.$strict>;
|
3187
|
+
type JSONRPCResponse = z.infer<typeof JSONRPCResponseSchema>;
|
3188
|
+
declare const JSONRPCErrorSchema: z.ZodObject<{
|
3189
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
3190
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
3191
|
+
error: z.ZodObject<{
|
3192
|
+
code: z.ZodNumber;
|
3193
|
+
message: z.ZodString;
|
3194
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
3195
|
+
}, z.core.$strip>;
|
3196
|
+
}, z.core.$strict>;
|
3197
|
+
type JSONRPCError = z.infer<typeof JSONRPCErrorSchema>;
|
3198
|
+
declare const JSONRPCNotificationSchema: z.ZodObject<{
|
3199
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
3200
|
+
method: z.ZodString;
|
3201
|
+
params: z.ZodOptional<z.ZodObject<{
|
3202
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3203
|
+
}, z.core.$loose>>;
|
3204
|
+
}, z.core.$strict>;
|
3205
|
+
type JSONRPCNotification = z.infer<typeof JSONRPCNotificationSchema>;
|
3206
|
+
declare const JSONRPCMessageSchema: z.ZodUnion<readonly [z.ZodObject<{
|
3207
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
3208
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
3209
|
+
method: z.ZodString;
|
3210
|
+
params: z.ZodOptional<z.ZodObject<{
|
3211
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3212
|
+
}, z.core.$loose>>;
|
3213
|
+
}, z.core.$strict>, z.ZodObject<{
|
3214
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
3215
|
+
method: z.ZodString;
|
3216
|
+
params: z.ZodOptional<z.ZodObject<{
|
3217
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3218
|
+
}, z.core.$loose>>;
|
3219
|
+
}, z.core.$strict>, z.ZodObject<{
|
3220
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
3221
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
3222
|
+
result: z.ZodObject<{
|
3223
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3224
|
+
}, z.core.$loose>;
|
3225
|
+
}, z.core.$strict>, z.ZodObject<{
|
3226
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
3227
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
3228
|
+
error: z.ZodObject<{
|
3229
|
+
code: z.ZodNumber;
|
3230
|
+
message: z.ZodString;
|
3231
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
3232
|
+
}, z.core.$strip>;
|
3233
|
+
}, z.core.$strict>]>;
|
3234
|
+
type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
|
3049
3235
|
|
3050
|
-
|
3051
|
-
|
3236
|
+
/**
|
3237
|
+
* Transport interface for MCP (Model Context Protocol) communication.
|
3238
|
+
* Maps to the `Transport` interface in the MCP spec.
|
3052
3239
|
*/
|
3053
|
-
|
3054
|
-
/**
|
3055
|
-
The enum values that the model should use.
|
3056
|
-
*/
|
3057
|
-
enum: Array<RESULT>;
|
3058
|
-
mode?: 'json';
|
3059
|
-
output: 'enum';
|
3060
|
-
} : OUTPUT extends 'no-schema' ? {} : {
|
3061
|
-
/**
|
3062
|
-
The schema of the object that the model should generate.
|
3063
|
-
*/
|
3064
|
-
schema: SCHEMA;
|
3240
|
+
interface MCPTransport {
|
3065
3241
|
/**
|
3066
|
-
|
3067
|
-
|
3068
|
-
|
3069
|
-
*/
|
3070
|
-
schemaName?: string;
|
3242
|
+
* Initialize and start the transport
|
3243
|
+
*/
|
3244
|
+
start(): Promise<void>;
|
3071
3245
|
/**
|
3072
|
-
|
3073
|
-
|
3074
|
-
|
3075
|
-
|
3076
|
-
schemaDescription?: string;
|
3246
|
+
* Send a JSON-RPC message through the transport
|
3247
|
+
* @param message The JSON-RPC message to send
|
3248
|
+
*/
|
3249
|
+
send(message: JSONRPCMessage): Promise<void>;
|
3077
3250
|
/**
|
3078
|
-
|
3079
|
-
|
3080
|
-
|
3081
|
-
|
3082
|
-
- 'auto': The provider will choose the best mode for the model.
|
3083
|
-
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
3084
|
-
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
3085
|
-
|
3086
|
-
Please note that most providers do not support all modes.
|
3087
|
-
|
3088
|
-
Default and recommended: 'auto' (best mode for the model).
|
3089
|
-
*/
|
3090
|
-
mode?: 'auto' | 'json' | 'tool';
|
3091
|
-
}) & {
|
3092
|
-
output?: OUTPUT;
|
3251
|
+
* Clean up and close the transport
|
3252
|
+
*/
|
3253
|
+
close(): Promise<void>;
|
3093
3254
|
/**
|
3094
|
-
|
3255
|
+
* Event handler for transport closure
|
3095
3256
|
*/
|
3096
|
-
|
3257
|
+
onclose?: () => void;
|
3097
3258
|
/**
|
3098
|
-
|
3099
|
-
to enable JSON parsing.
|
3259
|
+
* Event handler for transport errors
|
3100
3260
|
*/
|
3101
|
-
|
3261
|
+
onerror?: (error: Error) => void;
|
3102
3262
|
/**
|
3103
|
-
|
3104
|
-
|
3105
|
-
|
3263
|
+
* Event handler for received messages
|
3264
|
+
*/
|
3265
|
+
onmessage?: (message: JSONRPCMessage) => void;
|
3266
|
+
}
|
3267
|
+
type MCPTransportConfig = {
|
3268
|
+
type: 'sse';
|
3106
3269
|
/**
|
3107
|
-
|
3108
|
-
|
3109
|
-
|
3110
|
-
*/
|
3111
|
-
providerOptions?: ProviderOptions;
|
3270
|
+
* The URL of the MCP server.
|
3271
|
+
*/
|
3272
|
+
url: string;
|
3112
3273
|
/**
|
3113
|
-
*
|
3274
|
+
* Additional HTTP headers to be sent with requests.
|
3114
3275
|
*/
|
3115
|
-
|
3116
|
-
|
3117
|
-
|
3118
|
-
|
3119
|
-
|
3276
|
+
headers?: Record<string, string>;
|
3277
|
+
};
|
3278
|
+
|
3279
|
+
type ToolSchemas = Record<string, {
|
3280
|
+
inputSchema: FlexibleSchema<JSONObject | unknown>;
|
3281
|
+
}> | 'automatic' | undefined;
|
3282
|
+
type MappedTool<T extends Tool | JSONObject, OUTPUT extends any> = T extends Tool<infer INPUT> ? Tool<INPUT, OUTPUT> : T extends JSONObject ? Tool<T, OUTPUT> : never;
|
3283
|
+
type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> = TOOL_SCHEMAS extends Record<string, {
|
3284
|
+
inputSchema: FlexibleSchema<unknown>;
|
3285
|
+
}> ? {
|
3286
|
+
[K in keyof TOOL_SCHEMAS]: MappedTool<TOOL_SCHEMAS[K], CallToolResult> & Required<Pick<MappedTool<TOOL_SCHEMAS[K], CallToolResult>, 'execute'>>;
|
3287
|
+
} : McpToolSet<Record<string, {
|
3288
|
+
inputSchema: FlexibleSchema<unknown>;
|
3289
|
+
}>>;
|
3290
|
+
declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
|
3291
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3292
|
+
content: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
3293
|
+
type: z.ZodLiteral<"text">;
|
3294
|
+
text: z.ZodString;
|
3295
|
+
}, z.core.$loose>, z.ZodObject<{
|
3296
|
+
type: z.ZodLiteral<"image">;
|
3297
|
+
data: z.ZodString;
|
3298
|
+
mimeType: z.ZodString;
|
3299
|
+
}, z.core.$loose>, z.ZodObject<{
|
3300
|
+
type: z.ZodLiteral<"resource">;
|
3301
|
+
resource: z.ZodUnion<readonly [z.ZodObject<{
|
3302
|
+
uri: z.ZodString;
|
3303
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
3304
|
+
text: z.ZodString;
|
3305
|
+
}, z.core.$loose>, z.ZodObject<{
|
3306
|
+
uri: z.ZodString;
|
3307
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
3308
|
+
blob: z.ZodString;
|
3309
|
+
}, z.core.$loose>]>;
|
3310
|
+
}, z.core.$loose>]>>;
|
3311
|
+
isError: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
3312
|
+
}, z.core.$loose>, z.ZodObject<{
|
3313
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3314
|
+
toolResult: z.ZodUnknown;
|
3315
|
+
}, z.core.$loose>]>;
|
3316
|
+
type CallToolResult = z.infer<typeof CallToolResultSchema>;
|
3120
3317
|
|
3318
|
+
interface MCPClientConfig {
|
3319
|
+
/** Transport configuration for connecting to the MCP server */
|
3320
|
+
transport: MCPTransportConfig | MCPTransport;
|
3321
|
+
/** Optional callback for uncaught errors */
|
3322
|
+
onUncaughtError?: (error: unknown) => void;
|
3323
|
+
/** Optional client name, defaults to 'ai-sdk-mcp-client' */
|
3324
|
+
name?: string;
|
3325
|
+
}
|
3326
|
+
declare function createMCPClient(config: MCPClientConfig): Promise<MCPClient>;
|
3121
3327
|
/**
|
3122
|
-
|
3328
|
+
* A lightweight MCP Client implementation
|
3329
|
+
*
|
3330
|
+
* The primary purpose of this client is tool conversion between MCP<>AI SDK
|
3331
|
+
* but can later be extended to support other MCP features
|
3332
|
+
*
|
3333
|
+
* Tool parameters are automatically inferred from the server's JSON schema
|
3334
|
+
* if not explicitly provided in the tools configuration
|
3335
|
+
*
|
3336
|
+
* This client is meant to be used to communicate with a single server. To communicate and fetch tools across multiple servers, it's recommended to create a new client instance per server.
|
3337
|
+
*
|
3338
|
+
* Not supported:
|
3339
|
+
* - Client options (e.g. sampling, roots) as they are not needed for tool conversion
|
3340
|
+
* - Accepting notifications
|
3341
|
+
* - Session management (when passing a sessionId to an instance of the Streamable HTTP transport)
|
3342
|
+
* - Resumable SSE streams
|
3123
3343
|
*/
|
3124
|
-
|
3125
|
-
|
3126
|
-
|
3127
|
-
|
3128
|
-
|
3129
|
-
|
3130
|
-
|
3131
|
-
|
3132
|
-
|
3344
|
+
declare class MCPClient {
|
3345
|
+
private transport;
|
3346
|
+
private onUncaughtError?;
|
3347
|
+
private clientInfo;
|
3348
|
+
private requestMessageId;
|
3349
|
+
private responseHandlers;
|
3350
|
+
private serverCapabilities;
|
3351
|
+
private isClosed;
|
3352
|
+
constructor({ transport: transportConfig, name, onUncaughtError, }: MCPClientConfig);
|
3353
|
+
init(): Promise<this>;
|
3354
|
+
close(): Promise<void>;
|
3355
|
+
private assertCapability;
|
3356
|
+
private request;
|
3357
|
+
private listTools;
|
3358
|
+
private callTool;
|
3359
|
+
private notification;
|
3133
3360
|
/**
|
3134
|
-
|
3135
|
-
|
3136
|
-
results that can be fully encapsulated in the provider.
|
3361
|
+
* Returns a set of AI SDK tools from the MCP server
|
3362
|
+
* @returns A record of tool names to their implementations
|
3137
3363
|
*/
|
3138
|
-
|
3139
|
-
|
3140
|
-
|
3141
|
-
|
3142
|
-
|
3143
|
-
|
3144
|
-
|
3145
|
-
|
3146
|
-
|
3364
|
+
tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>({ schemas, }?: {
|
3365
|
+
schemas?: TOOL_SCHEMAS;
|
3366
|
+
}): Promise<McpToolSet<TOOL_SCHEMAS>>;
|
3367
|
+
private onClose;
|
3368
|
+
private onError;
|
3369
|
+
private onResponse;
|
3370
|
+
}
|
3371
|
+
|
3372
|
+
/**
|
3373
|
+
The result of a `transcribe` call.
|
3374
|
+
It contains the transcript and additional information.
|
3375
|
+
*/
|
3376
|
+
interface TranscriptionResult {
|
3147
3377
|
/**
|
3148
|
-
|
3149
|
-
|
3150
|
-
readonly
|
3378
|
+
* The complete transcribed text from the audio.
|
3379
|
+
*/
|
3380
|
+
readonly text: string;
|
3151
3381
|
/**
|
3152
|
-
|
3153
|
-
|
3154
|
-
|
3155
|
-
|
3156
|
-
|
3157
|
-
|
3382
|
+
* Array of transcript segments with timing information.
|
3383
|
+
* Each segment represents a portion of the transcribed text with start and end times.
|
3384
|
+
*/
|
3385
|
+
readonly segments: Array<{
|
3386
|
+
/**
|
3387
|
+
* The text content of this segment.
|
3388
|
+
*/
|
3389
|
+
readonly text: string;
|
3390
|
+
/**
|
3391
|
+
* The start time of this segment in seconds.
|
3392
|
+
*/
|
3393
|
+
readonly startSecond: number;
|
3394
|
+
/**
|
3395
|
+
* The end time of this segment in seconds.
|
3396
|
+
*/
|
3397
|
+
readonly endSecond: number;
|
3398
|
+
}>;
|
3158
3399
|
/**
|
3159
|
-
*
|
3400
|
+
* The detected language of the audio content, as an ISO-639-1 code (e.g., 'en' for English).
|
3401
|
+
* May be undefined if the language couldn't be detected.
|
3160
3402
|
*/
|
3161
|
-
readonly
|
3403
|
+
readonly language: string | undefined;
|
3162
3404
|
/**
|
3163
|
-
|
3164
|
-
|
3165
|
-
|
3166
|
-
readonly
|
3405
|
+
* The total duration of the audio file in seconds.
|
3406
|
+
* May be undefined if the duration couldn't be determined.
|
3407
|
+
*/
|
3408
|
+
readonly durationInSeconds: number | undefined;
|
3167
3409
|
/**
|
3168
|
-
|
3169
|
-
Only errors that stop the stream, such as network errors, are thrown.
|
3410
|
+
Warnings for the call, e.g. unsupported settings.
|
3170
3411
|
*/
|
3171
|
-
readonly
|
3412
|
+
readonly warnings: Array<TranscriptionWarning>;
|
3172
3413
|
/**
|
3173
|
-
|
3174
|
-
|
3175
|
-
|
3176
|
-
|
3177
|
-
@param response A Node.js response-like object (ServerResponse).
|
3178
|
-
@param init Optional headers, status code, and status text.
|
3179
|
-
*/
|
3180
|
-
pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): void;
|
3414
|
+
Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
3415
|
+
*/
|
3416
|
+
readonly responses: Array<TranscriptionModelResponseMetadata>;
|
3181
3417
|
/**
|
3182
|
-
|
3183
|
-
|
3184
|
-
|
3185
|
-
Non-text-delta events are ignored.
|
3186
|
-
|
3187
|
-
@param init Optional headers, status code, and status text.
|
3188
|
-
*/
|
3189
|
-
toTextStreamResponse(init?: ResponseInit): Response;
|
3418
|
+
Provider metadata from the provider.
|
3419
|
+
*/
|
3420
|
+
readonly providerMetadata: Record<string, Record<string, JSONValue$1>>;
|
3190
3421
|
}
|
3191
|
-
type ObjectStreamPart<PARTIAL> = {
|
3192
|
-
type: 'object';
|
3193
|
-
object: PARTIAL;
|
3194
|
-
} | {
|
3195
|
-
type: 'text-delta';
|
3196
|
-
textDelta: string;
|
3197
|
-
} | {
|
3198
|
-
type: 'error';
|
3199
|
-
error: unknown;
|
3200
|
-
} | {
|
3201
|
-
type: 'finish';
|
3202
|
-
finishReason: FinishReason;
|
3203
|
-
usage: LanguageModelUsage;
|
3204
|
-
response: LanguageModelResponseMetadata;
|
3205
|
-
providerMetadata?: ProviderMetadata;
|
3206
|
-
};
|
3207
3422
|
|
3208
3423
|
/**
|
3209
|
-
|
3424
|
+
Generates transcripts using a transcription model.
|
3210
3425
|
|
3211
|
-
@param
|
3212
|
-
|
3213
|
-
|
3214
|
-
|
3215
|
-
|
3216
|
-
|
3217
|
-
|
3426
|
+
@param model - The transcription model to use.
|
3427
|
+
@param audio - The audio data to transcribe as DataContent (string | Uint8Array | ArrayBuffer | Buffer) or a URL.
|
3428
|
+
@param providerOptions - Additional provider-specific options that are passed through to the provider
|
3429
|
+
as body parameters.
|
3430
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
3431
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
3432
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
3218
3433
|
|
3219
|
-
@
|
3434
|
+
@returns A result object that contains the generated transcript.
|
3220
3435
|
*/
|
3221
|
-
|
3222
|
-
/**
|
3223
|
-
The token usage of the generated response.
|
3224
|
-
*/
|
3225
|
-
usage: LanguageModelUsage;
|
3436
|
+
declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
|
3226
3437
|
/**
|
3227
|
-
The
|
3228
|
-
|
3229
|
-
|
3438
|
+
The transcription model to use.
|
3439
|
+
*/
|
3440
|
+
model: TranscriptionModelV2;
|
3230
3441
|
/**
|
3231
|
-
|
3232
|
-
|
3233
|
-
|
3442
|
+
The audio data to transcribe.
|
3443
|
+
*/
|
3444
|
+
audio: DataContent | URL;
|
3234
3445
|
/**
|
3235
|
-
|
3236
|
-
|
3237
|
-
|
3446
|
+
Additional provider-specific options that are passed through to the provider
|
3447
|
+
as body parameters.
|
3448
|
+
|
3449
|
+
The outer record is keyed by the provider name, and the inner
|
3450
|
+
record is keyed by the provider-specific metadata key.
|
3451
|
+
```ts
|
3452
|
+
{
|
3453
|
+
"openai": {
|
3454
|
+
"temperature": 0
|
3455
|
+
}
|
3456
|
+
}
|
3457
|
+
```
|
3458
|
+
*/
|
3459
|
+
providerOptions?: ProviderOptions;
|
3238
3460
|
/**
|
3239
|
-
|
3240
|
-
|
3241
|
-
|
3242
|
-
|
3243
|
-
|
3244
|
-
to the provider from the AI SDK and enable provider-specific
|
3245
|
-
functionality that can be fully encapsulated in the provider.
|
3246
|
-
*/
|
3247
|
-
providerMetadata: ProviderMetadata | undefined;
|
3248
|
-
}) => Promise<void> | void;
|
3249
|
-
/**
|
3250
|
-
Generate a structured, typed object for a given prompt and schema using a language model.
|
3251
|
-
|
3252
|
-
This function streams the output. If you do not want to stream the output, use `generateObject` instead.
|
3253
|
-
|
3254
|
-
@param model - The language model to use.
|
3255
|
-
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
3256
|
-
|
3257
|
-
@param system - A system message that will be part of the prompt.
|
3258
|
-
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
3259
|
-
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
3260
|
-
|
3261
|
-
@param maxOutputTokens - Maximum number of tokens to generate.
|
3262
|
-
@param temperature - Temperature setting.
|
3263
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
3264
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
3265
|
-
@param topP - Nucleus sampling.
|
3266
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
3267
|
-
It is recommended to set either `temperature` or `topP`, but not both.
|
3268
|
-
@param topK - Only sample from the top K options for each subsequent token.
|
3269
|
-
Used to remove "long tail" low probability responses.
|
3270
|
-
Recommended for advanced use cases only. You usually only need to use temperature.
|
3271
|
-
@param presencePenalty - Presence penalty setting.
|
3272
|
-
It affects the likelihood of the model to repeat information that is already in the prompt.
|
3273
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
3274
|
-
@param frequencyPenalty - Frequency penalty setting.
|
3275
|
-
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
3276
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
3277
|
-
@param stopSequences - Stop sequences.
|
3278
|
-
If set, the model will stop generating text when one of the stop sequences is generated.
|
3279
|
-
@param seed - The seed (integer) to use for random sampling.
|
3280
|
-
If set and supported by the model, calls will generate deterministic results.
|
3281
|
-
|
3282
|
-
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
3283
|
-
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
3284
|
-
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
3285
|
-
|
3286
|
-
@param schema - The schema of the object that the model should generate.
|
3287
|
-
@param schemaName - Optional name of the output that should be generated.
|
3288
|
-
Used by some providers for additional LLM guidance, e.g.
|
3289
|
-
via tool or schema name.
|
3290
|
-
@param schemaDescription - Optional description of the output that should be generated.
|
3291
|
-
Used by some providers for additional LLM guidance, e.g.
|
3292
|
-
via tool or schema description.
|
3293
|
-
|
3294
|
-
@param output - The type of the output.
|
3295
|
-
|
3296
|
-
- 'object': The output is an object.
|
3297
|
-
- 'array': The output is an array.
|
3298
|
-
- 'enum': The output is an enum.
|
3299
|
-
- 'no-schema': The output is not a schema.
|
3300
|
-
|
3301
|
-
@param experimental_telemetry - Optional telemetry configuration (experimental).
|
3302
|
-
|
3303
|
-
@param providerOptions - Additional provider-specific options. They are passed through
|
3304
|
-
to the provider from the AI SDK and enable provider-specific
|
3305
|
-
functionality that can be fully encapsulated in the provider.
|
3306
|
-
|
3307
|
-
@returns
|
3308
|
-
A result object for accessing the partial object stream and additional information.
|
3309
|
-
*/
|
3310
|
-
declare function streamObject<SCHEMA extends z3.Schema | z4$1.ZodType | Schema = z4$1.ZodType<JSONValue$1>, OUTPUT extends 'object' | 'array' | 'enum' | 'no-schema' = InferSchema<SCHEMA> extends string ? 'enum' : 'object', RESULT = OUTPUT extends 'array' ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (OUTPUT extends 'enum' ? {
|
3311
|
-
/**
|
3312
|
-
The enum values that the model should use.
|
3313
|
-
*/
|
3314
|
-
enum: Array<RESULT>;
|
3315
|
-
mode?: 'json';
|
3316
|
-
output: 'enum';
|
3317
|
-
} : OUTPUT extends 'no-schema' ? {} : {
|
3318
|
-
/**
|
3319
|
-
The schema of the object that the model should generate.
|
3320
|
-
*/
|
3321
|
-
schema: SCHEMA;
|
3322
|
-
/**
|
3323
|
-
Optional name of the output that should be generated.
|
3324
|
-
Used by some providers for additional LLM guidance, e.g.
|
3325
|
-
via tool or schema name.
|
3326
|
-
*/
|
3327
|
-
schemaName?: string;
|
3461
|
+
Maximum number of retries per transcript model call. Set to 0 to disable retries.
|
3462
|
+
|
3463
|
+
@default 2
|
3464
|
+
*/
|
3465
|
+
maxRetries?: number;
|
3328
3466
|
/**
|
3329
|
-
|
3330
|
-
|
3331
|
-
|
3332
|
-
*/
|
3333
|
-
schemaDescription?: string;
|
3467
|
+
Abort signal.
|
3468
|
+
*/
|
3469
|
+
abortSignal?: AbortSignal;
|
3334
3470
|
/**
|
3335
|
-
|
3336
|
-
|
3337
|
-
|
3338
|
-
|
3339
|
-
|
3340
|
-
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
3341
|
-
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
3471
|
+
Additional headers to include in the request.
|
3472
|
+
Only applicable for HTTP-based providers.
|
3473
|
+
*/
|
3474
|
+
headers?: Record<string, string>;
|
3475
|
+
}): Promise<TranscriptionResult>;
|
3342
3476
|
|
3343
|
-
|
3477
|
+
declare const getOriginalFetch: () => typeof fetch;
|
3478
|
+
declare function callCompletionApi({ api, prompt, credentials, headers, body, streamProtocol, setCompletion, setLoading, setError, setAbortController, onFinish, onError, fetch, }: {
|
3479
|
+
api: string;
|
3480
|
+
prompt: string;
|
3481
|
+
credentials: RequestCredentials | undefined;
|
3482
|
+
headers: HeadersInit | undefined;
|
3483
|
+
body: Record<string, any>;
|
3484
|
+
streamProtocol: 'data' | 'text' | undefined;
|
3485
|
+
setCompletion: (completion: string) => void;
|
3486
|
+
setLoading: (loading: boolean) => void;
|
3487
|
+
setError: (error: Error | undefined) => void;
|
3488
|
+
setAbortController: (abortController: AbortController | null) => void;
|
3489
|
+
onFinish: ((prompt: string, completion: string) => void) | undefined;
|
3490
|
+
onError: ((error: Error) => void) | undefined;
|
3491
|
+
fetch: ReturnType<typeof getOriginalFetch> | undefined;
|
3492
|
+
}): Promise<string | null | undefined>;
|
3344
3493
|
|
3345
|
-
|
3346
|
-
*/
|
3347
|
-
mode?: 'auto' | 'json' | 'tool';
|
3348
|
-
}) & {
|
3349
|
-
output?: OUTPUT;
|
3350
|
-
/**
|
3351
|
-
The language model to use.
|
3352
|
-
*/
|
3353
|
-
model: LanguageModel;
|
3494
|
+
interface UIMessageStreamWriter<UI_MESSAGE extends UIMessage = UIMessage> {
|
3354
3495
|
/**
|
3355
|
-
|
3496
|
+
* Appends a data stream part to the stream.
|
3356
3497
|
*/
|
3357
|
-
|
3358
|
-
/**
|
3359
|
-
Additional provider-specific options. They are passed through
|
3360
|
-
to the provider from the AI SDK and enable provider-specific
|
3361
|
-
functionality that can be fully encapsulated in the provider.
|
3362
|
-
*/
|
3363
|
-
providerOptions?: ProviderOptions;
|
3364
|
-
/**
|
3365
|
-
Callback that is invoked when an error occurs during streaming.
|
3366
|
-
You can use it to log errors.
|
3367
|
-
The stream processing will pause until the callback promise is resolved.
|
3368
|
-
*/
|
3369
|
-
onError?: StreamObjectOnErrorCallback;
|
3370
|
-
/**
|
3371
|
-
Callback that is called when the LLM response and the final object validation are finished.
|
3372
|
-
*/
|
3373
|
-
onFinish?: StreamObjectOnFinishCallback<RESULT>;
|
3498
|
+
write(part: InferUIMessageChunk<UI_MESSAGE>): void;
|
3374
3499
|
/**
|
3375
|
-
*
|
3500
|
+
* Merges the contents of another stream to this stream.
|
3376
3501
|
*/
|
3377
|
-
|
3378
|
-
generateId?: () => string;
|
3379
|
-
currentDate?: () => Date;
|
3380
|
-
now?: () => number;
|
3381
|
-
};
|
3382
|
-
}): StreamObjectResult<OUTPUT extends 'enum' ? string : OUTPUT extends 'array' ? RESULT : DeepPartial<RESULT>, OUTPUT extends 'array' ? RESULT : RESULT, OUTPUT extends 'array' ? RESULT extends Array<infer U> ? AsyncIterableStream<U> : never : never>;
|
3383
|
-
|
3384
|
-
/**
|
3385
|
-
* A generated audio file.
|
3386
|
-
*/
|
3387
|
-
interface GeneratedAudioFile extends GeneratedFile {
|
3502
|
+
merge(stream: ReadableStream<InferUIMessageChunk<UI_MESSAGE>>): void;
|
3388
3503
|
/**
|
3389
|
-
*
|
3504
|
+
* Error handler that is used by the data stream writer.
|
3505
|
+
* This is intended for forwarding when merging streams
|
3506
|
+
* to prevent duplicated error masking.
|
3390
3507
|
*/
|
3391
|
-
|
3508
|
+
onError: ErrorHandler | undefined;
|
3392
3509
|
}
|
3393
3510
|
|
3394
|
-
|
3395
|
-
|
3396
|
-
|
3397
|
-
|
3398
|
-
|
3399
|
-
/**
|
3400
|
-
* The audio data as a base64 encoded string or binary data.
|
3401
|
-
*/
|
3402
|
-
readonly audio: GeneratedAudioFile;
|
3403
|
-
/**
|
3404
|
-
Warnings for the call, e.g. unsupported settings.
|
3405
|
-
*/
|
3406
|
-
readonly warnings: Array<SpeechWarning>;
|
3407
|
-
/**
|
3408
|
-
Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
3409
|
-
*/
|
3410
|
-
readonly responses: Array<SpeechModelResponseMetadata>;
|
3511
|
+
declare function createUIMessageStream<UI_MESSAGE extends UIMessage>({ execute, onError, originalMessages, onFinish, generateId, }: {
|
3512
|
+
execute: (options: {
|
3513
|
+
writer: UIMessageStreamWriter<UI_MESSAGE>;
|
3514
|
+
}) => Promise<void> | void;
|
3515
|
+
onError?: (error: unknown) => string;
|
3411
3516
|
/**
|
3412
|
-
|
3517
|
+
* The original messages. If they are provided, persistence mode is assumed,
|
3518
|
+
* and a message ID is provided for the response message.
|
3413
3519
|
*/
|
3414
|
-
|
3520
|
+
originalMessages?: UI_MESSAGE[];
|
3521
|
+
onFinish?: (options: {
|
3522
|
+
/**
|
3523
|
+
* The updates list of UI messages.
|
3524
|
+
*/
|
3525
|
+
messages: UI_MESSAGE[];
|
3526
|
+
/**
|
3527
|
+
* Indicates whether the response message is a continuation of the last original message,
|
3528
|
+
* or if a new message was created.
|
3529
|
+
*/
|
3530
|
+
isContinuation: boolean;
|
3531
|
+
/**
|
3532
|
+
* The message that was sent to the client as a response
|
3533
|
+
* (including the original message if it was extended).
|
3534
|
+
*/
|
3535
|
+
responseMessage: UI_MESSAGE;
|
3536
|
+
}) => void;
|
3537
|
+
generateId?: IdGenerator;
|
3538
|
+
}): ReadableStream<InferUIMessageChunk<UI_MESSAGE>>;
|
3539
|
+
|
3540
|
+
declare function createUIMessageStreamResponse({ status, statusText, headers, stream, consumeSseStream, }: UIMessageStreamResponseInit & {
|
3541
|
+
stream: ReadableStream<UIMessageChunk>;
|
3542
|
+
}): Response;
|
3543
|
+
|
3544
|
+
declare class JsonToSseTransformStream extends TransformStream<unknown, string> {
|
3545
|
+
constructor();
|
3415
3546
|
}
|
3416
3547
|
|
3548
|
+
declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, consumeSseStream, }: {
|
3549
|
+
response: ServerResponse;
|
3550
|
+
stream: ReadableStream<UIMessageChunk>;
|
3551
|
+
} & UIMessageStreamResponseInit): void;
|
3552
|
+
|
3417
3553
|
/**
|
3418
|
-
|
3554
|
+
* Transforms a stream of `UIMessageChunk`s into an `AsyncIterableStream` of `UIMessage`s.
|
3555
|
+
*
|
3556
|
+
* @param options.message - The last assistant message to use as a starting point when the conversation is resumed. Otherwise undefined.
|
3557
|
+
* @param options.stream - The stream of `UIMessageChunk`s to read.
|
3558
|
+
*
|
3559
|
+
* @returns An `AsyncIterableStream` of `UIMessage`s. Each stream part is a different state of the same message
|
3560
|
+
* as it is being completed.
|
3561
|
+
*/
|
3562
|
+
declare function readUIMessageStream<UI_MESSAGE extends UIMessage>({ message, stream, }: {
|
3563
|
+
message?: UI_MESSAGE;
|
3564
|
+
stream: ReadableStream<UIMessageChunk>;
|
3565
|
+
}): AsyncIterableStream<UI_MESSAGE>;
|
3419
3566
|
|
3420
|
-
|
3421
|
-
|
3422
|
-
|
3423
|
-
|
3424
|
-
|
3425
|
-
|
3426
|
-
@param providerOptions - Additional provider-specific options that are passed through to the provider
|
3427
|
-
as body parameters.
|
3428
|
-
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
3429
|
-
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
3430
|
-
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
3431
|
-
|
3432
|
-
@returns A result object that contains the generated audio data.
|
3433
|
-
*/
|
3434
|
-
declare function generateSpeech({ model, text, voice, outputFormat, instructions, speed, language, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
|
3435
|
-
/**
|
3436
|
-
The speech model to use.
|
3437
|
-
*/
|
3438
|
-
model: SpeechModelV2;
|
3439
|
-
/**
|
3440
|
-
The text to convert to speech.
|
3441
|
-
*/
|
3442
|
-
text: string;
|
3443
|
-
/**
|
3444
|
-
The voice to use for speech generation.
|
3445
|
-
*/
|
3446
|
-
voice?: string;
|
3447
|
-
/**
|
3448
|
-
* The desired output format for the audio e.g. "mp3", "wav", etc.
|
3449
|
-
*/
|
3450
|
-
outputFormat?: 'mp3' | 'wav' | (string & {});
|
3451
|
-
/**
|
3452
|
-
Instructions for the speech generation e.g. "Speak in a slow and steady tone".
|
3453
|
-
*/
|
3454
|
-
instructions?: string;
|
3455
|
-
/**
|
3456
|
-
The speed of the speech generation.
|
3457
|
-
*/
|
3458
|
-
speed?: number;
|
3459
|
-
/**
|
3460
|
-
The language for speech generation. This should be an ISO 639-1 language code (e.g. "en", "es", "fr")
|
3461
|
-
or "auto" for automatic language detection. Provider support varies.
|
3462
|
-
*/
|
3463
|
-
language?: string;
|
3464
|
-
/**
|
3465
|
-
Additional provider-specific options that are passed through to the provider
|
3466
|
-
as body parameters.
|
3467
|
-
|
3468
|
-
The outer record is keyed by the provider name, and the inner
|
3469
|
-
record is keyed by the provider-specific metadata key.
|
3470
|
-
```ts
|
3471
|
-
{
|
3472
|
-
"openai": {}
|
3473
|
-
}
|
3474
|
-
```
|
3475
|
-
*/
|
3476
|
-
providerOptions?: ProviderOptions;
|
3477
|
-
/**
|
3478
|
-
Maximum number of retries per speech model call. Set to 0 to disable retries.
|
3479
|
-
|
3480
|
-
@default 2
|
3481
|
-
*/
|
3482
|
-
maxRetries?: number;
|
3483
|
-
/**
|
3484
|
-
Abort signal.
|
3485
|
-
*/
|
3486
|
-
abortSignal?: AbortSignal;
|
3487
|
-
/**
|
3488
|
-
Additional headers to include in the request.
|
3489
|
-
Only applicable for HTTP-based providers.
|
3490
|
-
*/
|
3491
|
-
headers?: Record<string, string>;
|
3492
|
-
}): Promise<SpeechResult>;
|
3493
|
-
|
3494
|
-
/**
|
3495
|
-
* Applies default settings for a language model.
|
3496
|
-
*/
|
3497
|
-
declare function defaultSettingsMiddleware({ settings, }: {
|
3498
|
-
settings: Partial<{
|
3499
|
-
maxOutputTokens?: LanguageModelV2CallOptions['maxOutputTokens'];
|
3500
|
-
temperature?: LanguageModelV2CallOptions['temperature'];
|
3501
|
-
stopSequences?: LanguageModelV2CallOptions['stopSequences'];
|
3502
|
-
topP?: LanguageModelV2CallOptions['topP'];
|
3503
|
-
topK?: LanguageModelV2CallOptions['topK'];
|
3504
|
-
presencePenalty?: LanguageModelV2CallOptions['presencePenalty'];
|
3505
|
-
frequencyPenalty?: LanguageModelV2CallOptions['frequencyPenalty'];
|
3506
|
-
responseFormat?: LanguageModelV2CallOptions['responseFormat'];
|
3507
|
-
seed?: LanguageModelV2CallOptions['seed'];
|
3508
|
-
tools?: LanguageModelV2CallOptions['tools'];
|
3509
|
-
toolChoice?: LanguageModelV2CallOptions['toolChoice'];
|
3510
|
-
headers?: LanguageModelV2CallOptions['headers'];
|
3511
|
-
providerOptions?: LanguageModelV2CallOptions['providerOptions'];
|
3512
|
-
}>;
|
3513
|
-
}): LanguageModelV2Middleware;
|
3514
|
-
|
3515
|
-
/**
|
3516
|
-
* Extract an XML-tagged reasoning section from the generated text and exposes it
|
3517
|
-
* as a `reasoning` property on the result.
|
3518
|
-
*
|
3519
|
-
* @param tagName - The name of the XML tag to extract reasoning from.
|
3520
|
-
* @param separator - The separator to use between reasoning and text sections.
|
3521
|
-
* @param startWithReasoning - Whether to start with reasoning tokens.
|
3522
|
-
*/
|
3523
|
-
declare function extractReasoningMiddleware({ tagName, separator, startWithReasoning, }: {
|
3524
|
-
tagName: string;
|
3525
|
-
separator?: string;
|
3526
|
-
startWithReasoning?: boolean;
|
3527
|
-
}): LanguageModelV2Middleware;
|
3528
|
-
|
3529
|
-
/**
|
3530
|
-
* Simulates streaming chunks with the response from a generate call.
|
3531
|
-
*/
|
3532
|
-
declare function simulateStreamingMiddleware(): LanguageModelV2Middleware;
|
3533
|
-
|
3534
|
-
/**
|
3535
|
-
* Wraps a LanguageModelV2 instance with middleware functionality.
|
3536
|
-
* This function allows you to apply middleware to transform parameters,
|
3537
|
-
* wrap generate operations, and wrap stream operations of a language model.
|
3538
|
-
*
|
3539
|
-
* @param options - Configuration options for wrapping the language model.
|
3540
|
-
* @param options.model - The original LanguageModelV2 instance to be wrapped.
|
3541
|
-
* @param options.middleware - The middleware to be applied to the language model. When multiple middlewares are provided, the first middleware will transform the input first, and the last middleware will be wrapped directly around the model.
|
3542
|
-
* @param options.modelId - Optional custom model ID to override the original model's ID.
|
3543
|
-
* @param options.providerId - Optional custom provider ID to override the original model's provider.
|
3544
|
-
* @returns A new LanguageModelV2 instance with middleware applied.
|
3545
|
-
*/
|
3546
|
-
declare const wrapLanguageModel: ({ model, middleware: middlewareArg, modelId, providerId, }: {
|
3547
|
-
model: LanguageModelV2;
|
3548
|
-
middleware: LanguageModelV2Middleware | LanguageModelV2Middleware[];
|
3549
|
-
modelId?: string;
|
3550
|
-
providerId?: string;
|
3551
|
-
}) => LanguageModelV2;
|
3552
|
-
|
3553
|
-
/**
|
3554
|
-
* Creates a custom provider with specified language models, text embedding models, image models, transcription models, speech models, and an optional fallback provider.
|
3555
|
-
*
|
3556
|
-
* @param {Object} options - The options for creating the custom provider.
|
3557
|
-
* @param {Record<string, LanguageModel>} [options.languageModels] - A record of language models, where keys are model IDs and values are LanguageModel instances.
|
3558
|
-
* @param {Record<string, EmbeddingModel<string>>} [options.textEmbeddingModels] - A record of text embedding models, where keys are model IDs and values are EmbeddingModel<string> instances.
|
3559
|
-
* @param {Record<string, ImageModel>} [options.imageModels] - A record of image models, where keys are model IDs and values are ImageModel instances.
|
3560
|
-
* @param {Record<string, TranscriptionModel>} [options.transcriptionModels] - A record of transcription models, where keys are model IDs and values are TranscriptionModel instances.
|
3561
|
-
* @param {Record<string, SpeechModel>} [options.speechModels] - A record of speech models, where keys are model IDs and values are SpeechModel instances.
|
3562
|
-
* @param {Provider} [options.fallbackProvider] - An optional fallback provider to use when a requested model is not found in the custom provider.
|
3563
|
-
* @returns {Provider} A Provider object with languageModel, textEmbeddingModel, imageModel, transcriptionModel, and speechModel methods.
|
3564
|
-
*
|
3565
|
-
* @throws {NoSuchModelError} Throws when a requested model is not found and no fallback provider is available.
|
3566
|
-
*/
|
3567
|
-
declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageModelV2>, EMBEDDING_MODELS extends Record<string, EmbeddingModelV2<string>>, IMAGE_MODELS extends Record<string, ImageModelV2>, TRANSCRIPTION_MODELS extends Record<string, TranscriptionModelV2>, SPEECH_MODELS extends Record<string, SpeechModelV2>>({ languageModels, textEmbeddingModels, imageModels, transcriptionModels, speechModels, fallbackProvider, }: {
|
3568
|
-
languageModels?: LANGUAGE_MODELS;
|
3569
|
-
textEmbeddingModels?: EMBEDDING_MODELS;
|
3570
|
-
imageModels?: IMAGE_MODELS;
|
3571
|
-
transcriptionModels?: TRANSCRIPTION_MODELS;
|
3572
|
-
speechModels?: SPEECH_MODELS;
|
3573
|
-
fallbackProvider?: ProviderV2;
|
3574
|
-
}): ProviderV2 & {
|
3575
|
-
languageModel(modelId: ExtractModelId<LANGUAGE_MODELS>): LanguageModelV2;
|
3576
|
-
textEmbeddingModel(modelId: ExtractModelId<EMBEDDING_MODELS>): EmbeddingModelV2<string>;
|
3577
|
-
imageModel(modelId: ExtractModelId<IMAGE_MODELS>): ImageModelV2;
|
3578
|
-
transcriptionModel(modelId: ExtractModelId<TRANSCRIPTION_MODELS>): TranscriptionModelV2;
|
3579
|
-
speechModel(modelId: ExtractModelId<SPEECH_MODELS>): SpeechModelV2;
|
3567
|
+
declare const UI_MESSAGE_STREAM_HEADERS: {
|
3568
|
+
'content-type': string;
|
3569
|
+
'cache-control': string;
|
3570
|
+
connection: string;
|
3571
|
+
'x-vercel-ai-ui-message-stream': string;
|
3572
|
+
'x-accel-buffering': string;
|
3580
3573
|
};
|
3581
|
-
/**
|
3582
|
-
* @deprecated Use `customProvider` instead.
|
3583
|
-
*/
|
3584
|
-
declare const experimental_customProvider: typeof customProvider;
|
3585
|
-
type ExtractModelId<MODELS extends Record<string, unknown>> = Extract<keyof MODELS, string>;
|
3586
|
-
|
3587
|
-
declare const symbol: unique symbol;
|
3588
|
-
declare class NoSuchProviderError extends NoSuchModelError {
|
3589
|
-
private readonly [symbol];
|
3590
|
-
readonly providerId: string;
|
3591
|
-
readonly availableProviders: string[];
|
3592
|
-
constructor({ modelId, modelType, providerId, availableProviders, message, }: {
|
3593
|
-
modelId: string;
|
3594
|
-
modelType: 'languageModel' | 'textEmbeddingModel' | 'imageModel' | 'transcriptionModel' | 'speechModel';
|
3595
|
-
providerId: string;
|
3596
|
-
availableProviders: string[];
|
3597
|
-
message?: string;
|
3598
|
-
});
|
3599
|
-
static isInstance(error: unknown): error is NoSuchProviderError;
|
3600
|
-
}
|
3601
|
-
|
3602
|
-
type ExtractLiteralUnion<T> = T extends string ? string extends T ? never : T : never;
|
3603
|
-
interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV2> = Record<string, ProviderV2>, SEPARATOR extends string = ':'> {
|
3604
|
-
languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['languageModel']>>[0]>}` : never): LanguageModelV2;
|
3605
|
-
languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): LanguageModelV2;
|
3606
|
-
textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['textEmbeddingModel']>>[0]>}` : never): EmbeddingModelV2<string>;
|
3607
|
-
textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): EmbeddingModelV2<string>;
|
3608
|
-
imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['imageModel']>>[0]>}` : never): ImageModelV2;
|
3609
|
-
imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): ImageModelV2;
|
3610
|
-
transcriptionModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['transcriptionModel']>>[0]>}` : never): TranscriptionModelV2;
|
3611
|
-
transcriptionModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): TranscriptionModelV2;
|
3612
|
-
speechModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['speechModel']>>[0]>}` : never): SpeechModelV2;
|
3613
|
-
speechModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): SpeechModelV2;
|
3614
|
-
}
|
3615
|
-
/**
|
3616
|
-
* Creates a registry for the given providers.
|
3617
|
-
*/
|
3618
|
-
declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV2>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, }?: {
|
3619
|
-
separator?: SEPARATOR;
|
3620
|
-
}): ProviderRegistryProvider<PROVIDERS, SEPARATOR>;
|
3621
|
-
/**
|
3622
|
-
* @deprecated Use `createProviderRegistry` instead.
|
3623
|
-
*/
|
3624
|
-
declare const experimental_createProviderRegistry: typeof createProviderRegistry;
|
3625
3574
|
|
3626
|
-
|
3627
|
-
|
3628
|
-
|
3629
|
-
|
3630
|
-
|
3631
|
-
|
3632
|
-
|
3633
|
-
|
3634
|
-
|
3635
|
-
|
3636
|
-
|
3637
|
-
|
3638
|
-
|
3639
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3640
|
-
}, z.core.$loose>;
|
3641
|
-
}, z.core.$strict>;
|
3642
|
-
type JSONRPCResponse = z.infer<typeof JSONRPCResponseSchema>;
|
3643
|
-
declare const JSONRPCErrorSchema: z.ZodObject<{
|
3644
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
3645
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
3646
|
-
error: z.ZodObject<{
|
3647
|
-
code: z.ZodNumber;
|
3648
|
-
message: z.ZodString;
|
3649
|
-
data: z.ZodOptional<z.ZodUnknown>;
|
3650
|
-
}, z.core.$strip>;
|
3651
|
-
}, z.core.$strict>;
|
3652
|
-
type JSONRPCError = z.infer<typeof JSONRPCErrorSchema>;
|
3653
|
-
declare const JSONRPCNotificationSchema: z.ZodObject<{
|
3654
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
3655
|
-
method: z.ZodString;
|
3656
|
-
params: z.ZodOptional<z.ZodObject<{
|
3657
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3658
|
-
}, z.core.$loose>>;
|
3659
|
-
}, z.core.$strict>;
|
3660
|
-
type JSONRPCNotification = z.infer<typeof JSONRPCNotificationSchema>;
|
3661
|
-
declare const JSONRPCMessageSchema: z.ZodUnion<readonly [z.ZodObject<{
|
3662
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
3663
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
3664
|
-
method: z.ZodString;
|
3665
|
-
params: z.ZodOptional<z.ZodObject<{
|
3666
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3667
|
-
}, z.core.$loose>>;
|
3668
|
-
}, z.core.$strict>, z.ZodObject<{
|
3669
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
3670
|
-
method: z.ZodString;
|
3671
|
-
params: z.ZodOptional<z.ZodObject<{
|
3672
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3673
|
-
}, z.core.$loose>>;
|
3674
|
-
}, z.core.$strict>, z.ZodObject<{
|
3675
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
3676
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
3677
|
-
result: z.ZodObject<{
|
3678
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3679
|
-
}, z.core.$loose>;
|
3680
|
-
}, z.core.$strict>, z.ZodObject<{
|
3681
|
-
jsonrpc: z.ZodLiteral<"2.0">;
|
3682
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
3683
|
-
error: z.ZodObject<{
|
3684
|
-
code: z.ZodNumber;
|
3685
|
-
message: z.ZodString;
|
3686
|
-
data: z.ZodOptional<z.ZodUnknown>;
|
3687
|
-
}, z.core.$strip>;
|
3688
|
-
}, z.core.$strict>]>;
|
3689
|
-
type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
|
3575
|
+
interface ChatTransport<UI_MESSAGE extends UIMessage> {
|
3576
|
+
sendMessages: (options: {
|
3577
|
+
chatId: string;
|
3578
|
+
messages: UI_MESSAGE[];
|
3579
|
+
abortSignal: AbortSignal | undefined;
|
3580
|
+
} & {
|
3581
|
+
trigger: 'submit-user-message' | 'submit-tool-result' | 'regenerate-assistant-message';
|
3582
|
+
messageId: string | undefined;
|
3583
|
+
} & ChatRequestOptions) => Promise<ReadableStream<UIMessageChunk>>;
|
3584
|
+
reconnectToStream: (options: {
|
3585
|
+
chatId: string;
|
3586
|
+
} & ChatRequestOptions) => Promise<ReadableStream<UIMessageChunk> | null>;
|
3587
|
+
}
|
3690
3588
|
|
3691
|
-
|
3692
|
-
|
3693
|
-
|
3694
|
-
|
3695
|
-
|
3589
|
+
type CreateUIMessage<UI_MESSAGE extends UIMessage> = Omit<UI_MESSAGE, 'id' | 'role'> & {
|
3590
|
+
id?: UI_MESSAGE['id'];
|
3591
|
+
role?: UI_MESSAGE['role'];
|
3592
|
+
};
|
3593
|
+
type UIDataPartSchemas = Record<string, Validator<any> | StandardSchemaV1<any>>;
|
3594
|
+
type UIDataTypesToSchemas<T extends UIDataTypes> = {
|
3595
|
+
[K in keyof T]: Validator<T[K]> | StandardSchemaV1<T[K]>;
|
3596
|
+
};
|
3597
|
+
type InferUIDataParts<T extends UIDataPartSchemas> = {
|
3598
|
+
[K in keyof T]: T[K] extends Validator<infer U> ? U : T[K] extends StandardSchemaV1<infer U> ? U : unknown;
|
3599
|
+
};
|
3600
|
+
type ChatRequestOptions = {
|
3696
3601
|
/**
|
3697
|
-
|
3602
|
+
Additional headers that should be to be passed to the API endpoint.
|
3698
3603
|
*/
|
3699
|
-
|
3604
|
+
headers?: Record<string, string> | Headers;
|
3700
3605
|
/**
|
3701
|
-
|
3702
|
-
* @param message The JSON-RPC message to send
|
3606
|
+
Additional body JSON properties that should be sent to the API endpoint.
|
3703
3607
|
*/
|
3704
|
-
|
3608
|
+
body?: object;
|
3609
|
+
metadata?: unknown;
|
3610
|
+
};
|
3611
|
+
type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
|
3612
|
+
interface ChatState<UI_MESSAGE extends UIMessage> {
|
3613
|
+
status: ChatStatus;
|
3614
|
+
error: Error | undefined;
|
3615
|
+
messages: UI_MESSAGE[];
|
3616
|
+
pushMessage: (message: UI_MESSAGE) => void;
|
3617
|
+
popMessage: () => void;
|
3618
|
+
replaceMessage: (index: number, message: UI_MESSAGE) => void;
|
3619
|
+
snapshot: <T>(thing: T) => T;
|
3620
|
+
}
|
3621
|
+
type ChatOnErrorCallback = (error: Error) => void;
|
3622
|
+
type ChatOnToolCallCallback = ({ toolCall, }: {
|
3623
|
+
toolCall: ToolCall<string, unknown>;
|
3624
|
+
}) => void | Promise<unknown> | unknown;
|
3625
|
+
type ChatOnDataCallback<UI_MESSAGE extends UIMessage> = (dataPart: DataUIPart<InferUIMessageData<UI_MESSAGE>>) => void;
|
3626
|
+
type ChatOnFinishCallback<UI_MESSAGE extends UIMessage> = (options: {
|
3627
|
+
message: UI_MESSAGE;
|
3628
|
+
}) => void;
|
3629
|
+
interface ChatInit<UI_MESSAGE extends UIMessage> {
|
3705
3630
|
/**
|
3706
|
-
*
|
3631
|
+
* A unique identifier for the chat. If not provided, a random one will be
|
3632
|
+
* generated.
|
3707
3633
|
*/
|
3708
|
-
|
3634
|
+
id?: string;
|
3635
|
+
messageMetadataSchema?: Validator<InferUIMessageMetadata<UI_MESSAGE>> | StandardSchemaV1<InferUIMessageMetadata<UI_MESSAGE>>;
|
3636
|
+
dataPartSchemas?: UIDataTypesToSchemas<InferUIMessageData<UI_MESSAGE>>;
|
3637
|
+
messages?: UI_MESSAGE[];
|
3709
3638
|
/**
|
3710
|
-
*
|
3639
|
+
* A way to provide a function that is going to be used for ids for messages and the chat.
|
3640
|
+
* If not provided the default AI SDK `generateId` is used.
|
3711
3641
|
*/
|
3712
|
-
|
3642
|
+
generateId?: IdGenerator;
|
3643
|
+
transport?: ChatTransport<UI_MESSAGE>;
|
3644
|
+
maxSteps?: number;
|
3713
3645
|
/**
|
3714
|
-
*
|
3646
|
+
* Callback function to be called when an error is encountered.
|
3715
3647
|
*/
|
3716
|
-
|
3648
|
+
onError?: ChatOnErrorCallback;
|
3717
3649
|
/**
|
3718
|
-
|
3650
|
+
Optional callback function that is invoked when a tool call is received.
|
3651
|
+
Intended for automatic client-side tool execution.
|
3652
|
+
|
3653
|
+
You can optionally return a result for the tool call,
|
3654
|
+
either synchronously or asynchronously.
|
3655
|
+
*/
|
3656
|
+
onToolCall?: ChatOnToolCallCallback;
|
3657
|
+
/**
|
3658
|
+
* Optional callback function that is called when the assistant message is finished streaming.
|
3659
|
+
*
|
3660
|
+
* @param message The message that was streamed.
|
3719
3661
|
*/
|
3720
|
-
|
3662
|
+
onFinish?: ChatOnFinishCallback<UI_MESSAGE>;
|
3663
|
+
/**
|
3664
|
+
* Optional callback function that is called when a data part is received.
|
3665
|
+
*
|
3666
|
+
* @param data The data part that was received.
|
3667
|
+
*/
|
3668
|
+
onData?: ChatOnDataCallback<UI_MESSAGE>;
|
3721
3669
|
}
|
3722
|
-
|
3723
|
-
|
3670
|
+
declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
3671
|
+
readonly id: string;
|
3672
|
+
readonly generateId: IdGenerator;
|
3673
|
+
protected state: ChatState<UI_MESSAGE>;
|
3674
|
+
private messageMetadataSchema;
|
3675
|
+
private dataPartSchemas;
|
3676
|
+
private readonly transport;
|
3677
|
+
private maxSteps;
|
3678
|
+
private onError?;
|
3679
|
+
private onToolCall?;
|
3680
|
+
private onFinish?;
|
3681
|
+
private onData?;
|
3682
|
+
private activeResponse;
|
3683
|
+
private jobExecutor;
|
3684
|
+
constructor({ generateId, id, transport, maxSteps, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, onData, }: Omit<ChatInit<UI_MESSAGE>, 'messages'> & {
|
3685
|
+
state: ChatState<UI_MESSAGE>;
|
3686
|
+
});
|
3724
3687
|
/**
|
3725
|
-
*
|
3688
|
+
* Hook status:
|
3689
|
+
*
|
3690
|
+
* - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.
|
3691
|
+
* - `streaming`: The response is actively streaming in from the API, receiving chunks of data.
|
3692
|
+
* - `ready`: The full response has been received and processed; a new user message can be submitted.
|
3693
|
+
* - `error`: An error occurred during the API request, preventing successful completion.
|
3726
3694
|
*/
|
3727
|
-
|
3695
|
+
get status(): ChatStatus;
|
3696
|
+
protected setStatus({ status, error, }: {
|
3697
|
+
status: ChatStatus;
|
3698
|
+
error?: Error;
|
3699
|
+
}): void;
|
3700
|
+
get error(): Error | undefined;
|
3701
|
+
get messages(): UI_MESSAGE[];
|
3702
|
+
get lastMessage(): UI_MESSAGE | undefined;
|
3703
|
+
set messages(messages: UI_MESSAGE[]);
|
3728
3704
|
/**
|
3729
|
-
*
|
3705
|
+
* Appends or replaces a user message to the chat list. This triggers the API call to fetch
|
3706
|
+
* the assistant's response.
|
3707
|
+
*
|
3708
|
+
* If a messageId is provided, the message will be replaced.
|
3730
3709
|
*/
|
3731
|
-
|
3732
|
-
|
3733
|
-
|
3734
|
-
|
3735
|
-
|
3736
|
-
|
3737
|
-
|
3738
|
-
|
3739
|
-
|
3740
|
-
|
3741
|
-
|
3742
|
-
|
3743
|
-
|
3744
|
-
|
3745
|
-
|
3746
|
-
|
3747
|
-
content: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
3748
|
-
type: z.ZodLiteral<"text">;
|
3749
|
-
text: z.ZodString;
|
3750
|
-
}, z.core.$loose>, z.ZodObject<{
|
3751
|
-
type: z.ZodLiteral<"image">;
|
3752
|
-
data: z.ZodString;
|
3753
|
-
mimeType: z.ZodString;
|
3754
|
-
}, z.core.$loose>, z.ZodObject<{
|
3755
|
-
type: z.ZodLiteral<"resource">;
|
3756
|
-
resource: z.ZodUnion<readonly [z.ZodObject<{
|
3757
|
-
uri: z.ZodString;
|
3758
|
-
mimeType: z.ZodOptional<z.ZodString>;
|
3759
|
-
text: z.ZodString;
|
3760
|
-
}, z.core.$loose>, z.ZodObject<{
|
3761
|
-
uri: z.ZodString;
|
3762
|
-
mimeType: z.ZodOptional<z.ZodString>;
|
3763
|
-
blob: z.ZodString;
|
3764
|
-
}, z.core.$loose>]>;
|
3765
|
-
}, z.core.$loose>]>>;
|
3766
|
-
isError: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
3767
|
-
}, z.core.$loose>, z.ZodObject<{
|
3768
|
-
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
3769
|
-
toolResult: z.ZodUnknown;
|
3770
|
-
}, z.core.$loose>]>;
|
3771
|
-
type CallToolResult = z.infer<typeof CallToolResultSchema>;
|
3772
|
-
|
3773
|
-
interface MCPClientConfig {
|
3774
|
-
/** Transport configuration for connecting to the MCP server */
|
3775
|
-
transport: MCPTransportConfig | MCPTransport;
|
3776
|
-
/** Optional callback for uncaught errors */
|
3777
|
-
onUncaughtError?: (error: unknown) => void;
|
3778
|
-
/** Optional client name, defaults to 'ai-sdk-mcp-client' */
|
3779
|
-
name?: string;
|
3780
|
-
}
|
3781
|
-
declare function createMCPClient(config: MCPClientConfig): Promise<MCPClient>;
|
3782
|
-
/**
|
3783
|
-
* A lightweight MCP Client implementation
|
3784
|
-
*
|
3785
|
-
* The primary purpose of this client is tool conversion between MCP<>AI SDK
|
3786
|
-
* but can later be extended to support other MCP features
|
3787
|
-
*
|
3788
|
-
* Tool parameters are automatically inferred from the server's JSON schema
|
3789
|
-
* if not explicitly provided in the tools configuration
|
3790
|
-
*
|
3791
|
-
* This client is meant to be used to communicate with a single server. To communicate and fetch tools across multiple servers, it's recommended to create a new client instance per server.
|
3792
|
-
*
|
3793
|
-
* Not supported:
|
3794
|
-
* - Client options (e.g. sampling, roots) as they are not needed for tool conversion
|
3795
|
-
* - Accepting notifications
|
3796
|
-
* - Session management (when passing a sessionId to an instance of the Streamable HTTP transport)
|
3797
|
-
* - Resumable SSE streams
|
3798
|
-
*/
|
3799
|
-
declare class MCPClient {
|
3800
|
-
private transport;
|
3801
|
-
private onUncaughtError?;
|
3802
|
-
private clientInfo;
|
3803
|
-
private requestMessageId;
|
3804
|
-
private responseHandlers;
|
3805
|
-
private serverCapabilities;
|
3806
|
-
private isClosed;
|
3807
|
-
constructor({ transport: transportConfig, name, onUncaughtError, }: MCPClientConfig);
|
3808
|
-
init(): Promise<this>;
|
3809
|
-
close(): Promise<void>;
|
3810
|
-
private assertCapability;
|
3811
|
-
private request;
|
3812
|
-
private listTools;
|
3813
|
-
private callTool;
|
3814
|
-
private notification;
|
3710
|
+
sendMessage: (message: (CreateUIMessage<UI_MESSAGE> & {
|
3711
|
+
text?: never;
|
3712
|
+
files?: never;
|
3713
|
+
messageId?: string;
|
3714
|
+
}) | {
|
3715
|
+
text: string;
|
3716
|
+
files?: FileList | FileUIPart[];
|
3717
|
+
metadata?: InferUIMessageMetadata<UI_MESSAGE>;
|
3718
|
+
parts?: never;
|
3719
|
+
messageId?: string;
|
3720
|
+
} | {
|
3721
|
+
files: FileList | FileUIPart[];
|
3722
|
+
metadata?: InferUIMessageMetadata<UI_MESSAGE>;
|
3723
|
+
parts?: never;
|
3724
|
+
messageId?: string;
|
3725
|
+
}, options?: ChatRequestOptions) => Promise<void>;
|
3815
3726
|
/**
|
3816
|
-
*
|
3817
|
-
*
|
3727
|
+
* Regenerate the assistant message with the provided message id.
|
3728
|
+
* If no message id is provided, the last assistant message will be regenerated.
|
3818
3729
|
*/
|
3819
|
-
|
3820
|
-
|
3821
|
-
})
|
3822
|
-
|
3823
|
-
|
3824
|
-
|
3730
|
+
regenerate: ({ messageId, ...options }?: {
|
3731
|
+
messageId?: string;
|
3732
|
+
} & ChatRequestOptions) => Promise<void>;
|
3733
|
+
/**
|
3734
|
+
* Attempt to resume an ongoing streaming response.
|
3735
|
+
*/
|
3736
|
+
resumeStream: (options?: ChatRequestOptions) => Promise<void>;
|
3737
|
+
addToolResult: ({ toolCallId, output, }: {
|
3738
|
+
toolCallId: string;
|
3739
|
+
output: unknown;
|
3740
|
+
}) => Promise<void>;
|
3741
|
+
/**
|
3742
|
+
* Abort the current request immediately, keep the generated tokens if any.
|
3743
|
+
*/
|
3744
|
+
stop: () => Promise<void>;
|
3745
|
+
private makeRequest;
|
3825
3746
|
}
|
3826
3747
|
|
3748
|
+
declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
|
3749
|
+
|
3827
3750
|
/**
|
3828
|
-
|
3829
|
-
|
3751
|
+
Converts an array of messages from useChat into an array of CoreMessages that can be used
|
3752
|
+
with the AI core functions (e.g. `streamText`).
|
3753
|
+
|
3754
|
+
@param messages - The messages to convert.
|
3755
|
+
@param options.tools - The tools to use.
|
3756
|
+
@param options.ignoreIncompleteToolCalls - Whether to ignore incomplete tool calls. Default is `false`.
|
3830
3757
|
*/
|
3831
|
-
|
3758
|
+
declare function convertToModelMessages(messages: Array<Omit<UIMessage, 'id'>>, options?: {
|
3759
|
+
tools?: ToolSet;
|
3760
|
+
ignoreIncompleteToolCalls?: boolean;
|
3761
|
+
}): ModelMessage[];
|
3762
|
+
/**
|
3763
|
+
@deprecated Use `convertToModelMessages` instead.
|
3764
|
+
*/
|
3765
|
+
declare const convertToCoreMessages: typeof convertToModelMessages;
|
3766
|
+
|
3767
|
+
type PrepareSendMessagesRequest<UI_MESSAGE extends UIMessage> = (options: {
|
3768
|
+
id: string;
|
3769
|
+
messages: UI_MESSAGE[];
|
3770
|
+
requestMetadata: unknown;
|
3771
|
+
body: Record<string, any> | undefined;
|
3772
|
+
credentials: RequestCredentials | undefined;
|
3773
|
+
headers: HeadersInit | undefined;
|
3774
|
+
api: string;
|
3775
|
+
} & {
|
3776
|
+
trigger: 'submit-user-message' | 'submit-tool-result' | 'regenerate-assistant-message';
|
3777
|
+
messageId: string | undefined;
|
3778
|
+
}) => {
|
3779
|
+
body: object;
|
3780
|
+
headers?: HeadersInit;
|
3781
|
+
credentials?: RequestCredentials;
|
3782
|
+
api?: string;
|
3783
|
+
} | PromiseLike<{
|
3784
|
+
body: object;
|
3785
|
+
headers?: HeadersInit;
|
3786
|
+
credentials?: RequestCredentials;
|
3787
|
+
api?: string;
|
3788
|
+
}>;
|
3789
|
+
type PrepareReconnectToStreamRequest = (options: {
|
3790
|
+
id: string;
|
3791
|
+
requestMetadata: unknown;
|
3792
|
+
body: Record<string, any> | undefined;
|
3793
|
+
credentials: RequestCredentials | undefined;
|
3794
|
+
headers: HeadersInit | undefined;
|
3795
|
+
api: string;
|
3796
|
+
}) => {
|
3797
|
+
headers?: HeadersInit;
|
3798
|
+
credentials?: RequestCredentials;
|
3799
|
+
api?: string;
|
3800
|
+
} | PromiseLike<{
|
3801
|
+
headers?: HeadersInit;
|
3802
|
+
credentials?: RequestCredentials;
|
3803
|
+
api?: string;
|
3804
|
+
}>;
|
3805
|
+
/**
|
3806
|
+
* Options for the `HttpChatTransport` class.
|
3807
|
+
*
|
3808
|
+
* @param UI_MESSAGE - The type of message to be used in the chat.
|
3809
|
+
*/
|
3810
|
+
type HttpChatTransportInitOptions<UI_MESSAGE extends UIMessage> = {
|
3832
3811
|
/**
|
3833
|
-
* The
|
3812
|
+
* The API URL to be used for the chat transport.
|
3813
|
+
* Defaults to '/api/chat'.
|
3834
3814
|
*/
|
3835
|
-
|
3815
|
+
api?: string;
|
3836
3816
|
/**
|
3837
|
-
*
|
3838
|
-
*
|
3817
|
+
* The credentials mode to be used for the fetch request.
|
3818
|
+
* Possible values are: 'omit', 'same-origin', 'include'.
|
3819
|
+
* Defaults to 'same-origin'.
|
3839
3820
|
*/
|
3840
|
-
|
3841
|
-
/**
|
3842
|
-
* The text content of this segment.
|
3843
|
-
*/
|
3844
|
-
readonly text: string;
|
3845
|
-
/**
|
3846
|
-
* The start time of this segment in seconds.
|
3847
|
-
*/
|
3848
|
-
readonly startSecond: number;
|
3849
|
-
/**
|
3850
|
-
* The end time of this segment in seconds.
|
3851
|
-
*/
|
3852
|
-
readonly endSecond: number;
|
3853
|
-
}>;
|
3821
|
+
credentials?: Resolvable<RequestCredentials>;
|
3854
3822
|
/**
|
3855
|
-
*
|
3856
|
-
* May be undefined if the language couldn't be detected.
|
3823
|
+
* HTTP headers to be sent with the API request.
|
3857
3824
|
*/
|
3858
|
-
|
3825
|
+
headers?: Resolvable<Record<string, string> | Headers>;
|
3859
3826
|
/**
|
3860
|
-
*
|
3861
|
-
*
|
3827
|
+
* Extra body object to be sent with the API request.
|
3828
|
+
* @example
|
3829
|
+
* Send a `sessionId` to the API along with the messages.
|
3830
|
+
* ```js
|
3831
|
+
* useChat({
|
3832
|
+
* body: {
|
3833
|
+
* sessionId: '123',
|
3834
|
+
* }
|
3835
|
+
* })
|
3836
|
+
* ```
|
3862
3837
|
*/
|
3863
|
-
|
3838
|
+
body?: Resolvable<object>;
|
3864
3839
|
/**
|
3865
|
-
|
3866
|
-
|
3867
|
-
|
3840
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
3841
|
+
or to provide a custom fetch implementation for e.g. testing.
|
3842
|
+
*/
|
3843
|
+
fetch?: FetchFunction;
|
3868
3844
|
/**
|
3869
|
-
|
3845
|
+
* When a function is provided, it will be used
|
3846
|
+
* to prepare the request body for the chat API. This can be useful for
|
3847
|
+
* customizing the request body based on the messages and data in the chat.
|
3848
|
+
*
|
3849
|
+
* @param id The id of the chat.
|
3850
|
+
* @param messages The current messages in the chat.
|
3851
|
+
* @param requestBody The request body object passed in the chat request.
|
3870
3852
|
*/
|
3871
|
-
|
3853
|
+
prepareSendMessagesRequest?: PrepareSendMessagesRequest<UI_MESSAGE>;
|
3872
3854
|
/**
|
3873
|
-
|
3855
|
+
* When a function is provided, it will be used
|
3856
|
+
* to prepare the request body for the chat API. This can be useful for
|
3857
|
+
* customizing the request body based on the messages and data in the chat.
|
3858
|
+
*
|
3859
|
+
* @param id The id of the chat.
|
3860
|
+
* @param messages The current messages in the chat.
|
3861
|
+
* @param requestBody The request body object passed in the chat request.
|
3874
3862
|
*/
|
3875
|
-
|
3863
|
+
prepareReconnectToStreamRequest?: PrepareReconnectToStreamRequest;
|
3864
|
+
};
|
3865
|
+
declare abstract class HttpChatTransport<UI_MESSAGE extends UIMessage> implements ChatTransport<UI_MESSAGE> {
|
3866
|
+
protected api: string;
|
3867
|
+
protected credentials: HttpChatTransportInitOptions<UI_MESSAGE>['credentials'];
|
3868
|
+
protected headers: HttpChatTransportInitOptions<UI_MESSAGE>['headers'];
|
3869
|
+
protected body: HttpChatTransportInitOptions<UI_MESSAGE>['body'];
|
3870
|
+
protected fetch?: FetchFunction;
|
3871
|
+
protected prepareSendMessagesRequest?: PrepareSendMessagesRequest<UI_MESSAGE>;
|
3872
|
+
protected prepareReconnectToStreamRequest?: PrepareReconnectToStreamRequest;
|
3873
|
+
constructor({ api, credentials, headers, body, fetch, prepareSendMessagesRequest, prepareReconnectToStreamRequest, }: HttpChatTransportInitOptions<UI_MESSAGE>);
|
3874
|
+
sendMessages({ abortSignal, ...options }: Parameters<ChatTransport<UI_MESSAGE>['sendMessages']>[0]): Promise<ReadableStream<UIMessageChunk>>;
|
3875
|
+
reconnectToStream(options: Parameters<ChatTransport<UI_MESSAGE>['reconnectToStream']>[0]): Promise<ReadableStream<UIMessageChunk> | null>;
|
3876
|
+
protected abstract processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageChunk>;
|
3876
3877
|
}
|
3877
3878
|
|
3878
|
-
|
3879
|
-
|
3879
|
+
declare class DefaultChatTransport<UI_MESSAGE extends UIMessage> extends HttpChatTransport<UI_MESSAGE> {
|
3880
|
+
constructor(options?: HttpChatTransportInitOptions<UI_MESSAGE>);
|
3881
|
+
protected processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageChunk>;
|
3882
|
+
}
|
3880
3883
|
|
3881
|
-
|
3882
|
-
|
3883
|
-
|
3884
|
-
|
3885
|
-
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
3886
|
-
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
3887
|
-
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
3884
|
+
declare class TextStreamChatTransport<UI_MESSAGE extends UIMessage> extends HttpChatTransport<UI_MESSAGE> {
|
3885
|
+
constructor(options?: HttpChatTransportInitOptions<UI_MESSAGE>);
|
3886
|
+
protected processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageChunk>;
|
3887
|
+
}
|
3888
3888
|
|
3889
|
-
|
3890
|
-
*/
|
3891
|
-
declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
|
3889
|
+
type CompletionRequestOptions = {
|
3892
3890
|
/**
|
3893
|
-
|
3891
|
+
An optional object of headers to be passed to the API endpoint.
|
3892
|
+
*/
|
3893
|
+
headers?: Record<string, string> | Headers;
|
3894
|
+
/**
|
3895
|
+
An optional object to be passed to the API endpoint.
|
3894
3896
|
*/
|
3895
|
-
|
3897
|
+
body?: object;
|
3898
|
+
};
|
3899
|
+
type UseCompletionOptions = {
|
3896
3900
|
/**
|
3897
|
-
|
3901
|
+
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
3902
|
+
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
3898
3903
|
*/
|
3899
|
-
|
3904
|
+
api?: string;
|
3900
3905
|
/**
|
3901
|
-
|
3902
|
-
|
3903
|
-
|
3904
|
-
|
3905
|
-
|
3906
|
-
```ts
|
3907
|
-
{
|
3908
|
-
"openai": {
|
3909
|
-
"temperature": 0
|
3910
|
-
}
|
3911
|
-
}
|
3912
|
-
```
|
3913
|
-
*/
|
3914
|
-
providerOptions?: ProviderOptions;
|
3906
|
+
* An unique identifier for the chat. If not provided, a random one will be
|
3907
|
+
* generated. When provided, the `useChat` hook with the same `id` will
|
3908
|
+
* have shared states across components.
|
3909
|
+
*/
|
3910
|
+
id?: string;
|
3915
3911
|
/**
|
3916
|
-
|
3917
|
-
|
3918
|
-
@default 2
|
3912
|
+
* Initial prompt input of the completion.
|
3919
3913
|
*/
|
3920
|
-
|
3914
|
+
initialInput?: string;
|
3921
3915
|
/**
|
3922
|
-
|
3923
|
-
|
3924
|
-
|
3916
|
+
* Initial completion result. Useful to load an existing history.
|
3917
|
+
*/
|
3918
|
+
initialCompletion?: string;
|
3925
3919
|
/**
|
3926
|
-
|
3927
|
-
|
3928
|
-
|
3929
|
-
|
3930
|
-
|
3920
|
+
* Callback function to be called when the completion is finished streaming.
|
3921
|
+
*/
|
3922
|
+
onFinish?: (prompt: string, completion: string) => void;
|
3923
|
+
/**
|
3924
|
+
* Callback function to be called when an error is encountered.
|
3925
|
+
*/
|
3926
|
+
onError?: (error: Error) => void;
|
3927
|
+
/**
|
3928
|
+
* The credentials mode to be used for the fetch request.
|
3929
|
+
* Possible values are: 'omit', 'same-origin', 'include'.
|
3930
|
+
* Defaults to 'same-origin'.
|
3931
|
+
*/
|
3932
|
+
credentials?: RequestCredentials;
|
3933
|
+
/**
|
3934
|
+
* HTTP headers to be sent with the API request.
|
3935
|
+
*/
|
3936
|
+
headers?: Record<string, string> | Headers;
|
3937
|
+
/**
|
3938
|
+
* Extra body object to be sent with the API request.
|
3939
|
+
* @example
|
3940
|
+
* Send a `sessionId` to the API along with the prompt.
|
3941
|
+
* ```js
|
3942
|
+
* useChat({
|
3943
|
+
* body: {
|
3944
|
+
* sessionId: '123',
|
3945
|
+
* }
|
3946
|
+
* })
|
3947
|
+
* ```
|
3948
|
+
*/
|
3949
|
+
body?: object;
|
3950
|
+
/**
|
3951
|
+
Streaming protocol that is used. Defaults to `data`.
|
3952
|
+
*/
|
3953
|
+
streamProtocol?: 'data' | 'text';
|
3954
|
+
/**
|
3955
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
3956
|
+
or to provide a custom fetch implementation for e.g. testing.
|
3957
|
+
*/
|
3958
|
+
fetch?: FetchFunction;
|
3959
|
+
};
|
3931
3960
|
|
3932
3961
|
declare global {
|
3933
3962
|
var AI_SDK_DEFAULT_PROVIDER: ProviderV2 | undefined;
|
3934
3963
|
}
|
3935
3964
|
|
3936
|
-
export { AbstractChat, CallSettings, CallWarning, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, ErrorHandler, Agent as Experimental_Agent, AgentSettings as Experimental_AgentSettings, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, InferUIDataParts, InferUITool, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SerialJobExecutor, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolErrorUnion, ToolResultUnion, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UITools, UI_MESSAGE_STREAM_HEADERS, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolName, hasToolCall, isDeepEqualData, isToolUIPart, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, readUIMessageStream, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, userModelMessageSchema, wrapLanguageModel };
|
3965
|
+
export { AbstractChat, CallSettings, CallWarning, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, ErrorHandler, Agent as Experimental_Agent, AgentSettings as Experimental_AgentSettings, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, InferUIDataParts, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SerialJobExecutor, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolErrorUnion, ToolResultUnion, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UITools, UI_MESSAGE_STREAM_HEADERS, UseCompletionOptions, assistantModelMessageSchema, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolName, hasToolCall, isDeepEqualData, isToolUIPart, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, readUIMessageStream, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, userModelMessageSchema, wrapLanguageModel };
|