ai 6.0.0-beta.99 → 6.0.1

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.
@@ -120,44 +120,19 @@ function detectMediaType({
120
120
  return void 0;
121
121
  }
122
122
 
123
- // src/util/download/download-error.ts
124
- import { AISDKError } from "@ai-sdk/provider";
125
- var name = "AI_DownloadError";
126
- var marker = `vercel.ai.error.${name}`;
127
- var symbol = Symbol.for(marker);
128
- var _a;
129
- var DownloadError = class extends AISDKError {
130
- constructor({
131
- url,
132
- statusCode,
133
- statusText,
134
- cause,
135
- message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
136
- }) {
137
- super({ name, message, cause });
138
- this[_a] = true;
139
- this.url = url;
140
- this.statusCode = statusCode;
141
- this.statusText = statusText;
142
- }
143
- static isInstance(error) {
144
- return AISDKError.hasMarker(error, marker);
145
- }
146
- };
147
- _a = symbol;
148
-
149
123
  // src/util/download/download.ts
124
+ import { DownloadError } from "@ai-sdk/provider-utils";
150
125
  import {
151
126
  withUserAgentSuffix,
152
127
  getRuntimeEnvironmentUserAgent
153
128
  } from "@ai-sdk/provider-utils";
154
129
 
155
130
  // src/version.ts
156
- var VERSION = true ? "6.0.0-beta.99" : "0.0.0-test";
131
+ var VERSION = true ? "6.0.1" : "0.0.0-test";
157
132
 
158
133
  // src/util/download/download.ts
159
134
  var download = async ({ url }) => {
160
- var _a5;
135
+ var _a4;
161
136
  const urlText = url.toString();
162
137
  try {
163
138
  const response = await fetch(urlText, {
@@ -176,7 +151,7 @@ var download = async ({ url }) => {
176
151
  }
177
152
  return {
178
153
  data: new Uint8Array(await response.arrayBuffer()),
179
- mediaType: (_a5 = response.headers.get("content-type")) != null ? _a5 : void 0
154
+ mediaType: (_a4 = response.headers.get("content-type")) != null ? _a4 : void 0
180
155
  };
181
156
  } catch (error) {
182
157
  if (DownloadError.isInstance(error)) {
@@ -194,7 +169,7 @@ var createDefaultDownloadFunction = (download2 = download) => (requestedDownload
194
169
  );
195
170
 
196
171
  // src/prompt/data-content.ts
197
- import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
172
+ import { AISDKError } from "@ai-sdk/provider";
198
173
  import {
199
174
  convertBase64ToUint8Array as convertBase64ToUint8Array2,
200
175
  convertUint8ArrayToBase64
@@ -225,8 +200,8 @@ var dataContentSchema = z.union([
225
200
  z.custom(
226
201
  // Buffer might not be available in some environments such as CloudFlare:
227
202
  (value) => {
228
- var _a5, _b;
229
- return (_b = (_a5 = globalThis.Buffer) == null ? void 0 : _a5.isBuffer(value)) != null ? _b : false;
203
+ var _a4, _b;
204
+ return (_b = (_a4 = globalThis.Buffer) == null ? void 0 : _a4.isBuffer(value)) != null ? _b : false;
230
205
  },
231
206
  { message: "Must be a Buffer" }
232
207
  )
@@ -249,7 +224,7 @@ function convertToLanguageModelV3DataContent(content) {
249
224
  content.toString()
250
225
  );
251
226
  if (dataUrlMediaType == null || base64Content == null) {
252
- throw new AISDKError2({
227
+ throw new AISDKError({
253
228
  name: "InvalidDataContentError",
254
229
  message: `Invalid data URL format in content ${content.toString()}`
255
230
  });
@@ -260,25 +235,30 @@ function convertToLanguageModelV3DataContent(content) {
260
235
  }
261
236
 
262
237
  // src/prompt/invalid-message-role-error.ts
263
- import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
264
- var name2 = "AI_InvalidMessageRoleError";
265
- var marker2 = `vercel.ai.error.${name2}`;
266
- var symbol2 = Symbol.for(marker2);
267
- var _a2;
268
- var InvalidMessageRoleError = class extends AISDKError3 {
238
+ import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
239
+ var name = "AI_InvalidMessageRoleError";
240
+ var marker = `vercel.ai.error.${name}`;
241
+ var symbol = Symbol.for(marker);
242
+ var _a;
243
+ var InvalidMessageRoleError = class extends AISDKError2 {
269
244
  constructor({
270
245
  role,
271
246
  message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
272
247
  }) {
273
- super({ name: name2, message });
274
- this[_a2] = true;
248
+ super({ name, message });
249
+ this[_a] = true;
275
250
  this.role = role;
276
251
  }
277
252
  static isInstance(error) {
278
- return AISDKError3.hasMarker(error, marker2);
253
+ return AISDKError2.hasMarker(error, marker);
279
254
  }
280
255
  };
281
- _a2 = symbol2;
256
+ _a = symbol;
257
+
258
+ // src/util/as-array.ts
259
+ function asArray(value) {
260
+ return value === void 0 ? [] : Array.isArray(value) ? value : [value];
261
+ }
282
262
 
283
263
  // src/prompt/convert-to-language-model-prompt.ts
284
264
  async function convertToLanguageModelPrompt({
@@ -292,7 +272,11 @@ async function convertToLanguageModelPrompt({
292
272
  supportedUrls
293
273
  );
294
274
  const messages = [
295
- ...prompt.system != null ? [{ role: "system", content: prompt.system }] : [],
275
+ ...prompt.system != null ? typeof prompt.system === "string" ? [{ role: "system", content: prompt.system }] : asArray(prompt.system).map((message) => ({
276
+ role: "system",
277
+ content: message.content,
278
+ providerOptions: message.providerOptions
279
+ })) : [],
296
280
  ...prompt.messages.map(
297
281
  (message) => convertToLanguageModelMessage({ message, downloadedAssets })
298
282
  )
@@ -432,8 +416,8 @@ async function downloadAssets(messages, download2, supportedUrls) {
432
416
  ).flat().filter(
433
417
  (part) => part.type === "image" || part.type === "file"
434
418
  ).map((part) => {
435
- var _a5;
436
- const mediaType = (_a5 = part.mediaType) != null ? _a5 : part.type === "image" ? "image/*" : void 0;
419
+ var _a4;
420
+ const mediaType = (_a4 = part.mediaType) != null ? _a4 : part.type === "image" ? "image/*" : void 0;
437
421
  let data = part.type === "image" ? part.image : part.data;
438
422
  if (typeof data === "string") {
439
423
  try {
@@ -463,7 +447,7 @@ async function downloadAssets(messages, download2, supportedUrls) {
463
447
  );
464
448
  }
465
449
  function convertPartToLanguageModelPart(part, downloadedAssets) {
466
- var _a5;
450
+ var _a4;
467
451
  if (part.type === "text") {
468
452
  return {
469
453
  type: "text",
@@ -496,7 +480,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
496
480
  switch (type) {
497
481
  case "image": {
498
482
  if (data instanceof Uint8Array || typeof data === "string") {
499
- mediaType = (_a5 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a5 : mediaType;
483
+ mediaType = (_a4 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a4 : mediaType;
500
484
  }
501
485
  return {
502
486
  type: "file",
@@ -568,10 +552,10 @@ async function prepareToolsAndToolChoice({
568
552
  };
569
553
  }
570
554
  const filteredTools = activeTools != null ? Object.entries(tools).filter(
571
- ([name5]) => activeTools.includes(name5)
555
+ ([name4]) => activeTools.includes(name4)
572
556
  ) : Object.entries(tools);
573
557
  const languageModelTools = [];
574
- for (const [name5, tool] of filteredTools) {
558
+ for (const [name4, tool] of filteredTools) {
575
559
  const toolType = tool.type;
576
560
  switch (toolType) {
577
561
  case void 0:
@@ -579,16 +563,18 @@ async function prepareToolsAndToolChoice({
579
563
  case "function":
580
564
  languageModelTools.push({
581
565
  type: "function",
582
- name: name5,
566
+ name: name4,
583
567
  description: tool.description,
584
568
  inputSchema: await asSchema(tool.inputSchema).jsonSchema,
585
- providerOptions: tool.providerOptions
569
+ ...tool.inputExamples != null ? { inputExamples: tool.inputExamples } : {},
570
+ providerOptions: tool.providerOptions,
571
+ ...tool.strict != null ? { strict: tool.strict } : {}
586
572
  });
587
573
  break;
588
- case "provider-defined":
574
+ case "provider":
589
575
  languageModelTools.push({
590
- type: "provider-defined",
591
- name: name5,
576
+ type: "provider",
577
+ name: name4,
592
578
  id: tool.id,
593
579
  args: tool.args
594
580
  });
@@ -607,7 +593,9 @@ async function prepareToolsAndToolChoice({
607
593
 
608
594
  // src/prompt/standardize-prompt.ts
609
595
  import { InvalidPromptError } from "@ai-sdk/provider";
610
- import { safeValidateTypes } from "@ai-sdk/provider-utils";
596
+ import {
597
+ safeValidateTypes
598
+ } from "@ai-sdk/provider-utils";
611
599
  import { z as z6 } from "zod/v4";
612
600
 
613
601
  // src/prompt/message.ts
@@ -830,10 +818,12 @@ async function standardizePrompt(prompt) {
830
818
  message: "prompt and messages cannot be defined at the same time"
831
819
  });
832
820
  }
833
- if (prompt.system != null && typeof prompt.system !== "string") {
821
+ if (prompt.system != null && typeof prompt.system !== "string" && !asArray(prompt.system).every(
822
+ (message) => typeof message === "object" && message !== null && "role" in message && message.role === "system"
823
+ )) {
834
824
  throw new InvalidPromptError({
835
825
  prompt,
836
- message: "system must be a string"
826
+ message: "system must be a string, SystemModelMessage, or array of SystemModelMessage"
837
827
  });
838
828
  }
839
829
  let messages;
@@ -862,7 +852,7 @@ async function standardizePrompt(prompt) {
862
852
  if (!validationResult.success) {
863
853
  throw new InvalidPromptError({
864
854
  prompt,
865
- message: "The messages must be a ModelMessage[]. If you have passed a UIMessage[], you can use convertToModelMessages to convert them.",
855
+ message: "The messages do not match the ModelMessage[] schema.",
866
856
  cause: validationResult.error
867
857
  });
868
858
  }
@@ -873,30 +863,30 @@ async function standardizePrompt(prompt) {
873
863
  }
874
864
 
875
865
  // src/error/invalid-argument-error.ts
876
- import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
877
- var name3 = "AI_InvalidArgumentError";
878
- var marker3 = `vercel.ai.error.${name3}`;
879
- var symbol3 = Symbol.for(marker3);
880
- var _a3;
881
- var InvalidArgumentError = class extends AISDKError4 {
866
+ import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
867
+ var name2 = "AI_InvalidArgumentError";
868
+ var marker2 = `vercel.ai.error.${name2}`;
869
+ var symbol2 = Symbol.for(marker2);
870
+ var _a2;
871
+ var InvalidArgumentError = class extends AISDKError3 {
882
872
  constructor({
883
873
  parameter,
884
874
  value,
885
875
  message
886
876
  }) {
887
877
  super({
888
- name: name3,
878
+ name: name2,
889
879
  message: `Invalid argument for parameter ${parameter}: ${message}`
890
880
  });
891
- this[_a3] = true;
881
+ this[_a2] = true;
892
882
  this.parameter = parameter;
893
883
  this.value = value;
894
884
  }
895
885
  static isInstance(error) {
896
- return AISDKError4.hasMarker(error, marker3);
886
+ return AISDKError3.hasMarker(error, marker2);
897
887
  }
898
888
  };
899
- _a3 = symbol3;
889
+ _a2 = symbol2;
900
890
 
901
891
  // src/prompt/prepare-call-settings.ts
902
892
  function prepareCallSettings({
@@ -996,28 +986,28 @@ import { APICallError } from "@ai-sdk/provider";
996
986
  import { delay, getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
997
987
 
998
988
  // src/util/retry-error.ts
999
- import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
1000
- var name4 = "AI_RetryError";
1001
- var marker4 = `vercel.ai.error.${name4}`;
1002
- var symbol4 = Symbol.for(marker4);
1003
- var _a4;
1004
- var RetryError = class extends AISDKError5 {
989
+ import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
990
+ var name3 = "AI_RetryError";
991
+ var marker3 = `vercel.ai.error.${name3}`;
992
+ var symbol3 = Symbol.for(marker3);
993
+ var _a3;
994
+ var RetryError = class extends AISDKError4 {
1005
995
  constructor({
1006
996
  message,
1007
997
  reason,
1008
998
  errors
1009
999
  }) {
1010
- super({ name: name4, message });
1011
- this[_a4] = true;
1000
+ super({ name: name3, message });
1001
+ this[_a3] = true;
1012
1002
  this.reason = reason;
1013
1003
  this.errors = errors;
1014
1004
  this.lastError = errors[errors.length - 1];
1015
1005
  }
1016
1006
  static isInstance(error) {
1017
- return AISDKError5.hasMarker(error, marker4);
1007
+ return AISDKError4.hasMarker(error, marker3);
1018
1008
  }
1019
1009
  };
1020
- _a4 = symbol4;
1010
+ _a3 = symbol3;
1021
1011
 
1022
1012
  // src/util/retry-with-exponential-backoff.ts
1023
1013
  function getRetryDelayInMs({
@@ -1145,7 +1135,35 @@ function prepareRetries({
1145
1135
  })
1146
1136
  };
1147
1137
  }
1138
+
1139
+ // src/types/usage.ts
1140
+ function asLanguageModelUsage(usage) {
1141
+ return {
1142
+ inputTokens: usage.inputTokens.total,
1143
+ inputTokenDetails: {
1144
+ noCacheTokens: usage.inputTokens.noCache,
1145
+ cacheReadTokens: usage.inputTokens.cacheRead,
1146
+ cacheWriteTokens: usage.inputTokens.cacheWrite
1147
+ },
1148
+ outputTokens: usage.outputTokens.total,
1149
+ outputTokenDetails: {
1150
+ textTokens: usage.outputTokens.text,
1151
+ reasoningTokens: usage.outputTokens.reasoning
1152
+ },
1153
+ totalTokens: addTokenCounts(
1154
+ usage.inputTokens.total,
1155
+ usage.outputTokens.total
1156
+ ),
1157
+ raw: usage.raw,
1158
+ reasoningTokens: usage.outputTokens.reasoning,
1159
+ cachedInputTokens: usage.inputTokens.cacheRead
1160
+ };
1161
+ }
1162
+ function addTokenCounts(tokenCount1, tokenCount2) {
1163
+ return tokenCount1 == null && tokenCount2 == null ? void 0 : (tokenCount1 != null ? tokenCount1 : 0) + (tokenCount2 != null ? tokenCount2 : 0);
1164
+ }
1148
1165
  export {
1166
+ asLanguageModelUsage,
1149
1167
  convertAsyncIteratorToReadableStream,
1150
1168
  convertToLanguageModelPrompt,
1151
1169
  prepareCallSettings,