(id: string)
| 45 | } |
| 46 | |
| 47 | export async function getThread(id: string): Promise<Thread | null> { |
| 48 | const database = await getDB(); |
| 49 | const rows = await database.select<{ |
| 50 | id: string; |
| 51 | book_id: string | null; |
| 52 | title: string; |
| 53 | memory_summary: string | null; |
| 54 | memory_updated_at: number | null; |
| 55 | memory_message_count: number | null; |
| 56 | created_at: number; |
| 57 | updated_at: number; |
| 58 | }>("SELECT * FROM threads WHERE id = ?", [id]); |
| 59 | if (rows.length === 0) return null; |
| 60 | |
| 61 | const row = rows[0]; |
| 62 | const messages = await getMessages(row.id); |
| 63 | return { |
| 64 | id: row.id, |
| 65 | bookId: row.book_id || undefined, |
| 66 | title: row.title, |
| 67 | messages, |
| 68 | memorySummary: row.memory_summary || undefined, |
| 69 | memoryUpdatedAt: row.memory_updated_at || undefined, |
| 70 | memoryMessageCount: row.memory_message_count || 0, |
| 71 | createdAt: row.created_at, |
| 72 | updatedAt: row.updated_at, |
| 73 | }; |
| 74 | } |
| 75 | |
| 76 | export async function insertThread(thread: Thread): Promise<void> { |
| 77 | const database = await getDB(); |
no test coverage detected