ai 5.0.0-alpha.11 → 5.0.0-alpha.12

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.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { ToolResultContent, Schema, ToolCall, ToolResult, Validator, StandardSchemaV1, IdGenerator, InferSchema, FetchFunction } from '@ai-sdk/provider-utils';
1
+ import { ToolResultContent, Schema, ToolCall, ToolResult, Validator, StandardSchemaV1, IdGenerator, FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
2
2
  export { IdGenerator, Schema, ToolCall, ToolResult, asSchema, createIdGenerator, generateId, jsonSchema } from '@ai-sdk/provider-utils';
3
3
  import { AISDKError, SharedV2ProviderMetadata, SharedV2ProviderOptions, EmbeddingModelV2, EmbeddingModelV2Embedding, ImageModelV2, ImageModelV2CallWarning, ImageModelV2ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV2, LanguageModelV2FinishReason, LanguageModelV2CallWarning, LanguageModelV2Source, SpeechModelV1, SpeechModelV1CallWarning, TranscriptionModelV1, TranscriptionModelV1CallWarning, LanguageModelV2Usage, JSONObject, LanguageModelV2ToolCall, JSONSchema7, LanguageModelV2CallOptions, JSONParseError, TypeValidationError, LanguageModelV2Middleware, ProviderV2, NoSuchModelError } from '@ai-sdk/provider';
4
4
  export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
@@ -1974,6 +1974,9 @@ type SingleRequestTextStreamPart<TOOLS extends ToolSet> = ContentPart<TOOLS> | {
1974
1974
  } | {
1975
1975
  type: 'error';
1976
1976
  error: unknown;
1977
+ } | {
1978
+ type: 'raw';
1979
+ rawValue: unknown;
1977
1980
  };
1978
1981
 
1979
1982
  declare const symbol$c: unique symbol;
@@ -2186,6 +2189,8 @@ type UIDataPartSchemas = Record<string, Validator<any> | StandardSchemaV1<any>>;
2186
2189
  type InferUIDataParts<T extends UIDataPartSchemas> = {
2187
2190
  [K in keyof T]: T[K] extends Validator<infer U> ? U : T[K] extends StandardSchemaV1<infer U> ? U : unknown;
2188
2191
  };
2192
+ type InferUIMessageData<T extends UIMessage> = T extends UIMessage<unknown, infer DATA_TYPES> ? DATA_TYPES : UIDataTypes;
2193
+ type InferUIMessageMetadata<T extends UIMessage> = T extends UIMessage<infer METADATA, UIDataTypes> ? METADATA : unknown;
2189
2194
  /**
2190
2195
  * A text part of a message.
2191
2196
  */
@@ -2341,352 +2346,497 @@ declare function callCompletionApi({ api, prompt, credentials, headers, body, st
2341
2346
  fetch: ReturnType<typeof getOriginalFetch> | undefined;
2342
2347
  }): Promise<string | null | undefined>;
2343
2348
 
2344
- /**
2345
- The result of an `embed` call.
2346
- It contains the embedding, the value, and additional information.
2347
- */
2348
- interface EmbedResult<VALUE> {
2349
- /**
2350
- The value that was embedded.
2351
- */
2352
- readonly value: VALUE;
2353
- /**
2354
- The embedding of the value.
2355
- */
2356
- readonly embedding: Embedding;
2357
- /**
2358
- The embedding token usage.
2359
- */
2360
- readonly usage: EmbeddingModelUsage;
2361
- /**
2362
- Optional response data.
2363
- */
2364
- readonly response?: {
2365
- /**
2366
- Response headers.
2367
- */
2368
- headers?: Record<string, string>;
2369
- /**
2370
- The response body.
2371
- */
2372
- body?: unknown;
2349
+ type DataUIMessageStreamPart<DATA_TYPES extends UIDataTypes> = ValueOf<{
2350
+ [NAME in keyof DATA_TYPES & string]: {
2351
+ type: `data-${NAME}`;
2352
+ id?: string;
2353
+ data: DATA_TYPES[NAME];
2373
2354
  };
2374
- }
2375
-
2376
- /**
2377
- Embed a value using an embedding model. The type of the value is defined by the embedding model.
2378
-
2379
- @param model - The embedding model to use.
2380
- @param value - The value that should be embedded.
2381
-
2382
- @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
2383
- @param abortSignal - An optional abort signal that can be used to cancel the call.
2384
- @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
2355
+ }>;
2356
+ type UIMessageStreamPart<METADATA = unknown, DATA_TYPES extends UIDataTypes = UIDataTypes> = {
2357
+ type: 'text';
2358
+ text: string;
2359
+ } | {
2360
+ type: 'error';
2361
+ errorText: string;
2362
+ } | {
2363
+ type: 'tool-call';
2364
+ toolCallId: string;
2365
+ toolName: string;
2366
+ args: unknown;
2367
+ } | {
2368
+ type: 'tool-result';
2369
+ toolCallId: string;
2370
+ result: unknown;
2371
+ providerMetadata?: ProviderMetadata;
2372
+ } | {
2373
+ type: 'tool-call-streaming-start';
2374
+ toolCallId: string;
2375
+ toolName: string;
2376
+ } | {
2377
+ type: 'tool-call-delta';
2378
+ toolCallId: string;
2379
+ argsTextDelta: string;
2380
+ } | {
2381
+ type: 'reasoning';
2382
+ text: string;
2383
+ providerMetadata?: ProviderMetadata;
2384
+ } | {
2385
+ type: 'source-url';
2386
+ sourceId: string;
2387
+ url: string;
2388
+ title?: string;
2389
+ providerMetadata?: ProviderMetadata;
2390
+ } | {
2391
+ type: 'source-document';
2392
+ sourceId: string;
2393
+ mediaType: string;
2394
+ title: string;
2395
+ filename?: string;
2396
+ providerMetadata?: ProviderMetadata;
2397
+ } | {
2398
+ type: 'file';
2399
+ url: string;
2400
+ mediaType: string;
2401
+ } | DataUIMessageStreamPart<DATA_TYPES> | {
2402
+ type: 'metadata';
2403
+ metadata: METADATA;
2404
+ } | {
2405
+ type: 'start-step';
2406
+ metadata?: METADATA;
2407
+ } | {
2408
+ type: 'finish-step';
2409
+ metadata?: METADATA;
2410
+ } | {
2411
+ type: 'start';
2412
+ messageId?: string;
2413
+ metadata?: METADATA;
2414
+ } | {
2415
+ type: 'finish';
2416
+ metadata?: METADATA;
2417
+ } | {
2418
+ type: 'reasoning-part-finish';
2419
+ };
2420
+ type InferUIMessageStreamPart<T extends UIMessage> = UIMessageStreamPart<InferUIMessageMetadata<T>, InferUIMessageData<T>>;
2385
2421
 
2386
- @returns A result object that contains the embedding, the value, and additional information.
2387
- */
2388
- declare function embed<VALUE>({ model, value, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
2389
- /**
2390
- The embedding model to use.
2391
- */
2392
- model: EmbeddingModel<VALUE>;
2422
+ interface UIMessageStreamWriter<UI_MESSAGE extends UIMessage = UIMessage> {
2393
2423
  /**
2394
- The value that should be embedded.
2424
+ * Appends a data stream part to the stream.
2395
2425
  */
2396
- value: VALUE;
2426
+ write(part: InferUIMessageStreamPart<UI_MESSAGE>): void;
2397
2427
  /**
2398
- Maximum number of retries per embedding model call. Set to 0 to disable retries.
2399
-
2400
- @default 2
2428
+ * Merges the contents of another stream to this stream.
2401
2429
  */
2402
- maxRetries?: number;
2403
- /**
2404
- Abort signal.
2405
- */
2406
- abortSignal?: AbortSignal;
2407
- /**
2408
- Additional headers to include in the request.
2409
- Only applicable for HTTP-based providers.
2410
- */
2411
- headers?: Record<string, string>;
2412
- /**
2413
- Additional provider-specific options. They are passed through
2414
- to the provider from the AI SDK and enable provider-specific
2415
- functionality that can be fully encapsulated in the provider.
2416
- */
2417
- providerOptions?: ProviderOptions;
2430
+ merge(stream: ReadableStream<InferUIMessageStreamPart<UI_MESSAGE>>): void;
2418
2431
  /**
2419
- * Optional telemetry configuration (experimental).
2432
+ * Error handler that is used by the data stream writer.
2433
+ * This is intended for forwarding when merging streams
2434
+ * to prevent duplicated error masking.
2420
2435
  */
2421
- experimental_telemetry?: TelemetrySettings;
2422
- }): Promise<EmbedResult<VALUE>>;
2436
+ onError: ((error: unknown) => string) | undefined;
2437
+ }
2423
2438
 
2424
- /**
2425
- The result of a `embedMany` call.
2426
- It contains the embeddings, the values, and additional information.
2427
- */
2428
- interface EmbedManyResult<VALUE> {
2429
- /**
2430
- The values that were embedded.
2431
- */
2432
- readonly values: Array<VALUE>;
2433
- /**
2434
- The embeddings. They are in the same order as the values.
2435
- */
2436
- readonly embeddings: Array<Embedding>;
2437
- /**
2438
- The embedding token usage.
2439
- */
2440
- readonly usage: EmbeddingModelUsage;
2439
+ declare function createUIMessageStream<UI_MESSAGE extends UIMessage>({ execute, onError, // mask error messages for safety by default
2440
+ originalMessages, onFinish, }: {
2441
+ execute: (options: {
2442
+ writer: UIMessageStreamWriter<UI_MESSAGE>;
2443
+ }) => Promise<void> | void;
2444
+ onError?: (error: unknown) => string;
2441
2445
  /**
2442
- Optional raw response data.
2443
- */
2444
- readonly responses?: Array<{
2446
+ * The original messages.
2447
+ */
2448
+ originalMessages?: UI_MESSAGE[];
2449
+ onFinish?: (options: {
2445
2450
  /**
2446
- Response headers.
2447
- */
2448
- headers?: Record<string, string>;
2451
+ * The updates list of UI messages.
2452
+ */
2453
+ messages: UI_MESSAGE[];
2449
2454
  /**
2450
- The response body.
2451
- */
2452
- body?: unknown;
2453
- } | undefined>;
2454
- }
2455
+ * Indicates whether the response message is a continuation of the last original message,
2456
+ * or if a new message was created.
2457
+ */
2458
+ isContinuation: boolean;
2459
+ /**
2460
+ * The message that was sent to the client as a response
2461
+ * (including the original message if it was extended).
2462
+ */
2463
+ responseMessage: UI_MESSAGE;
2464
+ }) => void;
2465
+ }): ReadableStream<InferUIMessageStreamPart<UI_MESSAGE>>;
2455
2466
 
2456
- /**
2457
- Embed several values using an embedding model. The type of the value is defined
2458
- by the embedding model.
2467
+ declare function createUIMessageStreamResponse({ status, statusText, headers, stream, }: ResponseInit & {
2468
+ stream: ReadableStream<UIMessageStreamPart>;
2469
+ }): Response;
2459
2470
 
2460
- `embedMany` automatically splits large requests into smaller chunks if the model
2461
- has a limit on how many embeddings can be generated in a single call.
2471
+ declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, }: {
2472
+ response: ServerResponse;
2473
+ stream: ReadableStream<UIMessageStreamPart>;
2474
+ } & ResponseInit): void;
2462
2475
 
2463
- @param model - The embedding model to use.
2464
- @param values - The values that should be embedded.
2476
+ declare class JsonToSseTransformStream extends TransformStream<unknown, string> {
2477
+ constructor();
2478
+ }
2465
2479
 
2466
- @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
2467
- @param abortSignal - An optional abort signal that can be used to cancel the call.
2468
- @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
2480
+ interface ChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> {
2481
+ submitMessages: (options: {
2482
+ chatId: string;
2483
+ messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
2484
+ abortSignal: AbortSignal | undefined;
2485
+ requestType: 'generate' | 'resume';
2486
+ } & ChatRequestOptions) => Promise<ReadableStream<UIMessageStreamPart>>;
2487
+ }
2469
2488
 
2470
- @returns A result object that contains the embeddings, the value, and additional information.
2471
- */
2472
- declare function embedMany<VALUE>({ model, values, maxParallelCalls, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
2489
+ type ChatRequestOptions = {
2473
2490
  /**
2474
- The embedding model to use.
2475
- */
2476
- model: EmbeddingModel<VALUE>;
2491
+ Additional headers that should be to be passed to the API endpoint.
2492
+ */
2493
+ headers?: Record<string, string> | Headers;
2477
2494
  /**
2478
- The values that should be embedded.
2495
+ Additional body JSON properties that should be sent to the API endpoint.
2479
2496
  */
2480
- values: Array<VALUE>;
2497
+ body?: object;
2498
+ metadata?: unknown;
2499
+ };
2500
+ type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
2501
+ interface ChatState<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> {
2502
+ status: ChatStatus;
2503
+ error: Error | undefined;
2504
+ messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
2505
+ pushMessage: (message: UIMessage<MESSAGE_METADATA, DATA_TYPES>) => void;
2506
+ popMessage: () => void;
2507
+ replaceMessage: (index: number, message: UIMessage<MESSAGE_METADATA, DATA_TYPES>) => void;
2508
+ snapshot: <T>(thing: T) => T;
2509
+ }
2510
+ interface ChatInit<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> {
2481
2511
  /**
2482
- Maximum number of retries per embedding model call. Set to 0 to disable retries.
2483
-
2484
- @default 2
2512
+ * A unique identifier for the chat. If not provided, a random one will be
2513
+ * generated.
2485
2514
  */
2486
- maxRetries?: number;
2515
+ id?: string;
2516
+ messageMetadataSchema?: Validator<MESSAGE_METADATA> | StandardSchemaV1<MESSAGE_METADATA>;
2517
+ dataPartSchemas?: UI_DATA_PART_SCHEMAS;
2518
+ messages?: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
2487
2519
  /**
2488
- Abort signal.
2489
- */
2490
- abortSignal?: AbortSignal;
2491
- /**
2492
- Additional headers to include in the request.
2493
- Only applicable for HTTP-based providers.
2494
- */
2495
- headers?: Record<string, string>;
2496
- /**
2497
- * Optional telemetry configuration (experimental).
2498
- */
2499
- experimental_telemetry?: TelemetrySettings;
2500
- /**
2501
- Additional provider-specific options. They are passed through
2502
- to the provider from the AI SDK and enable provider-specific
2503
- functionality that can be fully encapsulated in the provider.
2504
- */
2505
- providerOptions?: ProviderOptions;
2506
- /**
2507
- * Maximum number of concurrent requests.
2508
- *
2509
- * @default Infinity
2510
- */
2511
- maxParallelCalls?: number;
2512
- }): Promise<EmbedManyResult<VALUE>>;
2513
-
2514
- /**
2515
- A message that was generated during the generation process.
2516
- It can be either an assistant message or a tool message.
2517
- */
2518
- type ResponseMessage = AssistantModelMessage | ToolModelMessage;
2519
-
2520
- /**
2521
- * The result of a single step in the generation process.
2522
- */
2523
- type StepResult<TOOLS extends ToolSet> = {
2524
- /**
2525
- The content that was generated in the last step.
2526
- */
2527
- readonly content: Array<ContentPart<TOOLS>>;
2528
- /**
2529
- The generated text.
2530
- */
2531
- readonly text: string;
2532
- /**
2533
- The reasoning that was generated during the generation.
2534
- */
2535
- readonly reasoning: Array<ReasoningPart>;
2536
- /**
2537
- The reasoning text that was generated during the generation.
2538
- */
2539
- readonly reasoningText: string | undefined;
2540
- /**
2541
- The files that were generated during the generation.
2542
- */
2543
- readonly files: Array<GeneratedFile>;
2544
- /**
2545
- The sources that were used to generate the text.
2546
- */
2547
- readonly sources: Array<Source>;
2548
- /**
2549
- The tool calls that were made during the generation.
2550
- */
2551
- readonly toolCalls: ToolCallArray<TOOLS>;
2552
- /**
2553
- The results of the tool calls.
2554
- */
2555
- readonly toolResults: ToolResultArray<TOOLS>;
2556
- /**
2557
- The reason why the generation finished.
2558
- */
2559
- readonly finishReason: FinishReason;
2560
- /**
2561
- The token usage of the generated text.
2562
- */
2563
- readonly usage: LanguageModelUsage;
2564
- /**
2565
- Warnings from the model provider (e.g. unsupported settings).
2566
- */
2567
- readonly warnings: CallWarning[] | undefined;
2568
- /**
2569
- Additional request information.
2570
- */
2571
- readonly request: LanguageModelRequestMetadata;
2572
- /**
2573
- Additional response information.
2574
- */
2575
- readonly response: LanguageModelResponseMetadata & {
2576
- /**
2577
- The response messages that were generated during the call.
2578
- Response messages can be either assistant messages or tool messages.
2579
- They contain a generated id.
2580
- */
2581
- readonly messages: Array<ResponseMessage>;
2582
- /**
2583
- Response body (available only for providers that use HTTP requests).
2584
- */
2585
- body?: unknown;
2586
- };
2587
- /**
2588
- Additional provider-specific metadata. They are passed through
2589
- from the provider to the AI SDK and enable provider-specific
2590
- results that can be fully encapsulated in the provider.
2591
- */
2592
- readonly providerMetadata: ProviderMetadata | undefined;
2593
- };
2594
-
2595
- /**
2596
- The result of a `generateText` call.
2597
- It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
2598
- */
2599
- interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
2600
- /**
2601
- The content that was generated in the last step.
2602
- */
2603
- readonly content: Array<ContentPart<TOOLS>>;
2604
- /**
2605
- The text that was generated in the last step.
2606
- */
2607
- readonly text: string;
2608
- /**
2609
- The full reasoning that the model has generated in the last step.
2520
+ * A way to provide a function that is going to be used for ids for messages and the chat.
2521
+ * If not provided the default AI SDK `generateId` is used.
2610
2522
  */
2611
- readonly reasoning: Array<ReasoningPart>;
2523
+ generateId?: IdGenerator;
2524
+ transport?: ChatTransport<NoInfer<MESSAGE_METADATA>, NoInfer<InferUIDataParts<UI_DATA_PART_SCHEMAS>>>;
2525
+ maxSteps?: number;
2612
2526
  /**
2613
- The reasoning text that the model has generated in the last step. Can be undefined if the model
2614
- has only generated text.
2527
+ * Callback function to be called when an error is encountered.
2615
2528
  */
2616
- readonly reasoningText: string | undefined;
2529
+ onError?: (error: Error) => void;
2617
2530
  /**
2618
- The files that were generated in the last step.
2619
- Empty array if no files were generated.
2531
+ Optional callback function that is invoked when a tool call is received.
2532
+ Intended for automatic client-side tool execution.
2533
+
2534
+ You can optionally return a result for the tool call,
2535
+ either synchronously or asynchronously.
2620
2536
  */
2621
- readonly files: Array<GeneratedFile>;
2622
- /**
2623
- Sources that have been used as references in the last step.
2624
- */
2625
- readonly sources: Array<Source>;
2626
- /**
2627
- The tool calls that were made in the last step.
2628
- */
2629
- readonly toolCalls: ToolCallArray<TOOLS>;
2630
- /**
2631
- The results of the tool calls from the last step.
2632
- */
2633
- readonly toolResults: ToolResultArray<TOOLS>;
2634
- /**
2635
- The reason why the generation finished.
2636
- */
2637
- readonly finishReason: FinishReason;
2537
+ onToolCall?: ({ toolCall, }: {
2538
+ toolCall: ToolCall<string, unknown>;
2539
+ }) => void | Promise<unknown> | unknown;
2638
2540
  /**
2639
- The token usage of the last step.
2541
+ * Optional callback function that is called when the assistant message is finished streaming.
2542
+ *
2543
+ * @param message The message that was streamed.
2640
2544
  */
2641
- readonly usage: LanguageModelUsage;
2545
+ onFinish?: (options: {
2546
+ message: UIMessage<NoInfer<MESSAGE_METADATA>, NoInfer<InferUIDataParts<UI_DATA_PART_SCHEMAS>>>;
2547
+ }) => void;
2548
+ }
2549
+ declare abstract class AbstractChat<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> {
2550
+ readonly id: string;
2551
+ readonly generateId: IdGenerator;
2552
+ protected state: ChatState<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
2553
+ private messageMetadataSchema;
2554
+ private dataPartSchemas;
2555
+ private readonly transport;
2556
+ private maxSteps;
2557
+ private onError?;
2558
+ private onToolCall?;
2559
+ private onFinish?;
2560
+ private activeResponse;
2561
+ private jobExecutor;
2562
+ constructor({ generateId, id, transport, maxSteps, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, }: Omit<ChatInit<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS>, 'messages'> & {
2563
+ state: ChatState<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
2564
+ });
2642
2565
  /**
2643
- The total token usage of all steps.
2644
- When there are multiple steps, the usage is the sum of all step usages.
2566
+ * Hook status:
2567
+ *
2568
+ * - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.
2569
+ * - `streaming`: The response is actively streaming in from the API, receiving chunks of data.
2570
+ * - `ready`: The full response has been received and processed; a new user message can be submitted.
2571
+ * - `error`: An error occurred during the API request, preventing successful completion.
2645
2572
  */
2646
- readonly totalUsage: LanguageModelUsage;
2573
+ get status(): ChatStatus;
2574
+ protected setStatus({ status, error, }: {
2575
+ status: ChatStatus;
2576
+ error?: Error;
2577
+ }): void;
2578
+ get error(): Error | undefined;
2579
+ get messages(): UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
2580
+ get lastMessage(): UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>> | undefined;
2581
+ set messages(messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[]);
2582
+ removeAssistantResponse: () => void;
2647
2583
  /**
2648
- Warnings from the model provider (e.g. unsupported settings)
2584
+ * Append a user message to the chat list. This triggers the API call to fetch
2585
+ * the assistant's response.
2649
2586
  */
2650
- readonly warnings: CallWarning[] | undefined;
2587
+ sendMessage: (message: (CreateUIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>> & {
2588
+ text?: never;
2589
+ files?: never;
2590
+ }) | {
2591
+ text: string;
2592
+ files?: FileList | FileUIPart[];
2593
+ metadata?: MESSAGE_METADATA;
2594
+ parts?: never;
2595
+ } | {
2596
+ files: FileList | FileUIPart[];
2597
+ metadata?: MESSAGE_METADATA;
2598
+ parts?: never;
2599
+ }, options?: ChatRequestOptions) => Promise<void>;
2651
2600
  /**
2652
- Additional request information.
2601
+ * Regenerate the last assistant message.
2653
2602
  */
2654
- readonly request: LanguageModelRequestMetadata;
2603
+ reload: (options?: ChatRequestOptions) => Promise<void>;
2655
2604
  /**
2656
- Additional response information.
2605
+ * Resume an ongoing chat generation stream. This does not resume an aborted generation.
2657
2606
  */
2658
- readonly response: LanguageModelResponseMetadata & {
2659
- /**
2660
- The response messages that were generated during the call. It consists of an assistant message,
2661
- potentially containing tool calls.
2662
-
2663
- When there are tool results, there is an additional tool message with the tool results that are available.
2664
- If there are tools that do not have execute functions, they are not included in the tool results and
2665
- need to be added separately.
2666
- */
2667
- messages: Array<ResponseMessage>;
2668
- /**
2669
- Response body (available only for providers that use HTTP requests).
2670
- */
2671
- body?: unknown;
2672
- };
2607
+ experimental_resume: (options?: ChatRequestOptions) => Promise<void>;
2608
+ addToolResult: ({ toolCallId, result, }: {
2609
+ toolCallId: string;
2610
+ result: unknown;
2611
+ }) => Promise<void>;
2673
2612
  /**
2674
- Additional provider-specific metadata. They are passed through
2675
- from the provider to the AI SDK and enable provider-specific
2676
- results that can be fully encapsulated in the provider.
2613
+ * Abort the current request immediately, keep the generated tokens if any.
2677
2614
  */
2678
- readonly providerMetadata: ProviderMetadata | undefined;
2679
- /**
2680
- Details for all steps.
2681
- You can use this to get information about intermediate steps,
2682
- such as the tool calls or the response headers.
2615
+ stop: () => Promise<void>;
2616
+ private triggerRequest;
2617
+ }
2618
+
2619
+ declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
2620
+
2621
+ /**
2622
+ Converts an array of messages from useChat into an array of CoreMessages that can be used
2623
+ with the AI core functions (e.g. `streamText`).
2624
+ */
2625
+ declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<UIMessage, 'id'>>, options?: {
2626
+ tools?: TOOLS;
2627
+ }): ModelMessage[];
2628
+ /**
2629
+ @deprecated Use `convertToModelMessages` instead.
2630
+ */
2631
+ declare const convertToCoreMessages: typeof convertToModelMessages;
2632
+
2633
+ type PrepareRequest<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> = (options: {
2634
+ id: string;
2635
+ messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
2636
+ requestMetadata: unknown;
2637
+ body: Record<string, any> | undefined;
2638
+ credentials: RequestCredentials | undefined;
2639
+ headers: HeadersInit | undefined;
2640
+ }) => {
2641
+ body: object;
2642
+ headers?: HeadersInit;
2643
+ credentials?: RequestCredentials;
2644
+ };
2645
+
2646
+ declare class DefaultChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> implements ChatTransport<MESSAGE_METADATA, DATA_TYPES> {
2647
+ private api;
2648
+ private credentials?;
2649
+ private headers?;
2650
+ private body?;
2651
+ private fetch?;
2652
+ private prepareRequest?;
2653
+ constructor({ api, credentials, headers, body, fetch, prepareRequest, }?: {
2654
+ api?: string;
2655
+ /**
2656
+ * The credentials mode to be used for the fetch request.
2657
+ * Possible values are: 'omit', 'same-origin', 'include'.
2658
+ * Defaults to 'same-origin'.
2659
+ */
2660
+ credentials?: RequestCredentials;
2661
+ /**
2662
+ * HTTP headers to be sent with the API request.
2663
+ */
2664
+ headers?: Record<string, string> | Headers;
2665
+ /**
2666
+ * Extra body object to be sent with the API request.
2667
+ * @example
2668
+ * Send a `sessionId` to the API along with the messages.
2669
+ * ```js
2670
+ * useChat({
2671
+ * body: {
2672
+ * sessionId: '123',
2673
+ * }
2674
+ * })
2675
+ * ```
2676
+ */
2677
+ body?: object;
2678
+ /**
2679
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
2680
+ or to provide a custom fetch implementation for e.g. testing.
2681
+ */
2682
+ fetch?: FetchFunction;
2683
+ /**
2684
+ * When a function is provided, it will be used
2685
+ * to prepare the request body for the chat API. This can be useful for
2686
+ * customizing the request body based on the messages and data in the chat.
2687
+ *
2688
+ * @param id The id of the chat.
2689
+ * @param messages The current messages in the chat.
2690
+ * @param requestBody The request body object passed in the chat request.
2691
+ */
2692
+ prepareRequest?: PrepareRequest<MESSAGE_METADATA, DATA_TYPES>;
2693
+ });
2694
+ submitMessages({ chatId, messages, abortSignal, metadata, headers, body, requestType, }: Parameters<ChatTransport<MESSAGE_METADATA, DATA_TYPES>['submitMessages']>[0]): Promise<ReadableStream<UIMessageStreamPart>>;
2695
+ }
2696
+
2697
+ declare function getToolInvocations(message: UIMessage): ToolInvocation[];
2698
+
2699
+ declare class TextStreamChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> implements ChatTransport<MESSAGE_METADATA, DATA_TYPES> {
2700
+ private api;
2701
+ private credentials?;
2702
+ private headers?;
2703
+ private body?;
2704
+ private fetch?;
2705
+ private prepareRequest?;
2706
+ constructor({ api, credentials, headers, body, fetch, prepareRequest, }: {
2707
+ api: string;
2708
+ /**
2709
+ * The credentials mode to be used for the fetch request.
2710
+ * Possible values are: 'omit', 'same-origin', 'include'.
2711
+ * Defaults to 'same-origin'.
2712
+ */
2713
+ credentials?: RequestCredentials;
2714
+ /**
2715
+ * HTTP headers to be sent with the API request.
2716
+ */
2717
+ headers?: Record<string, string> | Headers;
2718
+ /**
2719
+ * Extra body object to be sent with the API request.
2720
+ * @example
2721
+ * Send a `sessionId` to the API along with the messages.
2722
+ * ```js
2723
+ * useChat({
2724
+ * body: {
2725
+ * sessionId: '123',
2726
+ * }
2727
+ * })
2728
+ * ```
2729
+ */
2730
+ body?: object;
2731
+ /**
2732
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
2733
+ or to provide a custom fetch implementation for e.g. testing.
2734
+ */
2735
+ fetch?: FetchFunction;
2736
+ /**
2737
+ * When a function is provided, it will be used
2738
+ * to prepare the request body for the chat API. This can be useful for
2739
+ * customizing the request body based on the messages and data in the chat.
2740
+ *
2741
+ * @param id The id of the chat.
2742
+ * @param messages The current messages in the chat.
2743
+ * @param requestBody The request body object passed in the chat request.
2744
+ */
2745
+ prepareRequest?: NoInfer<PrepareRequest<MESSAGE_METADATA, DATA_TYPES>>;
2746
+ });
2747
+ submitMessages({ chatId, messages, abortSignal, metadata, headers, body, requestType, }: Parameters<ChatTransport<MESSAGE_METADATA, DATA_TYPES>['submitMessages']>[0]): Promise<ReadableStream<UIMessageStreamPart<never, never>>>;
2748
+ }
2749
+
2750
+ type CompletionRequestOptions = {
2751
+ /**
2752
+ An optional object of headers to be passed to the API endpoint.
2683
2753
  */
2684
- readonly steps: Array<StepResult<TOOLS>>;
2754
+ headers?: Record<string, string> | Headers;
2685
2755
  /**
2686
- The generated structured output. It uses the `experimental_output` specification.
2756
+ An optional object to be passed to the API endpoint.
2757
+ */
2758
+ body?: object;
2759
+ };
2760
+ type UseCompletionOptions = {
2761
+ /**
2762
+ * The API endpoint that accepts a `{ prompt: string }` object and returns
2763
+ * a stream of tokens of the AI completion response. Defaults to `/api/completion`.
2687
2764
  */
2688
- readonly experimental_output: OUTPUT;
2689
- }
2765
+ api?: string;
2766
+ /**
2767
+ * An unique identifier for the chat. If not provided, a random one will be
2768
+ * generated. When provided, the `useChat` hook with the same `id` will
2769
+ * have shared states across components.
2770
+ */
2771
+ id?: string;
2772
+ /**
2773
+ * Initial prompt input of the completion.
2774
+ */
2775
+ initialInput?: string;
2776
+ /**
2777
+ * Initial completion result. Useful to load an existing history.
2778
+ */
2779
+ initialCompletion?: string;
2780
+ /**
2781
+ * Callback function to be called when the completion is finished streaming.
2782
+ */
2783
+ onFinish?: (prompt: string, completion: string) => void;
2784
+ /**
2785
+ * Callback function to be called when an error is encountered.
2786
+ */
2787
+ onError?: (error: Error) => void;
2788
+ /**
2789
+ * The credentials mode to be used for the fetch request.
2790
+ * Possible values are: 'omit', 'same-origin', 'include'.
2791
+ * Defaults to 'same-origin'.
2792
+ */
2793
+ credentials?: RequestCredentials;
2794
+ /**
2795
+ * HTTP headers to be sent with the API request.
2796
+ */
2797
+ headers?: Record<string, string> | Headers;
2798
+ /**
2799
+ * Extra body object to be sent with the API request.
2800
+ * @example
2801
+ * Send a `sessionId` to the API along with the prompt.
2802
+ * ```js
2803
+ * useChat({
2804
+ * body: {
2805
+ * sessionId: '123',
2806
+ * }
2807
+ * })
2808
+ * ```
2809
+ */
2810
+ body?: object;
2811
+ /**
2812
+ Streaming protocol that is used. Defaults to `data`.
2813
+ */
2814
+ streamProtocol?: 'data' | 'text';
2815
+ /**
2816
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
2817
+ or to provide a custom fetch implementation for e.g. testing.
2818
+ */
2819
+ fetch?: FetchFunction;
2820
+ };
2821
+
2822
+ /**
2823
+ * Calculates the cosine similarity between two vectors. This is a useful metric for
2824
+ * comparing the similarity of two vectors such as embeddings.
2825
+ *
2826
+ * @param vector1 - The first vector.
2827
+ * @param vector2 - The second vector.
2828
+ *
2829
+ * @returns The cosine similarity between vector1 and vector2.
2830
+ * @returns 0 if either vector is the zero vector.
2831
+ *
2832
+ * @throws {InvalidArgumentError} If the vectors do not have the same length.
2833
+ */
2834
+ declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
2835
+
2836
+ /**
2837
+ * Converts a data URL of type text/* to a text string.
2838
+ */
2839
+ declare function getTextFromDataUrl(dataUrl: string): string;
2690
2840
 
2691
2841
  /**
2692
2842
  Create a type from an object with all keys and nested keys set to optional.
@@ -2705,566 +2855,470 @@ type PartialObject<ObjectType extends object> = {
2705
2855
  [KeyType in keyof ObjectType]?: DeepPartialInternal<ObjectType[KeyType]>;
2706
2856
  };
2707
2857
 
2708
- interface Output<OUTPUT, PARTIAL> {
2709
- readonly type: 'object' | 'text';
2710
- responseFormat: LanguageModelV2CallOptions['responseFormat'];
2711
- parsePartial(options: {
2712
- text: string;
2713
- }): Promise<{
2714
- partial: PARTIAL;
2715
- } | undefined>;
2716
- parseOutput(options: {
2717
- text: string;
2718
- }, context: {
2719
- response: LanguageModelResponseMetadata;
2720
- usage: LanguageModelUsage;
2721
- finishReason: FinishReason;
2722
- }): Promise<OUTPUT>;
2723
- }
2724
- declare const text: () => Output<string, string>;
2725
- declare const object: <OUTPUT>({ schema: inputSchema, }: {
2726
- schema: z4.$ZodType<OUTPUT, any> | z3.Schema<OUTPUT, z3.ZodTypeDef, any> | Schema<OUTPUT>;
2727
- }) => Output<OUTPUT, DeepPartial<OUTPUT>>;
2858
+ /**
2859
+ * Performs a deep-equal comparison of two parsed JSON objects.
2860
+ *
2861
+ * @param {any} obj1 - The first object to compare.
2862
+ * @param {any} obj2 - The second object to compare.
2863
+ * @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
2864
+ */
2865
+ declare function isDeepEqualData(obj1: any, obj2: any): boolean;
2728
2866
 
2729
- type output_Output<OUTPUT, PARTIAL> = Output<OUTPUT, PARTIAL>;
2730
- declare const output_object: typeof object;
2731
- declare const output_text: typeof text;
2732
- declare namespace output {
2733
- export {
2734
- output_Output as Output,
2735
- output_object as object,
2736
- output_text as text,
2737
- };
2738
- }
2739
-
2740
- /**
2741
- Function that you can use to provide different settings for a step.
2742
-
2743
- @param options - The options for the step.
2744
- @param options.steps - The steps that have been executed so far.
2745
- @param options.stepNumber - The number of the step that is being executed.
2746
- @param options.model - The model that is being used.
2867
+ declare function parsePartialJson(jsonText: string | undefined): Promise<{
2868
+ value: JSONValue$1 | undefined;
2869
+ state: 'undefined-input' | 'successful-parse' | 'repaired-parse' | 'failed-parse';
2870
+ }>;
2747
2871
 
2748
- @returns An object that contains the settings for the step.
2749
- If you return undefined (or for undefined settings), the settings from the outer level will be used.
2750
- */
2751
- type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Tool>> = (options: {
2752
- steps: Array<StepResult<NoInfer<TOOLS>>>;
2753
- stepNumber: number;
2754
- model: LanguageModel;
2755
- }) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
2756
- type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
2757
- model?: LanguageModel;
2758
- toolChoice?: ToolChoice<NoInfer<TOOLS>>;
2759
- activeTools?: Array<keyof NoInfer<TOOLS>>;
2760
- system?: string;
2761
- } | undefined;
2872
+ type Job = () => Promise<void>;
2762
2873
 
2763
- type StopCondition<TOOLS extends ToolSet> = (options: {
2764
- steps: Array<StepResult<TOOLS>>;
2765
- }) => PromiseLike<boolean> | boolean;
2766
- declare function stepCountIs(stepCount: number): StopCondition<any>;
2767
- declare function hasToolCall(toolName: string): StopCondition<any>;
2874
+ declare class SerialJobExecutor {
2875
+ private queue;
2876
+ private isProcessing;
2877
+ private processQueue;
2878
+ run(job: Job): Promise<void>;
2879
+ }
2768
2880
 
2769
2881
  /**
2770
- Callback that is set using the `onStepFinish` option.
2771
-
2772
- @param stepResult - The result of the step.
2882
+ * Creates a ReadableStream that emits the provided values with an optional delay between each value.
2883
+ *
2884
+ * @param options - The configuration options
2885
+ * @param options.chunks - Array of values to be emitted by the stream
2886
+ * @param options.initialDelayInMs - Optional initial delay in milliseconds before emitting the first value (default: 0). Can be set to `null` to skip the initial delay. The difference between `initialDelayInMs: null` and `initialDelayInMs: 0` is that `initialDelayInMs: null` will emit the values without any delay, while `initialDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
2887
+ * @param options.chunkDelayInMs - Optional delay in milliseconds between emitting each value (default: 0). Can be set to `null` to skip the delay. The difference between `chunkDelayInMs: null` and `chunkDelayInMs: 0` is that `chunkDelayInMs: null` will emit the values without any delay, while `chunkDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
2888
+ * @returns A ReadableStream that emits the provided values
2773
2889
  */
2774
- type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
2775
- /**
2776
- Generate a text and call tools for a given prompt using a language model.
2777
-
2778
- This function does not stream the output. If you want to stream the output, use `streamText` instead.
2779
-
2780
- @param model - The language model to use.
2890
+ declare function simulateReadableStream<T>({ chunks, initialDelayInMs, chunkDelayInMs, _internal, }: {
2891
+ chunks: T[];
2892
+ initialDelayInMs?: number | null;
2893
+ chunkDelayInMs?: number | null;
2894
+ _internal?: {
2895
+ delay?: (ms: number | null) => Promise<void>;
2896
+ };
2897
+ }): ReadableStream<T>;
2781
2898
 
2782
- @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
2783
- @param toolChoice - The tool choice strategy. Default: 'auto'.
2899
+ /**
2900
+ The result of an `embed` call.
2901
+ It contains the embedding, the value, and additional information.
2902
+ */
2903
+ interface EmbedResult<VALUE> {
2904
+ /**
2905
+ The value that was embedded.
2906
+ */
2907
+ readonly value: VALUE;
2908
+ /**
2909
+ The embedding of the value.
2910
+ */
2911
+ readonly embedding: Embedding;
2912
+ /**
2913
+ The embedding token usage.
2914
+ */
2915
+ readonly usage: EmbeddingModelUsage;
2916
+ /**
2917
+ Optional response data.
2918
+ */
2919
+ readonly response?: {
2920
+ /**
2921
+ Response headers.
2922
+ */
2923
+ headers?: Record<string, string>;
2924
+ /**
2925
+ The response body.
2926
+ */
2927
+ body?: unknown;
2928
+ };
2929
+ }
2784
2930
 
2785
- @param system - A system message that will be part of the prompt.
2786
- @param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
2787
- @param messages - A list of messages. You can either use `prompt` or `messages` but not both.
2931
+ /**
2932
+ Embed a value using an embedding model. The type of the value is defined by the embedding model.
2788
2933
 
2789
- @param maxOutputTokens - Maximum number of tokens to generate.
2790
- @param temperature - Temperature setting.
2791
- The value is passed through to the provider. The range depends on the provider and model.
2792
- It is recommended to set either `temperature` or `topP`, but not both.
2793
- @param topP - Nucleus sampling.
2794
- The value is passed through to the provider. The range depends on the provider and model.
2795
- It is recommended to set either `temperature` or `topP`, but not both.
2796
- @param topK - Only sample from the top K options for each subsequent token.
2797
- Used to remove "long tail" low probability responses.
2798
- Recommended for advanced use cases only. You usually only need to use temperature.
2799
- @param presencePenalty - Presence penalty setting.
2800
- It affects the likelihood of the model to repeat information that is already in the prompt.
2801
- The value is passed through to the provider. The range depends on the provider and model.
2802
- @param frequencyPenalty - Frequency penalty setting.
2803
- It affects the likelihood of the model to repeatedly use the same words or phrases.
2804
- The value is passed through to the provider. The range depends on the provider and model.
2805
- @param stopSequences - Stop sequences.
2806
- If set, the model will stop generating text when one of the stop sequences is generated.
2807
- @param seed - The seed (integer) to use for random sampling.
2808
- If set and supported by the model, calls will generate deterministic results.
2934
+ @param model - The embedding model to use.
2935
+ @param value - The value that should be embedded.
2809
2936
 
2810
2937
  @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
2811
2938
  @param abortSignal - An optional abort signal that can be used to cancel the call.
2812
2939
  @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
2813
2940
 
2814
- @param experimental_generateMessageId - Generate a unique ID for each message.
2815
-
2816
- @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
2817
-
2818
- @returns
2819
- A result object that contains the generated text, the results of the tool calls, and additional information.
2941
+ @returns A result object that contains the embedding, the value, and additional information.
2820
2942
  */
2821
- declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model: modelArg, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools, activeTools, experimental_prepareStep, prepareStep, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
2822
- /**
2823
- The language model to use.
2824
- */
2825
- model: LanguageModel;
2943
+ declare function embed<VALUE>({ model, value, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, experimental_telemetry: telemetry, }: {
2826
2944
  /**
2827
- The tools that the model can call. The model needs to support calling tools.
2828
- */
2829
- tools?: TOOLS;
2945
+ The embedding model to use.
2946
+ */
2947
+ model: EmbeddingModel<VALUE>;
2830
2948
  /**
2831
- The tool choice strategy. Default: 'auto'.
2949
+ The value that should be embedded.
2832
2950
  */
2833
- toolChoice?: ToolChoice<NoInfer<TOOLS>>;
2951
+ value: VALUE;
2834
2952
  /**
2835
- Condition for stopping the generation when there are tool results in the last step.
2836
- When the condition is an array, any of the conditions can be met to stop the generation.
2837
-
2838
- @default stepCountIs(1)
2953
+ Maximum number of retries per embedding model call. Set to 0 to disable retries.
2954
+
2955
+ @default 2
2839
2956
  */
2840
- stopWhen?: StopCondition<NoInfer<TOOLS>> | Array<StopCondition<NoInfer<TOOLS>>>;
2957
+ maxRetries?: number;
2841
2958
  /**
2842
- Optional telemetry configuration (experimental).
2843
- */
2844
- experimental_telemetry?: TelemetrySettings;
2959
+ Abort signal.
2960
+ */
2961
+ abortSignal?: AbortSignal;
2845
2962
  /**
2846
- Additional provider-specific options. They are passed through
2847
- to the provider from the AI SDK and enable provider-specific
2848
- functionality that can be fully encapsulated in the provider.
2849
- */
2963
+ Additional headers to include in the request.
2964
+ Only applicable for HTTP-based providers.
2965
+ */
2966
+ headers?: Record<string, string>;
2967
+ /**
2968
+ Additional provider-specific options. They are passed through
2969
+ to the provider from the AI SDK and enable provider-specific
2970
+ functionality that can be fully encapsulated in the provider.
2971
+ */
2850
2972
  providerOptions?: ProviderOptions;
2851
2973
  /**
2852
- * @deprecated Use `activeTools` instead.
2974
+ * Optional telemetry configuration (experimental).
2853
2975
  */
2854
- experimental_activeTools?: Array<keyof NoInfer<TOOLS>>;
2976
+ experimental_telemetry?: TelemetrySettings;
2977
+ }): Promise<EmbedResult<VALUE>>;
2978
+
2979
+ /**
2980
+ The result of a `embedMany` call.
2981
+ It contains the embeddings, the values, and additional information.
2982
+ */
2983
+ interface EmbedManyResult<VALUE> {
2855
2984
  /**
2856
- Limits the tools that are available for the model to call without
2857
- changing the tool call and result types in the result.
2858
- */
2859
- activeTools?: Array<keyof NoInfer<TOOLS>>;
2985
+ The values that were embedded.
2986
+ */
2987
+ readonly values: Array<VALUE>;
2860
2988
  /**
2861
- Optional specification for parsing structured outputs from the LLM response.
2862
- */
2863
- experimental_output?: Output<OUTPUT, OUTPUT_PARTIAL>;
2989
+ The embeddings. They are in the same order as the values.
2990
+ */
2991
+ readonly embeddings: Array<Embedding>;
2864
2992
  /**
2865
- * @deprecated Use `prepareStep` instead.
2866
- */
2867
- experimental_prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
2993
+ The embedding token usage.
2994
+ */
2995
+ readonly usage: EmbeddingModelUsage;
2868
2996
  /**
2869
- Optional function that you can use to provide different settings for a step.
2997
+ Optional raw response data.
2998
+ */
2999
+ readonly responses?: Array<{
3000
+ /**
3001
+ Response headers.
3002
+ */
3003
+ headers?: Record<string, string>;
3004
+ /**
3005
+ The response body.
2870
3006
  */
2871
- prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
2872
- /**
2873
- A function that attempts to repair a tool call that failed to parse.
2874
- */
2875
- experimental_repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>;
3007
+ body?: unknown;
3008
+ } | undefined>;
3009
+ }
3010
+
3011
+ /**
3012
+ Embed several values using an embedding model. The type of the value is defined
3013
+ by the embedding model.
3014
+
3015
+ `embedMany` automatically splits large requests into smaller chunks if the model
3016
+ has a limit on how many embeddings can be generated in a single call.
3017
+
3018
+ @param model - The embedding model to use.
3019
+ @param values - The values that should be embedded.
3020
+
3021
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
3022
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
3023
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
3024
+
3025
+ @returns A result object that contains the embeddings, the value, and additional information.
3026
+ */
3027
+ declare function embedMany<VALUE>({ model, values, maxParallelCalls, maxRetries: maxRetriesArg, abortSignal, headers, providerOptions, experimental_telemetry: telemetry, }: {
2876
3028
  /**
2877
- Callback that is called when each step (LLM call) is finished, including intermediate steps.
2878
- */
2879
- onStepFinish?: GenerateTextOnStepFinishCallback<NoInfer<TOOLS>>;
3029
+ The embedding model to use.
3030
+ */
3031
+ model: EmbeddingModel<VALUE>;
2880
3032
  /**
2881
- * Internal. For test use only. May change without notice.
3033
+ The values that should be embedded.
2882
3034
  */
2883
- _internal?: {
2884
- generateId?: IdGenerator;
2885
- currentDate?: () => Date;
2886
- };
2887
- }): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
2888
-
2889
- type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
2890
-
2891
- type UIMessageStreamOptions = {
3035
+ values: Array<VALUE>;
2892
3036
  /**
2893
- * Message ID that is sent to the client if a new message is created.
2894
- * This is intended to be used for the UI message,
2895
- * if the last original message is not an assistant message
2896
- * (in which case that message ID is used).
3037
+ Maximum number of retries per embedding model call. Set to 0 to disable retries.
3038
+
3039
+ @default 2
2897
3040
  */
2898
- newMessageId?: string;
3041
+ maxRetries?: number;
2899
3042
  /**
2900
- * The original messages.
3043
+ Abort signal.
3044
+ */
3045
+ abortSignal?: AbortSignal;
3046
+ /**
3047
+ Additional headers to include in the request.
3048
+ Only applicable for HTTP-based providers.
3049
+ */
3050
+ headers?: Record<string, string>;
3051
+ /**
3052
+ * Optional telemetry configuration (experimental).
2901
3053
  */
2902
- originalMessages?: UIMessage[];
2903
- onFinish?: (options: {
2904
- /**
2905
- * The updates list of UI messages.
2906
- */
2907
- messages: UIMessage[];
2908
- /**
2909
- * Indicates whether the response message is a continuation of the last original message,
2910
- * or if a new message was created.
2911
- */
2912
- isContinuation: boolean;
2913
- /**
2914
- * The message that was sent to the client as a response
2915
- * (including the original message if it was extended).
2916
- */
2917
- responseMessage: UIMessage;
2918
- }) => void;
3054
+ experimental_telemetry?: TelemetrySettings;
2919
3055
  /**
2920
- * Extracts message metadata that will be send to the client.
3056
+ Additional provider-specific options. They are passed through
3057
+ to the provider from the AI SDK and enable provider-specific
3058
+ functionality that can be fully encapsulated in the provider.
3059
+ */
3060
+ providerOptions?: ProviderOptions;
3061
+ /**
3062
+ * Maximum number of concurrent requests.
2921
3063
  *
2922
- * Called on `start` and `finish` events.
3064
+ * @default Infinity
2923
3065
  */
2924
- messageMetadata?: (options: {
2925
- part: TextStreamPart<ToolSet> & {
2926
- type: 'start' | 'finish' | 'start-step' | 'finish-step';
2927
- };
2928
- }) => unknown;
3066
+ maxParallelCalls?: number;
3067
+ }): Promise<EmbedManyResult<VALUE>>;
3068
+
3069
+ /**
3070
+ A message that was generated during the generation process.
3071
+ It can be either an assistant message or a tool message.
3072
+ */
3073
+ type ResponseMessage = AssistantModelMessage | ToolModelMessage;
3074
+
3075
+ /**
3076
+ * The result of a single step in the generation process.
3077
+ */
3078
+ type StepResult<TOOLS extends ToolSet> = {
2929
3079
  /**
2930
- * Send reasoning parts to the client.
2931
- * Default to false.
3080
+ The content that was generated in the last step.
2932
3081
  */
2933
- sendReasoning?: boolean;
3082
+ readonly content: Array<ContentPart<TOOLS>>;
2934
3083
  /**
2935
- * Send source parts to the client.
2936
- * Default to false.
2937
- */
2938
- sendSources?: boolean;
3084
+ The generated text.
3085
+ */
3086
+ readonly text: string;
2939
3087
  /**
2940
- * Send the finish event to the client.
2941
- * Set to false if you are using additional streamText calls
2942
- * that send additional data.
2943
- * Default to true.
2944
- */
2945
- sendFinish?: boolean;
3088
+ The reasoning that was generated during the generation.
3089
+ */
3090
+ readonly reasoning: Array<ReasoningPart>;
2946
3091
  /**
2947
- * Send the message start event to the client.
2948
- * Set to false if you are using additional streamText calls
2949
- * and the message start event has already been sent.
2950
- * Default to true.
2951
- *
2952
- * Note: this setting is currently not used, but you should
2953
- * already set it to false if you are using additional
2954
- * streamText calls that send additional data to prevent
2955
- * the message start event from being sent multiple times.
3092
+ The reasoning text that was generated during the generation.
3093
+ */
3094
+ readonly reasoningText: string | undefined;
3095
+ /**
3096
+ The files that were generated during the generation.
3097
+ */
3098
+ readonly files: Array<GeneratedFile>;
3099
+ /**
3100
+ The sources that were used to generate the text.
3101
+ */
3102
+ readonly sources: Array<Source>;
3103
+ /**
3104
+ The tool calls that were made during the generation.
3105
+ */
3106
+ readonly toolCalls: ToolCallArray<TOOLS>;
3107
+ /**
3108
+ The results of the tool calls.
3109
+ */
3110
+ readonly toolResults: ToolResultArray<TOOLS>;
3111
+ /**
3112
+ The reason why the generation finished.
3113
+ */
3114
+ readonly finishReason: FinishReason;
3115
+ /**
3116
+ The token usage of the generated text.
3117
+ */
3118
+ readonly usage: LanguageModelUsage;
3119
+ /**
3120
+ Warnings from the model provider (e.g. unsupported settings).
3121
+ */
3122
+ readonly warnings: CallWarning[] | undefined;
3123
+ /**
3124
+ Additional request information.
2956
3125
  */
2957
- sendStart?: boolean;
3126
+ readonly request: LanguageModelRequestMetadata;
2958
3127
  /**
2959
- * Process an error, e.g. to log it. Default to `() => 'An error occurred.'`.
2960
- *
2961
- * @return error message to include in the data stream.
3128
+ Additional response information.
3129
+ */
3130
+ readonly response: LanguageModelResponseMetadata & {
3131
+ /**
3132
+ The response messages that were generated during the call.
3133
+ Response messages can be either assistant messages or tool messages.
3134
+ They contain a generated id.
3135
+ */
3136
+ readonly messages: Array<ResponseMessage>;
3137
+ /**
3138
+ Response body (available only for providers that use HTTP requests).
3139
+ */
3140
+ body?: unknown;
3141
+ };
3142
+ /**
3143
+ Additional provider-specific metadata. They are passed through
3144
+ from the provider to the AI SDK and enable provider-specific
3145
+ results that can be fully encapsulated in the provider.
2962
3146
  */
2963
- onError?: (error: unknown) => string;
2964
- };
2965
- type ConsumeStreamOptions = {
2966
- onError?: (error: unknown) => void;
3147
+ readonly providerMetadata: ProviderMetadata | undefined;
2967
3148
  };
