Opening menu and hands-free mode: call an agent by name (0.3.0)
The app now opens on a menu, which is the root page: "Hands free" first, "Agents" second. Agents is the 0.2.0 app unchanged. Hands free is the same agents, conversations and question path with one flag set: the microphone listens while the app is at rest and the app does not leave by itself. The mode is never remembered; every launch starts at the menu with the microphone closed, and double tap at Ready returns to the menu and closes it. Client: a loudness-only speech segmenter (core/vad.ts) cuts the stream into utterances; each goes to the bridge for a wake check. "Wendy, <q>" becomes a text turn to Wendy, with what was heard shown while she works. A name alone starts a recording that sends itself when the speaker stops. The status line starts with a dot for exactly as long as the microphone is open at rest. In wake mode every microphone open and close goes through one serialised reconciler; without the option the old path is untouched. Bridge: POST /v1/wake transcribes one utterance in memory and reports whether it BEGAN with an agent's name (first word of the display name, or an alias from HERMEVEN_AGENT_<ID>_WAKE). Exact match only; a near miss is reported as one word and never acted on. Creates no turn, stores nothing, returns and logs nothing that was not addressed to an agent. One check at a time per device, HERMEVEN_WAKE_CHECKS_PER_MINUTE (30). Docs: decision 0004, bridge API, security gaps 3c/3d, device plan D. The manifest's microphone description changed. Not reviewed, not deployed, not uploaded, not device-tested. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { existsSync, readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { AUDIO_FORMAT, DEFAULT_LIMITS } from '@hermeven/contracts';
|
||||
import { validateManifest, type ModelManifest } from './stt/modelStore.mjs';
|
||||
import { wakeWordsFor } from './wake.ts';
|
||||
|
||||
export interface AgentConfig {
|
||||
/** `default` for the main agent; otherwise the id from HERMEVEN_AGENTS. */
|
||||
@@ -10,6 +11,11 @@ export interface AgentConfig {
|
||||
name: string;
|
||||
baseUrl: string;
|
||||
apiKey: string;
|
||||
/**
|
||||
* What this agent answers to when spoken first ("Wendy, ..."): the first word of its name plus
|
||||
* any aliases, lower-case. Empty = it cannot be called by voice. Never sent to a client.
|
||||
*/
|
||||
wakeWords: string[];
|
||||
}
|
||||
|
||||
export const DEFAULT_AGENT_ID = 'default';
|
||||
@@ -65,6 +71,8 @@ export interface BridgeConfig {
|
||||
textMaxChars: number;
|
||||
audioMaxBytes: number;
|
||||
turnsPerMinute: number;
|
||||
/** Wake checks (speech heard while the app is open, tested for a leading agent name). */
|
||||
wakeChecksPerMinute: number;
|
||||
pairingAttemptsPerMinute: number;
|
||||
};
|
||||
credentials: {
|
||||
@@ -165,10 +173,32 @@ function agentName(key: string, raw: string | undefined, fallback: string): stri
|
||||
* profile its own key and refuses the default's, so every extra agent needs
|
||||
* HERMEVEN_AGENT_<ID>_API_KEY. Optional: HERMEVEN_AGENT_<ID>_PROFILE (default: the id) and
|
||||
* HERMEVEN_AGENT_<ID>_NAME (default: the id, capitalised).
|
||||
*
|
||||
* An agent is called by voice with the first word of its name. HERMEVEN_AGENT_<ID>_WAKE (for the
|
||||
* default agent, HERMEVEN_AGENT_WAKE) adds comma-separated aliases, for spellings the speech
|
||||
* model produces instead ("kody"). Two agents may not answer to the same word.
|
||||
*/
|
||||
function wakeWords(key: string, raw: string | undefined, name: string): string[] {
|
||||
const aliases = (raw ?? '')
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
if (aliases.length > 8 || aliases.some((a) => a.length > 32)) throw new ConfigError(`${key} takes at most 8 aliases of at most 32 characters`);
|
||||
return wakeWordsFor(name, aliases);
|
||||
}
|
||||
|
||||
function agentsFromEnv(env: NodeJS.ProcessEnv, baseUrl: string, defaultKey: string): AgentConfig[] {
|
||||
const defaultName = agentName('HERMEVEN_AGENT_NAME', env.HERMEVEN_AGENT_NAME, 'Agent');
|
||||
const agents: AgentConfig[] = [
|
||||
{ id: DEFAULT_AGENT_ID, name: agentName('HERMEVEN_AGENT_NAME', env.HERMEVEN_AGENT_NAME, 'Agent'), baseUrl, apiKey: defaultKey },
|
||||
{
|
||||
id: DEFAULT_AGENT_ID,
|
||||
name: defaultName,
|
||||
baseUrl,
|
||||
apiKey: defaultKey,
|
||||
// The placeholder name "Agent" is not something to listen for: the default agent answers
|
||||
// to a name only once the owner has given it one (or an alias).
|
||||
wakeWords: wakeWords('HERMEVEN_AGENT_WAKE', env.HERMEVEN_AGENT_WAKE, env.HERMEVEN_AGENT_NAME ? defaultName : ''),
|
||||
},
|
||||
];
|
||||
const ids = (env.HERMEVEN_AGENTS ?? '')
|
||||
.split(',')
|
||||
@@ -182,12 +212,16 @@ function agentsFromEnv(env: NodeJS.ProcessEnv, baseUrl: string, defaultKey: stri
|
||||
if (!apiKey) throw new ConfigError(`${prefix}_API_KEY is required: Hermes gives each profile its own API key`);
|
||||
const profile = env[`${prefix}_PROFILE`] || id;
|
||||
if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(profile)) throw new ConfigError(`${prefix}_PROFILE is not a valid profile name`);
|
||||
agents.push({
|
||||
id,
|
||||
name: agentName(`${prefix}_NAME`, env[`${prefix}_NAME`], id.charAt(0).toUpperCase() + id.slice(1)),
|
||||
baseUrl: `${baseUrl}/p/${profile}`,
|
||||
apiKey,
|
||||
});
|
||||
const name = agentName(`${prefix}_NAME`, env[`${prefix}_NAME`], id.charAt(0).toUpperCase() + id.slice(1));
|
||||
agents.push({ id, name, baseUrl: `${baseUrl}/p/${profile}`, apiKey, wakeWords: wakeWords(`${prefix}_WAKE`, env[`${prefix}_WAKE`], name) });
|
||||
}
|
||||
const claimed = new Map<string, string>();
|
||||
for (const agent of agents) {
|
||||
for (const word of agent.wakeWords) {
|
||||
const other = claimed.get(word);
|
||||
if (other) throw new ConfigError(`Agents "${other}" and "${agent.id}" would both answer to "${word}". Give one a different name or alias.`);
|
||||
claimed.set(word, agent.id);
|
||||
}
|
||||
}
|
||||
if (agents.length > 16) throw new ConfigError('HERMEVEN_AGENTS lists too many agents (at most 15 besides the default)');
|
||||
return agents;
|
||||
@@ -292,6 +326,7 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): BridgeConfig {
|
||||
// One extra second of headroom over the capture cap for frame alignment.
|
||||
audioMaxBytes: (captureMaxSeconds + 1) * AUDIO_FORMAT.bytesPerSecond,
|
||||
turnsPerMinute: int(env, 'HERMEVEN_TURNS_PER_MINUTE', 20, 1, 600),
|
||||
wakeChecksPerMinute: int(env, 'HERMEVEN_WAKE_CHECKS_PER_MINUTE', 30, 1, 600),
|
||||
pairingAttemptsPerMinute: int(env, 'HERMEVEN_PAIRING_ATTEMPTS_PER_MINUTE', 5, 1, 60),
|
||||
},
|
||||
credentials: {
|
||||
|
||||
Reference in New Issue
Block a user