/** * The console on this machine as a client asks it for every role's tools (novox/hq ADR 0571): the method `mesh/seats` * beside MCP's, answered in the shape the Go console's `seatsAnswer` gives (internal/console/mcp.go). Sets * MESH_CONSOLE to it, so a client, and a `mesh` it spawns, asks it. */ import { createServer } from "node:http"; import type { AddressInfo } from "node:net"; import { SEATS_METHOD } from "../dist/client.js"; export type SeatOfConsole = { seat: string; scope: string; tools: { name: string; description?: string; input?: unknown }[] }; export async function aConsoleWithSeats(seats: SeatOfConsole[]): Promise<{ url: string; close: () => Promise }> { const local = createServer((req, res) => { let body = ""; req.on("data", (c) => (body += c)); req.on("end", () => { const asked = JSON.parse(body) as { id: number; method: string }; res.setHeader("content-type", "application/json"); if (req.url !== "/mcp" || asked.method !== SEATS_METHOD) { res.end(JSON.stringify({ jsonrpc: "2.0", id: asked.id, error: { code: -32601, message: "no such method" } })); return; } res.end(JSON.stringify({ jsonrpc: "2.0", id: asked.id, result: { seats: seats.map((s) => ({ ...s, holders: [] })) } })); }); }); await new Promise((done) => local.listen(0, "127.0.0.1", done)); const url = `http://127.0.0.1:${(local.address() as AddressInfo).port}`; process.env.MESH_CONSOLE = url; return { url, close: () => new Promise((done) => local.close(() => done())) }; }