ai 5.0.0-alpha.4 → 5.0.0-alpha.5

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,20 @@
1
1
  # ai
2
2
 
3
+ ## 5.0.0-alpha.5
4
+
5
+ ### Major Changes
6
+
7
+ - ef256ed: chore (ai): refactor and use chatstore in svelte
8
+ - 1ed0287: chore (ai): stable sendStart/sendFinish options
9
+
10
+ ### Patch Changes
11
+
12
+ - 655cf3c: feat (ui): add onFinish to createUIMessageStream
13
+ - 1675396: fix: avoid job executor deadlock when adding tool result
14
+ - cf9af6e: feat (ai): allow sync prepareStep
15
+ - 825e8d7: release alpha.5
16
+ - 7324c21: fix (ai/telemetry): Avoid JSON.stringify on Uint8Arrays for telemetry
17
+
3
18
  ## 5.0.0-alpha.4
4
19
 
5
20
  ### Major Changes
package/dist/index.d.mts CHANGED
@@ -2693,6 +2693,31 @@ declare namespace output {
2693
2693
  };
2694
2694
  }
2695
2695
 
2696
+ /**
2697
+ Function that you can use to provide different settings for a step.
2698
+
2699
+ @param options - The options for the step.
2700
+ @param options.steps - The steps that have been executed so far.
2701
+ @param options.stepNumber - The number of the step that is being executed.
2702
+ @param options.model - The model that is being used.
2703
+
2704
+ @returns An object that contains the settings for the step.
2705
+ If you return undefined (or for undefined settings), the settings from the outer level will be used.
2706
+ */
2707
+ type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Tool>> = (options: {
2708
+ steps: Array<StepResult<NoInfer<TOOLS>>>;
2709
+ stepNumber: number;
2710
+ model: LanguageModel;
2711
+ }) => PromiseLike<{
2712
+ model?: LanguageModel;
2713
+ toolChoice?: ToolChoice<NoInfer<TOOLS>>;
2714
+ activeTools?: Array<keyof NoInfer<TOOLS>>;
2715
+ } | undefined> | {
2716
+ model?: LanguageModel;
2717
+ toolChoice?: ToolChoice<NoInfer<TOOLS>>;
2718
+ activeTools?: Array<keyof NoInfer<TOOLS>>;
2719
+ } | undefined;
2720
+
2696
2721
  type StopCondition<TOOLS extends ToolSet> = (options: {
2697
2722
  steps: Array<StepResult<TOOLS>>;
2698
2723
  }) => PromiseLike<boolean> | boolean;
@@ -2797,35 +2822,11 @@ Optional specification for parsing structured outputs from the LLM response.
2797
2822
  /**
2798
2823
  * @deprecated Use `prepareStep` instead.
2799
2824
  */
2800
- experimental_prepareStep?: (options: {
2801
- steps: Array<StepResult<NoInfer<TOOLS>>>;
2802
- stepNumber: number;
2803
- model: LanguageModel;
2804
- }) => PromiseLike<{
2805
- model?: LanguageModel;
2806
- toolChoice?: ToolChoice<NoInfer<TOOLS>>;
2807
- activeTools?: Array<keyof NoInfer<TOOLS>>;
2808
- } | undefined>;
2825
+ experimental_prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
2809
2826
  /**
2810
2827
  Optional function that you can use to provide different settings for a step.
2811
-
2812
- @param options - The options for the step.
2813
- @param options.steps - The steps that have been executed so far.
2814
- @param options.stepNumber - The number of the step that is being executed.
2815
- @param options.model - The model that is being used.
2816
-
2817
- @returns An object that contains the settings for the step.
2818
- If you return undefined (or for undefined settings), the settings from the outer level will be used.
2819
2828
  */
2820
- prepareStep?: (options: {
2821
- steps: Array<StepResult<NoInfer<TOOLS>>>;
2822
- stepNumber: number;
2823
- model: LanguageModel;
2824
- }) => PromiseLike<{
2825
- model?: LanguageModel;
2826
- toolChoice?: ToolChoice<NoInfer<TOOLS>>;
2827
- activeTools?: Array<keyof NoInfer<TOOLS>>;
2828
- } | undefined>;
2829
+ prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
2829
2830
  /**
2830
2831
  A function that attempts to repair a tool call that failed to parse.
2831
2832
  */