3149
+
2968
3150
  /**
2969
- A result object for accessing different stream types and additional information.
3151
+ The result of a `generateText` call.
3152
+ It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
2970
3153
  */
2971
- interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
3154
+ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
2972
3155
  /**
2973
3156
  The content that was generated in the last step.
2974
-
2975
- Resolved when the response is finished.
2976
3157
  */
2977
- readonly content: Promise<Array<ContentPart<TOOLS>>>;
3158
+ readonly content: Array<ContentPart<TOOLS>>;
2978
3159
  /**
2979
- The full text that has been generated by the last step.
2980
-
2981
- Resolved when the response is finished.
3160
+ The text that was generated in the last step.
2982
3161
  */
2983
- readonly text: Promise<string>;
3162
+ readonly text: string;
2984
3163
  /**
2985
- The full reasoning that the model has generated.
2986
-
2987
- Resolved when the response is finished.
3164
+ The full reasoning that the model has generated in the last step.
2988
3165
  */
2989
- readonly reasoning: Promise<Array<ReasoningPart>>;
2990
- /**
2991
- The reasoning that has been generated by the last step.
2992
-
2993
- Resolved when the response is finished.
2994
- */
2995
- readonly reasoningText: Promise<string | undefined>;
3166
+ readonly reasoning: Array<ReasoningPart>;
2996
3167
  /**
2997
- Files that have been generated by the model in the last step.
2998
-
2999
- Resolved when the response is finished.
3168
+ The reasoning text that the model has generated in the last step. Can be undefined if the model
3169
+ has only generated text.
3000
3170
  */
