1- import {
2- InputRenderable ,
3- LayoutEvents ,
4- ScrollBoxRenderable ,
5- TextAttributes ,
6- } from '@opentui/core'
7- import { render , useKeyboard , useRenderer } from '@opentui/react'
8- import { MultilineInput } from './multiline-input'
9- import {
10- renderMarkdown ,
11- renderStreamingMarkdown ,
12- hasMarkdown ,
13- type MarkdownPalette ,
14- } from './markdown-renderer'
15- import {
16- Fragment ,
1+ import { useRenderer } from '@opentui/react'
2+ import React , {
173 useCallback ,
184 useEffect ,
195 useMemo ,
206 useRef ,
217 useState ,
22- type ReactNode ,
238} from 'react'
9+
10+
11+ import { logger } from './logger'
12+ import { buildMessageTree } from './message-tree-utils'
13+ import { MultilineInput } from './multiline-input'
14+ import { Separator } from './separator'
15+ import { StatusIndicator , useHasStatus } from './status-indicator'
2416import {
25- getCodebuffClient ,
26- getToolDisplayInfo ,
27- formatToolOutput ,
28- } from './codebuff-client'
29- import type { ToolName } from '@codebuff/sdk'
30- import {
31- type ChatTheme ,
3217 type ThemeName ,
3318 chatThemes ,
3419 createMarkdownPalette ,
3520 detectSystemTheme ,
3621} from './theme-system'
37- import { formatTimestamp , formatQueuedPreview } from './utils'
3822import { useClipboard } from './use-clipboard'
3923import { useInputHistory } from './use-input-history'
24+ import { useKeyboardHandlers } from './use-keyboard-handlers'
4025import { useMessageQueue } from './use-message-queue'
41- import { buildMessageTree } from './message-tree-utils'
42- import { useSendMessage } from './use-send-message'
4326import { useMessageRenderer } from './use-message-renderer'
44- import { useKeyboardHandlers } from './use-keyboard-handlers'
4527import { useScrollManagement } from './use-scroll-management'
28+ import { useSendMessage } from './use-send-message'
29+ import { formatTimestamp , formatQueuedPreview } from './utils'
4630
47- import { logger } from './logger '
48-
49- import { StatusIndicator , useHasStatus } from './status-indicator'
50- import { Separator } from './separator'
51- import React from 'react '
31+ import type { ToolName } from '@codebuff/sdk '
32+ import type {
33+ InputRenderable ,
34+ ScrollBoxRenderable ,
35+ } from '@opentui/core '
5236
5337type ChatVariant = 'ai' | 'user' | 'agent'
5438
@@ -95,9 +79,6 @@ export const App = ({ initialPrompt }: { initialPrompt?: string } = {}) => {
9579 const renderer = useRenderer ( )
9680 const scrollRef = useRef < ScrollBoxRenderable | null > ( null )
9781 const inputRef = useRef < InputRenderable | null > ( null )
98- const [ inputRenderable , setInputRenderable ] =
99- useState < InputRenderable | null > ( null )
100- const [ inputWidth , setInputWidth ] = useState < number > ( 0 )
10182
10283 const [ themeName , setThemeName ] = useState < ThemeName > ( ( ) =>
10384 detectSystemTheme ( ) ,
@@ -109,15 +90,13 @@ export const App = ({ initialPrompt }: { initialPrompt?: string } = {}) => {
10990 const [ inputFocused , setInputFocused ] = useState < boolean > ( true )
11091
11192 const activeAgentStreamsRef = useRef < number > ( 0 )
112- const allAgentsScheduledRef = useRef < boolean > ( false )
11393 const isChainInProgressRef = useRef < boolean > ( false )
11494
11595 const { clipboardMessage } = useClipboard ( )
11696
11797 const [ collapsedAgents , setCollapsedAgents ] = useState < Set < string > > ( new Set ( ) )
11898 const [ streamingAgents , setStreamingAgents ] = useState < Set < string > > ( new Set ( ) )
11999 const [ focusedAgentId , setFocusedAgentId ] = useState < string | null > ( null )
120- const agentIdsRef = useRef < string [ ] > ( [ ] )
121100 const agentRefsMap = useRef < Map < string , any > > ( new Map ( ) )
122101
123102 const [ messages , setMessages ] = useState < ChatMessage [ ] > ( [
@@ -134,42 +113,13 @@ export const App = ({ initialPrompt }: { initialPrompt?: string } = {}) => {
134113 const hasAutoSubmittedRef = useRef ( false )
135114 const activeSubagentsRef = useRef < Set < string > > ( new Set ( ) )
136115
137- const handleInputRef = useCallback ( ( instance : InputRenderable | null ) => {
138- inputRef . current = instance
139- setInputRenderable ( instance )
140- if ( instance ) {
141- setInputWidth ( Math . max ( 0 , instance . width ) )
142- }
143- } , [ ] )
144-
145-
146-
147116 useEffect ( ( ) => {
148117 renderer ?. setBackgroundColor ( theme . background )
149118 } , [ renderer , theme . background ] )
150119
151120
152121
153- useEffect ( ( ) => {
154- const instance = inputRenderable
155- if ( ! instance ) return
156-
157- const updateWidth = ( ) => {
158- setInputWidth ( Math . max ( 0 , instance . width ) )
159- }
160-
161- updateWidth ( )
162122
163- const handleResize = ( { width } : { width : number } ) => {
164- setInputWidth ( Math . max ( 0 , width ) )
165- }
166-
167- instance . on ( LayoutEvents . RESIZED , handleResize )
168-
169- return ( ) => {
170- instance . off ( LayoutEvents . RESIZED , handleResize )
171- }
172- } , [ inputRenderable ] )
173123
174124 const abortControllerRef = useRef < AbortController | null > ( null )
175125
@@ -181,14 +131,13 @@ export const App = ({ initialPrompt }: { initialPrompt?: string } = {}) => {
181131 }
182132 } , [ ] )
183133
184- const { scrollToLatest , scrollToAgent } = useScrollManagement (
134+ const { scrollToAgent } = useScrollManagement (
185135 scrollRef ,
186136 messages ,
187137 agentRefsMap ,
188138 )
189139
190140 const { saveToHistory, navigateUp, navigateDown } = useInputHistory (
191- inputRenderable ,
192141 inputValue ,
193142 setInputValue ,
194143 )
@@ -198,14 +147,12 @@ export const App = ({ initialPrompt }: { initialPrompt?: string } = {}) => {
198147 const {
199148 queuedMessages,
200149 isStreaming,
201- canProcessQueue,
202150 isWaitingForResponse,
203151 streamMessageIdRef,
204152 addToQueue,
205153 startStreaming,
206154 stopStreaming,
207155 setIsWaitingForResponse,
208- clearStreaming,
209156 setCanProcessQueue,
210157 setIsStreaming,
211158 } = useMessageQueue (
@@ -325,7 +272,6 @@ export const App = ({ initialPrompt }: { initialPrompt?: string } = {}) => {
325272 isWaitingForResponse,
326273 abortControllerRef,
327274 focusedAgentId,
328- inputRenderable,
329275 setFocusedAgentId,
330276 setInputFocused,
331277 inputRef,
@@ -352,17 +298,6 @@ export const App = ({ initialPrompt }: { initialPrompt?: string } = {}) => {
352298 scrollToAgent,
353299 } )
354300
355- const fallbackInputWidth = Math . max ( 4 , renderer . width - 6 )
356- const effectiveInputWidth = inputWidth > 0 ? inputWidth : fallbackInputWidth
357- const maxCharsPerLine = Math . max ( 1 , effectiveInputWidth - 1 )
358- const textLengthForRows = Math . max ( 1 , inputValue . length )
359- const computedLineCount = Math . max (
360- 1 ,
361- Math . ceil ( textLengthForRows / maxCharsPerLine ) ,
362- )
363- const maxInputHeight = 5
364- const inputHeight = Math . max ( 1 , Math . min ( computedLineCount , maxInputHeight ) )
365-
366301 return (
367302 < box
368303 style = { {
0 commit comments