From 80759e3e88d470d324a5afe38642448d625d3dbc Mon Sep 17 00:00:00 2001 From: Tony Giorgio Date: Sat, 22 Nov 2025 20:36:30 -0600 Subject: [PATCH] feat: implement delete all conversations functionality - Update @opensecret/react to v1.5.1 - Implement combined delete logic for both archived and server-side conversations in AccountMenu - Ensure robust error handling during deletion process Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- frontend/bun.lock | 4 ++-- frontend/package.json | 2 +- frontend/src/components/AccountMenu.tsx | 26 +++++++++++++++++++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/frontend/bun.lock b/frontend/bun.lock index 759d44a15..600a75c5d 100644 --- a/frontend/bun.lock +++ b/frontend/bun.lock @@ -4,7 +4,7 @@ "": { "name": "maple", "dependencies": { - "@opensecret/react": "1.5.0", + "@opensecret/react": "1.5.1", "@radix-ui/react-alert-dialog": "^1.1.1", "@radix-ui/react-avatar": "^1.1.0", "@radix-ui/react-checkbox": "^1.3.3", @@ -223,7 +223,7 @@ "@nodelib/fs.walk": ["@nodelib/fs.walk@1.2.8", "", { "dependencies": { "@nodelib/fs.scandir": "2.1.5", "fastq": "^1.6.0" } }, "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg=="], - "@opensecret/react": ["@opensecret/react@1.5.0", "", { "dependencies": { "@peculiar/x509": "^1.12.2", "@stablelib/base64": "^2.0.0", "@stablelib/chacha20poly1305": "^2.0.0", "@stablelib/random": "^2.0.0", "cbor2": "^1.7.0", "tweetnacl": "^1.0.3", "zod": "^3.23.8" }, "peerDependencies": { "react": "^18.0.0 || ^19.0.0", "react-dom": "^18.0.0 || ^19.0.0" } }, "sha512-fcN4IYvlom1e2pdGeMSmQ572V4fOALn/0AshyIut0EZjfgMU7camxi1JjXX7lJtgSUyW3Nys7Kiej3wo5sXIwQ=="], + "@opensecret/react": ["@opensecret/react@1.5.1", "", { "dependencies": { "@peculiar/x509": "^1.12.2", "@stablelib/base64": "^2.0.0", "@stablelib/chacha20poly1305": "^2.0.0", "@stablelib/random": "^2.0.0", "cbor2": "^1.7.0", "tweetnacl": "^1.0.3", "zod": "^3.23.8" }, "peerDependencies": { "react": "^18.0.0 || ^19.0.0", "react-dom": "^18.0.0 || ^19.0.0" } }, "sha512-07bXbnwDU++T5pdzy0Z8dJR/07mMklBr8r32AtPuu0JEWC8Kb7l5016dK/VJUwF87G/pioFQEiN7+itXdJkt/g=="], "@peculiar/asn1-cms": ["@peculiar/asn1-cms@2.3.15", "", { "dependencies": { "@peculiar/asn1-schema": "^2.3.15", "@peculiar/asn1-x509": "^2.3.15", "@peculiar/asn1-x509-attr": "^2.3.15", "asn1js": "^3.0.5", "tslib": "^2.8.1" } }, "sha512-B+DoudF+TCrxoJSTjjcY8Mmu+lbv8e7pXGWrhNp2/EGJp9EEcpzjBCar7puU57sGifyzaRVM03oD5L7t7PghQg=="], diff --git a/frontend/package.json b/frontend/package.json index 019dad8c1..8689508ec 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -17,7 +17,7 @@ "mdast-util-gfm-autolink-literal": "2.0.0" }, "dependencies": { - "@opensecret/react": "1.5.0", + "@opensecret/react": "1.5.1", "@radix-ui/react-alert-dialog": "^1.1.1", "@radix-ui/react-avatar": "^1.1.0", "@radix-ui/react-checkbox": "^1.3.3", diff --git a/frontend/src/components/AccountMenu.tsx b/frontend/src/components/AccountMenu.tsx index 9c1c177d0..9905115b3 100644 --- a/frontend/src/components/AccountMenu.tsx +++ b/frontend/src/components/AccountMenu.tsx @@ -54,19 +54,37 @@ import { ApiKeyManagementDialog } from "@/components/apikeys/ApiKeyManagementDia function ConfirmDeleteDialog() { const { clearHistory } = useLocalState(); + const os = useOpenSecret(); const queryClient = useQueryClient(); const navigate = useNavigate(); async function handleDeleteHistory() { + // 1. Delete archived chats (KV) try { await clearHistory(); - console.log("History cleared"); + console.log("History (KV) cleared"); } catch (error) { console.error("Error clearing history:", error); - } finally { - queryClient.invalidateQueries({ queryKey: ["chatHistory"] }); - navigate({ to: "/" }); + // Continue to delete server conversations even if this fails } + + // 2. Delete server conversations (API) if any exist + try { + // Check if we have any conversations to delete + const conversations = await os.listConversations({ limit: 1 }); + if (conversations.data && conversations.data.length > 0) { + await os.deleteConversations(); + console.log("Server conversations deleted"); + } + } catch (e) { + console.error("Error deleting conversations:", e); + } + + // Always refresh UI and navigate home + queryClient.invalidateQueries({ queryKey: ["chatHistory"] }); + queryClient.invalidateQueries({ queryKey: ["conversations"] }); + queryClient.invalidateQueries({ queryKey: ["archivedChats"] }); + navigate({ to: "/" }); } return (