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.mjs
CHANGED
@@ -104,9 +104,9 @@ var toolCallStreamPart = {
|
|
104
104
|
code: "7",
|
105
105
|
name: "tool_calls",
|
106
106
|
parse: (value) => {
|
107
|
-
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(
|
108
|
-
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"
|
109
|
-
|
107
|
+
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(
|
108
|
+
(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"
|
109
|
+
)) {
|
110
110
|
throw new Error(
|
111
111
|
'"tool_calls" parts expect an object with a ToolCallPayload.'
|
112
112
|
);
|
@@ -219,27 +219,12 @@ async function* readDataStream(reader, {
|
|
219
219
|
}
|
220
220
|
}
|
221
221
|
|
222
|
-
// shared/
|
222
|
+
// shared/generate-id.ts
|
223
223
|
import { customAlphabet } from "nanoid/non-secure";
|
224
|
-
var
|
224
|
+
var generateId = customAlphabet(
|
225
225
|
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
226
226
|
7
|
227
227
|
);
|
228
|
-
function createChunkDecoder(complex) {
|
229
|
-
const decoder = new TextDecoder();
|
230
|
-
if (!complex) {
|
231
|
-
return function(chunk) {
|
232
|
-
if (!chunk)
|
233
|
-
return "";
|
234
|
-
return decoder.decode(chunk, { stream: true });
|
235
|
-
};
|
236
|
-
}
|
237
|
-
return function(chunk) {
|
238
|
-
const decoded = decoder.decode(chunk, { stream: true }).split("\n").filter((line) => line !== "");
|
239
|
-
return decoded.map(parseStreamPart).filter(Boolean);
|
240
|
-
};
|
241
|
-
}
|
242
|
-
var COMPLEX_HEADER = "X-Experimental-Stream-Data";
|
243
228
|
|
244
229
|
// shared/parse-complex-response.ts
|
245
230
|
function assignAnnotationsToMessage(message, annotations) {
|
@@ -252,7 +237,7 @@ async function parseComplexResponse({
|
|
252
237
|
abortControllerRef,
|
253
238
|
update,
|
254
239
|
onFinish,
|
255
|
-
generateId =
|
240
|
+
generateId: generateId2 = generateId,
|
256
241
|
getCurrentDate = () => /* @__PURE__ */ new Date()
|
257
242
|
}) {
|
258
243
|
const createdAt = getCurrentDate();
|
@@ -271,7 +256,7 @@ async function parseComplexResponse({
|
|
271
256
|
};
|
272
257
|
} else {
|
273
258
|
prefixMap["text"] = {
|
274
|
-
id:
|
259
|
+
id: generateId2(),
|
275
260
|
role: "assistant",
|
276
261
|
content: value,
|
277
262
|
createdAt
|
@@ -281,7 +266,7 @@ async function parseComplexResponse({
|
|
281
266
|
let functionCallMessage = null;
|
282
267
|
if (type === "function_call") {
|
283
268
|
prefixMap["function_call"] = {
|
284
|
-
id:
|
269
|
+
id: generateId2(),
|
285
270
|
role: "assistant",
|
286
271
|
content: "",
|
287
272
|
function_call: value.function_call,
|
@@ -293,7 +278,7 @@ async function parseComplexResponse({
|
|
293
278
|
let toolCallMessage = null;
|
294
279
|
if (type === "tool_calls") {
|
295
280
|
prefixMap["tool_calls"] = {
|
296
|
-
id:
|
281
|
+
id: generateId2(),
|
297
282
|
role: "assistant",
|
298
283
|
content: "",
|
299
284
|
tool_calls: value.tool_calls,
|
@@ -352,20 +337,36 @@ async function parseComplexResponse({
|
|
352
337
|
};
|
353
338
|
}
|
354
339
|
|
340
|
+
// shared/utils.ts
|
341
|
+
function createChunkDecoder(complex) {
|
342
|
+
const decoder = new TextDecoder();
|
343
|
+
if (!complex) {
|
344
|
+
return function(chunk) {
|
345
|
+
if (!chunk)
|
346
|
+
return "";
|
347
|
+
return decoder.decode(chunk, { stream: true });
|
348
|
+
};
|
349
|
+
}
|
350
|
+
return function(chunk) {
|
351
|
+
const decoded = decoder.decode(chunk, { stream: true }).split("\n").filter((line) => line !== "");
|
352
|
+
return decoded.map(parseStreamPart).filter(Boolean);
|
353
|
+
};
|
354
|
+
}
|
355
|
+
|
355
356
|
// shared/call-chat-api.ts
|
356
357
|
async function callChatApi({
|
357
358
|
api,
|
358
359
|
messages,
|
359
360
|
body,
|
361
|
+
streamMode = "stream-data",
|
360
362
|
credentials,
|
361
363
|
headers,
|
362
364
|
abortController,
|
363
|
-
appendMessage,
|
364
365
|
restoreMessagesOnFailure,
|
365
366
|
onResponse,
|
366
367
|
onUpdate,
|
367
368
|
onFinish,
|
368
|
-
generateId
|
369
|
+
generateId: generateId2
|
369
370
|
}) {
|
370
371
|
var _a;
|
371
372
|
const response = await fetch(api, {
|
@@ -401,63 +402,51 @@ async function callChatApi({
|
|
401
402
|
throw new Error("The response body is empty.");
|
402
403
|
}
|
403
404
|
const reader = response.body.getReader();
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
405
|
+
switch (streamMode) {
|
406
|
+
case "text": {
|
407
|
+
const decoder = createChunkDecoder();
|
408
|
+
const resultMessage = {
|
409
|
+
id: generateId2(),
|
410
|
+
createdAt: /* @__PURE__ */ new Date(),
|
411
|
+
role: "assistant",
|
412
|
+
content: ""
|
413
|
+
};
|
414
|
+
while (true) {
|
415
|
+
const { done, value } = await reader.read();
|
416
|
+
if (done) {
|
417
|
+
break;
|
418
|
+
}
|
419
|
+
resultMessage.content += decoder(value);
|
420
|
+
resultMessage.id = generateId2();
|
421
|
+
onUpdate([{ ...resultMessage }], []);
|
422
|
+
if ((abortController == null ? void 0 : abortController()) === null) {
|
423
|
+
reader.cancel();
|
424
|
+
break;
|
413
425
|
}
|
414
|
-
},
|
415
|
-
generateId
|
416
|
-
});
|
417
|
-
} else {
|
418
|
-
const createdAt = /* @__PURE__ */ new Date();
|
419
|
-
const decode = createChunkDecoder(false);
|
420
|
-
let streamedResponse = "";
|
421
|
-
const replyId = generateId();
|
422
|
-
let responseMessage = {
|
423
|
-
id: replyId,
|
424
|
-
createdAt,
|
425
|
-
content: "",
|
426
|
-
role: "assistant"
|
427
|
-
};
|
428
|
-
while (true) {
|
429
|
-
const { done, value } = await reader.read();
|
430
|
-
if (done) {
|
431
|
-
break;
|
432
|
-
}
|
433
|
-
streamedResponse += decode(value);
|
434
|
-
if (streamedResponse.startsWith('{"function_call":')) {
|
435
|
-
responseMessage["function_call"] = streamedResponse;
|
436
|
-
} else if (streamedResponse.startsWith('{"tool_calls":')) {
|
437
|
-
responseMessage["tool_calls"] = streamedResponse;
|
438
|
-
} else {
|
439
|
-
responseMessage["content"] = streamedResponse;
|
440
|
-
}
|
441
|
-
appendMessage({ ...responseMessage });
|
442
|
-
if ((abortController == null ? void 0 : abortController()) === null) {
|
443
|
-
reader.cancel();
|
444
|
-
break;
|
445
426
|
}
|
427
|
+
onFinish == null ? void 0 : onFinish(resultMessage);
|
428
|
+
return {
|
429
|
+
messages: [resultMessage],
|
430
|
+
data: []
|
431
|
+
};
|
446
432
|
}
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
433
|
+
case "stream-data": {
|
434
|
+
return await parseComplexResponse({
|
435
|
+
reader,
|
436
|
+
abortControllerRef: abortController != null ? { current: abortController() } : void 0,
|
437
|
+
update: onUpdate,
|
438
|
+
onFinish(prefixMap) {
|
439
|
+
if (onFinish && prefixMap.text != null) {
|
440
|
+
onFinish(prefixMap.text);
|
441
|
+
}
|
442
|
+
},
|
443
|
+
generateId: generateId2
|
444
|
+
});
|
456
445
|
}
|
457
|
-
|
458
|
-
|
446
|
+
default: {
|
447
|
+
const exhaustiveCheck = streamMode;
|
448
|
+
throw new Error(`Unknown stream mode: ${exhaustiveCheck}`);
|
459
449
|
}
|
460
|
-
return responseMessage;
|
461
450
|
}
|
462
451
|
}
|
463
452
|
|
@@ -578,7 +567,7 @@ async function processChatStream({
|
|
578
567
|
}
|
579
568
|
|
580
569
|
// react/use-chat.ts
|
581
|
-
var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, existingData, extraMetadataRef, messagesRef, abortControllerRef,
|
570
|
+
var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, existingData, extraMetadataRef, messagesRef, abortControllerRef, generateId2, streamMode, onFinish, onResponse, sendExtraMessageFields) => {
|
582
571
|
var _a, _b;
|
583
572
|
const previousMessages = messagesRef.current;
|
584
573
|
mutate(chatRequest.messages, false);
|
@@ -597,7 +586,7 @@ var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, exi
|
|
597
586
|
})
|
598
587
|
);
|
599
588
|
if (typeof api !== "string") {
|
600
|
-
const replyId =
|
589
|
+
const replyId = generateId2();
|
601
590
|
const createdAt = /* @__PURE__ */ new Date();
|
602
591
|
let responseMessage = {
|
603
592
|
id: replyId,
|
@@ -649,15 +638,13 @@ var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, exi
|
|
649
638
|
tool_choice: chatRequest.tool_choice
|
650
639
|
}
|
651
640
|
},
|
641
|
+
streamMode,
|
652
642
|
credentials: extraMetadataRef.current.credentials,
|
653
643
|
headers: {
|
654
644
|
...extraMetadataRef.current.headers,
|
655
645
|
...(_b = chatRequest.options) == null ? void 0 : _b.headers
|
656
646
|
},
|
657
647
|
abortController: () => abortControllerRef.current,
|
658
|
-
appendMessage(message) {
|
659
|
-
mutate([...chatRequest.messages, message], false);
|
660
|
-
},
|
661
648
|
restoreMessagesOnFailure() {
|
662
649
|
mutate(previousMessages, false);
|
663
650
|
},
|
@@ -667,7 +654,7 @@ var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, exi
|
|
667
654
|
mutateStreamData([...existingData || [], ...data || []], false);
|
668
655
|
},
|
669
656
|
onFinish,
|
670
|
-
generateId
|
657
|
+
generateId: generateId2
|
671
658
|
});
|
672
659
|
};
|
673
660
|
function useChat({
|
@@ -678,13 +665,14 @@ function useChat({
|
|
678
665
|
sendExtraMessageFields,
|
679
666
|
experimental_onFunctionCall,
|
680
667
|
experimental_onToolCall,
|
668
|
+
streamMode,
|
681
669
|
onResponse,
|
682
670
|
onFinish,
|
683
671
|
onError,
|
684
672
|
credentials,
|
685
673
|
headers,
|
686
674
|
body,
|
687
|
-
generateId =
|
675
|
+
generateId: generateId2 = generateId
|
688
676
|
} = {}) {
|
689
677
|
const hookId = useId();
|
690
678
|
const idKey = id != null ? id : hookId;
|
@@ -735,7 +723,8 @@ function useChat({
|
|
735
723
|
extraMetadataRef,
|
736
724
|
messagesRef,
|
737
725
|
abortControllerRef,
|
738
|
-
|
726
|
+
generateId2,
|
727
|
+
streamMode,
|
739
728
|
onFinish,
|
740
729
|
onResponse,
|
741
730
|
sendExtraMessageFields
|
@@ -777,7 +766,7 @@ function useChat({
|
|
777
766
|
experimental_onToolCall,
|
778
767
|
messagesRef,
|
779
768
|
abortControllerRef,
|
780
|
-
|
769
|
+
generateId2
|
781
770
|
]
|
782
771
|
);
|
783
772
|
const append = useCallback(
|
@@ -790,7 +779,7 @@ function useChat({
|
|
790
779
|
data
|
791
780
|
} = {}) => {
|
792
781
|
if (!message.id) {
|
793
|
-
message.id =
|
782
|
+
message.id = generateId2();
|
794
783
|
}
|
795
784
|
const chatRequest = {
|
796
785
|
messages: messagesRef.current.concat(message),
|
@@ -803,7 +792,7 @@ function useChat({
|
|
803
792
|
};
|
804
793
|
return triggerRequest(chatRequest);
|
805
794
|
},
|
806
|
-
[triggerRequest,
|
795
|
+
[triggerRequest, generateId2]
|
807
796
|
);
|
808
797
|
const reload = useCallback(
|
809
798
|
async ({
|
@@ -906,6 +895,7 @@ async function callCompletionApi({
|
|
906
895
|
credentials,
|
907
896
|
headers,
|
908
897
|
body,
|
898
|
+
streamMode = "stream-data",
|
909
899
|
setCompletion,
|
910
900
|
setLoading,
|
911
901
|
setError,
|
@@ -953,36 +943,44 @@ async function callCompletionApi({
|
|
953
943
|
}
|
954
944
|
let result = "";
|
955
945
|
const reader = res.body.getReader();
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
case "text": {
|
963
|
-
result += value;
|
964
|
-
setCompletion(result);
|
946
|
+
switch (streamMode) {
|
947
|
+
case "text": {
|
948
|
+
const decoder = createChunkDecoder();
|
949
|
+
while (true) {
|
950
|
+
const { done, value } = await reader.read();
|
951
|
+
if (done) {
|
965
952
|
break;
|
966
953
|
}
|
967
|
-
|
968
|
-
|
954
|
+
result += decoder(value);
|
955
|
+
setCompletion(result);
|
956
|
+
if (abortController === null) {
|
957
|
+
reader.cancel();
|
969
958
|
break;
|
970
959
|
}
|
971
960
|
}
|
961
|
+
break;
|
972
962
|
}
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
963
|
+
case "stream-data": {
|
964
|
+
for await (const { type, value } of readDataStream(reader, {
|
965
|
+
isAborted: () => abortController === null
|
966
|
+
})) {
|
967
|
+
switch (type) {
|
968
|
+
case "text": {
|
969
|
+
result += value;
|
970
|
+
setCompletion(result);
|
971
|
+
break;
|
972
|
+
}
|
973
|
+
case "data": {
|
974
|
+
onData == null ? void 0 : onData(value);
|
975
|
+
break;
|
976
|
+
}
|
977
|
+
}
|
985
978
|
}
|
979
|
+
break;
|
980
|
+
}
|
981
|
+
default: {
|
982
|
+
const exhaustiveCheck = streamMode;
|
983
|
+
throw new Error(`Unknown stream mode: ${exhaustiveCheck}`);
|
986
984
|
}
|
987
985
|
}
|
988
986
|
if (onFinish) {
|
@@ -1015,6 +1013,7 @@ function useCompletion({
|
|
1015
1013
|
credentials,
|
1016
1014
|
headers,
|
1017
1015
|
body,
|
1016
|
+
streamMode,
|
1018
1017
|
onResponse,
|
1019
1018
|
onFinish,
|
1020
1019
|
onError
|
@@ -1054,6 +1053,7 @@ function useCompletion({
|
|
1054
1053
|
...extraMetadataRef.current.body,
|
1055
1054
|
...options == null ? void 0 : options.body
|
1056
1055
|
},
|
1056
|
+
streamMode,
|
1057
1057
|
setCompletion: (completion2) => mutate(completion2, false),
|
1058
1058
|
setLoading: mutateLoading,
|
1059
1059
|
setError,
|
@@ -1126,9 +1126,8 @@ function useCompletion({
|
|
1126
1126
|
}
|
1127
1127
|
|
1128
1128
|
// react/use-assistant.ts
|
1129
|
-
import { nanoid as nanoid2 } from "nanoid";
|
1130
1129
|
import { useState as useState3 } from "react";
|
1131
|
-
function
|
1130
|
+
function useAssistant({
|
1132
1131
|
api,
|
1133
1132
|
threadId: threadIdParam,
|
1134
1133
|
credentials,
|
@@ -1144,35 +1143,37 @@ function experimental_useAssistant({
|
|
1144
1143
|
const handleInputChange = (event) => {
|
1145
1144
|
setInput(event.target.value);
|
1146
1145
|
};
|
1147
|
-
const
|
1148
|
-
var _a
|
1149
|
-
(_a = event == null ? void 0 : event.preventDefault) == null ? void 0 : _a.call(event);
|
1150
|
-
if (input === "") {
|
1151
|
-
return;
|
1152
|
-
}
|
1146
|
+
const append = async (message, requestOptions) => {
|
1147
|
+
var _a;
|
1153
1148
|
setStatus("in_progress");
|
1154
|
-
setMessages((messages2) =>
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
body: JSON.stringify({
|
1164
|
-
...body,
|
1165
|
-
// always use user-provided threadId when available:
|
1166
|
-
threadId: (_b = threadIdParam != null ? threadIdParam : threadId) != null ? _b : null,
|
1167
|
-
message: input,
|
1168
|
-
// optional request data:
|
1169
|
-
data: requestOptions == null ? void 0 : requestOptions.data
|
1170
|
-
})
|
1149
|
+
setMessages((messages2) => {
|
1150
|
+
var _a2;
|
1151
|
+
return [
|
1152
|
+
...messages2,
|
1153
|
+
{
|
1154
|
+
...message,
|
1155
|
+
id: (_a2 = message.id) != null ? _a2 : generateId()
|
1156
|
+
}
|
1157
|
+
];
|
1171
1158
|
});
|
1172
|
-
|
1173
|
-
throw new Error("The response body is empty.");
|
1174
|
-
}
|
1159
|
+
setInput("");
|
1175
1160
|
try {
|
1161
|
+
const result = await fetch(api, {
|
1162
|
+
method: "POST",
|
1163
|
+
credentials,
|
1164
|
+
headers: { "Content-Type": "application/json", ...headers },
|
1165
|
+
body: JSON.stringify({
|
1166
|
+
...body,
|
1167
|
+
// always use user-provided threadId when available:
|
1168
|
+
threadId: (_a = threadIdParam != null ? threadIdParam : threadId) != null ? _a : null,
|
1169
|
+
message: message.content,
|
1170
|
+
// optional request data:
|
1171
|
+
data: requestOptions == null ? void 0 : requestOptions.data
|
1172
|
+
})
|
1173
|
+
});
|
1174
|
+
if (result.body == null) {
|
1175
|
+
throw new Error("The response body is empty.");
|
1176
|
+
}
|
1176
1177
|
for await (const { type, value } of readDataStream(
|
1177
1178
|
result.body.getReader()
|
1178
1179
|
)) {
|
@@ -1208,7 +1209,7 @@ function experimental_useAssistant({
|
|
1208
1209
|
return [
|
1209
1210
|
...messages2,
|
1210
1211
|
{
|
1211
|
-
id: (_a2 = value.id) != null ? _a2 :
|
1212
|
+
id: (_a2 = value.id) != null ? _a2 : generateId(),
|
1212
1213
|
role: "data",
|
1213
1214
|
content: "",
|
1214
1215
|
data: value.data
|
@@ -1241,7 +1242,16 @@ function experimental_useAssistant({
|
|
1241
1242
|
}
|
1242
1243
|
setStatus("awaiting_message");
|
1243
1244
|
};
|
1245
|
+
const submitMessage = async (event, requestOptions) => {
|
1246
|
+
var _a;
|
1247
|
+
(_a = event == null ? void 0 : event.preventDefault) == null ? void 0 : _a.call(event);
|
1248
|
+
if (input === "") {
|
1249
|
+
return;
|
1250
|
+
}
|
1251
|
+
append({ role: "user", content: input }, requestOptions);
|
1252
|
+
};
|
1244
1253
|
return {
|
1254
|
+
append,
|
1245
1255
|
messages,
|
1246
1256
|
setMessages,
|
1247
1257
|
threadId,
|
@@ -1253,8 +1263,10 @@ function experimental_useAssistant({
|
|
1253
1263
|
error
|
1254
1264
|
};
|
1255
1265
|
}
|
1266
|
+
var experimental_useAssistant = useAssistant;
|
1256
1267
|
export {
|
1257
1268
|
experimental_useAssistant,
|
1269
|
+
useAssistant,
|
1258
1270
|
useChat,
|
1259
1271
|
useCompletion
|
1260
1272
|
};
|