ai 5.0.0-alpha.1 → 5.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # ai
2
2
 
3
+ ## 5.0.0-alpha.3
4
+
5
+ ### Major Changes
6
+
7
+ - ab7ccef: chore (ai): change source ui message parts to source-url
8
+ - 257224b: chore (ai): separate TextStreamChatTransport
9
+ - 0463011: fix (ai): update source url stream part
10
+ - d306260: feat (ai): replace maxSteps with continueUntil (streamText)
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [6b98118]
15
+ - @ai-sdk/provider@2.0.0-alpha.3
16
+ - @ai-sdk/provider-utils@3.0.0-alpha.3
17
+
18
+ ## 5.0.0-alpha.2
19
+
20
+ ### Patch Changes
21
+
22
+ - 82aa95d: fix (ai): merge data ui stream parts correctly
23
+ - Updated dependencies [26535e0]
24
+ - @ai-sdk/provider@2.0.0-alpha.2
25
+ - @ai-sdk/provider-utils@3.0.0-alpha.2
26
+
3
27
  ## 5.0.0-alpha.1
4
28
 
5
29
  ### Major Changes
package/dist/index.d.mts CHANGED
@@ -2154,7 +2154,7 @@ interface UIMessage<METADATA = unknown, DATA_PARTS extends UIDataTypes = UIDataT
2154
2154
  */
2155
2155
  parts: Array<UIMessagePart<DATA_PARTS>>;
2156
2156
  }
