ai 0.0.0-156c9f7b-20250115085202 → 0.0.0-677c097b-20250505090413

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,14 +1,67 @@
1
- import { DataStreamString, ToolInvocation, Attachment, Schema, DeepPartial, JSONValue as JSONValue$1, AssistantMessage, DataMessage } from '@ai-sdk/ui-utils';
2
- export { AssistantMessage, AssistantStatus, Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataMessage, DataStreamPart, DeepPartial, IdGenerator, JSONValue, Message, RequestOptions, Schema, ToolInvocation, UseAssistantOptions, formatAssistantStreamPart, formatDataStreamPart, jsonSchema, parseAssistantStreamPart, parseDataStreamPart, processDataStream, processTextStream } from '@ai-sdk/ui-utils';
3
- export { ToolCall as CoreToolCall, ToolResult as CoreToolResult, generateId } from '@ai-sdk/provider-utils';
4
- import { JSONValue, EmbeddingModelV1, EmbeddingModelV1Embedding, ImageModelV1, ImageModelV1CallWarning, LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, LanguageModelV1CallOptions, AISDKError, LanguageModelV1FunctionToolCall, JSONSchema7, NoSuchModelError } from '@ai-sdk/provider';
1
+ import { IDGenerator } from '@ai-sdk/provider-utils';
2
+ export { CoreToolCall, CoreToolResult, IDGenerator, ToolCall, ToolResult, createIdGenerator, generateId } from '@ai-sdk/provider-utils';
3
+ import { DataStreamString, Message, Schema, DeepPartial, JSONValue as JSONValue$1, AssistantMessage, DataMessage } from '@ai-sdk/ui-utils';
4
+ export { AssistantMessage, AssistantStatus, Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataMessage, DataStreamPart, DeepPartial, IdGenerator, JSONValue, Message, RequestOptions, Schema, ToolInvocation, UIMessage, UseAssistantOptions, formatAssistantStreamPart, formatDataStreamPart, jsonSchema, parseAssistantStreamPart, parseDataStreamPart, processDataStream, processTextStream, zodSchema } from '@ai-sdk/ui-utils';
5
+ import { LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1CallWarning, LanguageModelV1Source, JSONValue, EmbeddingModelV1, EmbeddingModelV1Embedding, ImageModelV1, ImageModelV1CallWarning, LanguageModelV1ProviderMetadata, TranscriptionModelV1, TranscriptionModelV1CallWarning, SpeechModelV1, SpeechModelV1CallWarning, LanguageModelV1CallOptions, AISDKError, LanguageModelV1FunctionToolCall, JSONSchema7, JSONParseError, TypeValidationError, ProviderV1, NoSuchModelError } from '@ai-sdk/provider';
5
6
  export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, LanguageModelV1, LanguageModelV1CallOptions, LanguageModelV1Prompt, LanguageModelV1StreamPart, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
6
7
  import { ServerResponse } from 'node:http';
7
8
  import { AttributeValue, Tracer } from '@opentelemetry/api';
8
9
  import { z } from 'zod';
9
10
  import { ServerResponse as ServerResponse$1 } from 'http';
10
11
 
12
+ /**
13
+ Language model that is used by the AI SDK Core functions.
14
+ */
15
+ type LanguageModel = LanguageModelV1;
16
+ /**
17
+ Reason why a language model finished generating a response.
18
+
19
+ Can be one of the following:
20
+ - `stop`: model generated stop sequence
21
+ - `length`: model generated maximum number of tokens
22
+ - `content-filter`: content filter violation stopped the model
23
+ - `tool-calls`: model triggered tool calls
24
+ - `error`: model stopped because of an error
25
+ - `other`: model stopped for other reasons
26
+ */
27
+ type FinishReason = LanguageModelV1FinishReason;
28
+ /**
29
+ Log probabilities for each token and its top log probabilities.
30
+
31
+ @deprecated Will become a provider extension in the future.
32
+ */
33
+ type LogProbs = LanguageModelV1LogProbs;
34
+ /**
35
+ Warning from the model provider for this call. The call will proceed, but e.g.
36
+ some settings might not be supported, which can lead to suboptimal results.
37
+ */
38
+ type CallWarning = LanguageModelV1CallWarning;
39
+ /**
40
+ A source that has been used as input to generate the response.
41
+ */
42
+ type Source = LanguageModelV1Source;
43
+ /**
44
+ Tool choice for the generation. It supports the following settings:
45
+
46
+ - `auto` (default): the model can choose whether and which tools to call.
47
+ - `required`: the model must call a tool. It can choose which tool to call.
48
+ - `none`: the model must not call tools
49
+ - `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
50
+ */
51
+ type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
52
+ type: 'tool';
53
+ toolName: keyof TOOLS;
54
+ };
55
+ /**
56
+ * @deprecated Use `ToolChoice` instead.
57
+ */
58
+ type CoreToolChoice<TOOLS extends Record<string, unknown>> = ToolChoice<TOOLS>;
59
+
11
60
  interface DataStreamWriter {
61
+ /**
62
+ * Appends a data part to the stream.
63
+ */
64
+ write(data: DataStreamString): void;
12
65
  /**
13
66
  * Appends a data part to the stream.
14
67
  */
@@ -17,6 +70,10 @@ interface DataStreamWriter {
17
70
  * Appends a message annotation to the stream.
18
71
  */
19
72
  writeMessageAnnotation(value: JSONValue): void;
73
+ /**
74
+ * Appends a source part to the stream.
75
+ */
76
+ writeSource(source: Source): void;
20
77
  /**
21
78
  * Merges the contents of another stream to this stream.
22
79
  */
@@ -99,44 +156,19 @@ some settings might not be supported, which can lead to suboptimal results.
99
156
  */
100
157
  type ImageGenerationWarning = ImageModelV1CallWarning;
101
158
 
102
- /**
103
- Language model that is used by the AI SDK Core functions.
104
- */
105
- type LanguageModel = LanguageModelV1;
106
- /**
107
- Reason why a language model finished generating a response.
108
-
109
- Can be one of the following:
110
- - `stop`: model generated stop sequence
111
- - `length`: model generated maximum number of tokens
112
- - `content-filter`: content filter violation stopped the model
113
- - `tool-calls`: model triggered tool calls
114
- - `error`: model stopped because of an error
115
- - `other`: model stopped for other reasons
116
- */
117
- type FinishReason = LanguageModelV1FinishReason;
118
- /**
119
- Log probabilities for each token and its top log probabilities.
120
-
121
- @deprecated Will become a provider extension in the future.
122
- */
123
- type LogProbs = LanguageModelV1LogProbs;
124
- /**
125
- Warning from the model provider for this call. The call will proceed, but e.g.
126
- some settings might not be supported, which can lead to suboptimal results.
127
- */
128
- type CallWarning = LanguageModelV1CallWarning;
129
- /**
130
- Tool choice for the generation. It supports the following settings:
131
-
132
- - `auto` (default): the model can choose whether and which tools to call.
133
- - `required`: the model must call a tool. It can choose which tool to call.
134
- - `none`: the model must not call tools
135
- - `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
136
- */
137
- type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
138
- type: 'tool';
139
- toolName: keyof TOOLS;
159
+ type ImageModelResponseMetadata = {
160
+ /**
161
+ Timestamp for the start of the generated response.
162
+ */
163
+ timestamp: Date;
164
+ /**
165
+ The ID of the response model that was used to generate the response.
166
+ */
167
+ modelId: string;
168
+ /**
169
+ Response headers.
170
+ */
171
+ headers?: Record<string, string>;
140
172
  };
141
173
 
142
174
  type LanguageModelRequestMetadata = {
@@ -160,13 +192,13 @@ type LanguageModelResponseMetadata = {
160
192
  */
161
193
  modelId: string;
162
194
  /**
163
- Response headers.
195
+ Response headers (available only for providers that use HTTP requests).
164
196
  */
165
197
  headers?: Record<string, string>;
166
198
  };
167
199
 
168
200
  /**
169
- * Provider for language and text embedding models.
201
+ * Provider for language, text embedding, and image models.
170
202
  */
171
203
  type Provider = {
172
204
  /**
@@ -191,14 +223,31 @@ type Provider = {
191
223
  @throws {NoSuchModelError} If no such model exists.
192
224
  */
193
225
  textEmbeddingModel(modelId: string): EmbeddingModel<string>;
226
+ /**
227
+ Returns the image model with the given id.
228
+ The model id is then passed to the provider function to get the model.
229
+
230
+ @param {string} id - The id of the model to return.
231
+
232
+ @returns {ImageModel} The image model associated with the id
233
+ */
234
+ imageModel(modelId: string): ImageModel;
194
235
  };
195
236
 
196
237
  /**
197
- Additional provider-specific metadata. They are passed through
198
- to the provider from the AI SDK and enable provider-specific
199
- functionality that can be fully encapsulated in the provider.
238
+ Additional provider-specific metadata that is returned from the provider.
239
+
240
+ This is needed to enable provider-specific functionality that can be
241
+ fully encapsulated in the provider.
200
242
  */
201
243
  type ProviderMetadata = LanguageModelV1ProviderMetadata;
244
+ /**
245
+ Additional provider-specific options.
246
+
247
+ They are passed through to the provider from the AI SDK and enable
248
+ provider-specific functionality that can be fully encapsulated in the provider.
249
+ */
250
+ type ProviderOptions = LanguageModelV1ProviderMetadata;
202
251
 
203
252
  /**
204
253
  Represents the number of tokens used in a prompt and completion.
@@ -227,6 +276,56 @@ type EmbeddingModelUsage = {
227
276
  tokens: number;
228
277
  };
229
278
 
279
+ /**
280
+ Transcription model that is used by the AI SDK Core functions.
281
+ */
282
+ type TranscriptionModel = TranscriptionModelV1;
283
+ /**
284
+ Warning from the model provider for this call. The call will proceed, but e.g.
285
+ some settings might not be supported, which can lead to suboptimal results.
286
+ */
287
+ type TranscriptionWarning = TranscriptionModelV1CallWarning;
288
+
289
+ type TranscriptionModelResponseMetadata = {
290
+ /**
291
+ Timestamp for the start of the generated response.
292
+ */
293
+ timestamp: Date;
294
+ /**
295
+ The ID of the response model that was used to generate the response.
296
+ */
297
+ modelId: string;
298
+ /**
299
+ Response headers.
300
+ */
301
+ headers?: Record<string, string>;
302
+ };
303
+
304
+ /**
305
+ Speech model that is used by the AI SDK Core functions.
306
+ */
307
+ type SpeechModel = SpeechModelV1;
308
+ /**
309
+ Warning from the model provider for this call. The call will proceed, but e.g.
310
+ some settings might not be supported, which can lead to suboptimal results.
311
+ */
312
+ type SpeechWarning = SpeechModelV1CallWarning;
313
+
314
+ type SpeechModelResponseMetadata = {
315
+ /**
316
+ Timestamp for the start of the generated response.
317
+ */
318
+ timestamp: Date;
319
+ /**
320
+ The ID of the response model that was used to generate the response.
321
+ */
322
+ modelId: string;
323
+ /**
324
+ Response headers.
325
+ */
326
+ headers?: Record<string, string>;
327
+ };
328
+
230
329
  /**
231
330
  The result of an `embed` call.
232
331
  It contains the embedding, the value, and additional information.
@@ -362,109 +461,6 @@ declare function embedMany<VALUE>({ model, values, maxRetries: maxRetriesArg, ab
362
461
  experimental_telemetry?: TelemetrySettings;
363
462
  }): Promise<EmbedManyResult<VALUE>>;
364
463
 
365
- /**
366
- The result of a `generateImage` call.
367
- It contains the images and additional information.
368
- */
369
- interface GenerateImageResult {
370
- /**
371
- The first image that was generated.
372
- */
373
- readonly image: GeneratedImage;
374
- /**
375
- The images that were generated.
376
- */
377
- readonly images: Array<GeneratedImage>;
378
- /**
379
- Warnings for the call, e.g. unsupported settings.
380
- */
381
- readonly warnings: Array<ImageGenerationWarning>;
382
- }
383
- interface GeneratedImage {
384
- /**
385
- Image as a base64 encoded string.
386
- */
387
- readonly base64: string;
388
- /**
389
- Image as a Uint8Array.
390
- */
391
- readonly uint8Array: Uint8Array;
392
- }
393
-
394
- /**
395
- Generates images using an image model.
396
-
397
- @param model - The image model to use.
398
- @param prompt - The prompt that should be used to generate the image.
399
- @param n - Number of images to generate. Default: 1.
400
- @param size - Size of the images to generate. Must have the format `{width}x{height}`.
401
- @param aspectRatio - Aspect ratio of the images to generate. Must have the format `{width}:{height}`.
402
- @param seed - Seed for the image generation.
403
- @param providerOptions - Additional provider-specific options that are passed through to the provider
404
- as body parameters.
405
- @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
406
- @param abortSignal - An optional abort signal that can be used to cancel the call.
407
- @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
408
-
409
- @returns A result object that contains the generated images.
410
- */
411
- declare function generateImage({ model, prompt, n, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
412
- /**
413
- The image model to use.
414
- */
415
- model: ImageModelV1;
416
- /**
417
- The prompt that should be used to generate the image.
418
- */
419
- prompt: string;
420
- /**
421
- Number of images to generate.
422
- */
423
- n?: number;
424
- /**
425
- Size of the images to generate. Must have the format `{width}x{height}`. If not provided, the default size will be used.
426
- */
427
- size?: `${number}x${number}`;
428
- /**
429
- Aspect ratio of the images to generate. Must have the format `{width}:{height}`. If not provided, the default aspect ratio will be used.
430
- */
431
- aspectRatio?: `${number}:${number}`;
432
- /**
433
- Seed for the image generation. If not provided, the default seed will be used.
434
- */
435
- seed?: number;
436
- /**
437
- Additional provider-specific options that are passed through to the provider
438
- as body parameters.
439
-
440
- The outer record is keyed by the provider name, and the inner
441
- record is keyed by the provider-specific metadata key.
442
- ```ts
443
- {
444
- "openai": {
445
- "style": "vivid"
446
- }
447
- }
448
- ```
449
- */
450
- providerOptions?: Record<string, Record<string, JSONValue>>;
451
- /**
452
- Maximum number of retries per embedding model call. Set to 0 to disable retries.
453
-
454
- @default 2
455
- */
456
- maxRetries?: number;
457
- /**
458
- Abort signal.
459
- */
460
- abortSignal?: AbortSignal;
461
- /**
462
- Additional headers to include in the request.
463
- Only applicable for HTTP-based providers.
464
- */
465
- headers?: Record<string, string>;
466
- }): Promise<GenerateImageResult>;
467
-
468
464
  type CallSettings = {
469
465
  /**
470
466
  Maximum number of tokens to generate.
@@ -566,6 +562,10 @@ interface TextPart {
566
562
  Additional provider-specific metadata. They are passed through
567
563
  to the provider from the AI SDK and enable provider-specific
568
564
  functionality that can be fully encapsulated in the provider.
565
+ */
566
+ providerOptions?: ProviderOptions;
567
+ /**
568
+ @deprecated Use `providerOptions` instead.
569
569
  */
570
570
  experimental_providerMetadata?: ProviderMetadata;
571
571
  }
@@ -589,6 +589,10 @@ interface ImagePart {
589
589
  Additional provider-specific metadata. They are passed through
590
590
  to the provider from the AI SDK and enable provider-specific
591
591
  functionality that can be fully encapsulated in the provider.
592
+ */
593
+ providerOptions?: ProviderOptions;
594
+ /**
595
+ @deprecated Use `providerOptions` instead.
592
596
  */
593
597
  experimental_providerMetadata?: ProviderMetadata;
594
598
  }
@@ -605,6 +609,10 @@ interface FilePart {
605
609
  */
606
610
  data: DataContent | URL;
607
611
  /**
612
+ Optional filename of the file.
613
+ */
614
+ filename?: string;
615
+ /**
608
616
  Mime type of the file.
609
617
  */
610
618
  mimeType: string;
@@ -612,16 +620,64 @@ interface FilePart {
612
620
  Additional provider-specific metadata. They are passed through
613
621
  to the provider from the AI SDK and enable provider-specific
614
622
  functionality that can be fully encapsulated in the provider.
623
+ */
624
+ providerOptions?: ProviderOptions;
625
+ /**
626
+ @deprecated Use `providerOptions` instead.
615
627
  */
616
628
  experimental_providerMetadata?: ProviderMetadata;
617
629
  }
618
630
  /**
619
- Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
631
+ * Reasoning content part of a prompt. It contains a reasoning.
620
632
  */
621
- interface ToolCallPart {
622
- type: 'tool-call';
633
+ interface ReasoningPart {
634
+ type: 'reasoning';
623
635
  /**
624
- ID of the tool call. This ID is used to match the tool call with the tool result.
636
+ The reasoning text.
637
+ */
638
+ text: string;
639
+ /**
640
+ An optional signature for verifying that the reasoning originated from the model.
641
+ */
642
+ signature?: string;
643
+ /**
644
+ Additional provider-specific metadata. They are passed through
645
+ to the provider from the AI SDK and enable provider-specific
646
+ functionality that can be fully encapsulated in the provider.
647
+ */
648
+ providerOptions?: ProviderOptions;
649
+ /**
650
+ @deprecated Use `providerOptions` instead.
651
+ */
652
+ experimental_providerMetadata?: ProviderMetadata;
653
+ }
654
+ /**
655
+ Redacted reasoning content part of a prompt.
656
+ */
657
+ interface RedactedReasoningPart {
658
+ type: 'redacted-reasoning';
659
+ /**
660
+ Redacted reasoning data.
661
+ */
662
+ data: string;
663
+ /**
664
+ Additional provider-specific metadata. They are passed through
665
+ to the provider from the AI SDK and enable provider-specific
666
+ functionality that can be fully encapsulated in the provider.
667
+ */
668
+ providerOptions?: ProviderOptions;
669
+ /**
670
+ @deprecated Use `providerOptions` instead.
671
+ */
672
+ experimental_providerMetadata?: ProviderMetadata;
673
+ }
674
+ /**
675
+ Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
676
+ */
677
+ interface ToolCallPart {
678
+ type: 'tool-call';
679
+ /**
680
+ ID of the tool call. This ID is used to match the tool call with the tool result.
625
681
  */
626
682
  toolCallId: string;
627
683
  /**
@@ -636,6 +692,10 @@ interface ToolCallPart {
636
692
  Additional provider-specific metadata. They are passed through
637
693
  to the provider from the AI SDK and enable provider-specific
638
694
  functionality that can be fully encapsulated in the provider.
695
+ */
696
+ providerOptions?: ProviderOptions;
697
+ /**
698
+ @deprecated Use `providerOptions` instead.
639
699
  */
640
700
  experimental_providerMetadata?: ProviderMetadata;
641
701
  }
@@ -668,6 +728,10 @@ interface ToolResultPart {
668
728
  Additional provider-specific metadata. They are passed through
669
729
  to the provider from the AI SDK and enable provider-specific
670
730
  functionality that can be fully encapsulated in the provider.
731
+ */
732
+ providerOptions?: ProviderOptions;
733
+ /**
734
+ @deprecated Use `providerOptions` instead.
671
735
  */
672
736
  experimental_providerMetadata?: ProviderMetadata;
673
737
  }
@@ -686,9 +750,14 @@ type CoreSystemMessage = {
686
750
  Additional provider-specific metadata. They are passed through
687
751
  to the provider from the AI SDK and enable provider-specific
688
752
  functionality that can be fully encapsulated in the provider.
753
+ */
754
+ providerOptions?: ProviderOptions;
755
+ /**
756
+ @deprecated Use `providerOptions` instead.
689
757
  */
690
758
  experimental_providerMetadata?: ProviderMetadata;
691
759
  };
760
+ declare const coreSystemMessageSchema: z.ZodType<CoreSystemMessage>;
692
761
  /**
693
762
  A user message. It can contain text or a combination of text and images.
694
763
  */
@@ -700,8 +769,13 @@ type CoreUserMessage = {
700
769
  to the provider from the AI SDK and enable provider-specific
701
770
  functionality that can be fully encapsulated in the provider.
702
771
  */
772
+ providerOptions?: ProviderOptions;
773
+ /**
774
+ @deprecated Use `providerOptions` instead.
775
+ */
703
776
  experimental_providerMetadata?: ProviderMetadata;
704
777
  };
778
+ declare const coreUserMessageSchema: z.ZodType<CoreUserMessage>;
705
779
  /**
706
780
  Content of a user message. It can be a string or an array of text and image parts.
707
781
  */
@@ -717,12 +791,18 @@ type CoreAssistantMessage = {
717
791
  to the provider from the AI SDK and enable provider-specific
718
792
  functionality that can be fully encapsulated in the provider.
719
793
  */
794
+ providerOptions?: ProviderOptions;
795
+ /**
796
+ @deprecated Use `providerOptions` instead.
797
+ */
720
798
  experimental_providerMetadata?: ProviderMetadata;
721
799
  };
800
+ declare const coreAssistantMessageSchema: z.ZodType<CoreAssistantMessage>;
722
801
  /**
723
- Content of an assistant message. It can be a string or an array of text and tool call parts.
802
+ Content of an assistant message.
803
+ It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts.
724
804
  */
725
- type AssistantContent = string | Array<TextPart | ToolCallPart>;
805
+ type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | RedactedReasoningPart | ToolCallPart>;
726
806
  /**
727
807
  A tool message. It contains the result of one or more tool calls.
728
808
  */
@@ -734,8 +814,13 @@ type CoreToolMessage = {
734
814
  to the provider from the AI SDK and enable provider-specific
735
815
  functionality that can be fully encapsulated in the provider.
736
816
  */
817
+ providerOptions?: ProviderOptions;
818
+ /**
819
+ @deprecated Use `providerOptions` instead.
820
+ */
737
821
  experimental_providerMetadata?: ProviderMetadata;
738
822
  };
823
+ declare const coreToolMessageSchema: z.ZodType<CoreToolMessage>;
739
824
  /**
740
825
  Content of a tool message. It is an array of tool result parts.
741
826
  */
@@ -745,13 +830,7 @@ A message that can be used in the `messages` field of a prompt.
745
830
  It can be a user message, an assistant message, or a tool message.
746
831
  */
747
832
  type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
748
-
749
- type UIMessage = {
750
- role: 'system' | 'user' | 'assistant' | 'data';
751
- content: string;
752
- toolInvocations?: ToolInvocation[];
753
- experimental_attachments?: Attachment[];
754
- };
833
+ declare const coreMessageSchema: z.ZodType<CoreMessage>;
755
834
 
756
835
  /**
757
836
  Prompt part of the AI function options.
@@ -769,825 +848,1407 @@ type Prompt = {
769
848
  /**
770
849
  A list of messages. You can either use `prompt` or `messages` but not both.
771
850
  */
772
- messages?: Array<CoreMessage> | Array<UIMessage>;
851
+ messages?: Array<CoreMessage> | Array<Omit<Message, 'id'>>;
773
852
  };
774
853
 
775
854
  /**
776
- The result of a `generateObject` call.
855
+ * A generated file.
777
856
  */
778
- interface GenerateObjectResult<OBJECT> {
779
- /**
780
- The generated object (typed according to the schema).
781
- */
782
- readonly object: OBJECT;
783
- /**
784
- The reason why the generation finished.
785
- */
786
- readonly finishReason: FinishReason;
857
+ interface GeneratedFile {
787
858
  /**
788
- The token usage of the generated text.
859
+ File as a base64 encoded string.
789
860
  */
790
- readonly usage: LanguageModelUsage;
861
+ readonly base64: string;
791
862
  /**
792
- Warnings from the model provider (e.g. unsupported settings).
863
+ File as a Uint8Array.
793
864
  */
794
- readonly warnings: CallWarning[] | undefined;
865
+ readonly uint8Array: Uint8Array;
795
866
  /**
796
- Additional request information.
867
+ MIME type of the file
797
868
  */
798
- readonly request: LanguageModelRequestMetadata;
869
+ readonly mimeType: string;
870
+ }
871
+
872
+ type ReasoningDetail = {
873
+ type: 'text';
874
+ text: string;
875
+ signature?: string;
876
+ } | {
877
+ type: 'redacted';
878
+ data: string;
879
+ };
880
+
881
+ type ToolParameters = z.ZodTypeAny | Schema<any>;
882
+ type inferParameters<PARAMETERS extends ToolParameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
883
+ interface ToolExecutionOptions {
799
884
  /**
800
- Additional response information.
885
+ * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
801
886
  */
802
- readonly response: LanguageModelResponseMetadata;
803
- /**
804
- Logprobs for the completion.
805
- `undefined` if the mode does not support logprobs or if was not enabled.
806
-
807
- @deprecated Will become a provider extension in the future.
808
- */
809
- readonly logprobs: LogProbs | undefined;
887
+ toolCallId: string;
810
888
  /**
811
- Additional provider-specific metadata. They are passed through
812
- from the provider to the AI SDK and enable provider-specific
813
- results that can be fully encapsulated in the provider.
889
+ * Messages that were sent to the language model to initiate the response that contained the tool call.
890
+ * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
814
891
  */
815
- readonly experimental_providerMetadata: ProviderMetadata | undefined;
892
+ messages: CoreMessage[];
816
893
  /**
817
- Converts the object to a JSON response.
818
- The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
819
- */
820
- toJsonResponse(init?: ResponseInit): Response;
894
+ * An optional abort signal that indicates that the overall operation should be aborted.
895
+ */
896
+ abortSignal?: AbortSignal;
821
897
  }
822
-
823
898
  /**
824
- Generate a structured, typed object for a given prompt and schema using a language model.
825
-
826
- This function does not stream the output. If you want to stream the output, use `streamObject` instead.
899
+ A tool contains the description and the schema of the input that the tool expects.
900
+ This enables the language model to generate the input.
827
901
 
828
- @returns
829
- A result object that contains the generated object, the finish reason, the token usage, and additional information.
902
+ The tool can also contain an optional execute function for the actual execution function of the tool.
830
903
  */
831
- declare function generateObject<OBJECT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
832
- output?: 'object' | undefined;
904
+ type Tool<PARAMETERS extends ToolParameters = any, RESULT = any> = {
833
905
  /**
834
- The language model to use.
835
- */
836
- model: LanguageModel;
906
+ The schema of the input that the tool expects. The language model will use this to generate the input.
907
+ It is also used to validate the output of the language model.
908
+ Use descriptions to make the input understandable for the language model.
909
+ */
910
+ parameters: PARAMETERS;
837
911
  /**
838
- The schema of the object that the model should generate.
839
- */
840
- schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT>;
912
+ An optional description of what the tool does.
913
+ Will be used by the language model to decide whether to use the tool.
914
+ Not used for provider-defined tools.
915
+ */
916
+ description?: string;
841
917
  /**
842
- Optional name of the output that should be generated.
843
- Used by some providers for additional LLM guidance, e.g.
844
- via tool or schema name.
845
- */
846
- schemaName?: string;
918
+ Optional conversion function that maps the tool result to multi-part tool content for LLMs.
919
+ */
920
+ experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
847
921
  /**
848
- Optional description of the output that should be generated.
849
- Used by some providers for additional LLM guidance, e.g.
850
- via tool or schema description.
851
- */
852
- schemaDescription?: string;
922
+ An async function that is called with the arguments from the tool call and produces a result.
923
+ If not provided, the tool will not be executed automatically.
924
+
925
+ @args is the input of the tool call.
926
+ @options.abortSignal is a signal that can be used to abort the tool call.
927
+ */
928
+ execute?: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
929
+ } & ({
853
930
  /**
854
- The mode to use for object generation.
855
-
856
- The schema is converted into a JSON schema and used in one of the following ways
857
-
858
- - 'auto': The provider will choose the best mode for the model.
859
- - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
860
- - '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.
861
-
862
- Please note that most providers do not support all modes.
863
-
864
- Default and recommended: 'auto' (best mode for the model).
865
- */
866
- mode?: 'auto' | 'json' | 'tool';
931
+ Function tool.
932
+ */
933
+ type?: undefined | 'function';
934
+ } | {
867
935
  /**
868
- Optional telemetry configuration (experimental).
936
+ Provider-defined tool.
869
937
  */
870
- experimental_telemetry?: TelemetrySettings;
938
+ type: 'provider-defined';
871
939
  /**
872
- Additional provider-specific metadata. They are passed through
873
- to the provider from the AI SDK and enable provider-specific
874
- functionality that can be fully encapsulated in the provider.
875
- */
876
- experimental_providerMetadata?: ProviderMetadata;
940
+ The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
941
+ */
942
+ id: `${string}.${string}`;
877
943
  /**
878
- * Internal. For test use only. May change without notice.
944
+ The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
879
945
  */
880
- _internal?: {
881
- generateId?: () => string;
882
- currentDate?: () => Date;
883
- };
884
- }): Promise<GenerateObjectResult<OBJECT>>;
946
+ args: Record<string, unknown>;
947
+ });
885
948
  /**
886
- Generate an array with structured, typed elements for a given prompt and element schema using a language model.
949
+ * @deprecated Use `Tool` instead.
950
+ */
951
+ type CoreTool<PARAMETERS extends ToolParameters = any, RESULT = any> = Tool<PARAMETERS, RESULT>;
952
+ /**
953
+ Helper function for inferring the execute args of a tool.
954
+ */
955
+ declare function tool<PARAMETERS extends ToolParameters, RESULT>(tool: Tool<PARAMETERS, RESULT> & {
956
+ execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
957
+ }): Tool<PARAMETERS, RESULT> & {
958
+ execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
959
+ };
960
+ declare function tool<PARAMETERS extends ToolParameters, RESULT>(tool: Tool<PARAMETERS, RESULT> & {
961
+ execute?: undefined;
962
+ }): Tool<PARAMETERS, RESULT> & {
963
+ execute: undefined;
964
+ };
887
965
 
888
- This function does not stream the output. If you want to stream the output, use `streamObject` instead.
966
+ /**
967
+ Create a union of the given object's values, and optionally specify which keys to get the values from.
889
968
 
890
- @return
891
- A result object that contains the generated object, the finish reason, the token usage, and additional information.
892
- */
893
- declare function generateObject<ELEMENT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
894
- output: 'array';
895
- /**
896
- The language model to use.
897
- */
898
- model: LanguageModel;
899
- /**
900
- The element schema of the array that the model should generate.
901
- */
902
- schema: z.Schema<ELEMENT, z.ZodTypeDef, any> | Schema<ELEMENT>;
903
- /**
904
- Optional name of the array that should be generated.
905
- Used by some providers for additional LLM guidance, e.g.
906
- via tool or schema name.
907
- */
908
- schemaName?: string;
909
- /**
910
- Optional description of the array that should be generated.
911
- Used by some providers for additional LLM guidance, e.g.
912
- via tool or schema description.
913
- */
914
- schemaDescription?: string;
915
- /**
916
- The mode to use for object generation.
969
+ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
917
970
 
918
- The schema is converted into a JSON schema and used in one of the following ways
971
+ @example
972
+ ```
973
+ // data.json
974
+ {
975
+ 'foo': 1,
976
+ 'bar': 2,
977
+ 'biz': 3
978
+ }
919
979
 
920
- - 'auto': The provider will choose the best mode for the model.
921
- - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
922
- - '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.
980
+ // main.ts
981
+ import type {ValueOf} from 'type-fest';
982
+ import data = require('./data.json');
923
983
 
924
- Please note that most providers do not support all modes.
984
+ export function getData(name: string): ValueOf<typeof data> {
985
+ return data[name];
986
+ }
925
987
 
926
- Default and recommended: 'auto' (best mode for the model).
927
- */
928
- mode?: 'auto' | 'json' | 'tool';
929
- /**
930
- Optional telemetry configuration (experimental).
931
- */
932
- experimental_telemetry?: TelemetrySettings;
933
- /**
934
- Additional provider-specific metadata. They are passed through
935
- to the provider from the AI SDK and enable provider-specific
936
- functionality that can be fully encapsulated in the provider.
937
- */
938
- experimental_providerMetadata?: ProviderMetadata;
939
- /**
940
- * Internal. For test use only. May change without notice.
941
- */
942
- _internal?: {
943
- generateId?: () => string;
944
- currentDate?: () => Date;
945
- };
946
- }): Promise<GenerateObjectResult<Array<ELEMENT>>>;
947
- /**
948
- Generate a value from an enum (limited list of string values) using a language model.
988
+ export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
989
+ return data[name];
990
+ }
949
991
 
950
- This function does not stream the output.
992
+ // file.ts
993
+ import {getData, onlyBar} from './main';
951
994
 
952
- @return
953
- A result object that contains the generated value, the finish reason, the token usage, and additional information.
954
- */
955
- declare function generateObject<ENUM extends string>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
956
- output: 'enum';
957
- /**
958
- The language model to use.
959
- */
960
- model: LanguageModel;
961
- /**
962
- The enum values that the model should use.
963
- */
964
- enum: Array<ENUM>;
965
- /**
966
- The mode to use for object generation.
995
+ getData('foo');
996
+ //=> 1
967
997
 
968
- The schema is converted into a JSON schema and used in one of the following ways
998
+ onlyBar('foo');
999
+ //=> TypeError ...
969
1000
 
970
- - 'auto': The provider will choose the best mode for the model.
971
- - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
972
- - '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.
1001
+ onlyBar('bar');
1002
+ //=> 2
1003
+ ```
1004
+ * @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
1005
+ */
1006
+ type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
973
1007
 
974
- Please note that most providers do not support all modes.
1008
+ declare const JSONRPCRequestSchema: z.ZodObject<z.objectUtil.extendShape<{
1009
+ jsonrpc: z.ZodLiteral<"2.0">;
1010
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
1011
+ }, {
1012
+ method: z.ZodString;
1013
+ params: z.ZodOptional<z.ZodObject<{
1014
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1015
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1016
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1017
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1018
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1019
+ }, z.ZodTypeAny, "passthrough">>>;
1020
+ }>, "strict", z.ZodTypeAny, {
1021
+ id: string | number;
1022
+ method: string;
1023
+ jsonrpc: "2.0";
1024
+ params?: z.objectOutputType<{
1025
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1026
+ }, z.ZodTypeAny, "passthrough"> | undefined;
1027
+ }, {
1028
+ id: string | number;
1029
+ method: string;
1030
+ jsonrpc: "2.0";
1031
+ params?: z.objectInputType<{
1032
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1033
+ }, z.ZodTypeAny, "passthrough"> | undefined;
1034
+ }>;
1035
+ type JSONRPCRequest = z.infer<typeof JSONRPCRequestSchema>;
1036
+ declare const JSONRPCResponseSchema: z.ZodObject<{
1037
+ jsonrpc: z.ZodLiteral<"2.0">;
1038
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
1039
+ result: z.ZodObject<{
1040
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1041
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1042
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1043
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1044
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1045
+ }, z.ZodTypeAny, "passthrough">>;
1046
+ }, "strict", z.ZodTypeAny, {
1047
+ result: {
1048
+ _meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
1049
+ } & {
1050
+ [k: string]: unknown;
1051
+ };
1052
+ id: string | number;
1053
+ jsonrpc: "2.0";
1054
+ }, {
1055
+ result: {
1056
+ _meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
1057
+ } & {
1058
+ [k: string]: unknown;
1059
+ };
1060
+ id: string | number;
1061
+ jsonrpc: "2.0";
1062
+ }>;
1063
+ type JSONRPCResponse = z.infer<typeof JSONRPCResponseSchema>;
1064
+ declare const JSONRPCErrorSchema: z.ZodObject<{
1065
+ jsonrpc: z.ZodLiteral<"2.0">;
1066
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
1067
+ error: z.ZodObject<{
1068
+ code: z.ZodNumber;
1069
+ message: z.ZodString;
1070
+ data: z.ZodOptional<z.ZodUnknown>;
1071
+ }, "strip", z.ZodTypeAny, {
1072
+ code: number;
1073
+ message: string;
1074
+ data?: unknown;
1075
+ }, {
1076
+ code: number;
1077
+ message: string;
1078
+ data?: unknown;
1079
+ }>;
1080
+ }, "strict", z.ZodTypeAny, {
1081
+ error: {
1082
+ code: number;
1083
+ message: string;
1084
+ data?: unknown;
1085
+ };
1086
+ id: string | number;
1087
+ jsonrpc: "2.0";
1088
+ }, {
1089
+ error: {
1090
+ code: number;
1091
+ message: string;
1092
+ data?: unknown;
1093
+ };
1094
+ id: string | number;
1095
+ jsonrpc: "2.0";
1096
+ }>;
1097
+ type JSONRPCError = z.infer<typeof JSONRPCErrorSchema>;
1098
+ declare const JSONRPCNotificationSchema: z.ZodObject<z.objectUtil.extendShape<{
1099
+ jsonrpc: z.ZodLiteral<"2.0">;
1100
+ }, {
1101
+ method: z.ZodString;
1102
+ params: z.ZodOptional<z.ZodObject<{
1103
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1104
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1105
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1106
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1107
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1108
+ }, z.ZodTypeAny, "passthrough">>>;
1109
+ }>, "strict", z.ZodTypeAny, {
1110
+ method: string;
1111
+ jsonrpc: "2.0";
1112
+ params?: z.objectOutputType<{
1113
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1114
+ }, z.ZodTypeAny, "passthrough"> | undefined;
1115
+ }, {
1116
+ method: string;
1117
+ jsonrpc: "2.0";
1118
+ params?: z.objectInputType<{
1119
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1120
+ }, z.ZodTypeAny, "passthrough"> | undefined;
1121
+ }>;
1122
+ type JSONRPCNotification = z.infer<typeof JSONRPCNotificationSchema>;
1123
+ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1124
+ jsonrpc: z.ZodLiteral<"2.0">;
1125
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
1126
+ }, {
1127
+ method: z.ZodString;
1128
+ params: z.ZodOptional<z.ZodObject<{
1129
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1130
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1131
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1132
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1133
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1134
+ }, z.ZodTypeAny, "passthrough">>>;
1135
+ }>, "strict", z.ZodTypeAny, {
1136
+ id: string | number;
1137
+ method: string;
1138
+ jsonrpc: "2.0";
1139
+ params?: z.objectOutputType<{
1140
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1141
+ }, z.ZodTypeAny, "passthrough"> | undefined;
1142
+ }, {
1143
+ id: string | number;
1144
+ method: string;
1145
+ jsonrpc: "2.0";
1146
+ params?: z.objectInputType<{
1147
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1148
+ }, z.ZodTypeAny, "passthrough"> | undefined;
1149
+ }>, z.ZodObject<z.objectUtil.extendShape<{
1150
+ jsonrpc: z.ZodLiteral<"2.0">;
1151
+ }, {
1152
+ method: z.ZodString;
1153
+ params: z.ZodOptional<z.ZodObject<{
1154
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1155
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1156
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1157
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1158
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1159
+ }, z.ZodTypeAny, "passthrough">>>;
1160
+ }>, "strict", z.ZodTypeAny, {
1161
+ method: string;
1162
+ jsonrpc: "2.0";
1163
+ params?: z.objectOutputType<{
1164
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1165
+ }, z.ZodTypeAny, "passthrough"> | undefined;
1166
+ }, {
1167
+ method: string;
1168
+ jsonrpc: "2.0";
1169
+ params?: z.objectInputType<{
1170
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1171
+ }, z.ZodTypeAny, "passthrough"> | undefined;
1172
+ }>, z.ZodObject<{
1173
+ jsonrpc: z.ZodLiteral<"2.0">;
1174
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
1175
+ result: z.ZodObject<{
1176
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1177
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1178
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1179
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1180
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1181
+ }, z.ZodTypeAny, "passthrough">>;
1182
+ }, "strict", z.ZodTypeAny, {
1183
+ result: {
1184
+ _meta?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
1185
+ } & {
1186
+ [k: string]: unknown;
1187
+ };
1188
+ id: string | number;
1189
+ jsonrpc: "2.0";
1190
+ }, {
1191
+ result: {
1192
+ _meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
1193
+ } & {
1194
+ [k: string]: unknown;
1195
+ };
1196
+ id: string | number;
1197
+ jsonrpc: "2.0";
1198
+ }>, z.ZodObject<{
1199
+ jsonrpc: z.ZodLiteral<"2.0">;
1200
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
1201
+ error: z.ZodObject<{
1202
+ code: z.ZodNumber;
1203
+ message: z.ZodString;
1204
+ data: z.ZodOptional<z.ZodUnknown>;
1205
+ }, "strip", z.ZodTypeAny, {
1206
+ code: number;
1207
+ message: string;
1208
+ data?: unknown;
1209
+ }, {
1210
+ code: number;
1211
+ message: string;
1212
+ data?: unknown;
1213
+ }>;
1214
+ }, "strict", z.ZodTypeAny, {
1215
+ error: {
1216
+ code: number;
1217
+ message: string;
1218
+ data?: unknown;
1219
+ };
1220
+ id: string | number;
1221
+ jsonrpc: "2.0";
1222
+ }, {
1223
+ error: {
1224
+ code: number;
1225
+ message: string;
1226
+ data?: unknown;
1227
+ };
1228
+ id: string | number;
1229
+ jsonrpc: "2.0";
1230
+ }>]>;
1231
+ type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
975
1232
 
