import { LOG_REDACT, createBridge } from './app.ts'; import { ConfigError, loadConfig } from './config.ts'; import { StateDirectoryError } from './db.ts'; import { loadEnvFile } from './env.ts'; import { BuiltinWhisperStt } from './stt/builtinWhisper.ts'; async function main(): Promise { loadEnvFile(); const config = loadConfig(); const bridge = await createBridge(config, { logger: { level: config.logLevel, redact: { paths: LOG_REDACT, censor: '[redacted]' } }, }); await bridge.app.listen({ host: config.host, port: config.port }); // Verify and load the built-in speech model in the background so the first spoken question // is not slowed by it. Nothing is downloaded here: the files must already be in the model // store (`bridge:cli fetch-model`) and must match their pinned hashes. const stt = bridge.stt; if (stt instanceof BuiltinWhisperStt) { const started = Date.now(); const pin = { model: config.stt.manifest!.model, revision: config.stt.manifest!.revision }; bridge.app.log.info(pin, 'stt.loading'); stt.warm().then( () => bridge.app.log.info({ ...pin, load_ms: Date.now() - started }, 'stt.ready'), () => bridge.app.log.error( { ...pin, reason: stt.lastLoadFailure, hint: stt.lastLoadFailure === 'missing' ? 'run: npm run bridge:cli -- fetch-model' : undefined, }, 'stt.load_failed', ), ); } let closing = false; const stop = (signal: string) => { if (closing) return; closing = true; bridge.app.log.info({ signal }, 'bridge.stopping'); bridge.close().then( () => process.exit(0), () => process.exit(1), ); }; process.on('SIGINT', () => stop('SIGINT')); process.on('SIGTERM', () => stop('SIGTERM')); } main().catch((err: unknown) => { // Configuration problems are operator-facing; never print the environment. if (err instanceof ConfigError) console.error(`Configuration error: ${err.message}`); else if (err instanceof StateDirectoryError) console.error(`Cannot start: ${err.message}`); else console.error(err); process.exit(1); });