ai 3.1.0-canary.4 → 3.1.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/dist/index.d.mts +982 -24
- package/dist/index.d.ts +982 -24
- package/dist/index.js +1748 -175
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1723 -174
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -28
- package/prompts/dist/index.d.mts +13 -1
- package/prompts/dist/index.d.ts +13 -1
- package/prompts/dist/index.js +13 -0
- package/prompts/dist/index.js.map +1 -1
- package/prompts/dist/index.mjs +12 -0
- package/prompts/dist/index.mjs.map +1 -1
- package/react/dist/index.d.mts +23 -6
- package/react/dist/index.d.ts +27 -8
- package/react/dist/index.js +154 -141
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +153 -141
- package/react/dist/index.mjs.map +1 -1
- package/react/dist/index.server.d.mts +4 -2
- package/react/dist/index.server.d.ts +4 -2
- package/react/dist/index.server.js.map +1 -1
- package/react/dist/index.server.mjs.map +1 -1
- package/rsc/dist/index.d.ts +388 -21
- package/rsc/dist/rsc-client.d.mts +1 -1
- package/rsc/dist/rsc-client.mjs +2 -0
- package/rsc/dist/rsc-client.mjs.map +1 -1
- package/rsc/dist/rsc-server.d.mts +370 -21
- package/rsc/dist/rsc-server.mjs +677 -36
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/rsc/dist/rsc-shared.d.mts +24 -9
- package/rsc/dist/rsc-shared.mjs +98 -4
- package/rsc/dist/rsc-shared.mjs.map +1 -1
- package/solid/dist/index.d.mts +7 -3
- package/solid/dist/index.d.ts +7 -3
- package/solid/dist/index.js +106 -107
- package/solid/dist/index.js.map +1 -1
- package/solid/dist/index.mjs +106 -107
- package/solid/dist/index.mjs.map +1 -1
- package/svelte/dist/index.d.mts +7 -3
- package/svelte/dist/index.d.ts +7 -3
- package/svelte/dist/index.js +109 -109
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs +109 -109
- package/svelte/dist/index.mjs.map +1 -1
- package/vue/dist/index.d.mts +7 -3
- package/vue/dist/index.d.ts +7 -3
- package/vue/dist/index.js +106 -107
- package/vue/dist/index.js.map +1 -1
- package/vue/dist/index.mjs +106 -107
- package/vue/dist/index.mjs.map +1 -1
- package/ai-model-specification/dist/index.d.mts +0 -665
- package/ai-model-specification/dist/index.d.ts +0 -665
- package/ai-model-specification/dist/index.js +0 -716
- package/ai-model-specification/dist/index.js.map +0 -1
- package/ai-model-specification/dist/index.mjs +0 -656
- package/ai-model-specification/dist/index.mjs.map +0 -1
- package/core/dist/index.d.mts +0 -626
- package/core/dist/index.d.ts +0 -626
- package/core/dist/index.js +0 -1918
- package/core/dist/index.js.map +0 -1
- package/core/dist/index.mjs +0 -1873
- package/core/dist/index.mjs.map +0 -1
- package/openai/dist/index.d.mts +0 -429
- package/openai/dist/index.d.ts +0 -429
- package/openai/dist/index.js +0 -1231
- package/openai/dist/index.js.map +0 -1
- package/openai/dist/index.mjs +0 -1195
- package/openai/dist/index.mjs.map +0 -1
package/react/dist/index.js
CHANGED
@@ -32,6 +32,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
32
32
|
var react_exports = {};
|
33
33
|
__export(react_exports, {
|
34
34
|
experimental_useAssistant: () => experimental_useAssistant,
|
35
|
+
useAssistant: () => useAssistant,
|
35
36
|
useChat: () => useChat,
|
36
37
|
useCompletion: () => useCompletion
|
37
38
|
});
|
@@ -141,9 +142,9 @@ var toolCallStreamPart = {
|
|
141
142
|
code: "7",
|
142
143
|
name: "tool_calls",
|
143
144
|
parse: (value) => {
|
144
|
-
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(
|
145
|
-
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"
|
146
|
-
|
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
|
+
)) {
|
147
148
|
throw new Error(
|
148
149
|
'"tool_calls" parts expect an object with a ToolCallPayload.'
|
149
150
|
);
|
@@ -256,27 +257,12 @@ async function* readDataStream(reader, {
|
|
256
257
|
}
|
257
258
|
}
|
258
259
|
|
259
|
-
// shared/
|
260
|
+
// shared/generate-id.ts
|
260
261
|
var import_non_secure = require("nanoid/non-secure");
|
261
|
-
var
|
262
|
+
var generateId = (0, import_non_secure.customAlphabet)(
|
262
263
|
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
263
264
|
7
|
264
265
|
);
|
265
|
-
function createChunkDecoder(complex) {
|
266
|
-
const decoder = new TextDecoder();
|
267
|
-
if (!complex) {
|
268
|
-
return function(chunk) {
|
269
|
-
if (!chunk)
|
270
|
-
return "";
|
271
|
-
return decoder.decode(chunk, { stream: true });
|
272
|
-
};
|
273
|
-
}
|
274
|
-
return function(chunk) {
|
275
|
-
const decoded = decoder.decode(chunk, { stream: true }).split("\n").filter((line) => line !== "");
|
276
|
-
return decoded.map(parseStreamPart).filter(Boolean);
|
277
|
-
};
|
278
|
-
}
|
279
|
-
var COMPLEX_HEADER = "X-Experimental-Stream-Data";
|
280
266
|
|
281
267
|
// shared/parse-complex-response.ts
|
282
268
|
function assignAnnotationsToMessage(message, annotations) {
|
@@ -289,7 +275,7 @@ async function parseComplexResponse({
|
|
289
275
|
abortControllerRef,
|
290
276
|
update,
|
291
277
|
onFinish,
|
292
|
-
generateId =
|
278
|
+
generateId: generateId2 = generateId,
|
293
279
|
getCurrentDate = () => /* @__PURE__ */ new Date()
|
294
280
|
}) {
|
295
281
|
const createdAt = getCurrentDate();
|
@@ -308,7 +294,7 @@ async function parseComplexResponse({
|
|
308
294
|
};
|
309
295
|
} else {
|
310
296
|
prefixMap["text"] = {
|
311
|
-
id:
|
297
|
+
id: generateId2(),
|
312
298
|
role: "assistant",
|
313
299
|
content: value,
|
314
300
|
createdAt
|
@@ -318,7 +304,7 @@ async function parseComplexResponse({
|
|
318
304
|
let functionCallMessage = null;
|
319
305
|
if (type === "function_call") {
|
320
306
|
prefixMap["function_call"] = {
|
321
|
-
id:
|
307
|
+
id: generateId2(),
|
322
308
|
role: "assistant",
|
323
309
|
content: "",
|
324
310
|
function_call: value.function_call,
|
@@ -330,7 +316,7 @@ async function parseComplexResponse({
|
|
330
316
|
let toolCallMessage = null;
|
331
317
|
if (type === "tool_calls") {
|
332
318
|
prefixMap["tool_calls"] = {
|
333
|
-
id:
|
319
|
+
id: generateId2(),
|
334
320
|
role: "assistant",
|
335
321
|
content: "",
|
336
322
|
tool_calls: value.tool_calls,
|
@@ -389,20 +375,36 @@ async function parseComplexResponse({
|
|
389
375
|
};
|
390
376
|
}
|
391
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
|
+
|
392
394
|
// shared/call-chat-api.ts
|
393
395
|
async function callChatApi({
|
394
396
|
api,
|
395
397
|
messages,
|
396
398
|
body,
|
399
|
+
streamMode = "stream-data",
|
397
400
|
credentials,
|
398
401
|
headers,
|
399
402
|
abortController,
|
400
|
-
appendMessage,
|
401
403
|
restoreMessagesOnFailure,
|
402
404
|
onResponse,
|
403
405
|
onUpdate,
|
404
406
|
onFinish,
|
405
|
-
generateId
|
407
|
+
generateId: generateId2
|
406
408
|
}) {
|
407
409
|
var _a;
|
408
410
|
const response = await fetch(api, {
|
@@ -438,63 +440,51 @@ async function callChatApi({
|
|
438
440
|
throw new Error("The response body is empty.");
|
439
441
|
}
|
440
442
|
const reader = response.body.getReader();
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
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;
|
450
463
|
}
|
451
|
-
},
|
452
|
-
generateId
|
453
|
-
});
|
454
|
-
} else {
|
455
|
-
const createdAt = /* @__PURE__ */ new Date();
|
456
|
-
const decode = createChunkDecoder(false);
|
457
|
-
let streamedResponse = "";
|
458
|
-
const replyId = generateId();
|
459
|
-
let responseMessage = {
|
460
|
-
id: replyId,
|
461
|
-
createdAt,
|
462
|
-
content: "",
|
463
|
-
role: "assistant"
|
464
|
-
};
|
465
|
-
while (true) {
|
466
|
-
const { done, value } = await reader.read();
|
467
|
-
if (done) {
|
468
|
-
break;
|
469
|
-
}
|
470
|
-
streamedResponse += decode(value);
|
471
|
-
if (streamedResponse.startsWith('{"function_call":')) {
|
472
|
-
responseMessage["function_call"] = streamedResponse;
|
473
|
-
} else if (streamedResponse.startsWith('{"tool_calls":')) {
|
474
|
-
responseMessage["tool_calls"] = streamedResponse;
|
475
|
-
} else {
|
476
|
-
responseMessage["content"] = streamedResponse;
|
477
|
-
}
|
478
|
-
appendMessage({ ...responseMessage });
|
479
|
-
if ((abortController == null ? void 0 : abortController()) === null) {
|
480
|
-
reader.cancel();
|
481
|
-
break;
|
482
464
|
}
|
465
|
+
onFinish == null ? void 0 : onFinish(resultMessage);
|
466
|
+
return {
|
467
|
+
messages: [resultMessage],
|
468
|
+
data: []
|
469
|
+
};
|
483
470
|
}
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
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
|
+
});
|
493
483
|
}
|
494
|
-
|
495
|
-
|
484
|
+
default: {
|
485
|
+
const exhaustiveCheck = streamMode;
|
486
|
+
throw new Error(`Unknown stream mode: ${exhaustiveCheck}`);
|
496
487
|
}
|
497
|
-
return responseMessage;
|
498
488
|
}
|
499
489
|
}
|
500
490
|
|
@@ -615,7 +605,7 @@ async function processChatStream({
|
|
615
605
|
}
|
616
606
|
|
617
607
|
// react/use-chat.ts
|
618
|
-
var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, existingData, extraMetadataRef, messagesRef, abortControllerRef,
|
608
|
+
var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, existingData, extraMetadataRef, messagesRef, abortControllerRef, generateId2, streamMode, onFinish, onResponse, sendExtraMessageFields) => {
|
619
609
|
var _a, _b;
|
620
610
|
const previousMessages = messagesRef.current;
|
621
611
|
mutate(chatRequest.messages, false);
|
@@ -634,7 +624,7 @@ var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, exi
|
|
634
624
|
})
|
635
625
|
);
|
636
626
|
if (typeof api !== "string") {
|
637
|
-
const replyId =
|
627
|
+
const replyId = generateId2();
|
638
628
|
const createdAt = /* @__PURE__ */ new Date();
|
639
629
|
let responseMessage = {
|
640
630
|
id: replyId,
|
@@ -686,15 +676,13 @@ var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, exi
|
|
686
676
|
tool_choice: chatRequest.tool_choice
|
687
677
|
}
|
688
678
|
},
|
679
|
+
streamMode,
|
689
680
|
credentials: extraMetadataRef.current.credentials,
|
690
681
|
headers: {
|
691
682
|
...extraMetadataRef.current.headers,
|
692
683
|
...(_b = chatRequest.options) == null ? void 0 : _b.headers
|
693
684
|
},
|
694
685
|
abortController: () => abortControllerRef.current,
|
695
|
-
appendMessage(message) {
|
696
|
-
mutate([...chatRequest.messages, message], false);
|
697
|
-
},
|
698
686
|
restoreMessagesOnFailure() {
|
699
687
|
mutate(previousMessages, false);
|
700
688
|
},
|
@@ -704,7 +692,7 @@ var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, exi
|
|
704
692
|
mutateStreamData([...existingData || [], ...data || []], false);
|
705
693
|
},
|
706
694
|
onFinish,
|
707
|
-
generateId
|
695
|
+
generateId: generateId2
|
708
696
|
});
|
709
697
|
};
|
710
698
|
function useChat({
|
@@ -715,13 +703,14 @@ function useChat({
|
|
715
703
|
sendExtraMessageFields,
|
716
704
|
experimental_onFunctionCall,
|
717
705
|
experimental_onToolCall,
|
706
|
+
streamMode,
|
718
707
|
onResponse,
|
719
708
|
onFinish,
|
720
709
|
onError,
|
721
710
|
credentials,
|
722
711
|
headers,
|
723
712
|
body,
|
724
|
-
generateId =
|
713
|
+
generateId: generateId2 = generateId
|
725
714
|
} = {}) {
|
726
715
|
const hookId = (0, import_react.useId)();
|
727
716
|
const idKey = id != null ? id : hookId;
|
@@ -772,7 +761,8 @@ function useChat({
|
|
772
761
|
extraMetadataRef,
|
773
762
|
messagesRef,
|
774
763
|
abortControllerRef,
|
775
|
-
|
764
|
+
generateId2,
|
765
|
+
streamMode,
|
776
766
|
onFinish,
|
777
767
|
onResponse,
|
778
768
|
sendExtraMessageFields
|
@@ -814,7 +804,7 @@ function useChat({
|
|
814
804
|
experimental_onToolCall,
|
815
805
|
messagesRef,
|
816
806
|
abortControllerRef,
|
817
|
-
|
807
|
+
generateId2
|
818
808
|
]
|
819
809
|
);
|
820
810
|
const append = (0, import_react.useCallback)(
|
@@ -827,7 +817,7 @@ function useChat({
|
|
827
817
|
data
|
828
818
|
} = {}) => {
|
829
819
|
if (!message.id) {
|
830
|
-
message.id =
|
820
|
+
message.id = generateId2();
|
831
821
|
}
|
832
822
|
const chatRequest = {
|
833
823
|
messages: messagesRef.current.concat(message),
|
@@ -840,7 +830,7 @@ function useChat({
|
|
840
830
|
};
|
841
831
|
return triggerRequest(chatRequest);
|
842
832
|
},
|
843
|
-
[triggerRequest,
|
833
|
+
[triggerRequest, generateId2]
|
844
834
|
);
|
845
835
|
const reload = (0, import_react.useCallback)(
|
846
836
|
async ({
|
@@ -943,6 +933,7 @@ async function callCompletionApi({
|
|
943
933
|
credentials,
|
944
934
|
headers,
|
945
935
|
body,
|
936
|
+
streamMode = "stream-data",
|
946
937
|
setCompletion,
|
947
938
|
setLoading,
|
948
939
|
setError,
|
@@ -990,36 +981,44 @@ async function callCompletionApi({
|
|
990
981
|
}
|
991
982
|
let result = "";
|
992
983
|
const reader = res.body.getReader();
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
case "text": {
|
1000
|
-
result += value;
|
1001
|
-
setCompletion(result);
|
984
|
+
switch (streamMode) {
|
985
|
+
case "text": {
|
986
|
+
const decoder = createChunkDecoder();
|
987
|
+
while (true) {
|
988
|
+
const { done, value } = await reader.read();
|
989
|
+
if (done) {
|
1002
990
|
break;
|
1003
991
|
}
|
1004
|
-
|
1005
|
-
|
992
|
+
result += decoder(value);
|
993
|
+
setCompletion(result);
|
994
|
+
if (abortController === null) {
|
995
|
+
reader.cancel();
|
1006
996
|
break;
|
1007
997
|
}
|
1008
998
|
}
|
999
|
+
break;
|
1009
1000
|
}
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1001
|
+
case "stream-data": {
|
1002
|
+
for await (const { type, value } of readDataStream(reader, {
|
1003
|
+
isAborted: () => abortController === null
|
1004
|
+
})) {
|
1005
|
+
switch (type) {
|
1006
|
+
case "text": {
|
1007
|
+
result += value;
|
1008
|
+
setCompletion(result);
|
1009
|
+
break;
|
1010
|
+
}
|
1011
|
+
case "data": {
|
1012
|
+
onData == null ? void 0 : onData(value);
|
1013
|
+
break;
|
1014
|
+
}
|
1015
|
+
}
|
1022
1016
|
}
|
1017
|
+
break;
|
1018
|
+
}
|
1019
|
+
default: {
|
1020
|
+
const exhaustiveCheck = streamMode;
|
1021
|
+
throw new Error(`Unknown stream mode: ${exhaustiveCheck}`);
|
1023
1022
|
}
|
1024
1023
|
}
|
1025
1024
|
if (onFinish) {
|
@@ -1052,6 +1051,7 @@ function useCompletion({
|
|
1052
1051
|
credentials,
|
1053
1052
|
headers,
|
1054
1053
|
body,
|
1054
|
+
streamMode,
|
1055
1055
|
onResponse,
|
1056
1056
|
onFinish,
|
1057
1057
|
onError
|
@@ -1091,6 +1091,7 @@ function useCompletion({
|
|
1091
1091
|
...extraMetadataRef.current.body,
|
1092
1092
|
...options == null ? void 0 : options.body
|
1093
1093
|
},
|
1094
|
+
streamMode,
|
1094
1095
|
setCompletion: (completion2) => mutate(completion2, false),
|
1095
1096
|
setLoading: mutateLoading,
|
1096
1097
|
setError,
|
@@ -1163,9 +1164,8 @@ function useCompletion({
|
|
1163
1164
|
}
|
1164
1165
|
|
1165
1166
|
// react/use-assistant.ts
|
1166
|
-
var import_nanoid = require("nanoid");
|
1167
1167
|
var import_react3 = require("react");
|
1168
|
-
function
|
1168
|
+
function useAssistant({
|
1169
1169
|
api,
|
1170
1170
|
threadId: threadIdParam,
|
1171
1171
|
credentials,
|
@@ -1181,35 +1181,37 @@ function experimental_useAssistant({
|
|
1181
1181
|
const handleInputChange = (event) => {
|
1182
1182
|
setInput(event.target.value);
|
1183
1183
|
};
|
1184
|
-
const
|
1185
|
-
var _a
|
1186
|
-
(_a = event == null ? void 0 : event.preventDefault) == null ? void 0 : _a.call(event);
|
1187
|
-
if (input === "") {
|
1188
|
-
return;
|
1189
|
-
}
|
1184
|
+
const append = async (message, requestOptions) => {
|
1185
|
+
var _a;
|
1190
1186
|
setStatus("in_progress");
|
1191
|
-
setMessages((messages2) =>
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
body: JSON.stringify({
|
1201
|
-
...body,
|
1202
|
-
// always use user-provided threadId when available:
|
1203
|
-
threadId: (_b = threadIdParam != null ? threadIdParam : threadId) != null ? _b : null,
|
1204
|
-
message: input,
|
1205
|
-
// optional request data:
|
1206
|
-
data: requestOptions == null ? void 0 : requestOptions.data
|
1207
|
-
})
|
1187
|
+
setMessages((messages2) => {
|
1188
|
+
var _a2;
|
1189
|
+
return [
|
1190
|
+
...messages2,
|
1191
|
+
{
|
1192
|
+
...message,
|
1193
|
+
id: (_a2 = message.id) != null ? _a2 : generateId()
|
1194
|
+
}
|
1195
|
+
];
|
1208
1196
|
});
|
1209
|
-
|
1210
|
-
throw new Error("The response body is empty.");
|
1211
|
-
}
|
1197
|
+
setInput("");
|
1212
1198
|
try {
|
1199
|
+
const result = await fetch(api, {
|
1200
|
+
method: "POST",
|
1201
|
+
credentials,
|
1202
|
+
headers: { "Content-Type": "application/json", ...headers },
|
1203
|
+
body: JSON.stringify({
|
1204
|
+
...body,
|
1205
|
+
// always use user-provided threadId when available:
|
1206
|
+
threadId: (_a = threadIdParam != null ? threadIdParam : threadId) != null ? _a : null,
|
1207
|
+
message: message.content,
|
1208
|
+
// optional request data:
|
1209
|
+
data: requestOptions == null ? void 0 : requestOptions.data
|
1210
|
+
})
|
1211
|
+
});
|
1212
|
+
if (result.body == null) {
|
1213
|
+
throw new Error("The response body is empty.");
|
1214
|
+
}
|
1213
1215
|
for await (const { type, value } of readDataStream(
|
1214
1216
|
result.body.getReader()
|
1215
1217
|
)) {
|
@@ -1245,7 +1247,7 @@ function experimental_useAssistant({
|
|
1245
1247
|
return [
|
1246
1248
|
...messages2,
|
1247
1249
|
{
|
1248
|
-
id: (_a2 = value.id) != null ? _a2 : (
|
1250
|
+
id: (_a2 = value.id) != null ? _a2 : generateId(),
|
1249
1251
|
role: "data",
|
1250
1252
|
content: "",
|
1251
1253
|
data: value.data
|
@@ -1278,7 +1280,16 @@ function experimental_useAssistant({
|
|
1278
1280
|
}
|
1279
1281
|
setStatus("awaiting_message");
|
1280
1282
|
};
|
1283
|
+
const submitMessage = async (event, requestOptions) => {
|
1284
|
+
var _a;
|
1285
|
+
(_a = event == null ? void 0 : event.preventDefault) == null ? void 0 : _a.call(event);
|
1286
|
+
if (input === "") {
|
1287
|
+
return;
|
1288
|
+
}
|
1289
|
+
append({ role: "user", content: input }, requestOptions);
|
1290
|
+
};
|
1281
1291
|
return {
|
1292
|
+
append,
|
1282
1293
|
messages,
|
1283
1294
|
setMessages,
|
1284
1295
|
threadId,
|
@@ -1290,9 +1301,11 @@ function experimental_useAssistant({
|
|
1290
1301
|
error
|
1291
1302
|
};
|
1292
1303
|
}
|
1304
|
+
var experimental_useAssistant = useAssistant;
|
1293
1305
|
// Annotate the CommonJS export names for ESM import in node:
|
1294
1306
|
0 && (module.exports = {
|
1295
1307
|
experimental_useAssistant,
|
1308
|
+
useAssistant,
|
1296
1309
|
useChat,
|
1297
1310
|
useCompletion
|
1298
1311
|
});
|