@ai-sdk/react 2.0.0-alpha.8 → 2.0.0-beta.1

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,109 @@
1
1
  # @ai-sdk/react
2
2
 
3
+ ## 2.0.0-beta.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [d88455d]
8
+ - Updated dependencies [45c1ea2]
9
+ - Updated dependencies [9ad0484]
10
+ - Updated dependencies [e025824]
11
+ - Updated dependencies [4048ce3]
12
+ - Updated dependencies [f2b041e]
13
+ - Updated dependencies [cb68df0]
14
+ - Updated dependencies [26695a3]
15
+ - Updated dependencies [bfdca8d]
16
+ - Updated dependencies [e7d2ce3]
17
+ - Updated dependencies [102b066]
18
+ - Updated dependencies [71f938d]
19
+ - Updated dependencies [28a5ed5]
20
+ - Updated dependencies [e862b5b]
21
+ - Updated dependencies [7bd025b]
22
+ - ai@5.0.0-beta.1
23
+ - @ai-sdk/provider-utils@3.0.0-beta.1
24
+
25
+ ## 2.0.0-alpha.15
26
+
27
+ ### Patch Changes
28
+
29
+ - ae0dc0a: feat (ui/react): add resume flag to useChat
30
+ - Updated dependencies [b1e3abd]
31
+ - Updated dependencies [8ba77a7]
32
+ - Updated dependencies [04d5063]
33
+ - Updated dependencies [b4b4bb2]
34
+ - Updated dependencies [d884051]
35
+ - Updated dependencies [954aa73]
36
+ - Updated dependencies [142576e]
37
+ - Updated dependencies [395c85e]
38
+ - Updated dependencies [60e2c56]
39
+ - ai@5.0.0-alpha.15
40
+ - @ai-sdk/provider-utils@3.0.0-alpha.15
41
+
42
+ ## 2.0.0-alpha.14
43
+
44
+ ### Patch Changes
45
+
46
+ - 995baa0: fix (react): structuredClone message in replaceMessage
47
+ - Updated dependencies [63f9e9b]
48
+ - ai@5.0.0-alpha.14
49
+ - @ai-sdk/provider-utils@3.0.0-alpha.14
50
+
51
+ ## 2.0.0-alpha.13
52
+
53
+ ### Major Changes
54
+
55
+ - 0a710d8: feat (ui): typed tool parts in ui messages
56
+ - 901df02: feat (ui): use UI_MESSAGE generic
57
+
58
+ ### Patch Changes
59
+
60
+ - Updated dependencies [0a710d8]
61
+ - Updated dependencies [6a83f7d]
62
+ - Updated dependencies [1f55c21]
63
+ - Updated dependencies [33eb499]
64
+ - Updated dependencies [901df02]
65
+ - ai@5.0.0-alpha.13
66
+ - @ai-sdk/provider-utils@3.0.0-alpha.13
67
+
68
+ ## 2.0.0-alpha.12
69
+
70
+ ### Patch Changes
71
+
72
+ - Updated dependencies [da1e6f0]
73
+ - Updated dependencies [4892798]
74
+ - ai@5.0.0-alpha.12
75
+ - @ai-sdk/provider-utils@3.0.0-alpha.12
76
+
77
+ ## 2.0.0-alpha.11
78
+
79
+ ### Patch Changes
80
+
81
+ - Updated dependencies [e8324c5]
82
+ - ai@5.0.0-alpha.11
83
+ - @ai-sdk/provider-utils@3.0.0-alpha.11
84
+
85
+ ## 2.0.0-alpha.10
86
+
87
+ ### Major Changes
88
+
89
+ - 98f25e5: chore (ui): remove managed chat inputs
90
+
91
+ ### Patch Changes
92
+
93
+ - Updated dependencies [98f25e5]
94
+ - Updated dependencies [7bb58d4]
95
+ - ai@5.0.0-alpha.10
96
+ - @ai-sdk/provider-utils@3.0.0-alpha.10
97
+
98
+ ## 2.0.0-alpha.9
99
+
100
+ ### Patch Changes
101
+
102
+ - Updated dependencies [8255639]
103
+ - Updated dependencies [9ae327d]
104
+ - ai@5.0.0-alpha.9
105
+ - @ai-sdk/provider-utils@3.0.0-alpha.9
106
+
3
107
  ## 2.0.0-alpha.8
4
108
 
