fix(chats): exclude chats with zero messages from listing
Merged
AR
4mo ago+16+16+01234567890123456789-24-24-01234567890123456789
Chats with no messages no longer appear in the chat listing. selectChatsWithSessions now inner-joins chat_messages, so a chat only surfaces once it has at least one message. This applies to both GET /api/chats and the get_chats MCP tool, which share the function. The embedded count keeps the query to one aggregate row per chat rather than fetching every message.
Test plan
pnpm test lib/chats lib/supabase/chats lib/mcp/tools/chats— 201 greenpnpm lint:check— clean- Verify on Vercel preview:
GET /api/chatsomits freshly-created, message-less chats and still returns chats with messages.
Summary by cubic
Exclude empty chats from listings by inner-joining chat_messages in selectChatsWithSessions, so a chat appears only after it has at least one message. Applies to GET /api/chats and the get_chats MCP tool; uses messages:chat_messages!inner ( id ) to enforce a true inner join, with tests updated to assert it and comments trimmed.
Summary by CodeRabbit
- Bug Fixes
- Chat listings now exclude conversations without messages.
- Message count information is now included in chat data.