feat: the brain can change the box's speaker volume

"Speak up" and "too loud" now work: the reply tool takes louder, in
percentage points, and the button service nudges the speaker's softvol
before it speaks that reply, so the person hears the change at once.
The box keeps the level between 10% and 80% (body/mixer.py).

No new port or key: the volume changes only with a reply, in a
conversation someone is listening to.

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-12-03 16:44:54 -06:00
1 parent cf503ac247
commit 5191ee9931
11 files changed
+146 -21

No files matched your search

+11 -4
View File
@@ -10,11 +10,14 @@ import { RpcTarget } from 'capnweb';
/** Spoken questions are short. */
export const MAX_QUESTION_CHARS = 2000;
/** The most a reply can change the box's speaker volume, in percentage points; the box keeps its own bounds. */
export const MAX_LOUDER = 30;
/** A conversation id: the box makes them up, so keep them tame. */
const CONVERSATION = /^[A-Za-z0-9-]{1,40}$/;
/**
* @typedef {{ text: string, end: boolean }} Answer
* @typedef {{ text: string, end: boolean, louder?: number }} Answer
* @typedef {{ conversation?: string, onSay?: (text: string) => unknown }} AskOpts
* @typedef {{ resolve: (a: Answer) => void, reject: (e: Error) => void, onSay?: AskOpts['onSay'] }} Pending
*/
@@ -74,13 +77,17 @@ export class Channel {
/**
* The brain's reply tool. Returns what to tell the brain.
* @param {string} chat_id @param {string} text @param {boolean} [end] the conversation is over
* @param {number} [louder] change the speaker volume this many percentage points first; negative is softer
*/
reply(chat_id, text, end = false) {
reply(chat_id, text, end = false, louder = undefined) {
const p = this.#pending.get(chat_id);
if (!p) return `no one is waiting on chat_id ${chat_id}: it timed out or was already answered`;
const volumeOk = louder === undefined || (Number.isInteger(louder) && Math.abs(louder) <= MAX_LOUDER);
this.#pending.delete(chat_id);
p.resolve({ text: String(text), end: end === true });
return end === true ? 'spoken; the conversation is over' : 'spoken';
p.resolve({ text: String(text), end: end === true, ...(volumeOk && louder ? { louder } : {}) });
const outcome = end === true ? 'spoken; the conversation is over' : 'spoken';
if (!volumeOk) return `${outcome}, but the volume is unchanged: louder must be a whole number from -${MAX_LOUDER} to ${MAX_LOUDER}`;
return louder ? `${outcome}, ${louder > 0 ? 'louder' : 'softer'} by ${Math.abs(louder)} points (within the box's bounds)` : outcome;
}
/** The box says a conversation is over: by goodbye, silence, or a press. @param {string} conversation @param {string} user */