Skip to content

πŸ™Œ OpenHands: AI-Driven Development

feat(frontend): Add active status for ws (#5944)

sp.wackeb93113b7a76
diff --git a/frontend/src/context/ws-client-provider.tsx b/frontend/src/context/ws-client-provider.tsx
index 19137c8182..4a55f661cd 100644
--- a/frontend/src/context/ws-client-provider.tsx
+++ b/frontend/src/context/ws-client-provider.tsx
@@ -1,13 +1,18 @@
import posthog from "posthog-js";
import React from "react";
import { io, Socket } from "socket.io-client";
-
import EventLogger from "#/utils/event-logger";
import { handleAssistantMessage } from "#/services/actions";
import { useRate } from "#/hooks/use-rate";
-
-const isOpenHandsMessage = (event: Record<string, unknown>) =>
- event.action === "message";
+import { OpenHandsParsedEvent } from "#/types/core";
+
+const isOpenHandsMessage = (event: unknown): event is OpenHandsParsedEvent =>
+ typeof event === "object" &&
+ event !== null &&
+ "id" in event &&
+ "source" in event &&
+ "message" in event &&
+ "timestamp" in event;
export enum WsClientProviderStatus {
CONNECTED,
diff --git a/frontend/src/hooks/query/use-conversation-config.ts b/frontend/src/hooks/query/use-conversation-config.ts
index da82d0772e..35479a5f08 100644
--- a/frontend/src/hooks/query/use-conversation-config.ts
+++ b/frontend/src/hooks/query/use-conversation-config.ts
@@ -17,7 +17,7 @@ export const useConversationConfig = () => {
if (!conversationId) throw new Error("No conversation ID");
return OpenHands.getRuntimeId(conversationId);
},
- enabled: status === WsClientProviderStatus.CONNECTED && !!conversationId,
+ enabled: status !== WsClientProviderStatus.DISCONNECTED && !!conversationId,
});
React.useEffect(() => {
diff --git a/frontend/src/hooks/query/use-list-files.ts b/frontend/src/hooks/query/use-list-files.ts
index 086baa2f52..e1896c9e21 100644
--- a/frontend/src/hooks/query/use-list-files.ts
+++ b/frontend/src/hooks/query/use-list-files.ts
@@ -1,10 +1,9 @@
import { useQuery } from "@tanstack/react-query";
-import {
- useWsClient,
- WsClientProviderStatus,
-} from "#/context/ws-client-provider";
+import { useSelector } from "react-redux";
import OpenHands from "#/api/open-hands";
import { useConversation } from "#/context/conversation-context";
+import { RootState } from "#/store";
+import { RUNTIME_INACTIVE_STATES } from "#/types/agent-state";
interface UseListFilesConfig {
path?: string;
@@ -17,8 +16,8 @@ const DEFAULT_CONFIG: UseListFilesConfig = {
export const useListFiles = (config: UseListFilesConfig = DEFAULT_CONFIG) => {
const { conversationId } = useConversation();
- const { status } = useWsClient();
- const isActive = status === WsClientProviderStatus.CONNECTED;
+ const { curAgentState } = useSelector((state: RootState) => state.agent);
+ const isActive = !RUNTIME_INACTIVE_STATES.includes(curAgentState);
return useQuery({
queryKey: ["files", conversationId, config?.path],
diff --git a/frontend/src/routes/_oh.app/hooks/use-ws-status-change.ts b/frontend/src/routes/_oh.app/hooks/use-ws-status-change.ts
index 1b1c4c69ae..538d868f87 100644
--- a/frontend/src/routes/_oh.app/hooks/use-ws-status-change.ts
+++ b/frontend/src/routes/_oh.app/hooks/use-ws-status-change.ts
@@ -71,7 +71,7 @@ export const useWSStatusChange = () => {
}
statusRef.current = status;
- if (status === WsClientProviderStatus.CONNECTED && initialQuery) {
+ if (status !== WsClientProviderStatus.DISCONNECTED && initialQuery) {
dispatch(
addUserMessage({
content: initialQuery,