feat(chat): session-scoped sidebar rename + archive-on-delete
Replaces chat#1758, which was auto-closed when its base branch (feat/sidebar-canonical-urls) was deleted alongside the chat#1756 merge. Same code, retargeted at test.
Two related changes to the sidebar's chat actions, now that chat#1756 has shipped session-scoped chat listings:
Rename — session-scoped PATCH
The rename flow was still hitting the legacy PATCH /api/chats shape ({ chatId, topic }), which only touched the rooms table. Repoint at PATCH /api/sessions/{sid}/chats/{cid} with { title } so the canonical chat row is updated.
updateChat({ sessionId, chatId, title })→PATCH /api/sessions/{sid}/chats/{cid}.useRenameModalsendstitle(wastopic).
Delete — archive the owning session
Instead of removing the chat row, the "Delete chat" action now archives the owning session via PATCH /api/sessions/{sid} { status: "archived" }. The api filters chats from archived sessions out of GET /api/chats (api#630), so the row disappears from the sidebar; archive also triggers stopSandboxOnArchive so we tear down running sandboxes for chats the user said they're done with. Reversible from the admin side.
This also sidesteps the 400 Cannot delete the only chat in a session guard that blocks chat-row deletes when a session has a single chat — archive has no such constraint.
- New
lib/sessions/archiveSession.ts→PATCH /api/sessions/{sid} { status: "archived" }. useDeleteChatcalls it (drops thechatIdarg).DeleteConfirmationModalno longer passeschatId.
Caveat
If a session ever has >1 chat, archiving from one row hides the others too. Today every sidebar row maps 1:1 to its own session (POST /api/sessions mints a fresh session per chat), so this is a theoretical concern. Will need to revisit if/when sessions ever hold multiple chats.
Summary by cubic
Session-scope the sidebar: renaming now updates the canonical chat row, and “Delete chat” archives the owning session so chats disappear and sandboxes stop.
-
New Features
- Rename chat via
PATCH /api/sessions/{sid}/chats/{cid}with{ title }(threadssessionId; switches fromtopic→title). - Delete chat now archives the session via
PATCH /api/sessions/{sid}with{ status: "archived" }; avoids the “Cannot delete the only chat in a session” 400, is reversible, and triggers sandbox teardown. - Delete modal supports bulk delete with progress and calls the archive path;
useDeleteChatnow takes{ sessionId }. - Removed legacy
lib/chats/deleteChat.ts; addedlib/sessions/archiveSession.ts.
- Rename chat via
-
Migration
- No action needed. Archiving hides all chats in a session and is reversible by admins; the API filters archived sessions from
GET /api/chats.
- No action needed. Archiving hides all chats in a session and is reversible by admins; the API filters archived sessions from
Summary by CodeRabbit
- Refactor
- Chat deletion now archives conversations instead of permanently removing them, preserving the ability to restore if needed.
- Chat renaming updated with improved session-scoped data handling.
- Streamlined delete confirmation workflow and session management logic.