Skip to content

Add gallery component for displaying multiple media items#2129

Open
gary149 wants to merge 2 commits intomainfrom
claude/add-tool-gallery-eo727
Open

Add gallery component for displaying multiple media items#2129
gary149 wants to merge 2 commits intomainfrom
claude/add-tool-gallery-eo727

Conversation

@gary149
Copy link
Collaborator

@gary149 gary149 commented Feb 17, 2026

Summary

This PR introduces a new ToolGallery component that allows displaying multiple media items (images, videos, and audio) in a horizontal scrollable gallery format. The component is integrated into the chat message rendering system to support a new <gallery> block syntax.

Key Changes

  • New ToolGallery.svelte component: A reusable gallery component that displays media items in a horizontal scrollable container with:

    • Support for images (with lightbox zoom), videos (with controls), and audio players
    • Optional title and per-item descriptions
    • Smooth scroll navigation with left/right arrow buttons
    • Responsive design with dark mode support
    • Snap scrolling for better UX
  • Updated ChatMessage.svelte:

    • Added gallery block detection using regex pattern <gallery>...</gallery>
    • Implemented parseGalleryBlock() function to extract title and JSON-formatted media items from gallery blocks
    • Created renderTextContent() snippet to handle rendering of both markdown content and gallery blocks
    • Gallery blocks are stripped from clipboard copy (similar to think blocks)
    • Integrated ToolGallery component into message rendering pipeline
  • Updated toolPrompt.ts:

    • Enhanced system prompt to instruct models on using the gallery component
    • Added guidance for formatting gallery blocks with proper JSON structure
    • Clarifies when to use gallery vs inline markdown for media presentation

Implementation Details

  • Gallery items require url and media_type fields; title, description, and thumbnail_url are optional
  • Gallery blocks are parsed from HTML-like tags with optional title attribute: <gallery title="...">JSON</gallery>
  • The component handles scroll state management to conditionally show navigation buttons
  • Media items are displayed in fixed-width (224px) cards with proper aspect ratio handling
  • Graceful fallback if gallery JSON parsing fails (silently skips invalid blocks)

https://claude.ai/code/session_019mXtHGmqM5d1zijZ3mVZB6

Add a new built-in tool that the LLM can call within the MCP flow to
present images, videos, and audio in a horizontal scrollable gallery.
The gallery renders prominently (not hidden in the tool accordion) and
the model is informed via the system prompt when to use it.

- New builtinTools.ts module with display_gallery schema and local execution
- ToolGallery.svelte with snap-scroll, arrow nav, lightbox, video/audio support
- Built-in tools merged into MCP flow alongside external MCP server tools
- toolInvocation intercepts built-in tools before MCP dispatch
- Gallery-specific guidance added to tool system prompt

https://claude.ai/code/session_019mXtHGmqM5d1zijZ3mVZB6
Replace the built-in display_gallery tool with a simpler <gallery> markup
approach that follows the same pattern as <think> blocks. The model outputs
<gallery title="...">JSON</gallery> inline in its response text, and the
frontend detects, parses, and renders it as a horizontal scrollable gallery.

This approach is better because:
- No server-side MCP pipeline changes needed
- Works even when tool-calling is disabled
- Gallery can appear inline with surrounding text naturally
- Follows the existing <think> block pattern

Changes:
- Revert builtinTools.ts, runMcpFlow.ts, toolInvocation.ts, ToolUpdate.svelte
- ChatMessage.svelte: add gallery regex detection, JSON parser, renderTextContent
  snippet that splits text by <gallery> blocks (works with <think> too)
- toolPrompt.ts: describe <gallery> markup format in system prompt
- ToolGallery.svelte component is unchanged (now used from ChatMessage)

https://claude.ai/code/session_019mXtHGmqM5d1zijZ3mVZB6
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e3f130abe1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

{#if item.media_type === "image"}
<button
class="block w-full cursor-zoom-in overflow-hidden rounded-lg border border-gray-200 dark:border-gray-700"
onclick={() => (lightboxSrc = item.url)}

Choose a reason for hiding this comment

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

P2 Badge Stop gallery image click from opening two lightboxes

Clicking a gallery image fires this handler and also bubbles to ChatMessage.handleContentClick, which opens a second ImageLightbox for any IMG target. In assistant messages that creates stacked modals (often requiring multiple closes and conflicting body-scroll state), so gallery image interactions are currently broken unless the click event is stopped here or lightbox ownership is centralized.

Useful? React with 👍 / 👎.

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