-- Source evidence follows the existing chat privacy/RLS policy.
alter table public.chat_messages
  add column if not exists agent_evidence jsonb,
  add column if not exists voice_backend_message_id text;

alter table public.chat_messages add constraint chat_agent_evidence_object
  check (agent_evidence is null or (jsonb_typeof(agent_evidence) = 'object' and octet_length(agent_evidence::text) <= 150000));

-- Replayed LiveKit metadata must not create duplicate answers.
create unique index if not exists chat_voice_backend_message_unique
  on public.chat_messages (trip_id, voice_backend_message_id)
  where voice_backend_message_id is not null;
