Skip to content

🙌 OpenHands: AI-Driven Development

fix: restore disabled Change Agent button on home page chat input (#858)

Hiep Lef9c6c99960ed
diff --git a/__tests__/components/features/chat/change-agent-button.test.tsx b/__tests__/components/features/chat/change-agent-button.test.tsx
index b7d44d1524..8eba5b6c47 100644
--- a/__tests__/components/features/chat/change-agent-button.test.tsx
+++ b/__tests__/components/features/chat/change-agent-button.test.tsx
@@ -1,3 +1,4 @@
+import type { ReactNode } from "react";
import { screen, waitFor } from "@testing-library/react";
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
import { QueryClient } from "@tanstack/react-query";
@@ -5,9 +6,29 @@ import { ChangeAgentButton } from "#/components/features/chat/change-agent-butto
import { renderWithProviders } from "../../../../test-utils";
import { useConversationStore } from "#/stores/conversation-store";
-// Mock WebSocket status
+// Stub StyledTooltip so its content renders eagerly. HeroUI's Tooltip (the
+// real engine) only mounts content on real-DOM hover, which jsdom doesn't
+// fire reliably, so we surface the content as a marker element instead.
+vi.mock("#/components/shared/buttons/styled-tooltip", () => ({
+ StyledTooltip: ({
+ content,
+ children,
+ }: {
+ content: ReactNode;
+ children: ReactNode;
+ }) => (
+ <>
+ {children}
+ <span data-testid="styled-tooltip-content">{content}</span>
+ </>
+ ),
+}));
+
+// Mock WebSocket status. Controllable so a test can simulate a ready
+// connection and isolate the home-page disable from the no-connection one.
+const wsState = vi.hoisted(() => ({ status: "CONNECTED" }));
vi.mock("#/hooks/use-unified-websocket-status", () => ({
- useUnifiedWebSocketStatus: () => "CONNECTED",
+ useUnifiedWebSocketStatus: () => wsState.status,
}));
// Mock agent state
@@ -76,6 +97,7 @@ describe("ChangeAgentButton - Cache Invalidation", () => {
// Reset mock task polling result
mockTaskPollingResult.taskStatus = undefined;
mockTaskPollingResult.subConversationId = undefined;
+ wsState.status = "CONNECTED";
});
afterEach(() => {
@@ -152,3 +174,43 @@ describe("ChangeAgentButton - Cache Invalidation", () => {
expect(button).toBeInTheDocument();
});
});
+
+describe("ChangeAgentButton - Home page", () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ useConversationStore.setState({
+ conversationMode: "code",
+ subConversationTaskId: null,
+ });
+ mockTaskPollingResult.taskStatus = undefined;
+ mockTaskPollingResult.subConversationId = undefined;
+ // A ready websocket isolates the home-page disable: the only reason the
+ // button is disabled here is the absence of a started conversation.
+ wsState.status = "OPEN";
+ });
+
+ it("disables the button and explains why via a tooltip on the home page", () => {
+ // Arrange & Act - render with no active conversation (the home page)
+ renderWithProviders(<ChangeAgentButton />, {
+ navigation: { conversationId: null },
+ });
+
+ // Assert - button stays disabled and the explanatory tooltip is wired up
+ expect(screen.getByRole("button")).toBeDisabled();
+ expect(screen.getByTestId("styled-tooltip-content")).toHaveTextContent(
+ "CHANGE_AGENT$SWITCH_AFTER_CONVERSATION",
+ );
+ });
+
+ it("drops the explanatory tooltip once a conversation has begun", () => {
+ // Arrange & Act - render inside an active conversation
+ renderWithProviders(<ChangeAgentButton />, {
+ navigation: { conversationId: "conversation-1" },
+ });
+
+ // Assert - no home-page tooltip wrapper is rendered
+ expect(
+ screen.queryByTestId("styled-tooltip-content"),
+ ).not.toBeInTheDocument();
+ });
+});
diff --git a/__tests__/components/features/chat/components/chat-input-actions.test.tsx b/__tests__/components/features/chat/components/chat-input-actions.test.tsx
index fdf0264394..050121ca86 100644
--- a/__tests__/components/features/chat/components/chat-input-actions.test.tsx
+++ b/__tests__/components/features/chat/components/chat-input-actions.test.tsx
@@ -160,7 +160,7 @@ describe("ChatInputActions", () => {
expect(screen.getByTestId("change-agent-button-stub")).toBeInTheDocument();
});
- it("hides the Change Agent button on the home page on a cloud backend", () => {
+ it("shows the Change Agent button on the home page on a cloud backend", () => {
setRegisteredBackends([cloudBackend]);
setActiveSelection({ backendId: cloudBackend.id });
@@ -172,7 +172,7 @@ describe("ChatInputActions", () => {
);
expect(
- screen.queryByTestId("change-agent-button-stub"),
- ).not.toBeInTheDocument();
+ screen.getByTestId("change-agent-button-stub"),
+ ).toBeInTheDocument();
});
});
diff --git a/src/components/features/chat/change-agent-button.tsx b/src/components/features/chat/change-agent-button.tsx
index 91782582b2..1d062fdcec 100644
--- a/src/components/features/chat/change-agent-button.tsx
+++ b/src/components/features/chat/change-agent-button.tsx
@@ -15,6 +15,8 @@ import { useActiveConversation } from "#/hooks/query/use-active-conversation";
import { useUnifiedWebSocketStatus } from "#/hooks/use-unified-websocket-status";
import { useSubConversationTaskPolling } from "#/hooks/query/use-sub-conversation-task-polling";
import { useHandlePlanClick } from "#/hooks/use-handle-plan-click";
+import { useOptionalConversationId } from "#/hooks/use-conversation-id";
+import { StyledTooltip } from "#/components/shared/buttons/styled-tooltip";
export function ChangeAgentButton() {
const [contextMenuOpen, setContextMenuOpen] = useState<boolean>(false);
@@ -22,6 +24,10 @@ export function ChangeAgentButton() {
const { conversationMode, setConversationMode, subConversationTaskId } =
useConversationStore();
+ const { conversationId } = useOptionalConversationId();
+
+ const isHomePage = !conversationId;
+
const webSocketStatus = useUnifiedWebSocketStatus();
const isWebSocketConnected = webSocketStatus === "OPEN";
@@ -80,7 +86,10 @@ export function ChangeAgentButton() {
}, [isAgentRunning, contextMenuOpen, isWebSocketConnected]);
const isButtonDisabled =
- isAgentRunning || isCreatingConversation || !isWebSocketConnected;
+ isHomePage ||
+ isAgentRunning ||
+ isCreatingConversation ||
+ !isWebSocketConnected;
// Handle Shift + Tab keyboard shortcut to cycle through modes
useEffect(() => {
@@ -145,7 +154,7 @@ export function ChangeAgentButton() {
return <LessonPlanIcon width={18} height={18} color="currentColor" />;
}, [isExecutionAgent]);
- return (
+ const button = (
<div className="relative">
<button
type="button"
@@ -186,4 +195,17 @@ export function ChangeAgentButton() {
)}
</div>
);
+
+ if (isHomePage) {
+ return (
+ <StyledTooltip
+ content={t(I18nKey.CHANGE_AGENT$SWITCH_AFTER_CONVERSATION)}
+ placement="top"
+ >
+ {button}
+ </StyledTooltip>
+ );
+ }
+
+ return button;
}
diff --git a/src/components/features/chat/components/chat-input-actions.tsx b/src/components/features/chat/components/chat-input-actions.tsx
index a44ead5795..35a2a70008 100644
--- a/src/components/features/chat/components/chat-input-actions.tsx
+++ b/src/components/features/chat/components/chat-input-actions.tsx
@@ -74,10 +74,10 @@ export function ChatInputActions({
? (labelForAcpModel(conversation?.acp_server, conversation?.llm_model) ??
conversation?.llm_model)
: conversation?.llm_model;
- // The change-agent button can never be enabled on the home page (no
- // conversation → no WebSocket → permanently disabled), so hide it there
- // entirely. It is still shown inside a conversation on cloud backends.
- const showChangeAgentButton = isCloud && Boolean(conversationId);
+ // Shown on cloud backends. On the home page it renders disabled with an
+ // explanatory tooltip (ChangeAgentButton handles that), since agent mode can
+ // only be switched once a conversation has begun.
+ const showChangeAgentButton = isCloud;
const webSocketStatus = useUnifiedWebSocketStatus();
const { curAgentState } = useAgentState();
const { conversationMode, setConversationMode } = useConversationStore();
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index 62c991dc46..ab729de558 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -23306,6 +23306,23 @@
"uk": "Окресліть цілі, структуруйте завдання та сплануйте наступні кроки.",
"ca": "Defineix objectius, estructura tasques i planifica els propers passos."
},
+ "CHANGE_AGENT$SWITCH_AFTER_CONVERSATION": {
+ "en": "Agent mode can be switched after a conversation begins",
+ "ja": "会話が始まると、エージェントモードを切り替えられます",
+ "zh-CN": "对话开始后即可切换智能体模式",
+ "zh-TW": "對話開始後即可切換代理模式",
+ "ko-KR": "대화가 시작된 후에 에이전트 모드를 전환할 수 있습니다",
+ "no": "Agentmodus kan byttes etter at en samtale har startet",
+ "it": "La modalità agente può essere cambiata dopo l'inizio di una conversazione",
+ "pt": "O modo do agente pode ser alterado após o início de uma conversa",
+ "es": "El modo de agente se puede cambiar después de que comience una conversación",
+ "ar": "يمكن تبديل وضع الوكيل بعد بدء المحادثة",
+ "fr": "Le mode agent peut être changé une fois la conversation commencée",
+ "tr": "Aracı modu, bir konuşma başladıktan sonra değiştirilebilir",
+ "de": "Der Agentenmodus kann gewechselt werden, nachdem ein Gespräch begonnen hat",
+ "uk": "Режим агента можна змінити після початку розмови",
+ "ca": "El mode d'agent es pot canviar després que comenci una conversa"
+ },
"PLANNING_AGENTT$PLANNING_AGENT_INITIALIZED": {
"en": "Planning agent initialized",
"ja": "プランニングエージェントが初期化されました",