refactor(chat): update chat components to use chatId instead of roomId

Merged
AH
6mo ago
+130-143

This commit removes the InstantChatRoom component and updates various hooks and components to replace references of roomId with chatId. The changes ensure that chat functionality is aligned with the new session-scoped architecture, improving consistency across the chat system. Additionally, the sessionId is now required in several components to streamline the chat transport process.


Summary by cubic

Refactored chat to use session-scoped chatId routes and require sessionId across the stack. Dropped legacy /chat/:id pages and the legacy /api/chat transport; all traffic goes through workflow.

  • Refactors

    • Removed app/chat/[roomId]/page.tsx; replaced roomId with chatId in hooks/components; sidebar derives the active chat from /sessions/:sessionId/chats/:chatId.
    • sessionId is now required in Chat, useVercelChat, useChatTransport, useMessageLoader, and VercelChatProvider; context exposes sessionId.
    • Transport always posts to POST /api/chat/workflow, injecting sessionId, chatId, and the bearer token.
    • Split URL helpers into lib/chat/getChatPath, lib/chat/getChatUrl, and lib/chat/isActiveChatRoomPath with tests; isActiveChatRoomPath now only matches session-scoped paths. Used for URL updates, email CTAs, and route guards.
    • Replaced usePathname with window.location.pathname and hard-nav via window.location.href in Header/Artist and OrganizationProvider to avoid Next router desync; simplified useParams to { chatId }.
    • Recent Chats now parses session-scoped paths; fixed new-chat URL handling by casting newRoomId to string and using getChatPath.
  • Migration

    • Pass sessionId and chatId to VercelChatProvider and Chat.
    • Rename any roomId params/routes to chatId; use /sessions/[sessionId]/chats/[chatId].
    • Use getChatPath/getChatUrl for links and history updates; remove any dependency on legacy /api/chat.
    • Update email CTAs to use getChatUrl(sessionId, conversationId) and ensure sessionId is provided.

Summary by CodeRabbit

  • Refactor

    • Chat routing unified to session-scoped URLs and consistent chat paths.
    • Sessions are now required for chat operations and context.
    • Chat transport always uses the workflow endpoint with consistent session/chat context.
    • URL generation and navigation updated for reliable chat-to-chat and organization switches.
  • Bug Fixes

    • Improved detection of active chat routes to prevent stale/incorrect redirects.
  • Other

    • Email links now point to the canonical chat URL.