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
@@ -0,0 +1,790 @@
1
+ import {
2
+ createObservabilityPlugin,
3
+ requestTrace,
4
+ resolveAdapter
5
+ } from "./chunk-MCTC6HSE.js";
6
+ import {
7
+ createLogger,
8
+ warnOnce
9
+ } from "./chunk-72DMJBXI.js";
10
+ import {
11
+ validateCsrfRequest
12
+ } from "./chunk-P6OS7652.js";
13
+ import {
14
+ processSingleton
15
+ } from "./chunk-3PBAN2YE.js";
16
+ import {
17
+ newSpanId,
18
+ newTraceId
19
+ } from "./chunk-UMNXCU3K.js";
20
+ import {
21
+ evaluateRoutePolicy
22
+ } from "./chunk-YN4W7LCX.js";
23
+
24
+ // src/server/agent/mount-agent.ts
25
+ import { compileAgentModule as compileAgentModule2, resolveEnabledSkills as resolveEnabledSkills2, streamAgentUIMessages as streamAgentUIMessages2 } from "@theokit/agents";
26
+
27
+ // src/server/agent/agent-access.ts
28
+ var AgentPolicyTypeError = class extends Error {
29
+ constructor(source, actual) {
30
+ super(
31
+ `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.`
32
+ );
33
+ this.name = "AgentPolicyTypeError";
34
+ }
35
+ };
36
+ function readAgentPolicy(mod, source) {
37
+ const declared = typeof mod === "object" && mod !== null ? mod.policy : void 0;
38
+ if (declared === void 0) return void 0;
39
+ if (declared !== "public" && typeof declared !== "function") {
40
+ throw new AgentPolicyTypeError(source, declared === null ? "null" : typeof declared);
41
+ }
42
+ return declared;
43
+ }
44
+ var log = createLogger({ context: { scope: "theokit:agent-access" } });
45
+ async function admitAgentRequest(policy, resolveSubject, params, body) {
46
+ if (policy === void 0 || policy === "public") return { allowed: true };
47
+ const subject = resolveSubject === void 0 ? null : await resolveSubject();
48
+ return evaluateRoutePolicy(policy, { subject, query: void 0, body, params });
49
+ }
50
+ function agentAccessDenied(decision, params) {
51
+ if (!decision.allowed) {
52
+ log.warn("agent endpoint refused a caller", {
53
+ agent: params.agent,
54
+ endpoint: params.endpoint,
55
+ reason: decision.reason
56
+ });
57
+ }
58
+ return new Response(
59
+ JSON.stringify({
60
+ error: {
61
+ code: "FORBIDDEN",
62
+ 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.`
63
+ }
64
+ }),
65
+ { status: 403, headers: { "content-type": "application/json; charset=utf-8" } }
66
+ );
67
+ }
68
+
69
+ // src/server/agent/build-agent-streamer.ts
70
+ import {
71
+ compileAgentModule,
72
+ resolveEnabledSkills,
73
+ streamAgentUIMessages
74
+ } from "@theokit/agents";
75
+
76
+ // src/server/agent/approval-registry.ts
77
+ function getApprovalRegistry() {
78
+ return processSingleton("approval-registry", () => createInProcessApprovalRegistry());
79
+ }
80
+ function createInProcessApprovalRegistry() {
81
+ const pending = /* @__PURE__ */ new Map();
82
+ return {
83
+ register(approvalId, opts) {
84
+ return new Promise((resolve) => {
85
+ const settle = (decision) => {
86
+ const entry = pending.get(approvalId);
87
+ if (!entry) return;
88
+ clearTimeout(entry.timer);
89
+ pending.delete(approvalId);
90
+ resolve(decision);
91
+ };
92
+ const timer = setTimeout(() => {
93
+ settle({
94
+ approved: opts.onTimeout === "proceed",
95
+ settledBy: "timeout",
96
+ // Every value in this sentence was already here and none of it used to survive the
97
+ // settle. `onTimeout` is named because all three of its values reach this line and two
98
+ // of them deny — an operator who wrote `'retry'` and got a denial had nothing to read
99
+ // that mentioned retry.
100
+ reason: `no decision within ${String(opts.timeoutMs)} ms; onTimeout: '${opts.onTimeout}' was applied`
101
+ });
102
+ }, opts.timeoutMs);
103
+ const info = {
104
+ approvalId,
105
+ toolName: opts.toolName,
106
+ question: opts.question,
107
+ expiresAt: Date.now() + opts.timeoutMs,
108
+ ...opts.payloadSchema !== void 0 ? { payloadSchema: opts.payloadSchema } : {}
109
+ };
110
+ pending.set(approvalId, {
111
+ settle,
112
+ timer,
113
+ info,
114
+ ...opts.owner !== void 0 ? { owner: opts.owner } : {}
115
+ });
116
+ });
117
+ },
118
+ resolve(approvalId, decision) {
119
+ const entry = pending.get(approvalId);
120
+ if (!entry) return false;
121
+ entry.settle(typeof decision === "boolean" ? { approved: decision } : decision);
122
+ return true;
123
+ },
124
+ list() {
125
+ return [...pending.values()].map((p) => p.info);
126
+ },
127
+ ownerOf(approvalId) {
128
+ return pending.get(approvalId)?.owner;
129
+ }
130
+ };
131
+ }
132
+
133
+ // src/config/schemas/rate-limit.ts
134
+ import { z } from "zod";
135
+ var baseRateLimitSchema = z.object({
136
+ windowMs: z.number().min(1),
137
+ max: z.number().int().min(1)
138
+ });
139
+ var rateLimitSchema = z.union([
140
+ baseRateLimitSchema,
141
+ z.object({
142
+ default: baseRateLimitSchema.optional(),
143
+ routes: z.record(z.string(), baseRateLimitSchema).optional(),
144
+ keyBy: z.union([
145
+ z.enum(["ip", "session", "user"]),
146
+ z.function({ input: z.tuple([z.unknown()]), output: z.string() })
147
+ ]).optional(),
148
+ cookieName: z.string().min(1).optional(),
149
+ /**
150
+ * How many reverse proxies sit in front of the app, for `keyBy: 'ip'`. `false` (default)
151
+ * trusts none; `true` means one; a number names a longer chain.
152
+ *
153
+ * Required for correct limiting behind Caddy/nginx/a load balancer — without it every visitor
154
+ * keys on the proxy address and shares a single bucket. Off by default because
155
+ * `x-forwarded-for` is client-writable.
156
+ */
157
+ trustProxy: z.union([z.boolean(), z.number().int().min(0)]).optional()
158
+ })
159
+ ]);
160
+
161
+ // src/config/schemas/upload.ts
162
+ import { z as z2 } from "zod";
163
+ var uploadSchema = z2.object({
164
+ maxFileSize: z2.number().min(1).default(10 * 1024 * 1024),
165
+ // 10MB
166
+ maxFiles: z2.number().int().min(1).default(10),
167
+ maxFieldSize: z2.number().min(1).default(1 * 1024 * 1024)
168
+ // 1MB
169
+ });
170
+
171
+ // src/config/schemas/logging.ts
172
+ import { z as z3 } from "zod";
173
+ var loggingSchema = z3.object({
174
+ level: z3.enum(["debug", "info", "warn", "error", "silent"]).default("info")
175
+ });
176
+
177
+ // src/config/schemas/cache.ts
178
+ import { z as z4 } from "zod";
179
+ var routeRuleSchema = z4.object({
180
+ maxAge: z4.number().nonnegative().optional(),
181
+ swr: z4.number().nonnegative().optional(),
182
+ tags: z4.array(z4.string()).optional()
183
+ });
184
+ var cacheSchema = z4.object({
185
+ enabled: z4.boolean().default(true),
186
+ /** 'memory' uses InMemoryCacheAdapter; otherwise pass a custom adapter instance. */
187
+ storage: z4.union([z4.literal("memory"), z4.custom()]).default("memory"),
188
+ maxEntries: z4.number().int().positive().default(1e3),
189
+ defaults: z4.object({
190
+ maxAge: z4.number().nonnegative().default(1),
191
+ swr: z4.number().nonnegative().optional(),
192
+ cacheErrors: z4.boolean().default(false)
193
+ }).default({ maxAge: 1, cacheErrors: false }),
194
+ keyDerivation: z4.object({
195
+ excludeQuery: z4.array(z4.string()).optional(),
196
+ sortQuery: z4.boolean().default(true),
197
+ lowercaseHost: z4.boolean().default(true)
198
+ }).default({ sortQuery: true, lowercaseHost: true }),
199
+ routeRules: z4.record(z4.string(), routeRuleSchema).optional()
200
+ });
201
+
202
+ // src/config/schemas/observability.ts
203
+ import { z as z5 } from "zod";
204
+ var observabilitySchema = z5.object({
205
+ /** Set `false` to opt out even when the environment would enable an exporter. */
206
+ enabled: z5.boolean().default(true),
207
+ /**
208
+ * An `ObservabilityAdapter` instance. Validated structurally rather than by
209
+ * shape, for the same reason `storage` and `plugins` are: the config layer
210
+ * cannot import the adapter contract without inverting the module graph, and
211
+ * the adapter is a live object rather than data.
212
+ */
213
+ provider: z5.custom().optional()
214
+ });
215
+
216
+ // src/config/schemas/security.ts
217
+ import { z as z7 } from "zod";
218
+
219
+ // src/config/schemas/header-safe.ts
220
+ import { z as z6 } from "zod";
221
+ var headerSafeString = z6.string().refine((s) => !/[\r\n]/.test(s), { message: "Header value must not contain CR/LF" });
222
+
223
+ // src/config/schemas/security.ts
224
+ var securityHeadersSchema = z7.object({
225
+ csp: z7.union([headerSafeString, z7.literal(false)]).optional(),
226
+ // T6.1 — default flipped from 'report-only' to 'enforce' for 0.3.0.
227
+ // Users who want the old behaviour set `cspMode: 'report-only'`
228
+ // explicitly.
229
+ cspMode: z7.enum(["enforce", "report-only", "off"]).default("enforce"),
230
+ hsts: z7.union([headerSafeString, z7.literal(false)]).optional(),
231
+ frameOptions: z7.enum(["DENY", "SAMEORIGIN"]).default("DENY"),
232
+ contentTypeOptions: z7.literal("nosniff").default("nosniff"),
233
+ referrerPolicy: headerSafeString.default("strict-origin-when-cross-origin"),
234
+ /**
235
+ * T1.1 — Permissions-Policy directive string. EC-3-refined: rejects CR/LF.
236
+ * Pass `false` to suppress the header.
237
+ */
238
+ permissionsPolicy: z7.union([headerSafeString, z7.literal(false)]).optional()
239
+ });
240
+ var disallowedConfigSchema = z7.object({
241
+ routes: z7.array(z7.union([z7.string(), z7.instanceof(RegExp)])),
242
+ behavior: z7.enum(["warn", "raise"]).default("raise")
243
+ });
244
+ var corsSchema = z7.object({
245
+ origins: z7.union([
246
+ z7.literal("*"),
247
+ headerSafeString,
248
+ z7.instanceof(RegExp),
249
+ z7.array(z7.union([headerSafeString, z7.instanceof(RegExp)])),
250
+ z7.function({ input: z7.tuple([z7.string()]), output: z7.boolean() })
251
+ ]),
252
+ methods: z7.array(z7.enum(["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"])).optional(),
253
+ allowedHeaders: z7.array(headerSafeString).optional(),
254
+ exposedHeaders: z7.array(headerSafeString).optional(),
255
+ credentials: z7.boolean().default(false),
256
+ maxAge: z7.number().int().min(0).max(86400).default(600)
257
+ }).refine((c) => !(c.origins === "*" && c.credentials), {
258
+ message: 'CORS spec forbids origins:"*" with credentials:true \u2014 browsers ignore the wildcard'
259
+ });
260
+ var securitySchema = z7.object({
261
+ // T6.1 — default flipped from 'warn' to 'strict' for 0.3.0. Apps that
262
+ // grep their warn-mode logs from 0.2.x already know which endpoints
263
+ // break; opt back into 'warn' globally OR use disallowedRoutes for
264
+ // surgical migration.
265
+ csrf: z7.enum(["off", "warn", "strict"]).default("strict"),
266
+ headers: securityHeadersSchema.optional(),
267
+ /** T5.1 — per-route escalation (Rails disallowed_warnings pattern). */
268
+ disallowed: disallowedConfigSchema.optional(),
269
+ /** T1.2 — Cross-Origin Resource Sharing. Single global config; runs first in pipeline. */
270
+ cors: corsSchema.optional()
271
+ });
272
+
273
+ // src/config/schemas/storage.ts
274
+ import { z as z8 } from "zod";
275
+ var tlsConfigSchema = z8.object({
276
+ rejectUnauthorized: z8.boolean().optional(),
277
+ caCert: z8.string().optional(),
278
+ clientCert: z8.string().optional(),
279
+ clientKey: z8.string().optional()
280
+ });
281
+ var serverConfigSchema = z8.object({
282
+ host: z8.string().min(1),
283
+ port: z8.number().int().positive().max(65535).optional(),
284
+ user: z8.string().min(1),
285
+ /** Password may be the empty string (some providers permit it). */
286
+ password: z8.string(),
287
+ tls: tlsConfigSchema.optional()
288
+ });
289
+ var postgresPoolConfigSchema = z8.object({
290
+ min: z8.number().int().nonnegative().optional(),
291
+ max: z8.number().int().positive().optional(),
292
+ connectionTimeoutMillis: z8.number().int().positive().optional(),
293
+ idleTimeoutMillis: z8.number().int().nonnegative().optional()
294
+ });
295
+ var postgresDatabaseConfigSchema = z8.object({
296
+ /** References a key in `storage.servers`. Resolved at `usePostgres()` call time. */
297
+ server: z8.string().min(1),
298
+ database: z8.string().min(1),
299
+ pool: postgresPoolConfigSchema.optional()
300
+ });
301
+ var redisServerConfigSchema = serverConfigSchema.extend({
302
+ db: z8.number().int().nonnegative().optional(),
303
+ maxRetriesPerRequest: z8.number().int().nonnegative().optional()
304
+ });
305
+ var storageSchema = z8.object({
306
+ servers: z8.record(z8.string(), serverConfigSchema).optional(),
307
+ databases: z8.record(z8.string(), postgresDatabaseConfigSchema).optional(),
308
+ redis: z8.record(z8.string(), redisServerConfigSchema).optional()
309
+ });
310
+
311
+ // src/server/observability-bootstrap.ts
312
+ var activeAdapter;
313
+ function getObservabilityAdapter() {
314
+ return activeAdapter;
315
+ }
316
+ function createObservabilityPluginFromConfig(observabilityConfig, env) {
317
+ const parsed = observabilityConfig === void 0 || observabilityConfig === null ? void 0 : observabilitySchema.parse(observabilityConfig);
318
+ if (parsed?.enabled === false) return void 0;
319
+ const cloudConfigured = Boolean(env.THEO_CLOUD_INGEST_URL) && Boolean(env.THEO_CLOUD_API_KEY);
320
+ if (parsed === void 0 && !cloudConfigured) return void 0;
321
+ const adapter = resolveAdapter({
322
+ env,
323
+ config: { provider: parsed?.provider }
324
+ });
325
+ if (adapter.name === "noop") {
326
+ if (parsed !== void 0) {
327
+ warnOnce("observability.no_exporter", {
328
+ event: "observability.no_exporter",
329
+ message: "observability is configured but no exporter resolved, so no spans will be recorded. Set THEO_CLOUD_INGEST_URL and THEO_CLOUD_API_KEY, or pass observability.provider with your own adapter. In development, NODE_ENV=development resolves the console exporter."
330
+ });
331
+ }
332
+ return void 0;
333
+ }
334
+ activeAdapter = adapter;
335
+ return createObservabilityPlugin(adapter);
336
+ }
337
+
338
+ // src/server/agent/hitl-pause-spans.ts
339
+ var pauseSpans = /* @__PURE__ */ new Map();
340
+ function registerPauseSpan(approvalId, span) {
341
+ pauseSpans.set(approvalId, span);
342
+ }
343
+ function closePauseSpan(approvalId, { resumeObserved }) {
344
+ const span = pauseSpans.get(approvalId);
345
+ if (span === void 0) return;
346
+ pauseSpans.delete(approvalId);
347
+ span.setAttribute("hitl.resume_observed", resumeObserved);
348
+ if (resumeObserved) span.setStatus("ok");
349
+ else
350
+ span.setStatus("error", "HITL pause never observed to resume; duration is not the human wait");
351
+ span.end();
352
+ }
353
+
354
+ // src/server/agent/observe-agent-run.ts
355
+ var TOKEN_FIELDS = [
356
+ ["inputTokens", "tokens.input"],
357
+ ["outputTokens", "tokens.output"],
358
+ ["totalTokens", "tokens.total"],
359
+ ["reasoningTokens", "tokens.reasoning"],
360
+ ["cacheReadTokens", "tokens.cache_read"],
361
+ ["cacheWriteTokens", "tokens.cache_write"]
362
+ ];
363
+ var STOP_REASONS = /* @__PURE__ */ new Set(["step_limit", "no_progress"]);
364
+ var GEN_AI_REQUEST_MODEL = "gen_ai.request.model";
365
+ function recordModel(span, metadata) {
366
+ if (metadata === null || typeof metadata !== "object") return;
367
+ const model = metadata.model;
368
+ if (typeof model === "string" && model.length > 0) span.setAttribute(GEN_AI_REQUEST_MODEL, model);
369
+ }
370
+ function recordStopReason(span, metadata) {
371
+ if (metadata === null || typeof metadata !== "object") return;
372
+ const reason = metadata.stopReason;
373
+ if (typeof reason === "string" && STOP_REASONS.has(reason)) {
374
+ span.setAttribute("stop.reason", reason);
375
+ }
376
+ }
377
+ function recordTokenUsage(span, metadata) {
378
+ if (metadata === null || typeof metadata !== "object") return;
379
+ const bag = metadata;
380
+ if (typeof bag.cost === "number") span.setAttribute("cost.usd", bag.cost);
381
+ const usage = bag.usage;
382
+ if (usage === null || usage === void 0 || typeof usage !== "object") return;
383
+ const fields = usage;
384
+ for (const [field, attribute] of TOKEN_FIELDS) {
385
+ const value = fields[field];
386
+ if (typeof value === "number") span.setAttribute(attribute, value);
387
+ }
388
+ }
389
+ function childOf(state) {
390
+ return { traceId: state.traceId, parentSpanId: state.runSpanId };
391
+ }
392
+ function openToolSpan(state, adapter, chunk) {
393
+ const id = chunk.toolCallId;
394
+ if (id === void 0) return;
395
+ const tool = chunk.toolName ?? "unknown";
396
+ state.toolNames.set(id, tool);
397
+ state.tools.set(
398
+ id,
399
+ adapter.startSpan("agent.tool", { agent: state.agent, tool, toolCallId: id }, childOf(state))
400
+ );
401
+ }
402
+ function openPauseSpan(state, adapter, chunk) {
403
+ const id = chunk.toolCallId;
404
+ const approvalId = chunk.approvalId;
405
+ if (id === void 0 || approvalId === void 0) return;
406
+ const pauseSpan = adapter.startSpan(
407
+ "agent.hitl",
408
+ {
409
+ agent: state.agent,
410
+ tool: state.toolNames.get(id) ?? "unknown",
411
+ approvalId,
412
+ toolCallId: id
413
+ },
414
+ childOf(state)
415
+ );
416
+ state.pauses.set(id, approvalId);
417
+ registerPauseSpan(approvalId, pauseSpan);
418
+ }
419
+ function closeToolSpan(state, chunk) {
420
+ const id = chunk.toolCallId;
421
+ if (id === void 0) return;
422
+ const pausedApprovalId = state.pauses.get(id);
423
+ if (pausedApprovalId !== void 0) {
424
+ closePauseSpan(pausedApprovalId, { resumeObserved: true });
425
+ state.pauses.delete(id);
426
+ }
427
+ const span = state.tools.get(id);
428
+ if (span === void 0) return;
429
+ if (chunk.type === "tool-output-error") span.setStatus("error", chunk.errorText);
430
+ else span.setStatus("ok");
431
+ span.end();
432
+ state.tools.delete(id);
433
+ }
434
+ async function* observeAgentRun(chunks, adapter, context) {
435
+ const runAttributes = { agent: context.agent };
436
+ if (context.sessionId !== void 0) runAttributes.sessionId = context.sessionId;
437
+ const traceId = context.traceId ?? newTraceId();
438
+ const runSpanId = newSpanId();
439
+ const runContext = context.traceId !== void 0 && context.parentSpanId !== void 0 ? { traceId, spanId: runSpanId, parentSpanId: context.parentSpanId } : { traceId, spanId: runSpanId };
440
+ const state = {
441
+ run: adapter.startSpan("agent.run", runAttributes, runContext),
442
+ tools: /* @__PURE__ */ new Map(),
443
+ pauses: /* @__PURE__ */ new Map(),
444
+ toolNames: /* @__PURE__ */ new Map(),
445
+ agent: context.agent,
446
+ traceId,
447
+ runSpanId
448
+ };
449
+ let settled = false;
450
+ function closeAll(status, message) {
451
+ if (settled) return;
452
+ settled = true;
453
+ for (const approvalId of state.pauses.values()) {
454
+ closePauseSpan(approvalId, { resumeObserved: false });
455
+ }
456
+ for (const span of state.tools.values()) {
457
+ span.setStatus(status, message);
458
+ span.end();
459
+ }
460
+ state.pauses.clear();
461
+ state.tools.clear();
462
+ state.run.setStatus(status, message);
463
+ state.run.end();
464
+ }
465
+ try {
466
+ for await (const chunk of chunks) {
467
+ const observed = chunk;
468
+ if (observed.type === "tool-input-available") openToolSpan(state, adapter, observed);
469
+ else if (observed.type === "tool-approval-request") openPauseSpan(state, adapter, observed);
470
+ else if (observed.type === "tool-output-available" || observed.type === "tool-output-error")
471
+ closeToolSpan(state, observed);
472
+ else if (observed.type === "finish") {
473
+ recordTokenUsage(state.run, observed.messageMetadata);
474
+ recordStopReason(state.run, observed.messageMetadata);
475
+ recordModel(state.run, observed.messageMetadata);
476
+ }
477
+ yield chunk;
478
+ }
479
+ closeAll("ok");
480
+ } catch (error) {
481
+ closeAll("error", error instanceof Error ? error.message : "unknown error");
482
+ throw error;
483
+ } finally {
484
+ closeAll("error", "agent run stream abandoned by its consumer");
485
+ }
486
+ }
487
+
488
+ // src/server/agent/observe-served-run.ts
489
+ function observeServedRun(stream, options) {
490
+ const adapter = getObservabilityAdapter();
491
+ if (adapter === void 0) return stream;
492
+ const trace = requestTrace(options.request);
493
+ const context = { agent: options.agentName, traceId: trace.traceId };
494
+ if (options.sessionId !== void 0) context.sessionId = options.sessionId;
495
+ const parentSpanId = trace.outermostSpanId ?? trace.parentSpanId;
496
+ if (parentSpanId !== void 0) context.parentSpanId = parentSpanId;
497
+ return observeAgentRun(stream, adapter, context);
498
+ }
499
+
500
+ // src/server/agent/build-agent-streamer.ts
501
+ function buildAgentHitl(compiled, owner) {
502
+ const gated = compiled.hitl;
503
+ if (gated === void 0 || gated.size === 0) return void 0;
504
+ const registry = getApprovalRegistry();
505
+ return {
506
+ gated,
507
+ awaitApproval: (approvalId, opts, toolName) => registry.register(approvalId, {
508
+ ...owner !== void 0 ? { owner } : {},
509
+ timeoutMs: opts.timeout ?? 3e5,
510
+ onTimeout: opts.onTimeout ?? "abort",
511
+ toolName,
512
+ question: opts.question,
513
+ ...opts.payloadSchema !== void 0 ? { payloadSchema: opts.payloadSchema } : {}
514
+ })
515
+ };
516
+ }
517
+ function makeThreadStartRun(mod, apiKey, source, agentName, request) {
518
+ return (sessionId, message) => (async function* () {
519
+ const compiled = compileAgentModule(mod, source);
520
+ if (compiled.skillsResolver) {
521
+ const enabled = await resolveEnabledSkills(
522
+ compiled.skillsResolver,
523
+ compiled.runContext ?? {}
524
+ );
525
+ if (enabled !== void 0) compiled.skills = { enabled, autoInject: true };
526
+ }
527
+ const hitl = buildAgentHitl(compiled);
528
+ const resolvedApiKey = typeof apiKey === "function" ? apiKey(compiled.model) : apiKey;
529
+ const stream = streamAgentUIMessages(compiled, resolvedApiKey, { message, sessionId, hitl });
530
+ yield* observeServedRun(stream, { agentName, sessionId, request });
531
+ })();
532
+ }
533
+
534
+ // src/server/agent/durable-ui-message-stream-response.ts
535
+ var SSE_BASE_HEADERS = {
536
+ "content-type": "text/event-stream",
537
+ "cache-control": "no-cache",
538
+ "x-accel-buffering": "no",
539
+ "x-vercel-ai-ui-message-stream": "v1"
540
+ };
541
+ var RUN_ID_HEADER = "x-theokit-run-id";
542
+ var SSE_DONE_FRAME = "data: [DONE]\n\n";
543
+ function formatSseFrame(seq, data) {
544
+ return `id: ${seq}
545
+ data: ${data}
546
+
547
+ `;
548
+ }
549
+ function encodeSse(text) {
550
+ return new TextEncoder().encode(text);
551
+ }
552
+ function durableUiMessageStreamResponse(chunks, deps) {
553
+ const { runId, cache } = deps;
554
+ const stream = new ReadableStream({
555
+ async start(controller) {
556
+ try {
557
+ for await (const chunk of chunks) {
558
+ const data = JSON.stringify(chunk);
559
+ const seq = cache.append(runId, data);
560
+ controller.enqueue(encodeSse(formatSseFrame(seq, data)));
561
+ }
562
+ } catch {
563
+ } finally {
564
+ cache.end(runId);
565
+ controller.enqueue(encodeSse(SSE_DONE_FRAME));
566
+ controller.close();
567
+ }
568
+ }
569
+ });
570
+ return new Response(stream, {
571
+ headers: { ...SSE_BASE_HEADERS, [RUN_ID_HEADER]: runId }
572
+ });
573
+ }
574
+
575
+ // src/server/agent/run-event-cache.ts
576
+ var DEFAULT_EVICT_AFTER_MS = 5 * 6e4;
577
+ var NOOP_UNSUBSCRIBE = () => {
578
+ };
579
+ function createInMemoryRunEventCache(opts = {}) {
580
+ const evictAfterMs = opts.evictAfterMs ?? DEFAULT_EVICT_AFTER_MS;
581
+ const runs = /* @__PURE__ */ new Map();
582
+ function getOrCreate(runId) {
583
+ let buf = runs.get(runId);
584
+ if (buf === void 0) {
585
+ buf = { frames: [], ended: false, listeners: /* @__PURE__ */ new Set() };
586
+ runs.set(runId, buf);
587
+ }
588
+ return buf;
589
+ }
590
+ return {
591
+ begin(runId) {
592
+ getOrCreate(runId);
593
+ },
594
+ append(runId, data) {
595
+ const buf = getOrCreate(runId);
596
+ const seq = buf.frames.length;
597
+ const frame = { seq, data };
598
+ buf.frames.push(frame);
599
+ for (const l of buf.listeners) {
600
+ try {
601
+ l.onFrame(frame);
602
+ } catch {
603
+ }
604
+ }
605
+ return seq;
606
+ },
607
+ has(runId) {
608
+ return runs.has(runId);
609
+ },
610
+ end(runId) {
611
+ const buf = runs.get(runId);
612
+ if (buf === void 0 || buf.ended) return;
613
+ buf.ended = true;
614
+ for (const l of buf.listeners) {
615
+ try {
616
+ l.onEnd();
617
+ } catch {
618
+ }
619
+ }
620
+ buf.listeners.clear();
621
+ buf.evictTimer = setTimeout(() => runs.delete(runId), evictAfterMs);
622
+ buf.evictTimer.unref();
623
+ },
624
+ attach(runId, afterSeq, onFrame, onEnd) {
625
+ const buf = runs.get(runId);
626
+ if (buf === void 0) {
627
+ return { known: false, replay: [], ended: false, unsubscribe: NOOP_UNSUBSCRIBE };
628
+ }
629
+ const replay = buf.frames.filter((f) => f.seq > afterSeq);
630
+ if (buf.ended) {
631
+ return { known: true, replay, ended: true, unsubscribe: NOOP_UNSUBSCRIBE };
632
+ }
633
+ const listener = { onFrame, onEnd };
634
+ buf.listeners.add(listener);
635
+ return {
636
+ known: true,
637
+ replay,
638
+ ended: false,
639
+ unsubscribe: () => {
640
+ buf.listeners.delete(listener);
641
+ }
642
+ };
643
+ }
644
+ };
645
+ }
646
+ var serverCache;
647
+ function getRunEventCache() {
648
+ serverCache ??= createInMemoryRunEventCache();
649
+ return serverCache;
650
+ }
651
+ function mintRunId() {
652
+ return `run-${crypto.randomUUID()}`;
653
+ }
654
+
655
+ // src/server/agent/mount-agent.ts
656
+ function partText(part) {
657
+ if (typeof part !== "object" || part === null) return "";
658
+ const p = part;
659
+ return p.type === "text" && typeof p.text === "string" ? p.text : "";
660
+ }
661
+ function jsonError(status, code, message) {
662
+ return new Response(JSON.stringify({ error: { code, message } }), {
663
+ status,
664
+ headers: { "content-type": "application/json" }
665
+ });
666
+ }
667
+ function parseAgentRequestBody(body) {
668
+ if (typeof body !== "object" || body === null) return null;
669
+ const b = body;
670
+ if (Array.isArray(b.messages) && b.messages.length > 0) {
671
+ const last = b.messages[b.messages.length - 1];
672
+ const parts = Array.isArray(last.parts) ? last.parts : [];
673
+ const text = parts.map(partText).join("");
674
+ if (text.length === 0) return null;
675
+ const sessionId = typeof b.id === "string" && b.id.length > 0 ? b.id : crypto.randomUUID();
676
+ return { message: text, sessionId };
677
+ }
678
+ if (typeof b.message === "string" && b.message.length > 0) {
679
+ const sessionId = typeof b.sessionId === "string" && b.sessionId.length > 0 ? b.sessionId : crypto.randomUUID();
680
+ return { message: b.message, sessionId };
681
+ }
682
+ return null;
683
+ }
684
+ function memoizeSubject(resolveSubject) {
685
+ if (resolveSubject === void 0) return void 0;
686
+ let resolved;
687
+ return async () => {
688
+ resolved ??= { subject: await resolveSubject() };
689
+ return resolved.subject;
690
+ };
691
+ }
692
+ async function resolveApprovalOwner(declaredPolicy, resolveOnce) {
693
+ if (declaredPolicy === void 0 || declaredPolicy === "public") return void 0;
694
+ return (await resolveOnce?.() ?? void 0)?.id;
695
+ }
696
+ async function admitRequest(request, policy, resolveSubject, agentName) {
697
+ let body = null;
698
+ try {
699
+ body = await request.json();
700
+ } catch {
701
+ }
702
+ const input = parseAgentRequestBody(body);
703
+ if (input === null) {
704
+ return jsonError(400, "BAD_REQUEST", "Request must contain a non-empty message or messages[].");
705
+ }
706
+ const params = { agent: agentName, endpoint: "run", sessionId: input.sessionId };
707
+ const decision = await admitAgentRequest(policy, resolveSubject, params, input);
708
+ if (!decision.allowed) return agentAccessDenied(decision, params);
709
+ return input;
710
+ }
711
+ async function mountAgent(mod, request, apiKey, {
712
+ source = "agent module",
713
+ csrfMode = "strict",
714
+ projectRoot,
715
+ agentName,
716
+ policy,
717
+ resolveSubject
718
+ } = {}) {
719
+ if (csrfMode !== "off") {
720
+ const csrf = validateCsrfRequest(request);
721
+ if (!csrf.valid && csrfMode === "strict") {
722
+ return jsonError(403, "CSRF_FAILED", `CSRF check failed: ${csrf.reason}`);
723
+ }
724
+ }
725
+ const identity = agentName ?? source;
726
+ const declaredPolicy = policy ?? readAgentPolicy(mod, source);
727
+ const resolveOnce = memoizeSubject(resolveSubject);
728
+ const admitted = await admitRequest(request, declaredPolicy, resolveOnce, identity);
729
+ if (admitted instanceof Response) return admitted;
730
+ const input = admitted;
731
+ const compiled = compileAgentModule2(mod, source);
732
+ const resolvedApiKey = typeof apiKey === "function" ? apiKey(compiled.model) : apiKey;
733
+ if (compiled.skillsResolver) {
734
+ const enabled = await resolveEnabledSkills2(compiled.skillsResolver, compiled.runContext ?? {});
735
+ if (enabled !== void 0) compiled.skills = { enabled, autoInject: true };
736
+ }
737
+ const hitl = buildAgentHitl(compiled, await resolveApprovalOwner(declaredPolicy, resolveOnce));
738
+ const runId = mintRunId();
739
+ const stream = streamAgentUIMessages2(compiled, resolvedApiKey, {
740
+ ...input,
741
+ hitl,
742
+ signal: request.signal,
743
+ cwd: resolveDiscoveryCwd(compiled, projectRoot),
744
+ baseDir: resolveSessionBaseDir(projectRoot)
745
+ });
746
+ return durableUiMessageStreamResponse(
747
+ observeServedRun(stream, { agentName: identity, request }),
748
+ { runId, cache: getRunEventCache() }
749
+ );
750
+ }
751
+ function resolveDiscoveryCwd(compiled, projectRoot) {
752
+ const optedIn = (compiled.settingSources?.length ?? 0) > 0;
753
+ return projectRoot !== void 0 && optedIn ? projectRoot : void 0;
754
+ }
755
+ function trimTrailingSlashes(value) {
756
+ let end = value.length;
757
+ while (end > 0 && value[end - 1] === "/") end -= 1;
758
+ return value.slice(0, end);
759
+ }
760
+ function resolveSessionBaseDir(projectRoot) {
761
+ if (projectRoot === void 0) return void 0;
762
+ return `${trimTrailingSlashes(projectRoot)}/.data/agent-sessions`;
763
+ }
764
+
765
+ export {
766
+ rateLimitSchema,
767
+ uploadSchema,
768
+ loggingSchema,
769
+ cacheSchema,
770
+ observabilitySchema,
771
+ securitySchema,
772
+ storageSchema,
773
+ readAgentPolicy,
774
+ admitAgentRequest,
775
+ agentAccessDenied,
776
+ getApprovalRegistry,
777
+ createObservabilityPluginFromConfig,
778
+ closePauseSpan,
779
+ makeThreadStartRun,
780
+ SSE_BASE_HEADERS,
781
+ RUN_ID_HEADER,
782
+ SSE_DONE_FRAME,
783
+ formatSseFrame,
784
+ encodeSse,
785
+ getRunEventCache,
786
+ mintRunId,
787
+ parseAgentRequestBody,
788
+ mountAgent
789
+ };
790
+ //# sourceMappingURL=chunk-WOBSEO75.js.map