976
- Default and recommended: 'auto' (best mode for the model).
977
- */
978
- mode?: 'auto' | 'json' | 'tool';
1233
+ /**
1234
+ * Transport interface for MCP (Model Context Protocol) communication.
1235
+ * Maps to the `Transport` interface in the MCP spec.
1236
+ */
1237
+ interface MCPTransport {
979
1238
  /**
980
- Optional telemetry configuration (experimental).
981
- */
982
- experimental_telemetry?: TelemetrySettings;
1239
+ * Initialize and start the transport
1240
+ */
1241
+ start(): Promise<void>;
983
1242
  /**
984
- Additional provider-specific metadata. They are passed through
985
- to the provider from the AI SDK and enable provider-specific
986
- functionality that can be fully encapsulated in the provider.
987
- */
988
- experimental_providerMetadata?: ProviderMetadata;
1243
+ * Send a JSON-RPC message through the transport
1244
+ * @param message The JSON-RPC message to send
1245
+ */
1246
+ send(message: JSONRPCMessage): Promise<void>;
989
1247
  /**
990
- * Internal. For test use only. May change without notice.
1248
+ * Clean up and close the transport
991
1249
  */
992
- _internal?: {
993
- generateId?: () => string;
994
- currentDate?: () => Date;
995
- };
996
- }): Promise<GenerateObjectResult<ENUM>>;
997
- /**
998
- Generate JSON with any schema for a given prompt using a language model.
999
-
1000
- This function does not stream the output. If you want to stream the output, use `streamObject` instead.
1001
-
1002
- @returns
1003
- A result object that contains the generated object, the finish reason, the token usage, and additional information.
1004
- */
1005
- declare function generateObject(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
1006
- output: 'no-schema';
1250
+ close(): Promise<void>;
1007
1251
  /**
1008
- The language model to use.
1009
- */
1010
- model: LanguageModel;
1252
+ * Event handler for transport closure
1253
+ */
1254
+ onclose?: () => void;
1011
1255
  /**
1012
- The mode to use for object generation. Must be "json" for no-schema output.
1013
- */
1014
- mode?: 'json';
1256
+ * Event handler for transport errors
1257
+ */
1258
+ onerror?: (error: Error) => void;
1015
1259
  /**
1016
- Optional telemetry configuration (experimental).
1260
+ * Event handler for received messages
1017
1261
  */
1018
- experimental_telemetry?: TelemetrySettings;
1262
+ onmessage?: (message: JSONRPCMessage) => void;
1263
+ }
1264
+ type MCPTransportConfig = {
1265
+ type: 'sse';
1019
1266
  /**
1020
- Additional provider-specific metadata. They are passed through
1021
- to the provider from the AI SDK and enable provider-specific
1022
- functionality that can be fully encapsulated in the provider.
1023
- */
1024
- experimental_providerMetadata?: ProviderMetadata;
1267
+ * The URL of the MCP server.
1268
+ */
1269
+ url: string;
1025
1270
  /**
1026
- * Internal. For test use only. May change without notice.
1271
+ * Additional HTTP headers to be sent with requests.
1027
1272
  */
1028
- _internal?: {
1029
- generateId?: () => string;
1030
- currentDate?: () => Date;
1273
+ headers?: Record<string, string>;
1274
+ };
1275
+
1276
+ type ToolSchemas = Record<string, {
1277
+ parameters: ToolParameters;
1278
+ }> | 'automatic' | undefined;
1279
+ type McpToolSet<TOOL_SCHEMAS extends ToolSchemas = 'automatic'> = TOOL_SCHEMAS extends Record<string, {
1280
+ parameters: ToolParameters;
1281
+ }> ? {
1282
+ [K in keyof TOOL_SCHEMAS]: Tool<TOOL_SCHEMAS[K]['parameters'], CallToolResult> & {
1283
+ execute: (args: inferParameters<TOOL_SCHEMAS[K]['parameters']>, options: ToolExecutionOptions) => PromiseLike<CallToolResult>;
1031
1284
  };
1032
- }): Promise<GenerateObjectResult<JSONValue>>;
1285
+ } : {
1286
+ [k: string]: Tool<z.ZodUnknown, CallToolResult> & {
1287
+ execute: (args: unknown, options: ToolExecutionOptions) => PromiseLike<CallToolResult>;
1288
+ };
1289
+ };
1290
+ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1291
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1292
+ }, {
1293
+ content: z.ZodArray<z.ZodUnion<[z.ZodObject<{
1294
+ type: z.ZodLiteral<"text">;
1295
+ text: z.ZodString;
1296
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1297
+ type: z.ZodLiteral<"text">;
1298
+ text: z.ZodString;
1299
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1300
+ type: z.ZodLiteral<"text">;
1301
+ text: z.ZodString;
1302
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1303
+ type: z.ZodLiteral<"image">;
1304
+ data: z.ZodString;
1305
+ mimeType: z.ZodString;
1306
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1307
+ type: z.ZodLiteral<"image">;
1308
+ data: z.ZodString;
1309
+ mimeType: z.ZodString;
1310
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1311
+ type: z.ZodLiteral<"image">;
1312
+ data: z.ZodString;
1313
+ mimeType: z.ZodString;
1314
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1315
+ type: z.ZodLiteral<"resource">;
1316
+ resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1317
+ /**
1318
+ * The URI of this resource.
1319
+ */
1320
+ uri: z.ZodString;
1321
+ /**
1322
+ * The MIME type of this resource, if known.
1323
+ */
1324
+ mimeType: z.ZodOptional<z.ZodString>;
1325
+ }, {
1326
+ text: z.ZodString;
1327
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1328
+ /**
1329
+ * The URI of this resource.
1330
+ */
1331
+ uri: z.ZodString;
1332
+ /**
1333
+ * The MIME type of this resource, if known.
1334
+ */
1335
+ mimeType: z.ZodOptional<z.ZodString>;
1336
+ }, {
1337
+ text: z.ZodString;
1338
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1339
+ /**
1340
+ * The URI of this resource.
1341
+ */
1342
+ uri: z.ZodString;
1343
+ /**
1344
+ * The MIME type of this resource, if known.
1345
+ */
1346
+ mimeType: z.ZodOptional<z.ZodString>;
1347
+ }, {
1348
+ text: z.ZodString;
1349
+ }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1350
+ /**
1351
+ * The URI of this resource.
1352
+ */
1353
+ uri: z.ZodString;
1354
+ /**
1355
+ * The MIME type of this resource, if known.
1356
+ */
1357
+ mimeType: z.ZodOptional<z.ZodString>;
1358
+ }, {
1359
+ blob: z.ZodString;
1360
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1361
+ /**
1362
+ * The URI of this resource.
1363
+ */
1364
+ uri: z.ZodString;
1365
+ /**
1366
+ * The MIME type of this resource, if known.
1367
+ */
1368
+ mimeType: z.ZodOptional<z.ZodString>;
1369
+ }, {
1370
+ blob: z.ZodString;
1371
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1372
+ /**
1373
+ * The URI of this resource.
1374
+ */
1375
+ uri: z.ZodString;
1376
+ /**
1377
+ * The MIME type of this resource, if known.
1378
+ */
1379
+ mimeType: z.ZodOptional<z.ZodString>;
1380
+ }, {
1381
+ blob: z.ZodString;
1382
+ }>, z.ZodTypeAny, "passthrough">>]>;
1383
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1384
+ type: z.ZodLiteral<"resource">;
1385
+ resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1386
+ /**
1387
+ * The URI of this resource.
1388
+ */
1389
+ uri: z.ZodString;
1390
+ /**
1391
+ * The MIME type of this resource, if known.
1392
+ */
1393
+ mimeType: z.ZodOptional<z.ZodString>;
1394
+ }, {
1395
+ text: z.ZodString;
1396
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1397
+ /**
1398
+ * The URI of this resource.
1399
+ */
1400
+ uri: z.ZodString;
1401
+ /**
1402
+ * The MIME type of this resource, if known.
1403
+ */
1404
+ mimeType: z.ZodOptional<z.ZodString>;
1405
+ }, {
1406
+ text: z.ZodString;
1407
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1408
+ /**
1409
+ * The URI of this resource.
1410
+ */
1411
+ uri: z.ZodString;
1412
+ /**
1413
+ * The MIME type of this resource, if known.
1414
+ */
1415
+ mimeType: z.ZodOptional<z.ZodString>;
1416
+ }, {
1417
+ text: z.ZodString;
1418
+ }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1419
+ /**
1420
+ * The URI of this resource.
1421
+ */
1422
+ uri: z.ZodString;
1423
+ /**
1424
+ * The MIME type of this resource, if known.
1425
+ */
1426
+ mimeType: z.ZodOptional<z.ZodString>;
1427
+ }, {
1428
+ blob: z.ZodString;
1429
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1430
+ /**
1431
+ * The URI of this resource.
1432
+ */
1433
+ uri: z.ZodString;
1434
+ /**
1435
+ * The MIME type of this resource, if known.
1436
+ */
1437
+ mimeType: z.ZodOptional<z.ZodString>;
1438
+ }, {
1439
+ blob: z.ZodString;
1440
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1441
+ /**
1442
+ * The URI of this resource.
1443
+ */
1444
+ uri: z.ZodString;
1445
+ /**
1446
+ * The MIME type of this resource, if known.
1447
+ */
1448
+ mimeType: z.ZodOptional<z.ZodString>;
1449
+ }, {
1450
+ blob: z.ZodString;
1451
+ }>, z.ZodTypeAny, "passthrough">>]>;
1452
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1453
+ type: z.ZodLiteral<"resource">;
1454
+ resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1455
+ /**
1456
+ * The URI of this resource.
1457
+ */
1458
+ uri: z.ZodString;
1459
+ /**
1460
+ * The MIME type of this resource, if known.
1461
+ */
1462
+ mimeType: z.ZodOptional<z.ZodString>;
1463
+ }, {
1464
+ text: z.ZodString;
1465
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1466
+ /**
1467
+ * The URI of this resource.
1468
+ */
1469
+ uri: z.ZodString;
1470
+ /**
1471
+ * The MIME type of this resource, if known.
1472
+ */
1473
+ mimeType: z.ZodOptional<z.ZodString>;
1474
+ }, {
1475
+ text: z.ZodString;
1476
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1477
+ /**
1478
+ * The URI of this resource.
1479
+ */
1480
+ uri: z.ZodString;
1481
+ /**
1482
+ * The MIME type of this resource, if known.
1483
+ */
1484
+ mimeType: z.ZodOptional<z.ZodString>;
1485
+ }, {
1486
+ text: z.ZodString;
1487
+ }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1488
+ /**
1489
+ * The URI of this resource.
1490
+ */
1491
+ uri: z.ZodString;
1492
+ /**
1493
+ * The MIME type of this resource, if known.
1494
+ */
1495
+ mimeType: z.ZodOptional<z.ZodString>;
1496
+ }, {
1497
+ blob: z.ZodString;
1498
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1499
+ /**
1500
+ * The URI of this resource.
1501
+ */
1502
+ uri: z.ZodString;
1503
+ /**
1504
+ * The MIME type of this resource, if known.
1505
+ */
1506
+ mimeType: z.ZodOptional<z.ZodString>;
1507
+ }, {
1508
+ blob: z.ZodString;
1509
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1510
+ /**
1511
+ * The URI of this resource.
1512
+ */
1513
+ uri: z.ZodString;
1514
+ /**
1515
+ * The MIME type of this resource, if known.
1516
+ */
1517
+ mimeType: z.ZodOptional<z.ZodString>;
1518
+ }, {
1519
+ blob: z.ZodString;
1520
+ }>, z.ZodTypeAny, "passthrough">>]>;
1521
+ }, z.ZodTypeAny, "passthrough">>]>, "many">;
1522
+ isError: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1523
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1524
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1525
+ }, {
1526
+ content: z.ZodArray<z.ZodUnion<[z.ZodObject<{
1527
+ type: z.ZodLiteral<"text">;
1528
+ text: z.ZodString;
1529
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1530
+ type: z.ZodLiteral<"text">;
1531
+ text: z.ZodString;
1532
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1533
+ type: z.ZodLiteral<"text">;
1534
+ text: z.ZodString;
1535
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1536
+ type: z.ZodLiteral<"image">;
1537
+ data: z.ZodString;
1538
+ mimeType: z.ZodString;
1539
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1540
+ type: z.ZodLiteral<"image">;
1541
+ data: z.ZodString;
1542
+ mimeType: z.ZodString;
1543
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1544
+ type: z.ZodLiteral<"image">;
1545
+ data: z.ZodString;
1546
+ mimeType: z.ZodString;
1547
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1548
+ type: z.ZodLiteral<"resource">;
1549
+ resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1550
+ /**
1551
+ * The URI of this resource.
1552
+ */
1553
+ uri: z.ZodString;
1554
+ /**
1555
+ * The MIME type of this resource, if known.
1556
+ */
1557
+ mimeType: z.ZodOptional<z.ZodString>;
1558
+ }, {
1559
+ text: z.ZodString;
1560
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1561
+ /**
1562
+ * The URI of this resource.
1563
+ */
1564
+ uri: z.ZodString;
1565
+ /**
1566
+ * The MIME type of this resource, if known.
1567
+ */
1568
+ mimeType: z.ZodOptional<z.ZodString>;
1569
+ }, {
1570
+ text: z.ZodString;
1571
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1572
+ /**
1573
+ * The URI of this resource.
1574
+ */
1575
+ uri: z.ZodString;
1576
+ /**
1577
+ * The MIME type of this resource, if known.
1578
+ */
1579
+ mimeType: z.ZodOptional<z.ZodString>;
1580
+ }, {
1581
+ text: z.ZodString;
1582
+ }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1583
+ /**
1584
+ * The URI of this resource.
1585
+ */
1586
+ uri: z.ZodString;
1587
+ /**
1588
+ * The MIME type of this resource, if known.
1589
+ */
1590
+ mimeType: z.ZodOptional<z.ZodString>;
1591
+ }, {
1592
+ blob: z.ZodString;
1593
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1594
+ /**
1595
+ * The URI of this resource.
1596
+ */
1597
+ uri: z.ZodString;
1598
+ /**
1599
+ * The MIME type of this resource, if known.
1600
+ */
1601
+ mimeType: z.ZodOptional<z.ZodString>;
1602
+ }, {
1603
+ blob: z.ZodString;
1604
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1605
+ /**
1606
+ * The URI of this resource.
1607
+ */
1608
+ uri: z.ZodString;
1609
+ /**
1610
+ * The MIME type of this resource, if known.
1611
+ */
1612
+ mimeType: z.ZodOptional<z.ZodString>;
1613
+ }, {
1614
+ blob: z.ZodString;
1615
+ }>, z.ZodTypeAny, "passthrough">>]>;
1616
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1617
+ type: z.ZodLiteral<"resource">;
1618
+ resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1619
+ /**
1620
+ * The URI of this resource.
1621
+ */
1622
+ uri: z.ZodString;
1623
+ /**
1624
+ * The MIME type of this resource, if known.
1625
+ */
1626
+ mimeType: z.ZodOptional<z.ZodString>;
1627
+ }, {
1628
+ text: z.ZodString;
1629
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1630
+ /**
1631
+ * The URI of this resource.
1632
+ */
1633
+ uri: z.ZodString;
1634
+ /**
1635
+ * The MIME type of this resource, if known.
1636
+ */
1637
+ mimeType: z.ZodOptional<z.ZodString>;
1638
+ }, {
1639
+ text: z.ZodString;
1640
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1641
+ /**
1642
+ * The URI of this resource.
1643
+ */
1644
+ uri: z.ZodString;
1645
+ /**
1646
+ * The MIME type of this resource, if known.
1647
+ */
1648
+ mimeType: z.ZodOptional<z.ZodString>;
1649
+ }, {
1650
+ text: z.ZodString;
1651
+ }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1652
+ /**
1653
+ * The URI of this resource.
1654
+ */
1655
+ uri: z.ZodString;
1656
+ /**
1657
+ * The MIME type of this resource, if known.
1658
+ */
1659
+ mimeType: z.ZodOptional<z.ZodString>;
1660
+ }, {
1661
+ blob: z.ZodString;
1662
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1663
+ /**
1664
+ * The URI of this resource.
1665
+ */
1666
+ uri: z.ZodString;
1667
+ /**
1668
+ * The MIME type of this resource, if known.
1669
+ */
1670
+ mimeType: z.ZodOptional<z.ZodString>;
1671
+ }, {
1672
+ blob: z.ZodString;
1673
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1674
+ /**
1675
+ * The URI of this resource.
1676
+ */
1677
+ uri: z.ZodString;
1678
+ /**
1679
+ * The MIME type of this resource, if known.
1680
+ */
1681
+ mimeType: z.ZodOptional<z.ZodString>;
1682
+ }, {
1683
+ blob: z.ZodString;
1684
+ }>, z.ZodTypeAny, "passthrough">>]>;
1685
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1686
+ type: z.ZodLiteral<"resource">;
1687
+ resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1688
+ /**
1689
+ * The URI of this resource.
1690
+ */
1691
+ uri: z.ZodString;
1692
+ /**
1693
+ * The MIME type of this resource, if known.
1694
+ */
1695
+ mimeType: z.ZodOptional<z.ZodString>;
1696
+ }, {
1697
+ text: z.ZodString;
1698
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1699
+ /**
1700
+ * The URI of this resource.
1701
+ */
1702
+ uri: z.ZodString;
1703
+ /**
1704
+ * The MIME type of this resource, if known.
1705
+ */
1706
+ mimeType: z.ZodOptional<z.ZodString>;
1707
+ }, {
1708
+ text: z.ZodString;
1709
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1710
+ /**
1711
+ * The URI of this resource.
1712
+ */
1713
+ uri: z.ZodString;
1714
+ /**
1715
+ * The MIME type of this resource, if known.
1716
+ */
1717
+ mimeType: z.ZodOptional<z.ZodString>;
1718
+ }, {
1719
+ text: z.ZodString;
1720
+ }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1721
+ /**
1722
+ * The URI of this resource.
1723
+ */
1724
+ uri: z.ZodString;
1725
+ /**
1726
+ * The MIME type of this resource, if known.
1727
+ */
1728
+ mimeType: z.ZodOptional<z.ZodString>;
1729
+ }, {
1730
+ blob: z.ZodString;
1731
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1732
+ /**
1733
+ * The URI of this resource.
1734
+ */
1735
+ uri: z.ZodString;
1736
+ /**
1737
+ * The MIME type of this resource, if known.
1738
+ */
1739
+ mimeType: z.ZodOptional<z.ZodString>;
1740
+ }, {
1741
+ blob: z.ZodString;
1742
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1743
+ /**
1744
+ * The URI of this resource.
1745
+ */
1746
+ uri: z.ZodString;
1747
+ /**
1748
+ * The MIME type of this resource, if known.
1749
+ */
1750
+ mimeType: z.ZodOptional<z.ZodString>;
1751
+ }, {
1752
+ blob: z.ZodString;
1753
+ }>, z.ZodTypeAny, "passthrough">>]>;
1754
+ }, z.ZodTypeAny, "passthrough">>]>, "many">;
1755
+ isError: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1756
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1757
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1758
+ }, {
1759
+ content: z.ZodArray<z.ZodUnion<[z.ZodObject<{
1760
+ type: z.ZodLiteral<"text">;
1761
+ text: z.ZodString;
1762
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1763
+ type: z.ZodLiteral<"text">;
1764
+ text: z.ZodString;
1765
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1766
+ type: z.ZodLiteral<"text">;
1767
+ text: z.ZodString;
1768
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1769
+ type: z.ZodLiteral<"image">;
1770
+ data: z.ZodString;
1771
+ mimeType: z.ZodString;
1772
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1773
+ type: z.ZodLiteral<"image">;
1774
+ data: z.ZodString;
1775
+ mimeType: z.ZodString;
1776
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1777
+ type: z.ZodLiteral<"image">;
1778
+ data: z.ZodString;
1779
+ mimeType: z.ZodString;
1780
+ }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
1781
+ type: z.ZodLiteral<"resource">;
1782
+ resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1783
+ /**
1784
+ * The URI of this resource.
1785
+ */
1786
+ uri: z.ZodString;
1787
+ /**
1788
+ * The MIME type of this resource, if known.
1789
+ */
1790
+ mimeType: z.ZodOptional<z.ZodString>;
1791
+ }, {
1792
+ text: z.ZodString;
1793
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1794
+ /**
1795
+ * The URI of this resource.
1796
+ */
1797
+ uri: z.ZodString;
1798
+ /**
1799
+ * The MIME type of this resource, if known.
1800
+ */
1801
+ mimeType: z.ZodOptional<z.ZodString>;
1802
+ }, {
1803
+ text: z.ZodString;
1804
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1805
+ /**
1806
+ * The URI of this resource.
1807
+ */
1808
+ uri: z.ZodString;
1809
+ /**
1810
+ * The MIME type of this resource, if known.
1811
+ */
1812
+ mimeType: z.ZodOptional<z.ZodString>;
1813
+ }, {
1814
+ text: z.ZodString;
1815
+ }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1816
+ /**
1817
+ * The URI of this resource.
1818
+ */
1819
+ uri: z.ZodString;
1820
+ /**
1821
+ * The MIME type of this resource, if known.
1822
+ */
1823
+ mimeType: z.ZodOptional<z.ZodString>;
1824
+ }, {
1825
+ blob: z.ZodString;
1826
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1827
+ /**
1828
+ * The URI of this resource.
1829
+ */
1830
+ uri: z.ZodString;
1831
+ /**
1832
+ * The MIME type of this resource, if known.
1833
+ */
1834
+ mimeType: z.ZodOptional<z.ZodString>;
1835
+ }, {
1836
+ blob: z.ZodString;
1837
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1838
+ /**
1839
+ * The URI of this resource.
1840
+ */
1841
+ uri: z.ZodString;
1842
+ /**
1843
+ * The MIME type of this resource, if known.
1844
+ */
1845
+ mimeType: z.ZodOptional<z.ZodString>;
1846
+ }, {
1847
+ blob: z.ZodString;
1848
+ }>, z.ZodTypeAny, "passthrough">>]>;
1849
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
1850
+ type: z.ZodLiteral<"resource">;
1851
+ resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1852
+ /**
1853
+ * The URI of this resource.
1854
+ */
1855
+ uri: z.ZodString;
1856
+ /**
1857
+ * The MIME type of this resource, if known.
1858
+ */
1859
+ mimeType: z.ZodOptional<z.ZodString>;
1860
+ }, {
1861
+ text: z.ZodString;
1862
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1863
+ /**
1864
+ * The URI of this resource.
1865
+ */
1866
+ uri: z.ZodString;
1867
+ /**
1868
+ * The MIME type of this resource, if known.
1869
+ */
1870
+ mimeType: z.ZodOptional<z.ZodString>;
1871
+ }, {
1872
+ text: z.ZodString;
1873
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1874
+ /**
1875
+ * The URI of this resource.
1876
+ */
1877
+ uri: z.ZodString;
1878
+ /**
1879
+ * The MIME type of this resource, if known.
1880
+ */
1881
+ mimeType: z.ZodOptional<z.ZodString>;
1882
+ }, {
1883
+ text: z.ZodString;
1884
+ }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1885
+ /**
1886
+ * The URI of this resource.
1887
+ */
1888
+ uri: z.ZodString;
1889
+ /**
1890
+ * The MIME type of this resource, if known.
1891
+ */
1892
+ mimeType: z.ZodOptional<z.ZodString>;
1893
+ }, {
1894
+ blob: z.ZodString;
1895
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1896
+ /**
1897
+ * The URI of this resource.
1898
+ */
1899
+ uri: z.ZodString;
1900
+ /**
1901
+ * The MIME type of this resource, if known.
1902
+ */
1903
+ mimeType: z.ZodOptional<z.ZodString>;
1904
+ }, {
1905
+ blob: z.ZodString;
1906
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1907
+ /**
1908
+ * The URI of this resource.
1909
+ */
1910
+ uri: z.ZodString;
1911
+ /**
1912
+ * The MIME type of this resource, if known.
1913
+ */
1914
+ mimeType: z.ZodOptional<z.ZodString>;
1915
+ }, {
1916
+ blob: z.ZodString;
1917
+ }>, z.ZodTypeAny, "passthrough">>]>;
1918
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
1919
+ type: z.ZodLiteral<"resource">;
1920
+ resource: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
1921
+ /**
1922
+ * The URI of this resource.
1923
+ */
1924
+ uri: z.ZodString;
1925
+ /**
1926
+ * The MIME type of this resource, if known.
1927
+ */
1928
+ mimeType: z.ZodOptional<z.ZodString>;
1929
+ }, {
1930
+ text: z.ZodString;
1931
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1932
+ /**
1933
+ * The URI of this resource.
1934
+ */
1935
+ uri: z.ZodString;
1936
+ /**
1937
+ * The MIME type of this resource, if known.
1938
+ */
1939
+ mimeType: z.ZodOptional<z.ZodString>;
1940
+ }, {
1941
+ text: z.ZodString;
1942
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1943
+ /**
1944
+ * The URI of this resource.
1945
+ */
1946
+ uri: z.ZodString;
1947
+ /**
1948
+ * The MIME type of this resource, if known.
1949
+ */
1950
+ mimeType: z.ZodOptional<z.ZodString>;
1951
+ }, {
1952
+ text: z.ZodString;
1953
+ }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1954
+ /**
1955
+ * The URI of this resource.
1956
+ */
1957
+ uri: z.ZodString;
1958
+ /**
1959
+ * The MIME type of this resource, if known.
1960
+ */
1961
+ mimeType: z.ZodOptional<z.ZodString>;
1962
+ }, {
1963
+ blob: z.ZodString;
1964
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1965
+ /**
1966
+ * The URI of this resource.
1967
+ */
1968
+ uri: z.ZodString;
1969
+ /**
1970
+ * The MIME type of this resource, if known.
1971
+ */
1972
+ mimeType: z.ZodOptional<z.ZodString>;
1973
+ }, {
1974
+ blob: z.ZodString;
1975
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1976
+ /**
1977
+ * The URI of this resource.
1978
+ */
1979
+ uri: z.ZodString;
1980
+ /**
1981
+ * The MIME type of this resource, if known.
1982
+ */
1983
+ mimeType: z.ZodOptional<z.ZodString>;
1984
+ }, {
1985
+ blob: z.ZodString;
1986
+ }>, z.ZodTypeAny, "passthrough">>]>;
1987
+ }, z.ZodTypeAny, "passthrough">>]>, "many">;
1988
+ isError: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1989
+ }>, z.ZodTypeAny, "passthrough">>, z.ZodObject<z.objectUtil.extendShape<{
1990
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1991
+ }, {
1992
+ toolResult: z.ZodUnknown;
1993
+ }>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
1994
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1995
+ }, {
1996
+ toolResult: z.ZodUnknown;
1997
+ }>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
1998
+ _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
1999
+ }, {
2000
+ toolResult: z.ZodUnknown;
2001
+ }>, z.ZodTypeAny, "passthrough">>]>;
2002
+ type CallToolResult = z.infer<typeof CallToolResultSchema>;
2003
+
2004
+ interface MCPClientConfig {
2005
+ /** Transport configuration for connecting to the MCP server */
2006
+ transport: MCPTransportConfig | MCPTransport;
2007
+ /** Optional callback for uncaught errors */
2008
+ onUncaughtError?: (error: unknown) => void;
2009
+ /** Optional client name, defaults to 'ai-sdk-mcp-client' */
2010
+ name?: string;
2011
+ }
2012
+ declare function createMCPClient(config: MCPClientConfig): Promise<MCPClient>;
2013
+ /**
2014
+ * A lightweight MCP Client implementation
2015
+ *
2016
+ * The primary purpose of this client is tool conversion between MCP<>AI SDK
2017
+ * but can later be extended to support other MCP features
2018
+ *
2019
+ * Tool parameters are automatically inferred from the server's JSON schema
2020
+ * if not explicitly provided in the tools configuration
2021
+ *
2022
+ * This client is meant to be used to communicate with a single server. To communicate and fetch tools across multiple servers, it's recommended to create a new client instance per server.
2023
+ *
2024
+ * Not supported:
2025
+ * - Client options (e.g. sampling, roots) as they are not needed for tool conversion
2026
+ * - Accepting notifications
2027
+ * - Session management (when passing a sessionId to an instance of the Streamable HTTP transport)
2028
+ * - Resumable SSE streams
2029
+ */
2030
+ declare class MCPClient {
2031
+ private transport;
2032
+ private onUncaughtError?;
2033
+ private clientInfo;
2034
+ private requestMessageId;
2035
+ private responseHandlers;
2036
+ private serverCapabilities;
2037
+ private isClosed;
2038
+ constructor({ transport: transportConfig, name, onUncaughtError, }: MCPClientConfig);
2039
+ init(): Promise<this>;
2040
+ close(): Promise<void>;
2041
+ private assertCapability;
2042
+ private request;
2043
+ private listTools;
2044
+ private callTool;
2045
+ private notification;
2046
+ /**
2047
+ * Returns a set of AI SDK tools from the MCP server
2048
+ * @returns A record of tool names to their implementations
2049
+ */
2050
+ tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>({ schemas, }?: {
2051
+ schemas?: TOOL_SCHEMAS;
2052
+ }): Promise<McpToolSet<TOOL_SCHEMAS>>;
2053
+ private onClose;
2054
+ private onError;
2055
+ private onResponse;
2056
+ }
1033
2057
 
