theokit 0.14.0 → 0.15.1
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.
- package/dist/{actions-virtual-module-3CDQTWOC.js → actions-virtual-module-G4BANOLW.js} +5 -3
- package/dist/{actions-virtual-module-3CDQTWOC.js.map → actions-virtual-module-G4BANOLW.js.map} +1 -1
- package/dist/agent-MN7XGJR3.js +209 -0
- package/dist/agent-MN7XGJR3.js.map +1 -0
- package/dist/{app-typed-client-CSOK7NPC.js → app-typed-client-Z6BHD4MF.js} +5 -3
- package/dist/{app-typed-client-CSOK7NPC.js.map → app-typed-client-Z6BHD4MF.js.map} +1 -1
- package/dist/{build-5K7LK77K.js → build-QDAFSKKW.js} +11 -7
- package/dist/{build-5K7LK77K.js.map → build-QDAFSKKW.js.map} +1 -1
- package/dist/chunk-34YQOXGM.js +37 -0
- package/dist/chunk-34YQOXGM.js.map +1 -0
- package/dist/{chunk-7YZHAQU7.js → chunk-567NA7Y6.js} +8 -99
- package/dist/chunk-567NA7Y6.js.map +1 -0
- package/dist/{chunk-BQDGES7C.js → chunk-GBXLKYIA.js} +19 -43
- package/dist/chunk-GBXLKYIA.js.map +1 -0
- package/dist/chunk-GDN3PXFH.js +101 -0
- package/dist/chunk-GDN3PXFH.js.map +1 -0
- package/dist/chunk-NBWB4S46.js +81 -0
- package/dist/chunk-NBWB4S46.js.map +1 -0
- package/dist/{chunk-F4YUPDJ2.js → chunk-NXTF5PPW.js} +15 -41
- package/dist/chunk-NXTF5PPW.js.map +1 -0
- package/dist/{chunk-S7Y5WLZY.js → chunk-OTFIRP6S.js} +76 -46
- package/dist/chunk-OTFIRP6S.js.map +1 -0
- package/dist/chunk-P37RZRFV.js +31 -0
- package/dist/chunk-P37RZRFV.js.map +1 -0
- package/dist/{chunk-RBHCJHRR.js → chunk-UOR6JTCI.js} +142 -7
- package/dist/chunk-UOR6JTCI.js.map +1 -0
- package/dist/{chunk-637WJB7Z.js → chunk-ZJDKAD3L.js} +55 -14
- package/dist/chunk-ZJDKAD3L.js.map +1 -0
- package/dist/cli/index.js +22 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/{dev-QOEVYNBG.js → dev-TEE4T6ZB.js} +13 -8
- package/dist/{dev-QOEVYNBG.js.map → dev-TEE4T6ZB.js.map} +1 -1
- package/dist/{dev-emit-5MDSBP5D.js → dev-emit-VJ5CFMPY.js} +5 -3
- package/dist/{dev-emit-5MDSBP5D.js.map → dev-emit-VJ5CFMPY.js.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/{info-OUEUZOT7.js → info-7PE2PZJI.js} +6 -5
- package/dist/{info-OUEUZOT7.js.map → info-7PE2PZJI.js.map} +1 -1
- package/dist/{internal-api-EFKZWIYZ.js → internal-api-J27TYE2I.js} +7 -4
- package/dist/load-config-JKYO5RFK.js +14 -0
- package/dist/{openapi-FHY6HC6I.js → openapi-MXMLZCXC.js} +7 -4
- package/dist/{openapi-FHY6HC6I.js.map → openapi-MXMLZCXC.js.map} +1 -1
- package/dist/{registry-34LL7NF4.js → registry-XJUYD2OU.js} +2 -2
- package/dist/{routes-EW7TP7NJ.js → routes-NNBEZSGN.js} +5 -3
- package/dist/{routes-EW7TP7NJ.js.map → routes-NNBEZSGN.js.map} +1 -1
- package/dist/{start-2KG4JSXM.js → start-7MQEEQH4.js} +68 -8
- package/dist/start-7MQEEQH4.js.map +1 -0
- package/dist/{static-55G3LX2I.js → static-7ARBVDJF.js} +4 -4
- package/dist/vite-plugin/index.js +1 -1
- package/dist/{vite-plugin-TDIDZ5U7.js → vite-plugin-GC6WCU4P.js} +11 -7
- package/dist/vite-plugin-GC6WCU4P.js.map +1 -0
- package/package.json +2 -2
- package/dist/chunk-637WJB7Z.js.map +0 -1
- package/dist/chunk-7YZHAQU7.js.map +0 -1
- package/dist/chunk-BQDGES7C.js.map +0 -1
- package/dist/chunk-F4YUPDJ2.js.map +0 -1
- package/dist/chunk-RBHCJHRR.js.map +0 -1
- package/dist/chunk-S7Y5WLZY.js.map +0 -1
- package/dist/start-2KG4JSXM.js.map +0 -1
- /package/dist/{internal-api-EFKZWIYZ.js.map → internal-api-J27TYE2I.js.map} +0 -0
- /package/dist/{vite-plugin-TDIDZ5U7.js.map → load-config-JKYO5RFK.js.map} +0 -0
- /package/dist/{registry-34LL7NF4.js.map → registry-XJUYD2OU.js.map} +0 -0
- /package/dist/{static-55G3LX2I.js.map → static-7ARBVDJF.js.map} +0 -0
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import "tsx/esm";
|
|
3
3
|
import {
|
|
4
|
+
handleAgentApproval,
|
|
4
5
|
incomingMessageToWebRequest,
|
|
6
|
+
isApprovalPath,
|
|
5
7
|
mountAgent,
|
|
6
|
-
resolveProvider,
|
|
7
8
|
resolveTransformer,
|
|
8
9
|
writeWebResponseToServerResponse
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-OTFIRP6S.js";
|
|
11
|
+
import {
|
|
12
|
+
getApprovalRegistry,
|
|
13
|
+
resolveProvider
|
|
14
|
+
} from "./chunk-NBWB4S46.js";
|
|
15
|
+
import {
|
|
16
|
+
isRouteFile,
|
|
17
|
+
scanRoutes
|
|
18
|
+
} from "./chunk-IEES3CHD.js";
|
|
10
19
|
import {
|
|
11
20
|
loadConfig
|
|
12
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-567NA7Y6.js";
|
|
13
22
|
import {
|
|
14
23
|
buildServicesProxyConfig
|
|
15
24
|
} from "./chunk-45C3WUQ7.js";
|
|
@@ -41,17 +50,13 @@ import {
|
|
|
41
50
|
} from "./chunk-WR4F4EEZ.js";
|
|
42
51
|
import {
|
|
43
52
|
scanAgents
|
|
44
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-34YQOXGM.js";
|
|
45
54
|
import {
|
|
46
55
|
matchRoute,
|
|
47
56
|
scanServerActions,
|
|
48
57
|
scanServerRoutes,
|
|
49
58
|
scanWebSocketRoutes
|
|
50
|
-
} from "./chunk-
|
|
51
|
-
import {
|
|
52
|
-
isRouteFile,
|
|
53
|
-
scanRoutes
|
|
54
|
-
} from "./chunk-IEES3CHD.js";
|
|
59
|
+
} from "./chunk-GBXLKYIA.js";
|
|
55
60
|
|
|
56
61
|
// src/vite-plugin/index.ts
|
|
57
62
|
import { existsSync as existsSync7 } from "fs";
|
|
@@ -401,6 +406,42 @@ function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
|
|
|
401
406
|
const start = Date.now();
|
|
402
407
|
res.setHeader("x-request-id", requestId);
|
|
403
408
|
const urlPath = url.split("?")[0];
|
|
409
|
+
if (isApprovalPath(urlPath)) {
|
|
410
|
+
const method2 = (req.method ?? "POST").toUpperCase();
|
|
411
|
+
if (method2 !== "POST") {
|
|
412
|
+
sendError(
|
|
413
|
+
res,
|
|
414
|
+
"METHOD_NOT_ALLOWED",
|
|
415
|
+
"Approve endpoints accept POST",
|
|
416
|
+
405,
|
|
417
|
+
void 0,
|
|
418
|
+
requestId
|
|
419
|
+
);
|
|
420
|
+
logRequest({ method: method2, url, status: 405, duration: Date.now() - start, requestId });
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
try {
|
|
424
|
+
const request = incomingMessageToWebRequest(req);
|
|
425
|
+
const response = await handleAgentApproval(
|
|
426
|
+
request,
|
|
427
|
+
urlPath,
|
|
428
|
+
getApprovalRegistry(),
|
|
429
|
+
csrfMode
|
|
430
|
+
);
|
|
431
|
+
await writeWebResponseToServerResponse(response, res);
|
|
432
|
+
} catch (err) {
|
|
433
|
+
sendError(
|
|
434
|
+
res,
|
|
435
|
+
"INTERNAL",
|
|
436
|
+
err instanceof Error ? err.message : "Approve handler failed",
|
|
437
|
+
500,
|
|
438
|
+
void 0,
|
|
439
|
+
requestId
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
logRequest({ method: method2, url, status: res.statusCode, duration: Date.now() - start, requestId });
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
404
445
|
const agent = scanAgents(projectRoot).find((a) => a.agentPath === urlPath);
|
|
405
446
|
if (!agent) {
|
|
406
447
|
next();
|
|
@@ -815,7 +856,7 @@ async function runConfigureServer(server, ctx) {
|
|
|
815
856
|
server.watcher.on("unlink", handleRouteChange);
|
|
816
857
|
if (ctx.resolvedOpenApi !== void 0) {
|
|
817
858
|
const openApiCfg = ctx.resolvedOpenApi;
|
|
818
|
-
const { reEmitOpenApi } = await import("./dev-emit-
|
|
859
|
+
const { reEmitOpenApi } = await import("./dev-emit-VJ5CFMPY.js");
|
|
819
860
|
const openApiServerDir = resolve4(ctx.projectRoot, "server");
|
|
820
861
|
const openApiDistDir = resolve4(ctx.projectRoot, ctx.resolvedDistDir);
|
|
821
862
|
const isRouteFileForOpenApi = (file) => file.startsWith(openApiServerDir) && /\.(ts|tsx|js|mjs)$/.test(file);
|
|
@@ -1801,19 +1842,19 @@ async function theoPluginAsync(rootOrOptions) {
|
|
|
1801
1842
|
})
|
|
1802
1843
|
);
|
|
1803
1844
|
}
|
|
1804
|
-
const { appTypedClientPlugin } = await import("./app-typed-client-
|
|
1845
|
+
const { appTypedClientPlugin } = await import("./app-typed-client-Z6BHD4MF.js");
|
|
1805
1846
|
const appClientPlugin = appTypedClientPlugin({
|
|
1806
1847
|
cwd: projectRoot,
|
|
1807
1848
|
serverDir: resolve7(projectRoot, "server"),
|
|
1808
1849
|
distDir: resolve7(projectRoot, ".theokit")
|
|
1809
1850
|
});
|
|
1810
|
-
const { actionsVirtualModule } = await import("./actions-virtual-module-
|
|
1851
|
+
const { actionsVirtualModule } = await import("./actions-virtual-module-G4BANOLW.js");
|
|
1811
1852
|
const actionsPlugin = actionsVirtualModule({
|
|
1812
1853
|
serverDir: resolve7(projectRoot, "server"),
|
|
1813
1854
|
distDir: resolve7(projectRoot, ".theokit")
|
|
1814
1855
|
});
|
|
1815
1856
|
const { agentsTypedClientPlugin } = await import("./agents-typed-client-UTEQUA63.js");
|
|
1816
|
-
const { generateManifest } = await import("./internal-api-
|
|
1857
|
+
const { generateManifest } = await import("./internal-api-J27TYE2I.js");
|
|
1817
1858
|
const agentsClientPlugin = agentsTypedClientPlugin({
|
|
1818
1859
|
projectRoot,
|
|
1819
1860
|
distDir: resolve7(projectRoot, ".theokit"),
|
|
@@ -1983,4 +2024,4 @@ export {
|
|
|
1983
2024
|
theoPluginAsync,
|
|
1984
2025
|
theoPlugin
|
|
1985
2026
|
};
|
|
1986
|
-
//# sourceMappingURL=chunk-
|
|
2027
|
+
//# sourceMappingURL=chunk-ZJDKAD3L.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vite-plugin/index.ts","../src/vite-plugin/config-hook.ts","../src/vite-plugin/theoui-detect.ts","../src/vite-plugin/config-resolve.ts","../src/vite-plugin/configure-server-hook.ts","../src/devtools/server-side/route-manifest.ts","../src/vite-plugin/action-middleware.ts","../src/vite-plugin/agent-middleware.ts","../src/vite-plugin/api-middleware.ts","../src/vite-plugin/ssr-dev-middleware.ts","../src/vite-plugin/ws-upgrade.ts","../src/vite-plugin/integrate-ui.ts","../src/vite-plugin/auto-detect.ts","../src/vite-plugin/resolve-theo-root.ts","../src/vite-plugin/transform-html-hook.ts","../src/vite-plugin/inject-devtools.ts","../src/vite-plugin/inject-entry-client.ts","../src/vite-plugin/inject-stylesheets.ts","../src/router/entry-server.ts","../src/router/entry.ts","../src/router/generate.ts","../src/vite-plugin/virtual-modules-hook.ts","../src/vite-plugin/integrations.ts"],"sourcesContent":["/* eslint-disable security/detect-non-literal-fs-filename --\n * Vite plugin entry. Reads `package.json` + checks for ts vs js source\n * layout under `theoSrcDir` (build-time literal). No HTTP input.\n */\nimport { existsSync } from 'node:fs'\nimport { resolve, dirname } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nimport type { Plugin } from 'vite'\n\nimport {\n type AuditLogger,\n type CorsConfig,\n type CsrfReadinessStore,\n type DisallowedConfig,\n type PluginRunner,\n type RateLimitConfig,\n type SecurityHeadersConfig,\n} from '../server/internal-api.js'\nimport type { TheoTransformer } from '../server/transformer.js'\nimport { type ServicesConfig } from '../services/index.js'\n\n// T2.1-T2.3 (architecture-medium-deferrals) + T2.6 (M6) — sibling extractions.\nimport { runConfigHook } from './config-hook.js'\nimport { resolvePluginConfig, type ResolvedOpenApi } from './config-resolve.js'\nimport { runConfigureServer } from './configure-server-hook.js'\nimport { integrateUseTheoUI } from './integrate-ui.js'\nimport { resolveTheoRootDir } from './resolve-theo-root.js'\nimport type { TheoUiDetectResult } from './theoui-detect.js'\nimport { runTransformIndexHtml } from './transform-html-hook.js'\nimport {\n loadVirtualModule,\n resolveVirtualModuleId,\n type VirtualModuleIds,\n} from './virtual-modules-hook.js'\n\nexport {\n defineTheoIntegration,\n createIntegrationRegistry,\n IntegrationRouteCollisionError,\n IntegrationVirtualModulePrefixError,\n} from './integrations.js'\nexport type {\n TheoIntegration,\n HookName as IntegrationHookName,\n Hook as IntegrationHook,\n HookContext as IntegrationHookContext,\n IntegrationRegistry,\n IntegrationRegistryOptions,\n IntegrationRoute,\n RouteHandler as IntegrationRouteHandler,\n} from './integrations.js'\n\nconst VIRTUAL_ENTRY_ID = '/@theo/entry-client'\nconst RESOLVED_ENTRY_ID = '\\0@theo/entry-client'\nconst VIRTUAL_MANIFEST_ID = '/@theo/route-manifest'\nconst RESOLVED_MANIFEST_ID = '\\0@theo/route-manifest'\nconst VIRTUAL_ENTRY_SERVER_ID = '/@theo/entry-server'\nconst RESOLVED_ENTRY_SERVER_ID = '\\0@theo/entry-server'\nconst VIRTUAL_RUNTIME_CONFIG_ID = '/@theo/runtime-config'\nconst RESOLVED_RUNTIME_CONFIG_ID = '\\0@theo/runtime-config'\n\nexport interface TheoPluginOptions {\n root?: string\n rateLimit?: RateLimitConfig\n ssr?: boolean\n ssrStreaming?: boolean\n /**\n * Wave 2 (T3.1) — polyglot services config. When passed, the\n * services-typed-client plugin is wired and generates `clients/<name>.ts`\n * per service with an OpenAPI URL. Empty `{}` → no-op.\n */\n services?: ServicesConfig\n /**\n * T4.1 (canvas-ecosystem-refactor / ADR D6) — extra package names appended\n * to Vite `optimizeDeps.include`. Required when an installed plugin\n * peer-dep is consumed via a literal `import('<pkg>')` (dynamic specifier)\n * — Vite cannot trace those without a hint, and the browser receives a\n * `Failed to resolve module specifier '<pkg>'` error.\n *\n * Default targets pre-bundled regardless: `@theokit/ui`, `lucide-react`.\n *\n * Example:\n * viteOptimizeDeps: ['mermaid']\n */\n viteOptimizeDeps?: string[]\n /**\n * Optional override for the in-memory CSRF readiness store consumed by\n * the `/__theo/csrf-readiness` endpoint and the devtools CSRF Readiness\n * tab. When omitted, the plugin auto-instantiates a default in-process\n * `CsrfReadinessStore` so the tab works out-of-the-box in dev.\n *\n * Override with a custom impl when you need cross-worker telemetry\n * (e.g., Redis-backed store) or want to silence the tab entirely\n * (pass an inert store that discards writes).\n */\n csrfReadinessStore?: CsrfReadinessStore\n}\n\n/**\n * T3.3 — Find a consumer-side config file (`tailwind.config.*`, `postcss.config.*`)\n * by walking from projectRoot up to 3 levels. Returns the absolute path on the\n * first hit, or `undefined`. Used to defer to consumer's manual config (D3).\n */\nfunction findConsumerConfig(projectRoot: string, basename: string): string | undefined {\n const extensions = ['.ts', '.js', '.mjs', '.cjs']\n let dir = projectRoot\n for (let level = 0; level < 3; level++) {\n for (const ext of extensions) {\n const candidate = resolve(dir, `${basename}${ext}`)\n if (existsSync(candidate)) return candidate\n }\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n return undefined\n}\n\n/**\n * Async factory companion. Returns `[theoPlugin, ...autoChainedPlugins]`.\n *\n * Why this exists alongside the sync `theoPlugin()` factory: Vite does NOT\n * reliably merge plugins returned from a child plugin's `config()` hook\n * (verified empirically 2026-05-23 — plugins were silently dropped from\n * the resolved chain despite being returned correctly). The canonical\n * Vite pattern for plugin-from-plugin is to return `Plugin[]` from the\n * plugin factory itself, which Vite flattens into the consumer's\n * `plugins` array.\n *\n * Consumers should prefer `await theoPluginAsync(...)` over `theoPlugin(...)`\n * when they want @theokit/ui + @tailwindcss/vite auto-chaining. The sync\n * factory remains for backward compatibility and tests.\n */\nexport async function theoPluginAsync(\n rootOrOptions?: string | TheoPluginOptions,\n): Promise<Plugin[]> {\n const options =\n typeof rootOrOptions === 'string' ? { root: rootOrOptions } : (rootOrOptions ?? {})\n const projectRoot = options.root ?? process.cwd()\n\n const consumerTailwindConfig = findConsumerConfig(projectRoot, 'tailwind.config')\n const consumerPostcssConfig = findConsumerConfig(projectRoot, 'postcss.config')\n const uiPlugins = await integrateUseTheoUI(projectRoot, {\n consumerTailwindConfig,\n consumerPostcssConfig,\n })\n\n // Wave 2 (T3.1) — typed-client plugin wired only when services declared.\n // Empty `services: {}` (default) → plugin is a no-op (no fetch fired).\n const servicesPlugins: Plugin[] = []\n if (options.services && Object.keys(options.services).length > 0) {\n const { servicesTypedClientPlugin } = await import('./services-typed-client.js')\n servicesPlugins.push(\n servicesTypedClientPlugin({\n cwd: projectRoot,\n services: options.services,\n }),\n )\n }\n\n // G1 — app typed client (`@theo/client`). Always wired (route detection is\n // cheap and the plugin is a no-op when `server/routes/` is absent).\n const { appTypedClientPlugin } = await import('./app-typed-client.js')\n const appClientPlugin = appTypedClientPlugin({\n cwd: projectRoot,\n serverDir: resolve(projectRoot, 'server'),\n distDir: resolve(projectRoot, '.theokit'),\n })\n\n // G3 — actions virtual module (`@theo/actions`). Always wired; the plugin\n // emits an empty `{}` facade when `server/actions/` is absent so consumers\n // can still `import { actions } from '@theo/actions'` without breakage.\n // The `distDir` opt enables `.theokit/actions.d.ts` emit so TS resolves the\n // virtual module ambient declaration in consumer apps.\n const { actionsVirtualModule } = await import('./actions-virtual-module.js')\n const actionsPlugin = actionsVirtualModule({\n serverDir: resolve(projectRoot, 'server'),\n distDir: resolve(projectRoot, '.theokit'),\n })\n\n // M2 — agents typed client (`@theo/agents`). Emits `.theokit/agents.d.ts` mapping each\n // top-level `agents/<name>.ts` to its `defineAgent({ input })` type, so `useAgent('name')`\n // is typed end-to-end with zero manual wiring. Watches `agents/*`.\n const { agentsTypedClientPlugin } = await import('./agents-typed-client.js')\n const { generateManifest } = await import('../server/internal-api.js')\n const agentsClientPlugin = agentsTypedClientPlugin({\n projectRoot,\n distDir: resolve(projectRoot, '.theokit'),\n // Agents live at <projectRoot>/agents; generateManifest scans them via the server dir's\n // parent, which is projectRoot for the canonical layout.\n scanManifest: () => generateManifest(resolve(projectRoot, 'server'), projectRoot),\n })\n\n // G6 T1.2 — server-routes HMR. Watches `<serverDir>/routes/**` and\n // invalidates SSR module cache + sends full-reload on any add/change/unlink\n // with a 50 ms debounce per EC-6.\n const { serverRoutesHmrPlugin } = await import('./server-routes-hmr.js')\n const routesHmrPlugin = serverRoutesHmrPlugin({\n serverDir: resolve(projectRoot, 'server'),\n })\n\n return [\n theoPlugin(rootOrOptions),\n ...uiPlugins,\n ...servicesPlugins,\n appClientPlugin,\n actionsPlugin,\n agentsClientPlugin,\n routesHmrPlugin,\n ]\n}\n\n/**\n * Build the `optimizeDeps.include` array Vite uses to pre-bundle heavy\n * deps at server startup. Detects `@theokit/ui` and `lucide-react` in\n * the consumer's `node_modules` (auto-include) and appends user-declared\n * peer deps via `viteOptimizeDeps` (e.g., `mermaid` for plugin-canvas\n * — without this hint Vite fails to resolve dynamic `import('mermaid')`\n * inside an installed plugin at dev time). T4.1 of canvas-ecosystem-refactor.\n */\nfunction buildOptimizeDepsInclude(\n projectRoot: string,\n viteOptimizeDeps: readonly string[] | undefined,\n): string[] {\n const include: string[] = []\n if (existsSync(resolve(projectRoot, 'node_modules', '@theokit', 'ui'))) {\n include.push('@theokit/ui')\n }\n if (existsSync(resolve(projectRoot, 'node_modules', 'lucide-react'))) {\n include.push('lucide-react')\n }\n // T7.1 — devalue is a peer of the @theo/actions virtual module facade.\n // Without this include hint, Vite import-analysis fails to resolve the\n // facade's `await import('devalue')` from the consumer context (devalue\n // lives in theokit's node_modules subtree, not the consumer root).\n include.push('devalue')\n if (Array.isArray(viteOptimizeDeps)) {\n for (const pkg of viteOptimizeDeps) {\n if (typeof pkg === 'string' && pkg.length > 0 && !include.includes(pkg)) {\n include.push(pkg)\n }\n }\n }\n return include\n}\n\nconst VIRTUAL_MODULE_IDS: VirtualModuleIds = {\n VIRTUAL_ENTRY_ID,\n RESOLVED_ENTRY_ID,\n VIRTUAL_MANIFEST_ID,\n RESOLVED_MANIFEST_ID,\n VIRTUAL_ENTRY_SERVER_ID,\n RESOLVED_ENTRY_SERVER_ID,\n VIRTUAL_RUNTIME_CONFIG_ID,\n RESOLVED_RUNTIME_CONFIG_ID,\n}\n\nexport function theoPlugin(rootOrOptions?: string | TheoPluginOptions): Plugin {\n const options =\n typeof rootOrOptions === 'string' ? { root: rootOrOptions } : (rootOrOptions ?? {})\n const projectRoot = options.root ?? process.cwd()\n const appDir = resolve(projectRoot, 'app')\n const ssrEnabled = options.ssr ?? false\n\n // Resolve paths for SSR module loading. Pure helper extracted for T1.3\n // regression test — see resolve-theo-root.ts for branch documentation.\n const currentDir = dirname(fileURLToPath(import.meta.url))\n const theoSrcDir = resolveTheoRootDir(currentDir)\n\n // EC-1: plugin runner cached in module closure. Instantiated in configResolved\n // (non-HMR-able). theo.config.ts edits during dev emit a warn but do NOT\n // re-instantiate — user must restart dev server for plugin changes.\n let pluginRunner: PluginRunner | undefined\n let transformer: TheoTransformer | undefined\n let resolvedBatching: { max?: number } | undefined\n let theoUi: TheoUiDetectResult | undefined\n let csrfMode: 'off' | 'warn' | 'strict' = 'strict'\n let securityHeaders: SecurityHeadersConfig | undefined\n let disallowed: DisallowedConfig | undefined\n // T1.2 — CORS config resolved from theo.config.ts; passed to api-middleware.\n let cors: CorsConfig | undefined\n // T4.1 — Audit logger from theo.config.ts.audit.logger\n let auditLogger: AuditLogger | undefined\n // T1.2 — devtools opt-out. `false` skips injection; anything else enables (dev only).\n let devtoolsEnabled = true\n // P#3 T1.1 — OpenAPI dev-emit config. undefined = opt-out (no behavior).\n let resolvedOpenApi: ResolvedOpenApi | undefined\n let resolvedDistDir = '.theokit'\n // Dev mode flag set in configureServer. transformIndexHtml runs in both\n // dev and build; we only want to inject during dev. Wrapped in a ref\n // struct so sub-hooks (configure-server-hook, transform-html-hook) can\n // observe mutations across hook boundaries without losing identity.\n const isDevModeRef = { value: false }\n let configLoadedOnce = false\n\n return {\n name: 'theo',\n\n async configResolved() {\n // T2.1 (architecture-medium-deferrals, ADR D2) — config-load logic\n // extracted to `config-resolve.ts`. This hook owns only the one-shot\n // semantic and the closure-variable assignment.\n if (configLoadedOnce) return\n configLoadedOnce = true\n const resolved = await resolvePluginConfig(projectRoot)\n pluginRunner = resolved.pluginRunner\n transformer = resolved.transformer\n resolvedBatching = resolved.resolvedBatching\n theoUi = resolved.theoUi\n csrfMode = resolved.csrfMode\n securityHeaders = resolved.securityHeaders\n disallowed = resolved.disallowed\n cors = resolved.cors\n auditLogger = resolved.auditLogger\n devtoolsEnabled = resolved.devtoolsEnabled\n resolvedOpenApi = resolved.openapi\n resolvedDistDir = resolved.distDir\n },\n\n // T2.6 (M6) — config() body extracted to config-hook.ts. The hook\n // owns optimizeDeps + warmup + services proxy + alias cascade.\n // The @theokit/ui + @tailwindcss/vite auto-chain lives in\n // `theoPluginAsync` because Vite drops plugins returned from a\n // child plugin's config() hook.\n config() {\n return runConfigHook({\n projectRoot,\n theoSrcDir,\n services: options.services,\n optimizeDepsInclude: buildOptimizeDepsInclude(projectRoot, options.viteOptimizeDeps),\n })\n },\n\n // T2.6 (M6) — transformIndexHtml hook extracted to transform-html-hook.ts.\n // Preserves the canonical 3-step order (entry-client → devtools → styles)\n // so EC-10 (Vite hook ordering side effects) is honored.\n transformIndexHtml: {\n order: 'pre' as const,\n handler(html: string): string {\n return runTransformIndexHtml(html, {\n isDevMode: isDevModeRef,\n devtoolsEnabled,\n projectRoot,\n })\n },\n },\n\n // T2.6 (M6) — virtual-module resolveId + load dispatch extracted to\n // virtual-modules-hook.ts. Pure structural split; identity branches\n // preserved.\n resolveId(id: string) {\n return resolveVirtualModuleId(id, VIRTUAL_MODULE_IDS)\n },\n\n load(id: string) {\n return loadVirtualModule(id, {\n ids: VIRTUAL_MODULE_IDS,\n appDir,\n ssrEnabled,\n streamingEnabled: options.ssrStreaming === true,\n theoUi,\n transformer,\n })\n },\n\n // T2.6 (M6) — configureServer body extracted to configure-server-hook.ts.\n // The hook owns middleware order, ws subscriptions, watcher handlers,\n // OpenAPI re-emit, and WS upgrade. EC-10 honored (every effect preserved\n // in its original ordering).\n async configureServer(server) {\n await runConfigureServer(server, {\n projectRoot,\n appDir,\n resolvedDistDir,\n ssrEnabled,\n isDevMode: isDevModeRef,\n pluginRunner,\n transformer,\n resolvedBatching,\n csrfMode,\n securityHeaders,\n disallowed,\n cors,\n auditLogger,\n resolvedOpenApi,\n services: options.services,\n rateLimit: options.rateLimit,\n csrfReadinessStoreOverride: options.csrfReadinessStore,\n virtualEntryServerId: VIRTUAL_ENTRY_SERVER_ID,\n resolvedManifestId: RESOLVED_MANIFEST_ID,\n })\n },\n }\n}\n","/* eslint-disable security/detect-non-literal-fs-filename --\n * config() hook extraction (T2.6 / M6). Reads `app/<file>` candidates +\n * theoSrcDir composition (build-time literals).\n */\nimport { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport { buildServicesProxyConfig, type ServicesConfig } from '../services/index.js'\n\nexport interface ConfigHookCtx {\n projectRoot: string\n theoSrcDir: string\n services: ServicesConfig | undefined\n optimizeDepsInclude: string[]\n}\n\n/**\n * Builds the partial Vite config returned from `theoPlugin.config()`.\n * Pure extraction — `optimizeDeps.force: true` (workspace iteration\n * coherence), `server.watch.ignored` (ENOSPC prevention), and the\n * `resolve.alias` cascade with order-matters comment all preserved.\n */\nexport function runConfigHook(ctx: ConfigHookCtx): Record<string, unknown> {\n // Detect whether we're running from source (.ts) or compiled dist (.js)\n const ext = existsSync(resolve(ctx.theoSrcDir, 'index.ts')) ? '.ts' : '.js'\n\n // Perf: warm up the app's critical-path files so Vite transforms them\n // before the browser asks. Cuts the visible LCP when these files\n // import heavy barrels (TheoUI).\n const warmupClientFiles: string[] = []\n for (const candidate of ['app/layout.tsx', 'app/page.tsx', 'app/page.jsx']) {\n const full = resolve(ctx.projectRoot, candidate)\n if (existsSync(full)) warmupClientFiles.push(`./${candidate}`)\n }\n\n // Wave 2 completion T1.1 — translate `services: {}` into Vite proxy.\n // Empty services → empty record → Vite proxy unaffected.\n const servicesProxy =\n ctx.services && Object.keys(ctx.services).length > 0\n ? buildServicesProxyConfig(ctx.services)\n : undefined\n\n // T7.1 dogfood fix — workspace-linked packages change frequently as\n // we iterate. Vite's pre-bundler caches by lockfile hash, NOT source-\n // content hash; when the workspace dist updates but the lockfile\n // doesn't, the cache serves stale bundles. Setting `force: true`\n // always re-optimizes on boot — slower cold-start but cache-coherent\n // across workspace iter.\n return {\n envPrefix: 'THEO_PUBLIC_',\n optimizeDeps: {\n ...(ctx.optimizeDepsInclude.length > 0 ? { include: ctx.optimizeDepsInclude } : {}),\n force: true,\n },\n server: {\n ...(warmupClientFiles.length > 0 ? { warmup: { clientFiles: warmupClientFiles } } : {}),\n ...(servicesProxy !== undefined ? { proxy: servicesProxy } : {}),\n // Skip watching gitignored heavy dirs to avoid hitting ENOSPC\n // (inotify watcher exhaustion).\n watch: {\n ignored: [\n '**/referencias/**',\n '**/.theokit/**',\n '**/.theokit/**',\n '**/dist/**',\n '**/node_modules/**',\n ],\n },\n },\n resolve: {\n alias: [\n // Order matters: most-specific first so `theokit/X` doesn't\n // get matched by the bare `theokit` alias.\n { find: 'theokit/server', replacement: resolve(ctx.theoSrcDir, `server/index${ext}`) },\n { find: 'theokit/client', replacement: resolve(ctx.theoSrcDir, `client/index${ext}`) },\n {\n // T2.1 (M5 lonely folders) moved the source from\n // `react-query/index.ts` into `client/react-query.ts` (sibling of\n // `client/index.ts`). The package.json export `./react-query`\n // still points at the build artifact `./dist/react-query/index.{js,d.ts}`,\n // but the dev-time source alias must follow the new location.\n find: 'theokit/react-query',\n replacement: resolve(ctx.theoSrcDir, `client/react-query${ext}`),\n },\n {\n find: 'theokit/vite-plugin',\n replacement: resolve(ctx.theoSrcDir, `vite-plugin/index${ext}`),\n },\n {\n find: 'theokit/adapters/web-shim',\n replacement: resolve(ctx.theoSrcDir, `adapters/web-shim${ext}`),\n },\n {\n find: 'theokit/adapters/ws-shim',\n replacement: resolve(ctx.theoSrcDir, `adapters/ws-shim${ext}`),\n },\n // T1.2 — devtools entry (DEV only; tree-shaken in build).\n // Source layout: src/devtools/dom/entry.tsx (has /dom/ segment)\n // Dist layout: dist/devtools/entry.js (tsup flattens /dom/)\n {\n find: 'theokit/devtools/entry',\n replacement: resolve(\n ctx.theoSrcDir,\n ext === '.ts' ? 'devtools/dom/entry.tsx' : 'devtools/entry.js',\n ),\n },\n { find: 'theokit', replacement: resolve(ctx.theoSrcDir, `index${ext}`) },\n ],\n },\n }\n}\n","/**\n * T2.1 — Detect `@theokit/ui` presence in the user's project.\n *\n * Uses `require.resolve` with explicit `paths` instead of `existsSync` so\n * pnpm-hoist layouts (TheoUI at workspace root, app in `apps/<x>/`) still\n * detect correctly. Returns `{ enabled: false }` on any failure — never throws.\n */\n\n/* eslint-disable security/detect-non-literal-fs-filename --\n * Reads `package.json` of `@theokit/ui` via filesystem walk under `node_modules`.\n * Paths come from a controlled CLI/config inputs; this is a build-time tool.\n *\n * D13 invariant (ADR 0021): @theokit/ui is ESM-only by design (`type: \"module\"`,\n * exports['.'] sem `require` condition). Não usar `createRequire(...).resolve()` —\n * `ERR_PACKAGE_PATH_NOT_EXPORTED` em runtime. Usar filesystem walk direto.\n */\nimport { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\n\nexport type TheoUiTheme = 'violet-forge' | 'noir' | 'paper'\nexport type TheoUiFonts = 'bundled' | 'cdn'\n\nexport interface TheoUiConfig {\n theme: TheoUiTheme\n fonts: TheoUiFonts\n}\n\nexport interface TheoUiDetectResult {\n enabled: boolean\n config: TheoUiConfig\n}\n\n/**\n * Raw user config shape (from theo.config.ts > ui field).\n * `false` = opt-out (force disabled); object = explicit config; undefined = default.\n */\nexport type RawTheoUiConfig = false | undefined | { theme?: TheoUiTheme; fonts?: TheoUiFonts }\n\n/**\n * Resolve the TheoUI config with defaults applied.\n * `false` → returns disabled defaults (caller checks `enabled`).\n */\nexport function resolveTheoUiConfig(\n raw: { theme?: TheoUiTheme; fonts?: TheoUiFonts } | undefined,\n): TheoUiConfig {\n return {\n theme: raw?.theme ?? 'violet-forge',\n fonts: raw?.fonts ?? 'bundled',\n }\n}\n\n/**\n * Detect whether `@theokit/ui` is installed under `projectRoot` (or any\n * parent dir via Node module resolution — handles pnpm hoist).\n *\n * EC-1: uses `require.resolve` with `paths: [projectRoot]` not `existsSync`.\n * EC-5: corrupted installs (dir without an importable entry) fall through to disabled.\n * EC-9: theme validation happens in the Zod schema, not here.\n *\n * Note: we resolve a known subpath (`./styles.css`) instead of `./package.json`\n * or the root specifier because (a) `@theokit/ui` declares `exports` with no\n * CJS entry, so `require.resolve('@theokit/ui')` fails inside CJS contexts,\n * and (b) `./package.json` is not listed in `exports`. The `styles.css`\n * subpath IS exported and is exactly what entry-client imports — if it\n * resolves, the package is installed and usable.\n */\n/** Resolver fn — abstracted so tests can stub Node's walk-up behavior. */\nexport type SubpathResolver = (specifier: string, projectRoot: string) => boolean\n\n/**\n * D13 invariant: substituir `require.resolve` por filesystem walk que LÊ exports.\n *\n * Specifier shape: `<pkgScope>/<pkgName>/<subpath>` (e.g. `@theokit/ui/styles.css`)\n * OR `<pkgName>/<subpath>` (e.g. `react/jsx-runtime`).\n *\n * Algoritmo:\n * 1. Walk up node_modules a partir de projectRoot (handle pnpm hoist + workspaces).\n * 2. Em cada candidato, ler package.json + resolver subpath via exports field.\n * 3. Se exports mapeia o subpath, checar existsSync no path mapeado.\n *\n * Mimica resolução ESM Node sem usar createRequire (D13).\n */\nfunction resolveExportSubpath(pkgRoot: string, subpath: string): string | null {\n const pkgJsonPath = join(pkgRoot, 'package.json')\n if (!existsSync(pkgJsonPath)) return null\n try {\n const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf-8')) as {\n exports?: Record<string, unknown>\n }\n const exportKey = `./${subpath}`\n const exp = pkg.exports?.[exportKey]\n if (!exp) {\n // Fallback: tentar path direto (dist/<subpath> é convenção comum)\n const fallback = join(pkgRoot, 'dist', subpath)\n return existsSync(fallback) ? fallback : null\n }\n // exports value: string OR { import, require, default, types, ... }\n let target: string | undefined\n if (typeof exp === 'string') target = exp\n else if (typeof exp === 'object') {\n const e = exp as { import?: string; default?: string }\n target = e.import ?? e.default\n }\n if (!target) return null\n const cleaned = target.replace(/^\\.\\//, '')\n const candidate = join(pkgRoot, cleaned)\n return existsSync(candidate) ? candidate : null\n } catch {\n return null\n }\n}\n\nconst defaultResolver: SubpathResolver = (specifier, projectRoot) => {\n const parts = specifier.split('/')\n const pkgName =\n parts[0]?.startsWith('@') && parts.length >= 2 ? `${parts[0]}/${parts[1]}` : parts[0]\n if (!pkgName) return false\n const subpath = specifier.slice(pkgName.length + 1)\n if (!subpath) return false\n // Walk up node_modules (handle pnpm hoist)\n let dir = projectRoot\n for (let depth = 0; depth < 10; depth++) {\n const pkgRoot = join(dir, 'node_modules', ...pkgName.split('/'))\n if (existsSync(pkgRoot)) {\n const resolved = resolveExportSubpath(pkgRoot, subpath)\n if (resolved) return true\n }\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n return false\n}\n\n/** Reads `<projectRoot>/package.json` and returns whether `@theokit/ui`\n * is declared as a (dev)dependency. Conservative gate: pnpm hoist still\n * works because pnpm rewrites the consumer's package.json to include the\n * declared dep, even when the install lives at the workspace root. */\nfunction isDeclaredInPackageJson(projectRoot: string): boolean {\n try {\n const raw = readFileSync(join(projectRoot, 'package.json'), 'utf-8')\n const pkg = JSON.parse(raw) as {\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n peerDependencies?: Record<string, string>\n }\n // `||` is intentional — any truthy version string (including '0.0.0')\n // counts as a declaration. `??` would let '' fall through, but version\n // strings are never empty.\n return Boolean(\n pkg.dependencies?.['@theokit/ui'] ??\n pkg.devDependencies?.['@theokit/ui'] ??\n pkg.peerDependencies?.['@theokit/ui'],\n )\n } catch {\n return false\n }\n}\n\nexport function detectTheoUi(\n projectRoot: string,\n rawConfig: RawTheoUiConfig,\n resolver: SubpathResolver = defaultResolver,\n): TheoUiDetectResult {\n const config = resolveTheoUiConfig(typeof rawConfig === 'object' ? rawConfig : undefined)\n\n // Explicit opt-out wins over detection\n if (rawConfig === false) {\n return { enabled: false, config }\n }\n\n // **Conservative gate** — require the dep to be DECLARED in the user's\n // package.json. Stops the monorepo workspace from being detected as\n // having TheoUI inside fixtures that never asked for it (and would\n // 500 on the import).\n if (!isDeclaredInPackageJson(projectRoot)) {\n return { enabled: false, config }\n }\n\n // EC-1 + EC-5: prefer a subpath that's guaranteed to be in `exports`.\n // Try several known subpaths; success on any one means the package is usable.\n const probes = ['@theokit/ui/styles.css', '@theokit/ui/fonts.css']\n for (const probe of probes) {\n if (resolver(probe, projectRoot)) {\n return { enabled: true, config }\n }\n }\n return { enabled: false, config }\n}\n","/**\n * T2.1 (architecture-medium-deferrals plan, ADR D2) — `configResolved` hook\n * body extracted from `vite-plugin/index.ts` for SRP.\n *\n * `resolvePluginConfig(projectRoot)` reads `theo.config.ts` and returns a\n * `ResolvedPluginConfig` bag with every field the Vite plugin needs at\n * `configResolved` time. The `configLoadedOnce` flag stays in `index.ts`\n * (caller owns the one-shot semantic).\n *\n * Errors during config load are swallowed silently (matches pre-refactor\n * behavior — config errors are surfaced elsewhere via validate-structure).\n */\n\nimport { loadConfig } from '../config/load-config.js'\nimport {\n createPluginRunnerFromConfig,\n type AuditLogger,\n type CorsConfig,\n type DisallowedConfig,\n type PluginRunner,\n type SecurityHeadersConfig,\n} from '../server/internal-api.js'\nimport { resolveTransformer, type TheoTransformer } from '../server/transformer.js'\n\nimport { detectTheoUi, type TheoUiDetectResult } from './theoui-detect.js'\n\nexport interface ResolvedOpenApi {\n servers: { url: string; description?: string }[]\n specVersion: '3.1.0' | '3.0.3'\n title: string\n version: string\n}\n\nexport interface ResolvedPluginConfig {\n pluginRunner: PluginRunner | undefined\n transformer: TheoTransformer | undefined\n resolvedBatching: { max?: number } | undefined\n theoUi: TheoUiDetectResult | undefined\n csrfMode: 'off' | 'warn' | 'strict'\n securityHeaders: SecurityHeadersConfig | undefined\n disallowed: DisallowedConfig | undefined\n cors: CorsConfig | undefined\n auditLogger: AuditLogger | undefined\n devtoolsEnabled: boolean\n // P#3 T1.1 — undefined when config.openapi opt-out; otherwise validated config block\n openapi: ResolvedOpenApi | undefined\n // P#3 T1.1 — distDir resolved relative to projectRoot for openapi-emit output\n distDir: string\n}\n\n/**\n * Default config when load fails — keeps the plugin running with safe defaults.\n */\nconst DEFAULT_RESOLVED: ResolvedPluginConfig = {\n pluginRunner: undefined,\n transformer: undefined,\n resolvedBatching: undefined,\n theoUi: undefined,\n csrfMode: 'strict',\n securityHeaders: undefined,\n disallowed: undefined,\n cors: undefined,\n auditLogger: undefined,\n devtoolsEnabled: true,\n openapi: undefined,\n distDir: '.theokit',\n}\n\nexport async function resolvePluginConfig(projectRoot: string): Promise<ResolvedPluginConfig> {\n try {\n const userConfig = await loadConfig(projectRoot)\n const pluginRunner = await createPluginRunnerFromConfig(userConfig.plugins)\n const transformer = resolveTransformer(userConfig.serialization)\n\n // Batching: Zod admits `boolean | { max?: number }`; normalize to object.\n let resolvedBatching: { max?: number } | undefined\n if (userConfig.batching === true) {\n resolvedBatching = {}\n } else if (typeof userConfig.batching === 'object') {\n resolvedBatching = userConfig.batching\n }\n\n const theoUi = detectTheoUi(projectRoot, userConfig.ui)\n\n // Audit logger — duck-type validation (consumer may pass any shape with `log()`).\n let auditLogger: AuditLogger | undefined\n const maybeLogger = (userConfig as { audit?: { logger?: unknown } }).audit?.logger\n if (maybeLogger && typeof (maybeLogger as { log?: unknown }).log === 'function') {\n auditLogger = maybeLogger as AuditLogger\n }\n\n return {\n pluginRunner,\n transformer,\n resolvedBatching,\n theoUi,\n csrfMode: userConfig.security?.csrf ?? 'strict',\n securityHeaders: userConfig.security?.headers,\n disallowed: userConfig.security?.disallowed,\n cors: userConfig.security?.cors,\n auditLogger,\n devtoolsEnabled: userConfig.devtools !== false,\n openapi: userConfig.openapi,\n distDir: userConfig.distDir,\n }\n } catch {\n // Config load errors are surfaced elsewhere (validate-structure).\n // Return safe defaults so middlewares can run without hooks.\n return DEFAULT_RESOLVED\n }\n}\n","import { resolve, basename } from 'node:path'\n\nimport type { ViteDevServer } from 'vite'\n\nimport { broadcastRouteManifest } from '../devtools/server-side/route-manifest.js'\nimport { scanRoutes } from '../router/scan.js'\nimport { isRouteFile } from '../router/types.js'\nimport {\n CsrfReadinessStore,\n type AuditLogger,\n type CorsConfig,\n type DisallowedConfig,\n type PluginRunner,\n type RateLimitConfig,\n type SecurityHeadersConfig,\n} from '../server/internal-api.js'\nimport type { TheoTransformer } from '../server/transformer.js'\nimport type { ServicesConfig } from '../services/index.js'\n\nimport { createActionMiddleware } from './action-middleware.js'\nimport { createAgentMiddleware } from './agent-middleware.js'\nimport { createApiMiddleware } from './api-middleware.js'\nimport type { ResolvedOpenApi } from './config-resolve.js'\nimport { setupSsrDevMiddleware } from './ssr-dev-middleware.js'\nimport { setupWsUpgrade } from './ws-upgrade.js'\n\n/**\n * Inputs assembled by `theoPlugin` from its closure variables + the\n * resolvedOpenApi from `config-resolve.ts`. Kept as a struct so the\n * extraction is a pure pass-through with no behavior change.\n */\nexport interface ConfigureServerCtx {\n projectRoot: string\n appDir: string\n resolvedDistDir: string\n ssrEnabled: boolean\n isDevMode: { value: boolean }\n pluginRunner: PluginRunner | undefined\n transformer: TheoTransformer | undefined\n resolvedBatching: { max?: number } | undefined\n csrfMode: 'off' | 'warn' | 'strict'\n securityHeaders: SecurityHeadersConfig | undefined\n disallowed: DisallowedConfig | undefined\n cors: CorsConfig | undefined\n auditLogger: AuditLogger | undefined\n resolvedOpenApi: ResolvedOpenApi | undefined\n services: ServicesConfig | undefined\n rateLimit: RateLimitConfig | undefined\n csrfReadinessStoreOverride: CsrfReadinessStore | undefined\n virtualEntryServerId: string\n resolvedManifestId: string\n}\n\n/**\n * Runs the body of Vite's `configureServer` hook. Pure extraction —\n * preserves invocation order of every server.watcher event, middleware\n * registration, and ws hook so EC-10 (Vite hook ordering side effects)\n * is honored.\n */\n\nexport async function runConfigureServer(\n server: ViteDevServer,\n ctx: ConfigureServerCtx,\n): Promise<void> {\n // T1.2 — mark dev mode so transformIndexHtml injects devtools script\n // and resolveId/load serve the virtual module. Build mode never calls\n // configureServer, so isDevMode stays false and injection is skipped.\n ctx.isDevMode.value = true\n\n // T2.4 — expose dev server WS to server-side broadcast helper\n ;(globalThis as { __theoViteHotServer?: typeof server }).__theoViteHotServer = server\n\n // T3.1 — re-broadcast the route manifest when the devtools bridge asks.\n server.ws.on('theo:devtools:request-manifest', () => {\n try {\n const tree = scanRoutes(ctx.appDir)\n broadcastRouteManifest(tree)\n } catch {\n /* fail silently — dev-only convenience */\n }\n })\n\n // Server middleware (action before API — more specific prefix first)\n const serverDir = resolve(ctx.projectRoot, 'server')\n server.middlewares.use(\n createActionMiddleware(server, serverDir, {\n pluginRunner: ctx.pluginRunner,\n csrfMode: ctx.csrfMode,\n disallowed: ctx.disallowed,\n }),\n )\n // M2 — agent convention (`/api/agents/<name>`) before the generic api-middleware\n // (mirrors the action prefix). Agents live at <projectRoot>/agents (LOCKED naming).\n // CSRF is enforced in `mountAgent` (shared dev+prod point) at the same mode as routes.\n server.middlewares.use(createAgentMiddleware(server, ctx.projectRoot, ctx.csrfMode))\n // Wave 2 completion — services-proxy prefixes flow through to the\n // api-middleware so it can call `next()` for paths that should be\n // forwarded to a sidecar by Vite's proxyMiddleware.\n const servicesProxyPrefixes =\n ctx.services && Object.keys(ctx.services).length > 0\n ? Object.values(ctx.services).map((s) => s.proxy)\n : []\n // Auto-instantiate a dev-only CsrfReadinessStore so the devtools\n // CSRF Readiness tab works out-of-the-box.\n const csrfReadinessStore = ctx.csrfReadinessStoreOverride ?? new CsrfReadinessStore()\n server.middlewares.use(\n createApiMiddleware(server, serverDir, {\n rateLimitConfig: ctx.rateLimit,\n pluginRunner: ctx.pluginRunner,\n batching: ctx.resolvedBatching,\n transformer: ctx.transformer,\n csrfMode: ctx.csrfMode,\n securityHeaders: ctx.securityHeaders,\n disallowed: ctx.disallowed,\n cors: ctx.cors,\n auditLogger: ctx.auditLogger,\n servicesProxyPrefixes,\n csrfReadinessStore,\n }),\n )\n\n // EC-1: warn if theo.config.ts is edited during dev session.\n const configPath = resolve(ctx.projectRoot, 'theo.config.ts')\n server.watcher.on('change', (file) => {\n if (file === configPath) {\n console.warn(\n '\\n[theokit] theo.config.ts changed; restart dev server for plugin changes to take effect\\n',\n )\n }\n })\n\n // T2.2 (architecture-medium-deferrals) — SSR dev middleware extracted.\n if (ctx.ssrEnabled) {\n setupSsrDevMiddleware(server, {\n projectRoot: ctx.projectRoot,\n virtualEntryServerId: ctx.virtualEntryServerId,\n securityHeaders: ctx.securityHeaders,\n })\n }\n\n // Frontend HMR watcher\n function handleRouteChange(filePath: string): void {\n if (!isRouteFile(basename(filePath))) return\n if (!filePath.startsWith(ctx.appDir)) return\n\n const mod = server.moduleGraph.getModuleById(ctx.resolvedManifestId)\n if (mod) {\n server.moduleGraph.invalidateModule(mod)\n server.ws.send({ type: 'full-reload' })\n }\n }\n\n server.watcher.on('add', handleRouteChange)\n server.watcher.on('unlink', handleRouteChange)\n\n // P#3 T1.1 — Dev-mode OpenAPI emit. Gated on config.openapi !== undefined.\n if (ctx.resolvedOpenApi !== undefined) {\n const openApiCfg = ctx.resolvedOpenApi\n const { reEmitOpenApi } = await import('./openapi-emit/dev-emit.js')\n const openApiServerDir = resolve(ctx.projectRoot, 'server')\n const openApiDistDir = resolve(ctx.projectRoot, ctx.resolvedDistDir)\n const isRouteFileForOpenApi = (file: string): boolean =>\n file.startsWith(openApiServerDir) && /\\.(ts|tsx|js|mjs)$/.test(file)\n // Boot emit (fire-and-forget — boot doesn't await)\n void reEmitOpenApi(openApiServerDir, openApiDistDir, openApiCfg)\n // Watcher emit\n server.watcher.on('change', (file: string) => {\n if (isRouteFileForOpenApi(file)) {\n void reEmitOpenApi(openApiServerDir, openApiDistDir, openApiCfg)\n }\n })\n server.watcher.on('add', (file: string) => {\n if (isRouteFileForOpenApi(file)) {\n void reEmitOpenApi(openApiServerDir, openApiDistDir, openApiCfg)\n }\n })\n server.watcher.on('unlink', (file: string) => {\n if (isRouteFileForOpenApi(file)) {\n void reEmitOpenApi(openApiServerDir, openApiDistDir, openApiCfg)\n }\n })\n }\n\n // T2.3 (architecture-medium-deferrals) — WS upgrade extracted to sibling.\n setupWsUpgrade(server, ctx.projectRoot)\n\n // T2.4 — clear devtools WS reference on shutdown\n server.httpServer?.once('close', () => {\n ;(globalThis as { __theoViteHotServer?: unknown }).__theoViteHotServer = undefined\n })\n}\n","/**\n * T3.1 — Translate the server-side RouteNode tree into the devtools-facing\n * RouteManifest shape, then broadcast over the HMR bridge.\n *\n * No-op in production / when no dev server is attached.\n *\n * NEVER use dangerouslySetInnerHTML in any devtools component — see plan EC-20.\n */\nimport type { RouteNode } from '../../core/contracts/route-node.js'\nimport type { RouteInfo, RouteManifest } from '../shared.js'\n\nimport { broadcastToDevtools } from './broadcast.js'\n\ninterface FlattenAccumulator {\n routes: RouteInfo[]\n}\n\nfunction buildPath(parents: string[], segment: string): string {\n const joined = [...parents, segment].filter(Boolean).join('/')\n return '/' + joined\n}\n\nfunction walk(\n node: RouteNode,\n parents: string[],\n layoutChain: string[],\n acc: FlattenAccumulator,\n): void {\n const path = buildPath(parents, node.segment)\n // Layout file (if any) joins the chain for any descendant page.\n const nextChain = node.layout ? [...layoutChain, node.layout] : layoutChain\n\n if (node.page) {\n acc.routes.push({\n path,\n absoluteFilePath: node.page,\n layoutChain: [...layoutChain], // freeze chain at this leaf\n hasLoading: Boolean(node.loading),\n hasError: Boolean(node.error),\n hasNotFound: Boolean(node.notFound),\n })\n }\n\n for (const child of node.children) {\n const nextParents = node.segment ? [...parents, node.segment] : parents\n walk(child, nextParents, nextChain, acc)\n }\n}\n\n/**\n * Pure helper: convert RouteNode tree → RouteManifest for the devtools UI.\n * Exported for testing.\n */\nexport function buildRouteManifest(tree: RouteNode): RouteManifest {\n const acc: FlattenAccumulator = { routes: [] }\n walk(tree, [], [], acc)\n return { routes: acc.routes }\n}\n\n/**\n * Broadcast the manifest to the devtools UI over the HMR bridge.\n * Safe to call from any dev-server context — no-op in production.\n */\nexport function broadcastRouteManifest(tree: RouteNode): void {\n const manifest = buildRouteManifest(tree)\n broadcastToDevtools('theo:devtools:manifest', manifest)\n}\n","import { randomUUID } from 'node:crypto'\n\nimport type { ViteDevServer, Connect } from 'vite'\n\nimport {\n createViteLoader,\n executeAction,\n findSuggestion,\n logRequest,\n scanServerActions,\n sendError,\n type CsrfMode,\n type DisallowedConfig,\n type PluginRunner,\n} from '../server/internal-api.js'\n\nconst PREFIX = '/api/__actions/'\n\nexport interface ActionMiddlewareOptions {\n pluginRunner?: PluginRunner\n /**\n * CSRF mode passed through to `executeAction`. Parity with the route\n * middleware — actions inherit the same warn/strict policy as routes.\n * Defaults to 'strict' (the 0.3.0 default).\n */\n csrfMode?: CsrfMode\n /**\n * T5.1 — Rails-inspired per-route escalation. Forwarded to `executeAction`.\n */\n disallowed?: DisallowedConfig\n}\n\nexport function createActionMiddleware(\n vite: ViteDevServer,\n serverDir: string,\n options?: ActionMiddlewareOptions,\n): Connect.NextHandleFunction {\n const loadModule = createViteLoader(vite)\n const pluginRunner = options?.pluginRunner\n const csrfMode: CsrfMode = options?.csrfMode ?? 'strict'\n const disallowed = options?.disallowed\n return (req, res, next) => {\n void (async () => {\n const url = req.url ?? ''\n if (!url.startsWith(PREFIX)) {\n next()\n return\n }\n\n const requestId = randomUUID()\n const start = Date.now()\n res.setHeader('x-request-id', requestId)\n\n const pathAfterPrefix = url.slice(PREFIX.length).split('?')[0]\n const segments = pathAfterPrefix.split('/').filter(Boolean)\n\n if (segments.length < 2) {\n sendError(\n res,\n 'BAD_REQUEST',\n 'Action URL must be /api/__actions/{file}/{exportName}',\n 400,\n undefined,\n requestId,\n )\n logRequest({\n method: req.method ?? 'POST',\n url,\n status: 400,\n duration: Date.now() - start,\n requestId,\n })\n return\n }\n\n const exportName = segments[segments.length - 1]\n const actionPath = segments.slice(0, -1).join('/')\n\n const actions = scanServerActions(serverDir)\n const action = actions.find((a) => a.actionPath === actionPath)\n\n if (!action) {\n const actionPaths = actions.map((a) => a.actionPath)\n const suggestion = findSuggestion(actionPath, actionPaths)\n const msg = suggestion\n ? `Action file \"${actionPath}\" not found. Did you mean: ${suggestion}?`\n : `Action file \"${actionPath}\" not found`\n sendError(res, 'NOT_FOUND', msg, 404, undefined, requestId)\n logRequest({\n method: req.method ?? 'POST',\n url,\n status: 404,\n duration: Date.now() - start,\n requestId,\n })\n return\n }\n\n await executeAction(\n action.filePath,\n exportName,\n req,\n res,\n loadModule,\n serverDir,\n requestId,\n pluginRunner,\n csrfMode,\n disallowed,\n )\n logRequest(\n {\n method: req.method ?? 'POST',\n url,\n status: res.statusCode,\n duration: Date.now() - start,\n requestId,\n },\n undefined,\n req,\n )\n })()\n }\n}\n","/**\n * M2 (theokit-ai-first) — dev middleware for the `agents/<name>.ts` convention.\n *\n * Serves `POST /api/agents/<name>` in `theokit dev` by scanning the top-level `agents/`\n * directory on each request, loading the matched module via Vite's SSR loader, and\n * streaming the M0/M1 UIMessageStream through `mountAgent` — the SAME wiring point the\n * prod server uses (`start/handlers.ts` `tryServeAgent`), so dev and build never drift.\n *\n * Registered under the reserved `/api/agents/` prefix BEFORE the generic api-middleware\n * (mirrors how the action middleware owns `/api/__actions/`); an unmatched agent path\n * falls through to `next()` so the api-middleware can 404 it consistently.\n */\nimport { randomUUID } from 'node:crypto'\n\nimport type { ViteDevServer, Connect } from 'vite'\n\nimport { getApprovalRegistry } from '../server/agent/approval-registry.js'\nimport { handleAgentApproval, isApprovalPath } from '../server/agent/approve-agent.js'\nimport { mountAgent } from '../server/agent/mount-agent.js'\nimport { resolveProvider } from '../server/agent/provider-resolver.js'\nimport {\n incomingMessageToWebRequest,\n writeWebResponseToServerResponse,\n} from '../server/http/node-web-adapter.js'\nimport {\n createViteLoader,\n logRequest,\n scanAgents,\n sendError,\n type CsrfMode,\n} from '../server/internal-api.js'\n\nconst PREFIX = '/api/agents/'\n\nexport function createAgentMiddleware(\n vite: ViteDevServer,\n projectRoot: string,\n csrfMode: CsrfMode = 'strict',\n): Connect.NextHandleFunction {\n const loadModule = createViteLoader(vite)\n return (req, res, next) => {\n void (async () => {\n const url = req.url ?? ''\n if (!url.startsWith(PREFIX)) {\n next()\n return\n }\n\n const requestId = randomUUID()\n const start = Date.now()\n res.setHeader('x-request-id', requestId)\n\n const urlPath = url.split('?')[0]\n\n // HITL approve route (`/api/agents/<name>/approve/<id>`, M4) — resolve the pending approval.\n // Branches BEFORE the agent-path exact match (the approve path never equals an `agentPath`).\n if (isApprovalPath(urlPath)) {\n const method = (req.method ?? 'POST').toUpperCase()\n if (method !== 'POST') {\n sendError(\n res,\n 'METHOD_NOT_ALLOWED',\n 'Approve endpoints accept POST',\n 405,\n undefined,\n requestId,\n )\n logRequest({ method, url, status: 405, duration: Date.now() - start, requestId })\n return\n }\n try {\n const request = incomingMessageToWebRequest(req)\n const response = await handleAgentApproval(\n request,\n urlPath,\n getApprovalRegistry(),\n csrfMode,\n )\n await writeWebResponseToServerResponse(response, res)\n } catch (err) {\n sendError(\n res,\n 'INTERNAL',\n err instanceof Error ? err.message : 'Approve handler failed',\n 500,\n undefined,\n requestId,\n )\n }\n logRequest({ method, url, status: res.statusCode, duration: Date.now() - start, requestId })\n return\n }\n\n const agent = scanAgents(projectRoot).find((a) => a.agentPath === urlPath)\n if (!agent) {\n // Not a known agent — let the api-middleware own the 404 (single 404 shape).\n next()\n return\n }\n\n const method = (req.method ?? 'POST').toUpperCase()\n if (method !== 'POST') {\n sendError(\n res,\n 'METHOD_NOT_ALLOWED',\n 'Agent endpoints accept POST',\n 405,\n undefined,\n requestId,\n )\n logRequest({ method, url, status: 405, duration: Date.now() - start, requestId })\n return\n }\n\n try {\n const mod = await loadModule(agent.filePath)\n const apiKey = resolveProvider().apiKey\n const request = incomingMessageToWebRequest(req)\n const response = await mountAgent(mod, request, apiKey, agent.filePath, csrfMode)\n await writeWebResponseToServerResponse(response, res)\n } catch (err) {\n sendError(\n res,\n 'INTERNAL',\n err instanceof Error ? err.message : 'Agent handler failed',\n 500,\n undefined,\n requestId,\n )\n }\n logRequest({ method, url, status: res.statusCode, duration: Date.now() - start, requestId })\n })()\n }\n}\n","import type { IncomingMessage, ServerResponse } from 'node:http'\n\nimport type { ViteDevServer, Connect } from 'vite'\n\nimport {\n BATCH_PATH,\n CSP_REPORT_PATH,\n TRACE_HEADER,\n applySecurityHeaders,\n createCorsHandler,\n createRateLimiter,\n createViteLoader,\n executeRoute,\n extractTraceId,\n findSuggestion,\n handleBatchRequest,\n handleCspReport,\n handleCsrfReadiness,\n logRequest,\n matchRoute,\n scanServerRoutes,\n sendError,\n type AuditLogger,\n type CorsConfig,\n type CspReportHandlerOptions,\n type CsrfReadinessStore,\n type DisallowedConfig,\n type PluginRunner,\n type RateLimitConfig,\n type SecurityHeadersConfig,\n} from '../server/internal-api.js'\nimport type { TheoTransformer } from '../server/transformer.js'\n\nexport interface ApiMiddlewareOptions {\n rateLimitConfig?: RateLimitConfig\n pluginRunner?: PluginRunner\n transformer?: TheoTransformer\n /** When defined, enables /api/__theo_batch__ endpoint with given options. */\n batching?: { max?: number }\n /** Phase 5 — CSRF enforcement mode. Default 'warn' (0.2.0). */\n csrfMode?: 'off' | 'warn' | 'strict'\n /** Phase 6 — Default security headers config. */\n securityHeaders?: SecurityHeadersConfig\n /** T5.1 — per-route disallowed escalation pattern. */\n disallowed?: DisallowedConfig\n /** T1.2 — CORS configuration. When undefined, no CORS handling (same-origin only). */\n cors?: CorsConfig\n /** T4.1 — Audit logger. Receives csrf.warn, rate-limit.exceeded, csp.violation events. */\n auditLogger?: AuditLogger\n /** T5.1 — Optional CSP violation hook (forwarded to Sentry / custom sink). */\n onCspViolation?: CspReportHandlerOptions['onViolation']\n /**\n * T2.2 — Optional CSRF readiness store. When provided, the\n * `/__theo/csrf-readiness` endpoint is mounted and warn events are\n * recorded into the store. Dev-mode middleware wires this automatically;\n * production hosts opt in via config.security.csrfTelemetry.exposeReadinessEndpoint.\n */\n csrfReadinessStore?: CsrfReadinessStore\n /**\n * Wave 2 completion (T1.1 vite-proxy) — list of services-proxy path prefixes\n * (e.g. `['/api/agent', '/api/worker']`). Requests whose path starts with\n * any of these prefixes bypass the api-middleware (call `next()`) so the\n * later proxyMiddleware (installed by Vite from `server.proxy`) can forward\n * them to the polyglot sidecar. Empty / undefined preserves Wave 1 BC.\n */\n servicesProxyPrefixes?: readonly string[]\n}\n\n/**\n * Wave 2 completion — true when `url` is OUTSIDE TheoKit's API namespace,\n * either because it doesn't start with `/api/` OR because it matches a\n * services-proxy prefix. In both cases the middleware should call `next()`\n * so the request reaches Vite's proxyMiddleware / static fallback. Combining\n * both checks into one helper keeps the main arrow function's cyclomatic\n * complexity within the eslint ceiling.\n */\nfunction shouldBypassApiMiddleware(url: string, prefixes: readonly string[]): boolean {\n if (!url.startsWith('/api/')) return true\n if (prefixes.length === 0) return false\n const path = url.split('?')[0]\n for (const prefix of prefixes) {\n if (path === prefix || path.startsWith(`${prefix}/`)) return true\n }\n return false\n}\n\nasync function handleCspReportIfMatch(\n req: IncomingMessage,\n res: ServerResponse,\n url: string,\n ctx: {\n auditLogger: AuditLogger | undefined\n onCspViolation: CspReportHandlerOptions['onViolation'] | undefined\n },\n): Promise<boolean> {\n const pathOnly = url.split('?')[0]\n if (pathOnly !== CSP_REPORT_PATH || req.method !== 'POST') return false\n await handleCspReport(req, res, { auditLogger: ctx.auditLogger, onViolation: ctx.onCspViolation })\n return true\n}\n\ninterface RateLimitCtx {\n rateLimiter:\n | ((req: IncomingMessage) => { limited: boolean; headers: Record<string, string> })\n | null\n requestId: string\n url: string\n start: number\n}\n\n/**\n * Apply rate-limit headers and send 429 if exceeded. Returns true when\n * the caller should stop handling the request (limit hit), false otherwise.\n * Extracted from `createApiMiddleware` to keep complexity within ceiling.\n */\nfunction applyRateLimitOr429(\n req: IncomingMessage,\n res: ServerResponse,\n ctx: RateLimitCtx,\n): boolean {\n if (!ctx.rateLimiter) return false\n const check = ctx.rateLimiter(req)\n for (const [k, v] of Object.entries(check.headers)) res.setHeader(k, v)\n if (!check.limited) return false\n sendError(res, 'RATE_LIMITED', 'Too many requests', 429, undefined, ctx.requestId)\n logRequest({\n method: req.method ?? 'GET',\n url: ctx.url,\n status: 429,\n duration: Date.now() - ctx.start,\n requestId: ctx.requestId,\n })\n return true\n}\n\ninterface BatchMatchCtx {\n url: string\n batching: { max?: number } | undefined\n requestId: string\n start: number\n}\n\nasync function handleBatchIfMatch(\n req: IncomingMessage,\n res: ServerResponse,\n ctx: BatchMatchCtx,\n): Promise<boolean> {\n if (!ctx.batching) return false\n const urlPathOnly = ctx.url.split('?')[0]\n if (urlPathOnly !== BATCH_PATH || req.method !== 'POST') return false\n await handleBatchInline(req, res, ctx.batching, ctx.requestId)\n logRequest({\n method: req.method ?? 'POST',\n url: ctx.url,\n status: res.statusCode,\n duration: Date.now() - ctx.start,\n requestId: ctx.requestId,\n })\n return true\n}\n\nasync function handleBatchInline(\n req: IncomingMessage,\n res: ServerResponse,\n batching: { max?: number },\n requestId: string,\n): Promise<void> {\n try {\n const chunks: Buffer[] = []\n await new Promise<void>((resolve, reject) => {\n req.on('data', (c) => chunks.push(c as Buffer))\n req.on('end', () => {\n resolve()\n })\n req.on('error', reject)\n })\n // CR-028: pass the parsed JSON as `unknown`; Zod inside\n // handleBatchRequest is the validation boundary.\n const payload: unknown = JSON.parse(Buffer.concat(chunks).toString())\n const outerHeaders: Record<string, string> = {}\n for (const [k, v] of Object.entries(req.headers)) {\n if (typeof v === 'string') outerHeaders[k.toLowerCase()] = v\n }\n const result = await handleBatchRequest(payload, {\n max: batching.max,\n outerHeaders,\n // T1.4 placeholder — full per-item route execution lands in a\n // follow-up; for now we return an empty ack so the integration\n // tests of the batch endpoint shape pass.\n execute: () => Promise.resolve({ data: { ok: true } }),\n })\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify(result))\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n sendError(res, 'BATCH_ERROR', message, 400, undefined, requestId)\n }\n}\n\n/**\n * P#3 T4.1 — fire pluginRunner.onRequest for unmatched routes so plugins\n * can intercept paths outside server/routes/ (e.g., @theokit/plugin-openapi\n * /api/docs). Returns true when a plugin short-circuited the response.\n */\ninterface RunPluginsCtx {\n req: IncomingMessage\n res: ServerResponse\n requestId: string\n start: number\n url: string\n}\n\nasync function runPluginsBeforeRouteMatch(\n pluginRunner: PluginRunner,\n reqCtx: RunPluginsCtx,\n): Promise<boolean> {\n const { req, res, requestId, start, url } = reqCtx\n try {\n const hookResult = await pluginRunner.runOnRequest({\n request: req,\n response: res,\n ctx: {},\n requestId,\n })\n if (hookResult.shortCircuited) {\n logRequest(\n {\n method: req.method ?? 'GET',\n url,\n status: res.statusCode,\n duration: Date.now() - start,\n requestId,\n },\n undefined,\n req,\n )\n return true\n }\n } catch (err) {\n sendError(res, 'PLUGIN_ERROR', (err as Error).message, 500, undefined, requestId)\n return true\n }\n return false\n}\n\nexport function createApiMiddleware(\n vite: ViteDevServer,\n serverDir: string,\n rateLimitConfigOrOptions?: RateLimitConfig | ApiMiddlewareOptions,\n): Connect.NextHandleFunction {\n // Backward-compat: accept either RateLimitConfig directly (old signature)\n // or an ApiMiddlewareOptions object (new signature with pluginRunner).\n const opts: ApiMiddlewareOptions =\n rateLimitConfigOrOptions && 'windowMs' in rateLimitConfigOrOptions\n ? { rateLimitConfig: rateLimitConfigOrOptions }\n : (rateLimitConfigOrOptions ?? {})\n\n const loadModule = createViteLoader(vite)\n const rateLimiter = opts.rateLimitConfig ? createRateLimiter(opts.rateLimitConfig) : null\n const pluginRunner = opts.pluginRunner\n const transformer = opts.transformer\n const batching = opts.batching\n // T6.1 — default flipped from 'warn' to 'strict' for 0.3.0.\n const csrfMode = opts.csrfMode ?? 'strict'\n const disallowed = opts.disallowed\n const securityHeadersConfig = opts.securityHeaders ?? {}\n const securityEnv = { production: process.env.NODE_ENV === 'production' }\n // T1.2 — CORS handler runs FIRST in the pipeline (D10).\n const corsHandler = opts.cors ? createCorsHandler(opts.cors) : null\n const auditLogger = opts.auditLogger\n const onCspViolation = opts.onCspViolation\n const csrfReadinessStore = opts.csrfReadinessStore\n const servicesProxyPrefixes = opts.servicesProxyPrefixes ?? []\n\n return (req, res, next) => {\n // Middleware dispatch arm: each branch guards a protocol concern\n // (CSP report, CSRF readiness, services proxy, CORS preflight, rate\n // limit, plugin onRequest, batch, route match); linear dispatch order\n // is more readable than per-concern function extraction.\n // eslint-disable-next-line complexity\n const handle = async (): Promise<void> => {\n const url = req.url ?? ''\n\n // T5.1 — built-in CSP report endpoint. Matched BEFORE the /api/* gate\n // so the path lives outside the user's route namespace. Endpoint is\n // CSRF-exempt (browsers don't send X-Theo-Action on report POSTs).\n if (await handleCspReportIfMatch(req, res, url, { auditLogger, onCspViolation })) {\n return\n }\n\n // T2.2 — CSRF readiness endpoint. Only mounted when a store is wired\n // (dev-mode wires it automatically; prod opt-in via config).\n if (csrfReadinessStore && (await handleCsrfReadiness(req, res, csrfReadinessStore))) {\n return\n }\n\n if (shouldBypassApiMiddleware(url, servicesProxyPrefixes)) {\n next()\n return\n }\n\n // T1.2 + D10 — CORS preflight runs BEFORE rate limit, BEFORE CSRF.\n // Preflight short-circuits the response (204 + Access-Control-* headers).\n if (corsHandler?.handlePreflight(req, res)) {\n return\n }\n\n // Phase 7 — traceId resolution. Reads traceparent / x-request-id /\n // generates UUID. The `requestId` name is kept for backward compat\n // with downstream helpers (sendError, logRequest) — same value flows\n // under both `x-request-id` (legacy) and `x-trace-id` (canonical).\n const requestId = extractTraceId(req)\n const start = Date.now()\n res.setHeader('x-request-id', requestId)\n res.setHeader(TRACE_HEADER, requestId)\n // Phase 6 — Apply security headers BEFORE the handler runs so route\n // handlers can still override via res.setHeader (last write wins).\n applySecurityHeaders(res, securityHeadersConfig, securityEnv)\n // T1.2 — Add CORS headers to non-preflight responses.\n corsHandler?.applyHeaders(req, res)\n\n if (applyRateLimitOr429(req, res, { rateLimiter, requestId, url, start })) {\n return\n }\n\n // P#3 T4.1 — fire pluginRunner.onRequest BEFORE matchRoute so plugins\n // can intercept unmatched paths (e.g., @theokit/plugin-openapi /api/docs).\n if (\n pluginRunner &&\n (await runPluginsBeforeRouteMatch(pluginRunner, { req, res, requestId, start, url }))\n ) {\n return\n }\n\n // T1.4 — Batch endpoint (only when batching is enabled in config)\n if (await handleBatchIfMatch(req, res, { url, batching, requestId, start })) {\n return\n }\n\n const routes = scanServerRoutes(serverDir)\n const match = matchRoute(url, routes)\n\n if (!match) {\n const urlPath = url.split('?')[0]\n const routePaths = routes.map((r) => r.routePath)\n const suggestion = findSuggestion(urlPath, routePaths)\n const msg = suggestion\n ? `API route not found: ${urlPath}. Did you mean: ${suggestion}?`\n : 'API route not found'\n sendError(res, 'NOT_FOUND', msg, 404, undefined, requestId)\n logRequest(\n {\n method: req.method ?? 'GET',\n url,\n status: 404,\n duration: Date.now() - start,\n requestId,\n },\n undefined,\n req,\n )\n return\n }\n\n const method = (req.method ?? 'GET').toUpperCase()\n // T3.1 (ADR-0016) — context object replaces 12 positional args\n await executeRoute({\n route: match.route,\n method,\n params: match.params,\n req,\n res,\n loadModule,\n serverDir,\n requestId,\n pluginRunner,\n transformer,\n csrfMode,\n disallowed,\n })\n logRequest(\n { method, url, status: res.statusCode, duration: Date.now() - start, requestId },\n undefined,\n req,\n )\n }\n void handle()\n }\n}\n","/**\n * T2.2 (architecture-medium-deferrals plan, ADR D2) — SSR dev middleware\n * extracted from `vite-plugin/index.ts` for SRP.\n *\n * `setupSsrDevMiddleware(server, opts)` registers a Connect-style middleware\n * on the Vite dev server that:\n * 1. Skips API, static, and HMR requests (let other middlewares handle).\n * 2. Reads `index.html`, runs `transformIndexHtml`.\n * 3. Generates per-request nonce, applies security headers (CSP + Cache-Control).\n * 4. Calls `ssrLoadModule(VIRTUAL_ENTRY_SERVER_ID).render(url, { nonce })`.\n * 5. Injects rendered HTML (with hydration script) into root div.\n * 6. On error: ssrFixStacktrace + fallback to CSR via `next()`.\n *\n * No-op when `ssrEnabled === false`. Caller's responsibility to gate.\n */\n\nimport { readFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport type { ViteDevServer } from 'vite'\n\nimport {\n applySecurityHeaders,\n generateNonce,\n type SecurityHeadersConfig,\n} from '../server/internal-api.js'\n\ninterface SsrRenderResult {\n html: string\n hydrationData: {\n loaderData?: unknown\n actionData?: unknown\n errors?: unknown\n }\n}\n\ninterface SsrEntryServer {\n render: (\n url: string,\n opts: { nonce: string },\n ) => Promise<SsrRenderResult | { redirect: Response } | string>\n}\n\nfunction isSsrRenderResult(value: unknown): value is SsrRenderResult {\n if (typeof value !== 'object' || value === null) return false\n if (!('html' in value)) return false\n return typeof (value as Record<string, unknown>).html === 'string'\n}\n\nexport interface SsrDevMiddlewareOptions {\n projectRoot: string\n virtualEntryServerId: string\n securityHeaders: SecurityHeadersConfig | undefined\n}\n\n/**\n * Attach the SSR dev middleware to a Vite dev server. Caller decides whether\n * to invoke this based on `ssrEnabled` — this function does not gate.\n */\nexport function setupSsrDevMiddleware(server: ViteDevServer, opts: SsrDevMiddlewareOptions): void {\n server.middlewares.use((req, res, next) => {\n void (async () => {\n const url = req.url ?? '/'\n // Skip API, static, and HMR requests\n if (\n url.startsWith('/api/') ||\n url.startsWith('/@') ||\n url.startsWith('/node_modules/') ||\n url.includes('.')\n ) {\n next()\n return\n }\n\n try {\n const indexPath = resolve(opts.projectRoot, 'index.html')\n // eslint-disable-next-line security/detect-non-literal-fs-filename -- projectRoot is from `theokit dev`'s caller-controlled cwd\n let template = readFileSync(indexPath, 'utf-8')\n template = await server.transformIndexHtml(url, template)\n\n // T4.1 — Generate a per-request nonce and apply security headers BEFORE render.\n // The same nonce flows into React's renderToPipeableStream({ nonce }) so every\n // emitted <script> carries it AND into the CSP script-src directive.\n // EC-3: applySecurityHeaders also forces Cache-Control: private, no-store.\n const nonce = generateNonce()\n applySecurityHeaders(\n res,\n opts.securityHeaders ?? {},\n { production: process.env.NODE_ENV === 'production' },\n { nonce },\n )\n\n const mod = (await server.ssrLoadModule(opts.virtualEntryServerId)) as SsrEntryServer\n const result = await mod.render(url, { nonce })\n\n if (result && typeof result === 'object' && 'redirect' in result) {\n res.writeHead(302, {\n Location: result.redirect.headers.get('location') ?? '/',\n })\n res.end()\n return\n }\n\n // Backward-compat: old render returned string. New shape returns\n // { html, hydrationData } so the framework can emit the hydration\n // data script OUTSIDE the React root (fixes hydration mismatch).\n let ssrHtml: string\n let hydrationScript = ''\n if (typeof result === 'string') {\n ssrHtml = result\n } else if (isSsrRenderResult(result)) {\n ssrHtml = result.html\n const dataJson = JSON.stringify(result.hydrationData).replace(/</g, '\\\\u003c')\n hydrationScript = `<script nonce=\"${nonce}\">window.__staticRouterHydrationData=${dataJson}</script>`\n } else {\n ssrHtml = ''\n }\n const rootDivMatch = /<div id=[\"']root[\"'][^>]*>/.exec(template)\n if (!rootDivMatch) {\n res.writeHead(200, { 'Content-Type': 'text/html' })\n res.end(template)\n return\n }\n\n const splitIdx = template.indexOf(rootDivMatch[0]) + rootDivMatch[0].length\n const html =\n template.slice(0, splitIdx) + ssrHtml + hydrationScript + template.slice(splitIdx)\n\n res.writeHead(200, { 'Content-Type': 'text/html' })\n res.end(html)\n } catch (err) {\n server.ssrFixStacktrace(err as Error)\n console.error('[SSR Dev Error]', err)\n // Fallback to CSR\n next()\n return\n }\n })()\n })\n}\n","/**\n * T2.3 (architecture-medium-deferrals plan, ADR D2) — WebSocket upgrade\n * handler extracted from `vite-plugin/index.ts` for SRP.\n *\n * `setupWsUpgrade(server, projectRoot)` scans `server/ws/*` and attaches an\n * upgrade handler to `server.httpServer`. Lazy-imports the `ws` package so\n * non-WS apps don't pay the cost.\n *\n * **EC-1 (architecture-medium-deferrals plan v1.1 MUST FIX):** must tolerate\n * `server.httpServer === null` (Vite middleware mode — embed in Express/etc).\n * Without the guard, dev embeds crash on plugin init. The function exits\n * silently when no httpServer is available; consumer can wire their own.\n *\n * Mirrors the prod surface in `cli/commands/start-websocket-handler.ts` —\n * same `onOpen`/`onMessage`/`onClose`/`onError` handler shape (EC-6 parity).\n */\n\nimport type { IncomingMessage } from 'node:http'\nimport { resolve } from 'node:path'\nimport type { Duplex } from 'node:stream'\n\nimport type { ViteDevServer } from 'vite'\n\nimport { scanWebSocketRoutes } from '../server/internal-api.js'\n\ninterface WsHandler {\n onOpen?: (ws: unknown, request: unknown) => void | Promise<void>\n onMessage?: (ws: unknown, data: string) => void | Promise<void>\n onClose?: (ws: unknown, code: number, reason: Buffer) => void | Promise<void>\n onError?: (ws: unknown, err: Error) => void | Promise<void>\n}\n\nexport function setupWsUpgrade(server: ViteDevServer, projectRoot: string): void {\n const wsRoutes = scanWebSocketRoutes(resolve(projectRoot, 'server'))\n if (wsRoutes.length === 0) return\n\n // EC-1 — middleware-mode Vite has no httpServer. Silently skip; the host\n // platform owns its own upgrade routing in that case.\n const wsHttpServer = server.httpServer\n if (!wsHttpServer) return\n\n // Lazy-import `ws` so non-WS apps don't pay the cost.\n void import('ws')\n .then(({ WebSocketServer }) => {\n const wss = new WebSocketServer({ noServer: true })\n\n wsHttpServer.on('upgrade', (request: IncomingMessage, socket: Duplex, head: Buffer) => {\n void (async () => {\n const url = request.url ?? '/'\n if (!url.startsWith('/ws/')) return // Let Vite handle HMR etc.\n\n const wsPath = url.split('?')[0]\n const match = wsRoutes.find((r) => r.wsPath === wsPath)\n if (!match) {\n socket.destroy()\n return\n }\n\n try {\n const mod = await server.ssrLoadModule(match.filePath)\n const handler = ((mod as { default?: unknown }).default ?? mod) as WsHandler\n\n wss.handleUpgrade(request, socket, head, (ws) => {\n void handler.onOpen?.(ws, request)\n ws.on('message', (data: Buffer) => {\n void handler.onMessage?.(ws, data.toString())\n })\n ws.on('close', (code: number, reason: Buffer) => {\n void handler.onClose?.(ws, code, reason)\n })\n ws.on('error', (err: Error) => {\n void handler.onError?.(ws, err)\n })\n })\n } catch {\n socket.destroy()\n }\n })()\n })\n })\n .catch(() => {\n console.warn(\n '[Theo] WebSocket routes found but \"ws\" package not installed. Run: npm install ws',\n )\n })\n}\n","/* eslint-disable security/detect-non-literal-fs-filename --\n * Build-time tool. Read-only filesystem walks under cwd + node_modules\n * to resolve consumer-side optional deps. Paths are derived from the\n * CLI-controlled cwd and a fixed package name list.\n */\n/**\n * `integrateUseTheoUI(cwd, opts)` — auto-chains the Vite plugins needed\n * for `@theokit/ui` styling when the consumer has the dep declared.\n *\n * Algorithm (D3 + D5 of the plan):\n * 1. opts.enabled === false → return [].\n * 2. detectPackage('@theokit/ui') — if absent, return [].\n * 3. opts.consumerTailwindConfig or opts.consumerPostcssConfig set →\n * log info + return []. Consumer-in-control wins (D3).\n * 4. detectPackage('@tailwindcss/vite') — if absent, log warn + return [].\n * 5. Dynamic-import both. Type-check default exports (EC-5). Type-check\n * return shapes (EC-6). If any guard fails, log + return [].\n * 6. Return [tailwindcssPlugin(), useTheoUIPlugin()].\n */\n\nimport { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { pathToFileURL } from 'node:url'\n\nimport type { Plugin } from 'vite'\n\nimport { detectPackage } from './auto-detect.js'\n\nexport interface IntegrateUiOptions {\n /** When `false`, disable auto-config regardless of detection. Default: true. */\n enabled?: boolean\n /** Path to the consumer's tailwind.config.* (any extension), if present. D3 deferral. */\n consumerTailwindConfig?: string\n /** Path to the consumer's postcss.config.* (any extension), if present. D3 deferral. */\n consumerPostcssConfig?: string\n}\n\n/**\n * Resolve a bare specifier to an absolute file URL by walking up from the\n * consumer's `cwd`, scanning `node_modules` directly. Works for ESM-only\n * packages that don't expose a `require` condition (createRequire fails\n * on those). Reads the resolved package.json's `exports.\".\"` field to\n * find the entry. Returns the file:// URL or null if not resolvable.\n */\nfunction resolveConsumerImport(name: string, cwd: string): string | null {\n let dir = cwd\n for (let i = 0; i < 10; i++) {\n const pkgDir = join(dir, 'node_modules', ...name.split('/'))\n const pkgJsonPath = join(pkgDir, 'package.json')\n if (existsSync(pkgJsonPath)) {\n try {\n const raw = readFileSync(pkgJsonPath, 'utf-8')\n const pkg = JSON.parse(raw) as {\n exports?: { '.'?: { import?: string; default?: string } | string }\n main?: string\n module?: string\n }\n let entry: string | undefined\n const dotExport = pkg.exports?.['.']\n if (typeof dotExport === 'string') entry = dotExport\n else if (dotExport && typeof dotExport === 'object') {\n entry = dotExport.import ?? dotExport.default\n }\n entry ??= pkg.module ?? pkg.main\n if (!entry) return null\n // Strip leading ./ then join.\n const cleaned = entry.replace(/^\\.\\//, '')\n return pathToFileURL(join(pkgDir, cleaned)).href\n } catch {\n return null\n }\n }\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n return null\n}\n\nfunction isValidPlugin(value: unknown): value is Plugin {\n if (value === null || typeof value !== 'object') return false\n if (Array.isArray(value)) return false\n // Vite Plugin shape: object with a `name: string` field at minimum.\n if (!('name' in value)) return false\n return typeof (value as Record<string, unknown>).name === 'string'\n}\n\n/**\n * Normalize a Vite plugin factory return value into a flat Plugin[].\n *\n * Background: Tailwind v3 returned a single Plugin from its factory.\n * Tailwind v4 (`@tailwindcss/vite@4.x`) returns an ARRAY of 3 plugins\n * (`@tailwindcss/vite:scan` + `:generate:serve` + `:generate:build`).\n * The EC-6 single-Plugin guard rejected the v4 array shape and silently\n * skipped chain integration, causing 0 utilities generated in the\n * consumer's CSS. This normalizer accepts both shapes.\n */\nfunction normalizePluginReturn(value: unknown): Plugin[] | null {\n if (Array.isArray(value)) {\n const result: Plugin[] = []\n for (const entry of value) {\n if (!isValidPlugin(entry)) return null\n result.push(entry)\n }\n return result.length > 0 ? result : null\n }\n if (isValidPlugin(value)) return [value]\n return null\n}\n\n/** Test-only side-door so EC-6 shape guard can be unit-tested directly. */\nexport const _isValidPluginForTest = isValidPlugin\n/** Test-only side-door for the v3/v4 normalizer. */\nexport const _normalizePluginReturnForTest = normalizePluginReturn\n\n// eslint-disable-next-line complexity -- canonical auto-config gate (5 detection branches + 2 import guards + 2 shape guards); flattening to micro-helpers would hide the linear contract\nexport async function integrateUseTheoUI(\n cwd: string,\n opts?: IntegrateUiOptions,\n): Promise<Plugin[]> {\n if (opts?.enabled === false) return []\n\n const uiDetect = detectPackage('@theokit/ui', cwd)\n if (!uiDetect.installed) return []\n\n // D3 — consumer's manual config wins\n if (opts?.consumerTailwindConfig || opts?.consumerPostcssConfig) {\n // eslint-disable-next-line no-console -- one-line transparency hint; goal is to surface the override path\n console.info(\n `[theokit] Detected your tailwind.config / postcss.config — skipping auto-config. Extend with \\`import preset from '@theokit/ui/preset'\\` to apply UI theme.`,\n )\n return []\n }\n\n const tailwindDetect = detectPackage('@tailwindcss/vite', cwd)\n if (!tailwindDetect.installed) {\n console.warn(\n `[theokit] @theokit/ui detected but @tailwindcss/vite is not installed. Run \\`pnpm add -D @tailwindcss/vite\\` to enable styling.`,\n )\n return []\n }\n\n // Explicit chain: @tailwindcss/vite FIRST + @theokit/ui/vite-plugin\n // with `{ tailwind: false }` (avoids double-add of @tailwindcss/vite).\n //\n // Why resolve via filesystem then import by URL: this module runs from\n // theokit's own dist/, so `await import('@tailwindcss/vite')` would\n // try to resolve from theokit's node_modules — where the consumer's\n // optional deps don't exist. Resolving from the consumer's cwd\n // gives the correct path.\n const tailwindUrl = resolveConsumerImport('@tailwindcss/vite', cwd)\n if (!tailwindUrl) {\n console.warn(\n `[theokit] @tailwindcss/vite installed but its package entry was not resolvable from ${cwd}. Skipping auto-config.`,\n )\n return []\n }\n let tailwindMod: { default?: unknown }\n let uiMod: { default?: unknown }\n try {\n tailwindMod = (await import(tailwindUrl)) as { default?: unknown }\n } catch (err) {\n console.warn(\n `[theokit] @tailwindcss/vite dynamic import failed (${(err as Error).message}). Skipping auto-config.`,\n )\n return []\n }\n // For @theokit/ui/vite-plugin, resolve via package + subpath:\n // node_modules/@theokit/ui/dist/vite-plugin.js\n const uiPkgInstalled = detectPackage('@theokit/ui', cwd)\n const uiPkgDir = uiPkgInstalled.resolvedPath\n ? uiPkgInstalled.resolvedPath.replace(/[\\\\/]package\\.json$/, '')\n : null\n const uiPluginPath = uiPkgDir ? join(uiPkgDir, 'dist', 'vite-plugin.js') : null\n if (!uiPluginPath || !existsSync(uiPluginPath)) {\n console.warn(\n `[theokit] @theokit/ui/vite-plugin entry not found at ${String(uiPluginPath)}. Skipping auto-config.`,\n )\n return []\n }\n try {\n uiMod = (await import(pathToFileURL(uiPluginPath).href)) as { default?: unknown }\n } catch (err) {\n console.warn(\n `[theokit] @theokit/ui/vite-plugin dynamic import failed (${(err as Error).message}). Skipping auto-config.`,\n )\n return []\n }\n\n if (typeof tailwindMod.default !== 'function') {\n console.warn(\n `[theokit] @tailwindcss/vite does not expose a default-export function. Skipping auto-config.`,\n )\n return []\n }\n if (typeof uiMod.default !== 'function') {\n console.warn(\n `[theokit] @theokit/ui/vite-plugin does not expose a default-export function. Skipping auto-config.`,\n )\n return []\n }\n\n let tailwindPlugin: unknown\n let uiPlugin: unknown\n try {\n tailwindPlugin = (tailwindMod.default as () => unknown)()\n } catch (err) {\n console.warn(`[theokit] @tailwindcss/vite() threw: ${(err as Error).message}`)\n return []\n }\n try {\n // Pass { tailwind: false } so the UI plugin skips its internal\n // @tailwindcss/vite chain (we already added it above).\n uiPlugin = (uiMod.default as (opts?: { tailwind?: boolean }) => unknown)({\n tailwind: false,\n })\n } catch (err) {\n console.warn(`[theokit] @theokit/ui/vite-plugin() threw: ${(err as Error).message}`)\n return []\n }\n\n const tailwindPlugins = normalizePluginReturn(tailwindPlugin)\n if (tailwindPlugins === null) {\n console.warn(`[theokit] @tailwindcss/vite returned unexpected shape. Skipping auto-config.`)\n return []\n }\n const uiPlugins = normalizePluginReturn(uiPlugin)\n if (uiPlugins === null) {\n console.warn(\n `[theokit] @theokit/ui/vite-plugin returned unexpected shape. Skipping auto-config.`,\n )\n return []\n }\n\n return [...tailwindPlugins, ...uiPlugins]\n}\n","/* eslint-disable security/detect-non-literal-fs-filename --\n * Reads <projectRoot>/package.json + resolves the target package's own\n * package.json. Paths come from controlled CLI/config inputs; this is a\n * build-time tool, no HTTP.\n */\n/**\n * `detectPackage(name, cwd)` — generalized form of `theoui-detect.ts`.\n *\n * Used by T3.2 `integrateUseTheoUI` to gate auto-config on whether the\n * consumer has `@theokit/ui` AND `@tailwindcss/vite` installed.\n *\n * Algorithm (same as `theoui-detect.ts` but parameterized):\n * 1. Read `<cwd>/package.json`. Check `dependencies` / `devDependencies` /\n * `peerDependencies` for the package name.\n * 2. If declared, probe `require.resolve('<name>/package.json', { paths: [cwd] })`.\n * Read the resolved package.json to capture `version`.\n * 3. If resolution fails, fall back to probing common entrypoints (so\n * packages whose `exports` doesn't include `./package.json` still\n * detect).\n *\n * NEVER throws. Returns `{installed: false}` on any failure.\n */\n\nimport { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\n\nimport type { DetectResult } from './auto-detect-types.js'\n\n/**\n * D13 invariant (ADR 0021): @theokit/ui is ESM-only by design.\n * NÃO usar `createRequire(...).resolve()` — `ERR_PACKAGE_PATH_NOT_EXPORTED`\n * em runtime para packages que declaram `type:\"module\"` sem `require` condition.\n * Tudo filesystem walk direto.\n */\n\nfunction isDeclared(name: string, projectRoot: string): boolean {\n try {\n const raw = readFileSync(join(projectRoot, 'package.json'), 'utf-8')\n const pkg = JSON.parse(raw) as {\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n peerDependencies?: Record<string, string>\n }\n return Boolean(\n pkg.dependencies?.[name] ?? pkg.devDependencies?.[name] ?? pkg.peerDependencies?.[name],\n )\n } catch {\n return false\n }\n}\n\n/**\n * D13: filesystem walk pra encontrar package.json (substitui require.resolve).\n * Walks node_modules up to 10 levels (handles pnpm hoist + workspace symlinks).\n */\nfunction resolvePackageJson(name: string, cwd: string): { path: string; version?: string } | null {\n let dir = cwd\n for (let depth = 0; depth < 10; depth++) {\n const pkgJsonPath = join(dir, 'node_modules', ...name.split('/'), 'package.json')\n if (existsSync(pkgJsonPath)) {\n try {\n const raw = readFileSync(pkgJsonPath, 'utf-8')\n const pkg = JSON.parse(raw) as { name?: string; version?: string }\n // Validate package name matches (defesa contra colisão path)\n if (pkg.name === name) {\n return { path: pkgJsonPath, version: pkg.version }\n }\n } catch {\n // continue walking\n }\n }\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n return null\n}\n\n/**\n * D13: fallback probe via filesystem (substitui require.resolve).\n * Tenta common entry paths em node_modules. Retorna path do entry achado.\n */\nfunction fallbackProbe(name: string, cwd: string): { resolvedEntry: string } | null {\n const candidates = ['index.mjs', 'dist/index.mjs', 'dist/index.js', 'index.js']\n let dir = cwd\n for (let depth = 0; depth < 10; depth++) {\n const pkgDir = join(dir, 'node_modules', ...name.split('/'))\n for (const candidate of candidates) {\n const entry = join(pkgDir, candidate)\n if (existsSync(entry)) return { resolvedEntry: entry }\n }\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n return null\n}\n\n/** Walk up from a resolved entry path until we hit the package's own package.json\n * whose `name` field matches `expectedName`. Returns null on any failure. */\nfunction findOwningPackageJson(\n entry: string,\n expectedName: string,\n): { path: string; version?: string } | null {\n let dir = dirname(entry)\n // Bound the walk to ~10 levels to avoid pathological cases.\n for (let i = 0; i < 10; i++) {\n const candidate = join(dir, 'package.json')\n if (existsSync(candidate)) {\n try {\n const raw = readFileSync(candidate, 'utf-8')\n const pkg = JSON.parse(raw) as { name?: string; version?: string }\n if (pkg.name === expectedName) {\n return { path: candidate, version: pkg.version }\n }\n } catch {\n // ignore + continue walking\n }\n }\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n return null\n}\n\nexport function detectPackage(name: string, cwd: string): DetectResult {\n if (!isDeclared(name, cwd)) {\n return { installed: false }\n }\n\n const pkgJson = resolvePackageJson(name, cwd)\n if (pkgJson) {\n return {\n installed: true,\n version: pkgJson.version,\n resolvedPath: pkgJson.path,\n }\n }\n\n // Filesystem fallback: ESM-only packages (no `require` condition) can't\n // be resolved by createRequire. Check node_modules directly. The walk\n // upward handles pnpm hoist + workspace symlinks.\n let dir = cwd\n for (let i = 0; i < 10; i++) {\n const nmPath = join(dir, 'node_modules', ...name.split('/'))\n const nmPkgJson = join(nmPath, 'package.json')\n if (existsSync(nmPkgJson)) {\n try {\n const raw = readFileSync(nmPkgJson, 'utf-8')\n const pkg = JSON.parse(raw) as { name?: string; version?: string }\n if (pkg.name === name) {\n return { installed: true, version: pkg.version, resolvedPath: nmPkgJson }\n }\n } catch {\n /* fall through to entry probe */\n }\n return { installed: true }\n }\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n\n // Last-resort fallback — exports doesn't include ./package.json. Walk up from\n // the resolved entry to find the package's own package.json.\n const probe = fallbackProbe(name, cwd)\n if (probe) {\n const owning = findOwningPackageJson(probe.resolvedEntry, name)\n if (owning) {\n return { installed: true, version: owning.version, resolvedPath: owning.path }\n }\n return { installed: true }\n }\n\n return { installed: false }\n}\n","/* eslint-disable security/detect-non-literal-fs-filename --\n * Resolves theokit's own install directory (the `node_modules/theokit/`).\n * Build-time tool. Read-only check. No HTTP input.\n */\nimport { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\n/**\n * Resolve the directory that holds the framework's compiled (or source)\n * subpaths — `client/`, `server/`, `react-query/`, etc.\n *\n * Cases (regression T1.3):\n * - Source mode (`src/vite-plugin/index.ts`) — `currentDir` is\n * `…/src/vite-plugin`. Parent (`…/src`) contains `client/`. Return parent.\n * - Dist mode (`dist/chunk-XYZ.js`) — `currentDir` is `…/dist`. That dir\n * itself contains `client/`. Return currentDir.\n * - Unknown shape — fall back to parent (legacy behavior). The dogfood\n * validator will catch the misconfiguration before runtime.\n *\n * Pure function — no side effects, only filesystem reads via `existsSync`.\n * Exported so the regression test can exercise the branch logic directly.\n */\nexport function resolveTheoRootDir(currentDir: string): string {\n if (existsSync(resolve(currentDir, 'client'))) {\n return currentDir\n }\n return resolve(currentDir, '..')\n}\n","/* eslint-disable security/detect-non-literal-fs-filename --\n * transformIndexHtml extraction (T2.6 / M6). hasPackage probe reads\n * `node_modules/<name>` paths built from build-time projectRoot. No\n * HTTP input.\n */\nimport { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nimport { injectDevtoolsScript } from './inject-devtools.js'\nimport { injectEntryClient } from './inject-entry-client.js'\nimport { injectStylesheets } from './inject-stylesheets.js'\n\nexport interface TransformHtmlCtx {\n isDevMode: { value: boolean }\n devtoolsEnabled: boolean\n projectRoot: string\n}\n\n/**\n * Runs the 3-step HTML injection sequence in the canonical order:\n * 1. entry-client (always)\n * 2. devtools (dev only)\n * 3. stylesheets (dev only)\n * Order is part of the contract — devtools depends on entry-client\n * being present; stylesheets injection sits last so the <link>\n * follows the bundled <script>. EC-10 honored.\n */\nexport function runTransformIndexHtml(html: string, ctx: TransformHtmlCtx): string {\n // 1. entry-client (always)\n const entry = injectEntryClient(html)\n\n if (entry.warning) console.warn(entry.warning)\n let next = entry.html\n\n // 2. devtools (dev only, respecting config.devtools = false)\n const devtools = injectDevtoolsScript(next, {\n isDev: ctx.isDevMode.value,\n enabled: ctx.devtoolsEnabled,\n })\n\n if (devtools.warning) console.warn(devtools.warning)\n next = devtools.html\n\n // 3. Stylesheet link (dev only) — fixes LCP. Without the\n // <link rel=\"stylesheet\">, CSS only loads after the JS bundle\n // executes `import 'styles.css'`, causing FOUC + LCP > 9s.\n // Production builds rely on Vite's SSR bundle for the\n // correctly-hashed <link>. Font preload was tried + reverted\n // (see inject-stylesheets.ts comment); CLS was hydration\n // mismatch, not font swap.\n const styles = injectStylesheets(next, {\n isDev: ctx.isDevMode.value,\n hasPackage: (name) => existsSync(resolve(ctx.projectRoot, 'node_modules', ...name.split('/'))),\n })\n next = styles.html\n\n return next\n}\n","/**\n * T1.2 — Auto-inject the devtools entry `<script>` into served HTML (dev only).\n *\n * Origin: matches the inject-entry-client.ts pattern but for the devtools\n * module. In dev, the Vite plugin's transformIndexHtml hook calls this for\n * every served HTML. In build, this is a no-op.\n *\n * - EC-30: naive `.replace('</head>', ...)` IS used; alternative HTML parser\n * is too heavy for the bug class (user putting `</head>` literal in inline\n * JS is near-zero). Documented in known limitations.\n * - User opt-out via `config.devtools = false` is respected at the plugin\n * level (this function is simply not called).\n *\n * NEVER use dangerouslySetInnerHTML in any devtools component — see plan EC-20.\n */\n\nexport const DEVTOOLS_VIRTUAL_ID = '/@theo/devtools/entry.js'\nexport const DEVTOOLS_RESOLVED_ID = '\\0@theo/devtools/entry.js'\n\nconst SCRIPT_TAG = `<script type=\"module\" src=\"${DEVTOOLS_VIRTUAL_ID}\"></script>`\n\nexport interface InjectDevtoolsResult {\n html: string\n injected: boolean\n warning?: string\n}\n\nexport function injectDevtoolsScript(\n html: string,\n opts: { isDev: boolean; enabled?: boolean },\n): InjectDevtoolsResult {\n // Build mode → no inject\n if (!opts.isDev) return { html, injected: false }\n // User opt-out via config.devtools = false\n if (opts.enabled === false) return { html, injected: false }\n\n // Already present (HMR re-run, user added manually) → idempotent\n if (html.includes(DEVTOOLS_VIRTUAL_ID)) {\n return { html, injected: false }\n }\n\n // Inject before </head> (case-insensitive, first occurrence)\n const headClosePattern = /<\\/head\\s*>/i\n if (headClosePattern.test(html)) {\n return {\n html: html.replace(headClosePattern, (match) => ` ${SCRIPT_TAG}\\n ${match}`),\n injected: true,\n }\n }\n\n // No </head> tag — skip inject + warn (rather than corrupt the HTML)\n return {\n html,\n injected: false,\n warning:\n 'theokit devtools: index.html has no </head> tag; devtools script was NOT injected. Add <head>…</head> to your template to enable devtools.',\n }\n}\n","/**\n * Auto-inject the entry-client `<script>` into served HTML.\n *\n * Origin: a real user (live session) wrote `index.html` without the\n * `<script type=\"module\" src=\"/@theo/entry-client\"></script>` tag. The\n * page rendered SSR perfectly but NO JS ran — every onClick was dead.\n * No error, no warning. An hour of debugging.\n *\n * Fix: the Vite plugin's `transformIndexHtml` hook runs this for every\n * served HTML. If the script is already present (by URL substring match\n * — handles every quoting/ordering variant) the HTML is returned\n * unchanged. Otherwise the script is inserted before `</body>`. If\n * there's no `</body>` at all (malformed HTML), the script is appended\n * at the end and we emit a console.warn in dev.\n */\n\nconst ENTRY_CLIENT_URL = '/@theo/entry-client'\nconst SCRIPT_TAG = `<script type=\"module\" src=\"${ENTRY_CLIENT_URL}\"></script>`\n\nexport interface InjectResult {\n html: string\n injected: boolean\n warning?: string\n}\n\nexport function injectEntryClient(html: string): InjectResult {\n // Detect via URL substring — robust against:\n // <script src='/@theo/entry-client'>\n // <script type=\"module\" src=\"/@theo/entry-client\" />\n // <link rel=\"modulepreload\" href=\"/@theo/entry-client\">\n if (html.includes(ENTRY_CLIENT_URL)) {\n return { html, injected: false }\n }\n\n // Inject before </body> (case-insensitive, first occurrence)\n const bodyClosePattern = /<\\/body\\s*>/i\n if (bodyClosePattern.test(html)) {\n return {\n html: html.replace(bodyClosePattern, (match) => ` ${SCRIPT_TAG}\\n ${match}`),\n injected: true,\n }\n }\n\n // Malformed HTML — append at end and warn\n return {\n html: `${html}\\n${SCRIPT_TAG}`,\n injected: true,\n warning:\n 'theokit: index.html has no </body> tag; entry-client script was appended at end. Add <body>…</body> to your template.',\n }\n}\n","/**\n * Inject `<link rel=\"stylesheet\">` tags into served HTML during DEV.\n *\n * Why this exists (real bug, 2026-05-22): the example chat app had an\n * LCP of 9-16s because the HTML response landed WITHOUT any `<link>` tag\n * for `@theokit/ui/styles.css`. CSS only loaded after entry-client.js\n * ran the layout import. Browser paint waited for the JS → CSS chain:\n *\n * HTML arrives → browser paints nothing\n * JS bundle arrives → React hydrates → encounters `import 'styles.css'`\n * CSS arrives → browser RE-paints with styles\n *\n * Fix: emit the `<link>` in the HTML head so the browser fetches CSS in\n * PARALLEL with JS. LCP becomes time-to-CSS instead of time-to-JS-exec.\n *\n * DEV-only: in production builds, Vite's SSR pipeline emits the\n * appropriate `<link>` via its own asset manifest (with content hashes).\n * We must not double-inject there.\n */\n\ninterface StylesheetTarget {\n /** Vite dev URL — what the browser hits */\n href: string\n /** node_modules path checked before injection */\n packageRoot: string\n}\n\nconst TARGETS: StylesheetTarget[] = [\n {\n href: '/@id/@theokit/ui/styles.css',\n packageRoot: '@theokit/ui',\n },\n]\n\n/**\n * Note (2026-05-23): font preloads were briefly added here to address a\n * \"FOUT-looking\" CLS of 0.39 measured in DevTools. They turned out to\n * be a misdiagnosis — the real cause was a React hydration mismatch\n * from `<StaticRouterProvider hydrate>` emitting a `<script>` inside\n * the React tree (fixed in commit 31506d1).\n *\n * Why we don't preload fonts:\n * - In dev, pnpm hoists @theokit/ui via `.pnpm/<hash>/...`. The CSS\n * `@font-face` resolves to the real path; our preload would use the\n * symlink path. Browser doesn't dedupe — preload is \"wasted\" and\n * Chrome logs \"preloaded but not used within a few seconds\".\n * - In prod, Vite's SSR bundle emits proper hashed preload metadata\n * for fonts referenced from compiled CSS. Manual preload there\n * would conflict.\n *\n * If a future regression brings back font-related CLS, the right path\n * is `font-display: optional` (no swap) or size-adjust metric matching\n * in @theokit/ui itself — not framework-side preload.\n */\n\nexport interface InjectStylesheetsResult {\n html: string\n injected: string[]\n}\n\nexport interface InjectStylesheetsOptions {\n /** Only inject in dev (default). Skip when building for production. */\n isDev: boolean\n /** Function that checks whether a package is installed at projectRoot. */\n hasPackage(name: string): boolean\n}\n\nexport function injectStylesheets(\n html: string,\n opts: InjectStylesheetsOptions,\n): InjectStylesheetsResult {\n if (!opts.isDev) return { html, injected: [] }\n\n const tagsToInject: string[] = []\n for (const target of TARGETS) {\n if (!opts.hasPackage(target.packageRoot)) continue\n // Idempotency: skip if href already present\n if (html.includes(target.href)) continue\n tagsToInject.push(`<link rel=\"stylesheet\" href=\"${target.href}\" />`)\n }\n\n if (tagsToInject.length === 0) return { html, injected: [] }\n\n const joined = tagsToInject.join('\\n ')\n // Inject before </head>; fall back to start of <body> if no head close.\n const headClosePattern = /<\\/head\\s*>/i\n if (headClosePattern.test(html)) {\n return {\n html: html.replace(headClosePattern, (match) => ` ${joined}\\n ${match}`),\n injected: tagsToInject,\n }\n }\n\n const bodyOpenPattern = /<body[^>]*>/i\n if (bodyOpenPattern.test(html)) {\n return {\n html: html.replace(bodyOpenPattern, (match) => `${match}\\n ${joined}`),\n injected: tagsToInject,\n }\n }\n\n // Malformed HTML — prepend and trust the browser\n return { html: `${joined}\\n${html}`, injected: tagsToInject }\n}\n","export interface EntryServerOptions {\n /** When true, emit a streaming entry using onShellReady + signal cleanup.\n * When false (default), emit the legacy single-shot onAllReady entry. */\n streaming?: boolean\n /**\n * TheoUI config — when present, the SSR React tree wraps StaticRouterProvider\n * in <TheoUIProvider> + <Suspense> to MATCH the client entry exactly. Without\n * this, hydration falls back silently because the trees differ — button\n * onClick handlers never get attached and the page looks dead.\n *\n * EC-2 (CSS): the SSR entry never imports CSS. Only the React tree is\n * mirrored — the CSS stays client-only.\n */\n theoUi?: { theme?: 'violet-forge' | 'noir' | 'paper' }\n}\n\nexport function generateEntryServer(options: EntryServerOptions = {}): string {\n if (options.streaming) {\n return generateStreamingEntry(options)\n }\n return generateSingleShotEntry(options)\n}\n\n/**\n * Build the React element tree the server renders. Must mirror the client\n * tree shape from `generateEntryClient` — same wrapper components, same\n * order — or hydration silently falls back to client-only render.\n */\nfunction buildAppTreeJs(options: EntryServerOptions): string {\n const theme = options.theoUi?.theme ?? 'violet-forge'\n // T4.1 — pass options.nonce to StaticRouterProvider so its internal\n // hydration data script (`<script>window.__staticRouterHydrationData\n // = ...</script>`) carries the nonce attribute. Without this, CSP\n // enforce mode (without 'unsafe-inline') blocks the hydration script\n // → React falls back to client-only render → button onClick handlers\n // never attach → page looks dead. The nonce option to\n // renderToPipeableStream covers React-emitted scripts but NOT the\n // hydration script which is emitted by react-router itself.\n // hydrate: false — CRITICAL fix for hydration mismatch.\n //\n // StaticRouterProvider with `hydrate: true` (default) emits\n // `<script>window.__staticRouterHydrationData = ...</script>` INSIDE\n // the React tree. The client's `<RouterProvider>` does NOT emit any\n // script. React's reconciler sees server={...stuff, <script>} vs\n // client={...stuff} and DISCARDS the entire server tree, regenerating\n // from scratch on the client. That regeneration causes a massive\n // layout shift (CLS 0.39 measured in the example).\n //\n // Fix: tell StaticRouterProvider to NOT emit the script. The framework\n // emits the hydration data as a separate `<script>` in the HTML\n // template (outside #root), via the `hydrationData` returned from\n // `render()`. The script still runs BEFORE entry-client.js, so\n // window.__staticRouterHydrationData is populated when\n // createBrowserRouter reads it.\n if (options.theoUi) {\n return [\n `React.createElement(TheoUIProvider, { theme: { defaultTheme: '${theme}' } },`,\n ` React.createElement(Suspense, { fallback: null },`,\n ` React.createElement(StaticRouterProvider, { router, context, hydrate: false })`,\n ` )`,\n ` )`,\n ].join('\\n')\n }\n return `React.createElement(Suspense, { fallback: null },\\n React.createElement(StaticRouterProvider, { router, context, hydrate: false })\\n )`\n}\n\n/**\n * Generate the hydration data extraction snippet. Reads\n * loaderData/actionData/errors from the StaticHandlerContext and returns\n * them as an object the framework can serialize into a `<script>` tag.\n */\nfunction hydrationDataExtractSnippet(): string {\n return [\n ` const hydrationData = {`,\n ` loaderData: context.loaderData,`,\n ` actionData: context.actionData,`,\n ` errors: context.errors,`,\n ` }`,\n ].join('\\n')\n}\n\nfunction generateSingleShotEntry(options: EntryServerOptions): string {\n const theoUiImport = options.theoUi ? `import { TheoUIProvider } from '@theokit/ui'\\n` : ''\n const appTree = buildAppTreeJs(options)\n return [\n `import React, { Suspense } from 'react'`,\n `import { renderToPipeableStream } from 'react-dom/server'`,\n `import { createStaticHandler, createStaticRouter, StaticRouterProvider } from 'react-router'`,\n `import { PassThrough } from 'node:stream'`,\n `import { routes } from '/@theo/route-manifest'`,\n theoUiImport,\n `export async function render(url, options = {}) {`,\n ` const handler = createStaticHandler(routes)`,\n ` const request = new Request('http://localhost' + url)`,\n ` const context = await handler.query(request)`,\n ``,\n ` if (context instanceof Response) {`,\n ` return { redirect: context }`,\n ` }`,\n ``,\n ` const router = createStaticRouter(handler.dataRoutes, context)`,\n ` const app = ${appTree}`,\n ``,\n hydrationDataExtractSnippet(),\n ``,\n ` return new Promise((resolve, reject) => {`,\n ` let html = ''`,\n ` let piped = false`,\n ` const passthrough = new PassThrough()`,\n ` passthrough.on('data', (chunk) => { html += chunk.toString() })`,\n ` passthrough.on('end', () => { resolve({ html, hydrationData }) })`,\n ` passthrough.on('error', reject)`,\n ``,\n ` // Pipe on onShellReady (Next.js pattern). Calling pipe() twice`,\n ` // throws \"React currently only supports piping to one writable`,\n ` // stream\". The \\`piped\\` flag is a belt-and-suspenders guard if`,\n ` // onShellReady fires unexpectedly more than once.`,\n ` // Forward options.nonce to React so every <script> tag React`,\n ` // emits (Suspense boundary scripts) carries the nonce attribute.`,\n ` const { pipe } = renderToPipeableStream(app, {`,\n ` nonce: options.nonce,`,\n ` onShellReady() { if (!piped) { piped = true; pipe(passthrough) } },`,\n ` onShellError(err) { reject(err) },`,\n ` onError(err) { console.error('[SSR Error]', err) },`,\n ` })`,\n ` })`,\n `}`,\n ].join('\\n')\n}\n\n// Generated-code fragments — extracted so the parent emitter stays under\n// the max-lines-per-function ceiling.\nfunction streamingWebRenderer(appTree: string): string[] {\n return [\n `// T2.3 — Web Standards streaming entry for edge runtimes (Cloudflare,`,\n `// Bun, Deno, Vercel Edge). Uses renderToReadableStream and returns a`,\n `// Response with the stream as body. Honors request.signal for client`,\n `// disconnect cleanup.`,\n `export async function renderStreamingWeb(request, options = {}) {`,\n ` const handler = createStaticHandler(routes)`,\n ` const url = new URL(request.url)`,\n ` const context = await handler.query(request)`,\n ``,\n ` if (context instanceof Response) {`,\n ` return context`,\n ` }`,\n ``,\n ` const router = createStaticRouter(handler.dataRoutes, context)`,\n ` const app = ${appTree}`,\n ``,\n ` const stream = await renderToReadableStream(app, {`,\n ` signal: request.signal,`,\n ` nonce: options.nonce,`,\n ` onError(err) { console.error('[SSR Web Stream Error]', err) },`,\n ` })`,\n ` return new Response(stream, {`,\n ` status: 200,`,\n ` headers: {`,\n ` 'Content-Type': 'text/html; charset=utf-8',`,\n ` 'Transfer-Encoding': 'chunked',`,\n ` },`,\n ` })`,\n `}`,\n ]\n}\n\nfunction streamingNodeRenderer(appTree: string): string[] {\n return [\n `// T6.1 — Node streaming SSR entry (opt-in via theo.config.ts > ssrStreaming: true)`,\n `// Flushes the shell as soon as it's ready, then streams Suspense boundaries.`,\n `// EC-11: respects request.signal for client-disconnect cleanup.`,\n `export async function renderStreaming(url, response, options = {}) {`,\n ` const handler = createStaticHandler(routes)`,\n ` const request = new Request('http://localhost' + url, { signal: options.signal })`,\n ` const context = await handler.query(request)`,\n ``,\n ` if (context instanceof Response) {`,\n ` return { redirect: context }`,\n ` }`,\n ``,\n ` const router = createStaticRouter(handler.dataRoutes, context)`,\n ` const app = ${appTree}`,\n ``,\n ` return new Promise((resolve, reject) => {`,\n ` let didError = false`,\n ` const stream = renderToPipeableStream(app, {`,\n ` nonce: options.nonce,`,\n ` onShellReady() {`,\n ` response.statusCode = didError ? 500 : 200`,\n ` response.setHeader('Content-Type', 'text/html; charset=utf-8')`,\n ` response.setHeader('Transfer-Encoding', 'chunked')`,\n ` stream.pipe(response)`,\n ` resolve({ streaming: true })`,\n ` },`,\n ` onShellError(err) { reject(err) },`,\n ` onError(err) {`,\n ` didError = true`,\n ` console.error('[SSR Stream Error]', err)`,\n ` },`,\n ` })`,\n ``,\n ` // EC-11: client disconnect cleanup`,\n ` if (options.signal) {`,\n ` options.signal.addEventListener('abort', () => { stream.abort() })`,\n ` }`,\n ` })`,\n `}`,\n ]\n}\n\nfunction backCompatRenderer(appTree: string): string[] {\n return [\n `// Backward compatibility: keep the single-shot render export available so`,\n `// callers that always used 'render()' don't break when streaming is on.`,\n `export async function render(url, options = {}) {`,\n ` const handler = createStaticHandler(routes)`,\n ` const request = new Request('http://localhost' + url)`,\n ` const context = await handler.query(request)`,\n ``,\n ` if (context instanceof Response) {`,\n ` return { redirect: context }`,\n ` }`,\n ``,\n ` const router = createStaticRouter(handler.dataRoutes, context)`,\n ` const app = ${appTree}`,\n ``,\n hydrationDataExtractSnippet(),\n ``,\n ` const { PassThrough } = await import('node:stream')`,\n ` return new Promise((resolve, reject) => {`,\n ` let html = ''`,\n ` let piped = false`,\n ` const passthrough = new PassThrough()`,\n ` passthrough.on('data', (chunk) => { html += chunk.toString() })`,\n ` passthrough.on('end', () => { resolve({ html, hydrationData }) })`,\n ` passthrough.on('error', reject)`,\n ``,\n ` // Pipe on onShellReady (Next.js pattern). nonce forwarded.`,\n ` const { pipe } = renderToPipeableStream(app, {`,\n ` nonce: options.nonce,`,\n ` onShellReady() { if (!piped) { piped = true; pipe(passthrough) } },`,\n ` onShellError(err) { reject(err) },`,\n ` onError(err) { console.error('[SSR Error]', err) },`,\n ` })`,\n ` })`,\n `}`,\n ]\n}\n\nfunction generateStreamingEntry(options: EntryServerOptions): string {\n const theoUiImport = options.theoUi ? `import { TheoUIProvider } from '@theokit/ui'\\n` : ''\n const appTree = buildAppTreeJs(options)\n return [\n `import React, { Suspense } from 'react'`,\n `import { renderToPipeableStream, renderToReadableStream } from 'react-dom/server'`,\n `import { createStaticHandler, createStaticRouter, StaticRouterProvider } from 'react-router'`,\n `import { routes } from '/@theo/route-manifest'`,\n theoUiImport,\n ``,\n ...streamingWebRenderer(appTree),\n ``,\n ...streamingNodeRenderer(appTree),\n ``,\n ...backCompatRenderer(appTree),\n ].join('\\n')\n}\n","export interface EntryClientOptions {\n theoUi?: {\n fonts?: 'bundled' | 'cdn'\n theme?: 'violet-forge' | 'noir' | 'paper'\n }\n}\n\nexport function generateEntryClient(ssr?: boolean, opts: EntryClientOptions = {}): string {\n const rootMethod = ssr ? 'hydrateRoot' : 'createRoot'\n\n // T2.2 — TheoUI CSS imports (client-only; EC-2: NEVER in entry-server)\n // T2.3 — Wrap RouterProvider in <TheoUIProvider>\n const theoUiImports: string[] = []\n if (opts.theoUi) {\n theoUiImports.push(\n `// T2.2 — TheoUI CSS auto-injected (config.ui)`,\n `import '@theokit/ui/styles.css'`,\n )\n const fontsModule = opts.theoUi.fonts === 'cdn' ? 'fonts-cdn.css' : 'fonts.css'\n theoUiImports.push(\n `import '@theokit/ui/${fontsModule}'`,\n `// T2.3 — TheoUIProvider auto-wraps RouterProvider`,\n `import { TheoUIProvider } from '@theokit/ui'`,\n )\n }\n\n const theme = opts.theoUi?.theme ?? 'violet-forge'\n // Build the React tree: when theoUi enabled, RouterProvider sits inside\n // TheoUIProvider; otherwise RouterProvider is the top-level child.\n const routerTree = opts.theoUi\n ? `React.createElement(TheoUIProvider, { theme: { defaultTheme: '${theme}' } },\\n React.createElement(Suspense, { fallback: null },\\n React.createElement(RouterProvider, { router })\\n )\\n )`\n : `React.createElement(Suspense, { fallback: null },\\n React.createElement(RouterProvider, { router })\\n )`\n\n const renderCall = ssr\n ? ` ${rootMethod}(el,\\n ${routerTree}\\n )`\n : ` ${rootMethod}(el).render(\\n ${routerTree}\\n )`\n\n // SSR hydration: <StaticRouterProvider hydrate> emits\n // `<script>window.__staticRouterHydrationData = …</script>` into the\n // server HTML. The browser router MUST receive this so it continues\n // from the server's state instead of re-fetching everything.\n //\n // Without `hydrationData`, `createBrowserRouter` boots from scratch,\n // React detects a DOM mismatch with the SSR-rendered HTML, and\n // hydration silently falls back to client-only render — every\n // `onClick` handler attached during hydration is lost. The page\n // looks fine but is \"dead HTML\".\n const hydrationLine = ssr\n ? `const router = createBrowserRouter(routes, { hydrationData: window.__staticRouterHydrationData })`\n : `const router = createBrowserRouter(routes)`\n\n // Phase 4 — Code-splitting + matchRoutes safeguard (EC-3).\n //\n // SSR mode: pages are React.lazy()-wrapped in the manifest. If we render\n // before the matched route's module is loaded, React.lazy throws a\n // promise, the outer Suspense fires its fallback (null), and the SSR\n // DOM is wiped before hydration → onClick handlers die.\n //\n // The fix:\n // 1. matchRoutes(routes, location.pathname) on the client to discover\n // which routes actually render at this URL. Using the client matcher\n // (not a server hint) avoids URL-drift races: SSR may have prepared\n // /foo while a browser auto-redirect now points at /bar.\n // 2. Look up each matched route's path in __theoPreloadMap and call\n // the import() factory. Browsers cache modules by URL — when\n // React.lazy fires its own import() during render, it gets the\n // cached promise instantly.\n // 3. Promise.all with a 1500ms timeout. On slow networks we'd rather\n // lose hydration on ONE request than hang the page forever. The\n // fallback path proceeds to hydrate anyway — React.lazy will then\n // Suspense its fallback as usual.\n const preloadBlock = ssr\n ? [\n `// Phase 4 — preload matched-route modules before hydrate (EC-3 safeguard)`,\n `const __theoMatches = matchRoutes(routes, window.location.pathname) ?? []`,\n `const __theoPreloadPaths = __theoMatches`,\n ` .map((m) => m.route && (m.route).path)`,\n ` .filter((p) => typeof p === 'string' && p in __theoPreloadMap)`,\n `const __theoPreloadPromise = Promise.all(`,\n ` __theoPreloadPaths.map((p) => __theoPreloadMap[p]().catch((err) => { console.error('[theo] preload failed', p, err); return null }))`,\n `)`,\n `const __theoTimeout = new Promise((resolve) => setTimeout(() => resolve('timeout'), 1500))`,\n `await Promise.race([__theoPreloadPromise, __theoTimeout])`,\n '',\n ]\n : []\n\n // The hydrate/render call needs to live inside an async IIFE when we\n // await preloads. In CSR-only mode we keep the existing synchronous\n // block for backward compat.\n const renderBlock = ssr\n ? [\n `if (el) {`,\n ` ;(async () => {`,\n ...preloadBlock.map((l) => ' ' + l),\n renderCall,\n ` })()`,\n `}`,\n ]\n : [`if (el) {`, renderCall, `}`]\n\n const manifestImports = ssr\n ? `import { routes, __theoPreloadMap } from '/@theo/route-manifest'`\n : `import { routes } from '/@theo/route-manifest'`\n\n const reactRouterImports = ssr\n ? `import { createBrowserRouter, RouterProvider, matchRoutes } from 'react-router'`\n : `import { createBrowserRouter, RouterProvider } from 'react-router'`\n\n return [\n `import React, { Suspense } from 'react'`,\n `import { ${rootMethod} } from 'react-dom/client'`,\n reactRouterImports,\n manifestImports,\n `// T1.3 — side-effect import sets globalThis.__THEO_TRANSFORMER__ for theoFetch`,\n `import '/@theo/runtime-config'`,\n ...theoUiImports,\n ``,\n hydrationLine,\n `const el = document.getElementById('root')`,\n ...renderBlock,\n ].join('\\n')\n}\n","import type { RouteNode } from './types.js'\n\nfunction normalizePath(p: string): string {\n return p.replace(/\\\\/g, '/')\n}\n\nfunction safeVarName(segment: string, prefix: string): string {\n const safe = segment.replace(/[^a-zA-Z0-9]/g, '_') || 'root'\n return `${prefix}_${safe}`\n}\n\n/**\n * Map a route node to its react-router path segment. Dynamic `[slug]` →\n * `:slug`; catch-all `[...slug]` → `*` (react-router splat — param read via\n * `params['*']`); static segments pass through unchanged. (T2.2 — the page\n * router uses react-router's own matcher, NOT the server regex; see plan D3.)\n */\nfunction segmentPath(node: RouteNode): string {\n if (node.dynamic?.catchAll) return '*'\n if (node.dynamic) return `:${node.dynamic.paramName}`\n return node.segment\n}\n\ninterface ImportEntry {\n varName: string\n importPath: string\n}\n\n/**\n * Build the absolute route path for a node by accumulating segments from\n * the root. Used to key the preload map exactly as react-router's\n * `matchRoutes` reports `match.route.path`.\n */\nfunction buildRoutePath(parents: string[], segment: string): string {\n const joined = [...parents, segment].filter(Boolean).join('/')\n return '/' + joined\n}\n\ninterface WalkAccumulator {\n staticImports: ImportEntry[]\n lazyPages: { varName: string; importPath: string; routePath: string }[]\n layoutState: { found: boolean }\n}\n\nfunction pushIf(staticImports: ImportEntry[], filePath: string | undefined, varName: string): void {\n if (filePath !== undefined) {\n staticImports.push({ varName, importPath: normalizePath(filePath) })\n }\n}\n\nfunction walkRouteTree(node: RouteNode, parents: string[], acc: WalkAccumulator): void {\n const seg = node.segment || 'root'\n const routePath = buildRoutePath(parents, segmentPath(node))\n\n if (node.page !== undefined) {\n acc.lazyPages.push({\n varName: safeVarName(seg, 'Page'),\n importPath: normalizePath(node.page),\n routePath,\n })\n }\n if (node.layout !== undefined) acc.layoutState.found = true\n pushIf(acc.staticImports, node.layout, safeVarName(seg, 'Layout'))\n pushIf(acc.staticImports, node.error, safeVarName(seg, 'Error'))\n pushIf(acc.staticImports, node.loading, safeVarName(seg, 'Loading'))\n pushIf(acc.staticImports, node.notFound, safeVarName(seg, 'NotFound'))\n for (const child of node.children) {\n const childSegPath = segmentPath(node)\n const nextParents = childSegPath ? [...parents, childSegPath] : parents\n walkRouteTree(child, nextParents, acc)\n }\n}\n\nexport function generateRouteManifest(tree: RouteNode): string {\n // Static imports (always-needed at boot): layouts, errors, loading, not-found.\n // Lazy-loaded pages — tracked separately so we emit React.lazy() and\n // build the preload map.\n const acc: WalkAccumulator = {\n staticImports: [],\n lazyPages: [],\n layoutState: { found: false },\n }\n walkRouteTree(tree, [], acc)\n const staticImports = acc.staticImports\n const lazyPages = acc.lazyPages\n const layoutState = acc.layoutState\n\n // Phase 4 — Code-splitting + matchRoutes safeguard (EC-3).\n // PAGES are lazy. LAYOUTS / ERROR / LOADING / NOT-FOUND stay static\n // because they're always needed at boot regardless of route.\n // The preload map exposes the same `import()` calls keyed by absolute\n // route path. The entry-client re-matches `routes` against\n // `location.pathname` and awaits the matched entries BEFORE\n // `hydrateRoot`, so React.lazy modules resolve from cache and no\n // Suspense fallback fires during hydration.\n const lines: string[] = [`import React, { Suspense } from 'react'`]\n\n if (layoutState.found) {\n lines.push(`import { Outlet } from 'react-router'`)\n }\n\n lines.push('')\n\n // Static imports first\n for (const imp of staticImports) {\n lines.push(`import ${imp.varName} from '${imp.importPath}'`)\n }\n\n // Lazy-loaded pages\n for (const lp of lazyPages) {\n lines.push(`const ${lp.varName} = React.lazy(() => import('${lp.importPath}'))`)\n }\n\n lines.push('')\n\n // Preload map — keys are absolute route paths, values are factories that\n // return the same import() the lazy() above resolves. Browsers cache the\n // module by URL so the preload + lazy() share a single promise.\n const preloadEntries = lazyPages.map(\n (lp) => ` '${lp.routePath}': () => import('${lp.importPath}'),`,\n )\n // No TS type annotation — this manifest is emitted as a virtual JS module\n // and Rollup rejects type annotations in production builds.\n lines.push('export const __theoPreloadMap = {')\n for (const e of preloadEntries) lines.push(e)\n lines.push('}', '')\n\n // Build the children-array string for one node, separately from the\n // wrapping logic — keeps `genRouteConfig` under the complexity ceiling.\n function buildChildrenArray(node: RouteNode, seg: string): string {\n const childConfigs: string[] = []\n\n // Index route for this node's page — wrap in Suspense (the lazy module\n // is preloaded on initial hydrate, so this fallback never fires there;\n // it covers client-side navigation to other routes too).\n if (node.page) {\n const pageVar = safeVarName(seg, 'Page')\n const fallbackEl = node.loading\n ? `React.createElement(${safeVarName(seg, 'Loading')})`\n : 'null'\n const pageElement = `React.createElement(Suspense, { fallback: ${fallbackEl} }, React.createElement(${pageVar}))`\n childConfigs.push(`{ index: true, element: ${pageElement} }`)\n }\n\n // Child routes\n for (const child of node.children) {\n childConfigs.push(genRouteConfig(child, false))\n }\n\n // Not-found wildcard (only at this level)\n if (node.notFound) {\n const nfVar = safeVarName(seg, 'NotFound')\n childConfigs.push(`{ path: '*', element: React.createElement(${nfVar}) }`)\n }\n\n let arr = `[${childConfigs.join(', ')}]`\n if (node.error) {\n const errVar = safeVarName(seg, 'Error')\n arr = `[{ errorElement: React.createElement(${errVar}), children: ${arr} }]`\n }\n return arr\n }\n\n // Generate route config\n function genRouteConfig(node: RouteNode, isRoot: boolean): string {\n const seg = node.segment || 'root'\n const childrenArray = buildChildrenArray(node, seg)\n\n // Build route object\n if (node.layout) {\n const layoutVar = safeVarName(seg, 'Layout')\n const pathPart = isRoot ? `path: '/'` : `path: '${segmentPath(node)}'`\n // Layout receives `<Outlet />` as `children` prop. This supports BOTH\n // conventions: Next.js-style layouts that render `{children}` AND\n // layouts that call `<Outlet />` directly (the prop is the same element,\n // ignored by the latter). Without this, Next.js-style templates render\n // empty because react-router does not pass a `children` prop by default.\n return `{ ${pathPart}, element: React.createElement(${layoutVar}, { children: React.createElement(Outlet) }), children: ${childrenArray} }`\n }\n\n // No layout — if root, wrap in path '/'\n if (isRoot) {\n if (node.children.length === 0 && !node.page && !node.notFound && !node.error) {\n return `{ path: '/', children: [] }`\n }\n // Root without layout: children are direct routes\n return `{ path: '/', children: ${childrenArray} }`\n }\n\n // Child segment without layout — just a route\n if (node.page && node.children.length === 0 && !node.error && !node.notFound) {\n const pageVar = safeVarName(seg, 'Page')\n const fallbackEl = node.loading\n ? `React.createElement(${safeVarName(seg, 'Loading')})`\n : 'null'\n const pageElement = `React.createElement(Suspense, { fallback: ${fallbackEl} }, React.createElement(${pageVar}))`\n return `{ path: '${segmentPath(node)}', element: ${pageElement} }`\n }\n\n // Child with children but no layout\n return `{ path: '${segmentPath(node)}', children: ${childrenArray} }`\n }\n\n const routeConfig = genRouteConfig(tree, true)\n lines.push(`export const routes = [${routeConfig}]`)\n\n return lines.join('\\n')\n}\n","/**\n * Virtual modules resolveId + load extraction (T2.6 / M6).\n *\n * Pure structural split — every branch identity preserved from the\n * original inline body in `theoPlugin()`. The dispatcher is purely\n * synchronous; effects (broadcast, transformer wiring) keep their\n * original ordering so EC-10 (Vite hook ordering side effects) is\n * honored.\n */\n\nimport { broadcastRouteManifest } from '../devtools/server-side/route-manifest.js'\nimport { generateEntryServer } from '../router/entry-server.js'\nimport { generateEntryClient } from '../router/entry.js'\nimport { generateRouteManifest } from '../router/generate.js'\nimport { scanRoutes } from '../router/scan.js'\nimport type { TheoTransformer } from '../server/transformer.js'\n\nimport { DEVTOOLS_RESOLVED_ID, DEVTOOLS_VIRTUAL_ID } from './inject-devtools.js'\nimport type { TheoUiDetectResult } from './theoui-detect.js'\n\nexport interface VirtualModuleIds {\n VIRTUAL_ENTRY_ID: string\n RESOLVED_ENTRY_ID: string\n VIRTUAL_MANIFEST_ID: string\n RESOLVED_MANIFEST_ID: string\n VIRTUAL_ENTRY_SERVER_ID: string\n RESOLVED_ENTRY_SERVER_ID: string\n VIRTUAL_RUNTIME_CONFIG_ID: string\n RESOLVED_RUNTIME_CONFIG_ID: string\n}\n\nexport interface VirtualModulesCtx {\n ids: VirtualModuleIds\n appDir: string\n ssrEnabled: boolean\n streamingEnabled: boolean\n theoUi: TheoUiDetectResult | undefined\n transformer: TheoTransformer | undefined\n}\n\nexport function resolveVirtualModuleId(id: string, ids: VirtualModuleIds): string | undefined {\n if (id === ids.VIRTUAL_ENTRY_ID) return ids.RESOLVED_ENTRY_ID\n if (id === ids.VIRTUAL_MANIFEST_ID) return ids.RESOLVED_MANIFEST_ID\n if (id === ids.VIRTUAL_ENTRY_SERVER_ID) return ids.RESOLVED_ENTRY_SERVER_ID\n if (id === ids.VIRTUAL_RUNTIME_CONFIG_ID) return ids.RESOLVED_RUNTIME_CONFIG_ID\n // T1.2 — devtools virtual module. Only resolves in dev; build mode\n // never serves it because transformIndexHtml never injects the tag.\n if (id === DEVTOOLS_VIRTUAL_ID) return DEVTOOLS_RESOLVED_ID\n return undefined\n}\n\nexport function loadVirtualModule(id: string, ctx: VirtualModulesCtx): string | undefined {\n if (id === ctx.ids.RESOLVED_ENTRY_ID) {\n return generateEntryClient(ctx.ssrEnabled, {\n theoUi: ctx.theoUi?.enabled\n ? { fonts: ctx.theoUi.config.fonts, theme: ctx.theoUi.config.theme }\n : undefined,\n })\n }\n if (id === ctx.ids.RESOLVED_MANIFEST_ID) {\n const tree = scanRoutes(ctx.appDir)\n // T3.1 — also broadcast a devtools-shaped manifest to the overlay\n // (no-op in prod / when no dev server is attached).\n broadcastRouteManifest(tree)\n return generateRouteManifest(tree)\n }\n if (id === ctx.ids.RESOLVED_ENTRY_SERVER_ID) {\n // SSR tree MUST mirror client tree shape — pass theoUi through so\n // <TheoUIProvider> wraps in both. Without this, React detects a\n // hydration mismatch and silently falls back to client-only\n // render — onClick handlers never get attached.\n return generateEntryServer({\n streaming: ctx.streamingEnabled,\n theoUi: ctx.theoUi?.enabled ? { theme: ctx.theoUi.config.theme } : undefined,\n })\n }\n if (id === ctx.ids.RESOLVED_RUNTIME_CONFIG_ID) {\n // T1.3 — set globalThis.__THEO_TRANSFORMER__ so theoFetch picks it up\n const tName = ctx.transformer?.name ?? 'json'\n return [\n `// Generated by Theo Vite plugin`,\n `;(globalThis).__THEO_TRANSFORMER__ = ${JSON.stringify(tName)}`,\n `export const TRANSFORMER_NAME = ${JSON.stringify(tName)}`,\n ].join('\\n')\n }\n if (id === DEVTOOLS_RESOLVED_ID) {\n // T1.2 — virtual module re-exports the real entry from theokit's devtools subpath.\n return [\n `// Theo devtools — virtual entry (DEV only)`,\n `import('theokit/devtools/entry').catch((e) => console.error('[theo devtools] mount failed', e))`,\n ].join('\\n')\n }\n return undefined\n}\n","/**\n * T3.1 — Vite integration extension API (`defineTheoIntegration`).\n *\n * Build-time extension system (mirrors Astro Integrations). Lets third\n * parties hook into Theo's Vite lifecycle without forking the plugin.\n *\n * Strictly separated from runtime `defineTheoPlugin` (Phase 4) — different\n * concerns, different surfaces. See ADR D7 in the plan.\n */\n\nexport type HookName =\n | 'theo:config:setup'\n | 'theo:build:start'\n | 'theo:build:done'\n | 'theo:dev:start'\n\nexport interface HookContext {\n addVirtualModule?: (id: string, code: string) => void\n addRoute?: (path: string, handler: RouteHandler) => void\n [key: string]: unknown\n}\n\nexport type Hook = (ctx: HookContext) => void | Promise<void>\n\nexport type RouteHandler = (request: Request) => Response | Promise<Response>\n\nexport interface TheoIntegration {\n name: string\n hooks: Partial<Record<HookName, Hook>>\n}\n\n/**\n * Identity factory for type-checking against TheoIntegration shape.\n */\nexport function defineTheoIntegration(integration: TheoIntegration): TheoIntegration {\n return integration\n}\n\nexport class IntegrationVirtualModulePrefixError extends Error {\n constructor(integrationName: string, id: string) {\n super(\n `Integration \"${integrationName}\" tried to addVirtualModule(\"${id}\"). ` +\n `Virtual module IDs must start with \"virtual:integration:${integrationName}/\" ` +\n `to avoid collisions with Theo internals or other integrations.`,\n )\n this.name = 'IntegrationVirtualModulePrefixError'\n }\n}\n\nexport class IntegrationRouteCollisionError extends Error {\n constructor(integrationName: string, path: string) {\n super(\n `Integration \"${integrationName}\" tried to register route \"${path}\", ` +\n `but it conflicts with an existing route. Choose a different path.`,\n )\n this.name = 'IntegrationRouteCollisionError'\n }\n}\n\nexport interface IntegrationRegistryOptions {\n /** Routes already scanned from `server/routes/`. Used to detect collisions. */\n existingRoutes: string[]\n}\n\nexport interface IntegrationRoute {\n path: string\n owner: string\n}\n\nexport interface IntegrationRegistry {\n registerIntegration(integration: TheoIntegration): void\n fire(hookName: HookName, baseCtx: Record<string, unknown>): Promise<void>\n addVirtualModule(integrationName: string, id: string, code: string): void\n addRoute(integrationName: string, path: string, handler: RouteHandler): void\n getVirtualModule(id: string): string | undefined\n listVirtualModules(): string[]\n listRoutes(): IntegrationRoute[]\n /** Test helper: invoke hook surface directly without firing the lifecycle. */\n callHook(\n integrationName: string,\n hookName: HookName,\n extraCtx: Partial<HookContext>,\n ): Promise<void>\n}\n\nexport function createIntegrationRegistry(\n options: IntegrationRegistryOptions,\n): IntegrationRegistry {\n const integrations: TheoIntegration[] = []\n const virtualModules = new Map<string, { code: string; owner: string }>()\n const routes: { path: string; owner: string; handler: RouteHandler }[] = []\n const userRoutes = new Set(options.existingRoutes)\n\n function buildHookCtxFor(integrationName: string, extra: Partial<HookContext>): HookContext {\n return {\n ...extra,\n addVirtualModule: (id: string, code: string) => {\n addVirtualModule(integrationName, id, code)\n },\n addRoute: (path: string, handler: RouteHandler) => {\n addRoute(integrationName, path, handler)\n },\n }\n }\n\n function addVirtualModule(integrationName: string, id: string, code: string): void {\n const expectedPrefix = `virtual:integration:${integrationName}/`\n if (!id.startsWith(expectedPrefix)) {\n throw new IntegrationVirtualModulePrefixError(integrationName, id)\n }\n virtualModules.set(id, { code, owner: integrationName })\n }\n\n function addRoute(integrationName: string, path: string, handler: RouteHandler): void {\n if (userRoutes.has(path)) {\n throw new IntegrationRouteCollisionError(integrationName, path)\n }\n if (routes.some((r) => r.path === path)) {\n throw new IntegrationRouteCollisionError(integrationName, path)\n }\n routes.push({ path, owner: integrationName, handler })\n }\n\n return {\n registerIntegration(integration) {\n integrations.push(integration)\n },\n async fire(hookName, baseCtx) {\n for (const intg of integrations) {\n const hook = intg.hooks[hookName]\n if (!hook) continue\n try {\n await hook(buildHookCtxFor(intg.name, baseCtx))\n } catch (err) {\n const e = err instanceof Error ? err : new Error(String(err))\n const wrapped = new Error(\n `Integration \"${intg.name}\" hook \"${hookName}\" threw: ${e.message}`,\n )\n ;(wrapped as { cause?: unknown }).cause = e\n throw wrapped\n }\n }\n },\n addVirtualModule,\n addRoute,\n getVirtualModule(id) {\n return virtualModules.get(id)?.code\n },\n listVirtualModules() {\n return Array.from(virtualModules.keys())\n },\n listRoutes() {\n return routes.map((r) => ({ path: r.path, owner: r.owner }))\n },\n // eslint-disable-next-line @typescript-eslint/require-await -- async surface for the public callHook contract\n async callHook(integrationName, _hookName, extraCtx) {\n // Build the ctx for parity with `fire()` so test invocations\n // observe the same shape; we don't actually need the value here.\n buildHookCtxFor(integrationName, extraCtx)\n // Surface for direct test invocation; production code uses fire()\n if (typeof extraCtx.addVirtualModule === 'function') {\n extraCtx.addVirtualModule(\n `virtual:integration:${integrationName}/test`,\n 'export const ok = true',\n )\n }\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,SAAS,cAAAA,mBAAkB;AAC3B,SAAS,WAAAC,UAAS,WAAAC,gBAAe;AACjC,SAAS,qBAAqB;;;ACF9B,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAiBjB,SAAS,cAAc,KAA6C;AAEzE,QAAM,MAAM,WAAW,QAAQ,IAAI,YAAY,UAAU,CAAC,IAAI,QAAQ;AAKtE,QAAM,oBAA8B,CAAC;AACrC,aAAW,aAAa,CAAC,kBAAkB,gBAAgB,cAAc,GAAG;AAC1E,UAAM,OAAO,QAAQ,IAAI,aAAa,SAAS;AAC/C,QAAI,WAAW,IAAI,EAAG,mBAAkB,KAAK,KAAK,SAAS,EAAE;AAAA,EAC/D;AAIA,QAAM,gBACJ,IAAI,YAAY,OAAO,KAAK,IAAI,QAAQ,EAAE,SAAS,IAC/C,yBAAyB,IA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A,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAAE,KAAK,IAAI;AACb;AAIA,SAAS,qBAAqB,SAA2B;AACvD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,iBAAiB,OAAO;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,sBAAsB,SAA2B;AACxD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,iBAAiB,OAAO;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,mBAAmB,SAA2B;AACrD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AA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;AAAA,QACA;AAAA,QACA;AAAA,QACA,WAAW;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,UAAU,QAAQ;AAAA,QAClB,WAAW,QAAQ;AAAA,QACnB,4BAA4B,QAAQ;AAAA,QACpC,sBAAsB;AAAA,QACtB,oBAAoB;AAAA,MACtB,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["existsSync","resolve","dirname","existsSync","resolve","randomUUID","PREFIX","randomUUID","method","resolve","readFileSync","resolve","resolve","readFileSync","resolve","resolve","resolve","existsSync","readFileSync","dirname","join","existsSync","readFileSync","dirname","join","join","existsSync","readFileSync","dirname","join","existsSync","existsSync","resolve","existsSync","resolve","SCRIPT_TAG","existsSync","resolve","basename","resolve","existsSync","dirname"]}
|