Skip to content

Commit

Permalink
(fix) actions.ts: restored handleAssistantMessage handling order (#4074)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobitege authored Sep 26, 2024
1 parent c919086 commit 29c34e0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/AgentStatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ function AgentStatusBar() {
const [statusMessage, setStatusMessage] = React.useState<string>("");

React.useEffect(() => {
const trimmedCustomMessage = curStatusMessage.message.trim();
const trimmedCustomMessage = curStatusMessage.status.trim();
if (trimmedCustomMessage) {
setStatusMessage(t(trimmedCustomMessage));
} else {
setStatusMessage(AgentStatusMap[curAgentState].message);
}
}, [curAgentState, curStatusMessage.message]);
}, [curAgentState, curStatusMessage.status]);

return (
<div className="flex flex-col items-center">
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/services/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ export function handleActionMessage(message: ActionMessage) {
}

export function handleStatusMessage(message: StatusMessage) {
const msg = message.message == null ? "" : message.message.trim();
const msg = message.status == null ? "" : message.status.trim();
store.dispatch(
setCurStatusMessage({
...message,
message: msg,
status: msg,
}),
);
}
Expand All @@ -160,9 +160,9 @@ export function handleAssistantMessage(data: string | SocketMessage) {

if ("action" in socketMessage) {
handleActionMessage(socketMessage);
} else if ("observation" in socketMessage) {
handleObservationMessage(socketMessage);
} else if ("message" in socketMessage) {
} else if ("status" in socketMessage) {
handleStatusMessage(socketMessage);
} else {
handleObservationMessage(socketMessage);
}
}
2 changes: 1 addition & 1 deletion frontend/src/state/statusSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { StatusMessage } from "#/types/Message";

const initialStatusMessage: StatusMessage = {
message: "",
status: "",
is_error: false,
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ export interface StatusMessage {
is_error: boolean;

// A status message to display to the user
message: string;
status: string;
}
21 changes: 15 additions & 6 deletions openhands/server/session/agent_session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio

from threading import Thread
from typing import Callable, Optional

Expand Down Expand Up @@ -76,10 +75,20 @@ async def start(
self.thread = Thread(target=self._run, daemon=True)
self.thread.start()

coro = self._start(runtime_name, config, agent, max_iterations, max_budget_per_task, agent_to_llm_config, agent_configs, status_message_callback)
asyncio.run_coroutine_threadsafe(coro, self.loop) # type: ignore
coro = self._start(
runtime_name,
config,
agent,
max_iterations,
max_budget_per_task,
agent_to_llm_config,
agent_configs,
status_message_callback,
)
asyncio.run_coroutine_threadsafe(coro, self.loop) # type: ignore

async def _start(self,
async def _start(
self,
runtime_name: str,
config: AppConfig,
agent: Agent,
Expand All @@ -103,8 +112,8 @@ async def _start(self,
ChangeAgentStateAction(AgentState.INIT), EventSource.USER
)
if self.controller:
self.controller.agent_task = self.controller.start_step_loop()
await self.controller.agent_task # type: ignore
self.controller.agent_task = self.controller.start_step_loop()
await self.controller.agent_task # type: ignore

def _run(self):
asyncio.set_event_loop(self.loop)
Expand Down
6 changes: 5 additions & 1 deletion openhands/server/session/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ async def send_message(self, message: str) -> bool:
"""Sends a message to the client."""
return await self.send({'message': message})

async def send_status_message(self, message: str) -> bool:
"""Sends a status message to the client."""
return await self.send({'status': message})

def update_connection(self, ws: WebSocket):
self.websocket = ws
self.is_alive = True
Expand All @@ -202,4 +206,4 @@ def load_from_data(self, data: dict) -> bool:
def queue_status_message(self, message: str):
"""Queues a status message to be sent asynchronously."""
# Ensure the coroutine runs in the main event loop
asyncio.run_coroutine_threadsafe(self.send_message(message), self.loop)
asyncio.run_coroutine_threadsafe(self.send_status_message(message), self.loop)

0 comments on commit 29c34e0

Please sign in to comment.