1034
- type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
2058
+ type ToolSet = Record<string, Tool>;
1035
2059
 
2060
+ type ToolCallUnion<TOOLS extends ToolSet> = ValueOf<{
2061
+ [NAME in keyof TOOLS]: {
2062
+ type: 'tool-call';
2063
+ toolCallId: string;
2064
+ toolName: NAME & string;
2065
+ args: inferParameters<TOOLS[NAME]['parameters']>;
2066
+ };
2067
+ }>;
1036
2068
  /**
1037
- The result of a `streamObject` call that contains the partial object stream and additional information.
2069
+ * @deprecated Use `ToolCallUnion` instead.
1038
2070
  */
1039
- interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
2071
+ type CoreToolCallUnion<TOOLS extends ToolSet> = ToolCallUnion<ToolSet>;
2072
+ type ToolCallArray<TOOLS extends ToolSet> = Array<ToolCallUnion<TOOLS>>;
2073
+
2074
+ type ToToolsWithExecute<TOOLS extends ToolSet> = {
2075
+ [K in keyof TOOLS as TOOLS[K] extends {
2076
+ execute: any;
2077
+ } ? K : never]: TOOLS[K];
2078
+ };
2079
+ type ToToolsWithDefinedExecute<TOOLS extends ToolSet> = {
2080
+ [K in keyof TOOLS as TOOLS[K]['execute'] extends undefined ? never : K]: TOOLS[K];
2081
+ };
2082
+ type ToToolResultObject<TOOLS extends ToolSet> = ValueOf<{
2083
+ [NAME in keyof TOOLS]: {
2084
+ type: 'tool-result';
2085
+ toolCallId: string;
2086
+ toolName: NAME & string;
2087
+ args: inferParameters<TOOLS[NAME]['parameters']>;
2088
+ result: Awaited<ReturnType<Exclude<TOOLS[NAME]['execute'], undefined>>>;
2089
+ };
2090
+ }>;
2091
+ type ToolResultUnion<TOOLS extends ToolSet> = ToToolResultObject<ToToolsWithDefinedExecute<ToToolsWithExecute<TOOLS>>>;
2092
+ /**
2093
+ * @deprecated Use `ToolResultUnion` instead.
2094
+ */
2095
+ type CoreToolResultUnion<TOOLS extends ToolSet> = ToolResultUnion<TOOLS>;
2096
+ type ToolResultArray<TOOLS extends ToolSet> = Array<ToolResultUnion<TOOLS>>;
2097
+
2098
+ /**
2099
+ A message that was generated during the generation process.
2100
+ It can be either an assistant message or a tool message.
2101
+ */
2102
+ type ResponseMessage = (CoreAssistantMessage | CoreToolMessage) & {
1040
2103
  /**
1041
- Warnings from the model provider (e.g. unsupported settings)
1042
- */
1043
- readonly warnings: Promise<CallWarning[] | undefined>;
2104
+ Message ID generated by the AI SDK.
2105
+ */
2106
+ id: string;
2107
+ };
2108
+ /**
2109
+ * The result of a single step in the generation process.
2110
+ */
2111
+ type StepResult<TOOLS extends ToolSet> = {
1044
2112
  /**
1045
- The token usage of the generated response. Resolved when the response is finished.
1046
- */
1047
- readonly usage: Promise<LanguageModelUsage>;
2113
+ The generated text.
2114
+ */
2115
+ readonly text: string;
1048
2116
  /**
1049
- Additional provider-specific metadata. They are passed through
1050
- from the provider to the AI SDK and enable provider-specific
1051
- results that can be fully encapsulated in the provider.
1052
- */
1053
- readonly experimental_providerMetadata: Promise<ProviderMetadata | undefined>;
2117
+ The reasoning that was generated during the generation.
2118
+ */
2119
+ readonly reasoning: string | undefined;
2120
+ readonly reasoningDetails: Array<ReasoningDetail>;
1054
2121
  /**
1055
- Additional request information from the last step.
1056
- */
1057
- readonly request: Promise<LanguageModelRequestMetadata>;
2122
+ The files that were generated during the generation.
2123
+ */
2124
+ readonly files: GeneratedFile[];
1058
2125
  /**
1059
- Additional response information.
1060
- */
1061
- readonly response: Promise<LanguageModelResponseMetadata>;
2126
+ The sources that were used to generate the text.
2127
+ */
2128
+ readonly sources: Source[];
1062
2129
  /**
1063
- The generated object (typed according to the schema). Resolved when the response is finished.
1064
- */
1065
- readonly object: Promise<RESULT>;
2130
+ The tool calls that were made during the generation.
2131
+ */
2132
+ readonly toolCalls: ToolCallArray<TOOLS>;
1066
2133
  /**
1067
- Stream of partial objects. It gets more complete as the stream progresses.
1068
-
1069
- Note that the partial object is not validated.
1070
- If you want to be certain that the actual content matches your schema, you need to implement your own validation for partial results.
1071
- */
1072
- readonly partialObjectStream: AsyncIterableStream<PARTIAL>;
2134
+ The results of the tool calls.
2135
+ */
2136
+ readonly toolResults: ToolResultArray<TOOLS>;
1073
2137
  /**
1074
- * Stream over complete array elements. Only available if the output strategy is set to `array`.
1075
- */
1076
- readonly elementStream: ELEMENT_STREAM;
2138
+ The reason why the generation finished.
2139
+ */
2140
+ readonly finishReason: FinishReason;
1077
2141
  /**
1078
- Text stream of the JSON representation of the generated object. It contains text chunks.
1079
- When the stream is finished, the object is valid JSON that can be parsed.
1080
- */
1081
- readonly textStream: AsyncIterableStream<string>;
2142
+ The token usage of the generated text.
2143
+ */
2144
+ readonly usage: LanguageModelUsage;
1082
2145
  /**
1083
- Stream of different types of events, including partial objects, errors, and finish events.
1084
- Only errors that stop the stream, such as network errors, are thrown.
1085
- */
1086
- readonly fullStream: AsyncIterableStream<ObjectStreamPart<PARTIAL>>;
2146
+ Warnings from the model provider (e.g. unsupported settings).
2147
+ */
2148
+ readonly warnings: CallWarning[] | undefined;
1087
2149
  /**
1088
- Writes text delta output to a Node.js response-like object.
1089
- It sets a `Content-Type` header to `text/plain; charset=utf-8` and
1090
- writes each text delta as a separate chunk.
1091
-
1092
- @param response A Node.js response-like object (ServerResponse).
1093
- @param init Optional headers, status code, and status text.
1094
- */
1095
- pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): void;
2150
+ Logprobs for the completion.
2151
+ `undefined` if the mode does not support logprobs or if was not enabled.
2152
+ */
2153
+ readonly logprobs: LogProbs | undefined;
1096
2154
  /**
1097
- Creates a simple text stream response.
1098
- The response has a `Content-Type` header set to `text/plain; charset=utf-8`.
1099
- Each text delta is encoded as UTF-8 and sent as a separate chunk.
1100
- Non-text-delta events are ignored.
1101
-
1102
- @param init Optional headers, status code, and status text.
1103
- */
1104
- toTextStreamResponse(init?: ResponseInit): Response;
1105
- }
1106
- type ObjectStreamPart<PARTIAL> = {
1107
- type: 'object';
1108
- object: PARTIAL;
1109
- } | {
1110
- type: 'text-delta';
1111
- textDelta: string;
1112
- } | {
1113
- type: 'error';
1114
- error: unknown;
1115
- } | {
1116
- type: 'finish';
1117
- finishReason: FinishReason;
1118
- logprobs?: LogProbs;
1119
- usage: LanguageModelUsage;
1120
- response: LanguageModelResponseMetadata;
1121
- providerMetadata?: ProviderMetadata;
1122
- };
1123
-
1124
- type OnFinishCallback<RESULT> = (event: {
1125
- /**
1126
- The token usage of the generated response.
1127
- */
1128
- usage: LanguageModelUsage;
1129
- /**
1130
- The generated object. Can be undefined if the final object does not match the schema.
1131
- */
1132
- object: RESULT | undefined;
1133
- /**
1134
- Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema.
1135
- */
1136
- error: unknown | undefined;
1137
- /**
1138
- Response metadata.
1139
- */
1140
- response: LanguageModelResponseMetadata;
2155
+ Additional request information.
2156
+ */
2157
+ readonly request: LanguageModelRequestMetadata;
1141
2158
  /**
1142
- Warnings from the model provider (e.g. unsupported settings).
2159
+ Additional response information.
1143
2160
  */
1144
- warnings?: CallWarning[];
2161
+ readonly response: LanguageModelResponseMetadata & {
2162
+ /**
2163
+ The response messages that were generated during the call.
2164
+ Response messages can be either assistant messages or tool messages.
2165
+ They contain a generated id.
2166
+ */
2167
+ readonly messages: Array<ResponseMessage>;
2168
+ /**
2169
+ Response body (available only for providers that use HTTP requests).
2170
+ */
2171
+ body?: unknown;
2172
+ };
1145
2173
  /**
1146
2174
  Additional provider-specific metadata. They are passed through
1147
2175
  from the provider to the AI SDK and enable provider-specific
1148
2176
  results that can be fully encapsulated in the provider.
1149
- */
1150
- experimental_providerMetadata: ProviderMetadata | undefined;
1151
- }) => Promise<void> | void;
1152
- /**
1153
- Generate a structured, typed object for a given prompt and schema using a language model.
1154
-
1155
- This function streams the output. If you do not want to stream the output, use `generateObject` instead.
1156
-
1157
- @return
1158
- A result object for accessing the partial object stream and additional information.
1159
- */
1160
- declare function streamObject<OBJECT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
1161
- output?: 'object' | undefined;
1162
- /**
1163
- The language model to use.
1164
- */
1165
- model: LanguageModel;
1166
- /**
1167
- The schema of the object that the model should generate.
1168
- */
1169
- schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT>;
1170
- /**
1171
- Optional name of the output that should be generated.
1172
- Used by some providers for additional LLM guidance, e.g.
1173
- via tool or schema name.
1174
- */
1175
- schemaName?: string;
1176
- /**
1177
- Optional description of the output that should be generated.
1178
- Used by some providers for additional LLM guidance, e.g.
1179
- via tool or schema description.
1180
- */
1181
- schemaDescription?: string;
1182
- /**
1183
- The mode to use for object generation.
1184
-
1185
- The schema is converted into a JSON schema and used in one of the following ways
1186
-
1187
- - 'auto': The provider will choose the best mode for the model.
1188
- - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
1189
- - '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.
1190
-
1191
- Please note that most providers do not support all modes.
1192
-
1193
- Default and recommended: 'auto' (best mode for the model).
1194
- */
1195
- mode?: 'auto' | 'json' | 'tool';
1196
- /**
1197
- Optional telemetry configuration (experimental).
1198
- */
1199
- experimental_telemetry?: TelemetrySettings;
2177
+ */
2178
+ readonly providerMetadata: ProviderMetadata | undefined;
1200
2179
  /**
1201
- Additional provider-specific metadata. They are passed through
1202
- to the provider from the AI SDK and enable provider-specific
1203
- functionality that can be fully encapsulated in the provider.
1204
- */
1205
- experimental_providerMetadata?: ProviderMetadata;
2180
+ @deprecated Use `providerMetadata` instead.
2181
+ */
2182
+ readonly experimental_providerMetadata: ProviderMetadata | undefined;
1206
2183
  /**
1207
- Callback that is called when the LLM response and the final object validation are finished.
1208
- */
1209
- onFinish?: OnFinishCallback<OBJECT>;
2184
+ The type of step that this result is for. The first step is always
2185
+ an "initial" step, and subsequent steps are either "continue" steps
2186
+ or "tool-result" steps.
2187
+ */
2188
+ readonly stepType: 'initial' | 'continue' | 'tool-result';
1210
2189
  /**
1211
- * Internal. For test use only. May change without notice.
2190
+ True when there will be a continuation step with a continuation text.
1212
2191
  */
