Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(copilot): store mode per session so indicator updates on switch (#12761)

Zamil Majdye5b0b7f18e87
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/store.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/store.test.ts
index e9ffe11db1..f993daf58d 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/store.test.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/store.test.ts
@@ -164,7 +164,6 @@ describe("useCopilotUIStore", () => {
it("sets mode to fast", () => {
useCopilotUIStore.getState().setCopilotMode("fast");
expect(useCopilotUIStore.getState().copilotMode).toBe("fast");
- expect(window.localStorage.getItem("copilot-mode")).toBe("fast");
});
it("sets mode back to extended_thinking", () => {
@@ -174,6 +173,11 @@ describe("useCopilotUIStore", () => {
"extended_thinking",
);
});
+
+ it("does not persist mode to localStorage", () => {
+ useCopilotUIStore.getState().setCopilotMode("fast");
+ expect(window.localStorage.getItem("copilot-mode")).toBeNull();
+ });
});
describe("clearCopilotLocalData", () => {
@@ -190,7 +194,6 @@ describe("useCopilotUIStore", () => {
expect(state.isNotificationsEnabled).toBe(false);
expect(state.isSoundEnabled).toBe(true);
expect(state.completedSessionIDs.size).toBe(0);
- expect(window.localStorage.getItem("copilot-mode")).toBeNull();
expect(
window.localStorage.getItem("copilot-notifications-enabled"),
).toBeNull();
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx
index 3dac5bf35e..d1e1ca4f9d 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx
@@ -196,10 +196,9 @@ export function ChatInput({
onFilesSelected={handleFilesSelected}
disabled={isBusy}
/>
- {showModeToggle && (
+ {showModeToggle && !isStreaming && (
<ModeToggleButton
mode={copilotMode}
- isStreaming={isStreaming}
onToggle={handleToggleMode}
/>
)}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx
index cb8f4227b4..ee92b7cc94 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx
@@ -152,11 +152,10 @@ describe("ChatInput mode toggle", () => {
expect(mockSetCopilotMode).toHaveBeenCalledWith("extended_thinking");
});
- it("disables toggle button when streaming", () => {
+ it("hides toggle button when streaming", () => {
mockFlagValue = true;
render(<ChatInput onSend={mockOnSend} isStreaming />);
- const button = screen.getByLabelText(/switch to fast mode/i);
- expect(button.hasAttribute("disabled")).toBe(true);
+ expect(screen.queryByLabelText(/switch to/i)).toBeNull();
});
it("exposes aria-pressed=true in extended_thinking mode", () => {
@@ -175,15 +174,6 @@ describe("ChatInput mode toggle", () => {
expect(button.getAttribute("aria-pressed")).toBe("false");
});
- it("uses streaming-specific tooltip when disabled", () => {
- mockFlagValue = true;
- render(<ChatInput onSend={mockOnSend} isStreaming />);
- const button = screen.getByLabelText(/switch to fast mode/i);
- expect(button.getAttribute("title")).toBe(
- "Mode cannot be changed while streaming",
- );
- });
-
it("shows a toast when the user toggles mode", async () => {
const { toast } = await import("@/components/molecules/Toast/use-toast");
mockFlagValue = true;
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ModeToggleButton.stories.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ModeToggleButton.stories.tsx
index 6bccdbc888..02114b04a8 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ModeToggleButton.stories.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ModeToggleButton.stories.tsx
@@ -10,7 +10,7 @@ const meta: Meta<typeof ModeToggleButton> = {
docs: {
description: {
component:
- "Toggle between Fast and Extended Thinking copilot modes. Disabled while a response is streaming.",
+ "Toggle between Fast and Extended Thinking copilot modes. Hidden while a response is streaming.",
},
},
},
@@ -25,20 +25,11 @@ type Story = StoryObj<typeof meta>;
export const FastMode: Story = {
args: {
mode: "fast",
- isStreaming: false,
},
};
export const ExtendedThinkingMode: Story = {
args: {
mode: "extended_thinking",
- isStreaming: false,
- },
-};
-
-export const DisabledWhileStreaming: Story = {
- args: {
- mode: "fast",
- isStreaming: true,
},
};
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ModeToggleButton.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ModeToggleButton.tsx
index 88d4bbba4d..6a3ab0d34d 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ModeToggleButton.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ModeToggleButton.tsx
@@ -6,34 +6,29 @@ import type { CopilotMode } from "../../../store";
interface Props {
mode: CopilotMode;
- isStreaming: boolean;
onToggle: () => void;
}
-export function ModeToggleButton({ mode, isStreaming, onToggle }: Props) {
+export function ModeToggleButton({ mode, onToggle }: Props) {
const isExtended = mode === "extended_thinking";
return (
<button
type="button"
aria-pressed={isExtended}
- disabled={isStreaming}
onClick={onToggle}
className={cn(
"inline-flex min-h-11 min-w-11 items-center justify-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors",
isExtended
? "bg-purple-100 text-purple-900 hover:bg-purple-200"
: "bg-amber-100 text-amber-900 hover:bg-amber-200",
- isStreaming && "cursor-not-allowed opacity-50",
)}
aria-label={
isExtended ? "Switch to Fast mode" : "Switch to Extended Thinking mode"
}
title={
- isStreaming
- ? "Mode cannot be changed while streaming"
- : isExtended
- ? "Extended Thinking mode — deeper reasoning (click to switch to Fast mode)"
- : "Fast mode — quicker responses (click to switch to Extended Thinking)"
+ isExtended
+ ? "Extended Thinking mode — deeper reasoning (click to switch to Fast mode)"
+ : "Fast mode — quicker responses (click to switch to Extended Thinking)"
}
>
{isExtended ? (
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/store.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/store.ts
index a72d515b6d..ebd9c3811f 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/store.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/store.ts
@@ -275,12 +275,8 @@ export const useCopilotUIStore = create<CopilotUIState>((set) => ({
};
}),
- copilotMode:
- isClient && storage.get(Key.COPILOT_MODE) === "fast"
- ? "fast"
- : "extended_thinking",
+ copilotMode: "extended_thinking",
setCopilotMode: (mode) => {
- storage.set(Key.COPILOT_MODE, mode);
set({ copilotMode: mode });
},
@@ -301,7 +297,6 @@ export const useCopilotUIStore = create<CopilotUIState>((set) => ({
storage.clean(Key.COPILOT_NOTIFICATION_BANNER_DISMISSED);
storage.clean(Key.COPILOT_NOTIFICATION_DIALOG_DISMISSED);
storage.clean(Key.COPILOT_ARTIFACT_PANEL_WIDTH);
- storage.clean(Key.COPILOT_MODE);
storage.clean(Key.COPILOT_COMPLETED_SESSIONS);
storage.clean(Key.COPILOT_DRY_RUN);
set({