fix: Responses API native content types in adapter - #16
Conversation
Content blocks now use input_text, input_image, input_file instead of Chat Completions types (text, image_url, file) which OpenAI rejects.
📝 WalkthroughWalkthroughThe PR updates the OpenAIResponsesAdapter to use OpenAI Responses API native content types (input_text, input_image, input_file) instead of Chat Completions types. Changes include version bump to 0.6.1, architectural refactoring from inheritance to interface implementation, and content transformation logic with comprehensive test coverage. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/openaiResponses.test.ts (1)
156-184: Consider adding a test for non-image URL rejection.The implementation throws an error when
slot_typeis not"image"for media URLs. A test for this error path would improve coverage.📝 Example test case
test("throws for non-image URL content", () => { const messages: ProviderMessage[] = [ { role: "user", content: [ { content_part_type: "media_url", url: "http://example.com/video.mp4", slot_name: "video-1", slot_type: "video", }, ], }, ]; expect(() => adapter.toLLMSyntax(messages)).toThrow( "Message contains a non-image URL, but OpenAI Responses API only supports image URLs.", ); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/openaiResponses.test.ts` around lines 156 - 184, Add a unit test covering the error path where a media_url has a non-"image" slot_type: call adapter.toLLMSyntax with a message whose content includes a media_url with slot_type "video" and assert it throws the expected message "Message contains a non-image URL, but OpenAI Responses API only supports image URLs."; place the test alongside existing cases in openaiResponses.test.ts and reference adapter.toLLMSyntax to ensure the non-image URL rejection logic is exercised.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/model.ts`:
- Around line 388-407: In formatBase64Content (MediaContentBase64 handling) add
defensive validation for item.content_type before using
item.content_type.split("/")[1]; if content_type is missing or does not contain
"/", fall back to a safe mime like "application/octet-stream" and a default file
extension (e.g., "bin") when building filename and the data URL, and ensure
filename uses a sanitized slot_name; update the branch that returns input_file
to compute ext = (content_type.includes("/") ? content_type.split("/")[1] :
"bin") and use a safe contentType variable in the data URL so undefined is never
embedded.
---
Nitpick comments:
In `@test/openaiResponses.test.ts`:
- Around line 156-184: Add a unit test covering the error path where a media_url
has a non-"image" slot_type: call adapter.toLLMSyntax with a message whose
content includes a media_url with slot_type "video" and assert it throws the
expected message "Message contains a non-image URL, but OpenAI Responses API
only supports image URLs."; place the test alongside existing cases in
openaiResponses.test.ts and reference adapter.toLLMSyntax to ensure the
non-image URL rejection logic is exercised.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c8a47841-43c7-47bb-9a09-83e006fbba42
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (4)
CHANGELOG.mdpackage.jsonsrc/model.tstest/openaiResponses.test.ts
Summary
OpenAIResponsesAdapternow produces Responses API native content types (input_text,input_image,input_file) instead of inheriting Chat Completions types (text,image_url,file) fromOpenAILLMAdapterinputparameterNote
Fix
OpenAIResponsesAdapterto emit Responses API-native content block typesOpenAIResponsesAdapterin src/model.ts to implementILLMAdapterdirectly instead of extendingOpenAILLMAdapter, so content blocks are no longer converted to Chat Completions types.{type: "input_text"}, image URLs to{type: "input_image"}, base64 images to{type: "input_image"}with a data URI, and base64 files to{type: "input_file"}with a derived filename.formatBase64Contenthelper to handle base64 image and file cases.Macroscope summarized fd1a2c7.
Summary by CodeRabbit
Release Notes v0.6.1
Bug Fixes
Tests