The TypeScript SDK's state reaches the runtime, a narrowed watch only its keys (novox/hq ADR 0201)
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
// 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 }) },
|
||||
]);
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
// The launcher the builder writes beside an entrypoint (novox/hq ADR 0193), for state-sdk.mjs.
|
||||
import { serveRegisteredOverStdio } from "@novox/mesh-sdk/stdio";
|
||||
await import("./state-sdk.mjs");
|
||||
await serveRegisteredOverStdio();
|
||||
Reference in New Issue
Block a user