| 24-search-history-branching |
01 |
api |
| postgres |
| drizzle-orm |
| tsvector |
| fts |
| express |
| bookmarks |
| branching |
| export |
|
| phase |
provides |
| 24-00 |
DB schema for chat_message_bookmarks, parentConversationId/branchFromMessageId in chatConversations, content_search tsvector column, searchMessagesSchema/branchConversationSchema validators, ChatMessageSearchResult/ChatBookmark types |
|
|
| searchMessages: tsvector FTS with ts_rank ranking, company-scoped via conversation join |
| toggleBookmark: transactional insert-or-delete bookmark |
| getBookmarks: paginated bookmarks with message and conversation join |
| branchConversation: copies messages up to branch point into new child conversation |
| listBranches: queries child conversations by parentConversationId |
| exportConversation: Markdown and JSON export with agent name resolution |
| Six Express route handlers: search, bookmark toggle, bookmark list, branch create, branch list, export download |
|
| 24-02 (UI hooks and API client wiring) |
| 24-03 (UI components for search/bookmark/branch) |
|
| added |
patterns |
|
|
| chatService(db) factory extended with new methods — same pattern as existing listConversations, addMessage |
| tsvector FTS via raw sql`` template — content_search column is Postgres-generated stored, not in Drizzle schema |
| Export route sets Content-Disposition + Content-Type headers, uses res.send(content) |
| Transaction for bookmark toggle ensures atomicity of read-then-write |
|
|
| created |
modified |
|
|
| server/src/services/chat.ts |
| server/src/routes/chat.ts |
|
|
| Used this.getConversation() reference in exportConversation to reuse existing notFound guard — avoids duplicate query logic |
| searchMessages returns early with empty items when query is blank after trim — avoids FTS error on empty tsquery |
|
| Pattern: LEFT JOIN agents ON chatMessages.agentId = agents.id for agent name resolution in export |
| Pattern: branchConversation uses lte(createdAt) to include branch point message in copy |
|
| CHAT-07 |
| CHAT-13 |
| CHAT-14 |
| HIST-04 |
| HIST-09 |
| HIST-10 |
| HIST-11 |
| PERF-04 |
|
12min |
2026-04-01 |