@@ -2899,7 +2900,7 @@ type UIMessageStreamOptions = {
2899
2900
  * that send additional data.
2900
2901
  * Default to true.
2901
2902
  */
2902
- experimental_sendFinish?: boolean;
2903
+ sendFinish?: boolean;
2903
2904
  /**
2904
2905
  * Send the message start event to the client.
2905
2906
  * Set to false if you are using additional streamText calls
@@ -2911,7 +2912,7 @@ type UIMessageStreamOptions = {
2911
2912
  * streamText calls that send additional data to prevent
2912
2913
  * the message start event from being sent multiple times.
2913
2914
  */
2914
- experimental_sendStart?: boolean;
2915
+ sendStart?: boolean;
2915
2916
  /**
2916
2917
  * Process an error, e.g. to log it. Default to `() => 'An error occurred.'`.
2917
2918
  *
@@ -3317,15 +3318,7 @@ Optional function that you can use to provide different settings for a step.
3317
3318
  @returns An object that contains the settings for the step.
3318
3319
  If you return undefined (or for undefined settings), the settings from the outer level will be used.
3319
3320
  */
3320
- prepareStep?: (options: {
3321
- steps: Array<StepResult<NoInfer<TOOLS>>>;
3322
- stepNumber: number;
3323
- model: LanguageModel;
3324
- }) => PromiseLike<{
3325
- model?: LanguageModel;
3326
- toolChoice?: ToolChoice<NoInfer<TOOLS>>;
3327
- activeTools?: Array<keyof NoInfer<TOOLS>>;
3328
- } | undefined>;
3321
+ prepareStep?: PrepareStepFunction<NoInfer<TOOLS>>;
3329
3322
  /**
3330
3323
  A function that attempts to repair a tool call that failed to parse.
3331
3324
  */
@@ -3670,6 +3663,20 @@ functionality that can be fully encapsulated in the provider.
3670
3663
  };
3671
3664
  }): Promise<GenerateObjectResult<RESULT>>;
3672
3665
 
3666
+ /**
3667
+ * Calculates the cosine similarity between two vectors. This is a useful metric for
3668
+ * comparing the similarity of two vectors such as embeddings.
3669
+ *
3670
+ * @param vector1 - The first vector.
3671
+ * @param vector2 - The second vector.
3672
+ *
3673
+ * @returns The cosine similarity between vector1 and vector2.
3674
+ * @returns 0 if either vector is the zero vector.
3675
+ *
3676
+ * @throws {InvalidArgumentError} If the vectors do not have the same length.
3677
+ */
3678
+ declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
3679
+
3673
3680
  /**
3674
3681
  * Converts a data URL of type text/* to a text string.
3675
3682
  */
@@ -3689,19 +3696,14 @@ declare function parsePartialJson(jsonText: string | undefined): Promise<{
3689
3696
  state: 'undefined-input' | 'successful-parse' | 'repaired-parse' | 'failed-parse';
3690
3697
  }>;
3691
3698
 
3692
- /**
3693
- * Calculates the cosine similarity between two vectors. This is a useful metric for
3694
- * comparing the similarity of two vectors such as embeddings.
3695
- *
3696
- * @param vector1 - The first vector.
3697
- * @param vector2 - The second vector.
3698
- *
3699
- * @returns The cosine similarity between vector1 and vector2.
3700
- * @returns 0 if either vector is the zero vector.
3701
- *
3702
- * @throws {InvalidArgumentError} If the vectors do not have the same length.
3703
- */
3704
- declare function cosineSimilarity(vector1: number[], vector2: number[]): number;
3699
+ type Job = () => Promise<void>;
3700
+
3701
+ declare class SerialJobExecutor {
3702
+ private queue;
3703
+ private isProcessing;
3704
+ private processQueue;
3705
+ run(job: Job): Promise<void>;
3706
+ }
3705
3707
 
