@ai-sdk/react 2.0.0-canary.2 → 2.0.0-canary.20

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,215 @@
1
1
  # @ai-sdk/react
2
2
 
3
+ ## 2.0.0-canary.20
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [d964901]
8
+ - Updated dependencies [0560977]
9
+ - Updated dependencies [66af894]
10
+ - Updated dependencies [516be5b]
11
+ - Updated dependencies [bfbfc4c]
12
+ - Updated dependencies [ea7a7c9]
13
+ - Updated dependencies [1409e13]
14
+ - ai@5.0.0-canary.21
15
+ - @ai-sdk/provider-utils@3.0.0-canary.17
16
+
17
+ ## 2.0.0-canary.19
18
+
19
+ ### Major Changes
20
+
21
+ - 496bbc1: chore (ui): inline/remove ChatRequest type
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [13fef90]
26
+ - Updated dependencies [e90d45d]
27
+ - Updated dependencies [bc3109f]
28
+ - Updated dependencies [496bbc1]
29
+ - Updated dependencies [da70d79]
30
+ - Updated dependencies [bcea599]
31
+ - Updated dependencies [48d675a]
32
+ - Updated dependencies [c7710a9]
33
+ - Updated dependencies [87b828f]
34
+ - Updated dependencies [35fc02c]
35
+ - Updated dependencies [b983b51]
36
+ - ai@5.0.0-canary.20
37
+ - @ai-sdk/provider-utils@3.0.0-canary.16
38
+
39
+ ## 2.0.0-canary.18
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies [2d03e19]
44
+ - Updated dependencies [319b989]
45
+ - Updated dependencies [441d042]
46
+ - Updated dependencies [dcc549b]
47
+ - Updated dependencies [cb2b53a]
48
+ - Updated dependencies [e244a78]
49
+ - ai@5.0.0-canary.19
50
+
51
+ ## 2.0.0-canary.17
52
+
53
+ ### Patch Changes
54
+
55
+ - Updated dependencies [a571d6e]
56
+ - Updated dependencies [c60f895]
57
+ - Updated dependencies [332167b]
58
+ - Updated dependencies [a8c8bd5]
59
+ - Updated dependencies [a662dea]
60
+ - Updated dependencies [41fa418]
61
+ - @ai-sdk/provider-utils@3.0.0-canary.15
62
+ - ai@5.0.0-canary.18
63
+
64
+ ## 2.0.0-canary.16
65
+
66
+ ### Patch Changes
67
+
68
+ - c34ccd7: feat (ui/react): support resuming an ongoing stream
69
+ - Updated dependencies [f04fb4a]
70
+ - Updated dependencies [fd1924b]
71
+ - Updated dependencies [957b739]
72
+ - Updated dependencies [fafc3f2]
73
+ - Updated dependencies [c9ad635]
74
+ - Updated dependencies [9bd5ab5]
75
+ - Updated dependencies [92cb0a2]
76
+ - ai@5.0.0-canary.17
77
+ - @ai-sdk/provider-utils@3.0.0-canary.14
78
+
79
+ ## 2.0.0-canary.15
80
+
81
+ ### Patch Changes
82
+
83
+ - 6a0ff37: fix (react): integrate addToolResult into UseChatHelpers type without intersection
84
+ - Updated dependencies [ec78cdc]
85
+ - Updated dependencies [9b4d074]
86
+ - Updated dependencies [8b86e99]
87
+ - Updated dependencies [28ad69e]
88
+ - Updated dependencies [2524fc7]
89
+ - Updated dependencies [ec5933d]
90
+ - Updated dependencies [175b868]
91
+ - ai@5.0.0-canary.16
92
+
93
+ ## 2.0.0-canary.14
94
+
95
+ ### Patch Changes
96
+
97
+ - Updated dependencies [d9209ca]
98
+ - Updated dependencies [ea27cc6]
99
+ - Updated dependencies [0ff02bb]
100
+ - Updated dependencies [4bfe9ec]
101
+ - Updated dependencies [2877a74]
102
+ - ai@5.0.0-canary.15
103
+ - @ai-sdk/provider-utils@3.0.0-canary.13
104
+
105
+ ## 2.0.0-canary.13
106
+
107
+ ### Patch Changes
108
+
109
+ - Updated dependencies [9bf7291]
110
+ - Updated dependencies [4617fab]
111
+ - Updated dependencies [a76a62b]
112
+ - ai@5.0.0-canary.14
113
+ - @ai-sdk/provider-utils@3.0.0-canary.12
114
+
115
+ ## 2.0.0-canary.12
116
+
117
+ ### Patch Changes
118
+
119
+ - Updated dependencies [14cb3be]
120
+ - Updated dependencies [66962ed]
121
+ - Updated dependencies [9301f86]
122
+ - ai@5.0.0-canary.13
123
+ - @ai-sdk/provider-utils@3.0.0-canary.11
124
+
125
+ ## 2.0.0-canary.11
126
+
127
+ ### Patch Changes
128
+
129
+ - ai@5.0.0-canary.12
130
+ - @ai-sdk/provider-utils@3.0.0-canary.10
131
+
132
+ ## 2.0.0-canary.10
133
+
134
+ ### Patch Changes
135
+
136
+ - Updated dependencies [8e64e9c]
137
+ - ai@5.0.0-canary.11
138
+ - @ai-sdk/provider-utils@3.0.0-canary.9
139
+
140
+ ## 2.0.0-canary.9
141
+
142
+ ### Patch Changes
143
+
144
+ - Updated dependencies [d8aeaef]
145
+ - Updated dependencies [3e10408]
146
+ - ai@5.0.0-canary.10
147
+
148
+ ## 2.0.0-canary.8
149
+
150
+ ### Patch Changes
151
+
152
+ - Updated dependencies [a847c3e]
153
+ - Updated dependencies [5d142ab]
154
+ - Updated dependencies [cb9c9e4]
155
+ - Updated dependencies [8aa9e20]
156
+ - Updated dependencies [b32e192]
157
+ - ai@5.0.0-canary.9
158
+ - @ai-sdk/provider-utils@3.0.0-canary.8
159
+
160
+ ## 2.0.0-canary.7
161
+
162
+ ### Patch Changes
163
+
164
+ - Updated dependencies [5d1e3ba]
165
+ - Updated dependencies [26735b5]
166
+ - Updated dependencies [14c9410]
167
+ - Updated dependencies [7827a49]
168
+ - Updated dependencies [bd8a36c]
169
+ - Updated dependencies [b6f9f3c]
170
+ - Updated dependencies [92c8e66]
171
+ - Updated dependencies [fd65bc6]
172
+ - Updated dependencies [5bdff05]
173
+ - ai@5.0.0-canary.8
174
+ - @ai-sdk/provider-utils@3.0.0-canary.7
175
+
176
+ ## 2.0.0-canary.6
177
+
178
+ ### Patch Changes
179
+
180
+ - Updated dependencies [0b78e17]
181
+ - Updated dependencies [6fba4c7]
182
+ - Updated dependencies [3e3b9df]
183
+ - Updated dependencies [1766ede]
184
+ - Updated dependencies [f10304b]
185
+ - ai@5.0.0-canary.7
186
+ - @ai-sdk/provider-utils@3.0.0-canary.6
187
+
188
+ ## 2.0.0-canary.5
189
+
190
+ ### Patch Changes
191
+
192
+ - ai@5.0.0-canary.6
193
+ - @ai-sdk/provider-utils@3.0.0-canary.5
194
+
195
+ ## 2.0.0-canary.4
196
+
197
+ ### Patch Changes
198
+
199
+ - Updated dependencies [b71fe8d]
200
+ - Updated dependencies [d91b50d]
201
+ - ai@5.0.0-canary.5
202
+ - @ai-sdk/provider-utils@3.0.0-canary.4
203
+
204
+ ## 2.0.0-canary.3
205
+
206
+ ### Patch Changes
207
+
208
+ - Updated dependencies [a166433]
209
+ - Updated dependencies [9f95b35]
210
+ - @ai-sdk/provider-utils@3.0.0-canary.3
211
+ - @ai-sdk/ui-utils@2.0.0-canary.3
212
+
3
213
  ## 2.0.0-canary.2
