ai 5.0.0-canary.21 → 5.0.0-canary.22
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 +9 -0
- package/README.md +1 -1
- package/dist/index.d.mts +574 -593
- package/dist/index.d.ts +574 -593
- package/dist/index.js +190 -202
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +187 -199
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -1,375 +1,12 @@
|
|
1
1
|
import { ToolResultContent, Schema, ToolCall, ToolResult, IdGenerator, FetchFunction } from '@ai-sdk/provider-utils';
|
2
2
|
export { IdGenerator, Schema, ToolCall, ToolResult, asSchema, createIdGenerator, generateId, jsonSchema } from '@ai-sdk/provider-utils';
|
3
|
-
import { z } from 'zod';
|
4
|
-
import { ServerResponse } from 'node:http';
|
5
3
|
import { AISDKError, SharedV2ProviderMetadata, SharedV2ProviderOptions, EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SpeechModelV1, SpeechModelV1CallWarning, TranscriptionModelV1, TranscriptionModelV1CallWarning, LanguageModelV2Usage, JSONObject, LanguageModelV2ToolCall, JSONSchema7, LanguageModelV2CallOptions, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
6
4
|
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
5
|
+
import { z } from 'zod';
|
6
|
+
import { ServerResponse } from 'node:http';
|
7
7
|
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
8
8
|
import { ServerResponse as ServerResponse$1 } from 'http';
|
9
9
|
|
10
|
-
declare const dataStreamPartSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
11
|
-
type: z.ZodLiteral<"text">;
|
12
|
-
value: z.ZodString;
|
13
|
-
}, "strip", z.ZodTypeAny, {
|
14
|
-
type: "text";
|
15
|
-
value: string;
|
16
|
-
}, {
|
17
|
-
type: "text";
|
18
|
-
value: string;
|
19
|
-
}>, z.ZodObject<{
|
20
|
-
type: z.ZodLiteral<"error">;
|
21
|
-
value: z.ZodString;
|
22
|
-
}, "strip", z.ZodTypeAny, {
|
23
|
-
type: "error";
|
24
|
-
value: string;
|
25
|
-
}, {
|
26
|
-
type: "error";
|
27
|
-
value: string;
|
28
|
-
}>, z.ZodObject<{
|
29
|
-
type: z.ZodLiteral<"tool-call">;
|
30
|
-
value: z.ZodObject<{
|
31
|
-
toolCallId: z.ZodString;
|
32
|
-
toolName: z.ZodString;
|
33
|
-
args: z.ZodUnknown;
|
34
|
-
}, "strip", z.ZodTypeAny, {
|
35
|
-
toolCallId: string;
|
36
|
-
toolName: string;
|
37
|
-
args?: unknown;
|
38
|
-
}, {
|
39
|
-
toolCallId: string;
|
40
|
-
toolName: string;
|
41
|
-
args?: unknown;
|
42
|
-
}>;
|
43
|
-
}, "strip", z.ZodTypeAny, {
|
44
|
-
type: "tool-call";
|
45
|
-
value: {
|
46
|
-
toolCallId: string;
|
47
|
-
toolName: string;
|
48
|
-
args?: unknown;
|
49
|
-
};
|
50
|
-
}, {
|
51
|
-
type: "tool-call";
|
52
|
-
value: {
|
53
|
-
toolCallId: string;
|
54
|
-
toolName: string;
|
55
|
-
args?: unknown;
|
56
|
-
};
|
57
|
-
}>, z.ZodObject<{
|
58
|
-
type: z.ZodLiteral<"tool-result">;
|
59
|
-
value: z.ZodObject<{
|
60
|
-
toolCallId: z.ZodString;
|
61
|
-
result: z.ZodUnknown;
|
62
|
-
providerMetadata: z.ZodOptional<z.ZodAny>;
|
63
|
-
}, "strip", z.ZodTypeAny, {
|
64
|
-
toolCallId: string;
|
65
|
-
result?: unknown;
|
66
|
-
providerMetadata?: any;
|
67
|
-
}, {
|
68
|
-
toolCallId: string;
|
69
|
-
result?: unknown;
|
70
|
-
providerMetadata?: any;
|
71
|
-
}>;
|
72
|
-
}, "strip", z.ZodTypeAny, {
|
73
|
-
type: "tool-result";
|
74
|
-
value: {
|
75
|
-
toolCallId: string;
|
76
|
-
result?: unknown;
|
77
|
-
providerMetadata?: any;
|
78
|
-
};
|
79
|
-
}, {
|
80
|
-
type: "tool-result";
|
81
|
-
value: {
|
82
|
-
toolCallId: string;
|
83
|
-
result?: unknown;
|
84
|
-
providerMetadata?: any;
|
85
|
-
};
|
86
|
-
}>, z.ZodObject<{
|
87
|
-
type: z.ZodLiteral<"tool-call-streaming-start">;
|
88
|
-
value: z.ZodObject<{
|
89
|
-
toolCallId: z.ZodString;
|
90
|
-
toolName: z.ZodString;
|
91
|
-
}, "strip", z.ZodTypeAny, {
|
92
|
-
toolCallId: string;
|
93
|
-
toolName: string;
|
94
|
-
}, {
|
95
|
-
toolCallId: string;
|
96
|
-
toolName: string;
|
97
|
-
}>;
|
98
|
-
}, "strip", z.ZodTypeAny, {
|
99
|
-
type: "tool-call-streaming-start";
|
100
|
-
value: {
|
101
|
-
toolCallId: string;
|
102
|
-
toolName: string;
|
103
|
-
};
|
104
|
-
}, {
|
105
|
-
type: "tool-call-streaming-start";
|
106
|
-
value: {
|
107
|
-
toolCallId: string;
|
108
|
-
toolName: string;
|
109
|
-
};
|
110
|
-
}>, z.ZodObject<{
|
111
|
-
type: z.ZodLiteral<"tool-call-delta">;
|
112
|
-
value: z.ZodObject<{
|
113
|
-
toolCallId: z.ZodString;
|
114
|
-
argsTextDelta: z.ZodString;
|
115
|
-
}, "strip", z.ZodTypeAny, {
|
116
|
-
toolCallId: string;
|
117
|
-
argsTextDelta: string;
|
118
|
-
}, {
|
119
|
-
toolCallId: string;
|
120
|
-
argsTextDelta: string;
|
121
|
-
}>;
|
122
|
-
}, "strip", z.ZodTypeAny, {
|
123
|
-
type: "tool-call-delta";
|
124
|
-
value: {
|
125
|
-
toolCallId: string;
|
126
|
-
argsTextDelta: string;
|
127
|
-
};
|
128
|
-
}, {
|
129
|
-
type: "tool-call-delta";
|
130
|
-
value: {
|
131
|
-
toolCallId: string;
|
132
|
-
argsTextDelta: string;
|
133
|
-
};
|
134
|
-
}>, z.ZodObject<{
|
135
|
-
type: z.ZodLiteral<"reasoning">;
|
136
|
-
value: z.ZodObject<{
|
137
|
-
text: z.ZodString;
|
138
|
-
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
139
|
-
}, "strip", z.ZodTypeAny, {
|
140
|
-
text: string;
|
141
|
-
providerMetadata?: Record<string, any> | undefined;
|
142
|
-
}, {
|
143
|
-
text: string;
|
144
|
-
providerMetadata?: Record<string, any> | undefined;
|
145
|
-
}>;
|
146
|
-
}, "strip", z.ZodTypeAny, {
|
147
|
-
type: "reasoning";
|
148
|
-
value: {
|
149
|
-
text: string;
|
150
|
-
providerMetadata?: Record<string, any> | undefined;
|
151
|
-
};
|
152
|
-
}, {
|
153
|
-
type: "reasoning";
|
154
|
-
value: {
|
155
|
-
text: string;
|
156
|
-
providerMetadata?: Record<string, any> | undefined;
|
157
|
-
};
|
158
|
-
}>, z.ZodObject<{
|
159
|
-
type: z.ZodLiteral<"source">;
|
160
|
-
value: z.ZodObject<{
|
161
|
-
type: z.ZodLiteral<"source">;
|
162
|
-
sourceType: z.ZodLiteral<"url">;
|
163
|
-
id: z.ZodString;
|
164
|
-
url: z.ZodString;
|
165
|
-
title: z.ZodOptional<z.ZodString>;
|
166
|
-
providerMetadata: z.ZodOptional<z.ZodAny>;
|
167
|
-
}, "strip", z.ZodTypeAny, {
|
168
|
-
type: "source";
|
169
|
-
sourceType: "url";
|
170
|
-
url: string;
|
171
|
-
id: string;
|
172
|
-
providerMetadata?: any;
|
173
|
-
title?: string | undefined;
|
174
|
-
}, {
|
175
|
-
type: "source";
|
176
|
-
sourceType: "url";
|
177
|
-
url: string;
|
178
|
-
id: string;
|
179
|
-
providerMetadata?: any;
|
180
|
-
title?: string | undefined;
|
181
|
-
}>;
|
182
|
-
}, "strip", z.ZodTypeAny, {
|
183
|
-
type: "source";
|
184
|
-
value: {
|
185
|
-
type: "source";
|
186
|
-
sourceType: "url";
|
187
|
-
url: string;
|
188
|
-
id: string;
|
189
|
-
providerMetadata?: any;
|
190
|
-
title?: string | undefined;
|
191
|
-
};
|
192
|
-
}, {
|
193
|
-
type: "source";
|
194
|
-
value: {
|
195
|
-
type: "source";
|
196
|
-
sourceType: "url";
|
197
|
-
url: string;
|
198
|
-
id: string;
|
199
|
-
providerMetadata?: any;
|
200
|
-
title?: string | undefined;
|
201
|
-
};
|
202
|
-
}>, z.ZodObject<{
|
203
|
-
type: z.ZodLiteral<"file">;
|
204
|
-
value: z.ZodObject<{
|
205
|
-
url: z.ZodString;
|
206
|
-
mediaType: z.ZodString;
|
207
|
-
}, "strip", z.ZodTypeAny, {
|
208
|
-
url: string;
|
209
|
-
mediaType: string;
|
210
|
-
}, {
|
211
|
-
url: string;
|
212
|
-
mediaType: string;
|
213
|
-
}>;
|
214
|
-
}, "strip", z.ZodTypeAny, {
|
215
|
-
type: "file";
|
216
|
-
value: {
|
217
|
-
url: string;
|
218
|
-
mediaType: string;
|
219
|
-
};
|
220
|
-
}, {
|
221
|
-
type: "file";
|
222
|
-
value: {
|
223
|
-
url: string;
|
224
|
-
mediaType: string;
|
225
|
-
};
|
226
|
-
}>, z.ZodObject<{
|
227
|
-
type: z.ZodLiteral<"metadata">;
|
228
|
-
value: z.ZodObject<{
|
229
|
-
metadata: z.ZodUnknown;
|
230
|
-
}, "strip", z.ZodTypeAny, {
|
231
|
-
metadata?: unknown;
|
232
|
-
}, {
|
233
|
-
metadata?: unknown;
|
234
|
-
}>;
|
235
|
-
}, "strip", z.ZodTypeAny, {
|
236
|
-
type: "metadata";
|
237
|
-
value: {
|
238
|
-
metadata?: unknown;
|
239
|
-
};
|
240
|
-
}, {
|
241
|
-
type: "metadata";
|
242
|
-
value: {
|
243
|
-
metadata?: unknown;
|
244
|
-
};
|
245
|
-
}>, z.ZodObject<{
|
246
|
-
type: z.ZodLiteral<"start-step">;
|
247
|
-
value: z.ZodObject<{
|
248
|
-
metadata: z.ZodUnknown;
|
249
|
-
}, "strip", z.ZodTypeAny, {
|
250
|
-
metadata?: unknown;
|
251
|
-
}, {
|
252
|
-
metadata?: unknown;
|
253
|
-
}>;
|
254
|
-
}, "strip", z.ZodTypeAny, {
|
255
|
-
type: "start-step";
|
256
|
-
value: {
|
257
|
-
metadata?: unknown;
|
258
|
-
};
|
259
|
-
}, {
|
260
|
-
type: "start-step";
|
261
|
-
value: {
|
262
|
-
metadata?: unknown;
|
263
|
-
};
|
264
|
-
}>, z.ZodObject<{
|
265
|
-
type: z.ZodLiteral<"finish-step">;
|
266
|
-
value: z.ZodObject<{
|
267
|
-
metadata: z.ZodUnknown;
|
268
|
-
}, "strip", z.ZodTypeAny, {
|
269
|
-
metadata?: unknown;
|
270
|
-
}, {
|
271
|
-
metadata?: unknown;
|
272
|
-
}>;
|
273
|
-
}, "strip", z.ZodTypeAny, {
|
274
|
-
type: "finish-step";
|
275
|
-
value: {
|
276
|
-
metadata?: unknown;
|
277
|
-
};
|
278
|
-
}, {
|
279
|
-
type: "finish-step";
|
280
|
-
value: {
|
281
|
-
metadata?: unknown;
|
282
|
-
};
|
283
|
-
}>, z.ZodObject<{
|
284
|
-
type: z.ZodLiteral<"start">;
|
285
|
-
value: z.ZodObject<{
|
286
|
-
messageId: z.ZodOptional<z.ZodString>;
|
287
|
-
metadata: z.ZodUnknown;
|
288
|
-
}, "strip", z.ZodTypeAny, {
|
289
|
-
metadata?: unknown;
|
290
|
-
messageId?: string | undefined;
|
291
|
-
}, {
|
292
|
-
metadata?: unknown;
|
293
|
-
messageId?: string | undefined;
|
294
|
-
}>;
|
295
|
-
}, "strip", z.ZodTypeAny, {
|
296
|
-
type: "start";
|
297
|
-
value: {
|
298
|
-
metadata?: unknown;
|
299
|
-
messageId?: string | undefined;
|
300
|
-
};
|
301
|
-
}, {
|
302
|
-
type: "start";
|
303
|
-
value: {
|
304
|
-
metadata?: unknown;
|
305
|
-
messageId?: string | undefined;
|
306
|
-
};
|
307
|
-
}>, z.ZodObject<{
|
308
|
-
type: z.ZodLiteral<"finish">;
|
309
|
-
value: z.ZodObject<{
|
310
|
-
metadata: z.ZodUnknown;
|
311
|
-
}, "strip", z.ZodTypeAny, {
|
312
|
-
metadata?: unknown;
|
313
|
-
}, {
|
314
|
-
metadata?: unknown;
|
315
|
-
}>;
|
316
|
-
}, "strip", z.ZodTypeAny, {
|
317
|
-
type: "finish";
|
318
|
-
value: {
|
319
|
-
metadata?: unknown;
|
320
|
-
};
|
321
|
-
}, {
|
322
|
-
type: "finish";
|
323
|
-
value: {
|
324
|
-
metadata?: unknown;
|
325
|
-
};
|
326
|
-
}>, z.ZodObject<{
|
327
|
-
type: z.ZodLiteral<"reasoning-part-finish">;
|
328
|
-
value: z.ZodNull;
|
329
|
-
}, "strip", z.ZodTypeAny, {
|
330
|
-
type: "reasoning-part-finish";
|
331
|
-
value: null;
|
332
|
-
}, {
|
333
|
-
type: "reasoning-part-finish";
|
334
|
-
value: null;
|
335
|
-
}>]>;
|
336
|
-
type DataStreamPart = z.infer<typeof dataStreamPartSchema>;
|
337
|
-
|
338
|
-
interface DataStreamWriter {
|
339
|
-
/**
|
340
|
-
* Appends a data stream part to the stream.
|
341
|
-
*/
|
342
|
-
write(part: DataStreamPart): void;
|
343
|
-
/**
|
344
|
-
* Merges the contents of another stream to this stream.
|
345
|
-
*/
|
346
|
-
merge(stream: ReadableStream<DataStreamPart>): void;
|
347
|
-
/**
|
348
|
-
* Error handler that is used by the data stream writer.
|
349
|
-
* This is intended for forwarding when merging streams
|
350
|
-
* to prevent duplicated error masking.
|
351
|
-
*/
|
352
|
-
onError: ((error: unknown) => string) | undefined;
|
353
|
-
}
|
354
|
-
|
355
|
-
declare function createDataStream({ execute, onError, }: {
|
356
|
-
execute: (writer: DataStreamWriter) => Promise<void> | void;
|
357
|
-
onError?: (error: unknown) => string;
|
358
|
-
}): ReadableStream<DataStreamPart>;
|
359
|
-
|
360
|
-
declare function createDataStreamResponse({ status, statusText, headers, dataStream, }: ResponseInit & {
|
361
|
-
dataStream: ReadableStream<DataStreamPart>;
|
362
|
-
}): Response;
|
363
|
-
|
364
|
-
declare function pipeDataStreamToResponse({ response, status, statusText, headers, dataStream, }: {
|
365
|
-
response: ServerResponse;
|
366
|
-
dataStream: ReadableStream<DataStreamPart>;
|
367
|
-
} & ResponseInit): void;
|
368
|
-
|
369
|
-
declare class JsonToSseTransformStream extends TransformStream<unknown, string> {
|
370
|
-
constructor();
|
371
|
-
}
|
372
|
-
|
373
10
|
declare const symbol$f: unique symbol;
|
374
11
|
declare class InvalidArgumentError extends AISDKError {
|
375
12
|
private readonly [symbol$f];
|
@@ -1037,29 +674,29 @@ declare const JSONRPCErrorSchema: z.ZodObject<{
|
|
1037
674
|
message: z.ZodString;
|
1038
675
|
data: z.ZodOptional<z.ZodUnknown>;
|
1039
676
|
}, "strip", z.ZodTypeAny, {
|
1040
|
-
code: number;
|
1041
677
|
message: string;
|
678
|
+
code: number;
|
1042
679
|
data?: unknown;
|
1043
680
|
}, {
|
1044
|
-
code: number;
|
1045
681
|
message: string;
|
682
|
+
code: number;
|
1046
683
|
data?: unknown;
|
1047
684
|
}>;
|
1048
685
|
}, "strict", z.ZodTypeAny, {
|
1049
|
-
id: string | number;
|
1050
686
|
error: {
|
1051
|
-
code: number;
|
1052
687
|
message: string;
|
688
|
+
code: number;
|
1053
689
|
data?: unknown;
|
1054
690
|
};
|
691
|
+
id: string | number;
|
1055
692
|
jsonrpc: "2.0";
|
1056
693
|
}, {
|
1057
|
-
id: string | number;
|
1058
694
|
error: {
|
1059
|
-
code: number;
|
1060
695
|
message: string;
|
696
|
+
code: number;
|
1061
697
|
data?: unknown;
|
1062
698
|
};
|
699
|
+
id: string | number;
|
1063
700
|
jsonrpc: "2.0";
|
1064
701
|
}>;
|
1065
702
|
type JSONRPCError = z.infer<typeof JSONRPCErrorSchema>;
|
@@ -1171,29 +808,29 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
|
|
1171
808
|
message: z.ZodString;
|
1172
809
|
data: z.ZodOptional<z.ZodUnknown>;
|
1173
810
|
}, "strip", z.ZodTypeAny, {
|
1174
|
-
code: number;
|
1175
811
|
message: string;
|
812
|
+
code: number;
|
1176
813
|
data?: unknown;
|
1177
814
|
}, {
|
1178
|
-
code: number;
|
1179
815
|
message: string;
|
816
|
+
code: number;
|
1180
817
|
data?: unknown;
|
1181
818
|
}>;
|
1182
819
|
}, "strict", z.ZodTypeAny, {
|
1183
|
-
id: string | number;
|
1184
820
|
error: {
|
1185
|
-
code: number;
|
1186
821
|
message: string;
|
822
|
+
code: number;
|
1187
823
|
data?: unknown;
|
1188
824
|
};
|
825
|
+
id: string | number;
|
1189
826
|
jsonrpc: "2.0";
|
1190
827
|
}, {
|
1191
|
-
id: string | number;
|
1192
828
|
error: {
|
1193
|
-
code: number;
|
1194
829
|
message: string;
|
830
|
+
code: number;
|
1195
831
|
data?: unknown;
|
1196
832
|
};
|
833
|
+
id: string | number;
|
1197
834
|
jsonrpc: "2.0";
|
1198
835
|
}>]>;
|
1199
836
|
type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
|
@@ -2659,14 +2296,6 @@ type ChatRequestOptions = {
|
|
2659
2296
|
Additional body JSON properties that should be sent to the API endpoint.
|
2660
2297
|
*/
|
2661
2298
|
body?: object;
|
2662
|
-
/**
|
2663
|
-
Additional data to be sent to the API endpoint.
|
2664
|
-
*/
|
2665
|
-
data?: JSONValue$1;
|
2666
|
-
/**
|
2667
|
-
* Allow submitting an empty message. Defaults to `false`.
|
2668
|
-
*/
|
2669
|
-
allowEmptySubmit?: boolean;
|
2670
2299
|
};
|
2671
2300
|
type UseChatOptions<MESSAGE_METADATA = unknown> = {
|
2672
2301
|
/**
|
@@ -2703,10 +2332,6 @@ type UseChatOptions<MESSAGE_METADATA = unknown> = {
|
|
2703
2332
|
onToolCall?: ({ toolCall, }: {
|
2704
2333
|
toolCall: ToolCall<string, unknown>;
|
2705
2334
|
}) => void | Promise<unknown> | unknown;
|
2706
|
-
/**
|
2707
|
-
* Callback function to be called when the API response is received.
|
2708
|
-
*/
|
2709
|
-
onResponse?: (response: Response) => void | Promise<void>;
|
2710
2335
|
/**
|
2711
2336
|
* Optional callback function that is called when the assistant message is finished streaming.
|
2712
2337
|
*
|
@@ -2731,209 +2356,566 @@ type UseChatOptions<MESSAGE_METADATA = unknown> = {
|
|
2731
2356
|
*/
|
2732
2357
|
credentials?: RequestCredentials;
|
2733
2358
|
/**
|
2734
|
-
* HTTP headers to be sent with the API request.
|
2359
|
+
* HTTP headers to be sent with the API request.
|
2360
|
+
*/
|
2361
|
+
headers?: Record<string, string> | Headers;
|
2362
|
+
/**
|
2363
|
+
* Extra body object to be sent with the API request.
|
2364
|
+
* @example
|
2365
|
+
* Send a `sessionId` to the API along with the messages.
|
2366
|
+
* ```js
|
2367
|
+
* useChat({
|
2368
|
+
* body: {
|
2369
|
+
* sessionId: '123',
|
2370
|
+
* }
|
2371
|
+
* })
|
2372
|
+
* ```
|
2373
|
+
*/
|
2374
|
+
body?: object;
|
2375
|
+
/**
|
2376
|
+
Streaming protocol that is used. Defaults to `ui-message`.
|
2377
|
+
*/
|
2378
|
+
streamProtocol?: 'ui-message' | 'text';
|
2379
|
+
/**
|
2380
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
2381
|
+
or to provide a custom fetch implementation for e.g. testing.
|
2382
|
+
*/
|
2383
|
+
fetch?: FetchFunction;
|
2384
|
+
/**
|
2385
|
+
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
2386
|
+
Must be at least 1.
|
2387
|
+
|
2388
|
+
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
2389
|
+
|
2390
|
+
By default, it's set to 1, which means that only a single LLM call is made.
|
2391
|
+
*/
|
2392
|
+
maxSteps?: number;
|
2393
|
+
};
|
2394
|
+
|
2395
|
+
declare const getOriginalFetch$1: () => typeof fetch;
|
2396
|
+
declare function callChatApi<MESSAGE_METADATA>({ api, body, streamProtocol, credentials, headers, abortController, onUpdate, onFinish, onToolCall, generateId, fetch, lastMessage, requestType, messageMetadataSchema, }: {
|
2397
|
+
api: string;
|
2398
|
+
body: Record<string, any>;
|
2399
|
+
streamProtocol: 'ui-message' | 'text' | undefined;
|
2400
|
+
credentials: RequestCredentials | undefined;
|
2401
|
+
headers: HeadersInit | undefined;
|
2402
|
+
abortController: (() => AbortController | null) | undefined;
|
2403
|
+
onUpdate: (options: {
|
2404
|
+
message: UIMessage<MESSAGE_METADATA>;
|
2405
|
+
}) => void;
|
2406
|
+
onFinish: UseChatOptions<MESSAGE_METADATA>['onFinish'];
|
2407
|
+
onToolCall: UseChatOptions<MESSAGE_METADATA>['onToolCall'];
|
2408
|
+
generateId: IdGenerator;
|
2409
|
+
fetch: ReturnType<typeof getOriginalFetch$1> | undefined;
|
2410
|
+
lastMessage: UIMessage<MESSAGE_METADATA> | undefined;
|
2411
|
+
requestType?: 'generate' | 'resume';
|
2412
|
+
messageMetadataSchema?: Schema<MESSAGE_METADATA>;
|
2413
|
+
}): Promise<void>;
|
2414
|
+
|
2415
|
+
declare const getOriginalFetch: () => typeof fetch;
|
2416
|
+
declare function callCompletionApi({ api, prompt, credentials, headers, body, streamProtocol, setCompletion, setLoading, setError, setAbortController, onFinish, onError, fetch, }: {
|
2417
|
+
api: string;
|
2418
|
+
prompt: string;
|
2419
|
+
credentials: RequestCredentials | undefined;
|
2420
|
+
headers: HeadersInit | undefined;
|
2421
|
+
body: Record<string, any>;
|
2422
|
+
streamProtocol: 'data' | 'text' | undefined;
|
2423
|
+
setCompletion: (completion: string) => void;
|
2424
|
+
setLoading: (loading: boolean) => void;
|
2425
|
+
setError: (error: Error | undefined) => void;
|
2426
|
+
setAbortController: (abortController: AbortController | null) => void;
|
2427
|
+
onFinish: ((prompt: string, completion: string) => void) | undefined;
|
2428
|
+
onError: ((error: Error) => void) | undefined;
|
2429
|
+
fetch: ReturnType<typeof getOriginalFetch> | undefined;
|
2430
|
+
}): Promise<string | null | undefined>;
|
2431
|
+
|
2432
|
+
declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
|
2433
|
+
|
2434
|
+
/**
|
2435
|
+
Converts an array of messages from useChat into an array of CoreMessages that can be used
|
2436
|
+
with the AI core functions (e.g. `streamText`).
|
2437
|
+
*/
|
2438
|
+
declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<UIMessage, 'id'>>, options?: {
|
2439
|
+
tools?: TOOLS;
|
2440
|
+
}): ModelMessage[];
|
2441
|
+
/**
|
2442
|
+
@deprecated Use `convertToModelMessages` instead.
|
2443
|
+
*/
|
2444
|
+
declare const convertToCoreMessages: typeof convertToModelMessages;
|
2445
|
+
|
2446
|
+
declare function extractMaxToolInvocationStep(toolInvocations: ToolInvocation[] | undefined): number | undefined;
|
2447
|
+
|
2448
|
+
declare function getToolInvocations(message: UIMessage): ToolInvocation[];
|
2449
|
+
|
2450
|
+
declare function processTextStream({ stream, onTextPart, }: {
|
2451
|
+
stream: ReadableStream<Uint8Array>;
|
2452
|
+
onTextPart: (chunk: string) => Promise<void> | void;
|
2453
|
+
}): Promise<void>;
|
2454
|
+
|
2455
|
+
declare function shouldResubmitMessages({ originalMaxToolInvocationStep, originalMessageCount, maxSteps, messages, }: {
|
2456
|
+
originalMaxToolInvocationStep: number | undefined;
|
2457
|
+
originalMessageCount: number;
|
2458
|
+
maxSteps: number;
|
2459
|
+
messages: UIMessage[];
|
2460
|
+
}): boolean;
|
2461
|
+
/**
|
2462
|
+
Check if the message is an assistant message with completed tool calls.
|
2463
|
+
The last step of the message must have at least one tool invocation and
|
2464
|
+
all tool invocations must have a result.
|
2465
|
+
*/
|
2466
|
+
declare function isAssistantMessageWithCompletedToolCalls(message: UIMessage): message is UIMessage & {
|
2467
|
+
role: 'assistant';
|
2468
|
+
};
|
2469
|
+
|
2470
|
+
/**
|
2471
|
+
* Updates the result of a specific tool invocation in the last message of the given messages array.
|
2472
|
+
*
|
2473
|
+
* @param {object} params - The parameters object.
|
2474
|
+
* @param {UIMessage[]} params.messages - An array of messages, from which the last one is updated.
|
2475
|
+
* @param {string} params.toolCallId - The unique identifier for the tool invocation to update.
|
2476
|
+
* @param {unknown} params.toolResult - The result object to attach to the tool invocation.
|
2477
|
+
* @returns {void} This function does not return anything.
|
2478
|
+
*/
|
2479
|
+
declare function updateToolCallResult({ messages, toolCallId, toolResult: result, }: {
|
2480
|
+
messages: UIMessage[];
|
2481
|
+
toolCallId: string;
|
2482
|
+
toolResult: unknown;
|
2483
|
+
}): void;
|
2484
|
+
|
2485
|
+
type CompletionRequestOptions = {
|
2486
|
+
/**
|
2487
|
+
An optional object of headers to be passed to the API endpoint.
|
2488
|
+
*/
|
2489
|
+
headers?: Record<string, string> | Headers;
|
2490
|
+
/**
|
2491
|
+
An optional object to be passed to the API endpoint.
|
2492
|
+
*/
|
2493
|
+
body?: object;
|
2494
|
+
};
|
2495
|
+
type UseCompletionOptions = {
|
2496
|
+
/**
|
2497
|
+
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
2498
|
+
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
2499
|
+
*/
|
2500
|
+
api?: string;
|
2501
|
+
/**
|
2502
|
+
* An unique identifier for the chat. If not provided, a random one will be
|
2503
|
+
* generated. When provided, the `useChat` hook with the same `id` will
|
2504
|
+
* have shared states across components.
|
2505
|
+
*/
|
2506
|
+
id?: string;
|
2507
|
+
/**
|
2508
|
+
* Initial prompt input of the completion.
|
2509
|
+
*/
|
2510
|
+
initialInput?: string;
|
2511
|
+
/**
|
2512
|
+
* Initial completion result. Useful to load an existing history.
|
2513
|
+
*/
|
2514
|
+
initialCompletion?: string;
|
2515
|
+
/**
|
2516
|
+
* Callback function to be called when the completion is finished streaming.
|
2517
|
+
*/
|
2518
|
+
onFinish?: (prompt: string, completion: string) => void;
|
2519
|
+
/**
|
2520
|
+
* Callback function to be called when an error is encountered.
|
2521
|
+
*/
|
2522
|
+
onError?: (error: Error) => void;
|
2523
|
+
/**
|
2524
|
+
* The credentials mode to be used for the fetch request.
|
2525
|
+
* Possible values are: 'omit', 'same-origin', 'include'.
|
2526
|
+
* Defaults to 'same-origin'.
|
2527
|
+
*/
|
2528
|
+
credentials?: RequestCredentials;
|
2529
|
+
/**
|
2530
|
+
* HTTP headers to be sent with the API request.
|
2531
|
+
*/
|
2532
|
+
headers?: Record<string, string> | Headers;
|
2533
|
+
/**
|
2534
|
+
* Extra body object to be sent with the API request.
|
2535
|
+
* @example
|
2536
|
+
* Send a `sessionId` to the API along with the prompt.
|
2537
|
+
* ```js
|
2538
|
+
* useChat({
|
2539
|
+
* body: {
|
2540
|
+
* sessionId: '123',
|
2541
|
+
* }
|
2542
|
+
* })
|
2543
|
+
* ```
|
2544
|
+
*/
|
2545
|
+
body?: object;
|
2546
|
+
/**
|
2547
|
+
Streaming protocol that is used. Defaults to `data`.
|
2548
|
+
*/
|
2549
|
+
streamProtocol?: 'data' | 'text';
|
2550
|
+
/**
|
2551
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
2552
|
+
or to provide a custom fetch implementation for e.g. testing.
|
2553
|
+
*/
|
2554
|
+
fetch?: FetchFunction;
|
2555
|
+
};
|
2556
|
+
|
2557
|
+
declare const uiMessageStreamPartSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
2558
|
+
type: z.ZodLiteral<"text">;
|
2559
|
+
value: z.ZodString;
|
2560
|
+
}, "strip", z.ZodTypeAny, {
|
2561
|
+
value: string;
|
2562
|
+
type: "text";
|
2563
|
+
}, {
|
2564
|
+
value: string;
|
2565
|
+
type: "text";
|
2566
|
+
}>, z.ZodObject<{
|
2567
|
+
type: z.ZodLiteral<"error">;
|
2568
|
+
value: z.ZodString;
|
2569
|
+
}, "strip", z.ZodTypeAny, {
|
2570
|
+
value: string;
|
2571
|
+
type: "error";
|
2572
|
+
}, {
|
2573
|
+
value: string;
|
2574
|
+
type: "error";
|
2575
|
+
}>, z.ZodObject<{
|
2576
|
+
type: z.ZodLiteral<"tool-call">;
|
2577
|
+
value: z.ZodObject<{
|
2578
|
+
toolCallId: z.ZodString;
|
2579
|
+
toolName: z.ZodString;
|
2580
|
+
args: z.ZodUnknown;
|
2581
|
+
}, "strip", z.ZodTypeAny, {
|
2582
|
+
toolName: string;
|
2583
|
+
toolCallId: string;
|
2584
|
+
args?: unknown;
|
2585
|
+
}, {
|
2586
|
+
toolName: string;
|
2587
|
+
toolCallId: string;
|
2588
|
+
args?: unknown;
|
2589
|
+
}>;
|
2590
|
+
}, "strip", z.ZodTypeAny, {
|
2591
|
+
value: {
|
2592
|
+
toolName: string;
|
2593
|
+
toolCallId: string;
|
2594
|
+
args?: unknown;
|
2595
|
+
};
|
2596
|
+
type: "tool-call";
|
2597
|
+
}, {
|
2598
|
+
value: {
|
2599
|
+
toolName: string;
|
2600
|
+
toolCallId: string;
|
2601
|
+
args?: unknown;
|
2602
|
+
};
|
2603
|
+
type: "tool-call";
|
2604
|
+
}>, z.ZodObject<{
|
2605
|
+
type: z.ZodLiteral<"tool-result">;
|
2606
|
+
value: z.ZodObject<{
|
2607
|
+
toolCallId: z.ZodString;
|
2608
|
+
result: z.ZodUnknown;
|
2609
|
+
providerMetadata: z.ZodOptional<z.ZodAny>;
|
2610
|
+
}, "strip", z.ZodTypeAny, {
|
2611
|
+
toolCallId: string;
|
2612
|
+
result?: unknown;
|
2613
|
+
providerMetadata?: any;
|
2614
|
+
}, {
|
2615
|
+
toolCallId: string;
|
2616
|
+
result?: unknown;
|
2617
|
+
providerMetadata?: any;
|
2618
|
+
}>;
|
2619
|
+
}, "strip", z.ZodTypeAny, {
|
2620
|
+
value: {
|
2621
|
+
toolCallId: string;
|
2622
|
+
result?: unknown;
|
2623
|
+
providerMetadata?: any;
|
2624
|
+
};
|
2625
|
+
type: "tool-result";
|
2626
|
+
}, {
|
2627
|
+
value: {
|
2628
|
+
toolCallId: string;
|
2629
|
+
result?: unknown;
|
2630
|
+
providerMetadata?: any;
|
2631
|
+
};
|
2632
|
+
type: "tool-result";
|
2633
|
+
}>, z.ZodObject<{
|
2634
|
+
type: z.ZodLiteral<"tool-call-streaming-start">;
|
2635
|
+
value: z.ZodObject<{
|
2636
|
+
toolCallId: z.ZodString;
|
2637
|
+
toolName: z.ZodString;
|
2638
|
+
}, "strip", z.ZodTypeAny, {
|
2639
|
+
toolName: string;
|
2640
|
+
toolCallId: string;
|
2641
|
+
}, {
|
2642
|
+
toolName: string;
|
2643
|
+
toolCallId: string;
|
2644
|
+
}>;
|
2645
|
+
}, "strip", z.ZodTypeAny, {
|
2646
|
+
value: {
|
2647
|
+
toolName: string;
|
2648
|
+
toolCallId: string;
|
2649
|
+
};
|
2650
|
+
type: "tool-call-streaming-start";
|
2651
|
+
}, {
|
2652
|
+
value: {
|
2653
|
+
toolName: string;
|
2654
|
+
toolCallId: string;
|
2655
|
+
};
|
2656
|
+
type: "tool-call-streaming-start";
|
2657
|
+
}>, z.ZodObject<{
|
2658
|
+
type: z.ZodLiteral<"tool-call-delta">;
|
2659
|
+
value: z.ZodObject<{
|
2660
|
+
toolCallId: z.ZodString;
|
2661
|
+
argsTextDelta: z.ZodString;
|
2662
|
+
}, "strip", z.ZodTypeAny, {
|
2663
|
+
toolCallId: string;
|
2664
|
+
argsTextDelta: string;
|
2665
|
+
}, {
|
2666
|
+
toolCallId: string;
|
2667
|
+
argsTextDelta: string;
|
2668
|
+
}>;
|
2669
|
+
}, "strip", z.ZodTypeAny, {
|
2670
|
+
value: {
|
2671
|
+
toolCallId: string;
|
2672
|
+
argsTextDelta: string;
|
2673
|
+
};
|
2674
|
+
type: "tool-call-delta";
|
2675
|
+
}, {
|
2676
|
+
value: {
|
2677
|
+
toolCallId: string;
|
2678
|
+
argsTextDelta: string;
|
2679
|
+
};
|
2680
|
+
type: "tool-call-delta";
|
2681
|
+
}>, z.ZodObject<{
|
2682
|
+
type: z.ZodLiteral<"reasoning">;
|
2683
|
+
value: z.ZodObject<{
|
2684
|
+
text: z.ZodString;
|
2685
|
+
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
2686
|
+
}, "strip", z.ZodTypeAny, {
|
2687
|
+
text: string;
|
2688
|
+
providerMetadata?: Record<string, any> | undefined;
|
2689
|
+
}, {
|
2690
|
+
text: string;
|
2691
|
+
providerMetadata?: Record<string, any> | undefined;
|
2692
|
+
}>;
|
2693
|
+
}, "strip", z.ZodTypeAny, {
|
2694
|
+
value: {
|
2695
|
+
text: string;
|
2696
|
+
providerMetadata?: Record<string, any> | undefined;
|
2697
|
+
};
|
2698
|
+
type: "reasoning";
|
2699
|
+
}, {
|
2700
|
+
value: {
|
2701
|
+
text: string;
|
2702
|
+
providerMetadata?: Record<string, any> | undefined;
|
2703
|
+
};
|
2704
|
+
type: "reasoning";
|
2705
|
+
}>, z.ZodObject<{
|
2706
|
+
type: z.ZodLiteral<"source">;
|
2707
|
+
value: z.ZodObject<{
|
2708
|
+
type: z.ZodLiteral<"source">;
|
2709
|
+
sourceType: z.ZodLiteral<"url">;
|
2710
|
+
id: z.ZodString;
|
2711
|
+
url: z.ZodString;
|
2712
|
+
title: z.ZodOptional<z.ZodString>;
|
2713
|
+
providerMetadata: z.ZodOptional<z.ZodAny>;
|
2714
|
+
}, "strip", z.ZodTypeAny, {
|
2715
|
+
type: "source";
|
2716
|
+
id: string;
|
2717
|
+
url: string;
|
2718
|
+
sourceType: "url";
|
2719
|
+
providerMetadata?: any;
|
2720
|
+
title?: string | undefined;
|
2721
|
+
}, {
|
2722
|
+
type: "source";
|
2723
|
+
id: string;
|
2724
|
+
url: string;
|
2725
|
+
sourceType: "url";
|
2726
|
+
providerMetadata?: any;
|
2727
|
+
title?: string | undefined;
|
2728
|
+
}>;
|
2729
|
+
}, "strip", z.ZodTypeAny, {
|
2730
|
+
value: {
|
2731
|
+
type: "source";
|
2732
|
+
id: string;
|
2733
|
+
url: string;
|
2734
|
+
sourceType: "url";
|
2735
|
+
providerMetadata?: any;
|
2736
|
+
title?: string | undefined;
|
2737
|
+
};
|
2738
|
+
type: "source";
|
2739
|
+
}, {
|
2740
|
+
value: {
|
2741
|
+
type: "source";
|
2742
|
+
id: string;
|
2743
|
+
url: string;
|
2744
|
+
sourceType: "url";
|
2745
|
+
providerMetadata?: any;
|
2746
|
+
title?: string | undefined;
|
2747
|
+
};
|
2748
|
+
type: "source";
|
2749
|
+
}>, z.ZodObject<{
|
2750
|
+
type: z.ZodLiteral<"file">;
|
2751
|
+
value: z.ZodObject<{
|
2752
|
+
url: z.ZodString;
|
2753
|
+
mediaType: z.ZodString;
|
2754
|
+
}, "strip", z.ZodTypeAny, {
|
2755
|
+
mediaType: string;
|
2756
|
+
url: string;
|
2757
|
+
}, {
|
2758
|
+
mediaType: string;
|
2759
|
+
url: string;
|
2760
|
+
}>;
|
2761
|
+
}, "strip", z.ZodTypeAny, {
|
2762
|
+
value: {
|
2763
|
+
mediaType: string;
|
2764
|
+
url: string;
|
2765
|
+
};
|
2766
|
+
type: "file";
|
2767
|
+
}, {
|
2768
|
+
value: {
|
2769
|
+
mediaType: string;
|
2770
|
+
url: string;
|
2771
|
+
};
|
2772
|
+
type: "file";
|
2773
|
+
}>, z.ZodObject<{
|
2774
|
+
type: z.ZodLiteral<"metadata">;
|
2775
|
+
value: z.ZodObject<{
|
2776
|
+
metadata: z.ZodUnknown;
|
2777
|
+
}, "strip", z.ZodTypeAny, {
|
2778
|
+
metadata?: unknown;
|
2779
|
+
}, {
|
2780
|
+
metadata?: unknown;
|
2781
|
+
}>;
|
2782
|
+
}, "strip", z.ZodTypeAny, {
|
2783
|
+
value: {
|
2784
|
+
metadata?: unknown;
|
2785
|
+
};
|
2786
|
+
type: "metadata";
|
2787
|
+
}, {
|
2788
|
+
value: {
|
2789
|
+
metadata?: unknown;
|
2790
|
+
};
|
2791
|
+
type: "metadata";
|
2792
|
+
}>, z.ZodObject<{
|
2793
|
+
type: z.ZodLiteral<"start-step">;
|
2794
|
+
value: z.ZodObject<{
|
2795
|
+
metadata: z.ZodUnknown;
|
2796
|
+
}, "strip", z.ZodTypeAny, {
|
2797
|
+
metadata?: unknown;
|
2798
|
+
}, {
|
2799
|
+
metadata?: unknown;
|
2800
|
+
}>;
|
2801
|
+
}, "strip", z.ZodTypeAny, {
|
2802
|
+
value: {
|
2803
|
+
metadata?: unknown;
|
2804
|
+
};
|
2805
|
+
type: "start-step";
|
2806
|
+
}, {
|
2807
|
+
value: {
|
2808
|
+
metadata?: unknown;
|
2809
|
+
};
|
2810
|
+
type: "start-step";
|
2811
|
+
}>, z.ZodObject<{
|
2812
|
+
type: z.ZodLiteral<"finish-step">;
|
2813
|
+
value: z.ZodObject<{
|
2814
|
+
metadata: z.ZodUnknown;
|
2815
|
+
}, "strip", z.ZodTypeAny, {
|
2816
|
+
metadata?: unknown;
|
2817
|
+
}, {
|
2818
|
+
metadata?: unknown;
|
2819
|
+
}>;
|
2820
|
+
}, "strip", z.ZodTypeAny, {
|
2821
|
+
value: {
|
2822
|
+
metadata?: unknown;
|
2823
|
+
};
|
2824
|
+
type: "finish-step";
|
2825
|
+
}, {
|
2826
|
+
value: {
|
2827
|
+
metadata?: unknown;
|
2828
|
+
};
|
2829
|
+
type: "finish-step";
|
2830
|
+
}>, z.ZodObject<{
|
2831
|
+
type: z.ZodLiteral<"start">;
|
2832
|
+
value: z.ZodObject<{
|
2833
|
+
messageId: z.ZodOptional<z.ZodString>;
|
2834
|
+
metadata: z.ZodUnknown;
|
2835
|
+
}, "strip", z.ZodTypeAny, {
|
2836
|
+
metadata?: unknown;
|
2837
|
+
messageId?: string | undefined;
|
2838
|
+
}, {
|
2839
|
+
metadata?: unknown;
|
2840
|
+
messageId?: string | undefined;
|
2841
|
+
}>;
|
2842
|
+
}, "strip", z.ZodTypeAny, {
|
2843
|
+
value: {
|
2844
|
+
metadata?: unknown;
|
2845
|
+
messageId?: string | undefined;
|
2846
|
+
};
|
2847
|
+
type: "start";
|
2848
|
+
}, {
|
2849
|
+
value: {
|
2850
|
+
metadata?: unknown;
|
2851
|
+
messageId?: string | undefined;
|
2852
|
+
};
|
2853
|
+
type: "start";
|
2854
|
+
}>, z.ZodObject<{
|
2855
|
+
type: z.ZodLiteral<"finish">;
|
2856
|
+
value: z.ZodObject<{
|
2857
|
+
metadata: z.ZodUnknown;
|
2858
|
+
}, "strip", z.ZodTypeAny, {
|
2859
|
+
metadata?: unknown;
|
2860
|
+
}, {
|
2861
|
+
metadata?: unknown;
|
2862
|
+
}>;
|
2863
|
+
}, "strip", z.ZodTypeAny, {
|
2864
|
+
value: {
|
2865
|
+
metadata?: unknown;
|
2866
|
+
};
|
2867
|
+
type: "finish";
|
2868
|
+
}, {
|
2869
|
+
value: {
|
2870
|
+
metadata?: unknown;
|
2871
|
+
};
|
2872
|
+
type: "finish";
|
2873
|
+
}>, z.ZodObject<{
|
2874
|
+
type: z.ZodLiteral<"reasoning-part-finish">;
|
2875
|
+
value: z.ZodNull;
|
2876
|
+
}, "strip", z.ZodTypeAny, {
|
2877
|
+
value: null;
|
2878
|
+
type: "reasoning-part-finish";
|
2879
|
+
}, {
|
2880
|
+
value: null;
|
2881
|
+
type: "reasoning-part-finish";
|
2882
|
+
}>]>;
|
2883
|
+
type UIMessageStreamPart = z.infer<typeof uiMessageStreamPartSchema>;
|
2884
|
+
|
2885
|
+
interface UIMessageStreamWriter {
|
2886
|
+
/**
|
2887
|
+
* Appends a data stream part to the stream.
|
2735
2888
|
*/
|
2736
|
-
|
2889
|
+
write(part: UIMessageStreamPart): void;
|
2737
2890
|
/**
|
2738
|
-
*
|
2739
|
-
* @example
|
2740
|
-
* Send a `sessionId` to the API along with the messages.
|
2741
|
-
* ```js
|
2742
|
-
* useChat({
|
2743
|
-
* body: {
|
2744
|
-
* sessionId: '123',
|
2745
|
-
* }
|
2746
|
-
* })
|
2747
|
-
* ```
|
2891
|
+
* Merges the contents of another stream to this stream.
|
2748
2892
|
*/
|
2749
|
-
|
2750
|
-
/**
|
2751
|
-
Streaming protocol that is used. Defaults to `data`.
|
2752
|
-
*/
|
2753
|
-
streamProtocol?: 'data' | 'text';
|
2893
|
+
merge(stream: ReadableStream<UIMessageStreamPart>): void;
|
2754
2894
|
/**
|
2755
|
-
|
2756
|
-
|
2757
|
-
|
2758
|
-
fetch?: FetchFunction;
|
2759
|
-
/**
|
2760
|
-
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
2761
|
-
Must be at least 1.
|
2762
|
-
|
2763
|
-
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
2764
|
-
|
2765
|
-
By default, it's set to 1, which means that only a single LLM call is made.
|
2895
|
+
* Error handler that is used by the data stream writer.
|
2896
|
+
* This is intended for forwarding when merging streams
|
2897
|
+
* to prevent duplicated error masking.
|
2766
2898
|
*/
|
2767
|
-
|
2768
|
-
}
|
2769
|
-
|
2770
|
-
declare const getOriginalFetch$1: () => typeof fetch;
|
2771
|
-
declare function callChatApi<MESSAGE_METADATA>({ api, body, streamProtocol, credentials, headers, abortController, onResponse, onUpdate, onFinish, onToolCall, generateId, fetch, lastMessage, requestType, messageMetadataSchema, }: {
|
2772
|
-
api: string;
|
2773
|
-
body: Record<string, any>;
|
2774
|
-
streamProtocol: 'data' | 'text' | undefined;
|
2775
|
-
credentials: RequestCredentials | undefined;
|
2776
|
-
headers: HeadersInit | undefined;
|
2777
|
-
abortController: (() => AbortController | null) | undefined;
|
2778
|
-
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
2779
|
-
onUpdate: (options: {
|
2780
|
-
message: UIMessage<MESSAGE_METADATA>;
|
2781
|
-
}) => void;
|
2782
|
-
onFinish: UseChatOptions<MESSAGE_METADATA>['onFinish'];
|
2783
|
-
onToolCall: UseChatOptions<MESSAGE_METADATA>['onToolCall'];
|
2784
|
-
generateId: IdGenerator;
|
2785
|
-
fetch: ReturnType<typeof getOriginalFetch$1> | undefined;
|
2786
|
-
lastMessage: UIMessage<MESSAGE_METADATA> | undefined;
|
2787
|
-
requestType?: 'generate' | 'resume';
|
2788
|
-
messageMetadataSchema?: Schema<MESSAGE_METADATA>;
|
2789
|
-
}): Promise<void>;
|
2790
|
-
|
2791
|
-
declare const getOriginalFetch: () => typeof fetch;
|
2792
|
-
declare function callCompletionApi({ api, prompt, credentials, headers, body, streamProtocol, setCompletion, setLoading, setError, setAbortController, onResponse, onFinish, onError, fetch, }: {
|
2793
|
-
api: string;
|
2794
|
-
prompt: string;
|
2795
|
-
credentials: RequestCredentials | undefined;
|
2796
|
-
headers: HeadersInit | undefined;
|
2797
|
-
body: Record<string, any>;
|
2798
|
-
streamProtocol: 'data' | 'text' | undefined;
|
2799
|
-
setCompletion: (completion: string) => void;
|
2800
|
-
setLoading: (loading: boolean) => void;
|
2801
|
-
setError: (error: Error | undefined) => void;
|
2802
|
-
setAbortController: (abortController: AbortController | null) => void;
|
2803
|
-
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
2804
|
-
onFinish: ((prompt: string, completion: string) => void) | undefined;
|
2805
|
-
onError: ((error: Error) => void) | undefined;
|
2806
|
-
fetch: ReturnType<typeof getOriginalFetch> | undefined;
|
2807
|
-
}): Promise<string | null | undefined>;
|
2808
|
-
|
2809
|
-
declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
|
2810
|
-
|
2811
|
-
/**
|
2812
|
-
Converts an array of messages from useChat into an array of CoreMessages that can be used
|
2813
|
-
with the AI core functions (e.g. `streamText`).
|
2814
|
-
*/
|
2815
|
-
declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<UIMessage, 'id'>>, options?: {
|
2816
|
-
tools?: TOOLS;
|
2817
|
-
}): ModelMessage[];
|
2818
|
-
/**
|
2819
|
-
@deprecated Use `convertToModelMessages` instead.
|
2820
|
-
*/
|
2821
|
-
declare const convertToCoreMessages: typeof convertToModelMessages;
|
2822
|
-
|
2823
|
-
declare function extractMaxToolInvocationStep(toolInvocations: ToolInvocation[] | undefined): number | undefined;
|
2824
|
-
|
2825
|
-
declare function getToolInvocations(message: UIMessage): ToolInvocation[];
|
2899
|
+
onError: ((error: unknown) => string) | undefined;
|
2900
|
+
}
|
2826
2901
|
|
2827
|
-
declare function
|
2828
|
-
|
2829
|
-
|
2830
|
-
}):
|
2902
|
+
declare function createUIMessageStream({ execute, onError, }: {
|
2903
|
+
execute: (writer: UIMessageStreamWriter) => Promise<void> | void;
|
2904
|
+
onError?: (error: unknown) => string;
|
2905
|
+
}): ReadableStream<UIMessageStreamPart>;
|
2831
2906
|
|
2832
|
-
declare function
|
2833
|
-
|
2834
|
-
|
2835
|
-
maxSteps: number;
|
2836
|
-
messages: UIMessage[];
|
2837
|
-
}): boolean;
|
2838
|
-
/**
|
2839
|
-
Check if the message is an assistant message with completed tool calls.
|
2840
|
-
The last step of the message must have at least one tool invocation and
|
2841
|
-
all tool invocations must have a result.
|
2842
|
-
*/
|
2843
|
-
declare function isAssistantMessageWithCompletedToolCalls(message: UIMessage): message is UIMessage & {
|
2844
|
-
role: 'assistant';
|
2845
|
-
};
|
2907
|
+
declare function createUIMessageStreamResponse({ status, statusText, headers, stream, }: ResponseInit & {
|
2908
|
+
stream: ReadableStream<UIMessageStreamPart>;
|
2909
|
+
}): Response;
|
2846
2910
|
|
2847
|
-
|
2848
|
-
|
2849
|
-
|
2850
|
-
|
2851
|
-
* @param {UIMessage[]} params.messages - An array of messages, from which the last one is updated.
|
2852
|
-
* @param {string} params.toolCallId - The unique identifier for the tool invocation to update.
|
2853
|
-
* @param {unknown} params.toolResult - The result object to attach to the tool invocation.
|
2854
|
-
* @returns {void} This function does not return anything.
|
2855
|
-
*/
|
2856
|
-
declare function updateToolCallResult({ messages, toolCallId, toolResult: result, }: {
|
2857
|
-
messages: UIMessage[];
|
2858
|
-
toolCallId: string;
|
2859
|
-
toolResult: unknown;
|
2860
|
-
}): void;
|
2911
|
+
declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, }: {
|
2912
|
+
response: ServerResponse;
|
2913
|
+
stream: ReadableStream<UIMessageStreamPart>;
|
2914
|
+
} & ResponseInit): void;
|
2861
2915
|
|
2862
|
-
|
2863
|
-
|
2864
|
-
|
2865
|
-
*/
|
2866
|
-
headers?: Record<string, string> | Headers;
|
2867
|
-
/**
|
2868
|
-
An optional object to be passed to the API endpoint.
|
2869
|
-
*/
|
2870
|
-
body?: object;
|
2871
|
-
};
|
2872
|
-
type UseCompletionOptions = {
|
2873
|
-
/**
|
2874
|
-
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
2875
|
-
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
2876
|
-
*/
|
2877
|
-
api?: string;
|
2878
|
-
/**
|
2879
|
-
* An unique identifier for the chat. If not provided, a random one will be
|
2880
|
-
* generated. When provided, the `useChat` hook with the same `id` will
|
2881
|
-
* have shared states across components.
|
2882
|
-
*/
|
2883
|
-
id?: string;
|
2884
|
-
/**
|
2885
|
-
* Initial prompt input of the completion.
|
2886
|
-
*/
|
2887
|
-
initialInput?: string;
|
2888
|
-
/**
|
2889
|
-
* Initial completion result. Useful to load an existing history.
|
2890
|
-
*/
|
2891
|
-
initialCompletion?: string;
|
2892
|
-
/**
|
2893
|
-
* Callback function to be called when the API response is received.
|
2894
|
-
*/
|
2895
|
-
onResponse?: (response: Response) => void | Promise<void>;
|
2896
|
-
/**
|
2897
|
-
* Callback function to be called when the completion is finished streaming.
|
2898
|
-
*/
|
2899
|
-
onFinish?: (prompt: string, completion: string) => void;
|
2900
|
-
/**
|
2901
|
-
* Callback function to be called when an error is encountered.
|
2902
|
-
*/
|
2903
|
-
onError?: (error: Error) => void;
|
2904
|
-
/**
|
2905
|
-
* The credentials mode to be used for the fetch request.
|
2906
|
-
* Possible values are: 'omit', 'same-origin', 'include'.
|
2907
|
-
* Defaults to 'same-origin'.
|
2908
|
-
*/
|
2909
|
-
credentials?: RequestCredentials;
|
2910
|
-
/**
|
2911
|
-
* HTTP headers to be sent with the API request.
|
2912
|
-
*/
|
2913
|
-
headers?: Record<string, string> | Headers;
|
2914
|
-
/**
|
2915
|
-
* Extra body object to be sent with the API request.
|
2916
|
-
* @example
|
2917
|
-
* Send a `sessionId` to the API along with the prompt.
|
2918
|
-
* ```js
|
2919
|
-
* useChat({
|
2920
|
-
* body: {
|
2921
|
-
* sessionId: '123',
|
2922
|
-
* }
|
2923
|
-
* })
|
2924
|
-
* ```
|
2925
|
-
*/
|
2926
|
-
body?: object;
|
2927
|
-
/**
|
2928
|
-
Streaming protocol that is used. Defaults to `data`.
|
2929
|
-
*/
|
2930
|
-
streamProtocol?: 'data' | 'text';
|
2931
|
-
/**
|
2932
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
2933
|
-
or to provide a custom fetch implementation for e.g. testing.
|
2934
|
-
*/
|
2935
|
-
fetch?: FetchFunction;
|
2936
|
-
};
|
2916
|
+
declare class JsonToSseTransformStream extends TransformStream<unknown, string> {
|
2917
|
+
constructor();
|
2918
|
+
}
|
2937
2919
|
|
2938
2920
|
/**
|
2939
2921
|
* Converts a data URL of type text/* to a text string.
|
@@ -3515,7 +3497,7 @@ A function that attempts to repair a tool call that failed to parse.
|
|
3515
3497
|
|
3516
3498
|
type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
|
3517
3499
|
|
3518
|
-
type
|
3500
|
+
type UIMessageStreamOptions = {
|
3519
3501
|
/**
|
3520
3502
|
* Message ID that is sent to the client if a new message is created.
|
3521
3503
|
* This is intended to be used for the UI message,
|
@@ -3724,7 +3706,7 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3724
3706
|
*/
|
3725
3707
|
consumeStream(options?: ConsumeStreamOptions): Promise<void>;
|
3726
3708
|
/**
|
3727
|
-
Converts the result to a
|
3709
|
+
Converts the result to a UI message stream.
|
3728
3710
|
|
3729
3711
|
@param options.getErrorMessage an optional function that converts an error to an error message.
|
3730
3712
|
@param options.sendUsage whether to send the usage information to the client. Defaults to true.
|
@@ -3733,11 +3715,11 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3733
3715
|
@param options.experimental_sendFinish whether to send the finish information to the client. Defaults to true.
|
3734
3716
|
@param options.experimental_sendStart whether to send the start information to the client. Defaults to true.
|
3735
3717
|
|
3736
|
-
@return A
|
3718
|
+
@return A UI message stream.
|
3737
3719
|
*/
|
3738
|
-
|
3720
|
+
toUIMessageStream(options?: UIMessageStreamOptions): ReadableStream<UIMessageStreamPart>;
|
3739
3721
|
/**
|
3740
|
-
Writes
|
3722
|
+
Writes UI message stream output to a Node.js response-like object.
|
3741
3723
|
@param response A Node.js response-like object (ServerResponse).
|
3742
3724
|
@param options.status The status code.
|
3743
3725
|
@param options.statusText The status text.
|
@@ -3746,7 +3728,7 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3746
3728
|
@param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
3747
3729
|
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
3748
3730
|
*/
|
3749
|
-
|
3731
|
+
pipeUIMessageStreamToResponse(response: ServerResponse, options?: ResponseInit & UIMessageStreamOptions): void;
|
3750
3732
|
/**
|
3751
3733
|
Writes text delta output to a Node.js response-like object.
|
3752
3734
|
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
@@ -3757,17 +3739,16 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3757
3739
|
pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void;
|
3758
3740
|
/**
|
3759
3741
|
Converts the result to a streamed response object with a stream data part stream.
|
3760
|
-
|
3742
|
+
|
3761
3743
|
@param options.status The status code.
|
3762
3744
|
@param options.statusText The status text.
|
3763
3745
|
@param options.headers The headers.
|
3764
|
-
@param options.data The stream data.
|
3765
3746
|
@param options.getErrorMessage An optional function that converts an error to an error message.
|
3766
3747
|
@param options.sendUsage Whether to send the usage information to the client. Defaults to true.
|
3767
3748
|
@param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
|
3768
3749
|
@return A response object.
|
3769
3750
|
*/
|
3770
|
-
|
3751
|
+
toUIMessageStreamResponse(options?: ResponseInit & UIMessageStreamOptions): Response;
|
3771
3752
|
/**
|
3772
3753
|
Creates a simple text stream response.
|
3773
3754
|
Each text delta is encoded as UTF-8 and sent as a separate chunk.
|
@@ -4913,4 +4894,4 @@ declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetr
|
|
4913
4894
|
headers?: Record<string, string>;
|
4914
4895
|
}): Promise<TranscriptionResult>;
|
4915
4896
|
|
4916
|
-
export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequestOptions, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent,
|
4897
|
+
export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequestOptions, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DeepPartial, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, ModelMessage, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SourceUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIMessage, UIMessagePart, UIMessageStreamOptions, UIMessageStreamPart, UIMessageStreamWriter, UseChatOptions, UseCompletionOptions, UserContent, UserModelMessage, appendClientMessage, assistantModelMessageSchema, callChatApi, 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, extractMaxToolInvocationStep, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolInvocations, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, processTextStream, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, updateToolCallResult, userModelMessageSchema, wrapLanguageModel };
|