mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 03:32:19 +00:00
* fix(voice): a selection steps a docked assistant panel down so Context shows; the panel keeps the last reply A voice or chat action that selects an entity (select_nearest_aircraft, track_entity) now minimizes a voice or chat panel docked in the right rail's lane, so the rail and its Context panel show as after a click. The voice card inside the panel no longer hides 14 s after its last update: the reply stays until the next turn, Stop or a dismissal. The floating card keeps its idle deadline. * fix(voice): a voice or chat selection opens its card in the Context panel A successful select_nearest_aircraft or track_entity now selects the entity in the Context panel's entity card store the same way a click does, so the panel opens on its details; the docked assistant panel then steps down so it shows. track_entity reports the id it tracked. Nothing opens in Cockpit, where Context is hidden. * fix(voice): a slow selection never replaces a card picked since; Cockpit is read from its own state The entity card store counts selections and clears. A voice or chat selection notes that count when it is asked and opens its card only if no other card was picked or cleared before it finished. Whether Cockpit is running is read from the style manager's Cockpit state when it has one. * Add the changelog entry * fix(voice): the app hands voice its Context card opener The voice package no longer imports the entity card store. The app builds the opener (createContextCardOpener) and passes it to the voice commands as contextCard, which keeps the voice package inside its own boundary.
154 lines
4.7 KiB
JavaScript
154 lines
4.7 KiB
JavaScript
import {
|
|
initialVoiceCardState,
|
|
reduceVoiceCard,
|
|
voiceCardView,
|
|
} from './voiceCardPresentation.js';
|
|
|
|
/** Hide an idle card this long after its last update. */
|
|
const VOICE_CARD_IDLE_MS = 14000;
|
|
|
|
/**
|
|
* Voice card controls. The card is part of the voice control (`control.js`),
|
|
* beside its help and error trays, so Clean-UI and recording mode hide it with
|
|
* the control. Receives provider-neutral session events through `handle` and
|
|
* annotation outline outcomes through `outline`, and presents the card's view
|
|
* on the control; owns only its listener and idle timer. Captions update
|
|
* silently; the polite live region carries final replies and result titles
|
|
* only.
|
|
*/
|
|
export class VoiceCardControls {
|
|
/**
|
|
* @param {object} options
|
|
* @param {object} options.ui The voice control presenter.
|
|
* @param {number|null} [options.idleMs] How long an idle card stays shown;
|
|
* null keeps it until the next turn, Stop or a dismissal.
|
|
* @param {Function} [options.setTimer]
|
|
* @param {Function} [options.clearTimer]
|
|
*/
|
|
constructor({
|
|
ui,
|
|
idleMs = VOICE_CARD_IDLE_MS,
|
|
setTimer = (fn, ms) => setTimeout(fn, ms),
|
|
clearTimer = (id) => clearTimeout(id),
|
|
onRender,
|
|
}) {
|
|
Object.assign(this, { ui, idleMs, setTimer, clearTimer, onRender });
|
|
this.state = initialVoiceCardState();
|
|
this.enabled = true;
|
|
this.presented = true;
|
|
this.announcementRevision = 0;
|
|
this.consumedPresentationAnnouncement = -1;
|
|
this.hideTimer = null;
|
|
this.destroyed = false;
|
|
if (!ui) return;
|
|
// The card's labels are worded again in a new locale.
|
|
this.offLocale = ui.on('locale', () => {
|
|
if (!this.destroyed) this.render();
|
|
});
|
|
this.offDismiss = ui.on('card-dismiss', () =>
|
|
this.handle({ type: 'dismiss' }),
|
|
);
|
|
this.render();
|
|
}
|
|
|
|
/** Apply one session event (or `outline`/`dismiss`). */
|
|
handle(event) {
|
|
if (this.destroyed || !this.ui) return;
|
|
const next = reduceVoiceCard(this.state, event);
|
|
if (next === this.state) return;
|
|
if (
|
|
next.announce !== this.state.announce ||
|
|
(next.announce &&
|
|
((event.type === 'transcript' &&
|
|
event.role === 'assistant' &&
|
|
event.final) ||
|
|
(event.type === 'action-result' &&
|
|
next.result !== this.state.result) ||
|
|
(event.type === 'pointer' &&
|
|
next.pointer &&
|
|
next.pointer !== this.state.pointer)))
|
|
)
|
|
this.announcementRevision++;
|
|
this.state = next;
|
|
this.render();
|
|
if (this.state.visible) this.scheduleIdle();
|
|
else this.cancelIdle();
|
|
}
|
|
|
|
/** A local submission allows future output after dismissal; keep its content. */
|
|
rearm() {
|
|
if (this.destroyed || !this.ui) return;
|
|
this.state = { ...this.state, dismissed: false };
|
|
}
|
|
|
|
/** An annotation outline resolved or failed after its tool result. */
|
|
outline(event) {
|
|
this.handle({ type: 'outline', id: event?.id, status: event?.status });
|
|
}
|
|
|
|
/** Change presentation only; session events and the idle deadline continue. */
|
|
setEnabled(enabled) {
|
|
if (this.destroyed || !this.ui) return;
|
|
this.enabled = Boolean(enabled);
|
|
this.render();
|
|
}
|
|
|
|
/** View selection changes presentation without changing the saved preference. */
|
|
setPresented(presented) {
|
|
if (this.destroyed || !this.ui || this.presented === presented) return;
|
|
if (!presented)
|
|
this.consumedPresentationAnnouncement = this.announcementRevision;
|
|
this.presented = presented;
|
|
this.render();
|
|
}
|
|
|
|
scheduleIdle() {
|
|
this.cancelIdle();
|
|
if (this.idleMs === null) return;
|
|
this.hideTimer = this.setTimer(() => {
|
|
this.hideTimer = null;
|
|
if (this.destroyed) return;
|
|
// Keep the card while the pointer or focus is inside it.
|
|
if (this.ui.element('card')?.matches?.(':hover, :focus-within')) {
|
|
this.scheduleIdle();
|
|
return;
|
|
}
|
|
this.handle({ type: 'idle' });
|
|
}, this.idleMs);
|
|
}
|
|
|
|
cancelIdle() {
|
|
if (this.hideTimer === null) return;
|
|
this.clearTimer(this.hideTimer);
|
|
this.hideTimer = null;
|
|
}
|
|
|
|
render() {
|
|
this.ui.replace('card', this.snapshot());
|
|
this.onRender?.();
|
|
}
|
|
|
|
/** Test/diagnostic view of what the card shows. */
|
|
snapshot() {
|
|
const view = voiceCardView(this.state);
|
|
return this.enabled && this.presented
|
|
? {
|
|
...view,
|
|
announce:
|
|
this.consumedPresentationAnnouncement === this.announcementRevision
|
|
? ''
|
|
: view.announce,
|
|
}
|
|
: { ...view, visible: false, announce: '' };
|
|
}
|
|
|
|
/** Idempotent: removes the listener and the idle timer; the control stays. */
|
|
destroy() {
|
|
if (this.destroyed) return;
|
|
this.destroyed = true;
|
|
this.cancelIdle();
|
|
this.offDismiss?.();
|
|
this.offLocale?.();
|
|
}
|
|
}
|