4
214
 
5
215
  ### Patch Changes
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # AI SDK: React provider
2
2
 
3
- [React](https://react.dev/) UI components for the [AI SDK](https://sdk.vercel.ai/docs):
3
+ [React](https://react.dev/) UI components for the [AI SDK](https://ai-sdk.dev/docs):
4
4
 
5
- - [`useChat`](https://sdk.vercel.ai/docs/reference/ai-sdk-ui/use-chat) hook
6
- - [`useCompletion`](https://sdk.vercel.ai/docs/reference/ai-sdk-ui/use-completion) hook
7
- - [`useObject`](https://sdk.vercel.ai/docs/reference/ai-sdk-ui/use-object) hook
5
+ - [`useChat`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) hook
6
+ - [`useCompletion`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) hook
7
+ - [`useObject`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) hook
package/dist/index.d.mts CHANGED
@@ -1,11 +1,11 @@
1
- import { UIMessage, Message, CreateMessage, ChatRequestOptions, JSONValue, UseChatOptions, RequestOptions, UseCompletionOptions, Schema, DeepPartial } from '@ai-sdk/ui-utils';
2
- export { CreateMessage, Message, UseChatOptions, UseCompletionOptions } from '@ai-sdk/ui-utils';
1
+ import { UIMessage, CreateUIMessage, ChatRequestOptions, FileUIPart, UseChatOptions, JSONValue, CompletionRequestOptions, UseCompletionOptions, Schema, DeepPartial } from 'ai';
2
+ export { CreateUIMessage, UIMessage, UseChatOptions, UseCompletionOptions } from 'ai';
3
3
  import { FetchFunction } from '@ai-sdk/provider-utils';
4
4
  import z from 'zod';
5
5
 
6
- type UseChatHelpers = {
6
+ type UseChatHelpers<MESSAGE_METADATA = unknown> = {
7
7
  /** Current messages in the chat */
8
- messages: UIMessage[];
8
+ messages: UIMessage<MESSAGE_METADATA>[];
9
9
  /** The error object of the API request */
10
10
  error: undefined | Error;
11
11
  /**
@@ -14,7 +14,7 @@ type UseChatHelpers = {
14
14
  * @param message The message to append
15
15
  * @param options Additional options to pass to the API call
16
16
  */
17
- append: (message: Message | CreateMessage, chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
17
+ append: (message: UIMessage<MESSAGE_METADATA> | CreateUIMessage<MESSAGE_METADATA>, chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
18
18
  /**
19
19
  * Reload the last AI chat response for the given chat history. If the last
20
20
  * message isn't from the assistant, it will request the API to generate a
@@ -25,12 +25,16 @@ type UseChatHelpers = {
25
25
  * Abort the current request immediately, keep the generated tokens if any.
26
26
  */
27
27
  stop: () => void;
28
+ /**
29
+ * Resume an ongoing chat generation stream. This does not resume an aborted generation.
30
+ */
31
+ experimental_resume: () => void;
28
32
  /**
29
33
  * Update the `messages` state locally. This is useful when you want to
30
34
  * edit the messages on the client, and then trigger the `reload` method
31
35
  * manually to regenerate the AI response.
32
36
  */
33
- setMessages: (messages: Message[] | ((messages: Message[]) => Message[])) => void;
37
+ setMessages: (messages: UIMessage<MESSAGE_METADATA>[] | ((messages: UIMessage<MESSAGE_METADATA>[]) => UIMessage<MESSAGE_METADATA>[])) => void;
34
38
  /** The current value of the input */
35
39
  input: string;
36
40
  /** setState-powered method to update the input value */
@@ -40,7 +44,9 @@ type UseChatHelpers = {
40
44
  /** Form submission handler to automatically reset input and append a user message */
41
45
  handleSubmit: (event?: {
42
46
  preventDefault?: () => void;
43
- }, chatRequestOptions?: ChatRequestOptions) => void;
47
+ }, chatRequestOptions?: ChatRequestOptions & {
48
+ files?: FileList | FileUIPart[];
49
+ }) => void;
44
50
  metadata?: Object;
45
51
  /**
46
52
  * Whether the API request is in progress
@@ -57,15 +63,14 @@ type UseChatHelpers = {
57
63
  * - `error`: An error occurred during the API request, preventing successful completion.
58
64
  */
59
65
  status: 'submitted' | 'streaming' | 'ready' | 'error';
60
- /** Additional data added on the server via StreamData. */
61
- data?: JSONValue[];
62
- /** Set the data of the chat. You can use this to transform or clear the chat data. */
63
- setData: (data: JSONValue[] | undefined | ((data: JSONValue[] | undefined) => JSONValue[] | undefined)) => void;
66
+ addToolResult: ({ toolCallId, result, }: {
67
+ toolCallId: string;
68
+ result: any;
69
+ }) => void;
64
70
  /** The id of the chat */
65
71
  id: string;
66
72
  };
67
- declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, onToolCall, experimental_prepareRequestBody, maxSteps, streamProtocol, onResponse, onFinish, onError, credentials, headers, body, generateId, fetch, keepLastMessageOnError, experimental_throttle: throttleWaitMs, }?: UseChatOptions & {
68
- key?: string;
73
+ declare function useChat<MESSAGE_METADATA>({ api, id, initialMessages, initialInput, onToolCall, experimental_prepareRequestBody, maxSteps, streamProtocol, onResponse, onFinish, onError, credentials, headers, body, generateId, fetch, experimental_throttle: throttleWaitMs, messageMetadataSchema, }?: UseChatOptions<MESSAGE_METADATA> & {
69
74
  /**
70
75
  * Experimental (React only). When a function is provided, it will be used
71
76
  * to prepare the request body for the chat API. This can be useful for
@@ -86,21 +91,7 @@ declare function useChat({ api, id, initialMessages, initialInput, sendExtraMess
86
91
  Default is undefined, which disables throttling.
87
92
  */
88
93
  experimental_throttle?: number;
89
- /**
90
- Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
91
- Must be at least 1.
92
-
93
- A maximum number is required to prevent infinite loops in the case of misconfigured tools.
94
-
95
- By default, it's set to 1, which means that only a single LLM call is made.
96
- */
97
- maxSteps?: number;
98
- }): UseChatHelpers & {
99
- addToolResult: ({ toolCallId, result, }: {
100
- toolCallId: string;
101
- result: any;
102
- }) => void;
103
- };
94
+ }): UseChatHelpers<MESSAGE_METADATA>;
104
95
 
105
96
  type UseCompletionHelpers = {
106
97
  /** The current completion result */
@@ -108,7 +99,7 @@ type UseCompletionHelpers = {
108
99
  /**
109
100
  * Send a new prompt to the API endpoint and update the completion state.
110
101
  */
111
- complete: (prompt: string, options?: RequestOptions) => Promise<string | null | undefined>;
102
+ complete: (prompt: string, options?: CompletionRequestOptions) => Promise<string | null | undefined>;
112
103
  /** The error object of the API request */
113
104
  error: undefined | Error;
114
105
  /**
@@ -145,8 +136,6 @@ type UseCompletionHelpers = {
145
136
  }) => void;
146
137
  /** Whether the API request is in progress */
147
138
  isLoading: boolean;
148
- /** Additional data added on the server via StreamData */
149
- data?: JSONValue[];
150
139
  };
151
140
  declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamProtocol, fetch, onResponse, onFinish, onError, experimental_throttle: throttleWaitMs, }?: UseCompletionOptions & {
152
141
  /**
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { UIMessage, Message, CreateMessage, ChatRequestOptions, JSONValue, UseChatOptions, RequestOptions, UseCompletionOptions, Schema, DeepPartial } from '@ai-sdk/ui-utils';
2
- export { CreateMessage, Message, UseChatOptions, UseCompletionOptions } from '@ai-sdk/ui-utils';
1
+ import { UIMessage, CreateUIMessage, ChatRequestOptions, FileUIPart, UseChatOptions, JSONValue, CompletionRequestOptions, UseCompletionOptions, Schema, DeepPartial } from 'ai';
2
+ export { CreateUIMessage, UIMessage, UseChatOptions, UseCompletionOptions } from 'ai';
3
3
  import { FetchFunction } from '@ai-sdk/provider-utils';
4
4
  import z from 'zod';
5
5
 
6
- type UseChatHelpers = {
6
+ type UseChatHelpers<MESSAGE_METADATA = unknown> = {
7
7
  /** Current messages in the chat */
8
- messages: UIMessage[];
8
+ messages: UIMessage<MESSAGE_METADATA>[];
9
9
  /** The error object of the API request */
10
10
  error: undefined | Error;
11
11
  /**
@@ -14,7 +14,7 @@ type UseChatHelpers = {
14
14
  * @param message The message to append
15
15
  * @param options Additional options to pass to the API call
16
16
  */
17
- append: (message: Message | CreateMessage, chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
17
+ append: (message: UIMessage<MESSAGE_METADATA> | CreateUIMessage<MESSAGE_METADATA>, chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>;
18
18
  /**
19
19
  * Reload the last AI chat response for the given chat history. If the last
20
20
  * message isn't from the assistant, it will request the API to generate a
@@ -25,12 +25,16 @@ type UseChatHelpers = {
25
25
  * Abort the current request immediately, keep the generated tokens if any.
26
26
  */
27
27
  stop: () => void;
28
+ /**
29
+ * Resume an ongoing chat generation stream. This does not resume an aborted generation.
30
+ */
31
+ experimental_resume: () => void;
28
32
  /**
29
33
  * Update the `messages` state locally. This is useful when you want to
30
34
  * edit the messages on the client, and then trigger the `reload` method
31
35
  * manually to regenerate the AI response.
32
36
  */
33
- setMessages: (messages: Message[] | ((messages: Message[]) => Message[])) => void;
37
+ setMessages: (messages: UIMessage<MESSAGE_METADATA>[] | ((messages: UIMessage<MESSAGE_METADATA>[]) => UIMessage<MESSAGE_METADATA>[])) => void;
34
38
  /** The current value of the input */
35
39
  input: string;
36
40
  /** setState-powered method to update the input value */
@@ -40,7 +44,9 @@ type UseChatHelpers = {
40
44
  /** Form submission handler to automatically reset input and append a user message */
41
45
  handleSubmit: (event?: {
42
46
  preventDefault?: () => void;
43
- }, chatRequestOptions?: ChatRequestOptions) => void;
47
+ }, chatRequestOptions?: ChatRequestOptions & {
48
+ files?: FileList | FileUIPart[];
49
+ }) => void;
44
50
  metadata?: Object;
45
51
  /**
46
52
  * Whether the API request is in progress
@@ -57,15 +63,14 @@ type UseChatHelpers = {
57
63
  * - `error`: An error occurred during the API request, preventing successful completion.
58
64
  */
59
65
  status: 'submitted' | 'streaming' | 'ready' | 'error';
60
- /** Additional data added on the server via StreamData. */
61
- data?: JSONValue[];
62
- /** Set the data of the chat. You can use this to transform or clear the chat data. */
63
- setData: (data: JSONValue[] | undefined | ((data: JSONValue[] | undefined) => JSONValue[] | undefined)) => void;
66
+ addToolResult: ({ toolCallId, result, }: {
67
+ toolCallId: string;
68
+ result: any;
69
+ }) => void;
64
70
  /** The id of the chat */
65
71
  id: string;
66
72
  };
67
- declare function useChat({ api, id, initialMessages, initialInput, sendExtraMessageFields, onToolCall, experimental_prepareRequestBody, maxSteps, streamProtocol, onResponse, onFinish, onError, credentials, headers, body, generateId, fetch, keepLastMessageOnError, experimental_throttle: throttleWaitMs, }?: UseChatOptions & {
68
- key?: string;
73
+ declare function useChat<MESSAGE_METADATA>({ api, id, initialMessages, initialInput, onToolCall, experimental_prepareRequestBody, maxSteps, streamProtocol, onResponse, onFinish, onError, credentials, headers, body, generateId, fetch, experimental_throttle: throttleWaitMs, messageMetadataSchema, }?: UseChatOptions<MESSAGE_METADATA> & {
69
74
  /**
70
75
  * Experimental (React only). When a function is provided, it will be used
71
76
  * to prepare the request body for the chat API. This can be useful for
@@ -86,21 +91,7 @@ declare function useChat({ api, id, initialMessages, initialInput, sendExtraMess
86
91
  Default is undefined, which disables throttling.
87
92
  */
88
93
  experimental_throttle?: number;
89
- /**
90
- Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
91
- Must be at least 1.
92
-
93
- A maximum number is required to prevent infinite loops in the case of misconfigured tools.
94
-
95
- By default, it's set to 1, which means that only a single LLM call is made.
96
- */
97
- maxSteps?: number;
98
- }): UseChatHelpers & {
99
- addToolResult: ({ toolCallId, result, }: {
100
- toolCallId: string;
101
- result: any;
102
- }) => void;
103
- };
94
+ }): UseChatHelpers<MESSAGE_METADATA>;
104
95
 
105
96
  type UseCompletionHelpers = {
106
97
  /** The current completion result */
@@ -108,7 +99,7 @@ type UseCompletionHelpers = {
108
99
  /**
109
100
  * Send a new prompt to the API endpoint and update the completion state.
110
101
  */
111
- complete: (prompt: string, options?: RequestOptions) => Promise<string | null | undefined>;
102
+ complete: (prompt: string, options?: CompletionRequestOptions) => Promise<string | null | undefined>;
112
103
  /** The error object of the API request */
113
104
  error: undefined | Error;
114
105
  /**
@@ -145,8 +136,6 @@ type UseCompletionHelpers = {
145
136
  }) => void;
146
137
  /** Whether the API request is in progress */
147
138
  isLoading: boolean;
148
- /** Additional data added on the server via StreamData */
149
- data?: JSONValue[];
150
139
  };
151
140
  declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamProtocol, fetch, onResponse, onFinish, onError, experimental_throttle: throttleWaitMs, }?: UseCompletionOptions & {
152
141
  /**