feat(voice): add authenticated Phase 2 live lifecycle

Add cookie authentication, owned conversations, durable Live reservations,
tool completion/replay fencing, revocation, and startup reconciliation.
Introduce forward lifecycle/owner-chain migrations and the temporary Gemini
adapter while preserving the existing OpenAI Realtime adapter.

Include the executable audio client, regression coverage, configuration,
API/database documentation, and recorded acceptance evidence.

Validation: focused review suite 82 passed; Python/TOML parsing, JavaScript
syntax, and whitespace checks passed. Full PostgreSQL/provider-free results
are recorded in the repair report; real-provider/browser acceptance is unrun.

Follow-up work remains for configurable OpenAI/Gemini selection, transport
admission, authority diagnostics, playback message bounds, and client replay
identity after ambiguous creation responses.
This commit is contained in:
11linear11
2026-10-09 07:59:02 -04:00
parent 07245cd5ca
commit 996435d2ae
42 changed files with 4551 additions and 88 deletions
+67
View File
@@ -0,0 +1,67 @@
/* Application PCM16LE/24kHz contract. The context must actually run at 24kHz. */
class Capture extends AudioWorkletProcessor {
constructor() {
super(); this.samples = []; this.active = true; this.pending = 0;
this.port.onmessage = e => { if (e.data.type === 'stop') this.active = false; else if (e.data.type === 'accepted') this.pending = Math.max(0, this.pending - 1); };
}
process(inputs) {
if (!this.active) return false;
const channels = inputs[0];
if (!channels?.length) return true;
for (let i = 0; i < channels[0].length; i++) {
let mono = 0; for (const channel of channels) mono += channel[i] / channels.length;
this.samples.push(Math.max(-32768, Math.min(32767, Math.round(mono * 32768))));
if (this.samples.length === 240) {
if (this.pending >= 100) {this.port.postMessage({type: 'overflow'}); this.active = false; return false;}
this.pending++;
const bytes = new ArrayBuffer(480), view = new DataView(bytes);
this.samples.forEach((value, index) => view.setInt16(index * 2, value, true));
this.samples.length = 0;
this.port.postMessage({type: 'pcm', bytes}, [bytes]);
}
}
return true;
}
}
class Playback extends AudioWorkletProcessor {
constructor() {
super(); this.queue = []; this.refs = new Map(); this.queued = 0;
this.port.onmessage = ({data}) => {
if (data.type === 'start') {
if (!this.refs.has(data.ref)) this.refs.set(data.ref, {played: 0, sealed: false});
} else if (data.type === 'pcm') {
const samples = new Float32Array(data.samples);
if (!this.refs.has(data.ref) || this.queued + samples.length > 48000) {
this.port.postMessage({type: 'overflow'}); return;
}
this.queue.push({ref: data.ref, samples, position: 0}); this.queued += samples.length;
} else if (data.type === 'end') {
const ref = this.refs.get(data.ref); if (ref) {ref.sealed = true; this.report(data.ref);}
} else if (data.type === 'flush') {
this.queue.length = 0; this.queued = 0;
for (const [ref] of this.refs) this.report(ref);
this.refs.clear(); this.port.postMessage({type: 'flushed', id: data.id});
}
};
}
report(ref) {
const state = this.refs.get(ref); if (!state) return;
this.port.postMessage({type: 'progress', ref, played_ms: Math.floor(state.played / 24)});
if (state.sealed && !this.queue.some(part => part.ref === ref)) this.refs.delete(ref);
}
process(inputs, outputs) {
const output = outputs[0]?.[0]; if (!output) return true;
output.fill(0);
const touched = new Set();
for (let i = 0; i < output.length && this.queue.length; i++) {
const part = this.queue[0], state = this.refs.get(part.ref);
output[i] = part.samples[part.position++]; this.queued--; state.played++; touched.add(part.ref);
if (part.position === part.samples.length) this.queue.shift();
}
// Reports count only samples actually consumed by this output process callback.
for (const ref of touched) this.report(ref);
return true;
}
}
registerProcessor('rag-capture', Capture);
registerProcessor('rag-playback', Playback);