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