@@ -2,14 +2,7 @@ import os from 'os'
22import path from 'path'
33
44import { useRenderer , useTerminalDimensions } from '@opentui/react'
5- import React , {
6- type ReactNode ,
7- useCallback ,
8- useEffect ,
9- useMemo ,
10- useRef ,
11- useState ,
12- } from 'react'
5+ import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react'
136import stringWidth from 'string-width'
147import { useShallow } from 'zustand/react/shallow'
158
@@ -37,6 +30,7 @@ import { useChatScrollbox } from './hooks/use-scroll-management'
3730import { useSendMessage } from './hooks/use-send-message'
3831import { useSuggestionEngine } from './hooks/use-suggestion-engine'
3932import { useSystemThemeDetector } from './hooks/use-system-theme-detector'
33+ import { handleSlashCommands } from './slash-commands/handlers'
4034import { useChatStore } from './state/chat-store'
4135import { flushAnalytics } from './utils/analytics'
4236import { getUserCredentials } from './utils/auth'
@@ -50,87 +44,18 @@ import {
5044import { logger } from './utils/logger'
5145import { buildMessageTree } from './utils/message-tree-utils'
5246import { openFileAtPath } from './utils/open-file'
53- import { handleSlashCommands } from './utils/slash-commands'
54- import {
55- chatThemes ,
56- createMarkdownPalette ,
57- type ChatTheme ,
58- } from './utils/theme-system'
47+ import { chatThemes , createMarkdownPalette } from './utils/theme-system'
5948import { formatValidationError } from './utils/validation-error-formatting'
6049
6150import type { SendMessageTimerEvent } from './hooks/use-send-message'
51+ import type { ChatMessage , ContentBlock } from './types/chat'
52+ import type { SendMessageFn } from './types/contracts/send-message'
6253import type { User } from './utils/auth'
63- import type { AgentMode } from './utils/constants'
64- import type { ToolName } from '@codebuff/sdk'
6554import type { ScrollBoxRenderable } from '@opentui/core'
6655
67- type ChatVariant = 'ai' | 'user' | 'agent' | 'error'
68-
6956const MAX_VIRTUALIZED_TOP_LEVEL = 60
7057const VIRTUAL_OVERSCAN = 12
7158
72- // LOGO_BLOCK moved to component to be reactive to terminal width changes
73-
74- type AgentMessage = {
75- agentName : string
76- agentType : string
77- responseCount : number
78- subAgentCount ?: number
79- }
80-
81- export type ContentBlock =
82- | {
83- type : 'text'
84- content : string
85- marginTop ?: number
86- marginBottom ?: number
87- }
88- | {
89- type : 'html'
90- marginTop ?: number
91- marginBottom ?: number
92- render : ( context : { textColor : string ; theme : ChatTheme } ) => ReactNode
93- }
94- | {
95- type : 'tool'
96- toolCallId : string
97- toolName : ToolName
98- input : any
99- output ?: string
100- agentId ?: string
101- }
102- | {
103- type : 'agent'
104- agentId : string
105- agentName : string
106- agentType : string
107- content : string
108- status : 'running' | 'complete'
109- blocks ?: ContentBlock [ ]
110- initialPrompt ?: string
111- }
112- | {
113- type : 'agent-list'
114- id : string
115- agents : Array < { id : string ; displayName : string } >
116- agentsDir : string
117- }
118-
119- export type ChatMessage = {
120- id : string
121- variant : ChatVariant
122- content : string
123- blocks ?: ContentBlock [ ]
124- timestamp : string
125- parentId ?: string
126- agent ?: AgentMessage
127- isCompletion ?: boolean
128- credits ?: number
129- completionTime ?: string
130- isComplete ?: boolean
131- metadata ?: Record < string , any >
132- }
133-
13459export const App = ( {
13560 initialPrompt,
13661 agentId,
@@ -788,10 +713,7 @@ export const App = ({
788713 setInputValue ,
789714 )
790715
791- const sendMessageRef =
792- useRef <
793- ( content : string , params : { agentMode : AgentMode } ) => Promise < void >
794- > ( )
716+ const sendMessageRef = useRef < SendMessageFn > ( )
795717
796718 const {
797719 queuedMessages,
@@ -806,7 +728,7 @@ export const App = ({
806728 setIsStreaming,
807729 } = useMessageQueue (
808730 ( content : string ) =>
809- sendMessageRef . current ?.( content , { agentMode } ) ?? Promise . resolve ( ) ,
731+ sendMessageRef . current ?.( { content, agentMode } ) ?? Promise . resolve ( ) ,
810732 isChainInProgressRef ,
811733 activeAgentStreamsRef ,
812734 )
@@ -870,7 +792,7 @@ export const App = ({
870792 const timeout = setTimeout ( ( ) => {
871793 logger . info ( { prompt : initialPrompt } , 'Auto-submitting initial prompt' )
872794 if ( sendMessageRef . current ) {
873- sendMessageRef . current ( initialPrompt , { agentMode } )
795+ sendMessageRef . current ( { content : initialPrompt , agentMode } )
874796 }
875797 } , 100 )
876798
@@ -888,28 +810,29 @@ export const App = ({
888810 )
889811
890812 const handleSubmit = useCallback (
891- ( ) => handleSlashCommands ( {
892- abortControllerRef,
893- agentMode,
894- inputRef,
895- inputValue,
896- isChainInProgressRef,
897- isStreaming,
898- logoutMutation,
899- streamMessageIdRef,
900- addToQueue,
901- handleCtrlC,
902- saveToHistory,
903- scrollToLatest,
904- sendMessage,
905- setCanProcessQueue,
906- setInputFocused,
907- setInputValue,
908- setIsAuthenticated,
909- setMessages,
910- setUser,
911- stopStreaming,
912- } ) ,
813+ ( ) =>
814+ handleSlashCommands ( {
815+ abortControllerRef,
816+ agentMode,
817+ inputRef,
818+ inputValue,
819+ isChainInProgressRef,
820+ isStreaming,
821+ logoutMutation,
822+ streamMessageIdRef,
823+ addToQueue,
824+ handleCtrlC,
825+ saveToHistory,
826+ scrollToLatest,
827+ sendMessage,
828+ setCanProcessQueue,
829+ setInputFocused,
830+ setInputValue,
831+ setIsAuthenticated,
832+ setMessages,
833+ setUser,
834+ stopStreaming,
835+ } ) ,
913836 [
914837 inputValue ,
915838 isStreaming ,
0 commit comments