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.
74 lines
4.7 KiB
Markdown
74 lines
4.7 KiB
Markdown
# Authenticated Gemini voice integration
|
|
|
|
Gemini Live is temporarily the sole voice provider because an OpenAI Realtime
|
|
voice key is unavailable. Extraction, embeddings, calibration and canonical
|
|
search retain their existing providers and frozen profiles. The browser never
|
|
receives a provider credential, event, model selector or private call ID.
|
|
|
|
Use the [client module](../../examples/voice-client.js) and
|
|
[audio worklet](../../examples/voice-audio-worklet.js), served on the configured
|
|
same origin. This is a developer example, not a production interface.
|
|
|
|
```js
|
|
import {VoiceClient} from './voice-client.js';
|
|
const client = new VoiceClient(event => console.log(event.type));
|
|
await client.login(username, password); // supply credentials from your local form
|
|
await client.reserve(); // retain request IDs for identical retries/recovery
|
|
await client.connect(); // call from a user gesture permitting AudioContext
|
|
// On explicit stop: await client.close(); await client.poll();
|
|
// On media loss: await client.recover(); await client.freshSession();
|
|
// On logout: await client.logout();
|
|
```
|
|
|
|
`GET /api/v1/me` refreshes actual expiry and CSRF. HTTP mutations use the opaque
|
|
cookie and CSRF; WebSocket upgrade uses that cookie plus the browser's Origin.
|
|
The API accepts no bearer or query token. Preserve the same normalized payload
|
|
and request ID after ambiguous creation; V03 recovers without opening Gemini.
|
|
Connected/terminal recovery does not restore media/provider context. Close the
|
|
old reservation before requesting a fresh conversation and session.
|
|
|
|
The exercised schemas are `session_ready`, `transcript` (role user/assistant,
|
|
status partial/completed), `sources`, `user_speech_started`, `audio_started`,
|
|
`audio_ended`, `turn_interrupted`, `error`, and the sole client control
|
|
`playback_progress` with `audio_ref` and cumulative `played_ms`. Transcripts
|
|
and sources are retrieved/current-session information, not durable full history.
|
|
|
|
The client waits for `session_ready` before opening the microphone. It verifies
|
|
an actual 24 kHz AudioContext, which resamples device capture; the worklet mixes
|
|
channels and emits aligned mono PCM16LE 480-byte frames. Unsupported context
|
|
rates fail explicitly. Sending is bounded by WebSocket buffered bytes. Ordered
|
|
binary playback belongs to the last audio_started reference and is sealed by
|
|
audio_ended. The playback worklet bounds samples and reports the floor of actual
|
|
consumed samples / 24, never estimated elapsed time or generated samples.
|
|
Interruption flushes queued audio and reports each reference's final consumed
|
|
position. Explicit close stops capture and tracks, flushes actual final playback progress
|
|
while the socket is usable, commits HTTP V04, and then closes transport/audio.
|
|
Requests wait at most five seconds each, flush at most 250 ms and AudioContext
|
|
close at most one second; a genuine transport loss stays a failure.
|
|
Connection generations own their audio, tracks and callbacks. Late permission
|
|
results are stopped immediately, cleanup is coalesced, and callbacks from an old
|
|
socket cannot close a newer session. Logout always attempts A02 even if identity
|
|
refresh or V04 fails, then clears local resources and identity. Valid sessions
|
|
retain CSRF enforcement; expired/repeated logout still validates Origin.
|
|
|
|
Canonical search errors for an eligible turn are displayed while its authorized
|
|
spoken explanation and later interaction continue. Setup/transport/overflow,
|
|
authority and context synchronization failures stop resources. Error fatality is
|
|
not inferred from retryable alone. The client does not retry tool execution.
|
|
Identical durable technical results replay only after fresh backend eligibility
|
|
checks; cancelled/revoked/stale-parent results cannot continue.
|
|
|
|
Gemini setup readiness requires native setupComplete, not an echoed requested
|
|
configuration. This profile requires native voiceActivity with usable offsets;
|
|
missing boundaries fail safely. Input transcripts without offsets become
|
|
ambiguous after more than one input; that fails rather than rebinding delayed
|
|
speech. Output transcripts use outputTranscription. There is no verified
|
|
sample-level Gemini context truncation: interruption/context cleanup closes the
|
|
session and requires freshSession. Seamless barge-in is not certified. Diagnostic text smoke uses native clientContent; first correlated model/tool
|
|
output proves input consumption. It never fabricates an item acknowledgement.
|
|
|
|
Technical fake-wire/worklet checks, retrieval quality and real-browser speech
|
|
acceptance are separate. Real microphone/Persian audio/network behavior remains
|
|
unverified until explicit provider opt-in, approved corpus, measured compatible
|
|
calibration and budgets are supplied. See the [repair report](realtime-agent-phase2-repair.md).
|