ai 5.0.0-canary.14 → 5.0.0-canary.15

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.
@@ -1,7 +1,7 @@
1
- import { SharedV2ProviderOptions, LanguageModelV2Source, LanguageModelV2Usage, LanguageModelV2FinishReason, JSONValue as JSONValue$1, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice, LanguageModelV2Prompt } from '@ai-sdk/provider';
1
+ import * as _ai_sdk_provider from '@ai-sdk/provider';
2
+ import { SharedV2ProviderOptions, JSONValue as JSONValue$1, LanguageModelV2Source, LanguageModelV2Usage, LanguageModelV2FinishReason, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice, LanguageModelV2Prompt } from '@ai-sdk/provider';
2
3
  import { z } from 'zod';
3
- import { ToolCall, ToolResult, Validator } from '@ai-sdk/provider-utils';
4
- import { JSONSchema7 } from 'json-schema';
4
+ import { ToolCall, ToolResult, Schema } from '@ai-sdk/provider-utils';
5
5
 
6
6
  type ToolResultContent = Array<{
7
7
  type: 'text';
@@ -255,6 +255,8 @@ It can be a user message, an assistant message, or a tool message.
255
255
  */
256
256
  type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
257
257
 
258
+ type JSONValue = JSONValue$1;
259
+
258
260
  /**
259
261
  A source that has been used as input to generate the response.
260
262
  */
@@ -272,25 +274,6 @@ type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'requ
272
274
  toolName: Extract<keyof TOOLS, string>;
273
275
  };
274
276
 
275
- /**
276
- Represents the number of tokens used in a prompt and completion.
277
- */
278
- type LanguageModelUsage = {
279
- /**
280
- The number of tokens used in the prompt.
281
- */
282
- promptTokens: number;
283
- /**
284
- The number of tokens used in the completion.
285
- */
286
- completionTokens: number;
287
- /**
288
- The total number of tokens used (promptTokens + completionTokens).
289
- */
290
- totalTokens: number;
291
- };
292
- declare function calculateLanguageModelUsage({ inputTokens, outputTokens, }: LanguageModelV2Usage): LanguageModelUsage;
293
-
294
277
  /**
295
278
  Tool invocations are either tool calls or tool results. For each assistant tool call,
296
279
  there is one tool invocation. While the call is in progress, the invocation is a tool call.
@@ -345,12 +328,6 @@ interface Message {
345
328
  */
346
329
  content: string;
347
330
  /**
348
- Reasoning for the message.
349
-
350
- @deprecated Use `parts` instead.
351
- */
352
- reasoning?: string;
353
- /**
354
331
  * Additional attachments to be sent along with the message.
355
332
  */
356
333
  experimental_attachments?: Attachment[];
@@ -359,15 +336,9 @@ interface Message {
359
336
  */
360
337
  role: 'system' | 'user' | 'assistant' | 'data';
361
338
  /**
362
- For data messages.
363
-
364
- @deprecated Data messages will be removed.
365
- */
366
- data?: JSONValue;
367
- /**
368
339
  * Additional message-specific information added on the server via StreamData
369
340
  */
370
- annotations?: JSONValue[] | undefined;
341
+ annotations?: JSONValue$1[] | undefined;
371
342
  /**
372
343
  Tool invocations (that can be tool calls or tool results, depending on whether or not the invocation has finished)
373
344
  that the assistant made as part of this message.
@@ -449,13 +420,25 @@ type FileUIPart = {
449
420
  type StepStartUIPart = {
450
421
  type: 'step-start';
451
422
  };
423
+
452
424
  /**
453
- A JSON value can be a string, number, boolean, object, array, or null.
454
- JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
425
+ Represents the number of tokens used in a prompt and completion.
455
426
  */
456
- type JSONValue = null | string | number | boolean | {
457
- [value: string]: JSONValue;
458
- } | Array<JSONValue>;
427
+ type LanguageModelUsage = {
428
+ /**
429
+ The number of tokens used in the prompt.
430
+ */
431
+ promptTokens: number;
432
+ /**
433
+ The number of tokens used in the completion.
434
+ */
435
+ completionTokens: number;
436
+ /**
437
+ The total number of tokens used (promptTokens + completionTokens).
438
+ */
439
+ totalTokens: number;
440
+ };
441
+ declare function calculateLanguageModelUsage({ inputTokens, outputTokens, }: LanguageModelV2Usage): LanguageModelUsage;
459
442
 
460
443
  type DataStreamString = `${(typeof DataStreamStringPrefixes)[keyof typeof DataStreamStringPrefixes]}:${string}\n`;
461
444
  interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
@@ -466,7 +449,7 @@ interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
466
449
  value: TYPE;
467
450
  };
468
451
  }
