import type { DevframeDefinition, RemoteAssets } from 'devframe' import { defineDevframe } from 'devframe' import pkg from '../../package.json' with { type: 'json' } import { setupInspect } from './setup' /** Default devframe id, driving the hosted mount path `/__/`. */ const DEFAULT_ID = 'devframes_plugin_inspect' // The Vue SPA ships in the lockstep-versioned `@devframes/plugin-inspect--assets` // package, not this slim node one. A locally installed copy (workspace link, or // an explicit install for air-gapped setups) is served with zero network via the // definition's `importMetaUrl`; otherwise assets stream through devframe's CDN. const distDir: RemoteAssets = { package: `${pkg.name}--assets`, version: pkg.version, } export interface InspectDevframeOptions { /** Override the devframe id (and default CLI command / mount path). */ id?: string /** Override the display name shown in a host dock. */ name?: string /** Override the dock icon. */ icon?: string /** * Override the mount path. Left unset, the SPA mounts at `/` standalone * and `/__/` when hosted (Vite/embedded). */ basePath?: string /** Preferred standalone CLI port. */ port?: number /** * Require the trust handshake on the standalone server. Enabled by * default; `--open` embeds the current OTP in the opened URL, so the * tab authenticates automatically without extra prompts. Hosted adapters * manage their own auth and ignore this. */ auth?: boolean } /** * Build a {@link DevframeDefinition} for the Devframe Inspector. The * same definition runs standalone (`/cli`, `/build`) and mounts * into a host (`/vite`, hub). * * @experimental This plugin is experimental and may change without a major * version bump until it stabilizes. */ export function createInspectDevframe(options: InspectDevframeOptions = {}): DevframeDefinition { const id = options.id ?? DEFAULT_ID return defineDevframe({ id, name: options.name ?? 'Devframe Inspector', version: pkg.version, packageName: pkg.name, importMetaUrl: import.meta.url, homepage: pkg.homepage, description: pkg.description, icon: options.icon ?? 'ph:stethoscope-duotone', basePath: options.basePath, clientAssets: distDir, cli: { command: id, port: options.port ?? 9012, /** * Gate the standalone server by default; `maybeOpenBrowser` folds the * current OTP into the `--open` URL so the tab lands already trusted. * Hosted adapters (Vite/hub) supply their own auth layer and ignore this. */ auth: options.auth ?? true, }, dock: { category: '~builtin', }, setup(ctx) { setupInspect(ctx) }, }) } export default createInspectDevframe export type { DevframeInspectCommandInfo, InvokeResult, RpcFunctionInfo } from './types'