ai 4.0.0-canary.1 → 4.0.0-canary.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "4.0.0-canary.1",
3
+ "version": "4.0.0-canary.11",
4
4
  "description": "AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -40,41 +40,30 @@
40
40
  }
41
41
  },
42
42
  "dependencies": {
43
- "@ai-sdk/provider": "0.0.26",
44
- "@ai-sdk/provider-utils": "1.0.22",
45
- "@ai-sdk/react": "1.0.0-canary.1",
46
- "@ai-sdk/ui-utils": "1.0.0-canary.1",
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",
47
47
  "@opentelemetry/api": "1.9.0",
48
- "eventsource-parser": "1.1.2",
49
48
  "jsondiffpatch": "0.6.0",
50
- "json-schema": "^0.4.0",
51
- "secure-json-parse": "^2.7.0",
52
49
  "zod-to-json-schema": "^3.23.3"
53
50
  },
54
51
  "devDependencies": {
55
52
  "@edge-runtime/vm": "^3.2.0",
56
- "@testing-library/jest-dom": "^6.4.5",
57
- "@testing-library/react": "^15.0.7",
58
- "@testing-library/user-event": "^14.5.1",
59
- "@types/json-schema": "7.0.15",
60
53
  "@types/node": "^18",
61
54
  "@types/react": "^18",
62
55
  "@types/react-dom": "^18",
63
- "@vitejs/plugin-react": "4.2.0",
64
- "eslint": "^7.32.0",
65
- "jsdom": "^24.0.0",
66
- "msw": "2.3.1",
67
- "openai": "4.52.6",
56
+ "@vitejs/plugin-react": "4.3.3",
57
+ "eslint": "8.57.1",
68
58
  "react-dom": "^18",
69
59
  "react-server-dom-webpack": "18.3.0-canary-eb33bd747-20240312",
70
60
  "tsup": "^7.2.0",
71
- "typescript": "5.5.4",
61
+ "typescript": "5.6.3",
72
62
  "zod": "3.23.8",
73
63
  "@vercel/ai-tsconfig": "0.0.0",
74
64
  "eslint-config-vercel-ai": "0.0.0"
75
65
  },
76
66
  "peerDependencies": {
77
- "openai": "^4.42.0",
78
67
  "react": "^18 || ^19 || ^19.0.0-rc",
79
68
  "zod": "^3.0.0"
80
69
  },
@@ -84,9 +73,6 @@
84
73
  },
85
74
  "zod": {
86
75
  "optional": true
87
- },
88
- "openai": {
89
- "optional": true
90
76
  }
91
77
  },
92
78
  "engines": {
@@ -111,9 +97,9 @@
111
97
  "nextjs"
112
98
  ],
113
99
  "scripts": {
114
- "build": "tsup && cat react/dist/index.server.d.ts >> react/dist/index.d.ts",
100
+ "build": "tsup",
101
+ "build:watch": "tsup --watch",
115
102
  "clean": "rm -rf dist && rm -rf react/dist && rm -rf rsc/dist",
116
- "dev": "tsup --watch",
117
103
  "lint": "eslint \"./**/*.ts*\"",
118
104
  "type-check": "tsc --noEmit",
119
105
  "prettier-check": "prettier --check \"./**/*.ts*\"",
@@ -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 };
@@ -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' | 'function' | 'data' | 'tool';
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' | 'function' | 'data' | 'tool';
438
+ role: 'system' | 'user' | 'assistant' | 'data';
439
439
  content: string;
440
440
  toolInvocations?: ToolInvocation[];
441
441
  experimental_attachments?: Attachment[];
@@ -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 "function":
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(usage) {
1183
+ function calculateLanguageModelUsage({
1184
+ promptTokens,
1185
+ completionTokens
1186
+ }) {
1255
1187
  return {
1256
- promptTokens: usage.promptTokens,
1257
- completionTokens: usage.completionTokens,
1258
- totalTokens: usage.promptTokens + usage.completionTokens
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.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
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,