ai 6.0.321 → 6.0.323

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.
@@ -144,7 +144,7 @@ import {
144
144
  } from "@ai-sdk/provider-utils";
145
145
 
146
146
  // src/version.ts
147
- var VERSION = true ? "6.0.321" : "0.0.0-test";
147
+ var VERSION = true ? "6.0.323" : "0.0.0-test";
148
148
 
149
149
  // src/util/download/download.ts
150
150
  var download = async ({
@@ -152,7 +152,7 @@ var download = async ({
152
152
  maxBytes,
153
153
  abortSignal
154
154
  }) => {
155
- var _a5;
155
+ var _a6;
156
156
  const urlText = url.toString();
157
157
  try {
158
158
  const headers = withUserAgentSuffix(
@@ -180,7 +180,7 @@ var download = async ({
180
180
  });
181
181
  return {
182
182
  data,
183
- mediaType: (_a5 = response.headers.get("content-type")) != null ? _a5 : void 0
183
+ mediaType: (_a6 = response.headers.get("content-type")) != null ? _a6 : void 0
184
184
  };
185
185
  } catch (error) {
186
186
  if (DownloadError.isInstance(error)) {
@@ -234,13 +234,37 @@ function mergeObjects(base, overrides) {
234
234
  }
235
235
 
236
236
  // src/prompt/data-content.ts
237
- import { AISDKError } from "@ai-sdk/provider";
237
+ import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
238
238
  import {
239
+ isUint8Array,
240
+ isArrayBuffer,
239
241
  convertBase64ToUint8Array as convertBase64ToUint8Array2,
240
242
  convertUint8ArrayToBase64
241
243
  } from "@ai-sdk/provider-utils";
242
244
  import { z } from "zod/v4";
243
245
 
246
+ // src/prompt/invalid-data-content-error.ts
247
+ import { AISDKError } from "@ai-sdk/provider";
248
+ var name = "AI_InvalidDataContentError";
249
+ var marker = `vercel.ai.error.${name}`;
250
+ var symbol = Symbol.for(marker);
251
+ var _a;
252
+ var InvalidDataContentError = class extends AISDKError {
253
+ constructor({
254
+ content,
255
+ cause,
256
+ message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
257
+ }) {
258
+ super({ name, message, cause });
259
+ this[_a] = true;
260
+ this.content = content;
261
+ }
262
+ static isInstance(error) {
263
+ return AISDKError.hasMarker(error, marker);
264
+ }
265
+ };
266
+ _a = symbol;
267
+
244
268
  // src/prompt/split-data-url.ts
245
269
  function splitDataUrl(dataUrl) {
246
270
  try {
@@ -260,23 +284,26 @@ function splitDataUrl(dataUrl) {
260
284
  // src/prompt/data-content.ts
261
285
  var dataContentSchema = z.union([
262
286
  z.string(),
263
- z.instanceof(Uint8Array),
264
- z.instanceof(ArrayBuffer),
287
+ z.custom(isUint8Array, { message: "Must be a Uint8Array" }),
288
+ z.custom(isArrayBuffer, { message: "Must be an ArrayBuffer" }),
265
289
  z.custom(
266
290
  // Buffer might not be available in some environments such as CloudFlare:
267
291
  (value) => {
268
- var _a5, _b;
269
- return (_b = (_a5 = globalThis.Buffer) == null ? void 0 : _a5.isBuffer(value)) != null ? _b : false;
292
+ var _a6, _b;
293
+ return (_b = (_a6 = globalThis.Buffer) == null ? void 0 : _a6.isBuffer(value)) != null ? _b : false;
270
294
  },
271
295
  { message: "Must be a Buffer" }
272
296
  )
273
297
  ]);
274
298
  function convertToLanguageModelV3DataContent(content) {
275
299
  let originalUrl;
276
- if (content instanceof Uint8Array) {
277
- return { data: content, mediaType: void 0 };
300
+ if (isUint8Array(content)) {
301
+ return {
302
+ data: convertDataContentToUint8Array(content),
303
+ mediaType: void 0
304
+ };
278
305
  }
279
- if (content instanceof ArrayBuffer) {
306
+ if (isArrayBuffer(content)) {
280
307
  return { data: new Uint8Array(content), mediaType: void 0 };
281
308
  }
282
309
  if (typeof content === "string") {
@@ -292,7 +319,7 @@ function convertToLanguageModelV3DataContent(content) {
292
319
  content.toString()
293
320
  );
294
321
  if (dataUrlMediaType == null || base64Content == null) {
295
- throw new AISDKError({
322
+ throw new AISDKError2({
296
323
  name: "InvalidDataContentError",
297
324
  message: `Invalid data URL format in content ${content.toString()}`
298
325
  });
@@ -309,32 +336,53 @@ function convertDataContentToBase64String(content) {
309
336
  if (typeof content === "string") {
310
337
  return content;
311
338
  }
312
- if (content instanceof ArrayBuffer) {
313
- return convertUint8ArrayToBase64(new Uint8Array(content));
339
+ return convertUint8ArrayToBase64(convertDataContentToUint8Array(content));
340
+ }
341
+ function convertDataContentToUint8Array(content) {
342
+ if (isUint8Array(content)) {
343
+ if (content instanceof Uint8Array) {
344
+ return content;
345
+ }
346
+ const { buffer, byteOffset, byteLength } = content;
347
+ return new Uint8Array(buffer, byteOffset, byteLength);
348
+ }
349
+ if (typeof content === "string") {
350
+ try {
351
+ return convertBase64ToUint8Array2(content);
352
+ } catch (error) {
353
+ throw new InvalidDataContentError({
354
+ message: "Invalid data content. Content string is not a base64-encoded media.",
355
+ content,
356
+ cause: error
357
+ });
358
+ }
359
+ }
360
+ if (isArrayBuffer(content)) {
361
+ return new Uint8Array(content);
314
362
  }
315
- return convertUint8ArrayToBase64(content);
363
+ throw new InvalidDataContentError({ content });
316
364
  }
317
365
 
318
366
  // src/prompt/invalid-message-role-error.ts
319
- import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
320
- var name = "AI_InvalidMessageRoleError";
321
- var marker = `vercel.ai.error.${name}`;
322
- var symbol = Symbol.for(marker);
323
- var _a;
324
- var InvalidMessageRoleError = class extends AISDKError2 {
367
+ import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
368
+ var name2 = "AI_InvalidMessageRoleError";
369
+ var marker2 = `vercel.ai.error.${name2}`;
370
+ var symbol2 = Symbol.for(marker2);
371
+ var _a2;
372
+ var InvalidMessageRoleError = class extends AISDKError3 {
325
373
  constructor({
326
374
  role,
327
375
  message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
328
376
  }) {
329
- super({ name, message });
330
- this[_a] = true;
377
+ super({ name: name2, message });
378
+ this[_a2] = true;
331
379
  this.role = role;
332
380
  }
333
381
  static isInstance(error) {
334
- return AISDKError2.hasMarker(error, marker);
382
+ return AISDKError3.hasMarker(error, marker2);
335
383
  }
336
384
  };
337
- _a = symbol;
385
+ _a2 = symbol2;
338
386
 
339
387
  // src/util/as-array.ts
340
388
  function asArray(value) {
@@ -342,27 +390,27 @@ function asArray(value) {
342
390
  }
343
391
 
344
392
  // src/error/missing-tool-result-error.ts
345
- import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
346
- var name2 = "AI_MissingToolResultsError";
347
- var marker2 = `vercel.ai.error.${name2}`;
348
- var symbol2 = Symbol.for(marker2);
349
- var _a2;
350
- var MissingToolResultsError = class extends AISDKError3 {
393
+ import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
394
+ var name3 = "AI_MissingToolResultsError";
395
+ var marker3 = `vercel.ai.error.${name3}`;
396
+ var symbol3 = Symbol.for(marker3);
397
+ var _a3;
398
+ var MissingToolResultsError = class extends AISDKError4 {
351
399
  constructor({ toolCallIds }) {
352
400
  super({
353
- name: name2,
401
+ name: name3,
354
402
  message: `Tool result${toolCallIds.length > 1 ? "s are" : " is"} missing for tool call${toolCallIds.length > 1 ? "s" : ""} ${toolCallIds.join(
355
403
  ", "
356
404
  )}.`
357
405
  });
358
- this[_a2] = true;
406
+ this[_a3] = true;
359
407
  this.toolCallIds = toolCallIds;
360
408
  }
361
409
  static isInstance(error) {
362
- return AISDKError3.hasMarker(error, marker2);
410
+ return AISDKError4.hasMarker(error, marker3);
363
411
  }
364
412
  };
365
- _a2 = symbol2;
413
+ _a3 = symbol3;
366
414
 
367
415
  // src/prompt/convert-to-language-model-prompt.ts
368
416
  async function convertToLanguageModelPrompt({
@@ -585,7 +633,7 @@ function convertToLanguageModelMessage({
585
633
  }
586
634
  }
587
635
  async function downloadAssets(messages, download2, supportedUrls) {
588
- var _a5;
636
+ var _a6;
589
637
  const downloadableFiles = [];
590
638
  for (const message of messages) {
591
639
  if (message.role === "user" && Array.isArray(message.content)) {
@@ -593,7 +641,7 @@ async function downloadAssets(messages, download2, supportedUrls) {
593
641
  if (part.type === "image" || part.type === "file") {
594
642
  downloadableFiles.push({
595
643
  data: part.type === "image" ? part.image : part.data,
596
- mediaType: (_a5 = part.mediaType) != null ? _a5 : part.type === "image" ? "image/*" : void 0
644
+ mediaType: (_a6 = part.mediaType) != null ? _a6 : part.type === "image" ? "image/*" : void 0
597
645
  });
598
646
  }
599
647
  }
@@ -645,7 +693,7 @@ async function downloadAssets(messages, download2, supportedUrls) {
645
693
  );
646
694
  }
647
695
  function convertPartToLanguageModelPart(part, downloadedAssets) {
648
- var _a5;
696
+ var _a6;
649
697
  if (part.type === "text") {
650
698
  return {
651
699
  type: "text",
@@ -682,7 +730,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
682
730
  switch (type) {
683
731
  case "image": {
684
732
  if (data instanceof Uint8Array || typeof data === "string") {
685
- mediaType = (_a5 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a5 : mediaType;
733
+ mediaType = (_a6 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a6 : mediaType;
686
734
  }
687
735
  return {
688
736
  type: "file",
@@ -719,14 +767,14 @@ function mapToolResultOutput({
719
767
  return {
720
768
  type: "content",
721
769
  value: output.value.map((item) => {
722
- var _a5, _b;
770
+ var _a6, _b;
723
771
  if (item.type === "image-url") {
724
772
  const downloadedFile = downloadedAssets[new URL(item.url).toString()];
725
773
  if (downloadedFile) {
726
774
  return {
727
775
  type: "image-data",
728
776
  data: convertDataContentToBase64String(downloadedFile.data),
729
- mediaType: (_a5 = downloadedFile.mediaType) != null ? _a5 : "image/*",
777
+ mediaType: (_a6 = downloadedFile.mediaType) != null ? _a6 : "image/*",
730
778
  providerOptions: item.providerOptions
731
779
  };
732
780
  }
@@ -784,10 +832,10 @@ async function prepareToolsAndToolChoice({
784
832
  };
785
833
  }
786
834
  const filteredTools = activeTools != null ? Object.entries(tools).filter(
787
- ([name5]) => activeTools.includes(name5)
835
+ ([name6]) => activeTools.includes(name6)
788
836
  ) : Object.entries(tools);
789
837
  const languageModelTools = [];
790
- for (const [name5, tool] of filteredTools) {
838
+ for (const [name6, tool] of filteredTools) {
791
839
  const toolType = tool.type;
792
840
  switch (toolType) {
793
841
  case void 0:
@@ -795,7 +843,7 @@ async function prepareToolsAndToolChoice({
795
843
  case "function":
796
844
  languageModelTools.push({
797
845
  type: "function",
798
- name: name5,
846
+ name: name6,
799
847
  description: tool.description,
800
848
  inputSchema: await asSchema(tool.inputSchema).jsonSchema,
801
849
  ...tool.inputExamples != null ? { inputExamples: tool.inputExamples } : {},
@@ -806,7 +854,7 @@ async function prepareToolsAndToolChoice({
806
854
  case "provider":
807
855
  languageModelTools.push({
808
856
  type: "provider",
809
- name: name5,
857
+ name: name6,
810
858
  id: tool.id,
811
859
  args: tool.args
812
860
  });
@@ -1108,30 +1156,30 @@ async function standardizePrompt({
1108
1156
  }
1109
1157
 
1110
1158
  // src/error/invalid-argument-error.ts
1111
- import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
1112
- var name3 = "AI_InvalidArgumentError";
1113
- var marker3 = `vercel.ai.error.${name3}`;
1114
- var symbol3 = Symbol.for(marker3);
1115
- var _a3;
1116
- var InvalidArgumentError = class extends AISDKError4 {
1159
+ import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
1160
+ var name4 = "AI_InvalidArgumentError";
1161
+ var marker4 = `vercel.ai.error.${name4}`;
1162
+ var symbol4 = Symbol.for(marker4);
1163
+ var _a4;
1164
+ var InvalidArgumentError = class extends AISDKError5 {
1117
1165
  constructor({
1118
1166
  parameter,
1119
1167
  value,
1120
1168
  message
1121
1169
  }) {
1122
1170
  super({
1123
- name: name3,
1171
+ name: name4,
1124
1172
  message: `Invalid argument for parameter ${parameter}: ${message}`
1125
1173
  });
1126
- this[_a3] = true;
1174
+ this[_a4] = true;
1127
1175
  this.parameter = parameter;
1128
1176
  this.value = value;
1129
1177
  }
1130
1178
  static isInstance(error) {
1131
- return AISDKError4.hasMarker(error, marker3);
1179
+ return AISDKError5.hasMarker(error, marker4);
1132
1180
  }
1133
1181
  };
1134
- _a3 = symbol3;
1182
+ _a4 = symbol4;
1135
1183
 
1136
1184
  // src/prompt/prepare-call-settings.ts
1137
1185
  function prepareCallSettings({
@@ -1234,28 +1282,28 @@ import {
1234
1282
  } from "@ai-sdk/provider-utils";
1235
1283
 
1236
1284
  // src/util/retry-error.ts
1237
- import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
1238
- var name4 = "AI_RetryError";
1239
- var marker4 = `vercel.ai.error.${name4}`;
1240
- var symbol4 = Symbol.for(marker4);
1241
- var _a4;
1242
- var RetryError = class extends AISDKError5 {
1285
+ import { AISDKError as AISDKError6 } from "@ai-sdk/provider";
1286
+ var name5 = "AI_RetryError";
1287
+ var marker5 = `vercel.ai.error.${name5}`;
1288
+ var symbol5 = Symbol.for(marker5);
1289
+ var _a5;
1290
+ var RetryError = class extends AISDKError6 {
1243
1291
  constructor({
1244
1292
  message,
1245
1293
  reason,
1246
1294
  errors
1247
1295
  }) {
1248
- super({ name: name4, message });
1249
- this[_a4] = true;
1296
+ super({ name: name5, message });
1297
+ this[_a5] = true;
1250
1298
  this.reason = reason;
1251
1299
  this.errors = errors;
1252
1300
  this.lastError = errors[errors.length - 1];
1253
1301
  }
1254
1302
  static isInstance(error) {
1255
- return AISDKError5.hasMarker(error, marker4);
1303
+ return AISDKError6.hasMarker(error, marker5);
1256
1304
  }
1257
1305
  };
1258
- _a4 = symbol4;
1306
+ _a5 = symbol5;
1259
1307
 
1260
1308
  // src/util/retry-with-exponential-backoff.ts
1261
1309
  function getRetryDelayInMs({