failproofai 1.0.7-beta.1 → 1.0.7

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 (429) hide show
  1. package/.next/standalone/.next/BUILD_ID +1 -1
  2. package/.next/standalone/.next/build-manifest.json +3 -3
  3. package/.next/standalone/.next/prerender-manifest.json +4 -4
  4. package/.next/standalone/.next/required-server-files.json +1 -1
  5. package/.next/standalone/.next/server/app/_global-error/page/server-reference-manifest.json +1 -1
  6. package/.next/standalone/.next/server/app/_global-error/page.js +4 -4
  7. package/.next/standalone/.next/server/app/_global-error/page.js.nft.json +1 -1
  8. package/.next/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  9. package/.next/standalone/.next/server/app/_global-error.html +1 -1
  10. package/.next/standalone/.next/server/app/_global-error.rsc +7 -7
  11. package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +6 -6
  12. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +7 -7
  13. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  14. package/.next/standalone/.next/server/app/_not-found/page/server-reference-manifest.json +1 -1
  15. package/.next/standalone/.next/server/app/_not-found/page.js +4 -4
  16. package/.next/standalone/.next/server/app/_not-found/page.js.nft.json +1 -1
  17. package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  18. package/.next/standalone/.next/server/app/_not-found.html +1 -1
  19. package/.next/standalone/.next/server/app/_not-found.rsc +15 -15
  20. package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +15 -15
  21. package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +14 -14
  22. package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  23. package/.next/standalone/.next/server/app/api/audit/invite/route.js.nft.json +1 -1
  24. package/.next/standalone/.next/server/app/api/audit/run/route.js +7 -8
  25. package/.next/standalone/.next/server/app/api/audit/run/route.js.nft.json +1 -1
  26. package/.next/standalone/.next/server/app/api/audit/status/route.js.nft.json +1 -1
  27. package/.next/standalone/.next/server/app/api/auth/login-request/route.js.nft.json +1 -1
  28. package/.next/standalone/.next/server/app/api/auth/login-verify/route.js.nft.json +1 -1
  29. package/.next/standalone/.next/server/app/api/auth/logout/route.js.nft.json +1 -1
  30. package/.next/standalone/.next/server/app/api/auth/status/route.js.nft.json +1 -1
  31. package/.next/standalone/.next/server/app/api/download/[project]/[session]/route.js.nft.json +1 -1
  32. package/.next/standalone/.next/server/app/audit/page/server-reference-manifest.json +2 -2
  33. package/.next/standalone/.next/server/app/audit/page.js +5 -7
  34. package/.next/standalone/.next/server/app/audit/page.js.nft.json +1 -1
  35. package/.next/standalone/.next/server/app/audit/page_client-reference-manifest.js +1 -1
  36. package/.next/standalone/.next/server/app/index.html +1 -1
  37. package/.next/standalone/.next/server/app/index.rsc +15 -15
  38. package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +14 -14
  39. package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +15 -15
  40. package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  41. package/.next/standalone/.next/server/app/page/server-reference-manifest.json +1 -1
  42. package/.next/standalone/.next/server/app/page.js +6 -6
  43. package/.next/standalone/.next/server/app/page.js.nft.json +1 -1
  44. package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  45. package/.next/standalone/.next/server/app/policies/page/server-reference-manifest.json +14 -14
  46. package/.next/standalone/.next/server/app/policies/page.js +11 -13
  47. package/.next/standalone/.next/server/app/policies/page.js.nft.json +1 -1
  48. package/.next/standalone/.next/server/app/policies/page_client-reference-manifest.js +1 -1
  49. package/.next/standalone/.next/server/app/project/[name]/page/server-reference-manifest.json +1 -1
  50. package/.next/standalone/.next/server/app/project/[name]/page.js +7 -8
  51. package/.next/standalone/.next/server/app/project/[name]/page.js.nft.json +1 -1
  52. package/.next/standalone/.next/server/app/project/[name]/page_client-reference-manifest.js +1 -1
  53. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/react-loadable-manifest.json +2 -2
  54. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/server-reference-manifest.json +2 -2
  55. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page.js +7 -7
  56. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page.js.nft.json +1 -1
  57. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page_client-reference-manifest.js +1 -1
  58. package/.next/standalone/.next/server/app/projects/page/server-reference-manifest.json +1 -1
  59. package/.next/standalone/.next/server/app/projects/page.js +6 -7
  60. package/.next/standalone/.next/server/app/projects/page.js.nft.json +1 -1
  61. package/.next/standalone/.next/server/app/projects/page_client-reference-manifest.js +1 -1
  62. package/.next/standalone/.next/server/app/settings/page/server-reference-manifest.json +8 -41
  63. package/.next/standalone/.next/server/app/settings/page.js +9 -12
  64. package/.next/standalone/.next/server/app/settings/page.js.nft.json +1 -1
  65. package/.next/standalone/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  66. package/.next/standalone/.next/server/chunks/{[externals]__1j-zsg5._.js → [externals]__1_bftcl._.js} +1 -1
  67. package/.next/standalone/.next/server/chunks/{[externals]__19_pzeq._.js → [externals]__1msfs-h._.js} +1 -1
  68. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0o07qi9._.js +1 -1
  69. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__1bf34x4._.js → [root-of-the-server]__1_r2rbg._.js} +7 -5
  70. package/.next/standalone/.next/server/chunks/_09dz7xv._.js +21 -21
  71. package/.next/standalone/.next/server/chunks/_0tovk6q._.js +1 -1
  72. package/.next/standalone/.next/server/chunks/_0trp3yc._.js +1 -1
  73. package/.next/standalone/.next/server/chunks/{_1q5i8mb._.js → _1c3k-8x._.js} +2 -2
  74. package/.next/standalone/.next/server/chunks/_1ek68ln._.js +16 -16
  75. package/.next/standalone/.next/server/chunks/node_modules_posthog-node_dist_entrypoints_index_node_mjs_09z9-p7._.js +1 -1
  76. package/.next/standalone/.next/server/chunks/package_json_[json]_cjs_1nxcc4v._.js +1 -1
  77. package/.next/standalone/.next/server/chunks/src_hooks_0iu54mz._.js +3 -0
  78. package/.next/standalone/.next/server/chunks/src_hooks_custom-hooks-loader_ts_0lnb3n3._.js +2 -4
  79. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0-_ki57._.js +4 -0
  80. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__013jr2b._.js +4 -0
  81. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__01wy8d-._.js +4 -0
  82. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__02npjtd._.js +4 -0
  83. package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0yxwl6j._.js → [root-of-the-server]__0bd3mje._.js} +2 -2
  84. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0cg-bgc._.js +5 -0
  85. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0cpu_mj._.js +3 -0
  86. package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__1mf3zp6._.js → [root-of-the-server]__0cxe_2_._.js} +3 -3
  87. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0da85px._.js +4 -0
  88. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0ftmoxc._.js +4 -0
  89. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0p-5p8u._.js +4 -0
  90. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0u3w0ll._.js +22 -0
  91. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__17d_ffl._.js +3 -0
  92. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__19d9tgz._.js +5 -0
  93. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1ctpynv._.js +3 -0
  94. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1jiwfsj._.js +3 -0
  95. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1p2otjt._.js +4 -0
  96. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1phc187._.js +3 -0
  97. package/.next/standalone/.next/server/chunks/ssr/_06imw3p._.js +5 -0
  98. package/.next/standalone/.next/server/chunks/ssr/_08x1r5t._.js +1 -1
  99. package/.next/standalone/.next/server/chunks/ssr/{_1w_5l7t._.js → _0h_douw._.js} +1 -1
  100. package/.next/standalone/.next/server/chunks/ssr/{_214wgrp._.js → _1-i_gzc._.js} +2 -2
  101. package/.next/standalone/.next/server/chunks/ssr/{_0bn2oo8._.js → _166t73i._.js} +1 -1
  102. package/.next/standalone/.next/server/chunks/ssr/{_1q46vxx._.js → _1_qswah._.js} +2 -2
  103. package/.next/standalone/.next/server/chunks/ssr/{_1gb0ifp._.js → _1es2j7i._.js} +5 -5
  104. package/.next/standalone/.next/server/chunks/ssr/_1u8-lu2._.js +3 -0
  105. package/.next/standalone/.next/server/chunks/ssr/_1zopuov._.js +1 -1
  106. package/.next/standalone/.next/server/chunks/ssr/_next-internal_server_app_policies_page_actions_1sp2-yo.js +2 -2
  107. package/.next/standalone/.next/server/chunks/ssr/app_audit__components_audit-dashboard_tsx_0p9ud47._.js +1 -1
  108. package/.next/standalone/.next/server/chunks/ssr/app_global-error_tsx_1kp6l3x._.js +1 -1
  109. package/.next/standalone/.next/server/chunks/ssr/app_policies_hooks-client_tsx_19dqvpc._.js +2 -2
  110. package/.next/standalone/.next/server/chunks/ssr/app_settings_settings-client_tsx_20lq-mq._.js +3 -0
  111. package/.next/standalone/.next/server/chunks/ssr/{node_modules_next_dist_18_d8l1._.js → node_modules_next_dist_0drixxt._.js} +4 -4
  112. package/.next/standalone/.next/server/chunks/ssr/src_hooks_1cv9_c4._.js +10 -0
  113. package/.next/standalone/.next/server/chunks/ssr/src_hooks_builtin-policies_ts_09j2ndl._.js +1 -1
  114. package/.next/standalone/.next/server/chunks/ssr/src_hooks_fp-home_ts_0je3xkv._.js +1 -1
  115. package/.next/standalone/.next/server/chunks/ssr/src_hooks_pack-cli_ts_0t7me65._.js +1 -1
  116. package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
  117. package/.next/standalone/.next/server/pages/404.html +1 -1
  118. package/.next/standalone/.next/server/pages/500.html +1 -1
  119. package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
  120. package/.next/standalone/.next/server/server-reference-manifest.json +23 -56
  121. package/.next/standalone/.next/static/chunks/094xgi4owxaqf.js +1 -0
  122. package/.next/standalone/.next/static/chunks/0__8a7m868fvf.js +1 -0
  123. package/.next/standalone/.next/static/chunks/{12tvm75t5ffui.js → 0o6qlkgubtoex.js} +1 -1
  124. package/.next/standalone/.next/static/chunks/13i7-9is-vhys.js +1 -0
  125. package/.next/standalone/.next/static/chunks/1rz20_pz828f3.js +6 -0
  126. package/.next/standalone/.next/static/chunks/2k9f4tyv04809.css +1 -0
  127. package/.next/standalone/.next/static/chunks/{0vmd180qfntfb.js → 2klitrtzpaoe0.js} +1 -1
  128. package/.next/standalone/.next/static/chunks/{258668t68du6b.js → 2mdh397ghgnvv.js} +1 -1
  129. package/.next/standalone/.next/static/chunks/2rshywgeqsyzk.css +2 -0
  130. package/.next/standalone/.next/static/chunks/3pzx4chkhko9k.js +1 -0
  131. package/.next/standalone/.next/static/chunks/{0qrbdkv9qmvli.js → 3rh5o7e16irrm.js} +1 -1
  132. package/.next/standalone/.next/static/chunks/{29fql3nbnfc9q.js → 43ufqrz8qo3h-.js} +1 -1
  133. package/.next/standalone/SECURITY.md +53 -0
  134. package/.next/standalone/app/actions/pack-actions.ts +0 -12
  135. package/.next/standalone/app/policies/hooks-client.tsx +0 -9
  136. package/.next/standalone/app/settings/page.tsx +1 -20
  137. package/.next/standalone/app/settings/settings-client.tsx +1 -27
  138. package/.next/standalone/app/settings/settings.css +0 -79
  139. package/.next/standalone/package.json +9 -9
  140. package/.next/standalone/sdk/python/skill/SKILL.md +60 -14
  141. package/.next/standalone/sdk/python/skill/agents/openai.yaml +2 -1
  142. package/.next/standalone/sdk/python/skill/references/evaluator.md +255 -0
  143. package/.next/standalone/sdk/python/skill/references/events.md +17 -8
  144. package/.next/standalone/sdk/python/skill/references/frameworks.md +3 -0
  145. package/.next/standalone/sdk/python/skill/references/install.md +3 -0
  146. package/.next/standalone/sdk/python/skill/references/integration.md +6 -2
  147. package/.next/standalone/sdk/python/skill/references/typescript.md +568 -0
  148. package/.next/standalone/sdk/typescript/CHANGELOG.md +133 -0
  149. package/.next/standalone/sdk/typescript/LICENSE +42 -0
  150. package/.next/standalone/sdk/typescript/README.md +552 -0
  151. package/.next/standalone/sdk/typescript/eslint.config.mjs +59 -0
  152. package/.next/standalone/sdk/typescript/examples/research-agent.ts +197 -0
  153. package/.next/standalone/sdk/typescript/integration/ai.test.ts +920 -0
  154. package/.next/standalone/sdk/typescript/integration/fixtures/ai-4/agent.ts +337 -0
  155. package/.next/standalone/sdk/typescript/integration/fixtures/ai-4/package-lock.json +261 -0
  156. package/.next/standalone/sdk/typescript/integration/fixtures/ai-4/package.json +16 -0
  157. package/.next/standalone/sdk/typescript/integration/fixtures/ai-4/surfaces.ts +605 -0
  158. package/.next/standalone/sdk/typescript/integration/fixtures/ai-4/tsconfig.json +12 -0
  159. package/.next/standalone/sdk/typescript/integration/fixtures/ai-4/tsconfig.surfaces.json +4 -0
  160. package/.next/standalone/sdk/typescript/integration/fixtures/ai-5/agent.ts +342 -0
  161. package/.next/standalone/sdk/typescript/integration/fixtures/ai-5/package-lock.json +156 -0
  162. package/.next/standalone/sdk/typescript/integration/fixtures/ai-5/package.json +16 -0
  163. package/.next/standalone/sdk/typescript/integration/fixtures/ai-5/surfaces.ts +628 -0
  164. package/.next/standalone/sdk/typescript/integration/fixtures/ai-5/tsconfig.json +12 -0
  165. package/.next/standalone/sdk/typescript/integration/fixtures/ai-5/tsconfig.surfaces.json +4 -0
  166. package/.next/standalone/sdk/typescript/integration/fixtures/ai-6/agent.ts +346 -0
  167. package/.next/standalone/sdk/typescript/integration/fixtures/ai-6/package-lock.json +156 -0
  168. package/.next/standalone/sdk/typescript/integration/fixtures/ai-6/package.json +13 -0
  169. package/.next/standalone/sdk/typescript/integration/fixtures/ai-6/surfaces.ts +651 -0
  170. package/.next/standalone/sdk/typescript/integration/fixtures/ai-6/tsconfig.json +12 -0
  171. package/.next/standalone/sdk/typescript/integration/fixtures/ai-6/tsconfig.surfaces.json +4 -0
  172. package/.next/standalone/sdk/typescript/integration/fixtures/ai-7/agent.ts +350 -0
  173. package/.next/standalone/sdk/typescript/integration/fixtures/ai-7/package-lock.json +153 -0
  174. package/.next/standalone/sdk/typescript/integration/fixtures/ai-7/package.json +13 -0
  175. package/.next/standalone/sdk/typescript/integration/fixtures/ai-7/surfaces.ts +651 -0
  176. package/.next/standalone/sdk/typescript/integration/fixtures/ai-7/tsconfig.json +12 -0
  177. package/.next/standalone/sdk/typescript/integration/fixtures/ai-7/tsconfig.surfaces.json +4 -0
  178. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-0.3/agent.ts +623 -0
  179. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-0.3/package-lock.json +344 -0
  180. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-0.3/package.json +19 -0
  181. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-0.3/tsconfig.json +12 -0
  182. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-1/agent-v1.ts +99 -0
  183. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-1/agent.ts +623 -0
  184. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-1/package-lock.json +336 -0
  185. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-1/package.json +15 -0
  186. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-1/tsconfig.json +12 -0
  187. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/agent.ts +96 -0
  188. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/package-lock.json +441 -0
  189. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/package.json +19 -0
  190. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/tsconfig.json +12 -0
  191. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/vendor/lc-weather-provider/index.cjs +53 -0
  192. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/vendor/lc-weather-provider/index.mjs +55 -0
  193. package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/vendor/lc-weather-provider/package.json +18 -0
  194. package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.11/agent.ts +659 -0
  195. package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.11/package-lock.json +635 -0
  196. package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.11/package.json +15 -0
  197. package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.11/tsconfig.json +12 -0
  198. package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.12/agent.ts +659 -0
  199. package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.12/package-lock.json +553 -0
  200. package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.12/package.json +15 -0
  201. package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.12/tsconfig.json +12 -0
  202. package/.next/standalone/sdk/typescript/integration/fixtures/mastra-0/agent.ts +877 -0
  203. package/.next/standalone/sdk/typescript/integration/fixtures/mastra-0/mcp-server.mjs +66 -0
  204. package/.next/standalone/sdk/typescript/integration/fixtures/mastra-0/package-lock.json +6797 -0
  205. package/.next/standalone/sdk/typescript/integration/fixtures/mastra-0/package.json +24 -0
  206. package/.next/standalone/sdk/typescript/integration/fixtures/mastra-0/tsconfig.json +12 -0
  207. package/.next/standalone/sdk/typescript/integration/fixtures/mastra-1/agent.ts +872 -0
  208. package/.next/standalone/sdk/typescript/integration/fixtures/mastra-1/mcp-server.mjs +66 -0
  209. package/.next/standalone/sdk/typescript/integration/fixtures/mastra-1/package-lock.json +2540 -0
  210. package/.next/standalone/sdk/typescript/integration/fixtures/mastra-1/package.json +15 -0
  211. package/.next/standalone/sdk/typescript/integration/fixtures/mastra-1/tsconfig.json +12 -0
  212. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/actions.ts +18 -0
  213. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/api/ai/route.ts +42 -0
  214. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/api/edge/route.ts +29 -0
  215. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/api/langgraph/route.ts +21 -0
  216. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/api/llamaindex/route.ts +11 -0
  217. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/api/mastra/route.ts +19 -0
  218. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/api/status/route.ts +7 -0
  219. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/layout.tsx +9 -0
  220. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/page.tsx +15 -0
  221. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/instrumentation.ts +15 -0
  222. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/lib/ai.ts +61 -0
  223. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/lib/langgraph.ts +68 -0
  224. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/lib/llamaindex.ts +98 -0
  225. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/lib/mastra.ts +90 -0
  226. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/next.config.ts +52 -0
  227. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/package-lock.json +4343 -0
  228. package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/package.json +28 -0
  229. package/.next/standalone/sdk/typescript/integration/fixtures/runtimes/agent.ts +51 -0
  230. package/.next/standalone/sdk/typescript/integration/fixtures/runtimes/deno-npm.ts +76 -0
  231. package/.next/standalone/sdk/typescript/integration/fixtures/runtimes/package-lock.json +484 -0
  232. package/.next/standalone/sdk/typescript/integration/fixtures/runtimes/package.json +15 -0
  233. package/.next/standalone/sdk/typescript/integration/fixtures/types/agent.ts +79 -0
  234. package/.next/standalone/sdk/typescript/integration/fixtures/types/package-lock.json +740 -0
  235. package/.next/standalone/sdk/typescript/integration/fixtures/types/package.json +11 -0
  236. package/.next/standalone/sdk/typescript/integration/fixtures/vanilla/agent.ts +197 -0
  237. package/.next/standalone/sdk/typescript/integration/fixtures/vanilla/package-lock.json +70 -0
  238. package/.next/standalone/sdk/typescript/integration/fixtures/vanilla/package.json +12 -0
  239. package/.next/standalone/sdk/typescript/integration/fixtures/vanilla/tsconfig.json +12 -0
  240. package/.next/standalone/sdk/typescript/integration/global-setup.ts +29 -0
  241. package/.next/standalone/sdk/typescript/integration/harness.ts +451 -0
  242. package/.next/standalone/sdk/typescript/integration/langchain.test.ts +682 -0
  243. package/.next/standalone/sdk/typescript/integration/llamaindex.test.ts +709 -0
  244. package/.next/standalone/sdk/typescript/integration/mastra-coverage.test.ts +386 -0
  245. package/.next/standalone/sdk/typescript/integration/mastra.test.ts +311 -0
  246. package/.next/standalone/sdk/typescript/integration/nextjs.test.ts +341 -0
  247. package/.next/standalone/sdk/typescript/integration/runtime-parity.ts +180 -0
  248. package/.next/standalone/sdk/typescript/integration/runtimes.bun.test.ts +15 -0
  249. package/.next/standalone/sdk/typescript/integration/runtimes.core.test.ts +113 -0
  250. package/.next/standalone/sdk/typescript/integration/runtimes.deno.test.ts +19 -0
  251. package/.next/standalone/sdk/typescript/integration/types.test.ts +141 -0
  252. package/.next/standalone/sdk/typescript/integration/vanilla.test.ts +255 -0
  253. package/.next/standalone/sdk/typescript/package-lock.json +2640 -0
  254. package/.next/standalone/sdk/typescript/package.json +401 -0
  255. package/.next/standalone/sdk/typescript/scripts/finalize-build.mjs +123 -0
  256. package/.next/standalone/sdk/typescript/scripts/release.mjs +177 -0
  257. package/.next/standalone/sdk/typescript/src/clock.ts +58 -0
  258. package/.next/standalone/sdk/typescript/src/context.ts +214 -0
  259. package/.next/standalone/sdk/typescript/src/edge/adapter.ts +18 -0
  260. package/.next/standalone/sdk/typescript/src/edge/ai.ts +116 -0
  261. package/.next/standalone/sdk/typescript/src/edge/index.ts +238 -0
  262. package/.next/standalone/sdk/typescript/src/edge/langchain.ts +18 -0
  263. package/.next/standalone/sdk/typescript/src/edge/llamaindex.ts +12 -0
  264. package/.next/standalone/sdk/typescript/src/edge/mastra.ts +17 -0
  265. package/.next/standalone/sdk/typescript/src/edge/notice.ts +33 -0
  266. package/.next/standalone/sdk/typescript/src/environment.ts +75 -0
  267. package/.next/standalone/sdk/typescript/src/evaluator/authoring.ts +480 -0
  268. package/.next/standalone/sdk/typescript/src/evaluator/cli.ts +96 -0
  269. package/.next/standalone/sdk/typescript/src/evaluator/client.ts +421 -0
  270. package/.next/standalone/sdk/typescript/src/evaluator/expression.ts +1292 -0
  271. package/.next/standalone/sdk/typescript/src/evaluator/index.ts +144 -0
  272. package/.next/standalone/sdk/typescript/src/evaluator/protocol.ts +747 -0
  273. package/.next/standalone/sdk/typescript/src/evaluator/runtime.ts +930 -0
  274. package/.next/standalone/sdk/typescript/src/evaluator/sandbox-worker.ts +171 -0
  275. package/.next/standalone/sdk/typescript/src/evaluator/source-limits.ts +27 -0
  276. package/.next/standalone/sdk/typescript/src/evaluator/source.ts +509 -0
  277. package/.next/standalone/sdk/typescript/src/events.ts +879 -0
  278. package/.next/standalone/sdk/typescript/src/exit.ts +117 -0
  279. package/.next/standalone/sdk/typescript/src/index.ts +186 -0
  280. package/.next/standalone/sdk/typescript/src/integrations/ai.ts +1566 -0
  281. package/.next/standalone/sdk/typescript/src/integrations/compat.ts +322 -0
  282. package/.next/standalone/sdk/typescript/src/integrations/core.ts +1321 -0
  283. package/.next/standalone/sdk/typescript/src/integrations/index.ts +355 -0
  284. package/.next/standalone/sdk/typescript/src/integrations/langchain.ts +2340 -0
  285. package/.next/standalone/sdk/typescript/src/integrations/llamaindex.ts +2111 -0
  286. package/.next/standalone/sdk/typescript/src/integrations/mastra.ts +1802 -0
  287. package/.next/standalone/sdk/typescript/src/logger.ts +98 -0
  288. package/.next/standalone/sdk/typescript/src/next.ts +115 -0
  289. package/.next/standalone/sdk/typescript/src/node-require.ts +446 -0
  290. package/.next/standalone/sdk/typescript/src/redact.ts +305 -0
  291. package/.next/standalone/sdk/typescript/src/resolver.ts +120 -0
  292. package/.next/standalone/sdk/typescript/src/runtime.ts +29 -0
  293. package/.next/standalone/sdk/typescript/src/schema.ts +410 -0
  294. package/.next/standalone/sdk/typescript/src/scopes.ts +701 -0
  295. package/.next/standalone/sdk/typescript/src/shared.ts +33 -0
  296. package/.next/standalone/sdk/typescript/src/version.ts +5 -0
  297. package/.next/standalone/sdk/typescript/src/writer.ts +934 -0
  298. package/.next/standalone/sdk/typescript/test/adapters.test.ts +397 -0
  299. package/.next/standalone/sdk/typescript/test/ai.test.ts +1076 -0
  300. package/.next/standalone/sdk/typescript/test/copies.test.ts +204 -0
  301. package/.next/standalone/sdk/typescript/test/edge.test.ts +183 -0
  302. package/.next/standalone/sdk/typescript/test/evaluator-client.test.ts +234 -0
  303. package/.next/standalone/sdk/typescript/test/evaluator-protocol.test.ts +225 -0
  304. package/.next/standalone/sdk/typescript/test/events.test.ts +193 -0
  305. package/.next/standalone/sdk/typescript/test/expression.test.ts +181 -0
  306. package/.next/standalone/sdk/typescript/test/global-setup.ts +26 -0
  307. package/.next/standalone/sdk/typescript/test/helpers.ts +130 -0
  308. package/.next/standalone/sdk/typescript/test/integrations.test.ts +369 -0
  309. package/.next/standalone/sdk/typescript/test/langchain-copies.test.ts +204 -0
  310. package/.next/standalone/sdk/typescript/test/langchain.test.ts +999 -0
  311. package/.next/standalone/sdk/typescript/test/llamaindex.test.ts +1760 -0
  312. package/.next/standalone/sdk/typescript/test/mastra-coverage.test.ts +501 -0
  313. package/.next/standalone/sdk/typescript/test/mastra-lifecycle.test.ts +479 -0
  314. package/.next/standalone/sdk/typescript/test/mastra.test.ts +285 -0
  315. package/.next/standalone/sdk/typescript/test/next.test.ts +109 -0
  316. package/.next/standalone/sdk/typescript/test/packaging.test.ts +312 -0
  317. package/.next/standalone/sdk/typescript/test/redaction.test.ts +171 -0
  318. package/.next/standalone/sdk/typescript/test/runtimes.test.ts +101 -0
  319. package/.next/standalone/sdk/typescript/test/sandbox.test.ts +189 -0
  320. package/.next/standalone/sdk/typescript/test/scopes.test.ts +271 -0
  321. package/.next/standalone/sdk/typescript/test/setup.ts +19 -0
  322. package/.next/standalone/sdk/typescript/test/skill-snippets.test.ts +73 -0
  323. package/.next/standalone/sdk/typescript/test/spool-contract.test.ts +124 -0
  324. package/.next/standalone/sdk/typescript/test/tracker-bounds.test.ts +191 -0
  325. package/.next/standalone/sdk/typescript/test/wire-format.test.ts +214 -0
  326. package/.next/standalone/sdk/typescript/test/writer.test.ts +407 -0
  327. package/.next/standalone/sdk/typescript/tsconfig.build.json +15 -0
  328. package/.next/standalone/sdk/typescript/tsconfig.cjs.json +19 -0
  329. package/.next/standalone/sdk/typescript/tsconfig.json +28 -0
  330. package/.next/standalone/sdk/typescript/vitest.config.ts +33 -0
  331. package/.next/standalone/sdk/typescript/vitest.integration.config.ts +23 -0
  332. package/.next/standalone/server.js +1 -1
  333. package/bin/failproofai.mjs +2 -115
  334. package/dist/cli.mjs +6538 -13686
  335. package/dist/index.js +1 -19
  336. package/dist/worker.mjs +2085 -8012
  337. package/package.json +9 -9
  338. package/pi-extension/index.ts +0 -11
  339. package/scripts/build-policy-pack.mjs +2 -39
  340. package/src/hooks/builtin-policies.ts +3 -21
  341. package/src/hooks/cloud-enrollment-cli.ts +1 -1
  342. package/src/hooks/cloud-managed-policies.ts +0 -22
  343. package/src/hooks/custom-hooks-loader.ts +7 -45
  344. package/src/hooks/custom-hooks-registry.ts +1 -45
  345. package/src/hooks/first-run-gate.ts +0 -5
  346. package/src/hooks/fp-home.ts +0 -23
  347. package/src/hooks/handler.ts +6 -265
  348. package/src/hooks/hook-activity-store.ts +1 -105
  349. package/src/hooks/hook-telemetry.ts +0 -41
  350. package/src/hooks/loader-utils.ts +0 -6
  351. package/src/hooks/pack-cli.ts +17 -278
  352. package/src/hooks/pack-manifest.ts +7 -479
  353. package/src/hooks/pack-store.ts +10 -156
  354. package/src/hooks/policy-catalog.ts +0 -65
  355. package/src/hooks/policy-evaluator.ts +796 -940
  356. package/src/hooks/policy-registry.ts +0 -25
  357. package/src/hooks/policy-types.ts +0 -126
  358. package/src/hooks/worker-server.ts +26 -119
  359. package/src/index.ts +0 -6
  360. package/.next/standalone/.next/server/chunks/src_hooks_01frwmb._.js +0 -5
  361. package/.next/standalone/.next/server/chunks/src_hooks_18qtd42._.js +0 -3
  362. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__01bmjsj._.js +0 -3
  363. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__04usis8._.js +0 -4
  364. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__056wjo4._.js +0 -4
  365. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__059yza8._.js +0 -3
  366. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0eip4_k._.js +0 -22
  367. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0n0xg95._.js +0 -4
  368. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0qcb0mg._.js +0 -3
  369. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0qxnccm._.js +0 -5
  370. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0rwtwpm._.js +0 -4
  371. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0s_yomn._.js +0 -4
  372. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0soxz2z._.js +0 -3
  373. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0yrsbd_._.js +0 -3
  374. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__11mayhe._.js +0 -4
  375. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__13d-wb6._.js +0 -3
  376. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1dinjii._.js +0 -3
  377. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1pprgri._.js +0 -4
  378. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1q4p5b8._.js +0 -4
  379. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1qiz0e4._.js +0 -3
  380. package/.next/standalone/.next/server/chunks/ssr/_042cgl1._.js +0 -3
  381. package/.next/standalone/.next/server/chunks/ssr/_0bqoto4._.js +0 -3
  382. package/.next/standalone/.next/server/chunks/ssr/_0uyu3jf._.js +0 -3
  383. package/.next/standalone/.next/server/chunks/ssr/_1feuvhb._.js +0 -5
  384. package/.next/standalone/.next/server/chunks/ssr/app_actions_get-scheduled-audit_ts_0ei9sni._.js +0 -3
  385. package/.next/standalone/.next/server/chunks/ssr/app_settings_02tf1h4._.js +0 -3
  386. package/.next/standalone/.next/server/chunks/ssr/node_modules_next_dist_0w6mzq5._.js +0 -151
  387. package/.next/standalone/.next/server/chunks/ssr/src_hooks_095a_79._.js +0 -5
  388. package/.next/standalone/.next/server/chunks/ssr/src_hooks_15t8kqj._.js +0 -3
  389. package/.next/standalone/.next/server/chunks/ssr/src_hooks_18k8rl0._.js +0 -12
  390. package/.next/standalone/.next/server/chunks/ssr/src_hooks_1fm2w5z._.js +0 -3
  391. package/.next/standalone/.next/server/chunks/ssr/src_hooks_1j0zy3v._.js +0 -3
  392. package/.next/standalone/.next/static/chunks/0cd-_8-c-m1ea.js +0 -6
  393. package/.next/standalone/.next/static/chunks/0uldbut9y2-e8.js +0 -1
  394. package/.next/standalone/.next/static/chunks/1u5zsejmgrir_.js +0 -1
  395. package/.next/standalone/.next/static/chunks/285spx855h_3r.css +0 -2
  396. package/.next/standalone/.next/static/chunks/2qv4hshejedtx.css +0 -1
  397. package/.next/standalone/.next/static/chunks/2vkvu9-opa_1z.js +0 -1
  398. package/.next/standalone/.next/static/chunks/37lhv7wa3ywt6.js +0 -1
  399. package/.next/standalone/app/actions/get-jev-config.ts +0 -409
  400. package/.next/standalone/app/actions/update-jev-config.ts +0 -420
  401. package/.next/standalone/app/components/jev-notices.tsx +0 -96
  402. package/.next/standalone/app/settings/jev-panel.tsx +0 -469
  403. package/src/hooks/effective-reviewers.ts +0 -79
  404. package/src/hooks/jev-activity.ts +0 -385
  405. package/src/hooks/jev-cli.ts +0 -1193
  406. package/src/hooks/policy-authority.ts +0 -333
  407. package/src/hooks/policy-reviewability.ts +0 -229
  408. package/src/hooks/semantic/combine.ts +0 -541
  409. package/src/hooks/semantic/compile.ts +0 -176
  410. package/src/hooks/semantic/decide.ts +0 -392
  411. package/src/hooks/semantic/envelope.ts +0 -1296
  412. package/src/hooks/semantic/evaluator.ts +0 -547
  413. package/src/hooks/semantic/facts.ts +0 -292
  414. package/src/hooks/semantic/intent.ts +0 -1190
  415. package/src/hooks/semantic/jev-client.ts +0 -643
  416. package/src/hooks/semantic/jev-config.ts +0 -594
  417. package/src/hooks/semantic/jev-review.ts +0 -374
  418. package/src/hooks/semantic/jev-stats.ts +0 -289
  419. package/src/hooks/semantic/jev-throttle.ts +0 -421
  420. package/src/hooks/semantic/pack-policies.ts +0 -251
  421. package/src/hooks/semantic/policies.ts +0 -596
  422. package/src/hooks/semantic/precondition-names.ts +0 -60
  423. package/src/hooks/semantic/preconditions.ts +0 -58
  424. package/src/hooks/semantic/redact.ts +0 -2910
  425. package/src/hooks/semantic/types.ts +0 -145
  426. package/src/hooks/semver-precedence.ts +0 -128
  427. /package/.next/standalone/.next/static/{T8YAYM9h_64fKv705vug7 → PgeWCHmyVbjRznv2VO7KF}/_buildManifest.js +0 -0
  428. /package/.next/standalone/.next/static/{T8YAYM9h_64fKv705vug7 → PgeWCHmyVbjRznv2VO7KF}/_clientMiddlewareManifest.js +0 -0
  429. /package/.next/standalone/.next/static/{T8YAYM9h_64fKv705vug7 → PgeWCHmyVbjRznv2VO7KF}/_ssgManifest.js +0 -0
