Fixed stdout
This commit is contained in:
@@ -14,6 +14,7 @@ class ClientMessage:
|
||||
APPROVE_RESPONSE = "APPROVE_RESPONSE"
|
||||
MODIFY_RESPONSE = "MODIFY_RESPONSE"
|
||||
SEND_INPUT = "SEND_INPUT"
|
||||
CLEAR_OUTPUT = "CLEAR_OUTPUT"
|
||||
|
||||
@dataclass
|
||||
class ServerMessage:
|
||||
@@ -41,6 +42,7 @@ class WebSocketManager:
|
||||
self.agent.add_state_change_handler(self._wrap_async(self._handle_state_change))
|
||||
self.agent.add_context_change_handler(self._wrap_async(self._handle_context_change))
|
||||
self.agent.add_response_change_handler(self._wrap_async(self._handle_response_change))
|
||||
self.io_buffer.add_stdout_change_handler(self._wrap_async(self._handle_stdout_change))
|
||||
return self
|
||||
|
||||
async def _broadcast_message(self, message: Dict):
|
||||
@@ -89,6 +91,13 @@ class WebSocketManager:
|
||||
"response": response,
|
||||
"validation_error": validation_error
|
||||
})
|
||||
|
||||
async def _handle_stdout_change(self, output: str):
|
||||
"""Handle output changes from the WebAgent."""
|
||||
await self._broadcast_message({
|
||||
"type": ServerMessage.OUTPUT_UPDATE,
|
||||
"output": output
|
||||
})
|
||||
|
||||
async def _handle_client_message(self, request: web.Request, data: dict[str, Any]):
|
||||
"""Handle incoming client message."""
|
||||
@@ -109,6 +118,8 @@ class WebSocketManager:
|
||||
self.agent.modify_response(data.get("response"))
|
||||
elif message_type == ClientMessage.SEND_INPUT:
|
||||
self.io_buffer.append_stdin(data.get("input"))
|
||||
elif message_type == ClientMessage.CLEAR_OUTPUT:
|
||||
self.io_buffer.clear_stdout()
|
||||
|
||||
async def handle_websocket(self, request: web.Request) -> web.WebSocketResponse:
|
||||
"""Handle new WebSocket connections and messages."""
|
||||
|
||||
Reference in New Issue
Block a user