MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / useChatInput

Function useChatInput

cli/src/hooks/use-chat-input.ts:23–106  ·  view source on GitHub ↗
({
  setInputValue,
  agentMode,
  setAgentMode,
  separatorWidth,
  initialPrompt,
  onSubmitPrompt,
  isCompactHeight,
  isNarrowWidth,
}: UseChatInputOptions)

Source from the content-addressed store, hash-verified

21const BUILD_IT_TEXT = 'Build it!'
22
23export const useChatInput = ({
24 setInputValue,
25 agentMode,
26 setAgentMode,
27 separatorWidth,
28 initialPrompt,
29 onSubmitPrompt,
30 isCompactHeight,
31 isNarrowWidth,
32}: UseChatInputOptions) => {
33 const hasAutoSubmittedRef = useRef(false)
34 const inputMode = useChatStore((state) => state.inputMode)
35
36 // Estimate the collapsed toggle width as rendered by AgentModeToggle.
37 // In Freebuff, the toggle is always hidden, so never reserve width for it.
38 // In non-Freebuff: hide in bash mode, compact height, or narrow width.
39 const estimatedToggleWidth = IS_FREEBUFF || inputMode !== 'default' || isCompactHeight || isNarrowWidth
40 ? 0
41 : stringWidth(`< ${agentMode}`) + 6 // 2 padding + 2 borders + 2 gap
42
43 // The content box that wraps the input row has paddingLeft/paddingRight = 1
44 // (see cli/src/chat.tsx). Subtract those columns so our MultilineInput width
45 // matches the true drawable area between the borders.
46 const contentPadding = 2 // 1 left + 1 right padding
47 const availableContentWidth = Math.max(1, separatorWidth - contentPadding)
48 const inputWidth = Math.max(1, availableContentWidth - estimatedToggleWidth)
49
50 const handleBuildFast = useCallback(() => {
51 setAgentMode('DEFAULT')
52 setInputValue({
53 text: BUILD_IT_TEXT,
54 cursorPosition: BUILD_IT_TEXT.length,
55 lastEditDueToNav: true,
56 })
57 setTimeout(() => {
58 onSubmitPrompt(BUILD_IT_TEXT, 'DEFAULT')
59 setInputValue({ text: '', cursorPosition: 0, lastEditDueToNav: false })
60 }, 0)
61 }, [setAgentMode, setInputValue, onSubmitPrompt])
62
63 const handleBuildMax = useCallback(() => {
64 setAgentMode('MAX')
65 setInputValue({
66 text: BUILD_IT_TEXT,
67 cursorPosition: BUILD_IT_TEXT.length,
68 lastEditDueToNav: true,
69 })
70 setTimeout(() => {
71 onSubmitPrompt('Build it!', 'MAX')
72 setInputValue({ text: '', cursorPosition: 0, lastEditDueToNav: false })
73 }, 0)
74 }, [setAgentMode, setInputValue, onSubmitPrompt])
75
76 const handleBuildLite = useCallback(() => {
77 setAgentMode('LITE')
78 setInputValue({
79 text: BUILD_IT_TEXT,
80 cursorPosition: BUILD_IT_TEXT.length,

Callers 1

ChatFunction · 0.90

Calls 2

setInputValueFunction · 0.85
setTimeoutFunction · 0.85

Tested by

no test coverage detected