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,83 @@
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
import { pino, type Logger } from 'pino';
|
||||
import type { BridgeConfig } from './config.ts';
|
||||
import { openDb, type Db } from './db.ts';
|
||||
import { Devices } from './devices.ts';
|
||||
import type { HermesAdapter } from './hermes/adapter.ts';
|
||||
import { HermesRunsAdapter } from './hermes/runsAdapter.ts';
|
||||
import { buildServer } from './server.ts';
|
||||
import { NoSttAdapter, type SttAdapter } from './stt/adapter.ts';
|
||||
import { OpenAiCompatibleStt } from './stt/openaiCompatible.ts';
|
||||
import { TurnEngine, type EngineLog, type EngineTiming } from './turns.ts';
|
||||
|
||||
export interface Bridge {
|
||||
app: FastifyInstance;
|
||||
db: Db;
|
||||
devices: Devices;
|
||||
engine: TurnEngine;
|
||||
close(): Promise<void>;
|
||||
}
|
||||
|
||||
/** Pino redaction: belt and braces, since we never pass these fields to the logger anyway. */
|
||||
export const LOG_REDACT = [
|
||||
'req.headers.authorization',
|
||||
'headers.authorization',
|
||||
'token',
|
||||
'code',
|
||||
'text',
|
||||
'input_text',
|
||||
'answer_text',
|
||||
'pending_body',
|
||||
'body',
|
||||
];
|
||||
|
||||
export function sttFromConfig(config: BridgeConfig): SttAdapter {
|
||||
if (config.stt.provider === 'openai-compatible') {
|
||||
return new OpenAiCompatibleStt({ baseUrl: config.stt.baseUrl, apiKey: config.stt.apiKey, model: config.stt.model });
|
||||
}
|
||||
return new NoSttAdapter();
|
||||
}
|
||||
|
||||
export async function createBridge(
|
||||
config: BridgeConfig,
|
||||
overrides: { hermes?: HermesAdapter; stt?: SttAdapter; timing?: EngineTiming; logger?: object | boolean } = {},
|
||||
): Promise<Bridge> {
|
||||
const db = openDb(config.dbPath);
|
||||
const hermes =
|
||||
overrides.hermes ??
|
||||
new HermesRunsAdapter({
|
||||
baseUrl: config.hermes.baseUrl,
|
||||
apiKey: config.hermes.apiKey,
|
||||
requestTimeoutMs: config.hermes.requestTimeoutMs,
|
||||
});
|
||||
const stt = overrides.stt ?? sttFromConfig(config);
|
||||
const devices = new Devices(db, config);
|
||||
|
||||
const given = overrides.logger;
|
||||
const logger: Logger =
|
||||
given && typeof given === 'object'
|
||||
? typeof (given as Logger).child === 'function'
|
||||
? (given as Logger)
|
||||
: pino(given as object)
|
||||
: pino({ level: 'silent' });
|
||||
const engine = new TurnEngine({ db, config, hermes, stt, log: logger as unknown as EngineLog, timing: overrides.timing });
|
||||
const app = await buildServer({ config, devices, hermes, stt, engine, logger });
|
||||
|
||||
engine.recover();
|
||||
engine.purgeExpired();
|
||||
const purge = setInterval(() => engine.purgeExpired(), 60_000);
|
||||
purge.unref();
|
||||
|
||||
return {
|
||||
app,
|
||||
db,
|
||||
devices,
|
||||
engine,
|
||||
async close() {
|
||||
clearInterval(purge);
|
||||
await app.close();
|
||||
await engine.shutdown();
|
||||
db.close();
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user