evOo-local/apps/web/src/lib/oo-audio-bus.ts
cynarAI de95cf1b91
Fix red main: typecheck, lint, i18n, unit and web E2E (#222)
* Fix red main: typecheck, lint, i18n and stale unit tests

Direct pushes to main left typecheck, lint and 16 unit tests red.

- Typecheck: AskCard test uses the current ask block shape, the sandbox
  fault test calls the two-argument desktop writeFile, removing a queued
  message notifies with the thread's latest event seq, and the replay
  fixture only reads ref from steps that carry one.
- Lint: format and import order.
- i18n: transcript status labels were German source strings; they are
  English now with German translations, catalogs re-extracted, and the
  mobile "Failed to remove message" string is translated.
- Tests follow intended behavior changes: the time instruction now
  closes the system prompt, short chat turns start at low reasoning,
  owner-owned read-only files (git objects) pass the home check, and the
  desktop computer may read and write host files outside its home. The
  old desktop write-containment suite is replaced by a host file test.
- The composer task pill test mocks the Lingui macros like other tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TnT7eVHuaCzZKY5CnYzpr1

* Bump Expo patch releases so expo install --check passes

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TnT7eVHuaCzZKY5CnYzpr1

* Bring web E2E back in line with the new side panel

The side panel lost its computer tab, which left the full computer window
(take control, teach, release) unreachable from the web app. The browser
view now offers an "Open in full window" button, and opening the panel no
longer boots a stopped computer.

Also: the slash picker scrolls instead of growing under the header, user
skills come first in it, the agent overview hides an empty routines block,
the hover time hides again with collapsed details, and the light destructive
token meets contrast on the sidebar. E2E specs follow the new panel layout,
and the cursor and hover tests no longer race the UI.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TnT7eVHuaCzZKY5CnYzpr1

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-22 21:58:24 +02:00

107 lines
3.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Shared procedural SFX bus — −18…−12 LUFS ballpark, ducks under TTS/PTT.
* See packages/ui-web/MOTION-EVOO-CHARACTER.md
*/
type AudioContextCtor = new () => AudioContext;
/** Master output ~−12 LUFS for clear, warm procedural peaks. */
const SFX_MASTER_GAIN = 0.85;
/** Duck depth when voice lane active (TTS or mic wash). */
const SFX_DUCK_RATIO = 0.28;
const DUCK_RAMP_S = 0.065;
function audioContextCtor(): AudioContextCtor | undefined {
if (typeof AudioContext === "function") return AudioContext;
if (typeof window === "undefined") return undefined;
const host = window as Window & { webkitAudioContext?: AudioContextCtor };
return host.webkitAudioContext;
}
class OoAudioBus {
private ctx: AudioContext | null = null;
private sfxGain: GainNode | null = null;
private voiceHold = 0;
private unlockBound = false;
ensureContext(): AudioContext | null {
this.bindGestureUnlock();
if (this.ctx && this.ctx.state !== "closed") return this.ctx;
const Ctor = audioContextCtor();
if (!Ctor) return null;
try {
const ctx = new Ctor();
const master = ctx.createGain();
master.gain.value = 1;
master.connect(ctx.destination);
const sfxGain = ctx.createGain();
sfxGain.gain.value = SFX_MASTER_GAIN;
sfxGain.connect(master);
this.ctx = ctx;
this.sfxGain = sfxGain;
return ctx;
} catch {
return null;
}
}
/** Unlocks Web Audio on the user's first click, key, or tap so async SSE events can play audio. */
bindGestureUnlock(): void {
if (
this.unlockBound ||
typeof window === "undefined" ||
typeof window.addEventListener !== "function"
) {
return;
}
this.unlockBound = true;
const unlock = () => {
const ctx = this.ensureContext();
if (ctx && ctx.state === "suspended") {
void ctx.resume().catch(() => undefined);
}
if (typeof window !== "undefined" && "speechSynthesis" in window) {
try {
window.speechSynthesis.getVoices?.();
} catch {
// Ignore voice preload errors.
}
}
};
window.addEventListener("pointerdown", unlock, { capture: true, passive: true });
window.addEventListener("keydown", unlock, { capture: true, passive: true });
window.addEventListener("touchstart", unlock, { capture: true, passive: true });
}
/** Route for oo-sound / oo-vocals / oo-voice-mark oscillators. */
sfxDestination(ctx: AudioContext): AudioNode {
if (ctx !== this.ctx) {
const master = ctx.createGain();
master.gain.value = SFX_MASTER_GAIN;
master.connect(ctx.destination);
return master;
}
return this.sfxGain ?? ctx.destination;
}
/** TTS playback or PTT/listening — duck SFX so vocals don't fight the wash. */
setVoiceLaneActive(active: boolean) {
const ctx = this.ensureContext();
if (!ctx || !this.sfxGain) return;
this.voiceHold = Math.max(0, this.voiceHold + (active ? 1 : -1));
const t = ctx.currentTime;
const target = this.voiceHold > 0 ? SFX_MASTER_GAIN * SFX_DUCK_RATIO : SFX_MASTER_GAIN;
this.sfxGain.gain.cancelScheduledValues(t);
this.sfxGain.gain.setValueAtTime(this.sfxGain.gain.value, t);
this.sfxGain.gain.linearRampToValueAtTime(target, t + DUCK_RAMP_S);
}
/** Test helper — reset duck state. */
resetVoiceHoldForTests() {
this.voiceHold = 0;
if (this.sfxGain) this.sfxGain.gain.value = SFX_MASTER_GAIN;
}
}
export const ooAudioBus = new OoAudioBus();