3001
- readonly files: Promise<GeneratedFile[]>;
3171
+ readonly reasoningText: string | undefined;
3172
+ /**
3173
+ The files that were generated in the last step.
3174
+ Empty array if no files were generated.
3175
+ */
3176
+ readonly files: Array<GeneratedFile>;
3002
3177
  /**
3003
3178
  Sources that have been used as references in the last step.
3004
-
3005
- Resolved when the response is finished.
3006
3179
  */
3007
- readonly sources: Promise<Source[]>;
3180
+ readonly sources: Array<Source>;
3008
3181
  /**
3009
- The tool calls that have been executed in the last step.
3010
-
3011
- Resolved when the response is finished.
3012
- */
3013
- readonly toolCalls: Promise<ToolCallUnion<TOOLS>[]>;
3182
+ The tool calls that were made in the last step.
3183
+ */
3184
+ readonly toolCalls: ToolCallArray<TOOLS>;
3014
3185
  /**
3015
- The tool results that have been generated in the last step.
3016
-
3017
- Resolved when the all tool executions are finished.
3186
+ The results of the tool calls from the last step.
3018
3187
  */
3019
- readonly toolResults: Promise<ToolResultUnion<TOOLS>[]>;
3188
+ readonly toolResults: ToolResultArray<TOOLS>;
3020
3189
  /**
3021
- The reason why the generation finished. Taken from the last step.
3022
-
3023
- Resolved when the response is finished.
3024
- */
3025
- readonly finishReason: Promise<FinishReason>;
3190
+ The reason why the generation finished.
3191
+ */
3192
+ readonly finishReason: FinishReason;
3026
3193
  /**
3027
3194
  The token usage of the last step.
3028
-
3029
- Resolved when the response is finished.
3030
3195
  */
3031
- readonly usage: Promise<LanguageModelUsage>;
3196
+ readonly usage: LanguageModelUsage;
3032
3197
  /**
3033
- The total token usage of the generated response.
3198
+ The total token usage of all steps.
3034
3199
  When there are multiple steps, the usage is the sum of all step usages.
3035
-
3036
- Resolved when the response is finished.
3037
- */
3038
- readonly totalUsage: Promise<LanguageModelUsage>;
3039
- /**
3040
- Warnings from the model provider (e.g. unsupported settings) for the first step.
3041
- */
3042
- readonly warnings: Promise<CallWarning[] | undefined>;
3200
+ */
3201
+ readonly totalUsage: LanguageModelUsage;
3043
3202
  /**
3044
- Details for all steps.
3045
- You can use this to get information about intermediate steps,
3046
- such as the tool calls or the response headers.
3203
+ Warnings from the model provider (e.g. unsupported settings)
3047
3204
  */
3048
- readonly steps: Promise<Array<StepResult<TOOLS>>>;
3205
+ readonly warnings: CallWarning[] | undefined;
3049
3206
  /**
3050
- Additional request information from the last step.
3051
- */
3052
- readonly request: Promise<LanguageModelRequestMetadata>;
3207
+ Additional request information.
3208
+ */
3209
+ readonly request: LanguageModelRequestMetadata;
3053
3210
  /**
3054
- Additional response information from the last step.
3055
- */
3056
- readonly response: Promise<LanguageModelResponseMetadata & {
3211
+ Additional response information.
3212
+ */
3213
+ readonly response: LanguageModelResponseMetadata & {
3057
3214
  /**
3058
- The response messages that were generated during the call. It consists of an assistant message,
3059
- potentially containing tool calls.
3060
-
3061
- When there are tool results, there is an additional tool message with the tool results that are available.
3062
- If there are tools that do not have execute functions, they are not included in the tool results and
3063
- need to be added separately.
3064
- */
3215
+ The response messages that were generated during the call. It consists of an assistant message,
3216
+ potentially containing tool calls.
3217
+
3218
+ When there are tool results, there is an additional tool message with the tool results that are available.
3219
+ If there are tools that do not have execute functions, they are not included in the tool results and
3220
+ need to be added separately.
3221
+ */
3065
3222
  messages: Array<ResponseMessage>;
3066
- }>;
3223
+ /**
3224
+ Response body (available only for providers that use HTTP requests).
3225
+ */
3226
+ body?: unknown;
3227
+ };
3067
3228
  /**
3068
- Additional provider-specific metadata from the last step.
3069
- Metadata is passed through from the provider to the AI SDK and
3070
- enables provider-specific results that can be fully encapsulated in the provider.
3229
+ Additional provider-specific metadata. They are passed through
3230
+ from the provider to the AI SDK and enable provider-specific
3231
+ results that can be fully encapsulated in the provider.
3071
3232
  */
3072
- readonly providerMetadata: Promise<ProviderMetadata | undefined>;
3073
- /**
3074
- A text stream that returns only the generated text deltas. You can use it
3075
- as either an AsyncIterable or a ReadableStream. When an error occurs, the
3076
- stream will throw the error.
3077
- */
3078
- readonly textStream: AsyncIterableStream<string>;
3079
- /**
3080
- A stream with all events, including text deltas, tool calls, tool results, and
3081
- errors.
3082
- You can use it as either an AsyncIterable or a ReadableStream.
3083
- Only errors that stop the stream, such as network errors, are thrown.
3084
- */
3085
- readonly fullStream: AsyncIterableStream<TextStreamPart<TOOLS>>;
3233
+ readonly providerMetadata: ProviderMetadata | undefined;
3086
3234
  /**
3087
- A stream of partial outputs. It uses the `experimental_output` specification.
3235
+ Details for all steps.
3236
+ You can use this to get information about intermediate steps,
3237
+ such as the tool calls or the response headers.
3088
3238
  */
3089
- readonly experimental_partialOutputStream: AsyncIterableStream<PARTIAL_OUTPUT>;
3090
- /**
3091
- Consumes the stream without processing the parts.
3092
- This is useful to force the stream to finish.
3093
- It effectively removes the backpressure and allows the stream to finish,
3094
- triggering the `onFinish` callback and the promise resolution.
3095
-
3096
- If an error occurs, it is passed to the optional `onError` callback.
3097
- */
3098
- consumeStream(options?: ConsumeStreamOptions): Promise<void>;
3099
- /**
3100
- Converts the result to a UI message stream.
3101
-
3102
- @param options.getErrorMessage an optional function that converts an error to an error message.
3103
- @param options.sendUsage whether to send the usage information to the client. Defaults to true.
3104
- @param options.sendReasoning whether to send the reasoning information to the client. Defaults to false.
3105
- @param options.sendSources whether to send the sources information to the client. Defaults to false.
3106
- @param options.experimental_sendFinish whether to send the finish information to the client. Defaults to true.
3107
- @param options.experimental_sendStart whether to send the start information to the client. Defaults to true.
3108
-
3109
- @return A UI message stream.
3110
- */
3111
- toUIMessageStream(options?: UIMessageStreamOptions): ReadableStream<UIMessageStreamPart>;
3112
- /**
3113
- Writes UI message stream output to a Node.js response-like object.
3114
- @param response A Node.js response-like object (ServerResponse).
3115
- @param options.status The status code.
3116
- @param options.statusText The status text.
3117
- @param options.headers The headers.
3118
- @param options.getErrorMessage An optional function that converts an error to an error message.
3119
- @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
3120
- @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
3121
- */
3122
- pipeUIMessageStreamToResponse(response: ServerResponse, options?: ResponseInit & UIMessageStreamOptions): void;
3123
- /**
3124
- Writes text delta output to a Node.js response-like object.
3125
- It sets a `Content-Type` header to `text/plain; charset=utf-8` and
3126
- writes each text delta as a separate chunk.
3127
- @param response A Node.js response-like object (ServerResponse).
3128
- @param init Optional headers, status code, and status text.
3129
- */
3130
- pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void;
3131
- /**
3132
- Converts the result to a streamed response object with a stream data part stream.
3133
-
3134
- @param options.status The status code.
3135
- @param options.statusText The status text.
3136
- @param options.headers The headers.
3137
- @param options.getErrorMessage An optional function that converts an error to an error message.
3138
- @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
3139
- @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
3140
- @return A response object.
3141
- */
3142
- toUIMessageStreamResponse(options?: ResponseInit & UIMessageStreamOptions): Response;
3239
+ readonly steps: Array<StepResult<TOOLS>>;
3143
3240
  /**
3144
- Creates a simple text stream response.
3145
- Each text delta is encoded as UTF-8 and sent as a separate chunk.
3146
- Non-text-delta events are ignored.
3147
- @param init Optional headers, status code, and status text.
3148
- */
3149
- toTextStreamResponse(init?: ResponseInit): Response;
3241
+ The generated structured output. It uses the `experimental_output` specification.
3242
+ */
3243
+ readonly experimental_output: OUTPUT;
3150
3244
  }
3151
- type TextStreamPart<TOOLS extends ToolSet> = ContentPart<TOOLS> | {
3152
- type: 'reasoning-part-finish';
3153
- } | {
3154
- type: 'tool-call-streaming-start';
3155
- toolCallId: string;
3156
- toolName: string;
3157
- } | {
3158
- type: 'tool-call-delta';
3159
- toolCallId: string;
3160
- toolName: string;
3161
- argsTextDelta: string;
3162
- } | {
3163
- type: 'start-step';
3164
- request: LanguageModelRequestMetadata;
3165
- warnings: CallWarning[];
3166
- } | {
3167
- type: 'finish-step';
3168
- response: LanguageModelResponseMetadata;
3169
- usage: LanguageModelUsage;
3170
- finishReason: FinishReason;
3171
- providerMetadata: ProviderMetadata | undefined;
3172
- } | {
3173
- type: 'start';
3174
- } | {
3175
- type: 'finish';
3176
- finishReason: FinishReason;
3177
- totalUsage: LanguageModelUsage;
3178
- } | {
3179
- type: 'error';
3180
- error: unknown;
3181
- };
3182
3245
 
3183
- /**
3184
- * Detects the first chunk in a buffer.
3185
- *
3186
- * @param buffer - The buffer to detect the first chunk in.
3187
- *
3188
- * @returns The first detected chunk, or `undefined` if no chunk was detected.
3189
- */
3190
- type ChunkDetector = (buffer: string) => string | undefined | null;
3191
- /**
3192
- * Smooths text streaming output.
3193
- *
3194
- * @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
3195
- * @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.
3196
- *
3197
- * @returns A transform stream that smooths text streaming output.
3198
- */
3199
- declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _internal: { delay }, }?: {
3200
- delayInMs?: number | null;
3201
- chunking?: 'word' | 'line' | RegExp | ChunkDetector;
3202
- /**
3203
- * Internal. For test use only. May change without notice.
3204
- */
3205
- _internal?: {
3206
- delay?: (delayInMs: number | null) => Promise<void>;
3207
- };
3208
- }): (options: {
3209
- tools: TOOLS;
3210
- }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
3246
+ interface Output<OUTPUT, PARTIAL> {
3247
+ readonly type: 'object' | 'text';
3248
+ responseFormat: LanguageModelV2CallOptions['responseFormat'];
3249
+ parsePartial(options: {
3250
+ text: string;
3251
+ }): Promise<{
3252
+ partial: PARTIAL;
3253
+ } | undefined>;
3254
+ parseOutput(options: {
3255
+ text: string;
3256
+ }, context: {
3257
+ response: LanguageModelResponseMetadata;
3258
+ usage: LanguageModelUsage;
3259
+ finishReason: FinishReason;
3260
+ }): Promise<OUTPUT>;
3261
+ }
3262
+ declare const text: () => Output<string, string>;
3263
+ declare const object: <OUTPUT>({ schema: inputSchema, }: {
3264
+ schema: z4.$ZodType<OUTPUT, any> | z3.Schema<OUTPUT, z3.ZodTypeDef, any> | Schema<OUTPUT>;
3265
+ }) => Output<OUTPUT, DeepPartial<OUTPUT>>;
3211
3266
 
3212
- /**
3213
- A transformation that is applied to the stream.
3267
+ type output_Output<OUTPUT, PARTIAL> = Output<OUTPUT, PARTIAL>;
3268
+ declare const output_object: typeof object;
3269
+ declare const output_text: typeof text;
3270
+ declare namespace output {
3271
+ export {
3272
+ output_Output as Output,
3273
+ output_object as object,
3274
+ output_text as text,
3275
+ };
3276
+ }
3214
3277
 
3215
- @param stopStream - A function that stops the source stream.
3216
- @param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
3217
- */
3218
- type StreamTextTransform<TOOLS extends ToolSet> = (options: {
3219
- tools: TOOLS;
3220
- stopStream: () => void;
3221
- }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
3222
3278
  /**
3223
- Callback that is set using the `onError` option.
3279
+ Function that you can use to provide different settings for a step.
3280
+
3281
+ @param options - The options for the step.
3282
+ @param options.steps - The steps that have been executed so far.
3283
+ @param options.stepNumber - The number of the step that is being executed.
3284
+ @param options.model - The model that is being used.
3285
+
3286
+ @returns An object that contains the settings for the step.
3287
+ If you return undefined (or for undefined settings), the settings from the outer level will be used.
3288
+ */
3289
+ type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Tool>> = (options: {
3290
+ steps: Array<StepResult<NoInfer<TOOLS>>>;
3291
+ stepNumber: number;
3292
+ model: LanguageModel;
3293
+ }) => PromiseLike<PrepareStepResult<TOOLS>> | PrepareStepResult<TOOLS>;
3294
+ type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
3295
+ model?: LanguageModel;
3296
+ toolChoice?: ToolChoice<NoInfer<TOOLS>>;
3297
+ activeTools?: Array<keyof NoInfer<TOOLS>>;
3298
+ system?: string;
3299
+ } | undefined;
3300
+
3301
+ type StopCondition<TOOLS extends ToolSet> = (options: {
3302
+ steps: Array<StepResult<TOOLS>>;
3303
+ }) => PromiseLike<boolean> | boolean;
3304
+ declare function stepCountIs(stepCount: number): StopCondition<any>;
3305
+ declare function hasToolCall(toolName: string): StopCondition<any>;
3224
3306
 
3225
- @param event - The event that is passed to the callback.
3226
- */
3227
- type StreamTextOnErrorCallback = (event: {
3228
- error: unknown;
3229
- }) => Promise<void> | void;
3230
3307
  /**
3231
3308
  Callback that is set using the `onStepFinish` option.
3232
3309
 
3233
3310
  @param stepResult - The result of the step.
3234
3311
  */
3235
- type StreamTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
3312
+ type GenerateTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
3236
3313
  /**
3237
- Callback that is set using the `onChunk` option.
3314
+ Generate a text and call tools for a given prompt using a language model.
3238
3315
 
3239
- @param event - The event that is passed to the callback.
3240
- */
3241
- type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
3242
- chunk: Extract<TextStreamPart<TOOLS>, {
3243
- type: 'text' | 'reasoning' | 'source' | 'tool-call' | 'tool-call-streaming-start' | 'tool-call-delta' | 'tool-result';
3244
- }>;
3245
- }) => Promise<void> | void;
3246
- /**
3247
- Callback that is set using the `onFinish` option.
3248
-
3249
- @param event - The event that is passed to the callback.
3250
- */
3251
- type StreamTextOnFinishCallback<TOOLS extends ToolSet> = (event: StepResult<TOOLS> & {
3252
- /**
3253
- Details for all steps.
3254
- */
3255
- readonly steps: StepResult<TOOLS>[];
3256
- /**
3257
- Total usage for all steps. This is the sum of the usage of all steps.
3258
- */
3259
- readonly totalUsage: LanguageModelUsage;
3260
- }) => Promise<void> | void;
3261
- /**
3262
- Generate a text and call tools for a given prompt using a language model.
3263
-
3264
- This function streams the output. If you do not want to stream the output, use `generateText` instead.
3316
+ This function does not stream the output. If you want to stream the output, use `streamText` instead.
3265
3317
 
3266
3318
  @param model - The language model to use.
3319
+
3267
3320
  @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
3321
+ @param toolChoice - The tool choice strategy. Default: 'auto'.
3268
3322
 
3269
3323
  @param system - A system message that will be part of the prompt.
3270
3324
  @param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
@@ -3295,30 +3349,26 @@ If set and supported by the model, calls will generate deterministic results.
3295
3349
  @param abortSignal - An optional abort signal that can be used to cancel the call.
3296
3350
  @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
3297
3351
 
3298
- @param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
3352
+ @param experimental_generateMessageId - Generate a unique ID for each message.
3299
3353
 
3300
- @param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
3301
- @param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
3302
3354
  @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
3303
- @param onFinish - Callback that is called when the LLM response and all request tool executions
3304
- (for tools that have an `execute` function) are finished.
3305
3355
 
3306
- @return
3307
- A result object for accessing different stream types and additional information.
3356
+ @returns
3357
+ A result object that contains the generated text, the results of the tool calls, and additional information.
3308
3358
  */
