@animalabs/agent-framework 0.26.2 → 0.28.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 (371) hide show
  1. package/README.md +99 -8
  2. package/dist/src/agent.d.ts +291 -23
  3. package/dist/src/agent.d.ts.map +1 -1
  4. package/dist/src/agent.js +596 -61
  5. package/dist/src/agent.js.map +1 -1
  6. package/dist/src/api/server.d.ts.map +1 -1
  7. package/dist/src/api/server.js +5 -4
  8. package/dist/src/api/server.js.map +1 -1
  9. package/dist/src/auto-continue.d.ts +34 -0
  10. package/dist/src/auto-continue.d.ts.map +1 -0
  11. package/dist/src/auto-continue.js +36 -0
  12. package/dist/src/auto-continue.js.map +1 -0
  13. package/dist/src/code-execution/isolate/scripts.d.ts +11 -0
  14. package/dist/src/code-execution/isolate/scripts.d.ts.map +1 -1
  15. package/dist/src/code-execution/isolate/scripts.js +5 -1
  16. package/dist/src/code-execution/isolate/scripts.js.map +1 -1
  17. package/dist/src/cut-off-round.d.ts +24 -0
  18. package/dist/src/cut-off-round.d.ts.map +1 -0
  19. package/dist/src/cut-off-round.js +87 -0
  20. package/dist/src/cut-off-round.js.map +1 -0
  21. package/dist/src/framework.d.ts +1038 -193
  22. package/dist/src/framework.d.ts.map +1 -1
  23. package/dist/src/framework.js +5967 -1514
  24. package/dist/src/framework.js.map +1 -1
  25. package/dist/src/gate/event-gate.d.ts +405 -46
  26. package/dist/src/gate/event-gate.d.ts.map +1 -1
  27. package/dist/src/gate/event-gate.js +2646 -399
  28. package/dist/src/gate/event-gate.js.map +1 -1
  29. package/dist/src/gate/index.d.ts +3 -2
  30. package/dist/src/gate/index.d.ts.map +1 -1
  31. package/dist/src/gate/index.js +2 -1
  32. package/dist/src/gate/index.js.map +1 -1
  33. package/dist/src/gate/recipe-reconcile.d.ts +103 -0
  34. package/dist/src/gate/recipe-reconcile.d.ts.map +1 -0
  35. package/dist/src/gate/recipe-reconcile.js +325 -0
  36. package/dist/src/gate/recipe-reconcile.js.map +1 -0
  37. package/dist/src/gate/reply-judge.d.ts +116 -0
  38. package/dist/src/gate/reply-judge.d.ts.map +1 -0
  39. package/dist/src/gate/reply-judge.js +467 -0
  40. package/dist/src/gate/reply-judge.js.map +1 -0
  41. package/dist/src/gate/types.d.ts +229 -8
  42. package/dist/src/gate/types.d.ts.map +1 -1
  43. package/dist/src/heartbeat/heartbeat.d.ts +184 -0
  44. package/dist/src/heartbeat/heartbeat.d.ts.map +1 -0
  45. package/dist/src/heartbeat/heartbeat.js +752 -0
  46. package/dist/src/heartbeat/heartbeat.js.map +1 -0
  47. package/dist/src/heartbeat/reminder-time.d.ts +5 -0
  48. package/dist/src/heartbeat/reminder-time.d.ts.map +1 -0
  49. package/dist/src/heartbeat/reminder-time.js +107 -0
  50. package/dist/src/heartbeat/reminder-time.js.map +1 -0
  51. package/dist/src/index.d.ts +10 -4
  52. package/dist/src/index.d.ts.map +1 -1
  53. package/dist/src/index.js +7 -2
  54. package/dist/src/index.js.map +1 -1
  55. package/dist/src/mcpl/capability-mask.d.ts.map +1 -1
  56. package/dist/src/mcpl/capability-mask.js +3 -2
  57. package/dist/src/mcpl/capability-mask.js.map +1 -1
  58. package/dist/src/mcpl/channel-registry.d.ts +433 -113
  59. package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
  60. package/dist/src/mcpl/channel-registry.js +1154 -435
  61. package/dist/src/mcpl/channel-registry.js.map +1 -1
  62. package/dist/src/mcpl/conversation-router.d.ts +16 -8
  63. package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
  64. package/dist/src/mcpl/conversation-router.js +29 -15
  65. package/dist/src/mcpl/conversation-router.js.map +1 -1
  66. package/dist/src/mcpl/convert-block.d.ts.map +1 -1
  67. package/dist/src/mcpl/convert-block.js +14 -2
  68. package/dist/src/mcpl/convert-block.js.map +1 -1
  69. package/dist/src/mcpl/hook-orchestrator.d.ts +7 -1
  70. package/dist/src/mcpl/hook-orchestrator.d.ts.map +1 -1
  71. package/dist/src/mcpl/hook-orchestrator.js +32 -7
  72. package/dist/src/mcpl/hook-orchestrator.js.map +1 -1
  73. package/dist/src/mcpl/inbound-source.d.ts +26 -10
  74. package/dist/src/mcpl/inbound-source.d.ts.map +1 -1
  75. package/dist/src/mcpl/inbound-source.js +40 -69
  76. package/dist/src/mcpl/inbound-source.js.map +1 -1
  77. package/dist/src/mcpl/index.d.ts +5 -1
  78. package/dist/src/mcpl/index.d.ts.map +1 -1
  79. package/dist/src/mcpl/index.js +4 -0
  80. package/dist/src/mcpl/index.js.map +1 -1
  81. package/dist/src/mcpl/inference-router.d.ts +14 -2
  82. package/dist/src/mcpl/inference-router.d.ts.map +1 -1
  83. package/dist/src/mcpl/inference-router.js +73 -28
  84. package/dist/src/mcpl/inference-router.js.map +1 -1
  85. package/dist/src/mcpl/prose-grammar.d.ts +4 -0
  86. package/dist/src/mcpl/prose-grammar.d.ts.map +1 -1
  87. package/dist/src/mcpl/prose-grammar.js +6 -0
  88. package/dist/src/mcpl/prose-grammar.js.map +1 -1
  89. package/dist/src/mcpl/protocol-family.d.ts.map +1 -1
  90. package/dist/src/mcpl/protocol-family.js +3 -0
  91. package/dist/src/mcpl/protocol-family.js.map +1 -1
  92. package/dist/src/mcpl/push-coalescer.d.ts +20 -2
  93. package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
  94. package/dist/src/mcpl/push-coalescer.js +33 -11
  95. package/dist/src/mcpl/push-coalescer.js.map +1 -1
  96. package/dist/src/mcpl/reference-fetcher.d.ts +63 -42
  97. package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
  98. package/dist/src/mcpl/reference-fetcher.js +177 -145
  99. package/dist/src/mcpl/reference-fetcher.js.map +1 -1
  100. package/dist/src/mcpl/references.d.ts +380 -46
  101. package/dist/src/mcpl/references.d.ts.map +1 -1
  102. package/dist/src/mcpl/references.js +736 -77
  103. package/dist/src/mcpl/references.js.map +1 -1
  104. package/dist/src/mcpl/server-connection.d.ts +93 -4
  105. package/dist/src/mcpl/server-connection.d.ts.map +1 -1
  106. package/dist/src/mcpl/server-connection.js +176 -11
  107. package/dist/src/mcpl/server-connection.js.map +1 -1
  108. package/dist/src/mcpl/tags.d.ts +9 -2
  109. package/dist/src/mcpl/tags.d.ts.map +1 -1
  110. package/dist/src/mcpl/tags.js +12 -2
  111. package/dist/src/mcpl/tags.js.map +1 -1
  112. package/dist/src/mcpl/tool-lifecycle.d.ts +11 -0
  113. package/dist/src/mcpl/tool-lifecycle.d.ts.map +1 -1
  114. package/dist/src/mcpl/tool-lifecycle.js +21 -0
  115. package/dist/src/mcpl/tool-lifecycle.js.map +1 -1
  116. package/dist/src/mcpl/tool-presence.d.ts +311 -0
  117. package/dist/src/mcpl/tool-presence.d.ts.map +1 -0
  118. package/dist/src/mcpl/tool-presence.js +697 -0
  119. package/dist/src/mcpl/tool-presence.js.map +1 -0
  120. package/dist/src/mcpl/tool-result-normalize.d.ts +9 -3
  121. package/dist/src/mcpl/tool-result-normalize.d.ts.map +1 -1
  122. package/dist/src/mcpl/tool-result-normalize.js +14 -6
  123. package/dist/src/mcpl/tool-result-normalize.js.map +1 -1
  124. package/dist/src/mcpl/tool-signature.d.ts +46 -0
  125. package/dist/src/mcpl/tool-signature.d.ts.map +1 -0
  126. package/dist/src/mcpl/tool-signature.js +321 -0
  127. package/dist/src/mcpl/tool-signature.js.map +1 -0
  128. package/dist/src/mcpl/toolset-host.d.ts +251 -0
  129. package/dist/src/mcpl/toolset-host.d.ts.map +1 -0
  130. package/dist/src/mcpl/toolset-host.js +720 -0
  131. package/dist/src/mcpl/toolset-host.js.map +1 -0
  132. package/dist/src/mcpl/toolsets-module.d.ts +83 -0
  133. package/dist/src/mcpl/toolsets-module.d.ts.map +1 -0
  134. package/dist/src/mcpl/toolsets-module.js +523 -0
  135. package/dist/src/mcpl/toolsets-module.js.map +1 -0
  136. package/dist/src/mcpl/transport.d.ts +2 -2
  137. package/dist/src/mcpl/transport.d.ts.map +1 -1
  138. package/dist/src/mcpl/transport.js +3 -2
  139. package/dist/src/mcpl/transport.js.map +1 -1
  140. package/dist/src/mcpl/types.d.ts +24 -2
  141. package/dist/src/mcpl/types.d.ts.map +1 -1
  142. package/dist/src/mcpl/types.js.map +1 -1
  143. package/dist/src/mcpl/visible-content.d.ts +7 -9
  144. package/dist/src/mcpl/visible-content.d.ts.map +1 -1
  145. package/dist/src/mcpl/visible-content.js +21 -9
  146. package/dist/src/mcpl/visible-content.js.map +1 -1
  147. package/dist/src/module-registry.d.ts +27 -9
  148. package/dist/src/module-registry.d.ts.map +1 -1
  149. package/dist/src/module-registry.js +77 -17
  150. package/dist/src/module-registry.js.map +1 -1
  151. package/dist/src/modules/discord/index.js +1 -1
  152. package/dist/src/modules/discord/index.js.map +1 -1
  153. package/dist/src/modules/history/index.d.ts +2 -1
  154. package/dist/src/modules/history/index.d.ts.map +1 -1
  155. package/dist/src/modules/history/index.js +73 -28
  156. package/dist/src/modules/history/index.js.map +1 -1
  157. package/dist/src/modules/history/semantic.d.ts +108 -6
  158. package/dist/src/modules/history/semantic.d.ts.map +1 -1
  159. package/dist/src/modules/history/semantic.js +273 -57
  160. package/dist/src/modules/history/semantic.js.map +1 -1
  161. package/dist/src/modules/workspace/answers.d.ts +22 -0
  162. package/dist/src/modules/workspace/answers.d.ts.map +1 -0
  163. package/dist/src/modules/workspace/answers.js +123 -0
  164. package/dist/src/modules/workspace/answers.js.map +1 -0
  165. package/dist/src/modules/workspace/branch-intent.d.ts +5 -3
  166. package/dist/src/modules/workspace/branch-intent.d.ts.map +1 -1
  167. package/dist/src/modules/workspace/branch-intent.js +6 -2
  168. package/dist/src/modules/workspace/branch-intent.js.map +1 -1
  169. package/dist/src/modules/workspace/direct-write.d.ts +184 -0
  170. package/dist/src/modules/workspace/direct-write.d.ts.map +1 -0
  171. package/dist/src/modules/workspace/direct-write.js +417 -0
  172. package/dist/src/modules/workspace/direct-write.js.map +1 -0
  173. package/dist/src/modules/workspace/disk-agreement.d.ts +33 -11
  174. package/dist/src/modules/workspace/disk-agreement.d.ts.map +1 -1
  175. package/dist/src/modules/workspace/disk-agreement.js +48 -17
  176. package/dist/src/modules/workspace/disk-agreement.js.map +1 -1
  177. package/dist/src/modules/workspace/edit-text.d.ts +27 -12
  178. package/dist/src/modules/workspace/edit-text.d.ts.map +1 -1
  179. package/dist/src/modules/workspace/edit-text.js +61 -29
  180. package/dist/src/modules/workspace/edit-text.js.map +1 -1
  181. package/dist/src/modules/workspace/effects.d.ts +10 -0
  182. package/dist/src/modules/workspace/effects.d.ts.map +1 -1
  183. package/dist/src/modules/workspace/effects.js +21 -14
  184. package/dist/src/modules/workspace/effects.js.map +1 -1
  185. package/dist/src/modules/workspace/index.d.ts +308 -78
  186. package/dist/src/modules/workspace/index.d.ts.map +1 -1
  187. package/dist/src/modules/workspace/index.js +2103 -720
  188. package/dist/src/modules/workspace/index.js.map +1 -1
  189. package/dist/src/modules/workspace/observe.d.ts +75 -63
  190. package/dist/src/modules/workspace/observe.d.ts.map +1 -1
  191. package/dist/src/modules/workspace/observe.js +366 -180
  192. package/dist/src/modules/workspace/observe.js.map +1 -1
  193. package/dist/src/modules/workspace/read-page.d.ts +41 -0
  194. package/dist/src/modules/workspace/read-page.d.ts.map +1 -0
  195. package/dist/src/modules/workspace/read-page.js +219 -0
  196. package/dist/src/modules/workspace/read-page.js.map +1 -0
  197. package/dist/src/modules/workspace/reconcile.d.ts.map +1 -1
  198. package/dist/src/modules/workspace/reconcile.js +26 -16
  199. package/dist/src/modules/workspace/reconcile.js.map +1 -1
  200. package/dist/src/modules/workspace/result-text.d.ts +68 -0
  201. package/dist/src/modules/workspace/result-text.d.ts.map +1 -0
  202. package/dist/src/modules/workspace/result-text.js +94 -0
  203. package/dist/src/modules/workspace/result-text.js.map +1 -0
  204. package/dist/src/modules/workspace/sync.d.ts +9 -0
  205. package/dist/src/modules/workspace/sync.d.ts.map +1 -1
  206. package/dist/src/modules/workspace/sync.js +14 -0
  207. package/dist/src/modules/workspace/sync.js.map +1 -1
  208. package/dist/src/modules/workspace/text.d.ts +29 -12
  209. package/dist/src/modules/workspace/text.d.ts.map +1 -1
  210. package/dist/src/modules/workspace/text.js +35 -33
  211. package/dist/src/modules/workspace/text.js.map +1 -1
  212. package/dist/src/modules/workspace/types.d.ts +137 -60
  213. package/dist/src/modules/workspace/types.d.ts.map +1 -1
  214. package/dist/src/modules/workspace/types.js.map +1 -1
  215. package/dist/src/modules/workspace/watcher.d.ts.map +1 -1
  216. package/dist/src/modules/workspace/watcher.js +8 -3
  217. package/dist/src/modules/workspace/watcher.js.map +1 -1
  218. package/dist/src/prose-drafts.d.ts +4 -3
  219. package/dist/src/prose-drafts.d.ts.map +1 -1
  220. package/dist/src/prose-drafts.js +3 -2
  221. package/dist/src/prose-drafts.js.map +1 -1
  222. package/dist/src/reasoning-loss-notice.d.ts +23 -0
  223. package/dist/src/reasoning-loss-notice.d.ts.map +1 -0
  224. package/dist/src/reasoning-loss-notice.js +50 -0
  225. package/dist/src/reasoning-loss-notice.js.map +1 -0
  226. package/dist/src/reasoning-loss.d.ts +24 -0
  227. package/dist/src/reasoning-loss.d.ts.map +1 -0
  228. package/dist/src/reasoning-loss.js +102 -0
  229. package/dist/src/reasoning-loss.js.map +1 -0
  230. package/dist/src/send-tools.d.ts +3 -2
  231. package/dist/src/send-tools.d.ts.map +1 -1
  232. package/dist/src/send-tools.js +3 -2
  233. package/dist/src/send-tools.js.map +1 -1
  234. package/dist/src/sent-rows.d.ts +59 -0
  235. package/dist/src/sent-rows.d.ts.map +1 -0
  236. package/dist/src/sent-rows.js +145 -0
  237. package/dist/src/sent-rows.js.map +1 -0
  238. package/dist/src/silent-heartbeat.d.ts +17 -10
  239. package/dist/src/silent-heartbeat.d.ts.map +1 -1
  240. package/dist/src/silent-heartbeat.js.map +1 -1
  241. package/dist/src/stable-hash.d.ts +3 -0
  242. package/dist/src/stable-hash.d.ts.map +1 -0
  243. package/dist/src/stable-hash.js +15 -0
  244. package/dist/src/stable-hash.js.map +1 -0
  245. package/dist/src/stored-injections.d.ts +99 -0
  246. package/dist/src/stored-injections.d.ts.map +1 -0
  247. package/dist/src/stored-injections.js +106 -0
  248. package/dist/src/stored-injections.js.map +1 -0
  249. package/dist/src/text-as-stored.d.ts +4 -3
  250. package/dist/src/text-as-stored.d.ts.map +1 -1
  251. package/dist/src/text-as-stored.js +4 -3
  252. package/dist/src/text-as-stored.js.map +1 -1
  253. package/dist/src/thinking-drops.d.ts +74 -0
  254. package/dist/src/thinking-drops.d.ts.map +1 -0
  255. package/dist/src/thinking-drops.js +96 -0
  256. package/dist/src/thinking-drops.js.map +1 -0
  257. package/dist/src/tool-args.d.ts +12 -0
  258. package/dist/src/tool-args.d.ts.map +1 -1
  259. package/dist/src/tool-args.js +35 -1
  260. package/dist/src/tool-args.js.map +1 -1
  261. package/dist/src/tool-image-ledger.d.ts +9 -8
  262. package/dist/src/tool-image-ledger.d.ts.map +1 -1
  263. package/dist/src/tool-image-ledger.js +9 -8
  264. package/dist/src/tool-image-ledger.js.map +1 -1
  265. package/dist/src/tool-presentation.d.ts.map +1 -1
  266. package/dist/src/tool-presentation.js +3 -1
  267. package/dist/src/tool-presentation.js.map +1 -1
  268. package/dist/src/tool-result-guard.d.ts +12 -6
  269. package/dist/src/tool-result-guard.d.ts.map +1 -1
  270. package/dist/src/tool-result-guard.js +44 -17
  271. package/dist/src/tool-result-guard.js.map +1 -1
  272. package/dist/src/tool-result-history.d.ts +176 -24
  273. package/dist/src/tool-result-history.d.ts.map +1 -1
  274. package/dist/src/tool-result-history.js +411 -91
  275. package/dist/src/tool-result-history.js.map +1 -1
  276. package/dist/src/tune-out/coordinator.d.ts +17 -9
  277. package/dist/src/tune-out/coordinator.d.ts.map +1 -1
  278. package/dist/src/tune-out/coordinator.js +84 -37
  279. package/dist/src/tune-out/coordinator.js.map +1 -1
  280. package/dist/src/tune-out/tools.d.ts +4 -1
  281. package/dist/src/tune-out/tools.d.ts.map +1 -1
  282. package/dist/src/types/agent.d.ts +217 -7
  283. package/dist/src/types/agent.d.ts.map +1 -1
  284. package/dist/src/types/events.d.ts +33 -9
  285. package/dist/src/types/events.d.ts.map +1 -1
  286. package/dist/src/types/framework.d.ts +39 -3
  287. package/dist/src/types/framework.d.ts.map +1 -1
  288. package/dist/src/types/module.d.ts +95 -9
  289. package/dist/src/types/module.d.ts.map +1 -1
  290. package/dist/src/types/trace.d.ts +91 -3
  291. package/dist/src/types/trace.d.ts.map +1 -1
  292. package/package.json +5 -4
  293. package/src/agent.ts +661 -67
  294. package/src/api/server.ts +5 -4
  295. package/src/auto-continue.ts +43 -0
  296. package/src/code-execution/isolate/scripts.ts +11 -3
  297. package/src/cut-off-round.ts +98 -0
  298. package/src/framework.ts +6168 -1540
  299. package/src/gate/event-gate.ts +2895 -405
  300. package/src/gate/index.ts +10 -1
  301. package/src/gate/recipe-reconcile.ts +355 -0
  302. package/src/gate/reply-judge.ts +512 -0
  303. package/src/gate/types.ts +234 -9
  304. package/src/heartbeat/heartbeat.ts +804 -0
  305. package/src/heartbeat/reminder-time.ts +107 -0
  306. package/src/index.ts +11 -4
  307. package/src/mcpl/capability-mask.ts +3 -2
  308. package/src/mcpl/channel-registry.ts +1222 -468
  309. package/src/mcpl/conversation-router.ts +34 -16
  310. package/src/mcpl/convert-block.ts +14 -1
  311. package/src/mcpl/hook-orchestrator.ts +33 -6
  312. package/src/mcpl/inbound-source.ts +42 -69
  313. package/src/mcpl/index.ts +6 -1
  314. package/src/mcpl/inference-router.ts +79 -34
  315. package/src/mcpl/prose-grammar.ts +7 -0
  316. package/src/mcpl/protocol-family.ts +2 -0
  317. package/src/mcpl/push-coalescer.ts +51 -13
  318. package/src/mcpl/reference-fetcher.ts +201 -162
  319. package/src/mcpl/references.ts +851 -77
  320. package/src/mcpl/server-connection.ts +189 -11
  321. package/src/mcpl/tags.ts +13 -2
  322. package/src/mcpl/tool-lifecycle.ts +21 -0
  323. package/src/mcpl/tool-presence.ts +716 -0
  324. package/src/mcpl/tool-result-normalize.ts +18 -6
  325. package/src/mcpl/tool-signature.ts +316 -0
  326. package/src/mcpl/toolset-host.ts +727 -0
  327. package/src/mcpl/toolsets-module.ts +545 -0
  328. package/src/mcpl/transport.ts +3 -2
  329. package/src/mcpl/types.ts +25 -2
  330. package/src/mcpl/visible-content.ts +22 -9
  331. package/src/module-registry.ts +85 -26
  332. package/src/modules/discord/index.ts +1 -1
  333. package/src/modules/history/index.ts +70 -30
  334. package/src/modules/history/semantic.ts +308 -54
  335. package/src/modules/workspace/answers.ts +133 -0
  336. package/src/modules/workspace/branch-intent.ts +10 -5
  337. package/src/modules/workspace/direct-write.ts +460 -0
  338. package/src/modules/workspace/disk-agreement.ts +52 -21
  339. package/src/modules/workspace/edit-text.ts +84 -35
  340. package/src/modules/workspace/effects.ts +22 -13
  341. package/src/modules/workspace/index.ts +2142 -723
  342. package/src/modules/workspace/observe.ts +381 -177
  343. package/src/modules/workspace/read-page.ts +228 -0
  344. package/src/modules/workspace/reconcile.ts +27 -15
  345. package/src/modules/workspace/result-text.ts +121 -0
  346. package/src/modules/workspace/sync.ts +16 -0
  347. package/src/modules/workspace/text.ts +58 -32
  348. package/src/modules/workspace/types.ts +137 -60
  349. package/src/modules/workspace/watcher.ts +8 -3
  350. package/src/prose-drafts.ts +4 -3
  351. package/src/reasoning-loss-notice.ts +62 -0
  352. package/src/reasoning-loss.ts +120 -0
  353. package/src/send-tools.ts +3 -2
  354. package/src/sent-rows.ts +162 -0
  355. package/src/silent-heartbeat.ts +17 -10
  356. package/src/stable-hash.ts +14 -0
  357. package/src/stored-injections.ts +131 -0
  358. package/src/text-as-stored.ts +4 -3
  359. package/src/thinking-drops.ts +135 -0
  360. package/src/tool-args.ts +34 -1
  361. package/src/tool-image-ledger.ts +9 -8
  362. package/src/tool-presentation.ts +3 -1
  363. package/src/tool-result-guard.ts +45 -17
  364. package/src/tool-result-history.ts +471 -90
  365. package/src/tune-out/coordinator.ts +80 -37
  366. package/src/tune-out/tools.ts +4 -1
  367. package/src/types/agent.ts +220 -7
  368. package/src/types/events.ts +33 -9
  369. package/src/types/framework.ts +36 -3
  370. package/src/types/module.ts +91 -9
  371. package/src/types/trace.ts +94 -3
