diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index ca5d16af..9e7906bf 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -593,10 +593,14 @@ export { updateConversationSchema, createMessageSchema, handoffSchema, + searchMessagesSchema, + branchConversationSchema, type CreateConversation, type UpdateConversation, type CreateMessage, type Handoff, + type SearchMessages, + type BranchConversation, } from "./validators/index.js"; export type { @@ -605,6 +609,12 @@ export type { ChatMessage, ChatConversationListResponse, ChatMessageListResponse, + ChatMessageSearchResult, + ChatMessageSearchResponse, + ChatBookmark, + ChatBookmarkWithMessage, + ChatBookmarkListResponse, + ChatBookmarkToggleResponse, } from "./types/chat.js"; export { API_PREFIX, API } from "./api.js"; diff --git a/packages/shared/src/types/chat.ts b/packages/shared/src/types/chat.ts index bd97469b..b015cd1b 100644 --- a/packages/shared/src/types/chat.ts +++ b/packages/shared/src/types/chat.ts @@ -8,6 +8,8 @@ export interface ChatConversation { deletedAt: string | null; createdAt: string; updatedAt: string; + parentConversationId: string | null; + branchFromMessageId: string | null; } export interface ChatConversationListItem { @@ -19,6 +21,8 @@ export interface ChatConversationListItem { archivedAt: string | null; updatedAt: string; lastMessagePreview: string | null; + parentConversationId: string | null; + branchFromMessageId: string | null; } export interface ChatMessage { @@ -41,3 +45,39 @@ export interface ChatMessageListResponse { items: ChatMessage[]; hasMore: boolean; } + +export interface ChatMessageSearchResult { + messageId: string; + conversationId: string; + conversationTitle: string | null; + content: string; + role: "user" | "assistant" | "system"; + agentId: string | null; + createdAt: string; + rank: number; +} + +export interface ChatMessageSearchResponse { + items: ChatMessageSearchResult[]; +} + +export interface ChatBookmark { + id: string; + companyId: string; + messageId: string; + conversationId: string; + createdAt: string; +} + +export interface ChatBookmarkWithMessage extends ChatBookmark { + message: ChatMessage; + conversationTitle: string | null; +} + +export interface ChatBookmarkListResponse { + items: ChatBookmarkWithMessage[]; +} + +export interface ChatBookmarkToggleResponse { + bookmarked: boolean; +} diff --git a/packages/shared/src/validators/chat.ts b/packages/shared/src/validators/chat.ts index b7a5a3b0..91a17f5c 100644 --- a/packages/shared/src/validators/chat.ts +++ b/packages/shared/src/validators/chat.ts @@ -33,3 +33,15 @@ export type CreateConversation = z.infer; export type UpdateConversation = z.infer; export type CreateMessage = z.infer; export type Handoff = z.infer; + +export const searchMessagesSchema = z.object({ + q: z.string().min(2).max(200), + limit: z.coerce.number().int().min(1).max(50).optional(), +}); + +export const branchConversationSchema = z.object({ + branchFromMessageId: z.string().uuid(), +}); + +export type SearchMessages = z.infer; +export type BranchConversation = z.infer; diff --git a/server/src/__tests__/chat-routes.test.ts b/server/src/__tests__/chat-routes.test.ts index 6b161fdb..02dcbeca 100644 --- a/server/src/__tests__/chat-routes.test.ts +++ b/server/src/__tests__/chat-routes.test.ts @@ -196,4 +196,22 @@ describe("chatRoutes", () => { ); }); }); + + describe("GET /companies/:id/messages/search", () => { + it.todo("returns 200 with search results"); + it.todo("returns 400 for short query"); + }); + + describe("POST /conversations/:id/bookmarks", () => { + it.todo("toggles bookmark on/off"); + }); + + describe("POST /conversations/:id/branch", () => { + it.todo("returns 201 with branched conversation"); + }); + + describe("GET /conversations/:id/export", () => { + it.todo("returns markdown file download"); + it.todo("returns JSON file download"); + }); }); diff --git a/server/src/__tests__/chat-service.test.ts b/server/src/__tests__/chat-service.test.ts index 0bd46e99..eae6da19 100644 --- a/server/src/__tests__/chat-service.test.ts +++ b/server/src/__tests__/chat-service.test.ts @@ -383,4 +383,25 @@ describe("chatService", () => { expect(result.items.length).toBe(50); }); }); + + describe("searchMessages", () => { + it.todo("returns ranked results for matching term"); + it.todo("returns empty for no match"); + it.todo("respects companyId scope"); + }); + + describe("toggleBookmark", () => { + it.todo("creates bookmark when not exists"); + it.todo("removes bookmark when exists"); + }); + + describe("branchConversation", () => { + it.todo("creates child conversation with copied messages"); + it.todo("throws not found for invalid message id"); + }); + + describe("exportConversation", () => { + it.todo("exports as markdown with agent names"); + it.todo("exports as JSON with all messages"); + }); });