ai 3.1.31 → 3.1.33
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 +74 -2
- package/dist/index.d.ts +74 -2
- package/dist/index.js +138 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
- package/rsc/dist/rsc-server.mjs +36 -63
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/rsc/dist/rsc-shared.d.mts +5 -1
- package/rsc/dist/rsc-shared.mjs +69 -44
- package/rsc/dist/rsc-shared.mjs.map +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ai",
|
3
|
-
"version": "3.1.
|
3
|
+
"version": "3.1.33",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"sideEffects": false,
|
6
6
|
"main": "./dist/index.js",
|
@@ -98,8 +98,8 @@
|
|
98
98
|
"tsup": "^7.2.0",
|
99
99
|
"typescript": "5.1.3",
|
100
100
|
"zod": "3.23.8",
|
101
|
-
"
|
102
|
-
"
|
101
|
+
"eslint-config-vercel-ai": "0.0.0",
|
102
|
+
"@vercel/ai-tsconfig": "0.0.0"
|
103
103
|
},
|
104
104
|
"peerDependencies": {
|
105
105
|
"openai": "^4.42.0",
|
@@ -149,12 +149,13 @@
|
|
149
149
|
"lint": "eslint \"./**/*.ts*\"",
|
150
150
|
"type-check": "tsc --noEmit",
|
151
151
|
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
152
|
-
"test": "pnpm test:node && pnpm test:edge && pnpm test:ui",
|
152
|
+
"test": "pnpm test:node && pnpm test:edge && pnpm test:ui && pnpm test:e2e",
|
153
153
|
"test:edge": "vitest --config vitest.edge.config.js --run",
|
154
154
|
"test:node": "vitest --config vitest.node.config.js --run",
|
155
155
|
"test:node:core": "pnpm vitest --config vitest.node.config.js --run ./core/",
|
156
156
|
"test:ui": "pnpm test:ui:react",
|
157
157
|
"test:ui:react": "vitest --config vitest.ui.react.config.js --run",
|
158
|
+
"test:e2e": "playwright test",
|
158
159
|
"test:edge:watch": "vitest --config vitest.edge.config.js",
|
159
160
|
"test:node:watch": "vitest --config vitest.node.config.js",
|
160
161
|
"test:ui:react:watch": "vitest --config vitest.ui.react.config.js"
|
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -3,8 +3,6 @@ import { AsyncLocalStorage } from "async_hooks";
|
|
3
3
|
import * as jsondiffpatch from "jsondiffpatch";
|
4
4
|
|
5
5
|
// rsc/utils.tsx
|
6
|
-
import { Suspense } from "react";
|
7
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
8
6
|
function createResolvablePromise() {
|
9
7
|
let resolve, reject;
|
10
8
|
const promise = new Promise((res, rej) => {
|
@@ -17,34 +15,6 @@ function createResolvablePromise() {
|
|
17
15
|
reject
|
18
16
|
};
|
19
17
|
}
|
20
|
-
var R = [
|
21
|
-
async ({
|
22
|
-
c,
|
23
|
-
// current
|
24
|
-
n
|
25
|
-
// next
|
26
|
-
}) => {
|
27
|
-
const chunk = await n;
|
28
|
-
if (chunk.done) {
|
29
|
-
return chunk.value;
|
30
|
-
}
|
31
|
-
if (chunk.append) {
|
32
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
33
|
-
c,
|
34
|
-
/* @__PURE__ */ jsx(Suspense, { fallback: chunk.value, children: /* @__PURE__ */ jsx(R, { c: chunk.value, n: chunk.next }) })
|
35
|
-
] });
|
36
|
-
}
|
37
|
-
return /* @__PURE__ */ jsx(Suspense, { fallback: chunk.value, children: /* @__PURE__ */ jsx(R, { c: chunk.value, n: chunk.next }) });
|
38
|
-
}
|
39
|
-
][0];
|
40
|
-
function createSuspensedChunk(initialValue) {
|
41
|
-
const { promise, resolve, reject } = createResolvablePromise();
|
42
|
-
return {
|
43
|
-
row: /* @__PURE__ */ jsx(Suspense, { fallback: initialValue, children: /* @__PURE__ */ jsx(R, { c: initialValue, n: promise }) }),
|
44
|
-
resolve,
|
45
|
-
reject
|
46
|
-
};
|
47
|
-
}
|
48
18
|
var isFunction = (x) => typeof x === "function";
|
49
19
|
var consumeStream = async (stream) => {
|
50
20
|
const reader = stream.getReader();
|
@@ -175,6 +145,7 @@ function getMutableAIState(...args) {
|
|
175
145
|
}
|
176
146
|
|
177
147
|
// rsc/streamable.tsx
|
148
|
+
import { isValidElement } from "react";
|
178
149
|
import zodToJsonSchema2 from "zod-to-json-schema";
|
179
150
|
|
180
151
|
// core/util/retry-with-exponential-backoff.ts
|
@@ -1001,10 +972,11 @@ var STREAMABLE_VALUE_TYPE = Symbol.for("ui.streamable.value");
|
|
1001
972
|
var DEV_DEFAULT_STREAMABLE_WARNING_TIME = 15 * 1e3;
|
1002
973
|
|
1003
974
|
// rsc/streamable.tsx
|
975
|
+
import { InternalStreamableUIClient } from "./rsc-shared.mjs";
|
976
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
1004
977
|
function createStreamableUI(initialValue) {
|
1005
|
-
|
978
|
+
const innerStreamable = createStreamableValue(initialValue);
|
1006
979
|
let closed = false;
|
1007
|
-
let { row, resolve, reject } = createSuspensedChunk(initialValue);
|
1008
980
|
function assertStream(method) {
|
1009
981
|
if (closed) {
|
1010
982
|
throw new Error(method + ": UI stream is already closed.");
|
@@ -1025,28 +997,16 @@ function createStreamableUI(initialValue) {
|
|
1025
997
|
}
|
1026
998
|
warnUnclosedStream();
|
1027
999
|
const streamable2 = {
|
1028
|
-
value:
|
1000
|
+
value: /* @__PURE__ */ jsx(InternalStreamableUIClient, { s: innerStreamable.value }),
|
1029
1001
|
update(value) {
|
1030
1002
|
assertStream(".update()");
|
1031
|
-
|
1032
|
-
warnUnclosedStream();
|
1033
|
-
return streamable2;
|
1034
|
-
}
|
1035
|
-
const resolvable = createResolvablePromise();
|
1036
|
-
currentValue = value;
|
1037
|
-
resolve({ value: currentValue, done: false, next: resolvable.promise });
|
1038
|
-
resolve = resolvable.resolve;
|
1039
|
-
reject = resolvable.reject;
|
1003
|
+
innerStreamable.update(value);
|
1040
1004
|
warnUnclosedStream();
|
1041
1005
|
return streamable2;
|
1042
1006
|
},
|
1043
1007
|
append(value) {
|
1044
1008
|
assertStream(".append()");
|
1045
|
-
|
1046
|
-
currentValue = value;
|
1047
|
-
resolve({ value, done: false, append: true, next: resolvable.promise });
|
1048
|
-
resolve = resolvable.resolve;
|
1049
|
-
reject = resolvable.reject;
|
1009
|
+
innerStreamable.append(value);
|
1050
1010
|
warnUnclosedStream();
|
1051
1011
|
return streamable2;
|
1052
1012
|
},
|
@@ -1056,7 +1016,7 @@ function createStreamableUI(initialValue) {
|
|
1056
1016
|
clearTimeout(warningTimeout);
|
1057
1017
|
}
|
1058
1018
|
closed = true;
|
1059
|
-
|
1019
|
+
innerStreamable.error(error);
|
1060
1020
|
return streamable2;
|
1061
1021
|
},
|
1062
1022
|
done(...args) {
|
@@ -1066,10 +1026,10 @@ function createStreamableUI(initialValue) {
|
|
1066
1026
|
}
|
1067
1027
|
closed = true;
|
1068
1028
|
if (args.length) {
|
1069
|
-
|
1029
|
+
innerStreamable.done(args[0]);
|
1070
1030
|
return streamable2;
|
1071
1031
|
}
|
1072
|
-
|
1032
|
+
innerStreamable.done();
|
1073
1033
|
return streamable2;
|
1074
1034
|
}
|
1075
1035
|
};
|
@@ -1189,25 +1149,38 @@ function createStreamableValueImpl(initialValue) {
|
|
1189
1149
|
},
|
1190
1150
|
append(value) {
|
1191
1151
|
assertStream(".append()");
|
1192
|
-
if (typeof
|
1152
|
+
if (typeof value !== "string" && !isValidElement(value)) {
|
1193
1153
|
throw new Error(
|
1194
|
-
`.append(): The
|
1154
|
+
`.append(): The value type can't be appended to the stream. Received: ${typeof value}`
|
1195
1155
|
);
|
1196
1156
|
}
|
1197
|
-
if (typeof
|
1157
|
+
if (typeof currentValue === "undefined") {
|
1158
|
+
currentPatchValue = void 0;
|
1159
|
+
currentValue = value;
|
1160
|
+
} else if (typeof currentValue === "string") {
|
1161
|
+
if (typeof value === "string") {
|
1162
|
+
currentPatchValue = [0, value];
|
1163
|
+
currentValue = currentValue + value;
|
1164
|
+
} else {
|
1165
|
+
currentPatchValue = [1, value];
|
1166
|
+
currentValue = /* @__PURE__ */ jsxs(Fragment, { children: [
|
1167
|
+
currentValue,
|
1168
|
+
value
|
1169
|
+
] });
|
1170
|
+
}
|
1171
|
+
} else if (isValidElement(currentValue)) {
|
1172
|
+
currentPatchValue = [1, value];
|
1173
|
+
currentValue = /* @__PURE__ */ jsxs(Fragment, { children: [
|
1174
|
+
currentValue,
|
1175
|
+
value
|
1176
|
+
] });
|
1177
|
+
} else {
|
1198
1178
|
throw new Error(
|
1199
|
-
`.append(): The value
|
1179
|
+
`.append(): The current value doesn't support appending data. Type: ${typeof currentValue}`
|
1200
1180
|
);
|
1201
1181
|
}
|
1202
1182
|
const resolvePrevious = resolvable.resolve;
|
1203
1183
|
resolvable = createResolvablePromise();
|
1204
|
-
if (typeof currentValue === "string") {
|
1205
|
-
currentPatchValue = [0, value];
|
1206
|
-
currentValue = currentValue + value;
|
1207
|
-
} else {
|
1208
|
-
currentPatchValue = void 0;
|
1209
|
-
currentValue = value;
|
1210
|
-
}
|
1211
1184
|
currentPromise = resolvable.promise;
|
1212
1185
|
resolvePrevious(createWrapped());
|
1213
1186
|
warnUnclosedStream();
|
@@ -1573,7 +1546,7 @@ async function streamUI({
|
|
1573
1546
|
}
|
1574
1547
|
|
1575
1548
|
// rsc/provider.tsx
|
1576
|
-
import * as
|
1549
|
+
import * as React from "react";
|
1577
1550
|
import { InternalAIProvider } from "./rsc-shared.mjs";
|
1578
1551
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
1579
1552
|
async function innerAction({
|
@@ -1612,7 +1585,7 @@ function createAI({
|
|
1612
1585
|
const wrappedSyncUIState = onGetUIState ? wrapAction(onGetUIState, {}) : void 0;
|
1613
1586
|
const AI = async (props) => {
|
1614
1587
|
var _a, _b;
|
1615
|
-
if ("useState" in
|
1588
|
+
if ("useState" in React) {
|
1616
1589
|
throw new Error(
|
1617
1590
|
"This component can only be used inside Server Components."
|
1618
1591
|
);
|