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