@@ -0,0 +1,879 @@
1
+ import * as context from "./context.js";
2
+ import { logger } from "./logger.js";
3
+ import {
4
+ agentEndEvent,
5
+ agentPauseEvent,
6
+ agentResumeEvent,
7
+ agentStartEvent,
8
+ errorEvent,
9
+ hookCompletedEvent,
10
+ hookTriggeredEvent,
11
+ humanInputEvent,
12
+ humanInterruptEvent,
13
+ humanPauseEvent,
14
+ humanWaitEvent,
15
+ modelRequestEvent,
16
+ modelResponseEvent,
17
+ toolResultEvent,
18
+ toolUseEvent,
19
+ } from "./schema.js";
20
+ import type { EventWriter } from "./writer.js";
21
+ import { formatMicros, nowMicros } from "./clock.js";
22
+ import { fatalSuffix, onProcessExit, type OpenItem } from "./exit.js";
23
+
24
+ /**
25
+ * `sessionId` and `agentId` are named options on every method, so a caller
26
+ * cannot pass them as extras. `timestamp` and `type` are not, so they would
27
+ * land in the extras and are caught here — and `environment` with them, since
28
+ * an extra of that name would overwrite the one the schema sets.
29
+ */
30
+ const RESERVED: ReadonlySet<string> = new Set([
31
+ "timestamp",
32
+ "session_id",
33
+ "agent_id",
34
+ "type",
35
+ "environment",
36
+ ]);
37
+
38
+ /**
39
+ * Payload keys ingest lifts out of the JSON blob into unsigned 32-bit columns
40
+ * via `pu32()`. Everything else is stored as-is and can be any shape, but these
41
+ * three are read with a typed accessor that returns null on a mismatch — and a
42
+ * null there is written as NULL under a 200 OK. Nothing is logged, nothing is
43
+ * rejected, and the row still arrives, so the only symptom is a column that is
44
+ * empty for some events and not others.
45
+ *
46
+ * `durationMs` is refused outright on the four events that MEASURE it. These
47
+ * checks cover the other way in: any of the three passed as a custom field on
48
+ * an event that does not name it, plus `modelResponse`'s own two options, which
49
+ * are the ones a caller is most likely to fill straight from a provider's usage
50
+ * object.
51
+ */
52
+ const PROMOTED_NUMERIC: ReadonlySet<string> = new Set([
53
+ "duration_ms",
54
+ "input_tokens",
55
+ "output_tokens",
56
+ ]);
57
+
58
+ /**
59
+ * Payload keys ingest lifts into an INDEXED STRING column via `ps()`, which
60
+ * reads JSON strings and stores NULL for anything else — the same
61
+ * silent-at-200 failure `PROMOTED_NUMERIC` guards. `undefined` is the realistic
62
+ * way in: `toolName: tool?.name` is ordinary code, and it produces a row that
63
+ * is invisible to every tool-name filter and whose `tool_result` never pairs.
64
+ */
65
+ const PROMOTED_STRING: ReadonlySet<string> = new Set([
66
+ "tool_name",
67
+ "tool_call_id",
68
+ "hook_name",
69
+ "hook_id",
70
+ "input_id",
71
+ "pause_id",
72
+ "error_type",
73
+ "model",
74
+ ]);
75
+
76
+ const U32_MAX = 2 ** 32 - 1;
77
+
78
+ /** A value for an error message, without rendering an object as `[object Object]`. */
79
+ function describe(value: unknown): string {
80
+ try {
81
+ return JSON.stringify(value) ?? typeof value;
82
+ } catch {
83
+ return typeof value;
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Reject anything `pu32()` would silently turn into NULL.
89
+ *
90
+ * Rejecting rather than coercing, and at the boundary rather than in the
91
+ * writer, for the same reason `validatedInterval` does: this is the last point
92
+ * where the caller still has a stack trace pointing at their own call. A
93
+ * non-integer is a mistake worth hearing about — the server drops it whole
94
+ * rather than rounding it — and rounding it here would hide that from the one
95
+ * person who could fix the source of it.
96
+ */
97
+ export function validatePromotedNumeric(name: string, value: unknown): void {
98
+ if (value === undefined || value === null) return;
99
+ if (typeof value !== "number" || !Number.isInteger(value)) {
100
+ throw new TypeError(
101
+ `${name} must be an integer (the server reads it as an unsigned 32-bit integer and ` +
102
+ `stores NULL for anything else), got ${typeof value}: ${describe(value)}`,
103
+ );
104
+ }
105
+ if (value < 0 || value > U32_MAX) {
106
+ throw new RangeError(
107
+ `${name} must be between 0 and ${U32_MAX} (an unsigned 32-bit integer), got ${value}`,
108
+ );
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Reject anything `ps()` would silently turn into NULL.
114
+ *
115
+ * Same reasoning and the same boundary. The schema copies the identity block
116
+ * verbatim, so an absent value here would reach the wire as an explicit JSON
117
+ * `null`, the row would be accepted at 200 OK, and the column would be empty
118
+ * for some events and not others with nothing logged anywhere.
119
+ *
120
+ * Extras no longer reach this holding a nullish value: `validateFields` drops
121
+ * the key and warns, so an optional column the caller simply does not have
122
+ * costs a log line rather than the whole event. The throw below stays as the
123
+ * backstop for the declared options.
124
+ */
125
+ export function validatePromotedString(name: string, value: unknown): void {
126
+ if (value === undefined || value === null) {
127
+ throw new TypeError(
128
+ `${name} must be a string (the server lifts it into an indexed column and stores NULL ` +
129
+ `for anything else, so the event would be accepted at 200 OK and be invisible to ` +
130
+ `every filter on ${name}), got ${value === null ? "null" : "undefined"}`,
131
+ );
132
+ }
133
+ if (typeof value !== "string") {
134
+ throw new TypeError(
135
+ `${name} must be a string (the server lifts it into an indexed column and stores NULL ` +
136
+ `for anything else), got ${typeof value}`,
137
+ );
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Reject an id the server will skip, at the point the caller can see it.
143
+ *
144
+ * `session_id` and `agent_id` are on every one of the 15 event types and are
145
+ * what everything downstream groups by. Ingest requires each to be a JSON
146
+ * string: hand it anything else and the row is SKIPPED — and the response is
147
+ * `200 OK` with `{"accepted": 0, "skipped": 1}`, so nothing upstream learns.
148
+ * The SDK reports success, the collector deletes the batch, and the event is
149
+ * gone. Verified against the live server for number, null and object.
150
+ *
151
+ * Empty and whitespace-only are refused as well, and those the server DOES
152
+ * accept. That is the worse outcome of the two: every event lands, grouped
153
+ * under one blank id, so the data looks present and is silently merged.
154
+ */
155
+ function validateIdentity(name: string, value: unknown): asserts value is string {
156
+ if (typeof value !== "string") {
157
+ throw new TypeError(
158
+ `${name} must be a string — the server skips any event whose ${name} is not a JSON ` +
159
+ `string, and answers 200 as though it stored it. Got ${value === null ? "null" : typeof value}`,
160
+ );
161
+ }
162
+ if (value.trim() === "") {
163
+ throw new Error(
164
+ `${name} must not be empty — the server accepts it, so every event sent this way is ` +
165
+ "silently grouped under one blank id.",
166
+ );
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Fill an omitted `sessionId`/`agentId` from the ambient scope, then validate.
172
+ *
173
+ * ORDER MATTERS. The validation runs on the RESOLVED value, not the argument.
174
+ * Validating first would reject every ambient call; resolving without
175
+ * validating would put the silent-skip back: ingest drops an event whose
176
+ * `session_id` is not a JSON string and answers `200 OK` with
177
+ * `{"accepted":0,"skipped":1}`, so a run with nothing bound would vanish rather
178
+ * than fail.
179
+ *
180
+ * Called AFTER `validateFields`, deliberately. A reserved extra is a fault in
181
+ * the call itself and reads identically from anywhere, so reporting it first
182
+ * gives a stable, reproducible message; the identity error depends on where the
183
+ * call was made from, and is the less useful of the two to hear when both are
184
+ * true.
185
+ *
186
+ * `agentId` falls back to `DEFAULT_AGENT_ID` rather than throwing — an event
187
+ * emitted inside `session()` with no `agent()` around it lands somewhere
188
+ * sensible. `sessionId` has no such default: inventing one would scatter a run
189
+ * across as many sessions as it has emit sites.
190
+ */
191
+ function resolveIdentity(
192
+ sessionId: string | null | undefined,
193
+ agentId: string | null | undefined,
194
+ ): [string, string] {
195
+ let sid: string | null | undefined = sessionId;
196
+ let aid: string | null | undefined = agentId;
197
+ if (sid === undefined || sid === null) sid = context.sessionId();
198
+ if (aid === undefined || aid === null) aid = context.agentId();
199
+
200
+ if (sid === undefined || sid === null) {
201
+ throw new TypeError(
202
+ "sessionId is required and nothing is bound. Pass sessionId, or wrap the call in " +
203
+ "`await failproofai.session(fn)` / `await failproofai.agent('name', fn)`. A callback " +
204
+ "stored in one run and invoked from another does not inherit the ambient scope — " +
205
+ "hand it over with `failproofai.propagate(fn)`.",
206
+ );
207
+ }
208
+ validateIdentity("sessionId", sid);
209
+ validateIdentity("agentId", aid);
210
+ return [sid, aid];
211
+ }
212
+
213
+ /**
214
+ * Whole milliseconds between a paired start and end, or undefined.
215
+ *
216
+ * `pu32()` reads `duration_ms` as an unsigned 32-bit integer and stores NULL
217
+ * for anything outside it, at `200 OK`, so an out-of-range duration is not an
218
+ * error anywhere: the row lands with an empty column and nothing says why.
219
+ *
220
+ * Two ways to leave the range, both reachable without anything being wrong with
221
+ * the caller:
222
+ *
223
+ * * **over.** 2**32 ms is ~49.7 days. A `humanWait` answered after a long
224
+ * weekend, or an `agentPause` resumed a month later, is an ordinary lifetime
225
+ * for these pairs, not an abuse of them.
226
+ * * **under.** These are wall-clock readings, so an NTP step backwards between
227
+ * start and end yields a NEGATIVE interval, and a negative into an unsigned
228
+ * column is the same silent NULL.
229
+ *
230
+ * Omitted rather than clamped. A clamped 49.7 days is indistinguishable from a
231
+ * measurement, and the whole reason `duration_ms` is computed here instead of
232
+ * accepted from the caller is that a reported duration is unfalsifiable. An
233
+ * absent field is at least honest, and the timestamps are still on both events
234
+ * for anyone who wants to do the subtraction themselves.
235
+ */
236
+ function measuredDurationMs(start: number | undefined, end: number): number | undefined {
237
+ if (start === undefined) return undefined;
238
+ const ms = Math.round((end - start) / 1000);
239
+ if (ms < 0 || ms > U32_MAX) {
240
+ logger.warn(
241
+ `omitted duration_ms=${ms}: outside the unsigned 32-bit range the server stores it in ` +
242
+ `(0..${U32_MAX}). The event is unaffected.`,
243
+ );
244
+ return undefined;
245
+ }
246
+ return ms;
247
+ }
248
+
249
+ /**
250
+ * Hard cap on the correlation map. Orphaned starts (a `toolUse` with no
251
+ * `toolResult`, a `humanWait` the user never answers) would otherwise grow it
252
+ * unbounded in a long-running process. At the cap the oldest entry is evicted —
253
+ * a `Map` preserves insertion order.
254
+ */
255
+ const PENDING_CAP = 10_000;
256
+
257
+ /**
258
+ * Every pairing is keyed by what it pairs and by the SESSION it belongs to —
259
+ * and deliberately NOT by the agent.
260
+ *
261
+ * The rule: include what makes the id unique, exclude what can legitimately
262
+ * change between the start event and the end event.
263
+ *
264
+ * * KIND belongs in the key. Tool pairs keyed on the bare `toolCallId` and hook
265
+ * pairs on the bare `hookId` would share one flat keyspace, so a caller whose
266
+ * tool call and hook happened to share an id — not exotic, both are
267
+ * frequently the harness's own step id — would get a `hook_completed` that
268
+ * consumed the `tool_use` timestamp, and then a `tool_result` with no
269
+ * duration at all.
270
+ *
271
+ * * SESSION belongs in the key. This map lives on one process-wide namespace,
272
+ * so two sessions in one process — a supervisor running agents concurrently,
273
+ * the ordinary multi-agent shape — would collide on any shared step id.
274
+ *
275
+ * * AGENT DOES NOT. This is the tempting third component and it is wrong. Once
276
+ * a framework runs tools inside sub-agents, a `tool_use` opened under
277
+ * `planner` and closed under `worker` is routine — LangGraph does it — and an
278
+ * agent-scoped key makes those pairs miss entirely, silently dropping
279
+ * `duration_ms` for exactly the nested runs that most need it. A session
280
+ * cannot change under a pair; an agent can.
281
+ *
282
+ * These are correlation keys only; they are never emitted and never leave the
283
+ * process, so the shape changes no wire format.
284
+ */
285
+ const toolKey = (sessionId: string, toolCallId: string): string =>
286
+ `tool:${sessionId}:${toolCallId}`;
287
+ const hookKey = (sessionId: string, hookId: string): string => `hook:${sessionId}:${hookId}`;
288
+ const pauseKey = (sessionId: string, pauseId: string): string => `pause:${sessionId}:${pauseId}`;
289
+ const humanKey = (sessionId: string, inputId: string): string => `human:${sessionId}:${inputId}`;
290
+
291
+ export interface BaseEventOptions {
292
+ sessionId?: string | null;
293
+ agentId?: string | null;
294
+ /**
295
+ * Any other key is a custom payload field, merged verbatim onto the event —
296
+ * the direct analogue of Python's `**fields`. Namespace anything
297
+ * framework-specific `fw_*`; a name that collides with a declared field is
298
+ * refused.
299
+ */
300
+ [field: string]: unknown;
301
+ }
302
+
303
+ export interface ToolUseOptions extends BaseEventOptions {
304
+ toolName: string;
305
+ toolCallId: string;
306
+ input?: Record<string, unknown> | null;
307
+ }
308
+
309
+ export interface ToolResultOptions extends BaseEventOptions {
310
+ toolName: string;
311
+ toolCallId: string;
312
+ output?: unknown;
313
+ error?: string | null;
314
+ }
315
+
316
+ export interface ModelRequestOptions extends BaseEventOptions {
317
+ model?: string | null;
318
+ messages?: Array<Record<string, unknown>> | null;
319
+ system?: unknown;
320
+ tools?: Array<Record<string, unknown>> | null;
321
+ requestId?: string | null;
322
+ }
323
+
324
+ export interface ModelResponseOptions extends BaseEventOptions {
325
+ model?: string | null;
326
+ stopReason?: string | null;
327
+ inputTokens?: number | null;
328
+ outputTokens?: number | null;
329
+ content?: unknown;
330
+ role?: string | null;
331
+ requestId?: string | null;
332
+ }
333
+
334
+ export interface AgentStartOptions extends BaseEventOptions {
335
+ goal?: string | null;
336
+ parentId?: string | null;
337
+ }
338
+
339
+ export interface AgentEndOptions extends BaseEventOptions {
340
+ outcome?: string | null;
341
+ summary?: string | null;
342
+ }
343
+
344
+ export interface AgentPauseOptions extends BaseEventOptions {
345
+ pauseId: string;
346
+ reason?: string | null;
347
+ userId?: string | null;
348
+ }
349
+
350
+ export interface AgentResumeOptions extends BaseEventOptions {
351
+ pauseId: string;
352
+ reason?: string | null;
353
+ userId?: string | null;
354
+ }
355
+
356
+ export interface HookTriggeredOptions extends BaseEventOptions {
357
+ hookName: string;
358
+ hookId: string;
359
+ triggerEvent?: string | null;
360
+ input?: unknown;
361
+ }
362
+
363
+ export interface HookCompletedOptions extends BaseEventOptions {
364
+ hookName: string;
365
+ hookId: string;
366
+ outcome?: string | null;
367
+ output?: unknown;
368
+ error?: string | null;
369
+ }
370
+
371
+ export interface ErrorOptions extends BaseEventOptions {
372
+ errorType: string;
373
+ message: string;
374
+ traceback?: string | null;
375
+ }
376
+
377
+ export interface HumanWaitOptions extends BaseEventOptions {
378
+ inputId: string;
379
+ prompt?: string | null;
380
+ options?: string[] | null;
381
+ reason?: string | null;
382
+ }
383
+
384
+ export interface HumanInputOptions extends BaseEventOptions {
385
+ inputId: string;
386
+ response?: string | null;
387
+ }
388
+
389
+ export interface HumanPauseOptions extends BaseEventOptions {
390
+ reason?: string | null;
391
+ userId?: string | null;
392
+ }
393
+
394
+ export interface HumanInterruptOptions extends BaseEventOptions {
395
+ reason?: string | null;
396
+ userId?: string | null;
397
+ atStep?: string | null;
398
+ }
399
+
400
+ type Extras = Record<string, unknown>;
401
+
402
+ /** A tool call, hook or model call opened and not yet closed. */
403
+ interface OpenLeaf {
404
+ kind: "tool" | "hook" | "model";
405
+ sessionId: string;
406
+ agentId: string;
407
+ id: string;
408
+ /** Tool or hook name; the model, for a model call. */
409
+ name: string | undefined;
410
+ /** When it opened: the exit path's ordering, and a model call's duration. */
411
+ startedMicros: number;
412
+ }
413
+
414
+ export class EventNamespace {
415
+ private readonly writer: EventWriter;
416
+ private readonly pending = new Map<string, number>();
417
+ /**
418
+ * Tool calls, hooks and model calls opened and not yet closed, keyed
419
+ * `<kind>:<session>:<id>`, so the exit path can close them — whoever opened
420
+ * them: a hand-written `event.*` call, a `toolCall()` scope, or an adapter.
421
+ * Every one of those goes through this namespace, which is why this is the
422
+ * one place it is done.
423
+ */
424
+ private readonly openLeaves = new Map<string, OpenLeaf>();
425
+ /** Open `agent_pause`s per session: a run waiting on a human is not abandoned. */
426
+ private readonly pausedSessions = new Map<string, number>();
427
+
428
+ constructor(writer: EventWriter) {
429
+ this.writer = writer;
430
+ const self = new WeakRef(this);
431
+ const unregister = onProcessExit(() => {
432
+ const namespace = self.deref();
433
+ if (namespace === undefined) {
434
+ unregister();
435
+ return [];
436
+ }
437
+ return namespace.openAtExit();
438
+ });
439
+ }
440
+
441
+ private openLeaf(key: string, leaf: OpenLeaf): void {
442
+ if (this.openLeaves.size >= PENDING_CAP) {
443
+ const oldest = this.openLeaves.keys().next();
444
+ if (!oldest.done) this.openLeaves.delete(oldest.value);
445
+ }
446
+ this.openLeaves.set(key, leaf);
447
+ }
448
+
449
+ /**
450
+ * The process is exiting: every open tool call, hook and model call, for the
451
+ * exit path to close in one most-recent-first order with everything else
452
+ * still open (`exit.ts`) — except in a session paused on a human, which
453
+ * another process may resume.
454
+ */
455
+ openAtExit(): OpenItem[] {
456
+ const items: OpenItem[] = [];
457
+ for (const [key, leaf] of this.openLeaves) {
458
+ if ((this.pausedSessions.get(leaf.sessionId) ?? 0) > 0) continue;
459
+ items.push({ opened: leaf.startedMicros, close: (exitCode) => this.closeLeaf(key, leaf, exitCode) });
460
+ }
461
+ return items;
462
+ }
463
+
464
+ private closeLeaf(key: string, leaf: OpenLeaf, exitCode: number): void {
465
+ if (!this.openLeaves.delete(key)) return; // closed normally in the meantime
466
+ const why = (what: string) =>
467
+ `ProcessExit: the process exited (code ${exitCode})${fatalSuffix()} while ${what} was still running`;
468
+ const identity = { sessionId: leaf.sessionId, agentId: leaf.agentId };
469
+ if (leaf.kind === "tool") {
470
+ this.toolResult({ ...identity, toolName: leaf.name ?? "tool", toolCallId: leaf.id, error: why(`tool ${JSON.stringify(leaf.name)}`) });
471
+ } else if (leaf.kind === "hook") {
472
+ this.hookCompleted({ ...identity, hookName: leaf.name ?? "hook", hookId: leaf.id, outcome: "failed", error: why(`hook ${JSON.stringify(leaf.name)}`) });
473
+ } else {
474
+ // Model calls are not timed by the SDK (a caller passes duration_ms);
475
+ // one closed here is, so it matches the tools and hooks closed beside it.
476
+ const elapsed = Math.round((nowMicros() - leaf.startedMicros) / 1000);
477
+ this.modelResponse({
478
+ ...identity,
479
+ requestId: leaf.id,
480
+ model: leaf.name,
481
+ stopReason: "error",
482
+ error: why("the model call"),
483
+ ...(elapsed >= 0 ? { duration_ms: elapsed } : {}),
484
+ });
485
+ }
486
+ }
487
+
488
+
489
+ private trackPending(key: string, ts: number): void {
490
+ // No lock and no tolerance for a concurrent evictor, unlike the Python SDK:
491
+ // JavaScript runs this on one thread, so `size` / `keys().next()` / `delete`
492
+ // cannot interleave with another emit. The cap is exact here rather than
493
+ // approximate.
494
+ if (this.pending.size >= PENDING_CAP) {
495
+ const oldest = this.pending.keys().next();
496
+ if (!oldest.done) this.pending.delete(oldest.value);
497
+ }
498
+ this.pending.set(key, ts);
499
+ }
500
+
501
+ private takePending(key: string): number | undefined {
502
+ const value = this.pending.get(key);
503
+ if (value !== undefined) this.pending.delete(key);
504
+ return value;
505
+ }
506
+
507
+ private validateFields(fields: Extras): void {
508
+ const bad = Object.keys(fields).filter((key) => RESERVED.has(key));
509
+ if (bad.length > 0) {
510
+ throw new Error(
511
+ `Reserved field names cannot be used as custom fields: ${JSON.stringify(bad.sort())}`,
512
+ );
513
+ }
514
+ // The schema merges extras verbatim, so a promoted key left nullish would
515
+ // reach the wire as an explicit JSON null — accepted at 200 OK, stored as
516
+ // NULL, invisible to every filter on that column. For a promoted column "no
517
+ // value" has to mean "no key", so drop it here, the one place holding the
518
+ // caller's own object. Warned rather than silent: passing a nullish value
519
+ // is still a mistake worth hearing about, it just must not cost the event.
520
+ for (const name of Object.keys(fields)) {
521
+ if (!PROMOTED_NUMERIC.has(name) && !PROMOTED_STRING.has(name)) continue;
522
+ if (fields[name] === undefined || fields[name] === null) {
523
+ logger.warn(
524
+ `${name} was passed as ${fields[name] === null ? "null" : "undefined"} and has been ` +
525
+ "omitted from the event; pass a value, or omit the key entirely to silence this.",
526
+ );
527
+ delete fields[name];
528
+ }
529
+ }
530
+ for (const name of Object.keys(fields)) {
531
+ if (PROMOTED_NUMERIC.has(name)) validatePromotedNumeric(name, fields[name]);
532
+ if (PROMOTED_STRING.has(name)) validatePromotedString(name, fields[name]);
533
+ }
534
+ }
535
+
536
+ private refuseDuration(fields: Extras): void {
537
+ if ("duration_ms" in fields || "durationMs" in fields) {
538
+ throw new Error(
539
+ "duration_ms is auto-computed by the SDK and cannot be passed by the caller",
540
+ );
541
+ }
542
+ }
543
+
544
+ /** Epoch microseconds, strictly increasing in the process — see `clock.ts`. */
545
+ private now(): number {
546
+ return nowMicros();
547
+ }
548
+
549
+ /**
550
+ * `2026-09-23T12:34:56.123004Z` — six fractional digits, matching the Python
551
+ * SDK's `%f` and the format the ingest endpoint parses. The last three are an
552
+ * ordering sequence inside the millisecond, not a measurement (`clock.ts`).
553
+ */
554
+ private fmtTs(micros: number): string {
555
+ return formatMicros(micros);
556
+ }
557
+
558
+ toolUse(options: ToolUseOptions): void {
559
+ const { sessionId, agentId, toolName, toolCallId, input, ...fields } = options;
560
+ this.validateFields(fields);
561
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
562
+ if (typeof toolCallId === "string") {
563
+ this.openLeaf(`tool:${sid}:${toolCallId}`, { kind: "tool", sessionId: sid, agentId: aid, id: toolCallId, name: toolName, startedMicros: nowMicros() });
564
+ }
565
+ const ts = this.now();
566
+ this.trackPending(toolKey(sid, toolCallId), ts);
567
+ this.writer.submit(
568
+ toolUseEvent({
569
+ timestamp: this.fmtTs(ts),
570
+ sessionId: sid,
571
+ agentId: aid,
572
+ toolName,
573
+ toolCallId,
574
+ input,
575
+ extraFields: fields,
576
+ }),
577
+ );
578
+ }
579
+
580
+ toolResult(options: ToolResultOptions): void {
581
+ const { sessionId, agentId, toolName, toolCallId, output, error, ...fields } = options;
582
+ this.refuseDuration(fields);
583
+ this.validateFields(fields);
584
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
585
+ this.openLeaves.delete(`tool:${sid}:${toolCallId}`);
586
+ const ts = this.now();
587
+ const durationMs = measuredDurationMs(this.takePending(toolKey(sid, toolCallId)), ts);
588
+ this.writer.submit(
589
+ toolResultEvent({
590
+ timestamp: this.fmtTs(ts),
591
+ sessionId: sid,
592
+ agentId: aid,
593
+ toolName,
594
+ toolCallId,
595
+ output,
596
+ error,
597
+ durationMs,
598
+ extraFields: fields,
599
+ }),
600
+ );
601
+ }
602
+
603
+ modelRequest(options: ModelRequestOptions = {}): void {
604
+ const { sessionId, agentId, model, messages, system, tools, requestId, ...fields } = options;
605
+ this.validateFields(fields);
606
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
607
+ if (typeof requestId === "string" && requestId !== "") {
608
+ this.openLeaf(`model:${sid}:${requestId}`, { kind: "model", sessionId: sid, agentId: aid, id: requestId, name: model ?? undefined, startedMicros: nowMicros() });
609
+ }
610
+ this.writer.submit(
611
+ modelRequestEvent({
612
+ timestamp: this.fmtTs(this.now()),
613
+ sessionId: sid,
614
+ agentId: aid,
615
+ model,
616
+ messages,
617
+ system,
618
+ tools,
619
+ requestId,
620
+ extraFields: fields,
621
+ }),
622
+ );
623
+ }
624
+
625
+ modelResponse(options: ModelResponseOptions = {}): void {
626
+ const {
627
+ sessionId,
628
+ agentId,
629
+ model,
630
+ stopReason,
631
+ inputTokens,
632
+ outputTokens,
633
+ content,
634
+ role,
635
+ requestId,
636
+ ...fields
637
+ } = options;
638
+ // Named options, so they never reach `validateFields`. They are also the
639
+ // likeliest of the three to arrive wrong: a caller reading them off a
640
+ // provider's usage object gets whatever that object holds.
641
+ validatePromotedNumeric("inputTokens", inputTokens);
642
+ validatePromotedNumeric("outputTokens", outputTokens);
643
+ this.validateFields(fields);
644
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
645
+ if (typeof requestId === "string") this.openLeaves.delete(`model:${sid}:${requestId}`);
646
+ this.writer.submit(
647
+ modelResponseEvent({
648
+ timestamp: this.fmtTs(this.now()),
649
+ sessionId: sid,
650
+ agentId: aid,
651
+ model,
652
+ stopReason,
653
+ inputTokens,
654
+ outputTokens,
655
+ content,
656
+ role,
657
+ requestId,
658
+ extraFields: fields,
659
+ }),
660
+ );
661
+ }
662
+
663
+ agentStart(options: AgentStartOptions = {}): void {
664
+ const { sessionId, agentId, goal, parentId, ...fields } = options;
665
+ this.validateFields(fields);
666
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
667
+ this.writer.submit(
668
+ agentStartEvent({
669
+ timestamp: this.fmtTs(this.now()),
670
+ sessionId: sid,
671
+ agentId: aid,
672
+ goal,
673
+ parentId,
674
+ extraFields: fields,
675
+ }),
676
+ );
677
+ }
678
+
679
+ agentEnd(options: AgentEndOptions = {}): void {
680
+ const { sessionId, agentId, outcome, summary, ...fields } = options;
681
+ this.validateFields(fields);
682
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
683
+ this.writer.submit(
684
+ agentEndEvent({
685
+ timestamp: this.fmtTs(this.now()),
686
+ sessionId: sid,
687
+ agentId: aid,
688
+ outcome,
689
+ summary,
690
+ extraFields: fields,
691
+ }),
692
+ );
693
+ }
694
+
695
+ agentPause(options: AgentPauseOptions): void {
696
+ const { sessionId, agentId, pauseId, reason, userId, ...fields } = options;
697
+ this.validateFields(fields);
698
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
699
+ this.pausedSessions.set(sid, (this.pausedSessions.get(sid) ?? 0) + 1);
700
+ const ts = this.now();
701
+ this.trackPending(pauseKey(sid, pauseId), ts);
702
+ this.writer.submit(
703
+ agentPauseEvent({
704
+ timestamp: this.fmtTs(ts),
705
+ sessionId: sid,
706
+ agentId: aid,
707
+ pauseId,
708
+ reason,
709
+ userId,
710
+ extraFields: fields,
711
+ }),
712
+ );
713
+ }
714
+
715
+ agentResume(options: AgentResumeOptions): void {
716
+ const { sessionId, agentId, pauseId, reason, userId, ...fields } = options;
717
+ this.refuseDuration(fields);
718
+ this.validateFields(fields);
719
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
720
+ {
721
+ const open = (this.pausedSessions.get(sid) ?? 0) - 1;
722
+ if (open > 0) this.pausedSessions.set(sid, open);
723
+ else this.pausedSessions.delete(sid);
724
+ }
725
+ const ts = this.now();
726
+ const durationMs = measuredDurationMs(this.takePending(pauseKey(sid, pauseId)), ts);
727
+ this.writer.submit(
728
+ agentResumeEvent({
729
+ timestamp: this.fmtTs(ts),
730
+ sessionId: sid,
731
+ agentId: aid,
732
+ pauseId,
733
+ durationMs,
734
+ reason,
735
+ userId,
736
+ extraFields: fields,
737
+ }),
738
+ );
739
+ }
740
+
741
+ hookTriggered(options: HookTriggeredOptions): void {
742
+ const { sessionId, agentId, hookName, hookId, triggerEvent, input, ...fields } = options;
743
+ this.validateFields(fields);
744
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
745
+ if (typeof hookId === "string") {
746
+ this.openLeaf(`hook:${sid}:${hookId}`, { kind: "hook", sessionId: sid, agentId: aid, id: hookId, name: hookName, startedMicros: nowMicros() });
747
+ }
748
+ const ts = this.now();
749
+ this.trackPending(hookKey(sid, hookId), ts);
750
+ this.writer.submit(
751
+ hookTriggeredEvent({
752
+ timestamp: this.fmtTs(ts),
753
+ sessionId: sid,
754
+ agentId: aid,
755
+ hookName,
756
+ hookId,
757
+ triggerEvent,
758
+ input,
759
+ extraFields: fields,
760
+ }),
761
+ );
762
+ }
763
+
764
+ hookCompleted(options: HookCompletedOptions): void {
765
+ const { sessionId, agentId, hookName, hookId, outcome, output, error, ...fields } = options;
766
+ this.refuseDuration(fields);
767
+ this.validateFields(fields);
768
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
769
+ const ts = this.now();
770
+ this.openLeaves.delete(`hook:${sid}:${hookId}`);
771
+ const durationMs = measuredDurationMs(this.takePending(hookKey(sid, hookId)), ts);
772
+ this.writer.submit(
773
+ hookCompletedEvent({
774
+ timestamp: this.fmtTs(ts),
775
+ sessionId: sid,
776
+ agentId: aid,
777
+ hookName,
778
+ hookId,
779
+ outcome,
780
+ output,
781
+ error,
782
+ durationMs,
783
+ extraFields: fields,
784
+ }),
785
+ );
786
+ }
787
+
788
+ error(options: ErrorOptions): void {
789
+ const { sessionId, agentId, errorType, message, traceback, ...fields } = options;
790
+ this.validateFields(fields);
791
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
792
+ this.writer.submit(
793
+ errorEvent({
794
+ timestamp: this.fmtTs(this.now()),
795
+ sessionId: sid,
796
+ agentId: aid,
797
+ errorType,
798
+ message,
799
+ traceback,
800
+ extraFields: fields,
801
+ }),
802
+ );
803
+ }
804
+
805
+ humanWait(opts: HumanWaitOptions): void {
806
+ const { sessionId, agentId, inputId, prompt, options, reason, ...fields } = opts;
807
+ this.validateFields(fields);
808
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
809
+ const ts = this.now();
810
+ this.trackPending(humanKey(sid, inputId), ts);
811
+ this.writer.submit(
812
+ humanWaitEvent({
813
+ timestamp: this.fmtTs(ts),
814
+ sessionId: sid,
815
+ agentId: aid,
816
+ inputId,
817
+ prompt,
818
+ options,
819
+ reason,
820
+ extraFields: fields,
821
+ }),
822
+ );
823
+ }
824
+
825
+ humanInput(options: HumanInputOptions): void {
826
+ const { sessionId, agentId, inputId, response, ...fields } = options;
827
+ this.refuseDuration(fields);
828
+ this.validateFields(fields);
829
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
830
+ const ts = this.now();
831
+ const durationMs = measuredDurationMs(this.takePending(humanKey(sid, inputId)), ts);
832
+ this.writer.submit(
833
+ humanInputEvent({
834
+ timestamp: this.fmtTs(ts),
835
+ sessionId: sid,
836
+ agentId: aid,
837
+ inputId,
838
+ response,
839
+ durationMs,
840
+ extraFields: fields,
841
+ }),
842
+ );
843
+ }
844
+
845
+ humanPause(options: HumanPauseOptions = {}): void {
846
+ const { sessionId, agentId, reason, userId, ...fields } = options;
847
+ this.validateFields(fields);
848
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
849
+ this.writer.submit(
850
+ humanPauseEvent({
851
+ timestamp: this.fmtTs(this.now()),
852
+ sessionId: sid,
853
+ agentId: aid,
854
+ reason,
855
+ userId,
856
+ extraFields: fields,
857
+ }),
858
+ );
859
+ }
860
+
861
+ humanInterrupt(options: HumanInterruptOptions = {}): void {
862
+ const { sessionId, agentId, reason, userId, atStep, ...fields } = options;
863
+ this.validateFields(fields);
864
+ const [sid, aid] = resolveIdentity(sessionId, agentId);
865
+ this.writer.submit(
866
+ humanInterruptEvent({
867
+ timestamp: this.fmtTs(this.now()),
868
+ sessionId: sid,
869
+ agentId: aid,
870
+ reason,
871
+ userId,
872
+ atStep,
873
+ extraFields: fields,
874
+ }),
875
+ );
876
+ }
877
+ }
878
+
879
+ export { RESERVED, PROMOTED_NUMERIC, PROMOTED_STRING, U32_MAX, PENDING_CAP };