1213
- _internal?: {
1214
- generateId?: () => string;
1215
- currentDate?: () => Date;
1216
- now?: () => number;
1217
- };
1218
- }): StreamObjectResult<DeepPartial<OBJECT>, OBJECT, never>;
1219
- /**
1220
- Generate an array with structured, typed elements for a given prompt and element schema using a language model.
1221
-
1222
- This function streams the output. If you do not want to stream the output, use `generateObject` instead.
2192
+ readonly isContinued: boolean;
2193
+ };
1223
2194
 
1224
- @return
1225
- A result object for accessing the partial object stream and additional information.
2195
+ /**
2196
+ The result of a `generateText` call.
2197
+ It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
1226
2198
  */
1227
- declare function streamObject<ELEMENT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
1228
- output: 'array';
1229
- /**
1230
- The language model to use.
1231
- */
1232
- model: LanguageModel;
1233
- /**
1234
- The element schema of the array that the model should generate.
1235
- */
1236
- schema: z.Schema<ELEMENT, z.ZodTypeDef, any> | Schema<ELEMENT>;
1237
- /**
1238
- Optional name of the array that should be generated.
1239
- Used by some providers for additional LLM guidance, e.g.
1240
- via tool or schema name.
1241
- */
1242
- schemaName?: string;
1243
- /**
1244
- Optional description of the array that should be generated.
1245
- Used by some providers for additional LLM guidance, e.g.
1246
- via tool or schema description.
1247
- */
1248
- schemaDescription?: string;
1249
- /**
1250
- The mode to use for object generation.
1251
-
1252
- The schema is converted into a JSON schema and used in one of the following ways
1253
-
1254
- - 'auto': The provider will choose the best mode for the model.
1255
- - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
1256
- - '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.
1257
-
1258
- Please note that most providers do not support all modes.
1259
-
1260
- Default and recommended: 'auto' (best mode for the model).
1261
- */
1262
- mode?: 'auto' | 'json' | 'tool';
1263
- /**
1264
- Optional telemetry configuration (experimental).
1265
- */
1266
- experimental_telemetry?: TelemetrySettings;
1267
- /**
1268
- Additional provider-specific metadata. They are passed through
1269
- to the provider from the AI SDK and enable provider-specific
1270
- functionality that can be fully encapsulated in the provider.
1271
- */
1272
- experimental_providerMetadata?: ProviderMetadata;
2199
+ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
1273
2200
  /**
1274
- Callback that is called when the LLM response and the final object validation are finished.
1275
- */
1276
- onFinish?: OnFinishCallback<Array<ELEMENT>>;
2201
+ The generated text.
2202
+ */
2203
+ readonly text: string;
1277
2204
  /**
1278
- * Internal. For test use only. May change without notice.
2205
+ The reasoning text that the model has generated. Can be undefined if the model
2206
+ has only generated text.
1279
2207
  */
1280
- _internal?: {
1281
- generateId?: () => string;
1282
- currentDate?: () => Date;
1283
- now?: () => number;
1284
- };
1285
- }): StreamObjectResult<Array<ELEMENT>, Array<ELEMENT>, AsyncIterableStream<ELEMENT>>;
1286
- /**
1287
- Generate JSON with any schema for a given prompt using a language model.
1288
-
1289
- This function streams the output. If you do not want to stream the output, use `generateObject` instead.
1290
-
1291
- @return
1292
- A result object for accessing the partial object stream and additional information.
1293
- */
1294
- declare function streamObject(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
1295
- output: 'no-schema';
1296
- /**
1297
- The language model to use.
1298
- */
1299
- model: LanguageModel;
2208
+ readonly reasoning: string | undefined;
1300
2209
  /**
1301
- The mode to use for object generation. Must be "json" for no-schema output.
1302
- */
1303
- mode?: 'json';
2210
+ The files that were generated. Empty array if no files were generated.
2211
+ */
2212
+ readonly files: Array<GeneratedFile>;
1304
2213
  /**
1305
- Optional telemetry configuration (experimental).
1306
- */
1307
- experimental_telemetry?: TelemetrySettings;
2214
+ The full reasoning that the model has generated.
2215
+ */
2216
+ readonly reasoningDetails: Array<ReasoningDetail>;
1308
2217
  /**
1309
- Additional provider-specific metadata. They are passed through
1310
- to the provider from the AI SDK and enable provider-specific
1311
- functionality that can be fully encapsulated in the provider.
1312
- */
1313
- experimental_providerMetadata?: ProviderMetadata;
2218
+ Sources that have been used as input to generate the response.
2219
+ For multi-step generation, the sources are accumulated from all steps.
2220
+ */
2221
+ readonly sources: Source[];
1314
2222
  /**
1315
- Callback that is called when the LLM response and the final object validation are finished.
1316
- */
1317
- onFinish?: OnFinishCallback<JSONValue>;
2223
+ The generated structured output. It uses the `experimental_output` specification.
2224
+ */
2225
+ readonly experimental_output: OUTPUT;
1318
2226
  /**
1319
- * Internal. For test use only. May change without notice.
2227
+ The tool calls that were made during the generation.
1320
2228
  */
1321
- _internal?: {
1322
- generateId?: () => string;
1323
- currentDate?: () => Date;
1324
- now?: () => number;
1325
- };
1326
- }): StreamObjectResult<JSONValue, JSONValue, never>;
1327
-
1328
- type Parameters = z.ZodTypeAny | Schema<any>;
1329
- type inferParameters<PARAMETERS extends Parameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
1330
- interface ToolExecutionOptions {
2229
+ readonly toolCalls: ToolCallArray<TOOLS>;
1331
2230
  /**
1332
- * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
2231
+ The results of the tool calls.
1333
2232
  */
1334
- toolCallId: string;
2233
+ readonly toolResults: ToolResultArray<TOOLS>;
1335
2234
  /**
1336
- * Messages that were sent to the language model to initiate the response that contained the tool call.
1337
- * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
2235
+ The reason why the generation finished.
1338
2236
  */
1339
- messages: CoreMessage[];
2237
+ readonly finishReason: FinishReason;
1340
2238
  /**
1341
- * An optional abort signal that indicates that the overall operation should be aborted.
2239
+ The token usage of the generated text.
1342
2240
  */
1343
- abortSignal?: AbortSignal;
1344
- }
1345
- /**
1346
- A tool contains the description and the schema of the input that the tool expects.
1347
- This enables the language model to generate the input.
1348
-
1349
- The tool can also contain an optional execute function for the actual execution function of the tool.
1350
- */
1351
- type CoreTool<PARAMETERS extends Parameters = any, RESULT = any> = {
2241
+ readonly usage: LanguageModelUsage;
1352
2242
  /**
1353
- The schema of the input that the tool expects. The language model will use this to generate the input.
1354
- It is also used to validate the output of the language model.
1355
- Use descriptions to make the input understandable for the language model.
2243
+ Warnings from the model provider (e.g. unsupported settings)
1356
2244
  */
1357
- parameters: PARAMETERS;
2245
+ readonly warnings: CallWarning[] | undefined;
1358
2246
  /**
1359
- Optional conversion function that maps the tool result to multi-part tool content for LLMs.
2247
+ Details for all steps.
2248
+ You can use this to get information about intermediate steps,
2249
+ such as the tool calls or the response headers.
1360
2250
  */
1361
- experimental_toToolResultContent?: (result: RESULT) => ToolResultContent;
1362
- /**
1363
- An async function that is called with the arguments from the tool call and produces a result.
1364
- If not provided, the tool will not be executed automatically.
1365
-
1366
- @args is the input of the tool call.
1367
- @options.abortSignal is a signal that can be used to abort the tool call.
1368
- */
1369
- execute?: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
1370
- } & ({
1371
- /**
1372
- Function tool.
1373
- */
1374
- type?: undefined | 'function';
1375
- /**
1376
- An optional description of what the tool does. Will be used by the language model to decide whether to use the tool.
1377
- */
1378
- description?: string;
1379
- } | {
1380
- /**
1381
- Provider-defined tool.
1382
- */
1383
- type: 'provider-defined';
1384
- /**
1385
- The ID of the tool. Should follow the format `<provider-name>.<tool-name>`.
1386
- */
1387
- id: `${string}.${string}`;
1388
- /**
1389
- The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
1390
- */
1391
- args: Record<string, unknown>;
1392
- });
1393
- /**
1394
- Helper function for inferring the execute args of a tool.
1395
- */
1396
- declare function tool<PARAMETERS extends Parameters, RESULT>(tool: CoreTool<PARAMETERS, RESULT> & {
1397
- execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
1398
- }): CoreTool<PARAMETERS, RESULT> & {
1399
- execute: (args: inferParameters<PARAMETERS>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
1400
- };
1401
- declare function tool<PARAMETERS extends Parameters, RESULT>(tool: CoreTool<PARAMETERS, RESULT> & {
1402
- execute?: undefined;
1403
- }): CoreTool<PARAMETERS, RESULT> & {
1404
- execute: undefined;
1405
- };
1406
-
1407
- /**
1408
- Converts an array of messages from useChat into an array of CoreMessages that can be used
1409
- with the AI core functions (e.g. `streamText`).
1410
- */
1411
- declare function convertToCoreMessages<TOOLS extends Record<string, CoreTool> = never>(messages: Array<UIMessage>, options?: {
1412
- tools?: TOOLS;
1413
- }): CoreMessage[];
1414
-
1415
- /**
1416
- Create a union of the given object's values, and optionally specify which keys to get the values from.
1417
-
1418
- Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
1419
-
1420
- @example
1421
- ```
1422
- // data.json
1423
- {
1424
- 'foo': 1,
1425
- 'bar': 2,
1426
- 'biz': 3
1427
- }
1428
-
1429
- // main.ts
1430
- import type {ValueOf} from 'type-fest';
1431
- import data = require('./data.json');
1432
-
1433
- export function getData(name: string): ValueOf<typeof data> {
1434
- return data[name];
1435
- }
1436
-
1437
- export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
1438
- return data[name];
1439
- }
1440
-
1441
- // file.ts
1442
- import {getData, onlyBar} from './main';
1443
-
1444
- getData('foo');
1445
- //=> 1
1446
-
1447
- onlyBar('foo');
1448
- //=> TypeError ...
1449
-
1450
- onlyBar('bar');
1451
- //=> 2
1452
- ```
1453
- * @see https://github.com/sindresorhus/type-fest/blob/main/source/value-of.d.ts
1454
- */
1455
- type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
1456
-
1457
- type ToolCallUnion<TOOLS extends Record<string, CoreTool>> = ValueOf<{
1458
- [NAME in keyof TOOLS]: {
1459
- type: 'tool-call';
1460
- toolCallId: string;
1461
- toolName: NAME & string;
1462
- args: inferParameters<TOOLS[NAME]['parameters']>;
1463
- };
1464
- }>;
1465
- type ToolCallArray<TOOLS extends Record<string, CoreTool>> = Array<ToolCallUnion<TOOLS>>;
1466
-
1467
- type ToToolsWithExecute<TOOLS extends Record<string, CoreTool>> = {
1468
- [K in keyof TOOLS as TOOLS[K] extends {
1469
- execute: any;
1470
- } ? K : never]: TOOLS[K];
1471
- };
1472
- type ToToolsWithDefinedExecute<TOOLS extends Record<string, CoreTool>> = {
1473
- [K in keyof TOOLS as TOOLS[K]['execute'] extends undefined ? never : K]: TOOLS[K];
1474
- };
1475
- type ToToolResultObject<TOOLS extends Record<string, CoreTool>> = ValueOf<{
1476
- [NAME in keyof TOOLS]: {
1477
- type: 'tool-result';
1478
- toolCallId: string;
1479
- toolName: NAME & string;
1480
- args: inferParameters<TOOLS[NAME]['parameters']>;
1481
- result: Awaited<ReturnType<Exclude<TOOLS[NAME]['execute'], undefined>>>;
1482
- };
1483
- }>;
1484
- type ToolResultUnion<TOOLS extends Record<string, CoreTool>> = ToToolResultObject<ToToolsWithDefinedExecute<ToToolsWithExecute<TOOLS>>>;
1485
- type ToolResultArray<TOOLS extends Record<string, CoreTool>> = Array<ToolResultUnion<TOOLS>>;
1486
-
1487
- /**
1488
- * The result of a single step in the generation process.
1489
- */
1490
- type StepResult<TOOLS extends Record<string, CoreTool>> = {
1491
- /**
1492
- The generated text.
1493
- */
1494
- readonly text: string;
1495
- /**
1496
- The tool calls that were made during the generation.
1497
- */
1498
- readonly toolCalls: ToolCallArray<TOOLS>;
1499
- /**
1500
- The results of the tool calls.
1501
- */
1502
- readonly toolResults: ToolResultArray<TOOLS>;
1503
- /**
1504
- The reason why the generation finished.
1505
- */
1506
- readonly finishReason: FinishReason;
1507
- /**
1508
- The token usage of the generated text.
1509
- */
1510
- readonly usage: LanguageModelUsage;
1511
- /**
1512
- Warnings from the model provider (e.g. unsupported settings).
1513
- */
1514
- readonly warnings: CallWarning[] | undefined;
1515
- /**
1516
- Logprobs for the completion.
1517
- `undefined` if the mode does not support logprobs or if was not enabled.
1518
- */
1519
- readonly logprobs: LogProbs | undefined;
1520
- /**
1521
- Additional request information.
1522
- */
1523
- readonly request: LanguageModelRequestMetadata;
1524
- /**
1525
- Additional response information.
1526
- */
1527
- readonly response: LanguageModelResponseMetadata & {
1528
- /**
1529
- The response messages that were generated during the call. It consists of an assistant message,
1530
- potentially containing tool calls.
1531
- */
1532
- readonly messages: Array<CoreAssistantMessage | CoreToolMessage>;
1533
- };
1534
- /**
1535
- Additional provider-specific metadata. They are passed through
1536
- from the provider to the AI SDK and enable provider-specific
1537
- results that can be fully encapsulated in the provider.
1538
- */
1539
- readonly experimental_providerMetadata: ProviderMetadata | undefined;
1540
- /**
1541
- The type of step that this result is for. The first step is always
1542
- an "initial" step, and subsequent steps are either "continue" steps
1543
- or "tool-result" steps.
1544
- */
1545
- readonly stepType: 'initial' | 'continue' | 'tool-result';
1546
- /**
1547
- True when there will be a continuation step with a continuation text.
1548
- */
1549
- readonly isContinued: boolean;
1550
- };
1551
-
1552
- /**
1553
- The result of a `generateText` call.
1554
- It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
1555
- */
1556
- interface GenerateTextResult<TOOLS extends Record<string, CoreTool>, OUTPUT> {
1557
- /**
1558
- The generated text.
1559
- */
1560
- readonly text: string;
1561
- /**
1562
- The generated structured output. It uses the `experimental_output` specification.
1563
- */
1564
- readonly experimental_output: OUTPUT;
1565
- /**
1566
- The tool calls that were made during the generation.
1567
- */
1568
- readonly toolCalls: ToolCallArray<TOOLS>;
1569
- /**
1570
- The results of the tool calls.
1571
- */
1572
- readonly toolResults: ToolResultArray<TOOLS>;
1573
- /**
1574
- The reason why the generation finished.
1575
- */
1576
- readonly finishReason: FinishReason;
1577
- /**
1578
- The token usage of the generated text.
1579
- */
1580
- readonly usage: LanguageModelUsage;
1581
- /**
1582
- Warnings from the model provider (e.g. unsupported settings)
1583
- */
1584
- readonly warnings: CallWarning[] | undefined;
1585
- /**
1586
- Details for all steps.
1587
- You can use this to get information about intermediate steps,
1588
- such as the tool calls or the response headers.
1589
- */
1590
- readonly steps: Array<StepResult<TOOLS>>;
2251
+ readonly steps: Array<StepResult<TOOLS>>;
1591
2252
  /**
1592
2253
  Additional request information.
1593
2254
  */
@@ -1604,7 +2265,11 @@ interface GenerateTextResult<TOOLS extends Record<string, CoreTool>, OUTPUT> {
1604
2265
  If there are tools that do not have execute functions, they are not included in the tool results and
1605
2266
  need to be added separately.
1606
2267
  */
1607
- messages: Array<CoreAssistantMessage | CoreToolMessage>;
2268
+ messages: Array<ResponseMessage>;
2269
+ /**
2270
+ Response body (available only for providers that use HTTP requests).
2271
+ */
2272
+ body?: unknown;
1608
2273
  };
1609
2274
  /**
1610
2275
  Logprobs for the completion.
@@ -1618,6 +2283,10 @@ interface GenerateTextResult<TOOLS extends Record<string, CoreTool>, OUTPUT> {
1618
2283
  from the provider to the AI SDK and enable provider-specific
1619
2284
  results that can be fully encapsulated in the provider.
1620
2285
  */
2286
+ readonly providerMetadata: ProviderMetadata | undefined;
2287
+ /**
2288
+ @deprecated Use `providerMetadata` instead.
2289
+ */
1621
2290
  readonly experimental_providerMetadata: ProviderMetadata | undefined;
1622
2291
  }
1623
2292
 
@@ -1640,6 +2309,7 @@ interface Output<OUTPUT, PARTIAL> {
1640
2309
  }, context: {
1641
2310
  response: LanguageModelResponseMetadata;
1642
2311
  usage: LanguageModelUsage;
2312
+ finishReason: FinishReason;
1643
2313
  }): OUTPUT;
