@@ -2,7 +2,6 @@ import { useCallback, useEffect, useRef } from 'react'
22import stringWidth from 'string-width'
33
44import type { InputValue } from '../state/chat-store'
5- import type { SendMessageFn } from '../types/contracts/send-message'
65import type { AgentMode } from '../utils/constants'
76
87interface UseChatInputOptions {
@@ -12,11 +11,7 @@ interface UseChatInputOptions {
1211 setAgentMode : ( mode : AgentMode ) => void
1312 separatorWidth : number
1413 initialPrompt : string | null
15- sendMessageRef : React . MutableRefObject < SendMessageFn | undefined >
16- isChainInProgressRef : React . MutableRefObject < boolean >
17- streamMessageIdRef : React . MutableRefObject < string | null >
18- isStreaming : boolean
19- addToQueue : ( message : string ) => void
14+ onSubmitPrompt : ( content : string , mode : AgentMode ) => void | Promise < unknown >
2015}
2116
2217const BUILD_IT_TEXT = 'Build it!'
@@ -28,11 +23,7 @@ export const useChatInput = ({
2823 setAgentMode,
2924 separatorWidth,
3025 initialPrompt,
31- sendMessageRef,
32- isChainInProgressRef,
33- streamMessageIdRef,
34- isStreaming,
35- addToQueue,
26+ onSubmitPrompt,
3627} : UseChatInputOptions ) => {
3728 const hasAutoSubmittedRef = useRef ( false )
3829
@@ -62,19 +53,10 @@ export const useChatInput = ({
6253 lastEditDueToNav : true ,
6354 } )
6455 setTimeout ( ( ) => {
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 ) {
73- sendMessageRef . current ( { content : BUILD_IT_TEXT , agentMode : 'DEFAULT' } )
74- }
56+ onSubmitPrompt ( BUILD_IT_TEXT , 'DEFAULT' )
7557 setInputValue ( { text : '' , cursorPosition : 0 , lastEditDueToNav : false } )
7658 } , 0 )
77- } , [ setAgentMode , setInputValue , sendMessageRef , isStreaming , streamMessageIdRef , isChainInProgressRef , addToQueue ] )
59+ } , [ setAgentMode , setInputValue , onSubmitPrompt ] )
7860
7961 const handleBuildMax = useCallback ( ( ) => {
8062 setAgentMode ( 'MAX' )
@@ -84,41 +66,23 @@ export const useChatInput = ({
8466 lastEditDueToNav : true ,
8567 } )
8668 setTimeout ( ( ) => {
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 ) {
95- sendMessageRef . current ( { content : 'Build it!' , agentMode : 'MAX' } )
96- }
69+ onSubmitPrompt ( 'Build it!' , 'MAX' )
9770 setInputValue ( { text : '' , cursorPosition : 0 , lastEditDueToNav : false } )
9871 } , 0 )
99- } , [ setAgentMode , setInputValue , sendMessageRef , isStreaming , streamMessageIdRef , isChainInProgressRef , addToQueue ] )
72+ } , [ setAgentMode , setInputValue , onSubmitPrompt ] )
10073
10174 useEffect ( ( ) => {
10275 if ( initialPrompt && ! hasAutoSubmittedRef . current ) {
10376 hasAutoSubmittedRef . current = true
10477
10578 const timeout = setTimeout ( ( ) => {
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 ) {
114- sendMessageRef . current ( { content : initialPrompt , agentMode } )
115- }
79+ onSubmitPrompt ( initialPrompt , agentMode )
11680 } , 100 )
11781
11882 return ( ) => clearTimeout ( timeout )
11983 }
12084 return undefined
121- } , [ initialPrompt , agentMode , sendMessageRef , isStreaming , streamMessageIdRef , isChainInProgressRef , addToQueue ] )
85+ } , [ initialPrompt , agentMode , onSubmitPrompt ] )
12286
12387 return {
12488 inputWidth,
0 commit comments