3309
- declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_toolCallStreaming, toolCallStreaming, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, onChunk, onError, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
3359
+ declare function generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>({ model: modelArg, tools, toolChoice, system, prompt, messages, maxRetries: maxRetriesArg, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_activeTools, activeTools, experimental_prepareStep, prepareStep, experimental_repairToolCall: repairToolCall, _internal: { generateId, currentDate, }, onStepFinish, ...settings }: CallSettings & Prompt & {
3310
3360
  /**
3311
3361
  The language model to use.
3312
3362
  */
3313
3363
  model: LanguageModel;
3314
3364
  /**
3315
3365
  The tools that the model can call. The model needs to support calling tools.
3316
- */
3366
+ */
3317
3367
  tools?: TOOLS;
3318
3368
  /**
3319
3369
  The tool choice strategy. Default: 'auto'.
3320
3370
  */
3321
- toolChoice?: ToolChoice<TOOLS>;
3371
+ toolChoice?: ToolChoice<NoInfer<TOOLS>>;
3322
3372
  /**
3323
3373
  Condition for stopping the generation when there are tool results in the last step.
3324
3374
  When the condition is an array, any of the conditions can be met to stop the generation.
@@ -3341,258 +3391,434 @@ functionality that can be fully encapsulated in the provider.
3341
3391
  */
3342
3392
  experimental_activeTools?: Array<keyof NoInfer<TOOLS>>;
3343
3393
  /**
3344
- Limits the tools that are available for the model to call without
3345
- changing the tool call and result types in the result.
3346
- */
3394
+ Limits the tools that are available for the model to call without
3395
+ changing the tool call and result types in the result.
3396
+ */
3347
3397
  activeTools?: Array<keyof NoInfer<TOOLS>>;
3348
3398
  /**
3349
3399
  Optional specification for parsing structured outputs from the LLM response.
3350
3400
  */
3351
- experimental_output?: Output<OUTPUT, PARTIAL_OUTPUT>;
3401
+ experimental_output?: Output<OUTPUT, OUTPUT_PARTIAL>;
3402
+ /**
3403
+ * @deprecated Use `prepareStep` instead.
3404
+ */
3405
+ experimental_prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
3352
3406
  /**
3353
3407
  Optional function that you can use to provide different settings for a step.
3354
-
3355
- @param options - The options for the step.
3356
- @param options.steps - The steps that have been executed so far.
3357
- @param options.stepNumber - The number of the step that is being executed.
3358
- @param options.model - The model that is being used.
3359
-
3360
- @returns An object that contains the settings for the step.
3361
- If you return undefined (or for undefined settings), the settings from the outer level will be used.
3362
3408
  */
3363
3409
  prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
3364
3410
  /**
3365
3411
  A function that attempts to repair a tool call that failed to parse.
3366
3412
  */
3367
- experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
3413
+ experimental_repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>;
3368
3414
  /**
3369
- Enable streaming of tool call deltas as they are generated. Disabled by default.
3370
- */
3371
- toolCallStreaming?: boolean;
3415
+ Callback that is called when each step (LLM call) is finished, including intermediate steps.
3416
+ */
3417
+ onStepFinish?: GenerateTextOnStepFinishCallback<NoInfer<TOOLS>>;
3372
3418
  /**
3373
- @deprecated Use `toolCallStreaming` instead.
3419
+ * Internal. For test use only. May change without notice.
3374
3420
  */
3375
- experimental_toolCallStreaming?: boolean;
3421
+ _internal?: {
3422
+ generateId?: IdGenerator;
3423
+ currentDate?: () => Date;
3424
+ };
3425
+ }): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
3426
+
3427
+ type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
3428
+
3429
+ type UIMessageStreamOptions<UI_MESSAGE extends UIMessage> = {
3376
3430
  /**
3377
- Optional stream transformations.
3378
- They are applied in the order they are provided.
3379
- The stream transformations must maintain the stream structure for streamText to work correctly.
3431
+ * Message ID that is sent to the client if a new message is created.
3432
+ * This is intended to be used for the UI message,
3433
+ * if the last original message is not an assistant message
3434
+ * (in which case that message ID is used).
3380
3435
  */
3381
- experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
3436
+ newMessageId?: string;
3382
3437
  /**
3383
- Callback that is called for each chunk of the stream.
3384
- The stream processing will pause until the callback promise is resolved.
3438
+ * The original messages.
3385
3439
  */
3386
- onChunk?: StreamTextOnChunkCallback<TOOLS>;
3440
+ originalMessages?: UI_MESSAGE[];
3441
+ onFinish?: (options: {
3442
+ /**
3443
+ * The updates list of UI messages.
3444
+ */
3445
+ messages: UI_MESSAGE[];
3446
+ /**
3447
+ * Indicates whether the response message is a continuation of the last original message,
3448
+ * or if a new message was created.
3449
+ */
3450
+ isContinuation: boolean;
3451
+ /**
3452
+ * The message that was sent to the client as a response
3453
+ * (including the original message if it was extended).
3454
+ */
3455
+ responseMessage: UI_MESSAGE;
3456
+ }) => void;
3387
3457
  /**
3388
- Callback that is invoked when an error occurs during streaming.
3389
- You can use it to log errors.
3390
- The stream processing will pause until the callback promise is resolved.
3458
+ * Extracts message metadata that will be send to the client.
3459
+ *
3460
+ * Called on `start` and `finish` events.
3391
3461
  */
3392
- onError?: StreamTextOnErrorCallback;
3462
+ messageMetadata?: (options: {
3463
+ part: TextStreamPart<ToolSet> & {
3464
+ type: 'start' | 'finish' | 'start-step' | 'finish-step';
3465
+ };
3466
+ }) => InferUIMessageMetadata<UI_MESSAGE> | undefined;
3393
3467
  /**
3394
- Callback that is called when the LLM response and all request tool executions
3395
- (for tools that have an `execute` function) are finished.
3396
-
3397
- The usage is the combined usage of all steps.
3468
+ * Send reasoning parts to the client.
3469
+ * Default to false.
3398
3470
  */
3399
- onFinish?: StreamTextOnFinishCallback<TOOLS>;
3400
- /**
3401
- Callback that is called when each step (LLM call) is finished, including intermediate steps.
3402
- */
3403
- onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
3471
+ sendReasoning?: boolean;
3404
3472
  /**
3405
- Internal. For test use only. May change without notice.
3473
+ * Send source parts to the client.
3474
+ * Default to false.
3406
3475
  */
3407
- _internal?: {
3408
- now?: () => number;
3409
- generateId?: IdGenerator;
3410
- currentDate?: () => Date;
3411
- };
3412
- }): StreamTextResult<TOOLS, PARTIAL_OUTPUT>;
3413
-
3414
- /**
3415
- The result of a `generateImage` call.
3416
- It contains the images and additional information.
3417
- */
3418
- interface GenerateImageResult {
3476
+ sendSources?: boolean;
3419
3477
  /**
3420
- The first image that was generated.
3478
+ * Send the finish event to the client.
3479
+ * Set to false if you are using additional streamText calls
3480
+ * that send additional data.
3481
+ * Default to true.
3421
3482
  */
3422
- readonly image: GeneratedFile;
3423
- /**
3424
- The images that were generated.
3425
- */
3426
- readonly images: Array<GeneratedFile>;
3427
- /**
3428
- Warnings for the call, e.g. unsupported settings.
3429
- */
3430
- readonly warnings: Array<ImageGenerationWarning>;
3483
+ sendFinish?: boolean;
3431
3484
  /**
3432
- Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
3485
+ * Send the message start event to the client.
3486
+ * Set to false if you are using additional streamText calls
3487
+ * and the message start event has already been sent.
3488
+ * Default to true.
3489
+ *
3490
+ * Note: this setting is currently not used, but you should
3491
+ * already set it to false if you are using additional
3492
+ * streamText calls that send additional data to prevent
3493
+ * the message start event from being sent multiple times.
3433
3494
  */
3434
- readonly responses: Array<ImageModelResponseMetadata>;
3495
+ sendStart?: boolean;
3435
3496
  /**
3436
- * Provider-specific metadata. They are passed through from the provider to the AI SDK and enable provider-specific
3437
- * results that can be fully encapsulated in the provider.
3497
+ * Process an error, e.g. to log it. Default to `() => 'An error occurred.'`.
3498
+ *
3499
+ * @return error message to include in the data stream.
3438
3500
  */
3439
- readonly providerMetadata: ImageModelProviderMetadata;
3440
- }
3441
-
3501
+ onError?: (error: unknown) => string;
3502
+ };
3503
+ type ConsumeStreamOptions = {
3504
+ onError?: (error: unknown) => void;
3505
+ };
3442
3506
  /**
3443
- Generates images using an image model.
3444
-
3445
- @param model - The image model to use.
3446
- @param prompt - The prompt that should be used to generate the image.
3447
- @param n - Number of images to generate. Default: 1.
3448
- @param size - Size of the images to generate. Must have the format `{width}x{height}`.
3449
- @param aspectRatio - Aspect ratio of the images to generate. Must have the format `{width}:{height}`.
3450
- @param seed - Seed for the image generation.
3451
- @param providerOptions - Additional provider-specific options that are passed through to the provider
3452
- as body parameters.
3453
- @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
3454
- @param abortSignal - An optional abort signal that can be used to cancel the call.
3455
- @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
3456
-
3457
- @returns A result object that contains the generated images.
3507
+ A result object for accessing different stream types and additional information.
3458
3508
  */
3459
- declare function generateImage({ model, prompt, n, maxImagesPerCall, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
3460
- /**
3461
- The image model to use.
3462
- */
3463
- model: ImageModelV2;
3509
+ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
3464
3510
  /**
3465
- The prompt that should be used to generate the image.
3511
+ The content that was generated in the last step.
3512
+
3513
+ Resolved when the response is finished.
3466
3514
  */
3467
- prompt: string;
3515
+ readonly content: Promise<Array<ContentPart<TOOLS>>>;
3468
3516
  /**
3469
- Number of images to generate.
3470
- */
3471
- n?: number;
3517
+ The full text that has been generated by the last step.
3518
+
3519
+ Resolved when the response is finished.
3520
+ */
3521
+ readonly text: Promise<string>;
3472
3522
  /**
3473
- Number of images to generate.
3523
+ The full reasoning that the model has generated.
3524
+
3525
+ Resolved when the response is finished.
3474
3526
  */
3475
- maxImagesPerCall?: number;
3527
+ readonly reasoning: Promise<Array<ReasoningPart>>;
3476
3528
  /**
3477
- Size of the images to generate. Must have the format `{width}x{height}`. If not provided, the default size will be used.
3478
- */
3479
- size?: `${number}x${number}`;
3529
+ The reasoning that has been generated by the last step.
3530
+
3531
+ Resolved when the response is finished.
3532
+ */
3533
+ readonly reasoningText: Promise<string | undefined>;
3480
3534
  /**
3481
- Aspect ratio of the images to generate. Must have the format `{width}:{height}`. If not provided, the default aspect ratio will be used.
3535
+ Files that have been generated by the model in the last step.
3536
+
3537
+ Resolved when the response is finished.
3482
3538
  */
3483
- aspectRatio?: `${number}:${number}`;
3539
+ readonly files: Promise<GeneratedFile[]>;
3484
3540
  /**
3485
- Seed for the image generation. If not provided, the default seed will be used.
3541
+ Sources that have been used as references in the last step.
3542
+
3543
+ Resolved when the response is finished.
3486
3544
  */
3487
- seed?: number;
3545
+ readonly sources: Promise<Source[]>;
3488
3546
  /**
3489
- Additional provider-specific options that are passed through to the provider
3490
- as body parameters.
3547
+ The tool calls that have been executed in the last step.
3491
3548
 
3492
- The outer record is keyed by the provider name, and the inner
3493
- record is keyed by the provider-specific metadata key.
3494
- ```ts
3495
- {
3496
- "openai": {
3497
- "style": "vivid"
3498
- }
3499
- }
3500
- ```
3549
+ Resolved when the response is finished.
3501
3550
  */
3502
- providerOptions?: ProviderOptions;
3551
+ readonly toolCalls: Promise<ToolCallUnion<TOOLS>[]>;
3503
3552
  /**
3504
- Maximum number of retries per embedding model call. Set to 0 to disable retries.
3553
+ The tool results that have been generated in the last step.
3505
3554
 
3506
- @default 2
3555
+ Resolved when the all tool executions are finished.
3507
3556
  */
3508
- maxRetries?: number;
3557
+ readonly toolResults: Promise<ToolResultUnion<TOOLS>[]>;
3509
3558
  /**
3510
- Abort signal.
3511
- */
3512
- abortSignal?: AbortSignal;
3559
+ The reason why the generation finished. Taken from the last step.
3560
+
3561
+ Resolved when the response is finished.
3562
+ */
3563
+ readonly finishReason: Promise<FinishReason>;
3513
3564
  /**
3514
- Additional headers to include in the request.
3515
- Only applicable for HTTP-based providers.
3516
- */
3517
- headers?: Record<string, string>;
3518
- }): Promise<GenerateImageResult>;
3519
-
3520
- /**
3521
- The result of a `generateObject` call.
3522
- */
3523
- interface GenerateObjectResult<OBJECT> {
3565
+ The token usage of the last step.
3566
+
3567
+ Resolved when the response is finished.
3568
+ */
3569
+ readonly usage: Promise<LanguageModelUsage>;
3524
3570
  /**
3525
- The generated object (typed according to the schema).
3571
+ The total token usage of the generated response.
3572
+ When there are multiple steps, the usage is the sum of all step usages.
3573
+
3574
+ Resolved when the response is finished.
3526
3575
  */
3527
- readonly object: OBJECT;
3576
+ readonly totalUsage: Promise<LanguageModelUsage>;
3528
3577
  /**
3529
- The reason why the generation finished.
3578
+ Warnings from the model provider (e.g. unsupported settings) for the first step.
3530
3579
  */
3531
- readonly finishReason: FinishReason;
3580
+ readonly warnings: Promise<CallWarning[] | undefined>;
3532
3581
  /**
3533
- The token usage of the generated text.
3582
+ Details for all steps.
3583
+ You can use this to get information about intermediate steps,
3584
+ such as the tool calls or the response headers.
3585
+ */
3586
+ readonly steps: Promise<Array<StepResult<TOOLS>>>;
3587
+ /**
3588
+ Additional request information from the last step.
3589
+ */
3590
+ readonly request: Promise<LanguageModelRequestMetadata>;
3591
+ /**
3592
+ Additional response information from the last step.
3593
+ */
3594
+ readonly response: Promise<LanguageModelResponseMetadata & {
3595
+ /**
3596
+ The response messages that were generated during the call. It consists of an assistant message,
3597
+ potentially containing tool calls.
3598
+
3599
+ When there are tool results, there is an additional tool message with the tool results that are available.
3600
+ If there are tools that do not have execute functions, they are not included in the tool results and
3601
+ need to be added separately.
3602
+ */
3603
+ messages: Array<ResponseMessage>;
3604
+ }>;
3605
+ /**
3606
+ Additional provider-specific metadata from the last step.
3607
+ Metadata is passed through from the provider to the AI SDK and
3608
+ enables provider-specific results that can be fully encapsulated in the provider.
3609
+ */
3610
+ readonly providerMetadata: Promise<ProviderMetadata | undefined>;
3611
+ /**
3612
+ A text stream that returns only the generated text deltas. You can use it
3613
+ as either an AsyncIterable or a ReadableStream. When an error occurs, the
3614
+ stream will throw the error.
3534
3615
  */
3535
- readonly usage: LanguageModelUsage;
3616
+ readonly textStream: AsyncIterableStream<string>;
3536
3617
  /**
3537
- Warnings from the model provider (e.g. unsupported settings).
3618
+ A stream with all events, including text deltas, tool calls, tool results, and
3619
+ errors.
3620
+ You can use it as either an AsyncIterable or a ReadableStream.
3621
+ Only errors that stop the stream, such as network errors, are thrown.
3538
3622
  */
3539
- readonly warnings: CallWarning[] | undefined;
3623
+ readonly fullStream: AsyncIterableStream<TextStreamPart<TOOLS>>;
3540
3624
  /**
3541
- Additional request information.
3625
+ A stream of partial outputs. It uses the `experimental_output` specification.
3542
3626
  */
3543
- readonly request: LanguageModelRequestMetadata;
3627
+ readonly experimental_partialOutputStream: AsyncIterableStream<PARTIAL_OUTPUT>;
3544
3628
  /**
3545
- Additional response information.
3546
- */
3547
- readonly response: LanguageModelResponseMetadata & {
3548
- /**
3549
- Response body (available only for providers that use HTTP requests).
3550
- */
3551
- body?: unknown;
3552
- };
3629
+ Consumes the stream without processing the parts.
3630
+ This is useful to force the stream to finish.
3631
+ It effectively removes the backpressure and allows the stream to finish,
3632
+ triggering the `onFinish` callback and the promise resolution.
3633
+
3634
+ If an error occurs, it is passed to the optional `onError` callback.
3635
+ */
3636
+ consumeStream(options?: ConsumeStreamOptions): Promise<void>;
3553
3637
  /**
3554
- Additional provider-specific metadata. They are passed through
3555
- from the provider to the AI SDK and enable provider-specific
3556
- results that can be fully encapsulated in the provider.
3557
- */
3558
- readonly providerMetadata: ProviderMetadata | undefined;
3638
+ Converts the result to a UI message stream.
3639
+
3640
+ @param options.getErrorMessage an optional function that converts an error to an error message.
3641
+ @param options.sendUsage whether to send the usage information to the client. Defaults to true.
3642
+ @param options.sendReasoning whether to send the reasoning information to the client. Defaults to false.
3643
+ @param options.sendSources whether to send the sources information to the client. Defaults to false.
3644
+ @param options.experimental_sendFinish whether to send the finish information to the client. Defaults to true.
3645
+ @param options.experimental_sendStart whether to send the start information to the client. Defaults to true.
3646
+
3647
+ @return A UI message stream.
3648
+ */
3649
+ toUIMessageStream<UI_MESSAGE extends UIMessage>(options?: UIMessageStreamOptions<UI_MESSAGE>): ReadableStream<InferUIMessageStreamPart<UI_MESSAGE>>;
3559
3650
  /**
3560
- Converts the object to a JSON response.
3561
- The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
3651
+ Writes UI message stream output to a Node.js response-like object.
3652
+ @param response A Node.js response-like object (ServerResponse).
3653
+ @param options.status The status code.
3654
+ @param options.statusText The status text.
3655
+ @param options.headers The headers.
3656
+ @param options.getErrorMessage An optional function that converts an error to an error message.
3657
+ @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
3658
+ @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
3562
3659
  */
3563
- toJsonResponse(init?: ResponseInit): Response;
3660
+ pipeUIMessageStreamToResponse<UI_MESSAGE extends UIMessage>(response: ServerResponse, options?: ResponseInit & UIMessageStreamOptions<UI_MESSAGE>): void;
3661
+ /**
3662
+ Writes text delta output to a Node.js response-like object.
3663
+ It sets a `Content-Type` header to `text/plain; charset=utf-8` and
3664
+ writes each text delta as a separate chunk.
3665
+ @param response A Node.js response-like object (ServerResponse).
3666
+ @param init Optional headers, status code, and status text.
3667
+ */
3668
+ pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void;
3669
+ /**
3670
+ Converts the result to a streamed response object with a stream data part stream.
3671
+
3672
+ @param options.status The status code.
3673
+ @param options.statusText The status text.
3674
+ @param options.headers The headers.
3675
+ @param options.getErrorMessage An optional function that converts an error to an error message.
3676
+ @param options.sendUsage Whether to send the usage information to the client. Defaults to true.
3677
+ @param options.sendReasoning Whether to send the reasoning information to the client. Defaults to false.
3678
+ @return A response object.
3679
+ */
3680
+ toUIMessageStreamResponse<UI_MESSAGE extends UIMessage>(options?: ResponseInit & UIMessageStreamOptions<UI_MESSAGE>): Response;
3681
+ /**
3682
+ Creates a simple text stream response.
3683
+ Each text delta is encoded as UTF-8 and sent as a separate chunk.
3684
+ Non-text-delta events are ignored.
3685
+ @param init Optional headers, status code, and status text.
3686
+ */
3687
+ toTextStreamResponse(init?: ResponseInit): Response;
3564
3688
  }
