@aprovan/mcp-app-server 0.1.0-dev.4d82df8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/.turbo/turbo-build.log +23 -0
  2. package/E2E_TESTING.md +224 -0
  3. package/LICENSE +373 -0
  4. package/README.md +164 -0
  5. package/dist/index.d.ts +128 -0
  6. package/dist/index.js +990 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/runtime/assets/__vite-browser-external-BIHI7g3E.js +1 -0
  9. package/dist/runtime/assets/index-tRNuU9ap.js +1059 -0
  10. package/dist/runtime/index.html +38 -0
  11. package/dist/server.d.ts +6 -0
  12. package/dist/server.js +1511 -0
  13. package/dist/server.js.map +1 -0
  14. package/dist/shell/shell.js +67 -0
  15. package/docs/widget-preview.png +0 -0
  16. package/e2e/__snapshots__/.gitkeep +0 -0
  17. package/e2e/global-setup.ts +114 -0
  18. package/e2e/global-teardown.ts +15 -0
  19. package/e2e/visual-regression.test.ts +86 -0
  20. package/e2e/widget-smoke.test.ts +109 -0
  21. package/index.html +32 -0
  22. package/package.json +51 -0
  23. package/playwright.config.ts +43 -0
  24. package/src/__tests__/live-update.test.ts +158 -0
  25. package/src/__tests__/local-backend.test.ts +100 -0
  26. package/src/__tests__/memory-backend.ts +144 -0
  27. package/src/__tests__/registry-backend.test.ts +256 -0
  28. package/src/__tests__/services.test.ts +153 -0
  29. package/src/__tests__/shim.test.ts +60 -0
  30. package/src/__tests__/widget-store.test.ts +188 -0
  31. package/src/e2e-visual.ts +148 -0
  32. package/src/index.ts +608 -0
  33. package/src/live-update.ts +150 -0
  34. package/src/logger.ts +44 -0
  35. package/src/reference-widgets/live-dashboard.ts +162 -0
  36. package/src/registry-backend.ts +306 -0
  37. package/src/runtime/index.html +38 -0
  38. package/src/runtime/main.ts +164 -0
  39. package/src/scripts/export-artifacts.ts +51 -0
  40. package/src/server.ts +398 -0
  41. package/src/services.ts +307 -0
  42. package/src/shell/main.ts +172 -0
  43. package/src/shim.ts +106 -0
  44. package/src/tunnel.ts +123 -0
  45. package/src/widget-store/index.ts +10 -0
  46. package/src/widget-store/local-backend.ts +77 -0
  47. package/src/widget-store/store.ts +242 -0
  48. package/src/widget-store/types.ts +53 -0
  49. package/tsconfig.json +10 -0
  50. package/tsup.config.ts +14 -0
  51. package/vite.runtime.config.ts +28 -0
  52. package/vite.shell.config.ts +30 -0
  53. package/vitest.config.ts +7 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server.ts","../src/logger.ts","../src/live-update.ts","../src/registry-backend.ts","../src/index.ts","../src/services.ts","../src/widget-store/store.ts","../src/widget-store/local-backend.ts","../src/tunnel.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport express from \"express\";\nimport { createMcpExpressApp } from \"@modelcontextprotocol/sdk/server/express.js\";\nimport { StreamableHTTPServerTransport } from \"@modelcontextprotocol/sdk/server/streamableHttp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport cors from \"cors\";\nimport { registerSession, unregisterSession } from \"./live-update.js\";\nimport { log, error } from \"./logger.js\";\nimport { createRegistryBackend, type RegistryBackend } from \"./registry-backend.js\";\nimport { createMcpAppServer, type McpAppServerOptions } from \"./index.js\";\nimport { getWidgetStore } from \"./widget-store/index.js\";\nimport { startTunnel, stopTunnel } from \"./tunnel.js\";\nimport type { Request, Response } from \"express\";\n\nconst PORT = Number(process.env[\"PORT\"] ?? 3000);\nconst WIDGET_PORT = Number(process.env[\"WIDGET_PORT\"] ?? 3002);\nconst HOST = process.env[\"HOST\"] ?? \"0.0.0.0\";\nconst TRANSPORT = process.env[\"TRANSPORT\"] ?? (process.argv.includes(\"--stdio\") ? \"stdio\" : \"http\");\nconst WIDGET_TUNNEL = process.env[\"WIDGET_TUNNEL\"] === \"true\" || process.argv.includes(\"--tunnel\");\n\ntype SessionEntry = {\n server: ReturnType<typeof createMcpAppServer>;\n transport: StreamableHTTPServerTransport;\n};\n\n/**\n * Cross-process coordination for the shared widget host.\n *\n * Every stdio spawn of this server (Claude Desktop respawns it freely) would\n * otherwise start its own widget server and its own cloudflared quick tunnel.\n * Only one can bind {@link WIDGET_PORT}; the rest orphan extra tunnels and, worse,\n * each render returns a *different* hostname — and any instance whose ephemeral\n * tunnel has dropped serves a dead URL (Cloudflare 1033) into the widget HTML.\n *\n * We elect a single owner via the port bind: whoever binds the port establishes\n * (and verifies) the tunnel and publishes its base URL to a temp file keyed by\n * port; every other instance reuses that URL instead of starting a tunnel.\n */\ninterface WidgetHostState {\n baseUrl: string;\n pid: number;\n updatedAt: number;\n}\n\nconst WIDGET_STATE_FILE = join(tmpdir(), `patchwork-widget-${WIDGET_PORT}.json`);\n\nfunction readWidgetHostState(): WidgetHostState | null {\n try {\n return JSON.parse(readFileSync(WIDGET_STATE_FILE, \"utf8\")) as WidgetHostState;\n } catch {\n return null;\n }\n}\n\nfunction publishWidgetHostState(baseUrl: string): void {\n try {\n const state: WidgetHostState = { baseUrl, pid: process.pid, updatedAt: Date.now() };\n writeFileSync(WIDGET_STATE_FILE, JSON.stringify(state));\n } catch (err) {\n error(\"mcp-app-server\", \"Failed to publish widget host state:\", err);\n }\n}\n\nfunction isProcessAlive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch (err) {\n // ESRCH = no such process; EPERM = exists but not ours (still alive).\n return (err as NodeJS.ErrnoException).code === \"EPERM\";\n }\n}\n\n/**\n * Wait for the owning instance to publish its (verified) base URL. Only adopt\n * state whose owning pid is still alive, so a non-owner never reuses a dead\n * previous owner's (now-1033) hostname.\n */\nasync function awaitPublishedWidgetBaseUrl(timeoutMs = 35000): Promise<string | null> {\n const deadline = Date.now() + timeoutMs;\n while (Date.now() < deadline) {\n const state = readWidgetHostState();\n if (state?.baseUrl && isProcessAlive(state.pid)) return state.baseUrl;\n await new Promise((r) => setTimeout(r, 500));\n }\n return null;\n}\n\n/** Locate a built browser bundle dir (dist/<name>) from either dist or src. */\nfunction resolveDistDir(name: string): string {\n const candidates = [\n fileURLToPath(new URL(`./${name}`, import.meta.url)), // built: dist/<name>\n fileURLToPath(new URL(`../dist/${name}`, import.meta.url)), // dev via tsx: src → dist\n ];\n return candidates.find((dir) => existsSync(dir)) ?? candidates[0]!;\n}\n\n/** Locate the built runtime bundle (dist/runtime). */\nexport function resolveRuntimeDir(): string {\n return resolveDistDir(\"runtime\");\n}\n\n/** Locate the built MCP App shell bundle (dist/shell). */\nexport function resolveShellDir(): string {\n return resolveDistDir(\"shell\");\n}\n\nasync function setupRegistryBackend(): Promise<{\n registryBackend: RegistryBackend | null;\n serverOptions: McpAppServerOptions;\n}> {\n const REGISTRY_PROVIDERS = process.env[\"REGISTRY_PROVIDERS\"];\n\n if (!REGISTRY_PROVIDERS) {\n return { registryBackend: null, serverOptions: {} };\n }\n\n const command = process.env[\"REGISTRY_COMMAND\"] ?? \"npx\";\n const extraArgs = process.env[\"REGISTRY_ARGS\"]?.split(\" \").filter(Boolean) ?? [];\n const args = [\"@utdk/mcp\", ...extraArgs];\n\n log(\"mcp-app-server\", `Connecting to Registry MCP server (providers: ${REGISTRY_PROVIDERS})...`);\n\n try {\n const registryBackend = await createRegistryBackend({\n command,\n args,\n providers: REGISTRY_PROVIDERS,\n });\n\n const toolInfos = registryBackend.getToolInfos();\n const namespaces = [...new Set(toolInfos.map((t) => t.namespace))];\n log(\n \"mcp-app-server\",\n `Registry ready: ${toolInfos.length} tools across namespaces: ${namespaces.join(\", \")}`\n );\n\n return {\n registryBackend,\n serverOptions: {\n services: {\n backend: registryBackend,\n tools: toolInfos,\n },\n },\n };\n } catch (err) {\n error(\"mcp-app-server\", \"Failed to connect to Registry MCP server:\", err);\n error(\"mcp-app-server\", \"Starting without Registry service backend.\");\n return { registryBackend: null, serverOptions: {} };\n }\n}\n\nfunction handleExistingSession(existing: SessionEntry, req: Request, res: Response): void {\n try {\n existing.transport.handleRequest(req, res, req.body);\n } catch (err) {\n error(\"mcp\", \"session request error\", err);\n if (!res.headersSent) {\n res.status(500).json({ error: \"Internal server error\" });\n }\n }\n}\n\nasync function createNewSession(\n serverOptions: McpAppServerOptions,\n sessionStore: Map<string, SessionEntry>,\n req: Request,\n res: Response\n): Promise<void> {\n const mcpServer = createMcpAppServer(serverOptions);\n const transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: () => randomUUID(),\n onsessioninitialized: (id) => {\n sessionStore.set(id, { server: mcpServer, transport });\n registerSession(id, mcpServer);\n },\n onsessionclosed: (id) => {\n sessionStore.delete(id);\n unregisterSession(id);\n },\n });\n\n res.on(\"close\", () => {\n const id = transport.sessionId;\n if (id && !sessionStore.has(id)) {\n void mcpServer.close();\n }\n });\n\n try {\n await mcpServer.connect(transport);\n await transport.handleRequest(req, res, req.body);\n } catch (err) {\n error(\"mcp\", \"new session error\", err);\n if (!res.headersSent) {\n res.status(500).json({ error: \"Internal server error\" });\n }\n }\n}\n\nfunction registerMcpEndpoint(\n app: ReturnType<typeof createMcpExpressApp>,\n serverOptions: McpAppServerOptions\n): Map<string, SessionEntry> {\n const sessionStore = new Map<string, SessionEntry>();\n\n app.all(\"/mcp\", async (req, res) => {\n const sessionId = req.headers[\"mcp-session-id\"] as string | undefined;\n\n if (sessionId) {\n const existing = sessionStore.get(sessionId);\n if (existing) {\n handleExistingSession(existing, req, res);\n return;\n }\n }\n\n await createNewSession(serverOptions, sessionStore, req, res);\n });\n\n return sessionStore;\n}\n\nfunction registerShutdownHandlers(registryBackend: RegistryBackend | null): void {\n const shutdown = () => {\n if (registryBackend) {\n registryBackend.close().catch(() => {\n /* ignore close errors on exit */\n });\n }\n process.exit(0);\n };\n process.on(\"SIGTERM\", shutdown);\n process.on(\"SIGINT\", shutdown);\n}\n\nasync function startServer(): Promise<void> {\n const { registryBackend, serverOptions } = await setupRegistryBackend();\n\n const app = createMcpExpressApp({ host: HOST });\n app.use(cors());\n\n registerMcpEndpoint(app, serverOptions);\n\n app.get(\"/health\", (_req, res) => {\n res.json({ status: \"ok\", service: \"patchwork-mcp-app-server\" });\n });\n\n app.listen(PORT, HOST, () => {\n log(\"mcp-app-server\", `MCP App Server listening on http://${HOST}:${PORT}`);\n log(\"mcp-app-server\", ` POST /mcp — MCP Streamable HTTP endpoint (stateful sessions)`);\n log(\"mcp-app-server\", ` GET /health — health check`);\n log(\"mcp-app-server\", \"\");\n log(\"mcp-app-server\", \"To expose locally via cloudflared:\");\n log(\"mcp-app-server\", ` cloudflared tunnel --url http://localhost:${PORT}`);\n });\n\n registerShutdownHandlers(registryBackend);\n}\n\nasync function startWidgetServer(): Promise<string> {\n const widgetApp = express();\n widgetApp.use(cors());\n\n const store = getWidgetStore();\n\n // Serve the MCP App shell (resource document's external script) and the shared\n // browser runtime bundle (compiles widgets in-browser). Both resolve to dist\n // whether running built (dist/server.js) or via tsx (src).\n widgetApp.use(\"/shell\", express.static(resolveShellDir()));\n widgetApp.use(\"/runtime\", express.static(resolveRuntimeDir()));\n\n // Raw widget source files — fetched by the runtime and compiled in-browser.\n widgetApp.get(\"/widget/:name/:hash/files\", async (req, res) => {\n const { name, hash } = req.params;\n try {\n const widget = await store.getWidget(name, hash);\n if (!widget) {\n res.status(404).json({ error: \"Widget not found\" });\n return;\n }\n res.json({ files: widget.files, entry: widget.entry, manifest: widget.manifest });\n } catch (err) {\n error(\"widget-server\", \"Error serving widget files:\", err);\n res.status(500).json({ error: \"Internal server error\" });\n }\n });\n\n // Convenience redirect: /widget/:name/:hash → runtime host with the widget preselected.\n widgetApp.get(\"/widget/:name/:hash\", (req, res) => {\n const { name, hash } = req.params;\n res.redirect(\n 302,\n `/runtime/?widget=${encodeURIComponent(name)}/${encodeURIComponent(hash)}`,\n );\n });\n\n widgetApp.get(\"/health\", (_req, res) => {\n res.json({ status: \"ok\", service: \"patchwork-widget-server\" });\n });\n\n // Elect the widget-host owner via the port bind. A failed bind (EADDRINUSE)\n // means another instance already owns the widget server + tunnel.\n const isOwner = await new Promise<boolean>((resolve) => {\n const httpServer = widgetApp.listen(WIDGET_PORT, HOST, () => {\n log(\"mcp-app-server\", `Widget server listening on http://${HOST}:${WIDGET_PORT}`);\n resolve(true);\n });\n httpServer.on(\"error\", (err: NodeJS.ErrnoException) => {\n if (err.code === \"EADDRINUSE\") {\n log(\n \"mcp-app-server\",\n `Widget port ${WIDGET_PORT} already owned by another instance; reusing its widget host.`,\n );\n } else {\n error(\"mcp-app-server\", \"Widget server failed to bind:\", err);\n }\n resolve(false);\n });\n });\n\n if (!isOwner) {\n // Reuse the owner's verified, published base URL so every instance hands out\n // the same live hostname instead of orphaning another (possibly dead) tunnel.\n const shared = await awaitPublishedWidgetBaseUrl();\n if (shared) {\n log(\"mcp-app-server\", `Reusing shared widget host: ${shared}`);\n return shared;\n }\n error(\n \"mcp-app-server\",\n \"Owner instance never published a base URL; falling back to localhost (widgets may not load in remote hosts).\",\n );\n return `http://localhost:${WIDGET_PORT}`;\n }\n\n // We own the widget server. Establish (and verify) the tunnel, then publish\n // the base URL for sibling instances.\n let widgetBaseUrl = `http://localhost:${WIDGET_PORT}`;\n\n if (WIDGET_TUNNEL) {\n try {\n widgetBaseUrl = await startTunnel(WIDGET_PORT);\n log(\"mcp-app-server\", `Widgets accessible at: ${widgetBaseUrl}`);\n } catch (err) {\n error(\"mcp-app-server\", \"Failed to start tunnel, using localhost:\", err);\n }\n }\n\n publishWidgetHostState(widgetBaseUrl);\n return widgetBaseUrl;\n}\n\nasync function startStdioServer(): Promise<void> {\n const { registryBackend, serverOptions } = await setupRegistryBackend();\n\n log(\"mcp-app-server\", \"Starting MCP App Server in stdio mode...\");\n\n // Start widget server and optionally tunnel\n const widgetBaseUrl = await startWidgetServer();\n\n // Create MCP server with widget base URL\n const mcpServer = createMcpAppServer({\n ...serverOptions,\n widgetBaseUrl,\n });\n const transport = new StdioServerTransport();\n\n await mcpServer.connect(transport);\n\n const shutdown = () => {\n stopTunnel();\n if (registryBackend) {\n registryBackend.close().catch(() => {});\n }\n process.exit(0);\n };\n process.on(\"SIGTERM\", shutdown);\n process.on(\"SIGINT\", shutdown);\n}\n\nasync function main(): Promise<void> {\n if (TRANSPORT === \"stdio\") {\n await startStdioServer();\n } else {\n await startServer();\n }\n}\n\nmain().catch((err: unknown) => {\n error(\"mcp-app-server\", \"Fatal startup error:\", err);\n process.exit(1);\n});\n","type LogLevel = 'debug' | 'info' | 'warn' | 'error';\n\nconst CURRENT_LEVEL: LogLevel =\n (process.env['LOG_LEVEL'] as LogLevel | undefined) ?? 'info';\n\nconst LEVEL_RANK: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n};\n\nfunction shouldLog(level: LogLevel): boolean {\n return LEVEL_RANK[level] >= LEVEL_RANK[CURRENT_LEVEL];\n}\n\nfunction formatMessage(tag: string, ...args: unknown[]): unknown[] {\n return [`[${tag}]`, ...args];\n}\n\n// All logging goes to stderr to avoid interfering with MCP stdio protocol on stdout\nexport function debug(tag: string, ...args: unknown[]): void {\n if (shouldLog('debug')) {\n console.error(...formatMessage(tag, ...args));\n }\n}\n\nexport function log(tag: string, ...args: unknown[]): void {\n if (shouldLog('info')) {\n console.error(...formatMessage(tag, ...args));\n }\n}\n\nexport function warn(tag: string, ...args: unknown[]): void {\n if (shouldLog('warn')) {\n console.error(...formatMessage(tag, ...args));\n }\n}\n\nexport function error(tag: string, ...args: unknown[]): void {\n if (shouldLog('error')) {\n console.error(...formatMessage(tag, ...args));\n }\n}\n","import { type McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { warn } from \"./logger.js\";\n\n/**\n * A single buffered event for a data stream.\n */\nexport interface StreamEvent {\n seq: number;\n data: unknown;\n timestamp: number;\n}\n\nconst RING_BUFFER_MAX = 100;\n\n/**\n * Process-level ring buffer for each named stream.\n * Shared across all sessions so any request can read from it.\n */\nconst streamBuffers = new Map<string, StreamEvent[]>();\nlet globalSeq = 0;\n\nfunction getOrCreateBuffer(stream: string): StreamEvent[] {\n let buf = streamBuffers.get(stream);\n if (!buf) {\n buf = [];\n streamBuffers.set(stream, buf);\n }\n return buf;\n}\n\n/**\n * Retrieve buffered events for a stream with sequence numbers > afterSeq.\n */\nexport function getEvents(stream: string, afterSeq: number): StreamEvent[] {\n const buf = streamBuffers.get(stream);\n if (!buf) return [];\n return buf.filter((e) => e.seq > afterSeq);\n}\n\n/**\n * Write an event into the ring buffer for a stream.\n * Evicts the oldest entry when the buffer is full.\n */\nexport function appendEvent(stream: string, data: unknown): StreamEvent {\n const buf = getOrCreateBuffer(stream);\n const event: StreamEvent = {\n seq: ++globalSeq,\n data,\n timestamp: Date.now(),\n };\n buf.push(event);\n if (buf.length > RING_BUFFER_MAX) {\n buf.shift();\n }\n return event;\n}\n\n/**\n * Per-session subscription tracking.\n * A session is keyed by the MCP session ID; its McpServer is used to send\n * `notifications/tools/list_changed` as a push signal when stream events arrive.\n */\ninterface SessionEntry {\n server: McpServer;\n streams: Set<string>;\n}\n\nconst sessions = new Map<string, SessionEntry>();\n\n/**\n * Register a live MCP session so it can receive push notifications.\n */\nexport function registerSession(sessionId: string, server: McpServer): void {\n if (!sessions.has(sessionId)) {\n sessions.set(sessionId, { server, streams: new Set() });\n }\n}\n\n/**\n * Unregister a session (e.g. on transport close or DELETE).\n */\nexport function unregisterSession(sessionId: string): void {\n sessions.delete(sessionId);\n}\n\n/**\n * Subscribe a session to a named stream.\n */\nexport function subscribeSession(sessionId: string, stream: string): void {\n const entry = sessions.get(sessionId);\n if (entry) {\n entry.streams.add(stream);\n }\n}\n\n/**\n * Unsubscribe a session from a named stream.\n */\nexport function unsubscribeSession(sessionId: string, stream: string): void {\n const entry = sessions.get(sessionId);\n if (entry) {\n entry.streams.delete(stream);\n }\n}\n\n/**\n * Push a data update to all sessions that have subscribed to `stream`.\n *\n * The event is appended to the ring buffer. Each subscribed session's McpServer\n * then sends a `notifications/tools/list_changed` notification to the host.\n * The host forwards this to the widget, which uses it as a signal to call\n * `poll_updates` and retrieve the buffered data.\n *\n * @returns The new sequence number assigned to this event.\n */\nexport async function pushStreamUpdate(\n stream: string,\n data: unknown,\n): Promise<number> {\n const event = appendEvent(stream, data);\n\n const pushPromises: Promise<void>[] = [];\n for (const [, entry] of sessions) {\n if (entry.streams.has(stream)) {\n const notifyPromise = entry.server.server\n .notification({ method: \"notifications/tools/list_changed\" })\n .catch((err: unknown) => {\n warn(\"live-update\", \"Failed to notify session:\", err);\n });\n pushPromises.push(notifyPromise);\n }\n }\n\n await Promise.all(pushPromises);\n return event.seq;\n}\n\n/**\n * Return the current highest sequence number (useful for initial subscribe).\n */\nexport function currentSeq(): number {\n return globalSeq;\n}\n\n/** Clears all buffers and sessions — for testing only. */\nexport function _resetForTests(): void {\n streamBuffers.clear();\n sessions.clear();\n globalSeq = 0;\n}\n","/**\n * Registry MCP backend for the Patchwork MCP App Server.\n *\n * Spawns (or connects to) the Aprovan Registry MCP server via stdio and bridges\n * its tools into the Patchwork ServiceBridge. Widgets can then call any Registry-\n * backed service (e.g. `github.repos_list()`, `stripe.charges_list()`) via the\n * standard Patchwork service proxy shim.\n *\n * Usage (in server.ts or programmatically):\n *\n * const backend = await createRegistryBackend({\n * command: \"npx\",\n * args: [\"@utdk/mcp\"],\n * providers: \"github,slack,stripe\",\n * });\n *\n * const bridge = new ServiceBridge({\n * backend,\n * tools: backend.getToolInfos(),\n * });\n */\n\nimport { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { StdioClientTransport } from \"@modelcontextprotocol/sdk/client/stdio.js\";\nimport { log, warn } from \"./logger.js\";\nimport type { ServiceBackend, ServiceToolInfo } from \"./services.js\";\n\n// ---------------------------------------------------------------------------\n// Minimal type alias for MCP callTool responses\n// ---------------------------------------------------------------------------\n\n/** Subset of the MCP CallToolResult used in this module. */\ninterface McpToolResult {\n isError?: boolean;\n content: Array<{ type: string; text?: string; [k: string]: unknown }>;\n}\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport interface RegistryBackendOptions {\n /** Executable to start the Registry MCP server (e.g. \"npx\" or an absolute path). */\n command: string;\n /** Arguments passed to the command (e.g. [\"@utdk/mcp\"]). */\n args?: string[];\n /**\n * Additional environment variables for the Registry process.\n * Merged on top of the current process.env, so provider credentials already\n * present in the environment are forwarded automatically.\n */\n env?: Record<string, string>;\n /**\n * Comma-separated list of `@utdk` providers to load, e.g. \"github,slack,stripe\".\n * Passed as UTDK_PROVIDERS to the Registry server.\n */\n providers: string;\n}\n\nexport interface RegistryBackend extends ServiceBackend {\n /** All service tool infos loaded from the Registry, ready for ServiceBridgeConfig. */\n getToolInfos(): ServiceToolInfo[];\n /** Close the underlying MCP client / Registry child process. */\n close(): Promise<void>;\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Split a Registry MCP tool name (e.g. \"github__repos_list\") into its\n * namespace (\"github\") and procedure (\"repos_list\") parts.\n *\n * The Registry convention is:\n * <provider>__<operation> (double underscore as separator)\n *\n * Everything before the first \"__\" is the namespace; the remainder is the\n * procedure (which may itself contain single underscores).\n */\nexport function parseRegistryToolName(mcpName: string): {\n namespace: string;\n procedure: string;\n} {\n const idx = mcpName.indexOf(\"__\");\n if (idx === -1) {\n // No separator — treat the whole name as a single-part namespace\n return { namespace: mcpName, procedure: \"call\" };\n }\n return {\n namespace: mcpName.slice(0, idx),\n procedure: mcpName.slice(idx + 2),\n };\n}\n\n/**\n * Fetch all tool metadata from the Registry via its `list_tools` / `tool_info`\n * meta-tools and convert to the `ServiceToolInfo` shape expected by ServiceBridge.\n */\nasync function loadRegistryToolInfos(client: Client): Promise<ServiceToolInfo[]> {\n // list_tools returns a flat JSON array of MCP tool names when no group_by is given.\n const listResult = (await client.callTool({\n name: \"list_tools\",\n arguments: {},\n })) as McpToolResult;\n\n const listText = listResult.content\n .filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n .map((c) => c.text)\n .join(\"\");\n\n let toolNames: unknown;\n try {\n toolNames = JSON.parse(listText);\n } catch {\n warn(\"registry-backend\", \"Failed to parse tool list response from Registry\");\n return [];\n }\n\n if (!Array.isArray(toolNames)) {\n warn(\"registry-backend\", \"Unexpected tool list format from Registry (expected array)\");\n return [];\n }\n\n const mcpNames = toolNames.filter((n): n is string => typeof n === \"string\");\n\n // Fetch full schema for each tool in parallel, chunked to avoid flooding the process.\n const CHUNK_SIZE = 20;\n const toolInfos: ServiceToolInfo[] = [];\n\n for (let i = 0; i < mcpNames.length; i += CHUNK_SIZE) {\n const chunk = mcpNames.slice(i, i + CHUNK_SIZE);\n const results = await Promise.all(\n chunk.map(async (mcpName): Promise<ServiceToolInfo | null> => {\n try {\n const infoResult = (await client.callTool({\n name: \"tool_info\",\n arguments: { tool_name: mcpName },\n })) as McpToolResult;\n\n const infoText = infoResult.content\n .filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n .map((c) => c.text)\n .join(\"\");\n\n const raw = JSON.parse(infoText) as {\n name?: string;\n description?: string;\n inputSchema?: Record<string, unknown>;\n };\n\n const { namespace, procedure } = parseRegistryToolName(mcpName);\n\n return {\n name: `${namespace}.${procedure}`,\n namespace,\n procedure,\n description: raw.description ?? `Call ${namespace}.${procedure}`,\n parameters: raw.inputSchema as Record<string, unknown> | undefined,\n };\n } catch (err) {\n warn(\"registry-backend\", `Failed to fetch tool info for '${mcpName}': ${err}`);\n return null;\n }\n }),\n );\n\n for (const info of results) {\n if (info !== null) {\n toolInfos.push(info);\n }\n }\n }\n\n const providerCount = new Set(toolInfos.map((t) => t.namespace)).size;\n log(\n \"registry-backend\",\n `Loaded ${toolInfos.length} tools from ${providerCount} provider(s)`,\n );\n\n return toolInfos;\n}\n\n// ---------------------------------------------------------------------------\n// Public factory\n// ---------------------------------------------------------------------------\n\n/**\n * Create a `RegistryBackend` that routes widget service calls through the\n * Aprovan Registry MCP server.\n *\n * The Registry server is spawned as a child process via stdio. All current\n * `process.env` variables (including provider credentials such as `GITHUB_TOKEN`)\n * are forwarded to the child process, with `UTDK_PROVIDERS` set to the given\n * providers list. Additional overrides can be passed via `options.env`.\n *\n * @example\n * ```ts\n * const backend = await createRegistryBackend({\n * command: \"npx\",\n * args: [\"@utdk/mcp\"],\n * providers: \"github,stripe\",\n * });\n *\n * const bridge = new ServiceBridge({\n * backend,\n * tools: backend.getToolInfos(),\n * });\n * ```\n */\nexport async function createRegistryBackend(\n options: RegistryBackendOptions,\n): Promise<RegistryBackend> {\n // Forward the current environment so provider API keys are available in the\n // spawned process. UTDK_PROVIDERS is the only variable that must be set here.\n const inheritedEnv: Record<string, string> = {};\n for (const [k, v] of Object.entries(process.env)) {\n if (v !== undefined) inheritedEnv[k] = v;\n }\n\n const env: Record<string, string> = {\n ...inheritedEnv,\n UTDK_PROVIDERS: options.providers,\n ...options.env,\n };\n\n const transport = new StdioClientTransport({\n command: options.command,\n args: options.args ?? [],\n env,\n // Route Registry stderr to the parent so operators can see provider logs.\n stderr: \"inherit\",\n });\n\n const client = new Client({\n name: \"patchwork-mcp-app-server\",\n version: \"0.1.0\",\n });\n\n await client.connect(transport);\n\n // Pre-load all tool metadata so ServiceBridge can be constructed synchronously.\n const toolInfos = await loadRegistryToolInfos(client);\n\n const backend: RegistryBackend = {\n /**\n * Execute a Registry-backed service tool.\n *\n * The call is forwarded as a Registry `call_tool` meta-tool invocation:\n * namespace + \"__\" + procedure → Registry MCP tool name\n *\n * The first element of `args` is treated as the tool's argument object.\n */\n async call(\n namespace: string,\n procedure: string,\n args: unknown[],\n ): Promise<unknown> {\n const toolName = `${namespace}__${procedure}`;\n const toolArgs = (typeof args[0] === \"object\" && args[0] !== null ? args[0] : {}) as Record<\n string,\n unknown\n >;\n\n const result = (await client.callTool({\n name: \"call_tool\",\n arguments: {\n tool_name: toolName,\n arguments: toolArgs,\n },\n })) as McpToolResult;\n\n if (result.isError) {\n const message = result.content\n .filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n .map((c) => c.text)\n .join(\"\\n\");\n throw new Error(message || `Registry call failed for '${toolName}'`);\n }\n\n // Return parsed JSON when the response looks like JSON, else return raw text.\n const textContent = result.content.find(\n (c): c is { type: \"text\"; text: string } => c.type === \"text\",\n );\n if (textContent) {\n try {\n return JSON.parse(textContent.text) as unknown;\n } catch {\n return textContent.text;\n }\n }\n\n return result;\n },\n\n getToolInfos(): ServiceToolInfo[] {\n return toolInfos;\n },\n\n async close(): Promise<void> {\n await client.close();\n },\n };\n\n return backend;\n}\n","import {\n createProjectFromFiles,\n createSingleFileProject,\n type Manifest,\n type VirtualFile,\n type VirtualProject,\n} from \"@aprovan/patchwork-compiler\";\nimport {\n registerAppTool,\n RESOURCE_MIME_TYPE,\n} from \"@modelcontextprotocol/ext-apps/server\";\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport {\n subscribeSession,\n unsubscribeSession as _unsubscribeSession,\n getEvents,\n pushStreamUpdate,\n currentSeq,\n type StreamEvent,\n} from \"./live-update.js\";\nimport { warn } from \"./logger.js\";\nimport {\n ServiceBridge,\n type ServiceBackend,\n type ServiceToolInfo,\n type ServiceBridgeConfig,\n} from \"./services.js\";\nimport { getWidgetStore } from \"./widget-store/index.js\";\n\nexport type { ServiceBackend, ServiceToolInfo, ServiceBridgeConfig };\nexport type { StreamEvent };\nexport { pushStreamUpdate };\n\nconst DEFAULT_WIDGET_PORT = Number(process.env[\"WIDGET_PORT\"] ?? 3002);\nconst DEFAULT_WIDGET_HOST = process.env[\"WIDGET_HOST\"] ?? \"localhost\";\nconst DEFAULT_WIDGET_BASE_URL = `http://${DEFAULT_WIDGET_HOST}:${DEFAULT_WIDGET_PORT}`;\n\ninterface WidgetRef {\n name: string;\n hash: string;\n entry: string;\n}\n\n/**\n * Generate the MCP App resource document.\n *\n * Per the MCP Apps protocol the resource document itself must be the app that\n * connects to the host, and it runs under a strict CSP with no `unsafe-eval` —\n * so esbuild-wasm cannot run here. The resource therefore loads the bundled\n * ext-apps \"shell\" (served from the widget host, allow-listed via\n * `resourceDomains`) which connects to the host and embeds the CSP-free runtime\n * iframe that actually compiles the widget. The widget + inputs are passed to\n * the shell via a base64 `data-config` attribute (no inline script → CSP-safe).\n */\nfunction generateResourceHtml(\n shellUrl: string,\n runtimeUrl: string,\n widget: WidgetRef,\n inputs: Record<string, unknown>,\n): string {\n const config = JSON.stringify({\n runtime: runtimeUrl,\n widget: `${widget.name}/${widget.hash}`,\n inputs,\n });\n const configB64 = Buffer.from(config, \"utf-8\").toString(\"base64\");\n return `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>${widget.name}</title>\n <style>\n * { margin: 0; padding: 0; box-sizing: border-box; }\n html, body { width: 100%; }\n #pw-root { width: 100%; }\n </style>\n</head>\n<body>\n <div id=\"pw-root\"></div>\n <script src=\"${shellUrl}\" data-config=\"${configB64}\"></script>\n</body>\n</html>`;\n}\n\n/** Stable, non-cryptographic content hash used as the widget store key. */\nfunction hashFiles(files: VirtualFile[], manifest: Manifest): string {\n const input = JSON.stringify({\n name: manifest.name,\n image: manifest.image,\n files: files.map((f) => [f.path, f.content]),\n });\n let hash = 0;\n for (let i = 0; i < input.length; i++) {\n hash = ((hash << 5) - hash + input.charCodeAt(i)) | 0;\n }\n return Math.abs(hash).toString(16).padStart(8, \"0\");\n}\n\nconst MANIFEST_DEFAULTS: Manifest = {\n name: \"widget\",\n version: \"0.1.0\",\n platform: \"browser\",\n image: \"@aprovan/patchwork-image-shadcn\",\n};\n\n/**\n * Build the CSP the host applies to the resource document.\n *\n * - `resourceDomains` (→ `script-src`) must allow the external shell bundle.\n * - `frameDomains` (→ `frame-src`) must allow the nested runtime iframe.\n *\n * Both live on the widget host origin, so a single allow-listed origin covers\n * them. Entries are scheme-qualified per the CSP spec.\n */\nfunction buildCspConfig(\n widgetBaseUrl: string,\n): { frameDomains: string[]; resourceDomains: string[] } | undefined {\n try {\n const url = new URL(widgetBaseUrl);\n // Use the exact origin (scheme + host + port). The shell bundle and the\n // nested runtime iframe both live on this single origin, so one entry covers\n // script-src (resourceDomains) and frame-src (frameDomains). Hosts enforce\n // the resource CSP strictly and drop broad wildcard hosts like\n // `https://*.trycloudflare.com`, which would leave script-src without the\n // shell origin and block the bootstrap script — so never wildcard.\n const origin = url.port\n ? `${url.protocol}//${url.hostname}:${url.port}`\n : `${url.protocol}//${url.hostname}`;\n return { frameDomains: [origin], resourceDomains: [origin] };\n } catch {\n return undefined;\n }\n}\n\nfunction buildManifest(input?: Record<string, unknown>): Manifest {\n return {\n name: (input?.[\"name\"] as string) ?? MANIFEST_DEFAULTS.name,\n version: (input?.[\"version\"] as string) ?? MANIFEST_DEFAULTS.version,\n platform: \"browser\",\n image: (input?.[\"image\"] as string) ?? MANIFEST_DEFAULTS.image,\n services: input?.[\"services\"] as string[] | undefined,\n };\n}\n\nconst DEFAULT_WIDGET_SOURCE =\n \"export default function Widget() { return <div>Hello Patchwork</div>; }\";\n\nfunction buildProject(\n name: string,\n source?: string,\n files?: Array<{ path: string; content: string }>,\n entry?: string\n): VirtualProject {\n if (files && files.length > 0) {\n const virtualFiles: VirtualFile[] = files.map((f) => ({\n path: f.path,\n content: f.content,\n }));\n const project = createProjectFromFiles(virtualFiles, name);\n if (entry) project.entry = entry;\n return project;\n }\n return createSingleFileProject(source ?? DEFAULT_WIDGET_SOURCE, entry ?? \"main.tsx\", name);\n}\n\nexport interface McpAppServerOptions {\n services?: ServiceBridgeConfig;\n /** Base URL for serving widgets (e.g., tunnel URL). Defaults to localhost:3002. */\n widgetBaseUrl?: string;\n}\n\nexport function createMcpAppServer(options: McpAppServerOptions = {}): McpServer {\n const server = new McpServer({\n name: \"patchwork-mcp-app-server\",\n version: \"0.1.0\",\n });\n\n const serviceBridge = options.services ? new ServiceBridge(options.services) : null;\n const widgetBaseUrl = options.widgetBaseUrl ?? DEFAULT_WIDGET_BASE_URL;\n\n const runtimeUrl = `${widgetBaseUrl}/runtime/`;\n const shellUrl = `${widgetBaseUrl}/shell/shell.js`;\n const directUrl = (name: string, hash: string): string =>\n `${runtimeUrl}?widget=${encodeURIComponent(name)}/${encodeURIComponent(hash)}`;\n\n const store = getWidgetStore();\n\n /** Build the MCP App resource document that renders a stored widget. */\n const renderResource = (ref: WidgetRef, inputs: Record<string, unknown>) => {\n const csp = buildCspConfig(widgetBaseUrl);\n return {\n type: \"resource\" as const,\n resource: {\n uri: store.resourceUriFor(ref.name, ref.hash),\n mimeType: RESOURCE_MIME_TYPE,\n text: generateResourceHtml(shellUrl, runtimeUrl, ref, inputs),\n ...(csp ? { _meta: { ui: { csp } } } : {}),\n },\n };\n };\n\n registerAppTool(\n server,\n \"save_widget\",\n {\n description:\n \"Save a JSX/TSX widget's raw source files for reuse and render it as an MCP App resource. \" +\n \"Pass source code for a single-file widget, or a files array for a multi-file project. \" +\n \"The widget is stored uncompiled and compiled in the browser by the shared Patchwork \" +\n \"runtime when rendered — pass `inputs` to supply startup props to the widget.\",\n inputSchema: {\n source: z\n .string()\n .optional()\n .describe(\n \"JSX/TSX source code for a single-file widget. Must export a default React component.\"\n ),\n files: z\n .array(\n z.object({\n path: z.string().describe(\"File path relative to project root (e.g. 'main.tsx')\"),\n content: z.string().describe(\"File contents\"),\n })\n )\n .optional()\n .describe(\n \"Array of files for a multi-file widget project. At least one file should be the entry point (main.tsx or index.tsx).\"\n ),\n entry: z\n .string()\n .optional()\n .describe(\"Entry point file path. Defaults to auto-detection (main.tsx, index.tsx).\"),\n name: z.string().optional().describe(\"Widget name for the manifest. Defaults to 'widget'.\"),\n image: z\n .string()\n .optional()\n .describe(\n \"Patchwork image package to use. Defaults to '@aprovan/patchwork-image-shadcn'.\"\n ),\n services: z\n .array(z.string())\n .optional()\n .describe(\n \"Service namespaces the widget calls (e.g., ['weather', 'stripe']). \" +\n \"A proxy shim is injected so widget code can call namespace.procedure(args) directly.\"\n ),\n inputs: z\n .record(z.unknown())\n .optional()\n .describe(\"Startup props passed to the widget's default export when it is rendered.\"),\n },\n _meta: {\n ui: { resourceUri: \"ui://widgets/{name}/{hash}/view.html\" },\n },\n },\n async (args) => {\n const source = args?.[\"source\"] as string | undefined;\n const files = args?.[\"files\"] as Array<{ path: string; content: string }> | undefined;\n const entry = args?.[\"entry\"] as string | undefined;\n const requestedServices = args?.[\"services\"] as string[] | undefined;\n const inputs = (args?.[\"inputs\"] as Record<string, unknown> | undefined) ?? {};\n\n const manifestInput: Record<string, unknown> = {};\n if (args?.[\"name\"]) manifestInput[\"name\"] = args[\"name\"];\n if (args?.[\"image\"]) manifestInput[\"image\"] = args[\"image\"];\n\n // Validate requested services against the connected backend.\n let services = requestedServices ?? [];\n if (services.length > 0 && serviceBridge) {\n const availableNamespaces = serviceBridge.getNamespaces();\n const unavailable = services.filter((ns) => !availableNamespaces.includes(ns));\n if (unavailable.length > 0) {\n warn(\n \"mcp-app-server\",\n `Requested services not available: ${unavailable.join(\", \")}. Available: ${availableNamespaces.join(\", \")}`\n );\n }\n services = services.filter((ns) => availableNamespaces.includes(ns));\n }\n if (services.length > 0) manifestInput[\"services\"] = services;\n\n const manifest = buildManifest(manifestInput);\n const project = buildProject(manifest.name, source, files, entry);\n const projectFiles = Array.from(project.files.values());\n\n try {\n const hash = hashFiles(projectFiles, manifest);\n await store.saveWidget(hash, projectFiles, manifest, project.entry);\n\n const ref: WidgetRef = { name: manifest.name, hash, entry: project.entry };\n\n return {\n content: [\n renderResource(ref, inputs),\n {\n type: \"text\" as const,\n text:\n `Widget \"${manifest.name}\" saved. Hash: ${hash}\\n` +\n `Compiled in-browser at: ${directUrl(manifest.name, hash)}`,\n },\n ],\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return {\n content: [\n {\n type: \"text\" as const,\n text: `Failed to save widget: ${message}`,\n },\n ],\n isError: true,\n };\n }\n }\n );\n\n if (serviceBridge) {\n // Register search_services and call_service tools only (not individual service tools)\n // This avoids exposing hundreds of tools with names that may exceed 64 chars\n serviceBridge.registerSearchServices(server);\n }\n\n registerAppTool(\n server,\n \"list_widgets\",\n {\n description:\n \"List all persisted widgets in the VFS widget store. \" +\n \"Returns each widget's name, version, description, path, and resource URI.\",\n _meta: { ui: { resourceUri: \"ui://widgets/list\" } },\n },\n async () => {\n const widgets = await store.listWidgets();\n\n if (widgets.length === 0) {\n return {\n content: [\n {\n type: \"text\" as const,\n text: \"No widgets stored in the VFS widget store.\",\n },\n ],\n };\n }\n\n const lines = widgets.map((w) => {\n const parts = [`- **${w.name}** (v${w.version})`];\n if (w.description) parts.push(` ${w.description}`);\n parts.push(` Path: ${w.path}`);\n parts.push(` URI: ${w.resourceUri}`);\n if (w.entry) parts.push(` Entry: ${w.entry}`);\n if (w.services && w.services.length > 0) parts.push(` Services: ${w.services.join(\", \")}`);\n return parts.join(\"\\n\");\n });\n\n return {\n content: [\n {\n type: \"text\" as const,\n text: `Stored widgets (${widgets.length}):\\n\\n${lines.join(\"\\n\\n\")}`,\n },\n ],\n };\n }\n );\n\n registerAppTool(\n server,\n \"render_widget\",\n {\n description:\n \"Render a persisted widget by its name and hash. \" +\n \"Serves the saved widget as an MCP App resource that compiles in the browser, \" +\n \"optionally supplying startup props via `inputs`.\",\n inputSchema: {\n name: z.string().describe(\"Widget name (as stored in the VFS widget store).\"),\n hash: z\n .string()\n .optional()\n .describe(\n \"Widget content hash. If omitted, renders the most recent version of the named widget.\"\n ),\n inputs: z\n .record(z.unknown())\n .optional()\n .describe(\"Startup props passed to the widget's default export when it is rendered.\"),\n },\n _meta: {\n ui: { resourceUri: \"ui://widgets/{name}/{hash}/view.html\" },\n },\n },\n async (args) => {\n const name = args?.[\"name\"] as string;\n const hashInput = args?.[\"hash\"] as string | undefined;\n const inputs = (args?.[\"inputs\"] as Record<string, unknown> | undefined) ?? {};\n\n if (!name) {\n return {\n content: [\n {\n type: \"text\" as const,\n text: \"Widget name is required.\",\n },\n ],\n isError: true,\n };\n }\n\n let hash = hashInput;\n if (!hash) {\n const widgets = await store.listWidgets();\n const match = widgets.find((w) => w.name === name);\n if (!match) {\n return {\n content: [\n {\n type: \"text\" as const,\n text: `No stored widget found with name \"${name}\".`,\n },\n ],\n isError: true,\n };\n }\n const resourcePath = match.resourceUri\n .replace(\"ui://widgets/\", \"\")\n .replace(\"/view.html\", \"\");\n const parts = resourcePath.split(\"/\");\n hash = parts[1] ?? parts[0] ?? \"\";\n }\n\n if (!hash) {\n return {\n content: [\n {\n type: \"text\" as const,\n text: `Could not determine hash for widget \"${name}\".`,\n },\n ],\n isError: true,\n };\n }\n\n const widget = await store.getWidget(name, hash);\n if (!widget) {\n return {\n content: [\n {\n type: \"text\" as const,\n text: `Widget \"${name}\" with hash \"${hash}\" not found in the VFS store.`,\n },\n ],\n isError: true,\n };\n }\n\n const ref: WidgetRef = { name, hash, entry: widget.entry };\n\n return {\n content: [\n renderResource(ref, inputs),\n {\n type: \"text\" as const,\n text: `Rendered widget \"${name}\" (hash: ${hash}).\\nCompiled in-browser at: ${directUrl(name, hash)}`,\n },\n ],\n };\n }\n );\n\n registerLiveUpdateTools(server);\n\n return server;\n}\n\nexport { WidgetStore, getWidgetStore, resetWidgetStore } from \"./widget-store/index.js\";\nexport type { StoredWidget, StoredWidgetInfo, WidgetStoreOptions } from \"./widget-store/types.js\";\n\n// ---------------------------------------------------------------------------\n// Live-update tools\n// ---------------------------------------------------------------------------\n\n/**\n * Register the three tools that power the live-update channel:\n *\n * - `subscribe_stream` — widget declares interest in a named data stream.\n * - `poll_updates` — widget fetches buffered events since a given seq.\n * - `push_update` — backend/LLM pushes new data onto a stream.\n *\n * The session ID is extracted from the MCP request's `_meta` extra or from the\n * internal `RequestHandlerExtra`. Tools that need the session ID use the\n * `extra.meta?.sessionId` field that the SDK populates from the transport.\n */\nfunction registerLiveUpdateTools(server: McpServer): void {\n // subscribe_stream — widget registers interest in a named data stream.\n server.registerTool(\n \"subscribe_stream\",\n {\n description:\n \"Subscribe this widget session to a named data stream. \" +\n \"The server will send `notifications/tools/list_changed` whenever new \" +\n \"events arrive; the widget should then call `poll_updates` to fetch them. \" +\n \"Returns the current sequence number so the widget knows where to start polling.\",\n inputSchema: {\n stream: z.string().describe(\"Name of the data stream to subscribe to.\"),\n session_id: z\n .string()\n .optional()\n .describe(\n \"MCP session ID. Widgets should pass the value returned in the \" +\n \"Mcp-Session-Id response header during initialization.\"\n ),\n },\n },\n (args, extra) => {\n const stream = (args as Record<string, unknown>)[\"stream\"] as string;\n // Prefer an explicit session_id arg; fall back to the transport session\n const sessionId =\n ((args as Record<string, unknown>)[\"session_id\"] as string | undefined) ??\n ((extra as Record<string, unknown>)[\"sessionId\"] as string | undefined);\n\n if (sessionId) {\n subscribeSession(sessionId, stream);\n }\n\n const seq = currentSeq();\n return {\n content: [\n {\n type: \"text\" as const,\n text: JSON.stringify({ success: true, stream, seq }),\n },\n ],\n };\n }\n );\n\n // poll_updates — returns buffered events for a stream since afterSeq.\n server.registerTool(\n \"poll_updates\",\n {\n description:\n \"Fetch buffered events for a data stream that arrived after the given \" +\n \"sequence number. Call this after receiving a `notifications/tools/list_changed` \" +\n \"notification (which the server sends when new data is available). \" +\n \"Pass the highest `seq` value from the last successful poll to avoid duplicates.\",\n inputSchema: {\n stream: z.string().describe(\"Name of the data stream to poll.\"),\n after_seq: z\n .number()\n .int()\n .default(0)\n .describe(\n \"Return only events with seq > after_seq. Pass 0 to retrieve all buffered events.\"\n ),\n },\n },\n (args) => {\n const stream = (args as Record<string, unknown>)[\"stream\"] as string;\n const afterSeq = ((args as Record<string, unknown>)[\"after_seq\"] as number) ?? 0;\n\n const events = getEvents(stream, afterSeq);\n return {\n content: [\n {\n type: \"text\" as const,\n text: JSON.stringify({ success: true, stream, events }),\n },\n ],\n };\n }\n );\n\n // push_update — backend or LLM pushes new data onto a stream.\n server.registerTool(\n \"push_update\",\n {\n description:\n \"Push a data update onto a named stream, broadcasting it to all \" +\n \"subscribed widget sessions. Subscribing widgets will receive a \" +\n \"`notifications/tools/list_changed` signal and then call `poll_updates` \" +\n \"to retrieve the new data. Use this tool from server-side code or as an \" +\n \"LLM tool to drive real-time widget updates.\",\n inputSchema: {\n stream: z.string().describe(\"Name of the data stream to push to.\"),\n data: z\n .record(z.unknown())\n .describe(\"Arbitrary JSON-serialisable payload to push to subscribers.\"),\n },\n },\n async (args) => {\n const stream = (args as Record<string, unknown>)[\"stream\"] as string;\n const data = (args as Record<string, unknown>)[\"data\"];\n\n const seq = await pushStreamUpdate(stream, data);\n return {\n content: [\n {\n type: \"text\" as const,\n text: JSON.stringify({ success: true, stream, seq }),\n },\n ],\n };\n }\n );\n}\n","import { type McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\n\nexport interface ServiceBackend {\n call(namespace: string, procedure: string, args: unknown[]): Promise<unknown>;\n}\n\nexport interface ServiceToolInfo {\n name: string;\n namespace: string;\n procedure: string;\n description?: string;\n parameters?: Record<string, unknown>;\n}\n\nexport interface ServiceBridgeConfig {\n backend: ServiceBackend;\n tools: ServiceToolInfo[];\n}\n\nconst TOOL_SEPARATOR = \"__\";\n\nfunction toMcpToolName(namespace: string, procedure: string): string {\n return `${namespace}${TOOL_SEPARATOR}${procedure}`;\n}\n\nfunction jsonSchemaToZodShape(schema?: Record<string, unknown>): Record<string, z.ZodTypeAny> {\n const properties = (schema?.[\"properties\"] ?? {}) as Record<\n string,\n { type?: string; description?: string }\n >;\n const required = new Set((schema?.[\"required\"] ?? []) as string[]);\n\n const shape: Record<string, z.ZodTypeAny> = {};\n for (const [key, prop] of Object.entries(properties)) {\n let field: z.ZodTypeAny;\n switch (prop.type) {\n case \"number\":\n case \"integer\":\n field = z.number();\n break;\n case \"boolean\":\n field = z.boolean();\n break;\n case \"array\":\n field = z.array(z.unknown());\n break;\n case \"object\":\n field = z.record(z.unknown());\n break;\n default:\n field = z.string();\n break;\n }\n if (prop.description) {\n field = field.describe(prop.description);\n }\n if (!required.has(key)) {\n field = field.optional();\n }\n shape[key] = field;\n }\n\n return shape;\n}\n\nexport class ServiceBridge {\n private backend: ServiceBackend;\n private tools: Map<string, ServiceToolInfo> = new Map();\n\n constructor(config: ServiceBridgeConfig) {\n this.backend = config.backend;\n for (const tool of config.tools) {\n this.tools.set(tool.name, tool);\n }\n }\n\n registerTools(server: McpServer): void {\n for (const [, info] of this.tools) {\n const mcpToolName = toMcpToolName(info.namespace, info.procedure);\n const inputShape = jsonSchemaToZodShape(info.parameters);\n\n server.registerTool(\n mcpToolName,\n {\n description: info.description ?? `Call ${info.namespace}.${info.procedure}`,\n inputSchema: inputShape,\n },\n async (args) => {\n try {\n const result = await this.backend.call(info.namespace, info.procedure, [args ?? {}]);\n return {\n content: [\n {\n type: \"text\" as const,\n text: typeof result === \"string\" ? result : JSON.stringify(result),\n },\n ],\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return {\n content: [\n {\n type: \"text\" as const,\n text: `Service call failed: ${message}`,\n },\n ],\n isError: true,\n };\n }\n }\n );\n }\n }\n\n registerSearchServices(server: McpServer): void {\n server.registerTool(\n \"search_services\",\n {\n description:\n \"Search for available service tools that widgets can call. \" +\n \"Returns matching services with their namespaces, procedures, and parameter schemas.\",\n inputSchema: {\n query: z\n .string()\n .optional()\n .describe(\n 'Natural language description of what you want to do (e.g., \"get weather forecast\")'\n ),\n namespace: z\n .string()\n .optional()\n .describe('Filter results to a specific service namespace (e.g., \"weather\")'),\n tool_name: z\n .string()\n .optional()\n .describe(\"Get detailed info about a specific tool by name\"),\n limit: z.number().optional().describe(\"Maximum number of results to return\"),\n },\n },\n async (args) => {\n const query = args?.[\"query\"] as string | undefined;\n const namespace = args?.[\"namespace\"] as string | undefined;\n const toolName = args?.[\"tool_name\"] as string | undefined;\n const limit = (args?.[\"limit\"] as number) ?? 10;\n\n if (toolName) {\n const dotName = toolName.replace(/__/g, \".\");\n const info = this.tools.get(toolName) ?? this.tools.get(dotName);\n if (!info) {\n return {\n content: [\n {\n type: \"text\" as const,\n text: JSON.stringify({\n success: false,\n error: `Tool '${toolName}' not found`,\n }),\n },\n ],\n };\n }\n return {\n content: [\n {\n type: \"text\" as const,\n text: JSON.stringify({ success: true, tool: info }),\n },\n ],\n };\n }\n\n let results = Array.from(this.tools.values());\n\n if (namespace) {\n results = results.filter((info) => info.namespace === namespace);\n }\n\n if (query) {\n const queryLower = query.toLowerCase();\n const keywords = queryLower.split(/\\s+/).filter(Boolean);\n results = results\n .map((info) => {\n const searchText =\n `${info.name} ${info.namespace} ${info.procedure} ${info.description ?? \"\"}`.toLowerCase();\n const matchCount = keywords.filter((kw) => searchText.includes(kw)).length;\n return { info, score: matchCount / keywords.length };\n })\n .filter(({ score }) => score > 0)\n .sort((a, b) => b.score - a.score)\n .map(({ info }) => info);\n }\n\n results = results.slice(0, limit);\n\n return {\n content: [\n {\n type: \"text\" as const,\n text: JSON.stringify({\n success: true,\n count: results.length,\n tools: results,\n namespaces: this.getNamespaces(),\n }),\n },\n ],\n };\n }\n );\n\n // call_service: Execute any service by namespace/procedure\n server.registerTool(\n \"call_service\",\n {\n description:\n \"Call a service tool by namespace and procedure. Use search_services to discover available tools first.\",\n inputSchema: {\n namespace: z.string().describe('Service namespace (e.g., \"github\", \"stripe\")'),\n procedure: z.string().describe('Procedure name (e.g., \"repos_list\", \"customers_create\")'),\n args: z.record(z.unknown()).optional().describe(\"Arguments to pass to the procedure\"),\n },\n },\n async (params) => {\n const namespace = params?.[\"namespace\"] as string;\n const procedure = params?.[\"procedure\"] as string;\n const args = (params?.[\"args\"] ?? {}) as Record<string, unknown>;\n\n if (!namespace || !procedure) {\n return {\n content: [\n {\n type: \"text\" as const,\n text: JSON.stringify({\n success: false,\n error: \"namespace and procedure are required\",\n }),\n },\n ],\n isError: true,\n };\n }\n\n // Look up tool info for validation\n const toolKey = `${namespace}.${procedure}`;\n const info = this.tools.get(toolKey);\n if (!info) {\n return {\n content: [\n {\n type: \"text\" as const,\n text: JSON.stringify({\n success: false,\n error: `Tool '${namespace}.${procedure}' not found. Use search_services to discover available tools.`,\n }),\n },\n ],\n isError: true,\n };\n }\n\n try {\n const result = await this.backend.call(namespace, procedure, [args]);\n return {\n content: [\n {\n type: \"text\" as const,\n text: typeof result === \"string\" ? result : JSON.stringify(result),\n },\n ],\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return {\n content: [\n {\n type: \"text\" as const,\n text: JSON.stringify({\n success: false,\n error: `Service call failed: ${message}`,\n }),\n },\n ],\n isError: true,\n };\n }\n }\n );\n }\n\n getNamespaces(): string[] {\n const namespaces = new Set<string>();\n for (const info of this.tools.values()) {\n namespaces.add(info.namespace);\n }\n return Array.from(namespaces);\n }\n\n getToolInfos(): ServiceToolInfo[] {\n return Array.from(this.tools.values());\n }\n\n has(namespace: string, procedure: string): boolean {\n return this.tools.has(`${namespace}.${procedure}`);\n }\n}\n","import { join, resolve } from \"node:path\";\nimport { homedir } from \"node:os\";\nimport { LocalFileBackend } from \"./local-backend.js\";\nimport type { FSProvider, StoredWidget, StoredWidgetInfo, WidgetStoreOptions } from \"./types.js\";\nimport type { Manifest, VirtualFile } from \"@aprovan/patchwork-compiler\";\n\nconst WIDGETS_PREFIX = \"widgets\";\nconst FILES_SUBDIR = \"files\";\nconst RESOURCE_URI_PREFIX = \"ui://widgets/\";\n\nfunction getDefaultStorageDir(): string {\n // Use WIDGET_STORE_PATH env var, or fall back to ~/.patchwork/widget-store\n return process.env[\"WIDGET_STORE_PATH\"] ?? join(homedir(), \".patchwork\", \"widget-store\");\n}\n\ninterface StoredManifest extends Manifest {\n entry: string;\n createdAt: number;\n}\n\n/**\n * Persistent store for **raw, uncompiled** widget source files.\n *\n * Widgets are saved as their original `.tsx`/`.ts` files plus a `manifest.json`;\n * compilation happens in the browser via the shared `@aprovan/patchwork-compiler`\n * runtime when the widget is rendered. Layout:\n *\n * ```\n * widgets/<name>/<hash>/\n * files/main.tsx\n * files/price-card.tsx\n * manifest.json { ...manifest, entry, createdAt }\n * ```\n */\nexport class WidgetStore {\n private provider: FSProvider;\n private storageDir: string;\n\n constructor(options: WidgetStoreOptions = {}) {\n this.storageDir = resolve(options.storageDir ?? getDefaultStorageDir());\n this.provider = options.backend ?? new LocalFileBackend(this.storageDir);\n }\n\n private fullPath(virtualPath: string): string {\n return join(WIDGETS_PREFIX, virtualPath);\n }\n\n private async readFilesRecursive(dir: string, base = \"\"): Promise<VirtualFile[]> {\n const files: VirtualFile[] = [];\n let entries;\n try {\n entries = await this.provider.readdir(dir);\n } catch {\n return files;\n }\n for (const entry of entries) {\n const childDir = join(dir, entry.name);\n const relPath = base ? `${base}/${entry.name}` : entry.name;\n if (entry.isDirectory()) {\n files.push(...(await this.readFilesRecursive(childDir, relPath)));\n } else {\n const content = await this.provider.readFile(childDir);\n files.push({ path: relPath, content });\n }\n }\n return files;\n }\n\n async saveWidget(\n hash: string,\n files: VirtualFile[],\n manifest: Manifest,\n entry: string,\n ): Promise<StoredWidget> {\n const widgetDir = `${manifest.name}/${hash}`;\n const createdAt = Date.now();\n\n await Promise.all(\n files.map((file) =>\n this.provider.writeFile(\n this.fullPath(`${widgetDir}/${FILES_SUBDIR}/${file.path}`),\n file.content,\n ),\n ),\n );\n\n const storedManifest: StoredManifest = { ...manifest, entry, createdAt };\n await this.provider.writeFile(\n this.fullPath(`${widgetDir}/manifest.json`),\n JSON.stringify(storedManifest),\n );\n\n return {\n path: this.fullPath(widgetDir),\n resourceUri: `${RESOURCE_URI_PREFIX}${widgetDir}/view.html`,\n files,\n entry,\n manifest,\n createdAt,\n };\n }\n\n async getWidget(name: string, hash: string): Promise<StoredWidget | null> {\n const widgetDir = `${name}/${hash}`;\n const manifestVirtualPath = this.fullPath(`${widgetDir}/manifest.json`);\n\n const exists = await this.provider.exists(manifestVirtualPath);\n if (!exists) return null;\n\n const files = await this.readFilesRecursive(this.fullPath(`${widgetDir}/${FILES_SUBDIR}`));\n\n let manifest: Manifest;\n let entry = files[0]?.path ?? \"main.tsx\";\n let createdAt = Date.now();\n try {\n const raw = await this.provider.readFile(manifestVirtualPath);\n const parsed = JSON.parse(raw) as Partial<StoredManifest>;\n manifest = {\n name: (parsed.name as string) ?? name,\n version: (parsed.version as string) ?? \"0.1.0\",\n platform: parsed.platform ?? \"browser\",\n image: (parsed.image as string) ?? \"@aprovan/patchwork-image-shadcn\",\n description: parsed.description,\n services: parsed.services,\n };\n if (parsed.entry) entry = parsed.entry;\n if (typeof parsed.createdAt === \"number\") createdAt = parsed.createdAt;\n } catch {\n manifest = {\n name,\n version: \"0.1.0\",\n platform: \"browser\",\n image: \"@aprovan/patchwork-image-shadcn\",\n };\n }\n\n return {\n path: this.fullPath(widgetDir),\n resourceUri: `${RESOURCE_URI_PREFIX}${widgetDir}/view.html`,\n files,\n entry,\n manifest,\n createdAt,\n };\n }\n\n async listWidgets(): Promise<StoredWidgetInfo[]> {\n const results: StoredWidgetInfo[] = [];\n const rootPath = this.fullPath(\"\");\n\n try {\n const names = await this.provider.readdir(rootPath);\n for (const nameEntry of names) {\n if (!nameEntry.isDirectory()) continue;\n const name = nameEntry.name;\n\n try {\n const hashes = await this.provider.readdir(join(rootPath, name));\n for (const hashEntry of hashes) {\n if (!hashEntry.isDirectory()) continue;\n const hash = hashEntry.name;\n const manifestVirtualPath = this.fullPath(`${name}/${hash}/manifest.json`);\n\n let manifest: Partial<StoredManifest> = {};\n try {\n const raw = await this.provider.readFile(manifestVirtualPath);\n manifest = JSON.parse(raw) as Partial<StoredManifest>;\n } catch {\n continue;\n }\n\n results.push({\n path: this.fullPath(`${name}/${hash}`),\n resourceUri: `${RESOURCE_URI_PREFIX}${name}/${hash}/view.html`,\n name: manifest.name ?? name,\n version: manifest.version ?? \"0.1.0\",\n description: manifest.description,\n services: manifest.services,\n entry: manifest.entry,\n createdAt: manifest.createdAt ?? 0,\n });\n }\n } catch {\n continue;\n }\n }\n } catch {\n return results;\n }\n\n return results.sort((a, b) => b.createdAt - a.createdAt);\n }\n\n async deleteWidget(name: string, hash: string): Promise<boolean> {\n const widgetDir = this.fullPath(`${name}/${hash}`);\n const exists = await this.provider.exists(widgetDir);\n if (!exists) return false;\n\n await this.provider.rmdir(widgetDir, { recursive: true });\n return true;\n }\n\n async hasWidget(name: string, hash: string): Promise<boolean> {\n return this.provider.exists(this.fullPath(`${name}/${hash}/manifest.json`));\n }\n\n resourceUriFor(name: string, hash: string): string {\n return `${RESOURCE_URI_PREFIX}${name}/${hash}/view.html`;\n }\n\n async loadAll(): Promise<StoredWidget[]> {\n const infos = await this.listWidgets();\n const widgets: StoredWidget[] = [];\n\n for (const info of infos) {\n const uriPath = info.resourceUri.replace(RESOURCE_URI_PREFIX, \"\").replace(/\\/view\\.html$/, \"\");\n const parts = uriPath.split(\"/\");\n const name = parts[0];\n const hash = parts[1];\n\n if (!name || !hash) continue;\n\n const widget = await this.getWidget(name, hash);\n if (widget) widgets.push(widget);\n }\n\n return widgets;\n }\n}\n\nlet _instance: WidgetStore | null = null;\n\nexport function getWidgetStore(options?: WidgetStoreOptions): WidgetStore {\n if (!_instance) {\n _instance = new WidgetStore(options);\n }\n return _instance;\n}\n\nexport function resetWidgetStore(): void {\n _instance = null;\n}\n","import { readFile, writeFile, unlink, stat, mkdir, readdir, rm, access } from \"node:fs/promises\";\nimport { join, dirname, normalize } from \"node:path\";\nimport type { DirEntry, FileStats, FSProvider } from \"./types.js\";\n\nfunction createDirEntry(name: string, isDir: boolean): DirEntry {\n return {\n name,\n isFile: () => !isDir,\n isDirectory: () => isDir,\n };\n}\n\nfunction createFileStats(size: number, mtime: Date, isDir: boolean): FileStats {\n return {\n size,\n mtime,\n isFile: () => !isDir,\n isDirectory: () => isDir,\n };\n}\n\nexport class LocalFileBackend implements FSProvider {\n constructor(private basePath: string) {}\n\n private resolve(path: string): string {\n return join(this.basePath, normalize(path));\n }\n\n async readFile(path: string): Promise<string> {\n return readFile(this.resolve(path), \"utf-8\");\n }\n\n async writeFile(path: string, content: string): Promise<void> {\n const fullPath = this.resolve(path);\n await mkdir(dirname(fullPath), { recursive: true });\n await writeFile(fullPath, content, \"utf-8\");\n }\n\n async unlink(path: string): Promise<void> {\n await unlink(this.resolve(path));\n }\n\n async stat(path: string): Promise<FileStats> {\n const fullPath = this.resolve(path);\n const s = await stat(fullPath);\n return createFileStats(s.size, s.mtime, s.isDirectory());\n }\n\n async mkdir(path: string, options?: { recursive?: boolean }): Promise<void> {\n await mkdir(this.resolve(path), options);\n }\n\n async readdir(path: string): Promise<DirEntry[]> {\n const fullPath = this.resolve(path);\n const entries = await readdir(fullPath, { withFileTypes: true });\n return entries.map((e) =>\n createDirEntry(e.name, e.isDirectory()),\n );\n }\n\n async rmdir(path: string, options?: { recursive?: boolean }): Promise<void> {\n if (options?.recursive) {\n await rm(this.resolve(path), { recursive: true, force: true });\n } else {\n await rm(this.resolve(path), { force: true });\n }\n }\n\n async exists(path: string): Promise<boolean> {\n try {\n await access(this.resolve(path));\n return true;\n } catch {\n return false;\n }\n }\n}\n","import { spawn, type ChildProcess } from \"node:child_process\";\nimport { log, error } from \"./logger.js\";\n\nlet tunnelProcess: ChildProcess | null = null;\nlet tunnelUrl: string | null = null;\n\n/**\n * Poll the tunnel's public `/health` endpoint until it returns 200.\n *\n * cloudflared prints the `*.trycloudflare.com` URL as soon as the process\n * registers, but the edge route is frequently not live yet — requests in that\n * window return Cloudflare error 1033 (\"unable to resolve\"). Publishing the URL\n * before it's actually reachable bakes a dead host into rendered widgets, so we\n * verify reachability before adopting it.\n */\nasync function waitForTunnelLive(url: string, timeoutMs = 30000): Promise<boolean> {\n const deadline = Date.now() + timeoutMs;\n while (Date.now() < deadline) {\n try {\n const res = await fetch(`${url}/health`, { signal: AbortSignal.timeout(5000) });\n if (res.ok) return true;\n } catch {\n // not reachable yet — keep polling\n }\n await new Promise((r) => setTimeout(r, 1000));\n }\n return false;\n}\n\n/**\n * Start a cloudflare tunnel to expose a local port publicly.\n * Returns the public URL once the tunnel is established AND verified reachable.\n */\nexport async function startTunnel(port: number): Promise<string> {\n if (tunnelUrl) return tunnelUrl;\n\n const detectedUrl = await new Promise<string>((resolve, reject) => {\n const args = [\"tunnel\", \"--url\", `http://localhost:${port}`];\n\n log(\"tunnel\", `Starting cloudflared tunnel for port ${port}...`);\n\n tunnelProcess = spawn(\"cloudflared\", args, {\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n\n let resolved = false;\n const timeout = setTimeout(() => {\n if (!resolved) {\n resolved = true;\n reject(new Error(\"Tunnel startup timed out after 30s\"));\n }\n }, 30000);\n\n const handleOutput = (data: Buffer) => {\n const text = data.toString();\n\n // Look for the tunnel URL in the output\n // cloudflared outputs: \"https://xxx.trycloudflare.com\"\n const urlMatch = text.match(/https:\\/\\/[^\\s]+\\.trycloudflare\\.com\\/?/);\n if (urlMatch && !resolved) {\n resolved = true;\n clearTimeout(timeout);\n resolve(urlMatch[0].replace(/\\/$/, \"\"));\n }\n };\n\n tunnelProcess.stdout?.on(\"data\", handleOutput);\n tunnelProcess.stderr?.on(\"data\", handleOutput);\n\n tunnelProcess.on(\"error\", (err) => {\n if (!resolved) {\n resolved = true;\n clearTimeout(timeout);\n error(\"tunnel\", \"Failed to start cloudflared:\", err);\n reject(err);\n }\n });\n\n tunnelProcess.on(\"exit\", (code) => {\n if (!resolved) {\n resolved = true;\n clearTimeout(timeout);\n reject(new Error(`cloudflared exited with code ${code}`));\n }\n tunnelProcess = null;\n tunnelUrl = null;\n });\n });\n\n // Verify-then-publish: don't adopt the hostname until the edge route is live,\n // otherwise rendered widgets reference a host that returns Cloudflare 1033.\n log(\"tunnel\", `Tunnel hostname detected (${detectedUrl}); verifying reachability...`);\n const live = await waitForTunnelLive(detectedUrl);\n if (!live) {\n error(\n \"tunnel\",\n `Tunnel ${detectedUrl} did not become reachable within 30s — publishing anyway, but widgets may fail to load until the edge route propagates.`,\n );\n } else {\n log(\"tunnel\", `Tunnel verified reachable: ${detectedUrl}`);\n }\n\n tunnelUrl = detectedUrl;\n return tunnelUrl;\n}\n\n/**\n * Stop the cloudflare tunnel if running.\n */\nexport function stopTunnel(): void {\n if (tunnelProcess) {\n tunnelProcess.kill();\n tunnelProcess = null;\n tunnelUrl = null;\n }\n}\n\n/**\n * Get the current tunnel URL if available.\n */\nexport function getTunnelUrl(): string | null {\n return tunnelUrl;\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,YAAY,cAAc,qBAAqB;AACxD,SAAS,cAAc;AACvB,SAAS,QAAAA,aAAY;AACrB,SAAS,qBAAqB;AAC9B,OAAO,aAAa;AACpB,SAAS,2BAA2B;AACpC,SAAS,qCAAqC;AAC9C,SAAS,4BAA4B;AACrC,OAAO,UAAU;;;ACPjB,IAAM,gBACH,QAAQ,IAAI,WAAW,KAA8B;AAExD,IAAM,aAAuC;AAAA,EAC3C,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AACT;AAEA,SAAS,UAAU,OAA0B;AAC3C,SAAO,WAAW,KAAK,KAAK,WAAW,aAAa;AACtD;AAEA,SAAS,cAAc,QAAgB,MAA4B;AACjE,SAAO,CAAC,IAAI,GAAG,KAAK,GAAG,IAAI;AAC7B;AASO,SAAS,IAAI,QAAgB,MAAuB;AACzD,MAAI,UAAU,MAAM,GAAG;AACrB,YAAQ,MAAM,GAAG,cAAc,KAAK,GAAG,IAAI,CAAC;AAAA,EAC9C;AACF;AAEO,SAAS,KAAK,QAAgB,MAAuB;AAC1D,MAAI,UAAU,MAAM,GAAG;AACrB,YAAQ,MAAM,GAAG,cAAc,KAAK,GAAG,IAAI,CAAC;AAAA,EAC9C;AACF;AAEO,SAAS,MAAM,QAAgB,MAAuB;AAC3D,MAAI,UAAU,OAAO,GAAG;AACtB,YAAQ,MAAM,GAAG,cAAc,KAAK,GAAG,IAAI,CAAC;AAAA,EAC9C;AACF;;;AC/BA,IAAM,kBAAkB;AAMxB,IAAM,gBAAgB,oBAAI,IAA2B;AACrD,IAAI,YAAY;AAEhB,SAAS,kBAAkB,QAA+B;AACxD,MAAI,MAAM,cAAc,IAAI,MAAM;AAClC,MAAI,CAAC,KAAK;AACR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