import type { OpenSurfaceResult, SurfaceContext, SurfaceDataMessage, SurfaceHost, SurfaceInfo, SurfaceInputMessage, SurfaceKind, SurfaceSize } from '@moxxy/sdk'; import type { Logger } from '../logger.js'; import type { SurfaceRegistryImpl } from '../registries/surfaces.js'; /** * Manages the live, open {@link SurfaceInstance}s for a Session and multiplexes * every instance's output through a single {@link onData} fan-out. The runner * subscribes once and rebroadcasts each frame as a `surface.data` notification; * the agent's tools reach the SAME underlying resource (PTY, page) through their * plugin's module state, so a `terminal`/`browser_session` tool call appears in * the very pane the user is watching. * * Opening a kind is idempotent: a second `open` returns the instance the first * created (surfaces are shared), so a late-joining viewer attaches to the * existing resource and gets its {@link SurfaceInstance.snapshot}. */ export declare class SurfaceHostImpl implements SurfaceHost { private readonly registry; private readonly ctx; private readonly logger?; /** Upper bound on a single instance.close() before we give up waiting on it. */ private static readonly CLOSE_TIMEOUT_MS; /** Open instances, keyed by kind (one shared instance per kind). */ private readonly instances; /** Per-instance unsubscribe from its onData, dropped on close. */ private readonly unsubs; private readonly dataListeners; /** In-flight opens, so concurrent `open(kind)` calls share one instance. */ private readonly opening; /** * Viewer attach count per kind. A surface is SHARED (the agent's tool + every * attached viewer drive the same PTY/page), so `open` retains and `close` * releases; the instance is only torn down when the last viewer detaches. * Without this, a single viewer's `close` would destroy the resource out from * under the others — and React StrictMode (dev) makes that routine: it * mounts → unmounts → remounts, so the first mount's late-resolving `open` * closes the very instance the remount just attached to, leaving `input`/ * `resize` to hit a now-missing instance (output still flows from the * snapshot, but keystrokes/navigation silently vanish). */ private readonly refs; /** Set once closeAll() runs: rejects/ tears down any open() that races teardown. */ private disposed; constructor(registry: SurfaceRegistryImpl, ctx: SurfaceContext, logger?: Logger | undefined); list(): Promise>; open(kind: SurfaceKind): Promise; input(surfaceId: string, msg: SurfaceInputMessage): Promise; resize(surfaceId: string, size: SurfaceSize): Promise; close(surfaceId: string): Promise; /** * Tear an instance down without ever blocking forever: a wedged PTY/browser * whose close() neither resolves nor rejects must not stall session shutdown. * Races close() against a timeout and swallows (logs) any rejection. */ private safeClose; /** Bump the viewer attach count for an already-open kind. */ private retain; private describe; onData(cb: (msg: SurfaceDataMessage) => void): () => void; closeAll(): Promise; private byId; private emit; } //# sourceMappingURL=host.d.ts.map