import { SduiNode } from '@ethisyscore/protocol'; import { h as WorkerCtor, M as McpHttpClient, k as WorkerRemoteDomTransport } from '../transport-C4xoMWBE.cjs'; import '../bridge-envelopes-DA6vxbyb.cjs'; /** * `npx mock-host ` — standalone declarative-mock-host dev server. * * Reads SDUI resources from `/**\/*.json` (recursive), wires them into the * {@link InMemoryMcpTransport}, and serves a Vite dev page that mounts * {@link DeclarativeMockHost} so plugin authors can iterate against the same * declarative pipeline the real host uses — without standing up the platform. * * Resource JSON shape (two accepted forms): * * 1. Tagged: `{ "uri": "books://catalog", "tree": }` * 2. Untagged: a bare SDUI node. The URI defaults to the file's relative * path under the resources directory (with `\\` normalised to `/` and the * `.json` extension stripped). * * The CLI's pure resource-loading core is exported as {@link loadResources} * for unit testing; the Vite-boot side effect is gated behind {@link run}. */ /** Map of MCP resource URI -> SDUI tree, as fed into the mock host. */ type ResourceMap = Record; /** * Map of MCP tool name -> canned result, as fed into the mock host. Each * value is returned verbatim when the tool is invoked from the rendered tree * (Form.submitTool, Action.tool, Field.lookupTool). Plugin authors who need * per-call dynamic behaviour can switch from the CLI's tools.json to a * hand-rolled Vite app that mounts DeclarativeMockHost with a typed tools * object directly. */ type ToolResultMap = Record; /** * Recursively load every `*.json` file under {@link dir} as a SDUI resource. * * - Tagged form (`{ uri, tree }`) wins when both fields are present. * - Untagged form uses the file's relative POSIX-normalised path (minus * extension) as the resource URI. * * Throws a single aggregated error if any file fails to parse — plugin authors * see one failure list instead of giving up at the first bad file. */ declare function loadResources(dir: string): Promise; /** * Read `/tools.json` (if present) and return a `Record` * map for the mock transport. Missing file → empty map. Malformed file → * throws a single descriptive error. * * Expected shape: `{ "": , ... }`. The literal is * returned verbatim from `InMemoryMcpTransport.invokeTool(name, args)`. */ declare function loadTools(dir: string): Promise; /** * Convert a parsed JSON value into a `{ uri, tree }` pair. * Exported for tests; not part of the public API. */ declare function normaliseEntry(parsed: unknown, absFile: string, absDir: string): { uri: string; tree: SduiNode; }; /** * Render a self-contained HTML page that mounts {@link DeclarativeMockHost} * with a debug registry (every primitive renders to a labelled `
`). * * Returned as a string so the Vite middleware can serve it from memory without * touching the consumer's filesystem. */ declare function renderIndexHtml(resourceUris: string[]): string; /** * Build the virtual entry module the browser loads. Embeds the resource map * inline so the dev server does not have to serve JSON over a separate * endpoint — Vite HMR re-evaluates this module whenever resources change. */ declare function renderEntryModule(resources: ResourceMap, tools?: ToolResultMap): string; /** Discriminated union of the two render modes the CLI knows about. */ type RenderMode = "host-rendered" | "remote-runtime"; /** * Parsed CLI arguments. `path` is the positional argument — its meaning * depends on {@link renderMode}: * * - `host-rendered`: a directory of SDUI resource JSON files. * - `remote-runtime`: a path (or URL) to a built worker bundle. */ interface ParsedArgs { renderMode: RenderMode; path: string; } /** * Parse the CLI's argv-slice. Exported so the test suite can assert flag * handling without booting a Vite server. * * Accepts both `--render-mode ` and `--render-mode=`. Defaults * to `host-rendered` to preserve Wave 0 behaviour for existing users. */ declare function parseArgs(args: readonly string[]): ParsedArgs; /** * Render the HTML shell for the Contract B mock host. The page hosts a * receiver that mounts the Remote DOM tree produced by the worker — each * Contract B primitive renders to a labelled placeholder. */ declare function renderWorkerBundleIndexHtml(bundlePath: string): string; /** * Build the inline entry module the browser loads for Contract B. * * The module: * 1. Constructs a {@link WorkerRemoteDomTransport} pointing at the bundle. * 2. Registers a placeholder for every Contract B semantic primitive — the * test-injectable seam from E2.S4. Production hosts would substitute * gogo-ui components here. * 3. Wires the receiver onto the host's `
` slot. * * In-page wiring is deliberately minimal — the goal is observability, not a * production receiver implementation. Authors iterate against the same * surface their plugins will mount into when the platform host is finished. */ declare function renderWorkerBundleEntryModule(bundleUrl: string): string; /** * Construction options for {@link bootContractBHost}. */ interface BootContractBHostOptions { /** * Path or canonical URL to the plugin's worker bundle. The mock host * serves it from the configured Vite root — production hosts always use * a path-pinned host-origin URL. */ bundleUrl: string; /** * Injectable Worker constructor. Tests pass a fake; the production CLI * path uses the global `Worker`. The transport itself defaults to * `globalThis.Worker` when omitted — but the mock-host CLI passes through * the caller's choice so test seams compose cleanly. */ workerCtor?: WorkerCtor; /** * Optional capability token provider. Defaults to a marker string so * authors don't need to wire token plumbing into local-dev. */ capabilityToken?: () => Promise; /** * Optional MCP HTTP client. Defaults to a stub that echoes the request * shape — authors who need real MCP traffic compose the platform host. */ mcpClient?: McpHttpClient; } /** * Spawn the in-process worker that drives the Contract B mock host. * * Returns the constructed transport so callers (production CLI: the dev page; * tests: assertions) can observe spawn shape, dispose the worker on shutdown, * and inspect coalescing behaviour. Reuses * {@link WorkerRemoteDomTransport} so the capability-token isolation rules * documented in E2.S3 apply without re-implementation. */ declare function bootContractBHost(options: BootContractBHostOptions): WorkerRemoteDomTransport; /** * Boot the Vite dev server with an in-memory entry + virtual page. * * Side-effectful: imports `vite` lazily so the pure `loadResources` export * stays usable from environments that lack a Vite install (e.g., the unit * tests in this package). * * Dispatches on `--render-mode`: * - `host-rendered` (default): Wave 0 declarative-mock-host behaviour. * - `remote-runtime`: Wave 1 Contract B — spawns a worker pointing at the * supplied bundle path and serves the placeholder dev page. */ declare function run(args: string[]): Promise<{ url: string; close: () => Promise; }>; export { type BootContractBHostOptions, type ParsedArgs, type RenderMode, type ResourceMap, type ToolResultMap, bootContractBHost, loadResources, loadTools, normaliseEntry, parseArgs, renderEntryModule, renderIndexHtml, renderWorkerBundleEntryModule, renderWorkerBundleIndexHtml, run };