/** * app() factory — the one-call entry point for prefab apps. * * Auto-detects environment (iframe → postMessage bridge, standalone → HTTP transport), * performs handshake if in iframe, applies host theme, and returns a clean API object. * * Usage: * ```ts * const ui = await prefab.app(); * * ui.onToolInput((args) => { * ui.render('#root', Column( * H1('Results'), * autoTable(args.data), * )); * }); * ``` */ import type { PrefabWireData, MountOptions, MountedApp } from './index.js'; import type { AppCapabilities, HostContext, HostCapabilities, HostTheme, DisplayMode } from './bridge.js'; import type { McpTransportOptions } from './transport.js'; import type { McpTransport } from './actions.js'; import { Store } from './state.js'; import type { ComponentNode } from './engine.js'; export interface AppOptions { /** Override environment detection: force bridge or standalone mode. */ mode?: 'bridge' | 'standalone' | 'auto'; /** Allowed host origin for postMessage (default: '*'). Set explicitly in production. */ hostOrigin?: string; /** HTTP transport options (for standalone mode). */ transport?: McpTransportOptions; /** App capabilities to advertise to host. */ capabilities?: AppCapabilities; } export type ToolInputHandler = (args: Record) => void; export type ToolResultHandler = (result: unknown) => void; export type VoidHandler = () => void; export interface PrefabApp { /** Call an MCP tool through the transport. */ callTool: (name: string, args?: Record) => Promise; /** Send a message through the transport. */ sendMessage: (message: string) => Promise; /** Register a handler for tool input from the host. */ onToolInput: (handler: ToolInputHandler) => void; /** Register a handler for tool results from the host. */ onToolResult: (handler: ToolResultHandler) => void; /** Register a handler for tool cancellation. */ onToolCancelled: (handler: VoidHandler) => void; /** Register a handler for partial/streaming tool input. */ onToolInputPartial: (handler: ToolInputHandler) => void; /** Register a handler for host context changes (full params from host-context-changed). */ onHostContextChanged: (handler: (context: Record) => void) => void; /** Render a component tree into a DOM element. */ render: (target: string | HTMLElement, ...components: ComponentNode[]) => MountHandle; /** Mount full wire-format data (legacy API). */ mount: (target: string | HTMLElement, data: PrefabWireData, opts?: MountOptions) => MountedApp; /** Request a display mode change. */ requestMode: (mode: DisplayMode) => void; /** Request the host to open a URL. */ openLink: (url: string, target?: string) => void; /** Send context updates. */ updateContext: (context: Record) => void; /** * Observe an element and notify the host whenever it resizes. * Mirrors the ext-apps SDK `autoResize: true` behaviour. * Returns a teardown function that disconnects the observer. */ setupAutoResize: (target: string | HTMLElement) => () => void; /** * Notify the host of declarative layout/size preferences from the wire format. * Called automatically when mounting wire data with a `layout` field. */ notifyPreferredSize: (layout: { preferredHeight?: number; minHeight?: number; maxHeight?: number; }) => void; /** Host context from initialization. */ host: HostContext; /** Host capabilities. */ capabilities: HostCapabilities; /** Host theme (if provided). */ theme: HostTheme | undefined; /** The underlying MCP transport. */ transport: McpTransport; /** Destroy the app and clean up. */ destroy: () => void; } export interface MountHandle { /** Re-render the current component tree. */ rerender: () => void; /** Access the reactive store. */ store: Store; /** Unmount. */ destroy: () => void; } /** * Create a prefab app. Auto-detects iframe vs standalone. * * In an iframe: uses postMessage bridge, performs handshake with host. * Standalone: uses HTTP transport (or noop if no config). */ export declare function app(options?: AppOptions): Promise; //# sourceMappingURL=app.d.ts.map