ai 3.1.34 → 3.1.35

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/dist/index.mjs CHANGED
@@ -239,6 +239,7 @@ var InvalidMessageRoleError = class extends Error {
239
239
  };
240
240
 
241
241
  // core/prompt/convert-to-language-model-prompt.ts
242
+ import { getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider-utils";
242
243
  function convertToLanguageModelPrompt(prompt) {
243
244
  const languageModelMessages = [];
244
245
  if (prompt.system != null) {
@@ -296,6 +297,47 @@ function convertToLanguageModelMessage(message) {
296
297
  mimeType: part.mimeType
297
298
  };
298
299
  }
300
+ if (typeof part.image === "string") {
301
+ try {
302
+ const url = new URL(part.image);
303
+ switch (url.protocol) {
304
+ case "http:":
305
+ case "https:": {
306
+ return {
307
+ type: "image",
308
+ image: url,
309
+ mimeType: part.mimeType
310
+ };
311
+ }
312
+ case "data:": {
313
+ try {
314
+ const [header, base64Content] = part.image.split(",");
315
+ const mimeType = header.split(";")[0].split(":")[1];
316
+ if (mimeType == null || base64Content == null) {
317
+ throw new Error("Invalid data URL format");
318
+ }
319
+ return {
320
+ type: "image",
321
+ image: convertDataContentToUint8Array(base64Content),
322
+ mimeType
323
+ };
324
+ } catch (error) {
325
+ throw new Error(
326
+ `Error processing data URL: ${getErrorMessage2(
327
+ message
328
+ )}`
329
+ );
330
+ }
331
+ }
332
+ default: {
333
+ throw new Error(
334
+ `Unsupported URL protocol: ${url.protocol}`
335
+ );
336
+ }
337
+ }
338
+ } catch (_ignored) {
339
+ }
340
+ }
299
341
  const imageUint8 = convertDataContentToUint8Array(part.image);
300
342
  return {
301
343
  type: "image",