Files
gods-eye-view/src/voice/realtimeSession.js
T
manjunath22466 da8b0dd8cd fix(voice): address review of typed AI chat
Typed chat sessions no longer end on the voice inactivity timeout, and a
failed or stopped reply keeps the conversation: Stop cancels only the
reply in progress, and map actions that already ran stay in the model's
context. Each upstream request and map action gets its own deadline, old
tool results shrink instead of the history overflowing, and step limits,
a missing or rejected key, the OAuth lock and throttling each get their
own message.

- Server: OpenAI chat is off under GEV_PREFER_CODEX_OAUTH; chat throttles
  default to the provider's throttle; replies carry API_KEY_MISSING,
  API_KEY_REJECTED, CODEX_OAUTH_REQUIRED and RATE_LIMITED codes; upstream
  Retry-After passes through, and a rejected key (Gemini's invalid-key 400
  included) cools down for a minute
- Pinokio forwards the chat throttle settings
- UI: the reply reveal publishes only the message list; the border orbit
  runs only while busy; layers attach with a button or Enter; the log is
  aria-busy while a reply types out; auto-scroll respects a reader who
  scrolled up; Escape closes the attach menu; the chat gear says Settings;
  a note says chat bills the OpenAI key when voice uses ChatGPT sign-in
- Layout does less work while panel height animates; unused blurs removed
- Gemini voice start ends chat; the voice preview clears on every new
  session
- Tests for the route gates, client limits, attachments and the fixes
2026-11-03 22:01:08 +05:30

75 lines
2.4 KiB
JavaScript

import { createTextChat } from './textChat.js';
import { GevRealtimeController } from './realtimeController.js';
/** Adapt the existing WebRTC implementation to the common voice session. */
export function createRealtimeSession({
emit,
runAction,
createController = (options) => new GevRealtimeController(options),
...options
}) {
const controller = createController({
...options,
actionExecutor: runAction,
onSessionEvent: emit,
});
let textOnly = false;
const chat = createTextChat({
...options,
provider: 'openai',
runAction,
emit: (event) => {
if (event.type === 'state') controller.status = event.state;
emit(event);
},
});
const startVoice = (settings) => {
chat.stop({ preserveStatus: true });
textOnly = false;
return controller.start(settings);
};
if (controller._input) controller._input.start = startVoice;
if (controller._radio)
controller._radio.isActive = () => !textOnly && controller.isActive();
return {
controller,
capabilities: { costControls: true, pushToTalk: true },
start: (settings) => {
if (!settings?.textOnly) return startVoice(settings);
textOnly = true;
return chat.start();
},
getStartOptions: () => ({
pushToTalk: Boolean(controller.pushToTalkMode),
...(textOnly ? { textOnly: true } : {}),
}),
stop: (settings) => {
chat.stop({ ...settings, preserveStatus: true });
controller.stop(settings);
},
// Chat Stop: abort the reply in progress, keep the conversation.
cancelTurn: () => textOnly && chat.cancelTurn(),
sendText: (text) =>
textOnly ? chat.sendText(text) : controller.sendTextCommand(text),
sendMapEvent: (event) =>
textOnly ? chat.sendMapEvent(event) : controller.notifyMapEvent(event),
ignoreButtonClick: () => Boolean(controller.spaceKeyHeld),
bindControls() {
// Kept as the remover; a full stop releases it. The cost readout and
// tier toggle are worded again in a new locale.
const offTier = controller.ui.on('tier', () =>
controller.toggleVoiceTier(),
);
const offLocale = controller.ui.on('locale', () =>
controller.syncCostUi(),
);
controller.tierHandler = () => {
offTier();
offLocale();
};
controller.syncCostUi();
controller.bindPushToTalkShortcut();
},
};
}