diff --git a/backend/main.py b/backend/main.py index e33ce59a6..43e608da4 100644 --- a/backend/main.py +++ b/backend/main.py @@ -62,6 +62,13 @@ async def list_conversations(): return storage.list_conversations() +@app.delete("/api/conversations") +async def delete_conversations(): + """Delete all conversations from storage.""" + storage.delete_all_conversations() + return {"status": "ok"} + + @app.post("/api/conversations", response_model=Conversation) async def create_conversation(request: CreateConversationRequest): """Create a new conversation.""" diff --git a/backend/storage.py b/backend/storage.py index 180111da4..b017b571c 100644 --- a/backend/storage.py +++ b/backend/storage.py @@ -170,3 +170,18 @@ def update_conversation_title(conversation_id: str, title: str): conversation["title"] = title save_conversation(conversation) + + +def delete_all_conversations(): + """ + Delete all conversation files from the data directory. + """ + ensure_data_dir() + for filename in os.listdir(DATA_DIR): + if filename.endswith('.json'): + path = os.path.join(DATA_DIR, filename) + try: + os.remove(path) + except OSError: + # ignore failures to remove individual files + pass diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 195415598..559277bb8 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -53,6 +53,18 @@ function App() { } }; + const handleClearConversations = async () => { + if (!window.confirm('Clear all conversations? This cannot be undone.')) return; + try { + await api.deleteAllConversations(); + setConversations([]); + setCurrentConversationId(null); + setCurrentConversation(null); + } catch (error) { + console.error('Failed to clear conversations:', error); + } + }; + const handleSelectConversation = (id) => { setCurrentConversationId(id); }; @@ -188,6 +200,7 @@ function App() { currentConversationId={currentConversationId} onSelectConversation={handleSelectConversation} onNewConversation={handleNewConversation} + onClearConversations={handleClearConversations} /> @@ -14,6 +15,14 @@ export default function Sidebar({ +