From 107d90b6abfa5d41f280c9a8faa30b51d03f3c76 Mon Sep 17 00:00:00 2001 From: Mike Fortman Date: Wed, 24 Sep 2025 15:31:52 -0500 Subject: [PATCH] update reset behavior --- frontend/src/app/settings/page.tsx | 25 ++++++++++++++++++++++--- frontend/src/lib/constants.ts | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 frontend/src/lib/constants.ts diff --git a/frontend/src/app/settings/page.tsx b/frontend/src/app/settings/page.tsx index 7f1ca858..91575423 100644 --- a/frontend/src/app/settings/page.tsx +++ b/frontend/src/app/settings/page.tsx @@ -35,10 +35,11 @@ import { Textarea } from "@/components/ui/textarea"; import { useAuth } from "@/contexts/auth-context"; import { useTask } from "@/contexts/task-context"; import { useDebounce } from "@/lib/debounce"; +import { DEFAULT_AGENT_SETTINGS, DEFAULT_KNOWLEDGE_SETTINGS, UI_CONSTANTS } from "@/lib/constants"; import { getFallbackModels, type ModelProvider } from "./helpers/model-helpers"; import { ModelSelectItems } from "./helpers/model-select-item"; -const MAX_SYSTEM_PROMPT_CHARS = 2000; +const { MAX_SYSTEM_PROMPT_CHARS } = UI_CONSTANTS; interface GoogleDriveFile { id: string; @@ -529,8 +530,17 @@ function KnowledgeSourcesPage() { fetch(`/api/reset-flow/retrieval`, { method: "POST", }) - .then((response) => response.json()) + .then((response) => { + if (response.ok) { + return response.json(); + } + throw new Error(`HTTP ${response.status}: ${response.statusText}`); + }) .then(() => { + // Only reset form values if the API call was successful + setSystemPrompt(DEFAULT_AGENT_SETTINGS.system_prompt); + // Trigger model update to default model + handleModelChange(DEFAULT_AGENT_SETTINGS.llm_model); closeDialog(); // Close after successful completion }) .catch((error) => { @@ -543,8 +553,17 @@ function KnowledgeSourcesPage() { fetch(`/api/reset-flow/ingest`, { method: "POST", }) - .then((response) => response.json()) + .then((response) => { + if (response.ok) { + return response.json(); + } + throw new Error(`HTTP ${response.status}: ${response.statusText}`); + }) .then(() => { + // Only reset form values if the API call was successful + setChunkSize(DEFAULT_KNOWLEDGE_SETTINGS.chunk_size); + setChunkOverlap(DEFAULT_KNOWLEDGE_SETTINGS.chunk_overlap); + setProcessingMode(DEFAULT_KNOWLEDGE_SETTINGS.processing_mode); closeDialog(); // Close after successful completion }) .catch((error) => { diff --git a/frontend/src/lib/constants.ts b/frontend/src/lib/constants.ts new file mode 100644 index 00000000..9c6ea7b0 --- /dev/null +++ b/frontend/src/lib/constants.ts @@ -0,0 +1,23 @@ +/** + * Default agent settings + */ +export const DEFAULT_AGENT_SETTINGS = { + llm_model: "gpt-4o-mini", + system_prompt: "You are a helpful assistant that can use tools to answer questions and perform tasks." +} as const; + +/** + * Default knowledge/ingest settings + */ +export const DEFAULT_KNOWLEDGE_SETTINGS = { + chunk_size: 1000, + chunk_overlap: 200, + processing_mode: "standard" +} as const; + +/** + * UI Constants + */ +export const UI_CONSTANTS = { + MAX_SYSTEM_PROMPT_CHARS: 2000, +} as const; \ No newline at end of file