mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
fix(frontend): Trigger VSCode URL query only when runtime is active (#5622)
This commit is contained in:
parent
09735c7869
commit
dabf0ce3af
@ -15,6 +15,10 @@ import { FileExplorerHeader } from "./file-explorer-header";
|
|||||||
import { useVSCodeUrl } from "#/hooks/query/use-vscode-url";
|
import { useVSCodeUrl } from "#/hooks/query/use-vscode-url";
|
||||||
import { OpenVSCodeButton } from "#/components/shared/buttons/open-vscode-button";
|
import { OpenVSCodeButton } from "#/components/shared/buttons/open-vscode-button";
|
||||||
import { addAssistantMessage } from "#/state/chat-slice";
|
import { addAssistantMessage } from "#/state/chat-slice";
|
||||||
|
import {
|
||||||
|
useWsClient,
|
||||||
|
WsClientProviderStatus,
|
||||||
|
} from "#/context/ws-client-provider";
|
||||||
|
|
||||||
interface FileExplorerProps {
|
interface FileExplorerProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@ -22,6 +26,7 @@ interface FileExplorerProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function FileExplorer({ isOpen, onToggle }: FileExplorerProps) {
|
export function FileExplorer({ isOpen, onToggle }: FileExplorerProps) {
|
||||||
|
const { status } = useWsClient();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
@ -30,12 +35,11 @@ export function FileExplorer({ isOpen, onToggle }: FileExplorerProps) {
|
|||||||
|
|
||||||
const { curAgentState } = useSelector((state: RootState) => state.agent);
|
const { curAgentState } = useSelector((state: RootState) => state.agent);
|
||||||
|
|
||||||
const agentIsReady =
|
|
||||||
curAgentState !== AgentState.INIT && curAgentState !== AgentState.LOADING;
|
|
||||||
|
|
||||||
const { data: paths, refetch, error } = useListFiles();
|
const { data: paths, refetch, error } = useListFiles();
|
||||||
const { mutate: uploadFiles } = useUploadFiles();
|
const { mutate: uploadFiles } = useUploadFiles();
|
||||||
const { data: vscodeUrl } = useVSCodeUrl({ enabled: agentIsReady });
|
const { data: vscodeUrl } = useVSCodeUrl({
|
||||||
|
enabled: status === WsClientProviderStatus.ACTIVE,
|
||||||
|
});
|
||||||
|
|
||||||
const handleOpenVSCode = () => {
|
const handleOpenVSCode = () => {
|
||||||
if (vscodeUrl?.vscode_url) {
|
if (vscodeUrl?.vscode_url) {
|
||||||
@ -166,7 +170,7 @@ export function FileExplorer({ isOpen, onToggle }: FileExplorerProps) {
|
|||||||
{isOpen && (
|
{isOpen && (
|
||||||
<OpenVSCodeButton
|
<OpenVSCodeButton
|
||||||
onClick={handleOpenVSCode}
|
onClick={handleOpenVSCode}
|
||||||
isDisabled={!agentIsReady}
|
isDisabled={status === WsClientProviderStatus.OPENING}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import { io, Socket } from "socket.io-client";
|
|||||||
import { Settings } from "#/services/settings";
|
import { Settings } from "#/services/settings";
|
||||||
import ActionType from "#/types/action-type";
|
import ActionType from "#/types/action-type";
|
||||||
import EventLogger from "#/utils/event-logger";
|
import EventLogger from "#/utils/event-logger";
|
||||||
import AgentState from "#/types/agent-state";
|
|
||||||
import { handleAssistantMessage } from "#/services/actions";
|
import { handleAssistantMessage } from "#/services/actions";
|
||||||
import { useRate } from "#/hooks/use-rate";
|
import { useRate } from "#/hooks/use-rate";
|
||||||
|
|
||||||
@ -102,10 +101,7 @@ export function WsClientProvider({
|
|||||||
if (!Number.isNaN(parseInt(event.id as string, 10))) {
|
if (!Number.isNaN(parseInt(event.id as string, 10))) {
|
||||||
lastEventRef.current = event;
|
lastEventRef.current = event;
|
||||||
}
|
}
|
||||||
const extras = event.extras as Record<string, unknown>;
|
|
||||||
if (extras?.agent_state === AgentState.INIT) {
|
|
||||||
setStatus(WsClientProviderStatus.ACTIVE);
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
status !== WsClientProviderStatus.ACTIVE &&
|
status !== WsClientProviderStatus.ACTIVE &&
|
||||||
event?.observation === "error"
|
event?.observation === "error"
|
||||||
@ -114,6 +110,10 @@ export function WsClientProvider({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (status !== WsClientProviderStatus.ACTIVE) {
|
||||||
|
setStatus(WsClientProviderStatus.ACTIVE);
|
||||||
|
}
|
||||||
|
|
||||||
if (!event.token) {
|
if (!event.token) {
|
||||||
handleAssistantMessage(event);
|
handleAssistantMessage(event);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user