feat(chat): stamp sessions with selected artist; refactor useArtists
Merged
AR
6mo ago+367+367+012345678901234567890123456789-232-232-012345678901234567890123456789
The new-chat bootstrap now forwards the selected artist's account id as artistId when calling POST /api/sessions. The api persists it on sessions.artist_id, grouping the chat under the artist for the sidebar's artist filter.
useNewChatBootstrapreadsselectedArtist?.account_idfromArtistProviderand passes it throughcreateSession.CreateSessionInputaccepts an optionalartistIdfield.
Pairs with api#628 (now merged) and database#27 (now merged). When no artist is selected, artistId is omitted and the session is created without artist linkage.
Test plan
- Select an artist, start a new chat from
/chat, thenGET /api/sessions/{sid}→ response hasartistId === selectedArtist.account_id. - No artist selected, start a new chat → response has
artistId === null.
Summary by cubic
New chats now tag sessions with the selected artist (artistId), and the bootstrap runs exactly once per (artistId, orgId) with proper loading gates to avoid duplicate POSTs. Switching or clearing the artist while viewing an existing chat hard-redirects to /chat; on bare /chat, the bootstrap re-runs in place.
-
New Features
- Send
selectedArtist.account_idasartistIdtoPOST /api/sessions(omit if none) sosessions.artist_idbacks the sidebar artist filter. - Add optional
artistIdtoCreateSessionInput.
- Send
-
Refactors
- Split artists logic: roster moved to
hooks/artists/useArtistsRoster(@tanstack/react-querykeyed on(userId, orgId)), selection tohooks/artists/useArtistSelection(override → saved → first), removeduseInitialArtists, persisted per org. - Roster query is gated on Privy’s
authenticated;setArtistsmutates the query cache;refetchArtistspowersgetArtists. useArtistsRostersurfaces react-query v5isPendingasisLoadingso the disabled-query window still blocks the bootstrap, preventing early provisioning withartistId: undefined.useNewChatBootstrapnow delegates tohooks/sessions/useProvisionChatSession(useMutationkeyed on(artistId, orgId)and gated on artist loading); extractedlib/sessions/provisionChatSessionto combinecreateSession+createSandbox.- In
Artist.tsx, detect existing-chat URLs and usewindow.location.href = "/chat"when changing or deselecting the artist; on bare/chat, no navigation.
- Split artists logic: roster moved to
Summary by CodeRabbit
-
New Features
- Chats now persist an associated artist and new sessions respect the selected artist.
- Improved artist roster loading and selection with per-organization persisted choices.
-
Bug Fixes
- Switching or deselecting an artist while on a chat now navigates to a fresh chat context to avoid stale state.
- Session provisioning is now gated to avoid premature or duplicate provisioning when artist/org or auth state changes.