@@ -58,11 +58,7 @@ const ws = new CommsWs({
5858 } ,
5959 onClose : ( ) => {
6060 state . setConnected ( false ) ;
61- renderSystemMessage (
62- document ,
63- messageTarget ,
64- "Disconnected — reconnecting..." ,
65- ) ;
61+ renderSystemMessage ( document , messageTarget , "Disconnected — reconnecting..." ) ;
6662 } ,
6763 onFrame : handleFrame ,
6864} ) ;
@@ -90,7 +86,10 @@ function handleFrame(frame: WsFrame): void {
9086 renderSystemMessage ( document , messageTarget , frame . result . content ) ;
9187 if ( ! frame . result . isError ) {
9288 // Auto-switch current room after successful join_room via command
93- if ( pendingAction ?. action === "join_room" && ! state . get ( ) . currentRoom ) {
89+ if (
90+ pendingAction ?. action === "join_room" &&
91+ ! state . get ( ) . currentRoom
92+ ) {
9493 const roomId = pendingAction . room ;
9594 state . setDmTarget ( undefined ) ;
9695 state . setCurrentRoom ( roomId ) ;
@@ -123,13 +122,15 @@ function sendAction(action: Action): void {
123122}
124123
125124async function refreshState ( ) : Promise < void > {
126- const [ agents , rooms ] = await Promise . all ( [ fetchAgents ( ) , fetchRooms ( ) ] ) ;
125+ const [ agents , rooms ] = await Promise . all ( [
126+ fetchAgents ( ) ,
127+ fetchRooms ( ) ,
128+ ] ) ;
127129 state . setAgents ( agents ) ;
128130 state . setRooms ( rooms ) ;
129131}
130132
131133async function onJoinRoom ( roomId : string ) : Promise < void > {
132- state . setDmTarget ( undefined ) ;
133134 state . setCurrentRoom ( roomId ) ;
134135 renderHeader ( { headerEl } , roomId ) ;
135136 clearMessages ( messageTarget ) ;
@@ -140,30 +141,18 @@ async function onJoinRoom(roomId: string): Promise<void> {
140141 const messages = await fetchRoomMessages ( roomId ) ;
141142 renderMessageHistory ( document , messageTarget , messages ) ;
142143 renderSystemMessage ( document , messageTarget , `Joined ${ roomId } ` ) ;
143- inputRaw . focus ( ) ;
144- }
145-
146- function onSelectAgent ( agentId : string ) : void {
147- state . setCurrentRoom ( undefined ) ;
148- state . setDmTarget ( agentId ) ;
149- clearMessages ( messageTarget ) ;
150- renderHeader ( { headerEl } , `DM with ${ agentId } ` ) ;
151- inputRaw . focus ( ) ;
144+ inputEl . focus ( ) ;
152145}
153146
154147// ---------------------------------------------------------------------------
155148// Input handling
156149// ---------------------------------------------------------------------------
157150
158151function handleInput ( ) : void {
159- const text = inputRaw . value ;
160- inputRaw . value = "" ;
152+ const text = inputEl . value ;
153+ inputEl . value = "" ;
161154
162- const result = parseInput (
163- text ,
164- state . get ( ) . currentRoom ,
165- state . get ( ) . dmTarget ,
166- ) ;
155+ const result = parseInput ( text , state . get ( ) . currentRoom , state . get ( ) . dmTarget ) ;
167156
168157 switch ( result . kind ) {
169158 case "action" :
@@ -179,7 +168,7 @@ function handleInput(): void {
179168
180169const sendBtn = requireElement ( document , "#send-btn" ) ;
181170sendBtn . onclick = handleInput ;
182- inputRaw . addEventListener ( "keydown" , ( e : KeyboardEvent ) => {
171+ inputEl . addEventListener ( "keydown" , ( e : KeyboardEvent ) => {
183172 if ( e . key === "Enter" ) handleInput ( ) ;
184173} ) ;
185174
@@ -189,4 +178,4 @@ inputRaw.addEventListener("keydown", (e: KeyboardEvent) => {
189178
190179ws . connect ( ) ;
191180void refreshState ( ) ;
192- inputRaw . focus ( ) ;
181+ inputEl . focus ( ) ;
0 commit comments