First vertical slice: Even client, bridge, contract v1, tests, docs
Client (apps/even-client): pure interaction reducer with generation-based stale-result rejection, HUD renderer, measured pagination, Even Hub SDK 0.0.16 adapter, bridge HTTP client, phone pairing/status/diagnostics page. Bridge (services/bridge): device pairing and revocable expiring credentials, turn engine with idempotent submit, cancel, deadlines and restart recovery, Hermes Runs API adapter, OpenAI-compatible STT adapter, operator CLI. Contract (packages/contracts): versioned schemas, types and error codes. Tests: 122 unit/integration (fakes), 6 simulator scenarios (Even Hub simulator 0.9.5), 9 scenarios against a real Hermes v0.23.1 gateway with a stub model. No real STT, real model or physical device has been exercised; see docs/test-evidence.md and docs/device-test-plan.md. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,171 @@
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
--bg: #f6f6f4;
|
||||
--surface: #ffffff;
|
||||
--text: #1c1c1a;
|
||||
--muted: #62625c;
|
||||
--line: #d9d9d3;
|
||||
--accent: #1f5fbf;
|
||||
--danger: #b3261e;
|
||||
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg: #131312;
|
||||
--surface: #1e1e1c;
|
||||
--text: #ececE6;
|
||||
--muted: #a3a39b;
|
||||
--line: #3a3a36;
|
||||
--accent: #8ab4f8;
|
||||
--danger: #f2b8b5;
|
||||
}
|
||||
}
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
line-height: 1.45;
|
||||
overscroll-behavior: none;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
#app,
|
||||
#preview {
|
||||
max-width: 40rem;
|
||||
margin: 0 auto;
|
||||
padding: 0 16px 16px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.4rem;
|
||||
margin: 20px 0 8px;
|
||||
}
|
||||
h2 {
|
||||
font-size: 1.05rem;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
h3 {
|
||||
font-size: 0.85rem;
|
||||
margin: 12px 0 2px;
|
||||
color: var(--muted);
|
||||
font-weight: 600;
|
||||
}
|
||||
section,
|
||||
details {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 10px;
|
||||
padding: 14px;
|
||||
margin: 12px 0;
|
||||
}
|
||||
label {
|
||||
display: block;
|
||||
font-size: 0.85rem;
|
||||
color: var(--muted);
|
||||
margin: 10px 0;
|
||||
}
|
||||
input,
|
||||
textarea {
|
||||
display: block;
|
||||
width: 100%;
|
||||
margin-top: 4px;
|
||||
padding: 10px;
|
||||
font: inherit;
|
||||
color: var(--text);
|
||||
background: var(--bg);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
}
|
||||
button {
|
||||
font: inherit;
|
||||
font-weight: 600;
|
||||
min-height: 44px;
|
||||
padding: 8px 16px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--accent);
|
||||
background: var(--accent);
|
||||
color: var(--bg);
|
||||
}
|
||||
button.secondary {
|
||||
background: transparent;
|
||||
color: var(--accent);
|
||||
}
|
||||
button.danger {
|
||||
background: transparent;
|
||||
border-color: var(--danger);
|
||||
color: var(--danger);
|
||||
}
|
||||
button:disabled {
|
||||
opacity: 0.45;
|
||||
}
|
||||
.row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.hint {
|
||||
font-size: 0.85rem;
|
||||
color: var(--muted);
|
||||
margin: 4px 0;
|
||||
}
|
||||
.message {
|
||||
min-height: 1.4em;
|
||||
margin: 4px 0;
|
||||
}
|
||||
.bad {
|
||||
color: var(--danger);
|
||||
}
|
||||
.phase {
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
}
|
||||
dl {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(7rem, auto) 1fr;
|
||||
gap: 4px 12px;
|
||||
margin: 0;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
dt {
|
||||
color: var(--muted);
|
||||
}
|
||||
dd {
|
||||
margin: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.answer,
|
||||
.turn p {
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
margin: 0;
|
||||
}
|
||||
.log {
|
||||
font-size: 0.72rem;
|
||||
overflow-x: auto;
|
||||
max-height: 16rem;
|
||||
margin: 10px 0 0;
|
||||
white-space: pre;
|
||||
}
|
||||
.hud {
|
||||
background: #000;
|
||||
border-radius: 8px;
|
||||
padding: 8px;
|
||||
margin: 8px 0;
|
||||
}
|
||||
.hud pre {
|
||||
margin: 0;
|
||||
color: #d8ffd8;
|
||||
font-size: 0.85rem;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.hud-body {
|
||||
min-height: 9em;
|
||||
}
|
||||
.hud-status {
|
||||
border-top: 1px solid #244;
|
||||
padding-top: 4px;
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
import type { Controller, Snapshot } from '../core/controller.ts';
|
||||
import { BridgeApiError, BridgeNetworkError, normalizeBridgeUrl } from '../net/bridgeClient.ts';
|
||||
|
||||
/**
|
||||
* Phone-side page: pairing, status, diagnostics, typed input and disconnect.
|
||||
* Built with DOM APIs and textContent only, so nothing from the bridge or the
|
||||
* agent is ever interpreted as HTML.
|
||||
*/
|
||||
function el<K extends keyof HTMLElementTagNameMap>(
|
||||
tag: K,
|
||||
props: Partial<HTMLElementTagNameMap[K]> & { class?: string } = {},
|
||||
children: Array<Node | string> = [],
|
||||
): HTMLElementTagNameMap[K] {
|
||||
const node = document.createElement(tag);
|
||||
const { class: className, ...rest } = props;
|
||||
if (className) node.className = className;
|
||||
Object.assign(node, rest);
|
||||
for (const child of children) node.append(child);
|
||||
return node;
|
||||
}
|
||||
|
||||
function explain(err: unknown): string {
|
||||
if (err instanceof BridgeApiError) return `${err.body.message} (${err.body.code})`;
|
||||
if (err instanceof BridgeNetworkError) {
|
||||
return (
|
||||
'Could not reach the bridge. Check the address, that the bridge is running, that this app build ' +
|
||||
"lists the bridge in its network whitelist, and that the bridge allows this page's origin."
|
||||
);
|
||||
}
|
||||
return err instanceof Error ? err.message : 'Something went wrong.';
|
||||
}
|
||||
|
||||
const PHASE_LABEL: Record<string, string> = {
|
||||
unpaired: 'Not paired',
|
||||
ready: 'Ready',
|
||||
listening: 'Listening (microphone open)',
|
||||
transcribing: 'Transcribing',
|
||||
thinking: 'Thinking',
|
||||
approval: 'Approval required',
|
||||
answer: 'Answer shown',
|
||||
error: 'Error',
|
||||
disconnected: 'Disconnected',
|
||||
cancelled: 'Cancelled',
|
||||
};
|
||||
|
||||
export function mountPhoneUi(root: HTMLElement, controller: Controller, defaults: { bridgeUrl: string; runtime: string }): (s: Snapshot) => void {
|
||||
root.replaceChildren();
|
||||
|
||||
const message = el('p', { class: 'message', role: 'status' } as never);
|
||||
const say = (text: string, bad = false) => {
|
||||
message.textContent = text;
|
||||
message.className = bad ? 'message bad' : 'message';
|
||||
};
|
||||
|
||||
async function guarded(button: HTMLButtonElement, action: () => Promise<string | void>): Promise<void> {
|
||||
button.disabled = true;
|
||||
try {
|
||||
const result = await action();
|
||||
if (result) say(result);
|
||||
} catch (err) {
|
||||
say(explain(err), true);
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- pairing
|
||||
const urlInput = el('input', { type: 'url', value: defaults.bridgeUrl, placeholder: 'https://bridge.example', autocomplete: 'off' });
|
||||
const codeInput = el('input', { type: 'text', placeholder: 'ABCDE-FGHJK', autocomplete: 'off', autocapitalize: 'characters' } as never);
|
||||
const nameInput = el('input', { type: 'text', value: 'G2', maxLength: 60 });
|
||||
const pairButton = el('button', { type: 'button', textContent: 'Pair' });
|
||||
pairButton.addEventListener('click', () =>
|
||||
guarded(pairButton, async () => {
|
||||
const url = normalizeBridgeUrl(urlInput.value);
|
||||
await controller.pair(url, codeInput.value.trim(), nameInput.value.trim() || 'G2');
|
||||
codeInput.value = '';
|
||||
return 'Paired.';
|
||||
}),
|
||||
);
|
||||
const pairing = el('section', {}, [
|
||||
el('h2', { textContent: 'Pair with your bridge' }),
|
||||
el('p', { class: 'hint', textContent: 'On the bridge host run “npm run bridge:cli -- pair” and enter the code it prints. Codes work once and expire in a few minutes.' }),
|
||||
el('label', {}, ['Bridge address', urlInput]),
|
||||
el('label', {}, ['Pairing code', codeInput]),
|
||||
el('label', {}, ['Device name', nameInput]),
|
||||
pairButton,
|
||||
]);
|
||||
|
||||
// ---- status
|
||||
const statusList = el('dl');
|
||||
const refreshButton = el('button', { type: 'button', class: 'secondary', textContent: 'Refresh' });
|
||||
refreshButton.addEventListener('click', () => guarded(refreshButton, () => controller.refreshStatus()));
|
||||
const renewButton = el('button', { type: 'button', class: 'secondary', textContent: 'Renew credential' });
|
||||
renewButton.addEventListener('click', () => guarded(renewButton, async () => (await controller.renew(), 'Credential renewed.')));
|
||||
const disconnectButton = el('button', { type: 'button', class: 'danger', textContent: 'Disconnect' });
|
||||
disconnectButton.addEventListener('click', () =>
|
||||
guarded(disconnectButton, async () => {
|
||||
const { revoked } = await controller.disconnect();
|
||||
return revoked
|
||||
? 'Disconnected. The credential was revoked and removed from this phone.'
|
||||
: 'Removed from this phone, but the bridge could not be reached. Revoke this device on the bridge host to finish.';
|
||||
}),
|
||||
);
|
||||
const status = el('section', {}, [
|
||||
el('h2', { textContent: 'Connection' }),
|
||||
statusList,
|
||||
el('div', { class: 'row' }, [refreshButton, renewButton, disconnectButton]),
|
||||
]);
|
||||
|
||||
// ---- conversation and typed input
|
||||
const textInput = el('textarea', { rows: 3, placeholder: 'Type a question (for testing, or when speaking is not possible)' });
|
||||
const askButton = el('button', { type: 'button', textContent: 'Ask' });
|
||||
askButton.addEventListener('click', () => {
|
||||
controller.askText(textInput.value);
|
||||
textInput.value = '';
|
||||
});
|
||||
const cancelButton = el('button', { type: 'button', class: 'secondary', textContent: 'Cancel request' });
|
||||
cancelButton.addEventListener('click', () => controller.cancel());
|
||||
const newButton = el('button', { type: 'button', class: 'secondary', textContent: 'New conversation' });
|
||||
newButton.addEventListener('click', () => controller.newConversation());
|
||||
const phase = el('p', { class: 'phase' });
|
||||
const captureNote = el('p', { class: 'hint' });
|
||||
const turnView = el('div', { class: 'turn' });
|
||||
const conversation = el('section', {}, [
|
||||
el('h2', { textContent: 'Conversation' }),
|
||||
phase,
|
||||
captureNote,
|
||||
el('label', {}, ['Typed question', textInput]),
|
||||
el('div', { class: 'row' }, [askButton, cancelButton, newButton]),
|
||||
turnView,
|
||||
]);
|
||||
|
||||
// ---- diagnostics
|
||||
const diagList = el('dl');
|
||||
const logView = el('pre', { class: 'log' });
|
||||
const diagnostics = el('details', {}, [
|
||||
el('summary', { textContent: 'Diagnostics' }),
|
||||
el('p', { class: 'hint', textContent: 'Identifiers, states and timings only. Questions and answers are not written to this log.' }),
|
||||
diagList,
|
||||
logView,
|
||||
]);
|
||||
|
||||
root.append(el('h1', { textContent: 'Hermeven' }), message, pairing, status, conversation, diagnostics);
|
||||
|
||||
const rows = (list: HTMLElement, entries: Array<[string, string]>) => {
|
||||
list.replaceChildren(...entries.flatMap(([k, v]) => [el('dt', { textContent: k }), el('dd', { textContent: v })]));
|
||||
};
|
||||
const when = (iso: string) => (iso ? new Date(iso).toLocaleString() : 'unknown');
|
||||
|
||||
return (s: Snapshot) => {
|
||||
pairing.hidden = s.paired;
|
||||
status.hidden = !s.paired;
|
||||
conversation.hidden = !s.paired;
|
||||
|
||||
rows(statusList, [
|
||||
['Bridge', s.bridgeUrl],
|
||||
['Agent', s.status ? (s.status.agent_reachable ? 'reachable' : 'not reachable from the bridge') : 'not checked'],
|
||||
['Speech-to-text', s.status ? (s.status.stt_configured ? 'configured' : 'not configured (typed questions only)') : 'not checked'],
|
||||
['Credential valid until', when(s.tokenExpiresAt)],
|
||||
['Pairing valid until', when(s.pairingExpiresAt)],
|
||||
['Stored on this phone', 'In the Even app’s app storage, which is not an encrypted vault. The credential is revocable and expires.'],
|
||||
]);
|
||||
|
||||
phase.textContent = PHASE_LABEL[s.state.phase] ?? s.state.phase;
|
||||
captureNote.textContent =
|
||||
`Recording starts only when you tap the glasses, shows “● REC” for as long as the microphone is open, ` +
|
||||
`and stops by itself after ${s.state.captureMaxSeconds} seconds.`;
|
||||
const inFlight = ['listening', 'transcribing', 'thinking', 'approval', 'disconnected'].includes(s.state.phase);
|
||||
askButton.disabled = inFlight;
|
||||
newButton.disabled = inFlight;
|
||||
cancelButton.disabled = !inFlight;
|
||||
|
||||
const t = s.lastTurn;
|
||||
turnView.replaceChildren();
|
||||
if (s.state.error) {
|
||||
turnView.append(el('p', { class: 'bad', textContent: `${s.state.error.hud} [${s.state.error.code}]` }));
|
||||
}
|
||||
if (t) {
|
||||
if (t.input_text) turnView.append(el('h3', { textContent: 'Sent to the agent' }), el('p', { textContent: t.input_text }));
|
||||
if (t.answer_text !== null) {
|
||||
turnView.append(
|
||||
el('h3', { textContent: t.outcome === 'incomplete' ? 'Partial answer' : 'Answer' }),
|
||||
el('p', { class: 'answer', textContent: t.answer_text }),
|
||||
);
|
||||
}
|
||||
turnView.append(
|
||||
el('p', {
|
||||
class: 'hint',
|
||||
textContent:
|
||||
`Outcome: ${t.outcome ?? 'pending'}${t.error ? ` · ${t.error.code}` : ''}` +
|
||||
`${t.cancel_requested ? ' · cancel was requested' : ''}`,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
rows(diagList, [
|
||||
['Runtime', defaults.runtime],
|
||||
['Page origin', location.origin],
|
||||
['HUD page', s.hudReady ? 'created' : 'not created'],
|
||||
['Device id', s.deviceId || 'none'],
|
||||
['Conversation id', s.state.conversationId ?? 'none'],
|
||||
['Request id', s.state.requestId ?? 'none'],
|
||||
['Generation', String(s.state.generation)],
|
||||
['Audio format', s.status ? `${s.status.audio_format.encoding} ${s.status.audio_format.sample_rate} Hz × ${s.status.audio_format.channels}` : 'unknown'],
|
||||
[
|
||||
'Deadlines',
|
||||
s.status
|
||||
? `transcribe ${s.status.limits.transcribe_deadline_seconds} s · agent ${s.status.limits.agent_deadline_seconds} s · approval ${s.status.limits.approval_wait_seconds} s`
|
||||
: 'unknown',
|
||||
],
|
||||
]);
|
||||
logView.textContent = s.log
|
||||
.slice(-60)
|
||||
.map((e) => `${new Date(e.at).toISOString().slice(11, 23)} ${e.kind.padEnd(12)} ${e.detail}`)
|
||||
.join('\n');
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user