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

Function getSegmentSummaries

packages/core/src/query/session-queries.ts:310–366  ·  view source on GitHub ↗
(
  db: DatabaseAdapter,
  options?: { limit?: number; timeFilter?: TimeFilter }
)

Source from the content-addressed store, hash-verified

308 * Get session summaries (only sessions that have AI-generated summaries)
309 */
310export function getSegmentSummaries(
311 db: DatabaseAdapter,
312 options?: { limit?: number; timeFilter?: TimeFilter }
313): SegmentSummaryData[] {
314 if (!hasTable(db, 'segment')) return []
315
316 const { limit = 50, timeFilter } = options ?? {}
317
318 let sql = `
319 SELECT cs.id, cs.start_ts as startTs, cs.end_ts as endTs,
320 cs.message_count as messageCount, cs.summary
321 FROM segment cs
322 WHERE cs.summary IS NOT NULL AND cs.summary != ''
323 `
324 const params: unknown[] = []
325
326 if (timeFilter?.startTs !== undefined) {
327 sql += ' AND cs.start_ts >= ?'
328 params.push(timeFilter.startTs)
329 }
330 if (timeFilter?.endTs !== undefined) {
331 sql += ' AND cs.start_ts <= ?'
332 params.push(timeFilter.endTs)
333 }
334
335 sql += ' ORDER BY cs.start_ts DESC LIMIT ?'
336 params.push(limit)
337
338 const sessions = db.prepare(sql).all(...params) as Array<{
339 id: number
340 startTs: number
341 endTs: number
342 messageCount: number
343 summary: string | null
344 }>
345
346 const participantsSql = `
347 SELECT DISTINCT COALESCE(mb.group_nickname, mb.account_name, mb.platform_id) as name
348 FROM message_context mc
349 JOIN message m ON m.id = mc.message_id
350 JOIN member mb ON mb.id = m.sender_id
351 WHERE mc.segment_id = ? LIMIT 10
352 `
353
354 return sessions.map((session) => {
355 const participants = db.prepare(participantsSql).all(session.id) as Array<{ name: string }>
356
357 return {
358 id: session.id,
359 startTs: session.startTs,
360 endTs: session.endTs,
361 messageCount: session.messageCount,
362 participants: participants.map((p) => p.name),
363 summary: session.summary,
364 }
365 })
366}
367

Callers

nothing calls this directly

Calls 3

hasTableFunction · 0.90
allMethod · 0.65
prepareMethod · 0.65

Tested by

no test coverage detected