14 lines
825 B
JavaScript
14 lines
825 B
JavaScript
// A module that keeps state through the SDK (novox/hq ADR 0201): it watches its servers as it is
|
|
// imported, and writes each change it is handed to STATE_LOG; one tool registers a server.
|
|
import { appendFileSync } from "node:fs";
|
|
import { state } from "@novox/mesh-sdk/state";
|
|
import { registerModuleTools } from "@novox/mesh-sdk/tools";
|
|
|
|
const servers = state("servers");
|
|
await servers.watch((c) => appendFileSync(process.env.STATE_LOG, `${c.current ? "was" : "now"} ${c.op} ${c.key}\n`));
|
|
await servers.watch((c) => appendFileSync(process.env.STATE_LOG, `narrow ${c.op} ${c.key}\n`), { key: "anchor.*" });
|
|
appendFileSync(process.env.STATE_LOG, "current\n");
|
|
registerModuleTools("sdkkeeper", () => [
|
|
{ name: "register", description: "put a server", input: {}, run: async (a) => servers.put(a.key, { url: a.url }) },
|
|
]);
|