feat(chat): session-scoped sidebar rename + archive-on-delete

Closed
AR
6mo ago
+120-65

Stacked on chat#1756. Two related changes to the sidebar's chat actions:

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}.
  • useRenameModal sends title (was topic).

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. The whole thing is 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" }.
  • useDeleteChat calls it (drops the chatId arg).
  • DeleteConfirmationModal no longer passes chatId.

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 session + single chat), so this is a no-op in practice — but worth knowing before we add a UI that creates additional chats inside an existing session.

Dependencies

  • Requires api#630 (filter archived sessions from GET /api/chats) live; until that lands, archived sessions still appear in the list.
  • Base auto-rebases to test once chat#1756 merges.

Test plan

  • Rename a chat → sidebar shows new title after refetch. Verify via GET /api/chats that title updated server-side.
  • Delete a single chat → row disappears after refetch. Verify the owning session is status: "archived" via GET /api/sessions/{sid}.
  • Bulk delete multiple rows. All disappear.
  • Delete a chat that's the only chat in its session (previously 400'd). Now succeeds.