1644
2314
  }
1645
2315
  declare const text: () => Output<string, string>;
@@ -1658,9 +2328,9 @@ declare namespace output {
1658
2328
  };
1659
2329
  }
1660
2330
 
1661
- declare const symbol$c: unique symbol;
2331
+ declare const symbol$f: unique symbol;
1662
2332
  declare class InvalidToolArgumentsError extends AISDKError {
1663
- private readonly [symbol$c];
2333
+ private readonly [symbol$f];
1664
2334
  readonly toolName: string;
1665
2335
  readonly toolArgs: string;
1666
2336
  constructor({ toolArgs, toolName, cause, message, }: {
@@ -1672,9 +2342,9 @@ declare class InvalidToolArgumentsError extends AISDKError {
1672
2342
  static isInstance(error: unknown): error is InvalidToolArgumentsError;
1673
2343
  }
1674
2344
 
1675
- declare const symbol$b: unique symbol;
2345
+ declare const symbol$e: unique symbol;
1676
2346
  declare class NoSuchToolError extends AISDKError {
1677
- private readonly [symbol$b];
2347
+ private readonly [symbol$e];
1678
2348
  readonly toolName: string;
1679
2349
  readonly availableTools: string[] | undefined;
1680
2350
  constructor({ toolName, availableTools, message, }: {
@@ -1685,6 +2355,42 @@ declare class NoSuchToolError extends AISDKError {
1685
2355
  static isInstance(error: unknown): error is NoSuchToolError;
1686
2356
  }
1687
2357
 
2358
+ /**
2359
+ * Appends a client message to the messages array.
2360
+ * If the last message in the array has the same id as the new message, it will be replaced.
2361
+ * Otherwise, the new message will be appended.
2362
+ */
2363
+ declare function appendClientMessage({ messages, message, }: {
2364
+ messages: Message[];
2365
+ message: Message;
2366
+ }): Message[];
2367
+
2368
+ /**
2369
+ * Appends the ResponseMessage[] from the response to a Message[] (for useChat).
2370
+ * The messages are converted to Messages before being appended.
2371
+ * Timestamps are generated for the new messages.
2372
+ *
2373
+ * @returns A new Message[] with the response messages appended.
2374
+ */
2375
+ declare function appendResponseMessages({ messages, responseMessages, _internal: { currentDate }, }: {
2376
+ messages: Message[];
2377
+ responseMessages: ResponseMessage[];
2378
+ /**
2379
+ Internal. For test use only. May change without notice.
2380
+ */
2381
+ _internal?: {
2382
+ currentDate?: () => Date;
2383
+ };
2384
+ }): Message[];
2385
+
2386
+ /**
2387
+ Converts an array of messages from useChat into an array of CoreMessages that can be used
2388
+ with the AI core functions (e.g. `streamText`).
2389
+ */
2390
+ declare function convertToCoreMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<Message, 'id'>>, options?: {
2391
+ tools?: TOOLS;
2392
+ }): CoreMessage[];
2393
+
1688
2394
  /**
1689
2395
  * A function that attempts to repair a tool call that failed to parse.
1690
2396
  *
@@ -1698,7 +2404,7 @@ declare class NoSuchToolError extends AISDKError {
1698
2404
  * @param options.parameterSchema - A function that returns the JSON Schema for a tool.
1699
2405
  * @param options.error - The error that occurred while parsing the tool call.
1700
2406
  */
1701
- type ToolCallRepairFunction<TOOLS extends Record<string, CoreTool>> = (options: {
2407
+ type ToolCallRepairFunction<TOOLS extends ToolSet> = (options: {
1702
2408
  system: string | undefined;
1703
2409
  messages: CoreMessage[];
1704
2410
  toolCall: LanguageModelV1FunctionToolCall;
@@ -1709,6 +2415,12 @@ type ToolCallRepairFunction<TOOLS extends Record<string, CoreTool>> = (options:
1709
2415
  error: NoSuchToolError | InvalidToolArgumentsError;
1710
2416
  }) => Promise<LanguageModelV1FunctionToolCall | null>;
1711
2417
 
2418
+ /**
2419
+ Callback that is set using the `onStepFinish` option.
2420
+
2421
+ @param stepResult - The result of the step.
2422
+ */
2423
+ type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
1712
2424
  /**
1713
2425
  Generate a text and call tools for a given prompt using a language model.
1714
2426
 
@@ -1749,13 +2461,14 @@ If set and supported by the model, calls will generate deterministic results.
1749
2461
  @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
1750
2462
 
1751
2463
  @param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
2464
+ @param experimental_generateMessageId - Generate a unique ID for each message.
1752
2465
 
1753
2466
  @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
1754
2467
 
1755
2468
  @returns
1756
2469
  A result object that contains the generated text, the results of the tool calls, and additional information.
1757
2470
  */
1758
- declare function generateText<TOOLS extends Record<string, CoreTool>, OUTPUT = never, OUTPUT_PARTIAL = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, maxSteps, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
2471
+ 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_prepareStep: prepareStep, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
1759
2472
  /**
1760
2473
  The language model to use.
1761
2474
  */
@@ -1767,7 +2480,7 @@ The tools that the model can call. The model needs to support calling tools.
1767
2480
  /**
1768
2481
  The tool choice strategy. Default: 'auto'.
1769
2482
  */
1770
- toolChoice?: CoreToolChoice<TOOLS>;
2483
+ toolChoice?: ToolChoice<TOOLS>;
1771
2484
  /**
1772
2485
  Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
1773
2486
 
@@ -1777,6 +2490,10 @@ By default, it's set to 1, which means that only a single LLM call is made.
1777
2490
  */
1778
2491
  maxSteps?: number;
1779
2492
  /**
2493
+ Generate a unique ID for each message.
2494
+ */
2495
+ experimental_generateMessageId?: IDGenerator;
2496
+ /**
1780
2497
  When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
1781
2498
 
1782
2499
  By default, it's set to false.
@@ -1787,10 +2504,14 @@ Optional telemetry configuration (experimental).
1787
2504
  */
1788
2505
  experimental_telemetry?: TelemetrySettings;
1789
2506
  /**
1790
- Additional provider-specific metadata. They are passed through
2507
+ Additional provider-specific options. They are passed through
1791
2508
  to the provider from the AI SDK and enable provider-specific
1792
2509
  functionality that can be fully encapsulated in the provider.
1793
2510
  */
2511
+ providerOptions?: ProviderOptions;
2512
+ /**
2513
+ @deprecated Use `providerOptions` instead.
2514
+ */
1794
2515
  experimental_providerMetadata?: ProviderMetadata;
1795
2516
  /**
1796
2517
  Limits the tools that are available for the model to call without
@@ -1802,18 +2523,40 @@ Optional specification for parsing structured outputs from the LLM response.
1802
2523
  */
1803
2524
  experimental_output?: Output<OUTPUT, OUTPUT_PARTIAL>;
1804
2525
  /**
2526
+ Optional function that you can use to provide different settings for a step.
2527
+
2528
+ @param options - The options for the step.
2529
+ @param options.steps - The steps that have been executed so far.
2530
+ @param options.stepNumber - The number of the step that is being executed.
2531
+ @param options.maxSteps - The maximum number of steps.
2532
+ @param options.model - The model that is being used.
2533
+
2534
+ @returns An object that contains the settings for the step.
2535
+ If you return undefined (or for undefined settings), the settings from the outer level will be used.
2536
+ */
2537
+ experimental_prepareStep?: (options: {
2538
+ steps: Array<StepResult<TOOLS>>;
2539
+ stepNumber: number;
2540
+ maxSteps: number;
2541
+ model: LanguageModel;
2542
+ }) => PromiseLike<{
2543
+ model?: LanguageModel;
2544
+ toolChoice?: ToolChoice<TOOLS>;
2545
+ experimental_activeTools?: Array<keyof TOOLS>;
2546
+ } | undefined>;
2547
+ /**
1805
2548
  A function that attempts to repair a tool call that failed to parse.
1806
2549
  */
1807
2550
  experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
1808
2551
  /**
1809
2552
  Callback that is called when each step (LLM call) is finished, including intermediate steps.
1810
2553
  */
1811
- onStepFinish?: (event: StepResult<TOOLS>) => Promise<void> | void;
2554
+ onStepFinish?: GenerateTextOnStepFinishCallback<TOOLS>;
1812
2555
  /**
1813
2556
  * Internal. For test use only. May change without notice.
1814
2557
  */
1815
2558
  _internal?: {
1816
- generateId?: () => string;
2559
+ generateId?: IDGenerator;
1817
2560
  currentDate?: () => Date;
1818
2561
  };
1819
2562
  }): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
@@ -1835,10 +2578,51 @@ declare class StreamData {
1835
2578
  appendMessageAnnotation(value: JSONValue$1): void;
1836
2579
  }
1837
2580
 
1838
- /**
1839
- A result object for accessing different stream types and additional information.
1840
- */
1841
- interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPUT> {
2581
+ type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
2582
+
2583
+ type DataStreamOptions = {
2584
+ /**
2585
+ * Send usage parts to the client.
2586
+ * Default to true.
2587
+ */
2588
+ sendUsage?: boolean;
2589
+ /**
2590
+ * Send reasoning parts to the client.
2591
+ * Default to false.
2592
+ */
2593
+ sendReasoning?: boolean;
2594
+ /**
2595
+ * Send source parts to the client.
2596
+ * Default to false.
2597
+ */
2598
+ sendSources?: boolean;
2599
+ /**
2600
+ * Send the finish event to the client.
2601
+ * Set to false if you are using additional streamText calls
2602
+ * that send additional data.
2603
+ * Default to true.
2604
+ */
2605
+ experimental_sendFinish?: boolean;
2606
+ /**
2607
+ * Send the message start event to the client.
2608
+ * Set to false if you are using additional streamText calls
2609
+ * and the message start event has already been sent.
2610
+ * Default to true.
2611
+ *
2612
+ * Note: this setting is currently not used, but you should
2613
+ * already set it to false if you are using additional
2614
+ * streamText calls that send additional data to prevent
2615
+ * the message start event from being sent multiple times.
2616
+ */
2617
+ experimental_sendStart?: boolean;
2618
+ };
2619
+ type ConsumeStreamOptions = {
2620
+ onError?: (error: unknown) => void;
2621
+ };
2622
+ /**
2623
+ A result object for accessing different stream types and additional information.
2624
+ */
2625
+ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
1842
2626
  /**
1843
2627
  Warnings from the model provider (e.g. unsupported settings) for the first step.
1844
2628
  */
@@ -1851,6 +2635,19 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
1851
2635
  */
1852
2636
  readonly usage: Promise<LanguageModelUsage>;
1853
2637
  /**
2638
+ Sources that have been used as input to generate the response.
2639
+ For multi-step generation, the sources are accumulated from all steps.
2640
+
2641
+ Resolved when the response is finished.
2642
+ */
2643
+ readonly sources: Promise<Source[]>;
2644
+ /**
2645
+ Files that have been generated by the model in the last step.
2646
+
2647
+ Resolved when the response is finished.
2648
+ */
2649
+ readonly files: Promise<GeneratedFile[]>;
2650
+ /**
1854
2651
  The reason why the generation finished. Taken from the last step.
1855
2652
 
1856
2653
  Resolved when the response is finished.
@@ -1861,6 +2658,10 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
1861
2658
  Metadata is passed through from the provider to the AI SDK and
1862
2659
  enables provider-specific results that can be fully encapsulated in the provider.
1863
2660
  */
2661
+ readonly providerMetadata: Promise<ProviderMetadata | undefined>;
2662
+ /**
2663
+ @deprecated Use `providerMetadata` instead.
2664
+ */
1864
2665
  readonly experimental_providerMetadata: Promise<ProviderMetadata | undefined>;
1865
2666
  /**
1866
2667
  The full text that has been generated by the last step.
@@ -1869,6 +2670,18 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
1869
2670
  */
1870
2671
  readonly text: Promise<string>;
1871
2672
  /**
2673
+ The reasoning that has been generated by the last step.
2674
+
2675
+ Resolved when the response is finished.
2676
+ */
2677
+ readonly reasoning: Promise<string | undefined>;
2678
+ /**
2679
+ The full reasoning that the model has generated.
2680
+
2681
+ Resolved when the response is finished.
2682
+ */
2683
+ readonly reasoningDetails: Promise<Array<ReasoningDetail>>;
2684
+ /**
1872
2685
  The tool calls that have been executed in the last step.
1873
2686
 
1874
2687
  Resolved when the response is finished.
@@ -1902,7 +2715,7 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
1902
2715
  If there are tools that do not have execute functions, they are not included in the tool results and
1903
2716
  need to be added separately.
1904
2717
  */
1905
- messages: Array<CoreAssistantMessage | CoreToolMessage>;
2718
+ messages: Array<ResponseMessage>;
1906
2719
  }>;
1907
2720
  /**
1908
2721
  A text stream that returns only the generated text deltas. You can use it
@@ -1922,25 +2735,35 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
1922
2735
  */
1923
2736
  readonly experimental_partialOutputStream: AsyncIterableStream<PARTIAL_OUTPUT>;
1924
2737
  /**
2738
+ Consumes the stream without processing the parts.
2739
+ This is useful to force the stream to finish.
2740
+ It effectively removes the backpressure and allows the stream to finish,
2741
+ triggering the `onFinish` callback and the promise resolution.
2742
+
2743
+ If an error occurs, it is passed to the optional `onError` callback.
2744
+ */
2745
+ consumeStream(options?: ConsumeStreamOptions): Promise<void>;
2746
+ /**
1925
2747
  Converts the result to a data stream.
1926
2748
 
1927
2749
  @param data an optional StreamData object that will be merged into the stream.
1928
2750
  @param getErrorMessage an optional function that converts an error to an error message.
1929
2751
  @param sendUsage whether to send the usage information to the client. Defaults to true.
1930
-
2752
+ @param sendReasoning whether to send the reasoning information to the client. Defaults to false.
1931
2753
  @return A data stream.
1932
2754
  */
1933
2755
  toDataStream(options?: {
1934
2756
  data?: StreamData;
1935
2757
  getErrorMessage?: (error: unknown) => string;
1936
- sendUsage?: boolean;
1937
- }): ReadableStream<Uint8Array>;
2758
+ } & DataStreamOptions): ReadableStream<Uint8Array>;
1938
2759
  /**
1939
2760
  * Merges the result as a data stream into another data stream.
1940
2761
  *
1941
2762
  * @param dataStream A data stream writer.
2763
+ * @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
2764
+ * @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
1942
2765
  */
1943
- mergeIntoDataStream(dataStream: DataStreamWriter): void;
2766
+ mergeIntoDataStream(dataStream: DataStreamWriter, options?: DataStreamOptions): void;
1944
2767
  /**
1945
2768
  Writes data stream output to a Node.js response-like object.
1946
2769
 
@@ -1951,12 +2774,12 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
1951
2774
  @param options.data The stream data.
1952
2775
  @param options.getErrorMessage An optional function that converts an error to an error message.
1953
2776
  @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
2777
+ @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
1954
2778
  */
1955
2779
  pipeDataStreamToResponse(response: ServerResponse, options?: ResponseInit & {
1956
2780
  data?: StreamData;
1957
2781
  getErrorMessage?: (error: unknown) => string;
1958
- sendUsage?: boolean;
1959
- }): void;
2782
+ } & DataStreamOptions): void;
1960
2783
  /**
1961
2784
  Writes text delta output to a Node.js response-like object.
1962
2785
  It sets a `Content-Type` header to `text/plain; charset=utf-8` and
@@ -1976,14 +2799,14 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
1976
2799
  @param options.data The stream data.
1977
2800
  @param options.getErrorMessage An optional function that converts an error to an error message.
1978
2801
  @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
2802
+ @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
1979
2803
 
1980
2804
  @return A response object.
1981
2805
  */
1982
2806
  toDataStreamResponse(options?: ResponseInit & {
1983
2807
  data?: StreamData;
1984
2808
  getErrorMessage?: (error: unknown) => string;
1985
- sendUsage?: boolean;
1986
- }): Response;
2809
+ } & DataStreamOptions): Response;
1987
2810
  /**
1988
2811
  Creates a simple text stream response.
1989
2812
  Each text delta is encoded as UTF-8 and sent as a separate chunk.
@@ -1993,10 +2816,24 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
1993
2816
  */
1994
2817
  toTextStreamResponse(init?: ResponseInit): Response;
1995
2818
  }
1996
- type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
2819
+ type TextStreamPart<TOOLS extends ToolSet> = {
1997
2820
  type: 'text-delta';
1998
2821
  textDelta: string;
2822
+ } | {
2823
+ type: 'reasoning';
2824
+ textDelta: string;
2825
+ } | {
2826
+ type: 'reasoning-signature';
2827
+ signature: string;
2828
+ } | {
2829
+ type: 'redacted-reasoning';
2830
+ data: string;
2831
+ } | {
2832
+ type: 'source';
2833
+ source: Source;
1999
2834
  } | ({
2835
+ type: 'file';
2836
+ } & GeneratedFile) | ({
2000
2837
  type: 'tool-call';
2001
2838
  } & ToolCallUnion<TOOLS>) | {
2002
2839
  type: 'tool-call-streaming-start';
@@ -2010,27 +2847,121 @@ type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
2010
2847
  } | ({
2011
2848
  type: 'tool-result';
2012
2849
  } & ToolResultUnion<TOOLS>) | {
2850
+ type: 'step-start';
2851
+ messageId: string;
2852
+ request: LanguageModelRequestMetadata;
2853
+ warnings: CallWarning[];
2854
+ } | {
2013
2855
  type: 'step-finish';
2014
- finishReason: FinishReason;
2856
+ messageId: string;
2015
2857
  logprobs?: LogProbs;
2016
- usage: LanguageModelUsage;
2017
2858
  request: LanguageModelRequestMetadata;
2018
- response: LanguageModelResponseMetadata;
2019
2859
  warnings: CallWarning[] | undefined;
2860
+ response: LanguageModelResponseMetadata;
2861
+ usage: LanguageModelUsage;
2862
+ finishReason: FinishReason;
2863
+ providerMetadata: ProviderMetadata | undefined;
2864
+ /**
2865
+ * @deprecated Use `providerMetadata` instead.
2866
+ */
2020
2867
  experimental_providerMetadata?: ProviderMetadata;
2021
2868
  isContinued: boolean;
2022
2869
  } | {
2023
2870
  type: 'finish';
2024
2871
  finishReason: FinishReason;
2025
- logprobs?: LogProbs;
2026
2872
  usage: LanguageModelUsage;
2027
- response: LanguageModelResponseMetadata;
2873
+ providerMetadata: ProviderMetadata | undefined;
2874
+ /**
2875
+ * @deprecated Use `providerMetadata` instead.
2876
+ */
2028
2877
  experimental_providerMetadata?: ProviderMetadata;
2878
+ /**
2879
+ * @deprecated will be moved into provider metadata
2880
+ */
2881
+ logprobs?: LogProbs;
2882
+ /**
2883
+ * @deprecated use response on step-finish instead
2884
+ */
2885
+ response: LanguageModelResponseMetadata;
2029
2886
  } | {
2030
2887
  type: 'error';
2031
2888
  error: unknown;
2032
2889
  };
