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:
@@ -10,6 +10,8 @@ import type { TurnResult } from '@hermeven/contracts';
|
||||
*/
|
||||
export type Phase =
|
||||
| 'unpaired'
|
||||
/** The opening menu: choose a mode. Nothing records and nothing is in flight. */
|
||||
| 'menu'
|
||||
| 'ready'
|
||||
| 'listening'
|
||||
| 'transcribing'
|
||||
@@ -35,8 +37,24 @@ export interface Agent {
|
||||
name: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* How the app is being used. Both modes talk to the same agents through the same path; the
|
||||
* only difference is whether the microphone listens for a name while at rest.
|
||||
* - agents: the microphone opens on a tap, and the app leaves the glasses when idle.
|
||||
* - handsfree: the microphone is open at rest, and the app stays until closed.
|
||||
*/
|
||||
export type Mode = 'agents' | 'handsfree';
|
||||
|
||||
export const MODE_LABEL: Record<Mode, string> = { handsfree: 'Hands free', agents: 'Agents' };
|
||||
|
||||
export interface AppState {
|
||||
phase: Phase;
|
||||
/** The app opens on a menu, and double tap at Ready goes back to it (instead of exiting). */
|
||||
menu: boolean;
|
||||
menuIndex: number;
|
||||
mode: Mode;
|
||||
/** Hands free can be offered: this build has it, and nothing has said the bridge cannot do it. */
|
||||
handsFree: boolean;
|
||||
/**
|
||||
* The agents the bridge offers, default first. Empty when there is only one (or the bridge
|
||||
* predates agent selection): nothing about agents is then shown or sent.
|
||||
@@ -58,6 +76,15 @@ export interface AppState {
|
||||
requestId: string | null;
|
||||
captureStartedAt: number | null;
|
||||
captureMaxSeconds: number;
|
||||
/** The recording was started by saying an agent's name: it sends itself when the speaker stops. */
|
||||
captureAuto: boolean;
|
||||
/**
|
||||
* The microphone is open at rest, listening for an agent's name. Reported by the controller
|
||||
* from what the microphone actually did, so the HUD's indicator is never a guess.
|
||||
*/
|
||||
wakeListening: boolean;
|
||||
/** The question as it was heard, when it was spoken after a name. Shown while the agent works. */
|
||||
heard: string | null;
|
||||
pages: string[];
|
||||
pageIndex: number;
|
||||
/** The answer is a partial one (agent stopped short). Shown on the HUD. */
|
||||
@@ -77,6 +104,10 @@ export interface AppState {
|
||||
|
||||
export const initialState: AppState = {
|
||||
phase: 'unpaired',
|
||||
menu: false,
|
||||
menuIndex: 0,
|
||||
mode: 'agents',
|
||||
handsFree: false,
|
||||
agents: [],
|
||||
agentId: null,
|
||||
generation: 0,
|
||||
@@ -86,6 +117,9 @@ export const initialState: AppState = {
|
||||
requestId: null,
|
||||
captureStartedAt: null,
|
||||
captureMaxSeconds: 30,
|
||||
captureAuto: false,
|
||||
wakeListening: false,
|
||||
heard: null,
|
||||
pages: [],
|
||||
pageIndex: 0,
|
||||
partial: false,
|
||||
@@ -106,7 +140,12 @@ export type AppEvent =
|
||||
storageFault?: boolean;
|
||||
agents?: Agent[];
|
||||
agentId?: string | null;
|
||||
/** Open on the menu. Without it the app opens at Ready, hands free if that is available. */
|
||||
menu?: boolean;
|
||||
handsFree?: boolean;
|
||||
}
|
||||
/** Hands free turned out not to be possible (the bridge cannot do it): fall back to Agents. */
|
||||
| { type: 'handsfree_lost' }
|
||||
/** The user picked another agent (a swipe at Ready). `conversationId` is that agent's own, if it has one. */
|
||||
| { type: 'agent_selected'; agentId: string; conversationId: string | null }
|
||||
/**
|
||||
@@ -116,6 +155,16 @@ export type AppEvent =
|
||||
*/
|
||||
| { type: 'agent_reconciled'; agentId: string; conversationId: string | null }
|
||||
| { type: 'unpaired' }
|
||||
/**
|
||||
* An agent was addressed by name and the question followed in the same breath ("Wendy, what
|
||||
* time is it"). `agentId` and `conversationId` are that agent's; null agent = no choice offered.
|
||||
*/
|
||||
| { type: 'wake_text'; freshId: string; agentId: string | null; conversationId: string | null; text: string }
|
||||
/** Only the name was said: record what follows and send it when the speaker stops. */
|
||||
| { type: 'wake_listen'; freshId: string; agentId: string | null; conversationId: string | null }
|
||||
/** A recording started by name heard nothing: back to rest, nothing sent. */
|
||||
| { type: 'capture_abandoned'; generation: number }
|
||||
| { type: 'wake_status'; listening: boolean }
|
||||
/** Semantic actions. `freshId` is a new UUID supplied by the caller in case a turn starts. */
|
||||
| { type: 'activate'; freshId: string }
|
||||
| { type: 'back' }
|
||||
@@ -140,7 +189,7 @@ export type AppEvent =
|
||||
| { type: 'app_exit' };
|
||||
|
||||
export type Effect =
|
||||
| { type: 'start_capture'; generation: number }
|
||||
| { type: 'start_capture'; generation: number; auto?: boolean }
|
||||
| { type: 'stop_capture_and_submit'; generation: number; requestId: string }
|
||||
| { type: 'discard_capture' }
|
||||
| { type: 'submit_text'; generation: number; requestId: string; text: string }
|
||||
@@ -158,6 +207,11 @@ export interface Step {
|
||||
const IDLE: ReadonlySet<Phase> = new Set(['ready', 'answer', 'error', 'cancelled']);
|
||||
const IN_FLIGHT: ReadonlySet<Phase> = new Set(['transcribing', 'thinking', 'approval']);
|
||||
|
||||
/** The menu's entries, in order. Hands free comes first whenever it can be offered. */
|
||||
export function menuItems(state: Pick<AppState, 'handsFree'>): Mode[] {
|
||||
return state.handsFree ? ['handsfree', 'agents'] : ['agents'];
|
||||
}
|
||||
|
||||
/** The agent questions go to now, or undefined when the bridge offers no choice. */
|
||||
export function currentAgent(state: AppState): Agent | undefined {
|
||||
if (state.agents.length === 0) return undefined;
|
||||
@@ -169,6 +223,8 @@ function clearTurn(state: AppState): AppState {
|
||||
...state,
|
||||
requestId: null,
|
||||
captureStartedAt: null,
|
||||
captureAuto: false,
|
||||
heard: null,
|
||||
pages: [],
|
||||
pageIndex: 0,
|
||||
partial: false,
|
||||
@@ -183,6 +239,24 @@ function same(state: AppState): Step {
|
||||
return { state, effects: [] };
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn to the agent that was addressed by name, with its own conversation. Null when that
|
||||
* agent is not one on offer. A change of agent or conversation starts a new conversation epoch,
|
||||
* so a conversation still being created for the previous one cannot land here.
|
||||
*/
|
||||
function address(state: AppState, agentId: string | null, conversationId: string | null): AppState | null {
|
||||
if (state.agents.length > 0 && agentId !== null && !state.agents.some((a) => a.id === agentId)) return null;
|
||||
const sameAgent = state.agents.length === 0 || agentId === null || agentId === currentAgent(state)?.id;
|
||||
if (sameAgent && conversationId === state.conversationId) return state;
|
||||
return {
|
||||
...state,
|
||||
agentId: sameAgent ? state.agentId : agentId,
|
||||
conversationId,
|
||||
conversationEpoch: state.conversationEpoch + 1,
|
||||
creatingConversation: false,
|
||||
};
|
||||
}
|
||||
|
||||
/** Abandon whatever is in progress. The generation bump is what silences late results. */
|
||||
function abandon(state: AppState): Step {
|
||||
const effects: Effect[] = [];
|
||||
@@ -209,6 +283,10 @@ export function reduce(state: AppState, event: AppEvent): Step {
|
||||
storageFault: event.storageFault === true,
|
||||
agents: event.agents ?? [],
|
||||
agentId: event.agentId ?? null,
|
||||
menu: event.menu === true,
|
||||
handsFree: event.handsFree === true,
|
||||
// With a menu, hands free is something the user chooses. Without one it is simply on.
|
||||
mode: event.menu !== true && event.handsFree === true ? 'handsfree' : 'agents',
|
||||
};
|
||||
if (!event.paired) return same({ ...base, phase: 'unpaired' });
|
||||
if (event.resumeRequestId) {
|
||||
@@ -219,7 +297,20 @@ export function reduce(state: AppState, event: AppEvent): Step {
|
||||
effects: [{ type: 'poll', generation: base.generation, requestId: event.resumeRequestId }],
|
||||
};
|
||||
}
|
||||
return same({ ...base, phase: 'ready' });
|
||||
return same({ ...base, phase: base.menu ? 'menu' : 'ready' });
|
||||
}
|
||||
|
||||
case 'handsfree_lost': {
|
||||
if (!state.handsFree) return same(state);
|
||||
const wasOn = state.mode === 'handsfree';
|
||||
return same({
|
||||
...state,
|
||||
handsFree: false,
|
||||
mode: 'agents',
|
||||
menuIndex: 0,
|
||||
wakeListening: false,
|
||||
notice: wasOn && state.phase === 'ready' ? 'Hands free is not available' : state.notice,
|
||||
});
|
||||
}
|
||||
|
||||
case 'agent_selected': {
|
||||
@@ -264,7 +355,44 @@ export function reduce(state: AppState, event: AppEvent): Step {
|
||||
};
|
||||
}
|
||||
|
||||
case 'wake_text': {
|
||||
if (!IDLE.has(state.phase)) return same(state);
|
||||
const addressed = address(state, event.agentId, event.conversationId);
|
||||
if (!addressed) return same(state);
|
||||
const generation = state.generation + 1;
|
||||
return {
|
||||
state: { ...clearTurn(addressed), phase: 'thinking', generation, requestId: event.freshId, heard: event.text },
|
||||
effects: [{ type: 'submit_text', generation, requestId: event.freshId, text: event.text }],
|
||||
};
|
||||
}
|
||||
|
||||
case 'wake_listen': {
|
||||
if (!IDLE.has(state.phase)) return same(state);
|
||||
const addressed = address(state, event.agentId, event.conversationId);
|
||||
if (!addressed) return same(state);
|
||||
const generation = state.generation + 1;
|
||||
return {
|
||||
state: { ...clearTurn(addressed), phase: 'listening', generation, requestId: event.freshId, captureAuto: true },
|
||||
effects: [{ type: 'start_capture', generation, auto: true }],
|
||||
};
|
||||
}
|
||||
|
||||
case 'capture_abandoned': {
|
||||
if (event.generation !== state.generation || state.phase !== 'listening') return same(state);
|
||||
return {
|
||||
state: { ...clearTurn(state), phase: 'ready', generation: state.generation + 1 },
|
||||
effects: [{ type: 'discard_capture' }],
|
||||
};
|
||||
}
|
||||
|
||||
case 'wake_status':
|
||||
return same(event.listening === state.wakeListening ? state : { ...state, wakeListening: event.listening });
|
||||
|
||||
case 'activate': {
|
||||
if (state.phase === 'menu') {
|
||||
const mode = menuItems(state)[state.menuIndex] ?? 'agents';
|
||||
return same({ ...clearTurn(state), phase: 'ready', mode, generation: state.generation + 1 });
|
||||
}
|
||||
if (IDLE.has(state.phase)) {
|
||||
const generation = state.generation + 1;
|
||||
return {
|
||||
@@ -297,7 +425,8 @@ export function reduce(state: AppState, event: AppEvent): Step {
|
||||
}
|
||||
|
||||
case 'submit_text': {
|
||||
if (!IDLE.has(state.phase)) return same(state);
|
||||
// Typed on the phone. Also accepted on the menu: it does not need a mode.
|
||||
if (!IDLE.has(state.phase) && state.phase !== 'menu') return same(state);
|
||||
const generation = state.generation + 1;
|
||||
return {
|
||||
state: { ...clearTurn(state), phase: 'thinking', generation, requestId: event.freshId },
|
||||
@@ -306,7 +435,11 @@ export function reduce(state: AppState, event: AppEvent): Step {
|
||||
}
|
||||
|
||||
case 'back': {
|
||||
if (state.phase === 'ready' || state.phase === 'unpaired') return { state, effects: [{ type: 'exit_dialog' }] };
|
||||
if (state.phase === 'ready' && state.menu) {
|
||||
// Leaving a mode. Hands free ends here: the microphone closes with it.
|
||||
return same({ ...clearTurn(state), phase: 'menu', mode: 'agents', menuIndex: 0, generation: state.generation + 1 });
|
||||
}
|
||||
if (state.phase === 'ready' || state.phase === 'unpaired' || state.phase === 'menu') return { state, effects: [{ type: 'exit_dialog' }] };
|
||||
if (state.phase === 'listening' || IN_FLIGHT.has(state.phase) || state.phase === 'disconnected') return abandon(state);
|
||||
// answer / error / cancelled: step back to the root page.
|
||||
return same({ ...clearTurn(state), phase: 'ready' });
|
||||
@@ -319,8 +452,12 @@ export function reduce(state: AppState, event: AppEvent): Step {
|
||||
|
||||
case 'next_page':
|
||||
case 'prev_page': {
|
||||
if (state.phase !== 'answer') return same(state);
|
||||
const delta = event.type === 'next_page' ? 1 : -1;
|
||||
if (state.phase === 'menu') {
|
||||
const menuIndex = Math.min(menuItems(state).length - 1, Math.max(0, state.menuIndex + delta));
|
||||
return same(menuIndex === state.menuIndex ? state : { ...state, menuIndex });
|
||||
}
|
||||
if (state.phase !== 'answer') return same(state);
|
||||
const pageIndex = Math.min(state.pages.length - 1, Math.max(0, state.pageIndex + delta));
|
||||
return same(pageIndex === state.pageIndex ? state : { ...state, pageIndex });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user