3706
3708
  /**
3707
3709
  * Creates a ReadableStream that emits the provided values with an optional delay between each value.
@@ -4379,15 +4381,6 @@ type UIMessageStreamPart = {
4379
4381
  type: 'reasoning-part-finish';
4380
4382
  };
4381
4383
 
4382
- type Job = () => Promise<void>;
4383
-
4384
- declare class SerialJobExecutor {
4385
- private queue;
4386
- private isProcessing;
4387
- private processQueue;
4388
- run(job: Job): Promise<void>;
4389
- }
4390
-
4391
4384
  interface UIMessageStreamWriter {
4392
4385
  /**
4393
4386
  * Appends a data stream part to the stream.
@@ -4405,9 +4398,32 @@ interface UIMessageStreamWriter {
4405
4398
  onError: ((error: unknown) => string) | undefined;
4406
4399
  }
4407
4400
 
4408
- declare function createUIMessageStream({ execute, onError, }: {
4409
- execute: (writer: UIMessageStreamWriter) => Promise<void> | void;
4401
+ declare function createUIMessageStream({ execute, onError, // mask error messages for safety by default
4402
+ originalMessages, onFinish, }: {
4403
+ execute: (options: {
4404
+ writer: UIMessageStreamWriter;
4405
+ }) => Promise<void> | void;
4410
4406
  onError?: (error: unknown) => string;
4407
+ /**
4408
+ * The original messages.
4409
+ */
4410
+ originalMessages?: UIMessage[];
4411
+ onFinish?: (options: {
4412
+ /**
4413
+ * The updates list of UI messages.
4414
+ */
4415
+ messages: UIMessage[];
4416
+ /**
4417
+ * Indicates whether the response message is a continuation of the last original message,
4418
+ * or if a new message was created.
4419
+ */
4420
+ isContinuation: boolean;
4421
+ /**
4422
+ * The message that was sent to the client as a response
4423
+ * (including the original message if it was extended).
4424
+ */
4425
+ responseMessage: UIMessage;
4426
+ }) => void;
4411
4427
  }): ReadableStream<UIMessageStreamPart>;
4412
4428
 
