diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index c16aab4fbe..3fa62ca595 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -2368,12 +2368,14 @@ export default function ChatView(props: ChatViewProps) { draftText: trimmed, planMarkdown: activeProposedPlan.planMarkdown, }); + const planFollowUpImages = [...composerImages]; promptRef.current = ""; clearComposerDraftContent(composerDraftTarget); composerRef.current?.resetCursorState(); await onSubmitPlanFollowUp({ text: followUp.text, interactionMode: followUp.interactionMode, + images: planFollowUpImages, }); return; } @@ -2806,9 +2808,11 @@ export default function ChatView(props: ChatViewProps) { async ({ text, interactionMode: nextInteractionMode, + images = [], }: { text: string; interactionMode: "default" | "plan"; + images?: ReadonlyArray; }) => { const api = readEnvironmentApi(environmentId); if ( @@ -2850,6 +2854,27 @@ export default function ChatView(props: ChatViewProps) { text: trimmed, }); + const turnAttachmentsPromise = + images.length > 0 + ? Promise.all( + images.map(async (image) => ({ + type: "image" as const, + name: image.name, + mimeType: image.mimeType, + sizeBytes: image.sizeBytes, + dataUrl: await readFileAsDataUrl(image.file), + })), + ) + : Promise.resolve([]); + const optimisticAttachments = images.map((image) => ({ + type: "image" as const, + id: image.id, + name: image.name, + mimeType: image.mimeType, + sizeBytes: image.sizeBytes, + previewUrl: image.previewUrl, + })); + sendInFlightRef.current = true; beginLocalDispatch({ preparingWorktree: false }); setThreadError(threadIdForSend, null); @@ -2866,12 +2891,15 @@ export default function ChatView(props: ChatViewProps) { id: messageIdForSend, role: "user", text: outgoingMessageText, + ...(optimisticAttachments.length > 0 ? { attachments: optimisticAttachments } : {}), createdAt: messageCreatedAt, streaming: false, }, ]); try { + const turnAttachments = await turnAttachmentsPromise; + await persistThreadSettingsForNextTurn({ threadId: threadIdForSend, createdAt: messageCreatedAt, @@ -2895,7 +2923,7 @@ export default function ChatView(props: ChatViewProps) { messageId: messageIdForSend, role: "user", text: outgoingMessageText, - attachments: [], + attachments: turnAttachments, }, modelSelection: ctxSelectedModelSelection, titleSeed: activeThread.title,