2033
2890
 
2891
+ /**
2892
+ * Detects the first chunk in a buffer.
2893
+ *
2894
+ * @param buffer - The buffer to detect the first chunk in.
2895
+ *
2896
+ * @returns The first detected chunk, or `undefined` if no chunk was detected.
2897
+ */
2898
+ type ChunkDetector = (buffer: string) => string | undefined | null;
2899
+ /**
2900
+ * Smooths text streaming output.
2901
+ *
2902
+ * @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
2903
+ * @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, or provide a custom RegExp pattern for custom chunking.
2904
+ *
2905
+ * @returns A transform stream that smooths text streaming output.
2906
+ */
2907
+ declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _internal: { delay }, }?: {
2908
+ delayInMs?: number | null;
2909
+ chunking?: 'word' | 'line' | RegExp | ChunkDetector;
2910
+ /**
2911
+ * Internal. For test use only. May change without notice.
2912
+ */
2913
+ _internal?: {
2914
+ delay?: (delayInMs: number | null) => Promise<void>;
2915
+ };
2916
+ }): (options: {
2917
+ tools: TOOLS;
2918
+ }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
2919
+
2920
+ /**
2921
+ A transformation that is applied to the stream.
2922
+
2923
+ @param stopStream - A function that stops the source stream.
2924
+ @param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
2925
+ */
2926
+ type StreamTextTransform<TOOLS extends ToolSet> = (options: {
2927
+ tools: TOOLS;
2928
+ stopStream: () => void;
2929
+ }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
2930
+ /**
2931
+ Callback that is set using the `onError` option.
2932
+
2933
+ @param event - The event that is passed to the callback.
2934
+ */
2935
+ type StreamTextOnErrorCallback = (event: {
2936
+ error: unknown;
2937
+ }) => Promise<void> | void;
2938
+ /**
2939
+ Callback that is set using the `onStepFinish` option.
2940
+
2941
+ @param stepResult - The result of the step.
2942
+ */
2943
+ type StreamTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
2944
+ /**
2945
+ Callback that is set using the `onChunk` option.
2946
+
2947
+ @param event - The event that is passed to the callback.
2948
+ */
2949
+ type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
2950
+ chunk: Extract<TextStreamPart<TOOLS>, {
2951
+ type: 'text-delta' | 'reasoning' | 'source' | 'tool-call' | 'tool-call-streaming-start' | 'tool-call-delta' | 'tool-result';
2952
+ }>;
2953
+ }) => Promise<void> | void;
2954
+ /**
2955
+ Callback that is set using the `onFinish` option.
2956
+
2957
+ @param event - The event that is passed to the callback.
2958
+ */
2959
+ type StreamTextOnFinishCallback<TOOLS extends ToolSet> = (event: Omit<StepResult<TOOLS>, 'stepType' | 'isContinued'> & {
2960
+ /**
2961
+ Details for all steps.
2962
+ */
2963
+ readonly steps: StepResult<TOOLS>[];
2964
+ }) => Promise<void> | void;
2034
2965
  /**
2035
2966
  Generate a text and call tools for a given prompt using a language model.
2036
2967
 
@@ -2069,8 +3000,10 @@ If set and supported by the model, calls will generate deterministic results.
2069
3000
  @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
2070
3001
 
2071
3002
  @param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
3003
+ @param experimental_generateMessageId - Generate a unique ID for each message.
2072
3004
 
2073
3005
  @param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
3006
+ @param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
2074
3007
  @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
2075
3008
  @param onFinish - Callback that is called when the LLM response and all request tool executions
2076
3009
  (for tools that have an `execute` function) are finished.
@@ -2078,7 +3011,7 @@ If set and supported by the model, calls will generate deterministic results.
2078
3011
  @return
2079
3012
  A result object for accessing different stream types and additional information.
2080
3013
  */
2081
- declare function streamText<TOOLS extends Record<string, CoreTool>, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxSteps, experimental_output: output, experimental_continueSteps: continueSteps, experimental_telemetry: telemetry, experimental_providerMetadata: providerMetadata, experimental_toolCallStreaming: toolCallStreaming, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, onChunk, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
3014
+ 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 & {
2082
3015
  /**
2083
3016
  The language model to use.
2084
3017
  */
@@ -2090,119 +3023,1072 @@ The tools that the model can call. The model needs to support calling tools.
2090
3023
  /**
2091
3024
  The tool choice strategy. Default: 'auto'.
2092
3025
  */
2093
- toolChoice?: CoreToolChoice<TOOLS>;
3026
+ toolChoice?: ToolChoice<TOOLS>;
2094
3027
  /**
2095
3028
  Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
2096
3029
 
2097
3030
  A maximum number is required to prevent infinite loops in the case of misconfigured tools.
2098
3031
 
2099
- By default, it's set to 1, which means that only a single LLM call is made.
3032
+ By default, it's set to 1, which means that only a single LLM call is made.
3033
+ */
3034
+ maxSteps?: number;
3035
+ /**
3036
+ Generate a unique ID for each message.
3037
+ */
3038
+ experimental_generateMessageId?: IDGenerator;
3039
+ /**
3040
+ When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
3041
+
3042
+ By default, it's set to false.
3043
+ */
3044
+ experimental_continueSteps?: boolean;
3045
+ /**
3046
+ Optional telemetry configuration (experimental).
3047
+ */
3048
+ experimental_telemetry?: TelemetrySettings;
3049
+ /**
3050
+ Additional provider-specific options. They are passed through
3051
+ to the provider from the AI SDK and enable provider-specific
3052
+ functionality that can be fully encapsulated in the provider.
3053
+ */
3054
+ providerOptions?: ProviderOptions;
3055
+ /**
3056
+ @deprecated Use `providerOptions` instead.
3057
+ */
3058
+ experimental_providerMetadata?: ProviderMetadata;
3059
+ /**
3060
+ Limits the tools that are available for the model to call without
3061
+ changing the tool call and result types in the result.
3062
+ */
3063
+ experimental_activeTools?: Array<keyof TOOLS>;
3064
+ /**
3065
+ Optional specification for parsing structured outputs from the LLM response.
3066
+ */
3067
+ experimental_output?: Output<OUTPUT, PARTIAL_OUTPUT>;
3068
+ /**
3069
+ A function that attempts to repair a tool call that failed to parse.
3070
+ */
3071
+ experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
3072
+ /**
3073
+ Enable streaming of tool call deltas as they are generated. Disabled by default.
3074
+ */
3075
+ toolCallStreaming?: boolean;
3076
+ /**
3077
+ @deprecated Use `toolCallStreaming` instead.
3078
+ */
3079
+ experimental_toolCallStreaming?: boolean;
3080
+ /**
3081
+ Optional stream transformations.
3082
+ They are applied in the order they are provided.
3083
+ The stream transformations must maintain the stream structure for streamText to work correctly.
3084
+ */
3085
+ experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
3086
+ /**
3087
+ Callback that is called for each chunk of the stream.
3088
+ The stream processing will pause until the callback promise is resolved.
3089
+ */
3090
+ onChunk?: StreamTextOnChunkCallback<TOOLS>;
3091
+ /**
3092
+ Callback that is invoked when an error occurs during streaming.
3093
+ You can use it to log errors.
3094
+ The stream processing will pause until the callback promise is resolved.
3095
+ */
3096
+ onError?: StreamTextOnErrorCallback;
3097
+ /**
3098
+ Callback that is called when the LLM response and all request tool executions
3099
+ (for tools that have an `execute` function) are finished.
3100
+
3101
+ The usage is the combined usage of all steps.
3102
+ */
3103
+ onFinish?: StreamTextOnFinishCallback<TOOLS>;
3104
+ /**
3105
+ Callback that is called when each step (LLM call) is finished, including intermediate steps.
3106
+ */
3107
+ onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
3108
+ /**
3109
+ Internal. For test use only. May change without notice.
3110
+ */
3111
+ _internal?: {
3112
+ now?: () => number;
3113
+ generateId?: IDGenerator;
3114
+ currentDate?: () => Date;
3115
+ };
3116
+ }): StreamTextResult<TOOLS, PARTIAL_OUTPUT>;
3117
+
3118
+ /**
3119
+ The result of a `generateImage` call.
3120
+ It contains the images and additional information.
3121
+ */
3122
+ interface GenerateImageResult {
3123
+ /**
3124
+ The first image that was generated.
3125
+ */
3126
+ readonly image: GeneratedFile;
3127
+ /**
3128
+ The images that were generated.
3129
+ */
3130
+ readonly images: Array<GeneratedFile>;
3131
+ /**
3132
+ Warnings for the call, e.g. unsupported settings.
3133
+ */
3134
+ readonly warnings: Array<ImageGenerationWarning>;
3135
+ /**
3136
+ Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
3137
+ */
3138
+ readonly responses: Array<ImageModelResponseMetadata>;
3139
+ }
3140
+
3141
+ /**
3142
+ Generates images using an image model.
3143
+
3144
+ @param model - The image model to use.
3145
+ @param prompt - The prompt that should be used to generate the image.
3146
+ @param n - Number of images to generate. Default: 1.
3147
+ @param size - Size of the images to generate. Must have the format `{width}x{height}`.
3148
+ @param aspectRatio - Aspect ratio of the images to generate. Must have the format `{width}:{height}`.
3149
+ @param seed - Seed for the image generation.
3150
+ @param providerOptions - Additional provider-specific options that are passed through to the provider
3151
+ as body parameters.
3152
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
3153
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
3154
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
3155
+
3156
+ @returns A result object that contains the generated images.
3157
+ */
3158
+ declare function generateImage({ model, prompt, n, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
3159
+ /**
3160
+ The image model to use.
3161
+ */
3162
+ model: ImageModelV1;
3163
+ /**
3164
+ The prompt that should be used to generate the image.
3165
+ */
3166
+ prompt: string;
3167
+ /**
3168
+ Number of images to generate.
3169
+ */
3170
+ n?: number;
3171
+ /**
3172
+ Size of the images to generate. Must have the format `{width}x{height}`. If not provided, the default size will be used.
3173
+ */
3174
+ size?: `${number}x${number}`;
3175
+ /**
3176
+ Aspect ratio of the images to generate. Must have the format `{width}:{height}`. If not provided, the default aspect ratio will be used.
3177
+ */
3178
+ aspectRatio?: `${number}:${number}`;
3179
+ /**
3180
+ Seed for the image generation. If not provided, the default seed will be used.
3181
+ */
3182
+ seed?: number;
3183
+ /**
3184
+ Additional provider-specific options that are passed through to the provider
3185
+ as body parameters.
3186
+
3187
+ The outer record is keyed by the provider name, and the inner
3188
+ record is keyed by the provider-specific metadata key.
3189
+ ```ts
3190
+ {
3191
+ "openai": {
3192
+ "style": "vivid"
3193
+ }
3194
+ }
3195
+ ```
3196
+ */
3197
+ providerOptions?: Record<string, Record<string, JSONValue>>;
3198
+ /**
3199
+ Maximum number of retries per embedding model call. Set to 0 to disable retries.
3200
+
3201
+ @default 2
3202
+ */
3203
+ maxRetries?: number;
3204
+ /**
3205
+ Abort signal.
3206
+ */
3207
+ abortSignal?: AbortSignal;
3208
+ /**
3209
+ Additional headers to include in the request.
3210
+ Only applicable for HTTP-based providers.
3211
+ */
3212
+ headers?: Record<string, string>;
3213
+ }): Promise<GenerateImageResult>;
3214
+
3215
+ /**
3216
+ The result of a `generateObject` call.
3217
+ */
3218
+ interface GenerateObjectResult<OBJECT> {
3219
+ /**
3220
+ The generated object (typed according to the schema).
3221
+ */
3222
+ readonly object: OBJECT;
3223
+ /**
3224
+ The reason why the generation finished.
3225
+ */
3226
+ readonly finishReason: FinishReason;
3227
+ /**
3228
+ The token usage of the generated text.
3229
+ */
3230
+ readonly usage: LanguageModelUsage;
3231
+ /**
3232
+ Warnings from the model provider (e.g. unsupported settings).
3233
+ */
3234
+ readonly warnings: CallWarning[] | undefined;
3235
+ /**
3236
+ Additional request information.
3237
+ */
3238
+ readonly request: LanguageModelRequestMetadata;
3239
+ /**
3240
+ Additional response information.
3241
+ */
3242
+ readonly response: LanguageModelResponseMetadata & {
3243
+ /**
3244
+ Response body (available only for providers that use HTTP requests).
3245
+ */
3246
+ body?: unknown;
3247
+ };
3248
+ /**
3249
+ Logprobs for the completion.
3250
+ `undefined` if the mode does not support logprobs or if was not enabled.
3251
+
3252
+ @deprecated Will become a provider extension in the future.
3253
+ */
3254
+ readonly logprobs: LogProbs | undefined;
3255
+ /**
3256
+ Additional provider-specific metadata. They are passed through
3257
+ from the provider to the AI SDK and enable provider-specific
3258
+ results that can be fully encapsulated in the provider.
3259
+ */
3260
+ readonly providerMetadata: ProviderMetadata | undefined;
3261
+ /**
3262
+ @deprecated Use `providerMetadata` instead.
3263
+ */
3264
+ readonly experimental_providerMetadata: ProviderMetadata | undefined;
3265
+ /**
3266
+ Converts the object to a JSON response.
3267
+ The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
3268
+ */
3269
+ toJsonResponse(init?: ResponseInit): Response;
3270
+ }
3271
+
3272
+ /**
3273
+ A function that attempts to repair the raw output of the mode
3274
+ to enable JSON parsing.
3275
+
3276
+ Should return the repaired text or null if the text cannot be repaired.
3277
+ */
3278
+ type RepairTextFunction = (options: {
3279
+ text: string;
3280
+ error: JSONParseError | TypeValidationError;
3281
+ }) => Promise<string | null>;
3282
+ /**
3283
+ Generate a structured, typed object for a given prompt and schema using a language model.
3284
+
3285
+ This function does not stream the output. If you want to stream the output, use `streamObject` instead.
3286
+
3287
+ @returns
3288
+ A result object that contains the generated object, the finish reason, the token usage, and additional information.
3289
+ */
3290
+ declare function generateObject<OBJECT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
3291
+ output?: 'object' | undefined;
3292
+ /**
3293
+ The language model to use.
3294
+ */
3295
+ model: LanguageModel;
3296
+ /**
3297
+ The schema of the object that the model should generate.
3298
+ */
3299
+ schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT>;
3300
+ /**
3301
+ Optional name of the output that should be generated.
3302
+ Used by some providers for additional LLM guidance, e.g.
3303
+ via tool or schema name.
3304
+ */
3305
+ schemaName?: string;
3306
+ /**
3307
+ Optional description of the output that should be generated.
3308
+ Used by some providers for additional LLM guidance, e.g.
3309
+ via tool or schema description.
3310
+ */
3311
+ schemaDescription?: string;
3312
+ /**
3313
+ The mode to use for object generation.
3314
+
3315
+ The schema is converted into a JSON schema and used in one of the following ways
3316
+
3317
+ - 'auto': The provider will choose the best mode for the model.
3318
+ - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
3319
+ - '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.
3320
+
3321
+ Please note that most providers do not support all modes.
3322
+
3323
+ Default and recommended: 'auto' (best mode for the model).
3324
+ */
3325
+ mode?: 'auto' | 'json' | 'tool';
3326
+ /**
3327
+ A function that attempts to repair the raw output of the mode
3328
+ to enable JSON parsing.
3329
+ */
3330
+ experimental_repairText?: RepairTextFunction;
3331
+ /**
3332
+ Optional telemetry configuration (experimental).
3333
+ */
3334
+ experimental_telemetry?: TelemetrySettings;
3335
+ /**
3336
+ Additional provider-specific options. They are passed through
3337
+ to the provider from the AI SDK and enable provider-specific
3338
+ functionality that can be fully encapsulated in the provider.
3339
+ */
3340
+ providerOptions?: ProviderOptions;
3341
+ /**
3342
+ @deprecated Use `providerOptions` instead.
3343
+ */
3344
+ experimental_providerMetadata?: ProviderMetadata;
3345
+ /**
3346
+ * Internal. For test use only. May change without notice.
3347
+ */
3348
+ _internal?: {
3349
+ generateId?: () => string;
3350
+ currentDate?: () => Date;
3351
+ };
3352
+ }): Promise<GenerateObjectResult<OBJECT>>;
3353
+ /**
3354
+ Generate an array with structured, typed elements for a given prompt and element schema using a language model.
3355
+
3356
+ This function does not stream the output. If you want to stream the output, use `streamObject` instead.
3357
+
3358
+ @return
3359
+ A result object that contains the generated object, the finish reason, the token usage, and additional information.
3360
+ */
3361
+ declare function generateObject<ELEMENT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
3362
+ output: 'array';
3363
+ /**
3364
+ The language model to use.
3365
+ */
3366
+ model: LanguageModel;
3367
+ /**
3368
+ The element schema of the array that the model should generate.
3369
+ */
3370
+ schema: z.Schema<ELEMENT, z.ZodTypeDef, any> | Schema<ELEMENT>;
3371
+ /**
3372
+ Optional name of the array that should be generated.
3373
+ Used by some providers for additional LLM guidance, e.g.
3374
+ via tool or schema name.
3375
+ */
3376
+ schemaName?: string;
3377
+ /**
3378
+ Optional description of the array that should be generated.
3379
+ Used by some providers for additional LLM guidance, e.g.
3380
+ via tool or schema description.
3381
+ */
3382
+ schemaDescription?: string;
3383
+ /**
3384
+ The mode to use for object generation.
3385
+
3386
+ The schema is converted into a JSON schema and used in one of the following ways
3387
+
3388
+ - 'auto': The provider will choose the best mode for the model.
3389
+ - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
3390
+ - '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.
3391
+
3392
+ Please note that most providers do not support all modes.
3393
+
3394
+ Default and recommended: 'auto' (best mode for the model).
3395
+ */
3396
+ mode?: 'auto' | 'json' | 'tool';
3397
+ /**
3398
+ A function that attempts to repair the raw output of the mode
3399
+ to enable JSON parsing.
3400
+ */
3401
+ experimental_repairText?: RepairTextFunction;
3402
+ /**
3403
+ Optional telemetry configuration (experimental).
3404
+ */
3405
+ experimental_telemetry?: TelemetrySettings;
3406
+ /**
3407
+ Additional provider-specific options. They are passed through
3408
+ to the provider from the AI SDK and enable provider-specific
3409
+ functionality that can be fully encapsulated in the provider.
3410
+ */
3411
+ providerOptions?: ProviderOptions;
3412
+ /**
3413
+ @deprecated Use `providerOptions` instead.
3414
+ */
3415
+ experimental_providerMetadata?: ProviderMetadata;
3416
+ /**
3417
+ * Internal. For test use only. May change without notice.
3418
+ */
3419
+ _internal?: {
3420
+ generateId?: () => string;
3421
+ currentDate?: () => Date;
3422
+ };
3423
+ }): Promise<GenerateObjectResult<Array<ELEMENT>>>;
3424
+ /**
3425
+ Generate a value from an enum (limited list of string values) using a language model.
3426
+
3427
+ This function does not stream the output.
3428
+
3429
+ @return
3430
+ A result object that contains the generated value, the finish reason, the token usage, and additional information.
3431
+ */
3432
+ declare function generateObject<ENUM extends string>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
3433
+ output: 'enum';
3434
+ /**
3435
+ The language model to use.
3436
+ */
3437
+ model: LanguageModel;
3438
+ /**
3439
+ The enum values that the model should use.
3440
+ */
3441
+ enum: Array<ENUM>;
3442
+ /**
3443
+ The mode to use for object generation.
3444
+
3445
+ The schema is converted into a JSON schema and used in one of the following ways
3446
+
3447
+ - 'auto': The provider will choose the best mode for the model.
3448
+ - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
3449
+ - '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.
3450
+
3451
+ Please note that most providers do not support all modes.
3452
+
3453
+ Default and recommended: 'auto' (best mode for the model).
3454
+ */
3455
+ mode?: 'auto' | 'json' | 'tool';
3456
+ /**
3457
+ A function that attempts to repair the raw output of the mode
3458
+ to enable JSON parsing.
3459
+ */
3460
+ experimental_repairText?: RepairTextFunction;
3461
+ /**
3462
+ Optional telemetry configuration (experimental).
3463
+ */
3464
+ experimental_telemetry?: TelemetrySettings;
3465
+ /**
3466
+ Additional provider-specific options. They are passed through
3467
+ to the provider from the AI SDK and enable provider-specific
3468
+ functionality that can be fully encapsulated in the provider.
3469
+ */
3470
+ providerOptions?: ProviderOptions;
3471
+ /**
3472
+ @deprecated Use `providerOptions` instead.
3473
+ */
3474
+ experimental_providerMetadata?: ProviderMetadata;
3475
+ /**
3476
+ * Internal. For test use only. May change without notice.
3477
+ */
3478
+ _internal?: {
3479
+ generateId?: () => string;
3480
+ currentDate?: () => Date;
3481
+ };
3482
+ }): Promise<GenerateObjectResult<ENUM>>;
3483
+ /**
3484
+ Generate JSON with any schema for a given prompt using a language model.
3485
+
3486
+ This function does not stream the output. If you want to stream the output, use `streamObject` instead.
3487
+
3488
+ @returns
3489
+ A result object that contains the generated object, the finish reason, the token usage, and additional information.
3490
+ */
3491
+ declare function generateObject(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
3492
+ output: 'no-schema';
3493
+ /**
3494
+ The language model to use.
3495
+ */
3496
+ model: LanguageModel;
3497
+ /**
3498
+ The mode to use for object generation. Must be "json" for no-schema output.
3499
+ */
3500
+ mode?: 'json';
3501
+ /**
3502
+ A function that attempts to repair the raw output of the mode
3503
+ to enable JSON parsing.
3504
+ */
3505
+ experimental_repairText?: RepairTextFunction;
3506
+ /**
3507
+ Optional telemetry configuration (experimental).
3508
+ */
3509
+ experimental_telemetry?: TelemetrySettings;
3510
+ /**
3511
+ Additional provider-specific options. They are passed through
3512
+ to the provider from the AI SDK and enable provider-specific
3513
+ functionality that can be fully encapsulated in the provider.
3514
+ */
3515
+ providerOptions?: ProviderOptions;
3516
+ /**
3517
+ @deprecated Use `providerOptions` instead.
3518
+ */
3519
+ experimental_providerMetadata?: ProviderMetadata;
3520
+ /**
3521
+ * Internal. For test use only. May change without notice.
3522
+ */
3523
+ _internal?: {
3524
+ generateId?: () => string;
3525
+ currentDate?: () => Date;
3526
+ };
3527
+ }): Promise<GenerateObjectResult<JSONValue>>;
3528
+
3529
+ /**
3530
+ The result of a `streamObject` call that contains the partial object stream and additional information.
3531
+ */
3532
+ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
3533
+ /**
3534
+ Warnings from the model provider (e.g. unsupported settings)
3535
+ */
3536
+ readonly warnings: Promise<CallWarning[] | undefined>;
3537
+ /**
3538
+ The token usage of the generated response. Resolved when the response is finished.
3539
+ */
3540
+ readonly usage: Promise<LanguageModelUsage>;
3541
+ /**
3542
+ Additional provider-specific metadata. They are passed through
3543
+ from the provider to the AI SDK and enable provider-specific
3544
+ results that can be fully encapsulated in the provider.
3545
+ */
3546
+ readonly providerMetadata: Promise<ProviderMetadata | undefined>;
3547
+ /**
3548
+ @deprecated Use `providerMetadata` instead.
3549
+ */
3550
+ readonly experimental_providerMetadata: Promise<ProviderMetadata | undefined>;
3551
+ /**
3552
+ Additional request information from the last step.
3553
+ */
3554
+ readonly request: Promise<LanguageModelRequestMetadata>;
3555
+ /**
3556
+ Additional response information.
3557
+ */
3558
+ readonly response: Promise<LanguageModelResponseMetadata>;
3559
+ /**
3560
+ The generated object (typed according to the schema). Resolved when the response is finished.
3561
+ */
3562
+ readonly object: Promise<RESULT>;
3563
+ /**
3564
+ Stream of partial objects. It gets more complete as the stream progresses.
3565
+
3566
+ Note that the partial object is not validated.
3567
+ If you want to be certain that the actual content matches your schema, you need to implement your own validation for partial results.
3568
+ */
3569
+ readonly partialObjectStream: AsyncIterableStream<PARTIAL>;
3570
+ /**
3571
+ * Stream over complete array elements. Only available if the output strategy is set to `array`.
3572
+ */
3573
+ readonly elementStream: ELEMENT_STREAM;
3574
+ /**
3575
+ Text stream of the JSON representation of the generated object. It contains text chunks.
3576
+ When the stream is finished, the object is valid JSON that can be parsed.
3577
+ */
3578
+ readonly textStream: AsyncIterableStream<string>;
3579
+ /**
3580
+ Stream of different types of events, including partial objects, errors, and finish events.
3581
+ Only errors that stop the stream, such as network errors, are thrown.
3582
+ */
3583
+ readonly fullStream: AsyncIterableStream<ObjectStreamPart<PARTIAL>>;
3584
+ /**
3585
+ Writes text delta output to a Node.js response-like object.
3586
+ It sets a `Content-Type` header to `text/plain; charset=utf-8` and
3587
+ writes each text delta as a separate chunk.
3588
+
3589
+ @param response A Node.js response-like object (ServerResponse).
3590
+ @param init Optional headers, status code, and status text.
3591
+ */
3592
+ pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): void;
3593
+ /**
3594
+ Creates a simple text stream response.
3595
+ The response has a `Content-Type` header set to `text/plain; charset=utf-8`.
3596
+ Each text delta is encoded as UTF-8 and sent as a separate chunk.
3597
+ Non-text-delta events are ignored.
3598
+
3599
+ @param init Optional headers, status code, and status text.
3600
+ */
3601
+ toTextStreamResponse(init?: ResponseInit): Response;
3602
+ }
3603
+ type ObjectStreamPart<PARTIAL> = {
3604
+ type: 'object';
3605
+ object: PARTIAL;
3606
+ } | {
3607
+ type: 'text-delta';
3608
+ textDelta: string;
3609
+ } | {
3610
+ type: 'error';
3611
+ error: unknown;
3612
+ } | {
3613
+ type: 'finish';
3614
+ finishReason: FinishReason;
3615
+ logprobs?: LogProbs;
3616
+ usage: LanguageModelUsage;
3617
+ response: LanguageModelResponseMetadata;
3618
+ providerMetadata?: ProviderMetadata;
3619
+ };
3620
+
3621
+ /**
3622
+ Callback that is set using the `onError` option.
3623
+
3624
+ @param event - The event that is passed to the callback.
3625
+ */
3626
+ type StreamObjectOnErrorCallback = (event: {
3627
+ error: unknown;
3628
+ }) => Promise<void> | void;
3629
+ /**
3630
+ Callback that is set using the `onFinish` option.
3631
+
3632
+ @param event - The event that is passed to the callback.
3633
+ */
3634
+ type StreamObjectOnFinishCallback<RESULT> = (event: {
3635
+ /**
3636
+ The token usage of the generated response.
3637
+ */
3638
+ usage: LanguageModelUsage;
3639
+ /**
3640
+ The generated object. Can be undefined if the final object does not match the schema.
3641
+ */
3642
+ object: RESULT | undefined;
3643
+ /**
3644
+ Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema.
3645
+ */
3646
+ error: unknown | undefined;
3647
+ /**
3648
+ Response metadata.
3649
+ */
3650
+ response: LanguageModelResponseMetadata;
3651
+ /**
3652
+ Warnings from the model provider (e.g. unsupported settings).
3653
+ */
3654
+ warnings?: CallWarning[];
3655
+ /**
3656
+ Additional provider-specific metadata. They are passed through
3657
+ to the provider from the AI SDK and enable provider-specific
3658
+ functionality that can be fully encapsulated in the provider.
3659
+ */
3660
+ providerMetadata: ProviderMetadata | undefined;
3661
+ /**
3662
+ @deprecated Use `providerMetadata` instead.
3663
+ */
3664
+ experimental_providerMetadata?: ProviderMetadata;
3665
+ }) => Promise<void> | void;
3666
+ /**
3667
+ Generate a structured, typed object for a given prompt and schema using a language model.
3668
+
3669
+ This function streams the output. If you do not want to stream the output, use `generateObject` instead.
3670
+
3671
+ @return
3672
+ A result object for accessing the partial object stream and additional information.
3673
+ */
3674
+ declare function streamObject<OBJECT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
3675
+ output?: 'object' | undefined;
3676
+ /**
3677
+ The language model to use.
3678
+ */
3679
+ model: LanguageModel;
3680
+ /**
3681
+ The schema of the object that the model should generate.
3682
+ */
3683
+ schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT>;
3684
+ /**
3685
+ Optional name of the output that should be generated.
3686
+ Used by some providers for additional LLM guidance, e.g.
3687
+ via tool or schema name.
3688
+ */
3689
+ schemaName?: string;
3690
+ /**
3691
+ Optional description of the output that should be generated.
3692
+ Used by some providers for additional LLM guidance, e.g.
3693
+ via tool or schema description.
3694
+ */
3695
+ schemaDescription?: string;
3696
+ /**
3697
+ The mode to use for object generation.
3698
+
3699
+ The schema is converted into a JSON schema and used in one of the following ways
3700
+
3701
+ - 'auto': The provider will choose the best mode for the model.
3702
+ - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
3703
+ - '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.
3704
+
3705
+ Please note that most providers do not support all modes.
3706
+
3707
+ Default and recommended: 'auto' (best mode for the model).
3708
+ */
3709
+ mode?: 'auto' | 'json' | 'tool';
3710
+ /**
3711
+ Optional telemetry configuration (experimental).
3712
+ */
3713
+ experimental_telemetry?: TelemetrySettings;
3714
+ /**
3715
+ Additional provider-specific options. They are passed through
3716
+ to the provider from the AI SDK and enable provider-specific
3717
+ functionality that can be fully encapsulated in the provider.
3718
+ */
3719
+ providerOptions?: ProviderOptions;
3720
+ /**
3721
+ @deprecated Use `providerOptions` instead.
3722
+ */
3723
+ experimental_providerMetadata?: ProviderMetadata;
3724
+ /**
3725
+ Callback that is invoked when an error occurs during streaming.
3726
+ You can use it to log errors.
3727
+ The stream processing will pause until the callback promise is resolved.
3728
+ */
3729
+ onError?: StreamObjectOnErrorCallback;
3730
+ /**
3731
+ Callback that is called when the LLM response and the final object validation are finished.
3732
+ */
3733
+ onFinish?: StreamObjectOnFinishCallback<OBJECT>;
3734
+ /**
3735
+ * Internal. For test use only. May change without notice.
3736
+ */
3737
+ _internal?: {
3738
+ generateId?: () => string;
3739
+ currentDate?: () => Date;
3740
+ now?: () => number;
3741
+ };
3742
+ }): StreamObjectResult<DeepPartial<OBJECT>, OBJECT, never>;
3743
+ /**
3744
+ Generate an array with structured, typed elements for a given prompt and element schema using a language model.
3745
+
3746
+ This function streams the output. If you do not want to stream the output, use `generateObject` instead.
3747
+
3748
+ @return
3749
+ A result object for accessing the partial object stream and additional information.
3750
+ */
3751
+ declare function streamObject<ELEMENT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
3752
+ output: 'array';
3753
+ /**
3754
+ The language model to use.
3755
+ */
3756
+ model: LanguageModel;
3757
+ /**
3758
+ The element schema of the array that the model should generate.
3759
+ */
3760
+ schema: z.Schema<ELEMENT, z.ZodTypeDef, any> | Schema<ELEMENT>;
3761
+ /**
3762
+ Optional name of the array that should be generated.
3763
+ Used by some providers for additional LLM guidance, e.g.
3764
+ via tool or schema name.
3765
+ */
3766
+ schemaName?: string;
3767
+ /**
3768
+ Optional description of the array that should be generated.
3769
+ Used by some providers for additional LLM guidance, e.g.
3770
+ via tool or schema description.
3771
+ */
3772
+ schemaDescription?: string;
3773
+ /**
3774
+ The mode to use for object generation.
3775
+
3776
+ The schema is converted into a JSON schema and used in one of the following ways
3777
+
3778
+ - 'auto': The provider will choose the best mode for the model.
3779
+ - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
3780
+ - '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.
3781
+
3782
+ Please note that most providers do not support all modes.
3783
+
3784
+ Default and recommended: 'auto' (best mode for the model).
3785
+ */
3786
+ mode?: 'auto' | 'json' | 'tool';
3787
+ /**
3788
+ Optional telemetry configuration (experimental).
3789
+ */
3790
+ experimental_telemetry?: TelemetrySettings;
3791
+ /**
3792
+ Additional provider-specific options. They are passed through
3793
+ to the provider from the AI SDK and enable provider-specific
3794
+ functionality that can be fully encapsulated in the provider.
3795
+ */
3796
+ providerOptions?: ProviderOptions;
3797
+ /**
3798
+ @deprecated Use `providerOptions` instead.
3799
+ */
3800
+ experimental_providerMetadata?: ProviderMetadata;
3801
+ /**
3802
+ Callback that is invoked when an error occurs during streaming.
3803
+ You can use it to log errors.
3804
+ The stream processing will pause until the callback promise is resolved.
3805
+ */
3806
+ onError?: StreamObjectOnErrorCallback;
3807
+ /**
3808
+ Callback that is called when the LLM response and the final object validation are finished.
3809
+ */
3810
+ onFinish?: StreamObjectOnFinishCallback<Array<ELEMENT>>;
3811
+ /**
3812
+ * Internal. For test use only. May change without notice.
3813
+ */
3814
+ _internal?: {
3815
+ generateId?: () => string;
3816
+ currentDate?: () => Date;
3817
+ now?: () => number;
3818
+ };
3819
+ }): StreamObjectResult<Array<ELEMENT>, Array<ELEMENT>, AsyncIterableStream<ELEMENT>>;
3820
+ /**
3821
+ Generate JSON with any schema for a given prompt using a language model.
3822
+
3823
+ This function streams the output. If you do not want to stream the output, use `generateObject` instead.
3824
+
3825
+ @return
3826
+ A result object for accessing the partial object stream and additional information.
3827
+ */
3828
+ declare function streamObject(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
3829
+ output: 'no-schema';
3830
+ /**
3831
+ The language model to use.
3832
+ */
3833
+ model: LanguageModel;
3834
+ /**
3835
+ The mode to use for object generation. Must be "json" for no-schema output.
3836
+ */
3837
+ mode?: 'json';
3838
+ /**
3839
+ Optional telemetry configuration (experimental).
3840
+ */
3841
+ experimental_telemetry?: TelemetrySettings;
3842
+ /**
3843
+ Additional provider-specific options. They are passed through
3844
+ to the provider from the AI SDK and enable provider-specific
3845
+ functionality that can be fully encapsulated in the provider.
3846
+ */
3847
+ providerOptions?: ProviderOptions;
3848
+ /**
3849
+ @deprecated Use `providerOptions` instead.
3850
+ */
3851
+ experimental_providerMetadata?: ProviderMetadata;
3852
+ /**
3853
+ Callback that is invoked when an error occurs during streaming.
3854
+ You can use it to log errors.
3855
+ The stream processing will pause until the callback promise is resolved.
3856
+ */
3857
+ onError?: StreamObjectOnErrorCallback;
3858
+ /**
3859
+ Callback that is called when the LLM response and the final object validation are finished.
3860
+ */
3861
+ onFinish?: StreamObjectOnFinishCallback<JSONValue>;
3862
+ /**
3863
+ * Internal. For test use only. May change without notice.
3864
+ */
3865
+ _internal?: {
3866
+ generateId?: () => string;
3867
+ currentDate?: () => Date;
3868
+ now?: () => number;
3869
+ };
3870
+ }): StreamObjectResult<JSONValue, JSONValue, never>;
3871
+
3872
+ /**
3873
+ * A generated audio file.
3874
+ */
3875
+ interface GeneratedAudioFile extends GeneratedFile {
3876
+ /**
3877
+ * Audio format of the file (e.g., 'mp3', 'wav', etc.)
3878
+ */
3879
+ readonly format: string;
3880
+ }
3881
+
3882
+ /**
3883
+ The result of a `generateSpeech` call.
3884
+ It contains the audio data and additional information.
3885
+ */
3886
+ interface SpeechResult {
3887
+ /**
3888
+ * The audio data as a base64 encoded string or binary data.
3889
+ */
3890
+ readonly audio: GeneratedAudioFile;
3891
+ /**
3892
+ Warnings for the call, e.g. unsupported settings.
3893
+ */
3894
+ readonly warnings: Array<SpeechWarning>;
3895
+ /**
3896
+ Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
3897
+ */
3898
+ readonly responses: Array<SpeechModelResponseMetadata>;
3899
+ /**
3900
+ Provider metadata from the provider.
3901
+ */
3902
+ readonly providerMetadata: Record<string, Record<string, JSONValue>>;
3903
+ }
3904
+
3905
+ /**
3906
+ Generates speech audio using a speech model.
3907
+
3908
+ @param model - The speech model to use.
3909
+ @param text - The text to convert to speech.
3910
+ @param voice - The voice to use for speech generation.
3911
+ @param outputFormat - The output format to use for speech generation e.g. "mp3", "wav", etc.
3912
+ @param instructions - Instructions for the speech generation e.g. "Speak in a slow and steady tone".
3913
+ @param speed - The speed of the speech generation.
3914
+ @param providerOptions - Additional provider-specific options that are passed through to the provider
3915
+ as body parameters.
3916
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
3917
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
3918
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
3919
+
3920
+ @returns A result object that contains the generated audio data.
2100
3921
  */
