ai 5.0.0-beta.32 → 5.0.0-beta.34

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-beta.34
4
+
5
+ ### Patch Changes
6
+
7
+ - 53569b8: feat (ai): add experimental repairText function to streamObject
8
+ - 88a8ee5: fix (ai): support abort during retry waits
9
+ - f2c7f19: feat (ui): add Chat.clearError()
10
+ - Updated dependencies [721775e]
11
+ - Updated dependencies [88a8ee5]
12
+ - @ai-sdk/gateway@1.0.0-beta.19
13
+ - @ai-sdk/provider-utils@3.0.0-beta.10
14
+
15
+ ## 5.0.0-beta.33
16
+
17
+ ### Patch Changes
18
+
19
+ - 48378b9: fix (ai): send null as tool output when tools return undefined
20
+ - 93d53a1: chore (ai): remove cli
21
+ - 27deb4d: feat (provider/gateway): Add providerMetadata to embeddings response
22
+ - Updated dependencies [27deb4d]
23
+ - @ai-sdk/gateway@1.0.0-beta.18
24
+ - @ai-sdk/provider@2.0.0-beta.2
25
+ - @ai-sdk/provider-utils@3.0.0-beta.9
26
+
3
27
  ## 5.0.0-beta.32
4
28
 
5
29
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -2060,6 +2060,10 @@ interface EmbedResult<VALUE> {
2060
2060
  */
2061
2061
  readonly usage: EmbeddingModelUsage;
2062
2062
  /**
2063
+ Optional provider-specific metadata.
2064
+ */
2065
+ readonly providerMetadata?: ProviderMetadata;
2066
+ /**
2063
2067
  Optional response data.
2064
2068
  */
2065
2069
  readonly response?: {
@@ -2140,6 +2144,10 @@ interface EmbedManyResult<VALUE> {
2140
2144
  */
2141
2145
  readonly usage: EmbeddingModelUsage;
2142
2146
  /**
2147
+ Optional provider-specific metadata.
2148
+ */
2149
+ readonly providerMetadata?: ProviderMetadata;
2150
+ /**
2143
2151
  Optional raw response data.
2144
2152
  */
2145
2153
  readonly responses?: Array<{
@@ -2643,7 +2651,7 @@ interface GenerateObjectResult<OBJECT> {
2643
2651
  }
2644
2652
 
2645
2653
  /**
2646
- A function that attempts to repair the raw output of the mode
2654
+ A function that attempts to repair the raw output of the model
2647
2655
  to enable JSON parsing.
2648
2656
 
2649
2657
  Should return the repaired text or null if the text cannot be repaired.
@@ -2652,6 +2660,7 @@ type RepairTextFunction = (options: {
2652
2660
  text: string;
2653
2661
  error: JSONParseError | TypeValidationError;
2654
2662
  }) => Promise<string | null>;
2663
+
2655
2664
  /**
2656
2665
  Generate a structured, typed object for a given prompt and schema using a language model.
2657
2666
 
@@ -2704,7 +2713,7 @@ via tool or schema description.
2704
2713
  - 'enum': The output is an enum.
2705
2714
  - 'no-schema': The output is not a schema.
2706
2715
 
2707
- @param experimental_repairText - A function that attempts to repair the raw output of the mode
2716
+ @param experimental_repairText - A function that attempts to repair the raw output of the model
2708
2717
  to enable JSON parsing.
2709
2718
 
2710
2719
  @param experimental_telemetry - Optional telemetry configuration (experimental).
@@ -2761,7 +2770,7 @@ The language model to use.
2761
2770
  */
2762
2771
  model: LanguageModel;
2763
2772
  /**
2764
- A function that attempts to repair the raw output of the mode
2773
+ A function that attempts to repair the raw output of the model
2765
2774
  to enable JSON parsing.
2766
2775
  */
2767
2776
  experimental_repairText?: RepairTextFunction;
@@ -3099,6 +3108,11 @@ The language model to use.
3099
3108
  */
3100
3109
  model: LanguageModel;
3101
3110
  /**
3111
+ A function that attempts to repair the raw output of the model
3112
+ to enable JSON parsing.
3113
+ */
3114
+ experimental_repairText?: RepairTextFunction;
3115
+ /**
3102
3116
  Optional telemetry configuration (experimental).
3103
3117
  */
3104
3118
  experimental_telemetry?: TelemetrySettings;
@@ -3761,16 +3775,77 @@ declare const UI_MESSAGE_STREAM_HEADERS: {
3761
3775
  'x-accel-buffering': string;
3762
3776
  };
3763
3777
 
3778
+ /**
3779
+ * Transport interface for handling chat message communication and streaming.
3780
+ *
3781
+ * The `ChatTransport` interface provides fine-grained control over how messages
3782
+ * are sent to API endpoints and how responses are processed. This enables
3783
+ * alternative communication protocols like WebSockets, custom authentication
3784
+ * patterns, or specialized backend integrations.
3785
+ *
3786
+ * @template UI_MESSAGE - The UI message type extending UIMessage
3787
+ */
3764
3788
  interface ChatTransport<UI_MESSAGE extends UIMessage> {
3789
+ /**
3790
+ * Sends messages to the chat API endpoint and returns a streaming response.
3791
+ *
3792
+ * This method handles both new message submission and message regeneration.
3793
+ * It supports real-time streaming of responses through UIMessageChunk events.
3794
+ *
3795
+ * @param options - Configuration object containing:
3796
+ * @param options.trigger - The type of message submission:
3797
+ * - `'submit-message'`: Submitting a new user message
3798
+ * - `'regenerate-message'`: Regenerating an assistant response
3799
+ * @param options.chatId - Unique identifier for the chat session
3800
+ * @param options.messageId - ID of the message to regenerate (for regenerate-message trigger) or undefined for new messages
3801
+ * @param options.messages - Array of UI messages representing the conversation history
3802
+ * @param options.abortSignal - Signal to abort the request if needed
3803
+ * @param options.headers - Additional HTTP headers to include in the request
3804
+ * @param options.body - Additional JSON properties to include in the request body
3805
+ * @param options.metadata - Custom metadata to attach to the request
3806
+ *
3807
+ * @returns Promise resolving to a ReadableStream of UIMessageChunk objects.
3808
+ * The stream emits various chunk types like:
3809
+ * - `text-start`, `text-delta`, `text-end`: For streaming text content
3810
+ * - `tool-input-start`, `tool-input-delta`, `tool-input-available`: For tool calls
3811
+ * - `data-part-start`, `data-part-delta`, `data-part-available`: For data parts
3812
+ * - `error`: For error handling
3813
+ *
3814
+ * @throws Error when the API request fails or response is invalid
3815
+ */
3765
3816
  sendMessages: (options: {
3817
+ /** The type of message submission - either new message or regeneration */
3818
+ trigger: 'submit-message' | 'regenerate-message';
3819
+ /** Unique identifier for the chat session */
3766
3820
  chatId: string;
3821
+ /** ID of the message to regenerate, or undefined for new messages */
3822
+ messageId: string | undefined;
3823
+ /** Array of UI messages representing the conversation history */
3767
3824
  messages: UI_MESSAGE[];
3825
+ /** Signal to abort the request if needed */
3768
3826
  abortSignal: AbortSignal | undefined;
3769
- } & {
3770
- trigger: 'submit-message' | 'regenerate-message';
3771
- messageId: string | undefined;
3772
3827
  } & ChatRequestOptions) => Promise<ReadableStream<UIMessageChunk>>;
3828
+ /**
3829
+ * Reconnects to an existing streaming response for the specified chat session.
3830
+ *
3831
+ * This method is used to resume streaming when a connection is interrupted
3832
+ * or when resuming a chat session. It's particularly useful for maintaining
3833
+ * continuity in long-running conversations or recovering from network issues.
3834
+ *
3835
+ * @param options - Configuration object containing:
3836
+ * @param options.chatId - Unique identifier for the chat session to reconnect to
3837
+ * @param options.headers - Additional HTTP headers to include in the reconnection request
3838
+ * @param options.body - Additional JSON properties to include in the request body
3839
+ * @param options.metadata - Custom metadata to attach to the request
3840
+ *
3841
+ * @returns Promise resolving to:
3842
+ * - `ReadableStream<UIMessageChunk>`: If an active stream is found and can be resumed
3843
+ * - `null`: If no active stream exists for the specified chat session (e.g., response already completed)
3844
+ *
3845
+ * @throws Error when the reconnection request fails or response is invalid
3846
+ */
3773
3847
  reconnectToStream: (options: {
3848
+ /** Unique identifier for the chat session to reconnect to */
3774
3849
  chatId: string;
3775
3850
  } & ChatRequestOptions) => Promise<ReadableStream<UIMessageChunk> | null>;
3776
3851
  }
@@ -3929,6 +4004,10 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
3929
4004
  * Attempt to resume an ongoing streaming response.
3930
4005
  */
3931
4006
  resumeStream: (options?: ChatRequestOptions) => Promise<void>;
4007
+ /**
4008
+ * Clear the error state and set the status to ready if the chat is in an error state.
4009
+ */
4010
+ clearError: () => void;
3932
4011
  addToolResult: <TOOL extends keyof InferUIMessageTools<UI_MESSAGE>>({ tool, toolCallId, output, }: {
3933
4012
  tool: TOOL;
3934
4013
  toolCallId: string;
package/dist/index.d.ts CHANGED
@@ -2060,6 +2060,10 @@ interface EmbedResult<VALUE> {
2060
2060
  */
2061
2061
  readonly usage: EmbeddingModelUsage;
2062
2062
  /**
2063
+ Optional provider-specific metadata.
2064
+ */
2065
+ readonly providerMetadata?: ProviderMetadata;
2066
+ /**
2063
2067
  Optional response data.
2064
2068
  */
2065
2069
  readonly response?: {
@@ -2140,6 +2144,10 @@ interface EmbedManyResult<VALUE> {
2140
2144
  */
2141
2145
  readonly usage: EmbeddingModelUsage;
2142
2146
  /**
2147
+ Optional provider-specific metadata.
2148
+ */
2149
+ readonly providerMetadata?: ProviderMetadata;
2150
+ /**
2143
2151
  Optional raw response data.
2144
2152
  */
2145
2153
  readonly responses?: Array<{
@@ -2643,7 +2651,7 @@ interface GenerateObjectResult<OBJECT> {
2643
2651
  }
2644
2652
 
2645
2653
  /**
2646
- A function that attempts to repair the raw output of the mode
2654
+ A function that attempts to repair the raw output of the model
2647
2655
  to enable JSON parsing.
2648
2656
 
2649
2657
  Should return the repaired text or null if the text cannot be repaired.
@@ -2652,6 +2660,7 @@ type RepairTextFunction = (options: {
2652
2660
  text: string;
2653
2661
  error: JSONParseError | TypeValidationError;
2654
2662
  }) => Promise<string | null>;
2663
+
2655
2664
  /**
2656
2665
  Generate a structured, typed object for a given prompt and schema using a language model.
2657
2666
 
@@ -2704,7 +2713,7 @@ via tool or schema description.
2704
2713
  - 'enum': The output is an enum.
2705
2714
  - 'no-schema': The output is not a schema.
2706
2715
 
2707
- @param experimental_repairText - A function that attempts to repair the raw output of the mode
2716
+ @param experimental_repairText - A function that attempts to repair the raw output of the model
2708
2717
  to enable JSON parsing.
2709
2718
 
2710
2719
  @param experimental_telemetry - Optional telemetry configuration (experimental).
@@ -2761,7 +2770,7 @@ The language model to use.
2761
2770
  */
2762
2771
  model: LanguageModel;
2763
2772
  /**
2764
- A function that attempts to repair the raw output of the mode
2773
+ A function that attempts to repair the raw output of the model
2765
2774
  to enable JSON parsing.
2766
2775
  */
2767
2776
  experimental_repairText?: RepairTextFunction;
@@ -3099,6 +3108,11 @@ The language model to use.
3099
3108
  */
3100
3109
  model: LanguageModel;
3101
3110
  /**
3111
+ A function that attempts to repair the raw output of the model
3112
+ to enable JSON parsing.
3113
+ */
3114
+ experimental_repairText?: RepairTextFunction;
3115
+ /**
3102
3116
  Optional telemetry configuration (experimental).
3103
3117
  */
3104
3118
  experimental_telemetry?: TelemetrySettings;
@@ -3761,16 +3775,77 @@ declare const UI_MESSAGE_STREAM_HEADERS: {
3761
3775
  'x-accel-buffering': string;
3762
3776
  };
3763
3777
 
3778
+ /**
3779
+ * Transport interface for handling chat message communication and streaming.
3780
+ *
3781
+ * The `ChatTransport` interface provides fine-grained control over how messages
3782
+ * are sent to API endpoints and how responses are processed. This enables
3783
+ * alternative communication protocols like WebSockets, custom authentication
3784
+ * patterns, or specialized backend integrations.
3785
+ *
3786
+ * @template UI_MESSAGE - The UI message type extending UIMessage
3787
+ */
3764
3788
  interface ChatTransport<UI_MESSAGE extends UIMessage> {
3789
+ /**
3790
+ * Sends messages to the chat API endpoint and returns a streaming response.
3791
+ *
3792
+ * This method handles both new message submission and message regeneration.
3793
+ * It supports real-time streaming of responses through UIMessageChunk events.
3794
+ *
3795
+ * @param options - Configuration object containing:
3796
+ * @param options.trigger - The type of message submission:
3797
+ * - `'submit-message'`: Submitting a new user message
3798
+ * - `'regenerate-message'`: Regenerating an assistant response
3799
+ * @param options.chatId - Unique identifier for the chat session
3800
+ * @param options.messageId - ID of the message to regenerate (for regenerate-message trigger) or undefined for new messages
3801
+ * @param options.messages - Array of UI messages representing the conversation history
3802
+ * @param options.abortSignal - Signal to abort the request if needed
3803
+ * @param options.headers - Additional HTTP headers to include in the request
3804
+ * @param options.body - Additional JSON properties to include in the request body
3805
+ * @param options.metadata - Custom metadata to attach to the request
3806
+ *
3807
+ * @returns Promise resolving to a ReadableStream of UIMessageChunk objects.
3808
+ * The stream emits various chunk types like:
3809
+ * - `text-start`, `text-delta`, `text-end`: For streaming text content
3810
+ * - `tool-input-start`, `tool-input-delta`, `tool-input-available`: For tool calls
3811
+ * - `data-part-start`, `data-part-delta`, `data-part-available`: For data parts
3812
+ * - `error`: For error handling
3813
+ *
3814
+ * @throws Error when the API request fails or response is invalid
3815
+ */
3765
3816
  sendMessages: (options: {
3817
+ /** The type of message submission - either new message or regeneration */
3818
+ trigger: 'submit-message' | 'regenerate-message';
3819
+ /** Unique identifier for the chat session */
3766
3820
  chatId: string;
3821
+ /** ID of the message to regenerate, or undefined for new messages */
3822
+ messageId: string | undefined;
3823
+ /** Array of UI messages representing the conversation history */
3767
3824
  messages: UI_MESSAGE[];
3825
+ /** Signal to abort the request if needed */
3768
3826
  abortSignal: AbortSignal | undefined;
3769
- } & {
3770
- trigger: 'submit-message' | 'regenerate-message';
3771
- messageId: string | undefined;
3772
3827
  } & ChatRequestOptions) => Promise<ReadableStream<UIMessageChunk>>;
3828
+ /**
3829
+ * Reconnects to an existing streaming response for the specified chat session.
3830
+ *
3831
+ * This method is used to resume streaming when a connection is interrupted
3832
+ * or when resuming a chat session. It's particularly useful for maintaining
3833
+ * continuity in long-running conversations or recovering from network issues.
3834
+ *
3835
+ * @param options - Configuration object containing:
3836
+ * @param options.chatId - Unique identifier for the chat session to reconnect to
3837
+ * @param options.headers - Additional HTTP headers to include in the reconnection request
3838
+ * @param options.body - Additional JSON properties to include in the request body
3839
+ * @param options.metadata - Custom metadata to attach to the request
3840
+ *
3841
+ * @returns Promise resolving to:
3842
+ * - `ReadableStream<UIMessageChunk>`: If an active stream is found and can be resumed
3843
+ * - `null`: If no active stream exists for the specified chat session (e.g., response already completed)
3844
+ *
3845
+ * @throws Error when the reconnection request fails or response is invalid
3846
+ */
3773
3847
  reconnectToStream: (options: {
3848
+ /** Unique identifier for the chat session to reconnect to */
3774
3849
  chatId: string;
3775
3850
  } & ChatRequestOptions) => Promise<ReadableStream<UIMessageChunk> | null>;
3776
3851
  }
@@ -3929,6 +4004,10 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
3929
4004
  * Attempt to resume an ongoing streaming response.
3930
4005
  */
3931
4006
  resumeStream: (options?: ChatRequestOptions) => Promise<void>;
4007
+ /**
4008
+ * Clear the error state and set the status to ready if the chat is in an error state.
4009
+ */
4010
+ clearError: () => void;
3932
4011
  addToolResult: <TOOL extends keyof InferUIMessageTools<UI_MESSAGE>>({ tool, toolCallId, output, }: {
3933
4012
  tool: TOOL;
3934
4013
  toolCallId: string;