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/vue/dist/index.js
CHANGED
@@ -139,9 +139,9 @@ var toolCallStreamPart = {
|
|
139
139
|
code: "7",
|
140
140
|
name: "tool_calls",
|
141
141
|
parse: (value) => {
|
142
|
-
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(
|
143
|
-
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"
|
144
|
-
|
142
|
+
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(
|
143
|
+
(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"
|
144
|
+
)) {
|
145
145
|
throw new Error(
|
146
146
|
'"tool_calls" parts expect an object with a ToolCallPayload.'
|
147
147
|
);
|
@@ -254,27 +254,12 @@ async function* readDataStream(reader, {
|
|
254
254
|
}
|
255
255
|
}
|
256
256
|
|
257
|
-
// shared/
|
257
|
+
// shared/generate-id.ts
|
258
258
|
var import_non_secure = require("nanoid/non-secure");
|
259
|
-
var
|
259
|
+
var generateId = (0, import_non_secure.customAlphabet)(
|
260
260
|
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
261
261
|
7
|
262
262
|
);
|
263
|
-
function createChunkDecoder(complex) {
|
264
|
-
const decoder = new TextDecoder();
|
265
|
-
if (!complex) {
|
266
|
-
return function(chunk) {
|
267
|
-
if (!chunk)
|
268
|
-
return "";
|
269
|
-
return decoder.decode(chunk, { stream: true });
|
270
|
-
};
|
271
|
-
}
|
272
|
-
return function(chunk) {
|
273
|
-
const decoded = decoder.decode(chunk, { stream: true }).split("\n").filter((line) => line !== "");
|
274
|
-
return decoded.map(parseStreamPart).filter(Boolean);
|
275
|
-
};
|
276
|
-
}
|
277
|
-
var COMPLEX_HEADER = "X-Experimental-Stream-Data";
|
278
263
|
|
279
264
|
// shared/parse-complex-response.ts
|
280
265
|
function assignAnnotationsToMessage(message, annotations) {
|
@@ -287,7 +272,7 @@ async function parseComplexResponse({
|
|
287
272
|
abortControllerRef,
|
288
273
|
update,
|
289
274
|
onFinish,
|
290
|
-
generateId =
|
275
|
+
generateId: generateId2 = generateId,
|
291
276
|
getCurrentDate = () => /* @__PURE__ */ new Date()
|
292
277
|
}) {
|
293
278
|
const createdAt = getCurrentDate();
|
@@ -306,7 +291,7 @@ async function parseComplexResponse({
|
|
306
291
|
};
|
307
292
|
} else {
|
308
293
|
prefixMap["text"] = {
|
309
|
-
id:
|
294
|
+
id: generateId2(),
|
310
295
|
role: "assistant",
|
311
296
|
content: value,
|
312
297
|
createdAt
|
@@ -316,7 +301,7 @@ async function parseComplexResponse({
|
|
316
301
|
let functionCallMessage = null;
|
317
302
|
if (type === "function_call") {
|
318
303
|
prefixMap["function_call"] = {
|
319
|
-
id:
|
304
|
+
id: generateId2(),
|
320
305
|
role: "assistant",
|
321
306
|
content: "",
|
322
307
|
function_call: value.function_call,
|
@@ -328,7 +313,7 @@ async function parseComplexResponse({
|
|
328
313
|
let toolCallMessage = null;
|
329
314
|
if (type === "tool_calls") {
|
330
315
|
prefixMap["tool_calls"] = {
|
331
|
-
id:
|
316
|
+
id: generateId2(),
|
332
317
|
role: "assistant",
|
333
318
|
content: "",
|
334
319
|
tool_calls: value.tool_calls,
|
@@ -387,20 +372,36 @@ async function parseComplexResponse({
|
|
387
372
|
};
|
388
373
|
}
|
389
374
|
|
375
|
+
// shared/utils.ts
|
376
|
+
function createChunkDecoder(complex) {
|
377
|
+
const decoder = new TextDecoder();
|
378
|
+
if (!complex) {
|
379
|
+
return function(chunk) {
|
380
|
+
if (!chunk)
|
381
|
+
return "";
|
382
|
+
return decoder.decode(chunk, { stream: true });
|
383
|
+
};
|
384
|
+
}
|
385
|
+
return function(chunk) {
|
386
|
+
const decoded = decoder.decode(chunk, { stream: true }).split("\n").filter((line) => line !== "");
|
387
|
+
return decoded.map(parseStreamPart).filter(Boolean);
|
388
|
+
};
|
389
|
+
}
|
390
|
+
|
390
391
|
// shared/call-chat-api.ts
|
391
392
|
async function callChatApi({
|
392
393
|
api,
|
393
394
|
messages,
|
394
395
|
body,
|
396
|
+
streamMode = "stream-data",
|
395
397
|
credentials,
|
396
398
|
headers,
|
397
399
|
abortController,
|
398
|
-
appendMessage,
|
399
400
|
restoreMessagesOnFailure,
|
400
401
|
onResponse,
|
401
402
|
onUpdate,
|
402
403
|
onFinish,
|
403
|
-
generateId
|
404
|
+
generateId: generateId2
|
404
405
|
}) {
|
405
406
|
var _a;
|
406
407
|
const response = await fetch(api, {
|
@@ -436,63 +437,51 @@ async function callChatApi({
|
|
436
437
|
throw new Error("The response body is empty.");
|
437
438
|
}
|
438
439
|
const reader = response.body.getReader();
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
440
|
+
switch (streamMode) {
|
441
|
+
case "text": {
|
442
|
+
const decoder = createChunkDecoder();
|
443
|
+
const resultMessage = {
|
444
|
+
id: generateId2(),
|
445
|
+
createdAt: /* @__PURE__ */ new Date(),
|
446
|
+
role: "assistant",
|
447
|
+
content: ""
|
448
|
+
};
|
449
|
+
while (true) {
|
450
|
+
const { done, value } = await reader.read();
|
451
|
+
if (done) {
|
452
|
+
break;
|
453
|
+
}
|
454
|
+
resultMessage.content += decoder(value);
|
455
|
+
resultMessage.id = generateId2();
|
456
|
+
onUpdate([{ ...resultMessage }], []);
|
457
|
+
if ((abortController == null ? void 0 : abortController()) === null) {
|
458
|
+
reader.cancel();
|
459
|
+
break;
|
448
460
|
}
|
449
|
-
},
|
450
|
-
generateId
|
451
|
-
});
|
452
|
-
} else {
|
453
|
-
const createdAt = /* @__PURE__ */ new Date();
|
454
|
-
const decode = createChunkDecoder(false);
|
455
|
-
let streamedResponse = "";
|
456
|
-
const replyId = generateId();
|
457
|
-
let responseMessage = {
|
458
|
-
id: replyId,
|
459
|
-
createdAt,
|
460
|
-
content: "",
|
461
|
-
role: "assistant"
|
462
|
-
};
|
463
|
-
while (true) {
|
464
|
-
const { done, value } = await reader.read();
|
465
|
-
if (done) {
|
466
|
-
break;
|
467
|
-
}
|
468
|
-
streamedResponse += decode(value);
|
469
|
-
if (streamedResponse.startsWith('{"function_call":')) {
|
470
|
-
responseMessage["function_call"] = streamedResponse;
|
471
|
-
} else if (streamedResponse.startsWith('{"tool_calls":')) {
|
472
|
-
responseMessage["tool_calls"] = streamedResponse;
|
473
|
-
} else {
|
474
|
-
responseMessage["content"] = streamedResponse;
|
475
|
-
}
|
476
|
-
appendMessage({ ...responseMessage });
|
477
|
-
if ((abortController == null ? void 0 : abortController()) === null) {
|
478
|
-
reader.cancel();
|
479
|
-
break;
|
480
461
|
}
|
462
|
+
onFinish == null ? void 0 : onFinish(resultMessage);
|
463
|
+
return {
|
464
|
+
messages: [resultMessage],
|
465
|
+
data: []
|
466
|
+
};
|
481
467
|
}
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
468
|
+
case "stream-data": {
|
469
|
+
return await parseComplexResponse({
|
470
|
+
reader,
|
471
|
+
abortControllerRef: abortController != null ? { current: abortController() } : void 0,
|
472
|
+
update: onUpdate,
|
473
|
+
onFinish(prefixMap) {
|
474
|
+
if (onFinish && prefixMap.text != null) {
|
475
|
+
onFinish(prefixMap.text);
|
476
|
+
}
|
477
|
+
},
|
478
|
+
generateId: generateId2
|
479
|
+
});
|
491
480
|
}
|
492
|
-
|
493
|
-
|
481
|
+
default: {
|
482
|
+
const exhaustiveCheck = streamMode;
|
483
|
+
throw new Error(`Unknown stream mode: ${exhaustiveCheck}`);
|
494
484
|
}
|
495
|
-
return responseMessage;
|
496
485
|
}
|
497
486
|
}
|
498
487
|
|
@@ -623,13 +612,14 @@ function useChat({
|
|
623
612
|
initialInput = "",
|
624
613
|
sendExtraMessageFields,
|
625
614
|
experimental_onFunctionCall,
|
615
|
+
streamMode,
|
626
616
|
onResponse,
|
627
617
|
onFinish,
|
628
618
|
onError,
|
629
619
|
credentials,
|
630
620
|
headers,
|
631
621
|
body,
|
632
|
-
generateId =
|
622
|
+
generateId: generateId2 = generateId
|
633
623
|
} = {}) {
|
634
624
|
var _a, _b;
|
635
625
|
const chatId = id || `chat-${uniqueId++}`;
|
@@ -686,6 +676,7 @@ function useChat({
|
|
686
676
|
// Use unref to unwrap the ref value
|
687
677
|
...options == null ? void 0 : options.body
|
688
678
|
},
|
679
|
+
streamMode,
|
689
680
|
headers: {
|
690
681
|
...headers,
|
691
682
|
...options == null ? void 0 : options.headers
|
@@ -701,13 +692,10 @@ function useChat({
|
|
701
692
|
mutate([...chatRequest.messages, message]);
|
702
693
|
onFinish == null ? void 0 : onFinish(message);
|
703
694
|
},
|
704
|
-
appendMessage(message) {
|
705
|
-
mutate([...chatRequest.messages, message]);
|
706
|
-
},
|
707
695
|
restoreMessagesOnFailure() {
|
708
696
|
mutate(previousMessages);
|
709
697
|
},
|
710
|
-
generateId
|
698
|
+
generateId: generateId2
|
711
699
|
});
|
712
700
|
},
|
713
701
|
experimental_onFunctionCall,
|
@@ -732,7 +720,7 @@ function useChat({
|
|
732
720
|
}
|
733
721
|
const append = async (message, options) => {
|
734
722
|
if (!message.id) {
|
735
|
-
message.id =
|
723
|
+
message.id = generateId2();
|
736
724
|
}
|
737
725
|
return triggerRequest(messages.value.concat(message), options);
|
738
726
|
};
|
@@ -795,6 +783,7 @@ async function callCompletionApi({
|
|
795
783
|
credentials,
|
796
784
|
headers,
|
797
785
|
body,
|
786
|
+
streamMode = "stream-data",
|
798
787
|
setCompletion,
|
799
788
|
setLoading,
|
800
789
|
setError,
|
@@ -842,36 +831,44 @@ async function callCompletionApi({
|
|
842
831
|
}
|
843
832
|
let result = "";
|
844
833
|
const reader = res.body.getReader();
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
case "text": {
|
852
|
-
result += value;
|
853
|
-
setCompletion(result);
|
834
|
+
switch (streamMode) {
|
835
|
+
case "text": {
|
836
|
+
const decoder = createChunkDecoder();
|
837
|
+
while (true) {
|
838
|
+
const { done, value } = await reader.read();
|
839
|
+
if (done) {
|
854
840
|
break;
|
855
841
|
}
|
856
|
-
|
857
|
-
|
842
|
+
result += decoder(value);
|
843
|
+
setCompletion(result);
|
844
|
+
if (abortController === null) {
|
845
|
+
reader.cancel();
|
858
846
|
break;
|
859
847
|
}
|
860
848
|
}
|
849
|
+
break;
|
861
850
|
}
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
851
|
+
case "stream-data": {
|
852
|
+
for await (const { type, value } of readDataStream(reader, {
|
853
|
+
isAborted: () => abortController === null
|
854
|
+
})) {
|
855
|
+
switch (type) {
|
856
|
+
case "text": {
|
857
|
+
result += value;
|
858
|
+
setCompletion(result);
|
859
|
+
break;
|
860
|
+
}
|
861
|
+
case "data": {
|
862
|
+
onData == null ? void 0 : onData(value);
|
863
|
+
break;
|
864
|
+
}
|
865
|
+
}
|
874
866
|
}
|
867
|
+
break;
|
868
|
+
}
|
869
|
+
default: {
|
870
|
+
const exhaustiveCheck = streamMode;
|
871
|
+
throw new Error(`Unknown stream mode: ${exhaustiveCheck}`);
|
875
872
|
}
|
876
873
|
}
|
877
874
|
if (onFinish) {
|
@@ -907,6 +904,7 @@ function useCompletion({
|
|
907
904
|
credentials,
|
908
905
|
headers,
|
909
906
|
body,
|
907
|
+
streamMode,
|
910
908
|
onResponse,
|
911
909
|
onFinish,
|
912
910
|
onError
|
@@ -947,6 +945,7 @@ function useCompletion({
|
|
947
945
|
...(0, import_vue2.unref)(body),
|
948
946
|
...options == null ? void 0 : options.body
|
949
947
|
},
|
948
|
+
streamMode,
|
950
949
|
setCompletion: mutate,
|
951
950
|
setLoading: (loading) => mutateLoading(() => loading),
|
952
951
|
setError: (err) => {
|