1- import { TextAttributes } from '@opentui/core'
2- import { useRenderer , useTerminalDimensions } from '@opentui/react'
31import os from 'os'
42import path from 'path'
3+
4+ import { useRenderer , useTerminalDimensions } from '@opentui/react'
55import React , {
66 type ReactNode ,
77 useCallback ,
@@ -15,14 +15,14 @@ import { useShallow } from 'zustand/react/shallow'
1515
1616import { AgentModeToggle } from './components/agent-mode-toggle'
1717import { LoginModal } from './components/login-modal'
18- import { TerminalLink } from './components/terminal-link'
1918import {
2019 MultilineInput ,
2120 type MultilineInputHandle ,
2221} from './components/multiline-input'
2322import { Separator } from './components/separator'
2423import { StatusIndicator , useHasStatus } from './components/status-indicator'
2524import { SuggestionMenu } from './components/suggestion-menu'
25+ import { TerminalLink } from './components/terminal-link'
2626import { SLASH_COMMANDS } from './data/slash-commands'
2727import { useAgentValidation } from './hooks/use-agent-validation'
2828import { useAuthQuery , useLogoutMutation } from './hooks/use-auth-query'
@@ -35,30 +35,32 @@ import { useMessageQueue } from './hooks/use-message-queue'
3535import { useMessageRenderer } from './hooks/use-message-renderer'
3636import { useChatScrollbox } from './hooks/use-scroll-management'
3737import { useSendMessage } from './hooks/use-send-message'
38- import type { SendMessageTimerEvent } from './hooks/use-send-message'
3938import { useSuggestionEngine } from './hooks/use-suggestion-engine'
4039import { useSystemThemeDetector } from './hooks/use-system-theme-detector'
4140import { useChatStore } from './state/chat-store'
4241import { flushAnalytics } from './utils/analytics'
4342import { getUserCredentials } from './utils/auth'
4443import { createChatScrollAcceleration } from './utils/chat-scroll-accel'
44+ import { createValidationErrorBlocks } from './utils/create-validation-error-blocks'
4545import { formatQueuedPreview } from './utils/helpers'
4646import {
4747 loadLocalAgents ,
4848 type LocalAgentInfo ,
4949} from './utils/local-agent-registry'
5050import { logger } from './utils/logger'
5151import { buildMessageTree } from './utils/message-tree-utils'
52+ import { openFileAtPath } from './utils/open-file'
53+ import { handleSlashCommands } from './utils/slash-commands'
5254import {
5355 chatThemes ,
5456 createMarkdownPalette ,
5557 type ChatTheme ,
5658} from './utils/theme-system'
57- import { openFileAtPath } from './utils/open-file'
5859import { formatValidationError } from './utils/validation-error-formatting'
59- import { createValidationErrorBlocks } from './utils/create-validation-error-blocks'
6060
61+ import type { SendMessageTimerEvent } from './hooks/use-send-message'
6162import type { User } from './utils/auth'
63+ import type { AgentMode } from './utils/constants'
6264import type { ToolName } from '@codebuff/sdk'
6365import type { ScrollBoxRenderable } from '@opentui/core'
6466
@@ -788,7 +790,7 @@ export const App = ({
788790
789791 const sendMessageRef =
790792 useRef <
791- ( content : string , params : { agentMode : 'FAST' | 'MAX' } ) => Promise < void >
793+ ( content : string , params : { agentMode : AgentMode } ) => Promise < void >
792794 > ( )
793795
794796 const {
@@ -885,86 +887,41 @@ export const App = ({
885887 mainAgentTimer ,
886888 )
887889
888- const handleSubmit = useCallback ( ( ) => {
889- const trimmed = inputValue . trim ( )
890- if ( ! trimmed ) return
891-
892- const normalized = trimmed . startsWith ( '/' ) ? trimmed . slice ( 1 ) : trimmed
893- const cmd = normalized . split ( / \s + / ) [ 0 ] . toLowerCase ( )
894- if ( cmd === 'login' || cmd === 'signin' ) {
895- const msg = {
896- id : `sys-${ Date . now ( ) } ` ,
897- variant : 'ai' as const ,
898- content : "You're already in the app. Use /logout to switch accounts." ,
899- timestamp : new Date ( ) . toISOString ( ) ,
900- }
901- setMessages ( ( prev ) => [ ...prev , msg ] )
902- setInputValue ( '' )
903- return
904- }
905- if ( cmd === 'logout' || cmd === 'signout' ) {
906- abortControllerRef . current ?. abort ( )
907- stopStreaming ( )
908- setCanProcessQueue ( false )
909-
910- logoutMutation . mutate ( undefined , {
911- onSettled : ( ) => {
912- const msg = {
913- id : `sys-${ Date . now ( ) } ` ,
914- variant : 'ai' as const ,
915- content : 'Logged out.' ,
916- timestamp : new Date ( ) . toISOString ( ) ,
917- }
918- setMessages ( ( prev ) => [ ...prev , msg ] )
919- setInputValue ( '' )
920- setTimeout ( ( ) => {
921- setUser ( null )
922- setIsAuthenticated ( false )
923- } , 300 )
924- } ,
925- } )
926- return
927- }
928-
929- if ( cmd === 'exit' || cmd === 'quit' ) {
930- abortControllerRef . current ?. abort ( )
931- stopStreaming ( )
932- setCanProcessQueue ( false )
933- setInputValue ( '' )
934- handleCtrlC ( )
935- return
936- }
937-
938- saveToHistory ( trimmed )
939- setInputValue ( '' )
940-
941- if (
942- isStreaming ||
943- streamMessageIdRef . current ||
944- isChainInProgressRef . current
945- ) {
946- addToQueue ( trimmed )
947- setInputFocused ( true )
948- inputRef . current ?. focus ( )
949- return
950- }
951-
952- sendMessage ( trimmed , { agentMode } )
953-
954- setTimeout ( ( ) => {
955- scrollToLatest ( )
956- } , 0 )
957- } , [
958- inputValue ,
959- isStreaming ,
960- sendMessage ,
961- saveToHistory ,
962- addToQueue ,
963- streamMessageIdRef ,
964- isChainInProgressRef ,
965- scrollToLatest ,
966- handleCtrlC ,
967- ] )
890+ 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+ } ) ,
913+ [
914+ inputValue ,
915+ isStreaming ,
916+ sendMessage ,
917+ saveToHistory ,
918+ addToQueue ,
919+ streamMessageIdRef ,
920+ isChainInProgressRef ,
921+ scrollToLatest ,
922+ handleCtrlC ,
923+ ] ,
924+ )
968925
969926 useKeyboardHandlers ( {
970927 isStreaming,
0 commit comments