theokit 0.75.1 → 0.76.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.
Files changed (205) hide show
  1. package/README.md +88 -1
  2. package/dist/{actions-virtual-module-MIQPBAZW.js → actions-virtual-module-52O6HJZT.js} +11 -9
  3. package/dist/actions-virtual-module-52O6HJZT.js.map +1 -0
  4. package/dist/{actions-virtual-module-QEI6QPK4.js → actions-virtual-module-HS4W7HQU.js} +6 -5
  5. package/dist/{actions-virtual-module-QEI6QPK4.js.map → actions-virtual-module-HS4W7HQU.js.map} +1 -1
  6. package/dist/adapters/agent-mount.js +9 -7
  7. package/dist/{agent-N4OV5MDY.js → agent-HCK5RHH7.js} +4 -3
  8. package/dist/{app-typed-client-CHSITA46.js → app-typed-client-BWITJLJA.js} +6 -5
  9. package/dist/{app-typed-client-CHSITA46.js.map → app-typed-client-BWITJLJA.js.map} +1 -1
  10. package/dist/{app-typed-client-XQJXF646.js → app-typed-client-CJCOALMM.js} +11 -9
  11. package/dist/app-typed-client-CJCOALMM.js.map +1 -0
  12. package/dist/{aws-lambda-K5Y6XS5V.js → aws-lambda-XT7ZDJ6B.js} +3 -3
  13. package/dist/{build-GNKTCEES.js → build-Y3CWTWP6.js} +24 -92
  14. package/dist/build-Y3CWTWP6.js.map +1 -0
  15. package/dist/{bun-VPXMWFBA.js → bun-PJLDELDT.js} +5 -5
  16. package/dist/{chunk-J2KYVTPD.js → chunk-2SGNODVJ.js} +30 -16
  17. package/dist/chunk-2SGNODVJ.js.map +1 -0
  18. package/dist/chunk-2SQ7YAU3.js +85 -0
  19. package/dist/chunk-2SQ7YAU3.js.map +1 -0
  20. package/dist/{chunk-SYIQV4UH.js → chunk-36ZACTF3.js} +5 -5
  21. package/dist/{chunk-RY6D4EXL.js → chunk-3GM4GACM.js} +25 -4
  22. package/dist/{chunk-RY6D4EXL.js.map → chunk-3GM4GACM.js.map} +1 -1
  23. package/dist/{chunk-EW5IG7GA.js → chunk-42TYMRBG.js} +1 -1
  24. package/dist/{chunk-EW5IG7GA.js.map → chunk-42TYMRBG.js.map} +1 -1
  25. package/dist/{chunk-BINRCILF.js → chunk-4JRXZTVQ.js} +4 -13
  26. package/dist/chunk-4JRXZTVQ.js.map +1 -0
  27. package/dist/{chunk-R4AMIBZL.js → chunk-4XZOUS5G.js} +8 -8
  28. package/dist/chunk-4XZOUS5G.js.map +1 -0
  29. package/dist/{chunk-ICXXHV4V.js → chunk-54BIQFP4.js} +4 -13
  30. package/dist/chunk-54BIQFP4.js.map +1 -0
  31. package/dist/{chunk-VPK7ABMB.js → chunk-7MCEJVGV.js} +3 -3
  32. package/dist/{chunk-D7STTNQN.js → chunk-BXQCJJPT.js} +3 -3
  33. package/dist/{chunk-NX3P5MLH.js → chunk-C2BRSL4W.js} +50 -6
  34. package/dist/chunk-C2BRSL4W.js.map +1 -0
  35. package/dist/{chunk-E5QTCOKC.js → chunk-FEK25JUL.js} +88 -24
  36. package/dist/chunk-FEK25JUL.js.map +1 -0
  37. package/dist/{chunk-NLHAYGQQ.js → chunk-G3DDIEYE.js} +4 -2
  38. package/dist/chunk-G3DDIEYE.js.map +1 -0
  39. package/dist/chunk-IXXZBZF7.js +70 -0
  40. package/dist/chunk-IXXZBZF7.js.map +1 -0
  41. package/dist/{chunk-PVNMLZ5G.js → chunk-JO462JZM.js} +2 -2
  42. package/dist/chunk-LXV5IEBB.js +76 -0
  43. package/dist/chunk-LXV5IEBB.js.map +1 -0
  44. package/dist/{chunk-D2R5SJEL.js → chunk-MAJZ2L3A.js} +2 -2
  45. package/dist/{chunk-D2R5SJEL.js.map → chunk-MAJZ2L3A.js.map} +1 -1
  46. package/dist/chunk-NF7LXSXZ.js +19 -0
  47. package/dist/chunk-NF7LXSXZ.js.map +1 -0
  48. package/dist/chunk-OED37LE5.js +469 -0
  49. package/dist/chunk-OED37LE5.js.map +1 -0
  50. package/dist/{chunk-CLSYYO5F.js → chunk-OIYSUQM7.js} +2 -2
  51. package/dist/{chunk-2Z7TANA4.js → chunk-PVCXREGE.js} +6 -6
  52. package/dist/{chunk-EVKNHQWG.js → chunk-QBK6YYZA.js} +48 -5
  53. package/dist/chunk-QBK6YYZA.js.map +1 -0
  54. package/dist/{chunk-4X43VTST.js → chunk-TODO6J42.js} +1 -1
  55. package/dist/chunk-TODO6J42.js.map +1 -0
  56. package/dist/{chunk-ZDCCILMP.js → chunk-TQTEKNOL.js} +2 -69
  57. package/dist/chunk-TQTEKNOL.js.map +1 -0
  58. package/dist/{chunk-3MKRDJQ2.js → chunk-UQQQ3V43.js} +278 -75
  59. package/dist/chunk-UQQQ3V43.js.map +1 -0
  60. package/dist/{chunk-MX63AWEK.js → chunk-VXDTQO3S.js} +22 -6
  61. package/dist/{chunk-MX63AWEK.js.map → chunk-VXDTQO3S.js.map} +1 -1
  62. package/dist/{chunk-OZB2TKGJ.js → chunk-W2I6L4IJ.js} +2 -2
  63. package/dist/{chunk-UWV3B3RY.js → chunk-XDLFOATW.js} +5 -5
  64. package/dist/{chunk-RQKMY3JW.js → chunk-XI4FALFZ.js} +3 -3
  65. package/dist/chunk-XI4FALFZ.js.map +1 -0
  66. package/dist/{chunk-2FHNJ7LI.js → chunk-Z76QQR7I.js} +2 -2
  67. package/dist/chunk-ZICY2CD7.js +16 -0
  68. package/dist/chunk-ZICY2CD7.js.map +1 -0
  69. package/dist/chunk-ZN5H7CUR.js +24 -0
  70. package/dist/chunk-ZN5H7CUR.js.map +1 -0
  71. package/dist/{chunk-I5PDEWZZ.js → chunk-ZQJORKBM.js} +9 -3
  72. package/dist/chunk-ZQJORKBM.js.map +1 -0
  73. package/dist/cli/index.js +21 -15
  74. package/dist/cli/index.js.map +1 -1
  75. package/dist/{cloudflare-7EZQE4UV.js → cloudflare-F7KLBOU4.js} +6 -6
  76. package/dist/{config-support-HUZ4DXR7.js → config-support-2TER2BYD.js} +28 -21
  77. package/dist/config-support-2TER2BYD.js.map +1 -0
  78. package/dist/cron-lock-CfAvLApv.d.ts +36 -0
  79. package/dist/db-ZWDKD57T.js +86 -0
  80. package/dist/db-ZWDKD57T.js.map +1 -0
  81. package/dist/{deno-deploy-M5V3PYWU.js → deno-deploy-LJ5JQQVR.js} +5 -5
  82. package/dist/{dev-7PMNIIOF.js → dev-R2ZYHZV4.js} +60 -11
  83. package/dist/dev-R2ZYHZV4.js.map +1 -0
  84. package/dist/{engine-singleton-X4R7AZBJ.js → engine-singleton-BQ5QOMTC.js} +15 -9
  85. package/dist/{engine-singleton-X4R7AZBJ.js.map → engine-singleton-BQ5QOMTC.js.map} +1 -1
  86. package/dist/{generate-RW3NO3NR.js → generate-VXBSMUMW.js} +291 -85
  87. package/dist/generate-VXBSMUMW.js.map +1 -0
  88. package/dist/{index-CmkWlIDO.d.ts → index-DfsJ3Qhk.d.ts} +1 -1
  89. package/dist/index.d.ts +10 -1
  90. package/dist/index.js +12 -10
  91. package/dist/index.js.map +1 -1
  92. package/dist/{info-6NAUW5XY.js → info-IPMW56PI.js} +4 -4
  93. package/dist/{internal-api-R7TTYMCY.js → internal-api-6RAOYIET.js} +6 -5
  94. package/dist/{internal-api-A5HA7TYF.js → internal-api-YGFPLQ4E.js} +14 -11
  95. package/dist/job-backend-WvUs5rO1.d.ts +119 -0
  96. package/dist/{load-config-CLFWJOXN.js → load-config-USRR4GXP.js} +4 -4
  97. package/dist/{mcp-3NRZAQKY.js → mcp-FBXEX45H.js} +5 -4
  98. package/dist/{mcp-3NRZAQKY.js.map → mcp-FBXEX45H.js.map} +1 -1
  99. package/dist/{netlify-NI4HYDKN.js → netlify-ZPQNREFH.js} +2 -2
  100. package/dist/{node-LORYECWI.js → node-3EV3CVWB.js} +2 -2
  101. package/dist/{observability-bootstrap-DOWRMADT.js → observability-bootstrap-DMJ7R6WA.js} +3 -3
  102. package/dist/{openapi-ZHKJB3XL.js → openapi-CA3E3LZH.js} +4 -4
  103. package/dist/{preview-SNS7VJWH.js → preview-DLIVPM7A.js} +3 -3
  104. package/dist/registry-3D2KR7UE.js +34 -0
  105. package/dist/{routes-SMNSI2ZX.js → routes-BJ7GGRCV.js} +4 -4
  106. package/dist/{schema-DJH3IOVR.js → schema-FBM2UH72.js} +3 -3
  107. package/dist/{schemas-2R2J64ZH.js → schemas-BUR6PWSA.js} +2 -2
  108. package/dist/server/agent/index.d.ts +1 -1
  109. package/dist/server/agent/index.js +2 -1
  110. package/dist/server/cost/index.d.ts +2 -2
  111. package/dist/server/cost/index.js +1 -1
  112. package/dist/server/cost/sqlite/index.d.ts +2 -2
  113. package/dist/server/cost/sqlite/index.js +1 -1
  114. package/dist/server/cron/index.d.ts +20 -7
  115. package/dist/server/cron/index.js +8 -2
  116. package/dist/server/http/index.d.ts +2 -2
  117. package/dist/server/http/index.js +9 -7
  118. package/dist/server/index.d.ts +19 -10
  119. package/dist/server/index.js +103 -41
  120. package/dist/server/index.js.map +1 -1
  121. package/dist/server/jobs/index.d.ts +85 -44
  122. package/dist/server/jobs/index.js +9 -2
  123. package/dist/server/observability/index.js +9 -8
  124. package/dist/server/storage/index.d.ts +6 -2
  125. package/dist/server/storage/index.js +5 -1
  126. package/dist/server/webhook/index.d.ts +4 -5
  127. package/dist/server/webhook/index.js +1 -1
  128. package/dist/{server-boundary-ZT6HN7ON.js → server-boundary-EKIGYL7B.js} +6 -5
  129. package/dist/{server-boundary-ZT6HN7ON.js.map → server-boundary-EKIGYL7B.js.map} +1 -1
  130. package/dist/{server-boundary-HYLYGFZY.js → server-boundary-IDWIB24L.js} +11 -9
  131. package/dist/server-boundary-IDWIB24L.js.map +1 -0
  132. package/dist/{start-L5TGWGLU.js → start-LNT5UVSY.js} +118 -185
  133. package/dist/start-LNT5UVSY.js.map +1 -0
  134. package/dist/{static-O2RZ5NLR.js → static-VNN4HYRN.js} +2 -2
  135. package/dist/{storage-manager-3O5PDO6O.js → storage-manager-3IUIEG2P.js} +49 -5
  136. package/dist/storage-manager-3IUIEG2P.js.map +1 -0
  137. package/dist/{storage-manager-BtG38jYl.d.ts → storage-manager-Clu2RBpH.d.ts} +15 -3
  138. package/dist/{storage-types-CFGPFIdB.d.ts → storage-types-ndO0ZZqH.d.ts} +2 -2
  139. package/dist/{theo-cloud-B4R7GCWK.js → theo-cloud-243SPOIA.js} +2 -2
  140. package/dist/{vercel-INHLOCSZ.js → vercel-EXKSZ2OQ.js} +5 -5
  141. package/dist/vite-plugin/index.js +12 -10
  142. package/dist/{vite-plugin-UXEXT7GX.js → vite-plugin-LE42ZIGV.js} +10 -9
  143. package/dist/{whatsapp-D_Fnl1LX.d.ts → whatsapp-4W2eK2ij.d.ts} +1 -1
  144. package/package.json +1 -1
  145. package/dist/actions-virtual-module-MIQPBAZW.js.map +0 -1
  146. package/dist/app-typed-client-XQJXF646.js.map +0 -1
  147. package/dist/build-GNKTCEES.js.map +0 -1
  148. package/dist/chunk-3MKRDJQ2.js.map +0 -1
  149. package/dist/chunk-4X43VTST.js.map +0 -1
  150. package/dist/chunk-BINRCILF.js.map +0 -1
  151. package/dist/chunk-E5QTCOKC.js.map +0 -1
  152. package/dist/chunk-EVKNHQWG.js.map +0 -1
  153. package/dist/chunk-I5PDEWZZ.js.map +0 -1
  154. package/dist/chunk-ICXXHV4V.js.map +0 -1
  155. package/dist/chunk-IDEZ7FU2.js +0 -18
  156. package/dist/chunk-IDEZ7FU2.js.map +0 -1
  157. package/dist/chunk-J2KYVTPD.js.map +0 -1
  158. package/dist/chunk-NLHAYGQQ.js.map +0 -1
  159. package/dist/chunk-NX3P5MLH.js.map +0 -1
  160. package/dist/chunk-R4AMIBZL.js.map +0 -1
  161. package/dist/chunk-RQKMY3JW.js.map +0 -1
  162. package/dist/chunk-YCF3N4JS.js +0 -26
  163. package/dist/chunk-YCF3N4JS.js.map +0 -1
  164. package/dist/chunk-ZDCCILMP.js.map +0 -1
  165. package/dist/config-support-HUZ4DXR7.js.map +0 -1
  166. package/dist/db-IVVCQE5Z.js +0 -76
  167. package/dist/db-IVVCQE5Z.js.map +0 -1
  168. package/dist/dev-7PMNIIOF.js.map +0 -1
  169. package/dist/generate-RW3NO3NR.js.map +0 -1
  170. package/dist/job-backend-CgC8Xf33.d.ts +0 -68
  171. package/dist/registry-3SVWZVIJ.js +0 -34
  172. package/dist/server-boundary-HYLYGFZY.js.map +0 -1
  173. package/dist/start-L5TGWGLU.js.map +0 -1
  174. package/dist/storage-manager-3O5PDO6O.js.map +0 -1
  175. /package/dist/{agent-N4OV5MDY.js.map → agent-HCK5RHH7.js.map} +0 -0
  176. /package/dist/{aws-lambda-K5Y6XS5V.js.map → aws-lambda-XT7ZDJ6B.js.map} +0 -0
  177. /package/dist/{bun-VPXMWFBA.js.map → bun-PJLDELDT.js.map} +0 -0
  178. /package/dist/{chunk-SYIQV4UH.js.map → chunk-36ZACTF3.js.map} +0 -0
  179. /package/dist/{chunk-VPK7ABMB.js.map → chunk-7MCEJVGV.js.map} +0 -0
  180. /package/dist/{chunk-D7STTNQN.js.map → chunk-BXQCJJPT.js.map} +0 -0
  181. /package/dist/{chunk-PVNMLZ5G.js.map → chunk-JO462JZM.js.map} +0 -0
  182. /package/dist/{chunk-CLSYYO5F.js.map → chunk-OIYSUQM7.js.map} +0 -0
  183. /package/dist/{chunk-2Z7TANA4.js.map → chunk-PVCXREGE.js.map} +0 -0
  184. /package/dist/{chunk-OZB2TKGJ.js.map → chunk-W2I6L4IJ.js.map} +0 -0
  185. /package/dist/{chunk-UWV3B3RY.js.map → chunk-XDLFOATW.js.map} +0 -0
  186. /package/dist/{chunk-2FHNJ7LI.js.map → chunk-Z76QQR7I.js.map} +0 -0
  187. /package/dist/{cloudflare-7EZQE4UV.js.map → cloudflare-F7KLBOU4.js.map} +0 -0
  188. /package/dist/{deno-deploy-M5V3PYWU.js.map → deno-deploy-LJ5JQQVR.js.map} +0 -0
  189. /package/dist/{info-6NAUW5XY.js.map → info-IPMW56PI.js.map} +0 -0
  190. /package/dist/{internal-api-R7TTYMCY.js.map → internal-api-6RAOYIET.js.map} +0 -0
  191. /package/dist/{internal-api-A5HA7TYF.js.map → internal-api-YGFPLQ4E.js.map} +0 -0
  192. /package/dist/{load-config-CLFWJOXN.js.map → load-config-USRR4GXP.js.map} +0 -0
  193. /package/dist/{netlify-NI4HYDKN.js.map → netlify-ZPQNREFH.js.map} +0 -0
  194. /package/dist/{node-LORYECWI.js.map → node-3EV3CVWB.js.map} +0 -0
  195. /package/dist/{observability-bootstrap-DOWRMADT.js.map → observability-bootstrap-DMJ7R6WA.js.map} +0 -0
  196. /package/dist/{openapi-ZHKJB3XL.js.map → openapi-CA3E3LZH.js.map} +0 -0
  197. /package/dist/{preview-SNS7VJWH.js.map → preview-DLIVPM7A.js.map} +0 -0
  198. /package/dist/{registry-3SVWZVIJ.js.map → registry-3D2KR7UE.js.map} +0 -0
  199. /package/dist/{routes-SMNSI2ZX.js.map → routes-BJ7GGRCV.js.map} +0 -0
  200. /package/dist/{schema-DJH3IOVR.js.map → schema-FBM2UH72.js.map} +0 -0
  201. /package/dist/{schemas-2R2J64ZH.js.map → schemas-BUR6PWSA.js.map} +0 -0
  202. /package/dist/{static-O2RZ5NLR.js.map → static-VNN4HYRN.js.map} +0 -0
  203. /package/dist/{theo-cloud-B4R7GCWK.js.map → theo-cloud-243SPOIA.js.map} +0 -0
  204. /package/dist/{vercel-INHLOCSZ.js.map → vercel-EXKSZ2OQ.js.map} +0 -0
  205. /package/dist/{vite-plugin-UXEXT7GX.js.map → vite-plugin-LE42ZIGV.js.map} +0 -0