469
- declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "toolName" | "args">>, DataStreamPart<"b", "tool_call_streaming_start", {
452
+ declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "toolName" | "args">>, DataStreamPart<"b", "tool_call_streaming_start", {
470
453
  toolCallId: string;
471
454
  toolName: string;
472
455
  }>, DataStreamPart<"c", "tool_call_delta", {
@@ -532,25 +515,6 @@ It ensures type-safety for the part type and value.
532
515
  */
533
516
  declare function formatDataStreamPart<T extends keyof DataStreamPartValueType>(type: T, value: DataStreamPartValueType[T]): DataStreamString;
534
517
 
535
- /**
536
- * Used to mark schemas so we can support both Zod and custom schemas.
537
- */
538
- declare const schemaSymbol: unique symbol;
539
- type Schema<OBJECT = unknown> = Validator<OBJECT> & {
540
- /**
541
- * Used to mark schemas so we can support both Zod and custom schemas.
542
- */
543
- [schemaSymbol]: true;
544
- /**
545
- * Schema type for inference.
546
- */
547
- _type: OBJECT;
548
- /**
549
- * The JSON Schema for the schema. It is passed to the providers.
550
- */
551
- readonly jsonSchema: JSONSchema7;
552
- };
553
-
554
518
  type ToolParameters<T = JSONObject> = z.Schema<T> | Schema<T>;
555
519
  interface ToolExecutionOptions {
556
520
  /**
@@ -1,7 +1,7 @@
1
- import { SharedV2ProviderOptions, LanguageModelV2Source, LanguageModelV2Usage, LanguageModelV2FinishReason, JSONValue as JSONValue$1, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice, LanguageModelV2Prompt } from '@ai-sdk/provider';
1
+ import * as _ai_sdk_provider from '@ai-sdk/provider';
2
+ import { SharedV2ProviderOptions, JSONValue as JSONValue$1, LanguageModelV2Source, LanguageModelV2Usage, LanguageModelV2FinishReason, JSONObject, LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice, LanguageModelV2Prompt } from '@ai-sdk/provider';
2
3
  import { z } from 'zod';
3
- import { ToolCall, ToolResult, Validator } from '@ai-sdk/provider-utils';
4
- import { JSONSchema7 } from 'json-schema';
4
+ import { ToolCall, ToolResult, Schema } from '@ai-sdk/provider-utils';
5
5
 
6
6
  type ToolResultContent = Array<{
7
7
  type: 'text';
@@ -255,6 +255,8 @@ It can be a user message, an assistant message, or a tool message.
255
255
  */
256
256
  type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage;
257
257
 
258
+ type JSONValue = JSONValue$1;
259
+
258
260
  /**
259
261
  A source that has been used as input to generate the response.
260
262
  */
@@ -272,25 +274,6 @@ type ToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'requ
272
274
  toolName: Extract<keyof TOOLS, string>;
273
275
  };
274
276
 
275
- /**
276
- Represents the number of tokens used in a prompt and completion.
277
- */
278
- type LanguageModelUsage = {
279
- /**
280
- The number of tokens used in the prompt.
281
- */
282
- promptTokens: number;
283
- /**
284
- The number of tokens used in the completion.
285
- */
286
- completionTokens: number;
287
- /**
288
- The total number of tokens used (promptTokens + completionTokens).
289
- */
290
- totalTokens: number;
291
- };
292
- declare function calculateLanguageModelUsage({ inputTokens, outputTokens, }: LanguageModelV2Usage): LanguageModelUsage;
293
-
294
277
  /**
295
278
  Tool invocations are either tool calls or tool results. For each assistant tool call,
296
279
  there is one tool invocation. While the call is in progress, the invocation is a tool call.
@@ -345,12 +328,6 @@ interface Message {
345
328
  */
346
329
  content: string;
347
330
  /**
348
- Reasoning for the message.
349
-
350
- @deprecated Use `parts` instead.
351
- */
352
- reasoning?: string;
353
- /**
354
331
  * Additional attachments to be sent along with the message.
355
332
  */
356
333
  experimental_attachments?: Attachment[];
@@ -359,15 +336,9 @@ interface Message {
359
336
  */
360
337
  role: 'system' | 'user' | 'assistant' | 'data';
361
338
  /**
362
- For data messages.
363
-
364
- @deprecated Data messages will be removed.
365
- */
366
- data?: JSONValue;
367
- /**
368
339
  * Additional message-specific information added on the server via StreamData
369
340
  */
370
- annotations?: JSONValue[] | undefined;
341
+ annotations?: JSONValue$1[] | undefined;
371
342
  /**
372
343
  Tool invocations (that can be tool calls or tool results, depending on whether or not the invocation has finished)
373
344
  that the assistant made as part of this message.
@@ -449,13 +420,25 @@ type FileUIPart = {
449
420
  type StepStartUIPart = {
450
421
  type: 'step-start';
451
422
  };
423
+
452
424
  /**
453
- A JSON value can be a string, number, boolean, object, array, or null.
454
- JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods.
425
+ Represents the number of tokens used in a prompt and completion.
455
426
  */
456
- type JSONValue = null | string | number | boolean | {
457
- [value: string]: JSONValue;
458
- } | Array<JSONValue>;
427
+ type LanguageModelUsage = {
428
+ /**
429
+ The number of tokens used in the prompt.
430
+ */
431
+ promptTokens: number;
432
+ /**
433
+ The number of tokens used in the completion.
434
+ */
435
+ completionTokens: number;
436
+ /**
437
+ The total number of tokens used (promptTokens + completionTokens).
438
+ */
439
+ totalTokens: number;
440
+ };
441
+ declare function calculateLanguageModelUsage({ inputTokens, outputTokens, }: LanguageModelV2Usage): LanguageModelUsage;
459
442
 
460
443
  type DataStreamString = `${(typeof DataStreamStringPrefixes)[keyof typeof DataStreamStringPrefixes]}:${string}\n`;
461
444
  interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
@@ -466,7 +449,7 @@ interface DataStreamPart<CODE extends string, NAME extends string, TYPE> {
466
449
  value: TYPE;
467
450
  };
468
451
  }
469
- declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "toolName" | "args">>, DataStreamPart<"b", "tool_call_streaming_start", {
452
+ declare const dataStreamParts: readonly [DataStreamPart<"0", "text", string>, DataStreamPart<"2", "data", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"3", "error", string>, DataStreamPart<"8", "message_annotations", _ai_sdk_provider.JSONValue[]>, DataStreamPart<"9", "tool_call", ToolCall<string, any>>, DataStreamPart<"a", "tool_result", Omit<ToolResult<string, any, any>, "toolName" | "args">>, DataStreamPart<"b", "tool_call_streaming_start", {
470
453
  toolCallId: string;
471
454
  toolName: string;
472
455
  }>, DataStreamPart<"c", "tool_call_delta", {
@@ -532,25 +515,6 @@ It ensures type-safety for the part type and value.
532
515
  */
533
516
  declare function formatDataStreamPart<T extends keyof DataStreamPartValueType>(type: T, value: DataStreamPartValueType[T]): DataStreamString;
534
517
 
535
- /**
536
- * Used to mark schemas so we can support both Zod and custom schemas.
537
- */
538
- declare const schemaSymbol: unique symbol;
539
- type Schema<OBJECT = unknown> = Validator<OBJECT> & {
540
- /**
541
- * Used to mark schemas so we can support both Zod and custom schemas.
542
- */
543
- [schemaSymbol]: true;
544
- /**
545
- * Schema type for inference.
546
- */
547
- _type: OBJECT;
548
- /**
549
- * The JSON Schema for the schema. It is passed to the providers.
550
- */
551
- readonly jsonSchema: JSONSchema7;
552
- };
553
-
554
518
  type ToolParameters<T = JSONObject> = z.Schema<T> | Schema<T>;
555
519
  interface ToolExecutionOptions {
556
520
  /**
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name7 in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // internal/index.ts
@@ -728,7 +718,7 @@ async function standardizePrompt({
728
718
  }
729
719
 
730
720
  // core/util/index.ts
731
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
721
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
732
722
 
733
723
  // core/util/data-stream-parts.ts
734
724
  var textStreamPart = {
@@ -986,53 +976,6 @@ function formatDataStreamPart(type, value) {
986
976
  `;
987
977
  }
988
978
 
989
- // core/util/schema.ts
990
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
991
-
992
- // core/util/zod-schema.ts
993
- var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
994
- function zodSchema(zodSchema2, options) {
995
- var _a7;
996
- const useReferences = (_a7 = options == null ? void 0 : options.useReferences) != null ? _a7 : false;
997
- return jsonSchema(
998
- (0, import_zod_to_json_schema.default)(zodSchema2, {
999
- $refStrategy: useReferences ? "root" : "none",
1000
- target: "jsonSchema7"
1001
- // note: openai mode breaks various gemini conversions
1002
- }),
1003
- {
1004
- validate: (value) => {
1005
- const result = zodSchema2.safeParse(value);
1006
- return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
1007
- }
1008
- }
1009
- );
1010
- }
1011
-
1012
- // core/util/schema.ts
1013
- var schemaSymbol = Symbol.for("vercel.ai.schema");
1014
- function jsonSchema(jsonSchema2, {
1015
- validate
1016
- } = {}) {
1017
- return {
1018
- [schemaSymbol]: true,
1019
- _type: void 0,
1020
- // should never be used directly
1021
- [import_provider_utils3.validatorSymbol]: true,
1022
- jsonSchema: jsonSchema2,
1023
- validate
1024
- };
1025
- }
1026
- function isSchema(value) {
1027
- return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
1028
- }
1029
- function asSchema(schema) {
1030
- return schema == null ? jsonSchema({
1031
- properties: {},
1032
- additionalProperties: false
1033
- }) : isSchema(schema) ? schema : zodSchema(schema);
1034
- }
1035
-
1036
979
  // core/util/is-non-empty-object.ts
1037
980
  function isNonEmptyObject(object) {
1038
981
  return object != null && Object.keys(object).length > 0;
@@ -1063,7 +1006,7 @@ function prepareToolsAndToolChoice({
1063
1006
  type: "function",
1064
1007
  name: name7,
1065
1008
  description: tool.description,
1066
- parameters: asSchema(tool.parameters).jsonSchema
1009
+ parameters: (0, import_provider_utils3.asSchema)(tool.parameters).jsonSchema
1067
1010
  };
1068
1011
  case "provider-defined":
1069
1012
  return {
@@ -1110,7 +1053,7 @@ _a3 = symbol3;
1110
1053
 
1111
1054
  // util/retry-with-exponential-backoff.ts
1112
1055
  var import_provider7 = require("@ai-sdk/provider");
1113
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
1056
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
1114
1057
 
1115
1058
  // util/retry-error.ts
1116
1059
  var import_provider6 = require("@ai-sdk/provider");
@@ -1154,13 +1097,13 @@ async function _retryWithExponentialBackoff(f, {
1154
1097
  try {
1155
1098
  return await f();
1156
1099
  } catch (error) {
1157
- if ((0, import_provider_utils5.isAbortError)(error)) {
1100
+ if ((0, import_provider_utils4.isAbortError)(error)) {
1158
1101
  throw error;
1159
1102
  }
1160
1103
  if (maxRetries === 0) {
1161
1104
  throw error;
1162
1105
  }
1163
- const errorMessage = (0, import_provider_utils5.getErrorMessage)(error);
1106
+ const errorMessage = (0, import_provider_utils4.getErrorMessage)(error);
1164
1107
  const newErrors = [...errors, error];
1165
1108
  const tryNumber = newErrors.length;
1166
1109
  if (tryNumber > maxRetries) {
@@ -1171,7 +1114,7 @@ async function _retryWithExponentialBackoff(f, {
1171
1114
  });
1172
1115
  }
1173
1116
  if (error instanceof Error && import_provider7.APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
1174
- await (0, import_provider_utils5.delay)(delayInMs);
1117
+ await (0, import_provider_utils4.delay)(delayInMs);
1175
1118
  return _retryWithExponentialBackoff(
1176
1119
  f,
1177
1120
  { maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
@@ -1361,7 +1304,7 @@ async function download({ url }) {
1361
1304
  }
1362
1305
 
1363
1306
  // core/util/detect-media-type.ts
1364
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
1307
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
1365
1308
  var imageMediaTypeSignatures = [
1366
1309
  {
1367
1310
  mediaType: "image/gif",
@@ -1436,7 +1379,7 @@ var imageMediaTypeSignatures = [
1436
1379
  }
1437
1380
  ];
1438
1381
  var stripID3 = (data) => {
1439
- const bytes = typeof data === "string" ? (0, import_provider_utils6.convertBase64ToUint8Array)(data) : data;
1382
+ const bytes = typeof data === "string" ? (0, import_provider_utils5.convertBase64ToUint8Array)(data) : data;
1440
1383
  const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
1441
1384
  return bytes.slice(id3Size + 10);
1442
1385
  };
@@ -1483,7 +1426,7 @@ var InvalidMessageRoleError = class extends import_provider9.AISDKError {
1483
1426
  _a6 = symbol6;
1484
1427
 
1485
1428
  // core/prompt/convert-to-language-model-prompt.ts
1486
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
1429
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
1487
1430
  async function convertToLanguageModelPrompt({
1488
1431
  prompt,
1489
1432
  supportedUrls,
@@ -1620,7 +1563,7 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
1620
1563
  }
1621
1564
  return { mediaType, data };
1622
1565
  }).filter(
1623
- (part) => part.data instanceof URL && part.mediaType != null && !(0, import_provider_utils7.isUrlSupported)({
1566
+ (part) => part.data instanceof URL && part.mediaType != null && !(0, import_provider_utils6.isUrlSupported)({
1624
1567
  url: part.data.toString(),
1625
1568
  mediaType: part.mediaType,
1626
1569
  supportedUrls