2101
- maxSteps?: number;
3922
+ declare function generateSpeech({ model, text, voice, outputFormat, instructions, speed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
2102
3923
  /**
2103
- When enabled, the model will perform additional steps if the finish reason is "length" (experimental).
2104
-
2105
- By default, it's set to false.
2106
- */
2107
- experimental_continueSteps?: boolean;
3924
+ The speech model to use.
3925
+ */
3926
+ model: SpeechModelV1;
2108
3927
  /**
2109
- Optional telemetry configuration (experimental).
3928
+ The text to convert to speech.
2110
3929
  */
2111
- experimental_telemetry?: TelemetrySettings;
2112
- /**
2113
- Additional provider-specific metadata. They are passed through
2114
- to the provider from the AI SDK and enable provider-specific
2115
- functionality that can be fully encapsulated in the provider.
2116
- */
2117
- experimental_providerMetadata?: ProviderMetadata;
3930
+ text: string;
2118
3931
  /**
2119
- Limits the tools that are available for the model to call without
2120
- changing the tool call and result types in the result.
3932
+ The voice to use for speech generation.
2121
3933
  */
2122
- experimental_activeTools?: Array<keyof TOOLS>;
3934
+ voice?: string;
2123
3935
  /**
2124
- Optional specification for parsing structured outputs from the LLM response.
3936
+ * The desired output format for the audio e.g. "mp3", "wav", etc.
2125
3937
  */
2126
- experimental_output?: Output<OUTPUT, PARTIAL_OUTPUT>;
3938
+ outputFormat?: 'mp3' | 'wav' | (string & {});
2127
3939
  /**
2128
- A function that attempts to repair a tool call that failed to parse.
3940
+ Instructions for the speech generation e.g. "Speak in a slow and steady tone".
3941
+ */
3942
+ instructions?: string;
3943
+ /**
3944
+ The speed of the speech generation.
2129
3945
  */
2130
- experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
3946
+ speed?: number;
2131
3947
  /**
2132
- Enable streaming of tool call deltas as they are generated. Disabled by default.
3948
+ Additional provider-specific options that are passed through to the provider
3949
+ as body parameters.
3950
+
3951
+ The outer record is keyed by the provider name, and the inner
3952
+ record is keyed by the provider-specific metadata key.
3953
+ ```ts
3954
+ {
3955
+ "openai": {}
3956
+ }
3957
+ ```
3958
+ */
3959
+ providerOptions?: ProviderOptions;
3960
+ /**
3961
+ Maximum number of retries per speech model call. Set to 0 to disable retries.
3962
+
3963
+ @default 2
2133
3964
  */
2134
- experimental_toolCallStreaming?: boolean;
3965
+ maxRetries?: number;
3966
+ /**
3967
+ Abort signal.
3968
+ */
3969
+ abortSignal?: AbortSignal;
2135
3970
  /**
2136
- Optional transformation that is applied to the stream.
3971
+ Additional headers to include in the request.
3972
+ Only applicable for HTTP-based providers.
3973
+ */
3974
+ headers?: Record<string, string>;
3975
+ }): Promise<SpeechResult>;
2137
3976
 
2138
- @param stopStream - A function that stops the source stream.
2139
- @param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
2140
- */
2141
- experimental_transform?: (options: {
2142
- tools: TOOLS;
2143
- stopStream: () => void;
2144
- }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
3977
+ /**
3978
+ The result of a `transcribe` call.
3979
+ It contains the transcript and additional information.
3980
+ */
3981
+ interface TranscriptionResult {
2145
3982
  /**
2146
- Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
3983
+ * The complete transcribed text from the audio.
2147
3984
  */
2148
- onChunk?: (event: {
2149
- chunk: Extract<TextStreamPart<TOOLS>, {
2150
- type: 'text-delta' | 'tool-call' | 'tool-call-streaming-start' | 'tool-call-delta' | 'tool-result';
2151
- }>;
2152
- }) => Promise<void> | void;
3985
+ readonly text: string;
2153
3986
  /**
2154
- Callback that is called when the LLM response and all request tool executions
2155
- (for tools that have an `execute` function) are finished.
2156
-
2157
- The usage is the combined usage of all steps.
3987
+ * Array of transcript segments with timing information.
3988
+ * Each segment represents a portion of the transcribed text with start and end times.
2158
3989
  */
2159
- onFinish?: (event: Omit<StepResult<TOOLS>, 'stepType' | 'isContinued'> & {
3990
+ readonly segments: Array<{
2160
3991
  /**
2161
- Details for all steps.
3992
+ * The text content of this segment.
3993
+ */
3994
+ readonly text: string;
3995
+ /**
3996
+ * The start time of this segment in seconds.
3997
+ */
3998
+ readonly startSecond: number;
3999
+ /**
4000
+ * The end time of this segment in seconds.
4001
+ */
4002
+ readonly endSecond: number;
4003
+ }>;
4004
+ /**
4005
+ * The detected language of the audio content, as an ISO-639-1 code (e.g., 'en' for English).
4006
+ * May be undefined if the language couldn't be detected.
4007
+ */
4008
+ readonly language: string | undefined;
4009
+ /**
4010
+ * The total duration of the audio file in seconds.
4011
+ * May be undefined if the duration couldn't be determined.
4012
+ */
4013
+ readonly durationInSeconds: number | undefined;
4014
+ /**
4015
+ Warnings for the call, e.g. unsupported settings.
2162
4016
  */
2163
- readonly steps: StepResult<TOOLS>[];
2164
- }) => Promise<void> | void;
4017
+ readonly warnings: Array<TranscriptionWarning>;
2165
4018
  /**
2166
- Callback that is called when each step (LLM call) is finished, including intermediate steps.
2167
- */
2168
- onStepFinish?: (event: StepResult<TOOLS>) => Promise<void> | void;
4019
+ Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
4020
+ */
4021
+ readonly responses: Array<TranscriptionModelResponseMetadata>;
2169
4022
  /**
2170
- * Internal. For test use only. May change without notice.
4023
+ Provider metadata from the provider.
2171
4024
  */
2172
- _internal?: {
2173
- now?: () => number;
2174
- generateId?: () => string;
2175
- currentDate?: () => Date;
2176
- };
2177
- }): StreamTextResult<TOOLS, PARTIAL_OUTPUT>;
4025
+ readonly providerMetadata: Record<string, Record<string, JSONValue>>;
4026
+ }
2178
4027
 
2179
4028
  /**
2180
- * Smooths text streaming output.
2181
- *
2182
- * @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
2183
- * @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, or provide a custom RegExp pattern for custom chunking.
2184
- *
2185
- * @returns A transform stream that smooths text streaming output.
4029
+ Generates transcripts using a transcription model.
4030
+
4031
+ @param model - The transcription model to use.
4032
+ @param audio - The audio data to transcribe as DataContent (string | Uint8Array | ArrayBuffer | Buffer) or a URL.
4033
+ @param providerOptions - Additional provider-specific options that are passed through to the provider
4034
+ as body parameters.
4035
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
4036
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
4037
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
4038
+
4039
+ @returns A result object that contains the generated transcript.
2186
4040
  */
2187
- declare function smoothStream<TOOLS extends Record<string, CoreTool>>({ delayInMs, chunking, _internal: { delay }, }?: {
2188
- delayInMs?: number | null;
2189
- chunking?: 'word' | 'line' | RegExp;
4041
+ declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
2190
4042
  /**
2191
- * Internal. For test use only. May change without notice.
4043
+ The transcription model to use.
4044
+ */
4045
+ model: TranscriptionModelV1;
4046
+ /**
4047
+ The audio data to transcribe.
2192
4048
  */
2193
- _internal?: {
2194
- delay?: (delayInMs: number | null) => Promise<void>;
2195
- };
2196
- }): (options: {
2197
- tools: TOOLS;
2198
- }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
4049
+ audio: DataContent | URL;
4050
+ /**
4051
+ Additional provider-specific options that are passed through to the provider
4052
+ as body parameters.
4053
+
4054
+ The outer record is keyed by the provider name, and the inner
4055
+ record is keyed by the provider-specific metadata key.
4056
+ ```ts
4057
+ {
4058
+ "openai": {
4059
+ "temperature": 0
4060
+ }
4061
+ }
4062
+ ```
4063
+ */
4064
+ providerOptions?: ProviderOptions;
4065
+ /**
4066
+ Maximum number of retries per transcript model call. Set to 0 to disable retries.
4067
+
4068
+ @default 2
4069
+ */
4070
+ maxRetries?: number;
4071
+ /**
4072
+ Abort signal.
4073
+ */
4074
+ abortSignal?: AbortSignal;
4075
+ /**
4076
+ Additional headers to include in the request.
4077
+ Only applicable for HTTP-based providers.
4078
+ */
4079
+ headers?: Record<string, string>;
4080
+ }): Promise<TranscriptionResult>;
2199
4081
 