3689
+ type TextStreamPart<TOOLS extends ToolSet> = ContentPart<TOOLS> | {
3690
+ type: 'reasoning-part-finish';
3691
+ } | {
3692
+ type: 'tool-call-streaming-start';
3693
+ toolCallId: string;
3694
+ toolName: string;
3695
+ } | {
3696
+ type: 'tool-call-delta';
3697
+ toolCallId: string;
3698
+ toolName: string;
3699
+ argsTextDelta: string;
3700
+ } | {
3701
+ type: 'start-step';
3702
+ request: LanguageModelRequestMetadata;
3703
+ warnings: CallWarning[];
3704
+ } | {
3705
+ type: 'finish-step';
3706
+ response: LanguageModelResponseMetadata;
3707
+ usage: LanguageModelUsage;
3708
+ finishReason: FinishReason;
3709
+ providerMetadata: ProviderMetadata | undefined;
3710
+ } | {
3711
+ type: 'start';
3712
+ } | {
3713
+ type: 'finish';
3714
+ finishReason: FinishReason;
3715
+ totalUsage: LanguageModelUsage;
3716
+ } | {
3717
+ type: 'error';
3718
+ error: unknown;
3719
+ } | {
3720
+ type: 'raw';
3721
+ rawValue: unknown;
3722
+ };
3565
3723
 
3566
3724
  /**
3567
- A function that attempts to repair the raw output of the mode
3568
- to enable JSON parsing.
3569
-
3570
- Should return the repaired text or null if the text cannot be repaired.
3725
+ * Detects the first chunk in a buffer.
3726
+ *
3727
+ * @param buffer - The buffer to detect the first chunk in.
3728
+ *
3729
+ * @returns The first detected chunk, or `undefined` if no chunk was detected.
3730
+ */
3731
+ type ChunkDetector = (buffer: string) => string | undefined | null;
3732
+ /**
3733
+ * Smooths text streaming output.
3734
+ *
3735
+ * @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
3736
+ * @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.
3737
+ *
3738
+ * @returns A transform stream that smooths text streaming output.
3739
+ */
3740
+ declare function smoothStream<TOOLS extends ToolSet>({ delayInMs, chunking, _internal: { delay }, }?: {
3741
+ delayInMs?: number | null;
3742
+ chunking?: 'word' | 'line' | RegExp | ChunkDetector;
3743
+ /**
3744
+ * Internal. For test use only. May change without notice.
3571
3745
  */
3572
- type RepairTextFunction = (options: {
3573
- text: string;
3574
- error: JSONParseError | TypeValidationError;
3575
- }) => Promise<string | null>;
3746
+ _internal?: {
3747
+ delay?: (delayInMs: number | null) => Promise<void>;
3748
+ };
3749
+ }): (options: {
3750
+ tools: TOOLS;
3751
+ }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
3752
+
3576
3753
  /**
3577
- Generate a structured, typed object for a given prompt and schema using a language model.
3754
+ A transformation that is applied to the stream.
3578
3755
 
3579
- This function does not stream the output. If you want to stream the output, use `streamObject` instead.
3756
+ @param stopStream - A function that stops the source stream.
3757
+ @param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
3758
+ */
3759
+ type StreamTextTransform<TOOLS extends ToolSet> = (options: {
3760
+ tools: TOOLS;
3761
+ stopStream: () => void;
3762
+ }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
3763
+ /**
3764
+ Callback that is set using the `onError` option.
3580
3765
 
3581
- @param model - The language model to use.
3582
- @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
3766
+ @param event - The event that is passed to the callback.
3767
+ */
3768
+ type StreamTextOnErrorCallback = (event: {
3769
+ error: unknown;
3770
+ }) => Promise<void> | void;
3771
+ /**
3772
+ Callback that is set using the `onStepFinish` option.
3583
3773
 
3584
- @param system - A system message that will be part of the prompt.
3585
- @param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
3586
- @param messages - A list of messages. You can either use `prompt` or `messages` but not both.
3774
+ @param stepResult - The result of the step.
3775
+ */
3776
+ type StreamTextOnStepFinishCallback<TOOLS extends ToolSet> = (stepResult: StepResult<TOOLS>) => Promise<void> | void;
3777
+ /**
3778
+ Callback that is set using the `onChunk` option.
3587
3779
 
3588
- @param maxOutputTokens - Maximum number of tokens to generate.
3589
- @param temperature - Temperature setting.
3590
- The value is passed through to the provider. The range depends on the provider and model.
3591
- It is recommended to set either `temperature` or `topP`, but not both.
3592
- @param topP - Nucleus sampling.
3593
- The value is passed through to the provider. The range depends on the provider and model.
3594
- It is recommended to set either `temperature` or `topP`, but not both.
3595
- @param topK - Only sample from the top K options for each subsequent token.
3780
+ @param event - The event that is passed to the callback.
3781
+ */
3782
+ type StreamTextOnChunkCallback<TOOLS extends ToolSet> = (event: {
3783
+ chunk: Extract<TextStreamPart<TOOLS>, {
3784
+ type: 'text' | 'reasoning' | 'source' | 'tool-call' | 'tool-call-streaming-start' | 'tool-call-delta' | 'tool-result';
3785
+ }>;
3786
+ }) => Promise<void> | void;
3787
+ /**
3788
+ Callback that is set using the `onFinish` option.
3789
+
3790
+ @param event - The event that is passed to the callback.
3791
+ */
3792
+ type StreamTextOnFinishCallback<TOOLS extends ToolSet> = (event: StepResult<TOOLS> & {
3793
+ /**
3794
+ Details for all steps.
3795
+ */
3796
+ readonly steps: StepResult<TOOLS>[];
3797
+ /**
3798
+ Total usage for all steps. This is the sum of the usage of all steps.
3799
+ */
3800
+ readonly totalUsage: LanguageModelUsage;
3801
+ }) => Promise<void> | void;
3802
+ /**
3803
+ Generate a text and call tools for a given prompt using a language model.
3804
+
3805
+ This function streams the output. If you do not want to stream the output, use `generateText` instead.
3806
+
3807
+ @param model - The language model to use.
3808
+ @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
3809
+
3810
+ @param system - A system message that will be part of the prompt.
3811
+ @param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
3812
+ @param messages - A list of messages. You can either use `prompt` or `messages` but not both.
3813
+
3814
+ @param maxOutputTokens - Maximum number of tokens to generate.
3815
+ @param temperature - Temperature setting.
3816
+ The value is passed through to the provider. The range depends on the provider and model.
3817
+ It is recommended to set either `temperature` or `topP`, but not both.
3818
+ @param topP - Nucleus sampling.
3819
+ The value is passed through to the provider. The range depends on the provider and model.
3820
+ It is recommended to set either `temperature` or `topP`, but not both.
3821
+ @param topK - Only sample from the top K options for each subsequent token.
3596
3822
  Used to remove "long tail" low probability responses.
3597
3823
  Recommended for advanced use cases only. You usually only need to use temperature.
3598
3824
  @param presencePenalty - Presence penalty setting.
@@ -3610,85 +3836,40 @@ If set and supported by the model, calls will generate deterministic results.
3610
3836
  @param abortSignal - An optional abort signal that can be used to cancel the call.
3611
3837
  @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
3612
3838
 
3613
- @param schema - The schema of the object that the model should generate.
3614
- @param schemaName - Optional name of the output that should be generated.
3615
- Used by some providers for additional LLM guidance, e.g.
3616
- via tool or schema name.
3617
- @param schemaDescription - Optional description of the output that should be generated.
3618
- Used by some providers for additional LLM guidance, e.g.
3619
- via tool or schema description.
3620
-
3621
- @param output - The type of the output.
3622
-
3623
- - 'object': The output is an object.
3624
- - 'array': The output is an array.
3625
- - 'enum': The output is an enum.
3626
- - 'no-schema': The output is not a schema.
3627
-
3628
- @param experimental_repairText - A function that attempts to repair the raw output of the mode
3629
- to enable JSON parsing.
3630
-
3631
- @param experimental_telemetry - Optional telemetry configuration (experimental).
3839
+ @param maxSteps - Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
3632
3840
 
3633
- @param providerOptions - Additional provider-specific options. They are passed through
3634
- to the provider from the AI SDK and enable provider-specific
3635
- functionality that can be fully encapsulated in the provider.
3841
+ @param onChunk - Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
3842
+ @param onError - Callback that is called when an error occurs during streaming. You can use it to log errors.
3843
+ @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
3844
+ @param onFinish - Callback that is called when the LLM response and all request tool executions
3845
+ (for tools that have an `execute` function) are finished.
3636
3846
 
3637
- @returns
3638
- A result object that contains the generated object, the finish reason, the token usage, and additional information.
3847
+ @return
3848
+ A result object for accessing different stream types and additional information.
3639
3849
  */
3640
- declare function generateObject<SCHEMA extends z3.Schema | z4.$ZodType | Schema = z4.$ZodType<JSONValue$1>, OUTPUT extends 'object' | 'array' | 'enum' | 'no-schema' = InferSchema<SCHEMA> extends string ? 'enum' : 'object', RESULT = OUTPUT extends 'array' ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (OUTPUT extends 'enum' ? {
3641
- /**
3642
- The enum values that the model should use.
3643
- */
3644
- enum: Array<RESULT>;
3645
- mode?: 'json';
3646
- output: 'enum';
3647
- } : OUTPUT extends 'no-schema' ? {} : {
3648
- /**
3649
- The schema of the object that the model should generate.
3650
- */
3651
- schema: SCHEMA;
3652
- /**
3653
- Optional name of the output that should be generated.
3654
- Used by some providers for additional LLM guidance, e.g.
3655
- via tool or schema name.
3656
- */
3657
- schemaName?: string;
3658
- /**
3659
- Optional description of the output that should be generated.
3660
- Used by some providers for additional LLM guidance, e.g.
3661
- via tool or schema description.
3662
- */
3663
- schemaDescription?: string;
3664
- /**
3665
- The mode to use for object generation.
3666
-
3667
- The schema is converted into a JSON schema and used in one of the following ways
3668
-
3669
- - 'auto': The provider will choose the best mode for the model.
3670
- - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
3671
- - '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.
3672
-
3673
- Please note that most providers do not support all modes.
3674
-
3675
- Default and recommended: 'auto' (best mode for the model).
3676
- */
3677
- mode?: 'auto' | 'json' | 'tool';
3678
- }) & {
3679
- output?: OUTPUT;
3850
+ declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, stopWhen, experimental_output: output, experimental_telemetry: telemetry, prepareStep, providerOptions, experimental_activeTools, activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, includeRawChunks, onChunk, onError, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
3680
3851
  /**
3681
3852
  The language model to use.
3682
3853
  */
3683
3854
  model: LanguageModel;
3684
3855
  /**
3685
- A function that attempts to repair the raw output of the mode
3686
- to enable JSON parsing.
3856
+ The tools that the model can call. The model needs to support calling tools.
3857
+ */
3858
+ tools?: TOOLS;
3859
+ /**
3860
+ The tool choice strategy. Default: 'auto'.
3687
3861
  */
3688
- experimental_repairText?: RepairTextFunction;
3862
+ toolChoice?: ToolChoice<TOOLS>;
3863
+ /**
3864
+ Condition for stopping the generation when there are tool results in the last step.
3865
+ When the condition is an array, any of the conditions can be met to stop the generation.
3866
+
3867
+ @default stepCountIs(1)
3868
+ */
3869
+ stopWhen?: StopCondition<NoInfer<TOOLS>> | Array<StopCondition<NoInfer<TOOLS>>>;
3689
3870
  /**
3690
3871
  Optional telemetry configuration (experimental).
3691
- */
3872
+ */
3692
3873
  experimental_telemetry?: TelemetrySettings;
3693
3874
  /**
3694
3875
  Additional provider-specific options. They are passed through
@@ -3697,206 +3878,245 @@ functionality that can be fully encapsulated in the provider.
3697
3878
  */
3698
3879
  providerOptions?: ProviderOptions;
3699
3880
  /**
3700
- * Internal. For test use only. May change without notice.
3881
+ * @deprecated Use `activeTools` instead.
3701
3882
  */
3702
- _internal?: {
3703
- generateId?: () => string;
3704
- currentDate?: () => Date;
3705
- };
3706
- }): Promise<GenerateObjectResult<RESULT>>;
3707
-
3708
- /**
3709
- * Calculates the cosine similarity between two vectors. This is a useful metric for
3710
- * comparing the similarity of two vectors such as embeddings.
3711
- *
3712
- * @param vector1 - The first vector.
3713
- * @param vector2 - The second vector.
3714
- *
3715
- * @returns The cosine similarity between vector1 and vector2.
3716
- * @returns 0 if either vector is the zero vector.
3717
- *
3718
- * @throws {InvalidArgumentError} If the vectors do not have the same length.
3719
- */
3720
- declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
3721
-
3722
- /**
3723
- * Converts a data URL of type text/* to a text string.
3724
- */
3725
- declare function getTextFromDataUrl(dataUrl: string): string;
3726
-
3727
- /**
3728
- * Performs a deep-equal comparison of two parsed JSON objects.
3729
- *
3730
- * @param {any} obj1 - The first object to compare.
3731
- * @param {any} obj2 - The second object to compare.
3732
- * @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
3733
- */
3734
- declare function isDeepEqualData(obj1: any, obj2: any): boolean;
3735
-
3736
- declare function parsePartialJson(jsonText: string | undefined): Promise<{
3737
- value: JSONValue$1 | undefined;
3738
- state: 'undefined-input' | 'successful-parse' | 'repaired-parse' | 'failed-parse';
3739
- }>;
3740
-
3741
- type Job = () => Promise<void>;
3742
-
3743
- declare class SerialJobExecutor {
3744
- private queue;
3745
- private isProcessing;
3746
- private processQueue;
3747
- run(job: Job): Promise<void>;
3748
- }
3883
+ experimental_activeTools?: Array<keyof NoInfer<TOOLS>>;
3884
+ /**
3885
+ Limits the tools that are available for the model to call without
3886
+ changing the tool call and result types in the result.
3887
+ */
3888
+ activeTools?: Array<keyof NoInfer<TOOLS>>;
3889
+ /**
3890
+ Optional specification for parsing structured outputs from the LLM response.
3891
+ */
3892
+ experimental_output?: Output<OUTPUT, PARTIAL_OUTPUT>;
3893
+ /**
3894
+ Optional function that you can use to provide different settings for a step.
3749
3895
 
3750
- /**
3751
- * Creates a ReadableStream that emits the provided values with an optional delay between each value.
3752
- *
3753
- * @param options - The configuration options
3754
- * @param options.chunks - Array of values to be emitted by the stream
3755
- * @param options.initialDelayInMs - Optional initial delay in milliseconds before emitting the first value (default: 0). Can be set to `null` to skip the initial delay. The difference between `initialDelayInMs: null` and `initialDelayInMs: 0` is that `initialDelayInMs: null` will emit the values without any delay, while `initialDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
3756
- * @param options.chunkDelayInMs - Optional delay in milliseconds between emitting each value (default: 0). Can be set to `null` to skip the delay. The difference between `chunkDelayInMs: null` and `chunkDelayInMs: 0` is that `chunkDelayInMs: null` will emit the values without any delay, while `chunkDelayInMs: 0` will emit the values with a delay of 0 milliseconds.
3757
- * @returns A ReadableStream that emits the provided values
3758
- */
3759
- declare function simulateReadableStream<T>({ chunks, initialDelayInMs, chunkDelayInMs, _internal, }: {
3760
- chunks: T[];
3761
- initialDelayInMs?: number | null;
3762
- chunkDelayInMs?: number | null;
3763
- _internal?: {
3764
- delay?: (ms: number | null) => Promise<void>;
3765
- };
3766
- }): ReadableStream<T>;
3896
+ @param options - The options for the step.
3897
+ @param options.steps - The steps that have been executed so far.
3898
+ @param options.stepNumber - The number of the step that is being executed.
3899
+ @param options.model - The model that is being used.
3767
3900
 
3768
- /**
3769
- The result of a `streamObject` call that contains the partial object stream and additional information.
3770
- */
3771
- interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
3901
+ @returns An object that contains the settings for the step.
3902
+ If you return undefined (or for undefined settings), the settings from the outer level will be used.
3903
+ */
3904
+ prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
3772
3905
  /**
3773
- Warnings from the model provider (e.g. unsupported settings)
3774
- */
3775
- readonly warnings: Promise<CallWarning[] | undefined>;
3906
+ A function that attempts to repair a tool call that failed to parse.
3907
+ */
3908
+ experimental_repairToolCall?: ToolCallRepairFunction<TOOLS>;
3776
3909
  /**
3777
- The token usage of the generated response. Resolved when the response is finished.
3778
- */
3779
- readonly usage: Promise<LanguageModelUsage>;
3910
+ Optional stream transformations.
3911
+ They are applied in the order they are provided.
3912
+ The stream transformations must maintain the stream structure for streamText to work correctly.
3913
+ */
3914
+ experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
3780
3915
  /**
3781
- Additional provider-specific metadata. They are passed through
3782
- from the provider to the AI SDK and enable provider-specific
3783
- results that can be fully encapsulated in the provider.
3916
+ Whether to include raw chunks from the provider in the stream.
3917
+ When enabled, you will receive raw chunks with type 'raw' that contain the unprocessed data from the provider.
3918
+ This allows access to cutting-edge provider features not yet wrapped by the AI SDK.
3919
+ Defaults to false.
3784
3920
  */
3785
- readonly providerMetadata: Promise<ProviderMetadata | undefined>;
3921
+ includeRawChunks?: boolean;
3786
3922
  /**
3787
- Additional request information from the last step.
3788
- */
3789
- readonly request: Promise<LanguageModelRequestMetadata>;
3923
+ Callback that is called for each chunk of the stream.
3924
+ The stream processing will pause until the callback promise is resolved.
3925
+ */
3926
+ onChunk?: StreamTextOnChunkCallback<TOOLS>;
3790
3927
  /**
3791
- Additional response information.
3792
- */
3793
- readonly response: Promise<LanguageModelResponseMetadata>;
3928
+ Callback that is invoked when an error occurs during streaming.
3929
+ You can use it to log errors.
3930
+ The stream processing will pause until the callback promise is resolved.
3931
+ */
3932
+ onError?: StreamTextOnErrorCallback;
3794
3933
  /**
3795
- The generated object (typed according to the schema). Resolved when the response is finished.
3796
- */
3797
- readonly object: Promise<RESULT>;
3934
+ Callback that is called when the LLM response and all request tool executions
3935
+ (for tools that have an `execute` function) are finished.
3936
+
3937
+ The usage is the combined usage of all steps.
3938
+ */
3939
+ onFinish?: StreamTextOnFinishCallback<TOOLS>;
3798
3940
  /**
3799
- Stream of partial objects. It gets more complete as the stream progresses.
3800
-
3801
- Note that the partial object is not validated.
3802
- If you want to be certain that the actual content matches your schema, you need to implement your own validation for partial results.
3803
- */
3804
- readonly partialObjectStream: AsyncIterableStream<PARTIAL>;
3941
+ Callback that is called when each step (LLM call) is finished, including intermediate steps.
3942
+ */
3943
+ onStepFinish?: StreamTextOnStepFinishCallback<TOOLS>;
3805
3944
  /**
3806
- * Stream over complete array elements. Only available if the output strategy is set to `array`.
3945
+ Internal. For test use only. May change without notice.
3807
3946
  */
3808
- readonly elementStream: ELEMENT_STREAM;
3947
+ _internal?: {
3948
+ now?: () => number;
3949
+ generateId?: IdGenerator;
3950
+ currentDate?: () => Date;
3951
+ };
3952
+ }): StreamTextResult<TOOLS, PARTIAL_OUTPUT>;
3953
+
3954
+ /**
3955
+ The result of a `generateImage` call.
3956
+ It contains the images and additional information.
3957
+ */
3958
+ interface GenerateImageResult {
3809
3959
  /**
3810
- Text stream of the JSON representation of the generated object. It contains text chunks.
3811
- When the stream is finished, the object is valid JSON that can be parsed.
3812
- */
3813
- readonly textStream: AsyncIterableStream<string>;
3960
+ The first image that was generated.
3961
+ */
3962
+ readonly image: GeneratedFile;
3814
3963
  /**
3815
- Stream of different types of events, including partial objects, errors, and finish events.
3816
- Only errors that stop the stream, such as network errors, are thrown.
3964
+ The images that were generated.
3817
3965
  */
3818
- readonly fullStream: AsyncIterableStream<ObjectStreamPart<PARTIAL>>;
3966
+ readonly images: Array<GeneratedFile>;
3819
3967
  /**
3820
- Writes text delta output to a Node.js response-like object.
3821
- It sets a `Content-Type` header to `text/plain; charset=utf-8` and
3822
- writes each text delta as a separate chunk.
3823
-
3824
- @param response A Node.js response-like object (ServerResponse).
3825
- @param init Optional headers, status code, and status text.
3968
+ Warnings for the call, e.g. unsupported settings.
3826
3969
  */
3827
- pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): void;
3970
+ readonly warnings: Array<ImageGenerationWarning>;
3828
3971
  /**
3829
- Creates a simple text stream response.
3830
- The response has a `Content-Type` header set to `text/plain; charset=utf-8`.
3831
- Each text delta is encoded as UTF-8 and sent as a separate chunk.
3832
- Non-text-delta events are ignored.
3833
-
3834
- @param init Optional headers, status code, and status text.
3835
- */
3836
- toTextStreamResponse(init?: ResponseInit): Response;
3972
+ Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
3973
+ */
3974
+ readonly responses: Array<ImageModelResponseMetadata>;
3975
+ /**
3976
+ * Provider-specific metadata. They are passed through from the provider to the AI SDK and enable provider-specific
3977
+ * results that can be fully encapsulated in the provider.
3978
+ */
3979
+ readonly providerMetadata: ImageModelProviderMetadata;
3837
3980
  }
