Composer: multi-image attachments (image fusion + chat vision) - #9
Merged
Conversation
Gateway image2image already accepted `image: string | string[]` (cap 4 for OpenAI, 3 for Google; see blockrun/src/app/api/v1/images/image2image/ route.ts:28) but the web composer was hardcoded to a single slot — clicking the + again replaced the picked image instead of appending. This lets the user attach up to the per-model cap. The + button: - accepts multiple files in one pick (multi-attribute when cap > 1) - appends to the existing list, never replaces - hides once the cap is reached - shows '2/4' counter in its title attribute Per-mode/per-model caps via maxAttachmentsFor(): - music: 0 (button never shown) - video: 1 (first attachment used as seed; rest dropped at send time) - image: maxImageFusionFor(model) — 4 for openai/*, 3 for google/*, 1 else - chat: 4 (matches the highest image cap for UX symmetry) Storage and wire: - ChatMessage gains `images?: string[]` for multi; single `image` kept for back-compat with legacy persisted conversations + assistant single outputs. userImages() helper flattens both shapes for every reader. - runChatWithTools maps every userImages(m) entry to its own image block in the Anthropic /v1/messages content array. - runMedia(image) sends `image: trimmed` (string when 1, string[] when 2+); video keeps single-seed behavior (first ref wins). UI: - Composer thumbnail strip switches from single .try-attach card to a .try-attach-row when there are 2+ images. - Bubble rendering switches to .try-msg-attach-row above 1 image. - Single-image rendering paths unchanged (zero visual regression for existing 1-attachment turns).
Images staged in one mode (image fusion refs / chat vision) survived a mode switch and were sent on the next turn — leaking into chat vision or into a music request that drops them with an empty prompt. Reset attachments in the existing mode-change block, matching the flyout-reset pattern from #7.
The .try-attach-row comment states single-attachment turns reuse the .try-attach card directly, but the composer wrapped every count in the row, whose 'margin: 0' rule stripped the single thumbnail's spacing. Gate the row on 2+ items, matching the message-bubble render and the PR's zero-regression promise for 1-attachment turns.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Gateway image2image has accepted multi-image input for a while (
image: string | string[], up to 4 for OpenAI / 3 for Google — seeblockrun/src/app/api/v1/images/image2image/route.ts:28) but the web composer was hardcoded to a single slot, and clicking+again replaced the picked image instead of appending. This PR wires the composer up to the gateway's real capability.Behavior
openai/*google/*xai/grok-imagine-imageetc.Cap is derived from
maxAttachmentsFor(mode, model)— exported from the chat hook so future panels (e.g. a richer skill marketplace) can read it.The
+button:multipleattribute when cap > 1)2/4counter in its title attributeWire / storage
ChatMessagegainsimages?: string[]for multi; the existingimage?: stringis kept for back-compat with legacy persisted conversations and assistant single-image outputs.userImages(m)helper flattens both shapes — every reader (vision routing, chat serialization, regenerate, bubble rendering) goes through it so no caller has to branch on the shape.runChatWithToolsmaps everyuserImages(m)entry to its own Anthropicimagecontent block.runMedia(image mode) sendsimage: trimmed— single string when 1 attachment,string[]when 2+. Matches the gateway's accepted shape on both sides of the union.UI
.try-attachcard visual; 2+ switch to a flex-wrap.try-attach-rowstrip with individual remove buttons..try-msg-attachlook, 2+ use.try-msg-attach-rowfor horizontal layout.Test plan
+still visible → attach 2 more → counter shows3/4→ attach 1 more →+disappears at4/43/3(button hides at 3, not 4)1/1(single anchor, classic behavior)+button.try-msg-attachcard as before (back-compat)