2200
4082
  /**
2201
4083
  * Experimental middleware for LanguageModelV1.
2202
4084
  * This type defines the structure for middleware that can be used to modify
2203
4085
  * the behavior of LanguageModelV1 operations.
2204
4086
  */
2205
- type Experimental_LanguageModelV1Middleware = {
4087
+ type LanguageModelV1Middleware = {
4088
+ /**
4089
+ * Middleware specification version. Use `v1` for the current version.
4090
+ */
4091
+ middlewareVersion?: 'v1' | undefined;
2206
4092
  /**
2207
4093
  * Transforms the parameters before they are passed to the language model.
2208
4094
  * @param options - Object containing the type of operation and the parameters.
@@ -2218,6 +4104,7 @@ type Experimental_LanguageModelV1Middleware = {
2218
4104
  * Wraps the generate operation of the language model.
2219
4105
  * @param options - Object containing the generate function, parameters, and model.
2220
4106
  * @param options.doGenerate - The original generate function.
4107
+ * @param options.doStream - The original stream function.
2221
4108
  * @param options.params - The parameters for the generate call. If the
2222
4109
  * `transformParams` middleware is used, this will be the transformed parameters.
2223
4110
  * @param options.model - The language model instance.
@@ -2225,12 +4112,15 @@ type Experimental_LanguageModelV1Middleware = {
2225
4112
  */
2226
4113
  wrapGenerate?: (options: {
2227
4114
  doGenerate: () => ReturnType<LanguageModelV1['doGenerate']>;
4115
+ doStream: () => ReturnType<LanguageModelV1['doStream']>;
2228
4116
  params: LanguageModelV1CallOptions;
2229
4117
  model: LanguageModelV1;
2230
4118
  }) => Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
2231
4119
  /**
2232
4120
  * Wraps the stream operation of the language model.
4121
+ *
2233
4122
  * @param options - Object containing the stream function, parameters, and model.
4123
+ * @param options.doGenerate - The original generate function.
2234
4124
  * @param options.doStream - The original stream function.
2235
4125
  * @param options.params - The parameters for the stream call. If the
2236
4126
  * `transformParams` middleware is used, this will be the transformed parameters.
@@ -2238,11 +4128,44 @@ type Experimental_LanguageModelV1Middleware = {
2238
4128
  * @returns A promise that resolves to the result of the stream operation.
2239
4129
  */
2240
4130
  wrapStream?: (options: {
4131
+ doGenerate: () => ReturnType<LanguageModelV1['doGenerate']>;
2241
4132
  doStream: () => ReturnType<LanguageModelV1['doStream']>;
2242
4133
  params: LanguageModelV1CallOptions;
2243
4134
  model: LanguageModelV1;
2244
4135
  }) => PromiseLike<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
2245
4136
  };
4137
+ /**
4138
+ * @deprecated Use `LanguageModelV1Middleware` instead.
4139
+ */
4140
+ type Experimental_LanguageModelV1Middleware = LanguageModelV1Middleware;
4141
+
4142
+ /**
4143
+ * Applies default settings for a language model.
4144
+ */
4145
+ declare function defaultSettingsMiddleware({ settings, }: {
4146
+ settings: Partial<LanguageModelV1CallOptions & {
4147
+ providerMetadata?: LanguageModelV1ProviderMetadata;
4148
+ }>;
4149
+ }): LanguageModelV1Middleware;
4150
+
4151
+ /**
4152
+ * Extract an XML-tagged reasoning section from the generated text and exposes it
4153
+ * as a `reasoning` property on the result.
4154
+ *
4155
+ * @param tagName - The name of the XML tag to extract reasoning from.
4156
+ * @param separator - The separator to use between reasoning and text sections.
4157
+ * @param startWithReasoning - Whether to start with reasoning tokens.
4158
+ */
4159
+ declare function extractReasoningMiddleware({ tagName, separator, startWithReasoning, }: {
4160
+ tagName: string;
4161
+ separator?: string;
4162
+ startWithReasoning?: boolean;
4163
+ }): LanguageModelV1Middleware;
4164
+
4165
+ /**
4166
+ * Simulates streaming chunks with the response from a generate call.
4167
+ */
4168
+ declare function simulateStreamingMiddleware(): LanguageModelV1Middleware;
2246
4169
 
2247
4170
  /**
2248
4171
  * Wraps a LanguageModelV1 instance with middleware functionality.
@@ -2251,14 +4174,23 @@ type Experimental_LanguageModelV1Middleware = {
2251
4174
  *
2252
4175
  * @param options - Configuration options for wrapping the language model.
2253
4176
  * @param options.model - The original LanguageModelV1 instance to be wrapped.
2254
- * @param options.middleware - The middleware to be applied to the language model.
4177
+ * @param options.middleware - The middleware to be applied to the language model. When multiple middlewares are provided, the first middleware will transform the input first, and the last middleware will be wrapped directly around the model.
2255
4178
  * @param options.modelId - Optional custom model ID to override the original model's ID.
2256
4179
  * @param options.providerId - Optional custom provider ID to override the original model's provider.
2257
4180
  * @returns A new LanguageModelV1 instance with middleware applied.
2258
4181
  */
2259
- declare const experimental_wrapLanguageModel: ({ model, middleware: { transformParams, wrapGenerate, wrapStream }, modelId, providerId, }: {
4182
+ declare const wrapLanguageModel: ({ model, middleware: middlewareArg, modelId, providerId, }: {
4183
+ model: LanguageModelV1;
4184
+ middleware: LanguageModelV1Middleware | LanguageModelV1Middleware[];
4185
+ modelId?: string;
4186
+ providerId?: string;
4187
+ }) => LanguageModelV1;
4188
+ /**
4189
+ * @deprecated Use `wrapLanguageModel` instead.
4190
+ */
4191
+ declare const experimental_wrapLanguageModel: ({ model, middleware: middlewareArg, modelId, providerId, }: {
2260
4192
  model: LanguageModelV1;
2261
- middleware: Experimental_LanguageModelV1Middleware;
4193
+ middleware: LanguageModelV1Middleware | LanguageModelV1Middleware[];
2262
4194
  modelId?: string;
2263
4195
  providerId?: string;
2264
4196
  }) => LanguageModelV1;
@@ -2267,22 +4199,33 @@ declare const experimental_wrapLanguageModel: ({ model, middleware: { transformP
2267
4199
  * Creates a custom provider with specified language models, text embedding models, and an optional fallback provider.
2268
4200
  *
2269
4201
  * @param {Object} options - The options for creating the custom provider.
2270
- * @param {Record<string, LanguageModelV1>} [options.languageModels] - A record of language models, where keys are model IDs and values are LanguageModelV1 instances.
2271
- * @param {Record<string, EmbeddingModelV1<string>>} [options.textEmbeddingModels] - A record of text embedding models, where keys are model IDs and values are EmbeddingModelV1<string> instances.
4202
+ * @param {Record<string, LanguageModel>} [options.languageModels] - A record of language models, where keys are model IDs and values are LanguageModel instances.
4203
+ * @param {Record<string, EmbeddingModel<string>>} [options.textEmbeddingModels] - A record of text embedding models, where keys are model IDs and values are EmbeddingModel<string> instances.
4204
+ * @param {Record<string, ImageModel>} [options.imageModels] - A record of image models, where keys are model IDs and values are ImageModel instances.
2272
4205
  * @param {Provider} [options.fallbackProvider] - An optional fallback provider to use when a requested model is not found in the custom provider.
2273
- * @returns {Provider} A Provider object with languageModel and textEmbeddingModel methods.
4206
+ * @returns {Provider} A Provider object with languageModel, textEmbeddingModel, and imageModel methods.
2274
4207
  *
2275
4208
  * @throws {NoSuchModelError} Throws when a requested model is not found and no fallback provider is available.
2276
4209
  */
2277
- declare function experimental_customProvider({ languageModels, textEmbeddingModels, fallbackProvider, }: {
2278
- languageModels?: Record<string, LanguageModelV1>;
2279
- textEmbeddingModels?: Record<string, EmbeddingModelV1<string>>;
2280
- fallbackProvider?: Provider;
2281
- }): Provider;
4210
+ declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageModel>, EMBEDDING_MODELS extends Record<string, EmbeddingModel<string>>, IMAGE_MODELS extends Record<string, ImageModel>>({ languageModels, textEmbeddingModels, imageModels, fallbackProvider, }: {
4211
+ languageModels?: LANGUAGE_MODELS;
4212
+ textEmbeddingModels?: EMBEDDING_MODELS;
4213
+ imageModels?: IMAGE_MODELS;
4214
+ fallbackProvider?: ProviderV1;
4215
+ }): Provider & {
4216
+ languageModel(modelId: ExtractModelId<LANGUAGE_MODELS>): LanguageModel;
4217
+ textEmbeddingModel(modelId: ExtractModelId<EMBEDDING_MODELS>): EmbeddingModel<string>;
4218
+ imageModel(modelId: ExtractModelId<IMAGE_MODELS>): ImageModel;
4219
+ };
4220
+ /**
4221
+ * @deprecated Use `customProvider` instead.
4222
+ */
4223
+ declare const experimental_customProvider: typeof customProvider;
4224
+ type ExtractModelId<MODELS extends Record<string, unknown>> = Extract<keyof MODELS, string>;
2282
4225
 
2283
- declare const symbol$a: unique symbol;
4226
+ declare const symbol$d: unique symbol;
2284
4227
  declare class NoSuchProviderError extends NoSuchModelError {
2285
- private readonly [symbol$a];
4228
+ private readonly [symbol$d];
2286
4229
  readonly providerId: string;
2287
4230
  readonly availableProviders: string[];
2288
4231
  constructor({ modelId, modelType, providerId, availableProviders, message, }: {
@@ -2295,10 +4238,25 @@ declare class NoSuchProviderError extends NoSuchModelError {
2295
4238
  static isInstance(error: unknown): error is NoSuchProviderError;
2296
4239
  }
2297
4240
 
4241
+ type ExtractLiteralUnion<T> = T extends string ? string extends T ? never : T : never;
4242
+ interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV1> = Record<string, ProviderV1>, SEPARATOR extends string = ':'> {
4243
+ languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['languageModel']>>[0]>}` : never): LanguageModel;
4244
+ languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): LanguageModel;
4245
+ textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['textEmbeddingModel']>>[0]>}` : never): EmbeddingModel<string>;
4246
+ textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): EmbeddingModel<string>;
4247
+ imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['imageModel']>>[0]>}` : never): ImageModel;
4248
+ imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): ImageModel;
4249
+ }
2298
4250
  /**
2299
4251
  * Creates a registry for the given providers.
2300
4252
  */
2301
- declare function experimental_createProviderRegistry(providers: Record<string, Provider>): Provider;
4253
+ declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV1>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, }?: {
4254
+ separator?: SEPARATOR;
4255
+ }): ProviderRegistryProvider<PROVIDERS, SEPARATOR>;
4256
+ /**
4257
+ * @deprecated Use `createProviderRegistry` instead.
4258
+ */
4259
+ declare const experimental_createProviderRegistry: typeof createProviderRegistry;
2302
4260
 
2303
4261
  /**
2304
4262
  * Calculates the cosine similarity between two vectors. This is a useful metric for
@@ -2306,11 +4264,21 @@ declare function experimental_createProviderRegistry(providers: Record<string, P
2306
4264
  *
2307
4265
  * @param vector1 - The first vector.
2308
4266
  * @param vector2 - The second vector.
4267
+ * @param options - Optional configuration.
4268
+ * @param options.throwErrorForEmptyVectors - If true, throws an error for empty vectors. Default: false.
2309
4269
  *
2310
4270
  * @returns The cosine similarity between vector1 and vector2.
2311
- * @throws {Error} If the vectors do not have the same length.
4271
+ * @returns 0 if either vector is the zero vector.
4272
+ *
4273
+ * @throws {InvalidArgumentError} If throwErrorForEmptyVectors is true and vectors are empty.
4274
+ * @throws {InvalidArgumentError} If the vectors do not have the same length.
2312
4275
  */
2313
- declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
4276
+ declare function cosineSimilarity(vector1: number[], vector2: number[], options?: {
4277
+ /**
4278
+ * @deprecated will be removed in 5.0
4279
+ */
4280
+ throwErrorForEmptyVectors?: boolean;
4281
+ }): number;
2314
4282
 
2315
4283
  /**
2316
4284
  * Creates a ReadableStream that emits the provided values with an optional delay between each value.
@@ -2330,9 +4298,9 @@ declare function simulateReadableStream<T>({ chunks, initialDelayInMs, chunkDela
2330
4298
  };
2331
4299
  }): ReadableStream<T>;
2332
4300
 
2333
- declare const symbol$9: unique symbol;
4301
+ declare const symbol$c: unique symbol;
2334
4302
  declare class InvalidArgumentError extends AISDKError {
2335
- private readonly [symbol$9];
4303
+ private readonly [symbol$c];
2336
4304
  readonly parameter: string;
2337
4305
  readonly value: unknown;
2338
4306
  constructor({ parameter, value, message, }: {
@@ -2343,7 +4311,85 @@ declare class InvalidArgumentError extends AISDKError {
2343
4311
  static isInstance(error: unknown): error is InvalidArgumentError;
2344
4312
  }
2345
4313
 
2346
- declare const symbol$8: unique symbol;
4314
+ type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
4315
+ type: 'text-delta';
4316
+ textDelta: string;
4317
+ } | {
4318
+ type: 'reasoning';
4319
+ textDelta: string;
4320
+ } | {
4321
+ type: 'reasoning-signature';
4322
+ signature: string;
4323
+ } | {
4324
+ type: 'redacted-reasoning';
4325
+ data: string;
4326
+ } | ({
4327
+ type: 'file';
4328
+ } & GeneratedFile) | {
4329
+ type: 'source';
4330
+ source: Source;
4331
+ } | ({
4332
+ type: 'tool-call';
4333
+ } & ToolCallUnion<TOOLS>) | {
4334
+ type: 'tool-call-streaming-start';
4335
+ toolCallId: string;
4336
+ toolName: string;
4337
+ } | {
4338
+ type: 'tool-call-delta';
4339
+ toolCallId: string;
4340
+ toolName: string;
4341
+ argsTextDelta: string;
4342
+ } | ({
4343
+ type: 'tool-result';
4344
+ } & ToolResultUnion<TOOLS>) | {
4345
+ type: 'response-metadata';
4346
+ id?: string;
4347
+ timestamp?: Date;
4348
+ modelId?: string;
4349
+ } | {
4350
+ type: 'finish';
4351
+ finishReason: FinishReason;
4352
+ logprobs?: LogProbs;
4353
+ usage: LanguageModelUsage;
4354
+ experimental_providerMetadata?: ProviderMetadata;
4355
+ } | {
4356
+ type: 'error';
4357
+ error: unknown;
4358
+ };
4359
+
4360
+ declare const symbol$b: unique symbol;
4361
+ declare class InvalidStreamPartError extends AISDKError {
4362
+ private readonly [symbol$b];
4363
+ readonly chunk: SingleRequestTextStreamPart<any>;
4364
+ constructor({ chunk, message, }: {
4365
+ chunk: SingleRequestTextStreamPart<any>;
4366
+ message: string;
4367
+ });
4368
+ static isInstance(error: unknown): error is InvalidStreamPartError;
4369
+ }
4370
+
4371
+ declare const symbol$a: unique symbol;
4372
+ /**
4373
+ Thrown when no image could be generated. This can have multiple causes:
4374
+
4375
+ - The model failed to generate a response.
4376
+ - The model generated a response that could not be parsed.
4377
+ */
4378
+ declare class NoImageGeneratedError extends AISDKError {
4379
+ private readonly [symbol$a];
4380
+ /**
4381
+ The response metadata for each call.
4382
+ */
4383
+ readonly responses: Array<ImageModelResponseMetadata> | undefined;
4384
+ constructor({ message, cause, responses, }: {
4385
+ message?: string;
4386
+ cause?: Error;
4387
+ responses?: Array<ImageModelResponseMetadata>;
4388
+ });
4389
+ static isInstance(error: unknown): error is NoImageGeneratedError;
4390
+ }
4391
+
4392
+ declare const symbol$9: unique symbol;
2347
4393
  /**
2348
4394
  Thrown when no object could be generated. This can have several causes:
2349
4395
 
@@ -2356,7 +4402,7 @@ The error contains the following properties:
2356
4402
  - `text`: The text that was generated by the model. This can be the raw text or the tool call text, depending on the model.
2357
4403
  */
2358
4404
  declare class NoObjectGeneratedError extends AISDKError {
2359
- private readonly [symbol$8];
4405
+ private readonly [symbol$9];
2360
4406
  /**
2361
4407
  The text that was generated by the model. This can be the raw text or the tool call text, depending on the model.
2362
4408
  */
@@ -2369,31 +4415,36 @@ declare class NoObjectGeneratedError extends AISDKError {
2369
4415
  The usage of the model.
2370
4416
  */
2371
4417
  readonly usage: LanguageModelUsage | undefined;
2372
- constructor({ message, cause, text, response, usage, }: {
4418
+ /**
4419
+ Reason why the model finished generating a response.
4420
+ */
4421
+ readonly finishReason: FinishReason | undefined;
4422
+ constructor({ message, cause, text, response, usage, finishReason, }: {
2373
4423
  message?: string;
2374
4424
  cause?: Error;
2375
4425
  text?: string;
2376
4426
  response: LanguageModelResponseMetadata;
2377
4427
  usage: LanguageModelUsage;
4428
+ finishReason: FinishReason;
2378
4429
  });
2379
4430
  static isInstance(error: unknown): error is NoObjectGeneratedError;
2380
4431
  }
2381
4432
 
2382
- declare const symbol$7: unique symbol;
4433
+ declare const symbol$8: unique symbol;
2383
4434
  /**
2384
4435
  Thrown when no output type is specified and output-related methods are called.
2385
4436
  */
2386
4437
  declare class NoOutputSpecifiedError extends AISDKError {
2387
- private readonly [symbol$7];
4438
+ private readonly [symbol$8];
2388
4439
  constructor({ message }?: {
2389
4440
  message?: string;
2390
4441
  });
2391
4442
  static isInstance(error: unknown): error is NoOutputSpecifiedError;
2392
4443
  }
2393
4444
 
2394
- declare const symbol$6: unique symbol;
4445
+ declare const symbol$7: unique symbol;
2395
4446
  declare class ToolCallRepairError extends AISDKError {
2396
- private readonly [symbol$6];
4447
+ private readonly [symbol$7];
2397
4448
  readonly originalError: NoSuchToolError | InvalidToolArgumentsError;
2398
4449
  constructor({ cause, originalError, message, }: {
2399
4450
  message?: string;
@@ -2403,9 +4454,9 @@ declare class ToolCallRepairError extends AISDKError {
2403
4454
  static isInstance(error: unknown): error is ToolCallRepairError;
2404
4455
  }
2405
4456
 
2406
- declare const symbol$5: unique symbol;
4457
+ declare const symbol$6: unique symbol;
2407
4458
  declare class ToolExecutionError extends AISDKError {
2408
- private readonly [symbol$5];
4459
+ private readonly [symbol$6];
2409
4460
  readonly toolName: string;
2410
4461
  readonly toolArgs: JSONValue;
2411
4462
  readonly toolCallId: string;
@@ -2419,6 +4470,20 @@ declare class ToolExecutionError extends AISDKError {
2419
4470
  static isInstance(error: unknown): error is ToolExecutionError;
2420
4471
  }
2421
4472
 
4473
+ declare const symbol$5: unique symbol;
4474
+ /**
4475
+ * An error occurred with the MCP client.
4476
+ */
4477
+ declare class MCPClientError extends AISDKError {
4478
+ private readonly [symbol$5];
4479
+ constructor({ name, message, cause, }: {
4480
+ name?: string;
4481
+ message: string;
4482
+ cause?: unknown;
4483
+ });
4484
+ static isInstance(error: unknown): error is MCPClientError;
4485
+ }
4486
+
2422
4487
  declare const symbol$4: unique symbol;
2423
4488
  declare class InvalidDataContentError extends AISDKError {
2424
4489
  private readonly [symbol$4];
@@ -2445,9 +4510,9 @@ declare class InvalidMessageRoleError extends AISDKError {
2445
4510
  declare const symbol$2: unique symbol;
2446
4511
  declare class MessageConversionError extends AISDKError {
2447
4512
  private readonly [symbol$2];
2448
- readonly originalMessage: UIMessage;
4513
+ readonly originalMessage: Omit<Message, 'id'>;
2449
4514
  constructor({ originalMessage, message, }: {
2450
- originalMessage: UIMessage;
4515
+ originalMessage: Omit<Message, 'id'>;
2451
4516
  message: string;
2452
4517
  });
2453
4518
  static isInstance(error: unknown): error is MessageConversionError;
@@ -2617,4 +4682,4 @@ declare namespace llamaindexAdapter {
2617
4682
  };
2618
4683
  }
2619
4684
 
2620
- export { AssistantContent, AssistantResponse, CallWarning, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, ToolCallUnion as CoreToolCallUnion, CoreToolChoice, CoreToolMessage, ToolResultUnion as CoreToolResultUnion, CoreUserMessage, DataContent, DataStreamWriter, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedImage as Experimental_GeneratedImage, Experimental_LanguageModelV1Middleware, FilePart, FinishReason, GenerateObjectResult, GenerateTextResult, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidToolArgumentsError, langchainAdapter as LangChainAdapter, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, llamaindexAdapter as LlamaIndexAdapter, LogProbs, MessageConversionError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Provider, ProviderMetadata, RetryError, StepResult, StreamData, StreamObjectResult, StreamTextResult, TextPart, TextStreamPart, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolResultPart, UserContent, convertToCoreMessages, cosineSimilarity, createDataStream, createDataStreamResponse, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, experimental_wrapLanguageModel, generateObject, generateText, pipeDataStreamToResponse, simulateReadableStream, smoothStream, streamObject, streamText, tool };
4685
+ export { AssistantContent, AssistantResponse, CallWarning, ChunkDetector, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, CoreToolCallUnion, CoreToolChoice, CoreToolMessage, CoreToolResultUnion, CoreUserMessage, DataContent, DataStreamOptions, DataStreamWriter, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, Experimental_LanguageModelV1Middleware, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FinishReason, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelResponseMetadata, ImagePart, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, langchainAdapter as LangChainAdapter, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LanguageModelV1Middleware, llamaindexAdapter as LlamaIndexAdapter, LogProbs, MCPClientError, MCPTransport, MessageConversionError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, Provider, ProviderMetadata, ProviderRegistryProvider, RepairTextFunction, RetryError, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StreamData, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextPart, TextStreamPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UserContent, appendClientMessage, appendResponseMessages, convertToCoreMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createDataStream, createDataStreamResponse, createProviderRegistry, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, experimental_wrapLanguageModel, extractReasoningMiddleware, generateObject, generateText, pipeDataStreamToResponse, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, tool, wrapLanguageModel };