feat(chat): consume session-scoped chat listing in sidebar
Merged
AR
6mo ago+256+256+012345678901234567890123456789-127-127-012345678901234567890123456789
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 underlib/chat/, with a zod schema validating the api response) maps the camelCase wire shape onto the localConversation(topic ← title,account_id ← accountId,updated_at ← updatedAt,artist_id ← artistId, newsessionId). It accepts an optionalartistAccountIdand forwards it as?artist_account_id=….useConversationspullsselectedArtist?.account_idfromArtistProviderand 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!isArtistsLoadingandRecentChatskeeps the skeleton up until then, so the user never sees the unfiltered list flash.useClickChatand theget_chatstool result component emit canonical URLs.addOptimisticConversationtakessessionId; legacy chats (nosessionId) 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_chatsAI tool result lists chats with canonical hrefs. - Sending a first message from
/chatadds an optimistic row to the sidebar; replaced by the real row on next refetch.