theokit 0.48.13 → 0.50.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 (327) hide show
  1. package/README.md +1 -0
  2. package/dist/{actions-virtual-module-YQXRSSMW.js → actions-virtual-module-5WBVSDOM.js} +22 -12
  3. package/dist/actions-virtual-module-5WBVSDOM.js.map +1 -0
  4. package/dist/{actions-virtual-module-LB4NGONI.js → actions-virtual-module-ZYLMNW6K.js} +13 -8
  5. package/dist/{actions-virtual-module-LB4NGONI.js.map → actions-virtual-module-ZYLMNW6K.js.map} +1 -1
  6. package/dist/adapters/agent-mount.d.ts +127 -0
  7. package/dist/adapters/agent-mount.js +24 -0
  8. package/dist/adapters/security-headers.d.ts +132 -0
  9. package/dist/adapters/security-headers.js +64 -0
  10. package/dist/adapters/security-headers.js.map +1 -0
  11. package/dist/adapters/web-shim.d.ts +100 -13
  12. package/dist/adapters/web-shim.js +158 -54
  13. package/dist/adapters/web-shim.js.map +1 -1
  14. package/dist/agent-GKUEL6OH.js +15 -0
  15. package/dist/agent-scan-BZa-pagG.d.ts +16 -0
  16. package/dist/{app-typed-client-GHO3EWZK.js → app-typed-client-4LAIEGFX.js} +23 -13
  17. package/dist/app-typed-client-4LAIEGFX.js.map +1 -0
  18. package/dist/{app-typed-client-G3J5G7E5.js → app-typed-client-DQM3Y6YY.js} +14 -9
  19. package/dist/app-typed-client-DQM3Y6YY.js.map +1 -0
  20. package/dist/aws-lambda-VKMYUMP2.js +261 -0
  21. package/dist/aws-lambda-VKMYUMP2.js.map +1 -0
  22. package/dist/{build-WU6AKKIB.js → build-FLX6VF7Q.js} +71 -26
  23. package/dist/build-FLX6VF7Q.js.map +1 -0
  24. package/dist/{bun-33RD6K7O.js → bun-L7PP6ID5.js} +105 -13
  25. package/dist/bun-L7PP6ID5.js.map +1 -0
  26. package/dist/{check-45NKUVSQ.js → check-GIPZBFTX.js} +2 -2
  27. package/dist/{chunk-KD5G3YXI.js → chunk-2AMLGJJA.js} +35 -9
  28. package/dist/chunk-2AMLGJJA.js.map +1 -0
  29. package/dist/chunk-3PBAN2YE.js +146 -0
  30. package/dist/chunk-3PBAN2YE.js.map +1 -0
  31. package/dist/{chunk-HBU2GIMZ.js → chunk-3QPVEJ7D.js} +15 -9
  32. package/dist/chunk-3QPVEJ7D.js.map +1 -0
  33. package/dist/{chunk-47CINLWF.js → chunk-44J2ANQC.js} +2 -2
  34. package/dist/{chunk-IEES3CHD.js → chunk-47MM2JUK.js} +8 -2
  35. package/dist/chunk-47MM2JUK.js.map +1 -0
  36. package/dist/chunk-4X6H2BXP.js +108 -0
  37. package/dist/chunk-4X6H2BXP.js.map +1 -0
  38. package/dist/{chunk-A7JBF5FO.js → chunk-5K4TDLRG.js} +8 -5
  39. package/dist/chunk-5K4TDLRG.js.map +1 -0
  40. package/dist/chunk-5YPXXSYY.js +181 -0
  41. package/dist/chunk-5YPXXSYY.js.map +1 -0
  42. package/dist/{chunk-YGAXV5HR.js → chunk-6J4JWHDJ.js} +191 -112
  43. package/dist/chunk-6J4JWHDJ.js.map +1 -0
  44. package/dist/chunk-72DMJBXI.js +424 -0
  45. package/dist/chunk-72DMJBXI.js.map +1 -0
  46. package/dist/chunk-7PM6K5EV.js +513 -0
  47. package/dist/chunk-7PM6K5EV.js.map +1 -0
  48. package/dist/{chunk-MTEWLGVY.js → chunk-BPYMC7SU.js} +4 -48
  49. package/dist/chunk-BPYMC7SU.js.map +1 -0
  50. package/dist/chunk-BU6RJPPJ.js +421 -0
  51. package/dist/chunk-BU6RJPPJ.js.map +1 -0
  52. package/dist/{chunk-FB2HBNIC.js → chunk-BX6EUYHU.js} +6 -2
  53. package/dist/chunk-BX6EUYHU.js.map +1 -0
  54. package/dist/{chunk-BIVCP6X5.js → chunk-C62IZEJI.js} +465 -202
  55. package/dist/chunk-C62IZEJI.js.map +1 -0
  56. package/dist/chunk-D4VP2QPR.js +16 -0
  57. package/dist/chunk-D4VP2QPR.js.map +1 -0
  58. package/dist/{chunk-J5MXCGKA.js → chunk-DHAD2O3S.js} +6 -6
  59. package/dist/chunk-DHAD2O3S.js.map +1 -0
  60. package/dist/chunk-E43VJ3E5.js +188 -0
  61. package/dist/chunk-E43VJ3E5.js.map +1 -0
  62. package/dist/chunk-EVZKNA2W.js +110 -0
  63. package/dist/chunk-EVZKNA2W.js.map +1 -0
  64. package/dist/chunk-FD4ZDTQ6.js +181 -0
  65. package/dist/chunk-FD4ZDTQ6.js.map +1 -0
  66. package/dist/chunk-FDOOBTXJ.js +17 -0
  67. package/dist/chunk-FDOOBTXJ.js.map +1 -0
  68. package/dist/chunk-FH3SQR6P.js +275 -0
  69. package/dist/chunk-FH3SQR6P.js.map +1 -0
  70. package/dist/chunk-HJHGTFEJ.js +23 -0
  71. package/dist/chunk-HJHGTFEJ.js.map +1 -0
  72. package/dist/{chunk-LXAESF4Y.js → chunk-HK4AZBKX.js} +7 -4
  73. package/dist/chunk-HK4AZBKX.js.map +1 -0
  74. package/dist/{chunk-T5C46IIU.js → chunk-HWBRS4DZ.js} +28 -269
  75. package/dist/chunk-HWBRS4DZ.js.map +1 -0
  76. package/dist/chunk-IRQGAC4L.js +52 -0
  77. package/dist/chunk-IRQGAC4L.js.map +1 -0
  78. package/dist/{chunk-FNTLKHZ7.js → chunk-JDN5SAAD.js} +7 -4
  79. package/dist/chunk-JDN5SAAD.js.map +1 -0
  80. package/dist/{chunk-GXEX4CBH.js → chunk-JIKNR5LX.js} +673 -484
  81. package/dist/chunk-JIKNR5LX.js.map +1 -0
  82. package/dist/{chunk-GRI4XHBJ.js → chunk-JWRCZIA4.js} +266 -108
  83. package/dist/chunk-JWRCZIA4.js.map +1 -0
  84. package/dist/{chunk-E576KYYT.js → chunk-KI4DOTN4.js} +25 -2
  85. package/dist/chunk-KI4DOTN4.js.map +1 -0
  86. package/dist/{chunk-ZB7D62OA.js → chunk-KUZVRJ7M.js} +3 -3
  87. package/dist/chunk-L4VFNFDL.js +248 -0
  88. package/dist/chunk-L4VFNFDL.js.map +1 -0
  89. package/dist/chunk-M2WC5MF7.js +127 -0
  90. package/dist/chunk-M2WC5MF7.js.map +1 -0
  91. package/dist/{chunk-O3JIAU3V.js → chunk-MCTC6HSE.js} +157 -103
  92. package/dist/chunk-MCTC6HSE.js.map +1 -0
  93. package/dist/{chunk-PXFXSFJL.js → chunk-NZ5JU6D3.js} +9 -9
  94. package/dist/{chunk-YRBR424R.js → chunk-OAUI273L.js} +338 -165
  95. package/dist/chunk-OAUI273L.js.map +1 -0
  96. package/dist/chunk-OGLS76RN.js +43 -0
  97. package/dist/chunk-OGLS76RN.js.map +1 -0
  98. package/dist/{chunk-7LVM22VG.js → chunk-OQCRCXCP.js} +6 -6
  99. package/dist/chunk-OQCRCXCP.js.map +1 -0
  100. package/dist/{chunk-OLGPYOLO.js → chunk-P6OS7652.js} +5 -2
  101. package/dist/chunk-P6OS7652.js.map +1 -0
  102. package/dist/chunk-Q5L5EGWZ.js +26 -0
  103. package/dist/chunk-Q5L5EGWZ.js.map +1 -0
  104. package/dist/{chunk-S433N3CT.js → chunk-QTHVHNJJ.js} +6 -36
  105. package/dist/chunk-QTHVHNJJ.js.map +1 -0
  106. package/dist/chunk-RPET332G.js +84 -0
  107. package/dist/chunk-RPET332G.js.map +1 -0
  108. package/dist/{chunk-646CA6RV.js → chunk-RQW5YMH7.js} +12 -4
  109. package/dist/chunk-RQW5YMH7.js.map +1 -0
  110. package/dist/{chunk-XALU5LCU.js → chunk-RWNYIU6A.js} +550 -146
  111. package/dist/chunk-RWNYIU6A.js.map +1 -0
  112. package/dist/chunk-SL7YUHPV.js +111 -0
  113. package/dist/chunk-SL7YUHPV.js.map +1 -0
  114. package/dist/chunk-U5PWXS3J.js +39 -0
  115. package/dist/chunk-U5PWXS3J.js.map +1 -0
  116. package/dist/chunk-ULDCFL2O.js +273 -0
  117. package/dist/chunk-ULDCFL2O.js.map +1 -0
  118. package/dist/{chunk-RWNSW4FM.js → chunk-UMNXCU3K.js} +12 -6
  119. package/dist/{chunk-RWNSW4FM.js.map → chunk-UMNXCU3K.js.map} +1 -1
  120. package/dist/chunk-VI7ZANB3.js +193 -0
  121. package/dist/chunk-VI7ZANB3.js.map +1 -0
  122. package/dist/chunk-VQPHPQ5L.js +14 -0
  123. package/dist/chunk-VQPHPQ5L.js.map +1 -0
  124. package/dist/chunk-WNJTJRM6.js +147 -0
  125. package/dist/chunk-WNJTJRM6.js.map +1 -0
  126. package/dist/chunk-WOBSEO75.js +790 -0
  127. package/dist/chunk-WOBSEO75.js.map +1 -0
  128. package/dist/{chunk-BMHS4WAN.js → chunk-XS7EX55U.js} +156 -42
  129. package/dist/chunk-XS7EX55U.js.map +1 -0
  130. package/dist/chunk-YN4W7LCX.js +31 -0
  131. package/dist/chunk-YN4W7LCX.js.map +1 -0
  132. package/dist/chunk-YSJOZEI6.js +1 -0
  133. package/dist/{chunk-JA2ZAT5Q.js → chunk-Z4PJMZLM.js} +2 -2
  134. package/dist/chunk-Z4PJMZLM.js.map +1 -0
  135. package/dist/{chunk-7VPQHEAJ.js → chunk-ZNZISJDZ.js} +6 -2
  136. package/dist/chunk-ZNZISJDZ.js.map +1 -0
  137. package/dist/chunk-ZWN3AODA.js +11 -0
  138. package/dist/chunk-ZWN3AODA.js.map +1 -0
  139. package/dist/cli/index.js +25 -10
  140. package/dist/cli/index.js.map +1 -1
  141. package/dist/client/core.d.ts +1 -1
  142. package/dist/client/core.js +2 -0
  143. package/dist/client/core.js.map +1 -1
  144. package/dist/client/index.d.ts +44 -10
  145. package/dist/client/index.js +35 -0
  146. package/dist/client/index.js.map +1 -1
  147. package/dist/cloudflare-SIG42OIW.js +335 -0
  148. package/dist/cloudflare-SIG42OIW.js.map +1 -0
  149. package/dist/config-support-WQHQIJTA.js +104 -0
  150. package/dist/config-support-WQHQIJTA.js.map +1 -0
  151. package/dist/{csrf-BBrEZSBW.d.ts → csrf-Dgot9qSM.d.ts} +1 -1
  152. package/dist/deno-deploy-LQAYOOPW.js +196 -0
  153. package/dist/deno-deploy-LQAYOOPW.js.map +1 -0
  154. package/dist/{dev-MUWJAZRD.js → dev-ANDSEVLB.js} +28 -18
  155. package/dist/dev-ANDSEVLB.js.map +1 -0
  156. package/dist/{dev-emit-GWD6IXV7.js → dev-emit-BFNMDCPB.js} +5 -5
  157. package/dist/{dev-emit-NBT6JD7R.js → dev-emit-MVAJAFGX.js} +5 -3
  158. package/dist/dev-emit-MVAJAFGX.js.map +1 -0
  159. package/dist/engine-singleton-X4R7AZBJ.js +315 -0
  160. package/dist/engine-singleton-X4R7AZBJ.js.map +1 -0
  161. package/dist/{generate-Y3GWM57K.js → generate-EN6EDITF.js} +43 -4
  162. package/dist/generate-EN6EDITF.js.map +1 -0
  163. package/dist/index-CzxtQcnp.d.ts +1058 -0
  164. package/dist/index.d.ts +4 -0
  165. package/dist/index.js +24 -13
  166. package/dist/index.js.map +1 -1
  167. package/dist/{info-XW7HGUPH.js → info-Y55RWS42.js} +8 -6
  168. package/dist/{info-XW7HGUPH.js.map → info-Y55RWS42.js.map} +1 -1
  169. package/dist/{internal-api-V5L65YSJ.js → internal-api-IP35YU3G.js} +22 -12
  170. package/dist/{internal-api-WEOSTMSN.js → internal-api-OPU456AT.js} +30 -16
  171. package/dist/internal-api-OPU456AT.js.map +1 -0
  172. package/dist/load-config-4ATXQUN3.js +16 -0
  173. package/dist/match-DmGgxjIU.d.ts +44 -0
  174. package/dist/{mcp-ULUFJNSZ.js → mcp-5LLNAGKA.js} +7 -7
  175. package/dist/netlify-C2IRCZKI.js +245 -0
  176. package/dist/netlify-C2IRCZKI.js.map +1 -0
  177. package/dist/node-OSVPYQ3D.js +10 -0
  178. package/dist/nonce-BXt7Qu_C.d.ts +31 -0
  179. package/dist/observability-bootstrap-MZMSOE66.js +15 -0
  180. package/dist/{openapi-HZXR335W.js → openapi-VFPEZSRI.js} +13 -11
  181. package/dist/{openapi-HZXR335W.js.map → openapi-VFPEZSRI.js.map} +1 -1
  182. package/dist/{plugin-runner-BFEcgtmJ.d.ts → plugin-runner-BVMOSxvb.d.ts} +1 -1
  183. package/dist/{plugin-types-D69-lJZ9.d.ts → plugin-types-BUVfUQ0V.d.ts} +13 -1
  184. package/dist/preview-GHPT2EQ5.js +23 -0
  185. package/dist/preview-GHPT2EQ5.js.map +1 -0
  186. package/dist/provider-resolver-Dx6QuWrw.d.ts +128 -0
  187. package/dist/registry-KBZDCFVQ.js +23 -0
  188. package/dist/route-config-Cm_ZMA1C.d.ts +72 -0
  189. package/dist/route-policy-BxOycCDq.d.ts +65 -0
  190. package/dist/router/element-scroll-restoration.d.ts +28 -0
  191. package/dist/router/element-scroll-restoration.js +96 -0
  192. package/dist/router/element-scroll-restoration.js.map +1 -0
  193. package/dist/{routes-OLNQX7CT.js → routes-BPLU3ISV.js} +11 -9
  194. package/dist/{routes-OLNQX7CT.js.map → routes-BPLU3ISV.js.map} +1 -1
  195. package/dist/{scan-7MJC6PYU.js → scan-YJEE4KQK.js} +2 -2
  196. package/dist/{schema-ZO3OSWVG.js → schema-SOAD43RQ.js} +7 -5
  197. package/dist/schemas-4AXHQMV3.js +25 -0
  198. package/dist/schemas-4AXHQMV3.js.map +1 -0
  199. package/dist/security-headers-Ccj7ncNx.d.ts +129 -0
  200. package/dist/server/agent/index.d.ts +2 -90
  201. package/dist/server/agent/index.js +1 -1
  202. package/dist/server/auth/index.d.ts +2 -21
  203. package/dist/server/auth/index.js +3 -2
  204. package/dist/server/cron/index.js +4 -3
  205. package/dist/server/define/index.d.ts +51 -57
  206. package/dist/server/define/index.js +10 -1
  207. package/dist/server/http/index.d.ts +7 -5
  208. package/dist/server/http/index.js +56 -12
  209. package/dist/server/index.d.ts +47 -439
  210. package/dist/server/index.js +119 -201
  211. package/dist/server/index.js.map +1 -1
  212. package/dist/server/jobs/index.js +4 -3
  213. package/dist/server/observability/index.d.ts +109 -35
  214. package/dist/server/observability/index.js +10 -7
  215. package/dist/server/plugins/index.d.ts +3 -3
  216. package/dist/server/scan/index.d.ts +47 -12
  217. package/dist/server/scan/index.js +13 -4
  218. package/dist/server/security/index.d.ts +61 -103
  219. package/dist/server/security/index.js +15 -6
  220. package/dist/server/webhook/index.d.ts +90 -3
  221. package/dist/server/webhook/index.js +12 -2
  222. package/dist/server-boundary-6B4ZQUY7.js +148 -0
  223. package/dist/server-boundary-6B4ZQUY7.js.map +1 -0
  224. package/dist/server-boundary-7VZQRPPX.js +133 -0
  225. package/dist/server-boundary-7VZQRPPX.js.map +1 -0
  226. package/dist/{services-typed-client-PSAGRPFF.js → services-typed-client-XGT5SUUN.js} +2 -2
  227. package/dist/{start-KR2JJR7K.js → start-UZDMOT7I.js} +342 -111
  228. package/dist/start-UZDMOT7I.js.map +1 -0
  229. package/dist/{static-M2W4HUWS.js → static-SVDWIOXJ.js} +24 -13
  230. package/dist/static-SVDWIOXJ.js.map +1 -0
  231. package/dist/{theo-cloud-XAHWOUFK.js → theo-cloud-3ET4G5T6.js} +9 -2
  232. package/dist/theo-cloud-3ET4G5T6.js.map +1 -0
  233. package/dist/vercel-BMCQKCWE.js +277 -0
  234. package/dist/vercel-BMCQKCWE.js.map +1 -0
  235. package/dist/vite-plugin/index.js +24 -13
  236. package/dist/vite-plugin-VKCT2LF2.js +42 -0
  237. package/dist/vite-plugin-VKCT2LF2.js.map +1 -0
  238. package/package.json +19 -6
  239. package/dist/actions-virtual-module-YQXRSSMW.js.map +0 -1
  240. package/dist/agent-7JJW3TPB.js +0 -15
  241. package/dist/app-typed-client-G3J5G7E5.js.map +0 -1
  242. package/dist/app-typed-client-GHO3EWZK.js.map +0 -1
  243. package/dist/aws-lambda-CYNDGU5O.js +0 -172
  244. package/dist/aws-lambda-CYNDGU5O.js.map +0 -1
  245. package/dist/build-WU6AKKIB.js.map +0 -1
  246. package/dist/bun-33RD6K7O.js.map +0 -1
  247. package/dist/chunk-646CA6RV.js.map +0 -1
  248. package/dist/chunk-6E5WKMDS.js +0 -67
  249. package/dist/chunk-6E5WKMDS.js.map +0 -1
  250. package/dist/chunk-6GGWS7J3.js +0 -91
  251. package/dist/chunk-6GGWS7J3.js.map +0 -1
  252. package/dist/chunk-7LVM22VG.js.map +0 -1
  253. package/dist/chunk-7VPQHEAJ.js.map +0 -1
  254. package/dist/chunk-A7JBF5FO.js.map +0 -1
  255. package/dist/chunk-AM3QABW5.js +0 -161
  256. package/dist/chunk-AM3QABW5.js.map +0 -1
  257. package/dist/chunk-BIVCP6X5.js.map +0 -1
  258. package/dist/chunk-BMHS4WAN.js.map +0 -1
  259. package/dist/chunk-E576KYYT.js.map +0 -1
  260. package/dist/chunk-FB2HBNIC.js.map +0 -1
  261. package/dist/chunk-FNTLKHZ7.js.map +0 -1
  262. package/dist/chunk-GRI4XHBJ.js.map +0 -1
  263. package/dist/chunk-GVW5EKEU.js +0 -422
  264. package/dist/chunk-GVW5EKEU.js.map +0 -1
  265. package/dist/chunk-GXEX4CBH.js.map +0 -1
  266. package/dist/chunk-HBU2GIMZ.js.map +0 -1
  267. package/dist/chunk-IEES3CHD.js.map +0 -1
  268. package/dist/chunk-J5MXCGKA.js.map +0 -1
  269. package/dist/chunk-JA2ZAT5Q.js.map +0 -1
  270. package/dist/chunk-KD5G3YXI.js.map +0 -1
  271. package/dist/chunk-LNVMHQ2Z.js +0 -54
  272. package/dist/chunk-LNVMHQ2Z.js.map +0 -1
  273. package/dist/chunk-LXAESF4Y.js.map +0 -1
  274. package/dist/chunk-MTEWLGVY.js.map +0 -1
  275. package/dist/chunk-O3JIAU3V.js.map +0 -1
  276. package/dist/chunk-OJLL4YD6.js +0 -403
  277. package/dist/chunk-OJLL4YD6.js.map +0 -1
  278. package/dist/chunk-OLGPYOLO.js.map +0 -1
  279. package/dist/chunk-S433N3CT.js.map +0 -1
  280. package/dist/chunk-T5C46IIU.js.map +0 -1
  281. package/dist/chunk-U267AOWS.js +0 -28
  282. package/dist/chunk-U267AOWS.js.map +0 -1
  283. package/dist/chunk-UW2TEAGR.js +0 -77
  284. package/dist/chunk-UW2TEAGR.js.map +0 -1
  285. package/dist/chunk-WPJOTQA5.js +0 -1
  286. package/dist/chunk-XALU5LCU.js.map +0 -1
  287. package/dist/chunk-XR74JD4M.js +0 -457
  288. package/dist/chunk-XR74JD4M.js.map +0 -1
  289. package/dist/chunk-YGAXV5HR.js.map +0 -1
  290. package/dist/chunk-YRBR424R.js.map +0 -1
  291. package/dist/cloudflare-KYUWCEPL.js +0 -122
  292. package/dist/cloudflare-KYUWCEPL.js.map +0 -1
  293. package/dist/deno-deploy-CCTB7HGS.js +0 -107
  294. package/dist/deno-deploy-CCTB7HGS.js.map +0 -1
  295. package/dist/dev-MUWJAZRD.js.map +0 -1
  296. package/dist/dev-emit-NBT6JD7R.js.map +0 -1
  297. package/dist/generate-Y3GWM57K.js.map +0 -1
  298. package/dist/index-BEtEv6ZH.d.ts +0 -575
  299. package/dist/load-config-VKD6LKWU.js +0 -14
  300. package/dist/match-CfbEFRG4.d.ts +0 -26
  301. package/dist/netlify-AFMDNKT4.js +0 -150
  302. package/dist/netlify-AFMDNKT4.js.map +0 -1
  303. package/dist/node-ZJQEJSP3.js +0 -10
  304. package/dist/registry-GKR3EWRW.js +0 -23
  305. package/dist/start-KR2JJR7K.js.map +0 -1
  306. package/dist/static-M2W4HUWS.js.map +0 -1
  307. package/dist/theo-cloud-XAHWOUFK.js.map +0 -1
  308. package/dist/vercel-SRS2DH6O.js +0 -133
  309. package/dist/vercel-SRS2DH6O.js.map +0 -1
  310. package/dist/vite-plugin-VPJFD4HK.js +0 -36
  311. /package/dist/{chunk-WPJOTQA5.js.map → adapters/agent-mount.js.map} +0 -0
  312. /package/dist/{agent-7JJW3TPB.js.map → agent-GKUEL6OH.js.map} +0 -0
  313. /package/dist/{check-45NKUVSQ.js.map → check-GIPZBFTX.js.map} +0 -0
  314. /package/dist/{chunk-47CINLWF.js.map → chunk-44J2ANQC.js.map} +0 -0
  315. /package/dist/{chunk-ZB7D62OA.js.map → chunk-KUZVRJ7M.js.map} +0 -0
  316. /package/dist/{chunk-PXFXSFJL.js.map → chunk-NZ5JU6D3.js.map} +0 -0
  317. /package/dist/{internal-api-WEOSTMSN.js.map → chunk-YSJOZEI6.js.map} +0 -0
  318. /package/dist/{dev-emit-GWD6IXV7.js.map → dev-emit-BFNMDCPB.js.map} +0 -0
  319. /package/dist/{internal-api-V5L65YSJ.js.map → internal-api-IP35YU3G.js.map} +0 -0
  320. /package/dist/{load-config-VKD6LKWU.js.map → load-config-4ATXQUN3.js.map} +0 -0
  321. /package/dist/{mcp-ULUFJNSZ.js.map → mcp-5LLNAGKA.js.map} +0 -0
  322. /package/dist/{node-ZJQEJSP3.js.map → node-OSVPYQ3D.js.map} +0 -0
  323. /package/dist/{scan-7MJC6PYU.js.map → observability-bootstrap-MZMSOE66.js.map} +0 -0
  324. /package/dist/{registry-GKR3EWRW.js.map → registry-KBZDCFVQ.js.map} +0 -0
  325. /package/dist/{schema-ZO3OSWVG.js.map → scan-YJEE4KQK.js.map} +0 -0
  326. /package/dist/{vite-plugin-VPJFD4HK.js.map → schema-SOAD43RQ.js.map} +0 -0
  327. /package/dist/{services-typed-client-PSAGRPFF.js.map → services-typed-client-XGT5SUUN.js.map} +0 -0
