/** * Guest-side server — runs a caller's {@link IsolatedImplementation} against a {@link PortLike}, * dispatching inbound `call`/`stream:start`/`stream:cancel`/`abort`/`shutdown` envelopes via a * {@link GuestEndpoint} and encoding results/deltas/errors back across the wire via the tiered codec. * * @remarks * `serveIsolatedOverPort` is the environment-neutral primitive: it takes an already-constructed * {@link PortLike}, so it works identically whether that port wraps a Web Worker's global scope, a * node `process`, or (as in the shared protocol's unit specs) a linked in-memory fake port. `serveIsolated` is the * convenience wrapper the browser and Node guest entry points call directly: it duck-detects the environment * (`globalThis.self.postMessage` → Worker; `globalThis.process?.send` → child_process) and builds the * matching `PortLike` itself — WITHOUT importing any `node:*` module (a plain `globalThis.process` duck * check, never `import 'node:...'`), keeping this module loadable in every environment. */ import { type IsolationObservabilityHooks } from "./observability"; import type { WireValue } from "./protocol"; import type { IsolatedEmitter, IsolatedImplementation, IsolatedServiceSpec, PortLike } from "./types"; /** Options accepted by {@link serveIsolated}/{@link serveIsolatedOverPort}. */ export interface ServeIsolatedOptions extends IsolationObservabilityHooks { /** Classes to register with `@nhtio/encoder`'s custom-encodable round-trip on this side (sugar over * `registerClass`; lazy — only touches the encoder peer when this array is non-empty). */ encodables?: ReadonlyArray<{ readonly name: string; }>; } /** The implementation factory `serveIsolated`/`serveIsolatedOverPort` calls once, up front, to obtain * the guest-side method/stream implementations plus the `emit` capability for declared events. */ export type IsolatedImplementationFactory = (input: { emit: IsolatedEmitter; /** Issue a guest-to-host capability call. */ hostcall: (method: string, args: WireValue[], maxBytes?: number) => Promise; }) => IsolatedImplementation; /** * Serve `spec` over an already-constructed {@link PortLike} — the environment-neutral primitive. * Builds the implementation via `factory`, wires a {@link GuestEndpoint} to it, and announces * readiness (`ready` envelope) once the encoder-availability probe resolves. * * @throws {@link @nhtio/adk/batteries/isolation!E_INVALID_ISOLATION_OPTIONS} when `options` fails * validation. * @returns A `stop()` function that tears down the endpoint's port subscription. Does NOT itself close * the port — callers own the port's lifecycle. */ export declare const serveIsolatedOverPort: (spec: S, factory: IsolatedImplementationFactory, port: PortLike, options?: ServeIsolatedOptions) => { stop: () => void; }; /** * Serve `spec` in the CURRENT environment, duck-detecting a Web Worker global scope * (`globalThis.self.postMessage`) or a node child_process (`globalThis.process.send`) — in that * order — and building the matching {@link PortLike} automatically. This module never imports any * `node:*` builtin, so it is safe to bundle for either target; the detection is a pure `globalThis` * duck check. * * @throws {@link @nhtio/adk/batteries/isolation!E_ISOLATION_UNSUPPORTED_ENV} when neither environment * is detected (e.g. called on a plain main-thread browser tab, or in a test with no fake `self`/ * `process.send`) — use {@link serveIsolatedOverPort} directly there instead. */ export declare const serveIsolated: (spec: S, factory: IsolatedImplementationFactory, options?: ServeIsolatedOptions) => { stop: () => void; };