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

Method getActiveMessageId

packages/node-runtime/src/ai/chats.ts:384–402  ·  view source on GitHub ↗
(aiChatId: string)

Source from the content-addressed store, hash-verified

382 }
383
384 private getActiveMessageId(aiChatId: string): string | null {
385 const db = this.getDb()
386 const row = db.prepare('SELECT active_message_id as activeMessageId FROM ai_chat WHERE id = ?').get(aiChatId) as
387 | { activeMessageId: string | null }
388 | undefined
389 if (row?.activeMessageId) {
390 const activeExists = db.prepare('SELECT 1 FROM ai_message WHERE id = ?').get(row.activeMessageId)
391 if (activeExists) return row.activeMessageId
392 }
393
394 const fallback = db
395 .prepare('SELECT id FROM ai_message WHERE ai_chat_id = ? ORDER BY timestamp DESC, id DESC LIMIT 1')
396 .get(aiChatId) as { id: string } | undefined
397 if (fallback?.id) {
398 db.prepare('UPDATE ai_chat SET active_message_id = ? WHERE id = ?').run(fallback.id, aiChatId)
399 return fallback.id
400 }
401 return null
402 }
403
404 private getAllMessageRows(aiChatId: string): AIMessageRow[] {
405 return this.getDb()

Callers 2

getActivePathRowsMethod · 0.95
addMessageMethod · 0.95

Calls 4

getDbMethod · 0.95
getMethod · 0.65
prepareMethod · 0.65
runMethod · 0.65

Tested by

no test coverage detected