Explorar o código

fix(frontend): prevent API key from resetting after modal change (#2329)

* remove bottom chatbox fade

* Modal wider; fix lint error

* settings: attempt to not clear api key for same provider

* prevent api key from resetting after changing the model

* revert other changes and fix post test tear down error

---------

Co-authored-by: amanape <83104063+amanape@users.noreply.github.com>
tobitege hai 1 ano
pai
achega
a8c6fd0d42

+ 4 - 4
frontend/src/components/chat/ChatInput.test.tsx

@@ -3,11 +3,11 @@ import userEvent from "@testing-library/user-event";
 import { act, render, fireEvent } from "@testing-library/react";
 import ChatInput from "./ChatInput";
 
-afterEach(() => {
-  vi.clearAllMocks();
-});
-
 describe("ChatInput", () => {
+  afterEach(() => {
+    vi.clearAllMocks();
+  });
+
   const onSendMessage = vi.fn();
 
   it("should render a textarea", () => {

+ 2 - 2
frontend/src/components/modals/settings/SettingsModal.test.tsx

@@ -26,6 +26,7 @@ vi.mock("#/services/settings", async (importOriginal) => ({
     LLM_MODEL: "gpt-4o",
     AGENT: "MonologueAgent",
     LANGUAGE: "en",
+    LLM_API_KEY: "sk-...",
   }),
   getDefaultSettings: vi.fn().mockReturnValue({
     LLM_MODEL: "gpt-4o",
@@ -139,7 +140,6 @@ describe("SettingsModal", () => {
       expect(saveSettings).toHaveBeenCalledWith({
         ...initialSettings,
         LLM_MODEL: "model3",
-        LLM_API_KEY: "", // reset after model change
       });
     });
 
@@ -196,7 +196,7 @@ describe("SettingsModal", () => {
         await userEvent.click(saveButton);
       });
 
-      expect(toastSpy).toHaveBeenCalledTimes(2);
+      expect(toastSpy).toHaveBeenCalledTimes(3);
     });
 
     it("should change the language", async () => {

+ 0 - 3
frontend/src/components/modals/settings/SettingsModal.tsx

@@ -66,12 +66,9 @@ function SettingsModal({ isOpen, onOpenChange }: SettingsProps) {
   }, []);
 
   const handleModelChange = (model: string) => {
-    // Needs to also reset the API key.
-    const key = localStorage.getItem(`API_KEY_${model}`);
     setSettings((prev) => ({
       ...prev,
       LLM_MODEL: model,
-      LLM_API_KEY: key || "",
     }));
   };