Surface (requirement 001 phase 2): navigation Stream (Inbox, Regeln) / Agents / Artifacts with keys 1-3 and hash routes (#graph and #tree redirect), header with title, command palette and settings only, server-side badges (unsnoozed inbox, beats within 900 s, open jobs), a Mayday banner with "aufheben", four stream chips with agent:/art:/seit: search, Filter and time menus, the inbox in main, an agents toolbar (Funk an alle with Newsletter, Broadcast, Pan-Pan, Security, Mayday; Priorität; Tag/Nacht), Post or Call in the agent panel, Ambiente in the settings and read-aloud over the seven classes with Mayday locked. Rename (decision 9): hub/ is orchestrator/, the package kvb_orchestrator, the unit kvb-orchestrator-runner.service, scripts/orchestrator.sh, environment KVB_ORCHESTRATOR_*, make targets orchestrator-*, the MCP server, image and compose project kvb-orchestrator, the guard header X-Kvb-Orchestrator and the message marker [kvb-orchestrator msg <id>]. install runs migrate first: it stops the old container, removes its image and code, moves state, approvals and pinned keys, swaps the MCP registration, the PermissionRequest hook and the runner unit, and changes nothing on a second run (scratch-HOME test with stub docker, claude and systemctl). Saved views fall back to the old localStorage key once. MEDUSA acceptances carried to the renamed paths: 82 rows whose lines are unchanged (reason prefixed "renamed from <old path>, line unchanged"), and 7 rows whose text changed only in the product name, the package name, a temp prefix or a new class argument, each upheld by one kvb-think-criticize skeptic (approval.py:60, messaging.py:53, server.py:56, tests/hub_support.py:64, passkey.py:205, page-agent.js:75, language.py:46). Cost 101 %: the longer name adds 15 tokens of skill text; the operator approved it with the commit. 🎯 Fix: 92 % 💥 Break: 4 % 💸 Cost: 101 % ⏱️ Time: – 🛡️ Security: 100 % 💰 Value: ? 🏆 Score: 87 🚦 Gate: ⚠️ cost 101 % > 100: ask the operator before the commit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
174 lines
5.9 KiB
JavaScript
174 lines
5.9 KiB
JavaScript
function loudness(kind) {
|
|
return Voice.loudness(kind, settings);
|
|
}
|
|
|
|
function speechFailed(lines) {
|
|
if (Date.now() - speech.warned > SPEECH_QUIET) {
|
|
speech.warned = Date.now();
|
|
toast("Funk vorlesen fehlgeschlagen", lines, false);
|
|
}
|
|
}
|
|
|
|
function say(item) {
|
|
speech.pending = Voice.enqueue(speech.pending, item, SPEECH_QUEUE);
|
|
pump();
|
|
}
|
|
|
|
async function pump() {
|
|
if (speech.busy || !speech.pending.length) {
|
|
return;
|
|
}
|
|
const sound = context();
|
|
if (!sound) {
|
|
speech.pending = [];
|
|
return;
|
|
}
|
|
const [item, ...rest] = speech.pending;
|
|
speech.pending = rest;
|
|
speech.busy = true;
|
|
const next = () => {
|
|
speech.busy = false;
|
|
pump();
|
|
};
|
|
try {
|
|
const response = await fetch("/api/tts", {method: "POST", headers: {"X-Kvb-Orchestrator": "1", "Content-Type": "application/json"}, body: JSON.stringify({text: item.text, voice: item.voice}), cache: "no-store"});
|
|
if (!response.ok) {
|
|
throw new Error(`${response.status} ${(await response.text()).trim()}`);
|
|
}
|
|
const buffer = await sound.decodeAudioData(await response.arrayBuffer());
|
|
const source = sound.createBufferSource();
|
|
const gain = sound.createGain();
|
|
gain.gain.value = loudness(item.tone);
|
|
source.buffer = buffer;
|
|
source.connect(gain).connect(sound.destination);
|
|
source.addEventListener("ended", next, {once: true});
|
|
duck(buffer.duration);
|
|
source.start();
|
|
} catch (error) {
|
|
speechFailed([String(error.message || error)]);
|
|
next();
|
|
}
|
|
}
|
|
|
|
function speakRows(rows) {
|
|
if (!settings.speech.on || !state.speech.tts) {
|
|
return;
|
|
}
|
|
for (const row of rows.filter((entry) => entry.ts >= state.now - SPEECH_FRESH && Voice.speakable(entry, settings.speech))) {
|
|
say({text: row.speech, voice: row.voice, tone: Voice.toneOf(row, HUMAN), cls: row.class});
|
|
}
|
|
}
|
|
|
|
function micButton(field) {
|
|
const button = h("button", {type: "button", class: "btn small ghost icon-btn mic", "aria-pressed": "false", "aria-label": "Spracheingabe: gedrückt halten und sprechen", title: "Gedrückt halten und sprechen; der Text landet im Feld und wird nicht gesendet"}, "🎙");
|
|
const reason = !window.isSecureContext || !navigator.mediaDevices
|
|
? "Das Mikrofon braucht einen sicheren Kontext: öffne den Hub über 127.0.0.1 oder localhost"
|
|
: !window.MediaRecorder ? "Dieser Browser kann nicht aufnehmen" : !state.speech.stt ? `Spracheingabe ist aus: ${state.speech.stt_off}` : "";
|
|
if (reason) {
|
|
button.disabled = true;
|
|
button.title = reason;
|
|
return button;
|
|
}
|
|
const press = (event) => {
|
|
event.preventDefault();
|
|
record(field, button);
|
|
};
|
|
button.addEventListener("pointerdown", press);
|
|
for (const name of ["pointerup", "pointerleave", "pointercancel"]) {
|
|
button.addEventListener(name, release);
|
|
}
|
|
button.addEventListener("keydown", (event) => {
|
|
if ((event.key === " " || event.key === "Enter") && !event.repeat) {
|
|
press(event);
|
|
}
|
|
});
|
|
button.addEventListener("keyup", (event) => {
|
|
if (event.key === " " || event.key === "Enter") {
|
|
event.preventDefault();
|
|
release();
|
|
}
|
|
});
|
|
return button;
|
|
}
|
|
|
|
async function record(field, button) {
|
|
if (mic.held || mic.recorder || mic.busy) {
|
|
return;
|
|
}
|
|
mic.held = true;
|
|
let media = null;
|
|
try {
|
|
media = await navigator.mediaDevices.getUserMedia({audio: {channelCount: 1, echoCancellation: true, noiseSuppression: true}});
|
|
} catch (error) {
|
|
mic.held = false;
|
|
toast("Mikrofon nicht verfügbar", [String(error.message || error)], false);
|
|
return;
|
|
}
|
|
if (!mic.held) {
|
|
media.getTracks().forEach((track) => track.stop());
|
|
return;
|
|
}
|
|
const recorder = new MediaRecorder(media);
|
|
const chunks = [];
|
|
recorder.addEventListener("dataavailable", (event) => {
|
|
if (event.data.size) {
|
|
chunks.push(event.data);
|
|
}
|
|
});
|
|
recorder.addEventListener("stop", () => {
|
|
media.getTracks().forEach((track) => track.stop());
|
|
mic.recorder = null;
|
|
button.setAttribute("aria-pressed", "false");
|
|
transcribe(new Blob(chunks, {type: recorder.mimeType}), field, button);
|
|
}, {once: true});
|
|
mic.recorder = recorder;
|
|
recorder.start();
|
|
button.setAttribute("aria-pressed", "true");
|
|
mic.timer = window.setTimeout(release, state.speech.seconds * 1000);
|
|
}
|
|
|
|
function release() {
|
|
mic.held = false;
|
|
window.clearTimeout(mic.timer);
|
|
if (mic.recorder && mic.recorder.state === "recording") {
|
|
mic.recorder.stop();
|
|
}
|
|
}
|
|
|
|
async function transcribe(blob, field, button) {
|
|
const sound = context();
|
|
if (!sound || !blob.size) {
|
|
return;
|
|
}
|
|
mic.busy = true;
|
|
button.disabled = true;
|
|
try {
|
|
const decoded = await sound.decodeAudioData(await blob.arrayBuffer());
|
|
const rate = state.speech.rate;
|
|
const length = Voice.frames(decoded.duration, rate, state.speech.seconds);
|
|
if (length < rate / 4) {
|
|
throw new Error("zu kurz: halte die Taste, solange du sprichst");
|
|
}
|
|
const offline = new OfflineAudioContext(1, length, rate);
|
|
const source = offline.createBufferSource();
|
|
source.buffer = decoded;
|
|
source.connect(offline.destination);
|
|
source.start();
|
|
const rendered = await offline.startRendering();
|
|
const result = await send("/api/stt", Voice.wav(rendered.getChannelData(0), rate), "audio/wav");
|
|
if (!result.ok || !result.data) {
|
|
throw new Error(`${result.status} ${result.text}`.trim());
|
|
}
|
|
if (result.data.text) {
|
|
field.value = [field.value.trim(), result.data.text].filter(Boolean).join(" ");
|
|
field.dispatchEvent(new Event("input", {bubbles: true}));
|
|
}
|
|
field.focus();
|
|
} catch (error) {
|
|
toast("Spracheingabe fehlgeschlagen", [String(error.message || error)], false);
|
|
} finally {
|
|
mic.busy = false;
|
|
button.disabled = false;
|
|
}
|
|
}
|