(bookId?: string)
| 3 | import { getMessages } from "./message-queries"; |
| 4 | |
| 5 | export async function getThreads(bookId?: string): Promise<Thread[]> { |
| 6 | const database = await getDB(); |
| 7 | const rows = bookId |
| 8 | ? await database.select<{ |
| 9 | id: string; |
| 10 | book_id: string | null; |
| 11 | title: string; |
| 12 | memory_summary: string | null; |
| 13 | memory_updated_at: number | null; |
| 14 | memory_message_count: number | null; |
| 15 | created_at: number; |
| 16 | updated_at: number; |
| 17 | }>("SELECT * FROM threads WHERE book_id = ? ORDER BY updated_at DESC", [bookId]) |
| 18 | : await database.select<{ |
| 19 | id: string; |
| 20 | book_id: string | null; |
| 21 | title: string; |
| 22 | memory_summary: string | null; |
| 23 | memory_updated_at: number | null; |
| 24 | memory_message_count: number | null; |
| 25 | created_at: number; |
| 26 | updated_at: number; |
| 27 | }>("SELECT * FROM threads ORDER BY updated_at DESC"); |
| 28 | |
| 29 | const threads: Thread[] = []; |
| 30 | for (const row of rows) { |
| 31 | const messages = await getMessages(row.id); |
| 32 | threads.push({ |
| 33 | id: row.id, |
| 34 | bookId: row.book_id || undefined, |
| 35 | title: row.title, |
| 36 | messages, |
| 37 | memorySummary: row.memory_summary || undefined, |
| 38 | memoryUpdatedAt: row.memory_updated_at || undefined, |
| 39 | memoryMessageCount: row.memory_message_count || 0, |
| 40 | createdAt: row.created_at, |
| 41 | updatedAt: row.updated_at, |
| 42 | }); |
| 43 | } |
| 44 | return threads; |
| 45 | } |
| 46 | |
| 47 | export async function getThread(id: string): Promise<Thread | null> { |
| 48 | const database = await getDB(); |
no test coverage detected