Skip to content

Commit f405b43

Browse files
committed
fix(cli): integrate message queue with chat input handlers
Add support for queueing messages when streaming or chain is in progress. Update Build it buttons and initial prompt handling to use queue instead of direct message sending when appropriate.
1 parent f9cbd6b commit f405b43

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

cli/src/chat.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,10 @@ export const Chat = ({
539539
separatorWidth,
540540
initialPrompt,
541541
sendMessageRef,
542+
isChainInProgressRef,
543+
streamMessageIdRef,
544+
isStreaming,
545+
addToQueue,
542546
})
543547

544548
const {

cli/src/hooks/use-chat-input.ts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ interface UseChatInputOptions {
1313
separatorWidth: number
1414
initialPrompt: string | null
1515
sendMessageRef: React.MutableRefObject<SendMessageFn | undefined>
16+
isChainInProgressRef: React.MutableRefObject<boolean>
17+
streamMessageIdRef: React.MutableRefObject<string | null>
18+
isStreaming: boolean
19+
addToQueue: (message: string) => void
1620
}
1721

1822
const BUILD_IT_TEXT = 'Build it!'
@@ -25,6 +29,10 @@ export const useChatInput = ({
2529
separatorWidth,
2630
initialPrompt,
2731
sendMessageRef,
32+
isChainInProgressRef,
33+
streamMessageIdRef,
34+
isStreaming,
35+
addToQueue,
2836
}: UseChatInputOptions) => {
2937
const hasAutoSubmittedRef = useRef(false)
3038

@@ -54,12 +62,19 @@ export const useChatInput = ({
5462
lastEditDueToNav: true,
5563
})
5664
setTimeout(() => {
57-
if (sendMessageRef.current) {
65+
// Check if streaming or chain in progress - if so, add to queue instead of sending
66+
if (
67+
isStreaming ||
68+
streamMessageIdRef.current ||
69+
isChainInProgressRef.current
70+
) {
71+
addToQueue(BUILD_IT_TEXT)
72+
} else if (sendMessageRef.current) {
5873
sendMessageRef.current({ content: BUILD_IT_TEXT, agentMode: 'DEFAULT' })
5974
}
6075
setInputValue({ text: '', cursorPosition: 0, lastEditDueToNav: false })
6176
}, 0)
62-
}, [setAgentMode, setInputValue, sendMessageRef])
77+
}, [setAgentMode, setInputValue, sendMessageRef, isStreaming, streamMessageIdRef, isChainInProgressRef, addToQueue])
6378

6479
const handleBuildMax = useCallback(() => {
6580
setAgentMode('MAX')
@@ -69,27 +84,41 @@ export const useChatInput = ({
6984
lastEditDueToNav: true,
7085
})
7186
setTimeout(() => {
72-
if (sendMessageRef.current) {
87+
// Check if streaming or chain in progress - if so, add to queue instead of sending
88+
if (
89+
isStreaming ||
90+
streamMessageIdRef.current ||
91+
isChainInProgressRef.current
92+
) {
93+
addToQueue('Build it!')
94+
} else if (sendMessageRef.current) {
7395
sendMessageRef.current({ content: 'Build it!', agentMode: 'MAX' })
7496
}
7597
setInputValue({ text: '', cursorPosition: 0, lastEditDueToNav: false })
7698
}, 0)
77-
}, [setAgentMode, setInputValue, sendMessageRef])
99+
}, [setAgentMode, setInputValue, sendMessageRef, isStreaming, streamMessageIdRef, isChainInProgressRef, addToQueue])
78100

79101
useEffect(() => {
80102
if (initialPrompt && !hasAutoSubmittedRef.current) {
81103
hasAutoSubmittedRef.current = true
82104

83105
const timeout = setTimeout(() => {
84-
if (sendMessageRef.current) {
106+
// Check if streaming or chain in progress - if so, add to queue instead of sending
107+
if (
108+
isStreaming ||
109+
streamMessageIdRef.current ||
110+
isChainInProgressRef.current
111+
) {
112+
addToQueue(initialPrompt)
113+
} else if (sendMessageRef.current) {
85114
sendMessageRef.current({ content: initialPrompt, agentMode })
86115
}
87116
}, 100)
88117

89118
return () => clearTimeout(timeout)
90119
}
91120
return undefined
92-
}, [initialPrompt, agentMode, sendMessageRef])
121+
}, [initialPrompt, agentMode, sendMessageRef, isStreaming, streamMessageIdRef, isChainInProgressRef, addToQueue])
93122

94123
return {
95124
inputWidth,

0 commit comments

Comments
 (0)