ai 0.0.0-e27b4ed4-20240419203611

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.
Files changed (56) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +37 -0
  3. package/dist/index.d.mts +1770 -0
  4. package/dist/index.d.ts +1770 -0
  5. package/dist/index.js +2958 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +2887 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +174 -0
  10. package/prompts/dist/index.d.mts +267 -0
  11. package/prompts/dist/index.d.ts +267 -0
  12. package/prompts/dist/index.js +178 -0
  13. package/prompts/dist/index.js.map +1 -0
  14. package/prompts/dist/index.mjs +146 -0
  15. package/prompts/dist/index.mjs.map +1 -0
  16. package/react/dist/index.d.mts +487 -0
  17. package/react/dist/index.d.ts +504 -0
  18. package/react/dist/index.js +1310 -0
  19. package/react/dist/index.js.map +1 -0
  20. package/react/dist/index.mjs +1271 -0
  21. package/react/dist/index.mjs.map +1 -0
  22. package/react/dist/index.server.d.mts +17 -0
  23. package/react/dist/index.server.d.ts +17 -0
  24. package/react/dist/index.server.js +50 -0
  25. package/react/dist/index.server.js.map +1 -0
  26. package/react/dist/index.server.mjs +23 -0
  27. package/react/dist/index.server.mjs.map +1 -0
  28. package/rsc/dist/index.d.ts +289 -0
  29. package/rsc/dist/index.mjs +18 -0
  30. package/rsc/dist/rsc-client.d.mts +1 -0
  31. package/rsc/dist/rsc-client.mjs +18 -0
  32. package/rsc/dist/rsc-client.mjs.map +1 -0
  33. package/rsc/dist/rsc-server.d.mts +225 -0
  34. package/rsc/dist/rsc-server.mjs +1246 -0
  35. package/rsc/dist/rsc-server.mjs.map +1 -0
  36. package/rsc/dist/rsc-shared.d.mts +94 -0
  37. package/rsc/dist/rsc-shared.mjs +346 -0
  38. package/rsc/dist/rsc-shared.mjs.map +1 -0
  39. package/solid/dist/index.d.mts +351 -0
  40. package/solid/dist/index.d.ts +351 -0
  41. package/solid/dist/index.js +1002 -0
  42. package/solid/dist/index.js.map +1 -0
  43. package/solid/dist/index.mjs +974 -0
  44. package/solid/dist/index.mjs.map +1 -0
  45. package/svelte/dist/index.d.mts +348 -0
  46. package/svelte/dist/index.d.ts +348 -0
  47. package/svelte/dist/index.js +1556 -0
  48. package/svelte/dist/index.js.map +1 -0
  49. package/svelte/dist/index.mjs +1528 -0
  50. package/svelte/dist/index.mjs.map +1 -0
  51. package/vue/dist/index.d.mts +345 -0
  52. package/vue/dist/index.d.ts +345 -0
  53. package/vue/dist/index.js +1002 -0
  54. package/vue/dist/index.js.map +1 -0
  55. package/vue/dist/index.mjs +964 -0
  56. package/vue/dist/index.mjs.map +1 -0
