@ai-sdk/react 1.2.12 → 2.0.0-alpha.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 +260 -26
- package/README.md +1 -1
- package/dist/index.d.mts +29 -122
- package/dist/index.d.ts +29 -122
- package/dist/index.js +164 -550
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +164 -558
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,58 +1,292 @@
|
|
|
1
1
|
# @ai-sdk/react
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 2.0.0-alpha.1
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- Updated dependencies [
|
|
8
|
-
|
|
9
|
-
-
|
|
7
|
+
- Updated dependencies [b346545]
|
|
8
|
+
- Updated dependencies [109c0ac]
|
|
9
|
+
- ai@5.0.0-alpha.1
|
|
10
|
+
- @ai-sdk/provider-utils@3.0.0-alpha.1
|
|
10
11
|
|
|
11
|
-
##
|
|
12
|
+
## 2.0.0-canary.23
|
|
12
13
|
|
|
13
14
|
### Patch Changes
|
|
14
15
|
|
|
15
|
-
-
|
|
16
|
-
- Updated dependencies [
|
|
17
|
-
|
|
16
|
+
- Updated dependencies [bedb239]
|
|
17
|
+
- Updated dependencies [507ac1d]
|
|
18
|
+
- Updated dependencies [2b9bbcd]
|
|
19
|
+
- Updated dependencies [f7e8bf4]
|
|
20
|
+
- Updated dependencies [cda32ba]
|
|
21
|
+
- Updated dependencies [50f0362]
|
|
22
|
+
- Updated dependencies [ed675de]
|
|
23
|
+
- Updated dependencies [faf8446]
|
|
24
|
+
- Updated dependencies [64f6d64]
|
|
25
|
+
- ai@5.0.0-canary.24
|
|
26
|
+
- @ai-sdk/provider-utils@3.0.0-canary.19
|
|
18
27
|
|
|
19
|
-
##
|
|
28
|
+
## 2.0.0-canary.22
|
|
29
|
+
|
|
30
|
+
### Major Changes
|
|
31
|
+
|
|
32
|
+
- 40acf9b: feat (ui): introduce ChatStore and ChatTransport
|
|
20
33
|
|
|
21
34
|
### Patch Changes
|
|
22
35
|
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
36
|
+
- Updated dependencies [40acf9b]
|
|
37
|
+
- @ai-sdk/provider-utils@3.0.0-canary.18
|
|
38
|
+
- ai@5.0.0-canary.23
|
|
26
39
|
|
|
27
|
-
##
|
|
40
|
+
## 2.0.0-canary.21
|
|
28
41
|
|
|
29
42
|
### Patch Changes
|
|
30
43
|
|
|
31
|
-
-
|
|
32
|
-
-
|
|
44
|
+
- Updated dependencies [e7dc6c7]
|
|
45
|
+
- Updated dependencies [a34eb39]
|
|
46
|
+
- Updated dependencies [b33ed7a]
|
|
47
|
+
- Updated dependencies [765f1cd]
|
|
48
|
+
- ai@5.0.0-canary.22
|
|
33
49
|
|
|
34
|
-
##
|
|
50
|
+
## 2.0.0-canary.20
|
|
35
51
|
|
|
36
52
|
### Patch Changes
|
|
37
53
|
|
|
38
|
-
-
|
|
39
|
-
-
|
|
54
|
+
- Updated dependencies [d964901]
|
|
55
|
+
- Updated dependencies [0560977]
|
|
56
|
+
- Updated dependencies [66af894]
|
|
57
|
+
- Updated dependencies [516be5b]
|
|
58
|
+
- Updated dependencies [bfbfc4c]
|
|
59
|
+
- Updated dependencies [ea7a7c9]
|
|
60
|
+
- Updated dependencies [1409e13]
|
|
61
|
+
- ai@5.0.0-canary.21
|
|
62
|
+
- @ai-sdk/provider-utils@3.0.0-canary.17
|
|
63
|
+
|
|
64
|
+
## 2.0.0-canary.19
|
|
65
|
+
|
|
66
|
+
### Major Changes
|
|
40
67
|
|
|
41
|
-
|
|
68
|
+
- 496bbc1: chore (ui): inline/remove ChatRequest type
|
|
42
69
|
|
|
43
70
|
### Patch Changes
|
|
44
71
|
|
|
45
|
-
- Updated dependencies [
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
- Updated dependencies [13fef90]
|
|
73
|
+
- Updated dependencies [e90d45d]
|
|
74
|
+
- Updated dependencies [bc3109f]
|
|
75
|
+
- Updated dependencies [496bbc1]
|
|
76
|
+
- Updated dependencies [da70d79]
|
|
77
|
+
- Updated dependencies [bcea599]
|
|
78
|
+
- Updated dependencies [48d675a]
|
|
79
|
+
- Updated dependencies [c7710a9]
|
|
80
|
+
- Updated dependencies [87b828f]
|
|
81
|
+
- Updated dependencies [35fc02c]
|
|
82
|
+
- Updated dependencies [b983b51]
|
|
83
|
+
- ai@5.0.0-canary.20
|
|
84
|
+
- @ai-sdk/provider-utils@3.0.0-canary.16
|
|
85
|
+
|
|
86
|
+
## 2.0.0-canary.18
|
|
87
|
+
|
|
88
|
+
### Patch Changes
|
|
89
|
+
|
|
90
|
+
- Updated dependencies [2d03e19]
|
|
91
|
+
- Updated dependencies [319b989]
|
|
92
|
+
- Updated dependencies [441d042]
|
|
93
|
+
- Updated dependencies [dcc549b]
|
|
94
|
+
- Updated dependencies [cb2b53a]
|
|
95
|
+
- Updated dependencies [e244a78]
|
|
96
|
+
- ai@5.0.0-canary.19
|
|
97
|
+
|
|
98
|
+
## 2.0.0-canary.17
|
|
99
|
+
|
|
100
|
+
### Patch Changes
|
|
101
|
+
|
|
102
|
+
- Updated dependencies [a571d6e]
|
|
103
|
+
- Updated dependencies [c60f895]
|
|
104
|
+
- Updated dependencies [332167b]
|
|
105
|
+
- Updated dependencies [a8c8bd5]
|
|
106
|
+
- Updated dependencies [a662dea]
|
|
107
|
+
- Updated dependencies [41fa418]
|
|
108
|
+
- @ai-sdk/provider-utils@3.0.0-canary.15
|
|
109
|
+
- ai@5.0.0-canary.18
|
|
110
|
+
|
|
111
|
+
## 2.0.0-canary.16
|
|
112
|
+
|
|
113
|
+
### Patch Changes
|
|
114
|
+
|
|
115
|
+
- c34ccd7: feat (ui/react): support resuming an ongoing stream
|
|
116
|
+
- Updated dependencies [f04fb4a]
|
|
117
|
+
- Updated dependencies [fd1924b]
|
|
118
|
+
- Updated dependencies [957b739]
|
|
119
|
+
- Updated dependencies [fafc3f2]
|
|
120
|
+
- Updated dependencies [c9ad635]
|
|
121
|
+
- Updated dependencies [9bd5ab5]
|
|
122
|
+
- Updated dependencies [92cb0a2]
|
|
123
|
+
- ai@5.0.0-canary.17
|
|
124
|
+
- @ai-sdk/provider-utils@3.0.0-canary.14
|
|
125
|
+
|
|
126
|
+
## 2.0.0-canary.15
|
|
127
|
+
|
|
128
|
+
### Patch Changes
|
|
129
|
+
|
|
130
|
+
- 6a0ff37: fix (react): integrate addToolResult into UseChatHelpers type without intersection
|
|
131
|
+
- Updated dependencies [ec78cdc]
|
|
132
|
+
- Updated dependencies [9b4d074]
|
|
133
|
+
- Updated dependencies [8b86e99]
|
|
134
|
+
- Updated dependencies [28ad69e]
|
|
135
|
+
- Updated dependencies [2524fc7]
|
|
136
|
+
- Updated dependencies [ec5933d]
|
|
137
|
+
- Updated dependencies [175b868]
|
|
138
|
+
- ai@5.0.0-canary.16
|
|
139
|
+
|
|
140
|
+
## 2.0.0-canary.14
|
|
141
|
+
|
|
142
|
+
### Patch Changes
|
|
143
|
+
|
|
144
|
+
- Updated dependencies [d9209ca]
|
|
145
|
+
- Updated dependencies [ea27cc6]
|
|
146
|
+
- Updated dependencies [0ff02bb]
|
|
147
|
+
- Updated dependencies [4bfe9ec]
|
|
148
|
+
- Updated dependencies [2877a74]
|
|
149
|
+
- ai@5.0.0-canary.15
|
|
150
|
+
- @ai-sdk/provider-utils@3.0.0-canary.13
|
|
151
|
+
|
|
152
|
+
## 2.0.0-canary.13
|
|
153
|
+
|
|
154
|
+
### Patch Changes
|
|
155
|
+
|
|
156
|
+
- Updated dependencies [9bf7291]
|
|
157
|
+
- Updated dependencies [4617fab]
|
|
158
|
+
- Updated dependencies [a76a62b]
|
|
159
|
+
- ai@5.0.0-canary.14
|
|
160
|
+
- @ai-sdk/provider-utils@3.0.0-canary.12
|
|
161
|
+
|
|
162
|
+
## 2.0.0-canary.12
|
|
163
|
+
|
|
164
|
+
### Patch Changes
|
|
165
|
+
|
|
166
|
+
- Updated dependencies [14cb3be]
|
|
167
|
+
- Updated dependencies [66962ed]
|
|
168
|
+
- Updated dependencies [9301f86]
|
|
169
|
+
- ai@5.0.0-canary.13
|
|
170
|
+
- @ai-sdk/provider-utils@3.0.0-canary.11
|
|
171
|
+
|
|
172
|
+
## 2.0.0-canary.11
|
|
173
|
+
|
|
174
|
+
### Patch Changes
|
|
175
|
+
|
|
176
|
+
- ai@5.0.0-canary.12
|
|
177
|
+
- @ai-sdk/provider-utils@3.0.0-canary.10
|
|
178
|
+
|
|
179
|
+
## 2.0.0-canary.10
|
|
180
|
+
|
|
181
|
+
### Patch Changes
|
|
182
|
+
|
|
183
|
+
- Updated dependencies [8e64e9c]
|
|
184
|
+
- ai@5.0.0-canary.11
|
|
185
|
+
- @ai-sdk/provider-utils@3.0.0-canary.9
|
|
186
|
+
|
|
187
|
+
## 2.0.0-canary.9
|
|
188
|
+
|
|
189
|
+
### Patch Changes
|
|
190
|
+
|
|
191
|
+
- Updated dependencies [d8aeaef]
|
|
192
|
+
- Updated dependencies [3e10408]
|
|
193
|
+
- ai@5.0.0-canary.10
|
|
194
|
+
|
|
195
|
+
## 2.0.0-canary.8
|
|
196
|
+
|
|
197
|
+
### Patch Changes
|
|
198
|
+
|
|
199
|
+
- Updated dependencies [a847c3e]
|
|
200
|
+
- Updated dependencies [5d142ab]
|
|
201
|
+
- Updated dependencies [cb9c9e4]
|
|
202
|
+
- Updated dependencies [8aa9e20]
|
|
203
|
+
- Updated dependencies [b32e192]
|
|
204
|
+
- ai@5.0.0-canary.9
|
|
205
|
+
- @ai-sdk/provider-utils@3.0.0-canary.8
|
|
206
|
+
|
|
207
|
+
## 2.0.0-canary.7
|
|
208
|
+
|
|
209
|
+
### Patch Changes
|
|
210
|
+
|
|
211
|
+
- Updated dependencies [5d1e3ba]
|
|
212
|
+
- Updated dependencies [26735b5]
|
|
213
|
+
- Updated dependencies [14c9410]
|
|
214
|
+
- Updated dependencies [7827a49]
|
|
215
|
+
- Updated dependencies [bd8a36c]
|
|
216
|
+
- Updated dependencies [b6f9f3c]
|
|
217
|
+
- Updated dependencies [92c8e66]
|
|
218
|
+
- Updated dependencies [fd65bc6]
|
|
219
|
+
- Updated dependencies [5bdff05]
|
|
220
|
+
- ai@5.0.0-canary.8
|
|
221
|
+
- @ai-sdk/provider-utils@3.0.0-canary.7
|
|
222
|
+
|
|
223
|
+
## 2.0.0-canary.6
|
|
224
|
+
|
|
225
|
+
### Patch Changes
|
|
226
|
+
|
|
227
|
+
- Updated dependencies [0b78e17]
|
|
228
|
+
- Updated dependencies [6fba4c7]
|
|
229
|
+
- Updated dependencies [3e3b9df]
|
|
230
|
+
- Updated dependencies [1766ede]
|
|
231
|
+
- Updated dependencies [f10304b]
|
|
232
|
+
- ai@5.0.0-canary.7
|
|
233
|
+
- @ai-sdk/provider-utils@3.0.0-canary.6
|
|
234
|
+
|
|
235
|
+
## 2.0.0-canary.5
|
|
236
|
+
|
|
237
|
+
### Patch Changes
|
|
238
|
+
|
|
239
|
+
- ai@5.0.0-canary.6
|
|
240
|
+
- @ai-sdk/provider-utils@3.0.0-canary.5
|
|
241
|
+
|
|
242
|
+
## 2.0.0-canary.4
|
|
243
|
+
|
|
244
|
+
### Patch Changes
|
|
245
|
+
|
|
246
|
+
- Updated dependencies [b71fe8d]
|
|
247
|
+
- Updated dependencies [d91b50d]
|
|
248
|
+
- ai@5.0.0-canary.5
|
|
249
|
+
- @ai-sdk/provider-utils@3.0.0-canary.4
|
|
250
|
+
|
|
251
|
+
## 2.0.0-canary.3
|
|
252
|
+
|
|
253
|
+
### Patch Changes
|
|
254
|
+
|
|
255
|
+
- Updated dependencies [a166433]
|
|
256
|
+
- Updated dependencies [9f95b35]
|
|
257
|
+
- @ai-sdk/provider-utils@3.0.0-canary.3
|
|
258
|
+
- @ai-sdk/ui-utils@2.0.0-canary.3
|
|
259
|
+
|
|
260
|
+
## 2.0.0-canary.2
|
|
261
|
+
|
|
262
|
+
### Patch Changes
|
|
263
|
+
|
|
264
|
+
- @ai-sdk/provider-utils@3.0.0-canary.2
|
|
265
|
+
- @ai-sdk/ui-utils@2.0.0-canary.2
|
|
266
|
+
|
|
267
|
+
## 2.0.0-canary.1
|
|
268
|
+
|
|
269
|
+
### Patch Changes
|
|
270
|
+
|
|
271
|
+
- Updated dependencies [060370c]
|
|
272
|
+
- Updated dependencies [0c0c0b3]
|
|
273
|
+
- Updated dependencies [63d791d]
|
|
274
|
+
- @ai-sdk/provider-utils@3.0.0-canary.1
|
|
275
|
+
- @ai-sdk/ui-utils@2.0.0-canary.1
|
|
276
|
+
|
|
277
|
+
## 2.0.0-canary.0
|
|
278
|
+
|
|
279
|
+
### Major Changes
|
|
48
280
|
|
|
49
|
-
|
|
281
|
+
- d5f588f: AI SDK 5
|
|
282
|
+
- 9477ebb: chore (ui): remove useAssistant hook (**breaking change**)
|
|
50
283
|
|
|
51
284
|
### Patch Changes
|
|
52
285
|
|
|
53
|
-
- Updated dependencies [
|
|
54
|
-
|
|
55
|
-
- @ai-sdk/
|
|
286
|
+
- Updated dependencies [d5f588f]
|
|
287
|
+
- Updated dependencies [9477ebb]
|
|
288
|
+
- @ai-sdk/provider-utils@3.0.0-canary.0
|
|
289
|
+
- @ai-sdk/ui-utils@2.0.0-canary.0
|
|
56
290
|
|
|
57
291
|
## 1.2.5
|
|
58
292
|
|
package/README.md
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
|
|
5
5
|
- [`useChat`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) hook
|
|
6
6
|
- [`useCompletion`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) hook
|
|
7
|
-
- [`
|
|
7
|
+
- [`useObject`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) hook
|
package/dist/index.d.mts
CHANGED
|
@@ -1,79 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { UIDataTypesSchemas, UIMessage, InferUIDataTypes, CreateUIMessage, ChatRequestOptions, FileUIPart, UseChatOptions, 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
|
|
6
|
+
type UseChatHelpers<MESSAGE_METADATA = unknown, DATA_TYPE_SCHEMAS extends UIDataTypesSchemas = UIDataTypesSchemas> = {
|
|
7
7
|
/**
|
|
8
|
-
* The
|
|
8
|
+
* The id of the chat.
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
readonly chatId: string;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* The
|
|
17
|
-
|
|
18
|
-
threadId: string | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Set the current thread ID. Specifying a thread ID will switch to that thread, if it exists. If set to 'undefined', a new thread will be created. For both cases, `threadId` will be updated with the new value and `messages` will be cleared.
|
|
21
|
-
*/
|
|
22
|
-
setThreadId: (threadId: string | undefined) => void;
|
|
23
|
-
/**
|
|
24
|
-
* The current value of the input field.
|
|
25
|
-
*/
|
|
26
|
-
input: string;
|
|
27
|
-
/**
|
|
28
|
-
* Append a user message to the chat list. This triggers the API call to fetch
|
|
29
|
-
* the assistant's response.
|
|
30
|
-
* @param message The message to append
|
|
31
|
-
* @param requestOptions Additional options to pass to the API call
|
|
32
|
-
*/
|
|
33
|
-
append: (message: Message | CreateMessage, requestOptions?: {
|
|
34
|
-
data?: Record<string, string>;
|
|
35
|
-
}) => Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
Abort the current request immediately, keep the generated tokens if any.
|
|
38
|
-
*/
|
|
39
|
-
stop: () => void;
|
|
40
|
-
/**
|
|
41
|
-
* setState-powered method to update the input value.
|
|
42
|
-
*/
|
|
43
|
-
setInput: React.Dispatch<React.SetStateAction<string>>;
|
|
44
|
-
/**
|
|
45
|
-
* Handler for the `onChange` event of the input field to control the input's value.
|
|
46
|
-
*/
|
|
47
|
-
handleInputChange: (event: React.ChangeEvent<HTMLInputElement> | React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
48
|
-
/**
|
|
49
|
-
* Form submission handler that automatically resets the input field and appends a user message.
|
|
50
|
-
*/
|
|
51
|
-
submitMessage: (event?: React.FormEvent<HTMLFormElement>, requestOptions?: {
|
|
52
|
-
data?: Record<string, string>;
|
|
53
|
-
}) => Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* The current status of the assistant. This can be used to show a loading indicator.
|
|
56
|
-
*/
|
|
57
|
-
status: AssistantStatus;
|
|
58
|
-
/**
|
|
59
|
-
* The error thrown during the assistant message processing, if any.
|
|
12
|
+
* Hook status:
|
|
13
|
+
*
|
|
14
|
+
* - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.
|
|
15
|
+
* - `streaming`: The response is actively streaming in from the API, receiving chunks of data.
|
|
16
|
+
* - `ready`: The full response has been received and processed; a new user message can be submitted.
|
|
17
|
+
* - `error`: An error occurred during the API request, preventing successful completion.
|
|
60
18
|
*/
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
declare function useAssistant({ api, threadId: threadIdParam, credentials, headers, body, onError, fetch, }: UseAssistantOptions): UseAssistantHelpers;
|
|
64
|
-
|
|
65
|
-
type UseChatHelpers = {
|
|
19
|
+
readonly status: 'submitted' | 'streaming' | 'ready' | 'error';
|
|
66
20
|
/** Current messages in the chat */
|
|
67
|
-
messages: UIMessage[];
|
|
21
|
+
readonly messages: UIMessage<MESSAGE_METADATA, InferUIDataTypes<DATA_TYPE_SCHEMAS>>[];
|
|
68
22
|
/** The error object of the API request */
|
|
69
|
-
error: undefined | Error;
|
|
23
|
+
readonly error: undefined | Error;
|
|
70
24
|
/**
|
|
71
25
|
* Append a user message to the chat list. This triggers the API call to fetch
|
|
72
26
|
* the assistant's response.
|
|
27
|
+
*
|
|
73
28
|
* @param message The message to append
|
|
74
29
|
* @param options Additional options to pass to the API call
|
|
75
30
|
*/
|
|
76
|
-
append: (message:
|
|
31
|
+
append: (message: CreateUIMessage<MESSAGE_METADATA, InferUIDataTypes<DATA_TYPE_SCHEMAS>>, options?: ChatRequestOptions) => Promise<void>;
|
|
77
32
|
/**
|
|
78
33
|
* Reload the last AI chat response for the given chat history. If the last
|
|
79
34
|
* message isn't from the assistant, it will request the API to generate a
|
|
@@ -93,7 +48,7 @@ type UseChatHelpers = {
|
|
|
93
48
|
* edit the messages on the client, and then trigger the `reload` method
|
|
94
49
|
* manually to regenerate the AI response.
|
|
95
50
|
*/
|
|
96
|
-
setMessages: (messages:
|
|
51
|
+
setMessages: (messages: UIMessage<MESSAGE_METADATA, InferUIDataTypes<DATA_TYPE_SCHEMAS>>[] | ((messages: UIMessage<MESSAGE_METADATA, InferUIDataTypes<DATA_TYPE_SCHEMAS>>[]) => UIMessage<MESSAGE_METADATA, InferUIDataTypes<DATA_TYPE_SCHEMAS>>[])) => void;
|
|
97
52
|
/** The current value of the input */
|
|
98
53
|
input: string;
|
|
99
54
|
/** setState-powered method to update the input value */
|
|
@@ -103,67 +58,21 @@ type UseChatHelpers = {
|
|
|
103
58
|
/** Form submission handler to automatically reset input and append a user message */
|
|
104
59
|
handleSubmit: (event?: {
|
|
105
60
|
preventDefault?: () => void;
|
|
106
|
-
}, chatRequestOptions?: ChatRequestOptions
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
isLoading: boolean;
|
|
114
|
-
/**
|
|
115
|
-
* Hook status:
|
|
116
|
-
*
|
|
117
|
-
* - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.
|
|
118
|
-
* - `streaming`: The response is actively streaming in from the API, receiving chunks of data.
|
|
119
|
-
* - `ready`: The full response has been received and processed; a new user message can be submitted.
|
|
120
|
-
* - `error`: An error occurred during the API request, preventing successful completion.
|
|
121
|
-
*/
|
|
122
|
-
status: 'submitted' | 'streaming' | 'ready' | 'error';
|
|
123
|
-
/** Additional data added on the server via StreamData. */
|
|
124
|
-
data?: JSONValue[];
|
|
125
|
-
/** Set the data of the chat. You can use this to transform or clear the chat data. */
|
|
126
|
-
setData: (data: JSONValue[] | undefined | ((data: JSONValue[] | undefined) => JSONValue[] | undefined)) => void;
|
|
127
|
-
/** The id of the chat */
|
|
128
|
-
id: string;
|
|
61
|
+
}, chatRequestOptions?: ChatRequestOptions & {
|
|
62
|
+
files?: FileList | FileUIPart[];
|
|
63
|
+
}) => void;
|
|
64
|
+
addToolResult: ({ toolCallId, result, }: {
|
|
65
|
+
toolCallId: string;
|
|
66
|
+
result: any;
|
|
67
|
+
}) => void;
|
|
129
68
|
};
|
|
130
|
-
declare function useChat
|
|
131
|
-
key?: string;
|
|
132
|
-
/**
|
|
133
|
-
* Experimental (React only). When a function is provided, it will be used
|
|
134
|
-
* to prepare the request body for the chat API. This can be useful for
|
|
135
|
-
* customizing the request body based on the messages and data in the chat.
|
|
136
|
-
*
|
|
137
|
-
* @param messages The current messages in the chat.
|
|
138
|
-
* @param requestData The data object passed in the chat request.
|
|
139
|
-
* @param requestBody The request body object passed in the chat request.
|
|
140
|
-
*/
|
|
141
|
-
experimental_prepareRequestBody?: (options: {
|
|
142
|
-
id: string;
|
|
143
|
-
messages: UIMessage[];
|
|
144
|
-
requestData?: JSONValue;
|
|
145
|
-
requestBody?: object;
|
|
146
|
-
}) => unknown;
|
|
69
|
+
declare function useChat<MESSAGE_METADATA = unknown, DATA_TYPE_SCHEMAS extends UIDataTypesSchemas = UIDataTypesSchemas>({ chatId, initialInput, onToolCall, onFinish, onError, generateId, experimental_throttle: throttleWaitMs, chatStore: chatStoreArg, }?: UseChatOptions<MESSAGE_METADATA, DATA_TYPE_SCHEMAS> & {
|
|
147
70
|
/**
|
|
148
71
|
Custom throttle wait in ms for the chat messages and data updates.
|
|
149
72
|
Default is undefined, which disables throttling.
|
|
150
73
|
*/
|
|
151
74
|
experimental_throttle?: number;
|
|
152
|
-
|
|
153
|
-
Maximum number of sequential LLM calls (steps), e.g. when you use tool calls.
|
|
154
|
-
Must be at least 1.
|
|
155
|
-
|
|
156
|
-
A maximum number is required to prevent infinite loops in the case of misconfigured tools.
|
|
157
|
-
|
|
158
|
-
By default, it's set to 1, which means that only a single LLM call is made.
|
|
159
|
-
*/
|
|
160
|
-
maxSteps?: number;
|
|
161
|
-
}): UseChatHelpers & {
|
|
162
|
-
addToolResult: ({ toolCallId, result, }: {
|
|
163
|
-
toolCallId: string;
|
|
164
|
-
result: any;
|
|
165
|
-
}) => void;
|
|
166
|
-
};
|
|
75
|
+
}): UseChatHelpers<MESSAGE_METADATA, DATA_TYPE_SCHEMAS>;
|
|
167
76
|
|
|
168
77
|
type UseCompletionHelpers = {
|
|
169
78
|
/** The current completion result */
|
|
@@ -171,7 +80,7 @@ type UseCompletionHelpers = {
|
|
|
171
80
|
/**
|
|
172
81
|
* Send a new prompt to the API endpoint and update the completion state.
|
|
173
82
|
*/
|
|
174
|
-
complete: (prompt: string, options?:
|
|
83
|
+
complete: (prompt: string, options?: CompletionRequestOptions) => Promise<string | null | undefined>;
|
|
175
84
|
/** The error object of the API request */
|
|
176
85
|
error: undefined | Error;
|
|
177
86
|
/**
|
|
@@ -208,10 +117,8 @@ type UseCompletionHelpers = {
|
|
|
208
117
|
}) => void;
|
|
209
118
|
/** Whether the API request is in progress */
|
|
210
119
|
isLoading: boolean;
|
|
211
|
-
/** Additional data added on the server via StreamData */
|
|
212
|
-
data?: JSONValue[];
|
|
213
120
|
};
|
|
214
|
-
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamProtocol, fetch,
|
|
121
|
+
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, streamProtocol, fetch, onFinish, onError, experimental_throttle: throttleWaitMs, }?: UseCompletionOptions & {
|
|
215
122
|
/**
|
|
216
123
|
* Custom throttle wait in ms for the completion and data updates.
|
|
217
124
|
* Default is undefined, which disables throttling.
|
|
@@ -298,4 +205,4 @@ declare function useObject<RESULT, INPUT = any>({ api, id, schema, // required,
|
|
|
298
205
|
initialValue, fetch, onError, onFinish, headers, credentials, }: Experimental_UseObjectOptions<RESULT>): Experimental_UseObjectHelpers<RESULT, INPUT>;
|
|
299
206
|
declare const experimental_useObject: typeof useObject;
|
|
300
207
|
|
|
301
|
-
export { Experimental_UseObjectHelpers, Experimental_UseObjectOptions,
|
|
208
|
+
export { Experimental_UseObjectHelpers, Experimental_UseObjectOptions, UseChatHelpers, UseCompletionHelpers, experimental_useObject, useChat, useCompletion };
|