From 3e1b0ffc5390da6a66c0e6436868019097a6ea76 Mon Sep 17 00:00:00 2001 From: Ayush8923 <80516839+Ayush8923@users.noreply.github.com> Date: Mon, 1 Jun 2026 15:00:23 +0530 Subject: [PATCH 1/3] fix(guardrails): remove edit and delete functionality --- app/(main)/guardrails/page.tsx | 80 +--- .../validators/configs/[config_id]/route.ts | 68 ---- .../guardrails/DeleteConfigModal.tsx | 53 --- .../guardrails/SavedConfigsList.tsx | 76 ++-- .../guardrails/ValidatorConfigPanel.tsx | 344 ++++++++++-------- app/components/ui/MultiSelect.tsx | 31 +- app/globals.css | 24 ++ app/lib/types/guardrails.ts | 8 - app/lib/utils/guardrails.ts | 14 - 9 files changed, 271 insertions(+), 427 deletions(-) delete mode 100644 app/api/guardrails/validators/configs/[config_id]/route.ts delete mode 100644 app/components/guardrails/DeleteConfigModal.tsx diff --git a/app/(main)/guardrails/page.tsx b/app/(main)/guardrails/page.tsx index f731de71..0089db5e 100644 --- a/app/(main)/guardrails/page.tsx +++ b/app/(main)/guardrails/page.tsx @@ -17,10 +17,8 @@ import { SavedValidatorConfig, OrgContext, } from "@/app/lib/types/guardrails"; -import { buildValidatorUpdatePayload } from "@/app/lib/utils/guardrails"; import ValidatorConfigPanel from "@/app/components/guardrails/ValidatorConfigPanel"; import SavedConfigsList from "@/app/components/guardrails/SavedConfigsList"; -import DeleteConfigModal from "@/app/components/guardrails/DeleteConfigModal"; export default function GuardrailsPage() { const { sidebarCollapsed } = useApp(); @@ -38,8 +36,6 @@ export default function GuardrailsPage() { const [selectedSavedConfig, setSelectedSavedConfig] = useState(null); const [isSaving, setIsSaving] = useState(false); - const [configPendingDelete, setConfigPendingDelete] = - useState(null); useEffect(() => { if (!isHydrated) return; @@ -122,39 +118,11 @@ export default function GuardrailsPage() { setSelectedSavedConfig(null); }; - const handleRequestDeleteConfig = (configId: string) => { - const cfg = savedConfigs.find((c) => c.id === configId); - if (cfg) setConfigPendingDelete(cfg); - }; - - const handleConfirmDeleteConfig = async () => { - if (!configPendingDelete) return; - if (!configsQueryString) { - setConfigPendingDelete(null); - return; - } - const configId = configPendingDelete.id; - setConfigPendingDelete(null); - try { - await guardrailsFetch( - `/api/guardrails/validators/configs/${configId}${configsQueryString}`, - apiKey, - { method: "DELETE" }, - ); - toast.success("Config deleted"); - if (selectedSavedConfig?.id === configId) { - handleClearForm(); - } - fetchSavedConfigs(); - } catch { - toast.error("Failed to delete config"); - } - }; - const handleSaveConfig = async ( name: string, configValues: Record, ) => { + if (selectedSavedConfig) return; if (!name.trim()) { toast.error("Please enter a config name"); return; @@ -165,33 +133,18 @@ export default function GuardrailsPage() { } setIsSaving(true); try { - const isUpdate = !!selectedSavedConfig; - const base = `/api/guardrails/validators/configs`; - const url = isUpdate - ? `${base}/${selectedSavedConfig!.id}${configsQueryString}` - : `${base}${configsQueryString}`; - - const body = isUpdate - ? buildValidatorUpdatePayload(configValues) - : configValues; - - await guardrailsFetch(url, apiKey, { - method: isUpdate ? "PATCH" : "POST", - body: JSON.stringify(body), - }); - toast.success( - isUpdate ? `Config "${name}" updated` : `Config "${name}" saved`, + await guardrailsFetch( + `/api/guardrails/validators/configs${configsQueryString}`, + apiKey, + { + method: "POST", + body: JSON.stringify(configValues), + }, ); - const savedConfigId = selectedSavedConfig?.id; - const freshList = await fetchSavedConfigs(); - if (isUpdate && savedConfigId) { - setSelectedSavedConfig( - freshList.find((c) => c.id === savedConfigId) ?? null, - ); - } else { - setSelectedSavedConfig(null); - setSelectedValidatorType(null); - } + toast.success(`Config "${name}" saved`); + await fetchSavedConfigs(); + setSelectedSavedConfig(null); + setSelectedValidatorType(null); } catch (e) { toast.error(e instanceof Error ? e.message : "Failed to save config"); } finally { @@ -234,7 +187,6 @@ export default function GuardrailsPage() { isLoading={savedConfigsLoading} selectedConfigId={selectedSavedConfig?.id ?? null} onSelectConfig={handleSelectSavedConfig} - onDeleteConfig={handleRequestDeleteConfig} onNewConfig={handleClearForm} /> @@ -250,17 +202,11 @@ export default function GuardrailsPage() { isSaving={isSaving} onSave={handleSaveConfig} onClear={handleClearForm} + readOnly={!!selectedSavedConfig} /> - - setConfigPendingDelete(null)} - onConfirm={handleConfirmDeleteConfig} - /> ); } diff --git a/app/api/guardrails/validators/configs/[config_id]/route.ts b/app/api/guardrails/validators/configs/[config_id]/route.ts deleted file mode 100644 index 2fb1aa02..00000000 --- a/app/api/guardrails/validators/configs/[config_id]/route.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { guardrailsClient } from "@/app/lib/guardrailsClient"; -import { buildValidatorConfigEndpoint } from "@/app/lib/utils/guardrails"; -import { NextResponse, NextRequest } from "next/server"; - -export async function GET( - request: NextRequest, - { params }: { params: Promise<{ config_id: string }> }, -) { - try { - const { config_id } = await params; - const { status, data } = await guardrailsClient( - request, - buildValidatorConfigEndpoint(request, config_id), - ); - return NextResponse.json(data, { status }); - } catch (e: unknown) { - return NextResponse.json( - { error: e instanceof Error ? e.message : String(e) }, - { status: 500 }, - ); - } -} - -export async function PATCH( - request: NextRequest, - { params }: { params: Promise<{ config_id: string }> }, -) { - try { - const { config_id } = await params; - const body = await request.json(); - const { status, data } = await guardrailsClient( - request, - buildValidatorConfigEndpoint(request, config_id), - { - method: "PATCH", - body: JSON.stringify(body), - }, - ); - return NextResponse.json(data, { status }); - } catch (e: unknown) { - return NextResponse.json( - { error: e instanceof Error ? e.message : String(e) }, - { status: 500 }, - ); - } -} - -export async function DELETE( - request: NextRequest, - { params }: { params: Promise<{ config_id: string }> }, -) { - try { - const { config_id } = await params; - const { status, data } = await guardrailsClient( - request, - buildValidatorConfigEndpoint(request, config_id), - { - method: "DELETE", - }, - ); - return NextResponse.json(data, { status }); - } catch (e: unknown) { - return NextResponse.json( - { error: e instanceof Error ? e.message : String(e) }, - { status: 500 }, - ); - } -} diff --git a/app/components/guardrails/DeleteConfigModal.tsx b/app/components/guardrails/DeleteConfigModal.tsx deleted file mode 100644 index 63ced310..00000000 --- a/app/components/guardrails/DeleteConfigModal.tsx +++ /dev/null @@ -1,53 +0,0 @@ -"use client"; - -import { Button, Modal } from "@/app/components/ui"; - -interface DeleteConfigModalProps { - open: boolean; - configName?: string; - onClose: () => void; - onConfirm: () => void; -} - -export default function DeleteConfigModal({ - open, - configName, - onClose, - onConfirm, -}: DeleteConfigModalProps) { - return ( - -
-

- {configName ? ( - <> - Are you sure you want to delete{" "} - - “{configName}” - - ? This action cannot be undone. - - ) : ( - <> - Are you sure you want to delete this configuration? This action - cannot be undone. - - )} -

-
- - -
-
-
- ); -} diff --git a/app/components/guardrails/SavedConfigsList.tsx b/app/components/guardrails/SavedConfigsList.tsx index c88c9da5..8f99cd90 100644 --- a/app/components/guardrails/SavedConfigsList.tsx +++ b/app/components/guardrails/SavedConfigsList.tsx @@ -2,7 +2,7 @@ import { SavedValidatorConfig, formatValidatorName, } from "@/app/lib/types/guardrails"; -import { TrashIcon, GuardrailsShieldCheckIcon } from "@/app/components/icons"; +import { GuardrailsShieldCheckIcon } from "@/app/components/icons"; import { Button } from "@/app/components/ui"; import { VALIDATOR_META_BY_TYPE } from "@/app/lib/utils/guardrails"; import SavedConfigsListSkeleton from "./SavedConfigsListSkeleton"; @@ -12,7 +12,6 @@ interface SavedConfigsListProps { isLoading: boolean; selectedConfigId: string | null; onSelectConfig: (cfg: SavedValidatorConfig) => void; - onDeleteConfig: (id: string) => void; onNewConfig: () => void; } @@ -21,7 +20,6 @@ export default function SavedConfigsList({ isLoading, selectedConfigId, onSelectConfig, - onDeleteConfig, onNewConfig, }: SavedConfigsListProps) { return ( @@ -84,51 +82,37 @@ export default function SavedConfigsList({ : "bg-bg-primary shadow-[0_4px_12px_rgba(0,0,0,0.08),0_2px_4px_rgba(0,0,0,0.05)] hover:shadow-[0_8px_22px_rgba(0,0,0,0.12),0_2px_4px_rgba(0,0,0,0.06)]" }`} > -
-
-

- {cfg.name} -

-
- - {displayName} +
+

+ {cfg.name} +

+
+ + {displayName} + + {cfg.stage && ( + + {cfg.stage} + + )} + {cfg.on_fail_action && ( + + on fail: {cfg.on_fail_action} - {cfg.stage && ( - - {cfg.stage} - - )} - {cfg.on_fail_action && ( - - on fail: {cfg.on_fail_action} - - )} - {cfg.is_enabled === false && ( - - disabled - - )} -
+ )} + {cfg.is_enabled === false && ( + + disabled + + )}
-
); diff --git a/app/components/guardrails/ValidatorConfigPanel.tsx b/app/components/guardrails/ValidatorConfigPanel.tsx index 768d4590..e80c7014 100644 --- a/app/components/guardrails/ValidatorConfigPanel.tsx +++ b/app/components/guardrails/ValidatorConfigPanel.tsx @@ -8,6 +8,7 @@ import { MultiSelect, Loader, } from "@/app/components/ui"; +import { CloseIcon } from "@/app/components/icons"; import { GUARDRAILS_FIELD_TOOLTIPS, KNOWN_ARRAY_OPTIONS, @@ -31,6 +32,7 @@ interface ValidatorConfigPanelProps { isSaving: boolean; onSave: (name: string, configValues: Record) => void; onClear: () => void; + readOnly?: boolean; } export default function ValidatorConfigPanel({ @@ -43,6 +45,7 @@ export default function ValidatorConfigPanel({ isSaving, onSave, onClear, + readOnly = false, }: ValidatorConfigPanelProps) { const [configName, setConfigName] = useState(""); const [stage, setStage] = useState<"input" | "output">("output"); @@ -145,180 +148,205 @@ export default function ValidatorConfigPanel({ return (
-
-

- {existingName ? existingName : "New Validator Config"} -

-

- {existingName - ? "Update this validator configuration" - : "Configure and save a validator"} -

+
+
+

+ {existingName ? existingName : "New Validator Config"} +

+

+ {readOnly + ? "Viewing this validator configuration (read-only)" + : existingName + ? "Update this validator configuration" + : "Configure and save a validator"} +

+
+ {readOnly && ( + + )}
- - -
- - setOnFailAction(e.target.value)} - options={[ - { value: "fix", label: "Fix" }, - { value: "exception", label: "Exception" }, - { value: "rephrase", label: "Rephrase" }, - ]} - /> -
- +
+ + onTypeChange(e.target.value || null)} - placeholder="Select a validator type…" - options={validators.map((v) => ({ - value: v.type, - label: - VALIDATOR_META_BY_TYPE[v.type]?.validator_name ?? - formatValidatorName(v.type), - }))} + value={onFailAction} + onChange={(e) => setOnFailAction(e.target.value)} + options={[ + { value: "fix", label: "Fix" }, + { value: "exception", label: "Exception" }, + { value: "rephrase", label: "Rephrase" }, + ]} /> - )} - {typeDescription && ( -

- {typeDescription} -

- )} -
+
- {validator && ( - <> - {isBanList && ( -
- handleFieldChange("ban_list_id", id)} - /> -
- )} + - {isTopicRelevance && ( -
- - handleFieldChange("topic_relevance_config_id", id) - } - /> +
+ + {validatorsLoading ? ( +
+ + Loading validator types…
+ ) : ( +