@ai-sdk/vue 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 +251 -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/dist/index.js
CHANGED
|
@@ -30,14 +30,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
-
useAssistant: () => useAssistant,
|
|
34
33
|
useChat: () => useChat,
|
|
35
34
|
useCompletion: () => useCompletion
|
|
36
35
|
});
|
|
37
36
|
module.exports = __toCommonJS(src_exports);
|
|
38
37
|
|
|
39
38
|
// src/use-chat.ts
|
|
40
|
-
var
|
|
39
|
+
var import_ai = require("ai");
|
|
41
40
|
var import_swrv = __toESM(require("swrv"));
|
|
42
41
|
var import_vue = require("vue");
|
|
43
42
|
var useSWRV = import_swrv.default.default || import_swrv.default;
|
|
@@ -45,94 +44,59 @@ var store = {};
|
|
|
45
44
|
var statusStore = {};
|
|
46
45
|
function useChat({
|
|
47
46
|
api = "/api/chat",
|
|
48
|
-
|
|
47
|
+
chatId,
|
|
49
48
|
initialMessages = [],
|
|
50
49
|
initialInput = "",
|
|
51
|
-
|
|
52
|
-
streamProtocol = "data",
|
|
53
|
-
onResponse,
|
|
50
|
+
streamProtocol = "ui-message",
|
|
54
51
|
onFinish,
|
|
55
52
|
onError,
|
|
56
53
|
credentials,
|
|
57
54
|
headers: metadataHeaders,
|
|
58
55
|
body: metadataBody,
|
|
59
|
-
generateId
|
|
56
|
+
generateId = import_ai.generateId,
|
|
60
57
|
onToolCall,
|
|
61
|
-
fetch
|
|
62
|
-
keepLastMessageOnError = true,
|
|
58
|
+
fetch,
|
|
63
59
|
maxSteps = 1,
|
|
64
|
-
experimental_prepareRequestBody
|
|
60
|
+
experimental_prepareRequestBody,
|
|
61
|
+
messageMetadataSchema
|
|
65
62
|
} = {
|
|
66
63
|
maxSteps: 1
|
|
67
64
|
}) {
|
|
68
65
|
var _a, _b;
|
|
69
|
-
const
|
|
70
|
-
const key = `${api}|${
|
|
71
|
-
const { data: messagesData, mutate: originalMutate } = useSWRV(
|
|
72
|
-
|
|
73
|
-
()
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
);
|
|
78
|
-
const status = (_a = statusStore[chatId]) != null ? _a : statusStore[chatId] = (0, import_vue.ref)(
|
|
79
|
-
"ready"
|
|
80
|
-
);
|
|
81
|
-
(_b = messagesData.value) != null ? _b : messagesData.value = (0, import_ui_utils.fillMessageParts)(initialMessages);
|
|
66
|
+
const stableChatId = chatId != null ? chatId : generateId();
|
|
67
|
+
const key = `${api}|${stableChatId}`;
|
|
68
|
+
const { data: messagesData, mutate: originalMutate } = useSWRV(key, () => {
|
|
69
|
+
var _a2;
|
|
70
|
+
return (_a2 = store[key]) != null ? _a2 : initialMessages;
|
|
71
|
+
});
|
|
72
|
+
const status = (_a = statusStore[stableChatId]) != null ? _a : statusStore[stableChatId] = (0, import_vue.ref)("ready");
|
|
73
|
+
(_b = messagesData.value) != null ? _b : messagesData.value = initialMessages;
|
|
82
74
|
const mutate = (data) => {
|
|
83
75
|
store[key] = data;
|
|
84
76
|
return originalMutate();
|
|
85
77
|
};
|
|
86
78
|
const messages = messagesData;
|
|
87
79
|
const error = (0, import_vue.ref)(void 0);
|
|
88
|
-
const streamData = (0, import_vue.ref)(void 0);
|
|
89
80
|
let abortController = null;
|
|
90
|
-
async function triggerRequest(messagesSnapshot, {
|
|
91
|
-
var _a2
|
|
81
|
+
async function triggerRequest(messagesSnapshot, { headers, body } = {}) {
|
|
82
|
+
var _a2;
|
|
92
83
|
error.value = void 0;
|
|
93
84
|
status.value = "submitted";
|
|
94
85
|
const messageCount = messages.value.length;
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
);
|
|
86
|
+
const lastMessage = messages.value.at(-1);
|
|
87
|
+
const maxStep = lastMessage != null ? (0, import_ai.extractMaxToolInvocationStep)((0, import_ai.getToolInvocations)(lastMessage)) : 0;
|
|
98
88
|
try {
|
|
99
89
|
abortController = new AbortController();
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
mutate(chatMessages);
|
|
103
|
-
const existingData = (_b2 = streamData.value) != null ? _b2 : [];
|
|
104
|
-
const constructedMessagesPayload = sendExtraMessageFields ? chatMessages : chatMessages.map(
|
|
105
|
-
({
|
|
106
|
-
role,
|
|
107
|
-
content,
|
|
108
|
-
experimental_attachments,
|
|
109
|
-
data: data2,
|
|
110
|
-
annotations,
|
|
111
|
-
toolInvocations,
|
|
112
|
-
parts
|
|
113
|
-
}) => ({
|
|
114
|
-
role,
|
|
115
|
-
content,
|
|
116
|
-
...experimental_attachments !== void 0 && {
|
|
117
|
-
experimental_attachments
|
|
118
|
-
},
|
|
119
|
-
...data2 !== void 0 && { data: data2 },
|
|
120
|
-
...annotations !== void 0 && { annotations },
|
|
121
|
-
...toolInvocations !== void 0 && { toolInvocations },
|
|
122
|
-
...parts !== void 0 && { parts }
|
|
123
|
-
})
|
|
124
|
-
);
|
|
125
|
-
await (0, import_ui_utils.callChatApi)({
|
|
90
|
+
mutate(messagesSnapshot);
|
|
91
|
+
await (0, import_ai.callChatApi)({
|
|
126
92
|
api,
|
|
127
|
-
body: (
|
|
128
|
-
|
|
129
|
-
messages:
|
|
130
|
-
requestData: data,
|
|
93
|
+
body: (_a2 = experimental_prepareRequestBody == null ? void 0 : experimental_prepareRequestBody({
|
|
94
|
+
chatId: stableChatId,
|
|
95
|
+
messages: messagesSnapshot,
|
|
131
96
|
requestBody: body
|
|
132
|
-
})) != null ?
|
|
133
|
-
|
|
134
|
-
messages:
|
|
135
|
-
data,
|
|
97
|
+
})) != null ? _a2 : {
|
|
98
|
+
chatId: stableChatId,
|
|
99
|
+
messages: messagesSnapshot,
|
|
136
100
|
...(0, import_vue.unref)(metadataBody),
|
|
137
101
|
// Use unref to unwrap the ref value
|
|
138
102
|
...body
|
|
@@ -144,28 +108,23 @@ function useChat({
|
|
|
144
108
|
},
|
|
145
109
|
abortController: () => abortController,
|
|
146
110
|
credentials,
|
|
147
|
-
|
|
148
|
-
onUpdate({ message, data: data2, replaceLastMessage }) {
|
|
111
|
+
onUpdate({ message }) {
|
|
149
112
|
status.value = "streaming";
|
|
113
|
+
const replaceLastMessage = message.id === messagesSnapshot[messagesSnapshot.length - 1].id;
|
|
150
114
|
mutate([
|
|
151
|
-
...replaceLastMessage ?
|
|
115
|
+
...replaceLastMessage ? messagesSnapshot.slice(0, messagesSnapshot.length - 1) : messagesSnapshot,
|
|
152
116
|
message
|
|
153
117
|
]);
|
|
154
|
-
if (data2 == null ? void 0 : data2.length) {
|
|
155
|
-
streamData.value = [...existingData, ...data2];
|
|
156
|
-
}
|
|
157
118
|
},
|
|
158
119
|
onFinish,
|
|
159
|
-
|
|
160
|
-
if (!keepLastMessageOnError) {
|
|
161
|
-
mutate(previousMessages);
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
generateId: generateId2,
|
|
120
|
+
generateId,
|
|
165
121
|
onToolCall,
|
|
166
|
-
fetch
|
|
122
|
+
fetch,
|
|
167
123
|
// enabled use of structured clone in processChatResponse:
|
|
168
|
-
lastMessage: recursiveToRaw(
|
|
124
|
+
lastMessage: recursiveToRaw(
|
|
125
|
+
messagesSnapshot[messagesSnapshot.length - 1]
|
|
126
|
+
),
|
|
127
|
+
messageMetadataSchema
|
|
169
128
|
});
|
|
170
129
|
status.value = "ready";
|
|
171
130
|
} catch (err) {
|
|
@@ -182,7 +141,7 @@ function useChat({
|
|
|
182
141
|
} finally {
|
|
183
142
|
abortController = null;
|
|
184
143
|
}
|
|
185
|
-
if ((0,
|
|
144
|
+
if ((0, import_ai.shouldResubmitMessages)({
|
|
186
145
|
originalMaxToolInvocationStep: maxStep,
|
|
187
146
|
originalMessageCount: messageCount,
|
|
188
147
|
maxSteps,
|
|
@@ -192,17 +151,12 @@ function useChat({
|
|
|
192
151
|
}
|
|
193
152
|
}
|
|
194
153
|
const append = async (message, options) => {
|
|
195
|
-
var _a2
|
|
196
|
-
const attachmentsForRequest = await (0, import_ui_utils.prepareAttachmentsForRequest)(
|
|
197
|
-
(_a2 = options == null ? void 0 : options.experimental_attachments) != null ? _a2 : message.experimental_attachments
|
|
198
|
-
);
|
|
154
|
+
var _a2;
|
|
199
155
|
return triggerRequest(
|
|
200
156
|
messages.value.concat({
|
|
201
157
|
...message,
|
|
202
|
-
id: (
|
|
203
|
-
|
|
204
|
-
experimental_attachments: attachmentsForRequest.length > 0 ? attachmentsForRequest : void 0,
|
|
205
|
-
parts: (0, import_ui_utils.getMessageParts)(message)
|
|
158
|
+
id: (_a2 = message.id) != null ? _a2 : generateId(),
|
|
159
|
+
parts: message.parts
|
|
206
160
|
}),
|
|
207
161
|
options
|
|
208
162
|
);
|
|
@@ -227,32 +181,21 @@ function useChat({
|
|
|
227
181
|
if (typeof messagesArg === "function") {
|
|
228
182
|
messagesArg = messagesArg(messages.value);
|
|
229
183
|
}
|
|
230
|
-
mutate(
|
|
231
|
-
};
|
|
232
|
-
const setData = (dataArg) => {
|
|
233
|
-
if (typeof dataArg === "function") {
|
|
234
|
-
dataArg = dataArg(streamData.value);
|
|
235
|
-
}
|
|
236
|
-
streamData.value = dataArg;
|
|
184
|
+
mutate(messagesArg);
|
|
237
185
|
};
|
|
238
186
|
const input = (0, import_vue.ref)(initialInput);
|
|
239
187
|
const handleSubmit = async (event, options = {}) => {
|
|
240
188
|
var _a2;
|
|
241
189
|
(_a2 = event == null ? void 0 : event.preventDefault) == null ? void 0 : _a2.call(event);
|
|
242
190
|
const inputValue = input.value;
|
|
243
|
-
|
|
191
|
+
const fileParts = Array.isArray(options == null ? void 0 : options.files) ? options.files : await (0, import_ai.convertFileListToFileUIParts)(options == null ? void 0 : options.files);
|
|
192
|
+
if (!inputValue && fileParts.length === 0)
|
|
244
193
|
return;
|
|
245
|
-
const attachmentsForRequest = await (0, import_ui_utils.prepareAttachmentsForRequest)(
|
|
246
|
-
options.experimental_attachments
|
|
247
|
-
);
|
|
248
194
|
triggerRequest(
|
|
249
195
|
messages.value.concat({
|
|
250
|
-
id:
|
|
251
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
252
|
-
content: inputValue,
|
|
196
|
+
id: generateId(),
|
|
253
197
|
role: "user",
|
|
254
|
-
|
|
255
|
-
parts: [{ type: "text", text: inputValue }]
|
|
198
|
+
parts: [...fileParts, { type: "text", text: inputValue }]
|
|
256
199
|
}),
|
|
257
200
|
options
|
|
258
201
|
);
|
|
@@ -263,7 +206,7 @@ function useChat({
|
|
|
263
206
|
result
|
|
264
207
|
}) => {
|
|
265
208
|
const currentMessages = messages.value;
|
|
266
|
-
(0,
|
|
209
|
+
(0, import_ai.updateToolCallResult)({
|
|
267
210
|
messages: currentMessages,
|
|
268
211
|
toolCallId,
|
|
269
212
|
toolResult: result
|
|
@@ -273,12 +216,12 @@ function useChat({
|
|
|
273
216
|
return;
|
|
274
217
|
}
|
|
275
218
|
const lastMessage = currentMessages[currentMessages.length - 1];
|
|
276
|
-
if ((0,
|
|
219
|
+
if ((0, import_ai.isAssistantMessageWithCompletedToolCalls)(lastMessage)) {
|
|
277
220
|
triggerRequest(currentMessages);
|
|
278
221
|
}
|
|
279
222
|
};
|
|
280
223
|
return {
|
|
281
|
-
|
|
224
|
+
chatId: stableChatId,
|
|
282
225
|
messages,
|
|
283
226
|
append,
|
|
284
227
|
error,
|
|
@@ -287,12 +230,7 @@ function useChat({
|
|
|
287
230
|
setMessages,
|
|
288
231
|
input,
|
|
289
232
|
handleSubmit,
|
|
290
|
-
isLoading: (0, import_vue.computed)(
|
|
291
|
-
() => status.value === "submitted" || status.value === "streaming"
|
|
292
|
-
),
|
|
293
233
|
status,
|
|
294
|
-
data: streamData,
|
|
295
|
-
setData,
|
|
296
234
|
addToolResult
|
|
297
235
|
};
|
|
298
236
|
}
|
|
@@ -311,7 +249,7 @@ function recursiveToRaw(inputValue) {
|
|
|
311
249
|
}
|
|
312
250
|
|
|
313
251
|
// src/use-completion.ts
|
|
314
|
-
var
|
|
252
|
+
var import_ai2 = require("ai");
|
|
315
253
|
var import_swrv2 = __toESM(require("swrv"));
|
|
316
254
|
var import_vue2 = require("vue");
|
|
317
255
|
var uniqueId = 0;
|
|
@@ -326,10 +264,9 @@ function useCompletion({
|
|
|
326
264
|
headers,
|
|
327
265
|
body,
|
|
328
266
|
streamProtocol,
|
|
329
|
-
onResponse,
|
|
330
267
|
onFinish,
|
|
331
268
|
onError,
|
|
332
|
-
fetch
|
|
269
|
+
fetch
|
|
333
270
|
} = {}) {
|
|
334
271
|
var _a;
|
|
335
272
|
const completionId = id || `completion-${uniqueId++}`;
|
|
@@ -343,7 +280,6 @@ function useCompletion({
|
|
|
343
280
|
null
|
|
344
281
|
);
|
|
345
282
|
(_a = isLoading.value) != null ? _a : isLoading.value = false;
|
|
346
|
-
const { data: streamData, mutate: mutateStreamData } = useSWRV2(`${completionId}-data`, null);
|
|
347
283
|
data.value || (data.value = initialCompletion);
|
|
348
284
|
const mutate = (data2) => {
|
|
349
285
|
store2[key] = data2;
|
|
@@ -353,9 +289,7 @@ function useCompletion({
|
|
|
353
289
|
const error = (0, import_vue2.ref)(void 0);
|
|
354
290
|
let abortController = null;
|
|
355
291
|
async function triggerRequest(prompt, options) {
|
|
356
|
-
|
|
357
|
-
const existingData = (_a2 = streamData.value) != null ? _a2 : [];
|
|
358
|
-
return (0, import_ui_utils2.callCompletionApi)({
|
|
292
|
+
return (0, import_ai2.callCompletionApi)({
|
|
359
293
|
api,
|
|
360
294
|
prompt,
|
|
361
295
|
credentials,
|
|
@@ -376,13 +310,9 @@ function useCompletion({
|
|
|
376
310
|
setAbortController: (controller) => {
|
|
377
311
|
abortController = controller;
|
|
378
312
|
},
|
|
379
|
-
onResponse,
|
|
380
313
|
onFinish,
|
|
381
314
|
onError,
|
|
382
|
-
|
|
383
|
-
mutateStreamData(() => [...existingData, ...data2 != null ? data2 : []]);
|
|
384
|
-
},
|
|
385
|
-
fetch: fetch2
|
|
315
|
+
fetch
|
|
386
316
|
});
|
|
387
317
|
}
|
|
388
318
|
const complete = async (prompt, options) => {
|
|
@@ -412,182 +342,11 @@ function useCompletion({
|
|
|
412
342
|
setCompletion,
|
|
413
343
|
input,
|
|
414
344
|
handleSubmit,
|
|
415
|
-
isLoading
|
|
416
|
-
data: streamData
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// src/use-assistant.ts
|
|
421
|
-
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
422
|
-
var import_ui_utils3 = require("@ai-sdk/ui-utils");
|
|
423
|
-
var import_vue3 = require("vue");
|
|
424
|
-
function useAssistant({
|
|
425
|
-
api,
|
|
426
|
-
threadId: threadIdParam,
|
|
427
|
-
credentials,
|
|
428
|
-
headers,
|
|
429
|
-
body,
|
|
430
|
-
onError
|
|
431
|
-
}) {
|
|
432
|
-
const messages = (0, import_vue3.ref)([]);
|
|
433
|
-
const input = (0, import_vue3.ref)("");
|
|
434
|
-
const currentThreadId = (0, import_vue3.ref)(void 0);
|
|
435
|
-
const status = (0, import_vue3.ref)("awaiting_message");
|
|
436
|
-
const error = (0, import_vue3.ref)(void 0);
|
|
437
|
-
const setMessages = (messageFactory) => {
|
|
438
|
-
messages.value = messageFactory(messages.value);
|
|
439
|
-
};
|
|
440
|
-
const setCurrentThreadId = (newThreadId) => {
|
|
441
|
-
currentThreadId.value = newThreadId;
|
|
442
|
-
messages.value = [];
|
|
443
|
-
};
|
|
444
|
-
const handleInputChange = (event) => {
|
|
445
|
-
var _a;
|
|
446
|
-
input.value = (_a = event == null ? void 0 : event.target) == null ? void 0 : _a.value;
|
|
447
|
-
};
|
|
448
|
-
const isSending = (0, import_vue3.computed)(() => status.value === "in_progress");
|
|
449
|
-
const abortController = (0, import_vue3.ref)(null);
|
|
450
|
-
const stop = (0, import_vue3.computed)(() => {
|
|
451
|
-
return () => {
|
|
452
|
-
if (abortController.value) {
|
|
453
|
-
abortController.value.abort();
|
|
454
|
-
abortController.value = null;
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
});
|
|
458
|
-
const append = async (message, requestOptions) => {
|
|
459
|
-
var _a, _b, _c, _d;
|
|
460
|
-
status.value = "in_progress";
|
|
461
|
-
const newMessage = {
|
|
462
|
-
...message,
|
|
463
|
-
id: (_a = message.id) != null ? _a : (0, import_ui_utils3.generateId)()
|
|
464
|
-
};
|
|
465
|
-
setMessages((messages2) => [...messages2, newMessage]);
|
|
466
|
-
input.value = "";
|
|
467
|
-
const controller = new AbortController();
|
|
468
|
-
try {
|
|
469
|
-
abortController.value = controller;
|
|
470
|
-
const response = await fetch(api, {
|
|
471
|
-
method: "POST",
|
|
472
|
-
headers: {
|
|
473
|
-
"Content-Type": "application/json",
|
|
474
|
-
...headers
|
|
475
|
-
},
|
|
476
|
-
body: JSON.stringify({
|
|
477
|
-
...body,
|
|
478
|
-
// Message Content
|
|
479
|
-
message: message.content,
|
|
480
|
-
// Always Use User Provided Thread ID When Available
|
|
481
|
-
threadId: (_b = threadIdParam != null ? threadIdParam : currentThreadId.value) != null ? _b : null,
|
|
482
|
-
// Optional Request Data
|
|
483
|
-
...(requestOptions == null ? void 0 : requestOptions.data) && { data: requestOptions == null ? void 0 : requestOptions.data }
|
|
484
|
-
}),
|
|
485
|
-
signal: controller.signal,
|
|
486
|
-
credentials
|
|
487
|
-
});
|
|
488
|
-
if (!response.ok) {
|
|
489
|
-
throw new Error(
|
|
490
|
-
(_c = response.statusText) != null ? _c : "An error occurred while sending the message"
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
if (!response.body) {
|
|
494
|
-
throw new Error("The response body is empty");
|
|
495
|
-
}
|
|
496
|
-
await (0, import_ui_utils3.processAssistantStream)({
|
|
497
|
-
stream: response.body,
|
|
498
|
-
onAssistantMessagePart(value) {
|
|
499
|
-
messages.value = [
|
|
500
|
-
...messages.value,
|
|
501
|
-
{
|
|
502
|
-
id: value.id,
|
|
503
|
-
content: value.content[0].text.value,
|
|
504
|
-
role: value.role,
|
|
505
|
-
parts: []
|
|
506
|
-
}
|
|
507
|
-
];
|
|
508
|
-
},
|
|
509
|
-
onTextPart(value) {
|
|
510
|
-
setMessages((messages2) => {
|
|
511
|
-
const lastMessage = messages2[messages2.length - 1];
|
|
512
|
-
lastMessage.content += value;
|
|
513
|
-
return [...messages2.slice(0, -1), lastMessage];
|
|
514
|
-
});
|
|
515
|
-
},
|
|
516
|
-
onAssistantControlDataPart(value) {
|
|
517
|
-
if (value.threadId) {
|
|
518
|
-
currentThreadId.value = value.threadId;
|
|
519
|
-
}
|
|
520
|
-
setMessages((messages2) => {
|
|
521
|
-
const lastMessage = messages2[messages2.length - 1];
|
|
522
|
-
lastMessage.id = value.messageId;
|
|
523
|
-
return [...messages2.slice(0, -1), lastMessage];
|
|
524
|
-
});
|
|
525
|
-
},
|
|
526
|
-
onDataMessagePart(value) {
|
|
527
|
-
setMessages((messages2) => {
|
|
528
|
-
var _a2;
|
|
529
|
-
return [
|
|
530
|
-
...messages2,
|
|
531
|
-
{
|
|
532
|
-
id: (_a2 = value.id) != null ? _a2 : (0, import_ui_utils3.generateId)(),
|
|
533
|
-
role: "data",
|
|
534
|
-
content: "",
|
|
535
|
-
data: value.data,
|
|
536
|
-
parts: []
|
|
537
|
-
}
|
|
538
|
-
];
|
|
539
|
-
});
|
|
540
|
-
},
|
|
541
|
-
onErrorPart(value) {
|
|
542
|
-
error.value = new Error(value);
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
} catch (err) {
|
|
546
|
-
if ((0, import_provider_utils.isAbortError)(err) && ((_d = abortController.value) == null ? void 0 : _d.signal.aborted)) {
|
|
547
|
-
abortController.value = null;
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
|
-
if (onError && err instanceof Error) {
|
|
551
|
-
onError(err);
|
|
552
|
-
}
|
|
553
|
-
error.value = err;
|
|
554
|
-
} finally {
|
|
555
|
-
abortController.value = null;
|
|
556
|
-
status.value = "awaiting_message";
|
|
557
|
-
}
|
|
558
|
-
};
|
|
559
|
-
const submitMessage = async (event, requestOptions) => {
|
|
560
|
-
var _a;
|
|
561
|
-
(_a = event == null ? void 0 : event.preventDefault) == null ? void 0 : _a.call(event);
|
|
562
|
-
if (!input.value)
|
|
563
|
-
return;
|
|
564
|
-
append(
|
|
565
|
-
{
|
|
566
|
-
role: "user",
|
|
567
|
-
content: input.value,
|
|
568
|
-
parts: []
|
|
569
|
-
},
|
|
570
|
-
requestOptions
|
|
571
|
-
);
|
|
572
|
-
};
|
|
573
|
-
return {
|
|
574
|
-
append,
|
|
575
|
-
messages,
|
|
576
|
-
setMessages,
|
|
577
|
-
threadId: (0, import_vue3.readonly)(currentThreadId),
|
|
578
|
-
setThreadId: setCurrentThreadId,
|
|
579
|
-
input,
|
|
580
|
-
handleInputChange,
|
|
581
|
-
handleSubmit: submitMessage,
|
|
582
|
-
isSending,
|
|
583
|
-
status,
|
|
584
|
-
error,
|
|
585
|
-
stop
|
|
345
|
+
isLoading
|
|
586
346
|
};
|
|
587
347
|
}
|
|
588
348
|
// Annotate the CommonJS export names for ESM import in node:
|
|
589
349
|
0 && (module.exports = {
|
|
590
|
-
useAssistant,
|
|
591
350
|
useChat,
|
|
592
351
|
useCompletion
|
|
593
352
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/use-chat.ts","../src/use-completion.ts","../src/use-assistant.ts"],"sourcesContent":["export * from './use-chat';\nexport * from './use-completion';\nexport * from './use-assistant';\n","import type {\n ChatRequestOptions,\n CreateMessage,\n JSONValue,\n Message,\n UIMessage,\n UseChatOptions,\n} from '@ai-sdk/ui-utils';\nimport {\n callChatApi,\n extractMaxToolInvocationStep,\n fillMessageParts,\n generateId as generateIdFunc,\n getMessageParts,\n isAssistantMessageWithCompletedToolCalls,\n prepareAttachmentsForRequest,\n shouldResubmitMessages,\n updateToolCallResult,\n} from '@ai-sdk/ui-utils';\nimport swrv from 'swrv';\nimport type { Ref } from 'vue';\nimport { computed, ref, unref } from 'vue';\n\nexport type { CreateMessage, Message, UIMessage, UseChatOptions };\n\nexport type UseChatHelpers = {\n /** Current messages in the chat */\n messages: Ref<UIMessage[]>;\n /** The error object of the API request */\n error: Ref<undefined | Error>;\n /**\n * Append a user message to the chat list. This triggers the API call to fetch\n * the assistant's response.\n */\n append: (\n message: Message | CreateMessage,\n chatRequestOptions?: ChatRequestOptions,\n ) => Promise<string | null | undefined>;\n /**\n * Reload the last AI chat response for the given chat history. If the last\n * message isn't from the assistant, it will request the API to generate a\n * new response.\n */\n reload: (\n chatRequestOptions?: ChatRequestOptions,\n ) => Promise<string | null | undefined>;\n /**\n * Abort the current request immediately, keep the generated tokens if any.\n */\n stop: () => void;\n /**\n * Update the `messages` state locally. This is useful when you want to\n * edit the messages on the client, and then trigger the `reload` method\n * manually to regenerate the AI response.\n */\n setMessages: (\n messages: Message[] | ((messages: Message[]) => Message[]),\n ) => void;\n /** The current value of the input */\n input: Ref<string>;\n /** Form submission handler to automatically reset input and append a user message */\n handleSubmit: (\n event?: { preventDefault?: () => void },\n chatRequestOptions?: ChatRequestOptions,\n ) => void;\n\n /**\n * Whether the API request is in progress\n *\n * @deprecated use `status` instead\n */\n isLoading: Ref<boolean>;\n\n /**\n * Hook status:\n *\n * - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.\n * - `streaming`: The response is actively streaming in from the API, receiving chunks of data.\n * - `ready`: The full response has been received and processed; a new user message can be submitted.\n * - `error`: An error occurred during the API request, preventing successful completion.\n */\n status: Ref<'submitted' | 'streaming' | 'ready' | 'error'>;\n\n /** Additional data added on the server via StreamData. */\n data: Ref<JSONValue[] | undefined>;\n /** Set the data of the chat. You can use this to transform or clear the chat data. */\n setData: (\n data:\n | JSONValue[]\n | undefined\n | ((data: JSONValue[] | undefined) => JSONValue[] | undefined),\n ) => void;\n\n addToolResult: ({\n toolCallId,\n result,\n }: {\n toolCallId: string;\n result: any;\n }) => void;\n\n /** The id of the chat */\n id: string;\n};\n\n// @ts-expect-error - some issues with the default export of useSWRV\nconst useSWRV = (swrv.default as (typeof import('swrv'))['default']) || swrv;\nconst store: Record<string, UIMessage[] | undefined> = {};\nconst statusStore: Record<\n string,\n Ref<'submitted' | 'streaming' | 'ready' | 'error'>\n> = {};\n\nexport function useChat(\n {\n api = '/api/chat',\n id,\n initialMessages = [],\n initialInput = '',\n sendExtraMessageFields,\n streamProtocol = 'data',\n onResponse,\n onFinish,\n onError,\n credentials,\n headers: metadataHeaders,\n body: metadataBody,\n generateId = generateIdFunc,\n onToolCall,\n fetch,\n keepLastMessageOnError = true,\n maxSteps = 1,\n experimental_prepareRequestBody,\n }: UseChatOptions & {\n /**\n * Maximum number of sequential LLM calls (steps), e.g. when you use tool calls. Must be at least 1.\n * A maximum number is required to prevent infinite loops in the case of misconfigured tools.\n * By default, it's set to 1, which means that only a single LLM call is made.\n */\n maxSteps?: number;\n\n /**\n * Experimental (Vue only). When a function is provided, it will be used\n * to prepare the request body for the chat API. This can be useful for\n * customizing the request body based on the messages and data in the chat.\n *\n * @param id The chat ID\n * @param messages The current messages in the chat\n * @param requestData The data object passed in the chat request\n * @param requestBody The request body object passed in the chat request\n */\n experimental_prepareRequestBody?: (options: {\n id: string;\n messages: UIMessage[];\n requestData?: JSONValue;\n requestBody?: object;\n }) => unknown;\n } = {\n maxSteps: 1,\n },\n): UseChatHelpers {\n // Generate a unique ID for the chat if not provided.\n const chatId = id ?? generateId();\n\n const key = `${api}|${chatId}`;\n const { data: messagesData, mutate: originalMutate } = useSWRV<UIMessage[]>(\n key,\n () => store[key] ?? fillMessageParts(initialMessages),\n );\n\n const status =\n statusStore[chatId] ??\n (statusStore[chatId] = ref<'submitted' | 'streaming' | 'ready' | 'error'>(\n 'ready',\n ));\n\n // Force the `data` to be `initialMessages` if it's `undefined`.\n messagesData.value ??= fillMessageParts(initialMessages);\n\n const mutate = (data?: UIMessage[]) => {\n store[key] = data;\n return originalMutate();\n };\n\n // Because of the `initialData` option, the `data` will never be `undefined`.\n const messages = messagesData as Ref<UIMessage[]>;\n\n const error = ref<undefined | Error>(undefined);\n // cannot use JSONValue[] in ref because of infinite Typescript recursion:\n const streamData = ref<undefined | unknown[]>(undefined);\n\n let abortController: AbortController | null = null;\n\n async function triggerRequest(\n messagesSnapshot: Message[],\n { data, headers, body }: ChatRequestOptions = {},\n ) {\n error.value = undefined;\n status.value = 'submitted';\n\n const messageCount = messages.value.length;\n const maxStep = extractMaxToolInvocationStep(\n messages.value[messages.value.length - 1]?.toolInvocations,\n );\n\n try {\n abortController = new AbortController();\n\n // Do an optimistic update to the chat state to show the updated messages\n // immediately.\n const previousMessages = fillMessageParts(messagesSnapshot);\n const chatMessages = previousMessages;\n mutate(chatMessages);\n\n const existingData = (streamData.value ?? []) as JSONValue[];\n\n const constructedMessagesPayload = sendExtraMessageFields\n ? chatMessages\n : chatMessages.map(\n ({\n role,\n content,\n experimental_attachments,\n data,\n annotations,\n toolInvocations,\n parts,\n }) => ({\n role,\n content,\n ...(experimental_attachments !== undefined && {\n experimental_attachments,\n }),\n ...(data !== undefined && { data }),\n ...(annotations !== undefined && { annotations }),\n ...(toolInvocations !== undefined && { toolInvocations }),\n ...(parts !== undefined && { parts }),\n }),\n );\n\n await callChatApi({\n api,\n body: experimental_prepareRequestBody?.({\n id: chatId,\n messages: chatMessages,\n requestData: data,\n requestBody: body,\n }) ?? {\n id: chatId,\n messages: constructedMessagesPayload,\n data,\n ...unref(metadataBody), // Use unref to unwrap the ref value\n ...body,\n },\n streamProtocol,\n headers: {\n ...metadataHeaders,\n ...headers,\n },\n abortController: () => abortController,\n credentials,\n onResponse,\n onUpdate({ message, data, replaceLastMessage }) {\n status.value = 'streaming';\n\n mutate([\n ...(replaceLastMessage\n ? chatMessages.slice(0, chatMessages.length - 1)\n : chatMessages),\n message,\n ]);\n if (data?.length) {\n streamData.value = [...existingData, ...data];\n }\n },\n onFinish,\n restoreMessagesOnFailure() {\n // Restore the previous messages if the request fails.\n if (!keepLastMessageOnError) {\n mutate(previousMessages);\n }\n },\n generateId,\n onToolCall,\n fetch,\n // enabled use of structured clone in processChatResponse:\n lastMessage: recursiveToRaw(chatMessages[chatMessages.length - 1]),\n });\n\n status.value = 'ready';\n } catch (err) {\n // Ignore abort errors as they are expected.\n if ((err as any).name === 'AbortError') {\n abortController = null;\n status.value = 'ready';\n return null;\n }\n\n if (onError && err instanceof Error) {\n onError(err);\n }\n\n error.value = err as Error;\n status.value = 'error';\n } finally {\n abortController = null;\n }\n\n // auto-submit when all tool calls in the last assistant message have results:\n if (\n shouldResubmitMessages({\n originalMaxToolInvocationStep: maxStep,\n originalMessageCount: messageCount,\n maxSteps,\n messages: messages.value,\n })\n ) {\n await triggerRequest(messages.value);\n }\n }\n\n const append: UseChatHelpers['append'] = async (message, options) => {\n const attachmentsForRequest = await prepareAttachmentsForRequest(\n options?.experimental_attachments ?? message.experimental_attachments,\n );\n\n return triggerRequest(\n messages.value.concat({\n ...message,\n id: message.id ?? generateId(),\n createdAt: message.createdAt ?? new Date(),\n experimental_attachments:\n attachmentsForRequest.length > 0 ? attachmentsForRequest : undefined,\n parts: getMessageParts(message),\n }),\n options,\n );\n };\n\n const reload: UseChatHelpers['reload'] = async options => {\n const messagesSnapshot = messages.value;\n if (messagesSnapshot.length === 0) return null;\n\n const lastMessage = messagesSnapshot[messagesSnapshot.length - 1];\n if (lastMessage.role === 'assistant') {\n return triggerRequest(messagesSnapshot.slice(0, -1), options);\n }\n\n return triggerRequest(messagesSnapshot, options);\n };\n\n const stop = () => {\n if (abortController) {\n abortController.abort();\n abortController = null;\n }\n };\n\n const setMessages = (\n messagesArg: Message[] | ((messages: Message[]) => Message[]),\n ) => {\n if (typeof messagesArg === 'function') {\n messagesArg = messagesArg(messages.value);\n }\n\n mutate(fillMessageParts(messagesArg));\n };\n\n const setData = (\n dataArg:\n | JSONValue[]\n | undefined\n | ((data: JSONValue[] | undefined) => JSONValue[] | undefined),\n ) => {\n if (typeof dataArg === 'function') {\n dataArg = dataArg(streamData.value as JSONValue[] | undefined);\n }\n\n streamData.value = dataArg;\n };\n\n const input = ref(initialInput);\n\n const handleSubmit = async (\n event?: { preventDefault?: () => void },\n options: ChatRequestOptions = {},\n ) => {\n event?.preventDefault?.();\n\n const inputValue = input.value;\n\n if (!inputValue && !options.allowEmptySubmit) return;\n\n const attachmentsForRequest = await prepareAttachmentsForRequest(\n options.experimental_attachments,\n );\n\n triggerRequest(\n messages.value.concat({\n id: generateId(),\n createdAt: new Date(),\n content: inputValue,\n role: 'user',\n experimental_attachments:\n attachmentsForRequest.length > 0 ? attachmentsForRequest : undefined,\n parts: [{ type: 'text', text: inputValue }],\n }),\n options,\n );\n\n input.value = '';\n };\n\n const addToolResult = ({\n toolCallId,\n result,\n }: {\n toolCallId: string;\n result: unknown;\n }) => {\n const currentMessages = messages.value;\n\n updateToolCallResult({\n messages: currentMessages,\n toolCallId,\n toolResult: result,\n });\n\n mutate(currentMessages);\n\n // when the request is ongoing, the auto-submit will be triggered after the request is finished\n if (status.value === 'submitted' || status.value === 'streaming') {\n return;\n }\n\n // auto-submit when all tool calls in the last assistant message have results:\n const lastMessage = currentMessages[currentMessages.length - 1];\n if (isAssistantMessageWithCompletedToolCalls(lastMessage)) {\n triggerRequest(currentMessages);\n }\n };\n\n return {\n id: chatId,\n messages,\n append,\n error,\n reload,\n stop,\n setMessages,\n input,\n handleSubmit,\n isLoading: computed(\n () => status.value === 'submitted' || status.value === 'streaming',\n ),\n status: status as Ref<'submitted' | 'streaming' | 'ready' | 'error'>,\n data: streamData as Ref<undefined | JSONValue[]>,\n setData,\n addToolResult,\n };\n}\n\n// required for use of structured clone\nfunction recursiveToRaw<T>(inputValue: T): T {\n if (Array.isArray(inputValue)) {\n return [...inputValue.map(recursiveToRaw)] as T;\n } else if (typeof inputValue === 'object' && inputValue !== null) {\n const clone: any = {};\n for (const [key, value] of Object.entries(inputValue)) {\n clone[key] = recursiveToRaw(value);\n }\n return clone;\n } else {\n return inputValue;\n }\n}\n","import type {\n JSONValue,\n RequestOptions,\n UseCompletionOptions,\n} from '@ai-sdk/ui-utils';\nimport { callCompletionApi } from '@ai-sdk/ui-utils';\nimport swrv from 'swrv';\nimport type { Ref } from 'vue';\nimport { ref, unref } from 'vue';\n\nexport type { UseCompletionOptions };\n\nexport type UseCompletionHelpers = {\n /** The current completion result */\n completion: Ref<string>;\n /** The error object of the API request */\n error: Ref<undefined | Error>;\n /**\n * Send a new prompt to the API endpoint and update the completion state.\n */\n complete: (\n prompt: string,\n options?: RequestOptions,\n ) => Promise<string | null | undefined>;\n /**\n * Abort the current API request but keep the generated tokens.\n */\n stop: () => void;\n /**\n * Update the `completion` state locally.\n */\n setCompletion: (completion: string) => void;\n /** The current value of the input */\n input: Ref<string>;\n /**\n * Form submission handler to automatically reset input and append a user message\n * @example\n * ```jsx\n * <form @submit=\"handleSubmit\">\n * <input @change=\"handleInputChange\" v-model=\"input\" />\n * </form>\n * ```\n */\n handleSubmit: (event?: { preventDefault?: () => void }) => void;\n /** Whether the API request is in progress */\n isLoading: Ref<boolean | undefined>;\n\n /** Additional data added on the server via StreamData */\n data: Ref<JSONValue[] | undefined>;\n};\n\nlet uniqueId = 0;\n\n// @ts-expect-error - some issues with the default export of useSWRV\nconst useSWRV = (swrv.default as (typeof import('swrv'))['default']) || swrv;\nconst store: Record<string, any> = {};\n\nexport function useCompletion({\n api = '/api/completion',\n id,\n initialCompletion = '',\n initialInput = '',\n credentials,\n headers,\n body,\n streamProtocol,\n onResponse,\n onFinish,\n onError,\n fetch,\n}: UseCompletionOptions = {}): UseCompletionHelpers {\n // Generate an unique id for the completion if not provided.\n const completionId = id || `completion-${uniqueId++}`;\n\n const key = `${api}|${completionId}`;\n const { data, mutate: originalMutate } = useSWRV<string>(\n key,\n () => store[key] || initialCompletion,\n );\n\n const { data: isLoading, mutate: mutateLoading } = useSWRV<boolean>(\n `${completionId}-loading`,\n null,\n );\n\n isLoading.value ??= false;\n\n const { data: streamData, mutate: mutateStreamData } = useSWRV<\n JSONValue[] | undefined\n >(`${completionId}-data`, null);\n\n // Force the `data` to be `initialCompletion` if it's `undefined`.\n data.value ||= initialCompletion;\n\n const mutate = (data: string) => {\n store[key] = data;\n return originalMutate();\n };\n\n // Because of the `initialData` option, the `data` will never be `undefined`.\n const completion = data as Ref<string>;\n\n const error = ref<undefined | Error>(undefined);\n\n let abortController: AbortController | null = null;\n\n async function triggerRequest(prompt: string, options?: RequestOptions) {\n const existingData = (streamData.value ?? []) as JSONValue[];\n return callCompletionApi({\n api,\n prompt,\n credentials,\n headers: {\n ...headers,\n ...options?.headers,\n },\n body: {\n ...unref(body),\n ...options?.body,\n },\n streamProtocol,\n setCompletion: mutate,\n setLoading: loading => mutateLoading(() => loading),\n setError: err => {\n error.value = err;\n },\n setAbortController: controller => {\n abortController = controller;\n },\n onResponse,\n onFinish,\n onError,\n onData: data => {\n mutateStreamData(() => [...existingData, ...(data ?? [])]);\n },\n fetch,\n });\n }\n\n const complete: UseCompletionHelpers['complete'] = async (\n prompt,\n options,\n ) => {\n return triggerRequest(prompt, options);\n };\n\n const stop = () => {\n if (abortController) {\n abortController.abort();\n abortController = null;\n }\n };\n\n const setCompletion = (completion: string) => {\n mutate(completion);\n };\n\n const input = ref(initialInput);\n\n const handleSubmit = (event?: { preventDefault?: () => void }) => {\n event?.preventDefault?.();\n const inputValue = input.value;\n return inputValue ? complete(inputValue) : undefined;\n };\n\n return {\n completion,\n complete,\n error,\n stop,\n setCompletion,\n input,\n handleSubmit,\n isLoading,\n data: streamData,\n };\n}\n","/**\n * A vue.js composable function to interact with the assistant API.\n */\n\nimport { isAbortError } from '@ai-sdk/provider-utils';\nimport type {\n AssistantStatus,\n CreateMessage,\n Message,\n UseAssistantOptions,\n} from '@ai-sdk/ui-utils';\nimport { generateId, processAssistantStream } from '@ai-sdk/ui-utils';\nimport type { ComputedRef, Ref } from 'vue';\nimport { computed, readonly, ref } from 'vue';\n\nexport type UseAssistantHelpers = {\n /**\n * The current array of chat messages.\n */\n messages: Ref<Message[]>;\n\n /**\n * Update the message store with a new array of messages.\n */\n setMessages: (messagesProcessor: (messages: Message[]) => Message[]) => void;\n\n /**\n * The current thread ID.\n */\n threadId: Ref<string | undefined>;\n\n /**\n * 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.\n */\n setThreadId: (threadId: string | undefined) => void;\n /**\n * The current value of the input field.\n */\n input: Ref<string>;\n\n /**\n * Append a user message to the chat list. This triggers the API call to fetch\n * the assistant's response.\n * @param message The message to append\n * @param requestOptions Additional options to pass to the API call\n */\n append: (\n message: Message | CreateMessage,\n requestOptions?: {\n data?: Record<string, string>;\n },\n ) => Promise<void>;\n\n /**\n * Abort the current request immediately, keep the generated tokens if any.\n */\n stop: ComputedRef<() => void>;\n\n /**\n * Handler for the `onChange` event of the input field to control the input's value.\n */\n handleInputChange: (e: Event & { target: HTMLInputElement }) => void;\n\n /**\n * Handler for the `onSubmit` event of the form to append a user message and reset the input.\n */\n handleSubmit: (e: Event & { target: HTMLFormElement }) => void;\n\n /**\n * Whether the assistant is currently sending a message.\n */\n isSending: ComputedRef<boolean>;\n\n /**\n * The current status of the assistant.\n */\n status: Ref<AssistantStatus>;\n\n /**\n * The current error, if any.\n */\n error: Ref<Error | undefined>;\n};\n\nexport function useAssistant({\n api,\n threadId: threadIdParam,\n credentials,\n headers,\n body,\n onError,\n}: UseAssistantOptions): UseAssistantHelpers {\n const messages: Ref<Message[]> = ref([]);\n const input: Ref<string> = ref('');\n const currentThreadId: Ref<string | undefined> = ref(undefined);\n const status: Ref<AssistantStatus> = ref('awaiting_message');\n const error: Ref<undefined | Error> = ref(undefined);\n\n const setMessages = (messageFactory: (messages: Message[]) => Message[]) => {\n messages.value = messageFactory(messages.value);\n };\n\n const setCurrentThreadId = (newThreadId: string | undefined) => {\n currentThreadId.value = newThreadId;\n messages.value = [];\n };\n\n const handleInputChange = (event: Event & { target: HTMLInputElement }) => {\n input.value = event?.target?.value;\n };\n\n const isSending = computed(() => status.value === 'in_progress');\n\n // Abort controller to cancel the current API call when required\n const abortController = ref<AbortController | null>(null);\n\n // memoized function to stop the current request when required\n const stop = computed(() => {\n return () => {\n if (abortController.value) {\n abortController.value.abort();\n abortController.value = null;\n }\n };\n });\n\n const append = async (\n message: Message | CreateMessage,\n requestOptions?: {\n data?: Record<string, string>;\n },\n ) => {\n status.value = 'in_progress';\n\n // Append the new message to the current list of messages\n const newMessage: Message = {\n ...message,\n id: message.id ?? generateId(),\n };\n\n // Update the messages list with the new message\n setMessages(messages => [...messages, newMessage]);\n\n input.value = '';\n\n const controller = new AbortController();\n\n try {\n // Assign the new controller to the abortController ref\n abortController.value = controller;\n\n const response = await fetch(api, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n body: JSON.stringify({\n ...body,\n // Message Content\n message: message.content,\n\n // Always Use User Provided Thread ID When Available\n threadId: threadIdParam ?? currentThreadId.value ?? null,\n\n // Optional Request Data\n ...(requestOptions?.data && { data: requestOptions?.data }),\n }),\n signal: controller.signal,\n credentials,\n });\n\n if (!response.ok) {\n throw new Error(\n response.statusText ?? 'An error occurred while sending the message',\n );\n }\n\n if (!response.body) {\n throw new Error('The response body is empty');\n }\n\n await processAssistantStream({\n stream: response.body,\n onAssistantMessagePart(value) {\n messages.value = [\n ...messages.value,\n {\n id: value.id,\n content: value.content[0].text.value,\n role: value.role,\n parts: [],\n },\n ];\n },\n onTextPart(value) {\n setMessages(messages => {\n const lastMessage = messages[messages.length - 1];\n lastMessage.content += value;\n\n return [...messages.slice(0, -1), lastMessage];\n });\n },\n onAssistantControlDataPart(value) {\n if (value.threadId) {\n currentThreadId.value = value.threadId;\n }\n\n setMessages(messages => {\n const lastMessage = messages[messages.length - 1];\n lastMessage.id = value.messageId;\n\n return [...messages.slice(0, -1), lastMessage];\n });\n },\n onDataMessagePart(value) {\n setMessages(messages => [\n ...messages,\n {\n id: value.id ?? generateId(),\n role: 'data',\n content: '',\n data: value.data,\n parts: [],\n },\n ]);\n },\n onErrorPart(value) {\n error.value = new Error(value);\n },\n });\n } catch (err) {\n // If the error is an AbortError and the signal is aborted, reset the abortController and do nothing.\n if (isAbortError(err) && abortController.value?.signal.aborted) {\n abortController.value = null;\n return;\n }\n\n // If an error handler is provided, call it with the error\n if (onError && err instanceof Error) {\n onError(err);\n }\n\n error.value = err as Error;\n } finally {\n // Reset the status to 'awaiting_message' after the request is complete\n abortController.value = null;\n status.value = 'awaiting_message';\n }\n };\n\n const submitMessage = async (\n event: Event & { target: HTMLFormElement },\n requestOptions?: {\n data?: Record<string, string>;\n },\n ) => {\n event?.preventDefault?.();\n\n if (!input.value) return;\n\n append(\n {\n role: 'user',\n content: input.value,\n parts: [],\n },\n requestOptions,\n );\n };\n\n return {\n append,\n messages,\n setMessages,\n threadId: readonly(currentThreadId),\n setThreadId: setCurrentThreadId,\n input,\n handleInputChange,\n handleSubmit: submitMessage,\n isSending,\n status,\n error,\n stop,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQA,sBAUO;AACP,kBAAiB;AAEjB,iBAAqC;AAqFrC,IAAM,UAAW,YAAAA,QAAK,WAAkD,YAAAA;AACxE,IAAM,QAAiD,CAAC;AACxD,IAAM,cAGF,CAAC;AAEE,SAAS,QACd;AAAA,EACE,MAAM;AAAA,EACN;AAAA,EACA,kBAAkB,CAAC;AAAA,EACnB,eAAe;AAAA,EACf;AAAA,EACA,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,MAAM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sBAAgB,QAAQ;AACxB,aAAO,QAAQ;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,gBAAgB,OACpB,OACA,mBAGG;AAhQP;AAiQI,yCAAO,mBAAP;AAEA,QAAI,CAAC,MAAM;AAAO;AAElB;AAAA,MACE;AAAA,QACE,MAAM;AAAA,QACN,SAAS,MAAM;AAAA,QACf,OAAO,CAAC;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAU,sBAAS,eAAe;AAAA,IAClC,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["swrv","generateId","generateIdFunc","fetch","_a","_b","data","import_ui_utils","import_swrv","import_vue","useSWRV","swrv","store","fetch","data","_a","completion","import_ui_utils","import_vue","messages","_a"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/use-chat.ts","../src/use-completion.ts"],"sourcesContent":["export * from './use-chat';\nexport * from './use-completion';\n","import type {\n ChatRequestOptions,\n CreateUIMessage,\n FileUIPart,\n JSONValue,\n OriginalUseChatOptions,\n UIMessage,\n UseChatOptions,\n} from 'ai';\nimport {\n callChatApi,\n convertFileListToFileUIParts,\n extractMaxToolInvocationStep,\n generateId as generateIdFunc,\n getToolInvocations,\n isAssistantMessageWithCompletedToolCalls,\n shouldResubmitMessages,\n updateToolCallResult,\n} from 'ai';\nimport swrv from 'swrv';\nimport type { Ref } from 'vue';\nimport { ref, unref } from 'vue';\n\nexport type { CreateUIMessage, UIMessage, UseChatOptions };\n\nexport type UseChatHelpers<MESSAGE_METADATA> = {\n /** Current messages in the chat */\n messages: Ref<UIMessage<MESSAGE_METADATA>[]>;\n /** The error object of the API request */\n error: Ref<undefined | Error>;\n /**\n * Append a user message to the chat list. This triggers the API call to fetch\n * the assistant's response.\n */\n append: (\n message: UIMessage<MESSAGE_METADATA> | CreateUIMessage<MESSAGE_METADATA>,\n chatRequestOptions?: ChatRequestOptions,\n ) => Promise<string | null | undefined>;\n /**\n * Reload the last AI chat response for the given chat history. If the last\n * message isn't from the assistant, it will request the API to generate a\n * new response.\n */\n reload: (\n chatRequestOptions?: ChatRequestOptions,\n ) => Promise<string | null | undefined>;\n /**\n * Abort the current request immediately, keep the generated tokens if any.\n */\n stop: () => void;\n /**\n * Update the `messages` state locally. This is useful when you want to\n * edit the messages on the client, and then trigger the `reload` method\n * manually to regenerate the AI response.\n */\n setMessages: (\n messages:\n | UIMessage<MESSAGE_METADATA>[]\n | ((\n messages: UIMessage<MESSAGE_METADATA>[],\n ) => UIMessage<MESSAGE_METADATA>[]),\n ) => void;\n /** The current value of the input */\n input: Ref<string>;\n /** Form submission handler to automatically reset input and append a user message */\n handleSubmit: (\n event?: { preventDefault?: () => void },\n chatRequestOptions?: ChatRequestOptions & {\n files?: FileList | FileUIPart[];\n },\n ) => void;\n\n /**\n * Hook status:\n *\n * - `submitted`: The message has been sent to the API and we're awaiting the start of the response stream.\n * - `streaming`: The response is actively streaming in from the API, receiving chunks of data.\n * - `ready`: The full response has been received and processed; a new user message can be submitted.\n * - `error`: An error occurred during the API request, preventing successful completion.\n */\n status: Ref<'submitted' | 'streaming' | 'ready' | 'error'>;\n\n addToolResult: ({\n toolCallId,\n result,\n }: {\n toolCallId: string;\n result: any;\n }) => void;\n\n /** The id of the chat */\n chatId: string;\n};\n\n// @ts-expect-error - some issues with the default export of useSWRV\nconst useSWRV = (swrv.default as (typeof import('swrv'))['default']) || swrv;\nconst store: Record<string, UIMessage<any>[] | undefined> = {};\nconst statusStore: Record<\n string,\n Ref<'submitted' | 'streaming' | 'ready' | 'error'>\n> = {};\n\nexport function useChat<MESSAGE_METADATA = unknown>(\n {\n api = '/api/chat',\n chatId,\n initialMessages = [],\n initialInput = '',\n streamProtocol = 'ui-message',\n onFinish,\n onError,\n credentials,\n headers: metadataHeaders,\n body: metadataBody,\n generateId = generateIdFunc,\n onToolCall,\n fetch,\n maxSteps = 1,\n experimental_prepareRequestBody,\n messageMetadataSchema,\n }: OriginalUseChatOptions<MESSAGE_METADATA> & {\n /**\n * Experimental (Vue only). When a function is provided, it will be used\n * to prepare the request body for the chat API. This can be useful for\n * customizing the request body based on the messages and data in the chat.\n *\n * @param id The chat ID\n * @param messages The current messages in the chat\n * @param requestData The data object passed in the chat request\n * @param requestBody The request body object passed in the chat request\n */\n experimental_prepareRequestBody?: (options: {\n chatId: string;\n messages: UIMessage<MESSAGE_METADATA>[];\n requestData?: JSONValue;\n requestBody?: object;\n }) => unknown;\n } = {\n maxSteps: 1,\n },\n): UseChatHelpers<MESSAGE_METADATA> {\n // Generate a unique ID for the chat if not provided.\n const stableChatId = chatId ?? generateId();\n\n const key = `${api}|${stableChatId}`;\n const { data: messagesData, mutate: originalMutate } = useSWRV<\n UIMessage<MESSAGE_METADATA>[]\n >(key, () => store[key] ?? initialMessages);\n\n const status =\n statusStore[stableChatId] ??\n (statusStore[stableChatId] = ref<\n 'submitted' | 'streaming' | 'ready' | 'error'\n >('ready'));\n\n // Force the `data` to be `initialMessages` if it's `undefined`.\n messagesData.value ??= initialMessages;\n\n const mutate = (data?: UIMessage<MESSAGE_METADATA>[]) => {\n store[key] = data;\n return originalMutate();\n };\n\n // Because of the `initialData` option, the `data` will never be `undefined`.\n const messages = messagesData as Ref<UIMessage<MESSAGE_METADATA>[]>;\n\n const error = ref<undefined | Error>(undefined);\n\n let abortController: AbortController | null = null;\n\n async function triggerRequest(\n messagesSnapshot: UIMessage<MESSAGE_METADATA>[],\n { headers, body }: ChatRequestOptions = {},\n ) {\n error.value = undefined;\n status.value = 'submitted';\n\n const messageCount = messages.value.length;\n const lastMessage = messages.value.at(-1);\n const maxStep =\n lastMessage != null\n ? extractMaxToolInvocationStep(getToolInvocations(lastMessage))\n : 0;\n\n try {\n abortController = new AbortController();\n\n // Do an optimistic update to show the updated messages immediately:\n mutate(messagesSnapshot);\n\n await callChatApi({\n api,\n body: experimental_prepareRequestBody?.({\n chatId: stableChatId,\n messages: messagesSnapshot,\n requestBody: body,\n }) ?? {\n chatId: stableChatId,\n messages: messagesSnapshot,\n ...unref(metadataBody), // Use unref to unwrap the ref value\n ...body,\n },\n streamProtocol,\n headers: {\n ...metadataHeaders,\n ...headers,\n },\n abortController: () => abortController,\n credentials,\n onUpdate({ message }) {\n status.value = 'streaming';\n\n const replaceLastMessage =\n message.id === messagesSnapshot[messagesSnapshot.length - 1].id;\n\n mutate([\n ...(replaceLastMessage\n ? messagesSnapshot.slice(0, messagesSnapshot.length - 1)\n : messagesSnapshot),\n message,\n ]);\n },\n onFinish,\n generateId,\n onToolCall,\n fetch,\n // enabled use of structured clone in processChatResponse:\n lastMessage: recursiveToRaw(\n messagesSnapshot[messagesSnapshot.length - 1],\n ),\n messageMetadataSchema,\n });\n\n status.value = 'ready';\n } catch (err) {\n // Ignore abort errors as they are expected.\n if ((err as any).name === 'AbortError') {\n abortController = null;\n status.value = 'ready';\n return null;\n }\n\n if (onError && err instanceof Error) {\n onError(err);\n }\n\n error.value = err as Error;\n status.value = 'error';\n } finally {\n abortController = null;\n }\n\n // auto-submit when all tool calls in the last assistant message have results:\n if (\n shouldResubmitMessages({\n originalMaxToolInvocationStep: maxStep,\n originalMessageCount: messageCount,\n maxSteps,\n messages: messages.value,\n })\n ) {\n await triggerRequest(messages.value);\n }\n }\n\n const append: UseChatHelpers<MESSAGE_METADATA>['append'] = async (\n message,\n options,\n ) => {\n return triggerRequest(\n messages.value.concat({\n ...message,\n id: message.id ?? generateId(),\n parts: message.parts,\n }),\n options,\n );\n };\n\n const reload: UseChatHelpers<MESSAGE_METADATA>['reload'] = async options => {\n const messagesSnapshot = messages.value;\n if (messagesSnapshot.length === 0) return null;\n\n const lastMessage = messagesSnapshot[messagesSnapshot.length - 1];\n if (lastMessage.role === 'assistant') {\n return triggerRequest(messagesSnapshot.slice(0, -1), options);\n }\n\n return triggerRequest(messagesSnapshot, options);\n };\n\n const stop = () => {\n if (abortController) {\n abortController.abort();\n abortController = null;\n }\n };\n\n const setMessages = (\n messagesArg:\n | UIMessage<MESSAGE_METADATA>[]\n | ((\n messages: UIMessage<MESSAGE_METADATA>[],\n ) => UIMessage<MESSAGE_METADATA>[]),\n ) => {\n if (typeof messagesArg === 'function') {\n messagesArg = messagesArg(messages.value);\n }\n\n mutate(messagesArg);\n };\n\n const input = ref(initialInput);\n\n const handleSubmit = async (\n event?: { preventDefault?: () => void },\n options: ChatRequestOptions & { files?: FileList | FileUIPart[] } = {},\n ) => {\n event?.preventDefault?.();\n\n const inputValue = input.value;\n\n const fileParts = Array.isArray(options?.files)\n ? options.files\n : await convertFileListToFileUIParts(options?.files);\n\n if (!inputValue && fileParts.length === 0) return;\n\n triggerRequest(\n messages.value.concat({\n id: generateId(),\n role: 'user',\n parts: [...fileParts, { type: 'text', text: inputValue }],\n }),\n options,\n );\n\n input.value = '';\n };\n\n const addToolResult = ({\n toolCallId,\n result,\n }: {\n toolCallId: string;\n result: unknown;\n }) => {\n const currentMessages = messages.value;\n\n updateToolCallResult({\n messages: currentMessages,\n toolCallId,\n toolResult: result,\n });\n\n mutate(currentMessages);\n\n // when the request is ongoing, the auto-submit will be triggered after the request is finished\n if (status.value === 'submitted' || status.value === 'streaming') {\n return;\n }\n\n // auto-submit when all tool calls in the last assistant message have results:\n const lastMessage = currentMessages[currentMessages.length - 1];\n if (isAssistantMessageWithCompletedToolCalls(lastMessage)) {\n triggerRequest(currentMessages);\n }\n };\n\n return {\n chatId: stableChatId,\n messages,\n append,\n error,\n reload,\n stop,\n setMessages,\n input,\n handleSubmit,\n status: status as Ref<'submitted' | 'streaming' | 'ready' | 'error'>,\n addToolResult,\n };\n}\n\n// required for use of structured clone\nfunction recursiveToRaw<T>(inputValue: T): T {\n if (Array.isArray(inputValue)) {\n return [...inputValue.map(recursiveToRaw)] as T;\n } else if (typeof inputValue === 'object' && inputValue !== null) {\n const clone: any = {};\n for (const [key, value] of Object.entries(inputValue)) {\n clone[key] = recursiveToRaw(value);\n }\n return clone;\n } else {\n return inputValue;\n }\n}\n","import type { CompletionRequestOptions, UseCompletionOptions } from 'ai';\nimport { callCompletionApi } from 'ai';\nimport swrv from 'swrv';\nimport type { Ref } from 'vue';\nimport { ref, unref } from 'vue';\n\nexport type { UseCompletionOptions };\n\nexport type UseCompletionHelpers = {\n /** The current completion result */\n completion: Ref<string>;\n /** The error object of the API request */\n error: Ref<undefined | Error>;\n /**\n * Send a new prompt to the API endpoint and update the completion state.\n */\n complete: (\n prompt: string,\n options?: CompletionRequestOptions,\n ) => Promise<string | null | undefined>;\n /**\n * Abort the current API request but keep the generated tokens.\n */\n stop: () => void;\n /**\n * Update the `completion` state locally.\n */\n setCompletion: (completion: string) => void;\n /** The current value of the input */\n input: Ref<string>;\n /**\n * Form submission handler to automatically reset input and append a user message\n * @example\n * ```jsx\n * <form @submit=\"handleSubmit\">\n * <input @change=\"handleInputChange\" v-model=\"input\" />\n * </form>\n * ```\n */\n handleSubmit: (event?: { preventDefault?: () => void }) => void;\n /** Whether the API request is in progress */\n isLoading: Ref<boolean | undefined>;\n};\n\nlet uniqueId = 0;\n\n// @ts-expect-error - some issues with the default export of useSWRV\nconst useSWRV = (swrv.default as (typeof import('swrv'))['default']) || swrv;\nconst store: Record<string, any> = {};\n\nexport function useCompletion({\n api = '/api/completion',\n id,\n initialCompletion = '',\n initialInput = '',\n credentials,\n headers,\n body,\n streamProtocol,\n onFinish,\n onError,\n fetch,\n}: UseCompletionOptions = {}): UseCompletionHelpers {\n // Generate an unique id for the completion if not provided.\n const completionId = id || `completion-${uniqueId++}`;\n\n const key = `${api}|${completionId}`;\n const { data, mutate: originalMutate } = useSWRV<string>(\n key,\n () => store[key] || initialCompletion,\n );\n\n const { data: isLoading, mutate: mutateLoading } = useSWRV<boolean>(\n `${completionId}-loading`,\n null,\n );\n\n isLoading.value ??= false;\n\n // Force the `data` to be `initialCompletion` if it's `undefined`.\n data.value ||= initialCompletion;\n\n const mutate = (data: string) => {\n store[key] = data;\n return originalMutate();\n };\n\n // Because of the `initialData` option, the `data` will never be `undefined`.\n const completion = data as Ref<string>;\n\n const error = ref<undefined | Error>(undefined);\n\n let abortController: AbortController | null = null;\n\n async function triggerRequest(\n prompt: string,\n options?: CompletionRequestOptions,\n ) {\n return callCompletionApi({\n api,\n prompt,\n credentials,\n headers: {\n ...headers,\n ...options?.headers,\n },\n body: {\n ...unref(body),\n ...options?.body,\n },\n streamProtocol,\n setCompletion: mutate,\n setLoading: loading => mutateLoading(() => loading),\n setError: err => {\n error.value = err;\n },\n setAbortController: controller => {\n abortController = controller;\n },\n onFinish,\n onError,\n fetch,\n });\n }\n\n const complete: UseCompletionHelpers['complete'] = async (\n prompt,\n options,\n ) => {\n return triggerRequest(prompt, options);\n };\n\n const stop = () => {\n if (abortController) {\n abortController.abort();\n abortController = null;\n }\n };\n\n const setCompletion = (completion: string) => {\n mutate(completion);\n };\n\n const input = ref(initialInput);\n\n const handleSubmit = (event?: { preventDefault?: () => void }) => {\n event?.preventDefault?.();\n const inputValue = input.value;\n return inputValue ? complete(inputValue) : undefined;\n };\n\n return {\n completion,\n complete,\n error,\n stop,\n setCompletion,\n input,\n handleSubmit,\n isLoading,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSA,gBASO;AACP,kBAAiB;AAEjB,iBAA2B;AA0E3B,IAAM,UAAW,YAAAA,QAAK,WAAkD,YAAAA;AACxE,IAAM,QAAsD,CAAC;AAC7D,IAAM,cAGF,CAAC;AAEE,SAAS,QACd;AAAA,EACE,MAAM;AAAA,EACN;AAAA,EACA,kBAAkB,CAAC;AAAA,EACnB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,MAAM;AAAA,EACN,aAAa,UAAAC;AAAA,EACb;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX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IdFunc","_a","import_ai","import_swrv","import_vue","useSWRV","swrv","store","data","completion","_a"]}
|