4413
4429
  declare function createUIMessageStreamResponse({ status, statusText, headers, stream, }: ResponseInit & {
@@ -4564,16 +4580,10 @@ interface ChatStoreEvent {
4564
4580
  error?: Error;
4565
4581
  }
4566
4582
  type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
4567
- interface Chat<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> {
4568
- status: ChatStatus;
4569
- messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4570
- error?: Error;
4571
- activeResponse?: {
4572
- state: StreamingUIMessageState<MESSAGE_METADATA>;
4573
- abortController?: AbortController;
4574
- };
4575
- jobExecutor: SerialJobExecutor;
4576
- }
4583
+ type ActiveResponse<MESSAGE_METADATA> = {
4584
+ state: StreamingUIMessageState<MESSAGE_METADATA>;
4585
+ abortController: AbortController | undefined;
4586
+ };
4577
4587
  type ExtendedCallOptions<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> = ChatRequestOptions & {
4578
4588
  onError?: (error: Error) => void;
4579
4589
  /**
@@ -4599,15 +4609,47 @@ type UIDataPartSchemas = Record<string, Validator<any> | StandardSchemaV1<any>>;
4599
4609
  type InferUIDataParts<T extends UIDataPartSchemas> = {
4600
4610
  [K in keyof T]: T[K] extends Validator<infer U> ? U : T[K] extends StandardSchemaV1<infer U> ? U : unknown;
4601
4611
  };
4602
- declare class ChatStore<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas> {
4612
+ type ChatFactory<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> = (options: {
4613
+ messages?: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4614
+ }) => Chat<MESSAGE_METADATA, DATA_TYPES>;
4615
+ type ChatStoreOptions<MESSAGE_METADATA, DATA_PART_SCHEMAS extends UIDataPartSchemas> = {
4616
+ chats?: {
4617
+ [id: string]: {
4618
+ messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>[];
4619
+ };
4620
+ };
4621
+ generateId?: UseChatOptions['generateId'];
4622
+ transport: ChatTransport<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>;
4623
+ maxSteps?: number;
4624
+ messageMetadataSchema?: Validator<MESSAGE_METADATA> | StandardSchemaV1<MESSAGE_METADATA>;
4625
+ dataPartSchemas?: DATA_PART_SCHEMAS;
4626
+ };
4627
+ type ChatStoreFactory<MESSAGE_METADATA, DATA_PART_SCHEMAS extends UIDataPartSchemas> = (options: ChatStoreOptions<MESSAGE_METADATA, DATA_PART_SCHEMAS>) => ChatStore<MESSAGE_METADATA, DATA_PART_SCHEMAS>;
4628
+ interface Chat<MESSAGE_METADATA, DATA_TYPES extends UIDataTypes> {
4629
+ readonly status: ChatStatus;
4630
+ readonly messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[];
4631
+ readonly error: Error | undefined;
4632
+ readonly activeResponse: ActiveResponse<MESSAGE_METADATA> | undefined;
4633
+ readonly jobExecutor: SerialJobExecutor;
4634
+ setStatus: (status: ChatStatus) => void;
4635
+ setError: (error: Error | undefined) => void;
4636
+ setActiveResponse: (activeResponse: ActiveResponse<MESSAGE_METADATA> | undefined) => void;
4637
+ pushMessage: (message: UIMessage<MESSAGE_METADATA, DATA_TYPES>) => void;
4638
+ popMessage: () => void;
4639
+ replaceMessage: (index: number, message: UIMessage<MESSAGE_METADATA, DATA_TYPES>) => void;
4640
+ setMessages: (messages: UIMessage<MESSAGE_METADATA, DATA_TYPES>[]) => void;
4641
+ snapshot?: <T>(thing: T) => T;
4642
+ }
4643
+ declare class ChatStore<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> {
4603
4644
  private chats;
4645
+ private readonly createChat;
4604
4646
  private subscribers;
4605
4647
  private generateId;
4606
4648
  private messageMetadataSchema;
4607
4649
  private dataPartSchemas;
4608
4650
  private transport;
4609
4651
  private maxSteps;
4610
- constructor({ chats, generateId, transport, maxSteps, messageMetadataSchema, dataPartSchemas, }: {
4652
+ constructor({ chats, generateId, transport, maxSteps, messageMetadataSchema, dataPartSchemas, createChat, }: {
4611
4653
  chats?: {
4612
4654
  [id: string]: {
4613
4655
  messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
@@ -4618,6 +4660,7 @@ declare class ChatStore<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS extends UIDataPar
4618
4660
  maxSteps?: number;
4619
4661
  messageMetadataSchema?: Validator<MESSAGE_METADATA> | StandardSchemaV1<MESSAGE_METADATA>;
4620
4662
  dataPartSchemas?: UI_DATA_PART_SCHEMAS;
4663
+ createChat: ChatFactory<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>;
4621
4664
  });
4622
4665
  hasChat(id: string): boolean;
4623
4666
  addChat(id: string, messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[]): void;
@@ -4626,7 +4669,7 @@ declare class ChatStore<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS extends UIDataPar
4626
4669
  getStatus(id: string): ChatStatus;
4627
4670
  setStatus({ id, status, error, }: {
4628
4671
  id: string;
4629
- status: Chat<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>['status'];
4672
+ status: ChatStatus;
4630
4673
  error?: Error;
4631
4674
  }): void;
4632
4675
  getError(id: string): Error | undefined;
@@ -4657,7 +4700,7 @@ declare class ChatStore<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS extends UIDataPar
4657
4700
  chatId: string;
4658
4701
  }): Promise<void>;
4659
4702
  private emit;
4660
- private getChat;
4703
+ private getChatState;
4661
4704
  private triggerRequest;
4662
4705
  }
4663
4706
 
@@ -4710,9 +4753,21 @@ type UseChatOptions<MESSAGE_METADATA = unknown, DATA_TYPE_SCHEMAS extends UIData
4710
4753
  */
4711
4754
  generateId?: IdGenerator;
4712
4755
  /**
4713
- * Optional chat store. Default is used when not provided.
4756
+ * Chat store that should be used.
4757
+ * It must not change during the component lifecycle.
4758
+ *
4759
+ * When a ChatStore is provided, it will be used as is.
4760
+ * It should be stable and the stability is guaranteed by the user.
4761
+ *
4762
+ * When a function is provided, it will be called to create a new chat store.
4763
+ * The function will be called when the hook is mounted and the chat store will be
4764
+ * created.
4765
+ * The function will be called with the same arguments as the hook is called with.
4766
+ * The function should return a ChatStoreOptions object.
4767
+ *
4768
+ * When no value is provided, a default chat store will be created.
4714
4769
  */
4715
- chatStore?: ChatStore<MESSAGE_METADATA, DATA_TYPE_SCHEMAS>;
4770
+ chatStore?: ChatStore<MESSAGE_METADATA, DATA_TYPE_SCHEMAS> | (() => ChatStoreOptions<MESSAGE_METADATA, DATA_TYPE_SCHEMAS>);
4716
4771
  };
4717
4772
  type OriginalUseChatOptions<MESSAGE_METADATA = unknown> = {
4718
4773
  /**
@@ -4860,84 +4915,6 @@ declare function convertToModelMessages<TOOLS extends ToolSet = never>(messages:
4860
4915
  */
4861
4916
  declare const convertToCoreMessages: typeof convertToModelMessages;
4862
4917
 
4863
- declare function defaultChatStore<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas>({ api, fetch, credentials, headers, body, prepareRequestBody, generateId, dataPartSchemas, messageMetadataSchema, maxSteps, chats, }: {
4864
- /**
4865
- * Schema for the message metadata. Validates the message metadata.
4866
- * Message metadata can be undefined or must match the schema.
4867
- */
4868
- messageMetadataSchema?: Validator<MESSAGE_METADATA> | StandardSchemaV1<MESSAGE_METADATA>;
4869
- /**
4870
- * Schema for the data types. Validates the data types.
4871
- */
4872
- dataPartSchemas?: UI_DATA_PART_SCHEMAS;
4873
- /**
4874
- * The API endpoint that accepts a `{ messages: Message[] }` object and returns
4875
- * a stream of tokens of the AI chat response.
4876
- */
4877
- api: string;
4878
- /**
4879
- * A way to provide a function that is going to be used for ids for messages and the chat.
4880
- * If not provided the default AI SDK `generateId` is used.
4881
- */
4882
- generateId?: IdGenerator;
4883
- /**
4884
- * The credentials mode to be used for the fetch request.
4885
- * Possible values are: 'omit', 'same-origin', 'include'.
4886
- * Defaults to 'same-origin'.
4887
- */
4888
- credentials?: RequestCredentials;
4889
- /**
4890
- * HTTP headers to be sent with the API request.
4891
- */
4892
- headers?: Record<string, string> | Headers;
4893
- /**
4894
- * Extra body object to be sent with the API request.
4895
- * @example
4896
- * Send a `sessionId` to the API along with the messages.
4897
- * ```js
4898
- * useChat({
4899
- * body: {
4900
- * sessionId: '123',
4901
- * }
4902
- * })
4903
- * ```
4904
- */
4905
- body?: object;
4906
- /**
4907
- Custom fetch implementation. You can use it as a middleware to intercept requests,
4908
- or to provide a custom fetch implementation for e.g. testing.
4909
- */
4910
- fetch?: FetchFunction;
4911
- /**
4912
- Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
4913
- Must be at least 1.
4914
-
4915
- A maximum number is required to prevent infinite loops in the case of misconfigured tools.
4916
-
4917
- By default, it's set to 1, which means that only a single LLM call is made.
4918
- */
4919
- maxSteps?: number;
4920
- /**
4921
- * When a function is provided, it will be used
4922
- * to prepare the request body for the chat API. This can be useful for
4923
- * customizing the request body based on the messages and data in the chat.
4924
- *
4925
- * @param chatId The id of the chat.
4926
- * @param messages The current messages in the chat.
4927
- * @param requestBody The request body object passed in the chat request.
4928
- */
4929
- prepareRequestBody?: (options: {
4930
- chatId: string;
4931
- messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
4932
- requestBody?: object;
4933
- }) => unknown;
4934
- chats?: {
4935
- [id: string]: {
4936
- messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
4937
- };
4938
- };
4939
- }): ChatStore<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS>;
4940
-
4941
4918
  declare function extractMaxToolInvocationStep(toolInvocations: ToolInvocation[] | undefined): number | undefined;
4942
4919
 
4943
4920
  declare function getToolInvocations(message: UIMessage): ToolInvocation[];
@@ -5044,4 +5021,85 @@ type UseCompletionOptions = {
5044
5021
  fetch?: FetchFunction;
5045
5022
  };
5046
5023
 
5047
- 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, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, updateToolCallResult, userModelMessageSchema, wrapLanguageModel };
5024
+ interface DefaultChatStoreOptions<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> {
5025
+ /**
5026
+ * Schema for the message metadata. Validates the message metadata.
5027
+ * Message metadata can be undefined or must match the schema.
5028
+ */
5029
+ messageMetadataSchema?: Validator<MESSAGE_METADATA> | StandardSchemaV1<MESSAGE_METADATA>;
5030
+ /**
5031
+ * Schema for the data types. Validates the data types.
5032
+ */
5033
+ dataPartSchemas?: UI_DATA_PART_SCHEMAS;
5034
+ /**
5035
+ * The API endpoint that accepts a `{ messages: Message[] }` object and returns
5036
+ * a stream of tokens of the AI chat response.
5037
+ *
5038
+ * Defaults to `/api/chat`
5039
+ */
5040
+ api?: string;
5041
+ /**
5042
+ * A way to provide a function that is going to be used for ids for messages and the chat.
5043
+ * If not provided the default AI SDK `generateId` is used.
5044
+ */
5045
+ generateId?: IdGenerator;
5046
+ /**
5047
+ * The credentials mode to be used for the fetch request.
5048
+ * Possible values are: 'omit', 'same-origin', 'include'.
5049
+ * Defaults to 'same-origin'.
5050
+ */
5051
+ credentials?: RequestCredentials;
5052
+ /**
5053
+ * HTTP headers to be sent with the API request.
5054
+ */
5055
+ headers?: Record<string, string> | Headers;
5056
+ /**
5057
+ * Extra body object to be sent with the API request.
5058
+ * @example
5059
+ * Send a `sessionId` to the API along with the messages.
5060
+ * ```js
5061
+ * useChat({
5062
+ * body: {
5063
+ * sessionId: '123',
5064
+ * }
5065
+ * })
5066
+ * ```
5067
+ */
5068
+ body?: object;
5069
+ /**
5070
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
5071
+ or to provide a custom fetch implementation for e.g. testing.
5072
+ */
5073
+ fetch?: FetchFunction;
5074
+ /**
5075
+ Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
5076
+ Must be at least 1.
5077
+
5078
+ A maximum number is required to prevent infinite loops in the case of misconfigured tools.
5079
+
5080
+ By default, it's set to 1, which means that only a single LLM call is made.
5081
+ */
5082
+ maxSteps?: number;
5083
+ /**
5084
+ * When a function is provided, it will be used
5085
+ * to prepare the request body for the chat API. This can be useful for
5086
+ * customizing the request body based on the messages and data in the chat.
5087
+ *
5088
+ * @param chatId The id of the chat.
5089
+ * @param messages The current messages in the chat.
5090
+ * @param requestBody The request body object passed in the chat request.
5091
+ */
5092
+ prepareRequestBody?: (options: {
5093
+ chatId: string;
5094
+ messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
5095
+ requestBody?: object;
5096
+ }) => unknown;
5097
+ chats?: {
5098
+ [id: string]: {
5099
+ messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<UI_DATA_PART_SCHEMAS>>[];
5100
+ };
5101
+ };
5102
+ }
5103
+ declare function defaultChatStoreOptions<MESSAGE_METADATA = unknown, UI_DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas>({ api, fetch, credentials, headers, body, prepareRequestBody, generateId, messageMetadataSchema, maxSteps, dataPartSchemas, chats, }: DefaultChatStoreOptions<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS>): () => ChatStoreOptions<MESSAGE_METADATA, UI_DATA_PART_SCHEMAS>;
5104
+
5105
+ export { ActiveResponse, AssistantContent, AssistantModelMessage, CallSettings, CallWarning, Chat, ChatRequestOptions, ChatStatus, ChatStore, ChatStoreEvent, ChatStoreFactory, ChatStoreOptions, ChatTransport, ChunkDetector, CompletionRequestOptions, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreToolMessage, CoreUserMessage, CreateUIMessage, DataContent, DataUIPart, DeepPartial, DefaultChatStoreOptions, 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, 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, PrepareStepFunction, 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, ToolCallPart, ToolCallRepairError, ToolCallRepairFunction, ToolCallUnion, ToolChoice, ToolContent, ToolExecutionError, ToolExecutionOptions, ToolInvocation, ToolInvocationUIPart, ToolModelMessage, ToolResultPart, ToolResultUnion, ToolSet, TranscriptionModel, TranscriptionModelResponseMetadata, TranscriptionWarning, UIDataPartSchemas, UIDataTypes, 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, defaultChatStoreOptions, 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, modelMessageSchema, parsePartialJson, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, shouldResubmitMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, tool, toolModelMessageSchema, updateToolCallResult, userModelMessageSchema, wrapLanguageModel };