(aiChatId: string, messageId: string)
| 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() |
nothing calls this directly
no test coverage detected