/** * Types for Unified UI Bridge Architecture * * Based on @modelcontextprotocol/ext-apps SDK */ /** * Lightweight method metadata for bridge-side auto-inference. * Subset of MethodInfo — only what the declarative binding engine needs. */ export interface BridgeMethodMeta { /** Output format from @format tag: table, gauge, chart:bar, etc. */ format?: string; /** Cron schedule from @scheduled/@cron tag */ scheduled?: string; /** True if method has no side effects (@readOnly) */ readOnly?: boolean; /** JSON Schema for method parameters — enables auto form/result detection and form generation */ inputSchema?: { type?: string; properties?: Record; required?: string[]; }; } /** * Photon context passed to the bridge */ export interface PhotonBridgeContext { photon: string; method: string; theme: 'light' | 'dark'; locale?: string; hostName?: string; hostVersion?: string; /** Names of injected @photon dependencies (for client-side event routing) */ injectedPhotons?: string[]; /** True if photon class has @stateful tag (all methods auto-emit) */ stateful?: boolean; /** Per-method metadata for declarative binding auto-inference */ methodMeta?: Record; } /** * Size constraints from meta tags and host context */ export interface SizeConstraints { minWidth?: number; minHeight?: number; maxWidth?: number; maxHeight?: number; } /** * Custom Photon notification types (JSON-RPC method names) */ export type PhotonNotificationMethod = 'photon/notifications/progress' | 'photon/notifications/status' | 'photon/notifications/stream' | 'photon/notifications/emit' | 'photon/notifications/channel-event'; /** * Progress notification payload */ export interface ProgressNotification { percent?: number; message?: string; } /** * Status notification payload */ export interface StatusNotification { type: 'info' | 'success' | 'error' | 'warn'; message: string; } /** * Stream notification payload */ export interface StreamNotification { chunk: string; done?: boolean; } /** * Emit notification payload */ export interface EmitNotification { event: string; data?: any; } /** * Channel event notification payload */ export interface ChannelEventNotification { channel: string; event: string; data?: any; } /** * window.photon API interface */ export interface PhotonAPI { readonly toolOutput: any; readonly toolInput: Record; readonly widgetState: unknown; onResult(cb: (data: any) => void): () => void; onThemeChange(cb: (theme: 'light' | 'dark') => void): () => void; onProgress(cb: (notification: ProgressNotification) => void): () => void; onStatus(cb: (notification: StatusNotification) => void): () => void; onStream(cb: (notification: StreamNotification) => void): () => void; onEmit(cb: (notification: EmitNotification) => void): () => void; invoke(name: string, args?: Record): Promise; callTool(name: string, args?: Record): Promise; setWidgetState(state: unknown): void; readonly theme: 'light' | 'dark'; readonly locale: string; /** Base URL of this photon including any proxy prefix. Use for all fetch() calls. */ readonly url: string; } /** * window.openai API interface (OpenAI Apps SDK compatibility) */ export interface OpenAIAPI { readonly theme: 'light' | 'dark'; readonly displayMode: 'inline' | 'fullscreen' | 'pip'; readonly locale: string; readonly maxHeight: number; readonly toolInput: Record; readonly toolOutput: unknown; readonly widgetState: unknown; setWidgetState(state: unknown): void; callTool(name: string, args: Record): Promise; sendFollowUpMessage(options: { prompt: string; }): Promise; uploadFile(file: File): Promise<{ fileId: string; }>; getFileDownloadUrl(options: { fileId: string; }): Promise; requestDisplayMode(mode: 'inline' | 'fullscreen' | 'pip'): Promise; requestModal(options: { params: unknown; template: string; }): Promise; notifyIntrinsicHeight(height: number): void; openExternal(options: { href: string; }): void; setOpenInAppUrl(options: { href: string; }): void; } /** * Bidirectional state exposure convention. * * When a custom UI calls `callTool()`, the bridge automatically attaches the * current `widgetState` as `_clientState` in the tool call arguments if the * widget state has any keys set. The loader strips `_clientState` before JSON * Schema validation and makes it available on the photon instance as * `this._clientState`. * * This enables custom UIs to passively expose context to photon methods without * the user explicitly passing it as a tool argument. * * CLI calls (no widgetState) work unchanged — `_clientState` is simply absent. */ export interface ClientState { [key: string]: unknown; } declare global { interface Window { photon: PhotonAPI; openai: OpenAIAPI; } } //# sourceMappingURL=types.d.ts.map