@@ -0,0 +1,467 @@
1
+ /**
2
+ * ReplyJudge — the small model a `judge` wake rule asks whether now is a good
3
+ * time for the agent to reply (JudgeConfig).
4
+ *
5
+ * Per batch it takes the request the agent WOULD send if woken now (the
6
+ * framework's previewActivation, a dry run that commits nothing), renders it
7
+ * as one plain-text document (the agent's system prompt, abridged, then its
8
+ * conversation, oldest first), keeps the newest part of that document that
9
+ * fits the judge's input budget, and asks the model, with the agent's own
10
+ * instructions and the batch, for one line: `REPLY: <reason>` or
11
+ * `WAIT: <reason>`.
12
+ *
13
+ * Cost and latency. The budget (`maxInputTokens`, default 90,000) keeps every
14
+ * request under the 100,000-token line past which Claude Haiku 5.5 costs five
15
+ * times as much. Tokens are estimated from characters, at a ratio the judge
16
+ * corrects from every response's reported input, so the estimate tracks the
17
+ * model's tokenizer and the context's mix of prose and code. The document is
18
+ * sent as a run of chunks that start at an anchor, the first message shown,
19
+ * which stays put while the window grows into its budget: the chunks before
20
+ * the newest stay byte-identical from one request to the next, and a cache
21
+ * breakpoint after the last full one lets every later request read them from
22
+ * the prompt cache. Only when the window outgrows its budget does the anchor
23
+ * move, to leave the window a share of the budget to grow into again.
24
+ *
25
+ * The judge reads; it never writes into the agent's context and never speaks.
26
+ */
27
+ import { NativeFormatter } from '@animalabs/membrane';
28
+ /** The judge's model when the host names none. */
29
+ export const DEFAULT_JUDGE_MODEL = 'claude-haiku-5-5';
30
+ /** The judge's input budget when the host names none: under Haiku 5.5's 100K price line, with margin. */
31
+ export const DEFAULT_JUDGE_MAX_INPUT_TOKENS = 90_000;
32
+ /** The smallest input budget the judge takes: its instructions, the batch and a little context. A
33
+ * host that wants only the newest few messages read (a short tail, cheaper and quicker, with less
34
+ * of the room's history to weigh) sets a budget near it. */
35
+ export const MIN_JUDGE_INPUT_TOKENS = 4_000;
36
+ /** Characters per token the judge assumes before any response has told it better. Low, so a first estimate overshoots. */
37
+ const INITIAL_CHARS_PER_TOKEN = 3;
38
+ /** The share of each measured ratio the running estimate takes: more when the
39
+ * text proved denser than estimated (more tokens a character), which is the
40
+ * side that overruns the budget, less when sparser. */
41
+ const CALIBRATION_WEIGHT_DENSER = 0.6;
42
+ const CALIBRATION_WEIGHT_SPARSER = 0.2;
43
+ /** The share of the budget the system prompt (the agent's, abridged) may fill. */
44
+ const SYSTEM_SHARE = 0.08;
45
+ /** The share of the document budget a fresh window starts at, leaving the rest to grow into before the anchor moves. */
46
+ const FRESH_WINDOW_SHARE = 0.65;
47
+ /** Estimated tokens per cached chunk of the document: above every model's minimum cacheable prefix. */
48
+ const CHUNK_TOKENS = 6_000;
49
+ /** Tokens held back for the judge's own instructions, the batch and the question. */
50
+ const FIXED_TOKENS_RESERVE = 3_000;
51
+ /** Longest text block (characters) a message renders whole; a longer one keeps its head and tail. */
52
+ const MAX_TEXT_CHARS = 6_000;
53
+ /** Longest message (characters) rendered, all its blocks together. */
54
+ const MAX_MESSAGE_CHARS = 12_000;
55
+ /** Longest tool call input / tool result (characters) rendered. */
56
+ const MAX_TOOL_CHARS = 600;
57
+ /** Output tokens a verdict may take, adaptive thinking included: room enough
58
+ * that thinking at the model's default effort doesn't crowd out the line.
59
+ * Only what's generated is billed. */
60
+ const VERDICT_MAX_TOKENS = 4_096;
61
+ /** The share of the budget the batch's listing may fill; past it the oldest events are counted, not listed. */
62
+ const EVENTS_SHARE = 0.1;
63
+ /** The participant the judge's request names as the assistant: none of its messages is one. */
64
+ const JUDGE_PARTICIPANT = 'reply-judge';
65
+ /** A message as the document shows it: its participant, and each block as text. Thinking is the agent's own, and isn't shown. */
66
+ export function renderMessage(message) {
67
+ const parts = [];
68
+ for (const block of message.content) {
69
+ const line = renderBlock(block);
70
+ if (line)
71
+ parts.push(line);
72
+ }
73
+ if (parts.length === 0)
74
+ return '';
75
+ return cut(`[${message.participant}] ${parts.join('\n')}`, MAX_MESSAGE_CHARS);
76
+ }
77
+ function renderBlock(block) {
78
+ switch (block.type) {
79
+ case 'text':
80
+ return cut(block.text, MAX_TEXT_CHARS);
81
+ case 'image':
82
+ case 'generated_image':
83
+ return '[image]';
84
+ case 'document':
85
+ return '[document]';
86
+ case 'audio':
87
+ return '[audio]';
88
+ case 'video':
89
+ return '[video]';
90
+ case 'tool_use':
91
+ return `[calls ${block.name}] ${cut(safeJson(block.input), MAX_TOOL_CHARS)}`;
92
+ case 'tool_result': {
93
+ const body = typeof block.content === 'string'
94
+ ? block.content
95
+ : block.content.map((b) => (b.type === 'text' ? b.text : `[${b.type}]`)).join('\n');
96
+ return `[${block.toolName ?? 'tool'} ${block.isError ? 'failed' : 'returned'}] ${cut(body, MAX_TOOL_CHARS)}`;
97
+ }
98
+ default:
99
+ // thinking, redacted thinking, system changes: not the conversation.
100
+ return '';
101
+ }
102
+ }
103
+ function safeJson(value) {
104
+ try {
105
+ return JSON.stringify(value) ?? '';
106
+ }
107
+ catch {
108
+ return String(value);
109
+ }
110
+ }
111
+ /** Text no longer than `max` characters: a longer one keeps its head and tail, the middle named as cut. */
112
+ export function cut(text, max) {
113
+ if (text.length <= max)
114
+ return text;
115
+ const keep = Math.floor((max - 40) / 2);
116
+ return `${text.slice(0, keep)} […${text.length - 2 * keep} characters cut…] ${text.slice(-keep)}`;
117
+ }
118
+ /** A cheap, stable key for an entry (FNV-1a over its text, with its length). */
119
+ function keyOf(text) {
120
+ let h = 0x811c9dc5;
121
+ for (let i = 0; i < text.length; i++) {
122
+ h ^= text.charCodeAt(i);
123
+ h = Math.imul(h, 0x01000193);
124
+ }
125
+ return `${(h >>> 0).toString(36)}:${text.length}`;
126
+ }
127
+ /** The text of a system prompt, as membrane's request may hold it. */
128
+ function systemText(system) {
129
+ if (typeof system === 'string')
130
+ return system;
131
+ if (Array.isArray(system)) {
132
+ return system.map((b) => (b && typeof b === 'object' && typeof b.text === 'string' ? b.text : '')).join('\n');
133
+ }
134
+ return '';
135
+ }
136
+ /** In how long, as the judge is told an upcoming wake. */
137
+ function inWhile(at, now) {
138
+ if (at === undefined)
139
+ return 'as soon as it is free';
140
+ const s = Math.max(0, Math.round((at - now) / 1000));
141
+ if (s < 90)
142
+ return `in ${s} s`;
143
+ const m = Math.round(s / 60);
144
+ if (m < 90)
145
+ return `in ${m} min`;
146
+ const h = Math.floor(m / 60);
147
+ return `in ${h} h${m % 60 ? ` ${m % 60} min` : ''}`;
148
+ }
149
+ /**
150
+ * What waiting would leave the agent with: what wakes it anyway, soonest
151
+ * first, or that nothing the host knows of is scheduled. A server's own
152
+ * timers (a heartbeat, a reminder) are listed only where the host was told
153
+ * of them, so the empty case says so.
154
+ */
155
+ export function ifYouWait(wakes, agentName, now) {
156
+ const sorted = [...wakes].sort((a, b) => (a.at ?? now) - (b.at ?? now));
157
+ const lines = sorted.slice(0, 8).map((w) => `- ${inWhile(w.at, now)}${w.certain ? '' : ', maybe'}: ${w.what}`);
158
+ const more = sorted.length > 8 ? [`- and ${sorted.length - 8} more`] : [];
159
+ return [
160
+ '<if_you_wait>',
161
+ ...(lines.length > 0
162
+ ? [`If you answer WAIT and nothing new arrives, ${agentName} is next woken by:`, ...lines, ...more]
163
+ : [`Nothing the host knows of is scheduled to wake ${agentName}: if you answer WAIT, it isn't woken until a new event arrives (a server's own timers, such as a heartbeat, may not be listed).`]),
164
+ '</if_you_wait>',
165
+ ].join('\n');
166
+ }
167
+ /** Seconds or minutes ago, as the batch shows each event. */
168
+ function ago(at, now) {
169
+ const s = Math.max(0, Math.round((now - at) / 1000));
170
+ return s < 120 ? `${s}s ago` : `${Math.round(s / 60)}m ago`;
171
+ }
172
+ /**
173
+ * The verdict in a response's text: its last line that starts with REPLY or
174
+ * WAIT in capitals followed by a colon or a dash, as the judge is asked to
175
+ * write it. A capital word without one, or a lower-case "reply" or "wait" in
176
+ * the judge's reasoning ("Wait, they did ask"), isn't a verdict.
177
+ */
178
+ export function parseVerdict(text) {
179
+ const re = /^[\s*_>`#]*(REPLY|WAIT)[*_`]*\s*[:\-–—]\s*(.*)$/gm;
180
+ let last;
181
+ for (let m = re.exec(text); m; m = re.exec(text))
182
+ last = m;
183
+ if (!last)
184
+ return undefined;
185
+ return { reply: last[1] === 'REPLY', reason: last[2].trim().replace(/^[*_`]+|[*_`]+$/g, '').trim() };
186
+ }
187
+ /** The judge's own system prompt: stable per agent, so it caches. */
188
+ export function judgeSystemPrompt(agentName) {
189
+ return [
190
+ `You are the reply judge for an AI agent named ${agentName}. The agent isn't woken for every message: when new`,
191
+ 'events arrive, you decide whether now is a good time to wake it so it can respond. Waking it costs it a turn;',
192
+ "letting the events go by means it won't act on them until something else wakes it (they stay in its context,",
193
+ 'so it will see them then).',
194
+ '',
195
+ "You're given the agent's context as a document: its conversation, oldest first, cut from the oldest end to",
196
+ "fit, then its system prompt (abridged). The agent's own messages are those from the participant named",
197
+ `${agentName}. Then you're given the new events and, when it has written them, the agent's own instructions to you.`,
198
+ "Its instructions are its preferences about its own attention and come first. Where they don't decide, wake it",
199
+ 'when it is addressed or asked something, when a reply from it is expected or would clearly help, or when',
200
+ 'something it is following needs it; let events go by when the talk is between others and does not need it,',
201
+ 'when it has already answered, or when replying would only add noise.',
202
+ '',
203
+ "You're also told what will wake the agent anyway if you let the events go by. Waiting costs little when it",
204
+ "will be woken soon regardless; when nothing is scheduled, waiting means it may not see these events for a",
205
+ 'long time, so weigh how much they matter.',
206
+ '',
207
+ "Don't answer the messages yourself and don't speak as the agent. Answer with exactly one line:",
208
+ '"REPLY: <a short reason>" to wake it, or "WAIT: <a short reason>" to let the events go by.',
209
+ ].join('\n');
210
+ }
211
+ /** The closing message: the batch, the agent's instructions, the question. */
212
+ export function judgeQuestion(request, agentName, now, maxEventChars = Infinity) {
213
+ // Newest first into the listing's share, shown oldest first; the rest are
214
+ // counted, so a long held batch can't crowd out the context.
215
+ const lines = [];
216
+ let used = 0;
217
+ let i = request.events.length;
218
+ while (i > 0) {
219
+ const e = request.events[i - 1];
220
+ const where = e.channel ? ` in ${e.channel}` : '';
221
+ const who = e.authorId ? ` from ${e.authorId}` : '';
222
+ const addressed = e.addressed ? ' (addresses the agent)' : '';
223
+ const line = `- ${ago(e.at, now)}${where}${who}${addressed}: ${e.content}`;
224
+ if (lines.length > 0 && used + line.length > maxEventChars)
225
+ break;
226
+ lines.unshift(line);
227
+ used += line.length + 1;
228
+ i--;
229
+ }
230
+ const parts = [
231
+ `<new_events count="${request.events.length}">`,
232
+ ...(i > 0 ? [`- (${i} earlier ${i === 1 ? 'event' : 'events'} in this batch not listed)`] : []),
233
+ ...lines,
234
+ '</new_events>',
235
+ ];
236
+ parts.push('', ifYouWait(request.upcomingWakes ?? [], agentName, now));
237
+ if (request.instructions && request.instructions.trim()) {
238
+ parts.push('', `<instructions_from_${agentName.replace(/[^A-Za-z0-9_-]/g, '_')}>`, request.instructions.trim(), '</instructions_from_' + agentName.replace(/[^A-Za-z0-9_-]/g, '_') + '>');
239
+ }
240
+ parts.push('', `Should ${agentName} be woken now to respond? One line: "REPLY: <reason>" or "WAIT: <reason>".`);
241
+ return parts.join('\n');
242
+ }
243
+ export class ReplyJudge {
244
+ membraneFor;
245
+ cacheTtl;
246
+ model;
247
+ maxInputTokens;
248
+ effort;
249
+ chooseAgent;
250
+ preview;
251
+ recordUsage;
252
+ extraWakes;
253
+ /** Characters per token, corrected from each response's reported input. */
254
+ charsPerToken = INITIAL_CHARS_PER_TOKEN;
255
+ anchors = new Map();
256
+ constructor(deps) {
257
+ this.membraneFor = deps.membraneFor;
258
+ this.cacheTtl = deps.options?.cacheTtl === '1h' ? '1h' : '5m';
259
+ this.model = deps.options?.model || DEFAULT_JUDGE_MODEL;
260
+ const max = deps.options?.maxInputTokens;
261
+ if (max === undefined) {
262
+ this.maxInputTokens = DEFAULT_JUDGE_MAX_INPUT_TOKENS;
263
+ }
264
+ else if (typeof max !== 'number' || !Number.isFinite(max)) {
265
+ this.maxInputTokens = DEFAULT_JUDGE_MAX_INPUT_TOKENS;
266
+ console.error(`[gate] the reply judge's maxInputTokens isn't a number, so it's read as ${DEFAULT_JUDGE_MAX_INPUT_TOKENS}`);
267
+ }
268
+ else if (max < MIN_JUDGE_INPUT_TOKENS) {
269
+ // At its nearest bound, as the gate reads a value out of range: a small
270
+ // budget set to save money stays small.
271
+ this.maxInputTokens = MIN_JUDGE_INPUT_TOKENS;
272
+ console.error(`[gate] the reply judge's maxInputTokens is ${max}, under the ${MIN_JUDGE_INPUT_TOKENS} minimum, so it's read as ${MIN_JUDGE_INPUT_TOKENS}`);
273
+ }
274
+ else {
275
+ this.maxInputTokens = Math.floor(max);
276
+ }
277
+ this.effort = deps.options?.effort ?? 'low';
278
+ this.chooseAgent = deps.chooseAgent;
279
+ this.preview = deps.preview;
280
+ this.recordUsage = deps.recordUsage;
281
+ this.extraWakes = deps.upcomingWakes;
282
+ }
283
+ /** The gate's judge function. */
284
+ judge = async (request) => this.decide(request);
285
+ /** The ratio the judge estimates tokens by now (for tests and status). */
286
+ estimateRatio() {
287
+ return this.charsPerToken;
288
+ }
289
+ tokens(chars) {
290
+ return Math.ceil(chars / this.charsPerToken);
291
+ }
292
+ /** Build the judge's request for one batch: the system prompt, the document in chunks, the question. */
293
+ async buildRequest(request, now = Date.now()) {
294
+ const agentName = this.chooseAgent(request.agentNames);
295
+ if (!agentName)
296
+ throw new Error('no agent to judge for');
297
+ const preview = await this.preview(agentName);
298
+ if (request.signal.aborted)
299
+ throw new Error('the judge was stopped before its request');
300
+ let extra = [];
301
+ try {
302
+ extra = (await this.extraWakes?.(agentName)) ?? [];
303
+ }
304
+ catch {
305
+ extra = [];
306
+ }
307
+ const upcoming = [...(request.upcomingWakes ?? []), ...extra];
308
+ const system = judgeSystemPrompt(agentName);
309
+ const question = judgeQuestion({ ...request, upcomingWakes: upcoming }, agentName, now, Math.floor(this.maxInputTokens * EVENTS_SHARE * this.charsPerToken));
310
+ const fixedChars = system.length + question.length;
311
+ // The budget the document may fill, in characters at the current ratio.
312
+ const docTokens = Math.max(1_000, this.maxInputTokens - FIXED_TOKENS_RESERVE - this.tokens(fixedChars));
313
+ const docChars = Math.floor(docTokens * this.charsPerToken);
314
+ // The agent's system prompt comes after the conversation, just before the
315
+ // question: a system prompt that changes between requests (a host that
316
+ // writes the time or a status into it) then costs only its own tokens,
317
+ // not the cached conversation before it.
318
+ const agentSystem = systemText(preview.system);
319
+ const systemChars = Math.floor(docChars * SYSTEM_SHARE);
320
+ const about = [
321
+ `## ${agentName}'s system prompt${agentSystem.length > systemChars ? ' (abridged)' : ''}`,
322
+ '',
323
+ agentSystem ? cut(agentSystem, systemChars) : '(none)',
324
+ ].join('\n');
325
+ const header = `# ${agentName}'s context\n\n## Conversation (oldest shown first)`;
326
+ const entries = [];
327
+ for (const message of preview.messages) {
328
+ const text = renderMessage(message);
329
+ if (text)
330
+ entries.push({ text, key: keyOf(text) });
331
+ }
332
+ const windowChars = Math.max(0, docChars - header.length - about.length);
333
+ const start = this.windowStart(agentName, entries, windowChars);
334
+ const shown = entries.slice(start);
335
+ if (shown.length > 0) {
336
+ this.anchors.set(agentName, { keys: shown.slice(0, 3).map((e) => e.key) });
337
+ }
338
+ // Chunks of whole messages from the anchor, each closed at CHUNK_TOKENS:
339
+ // the same entries from the same anchor make the same chunks, so every
340
+ // chunk before the open one is the same bytes as last time.
341
+ const chunkChars = CHUNK_TOKENS * INITIAL_CHARS_PER_TOKEN;
342
+ const chunks = [];
343
+ let current = start > 0 ? `${header}\n[…earlier messages not shown…]\n\n` : `${header}\n\n`;
344
+ for (const entry of shown) {
345
+ if (current.length + entry.text.length > chunkChars && current.length > 0) {
346
+ chunks.push(current);
347
+ current = '';
348
+ }
349
+ current += `${entry.text}\n\n`;
350
+ }
351
+ const open = current;
352
+ const messages = chunks.map((text, i) => ({
353
+ participant: 'user',
354
+ content: [{ type: 'text', text }],
355
+ // After the last closed chunk: the prefix every later request shares.
356
+ ...(i === chunks.length - 1 ? { cacheBreakpoint: true } : {}),
357
+ }));
358
+ if (open)
359
+ messages.push({ participant: 'user', content: [{ type: 'text', text: open }] });
360
+ messages.push({ participant: 'user', content: [{ type: 'text', text: about }] });
361
+ messages.push({ participant: 'user', content: [{ type: 'text', text: question }] });
362
+ const chars = system.length + messages.reduce((n, m) => n + m.content[0].text.length, 0);
363
+ return {
364
+ agentName,
365
+ chars,
366
+ request: {
367
+ system,
368
+ messages,
369
+ config: { model: this.model, maxTokens: VERDICT_MAX_TOKENS },
370
+ assistantParticipant: JUDGE_PARTICIPANT,
371
+ promptCaching: true,
372
+ cacheTtl: this.cacheTtl,
373
+ ...(this.effort !== 'none' ? { providerParams: { output_config: { effort: this.effort } } } : {}),
374
+ },
375
+ };
376
+ }
377
+ /**
378
+ * Where the window starts: at last request's anchor, while the window from
379
+ * there fits; otherwise where the newest messages fill FRESH_WINDOW_SHARE
380
+ * of the budget, leaving room to grow before it moves again.
381
+ */
382
+ windowStart(agentName, entries, windowChars) {
383
+ const tailFrom = (budget) => {
384
+ let used = 0;
385
+ let i = entries.length;
386
+ while (i > 0 && used + entries[i - 1].text.length + 2 <= budget) {
387
+ used += entries[i - 1].text.length + 2;
388
+ i--;
389
+ }
390
+ // The newest message is shown even when it alone is over budget (it's cut to MAX_MESSAGE_CHARS already).
391
+ return Math.min(i, Math.max(0, entries.length - 1));
392
+ };
393
+ const anchor = this.anchors.get(agentName);
394
+ if (anchor && anchor.keys.length > 0) {
395
+ const at = this.findAnchor(entries, anchor.keys);
396
+ if (at !== undefined) {
397
+ let size = 0;
398
+ for (let i = at; i < entries.length; i++)
399
+ size += entries[i].text.length + 2;
400
+ if (size <= windowChars)
401
+ return at;
402
+ }
403
+ }
404
+ return tailFrom(Math.floor(windowChars * FRESH_WINDOW_SHARE));
405
+ }
406
+ findAnchor(entries, keys) {
407
+ for (let i = 0; i + keys.length <= entries.length; i++) {
408
+ let all = true;
409
+ for (let k = 0; k < keys.length; k++) {
410
+ if (entries[i + k].key !== keys[k]) {
411
+ all = false;
412
+ break;
413
+ }
414
+ }
415
+ if (all)
416
+ return i;
417
+ }
418
+ return undefined;
419
+ }
420
+ /** Learn the tokenizer's ratio from one response, leaning conservative after an overshoot. */
421
+ calibrate(chars, inputTokens) {
422
+ if (!(inputTokens > 0) || !(chars > 0))
423
+ return;
424
+ const measured = chars / inputTokens;
425
+ const weight = measured < this.charsPerToken ? CALIBRATION_WEIGHT_DENSER : CALIBRATION_WEIGHT_SPARSER;
426
+ const next = this.charsPerToken * (1 - weight) + measured * weight;
427
+ // Over budget: take the measured ratio at once, with a margin, rather than drift toward it.
428
+ this.charsPerToken = inputTokens > this.maxInputTokens ? Math.min(next, measured * 0.9) : next;
429
+ this.charsPerToken = Math.min(6, Math.max(1, this.charsPerToken));
430
+ }
431
+ async decide(request) {
432
+ const built = await this.buildRequest(request);
433
+ // The native formatter whatever the host's agents use: an XML or
434
+ // completions formatter would end the judge's request in a prefill, which
435
+ // current Claude models refuse.
436
+ const response = await this.membraneFor(built.agentName).complete(built.request, {
437
+ signal: request.signal,
438
+ formatter: new NativeFormatter(),
439
+ });
440
+ const usage = response.details?.usage;
441
+ if (usage)
442
+ this.recordUsage?.(built.agentName, usage);
443
+ const inputTokens = (response.usage?.inputTokens ?? 0) + (usage?.cacheReadTokens ?? 0) + (usage?.cacheCreationTokens ?? 0);
444
+ this.calibrate(built.chars, inputTokens);
445
+ if (inputTokens > this.maxInputTokens) {
446
+ console.error(`[gate] the reply judge's request carried ${inputTokens} input tokens, over its ${this.maxInputTokens} budget; `
447
+ + `its estimate is now ${this.charsPerToken.toFixed(2)} characters a token`);
448
+ }
449
+ const text = response.content
450
+ .filter((b) => b.type === 'text')
451
+ .map((b) => b.text)
452
+ .join('\n');
453
+ const verdict = parseVerdict(text);
454
+ if (!verdict) {
455
+ const stop = response.stopReason;
456
+ throw new Error(`the judge's answer held no verdict (stop: ${stop}${text ? `, text: ${JSON.stringify(cut(text, 120))}` : ''})`);
457
+ }
458
+ return {
459
+ ...verdict,
460
+ model: response.details?.model?.actual || this.model,
461
+ inputTokens,
462
+ ...(usage?.cacheReadTokens !== undefined ? { cacheReadTokens: usage.cacheReadTokens } : {}),
463
+ outputTokens: response.usage?.outputTokens,
464
+ };
465
+ }
466
+ }
467
+ //# sourceMappingURL=reply-judge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reply-judge.js","sourceRoot":"","sources":["../../../src/gate/reply-judge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAItD,kDAAkD;AAClD,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AACtD,yGAAyG;AACzG,MAAM,CAAC,MAAM,8BAA8B,GAAG,MAAM,CAAC;AACrD;;6DAE6D;AAC7D,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAE5C,0HAA0H;AAC1H,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAClC;;wDAEwD;AACxD,MAAM,yBAAyB,GAAG,GAAG,CAAC;AACtC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AACvC,kFAAkF;AAClF,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,wHAAwH;AACxH,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,uGAAuG;AACvG,MAAM,YAAY,GAAG,KAAK,CAAC;AAC3B,qFAAqF;AACrF,MAAM,oBAAoB,GAAG,KAAK,CAAC;AACnC,qGAAqG;AACrG,MAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,sEAAsE;AACtE,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACjC,mEAAmE;AACnE,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B;;uCAEuC;AACvC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACjC,+GAA+G;AAC/G,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,+FAA+F;AAC/F,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAiCxC,iIAAiI;AACjI,MAAM,UAAU,aAAa,CAAC,OAA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