@@ -17,31 +17,34 @@ import { HumanRelayDialog } from "./components/human-relay/HumanRelayDialog"
1717
1818type Tab = "settings" | "history" | "mcp" | "prompts" | "chat"
1919
20+ type HumanRelayDialogState = {
21+ isOpen : boolean
22+ requestId : string
23+ promptText : string
24+ }
25+
2026const tabsByMessageAction : Partial < Record < NonNullable < ExtensionMessage [ "action" ] > , Tab > > = {
2127 chatButtonClicked : "chat" ,
2228 settingsButtonClicked : "settings" ,
2329 promptsButtonClicked : "prompts" ,
2430 mcpButtonClicked : "mcp" ,
2531 historyButtonClicked : "history" ,
2632}
33+
2734const App = ( ) => {
2835 const { didHydrateState, showWelcome, shouldShowAnnouncement, telemetrySetting, telemetryKey, machineId } =
2936 useExtensionState ( )
37+
3038 const [ showAnnouncement , setShowAnnouncement ] = useState ( false )
3139 const [ tab , setTab ] = useState < Tab > ( "chat" )
32- const settingsRef = useRef < SettingsViewRef > ( null )
33-
34- // Human Relay Dialog Status
35- const [ humanRelayDialogState , setHumanRelayDialogState ] = useState < {
36- isOpen : boolean
37- requestId : string
38- promptText : string
39- } > ( {
40+ const [ humanRelayDialogState , setHumanRelayDialogState ] = useState < HumanRelayDialogState > ( {
4041 isOpen : false ,
4142 requestId : "" ,
4243 promptText : "" ,
4344 } )
4445
46+ const settingsRef = useRef < SettingsViewRef > ( null )
47+
4548 const switchTab = useCallback ( ( newTab : Tab ) => {
4649 if ( settingsRef . current ?. checkUnsaveChanges ) {
4750 settingsRef . current . checkUnsaveChanges ( ( ) => setTab ( newTab ) )
@@ -74,23 +77,6 @@ const App = () => {
7477 [ switchTab ] ,
7578 )
7679
77- // Processing Human Relay Dialog Submission
78- const handleHumanRelaySubmit = ( requestId : string , text : string ) => {
79- vscode . postMessage ( {
80- type : "humanRelayResponse" ,
81- requestId,
82- text,
83- } )
84- }
85-
86- // Handle Human Relay dialog box cancel
87- const handleHumanRelayCancel = ( requestId : string ) => {
88- vscode . postMessage ( {
89- type : "humanRelayCancel" ,
90- requestId,
91- } )
92- }
93-
9480 useEvent ( "message" , onMessage )
9581
9682 useEffect ( ( ) => {
@@ -106,7 +92,7 @@ const App = () => {
10692 }
10793 } , [ telemetrySetting , telemetryKey , machineId , didHydrateState ] )
10894
109- // Tell Extension that we are ready to receive messages
95+ // Tell the extension that we are ready to receive messages.
11096 useEffect ( ( ) => {
11197 vscode . postMessage ( { type : "webviewDidLaunch" } )
11298 } , [ ] )
@@ -121,24 +107,23 @@ const App = () => {
121107 < WelcomeView />
122108 ) : (
123109 < >
124- { tab === "settings" && < SettingsView ref = { settingsRef } onDone = { ( ) => setTab ( "chat" ) } /> }
125- { tab === "history" && < HistoryView onDone = { ( ) => switchTab ( "chat" ) } /> }
126- { tab === "mcp" && < McpView onDone = { ( ) => switchTab ( "chat" ) } /> }
127110 { tab === "prompts" && < PromptsView onDone = { ( ) => switchTab ( "chat" ) } /> }
111+ { tab === "mcp" && < McpView onDone = { ( ) => switchTab ( "chat" ) } /> }
112+ { tab === "history" && < HistoryView onDone = { ( ) => switchTab ( "chat" ) } /> }
113+ { tab === "settings" && < SettingsView ref = { settingsRef } onDone = { ( ) => setTab ( "chat" ) } /> }
128114 < ChatView
129115 isHidden = { tab !== "chat" }
130116 showAnnouncement = { showAnnouncement }
131117 hideAnnouncement = { ( ) => setShowAnnouncement ( false ) }
132118 showHistoryView = { ( ) => switchTab ( "history" ) }
133119 />
134- { /* Human Relay Dialog */ }
135120 < HumanRelayDialog
136121 isOpen = { humanRelayDialogState . isOpen }
137122 requestId = { humanRelayDialogState . requestId }
138123 promptText = { humanRelayDialogState . promptText }
139124 onClose = { ( ) => setHumanRelayDialogState ( ( prev ) => ( { ...prev , isOpen : false } ) ) }
140- onSubmit = { handleHumanRelaySubmit }
141- onCancel = { handleHumanRelayCancel }
125+ onSubmit = { ( requestId , text ) => vscode . postMessage ( { type : "humanRelayResponse" , requestId , text } ) }
126+ onCancel = { ( requestId ) => vscode . postMessage ( { type : "humanRelayCancel" , requestId } ) }
142127 />
143128 </ >
144129 )
@@ -147,6 +132,7 @@ const App = () => {
147132const AppWithProviders = ( ) => (
148133 < ExtensionStateContextProvider >
149134 < App />
135+ < div id = "roo-portal" />
150136 </ ExtensionStateContextProvider >
151137)
152138
0 commit comments