ai 2.1.11 → 2.1.13
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/package.json +3 -2
- package/react/dist/index.d.ts +5 -2
- package/react/dist/index.js +2 -30
- package/react/dist/index.mjs +4 -31
- package/react/dist/index.server.d.ts +15 -0
- package/react/dist/index.server.js +73 -0
- package/react/dist/index.server.mjs +47 -0
- package/svelte/dist/index.js +2 -4
- package/svelte/dist/index.mjs +2 -4
- package/vue/dist/index.js +2 -4
- package/vue/dist/index.mjs +2 -4
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ai",
|
3
|
-
"version": "2.1.
|
3
|
+
"version": "2.1.13",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"sideEffects": false,
|
6
6
|
"main": "./dist/index.js",
|
@@ -22,6 +22,7 @@
|
|
22
22
|
},
|
23
23
|
"./react": {
|
24
24
|
"types": "./react/dist/index.d.ts",
|
25
|
+
"react-server": "./react/dist/index.server.mjs",
|
25
26
|
"import": "./react/dist/index.mjs",
|
26
27
|
"module": "./react/dist/index.mjs",
|
27
28
|
"require": "./react/dist/index.js"
|
@@ -88,7 +89,7 @@
|
|
88
89
|
"access": "public"
|
89
90
|
},
|
90
91
|
"scripts": {
|
91
|
-
"build": "tsup",
|
92
|
+
"build": "tsup && cat react/dist/index.server.d.ts >> react/dist/index.d.ts",
|
92
93
|
"clean": "rm -rf dist && rm -rf react/dist && rm -rf svelte/dist && rm -rf vue/dist",
|
93
94
|
"dev": "tsup --watch",
|
94
95
|
"lint": "eslint \"./**/*.ts*\"",
|
package/react/dist/index.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { ChatCompletionRequestMessageFunctionCall, CreateChatCompletionRequestFunctionCall } from 'openai-edge';
|
2
2
|
import { ChatCompletionFunctions } from 'openai-edge/types/api';
|
3
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
4
3
|
|
5
4
|
/**
|
6
5
|
* Shared types between the API and UI packages.
|
@@ -252,6 +251,9 @@ type UseCompletionHelpers = {
|
|
252
251
|
};
|
253
252
|
declare function useCompletion({ api, id, initialCompletion, initialInput, credentials, headers, body, onResponse, onFinish, onError }?: UseCompletionOptions): UseCompletionHelpers;
|
254
253
|
|
254
|
+
export { CreateMessage, Message, UseChatHelpers, UseChatOptions, UseCompletionHelpers, useChat, useCompletion };
|
255
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
256
|
+
|
255
257
|
type Props = {
|
256
258
|
/**
|
257
259
|
* A ReadableStream produced by the AI SDK.
|
@@ -260,7 +262,8 @@ type Props = {
|
|
260
262
|
};
|
261
263
|
/**
|
262
264
|
* A React Server Component that recursively renders a stream of tokens.
|
265
|
+
* Can only be used inside of server components.
|
263
266
|
*/
|
264
267
|
declare function Tokens(props: Props): Promise<react_jsx_runtime.JSX.Element>;
|
265
268
|
|
266
|
-
export {
|
269
|
+
export { Tokens };
|
package/react/dist/index.js
CHANGED
@@ -65,7 +65,6 @@ var __async = (__this, __arguments, generator) => {
|
|
65
65
|
// react/index.ts
|
66
66
|
var react_exports = {};
|
67
67
|
__export(react_exports, {
|
68
|
-
Tokens: () => Tokens,
|
69
68
|
useChat: () => useChat,
|
70
69
|
useCompletion: () => useCompletion
|
71
70
|
});
|
@@ -186,8 +185,7 @@ function useChat({
|
|
186
185
|
headers,
|
187
186
|
body
|
188
187
|
} = {}) {
|
189
|
-
const
|
190
|
-
const chatId = id || hookId;
|
188
|
+
const chatId = id || `chat-${nanoid()}`;
|
191
189
|
const { data, mutate } = (0, import_swr.default)([api, chatId], null, {
|
192
190
|
fallbackData: initialMessages
|
193
191
|
});
|
@@ -361,8 +359,7 @@ function useCompletion({
|
|
361
359
|
onFinish,
|
362
360
|
onError
|
363
361
|
} = {}) {
|
364
|
-
const
|
365
|
-
const completionId = id || hookId;
|
362
|
+
const completionId = id || `completion-${nanoid()}`;
|
366
363
|
const { data, mutate } = (0, import_swr2.default)([api, completionId], null, {
|
367
364
|
fallbackData: initialCompletion
|
368
365
|
});
|
@@ -497,33 +494,8 @@ function useCompletion({
|
|
497
494
|
isLoading: isMutating
|
498
495
|
};
|
499
496
|
}
|
500
|
-
|
501
|
-
// react/tokens.tsx
|
502
|
-
var import_react3 = require("react");
|
503
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
504
|
-
function Tokens(props) {
|
505
|
-
return __async(this, null, function* () {
|
506
|
-
const { stream } = props;
|
507
|
-
const reader = stream.getReader();
|
508
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react3.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecursiveTokens, { reader }) });
|
509
|
-
});
|
510
|
-
}
|
511
|
-
function RecursiveTokens(_0) {
|
512
|
-
return __async(this, arguments, function* ({ reader }) {
|
513
|
-
const { done, value } = yield reader.read();
|
514
|
-
if (done) {
|
515
|
-
return null;
|
516
|
-
}
|
517
|
-
const text = new TextDecoder().decode(value);
|
518
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
519
|
-
text,
|
520
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react3.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecursiveTokens, { reader }) })
|
521
|
-
] });
|
522
|
-
});
|
523
|
-
}
|
524
497
|
// Annotate the CommonJS export names for ESM import in node:
|
525
498
|
0 && (module.exports = {
|
526
|
-
Tokens,
|
527
499
|
useChat,
|
528
500
|
useCompletion
|
529
501
|
});
|
package/react/dist/index.mjs
CHANGED
@@ -37,7 +37,7 @@ var __async = (__this, __arguments, generator) => {
|
|
37
37
|
};
|
38
38
|
|
39
39
|
// react/use-chat.ts
|
40
|
-
import { useCallback, useEffect,
|
40
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
41
41
|
import useSWRMutation from "swr/mutation";
|
42
42
|
import useSWR from "swr";
|
43
43
|
|
@@ -151,8 +151,7 @@ function useChat({
|
|
151
151
|
headers,
|
152
152
|
body
|
153
153
|
} = {}) {
|
154
|
-
const
|
155
|
-
const chatId = id || hookId;
|
154
|
+
const chatId = id || `chat-${nanoid()}`;
|
156
155
|
const { data, mutate } = useSWR([api, chatId], null, {
|
157
156
|
fallbackData: initialMessages
|
158
157
|
});
|
@@ -311,7 +310,7 @@ function useChat({
|
|
311
310
|
}
|
312
311
|
|
313
312
|
// react/use-completion.ts
|
314
|
-
import { useCallback as useCallback2, useEffect as useEffect2,
|
313
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
315
314
|
import useSWRMutation2 from "swr/mutation";
|
316
315
|
import useSWR2 from "swr";
|
317
316
|
function useCompletion({
|
@@ -326,8 +325,7 @@ function useCompletion({
|
|
326
325
|
onFinish,
|
327
326
|
onError
|
328
327
|
} = {}) {
|
329
|
-
const
|
330
|
-
const completionId = id || hookId;
|
328
|
+
const completionId = id || `completion-${nanoid()}`;
|
331
329
|
const { data, mutate } = useSWR2([api, completionId], null, {
|
332
330
|
fallbackData: initialCompletion
|
333
331
|
});
|
@@ -462,32 +460,7 @@ function useCompletion({
|
|
462
460
|
isLoading: isMutating
|
463
461
|
};
|
464
462
|
}
|
465
|
-
|
466
|
-
// react/tokens.tsx
|
467
|
-
import { Suspense } from "react";
|
468
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
469
|
-
function Tokens(props) {
|
470
|
-
return __async(this, null, function* () {
|
471
|
-
const { stream } = props;
|
472
|
-
const reader = stream.getReader();
|
473
|
-
return /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(RecursiveTokens, { reader }) });
|
474
|
-
});
|
475
|
-
}
|
476
|
-
function RecursiveTokens(_0) {
|
477
|
-
return __async(this, arguments, function* ({ reader }) {
|
478
|
-
const { done, value } = yield reader.read();
|
479
|
-
if (done) {
|
480
|
-
return null;
|
481
|
-
}
|
482
|
-
const text = new TextDecoder().decode(value);
|
483
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
484
|
-
text,
|
485
|
-
/* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(RecursiveTokens, { reader }) })
|
486
|
-
] });
|
487
|
-
});
|
488
|
-
}
|
489
463
|
export {
|
490
|
-
Tokens,
|
491
464
|
useChat,
|
492
465
|
useCompletion
|
493
466
|
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
|
+
|
3
|
+
type Props = {
|
4
|
+
/**
|
5
|
+
* A ReadableStream produced by the AI SDK.
|
6
|
+
*/
|
7
|
+
stream: ReadableStream;
|
8
|
+
};
|
9
|
+
/**
|
10
|
+
* A React Server Component that recursively renders a stream of tokens.
|
11
|
+
* Can only be used inside of server components.
|
12
|
+
*/
|
13
|
+
declare function Tokens(props: Props): Promise<react_jsx_runtime.JSX.Element>;
|
14
|
+
|
15
|
+
export { Tokens };
|
@@ -0,0 +1,73 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var __async = (__this, __arguments, generator) => {
|
20
|
+
return new Promise((resolve, reject) => {
|
21
|
+
var fulfilled = (value) => {
|
22
|
+
try {
|
23
|
+
step(generator.next(value));
|
24
|
+
} catch (e) {
|
25
|
+
reject(e);
|
26
|
+
}
|
27
|
+
};
|
28
|
+
var rejected = (value) => {
|
29
|
+
try {
|
30
|
+
step(generator.throw(value));
|
31
|
+
} catch (e) {
|
32
|
+
reject(e);
|
33
|
+
}
|
34
|
+
};
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
37
|
+
});
|
38
|
+
};
|
39
|
+
|
40
|
+
// react/index.server.ts
|
41
|
+
var index_server_exports = {};
|
42
|
+
__export(index_server_exports, {
|
43
|
+
Tokens: () => Tokens
|
44
|
+
});
|
45
|
+
module.exports = __toCommonJS(index_server_exports);
|
46
|
+
|
47
|
+
// react/tokens.tsx
|
48
|
+
var import_react = require("react");
|
49
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
50
|
+
function Tokens(props) {
|
51
|
+
return __async(this, null, function* () {
|
52
|
+
const { stream } = props;
|
53
|
+
const reader = stream.getReader();
|
54
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecursiveTokens, { reader }) });
|
55
|
+
});
|
56
|
+
}
|
57
|
+
function RecursiveTokens(_0) {
|
58
|
+
return __async(this, arguments, function* ({ reader }) {
|
59
|
+
const { done, value } = yield reader.read();
|
60
|
+
if (done) {
|
61
|
+
return null;
|
62
|
+
}
|
63
|
+
const text = new TextDecoder().decode(value);
|
64
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
65
|
+
text,
|
66
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecursiveTokens, { reader }) })
|
67
|
+
] });
|
68
|
+
});
|
69
|
+
}
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
71
|
+
0 && (module.exports = {
|
72
|
+
Tokens
|
73
|
+
});
|
@@ -0,0 +1,47 @@
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
2
|
+
return new Promise((resolve, reject) => {
|
3
|
+
var fulfilled = (value) => {
|
4
|
+
try {
|
5
|
+
step(generator.next(value));
|
6
|
+
} catch (e) {
|
7
|
+
reject(e);
|
8
|
+
}
|
9
|
+
};
|
10
|
+
var rejected = (value) => {
|
11
|
+
try {
|
12
|
+
step(generator.throw(value));
|
13
|
+
} catch (e) {
|
14
|
+
reject(e);
|
15
|
+
}
|
16
|
+
};
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
19
|
+
});
|
20
|
+
};
|
21
|
+
|
22
|
+
// react/tokens.tsx
|
23
|
+
import { Suspense } from "react";
|
24
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
25
|
+
function Tokens(props) {
|
26
|
+
return __async(this, null, function* () {
|
27
|
+
const { stream } = props;
|
28
|
+
const reader = stream.getReader();
|
29
|
+
return /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(RecursiveTokens, { reader }) });
|
30
|
+
});
|
31
|
+
}
|
32
|
+
function RecursiveTokens(_0) {
|
33
|
+
return __async(this, arguments, function* ({ reader }) {
|
34
|
+
const { done, value } = yield reader.read();
|
35
|
+
if (done) {
|
36
|
+
return null;
|
37
|
+
}
|
38
|
+
const text = new TextDecoder().decode(value);
|
39
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
40
|
+
text,
|
41
|
+
/* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(RecursiveTokens, { reader }) })
|
42
|
+
] });
|
43
|
+
});
|
44
|
+
}
|
45
|
+
export {
|
46
|
+
Tokens
|
47
|
+
};
|
package/svelte/dist/index.js
CHANGED
@@ -516,7 +516,6 @@ function createChunkDecoder() {
|
|
516
516
|
}
|
517
517
|
|
518
518
|
// svelte/use-chat.ts
|
519
|
-
var uniqueId = 0;
|
520
519
|
var store = {};
|
521
520
|
function useChat({
|
522
521
|
api = "/api/chat",
|
@@ -531,7 +530,7 @@ function useChat({
|
|
531
530
|
headers,
|
532
531
|
body
|
533
532
|
} = {}) {
|
534
|
-
const chatId = id || `chat-${
|
533
|
+
const chatId = id || `chat-${nanoid()}`;
|
535
534
|
const key = `${api}|${chatId}`;
|
536
535
|
const { data, mutate: originalMutate } = $(key, {
|
537
536
|
fetcher: () => store[key] || initialMessages,
|
@@ -686,7 +685,6 @@ function useChat({
|
|
686
685
|
|
687
686
|
// svelte/use-completion.ts
|
688
687
|
var import_store2 = require("svelte/store");
|
689
|
-
var uniqueId2 = 0;
|
690
688
|
var store2 = {};
|
691
689
|
function useCompletion({
|
692
690
|
api = "/api/completion",
|
@@ -700,7 +698,7 @@ function useCompletion({
|
|
700
698
|
onFinish,
|
701
699
|
onError
|
702
700
|
} = {}) {
|
703
|
-
const completionId = id || `completion-${
|
701
|
+
const completionId = id || `completion-${nanoid()}`;
|
704
702
|
const key = `${api}|${completionId}`;
|
705
703
|
const { data, mutate: originalMutate } = $(key, {
|
706
704
|
fetcher: () => store2[key] || initialCompletion,
|
package/svelte/dist/index.mjs
CHANGED
@@ -492,7 +492,6 @@ function createChunkDecoder() {
|
|
492
492
|
}
|
493
493
|
|
494
494
|
// svelte/use-chat.ts
|
495
|
-
var uniqueId = 0;
|
496
495
|
var store = {};
|
497
496
|
function useChat({
|
498
497
|
api = "/api/chat",
|
@@ -507,7 +506,7 @@ function useChat({
|
|
507
506
|
headers,
|
508
507
|
body
|
509
508
|
} = {}) {
|
510
|
-
const chatId = id || `chat-${
|
509
|
+
const chatId = id || `chat-${nanoid()}`;
|
511
510
|
const key = `${api}|${chatId}`;
|
512
511
|
const { data, mutate: originalMutate } = $(key, {
|
513
512
|
fetcher: () => store[key] || initialMessages,
|
@@ -662,7 +661,6 @@ function useChat({
|
|
662
661
|
|
663
662
|
// svelte/use-completion.ts
|
664
663
|
import { get as get2, writable as writable2 } from "svelte/store";
|
665
|
-
var uniqueId2 = 0;
|
666
664
|
var store2 = {};
|
667
665
|
function useCompletion({
|
668
666
|
api = "/api/completion",
|
@@ -676,7 +674,7 @@ function useCompletion({
|
|
676
674
|
onFinish,
|
677
675
|
onError
|
678
676
|
} = {}) {
|
679
|
-
const completionId = id || `completion-${
|
677
|
+
const completionId = id || `completion-${nanoid()}`;
|
680
678
|
const key = `${api}|${completionId}`;
|
681
679
|
const { data, mutate: originalMutate } = $(key, {
|
682
680
|
fetcher: () => store2[key] || initialCompletion,
|
package/vue/dist/index.js
CHANGED
@@ -89,7 +89,6 @@ function createChunkDecoder() {
|
|
89
89
|
}
|
90
90
|
|
91
91
|
// vue/use-chat.ts
|
92
|
-
var uniqueId = 0;
|
93
92
|
var useSWRV = import_swrv.default.default || import_swrv.default;
|
94
93
|
var store = {};
|
95
94
|
function useChat({
|
@@ -105,7 +104,7 @@ function useChat({
|
|
105
104
|
headers,
|
106
105
|
body
|
107
106
|
} = {}) {
|
108
|
-
const chatId = id || `chat-${
|
107
|
+
const chatId = id || `chat-${nanoid()}`;
|
109
108
|
const key = `${api}|${chatId}`;
|
110
109
|
const { data, mutate: originalMutate } = useSWRV(
|
111
110
|
key,
|
@@ -260,7 +259,6 @@ function useChat({
|
|
260
259
|
// vue/use-completion.ts
|
261
260
|
var import_swrv2 = __toESM(require("swrv"));
|
262
261
|
var import_vue2 = require("vue");
|
263
|
-
var uniqueId2 = 0;
|
264
262
|
var useSWRV2 = import_swrv2.default.default || import_swrv2.default;
|
265
263
|
var store2 = {};
|
266
264
|
function useCompletion({
|
@@ -275,7 +273,7 @@ function useCompletion({
|
|
275
273
|
onFinish,
|
276
274
|
onError
|
277
275
|
} = {}) {
|
278
|
-
const completionId = id || `completion-${
|
276
|
+
const completionId = id || `completion-${nanoid()}`;
|
279
277
|
const key = `${api}|${completionId}`;
|
280
278
|
const { data, mutate: originalMutate } = useSWRV2(
|
281
279
|
key,
|
package/vue/dist/index.mjs
CHANGED
@@ -55,7 +55,6 @@ function createChunkDecoder() {
|
|
55
55
|
}
|
56
56
|
|
57
57
|
// vue/use-chat.ts
|
58
|
-
var uniqueId = 0;
|
59
58
|
var useSWRV = swrv.default || swrv;
|
60
59
|
var store = {};
|
61
60
|
function useChat({
|
@@ -71,7 +70,7 @@ function useChat({
|
|
71
70
|
headers,
|
72
71
|
body
|
73
72
|
} = {}) {
|
74
|
-
const chatId = id || `chat-${
|
73
|
+
const chatId = id || `chat-${nanoid()}`;
|
75
74
|
const key = `${api}|${chatId}`;
|
76
75
|
const { data, mutate: originalMutate } = useSWRV(
|
77
76
|
key,
|
@@ -226,7 +225,6 @@ function useChat({
|
|
226
225
|
// vue/use-completion.ts
|
227
226
|
import swrv2 from "swrv";
|
228
227
|
import { ref as ref2 } from "vue";
|
229
|
-
var uniqueId2 = 0;
|
230
228
|
var useSWRV2 = swrv2.default || swrv2;
|
231
229
|
var store2 = {};
|
232
230
|
function useCompletion({
|
@@ -241,7 +239,7 @@ function useCompletion({
|
|
241
239
|
onFinish,
|
242
240
|
onError
|
243
241
|
} = {}) {
|
244
|
-
const completionId = id || `completion-${
|
242
|
+
const completionId = id || `completion-${nanoid()}`;
|
245
243
|
const key = `${api}|${completionId}`;
|
246
244
|
const { data, mutate: originalMutate } = useSWRV2(
|
247
245
|
key,
|