Skip to content

fix: convert media content to provider format before recording - #18

Closed
callingmedic911 wants to merge 2 commits into
mainfrom
fix/media-recording-format
Closed

fix: convert media content to provider format before recording#18
callingmedic911 wants to merge 2 commits into
mainfrom
fix/media-recording-format

Conversation

@callingmedic911

@callingmedic911 callingmedic911 commented Mar 13, 2026

Copy link
Copy Markdown
Member

Summary

  • Media messages from bind() contain internal content objects (content_part_type: "text", "media_base64", etc.) that aren't in any provider format the backend accepts.
  • allMessages() returned these raw messages, causing recording API validation failures for prompts with media inputs.
  • In format(), media messages are now re-run through the adapter individually to produce provider-formatted content while preserving messages the adapter would otherwise drop (e.g. system for Responses API).

Test plan

  • New test media messages in allMessages have provider format verifies no internal fields leak and content blocks have proper type discriminators
  • Existing Handles images for OpenAI test updated to expect provider format
  • All 68 unit tests pass

Summary by CodeRabbit

  • Bug Fixes

    • Fixed validation errors when recording prompts with media inputs by ensuring media content in recorded messages uses provider-formatted objects, so recorded prompts with media attachments validate and process correctly.
  • Tests

    • Added tests to verify recorded messages with media use provider-formatted content and remain JSON-serializable.

@coderabbitai

coderabbitai Bot commented Mar 13, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cf991b11-ae04-4127-affc-9c3dae825c7c

📥 Commits

Reviewing files that changed from the base of the PR and between 7129234 and b0d6dc2.

📒 Files selected for processing (1)
  • src/resources/prompts.ts

📝 Walkthrough

Walkthrough

BoundPrompt.format now post-processes prepared messages to convert internal media content_part_type objects into provider-formatted objects by re-invoking the LLM adapter; package version bumped to 0.6.2 and tests updated/added to assert provider-formatted media in recorded messages.

Changes

Cohort / File(s) Summary
Version & Changelog
CHANGELOG.md, package.json
Bump to 0.6.2 and add changelog entry documenting the fix for media content formatting in recorded messages.
Core Logic
src/resources/prompts.ts
BoundPrompt.format adds a post-processing step: detects internal content_part_type parts in prepared messages, re-runs that single message through the LLM adapter to obtain provider-formatted content, and substitutes the first formatted result when available.
Tests — new/updated
test/resources/prompts.test.ts, test/sdk.test.ts
Add test ensuring allMessages contains provider-formatted media blocks (with type) and update test payloads/expectations from content_part_type/media_url/media_base64 to provider-style type and image_url structures.

Sequence Diagram(s)

sequenceDiagram
  participant BoundPrompt
  participant PrepareMessages
  participant LLMAdapter
  participant Provider

  BoundPrompt->>PrepareMessages: prepareMessages(prompt, boundValues)
  PrepareMessages-->>BoundPrompt: preparedMessages (may contain content_part_type)
  alt contains content_part_type
    BoundPrompt->>LLMAdapter: format([singlePreparedMessage])
    LLMAdapter->>Provider: emit provider-formatted content
    Provider-->>LLMAdapter: provider-formatted blocks
    LLMAdapter-->>BoundPrompt: formattedMessageArray
    BoundPrompt->>BoundPrompt: replace original message with first formatted block
  end
  BoundPrompt-->>Client: allMessages (provider-formatted)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • nicot
  • BrianNewsom

Poem

🐰 I hopped through messages, found a glitch,
Swapped odd parts for a provider's stitch.
Now media hops in tidy lines,
No more internal type confines.
Recorded prompts sing—new designs! 📹

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: converting media content to provider format before recording to fix validation errors.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/media-recording-format
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can approve the review once all CodeRabbit's comments are resolved.

Enable the reviews.request_changes_workflow setting to automatically approve the review once all CodeRabbit's comments are resolved.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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/resources/prompts.ts`:
- Around line 495-498: The predicate that checks for "content_part_type" can
throw if msg.content contains primitives; update the Array.isArray(msg.content)
&& msg.content.some(...) check to first guard each element (the part variable)
is a non-null object before using the in operator—e.g. ensure typeof part ===
"object" && part !== null && "content_part_type" in part inside the callback
used by msg.content.some so primitives and nulls are skipped safely.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6b9f463c-6d6a-4f27-a56a-867c0eee46ef

📥 Commits

Reviewing files that changed from the base of the PR and between 9632c97 and 7129234.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • CHANGELOG.md
  • package.json
  • src/resources/prompts.ts
  • test/resources/prompts.test.ts
  • test/sdk.test.ts

Comment thread src/resources/prompts.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant