diff --git a/js/plugins/compat-oai/src/model.ts b/js/plugins/compat-oai/src/model.ts index d2ce7cce99..b3567fb51e 100644 --- a/js/plugins/compat-oai/src/model.ts +++ b/js/plugins/compat-oai/src/model.ts @@ -177,7 +177,9 @@ export function toOpenAITextAndMedia( } // Check if this is an image type - if (isImageContentType(contentType)) { + // If no contentType is provided, preserve legacy behavior by treating the media + // as an image URL (e.g. signed URLs or remote images without metadata) + if (!contentType || isImageContentType(contentType)) { return { type: 'image_url', image_url: { diff --git a/js/plugins/compat-oai/tests/compat_oai_test.ts b/js/plugins/compat-oai/tests/compat_oai_test.ts index 93844e3fba..295d76a9d1 100644 --- a/js/plugins/compat-oai/tests/compat_oai_test.ts +++ b/js/plugins/compat-oai/tests/compat_oai_test.ts @@ -171,6 +171,21 @@ describe('toOpenAiTextAndMedia', () => { }); }); + it('should transform image from signed URLs', () => { + const part: Part = { + media: { + url: 'https://storage.googleapis.com/bucket/image.png?X-Goog-Signature=fake', + }, + }; + expect(toOpenAITextAndMedia(part, 'low')).toStrictEqual({ + type: 'image_url', + image_url: { + url: 'https://storage.googleapis.com/bucket/image.png?X-Goog-Signature=fake', + detail: 'low', + }, + }); + }); + it('should throw error for file URLs (non-base64 PDFs)', () => { const part: Part = { media: {