freestyle-sandboxes 0.0.59 → 0.0.60

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.
Files changed (55) hide show
  1. package/dist/ai/inde.d.cts +1 -1
  2. package/dist/ai/inde.d.mts +1 -1
  3. package/dist/ai/index.d.cts +1 -1
  4. package/dist/ai/index.d.mts +1 -1
  5. package/dist/inde.d.cts +2 -2
  6. package/dist/inde.d.mts +2 -2
  7. package/dist/index-BBXyg0JQ.cjs +3253 -0
  8. package/dist/index-BQHqnjZK.mjs +3231 -0
  9. package/dist/index-CEEa9WHp.cjs +3238 -0
  10. package/dist/index-D1ulQeJR.mjs +3247 -0
  11. package/dist/index-DCF70Xbq.mjs +3246 -0
  12. package/dist/index-H7UNEAjs.cjs +3254 -0
  13. package/dist/index.d-CXx1AdyW.d.ts +4210 -0
  14. package/dist/index.d.cts +2 -2
  15. package/dist/index.d.mts +2 -2
  16. package/dist/langgraph/inde.d.cts +1 -1
  17. package/dist/langgraph/inde.d.mts +1 -1
  18. package/dist/langgraph/index.d.cts +1 -1
  19. package/dist/langgraph/index.d.mts +1 -1
  20. package/dist/mastra/inde.d.cts +1 -1
  21. package/dist/mastra/inde.d.mts +1 -1
  22. package/dist/mastra/index.d.cts +1 -1
  23. package/dist/mastra/index.d.mts +1 -1
  24. package/dist/types.gen-1sd31qLV.d.ts +172 -0
  25. package/dist/types.gen-627pxroW.d.ts +830 -0
  26. package/dist/types.gen-BCdfx7yt.d.ts +760 -0
  27. package/dist/types.gen-BaMKzqxQ.d.ts +233 -0
  28. package/dist/types.gen-BbekD8Sd.d.ts +1119 -0
  29. package/dist/types.gen-BtK6PMQy.d.ts +195 -0
  30. package/dist/types.gen-BuhQ5LpB.d.ts +764 -0
  31. package/dist/types.gen-BzRtj_TA.d.ts +725 -0
  32. package/dist/types.gen-C03gaIPq.d.ts +297 -0
  33. package/dist/types.gen-CMuCas4r.d.ts +183 -0
  34. package/dist/types.gen-CZUnqmzP.d.ts +789 -0
  35. package/dist/types.gen-CnEkmbco.d.ts +314 -0
  36. package/dist/types.gen-DDYpuDzZ.d.ts +764 -0
  37. package/dist/types.gen-DHmdEOOa.d.ts +172 -0
  38. package/dist/types.gen-DLYohMJT.d.ts +382 -0
  39. package/dist/types.gen-DbTb_SrD.d.ts +156 -0
  40. package/dist/types.gen-DkQ-Dbs1.d.ts +764 -0
  41. package/dist/{types.gen-BoJEFWW-.d.ts → types.gen-DyY7Deri.d.ts} +55 -1
  42. package/dist/types.gen-MBZCvIhE.d.ts +311 -0
  43. package/dist/types.gen-YhJAHBw8.d.ts +233 -0
  44. package/dist/types.gen-cCnnhnB6.d.ts +182 -0
  45. package/dist/types.gen-mg_JNXrq.d.ts +830 -0
  46. package/dist/types.gen-uDTr6v-7.d.ts +731 -0
  47. package/dist/utils/inde.d.cts +1 -1
  48. package/dist/utils/inde.d.mts +1 -1
  49. package/dist/utils/index.d.cts +1 -1
  50. package/dist/utils/index.d.mts +1 -1
  51. package/openapi/sdk.gen.ts +98 -1
  52. package/openapi/types.gen.ts +329 -5
  53. package/openapi.json +1 -1
  54. package/package.json +2 -2
  55. package/.env +0 -1
