feat(chat): archive the session for sidebar "Delete chat"

Closed
AR
6mo ago
+83-47

Summary

Switches the sidebar's "Delete chat" action to soft-delete by archiving the owning session instead of deleting the chat row. The api (api#630) filters chats from archived sessions out of GET /api/chats, so the row disappears from the sidebar; archive also triggers the existing sandbox-teardown lifecycle, and the whole thing is reversible from the admin side.

This also unblocks deleting the last chat in a session — the previous chat-row delete refused with 400 Cannot delete the only chat in a session, while 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.
  • Remove the now-unused lib/chats/deleteChat.ts.

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 (each 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

  • Base: chat#1758 (feat/sidebar-delete-rename-session-scoped). Stacked so the file moves don't conflict.
  • Requires api#630 live; until then, archived sessions still appear in the chat list.

Test plan

  • On a Vercel preview with api#630 live, click a sidebar chat → ⋮ → Delete → Confirm. Row disappears after refetch. Verify the underlying session is now status: "archived" via GET /api/sessions/{sid}.
  • Bulk delete multiple rows. All disappear.
  • Delete a chat that was previously the "only chat in its session" (used to 400). Now succeeds.

Summary by cubic

Switch the sidebar “Delete chat” to archive the session instead of deleting the chat. The row disappears, sandbox teardown runs, deleting the last chat now works, and the action is reversible.

  • New Features

    • Archive sessions via lib/sessions/archiveSession.ts (PATCH /api/sessions/{sid} with { status: "archived" }).
    • Update useDeleteChat and DeleteConfirmationModal to use session archive (no chatId).
    • Remove lib/chats/deleteChat.ts.
    • Archiving a session hides all its chats.
  • Dependencies

    • Requires api#630 to filter archived sessions from GET /api/chats; until live, archived sessions still appear.
    • Stacked on chat#1758 (feat/sidebar-delete-rename-session-scoped).