2157
- type UIMessagePart<DATA_TYPES extends UIDataTypes> = TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | DataUIPart<DATA_TYPES> | StepStartUIPart;
2157
+ type UIMessagePart<DATA_TYPES extends UIDataTypes> = TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUrlUIPart | FileUIPart | DataUIPart<DATA_TYPES> | StepStartUIPart;
2158
2158
  type DataUIPart<DATA_TYPES extends UIDataTypes> = ValueOf<{
2159
2159
  [NAME in keyof DATA_TYPES & string]: {
2160
2160
  type: `data-${NAME}`;
@@ -2199,18 +2199,12 @@ type ToolInvocationUIPart = {
2199
2199
  /**
2200
2200
  * A source part of a message.
2201
2201
  */
2202
- type SourceUIPart = {
2203
- type: 'source';
2204
- /**
2205
- * The source.
2206
- */
2207
- source: {
2208
- sourceType: 'url';
2209
- id: string;
2210
- url: string;
2211
- title?: string;
2212
- providerMetadata?: Record<string, any>;
2213
- };
2202
+ type SourceUrlUIPart = {
2203
+ type: 'source-url';
2204
+ sourceId: string;
2205
+ url: string;
2206
+ title?: string;
2207
+ providerMetadata?: Record<string, any>;
2214
2208
  };
2215
2209
  /**
2216
2210
  * A file part of a message.
@@ -3247,7 +3241,7 @@ If set and supported by the model, calls will generate deterministic results.
3247
3241
  @return
3248
3242
  A result object for accessing different stream types and additional information.
3249
3243
  */
3250
- declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxSteps, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_toolCallStreaming, toolCallStreaming, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, onChunk, onError, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
3244
+ declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, continueUntil, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_toolCallStreaming, toolCallStreaming, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, onChunk, onError, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
3251
3245
  /**
3252
3246
  The language model to use.
3253
3247
  */
@@ -3260,14 +3254,7 @@ The tools that the model can call. The model needs to support calling tools.
3260
3254
  The tool choice strategy. Default: 'auto'.
3261
3255
  */
3262
3256
  toolChoice?: ToolChoice<TOOLS>;
3263
- /**
3264
- Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
3265
-
3266
- A maximum number is required to prevent infinite loops in the case of misconfigured tools.
3267
-
3268
- By default, it's set to 1, which means that only a single LLM call is made.
3269
- */
3270
- maxSteps?: number;
3257
+ continueUntil?: StopCondition<NoInfer<TOOLS>>;
3271
3258
  /**
3272
3259
  Optional telemetry configuration (experimental).
3273
3260
  */
@@ -4311,9 +4298,8 @@ type UIMessageStreamPart = {
4311
4298
  text: string;
4312
4299
  providerMetadata?: ProviderMetadata;
4313
4300
  } | {
4314
- type: 'source';
4315
- sourceType: 'url';
4316
- id: string;
4301
+ type: 'source-url';
4302
+ sourceId: string;
4317
4303
  url: string;
4318
4304
  title?: string;
4319
4305
  providerMetadata?: ProviderMetadata;
@@ -4400,10 +4386,9 @@ declare class DefaultChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTy
4400
4386
  private credentials?;
4401
4387
  private headers?;
4402
4388
  private body?;
4403
- private streamProtocol?;
4404
4389
  private fetch?;
4405
4390
  private prepareRequestBody?;
4406
- constructor({ api, credentials, headers, body, streamProtocol, fetch, prepareRequestBody, }: {
4391
+ constructor({ api, credentials, headers, body, fetch, prepareRequestBody, }: {
4407
4392
  api: string;
4408
4393
  /**
4409
4394
  * The credentials mode to be used for the fetch request.
@@ -4429,9 +4414,59 @@ declare class DefaultChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTy
4429
4414
  */
4430
4415
  body?: object;
4431
4416
  /**
4432
- Streaming protocol that is used. Defaults to `ui-message`.
4417
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
4418
+ or to provide a custom fetch implementation for e.g. testing.
4419
+ */
4420
+ fetch?: FetchFunction;
4421
+ /**
4422
+ * When a function is provided, it will be used
4423
+ * to prepare the request body for the chat API. This can be useful for
4424
+ * customizing the request body based on the messages and data in the chat.
4425
+ *
4426
+ * @param id The id of the chat.
4427
+ * @param messages The current messages in the chat.
4428
+ * @param requestBody The request body object passed in the chat request.
4429
+ */
4430
+ prepareRequestBody?: (options: {
4431
+ chatId: string;
4432
+ messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4433
+ requestBody?: object;
4434
+ }) => unknown;
4435
+ });
4436
+ submitMessages({ chatId, messages, abortController, body, headers, requestType, }: Parameters<ChatTransport<MESSAGE_METADATA, DATA_TYPES>['submitMessages']>[0]): Promise<ReadableStream<UIMessageStreamPart>>;
4437
+ }
4438
+ declare class TextStreamChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> implements ChatTransport<MESSAGE_METADATA, DATA_TYPES> {
4439
+ private api;
4440
+ private credentials?;
4441
+ private headers?;
4442
+ private body?;
4443
+ private fetch?;
4444
+ private prepareRequestBody?;
4445
+ constructor({ api, credentials, headers, body, fetch, prepareRequestBody, }: {
4446
+ api: string;
4447
+ /**
4448
+ * The credentials mode to be used for the fetch request.
4449
+ * Possible values are: 'omit', 'same-origin', 'include'.
4450
+ * Defaults to 'same-origin'.
4433
4451
  */
4434
- streamProtocol?: 'ui-message' | 'text';
4452
+ credentials?: RequestCredentials;
4453
+ /**
4454
+ * HTTP headers to be sent with the API request.
4455
+ */
4456
+ headers?: Record<string, string> | Headers;
4457
+ /**
4458
+ * Extra body object to be sent with the API request.
4459
+ * @example
4460
+ * Send a `sessionId` to the API along with the messages.
4461
+ * ```js
4462
+ * useChat({
4463
+ * body: {
4464
+ * sessionId: '123',
4465
+ * }
4466
+ * })
4467
+ * ```
4468
+ */
4469
+ body?: object;
4435
4470
  /**
4436
4471
  Custom fetch implementation. You can use it as a middleware to intercept requests,
4437
4472
  or to provide a custom fetch implementation for e.g. testing.
@@ -4773,7 +4808,7 @@ declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages:
4773
4808
  */
4774
4809
  declare const convertToCoreMessages: typeof convertToModelMessages;
4775
4810
 
4776
- declare function defaultChatStore<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas>({ api, fetch, streamProtocol, credentials, headers, body, prepareRequestBody, generateId, dataPartSchemas, messageMetadataSchema, maxSteps, chats, }: {
4811
+ declare function defaultChatStore<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas>({ api, fetch, credentials, headers, body, prepareRequestBody, generateId, dataPartSchemas, messageMetadataSchema, maxSteps, chats, }: {
4777
4812
  /**
4778
4813
  * Schema for the message metadata. Validates the message metadata.
4779
4814
  * Message metadata can be undefined or must match the schema.
@@ -4816,10 +4851,6 @@ declare function defaultChatStore<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS extends
4816
4851
  * ```
4817
4852
  */
4818
4853
  body?: object;
4819
- /**
4820
- Streaming protocol that is used. Defaults to `ui-message`.
4821
- */
4822
- streamProtocol?: 'ui-message' | 'text';
4823
4854
  /**
4824
4855
  Custom fetch implementation. You can use it as a middleware to intercept requests,
4825
4856
  or to provide a custom fetch implementation for e.g. testing.
@@ -4961,4 +4992,4 @@ type UseCompletionOptions = {
4961
4992
  fetch?: FetchFunction;
4962
4993
  };
4963
4994
 
4964
- export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequestOptions, ChatStatus, ChatStore, ChatStoreEvent, 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, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InferUIDataParts as InferUIDataTypes, 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, OriginalUseChatOptions, output as Output, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SourceUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataTypes, UIDataPartSchemas as UIDataTypesSchemas, UIMessage, UIMessagePart, UIMessageStreamOptions, UIMessageStreamPart, UIMessageStreamWriter, UseChatOptions, UseCompletionOptions, UserContent, UserModelMessage, appendClientMessage, assistantModelMessageSchema, callChatApi, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultChatStore, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractMaxToolInvocationStep, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolInvocations, hasToolCall, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, maxSteps, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, updateToolCallResult, userModelMessageSchema, wrapLanguageModel };
4995
+ export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequestOptions, ChatStatus, ChatStore, ChatStoreEvent, 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, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InferUIDataParts as InferUIDataTypes, 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, OriginalUseChatOptions, output as Output, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamChatTransport, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataTypes, UIDataPartSchemas as UIDataTypesSchemas, UIMessage, UIMessagePart, UIMessageStreamOptions, UIMessageStreamPart, UIMessageStreamWriter, UseChatOptions, UseCompletionOptions, UserContent, UserModelMessage, appendClientMessage, assistantModelMessageSchema, callChatApi, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultChatStore, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractMaxToolInvocationStep, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolInvocations, hasToolCall, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, maxSteps, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, updateToolCallResult, userModelMessageSchema, wrapLanguageModel };
package/dist/index.d.ts CHANGED
@@ -2154,7 +2154,7 @@ interface UIMessage<METADATA = unknown, DATA_PARTS extends UIDataTypes = UIDataT
2154
2154
  */
2155
2155
  parts: Array<UIMessagePart<DATA_PARTS>>;
2156
2156
  }
2157
- type UIMessagePart<DATA_TYPES extends UIDataTypes> = TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUIPart | FileUIPart | DataUIPart<DATA_TYPES> | StepStartUIPart;
2157
+ type UIMessagePart<DATA_TYPES extends UIDataTypes> = TextUIPart | ReasoningUIPart | ToolInvocationUIPart | SourceUrlUIPart | FileUIPart | DataUIPart<DATA_TYPES> | StepStartUIPart;
2158
2158
  type DataUIPart<DATA_TYPES extends UIDataTypes> = ValueOf<{
2159
2159
  [NAME in keyof DATA_TYPES & string]: {
2160
2160
  type: `data-${NAME}`;
@@ -2199,18 +2199,12 @@ type ToolInvocationUIPart = {
2199
2199
  /**
2200
2200
  * A source part of a message.
2201
2201
  */
2202
- type SourceUIPart = {
2203
- type: 'source';
2204
- /**
2205
- * The source.
2206
- */
2207
- source: {
2208
- sourceType: 'url';
2209
- id: string;
2210
- url: string;
2211
- title?: string;
2212
- providerMetadata?: Record<string, any>;
2213
- };
2202
+ type SourceUrlUIPart = {
2203
+ type: 'source-url';
2204
+ sourceId: string;
2205
+ url: string;
2206
+ title?: string;
2207
+ providerMetadata?: Record<string, any>;
2214
2208
  };
2215
2209
  /**
2216
2210
  * A file part of a message.
@@ -3247,7 +3241,7 @@ If set and supported by the model, calls will generate deterministic results.
3247
3241
  @return
3248
3242
  A result object for accessing different stream types and additional information.
3249
3243
  */
3250
- declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, maxSteps, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_toolCallStreaming, toolCallStreaming, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, onChunk, onError, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
3244
+ declare function streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, continueUntil, experimental_output: output, experimental_telemetry: telemetry, providerOptions, experimental_toolCallStreaming, toolCallStreaming, experimental_activeTools: activeTools, experimental_repairToolCall: repairToolCall, experimental_transform: transform, onChunk, onError, onFinish, onStepFinish, _internal: { now, generateId, currentDate, }, ...settings }: CallSettings & Prompt & {
3251
3245
  /**
3252
3246
  The language model to use.
3253
3247
  */
@@ -3260,14 +3254,7 @@ The tools that the model can call. The model needs to support calling tools.
3260
3254
  The tool choice strategy. Default: 'auto'.
3261
3255
  */
3262
3256
  toolChoice?: ToolChoice<TOOLS>;
3263
- /**
3264
- Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.
3265
-
3266
- A maximum number is required to prevent infinite loops in the case of misconfigured tools.
3267
-
3268
- By default, it's set to 1, which means that only a single LLM call is made.
3269
- */
3270
- maxSteps?: number;
3257
+ continueUntil?: StopCondition<NoInfer<TOOLS>>;
3271
3258
  /**
3272
3259
  Optional telemetry configuration (experimental).
3273
3260
  */
@@ -4311,9 +4298,8 @@ type UIMessageStreamPart = {
4311
4298
  text: string;
4312
4299
  providerMetadata?: ProviderMetadata;
4313
4300
  } | {
4314
- type: 'source';
4315
- sourceType: 'url';
4316
- id: string;
4301
+ type: 'source-url';
4302
+ sourceId: string;
4317
4303
  url: string;
4318
4304
  title?: string;
4319
4305
  providerMetadata?: ProviderMetadata;
@@ -4400,10 +4386,9 @@ declare class DefaultChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTy
4400
4386
  private credentials?;
4401
4387
  private headers?;
4402
4388
  private body?;
4403
- private streamProtocol?;
4404
4389
  private fetch?;
4405
4390
  private prepareRequestBody?;
4406
- constructor({ api, credentials, headers, body, streamProtocol, fetch, prepareRequestBody, }: {
4391
+ constructor({ api, credentials, headers, body, fetch, prepareRequestBody, }: {
4407
4392
  api: string;
4408
4393
  /**
4409
4394
  * The credentials mode to be used for the fetch request.
@@ -4429,9 +4414,59 @@ declare class DefaultChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTy
4429
4414
  */
4430
4415
  body?: object;
4431
4416
  /**
4432
- Streaming protocol that is used. Defaults to `ui-message`.
4417
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
4418
+ or to provide a custom fetch implementation for e.g. testing.
4419
+ */
4420
+ fetch?: FetchFunction;
4421
+ /**
4422
+ * When a function is provided, it will be used
4423
+ * to prepare the request body for the chat API. This can be useful for
4424
+ * customizing the request body based on the messages and data in the chat.
4425
+ *
4426
+ * @param id The id of the chat.
4427
+ * @param messages The current messages in the chat.
4428
+ * @param requestBody The request body object passed in the chat request.
4429
+ */
4430
+ prepareRequestBody?: (options: {
4431
+ chatId: string;
4432
+ messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4433
+ requestBody?: object;
4434
+ }) => unknown;
4435
+ });
4436
+ submitMessages({ chatId, messages, abortController, body, headers, requestType, }: Parameters<ChatTransport<MESSAGE_METADATA, DATA_TYPES>['submitMessages']>[0]): Promise<ReadableStream<UIMessageStreamPart>>;
4437
+ }
4438
+ declare class TextStreamChatTransport<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> implements ChatTransport<MESSAGE_METADATA, DATA_TYPES> {
4439
+ private api;
4440
+ private credentials?;
4441
+ private headers?;
4442
+ private body?;
4443
+ private fetch?;
4444
+ private prepareRequestBody?;
4445
+ constructor({ api, credentials, headers, body, fetch, prepareRequestBody, }: {
4446
+ api: string;
4447
+ /**
4448
+ * The credentials mode to be used for the fetch request.
4449
+ * Possible values are: 'omit', 'same-origin', 'include'.
4450
+ * Defaults to 'same-origin'.
4433
4451
  */
4434
- streamProtocol?: 'ui-message' | 'text';
4452
+ credentials?: RequestCredentials;
4453
+ /**
4454
+ * HTTP headers to be sent with the API request.
4455
+ */
4456
+ headers?: Record<string, string> | Headers;
4457
+ /**
4458
+ * Extra body object to be sent with the API request.
4459
+ * @example
4460
+ * Send a `sessionId` to the API along with the messages.
4461
+ * ```js
4462
+ * useChat({
4463
+ * body: {
4464
+ * sessionId: '123',
4465
+ * }
4466
+ * })
4467
+ * ```
4468
+ */
4469
+ body?: object;
4435
4470
  /**
4436
4471
  Custom fetch implementation. You can use it as a middleware to intercept requests,
4437
4472
  or to provide a custom fetch implementation for e.g. testing.
@@ -4773,7 +4808,7 @@ declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages:
4773
4808
  */
4774
4809
  declare const convertToCoreMessages: typeof convertToModelMessages;
4775
4810
 
4776
- declare function defaultChatStore<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas>({ api, fetch, streamProtocol, credentials, headers, body, prepareRequestBody, generateId, dataPartSchemas, messageMetadataSchema, maxSteps, chats, }: {
4811
+ declare function defaultChatStore<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas>({ api, fetch, credentials, headers, body, prepareRequestBody, generateId, dataPartSchemas, messageMetadataSchema, maxSteps, chats, }: {
4777
4812
  /**
4778
4813
  * Schema for the message metadata. Validates the message metadata.
4779
4814
  * Message metadata can be undefined or must match the schema.
@@ -4816,10 +4851,6 @@ declare function defaultChatStore<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS extends
4816
4851
  * ```
4817
4852
  */
4818
4853
  body?: object;
4819
- /**
4820
- Streaming protocol that is used. Defaults to `ui-message`.
4821
- */
4822
- streamProtocol?: 'ui-message' | 'text';
4823
4854
  /**
4824
4855
  Custom fetch implementation. You can use it as a middleware to intercept requests,
4825
4856
  or to provide a custom fetch implementation for e.g. testing.
@@ -4961,4 +4992,4 @@ type UseCompletionOptions = {
4961
4992
  fetch?: FetchFunction;
4962
4993
  };
4963
4994
 
4964
- export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequestOptions, ChatStatus, ChatStore, ChatStoreEvent, 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, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InferUIDataParts as InferUIDataTypes, 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, OriginalUseChatOptions, output as Output, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SourceUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataTypes, UIDataPartSchemas as UIDataTypesSchemas, UIMessage, UIMessagePart, UIMessageStreamOptions, UIMessageStreamPart, UIMessageStreamWriter, UseChatOptions, UseCompletionOptions, UserContent, UserModelMessage, appendClientMessage, assistantModelMessageSchema, callChatApi, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultChatStore, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractMaxToolInvocationStep, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolInvocations, hasToolCall, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, maxSteps, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, updateToolCallResult, userModelMessageSchema, wrapLanguageModel };
4995
+ export { AssistantContent, AssistantModelMessage, CallSettings, CallWarning, ChatRequestOptions, ChatStatus, ChatStore, ChatStoreEvent, 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, GenerateObjectResult, GenerateTextOnStepFinishCallback, GenerateTextResult, GeneratedAudioFile, GeneratedFile, ImageModel, ImageGenerationWarning as ImageModelCallWarning, ImageModelProviderMetadata, ImageModelResponseMetadata, ImagePart, InferUIDataParts as InferUIDataTypes, 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, OriginalUseChatOptions, output as Output, Prompt, Provider, ProviderMetadata, ProviderOptions, ProviderRegistryProvider, ReasoningUIPart, RepairTextFunction, RetryError, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, SpeechWarning, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStepFinishCallback, StreamTextResult, StreamTextTransform, SystemModelMessage, TelemetrySettings, TextPart, TextStreamChatTransport, TextStreamPart, TextUIPart, Tool, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataTypes, UIDataPartSchemas as UIDataTypesSchemas, UIMessage, UIMessagePart, UIMessageStreamOptions, UIMessageStreamPart, UIMessageStreamWriter, UseChatOptions, UseCompletionOptions, UserContent, UserModelMessage, appendClientMessage, assistantModelMessageSchema, callChatApi, callCompletionApi, convertFileListToFileUIParts, convertToCoreMessages, convertToModelMessages, coreAssistantMessageSchema, coreMessageSchema, coreSystemMessageSchema, coreToolMessageSchema, coreUserMessageSchema, cosineSimilarity, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultChatStore, defaultSettingsMiddleware, embed, embedMany, createMCPClient as experimental_createMCPClient, experimental_createProviderRegistry, experimental_customProvider, generateImage as experimental_generateImage, generateSpeech as experimental_generateSpeech, transcribe as experimental_transcribe, extractMaxToolInvocationStep, extractReasoningMiddleware, generateObject, generateText, getTextFromDataUrl, getToolInvocations, hasToolCall, isAssistantMessageWithCompletedToolCalls, isDeepEqualData, maxSteps, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, updateToolCallResult, userModelMessageSchema, wrapLanguageModel };