theokit 0.48.14 → 0.50.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 (337) hide show
  1. package/README.md +1 -0
  2. package/dist/{actions-virtual-module-YZRZMHAX.js → actions-virtual-module-DSIVNGK7.js} +14 -8
  3. package/dist/{actions-virtual-module-YZRZMHAX.js.map → actions-virtual-module-DSIVNGK7.js.map} +1 -1
  4. package/dist/{actions-virtual-module-E4PISKMB.js → actions-virtual-module-RXL2RJTW.js} +23 -12
  5. package/dist/actions-virtual-module-RXL2RJTW.js.map +1 -0
  6. package/dist/adapters/agent-mount.d.ts +127 -0
  7. package/dist/adapters/agent-mount.js +25 -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-7IPEVCAY.js +15 -0
  15. package/dist/agent-scan-BZa-pagG.d.ts +16 -0
  16. package/dist/{app-typed-client-I4X2UJWW.js → app-typed-client-UTBMJZOE.js} +15 -9
  17. package/dist/app-typed-client-UTBMJZOE.js.map +1 -0
  18. package/dist/{app-typed-client-HLP26EYM.js → app-typed-client-XGDZKH73.js} +24 -13
  19. package/dist/app-typed-client-XGDZKH73.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/{body-parser-web-4Z2QTPDU.js → body-parser-web-ON5CUTEL.js} +5 -2
  23. package/dist/body-parser-web-ON5CUTEL.js.map +1 -0
  24. package/dist/{body-parser-web-TIOTXPDW.js → body-parser-web-RV2SSAI3.js} +5 -2
  25. package/dist/body-parser-web-RV2SSAI3.js.map +1 -0
  26. package/dist/{build-F2Q5QTSC.js → build-VZODSYIQ.js} +72 -26
  27. package/dist/build-VZODSYIQ.js.map +1 -0
  28. package/dist/{bun-A5B2MJMO.js → bun-L7PP6ID5.js} +105 -13
  29. package/dist/bun-L7PP6ID5.js.map +1 -0
  30. package/dist/{check-45NKUVSQ.js → check-GIPZBFTX.js} +2 -2
  31. package/dist/{chunk-WYHYOYRH.js → chunk-2COPDKIG.js} +468 -203
  32. package/dist/chunk-2COPDKIG.js.map +1 -0
  33. package/dist/chunk-3PBAN2YE.js +146 -0
  34. package/dist/chunk-3PBAN2YE.js.map +1 -0
  35. package/dist/{chunk-HBU2GIMZ.js → chunk-3QPVEJ7D.js} +15 -9
  36. package/dist/chunk-3QPVEJ7D.js.map +1 -0
  37. package/dist/{chunk-IEES3CHD.js → chunk-47MM2JUK.js} +8 -2
  38. package/dist/chunk-47MM2JUK.js.map +1 -0
  39. package/dist/chunk-4X6H2BXP.js +108 -0
  40. package/dist/chunk-4X6H2BXP.js.map +1 -0
  41. package/dist/{chunk-A7JBF5FO.js → chunk-5K4TDLRG.js} +8 -5
  42. package/dist/chunk-5K4TDLRG.js.map +1 -0
  43. package/dist/chunk-5YPXXSYY.js +181 -0
  44. package/dist/chunk-5YPXXSYY.js.map +1 -0
  45. package/dist/{chunk-YGAXV5HR.js → chunk-6J4JWHDJ.js} +191 -112
  46. package/dist/chunk-6J4JWHDJ.js.map +1 -0
  47. package/dist/{chunk-FTFN4MYN.js → chunk-7AEBH52I.js} +639 -516
  48. package/dist/chunk-7AEBH52I.js.map +1 -0
  49. package/dist/chunk-7UZZHCRN.js +21 -0
  50. package/dist/chunk-7UZZHCRN.js.map +1 -0
  51. package/dist/{chunk-MTEWLGVY.js → chunk-BPYMC7SU.js} +4 -48
  52. package/dist/chunk-BPYMC7SU.js.map +1 -0
  53. package/dist/chunk-BU6RJPPJ.js +421 -0
  54. package/dist/chunk-BU6RJPPJ.js.map +1 -0
  55. package/dist/{chunk-FB2HBNIC.js → chunk-BX6EUYHU.js} +6 -2
  56. package/dist/chunk-BX6EUYHU.js.map +1 -0
  57. package/dist/chunk-CHTAWXC2.js +18 -0
  58. package/dist/chunk-CHTAWXC2.js.map +1 -0
  59. package/dist/chunk-D4VP2QPR.js +16 -0
  60. package/dist/chunk-D4VP2QPR.js.map +1 -0
  61. package/dist/{chunk-YXG2SGQ3.js → chunk-DHAD2O3S.js} +6 -6
  62. package/dist/chunk-DHAD2O3S.js.map +1 -0
  63. package/dist/chunk-DOI4G4X3.js +428 -0
  64. package/dist/chunk-DOI4G4X3.js.map +1 -0
  65. package/dist/chunk-E43VJ3E5.js +188 -0
  66. package/dist/chunk-E43VJ3E5.js.map +1 -0
  67. package/dist/{chunk-47CINLWF.js → chunk-EDWEYQRG.js} +2 -2
  68. package/dist/chunk-EVZKNA2W.js +110 -0
  69. package/dist/chunk-EVZKNA2W.js.map +1 -0
  70. package/dist/chunk-FD4ZDTQ6.js +181 -0
  71. package/dist/chunk-FD4ZDTQ6.js.map +1 -0
  72. package/dist/chunk-FDOOBTXJ.js +17 -0
  73. package/dist/chunk-FDOOBTXJ.js.map +1 -0
  74. package/dist/chunk-FH3SQR6P.js +275 -0
  75. package/dist/chunk-FH3SQR6P.js.map +1 -0
  76. package/dist/{chunk-T5C46IIU.js → chunk-FMTRNQQ7.js} +28 -269
  77. package/dist/chunk-FMTRNQQ7.js.map +1 -0
  78. package/dist/chunk-H53KNS6Q.js +513 -0
  79. package/dist/chunk-H53KNS6Q.js.map +1 -0
  80. package/dist/chunk-HJHGTFEJ.js +23 -0
  81. package/dist/chunk-HJHGTFEJ.js.map +1 -0
  82. package/dist/{chunk-LXAESF4Y.js → chunk-HK4AZBKX.js} +7 -4
  83. package/dist/chunk-HK4AZBKX.js.map +1 -0
  84. package/dist/chunk-IRQGAC4L.js +52 -0
  85. package/dist/chunk-IRQGAC4L.js.map +1 -0
  86. package/dist/{chunk-FNTLKHZ7.js → chunk-JDN5SAAD.js} +7 -4
  87. package/dist/chunk-JDN5SAAD.js.map +1 -0
  88. package/dist/{chunk-XALU5LCU.js → chunk-JKF25N73.js} +555 -147
  89. package/dist/chunk-JKF25N73.js.map +1 -0
  90. package/dist/{chunk-BHOTGS7N.js → chunk-KI4DOTN4.js} +25 -2
  91. package/dist/chunk-KI4DOTN4.js.map +1 -0
  92. package/dist/chunk-KOS567NB.js +790 -0
  93. package/dist/chunk-KOS567NB.js.map +1 -0
  94. package/dist/{chunk-OOBYPCZC.js → chunk-KTS6G26H.js} +304 -195
  95. package/dist/chunk-KTS6G26H.js.map +1 -0
  96. package/dist/{chunk-ZB7D62OA.js → chunk-KUZVRJ7M.js} +3 -3
  97. package/dist/chunk-L4VFNFDL.js +248 -0
  98. package/dist/chunk-L4VFNFDL.js.map +1 -0
  99. package/dist/chunk-M2WC5MF7.js +127 -0
  100. package/dist/chunk-M2WC5MF7.js.map +1 -0
  101. package/dist/chunk-N42ZWWOW.js +273 -0
  102. package/dist/chunk-N42ZWWOW.js.map +1 -0
  103. package/dist/chunk-OGLS76RN.js +43 -0
  104. package/dist/chunk-OGLS76RN.js.map +1 -0
  105. package/dist/{chunk-7LVM22VG.js → chunk-OQCRCXCP.js} +6 -6
  106. package/dist/chunk-OQCRCXCP.js.map +1 -0
  107. package/dist/{chunk-OLGPYOLO.js → chunk-P6OS7652.js} +5 -2
  108. package/dist/chunk-P6OS7652.js.map +1 -0
  109. package/dist/{chunk-O3JIAU3V.js → chunk-PF3YM6NY.js} +157 -103
  110. package/dist/chunk-PF3YM6NY.js.map +1 -0
  111. package/dist/{chunk-NTWNO24W.js → chunk-PLUHPNGA.js} +266 -110
  112. package/dist/chunk-PLUHPNGA.js.map +1 -0
  113. package/dist/chunk-Q5L5EGWZ.js +26 -0
  114. package/dist/chunk-Q5L5EGWZ.js.map +1 -0
  115. package/dist/{chunk-AATSV4UV.js → chunk-QTHVHNJJ.js} +6 -36
  116. package/dist/chunk-QTHVHNJJ.js.map +1 -0
  117. package/dist/{chunk-KD5G3YXI.js → chunk-RARK7JBR.js} +39 -10
  118. package/dist/chunk-RARK7JBR.js.map +1 -0
  119. package/dist/chunk-RJJF457I.js +111 -0
  120. package/dist/chunk-RJJF457I.js.map +1 -0
  121. package/dist/chunk-RPET332G.js +84 -0
  122. package/dist/chunk-RPET332G.js.map +1 -0
  123. package/dist/{chunk-646CA6RV.js → chunk-RQW5YMH7.js} +12 -4
  124. package/dist/chunk-RQW5YMH7.js.map +1 -0
  125. package/dist/chunk-U5PWXS3J.js +39 -0
  126. package/dist/chunk-U5PWXS3J.js.map +1 -0
  127. package/dist/{chunk-RWNSW4FM.js → chunk-UMNXCU3K.js} +12 -6
  128. package/dist/{chunk-RWNSW4FM.js.map → chunk-UMNXCU3K.js.map} +1 -1
  129. package/dist/{chunk-DS5MCU2X.js → chunk-URCXSUI3.js} +9 -9
  130. package/dist/chunk-VI7ZANB3.js +193 -0
  131. package/dist/chunk-VI7ZANB3.js.map +1 -0
  132. package/dist/chunk-VQPHPQ5L.js +14 -0
  133. package/dist/chunk-VQPHPQ5L.js.map +1 -0
  134. package/dist/chunk-WNJTJRM6.js +147 -0
  135. package/dist/chunk-WNJTJRM6.js.map +1 -0
  136. package/dist/{chunk-BMHS4WAN.js → chunk-XS7EX55U.js} +156 -42
  137. package/dist/chunk-XS7EX55U.js.map +1 -0
  138. package/dist/chunk-YN4W7LCX.js +31 -0
  139. package/dist/chunk-YN4W7LCX.js.map +1 -0
  140. package/dist/chunk-YSJOZEI6.js +1 -0
  141. package/dist/{chunk-JA2ZAT5Q.js → chunk-Z4PJMZLM.js} +2 -2
  142. package/dist/chunk-Z4PJMZLM.js.map +1 -0
  143. package/dist/{chunk-WSXNGF7X.js → chunk-ZNZISJDZ.js} +6 -2
  144. package/dist/chunk-ZNZISJDZ.js.map +1 -0
  145. package/dist/chunk-ZWN3AODA.js +11 -0
  146. package/dist/chunk-ZWN3AODA.js.map +1 -0
  147. package/dist/cli/index.js +25 -10
  148. package/dist/cli/index.js.map +1 -1
  149. package/dist/client/core.d.ts +1 -1
  150. package/dist/client/core.js +2 -0
  151. package/dist/client/core.js.map +1 -1
  152. package/dist/client/index.d.ts +44 -10
  153. package/dist/client/index.js +35 -0
  154. package/dist/client/index.js.map +1 -1
  155. package/dist/cloudflare-SIG42OIW.js +335 -0
  156. package/dist/cloudflare-SIG42OIW.js.map +1 -0
  157. package/dist/config-support-WQHQIJTA.js +104 -0
  158. package/dist/config-support-WQHQIJTA.js.map +1 -0
  159. package/dist/{csrf-BBrEZSBW.d.ts → csrf-Dgot9qSM.d.ts} +1 -1
  160. package/dist/deno-deploy-LQAYOOPW.js +196 -0
  161. package/dist/deno-deploy-LQAYOOPW.js.map +1 -0
  162. package/dist/{dev-CDFPXISP.js → dev-3UQVD2W6.js} +29 -18
  163. package/dist/dev-3UQVD2W6.js.map +1 -0
  164. package/dist/{dev-emit-GWD6IXV7.js → dev-emit-BFNMDCPB.js} +5 -5
  165. package/dist/{dev-emit-NBT6JD7R.js → dev-emit-MVAJAFGX.js} +5 -3
  166. package/dist/dev-emit-MVAJAFGX.js.map +1 -0
  167. package/dist/engine-singleton-X4R7AZBJ.js +315 -0
  168. package/dist/engine-singleton-X4R7AZBJ.js.map +1 -0
  169. package/dist/{generate-Y3GWM57K.js → generate-EN6EDITF.js} +43 -4
  170. package/dist/generate-EN6EDITF.js.map +1 -0
  171. package/dist/index-DctfHtv-.d.ts +1058 -0
  172. package/dist/index.d.ts +8 -4
  173. package/dist/index.js +25 -13
  174. package/dist/index.js.map +1 -1
  175. package/dist/{info-QXZW722N.js → info-Y55RWS42.js} +8 -6
  176. package/dist/{info-QXZW722N.js.map → info-Y55RWS42.js.map} +1 -1
  177. package/dist/{internal-api-FBK2YXSI.js → internal-api-4X6NDS2F.js} +23 -12
  178. package/dist/{internal-api-ZCJWJ5EC.js → internal-api-XQHU5JKY.js} +31 -16
  179. package/dist/internal-api-XQHU5JKY.js.map +1 -0
  180. package/dist/load-config-4ATXQUN3.js +16 -0
  181. package/dist/match-DmGgxjIU.d.ts +44 -0
  182. package/dist/{mcp-KTYP4ZON.js → mcp-IQRHFP3Y.js} +7 -7
  183. package/dist/netlify-C2IRCZKI.js +245 -0
  184. package/dist/netlify-C2IRCZKI.js.map +1 -0
  185. package/dist/node-OSVPYQ3D.js +10 -0
  186. package/dist/nonce-BXt7Qu_C.d.ts +31 -0
  187. package/dist/observability-bootstrap-LERYDHKY.js +16 -0
  188. package/dist/{openapi-OUXNB2F2.js → openapi-VFPEZSRI.js} +13 -11
  189. package/dist/{openapi-OUXNB2F2.js.map → openapi-VFPEZSRI.js.map} +1 -1
  190. package/dist/{plugin-runner-DHVr1cC5.d.ts → plugin-runner-BVMOSxvb.d.ts} +1 -1
  191. package/dist/{plugin-types-4VN1GMqV.d.ts → plugin-types-BUVfUQ0V.d.ts} +1 -1
  192. package/dist/preview-BT47VMIB.js +23 -0
  193. package/dist/preview-BT47VMIB.js.map +1 -0
  194. package/dist/provider-resolver-Dx6QuWrw.d.ts +128 -0
  195. package/dist/registry-KBZDCFVQ.js +23 -0
  196. package/dist/route-config-Cm_ZMA1C.d.ts +72 -0
  197. package/dist/route-policy-BxOycCDq.d.ts +65 -0
  198. package/dist/router/element-scroll-restoration.d.ts +28 -0
  199. package/dist/router/element-scroll-restoration.js +96 -0
  200. package/dist/router/element-scroll-restoration.js.map +1 -0
  201. package/dist/{routes-NJR4ISCT.js → routes-BPLU3ISV.js} +11 -9
  202. package/dist/{routes-NJR4ISCT.js.map → routes-BPLU3ISV.js.map} +1 -1
  203. package/dist/{scan-7MJC6PYU.js → scan-YJEE4KQK.js} +2 -2
  204. package/dist/{schema-DNIT7JQX.js → schema-SOAD43RQ.js} +7 -5
  205. package/dist/schemas-4AXHQMV3.js +25 -0
  206. package/dist/schemas-4AXHQMV3.js.map +1 -0
  207. package/dist/security-headers-Ccj7ncNx.d.ts +129 -0
  208. package/dist/server/agent/index.d.ts +2 -105
  209. package/dist/server/agent/index.js +1 -1
  210. package/dist/server/auth/index.d.ts +2 -21
  211. package/dist/server/auth/index.js +3 -2
  212. package/dist/server/cron/index.js +4 -3
  213. package/dist/server/define/index.d.ts +43 -57
  214. package/dist/server/define/index.js +10 -1
  215. package/dist/server/http/index.d.ts +7 -5
  216. package/dist/server/http/index.js +57 -12
  217. package/dist/server/index.d.ts +47 -439
  218. package/dist/server/index.js +120 -201
  219. package/dist/server/index.js.map +1 -1
  220. package/dist/server/jobs/index.js +4 -3
  221. package/dist/server/observability/index.d.ts +109 -35
  222. package/dist/server/observability/index.js +11 -7
  223. package/dist/server/plugins/index.d.ts +3 -3
  224. package/dist/server/scan/index.d.ts +47 -12
  225. package/dist/server/scan/index.js +13 -4
  226. package/dist/server/security/index.d.ts +61 -103
  227. package/dist/server/security/index.js +15 -6
  228. package/dist/server/webhook/index.d.ts +90 -3
  229. package/dist/server/webhook/index.js +12 -2
  230. package/dist/server-boundary-2WFT546S.js +149 -0
  231. package/dist/server-boundary-2WFT546S.js.map +1 -0
  232. package/dist/server-boundary-A67OPRKO.js +134 -0
  233. package/dist/server-boundary-A67OPRKO.js.map +1 -0
  234. package/dist/{services-typed-client-P4JERLBL.js → services-typed-client-XGT5SUUN.js} +2 -2
  235. package/dist/{start-25OV2CAK.js → start-3K3C4Z2X.js} +224 -161
  236. package/dist/start-3K3C4Z2X.js.map +1 -0
  237. package/dist/{static-RTO637XW.js → static-SVDWIOXJ.js} +24 -13
  238. package/dist/static-SVDWIOXJ.js.map +1 -0
  239. package/dist/{theo-cloud-UZ3GINRU.js → theo-cloud-3ET4G5T6.js} +9 -2
  240. package/dist/theo-cloud-3ET4G5T6.js.map +1 -0
  241. package/dist/vercel-BMCQKCWE.js +277 -0
  242. package/dist/vercel-BMCQKCWE.js.map +1 -0
  243. package/dist/vite-plugin/index.js +25 -13
  244. package/dist/vite-plugin-USXUIV3H.js +43 -0
  245. package/dist/vite-plugin-USXUIV3H.js.map +1 -0
  246. package/package.json +19 -6
  247. package/dist/actions-virtual-module-E4PISKMB.js.map +0 -1
  248. package/dist/agent-XAQCUQNB.js +0 -15
  249. package/dist/app-typed-client-HLP26EYM.js.map +0 -1
  250. package/dist/app-typed-client-I4X2UJWW.js.map +0 -1
  251. package/dist/aws-lambda-KES4MFJV.js +0 -172
  252. package/dist/aws-lambda-KES4MFJV.js.map +0 -1
  253. package/dist/body-parser-web-4Z2QTPDU.js.map +0 -1
  254. package/dist/body-parser-web-TIOTXPDW.js.map +0 -1
  255. package/dist/build-F2Q5QTSC.js.map +0 -1
  256. package/dist/bun-A5B2MJMO.js.map +0 -1
  257. package/dist/chunk-646CA6RV.js.map +0 -1
  258. package/dist/chunk-7LVM22VG.js.map +0 -1
  259. package/dist/chunk-A7JBF5FO.js.map +0 -1
  260. package/dist/chunk-AATSV4UV.js.map +0 -1
  261. package/dist/chunk-AM3QABW5.js +0 -161
  262. package/dist/chunk-AM3QABW5.js.map +0 -1
  263. package/dist/chunk-AXKUA57G.js +0 -94
  264. package/dist/chunk-AXKUA57G.js.map +0 -1
  265. package/dist/chunk-BHOTGS7N.js.map +0 -1
  266. package/dist/chunk-BMHS4WAN.js.map +0 -1
  267. package/dist/chunk-CMYSHZFT.js +0 -422
  268. package/dist/chunk-CMYSHZFT.js.map +0 -1
  269. package/dist/chunk-DQIPV7L5.js +0 -118
  270. package/dist/chunk-DQIPV7L5.js.map +0 -1
  271. package/dist/chunk-FB2HBNIC.js.map +0 -1
  272. package/dist/chunk-FNTLKHZ7.js.map +0 -1
  273. package/dist/chunk-FTFN4MYN.js.map +0 -1
  274. package/dist/chunk-HBU2GIMZ.js.map +0 -1
  275. package/dist/chunk-IEES3CHD.js.map +0 -1
  276. package/dist/chunk-JA2ZAT5Q.js.map +0 -1
  277. package/dist/chunk-KD5G3YXI.js.map +0 -1
  278. package/dist/chunk-KTKTHIUF.js +0 -405
  279. package/dist/chunk-KTKTHIUF.js.map +0 -1
  280. package/dist/chunk-LNVMHQ2Z.js +0 -54
  281. package/dist/chunk-LNVMHQ2Z.js.map +0 -1
  282. package/dist/chunk-LXAESF4Y.js.map +0 -1
  283. package/dist/chunk-MTEWLGVY.js.map +0 -1
  284. package/dist/chunk-NTWNO24W.js.map +0 -1
  285. package/dist/chunk-O3JIAU3V.js.map +0 -1
  286. package/dist/chunk-OLGPYOLO.js.map +0 -1
  287. package/dist/chunk-OOBYPCZC.js.map +0 -1
  288. package/dist/chunk-T5C46IIU.js.map +0 -1
  289. package/dist/chunk-U267AOWS.js +0 -28
  290. package/dist/chunk-U267AOWS.js.map +0 -1
  291. package/dist/chunk-UW2TEAGR.js +0 -77
  292. package/dist/chunk-UW2TEAGR.js.map +0 -1
  293. package/dist/chunk-WPJOTQA5.js +0 -1
  294. package/dist/chunk-WSXNGF7X.js.map +0 -1
  295. package/dist/chunk-WYHYOYRH.js.map +0 -1
  296. package/dist/chunk-XALU5LCU.js.map +0 -1
  297. package/dist/chunk-XR74JD4M.js +0 -457
  298. package/dist/chunk-XR74JD4M.js.map +0 -1
  299. package/dist/chunk-YGAXV5HR.js.map +0 -1
  300. package/dist/chunk-YXG2SGQ3.js.map +0 -1
  301. package/dist/cloudflare-IN2WB7FZ.js +0 -122
  302. package/dist/cloudflare-IN2WB7FZ.js.map +0 -1
  303. package/dist/deno-deploy-LYXQEJ6A.js +0 -107
  304. package/dist/deno-deploy-LYXQEJ6A.js.map +0 -1
  305. package/dist/dev-CDFPXISP.js.map +0 -1
  306. package/dist/dev-emit-NBT6JD7R.js.map +0 -1
  307. package/dist/generate-Y3GWM57K.js.map +0 -1
  308. package/dist/index-D_PxPXgQ.d.ts +0 -575
  309. package/dist/load-config-FIWNKOJO.js +0 -14
  310. package/dist/match-CfbEFRG4.d.ts +0 -26
  311. package/dist/netlify-DLEOCFAD.js +0 -150
  312. package/dist/netlify-DLEOCFAD.js.map +0 -1
  313. package/dist/node-QXYSUWQ4.js +0 -10
  314. package/dist/registry-S7OMF3OS.js +0 -23
  315. package/dist/start-25OV2CAK.js.map +0 -1
  316. package/dist/static-RTO637XW.js.map +0 -1
  317. package/dist/theo-cloud-UZ3GINRU.js.map +0 -1
  318. package/dist/vercel-6D6EZUVD.js +0 -133
  319. package/dist/vercel-6D6EZUVD.js.map +0 -1
  320. package/dist/vite-plugin-RJFKLF2U.js +0 -36
  321. /package/dist/{chunk-WPJOTQA5.js.map → adapters/agent-mount.js.map} +0 -0
  322. /package/dist/{agent-XAQCUQNB.js.map → agent-7IPEVCAY.js.map} +0 -0
  323. /package/dist/{check-45NKUVSQ.js.map → check-GIPZBFTX.js.map} +0 -0
  324. /package/dist/{chunk-47CINLWF.js.map → chunk-EDWEYQRG.js.map} +0 -0
  325. /package/dist/{chunk-ZB7D62OA.js.map → chunk-KUZVRJ7M.js.map} +0 -0
  326. /package/dist/{chunk-DS5MCU2X.js.map → chunk-URCXSUI3.js.map} +0 -0
  327. /package/dist/{internal-api-ZCJWJ5EC.js.map → chunk-YSJOZEI6.js.map} +0 -0
  328. /package/dist/{dev-emit-GWD6IXV7.js.map → dev-emit-BFNMDCPB.js.map} +0 -0
  329. /package/dist/{internal-api-FBK2YXSI.js.map → internal-api-4X6NDS2F.js.map} +0 -0
  330. /package/dist/{load-config-FIWNKOJO.js.map → load-config-4ATXQUN3.js.map} +0 -0
  331. /package/dist/{mcp-KTYP4ZON.js.map → mcp-IQRHFP3Y.js.map} +0 -0
  332. /package/dist/{node-QXYSUWQ4.js.map → node-OSVPYQ3D.js.map} +0 -0
  333. /package/dist/{scan-7MJC6PYU.js.map → observability-bootstrap-LERYDHKY.js.map} +0 -0
  334. /package/dist/{registry-S7OMF3OS.js.map → registry-KBZDCFVQ.js.map} +0 -0
  335. /package/dist/{schema-DNIT7JQX.js.map → scan-YJEE4KQK.js.map} +0 -0
  336. /package/dist/{vite-plugin-RJFKLF2U.js.map → schema-SOAD43RQ.js.map} +0 -0
  337. /package/dist/{services-typed-client-P4JERLBL.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-DQIPV7L5.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-FMTRNQQ7.js";
16
+ import {
17
+ buildSecurityHeaders
18
+ } from "./chunk-RPET332G.js";
19
+ import {
20
+ getObservabilityAdapter,
21
+ newSpanId,
22
+ newTraceId,
23
+ requestTrace
24
+ } from "./chunk-H53KNS6Q.js";
25
+ import {
26
+ RequestBodyConsumedError,
27
+ createLogger,
28
+ parseRequestBody,
15
29
  warnOnce
16
- } from "./chunk-T5C46IIU.js";
30
+ } from "./chunk-RARK7JBR.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) {
@@ -1017,7 +1149,11 @@ async function readActionBody(req, res, requestId, actionConfig) {
1017
1149
  function synthesizeFormData(parsed) {
1018
1150
  const fd = new FormData();
1019
1151
  for (const [name, value] of Object.entries(parsed.fields)) {
1020
- fd.append(name, value);
1152
+ if (Array.isArray(value)) {
1153
+ for (const single of value) fd.append(name, single);
1154
+ } else {
1155
+ fd.append(name, value);
1156
+ }
1021
1157
  }
1022
1158
  for (const file of parsed.files) {
1023
1159
  const blob = new Blob([file.buffer], {
@@ -1328,44 +1464,6 @@ function createCorsHandler(config) {
1328
1464
  };
1329
1465
  }
1330
1466
 
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
1467
  // src/server/observability/suggest.ts
1370
1468
  function levenshtein(a, b) {
1371
1469
  const m = a.length;
@@ -1757,19 +1855,226 @@ function resultFromState(state, config) {
1757
1855
  // src/server/agent/mount-agent.ts
1758
1856
  import { compileAgentModule as compileAgentModule2, resolveEnabledSkills as resolveEnabledSkills2, streamAgentUIMessages as streamAgentUIMessages2 } from "@theokit/agents";
1759
1857
 
1858
+ // src/server/agent/agent-access.ts
1859
+ var AgentPolicyTypeError = class extends Error {
1860
+ constructor(source, actual) {
1861
+ super(
1862
+ `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.`
1863
+ );
1864
+ this.name = "AgentPolicyTypeError";
1865
+ }
1866
+ };
1867
+ function readAgentPolicy(mod, source) {
1868
+ const declared = typeof mod === "object" && mod !== null ? mod.policy : void 0;
1869
+ if (declared === void 0) return void 0;
1870
+ if (declared !== "public" && typeof declared !== "function") {
1871
+ throw new AgentPolicyTypeError(source, declared === null ? "null" : typeof declared);
1872
+ }
1873
+ return declared;
1874
+ }
1875
+ var log = createLogger({ context: { scope: "theokit:agent-access" } });
1876
+ async function admitAgentRequest(policy, resolveSubject, params, body) {
1877
+ if (policy === void 0 || policy === "public") return { allowed: true };
1878
+ const subject = resolveSubject === void 0 ? null : await resolveSubject();
1879
+ return evaluateRoutePolicy(policy, { subject, query: void 0, body, params });
1880
+ }
1881
+ function agentAccessDenied(decision, params) {
1882
+ if (!decision.allowed) {
1883
+ log.warn("agent endpoint refused a caller", {
1884
+ agent: params.agent,
1885
+ endpoint: params.endpoint,
1886
+ reason: decision.reason
1887
+ });
1888
+ }
1889
+ return new Response(
1890
+ JSON.stringify({
1891
+ error: {
1892
+ code: "FORBIDDEN",
1893
+ 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.`
1894
+ }
1895
+ }),
1896
+ { status: 403, headers: { "content-type": "application/json; charset=utf-8" } }
1897
+ );
1898
+ }
1899
+
1760
1900
  // src/server/agent/build-agent-streamer.ts
1761
1901
  import {
1762
1902
  compileAgentModule,
1763
1903
  resolveEnabledSkills,
1764
1904
  streamAgentUIMessages
1765
1905
  } from "@theokit/agents";
1766
- function buildAgentHitl(compiled) {
1906
+
1907
+ // src/server/agent/hitl-pause-spans.ts
1908
+ var pauseSpans = /* @__PURE__ */ new Map();
1909
+ function registerPauseSpan(approvalId, span) {
1910
+ pauseSpans.set(approvalId, span);
1911
+ }
1912
+ function closePauseSpan(approvalId, { resumeObserved }) {
1913
+ const span = pauseSpans.get(approvalId);
1914
+ if (span === void 0) return;
1915
+ pauseSpans.delete(approvalId);
1916
+ span.setAttribute("hitl.resume_observed", resumeObserved);
1917
+ if (resumeObserved) span.setStatus("ok");
1918
+ else
1919
+ span.setStatus("error", "HITL pause never observed to resume; duration is not the human wait");
1920
+ span.end();
1921
+ }
1922
+
1923
+ // src/server/agent/observe-agent-run.ts
1924
+ var TOKEN_FIELDS = [
1925
+ ["inputTokens", "tokens.input"],
1926
+ ["outputTokens", "tokens.output"],
1927
+ ["totalTokens", "tokens.total"],
1928
+ ["reasoningTokens", "tokens.reasoning"],
1929
+ ["cacheReadTokens", "tokens.cache_read"],
1930
+ ["cacheWriteTokens", "tokens.cache_write"]
1931
+ ];
1932
+ var STOP_REASONS = /* @__PURE__ */ new Set(["step_limit", "no_progress"]);
1933
+ var GEN_AI_REQUEST_MODEL = "gen_ai.request.model";
1934
+ function recordModel(span, metadata) {
1935
+ if (metadata === null || typeof metadata !== "object") return;
1936
+ const model = metadata.model;
1937
+ if (typeof model === "string" && model.length > 0) span.setAttribute(GEN_AI_REQUEST_MODEL, model);
1938
+ }
1939
+ function recordStopReason(span, metadata) {
1940
+ if (metadata === null || typeof metadata !== "object") return;
1941
+ const reason = metadata.stopReason;
1942
+ if (typeof reason === "string" && STOP_REASONS.has(reason)) {
1943
+ span.setAttribute("stop.reason", reason);
1944
+ }
1945
+ }
1946
+ function recordTokenUsage(span, metadata) {
1947
+ if (metadata === null || typeof metadata !== "object") return;
1948
+ const bag = metadata;
1949
+ if (typeof bag.cost === "number") span.setAttribute("cost.usd", bag.cost);
1950
+ const usage = bag.usage;
1951
+ if (usage === null || usage === void 0 || typeof usage !== "object") return;
1952
+ const fields = usage;
1953
+ for (const [field, attribute] of TOKEN_FIELDS) {
1954
+ const value = fields[field];
1955
+ if (typeof value === "number") span.setAttribute(attribute, value);
1956
+ }
1957
+ }
1958
+ function childOf(state) {
1959
+ return { traceId: state.traceId, parentSpanId: state.runSpanId };
1960
+ }
1961
+ function openToolSpan(state, adapter, chunk) {
1962
+ const id = chunk.toolCallId;
1963
+ if (id === void 0) return;
1964
+ const tool = chunk.toolName ?? "unknown";
1965
+ state.toolNames.set(id, tool);
1966
+ state.tools.set(
1967
+ id,
1968
+ adapter.startSpan("agent.tool", { agent: state.agent, tool, toolCallId: id }, childOf(state))
1969
+ );
1970
+ }
1971
+ function openPauseSpan(state, adapter, chunk) {
1972
+ const id = chunk.toolCallId;
1973
+ const approvalId = chunk.approvalId;
1974
+ if (id === void 0 || approvalId === void 0) return;
1975
+ const pauseSpan = adapter.startSpan(
1976
+ "agent.hitl",
1977
+ {
1978
+ agent: state.agent,
1979
+ tool: state.toolNames.get(id) ?? "unknown",
1980
+ approvalId,
1981
+ toolCallId: id
1982
+ },
1983
+ childOf(state)
1984
+ );
1985
+ state.pauses.set(id, approvalId);
1986
+ registerPauseSpan(approvalId, pauseSpan);
1987
+ }
1988
+ function closeToolSpan(state, chunk) {
1989
+ const id = chunk.toolCallId;
1990
+ if (id === void 0) return;
1991
+ const pausedApprovalId = state.pauses.get(id);
1992
+ if (pausedApprovalId !== void 0) {
1993
+ closePauseSpan(pausedApprovalId, { resumeObserved: true });
1994
+ state.pauses.delete(id);
1995
+ }
1996
+ const span = state.tools.get(id);
1997
+ if (span === void 0) return;
1998
+ if (chunk.type === "tool-output-error") span.setStatus("error", chunk.errorText);
1999
+ else span.setStatus("ok");
2000
+ span.end();
2001
+ state.tools.delete(id);
2002
+ }
2003
+ async function* observeAgentRun(chunks, adapter, context) {
2004
+ const runAttributes = { agent: context.agent };
2005
+ if (context.sessionId !== void 0) runAttributes.sessionId = context.sessionId;
2006
+ const traceId = context.traceId ?? newTraceId();
2007
+ const runSpanId = newSpanId();
2008
+ const runContext = context.traceId !== void 0 && context.parentSpanId !== void 0 ? { traceId, spanId: runSpanId, parentSpanId: context.parentSpanId } : { traceId, spanId: runSpanId };
2009
+ const state = {
2010
+ run: adapter.startSpan("agent.run", runAttributes, runContext),
2011
+ tools: /* @__PURE__ */ new Map(),
2012
+ pauses: /* @__PURE__ */ new Map(),
2013
+ toolNames: /* @__PURE__ */ new Map(),
2014
+ agent: context.agent,
2015
+ traceId,
2016
+ runSpanId
2017
+ };
2018
+ let settled = false;
2019
+ function closeAll(status, message) {
2020
+ if (settled) return;
2021
+ settled = true;
2022
+ for (const approvalId of state.pauses.values()) {
2023
+ closePauseSpan(approvalId, { resumeObserved: false });
2024
+ }
2025
+ for (const span of state.tools.values()) {
2026
+ span.setStatus(status, message);
2027
+ span.end();
2028
+ }
2029
+ state.pauses.clear();
2030
+ state.tools.clear();
2031
+ state.run.setStatus(status, message);
2032
+ state.run.end();
2033
+ }
2034
+ try {
2035
+ for await (const chunk of chunks) {
2036
+ const observed = chunk;
2037
+ if (observed.type === "tool-input-available") openToolSpan(state, adapter, observed);
2038
+ else if (observed.type === "tool-approval-request") openPauseSpan(state, adapter, observed);
2039
+ else if (observed.type === "tool-output-available" || observed.type === "tool-output-error")
2040
+ closeToolSpan(state, observed);
2041
+ else if (observed.type === "finish") {
2042
+ recordTokenUsage(state.run, observed.messageMetadata);
2043
+ recordStopReason(state.run, observed.messageMetadata);
2044
+ recordModel(state.run, observed.messageMetadata);
2045
+ }
2046
+ yield chunk;
2047
+ }
2048
+ closeAll("ok");
2049
+ } catch (error) {
2050
+ closeAll("error", error instanceof Error ? error.message : "unknown error");
2051
+ throw error;
2052
+ } finally {
2053
+ closeAll("error", "agent run stream abandoned by its consumer");
2054
+ }
2055
+ }
2056
+
2057
+ // src/server/agent/observe-served-run.ts
2058
+ function observeServedRun(stream, options) {
2059
+ const adapter = getObservabilityAdapter();
2060
+ if (adapter === void 0) return stream;
2061
+ const trace = requestTrace(options.request);
2062
+ const context = { agent: options.agentName, traceId: trace.traceId };
2063
+ if (options.sessionId !== void 0) context.sessionId = options.sessionId;
2064
+ const parentSpanId = trace.outermostSpanId ?? trace.parentSpanId;
2065
+ if (parentSpanId !== void 0) context.parentSpanId = parentSpanId;
2066
+ return observeAgentRun(stream, adapter, context);
2067
+ }
2068
+
2069
+ // src/server/agent/build-agent-streamer.ts
2070
+ function buildAgentHitl(compiled, owner) {
1767
2071
  const gated = compiled.hitl;
1768
2072
  if (gated === void 0 || gated.size === 0) return void 0;
1769
2073
  const registry = getApprovalRegistry();
1770
2074
  return {
1771
2075
  gated,
1772
2076
  awaitApproval: (approvalId, opts, toolName) => registry.register(approvalId, {
2077
+ ...owner !== void 0 ? { owner } : {},
1773
2078
  timeoutMs: opts.timeout ?? 3e5,
1774
2079
  onTimeout: opts.onTimeout ?? "abort",
1775
2080
  toolName,
@@ -1778,7 +2083,7 @@ function buildAgentHitl(compiled) {
1778
2083
  })
1779
2084
  };
1780
2085
  }
1781
- function makeThreadStartRun(mod, apiKey, source) {
2086
+ function makeThreadStartRun(mod, apiKey, source, agentName, request) {
1782
2087
  return (sessionId, message) => (async function* () {
1783
2088
  const compiled = compileAgentModule(mod, source);
1784
2089
  if (compiled.skillsResolver) {
@@ -1790,13 +2095,16 @@ function makeThreadStartRun(mod, apiKey, source) {
1790
2095
  }
1791
2096
  const hitl = buildAgentHitl(compiled);
1792
2097
  const resolvedApiKey = typeof apiKey === "function" ? apiKey(compiled.model) : apiKey;
1793
- yield* streamAgentUIMessages(compiled, resolvedApiKey, { message, sessionId, hitl });
2098
+ const stream = streamAgentUIMessages(compiled, resolvedApiKey, { message, sessionId, hitl });
2099
+ yield* observeServedRun(stream, { agentName, sessionId, request });
1794
2100
  })();
1795
2101
  }
1796
2102
 
1797
2103
  // src/server/agent/durable-ui-message-stream-response.ts
1798
2104
  var SSE_BASE_HEADERS = {
1799
2105
  "content-type": "text/event-stream",
2106
+ "cache-control": "no-cache",
2107
+ "x-accel-buffering": "no",
1800
2108
  "x-vercel-ai-ui-message-stream": "v1"
1801
2109
  };
1802
2110
  var RUN_ID_HEADER = "x-theokit-run-id";
@@ -1942,38 +2250,70 @@ function parseAgentRequestBody(body) {
1942
2250
  }
1943
2251
  return null;
1944
2252
  }
1945
- async function mountAgent(mod, request, apiKey, { source = "agent module", csrfMode = "strict", projectRoot } = {}) {
2253
+ function memoizeSubject(resolveSubject) {
2254
+ if (resolveSubject === void 0) return void 0;
2255
+ let resolved;
2256
+ return async () => {
2257
+ resolved ??= { subject: await resolveSubject() };
2258
+ return resolved.subject;
2259
+ };
2260
+ }
2261
+ async function resolveApprovalOwner(declaredPolicy, resolveOnce) {
2262
+ if (declaredPolicy === void 0 || declaredPolicy === "public") return void 0;
2263
+ return (await resolveOnce?.() ?? void 0)?.id;
2264
+ }
2265
+ async function admitRequest(request, policy, resolveSubject, agentName) {
2266
+ let body = null;
2267
+ try {
2268
+ body = await request.json();
2269
+ } catch {
2270
+ }
2271
+ const input = parseAgentRequestBody(body);
2272
+ if (input === null) {
2273
+ return jsonError(400, "BAD_REQUEST", "Request must contain a non-empty message or messages[].");
2274
+ }
2275
+ const params = { agent: agentName, endpoint: "run", sessionId: input.sessionId };
2276
+ const decision = await admitAgentRequest(policy, resolveSubject, params, input);
2277
+ if (!decision.allowed) return agentAccessDenied(decision, params);
2278
+ return input;
2279
+ }
2280
+ async function mountAgent(mod, request, apiKey, {
2281
+ source = "agent module",
2282
+ csrfMode = "strict",
2283
+ projectRoot,
2284
+ agentName,
2285
+ policy,
2286
+ resolveSubject
2287
+ } = {}) {
1946
2288
  if (csrfMode !== "off") {
1947
2289
  const csrf = validateCsrfRequest(request);
1948
2290
  if (!csrf.valid && csrfMode === "strict") {
1949
2291
  return jsonError(403, "CSRF_FAILED", `CSRF check failed: ${csrf.reason}`);
1950
2292
  }
1951
2293
  }
2294
+ const identity = agentName ?? source;
2295
+ const declaredPolicy = policy ?? readAgentPolicy(mod, source);
2296
+ const resolveOnce = memoizeSubject(resolveSubject);
2297
+ const admitted = await admitRequest(request, declaredPolicy, resolveOnce, identity);
2298
+ if (admitted instanceof Response) return admitted;
2299
+ const input = admitted;
1952
2300
  const compiled = compileAgentModule2(mod, source);
1953
2301
  const resolvedApiKey = typeof apiKey === "function" ? apiKey(compiled.model) : apiKey;
1954
2302
  if (compiled.skillsResolver) {
1955
2303
  const enabled = await resolveEnabledSkills2(compiled.skillsResolver, compiled.runContext ?? {});
1956
2304
  if (enabled !== void 0) compiled.skills = { enabled, autoInject: true };
1957
2305
  }
1958
- let body = null;
1959
- try {
1960
- body = await request.json();
1961
- } catch {
1962
- }
1963
- const input = parseAgentRequestBody(body);
1964
- if (input === null) {
1965
- return jsonError(400, "BAD_REQUEST", "Request must contain a non-empty message or messages[].");
1966
- }
1967
- const hitl = buildAgentHitl(compiled);
2306
+ const hitl = buildAgentHitl(compiled, await resolveApprovalOwner(declaredPolicy, resolveOnce));
1968
2307
  const runId = mintRunId();
2308
+ const stream = streamAgentUIMessages2(compiled, resolvedApiKey, {
2309
+ ...input,
2310
+ hitl,
2311
+ signal: request.signal,
2312
+ cwd: resolveDiscoveryCwd(compiled, projectRoot),
2313
+ baseDir: resolveSessionBaseDir(projectRoot)
2314
+ });
1969
2315
  return durableUiMessageStreamResponse(
1970
- streamAgentUIMessages2(compiled, resolvedApiKey, {
1971
- ...input,
1972
- hitl,
1973
- signal: request.signal,
1974
- cwd: resolveDiscoveryCwd(compiled, projectRoot),
1975
- baseDir: resolveSessionBaseDir(projectRoot)
1976
- }),
2316
+ observeServedRun(stream, { agentName: identity, request }),
1977
2317
  { runId, cache: getRunEventCache() }
1978
2318
  );
1979
2319
  }
@@ -1992,21 +2332,17 @@ function resolveSessionBaseDir(projectRoot) {
1992
2332
  }
1993
2333
 
1994
2334
  // src/server/scan/module-loader.ts
1995
- import { pathToFileURL } from "url";
1996
2335
  function createViteLoader(vite) {
1997
2336
  return (path) => vite.ssrLoadModule(path);
1998
2337
  }
1999
2338
  function createProductionLoader() {
2000
- return async (path) => {
2001
- const url = pathToFileURL(path).href;
2002
- return import(url);
2003
- };
2339
+ return (path) => importUserModule(path);
2004
2340
  }
2005
2341
 
2006
2342
  // src/server/security/csp-report.ts
2007
2343
  var CSP_REPORT_PATH = "/__theo/csp-report";
2008
2344
  var MAX_BODY = 16 * 1024;
2009
- function pickHeader2(value) {
2345
+ function pickHeader(value) {
2010
2346
  if (typeof value === "string") return value;
2011
2347
  if (Array.isArray(value) && value.length > 0) return value[0];
2012
2348
  return "";
@@ -2069,7 +2405,7 @@ async function readBody(req, maxBytes) {
2069
2405
  }
2070
2406
  async function handleCspReport(req, res, opts) {
2071
2407
  const ctHeader = req.headers["content-type"];
2072
- const ct = pickHeader2(ctHeader);
2408
+ const ct = pickHeader(ctHeader);
2073
2409
  let raw;
2074
2410
  try {
2075
2411
  raw = await readBody(req, MAX_BODY);
@@ -2225,50 +2561,6 @@ var CsrfReadinessStore = class _CsrfReadinessStore {
2225
2561
  };
2226
2562
 
2227
2563
  // src/server/security/security-headers.ts
2228
- 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";
2229
- var DEFAULT_PERMISSIONS_POLICY = "geolocation=(), camera=(), microphone=(), payment=(), usb=(), accelerometer=(), gyroscope=()";
2230
- var DEFAULT_HSTS = "max-age=31536000; includeSubDomains";
2231
- function applyNonceToCsp(policy, nonce) {
2232
- return policy.split(";").map((directive) => {
2233
- const trimmed = directive.trim();
2234
- if (!trimmed.startsWith("script-src")) return directive;
2235
- if (trimmed.includes("'unsafe-inline'")) {
2236
- return directive.replace("'unsafe-inline'", `'nonce-${nonce}'`);
2237
- }
2238
- return `${directive} 'nonce-${nonce}'`;
2239
- }).join(";");
2240
- }
2241
- function applyCsp(out, config, effectiveNonce) {
2242
- if (config.csp === false || config.cspMode === "off") return;
2243
- let policy = typeof config.csp === "string" ? config.csp : DEFAULT_CSP;
2244
- if (effectiveNonce) {
2245
- policy = applyNonceToCsp(policy, effectiveNonce);
2246
- }
2247
- const mode = config.cspMode ?? "enforce";
2248
- if (mode === "enforce") {
2249
- out["Content-Security-Policy"] = policy;
2250
- } else {
2251
- out["Content-Security-Policy-Report-Only"] = policy;
2252
- }
2253
- }
2254
- function buildSecurityHeaders(config, env, options = {}) {
2255
- const out = {};
2256
- const effectiveNonce = options.prerender ? void 0 : options.nonce;
2257
- applyCsp(out, config, effectiveNonce);
2258
- out["X-Frame-Options"] = config.frameOptions ?? "DENY";
2259
- out["X-Content-Type-Options"] = config.contentTypeOptions ?? "nosniff";
2260
- out["Referrer-Policy"] = config.referrerPolicy ?? "strict-origin-when-cross-origin";
2261
- if (config.permissionsPolicy !== false) {
2262
- out["Permissions-Policy"] = typeof config.permissionsPolicy === "string" ? config.permissionsPolicy : DEFAULT_PERMISSIONS_POLICY;
2263
- }
2264
- if (env.production && config.hsts !== false) {
2265
- out["Strict-Transport-Security"] = typeof config.hsts === "string" ? config.hsts : DEFAULT_HSTS;
2266
- }
2267
- if (effectiveNonce) {
2268
- out["Cache-Control"] = "private, no-store";
2269
- }
2270
- return out;
2271
- }
2272
2564
  function applySecurityHeaders(res, config, env, options = {}) {
2273
2565
  const headers = buildSecurityHeaders(config, env, options);
2274
2566
  for (const [key, value] of Object.entries(headers)) {
@@ -2276,48 +2568,23 @@ function applySecurityHeaders(res, config, env, options = {}) {
2276
2568
  }
2277
2569
  }
2278
2570
 
2279
- // src/server/auth/nonce.ts
2280
- function bytesToBase64(bytes) {
2281
- if (typeof Buffer !== "undefined") {
2282
- return Buffer.from(bytes).toString("base64");
2283
- }
2284
- let binary = "";
2285
- for (const b of bytes) {
2286
- binary += String.fromCharCode(b);
2287
- }
2288
- return btoa(binary);
2289
- }
2290
- var cachedWebCrypto;
2291
- function getWebCrypto() {
2292
- if (cachedWebCrypto === void 0) {
2293
- const candidate = globalThis.crypto;
2294
- cachedWebCrypto = candidate && typeof candidate.getRandomValues === "function" ? candidate : null;
2295
- }
2296
- if (!cachedWebCrypto) {
2297
- throw new Error(
2298
- "generateNonce: Web Crypto unavailable. TheoKit requires Node.js 19+, Bun, Deno, or any modern Edge runtime where `globalThis.crypto.getRandomValues` is present."
2299
- );
2300
- }
2301
- return cachedWebCrypto;
2302
- }
2303
- function generateNonce() {
2304
- const buf = new Uint8Array(16);
2305
- getWebCrypto().getRandomValues(buf);
2306
- return bytesToBase64(buf);
2307
- }
2308
-
2309
2571
  export {
2572
+ subjectFromContext,
2573
+ writeWebResponseToServerResponse,
2574
+ createServerContext,
2310
2575
  executeRoute,
2311
2576
  executeAction,
2312
2577
  BATCH_PATH,
2313
2578
  handleBatchRequest,
2314
2579
  createCorsHandler,
2315
- TRACE_HEADER,
2316
- extractTraceId,
2317
2580
  findSuggestion,
2318
2581
  createPluginRunnerFromConfig,
2319
2582
  InMemoryStore,
2320
2583
  createRateLimiter,
2584
+ readAgentPolicy,
2585
+ admitAgentRequest,
2586
+ agentAccessDenied,
2587
+ closePauseSpan,
2321
2588
  makeThreadStartRun,
2322
2589
  SSE_BASE_HEADERS,
2323
2590
  RUN_ID_HEADER,
@@ -2334,8 +2601,6 @@ export {
2334
2601
  handleCspReport,
2335
2602
  handleCsrfReadiness,
2336
2603
  CsrfReadinessStore,
2337
- buildSecurityHeaders,
2338
- applySecurityHeaders,
2339
- generateNonce
2604
+ applySecurityHeaders
2340
2605
  };
2341
- //# sourceMappingURL=chunk-WYHYOYRH.js.map
2606
+ //# sourceMappingURL=chunk-2COPDKIG.js.map