Skip to content

Commit b100c54

Browse files
committed
defer the file processing until press send
1 parent 9a363ab commit b100c54

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

AgentCrew/modules/chat/message/command_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def _handle_file_command(self, user_input: str) -> CommandResult:
458458

459459
# Process each file
460460
for file_path in file_paths:
461-
self.message_handler._notify("file_processing", {"file_path": file_path})
461+
# self.message_handler._notify("file_processing", {"file_path": file_path})
462462

463463
# Process file with the file handling service
464464
if self.message_handler.file_handler is None:

AgentCrew/modules/chat/message/handler.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import Tuple, Optional
1+
from typing import Tuple, Optional, List
2+
import os
3+
import shlex
24
import traceback
35
import time
46

@@ -55,6 +57,7 @@ def __init__(
5557
self.current_user_input_idx = -1
5658
self.last_assisstant_response_idx = -1
5759
self.file_handler: Optional[FileHandler] = None
60+
self._queued_attached_files = []
5861
self.stop_streaming = False
5962
self.streamline_messages = []
6063
self.current_conversation_id: Optional[str] = None # ID for persistence
@@ -75,6 +78,18 @@ def _messages_append(self, message):
7578
)
7679
self.streamline_messages.extend(std_msg)
7780

81+
def _prepare_files_processing(self, file_command):
82+
self._queued_attached_files.append(file_command)
83+
file_paths_str: str = file_command[6:].strip()
84+
file_paths: List[str] = [
85+
os.path.expanduser(path.strip())
86+
for path in shlex.split(file_paths_str)
87+
if path.strip()
88+
]
89+
90+
for file_path in file_paths:
91+
self._notify("file_processing", {"file_path": file_path})
92+
7893
async def process_user_input(
7994
self,
8095
user_input: str,
@@ -90,6 +105,10 @@ async def process_user_input(
90105
"""
91106
self.history_manager.add_entry(user_input)
92107

108+
if user_input.startswith("/file "):
109+
self._prepare_files_processing(user_input)
110+
return False, True
111+
93112
# Process commands first
94113
command_result = await self.command_processor.process_command(user_input)
95114
if command_result.handled:
@@ -122,6 +141,13 @@ async def process_user_input(
122141
# ],
123142
# }
124143
# )
144+
145+
# Delays file processing until user send message
146+
147+
while len(self._queued_attached_files) > 0:
148+
file_command = self._queued_attached_files.pop(0)
149+
await self.command_processor.process_command(file_command)
150+
125151
# Add regular text message
126152
self._messages_append(
127153
{"role": "user", "content": [{"type": "text", "text": user_input}]}

AgentCrew/modules/console/console_ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def listen(self, event: str, data: Any = None):
181181
self.display_handlers.display_message(preview_text)
182182
elif event == "thinking_completed":
183183
self.display_handlers.display_divider()
184-
elif event == "file_processed":
184+
elif event == "file_processing":
185185
self.ui_effects.stop_loading_animation() # Stop loading on first chunk
186186
self.display_handlers.add_file(data["file_path"])
187187
elif event == "consolidation_completed":

AgentCrew/modules/console/input_handler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def _input_thread_worker(self):
192192

193193
# Put the input in the queue
194194
self._input_queue.put(user_input)
195-
time.sleep(0.1) # Allow time for input processing
195+
time.sleep(0.4) # Allow time for input processing
196196

197197
except KeyboardInterrupt:
198198
# Handle Ctrl+C in input thread
@@ -267,7 +267,6 @@ def get_user_input(self):
267267
self.display_handlers.print_prompt_prefix(
268268
self.message_handler.agent.name, self.message_handler.agent.get_model()
269269
)
270-
time.sleep(0.4) # prevent conflict
271270
self.clear_buffer()
272271

273272
# Wait for input while allowing events to be processed

AgentCrew/modules/gui/qt_ui.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ def __init__(self, message_handler: MessageHandler):
194194
self.current_file_bubble = None
195195
self.thinking_content = ""
196196
self.expecting_response = False
197-
self._is_file_processing = False
198197
self._delegated_user_input = None
199198

200199
# Track session cost
@@ -262,11 +261,6 @@ def send_message(self):
262261
self.current_response_bubble = None
263262
self.current_response_container = None
264263

265-
# Send the request to worker thread via signal
266-
# This is thread-safe and doesn't require QMetaObject.invokeMethod
267-
if self._is_file_processing:
268-
self._delegated_user_input = user_input
269-
return
270264
# Update status bar
271265
self.display_status_message("Processing your message...")
272266
self.llm_worker.process_request.emit(user_input)
@@ -504,26 +498,19 @@ def handle_event(self, event: str, data: Any):
504498
if self.current_file_bubble:
505499
self.chat_components.remove_messages_after(self.current_file_bubble)
506500
self.current_file_bubble = None
507-
self._is_file_processing = False
508501
self.display_error(data)
509502
elif event == "consolidation_completed":
510503
self.conversation_components.display_consolidation(data)
511504
self.ui_state_manager.set_input_controls_enabled(True)
512505
elif event == "file_processing":
513-
self._is_file_processing = True
514506
file_path = data["file_path"]
515507
self.current_file_bubble = self.chat_components.append_file(
516508
file_path, is_user=True
517509
)
518510
if not self.loading_conversation:
519511
self.ui_state_manager.set_input_controls_enabled(True)
520512
elif event == "file_processed":
521-
if self._is_file_processing:
522-
if self._delegated_user_input:
523-
self.llm_worker.process_request.emit(self._delegated_user_input)
524-
self._delegated_user_input = None
525-
self.current_file_bubble = None
526-
self._is_file_processing = False
513+
self.current_file_bubble = None
527514
elif event == "image_generated":
528515
self.chat_components.append_file(data, False, True)
529516
# Command-related events are now handled by command_handler above

0 commit comments

Comments
 (0)