theokit 0.37.0 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/{actions-virtual-module-6HQK5GHV.js → actions-virtual-module-H3LY5Q22.js} +3 -3
  2. package/dist/{actions-virtual-module-HYCFRMC3.js → actions-virtual-module-WLOT2SPR.js} +3 -3
  3. package/dist/{agent-PSJ77NJA.js → agent-VQMWM5BK.js} +2 -2
  4. package/dist/{app-typed-client-X2A6NMI2.js → app-typed-client-67GBLYD6.js} +113 -24
  5. package/dist/app-typed-client-67GBLYD6.js.map +1 -0
  6. package/dist/{app-typed-client-K3PXIZDZ.js → app-typed-client-SPFNGVZL.js} +113 -24
  7. package/dist/app-typed-client-SPFNGVZL.js.map +1 -0
  8. package/dist/{build-4HOXGMZV.js → build-3BFIACHN.js} +6 -6
  9. package/dist/{chunk-J5PK5FRN.js → chunk-2HKRQUWU.js} +2 -2
  10. package/dist/{chunk-PMBYKLLN.js → chunk-BKYFOEBK.js} +3 -1
  11. package/dist/{chunk-4FE56YQP.js → chunk-GW5H4KB4.js} +2 -2
  12. package/dist/{chunk-EZWFDHTI.js → chunk-IPSFSNEJ.js} +2 -2
  13. package/dist/{chunk-GNUXRXHI.js → chunk-OLZLYLOE.js} +109 -7
  14. package/dist/chunk-OLZLYLOE.js.map +1 -0
  15. package/dist/{chunk-CEHXC5NI.js → chunk-Q3C3KH3C.js} +24 -5
  16. package/dist/chunk-Q3C3KH3C.js.map +1 -0
  17. package/dist/{chunk-XQPBWMC2.js → chunk-QCB7ZNR2.js} +91 -36
  18. package/dist/chunk-QCB7ZNR2.js.map +1 -0
  19. package/dist/{chunk-AXF3KYY5.js → chunk-QMV3R6D5.js} +88 -35
  20. package/dist/chunk-QMV3R6D5.js.map +1 -0
  21. package/dist/chunk-QNFVYST4.js +110 -0
  22. package/dist/chunk-QNFVYST4.js.map +1 -0
  23. package/dist/{chunk-2WTL2GZO.js → chunk-QWBXUZAX.js} +2 -1
  24. package/dist/cli/index.js +5 -5
  25. package/dist/client/core.d.ts +12 -1
  26. package/dist/client/core.js +1 -1
  27. package/dist/client/index.d.ts +7 -1
  28. package/dist/client/index.js +2 -1
  29. package/dist/client/index.js.map +1 -1
  30. package/dist/controller-swc-transform-URELVCBM.js +27 -0
  31. package/dist/controller-swc-transform-URELVCBM.js.map +1 -0
  32. package/dist/controller-swc-transform-XV3ETSE3.js +28 -0
  33. package/dist/controller-swc-transform-XV3ETSE3.js.map +1 -0
  34. package/dist/{dev-GA572OS7.js → dev-IBCZYFZZ.js} +8 -8
  35. package/dist/index.js +4 -4
  36. package/dist/{internal-api-N6JGTRMN.js → internal-api-MDCX7A7H.js} +8 -3
  37. package/dist/{internal-api-TV4CFQY2.js → internal-api-OLNM25HS.js} +7 -3
  38. package/dist/{mcp-Z3SZULLS.js → mcp-DKRODZAL.js} +2 -2
  39. package/dist/{registry-3NB7KOUI.js → registry-FKPH7XEL.js} +1 -1
  40. package/dist/server/http/index.js +1 -1
  41. package/dist/server/index.js +2 -2
  42. package/dist/{start-SWWCB36Q.js → start-WB7GYXEW.js} +3 -3
  43. package/dist/vite-plugin/index.js +4 -4
  44. package/dist/{vite-plugin-OY5ESFTR.js → vite-plugin-5Y3LDTXI.js} +5 -5
  45. package/package.json +2 -2
  46. package/dist/app-typed-client-K3PXIZDZ.js.map +0 -1
  47. package/dist/app-typed-client-X2A6NMI2.js.map +0 -1
  48. package/dist/chunk-AXF3KYY5.js.map +0 -1
  49. package/dist/chunk-CEHXC5NI.js.map +0 -1
  50. package/dist/chunk-GNUXRXHI.js.map +0 -1
  51. package/dist/chunk-VB2WWBIT.js +0 -1
  52. package/dist/chunk-XQPBWMC2.js.map +0 -1
  53. package/dist/vite-plugin-OY5ESFTR.js.map +0 -1
  54. /package/dist/{actions-virtual-module-6HQK5GHV.js.map → actions-virtual-module-H3LY5Q22.js.map} +0 -0
  55. /package/dist/{actions-virtual-module-HYCFRMC3.js.map → actions-virtual-module-WLOT2SPR.js.map} +0 -0
  56. /package/dist/{agent-PSJ77NJA.js.map → agent-VQMWM5BK.js.map} +0 -0
  57. /package/dist/{build-4HOXGMZV.js.map → build-3BFIACHN.js.map} +0 -0
  58. /package/dist/{chunk-J5PK5FRN.js.map → chunk-2HKRQUWU.js.map} +0 -0
  59. /package/dist/{chunk-PMBYKLLN.js.map → chunk-BKYFOEBK.js.map} +0 -0
  60. /package/dist/{chunk-4FE56YQP.js.map → chunk-GW5H4KB4.js.map} +0 -0
  61. /package/dist/{chunk-EZWFDHTI.js.map → chunk-IPSFSNEJ.js.map} +0 -0
  62. /package/dist/{chunk-2WTL2GZO.js.map → chunk-QWBXUZAX.js.map} +0 -0
  63. /package/dist/{dev-GA572OS7.js.map → dev-IBCZYFZZ.js.map} +0 -0
  64. /package/dist/{chunk-VB2WWBIT.js.map → internal-api-MDCX7A7H.js.map} +0 -0
  65. /package/dist/{internal-api-N6JGTRMN.js.map → internal-api-OLNM25HS.js.map} +0 -0
  66. /package/dist/{mcp-Z3SZULLS.js.map → mcp-DKRODZAL.js.map} +0 -0
  67. /package/dist/{registry-3NB7KOUI.js.map → registry-FKPH7XEL.js.map} +0 -0
  68. /package/dist/{start-SWWCB36Q.js.map → start-WB7GYXEW.js.map} +0 -0
  69. /package/dist/{internal-api-TV4CFQY2.js.map → vite-plugin-5Y3LDTXI.js.map} +0 -0
