feat(chat): consume session-scoped chat listing in sidebar

Merged
AR
6mo ago
+256-127

Pairs with the api change that pivots GET /api/chats to read chats ⋈ sessions. Each row carries sessionId and artistId, so the sidebar pushes the canonical /sessions/{sid}/chats/{cid} URL directly and scopes the list to the currently selected artist.

  • getConversations (now under lib/chat/, with a zod schema validating the api response) maps the camelCase wire shape onto the local Conversation (topic ← title, account_id ← accountId, updated_at ← updatedAt, artist_id ← artistId, new sessionId). It accepts an optional artistAccountId and forwards it as ?artist_account_id=….
  • useConversations pulls selectedArtist?.account_id from ArtistProvider and threads it through the fetcher; the artist id is part of the react-query key so switching artists triggers a fresh fetch rather than reusing the previous artist's cached list. The query is gated on !isArtistsLoading and RecentChats keeps the skeleton up until then, so the user never sees the unfiltered list flash.
  • useClickChat and the get_chats tool result component emit canonical URLs.
  • addOptimisticConversation takes sessionId; legacy chats (no sessionId) skip optimistic add and surface on the next refetch.

Branch already includes test (which carries chat#1752 + chat#1757), so the canonical /sessions/[sessionId]/chats/[chatId] route is in scope and clicks render the chat page — no 404.

Test plan

  • On a Vercel preview with an artist selected, sidebar lists only that artist's chats.
  • Switch to a different artist and confirm the list refetches and updates without showing an unfiltered flash.
  • Sidebar row click pushes /sessions/{sid}/chats/{cid} and the chat page renders (existing chats hydrate with history, new ones show the empty input).
  • get_chats AI tool result lists chats with canonical hrefs.
  • Sending a first message from /chat adds an optimistic row to the sidebar; replaced by the real row on next refetch.