3838
- type ObjectStreamPart<PARTIAL> = {
3839
- type: 'object';
3840
- object: PARTIAL;
3841
- } | {
3842
- type: 'text-delta';
3843
- textDelta: string;
3844
- } | {
3845
- type: 'error';
3846
- error: unknown;
3847
- } | {
3848
- type: 'finish';
3849
- finishReason: FinishReason;
3850
- usage: LanguageModelUsage;
3851
- response: LanguageModelResponseMetadata;
3852
- providerMetadata?: ProviderMetadata;
3853
- };
3854
3981
 
3855
3982
  /**
3856
- Callback that is set using the `onError` option.
3983
+ Generates images using an image model.
3857
3984
 
3858
- @param event - The event that is passed to the callback.
3859
- */
3860
- type StreamObjectOnErrorCallback = (event: {
3861
- error: unknown;
3862
- }) => Promise<void> | void;
3863
- /**
3864
- Callback that is set using the `onFinish` option.
3985
+ @param model - The image model to use.
3986
+ @param prompt - The prompt that should be used to generate the image.
3987
+ @param n - Number of images to generate. Default: 1.
3988
+ @param size - Size of the images to generate. Must have the format `{width}x{height}`.
3989
+ @param aspectRatio - Aspect ratio of the images to generate. Must have the format `{width}:{height}`.
3990
+ @param seed - Seed for the image generation.
3991
+ @param providerOptions - Additional provider-specific options that are passed through to the provider
3992
+ as body parameters.
3993
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
3994
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
3995
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
3865
3996
 
3866
- @param event - The event that is passed to the callback.
3997
+ @returns A result object that contains the generated images.
3867
3998
  */
3868
- type StreamObjectOnFinishCallback<RESULT> = (event: {
3999
+ declare function generateImage({ model, prompt, n, maxImagesPerCall, size, aspectRatio, seed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
3869
4000
  /**
3870
- The token usage of the generated response.
3871
- */
3872
- usage: LanguageModelUsage;
4001
+ The image model to use.
4002
+ */
4003
+ model: ImageModelV2;
3873
4004
  /**
3874
- The generated object. Can be undefined if the final object does not match the schema.
3875
- */
3876
- object: RESULT | undefined;
4005
+ The prompt that should be used to generate the image.
4006
+ */
4007
+ prompt: string;
3877
4008
  /**
3878
- Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema.
3879
- */
3880
- error: unknown | undefined;
4009
+ Number of images to generate.
4010
+ */
4011
+ n?: number;
3881
4012
  /**
3882
- Response metadata.
4013
+ Number of images to generate.
4014
+ */
4015
+ maxImagesPerCall?: number;
4016
+ /**
4017
+ Size of the images to generate. Must have the format `{width}x{height}`. If not provided, the default size will be used.
4018
+ */
4019
+ size?: `${number}x${number}`;
4020
+ /**
4021
+ Aspect ratio of the images to generate. Must have the format `{width}:{height}`. If not provided, the default aspect ratio will be used.
4022
+ */
4023
+ aspectRatio?: `${number}:${number}`;
4024
+ /**
4025
+ Seed for the image generation. If not provided, the default seed will be used.
4026
+ */
4027
+ seed?: number;
4028
+ /**
4029
+ Additional provider-specific options that are passed through to the provider
4030
+ as body parameters.
4031
+
4032
+ The outer record is keyed by the provider name, and the inner
4033
+ record is keyed by the provider-specific metadata key.
4034
+ ```ts
4035
+ {
4036
+ "openai": {
4037
+ "style": "vivid"
4038
+ }
4039
+ }
4040
+ ```
4041
+ */
4042
+ providerOptions?: ProviderOptions;
4043
+ /**
4044
+ Maximum number of retries per embedding model call. Set to 0 to disable retries.
4045
+
4046
+ @default 2
4047
+ */
4048
+ maxRetries?: number;
4049
+ /**
4050
+ Abort signal.
3883
4051
  */
3884
- response: LanguageModelResponseMetadata;
4052
+ abortSignal?: AbortSignal;
3885
4053
  /**
3886
- Warnings from the model provider (e.g. unsupported settings).
3887
- */
3888
- warnings?: CallWarning[];
4054
+ Additional headers to include in the request.
4055
+ Only applicable for HTTP-based providers.
4056
+ */
4057
+ headers?: Record<string, string>;
4058
+ }): Promise<GenerateImageResult>;
4059
+
4060
+ /**
4061
+ The result of a `generateObject` call.
4062
+ */
4063
+ interface GenerateObjectResult<OBJECT> {
4064
+ /**
4065
+ The generated object (typed according to the schema).
4066
+ */
4067
+ readonly object: OBJECT;
4068
+ /**
4069
+ The reason why the generation finished.
4070
+ */
4071
+ readonly finishReason: FinishReason;
4072
+ /**
4073
+ The token usage of the generated text.
4074
+ */
4075
+ readonly usage: LanguageModelUsage;
4076
+ /**
4077
+ Warnings from the model provider (e.g. unsupported settings).
4078
+ */
4079
+ readonly warnings: CallWarning[] | undefined;
4080
+ /**
4081
+ Additional request information.
4082
+ */
4083
+ readonly request: LanguageModelRequestMetadata;
4084
+ /**
4085
+ Additional response information.
4086
+ */
4087
+ readonly response: LanguageModelResponseMetadata & {
4088
+ /**
4089
+ Response body (available only for providers that use HTTP requests).
4090
+ */
4091
+ body?: unknown;
4092
+ };
3889
4093
  /**
3890
4094
  Additional provider-specific metadata. They are passed through
3891
- to the provider from the AI SDK and enable provider-specific
3892
- functionality that can be fully encapsulated in the provider.
3893
- */
3894
- providerMetadata: ProviderMetadata | undefined;
3895
- }) => Promise<void> | void;
4095
+ from the provider to the AI SDK and enable provider-specific
4096
+ results that can be fully encapsulated in the provider.
4097
+ */
4098
+ readonly providerMetadata: ProviderMetadata | undefined;
4099
+ /**
4100
+ Converts the object to a JSON response.
4101
+ The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.
4102
+ */
4103
+ toJsonResponse(init?: ResponseInit): Response;
4104
+ }
4105
+
4106
+ /**
4107
+ A function that attempts to repair the raw output of the mode
4108
+ to enable JSON parsing.
4109
+
4110
+ Should return the repaired text or null if the text cannot be repaired.
4111
+ */
4112
+ type RepairTextFunction = (options: {
4113
+ text: string;
4114
+ error: JSONParseError | TypeValidationError;
4115
+ }) => Promise<string | null>;
3896
4116
  /**
3897
4117
  Generate a structured, typed object for a given prompt and schema using a language model.
3898
4118
 
3899
- This function streams the output. If you do not want to stream the output, use `generateObject` instead.
4119
+ This function does not stream the output. If you want to stream the output, use `streamObject` instead.
3900
4120
 
3901
4121
  @param model - The language model to use.
3902
4122
  @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
@@ -3945,6 +4165,9 @@ via tool or schema description.
3945
4165
  - 'enum': The output is an enum.
3946
4166
  - 'no-schema': The output is not a schema.
3947
4167
 
4168
+ @param experimental_repairText - A function that attempts to repair the raw output of the mode
4169
+ to enable JSON parsing.
4170
+
3948
4171
  @param experimental_telemetry - Optional telemetry configuration (experimental).
3949
4172
 
3950
4173
  @param providerOptions - Additional provider-specific options. They are passed through
@@ -3952,9 +4175,9 @@ to the provider from the AI SDK and enable provider-specific
3952
4175
  functionality that can be fully encapsulated in the provider.
3953
4176
 
3954
4177
  @returns
3955
- A result object for accessing the partial object stream and additional information.
4178
+ A result object that contains the generated object, the finish reason, the token usage, and additional information.
3956
4179
  */
3957
- declare function streamObject<SCHEMA extends z3.Schema | z4.$ZodType | Schema = z4.$ZodType<JSONValue$1>, OUTPUT extends 'object' | 'array' | 'enum' | 'no-schema' = InferSchema<SCHEMA> extends string ? 'enum' : 'object', RESULT = OUTPUT extends 'array' ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (OUTPUT extends 'enum' ? {
4180
+ declare function generateObject<SCHEMA extends z3.Schema | z4.$ZodType | Schema = z4.$ZodType<JSONValue$1>, OUTPUT extends 'object' | 'array' | 'enum' | 'no-schema' = InferSchema<SCHEMA> extends string ? 'enum' : 'object', RESULT = OUTPUT extends 'array' ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (OUTPUT extends 'enum' ? {
3958
4181
  /**
3959
4182
  The enum values that the model should use.
3960
4183
  */
@@ -3996,847 +4219,625 @@ Default and recommended: 'auto' (best mode for the model).
3996
4219
  output?: OUTPUT;
3997
4220
  /**
3998
4221
  The language model to use.
3999
- */
4222
+ */
4000
4223
  model: LanguageModel;
4001
4224
  /**
4002
- Optional telemetry configuration (experimental).
4225
+ A function that attempts to repair the raw output of the mode
4226
+ to enable JSON parsing.
4003
4227
  */
4228
+ experimental_repairText?: RepairTextFunction;
4229
+ /**
4230
+ Optional telemetry configuration (experimental).
4231
+ */
4004
4232
  experimental_telemetry?: TelemetrySettings;
4005
4233
  /**
4006
4234
  Additional provider-specific options. They are passed through
4007
4235
  to the provider from the AI SDK and enable provider-specific
4008
4236
  functionality that can be fully encapsulated in the provider.
4009
- */
4237
+ */
4010
4238
  providerOptions?: ProviderOptions;
4011
4239
  /**
4012
- Callback that is invoked when an error occurs during streaming.
4013
- You can use it to log errors.
4014
- The stream processing will pause until the callback promise is resolved.
4015
- */
4016
- onError?: StreamObjectOnErrorCallback;
4017
- /**
4018
- Callback that is called when the LLM response and the final object validation are finished.
4019
- */
4020
- onFinish?: StreamObjectOnFinishCallback<RESULT>;
4021
- /**
4022
4240
  * Internal. For test use only. May change without notice.
4023
4241
  */
4024
4242
  _internal?: {
4025
4243
  generateId?: () => string;
4026
4244
  currentDate?: () => Date;
4027
- now?: () => number;
4028
4245
  };
4029
- }): StreamObjectResult<OUTPUT extends 'enum' ? string : OUTPUT extends 'array' ? RESULT : DeepPartial<RESULT>, OUTPUT extends 'array' ? RESULT : RESULT, OUTPUT extends 'array' ? RESULT extends Array<infer U> ? AsyncIterableStream<U> : never : never>;
4030
-
4031
- /**
4032
- * A generated audio file.
4033
- */
4034
- interface GeneratedAudioFile extends GeneratedFile {
4035
- /**
4036
- * Audio format of the file (e.g., 'mp3', 'wav', etc.)
4037
- */
4038
- readonly format: string;
4039
- }
4246
+ }): Promise<GenerateObjectResult<RESULT>>;
4040
4247
 
4041
4248
  /**
4042
- The result of a `generateSpeech` call.
4043
- It contains the audio data and additional information.
4249
+ The result of a `streamObject` call that contains the partial object stream and additional information.
4044
4250
  */
4045
- interface SpeechResult {
4251
+ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
4046
4252
  /**
4047
- * The audio data as a base64 encoded string or binary data.
4048
- */
4049
- readonly audio: GeneratedAudioFile;
4253
+ Warnings from the model provider (e.g. unsupported settings)
4254
+ */
4255
+ readonly warnings: Promise<CallWarning[] | undefined>;
4050
4256
  /**
4051
- Warnings for the call, e.g. unsupported settings.
4257
+ The token usage of the generated response. Resolved when the response is finished.
4052
4258
  */
4053
- readonly warnings: Array<SpeechWarning>;
4259
+ readonly usage: Promise<LanguageModelUsage>;
4054
4260
  /**
4055
- Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
4261
+ Additional provider-specific metadata. They are passed through
4262
+ from the provider to the AI SDK and enable provider-specific
4263
+ results that can be fully encapsulated in the provider.
4056
4264
  */
4057
- readonly responses: Array<SpeechModelResponseMetadata>;
4265
+ readonly providerMetadata: Promise<ProviderMetadata | undefined>;
4058
4266
  /**
4059
- Provider metadata from the provider.
4060
- */
4061
- readonly providerMetadata: Record<string, Record<string, JSONValue$1>>;
4062
- }
4063
-
4064
- /**
4065
- Generates speech audio using a speech model.
4066
-
4067
- @param model - The speech model to use.
4068
- @param text - The text to convert to speech.
4069
- @param voice - The voice to use for speech generation.
4070
- @param outputFormat - The output format to use for speech generation e.g. "mp3", "wav", etc.
4071
- @param instructions - Instructions for the speech generation e.g. "Speak in a slow and steady tone".
4072
- @param speed - The speed of the speech generation.
4073
- @param providerOptions - Additional provider-specific options that are passed through to the provider
4074
- as body parameters.
4075
- @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
4076
- @param abortSignal - An optional abort signal that can be used to cancel the call.
4077
- @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
4078
-
4079
- @returns A result object that contains the generated audio data.
4080
- */
4081
- declare function generateSpeech({ model, text, voice, outputFormat, instructions, speed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
4267
+ Additional request information from the last step.
4268
+ */
4269
+ readonly request: Promise<LanguageModelRequestMetadata>;
4082
4270
  /**
4083
- The speech model to use.
4084
- */
4085
- model: SpeechModelV1;
4271
+ Additional response information.
4272
+ */
4273
+ readonly response: Promise<LanguageModelResponseMetadata>;
4086
4274
  /**
4087
- The text to convert to speech.
4088
- */
4089
- text: string;
4275
+ The generated object (typed according to the schema). Resolved when the response is finished.
4276
+ */
4277
+ readonly object: Promise<RESULT>;
4090
4278
  /**
4091
- The voice to use for speech generation.
4092
- */
4093
- voice?: string;
4279
+ Stream of partial objects. It gets more complete as the stream progresses.
4280
+
4281
+ Note that the partial object is not validated.
4282
+ If you want to be certain that the actual content matches your schema, you need to implement your own validation for partial results.
4283
+ */
4284
+ readonly partialObjectStream: AsyncIterableStream<PARTIAL>;
4094
4285
  /**
4095
- * The desired output format for the audio e.g. "mp3", "wav", etc.
4286
+ * Stream over complete array elements. Only available if the output strategy is set to `array`.
4096
4287
  */
4097
- outputFormat?: 'mp3' | 'wav' | (string & {});
4288
+ readonly elementStream: ELEMENT_STREAM;
4098
4289
  /**
4099
- Instructions for the speech generation e.g. "Speak in a slow and steady tone".
4100
- */
4101
- instructions?: string;
4290
+ Text stream of the JSON representation of the generated object. It contains text chunks.
4291
+ When the stream is finished, the object is valid JSON that can be parsed.
4292
+ */
4293
+ readonly textStream: AsyncIterableStream<string>;
4102
4294
  /**
4103
- The speed of the speech generation.
4104
- */
4105
- speed?: number;
4295
+ Stream of different types of events, including partial objects, errors, and finish events.
4296
+ Only errors that stop the stream, such as network errors, are thrown.
4297
+ */
4298
+ readonly fullStream: AsyncIterableStream<ObjectStreamPart<PARTIAL>>;
4106
4299
  /**
4107
- Additional provider-specific options that are passed through to the provider
4108
- as body parameters.
4300
+ Writes text delta output to a Node.js response-like object.
4301
+ It sets a `Content-Type` header to `text/plain; charset=utf-8` and
4302
+ writes each text delta as a separate chunk.
4109
4303
 
4110
- The outer record is keyed by the provider name, and the inner
4111
- record is keyed by the provider-specific metadata key.
4112
- ```ts
4113
- {
4114
- "openai": {}
4115
- }
4116
- ```
4304
+ @param response A Node.js response-like object (ServerResponse).
4305
+ @param init Optional headers, status code, and status text.
4117
4306
  */
4118
- providerOptions?: ProviderOptions;
4307
+ pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): void;
4119
4308
  /**
4120
- Maximum number of retries per speech model call. Set to 0 to disable retries.
4309
+ Creates a simple text stream response.
4310
+ The response has a `Content-Type` header set to `text/plain; charset=utf-8`.
4311
+ Each text delta is encoded as UTF-8 and sent as a separate chunk.
4312
+ Non-text-delta events are ignored.
4121
4313
 
4122
- @default 2
4123
- */
4124
- maxRetries?: number;
4125
- /**
4126
- Abort signal.
4127
- */
4128
- abortSignal?: AbortSignal;
4129
- /**
4130
- Additional headers to include in the request.
4131
- Only applicable for HTTP-based providers.
4132
- */
4133
- headers?: Record<string, string>;
4134
- }): Promise<SpeechResult>;
4135
-
4136
- /**
4137
- * Applies default settings for a language model.
4138
- */
4139
- declare function defaultSettingsMiddleware({ settings, }: {
4140
- settings: Partial<{
4141
- maxOutputTokens?: LanguageModelV2CallOptions['maxOutputTokens'];
4142
- temperature?: LanguageModelV2CallOptions['temperature'];
4143
- stopSequences?: LanguageModelV2CallOptions['stopSequences'];
4144
- topP?: LanguageModelV2CallOptions['topP'];
4145
- topK?: LanguageModelV2CallOptions['topK'];
4146
- presencePenalty?: LanguageModelV2CallOptions['presencePenalty'];
4147
- frequencyPenalty?: LanguageModelV2CallOptions['frequencyPenalty'];
4148
- responseFormat?: LanguageModelV2CallOptions['responseFormat'];
4149
- seed?: LanguageModelV2CallOptions['seed'];
4150
- tools?: LanguageModelV2CallOptions['tools'];
4151
- toolChoice?: LanguageModelV2CallOptions['toolChoice'];
4152
- headers?: LanguageModelV2CallOptions['headers'];
4153
- providerOptions?: LanguageModelV2CallOptions['providerOptions'];
4154
- }>;
4155
- }): LanguageModelV2Middleware;
4314
+ @param init Optional headers, status code, and status text.
4315
+ */
4316
+ toTextStreamResponse(init?: ResponseInit): Response;
4317
+ }
4318
+ type ObjectStreamPart<PARTIAL> = {
4319
+ type: 'object';
4320
+ object: PARTIAL;
4321
+ } | {
4322
+ type: 'text-delta';
4323
+ textDelta: string;
4324
+ } | {
4325
+ type: 'error';
4326
+ error: unknown;
4327
+ } | {
4328
+ type: 'finish';
4329
+ finishReason: FinishReason;
4330
+ usage: LanguageModelUsage;
4331
+ response: LanguageModelResponseMetadata;
4332
+ providerMetadata?: ProviderMetadata;
4333
+ };
4156
4334
 
4157
4335
  /**
4158
- * Extract an XML-tagged reasoning section from the generated text and exposes it
4159
- * as a `reasoning` property on the result.
4160
- *
4161
- * @param tagName - The name of the XML tag to extract reasoning from.
4162
- * @param separator - The separator to use between reasoning and text sections.
4163
- * @param startWithReasoning - Whether to start with reasoning tokens.
4164
- */
4165
- declare function extractReasoningMiddleware({ tagName, separator, startWithReasoning, }: {
4166
- tagName: string;
4167
- separator?: string;
4168
- startWithReasoning?: boolean;
4169
- }): LanguageModelV2Middleware;
4336
+ Callback that is set using the `onError` option.
4170
4337
 
4171
- /**
4172
- * Simulates streaming chunks with the response from a generate call.
4338
+ @param event - The event that is passed to the callback.
4173
4339
  */
4174
- declare function simulateStreamingMiddleware(): LanguageModelV2Middleware;
4175
-
4340
+ type StreamObjectOnErrorCallback = (event: {
4341
+ error: unknown;
4342
+ }) => Promise<void> | void;
4176
4343
  /**
4177
- * Wraps a LanguageModelV2 instance with middleware functionality.
4178
- * This function allows you to apply middleware to transform parameters,
4179
- * wrap generate operations, and wrap stream operations of a language model.
4180
- *
4181
- * @param options - Configuration options for wrapping the language model.
4182
- * @param options.model - The original LanguageModelV2 instance to be wrapped.
4183
- * @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.
4184
- * @param options.modelId - Optional custom model ID to override the original model's ID.
4185
- * @param options.providerId - Optional custom provider ID to override the original model's provider.
4186
- * @returns A new LanguageModelV2 instance with middleware applied.
4187
- */
4188
- declare const wrapLanguageModel: ({ model, middleware: middlewareArg, modelId, providerId, }: {
4189
- model: LanguageModelV2;
4190
- middleware: LanguageModelV2Middleware | LanguageModelV2Middleware[];
4191
- modelId?: string;
4192
- providerId?: string;
4193
- }) => LanguageModelV2;
4344
+ Callback that is set using the `onFinish` option.
4194
4345
 
4195
- /**
4196
- * Creates a custom provider with specified language models, text embedding models, and an optional fallback provider.
4197
- *
4198
- * @param {Object} options - The options for creating the custom provider.
4199
- * @param {Record<string, LanguageModel>} [options.languageModels] - A record of language models, where keys are model IDs and values are LanguageModel instances.
4200
- * @param {Record<string, EmbeddingModel<string>>} [options.textEmbeddingModels] - A record of text embedding models, where keys are model IDs and values are EmbeddingModel<string> instances.
4201
- * @param {Record<string, ImageModel>} [options.imageModels] - A record of image models, where keys are model IDs and values are ImageModel instances.
4202
- * @param {Provider} [options.fallbackProvider] - An optional fallback provider to use when a requested model is not found in the custom provider.
4203
- * @returns {Provider} A Provider object with languageModel, textEmbeddingModel, and imageModel methods.
4204
- *
4205
- * @throws {NoSuchModelError} Throws when a requested model is not found and no fallback provider is available.
4346
+ @param event - The event that is passed to the callback.
4206
4347
  */
