Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions frontend/src/context/ws-client-provider.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/query/use-conversation-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
11 changes: 5 additions & 6 deletions frontend/src/hooks/query/use-list-files.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/_oh.app/hooks/use-ws-status-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const useWSStatusChange = () => {
}
statusRef.current = status;

if (status === WsClientProviderStatus.CONNECTED && initialQuery) {
if (status !== WsClientProviderStatus.DISCONNECTED && initialQuery) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason for these flips? Or just a remnant of the original implementation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are remnants of the original implementation, but are also helpful in the (unlikely) case we extend the WsClientProviderStatus enum

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LMK if you think we should change it, should be a minute-PR

dispatch(
addUserMessage({
content: initialQuery,
Expand Down
Loading