@@ -0,0 +1,4210 @@
1
+ import { z } from 'zod';
2
+ import { ServerResponse } from 'node:http';
3
+ import { ServerResponse as ServerResponse$1 } from 'http';
4
+
5
+ // ==================================================================================================
6
+ // JSON Schema Draft 07
7
+ // ==================================================================================================
8
+ // https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
9
+ // --------------------------------------------------------------------------------------------------
10
+
11
+ /**
12
+ * Primitive type
13
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
14
+ */
15
+ type JSONSchema7TypeName =
16
+ | "string" //
17
+ | "number"
18
+ | "integer"
19
+ | "boolean"
20
+ | "object"
21
+ | "array"
22
+ | "null";
23
+
24
+ /**
25
+ * Primitive type
26
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
27
+ */
28
+ type JSONSchema7Type =
29
+ | string //
30
+ | number
31
+ | boolean
32
+ | JSONSchema7Object
33
+ | JSONSchema7Array
34
+ | null;
35
+
36
+ // Workaround for infinite type recursion
37
+ interface JSONSchema7Object {
38
+ [key: string]: JSONSchema7Type;
39
+ }
40
+
41
+ // Workaround for infinite type recursion
42
+ // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
43
+ interface JSONSchema7Array extends Array<JSONSchema7Type> {}
44
+
45
+ /**
46
+ * Meta schema
47
+ *
48
+ * Recommended values:
49
+ * - 'http://json-schema.org/schema#'
50
+ * - 'http://json-schema.org/hyper-schema#'
51
+ * - 'http://json-schema.org/draft-07/schema#'
52
+ * - 'http://json-schema.org/draft-07/hyper-schema#'
53
+ *
54
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
55
+ */
56
+ type JSONSchema7Version = string;
57
+
58
+ /**
59
+ * JSON Schema v7
60
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
61
+ */
62
+ type JSONSchema7Definition = JSONSchema7 | boolean;
63
+ interface JSONSchema7 {
64
+ $id?: string | undefined;
65
+ $ref?: string | undefined;
66
+ $schema?: JSONSchema7Version | undefined;
67
+ $comment?: string | undefined;
68
+
69
+ /**
70
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
71
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
72
+ */
73
+ $defs?: {
74
+ [key: string]: JSONSchema7Definition;
75
+ } | undefined;
76
+
77
+ /**
78
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
79
+ */
80
+ type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
81
+ enum?: JSONSchema7Type[] | undefined;
82
+ const?: JSONSchema7Type | undefined;
83
+
84
+ /**
85
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
86
+ */
87
+ multipleOf?: number | undefined;
88
+ maximum?: number | undefined;
89
+ exclusiveMaximum?: number | undefined;
90
+ minimum?: number | undefined;
91
+ exclusiveMinimum?: number | undefined;
92
+
93
+ /**
94
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
95
+ */
96
+ maxLength?: number | undefined;
97
+ minLength?: number | undefined;
98
+ pattern?: string | undefined;
99
+
100
+ /**
101
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
102
+ */
103
+ items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
104
+ additionalItems?: JSONSchema7Definition | undefined;
105
+ maxItems?: number | undefined;
106
+ minItems?: number | undefined;
107
+ uniqueItems?: boolean | undefined;
108
+ contains?: JSONSchema7Definition | undefined;
109
+
110
+ /**
111
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
112
+ */
113
+ maxProperties?: number | undefined;
114
+ minProperties?: number | undefined;
115
+ required?: string[] | undefined;
116
+ properties?: {
117
+ [key: string]: JSONSchema7Definition;
118
+ } | undefined;
119
+ patternProperties?: {
120
+ [key: string]: JSONSchema7Definition;
121
+ } | undefined;
122
+ additionalProperties?: JSONSchema7Definition | undefined;
123
+ dependencies?: {
124
+ [key: string]: JSONSchema7Definition | string[];
125
+ } | undefined;
126
+ propertyNames?: JSONSchema7Definition | undefined;
127
+
128
+ /**
129
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
130
+ */
131
+ if?: JSONSchema7Definition | undefined;
132
+ then?: JSONSchema7Definition | undefined;
133
+ else?: JSONSchema7Definition | undefined;
134
+
135
+ /**
136
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
137
+ */
138
+ allOf?: JSONSchema7Definition[] | undefined;
139
+ anyOf?: JSONSchema7Definition[] | undefined;
140
+ oneOf?: JSONSchema7Definition[] | undefined;
141
+ not?: JSONSchema7Definition | undefined;
142
+
143
+ /**
144
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
145
+ */
146
+ format?: string | undefined;
147
+
148
+ /**
149
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
150
+ */
151
+ contentMediaType?: string | undefined;
152
+ contentEncoding?: string | undefined;
153
+
154
+ /**
155
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
156
+ */
157
+ definitions?: {
158
+ [key: string]: JSONSchema7Definition;
159
+ } | undefined;
160
+
161
+ /**
162
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
163
+ */
164
+ title?: string | undefined;
165
+ description?: string | undefined;
166
+ default?: JSONSchema7Type | undefined;
167
+ readOnly?: boolean | undefined;
168
+ writeOnly?: boolean | undefined;
169
+ examples?: JSONSchema7Type | undefined;
170
+ }
171
+
172
+ /**
173
+ An embedding is a vector, i.e. an array of numbers.
174
+ It is e.g. used to represent a text as a vector of word embeddings.
175
+ */
176
+ type EmbeddingModelV1Embedding = Array<number>;
177
+
178
+ /**
179
+ Specification for an embedding model that implements the embedding model
180
+ interface version 1.
181
+
182
+ VALUE is the type of the values that the model can embed.
183
+ This will allow us to go beyond text embeddings in the future,
184
+ e.g. to support image embeddings
185
+ */
186
+ type EmbeddingModelV1<VALUE> = {
187
+ /**
188
+ The embedding model must specify which embedding model interface
189
+ version it implements. This will allow us to evolve the embedding
190
+ model interface and retain backwards compatibility. The different
191
+ implementation versions can be handled as a discriminated union
192
+ on our side.
193
+ */
194
+ readonly specificationVersion: 'v1';
195
+ /**
196
+ Name of the provider for logging purposes.
197
+ */
198
+ readonly provider: string;
199
+ /**
200
+ Provider-specific model ID for logging purposes.
201
+ */
202
+ readonly modelId: string;
203
+ /**
204
+ Limit of how many embeddings can be generated in a single API call.
205
+ */
206
+ readonly maxEmbeddingsPerCall: number | undefined;
207
+ /**
208
+ True if the model can handle multiple embedding calls in parallel.
209
+ */
210
+ readonly supportsParallelCalls: boolean;
211
+ /**
212
+ Generates a list of embeddings for the given input text.
213
+
214
+ Naming: "do" prefix to prevent accidental direct usage of the method
215
+ by the user.
216
+ */
217
+ doEmbed(options: {
218
+ /**
219
+ List of values to embed.
220
+ */
221
+ values: Array<VALUE>;
222
+ /**
223
+ Abort signal for cancelling the operation.
224
+ */
225
+ abortSignal?: AbortSignal;
226
+ /**
227
+ Additional HTTP headers to be sent with the request.
228
+ Only applicable for HTTP-based providers.
229
+ */
230
+ headers?: Record<string, string | undefined>;
231
+ }): PromiseLike<{
232
+ /**
233
+ Generated embeddings. They are in the same order as the input values.
234
+ */
235
+ embeddings: Array<EmbeddingModelV1Embedding>;
236
+ /**
237
+ Token usage. We only have input tokens for embeddings.
238
+ */
239
+ usage?: {
240
+ tokens: number;
241
+ };
242
+ /**
243
+ Optional raw response information for debugging purposes.
244
+ */
245
+ rawResponse?: {
246
+ /**
247
+ Response headers.
248
+ */
249
+ headers?: Record<string, string>;
250
+ };
251
+ }>;
252
+ };
253
+
254
+ declare const symbol$d: unique symbol;
255
+ /**
256
+ * Custom error class for AI SDK related errors.
257
+ * @extends Error
258
+ */
259
+ declare class AISDKError extends Error {
260
+ private readonly [symbol$d];
261
+ /**
262
+ * The underlying cause of the error, if any.
263
+ */
264
+ readonly cause?: unknown;
265
+ /**
266
+ * Creates an AI SDK Error.
267
+ *
268
+ * @param {Object} params - The parameters for creating the error.
269
+ * @param {string} params.name - The name of the error.
270
+ * @param {string} params.message - The error message.
271
+ * @param {unknown} [params.cause] - The underlying cause of the error.
272
+ */
273
+ constructor({ name, message, cause, }: {
274
+ name: string;
275
+ message: string;
276
+ cause?: unknown;
277
+ });
278
+ /**
279
+ * Checks if the given error is an AI SDK Error.
280
+ * @param {unknown} error - The error to check.
281
+ * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
282
+ */
283
+ static isInstance(error: unknown): error is AISDKError;
284
+ protected static hasMarker(error: unknown, marker: string): boolean;
285
+ }
286
+
287
+ declare const symbol$7: unique symbol;
288
+ declare class JSONParseError extends AISDKError {
289
+ private readonly [symbol$7];
290
+ readonly text: string;
291
+ constructor({ text, cause }: {
292
+ text: string;
293
+ cause: unknown;
294
+ });
295
+ static isInstance(error: unknown): error is JSONParseError;
296
+ }
297
+
298
+ declare const symbol$1: unique symbol;
299
+ declare class TypeValidationError extends AISDKError {
300
+ private readonly [symbol$1];
301
+ readonly value: unknown;
302
+ constructor({ value, cause }: {
303
+ value: unknown;
304
+ cause: unknown;
305
+ });
306
+ static isInstance(error: unknown): error is TypeValidationError;
307
+ /**
308
+ * Wraps an error into a TypeValidationError.
309
+ * If the cause is already a TypeValidationError with the same value, it returns the cause.
310
+ * Otherwise, it creates a new TypeValidationError.
311
+ *
312
+ * @param {Object} params - The parameters for wrapping the error.
313
+ * @param {unknown} params.value - The value that failed validation.
314
+ * @param {unknown} params.cause - The original error or cause of the validation failure.
315
+ * @returns {TypeValidationError} A TypeValidationError instance.
316
+ */
317
+ static wrap({ value, cause, }: {
318
+ value: unknown;
319
+ cause: unknown;
320
+ }): TypeValidationError;
321
+ }
322
+
323
+ type JSONValue$2 = null | string | number | boolean | JSONObject$1 | JSONArray$1;
324
+ type JSONObject$1 = {
325
+ [key: string]: JSONValue$2;
326
+ };
327
+ type JSONArray$1 = JSONValue$2[];
328
+
329
+ /**
330
+ * Additional provider-specific metadata. They are passed through
331
+ * to the provider from the AI SDK and enable provider-specific
332
+ * functionality that can be fully encapsulated in the provider.
333
+ *
334
+ * This enables us to quickly ship provider-specific functionality
335
+ * without affecting the core AI SDK.
336
+ *
337
+ * The outer record is keyed by the provider name, and the inner
338
+ * record is keyed by the provider-specific metadata key.
339
+ *
340
+ * ```ts
341
+ * {
342
+ * "anthropic": {
343
+ * "cacheControl": { "type": "ephemeral" }
344
+ * }
345
+ * }
346
+ * ```
347
+ */
348
+ type LanguageModelV1ProviderMetadata$1 = Record<string, Record<string, JSONValue$2>>;
349
+
350
+ /**
351
+ * A source that has been used as input to generate the response.
352
+ */
353
+ type LanguageModelV1Source$1 = {
354
+ /**
355
+ * A URL source. This is return by web search RAG models.
356
+ */
357
+ sourceType: 'url';
358
+ /**
359
+ * The ID of the source.
360
+ */
361
+ id: string;
362
+ /**
363
+ * The URL of the source.
364
+ */
365
+ url: string;
366
+ /**
367
+ * The title of the source.
368
+ */
369
+ title?: string;
370
+ /**
371
+ * Additional provider metadata for the source.
372
+ */
373
+ providerMetadata?: LanguageModelV1ProviderMetadata$1;
374
+ };
375
+
376
+ type LanguageModelV1CallSettings = {
377
+ /**
378
+ Maximum number of tokens to generate.
379
+ */
380
+ maxTokens?: number;
381
+ /**
382
+ Temperature setting.
383
+
384
+ It is recommended to set either `temperature` or `topP`, but not both.
385
+ */
386
+ temperature?: number;
387
+ /**
388
+ Stop sequences.
389
+ If set, the model will stop generating text when one of the stop sequences is generated.
390
+ Providers may have limits on the number of stop sequences.
391
+ */
392
+ stopSequences?: string[];
393
+ /**
394
+ Nucleus sampling.
395
+
396
+ It is recommended to set either `temperature` or `topP`, but not both.
397
+ */
398
+ topP?: number;
399
+ /**
400
+ Only sample from the top K options for each subsequent token.
401
+
402
+ Used to remove "long tail" low probability responses.
403
+ Recommended for advanced use cases only. You usually only need to use temperature.
404
+ */
405
+ topK?: number;
406
+ /**
407
+ Presence penalty setting. It affects the likelihood of the model to
408
+ repeat information that is already in the prompt.
409
+ */
410
+ presencePenalty?: number;
411
+ /**
412
+ Frequency penalty setting. It affects the likelihood of the model
413
+ to repeatedly use the same words or phrases.
414
+ */
415
+ frequencyPenalty?: number;
416
+ /**
417
+ Response format. The output can either be text or JSON. Default is text.
418
+
419
+ If JSON is selected, a schema can optionally be provided to guide the LLM.
420
+ */
421
+ responseFormat?: {
422
+ type: 'text';
423
+ } | {
424
+ type: 'json';
425
+ /**
426
+ * JSON schema that the generated output should conform to.
427
+ */
428
+ schema?: JSONSchema7;
429
+ /**
430
+ * Name of output that should be generated. Used by some providers for additional LLM guidance.
431
+ */
432
+ name?: string;
433
+ /**
434
+ * Description of the output that should be generated. Used by some providers for additional LLM guidance.
435
+ */
436
+ description?: string;
437
+ };
438
+ /**
439
+ The seed (integer) to use for random sampling. If set and supported
440
+ by the model, calls will generate deterministic results.
441
+ */
442
+ seed?: number;
443
+ /**
444
+ Abort signal for cancelling the operation.
445
+ */
446
+ abortSignal?: AbortSignal;
447
+ /**
448
+ Additional HTTP headers to be sent with the request.
449
+ Only applicable for HTTP-based providers.
450
+ */
451
+ headers?: Record<string, string | undefined>;
452
+ };
453
+
454
+ /**
455
+ A tool has a name, a description, and a set of parameters.
456
+
457
+ Note: this is **not** the user-facing tool definition. The AI SDK methods will
458
+ map the user-facing tool definitions to this format.
459
+ */
460
+ type LanguageModelV1FunctionTool = {
461
+ /**
462
+ The type of the tool (always 'function').
463
+ */
464
+ type: 'function';
465
+ /**
466
+ The name of the tool. Unique within this model call.
467
+ */
468
+ name: string;
469
+ /**
470
+ A description of the tool. The language model uses this to understand the
471
+ tool's purpose and to provide better completion suggestions.
472
+ */
473
+ description?: string;
474
+ /**
475
+ The parameters that the tool expects. The language model uses this to
476
+ understand the tool's input requirements and to provide matching suggestions.
477
+ */
478
+ parameters: JSONSchema7;
479
+ };
480
+
481
+ /**
482
+ A prompt is a list of messages.
483
+
484
+ Note: Not all models and prompt formats support multi-modal inputs and
485
+ tool calls. The validation happens at runtime.
486
+
487
+ Note: This is not a user-facing prompt. The AI SDK methods will map the
488
+ user-facing prompt types such as chat or instruction prompts to this format.
489
+ */
490
+ type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
491
+ type LanguageModelV1Message = ({
492
+ role: 'system';
493
+ content: string;
494
+ } | {
495
+ role: 'user';
496
+ content: Array<LanguageModelV1TextPart | LanguageModelV1ImagePart | LanguageModelV1FilePart>;
497
+ } | {
498
+ role: 'assistant';
499
+ content: Array<LanguageModelV1TextPart | LanguageModelV1ReasoningPart | LanguageModelV1RedactedReasoningPart | LanguageModelV1ToolCallPart>;
500
+ } | {
501
+ role: 'tool';
502
+ content: Array<LanguageModelV1ToolResultPart>;
503
+ }) & {
504
+ /**
505
+ * Additional provider-specific metadata. They are passed through
506
+ * to the provider from the AI SDK and enable provider-specific
507
+ * functionality that can be fully encapsulated in the provider.
508
+ */
509
+ providerMetadata?: LanguageModelV1ProviderMetadata$1;
510
+ };
511
+ /**
512
+ Text content part of a prompt. It contains a string of text.
513
+ */
514
+ interface LanguageModelV1TextPart {
515
+ type: 'text';
516
+ /**
517
+ The text content.
518
+ */
519
+ text: string;
520
+ /**
521
+ * Additional provider-specific metadata. They are passed through
522
+ * to the provider from the AI SDK and enable provider-specific
523
+ * functionality that can be fully encapsulated in the provider.
524
+ */
525
+ providerMetadata?: LanguageModelV1ProviderMetadata$1;
526
+ }
527
+ /**
528
+ Reasoning content part of a prompt. It contains a string of reasoning text.
529
+ */
530
+ interface LanguageModelV1ReasoningPart {
531
+ type: 'reasoning';
532
+ /**
533
+ The reasoning text.
534
+ */
535
+ text: string;
536
+ /**
537
+ An optional signature for verifying that the reasoning originated from the model.
538
+ */
539
+ signature?: string;
540
+ /**
541
+ Additional provider-specific metadata. They are passed through
542
+ to the provider from the AI SDK and enable provider-specific
543
+ functionality that can be fully encapsulated in the provider.
544
+ */
545
+ providerMetadata?: LanguageModelV1ProviderMetadata$1;
546
+ }
547
+ /**
548
+ Redacted reasoning content part of a prompt.
549
+ */
550
+ interface LanguageModelV1RedactedReasoningPart {
551
+ type: 'redacted-reasoning';
552
+ /**
553
+ Redacted reasoning data.
554
+ */
555
+ data: string;
556
+ /**
557
+ Additional provider-specific metadata. They are passed through
558
+ to the provider from the AI SDK and enable provider-specific
559
+ functionality that can be fully encapsulated in the provider.
560
+ */
561
+ providerMetadata?: LanguageModelV1ProviderMetadata$1;
562
+ }
563
+ /**
564
+ Image content part of a prompt. It contains an image.
565
+ */
566
+ interface LanguageModelV1ImagePart {
567
+ type: 'image';
568
+ /**
569
+ Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
570
+ */
571
+ image: Uint8Array | URL;
572
+ /**
573
+ Optional mime type of the image.
574
+ */
575
+ mimeType?: string;
576
+ /**
577
+ * Additional provider-specific metadata. They are passed through
578
+ * to the provider from the AI SDK and enable provider-specific
579
+ * functionality that can be fully encapsulated in the provider.
580
+ */
581
+ providerMetadata?: LanguageModelV1ProviderMetadata$1;
582
+ }
583
+ /**
584
+ File content part of a prompt. It contains a file.
585
+ */
586
+ interface LanguageModelV1FilePart {
587
+ type: 'file';
588
+ /**
589
+ * Optional filename of the file.
590
+ */
591
+ filename?: string;
592
+ /**
593
+ File data as base64 encoded string or as a URL.
594
+ */
595
+ data: string | URL;
596
+ /**
597
+ Mime type of the file.
598
+ */
599
+ mimeType: string;
600
+ /**
601
+ * Additional provider-specific metadata. They are passed through
602
+ * to the provider from the AI SDK and enable provider-specific
603
+ * functionality that can be fully encapsulated in the provider.
604
+ */
605
+ providerMetadata?: LanguageModelV1ProviderMetadata$1;
606
+ }
607
+ /**
608
+ Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
609
+ */
610
+ interface LanguageModelV1ToolCallPart {
611
+ type: 'tool-call';
612
+ /**
613
+ ID of the tool call. This ID is used to match the tool call with the tool result.
614
+ */
615
+ toolCallId: string;
616
+ /**
617
+ Name of the tool that is being called.
618
+ */
619
+ toolName: string;
620
+ /**
621
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
622
+ */
623
+ args: unknown;
624
+ /**
625
+ * Additional provider-specific metadata. They are passed through
626
+ * to the provider from the AI SDK and enable provider-specific
627
+ * functionality that can be fully encapsulated in the provider.
628
+ */
629
+ providerMetadata?: LanguageModelV1ProviderMetadata$1;
630
+ }
631
+ /**
632
+ Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
633
+ */
634
+ interface LanguageModelV1ToolResultPart {
635
+ type: 'tool-result';
636
+ /**
637
+ ID of the tool call that this result is associated with.
638
+ */
639
+ toolCallId: string;
640
+ /**
641
+ Name of the tool that generated this result.
642
+ */
643
+ toolName: string;
644
+ /**
645
+ Result of the tool call. This is a JSON-serializable object.
646
+ */
647
+ result: unknown;
648
+ /**
649
+ Optional flag if the result is an error or an error message.
650
+ */
651
+ isError?: boolean;
652
+ /**
653
+ Tool results as an array of parts. This enables advanced tool results including images.
654
+ When this is used, the `result` field should be ignored (if the provider supports content).
655
+ */
656
+ content?: Array<{
657
+ type: 'text';
658
+ /**
659
+ Text content.
660
+ */
661
+ text: string;
662
+ } | {
663
+ type: 'image';
664
+ /**
665
+ base-64 encoded image data
666
+ */
667
+ data: string;
668
+ /**
669
+ Mime type of the image.
670
+ */
671
+ mimeType?: string;
672
+ }>;
673
+ /**
674
+ * Additional provider-specific metadata. They are passed through
675
+ * to the provider from the AI SDK and enable provider-specific
676
+ * functionality that can be fully encapsulated in the provider.
677
+ */
678
+ providerMetadata?: LanguageModelV1ProviderMetadata$1;
679
+ }
680
+
681
+ /**
682
+ The configuration of a tool that is defined by the provider.
683
+ */
684
+ type LanguageModelV1ProviderDefinedTool = {
685
+ /**
686
+ The type of the tool (always 'provider-defined').
687
+ */
688
+ type: 'provider-defined';
689
+ /**
690
+ The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
691
+ */
692
+ id: `${string}.${string}`;
693
+ /**
694
+ The name of the tool. Unique within this model call.
695
+ */
696
+ name: string;
697
+ /**
698
+ The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
699
+ */
700
+ args: Record<string, unknown>;
701
+ };
702
+
703
+ type LanguageModelV1ToolChoice = {
704
+ type: 'auto';
705
+ } | {
706
+ type: 'none';
707
+ } | {
708
+ type: 'required';
709
+ } | {
710
+ type: 'tool';
711
+ toolName: string;
712
+ };
713
+
714
+ type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
715
+ /**
716
+ Whether the user provided the input as messages or as
717
+ a prompt. This can help guide non-chat models in the
718
+ expansion, bc different expansions can be needed for
719
+ chat/non-chat use cases.
720
+ */
721
+ inputFormat: 'messages' | 'prompt';
722
+ /**
723
+ The mode affects the behavior of the language model. It is required to
724
+ support provider-independent streaming and generation of structured objects.
725
+ The model can take this information and e.g. configure json mode, the correct
726
+ low level grammar, etc. It can also be used to optimize the efficiency of the
727
+ streaming, e.g. tool-delta stream parts are only needed in the
728
+ object-tool mode.
729
+
730
+ @deprecated mode will be removed in v2.
731
+ All necessary settings will be directly supported through the call settings,
732
+ in particular responseFormat, toolChoice, and tools.
733
+ */
734
+ mode: {
735
+ type: 'regular';
736
+ /**
737
+ The tools that are available for the model.
738
+ */
739
+ tools?: Array<LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool>;
740
+ /**
741
+ Specifies how the tool should be selected. Defaults to 'auto'.
742
+ */
743
+ toolChoice?: LanguageModelV1ToolChoice;
744
+ } | {
745
+ type: 'object-json';
746
+ /**
747
+ * JSON schema that the generated output should conform to.
748
+ */
749
+ schema?: JSONSchema7;
750
+ /**
751
+ * Name of output that should be generated. Used by some providers for additional LLM guidance.
752
+ */
753
+ name?: string;
754
+ /**
755
+ * Description of the output that should be generated. Used by some providers for additional LLM guidance.
756
+ */
757
+ description?: string;
758
+ } | {
759
+ type: 'object-tool';
760
+ tool: LanguageModelV1FunctionTool;
761
+ };
762
+ /**
763
+ A language mode prompt is a standardized prompt type.
764
+
765
+ Note: This is **not** the user-facing prompt. The AI SDK methods will map the
766
+ user-facing prompt types such as chat or instruction prompts to this format.
767
+ That approach allows us to evolve the user facing prompts without breaking
768
+ the language model interface.
769
+ */
770
+ prompt: LanguageModelV1Prompt;
771
+ /**
772
+ Additional provider-specific metadata.
773
+ The metadata is passed through to the provider from the AI SDK and enables
774
+ provider-specific functionality that can be fully encapsulated in the provider.
775
+ */
776
+ providerMetadata?: LanguageModelV1ProviderMetadata$1;
777
+ };
778
+
779
+ /**
780
+ Warning from the model provider for this call. The call will proceed, but e.g.
781
+ some settings might not be supported, which can lead to suboptimal results.
782
+ */
783
+ type LanguageModelV1CallWarning = {
784
+ type: 'unsupported-setting';
785
+ setting: keyof LanguageModelV1CallSettings;
786
+ details?: string;
787
+ } | {
788
+ type: 'unsupported-tool';
789
+ tool: LanguageModelV1FunctionTool | LanguageModelV1ProviderDefinedTool;
790
+ details?: string;
791
+ } | {
792
+ type: 'other';
793
+ message: string;
794
+ };
795
+
796
+ /**
797
+ Reason why a language model finished generating a response.
798
+
799
+ Can be one of the following:
800
+ - `stop`: model generated stop sequence
801
+ - `length`: model generated maximum number of tokens
802
+ - `content-filter`: content filter violation stopped the model
803
+ - `tool-calls`: model triggered tool calls
804
+ - `error`: model stopped because of an error
805
+ - `other`: model stopped for other reasons
806
+ - `unknown`: the model has not transmitted a finish reason
807
+ */
808
+ type LanguageModelV1FinishReason$1 = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
809
+
810
+ type LanguageModelV1FunctionToolCall = {
811
+ toolCallType: 'function';
812
+ toolCallId: string;
813
+ toolName: string;
814
+ /**
815
+ Stringified JSON object with the tool call arguments. Must match the
816
+ parameters schema of the tool.
817
+ */
818
+ args: string;
819
+ };
820
+
821
+ /**
822
+ Log probabilities for each token and its top log probabilities.
823
+ */
824
+ type LanguageModelV1LogProbs = Array<{
825
+ token: string;
826
+ logprob: number;
827
+ topLogprobs: Array<{
828
+ token: string;
829
+ logprob: number;
830
+ }>;
831
+ }>;
832
+
833
+ /**
834
+ Specification for a language model that implements the language model interface version 1.
835
+ */
836
+ type LanguageModelV1 = {
837
+ /**
838
+ The language model must specify which language model interface
839
+ version it implements. This will allow us to evolve the language
840
+ model interface and retain backwards compatibility. The different
841
+ implementation versions can be handled as a discriminated union
842
+ on our side.
843
+ */
844
+ readonly specificationVersion: 'v1';
845
+ /**
846
+ Name of the provider for logging purposes.
847
+ */
848
+ readonly provider: string;
849
+ /**
850
+ Provider-specific model ID for logging purposes.
851
+ */
852
+ readonly modelId: string;
853
+ /**
854
+ Default object generation mode that should be used with this model when
855
+ no mode is specified. Should be the mode with the best results for this
856
+ model. `undefined` can be returned if object generation is not supported.
857
+
858
+ This is needed to generate the best objects possible w/o requiring the
859
+ user to explicitly specify the object generation mode.
860
+ */
861
+ readonly defaultObjectGenerationMode: LanguageModelV1ObjectGenerationMode;
862
+ /**
863
+ Flag whether this model supports image URLs. Default is `true`.
864
+
865
+ When the flag is set to `false`, the AI SDK will download the image and
866
+ pass the image data to the model.
867
+ */
868
+ readonly supportsImageUrls?: boolean;
869
+ /**
870
+ Flag whether this model supports grammar-guided generation,
871
+ i.e. follows JSON schemas for object generation
872
+ when the response format is set to 'json' or
873
+ when the `object-json` mode is used.
874
+
875
+ This means that the model guarantees that the generated JSON
876
+ will be a valid JSON object AND that the object will match the
877
+ JSON schema.
878
+
879
+ Please note that `generateObject` and `streamObject` will work
880
+ regardless of this flag, but might send different prompts and
881
+ use further optimizations if this flag is set to `true`.
882
+
883
+ Defaults to `false`.
884
+ */
885
+ readonly supportsStructuredOutputs?: boolean;
886
+ /**
887
+ Checks if the model supports the given URL for file parts natively.
888
+ If the model does not support the URL,
889
+ the AI SDK will download the file and pass the file data to the model.
890
+
891
+ When undefined, the AI SDK will download the file.
892
+ */
893
+ supportsUrl?(url: URL): boolean;
894
+ /**
895
+ Generates a language model output (non-streaming).
896
+
897
+ Naming: "do" prefix to prevent accidental direct usage of the method
898
+ by the user.
899
+ */
900
+ doGenerate(options: LanguageModelV1CallOptions): PromiseLike<{
901
+ /**
902
+ Text that the model has generated.
903
+ Can be undefined if the model did not generate any text.
904
+ */
905
+ text?: string;
906
+ /**
907
+ Reasoning that the model has generated.
908
+ Can be undefined if the model does not support reasoning.
909
+ */
910
+ reasoning?: string | Array<{
911
+ type: 'text';
912
+ text: string;
913
+ /**
914
+ An optional signature for verifying that the reasoning originated from the model.
915
+ */
916
+ signature?: string;
917
+ } | {
918
+ type: 'redacted';
919
+ data: string;
920
+ }>;
921
+ /**
922
+ Tool calls that the model has generated.
923
+ Can be undefined if the model did not generate any tool calls.
924
+ */
925
+ toolCalls?: Array<LanguageModelV1FunctionToolCall>;
926
+ /**
927
+ Finish reason.
928
+ */
929
+ finishReason: LanguageModelV1FinishReason$1;
930
+ /**
931
+ Usage information.
932
+ */
933
+ usage: {
934
+ promptTokens: number;
935
+ completionTokens: number;
936
+ };
937
+ /**
938
+ Raw prompt and setting information for observability provider integration.
939
+ */
940
+ rawCall: {
941
+ /**
942
+ Raw prompt after expansion and conversion to the format that the
943
+ provider uses to send the information to their API.
944
+ */
945
+ rawPrompt: unknown;
946
+ /**
947
+ Raw settings that are used for the API call. Includes provider-specific
948
+ settings.
949
+ */
950
+ rawSettings: Record<string, unknown>;
951
+ };
952
+ /**
953
+ Optional response information for telemetry and debugging purposes.
954
+ */
955
+ rawResponse?: {
956
+ /**
957
+ Response headers.
958
+ */
959
+ headers?: Record<string, string>;
960
+ /**
961
+ Response body.
962
+ */
963
+ body?: unknown;
964
+ };
965
+ /**
966
+ Optional request information for telemetry and debugging purposes.
967
+ */
968
+ request?: {
969
+ /**
970
+ Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
971
+ Non-HTTP(s) providers should not set this.
972
+ */
973
+ body?: string;
974
+ };
975
+ /**
976
+ Optional response information for telemetry and debugging purposes.
977
+ */
978
+ response?: {
979
+ /**
980
+ ID for the generated response, if the provider sends one.
981
+ */
982
+ id?: string;
983
+ /**
984
+ Timestamp for the start of the generated response, if the provider sends one.
985
+ */
986
+ timestamp?: Date;
987
+ /**
988
+ The ID of the response model that was used to generate the response, if the provider sends one.
989
+ */
990
+ modelId?: string;
991
+ };
992
+ warnings?: LanguageModelV1CallWarning[];
993
+ /**
994
+ Additional provider-specific metadata. They are passed through
995
+ from the provider to the AI SDK and enable provider-specific
996
+ results that can be fully encapsulated in the provider.
997
+ */
998
+ providerMetadata?: LanguageModelV1ProviderMetadata$1;
999
+ /**
1000
+ Sources that have been used as input to generate the response.
1001
+ */
1002
+ sources?: LanguageModelV1Source$1[];
1003
+ /**
1004
+ Logprobs for the completion.
1005
+ `undefined` if the mode does not support logprobs or if was not enabled
1006
+
1007
+ @deprecated will be changed into a provider-specific extension in v2
1008
+ */
1009
+ logprobs?: LanguageModelV1LogProbs;
1010
+ }>;
1011
+ /**
1012
+ Generates a language model output (streaming).
1013
+
1014
+ Naming: "do" prefix to prevent accidental direct usage of the method
1015
+ by the user.
1016
+ *
1017
+ @return A stream of higher-level language model output parts.
1018
+ */
1019
+ doStream(options: LanguageModelV1CallOptions): PromiseLike<{
1020
+ stream: ReadableStream<LanguageModelV1StreamPart>;
1021
+ /**
1022
+ Raw prompt and setting information for observability provider integration.
1023
+ */
1024
+ rawCall: {
1025
+ /**
1026
+ Raw prompt after expansion and conversion to the format that the
1027
+ provider uses to send the information to their API.
1028
+ */
1029
+ rawPrompt: unknown;
1030
+ /**
1031
+ Raw settings that are used for the API call. Includes provider-specific
1032
+ settings.
1033
+ */
1034
+ rawSettings: Record<string, unknown>;
1035
+ };
1036
+ /**
1037
+ Optional raw response data.
1038
+ */
1039
+ rawResponse?: {
1040
+ /**
1041
+ Response headers.
1042
+ */
1043
+ headers?: Record<string, string>;
1044
+ };
1045
+ /**
1046
+ Optional request information for telemetry and debugging purposes.
1047
+ */
1048
+ request?: {
1049
+ /**
1050
+ Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
1051
+ Non-HTTP(s) providers should not set this.
1052
+ */
1053
+ body?: string;
1054
+ };
1055
+ /**
1056
+ Warnings for the call, e.g. unsupported settings.
1057
+ */
1058
+ warnings?: Array<LanguageModelV1CallWarning>;
1059
+ }>;
1060
+ };
1061
+ type LanguageModelV1StreamPart = {
1062
+ type: 'text-delta';
1063
+ textDelta: string;
1064
+ } | {
1065
+ type: 'reasoning';
1066
+ textDelta: string;
1067
+ } | {
1068
+ type: 'reasoning-signature';
1069
+ signature: string;
1070
+ } | {
1071
+ type: 'redacted-reasoning';
1072
+ data: string;
1073
+ } | {
1074
+ type: 'source';
1075
+ source: LanguageModelV1Source$1;
1076
+ } | ({
1077
+ type: 'tool-call';
1078
+ } & LanguageModelV1FunctionToolCall) | {
1079
+ type: 'tool-call-delta';
1080
+ toolCallType: 'function';
1081
+ toolCallId: string;
1082
+ toolName: string;
1083
+ argsTextDelta: string;
1084
+ } | {
1085
+ type: 'response-metadata';
1086
+ id?: string;
1087
+ timestamp?: Date;
1088
+ modelId?: string;
1089
+ } | {
1090
+ type: 'finish';
1091
+ finishReason: LanguageModelV1FinishReason$1;
1092
+ providerMetadata?: LanguageModelV1ProviderMetadata$1;
1093
+ usage: {
1094
+ promptTokens: number;
1095
+ completionTokens: number;
1096
+ };
1097
+ logprobs?: LanguageModelV1LogProbs;
1098
+ } | {
1099
+ type: 'error';
1100
+ error: unknown;
1101
+ };
1102
+ /**
1103
+ The object generation modes available for use with a model. `undefined`
1104
+ represents no support for object generation.
1105
+ */
1106
+ type LanguageModelV1ObjectGenerationMode = 'json' | 'tool' | undefined;
1107
+
1108
+ /**
1109
+ A function that generates an ID.
1110
+ */
1111
+ type IDGenerator = () => string;
1112
+
1113
+ type JSONValue$1 = null | string | number | boolean | JSONObject | JSONArray;
1114
+ type JSONObject = {
1115
+ [key: string]: JSONValue$1;
1116
+ };
1117
+ type JSONArray = JSONValue$1[];
1118
+
1119
+ /**
1120
+ * Additional provider-specific metadata. They are passed through
1121
+ * to the provider from the AI SDK and enable provider-specific
1122
+ * functionality that can be fully encapsulated in the provider.
1123
+ *
1124
+ * This enables us to quickly ship provider-specific functionality
1125
+ * without affecting the core AI SDK.
1126
+ *
1127
+ * The outer record is keyed by the provider name, and the inner
1128
+ * record is keyed by the provider-specific metadata key.
1129
+ *
1130
+ * ```ts
1131
+ * {
1132
+ * "anthropic": {
1133
+ * "cacheControl": { "type": "ephemeral" }
1134
+ * }
1135
+ * }
1136
+ * ```
1137
+ */
1138
+ type LanguageModelV1ProviderMetadata = Record<string, Record<string, JSONValue$1>>;
1139
+
1140
+ /**
1141
+ * A source that has been used as input to generate the response.
1142
+ */
1143
+ type LanguageModelV1Source = {
1144
+ /**
1145
+ * A URL source. This is return by web search RAG models.
1146
+ */
1147
+ sourceType: 'url';
1148
+ /**
1149
+ * The ID of the source.
1150
+ */
1151
+ id: string;
1152
+ /**
1153
+ * The URL of the source.
1154
+ */
1155
+ url: string;
1156
+ /**
1157
+ * The title of the source.
1158
+ */
1159
+ title?: string;
1160
+ /**
1161
+ * Additional provider metadata for the source.
1162
+ */
1163
+ providerMetadata?: LanguageModelV1ProviderMetadata;
1164
+ };
1165
+
1166
+ /**
1167
+ Reason why a language model finished generating a response.
1168
+
1169
+ Can be one of the following:
1170
+ - `stop`: model generated stop sequence
1171
+ - `length`: model generated maximum number of tokens
1172
+ - `content-filter`: content filter violation stopped the model
1173
+ - `tool-calls`: model triggered tool calls
1174
+ - `error`: model stopped because of an error
1175
+ - `other`: model stopped for other reasons
1176
+ - `unknown`: the model has not transmitted a finish reason
1177
+ */
1178
+ type LanguageModelV1FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
1179
+
1180
+ /**
1181
+ * Used to mark validator functions so we can support both Zod and custom schemas.
1182
+ */
1183
+ declare const validatorSymbol: unique symbol;
1184
+ type ValidationResult<OBJECT> = {
1185
+ success: true;
1186
+ value: OBJECT;
1187
+ } | {
1188
+ success: false;
1189
+ error: Error;
1190
+ };
1191
+ type Validator<OBJECT = unknown> = {
1192
+ /**
1193
+ * Used to mark validator functions so we can support both Zod and custom schemas.
1194
+ */
1195
+ [validatorSymbol]: true;
1196
+ /**
1197
+ * Optional. Validates that the structure of a value matches this schema,
1198
+ * and returns a typed version of the value if it does.
1199
+ */
1200
+ readonly validate?: (value: unknown) => ValidationResult<OBJECT>;
1201
+ };
1202
+
1203
+ /**
1204
+ Typed tool call that is returned by generateText and streamText.
1205
+ It contains the tool call ID, the tool name, and the tool arguments.
1206
+ */
1207
+ interface ToolCall<NAME extends string, ARGS> {
1208
+ /**
1209
+ ID of the tool call. This ID is used to match the tool call with the tool result.
1210
+ */
1211
+ toolCallId: string;
1212
+ /**
1213
+ Name of the tool that is being called.
1214
+ */
1215
+ toolName: NAME;
1216
+ /**
1217
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
1218
+ */
1219
+ args: ARGS;
1220
+ }
1221
+
1222
+ /**
1223
+ Typed tool result that is returned by `generateText` and `streamText`.
1224
+ It contains the tool call ID, the tool name, the tool arguments, and the tool result.
1225
+ */
1226
+ interface ToolResult<NAME extends string, ARGS, RESULT> {
1227
+ /**
1228
+ ID of the tool call. This ID is used to match the tool call with the tool result.
1229
+ */
1230
+ toolCallId: string;
1231
+ /**
1232
+ Name of the tool that was called.
1233
+ */
1234
+ toolName: NAME;
1235
+ /**
1236
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
1237
+ */
1238
+ args: ARGS;
1239
+ /**
1240
+ Result of the tool call. This is the result of the tool's execution.
1241
+ */
1242
+ result: RESULT;
1243
+ }
1244
+
1245
+ /**
1246
+ Tool invocations are either tool calls or tool results. For each assistant tool call,
1247
+ there is one tool invocation. While the call is in progress, the invocation is a tool call.
1248
+ Once the call is complete, the invocation is a tool result.
1249
+
1250
+ The step is used to track how to map an assistant UI message with many tool invocations
1251
+ back to a sequence of LLM assistant/tool result message pairs.
1252
+ It is optional for backwards compatibility.
1253
+ */
1254
+ type ToolInvocation = ({
1255
+ state: 'partial-call';
1256
+ step?: number;
1257
+ } & ToolCall<string, any>) | ({
1258
+ state: 'call';
1259
+ step?: number;
1260
+ } & ToolCall<string, any>) | ({
1261
+ state: 'result';
1262
+ step?: number;
1263
+ } & ToolResult<string, any, any>);
1264
+ /**
1265
+ * An attachment that can be sent along with a message.
1266
+ */
1267
+ interface Attachment {
1268
+ /**
1269
+ * The name of the attachment, usually the file name.
1270
+ */
1271
+ name?: string;
1272
+ /**
1273
+ * A string indicating the [media type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type).
1274
+ * By default, it's extracted from the pathname's extension.
1275
+ */
1276
+ contentType?: string;
1277
+ /**
1278
+ * The URL of the attachment. 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).
1279
+ */
1280
+ url: string;
1281
+ }
1282
+ /**
1283
+ * AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
1284
+ */
1285
+ interface Message {
1286
+ /**
1287
+ A unique identifier for the message.
1288
+ */
1289
+ id: string;
1290
+ /**
1291
+ The timestamp of the message.
1292
+ */
1293
+ createdAt?: Date;
1294
+ /**
1295
+ Text content of the message. Use parts when possible.
1296
+ */
1297
+ content: string;
1298
+ /**
1299
+ Reasoning for the message.
1300
+
1301
+ @deprecated Use `parts` instead.
1302
+ */
1303
+ reasoning?: string;
1304
+ /**
1305
+ * Additional attachments to be sent along with the message.
1306
+ */
1307
+ experimental_attachments?: Attachment[];
1308
+ /**
1309
+ The 'data' role is deprecated.
1310
+ */
1311
+ role: 'system' | 'user' | 'assistant' | 'data';
1312
+ /**
1313
+ For data messages.
1314
+
1315
+ @deprecated Data messages will be removed.
1316
+ */
1317
+ data?: JSONValue;
1318
+ /**
1319
+ * Additional message-specific information added on the server via StreamData
1320
+ */
1321
+ annotations?: JSONValue[] | undefined;
1322
+ /**
1323
+ Tool invocations (that can be tool calls or tool results, depending on whether or not the invocation has finished)
1324
+ that the assistant made as part of this message.
1325
+
1326
+ @deprecated Use `parts` instead.
1327
+ */
1328
+ toolInvocations?: Array<ToolInvocation>;
1329
+ /**
1330
+ * The parts of the message. Use this for rendering the message in the UI.
1331
+ *
1332
+ * Assistant messages can have text, reasoning and tool invocation parts.
1333
+ * User messages can have text parts.
1334
+ */
1335
+ parts?: Array<TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart>;
1336
+ }
1337
+ /**
1338
+ * A text part of a message.
1339
+ */
1340
+ type TextUIPart = {
1341
+ type: 'text';
1342
+ /**
1343
+ * The text content.
1344
+ */
1345
+ text: string;
1346
+ };
1347
+ /**
1348
+ * A reasoning part of a message.
1349
+ */
1350
+ type ReasoningUIPart = {
1351
+ type: 'reasoning';
1352
+ /**
1353
+ * The reasoning text.
1354
+ */
1355
+ reasoning: string;
1356
+ details: Array<{
1357
+ type: 'text';
1358
+ text: string;
1359
+ signature?: string;
1360
+ } | {
1361
+ type: 'redacted';
1362
+ data: string;
1363
+ }>;
1364
+ };
1365
+ /**
1366
+ * A tool invocation part of a message.
1367
+ */
1368
+ type ToolInvocationUIPart = {
1369
+ type: 'tool-invocation';
1370
+ /**
1371
+ * The tool invocation.
1372
+ */
1373
+ toolInvocation: ToolInvocation;
1374
+ };
1375
+ /**
1376
+ * A source part of a message.
1377
+ */
1378
+ type SourceUIPart = {
1379
+ type: 'source';
1380
+ /**
1381
+ * The source.
1382
+ */
1383
+ source: LanguageModelV1Source;
1384
+ };
1385
+ /**
1386
+ A JSON value can be a string, number, boolean, object, array, or null.
1387
+ JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
1388
+ */
1389
+ type JSONValue = null | string | number | boolean | {
1390
+ [value: string]: JSONValue;
1391
+ } | Array<JSONValue>;
1392
+
1393
+ type DataStreamString = `${(typeof DataStreamStringPrefixes)[keyof typeof DataStreamStringPrefixes]}:${string}\n`;
1394
+ interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
1395
+ code: CODE;
1396
+ name: NAME;
1397
+ parse: (value: JSONValue) => {
1398
+ type: NAME;
1399
+ value: TYPE;
1400
+ };
1401
+ }
1402
+ declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "args" | "toolName">>, DataStreamPart<"b", "tool_call_streaming_start", {
1403
+ toolCallId: string;
1404
+ toolName: string;
1405
+ }>, DataStreamPart<"c", "tool_call_delta", {
1406
+ toolCallId: string;
1407
+ argsTextDelta: string;
1408
+ }>, DataStreamPart<"d", "finish_message", {
1409
+ finishReason: LanguageModelV1FinishReason;
1410
+ usage?: {
1411
+ promptTokens: number;
1412
+ completionTokens: number;
1413
+ };
1414
+ }>, DataStreamPart<"e", "finish_step", {
1415
+ isContinued: boolean;
1416
+ finishReason: LanguageModelV1FinishReason;
1417
+ usage?: {
1418
+ promptTokens: number;
1419
+ completionTokens: number;
1420
+ };
1421
+ }>, DataStreamPart<"f", "start_step", {
1422
+ messageId: string;
1423
+ }>, DataStreamPart<"g", "reasoning", string>, DataStreamPart<"h", "source", LanguageModelV1Source>, DataStreamPart<"i", "redacted_reasoning", {
1424
+ data: string;
1425
+ }>, DataStreamPart<"j", "reasoning_signature", {
1426
+ signature: string;
1427
+ }>];
1428
+ type DataStreamParts = (typeof dataStreamParts)[number];
1429
+ /**
1430
+ * The map of prefixes for data in the stream
1431
+ *
1432
+ * - 0: Text from the LLM response
1433
+ * - 1: (OpenAI) function_call responses
1434
+ * - 2: custom JSON added by the user using `Data`
1435
+ * - 6: (OpenAI) tool_call responses
1436
+ *
1437
+ * Example:
1438
+ * ```
1439
+ * 0:Vercel
1440
+ * 0:'s
1441
+ * 0: AI
1442
+ * 0: AI
1443
+ * 0: SDK
1444
+ * 0: is great
1445
+ * 0:!
1446
+ * 2: { "someJson": "value" }
1447
+ * 1: {"function_call": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}
1448
+ * 6: {"tool_call": {"id": "tool_0", "type": "function", "function": {"name": "get_current_weather", "arguments": "{\\n\\"location\\": \\"Charlottesville, Virginia\\",\\n\\"format\\": \\"celsius\\"\\n}"}}}
1449
+ *```
1450
+ */
1451
+ declare const DataStreamStringPrefixes: { [K in DataStreamParts["name"]]: (typeof dataStreamParts)[number]["code"]; };
1452
+
1453
+ /**
1454
+ Create a type from an object with all keys and nested keys set to optional.
1455
+ The helper supports normal objects and Zod schemas (which are resolved automatically).
1456
+ It always recurses into arrays.
1457
+
1458
+ Adopted from [type-fest](https://github.com/sindresorhus/type-fest/tree/main) PartialDeep.
1459
+ */
1460
+ type DeepPartial<T> = T extends z.ZodTypeAny ? DeepPartialInternal<z.infer<T>> : DeepPartialInternal<T>;
1461
+ 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;
1462
+ type PartialMap<KeyType, ValueType> = {} & Map<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
1463
+ type PartialSet<T> = {} & Set<DeepPartialInternal<T>>;
1464
+ type PartialReadonlyMap<KeyType, ValueType> = {} & ReadonlyMap<DeepPartialInternal<KeyType>, DeepPartialInternal<ValueType>>;
1465
+ type PartialReadonlySet<T> = {} & ReadonlySet<DeepPartialInternal<T>>;
1466
+ type PartialObject<ObjectType extends object> = {
1467
+ [KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
1468
+ };
1469
+
1470
+ /**
1471
+ * Used to mark schemas so we can support both Zod and custom schemas.
1472
+ */
1473
+ declare const schemaSymbol: unique symbol;
1474
+ type Schema<OBJECT = unknown> = Validator<OBJECT> & {
1475
+ /**
1476
+ * Used to mark schemas so we can support both Zod and custom schemas.
1477
+ */
1478
+ [schemaSymbol]: true;
1479
+ /**
1480
+ * Schema type for inference.
1481
+ */
1482
+ _type: OBJECT;
1483
+ /**
1484
+ * The JSON Schema for the schema. It is passed to the providers.
1485
+ */
1486
+ readonly jsonSchema: JSONSchema7;
1487
+ };
1488
+
1489
+ interface ExceptionWithCode {
1490
+ code: string | number;
1491
+ name?: string;
1492
+ message?: string;
1493
+ stack?: string;
1494
+ }
1495
+ interface ExceptionWithMessage {
1496
+ code?: string | number;
1497
+ message: string;
1498
+ name?: string;
1499
+ stack?: string;
1500
+ }
1501
+ interface ExceptionWithName {
1502
+ code?: string | number;
1503
+ message?: string;
1504
+ name: string;
1505
+ stack?: string;
1506
+ }
1507
+ /**
1508
+ * Defines Exception.
1509
+ *
1510
+ * string or an object with one of (message or name or code) and optional stack
1511
+ */
1512
+ declare type Exception = ExceptionWithCode | ExceptionWithMessage | ExceptionWithName | string;
1513
+
1514
+ /**
1515
+ * Defines High-Resolution Time.
1516
+ *
1517
+ * The first number, HrTime[0], is UNIX Epoch time in seconds since 00:00:00 UTC on 1 January 1970.
1518
+ * The second number, HrTime[1], represents the partial second elapsed since Unix Epoch time represented by first number in nanoseconds.
1519
+ * For example, 2021-01-01T12:30:10.150Z in UNIX Epoch time in milliseconds is represented as 1609504210150.
1520
+ * The first number is calculated by converting and truncating the Epoch time in milliseconds to seconds:
1521
+ * HrTime[0] = Math.trunc(1609504210150 / 1000) = 1609504210.
1522
+ * The second number is calculated by converting the digits after the decimal point of the subtraction, (1609504210150 / 1000) - HrTime[0], to nanoseconds:
1523
+ * HrTime[1] = Number((1609504210.150 - HrTime[0]).toFixed(9)) * 1e9 = 150000000.
1524
+ * This is represented in HrTime format as [1609504210, 150000000].
1525
+ */
1526
+ declare type HrTime = [number, number];
1527
+ /**
1528
+ * Defines TimeInput.
1529
+ *
1530
+ * hrtime, epoch milliseconds, performance.now() or Date
1531
+ */
1532
+ declare type TimeInput = HrTime | number | Date;
1533
+
1534
+ /**
1535
+ * Attributes is a map from string to attribute values.
1536
+ *
1537
+ * Note: only the own enumerable keys are counted as valid attribute keys.
1538
+ */
1539
+ interface Attributes {
1540
+ [attributeKey: string]: AttributeValue | undefined;
1541
+ }
1542
+ /**
1543
+ * Attribute values may be any non-nullish primitive value except an object.
1544
+ *
1545
+ * null or undefined attribute values are invalid and will result in undefined behavior.
1546
+ */
1547
+ declare type AttributeValue = string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>;
1548
+
1549
+ /**
1550
+ * @deprecated please use {@link Attributes}
1551
+ */
1552
+ declare type SpanAttributes = Attributes;
1553
+ /**
1554
+ * @deprecated please use {@link AttributeValue}
1555
+ */
1556
+ declare type SpanAttributeValue = AttributeValue;
1557
+
1558
+ interface TraceState {
1559
+ /**
1560
+ * Create a new TraceState which inherits from this TraceState and has the
1561
+ * given key set.
1562
+ * The new entry will always be added in the front of the list of states.
1563
+ *
1564
+ * @param key key of the TraceState entry.
1565
+ * @param value value of the TraceState entry.
1566
+ */
1567
+ set(key: string, value: string): TraceState;
1568
+ /**
1569
+ * Return a new TraceState which inherits from this TraceState but does not
1570
+ * contain the given key.
1571
+ *
1572
+ * @param key the key for the TraceState entry to be removed.
1573
+ */
1574
+ unset(key: string): TraceState;
1575
+ /**
1576
+ * Returns the value to which the specified key is mapped, or `undefined` if
1577
+ * this map contains no mapping for the key.
1578
+ *
1579
+ * @param key with which the specified value is to be associated.
1580
+ * @returns the value to which the specified key is mapped, or `undefined` if
1581
+ * this map contains no mapping for the key.
1582
+ */
1583
+ get(key: string): string | undefined;
1584
+ /**
1585
+ * Serializes the TraceState to a `list` as defined below. The `list` is a
1586
+ * series of `list-members` separated by commas `,`, and a list-member is a
1587
+ * key/value pair separated by an equals sign `=`. Spaces and horizontal tabs
1588
+ * surrounding `list-members` are ignored. There can be a maximum of 32
1589
+ * `list-members` in a `list`.
1590
+ *
1591
+ * @returns the serialized string.
1592
+ */
1593
+ serialize(): string;
1594
+ }
1595
+
1596
+ /**
1597
+ * A SpanContext represents the portion of a {@link Span} which must be
1598
+ * serialized and propagated along side of a {@link Baggage}.
1599
+ */
1600
+ interface SpanContext {
1601
+ /**
1602
+ * The ID of the trace that this span belongs to. It is worldwide unique
1603
+ * with practically sufficient probability by being made as 16 randomly
1604
+ * generated bytes, encoded as a 32 lowercase hex characters corresponding to
1605
+ * 128 bits.
1606
+ */
1607
+ traceId: string;
1608
+ /**
1609
+ * The ID of the Span. It is globally unique with practically sufficient
1610
+ * probability by being made as 8 randomly generated bytes, encoded as a 16
1611
+ * lowercase hex characters corresponding to 64 bits.
1612
+ */
1613
+ spanId: string;
1614
+ /**
1615
+ * Only true if the SpanContext was propagated from a remote parent.
1616
+ */
1617
+ isRemote?: boolean;
1618
+ /**
1619
+ * Trace flags to propagate.
1620
+ *
1621
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
1622
+ * sampled or not. When set, the least significant bit documents that the
1623
+ * caller may have recorded trace data. A caller who does not record trace
1624
+ * data out-of-band leaves this flag unset.
1625
+ *
1626
+ * see {@link TraceFlags} for valid flag values.
1627
+ */
1628
+ traceFlags: number;
1629
+ /**
1630
+ * Tracing-system-specific info to propagate.
1631
+ *
1632
+ * The tracestate field value is a `list` as defined below. The `list` is a
1633
+ * series of `list-members` separated by commas `,`, and a list-member is a
1634
+ * key/value pair separated by an equals sign `=`. Spaces and horizontal tabs
1635
+ * surrounding `list-members` are ignored. There can be a maximum of 32
1636
+ * `list-members` in a `list`.
1637
+ * More Info: https://www.w3.org/TR/trace-context/#tracestate-field
1638
+ *
1639
+ * Examples:
1640
+ * Single tracing system (generic format):
1641
+ * tracestate: rojo=00f067aa0ba902b7
1642
+ * Multiple tracing systems (with different formatting):
1643
+ * tracestate: rojo=00f067aa0ba902b7,congo=t61rcWkgMzE
1644
+ */
1645
+ traceState?: TraceState;
1646
+ }
1647
+
1648
+ interface SpanStatus {
1649
+ /** The status code of this message. */
1650
+ code: SpanStatusCode;
1651
+ /** A developer-facing error message. */
1652
+ message?: string;
1653
+ }
1654
+ /**
1655
+ * An enumeration of status codes.
1656
+ */
1657
+ declare enum SpanStatusCode {
1658
+ /**
1659
+ * The default status.
1660
+ */
1661
+ UNSET = 0,
1662
+ /**
1663
+ * The operation has been validated by an Application developer or
1664
+ * Operator to have completed successfully.
1665
+ */
1666
+ OK = 1,
1667
+ /**
1668
+ * The operation contains an error.
1669
+ */
1670
+ ERROR = 2
1671
+ }
1672
+
1673
+ /**
1674
+ * A pointer from the current {@link Span} to another span in the same trace or
1675
+ * in a different trace.
1676
+ * Few examples of Link usage.
1677
+ * 1. Batch Processing: A batch of elements may contain elements associated
1678
+ * with one or more traces/spans. Since there can only be one parent
1679
+ * SpanContext, Link is used to keep reference to SpanContext of all
1680
+ * elements in the batch.
1681
+ * 2. Public Endpoint: A SpanContext in incoming client request on a public
1682
+ * endpoint is untrusted from service provider perspective. In such case it
1683
+ * is advisable to start a new trace with appropriate sampling decision.
1684
+ * However, it is desirable to associate incoming SpanContext to new trace
1685
+ * initiated on service provider side so two traces (from Client and from
1686
+ * Service Provider) can be correlated.
1687
+ */
1688
+ interface Link {
1689
+ /** The {@link SpanContext} of a linked span. */
1690
+ context: SpanContext;
1691
+ /** A set of {@link SpanAttributes} on the link. */
1692
+ attributes?: SpanAttributes;
1693
+ /** Count of attributes of the link that were dropped due to collection limits */
1694
+ droppedAttributesCount?: number;
1695
+ }
1696
+
1697
+ /**
1698
+ * An interface that represents a span. A span represents a single operation
1699
+ * within a trace. Examples of span might include remote procedure calls or a
1700
+ * in-process function calls to sub-components. A Trace has a single, top-level
1701
+ * "root" Span that in turn may have zero or more child Spans, which in turn
1702
+ * may have children.
1703
+ *
1704
+ * Spans are created by the {@link Tracer.startSpan} method.
1705
+ */
1706
+ interface Span {
1707
+ /**
1708
+ * Returns the {@link SpanContext} object associated with this Span.
1709
+ *
1710
+ * Get an immutable, serializable identifier for this span that can be used
1711
+ * to create new child spans. Returned SpanContext is usable even after the
1712
+ * span ends.
1713
+ *
1714
+ * @returns the SpanContext object associated with this Span.
1715
+ */
1716
+ spanContext(): SpanContext;
1717
+ /**
1718
+ * Sets an attribute to the span.
1719
+ *
1720
+ * Sets a single Attribute with the key and value passed as arguments.
1721
+ *
1722
+ * @param key the key for this attribute.
1723
+ * @param value the value for this attribute. Setting a value null or
1724
+ * undefined is invalid and will result in undefined behavior.
1725
+ */
1726
+ setAttribute(key: string, value: SpanAttributeValue): this;
1727
+ /**
1728
+ * Sets attributes to the span.
1729
+ *
1730
+ * @param attributes the attributes that will be added.
1731
+ * null or undefined attribute values
1732
+ * are invalid and will result in undefined behavior.
1733
+ */
1734
+ setAttributes(attributes: SpanAttributes): this;
1735
+ /**
1736
+ * Adds an event to the Span.
1737
+ *
1738
+ * @param name the name of the event.
1739
+ * @param [attributesOrStartTime] the attributes that will be added; these are
1740
+ * associated with this event. Can be also a start time
1741
+ * if type is {@type TimeInput} and 3rd param is undefined
1742
+ * @param [startTime] start time of the event.
1743
+ */
1744
+ addEvent(name: string, attributesOrStartTime?: SpanAttributes | TimeInput, startTime?: TimeInput): this;
1745
+ /**
1746
+ * Adds a single link to the span.
1747
+ *
1748
+ * Links added after the creation will not affect the sampling decision.
1749
+ * It is preferred span links be added at span creation.
1750
+ *
1751
+ * @param link the link to add.
1752
+ */
1753
+ addLink(link: Link): this;
1754
+ /**
1755
+ * Adds multiple links to the span.
1756
+ *
1757
+ * Links added after the creation will not affect the sampling decision.
1758
+ * It is preferred span links be added at span creation.
1759
+ *
1760
+ * @param links the links to add.
1761
+ */
1762
+ addLinks(links: Link[]): this;
1763
+ /**
1764
+ * Sets a status to the span. If used, this will override the default Span
1765
+ * status. Default is {@link SpanStatusCode.UNSET}. SetStatus overrides the value
1766
+ * of previous calls to SetStatus on the Span.
1767
+ *
1768
+ * @param status the SpanStatus to set.
1769
+ */
1770
+ setStatus(status: SpanStatus): this;
1771
+ /**
1772
+ * Updates the Span name.
1773
+ *
1774
+ * This will override the name provided via {@link Tracer.startSpan}.
1775
+ *
1776
+ * Upon this update, any sampling behavior based on Span name will depend on
1777
+ * the implementation.
1778
+ *
1779
+ * @param name the Span name.
1780
+ */
1781
+ updateName(name: string): this;
1782
+ /**
1783
+ * Marks the end of Span execution.
1784
+ *
1785
+ * Call to End of a Span MUST not have any effects on child spans. Those may
1786
+ * still be running and can be ended later.
1787
+ *
1788
+ * Do not return `this`. The Span generally should not be used after it
1789
+ * is ended so chaining is not desired in this context.
1790
+ *
1791
+ * @param [endTime] the time to set as Span's end time. If not provided,
1792
+ * use the current time as the span's end time.
1793
+ */
1794
+ end(endTime?: TimeInput): void;
1795
+ /**
1796
+ * Returns the flag whether this span will be recorded.
1797
+ *
1798
+ * @returns true if this Span is active and recording information like events
1799
+ * with the `AddEvent` operation and attributes using `setAttributes`.
1800
+ */
1801
+ isRecording(): boolean;
1802
+ /**
1803
+ * Sets exception as a span event
1804
+ * @param exception the exception the only accepted values are string or Error
1805
+ * @param [time] the time to set as Span's event time. If not provided,
1806
+ * use the current time.
1807
+ */
1808
+ recordException(exception: Exception, time?: TimeInput): void;
1809
+ }
1810
+
1811
+ interface Context {
1812
+ /**
1813
+ * Get a value from the context.
1814
+ *
1815
+ * @param key key which identifies a context value
1816
+ */
1817
+ getValue(key: symbol): unknown;
1818
+ /**
1819
+ * Create a new context which inherits from this context and has
1820
+ * the given key set to the given value.
1821
+ *
1822
+ * @param key context key for which to set the value
1823
+ * @param value value to set for the given key
1824
+ */
1825
+ setValue(key: symbol, value: unknown): Context;
1826
+ /**
1827
+ * Return a new context which inherits from this context but does
1828
+ * not contain a value for the given key.
1829
+ *
1830
+ * @param key context key for which to clear a value
1831
+ */
1832
+ deleteValue(key: symbol): Context;
1833
+ }
1834
+
1835
+ declare enum SpanKind {
1836
+ /** Default value. Indicates that the span is used internally. */
1837
+ INTERNAL = 0,
1838
+ /**
1839
+ * Indicates that the span covers server-side handling of an RPC or other
1840
+ * remote request.
1841
+ */
1842
+ SERVER = 1,
1843
+ /**
1844
+ * Indicates that the span covers the client-side wrapper around an RPC or
1845
+ * other remote request.
1846
+ */
1847
+ CLIENT = 2,
1848
+ /**
1849
+ * Indicates that the span describes producer sending a message to a
1850
+ * broker. Unlike client and server, there is no direct critical path latency
1851
+ * relationship between producer and consumer spans.
1852
+ */
1853
+ PRODUCER = 3,
1854
+ /**
1855
+ * Indicates that the span describes consumer receiving a message from a
1856
+ * broker. Unlike client and server, there is no direct critical path latency
1857
+ * relationship between producer and consumer spans.
1858
+ */
1859
+ CONSUMER = 4
1860
+ }
1861
+
1862
+ /**
1863
+ * Options needed for span creation
1864
+ */
1865
+ interface SpanOptions {
1866
+ /**
1867
+ * The SpanKind of a span
1868
+ * @default {@link SpanKind.INTERNAL}
1869
+ */
1870
+ kind?: SpanKind;
1871
+ /** A span's attributes */
1872
+ attributes?: SpanAttributes;
1873
+ /** {@link Link}s span to other spans */
1874
+ links?: Link[];
1875
+ /** A manually specified start time for the created `Span` object. */
1876
+ startTime?: TimeInput;
1877
+ /** The new span should be a root span. (Ignore parent from context). */
1878
+ root?: boolean;
1879
+ }
1880
+
1881
+ /**
1882
+ * Tracer provides an interface for creating {@link Span}s.
1883
+ */
1884
+ interface Tracer {
1885
+ /**
1886
+ * Starts a new {@link Span}. Start the span without setting it on context.
1887
+ *
1888
+ * This method do NOT modify the current Context.
1889
+ *
1890
+ * @param name The name of the span
1891
+ * @param [options] SpanOptions used for span creation
1892
+ * @param [context] Context to use to extract parent
1893
+ * @returns Span The newly created span
1894
+ * @example
1895
+ * const span = tracer.startSpan('op');
1896
+ * span.setAttribute('key', 'value');
1897
+ * span.end();
1898
+ */
1899
+ startSpan(name: string, options?: SpanOptions, context?: Context): Span;
1900
+ /**
1901
+ * Starts a new {@link Span} and calls the given function passing it the
1902
+ * created span as first argument.
1903
+ * Additionally the new span gets set in context and this context is activated
1904
+ * for the duration of the function call.
1905
+ *
1906
+ * @param name The name of the span
1907
+ * @param [options] SpanOptions used for span creation
1908
+ * @param [context] Context to use to extract parent
1909
+ * @param fn function called in the context of the span and receives the newly created span as an argument
1910
+ * @returns return value of fn
1911
+ * @example
1912
+ * const something = tracer.startActiveSpan('op', span => {
1913
+ * try {
1914
+ * do some work
1915
+ * span.setStatus({code: SpanStatusCode.OK});
1916
+ * return something;
1917
+ * } catch (err) {
1918
+ * span.setStatus({
1919
+ * code: SpanStatusCode.ERROR,
1920
+ * message: err.message,
1921
+ * });
1922
+ * throw err;
1923
+ * } finally {
1924
+ * span.end();
1925
+ * }
1926
+ * });
1927
+ *
1928
+ * @example
1929
+ * const span = tracer.startActiveSpan('op', span => {
1930
+ * try {
1931
+ * do some work
1932
+ * return span;
1933
+ * } catch (err) {
1934
+ * span.setStatus({
1935
+ * code: SpanStatusCode.ERROR,
1936
+ * message: err.message,
1937
+ * });
1938
+ * throw err;
1939
+ * }
1940
+ * });
1941
+ * do some more work
1942
+ * span.end();
1943
+ */
1944
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, fn: F): ReturnType<F>;
1945
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, fn: F): ReturnType<F>;
1946
+ startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, context: Context, fn: F): ReturnType<F>;
1947
+ }
1948
+
1949
+ /**
1950
+ Language model that is used by the AI SDK Core functions.
1951
+ */
1952
+ type LanguageModel = LanguageModelV1;
1953
+ /**
1954
+ Reason why a language model finished generating a response.
1955
+
1956
+ Can be one of the following:
1957
+ - `stop`: model generated stop sequence
1958
+ - `length`: model generated maximum number of tokens
1959
+ - `content-filter`: content filter violation stopped the model
1960
+ - `tool-calls`: model triggered tool calls
1961
+ - `error`: model stopped because of an error
1962
+ - `other`: model stopped for other reasons
1963
+ */
1964
+ type FinishReason = LanguageModelV1FinishReason$1;
1965
+ /**
1966
+ Log probabilities for each token and its top log probabilities.
1967
+
1968
+ @deprecated Will become a provider extension in the future.
1969
+ */
1970
+ type LogProbs = LanguageModelV1LogProbs;
1971
+ /**
1972
+ Warning from the model provider for this call. The call will proceed, but e.g.
1973
+ some settings might not be supported, which can lead to suboptimal results.
1974
+ */
1975
+ type CallWarning = LanguageModelV1CallWarning;
1976
+ /**
1977
+ A source that has been used as input to generate the response.
1978
+ */
1979
+ type Source = LanguageModelV1Source$1;
1980
+ /**
1981
+ Tool choice for the generation. It supports the following settings:
1982
+
1983
+ - `auto` (default): the model can choose whether and which tools to call.
1984
+ - `required`: the model must call a tool. It can choose which tool to call.
1985
+ - `none`: the model must not call tools
1986
+ - `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
1987
+ */
1988
+ type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
1989
+ type: 'tool';
1990
+ toolName: keyof TOOLS;
1991
+ };
1992
+
1993
+ interface DataStreamWriter {
1994
+ /**
1995
+ * Appends a data part to the stream.
1996
+ */
1997
+ write(data: DataStreamString): void;
1998
+ /**
1999
+ * Appends a data part to the stream.
2000
+ */
2001
+ writeData(value: JSONValue$2): void;
2002
+ /**
2003
+ * Appends a message annotation to the stream.
2004
+ */
2005
+ writeMessageAnnotation(value: JSONValue$2): void;
2006
+ /**
2007
+ * Appends a source part to the stream.
2008
+ */
2009
+ writeSource(source: Source): void;
2010
+ /**
2011
+ * Merges the contents of another stream to this stream.
2012
+ */
2013
+ merge(stream: ReadableStream<DataStreamString>): void;
2014
+ /**
2015
+ * Error handler that is used by the data stream writer.
2016
+ * This is intended for forwarding when merging streams
2017
+ * to prevent duplicated error masking.
2018
+ */
2019
+ onError: ((error: unknown) => string) | undefined;
2020
+ }
2021
+
2022
+ /**
2023
+ * Telemetry configuration.
2024
+ */
2025
+ type TelemetrySettings = {
2026
+ /**
2027
+ * Enable or disable telemetry. Disabled by default while experimental.
2028
+ */
2029
+ isEnabled?: boolean;
2030
+ /**
2031
+ * Enable or disable input recording. Enabled by default.
2032
+ *
2033
+ * You might want to disable input recording to avoid recording sensitive
2034
+ * information, to reduce data transfers, or to increase performance.
2035
+ */
2036
+ recordInputs?: boolean;
2037
+ /**
2038
+ * Enable or disable output recording. Enabled by default.
2039
+ *
2040
+ * You might want to disable output recording to avoid recording sensitive
2041
+ * information, to reduce data transfers, or to increase performance.
2042
+ */
2043
+ recordOutputs?: boolean;
2044
+ /**
2045
+ * Identifier for this function. Used to group telemetry data by function.
2046
+ */
2047
+ functionId?: string;
2048
+ /**
2049
+ * Additional information to include in the telemetry data.
2050
+ */
2051
+ metadata?: Record<string, AttributeValue>;
2052
+ /**
2053
+ * A custom tracer to use for the telemetry data.
2054
+ */
2055
+ tracer?: Tracer;
2056
+ };
2057
+
2058
+ /**
2059
+ Embedding model that is used by the AI SDK Core functions.
2060
+ */
2061
+ type EmbeddingModel<VALUE> = EmbeddingModelV1<VALUE>;
2062
+
2063
+ type LanguageModelRequestMetadata = {
2064
+ /**
2065
+ Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).
2066
+ */
2067
+ body?: string;
2068
+ };
2069
+
2070
+ type LanguageModelResponseMetadata = {
2071
+ /**
2072
+ ID for the generated response.
2073
+ */
2074
+ id: string;
2075
+ /**
2076
+ Timestamp for the start of the generated response.
2077
+ */
2078
+ timestamp: Date;
2079
+ /**
2080
+ The ID of the response model that was used to generate the response.
2081
+ */
2082
+ modelId: string;
2083
+ /**
2084
+ Response headers (available only for providers that use HTTP requests).
2085
+ */
2086
+ headers?: Record<string, string>;
2087
+ };
2088
+
2089
+ /**
2090
+ Additional provider-specific metadata that is returned from the provider.
2091
+
2092
+ This is needed to enable provider-specific functionality that can be
2093
+ fully encapsulated in the provider.
2094
+ */
2095
+ type ProviderMetadata = LanguageModelV1ProviderMetadata$1;
2096
+ /**
2097
+ Additional provider-specific options.
2098
+
2099
+ They are passed through to the provider from the AI SDK and enable
2100
+ provider-specific functionality that can be fully encapsulated in the provider.
2101
+ */
2102
+ type ProviderOptions = LanguageModelV1ProviderMetadata$1;
2103
+
2104
+ /**
2105
+ Represents the number of tokens used in a prompt and completion.
2106
+ */
2107
+ type LanguageModelUsage = {
2108
+ /**
2109
+ The number of tokens used in the prompt.
2110
+ */
2111
+ promptTokens: number;
2112
+ /**
2113
+ The number of tokens used in the completion.
2114
+ */
2115
+ completionTokens: number;
2116
+ /**
2117
+ The total number of tokens used (promptTokens + completionTokens).
2118
+ */
2119
+ totalTokens: number;
2120
+ };
2121
+
2122
+ type CallSettings = {
2123
+ /**
2124
+ Maximum number of tokens to generate.
2125
+ */
2126
+ maxTokens?: number;
2127
+ /**
2128
+ Temperature setting. This is a number between 0 (almost no randomness) and
2129
+ 1 (very random).
2130
+
2131
+ It is recommended to set either `temperature` or `topP`, but not both.
2132
+
2133
+ @default 0
2134
+ */
2135
+ temperature?: number;
2136
+ /**
2137
+ Nucleus sampling. This is a number between 0 and 1.
2138
+
2139
+ E.g. 0.1 would mean that only tokens with the top 10% probability mass
2140
+ are considered.
2141
+
2142
+ It is recommended to set either `temperature` or `topP`, but not both.
2143
+ */
2144
+ topP?: number;
2145
+ /**
2146
+ Only sample from the top K options for each subsequent token.
2147
+
2148
+ Used to remove "long tail" low probability responses.
2149
+ Recommended for advanced use cases only. You usually only need to use temperature.
2150
+ */
2151
+ topK?: number;
2152
+ /**
2153
+ Presence penalty setting. It affects the likelihood of the model to
2154
+ repeat information that is already in the prompt.
2155
+
2156
+ The presence penalty is a number between -1 (increase repetition)
2157
+ and 1 (maximum penalty, decrease repetition). 0 means no penalty.
2158
+ */
2159
+ presencePenalty?: number;
2160
+ /**
2161
+ Frequency penalty setting. It affects the likelihood of the model
2162
+ to repeatedly use the same words or phrases.
2163
+
2164
+ The frequency penalty is a number between -1 (increase repetition)
2165
+ and 1 (maximum penalty, decrease repetition). 0 means no penalty.
2166
+ */
2167
+ frequencyPenalty?: number;
2168
+ /**
2169
+ Stop sequences.
2170
+ If set, the model will stop generating text when one of the stop sequences is generated.
2171
+ Providers may have limits on the number of stop sequences.
2172
+ */
2173
+ stopSequences?: string[];
2174
+ /**
2175
+ The seed (integer) to use for random sampling. If set and supported
2176
+ by the model, calls will generate deterministic results.
2177
+ */
2178
+ seed?: number;
2179
+ /**
2180
+ Maximum number of retries. Set to 0 to disable retries.
2181
+
2182
+ @default 2
2183
+ */
2184
+ maxRetries?: number;
2185
+ /**
2186
+ Abort signal.
2187
+ */
2188
+ abortSignal?: AbortSignal;
2189
+ /**
2190
+ Additional HTTP headers to be sent with the request.
2191
+ Only applicable for HTTP-based providers.
2192
+ */
2193
+ headers?: Record<string, string | undefined>;
2194
+ };
2195
+
2196
+ /**
2197
+ Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
2198
+ */
2199
+ type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
2200
+
2201
+ type ToolResultContent = Array<{
2202
+ type: 'text';
2203
+ text: string;
2204
+ } | {
2205
+ type: 'image';
2206
+ data: string;
2207
+ mimeType?: string;
2208
+ }>;
2209
+
2210
+ /**
2211
+ Text content part of a prompt. It contains a string of text.
2212
+ */
2213
+ interface TextPart {
2214
+ type: 'text';
2215
+ /**
2216
+ The text content.
2217
+ */
2218
+ text: string;
2219
+ /**
2220
+ Additional provider-specific metadata. They are passed through
2221
+ to the provider from the AI SDK and enable provider-specific
2222
+ functionality that can be fully encapsulated in the provider.
2223
+ */
2224
+ providerOptions?: ProviderOptions;
2225
+ /**
2226
+ @deprecated Use `providerOptions` instead.
2227
+ */
2228
+ experimental_providerMetadata?: ProviderMetadata;
2229
+ }
2230
+ /**
2231
+ Image content part of a prompt. It contains an image.
2232
+ */
2233
+ interface ImagePart {
2234
+ type: 'image';
2235
+ /**
2236
+ Image data. Can either be:
2237
+
2238
+ - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
2239
+ - URL: a URL that points to the image
2240
+ */
2241
+ image: DataContent | URL;
2242
+ /**
2243
+ Optional mime type of the image.
2244
+ */
2245
+ mimeType?: string;
2246
+ /**
2247
+ Additional provider-specific metadata. They are passed through
2248
+ to the provider from the AI SDK and enable provider-specific
2249
+ functionality that can be fully encapsulated in the provider.
2250
+ */
2251
+ providerOptions?: ProviderOptions;
2252
+ /**
2253
+ @deprecated Use `providerOptions` instead.
2254
+ */
2255
+ experimental_providerMetadata?: ProviderMetadata;
2256
+ }
2257
+ /**
2258
+ File content part of a prompt. It contains a file.
2259
+ */
2260
+ interface FilePart {
2261
+ type: 'file';
2262
+ /**
2263
+ File data. Can either be:
2264
+
2265
+ - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
2266
+ - URL: a URL that points to the image
2267
+ */
2268
+ data: DataContent | URL;
2269
+ /**
2270
+ Optional filename of the file.
2271
+ */
2272
+ filename?: string;
2273
+ /**
2274
+ Mime type of the file.
2275
+ */
2276
+ mimeType: string;
2277
+ /**
2278
+ Additional provider-specific metadata. They are passed through
2279
+ to the provider from the AI SDK and enable provider-specific
2280
+ functionality that can be fully encapsulated in the provider.
2281
+ */
2282
+ providerOptions?: ProviderOptions;
2283
+ /**
2284
+ @deprecated Use `providerOptions` instead.
2285
+ */
2286
+ experimental_providerMetadata?: ProviderMetadata;
2287
+ }
2288
+ /**
2289
+ * Reasoning content part of a prompt. It contains a reasoning.
2290
+ */
2291
+ interface ReasoningPart {
2292
+ type: 'reasoning';
2293
+ /**
2294
+ The reasoning text.
2295
+ */
2296
+ text: string;
2297
+ /**
2298
+ An optional signature for verifying that the reasoning originated from the model.
2299
+ */
2300
+ signature?: string;
2301
+ /**
2302
+ Additional provider-specific metadata. They are passed through
2303
+ to the provider from the AI SDK and enable provider-specific
2304
+ functionality that can be fully encapsulated in the provider.
2305
+ */
2306
+ providerOptions?: ProviderOptions;
2307
+ /**
2308
+ @deprecated Use `providerOptions` instead.
2309
+ */
2310
+ experimental_providerMetadata?: ProviderMetadata;
2311
+ }
2312
+ /**
2313
+ Redacted reasoning content part of a prompt.
2314
+ */
2315
+ interface RedactedReasoningPart {
2316
+ type: 'redacted-reasoning';
2317
+ /**
2318
+ Redacted reasoning data.
2319
+ */
2320
+ data: string;
2321
+ /**
2322
+ Additional provider-specific metadata. They are passed through
2323
+ to the provider from the AI SDK and enable provider-specific
2324
+ functionality that can be fully encapsulated in the provider.
2325
+ */
2326
+ providerOptions?: ProviderOptions;
2327
+ /**
2328
+ @deprecated Use `providerOptions` instead.
2329
+ */
2330
+ experimental_providerMetadata?: ProviderMetadata;
2331
+ }
2332
+ /**
2333
+ Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
2334
+ */
2335
+ interface ToolCallPart {
2336
+ type: 'tool-call';
2337
+ /**
2338
+ ID of the tool call. This ID is used to match the tool call with the tool result.
2339
+ */
2340
+ toolCallId: string;
2341
+ /**
2342
+ Name of the tool that is being called.
2343
+ */
2344
+ toolName: string;
2345
+ /**
2346
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
2347
+ */
2348
+ args: unknown;
2349
+ /**
2350
+ Additional provider-specific metadata. They are passed through
2351
+ to the provider from the AI SDK and enable provider-specific
2352
+ functionality that can be fully encapsulated in the provider.
2353
+ */
2354
+ providerOptions?: ProviderOptions;
2355
+ /**
2356
+ @deprecated Use `providerOptions` instead.
2357
+ */
2358
+ experimental_providerMetadata?: ProviderMetadata;
2359
+ }
2360
+ /**
2361
+ Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
2362
+ */
2363
+ interface ToolResultPart {
2364
+ type: 'tool-result';
2365
+ /**
2366
+ ID of the tool call that this result is associated with.
2367
+ */
2368
+ toolCallId: string;
2369
+ /**
2370
+ Name of the tool that generated this result.
2371
+ */
2372
+ toolName: string;
2373
+ /**
2374
+ Result of the tool call. This is a JSON-serializable object.
2375
+ */
2376
+ result: unknown;
2377
+ /**
2378
+ Multi-part content of the tool result. Only for tools that support multipart results.
2379
+ */
2380
+ experimental_content?: ToolResultContent;
2381
+ /**
2382
+ Optional flag if the result is an error or an error message.
2383
+ */
2384
+ isError?: boolean;
2385
+ /**
2386
+ Additional provider-specific metadata. They are passed through
2387
+ to the provider from the AI SDK and enable provider-specific
2388
+ functionality that can be fully encapsulated in the provider.
2389
+ */
2390
+ providerOptions?: ProviderOptions;
2391
+ /**
2392
+ @deprecated Use `providerOptions` instead.
2393
+ */
2394
+ experimental_providerMetadata?: ProviderMetadata;
2395
+ }
2396
+
2397
+ /**
2398
+ A system message. It can contain system information.
2399
+
2400
+ Note: using the "system" part of the prompt is strongly preferred
2401
+ to increase the resilience against prompt injection attacks,
2402
+ and because not all providers support several system messages.
2403
+ */
2404
+ type CoreSystemMessage = {
2405
+ role: 'system';
2406
+ content: string;
2407
+ /**
2408
+ Additional provider-specific metadata. They are passed through
2409
+ to the provider from the AI SDK and enable provider-specific
2410
+ functionality that can be fully encapsulated in the provider.
2411
+ */
2412
+ providerOptions?: ProviderOptions;
2413
+ /**
2414
+ @deprecated Use `providerOptions` instead.
2415
+ */
2416
+ experimental_providerMetadata?: ProviderMetadata;
2417
+ };
2418
+ /**
2419
+ A user message. It can contain text or a combination of text and images.
2420
+ */
2421
+ type CoreUserMessage = {
2422
+ role: 'user';
2423
+ content: UserContent;
2424
+ /**
2425
+ Additional provider-specific metadata. They are passed through
2426
+ to the provider from the AI SDK and enable provider-specific
2427
+ functionality that can be fully encapsulated in the provider.
2428
+ */
2429
+ providerOptions?: ProviderOptions;
2430
+ /**
2431
+ @deprecated Use `providerOptions` instead.
2432
+ */
2433
+ experimental_providerMetadata?: ProviderMetadata;
2434
+ };
2435
+ /**
2436
+ Content of a user message. It can be a string or an array of text and image parts.
2437
+ */
2438
+ type UserContent = string | Array<TextPart | ImagePart | FilePart>;
2439
+ /**
2440
+ An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
2441
+ */
2442
+ type CoreAssistantMessage = {
2443
+ role: 'assistant';
2444
+ content: AssistantContent;
2445
+ /**
2446
+ Additional provider-specific metadata. They are passed through
2447
+ to the provider from the AI SDK and enable provider-specific
2448
+ functionality that can be fully encapsulated in the provider.
2449
+ */
2450
+ providerOptions?: ProviderOptions;
2451
+ /**
2452
+ @deprecated Use `providerOptions` instead.
2453
+ */
2454
+ experimental_providerMetadata?: ProviderMetadata;
2455
+ };
2456
+ /**
2457
+ Content of an assistant message. It can be a string or an array of text and tool call parts.
2458
+ */
2459
+ type AssistantContent = string | Array<TextPart | ReasoningPart | RedactedReasoningPart | ToolCallPart>;
2460
+ /**
2461
+ A tool message. It contains the result of one or more tool calls.
2462
+ */
2463
+ type CoreToolMessage = {
2464
+ role: 'tool';
2465
+ content: ToolContent;
2466
+ /**
2467
+ Additional provider-specific metadata. They are passed through
2468
+ to the provider from the AI SDK and enable provider-specific
2469
+ functionality that can be fully encapsulated in the provider.
2470
+ */
2471
+ providerOptions?: ProviderOptions;
2472
+ /**
2473
+ @deprecated Use `providerOptions` instead.
2474
+ */
2475
+ experimental_providerMetadata?: ProviderMetadata;
2476
+ };
2477
+ /**
2478
+ Content of a tool message. It is an array of tool result parts.
2479
+ */
2480
+ type ToolContent = Array<ToolResultPart>;
2481
+ /**
2482
+ A message that can be used in the `messages` field of a prompt.
2483
+ It can be a user message, an assistant message, or a tool message.
2484
+ */
2485
+ type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
2486
+
2487
+ /**
2488
+ Prompt part of the AI function options.
2489
+ It contains a system message, a simple text prompt, or a list of messages.
2490
+ */
2491
+ type Prompt = {
2492
+ /**
2493
+ System message to include in the prompt. Can be used with `prompt` or `messages`.
2494
+ */
2495
+ system?: string;
2496
+ /**
2497
+ A simple text prompt. You can either use `prompt` or `messages` but not both.
2498
+ */
2499
+ prompt?: string;
2500
+ /**
2501
+ A list of messages. You can either use `prompt` or `messages` but not both.
2502
+ */
2503
+ messages?: Array<CoreMessage> | Array<Omit<Message, 'id'>>;
2504
+ };
2505
+
2506
+ /**
2507
+ The result of a `generateObject` call.
2508
+ */
2509
+ interface GenerateObjectResult<OBJECT> {
2510
+ /**
2511
+ The generated object (typed according to the schema).
2512
+ */
2513
+ readonly object: OBJECT;
2514
+ /**
2515
+ The reason why the generation finished.
2516
+ */
2517
+ readonly finishReason: FinishReason;
2518
+ /**
2519
+ The token usage of the generated text.
2520
+ */
2521
+ readonly usage: LanguageModelUsage;
2522
+ /**
2523
+ Warnings from the model provider (e.g. unsupported settings).
2524
+ */
2525
+ readonly warnings: CallWarning[] | undefined;
2526
+ /**
2527
+ Additional request information.
2528
+ */
2529
+ readonly request: LanguageModelRequestMetadata;
2530
+ /**
2531
+ Additional response information.
2532
+ */
2533
+ readonly response: LanguageModelResponseMetadata & {
2534
+ /**
2535
+ Response body (available only for providers that use HTTP requests).
2536
+ */
2537
+ body?: unknown;
2538
+ };
2539
+ /**
2540
+ Logprobs for the completion.
2541
+ `undefined` if the mode does not support logprobs or if was not enabled.
2542
+
2543
+ @deprecated Will become a provider extension in the future.
2544
+ */
2545
+ readonly logprobs: LogProbs | undefined;
2546
+ /**
2547
+ Additional provider-specific metadata. They are passed through
2548
+ from the provider to the AI SDK and enable provider-specific
2549
+ results that can be fully encapsulated in the provider.
2550
+ */
2551
+ readonly providerMetadata: ProviderMetadata | undefined;
2552
+ /**
2553
+ @deprecated Use `providerMetadata` instead.
2554
+ */
2555
+ readonly experimental_providerMetadata: ProviderMetadata | undefined;
2556
+ /**
2557
+ Converts the object to a JSON response.
2558
+ The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
2559
+ */
2560
+ toJsonResponse(init?: ResponseInit): Response;
2561
+ }
2562
+
2563
+ /**
2564
+ A function that attempts to repair the raw output of the mode
2565
+ to enable JSON parsing.
2566
+
2567
+ Should return the repaired text or null if the text cannot be repaired.
2568
+ */
2569
+ type RepairTextFunction = (options: {
2570
+ text: string;
2571
+ error: JSONParseError | TypeValidationError;
2572
+ }) => Promise<string | null>;
2573
+ /**
2574
+ Generate a structured, typed object for a given prompt and schema using a language model.
2575
+
2576
+ This function does not stream the output. If you want to stream the output, use `streamObject` instead.
2577
+
2578
+ @returns
2579
+ A result object that contains the generated object, the finish reason, the token usage, and additional information.
2580
+ */
2581
+ declare function generateObject<OBJECT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
2582
+ output?: 'object' | undefined;
2583
+ /**
2584
+ The language model to use.
2585
+ */
2586
+ model: LanguageModel;
2587
+ /**
2588
+ The schema of the object that the model should generate.
2589
+ */
2590
+ schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT>;
2591
+ /**
2592
+ Optional name of the output that should be generated.
2593
+ Used by some providers for additional LLM guidance, e.g.
2594
+ via tool or schema name.
2595
+ */
2596
+ schemaName?: string;
2597
+ /**
2598
+ Optional description of the output that should be generated.
2599
+ Used by some providers for additional LLM guidance, e.g.
2600
+ via tool or schema description.
2601
+ */
2602
+ schemaDescription?: string;
2603
+ /**
2604
+ The mode to use for object generation.
2605
+
2606
+ The schema is converted into a JSON schema and used in one of the following ways
2607
+
2608
+ - 'auto': The provider will choose the best mode for the model.
2609
+ - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
2610
+ - 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
2611
+
2612
+ Please note that most providers do not support all modes.
2613
+
2614
+ Default and recommended: 'auto' (best mode for the model).
2615
+ */
2616
+ mode?: 'auto' | 'json' | 'tool';
2617
+ /**
2618
+ A function that attempts to repair the raw output of the mode
2619
+ to enable JSON parsing.
2620
+ */
2621
+ experimental_repairText?: RepairTextFunction;
2622
+ /**
2623
+ Optional telemetry configuration (experimental).
2624
+ */
2625
+ experimental_telemetry?: TelemetrySettings;
2626
+ /**
2627
+ Additional provider-specific options. They are passed through
2628
+ to the provider from the AI SDK and enable provider-specific
2629
+ functionality that can be fully encapsulated in the provider.
2630
+ */
2631
+ providerOptions?: ProviderOptions;
2632
+ /**
2633
+ @deprecated Use `providerOptions` instead.
2634
+ */
2635
+ experimental_providerMetadata?: ProviderMetadata;
2636
+ /**
2637
+ * Internal. For test use only. May change without notice.
2638
+ */
2639
+ _internal?: {
2640
+ generateId?: () => string;
2641
+ currentDate?: () => Date;
2642
+ };
2643
+ }): Promise<GenerateObjectResult<OBJECT>>;
2644
+ /**
2645
+ Generate an array with structured, typed elements for a given prompt and element schema using a language model.
2646
+
2647
+ This function does not stream the output. If you want to stream the output, use `streamObject` instead.
2648
+
2649
+ @return
2650
+ A result object that contains the generated object, the finish reason, the token usage, and additional information.
2651
+ */
2652
+ declare function generateObject<ELEMENT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
2653
+ output: 'array';
2654
+ /**
2655
+ The language model to use.
2656
+ */
2657
+ model: LanguageModel;
2658
+ /**
2659
+ The element schema of the array that the model should generate.
2660
+ */
2661
+ schema: z.Schema<ELEMENT, z.ZodTypeDef, any> | Schema<ELEMENT>;
2662
+ /**
2663
+ Optional name of the array that should be generated.
2664
+ Used by some providers for additional LLM guidance, e.g.
2665
+ via tool or schema name.
2666
+ */
2667
+ schemaName?: string;
2668
+ /**
2669
+ Optional description of the array that should be generated.
2670
+ Used by some providers for additional LLM guidance, e.g.
2671
+ via tool or schema description.
2672
+ */
2673
+ schemaDescription?: string;
2674
+ /**
2675
+ The mode to use for object generation.
2676
+
2677
+ The schema is converted into a JSON schema and used in one of the following ways
2678
+
2679
+ - 'auto': The provider will choose the best mode for the model.
2680
+ - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
2681
+ - 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
2682
+
2683
+ Please note that most providers do not support all modes.
2684
+
2685
+ Default and recommended: 'auto' (best mode for the model).
2686
+ */
2687
+ mode?: 'auto' | 'json' | 'tool';
2688
+ /**
2689
+ A function that attempts to repair the raw output of the mode
2690
+ to enable JSON parsing.
2691
+ */
2692
+ experimental_repairText?: RepairTextFunction;
2693
+ /**
2694
+ Optional telemetry configuration (experimental).
2695
+ */
2696
+ experimental_telemetry?: TelemetrySettings;
2697
+ /**
2698
+ Additional provider-specific options. They are passed through
2699
+ to the provider from the AI SDK and enable provider-specific
2700
+ functionality that can be fully encapsulated in the provider.
2701
+ */
2702
+ providerOptions?: ProviderOptions;
2703
+ /**
2704
+ @deprecated Use `providerOptions` instead.
2705
+ */
2706
+ experimental_providerMetadata?: ProviderMetadata;
2707
+ /**
2708
+ * Internal. For test use only. May change without notice.
2709
+ */
2710
+ _internal?: {
2711
+ generateId?: () => string;
2712
+ currentDate?: () => Date;
2713
+ };
2714
+ }): Promise<GenerateObjectResult<Array<ELEMENT>>>;
2715
+ /**
2716
+ Generate a value from an enum (limited list of string values) using a language model.
2717
+
2718
+ This function does not stream the output.
2719
+
2720
+ @return
2721
+ A result object that contains the generated value, the finish reason, the token usage, and additional information.
2722
+ */
2723
+ declare function generateObject<ENUM extends string>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
2724
+ output: 'enum';
2725
+ /**
2726
+ The language model to use.
2727
+ */
2728
+ model: LanguageModel;
2729
+ /**
2730
+ The enum values that the model should use.
2731
+ */
2732
+ enum: Array<ENUM>;
2733
+ /**
2734
+ The mode to use for object generation.
2735
+
2736
+ The schema is converted into a JSON schema and used in one of the following ways
2737
+
2738
+ - 'auto': The provider will choose the best mode for the model.
2739
+ - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
2740
+ - 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
2741
+
2742
+ Please note that most providers do not support all modes.
2743
+
2744
+ Default and recommended: 'auto' (best mode for the model).
2745
+ */
2746
+ mode?: 'auto' | 'json' | 'tool';
2747
+ /**
2748
+ A function that attempts to repair the raw output of the mode
2749
+ to enable JSON parsing.
2750
+ */
2751
+ experimental_repairText?: RepairTextFunction;
2752
+ /**
2753
+ Optional telemetry configuration (experimental).
2754
+ */
2755
+ experimental_telemetry?: TelemetrySettings;
2756
+ /**
2757
+ Additional provider-specific options. They are passed through
2758
+ to the provider from the AI SDK and enable provider-specific
2759
+ functionality that can be fully encapsulated in the provider.
2760
+ */
2761
+ providerOptions?: ProviderOptions;
2762
+ /**
2763
+ @deprecated Use `providerOptions` instead.
2764
+ */
2765
+ experimental_providerMetadata?: ProviderMetadata;
2766
+ /**
2767
+ * Internal. For test use only. May change without notice.
2768
+ */
2769
+ _internal?: {
2770
+ generateId?: () => string;
2771
+ currentDate?: () => Date;
2772
+ };
2773
+ }): Promise<GenerateObjectResult<ENUM>>;
2774
+ /**
2775
+ Generate JSON with any schema for a given prompt using a language model.
2776
+
2777
+ This function does not stream the output. If you want to stream the output, use `streamObject` instead.
2778
+
2779
+ @returns
2780
+ A result object that contains the generated object, the finish reason, the token usage, and additional information.
2781
+ */
2782
+ declare function generateObject(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
2783
+ output: 'no-schema';
2784
+ /**
2785
+ The language model to use.
2786
+ */
2787
+ model: LanguageModel;
2788
+ /**
2789
+ The mode to use for object generation. Must be "json" for no-schema output.
2790
+ */
2791
+ mode?: 'json';
2792
+ /**
2793
+ A function that attempts to repair the raw output of the mode
2794
+ to enable JSON parsing.
2795
+ */
2796
+ experimental_repairText?: RepairTextFunction;
2797
+ /**
2798
+ Optional telemetry configuration (experimental).
2799
+ */
2800
+ experimental_telemetry?: TelemetrySettings;
2801
+ /**
2802
+ Additional provider-specific options. They are passed through
2803
+ to the provider from the AI SDK and enable provider-specific
2804
+ functionality that can be fully encapsulated in the provider.
2805
+ */
2806
+ providerOptions?: ProviderOptions;
2807
+ /**
2808
+ @deprecated Use `providerOptions` instead.
2809
+ */
2810
+ experimental_providerMetadata?: ProviderMetadata;
2811
+ /**
2812
+ * Internal. For test use only. May change without notice.
2813
+ */
2814
+ _internal?: {
2815
+ generateId?: () => string;
2816
+ currentDate?: () => Date;
2817
+ };
2818
+ }): Promise<GenerateObjectResult<JSONValue$2>>;
2819
+
2820
+ type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
2821
+
2822
+ /**
2823
+ The result of a `streamObject` call that contains the partial object stream and additional information.
2824
+ */
2825
+ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
2826
+ /**
2827
+ Warnings from the model provider (e.g. unsupported settings)
2828
+ */
2829
+ readonly warnings: Promise<CallWarning[] | undefined>;
2830
+ /**
2831
+ The token usage of the generated response. Resolved when the response is finished.
2832
+ */
2833
+ readonly usage: Promise<LanguageModelUsage>;
2834
+ /**
2835
+ Additional provider-specific metadata. They are passed through
2836
+ from the provider to the AI SDK and enable provider-specific
2837
+ results that can be fully encapsulated in the provider.
2838
+ */
2839
+ readonly providerMetadata: Promise<ProviderMetadata | undefined>;
2840
+ /**
2841
+ @deprecated Use `providerMetadata` instead.
2842
+ */
2843
+ readonly experimental_providerMetadata: Promise<ProviderMetadata | undefined>;
2844
+ /**
2845
+ Additional request information from the last step.
2846
+ */
2847
+ readonly request: Promise<LanguageModelRequestMetadata>;
2848
+ /**
2849
+ Additional response information.
2850
+ */
2851
+ readonly response: Promise<LanguageModelResponseMetadata>;
2852
+ /**
2853
+ The generated object (typed according to the schema). Resolved when the response is finished.
2854
+ */
2855
+ readonly object: Promise<RESULT>;
2856
+ /**
2857
+ Stream of partial objects. It gets more complete as the stream progresses.
2858
+
2859
+ Note that the partial object is not validated.
2860
+ If you want to be certain that the actual content matches your schema, you need to implement your own validation for partial results.
2861
+ */
2862
+ readonly partialObjectStream: AsyncIterableStream<PARTIAL>;
2863
+ /**
2864
+ * Stream over complete array elements. Only available if the output strategy is set to `array`.
2865
+ */
2866
+ readonly elementStream: ELEMENT_STREAM;
2867
+ /**
2868
+ Text stream of the JSON representation of the generated object. It contains text chunks.
2869
+ When the stream is finished, the object is valid JSON that can be parsed.
2870
+ */
2871
+ readonly textStream: AsyncIterableStream<string>;
2872
+ /**
2873
+ Stream of different types of events, including partial objects, errors, and finish events.
2874
+ Only errors that stop the stream, such as network errors, are thrown.
2875
+ */
2876
+ readonly fullStream: AsyncIterableStream<ObjectStreamPart<PARTIAL>>;
2877
+ /**
2878
+ Writes text delta output to a Node.js response-like object.
2879
+ It sets a `Content-Type` header to `text/plain; charset=utf-8` and
2880
+ writes each text delta as a separate chunk.
2881
+
2882
+ @param response A Node.js response-like object (ServerResponse).
2883
+ @param init Optional headers, status code, and status text.
2884
+ */
2885
+ pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): void;
2886
+ /**
2887
+ Creates a simple text stream response.
2888
+ The response has a `Content-Type` header set to `text/plain; charset=utf-8`.
2889
+ Each text delta is encoded as UTF-8 and sent as a separate chunk.
2890
+ Non-text-delta events are ignored.
2891
+
2892
+ @param init Optional headers, status code, and status text.
2893
+ */
2894
+ toTextStreamResponse(init?: ResponseInit): Response;
2895
+ }
2896
+ type ObjectStreamPart<PARTIAL> = {
2897
+ type: 'object';
2898
+ object: PARTIAL;
2899
+ } | {
2900
+ type: 'text-delta';
2901
+ textDelta: string;
2902
+ } | {
2903
+ type: 'error';
2904
+ error: unknown;
2905
+ } | {
2906
+ type: 'finish';
2907
+ finishReason: FinishReason;
2908
+ logprobs?: LogProbs;
2909
+ usage: LanguageModelUsage;
2910
+ response: LanguageModelResponseMetadata;
2911
+ providerMetadata?: ProviderMetadata;
2912
+ };
2913
+
2914
+ /**
2915
+ Callback that is set using the `onError` option.
2916
+
2917
+ @param event - The event that is passed to the callback.
2918
+ */
2919
+ type StreamObjectOnErrorCallback = (event: {
2920
+ error: unknown;
2921
+ }) => Promise<void> | void;
2922
+ /**
2923
+ Callback that is set using the `onFinish` option.
2924
+
2925
+ @param event - The event that is passed to the callback.
2926
+ */
2927
+ type StreamObjectOnFinishCallback<RESULT> = (event: {
2928
+ /**
2929
+ The token usage of the generated response.
2930
+ */
2931
+ usage: LanguageModelUsage;
2932
+ /**
2933
+ The generated object. Can be undefined if the final object does not match the schema.
2934
+ */
2935
+ object: RESULT | undefined;
2936
+ /**
2937
+ Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema.
2938
+ */
2939
+ error: unknown | undefined;
2940
+ /**
2941
+ Response metadata.
2942
+ */
2943
+ response: LanguageModelResponseMetadata;
2944
+ /**
2945
+ Warnings from the model provider (e.g. unsupported settings).
2946
+ */
2947
+ warnings?: CallWarning[];
2948
+ /**
2949
+ Additional provider-specific metadata. They are passed through
2950
+ to the provider from the AI SDK and enable provider-specific
2951
+ functionality that can be fully encapsulated in the provider.
2952
+ */
2953
+ providerMetadata: ProviderMetadata | undefined;
2954
+ /**
2955
+ @deprecated Use `providerMetadata` instead.
2956
+ */
2957
+ experimental_providerMetadata?: ProviderMetadata;
2958
+ }) => Promise<void> | void;
2959
+ /**
2960
+ Generate a structured, typed object for a given prompt and schema using a language model.
2961
+
2962
+ This function streams the output. If you do not want to stream the output, use `generateObject` instead.
2963
+
2964
+ @return
2965
+ A result object for accessing the partial object stream and additional information.
2966
+ */
2967
+ declare function streamObject<OBJECT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
2968
+ output?: 'object' | undefined;
2969
+ /**
2970
+ The language model to use.
2971
+ */
2972
+ model: LanguageModel;
2973
+ /**
2974
+ The schema of the object that the model should generate.
2975
+ */
2976
+ schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT>;
2977
+ /**
2978
+ Optional name of the output that should be generated.
2979
+ Used by some providers for additional LLM guidance, e.g.
2980
+ via tool or schema name.
2981
+ */
2982
+ schemaName?: string;
2983
+ /**
2984
+ Optional description of the output that should be generated.
2985
+ Used by some providers for additional LLM guidance, e.g.
2986
+ via tool or schema description.
2987
+ */
2988
+ schemaDescription?: string;
2989
+ /**
2990
+ The mode to use for object generation.
2991
+
2992
+ The schema is converted into a JSON schema and used in one of the following ways
2993
+
2994
+ - 'auto': The provider will choose the best mode for the model.
2995
+ - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
2996
+ - 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
2997
+
2998
+ Please note that most providers do not support all modes.
2999
+
3000
+ Default and recommended: 'auto' (best mode for the model).
3001
+ */
3002
+ mode?: 'auto' | 'json' | 'tool';
3003
+ /**
3004
+ Optional telemetry configuration (experimental).
3005
+ */
3006
+ experimental_telemetry?: TelemetrySettings;
3007
+ /**
3008
+ Additional provider-specific options. They are passed through
3009
+ to the provider from the AI SDK and enable provider-specific
3010
+ functionality that can be fully encapsulated in the provider.
3011
+ */
3012
+ providerOptions?: ProviderOptions;
3013
+ /**
3014
+ @deprecated Use `providerOptions` instead.
3015
+ */
3016
+ experimental_providerMetadata?: ProviderMetadata;
3017
+ /**
3018
+ Callback that is invoked when an error occurs during streaming.
3019
+ You can use it to log errors.
3020
+ The stream processing will pause until the callback promise is resolved.
3021
+ */
3022
+ onError?: StreamObjectOnErrorCallback;
3023
+ /**
3024
+ Callback that is called when the LLM response and the final object validation are finished.
3025
+ */
3026
+ onFinish?: StreamObjectOnFinishCallback<OBJECT>;
3027
+ /**
3028
+ * Internal. For test use only. May change without notice.
3029
+ */
3030
+ _internal?: {
3031
+ generateId?: () => string;
3032
+ currentDate?: () => Date;
3033
+ now?: () => number;
3034
+ };
3035
+ }): StreamObjectResult<DeepPartial<OBJECT>, OBJECT, never>;
3036
+ /**
3037
+ Generate an array with structured, typed elements for a given prompt and element schema using a language model.
3038
+
3039
+ This function streams the output. If you do not want to stream the output, use `generateObject` instead.
3040
+
3041
+ @return
3042
+ A result object for accessing the partial object stream and additional information.
3043
+ */
3044
+ declare function streamObject<ELEMENT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
3045
+ output: 'array';
3046
+ /**
3047
+ The language model to use.
3048
+ */
3049
+ model: LanguageModel;
3050
+ /**
3051
+ The element schema of the array that the model should generate.
3052
+ */
3053
+ schema: z.Schema<ELEMENT, z.ZodTypeDef, any> | Schema<ELEMENT>;
3054
+ /**
3055
+ Optional name of the array that should be generated.
3056
+ Used by some providers for additional LLM guidance, e.g.
3057
+ via tool or schema name.
3058
+ */
3059
+ schemaName?: string;
3060
+ /**
3061
+ Optional description of the array that should be generated.
3062
+ Used by some providers for additional LLM guidance, e.g.
3063
+ via tool or schema description.
3064
+ */
3065
+ schemaDescription?: string;
3066
+ /**
3067
+ The mode to use for object generation.
3068
+
3069
+ The schema is converted into a JSON schema and used in one of the following ways
3070
+
3071
+ - 'auto': The provider will choose the best mode for the model.
3072
+ - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
3073
+ - 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
3074
+
3075
+ Please note that most providers do not support all modes.
3076
+
3077
+ Default and recommended: 'auto' (best mode for the model).
3078
+ */
3079
+ mode?: 'auto' | 'json' | 'tool';
3080
+ /**
3081
+ Optional telemetry configuration (experimental).
3082
+ */
3083
+ experimental_telemetry?: TelemetrySettings;
3084
+ /**
3085
+ Additional provider-specific options. They are passed through
3086
+ to the provider from the AI SDK and enable provider-specific
3087
+ functionality that can be fully encapsulated in the provider.
3088
+ */
3089
+ providerOptions?: ProviderOptions;
3090
+ /**
3091
+ @deprecated Use `providerOptions` instead.
3092
+ */
3093
+ experimental_providerMetadata?: ProviderMetadata;
3094
+ /**
3095
+ Callback that is invoked when an error occurs during streaming.
3096
+ You can use it to log errors.
3097
+ The stream processing will pause until the callback promise is resolved.
3098
+ */
3099
+ onError?: StreamObjectOnErrorCallback;
3100
+ /**
3101
+ Callback that is called when the LLM response and the final object validation are finished.
3102
+ */
3103
+ onFinish?: StreamObjectOnFinishCallback<Array<ELEMENT>>;
3104
+ /**
3105
+ * Internal. For test use only. May change without notice.
3106
+ */
3107
+ _internal?: {
3108
+ generateId?: () => string;
3109
+ currentDate?: () => Date;
3110
+ now?: () => number;
3111
+ };
3112
+ }): StreamObjectResult<Array<ELEMENT>, Array<ELEMENT>, AsyncIterableStream<ELEMENT>>;
3113
+ /**
3114
+ Generate JSON with any schema for a given prompt using a language model.
3115
+
3116
+ This function streams the output. If you do not want to stream the output, use `generateObject` instead.
3117
+
3118
+ @return
3119
+ A result object for accessing the partial object stream and additional information.
3120
+ */
3121
+ declare function streamObject(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
3122
+ output: 'no-schema';
3123
+ /**
3124
+ The language model to use.
3125
+ */
3126
+ model: LanguageModel;
3127
+ /**
3128
+ The mode to use for object generation. Must be "json" for no-schema output.
3129
+ */
3130
+ mode?: 'json';
3131
+ /**
3132
+ Optional telemetry configuration (experimental).
3133
+ */
3134
+ experimental_telemetry?: TelemetrySettings;
3135
+ /**
3136
+ Additional provider-specific options. They are passed through
3137
+ to the provider from the AI SDK and enable provider-specific
3138
+ functionality that can be fully encapsulated in the provider.
3139
+ */
3140
+ providerOptions?: ProviderOptions;
3141
+ /**
3142
+ @deprecated Use `providerOptions` instead.
3143
+ */
3144
+ experimental_providerMetadata?: ProviderMetadata;
3145
+ /**
3146
+ Callback that is invoked when an error occurs during streaming.
3147
+ You can use it to log errors.
3148
+ The stream processing will pause until the callback promise is resolved.
3149
+ */
3150
+ onError?: StreamObjectOnErrorCallback;
3151
+ /**
3152
+ Callback that is called when the LLM response and the final object validation are finished.
3153
+ */
3154
+ onFinish?: StreamObjectOnFinishCallback<JSONValue$2>;
3155
+ /**
3156
+ * Internal. For test use only. May change without notice.
3157
+ */
3158
+ _internal?: {
3159
+ generateId?: () => string;
3160
+ currentDate?: () => Date;
3161
+ now?: () => number;
3162
+ };
3163
+ }): StreamObjectResult<JSONValue$2, JSONValue$2, never>;
3164
+
3165
+ type ReasoningDetail = {
3166
+ type: 'text';
3167
+ text: string;
3168
+ signature?: string;
3169
+ } | {
3170
+ type: 'redacted';
3171
+ data: string;
3172
+ };
3173
+
3174
+ type ToolParameters = z.ZodTypeAny | Schema<any>;
3175
+ type inferParameters<PARAMETERS extends ToolParameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
3176
+ interface ToolExecutionOptions {
3177
+ /**
3178
+ * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
3179
+ */
3180
+ toolCallId: string;
3181
+ /**
3182
+ * Messages that were sent to the language model to initiate the response that contained the tool call.
3183
+ * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
3184
+ */
3185
+ messages: CoreMessage[];
3186
+ /**
3187
+ * An optional abort signal that indicates that the overall operation should be aborted.
3188
+ */
3189
+ abortSignal?: AbortSignal;
3190
+ }
3191
+ /**
3192
+ A tool contains the description and the schema of the input that the tool expects.
3193
+ This enables the language model to generate the input.
3194
+
3195
+ The tool can also contain an optional execute function for the actual execution function of the tool.
3196
+ */
3197
+ type Tool<PARAMETERS extends ToolParameters = any, RESULT = any> = {
3198
+ /**
3199
+ The schema of the input that the tool expects. The language model will use this to generate the input.
3200
+ It is also used to validate the output of the language model.
3201
+ Use descriptions to make the input understandable for the language model.
3202
+ */
3203
+ parameters: PARAMETERS;
3204
+ /**
3205
+ An optional description of what the tool does.
3206
+ Will be used by the language model to decide whether to use the tool.
3207
+ Not used for provider-defined tools.
3208
+ */
3209
+ description?: string;
3210
+ /**
3211
+ Optional conversion function that maps the tool result to multi-part tool content for LLMs.
3212
+ */
3213
+ experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
3214
+ /**
3215
+ An async function that is called with the arguments from the tool call and produces a result.
3216
+ If not provided, the tool will not be executed automatically.
3217
+
3218
+ @args is the input of the tool call.
3219
+ @options.abortSignal is a signal that can be used to abort the tool call.
3220
+ */
3221
+ execute?: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
3222
+ } & ({
3223
+ /**
3224
+ Function tool.
3225
+ */
3226
+ type?: undefined | 'function';
3227
+ } | {
3228
+ /**
3229
+ Provider-defined tool.
3230
+ */
3231
+ type: 'provider-defined';
3232
+ /**
3233
+ The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
3234
+ */
3235
+ id: `${string}.${string}`;
3236
+ /**
3237
+ The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
3238
+ */
3239
+ args: Record<string, unknown>;
3240
+ });
3241
+
3242
+ /**
3243
+ Create a union of the given object's values, and optionally specify which keys to get the values from.
3244
+
3245
+ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
3246
+
3247
+ @example
3248
+ ```
3249
+ // data.json
3250
+ {
3251
+ 'foo': 1,
3252
+ 'bar': 2,
3253
+ 'biz': 3
3254
+ }
3255
+
3256
+ // main.ts
3257
+ import type {ValueOf} from 'type-fest';
3258
+ import data = require('./data.json');
3259
+
3260
+ export function getData(name: string): ValueOf<typeof data> {
3261
+ return data[name];
3262
+ }
3263
+
3264
+ export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
3265
+ return data[name];
3266
+ }
3267
+
3268
+ // file.ts
3269
+ import {getData, onlyBar} from './main';
3270
+
3271
+ getData('foo');
3272
+ //=> 1
3273
+
3274
+ onlyBar('foo');
3275
+ //=> TypeError ...
3276
+
3277
+ onlyBar('bar');
3278
+ //=> 2
3279
+ ```
3280
+ * @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
3281
+ */
3282
+ type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
3283
+
3284
+ type ToolSet = Record<string, Tool>;
3285
+
3286
+ type ToolCallUnion<TOOLS extends ToolSet> = ValueOf<{
3287
+ [NAME in keyof TOOLS]: {
3288
+ type: 'tool-call';
3289
+ toolCallId: string;
3290
+ toolName: NAME & string;
3291
+ args: inferParameters<TOOLS[NAME]['parameters']>;
3292
+ };
3293
+ }>;
3294
+ type ToolCallArray<TOOLS extends ToolSet> = Array<ToolCallUnion<TOOLS>>;
3295
+
3296
+ type ToToolsWithExecute<TOOLS extends ToolSet> = {
3297
+ [K in keyof TOOLS as TOOLS[K] extends {
3298
+ execute: any;
3299
+ } ? K : never]: TOOLS[K];
3300
+ };
3301
+ type ToToolsWithDefinedExecute<TOOLS extends ToolSet> = {
3302
+ [K in keyof TOOLS as TOOLS[K]['execute'] extends undefined ? never : K]: TOOLS[K];
3303
+ };
3304
+ type ToToolResultObject<TOOLS extends ToolSet> = ValueOf<{
3305
+ [NAME in keyof TOOLS]: {
3306
+ type: 'tool-result';
3307
+ toolCallId: string;
3308
+ toolName: NAME & string;
3309
+ args: inferParameters<TOOLS[NAME]['parameters']>;
3310
+ result: Awaited<ReturnType<Exclude<TOOLS[NAME]['execute'], undefined>>>;
3311
+ };
3312
+ }>;
3313
+ type ToolResultUnion<TOOLS extends ToolSet> = ToToolResultObject<ToToolsWithDefinedExecute<ToToolsWithExecute<TOOLS>>>;
3314
+ type ToolResultArray<TOOLS extends ToolSet> = Array<ToolResultUnion<TOOLS>>;
3315
+
3316
+ /**
3317
+ A message that was generated during the generation process.
3318
+ It can be either an assistant message or a tool message.
3319
+ */
3320
+ type ResponseMessage = (CoreAssistantMessage | CoreToolMessage) & {
3321
+ /**
3322
+ Message ID generated by the AI SDK.
3323
+ */
3324
+ id: string;
3325
+ };
3326
+ /**
3327
+ * The result of a single step in the generation process.
3328
+ */
3329
+ type StepResult<TOOLS extends ToolSet> = {
3330
+ /**
3331
+ The generated text.
3332
+ */
3333
+ readonly text: string;
3334
+ /**
3335
+ The reasoning that was generated during the generation.
3336
+ */
3337
+ readonly reasoning: string | undefined;
3338
+ readonly reasoningDetails: Array<ReasoningDetail>;
3339
+ /**
3340
+ The sources that were used to generate the text.
3341
+ */
3342
+ readonly sources: Source[];
3343
+ /**
3344
+ The tool calls that were made during the generation.
3345
+ */
3346
+ readonly toolCalls: ToolCallArray<TOOLS>;
3347
+ /**
3348
+ The results of the tool calls.
3349
+ */
3350
+ readonly toolResults: ToolResultArray<TOOLS>;
3351
+ /**
3352
+ The reason why the generation finished.
3353
+ */
3354
+ readonly finishReason: FinishReason;
3355
+ /**
3356
+ The token usage of the generated text.
3357
+ */
3358
+ readonly usage: LanguageModelUsage;
3359
+ /**
3360
+ Warnings from the model provider (e.g. unsupported settings).
3361
+ */
3362
+ readonly warnings: CallWarning[] | undefined;
3363
+ /**
3364
+ Logprobs for the completion.
3365
+ `undefined` if the mode does not support logprobs or if was not enabled.
3366
+ */
3367
+ readonly logprobs: LogProbs | undefined;
3368
+ /**
3369
+ Additional request information.
3370
+ */
3371
+ readonly request: LanguageModelRequestMetadata;
3372
+ /**
3373
+ Additional response information.
3374
+ */
3375
+ readonly response: LanguageModelResponseMetadata & {
3376
+ /**
3377
+ The response messages that were generated during the call.
3378
+ Response messages can be either assistant messages or tool messages.
3379
+ They contain a generated id.
3380
+ */
3381
+ readonly messages: Array<ResponseMessage>;
3382
+ /**
3383
+ Response body (available only for providers that use HTTP requests).
3384
+ */
3385
+ body?: unknown;
3386
+ };
3387
+ /**
3388
+ Additional provider-specific metadata. They are passed through
3389
+ from the provider to the AI SDK and enable provider-specific
3390
+ results that can be fully encapsulated in the provider.
3391
+ */
3392
+ readonly providerMetadata: ProviderMetadata | undefined;
3393
+ /**
3394
+ @deprecated Use `providerMetadata` instead.
3395
+ */
3396
+ readonly experimental_providerMetadata: ProviderMetadata | undefined;
3397
+ /**
3398
+ The type of step that this result is for. The first step is always
3399
+ an "initial" step, and subsequent steps are either "continue" steps
3400
+ or "tool-result" steps.
3401
+ */
3402
+ readonly stepType: 'initial' | 'continue' | 'tool-result';
3403
+ /**
3404
+ True when there will be a continuation step with a continuation text.
3405
+ */
3406
+ readonly isContinued: boolean;
3407
+ };
3408
+
3409
+ /**
3410
+ The result of a `generateText` call.
3411
+ It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
3412
+ */
3413
+ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
3414
+ /**
3415
+ The generated text.
3416
+ */
3417
+ readonly text: string;
3418
+ /**
3419
+ The reasoning text that the model has generated. Can be undefined if the model
3420
+ has only generated text.
3421
+ */
3422
+ readonly reasoning: string | undefined;
3423
+ /**
3424
+ The full reasoning that the model has generated.
3425
+ */
3426
+ readonly reasoningDetails: Array<ReasoningDetail>;
3427
+ /**
3428
+ Sources that have been used as input to generate the response.
3429
+ For multi-step generation, the sources are accumulated from all steps.
3430
+ */
3431
+ readonly sources: Source[];
3432
+ /**
3433
+ The generated structured output. It uses the `experimental_output` specification.
3434
+ */
3435
+ readonly experimental_output: OUTPUT;
3436
+ /**
3437
+ The tool calls that were made during the generation.
3438
+ */
3439
+ readonly toolCalls: ToolCallArray<TOOLS>;
3440
+ /**
3441
+ The results of the tool calls.
3442
+ */
3443
+ readonly toolResults: ToolResultArray<TOOLS>;
3444
+ /**
3445
+ The reason why the generation finished.
3446
+ */
3447
+ readonly finishReason: FinishReason;
3448
+ /**
3449
+ The token usage of the generated text.
3450
+ */
3451
+ readonly usage: LanguageModelUsage;
3452
+ /**
3453
+ Warnings from the model provider (e.g. unsupported settings)
3454
+ */
3455
+ readonly warnings: CallWarning[] | undefined;
3456
+ /**
3457
+ Details for all steps.
3458
+ You can use this to get information about intermediate steps,
3459
+ such as the tool calls or the response headers.
3460
+ */
3461
+ readonly steps: Array<StepResult<TOOLS>>;
3462
+ /**
3463
+ Additional request information.
3464
+ */
3465
+ readonly request: LanguageModelRequestMetadata;
3466
+ /**
3467
+ Additional response information.
3468
+ */
3469
+ readonly response: LanguageModelResponseMetadata & {
3470
+ /**
3471
+ The response messages that were generated during the call. It consists of an assistant message,
3472
+ potentially containing tool calls.
3473
+
3474
+ When there are tool results, there is an additional tool message with the tool results that are available.
3475
+ If there are tools that do not have execute functions, they are not included in the tool results and
3476
+ need to be added separately.
3477
+ */
3478
+ messages: Array<ResponseMessage>;
3479
+ /**
3480
+ Response body (available only for providers that use HTTP requests).
3481
+ */
3482
+ body?: unknown;
3483
+ };
3484
+ /**
3485
+ Logprobs for the completion.
3486
+ `undefined` if the mode does not support logprobs or if it was not enabled.
3487
+
3488
+ @deprecated Will become a provider extension in the future.
3489
+ */
3490
+ readonly logprobs: LogProbs | undefined;
3491
+ /**
3492
+ Additional provider-specific metadata. They are passed through
3493
+ from the provider to the AI SDK and enable provider-specific
3494
+ results that can be fully encapsulated in the provider.
3495
+ */
3496
+ readonly providerMetadata: ProviderMetadata | undefined;
3497
+ /**
3498
+ @deprecated Use `providerMetadata` instead.
3499
+ */
3500
+ readonly experimental_providerMetadata: ProviderMetadata | undefined;
3501
+ }
3502
+
3503
+ interface Output<OUTPUT, PARTIAL> {
3504
+ readonly type: 'object' | 'text';
3505
+ injectIntoSystemPrompt(options: {
3506
+ system: string | undefined;
3507
+ model: LanguageModel;
3508
+ }): string | undefined;
3509
+ responseFormat: (options: {
3510
+ model: LanguageModel;
3511
+ }) => LanguageModelV1CallOptions['responseFormat'];
3512
+ parsePartial(options: {
3513
+ text: string;
3514
+ }): {
3515
+ partial: PARTIAL;
3516
+ } | undefined;
3517
+ parseOutput(options: {
3518
+ text: string;
3519
+ }, context: {
3520
+ response: LanguageModelResponseMetadata;
3521
+ usage: LanguageModelUsage;
3522
+ }): OUTPUT;
3523
+ }
3524
+
3525
+ declare const symbol$f: unique symbol;
3526
+ declare class InvalidToolArgumentsError extends AISDKError {
3527
+ private readonly [symbol$f];
3528
+ readonly toolName: string;
3529
+ readonly toolArgs: string;
3530
+ constructor({ toolArgs, toolName, cause, message, }: {
3531
+ message?: string;
3532
+ toolArgs: string;
3533
+ toolName: string;
3534
+ cause: unknown;
3535
+ });
3536
+ static isInstance(error: unknown): error is InvalidToolArgumentsError;
3537
+ }
3538
+
3539
+ declare const symbol$e: unique symbol;
3540
+ declare class NoSuchToolError extends AISDKError {
3541
+ private readonly [symbol$e];
3542
+ readonly toolName: string;
3543
+ readonly availableTools: string[] | undefined;
3544
+ constructor({ toolName, availableTools, message, }: {
3545
+ toolName: string;
3546
+ availableTools?: string[] | undefined;
3547
+ message?: string;
3548
+ });
3549
+ static isInstance(error: unknown): error is NoSuchToolError;
3550
+ }
3551
+
3552
+ /**
3553
+ * A function that attempts to repair a tool call that failed to parse.
3554
+ *
3555
+ * It receives the error and the context as arguments and returns the repair
3556
+ * tool call JSON as text.
3557
+ *
3558
+ * @param options.system - The system prompt.
3559
+ * @param options.messages - The messages in the current generation step.
3560
+ * @param options.toolCall - The tool call that failed to parse.
3561
+ * @param options.tools - The tools that are available.
3562
+ * @param options.parameterSchema - A function that returns the JSON Schema for a tool.
3563
+ * @param options.error - The error that occurred while parsing the tool call.
3564
+ */
3565
+ type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
3566
+ system: string | undefined;
3567
+ messages: CoreMessage[];
3568
+ toolCall: LanguageModelV1FunctionToolCall;
3569
+ tools: TOOLS;
3570
+ parameterSchema: (options: {
3571
+ toolName: string;
3572
+ }) => JSONSchema7;
3573
+ error: NoSuchToolError | InvalidToolArgumentsError;
3574
+ }) => Promise<LanguageModelV1FunctionToolCall | null>;
3575
+
3576
+ /**
3577
+ Callback that is set using the `onStepFinish` option.
3578
+
3579
+ @param stepResult - The result of the step.
3580
+ */
3581
+ type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
3582
+ /**
3583
+ Generate a text and call tools for a given prompt using a language model.
3584
+
3585
+ This function does not stream the output. If you want to stream the output, use `streamText` instead.
3586
+
3587
+ @param model - The language model to use.
3588
+
3589
+ @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
3590
+ @param toolChoice - The tool choice strategy. Default: 'auto'.
3591
+
3592
+ @param system - A system message that will be part of the prompt.
3593
+ @param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
3594
+ @param messages - A list of messages. You can either use `prompt` or `messages` but not both.
3595
+
3596
+ @param maxTokens - Maximum number of tokens to generate.
3597
+ @param temperature - Temperature setting.
3598
+ The value is passed through to the provider. The range depends on the provider and model.
3599
+ It is recommended to set either `temperature` or `topP`, but not both.
3600
+ @param topP - Nucleus sampling.
3601
+ The value is passed through to the provider. The range depends on the provider and model.
3602
+ It is recommended to set either `temperature` or `topP`, but not both.
3603
+ @param topK - Only sample from the top K options for each subsequent token.
3604
+ Used to remove "long tail" low probability responses.
3605
+ Recommended for advanced use cases only. You usually only need to use temperature.
3606
+ @param presencePenalty - Presence penalty setting.
3607
+ It affects the likelihood of the model to repeat information that is already in the prompt.
3608
+ The value is passed through to the provider. The range depends on the provider and model.
3609
+ @param frequencyPenalty - Frequency penalty setting.
3610
+ It affects the likelihood of the model to repeatedly use the same words or phrases.
3611
+ The value is passed through to the provider. The range depends on the provider and model.
3612
+ @param stopSequences - Stop sequences.
3613
+ If set, the model will stop generating text when one of the stop sequences is generated.
3614
+ @param seed - The seed (integer) to use for random sampling.
3615
+ If set and supported by the model, calls will generate deterministic results.
3616
+
3617
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
3618
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
3619
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
3620
+
3621
+ @param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
3622
+ @param experimental_generateMessageId - Generate a unique ID for each message.
3623
+
3624
+ @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
3625
+
3626
+ @returns
3627
+ A result object that contains the generated text, the results of the tool calls, and additional information.
3628
+ */
3629
+ 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, experimental_providerMetadata, providerOptions, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
3630
+ /**
3631
+ The language model to use.
3632
+ */
3633
+ model: LanguageModel;
3634
+ /**
3635
+ The tools that the model can call. The model needs to support calling tools.
3636
+ */
3637
+ tools?: TOOLS;
3638
+ /**
3639
+ The tool choice strategy. Default: 'auto'.
3640
+ */
3641
+ toolChoice?: ToolChoice<TOOLS>;
3642
+ /**
3643
+ Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
3644
+
3645
+ A maximum number is required to prevent infinite loops in the case of misconfigured tools.
3646
+
3647
+ By default, it's set to 1, which means that only a single LLM call is made.
3648
+ */
3649
+ maxSteps?: number;
3650
+ /**
3651
+ Generate a unique ID for each message.
3652
+ */
3653
+ experimental_generateMessageId?: IDGenerator;
3654
+ /**
3655
+ When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
3656
+
3657
+ By default, it's set to false.
3658
+ */
3659
+ experimental_continueSteps?: boolean;
3660
+ /**
3661
+ Optional telemetry configuration (experimental).
3662
+ */
3663
+ experimental_telemetry?: TelemetrySettings;
3664
+ /**
3665
+ Additional provider-specific options. They are passed through
3666
+ to the provider from the AI SDK and enable provider-specific
3667
+ functionality that can be fully encapsulated in the provider.
3668
+ */
3669
+ providerOptions?: ProviderOptions;
3670
+ /**
3671
+ @deprecated Use `providerOptions` instead.
3672
+ */
3673
+ experimental_providerMetadata?: ProviderMetadata;
3674
+ /**
3675
+ Limits the tools that are available for the model to call without
3676
+ changing the tool call and result types in the result.
3677
+ */
3678
+ experimental_activeTools?: Array<keyof TOOLS>;
3679
+ /**
3680
+ Optional specification for parsing structured outputs from the LLM response.
3681
+ */
3682
+ experimental_output?: Output<OUTPUT, OUTPUT_PARTIAL>;
3683
+ /**
3684
+ A function that attempts to repair a tool call that failed to parse.
3685
+ */
3686
+ experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
3687
+ /**
3688
+ Callback that is called when each step (LLM call) is finished, including intermediate steps.
3689
+ */
3690
+ onStepFinish?: GenerateTextOnStepFinishCallback<TOOLS>;
3691
+ /**
3692
+ * Internal. For test use only. May change without notice.
3693
+ */
3694
+ _internal?: {
3695
+ generateId?: IDGenerator;
3696
+ currentDate?: () => Date;
3697
+ };
3698
+ }): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
3699
+
3700
+ /**
3701
+ * A stream wrapper to send custom JSON-encoded data back to the client.
3702
+ *
3703
+ * @deprecated Please use `createDataStream`, `createDataStreamResponse`, and `pipeDataStreamToResponse` instead.
3704
+ */
3705
+ declare class StreamData {
3706
+ private encoder;
3707
+ private controller;
3708
+ stream: ReadableStream<Uint8Array>;
3709
+ private isClosed;
3710
+ private warningTimeout;
3711
+ constructor();
3712
+ close(): Promise<void>;
3713
+ append(value: JSONValue): void;
3714
+ appendMessageAnnotation(value: JSONValue): void;
3715
+ }
3716
+
3717
+ type DataStreamOptions = {
3718
+ /**
3719
+ * Send usage parts to the client.
3720
+ * Default to true.
3721
+ */
3722
+ sendUsage?: boolean;
3723
+ /**
3724
+ * Send reasoning parts to the client.
3725
+ * Default to false.
3726
+ */
3727
+ sendReasoning?: boolean;
3728
+ /**
3729
+ * Send source parts to the client.
3730
+ * Default to false.
3731
+ */
3732
+ sendSources?: boolean;
3733
+ /**
3734
+ * Send the finish event to the client.
3735
+ * Set to false if you are using additional streamText calls
3736
+ * that send additional data.
3737
+ * Default to true.
3738
+ */
3739
+ experimental_sendFinish?: boolean;
3740
+ /**
3741
+ * Send the message start event to the client.
3742
+ * Set to false if you are using additional streamText calls
3743
+ * and the message start event has already been sent.
3744
+ * Default to true.
3745
+ *
3746
+ * Note: this setting is currently not used, but you should
3747
+ * already set it to false if you are using additional
3748
+ * streamText calls that send additional data to prevent
3749
+ * the message start event from being sent multiple times.
3750
+ */
3751
+ experimental_sendStart?: boolean;
3752
+ };
3753
+ /**
3754
+ A result object for accessing different stream types and additional information.
3755
+ */
3756
+ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
3757
+ /**
3758
+ Warnings from the model provider (e.g. unsupported settings) for the first step.
3759
+ */
3760
+ readonly warnings: Promise<CallWarning[] | undefined>;
3761
+ /**
3762
+ The total token usage of the generated response.
3763
+ When there are multiple steps, the usage is the sum of all step usages.
3764
+
3765
+ Resolved when the response is finished.
3766
+ */
3767
+ readonly usage: Promise<LanguageModelUsage>;
3768
+ /**
3769
+ Sources that have been used as input to generate the response.
3770
+ For multi-step generation, the sources are accumulated from all steps.
3771
+
3772
+ Resolved when the response is finished.
3773
+ */
3774
+ readonly sources: Promise<Source[]>;
3775
+ /**
3776
+ The reason why the generation finished. Taken from the last step.
3777
+
3778
+ Resolved when the response is finished.
3779
+ */
3780
+ readonly finishReason: Promise<FinishReason>;
3781
+ /**
3782
+ Additional provider-specific metadata from the last step.
3783
+ Metadata is passed through from the provider to the AI SDK and
3784
+ enables provider-specific results that can be fully encapsulated in the provider.
3785
+ */
3786
+ readonly providerMetadata: Promise<ProviderMetadata | undefined>;
3787
+ /**
3788
+ @deprecated Use `providerMetadata` instead.
3789
+ */
3790
+ readonly experimental_providerMetadata: Promise<ProviderMetadata | undefined>;
3791
+ /**
3792
+ The full text that has been generated by the last step.
3793
+
3794
+ Resolved when the response is finished.
3795
+ */
3796
+ readonly text: Promise<string>;
3797
+ /**
3798
+ The reasoning that has been generated by the last step.
3799
+
3800
+ Resolved when the response is finished.
3801
+ */
3802
+ readonly reasoning: Promise<string | undefined>;
3803
+ /**
3804
+ The full reasoning that the model has generated.
3805
+
3806
+ Resolved when the response is finished.
3807
+ */
3808
+ readonly reasoningDetails: Promise<Array<ReasoningDetail>>;
3809
+ /**
3810
+ The tool calls that have been executed in the last step.
3811
+
3812
+ Resolved when the response is finished.
3813
+ */
3814
+ readonly toolCalls: Promise<ToolCallUnion<TOOLS>[]>;
3815
+ /**
3816
+ The tool results that have been generated in the last step.
3817
+
3818
+ Resolved when the all tool executions are finished.
3819
+ */
3820
+ readonly toolResults: Promise<ToolResultUnion<TOOLS>[]>;
3821
+ /**
3822
+ Details for all steps.
3823
+ You can use this to get information about intermediate steps,
3824
+ such as the tool calls or the response headers.
3825
+ */
3826
+ readonly steps: Promise<Array<StepResult<TOOLS>>>;
3827
+ /**
3828
+ Additional request information from the last step.
3829
+ */
3830
+ readonly request: Promise<LanguageModelRequestMetadata>;
3831
+ /**
3832
+ Additional response information from the last step.
3833
+ */
3834
+ readonly response: Promise<LanguageModelResponseMetadata & {
3835
+ /**
3836
+ The response messages that were generated during the call. It consists of an assistant message,
3837
+ potentially containing tool calls.
3838
+
3839
+ When there are tool results, there is an additional tool message with the tool results that are available.
3840
+ If there are tools that do not have execute functions, they are not included in the tool results and
3841
+ need to be added separately.
3842
+ */
3843
+ messages: Array<ResponseMessage>;
3844
+ }>;
3845
+ /**
3846
+ A text stream that returns only the generated text deltas. You can use it
3847
+ as either an AsyncIterable or a ReadableStream. When an error occurs, the
3848
+ stream will throw the error.
3849
+ */
3850
+ readonly textStream: AsyncIterableStream<string>;
3851
+ /**
3852
+ A stream with all events, including text deltas, tool calls, tool results, and
3853
+ errors.
3854
+ You can use it as either an AsyncIterable or a ReadableStream.
3855
+ Only errors that stop the stream, such as network errors, are thrown.
3856
+ */
3857
+ readonly fullStream: AsyncIterableStream<TextStreamPart<TOOLS>>;
3858
+ /**
3859
+ A stream of partial outputs. It uses the `experimental_output` specification.
3860
+ */
3861
+ readonly experimental_partialOutputStream: AsyncIterableStream<PARTIAL_OUTPUT>;
3862
+ /**
3863
+ Consumes the stream without processing the parts.
3864
+ This is useful to force the stream to finish.
3865
+ It effectively removes the backpressure and allows the stream to finish,
3866
+ triggering the `onFinish` callback and the promise resolution.
3867
+ */
3868
+ consumeStream(): Promise<void>;
3869
+ /**
3870
+ Converts the result to a data stream.
3871
+
3872
+ @param data an optional StreamData object that will be merged into the stream.
3873
+ @param getErrorMessage an optional function that converts an error to an error message.
3874
+ @param sendUsage whether to send the usage information to the client. Defaults to true.
3875
+ @param sendReasoning whether to send the reasoning information to the client. Defaults to false.
3876
+ @return A data stream.
3877
+ */
3878
+ toDataStream(options?: {
3879
+ data?: StreamData;
3880
+ getErrorMessage?: (error: unknown) => string;
3881
+ } & DataStreamOptions): ReadableStream<Uint8Array>;
3882
+ /**
3883
+ * Merges the result as a data stream into another data stream.
3884
+ *
3885
+ * @param dataStream A data stream writer.
3886
+ * @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
3887
+ * @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
3888
+ */
3889
+ mergeIntoDataStream(dataStream: DataStreamWriter, options?: DataStreamOptions): void;
3890
+ /**
3891
+ Writes data stream output to a Node.js response-like object.
3892
+
3893
+ @param response A Node.js response-like object (ServerResponse).
3894
+ @param options.status The status code.
3895
+ @param options.statusText The status text.
3896
+ @param options.headers The headers.
3897
+ @param options.data The stream data.
3898
+ @param options.getErrorMessage An optional function that converts an error to an error message.
3899
+ @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
3900
+ @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
3901
+ */
3902
+ pipeDataStreamToResponse(response: ServerResponse, options?: ResponseInit & {
3903
+ data?: StreamData;
3904
+ getErrorMessage?: (error: unknown) => string;
3905
+ } & DataStreamOptions): void;
3906
+ /**
3907
+ Writes text delta output to a Node.js response-like object.
3908
+ It sets a `Content-Type` header to `text/plain; charset=utf-8` and
3909
+ writes each text delta as a separate chunk.
3910
+
3911
+ @param response A Node.js response-like object (ServerResponse).
3912
+ @param init Optional headers, status code, and status text.
3913
+ */
3914
+ pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void;
3915
+ /**
3916
+ Converts the result to a streamed response object with a stream data part stream.
3917
+ It can be used with the `useChat` and `useCompletion` hooks.
3918
+
3919
+ @param options.status The status code.
3920
+ @param options.statusText The status text.
3921
+ @param options.headers The headers.
3922
+ @param options.data The stream data.
3923
+ @param options.getErrorMessage An optional function that converts an error to an error message.
3924
+ @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
3925
+ @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
3926
+
3927
+ @return A response object.
3928
+ */
3929
+ toDataStreamResponse(options?: ResponseInit & {
3930
+ data?: StreamData;
3931
+ getErrorMessage?: (error: unknown) => string;
3932
+ } & DataStreamOptions): Response;
3933
+ /**
3934
+ Creates a simple text stream response.
3935
+ Each text delta is encoded as UTF-8 and sent as a separate chunk.
3936
+ Non-text-delta events are ignored.
3937
+
3938
+ @param init Optional headers, status code, and status text.
3939
+ */
3940
+ toTextStreamResponse(init?: ResponseInit): Response;
3941
+ }
3942
+ type TextStreamPart<TOOLS extends ToolSet> = {
3943
+ type: 'text-delta';
3944
+ textDelta: string;
3945
+ } | {
3946
+ type: 'reasoning';
3947
+ textDelta: string;
3948
+ } | {
3949
+ type: 'reasoning-signature';
3950
+ signature: string;
3951
+ } | {
3952
+ type: 'redacted-reasoning';
3953
+ data: string;
3954
+ } | {
3955
+ type: 'source';
3956
+ source: Source;
3957
+ } | ({
3958
+ type: 'tool-call';
3959
+ } & ToolCallUnion<TOOLS>) | {
3960
+ type: 'tool-call-streaming-start';
3961
+ toolCallId: string;
3962
+ toolName: string;
3963
+ } | {
3964
+ type: 'tool-call-delta';
3965
+ toolCallId: string;
3966
+ toolName: string;
3967
+ argsTextDelta: string;
3968
+ } | ({
3969
+ type: 'tool-result';
3970
+ } & ToolResultUnion<TOOLS>) | {
3971
+ type: 'step-start';
3972
+ messageId: string;
3973
+ request: LanguageModelRequestMetadata;
3974
+ warnings: CallWarning[];
3975
+ } | {
3976
+ type: 'step-finish';
3977
+ messageId: string;
3978
+ logprobs?: LogProbs;
3979
+ request: LanguageModelRequestMetadata;
3980
+ warnings: CallWarning[] | undefined;
3981
+ response: LanguageModelResponseMetadata;
3982
+ usage: LanguageModelUsage;
3983
+ finishReason: FinishReason;
3984
+ providerMetadata: ProviderMetadata | undefined;
3985
+ /**
3986
+ * @deprecated Use `providerMetadata` instead.
3987
+ */
3988
+ experimental_providerMetadata?: ProviderMetadata;
3989
+ isContinued: boolean;
3990
+ } | {
3991
+ type: 'finish';
3992
+ finishReason: FinishReason;
3993
+ usage: LanguageModelUsage;
3994
+ providerMetadata: ProviderMetadata | undefined;
3995
+ /**
3996
+ * @deprecated Use `providerMetadata` instead.
3997
+ */
3998
+ experimental_providerMetadata?: ProviderMetadata;
3999
+ /**
4000
+ * @deprecated will be moved into provider metadata
4001
+ */
4002
+ logprobs?: LogProbs;
4003
+ /**
4004
+ * @deprecated use response on step-finish instead
4005
+ */
4006
+ response: LanguageModelResponseMetadata;
4007
+ } | {
4008
+ type: 'error';
4009
+ error: unknown;
4010
+ };
4011
+
4012
+ /**
4013
+ A transformation that is applied to the stream.
4014
+
4015
+ @param stopStream - A function that stops the source stream.
4016
+ @param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
4017
+ */
4018
+ type StreamTextTransform<TOOLS extends ToolSet> = (options: {
4019
+ tools: TOOLS;
4020
+ stopStream: () => void;
4021
+ }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
4022
+ /**
4023
+ Callback that is set using the `onError` option.
4024
+
4025
+ @param event - The event that is passed to the callback.
4026
+ */
4027
+ type StreamTextOnErrorCallback = (event: {
4028
+ error: unknown;
4029
+ }) => Promise<void> | void;
4030
+ /**
4031
+ Callback that is set using the `onStepFinish` option.
4032
+
4033
+ @param stepResult - The result of the step.
4034
+ */
4035
+ type StreamTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
4036
+ /**
4037
+ Callback that is set using the `onChunk` option.
4038
+
4039
+ @param event - The event that is passed to the callback.
4040
+ */
4041
+ type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
4042
+ chunk: Extract<TextStreamPart<TOOLS>, {
4043
+ type: 'text-delta' | 'reasoning' | 'source' | 'tool-call' | 'tool-call-streaming-start' | 'tool-call-delta' | 'tool-result';
4044
+ }>;
4045
+ }) => Promise<void> | void;
4046
+ /**
4047
+ Callback that is set using the `onFinish` option.
4048
+
4049
+ @param event - The event that is passed to the callback.
4050
+ */
4051
+ type StreamTextOnFinishCallback<TOOLS extends ToolSet> = (event: Omit<StepResult<TOOLS>, 'stepType' | 'isContinued'> & {
4052
+ /**
4053
+ Details for all steps.
4054
+ */
4055
+ readonly steps: StepResult<TOOLS>[];
4056
+ }) => Promise<void> | void;
4057
+ /**
4058
+ Generate a text and call tools for a given prompt using a language model.
4059
+
4060
+ This function streams the output. If you do not want to stream the output, use `generateText` instead.
4061
+
4062
+ @param model - The language model to use.
4063
+ @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
4064
+
4065
+ @param system - A system message that will be part of the prompt.
4066
+ @param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
4067
+ @param messages - A list of messages. You can either use `prompt` or `messages` but not both.
4068
+
4069
+ @param maxTokens - Maximum number of tokens to generate.
4070
+ @param temperature - Temperature setting.
4071
+ The value is passed through to the provider. The range depends on the provider and model.
4072
+ It is recommended to set either `temperature` or `topP`, but not both.
4073
+ @param topP - Nucleus sampling.
4074
+ The value is passed through to the provider. The range depends on the provider and model.
4075
+ It is recommended to set either `temperature` or `topP`, but not both.
4076
+ @param topK - Only sample from the top K options for each subsequent token.
4077
+ Used to remove "long tail" low probability responses.
4078
+ Recommended for advanced use cases only. You usually only need to use temperature.
4079
+ @param presencePenalty - Presence penalty setting.
4080
+ It affects the likelihood of the model to repeat information that is already in the prompt.
4081
+ The value is passed through to the provider. The range depends on the provider and model.
4082
+ @param frequencyPenalty - Frequency penalty setting.
4083
+ It affects the likelihood of the model to repeatedly use the same words or phrases.
4084
+ The value is passed through to the provider. The range depends on the provider and model.
4085
+ @param stopSequences - Stop sequences.
4086
+ If set, the model will stop generating text when one of the stop sequences is generated.
4087
+ @param seed - The seed (integer) to use for random sampling.
4088
+ If set and supported by the model, calls will generate deterministic results.
4089
+
4090
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
4091
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
4092
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
4093
+
4094
+ @param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
4095
+ @param experimental_generateMessageId - Generate a unique ID for each message.
4096
+
4097
+ @param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
4098
+ @param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
4099
+ @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
4100
+ @param onFinish - Callback that is called when the LLM response and all request tool executions
4101
+ (for tools that have an `execute` function) are finished.
4102
+
4103
+ @return
4104
+ A result object for accessing different stream types and additional information.
4105
+ */
4106
+ declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxSteps, experimental_generateMessageId: generateMessageId, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, experimental_providerMetadata, providerOptions, experimental_toolCallStreaming, toolCallStreaming, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, onChunk, onError, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
4107
+ /**
4108
+ The language model to use.
4109
+ */
4110
+ model: LanguageModel;
4111
+ /**
4112
+ The tools that the model can call. The model needs to support calling tools.
4113
+ */
4114
+ tools?: TOOLS;
4115
+ /**
4116
+ The tool choice strategy. Default: 'auto'.
4117
+ */
4118
+ toolChoice?: ToolChoice<TOOLS>;
4119
+ /**
4120
+ Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
4121
+
4122
+ A maximum number is required to prevent infinite loops in the case of misconfigured tools.
4123
+
4124
+ By default, it's set to 1, which means that only a single LLM call is made.
4125
+ */
4126
+ maxSteps?: number;
4127
+ /**
4128
+ Generate a unique ID for each message.
4129
+ */
4130
+ experimental_generateMessageId?: IDGenerator;
4131
+ /**
4132
+ When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
4133
+
4134
+ By default, it's set to false.
4135
+ */
4136
+ experimental_continueSteps?: boolean;
4137
+ /**
4138
+ Optional telemetry configuration (experimental).
4139
+ */
4140
+ experimental_telemetry?: TelemetrySettings;
4141
+ /**
4142
+ Additional provider-specific options. They are passed through
4143
+ to the provider from the AI SDK and enable provider-specific
4144
+ functionality that can be fully encapsulated in the provider.
4145
+ */
4146
+ providerOptions?: ProviderOptions;
4147
+ /**
4148
+ @deprecated Use `providerOptions` instead.
4149
+ */
4150
+ experimental_providerMetadata?: ProviderMetadata;
4151
+ /**
4152
+ Limits the tools that are available for the model to call without
4153
+ changing the tool call and result types in the result.
4154
+ */
4155
+ experimental_activeTools?: Array<keyof TOOLS>;
4156
+ /**
4157
+ Optional specification for parsing structured outputs from the LLM response.
4158
+ */
4159
+ experimental_output?: Output<OUTPUT, PARTIAL_OUTPUT>;
4160
+ /**
4161
+ A function that attempts to repair a tool call that failed to parse.
4162
+ */
4163
+ experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
4164
+ /**
4165
+ Enable streaming of tool call deltas as they are generated. Disabled by default.
4166
+ */
4167
+ toolCallStreaming?: boolean;
4168
+ /**
4169
+ @deprecated Use `toolCallStreaming` instead.
4170
+ */
4171
+ experimental_toolCallStreaming?: boolean;
4172
+ /**
4173
+ Optional stream transformations.
4174
+ They are applied in the order they are provided.
4175
+ The stream transformations must maintain the stream structure for streamText to work correctly.
4176
+ */
4177
+ experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
4178
+ /**
4179
+ Callback that is called for each chunk of the stream.
4180
+ The stream processing will pause until the callback promise is resolved.
4181
+ */
4182
+ onChunk?: StreamTextOnChunkCallback<TOOLS>;
4183
+ /**
4184
+ Callback that is invoked when an error occurs during streaming.
4185
+ You can use it to log errors.
4186
+ The stream processing will pause until the callback promise is resolved.
4187
+ */
4188
+ onError?: StreamTextOnErrorCallback;
4189
+ /**
4190
+ Callback that is called when the LLM response and all request tool executions
4191
+ (for tools that have an `execute` function) are finished.
4192
+
4193
+ The usage is the combined usage of all steps.
4194
+ */
4195
+ onFinish?: StreamTextOnFinishCallback<TOOLS>;
4196
+ /**
4197
+ Callback that is called when each step (LLM call) is finished, including intermediate steps.
4198
+ */
4199
+ onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
4200
+ /**
4201
+ Internal. For test use only. May change without notice.
4202
+ */
4203
+ _internal?: {
4204
+ now?: () => number;
4205
+ generateId?: IDGenerator;
4206
+ currentDate?: () => Date;
4207
+ };
4208
+ }): StreamTextResult<TOOLS, PARTIAL_OUTPUT>;
4209
+
4210
+ export { type AssistantContent as A, type CoreMessage as C, type DeepPartial as D, type EmbeddingModel as E, type GenerateTextResult as G, type HrTime as H, type JSONSchema7 as J, type Link as L, type Message as M, type SpanAttributes as S, type Tool as T, type UserContent as U, type ToolExecutionOptions as a, SpanKind as b, type SpanContext as c, type SpanStatus as d, type Tracer as e, type Span as f, type LanguageModel as g, type LanguageModelV1 as h, type ToolContent as i, type TelemetrySettings as j, generateText as k, generateObject as l, type GenerateObjectResult as m, type StreamTextResult as n, streamObject as o, type StreamObjectResult as p, type CoreUserMessage as q, streamText as s };