@@ -11,7 +11,11 @@ import {
1111import { useShallow } from 'zustand/react/shallow'
1212
1313import { routeUserPrompt , addBashMessageToHistory } from './commands/router'
14+ import { addClipboardPlaceholder , addPendingImageFromFile } from './utils/add-pending-image'
15+ import { getProjectRoot } from './project-files'
1416import { AnnouncementBanner } from './components/announcement-banner'
17+ import { hasClipboardImage , readClipboardImage , readClipboardText } from './utils/clipboard-image'
18+ import { showClipboardMessage } from './utils/clipboard'
1519import { ChatInputBar } from './components/chat-input-bar'
1620import { MessageWithAgents } from './components/message-with-agents'
1721import { PendingBashMessage } from './components/pending-bash-message'
@@ -36,7 +40,7 @@ import {
3640 type ChatKeyboardState ,
3741 createDefaultChatKeyboardState ,
3842} from './utils/keyboard-actions'
39- import { useMessageQueue } from './hooks/use-message-queue'
43+ import { useMessageQueue , type QueuedMessage } from './hooks/use-message-queue'
4044import { useQueueControls } from './hooks/use-queue-controls'
4145import { useQueueUi } from './hooks/use-queue-ui'
4246import { useChatScrollbox } from './hooks/use-scroll-management'
@@ -429,6 +433,7 @@ export const Chat = ({
429433 const inputMode = useChatStore ( ( state ) => state . inputMode )
430434 const setInputMode = useChatStore ( ( state ) => state . setInputMode )
431435 const askUserState = useChatStore ( ( state ) => state . askUserState )
436+ const pendingImages = useChatStore ( ( state ) => state . pendingImages )
432437
433438 const {
434439 slashContext,
@@ -542,31 +547,12 @@ export const Chat = ({
542547 clearQueue,
543548 isQueuePausedRef,
544549 } = useMessageQueue (
545- ( content : string ) => {
546- // Route queued messages through the router to handle bash commands, slash commands, etc.
547- return routeUserPrompt ( {
548- abortControllerRef,
550+ ( message : QueuedMessage ) =>
551+ sendMessageRef . current ?.( {
552+ content : message . content ,
549553 agentMode,
550- inputRef,
551- inputValue : content ,
552- isChainInProgressRef,
553- isStreaming,
554- logoutMutation,
555- streamMessageIdRef,
556- addToQueue,
557- clearMessages,
558- saveToHistory : ( ) => { } , // Already saved when queued
559- scrollToLatest,
560- sendMessage,
561- setCanProcessQueue,
562- setInputFocused,
563- setInputValue : ( ) => { } , // Input already cleared when queued
564- setIsAuthenticated,
565- setMessages,
566- setUser,
567- stopStreaming,
568- } )
569- } ,
554+ images : message . images ,
555+ } ) ?? Promise . resolve ( ) ,
570556 isChainInProgressRef ,
571557 activeAgentStreamsRef ,
572558 )
@@ -1032,8 +1018,42 @@ export const Chat = ({
10321018 onExitApp : ( ) => handleCtrlC ( ) ,
10331019 onBashHistoryUp : navigateUp ,
10341020 onBashHistoryDown : navigateDown ,
1035- onDismissBashOverlay : ( ) => { } ,
1036- onCancelBashCommand : ( ) => { } ,
1021+ onPasteImage : ( ) => {
1022+ const placeholderPath = addClipboardPlaceholder ( )
1023+
1024+ setTimeout ( ( ) => {
1025+ if ( ! hasClipboardImage ( ) ) {
1026+ useChatStore . getState ( ) . removePendingImage ( placeholderPath )
1027+ const text = readClipboardText ( )
1028+ if ( text ) {
1029+ setInputValue ( ( prev ) => {
1030+ const before = prev . text . slice ( 0 , prev . cursorPosition )
1031+ const after = prev . text . slice ( prev . cursorPosition )
1032+ return {
1033+ text : before + text + after ,
1034+ cursorPosition : before . length + text . length ,
1035+ lastEditDueToNav : false ,
1036+ }
1037+ } )
1038+ }
1039+ return
1040+ }
1041+
1042+ const result = readClipboardImage ( )
1043+ if ( ! result . success || ! result . imagePath ) {
1044+ useChatStore . getState ( ) . removePendingImage ( placeholderPath )
1045+ showClipboardMessage ( result . error || 'Failed to paste image' , {
1046+ durationMs : 3000 ,
1047+ } )
1048+ return
1049+ }
1050+
1051+ const cwd = getProjectRoot ( ) ?? process . cwd ( )
1052+ void addPendingImageFromFile ( result . imagePath , cwd , placeholderPath )
1053+ } , 0 )
1054+
1055+ return true
1056+ } ,
10371057 } ) ,
10381058 [
10391059 setInputMode ,
0 commit comments