@@ -2,17 +2,11 @@ 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
9+ import { routeUserPrompt } from './commands/router'
1610import { AgentModeToggle } from './components/agent-mode-toggle'
1711import { LoginModal } from './components/login-modal'
1812import {
@@ -49,92 +43,32 @@ import {
4943} from './utils/local-agent-registry'
5044import { logger } from './utils/logger'
5145import { buildMessageTree } from './utils/message-tree-utils'
46+ import { openFileAtPath } from './utils/open-file'
5247import { handleSlashCommands } from './utils/slash-commands'
5348import {
49+ chatThemes ,
5450 createMarkdownPalette ,
5551 resolveThemeColor ,
56- type ChatTheme ,
5752} from './utils/theme-system'
5853import { env } from '@codebuff/common/env'
5954import { clientEnvVars } from '@codebuff/common/env-schema'
6055import { formatValidationError } from './utils/validation-error-formatting'
6156import { getCodebuffClient } from './utils/codebuff-client'
62- import { openFileAtPath } from './utils/open-file'
6357
6458import type { SendMessageTimerEvent } from './hooks/use-send-message'
59+ import type {
60+ ChatMessage ,
61+ ContentBlock ,
62+ ChatVariant ,
63+ AgentMessage ,
64+ } from './types/chat'
65+ import type { SendMessageFn } from './types/contracts/send-message'
6566import type { User } from './utils/auth'
66- import type { AgentMode } from './utils/constants'
67- import type { ToolName } from '@codebuff/sdk'
6867import type { ScrollBoxRenderable } from '@opentui/core'
6968
70- type ChatVariant = 'ai' | 'user' | 'agent' | 'error'
71-
7269const MAX_VIRTUALIZED_TOP_LEVEL = 60
7370const VIRTUAL_OVERSCAN = 12
7471
75- type AgentMessage = {
76- agentName : string
77- agentType : string
78- responseCount : number
79- subAgentCount ?: number
80- }
81-
82- export type ContentBlock =
83- | {
84- type : 'text'
85- content : string
86- color ?: string
87- marginTop ?: number
88- marginBottom ?: number
89- status ?: 'running' | 'complete'
90- }
91- | {
92- type : 'html'
93- marginTop ?: number
94- marginBottom ?: number
95- render : ( context : { textColor : string ; theme : ChatTheme } ) => ReactNode
96- }
97- | {
98- type : 'tool'
99- toolCallId : string
100- toolName : ToolName
101- input : any
102- output ?: string
103- outputRaw ?: unknown
104- agentId ?: string
105- }
106- | {
107- type : 'agent'
108- agentId : string
109- agentName : string
110- agentType : string
111- content : string
112- status : 'running' | 'complete'
113- blocks ?: ContentBlock [ ]
114- initialPrompt ?: string
115- }
116- | {
117- type : 'agent-list'
118- id : string
119- agents : Array < { id : string ; displayName : string } >
120- agentsDir : string
121- }
122-
123- export type ChatMessage = {
124- id : string
125- variant : ChatVariant
126- content : string
127- blocks ?: ContentBlock [ ]
128- timestamp : string
129- parentId ?: string
130- agent ?: AgentMessage
131- isCompletion ?: boolean
132- credits ?: number
133- completionTime ?: string
134- isComplete ?: boolean
135- metadata ?: Record < string , any >
136- }
137-
13872export const App = ( {
13973 initialPrompt,
14074 agentId,
@@ -927,10 +861,7 @@ export const App = ({
927861 setInputValue ,
928862 )
929863
930- const sendMessageRef =
931- useRef <
932- ( content : string , params : { agentMode : AgentMode } ) => Promise < void >
933- > ( )
864+ const sendMessageRef = useRef < SendMessageFn > ( )
934865
935866 const {
936867 queuedMessages,
@@ -945,7 +876,7 @@ export const App = ({
945876 setIsStreaming,
946877 } = useMessageQueue (
947878 ( content : string ) =>
948- sendMessageRef . current ?.( content , { agentMode } ) ?? Promise . resolve ( ) ,
879+ sendMessageRef . current ?.( { content, agentMode } ) ?? Promise . resolve ( ) ,
949880 isChainInProgressRef ,
950881 activeAgentStreamsRef ,
951882 )
@@ -1009,7 +940,7 @@ export const App = ({
1009940 const timeout = setTimeout ( ( ) => {
1010941 logger . info ( { prompt : initialPrompt } , 'Auto-submitting initial prompt' )
1011942 if ( sendMessageRef . current ) {
1012- sendMessageRef . current ( initialPrompt , { agentMode } )
943+ sendMessageRef . current ( { content : initialPrompt , agentMode } )
1013944 }
1014945 } , 100 )
1015946
@@ -1027,28 +958,29 @@ export const App = ({
1027958 )
1028959
1029960 const handleSubmit = useCallback (
1030- ( ) => handleSlashCommands ( {
1031- abortControllerRef,
1032- agentMode,
1033- inputRef,
1034- inputValue,
1035- isChainInProgressRef,
1036- isStreaming,
1037- logoutMutation,
1038- streamMessageIdRef,
1039- addToQueue,
1040- handleCtrlC,
1041- saveToHistory,
1042- scrollToLatest,
1043- sendMessage,
1044- setCanProcessQueue,
1045- setInputFocused,
1046- setInputValue,
1047- setIsAuthenticated,
1048- setMessages,
1049- setUser,
1050- stopStreaming,
1051- } ) ,
961+ ( ) =>
962+ routeUserPrompt ( {
963+ abortControllerRef,
964+ agentMode,
965+ inputRef,
966+ inputValue,
967+ isChainInProgressRef,
968+ isStreaming,
969+ logoutMutation,
970+ streamMessageIdRef,
971+ addToQueue,
972+ handleCtrlC,
973+ saveToHistory,
974+ scrollToLatest,
975+ sendMessage,
976+ setCanProcessQueue,
977+ setInputFocused,
978+ setInputValue,
979+ setIsAuthenticated,
980+ setMessages,
981+ setUser,
982+ stopStreaming,
983+ } ) ,
1052984 [
1053985 agentMode ,
1054986 inputValue ,
0 commit comments