Skip to content
Open
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
14 changes: 12 additions & 2 deletions __tests__/components/features/chat/change-agent-button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { ChangeAgentButton } from "#/components/features/chat/change-agent-butto
import { renderWithProviders } from "../../../../test-utils";
import { useConversationStore } from "#/stores/conversation-store";

// Mock WebSocket status
const mockWebSocketStatus = vi.hoisted(() => vi.fn(() => "OPEN"));

vi.mock("#/hooks/use-unified-websocket-status", () => ({
useUnifiedWebSocketStatus: () => "CONNECTED",
useUnifiedWebSocketStatus: () => mockWebSocketStatus(),
}));

// Mock agent state
Expand Down Expand Up @@ -68,6 +69,7 @@ vi.mock("#/hooks/use-handle-plan-click", () => ({
describe("ChangeAgentButton - Cache Invalidation", () => {
beforeEach(() => {
vi.clearAllMocks();
mockWebSocketStatus.mockReturnValue("OPEN");
// Reset store state
useConversationStore.setState({
conversationMode: "code",
Expand Down Expand Up @@ -151,4 +153,12 @@ describe("ChangeAgentButton - Cache Invalidation", () => {
const button = screen.getByRole("button");
expect(button).toBeInTheDocument();
});

it("enables mode switch on pre-conversation surfaces without a websocket", () => {
mockWebSocketStatus.mockReturnValue("CLOSED");
renderWithProviders(<ChangeAgentButton />, {
navigation: { conversationId: null },
});
expect(screen.getByRole("button")).not.toBeDisabled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("ChatInputModel", () => {
const llmSettingsLink = screen.getByRole("link", {
name: /LLM Profiles|SETTINGS\$LLM_PROFILES|LLM Settings|SETTINGS\$LLM_SETTINGS/,
});
expect(llmSettingsLink).toHaveAttribute("href", "/settings");
expect(llmSettingsLink).toHaveAttribute("href", "/settings/llm");
});

it("renders nothing when llm_model is missing", () => {
Expand Down
18 changes: 15 additions & 3 deletions src/components/features/chat/change-agent-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ 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";

export function ChangeAgentButton() {
const [contextMenuOpen, setContextMenuOpen] = useState<boolean>(false);

const { conversationMode, setConversationMode, subConversationTaskId } =
useConversationStore();

const { conversationId } = useOptionalConversationId();
const isPreConversation = conversationId == null;

const webSocketStatus = useUnifiedWebSocketStatus();

const isWebSocketConnected = webSocketStatus === "OPEN";
Expand Down Expand Up @@ -74,13 +78,21 @@ export function ChangeAgentButton() {

// Close context menu when agent starts running
useEffect(() => {
if ((isAgentRunning || !isWebSocketConnected) && contextMenuOpen) {
const blockedBySocket = !isPreConversation && !isWebSocketConnected;
if ((isAgentRunning || blockedBySocket) && contextMenuOpen) {
setContextMenuOpen(false);
}
}, [isAgentRunning, contextMenuOpen, isWebSocketConnected]);
}, [
isAgentRunning,
contextMenuOpen,
isWebSocketConnected,
isPreConversation,
]);

const isButtonDisabled =
isAgentRunning || isCreatingConversation || !isWebSocketConnected;
isCreatingConversation ||
isAgentRunning ||
(!isPreConversation && !isWebSocketConnected);

// Handle Shift + Tab keyboard shortcut to cycle through modes
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export function ChatInputActions({
const isAgentSwitcherDisabled =
curAgentState === AgentState.RUNNING ||
isCreatingConversation ||
webSocketStatus !== "OPEN";
(conversationId != null && webSocketStatus !== "OPEN");

const closeOverflowMenus = () => {
setActiveSubmenu(null);
Expand Down Expand Up @@ -449,7 +449,7 @@ export function ChatInputActions({
<Divider inset="menu" />
<li className="text-sm">
<NavigationLink
to="/settings"
to="/settings/llm"
onClick={closeOverflowMenus}
className="group flex h-[30px] items-center gap-2 rounded p-2 leading-5 text-[var(--oh-foreground)] hover:bg-[var(--oh-interactive-hover)] transition-colors"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function ChatInputModel() {
<Divider />
<li className="text-sm">
<NavigationLink
to="/settings"
to="/settings/llm"
onClick={() => setIsPopoverOpen(false)}
className="flex h-[30px] items-center gap-2 rounded p-2 leading-5 text-white hover:bg-[var(--oh-interactive-hover)] transition-colors"
>
Expand Down