ai 3.0.16 → 3.0.18

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
@@ -351,6 +351,22 @@ function calculateTokenUsage(usage) {
351
351
  };
352
352
  }
353
353
 
354
+ // core/util/detect-image-mimetype.ts
355
+ var mimeTypeSignatures = [
356
+ { mimeType: "image/gif", bytes: [71, 73, 70] },
357
+ { mimeType: "image/png", bytes: [137, 80, 78, 71] },
358
+ { mimeType: "image/jpeg", bytes: [255, 216] },
359
+ { mimeType: "image/webp", bytes: [82, 73, 70, 70] }
360
+ ];
361
+ function detectImageMimeType(image) {
362
+ for (const { bytes, mimeType } of mimeTypeSignatures) {
363
+ if (image.length >= bytes.length && bytes.every((byte, index) => image[index] === byte)) {
364
+ return mimeType;
365
+ }
366
+ }
367
+ return void 0;
368
+ }
369
+
354
370
  // core/prompt/data-content.ts
355
371
  function convertDataContentToBase64String(content) {
356
372
  if (typeof content === "string") {
@@ -403,15 +419,26 @@ function convertToLanguageModelPrompt(prompt2) {
403
419
  role: "user",
404
420
  content: message.content.map(
405
421
  (part) => {
422
+ var _a;
406
423
  switch (part.type) {
407
424
  case "text": {
408
425
  return part;
409
426
  }
410
427
  case "image": {
428
+ if (part.image instanceof URL) {
429
+ return {
430
+ type: "image",
431
+ image: part.image,
432
+ mimeType: part.mimeType
433
+ };
434
+ }
435
+ const imageUint8 = convertDataContentToUint8Array(
436
+ part.image
437
+ );
411
438
  return {
412
439
  type: "image",
413
- image: part.image instanceof URL ? part.image : convertDataContentToUint8Array(part.image),
414
- mimeType: part.mimeType
440
+ image: imageUint8,
441
+ mimeType: (_a = part.mimeType) != null ? _a : detectImageMimeType(imageUint8)
415
442
  };
416
443
  }
417
444
  }