feat(box): the box's NixOS system as a module, and lib.mkBox from a few names
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The box within reach of the couch: a Raspberry Pi 3B with the AIY Voice HAT, from the first household's configuration, made generic. - box/body: the button service, in Python: press and talk, turns by voice, a press interrupts; the look signal - box/*.js: the ir and look capabilities, behind gates, for the brain; the ask client, the box's side of a conversation - box/module.nix: the services, each confined to the devices and addresses it needs; the private network as an option (a tailnet by default); the Pico found by its USB IDs, as /dev/pdtv26-ir - box/voicehat.nix: the Voice HAT's device tree overlay and ALSA setup - lib.mkBox: a box's whole system from its name, the home server's, the Wi-Fi network's, and who looks after it - checks: box-js, box-py (doctests and pyflakes), and box-system (an example box's system evaluates) Generated-by: Claude Opus 5.5
This commit is contained in:
1 parent
2e7156dc36
commit
521998b666
35 files changed
+2165
-3
No files matched your search
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* @file ask-client: the box's side of a conversation with the brain, through its ask capability.
|
||||
* usage: ask-client.js URL CONVERSATION < question.txt
|
||||
* prints JSON lines: {"say": "..."} for each thing the brain says meanwhile,
|
||||
* then {"reply": "...", "end": false}; end is true when the brain ends the conversation.
|
||||
* usage: ask-client.js URL CONVERSATION end
|
||||
* tells the brain the conversation is over.
|
||||
* The key is in $CREDENTIALS_DIRECTORY/ask-key (systemd LoadCredential), not argv, where ps would show it.
|
||||
*/
|
||||
import { newWebSocketRpcSession } from 'capnweb';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import process from 'node:process';
|
||||
import { text } from 'node:stream/consumers';
|
||||
|
||||
/**
|
||||
* Ask the brain at URL the question on stdin, or tell it the conversation is over.
|
||||
*
|
||||
* @param {object} [io] what it reaches; the process's own, by default
|
||||
* @param {string[]} [io.argv] URL CONVERSATION [end]
|
||||
* @param {Record<string, string | undefined>} [io.env] for CREDENTIALS_DIRECTORY
|
||||
* @param {typeof readFile} [io.read] reads the key
|
||||
* @param {AsyncIterable<Uint8Array>} [io.stdin] the question
|
||||
* @param {{ write(s: string): unknown }} [io.stdout] the answer goes here, as JSON lines
|
||||
* @param {typeof newWebSocketRpcSession} [io.connect] opens a session with the gate at URL
|
||||
*/
|
||||
const main = async ({
|
||||
argv = process.argv.slice(2),
|
||||
env = process.env,
|
||||
read = readFile,
|
||||
stdin = process.stdin,
|
||||
stdout = process.stdout,
|
||||
connect = newWebSocketRpcSession,
|
||||
} = {}) => {
|
||||
const [url, conversation, verb] = argv;
|
||||
const key = (await read(`${env.CREDENTIALS_DIRECTORY}/ask-key`, 'utf8')).trim();
|
||||
/** @param {object} obj */
|
||||
const line = (obj) => stdout.write(`${JSON.stringify(obj)}\n`);
|
||||
const gate = connect(url);
|
||||
try {
|
||||
const asker = gate.open(key);
|
||||
if (verb === 'end') {
|
||||
await asker.end(conversation);
|
||||
return;
|
||||
}
|
||||
const question = (await text(stdin)).trim();
|
||||
// Cap'n Web passes the function by reference: the brain calls it back over this session.
|
||||
const { text: reply, end } = await asker.ask(question, conversation, (/** @type {string} */ said) => { line({ say: said }); });
|
||||
line({ reply, end });
|
||||
} finally {
|
||||
gate[Symbol.dispose]();
|
||||
}
|
||||
};
|
||||
|
||||
main().catch((err) => {
|
||||
console.error(`ask-client: ${err.message ?? err}`);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in new issue
Block a user