@@ -9,7 +9,7 @@ import {
9
9
  resolveTransformer,
10
10
  serveAgentAuxRoute,
11
11
  writeWebResponseToServerResponse
12
- } from "./chunk-J5PK5FRN.js";
12
+ } from "./chunk-2HKRQUWU.js";
13
13
  import {
14
14
  isMcpPath
15
15
  } from "./chunk-2CVV6CNN.js";
@@ -36,11 +36,12 @@ import {
36
36
  CsrfReadinessStore,
37
37
  TRACE_HEADER,
38
38
  createCorsHandler,
39
+ dispatchControllerRequest,
39
40
  extractTraceId,
40
41
  handleBatchRequest,
41
42
  handleCspReport,
42
43
  handleCsrfReadiness
43
- } from "./chunk-GNUXRXHI.js";
44
+ } from "./chunk-OLZLYLOE.js";
44
45
  import {
45
46
  applySecurityHeaders,
46
47
  createPluginRunnerFromConfig,
@@ -54,7 +55,7 @@ import {
54
55
  incomingMessageToWebRequest,
55
56
  logRequest,
56
57
  sendError
57
- } from "./chunk-PMBYKLLN.js";
58
+ } from "./chunk-BKYFOEBK.js";
58
59
  import {
59
60
  scanAgents
60
61
  } from "./chunk-L4GCEMNW.js";
