MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / getRecentChatSessions

Function getRecentChatSessions

packages/core/src/query/session-queries.ts:456–474  ·  view source on GitHub ↗
(db: DatabaseAdapter, limit: number)

Source from the content-addressed store, hash-verified

454 * Get the most recent N chat sessions.
455 */
456export function getRecentChatSessions(db: DatabaseAdapter, limit: number): ChatSessionItem[] {
457 if (!hasTable(db, 'segment')) return []
458 try {
459 return db
460 .prepare(
461 `SELECT
462 id, start_ts as startTs, end_ts as endTs,
463 message_count as messageCount, summary,
464 (SELECT mc.message_id FROM message_context mc
465 WHERE mc.segment_id = cs.id ORDER BY mc.message_id LIMIT 1) as firstMessageId
466 FROM segment cs
467 ORDER BY start_ts DESC
468 LIMIT ?`
469 )
470 .all(limit) as unknown as ChatSessionItem[]
471 } catch {
472 return []
473 }
474}
475
476/**
477 * Timeline list of chat sessions with first message id and summary.

Callers

nothing calls this directly

Calls 3

hasTableFunction · 0.90
allMethod · 0.65
prepareMethod · 0.65

Tested by

no test coverage detected