From eb091291488eca0d72fdd5a3410b9af9929fe9f5 Mon Sep 17 00:00:00 2001 From: qixinbo Date: Sun, 15 Mar 2026 17:05:16 +0800 Subject: [PATCH] fix: sidebar bug --- backend/main.py | 15 +++++++++++++++ frontend/src/components/Sidebar.tsx | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/backend/main.py b/backend/main.py index 5165c9a..a5fad05 100644 --- a/backend/main.py +++ b/backend/main.py @@ -186,6 +186,21 @@ def get_session(session_id: str): "messages": session.messages } +@app.post("/nanobot/sessions/{session_id}/ensure") +def ensure_session(session_id: str): + if not nanobot_service.agent: + raise HTTPException(status_code=400, detail="Nanobot not running") + session = nanobot_service.agent.sessions.get_or_create(session_id) + nanobot_service.agent.sessions.save(session) + alias = session_alias_store.get_alias(session_id) + return { + "key": session.key, + "created_at": session.created_at, + "updated_at": session.updated_at, + "metadata": session.metadata, + "alias": alias, + } + @app.delete("/nanobot/sessions/{session_id}") def delete_session(session_id: str): if not nanobot_service.agent: diff --git a/frontend/src/components/Sidebar.tsx b/frontend/src/components/Sidebar.tsx index 44954df..93e095a 100644 --- a/frontend/src/components/Sidebar.tsx +++ b/frontend/src/components/Sidebar.tsx @@ -208,8 +208,15 @@ function SidebarBody() { navigate(`/?session=${encodeURIComponent(key)}`); }; - const handleNewThread = () => { + const handleNewThread = async () => { const newSessionId = `api:${Date.now()}`; + try { + await api.post(`/nanobot/sessions/${encodeURIComponent(newSessionId)}/ensure`, {}); + await fetchSessions(); + window.dispatchEvent(new Event("nanobot:sessions-changed")); + } catch (e) { + console.error("Failed to create session", e); + } navigate(`/?session=${encodeURIComponent(newSessionId)}`); };