@@ -67,7 +68,7 @@ import {
67
68
 
68
69
  // src/vite-plugin/index.ts
69
70
  import { existsSync as existsSync7 } from "fs";
70
- import { resolve as resolve7, dirname as dirname4 } from "path";
71
+ import { resolve as resolve8, dirname as dirname4 } from "path";
71
72
  import { fileURLToPath } from "url";
72
73
 
73
74
  // src/vite-plugin/config-hook.ts
@@ -90,15 +91,23 @@ function runConfigHook(ctx) {
90
91
  server: {
91
92
  ...warmupClientFiles.length > 0 ? { warmup: { clientFiles: warmupClientFiles } } : {},
92
93
  ...servicesProxy !== void 0 ? { proxy: servicesProxy } : {},
93
- // Skip watching gitignored heavy dirs to avoid hitting ENOSPC
94
- // (inotify watcher exhaustion).
94
+ // Skip watching gitignored heavy dirs to avoid ENOSPC (inotify watcher
95
+ // exhaustion), theokit's own generated output, and local SQLite data.
96
+ // #121: a DB write (`.data/app.db` + `-wal`/`-shm`) on every agent turn /
97
+ // request must NOT trigger a full page reload — that "blinks" the screen
98
+ // and tears down the in-flight agent stream.
95
99
  watch: {
96
100
  ignored: [
97
101
  "**/referencias/**",
98
102
  "**/.theokit/**",
99
- "**/.theokit/**",
100
103
  "**/dist/**",
101
- "**/node_modules/**"
104
+ "**/node_modules/**",
105
+ "**/.data/**",
106
+ "**/*.db",
107
+ "**/*.db-wal",
108
+ "**/*.db-shm",
109
+ "**/*.sqlite",
110
+ "**/*.sqlite-journal"
102
111
  ]
103
112
  }
104
113
  },
@@ -278,7 +287,7 @@ async function resolvePluginConfig(projectRoot) {
278
287
  }
279
288
 
280
289
  // src/vite-plugin/configure-server-hook.ts
281
- import { resolve as resolve4, basename } from "path";
290
+ import { resolve as resolve5, basename } from "path";
282
291
 
283
292
  // src/devtools/server-side/route-manifest.ts
284
293
  function buildPath(parents, segment) {
@@ -554,6 +563,7 @@ function createAgentMiddleware(vite, projectRoot, csrfMode = "strict", agentsDir
554
563
  }
555
564
 
556
565
  // src/vite-plugin/api-middleware.ts
566
+ import { resolve as resolve2 } from "path";
557
567
  function shouldBypassApiMiddleware(url, prefixes) {
558
568
  if (!url.startsWith("/api/")) return true;
559
569
  if (prefixes.length === 0) return false;
@@ -601,10 +611,10 @@ async function handleBatchIfMatch(req, res, ctx) {
601
611
  async function handleBatchInline(req, res, batching, requestId) {
602
612
  try {
603
613
  const chunks = [];
604
- await new Promise((resolve8, reject) => {
614
+ await new Promise((resolve9, reject) => {
605
615
  req.on("data", (c) => chunks.push(c));
606
616
  req.on("end", () => {
607
- resolve8();
617
+ resolve9();
608
618
  });
609
619
  req.on("error", reject);
610
620
  });
@@ -658,6 +668,30 @@ async function runPluginsBeforeRouteMatch(pluginRunner, reqCtx) {
658
668
  }
659
669
  return false;
660
670
  }
671
+ async function tryControllerFallthrough(ctx) {
672
+ const handled = await dispatchControllerRequest({
673
+ controllersDir: resolve2(ctx.serverDir, "controllers"),
674
+ loadModule: ctx.loadModule,
675
+ req: ctx.req,
676
+ res: ctx.res,
677
+ csrfMode: ctx.csrfMode,
678
+ disallowed: ctx.disallowed,
679
+ requestId: ctx.requestId
680
+ });
681
+ if (!handled) return false;
682
+ logRequest(
683
+ {
684
+ method: (ctx.req.method ?? "GET").toUpperCase(),
685
+ url: ctx.url,
686
+ status: ctx.res.statusCode,
687
+ duration: Date.now() - ctx.start,
688
+ requestId: ctx.requestId
689
+ },
690
+ void 0,
691
+ ctx.req
692
+ );
693
+ return true;
694
+ }
661
695
  function createApiMiddleware(vite, serverDir, rateLimitConfigOrOptions) {
662
696
  const opts = rateLimitConfigOrOptions && "windowMs" in rateLimitConfigOrOptions ? { rateLimitConfig: rateLimitConfigOrOptions } : rateLimitConfigOrOptions ?? {};
663
697
  const loadModule = createViteLoader(vite);
@@ -708,6 +742,19 @@ function createApiMiddleware(vite, serverDir, rateLimitConfigOrOptions) {
708
742
  const routes = scanServerRoutes(serverDir);
709
743
  const match = matchRoute(url, routes);
710
744
  if (!match) {
745
+ if (await tryControllerFallthrough({
746
+ req,
747
+ res,
748
+ serverDir,
749
+ loadModule,
750
+ csrfMode,
751
+ disallowed,
752
+ requestId,
753
+ url,
754
+ start
755
+ })) {
756
+ return;
757
+ }
711
758
  const urlPath = url.split("?")[0];
712
759
  const routePaths = routes.map((r) => r.routePath);
713
760
  const suggestion = findSuggestion(urlPath, routePaths);
@@ -753,7 +800,7 @@ function createApiMiddleware(vite, serverDir, rateLimitConfigOrOptions) {
753
800
 
754
801
  // src/vite-plugin/ssr-dev-middleware.ts
755
802
  import { readFileSync as readFileSync2 } from "fs";
756
- import { resolve as resolve2 } from "path";
803
+ import { resolve as resolve3 } from "path";
757
804
  function isSsrRenderResult(value) {
758
805
  if (typeof value !== "object" || value === null) return false;
759
806
  if (!("html" in value)) return false;
@@ -768,7 +815,7 @@ function setupSsrDevMiddleware(server, opts) {
768
815
  return;
769
816
  }
770
817
  try {
771
- const indexPath = resolve2(opts.projectRoot, "index.html");
818
+ const indexPath = resolve3(opts.projectRoot, "index.html");
772
819
  let template = readFileSync2(indexPath, "utf-8");
773
820
  template = await server.transformIndexHtml(url, template);
774
821
  const nonce = generateNonce();
@@ -819,9 +866,9 @@ function setupSsrDevMiddleware(server, opts) {
819
866
  }
820
867
 
821
868
  // src/vite-plugin/ws-upgrade.ts
822
- import { resolve as resolve3 } from "path";
869
+ import { resolve as resolve4 } from "path";
823
870
  function setupWsUpgrade(server, projectRoot) {
824
- const wsRoutes = scanWebSocketRoutes(resolve3(projectRoot, "server"));
871
+ const wsRoutes = scanWebSocketRoutes(resolve4(projectRoot, "server"));
825
872
  if (wsRoutes.length === 0) return;
826
873
  const wsHttpServer = server.httpServer;
827
874
  if (!wsHttpServer) return;
@@ -903,7 +950,7 @@ async function runConfigureServer(server, ctx) {
903
950
  csrfReadinessStore
904
951
  })
905
952
  );
906
- const configPath = resolve4(ctx.projectRoot, "theo.config.ts");
953
+ const configPath = resolve5(ctx.projectRoot, "theo.config.ts");
907
954
  server.watcher.on("change", (file) => {
908
955
  if (file === configPath) {
909
956
  console.warn(
@@ -933,7 +980,7 @@ async function runConfigureServer(server, ctx) {
933
980
  const openApiCfg = ctx.resolvedOpenApi;
934
981
  const { reEmitOpenApi } = await import("./dev-emit-XVTJXZGA.js");
935
982
  const openApiServerDir = ctx.serverDir;
936
- const openApiDistDir = resolve4(ctx.projectRoot, ctx.resolvedDistDir);
983
+ const openApiDistDir = resolve5(ctx.projectRoot, ctx.resolvedDistDir);
937
984
  const isRouteFileForOpenApi = (file) => file.startsWith(openApiServerDir) && /\.(ts|tsx|js|mjs)$/.test(file);
938
985
  void reEmitOpenApi(openApiServerDir, openApiDistDir, openApiCfg);
939
986
  server.watcher.on("change", (file) => {
@@ -1219,17 +1266,17 @@ async function integrateUseTheoUI(cwd, opts) {
1219
1266
 
1220
1267
  // src/vite-plugin/resolve-theo-root.ts
1221
1268
  import { existsSync as existsSync5 } from "fs";
1222
- import { resolve as resolve5 } from "path";
1269
+ import { resolve as resolve6 } from "path";
1223
1270
  function resolveTheoRootDir(currentDir) {
1224
- if (existsSync5(resolve5(currentDir, "client"))) {
1271
+ if (existsSync5(resolve6(currentDir, "client"))) {
1225
1272
  return currentDir;
1226
1273
  }
1227
- return resolve5(currentDir, "..");
1274
+ return resolve6(currentDir, "..");
1228
1275
  }
1229
1276
 
1230
1277
  // src/vite-plugin/transform-html-hook.ts
1231
1278
  import { existsSync as existsSync6 } from "fs";
1232
- import { resolve as resolve6 } from "path";
1279
+ import { resolve as resolve7 } from "path";
1233
1280
 
1234
1281
  // src/vite-plugin/inject-devtools.ts
1235
1282
  var DEVTOOLS_VIRTUAL_ID = "/@theo/devtools/entry.js";
@@ -1329,7 +1376,7 @@ function runTransformIndexHtml(html, ctx) {
1329
1376
  next = devtools.html;
1330
1377
  const styles = injectStylesheets(next, {
1331
1378
  isDev: ctx.isDevMode.value,
1332
- hasPackage: (name) => existsSync6(resolve6(ctx.projectRoot, "node_modules", ...name.split("/")))
1379
+ hasPackage: (name) => existsSync6(resolve7(ctx.projectRoot, "node_modules", ...name.split("/")))
1333
1380
  });
1334
1381
  next = styles.html;
1335
1382
  return next;
@@ -1889,7 +1936,7 @@ function findConsumerConfig(projectRoot, basename2) {
1889
1936
  let dir = projectRoot;
1890
1937
  for (let level = 0; level < 3; level++) {
1891
1938
  for (const ext of extensions) {
1892
- const candidate = resolve7(dir, `${basename2}${ext}`);
1939
+ const candidate = resolve8(dir, `${basename2}${ext}`);
1893
1940
  if (existsSync7(candidate)) return candidate;
1894
1941
  }
1895
1942
  const parent = dirname4(dir);
@@ -1901,7 +1948,7 @@ function findConsumerConfig(projectRoot, basename2) {
1901
1948
  async function theoPluginAsync(rootOrOptions) {
1902
1949
  const options = typeof rootOrOptions === "string" ? { root: rootOrOptions } : rootOrOptions ?? {};
1903
1950
  const projectRoot = options.root ?? process.cwd();
1904
- const serverDirAbs = resolve7(projectRoot, options.serverDir ?? "server");
1951
+ const serverDirAbs = resolve8(projectRoot, options.serverDir ?? "server");
1905
1952
  const agentsDirName = options.agentsDir ?? "agents";
1906
1953
  const consumerTailwindConfig = findConsumerConfig(projectRoot, "tailwind.config");
1907
1954
  const consumerPostcssConfig = findConsumerConfig(projectRoot, "postcss.config");
@@ -1919,23 +1966,23 @@ async function theoPluginAsync(rootOrOptions) {
1919
1966
  })
1920
1967
  );
1921
1968
  }
1922
- const { appTypedClientPlugin } = await import("./app-typed-client-X2A6NMI2.js");
1969
+ const { appTypedClientPlugin } = await import("./app-typed-client-67GBLYD6.js");
1923
1970
  const appClientPlugin = appTypedClientPlugin({
1924
1971
  cwd: projectRoot,
1925
1972
  serverDir: serverDirAbs,
1926
- distDir: resolve7(projectRoot, ".theokit")
1973
+ distDir: resolve8(projectRoot, ".theokit")
1927
1974
  });
1928
- const { actionsVirtualModule } = await import("./actions-virtual-module-HYCFRMC3.js");
1975
+ const { actionsVirtualModule } = await import("./actions-virtual-module-WLOT2SPR.js");
1929
1976
  const actionsPlugin = actionsVirtualModule({
1930
1977
  serverDir: serverDirAbs,
1931
- distDir: resolve7(projectRoot, ".theokit")
1978
+ distDir: resolve8(projectRoot, ".theokit")
1932
1979
  });
1933
1980
  const { agentsTypedClientPlugin } = await import("./agents-typed-client-5DCGDWFZ.js");
1934
- const { generateManifest } = await import("./internal-api-TV4CFQY2.js");
1981
+ const { generateManifest } = await import("./internal-api-OLNM25HS.js");
1935
1982
  const agentsClientPlugin = agentsTypedClientPlugin({
1936
1983
  projectRoot,
1937
1984
  agentsDir: agentsDirName,
1938
- distDir: resolve7(projectRoot, ".theokit"),
1985
+ distDir: resolve8(projectRoot, ".theokit"),
1939
1986
  // Agents live at <projectRoot>/<agentsDir>; generateManifest scans them via the server dir's
1940
1987
  // parent (projectRoot for the canonical layout) + the agents dir name (#95 follow-up).
1941
1988
  scanManifest: () => generateManifest(serverDirAbs, projectRoot, agentsDirName)
@@ -1944,10 +1991,16 @@ async function theoPluginAsync(rootOrOptions) {
1944
1991
  const routesHmrPlugin = serverRoutesHmrPlugin({
1945
1992
  serverDir: serverDirAbs
1946
1993
  });
1994
+ const { controllerSwcTransformPlugin } = await import("./controller-swc-transform-XV3ETSE3.js");
1995
+ const controllerTransformPlugin = controllerSwcTransformPlugin({
1996
+ serverDir: serverDirAbs
1997
+ });
1947
1998
  return [
1948
1999
  theoPlugin(rootOrOptions),
1949
2000
  ...uiPlugins,
1950
2001
  ...servicesPlugins,
2002
+ // #122 — swc-compile controllers/** (enforce:'pre'; order-independent).
2003
+ controllerTransformPlugin,
1951
2004
  appClientPlugin,
1952
2005
  actionsPlugin,
1953
2006
  agentsClientPlugin,
@@ -1956,10 +2009,10 @@ async function theoPluginAsync(rootOrOptions) {
1956
2009
  }
1957
2010
  function buildOptimizeDepsInclude(projectRoot, viteOptimizeDeps) {
1958
2011
  const include = [];
1959
- if (existsSync7(resolve7(projectRoot, "node_modules", "@theokit", "ui"))) {
2012
+ if (existsSync7(resolve8(projectRoot, "node_modules", "@theokit", "ui"))) {
1960
2013
  include.push("@theokit/ui");
1961
2014
  }
1962
- if (existsSync7(resolve7(projectRoot, "node_modules", "lucide-react"))) {
2015
+ if (existsSync7(resolve8(projectRoot, "node_modules", "lucide-react"))) {
1963
2016
  include.push("lucide-react");
1964
2017
  }
1965
2018
  include.push("devalue");
@@ -1985,8 +2038,8 @@ var VIRTUAL_MODULE_IDS = {
1985
2038
  function theoPlugin(rootOrOptions) {
1986
2039
  const options = typeof rootOrOptions === "string" ? { root: rootOrOptions } : rootOrOptions ?? {};
1987
2040
  const projectRoot = options.root ?? process.cwd();
1988
- const appDir = resolve7(projectRoot, options.appDir ?? "app");
1989
- const serverDir = resolve7(projectRoot, options.serverDir ?? "server");
2041
+ const appDir = resolve8(projectRoot, options.appDir ?? "app");
2042
+ const serverDir = resolve8(projectRoot, options.serverDir ?? "server");
1990
2043
  const agentsDir = options.agentsDir ?? "agents";
1991
2044
  const ssrEnabled = options.ssr ?? false;
1992
2045
  const currentDir = dirname4(fileURLToPath(import.meta.url));
@@ -2106,4 +2159,4 @@ export {
2106
2159
  theoPluginAsync,
2107
2160
  theoPlugin
2108
2161
  };
2109
- //# sourceMappingURL=chunk-AXF3KYY5.js.map
2162
+ //# sourceMappingURL=chunk-QMV3R6D5.js.map