@@ -7,15 +7,22 @@ import {
7
7
  parseCookieHeader
8
8
  } from "./chunk-V7MTRM6Q.js";
9
9
  import {
10
- injectModulePreloads,
11
- parseAssetsMap
12
- } from "./chunk-46FM5AFZ.js";
13
- import {
14
- initCacheEngineFromConfig
15
- } from "./chunk-YCF3N4JS.js";
10
+ configureAgentRegistryFromConfig,
11
+ configureStorageManagerFromConfig,
12
+ createCronScheduler,
13
+ initCacheEngineFromConfig,
14
+ loadCronDefinitions,
15
+ loadJobDefinitions,
16
+ resolveSsrEntry,
17
+ startJobWorker
18
+ } from "./chunk-OED37LE5.js";
16
19
  import {
17
20
  preflightNodeAndBindings
18
21
  } from "./chunk-KTMQUYED.js";
22
+ import {
23
+ injectModulePreloads,
24
+ parseAssetsMap
25
+ } from "./chunk-46FM5AFZ.js";
19
26
  import {
20
27
  applyNonceToInlineScripts,
21
28
  createAgentSubjectResolver,
@@ -23,13 +30,14 @@ import {
23
30
  handleAgentApproval,
24
31
  injectIntoHead,
25
32
  isApprovalPath,
33
+ jobBackendFromConfig,
26
34
  matchAgentAuxRoute,
27
35
  parseApprovalAgentName,
28
36
  resolvePluginSpecifiers,
29
37
  resolveTransformer,
30
38
  serveMatchedAuxRoute,
31
39
  serveThroughPluginLifecycle
32
- } from "./chunk-I5PDEWZZ.js";
40
+ } from "./chunk-ZQJORKBM.js";
33
41
  import "./chunk-BDH5GKFZ.js";
