@@ -109,11 +109,24 @@ export class AIChatModel extends AbstractChatModel {
109109 this . _agentManager = options . agentManager ;
110110 this . _trans = options . trans ;
111111
112- // Listen for agent events
112+ // Listen for agent events and busy state
113113 this . _agentManager . agentEvent . connect ( this . _onAgentEvent , this ) ;
114+ this . _agentManager . busyChanged . connect ( ( _ , busy ) => {
115+ this . _busyChanged . emit ( busy ) ;
116+ } ) ;
114117
115118 // Listen for settings changes to update chat behavior
116119 this . _settingsModel . stateChanged . connect ( this . _onSettingsChanged , this ) ;
120+
121+ // Prevent clearing input field when agent is busy.
122+ const originalSend = this . input . send ;
123+ this . input . send = ( content : string ) => {
124+ if ( this . _agentManager . busy ) {
125+ return ;
126+ }
127+ originalSend ( content ) ;
128+ } ;
129+
117130 this . setReady ( ) ;
118131 }
119132
@@ -156,6 +169,20 @@ export class AIChatModel extends AbstractChatModel {
156169 return this . _agentManager ;
157170 }
158171
172+ /**
173+ * Whether the agent is currently busy generating a response or executing tools.
174+ */
175+ get busy ( ) : boolean {
176+ return this . _agentManager . busy ;
177+ }
178+
179+ /**
180+ * A signal emitted when the busy state changes.
181+ */
182+ get busyChanged ( ) : ISignal < this, boolean > {
183+ return this . _busyChanged ;
184+ }
185+
159186 /**
160187 * Creates a chat context for the current conversation.
161188 */
@@ -214,6 +241,11 @@ export class AIChatModel extends AbstractChatModel {
214241 return ;
215242 }
216243
244+ // Prevent sending multiple messages concurrently
245+ if ( this . _agentManager . busy ) {
246+ return ;
247+ }
248+
217249 // Add user message to chat
218250 const userMessage : IMessageContent = {
219251 body : message . body ,
@@ -916,6 +948,7 @@ export class AIChatModel extends AbstractChatModel {
916948 }
917949
918950 // Private fields
951+ private _busyChanged = new Signal < this, boolean > ( this ) ;
919952 private _settingsModel : AISettingsModel ;
920953 private _user : IUser ;
921954 private _toolContexts : Map < string , IToolExecutionContext > = new Map ( ) ;
0 commit comments