/** * BeamState — Shared state for Beam modules. * * Replaces the ~30 closure variables in startBeam() with a single * typed object that route handlers and utility modules can share. */ import type { PhotonLoader } from '../../loader.js'; import type { MarketplaceManager } from '../../marketplace-manager.js'; import type { PhotonContext } from '../../context.js'; import type { SimpleRateLimiter } from '../../shared/security.js'; import type { AnyPhotonInfo, ExternalMCPInfo, MCPServerConfig } from '../types.js'; import type { Client } from '@modelcontextprotocol/sdk/client/index.js'; /** Unified config structure for config.json */ export interface PhotonConfig { photons: Record>; mcpServers: Record; } /** Channel subscription with reference counting */ export interface ChannelSubscription { photonName: string; channelPattern: string; refCount: number; unsubscribe: () => void; } /** Buffered event for replay on new subscriptions */ export interface BufferedEvent { channel: string; data: unknown; timestamp: number; } /** Route handler signature: returns true if it handled the request */ export type RouteHandler = (req: import('http').IncomingMessage, res: import('http').ServerResponse, url: URL, state: BeamState) => Promise; /** Callbacks that route handlers can invoke to trigger side effects */ export interface BeamActions { broadcastPhotonChange: () => void; handleFileChange: (photonName: string) => Promise; loadSinglePhoton: (name: string) => Promise; reconnectExternalMCP: (name: string) => Promise<{ success: boolean; error?: string; }>; loadUIAsset: (photonName: string, uiId: string) => Promise<{ content: string; isPhotonTemplate: boolean; compiled?: import('../../tsx-compiler.js').CompiledTsx; } | null>; subscribeToChannel: (channel: string) => Promise; unsubscribeFromChannel: (channel: string) => void; configurePhotonViaMCP: (photonName: string, config: Record) => Promise; reloadPhotonViaMCP: (photonName: string) => Promise; removePhotonViaMCP: (photonName: string) => Promise; } /** * BeamState — mutable shared state for the Beam server. * * Created once in startBeam() and passed to all route handlers and utilities. * This replaces the closure-captured variables scattered throughout the 4300-line function. */ export interface BeamState { /** Actions (callbacks) that route handlers can invoke */ actions: BeamActions; /** Resolved working directory */ workingDir: string; /** * PhotonContext for path resolution. Currently unused by route modules — * field is kept for future plumbing but holds null today. */ ctx: PhotonContext | null; /** Photon loader instance */ loader: PhotonLoader; /** Marketplace manager */ marketplace: MarketplaceManager; /** In-memory mirror of config.json */ savedConfig: PhotonConfig; /** All loaded photons (configured + unconfigured) */ photons: AnyPhotonInfo[]; /** Map of photon name → loaded MCP instance */ photonMCPs: Map; /** External MCP server info */ externalMCPs: ExternalMCPInfo[]; /** Active MCP transport clients for external MCPs */ externalMCPClients: Map; /** Direct SDK clients for resource access */ externalMCPSDKClients: Map; /** Channel subscriptions (ref-counted) */ channelSubscriptions: Map; /** Event buffer for replay */ channelEventBuffers: Map; /** Per-session view state (which board each session is viewing) */ sessionViewState: Map; /** API rate limiter */ apiRateLimiter: SimpleRateLimiter; /** HTTP server instance */ server: import('http').Server | null; /** File watchers */ watchers: import('fs').FSWatcher[]; /** Pending reload debounce timers */ pendingReloads: Map; /** Currently loading photon names (prevents duplicate loads) */ activeLoads: Set; /** Callbacks to run after a load completes */ pendingAfterLoad: Map void>>; /** __dirname of the beam module (for resolving static assets) */ beamDir: string; /** Count of configured photons */ configuredCount: number; /** Count of unconfigured photons */ unconfiguredCount: number; } //# sourceMappingURL=types.d.ts.map