(
existing: Array<{ id: string; sessionId: string; assistantId?: string }> = []
)
| 13 | } |
| 14 | |
| 15 | function createAIChatManager( |
| 16 | existing: Array<{ id: string; sessionId: string; assistantId?: string }> = [] |
| 17 | ): AIChatManager { |
| 18 | const chats = new Map<string, { id: string; sessionId: string; title: string | null; assistantId: string }>( |
| 19 | existing.map((chat) => [chat.id, { ...chat, title: null, assistantId: chat.assistantId ?? 'general_cn' }]) |
| 20 | ) |
| 21 | const messages: Array<{ |
| 22 | aiChatId: string |
| 23 | role: string |
| 24 | content: string |
| 25 | contentBlocks?: ContentBlock[] |
| 26 | tokenUsage?: TokenUsageData |
| 27 | }> = [] |
| 28 | |
| 29 | return { |
| 30 | getAIChat: (aiChatId: string) => chats.get(aiChatId) ?? null, |
| 31 | createAIChat: (sessionId: string, title: string | undefined, assistantId: string) => { |
| 32 | const id = `ai_chat_${chats.size + 1}` |
| 33 | const chat = { id, sessionId, title: title ?? null, assistantId } |
| 34 | chats.set(id, chat) |
| 35 | return chat |
| 36 | }, |
| 37 | addMessage: ( |
| 38 | aiChatId: string, |
| 39 | role: string, |
| 40 | content: string, |
| 41 | _dataKeywords?: string[], |
| 42 | _dataMessageCount?: number, |
| 43 | contentBlocks?: ContentBlock[], |
| 44 | tokenUsage?: TokenUsageData |
| 45 | ) => { |
| 46 | messages.push({ |
| 47 | aiChatId, |
| 48 | role, |
| 49 | content, |
| 50 | ...(contentBlocks ? { contentBlocks } : {}), |
| 51 | ...(tokenUsage ? { tokenUsage } : {}), |
| 52 | }) |
| 53 | return { id: `msg_${messages.length}`, aiChatId, role, content, timestamp: 1 } |
| 54 | }, |
| 55 | __messages: messages, |
| 56 | } as unknown as AIChatManager |
| 57 | } |
| 58 | |
| 59 | class MemoryWritable extends Writable { |
| 60 | chunks: string[] = [] |
no test coverage detected