import type { AgenticMcpModule, DevframeInstanceRecord, InstanceShellApi, ResolvedMcpConfig } from 'devframe/internal' import type { DevframeAuthHandler } from 'devframe/node/auth' import type { AuthBannerFunction } from 'devframe/recipes/interactive-auth' import type { WsOriginRegistry } from 'devframe/rpc/transports/ws-server' import type { ConnectionMeta, DevframeDefinition, DevframeServiceInput, DevframeSseOptions, DevframeStorageScope, DevframeWsOptions, McpRouteOptions, McpSetting } from 'devframe/types' import type { Buffer } from 'node:buffer' import type { IncomingMessage, Server as NodeHttpServer, ServerResponse } from 'node:http' import type { Duplex } from 'node:stream' import type { ClientScriptEntry } from '../types/docks' import type { CreateHubContextOptions, DevframeHubContext } from './context' import type { InstallDevframeOptions } from './install-devframe' import { readFile } from 'node:fs/promises' import process from 'node:process' import { DEVFRAME_CONNECTION_META_FILENAME, DEVFRAME_DOCK_IMPORTS_FILENAME, DEVFRAME_MCP_ROUTE } from 'devframe/constants' import { createH3DevframeHost, createInstanceShell, importAgenticMcp, loadAutoMcpAdapter, resolveInstanceRegister, resolveMcpConfig } from 'devframe/internal' import { createInteractiveAuth } from 'devframe/recipes/interactive-auth' import { mountStaticHandler } from 'devframe/utils/serve-static' import { joinURL, withoutLeadingSlash } from 'devframe/utils/url' import { H3 } from 'h3' import { resolve } from 'pathe' import { DEVFRAMES_HUB_BASE, DOCK_RENDERERS_STATE_KEY, normalizeHubBase } from '../constants' import { mountDevframes, renderClientImportsModule, resolveDevframesInput, resolveRendererRegistrations } from './assemble' import { createHubContext } from './context' import { diagnostics } from './diagnostics' /** A `devframes` entry with per-mount dock customization. */ export interface HubDevframeEntry { devframe: DevframeDefinition /** Per-mount overrides for the auto-synthesized iframe dock entry. */ dock?: InstallDevframeOptions['dock'] } type Thenable = T | Promise type Arrayable = T | readonly T[] /** Default mount base for a hub instance, re-exported from `../constants` (the client-safe home) for existing importers of this node entry. */ export { DEVFRAMES_HUB_BASE } /** Content-type for a UI asset key, inferred from its file extension. */ function assetContentType(key: string): string { if (key.endsWith('.json')) return 'application/json; charset=utf-8' if (key.endsWith('.js') || key.endsWith('.mjs')) return 'text/javascript; charset=utf-8' if (key.endsWith('.css')) return 'text/css; charset=utf-8' if (key.endsWith('.svg')) return 'image/svg+xml' if (key.endsWith('.html')) return 'text/html; charset=utf-8' return 'application/octet-stream' } /** * One dock-type → prebuilt renderer-module registration for * {@link InitHubOptions.renderers}. The hub serves the module at * `__renderers/.mjs` and publishes it in the renderer manifest * (the `devframe:dock-renderers` shared-state slot), so any viewer (the * reference UI, a community viewer, a hand-rolled host page) lazily imports * it the first time a dock of that `type` needs rendering. * * The module must be a **self-contained browser ES module** (its framework * and styles bundled in) whose {@link DockRendererRegistration.importName} * export is a ready `DockRenderer`. Renderer packages ship a node helper * returning this shape, e.g. `jsonRenderUiRenderer()` from * `@devframes/json-render-ui/hub`. */ export interface DockRendererRegistration { /** Dock `type` this renderer handles (e.g. `'json-render'`). */ type: string /** Absolute path of the prebuilt, self-contained browser ES module. */ file: string /** * Named export carrying the renderer. * * @default 'default' */ importName?: string } /** * The UI slot of a hub instance: pure data, zero policy. The hub itself is * headless: whoever fills this slot decides what a viewer looks like. * `@devframes/hub-ui` ships the reference implementation (`createUi()`); * Vite DevTools or any community viewer supplies its own object to the same * slot and reuses all the infrastructure. */ export interface DevframeHubUi { /** * A standalone viewer SPA (built with relative asset paths) served at the * hub base itself; open `` in a tab and the devtools are there. */ viewer?: { /** Directory of the prebuilt viewer SPA. */ distDir: string } /** * A prebuilt, self-contained script served at `embedded.js`: the * floating-devtools bootstrap a host page loads with one * `