ai 3.2.4 → 3.2.6
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/rsc/dist/index.d.ts +1 -1
- package/rsc/dist/rsc-server.d.mts +1 -1
- package/rsc/dist/rsc-server.mjs +63 -36
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/rsc/dist/rsc-shared.d.mts +1 -5
- package/rsc/dist/rsc-shared.mjs +44 -69
- 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.2.
|
3
|
+
"version": "3.2.6",
|
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",
|
package/rsc/dist/index.d.ts
CHANGED
@@ -445,7 +445,7 @@ Tool choice for the generation. It supports the following settings:
|
|
445
445
|
- `auto` (default): the model can choose whether and which tools to call.
|
446
446
|
- `required`: the model must call a tool. It can choose which tool to call.
|
447
447
|
- `none`: the model must not call tools
|
448
|
-
- `{ type: 'tool',
|
448
|
+
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
449
449
|
*/
|
450
450
|
type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
451
451
|
type: 'tool';
|
@@ -443,7 +443,7 @@ Tool choice for the generation. It supports the following settings:
|
|
443
443
|
- `auto` (default): the model can choose whether and which tools to call.
|
444
444
|
- `required`: the model must call a tool. It can choose which tool to call.
|
445
445
|
- `none`: the model must not call tools
|
446
|
-
- `{ type: 'tool',
|
446
|
+
- `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
|
447
447
|
*/
|
448
448
|
type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
|
449
449
|
type: 'tool';
|
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -3,6 +3,8 @@ 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";
|
6
8
|
function createResolvablePromise() {
|
7
9
|
let resolve, reject;
|
8
10
|
const promise = new Promise((res, rej) => {
|
@@ -15,6 +17,34 @@ function createResolvablePromise() {
|
|
15
17
|
reject
|
16
18
|
};
|
17
19
|
}
|
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
|
+
}
|
18
48
|
var isFunction = (x) => typeof x === "function";
|
19
49
|
var consumeStream = async (stream) => {
|
20
50
|
const reader = stream.getReader();
|
@@ -145,7 +175,6 @@ function getMutableAIState(...args) {
|
|
145
175
|
}
|
146
176
|
|
147
177
|
// rsc/streamable.tsx
|
148
|
-
import { isValidElement } from "react";
|
149
178
|
import zodToJsonSchema2 from "zod-to-json-schema";
|
150
179
|
|
151
180
|
// core/util/retry-with-exponential-backoff.ts
|
@@ -1047,11 +1076,10 @@ var STREAMABLE_VALUE_TYPE = Symbol.for("ui.streamable.value");
|
|
1047
1076
|
var DEV_DEFAULT_STREAMABLE_WARNING_TIME = 15 * 1e3;
|
1048
1077
|
|
1049
1078
|
// rsc/streamable.tsx
|
1050
|
-
import { InternalStreamableUIClient } from "./rsc-shared.mjs";
|
1051
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
1052
1079
|
function createStreamableUI(initialValue) {
|
1053
|
-
|
1080
|
+
let currentValue = initialValue;
|
1054
1081
|
let closed = false;
|
1082
|
+
let { row, resolve, reject } = createSuspensedChunk(initialValue);
|
1055
1083
|
function assertStream(method) {
|
1056
1084
|
if (closed) {
|
1057
1085
|
throw new Error(method + ": UI stream is already closed.");
|
@@ -1072,16 +1100,28 @@ function createStreamableUI(initialValue) {
|
|
1072
1100
|
}
|
1073
1101
|
warnUnclosedStream();
|
1074
1102
|
const streamable2 = {
|
1075
|
-
value:
|
1103
|
+
value: row,
|
1076
1104
|
update(value) {
|
1077
1105
|
assertStream(".update()");
|
1078
|
-
|
1106
|
+
if (value === currentValue) {
|
1107
|
+
warnUnclosedStream();
|
1108
|
+
return streamable2;
|
1109
|
+
}
|
1110
|
+
const resolvable = createResolvablePromise();
|
1111
|
+
currentValue = value;
|
1112
|
+
resolve({ value: currentValue, done: false, next: resolvable.promise });
|
1113
|
+
resolve = resolvable.resolve;
|
1114
|
+
reject = resolvable.reject;
|
1079
1115
|
warnUnclosedStream();
|
1080
1116
|
return streamable2;
|
1081
1117
|
},
|
1082
1118
|
append(value) {
|
1083
1119
|
assertStream(".append()");
|
1084
|
-
|
1120
|
+
const resolvable = createResolvablePromise();
|
1121
|
+
currentValue = value;
|
1122
|
+
resolve({ value, done: false, append: true, next: resolvable.promise });
|
1123
|
+
resolve = resolvable.resolve;
|
1124
|
+
reject = resolvable.reject;
|
1085
1125
|
warnUnclosedStream();
|
1086
1126
|
return streamable2;
|
1087
1127
|
},
|
@@ -1091,7 +1131,7 @@ function createStreamableUI(initialValue) {
|
|
1091
1131
|
clearTimeout(warningTimeout);
|
1092
1132
|
}
|
1093
1133
|
closed = true;
|
1094
|
-
|
1134
|
+
reject(error);
|
1095
1135
|
return streamable2;
|
1096
1136
|
},
|
1097
1137
|
done(...args) {
|
@@ -1101,10 +1141,10 @@ function createStreamableUI(initialValue) {
|
|
1101
1141
|
}
|
1102
1142
|
closed = true;
|
1103
1143
|
if (args.length) {
|
1104
|
-
|
1144
|
+
resolve({ value: args[0], done: true });
|
1105
1145
|
return streamable2;
|
1106
1146
|
}
|
1107
|
-
|
1147
|
+
resolve({ value: currentValue, done: true });
|
1108
1148
|
return streamable2;
|
1109
1149
|
}
|
1110
1150
|
};
|
@@ -1224,38 +1264,25 @@ function createStreamableValueImpl(initialValue) {
|
|
1224
1264
|
},
|
1225
1265
|
append(value) {
|
1226
1266
|
assertStream(".append()");
|
1227
|
-
if (typeof
|
1267
|
+
if (typeof currentValue !== "string" && typeof currentValue !== "undefined") {
|
1228
1268
|
throw new Error(
|
1229
|
-
`.append(): The value
|
1269
|
+
`.append(): The current value is not a string. Received: ${typeof currentValue}`
|
1230
1270
|
);
|
1231
1271
|
}
|
1232
|
-
if (typeof
|
1233
|
-
currentPatchValue = void 0;
|
1234
|
-
currentValue = value;
|
1235
|
-
} else if (typeof currentValue === "string") {
|
1236
|
-
if (typeof value === "string") {
|
1237
|
-
currentPatchValue = [0, value];
|
1238
|
-
currentValue = currentValue + value;
|
1239
|
-
} else {
|
1240
|
-
currentPatchValue = [1, value];
|
1241
|
-
currentValue = /* @__PURE__ */ jsxs(Fragment, { children: [
|
1242
|
-
currentValue,
|
1243
|
-
value
|
1244
|
-
] });
|
1245
|
-
}
|
1246
|
-
} else if (isValidElement(currentValue)) {
|
1247
|
-
currentPatchValue = [1, value];
|
1248
|
-
currentValue = /* @__PURE__ */ jsxs(Fragment, { children: [
|
1249
|
-
currentValue,
|
1250
|
-
value
|
1251
|
-
] });
|
1252
|
-
} else {
|
1272
|
+
if (typeof value !== "string") {
|
1253
1273
|
throw new Error(
|
1254
|
-
`.append(): The
|
1274
|
+
`.append(): The value is not a string. Received: ${typeof value}`
|
1255
1275
|
);
|
1256
1276
|
}
|
1257
1277
|
const resolvePrevious = resolvable.resolve;
|
1258
1278
|
resolvable = createResolvablePromise();
|
1279
|
+
if (typeof currentValue === "string") {
|
1280
|
+
currentPatchValue = [0, value];
|
1281
|
+
currentValue = currentValue + value;
|
1282
|
+
} else {
|
1283
|
+
currentPatchValue = void 0;
|
1284
|
+
currentValue = value;
|
1285
|
+
}
|
1259
1286
|
currentPromise = resolvable.promise;
|
1260
1287
|
resolvePrevious(createWrapped());
|
1261
1288
|
warnUnclosedStream();
|
@@ -1629,7 +1656,7 @@ async function streamUI({
|
|
1629
1656
|
}
|
1630
1657
|
|
1631
1658
|
// rsc/provider.tsx
|
1632
|
-
import * as
|
1659
|
+
import * as React2 from "react";
|
1633
1660
|
import { InternalAIProvider } from "./rsc-shared.mjs";
|
1634
1661
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
1635
1662
|
async function innerAction({
|
@@ -1668,7 +1695,7 @@ function createAI({
|
|
1668
1695
|
const wrappedSyncUIState = onGetUIState ? wrapAction(onGetUIState, {}) : void 0;
|
1669
1696
|
const AI = async (props) => {
|
1670
1697
|
var _a, _b;
|
1671
|
-
if ("useState" in
|
1698
|
+
if ("useState" in React2) {
|
1672
1699
|
throw new Error(
|
1673
1700
|
"This component can only be used inside Server Components."
|
1674
1701
|
);
|