@@ -0,0 +1,1310 @@
1
+ 'use client'
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // react/index.ts
32
+ var react_exports = {};
33
+ __export(react_exports, {
34
+ experimental_useAssistant: () => experimental_useAssistant,
35
+ useAssistant: () => useAssistant,
36
+ useChat: () => useChat,
37
+ useCompletion: () => useCompletion
38
+ });
39
+ module.exports = __toCommonJS(react_exports);
40
+
41
+ // react/use-chat.ts
42
+ var import_react = require("react");
43
+ var import_swr = __toESM(require("swr"));
44
+
45
+ // shared/stream-parts.ts
46
+ var textStreamPart = {
47
+ code: "0",
48
+ name: "text",
49
+ parse: (value) => {
50
+ if (typeof value !== "string") {
51
+ throw new Error('"text" parts expect a string value.');
52
+ }
53
+ return { type: "text", value };
54
+ }
55
+ };
56
+ var functionCallStreamPart = {
57
+ code: "1",
58
+ name: "function_call",
59
+ parse: (value) => {
60
+ if (value == null || typeof value !== "object" || !("function_call" in value) || typeof value.function_call !== "object" || value.function_call == null || !("name" in value.function_call) || !("arguments" in value.function_call) || typeof value.function_call.name !== "string" || typeof value.function_call.arguments !== "string") {
61
+ throw new Error(
62
+ '"function_call" parts expect an object with a "function_call" property.'
63
+ );
64
+ }
65
+ return {
66
+ type: "function_call",
67
+ value
68
+ };
69
+ }
70
+ };
71
+ var dataStreamPart = {
72
+ code: "2",
73
+ name: "data",
74
+ parse: (value) => {
75
+ if (!Array.isArray(value)) {
76
+ throw new Error('"data" parts expect an array value.');
77
+ }
78
+ return { type: "data", value };
79
+ }
80
+ };
81
+ var errorStreamPart = {
82
+ code: "3",
83
+ name: "error",
84
+ parse: (value) => {
85
+ if (typeof value !== "string") {
86
+ throw new Error('"error" parts expect a string value.');
87
+ }
88
+ return { type: "error", value };
89
+ }
90
+ };
91
+ var assistantMessageStreamPart = {
92
+ code: "4",
93
+ name: "assistant_message",
94
+ parse: (value) => {
95
+ if (value == null || typeof value !== "object" || !("id" in value) || !("role" in value) || !("content" in value) || typeof value.id !== "string" || typeof value.role !== "string" || value.role !== "assistant" || !Array.isArray(value.content) || !value.content.every(
96
+ (item) => item != null && typeof item === "object" && "type" in item && item.type === "text" && "text" in item && item.text != null && typeof item.text === "object" && "value" in item.text && typeof item.text.value === "string"
97
+ )) {
98
+ throw new Error(
99
+ '"assistant_message" parts expect an object with an "id", "role", and "content" property.'
100
+ );
101
+ }
102
+ return {
103
+ type: "assistant_message",
104
+ value
105
+ };
106
+ }
107
+ };
108
+ var assistantControlDataStreamPart = {
109
+ code: "5",
110
+ name: "assistant_control_data",
111
+ parse: (value) => {
112
+ if (value == null || typeof value !== "object" || !("threadId" in value) || !("messageId" in value) || typeof value.threadId !== "string" || typeof value.messageId !== "string") {
113
+ throw new Error(
114
+ '"assistant_control_data" parts expect an object with a "threadId" and "messageId" property.'
115
+ );
116
+ }
117
+ return {
118
+ type: "assistant_control_data",
119
+ value: {
120
+ threadId: value.threadId,
121
+ messageId: value.messageId
122
+ }
123
+ };
124
+ }
125
+ };
126
+ var dataMessageStreamPart = {
127
+ code: "6",
128
+ name: "data_message",
129
+ parse: (value) => {
130
+ if (value == null || typeof value !== "object" || !("role" in value) || !("data" in value) || typeof value.role !== "string" || value.role !== "data") {
131
+ throw new Error(
132
+ '"data_message" parts expect an object with a "role" and "data" property.'
133
+ );
134
+ }
135
+ return {
136
+ type: "data_message",
137
+ value
138
+ };
139
+ }
140
+ };
141
+ var toolCallStreamPart = {
142
+ code: "7",
143
+ name: "tool_calls",
144
+ parse: (value) => {
145
+ if (value == null || typeof value !== "object" || !("tool_calls" in value) || typeof value.tool_calls !== "object" || value.tool_calls == null || !Array.isArray(value.tool_calls) || value.tool_calls.some(
146
+ (tc) => tc == null || typeof tc !== "object" || !("id" in tc) || typeof tc.id !== "string" || !("type" in tc) || typeof tc.type !== "string" || !("function" in tc) || tc.function == null || typeof tc.function !== "object" || !("arguments" in tc.function) || typeof tc.function.name !== "string" || typeof tc.function.arguments !== "string"
147
+ )) {
148
+ throw new Error(
149
+ '"tool_calls" parts expect an object with a ToolCallPayload.'
150
+ );
151
+ }
152
+ return {
153
+ type: "tool_calls",
154
+ value
155
+ };
156
+ }
157
+ };
158
+ var messageAnnotationsStreamPart = {
159
+ code: "8",
160
+ name: "message_annotations",
161
+ parse: (value) => {
162
+ if (!Array.isArray(value)) {
163
+ throw new Error('"message_annotations" parts expect an array value.');
164
+ }
165
+ return { type: "message_annotations", value };
166
+ }
167
+ };
168
+ var streamParts = [
169
+ textStreamPart,
170
+ functionCallStreamPart,
171
+ dataStreamPart,
172
+ errorStreamPart,
173
+ assistantMessageStreamPart,
174
+ assistantControlDataStreamPart,
175
+ dataMessageStreamPart,
176
+ toolCallStreamPart,
177
+ messageAnnotationsStreamPart
178
+ ];
179
+ var streamPartsByCode = {
180
+ [textStreamPart.code]: textStreamPart,
181
+ [functionCallStreamPart.code]: functionCallStreamPart,
182
+ [dataStreamPart.code]: dataStreamPart,
183
+ [errorStreamPart.code]: errorStreamPart,
184
+ [assistantMessageStreamPart.code]: assistantMessageStreamPart,
185
+ [assistantControlDataStreamPart.code]: assistantControlDataStreamPart,
186
+ [dataMessageStreamPart.code]: dataMessageStreamPart,
187
+ [toolCallStreamPart.code]: toolCallStreamPart,
188
+ [messageAnnotationsStreamPart.code]: messageAnnotationsStreamPart
189
+ };
190
+ var StreamStringPrefixes = {
191
+ [textStreamPart.name]: textStreamPart.code,
192
+ [functionCallStreamPart.name]: functionCallStreamPart.code,
193
+ [dataStreamPart.name]: dataStreamPart.code,
194
+ [errorStreamPart.name]: errorStreamPart.code,
195
+ [assistantMessageStreamPart.name]: assistantMessageStreamPart.code,
196
+ [assistantControlDataStreamPart.name]: assistantControlDataStreamPart.code,
197
+ [dataMessageStreamPart.name]: dataMessageStreamPart.code,
198
+ [toolCallStreamPart.name]: toolCallStreamPart.code,
199
+ [messageAnnotationsStreamPart.name]: messageAnnotationsStreamPart.code
200
+ };
201
+ var validCodes = streamParts.map((part) => part.code);
202
+ var parseStreamPart = (line) => {
203
+ const firstSeparatorIndex = line.indexOf(":");
204
+ if (firstSeparatorIndex === -1) {
205
+ throw new Error("Failed to parse stream string. No separator found.");
206
+ }
207
+ const prefix = line.slice(0, firstSeparatorIndex);
208
+ if (!validCodes.includes(prefix)) {
209
+ throw new Error(`Failed to parse stream string. Invalid code ${prefix}.`);
210
+ }
211
+ const code = prefix;
212
+ const textValue = line.slice(firstSeparatorIndex + 1);
213
+ const jsonValue = JSON.parse(textValue);
214
+ return streamPartsByCode[code].parse(jsonValue);
215
+ };
216
+
217
+ // shared/read-data-stream.ts
218
+ var NEWLINE = "\n".charCodeAt(0);
219
+ function concatChunks(chunks, totalLength) {
220
+ const concatenatedChunks = new Uint8Array(totalLength);
221
+ let offset = 0;
222
+ for (const chunk of chunks) {
223
+ concatenatedChunks.set(chunk, offset);
224
+ offset += chunk.length;
225
+ }
226
+ chunks.length = 0;
227
+ return concatenatedChunks;
228
+ }
229
+ async function* readDataStream(reader, {
230
+ isAborted
231
+ } = {}) {
232
+ const decoder = new TextDecoder();
233
+ const chunks = [];
234
+ let totalLength = 0;
235
+ while (true) {
236
+ const { value } = await reader.read();
237
+ if (value) {
238
+ chunks.push(value);
239
+ totalLength += value.length;
240
+ if (value[value.length - 1] !== NEWLINE) {
241
+ continue;
242
+ }
243
+ }
244
+ if (chunks.length === 0) {
245
+ break;
246
+ }
247
+ const concatenatedChunks = concatChunks(chunks, totalLength);
248
+ totalLength = 0;
249
+ const streamParts2 = decoder.decode(concatenatedChunks, { stream: true }).split("\n").filter((line) => line !== "").map(parseStreamPart);
250
+ for (const streamPart of streamParts2) {
251
+ yield streamPart;
252
+ }
253
+ if (isAborted == null ? void 0 : isAborted()) {
254
+ reader.cancel();
255
+ break;
256
+ }
257
+ }
258
+ }
259
+
260
+ // shared/generate-id.ts
261
+ var import_non_secure = require("nanoid/non-secure");
262
+ var generateId = (0, import_non_secure.customAlphabet)(
263
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
264
+ 7
265
+ );
266
+
267
+ // shared/parse-complex-response.ts
268
+ function assignAnnotationsToMessage(message, annotations) {
269
+ if (!message || !annotations || !annotations.length)
270
+ return message;
271
+ return { ...message, annotations: [...annotations] };
272
+ }
273
+ async function parseComplexResponse({
274
+ reader,
275
+ abortControllerRef,
276
+ update,
277
+ onFinish,
278
+ generateId: generateId2 = generateId,
279
+ getCurrentDate = () => /* @__PURE__ */ new Date()
280
+ }) {
281
+ const createdAt = getCurrentDate();
282
+ const prefixMap = {
283
+ data: []
284
+ };
285
+ let message_annotations = void 0;
286
+ for await (const { type, value } of readDataStream(reader, {
287
+ isAborted: () => (abortControllerRef == null ? void 0 : abortControllerRef.current) === null
288
+ })) {
289
+ if (type === "text") {
290
+ if (prefixMap["text"]) {
291
+ prefixMap["text"] = {
292
+ ...prefixMap["text"],
293
+ content: (prefixMap["text"].content || "") + value
294
+ };
295
+ } else {
296
+ prefixMap["text"] = {
297
+ id: generateId2(),
298
+ role: "assistant",
299
+ content: value,
300
+ createdAt
301
+ };
302
+ }
303
+ }
304
+ let functionCallMessage = null;
305
+ if (type === "function_call") {
306
+ prefixMap["function_call"] = {
307
+ id: generateId2(),
308
+ role: "assistant",
309
+ content: "",
310
+ function_call: value.function_call,
311
+ name: value.function_call.name,
312
+ createdAt
313
+ };
314
+ functionCallMessage = prefixMap["function_call"];
315
+ }
316
+ let toolCallMessage = null;
317
+ if (type === "tool_calls") {
318
+ prefixMap["tool_calls"] = {
319
+ id: generateId2(),
320
+ role: "assistant",
321
+ content: "",
322
+ tool_calls: value.tool_calls,
323
+ createdAt
324
+ };
325
+ toolCallMessage = prefixMap["tool_calls"];
326
+ }
327
+ if (type === "data") {
328
+ prefixMap["data"].push(...value);
329
+ }
330
+ let responseMessage = prefixMap["text"];
331
+ if (type === "message_annotations") {
332
+ if (!message_annotations) {
333
+ message_annotations = [...value];
334
+ } else {
335
+ message_annotations.push(...value);
336
+ }
337
+ functionCallMessage = assignAnnotationsToMessage(
338
+ prefixMap["function_call"],
339
+ message_annotations
340
+ );
341
+ toolCallMessage = assignAnnotationsToMessage(
342
+ prefixMap["tool_calls"],
343
+ message_annotations
344
+ );
345
+ responseMessage = assignAnnotationsToMessage(
346
+ prefixMap["text"],
347
+ message_annotations
348
+ );
349
+ }
350
+ if (message_annotations == null ? void 0 : message_annotations.length) {
351
+ const messagePrefixKeys = [
352
+ "text",
353
+ "function_call",
354
+ "tool_calls"
355
+ ];
356
+ messagePrefixKeys.forEach((key) => {
357
+ if (prefixMap[key]) {
358
+ prefixMap[key].annotations = [...message_annotations];
359
+ }
360
+ });
361
+ }
362
+ const merged = [functionCallMessage, toolCallMessage, responseMessage].filter(Boolean).map((message) => ({
363
+ ...assignAnnotationsToMessage(message, message_annotations)
364
+ }));
365
+ update(merged, [...prefixMap["data"]]);
366
+ }
367
+ onFinish == null ? void 0 : onFinish(prefixMap);
368
+ return {
369
+ messages: [
370
+ prefixMap.text,
371
+ prefixMap.function_call,
372
+ prefixMap.tool_calls
373
+ ].filter(Boolean),
374
+ data: prefixMap.data
375
+ };
376
+ }
377
+
378
+ // shared/utils.ts
379
+ function createChunkDecoder(complex) {
380
+ const decoder = new TextDecoder();
381
+ if (!complex) {
382
+ return function(chunk) {
383
+ if (!chunk)
384
+ return "";
385
+ return decoder.decode(chunk, { stream: true });
386
+ };
387
+ }
388
+ return function(chunk) {
389
+ const decoded = decoder.decode(chunk, { stream: true }).split("\n").filter((line) => line !== "");
390
+ return decoded.map(parseStreamPart).filter(Boolean);
391
+ };
392
+ }
393
+
394
+ // shared/call-chat-api.ts
395
+ async function callChatApi({
396
+ api,
397
+ messages,
398
+ body,
399
+ streamMode = "stream-data",
400
+ credentials,
401
+ headers,
402
+ abortController,
403
+ restoreMessagesOnFailure,
404
+ onResponse,
405
+ onUpdate,
406
+ onFinish,
407
+ generateId: generateId2
408
+ }) {
409
+ var _a;
410
+ const response = await fetch(api, {
411
+ method: "POST",
412
+ body: JSON.stringify({
413
+ messages,
414
+ ...body
415
+ }),
416
+ headers: {
417
+ "Content-Type": "application/json",
418
+ ...headers
419
+ },
420
+ signal: (_a = abortController == null ? void 0 : abortController()) == null ? void 0 : _a.signal,
421
+ credentials
422
+ }).catch((err) => {
423
+ restoreMessagesOnFailure();
424
+ throw err;
425
+ });
426
+ if (onResponse) {
427
+ try {
428
+ await onResponse(response);
429
+ } catch (err) {
430
+ throw err;
431
+ }
432
+ }
433
+ if (!response.ok) {
434
+ restoreMessagesOnFailure();
435
+ throw new Error(
436
+ await response.text() || "Failed to fetch the chat response."
437
+ );
438
+ }
439
+ if (!response.body) {
440
+ throw new Error("The response body is empty.");
441
+ }
442
+ const reader = response.body.getReader();
443
+ switch (streamMode) {
444
+ case "text": {
445
+ const decoder = createChunkDecoder();
446
+ const resultMessage = {
447
+ id: generateId2(),
448
+ createdAt: /* @__PURE__ */ new Date(),
449
+ role: "assistant",
450
+ content: ""
451
+ };
452
+ while (true) {
453
+ const { done, value } = await reader.read();
454
+ if (done) {
455
+ break;
456
+ }
457
+ resultMessage.content += decoder(value);
458
+ resultMessage.id = generateId2();
459
+ onUpdate([{ ...resultMessage }], []);
460
+ if ((abortController == null ? void 0 : abortController()) === null) {
461
+ reader.cancel();
462
+ break;
463
+ }
464
+ }
465
+ onFinish == null ? void 0 : onFinish(resultMessage);
466
+ return {
467
+ messages: [resultMessage],
468
+ data: []
469
+ };
470
+ }
471
+ case "stream-data": {
472
+ return await parseComplexResponse({
473
+ reader,
474
+ abortControllerRef: abortController != null ? { current: abortController() } : void 0,
475
+ update: onUpdate,
476
+ onFinish(prefixMap) {
477
+ if (onFinish && prefixMap.text != null) {
478
+ onFinish(prefixMap.text);
479
+ }
480
+ },
481
+ generateId: generateId2
482
+ });
483
+ }
484
+ default: {
485
+ const exhaustiveCheck = streamMode;
486
+ throw new Error(`Unknown stream mode: ${exhaustiveCheck}`);
487
+ }
488
+ }
489
+ }
490
+
491
+ // shared/process-chat-stream.ts
492
+ async function processChatStream({
493
+ getStreamedResponse: getStreamedResponse2,
494
+ experimental_onFunctionCall,
495
+ experimental_onToolCall,
496
+ updateChatRequest,
497
+ getCurrentMessages
498
+ }) {
499
+ while (true) {
500
+ const messagesAndDataOrJustMessage = await getStreamedResponse2();
501
+ if ("messages" in messagesAndDataOrJustMessage) {
502
+ let hasFollowingResponse = false;
503
+ for (const message of messagesAndDataOrJustMessage.messages) {
504
+ if ((message.function_call === void 0 || typeof message.function_call === "string") && (message.tool_calls === void 0 || typeof message.tool_calls === "string")) {
505
+ continue;
506
+ }
507
+ hasFollowingResponse = true;
508
+ if (experimental_onFunctionCall) {
509
+ const functionCall = message.function_call;
510
+ if (typeof functionCall !== "object") {
511
+ console.warn(
512
+ "experimental_onFunctionCall should not be defined when using tools"
513
+ );
514
+ continue;
515
+ }
516
+ const functionCallResponse = await experimental_onFunctionCall(
517
+ getCurrentMessages(),
518
+ functionCall
519
+ );
520
+ if (functionCallResponse === void 0) {
521
+ hasFollowingResponse = false;
522
+ break;
523
+ }
524
+ updateChatRequest(functionCallResponse);
525
+ }
526
+ if (experimental_onToolCall) {
527
+ const toolCalls = message.tool_calls;
528
+ if (!Array.isArray(toolCalls) || toolCalls.some((toolCall) => typeof toolCall !== "object")) {
529
+ console.warn(
530
+ "experimental_onToolCall should not be defined when using tools"
531
+ );
532
+ continue;
533
+ }
534
+ const toolCallResponse = await experimental_onToolCall(getCurrentMessages(), toolCalls);
535
+ if (toolCallResponse === void 0) {
536
+ hasFollowingResponse = false;
537
+ break;
538
+ }
539
+ updateChatRequest(toolCallResponse);
540
+ }
541
+ }
542
+ if (!hasFollowingResponse) {
543
+ break;
544
+ }
545
+ } else {
546
+ let fixFunctionCallArguments2 = function(response) {
547
+ for (const message of response.messages) {
548
+ if (message.tool_calls !== void 0) {
549
+ for (const toolCall of message.tool_calls) {
550
+ if (typeof toolCall === "object") {
551
+ if (toolCall.function.arguments && typeof toolCall.function.arguments !== "string") {
552
+ toolCall.function.arguments = JSON.stringify(
553
+ toolCall.function.arguments
554
+ );
555
+ }
556
+ }
557
+ }
558
+ }
559
+ if (message.function_call !== void 0) {
560
+ if (typeof message.function_call === "object") {
561
+ if (message.function_call.arguments && typeof message.function_call.arguments !== "string") {
562
+ message.function_call.arguments = JSON.stringify(
563
+ message.function_call.arguments
564
+ );
565
+ }
566
+ }
567
+ }
568
+ }
569
+ };
570
+ var fixFunctionCallArguments = fixFunctionCallArguments2;
571
+ const streamedResponseMessage = messagesAndDataOrJustMessage;
572
+ if ((streamedResponseMessage.function_call === void 0 || typeof streamedResponseMessage.function_call === "string") && (streamedResponseMessage.tool_calls === void 0 || typeof streamedResponseMessage.tool_calls === "string")) {
573
+ break;
574
+ }
575
+ if (experimental_onFunctionCall) {
576
+ const functionCall = streamedResponseMessage.function_call;
577
+ if (!(typeof functionCall === "object")) {
578
+ console.warn(
579
+ "experimental_onFunctionCall should not be defined when using tools"
580
+ );
581
+ continue;
582
+ }
583
+ const functionCallResponse = await experimental_onFunctionCall(getCurrentMessages(), functionCall);
584
+ if (functionCallResponse === void 0)
585
+ break;
586
+ fixFunctionCallArguments2(functionCallResponse);
587
+ updateChatRequest(functionCallResponse);
588
+ }
589
+ if (experimental_onToolCall) {
590
+ const toolCalls = streamedResponseMessage.tool_calls;
591
+ if (!(typeof toolCalls === "object")) {
592
+ console.warn(
593
+ "experimental_onToolCall should not be defined when using functions"
594
+ );
595
+ continue;
596
+ }
597
+ const toolCallResponse = await experimental_onToolCall(getCurrentMessages(), toolCalls);
598
+ if (toolCallResponse === void 0)
599
+ break;
600
+ fixFunctionCallArguments2(toolCallResponse);
601
+ updateChatRequest(toolCallResponse);
602
+ }
603
+ }
604
+ }
605
+ }
606
+
607
+ // react/use-chat.ts
608
+ var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, existingData, extraMetadataRef, messagesRef, abortControllerRef, generateId2, streamMode, onFinish, onResponse, sendExtraMessageFields) => {
609
+ var _a, _b;
610
+ const previousMessages = messagesRef.current;
611
+ mutate(chatRequest.messages, false);
612
+ const constructedMessagesPayload = sendExtraMessageFields ? chatRequest.messages : chatRequest.messages.map(
613
+ ({
614
+ role,
615
+ content,
616
+ data,
617
+ name,
618
+ function_call,
619
+ tool_calls,
620
+ tool_call_id
621
+ }) => ({
622
+ role,
623
+ content,
624
+ tool_call_id,
625
+ ...name !== void 0 && { name },
626
+ ...data !== void 0 && { data },
627
+ ...function_call !== void 0 && {
628
+ function_call
629
+ },
630
+ ...tool_calls !== void 0 && {
631
+ tool_calls
632
+ }
633
+ })
634
+ );
635
+ if (typeof api !== "string") {
636
+ const replyId = generateId2();
637
+ const createdAt = /* @__PURE__ */ new Date();
638
+ let responseMessage = {
639
+ id: replyId,
640
+ createdAt,
641
+ content: "",
642
+ role: "assistant"
643
+ };
644
+ async function readRow(promise) {
645
+ const { content, ui, next } = await promise;
646
+ responseMessage["content"] = content;
647
+ responseMessage["ui"] = await ui;
648
+ mutate([...chatRequest.messages, { ...responseMessage }], false);
649
+ if (next) {
650
+ await readRow(next);
651
+ }
652
+ }
653
+ try {
654
+ const promise = api({
655
+ messages: constructedMessagesPayload,
656
+ data: chatRequest.data
657
+ });
658
+ await readRow(promise);
659
+ } catch (e) {
660
+ mutate(previousMessages, false);
661
+ throw e;
662
+ }
663
+ if (onFinish) {
664
+ onFinish(responseMessage);
665
+ }
666
+ return responseMessage;
667
+ }
668
+ return await callChatApi({
669
+ api,
670
+ messages: constructedMessagesPayload,
671
+ body: {
672
+ data: chatRequest.data,
673
+ ...extraMetadataRef.current.body,
674
+ ...(_a = chatRequest.options) == null ? void 0 : _a.body,
675
+ ...chatRequest.functions !== void 0 && {
676
+ functions: chatRequest.functions
677
+ },
678
+ ...chatRequest.function_call !== void 0 && {
679
+ function_call: chatRequest.function_call
680
+ },
681
+ ...chatRequest.tools !== void 0 && {
682
+ tools: chatRequest.tools
683
+ },
684
+ ...chatRequest.tool_choice !== void 0 && {
685
+ tool_choice: chatRequest.tool_choice
686
+ }
687
+ },
688
+ streamMode,
689
+ credentials: extraMetadataRef.current.credentials,
690
+ headers: {
691
+ ...extraMetadataRef.current.headers,
692
+ ...(_b = chatRequest.options) == null ? void 0 : _b.headers
693
+ },
694
+ abortController: () => abortControllerRef.current,
695
+ restoreMessagesOnFailure() {
696
+ mutate(previousMessages, false);
697
+ },
698
+ onResponse,
699
+ onUpdate(merged, data) {
700
+ mutate([...chatRequest.messages, ...merged], false);
701
+ mutateStreamData([...existingData || [], ...data || []], false);
702
+ },
703
+ onFinish,
704
+ generateId: generateId2
705
+ });
706
+ };
707
+ function useChat({
708
+ api = "/api/chat",
709
+ id,
710
+ initialMessages,
711
+ initialInput = "",
712
+ sendExtraMessageFields,
713
+ experimental_onFunctionCall,
714
+ experimental_onToolCall,
715
+ streamMode,
716
+ onResponse,
717
+ onFinish,
718
+ onError,
719
+ credentials,
720
+ headers,
721
+ body,
722
+ generateId: generateId2 = generateId
723
+ } = {}) {
724
+ const hookId = (0, import_react.useId)();
725
+ const idKey = id != null ? id : hookId;
726
+ const chatKey = typeof api === "string" ? [api, idKey] : idKey;
727
+ const [initialMessagesFallback] = (0, import_react.useState)([]);
728
+ const { data: messages, mutate } = (0, import_swr.default)(
729
+ [chatKey, "messages"],
730
+ null,
731
+ { fallbackData: initialMessages != null ? initialMessages : initialMessagesFallback }
732
+ );
733
+ const { data: isLoading = false, mutate: mutateLoading } = (0, import_swr.default)(
734
+ [chatKey, "loading"],
735
+ null
736
+ );
737
+ const { data: streamData, mutate: mutateStreamData } = (0, import_swr.default)([chatKey, "streamData"], null);
738
+ const { data: error = void 0, mutate: setError } = (0, import_swr.default)([chatKey, "error"], null);
739
+ const messagesRef = (0, import_react.useRef)(messages || []);
740
+ (0, import_react.useEffect)(() => {
741
+ messagesRef.current = messages || [];
742
+ }, [messages]);
743
+ const abortControllerRef = (0, import_react.useRef)(null);
744
+ const extraMetadataRef = (0, import_react.useRef)({
745
+ credentials,
746
+ headers,
747
+ body
748
+ });
749
+ (0, import_react.useEffect)(() => {
750
+ extraMetadataRef.current = {
751
+ credentials,
752
+ headers,
753
+ body
754
+ };
755
+ }, [credentials, headers, body]);
756
+ const triggerRequest = (0, import_react.useCallback)(
757
+ async (chatRequest) => {
758
+ try {
759
+ mutateLoading(true);
760
+ setError(void 0);
761
+ const abortController = new AbortController();
762
+ abortControllerRef.current = abortController;
763
+ await processChatStream({
764
+ getStreamedResponse: () => getStreamedResponse(
765
+ api,
766
+ chatRequest,
767
+ mutate,
768
+ mutateStreamData,
769
+ streamData,
770
+ extraMetadataRef,
771
+ messagesRef,
772
+ abortControllerRef,
773
+ generateId2,
774
+ streamMode,
775
+ onFinish,
776
+ onResponse,
777
+ sendExtraMessageFields
778
+ ),
779
+ experimental_onFunctionCall,
780
+ experimental_onToolCall,
781
+ updateChatRequest: (chatRequestParam) => {
782
+ chatRequest = chatRequestParam;
783
+ },
784
+ getCurrentMessages: () => messagesRef.current
785
+ });
786
+ abortControllerRef.current = null;
787
+ } catch (err) {
788
+ if (err.name === "AbortError") {
789
+ abortControllerRef.current = null;
790
+ return null;
791
+ }
792
+ if (onError && err instanceof Error) {
793
+ onError(err);
794
+ }
795
+ setError(err);
796
+ } finally {
797
+ mutateLoading(false);
798
+ }
799
+ },
800
+ [
801
+ mutate,
802
+ mutateLoading,
803
+ api,
804
+ extraMetadataRef,
805
+ onResponse,
806
+ onFinish,
807
+ onError,
808
+ setError,
809
+ mutateStreamData,
810
+ streamData,
811
+ sendExtraMessageFields,
812
+ experimental_onFunctionCall,
813
+ experimental_onToolCall,
814
+ messagesRef,
815
+ abortControllerRef,
816
+ generateId2
817
+ ]
818
+ );
819
+ const append = (0, import_react.useCallback)(
820
+ async (message, {
821
+ options,
822
+ functions,
823
+ function_call,
824
+ tools,
825
+ tool_choice,
826
+ data
827
+ } = {}) => {
828
+ if (!message.id) {
829
+ message.id = generateId2();
830
+ }
831
+ const chatRequest = {
832
+ messages: messagesRef.current.concat(message),
833
+ options,
834
+ data,
835
+ ...functions !== void 0 && { functions },
836
+ ...function_call !== void 0 && { function_call },
837
+ ...tools !== void 0 && { tools },
838
+ ...tool_choice !== void 0 && { tool_choice }
839
+ };
840
+ return triggerRequest(chatRequest);
841
+ },
842
+ [triggerRequest, generateId2]
843
+ );
844
+ const reload = (0, import_react.useCallback)(
845
+ async ({
846
+ options,
847
+ functions,
848
+ function_call,
849
+ tools,
850
+ tool_choice
851
+ } = {}) => {
852
+ if (messagesRef.current.length === 0)
853
+ return null;
854
+ const lastMessage = messagesRef.current[messagesRef.current.length - 1];
855
+ if (lastMessage.role === "assistant") {
856
+ const chatRequest2 = {
857
+ messages: messagesRef.current.slice(0, -1),
858
+ options,
859
+ ...functions !== void 0 && { functions },
860
+ ...function_call !== void 0 && { function_call },
861
+ ...tools !== void 0 && { tools },
862
+ ...tool_choice !== void 0 && { tool_choice }
863
+ };
864
+ return triggerRequest(chatRequest2);
865
+ }
866
+ const chatRequest = {
867
+ messages: messagesRef.current,
868
+ options,
869
+ ...functions !== void 0 && { functions },
870
+ ...function_call !== void 0 && { function_call },
871
+ ...tools !== void 0 && { tools },
872
+ ...tool_choice !== void 0 && { tool_choice }
873
+ };
874
+ return triggerRequest(chatRequest);
875
+ },
876
+ [triggerRequest]
877
+ );
878
+ const stop = (0, import_react.useCallback)(() => {
879
+ if (abortControllerRef.current) {
880
+ abortControllerRef.current.abort();
881
+ abortControllerRef.current = null;
882
+ }
883
+ }, []);
884
+ const setMessages = (0, import_react.useCallback)(
885
+ (messages2) => {
886
+ mutate(messages2, false);
887
+ messagesRef.current = messages2;
888
+ },
889
+ [mutate]
890
+ );
891
+ const [input, setInput] = (0, import_react.useState)(initialInput);
892
+ const handleSubmit = (0, import_react.useCallback)(
893
+ (e, options = {}, metadata) => {
894
+ if (metadata) {
895
+ extraMetadataRef.current = {
896
+ ...extraMetadataRef.current,
897
+ ...metadata
898
+ };
899
+ }
900
+ e.preventDefault();
901
+ if (!input)
902
+ return;
903
+ append(
904
+ {
905
+ content: input,
906
+ role: "user",
907
+ createdAt: /* @__PURE__ */ new Date()
908
+ },
909
+ options
910
+ );
911
+ setInput("");
912
+ },
913
+ [input, append]
914
+ );
915
+ const handleInputChange = (e) => {
916
+ setInput(e.target.value);
917
+ };
918
+ return {
919
+ messages: messages || [],
920
+ error,
921
+ append,
922
+ reload,
923
+ stop,
924
+ setMessages,
925
+ input,
926
+ setInput,
927
+ handleInputChange,
928
+ handleSubmit,
929
+ isLoading,
930
+ data: streamData
931
+ };
932
+ }
933
+
934
+ // react/use-completion.ts
935
+ var import_react2 = require("react");
936
+ var import_swr2 = __toESM(require("swr"));
937
+
938
+ // shared/call-completion-api.ts
939
+ async function callCompletionApi({
940
+ api,
941
+ prompt,
942
+ credentials,
943
+ headers,
944
+ body,
945
+ streamMode = "stream-data",
946
+ setCompletion,
947
+ setLoading,
948
+ setError,
949
+ setAbortController,
950
+ onResponse,
951
+ onFinish,
952
+ onError,
953
+ onData
954
+ }) {
955
+ try {
956
+ setLoading(true);
957
+ setError(void 0);
958
+ const abortController = new AbortController();
959
+ setAbortController(abortController);
960
+ setCompletion("");
961
+ const res = await fetch(api, {
962
+ method: "POST",
963
+ body: JSON.stringify({
964
+ prompt,
965
+ ...body
966
+ }),
967
+ credentials,
968
+ headers: {
969
+ "Content-Type": "application/json",
970
+ ...headers
971
+ },
972
+ signal: abortController.signal
973
+ }).catch((err) => {
974
+ throw err;
975
+ });
976
+ if (onResponse) {
977
+ try {
978
+ await onResponse(res);
979
+ } catch (err) {
980
+ throw err;
981
+ }
982
+ }
983
+ if (!res.ok) {
984
+ throw new Error(
985
+ await res.text() || "Failed to fetch the chat response."
986
+ );
987
+ }
988
+ if (!res.body) {
989
+ throw new Error("The response body is empty.");
990
+ }
991
+ let result = "";
992
+ const reader = res.body.getReader();
993
+ switch (streamMode) {
994
+ case "text": {
995
+ const decoder = createChunkDecoder();
996
+ while (true) {
997
+ const { done, value } = await reader.read();
998
+ if (done) {
999
+ break;
1000
+ }
1001
+ result += decoder(value);
1002
+ setCompletion(result);
1003
+ if (abortController === null) {
1004
+ reader.cancel();
1005
+ break;
1006
+ }
1007
+ }
1008
+ break;
1009
+ }
1010
+ case "stream-data": {
1011
+ for await (const { type, value } of readDataStream(reader, {
1012
+ isAborted: () => abortController === null
1013
+ })) {
1014
+ switch (type) {
1015
+ case "text": {
1016
+ result += value;
1017
+ setCompletion(result);
1018
+ break;
1019
+ }
1020
+ case "data": {
1021
+ onData == null ? void 0 : onData(value);
1022
+ break;
1023
+ }
1024
+ }
1025
+ }
1026
+ break;
1027
+ }
1028
+ default: {
1029
+ const exhaustiveCheck = streamMode;
1030
+ throw new Error(`Unknown stream mode: ${exhaustiveCheck}`);
1031
+ }
1032
+ }
1033
+ if (onFinish) {
1034
+ onFinish(prompt, result);
1035
+ }
1036
+ setAbortController(null);
1037
+ return result;
1038
+ } catch (err) {
1039
+ if (err.name === "AbortError") {
1040
+ setAbortController(null);
1041
+ return null;
1042
+ }
1043
+ if (err instanceof Error) {
1044
+ if (onError) {
1045
+ onError(err);
1046
+ }
1047
+ }
1048
+ setError(err);
1049
+ } finally {
1050
+ setLoading(false);
1051
+ }
1052
+ }
1053
+
1054
+ // react/use-completion.ts
1055
+ function useCompletion({
1056
+ api = "/api/completion",
1057
+ id,
1058
+ initialCompletion = "",
1059
+ initialInput = "",
1060
+ credentials,
1061
+ headers,
1062
+ body,
1063
+ streamMode,
1064
+ onResponse,
1065
+ onFinish,
1066
+ onError
1067
+ } = {}) {
1068
+ const hookId = (0, import_react2.useId)();
1069
+ const completionId = id || hookId;
1070
+ const { data, mutate } = (0, import_swr2.default)([api, completionId], null, {
1071
+ fallbackData: initialCompletion
1072
+ });
1073
+ const { data: isLoading = false, mutate: mutateLoading } = (0, import_swr2.default)(
1074
+ [completionId, "loading"],
1075
+ null
1076
+ );
1077
+ const { data: streamData, mutate: mutateStreamData } = (0, import_swr2.default)([completionId, "streamData"], null);
1078
+ const [error, setError] = (0, import_react2.useState)(void 0);
1079
+ const completion = data;
1080
+ const [abortController, setAbortController] = (0, import_react2.useState)(null);
1081
+ const extraMetadataRef = (0, import_react2.useRef)({
1082
+ credentials,
1083
+ headers,
1084
+ body
1085
+ });
1086
+ (0, import_react2.useEffect)(() => {
1087
+ extraMetadataRef.current = {
1088
+ credentials,
1089
+ headers,
1090
+ body
1091
+ };
1092
+ }, [credentials, headers, body]);
1093
+ const triggerRequest = (0, import_react2.useCallback)(
1094
+ async (prompt, options) => callCompletionApi({
1095
+ api,
1096
+ prompt,
1097
+ credentials: extraMetadataRef.current.credentials,
1098
+ headers: { ...extraMetadataRef.current.headers, ...options == null ? void 0 : options.headers },
1099
+ body: {
1100
+ ...extraMetadataRef.current.body,
1101
+ ...options == null ? void 0 : options.body
1102
+ },
1103
+ streamMode,
1104
+ setCompletion: (completion2) => mutate(completion2, false),
1105
+ setLoading: mutateLoading,
1106
+ setError,
1107
+ setAbortController,
1108
+ onResponse,
1109
+ onFinish,
1110
+ onError,
1111
+ onData: (data2) => {
1112
+ mutateStreamData([...streamData || [], ...data2 || []], false);
1113
+ }
1114
+ }),
1115
+ [
1116
+ mutate,
1117
+ mutateLoading,
1118
+ api,
1119
+ extraMetadataRef,
1120
+ setAbortController,
1121
+ onResponse,
1122
+ onFinish,
1123
+ onError,
1124
+ setError,
1125
+ streamData,
1126
+ mutateStreamData
1127
+ ]
1128
+ );
1129
+ const stop = (0, import_react2.useCallback)(() => {
1130
+ if (abortController) {
1131
+ abortController.abort();
1132
+ setAbortController(null);
1133
+ }
1134
+ }, [abortController]);
1135
+ const setCompletion = (0, import_react2.useCallback)(
1136
+ (completion2) => {
1137
+ mutate(completion2, false);
1138
+ },
1139
+ [mutate]
1140
+ );
1141
+ const complete = (0, import_react2.useCallback)(
1142
+ async (prompt, options) => {
1143
+ return triggerRequest(prompt, options);
1144
+ },
1145
+ [triggerRequest]
1146
+ );
1147
+ const [input, setInput] = (0, import_react2.useState)(initialInput);
1148
+ const handleSubmit = (0, import_react2.useCallback)(
1149
+ (e) => {
1150
+ e.preventDefault();
1151
+ if (!input)
1152
+ return;
1153
+ return complete(input);
1154
+ },
1155
+ [input, complete]
1156
+ );
1157
+ const handleInputChange = (e) => {
1158
+ setInput(e.target.value);
1159
+ };
1160
+ return {
1161
+ completion,
1162
+ complete,
1163
+ error,
1164
+ setCompletion,
1165
+ stop,
1166
+ input,
1167
+ setInput,
1168
+ handleInputChange,
1169
+ handleSubmit,
1170
+ isLoading,
1171
+ data: streamData
1172
+ };
1173
+ }
1174
+
1175
+ // react/use-assistant.ts
1176
+ var import_react3 = require("react");
1177
+ function useAssistant({
1178
+ api,
1179
+ threadId: threadIdParam,
1180
+ credentials,
1181
+ headers,
1182
+ body,
1183
+ onError
1184
+ }) {
1185
+ const [messages, setMessages] = (0, import_react3.useState)([]);
1186
+ const [input, setInput] = (0, import_react3.useState)("");
1187
+ const [threadId, setThreadId] = (0, import_react3.useState)(void 0);
1188
+ const [status, setStatus] = (0, import_react3.useState)("awaiting_message");
1189
+ const [error, setError] = (0, import_react3.useState)(void 0);
1190
+ const handleInputChange = (event) => {
1191
+ setInput(event.target.value);
1192
+ };
1193
+ const submitMessage = async (event, requestOptions) => {
1194
+ var _a, _b;
1195
+ (_a = event == null ? void 0 : event.preventDefault) == null ? void 0 : _a.call(event);
1196
+ if (input === "") {
1197
+ return;
1198
+ }
1199
+ setStatus("in_progress");
1200
+ setMessages((messages2) => [
1201
+ ...messages2,
1202
+ { id: "", role: "user", content: input }
1203
+ ]);
1204
+ setInput("");
1205
+ const result = await fetch(api, {
1206
+ method: "POST",
1207
+ credentials,
1208
+ headers: { "Content-Type": "application/json", ...headers },
1209
+ body: JSON.stringify({
1210
+ ...body,
1211
+ // always use user-provided threadId when available:
1212
+ threadId: (_b = threadIdParam != null ? threadIdParam : threadId) != null ? _b : null,
1213
+ message: input,
1214
+ // optional request data:
1215
+ data: requestOptions == null ? void 0 : requestOptions.data
1216
+ })
1217
+ });
1218
+ if (result.body == null) {
1219
+ throw new Error("The response body is empty.");
1220
+ }
1221
+ try {
1222
+ for await (const { type, value } of readDataStream(
1223
+ result.body.getReader()
1224
+ )) {
1225
+ switch (type) {
1226
+ case "assistant_message": {
1227
+ setMessages((messages2) => [
1228
+ ...messages2,
1229
+ {
1230
+ id: value.id,
1231
+ role: value.role,
1232
+ content: value.content[0].text.value
1233
+ }
1234
+ ]);
1235
+ break;
1236
+ }
1237
+ case "text": {
1238
+ setMessages((messages2) => {
1239
+ const lastMessage = messages2[messages2.length - 1];
1240
+ return [
1241
+ ...messages2.slice(0, messages2.length - 1),
1242
+ {
1243
+ id: lastMessage.id,
1244
+ role: lastMessage.role,
1245
+ content: lastMessage.content + value
1246
+ }
1247
+ ];
1248
+ });
1249
+ break;
1250
+ }
1251
+ case "data_message": {
1252
+ setMessages((messages2) => {
1253
+ var _a2;
1254
+ return [
1255
+ ...messages2,
1256
+ {
1257
+ id: (_a2 = value.id) != null ? _a2 : generateId(),
1258
+ role: "data",
1259
+ content: "",
1260
+ data: value.data
1261
+ }
1262
+ ];
1263
+ });
1264
+ break;
1265
+ }
1266
+ case "assistant_control_data": {
1267
+ setThreadId(value.threadId);
1268
+ setMessages((messages2) => {
1269
+ const lastMessage = messages2[messages2.length - 1];
1270
+ lastMessage.id = value.messageId;
1271
+ return [...messages2.slice(0, messages2.length - 1), lastMessage];
1272
+ });
1273
+ break;
1274
+ }
1275
+ case "error": {
1276
+ const errorObj = new Error(value);
1277
+ setError(errorObj);
1278
+ break;
1279
+ }
1280
+ }
1281
+ }
1282
+ } catch (error2) {
1283
+ if (onError && error2 instanceof Error) {
1284
+ onError(error2);
1285
+ }
1286
+ setError(error2);
1287
+ }
1288
+ setStatus("awaiting_message");
1289
+ };
1290
+ return {
1291
+ messages,
1292
+ setMessages,
1293
+ threadId,
1294
+ input,
1295
+ setInput,
1296
+ handleInputChange,
1297
+ submitMessage,
1298
+ status,
1299
+ error
1300
+ };
1301
+ }
1302
+ var experimental_useAssistant = useAssistant;
1303
+ // Annotate the CommonJS export names for ESM import in node:
1304
+ 0 && (module.exports = {
1305
+ experimental_useAssistant,
1306
+ useAssistant,
1307
+ useChat,
1308
+ useCompletion
1309
+ });
1310
+ //# sourceMappingURL=index.js.map