Promote chat-workflow cutover to main

Merged
SW
6mo ago
+1311-552

Promotes the chat-workflow cutover from test to main. This is the chat half of the recoupable/chat#1747 bundle — pairs with recoupable/api#631 (must merge before this).

What this ships

9 PRs merged to test since the cutover began:

PRWhat
#1748feat: route new chats through recoup-api /api/chat/workflow (vertical-slice cutover)
#1751fix(deps): bump ai SDK off beta to stable v6 so workflow tool outputs render
#1752feat(chat): add /sessions/[sid]/chats/[cid] route + session-scoped loader
#1756feat(chat): consume session-scoped chat listing in sidebar (artist filter via ?artist_account_id=)
#1757feat(chat): rewrite silentlyUpdateUrl to emit canonical session URL
#1759feat(chat): stamp sessions.artist_id from selectedArtist; refactor useArtists
#1760refactor(chat): HomePage / uses NewChatBootstrap (bash tools on /)
#1761refactor: centralize useAutoLogin into UserProvider (5 sites → 1)
#1763feat(chat): session-scoped sidebar rename + archive-on-delete

9 commits ahead of main, 0 behind.

What changes for the user

On / and /chat:

  • New chats go through POST /api/sessions (session+chat row provisioned in api) + POST /api/sandbox (Vercel Sandbox spun up) + POST /api/chat/workflow (streaming response)
  • The agent has bash tools available — files, grep, code execution all work
  • URL canonicalizes on first send: /sessions/{sid}/chats/{cid}

Sidebar:

  • Lists are scoped to the selected artist via ?artist_account_id= (server-side filter)
  • Click a chat row → navigates to canonical URL
  • Rename hits session-scoped PATCH; delete archives the owning session

Legacy /chat/{roomId} URLs:

  • Still resolve (route preserved), but show empty default greeting instead of message history because the new reader requires a sessionId
  • Step 1 of chat#1747 will tighten this to a clean 404 in a follow-up

Known accepted regressions

Documented in the chat#1747 issue body and verified during preview testing:

  • MCP tools removed from the workflow sandbox (no get_chats, no artist-data tools, no send_email, no Composio integrations). The workflow agent gets bash + general file access only.
  • No automatic chat title generation — chat title is the first user message verbatim
  • No artist context in system prompt — agent doesn't know which artist the chat is about
  • No Telegram new-conversation notifications (re-scoped into a future spend-digest cron)
  • Artist switch mid-chat provisions 3 sessions instead of 1 — flagged in chat#1759 comment; only the final session is used by <Chat>, but the lifecycle is wasteful. Follow-up after promotion.
  • /api/chats/{chatId}/artist 404s on chats without a rooms.artist_id row — pre-existing endpoint issue, doesn't break functionality

Ordering requirement

Merge api#631 first. Wait for it to deploy to https://recoup-api.vercel.app. Verify the new shape ships:

curl -s -H "x-api-key: ..." "https://recoup-api.vercel.app/api/chats" | jq '.chats[0] | keys'
# Expect: ["accountId", "artistId", "id", "sessionId", "title", "updatedAt"]

Then merge this PR. The chat client calls endpoints that only exist in api#631:

  • GET /api/sessions/{sid}/chats/{cid} — history reader
  • PATCH /api/sessions/{sid}/chats/{cid} — rename
  • PATCH /api/sessions/{sid} {"status": "archived"} — delete
  • POST /api/sessions { artistId } — new chat
  • GET /api/chats?artist_account_id=... — sidebar filter

If chat merges first, the sidebar breaks (wrong response shape), new chats fail, and rename/delete 404.

Rollback plan

Revert the merge commit. If chat ships but api hasn't (or api gets rolled back), users will see broken sidebar + broken new-chat flow until chat is also reverted.

Test plan

  • api#631 merged and deployed to https://recoup-api.vercel.app
  • Verify api response shape on prod (curl above)
  • CI green on this PR's merge commit
  • On https://chat.recoupable.com: load /, send a message, confirm URL canonicalizes to /sessions/{sid}/chats/{cid} and bash tools work
  • On https://chat.recoupable.com: sidebar lists only the selected artist's chats; switch artist → list updates
  • On https://chat.recoupable.com: rename a chat → title updates; delete a chat → row disappears

Summary by cubic

Routes new chats through recoup-api’s POST /api/chat/workflow by bootstrapping a session and sandbox, and switches the app to canonical session-based chat URLs with an artist-scoped sidebar. Also upgrades the ai SDK stack to stable v6 for proper tool output rendering.

  • New Features

    • New-chat flow: POST /api/sessions → POST /api/sandbox → stream via POST /api/chat/workflow (bash tools enabled).
    • Canonical route: /sessions/[sessionId]/chats/[chatId]; URL updates after first send.
    • Sidebar: lists from GET /api/chats, server-filtered by ?artist_account_id=; click navigates to the canonical URL.
    • Rename: PATCH /api/sessions/{sid}/chats/{cid}; Delete: archive session via PATCH /api/sessions/{sid} { status: "archived" }.
    • Artist UX: new useArtistsRoster + useArtistSelection stabilize per-org selection and prevent duplicate bootstraps.
    • Transport: uses workflow path when sessionId is present; legacy chats still post to /api/chat. Messages load via GET /api/sessions/{sid}/chats/{cid}.
    • Auth: useAutoLogin centralized in UserProvider.
    • Dependencies: upgrade ai → 6.0.165, @ai-sdk/react → 3.0.167, @ai-sdk/anthropic → 3.0.80, @ai-sdk/google → 3.0.80, @ai-sdk/openai → 3.0.66.
  • Migration

    • Merge recoupable/api#631 first and wait for deploy. Verify: GET https://recoup-api.vercel.app/api/chats returns chat rows with ["accountId","artistId","id","sessionId","title","updatedAt"].
    • Chat depends on new endpoints and shapes:
      • POST /api/sessions, POST /api/sandbox, POST /api/chat/workflow
      • GET /api/chats?artist_account_id=...
      • GET /api/sessions/{sid}/chats/{cid}, PATCH /api/sessions/{sid}/chats/{cid}, PATCH /api/sessions/{sid}
    • If chat lands before the API, new chats, sidebar, and rename/delete will fail. Rollback by reverting this merge.