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

Method deleteMessagesFrom

packages/node-runtime/src/ai/chats.ts:656–676  ·  view source on GitHub ↗
(aiChatId: string, messageId: string)

Source from the content-addressed store, hash-verified

654 }
655
656 deleteMessagesFrom(aiChatId: string, messageId: string): void {
657 const db = this.getDb()
658 const target = this.getMessageRow(messageId)
659 if (!target || target.aiChatId !== aiChatId) {
660 throw new Error('Message not found in AI chat')
661 }
662
663 const activePath = this.getActivePathRows(aiChatId)
664 const targetIndex = activePath.findIndex((row) => row.id === messageId)
665 if (targetIndex < 0) {
666 throw new Error('Message not on active path')
667 }
668
669 const idsToDelete = activePath.slice(targetIndex).map((row) => row.id)
670 const placeholders = idsToDelete.map(() => '?').join(', ')
671 db.prepare(`DELETE FROM ai_message WHERE id IN (${placeholders})`).run(...idsToDelete)
672
673 const newLeafId = targetIndex > 0 ? activePath[targetIndex - 1]!.id : null
674 const now = Math.floor(Date.now() / 1000)
675 db.prepare('UPDATE ai_chat SET active_message_id = ?, updated_at = ? WHERE id = ?').run(newLeafId, now, aiChatId)
676 }
677
678 forkAIChat(sourceAIChatId: string, upToMessageId: string, title?: string): AIChat {
679 const db = this.getDb()

Callers

nothing calls this directly

Calls 6

getDbMethod · 0.95
getMessageRowMethod · 0.95
getActivePathRowsMethod · 0.95
runMethod · 0.65
prepareMethod · 0.65
nowMethod · 0.45

Tested by

no test coverage detected