feat(voice): port the pure realtime core - #2387
Merged
Merged
Conversation
Ports the proven core from the pagespace-voice prototype into apps/web/src/lib/ai/realtime/ as three pure modules — no I/O, no clock, no randomness, no module-level mutable state, no React: - events.ts: function calls out of `response.done`, transcripts under BOTH `response.output_audio_transcript.done` and the older `response.audio_transcript.done` (renamed across releases, deployments straddle it), the `function_call_output` client event, and a `parseEvent` that returns undefined on a malformed frame rather than throwing. - session.ts: the `client_secrets` body shape, the two endpoint URLs, the `oai-events` channel name, and defensive `value` narrowing on the mint response. Default model is `gpt-realtime` — access is per-account, `client_secrets` accepts any string, and `/v1/realtime/calls` 403s `model_not_found` at connect time — with OPENAI_REALTIME_MODEL as the upgrade path, resolved purely from a passed-in env bag. - session-state.ts: the session reducer. A failure keeps the transcript; a drop mid-conversation must not erase the record. Tool definitions are deliberately not ported: PageSpace has its own tool registry, so only the transport-shaped `RealtimeTool` type lives here. 68 tests, 100% statements/branches/functions/lines on all three files, mutation-checked (34 mutations, each verified to turn the suite red). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VuzQWypmJU8b8pKvqt3BgW
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First leaf of the audio-native voice epic. Adds the pure, I/O-free realtime core under
apps/web/src/lib/ai/realtime/, ported from the workingpagespace-voiceprototype.events.ts—extractFunctionCalls,extractTranscript(handles bothresponse.output_audio_transcript.doneand the legacyresponse.audio_transcript.done),buildFunctionOutput,parseEventsession.ts— session config builder,resolveRealtimeModel(env), and theRealtimeToolwire typesession-state.ts— the UI reducer; a failed connection preserves the transcriptDEFAULT_REALTIME_MODEL = 'gpt-realtime', not 2.1 — the W0 spike provedgpt-realtime-2.1is not on this account (mint returns 200, then/v1/realtime/calls403smodel_not_found), and the prototype's own.envpinsgpt-realtime.OPENAI_REALTIME_MODELremains the upgrade path.Verification: 68 tests pass;
tsc --noEmitclean; mutation-checked the dual transcript-event-name coverage (deleting the legacy name turns exactly one test red).Pure only — no I/O, no clock, no randomness. 888 insertions, no lockfile noise.