@@ -2,18 +2,38 @@
2
2
  import "tsx/esm";
3
3
  import {
4
4
  getApprovalRegistry
5
- } from "./chunk-6GGWS7J3.js";
5
+ } from "./chunk-5YPXXSYY.js";
6
6
  import {
7
+ createWebRequestSource,
7
8
  dispatchCsrfWarn,
8
9
  enforceCsrf,
9
10
  incomingMessageToHandlerRequest,
10
- parseRequestBody,
11
11
  safeAudit,
12
12
  sendError,
13
13
  sendJson,
14
- validateCsrfRequest,
14
+ validateCsrfRequest
15
+ } from "./chunk-HWBRS4DZ.js";
16
+ import {
17
+ buildSecurityHeaders
18
+ } from "./chunk-RPET332G.js";
19
+ import {
20
+ getObservabilityAdapter,
21
+ newSpanId,
22
+ newTraceId,
23
+ requestTrace
24
+ } from "./chunk-7PM6K5EV.js";
25
+ import {
26
+ RequestBodyConsumedError,
27
+ createLogger,
28
+ parseRequestBody,
15
29
  warnOnce
16
- } from "./chunk-T5C46IIU.js";
30
+ } from "./chunk-2AMLGJJA.js";
31
+ import {
32
+ compareByCodeUnit
33
+ } from "./chunk-FD4ZDTQ6.js";
34
+ import {
35
+ importUserModule
36
+ } from "./chunk-U5PWXS3J.js";
17
37
  import {
18
38
  TheoError,
19
39
  serverErrorToEnvelope
@@ -186,6 +206,24 @@ function isAuthRequiredError(err) {
186
206
  return e.code === "AUTH_REQUIRED" && e.status === 401;
187
207
  }
188
208
 
209
+ // src/core/contracts/route-policy.ts
210
+ function subjectFromContext(context) {
211
+ if (context === null || typeof context !== "object") return null;
212
+ const candidate = context.subject;
213
+ if (candidate === null || candidate === void 0 || typeof candidate !== "object") return null;
214
+ const id = candidate.id;
215
+ return typeof id === "string" && id.length > 0 ? candidate : null;
216
+ }
217
+ async function evaluateRoutePolicy(policy, input) {
218
+ if (policy === void 0) return { allowed: true };
219
+ if (policy === "public") return { allowed: true };
220
+ const verdict = await policy(input);
221
+ if (typeof verdict === "boolean") {
222
+ return verdict ? { allowed: true } : { allowed: false, reason: "access denied by route policy" };
223
+ }
224
+ return verdict;
225
+ }
226
+
189
227
  // src/server/jobs/duplicate-context-key-error.ts
190
228
  var DuplicateContextKeyError = class extends Error {
191
229
  constructor(key, opts) {
@@ -301,6 +339,10 @@ async function parseQueryAndBody(req, res, requestId) {
301
339
  body = void 0;
302
340
  }
303
341
  } catch (err) {
342
+ if (err instanceof RequestBodyConsumedError) {
343
+ sendError(res, "INTERNAL_ERROR", err.message, err.status, void 0, requestId);
344
+ return { ok: false };
345
+ }
304
346
  const message = err.message;
305
347
  const status = message.includes("Unsupported Content-Type") ? 415 : 400;
306
348
  sendError(res, "VALIDATION_ERROR", message, status, void 0, requestId);
@@ -364,6 +406,9 @@ function runZodValidation(routeConfig, res, requestId, input) {
364
406
  import { existsSync as existsSync2 } from "fs";
365
407
  import { join as join2 } from "path";
366
408
 
409
+ // src/server/define/define-middleware.ts
410
+ var WEB_SHAPED_MIDDLEWARE = /* @__PURE__ */ Symbol.for("theokit.middleware.web-shaped");
411
+
367
412
  // src/server/scan/middleware-scan.ts
368
413
  import { readdirSync, existsSync, statSync } from "fs";
369
414
  import { join, extname } from "path";
@@ -382,10 +427,70 @@ function scanMiddlewares(serverDir) {
382
427
  if (!MW_EXTENSIONS.has(ext)) continue;
383
428
  files.push(join(mwDir, entry.name));
384
429
  }
385
- files.sort((a, b) => a.localeCompare(b));
430
+ files.sort(compareByCodeUnit);
386
431
  return files;
387
432
  }
388
433
 
434
+ // src/core/contracts/envelope-code-to-status.ts
435
+ var CODE_TO_STATUS2 = {
436
+ // 4xx — client errors
437
+ BAD_REQUEST: 400,
438
+ UNAUTHORIZED: 401,
439
+ FORBIDDEN: 403,
440
+ NOT_FOUND: 404,
441
+ METHOD_NOT_ALLOWED: 405,
442
+ CONFLICT: 409,
443
+ PRECONDITION_FAILED: 412,
444
+ PAYLOAD_TOO_LARGE: 413,
445
+ UNSUPPORTED_MEDIA_TYPE: 415,
446
+ UNPROCESSABLE_ENTITY: 422,
447
+ TOO_MANY_REQUESTS: 429,
448
+ RATE_LIMITED: 429,
449
+ // 5xx — server errors
450
+ INTERNAL_SERVER_ERROR: 500,
451
+ NOT_IMPLEMENTED: 501,
452
+ BAD_GATEWAY: 502,
453
+ SERVICE_UNAVAILABLE: 503,
454
+ GATEWAY_TIMEOUT: 504,
455
+ // SDK-domain codes — intentionally 500
456
+ AGENT_RUN_ERROR: 500,
457
+ PROVIDER_KEY_MISSING: 500,
458
+ BUDGET_EXCEEDED: 500,
459
+ CREDENTIAL_POOL_EXHAUSTED: 500
460
+ };
461
+ function envelopeCodeToStatus(code) {
462
+ return CODE_TO_STATUS2[code] ?? 500;
463
+ }
464
+
465
+ // src/server/http/node-web-adapter.ts
466
+ async function writeWebResponseToServerResponse(response, res) {
467
+ const setCookies = response.headers.getSetCookie();
468
+ if (setCookies.length > 0) {
469
+ res.setHeader("Set-Cookie", setCookies);
470
+ }
471
+ const otherHeaders = {};
472
+ for (const [key, value] of response.headers.entries()) {
473
+ if (key.toLowerCase() === "set-cookie") continue;
474
+ otherHeaders[key] = value;
475
+ }
476
+ res.writeHead(response.status, response.statusText, otherHeaders);
477
+ if (response.body === null) {
478
+ res.end();
479
+ return;
480
+ }
481
+ const reader = response.body.getReader();
482
+ try {
483
+ for (; ; ) {
484
+ const { done, value } = await reader.read();
485
+ if (done) break;
486
+ res.write(value);
487
+ }
488
+ res.end();
489
+ } finally {
490
+ reader.releaseLock();
491
+ }
492
+ }
493
+
389
494
  // src/server/http/middleware-runner.ts
390
495
  var middlewareCache = /* @__PURE__ */ new Map();
391
496
  function getCachedScan(serverDir) {
@@ -401,6 +506,24 @@ function getCachedScan(serverDir) {
401
506
  }
402
507
  return cached;
403
508
  }
509
+ async function runWebShapedMiddleware(mw, req, res, context) {
510
+ const request = createWebRequestSource(req).toRequest();
511
+ const result = await mw(request, context);
512
+ if (!(result instanceof Response)) return { shortCircuited: false };
513
+ await writeWebResponseToServerResponse(result, res);
514
+ return { shortCircuited: true };
515
+ }
516
+ function isWebShaped(mw) {
517
+ return WEB_SHAPED_MIDDLEWARE in mw;
518
+ }
519
+ async function runScannedMiddleware(mw, req, res, context) {
520
+ if (isWebShaped(mw)) {
521
+ const { shortCircuited } = await runWebShapedMiddleware(mw, req, res, context);
522
+ return { aborted: shortCircuited };
523
+ }
524
+ const { nextCalled } = await runOneMiddleware(mw, req, res);
525
+ return { aborted: !nextCalled || res.writableEnded };
526
+ }
404
527
  async function runOneMiddleware(mw, req, res) {
405
528
  const state = { nextCalled: false };
406
529
  await mw(req, res, () => {
@@ -411,6 +534,7 @@ async function runOneMiddleware(mw, req, res) {
411
534
  async function runMiddlewareAndContext(req, res, loadModule, serverDir) {
412
535
  const { singleFilePath, singleFileExists, dirMiddlewares } = getCachedScan(serverDir);
413
536
  const dirExists = dirMiddlewares.length > 0;
537
+ const middlewareCtx = {};
414
538
  if (singleFileExists && dirExists) {
415
539
  throw new Error(
416
540
  "Ambiguous middleware configuration: found both server/middleware.ts and server/middleware/ directory. Use one or the other, not both."
@@ -421,36 +545,54 @@ async function runMiddlewareAndContext(req, res, loadModule, serverDir) {
421
545
  const mod = await loadModule(mwPath);
422
546
  const mw = mod.default;
423
547
  if (typeof mw !== "function") continue;
424
- const { nextCalled } = await runOneMiddleware(mw, req, res);
425
- if (!nextCalled || res.writableEnded) {
426
- return { ctx: {}, aborted: true };
427
- }
548
+ const { aborted } = await runScannedMiddleware(mw, req, res, middlewareCtx);
549
+ if (aborted) return { ctx: middlewareCtx, aborted: true };
428
550
  }
429
551
  }
430
552
  if (singleFileExists) {
431
553
  const mod = await loadModule(singleFilePath);
432
554
  const mw = mod.default;
433
555
  if (typeof mw === "function") {
434
- const { nextCalled } = await runOneMiddleware(mw, req, res);
435
- if (!nextCalled || res.writableEnded) {
436
- return { ctx: {}, aborted: true };
437
- }
556
+ const { aborted } = await runScannedMiddleware(mw, req, res, middlewareCtx);
557
+ if (aborted) return { ctx: middlewareCtx, aborted: true };
438
558
  }
439
559
  }
440
- let ctx = {};
441
- const contextPath = join2(serverDir, "context.ts");
442
- if (existsSync2(contextPath)) {
443
- const mod = await loadModule(contextPath);
444
- const createContext = mod.createContext;
445
- if (typeof createContext === "function") {
446
- ctx = await createContext({ request: req, response: res });
447
- }
560
+ const factoryCtx = await createServerContext(req, res, loadModule, serverDir);
561
+ if (factoryCtx === null || typeof factoryCtx !== "object") {
562
+ return { ctx: middlewareCtx, aborted: false };
448
563
  }
449
- return { ctx, aborted: false };
564
+ return { ctx: { ...middlewareCtx, ...factoryCtx }, aborted: false };
565
+ }
566
+ async function createServerContext(req, res, loadModule, serverDir) {
567
+ const contextPath = join2(serverDir, "context.ts");
568
+ if (!existsSync2(contextPath)) return {};
569
+ const mod = await loadModule(contextPath);
570
+ const createContext = mod.createContext;
571
+ if (typeof createContext !== "function") return {};
572
+ return await createContext({ request: req, response: res });
450
573
  }
451
574
 
452
575
  // src/server/http/execute.ts
453
576
  var CSRF_PROTECTED_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
577
+ async function waitForDrain(res) {
578
+ if (typeof res.once !== "function") return;
579
+ await new Promise((resolve) => {
580
+ let settled = false;
581
+ const finish = () => {
582
+ if (settled) return;
583
+ settled = true;
584
+ if (typeof res.off === "function") {
585
+ res.off("drain", finish);
586
+ res.off("close", finish);
587
+ res.off("error", finish);
588
+ }
589
+ resolve();
590
+ };
591
+ res.once("drain", finish);
592
+ res.once("close", finish);
593
+ res.once("error", finish);
594
+ });
595
+ }
454
596
  async function pipeWebStreamToResponse(body, res, ctx) {
455
597
  const reader = body.getReader();
456
598
  try {
@@ -458,7 +600,7 @@ async function pipeWebStreamToResponse(body, res, ctx) {
458
600
  while (!done) {
459
601
  const chunk = await reader.read();
460
602
  done = chunk.done;
461
- if (!done) res.write(chunk.value);
603
+ if (!done && res.write(chunk.value) === false) await waitForDrain(res);
462
604
  }
463
605
  } catch (streamErr) {
464
606
  warnOnce(`stream-error:${ctx.routePath}:${ctx.method}`, {
@@ -474,12 +616,15 @@ async function pipeWebStreamToResponse(body, res, ctx) {
474
616
  } catch {
475
617
  }
476
618
  }
619
+ res.destroy(streamErr instanceof Error ? streamErr : new Error(String(streamErr)));
620
+ return false;
477
621
  } finally {
478
622
  try {
479
623
  reader.releaseLock();
480
624
  } catch {
481
625
  }
482
626
  }
627
+ return true;
483
628
  }
484
629
  async function executeRoute(ctx) {
485
630
  const {
@@ -595,6 +740,23 @@ async function executeRoute(ctx) {
595
740
  if (preResult.shortCircuited) return;
596
741
  }
597
742
  const callableHandler = handler;
743
+ const accessDecision = await evaluateRoutePolicy(rc.policy, {
744
+ subject: subjectFromContext(ctx2),
745
+ query,
746
+ body,
747
+ params
748
+ });
749
+ if (!accessDecision.allowed) {
750
+ sendError(
751
+ res,
752
+ "FORBIDDEN",
753
+ `Access denied: ${accessDecision.reason}`,
754
+ 403,
755
+ void 0,
756
+ requestId
757
+ );
758
+ return;
759
+ }
598
760
  const handlerResult = await callableHandler({ query, body, params, request: webRequest, ctx: ctx2 });
599
761
  if (handlerResult === void 0 || handlerResult === null) {
600
762
  sendJson(res, null, rc.status ?? 204, transformer);
@@ -611,8 +773,9 @@ async function executeRoute(ctx) {
611
773
  res.setHeader("Set-Cookie", setCookies);
612
774
  }
613
775
  res.writeHead(handlerResult.status, headersBag);
776
+ let bodyCompleted = true;
614
777
  if (handlerResult.body) {
615
- await pipeWebStreamToResponse(handlerResult.body, res, {
778
+ bodyCompleted = await pipeWebStreamToResponse(handlerResult.body, res, {
616
779
  buildPluginCtx,
617
780
  ctx: ctx2,
618
781
  method,
@@ -621,7 +784,7 @@ async function executeRoute(ctx) {
621
784
  routePath: route.routePath
622
785
  });
623
786
  }
624
- res.end();
787
+ if (bodyCompleted) res.end();
625
788
  if (pluginRunner) await pluginRunner.runOnResponse(buildPluginCtx(ctx2));
626
789
  return;
627
790
  }
@@ -768,37 +931,6 @@ function coerceBoolean(formData, key) {
768
931
  return Boolean(val);
769
932
  }
770
933
 
771
- // src/core/contracts/envelope-code-to-status.ts
772
- var CODE_TO_STATUS2 = {
773
- // 4xx — client errors
774
- BAD_REQUEST: 400,
775
- UNAUTHORIZED: 401,
776
- FORBIDDEN: 403,
777
- NOT_FOUND: 404,
778
- METHOD_NOT_ALLOWED: 405,
779
- CONFLICT: 409,
780
- PRECONDITION_FAILED: 412,
781
- PAYLOAD_TOO_LARGE: 413,
782
- UNSUPPORTED_MEDIA_TYPE: 415,
783
- UNPROCESSABLE_ENTITY: 422,
784
- TOO_MANY_REQUESTS: 429,
785
- RATE_LIMITED: 429,
786
- // 5xx — server errors
787
- INTERNAL_SERVER_ERROR: 500,
788
- NOT_IMPLEMENTED: 501,
789
- BAD_GATEWAY: 502,
790
- SERVICE_UNAVAILABLE: 503,
791
- GATEWAY_TIMEOUT: 504,
792
- // SDK-domain codes — intentionally 500
793
- AGENT_RUN_ERROR: 500,
794
- PROVIDER_KEY_MISSING: 500,
795
- BUDGET_EXCEEDED: 500,
796
- CREDENTIAL_POOL_EXHAUSTED: 500
797
- };
798
- function envelopeCodeToStatus(code) {
799
- return CODE_TO_STATUS2[code] ?? 500;
800
- }
801
-
802
934
  // src/server/http/handle-request-error.ts
803
935
  async function handleRequestError(err, c) {
804
936
  if (c.pluginRunner) {
@@ -1328,44 +1460,6 @@ function createCorsHandler(config) {
1328
1460
  };
1329
1461
  }
1330
1462
 
1331
- // src/server/http/trace-context.ts
1332
- var TRACE_HEADER = "x-trace-id";
1333
- var TRACE_PARENT_HEADER = "traceparent";
1334
- var REQUEST_ID_HEADER = "x-request-id";
1335
- var TRACEPARENT_RE = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/;
1336
- function parseTraceparent(value) {
1337
- if (!value) return null;
1338
- const m = TRACEPARENT_RE.exec(value);
1339
- if (!m) return null;
1340
- const traceId = m[1];
1341
- if (/^0+$/.test(traceId)) return null;
1342
- return traceId;
1343
- }
1344
- function pickHeader(value) {
1345
- if (Array.isArray(value)) {
1346
- for (const v of value) {
1347
- if (typeof v === "string" && v.length > 0) return v;
1348
- }
1349
- return null;
1350
- }
1351
- if (typeof value === "string" && value.length > 0) return value;
1352
- return null;
1353
- }
1354
- function resolveTraceIdFromHeaders(traceparent, requestId) {
1355
- if (traceparent !== null) {
1356
- const parsed = parseTraceparent(traceparent);
1357
- if (parsed !== null) return parsed;
1358
- }
1359
- if (requestId !== null) return requestId;
1360
- return globalThis.crypto.randomUUID();
1361
- }
1362
- function extractTraceId(req) {
1363
- return resolveTraceIdFromHeaders(
1364
- pickHeader(req.headers[TRACE_PARENT_HEADER]),
1365
- pickHeader(req.headers[REQUEST_ID_HEADER])
1366
- );
1367
- }
1368
-
1369
1463
  // src/server/observability/suggest.ts
1370
1464
  function levenshtein(a, b) {
1371
1465
  const m = a.length;
@@ -1757,19 +1851,226 @@ function resultFromState(state, config) {
1757
1851
  // src/server/agent/mount-agent.ts
1758
1852
  import { compileAgentModule as compileAgentModule2, resolveEnabledSkills as resolveEnabledSkills2, streamAgentUIMessages as streamAgentUIMessages2 } from "@theokit/agents";
1759
1853
 
1854
+ // src/server/agent/agent-access.ts
1855
+ var AgentPolicyTypeError = class extends Error {
1856
+ constructor(source, actual) {
1857
+ super(
1858
+ `Agent "${source}" exports a \`policy\` of type ${actual}. A policy is the string 'public' or a function ({ subject, body, params }) => boolean | AccessDecision. Import \`requireOwner\` from 'theokit/server/define' to write the owner check.`
1859
+ );
1860
+ this.name = "AgentPolicyTypeError";
1861
+ }
1862
+ };
1863
+ function readAgentPolicy(mod, source) {
1864
+ const declared = typeof mod === "object" && mod !== null ? mod.policy : void 0;
1865
+ if (declared === void 0) return void 0;
1866
+ if (declared !== "public" && typeof declared !== "function") {
1867
+ throw new AgentPolicyTypeError(source, declared === null ? "null" : typeof declared);
1868
+ }
1869
+ return declared;
1870
+ }
1871
+ var log = createLogger({ context: { scope: "theokit:agent-access" } });
1872
+ async function admitAgentRequest(policy, resolveSubject, params, body) {
1873
+ if (policy === void 0 || policy === "public") return { allowed: true };
1874
+ const subject = resolveSubject === void 0 ? null : await resolveSubject();
1875
+ return evaluateRoutePolicy(policy, { subject, query: void 0, body, params });
1876
+ }
1877
+ function agentAccessDenied(decision, params) {
1878
+ if (!decision.allowed) {
1879
+ log.warn("agent endpoint refused a caller", {
1880
+ agent: params.agent,
1881
+ endpoint: params.endpoint,
1882
+ reason: decision.reason
1883
+ });
1884
+ }
1885
+ return new Response(
1886
+ JSON.stringify({
1887
+ error: {
1888
+ code: "FORBIDDEN",
1889
+ message: `Access denied by the policy exported from agent "${params.agent}". Send the credential your app turns into \`ctx.subject\` in server/context.ts; the server log records which check refused this request.`
1890
+ }
1891
+ }),
1892
+ { status: 403, headers: { "content-type": "application/json; charset=utf-8" } }
1893
+ );
1894
+ }
1895
+
1760
1896
  // src/server/agent/build-agent-streamer.ts
1761
1897
  import {
1762
1898
  compileAgentModule,
1763
1899
  resolveEnabledSkills,
1764
1900
  streamAgentUIMessages
1765
1901
  } from "@theokit/agents";
1766
- function buildAgentHitl(compiled) {
1902
+
1903
+ // src/server/agent/hitl-pause-spans.ts
1904
+ var pauseSpans = /* @__PURE__ */ new Map();
1905
+ function registerPauseSpan(approvalId, span) {
1906
+ pauseSpans.set(approvalId, span);
1907
+ }
1908
+ function closePauseSpan(approvalId, { resumeObserved }) {
1909
+ const span = pauseSpans.get(approvalId);
1910
+ if (span === void 0) return;
1911
+ pauseSpans.delete(approvalId);
1912
+ span.setAttribute("hitl.resume_observed", resumeObserved);
1913
+ if (resumeObserved) span.setStatus("ok");
1914
+ else
1915
+ span.setStatus("error", "HITL pause never observed to resume; duration is not the human wait");
1916
+ span.end();
1917
+ }
1918
+
1919
+ // src/server/agent/observe-agent-run.ts
1920
+ var TOKEN_FIELDS = [
1921
+ ["inputTokens", "tokens.input"],
1922
+ ["outputTokens", "tokens.output"],
1923
+ ["totalTokens", "tokens.total"],
1924
+ ["reasoningTokens", "tokens.reasoning"],
1925
+ ["cacheReadTokens", "tokens.cache_read"],
1926
+ ["cacheWriteTokens", "tokens.cache_write"]
1927
+ ];
1928
+ var STOP_REASONS = /* @__PURE__ */ new Set(["step_limit", "no_progress"]);
1929
+ var GEN_AI_REQUEST_MODEL = "gen_ai.request.model";
1930
+ function recordModel(span, metadata) {
1931
+ if (metadata === null || typeof metadata !== "object") return;
1932
+ const model = metadata.model;
1933
+ if (typeof model === "string" && model.length > 0) span.setAttribute(GEN_AI_REQUEST_MODEL, model);
1934
+ }
1935
+ function recordStopReason(span, metadata) {
1936
+ if (metadata === null || typeof metadata !== "object") return;
1937
+ const reason = metadata.stopReason;
1938
+ if (typeof reason === "string" && STOP_REASONS.has(reason)) {
1939
+ span.setAttribute("stop.reason", reason);
1940
+ }
1941
+ }
1942
+ function recordTokenUsage(span, metadata) {
1943
+ if (metadata === null || typeof metadata !== "object") return;
1944
+ const bag = metadata;
1945
+ if (typeof bag.cost === "number") span.setAttribute("cost.usd", bag.cost);
1946
+ const usage = bag.usage;
1947
+ if (usage === null || usage === void 0 || typeof usage !== "object") return;
1948
+ const fields = usage;
1949
+ for (const [field, attribute] of TOKEN_FIELDS) {
1950
+ const value = fields[field];
1951
+ if (typeof value === "number") span.setAttribute(attribute, value);
1952
+ }
1953
+ }
1954
+ function childOf(state) {
1955
+ return { traceId: state.traceId, parentSpanId: state.runSpanId };
1956
+ }
1957
+ function openToolSpan(state, adapter, chunk) {
1958
+ const id = chunk.toolCallId;
1959
+ if (id === void 0) return;
1960
+ const tool = chunk.toolName ?? "unknown";
1961
+ state.toolNames.set(id, tool);
1962
+ state.tools.set(
1963
+ id,
1964
+ adapter.startSpan("agent.tool", { agent: state.agent, tool, toolCallId: id }, childOf(state))
1965
+ );
1966
+ }
1967
+ function openPauseSpan(state, adapter, chunk) {
1968
+ const id = chunk.toolCallId;
1969
+ const approvalId = chunk.approvalId;
1970
+ if (id === void 0 || approvalId === void 0) return;
1971
+ const pauseSpan = adapter.startSpan(
1972
+ "agent.hitl",
1973
+ {
1974
+ agent: state.agent,
1975
+ tool: state.toolNames.get(id) ?? "unknown",
1976
+ approvalId,
1977
+ toolCallId: id
1978
+ },
1979
+ childOf(state)
1980
+ );
1981
+ state.pauses.set(id, approvalId);
1982
+ registerPauseSpan(approvalId, pauseSpan);
1983
+ }
1984
+ function closeToolSpan(state, chunk) {
1985
+ const id = chunk.toolCallId;
1986
+ if (id === void 0) return;
1987
+ const pausedApprovalId = state.pauses.get(id);
1988
+ if (pausedApprovalId !== void 0) {
1989
+ closePauseSpan(pausedApprovalId, { resumeObserved: true });
1990
+ state.pauses.delete(id);
1991
+ }
1992
+ const span = state.tools.get(id);
1993
+ if (span === void 0) return;
1994
+ if (chunk.type === "tool-output-error") span.setStatus("error", chunk.errorText);
1995
+ else span.setStatus("ok");
1996
+ span.end();
1997
+ state.tools.delete(id);
1998
+ }
1999
+ async function* observeAgentRun(chunks, adapter, context) {
2000
+ const runAttributes = { agent: context.agent };
2001
+ if (context.sessionId !== void 0) runAttributes.sessionId = context.sessionId;
2002
+ const traceId = context.traceId ?? newTraceId();
2003
+ const runSpanId = newSpanId();
2004
+ const runContext = context.traceId !== void 0 && context.parentSpanId !== void 0 ? { traceId, spanId: runSpanId, parentSpanId: context.parentSpanId } : { traceId, spanId: runSpanId };
2005
+ const state = {
2006
+ run: adapter.startSpan("agent.run", runAttributes, runContext),
2007
+ tools: /* @__PURE__ */ new Map(),
2008
+ pauses: /* @__PURE__ */ new Map(),
2009
+ toolNames: /* @__PURE__ */ new Map(),
2010
+ agent: context.agent,
2011
+ traceId,
2012
+ runSpanId
2013
+ };
2014
+ let settled = false;
2015
+ function closeAll(status, message) {
2016
+ if (settled) return;
2017
+ settled = true;
2018
+ for (const approvalId of state.pauses.values()) {
2019
+ closePauseSpan(approvalId, { resumeObserved: false });
2020
+ }
2021
+ for (const span of state.tools.values()) {
2022
+ span.setStatus(status, message);
2023
+ span.end();
2024
+ }
2025
+ state.pauses.clear();
2026
+ state.tools.clear();
2027
+ state.run.setStatus(status, message);
2028
+ state.run.end();
2029
+ }
2030
+ try {
2031
+ for await (const chunk of chunks) {
2032
+ const observed = chunk;
2033
+ if (observed.type === "tool-input-available") openToolSpan(state, adapter, observed);
2034
+ else if (observed.type === "tool-approval-request") openPauseSpan(state, adapter, observed);
2035
+ else if (observed.type === "tool-output-available" || observed.type === "tool-output-error")
2036
+ closeToolSpan(state, observed);
2037
+ else if (observed.type === "finish") {
2038
+ recordTokenUsage(state.run, observed.messageMetadata);
2039
+ recordStopReason(state.run, observed.messageMetadata);
2040
+ recordModel(state.run, observed.messageMetadata);
2041
+ }
2042
+ yield chunk;
2043
+ }
2044
+ closeAll("ok");
2045
+ } catch (error) {
2046
+ closeAll("error", error instanceof Error ? error.message : "unknown error");
2047
+ throw error;
2048
+ } finally {
2049
+ closeAll("error", "agent run stream abandoned by its consumer");
2050
+ }
2051
+ }
2052
+
2053
+ // src/server/agent/observe-served-run.ts
2054
+ function observeServedRun(stream, options) {
2055
+ const adapter = getObservabilityAdapter();
2056
+ if (adapter === void 0) return stream;
2057
+ const trace = requestTrace(options.request);
2058
+ const context = { agent: options.agentName, traceId: trace.traceId };
2059
+ if (options.sessionId !== void 0) context.sessionId = options.sessionId;
2060
+ const parentSpanId = trace.outermostSpanId ?? trace.parentSpanId;
2061
+ if (parentSpanId !== void 0) context.parentSpanId = parentSpanId;
2062
+ return observeAgentRun(stream, adapter, context);
2063
+ }
2064
+
2065
+ // src/server/agent/build-agent-streamer.ts
2066
+ function buildAgentHitl(compiled, owner) {
1767
2067
  const gated = compiled.hitl;
1768
2068
  if (gated === void 0 || gated.size === 0) return void 0;
1769
2069
  const registry = getApprovalRegistry();
1770
2070
  return {
1771
2071
  gated,
1772
2072
  awaitApproval: (approvalId, opts, toolName) => registry.register(approvalId, {
2073
+ ...owner !== void 0 ? { owner } : {},
1773
2074
  timeoutMs: opts.timeout ?? 3e5,
1774
2075
  onTimeout: opts.onTimeout ?? "abort",
1775
2076
  toolName,
@@ -1778,7 +2079,7 @@ function buildAgentHitl(compiled) {
1778
2079
  })
1779
2080
  };
1780
2081
  }
1781
- function makeThreadStartRun(mod, apiKey, source) {
2082
+ function makeThreadStartRun(mod, apiKey, source, agentName, request) {
1782
2083
  return (sessionId, message) => (async function* () {
1783
2084
  const compiled = compileAgentModule(mod, source);
1784
2085
  if (compiled.skillsResolver) {
@@ -1789,13 +2090,17 @@ function makeThreadStartRun(mod, apiKey, source) {
1789
2090
  if (enabled !== void 0) compiled.skills = { enabled, autoInject: true };
1790
2091
  }
1791
2092
  const hitl = buildAgentHitl(compiled);
1792
- yield* streamAgentUIMessages(compiled, apiKey, { message, sessionId, hitl });
2093
+ const resolvedApiKey = typeof apiKey === "function" ? apiKey(compiled.model) : apiKey;
2094
+ const stream = streamAgentUIMessages(compiled, resolvedApiKey, { message, sessionId, hitl });
2095
+ yield* observeServedRun(stream, { agentName, sessionId, request });
1793
2096
  })();
1794
2097
  }
1795
2098
 
1796
2099
  // src/server/agent/durable-ui-message-stream-response.ts
1797
2100
  var SSE_BASE_HEADERS = {
1798
2101
  "content-type": "text/event-stream",
2102
+ "cache-control": "no-cache",
2103
+ "x-accel-buffering": "no",
1799
2104
  "x-vercel-ai-ui-message-stream": "v1"
1800
2105
  };
1801
2106
  var RUN_ID_HEADER = "x-theokit-run-id";
@@ -1941,37 +2246,70 @@ function parseAgentRequestBody(body) {
1941
2246
  }
1942
2247
  return null;
1943
2248
  }
1944
- async function mountAgent(mod, request, apiKey, { source = "agent module", csrfMode = "strict", projectRoot } = {}) {
2249
+ function memoizeSubject(resolveSubject) {
2250
+ if (resolveSubject === void 0) return void 0;
2251
+ let resolved;
2252
+ return async () => {
2253
+ resolved ??= { subject: await resolveSubject() };
2254
+ return resolved.subject;
2255
+ };
2256
+ }
2257
+ async function resolveApprovalOwner(declaredPolicy, resolveOnce) {
2258
+ if (declaredPolicy === void 0 || declaredPolicy === "public") return void 0;
2259
+ return (await resolveOnce?.() ?? void 0)?.id;
2260
+ }
2261
+ async function admitRequest(request, policy, resolveSubject, agentName) {
2262
+ let body = null;
2263
+ try {
2264
+ body = await request.json();
2265
+ } catch {
2266
+ }
2267
+ const input = parseAgentRequestBody(body);
2268
+ if (input === null) {
2269
+ return jsonError(400, "BAD_REQUEST", "Request must contain a non-empty message or messages[].");
2270
+ }
2271
+ const params = { agent: agentName, endpoint: "run", sessionId: input.sessionId };
2272
+ const decision = await admitAgentRequest(policy, resolveSubject, params, input);
2273
+ if (!decision.allowed) return agentAccessDenied(decision, params);
2274
+ return input;
2275
+ }
2276
+ async function mountAgent(mod, request, apiKey, {
2277
+ source = "agent module",
2278
+ csrfMode = "strict",
2279
+ projectRoot,
2280
+ agentName,
2281
+ policy,
2282
+ resolveSubject
2283
+ } = {}) {
1945
2284
  if (csrfMode !== "off") {
1946
2285
  const csrf = validateCsrfRequest(request);
1947
2286
  if (!csrf.valid && csrfMode === "strict") {
1948
2287
  return jsonError(403, "CSRF_FAILED", `CSRF check failed: ${csrf.reason}`);
1949
2288
  }
1950
2289
  }
2290
+ const identity = agentName ?? source;
2291
+ const declaredPolicy = policy ?? readAgentPolicy(mod, source);
2292
+ const resolveOnce = memoizeSubject(resolveSubject);
2293
+ const admitted = await admitRequest(request, declaredPolicy, resolveOnce, identity);
2294
+ if (admitted instanceof Response) return admitted;
2295
+ const input = admitted;
1951
2296
  const compiled = compileAgentModule2(mod, source);
2297
+ const resolvedApiKey = typeof apiKey === "function" ? apiKey(compiled.model) : apiKey;
1952
2298
  if (compiled.skillsResolver) {
1953
2299
  const enabled = await resolveEnabledSkills2(compiled.skillsResolver, compiled.runContext ?? {});
1954
2300
  if (enabled !== void 0) compiled.skills = { enabled, autoInject: true };
1955
2301
  }
1956
- let body = null;
1957
- try {
1958
- body = await request.json();
1959
- } catch {
1960
- }
1961
- const input = parseAgentRequestBody(body);
1962
- if (input === null) {
1963
- return jsonError(400, "BAD_REQUEST", "Request must contain a non-empty message or messages[].");
1964
- }
1965
- const hitl = buildAgentHitl(compiled);
2302
+ const hitl = buildAgentHitl(compiled, await resolveApprovalOwner(declaredPolicy, resolveOnce));
1966
2303
  const runId = mintRunId();
2304
+ const stream = streamAgentUIMessages2(compiled, resolvedApiKey, {
2305
+ ...input,
2306
+ hitl,
2307
+ signal: request.signal,
2308
+ cwd: resolveDiscoveryCwd(compiled, projectRoot),
2309
+ baseDir: resolveSessionBaseDir(projectRoot)
2310
+ });
1967
2311
  return durableUiMessageStreamResponse(
1968
- streamAgentUIMessages2(compiled, apiKey, {
1969
- ...input,
1970
- hitl,
1971
- signal: request.signal,
1972
- cwd: resolveDiscoveryCwd(compiled, projectRoot),
1973
- baseDir: resolveSessionBaseDir(projectRoot)
1974
- }),
2312
+ observeServedRun(stream, { agentName: identity, request }),
1975
2313
  { runId, cache: getRunEventCache() }
1976
2314
  );
1977
2315
  }
@@ -1990,21 +2328,17 @@ function resolveSessionBaseDir(projectRoot) {
1990
2328
  }
1991
2329
 
1992
2330
  // src/server/scan/module-loader.ts
1993
- import { pathToFileURL } from "url";
1994
2331
  function createViteLoader(vite) {
1995
2332
  return (path) => vite.ssrLoadModule(path);
1996
2333
  }
1997
2334
  function createProductionLoader() {
1998
- return async (path) => {
1999
- const url = pathToFileURL(path).href;
2000
- return import(url);
2001
- };
2335
+ return (path) => importUserModule(path);
2002
2336
  }
2003
2337
 
2004
2338
  // src/server/security/csp-report.ts
2005
2339
  var CSP_REPORT_PATH = "/__theo/csp-report";
2006
2340
  var MAX_BODY = 16 * 1024;
2007
- function pickHeader2(value) {
2341
+ function pickHeader(value) {
2008
2342
  if (typeof value === "string") return value;
2009
2343
  if (Array.isArray(value) && value.length > 0) return value[0];
2010
2344
  return "";
@@ -2067,7 +2401,7 @@ async function readBody(req, maxBytes) {
2067
2401
  }
2068
2402
  async function handleCspReport(req, res, opts) {
2069
2403
  const ctHeader = req.headers["content-type"];
2070
- const ct = pickHeader2(ctHeader);
2404
+ const ct = pickHeader(ctHeader);
2071
2405
  let raw;
2072
2406
  try {
2073
2407
  raw = await readBody(req, MAX_BODY);
@@ -2223,50 +2557,6 @@ var CsrfReadinessStore = class _CsrfReadinessStore {
2223
2557
  };
2224
2558
 
2225
2559
  // src/server/security/security-headers.ts
2226
- var DEFAULT_CSP = "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self' ws: wss:; frame-ancestors 'none'; report-uri /__theo/csp-report";
2227
- var DEFAULT_PERMISSIONS_POLICY = "geolocation=(), camera=(), microphone=(), payment=(), usb=(), accelerometer=(), gyroscope=()";
2228
- var DEFAULT_HSTS = "max-age=31536000; includeSubDomains";
2229
- function applyNonceToCsp(policy, nonce) {
2230
- return policy.split(";").map((directive) => {
2231
- const trimmed = directive.trim();
2232
- if (!trimmed.startsWith("script-src")) return directive;
2233
- if (trimmed.includes("'unsafe-inline'")) {
2234
- return directive.replace("'unsafe-inline'", `'nonce-${nonce}'`);
2235
- }
2236
- return `${directive} 'nonce-${nonce}'`;
2237
- }).join(";");
2238
- }
2239
- function applyCsp(out, config, effectiveNonce) {
2240
- if (config.csp === false || config.cspMode === "off") return;
2241
- let policy = typeof config.csp === "string" ? config.csp : DEFAULT_CSP;
2242
- if (effectiveNonce) {
2243
- policy = applyNonceToCsp(policy, effectiveNonce);
2244
- }
2245
- const mode = config.cspMode ?? "enforce";
2246
- if (mode === "enforce") {
2247
- out["Content-Security-Policy"] = policy;
2248
- } else {
2249
- out["Content-Security-Policy-Report-Only"] = policy;
2250
- }
2251
- }
2252
- function buildSecurityHeaders(config, env, options = {}) {
2253
- const out = {};
2254
- const effectiveNonce = options.prerender ? void 0 : options.nonce;
2255
- applyCsp(out, config, effectiveNonce);
2256
- out["X-Frame-Options"] = config.frameOptions ?? "DENY";
2257
- out["X-Content-Type-Options"] = config.contentTypeOptions ?? "nosniff";
2258
- out["Referrer-Policy"] = config.referrerPolicy ?? "strict-origin-when-cross-origin";
2259
- if (config.permissionsPolicy !== false) {
2260
- out["Permissions-Policy"] = typeof config.permissionsPolicy === "string" ? config.permissionsPolicy : DEFAULT_PERMISSIONS_POLICY;
2261
- }
2262
- if (env.production && config.hsts !== false) {
2263
- out["Strict-Transport-Security"] = typeof config.hsts === "string" ? config.hsts : DEFAULT_HSTS;
2264
- }
2265
- if (effectiveNonce) {
2266
- out["Cache-Control"] = "private, no-store";
2267
- }
2268
- return out;
2269
- }
2270
2560
  function applySecurityHeaders(res, config, env, options = {}) {
2271
2561
  const headers = buildSecurityHeaders(config, env, options);
2272
2562
  for (const [key, value] of Object.entries(headers)) {
@@ -2274,48 +2564,23 @@ function applySecurityHeaders(res, config, env, options = {}) {
2274
2564
  }
2275
2565
  }
2276
2566
 
2277
- // src/server/auth/nonce.ts
2278
- function bytesToBase64(bytes) {
2279
- if (typeof Buffer !== "undefined") {
2280
- return Buffer.from(bytes).toString("base64");
2281
- }
2282
- let binary = "";
2283
- for (const b of bytes) {
2284
- binary += String.fromCharCode(b);
2285
- }
2286
- return btoa(binary);
2287
- }
2288
- var cachedWebCrypto;
2289
- function getWebCrypto() {
2290
- if (cachedWebCrypto === void 0) {
2291
- const candidate = globalThis.crypto;
2292
- cachedWebCrypto = candidate && typeof candidate.getRandomValues === "function" ? candidate : null;
2293
- }
2294
- if (!cachedWebCrypto) {
2295
- throw new Error(
2296
- "generateNonce: Web Crypto unavailable. TheoKit requires Node.js 19+, Bun, Deno, or any modern Edge runtime where `globalThis.crypto.getRandomValues` is present."
2297
- );
2298
- }
2299
- return cachedWebCrypto;
2300
- }
2301
- function generateNonce() {
2302
- const buf = new Uint8Array(16);
2303
- getWebCrypto().getRandomValues(buf);
2304
- return bytesToBase64(buf);
2305
- }
2306
-
2307
2567
  export {
2568
+ subjectFromContext,
2569
+ writeWebResponseToServerResponse,
2570
+ createServerContext,
2308
2571
  executeRoute,
2309
2572
  executeAction,
2310
2573
  BATCH_PATH,
2311
2574
  handleBatchRequest,
2312
2575
  createCorsHandler,
2313
- TRACE_HEADER,
2314
- extractTraceId,
2315
2576
  findSuggestion,
2316
2577
  createPluginRunnerFromConfig,
2317
2578
  InMemoryStore,
2318
2579
  createRateLimiter,
2580
+ readAgentPolicy,
2581
+ admitAgentRequest,
2582
+ agentAccessDenied,
2583
+ closePauseSpan,
2319
2584
  makeThreadStartRun,
2320
2585
  SSE_BASE_HEADERS,
2321
2586
  RUN_ID_HEADER,
@@ -2332,8 +2597,6 @@ export {
2332
2597
  handleCspReport,
2333
2598
  handleCsrfReadiness,
2334
2599
  CsrfReadinessStore,
2335
- buildSecurityHeaders,
2336
- applySecurityHeaders,
2337
- generateNonce
2600
+ applySecurityHeaders
2338
2601
  };
2339
- //# sourceMappingURL=chunk-BIVCP6X5.js.map
2602
+ //# sourceMappingURL=chunk-C62IZEJI.js.map