Skip to content

Add support for image content blocks in agent messages#197

Open
Glavin001 wants to merge 2 commits intorivet-dev:mainfrom
Glavin001:claude/add-image-support-MjMZz
Open

Add support for image content blocks in agent messages#197
Glavin001 wants to merge 2 commits intorivet-dev:mainfrom
Glavin001:claude/add-image-support-MjMZz

Conversation

@Glavin001
Copy link

Summary

This PR adds support for handling image content blocks in agent messages, allowing the system to process and display images alongside text in the chat interface.

Key Changes

Backend (opencode-adapter):

  • Extended translate_session_update to discriminate content blocks by type (text vs. image)
  • Added image content block handling that extracts URI and MIME type from ACP ImageContent
  • Implemented logic to finalize any accumulated text before emitting image parts
  • Image parts are persisted and emitted as file-type message parts with URI, MIME type, and filename

Frontend (inspector):

  • Updated App.tsx to recognize and handle image content in agent message chunks
  • Converts file:// URIs to /v1/fs/file API endpoints for browser-accessible image fetching
  • Added "image" as a new TimelineEntry kind type
  • Updated ChatMessages.tsx to render images with proper styling (max-width, border-radius)
  • Images are displayed inline in the chat with text flushed before image rendering

Implementation Details

  • Image content blocks are identified by type: "image" in the content discriminator
  • Text accumulation is finalized and persisted before emitting images to maintain proper message ordering
  • File URIs are stripped of the file:// prefix and passed through the sandbox agent's file serving API
  • Images are rendered with responsive sizing and rounded corners to match the chat UI aesthetic

https://claude.ai/code/session_01Exgh67PQ5vVF1MxHDSHm4s

…date

The translate_session_update function only handled text content blocks
from agent_message_chunk/agent_thought_chunk notifications, silently
dropping image content. This adds support for ACP ImageContent blocks
(type=image, uri, mimeType) by translating them into OpenCode "file"
parts with the correct MIME type and file:// URI, matching the pattern
used by the opencode_compat layer. Pending text is finalized before
emitting the image part, and both are persisted for session replay.

https://claude.ai/code/session_01Exgh67PQ5vVF1MxHDSHm4s
Add image support to the inspector UI so that ACP agent_message_chunk
notifications with type=image content blocks are displayed inline.

- Add `image` kind and field to TimelineEntry type
- Parse image content blocks in the App.tsx event-to-timeline mapper,
  converting file:// URIs to /v1/fs/file API URLs for browser rendering
- Flush accumulated text before emitting an image entry
- Render <img> tags in ChatMessages for image timeline entries

https://claude.ai/code/session_01Exgh67PQ5vVF1MxHDSHm4s
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.

2 participants