ai 3.0.12 → 3.0.14
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/README.md +1 -1
- package/ai-model-specification/dist/index.d.mts +704 -0
- package/ai-model-specification/dist/index.d.ts +704 -0
- package/ai-model-specification/dist/index.js +806 -0
- package/ai-model-specification/dist/index.js.map +1 -0
- package/ai-model-specification/dist/index.mjs +742 -0
- package/ai-model-specification/dist/index.mjs.map +1 -0
- package/dist/index.d.mts +686 -4
- package/dist/index.d.ts +686 -4
- package/dist/index.js +1723 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1700 -15
- package/dist/index.mjs.map +1 -1
- package/mistral/dist/index.d.mts +367 -0
- package/mistral/dist/index.d.ts +367 -0
- package/mistral/dist/index.js +936 -0
- package/mistral/dist/index.js.map +1 -0
- package/mistral/dist/index.mjs +900 -0
- package/mistral/dist/index.mjs.map +1 -0
- package/openai/dist/index.d.mts +430 -0
- package/openai/dist/index.d.ts +430 -0
- package/openai/dist/index.js +1355 -0
- package/openai/dist/index.js.map +1 -0
- package/openai/dist/index.mjs +1319 -0
- package/openai/dist/index.mjs.map +1 -0
- package/package.json +33 -7
- 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 +8 -4
- package/react/dist/index.d.ts +8 -4
- package/react/dist/index.js +36 -34
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +36 -34
- package/react/dist/index.mjs.map +1 -1
- package/rsc/dist/index.d.ts +45 -8
- package/rsc/dist/rsc-server.d.mts +45 -8
- package/rsc/dist/rsc-server.mjs +67 -13
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/rsc/dist/rsc-shared.d.mts +5 -8
- package/rsc/dist/rsc-shared.mjs +23 -2
- package/rsc/dist/rsc-shared.mjs.map +1 -1
- package/solid/dist/index.js +29 -27
- package/solid/dist/index.js.map +1 -1
- package/solid/dist/index.mjs +29 -27
- package/solid/dist/index.mjs.map +1 -1
- package/svelte/dist/index.js +31 -29
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs +31 -29
- package/svelte/dist/index.mjs.map +1 -1
- package/vue/dist/index.js +29 -27
- package/vue/dist/index.js.map +1 -1
- package/vue/dist/index.mjs +29 -27
- package/vue/dist/index.mjs.map +1 -1
package/react/dist/index.d.ts
CHANGED
@@ -299,7 +299,7 @@ declare class experimental_StreamingReactResponse {
|
|
299
299
|
constructor(res: ReadableStream, options?: {
|
300
300
|
ui?: (message: {
|
301
301
|
content: string;
|
302
|
-
data?: JSONValue[]
|
302
|
+
data?: JSONValue[];
|
303
303
|
}) => UINode | Promise<UINode>;
|
304
304
|
data?: experimental_StreamData;
|
305
305
|
generateId?: IdGenerator;
|
@@ -346,7 +346,7 @@ type UseChatHelpers = {
|
|
346
346
|
/** Whether the API request is in progress */
|
347
347
|
isLoading: boolean;
|
348
348
|
/** Additional data added on the server via StreamData */
|
349
|
-
data?: JSONValue[]
|
349
|
+
data?: JSONValue[];
|
350
350
|
};
|
351
351
|
type StreamingReactResponseAction = (payload: {
|
352
352
|
messages: Message[];
|
@@ -399,7 +399,7 @@ type UseCompletionHelpers = {
|
|
399
399
|
/** Whether the API request is in progress */
|
400
400
|
isLoading: boolean;
|
401
401
|
/** Additional data added on the server via StreamData */
|
402
|
-
data?: JSONValue[]
|
402
|
+
data?: JSONValue[];
|
403
403
|
};
|
404
404
|
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, onResponse, onFinish, onError, }?: UseCompletionOptions): UseCompletionHelpers;
|
405
405
|
|
@@ -409,6 +409,10 @@ type UseAssistantHelpers = {
|
|
409
409
|
* The current array of chat messages.
|
410
410
|
*/
|
411
411
|
messages: Message[];
|
412
|
+
/**
|
413
|
+
* setState-powered method to update the messages array.
|
414
|
+
*/
|
415
|
+
setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
|
412
416
|
/**
|
413
417
|
* The current thread ID.
|
414
418
|
*/
|
@@ -451,7 +455,7 @@ type UseAssistantOptions = {
|
|
451
455
|
* An optional string that represents the ID of an existing thread.
|
452
456
|
* If not provided, a new thread will be created.
|
453
457
|
*/
|
454
|
-
threadId?: string
|
458
|
+
threadId?: string;
|
455
459
|
/**
|
456
460
|
* An optional literal that sets the mode of credentials to be used on the request.
|
457
461
|
* Defaults to "same-origin".
|
package/react/dist/index.js
CHANGED
@@ -256,27 +256,12 @@ async function* readDataStream(reader, {
|
|
256
256
|
}
|
257
257
|
}
|
258
258
|
|
259
|
-
// shared/
|
259
|
+
// shared/generate-id.ts
|
260
260
|
var import_non_secure = require("nanoid/non-secure");
|
261
|
-
var
|
261
|
+
var generateId = (0, import_non_secure.customAlphabet)(
|
262
262
|
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
263
263
|
7
|
264
264
|
);
|
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
265
|
|
281
266
|
// shared/parse-complex-response.ts
|
282
267
|
function assignAnnotationsToMessage(message, annotations) {
|
@@ -289,7 +274,7 @@ async function parseComplexResponse({
|
|
289
274
|
abortControllerRef,
|
290
275
|
update,
|
291
276
|
onFinish,
|
292
|
-
generateId =
|
277
|
+
generateId: generateId2 = generateId,
|
293
278
|
getCurrentDate = () => /* @__PURE__ */ new Date()
|
294
279
|
}) {
|
295
280
|
const createdAt = getCurrentDate();
|
@@ -308,7 +293,7 @@ async function parseComplexResponse({
|
|
308
293
|
};
|
309
294
|
} else {
|
310
295
|
prefixMap["text"] = {
|
311
|
-
id:
|
296
|
+
id: generateId2(),
|
312
297
|
role: "assistant",
|
313
298
|
content: value,
|
314
299
|
createdAt
|
@@ -318,7 +303,7 @@ async function parseComplexResponse({
|
|
318
303
|
let functionCallMessage = null;
|
319
304
|
if (type === "function_call") {
|
320
305
|
prefixMap["function_call"] = {
|
321
|
-
id:
|
306
|
+
id: generateId2(),
|
322
307
|
role: "assistant",
|
323
308
|
content: "",
|
324
309
|
function_call: value.function_call,
|
@@ -330,7 +315,7 @@ async function parseComplexResponse({
|
|
330
315
|
let toolCallMessage = null;
|
331
316
|
if (type === "tool_calls") {
|
332
317
|
prefixMap["tool_calls"] = {
|
333
|
-
id:
|
318
|
+
id: generateId2(),
|
334
319
|
role: "assistant",
|
335
320
|
content: "",
|
336
321
|
tool_calls: value.tool_calls,
|
@@ -389,6 +374,23 @@ async function parseComplexResponse({
|
|
389
374
|
};
|
390
375
|
}
|
391
376
|
|
377
|
+
// shared/utils.ts
|
378
|
+
function createChunkDecoder(complex) {
|
379
|
+
const decoder = new TextDecoder();
|
380
|
+
if (!complex) {
|
381
|
+
return function(chunk) {
|
382
|
+
if (!chunk)
|
383
|
+
return "";
|
384
|
+
return decoder.decode(chunk, { stream: true });
|
385
|
+
};
|
386
|
+
}
|
387
|
+
return function(chunk) {
|
388
|
+
const decoded = decoder.decode(chunk, { stream: true }).split("\n").filter((line) => line !== "");
|
389
|
+
return decoded.map(parseStreamPart).filter(Boolean);
|
390
|
+
};
|
391
|
+
}
|
392
|
+
var COMPLEX_HEADER = "X-Experimental-Stream-Data";
|
393
|
+
|
392
394
|
// shared/call-chat-api.ts
|
393
395
|
async function callChatApi({
|
394
396
|
api,
|
@@ -402,7 +404,7 @@ async function callChatApi({
|
|
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, {
|
@@ -449,13 +451,13 @@ async function callChatApi({
|
|
449
451
|
onFinish(prefixMap.text);
|
450
452
|
}
|
451
453
|
},
|
452
|
-
generateId
|
454
|
+
generateId: generateId2
|
453
455
|
});
|
454
456
|
} else {
|
455
457
|
const createdAt = /* @__PURE__ */ new Date();
|
456
458
|
const decode = createChunkDecoder(false);
|
457
459
|
let streamedResponse = "";
|
458
|
-
const replyId =
|
460
|
+
const replyId = generateId2();
|
459
461
|
let responseMessage = {
|
460
462
|
id: replyId,
|
461
463
|
createdAt,
|
@@ -615,7 +617,7 @@ async function processChatStream({
|
|
615
617
|
}
|
616
618
|
|
617
619
|
// react/use-chat.ts
|
618
|
-
var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, existingData, extraMetadataRef, messagesRef, abortControllerRef,
|
620
|
+
var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, existingData, extraMetadataRef, messagesRef, abortControllerRef, generateId2, onFinish, onResponse, sendExtraMessageFields) => {
|
619
621
|
var _a, _b;
|
620
622
|
const previousMessages = messagesRef.current;
|
621
623
|
mutate(chatRequest.messages, false);
|
@@ -634,7 +636,7 @@ var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, exi
|
|
634
636
|
})
|
635
637
|
);
|
636
638
|
if (typeof api !== "string") {
|
637
|
-
const replyId =
|
639
|
+
const replyId = generateId2();
|
638
640
|
const createdAt = /* @__PURE__ */ new Date();
|
639
641
|
let responseMessage = {
|
640
642
|
id: replyId,
|
@@ -704,7 +706,7 @@ var getStreamedResponse = async (api, chatRequest, mutate, mutateStreamData, exi
|
|
704
706
|
mutateStreamData([...existingData || [], ...data || []], false);
|
705
707
|
},
|
706
708
|
onFinish,
|
707
|
-
generateId
|
709
|
+
generateId: generateId2
|
708
710
|
});
|
709
711
|
};
|
710
712
|
function useChat({
|
@@ -721,7 +723,7 @@ function useChat({
|
|
721
723
|
credentials,
|
722
724
|
headers,
|
723
725
|
body,
|
724
|
-
generateId =
|
726
|
+
generateId: generateId2 = generateId
|
725
727
|
} = {}) {
|
726
728
|
const hookId = (0, import_react.useId)();
|
727
729
|
const idKey = id != null ? id : hookId;
|
@@ -772,7 +774,7 @@ function useChat({
|
|
772
774
|
extraMetadataRef,
|
773
775
|
messagesRef,
|
774
776
|
abortControllerRef,
|
775
|
-
|
777
|
+
generateId2,
|
776
778
|
onFinish,
|
777
779
|
onResponse,
|
778
780
|
sendExtraMessageFields
|
@@ -814,7 +816,7 @@ function useChat({
|
|
814
816
|
experimental_onToolCall,
|
815
817
|
messagesRef,
|
816
818
|
abortControllerRef,
|
817
|
-
|
819
|
+
generateId2
|
818
820
|
]
|
819
821
|
);
|
820
822
|
const append = (0, import_react.useCallback)(
|
@@ -827,7 +829,7 @@ function useChat({
|
|
827
829
|
data
|
828
830
|
} = {}) => {
|
829
831
|
if (!message.id) {
|
830
|
-
message.id =
|
832
|
+
message.id = generateId2();
|
831
833
|
}
|
832
834
|
const chatRequest = {
|
833
835
|
messages: messagesRef.current.concat(message),
|
@@ -840,7 +842,7 @@ function useChat({
|
|
840
842
|
};
|
841
843
|
return triggerRequest(chatRequest);
|
842
844
|
},
|
843
|
-
[triggerRequest,
|
845
|
+
[triggerRequest, generateId2]
|
844
846
|
);
|
845
847
|
const reload = (0, import_react.useCallback)(
|
846
848
|
async ({
|
@@ -1164,7 +1166,6 @@ function useCompletion({
|
|
1164
1166
|
|
1165
1167
|
// react/use-assistant.ts
|
1166
1168
|
var import_react3 = require("react");
|
1167
|
-
var import_nanoid = require("nanoid");
|
1168
1169
|
function experimental_useAssistant({
|
1169
1170
|
api,
|
1170
1171
|
threadId: threadIdParam,
|
@@ -1245,7 +1246,7 @@ function experimental_useAssistant({
|
|
1245
1246
|
return [
|
1246
1247
|
...messages2,
|
1247
1248
|
{
|
1248
|
-
id: (_a2 = value.id) != null ? _a2 : (
|
1249
|
+
id: (_a2 = value.id) != null ? _a2 : generateId(),
|
1249
1250
|
role: "data",
|
1250
1251
|
content: "",
|
1251
1252
|
data: value.data
|
@@ -1280,6 +1281,7 @@ function experimental_useAssistant({
|
|
1280
1281
|
};
|
1281
1282
|
return {
|
1282
1283
|
messages,
|
1284
|
+
setMessages,
|
1283
1285
|
threadId,
|
1284
1286
|
input,
|
1285
1287
|
setInput,
|