4207
- declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageModelV2>, EMBEDDING_MODELS extends Record<string, EmbeddingModelV2<string>>, IMAGE_MODELS extends Record<string, ImageModelV2>>({ languageModels, textEmbeddingModels, imageModels, fallbackProvider, }: {
4208
- languageModels?: LANGUAGE_MODELS;
4209
- textEmbeddingModels?: EMBEDDING_MODELS;
4210
- imageModels?: IMAGE_MODELS;
4211
- fallbackProvider?: ProviderV2;
4212
- }): ProviderV2 & {
4213
- languageModel(modelId: ExtractModelId<LANGUAGE_MODELS>): LanguageModelV2;
4214
- textEmbeddingModel(modelId: ExtractModelId<EMBEDDING_MODELS>): EmbeddingModelV2<string>;
4215
- imageModel(modelId: ExtractModelId<IMAGE_MODELS>): ImageModelV2;
4216
- };
4348
+ type StreamObjectOnFinishCallback<RESULT> = (event: {
4349
+ /**
4350
+ The token usage of the generated response.
4351
+ */
4352
+ usage: LanguageModelUsage;
4353
+ /**
4354
+ The generated object. Can be undefined if the final object does not match the schema.
4355
+ */
4356
+ object: RESULT | undefined;
4357
+ /**
4358
+ Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema.
4359
+ */
4360
+ error: unknown | undefined;
4361
+ /**
4362
+ Response metadata.
4363
+ */
4364
+ response: LanguageModelResponseMetadata;
4365
+ /**
4366
+ Warnings from the model provider (e.g. unsupported settings).
4367
+ */
4368
+ warnings?: CallWarning[];
4369
+ /**
4370
+ Additional provider-specific metadata. They are passed through
4371
+ to the provider from the AI SDK and enable provider-specific
4372
+ functionality that can be fully encapsulated in the provider.
4373
+ */
4374
+ providerMetadata: ProviderMetadata | undefined;
4375
+ }) => Promise<void> | void;
4217
4376
  /**
4218
- * @deprecated Use `customProvider` instead.
4219
- */
4220
- declare const experimental_customProvider: typeof customProvider;
4221
- type ExtractModelId<MODELS extends Record<string, unknown>> = Extract<keyof MODELS, string>;
4377
+ Generate a structured, typed object for a given prompt and schema using a language model.
4222
4378
 
4223
- declare const symbol: unique symbol;
4224
- declare class NoSuchProviderError extends NoSuchModelError {
4225
- private readonly [symbol];
4226
- readonly providerId: string;
4227
- readonly availableProviders: string[];
4228
- constructor({ modelId, modelType, providerId, availableProviders, message, }: {
4229
- modelId: string;
4230
- modelType: 'languageModel' | 'textEmbeddingModel';
4231
- providerId: string;
4232
- availableProviders: string[];
4233
- message?: string;
4234
- });
4235
- static isInstance(error: unknown): error is NoSuchProviderError;
4236
- }
4379
+ This function streams the output. If you do not want to stream the output, use `generateObject` instead.
4237
4380
 
4238
- type ExtractLiteralUnion<T> = T extends string ? string extends T ? never : T : never;
4239
- interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV2> = Record<string, ProviderV2>, SEPARATOR extends string = ':'> {
4240
- languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['languageModel']>>[0]>}` : never): LanguageModelV2;
4241
- languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): LanguageModelV2;
4242
- textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['textEmbeddingModel']>>[0]>}` : never): EmbeddingModelV2<string>;
4243
- textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): EmbeddingModelV2<string>;
4244
- imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['imageModel']>>[0]>}` : never): ImageModelV2;
4245
- imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): ImageModelV2;
4246
- }
4247
- /**
4248
- * Creates a registry for the given providers.
4249
- */
4250
- declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV2>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, }?: {
4251
- separator?: SEPARATOR;
4252
- }): ProviderRegistryProvider<PROVIDERS, SEPARATOR>;
4253
- /**
4254
- * @deprecated Use `createProviderRegistry` instead.
4255
- */
4256
- declare const experimental_createProviderRegistry: typeof createProviderRegistry;
4381
+ @param model - The language model to use.
4382
+ @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
4257
4383
 
4258
- /**
4259
- The result of a `transcribe` call.
4260
- It contains the transcript and additional information.
4384
+ @param system - A system message that will be part of the prompt.
4385
+ @param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
4386
+ @param messages - A list of messages. You can either use `prompt` or `messages` but not both.
4387
+
4388
+ @param maxOutputTokens - Maximum number of tokens to generate.
4389
+ @param temperature - Temperature setting.
4390
+ The value is passed through to the provider. The range depends on the provider and model.
4391
+ It is recommended to set either `temperature` or `topP`, but not both.
4392
+ @param topP - Nucleus sampling.
4393
+ The value is passed through to the provider. The range depends on the provider and model.
4394
+ It is recommended to set either `temperature` or `topP`, but not both.
4395
+ @param topK - Only sample from the top K options for each subsequent token.
4396
+ Used to remove "long tail" low probability responses.
4397
+ Recommended for advanced use cases only. You usually only need to use temperature.
4398
+ @param presencePenalty - Presence penalty setting.
4399
+ It affects the likelihood of the model to repeat information that is already in the prompt.
4400
+ The value is passed through to the provider. The range depends on the provider and model.
4401
+ @param frequencyPenalty - Frequency penalty setting.
4402
+ It affects the likelihood of the model to repeatedly use the same words or phrases.
4403
+ The value is passed through to the provider. The range depends on the provider and model.
4404
+ @param stopSequences - Stop sequences.
4405
+ If set, the model will stop generating text when one of the stop sequences is generated.
4406
+ @param seed - The seed (integer) to use for random sampling.
4407
+ If set and supported by the model, calls will generate deterministic results.
4408
+
4409
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
4410
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
4411
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
4412
+
4413
+ @param schema - The schema of the object that the model should generate.
4414
+ @param schemaName - Optional name of the output that should be generated.
4415
+ Used by some providers for additional LLM guidance, e.g.
4416
+ via tool or schema name.
4417
+ @param schemaDescription - Optional description of the output that should be generated.
4418
+ Used by some providers for additional LLM guidance, e.g.
4419
+ via tool or schema description.
4420
+
4421
+ @param output - The type of the output.
4422
+
4423
+ - 'object': The output is an object.
4424
+ - 'array': The output is an array.
4425
+ - 'enum': The output is an enum.
4426
+ - 'no-schema': The output is not a schema.
4427
+
4428
+ @param experimental_telemetry - Optional telemetry configuration (experimental).
4429
+
4430
+ @param providerOptions - Additional provider-specific options. They are passed through
4431
+ to the provider from the AI SDK and enable provider-specific
4432
+ functionality that can be fully encapsulated in the provider.
4433
+
4434
+ @returns
4435
+ A result object for accessing the partial object stream and additional information.
4261
4436
  */
4262
- interface TranscriptionResult {
4263
- /**
4264
- * The complete transcribed text from the audio.
4265
- */
4266
- readonly text: string;
4267
- /**
4268
- * Array of transcript segments with timing information.
4269
- * Each segment represents a portion of the transcribed text with start and end times.
4270
- */
4271
- readonly segments: Array<{
4272
- /**
4273
- * The text content of this segment.
4274
- */
4275
- readonly text: string;
4276
- /**
4277
- * The start time of this segment in seconds.
4278
- */
4279
- readonly startSecond: number;
4280
- /**
4281
- * The end time of this segment in seconds.
4282
- */
4283
- readonly endSecond: number;
4284
- }>;
4437
+ declare function streamObject<SCHEMA extends z3.Schema | z4.$ZodType | Schema = z4.$ZodType<JSONValue$1>, OUTPUT extends 'object' | 'array' | 'enum' | 'no-schema' = InferSchema<SCHEMA> extends string ? 'enum' : 'object', RESULT = OUTPUT extends 'array' ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(options: Omit<CallSettings, 'stopSequences'> & Prompt & (OUTPUT extends 'enum' ? {
4285
4438
  /**
4286
- * The detected language of the audio content, as an ISO-639-1 code (e.g., 'en' for English).
4287
- * May be undefined if the language couldn't be detected.
4288
- */
4289
- readonly language: string | undefined;
4439
+ The enum values that the model should use.
4440
+ */
4441
+ enum: Array<RESULT>;
4442
+ mode?: 'json';
4443
+ output: 'enum';
4444
+ } : OUTPUT extends 'no-schema' ? {} : {
4290
4445
  /**
4291
- * The total duration of the audio file in seconds.
4292
- * May be undefined if the duration couldn't be determined.
4293
- */
4294
- readonly durationInSeconds: number | undefined;
4446
+ The schema of the object that the model should generate.
4447
+ */
4448
+ schema: SCHEMA;
4295
4449
  /**
4296
- Warnings for the call, e.g. unsupported settings.
4297
- */
4298
- readonly warnings: Array<TranscriptionWarning>;
4450
+ Optional name of the output that should be generated.
4451
+ Used by some providers for additional LLM guidance, e.g.
4452
+ via tool or schema name.
4453
+ */
4454
+ schemaName?: string;
4299
4455
  /**
4300
- Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
4301
- */
4302
- readonly responses: Array<TranscriptionModelResponseMetadata>;
4456
+ Optional description of the output that should be generated.
4457
+ Used by some providers for additional LLM guidance, e.g.
4458
+ via tool or schema description.
4459
+ */
4460
+ schemaDescription?: string;
4303
4461
  /**
4304
- Provider metadata from the provider.
4305
- */
4306
- readonly providerMetadata: Record<string, Record<string, JSONValue$1>>;
4307
- }
4462
+ The mode to use for object generation.
4308
4463
 
4309
- /**
4310
- Generates transcripts using a transcription model.
4464
+ The schema is converted into a JSON schema and used in one of the following ways
4311
4465
 
4312
- @param model - The transcription model to use.
4313
- @param audio - The audio data to transcribe as DataContent (string | Uint8Array | ArrayBuffer | Buffer) or a URL.
4314
- @param providerOptions - Additional provider-specific options that are passed through to the provider
4315
- as body parameters.
4316
- @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
4317
- @param abortSignal - An optional abort signal that can be used to cancel the call.
4318
- @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
4466
+ - 'auto': The provider will choose the best mode for the model.
4467
+ - 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
4468
+ - '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.
4319
4469
 
4320
- @returns A result object that contains the generated transcript.
4321
- */
4322
- declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
4470
+ Please note that most providers do not support all modes.
4471
+
4472
+ Default and recommended: 'auto' (best mode for the model).
4473
+ */
4474
+ mode?: 'auto' | 'json' | 'tool';
4475
+ }) & {
4476
+ output?: OUTPUT;
4323
4477
  /**
4324
- The transcription model to use.
4325
- */
4326
- model: TranscriptionModelV1;
4478
+ The language model to use.
4479
+ */
4480
+ model: LanguageModel;
4327
4481
  /**
4328
- The audio data to transcribe.
4482
+ Optional telemetry configuration (experimental).
4329
4483
  */
4330
- audio: DataContent | URL;
4484
+ experimental_telemetry?: TelemetrySettings;
4331
4485
  /**
4332
- Additional provider-specific options that are passed through to the provider
4333
- as body parameters.
4334
-
4335
- The outer record is keyed by the provider name, and the inner
4336
- record is keyed by the provider-specific metadata key.
4337
- ```ts
4338
- {
4339
- "openai": {
4340
- "temperature": 0
4341
- }
4342
- }
4343
- ```
4344
- */
4486
+ Additional provider-specific options. They are passed through
4487
+ to the provider from the AI SDK and enable provider-specific
4488
+ functionality that can be fully encapsulated in the provider.
4489
+ */
4345
4490
  providerOptions?: ProviderOptions;
4346
4491
  /**
4347
- Maximum number of retries per transcript model call. Set to 0 to disable retries.
4348
-
4349
- @default 2
4350
- */
4351
- maxRetries?: number;
4352
- /**
4353
- Abort signal.
4354
- */
4355
- abortSignal?: AbortSignal;
4356
- /**
4357
- Additional headers to include in the request.
4358
- Only applicable for HTTP-based providers.
4492
+ Callback that is invoked when an error occurs during streaming.
4493
+ You can use it to log errors.
4494
+ The stream processing will pause until the callback promise is resolved.
4359
4495
  */
4360
- headers?: Record<string, string>;
4361
- }): Promise<TranscriptionResult>;
4362
-
4363
- type DataUIMessageStreamPart = {
4364
- type: `data-${string}`;
4365
- id?: string;
4366
- data: unknown;
4367
- };
4368
- type UIMessageStreamPart = {
4369
- type: 'text';
4370
- text: string;
4371
- } | {
4372
- type: 'error';
4373
- errorText: string;
4374
- } | {
4375
- type: 'tool-call';
4376
- toolCallId: string;
4377
- toolName: string;
4378
- args: unknown;
4379
- } | {
4380
- type: 'tool-result';
4381
- toolCallId: string;
4382
- result: unknown;
4383
- providerMetadata?: ProviderMetadata;
4384
- } | {
4385
- type: 'tool-call-streaming-start';
4386
- toolCallId: string;
4387
- toolName: string;
4388
- } | {
4389
- type: 'tool-call-delta';
4390
- toolCallId: string;
4391
- argsTextDelta: string;
4392
- } | {
4393
- type: 'reasoning';
4394
- text: string;
4395
- providerMetadata?: ProviderMetadata;
4396
- } | {
4397
- type: 'source-url';
4398
- sourceId: string;
4399
- url: string;
4400
- title?: string;
4401
- providerMetadata?: ProviderMetadata;
4402
- } | {
4403
- type: 'source-document';
4404
- sourceId: string;
4405
- mediaType: string;
4406
- title: string;
4407
- filename?: string;
4408
- providerMetadata?: ProviderMetadata;
4409
- } | {
4410
- type: 'file';
4411
- url: string;
4412
- mediaType: string;
4413
- } | DataUIMessageStreamPart | {
4414
- type: 'metadata';
4415
- metadata: unknown;
4416
- } | {
4417
- type: 'start-step';
4418
- metadata?: unknown;
4419
- } | {
4420
- type: 'finish-step';
4421
- metadata?: unknown;
4422
- } | {
4423
- type: 'start';
4424
- messageId?: string;
4425
- metadata?: unknown;
4426
- } | {
4427
- type: 'finish';
4428
- metadata?: unknown;
4429
- } | {
4430
- type: 'reasoning-part-finish';
4431
- };
4432
-
4433
- interface UIMessageStreamWriter {
4434
- /**
4435
- * Appends a data stream part to the stream.
4436
- */
4437
- write(part: UIMessageStreamPart): void;
4496
+ onError?: StreamObjectOnErrorCallback;
4438
4497
  /**
4439
- * Merges the contents of another stream to this stream.
4440
- */
4441
- merge(stream: ReadableStream<UIMessageStreamPart>): void;
4498
+ Callback that is called when the LLM response and the final object validation are finished.
4499
+ */
4500
+ onFinish?: StreamObjectOnFinishCallback<RESULT>;
4442
4501
  /**
4443
- * Error handler that is used by the data stream writer.
4444
- * This is intended for forwarding when merging streams
4445
- * to prevent duplicated error masking.
4502
+ * Internal. For test use only. May change without notice.
4446
4503
  */
4447
- onError: ((error: unknown) => string) | undefined;
4448
- }
4504
+ _internal?: {
4505
+ generateId?: () => string;
4506
+ currentDate?: () => Date;
4507
+ now?: () => number;
4508
+ };
4509
+ }): StreamObjectResult<OUTPUT extends 'enum' ? string : OUTPUT extends 'array' ? RESULT : DeepPartial<RESULT>, OUTPUT extends 'array' ? RESULT : RESULT, OUTPUT extends 'array' ? RESULT extends Array<infer U> ? AsyncIterableStream<U> : never : never>;
4449
4510
 
4450
- declare function createUIMessageStream({ execute, onError, // mask error messages for safety by default
4451
- originalMessages, onFinish, }: {
4452
- execute: (options: {
4453
- writer: UIMessageStreamWriter;
4454
- }) => Promise<void> | void;
4455
- onError?: (error: unknown) => string;
4511
+ /**
4512
+ * A generated audio file.
4513
+ */
4514
+ interface GeneratedAudioFile extends GeneratedFile {
4456
4515
  /**
4457
- * The original messages.
4516
+ * Audio format of the file (e.g., 'mp3', 'wav', etc.)
4458
4517
  */
4459
- originalMessages?: UIMessage[];
4460
- onFinish?: (options: {
4461
- /**
4462
- * The updates list of UI messages.
4463
- */
4464
- messages: UIMessage[];
4465
- /**
4466
- * Indicates whether the response message is a continuation of the last original message,
4467
- * or if a new message was created.
4468
- */
4469
- isContinuation: boolean;
4470
- /**
4471
- * The message that was sent to the client as a response
4472
- * (including the original message if it was extended).
4473
- */
4474
- responseMessage: UIMessage;
4475
- }) => void;
4476
- }): ReadableStream<UIMessageStreamPart>;
4477
-
4478
- declare function createUIMessageStreamResponse({ status, statusText, headers, stream, }: ResponseInit & {
4479
- stream: ReadableStream<UIMessageStreamPart>;
4480
- }): Response;
4481
-
4482
- declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, }: {
4483
- response: ServerResponse;
4484
- stream: ReadableStream<UIMessageStreamPart>;
4485
- } & ResponseInit): void;
4486
-
4487
- declare class JsonToSseTransformStream extends TransformStream<unknown, string> {
4488
- constructor();
4489
- }
4490
-
4491
- interface ChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> {
4492
- submitMessages: (options: {
4493
- chatId: string;
4494
- messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4495
- abortSignal: AbortSignal | undefined;
4496
- requestType: 'generate' | 'resume';
4497
- } & ChatRequestOptions) => Promise<ReadableStream<UIMessageStreamPart>>;
4518
+ readonly format: string;
4498
4519
  }
4499
4520
 
4500
- type ChatRequestOptions = {
4501
- /**
4502
- Additional headers that should be to be passed to the API endpoint.
4503
- */
4504
- headers?: Record<string, string> | Headers;
4505
- /**
4506
- Additional body JSON properties that should be sent to the API endpoint.
4507
- */
4508
- body?: object;
4509
- metadata?: unknown;
4510
- };
4511
- interface ChatSubscriber {
4512
- onChange: (event: ChatEvent) => void;
4513
- }
4514
- interface ChatEvent {
4515
- type: 'messages-changed' | 'status-changed';
4516
- }
4517
- type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
4518
- interface ChatState<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> {
4519
- status: ChatStatus;
4520
- error: Error | undefined;
4521
- messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4522
- pushMessage: (message: UIMessage<MESSAGE_METADATA, DATA_TYPES>) => void;
4523
- popMessage: () => void;
4524
- replaceMessage: (index: number, message: UIMessage<MESSAGE_METADATA, DATA_TYPES>) => void;
4525
- snapshot: <T>(thing: T) => T;
4526
- }
4527
- interface ChatInit<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> {
4528
- /**
4529
- * A unique identifier for the chat. If not provided, a random one will be
4530
- * generated.
4531
- */
4532
- id?: string;
4533
- messageMetadataSchema?: Validator<MESSAGE_METADATA> | StandardSchemaV1<MESSAGE_METADATA>;
4534
- dataPartSchemas?: UI_DATA_PART_SCHEMAS;
4535
- messages?: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
4536
- /**
4537
- * A way to provide a function that is going to be used for ids for messages and the chat.
4538
- * If not provided the default AI SDK `generateId` is used.
4539
- */
4540
- generateId?: IdGenerator;
4541
- transport?: ChatTransport<NoInfer<MESSAGE_METADATA>, NoInfer<InferUIDataParts<UI_DATA_PART_SCHEMAS>>>;
4542
- maxSteps?: number;
4521
+ /**
4522
+ The result of a `generateSpeech` call.
4523
+ It contains the audio data and additional information.
4524
+ */
4525
+ interface SpeechResult {
4543
4526
  /**
4544
- * Callback function to be called when an error is encountered.
4527
+ * The audio data as a base64 encoded string or binary data.
4545
4528
  */
4546
- onError?: (error: Error) => void;
4529
+ readonly audio: GeneratedAudioFile;
4547
4530
  /**
4548
- Optional callback function that is invoked when a tool call is received.
4549
- Intended for automatic client-side tool execution.
4550
-
4551
- You can optionally return a result for the tool call,
4552
- either synchronously or asynchronously.
4531
+ Warnings for the call, e.g. unsupported settings.
4553
4532
  */
4554
- onToolCall?: ({ toolCall, }: {
4555
- toolCall: ToolCall<string, unknown>;
4556
- }) => void | Promise<unknown> | unknown;
4533
+ readonly warnings: Array<SpeechWarning>;
4557
4534
  /**
4558
- * Optional callback function that is called when the assistant message is finished streaming.
4559
- *
4560
- * @param message The message that was streamed.
4535
+ Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
4561
4536
  */
4562
- onFinish?: (options: {
4563
- message: UIMessage<NoInfer<MESSAGE_METADATA>, NoInfer<InferUIDataParts<UI_DATA_PART_SCHEMAS>>>;
4564
- }) => void;
4537
+ readonly responses: Array<SpeechModelResponseMetadata>;
4538
+ /**
4539
+ Provider metadata from the provider.
4540
+ */
4541
+ readonly providerMetadata: Record<string, Record<string, JSONValue$1>>;
4565
4542
  }
4566
- declare abstract class AbstractChat<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> {
4567
- readonly id: string;
4568
- readonly generateId: IdGenerator;
4569
- protected state: ChatState<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
4570
- private readonly subscribers;
4571
- private messageMetadataSchema;
4572
- private dataPartSchemas;
4573
- private readonly transport;
4574
- private maxSteps;
4575
- private onError?;
4576
- private onToolCall?;
4577
- private onFinish?;
4578
- private activeResponse;
4579
- private jobExecutor;
4580
- constructor({ generateId, id, transport, maxSteps, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, }: Omit<ChatInit<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS>, 'messages'> & {
4581
- state: ChatState<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
4582
- });
4543
+
4544
+ /**
4545
+ Generates speech audio using a speech model.
4546
+
4547
+ @param model - The speech model to use.
4548
+ @param text - The text to convert to speech.
4549
+ @param voice - The voice to use for speech generation.
4550
+ @param outputFormat - The output format to use for speech generation e.g. "mp3", "wav", etc.
4551
+ @param instructions - Instructions for the speech generation e.g. "Speak in a slow and steady tone".
4552
+ @param speed - The speed of the speech generation.
4553
+ @param providerOptions - Additional provider-specific options that are passed through to the provider
4554
+ as body parameters.
4555
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
4556
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
4557
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
4558
+
4559
+ @returns A result object that contains the generated audio data.
4560
+ */
4561
+ declare function generateSpeech({ model, text, voice, outputFormat, instructions, speed, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
4583
4562
  /**
4584
- * Hook status:
4585
- *
4586
- * - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.
4587
- * - `streaming`: The response is actively streaming in from the API, receiving chunks of data.
4588
- * - `ready`: The full response has been received and processed; a new user message can be submitted.
4589
- * - `error`: An error occurred during the API request, preventing successful completion.
4563
+ The speech model to use.
4564
+ */
4565
+ model: SpeechModelV1;
4566
+ /**
4567
+ The text to convert to speech.
4590
4568
  */
4591
- get status(): ChatStatus;
4592
- protected setStatus({ status, error, }: {
4593
- status: ChatStatus;
4594
- error?: Error;
4595
- }): void;
4596
- get error(): Error | undefined;
4597
- get messages(): UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
4598
- get lastMessage(): UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>> | undefined;
4599
- subscribe(subscriber: ChatSubscriber): () => void;
4600
- set messages(messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[]);
4601
- removeAssistantResponse: () => void;
4569
+ text: string;
4602
4570
  /**
4603
- * Append a user message to the chat list. This triggers the API call to fetch
4604
- * the assistant's response.
4571
+ The voice to use for speech generation.
4605
4572
  */
4606
- sendMessage: (message: (CreateUIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>> & {
4607
- text?: never;
4608
- files?: never;
4609
- }) | {
4610
- text: string;
4611
- files?: FileList | FileUIPart[];
4612
- metadata?: MESSAGE_METADATA;
4613
- parts?: never;
4614
- } | {
4615
- files: FileList | FileUIPart[];
4616
- metadata?: MESSAGE_METADATA;
4617
- parts?: never;
4618
- }, options?: ChatRequestOptions) => Promise<void>;
4573
+ voice?: string;
4619
4574
  /**
4620
- * Regenerate the last assistant message.
4575
+ * The desired output format for the audio e.g. "mp3", "wav", etc.
4621
4576
  */
4622
- reload: (options?: ChatRequestOptions) => Promise<void>;
4577
+ outputFormat?: 'mp3' | 'wav' | (string & {});
4623
4578
  /**
4624
- * Resume an ongoing chat generation stream. This does not resume an aborted generation.
4579
+ Instructions for the speech generation e.g. "Speak in a slow and steady tone".
4580
+ */
4581
+ instructions?: string;
4582
+ /**
4583
+ The speed of the speech generation.
4625
4584
  */
4626
- experimental_resume: (options?: ChatRequestOptions) => Promise<void>;
4627
- addToolResult: ({ toolCallId, result, }: {
4628
- toolCallId: string;
4629
- result: unknown;
4630
- }) => Promise<void>;
4585
+ speed?: number;
4631
4586
  /**
4632
- * Abort the current request immediately, keep the generated tokens if any.
4587
+ Additional provider-specific options that are passed through to the provider
4588
+ as body parameters.
4589
+
4590
+ The outer record is keyed by the provider name, and the inner
4591
+ record is keyed by the provider-specific metadata key.
4592
+ ```ts
4593
+ {
4594
+ "openai": {}
4595
+ }
4596
+ ```
4597
+ */
4598
+ providerOptions?: ProviderOptions;
4599
+ /**
4600
+ Maximum number of retries per speech model call. Set to 0 to disable retries.
4601
+
4602
+ @default 2
4633
4603
  */
4634
- stop: () => Promise<void>;
4635
- private emit;
4636
- private triggerRequest;
4637
- }
4638
-
4639
- declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
4604
+ maxRetries?: number;
4605
+ /**
4606
+ Abort signal.
4607
+ */
4608
+ abortSignal?: AbortSignal;
4609
+ /**
4610
+ Additional headers to include in the request.
4611
+ Only applicable for HTTP-based providers.
4612
+ */
4613
+ headers?: Record<string, string>;
4614
+ }): Promise<SpeechResult>;
4640
4615
 
4641
4616
  /**
4642
- Converts an array of messages from useChat into an array of CoreMessages that can be used
4643
- with the AI core functions (e.g. `streamText`).
4617
+ * Applies default settings for a language model.
4644
4618
  */
4645
- declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<UIMessage, 'id'>>, options?: {
4646
- tools?: TOOLS;
4647
- }): ModelMessage[];
4619
+ declare function defaultSettingsMiddleware({ settings, }: {
4620
+ settings: Partial<{
4621
+ maxOutputTokens?: LanguageModelV2CallOptions['maxOutputTokens'];
4622
+ temperature?: LanguageModelV2CallOptions['temperature'];
4623
+ stopSequences?: LanguageModelV2CallOptions['stopSequences'];
4624
+ topP?: LanguageModelV2CallOptions['topP'];
4625
+ topK?: LanguageModelV2CallOptions['topK'];
4626
+ presencePenalty?: LanguageModelV2CallOptions['presencePenalty'];
4627
+ frequencyPenalty?: LanguageModelV2CallOptions['frequencyPenalty'];
4628
+ responseFormat?: LanguageModelV2CallOptions['responseFormat'];
4629
+ seed?: LanguageModelV2CallOptions['seed'];
4630
+ tools?: LanguageModelV2CallOptions['tools'];
4631
+ toolChoice?: LanguageModelV2CallOptions['toolChoice'];
4632
+ headers?: LanguageModelV2CallOptions['headers'];
4633
+ providerOptions?: LanguageModelV2CallOptions['providerOptions'];
4634
+ }>;
4635
+ }): LanguageModelV2Middleware;
4636
+
4648
4637
  /**
4649
- @deprecated Use `convertToModelMessages` instead.
4638
+ * Extract an XML-tagged reasoning section from the generated text and exposes it
4639
+ * as a `reasoning` property on the result.
4640
+ *
4641
+ * @param tagName - The name of the XML tag to extract reasoning from.
4642
+ * @param separator - The separator to use between reasoning and text sections.
4643
+ * @param startWithReasoning - Whether to start with reasoning tokens.
4650
4644
  */
4651
- declare const convertToCoreMessages: typeof convertToModelMessages;
4645
+ declare function extractReasoningMiddleware({ tagName, separator, startWithReasoning, }: {
4646
+ tagName: string;
4647
+ separator?: string;
4648
+ startWithReasoning?: boolean;
4649
+ }): LanguageModelV2Middleware;
4652
4650
 
4653
- type PrepareRequest<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> = (options: {
4654
- id: string;
4655
- messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4656
- requestMetadata: unknown;
4657
- body: Record<string, any> | undefined;
4658
- credentials: RequestCredentials | undefined;
4659
- headers: HeadersInit | undefined;
4660
- }) => {
4661
- body: object;
4662
- headers?: HeadersInit;
4663
- credentials?: RequestCredentials;
4664
- };
4651
+ /**
4652
+ * Simulates streaming chunks with the response from a generate call.
4653
+ */
4654
+ declare function simulateStreamingMiddleware(): LanguageModelV2Middleware;
4665
4655
 
4666
- declare class DefaultChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> implements ChatTransport<MESSAGE_METADATA, DATA_TYPES> {
4667
- private api;
4668
- private credentials?;
4669
- private headers?;
4670
- private body?;
4671
- private fetch?;
4672
- private prepareRequest?;
4673
- constructor({ api, credentials, headers, body, fetch, prepareRequest, }?: {
4674
- api?: string;
4675
- /**
4676
- * The credentials mode to be used for the fetch request.
4677
- * Possible values are: 'omit', 'same-origin', 'include'.
4678
- * Defaults to 'same-origin'.
4679
- */
4680
- credentials?: RequestCredentials;
4681
- /**
4682
- * HTTP headers to be sent with the API request.
4683
- */
4684
- headers?: Record<string, string> | Headers;
4685
- /**
4686
- * Extra body object to be sent with the API request.
4687
- * @example
4688
- * Send a `sessionId` to the API along with the messages.
4689
- * ```js
4690
- * useChat({
4691
- * body: {
4692
- * sessionId: '123',
4693
- * }
4694
- * })
4695
- * ```
4696
- */
4697
- body?: object;
4698
- /**
4699
- Custom fetch implementation. You can use it as a middleware to intercept requests,
4700
- or to provide a custom fetch implementation for e.g. testing.
4701
- */
4702
- fetch?: FetchFunction;
4703
- /**
4704
- * When a function is provided, it will be used
4705
- * to prepare the request body for the chat API. This can be useful for
4706
- * customizing the request body based on the messages and data in the chat.
4707
- *
4708
- * @param id The id of the chat.
4709
- * @param messages The current messages in the chat.
4710
- * @param requestBody The request body object passed in the chat request.
4711
- */
4712
- prepareRequest?: PrepareRequest<MESSAGE_METADATA, DATA_TYPES>;
4656
+ /**
4657
+ * Wraps a LanguageModelV2 instance with middleware functionality.
4658
+ * This function allows you to apply middleware to transform parameters,
4659
+ * wrap generate operations, and wrap stream operations of a language model.
4660
+ *
4661
+ * @param options - Configuration options for wrapping the language model.
4662
+ * @param options.model - The original LanguageModelV2 instance to be wrapped.
4663
+ * @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.
4664
+ * @param options.modelId - Optional custom model ID to override the original model's ID.
4665
+ * @param options.providerId - Optional custom provider ID to override the original model's provider.
4666
+ * @returns A new LanguageModelV2 instance with middleware applied.
4667
+ */
4668
+ declare const wrapLanguageModel: ({ model, middleware: middlewareArg, modelId, providerId, }: {
4669
+ model: LanguageModelV2;
4670
+ middleware: LanguageModelV2Middleware | LanguageModelV2Middleware[];
4671
+ modelId?: string;
4672
+ providerId?: string;
4673
+ }) => LanguageModelV2;
4674
+
4675
+ /**
4676
+ * Creates a custom provider with specified language models, text embedding models, and an optional fallback provider.
4677
+ *
4678
+ * @param {Object} options - The options for creating the custom provider.
4679
+ * @param {Record<string, LanguageModel>} [options.languageModels] - A record of language models, where keys are model IDs and values are LanguageModel instances.
4680
+ * @param {Record<string, EmbeddingModel<string>>} [options.textEmbeddingModels] - A record of text embedding models, where keys are model IDs and values are EmbeddingModel<string> instances.
4681
+ * @param {Record<string, ImageModel>} [options.imageModels] - A record of image models, where keys are model IDs and values are ImageModel instances.
4682
+ * @param {Provider} [options.fallbackProvider] - An optional fallback provider to use when a requested model is not found in the custom provider.
4683
+ * @returns {Provider} A Provider object with languageModel, textEmbeddingModel, and imageModel methods.
4684
+ *
4685
+ * @throws {NoSuchModelError} Throws when a requested model is not found and no fallback provider is available.
4686
+ */
4687
+ declare function customProvider<LANGUAGE_MODELS extends Record<string, LanguageModelV2>, EMBEDDING_MODELS extends Record<string, EmbeddingModelV2<string>>, IMAGE_MODELS extends Record<string, ImageModelV2>>({ languageModels, textEmbeddingModels, imageModels, fallbackProvider, }: {
4688
+ languageModels?: LANGUAGE_MODELS;
4689
+ textEmbeddingModels?: EMBEDDING_MODELS;
4690
+ imageModels?: IMAGE_MODELS;
4691
+ fallbackProvider?: ProviderV2;
4692
+ }): ProviderV2 & {
4693
+ languageModel(modelId: ExtractModelId<LANGUAGE_MODELS>): LanguageModelV2;
4694
+ textEmbeddingModel(modelId: ExtractModelId<EMBEDDING_MODELS>): EmbeddingModelV2<string>;
4695
+ imageModel(modelId: ExtractModelId<IMAGE_MODELS>): ImageModelV2;
4696
+ };
4697
+ /**
4698
+ * @deprecated Use `customProvider` instead.
4699
+ */
4700
+ declare const experimental_customProvider: typeof customProvider;
4701
+ type ExtractModelId<MODELS extends Record<string, unknown>> = Extract<keyof MODELS, string>;
4702
+
4703
+ declare const symbol: unique symbol;
4704
+ declare class NoSuchProviderError extends NoSuchModelError {
4705
+ private readonly [symbol];
4706
+ readonly providerId: string;
4707
+ readonly availableProviders: string[];
4708
+ constructor({ modelId, modelType, providerId, availableProviders, message, }: {
4709
+ modelId: string;
4710
+ modelType: 'languageModel' | 'textEmbeddingModel';
4711
+ providerId: string;
4712
+ availableProviders: string[];
4713
+ message?: string;
4713
4714
  });
4714
- submitMessages({ chatId, messages, abortSignal, metadata, headers, body, requestType, }: Parameters<ChatTransport<MESSAGE_METADATA, DATA_TYPES>['submitMessages']>[0]): Promise<ReadableStream<UIMessageStreamPart>>;
4715
+ static isInstance(error: unknown): error is NoSuchProviderError;
4715
4716
  }
4716
4717
 
4717
- declare function getToolInvocations(message: UIMessage): ToolInvocation[];
4718
+ type ExtractLiteralUnion<T> = T extends string ? string extends T ? never : T : never;
4719
+ interface ProviderRegistryProvider<PROVIDERS extends Record<string, ProviderV2> = Record<string, ProviderV2>, SEPARATOR extends string = ':'> {
4720
+ languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['languageModel']>>[0]>}` : never): LanguageModelV2;
4721
+ languageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): LanguageModelV2;
4722
+ textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['textEmbeddingModel']>>[0]>}` : never): EmbeddingModelV2<string>;
4723
+ textEmbeddingModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): EmbeddingModelV2<string>;
4724
+ imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${ExtractLiteralUnion<Parameters<NonNullable<PROVIDERS[KEY]['imageModel']>>[0]>}` : never): ImageModelV2;
4725
+ imageModel<KEY extends keyof PROVIDERS>(id: KEY extends string ? `${KEY & string}${SEPARATOR}${string}` : never): ImageModelV2;
4726
+ }
4727
+ /**
4728
+ * Creates a registry for the given providers.
4729
+ */
4730
+ declare function createProviderRegistry<PROVIDERS extends Record<string, ProviderV2>, SEPARATOR extends string = ':'>(providers: PROVIDERS, { separator, }?: {
4731
+ separator?: SEPARATOR;
4732
+ }): ProviderRegistryProvider<PROVIDERS, SEPARATOR>;
4733
+ /**
4734
+ * @deprecated Use `createProviderRegistry` instead.
4735
+ */
4736
+ declare const experimental_createProviderRegistry: typeof createProviderRegistry;
4718
4737
 