34
42
  import {
35
43
  findRootDiv
@@ -45,11 +53,11 @@ import {
45
53
  mountAgent,
46
54
  readAgentPolicy,
47
55
  writeWebResponseToServerResponse
48
- } from "./chunk-RQKMY3JW.js";
56
+ } from "./chunk-XI4FALFZ.js";
49
57
  import {
50
58
  getApprovalRegistry,
51
59
  resolveProvider
52
- } from "./chunk-BINRCILF.js";
60
+ } from "./chunk-4JRXZTVQ.js";
53
61
  import {
54
62
  createWebRequestSource,
55
63
  dispatchControllerRequest,
@@ -62,9 +70,8 @@ import {
62
70
  import {
63
71
  TRACE_HEADER,
64
72
  createObservabilityPluginFromConfig,
65
- extractTraceId,
66
- generateNewTraceContext
67
- } from "./chunk-MX63AWEK.js";
73
+ extractTraceId
74
+ } from "./chunk-VXDTQO3S.js";
68
75
  import {
69
76
  logRequest,
70
77
  warnOnce
@@ -85,91 +92,21 @@ import {
85
92
  import "./chunk-Z7CJHDLS.js";
86
93
  import {
87
94
  loadConfig
88
- } from "./chunk-OZB2TKGJ.js";
95
+ } from "./chunk-W2I6L4IJ.js";
89
96
  import {
90
97
  loadEnv
91
98
  } from "./chunk-3QPVEJ7D.js";
92
99
  import "./chunk-O5JZ6ROY.js";
93
- import "./chunk-NX3P5MLH.js";
100
+ import "./chunk-C2BRSL4W.js";
94
101
  import "./chunk-L4V5V2TI.js";
95
- import "./chunk-D2R5SJEL.js";
102
+ import "./chunk-MAJZ2L3A.js";
103
+ import "./chunk-NF7LXSXZ.js";
96
104
  import "./chunk-VQIUTCK2.js";
97
105
 
98
106
  // src/cli/commands/start/index.ts
99
- import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
107
+ import { existsSync as existsSync2, readFileSync as readFileSync4 } from "fs";
100
108
  import { createServer } from "http";
101
- import { join as join2, resolve as resolve4 } from "path";
102
-
103
- // src/server/cron/cron-runtime-node.ts
104
- import { CronExpressionParser } from "cron-parser";
105
- function createCronScheduler(definitions) {
106
- const states = definitions.map((def) => ({
107
- def,
108
- inFlight: false,
109
- timer: null,
110
- abortController: null
111
- }));
112
- let started = false;
113
- const fireAndReschedule = (state, scheduledAt) => {
114
- state.timer = null;
115
- if (state.inFlight && state.def.concurrency === "forbid") {
116
- console.warn(
117
- `[theokit:cron] "${state.def.name}" skipped tick at ${scheduledAt.toISOString()} \u2014 previous handler still running (concurrency: forbid).`
118
- );
119
- scheduleNext(state);
120
- return;
121
- }
122
- state.inFlight = true;
123
- state.abortController = new AbortController();
124
- const traceCtx = generateNewTraceContext();
125
- const ctx = {
126
- traceId: traceCtx.trace_id,
127
- scheduledAt,
128
- signal: state.abortController.signal
129
- };
130
- void Promise.resolve().then(() => state.def.handler(ctx)).catch((err) => {
131
- console.error(
132
- `[theokit:cron] "${state.def.name}" handler error:`,
133
- err instanceof Error ? err.message : err
134
- );
135
- }).finally(() => {
136
- state.inFlight = false;
137
- });
138
- scheduleNext(state);
139
- };
140
- const scheduleNext = (state) => {
141
- if (!started) return;
142
- const interval = CronExpressionParser.parse(state.def.schedule, {
143
- tz: "UTC",
144
- currentDate: /* @__PURE__ */ new Date()
145
- });
146
- const next = interval.next().toDate();
147
- const delayMs = Math.max(0, next.getTime() - Date.now());
148
- state.timer = setTimeout(() => {
149
- fireAndReschedule(state, next);
150
- }, delayMs);
151
- };
152
- return {
153
- start() {
154
- if (started) return;
155
- started = true;
156
- for (const state of states) {
157
- scheduleNext(state);
158
- }
159
- },
160
- stop() {
161
- started = false;
162
- for (const state of states) {
163
- if (state.timer) {
164
- clearTimeout(state.timer);
165
- state.timer = null;
166
- }
167
- state.abortController?.abort();
168
- state.abortController = null;
169
- }
170
- }
171
- };
172
- }
109
+ import { join as join2, resolve as resolve3 } from "path";
173
110
 
174
111
  // src/server/define/health-route.ts
175
112
  var HEALTH_PATH = "/__theo/health";
@@ -406,84 +343,72 @@ function assertSdkCompatible(opts) {
406
343
  }
407
344
  }
408
345
 
409
- // src/cli/commands/start/bootstrap-stages.ts
410
- import { existsSync } from "fs";
346
+ // src/cli/commands/start/background-work.ts
411
347
  import { resolve } from "path";
412
- async function configureAgentRegistryFromConfig(registryConfig) {
413
- if (registryConfig === void 0) return;
414
- try {
415
- const sdk = await import("@theokit/sdk").catch(() => null);
416
- const sdkConfigure = sdk?.Agent?.registry?.configure;
417
- if (sdkConfigure === void 0) return;
418
- const { configureAgentRegistryOnce } = await import("./configure-agent-registry-ZOBVU3MV.js");
419
- configureAgentRegistryOnce(
420
- {
421
- configure: (opts) => {
422
- sdkConfigure(opts);
423
- }
424
- },
425
- registryConfig
426
- );
427
- } catch (err) {
428
- const msg = err instanceof Error ? err.message : String(err);
429
- warnOnce("bootstrap.agent_registry_skip", {
430
- event: "bootstrap.agent_registry_skip",
431
- message: msg
432
- });
348
+
349
+ // src/server/cron/cron-lock-from-config.ts
350
+ function cronLockFromConfig(config) {
351
+ const declared = config.cron?.lock;
352
+ if (declared === false) {
353
+ return { lock: void 0, description: "no distributed lock (cron.lock: false)" };
433
354
  }
434
- }
435
- async function configureStorageManagerFromConfig(storageConfig) {
436
- if (storageConfig === void 0 || storageConfig === null) return;
437
- try {
438
- const { getStorageManager } = await import("./storage-manager-3O5PDO6O.js");
439
- const { storageSchema } = await import("./schema-DJH3IOVR.js");
440
- const parsed = storageSchema.parse(storageConfig);
441
- getStorageManager().configure(parsed);
442
- } catch (err) {
443
- const msg = err instanceof Error ? err.message : String(err);
444
- warnOnce("bootstrap.storage_skip", {
445
- event: "bootstrap.storage_skip",
446
- message: msg
447
- });
355
+ if (declared !== void 0) {
356
+ return {
357
+ lock: declared,
358
+ description: "one firing per tick across processes (cron.lock)"
359
+ };
448
360
  }
449
- }
450
- var SSR_EXTENSIONS = [".mjs", ".js"];
451
- function resolveSsrEntry(distDir) {
452
- for (const ext of SSR_EXTENSIONS) {
453
- const path = resolve(distDir, `server/entry-server${ext}`);
454
- if (existsSync(path)) return path;
361
+ const backend = config.jobs?.backend;
362
+ if (backend !== void 0 && typeof backend.cronLock === "function") {
363
+ const lock = backend.cronLock.call(backend);
364
+ return {
365
+ lock,
366
+ description: `one firing per tick across processes (lock on the ${String(backend.name)} jobs backend)`
367
+ };
455
368
  }
456
- return null;
369
+ return {
370
+ lock: void 0,
371
+ description: "no distributed lock: every process running theokit start fires each cron. Run one replica, or set cron.lock (a PostgresJobBackend in jobs.backend provides one)"
372
+ };
457
373
  }
458
374
 
459
- // src/cli/commands/start/cron-bootstrap.ts
460
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
461
- import { resolve as resolve2 } from "path";
462
- async function loadCronDefinitions(manifestPath, projectRoot, loadModule) {
463
- if (!existsSync2(manifestPath)) return [];
464
- const manifest = JSON.parse(readFileSync2(manifestPath, "utf-8"));
465
- const definitions = [];
466
- for (const entry of manifest.crons) {
467
- const filePath = resolve2(projectRoot, entry.filePath);
468
- const mod = await loadModule(filePath);
469
- const exported = mod.default;
470
- if (!isCronDefinition(exported)) {
471
- throw new Error(
472
- `Cron "${entry.name}" declared in "${entry.filePath}" is missing a valid default export. Expected \`export default defineCron(name, { schedule, handler })\`. Re-run \`theokit build\` if the file changed since the last build.`
473
- );
474
- }
475
- definitions.push(exported);
375
+ // src/cli/commands/start/background-work.ts
376
+ async function startBackgroundWork(config, distDir, projectRoot, loadModule) {
377
+ const summaries = [];
378
+ const cronDefinitions = await loadCronDefinitions(
379
+ resolve(distDir, "crons.json"),
380
+ projectRoot,
381
+ loadModule
382
+ );
383
+ let scheduler;
384
+ if (cronDefinitions.length > 0) {
385
+ const { lock, description } = cronLockFromConfig(config);
386
+ scheduler = createCronScheduler(cronDefinitions, { lock });
387
+ scheduler.start();
388
+ summaries.push(`Crons: ${String(cronDefinitions.length)} scheduled in-process, ${description}`);
476
389
  }
477
- return definitions;
478
- }
479
- function isCronDefinition(value) {
480
- if (typeof value !== "object" || value === null) return false;
481
- const candidate = value;
482
- return typeof candidate.name === "string" && typeof candidate.schedule === "string" && typeof candidate.handler === "function";
390
+ const jobDefinitions = await loadJobDefinitions(
391
+ resolve(distDir, "jobs.json"),
392
+ projectRoot,
393
+ loadModule
394
+ );
395
+ const jobs = startJobWorker(config, jobDefinitions);
396
+ if (jobs.summary !== void 0) summaries.push(jobs.summary);
397
+ return {
398
+ summaries,
399
+ async stop() {
400
+ scheduler?.stop();
401
+ if (jobs.worker !== void 0) {
402
+ await jobs.worker.stop();
403
+ console.log(" [theokit] jobs worker stopped");
404
+ }
405
+ }
406
+ };
483
407
  }
484
408
 
485
409
  // src/cli/commands/start/graceful-shutdown.ts
486
- function installGracefulShutdown(server) {
410
+ var BACKGROUND_STOP_BUDGET_MS = 2e4;
411
+ function installGracefulShutdown(server, stopBackgroundWork = () => Promise.resolve()) {
487
412
  let shuttingDown = false;
488
413
  const shutdown = (signal) => {
489
414
  if (shuttingDown) return;
@@ -491,6 +416,17 @@ function installGracefulShutdown(server) {
491
416
  console.log(`
492
417
  [theokit] ${signal} received \u2014 evicting agents`);
493
418
  void (async () => {
419
+ try {
420
+ await Promise.race([
421
+ stopBackgroundWork(),
422
+ new Promise((resolve4) => setTimeout(resolve4, BACKGROUND_STOP_BUDGET_MS).unref())
423
+ ]);
424
+ } catch (err) {
425
+ warnOnce("shutdown.background_error", {
426
+ event: "shutdown.background_error",
427
+ message: err instanceof Error ? err.message : String(err)
428
+ });
429
+ }
494
430
  try {
495
431
  const sdk = await import("@theokit/sdk").catch(() => null);
496
432
  if (sdk?.Agent?.registry?.evictAll !== void 0) {
@@ -504,7 +440,7 @@ function installGracefulShutdown(server) {
504
440
  });
505
441
  }
506
442
  try {
507
- const { getStorageManager } = await import("./storage-manager-3O5PDO6O.js");
443
+ const { getStorageManager } = await import("./storage-manager-3IUIEG2P.js");
508
444
  const manager = getStorageManager();
509
445
  await manager.dispose();
510
446
  } catch (err) {
@@ -515,7 +451,7 @@ function installGracefulShutdown(server) {
515
451
  });
516
452
  }
517
453
  try {
518
- const { getObservabilityAdapter } = await import("./observability-bootstrap-DOWRMADT.js");
454
+ const { getObservabilityAdapter } = await import("./observability-bootstrap-DMJ7R6WA.js");
519
455
  await getObservabilityAdapter()?.shutdown();
520
456
  } catch (err) {
521
457
  const msg = err instanceof Error ? err.message : String(err);
@@ -546,11 +482,11 @@ function installGracefulShutdown(server) {
546
482
  }
547
483
 
548
484
  // src/cli/commands/start/manifest-loader.ts
549
- import { existsSync as existsSync3 } from "fs";
485
+ import { existsSync } from "fs";
550
486
  import { dirname, join } from "path";
551
487
  function loadRoutesAndActions(distDir, serverDir, agentsDir = "agents", projectRoot = dirname(serverDir)) {
552
488
  const manifestPath = join(distDir, "manifest.json");
553
- if (existsSync3(manifestPath)) {
489
+ if (existsSync(manifestPath)) {
554
490
  const manifest = loadManifest(distDir, serverDir, projectRoot);
555
491
  return {
556
492
  routes: manifest.routes,
@@ -646,8 +582,8 @@ import { extname as extname2 } from "path";
646
582
  import { pathToFileURL } from "url";
647
583
 
648
584
  // src/server/http/static.ts
649
- import { closeSync, fstatSync, openSync, readFileSync as readFileSync3, realpathSync } from "fs";
650
- import { resolve as resolve3, extname, sep } from "path";
585
+ import { closeSync, fstatSync, openSync, readFileSync as readFileSync2, realpathSync } from "fs";
586
+ import { resolve as resolve2, extname, sep } from "path";
651
587
  var MIME_TYPES = {
652
588
  ".html": "text/html",
653
589
  ".js": "application/javascript",
@@ -668,7 +604,7 @@ var MIME_TYPES = {
668
604
  };
669
605
  function serveStaticFile(req, res, clientDir) {
670
606
  const urlPath = (req.url ?? "/").split("?")[0];
671
- const filePath = resolve3(clientDir, "." + urlPath);
607
+ const filePath = resolve2(clientDir, "." + urlPath);
672
608
  if (filePath !== clientDir && !filePath.startsWith(clientDir + sep)) {
673
609
  res.writeHead(403);
674
610
  res.end("Forbidden");
@@ -693,7 +629,7 @@ function serveStaticFile(req, res, clientDir) {
693
629
  if (!fstatSync(fd).isFile()) return false;
694
630
  const ext = extname(filePath);
695
631
  const contentType = MIME_TYPES[ext] ?? "application/octet-stream";
696
- const content = readFileSync3(fd);
632
+ const content = readFileSync2(fd);
697
633
  res.writeHead(200, {
698
634
  "Content-Type": contentType,
699
635
  "Content-Length": content.length
@@ -1006,7 +942,8 @@ async function tryServeApiRoute(c) {
1006
942
  pluginRunner: c.pluginRunner,
1007
943
  transformer: c.transformer,
1008
944
  csrfMode: c.csrfMode,
1009
- disallowed: c.disallowed
945
+ disallowed: c.disallowed,
946
+ jobBackend: c.jobBackend
1010
947
  });
1011
948
  logRequest({
1012
949
  method,
@@ -1031,7 +968,7 @@ function tryServeCustom404(c) {
1031
968
  }
1032
969
 
1033
970
  // src/cli/commands/start/ssr-setup.ts
1034
- import { readFileSync as readFileSync4 } from "fs";
971
+ import { readFileSync as readFileSync3 } from "fs";
1035
972
  function isSsrRenderResult(value) {
1036
973
  if (typeof value !== "object" || value === null) return false;
1037
974
  if (!("html" in value)) return false;
@@ -1067,7 +1004,7 @@ async function setupSsr(opts) {
1067
1004
  }
1068
1005
  function loadAssetsMap(path) {
1069
1006
  try {
1070
- return parseAssetsMap(readFileSync4(path, "utf8"));
1007
+ return parseAssetsMap(readFileSync3(path, "utf8"));
1071
1008
  } catch {
1072
1009
  return void 0;
1073
1010
  }
@@ -1303,15 +1240,15 @@ async function startCommand(options) {
1303
1240
  await configureAgentRegistryFromConfig(config.agents?.registry);
1304
1241
  await configureStorageManagerFromConfig(config.storage);
1305
1242
  await initCacheEngineFromConfig(config.cache);
1306
- const distDir = resolve4(cwd, ".theokit");
1307
- const clientDir = resolve4(distDir, "client");
1308
- const assetsMap = loadAssetsMap(resolve4(clientDir, "assets-map.json"));
1309
- const controllersDistDir = existsSync4(resolve4(distDir, CONTROLLER_MANIFEST_FILE)) ? resolve4(distDir, "controllers") : void 0;
1310
- const serverDir = resolve4(cwd, config.serverDir);
1311
- if (!existsSync4(clientDir)) {
1243
+ const distDir = resolve3(cwd, ".theokit");
1244
+ const clientDir = resolve3(distDir, "client");
1245
+ const assetsMap = loadAssetsMap(resolve3(clientDir, "assets-map.json"));
1246
+ const controllersDistDir = existsSync2(resolve3(distDir, CONTROLLER_MANIFEST_FILE)) ? resolve3(distDir, "controllers") : void 0;
1247
+ const serverDir = resolve3(cwd, config.serverDir);
1248
+ if (!existsSync2(clientDir)) {
1312
1249
  throw new Error("No build found. Run `theo build` first.");
1313
1250
  }
1314
- const indexHtml = readFileSync5(join2(clientDir, "index.html"), "utf-8");
1251
+ const indexHtml = readFileSync4(join2(clientDir, "index.html"), "utf-8");
1315
1252
  const loadModule = createProductionLoader();
1316
1253
  const envPort = Number.parseInt(process.env.PORT ?? "", 10);
1317
1254
  const port = options.port ?? (Number.isInteger(envPort) ? envPort : void 0) ?? config.port;
@@ -1323,8 +1260,8 @@ async function startCommand(options) {
1323
1260
  const transformer = resolveTransformer(config.serialization);
1324
1261
  const custom404Path = join2(clientDir, "404.html");
1325
1262
  const custom500Path = join2(clientDir, "500.html");
1326
- const custom404Html = existsSync4(custom404Path) ? readFileSync5(custom404Path, "utf-8") : null;
1327
- const custom500Html = existsSync4(custom500Path) ? readFileSync5(custom500Path, "utf-8") : null;
1263
+ const custom404Html = existsSync2(custom404Path) ? readFileSync4(custom404Path, "utf-8") : null;
1264
+ const custom500Html = existsSync2(custom500Path) ? readFileSync4(custom500Path, "utf-8") : null;
1328
1265
  const {
1329
1266
  routes: cachedRoutes,
1330
1267
  actions: cachedActions,
@@ -1359,6 +1296,7 @@ async function startCommand(options) {
1359
1296
  transformer,
1360
1297
  csrfMode: config.security?.csrf ?? "strict",
1361
1298
  disallowed: config.security?.disallowed,
1299
+ jobBackend: jobBackendFromConfig(config),
1362
1300
  rateLimiter
1363
1301
  }),
1364
1302
  securityHeadersConfig: config.security?.headers ?? {},
@@ -1381,10 +1319,6 @@ async function startCommand(options) {
1381
1319
  })
1382
1320
  );
1383
1321
  await attachWebSocketHandler(server, cachedWsRoutes, loadModule);
1384
- const cronDefinitions = await loadCronDefinitions(resolve4(distDir, "crons.json"), cwd, loadModule);
1385
- if (cronDefinitions.length > 0) {
1386
- createCronScheduler(cronDefinitions).start();
1387
- }
1388
1322
  const listenTarget = resolveListenTarget(config.host);
1389
1323
  const exposure = assessPublicExposure({
1390
1324
  routes: cachedRoutes,
@@ -1407,6 +1341,7 @@ async function startCommand(options) {
1407
1341
  ${exposure.message}
1408
1342
  `);
1409
1343
  }
1344
+ const background = await startBackgroundWork(config, distDir, cwd, loadModule);
1410
1345
  server.listen(port, listenTarget.host, () => {
1411
1346
  console.log(`
1412
1347
  Theo production server`);
@@ -1420,15 +1355,13 @@ async function startCommand(options) {
1420
1355
  for (const e of exposure.exposures) console.warn(` ${e.method} ${e.routePath}`);
1421
1356
  console.warn("");
1422
1357
  }
1423
- if (cronDefinitions.length > 0) {
1424
- console.log(` Crons: ${String(cronDefinitions.length)} scheduled in-process
1358
+ for (const line of background.summaries) console.log(` ${line}
1425
1359
  `);
1426
- }
1427
1360
  });
1428
- installGracefulShutdown(server);
1361
+ installGracefulShutdown(server, () => background.stop());
1429
1362
  }
1430
1363
  export {
1431
1364
  resolveSsrEntry,
1432
1365
  startCommand
1433
1366
  };
1434
- //# sourceMappingURL=start-L5TGWGLU.js.map
1367
+ //# sourceMappingURL=start-LNT5UVSY.js.map