@posthog/ai 7.17.2 → 7.17.3

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
@@ -411,6 +411,31 @@ const formatResponseOpenAI = response => {
411
411
  }
412
412
  return output;
413
413
  };
414
+ const buildInlineDataBlock = (mimeType, data) => {
415
+ if (mimeType.startsWith('audio/')) {
416
+ return {
417
+ type: 'audio',
418
+ mime_type: mimeType,
419
+ data
420
+ };
421
+ }
422
+ if (mimeType.startsWith('image/')) {
423
+ return {
424
+ type: 'image',
425
+ inline_data: {
426
+ mime_type: mimeType,
427
+ data
428
+ }
429
+ };
430
+ }
431
+ return {
432
+ type: 'document',
433
+ inline_data: {
434
+ mime_type: mimeType,
435
+ data
436
+ }
437
+ };
438
+ };
414
439
  const formatResponseGemini = response => {
415
440
  const output = [];
416
441
  if (response.candidates && Array.isArray(response.candidates)) {
@@ -432,8 +457,8 @@ const formatResponseGemini = response => {
432
457
  }
433
458
  });
434
459
  } else if (part.inlineData) {
435
- // Handle audio/media inline data
436
- const mimeType = part.inlineData.mimeType || 'audio/pcm';
460
+ // Handle inline data (images, audio, documents)
461
+ const mimeType = part.inlineData.mimeType || part.inlineData.mime_type || 'application/octet-stream';
437
462
  let data = part.inlineData.data;
438
463
  // Handle binary data (Uint8Array/Buffer -> base64)
439
464
  if (data instanceof Uint8Array) {
@@ -449,11 +474,7 @@ const formatResponseGemini = response => {
449
474
  }
450
475
  // Sanitize base64 data for images and other large inline data
451
476
  data = redactBase64DataUrl(data);
452
- content.push({
453
- type: 'audio',
454
- mime_type: mimeType,
455
- data: data
456
- });
477
+ content.push(buildInlineDataBlock(mimeType, data));
457
478
  }
458
479
  }
459
480
  if (content.length > 0) {
@@ -756,7 +777,7 @@ function formatOpenAIResponsesInput(input, instructions) {
756
777
  return messages;
757
778
  }
758
779
 
759
- var version = "7.17.2";
780
+ var version = "7.17.3";
760
781
 
761
782
  /**
762
783
  * Capture an `$ai_generation` (or `$ai_embedding`) event to PostHog.
@@ -3160,15 +3181,8 @@ class WrappedModels {
3160
3181
  // Handle inlineData (images, audio, PDFs)
3161
3182
  else if (part && typeof part === 'object' && 'inlineData' in part) {
3162
3183
  const inlineData = part.inlineData;
3163
- const mimeType = inlineData.mimeType || inlineData.mime_type || '';
3164
- const contentType = mimeType.startsWith('image/') ? 'image' : 'document';
3165
- blocks.push({
3166
- type: contentType,
3167
- inline_data: {
3168
- data: inlineData.data,
3169
- mime_type: mimeType
3170
- }
3171
- });
3184
+ const mimeType = inlineData.mimeType || inlineData.mime_type || 'application/octet-stream';
3185
+ blocks.push(buildInlineDataBlock(mimeType, inlineData.data));
3172
3186
  }
3173
3187
  }
3174
3188
  return blocks;