From 6a9bc911e40aeacf38758b0c2ccb03bc853d89f2 Mon Sep 17 00:00:00 2001 From: 7hokerz Date: Wed, 21 Jan 2026 13:40:41 +0900 Subject: [PATCH 1/2] feat(js/plugin/compat-oai): preserve legacy image URL handling when contentType is missing --- js/plugins/compat-oai/src/model.ts | 12 ++++++++++++ js/plugins/compat-oai/tests/compat_oai_test.ts | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/js/plugins/compat-oai/src/model.ts b/js/plugins/compat-oai/src/model.ts index d2ce7cce99..e5c6cf74d2 100644 --- a/js/plugins/compat-oai/src/model.ts +++ b/js/plugins/compat-oai/src/model.ts @@ -187,6 +187,18 @@ export function toOpenAITextAndMedia( }; } + // 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) { + return { + type: 'image_url', + image_url: { + url: part.media.url, + detail: visualDetailLevel, + }, + }; + } + // For non-image types (like PDF), use the file type // OpenAI expects the full data URL (with data: prefix) in file_data if (part.media.url.startsWith('data:')) { 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: { From cfd5b44d8ce2694917ab005601a7857853c565d5 Mon Sep 17 00:00:00 2001 From: 7hokerz Date: Fri, 23 Jan 2026 02:19:03 +0900 Subject: [PATCH 2/2] refactor: Reduce duplication --- js/plugins/compat-oai/src/model.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/js/plugins/compat-oai/src/model.ts b/js/plugins/compat-oai/src/model.ts index e5c6cf74d2..b3567fb51e 100644 --- a/js/plugins/compat-oai/src/model.ts +++ b/js/plugins/compat-oai/src/model.ts @@ -177,19 +177,9 @@ export function toOpenAITextAndMedia( } // Check if this is an image type - if (isImageContentType(contentType)) { - return { - type: 'image_url', - image_url: { - url: part.media.url, - detail: visualDetailLevel, - }, - }; - } - // 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) { + if (!contentType || isImageContentType(contentType)) { return { type: 'image_url', image_url: {