5
109
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,79 +1,44 @@
1
- import { UIDataPartSchemas, UIMessage, InferUIDataParts, CreateUIMessage, ChatRequestOptions, FileUIPart, UseChatOptions, CompletionRequestOptions, UseCompletionOptions, Schema, DeepPartial, ChatStoreOptions, ChatStore } from 'ai';
2
- export { CreateUIMessage, UIMessage, UseChatOptions, UseCompletionOptions } from 'ai';
1
+ import { UIMessage, AbstractChat, ChatInit, CompletionRequestOptions, UseCompletionOptions, Schema, DeepPartial } from 'ai';
2
+ export { CreateUIMessage, UIMessage, UseCompletionOptions } from 'ai';
3
3
  import { FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
4
4
  import * as z3 from 'zod/v3';
5
5
  import * as z4 from 'zod/v4/core';
6
6
 
7
- type UseChatHelpers<MESSAGE_METADATA = unknown, DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> = {
7
+ declare class Chat<UI_MESSAGE extends UIMessage> extends AbstractChat<UI_MESSAGE> {
8
+ #private;
9
+ constructor({ messages, ...init }: ChatInit<UI_MESSAGE>);
10
+ '~registerMessagesCallback': (onChange: () => void, throttleWaitMs?: number) => (() => void);
11
+ '~registerStatusCallback': (onChange: () => void) => (() => void);
12
+ '~registerErrorCallback': (onChange: () => void) => (() => void);
13
+ }
14
+
15
+ type UseChatHelpers<UI_MESSAGE extends UIMessage> = {
8
16
  /**
9
17
  * The id of the chat.
10
18
  */
11
- readonly chatId: string;
12
- /**
13
- * Hook status:
14
- *
15
- * - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.
16
- * - `streaming`: The response is actively streaming in from the API, receiving chunks of data.
17
- * - `ready`: The full response has been received and processed; a new user message can be submitted.
18
- * - `error`: An error occurred during the API request, preventing successful completion.
19
- */
20
- readonly status: 'submitted' | 'streaming' | 'ready' | 'error';
21
- /** Current messages in the chat */
22
- readonly messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>[];
23
- /** The error object of the API request */
24
- readonly error: undefined | Error;
25
- /**
26
- * Append a user message to the chat list. This triggers the API call to fetch
27
- * the assistant's response.
28
- *
29
- * @param message The message to append
30
- * @param options Additional options to pass to the API call
31
- */
32
- append: (message: CreateUIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>, options?: ChatRequestOptions) => Promise<void>;
33
- /**
34
- * Reload the last AI chat response for the given chat history. If the last
35
- * message isn't from the assistant, it will request the API to generate a
36
- * new response.
37
- */
38
- reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
39
- /**
40
- * Abort the current request immediately, keep the generated tokens if any.
41
- */
42
- stop: () => void;
43
- /**
44
- * Resume an ongoing chat generation stream. This does not resume an aborted generation.
45
- */
46
- experimental_resume: () => void;
19
+ readonly id: string;
47
20
  /**
48
21
  * Update the `messages` state locally. This is useful when you want to
49
22
  * edit the messages on the client, and then trigger the `reload` method
50
23
  * manually to regenerate the AI response.
51
24
  */
52
- setMessages: (messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>[] | ((messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>[]) => UIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>[])) => void;
53
- /** The current value of the input */
54
- input: string;
55
- /** setState-powered method to update the input value */
56
- setInput: React.Dispatch<React.SetStateAction<string>>;
57
- /** An input/textarea-ready onChange handler to control the value of the input */
58
- handleInputChange: (e: React.ChangeEvent<HTMLInputElement> | React.ChangeEvent<HTMLTextAreaElement>) => void;
59
- /** Form submission handler to automatically reset input and append a user message */
60
- handleSubmit: (event?: {
61
- preventDefault?: () => void;
62
- }, chatRequestOptions?: ChatRequestOptions & {
63
- files?: FileList | FileUIPart[];
64
- }) => void;
65
- addToolResult: ({ toolCallId, result, }: {
66
- toolCallId: string;
67
- result: any;
68
- }) => void;
69
- };
70
- declare function useChat<MESSAGE_METADATA = unknown, DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas>({ chatId, initialInput, onToolCall, onFinish, onError, generateId, experimental_throttle: throttleWaitMs, chatStore: chatStoreArg, }?: UseChatOptions<MESSAGE_METADATA, DATA_PART_SCHEMAS> & {
25
+ setMessages: (messages: UI_MESSAGE[] | ((messages: UI_MESSAGE[]) => UI_MESSAGE[])) => void;
26
+ error: Error | undefined;
27
+ } & Pick<AbstractChat<UI_MESSAGE>, 'sendMessage' | 'regenerate' | 'stop' | 'resumeStream' | 'addToolResult' | 'status' | 'messages'>;
28
+ type UseChatOptions<UI_MESSAGE extends UIMessage> = ({
29
+ chat: Chat<UI_MESSAGE>;
30
+ } | ChatInit<UI_MESSAGE>) & {
71
31
  /**
72
32
  Custom throttle wait in ms for the chat messages and data updates.
73
33
  Default is undefined, which disables throttling.
74
34
  */
75
35
  experimental_throttle?: number;
76
- }): UseChatHelpers<MESSAGE_METADATA, DATA_PART_SCHEMAS>;
36
+ /**
37
+ * Whether to resume an ongoing chat generation stream.
38
+ */
39
+ resume?: boolean;
40
+ };
41
+ declare function useChat<UI_MESSAGE extends UIMessage = UIMessage>({ experimental_throttle: throttleWaitMs, resume, ...options }?: UseChatOptions<UI_MESSAGE>): UseChatHelpers<UI_MESSAGE>;
77
42
 
78
43
  type UseCompletionHelpers = {
79
44
  /** The current completion result */
@@ -206,6 +171,4 @@ declare function useObject<SCHEMA extends z4.$ZodType | z3.Schema | Schema, RESU
206
171
  initialValue, fetch, onError, onFinish, headers, credentials, }: Experimental_UseObjectOptions<SCHEMA, RESULT>): Experimental_UseObjectHelpers<RESULT, INPUT>;
