ai 4.0.0-canary.0 → 4.0.0-canary.10
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/CHANGELOG.md +135 -0
- package/dist/index.d.mts +92 -671
- package/dist/index.d.ts +92 -671
- package/dist/index.js +151 -586
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +125 -548
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -30
- package/react/dist/index.d.ts +0 -17
- package/rsc/dist/index.d.ts +19 -19
- package/rsc/dist/rsc-server.d.mts +19 -19
- package/rsc/dist/rsc-server.mjs +9 -132
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/prompts/dist/index.d.mts +0 -220
- package/prompts/dist/index.d.ts +0 -220
- package/prompts/dist/index.js +0 -178
- package/prompts/dist/index.js.map +0 -1
- package/prompts/dist/index.mjs +0 -146
- package/prompts/dist/index.mjs.map +0 -1
- package/react/dist/index.server.d.mts +0 -17
- package/react/dist/index.server.d.ts +0 -17
- package/react/dist/index.server.js +0 -50
- package/react/dist/index.server.js.map +0 -1
- package/react/dist/index.server.mjs +0 -23
- package/react/dist/index.server.mjs.map +0 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ai",
|
3
|
-
"version": "4.0.0-canary.
|
3
|
+
"version": "4.0.0-canary.10",
|
4
4
|
"description": "AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"sideEffects": false,
|
@@ -10,7 +10,6 @@
|
|
10
10
|
"files": [
|
11
11
|
"dist/**/*",
|
12
12
|
"react/dist/**/*",
|
13
|
-
"prompts/dist/**/*",
|
14
13
|
"rsc/dist/**/*",
|
15
14
|
"test/dist/**/*",
|
16
15
|
"CHANGELOG.md"
|
@@ -33,11 +32,6 @@
|
|
33
32
|
"react-server": "./rsc/dist/rsc-server.mjs",
|
34
33
|
"import": "./rsc/dist/rsc-client.mjs"
|
35
34
|
},
|
36
|
-
"./prompts": {
|
37
|
-
"types": "./prompts/dist/index.d.ts",
|
38
|
-
"import": "./prompts/dist/index.mjs",
|
39
|
-
"require": "./prompts/dist/index.js"
|
40
|
-
},
|
41
35
|
"./react": {
|
42
36
|
"types": "./react/dist/index.d.ts",
|
43
37
|
"react-server": "./react/dist/index.server.mjs",
|
@@ -46,41 +40,30 @@
|
|
46
40
|
}
|
47
41
|
},
|
48
42
|
"dependencies": {
|
49
|
-
"@ai-sdk/provider": "0.0.
|
50
|
-
"@ai-sdk/provider-utils": "
|
51
|
-
"@ai-sdk/react": "1.0.0-canary.
|
52
|
-
"@ai-sdk/ui-utils": "1.0.0-canary.
|
43
|
+
"@ai-sdk/provider": "1.0.0-canary.0",
|
44
|
+
"@ai-sdk/provider-utils": "2.0.0-canary.3",
|
45
|
+
"@ai-sdk/react": "1.0.0-canary.7",
|
46
|
+
"@ai-sdk/ui-utils": "1.0.0-canary.7",
|
53
47
|
"@opentelemetry/api": "1.9.0",
|
54
|
-
"eventsource-parser": "1.1.2",
|
55
48
|
"jsondiffpatch": "0.6.0",
|
56
|
-
"json-schema": "^0.4.0",
|
57
|
-
"secure-json-parse": "^2.7.0",
|
58
49
|
"zod-to-json-schema": "^3.23.3"
|
59
50
|
},
|
60
51
|
"devDependencies": {
|
61
52
|
"@edge-runtime/vm": "^3.2.0",
|
62
|
-
"@testing-library/jest-dom": "^6.4.5",
|
63
|
-
"@testing-library/react": "^15.0.7",
|
64
|
-
"@testing-library/user-event": "^14.5.1",
|
65
|
-
"@types/json-schema": "7.0.15",
|
66
53
|
"@types/node": "^18",
|
67
54
|
"@types/react": "^18",
|
68
55
|
"@types/react-dom": "^18",
|
69
|
-
"@vitejs/plugin-react": "4.
|
70
|
-
"eslint": "
|
71
|
-
"jsdom": "^24.0.0",
|
72
|
-
"msw": "2.3.1",
|
73
|
-
"openai": "4.52.6",
|
56
|
+
"@vitejs/plugin-react": "4.3.3",
|
57
|
+
"eslint": "8.57.1",
|
74
58
|
"react-dom": "^18",
|
75
59
|
"react-server-dom-webpack": "18.3.0-canary-eb33bd747-20240312",
|
76
60
|
"tsup": "^7.2.0",
|
77
|
-
"typescript": "5.
|
61
|
+
"typescript": "5.6.3",
|
78
62
|
"zod": "3.23.8",
|
79
63
|
"@vercel/ai-tsconfig": "0.0.0",
|
80
64
|
"eslint-config-vercel-ai": "0.0.0"
|
81
65
|
},
|
82
66
|
"peerDependencies": {
|
83
|
-
"openai": "^4.42.0",
|
84
67
|
"react": "^18 || ^19 || ^19.0.0-rc",
|
85
68
|
"zod": "^3.0.0"
|
86
69
|
},
|
@@ -90,9 +73,6 @@
|
|
90
73
|
},
|
91
74
|
"zod": {
|
92
75
|
"optional": true
|
93
|
-
},
|
94
|
-
"openai": {
|
95
|
-
"optional": true
|
96
76
|
}
|
97
77
|
},
|
98
78
|
"engines": {
|
@@ -117,9 +97,9 @@
|
|
117
97
|
"nextjs"
|
118
98
|
],
|
119
99
|
"scripts": {
|
120
|
-
"build": "tsup
|
100
|
+
"build": "tsup",
|
101
|
+
"build:watch": "tsup --watch",
|
121
102
|
"clean": "rm -rf dist && rm -rf react/dist && rm -rf rsc/dist",
|
122
|
-
"dev": "tsup --watch",
|
123
103
|
"lint": "eslint \"./**/*.ts*\"",
|
124
104
|
"type-check": "tsc --noEmit",
|
125
105
|
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
package/react/dist/index.d.ts
CHANGED
@@ -8,20 +8,3 @@ declare const useAssistant: typeof useAssistant$1;
|
|
8
8
|
declare const experimental_useObject: <RESULT, INPUT = any>({ api, id, schema, initialValue, fetch, onError, onFinish, headers, }: _ai_sdk_react.Experimental_UseObjectOptions<RESULT>) => _ai_sdk_react.Experimental_UseObjectHelpers<RESULT, INPUT>;
|
9
9
|
|
10
10
|
export { experimental_useObject, useAssistant, useChat, useCompletion };
|
11
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
12
|
-
|
13
|
-
type Props = {
|
14
|
-
/**
|
15
|
-
* A ReadableStream produced by the AI SDK.
|
16
|
-
*/
|
17
|
-
stream: ReadableStream;
|
18
|
-
};
|
19
|
-
/**
|
20
|
-
A React Server Component that recursively renders a stream of tokens.
|
21
|
-
Can only be used inside of server components.
|
22
|
-
|
23
|
-
@deprecated Use RSCs / Generative AI instead.
|
24
|
-
*/
|
25
|
-
declare function Tokens(props: Props): Promise<react_jsx_runtime.JSX.Element>;
|
26
|
-
|
27
|
-
export { Tokens };
|
package/rsc/dist/index.d.ts
CHANGED
@@ -174,24 +174,6 @@ type CallSettings = {
|
|
174
174
|
headers?: Record<string, string | undefined>;
|
175
175
|
};
|
176
176
|
|
177
|
-
/**
|
178
|
-
Represents the number of tokens used in a prompt and completion.
|
179
|
-
*/
|
180
|
-
type LanguageModelUsage = {
|
181
|
-
/**
|
182
|
-
The number of tokens used in the prompt.
|
183
|
-
*/
|
184
|
-
promptTokens: number;
|
185
|
-
/**
|
186
|
-
The number of tokens used in the completion.
|
187
|
-
*/
|
188
|
-
completionTokens: number;
|
189
|
-
/**
|
190
|
-
The total number of tokens used (promptTokens + completionTokens).
|
191
|
-
*/
|
192
|
-
totalTokens: number;
|
193
|
-
};
|
194
|
-
|
195
177
|
/**
|
196
178
|
Reason why a language model finished generating a response.
|
197
179
|
|
@@ -229,6 +211,24 @@ functionality that can be fully encapsulated in the provider.
|
|
229
211
|
*/
|
230
212
|
type ProviderMetadata = LanguageModelV1ProviderMetadata;
|
231
213
|
|
214
|
+
/**
|
215
|
+
Represents the number of tokens used in a prompt and completion.
|
216
|
+
*/
|
217
|
+
type LanguageModelUsage = {
|
218
|
+
/**
|
219
|
+
The number of tokens used in the prompt.
|
220
|
+
*/
|
221
|
+
promptTokens: number;
|
222
|
+
/**
|
223
|
+
The number of tokens used in the completion.
|
224
|
+
*/
|
225
|
+
completionTokens: number;
|
226
|
+
/**
|
227
|
+
The total number of tokens used (promptTokens + completionTokens).
|
228
|
+
*/
|
229
|
+
totalTokens: number;
|
230
|
+
};
|
231
|
+
|
232
232
|
/**
|
233
233
|
Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
234
234
|
*/
|
@@ -437,7 +437,7 @@ It can be a user message, an assistant message, or a tool message.
|
|
437
437
|
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
438
438
|
|
439
439
|
type UIMessage = {
|
440
|
-
role: 'system' | 'user' | 'assistant' | '
|
440
|
+
role: 'system' | 'user' | 'assistant' | 'data';
|
441
441
|
content: string;
|
442
442
|
toolInvocations?: ToolInvocation[];
|
443
443
|
experimental_attachments?: Attachment[];
|
@@ -172,24 +172,6 @@ type CallSettings = {
|
|
172
172
|
headers?: Record<string, string | undefined>;
|
173
173
|
};
|
174
174
|
|
175
|
-
/**
|
176
|
-
Represents the number of tokens used in a prompt and completion.
|
177
|
-
*/
|
178
|
-
type LanguageModelUsage = {
|
179
|
-
/**
|
180
|
-
The number of tokens used in the prompt.
|
181
|
-
*/
|
182
|
-
promptTokens: number;
|
183
|
-
/**
|
184
|
-
The number of tokens used in the completion.
|
185
|
-
*/
|
186
|
-
completionTokens: number;
|
187
|
-
/**
|
188
|
-
The total number of tokens used (promptTokens + completionTokens).
|
189
|
-
*/
|
190
|
-
totalTokens: number;
|
191
|
-
};
|
192
|
-
|
193
175
|
/**
|
194
176
|
Reason why a language model finished generating a response.
|
195
177
|
|
@@ -227,6 +209,24 @@ functionality that can be fully encapsulated in the provider.
|
|
227
209
|
*/
|
228
210
|
type ProviderMetadata = LanguageModelV1ProviderMetadata;
|
229
211
|
|
212
|
+
/**
|
213
|
+
Represents the number of tokens used in a prompt and completion.
|
214
|
+
*/
|
215
|
+
type LanguageModelUsage = {
|
216
|
+
/**
|
217
|
+
The number of tokens used in the prompt.
|
218
|
+
*/
|
219
|
+
promptTokens: number;
|
220
|
+
/**
|
221
|
+
The number of tokens used in the completion.
|
222
|
+
*/
|
223
|
+
completionTokens: number;
|
224
|
+
/**
|
225
|
+
The total number of tokens used (promptTokens + completionTokens).
|
226
|
+
*/
|
227
|
+
totalTokens: number;
|
228
|
+
};
|
229
|
+
|
230
230
|
/**
|
231
231
|
Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
|
232
232
|
*/
|
@@ -435,7 +435,7 @@ It can be a user message, an assistant message, or a tool message.
|
|
435
435
|
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
|
436
436
|
|
437
437
|
type UIMessage = {
|
438
|
-
role: 'system' | 'user' | 'assistant' | '
|
438
|
+
role: 'system' | 'user' | 'assistant' | 'data';
|
439
439
|
content: string;
|
440
440
|
toolInvocations?: ToolInvocation[];
|
441
441
|
experimental_attachments?: Attachment[];
|
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -236,25 +236,6 @@ var DownloadError = class extends AISDKError {
|
|
236
236
|
static isInstance(error) {
|
237
237
|
return AISDKError.hasMarker(error, marker);
|
238
238
|
}
|
239
|
-
/**
|
240
|
-
* @deprecated use `isInstance` instead
|
241
|
-
*/
|
242
|
-
static isDownloadError(error) {
|
243
|
-
return error instanceof Error && error.name === name && typeof error.url === "string" && (error.statusCode == null || typeof error.statusCode === "number") && (error.statusText == null || typeof error.statusText === "string");
|
244
|
-
}
|
245
|
-
/**
|
246
|
-
* @deprecated Do not use this method. It will be removed in the next major version.
|
247
|
-
*/
|
248
|
-
toJSON() {
|
249
|
-
return {
|
250
|
-
name: this.name,
|
251
|
-
message: this.message,
|
252
|
-
url: this.url,
|
253
|
-
statusCode: this.statusCode,
|
254
|
-
statusText: this.statusText,
|
255
|
-
cause: this.cause
|
256
|
-
};
|
257
|
-
}
|
258
239
|
};
|
259
240
|
_a = symbol;
|
260
241
|
|
@@ -327,24 +308,6 @@ var InvalidDataContentError = class extends AISDKError2 {
|
|
327
308
|
static isInstance(error) {
|
328
309
|
return AISDKError2.hasMarker(error, marker2);
|
329
310
|
}
|
330
|
-
/**
|
331
|
-
* @deprecated use `isInstance` instead
|
332
|
-
*/
|
333
|
-
static isInvalidDataContentError(error) {
|
334
|
-
return error instanceof Error && error.name === name2 && error.content != null;
|
335
|
-
}
|
336
|
-
/**
|
337
|
-
* @deprecated Do not use this method. It will be removed in the next major version.
|
338
|
-
*/
|
339
|
-
toJSON() {
|
340
|
-
return {
|
341
|
-
name: this.name,
|
342
|
-
message: this.message,
|
343
|
-
stack: this.stack,
|
344
|
-
cause: this.cause,
|
345
|
-
content: this.content
|
346
|
-
};
|
347
|
-
}
|
348
311
|
};
|
349
312
|
_a2 = symbol2;
|
350
313
|
|
@@ -418,23 +381,6 @@ var InvalidMessageRoleError = class extends AISDKError3 {
|
|
418
381
|
static isInstance(error) {
|
419
382
|
return AISDKError3.hasMarker(error, marker3);
|
420
383
|
}
|
421
|
-
/**
|
422
|
-
* @deprecated use `isInstance` instead
|
423
|
-
*/
|
424
|
-
static isInvalidMessageRoleError(error) {
|
425
|
-
return error instanceof Error && error.name === name3 && typeof error.role === "string";
|
426
|
-
}
|
427
|
-
/**
|
428
|
-
* @deprecated Do not use this method. It will be removed in the next major version.
|
429
|
-
*/
|
430
|
-
toJSON() {
|
431
|
-
return {
|
432
|
-
name: this.name,
|
433
|
-
message: this.message,
|
434
|
-
stack: this.stack,
|
435
|
-
role: this.role
|
436
|
-
};
|
437
|
-
}
|
438
384
|
};
|
439
385
|
_a3 = symbol3;
|
440
386
|
|
@@ -662,21 +608,6 @@ var InvalidArgumentError = class extends AISDKError4 {
|
|
662
608
|
static isInstance(error) {
|
663
609
|
return AISDKError4.hasMarker(error, marker4);
|
664
610
|
}
|
665
|
-
/**
|
666
|
-
* @deprecated use `isInstance` instead
|
667
|
-
*/
|
668
|
-
static isInvalidArgumentError(error) {
|
669
|
-
return error instanceof Error && error.name === name4 && typeof error.parameter === "string" && typeof error.value === "string";
|
670
|
-
}
|
671
|
-
toJSON() {
|
672
|
-
return {
|
673
|
-
name: this.name,
|
674
|
-
message: this.message,
|
675
|
-
stack: this.stack,
|
676
|
-
parameter: this.parameter,
|
677
|
-
value: this.value
|
678
|
-
};
|
679
|
-
}
|
680
611
|
};
|
681
612
|
_a4 = symbol4;
|
682
613
|
|
@@ -1161,9 +1092,7 @@ function convertToCoreMessages(messages, options) {
|
|
1161
1092
|
});
|
1162
1093
|
break;
|
1163
1094
|
}
|
1164
|
-
case "
|
1165
|
-
case "data":
|
1166
|
-
case "tool": {
|
1095
|
+
case "data": {
|
1167
1096
|
break;
|
1168
1097
|
}
|
1169
1098
|
default: {
|
@@ -1251,11 +1180,14 @@ function standardizePrompt({
|
|
1251
1180
|
}
|
1252
1181
|
|
1253
1182
|
// core/types/usage.ts
|
1254
|
-
function calculateLanguageModelUsage(
|
1183
|
+
function calculateLanguageModelUsage({
|
1184
|
+
promptTokens,
|
1185
|
+
completionTokens
|
1186
|
+
}) {
|
1255
1187
|
return {
|
1256
|
-
promptTokens
|
1257
|
-
completionTokens
|
1258
|
-
totalTokens:
|
1188
|
+
promptTokens,
|
1189
|
+
completionTokens,
|
1190
|
+
totalTokens: promptTokens + completionTokens
|
1259
1191
|
};
|
1260
1192
|
}
|
1261
1193
|
|
@@ -1282,25 +1214,6 @@ var InvalidToolArgumentsError = class extends AISDKError6 {
|
|
1282
1214
|
static isInstance(error) {
|
1283
1215
|
return AISDKError6.hasMarker(error, marker6);
|
1284
1216
|
}
|
1285
|
-
/**
|
1286
|
-
* @deprecated use `isInstance` instead
|
1287
|
-
*/
|
1288
|
-
static isInvalidToolArgumentsError(error) {
|
1289
|
-
return error instanceof Error && error.name === name6 && typeof error.toolName === "string" && typeof error.toolArgs === "string";
|
1290
|
-
}
|
1291
|
-
/**
|
1292
|
-
* @deprecated Do not use this method. It will be removed in the next major version.
|
1293
|
-
*/
|
1294
|
-
toJSON() {
|
1295
|
-
return {
|
1296
|
-
name: this.name,
|
1297
|
-
message: this.message,
|
1298
|
-
cause: this.cause,
|
1299
|
-
stack: this.stack,
|
1300
|
-
toolName: this.toolName,
|
1301
|
-
toolArgs: this.toolArgs
|
1302
|
-
};
|
1303
|
-
}
|
1304
1217
|
};
|
1305
1218
|
_a6 = symbol6;
|
1306
1219
|
|
@@ -1324,24 +1237,6 @@ var NoSuchToolError = class extends AISDKError7 {
|
|
1324
1237
|
static isInstance(error) {
|
1325
1238
|
return AISDKError7.hasMarker(error, marker7);
|
1326
1239
|
}
|
1327
|
-
/**
|
1328
|
-
* @deprecated use `isInstance` instead
|
1329
|
-
*/
|
1330
|
-
static isNoSuchToolError(error) {
|
1331
|
-
return error instanceof Error && error.name === name7 && "toolName" in error && error.toolName != void 0 && typeof error.name === "string";
|
1332
|
-
}
|
1333
|
-
/**
|
1334
|
-
* @deprecated Do not use this method. It will be removed in the next major version.
|
1335
|
-
*/
|
1336
|
-
toJSON() {
|
1337
|
-
return {
|
1338
|
-
name: this.name,
|
1339
|
-
message: this.message,
|
1340
|
-
stack: this.stack,
|
1341
|
-
toolName: this.toolName,
|
1342
|
-
availableTools: this.availableTools
|
1343
|
-
};
|
1344
|
-
}
|
1345
1240
|
};
|
1346
1241
|
_a7 = symbol7;
|
1347
1242
|
|
@@ -1385,24 +1280,6 @@ var RetryError = class extends AISDKError8 {
|
|
1385
1280
|
static isInstance(error) {
|
1386
1281
|
return AISDKError8.hasMarker(error, marker8);
|
1387
1282
|
}
|
1388
|
-
/**
|
1389
|
-
* @deprecated use `isInstance` instead
|
1390
|
-
*/
|
1391
|
-
static isRetryError(error) {
|
1392
|
-
return error instanceof Error && error.name === name8 && typeof error.reason === "string" && Array.isArray(error.errors);
|
1393
|
-
}
|
1394
|
-
/**
|
1395
|
-
* @deprecated Do not use this method. It will be removed in the next major version.
|
1396
|
-
*/
|
1397
|
-
toJSON() {
|
1398
|
-
return {
|
1399
|
-
name: this.name,
|
1400
|
-
message: this.message,
|
1401
|
-
reason: this.reason,
|
1402
|
-
lastError: this.lastError,
|
1403
|
-
errors: this.errors
|
1404
|
-
};
|
1405
|
-
}
|
1406
1283
|
};
|
1407
1284
|
_a8 = symbol8;
|
1408
1285
|
|
@@ -1440,7 +1317,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
1440
1317
|
errors: newErrors
|
1441
1318
|
});
|
1442
1319
|
}
|
1443
|
-
if (error instanceof Error && APICallError.
|
1320
|
+
if (error instanceof Error && APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
1444
1321
|
await delay(delayInMs);
|
1445
1322
|
return _retryWithExponentialBackoff(
|
1446
1323
|
f,
|