feat(speech): the speech capability over Cap'n Web, behind a gate
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The agent's ears and voice: a server on the home server transcribes a clip (sox, whisper.cpp) and speaks text (piper), one job at a time. A gate hands the capability to whoever presents its key; the key comes from systemd's credentials, not argv. make test runs the unit tests in Nix's sandbox; make smoke starts a real server on localhost, speaks a phrase, and hears it back. Generated-by: Claude Opus 5.5
This commit is contained in:
1 parent
4a42c896db
commit
2e7156dc36
20 files changed
+621
No files matched your search
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @file The gate: hands a capability to whoever presents its key.
|
||||
* A server listens with a gate, not the capability itself, so a connection gets nothing
|
||||
* until it shows the key: open(key) returns the capability, and pipelines, so a client
|
||||
* can open and call in one round trip.
|
||||
*/
|
||||
import { RpcTarget } from 'capnweb';
|
||||
import { createHash, timingSafeEqual } from 'node:crypto';
|
||||
|
||||
const digest = (s) => createHash('sha256').update(String(s)).digest();
|
||||
|
||||
/**
|
||||
* @template T
|
||||
*/
|
||||
export class Gate extends RpcTarget {
|
||||
#want;
|
||||
#cap;
|
||||
|
||||
/**
|
||||
* @param {string} key unguessable, from a credential file
|
||||
* @param {T} cap what open(key) hands out
|
||||
*/
|
||||
constructor(key, cap) {
|
||||
super();
|
||||
this.#want = digest(key);
|
||||
this.#cap = cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} k
|
||||
* @returns {T}
|
||||
*/
|
||||
open(k) {
|
||||
// Digests are the same length whatever k is, so the comparison takes the same time.
|
||||
if (!timingSafeEqual(digest(k), this.#want)) throw new Error('no such key');
|
||||
return this.#cap;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user