207
172
  declare const experimental_useObject: typeof useObject;
208
173
 
209
- declare function createChatStore<MESSAGE_METADATA = unknown, DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas>(options: ChatStoreOptions<MESSAGE_METADATA, DATA_PART_SCHEMAS>): ChatStore<MESSAGE_METADATA, DATA_PART_SCHEMAS>;
210
-
211
- export { Experimental_UseObjectHelpers, Experimental_UseObjectOptions, UseChatHelpers, UseCompletionHelpers, createChatStore, experimental_useObject, useChat, useCompletion };
174
+ export { Chat, Experimental_UseObjectHelpers, Experimental_UseObjectOptions, UseChatHelpers, UseChatOptions, UseCompletionHelpers, experimental_useObject, useChat, useCompletion };
package/dist/index.d.ts CHANGED
@@ -1,79 +1,44 @@
1
- import { UIDataPartSchemas, UIMessage, InferUIDataParts, CreateUIMessage, ChatRequestOptions, FileUIPart, UseChatOptions, CompletionRequestOptions, UseCompletionOptions, Schema, DeepPartial, ChatStoreOptions, ChatStore } from 'ai';
2
- export { CreateUIMessage, UIMessage, UseChatOptions, UseCompletionOptions } from 'ai';
1
+ import { UIMessage, AbstractChat, ChatInit, CompletionRequestOptions, UseCompletionOptions, Schema, DeepPartial } from 'ai';
2
+ export { CreateUIMessage, UIMessage, UseCompletionOptions } from 'ai';
3
3
  import { FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
4
4
  import * as z3 from 'zod/v3';
5
5
  import * as z4 from 'zod/v4/core';
6
6
 
7
- type UseChatHelpers<MESSAGE_METADATA = unknown, DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas> = {
7
+ declare class Chat<UI_MESSAGE extends UIMessage> extends AbstractChat<UI_MESSAGE> {
8
+ #private;
9
+ constructor({ messages, ...init }: ChatInit<UI_MESSAGE>);
10
+ '~registerMessagesCallback': (onChange: () => void, throttleWaitMs?: number) => (() => void);
11
+ '~registerStatusCallback': (onChange: () => void) => (() => void);
12
+ '~registerErrorCallback': (onChange: () => void) => (() => void);
13
+ }
14
+
15
+ type UseChatHelpers<UI_MESSAGE extends UIMessage> = {
8
16
  /**
9
17
  * The id of the chat.
10
18
  */
11
- readonly chatId: string;
12
- /**
13
- * Hook status:
14
- *
15
- * - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.
16
- * - `streaming`: The response is actively streaming in from the API, receiving chunks of data.
17
- * - `ready`: The full response has been received and processed; a new user message can be submitted.
18
- * - `error`: An error occurred during the API request, preventing successful completion.
19
- */
20
- readonly status: 'submitted' | 'streaming' | 'ready' | 'error';
21
- /** Current messages in the chat */
22
- readonly messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>[];
23
- /** The error object of the API request */
24
- readonly error: undefined | Error;
25
- /**
26
- * Append a user message to the chat list. This triggers the API call to fetch
27
- * the assistant's response.
28
- *
29
- * @param message The message to append
30
- * @param options Additional options to pass to the API call
31
- */
32
- append: (message: CreateUIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>, options?: ChatRequestOptions) => Promise<void>;
33
- /**
34
- * Reload the last AI chat response for the given chat history. If the last
35
- * message isn't from the assistant, it will request the API to generate a
36
- * new response.
37
- */
38
- reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
39
- /**
40
- * Abort the current request immediately, keep the generated tokens if any.
41
- */
42
- stop: () => void;
43
- /**
44
- * Resume an ongoing chat generation stream. This does not resume an aborted generation.
45
- */
46
- experimental_resume: () => void;
19
+ readonly id: string;
47
20
  /**
48
21
  * Update the `messages` state locally. This is useful when you want to
49
22
  * edit the messages on the client, and then trigger the `reload` method
50
23
  * manually to regenerate the AI response.
51
24
  */
52
- setMessages: (messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>[] | ((messages: UIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>[]) => UIMessage<MESSAGE_METADATA, InferUIDataParts<DATA_PART_SCHEMAS>>[])) => void;
53
- /** The current value of the input */
54
- input: string;
55
- /** setState-powered method to update the input value */
56
- setInput: React.Dispatch<React.SetStateAction<string>>;
57
- /** An input/textarea-ready onChange handler to control the value of the input */
58
- handleInputChange: (e: React.ChangeEvent<HTMLInputElement> | React.ChangeEvent<HTMLTextAreaElement>) => void;
59
- /** Form submission handler to automatically reset input and append a user message */
60
- handleSubmit: (event?: {
61
- preventDefault?: () => void;
62
- }, chatRequestOptions?: ChatRequestOptions & {
63
- files?: FileList | FileUIPart[];
64
- }) => void;
65
- addToolResult: ({ toolCallId, result, }: {
66
- toolCallId: string;
67
- result: any;
68
- }) => void;
69
- };
70
- declare function useChat<MESSAGE_METADATA = unknown, DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas>({ chatId, initialInput, onToolCall, onFinish, onError, generateId, experimental_throttle: throttleWaitMs, chatStore: chatStoreArg, }?: UseChatOptions<MESSAGE_METADATA, DATA_PART_SCHEMAS> & {
25
+ setMessages: (messages: UI_MESSAGE[] | ((messages: UI_MESSAGE[]) => UI_MESSAGE[])) => void;
26
+ error: Error | undefined;
27
+ } & Pick<AbstractChat<UI_MESSAGE>, 'sendMessage' | 'regenerate' | 'stop' | 'resumeStream' | 'addToolResult' | 'status' | 'messages'>;
28
+ type UseChatOptions<UI_MESSAGE extends UIMessage> = ({
29
+ chat: Chat<UI_MESSAGE>;
30
+ } | ChatInit<UI_MESSAGE>) & {
71
31
  /**
72
32
  Custom throttle wait in ms for the chat messages and data updates.
73
33
  Default is undefined, which disables throttling.
74
34
  */
75
35
  experimental_throttle?: number;
76
- }): UseChatHelpers<MESSAGE_METADATA, DATA_PART_SCHEMAS>;
36
+ /**
37
+ * Whether to resume an ongoing chat generation stream.
38
+ */
39
+ resume?: boolean;
40
+ };
41
+ declare function useChat<UI_MESSAGE extends UIMessage = UIMessage>({ experimental_throttle: throttleWaitMs, resume, ...options }?: UseChatOptions<UI_MESSAGE>): UseChatHelpers<UI_MESSAGE>;
77
42
 
78
43
  type UseCompletionHelpers = {
79
44
  /** The current completion result */
@@ -206,6 +171,4 @@ declare function useObject<SCHEMA extends z4.$ZodType | z3.Schema | Schema, RESU
206
171
  initialValue, fetch, onError, onFinish, headers, credentials, }: Experimental_UseObjectOptions<SCHEMA, RESULT>): Experimental_UseObjectHelpers<RESULT, INPUT>;
207
172
  declare const experimental_useObject: typeof useObject;
208
173
 
209
- declare function createChatStore<MESSAGE_METADATA = unknown, DATA_PART_SCHEMAS extends UIDataPartSchemas = UIDataPartSchemas>(options: ChatStoreOptions<MESSAGE_METADATA, DATA_PART_SCHEMAS>): ChatStore<MESSAGE_METADATA, DATA_PART_SCHEMAS>;
210
-
211
- export { Experimental_UseObjectHelpers, Experimental_UseObjectOptions, UseChatHelpers, UseCompletionHelpers, createChatStore, experimental_useObject, useChat, useCompletion };
174
+ export { Chat, Experimental_UseObjectHelpers, Experimental_UseObjectOptions, UseChatHelpers, UseChatOptions, UseCompletionHelpers, experimental_useObject, useChat, useCompletion };