A TypeScript holder, the forge module first, must judge a verb's caller by the runtime's proof, say its seat's events and answer its first views' read and ask-again tools (design 47, The forge module's tools come from mesh-sdk's TypeScript side; G-F1 option A). The stdio session now hands each tool the caller and call id the runtime wrote in _meta (callers.callerOf, the Go rules for Callers and VerbCallers), binds the runtime for seatPublish over mesh/seat.publish and config, and views gains the Follower and its two status tools over the state first-views. @novox/mesh-sdk 0.1.19. Builds: design 47 G §196, §200, §336 Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
38 lines
1.9 KiB
TypeScript
38 lines
1.9 KiB
TypeScript
// 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<unknown>;
|
|
|
|
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<unknown> {
|
|
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.<seat>.event.<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<void> {
|
|
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<unknown> {
|
|
return askRuntime("mesh/provision.get", { kind: "config", key });
|
|
}
|