ai 5.0.0-canary.19 → 5.0.0-canary.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/index.d.mts +2335 -2332
- package/dist/index.d.ts +2335 -2332
- package/dist/index.js +3761 -3769
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3829 -3819
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +95 -677
- package/dist/internal/index.d.ts +95 -677
- package/dist/internal/index.js +210 -476
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +204 -471
- 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 +1 -4
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs +1 -16
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/dist/test/index.d.mts +1 -1
- package/dist/test/index.d.ts +1 -1
- package/dist/test/index.js +5 -1
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +5 -1
- package/dist/test/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
@@ -1,850 +1,521 @@
|
|
1
|
-
import { ToolCall, ToolResult,
|
1
|
+
import { ToolCall, ToolResult, ToolResultContent, Schema, 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 { AttributeValue, Tracer } from '@opentelemetry/api';
|
4
|
-
import { EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SharedV2ProviderMetadata, SharedV2ProviderOptions, SpeechModelV1, SpeechModelV1CallWarning, TranscriptionModelV1, TranscriptionModelV1CallWarning, LanguageModelV2Usage, JSONObject, LanguageModelV2CallOptions, AISDKError, LanguageModelV2ToolCall, JSONSchema7, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
|
5
|
-
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
6
3
|
import { z } from 'zod';
|
7
|
-
import { ServerResponse as ServerResponse$1 } from 'http';
|
8
4
|
import { ServerResponse } from 'node:http';
|
5
|
+
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
|
+
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
7
|
+
import { AttributeValue, Tracer } from '@opentelemetry/api';
|
8
|
+
import { ServerResponse as ServerResponse$1 } from 'http';
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
type
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
}
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
type
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
}
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
}
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
}
|
321
|
-
type
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
};
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
type
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
type
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
}
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
type
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
};
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
type
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
*/
|
400
|
-
headers?: Record<string, string> | Headers;
|
401
|
-
/**
|
402
|
-
An optional object to be passed to the API endpoint.
|
403
|
-
*/
|
404
|
-
body?: object;
|
405
|
-
/**
|
406
|
-
The messages of the chat.
|
407
|
-
*/
|
408
|
-
messages: UIMessage[];
|
409
|
-
/**
|
410
|
-
Additional data to be sent to the server.
|
411
|
-
*/
|
412
|
-
data?: JSONValue$1;
|
413
|
-
};
|
414
|
-
type RequestOptions = {
|
415
|
-
/**
|
416
|
-
An optional object of headers to be passed to the API endpoint.
|
417
|
-
*/
|
418
|
-
headers?: Record<string, string> | Headers;
|
419
|
-
/**
|
420
|
-
An optional object to be passed to the API endpoint.
|
421
|
-
*/
|
422
|
-
body?: object;
|
423
|
-
};
|
424
|
-
type ChatRequestOptions = {
|
425
|
-
/**
|
426
|
-
Additional headers that should be to be passed to the API endpoint.
|
427
|
-
*/
|
428
|
-
headers?: Record<string, string> | Headers;
|
429
|
-
/**
|
430
|
-
Additional body JSON properties that should be sent to the API endpoint.
|
431
|
-
*/
|
432
|
-
body?: object;
|
433
|
-
/**
|
434
|
-
Additional data to be sent to the API endpoint.
|
435
|
-
*/
|
436
|
-
data?: JSONValue$1;
|
437
|
-
/**
|
438
|
-
* Allow submitting an empty message. Defaults to `false`.
|
439
|
-
*/
|
440
|
-
allowEmptySubmit?: boolean;
|
441
|
-
};
|
442
|
-
type UseChatOptions = {
|
443
|
-
/**
|
444
|
-
* The API endpoint that accepts a `{ messages: Message[] }` object and returns
|
445
|
-
* a stream of tokens of the AI chat response. Defaults to `/api/chat`.
|
446
|
-
*/
|
447
|
-
api?: string;
|
448
|
-
/**
|
449
|
-
* A unique identifier for the chat. If not provided, a random one will be
|
450
|
-
* generated. When provided, the `useChat` hook with the same `id` will
|
451
|
-
* have shared states across components.
|
452
|
-
*/
|
453
|
-
id?: string;
|
454
|
-
/**
|
455
|
-
* Initial messages of the chat. Useful to load an existing chat history.
|
456
|
-
*/
|
457
|
-
initialMessages?: UIMessage[];
|
458
|
-
/**
|
459
|
-
* Initial input of the chat.
|
460
|
-
*/
|
461
|
-
initialInput?: string;
|
462
|
-
/**
|
463
|
-
Optional callback function that is invoked when a tool call is received.
|
464
|
-
Intended for automatic client-side tool execution.
|
465
|
-
|
466
|
-
You can optionally return a result for the tool call,
|
467
|
-
either synchronously or asynchronously.
|
468
|
-
*/
|
469
|
-
onToolCall?: ({ toolCall, }: {
|
470
|
-
toolCall: ToolCall<string, unknown>;
|
471
|
-
}) => void | Promise<unknown> | unknown;
|
472
|
-
/**
|
473
|
-
* Callback function to be called when the API response is received.
|
474
|
-
*/
|
475
|
-
onResponse?: (response: Response) => void | Promise<void>;
|
476
|
-
/**
|
477
|
-
* Optional callback function that is called when the assistant message is finished streaming.
|
478
|
-
*
|
479
|
-
* @param message The message that was streamed.
|
480
|
-
* @param options.usage The token usage of the message.
|
481
|
-
* @param options.finishReason The finish reason of the message.
|
482
|
-
*/
|
483
|
-
onFinish?: (message: UIMessage, options: {
|
484
|
-
usage: LanguageModelUsage;
|
485
|
-
finishReason: LanguageModelV2FinishReason;
|
486
|
-
}) => void;
|
487
|
-
/**
|
488
|
-
* Callback function to be called when an error is encountered.
|
489
|
-
*/
|
490
|
-
onError?: (error: Error) => void;
|
491
|
-
/**
|
492
|
-
* A way to provide a function that is going to be used for ids for messages and the chat.
|
493
|
-
* If not provided the default AI SDK `generateId` is used.
|
494
|
-
*/
|
495
|
-
generateId?: IdGenerator;
|
496
|
-
/**
|
497
|
-
* The credentials mode to be used for the fetch request.
|
498
|
-
* Possible values are: 'omit', 'same-origin', 'include'.
|
499
|
-
* Defaults to 'same-origin'.
|
500
|
-
*/
|
501
|
-
credentials?: RequestCredentials;
|
502
|
-
/**
|
503
|
-
* HTTP headers to be sent with the API request.
|
504
|
-
*/
|
505
|
-
headers?: Record<string, string> | Headers;
|
506
|
-
/**
|
507
|
-
* Extra body object to be sent with the API request.
|
508
|
-
* @example
|
509
|
-
* Send a `sessionId` to the API along with the messages.
|
510
|
-
* ```js
|
511
|
-
* useChat({
|
512
|
-
* body: {
|
513
|
-
* sessionId: '123',
|
514
|
-
* }
|
515
|
-
* })
|
516
|
-
* ```
|
517
|
-
*/
|
518
|
-
body?: object;
|
519
|
-
/**
|
520
|
-
Streaming protocol that is used. Defaults to `data`.
|
521
|
-
*/
|
522
|
-
streamProtocol?: 'data' | 'text';
|
523
|
-
/**
|
524
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
525
|
-
or to provide a custom fetch implementation for e.g. testing.
|
526
|
-
*/
|
527
|
-
fetch?: FetchFunction;
|
528
|
-
/**
|
529
|
-
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
530
|
-
Must be at least 1.
|
531
|
-
|
532
|
-
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
533
|
-
|
534
|
-
By default, it's set to 1, which means that only a single LLM call is made.
|
535
|
-
*/
|
536
|
-
maxSteps?: number;
|
537
|
-
};
|
538
|
-
type UseCompletionOptions = {
|
539
|
-
/**
|
540
|
-
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
541
|
-
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
542
|
-
*/
|
543
|
-
api?: string;
|
544
|
-
/**
|
545
|
-
* An unique identifier for the chat. If not provided, a random one will be
|
546
|
-
* generated. When provided, the `useChat` hook with the same `id` will
|
547
|
-
* have shared states across components.
|
548
|
-
*/
|
549
|
-
id?: string;
|
550
|
-
/**
|
551
|
-
* Initial prompt input of the completion.
|
552
|
-
*/
|
553
|
-
initialInput?: string;
|
554
|
-
/**
|
555
|
-
* Initial completion result. Useful to load an existing history.
|
556
|
-
*/
|
557
|
-
initialCompletion?: string;
|
558
|
-
/**
|
559
|
-
* Callback function to be called when the API response is received.
|
560
|
-
*/
|
561
|
-
onResponse?: (response: Response) => void | Promise<void>;
|
562
|
-
/**
|
563
|
-
* Callback function to be called when the completion is finished streaming.
|
564
|
-
*/
|
565
|
-
onFinish?: (prompt: string, completion: string) => void;
|
566
|
-
/**
|
567
|
-
* Callback function to be called when an error is encountered.
|
568
|
-
*/
|
569
|
-
onError?: (error: Error) => void;
|
570
|
-
/**
|
571
|
-
* The credentials mode to be used for the fetch request.
|
572
|
-
* Possible values are: 'omit', 'same-origin', 'include'.
|
573
|
-
* Defaults to 'same-origin'.
|
574
|
-
*/
|
575
|
-
credentials?: RequestCredentials;
|
576
|
-
/**
|
577
|
-
* HTTP headers to be sent with the API request.
|
578
|
-
*/
|
579
|
-
headers?: Record<string, string> | Headers;
|
580
|
-
/**
|
581
|
-
* Extra body object to be sent with the API request.
|
582
|
-
* @example
|
583
|
-
* Send a `sessionId` to the API along with the prompt.
|
584
|
-
* ```js
|
585
|
-
* useChat({
|
586
|
-
* body: {
|
587
|
-
* sessionId: '123',
|
588
|
-
* }
|
589
|
-
* })
|
590
|
-
* ```
|
591
|
-
*/
|
592
|
-
body?: object;
|
593
|
-
/**
|
594
|
-
Streaming protocol that is used. Defaults to `data`.
|
595
|
-
*/
|
596
|
-
streamProtocol?: 'data' | 'text';
|
597
|
-
/**
|
598
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
599
|
-
or to provide a custom fetch implementation for e.g. testing.
|
600
|
-
*/
|
601
|
-
fetch?: FetchFunction;
|
602
|
-
};
|
603
|
-
|
604
|
-
/**
|
605
|
-
The result of an `embed` call.
|
606
|
-
It contains the embedding, the value, and additional information.
|
607
|
-
*/
|
608
|
-
interface EmbedResult<VALUE> {
|
609
|
-
/**
|
610
|
-
The value that was embedded.
|
611
|
-
*/
|
612
|
-
readonly value: VALUE;
|
613
|
-
/**
|
614
|
-
The embedding of the value.
|
615
|
-
*/
|
616
|
-
readonly embedding: Embedding;
|
617
|
-
/**
|
618
|
-
The embedding token usage.
|
619
|
-
*/
|
620
|
-
readonly usage: EmbeddingModelUsage;
|
621
|
-
/**
|
622
|
-
Optional response data.
|
623
|
-
*/
|
624
|
-
readonly response?: {
|
625
|
-
/**
|
626
|
-
Response headers.
|
627
|
-
*/
|
628
|
-
headers?: Record<string, string>;
|
629
|
-
/**
|
630
|
-
The response body.
|
631
|
-
*/
|
632
|
-
body?: unknown;
|
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<"data">;
|
21
|
+
value: z.ZodArray<z.ZodAny, "many">;
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
23
|
+
type: "data";
|
24
|
+
value: any[];
|
25
|
+
}, {
|
26
|
+
type: "data";
|
27
|
+
value: any[];
|
28
|
+
}>, z.ZodObject<{
|
29
|
+
type: z.ZodLiteral<"error">;
|
30
|
+
value: z.ZodString;
|
31
|
+
}, "strip", z.ZodTypeAny, {
|
32
|
+
type: "error";
|
33
|
+
value: string;
|
34
|
+
}, {
|
35
|
+
type: "error";
|
36
|
+
value: string;
|
37
|
+
}>, z.ZodObject<{
|
38
|
+
type: z.ZodLiteral<"message-annotations">;
|
39
|
+
value: z.ZodArray<z.ZodAny, "many">;
|
40
|
+
}, "strip", z.ZodTypeAny, {
|
41
|
+
type: "message-annotations";
|
42
|
+
value: any[];
|
43
|
+
}, {
|
44
|
+
type: "message-annotations";
|
45
|
+
value: any[];
|
46
|
+
}>, z.ZodObject<{
|
47
|
+
type: z.ZodLiteral<"tool-call">;
|
48
|
+
value: z.ZodObject<{
|
49
|
+
toolCallId: z.ZodString;
|
50
|
+
toolName: z.ZodString;
|
51
|
+
args: z.ZodUnknown;
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
53
|
+
toolCallId: string;
|
54
|
+
toolName: string;
|
55
|
+
args?: unknown;
|
56
|
+
}, {
|
57
|
+
toolCallId: string;
|
58
|
+
toolName: string;
|
59
|
+
args?: unknown;
|
60
|
+
}>;
|
61
|
+
}, "strip", z.ZodTypeAny, {
|
62
|
+
type: "tool-call";
|
63
|
+
value: {
|
64
|
+
toolCallId: string;
|
65
|
+
toolName: string;
|
66
|
+
args?: unknown;
|
67
|
+
};
|
68
|
+
}, {
|
69
|
+
type: "tool-call";
|
70
|
+
value: {
|
71
|
+
toolCallId: string;
|
72
|
+
toolName: string;
|
73
|
+
args?: unknown;
|
74
|
+
};
|
75
|
+
}>, z.ZodObject<{
|
76
|
+
type: z.ZodLiteral<"tool-result">;
|
77
|
+
value: z.ZodObject<{
|
78
|
+
toolCallId: z.ZodString;
|
79
|
+
result: z.ZodUnknown;
|
80
|
+
providerMetadata: z.ZodOptional<z.ZodAny>;
|
81
|
+
}, "strip", z.ZodTypeAny, {
|
82
|
+
toolCallId: string;
|
83
|
+
result?: unknown;
|
84
|
+
providerMetadata?: any;
|
85
|
+
}, {
|
86
|
+
toolCallId: string;
|
87
|
+
result?: unknown;
|
88
|
+
providerMetadata?: any;
|
89
|
+
}>;
|
90
|
+
}, "strip", z.ZodTypeAny, {
|
91
|
+
type: "tool-result";
|
92
|
+
value: {
|
93
|
+
toolCallId: string;
|
94
|
+
result?: unknown;
|
95
|
+
providerMetadata?: any;
|
96
|
+
};
|
97
|
+
}, {
|
98
|
+
type: "tool-result";
|
99
|
+
value: {
|
100
|
+
toolCallId: string;
|
101
|
+
result?: unknown;
|
102
|
+
providerMetadata?: any;
|
103
|
+
};
|
104
|
+
}>, z.ZodObject<{
|
105
|
+
type: z.ZodLiteral<"tool-call-streaming-start">;
|
106
|
+
value: z.ZodObject<{
|
107
|
+
toolCallId: z.ZodString;
|
108
|
+
toolName: z.ZodString;
|
109
|
+
}, "strip", z.ZodTypeAny, {
|
110
|
+
toolCallId: string;
|
111
|
+
toolName: string;
|
112
|
+
}, {
|
113
|
+
toolCallId: string;
|
114
|
+
toolName: string;
|
115
|
+
}>;
|
116
|
+
}, "strip", z.ZodTypeAny, {
|
117
|
+
type: "tool-call-streaming-start";
|
118
|
+
value: {
|
119
|
+
toolCallId: string;
|
120
|
+
toolName: string;
|
121
|
+
};
|
122
|
+
}, {
|
123
|
+
type: "tool-call-streaming-start";
|
124
|
+
value: {
|
125
|
+
toolCallId: string;
|
126
|
+
toolName: string;
|
127
|
+
};
|
128
|
+
}>, z.ZodObject<{
|
129
|
+
type: z.ZodLiteral<"tool-call-delta">;
|
130
|
+
value: z.ZodObject<{
|
131
|
+
toolCallId: z.ZodString;
|
132
|
+
argsTextDelta: z.ZodString;
|
133
|
+
}, "strip", z.ZodTypeAny, {
|
134
|
+
toolCallId: string;
|
135
|
+
argsTextDelta: string;
|
136
|
+
}, {
|
137
|
+
toolCallId: string;
|
138
|
+
argsTextDelta: string;
|
139
|
+
}>;
|
140
|
+
}, "strip", z.ZodTypeAny, {
|
141
|
+
type: "tool-call-delta";
|
142
|
+
value: {
|
143
|
+
toolCallId: string;
|
144
|
+
argsTextDelta: string;
|
145
|
+
};
|
146
|
+
}, {
|
147
|
+
type: "tool-call-delta";
|
148
|
+
value: {
|
149
|
+
toolCallId: string;
|
150
|
+
argsTextDelta: string;
|
151
|
+
};
|
152
|
+
}>, z.ZodObject<{
|
153
|
+
type: z.ZodLiteral<"finish-message">;
|
154
|
+
value: z.ZodObject<{
|
155
|
+
finishReason: z.ZodEnum<["stop", "length", "tool-calls", "content-filter", "other", "error", "unknown"]>;
|
156
|
+
usage: z.ZodOptional<z.ZodObject<{
|
157
|
+
inputTokens: z.ZodOptional<z.ZodNumber>;
|
158
|
+
outputTokens: z.ZodOptional<z.ZodNumber>;
|
159
|
+
totalTokens: z.ZodOptional<z.ZodNumber>;
|
160
|
+
reasoningTokens: z.ZodOptional<z.ZodNumber>;
|
161
|
+
cachedInputTokens: z.ZodOptional<z.ZodNumber>;
|
162
|
+
}, "strip", z.ZodTypeAny, {
|
163
|
+
inputTokens?: number | undefined;
|
164
|
+
outputTokens?: number | undefined;
|
165
|
+
totalTokens?: number | undefined;
|
166
|
+
reasoningTokens?: number | undefined;
|
167
|
+
cachedInputTokens?: number | undefined;
|
168
|
+
}, {
|
169
|
+
inputTokens?: number | undefined;
|
170
|
+
outputTokens?: number | undefined;
|
171
|
+
totalTokens?: number | undefined;
|
172
|
+
reasoningTokens?: number | undefined;
|
173
|
+
cachedInputTokens?: number | undefined;
|
174
|
+
}>>;
|
175
|
+
}, "strip", z.ZodTypeAny, {
|
176
|
+
finishReason: "length" | "stop" | "tool-calls" | "content-filter" | "other" | "error" | "unknown";
|
177
|
+
usage?: {
|
178
|
+
inputTokens?: number | undefined;
|
179
|
+
outputTokens?: number | undefined;
|
180
|
+
totalTokens?: number | undefined;
|
181
|
+
reasoningTokens?: number | undefined;
|
182
|
+
cachedInputTokens?: number | undefined;
|
183
|
+
} | undefined;
|
184
|
+
}, {
|
185
|
+
finishReason: "length" | "stop" | "tool-calls" | "content-filter" | "other" | "error" | "unknown";
|
186
|
+
usage?: {
|
187
|
+
inputTokens?: number | undefined;
|
188
|
+
outputTokens?: number | undefined;
|
189
|
+
totalTokens?: number | undefined;
|
190
|
+
reasoningTokens?: number | undefined;
|
191
|
+
cachedInputTokens?: number | undefined;
|
192
|
+
} | undefined;
|
193
|
+
}>;
|
194
|
+
}, "strip", z.ZodTypeAny, {
|
195
|
+
type: "finish-message";
|
196
|
+
value: {
|
197
|
+
finishReason: "length" | "stop" | "tool-calls" | "content-filter" | "other" | "error" | "unknown";
|
198
|
+
usage?: {
|
199
|
+
inputTokens?: number | undefined;
|
200
|
+
outputTokens?: number | undefined;
|
201
|
+
totalTokens?: number | undefined;
|
202
|
+
reasoningTokens?: number | undefined;
|
203
|
+
cachedInputTokens?: number | undefined;
|
204
|
+
} | undefined;
|
205
|
+
};
|
206
|
+
}, {
|
207
|
+
type: "finish-message";
|
208
|
+
value: {
|
209
|
+
finishReason: "length" | "stop" | "tool-calls" | "content-filter" | "other" | "error" | "unknown";
|
210
|
+
usage?: {
|
211
|
+
inputTokens?: number | undefined;
|
212
|
+
outputTokens?: number | undefined;
|
213
|
+
totalTokens?: number | undefined;
|
214
|
+
reasoningTokens?: number | undefined;
|
215
|
+
cachedInputTokens?: number | undefined;
|
216
|
+
} | undefined;
|
217
|
+
};
|
218
|
+
}>, z.ZodObject<{
|
219
|
+
type: z.ZodLiteral<"finish-step">;
|
220
|
+
value: z.ZodObject<{
|
221
|
+
isContinued: z.ZodBoolean;
|
222
|
+
finishReason: z.ZodEnum<["stop", "length", "tool-calls", "content-filter", "other", "error", "unknown"]>;
|
223
|
+
usage: z.ZodOptional<z.ZodObject<{
|
224
|
+
inputTokens: z.ZodOptional<z.ZodNumber>;
|
225
|
+
outputTokens: z.ZodOptional<z.ZodNumber>;
|
226
|
+
totalTokens: z.ZodOptional<z.ZodNumber>;
|
227
|
+
reasoningTokens: z.ZodOptional<z.ZodNumber>;
|
228
|
+
cachedInputTokens: z.ZodOptional<z.ZodNumber>;
|
229
|
+
}, "strip", z.ZodTypeAny, {
|
230
|
+
inputTokens?: number | undefined;
|
231
|
+
outputTokens?: number | undefined;
|
232
|
+
totalTokens?: number | undefined;
|
233
|
+
reasoningTokens?: number | undefined;
|
234
|
+
cachedInputTokens?: number | undefined;
|
235
|
+
}, {
|
236
|
+
inputTokens?: number | undefined;
|
237
|
+
outputTokens?: number | undefined;
|
238
|
+
totalTokens?: number | undefined;
|
239
|
+
reasoningTokens?: number | undefined;
|
240
|
+
cachedInputTokens?: number | undefined;
|
241
|
+
}>>;
|
242
|
+
}, "strip", z.ZodTypeAny, {
|
243
|
+
finishReason: "length" | "stop" | "tool-calls" | "content-filter" | "other" | "error" | "unknown";
|
244
|
+
isContinued: boolean;
|
245
|
+
usage?: {
|
246
|
+
inputTokens?: number | undefined;
|
247
|
+
outputTokens?: number | undefined;
|
248
|
+
totalTokens?: number | undefined;
|
249
|
+
reasoningTokens?: number | undefined;
|
250
|
+
cachedInputTokens?: number | undefined;
|
251
|
+
} | undefined;
|
252
|
+
}, {
|
253
|
+
finishReason: "length" | "stop" | "tool-calls" | "content-filter" | "other" | "error" | "unknown";
|
254
|
+
isContinued: boolean;
|
255
|
+
usage?: {
|
256
|
+
inputTokens?: number | undefined;
|
257
|
+
outputTokens?: number | undefined;
|
258
|
+
totalTokens?: number | undefined;
|
259
|
+
reasoningTokens?: number | undefined;
|
260
|
+
cachedInputTokens?: number | undefined;
|
261
|
+
} | undefined;
|
262
|
+
}>;
|
263
|
+
}, "strip", z.ZodTypeAny, {
|
264
|
+
type: "finish-step";
|
265
|
+
value: {
|
266
|
+
finishReason: "length" | "stop" | "tool-calls" | "content-filter" | "other" | "error" | "unknown";
|
267
|
+
isContinued: boolean;
|
268
|
+
usage?: {
|
269
|
+
inputTokens?: number | undefined;
|
270
|
+
outputTokens?: number | undefined;
|
271
|
+
totalTokens?: number | undefined;
|
272
|
+
reasoningTokens?: number | undefined;
|
273
|
+
cachedInputTokens?: number | undefined;
|
274
|
+
} | undefined;
|
275
|
+
};
|
276
|
+
}, {
|
277
|
+
type: "finish-step";
|
278
|
+
value: {
|
279
|
+
finishReason: "length" | "stop" | "tool-calls" | "content-filter" | "other" | "error" | "unknown";
|
280
|
+
isContinued: boolean;
|
281
|
+
usage?: {
|
282
|
+
inputTokens?: number | undefined;
|
283
|
+
outputTokens?: number | undefined;
|
284
|
+
totalTokens?: number | undefined;
|
285
|
+
reasoningTokens?: number | undefined;
|
286
|
+
cachedInputTokens?: number | undefined;
|
287
|
+
} | undefined;
|
288
|
+
};
|
289
|
+
}>, z.ZodObject<{
|
290
|
+
type: z.ZodLiteral<"start-step">;
|
291
|
+
value: z.ZodObject<{
|
292
|
+
messageId: z.ZodString;
|
293
|
+
}, "strip", z.ZodTypeAny, {
|
294
|
+
messageId: string;
|
295
|
+
}, {
|
296
|
+
messageId: string;
|
297
|
+
}>;
|
298
|
+
}, "strip", z.ZodTypeAny, {
|
299
|
+
type: "start-step";
|
300
|
+
value: {
|
301
|
+
messageId: string;
|
302
|
+
};
|
303
|
+
}, {
|
304
|
+
type: "start-step";
|
305
|
+
value: {
|
306
|
+
messageId: string;
|
307
|
+
};
|
308
|
+
}>, z.ZodObject<{
|
309
|
+
type: z.ZodLiteral<"reasoning">;
|
310
|
+
value: z.ZodObject<{
|
311
|
+
text: z.ZodString;
|
312
|
+
providerMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
313
|
+
}, "strip", z.ZodTypeAny, {
|
314
|
+
text: string;
|
315
|
+
providerMetadata?: Record<string, any> | undefined;
|
316
|
+
}, {
|
317
|
+
text: string;
|
318
|
+
providerMetadata?: Record<string, any> | undefined;
|
319
|
+
}>;
|
320
|
+
}, "strip", z.ZodTypeAny, {
|
321
|
+
type: "reasoning";
|
322
|
+
value: {
|
323
|
+
text: string;
|
324
|
+
providerMetadata?: Record<string, any> | undefined;
|
325
|
+
};
|
326
|
+
}, {
|
327
|
+
type: "reasoning";
|
328
|
+
value: {
|
329
|
+
text: string;
|
330
|
+
providerMetadata?: Record<string, any> | undefined;
|
331
|
+
};
|
332
|
+
}>, z.ZodObject<{
|
333
|
+
type: z.ZodLiteral<"source">;
|
334
|
+
value: z.ZodObject<{
|
335
|
+
type: z.ZodLiteral<"source">;
|
336
|
+
sourceType: z.ZodLiteral<"url">;
|
337
|
+
id: z.ZodString;
|
338
|
+
url: z.ZodString;
|
339
|
+
title: z.ZodOptional<z.ZodString>;
|
340
|
+
providerMetadata: z.ZodOptional<z.ZodAny>;
|
341
|
+
}, "strip", z.ZodTypeAny, {
|
342
|
+
type: "source";
|
343
|
+
sourceType: "url";
|
344
|
+
url: string;
|
345
|
+
id: string;
|
346
|
+
providerMetadata?: any;
|
347
|
+
title?: string | undefined;
|
348
|
+
}, {
|
349
|
+
type: "source";
|
350
|
+
sourceType: "url";
|
351
|
+
url: string;
|
352
|
+
id: string;
|
353
|
+
providerMetadata?: any;
|
354
|
+
title?: string | undefined;
|
355
|
+
}>;
|
356
|
+
}, "strip", z.ZodTypeAny, {
|
357
|
+
type: "source";
|
358
|
+
value: {
|
359
|
+
type: "source";
|
360
|
+
sourceType: "url";
|
361
|
+
url: string;
|
362
|
+
id: string;
|
363
|
+
providerMetadata?: any;
|
364
|
+
title?: string | undefined;
|
365
|
+
};
|
366
|
+
}, {
|
367
|
+
type: "source";
|
368
|
+
value: {
|
369
|
+
type: "source";
|
370
|
+
sourceType: "url";
|
371
|
+
url: string;
|
372
|
+
id: string;
|
373
|
+
providerMetadata?: any;
|
374
|
+
title?: string | undefined;
|
375
|
+
};
|
376
|
+
}>, z.ZodObject<{
|
377
|
+
type: z.ZodLiteral<"file">;
|
378
|
+
value: z.ZodObject<{
|
379
|
+
url: z.ZodString;
|
380
|
+
mediaType: z.ZodString;
|
381
|
+
}, "strip", z.ZodTypeAny, {
|
382
|
+
url: string;
|
383
|
+
mediaType: string;
|
384
|
+
}, {
|
385
|
+
url: string;
|
386
|
+
mediaType: string;
|
387
|
+
}>;
|
388
|
+
}, "strip", z.ZodTypeAny, {
|
389
|
+
type: "file";
|
390
|
+
value: {
|
391
|
+
url: string;
|
392
|
+
mediaType: string;
|
393
|
+
};
|
394
|
+
}, {
|
395
|
+
type: "file";
|
396
|
+
value: {
|
397
|
+
url: string;
|
398
|
+
mediaType: string;
|
633
399
|
};
|
634
|
-
}
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
400
|
+
}>, z.ZodObject<{
|
401
|
+
type: z.ZodLiteral<"reasoning-part-finish">;
|
402
|
+
value: z.ZodNull;
|
403
|
+
}, "strip", z.ZodTypeAny, {
|
404
|
+
type: "reasoning-part-finish";
|
405
|
+
value: null;
|
406
|
+
}, {
|
407
|
+
type: "reasoning-part-finish";
|
408
|
+
value: null;
|
409
|
+
}>]>;
|
410
|
+
type DataStreamPart = z.infer<typeof dataStreamPartSchema>;
|
645
411
|
|
646
|
-
|
647
|
-
*/
|
648
|
-
declare function embed<VALUE>({ model, value, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
|
649
|
-
/**
|
650
|
-
The embedding model to use.
|
651
|
-
*/
|
652
|
-
model: EmbeddingModel<VALUE>;
|
412
|
+
interface DataStreamWriter {
|
653
413
|
/**
|
654
|
-
|
414
|
+
* Appends a data stream part to the stream.
|
655
415
|
*/
|
656
|
-
|
416
|
+
write(part: DataStreamPart): void;
|
657
417
|
/**
|
658
|
-
|
659
|
-
|
660
|
-
@default 2
|
418
|
+
* Merges the contents of another stream to this stream.
|
661
419
|
*/
|
662
|
-
|
663
|
-
/**
|
664
|
-
Abort signal.
|
665
|
-
*/
|
666
|
-
abortSignal?: AbortSignal;
|
667
|
-
/**
|
668
|
-
Additional headers to include in the request.
|
669
|
-
Only applicable for HTTP-based providers.
|
670
|
-
*/
|
671
|
-
headers?: Record<string, string>;
|
672
|
-
/**
|
673
|
-
Additional provider-specific options. They are passed through
|
674
|
-
to the provider from the AI SDK and enable provider-specific
|
675
|
-
functionality that can be fully encapsulated in the provider.
|
676
|
-
*/
|
677
|
-
providerOptions?: ProviderOptions;
|
420
|
+
merge(stream: ReadableStream<DataStreamPart>): void;
|
678
421
|
/**
|
679
|
-
*
|
422
|
+
* Error handler that is used by the data stream writer.
|
423
|
+
* This is intended for forwarding when merging streams
|
424
|
+
* to prevent duplicated error masking.
|
680
425
|
*/
|
681
|
-
|
682
|
-
}): Promise<EmbedResult<VALUE>>;
|
683
|
-
|
684
|
-
/**
|
685
|
-
The result of a `embedMany` call.
|
686
|
-
It contains the embeddings, the values, and additional information.
|
687
|
-
*/
|
688
|
-
interface EmbedManyResult<VALUE> {
|
689
|
-
/**
|
690
|
-
The values that were embedded.
|
691
|
-
*/
|
692
|
-
readonly values: Array<VALUE>;
|
693
|
-
/**
|
694
|
-
The embeddings. They are in the same order as the values.
|
695
|
-
*/
|
696
|
-
readonly embeddings: Array<Embedding>;
|
697
|
-
/**
|
698
|
-
The embedding token usage.
|
699
|
-
*/
|
700
|
-
readonly usage: EmbeddingModelUsage;
|
701
|
-
/**
|
702
|
-
Optional raw response data.
|
703
|
-
*/
|
704
|
-
readonly responses?: Array<{
|
705
|
-
/**
|
706
|
-
Response headers.
|
707
|
-
*/
|
708
|
-
headers?: Record<string, string>;
|
709
|
-
/**
|
710
|
-
The response body.
|
711
|
-
*/
|
712
|
-
body?: unknown;
|
713
|
-
} | undefined>;
|
426
|
+
onError: ((error: unknown) => string) | undefined;
|
714
427
|
}
|
715
428
|
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
`embedMany` automatically splits large requests into smaller chunks if the model
|
721
|
-
has a limit on how many embeddings can be generated in a single call.
|
722
|
-
|
723
|
-
@param model - The embedding model to use.
|
724
|
-
@param values - The values that should be embedded.
|
429
|
+
declare function createDataStream({ execute, onError, }: {
|
430
|
+
execute: (writer: DataStreamWriter) => Promise<void> | void;
|
431
|
+
onError?: (error: unknown) => string;
|
432
|
+
}): ReadableStream<DataStreamPart>;
|
725
433
|
|
726
|
-
|
727
|
-
|
728
|
-
|
434
|
+
declare function createDataStreamResponse({ status, statusText, headers, dataStream, }: ResponseInit & {
|
435
|
+
dataStream: ReadableStream<DataStreamPart>;
|
436
|
+
}): Response;
|
729
437
|
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
The embedding model to use.
|
735
|
-
*/
|
736
|
-
model: EmbeddingModel<VALUE>;
|
737
|
-
/**
|
738
|
-
The values that should be embedded.
|
739
|
-
*/
|
740
|
-
values: Array<VALUE>;
|
741
|
-
/**
|
742
|
-
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
743
|
-
|
744
|
-
@default 2
|
745
|
-
*/
|
746
|
-
maxRetries?: number;
|
747
|
-
/**
|
748
|
-
Abort signal.
|
749
|
-
*/
|
750
|
-
abortSignal?: AbortSignal;
|
751
|
-
/**
|
752
|
-
Additional headers to include in the request.
|
753
|
-
Only applicable for HTTP-based providers.
|
754
|
-
*/
|
755
|
-
headers?: Record<string, string>;
|
756
|
-
/**
|
757
|
-
* Optional telemetry configuration (experimental).
|
758
|
-
*/
|
759
|
-
experimental_telemetry?: TelemetrySettings;
|
760
|
-
/**
|
761
|
-
Additional provider-specific options. They are passed through
|
762
|
-
to the provider from the AI SDK and enable provider-specific
|
763
|
-
functionality that can be fully encapsulated in the provider.
|
764
|
-
*/
|
765
|
-
providerOptions?: ProviderOptions;
|
766
|
-
/**
|
767
|
-
* Maximum number of concurrent requests.
|
768
|
-
*
|
769
|
-
* @default Infinity
|
770
|
-
*/
|
771
|
-
maxParallelCalls?: number;
|
772
|
-
}): Promise<EmbedManyResult<VALUE>>;
|
438
|
+
declare function pipeDataStreamToResponse({ response, status, statusText, headers, dataStream, }: {
|
439
|
+
response: ServerResponse;
|
440
|
+
dataStream: ReadableStream<DataStreamPart>;
|
441
|
+
} & ResponseInit): void;
|
773
442
|
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
443
|
+
declare function processDataStream({ stream, onTextPart, onReasoningPart, onReasoningPartFinish, onSourcePart, onFilePart, onDataPart, onErrorPart, onToolCallStreamingStartPart, onToolCallDeltaPart, onToolCallPart, onToolResultPart, onMessageAnnotationsPart, onFinishMessagePart, onFinishStepPart, onStartStepPart, }: {
|
444
|
+
stream: ReadableStream<Uint8Array>;
|
445
|
+
onTextPart?: (streamPart: (DataStreamPart & {
|
446
|
+
type: 'text';
|
447
|
+
})['value']) => Promise<void> | void;
|
448
|
+
onReasoningPart?: (streamPart: (DataStreamPart & {
|
449
|
+
type: 'reasoning';
|
450
|
+
})['value']) => Promise<void> | void;
|
451
|
+
onReasoningPartFinish?: (streamPart: (DataStreamPart & {
|
452
|
+
type: 'reasoning-part-finish';
|
453
|
+
})['value']) => Promise<void> | void;
|
454
|
+
onFilePart?: (streamPart: (DataStreamPart & {
|
455
|
+
type: 'file';
|
456
|
+
})['value']) => Promise<void> | void;
|
457
|
+
onSourcePart?: (streamPart: (DataStreamPart & {
|
458
|
+
type: 'source';
|
459
|
+
})['value']) => Promise<void> | void;
|
460
|
+
onDataPart?: (streamPart: (DataStreamPart & {
|
461
|
+
type: 'data';
|
462
|
+
})['value']) => Promise<void> | void;
|
463
|
+
onErrorPart?: (streamPart: (DataStreamPart & {
|
464
|
+
type: 'error';
|
465
|
+
})['value']) => Promise<void> | void;
|
466
|
+
onToolCallStreamingStartPart?: (streamPart: (DataStreamPart & {
|
467
|
+
type: 'tool-call-streaming-start';
|
468
|
+
})['value']) => Promise<void> | void;
|
469
|
+
onToolCallDeltaPart?: (streamPart: (DataStreamPart & {
|
470
|
+
type: 'tool-call-delta';
|
471
|
+
})['value']) => Promise<void> | void;
|
472
|
+
onToolCallPart?: (streamPart: ToolCall<string, any>) => Promise<void> | void;
|
473
|
+
onToolResultPart?: (streamPart: ToolResult<string, any, any>) => Promise<void> | void;
|
474
|
+
onMessageAnnotationsPart?: (streamPart: (DataStreamPart & {
|
475
|
+
type: 'message-annotations';
|
476
|
+
})['value']) => Promise<void> | void;
|
477
|
+
onFinishMessagePart?: (streamPart: (DataStreamPart & {
|
478
|
+
type: 'finish-message';
|
479
|
+
})['value']) => Promise<void> | void;
|
480
|
+
onFinishStepPart?: (streamPart: (DataStreamPart & {
|
481
|
+
type: 'finish-step';
|
482
|
+
})['value']) => Promise<void> | void;
|
483
|
+
onStartStepPart?: (streamPart: (DataStreamPart & {
|
484
|
+
type: 'start-step';
|
485
|
+
})['value']) => Promise<void> | void;
|
486
|
+
}): Promise<void>;
|
487
|
+
|
488
|
+
declare class JsonToSseTransformStream extends TransformStream<unknown, string> {
|
489
|
+
constructor();
|
490
|
+
}
|
491
|
+
|
492
|
+
declare const symbol$f: unique symbol;
|
493
|
+
declare class InvalidArgumentError extends AISDKError {
|
494
|
+
private readonly [symbol$f];
|
495
|
+
readonly parameter: string;
|
496
|
+
readonly value: unknown;
|
497
|
+
constructor({ parameter, value, message, }: {
|
498
|
+
parameter: string;
|
499
|
+
value: unknown;
|
500
|
+
message: string;
|
501
|
+
});
|
502
|
+
static isInstance(error: unknown): error is InvalidArgumentError;
|
503
|
+
}
|
504
|
+
|
505
|
+
/**
|
506
|
+
Additional provider-specific metadata that is returned from the provider.
|
507
|
+
|
508
|
+
This is needed to enable provider-specific functionality that can be
|
509
|
+
fully encapsulated in the provider.
|
510
|
+
*/
|
511
|
+
type ProviderMetadata = SharedV2ProviderMetadata;
|
512
|
+
/**
|
513
|
+
Additional provider-specific options.
|
514
|
+
|
515
|
+
They are passed through to the provider from the AI SDK and enable
|
516
|
+
provider-specific functionality that can be fully encapsulated in the provider.
|
517
|
+
*/
|
518
|
+
type ProviderOptions = SharedV2ProviderOptions;
|
848
519
|
|
849
520
|
/**
|
850
521
|
Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
@@ -1115,22 +786,248 @@ declare const modelMessageSchema: z.ZodType<ModelMessage>;
|
|
1115
786
|
declare const coreMessageSchema: z.ZodType<CoreMessage>;
|
1116
787
|
|
1117
788
|
/**
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
789
|
+
* Telemetry configuration.
|
790
|
+
*/
|
791
|
+
type TelemetrySettings = {
|
792
|
+
/**
|
793
|
+
* Enable or disable telemetry. Disabled by default while experimental.
|
794
|
+
*/
|
795
|
+
isEnabled?: boolean;
|
796
|
+
/**
|
797
|
+
* Enable or disable input recording. Enabled by default.
|
798
|
+
*
|
799
|
+
* You might want to disable input recording to avoid recording sensitive
|
800
|
+
* information, to reduce data transfers, or to increase performance.
|
801
|
+
*/
|
802
|
+
recordInputs?: boolean;
|
803
|
+
/**
|
804
|
+
* Enable or disable output recording. Enabled by default.
|
805
|
+
*
|
806
|
+
* You might want to disable output recording to avoid recording sensitive
|
807
|
+
* information, to reduce data transfers, or to increase performance.
|
808
|
+
*/
|
809
|
+
recordOutputs?: boolean;
|
810
|
+
/**
|
811
|
+
* Identifier for this function. Used to group telemetry data by function.
|
812
|
+
*/
|
813
|
+
functionId?: string;
|
814
|
+
/**
|
815
|
+
* Additional information to include in the telemetry data.
|
816
|
+
*/
|
817
|
+
metadata?: Record<string, AttributeValue>;
|
818
|
+
/**
|
819
|
+
* A custom tracer to use for the telemetry data.
|
820
|
+
*/
|
821
|
+
tracer?: Tracer;
|
822
|
+
};
|
823
|
+
|
824
|
+
/**
|
825
|
+
Embedding model that is used by the AI SDK Core functions.
|
826
|
+
*/
|
827
|
+
type EmbeddingModel<VALUE> = EmbeddingModelV2<VALUE>;
|
828
|
+
/**
|
829
|
+
Embedding.
|
830
|
+
*/
|
831
|
+
type Embedding = EmbeddingModelV2Embedding;
|
832
|
+
|
833
|
+
/**
|
834
|
+
Image model that is used by the AI SDK Core functions.
|
835
|
+
*/
|
836
|
+
type ImageModel = ImageModelV2;
|
837
|
+
/**
|
838
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
839
|
+
some settings might not be supported, which can lead to suboptimal results.
|
840
|
+
*/
|
841
|
+
type ImageGenerationWarning = ImageModelV2CallWarning;
|
842
|
+
/**
|
843
|
+
Metadata from the model provider for this call
|
844
|
+
*/
|
845
|
+
type ImageModelProviderMetadata = ImageModelV2ProviderMetadata;
|
846
|
+
|
847
|
+
type ImageModelResponseMetadata = {
|
848
|
+
/**
|
849
|
+
Timestamp for the start of the generated response.
|
850
|
+
*/
|
851
|
+
timestamp: Date;
|
852
|
+
/**
|
853
|
+
The ID of the response model that was used to generate the response.
|
854
|
+
*/
|
855
|
+
modelId: string;
|
856
|
+
/**
|
857
|
+
Response headers.
|
858
|
+
*/
|
859
|
+
headers?: Record<string, string>;
|
860
|
+
};
|
861
|
+
|
862
|
+
type JSONValue = JSONValue$1;
|
863
|
+
|
864
|
+
/**
|
865
|
+
Language model that is used by the AI SDK Core functions.
|
866
|
+
*/
|
867
|
+
type LanguageModel = LanguageModelV2;
|
868
|
+
/**
|
869
|
+
Reason why a language model finished generating a response.
|
870
|
+
|
871
|
+
Can be one of the following:
|
872
|
+
- `stop`: model generated stop sequence
|
873
|
+
- `length`: model generated maximum number of tokens
|
874
|
+
- `content-filter`: content filter violation stopped the model
|
875
|
+
- `tool-calls`: model triggered tool calls
|
876
|
+
- `error`: model stopped because of an error
|
877
|
+
- `other`: model stopped for other reasons
|
878
|
+
*/
|
879
|
+
type FinishReason = LanguageModelV2FinishReason;
|
880
|
+
/**
|
881
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
882
|
+
some settings might not be supported, which can lead to suboptimal results.
|
883
|
+
*/
|
884
|
+
type CallWarning = LanguageModelV2CallWarning;
|
885
|
+
/**
|
886
|
+
A source that has been used as input to generate the response.
|
887
|
+
*/
|
888
|
+
type Source = LanguageModelV2Source;
|
889
|
+
/**
|
890
|
+
Tool choice for the generation. It supports the following settings:
|
891
|
+
|
892
|
+
- `auto` (default): the model can choose whether and which tools to call.
|
893
|
+
- `required`: the model must call a tool. It can choose which tool to call.
|
894
|
+
- `none`: the model must not call tools
|
895
|
+
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
896
|
+
*/
|
897
|
+
type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
898
|
+
type: 'tool';
|
899
|
+
toolName: Extract<keyof TOOLS, string>;
|
900
|
+
};
|
901
|
+
|
902
|
+
type LanguageModelRequestMetadata = {
|
903
|
+
/**
|
904
|
+
Request HTTP body that was sent to the provider API.
|
905
|
+
*/
|
906
|
+
body?: unknown;
|
907
|
+
};
|
908
|
+
|
909
|
+
type LanguageModelResponseMetadata = {
|
910
|
+
/**
|
911
|
+
ID for the generated response.
|
912
|
+
*/
|
913
|
+
id: string;
|
914
|
+
/**
|
915
|
+
Timestamp for the start of the generated response.
|
916
|
+
*/
|
917
|
+
timestamp: Date;
|
918
|
+
/**
|
919
|
+
The ID of the response model that was used to generate the response.
|
920
|
+
*/
|
921
|
+
modelId: string;
|
922
|
+
/**
|
923
|
+
Response headers (available only for providers that use HTTP requests).
|
924
|
+
*/
|
925
|
+
headers?: Record<string, string>;
|
926
|
+
};
|
927
|
+
|
928
|
+
/**
|
929
|
+
* Provider for language, text embedding, and image models.
|
930
|
+
*/
|
931
|
+
type Provider = {
|
932
|
+
/**
|
933
|
+
Returns the language model with the given id.
|
934
|
+
The model id is then passed to the provider function to get the model.
|
935
|
+
|
936
|
+
@param {string} id - The id of the model to return.
|
937
|
+
|
938
|
+
@returns {LanguageModel} The language model associated with the id
|
939
|
+
|
940
|
+
@throws {NoSuchModelError} If no such model exists.
|
941
|
+
*/
|
942
|
+
languageModel(modelId: string): LanguageModel;
|
943
|
+
/**
|
944
|
+
Returns the text embedding model with the given id.
|
945
|
+
The model id is then passed to the provider function to get the model.
|
946
|
+
|
947
|
+
@param {string} id - The id of the model to return.
|
948
|
+
|
949
|
+
@returns {LanguageModel} The language model associated with the id
|
950
|
+
|
951
|
+
@throws {NoSuchModelError} If no such model exists.
|
952
|
+
*/
|
953
|
+
textEmbeddingModel(modelId: string): EmbeddingModel<string>;
|
954
|
+
/**
|
955
|
+
Returns the image model with the given id.
|
956
|
+
The model id is then passed to the provider function to get the model.
|
957
|
+
|
958
|
+
@param {string} id - The id of the model to return.
|
959
|
+
|
960
|
+
@returns {ImageModel} The image model associated with the id
|
961
|
+
*/
|
962
|
+
imageModel(modelId: string): ImageModel;
|
963
|
+
};
|
964
|
+
|
965
|
+
/**
|
966
|
+
Speech model that is used by the AI SDK Core functions.
|
967
|
+
*/
|
968
|
+
type SpeechModel = SpeechModelV1;
|
969
|
+
/**
|
970
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
971
|
+
some settings might not be supported, which can lead to suboptimal results.
|
972
|
+
*/
|
973
|
+
type SpeechWarning = SpeechModelV1CallWarning;
|
974
|
+
|
975
|
+
type SpeechModelResponseMetadata = {
|
976
|
+
/**
|
977
|
+
Timestamp for the start of the generated response.
|
978
|
+
*/
|
979
|
+
timestamp: Date;
|
980
|
+
/**
|
981
|
+
The ID of the response model that was used to generate the response.
|
982
|
+
*/
|
983
|
+
modelId: string;
|
984
|
+
/**
|
985
|
+
Response headers.
|
986
|
+
*/
|
987
|
+
headers?: Record<string, string>;
|
988
|
+
/**
|
989
|
+
Response body.
|
990
|
+
*/
|
991
|
+
body?: unknown;
|
992
|
+
};
|
993
|
+
|
994
|
+
/**
|
995
|
+
Transcription model that is used by the AI SDK Core functions.
|
996
|
+
*/
|
997
|
+
type TranscriptionModel = TranscriptionModelV1;
|
998
|
+
/**
|
999
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
1000
|
+
some settings might not be supported, which can lead to suboptimal results.
|
1001
|
+
*/
|
1002
|
+
type TranscriptionWarning = TranscriptionModelV1CallWarning;
|
1003
|
+
|
1004
|
+
type TranscriptionModelResponseMetadata = {
|
1122
1005
|
/**
|
1123
|
-
|
1006
|
+
Timestamp for the start of the generated response.
|
1124
1007
|
*/
|
1125
|
-
|
1008
|
+
timestamp: Date;
|
1126
1009
|
/**
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1010
|
+
The ID of the response model that was used to generate the response.
|
1011
|
+
*/
|
1012
|
+
modelId: string;
|
1013
|
+
/**
|
1014
|
+
Response headers.
|
1015
|
+
*/
|
1016
|
+
headers?: Record<string, string>;
|
1017
|
+
};
|
1018
|
+
|
1019
|
+
/**
|
1020
|
+
Represents the number of tokens used in a prompt and completion.
|
1021
|
+
*/
|
1022
|
+
type LanguageModelUsage = LanguageModelV2Usage;
|
1023
|
+
/**
|
1024
|
+
Represents the number of tokens used in an embedding.
|
1025
|
+
*/
|
1026
|
+
type EmbeddingModelUsage = {
|
1130
1027
|
/**
|
1131
|
-
|
1028
|
+
The number of tokens used in the embedding.
|
1132
1029
|
*/
|
1133
|
-
|
1030
|
+
tokens: number;
|
1134
1031
|
};
|
1135
1032
|
|
1136
1033
|
/**
|
@@ -1153,6 +1050,48 @@ interface GeneratedFile {
|
|
1153
1050
|
readonly mediaType: string;
|
1154
1051
|
}
|
1155
1052
|
|
1053
|
+
/**
|
1054
|
+
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
1055
|
+
|
1056
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
1057
|
+
|
1058
|
+
@example
|
1059
|
+
```
|
1060
|
+
// data.json
|
1061
|
+
{
|
1062
|
+
'foo': 1,
|
1063
|
+
'bar': 2,
|
1064
|
+
'biz': 3
|
1065
|
+
}
|
1066
|
+
|
1067
|
+
// main.ts
|
1068
|
+
import type {ValueOf} from 'type-fest';
|
1069
|
+
import data = require('./data.json');
|
1070
|
+
|
1071
|
+
export function getData(name: string): ValueOf<typeof data> {
|
1072
|
+
return data[name];
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
|
1076
|
+
return data[name];
|
1077
|
+
}
|
1078
|
+
|
1079
|
+
// file.ts
|
1080
|
+
import {getData, onlyBar} from './main';
|
1081
|
+
|
1082
|
+
getData('foo');
|
1083
|
+
//=> 1
|
1084
|
+
|
1085
|
+
onlyBar('foo');
|
1086
|
+
//=> TypeError ...
|
1087
|
+
|
1088
|
+
onlyBar('bar');
|
1089
|
+
//=> 2
|
1090
|
+
```
|
1091
|
+
* @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
|
1092
|
+
*/
|
1093
|
+
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
1094
|
+
|
1156
1095
|
declare const JSONRPCRequestSchema: z.ZodObject<z.objectUtil.extendShape<{
|
1157
1096
|
jsonrpc: z.ZodLiteral<"2.0">;
|
1158
1097
|
id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
@@ -1217,26 +1156,26 @@ declare const JSONRPCErrorSchema: z.ZodObject<{
|
|
1217
1156
|
message: z.ZodString;
|
1218
1157
|
data: z.ZodOptional<z.ZodUnknown>;
|
1219
1158
|
}, "strip", z.ZodTypeAny, {
|
1220
|
-
message: string;
|
1221
1159
|
code: number;
|
1160
|
+
message: string;
|
1222
1161
|
data?: unknown;
|
1223
1162
|
}, {
|
1224
|
-
message: string;
|
1225
1163
|
code: number;
|
1164
|
+
message: string;
|
1226
1165
|
data?: unknown;
|
1227
1166
|
}>;
|
1228
1167
|
}, "strict", z.ZodTypeAny, {
|
1229
1168
|
error: {
|
1230
|
-
message: string;
|
1231
1169
|
code: number;
|
1170
|
+
message: string;
|
1232
1171
|
data?: unknown;
|
1233
1172
|
};
|
1234
1173
|
id: string | number;
|
1235
1174
|
jsonrpc: "2.0";
|
1236
1175
|
}, {
|
1237
1176
|
error: {
|
1238
|
-
message: string;
|
1239
1177
|
code: number;
|
1178
|
+
message: string;
|
1240
1179
|
data?: unknown;
|
1241
1180
|
};
|
1242
1181
|
id: string | number;
|
@@ -1351,26 +1290,26 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS
|
|
1351
1290
|
message: z.ZodString;
|
1352
1291
|
data: z.ZodOptional<z.ZodUnknown>;
|
1353
1292
|
}, "strip", z.ZodTypeAny, {
|
1354
|
-
message: string;
|
1355
1293
|
code: number;
|
1294
|
+
message: string;
|
1356
1295
|
data?: unknown;
|
1357
1296
|
}, {
|
1358
|
-
message: string;
|
1359
1297
|
code: number;
|
1298
|
+
message: string;
|
1360
1299
|
data?: unknown;
|
1361
1300
|
}>;
|
1362
1301
|
}, "strict", z.ZodTypeAny, {
|
1363
1302
|
error: {
|
1364
|
-
message: string;
|
1365
1303
|
code: number;
|
1304
|
+
message: string;
|
1366
1305
|
data?: unknown;
|
1367
1306
|
};
|
1368
1307
|
id: string | number;
|
1369
1308
|
jsonrpc: "2.0";
|
1370
1309
|
}, {
|
1371
1310
|
error: {
|
1372
|
-
message: string;
|
1373
1311
|
code: number;
|
1312
|
+
message: string;
|
1374
1313
|
data?: unknown;
|
1375
1314
|
};
|
1376
1315
|
id: string | number;
|
@@ -1421,123 +1360,6 @@ type MCPTransportConfig = {
|
|
1421
1360
|
headers?: Record<string, string>;
|
1422
1361
|
};
|
1423
1362
|
|
1424
|
-
declare const getOriginalFetch$1: () => typeof fetch;
|
1425
|
-
declare function callChatApi({ api, body, streamProtocol, credentials, headers, abortController, onResponse, onUpdate, onFinish, onToolCall, generateId, fetch, lastMessage, getCurrentDate, requestType, }: {
|
1426
|
-
api: string;
|
1427
|
-
body: Record<string, any>;
|
1428
|
-
streamProtocol: 'data' | 'text' | undefined;
|
1429
|
-
credentials: RequestCredentials | undefined;
|
1430
|
-
headers: HeadersInit | undefined;
|
1431
|
-
abortController: (() => AbortController | null) | undefined;
|
1432
|
-
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
1433
|
-
onUpdate: (options: {
|
1434
|
-
message: UIMessage;
|
1435
|
-
data: JSONValue$1[] | undefined;
|
1436
|
-
replaceLastMessage: boolean;
|
1437
|
-
}) => void;
|
1438
|
-
onFinish: UseChatOptions['onFinish'];
|
1439
|
-
onToolCall: UseChatOptions['onToolCall'];
|
1440
|
-
generateId: IdGenerator;
|
1441
|
-
fetch: ReturnType<typeof getOriginalFetch$1> | undefined;
|
1442
|
-
lastMessage: UIMessage | undefined;
|
1443
|
-
getCurrentDate: () => Date;
|
1444
|
-
requestType?: 'generate' | 'resume';
|
1445
|
-
}): Promise<void>;
|
1446
|
-
|
1447
|
-
declare const getOriginalFetch: () => typeof fetch;
|
1448
|
-
declare function callCompletionApi({ api, prompt, credentials, headers, body, streamProtocol, setCompletion, setLoading, setError, setAbortController, onResponse, onFinish, onError, onData, fetch, }: {
|
1449
|
-
api: string;
|
1450
|
-
prompt: string;
|
1451
|
-
credentials: RequestCredentials | undefined;
|
1452
|
-
headers: HeadersInit | undefined;
|
1453
|
-
body: Record<string, any>;
|
1454
|
-
streamProtocol: 'data' | 'text' | undefined;
|
1455
|
-
setCompletion: (completion: string) => void;
|
1456
|
-
setLoading: (loading: boolean) => void;
|
1457
|
-
setError: (error: Error | undefined) => void;
|
1458
|
-
setAbortController: (abortController: AbortController | null) => void;
|
1459
|
-
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
1460
|
-
onFinish: ((prompt: string, completion: string) => void) | undefined;
|
1461
|
-
onError: ((error: Error) => void) | undefined;
|
1462
|
-
onData: ((data: JSONValue$1[]) => void) | undefined;
|
1463
|
-
fetch: ReturnType<typeof getOriginalFetch> | undefined;
|
1464
|
-
}): Promise<string | null | undefined>;
|
1465
|
-
|
1466
|
-
declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
|
1467
|
-
|
1468
|
-
/**
|
1469
|
-
* Converts a data URL of type text/* to a text string.
|
1470
|
-
*/
|
1471
|
-
declare function getTextFromDataUrl(dataUrl: string): string;
|
1472
|
-
|
1473
|
-
/**
|
1474
|
-
Create a type from an object with all keys and nested keys set to optional.
|
1475
|
-
The helper supports normal objects and Zod schemas (which are resolved automatically).
|
1476
|
-
It always recurses into arrays.
|
1477
|
-
|
1478
|
-
Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
|
1479
|
-
*/
|
1480
|
-
type DeepPartial<T> = T extends z.ZodTypeAny ? DeepPartialInternal<z.infer<T>> : DeepPartialInternal<T>;
|
1481
|
-
type DeepPartialInternal<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartialInternal<ItemType | undefined>> : Array<DeepPartialInternal<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
|
1482
|
-
type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
1483
|
-
type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
|
1484
|
-
type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
1485
|
-
type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartialInternal<T>>;
|
1486
|
-
type PartialObject<ObjectType extends object> = {
|
1487
|
-
[KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
|
1488
|
-
};
|
1489
|
-
|
1490
|
-
declare function extractMaxToolInvocationStep(toolInvocations: ToolInvocation[] | undefined): number | undefined;
|
1491
|
-
|
1492
|
-
/**
|
1493
|
-
* Performs a deep-equal comparison of two parsed JSON objects.
|
1494
|
-
*
|
1495
|
-
* @param {any} obj1 - The first object to compare.
|
1496
|
-
* @param {any} obj2 - The second object to compare.
|
1497
|
-
* @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
|
1498
|
-
*/
|
1499
|
-
declare function isDeepEqualData(obj1: any, obj2: any): boolean;
|
1500
|
-
|
1501
|
-
declare function parsePartialJson(jsonText: string | undefined): Promise<{
|
1502
|
-
value: JSONValue$1 | undefined;
|
1503
|
-
state: 'undefined-input' | 'successful-parse' | 'repaired-parse' | 'failed-parse';
|
1504
|
-
}>;
|
1505
|
-
|
1506
|
-
declare function processTextStream({ stream, onTextPart, }: {
|
1507
|
-
stream: ReadableStream<Uint8Array>;
|
1508
|
-
onTextPart: (chunk: string) => Promise<void> | void;
|
1509
|
-
}): Promise<void>;
|
1510
|
-
|
1511
|
-
declare function shouldResubmitMessages({ originalMaxToolInvocationStep, originalMessageCount, maxSteps, messages, }: {
|
1512
|
-
originalMaxToolInvocationStep: number | undefined;
|
1513
|
-
originalMessageCount: number;
|
1514
|
-
maxSteps: number;
|
1515
|
-
messages: UIMessage[];
|
1516
|
-
}): boolean;
|
1517
|
-
/**
|
1518
|
-
Check if the message is an assistant message with completed tool calls.
|
1519
|
-
The last step of the message must have at least one tool invocation and
|
1520
|
-
all tool invocations must have a result.
|
1521
|
-
*/
|
1522
|
-
declare function isAssistantMessageWithCompletedToolCalls(message: UIMessage): message is UIMessage & {
|
1523
|
-
role: 'assistant';
|
1524
|
-
};
|
1525
|
-
|
1526
|
-
/**
|
1527
|
-
* Updates the result of a specific tool invocation in the last message of the given messages array.
|
1528
|
-
*
|
1529
|
-
* @param {object} params - The parameters object.
|
1530
|
-
* @param {UIMessage[]} params.messages - An array of messages, from which the last one is updated.
|
1531
|
-
* @param {string} params.toolCallId - The unique identifier for the tool invocation to update.
|
1532
|
-
* @param {unknown} params.toolResult - The result object to attach to the tool invocation.
|
1533
|
-
* @returns {void} This function does not return anything.
|
1534
|
-
*/
|
1535
|
-
declare function updateToolCallResult({ messages, toolCallId, toolResult: result, }: {
|
1536
|
-
messages: UIMessage[];
|
1537
|
-
toolCallId: string;
|
1538
|
-
toolResult: unknown;
|
1539
|
-
}): void;
|
1540
|
-
|
1541
1363
|
type ToolParameters<T = JSONObject> = z.Schema<T> | Schema<T>;
|
1542
1364
|
interface ToolExecutionOptions {
|
1543
1365
|
/**
|
@@ -2379,63 +2201,21 @@ declare class MCPClient {
|
|
2379
2201
|
close(): Promise<void>;
|
2380
2202
|
private assertCapability;
|
2381
2203
|
private request;
|
2382
|
-
private listTools;
|
2383
|
-
private callTool;
|
2384
|
-
private notification;
|
2385
|
-
/**
|
2386
|
-
* Returns a set of AI SDK tools from the MCP server
|
2387
|
-
* @returns A record of tool names to their implementations
|
2388
|
-
*/
|
2389
|
-
tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>({ schemas, }?: {
|
2390
|
-
schemas?: TOOL_SCHEMAS;
|
2391
|
-
}): Promise<McpToolSet<TOOL_SCHEMAS>>;
|
2392
|
-
private onClose;
|
2393
|
-
private onError;
|
2394
|
-
private onResponse;
|
2395
|
-
}
|
2396
|
-
|
2397
|
-
/**
|
2398
|
-
Create a union of the given object's values, and optionally specify which keys to get the values from.
|
2399
|
-
|
2400
|
-
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
|
2401
|
-
|
2402
|
-
@example
|
2403
|
-
```
|
2404
|
-
// data.json
|
2405
|
-
{
|
2406
|
-
'foo': 1,
|
2407
|
-
'bar': 2,
|
2408
|
-
'biz': 3
|
2409
|
-
}
|
2410
|
-
|
2411
|
-
// main.ts
|
2412
|
-
import type {ValueOf} from 'type-fest';
|
2413
|
-
import data = require('./data.json');
|
2414
|
-
|
2415
|
-
export function getData(name: string): ValueOf<typeof data> {
|
2416
|
-
return data[name];
|
2417
|
-
}
|
2418
|
-
|
2419
|
-
export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
|
2420
|
-
return data[name];
|
2204
|
+
private listTools;
|
2205
|
+
private callTool;
|
2206
|
+
private notification;
|
2207
|
+
/**
|
2208
|
+
* Returns a set of AI SDK tools from the MCP server
|
2209
|
+
* @returns A record of tool names to their implementations
|
2210
|
+
*/
|
2211
|
+
tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>({ schemas, }?: {
|
2212
|
+
schemas?: TOOL_SCHEMAS;
|
2213
|
+
}): Promise<McpToolSet<TOOL_SCHEMAS>>;
|
2214
|
+
private onClose;
|
2215
|
+
private onError;
|
2216
|
+
private onResponse;
|
2421
2217
|
}
|
2422
2218
|
|
2423
|
-
// file.ts
|
2424
|
-
import {getData, onlyBar} from './main';
|
2425
|
-
|
2426
|
-
getData('foo');
|
2427
|
-
//=> 1
|
2428
|
-
|
2429
|
-
onlyBar('foo');
|
2430
|
-
//=> TypeError ...
|
2431
|
-
|
2432
|
-
onlyBar('bar');
|
2433
|
-
//=> 2
|
2434
|
-
```
|
2435
|
-
* @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
|
2436
|
-
*/
|
2437
|
-
type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
|
2438
|
-
|
2439
2219
|
type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, 'execute'>>;
|
2440
2220
|
|
2441
2221
|
type ToolCallUnion<TOOLS extends ToolSet> = ValueOf<{
|
@@ -2448,233 +2228,9 @@ type ToolCallUnion<TOOLS extends ToolSet> = ValueOf<{
|
|
2448
2228
|
}>;
|
2449
2229
|
type ToolCallArray<TOOLS extends ToolSet> = Array<ToolCallUnion<TOOLS>>;
|
2450
2230
|
|
2451
|
-
|
2452
|
-
[K in keyof TOOLS as TOOLS[K]['execute'] extends undefined ? never : K]: TOOLS[K];
|
2453
|
-
};
|
2454
|
-
type ToToolResultObject<TOOLS extends ToolSet> = ValueOf<{
|
2455
|
-
[NAME in keyof TOOLS]: {
|
2456
|
-
type: 'tool-result';
|
2457
|
-
toolCallId: string;
|
2458
|
-
toolName: NAME & string;
|
2459
|
-
args: TOOLS[NAME] extends Tool<infer P> ? P : never;
|
2460
|
-
result: Awaited<ReturnType<Exclude<TOOLS[NAME]['execute'], undefined>>>;
|
2461
|
-
};
|
2462
|
-
}>;
|
2463
|
-
type ToolResultUnion<TOOLS extends ToolSet> = ToToolResultObject<ToToolsWithDefinedExecute<TOOLS>>;
|
2464
|
-
type ToolResultArray<TOOLS extends ToolSet> = Array<ToolResultUnion<TOOLS>>;
|
2465
|
-
|
2466
|
-
/**
|
2467
|
-
A message that was generated during the generation process.
|
2468
|
-
It can be either an assistant message or a tool message.
|
2469
|
-
*/
|
2470
|
-
type ResponseMessage = (AssistantModelMessage | ToolModelMessage) & {
|
2471
|
-
/**
|
2472
|
-
Message ID generated by the AI SDK.
|
2473
|
-
*/
|
2474
|
-
id: string;
|
2475
|
-
};
|
2476
|
-
/**
|
2477
|
-
* The result of a single step in the generation process.
|
2478
|
-
*/
|
2479
|
-
type StepResult<TOOLS extends ToolSet> = {
|
2480
|
-
/**
|
2481
|
-
The generated text.
|
2482
|
-
*/
|
2483
|
-
readonly text: string;
|
2484
|
-
/**
|
2485
|
-
The reasoning that was generated during the generation.
|
2486
|
-
*/
|
2487
|
-
readonly reasoning: Array<ReasoningPart>;
|
2488
|
-
/**
|
2489
|
-
The reasoning text that was generated during the generation.
|
2490
|
-
*/
|
2491
|
-
readonly reasoningText: string | undefined;
|
2492
|
-
/**
|
2493
|
-
The files that were generated during the generation.
|
2494
|
-
*/
|
2495
|
-
readonly files: GeneratedFile[];
|
2496
|
-
/**
|
2497
|
-
The sources that were used to generate the text.
|
2498
|
-
*/
|
2499
|
-
readonly sources: Source[];
|
2500
|
-
/**
|
2501
|
-
The tool calls that were made during the generation.
|
2502
|
-
*/
|
2503
|
-
readonly toolCalls: ToolCallArray<TOOLS>;
|
2504
|
-
/**
|
2505
|
-
The results of the tool calls.
|
2506
|
-
*/
|
2507
|
-
readonly toolResults: ToolResultArray<TOOLS>;
|
2508
|
-
/**
|
2509
|
-
The reason why the generation finished.
|
2510
|
-
*/
|
2511
|
-
readonly finishReason: FinishReason;
|
2512
|
-
/**
|
2513
|
-
The token usage of the generated text.
|
2514
|
-
*/
|
2515
|
-
readonly usage: LanguageModelUsage;
|
2516
|
-
/**
|
2517
|
-
Warnings from the model provider (e.g. unsupported settings).
|
2518
|
-
*/
|
2519
|
-
readonly warnings: CallWarning[] | undefined;
|
2520
|
-
/**
|
2521
|
-
Additional request information.
|
2522
|
-
*/
|
2523
|
-
readonly request: LanguageModelRequestMetadata;
|
2524
|
-
/**
|
2525
|
-
Additional response information.
|
2526
|
-
*/
|
2527
|
-
readonly response: LanguageModelResponseMetadata & {
|
2528
|
-
/**
|
2529
|
-
The response messages that were generated during the call.
|
2530
|
-
Response messages can be either assistant messages or tool messages.
|
2531
|
-
They contain a generated id.
|
2532
|
-
*/
|
2533
|
-
readonly messages: Array<ResponseMessage>;
|
2534
|
-
/**
|
2535
|
-
Response body (available only for providers that use HTTP requests).
|
2536
|
-
*/
|
2537
|
-
body?: unknown;
|
2538
|
-
};
|
2539
|
-
/**
|
2540
|
-
Additional provider-specific metadata. They are passed through
|
2541
|
-
from the provider to the AI SDK and enable provider-specific
|
2542
|
-
results that can be fully encapsulated in the provider.
|
2543
|
-
*/
|
2544
|
-
readonly providerMetadata: ProviderMetadata | undefined;
|
2545
|
-
/**
|
2546
|
-
The type of step that this result is for. The first step is always
|
2547
|
-
an "initial" step, and subsequent steps are either "continue" steps
|
2548
|
-
or "tool-result" steps.
|
2549
|
-
*/
|
2550
|
-
readonly stepType: 'initial' | 'continue' | 'tool-result';
|
2551
|
-
/**
|
2552
|
-
True when there will be a continuation step with a continuation text.
|
2553
|
-
*/
|
2554
|
-
readonly isContinued: boolean;
|
2555
|
-
};
|
2556
|
-
|
2557
|
-
/**
|
2558
|
-
The result of a `generateText` call.
|
2559
|
-
It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
|
2560
|
-
*/
|
2561
|
-
interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
|
2562
|
-
/**
|
2563
|
-
The generated text.
|
2564
|
-
*/
|
2565
|
-
readonly text: string;
|
2566
|
-
/**
|
2567
|
-
The full reasoning that the model has generated.
|
2568
|
-
*/
|
2569
|
-
readonly reasoning: Array<ReasoningPart>;
|
2570
|
-
/**
|
2571
|
-
The reasoning text that the model has generated. Can be undefined if the model
|
2572
|
-
has only generated text.
|
2573
|
-
*/
|
2574
|
-
readonly reasoningText: string | undefined;
|
2575
|
-
/**
|
2576
|
-
The files that were generated. Empty array if no files were generated.
|
2577
|
-
*/
|
2578
|
-
readonly files: Array<GeneratedFile>;
|
2579
|
-
/**
|
2580
|
-
Sources that have been used as input to generate the response.
|
2581
|
-
For multi-step generation, the sources are accumulated from all steps.
|
2582
|
-
*/
|
2583
|
-
readonly sources: Source[];
|
2584
|
-
/**
|
2585
|
-
The generated structured output. It uses the `experimental_output` specification.
|
2586
|
-
*/
|
2587
|
-
readonly experimental_output: OUTPUT;
|
2588
|
-
/**
|
2589
|
-
The tool calls that were made during the generation.
|
2590
|
-
*/
|
2591
|
-
readonly toolCalls: ToolCallArray<TOOLS>;
|
2592
|
-
/**
|
2593
|
-
The results of the tool calls.
|
2594
|
-
*/
|
2595
|
-
readonly toolResults: ToolResultArray<TOOLS>;
|
2596
|
-
/**
|
2597
|
-
The reason why the generation finished.
|
2598
|
-
*/
|
2599
|
-
readonly finishReason: FinishReason;
|
2600
|
-
/**
|
2601
|
-
The token usage of the generated text.
|
2602
|
-
*/
|
2603
|
-
readonly usage: LanguageModelUsage;
|
2604
|
-
/**
|
2605
|
-
Warnings from the model provider (e.g. unsupported settings)
|
2606
|
-
*/
|
2607
|
-
readonly warnings: CallWarning[] | undefined;
|
2608
|
-
/**
|
2609
|
-
Details for all steps.
|
2610
|
-
You can use this to get information about intermediate steps,
|
2611
|
-
such as the tool calls or the response headers.
|
2612
|
-
*/
|
2613
|
-
readonly steps: Array<StepResult<TOOLS>>;
|
2614
|
-
/**
|
2615
|
-
Additional request information.
|
2616
|
-
*/
|
2617
|
-
readonly request: LanguageModelRequestMetadata;
|
2618
|
-
/**
|
2619
|
-
Additional response information.
|
2620
|
-
*/
|
2621
|
-
readonly response: LanguageModelResponseMetadata & {
|
2622
|
-
/**
|
2623
|
-
The response messages that were generated during the call. It consists of an assistant message,
|
2624
|
-
potentially containing tool calls.
|
2625
|
-
|
2626
|
-
When there are tool results, there is an additional tool message with the tool results that are available.
|
2627
|
-
If there are tools that do not have execute functions, they are not included in the tool results and
|
2628
|
-
need to be added separately.
|
2629
|
-
*/
|
2630
|
-
messages: Array<ResponseMessage>;
|
2631
|
-
/**
|
2632
|
-
Response body (available only for providers that use HTTP requests).
|
2633
|
-
*/
|
2634
|
-
body?: unknown;
|
2635
|
-
};
|
2636
|
-
/**
|
2637
|
-
Additional provider-specific metadata. They are passed through
|
2638
|
-
from the provider to the AI SDK and enable provider-specific
|
2639
|
-
results that can be fully encapsulated in the provider.
|
2640
|
-
*/
|
2641
|
-
readonly providerMetadata: ProviderMetadata | undefined;
|
2642
|
-
}
|
2643
|
-
|
2644
|
-
interface Output$1<OUTPUT, PARTIAL> {
|
2645
|
-
readonly type: 'object' | 'text';
|
2646
|
-
responseFormat: LanguageModelV2CallOptions['responseFormat'];
|
2647
|
-
parsePartial(options: {
|
2648
|
-
text: string;
|
2649
|
-
}): Promise<{
|
2650
|
-
partial: PARTIAL;
|
2651
|
-
} | undefined>;
|
2652
|
-
parseOutput(options: {
|
2653
|
-
text: string;
|
2654
|
-
}, context: {
|
2655
|
-
response: LanguageModelResponseMetadata;
|
2656
|
-
usage: LanguageModelUsage;
|
2657
|
-
finishReason: FinishReason;
|
2658
|
-
}): Promise<OUTPUT>;
|
2659
|
-
}
|
2660
|
-
declare const text: () => Output$1<string, string>;
|
2661
|
-
declare const object: <OUTPUT>({ schema: inputSchema, }: {
|
2662
|
-
schema: z.Schema<OUTPUT, z.ZodTypeDef, any> | Schema<OUTPUT>;
|
2663
|
-
}) => Output$1<OUTPUT, DeepPartial<OUTPUT>>;
|
2664
|
-
|
2665
|
-
declare const output_object: typeof object;
|
2666
|
-
declare const output_text: typeof text;
|
2667
|
-
declare namespace output {
|
2668
|
-
export {
|
2669
|
-
Output$1 as Output,
|
2670
|
-
output_object as object,
|
2671
|
-
output_text as text,
|
2672
|
-
};
|
2673
|
-
}
|
2674
|
-
|
2675
|
-
declare const symbol$f: unique symbol;
|
2231
|
+
declare const symbol$e: unique symbol;
|
2676
2232
|
declare class InvalidToolArgumentsError extends AISDKError {
|
2677
|
-
private readonly [symbol$
|
2233
|
+
private readonly [symbol$e];
|
2678
2234
|
readonly toolName: string;
|
2679
2235
|
readonly toolArgs: string;
|
2680
2236
|
constructor({ toolArgs, toolName, cause, message, }: {
|
@@ -2686,9 +2242,9 @@ declare class InvalidToolArgumentsError extends AISDKError {
|
|
2686
2242
|
static isInstance(error: unknown): error is InvalidToolArgumentsError;
|
2687
2243
|
}
|
2688
2244
|
|
2689
|
-
declare const symbol$
|
2245
|
+
declare const symbol$d: unique symbol;
|
2690
2246
|
declare class NoSuchToolError extends AISDKError {
|
2691
|
-
private readonly [symbol$
|
2247
|
+
private readonly [symbol$d];
|
2692
2248
|
readonly toolName: string;
|
2693
2249
|
readonly availableTools: string[] | undefined;
|
2694
2250
|
constructor({ toolName, availableTools, message, }: {
|
@@ -2699,45 +2255,103 @@ declare class NoSuchToolError extends AISDKError {
|
|
2699
2255
|
static isInstance(error: unknown): error is NoSuchToolError;
|
2700
2256
|
}
|
2701
2257
|
|
2702
|
-
|
2703
|
-
* Appends a client message to the messages array.
|
2704
|
-
* If the last message in the array has the same id as the new message, it will be replaced.
|
2705
|
-
* Otherwise, the new message will be appended.
|
2706
|
-
*/
|
2707
|
-
declare function appendClientMessage({ messages, message, }: {
|
2708
|
-
messages: UIMessage[];
|
2709
|
-
message: UIMessage;
|
2710
|
-
}): UIMessage[];
|
2711
|
-
|
2712
|
-
/**
|
2713
|
-
* Appends the ResponseMessage[] from the response to a Message[] (for useChat).
|
2714
|
-
* The messages are converted to Messages before being appended.
|
2715
|
-
* Timestamps are generated for the new messages.
|
2716
|
-
*
|
2717
|
-
* @returns A new Message[] with the response messages appended.
|
2718
|
-
*/
|
2719
|
-
declare function appendResponseMessages({ messages, responseMessages, _internal: { currentDate }, }: {
|
2720
|
-
messages: UIMessage[];
|
2721
|
-
responseMessages: ResponseMessage[];
|
2258
|
+
type CallSettings = {
|
2722
2259
|
/**
|
2723
|
-
|
2724
|
-
|
2725
|
-
|
2726
|
-
|
2727
|
-
|
2728
|
-
|
2260
|
+
Maximum number of tokens to generate.
|
2261
|
+
*/
|
2262
|
+
maxOutputTokens?: number;
|
2263
|
+
/**
|
2264
|
+
Temperature setting. This is a number between 0 (almost no randomness) and
|
2265
|
+
1 (very random).
|
2266
|
+
|
2267
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
2268
|
+
Use `null` to use the provider's default temperature.
|
2269
|
+
|
2270
|
+
@default 0
|
2271
|
+
*/
|
2272
|
+
temperature?: number | null;
|
2273
|
+
/**
|
2274
|
+
Nucleus sampling. This is a number between 0 and 1.
|
2275
|
+
|
2276
|
+
E.g. 0.1 would mean that only tokens with the top 10% probability mass
|
2277
|
+
are considered.
|
2278
|
+
|
2279
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
2280
|
+
*/
|
2281
|
+
topP?: number;
|
2282
|
+
/**
|
2283
|
+
Only sample from the top K options for each subsequent token.
|
2284
|
+
|
2285
|
+
Used to remove "long tail" low probability responses.
|
2286
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
2287
|
+
*/
|
2288
|
+
topK?: number;
|
2289
|
+
/**
|
2290
|
+
Presence penalty setting. It affects the likelihood of the model to
|
2291
|
+
repeat information that is already in the prompt.
|
2292
|
+
|
2293
|
+
The presence penalty is a number between -1 (increase repetition)
|
2294
|
+
and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
2295
|
+
*/
|
2296
|
+
presencePenalty?: number;
|
2297
|
+
/**
|
2298
|
+
Frequency penalty setting. It affects the likelihood of the model
|
2299
|
+
to repeatedly use the same words or phrases.
|
2300
|
+
|
2301
|
+
The frequency penalty is a number between -1 (increase repetition)
|
2302
|
+
and 1 (maximum penalty, decrease repetition). 0 means no penalty.
|
2303
|
+
*/
|
2304
|
+
frequencyPenalty?: number;
|
2305
|
+
/**
|
2306
|
+
Stop sequences.
|
2307
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
2308
|
+
Providers may have limits on the number of stop sequences.
|
2309
|
+
*/
|
2310
|
+
stopSequences?: string[];
|
2311
|
+
/**
|
2312
|
+
The seed (integer) to use for random sampling. If set and supported
|
2313
|
+
by the model, calls will generate deterministic results.
|
2314
|
+
*/
|
2315
|
+
seed?: number;
|
2316
|
+
/**
|
2317
|
+
Maximum number of retries. Set to 0 to disable retries.
|
2318
|
+
|
2319
|
+
@default 2
|
2320
|
+
*/
|
2321
|
+
maxRetries?: number;
|
2322
|
+
/**
|
2323
|
+
Abort signal.
|
2324
|
+
*/
|
2325
|
+
abortSignal?: AbortSignal;
|
2326
|
+
/**
|
2327
|
+
Additional HTTP headers to be sent with the request.
|
2328
|
+
Only applicable for HTTP-based providers.
|
2329
|
+
*/
|
2330
|
+
headers?: Record<string, string | undefined>;
|
2331
|
+
};
|
2729
2332
|
|
2730
2333
|
/**
|
2731
|
-
|
2732
|
-
|
2733
|
-
*/
|
2734
|
-
declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<UIMessage, 'id'>>, options?: {
|
2735
|
-
tools?: TOOLS;
|
2736
|
-
}): ModelMessage[];
|
2737
|
-
/**
|
2738
|
-
@deprecated Use `convertToModelMessages` instead.
|
2334
|
+
Prompt part of the AI function options.
|
2335
|
+
It contains a system message, a simple text prompt, or a list of messages.
|
2739
2336
|
*/
|
2740
|
-
|
2337
|
+
type Prompt = {
|
2338
|
+
/**
|
2339
|
+
System message to include in the prompt. Can be used with `prompt` or `messages`.
|
2340
|
+
*/
|
2341
|
+
system?: string;
|
2342
|
+
/**
|
2343
|
+
A prompt. It can be either a text prompt or a list of messages.
|
2344
|
+
|
2345
|
+
You can either use `prompt` or `messages` but not both.
|
2346
|
+
*/
|
2347
|
+
prompt?: string | Array<ModelMessage>;
|
2348
|
+
/**
|
2349
|
+
A list of messages.
|
2350
|
+
|
2351
|
+
You can either use `prompt` or `messages` but not both.
|
2352
|
+
*/
|
2353
|
+
messages?: Array<ModelMessage>;
|
2354
|
+
};
|
2741
2355
|
|
2742
2356
|
/**
|
2743
2357
|
* A function that attempts to repair a tool call that failed to parse.
|
@@ -2763,549 +2377,1323 @@ type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
|
|
2763
2377
|
error: NoSuchToolError | InvalidToolArgumentsError;
|
2764
2378
|
}) => Promise<LanguageModelV2ToolCall | null>;
|
2765
2379
|
|
2380
|
+
type ToToolsWithDefinedExecute<TOOLS extends ToolSet> = {
|
2381
|
+
[K in keyof TOOLS as TOOLS[K]['execute'] extends undefined ? never : K]: TOOLS[K];
|
2382
|
+
};
|
2383
|
+
type ToToolResultObject<TOOLS extends ToolSet> = ValueOf<{
|
2384
|
+
[NAME in keyof TOOLS]: {
|
2385
|
+
type: 'tool-result';
|
2386
|
+
toolCallId: string;
|
2387
|
+
toolName: NAME & string;
|
2388
|
+
args: TOOLS[NAME] extends Tool<infer P> ? P : never;
|
2389
|
+
result: Awaited<ReturnType<Exclude<TOOLS[NAME]['execute'], undefined>>>;
|
2390
|
+
};
|
2391
|
+
}>;
|
2392
|
+
type ToolResultUnion<TOOLS extends ToolSet> = ToToolResultObject<ToToolsWithDefinedExecute<TOOLS>>;
|
2393
|
+
type ToolResultArray<TOOLS extends ToolSet> = Array<ToolResultUnion<TOOLS>>;
|
2394
|
+
|
2395
|
+
type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
|
2396
|
+
type: 'stream-start';
|
2397
|
+
warnings: LanguageModelV2CallWarning[];
|
2398
|
+
} | {
|
2399
|
+
type: 'text';
|
2400
|
+
text: string;
|
2401
|
+
} | {
|
2402
|
+
type: 'reasoning';
|
2403
|
+
text: string;
|
2404
|
+
providerMetadata?: ProviderMetadata;
|
2405
|
+
} | {
|
2406
|
+
type: 'reasoning-part-finish';
|
2407
|
+
} | {
|
2408
|
+
type: 'file';
|
2409
|
+
file: GeneratedFile;
|
2410
|
+
} | ({
|
2411
|
+
type: 'source';
|
2412
|
+
} & Source) | ({
|
2413
|
+
type: 'tool-call';
|
2414
|
+
} & ToolCallUnion<TOOLS>) | {
|
2415
|
+
type: 'tool-call-streaming-start';
|
2416
|
+
toolCallId: string;
|
2417
|
+
toolName: string;
|
2418
|
+
} | {
|
2419
|
+
type: 'tool-call-delta';
|
2420
|
+
toolCallId: string;
|
2421
|
+
toolName: string;
|
2422
|
+
argsTextDelta: string;
|
2423
|
+
} | ({
|
2424
|
+
type: 'tool-result';
|
2425
|
+
} & ToolResultUnion<TOOLS>) | {
|
2426
|
+
type: 'response-metadata';
|
2427
|
+
id?: string;
|
2428
|
+
timestamp?: Date;
|
2429
|
+
modelId?: string;
|
2430
|
+
} | {
|
2431
|
+
type: 'finish';
|
2432
|
+
finishReason: FinishReason;
|
2433
|
+
usage: LanguageModelUsage;
|
2434
|
+
providerMetadata?: ProviderMetadata;
|
2435
|
+
} | {
|
2436
|
+
type: 'error';
|
2437
|
+
error: unknown;
|
2438
|
+
};
|
2439
|
+
|
2440
|
+
declare const symbol$c: unique symbol;
|
2441
|
+
declare class InvalidStreamPartError extends AISDKError {
|
2442
|
+
private readonly [symbol$c];
|
2443
|
+
readonly chunk: SingleRequestTextStreamPart<any>;
|
2444
|
+
constructor({ chunk, message, }: {
|
2445
|
+
chunk: SingleRequestTextStreamPart<any>;
|
2446
|
+
message: string;
|
2447
|
+
});
|
2448
|
+
static isInstance(error: unknown): error is InvalidStreamPartError;
|
2449
|
+
}
|
2450
|
+
|
2451
|
+
declare const symbol$b: unique symbol;
|
2452
|
+
/**
|
2453
|
+
* An error occurred with the MCP client.
|
2454
|
+
*/
|
2455
|
+
declare class MCPClientError extends AISDKError {
|
2456
|
+
private readonly [symbol$b];
|
2457
|
+
constructor({ name, message, cause, }: {
|
2458
|
+
name?: string;
|
2459
|
+
message: string;
|
2460
|
+
cause?: unknown;
|
2461
|
+
});
|
2462
|
+
static isInstance(error: unknown): error is MCPClientError;
|
2463
|
+
}
|
2464
|
+
|
2465
|
+
declare const symbol$a: unique symbol;
|
2466
|
+
/**
|
2467
|
+
Thrown when no image could be generated. This can have multiple causes:
|
2468
|
+
|
2469
|
+
- The model failed to generate a response.
|
2470
|
+
- The model generated a response that could not be parsed.
|
2471
|
+
*/
|
2472
|
+
declare class NoImageGeneratedError extends AISDKError {
|
2473
|
+
private readonly [symbol$a];
|
2474
|
+
/**
|
2475
|
+
The response metadata for each call.
|
2476
|
+
*/
|
2477
|
+
readonly responses: Array<ImageModelResponseMetadata> | undefined;
|
2478
|
+
constructor({ message, cause, responses, }: {
|
2479
|
+
message?: string;
|
2480
|
+
cause?: Error;
|
2481
|
+
responses?: Array<ImageModelResponseMetadata>;
|
2482
|
+
});
|
2483
|
+
static isInstance(error: unknown): error is NoImageGeneratedError;
|
2484
|
+
}
|
2485
|
+
|
2486
|
+
declare const symbol$9: unique symbol;
|
2487
|
+
/**
|
2488
|
+
Thrown when no object could be generated. This can have several causes:
|
2489
|
+
|
2490
|
+
- The model failed to generate a response.
|
2491
|
+
- The model generated a response that could not be parsed.
|
2492
|
+
- The model generated a response that could not be validated against the schema.
|
2493
|
+
|
2494
|
+
The error contains the following properties:
|
2495
|
+
|
2496
|
+
- `text`: The text that was generated by the model. This can be the raw text or the tool call text, depending on the model.
|
2497
|
+
*/
|
2498
|
+
declare class NoObjectGeneratedError extends AISDKError {
|
2499
|
+
private readonly [symbol$9];
|
2500
|
+
/**
|
2501
|
+
The text that was generated by the model. This can be the raw text or the tool call text, depending on the model.
|
2502
|
+
*/
|
2503
|
+
readonly text: string | undefined;
|
2504
|
+
/**
|
2505
|
+
The response metadata.
|
2506
|
+
*/
|
2507
|
+
readonly response: LanguageModelResponseMetadata | undefined;
|
2508
|
+
/**
|
2509
|
+
The usage of the model.
|
2510
|
+
*/
|
2511
|
+
readonly usage: LanguageModelUsage | undefined;
|
2512
|
+
/**
|
2513
|
+
Reason why the model finished generating a response.
|
2514
|
+
*/
|
2515
|
+
readonly finishReason: FinishReason | undefined;
|
2516
|
+
constructor({ message, cause, text, response, usage, finishReason, }: {
|
2517
|
+
message?: string;
|
2518
|
+
cause?: Error;
|
2519
|
+
text?: string;
|
2520
|
+
response: LanguageModelResponseMetadata;
|
2521
|
+
usage: LanguageModelUsage;
|
2522
|
+
finishReason: FinishReason;
|
2523
|
+
});
|
2524
|
+
static isInstance(error: unknown): error is NoObjectGeneratedError;
|
2525
|
+
}
|
2526
|
+
|
2527
|
+
declare const symbol$8: unique symbol;
|
2766
2528
|
/**
|
2767
|
-
|
2768
|
-
|
2769
|
-
@param stepResult - The result of the step.
|
2529
|
+
Thrown when no output type is specified and output-related methods are called.
|
2770
2530
|
*/
|
2771
|
-
|
2772
|
-
|
2773
|
-
|
2774
|
-
|
2775
|
-
|
2776
|
-
|
2777
|
-
|
2778
|
-
|
2779
|
-
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
2780
|
-
@param toolChoice - The tool choice strategy. Default: 'auto'.
|
2531
|
+
declare class NoOutputSpecifiedError extends AISDKError {
|
2532
|
+
private readonly [symbol$8];
|
2533
|
+
constructor({ message }?: {
|
2534
|
+
message?: string;
|
2535
|
+
});
|
2536
|
+
static isInstance(error: unknown): error is NoOutputSpecifiedError;
|
2537
|
+
}
|
2781
2538
|
|
2782
|
-
|
2783
|
-
|
2784
|
-
|
2539
|
+
declare const symbol$7: unique symbol;
|
2540
|
+
declare class ToolCallRepairError extends AISDKError {
|
2541
|
+
private readonly [symbol$7];
|
2542
|
+
readonly originalError: NoSuchToolError | InvalidToolArgumentsError;
|
2543
|
+
constructor({ cause, originalError, message, }: {
|
2544
|
+
message?: string;
|
2545
|
+
cause: unknown;
|
2546
|
+
originalError: NoSuchToolError | InvalidToolArgumentsError;
|
2547
|
+
});
|
2548
|
+
static isInstance(error: unknown): error is ToolCallRepairError;
|
2549
|
+
}
|
2785
2550
|
|
2786
|
-
|
2787
|
-
|
2788
|
-
|
2789
|
-
|
2790
|
-
|
2791
|
-
|
2792
|
-
|
2793
|
-
|
2794
|
-
|
2795
|
-
|
2796
|
-
|
2797
|
-
|
2798
|
-
|
2799
|
-
|
2800
|
-
|
2801
|
-
The value is passed through to the provider. The range depends on the provider and model.
|
2802
|
-
@param stopSequences - Stop sequences.
|
2803
|
-
If set, the model will stop generating text when one of the stop sequences is generated.
|
2804
|
-
@param seed - The seed (integer) to use for random sampling.
|
2805
|
-
If set and supported by the model, calls will generate deterministic results.
|
2551
|
+
declare const symbol$6: unique symbol;
|
2552
|
+
declare class ToolExecutionError extends AISDKError {
|
2553
|
+
private readonly [symbol$6];
|
2554
|
+
readonly toolName: string;
|
2555
|
+
readonly toolArgs: JSONValue$1 | unknown;
|
2556
|
+
readonly toolCallId: string;
|
2557
|
+
constructor({ toolArgs, toolName, toolCallId, cause, message, }: {
|
2558
|
+
message?: string;
|
2559
|
+
toolArgs: JSONValue$1 | unknown;
|
2560
|
+
toolName: string;
|
2561
|
+
toolCallId: string;
|
2562
|
+
cause: unknown;
|
2563
|
+
});
|
2564
|
+
static isInstance(error: unknown): error is ToolExecutionError;
|
2565
|
+
}
|
2806
2566
|
|
2807
|
-
|
2808
|
-
|
2809
|
-
|
2567
|
+
declare const symbol$5: unique symbol;
|
2568
|
+
declare class InvalidDataContentError extends AISDKError {
|
2569
|
+
private readonly [symbol$5];
|
2570
|
+
readonly content: unknown;
|
2571
|
+
constructor({ content, cause, message, }: {
|
2572
|
+
content: unknown;
|
2573
|
+
cause?: unknown;
|
2574
|
+
message?: string;
|
2575
|
+
});
|
2576
|
+
static isInstance(error: unknown): error is InvalidDataContentError;
|
2577
|
+
}
|
2810
2578
|
|
2811
|
-
|
2812
|
-
|
2579
|
+
declare const symbol$4: unique symbol;
|
2580
|
+
declare class InvalidMessageRoleError extends AISDKError {
|
2581
|
+
private readonly [symbol$4];
|
2582
|
+
readonly role: string;
|
2583
|
+
constructor({ role, message, }: {
|
2584
|
+
role: string;
|
2585
|
+
message?: string;
|
2586
|
+
});
|
2587
|
+
static isInstance(error: unknown): error is InvalidMessageRoleError;
|
2588
|
+
}
|
2813
2589
|
|
2814
|
-
|
2590
|
+
/**
|
2591
|
+
Tool invocations are either tool calls or tool results. For each assistant tool call,
|
2592
|
+
there is one tool invocation. While the call is in progress, the invocation is a tool call.
|
2593
|
+
Once the call is complete, the invocation is a tool result.
|
2815
2594
|
|
2816
|
-
|
2817
|
-
|
2595
|
+
The step is used to track how to map an assistant UI message with many tool invocations
|
2596
|
+
back to a sequence of LLM assistant/tool result message pairs.
|
2597
|
+
It is optional for backwards compatibility.
|
2818
2598
|
*/
|
2819
|
-
|
2599
|
+
type ToolInvocation = ({
|
2600
|
+
state: 'partial-call';
|
2601
|
+
step?: number;
|
2602
|
+
} & ToolCall<string, any>) | ({
|
2603
|
+
state: 'call';
|
2604
|
+
step?: number;
|
2605
|
+
} & ToolCall<string, any>) | ({
|
2606
|
+
state: 'result';
|
2607
|
+
step?: number;
|
2608
|
+
} & ToolResult<string, any, any>);
|
2609
|
+
/**
|
2610
|
+
* AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
2611
|
+
*/
|
2612
|
+
interface UIMessage {
|
2820
2613
|
/**
|
2821
|
-
|
2614
|
+
A unique identifier for the message.
|
2822
2615
|
*/
|
2823
|
-
|
2824
|
-
/**
|
2825
|
-
The tools that the model can call. The model needs to support calling tools.
|
2826
|
-
*/
|
2827
|
-
tools?: TOOLS;
|
2616
|
+
id: string;
|
2828
2617
|
/**
|
2829
|
-
The
|
2618
|
+
The timestamp of the message.
|
2830
2619
|
*/
|
2831
|
-
|
2620
|
+
createdAt?: Date;
|
2832
2621
|
/**
|
2833
|
-
|
2834
|
-
|
2835
|
-
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
2836
|
-
|
2837
|
-
By default, it's set to 1, which means that only a single LLM call is made.
|
2622
|
+
The role of the message.
|
2838
2623
|
*/
|
2839
|
-
|
2624
|
+
role: 'system' | 'user' | 'assistant';
|
2840
2625
|
/**
|
2841
|
-
|
2626
|
+
Additional message-specific information added on the server via StreamData
|
2842
2627
|
*/
|
2843
|
-
|
2628
|
+
annotations?: JSONValue$1[] | undefined;
|
2844
2629
|
/**
|
2845
|
-
|
2846
|
-
|
2847
|
-
|
2630
|
+
The parts of the message. Use this for rendering the message in the UI.
|
2631
|
+
|
2632
|
+
System messages should be avoided (set the system prompt on the server instead).
|
2633
|
+
They can have text parts.
|
2634
|
+
|
2635
|
+
User messages can have text parts and file parts.
|
2636
|
+
|
2637
|
+
Assistant messages can have text, reasoning, tool invocation, and file parts.
|
2848
2638
|
*/
|
2849
|
-
|
2639
|
+
parts: Array<UIMessagePart>;
|
2640
|
+
}
|
2641
|
+
type UIMessagePart = TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | StepStartUIPart;
|
2642
|
+
/**
|
2643
|
+
* A text part of a message.
|
2644
|
+
*/
|
2645
|
+
type TextUIPart = {
|
2646
|
+
type: 'text';
|
2850
2647
|
/**
|
2851
|
-
|
2648
|
+
* The text content.
|
2852
2649
|
*/
|
2853
|
-
|
2854
|
-
|
2855
|
-
|
2856
|
-
|
2857
|
-
functionality that can be fully encapsulated in the provider.
|
2650
|
+
text: string;
|
2651
|
+
};
|
2652
|
+
/**
|
2653
|
+
* A reasoning part of a message.
|
2858
2654
|
*/
|
2859
|
-
|
2655
|
+
type ReasoningUIPart = {
|
2656
|
+
type: 'reasoning';
|
2860
2657
|
/**
|
2861
|
-
|
2862
|
-
changing the tool call and result types in the result.
|
2658
|
+
* The reasoning text.
|
2863
2659
|
*/
|
2864
|
-
|
2660
|
+
text: string;
|
2865
2661
|
/**
|
2866
|
-
|
2662
|
+
* The provider metadata.
|
2867
2663
|
*/
|
2868
|
-
|
2664
|
+
providerMetadata?: Record<string, any>;
|
2665
|
+
};
|
2666
|
+
/**
|
2667
|
+
* A tool invocation part of a message.
|
2668
|
+
*/
|
2669
|
+
type ToolInvocationUIPart = {
|
2670
|
+
type: 'tool-invocation';
|
2869
2671
|
/**
|
2870
|
-
|
2871
|
-
|
2872
|
-
|
2873
|
-
|
2874
|
-
|
2875
|
-
|
2876
|
-
|
2877
|
-
|
2878
|
-
|
2879
|
-
If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
2880
|
-
*/
|
2881
|
-
experimental_prepareStep?: (options: {
|
2882
|
-
steps: Array<StepResult<TOOLS>>;
|
2883
|
-
stepNumber: number;
|
2884
|
-
maxSteps: number;
|
2885
|
-
model: LanguageModel;
|
2886
|
-
}) => PromiseLike<{
|
2887
|
-
model?: LanguageModel;
|
2888
|
-
toolChoice?: ToolChoice<TOOLS>;
|
2889
|
-
experimental_activeTools?: Array<keyof TOOLS>;
|
2890
|
-
} | undefined>;
|
2672
|
+
* The tool invocation.
|
2673
|
+
*/
|
2674
|
+
toolInvocation: ToolInvocation;
|
2675
|
+
};
|
2676
|
+
/**
|
2677
|
+
* A source part of a message.
|
2678
|
+
*/
|
2679
|
+
type SourceUIPart = {
|
2680
|
+
type: 'source';
|
2891
2681
|
/**
|
2892
|
-
|
2682
|
+
* The source.
|
2893
2683
|
*/
|
2894
|
-
|
2684
|
+
source: LanguageModelV2Source;
|
2685
|
+
};
|
2686
|
+
/**
|
2687
|
+
* A file part of a message.
|
2688
|
+
*/
|
2689
|
+
type FileUIPart = {
|
2690
|
+
type: 'file';
|
2895
2691
|
/**
|
2896
|
-
|
2897
|
-
|
2898
|
-
|
2692
|
+
* IANA media type of the file.
|
2693
|
+
*
|
2694
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
2695
|
+
*/
|
2696
|
+
mediaType: string;
|
2899
2697
|
/**
|
2900
|
-
*
|
2698
|
+
* Optional filename of the file.
|
2901
2699
|
*/
|
2902
|
-
|
2903
|
-
|
2904
|
-
|
2905
|
-
|
2906
|
-
|
2700
|
+
filename?: string;
|
2701
|
+
/**
|
2702
|
+
* The URL of the file.
|
2703
|
+
* It can either be a URL to a hosted file or a [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs).
|
2704
|
+
*/
|
2705
|
+
url: string;
|
2706
|
+
};
|
2707
|
+
/**
|
2708
|
+
* A step boundary part of a message.
|
2709
|
+
*/
|
2710
|
+
type StepStartUIPart = {
|
2711
|
+
type: 'step-start';
|
2712
|
+
};
|
2713
|
+
type CreateUIMessage = Omit<UIMessage, 'id'> & {
|
2714
|
+
id?: UIMessage['id'];
|
2715
|
+
};
|
2907
2716
|
|
2908
|
-
declare const
|
2909
|
-
|
2910
|
-
|
2911
|
-
|
2912
|
-
|
2913
|
-
|
2914
|
-
|
2915
|
-
|
2916
|
-
|
2917
|
-
}
|
2918
|
-
|
2919
|
-
|
2920
|
-
|
2921
|
-
|
2922
|
-
|
2923
|
-
|
2924
|
-
|
2925
|
-
|
2926
|
-
|
2927
|
-
|
2928
|
-
|
2929
|
-
|
2930
|
-
|
2931
|
-
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2936
|
-
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
|
2943
|
-
|
2944
|
-
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
2951
|
-
|
2952
|
-
|
2953
|
-
|
2954
|
-
|
2955
|
-
|
2956
|
-
|
2957
|
-
|
2958
|
-
|
2959
|
-
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2963
|
-
|
2964
|
-
|
2965
|
-
|
2966
|
-
|
2967
|
-
|
2968
|
-
|
2969
|
-
|
2970
|
-
|
2971
|
-
|
2972
|
-
|
2973
|
-
|
2974
|
-
|
2975
|
-
|
2976
|
-
|
2977
|
-
|
2978
|
-
|
2979
|
-
|
2980
|
-
|
2981
|
-
|
2982
|
-
|
2983
|
-
|
2984
|
-
|
2985
|
-
|
2986
|
-
|
2987
|
-
|
2988
|
-
|
2989
|
-
|
2990
|
-
|
2991
|
-
|
2992
|
-
|
2993
|
-
|
2994
|
-
|
2995
|
-
|
2996
|
-
|
2997
|
-
|
2998
|
-
|
2999
|
-
|
3000
|
-
|
3001
|
-
|
3002
|
-
|
3003
|
-
|
3004
|
-
|
3005
|
-
|
3006
|
-
|
3007
|
-
|
3008
|
-
|
3009
|
-
|
3010
|
-
|
3011
|
-
|
3012
|
-
|
3013
|
-
|
3014
|
-
|
3015
|
-
|
3016
|
-
|
3017
|
-
|
3018
|
-
|
3019
|
-
|
3020
|
-
|
3021
|
-
|
3022
|
-
|
3023
|
-
|
3024
|
-
|
3025
|
-
|
3026
|
-
|
3027
|
-
|
3028
|
-
|
3029
|
-
|
3030
|
-
|
3031
|
-
|
3032
|
-
|
3033
|
-
|
3034
|
-
|
3035
|
-
|
3036
|
-
|
3037
|
-
|
3038
|
-
|
3039
|
-
|
3040
|
-
|
3041
|
-
|
3042
|
-
|
3043
|
-
|
3044
|
-
|
3045
|
-
|
3046
|
-
|
3047
|
-
|
3048
|
-
|
3049
|
-
|
3050
|
-
|
3051
|
-
|
3052
|
-
|
3053
|
-
|
3054
|
-
|
3055
|
-
|
3056
|
-
|
3057
|
-
|
3058
|
-
|
3059
|
-
|
3060
|
-
|
3061
|
-
|
3062
|
-
|
3063
|
-
totalTokens?: number | undefined;
|
3064
|
-
reasoningTokens?: number | undefined;
|
3065
|
-
cachedInputTokens?: number | undefined;
|
3066
|
-
}, {
|
3067
|
-
inputTokens?: number | undefined;
|
3068
|
-
outputTokens?: number | undefined;
|
3069
|
-
totalTokens?: number | undefined;
|
3070
|
-
reasoningTokens?: number | undefined;
|
3071
|
-
cachedInputTokens?: number | undefined;
|
3072
|
-
}>>;
|
3073
|
-
}, "strip", z.ZodTypeAny, {
|
3074
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3075
|
-
usage?: {
|
3076
|
-
inputTokens?: number | undefined;
|
3077
|
-
outputTokens?: number | undefined;
|
3078
|
-
totalTokens?: number | undefined;
|
3079
|
-
reasoningTokens?: number | undefined;
|
3080
|
-
cachedInputTokens?: number | undefined;
|
3081
|
-
} | undefined;
|
3082
|
-
}, {
|
3083
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3084
|
-
usage?: {
|
3085
|
-
inputTokens?: number | undefined;
|
3086
|
-
outputTokens?: number | undefined;
|
3087
|
-
totalTokens?: number | undefined;
|
3088
|
-
reasoningTokens?: number | undefined;
|
3089
|
-
cachedInputTokens?: number | undefined;
|
3090
|
-
} | undefined;
|
3091
|
-
}>;
|
3092
|
-
}, "strip", z.ZodTypeAny, {
|
3093
|
-
value: {
|
3094
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3095
|
-
usage?: {
|
3096
|
-
inputTokens?: number | undefined;
|
3097
|
-
outputTokens?: number | undefined;
|
3098
|
-
totalTokens?: number | undefined;
|
3099
|
-
reasoningTokens?: number | undefined;
|
3100
|
-
cachedInputTokens?: number | undefined;
|
3101
|
-
} | undefined;
|
3102
|
-
};
|
3103
|
-
type: "finish-message";
|
3104
|
-
}, {
|
3105
|
-
value: {
|
3106
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3107
|
-
usage?: {
|
3108
|
-
inputTokens?: number | undefined;
|
3109
|
-
outputTokens?: number | undefined;
|
3110
|
-
totalTokens?: number | undefined;
|
3111
|
-
reasoningTokens?: number | undefined;
|
3112
|
-
cachedInputTokens?: number | undefined;
|
3113
|
-
} | undefined;
|
2717
|
+
declare const symbol$3: unique symbol;
|
2718
|
+
declare class MessageConversionError extends AISDKError {
|
2719
|
+
private readonly [symbol$3];
|
2720
|
+
readonly originalMessage: Omit<UIMessage, 'id'>;
|
2721
|
+
constructor({ originalMessage, message, }: {
|
2722
|
+
originalMessage: Omit<UIMessage, 'id'>;
|
2723
|
+
message: string;
|
2724
|
+
});
|
2725
|
+
static isInstance(error: unknown): error is MessageConversionError;
|
2726
|
+
}
|
2727
|
+
|
2728
|
+
declare const symbol$2: unique symbol;
|
2729
|
+
declare class DownloadError extends AISDKError {
|
2730
|
+
private readonly [symbol$2];
|
2731
|
+
readonly url: string;
|
2732
|
+
readonly statusCode?: number;
|
2733
|
+
readonly statusText?: string;
|
2734
|
+
constructor({ url, statusCode, statusText, cause, message, }: {
|
2735
|
+
url: string;
|
2736
|
+
statusCode?: number;
|
2737
|
+
statusText?: string;
|
2738
|
+
message?: string;
|
2739
|
+
cause?: unknown;
|
2740
|
+
});
|
2741
|
+
static isInstance(error: unknown): error is DownloadError;
|
2742
|
+
}
|
2743
|
+
|
2744
|
+
declare const symbol$1: unique symbol;
|
2745
|
+
type RetryErrorReason = 'maxRetriesExceeded' | 'errorNotRetryable' | 'abort';
|
2746
|
+
declare class RetryError extends AISDKError {
|
2747
|
+
private readonly [symbol$1];
|
2748
|
+
readonly reason: RetryErrorReason;
|
2749
|
+
readonly lastError: unknown;
|
2750
|
+
readonly errors: Array<unknown>;
|
2751
|
+
constructor({ message, reason, errors, }: {
|
2752
|
+
message: string;
|
2753
|
+
reason: RetryErrorReason;
|
2754
|
+
errors: Array<unknown>;
|
2755
|
+
});
|
2756
|
+
static isInstance(error: unknown): error is RetryError;
|
2757
|
+
}
|
2758
|
+
|
2759
|
+
declare function createTextStreamResponse({ status, statusText, headers, textStream, }: ResponseInit & {
|
2760
|
+
textStream: ReadableStream<string>;
|
2761
|
+
}): Response;
|
2762
|
+
|
2763
|
+
declare function pipeTextStreamToResponse({ response, status, statusText, headers, textStream, }: {
|
2764
|
+
response: ServerResponse;
|
2765
|
+
textStream: ReadableStream<string>;
|
2766
|
+
} & ResponseInit): void;
|
2767
|
+
|
2768
|
+
/**
|
2769
|
+
* Appends a client message to the messages array.
|
2770
|
+
* If the last message in the array has the same id as the new message, it will be replaced.
|
2771
|
+
* Otherwise, the new message will be appended.
|
2772
|
+
*/
|
2773
|
+
declare function appendClientMessage({ messages, message, }: {
|
2774
|
+
messages: UIMessage[];
|
2775
|
+
message: UIMessage;
|
2776
|
+
}): UIMessage[];
|
2777
|
+
|
2778
|
+
type ContentPart<TOOLS extends ToolSet> = {
|
2779
|
+
type: 'text';
|
2780
|
+
text: string;
|
2781
|
+
} | {
|
2782
|
+
type: 'reasoning';
|
2783
|
+
text: string;
|
2784
|
+
providerMetadata?: ProviderMetadata;
|
2785
|
+
} | ({
|
2786
|
+
type: 'source';
|
2787
|
+
} & Source) | {
|
2788
|
+
type: 'file';
|
2789
|
+
file: GeneratedFile;
|
2790
|
+
} | ({
|
2791
|
+
type: 'tool-call';
|
2792
|
+
} & ToolCallUnion<TOOLS>) | ({
|
2793
|
+
type: 'tool-result';
|
2794
|
+
} & ToolResultUnion<TOOLS>);
|
2795
|
+
|
2796
|
+
/**
|
2797
|
+
A message that was generated during the generation process.
|
2798
|
+
It can be either an assistant message or a tool message.
|
2799
|
+
*/
|
2800
|
+
type ResponseMessage = (AssistantModelMessage | ToolModelMessage) & {
|
2801
|
+
/**
|
2802
|
+
Message ID generated by the AI SDK.
|
2803
|
+
*/
|
2804
|
+
id: string;
|
2805
|
+
};
|
2806
|
+
/**
|
2807
|
+
* The result of a single step in the generation process.
|
2808
|
+
*/
|
2809
|
+
type StepResult<TOOLS extends ToolSet> = {
|
2810
|
+
/**
|
2811
|
+
The content that was generated in the last step.
|
2812
|
+
*/
|
2813
|
+
readonly content: Array<ContentPart<TOOLS>>;
|
2814
|
+
/**
|
2815
|
+
The generated text.
|
2816
|
+
*/
|
2817
|
+
readonly text: string;
|
2818
|
+
/**
|
2819
|
+
The reasoning that was generated during the generation.
|
2820
|
+
*/
|
2821
|
+
readonly reasoning: Array<ReasoningPart>;
|
2822
|
+
/**
|
2823
|
+
The reasoning text that was generated during the generation.
|
2824
|
+
*/
|
2825
|
+
readonly reasoningText: string | undefined;
|
2826
|
+
/**
|
2827
|
+
The files that were generated during the generation.
|
2828
|
+
*/
|
2829
|
+
readonly files: Array<GeneratedFile>;
|
2830
|
+
/**
|
2831
|
+
The sources that were used to generate the text.
|
2832
|
+
*/
|
2833
|
+
readonly sources: Array<Source>;
|
2834
|
+
/**
|
2835
|
+
The tool calls that were made during the generation.
|
2836
|
+
*/
|
2837
|
+
readonly toolCalls: ToolCallArray<TOOLS>;
|
2838
|
+
/**
|
2839
|
+
The results of the tool calls.
|
2840
|
+
*/
|
2841
|
+
readonly toolResults: ToolResultArray<TOOLS>;
|
2842
|
+
/**
|
2843
|
+
The reason why the generation finished.
|
2844
|
+
*/
|
2845
|
+
readonly finishReason: FinishReason;
|
2846
|
+
/**
|
2847
|
+
The token usage of the generated text.
|
2848
|
+
*/
|
2849
|
+
readonly usage: LanguageModelUsage;
|
2850
|
+
/**
|
2851
|
+
Warnings from the model provider (e.g. unsupported settings).
|
2852
|
+
*/
|
2853
|
+
readonly warnings: CallWarning[] | undefined;
|
2854
|
+
/**
|
2855
|
+
Additional request information.
|
2856
|
+
*/
|
2857
|
+
readonly request: LanguageModelRequestMetadata;
|
2858
|
+
/**
|
2859
|
+
Additional response information.
|
2860
|
+
*/
|
2861
|
+
readonly response: LanguageModelResponseMetadata & {
|
2862
|
+
/**
|
2863
|
+
The response messages that were generated during the call.
|
2864
|
+
Response messages can be either assistant messages or tool messages.
|
2865
|
+
They contain a generated id.
|
2866
|
+
*/
|
2867
|
+
readonly messages: Array<ResponseMessage>;
|
2868
|
+
/**
|
2869
|
+
Response body (available only for providers that use HTTP requests).
|
2870
|
+
*/
|
2871
|
+
body?: unknown;
|
3114
2872
|
};
|
3115
|
-
|
3116
|
-
|
3117
|
-
|
3118
|
-
|
3119
|
-
|
3120
|
-
|
3121
|
-
|
3122
|
-
|
3123
|
-
|
3124
|
-
|
3125
|
-
|
3126
|
-
|
3127
|
-
|
3128
|
-
|
3129
|
-
|
3130
|
-
|
3131
|
-
|
3132
|
-
|
3133
|
-
|
3134
|
-
|
3135
|
-
|
3136
|
-
|
3137
|
-
|
3138
|
-
|
3139
|
-
|
3140
|
-
|
3141
|
-
|
3142
|
-
|
3143
|
-
|
3144
|
-
|
3145
|
-
|
3146
|
-
|
3147
|
-
|
3148
|
-
cachedInputTokens?: number | undefined;
|
3149
|
-
} | undefined;
|
3150
|
-
}, {
|
3151
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3152
|
-
isContinued: boolean;
|
3153
|
-
usage?: {
|
3154
|
-
inputTokens?: number | undefined;
|
3155
|
-
outputTokens?: number | undefined;
|
3156
|
-
totalTokens?: number | undefined;
|
3157
|
-
reasoningTokens?: number | undefined;
|
3158
|
-
cachedInputTokens?: number | undefined;
|
3159
|
-
} | undefined;
|
3160
|
-
}>;
|
3161
|
-
}, "strip", z.ZodTypeAny, {
|
3162
|
-
value: {
|
3163
|
-
finishReason: "length" | "unknown" | "stop" | "content-filter" | "tool-calls" | "error" | "other";
|
3164
|
-
isContinued: boolean;
|
3165
|
-
usage?: {
|
3166
|
-
inputTokens?: number | undefined;
|
3167
|
-
outputTokens?: number | undefined;
|
3168
|
-
totalTokens?: number | undefined;
|
3169
|
-
reasoningTokens?: number | undefined;
|
3170
|
-
cachedInputTokens?: number | undefined;
|
3171
|
-
} | undefined;
|
2873
|
+
/**
|
2874
|
+
Additional provider-specific metadata. They are passed through
|
2875
|
+
from the provider to the AI SDK and enable provider-specific
|
2876
|
+
results that can be fully encapsulated in the provider.
|
2877
|
+
*/
|
2878
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
2879
|
+
/**
|
2880
|
+
The type of step that this result is for. The first step is always
|
2881
|
+
an "initial" step, and subsequent steps are either "continue" steps
|
2882
|
+
or "tool-result" steps.
|
2883
|
+
*/
|
2884
|
+
readonly stepType: 'initial' | 'continue' | 'tool-result';
|
2885
|
+
/**
|
2886
|
+
True when there will be a continuation step with a continuation text.
|
2887
|
+
*/
|
2888
|
+
readonly isContinued: boolean;
|
2889
|
+
};
|
2890
|
+
|
2891
|
+
/**
|
2892
|
+
* Appends the ResponseMessage[] from the response to a Message[] (for useChat).
|
2893
|
+
* The messages are converted to Messages before being appended.
|
2894
|
+
* Timestamps are generated for the new messages.
|
2895
|
+
*
|
2896
|
+
* @returns A new Message[] with the response messages appended.
|
2897
|
+
*/
|
2898
|
+
declare function appendResponseMessages({ messages, responseMessages, _internal: { currentDate }, }: {
|
2899
|
+
messages: UIMessage[];
|
2900
|
+
responseMessages: ResponseMessage[];
|
2901
|
+
/**
|
2902
|
+
Internal. For test use only. May change without notice.
|
2903
|
+
*/
|
2904
|
+
_internal?: {
|
2905
|
+
currentDate?: () => Date;
|
3172
2906
|
};
|
3173
|
-
|
3174
|
-
|
3175
|
-
|
3176
|
-
|
3177
|
-
|
3178
|
-
|
3179
|
-
|
3180
|
-
|
3181
|
-
|
3182
|
-
|
3183
|
-
|
3184
|
-
|
2907
|
+
}): UIMessage[];
|
2908
|
+
|
2909
|
+
type ChatRequestOptions = {
|
2910
|
+
/**
|
2911
|
+
Additional headers that should be to be passed to the API endpoint.
|
2912
|
+
*/
|
2913
|
+
headers?: Record<string, string> | Headers;
|
2914
|
+
/**
|
2915
|
+
Additional body JSON properties that should be sent to the API endpoint.
|
2916
|
+
*/
|
2917
|
+
body?: object;
|
2918
|
+
/**
|
2919
|
+
Additional data to be sent to the API endpoint.
|
2920
|
+
*/
|
2921
|
+
data?: JSONValue$1;
|
2922
|
+
/**
|
2923
|
+
* Allow submitting an empty message. Defaults to `false`.
|
2924
|
+
*/
|
2925
|
+
allowEmptySubmit?: boolean;
|
2926
|
+
};
|
2927
|
+
type UseChatOptions = {
|
2928
|
+
/**
|
2929
|
+
* The API endpoint that accepts a `{ messages: Message[] }` object and returns
|
2930
|
+
* a stream of tokens of the AI chat response. Defaults to `/api/chat`.
|
2931
|
+
*/
|
2932
|
+
api?: string;
|
2933
|
+
/**
|
2934
|
+
* A unique identifier for the chat. If not provided, a random one will be
|
2935
|
+
* generated. When provided, the `useChat` hook with the same `id` will
|
2936
|
+
* have shared states across components.
|
2937
|
+
*/
|
2938
|
+
id?: string;
|
2939
|
+
/**
|
2940
|
+
* Initial messages of the chat. Useful to load an existing chat history.
|
2941
|
+
*/
|
2942
|
+
initialMessages?: UIMessage[];
|
2943
|
+
/**
|
2944
|
+
* Initial input of the chat.
|
2945
|
+
*/
|
2946
|
+
initialInput?: string;
|
2947
|
+
/**
|
2948
|
+
Optional callback function that is invoked when a tool call is received.
|
2949
|
+
Intended for automatic client-side tool execution.
|
2950
|
+
|
2951
|
+
You can optionally return a result for the tool call,
|
2952
|
+
either synchronously or asynchronously.
|
2953
|
+
*/
|
2954
|
+
onToolCall?: ({ toolCall, }: {
|
2955
|
+
toolCall: ToolCall<string, unknown>;
|
2956
|
+
}) => void | Promise<unknown> | unknown;
|
2957
|
+
/**
|
2958
|
+
* Callback function to be called when the API response is received.
|
2959
|
+
*/
|
2960
|
+
onResponse?: (response: Response) => void | Promise<void>;
|
2961
|
+
/**
|
2962
|
+
* Optional callback function that is called when the assistant message is finished streaming.
|
2963
|
+
*
|
2964
|
+
* @param message The message that was streamed.
|
2965
|
+
* @param options.usage The token usage of the message.
|
2966
|
+
* @param options.finishReason The finish reason of the message.
|
2967
|
+
*/
|
2968
|
+
onFinish?: (message: UIMessage, options: {
|
2969
|
+
usage: LanguageModelUsage;
|
2970
|
+
finishReason: LanguageModelV2FinishReason;
|
2971
|
+
}) => void;
|
2972
|
+
/**
|
2973
|
+
* Callback function to be called when an error is encountered.
|
2974
|
+
*/
|
2975
|
+
onError?: (error: Error) => void;
|
2976
|
+
/**
|
2977
|
+
* A way to provide a function that is going to be used for ids for messages and the chat.
|
2978
|
+
* If not provided the default AI SDK `generateId` is used.
|
2979
|
+
*/
|
2980
|
+
generateId?: IdGenerator;
|
2981
|
+
/**
|
2982
|
+
* The credentials mode to be used for the fetch request.
|
2983
|
+
* Possible values are: 'omit', 'same-origin', 'include'.
|
2984
|
+
* Defaults to 'same-origin'.
|
2985
|
+
*/
|
2986
|
+
credentials?: RequestCredentials;
|
2987
|
+
/**
|
2988
|
+
* HTTP headers to be sent with the API request.
|
2989
|
+
*/
|
2990
|
+
headers?: Record<string, string> | Headers;
|
2991
|
+
/**
|
2992
|
+
* Extra body object to be sent with the API request.
|
2993
|
+
* @example
|
2994
|
+
* Send a `sessionId` to the API along with the messages.
|
2995
|
+
* ```js
|
2996
|
+
* useChat({
|
2997
|
+
* body: {
|
2998
|
+
* sessionId: '123',
|
2999
|
+
* }
|
3000
|
+
* })
|
3001
|
+
* ```
|
3002
|
+
*/
|
3003
|
+
body?: object;
|
3004
|
+
/**
|
3005
|
+
Streaming protocol that is used. Defaults to `data`.
|
3006
|
+
*/
|
3007
|
+
streamProtocol?: 'data' | 'text';
|
3008
|
+
/**
|
3009
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
3010
|
+
or to provide a custom fetch implementation for e.g. testing.
|
3011
|
+
*/
|
3012
|
+
fetch?: FetchFunction;
|
3013
|
+
/**
|
3014
|
+
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
3015
|
+
Must be at least 1.
|
3016
|
+
|
3017
|
+
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
3018
|
+
|
3019
|
+
By default, it's set to 1, which means that only a single LLM call is made.
|
3020
|
+
*/
|
3021
|
+
maxSteps?: number;
|
3022
|
+
};
|
3023
|
+
|
3024
|
+
declare const getOriginalFetch$1: () => typeof fetch;
|
3025
|
+
declare function callChatApi({ api, body, streamProtocol, credentials, headers, abortController, onResponse, onUpdate, onFinish, onToolCall, generateId, fetch, lastMessage, getCurrentDate, requestType, }: {
|
3026
|
+
api: string;
|
3027
|
+
body: Record<string, any>;
|
3028
|
+
streamProtocol: 'data' | 'text' | undefined;
|
3029
|
+
credentials: RequestCredentials | undefined;
|
3030
|
+
headers: HeadersInit | undefined;
|
3031
|
+
abortController: (() => AbortController | null) | undefined;
|
3032
|
+
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
3033
|
+
onUpdate: (options: {
|
3034
|
+
message: UIMessage;
|
3035
|
+
data: JSONValue$1[] | undefined;
|
3036
|
+
replaceLastMessage: boolean;
|
3037
|
+
}) => void;
|
3038
|
+
onFinish: UseChatOptions['onFinish'];
|
3039
|
+
onToolCall: UseChatOptions['onToolCall'];
|
3040
|
+
generateId: IdGenerator;
|
3041
|
+
fetch: ReturnType<typeof getOriginalFetch$1> | undefined;
|
3042
|
+
lastMessage: UIMessage | undefined;
|
3043
|
+
getCurrentDate: () => Date;
|
3044
|
+
requestType?: 'generate' | 'resume';
|
3045
|
+
}): Promise<void>;
|
3046
|
+
|
3047
|
+
declare const getOriginalFetch: () => typeof fetch;
|
3048
|
+
declare function callCompletionApi({ api, prompt, credentials, headers, body, streamProtocol, setCompletion, setLoading, setError, setAbortController, onResponse, onFinish, onError, onData, fetch, }: {
|
3049
|
+
api: string;
|
3050
|
+
prompt: string;
|
3051
|
+
credentials: RequestCredentials | undefined;
|
3052
|
+
headers: HeadersInit | undefined;
|
3053
|
+
body: Record<string, any>;
|
3054
|
+
streamProtocol: 'data' | 'text' | undefined;
|
3055
|
+
setCompletion: (completion: string) => void;
|
3056
|
+
setLoading: (loading: boolean) => void;
|
3057
|
+
setError: (error: Error | undefined) => void;
|
3058
|
+
setAbortController: (abortController: AbortController | null) => void;
|
3059
|
+
onResponse: ((response: Response) => void | Promise<void>) | undefined;
|
3060
|
+
onFinish: ((prompt: string, completion: string) => void) | undefined;
|
3061
|
+
onError: ((error: Error) => void) | undefined;
|
3062
|
+
onData: ((data: JSONValue$1[]) => void) | undefined;
|
3063
|
+
fetch: ReturnType<typeof getOriginalFetch> | undefined;
|
3064
|
+
}): Promise<string | null | undefined>;
|
3065
|
+
|
3066
|
+
declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
|
3067
|
+
|
3068
|
+
/**
|
3069
|
+
Converts an array of messages from useChat into an array of CoreMessages that can be used
|
3070
|
+
with the AI core functions (e.g. `streamText`).
|
3071
|
+
*/
|
3072
|
+
declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<UIMessage, 'id'>>, options?: {
|
3073
|
+
tools?: TOOLS;
|
3074
|
+
}): ModelMessage[];
|
3075
|
+
/**
|
3076
|
+
@deprecated Use `convertToModelMessages` instead.
|
3077
|
+
*/
|
3078
|
+
declare const convertToCoreMessages: typeof convertToModelMessages;
|
3079
|
+
|
3080
|
+
declare function extractMaxToolInvocationStep(toolInvocations: ToolInvocation[] | undefined): number | undefined;
|
3081
|
+
|
3082
|
+
declare function getToolInvocations(message: UIMessage): ToolInvocation[];
|
3083
|
+
|
3084
|
+
declare function processTextStream({ stream, onTextPart, }: {
|
3085
|
+
stream: ReadableStream<Uint8Array>;
|
3086
|
+
onTextPart: (chunk: string) => Promise<void> | void;
|
3087
|
+
}): Promise<void>;
|
3088
|
+
|
3089
|
+
declare function shouldResubmitMessages({ originalMaxToolInvocationStep, originalMessageCount, maxSteps, messages, }: {
|
3090
|
+
originalMaxToolInvocationStep: number | undefined;
|
3091
|
+
originalMessageCount: number;
|
3092
|
+
maxSteps: number;
|
3093
|
+
messages: UIMessage[];
|
3094
|
+
}): boolean;
|
3095
|
+
/**
|
3096
|
+
Check if the message is an assistant message with completed tool calls.
|
3097
|
+
The last step of the message must have at least one tool invocation and
|
3098
|
+
all tool invocations must have a result.
|
3099
|
+
*/
|
3100
|
+
declare function isAssistantMessageWithCompletedToolCalls(message: UIMessage): message is UIMessage & {
|
3101
|
+
role: 'assistant';
|
3102
|
+
};
|
3103
|
+
|
3104
|
+
/**
|
3105
|
+
* Updates the result of a specific tool invocation in the last message of the given messages array.
|
3106
|
+
*
|
3107
|
+
* @param {object} params - The parameters object.
|
3108
|
+
* @param {UIMessage[]} params.messages - An array of messages, from which the last one is updated.
|
3109
|
+
* @param {string} params.toolCallId - The unique identifier for the tool invocation to update.
|
3110
|
+
* @param {unknown} params.toolResult - The result object to attach to the tool invocation.
|
3111
|
+
* @returns {void} This function does not return anything.
|
3112
|
+
*/
|
3113
|
+
declare function updateToolCallResult({ messages, toolCallId, toolResult: result, }: {
|
3114
|
+
messages: UIMessage[];
|
3115
|
+
toolCallId: string;
|
3116
|
+
toolResult: unknown;
|
3117
|
+
}): void;
|
3118
|
+
|
3119
|
+
type CompletionRequestOptions = {
|
3120
|
+
/**
|
3121
|
+
An optional object of headers to be passed to the API endpoint.
|
3122
|
+
*/
|
3123
|
+
headers?: Record<string, string> | Headers;
|
3124
|
+
/**
|
3125
|
+
An optional object to be passed to the API endpoint.
|
3126
|
+
*/
|
3127
|
+
body?: object;
|
3128
|
+
};
|
3129
|
+
type UseCompletionOptions = {
|
3130
|
+
/**
|
3131
|
+
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
3132
|
+
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
3133
|
+
*/
|
3134
|
+
api?: string;
|
3135
|
+
/**
|
3136
|
+
* An unique identifier for the chat. If not provided, a random one will be
|
3137
|
+
* generated. When provided, the `useChat` hook with the same `id` will
|
3138
|
+
* have shared states across components.
|
3139
|
+
*/
|
3140
|
+
id?: string;
|
3141
|
+
/**
|
3142
|
+
* Initial prompt input of the completion.
|
3143
|
+
*/
|
3144
|
+
initialInput?: string;
|
3145
|
+
/**
|
3146
|
+
* Initial completion result. Useful to load an existing history.
|
3147
|
+
*/
|
3148
|
+
initialCompletion?: string;
|
3149
|
+
/**
|
3150
|
+
* Callback function to be called when the API response is received.
|
3151
|
+
*/
|
3152
|
+
onResponse?: (response: Response) => void | Promise<void>;
|
3153
|
+
/**
|
3154
|
+
* Callback function to be called when the completion is finished streaming.
|
3155
|
+
*/
|
3156
|
+
onFinish?: (prompt: string, completion: string) => void;
|
3157
|
+
/**
|
3158
|
+
* Callback function to be called when an error is encountered.
|
3159
|
+
*/
|
3160
|
+
onError?: (error: Error) => void;
|
3161
|
+
/**
|
3162
|
+
* The credentials mode to be used for the fetch request.
|
3163
|
+
* Possible values are: 'omit', 'same-origin', 'include'.
|
3164
|
+
* Defaults to 'same-origin'.
|
3165
|
+
*/
|
3166
|
+
credentials?: RequestCredentials;
|
3167
|
+
/**
|
3168
|
+
* HTTP headers to be sent with the API request.
|
3169
|
+
*/
|
3170
|
+
headers?: Record<string, string> | Headers;
|
3171
|
+
/**
|
3172
|
+
* Extra body object to be sent with the API request.
|
3173
|
+
* @example
|
3174
|
+
* Send a `sessionId` to the API along with the prompt.
|
3175
|
+
* ```js
|
3176
|
+
* useChat({
|
3177
|
+
* body: {
|
3178
|
+
* sessionId: '123',
|
3179
|
+
* }
|
3180
|
+
* })
|
3181
|
+
* ```
|
3182
|
+
*/
|
3183
|
+
body?: object;
|
3184
|
+
/**
|
3185
|
+
Streaming protocol that is used. Defaults to `data`.
|
3186
|
+
*/
|
3187
|
+
streamProtocol?: 'data' | 'text';
|
3188
|
+
/**
|
3189
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
3190
|
+
or to provide a custom fetch implementation for e.g. testing.
|
3191
|
+
*/
|
3192
|
+
fetch?: FetchFunction;
|
3193
|
+
};
|
3194
|
+
|
3195
|
+
/**
|
3196
|
+
* Converts a data URL of type text/* to a text string.
|
3197
|
+
*/
|
3198
|
+
declare function getTextFromDataUrl(dataUrl: string): string;
|
3199
|
+
|
3200
|
+
/**
|
3201
|
+
Create a type from an object with all keys and nested keys set to optional.
|
3202
|
+
The helper supports normal objects and Zod schemas (which are resolved automatically).
|
3203
|
+
It always recurses into arrays.
|
3204
|
+
|
3205
|
+
Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
|
3206
|
+
*/
|
3207
|
+
type DeepPartial<T> = T extends z.ZodTypeAny ? DeepPartialInternal<z.infer<T>> : DeepPartialInternal<T>;
|
3208
|
+
type DeepPartialInternal<T> = T extends null | undefined | string | number | boolean | symbol | bigint | void | Date | RegExp | ((...arguments_: any[]) => unknown) | (new (...arguments_: any[]) => unknown) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySet<ItemType> : T extends object ? T extends ReadonlyArray<infer ItemType> ? ItemType[] extends T ? readonly ItemType[] extends T ? ReadonlyArray<DeepPartialInternal<ItemType | undefined>> : Array<DeepPartialInternal<ItemType | undefined>> : PartialObject<T> : PartialObject<T> : unknown;
|
3209
|
+
type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
3210
|
+
type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
|
3211
|
+
type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
|
3212
|
+
type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartialInternal<T>>;
|
3213
|
+
type PartialObject<ObjectType extends object> = {
|
3214
|
+
[KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
|
3215
|
+
};
|
3216
|
+
|
3217
|
+
/**
|
3218
|
+
* Performs a deep-equal comparison of two parsed JSON objects.
|
3219
|
+
*
|
3220
|
+
* @param {any} obj1 - The first object to compare.
|
3221
|
+
* @param {any} obj2 - The second object to compare.
|
3222
|
+
* @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
|
3223
|
+
*/
|
3224
|
+
declare function isDeepEqualData(obj1: any, obj2: any): boolean;
|
3225
|
+
|
3226
|
+
declare function parsePartialJson(jsonText: string | undefined): Promise<{
|
3227
|
+
value: JSONValue$1 | undefined;
|
3228
|
+
state: 'undefined-input' | 'successful-parse' | 'repaired-parse' | 'failed-parse';
|
3229
|
+
}>;
|
3230
|
+
|
3231
|
+
/**
|
3232
|
+
* Calculates the cosine similarity between two vectors. This is a useful metric for
|
3233
|
+
* comparing the similarity of two vectors such as embeddings.
|
3234
|
+
*
|
3235
|
+
* @param vector1 - The first vector.
|
3236
|
+
* @param vector2 - The second vector.
|
3237
|
+
*
|
3238
|
+
* @returns The cosine similarity between vector1 and vector2.
|
3239
|
+
* @returns 0 if either vector is the zero vector.
|
3240
|
+
*
|
3241
|
+
* @throws {InvalidArgumentError} If the vectors do not have the same length.
|
3242
|
+
*/
|
3243
|
+
declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
|
3244
|
+
|
3245
|
+
/**
|
3246
|
+
* Creates a ReadableStream that emits the provided values with an optional delay between each value.
|
3247
|
+
*
|
3248
|
+
* @param options - The configuration options
|
3249
|
+
* @param options.chunks - Array of values to be emitted by the stream
|
3250
|
+
* @param options.initialDelayInMs - Optional initial delay in milliseconds before emitting the first value (default: 0). Can be set to `null` to skip the initial delay. The difference between `initialDelayInMs: null` and `initialDelayInMs: 0` is that `initialDelayInMs: null` will emit the values without any delay, while `initialDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
|
3251
|
+
* @param options.chunkDelayInMs - Optional delay in milliseconds between emitting each value (default: 0). Can be set to `null` to skip the delay. The difference between `chunkDelayInMs: null` and `chunkDelayInMs: 0` is that `chunkDelayInMs: null` will emit the values without any delay, while `chunkDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
|
3252
|
+
* @returns A ReadableStream that emits the provided values
|
3253
|
+
*/
|
3254
|
+
declare function simulateReadableStream<T>({ chunks, initialDelayInMs, chunkDelayInMs, _internal, }: {
|
3255
|
+
chunks: T[];
|
3256
|
+
initialDelayInMs?: number | null;
|
3257
|
+
chunkDelayInMs?: number | null;
|
3258
|
+
_internal?: {
|
3259
|
+
delay?: (ms: number | null) => Promise<void>;
|
3185
3260
|
};
|
3186
|
-
|
3187
|
-
|
3188
|
-
|
3189
|
-
|
3190
|
-
|
3191
|
-
|
3192
|
-
|
3193
|
-
|
3194
|
-
|
3195
|
-
|
3196
|
-
|
3197
|
-
|
3198
|
-
|
3261
|
+
}): ReadableStream<T>;
|
3262
|
+
|
3263
|
+
/**
|
3264
|
+
The result of an `embed` call.
|
3265
|
+
It contains the embedding, the value, and additional information.
|
3266
|
+
*/
|
3267
|
+
interface EmbedResult<VALUE> {
|
3268
|
+
/**
|
3269
|
+
The value that was embedded.
|
3270
|
+
*/
|
3271
|
+
readonly value: VALUE;
|
3272
|
+
/**
|
3273
|
+
The embedding of the value.
|
3274
|
+
*/
|
3275
|
+
readonly embedding: Embedding;
|
3276
|
+
/**
|
3277
|
+
The embedding token usage.
|
3278
|
+
*/
|
3279
|
+
readonly usage: EmbeddingModelUsage;
|
3280
|
+
/**
|
3281
|
+
Optional response data.
|
3282
|
+
*/
|
3283
|
+
readonly response?: {
|
3284
|
+
/**
|
3285
|
+
Response headers.
|
3286
|
+
*/
|
3287
|
+
headers?: Record<string, string>;
|
3288
|
+
/**
|
3289
|
+
The response body.
|
3290
|
+
*/
|
3291
|
+
body?: unknown;
|
3199
3292
|
};
|
3200
|
-
|
3201
|
-
|
3202
|
-
|
3203
|
-
|
3293
|
+
}
|
3294
|
+
|
3295
|
+
/**
|
3296
|
+
Embed a value using an embedding model. The type of the value is defined by the embedding model.
|
3297
|
+
|
3298
|
+
@param model - The embedding model to use.
|
3299
|
+
@param value - The value that should be embedded.
|
3300
|
+
|
3301
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
3302
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
3303
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
3304
|
+
|
3305
|
+
@returns A result object that contains the embedding, the value, and additional information.
|
3306
|
+
*/
|
3307
|
+
declare function embed<VALUE>({ model, value, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
|
3308
|
+
/**
|
3309
|
+
The embedding model to use.
|
3310
|
+
*/
|
3311
|
+
model: EmbeddingModel<VALUE>;
|
3312
|
+
/**
|
3313
|
+
The value that should be embedded.
|
3314
|
+
*/
|
3315
|
+
value: VALUE;
|
3316
|
+
/**
|
3317
|
+
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
3318
|
+
|
3319
|
+
@default 2
|
3320
|
+
*/
|
3321
|
+
maxRetries?: number;
|
3322
|
+
/**
|
3323
|
+
Abort signal.
|
3324
|
+
*/
|
3325
|
+
abortSignal?: AbortSignal;
|
3326
|
+
/**
|
3327
|
+
Additional headers to include in the request.
|
3328
|
+
Only applicable for HTTP-based providers.
|
3329
|
+
*/
|
3330
|
+
headers?: Record<string, string>;
|
3331
|
+
/**
|
3332
|
+
Additional provider-specific options. They are passed through
|
3333
|
+
to the provider from the AI SDK and enable provider-specific
|
3334
|
+
functionality that can be fully encapsulated in the provider.
|
3335
|
+
*/
|
3336
|
+
providerOptions?: ProviderOptions;
|
3337
|
+
/**
|
3338
|
+
* Optional telemetry configuration (experimental).
|
3339
|
+
*/
|
3340
|
+
experimental_telemetry?: TelemetrySettings;
|
3341
|
+
}): Promise<EmbedResult<VALUE>>;
|
3342
|
+
|
3343
|
+
/**
|
3344
|
+
The result of a `embedMany` call.
|
3345
|
+
It contains the embeddings, the values, and additional information.
|
3346
|
+
*/
|
3347
|
+
interface EmbedManyResult<VALUE> {
|
3348
|
+
/**
|
3349
|
+
The values that were embedded.
|
3350
|
+
*/
|
3351
|
+
readonly values: Array<VALUE>;
|
3352
|
+
/**
|
3353
|
+
The embeddings. They are in the same order as the values.
|
3354
|
+
*/
|
3355
|
+
readonly embeddings: Array<Embedding>;
|
3356
|
+
/**
|
3357
|
+
The embedding token usage.
|
3358
|
+
*/
|
3359
|
+
readonly usage: EmbeddingModelUsage;
|
3360
|
+
/**
|
3361
|
+
Optional raw response data.
|
3362
|
+
*/
|
3363
|
+
readonly responses?: Array<{
|
3364
|
+
/**
|
3365
|
+
Response headers.
|
3366
|
+
*/
|
3367
|
+
headers?: Record<string, string>;
|
3368
|
+
/**
|
3369
|
+
The response body.
|
3370
|
+
*/
|
3371
|
+
body?: unknown;
|
3372
|
+
} | undefined>;
|
3373
|
+
}
|
3374
|
+
|
3375
|
+
/**
|
3376
|
+
Embed several values using an embedding model. The type of the value is defined
|
3377
|
+
by the embedding model.
|
3378
|
+
|
3379
|
+
`embedMany` automatically splits large requests into smaller chunks if the model
|
3380
|
+
has a limit on how many embeddings can be generated in a single call.
|
3381
|
+
|
3382
|
+
@param model - The embedding model to use.
|
3383
|
+
@param values - The values that should be embedded.
|
3384
|
+
|
3385
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
3386
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
3387
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
3388
|
+
|
3389
|
+
@returns A result object that contains the embeddings, the value, and additional information.
|
3390
|
+
*/
|
3391
|
+
declare function embedMany<VALUE>({ model, values, maxParallelCalls, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
|
3392
|
+
/**
|
3393
|
+
The embedding model to use.
|
3394
|
+
*/
|
3395
|
+
model: EmbeddingModel<VALUE>;
|
3396
|
+
/**
|
3397
|
+
The values that should be embedded.
|
3398
|
+
*/
|
3399
|
+
values: Array<VALUE>;
|
3400
|
+
/**
|
3401
|
+
Maximum number of retries per embedding model call. Set to 0 to disable retries.
|
3402
|
+
|
3403
|
+
@default 2
|
3404
|
+
*/
|
3405
|
+
maxRetries?: number;
|
3406
|
+
/**
|
3407
|
+
Abort signal.
|
3408
|
+
*/
|
3409
|
+
abortSignal?: AbortSignal;
|
3410
|
+
/**
|
3411
|
+
Additional headers to include in the request.
|
3412
|
+
Only applicable for HTTP-based providers.
|
3413
|
+
*/
|
3414
|
+
headers?: Record<string, string>;
|
3415
|
+
/**
|
3416
|
+
* Optional telemetry configuration (experimental).
|
3417
|
+
*/
|
3418
|
+
experimental_telemetry?: TelemetrySettings;
|
3419
|
+
/**
|
3420
|
+
Additional provider-specific options. They are passed through
|
3421
|
+
to the provider from the AI SDK and enable provider-specific
|
3422
|
+
functionality that can be fully encapsulated in the provider.
|
3423
|
+
*/
|
3424
|
+
providerOptions?: ProviderOptions;
|
3425
|
+
/**
|
3426
|
+
* Maximum number of concurrent requests.
|
3427
|
+
*
|
3428
|
+
* @default Infinity
|
3429
|
+
*/
|
3430
|
+
maxParallelCalls?: number;
|
3431
|
+
}): Promise<EmbedManyResult<VALUE>>;
|
3432
|
+
|
3433
|
+
/**
|
3434
|
+
The result of a `generateText` call.
|
3435
|
+
It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
|
3436
|
+
*/
|
3437
|
+
interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
|
3438
|
+
/**
|
3439
|
+
The content that was generated in the last step.
|
3440
|
+
*/
|
3441
|
+
readonly content: Array<ContentPart<TOOLS>>;
|
3442
|
+
/**
|
3443
|
+
The generated text. If you are using continue steps, this can include text from all steps.
|
3444
|
+
*/
|
3445
|
+
readonly text: string;
|
3446
|
+
/**
|
3447
|
+
The full reasoning that the model has generated.
|
3448
|
+
*/
|
3449
|
+
readonly reasoning: Array<ReasoningPart>;
|
3450
|
+
/**
|
3451
|
+
The reasoning text that the model has generated. Can be undefined if the model
|
3452
|
+
has only generated text.
|
3453
|
+
*/
|
3454
|
+
readonly reasoningText: string | undefined;
|
3455
|
+
/**
|
3456
|
+
The files that were generated in the last step.
|
3457
|
+
Empty array if no files were generated.
|
3458
|
+
*/
|
3459
|
+
readonly files: Array<GeneratedFile>;
|
3460
|
+
/**
|
3461
|
+
Sources that have been used as input to generate the response.
|
3462
|
+
For multi-step generation, the sources are accumulated from all steps.
|
3463
|
+
*/
|
3464
|
+
readonly sources: Array<Source>;
|
3465
|
+
/**
|
3466
|
+
The tool calls that were made during the generation.
|
3467
|
+
*/
|
3468
|
+
readonly toolCalls: ToolCallArray<TOOLS>;
|
3469
|
+
/**
|
3470
|
+
The results of the tool calls.
|
3471
|
+
*/
|
3472
|
+
readonly toolResults: ToolResultArray<TOOLS>;
|
3473
|
+
/**
|
3474
|
+
The reason why the generation finished.
|
3475
|
+
*/
|
3476
|
+
readonly finishReason: FinishReason;
|
3477
|
+
/**
|
3478
|
+
The token usage of the generated text.
|
3479
|
+
*/
|
3480
|
+
readonly usage: LanguageModelUsage;
|
3481
|
+
/**
|
3482
|
+
Warnings from the model provider (e.g. unsupported settings)
|
3483
|
+
*/
|
3484
|
+
readonly warnings: CallWarning[] | undefined;
|
3485
|
+
/**
|
3486
|
+
Additional request information.
|
3487
|
+
*/
|
3488
|
+
readonly request: LanguageModelRequestMetadata;
|
3489
|
+
/**
|
3490
|
+
Additional response information.
|
3491
|
+
*/
|
3492
|
+
readonly response: LanguageModelResponseMetadata & {
|
3493
|
+
/**
|
3494
|
+
The response messages that were generated during the call. It consists of an assistant message,
|
3495
|
+
potentially containing tool calls.
|
3496
|
+
|
3497
|
+
When there are tool results, there is an additional tool message with the tool results that are available.
|
3498
|
+
If there are tools that do not have execute functions, they are not included in the tool results and
|
3499
|
+
need to be added separately.
|
3500
|
+
*/
|
3501
|
+
messages: Array<ResponseMessage>;
|
3502
|
+
/**
|
3503
|
+
Response body (available only for providers that use HTTP requests).
|
3504
|
+
*/
|
3505
|
+
body?: unknown;
|
3204
3506
|
};
|
3205
|
-
|
3206
|
-
|
3207
|
-
|
3208
|
-
|
3209
|
-
|
3210
|
-
|
3211
|
-
|
3212
|
-
|
3213
|
-
|
3214
|
-
|
3215
|
-
|
3216
|
-
|
3217
|
-
|
3218
|
-
|
3219
|
-
|
3507
|
+
/**
|
3508
|
+
Additional provider-specific metadata. They are passed through
|
3509
|
+
from the provider to the AI SDK and enable provider-specific
|
3510
|
+
results that can be fully encapsulated in the provider.
|
3511
|
+
*/
|
3512
|
+
readonly providerMetadata: ProviderMetadata | undefined;
|
3513
|
+
/**
|
3514
|
+
Details for all steps.
|
3515
|
+
You can use this to get information about intermediate steps,
|
3516
|
+
such as the tool calls or the response headers.
|
3517
|
+
*/
|
3518
|
+
readonly steps: Array<StepResult<TOOLS>>;
|
3519
|
+
/**
|
3520
|
+
The generated structured output. It uses the `experimental_output` specification.
|
3521
|
+
*/
|
3522
|
+
readonly experimental_output: OUTPUT;
|
3523
|
+
}
|
3524
|
+
|
3525
|
+
interface Output$1<OUTPUT, PARTIAL> {
|
3526
|
+
readonly type: 'object' | 'text';
|
3527
|
+
responseFormat: LanguageModelV2CallOptions['responseFormat'];
|
3528
|
+
parsePartial(options: {
|
3220
3529
|
text: string;
|
3221
|
-
|
3222
|
-
|
3223
|
-
|
3224
|
-
|
3225
|
-
value: {
|
3530
|
+
}): Promise<{
|
3531
|
+
partial: PARTIAL;
|
3532
|
+
} | undefined>;
|
3533
|
+
parseOutput(options: {
|
3226
3534
|
text: string;
|
3227
|
-
|
3228
|
-
|
3229
|
-
|
3230
|
-
|
3231
|
-
|
3232
|
-
|
3233
|
-
|
3234
|
-
|
3235
|
-
|
3236
|
-
|
3237
|
-
|
3238
|
-
|
3239
|
-
|
3240
|
-
|
3241
|
-
|
3242
|
-
|
3243
|
-
|
3244
|
-
|
3245
|
-
|
3246
|
-
|
3247
|
-
|
3248
|
-
|
3249
|
-
|
3250
|
-
|
3251
|
-
|
3252
|
-
|
3253
|
-
|
3254
|
-
|
3255
|
-
|
3256
|
-
|
3257
|
-
|
3258
|
-
|
3259
|
-
|
3260
|
-
|
3261
|
-
|
3262
|
-
|
3263
|
-
|
3264
|
-
|
3265
|
-
|
3266
|
-
|
3267
|
-
|
3268
|
-
|
3269
|
-
|
3270
|
-
|
3271
|
-
|
3272
|
-
|
3273
|
-
|
3274
|
-
|
3275
|
-
|
3276
|
-
|
3277
|
-
|
3278
|
-
|
3279
|
-
|
3280
|
-
|
3281
|
-
|
3282
|
-
|
3283
|
-
|
3284
|
-
|
3285
|
-
|
3286
|
-
|
3287
|
-
|
3288
|
-
|
3289
|
-
|
3290
|
-
|
3291
|
-
|
3292
|
-
|
3293
|
-
|
3294
|
-
|
3295
|
-
|
3535
|
+
}, context: {
|
3536
|
+
response: LanguageModelResponseMetadata;
|
3537
|
+
usage: LanguageModelUsage;
|
3538
|
+
finishReason: FinishReason;
|
3539
|
+
}): Promise<OUTPUT>;
|
3540
|
+
}
|
3541
|
+
declare const text: () => Output$1<string, string>;
|
3542
|
+
declare const object: <OUTPUT>({ schema: inputSchema, }: {
|
3543
|
+
schema: z.Schema<OUTPUT, z.ZodTypeDef, any> | Schema<OUTPUT>;
|
3544
|
+
}) => Output$1<OUTPUT, DeepPartial<OUTPUT>>;
|
3545
|
+
|
3546
|
+
declare const output_object: typeof object;
|
3547
|
+
declare const output_text: typeof text;
|
3548
|
+
declare namespace output {
|
3549
|
+
export {
|
3550
|
+
Output$1 as Output,
|
3551
|
+
output_object as object,
|
3552
|
+
output_text as text,
|
3553
|
+
};
|
3554
|
+
}
|
3555
|
+
|
3556
|
+
/**
|
3557
|
+
Callback that is set using the `onStepFinish` option.
|
3558
|
+
|
3559
|
+
@param stepResult - The result of the step.
|
3560
|
+
*/
|
3561
|
+
type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
|
3562
|
+
/**
|
3563
|
+
Generate a text and call tools for a given prompt using a language model.
|
3564
|
+
|
3565
|
+
This function does not stream the output. If you want to stream the output, use `streamText` instead.
|
3566
|
+
|
3567
|
+
@param model - The language model to use.
|
3568
|
+
|
3569
|
+
@param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
3570
|
+
@param toolChoice - The tool choice strategy. Default: 'auto'.
|
3571
|
+
|
3572
|
+
@param system - A system message that will be part of the prompt.
|
3573
|
+
@param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
3574
|
+
@param messages - A list of messages. You can either use `prompt` or `messages` but not both.
|
3575
|
+
|
3576
|
+
@param maxOutputTokens - Maximum number of tokens to generate.
|
3577
|
+
@param temperature - Temperature setting.
|
3578
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
3579
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
3580
|
+
@param topP - Nucleus sampling.
|
3581
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
3582
|
+
It is recommended to set either `temperature` or `topP`, but not both.
|
3583
|
+
@param topK - Only sample from the top K options for each subsequent token.
|
3584
|
+
Used to remove "long tail" low probability responses.
|
3585
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
3586
|
+
@param presencePenalty - Presence penalty setting.
|
3587
|
+
It affects the likelihood of the model to repeat information that is already in the prompt.
|
3588
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
3589
|
+
@param frequencyPenalty - Frequency penalty setting.
|
3590
|
+
It affects the likelihood of the model to repeatedly use the same words or phrases.
|
3591
|
+
The value is passed through to the provider. The range depends on the provider and model.
|
3592
|
+
@param stopSequences - Stop sequences.
|
3593
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
3594
|
+
@param seed - The seed (integer) to use for random sampling.
|
3595
|
+
If set and supported by the model, calls will generate deterministic results.
|
3596
|
+
|
3597
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
3598
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
3599
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
3600
|
+
|
3601
|
+
@param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
3602
|
+
@param experimental_generateMessageId - Generate a unique ID for each message.
|
3603
|
+
|
3604
|
+
@param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
3605
|
+
|
3606
|
+
@returns
|
3607
|
+
A result object that contains the generated text, the results of the tool calls, and additional information.
|
3608
|
+
*/
|
3609
|
+
declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, maxSteps, experimental_generateMessageId: generateMessageId, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, providerOptions, experimental_activeTools: activeTools, experimental_prepareStep: prepareStep, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
|
3610
|
+
/**
|
3611
|
+
The language model to use.
|
3612
|
+
*/
|
3613
|
+
model: LanguageModel;
|
3614
|
+
/**
|
3615
|
+
The tools that the model can call. The model needs to support calling tools.
|
3616
|
+
*/
|
3617
|
+
tools?: TOOLS;
|
3618
|
+
/**
|
3619
|
+
The tool choice strategy. Default: 'auto'.
|
3620
|
+
*/
|
3621
|
+
toolChoice?: ToolChoice<TOOLS>;
|
3622
|
+
/**
|
3623
|
+
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
|
3624
|
+
|
3625
|
+
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
3626
|
+
|
3627
|
+
By default, it's set to 1, which means that only a single LLM call is made.
|
3628
|
+
*/
|
3629
|
+
maxSteps?: number;
|
3630
|
+
/**
|
3631
|
+
Generate a unique ID for each message.
|
3632
|
+
*/
|
3633
|
+
experimental_generateMessageId?: IdGenerator;
|
3634
|
+
/**
|
3635
|
+
When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
|
3636
|
+
|
3637
|
+
By default, it's set to false.
|
3638
|
+
*/
|
3639
|
+
experimental_continueSteps?: boolean;
|
3640
|
+
/**
|
3641
|
+
Optional telemetry configuration (experimental).
|
3642
|
+
*/
|
3643
|
+
experimental_telemetry?: TelemetrySettings;
|
3644
|
+
/**
|
3645
|
+
Additional provider-specific options. They are passed through
|
3646
|
+
to the provider from the AI SDK and enable provider-specific
|
3647
|
+
functionality that can be fully encapsulated in the provider.
|
3648
|
+
*/
|
3649
|
+
providerOptions?: ProviderOptions;
|
3650
|
+
/**
|
3651
|
+
Limits the tools that are available for the model to call without
|
3652
|
+
changing the tool call and result types in the result.
|
3653
|
+
*/
|
3654
|
+
experimental_activeTools?: Array<keyof TOOLS>;
|
3655
|
+
/**
|
3656
|
+
Optional specification for parsing structured outputs from the LLM response.
|
3657
|
+
*/
|
3658
|
+
experimental_output?: Output$1<OUTPUT, OUTPUT_PARTIAL>;
|
3659
|
+
/**
|
3660
|
+
Optional function that you can use to provide different settings for a step.
|
3661
|
+
|
3662
|
+
@param options - The options for the step.
|
3663
|
+
@param options.steps - The steps that have been executed so far.
|
3664
|
+
@param options.stepNumber - The number of the step that is being executed.
|
3665
|
+
@param options.maxSteps - The maximum number of steps.
|
3666
|
+
@param options.model - The model that is being used.
|
3667
|
+
|
3668
|
+
@returns An object that contains the settings for the step.
|
3669
|
+
If you return undefined (or for undefined settings), the settings from the outer level will be used.
|
3670
|
+
*/
|
3671
|
+
experimental_prepareStep?: (options: {
|
3672
|
+
steps: Array<StepResult<TOOLS>>;
|
3673
|
+
stepNumber: number;
|
3674
|
+
maxSteps: number;
|
3675
|
+
model: LanguageModel;
|
3676
|
+
}) => PromiseLike<{
|
3677
|
+
model?: LanguageModel;
|
3678
|
+
toolChoice?: ToolChoice<TOOLS>;
|
3679
|
+
experimental_activeTools?: Array<keyof TOOLS>;
|
3680
|
+
} | undefined>;
|
3681
|
+
/**
|
3682
|
+
A function that attempts to repair a tool call that failed to parse.
|
3683
|
+
*/
|
3684
|
+
experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
|
3685
|
+
/**
|
3686
|
+
Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
3687
|
+
*/
|
3688
|
+
onStepFinish?: GenerateTextOnStepFinishCallback<TOOLS>;
|
3689
|
+
/**
|
3690
|
+
* Internal. For test use only. May change without notice.
|
3691
|
+
*/
|
3692
|
+
_internal?: {
|
3693
|
+
generateId?: IdGenerator;
|
3694
|
+
currentDate?: () => Date;
|
3296
3695
|
};
|
3297
|
-
|
3298
|
-
}>, z.ZodObject<{
|
3299
|
-
type: z.ZodLiteral<"reasoning-part-finish">;
|
3300
|
-
value: z.ZodNull;
|
3301
|
-
}, "strip", z.ZodTypeAny, {
|
3302
|
-
value: null;
|
3303
|
-
type: "reasoning-part-finish";
|
3304
|
-
}, {
|
3305
|
-
value: null;
|
3306
|
-
type: "reasoning-part-finish";
|
3307
|
-
}>]>;
|
3308
|
-
type DataStreamPart = z.infer<typeof dataStreamPartSchema>;
|
3696
|
+
}): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
3309
3697
|
|
3310
3698
|
type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
|
3311
3699
|
|
@@ -3359,23 +3747,29 @@ A result object for accessing different stream types and additional information.
|
|
3359
3747
|
*/
|
3360
3748
|
interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
3361
3749
|
/**
|
3362
|
-
|
3363
|
-
|
3364
|
-
|
3750
|
+
The content that was generated in the last step.
|
3751
|
+
|
3752
|
+
Resolved when the response is finished.
|
3753
|
+
*/
|
3754
|
+
readonly content: Promise<Array<ContentPart<TOOLS>>>;
|
3365
3755
|
/**
|
3366
|
-
The
|
3367
|
-
When there are multiple steps, the usage is the sum of all step usages.
|
3756
|
+
The full text that has been generated by the last step.
|
3368
3757
|
|
3369
3758
|
Resolved when the response is finished.
|
3370
3759
|
*/
|
3371
|
-
readonly
|
3760
|
+
readonly text: Promise<string>;
|
3372
3761
|
/**
|
3373
|
-
|
3374
|
-
For multi-step generation, the sources are accumulated from all steps.
|
3762
|
+
The full reasoning that the model has generated.
|
3375
3763
|
|
3376
3764
|
Resolved when the response is finished.
|
3377
3765
|
*/
|
3378
|
-
readonly
|
3766
|
+
readonly reasoning: Promise<Array<ReasoningPart>>;
|
3767
|
+
/**
|
3768
|
+
The reasoning that has been generated by the last step.
|
3769
|
+
|
3770
|
+
Resolved when the response is finished.
|
3771
|
+
*/
|
3772
|
+
readonly reasoningText: Promise<string | undefined>;
|
3379
3773
|
/**
|
3380
3774
|
Files that have been generated by the model in the last step.
|
3381
3775
|
|
@@ -3383,47 +3777,41 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3383
3777
|
*/
|
3384
3778
|
readonly files: Promise<GeneratedFile[]>;
|
3385
3779
|
/**
|
3386
|
-
|
3780
|
+
Sources that have been used as input to generate the response.
|
3781
|
+
For multi-step generation, the sources are accumulated from all steps.
|
3387
3782
|
|
3388
3783
|
Resolved when the response is finished.
|
3389
|
-
*/
|
3390
|
-
readonly finishReason: Promise<FinishReason>;
|
3391
|
-
/**
|
3392
|
-
Additional provider-specific metadata from the last step.
|
3393
|
-
Metadata is passed through from the provider to the AI SDK and
|
3394
|
-
enables provider-specific results that can be fully encapsulated in the provider.
|
3395
3784
|
*/
|
3396
|
-
readonly
|
3785
|
+
readonly sources: Promise<Source[]>;
|
3397
3786
|
/**
|
3398
|
-
The
|
3787
|
+
The tool calls that have been executed in the last step.
|
3399
3788
|
|
3400
3789
|
Resolved when the response is finished.
|
3401
3790
|
*/
|
3402
|
-
readonly
|
3791
|
+
readonly toolCalls: Promise<ToolCallUnion<TOOLS>[]>;
|
3403
3792
|
/**
|
3404
|
-
The
|
3793
|
+
The tool results that have been generated in the last step.
|
3405
3794
|
|
3406
|
-
Resolved when the
|
3795
|
+
Resolved when the all tool executions are finished.
|
3407
3796
|
*/
|
3408
|
-
readonly
|
3797
|
+
readonly toolResults: Promise<ToolResultUnion<TOOLS>[]>;
|
3409
3798
|
/**
|
3410
|
-
The
|
3799
|
+
The reason why the generation finished. Taken from the last step.
|
3411
3800
|
|
3412
3801
|
Resolved when the response is finished.
|
3413
3802
|
*/
|
3414
|
-
readonly
|
3803
|
+
readonly finishReason: Promise<FinishReason>;
|
3415
3804
|
/**
|
3416
|
-
The
|
3805
|
+
The total token usage of the generated response.
|
3806
|
+
When there are multiple steps, the usage is the sum of all step usages.
|
3417
3807
|
|
3418
3808
|
Resolved when the response is finished.
|
3419
3809
|
*/
|
3420
|
-
readonly
|
3810
|
+
readonly usage: Promise<LanguageModelUsage>;
|
3421
3811
|
/**
|
3422
|
-
|
3423
|
-
|
3424
|
-
Resolved when the all tool executions are finished.
|
3812
|
+
Warnings from the model provider (e.g. unsupported settings) for the first step.
|
3425
3813
|
*/
|
3426
|
-
readonly
|
3814
|
+
readonly warnings: Promise<CallWarning[] | undefined>;
|
3427
3815
|
/**
|
3428
3816
|
Details for all steps.
|
3429
3817
|
You can use this to get information about intermediate steps,
|
@@ -3449,6 +3837,12 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3449
3837
|
messages: Array<ResponseMessage>;
|
3450
3838
|
}>;
|
3451
3839
|
/**
|
3840
|
+
Additional provider-specific metadata from the last step.
|
3841
|
+
Metadata is passed through from the provider to the AI SDK and
|
3842
|
+
enables provider-specific results that can be fully encapsulated in the provider.
|
3843
|
+
*/
|
3844
|
+
readonly providerMetadata: Promise<ProviderMetadata | undefined>;
|
3845
|
+
/**
|
3452
3846
|
A text stream that returns only the generated text deltas. You can use it
|
3453
3847
|
as either an AsyncIterable or a ReadableStream. When an error occurs, the
|
3454
3848
|
stream will throw the error.
|
@@ -3527,23 +3921,9 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
|
|
3527
3921
|
*/
|
3528
3922
|
toTextStreamResponse(init?: ResponseInit): Response;
|
3529
3923
|
}
|
3530
|
-
type TextStreamPart<TOOLS extends ToolSet> = {
|
3531
|
-
type: 'text';
|
3532
|
-
text: string;
|
3533
|
-
} | {
|
3534
|
-
type: 'reasoning';
|
3535
|
-
text: string;
|
3536
|
-
providerMetadata?: ProviderMetadata;
|
3537
|
-
} | {
|
3924
|
+
type TextStreamPart<TOOLS extends ToolSet> = ContentPart<TOOLS> | {
|
3538
3925
|
type: 'reasoning-part-finish';
|
3539
|
-
} |
|
3540
|
-
type: 'source';
|
3541
|
-
} & Source) | {
|
3542
|
-
type: 'file';
|
3543
|
-
file: GeneratedFile;
|
3544
|
-
} | ({
|
3545
|
-
type: 'tool-call';
|
3546
|
-
} & ToolCallUnion<TOOLS>) | {
|
3926
|
+
} | {
|
3547
3927
|
type: 'tool-call-streaming-start';
|
3548
3928
|
toolCallId: string;
|
3549
3929
|
toolName: string;
|
@@ -3552,9 +3932,7 @@ type TextStreamPart<TOOLS extends ToolSet> = {
|
|
3552
3932
|
toolCallId: string;
|
3553
3933
|
toolName: string;
|
3554
3934
|
argsTextDelta: string;
|
3555
|
-
} |
|
3556
|
-
type: 'tool-result';
|
3557
|
-
} & ToolResultUnion<TOOLS>) | {
|
3935
|
+
} | {
|
3558
3936
|
type: 'step-start';
|
3559
3937
|
messageId: string;
|
3560
3938
|
request: LanguageModelRequestMetadata;
|
@@ -4316,116 +4694,13 @@ declare function generateSpeech({ model, text, voice, outputFormat, instructions
|
|
4316
4694
|
*/
|
4317
4695
|
outputFormat?: 'mp3' | 'wav' | (string & {});
|
4318
4696
|
/**
|
4319
|
-
Instructions for the speech generation e.g. "Speak in a slow and steady tone".
|
4320
|
-
*/
|
4321
|
-
instructions?: string;
|
4322
|
-
/**
|
4323
|
-
The speed of the speech generation.
|
4324
|
-
*/
|
4325
|
-
speed?: number;
|
4326
|
-
/**
|
4327
|
-
Additional provider-specific options that are passed through to the provider
|
4328
|
-
as body parameters.
|
4329
|
-
|
4330
|
-
The outer record is keyed by the provider name, and the inner
|
4331
|
-
record is keyed by the provider-specific metadata key.
|
4332
|
-
```ts
|
4333
|
-
{
|
4334
|
-
"openai": {}
|
4335
|
-
}
|
4336
|
-
```
|
4337
|
-
*/
|
4338
|
-
providerOptions?: ProviderOptions;
|
4339
|
-
/**
|
4340
|
-
Maximum number of retries per speech model call. Set to 0 to disable retries.
|
4341
|
-
|
4342
|
-
@default 2
|
4343
|
-
*/
|
4344
|
-
maxRetries?: number;
|
4345
|
-
/**
|
4346
|
-
Abort signal.
|
4347
|
-
*/
|
4348
|
-
abortSignal?: AbortSignal;
|
4349
|
-
/**
|
4350
|
-
Additional headers to include in the request.
|
4351
|
-
Only applicable for HTTP-based providers.
|
4352
|
-
*/
|
4353
|
-
headers?: Record<string, string>;
|
4354
|
-
}): Promise<SpeechResult>;
|
4355
|
-
|
4356
|
-
/**
|
4357
|
-
The result of a `transcribe` call.
|
4358
|
-
It contains the transcript and additional information.
|
4359
|
-
*/
|
4360
|
-
interface TranscriptionResult {
|
4361
|
-
/**
|
4362
|
-
* The complete transcribed text from the audio.
|
4363
|
-
*/
|
4364
|
-
readonly text: string;
|
4365
|
-
/**
|
4366
|
-
* Array of transcript segments with timing information.
|
4367
|
-
* Each segment represents a portion of the transcribed text with start and end times.
|
4368
|
-
*/
|
4369
|
-
readonly segments: Array<{
|
4370
|
-
/**
|
4371
|
-
* The text content of this segment.
|
4372
|
-
*/
|
4373
|
-
readonly text: string;
|
4374
|
-
/**
|
4375
|
-
* The start time of this segment in seconds.
|
4376
|
-
*/
|
4377
|
-
readonly startSecond: number;
|
4378
|
-
/**
|
4379
|
-
* The end time of this segment in seconds.
|
4380
|
-
*/
|
4381
|
-
readonly endSecond: number;
|
4382
|
-
}>;
|
4383
|
-
/**
|
4384
|
-
* The detected language of the audio content, as an ISO-639-1 code (e.g., 'en' for English).
|
4385
|
-
* May be undefined if the language couldn't be detected.
|
4386
|
-
*/
|
4387
|
-
readonly language: string | undefined;
|
4388
|
-
/**
|
4389
|
-
* The total duration of the audio file in seconds.
|
4390
|
-
* May be undefined if the duration couldn't be determined.
|
4391
|
-
*/
|
4392
|
-
readonly durationInSeconds: number | undefined;
|
4393
|
-
/**
|
4394
|
-
Warnings for the call, e.g. unsupported settings.
|
4395
|
-
*/
|
4396
|
-
readonly warnings: Array<TranscriptionWarning>;
|
4397
|
-
/**
|
4398
|
-
Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
4399
|
-
*/
|
4400
|
-
readonly responses: Array<TranscriptionModelResponseMetadata>;
|
4401
|
-
/**
|
4402
|
-
Provider metadata from the provider.
|
4403
|
-
*/
|
4404
|
-
readonly providerMetadata: Record<string, Record<string, JSONValue$1>>;
|
4405
|
-
}
|
4406
|
-
|
4407
|
-
/**
|
4408
|
-
Generates transcripts using a transcription model.
|
4409
|
-
|
4410
|
-
@param model - The transcription model to use.
|
4411
|
-
@param audio - The audio data to transcribe as DataContent (string | Uint8Array | ArrayBuffer | Buffer) or a URL.
|
4412
|
-
@param providerOptions - Additional provider-specific options that are passed through to the provider
|
4413
|
-
as body parameters.
|
4414
|
-
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
4415
|
-
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
4416
|
-
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
4417
|
-
|
4418
|
-
@returns A result object that contains the generated transcript.
|
4419
|
-
*/
|
4420
|
-
declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
|
4421
|
-
/**
|
4422
|
-
The transcription model to use.
|
4423
|
-
*/
|
4424
|
-
model: TranscriptionModelV1;
|
4697
|
+
Instructions for the speech generation e.g. "Speak in a slow and steady tone".
|
4698
|
+
*/
|
4699
|
+
instructions?: string;
|
4425
4700
|
/**
|
4426
|
-
|
4701
|
+
The speed of the speech generation.
|
4427
4702
|
*/
|
4428
|
-
|
4703
|
+
speed?: number;
|
4429
4704
|
/**
|
4430
4705
|
Additional provider-specific options that are passed through to the provider
|
4431
4706
|
as body parameters.
|
@@ -4434,15 +4709,13 @@ declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetr
|
|
4434
4709
|
record is keyed by the provider-specific metadata key.
|
4435
4710
|
```ts
|
4436
4711
|
{
|
4437
|
-
"openai": {
|
4438
|
-
"temperature": 0
|
4439
|
-
}
|
4712
|
+
"openai": {}
|
4440
4713
|
}
|
4441
4714
|
```
|
4442
4715
|
*/
|
4443
4716
|
providerOptions?: ProviderOptions;
|
4444
4717
|
/**
|
4445
|
-
Maximum number of retries per
|
4718
|
+
Maximum number of retries per speech model call. Set to 0 to disable retries.
|
4446
4719
|
|
4447
4720
|
@default 2
|
4448
4721
|
*/
|
@@ -4456,7 +4729,7 @@ declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetr
|
|
4456
4729
|
Only applicable for HTTP-based providers.
|
4457
4730
|
*/
|
4458
4731
|
headers?: Record<string, string>;
|
4459
|
-
}): Promise<
|
4732
|
+
}): Promise<SpeechResult>;
|
4460
4733
|
|
4461
4734
|
/**
|
4462
4735
|
* Applies default settings for a language model.
|
@@ -4545,414 +4818,144 @@ declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageM
|
|
4545
4818
|
declare const experimental_customProvider: typeof customProvider;
|
4546
4819
|
type ExtractModelId<MODELS extends Record<string, unknown>> = Extract<keyof MODELS, string>;
|
4547
4820
|
|
4548
|
-
declare const symbol
|
4821
|
+
declare const symbol: unique symbol;
|
4549
4822
|
declare class NoSuchProviderError extends NoSuchModelError {
|
4550
|
-
private readonly [symbol
|
4823
|
+
private readonly [symbol];
|
4551
4824
|
readonly providerId: string;
|
4552
4825
|
readonly availableProviders: string[];
|
4553
4826
|
constructor({ modelId, modelType, providerId, availableProviders, message, }: {
|
4554
4827
|
modelId: string;
|
4555
|
-
modelType: 'languageModel' | 'textEmbeddingModel';
|
4556
|
-
providerId: string;
|
4557
|
-
availableProviders: string[];
|
4558
|
-
message?: string;
|
4559
|
-
});
|
4560
|
-
static isInstance(error: unknown): error is NoSuchProviderError;
|
4561
|
-
}
|
4562
|
-
|
4563
|
-
type ExtractLiteralUnion<T> = T extends string ? string extends T ? never : T : never;
|
4564
|
-
interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV2> = Record<string, ProviderV2>, SEPARATOR extends string = ':'> {
|
4565
|
-
languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['languageModel']>>[0]>}` : never): LanguageModel;
|
4566
|
-
languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): LanguageModel;
|
4567
|
-
textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['textEmbeddingModel']>>[0]>}` : never): EmbeddingModel<string>;
|
4568
|
-
textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): EmbeddingModel<string>;
|
4569
|
-
imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['imageModel']>>[0]>}` : never): ImageModel;
|
4570
|
-
imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): ImageModel;
|
4571
|
-
}
|
4572
|
-
/**
|
4573
|
-
* Creates a registry for the given providers.
|
4574
|
-
*/
|
4575
|
-
declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV2>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, }?: {
|
4576
|
-
separator?: SEPARATOR;
|
4577
|
-
}): ProviderRegistryProvider<PROVIDERS, SEPARATOR>;
|
4578
|
-
/**
|
4579
|
-
* @deprecated Use `createProviderRegistry` instead.
|
4580
|
-
*/
|
4581
|
-
declare const experimental_createProviderRegistry: typeof createProviderRegistry;
|
4582
|
-
|
4583
|
-
declare function getToolInvocations(message: UIMessage): ToolInvocation[];
|
4584
|
-
|
4585
|
-
declare function getUIText(parts: UIMessagePart[]): string;
|
4586
|
-
|
4587
|
-
/**
|
4588
|
-
* Calculates the cosine similarity between two vectors. This is a useful metric for
|
4589
|
-
* comparing the similarity of two vectors such as embeddings.
|
4590
|
-
*
|
4591
|
-
* @param vector1 - The first vector.
|
4592
|
-
* @param vector2 - The second vector.
|
4593
|
-
*
|
4594
|
-
* @returns The cosine similarity between vector1 and vector2.
|
4595
|
-
* @returns 0 if either vector is the zero vector.
|
4596
|
-
*
|
4597
|
-
* @throws {InvalidArgumentError} If the vectors do not have the same length.
|
4598
|
-
*/
|
4599
|
-
declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
|
4600
|
-
|
4601
|
-
/**
|
4602
|
-
* Creates a ReadableStream that emits the provided values with an optional delay between each value.
|
4603
|
-
*
|
4604
|
-
* @param options - The configuration options
|
4605
|
-
* @param options.chunks - Array of values to be emitted by the stream
|
4606
|
-
* @param options.initialDelayInMs - Optional initial delay in milliseconds before emitting the first value (default: 0). Can be set to `null` to skip the initial delay. The difference between `initialDelayInMs: null` and `initialDelayInMs: 0` is that `initialDelayInMs: null` will emit the values without any delay, while `initialDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
|
4607
|
-
* @param options.chunkDelayInMs - Optional delay in milliseconds between emitting each value (default: 0). Can be set to `null` to skip the delay. The difference between `chunkDelayInMs: null` and `chunkDelayInMs: 0` is that `chunkDelayInMs: null` will emit the values without any delay, while `chunkDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
|
4608
|
-
* @returns A ReadableStream that emits the provided values
|
4609
|
-
*/
|
4610
|
-
declare function simulateReadableStream<T>({ chunks, initialDelayInMs, chunkDelayInMs, _internal, }: {
|
4611
|
-
chunks: T[];
|
4612
|
-
initialDelayInMs?: number | null;
|
4613
|
-
chunkDelayInMs?: number | null;
|
4614
|
-
_internal?: {
|
4615
|
-
delay?: (ms: number | null) => Promise<void>;
|
4616
|
-
};
|
4617
|
-
}): ReadableStream<T>;
|
4618
|
-
|
4619
|
-
interface DataStreamWriter {
|
4620
|
-
/**
|
4621
|
-
* Appends a data stream part to the stream.
|
4622
|
-
*/
|
4623
|
-
write(part: DataStreamPart): void;
|
4624
|
-
/**
|
4625
|
-
* Merges the contents of another stream to this stream.
|
4626
|
-
*/
|
4627
|
-
merge(stream: ReadableStream<DataStreamPart>): void;
|
4628
|
-
/**
|
4629
|
-
* Error handler that is used by the data stream writer.
|
4630
|
-
* This is intended for forwarding when merging streams
|
4631
|
-
* to prevent duplicated error masking.
|
4632
|
-
*/
|
4633
|
-
onError: ((error: unknown) => string) | undefined;
|
4634
|
-
}
|
4635
|
-
|
4636
|
-
declare function createDataStream({ execute, onError, }: {
|
4637
|
-
execute: (writer: DataStreamWriter) => Promise<void> | void;
|
4638
|
-
onError?: (error: unknown) => string;
|
4639
|
-
}): ReadableStream<DataStreamPart>;
|
4640
|
-
|
4641
|
-
declare function createDataStreamResponse({ status, statusText, headers, dataStream, }: ResponseInit & {
|
4642
|
-
dataStream: ReadableStream<DataStreamPart>;
|
4643
|
-
}): Response;
|
4644
|
-
|
4645
|
-
declare function pipeDataStreamToResponse({ response, status, statusText, headers, dataStream, }: {
|
4646
|
-
response: ServerResponse;
|
4647
|
-
dataStream: ReadableStream<DataStreamPart>;
|
4648
|
-
} & ResponseInit): void;
|
4649
|
-
|
4650
|
-
declare function processDataStream({ stream, onTextPart, onReasoningPart, onReasoningPartFinish, onSourcePart, onFilePart, onDataPart, onErrorPart, onToolCallStreamingStartPart, onToolCallDeltaPart, onToolCallPart, onToolResultPart, onMessageAnnotationsPart, onFinishMessagePart, onFinishStepPart, onStartStepPart, }: {
|
4651
|
-
stream: ReadableStream<Uint8Array>;
|
4652
|
-
onTextPart?: (streamPart: (DataStreamPart & {
|
4653
|
-
type: 'text';
|
4654
|
-
})['value']) => Promise<void> | void;
|
4655
|
-
onReasoningPart?: (streamPart: (DataStreamPart & {
|
4656
|
-
type: 'reasoning';
|
4657
|
-
})['value']) => Promise<void> | void;
|
4658
|
-
onReasoningPartFinish?: (streamPart: (DataStreamPart & {
|
4659
|
-
type: 'reasoning-part-finish';
|
4660
|
-
})['value']) => Promise<void> | void;
|
4661
|
-
onFilePart?: (streamPart: (DataStreamPart & {
|
4662
|
-
type: 'file';
|
4663
|
-
})['value']) => Promise<void> | void;
|
4664
|
-
onSourcePart?: (streamPart: (DataStreamPart & {
|
4665
|
-
type: 'source';
|
4666
|
-
})['value']) => Promise<void> | void;
|
4667
|
-
onDataPart?: (streamPart: (DataStreamPart & {
|
4668
|
-
type: 'data';
|
4669
|
-
})['value']) => Promise<void> | void;
|
4670
|
-
onErrorPart?: (streamPart: (DataStreamPart & {
|
4671
|
-
type: 'error';
|
4672
|
-
})['value']) => Promise<void> | void;
|
4673
|
-
onToolCallStreamingStartPart?: (streamPart: (DataStreamPart & {
|
4674
|
-
type: 'tool-call-streaming-start';
|
4675
|
-
})['value']) => Promise<void> | void;
|
4676
|
-
onToolCallDeltaPart?: (streamPart: (DataStreamPart & {
|
4677
|
-
type: 'tool-call-delta';
|
4678
|
-
})['value']) => Promise<void> | void;
|
4679
|
-
onToolCallPart?: (streamPart: ToolCall<string, any>) => Promise<void> | void;
|
4680
|
-
onToolResultPart?: (streamPart: ToolResult<string, any, any>) => Promise<void> | void;
|
4681
|
-
onMessageAnnotationsPart?: (streamPart: (DataStreamPart & {
|
4682
|
-
type: 'message-annotations';
|
4683
|
-
})['value']) => Promise<void> | void;
|
4684
|
-
onFinishMessagePart?: (streamPart: (DataStreamPart & {
|
4685
|
-
type: 'finish-message';
|
4686
|
-
})['value']) => Promise<void> | void;
|
4687
|
-
onFinishStepPart?: (streamPart: (DataStreamPart & {
|
4688
|
-
type: 'finish-step';
|
4689
|
-
})['value']) => Promise<void> | void;
|
4690
|
-
onStartStepPart?: (streamPart: (DataStreamPart & {
|
4691
|
-
type: 'start-step';
|
4692
|
-
})['value']) => Promise<void> | void;
|
4693
|
-
}): Promise<void>;
|
4694
|
-
|
4695
|
-
declare class DataStreamToSSETransformStream extends TransformStream<DataStreamPart, string> {
|
4696
|
-
constructor();
|
4697
|
-
}
|
4698
|
-
|
4699
|
-
declare function createTextStreamResponse({ status, statusText, headers, textStream, }: ResponseInit & {
|
4700
|
-
textStream: ReadableStream<string>;
|
4701
|
-
}): Response;
|
4702
|
-
|
4703
|
-
declare function pipeTextStreamToResponse({ response, status, statusText, headers, textStream, }: {
|
4704
|
-
response: ServerResponse;
|
4705
|
-
textStream: ReadableStream<string>;
|
4706
|
-
} & ResponseInit): void;
|
4707
|
-
|
4708
|
-
declare const symbol$c: unique symbol;
|
4709
|
-
declare class InvalidArgumentError extends AISDKError {
|
4710
|
-
private readonly [symbol$c];
|
4711
|
-
readonly parameter: string;
|
4712
|
-
readonly value: unknown;
|
4713
|
-
constructor({ parameter, value, message, }: {
|
4714
|
-
parameter: string;
|
4715
|
-
value: unknown;
|
4716
|
-
message: string;
|
4717
|
-
});
|
4718
|
-
static isInstance(error: unknown): error is InvalidArgumentError;
|
4719
|
-
}
|
4720
|
-
|
4721
|
-
type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
|
4722
|
-
type: 'stream-start';
|
4723
|
-
warnings: LanguageModelV2CallWarning[];
|
4724
|
-
} | {
|
4725
|
-
type: 'text';
|
4726
|
-
text: string;
|
4727
|
-
} | {
|
4728
|
-
type: 'reasoning';
|
4729
|
-
text: string;
|
4730
|
-
providerMetadata?: ProviderMetadata;
|
4731
|
-
} | {
|
4732
|
-
type: 'reasoning-part-finish';
|
4733
|
-
} | {
|
4734
|
-
type: 'file';
|
4735
|
-
file: GeneratedFile;
|
4736
|
-
} | ({
|
4737
|
-
type: 'source';
|
4738
|
-
} & Source) | ({
|
4739
|
-
type: 'tool-call';
|
4740
|
-
} & ToolCallUnion<TOOLS>) | {
|
4741
|
-
type: 'tool-call-streaming-start';
|
4742
|
-
toolCallId: string;
|
4743
|
-
toolName: string;
|
4744
|
-
} | {
|
4745
|
-
type: 'tool-call-delta';
|
4746
|
-
toolCallId: string;
|
4747
|
-
toolName: string;
|
4748
|
-
argsTextDelta: string;
|
4749
|
-
} | ({
|
4750
|
-
type: 'tool-result';
|
4751
|
-
} & ToolResultUnion<TOOLS>) | {
|
4752
|
-
type: 'response-metadata';
|
4753
|
-
id?: string;
|
4754
|
-
timestamp?: Date;
|
4755
|
-
modelId?: string;
|
4756
|
-
} | {
|
4757
|
-
type: 'finish';
|
4758
|
-
finishReason: FinishReason;
|
4759
|
-
usage: LanguageModelUsage;
|
4760
|
-
providerMetadata?: ProviderMetadata;
|
4761
|
-
} | {
|
4762
|
-
type: 'error';
|
4763
|
-
error: unknown;
|
4764
|
-
};
|
4765
|
-
|
4766
|
-
declare const symbol$b: unique symbol;
|
4767
|
-
declare class InvalidStreamPartError extends AISDKError {
|
4768
|
-
private readonly [symbol$b];
|
4769
|
-
readonly chunk: SingleRequestTextStreamPart<any>;
|
4770
|
-
constructor({ chunk, message, }: {
|
4771
|
-
chunk: SingleRequestTextStreamPart<any>;
|
4772
|
-
message: string;
|
4773
|
-
});
|
4774
|
-
static isInstance(error: unknown): error is InvalidStreamPartError;
|
4775
|
-
}
|
4776
|
-
|
4777
|
-
declare const symbol$a: unique symbol;
|
4778
|
-
/**
|
4779
|
-
Thrown when no image could be generated. This can have multiple causes:
|
4780
|
-
|
4781
|
-
- The model failed to generate a response.
|
4782
|
-
- The model generated a response that could not be parsed.
|
4783
|
-
*/
|
4784
|
-
declare class NoImageGeneratedError extends AISDKError {
|
4785
|
-
private readonly [symbol$a];
|
4786
|
-
/**
|
4787
|
-
The response metadata for each call.
|
4788
|
-
*/
|
4789
|
-
readonly responses: Array<ImageModelResponseMetadata> | undefined;
|
4790
|
-
constructor({ message, cause, responses, }: {
|
4828
|
+
modelType: 'languageModel' | 'textEmbeddingModel';
|
4829
|
+
providerId: string;
|
4830
|
+
availableProviders: string[];
|
4791
4831
|
message?: string;
|
4792
|
-
cause?: Error;
|
4793
|
-
responses?: Array<ImageModelResponseMetadata>;
|
4794
4832
|
});
|
4795
|
-
static isInstance(error: unknown): error is
|
4833
|
+
static isInstance(error: unknown): error is NoSuchProviderError;
|
4796
4834
|
}
|
4797
4835
|
|
4798
|
-
|
4836
|
+
type ExtractLiteralUnion<T> = T extends string ? string extends T ? never : T : never;
|
4837
|
+
interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV2> = Record<string, ProviderV2>, SEPARATOR extends string = ':'> {
|
4838
|
+
languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['languageModel']>>[0]>}` : never): LanguageModel;
|
4839
|
+
languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): LanguageModel;
|
4840
|
+
textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['textEmbeddingModel']>>[0]>}` : never): EmbeddingModel<string>;
|
4841
|
+
textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): EmbeddingModel<string>;
|
4842
|
+
imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['imageModel']>>[0]>}` : never): ImageModel;
|
4843
|
+
imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): ImageModel;
|
4844
|
+
}
|
4799
4845
|
/**
|
4800
|
-
|
4801
|
-
|
4802
|
-
|
4803
|
-
|
4804
|
-
|
4805
|
-
|
4806
|
-
|
4846
|
+
* Creates a registry for the given providers.
|
4847
|
+
*/
|
4848
|
+
declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV2>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, }?: {
|
4849
|
+
separator?: SEPARATOR;
|
4850
|
+
}): ProviderRegistryProvider<PROVIDERS, SEPARATOR>;
|
4851
|
+
/**
|
4852
|
+
* @deprecated Use `createProviderRegistry` instead.
|
4853
|
+
*/
|
4854
|
+
declare const experimental_createProviderRegistry: typeof createProviderRegistry;
|
4807
4855
|
|
4808
|
-
|
4856
|
+
/**
|
4857
|
+
The result of a `transcribe` call.
|
4858
|
+
It contains the transcript and additional information.
|
4809
4859
|
*/
|
4810
|
-
|
4811
|
-
private readonly [symbol$9];
|
4860
|
+
interface TranscriptionResult {
|
4812
4861
|
/**
|
4813
|
-
|
4862
|
+
* The complete transcribed text from the audio.
|
4814
4863
|
*/
|
4815
|
-
readonly text: string
|
4864
|
+
readonly text: string;
|
4816
4865
|
/**
|
4817
|
-
|
4866
|
+
* Array of transcript segments with timing information.
|
4867
|
+
* Each segment represents a portion of the transcribed text with start and end times.
|
4818
4868
|
*/
|
4819
|
-
readonly
|
4869
|
+
readonly segments: Array<{
|
4870
|
+
/**
|
4871
|
+
* The text content of this segment.
|
4872
|
+
*/
|
4873
|
+
readonly text: string;
|
4874
|
+
/**
|
4875
|
+
* The start time of this segment in seconds.
|
4876
|
+
*/
|
4877
|
+
readonly startSecond: number;
|
4878
|
+
/**
|
4879
|
+
* The end time of this segment in seconds.
|
4880
|
+
*/
|
4881
|
+
readonly endSecond: number;
|
4882
|
+
}>;
|
4820
4883
|
/**
|
4821
|
-
|
4884
|
+
* The detected language of the audio content, as an ISO-639-1 code (e.g., 'en' for English).
|
4885
|
+
* May be undefined if the language couldn't be detected.
|
4822
4886
|
*/
|
4823
|
-
readonly
|
4887
|
+
readonly language: string | undefined;
|
4824
4888
|
/**
|
4825
|
-
|
4889
|
+
* The total duration of the audio file in seconds.
|
4890
|
+
* May be undefined if the duration couldn't be determined.
|
4826
4891
|
*/
|
4827
|
-
readonly
|
4828
|
-
|
4829
|
-
|
4830
|
-
|
4831
|
-
|
4832
|
-
|
4833
|
-
|
4834
|
-
|
4835
|
-
|
4836
|
-
|
4892
|
+
readonly durationInSeconds: number | undefined;
|
4893
|
+
/**
|
4894
|
+
Warnings for the call, e.g. unsupported settings.
|
4895
|
+
*/
|
4896
|
+
readonly warnings: Array<TranscriptionWarning>;
|
4897
|
+
/**
|
4898
|
+
Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
|
4899
|
+
*/
|
4900
|
+
readonly responses: Array<TranscriptionModelResponseMetadata>;
|
4901
|
+
/**
|
4902
|
+
Provider metadata from the provider.
|
4903
|
+
*/
|
4904
|
+
readonly providerMetadata: Record<string, Record<string, JSONValue$1>>;
|
4837
4905
|
}
|
4838
4906
|
|
4839
|
-
declare const symbol$8: unique symbol;
|
4840
4907
|
/**
|
4841
|
-
|
4842
|
-
*/
|
4843
|
-
declare class NoOutputSpecifiedError extends AISDKError {
|
4844
|
-
private readonly [symbol$8];
|
4845
|
-
constructor({ message }?: {
|
4846
|
-
message?: string;
|
4847
|
-
});
|
4848
|
-
static isInstance(error: unknown): error is NoOutputSpecifiedError;
|
4849
|
-
}
|
4850
|
-
|
4851
|
-
declare const symbol$7: unique symbol;
|
4852
|
-
declare class ToolCallRepairError extends AISDKError {
|
4853
|
-
private readonly [symbol$7];
|
4854
|
-
readonly originalError: NoSuchToolError | InvalidToolArgumentsError;
|
4855
|
-
constructor({ cause, originalError, message, }: {
|
4856
|
-
message?: string;
|
4857
|
-
cause: unknown;
|
4858
|
-
originalError: NoSuchToolError | InvalidToolArgumentsError;
|
4859
|
-
});
|
4860
|
-
static isInstance(error: unknown): error is ToolCallRepairError;
|
4861
|
-
}
|
4908
|
+
Generates transcripts using a transcription model.
|
4862
4909
|
|
4863
|
-
|
4864
|
-
|
4865
|
-
|
4866
|
-
|
4867
|
-
|
4868
|
-
|
4869
|
-
|
4870
|
-
message?: string;
|
4871
|
-
toolArgs: JSONValue$1 | unknown;
|
4872
|
-
toolName: string;
|
4873
|
-
toolCallId: string;
|
4874
|
-
cause: unknown;
|
4875
|
-
});
|
4876
|
-
static isInstance(error: unknown): error is ToolExecutionError;
|
4877
|
-
}
|
4910
|
+
@param model - The transcription model to use.
|
4911
|
+
@param audio - The audio data to transcribe as DataContent (string | Uint8Array | ArrayBuffer | Buffer) or a URL.
|
4912
|
+
@param providerOptions - Additional provider-specific options that are passed through to the provider
|
4913
|
+
as body parameters.
|
4914
|
+
@param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
|
4915
|
+
@param abortSignal - An optional abort signal that can be used to cancel the call.
|
4916
|
+
@param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
|
4878
4917
|
|
4879
|
-
|
4880
|
-
/**
|
4881
|
-
* An error occurred with the MCP client.
|
4918
|
+
@returns A result object that contains the generated transcript.
|
4882
4919
|
*/
|
4883
|
-
declare
|
4884
|
-
|
4885
|
-
|
4886
|
-
|
4887
|
-
|
4888
|
-
|
4889
|
-
|
4890
|
-
|
4891
|
-
|
4892
|
-
|
4893
|
-
|
4894
|
-
|
4895
|
-
|
4896
|
-
|
4897
|
-
|
4898
|
-
|
4899
|
-
|
4900
|
-
|
4901
|
-
|
4902
|
-
|
4903
|
-
}
|
4904
|
-
|
4905
|
-
|
4906
|
-
|
4907
|
-
|
4908
|
-
|
4909
|
-
|
4910
|
-
|
4911
|
-
|
4912
|
-
|
4913
|
-
|
4914
|
-
|
4915
|
-
|
4916
|
-
|
4917
|
-
|
4918
|
-
|
4919
|
-
|
4920
|
-
|
4921
|
-
|
4922
|
-
|
4923
|
-
});
|
4924
|
-
static isInstance(error: unknown): error is MessageConversionError;
|
4925
|
-
}
|
4926
|
-
|
4927
|
-
declare const symbol$1: unique symbol;
|
4928
|
-
declare class DownloadError extends AISDKError {
|
4929
|
-
private readonly [symbol$1];
|
4930
|
-
readonly url: string;
|
4931
|
-
readonly statusCode?: number;
|
4932
|
-
readonly statusText?: string;
|
4933
|
-
constructor({ url, statusCode, statusText, cause, message, }: {
|
4934
|
-
url: string;
|
4935
|
-
statusCode?: number;
|
4936
|
-
statusText?: string;
|
4937
|
-
message?: string;
|
4938
|
-
cause?: unknown;
|
4939
|
-
});
|
4940
|
-
static isInstance(error: unknown): error is DownloadError;
|
4941
|
-
}
|
4942
|
-
|
4943
|
-
declare const symbol: unique symbol;
|
4944
|
-
type RetryErrorReason = 'maxRetriesExceeded' | 'errorNotRetryable' | 'abort';
|
4945
|
-
declare class RetryError extends AISDKError {
|
4946
|
-
private readonly [symbol];
|
4947
|
-
readonly reason: RetryErrorReason;
|
4948
|
-
readonly lastError: unknown;
|
4949
|
-
readonly errors: Array<unknown>;
|
4950
|
-
constructor({ message, reason, errors, }: {
|
4951
|
-
message: string;
|
4952
|
-
reason: RetryErrorReason;
|
4953
|
-
errors: Array<unknown>;
|
4954
|
-
});
|
4955
|
-
static isInstance(error: unknown): error is RetryError;
|
4956
|
-
}
|
4920
|
+
declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
|
4921
|
+
/**
|
4922
|
+
The transcription model to use.
|
4923
|
+
*/
|
4924
|
+
model: TranscriptionModelV1;
|
4925
|
+
/**
|
4926
|
+
The audio data to transcribe.
|
4927
|
+
*/
|
4928
|
+
audio: DataContent | URL;
|
4929
|
+
/**
|
4930
|
+
Additional provider-specific options that are passed through to the provider
|
4931
|
+
as body parameters.
|
4932
|
+
|
4933
|
+
The outer record is keyed by the provider name, and the inner
|
4934
|
+
record is keyed by the provider-specific metadata key.
|
4935
|
+
```ts
|
4936
|
+
{
|
4937
|
+
"openai": {
|
4938
|
+
"temperature": 0
|
4939
|
+
}
|
4940
|
+
}
|
4941
|
+
```
|
4942
|
+
*/
|
4943
|
+
providerOptions?: ProviderOptions;
|
4944
|
+
/**
|
4945
|
+
Maximum number of retries per transcript model call. Set to 0 to disable retries.
|
4946
|
+
|
4947
|
+
@default 2
|
4948
|
+
*/
|
4949
|
+
maxRetries?: number;
|
4950
|
+
/**
|
4951
|
+
Abort signal.
|
4952
|
+
*/
|
4953
|
+
abortSignal?: AbortSignal;
|
4954
|
+
/**
|
4955
|
+
Additional headers to include in the request.
|
4956
|
+
Only applicable for HTTP-based providers.
|
4957
|
+
*/
|
4958
|
+
headers?: Record<string, string>;
|
4959
|
+
}): Promise<TranscriptionResult>;
|
4957
4960
|
|
4958
|
-
export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning,
|
4961
|
+
export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequestOptions, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DataStreamOptions, DataStreamPart, DataStreamWriter, DeepPartial, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, 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, UseChatOptions, UseCompletionOptions, UserContent, UserModelMessage, appendClientMessage, appendResponseMessages, assistantModelMessageSchema, callChatApi, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDataStream, createDataStreamResponse, createProviderRegistry, createTextStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractMaxToolInvocationStep, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolInvocations, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, modelMessageSchema, parsePartialJson, pipeDataStreamToResponse, pipeTextStreamToResponse, processDataStream, processTextStream, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, updateToolCallResult, userModelMessageSchema, wrapLanguageModel };
|