feat(ai): citations column on ai_messages (contract request 5)

New packages/feature-ai/migrations/0001_ai_message_citations.sql adds
ai_messages.citations_json and folds v1 'sources' rows into the assistant
row before them. The feature writes and reads the column directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas WintherandClaude Opus 5.5 committed 2026-10-30 20:28:23 +01:00
1 parent fbfe16534a
commit d34a5c1f0c
9 files changed
+94 -22

No files matched your search

@@ -0,0 +1,10 @@
-- v1.1 (contract request 5): an assistant message's citations live in its own column.
-- v1 stored them as an extra row with role 'sources' right after the assistant row (ids sort in write order).
-- Fold each such row into the assistant row before it, then drop every 'sources' row.
ALTER TABLE ai_messages ADD COLUMN citations_json TEXT;
UPDATE ai_messages SET citations_json = (
SELECT s.content FROM ai_messages s
WHERE s.conversation_id = ai_messages.conversation_id AND s.role = 'sources'
AND s.id = (SELECT MIN(n.id) FROM ai_messages n WHERE n.conversation_id = ai_messages.conversation_id AND n.id > ai_messages.id)
) WHERE role = 'assistant';
DELETE FROM ai_messages WHERE role = 'sources';