(db: DatabaseAdapter)
| 477 | * Timeline list of chat sessions with first message id and summary. |
| 478 | */ |
| 479 | export function getChatSessionList(db: DatabaseAdapter): ChatSessionItem[] { |
| 480 | if (!hasTable(db, 'segment')) return [] |
| 481 | try { |
| 482 | return db |
| 483 | .prepare( |
| 484 | `SELECT |
| 485 | cs.id, |
| 486 | cs.start_ts as startTs, |
| 487 | cs.end_ts as endTs, |
| 488 | cs.message_count as messageCount, |
| 489 | cs.summary, |
| 490 | (SELECT mc.message_id FROM message_context mc |
| 491 | WHERE mc.segment_id = cs.id ORDER BY mc.message_id LIMIT 1) as firstMessageId |
| 492 | FROM segment cs |
| 493 | ORDER BY cs.start_ts ASC` |
| 494 | ) |
| 495 | .all() as unknown as ChatSessionItem[] |
| 496 | } catch { |
| 497 | return [] |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Load messages for a chat session (for summary generation). |
no test coverage detected