// The runtime that launched this bundle, as one channel of requests (novox/hq ADR 0193, ADR 0198): what a module's code // asks of its node's tool runner beyond emitting, subscribing and its state, each named by the runtime's method // (`mesh/seat.publish`, `mesh/provision.get`). The stdio session binds it when the runtime launched the process; a // bundle never names a transport. /** What the runtime is asked through: the stdio session provides it. */ export type RuntimeAsk = (method: string, params: unknown) => Promise; let bound: RuntimeAsk | undefined; /** Bind the channel. The stdio session calls this when the runtime launched the process; a test binds its own. */ export function useRuntime(ask: RuntimeAsk | undefined): void { bound = ask; } /** Ask the runtime one of its methods; refused with the reason when no runtime launched this bundle. */ export async function askRuntime(method: string, params: unknown): Promise { if (!bound) { throw new Error(`no runtime to ask ${method} of: it is reached through the runtime that launched this bundle (novox/hq ADR 0198)`); } return bound(method, params); } /** * Submit an accept, or say an event, on a seat (novox/hq ADR 0259 ยง3): `subject` whole, as the seat's contract names * it (`mesh.seat..event.`), de-duplicated by `id` (the same id twice is one message; empty is the * runtime's to make). The runtime does it as this module, only as far as its membership lists, and refuses the rest * with the reason: the Go side's `stdio.SeatPublish`. */ export async function seatPublish(subject: string, body: unknown, id = ""): Promise { await askRuntime("mesh/seat.publish", { subject, body, id }); } /** This module's config value `key`, as mesh-config resolved it for this machine (the Go side's `stdio.Config`). */ export async function config(key: string): Promise { return askRuntime("mesh/provision.get", { kind: "config", key }); }