4719
- declare class TextStreamChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> implements ChatTransport<MESSAGE_METADATA, DATA_TYPES> {
4720
- private api;
4721
- private credentials?;
4722
- private headers?;
4723
- private body?;
4724
- private fetch?;
4725
- private prepareRequest?;
4726
- constructor({ api, credentials, headers, body, fetch, prepareRequest, }: {
4727
- api: string;
4728
- /**
4729
- * The credentials mode to be used for the fetch request.
4730
- * Possible values are: 'omit', 'same-origin', 'include'.
4731
- * Defaults to 'same-origin'.
4732
- */
4733
- credentials?: RequestCredentials;
4738
+ /**
4739
+ The result of a `transcribe` call.
4740
+ It contains the transcript and additional information.
4741
+ */
4742
+ interface TranscriptionResult {
4743
+ /**
4744
+ * The complete transcribed text from the audio.
4745
+ */
4746
+ readonly text: string;
4747
+ /**
4748
+ * Array of transcript segments with timing information.
4749
+ * Each segment represents a portion of the transcribed text with start and end times.
4750
+ */
4751
+ readonly segments: Array<{
4734
4752
  /**
4735
- * HTTP headers to be sent with the API request.
4753
+ * The text content of this segment.
4736
4754
  */
4737
- headers?: Record<string, string> | Headers;
4755
+ readonly text: string;
4738
4756
  /**
4739
- * Extra body object to be sent with the API request.
4740
- * @example
4741
- * Send a `sessionId` to the API along with the messages.
4742
- * ```js
4743
- * useChat({
4744
- * body: {
4745
- * sessionId: '123',
4746
- * }
4747
- * })
4748
- * ```
4757
+ * The start time of this segment in seconds.
4749
4758
  */
4750
- body?: object;
4751
- /**
4752
- Custom fetch implementation. You can use it as a middleware to intercept requests,
4753
- or to provide a custom fetch implementation for e.g. testing.
4754
- */
4755
- fetch?: FetchFunction;
4759
+ readonly startSecond: number;
4756
4760
  /**
4757
- * When a function is provided, it will be used
4758
- * to prepare the request body for the chat API. This can be useful for
4759
- * customizing the request body based on the messages and data in the chat.
4760
- *
4761
- * @param id The id of the chat.
4762
- * @param messages The current messages in the chat.
4763
- * @param requestBody The request body object passed in the chat request.
4761
+ * The end time of this segment in seconds.
4764
4762
  */
4765
- prepareRequest?: NoInfer<PrepareRequest<MESSAGE_METADATA, DATA_TYPES>>;
4766
- });
4767
- submitMessages({ chatId, messages, abortSignal, metadata, headers, body, requestType, }: Parameters<ChatTransport<MESSAGE_METADATA, DATA_TYPES>['submitMessages']>[0]): Promise<ReadableStream<UIMessageStreamPart>>;
4768
- }
4769
-
4770
- type CompletionRequestOptions = {
4771
- /**
4772
- An optional object of headers to be passed to the API endpoint.
4773
- */
4774
- headers?: Record<string, string> | Headers;
4775
- /**
4776
- An optional object to be passed to the API endpoint.
4777
- */
4778
- body?: object;
4779
- };
4780
- type UseCompletionOptions = {
4763
+ readonly endSecond: number;
4764
+ }>;
4781
4765
  /**
4782
- * The API endpoint that accepts a `{ prompt: string }` object and returns
4783
- * a stream of tokens of the AI completion response. Defaults to `/api/completion`.
4766
+ * The detected language of the audio content, as an ISO-639-1 code (e.g., 'en' for English).
4767
+ * May be undefined if the language couldn't be detected.
4784
4768
  */
4785
- api?: string;
4769
+ readonly language: string | undefined;
4786
4770
  /**
4787
- * An unique identifier for the chat. If not provided, a random one will be
4788
- * generated. When provided, the `useChat` hook with the same `id` will
4789
- * have shared states across components.
4771
+ * The total duration of the audio file in seconds.
4772
+ * May be undefined if the duration couldn't be determined.
4790
4773
  */
4791
- id?: string;
4774
+ readonly durationInSeconds: number | undefined;
4792
4775
  /**
4793
- * Initial prompt input of the completion.
4794
- */
4795
- initialInput?: string;
4776
+ Warnings for the call, e.g. unsupported settings.
4777
+ */
4778
+ readonly warnings: Array<TranscriptionWarning>;
4796
4779
  /**
4797
- * Initial completion result. Useful to load an existing history.
4780
+ Response metadata from the provider. There may be multiple responses if we made multiple calls to the model.
4798
4781
  */
4799
- initialCompletion?: string;
4782
+ readonly responses: Array<TranscriptionModelResponseMetadata>;
4800
4783
  /**
4801
- * Callback function to be called when the completion is finished streaming.
4784
+ Provider metadata from the provider.
4802
4785
  */
4803
- onFinish?: (prompt: string, completion: string) => void;
4786
+ readonly providerMetadata: Record<string, Record<string, JSONValue$1>>;
4787
+ }
4788
+
4789
+ /**
4790
+ Generates transcripts using a transcription model.
4791
+
4792
+ @param model - The transcription model to use.
4793
+ @param audio - The audio data to transcribe as DataContent (string | Uint8Array | ArrayBuffer | Buffer) or a URL.
4794
+ @param providerOptions - Additional provider-specific options that are passed through to the provider
4795
+ as body parameters.
4796
+ @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
4797
+ @param abortSignal - An optional abort signal that can be used to cancel the call.
4798
+ @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
4799
+
4800
+ @returns A result object that contains the generated transcript.
4801
+ */
4802
+ declare function transcribe({ model, audio, providerOptions, maxRetries: maxRetriesArg, abortSignal, headers, }: {
4804
4803
  /**
4805
- * Callback function to be called when an error is encountered.
4806
- */
4807
- onError?: (error: Error) => void;
4804
+ The transcription model to use.
4805
+ */
4806
+ model: TranscriptionModelV1;
4808
4807
  /**
4809
- * The credentials mode to be used for the fetch request.
4810
- * Possible values are: 'omit', 'same-origin', 'include'.
4811
- * Defaults to 'same-origin'.
4808
+ The audio data to transcribe.
4812
4809
  */
4813
- credentials?: RequestCredentials;
4810
+ audio: DataContent | URL;
4814
4811
  /**
4815
- * HTTP headers to be sent with the API request.
4816
- */
4817
- headers?: Record<string, string> | Headers;
4812
+ Additional provider-specific options that are passed through to the provider
4813
+ as body parameters.
4814
+
4815
+ The outer record is keyed by the provider name, and the inner
4816
+ record is keyed by the provider-specific metadata key.
4817
+ ```ts
4818
+ {
4819
+ "openai": {
4820
+ "temperature": 0
4821
+ }
4822
+ }
4823
+ ```
4824
+ */
4825
+ providerOptions?: ProviderOptions;
4818
4826
  /**
4819
- * Extra body object to be sent with the API request.
4820
- * @example
4821
- * Send a `sessionId` to the API along with the prompt.
4822
- * ```js
4823
- * useChat({
4824
- * body: {
4825
- * sessionId: '123',
4826
- * }
4827
- * })
4828
- * ```
4827
+ Maximum number of retries per transcript model call. Set to 0 to disable retries.
4828
+
4829
+ @default 2
4829
4830
  */
4830
- body?: object;
4831
+ maxRetries?: number;
4831
4832
  /**
4832
- Streaming protocol that is used. Defaults to `data`.
4833
- */
4834
- streamProtocol?: 'data' | 'text';
4833
+ Abort signal.
4834
+ */
4835
+ abortSignal?: AbortSignal;
4835
4836
  /**
4836
- Custom fetch implementation. You can use it as a middleware to intercept requests,
4837
- or to provide a custom fetch implementation for e.g. testing.
4838
- */
4839
- fetch?: FetchFunction;
4840
- };
4837
+ Additional headers to include in the request.
4838
+ Only applicable for HTTP-based providers.
4839
+ */
4840
+ headers?: Record<string, string>;
4841
+ }): Promise<TranscriptionResult>;
4841
4842
 
4842
- export { AbstractChat, AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatEvent, ChatInit, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GLOBAL_DEFAULT_PROVIDER, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InferUIDataParts, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, ModelMessage, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SerialJobExecutor, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamChatTransport, TextStreamPart, TextUIPart, Tool, ToolCallOptions, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessagePart, UIMessageStreamOptions, UIMessageStreamPart, UIMessageStreamWriter, UseCompletionOptions, UserContent, UserModelMessage, assistantModelMessageSchema, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolInvocations, hasToolCall, isDeepEqualData, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, userModelMessageSchema, wrapLanguageModel };
4843
+ export { AbstractChat, AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatInit, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DataUIPart, DeepPartial, DefaultChatTransport, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelUsage, GenerateImageResult as Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FilePart, FileUIPart, FinishReason, GLOBAL_DEFAULT_PROVIDER, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InferUIDataParts, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolArgumentsError, JSONRPCError, JSONRPCMessage, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, MCPClientError, MCPTransport, MessageConversionError, ModelMessage, NoImageGeneratedError, NoObjectGeneratedError, NoOutputSpecifiedError, NoSuchProviderError, NoSuchToolError, ObjectStreamPart, output as Output, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SerialJobExecutor, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamChatTransport, TextStreamPart, TextUIPart, Tool, ToolCallOptions, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessagePart, UIMessageStreamOptions, UIMessageStreamPart, UIMessageStreamWriter, UseCompletionOptions, UserContent, UserModelMessage, assistantModelMessageSchema, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolInvocations, hasToolCall, isDeepEqualData, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, userModelMessageSchema, wrapLanguageModel };