ai 5.0.0-canary.13 → 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
  /**
@@ -643,11 +607,6 @@ type Prompt = {
643
607
  };
644
608
 
645
609
  type StandardizedPrompt = {
646
- /**
647
- * Original prompt type. This is forwarded to the providers and can be used
648
- * to write send raw text to providers that support it.
649
- */
650
- type: 'prompt' | 'messages';
651
610
  /**
652
611
  * System message.
653
612
  */
@@ -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
  /**
@@ -643,11 +607,6 @@ type Prompt = {
643
607
  };
644
608
 
645
609
  type StandardizedPrompt = {
646
- /**
647
- * Original prompt type. This is forwarded to the providers and can be used
648
- * to write send raw text to providers that support it.
649
- */
650
- type: 'prompt' | 'messages';
651
610
  /**
652
611
  * System message.
653
612
  */
@@ -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
@@ -682,7 +672,6 @@ async function standardizePrompt({
682
672
  });
683
673
  }
684
674
  return {
685
- type: "prompt",
686
675
  system: prompt.system,
687
676
  messages: [
688
677
  {
@@ -721,7 +710,6 @@ async function standardizePrompt({
721
710
  });
722
711
  }
723
712
  return {
724
- type: "messages",
725
713
  messages,
726
714
  system: prompt.system
727
715
  };
@@ -730,7 +718,7 @@ async function standardizePrompt({
730
718
  }
731
719
 
732
720
  // core/util/index.ts
733
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
721
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
734
722
 
735
723
  // core/util/data-stream-parts.ts
736
724
  var textStreamPart = {
@@ -988,53 +976,6 @@ function formatDataStreamPart(type, value) {
988
976
  `;
989
977
  }
990
978
 
991
- // core/util/schema.ts
992
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
993
-
994
- // core/util/zod-schema.ts
995
- var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
996
- function zodSchema(zodSchema2, options) {
997
- var _a7;
998
- const useReferences = (_a7 = options == null ? void 0 : options.useReferences) != null ? _a7 : false;
999
- return jsonSchema(
1000
- (0, import_zod_to_json_schema.default)(zodSchema2, {
1001
- $refStrategy: useReferences ? "root" : "none",
1002
- target: "jsonSchema7"
1003
- // note: openai mode breaks various gemini conversions
1004
- }),
1005
- {
1006
- validate: (value) => {
1007
- const result = zodSchema2.safeParse(value);
1008
- return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
1009
- }
1010
- }
1011
- );
1012
- }
1013
-
1014
- // core/util/schema.ts
1015
- var schemaSymbol = Symbol.for("vercel.ai.schema");
1016
- function jsonSchema(jsonSchema2, {
1017
- validate
1018
- } = {}) {
1019
- return {
1020
- [schemaSymbol]: true,
1021
- _type: void 0,
1022
- // should never be used directly
1023
- [import_provider_utils3.validatorSymbol]: true,
1024
- jsonSchema: jsonSchema2,
1025
- validate
1026
- };
1027
- }
1028
- function isSchema(value) {
1029
- return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
1030
- }
1031
- function asSchema(schema) {
1032
- return schema == null ? jsonSchema({
1033
- properties: {},
1034
- additionalProperties: false
1035
- }) : isSchema(schema) ? schema : zodSchema(schema);
1036
- }
1037
-
1038
979
  // core/util/is-non-empty-object.ts
1039
980
  function isNonEmptyObject(object) {
1040
981
  return object != null && Object.keys(object).length > 0;
@@ -1065,7 +1006,7 @@ function prepareToolsAndToolChoice({
1065
1006
  type: "function",
1066
1007
  name: name7,
1067
1008
  description: tool.description,
1068
- parameters: asSchema(tool.parameters).jsonSchema
1009
+ parameters: (0, import_provider_utils3.asSchema)(tool.parameters).jsonSchema
1069
1010
  };
1070
1011
  case "provider-defined":
1071
1012
  return {
@@ -1112,7 +1053,7 @@ _a3 = symbol3;
1112
1053
 
1113
1054
  // util/retry-with-exponential-backoff.ts
1114
1055
  var import_provider7 = require("@ai-sdk/provider");
1115
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
1056
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
1116
1057
 
1117
1058
  // util/retry-error.ts
1118
1059
  var import_provider6 = require("@ai-sdk/provider");
@@ -1156,13 +1097,13 @@ async function _retryWithExponentialBackoff(f, {
1156
1097
  try {
1157
1098
  return await f();
1158
1099
  } catch (error) {
1159
- if ((0, import_provider_utils5.isAbortError)(error)) {
1100
+ if ((0, import_provider_utils4.isAbortError)(error)) {
1160
1101
  throw error;
1161
1102
  }
1162
1103
  if (maxRetries === 0) {
1163
1104
  throw error;
1164
1105
  }
1165
- const errorMessage = (0, import_provider_utils5.getErrorMessage)(error);
1106
+ const errorMessage = (0, import_provider_utils4.getErrorMessage)(error);
1166
1107
  const newErrors = [...errors, error];
1167
1108
  const tryNumber = newErrors.length;
1168
1109
  if (tryNumber > maxRetries) {
@@ -1173,7 +1114,7 @@ async function _retryWithExponentialBackoff(f, {
1173
1114
  });
1174
1115
  }
1175
1116
  if (error instanceof Error && import_provider7.APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
1176
- await (0, import_provider_utils5.delay)(delayInMs);
1117
+ await (0, import_provider_utils4.delay)(delayInMs);
1177
1118
  return _retryWithExponentialBackoff(
1178
1119
  f,
1179
1120
  { maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
@@ -1363,7 +1304,7 @@ async function download({ url }) {
1363
1304
  }
1364
1305
 
1365
1306
  // core/util/detect-media-type.ts
1366
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
1307
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
1367
1308
  var imageMediaTypeSignatures = [
1368
1309
  {
1369
1310
  mediaType: "image/gif",
@@ -1438,7 +1379,7 @@ var imageMediaTypeSignatures = [
1438
1379
  }
1439
1380
  ];
1440
1381
  var stripID3 = (data) => {
1441
- 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;
1442
1383
  const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
1443
1384
  return bytes.slice(id3Size + 10);
1444
1385
  };
@@ -1485,7 +1426,7 @@ var InvalidMessageRoleError = class extends import_provider9.AISDKError {
1485
1426
  _a6 = symbol6;
1486
1427
 
1487
1428
  // core/prompt/convert-to-language-model-prompt.ts
1488
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
1429
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
1489
1430
  async function convertToLanguageModelPrompt({
1490
1431
  prompt,
1491
1432
  supportedUrls,
@@ -1622,7 +1563,7 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
1622
1563
  }
1623
1564
  return { mediaType, data };
1624
1565
  }).filter(
1625
- (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)({
1626
1567
  url: part.data.toString(),
1627
1568
  mediaType: part.mediaType,
1628
1569
  supportedUrls