ai 5.0.0-alpha.13 → 5.0.0-alpha.15
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 +37 -0
- package/dist/index.d.mts +207 -186
- package/dist/index.d.ts +207 -186
- package/dist/index.js +345 -339
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +345 -341
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +33 -20
- package/dist/internal/index.d.ts +33 -20
- package/dist/internal/index.js +14 -7
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +14 -7
- package/dist/internal/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.d.mts +3 -3
- package/dist/mcp-stdio/index.d.ts +3 -3
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
@@ -144,7 +144,7 @@ interface ToolCallPart {
|
|
144
144
|
/**
|
145
145
|
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
146
146
|
*/
|
147
|
-
|
147
|
+
input: unknown;
|
148
148
|
/**
|
149
149
|
Additional provider-specific metadata. They are passed through
|
150
150
|
to the provider from the AI SDK and enable provider-specific
|
@@ -168,7 +168,7 @@ interface ToolResultPart {
|
|
168
168
|
/**
|
169
169
|
Result of the tool call. This is a JSON-serializable object.
|
170
170
|
*/
|
171
|
-
|
171
|
+
output: unknown;
|
172
172
|
/**
|
173
173
|
Multi-part content of the tool result. Only for tools that support multipart results.
|
174
174
|
*/
|
@@ -651,21 +651,21 @@ declare const JSONRPCResponseSchema: z.ZodObject<{
|
|
651
651
|
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
652
652
|
}, z.ZodTypeAny, "passthrough">>;
|
653
653
|
}, "strict", z.ZodTypeAny, {
|
654
|
+
id: string | number;
|
655
|
+
jsonrpc: "2.0";
|
654
656
|
result: {
|
655
657
|
_meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
656
658
|
} & {
|
657
659
|
[k: string]: unknown;
|
658
660
|
};
|
661
|
+
}, {
|
659
662
|
id: string | number;
|
660
663
|
jsonrpc: "2.0";
|
661
|
-
}, {
|
662
664
|
result: {
|
663
665
|
_meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
664
666
|
} & {
|
665
667
|
[k: string]: unknown;
|
666
668
|
};
|
667
|
-
id: string | number;
|
668
|
-
jsonrpc: "2.0";
|
669
669
|
}>;
|
670
670
|
type JSONRPCResponse = z.infer<typeof JSONRPCResponseSchema>;
|
671
671
|
declare const JSONRPCErrorSchema: z.ZodObject<{
|
@@ -787,21 +787,21 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
787
787
|
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
788
788
|
}, z.ZodTypeAny, "passthrough">>;
|
789
789
|
}, "strict", z.ZodTypeAny, {
|
790
|
+
id: string | number;
|
791
|
+
jsonrpc: "2.0";
|
790
792
|
result: {
|
791
793
|
_meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
792
794
|
} & {
|
793
795
|
[k: string]: unknown;
|
794
796
|
};
|
797
|
+
}, {
|
795
798
|
id: string | number;
|
796
799
|
jsonrpc: "2.0";
|
797
|
-
}, {
|
798
800
|
result: {
|
799
801
|
_meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
|
800
802
|
} & {
|
801
803
|
[k: string]: unknown;
|
802
804
|
};
|
803
|
-
id: string | number;
|
804
|
-
jsonrpc: "2.0";
|
805
805
|
}>, z.ZodObject<{
|
806
806
|
jsonrpc: z.ZodLiteral<"2.0">;
|
807
807
|
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
@@ -880,7 +880,7 @@ type MCPTransportConfig = {
|
|
880
880
|
headers?: Record<string, string>;
|
881
881
|
};
|
882
882
|
|
883
|
-
type
|
883
|
+
type ToolInputSchema<T = JSONObject> = z4.$ZodType<T> | z3.Schema<T> | Schema<T>;
|
884
884
|
interface ToolCallOptions {
|
885
885
|
/**
|
886
886
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
@@ -903,21 +903,21 @@ This enables the language model to generate the input.
|
|
903
903
|
|
904
904
|
The tool can also contain an optional execute function for the actual execution function of the tool.
|
905
905
|
*/
|
906
|
-
type Tool<
|
906
|
+
type Tool<INPUT extends JSONValue$1 | unknown | never = any, OUTPUT = any> = {
|
907
907
|
/**
|
908
908
|
An optional description of what the tool does.
|
909
909
|
Will be used by the language model to decide whether to use the tool.
|
910
|
-
Not used for provider-defined tools.
|
910
|
+
Not used for provider-defined-client tools.
|
911
911
|
*/
|
912
912
|
description?: string;
|
913
|
-
} & NeverOptional<
|
913
|
+
} & NeverOptional<INPUT, {
|
914
914
|
/**
|
915
915
|
The schema of the input that the tool expects. The language model will use this to generate the input.
|
916
916
|
It is also used to validate the output of the language model.
|
917
917
|
Use descriptions to make the input understandable for the language model.
|
918
918
|
*/
|
919
|
-
|
920
|
-
}> & NeverOptional<
|
919
|
+
inputSchema: ToolInputSchema<INPUT>;
|
920
|
+
}> & NeverOptional<OUTPUT, {
|
921
921
|
/**
|
922
922
|
An async function that is called with the arguments from the tool call and produces a result.
|
923
923
|
If not provided, the tool will not be executed automatically.
|
@@ -925,29 +925,29 @@ If not provided, the tool will not be executed automatically.
|
|
925
925
|
@args is the input of the tool call.
|
926
926
|
@options.abortSignal is a signal that can be used to abort the tool call.
|
927
927
|
*/
|
928
|
-
execute: (
|
928
|
+
execute: (input: [INPUT] extends [never] ? undefined : INPUT, options: ToolCallOptions) => PromiseLike<OUTPUT>;
|
929
929
|
/**
|
930
930
|
Optional conversion function that maps the tool result to multi-part tool content for LLMs.
|
931
931
|
*/
|
932
|
-
experimental_toToolResultContent?: (
|
932
|
+
experimental_toToolResultContent?: (output: OUTPUT) => ToolResultContent;
|
933
933
|
/**
|
934
934
|
* Optional function that is called when the argument streaming starts.
|
935
935
|
* Only called when the tool is used in a streaming context.
|
936
936
|
*/
|
937
|
-
|
937
|
+
onInputStart?: (options: ToolCallOptions) => void | PromiseLike<void>;
|
938
938
|
/**
|
939
939
|
* Optional function that is called when an argument streaming delta is available.
|
940
940
|
* Only called when the tool is used in a streaming context.
|
941
941
|
*/
|
942
|
-
|
943
|
-
|
942
|
+
onInputDelta?: (options: {
|
943
|
+
inputTextDelta: string;
|
944
944
|
} & ToolCallOptions) => void | PromiseLike<void>;
|
945
945
|
/**
|
946
946
|
* Optional function that is called when a tool call can be started,
|
947
947
|
* even if the execute function is not provided.
|
948
948
|
*/
|
949
|
-
|
950
|
-
|
949
|
+
onInputAvailable?: (options: {
|
950
|
+
input: [INPUT] extends [never] ? undefined : INPUT;
|
951
951
|
} & ToolCallOptions) => void | PromiseLike<void>;
|
952
952
|
}> & ({
|
953
953
|
/**
|
@@ -956,9 +956,22 @@ Function tool.
|
|
956
956
|
type?: undefined | 'function';
|
957
957
|
} | {
|
958
958
|
/**
|
959
|
-
Provider-defined tool.
|
959
|
+
Provider-defined-client tool.
|
960
|
+
*/
|
961
|
+
type: 'provider-defined-client';
|
962
|
+
/**
|
963
|
+
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
964
|
+
*/
|
965
|
+
id: `${string}.${string}`;
|
966
|
+
/**
|
967
|
+
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
968
|
+
*/
|
969
|
+
args: Record<string, unknown>;
|
970
|
+
} | {
|
971
|
+
/**
|
972
|
+
Provider-defined-server tool.
|
960
973
|
*/
|
961
|
-
type: 'provider-defined';
|
974
|
+
type: 'provider-defined-server';
|
962
975
|
/**
|
963
976
|
The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
|
964
977
|
*/
|
@@ -971,21 +984,21 @@ The arguments for configuring the tool. Must match the expected arguments define
|
|
971
984
|
/**
|
972
985
|
Helper function for inferring the execute args of a tool.
|
973
986
|
*/
|
974
|
-
declare function tool<
|
975
|
-
declare function tool<
|
976
|
-
declare function tool<
|
987
|
+
declare function tool<INPUT, OUTPUT>(tool: Tool<INPUT, OUTPUT>): Tool<INPUT, OUTPUT>;
|
988
|
+
declare function tool<INPUT>(tool: Tool<INPUT, never>): Tool<INPUT, never>;
|
989
|
+
declare function tool<OUTPUT>(tool: Tool<never, OUTPUT>): Tool<never, OUTPUT>;
|
977
990
|
declare function tool(tool: Tool<never, never>): Tool<never, never>;
|
978
|
-
type MappedTool<T extends Tool | JSONObject,
|
991
|
+
type MappedTool<T extends Tool | JSONObject, OUTPUT extends any> = T extends Tool<infer INPUT> ? Tool<INPUT, OUTPUT> : T extends JSONObject ? Tool<T, OUTPUT> : never;
|
979
992
|
|
980
993
|
type ToolSchemas = Record<string, {
|
981
|
-
|
994
|
+
inputSchema: ToolInputSchema<JSONObject | unknown>;
|
982
995
|
}> | 'automatic' | undefined;
|
983
996
|
type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> = TOOL_SCHEMAS extends Record<string, {
|
984
|
-
|
997
|
+
inputSchema: ToolInputSchema<unknown>;
|
985
998
|
}> ? {
|
986
999
|
[K in keyof TOOL_SCHEMAS]: MappedTool<TOOL_SCHEMAS[K], CallToolResult> & Required<Pick<MappedTool<TOOL_SCHEMAS[K], CallToolResult>, 'execute'>>;
|
987
1000
|
} : McpToolSet<Record<string, {
|
988
|
-
|
1001
|
+
inputSchema: ToolInputSchema<unknown>;
|
989
1002
|
}>>;
|
990
1003
|
declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
|
991
1004
|
_meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
@@ -1755,14 +1768,14 @@ declare class MCPClient {
|
|
1755
1768
|
private onResponse;
|
1756
1769
|
}
|
1757
1770
|
|
1758
|
-
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute' | '
|
1771
|
+
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute' | 'onInputAvailable' | 'onInputStart' | 'onInputDelta'>>;
|
1759
1772
|
|
1760
1773
|
type ToolCallUnion<TOOLS extends ToolSet> = ValueOf<{
|
1761
1774
|
[NAME in keyof TOOLS]: {
|
1762
1775
|
type: 'tool-call';
|
1763
1776
|
toolCallId: string;
|
1764
1777
|
toolName: NAME & string;
|
1765
|
-
|
1778
|
+
input: TOOLS[NAME] extends Tool<infer PARAMETERS> ? PARAMETERS : never;
|
1766
1779
|
};
|
1767
1780
|
}>;
|
1768
1781
|
type ToolCallArray<TOOLS extends ToolSet> = Array<ToolCallUnion<TOOLS>>;
|
@@ -1775,8 +1788,8 @@ type ToToolResultObject<TOOLS extends ToolSet> = ValueOf<{
|
|
1775
1788
|
type: 'tool-result';
|
1776
1789
|
toolCallId: string;
|
1777
1790
|
toolName: NAME & string;
|
1778
|
-
|
1779
|
-
|
1791
|
+
input: TOOLS[NAME] extends Tool<infer P> ? P : never;
|
1792
|
+
output: Awaited<ReturnType<Exclude<TOOLS[NAME]['execute'], undefined>>>;
|
1780
1793
|
};
|
1781
1794
|
}>;
|
1782
1795
|
type ToolResultUnion<TOOLS extends ToolSet> = ToToolResultObject<ToToolsWithDefinedExecute<TOOLS>>;
|
@@ -1801,17 +1814,17 @@ type ContentPart<TOOLS extends ToolSet> = {
|
|
1801
1814
|
} & ToolResultUnion<TOOLS>);
|
1802
1815
|
|
1803
1816
|
declare const symbol$e: unique symbol;
|
1804
|
-
declare class
|
1817
|
+
declare class InvalidToolInputError extends AISDKError {
|
1805
1818
|
private readonly [symbol$e];
|
1806
1819
|
readonly toolName: string;
|
1807
|
-
readonly
|
1808
|
-
constructor({
|
1820
|
+
readonly toolInput: string;
|
1821
|
+
constructor({ toolInput, toolName, cause, message, }: {
|
1809
1822
|
message?: string;
|
1810
|
-
|
1823
|
+
toolInput: string;
|
1811
1824
|
toolName: string;
|
1812
1825
|
cause: unknown;
|
1813
1826
|
});
|
1814
|
-
static isInstance(error: unknown): error is
|
1827
|
+
static isInstance(error: unknown): error is InvalidToolInputError;
|
1815
1828
|
}
|
1816
1829
|
|
1817
1830
|
declare const symbol$d: unique symbol;
|
@@ -1921,8 +1934,6 @@ type Prompt = {
|
|
1921
1934
|
messages?: Array<ModelMessage>;
|
1922
1935
|
};
|
1923
1936
|
|
1924
|
-
declare const GLOBAL_DEFAULT_PROVIDER: unique symbol;
|
1925
|
-
|
1926
1937
|
/**
|
1927
1938
|
* A function that attempts to repair a tool call that failed to parse.
|
1928
1939
|
*
|
@@ -1933,7 +1944,7 @@ declare const GLOBAL_DEFAULT_PROVIDER: unique symbol;
|
|
1933
1944
|
* @param options.messages - The messages in the current generation step.
|
1934
1945
|
* @param options.toolCall - The tool call that failed to parse.
|
1935
1946
|
* @param options.tools - The tools that are available.
|
1936
|
-
* @param options.
|
1947
|
+
* @param options.inputSchema - A function that returns the JSON Schema for a tool.
|
1937
1948
|
* @param options.error - The error that occurred while parsing the tool call.
|
1938
1949
|
*/
|
1939
1950
|
type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
@@ -1941,10 +1952,10 @@ type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
|
1941
1952
|
messages: ModelMessage[];
|
1942
1953
|
toolCall: LanguageModelV2ToolCall;
|
1943
1954
|
tools: TOOLS;
|
1944
|
-
|
1955
|
+
inputSchema: (options: {
|
1945
1956
|
toolName: string;
|
1946
1957
|
}) => JSONSchema7;
|
1947
|
-
error: NoSuchToolError |
|
1958
|
+
error: NoSuchToolError | InvalidToolInputError;
|
1948
1959
|
}) => Promise<LanguageModelV2ToolCall | null>;
|
1949
1960
|
|
1950
1961
|
type SingleRequestTextStreamPart<TOOLS extends ToolSet> = ContentPart<TOOLS> | {
|
@@ -1960,7 +1971,7 @@ type SingleRequestTextStreamPart<TOOLS extends ToolSet> = ContentPart<TOOLS> | {
|
|
1960
1971
|
type: 'tool-call-delta';
|
1961
1972
|
toolCallId: string;
|
1962
1973
|
toolName: string;
|
1963
|
-
|
1974
|
+
inputTextDelta: string;
|
1964
1975
|
} | {
|
1965
1976
|
type: 'response-metadata';
|
1966
1977
|
id?: string;
|
@@ -2081,11 +2092,11 @@ declare class NoOutputSpecifiedError extends AISDKError {
|
|
2081
2092
|
declare const symbol$7: unique symbol;
|
2082
2093
|
declare class ToolCallRepairError extends AISDKError {
|
2083
2094
|
private readonly [symbol$7];
|
2084
|
-
readonly originalError: NoSuchToolError |
|
2095
|
+
readonly originalError: NoSuchToolError | InvalidToolInputError;
|
2085
2096
|
constructor({ cause, originalError, message, }: {
|
2086
2097
|
message?: string;
|
2087
2098
|
cause: unknown;
|
2088
|
-
originalError: NoSuchToolError |
|
2099
|
+
originalError: NoSuchToolError | InvalidToolInputError;
|
2089
2100
|
});
|
2090
2101
|
static isInstance(error: unknown): error is ToolCallRepairError;
|
2091
2102
|
}
|
@@ -2094,11 +2105,11 @@ declare const symbol$6: unique symbol;
|
|
2094
2105
|
declare class ToolExecutionError extends AISDKError {
|
2095
2106
|
private readonly [symbol$6];
|
2096
2107
|
readonly toolName: string;
|
2097
|
-
readonly
|
2108
|
+
readonly toolInput: JSONValue$1 | unknown;
|
2098
2109
|
readonly toolCallId: string;
|
2099
|
-
constructor({
|
2110
|
+
constructor({ toolInput, toolName, toolCallId, cause, message, }: {
|
2100
2111
|
message?: string;
|
2101
|
-
|
2112
|
+
toolInput: JSONValue$1 | unknown;
|
2102
2113
|
toolName: string;
|
2103
2114
|
toolCallId: string;
|
2104
2115
|
cause: unknown;
|
@@ -2151,8 +2162,8 @@ The data types that can be used in the UI message for the UI message data parts.
|
|
2151
2162
|
*/
|
2152
2163
|
type UIDataTypes = Record<string, unknown>;
|
2153
2164
|
type UITools = Record<string, {
|
2154
|
-
|
2155
|
-
|
2165
|
+
input: unknown;
|
2166
|
+
output: unknown | undefined;
|
2156
2167
|
}>;
|
2157
2168
|
/**
|
2158
2169
|
AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
@@ -2267,15 +2278,15 @@ type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
|
|
2267
2278
|
type: `tool-${NAME}`;
|
2268
2279
|
toolCallId: string;
|
2269
2280
|
} & ({
|
2270
|
-
state: '
|
2271
|
-
|
2281
|
+
state: 'input-streaming';
|
2282
|
+
input: DeepPartial<TOOLS[NAME]['input']>;
|
2272
2283
|
} | {
|
2273
|
-
state: '
|
2274
|
-
|
2284
|
+
state: 'input-available';
|
2285
|
+
input: TOOLS[NAME]['input'];
|
2275
2286
|
} | {
|
2276
|
-
state: '
|
2277
|
-
|
2278
|
-
|
2287
|
+
state: 'output-available';
|
2288
|
+
input: TOOLS[NAME]['input'];
|
2289
|
+
output: TOOLS[NAME]['output'];
|
2279
2290
|
});
|
2280
2291
|
}>;
|
2281
2292
|
declare function isToolUIPart<TOOLS extends UITools>(part: UIMessagePart<UIDataTypes, TOOLS>): part is ToolUIPart<TOOLS>;
|
@@ -2365,23 +2376,23 @@ type UIMessageStreamPart<METADATA = unknown, DATA_TYPES extends UIDataTypes = UI
|
|
2365
2376
|
type: 'error';
|
2366
2377
|
errorText: string;
|
2367
2378
|
} | {
|
2368
|
-
type: 'tool-
|
2379
|
+
type: 'tool-input-available';
|
2369
2380
|
toolCallId: string;
|
2370
2381
|
toolName: string;
|
2371
|
-
|
2382
|
+
input: unknown;
|
2372
2383
|
} | {
|
2373
|
-
type: 'tool-
|
2384
|
+
type: 'tool-output-available';
|
2374
2385
|
toolCallId: string;
|
2375
|
-
|
2386
|
+
output: unknown;
|
2376
2387
|
providerMetadata?: ProviderMetadata;
|
2377
2388
|
} | {
|
2378
|
-
type: 'tool-
|
2389
|
+
type: 'tool-input-start';
|
2379
2390
|
toolCallId: string;
|
2380
2391
|
toolName: string;
|
2381
2392
|
} | {
|
2382
|
-
type: 'tool-
|
2393
|
+
type: 'tool-input-delta';
|
2383
2394
|
toolCallId: string;
|
2384
|
-
|
2395
|
+
inputTextDelta: string;
|
2385
2396
|
} | {
|
2386
2397
|
type: 'reasoning';
|
2387
2398
|
text: string;
|
@@ -2469,26 +2480,45 @@ originalMessages, onFinish, generateId, }: {
|
|
2469
2480
|
generateId?: IdGenerator;
|
2470
2481
|
}): ReadableStream<InferUIMessageStreamPart<UI_MESSAGE>>;
|
2471
2482
|
|
2472
|
-
|
2473
|
-
|
2474
|
-
|
2483
|
+
type UIMessageStreamResponseInit = ResponseInit & {
|
2484
|
+
consumeSseStream?: (options: {
|
2485
|
+
stream: ReadableStream<string>;
|
2486
|
+
}) => PromiseLike<void> | void;
|
2487
|
+
};
|
2475
2488
|
|
2476
|
-
declare function
|
2477
|
-
response: ServerResponse;
|
2489
|
+
declare function createUIMessageStreamResponse({ status, statusText, headers, stream, consumeSseStream, }: UIMessageStreamResponseInit & {
|
2478
2490
|
stream: ReadableStream<UIMessageStreamPart>;
|
2479
|
-
}
|
2491
|
+
}): Response;
|
2480
2492
|
|
2481
2493
|
declare class JsonToSseTransformStream extends TransformStream<unknown, string> {
|
2482
2494
|
constructor();
|
2483
2495
|
}
|
2484
2496
|
|
2497
|
+
declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, consumeSseStream, }: {
|
2498
|
+
response: ServerResponse;
|
2499
|
+
stream: ReadableStream<UIMessageStreamPart>;
|
2500
|
+
} & UIMessageStreamResponseInit): void;
|
2501
|
+
|
2502
|
+
declare const UI_MESSAGE_STREAM_HEADERS: {
|
2503
|
+
'content-type': string;
|
2504
|
+
'cache-control': string;
|
2505
|
+
connection: string;
|
2506
|
+
'x-vercel-ai-ui-message-stream': string;
|
2507
|
+
'x-accel-buffering': string;
|
2508
|
+
};
|
2509
|
+
|
2485
2510
|
interface ChatTransport<UI_MESSAGE extends UIMessage> {
|
2486
|
-
|
2511
|
+
sendMessages: (options: {
|
2487
2512
|
chatId: string;
|
2488
2513
|
messages: UI_MESSAGE[];
|
2489
2514
|
abortSignal: AbortSignal | undefined;
|
2490
|
-
|
2515
|
+
} & {
|
2516
|
+
trigger: 'submit-user-message' | 'submit-tool-result' | 'regenerate-assistant-message';
|
2517
|
+
messageId: string | undefined;
|
2491
2518
|
} & ChatRequestOptions) => Promise<ReadableStream<UIMessageStreamPart>>;
|
2519
|
+
reconnectToStream: (options: {
|
2520
|
+
chatId: string;
|
2521
|
+
} & ChatRequestOptions) => Promise<ReadableStream<UIMessageStreamPart> | null>;
|
2492
2522
|
}
|
2493
2523
|
|
2494
2524
|
type CreateUIMessage<UI_MESSAGE extends UIMessage> = Omit<UI_MESSAGE, 'id' | 'role'> & {
|
@@ -2595,41 +2625,48 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
|
|
2595
2625
|
get messages(): UI_MESSAGE[];
|
2596
2626
|
get lastMessage(): UI_MESSAGE | undefined;
|
2597
2627
|
set messages(messages: UI_MESSAGE[]);
|
2598
|
-
removeAssistantResponse: () => void;
|
2599
2628
|
/**
|
2600
|
-
*
|
2629
|
+
* Appends or replaces a user message to the chat list. This triggers the API call to fetch
|
2601
2630
|
* the assistant's response.
|
2631
|
+
*
|
2632
|
+
* If a messageId is provided, the message will be replaced.
|
2602
2633
|
*/
|
2603
2634
|
sendMessage: (message: (CreateUIMessage<UI_MESSAGE> & {
|
2604
2635
|
text?: never;
|
2605
2636
|
files?: never;
|
2637
|
+
messageId?: string;
|
2606
2638
|
}) | {
|
2607
2639
|
text: string;
|
2608
2640
|
files?: FileList | FileUIPart[];
|
2609
2641
|
metadata?: InferUIMessageMetadata<UI_MESSAGE>;
|
2610
2642
|
parts?: never;
|
2643
|
+
messageId?: string;
|
2611
2644
|
} | {
|
2612
2645
|
files: FileList | FileUIPart[];
|
2613
2646
|
metadata?: InferUIMessageMetadata<UI_MESSAGE>;
|
2614
2647
|
parts?: never;
|
2648
|
+
messageId?: string;
|
2615
2649
|
}, options?: ChatRequestOptions) => Promise<void>;
|
2616
2650
|
/**
|
2617
|
-
* Regenerate the
|
2651
|
+
* Regenerate the assistant message with the provided message id.
|
2652
|
+
* If no message id is provided, the last assistant message will be regenerated.
|
2618
2653
|
*/
|
2619
|
-
|
2654
|
+
regenerate: ({ messageId, ...options }?: {
|
2655
|
+
messageId?: string;
|
2656
|
+
} & ChatRequestOptions) => Promise<void>;
|
2620
2657
|
/**
|
2621
|
-
*
|
2658
|
+
* Attempt to resume an ongoing streaming response.
|
2622
2659
|
*/
|
2623
|
-
|
2624
|
-
addToolResult: ({ toolCallId,
|
2660
|
+
resumeStream: (options?: ChatRequestOptions) => Promise<void>;
|
2661
|
+
addToolResult: ({ toolCallId, output, }: {
|
2625
2662
|
toolCallId: string;
|
2626
|
-
|
2663
|
+
output: unknown;
|
2627
2664
|
}) => Promise<void>;
|
2628
2665
|
/**
|
2629
2666
|
* Abort the current request immediately, keep the generated tokens if any.
|
2630
2667
|
*/
|
2631
2668
|
stop: () => Promise<void>;
|
2632
|
-
private
|
2669
|
+
private makeRequest;
|
2633
2670
|
}
|
2634
2671
|
|
2635
2672
|
declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
|
@@ -2646,119 +2683,99 @@ declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages:
|
|
2646
2683
|
*/
|
2647
2684
|
declare const convertToCoreMessages: typeof convertToModelMessages;
|
2648
2685
|
|
2649
|
-
type
|
2686
|
+
type PrepareSendMessagesRequest<UI_MESSAGE extends UIMessage> = (options: {
|
2650
2687
|
id: string;
|
2651
2688
|
messages: UI_MESSAGE[];
|
2652
2689
|
requestMetadata: unknown;
|
2653
2690
|
body: Record<string, any> | undefined;
|
2654
2691
|
credentials: RequestCredentials | undefined;
|
2655
2692
|
headers: HeadersInit | undefined;
|
2693
|
+
api: string;
|
2694
|
+
} & {
|
2695
|
+
trigger: 'submit-user-message' | 'submit-tool-result' | 'regenerate-assistant-message';
|
2696
|
+
messageId: string | undefined;
|
2656
2697
|
}) => {
|
2657
2698
|
body: object;
|
2658
2699
|
headers?: HeadersInit;
|
2659
2700
|
credentials?: RequestCredentials;
|
2701
|
+
api?: string;
|
2702
|
+
};
|
2703
|
+
type PrepareReconnectToStreamRequest = (options: {
|
2704
|
+
id: string;
|
2705
|
+
requestMetadata: unknown;
|
2706
|
+
body: Record<string, any> | undefined;
|
2707
|
+
credentials: RequestCredentials | undefined;
|
2708
|
+
headers: HeadersInit | undefined;
|
2709
|
+
api: string;
|
2710
|
+
}) => {
|
2711
|
+
headers?: HeadersInit;
|
2712
|
+
credentials?: RequestCredentials;
|
2713
|
+
api?: string;
|
2714
|
+
};
|
2715
|
+
type HttpChatTransportInitOptions<UI_MESSAGE extends UIMessage> = {
|
2716
|
+
api?: string;
|
2717
|
+
/**
|
2718
|
+
* The credentials mode to be used for the fetch request.
|
2719
|
+
* Possible values are: 'omit', 'same-origin', 'include'.
|
2720
|
+
* Defaults to 'same-origin'.
|
2721
|
+
*/
|
2722
|
+
credentials?: RequestCredentials;
|
2723
|
+
/**
|
2724
|
+
* HTTP headers to be sent with the API request.
|
2725
|
+
*/
|
2726
|
+
headers?: Record<string, string> | Headers;
|
2727
|
+
/**
|
2728
|
+
* Extra body object to be sent with the API request.
|
2729
|
+
* @example
|
2730
|
+
* Send a `sessionId` to the API along with the messages.
|
2731
|
+
* ```js
|
2732
|
+
* useChat({
|
2733
|
+
* body: {
|
2734
|
+
* sessionId: '123',
|
2735
|
+
* }
|
2736
|
+
* })
|
2737
|
+
* ```
|
2738
|
+
*/
|
2739
|
+
body?: object;
|
2740
|
+
/**
|
2741
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
2742
|
+
or to provide a custom fetch implementation for e.g. testing.
|
2743
|
+
*/
|
2744
|
+
fetch?: FetchFunction;
|
2745
|
+
/**
|
2746
|
+
* When a function is provided, it will be used
|
2747
|
+
* to prepare the request body for the chat API. This can be useful for
|
2748
|
+
* customizing the request body based on the messages and data in the chat.
|
2749
|
+
*
|
2750
|
+
* @param id The id of the chat.
|
2751
|
+
* @param messages The current messages in the chat.
|
2752
|
+
* @param requestBody The request body object passed in the chat request.
|
2753
|
+
*/
|
2754
|
+
prepareSendMessagesRequest?: PrepareSendMessagesRequest<UI_MESSAGE>;
|
2755
|
+
prepareReconnectToStreamRequest?: PrepareReconnectToStreamRequest;
|
2660
2756
|
};
|
2757
|
+
declare abstract class HttpChatTransport<UI_MESSAGE extends UIMessage> implements ChatTransport<UI_MESSAGE> {
|
2758
|
+
protected api: string;
|
2759
|
+
protected credentials?: RequestCredentials;
|
2760
|
+
protected headers?: Record<string, string> | Headers;
|
2761
|
+
protected body?: object;
|
2762
|
+
protected fetch: FetchFunction;
|
2763
|
+
protected prepareSendMessagesRequest?: PrepareSendMessagesRequest<UI_MESSAGE>;
|
2764
|
+
protected prepareReconnectToStreamRequest?: PrepareReconnectToStreamRequest;
|
2765
|
+
constructor({ api, credentials, headers, body, fetch, prepareSendMessagesRequest, prepareReconnectToStreamRequest, }: HttpChatTransportInitOptions<UI_MESSAGE>);
|
2766
|
+
sendMessages({ abortSignal, ...options }: Parameters<ChatTransport<UI_MESSAGE>['sendMessages']>[0]): Promise<ReadableStream<UIMessageStreamPart>>;
|
2767
|
+
reconnectToStream(options: Parameters<ChatTransport<UI_MESSAGE>['reconnectToStream']>[0]): Promise<ReadableStream<UIMessageStreamPart> | null>;
|
2768
|
+
protected abstract processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageStreamPart>;
|
2769
|
+
}
|
2661
2770
|
|
2662
|
-
declare class DefaultChatTransport<UI_MESSAGE extends UIMessage>
|
2663
|
-
|
2664
|
-
|
2665
|
-
private headers?;
|
2666
|
-
private body?;
|
2667
|
-
private fetch?;
|
2668
|
-
private prepareRequest?;
|
2669
|
-
constructor({ api, credentials, headers, body, fetch, prepareRequest, }?: {
|
2670
|
-
api?: string;
|
2671
|
-
/**
|
2672
|
-
* The credentials mode to be used for the fetch request.
|
2673
|
-
* Possible values are: 'omit', 'same-origin', 'include'.
|
2674
|
-
* Defaults to 'same-origin'.
|
2675
|
-
*/
|
2676
|
-
credentials?: RequestCredentials;
|
2677
|
-
/**
|
2678
|
-
* HTTP headers to be sent with the API request.
|
2679
|
-
*/
|
2680
|
-
headers?: Record<string, string> | Headers;
|
2681
|
-
/**
|
2682
|
-
* Extra body object to be sent with the API request.
|
2683
|
-
* @example
|
2684
|
-
* Send a `sessionId` to the API along with the messages.
|
2685
|
-
* ```js
|
2686
|
-
* useChat({
|
2687
|
-
* body: {
|
2688
|
-
* sessionId: '123',
|
2689
|
-
* }
|
2690
|
-
* })
|
2691
|
-
* ```
|
2692
|
-
*/
|
2693
|
-
body?: object;
|
2694
|
-
/**
|
2695
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
2696
|
-
or to provide a custom fetch implementation for e.g. testing.
|
2697
|
-
*/
|
2698
|
-
fetch?: FetchFunction;
|
2699
|
-
/**
|
2700
|
-
* When a function is provided, it will be used
|
2701
|
-
* to prepare the request body for the chat API. This can be useful for
|
2702
|
-
* customizing the request body based on the messages and data in the chat.
|
2703
|
-
*
|
2704
|
-
* @param id The id of the chat.
|
2705
|
-
* @param messages The current messages in the chat.
|
2706
|
-
* @param requestBody The request body object passed in the chat request.
|
2707
|
-
*/
|
2708
|
-
prepareRequest?: PrepareRequest<UI_MESSAGE>;
|
2709
|
-
});
|
2710
|
-
submitMessages({ chatId, messages, abortSignal, metadata, headers, body, requestType, }: Parameters<ChatTransport<UI_MESSAGE>['submitMessages']>[0]): Promise<ReadableStream<UIMessageStreamPart>>;
|
2771
|
+
declare class DefaultChatTransport<UI_MESSAGE extends UIMessage> extends HttpChatTransport<UI_MESSAGE> {
|
2772
|
+
constructor(options?: HttpChatTransportInitOptions<UI_MESSAGE>);
|
2773
|
+
protected processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageStreamPart>;
|
2711
2774
|
}
|
2712
2775
|
|
2713
|
-
declare class TextStreamChatTransport<UI_MESSAGE extends UIMessage>
|
2714
|
-
|
2715
|
-
|
2716
|
-
private headers?;
|
2717
|
-
private body?;
|
2718
|
-
private fetch?;
|
2719
|
-
private prepareRequest?;
|
2720
|
-
constructor({ api, credentials, headers, body, fetch, prepareRequest, }: {
|
2721
|
-
api: string;
|
2722
|
-
/**
|
2723
|
-
* The credentials mode to be used for the fetch request.
|
2724
|
-
* Possible values are: 'omit', 'same-origin', 'include'.
|
2725
|
-
* Defaults to 'same-origin'.
|
2726
|
-
*/
|
2727
|
-
credentials?: RequestCredentials;
|
2728
|
-
/**
|
2729
|
-
* HTTP headers to be sent with the API request.
|
2730
|
-
*/
|
2731
|
-
headers?: Record<string, string> | Headers;
|
2732
|
-
/**
|
2733
|
-
* Extra body object to be sent with the API request.
|
2734
|
-
* @example
|
2735
|
-
* Send a `sessionId` to the API along with the messages.
|
2736
|
-
* ```js
|
2737
|
-
* useChat({
|
2738
|
-
* body: {
|
2739
|
-
* sessionId: '123',
|
2740
|
-
* }
|
2741
|
-
* })
|
2742
|
-
* ```
|
2743
|
-
*/
|
2744
|
-
body?: object;
|
2745
|
-
/**
|
2746
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
2747
|
-
or to provide a custom fetch implementation for e.g. testing.
|
2748
|
-
*/
|
2749
|
-
fetch?: FetchFunction;
|
2750
|
-
/**
|
2751
|
-
* When a function is provided, it will be used
|
2752
|
-
* to prepare the request body for the chat API. This can be useful for
|
2753
|
-
* customizing the request body based on the messages and data in the chat.
|
2754
|
-
*
|
2755
|
-
* @param id The id of the chat.
|
2756
|
-
* @param messages The current messages in the chat.
|
2757
|
-
* @param requestBody The request body object passed in the chat request.
|
2758
|
-
*/
|
2759
|
-
prepareRequest?: NoInfer<PrepareRequest<UI_MESSAGE>>;
|
2760
|
-
});
|
2761
|
-
submitMessages({ chatId, messages, abortSignal, metadata, headers, body, requestType, }: Parameters<ChatTransport<UI_MESSAGE>['submitMessages']>[0]): Promise<ReadableStream<UIMessageStreamPart<never, never>>>;
|
2776
|
+
declare class TextStreamChatTransport<UI_MESSAGE extends UIMessage> extends HttpChatTransport<UI_MESSAGE> {
|
2777
|
+
constructor(options?: HttpChatTransportInitOptions<UI_MESSAGE>);
|
2778
|
+
protected processResponseStream(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): ReadableStream<UIMessageStreamPart>;
|
2762
2779
|
}
|
2763
2780
|
|
2764
2781
|
type CompletionRequestOptions = {
|
@@ -3646,7 +3663,7 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3646
3663
|
@param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
3647
3664
|
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
3648
3665
|
*/
|
3649
|
-
pipeUIMessageStreamToResponse<UI_MESSAGE extends UIMessage>(response: ServerResponse, options?:
|
3666
|
+
pipeUIMessageStreamToResponse<UI_MESSAGE extends UIMessage>(response: ServerResponse, options?: UIMessageStreamResponseInit & UIMessageStreamOptions<UI_MESSAGE>): void;
|
3650
3667
|
/**
|
3651
3668
|
Writes text delta output to a Node.js response-like object.
|
3652
3669
|
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
@@ -3666,7 +3683,7 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3666
3683
|
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
3667
3684
|
@return A response object.
|
3668
3685
|
*/
|
3669
|
-
toUIMessageStreamResponse<UI_MESSAGE extends UIMessage>(options?:
|
3686
|
+
toUIMessageStreamResponse<UI_MESSAGE extends UIMessage>(options?: UIMessageStreamResponseInit & UIMessageStreamOptions<UI_MESSAGE>): Response;
|
3670
3687
|
/**
|
3671
3688
|
Creates a simple text stream response.
|
3672
3689
|
Each text delta is encoded as UTF-8 and sent as a separate chunk.
|
@@ -3685,7 +3702,7 @@ type TextStreamPart<TOOLS extends ToolSet> = ContentPart<TOOLS> | {
|
|
3685
3702
|
type: 'tool-call-delta';
|
3686
3703
|
toolCallId: string;
|
3687
3704
|
toolName: string;
|
3688
|
-
|
3705
|
+
inputTextDelta: string;
|
3689
3706
|
} | {
|
3690
3707
|
type: 'start-step';
|
3691
3708
|
request: LanguageModelRequestMetadata;
|
@@ -4829,4 +4846,8 @@ declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetr
|
|
4829
4846
|
headers?: Record<string, string>;
|
4830
4847
|
}): Promise<TranscriptionResult>;
|
4831
4848
|
|
4832
|
-
|
4849
|
+
declare global {
|
4850
|
+
var AI_SDK_DEFAULT_PROVIDER: ProviderV2 | undefined;
|
4851
|
+
}
|
4852
|
+
|
4853
|
+
export { AbstractChat, AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatInit, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InferUIDataParts, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolInputError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, ModelMessage, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SerialJobExecutor, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamChatTransport, TextStreamPart, TextUIPart, Tool, ToolCallOptions, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessagePart, UIMessageStreamOptions, UIMessageStreamPart, UIMessageStreamWriter, UI_MESSAGE_STREAM_HEADERS, UseCompletionOptions, UserContent, UserModelMessage, 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, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, userModelMessageSchema, wrapLanguageModel };
|