agentix-cli 0.154.0 → 0.154.2

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 (121) hide show
  1. package/dist/{App-OL5GYZBS.js → App-6T6NVB7O.js} +2 -2
  2. package/dist/{ChatApp-EEHKOZQX.js → ChatApp-QZBJ4NHC.js} +2 -2
  3. package/dist/{absorb-eval-PVCA7UE6.js → absorb-eval-EVX7LDXR.js} +2 -2
  4. package/dist/{agent-3ETFZSEZ.js → agent-F2NT6B25.js} +2 -2
  5. package/dist/{board-dashboard-RUO6R5NI.js → board-dashboard-642BO7GV.js} +4 -4
  6. package/dist/{chunk-GDNKUNT7.js → chunk-37I654UJ.js} +2 -2
  7. package/dist/{chunk-BMZK232D.js → chunk-4CWACHEH.js} +2 -2
  8. package/dist/{chunk-CJKN4APJ.js → chunk-67DWBJEO.js} +5 -5
  9. package/dist/{chunk-FFPQS2C4.js → chunk-743RAKLP.js} +2 -2
  10. package/dist/{chunk-M5TMFCPA.js → chunk-ABCQ6QMJ.js} +2 -2
  11. package/dist/{chunk-HOLJZIVJ.js → chunk-AKCEMKQM.js} +2 -2
  12. package/dist/{chunk-HF55LKFC.js → chunk-B75BLZ2M.js} +2 -2
  13. package/dist/{chunk-TDMX6HTT.js → chunk-CUAS4ITR.js} +2 -2
  14. package/dist/{chunk-U3PHNPIJ.js → chunk-E76HREC7.js} +3 -3
  15. package/dist/{chunk-ABKEGNY4.js → chunk-EGTANAFI.js} +2 -2
  16. package/dist/{chunk-2FH4TULF.js → chunk-GFRAHUAQ.js} +2 -2
  17. package/dist/{chunk-NUMWHIFL.js → chunk-GRVTLUQ6.js} +2 -2
  18. package/dist/{chunk-4FKFEWCE.js → chunk-HSCZSNOX.js} +2 -2
  19. package/dist/{chunk-5NTEGDXT.js → chunk-HUN6COOF.js} +2 -2
  20. package/dist/{chunk-VCAVVCXT.js → chunk-IA4J3YLB.js} +2 -2
  21. package/dist/{chunk-RTXFDYFR.js → chunk-IWWEUXZQ.js} +2 -2
  22. package/dist/{chunk-RARXW4KB.js → chunk-KA2NV7H4.js} +2 -2
  23. package/dist/{chunk-NKTBJHIF.js → chunk-MLC5INGD.js} +5 -5
  24. package/dist/{chunk-F5KWRBTF.js → chunk-S3EX64LR.js} +2 -2
  25. package/dist/{chunk-IYL4YUXQ.js → chunk-SD3CC4EX.js} +2 -2
  26. package/dist/{chunk-IRDPIQRR.js → chunk-U4YTTWR6.js} +2 -2
  27. package/dist/{chunk-GVJMPSE2.js → chunk-VKEH4IBA.js} +16 -16
  28. package/dist/chunk-VKEH4IBA.js.map +1 -0
  29. package/dist/{chunk-JXY7EEAR.js → chunk-VRF4YW46.js} +2 -2
  30. package/dist/{chunk-USCFJVVI.js → chunk-W2RB5XG7.js} +2 -2
  31. package/dist/{chunk-2K2QDTGP.js → chunk-XOUK5ZIQ.js} +2 -2
  32. package/dist/{chunk-MKIJAGES.js → chunk-YJNUVAM4.js} +2 -2
  33. package/dist/{chunk-UWUJVING.js → chunk-YL26FRKJ.js} +2 -2
  34. package/dist/cli.js +1 -1
  35. package/dist/{client-WBAWHYAY.js → client-OCLSGJYQ.js} +2 -2
  36. package/dist/{config-VXXKMXHH.js → config-FZTWI3VG.js} +2 -2
  37. package/dist/{config-mutate-MMTHEXWM.js → config-mutate-X5IKMROK.js} +2 -2
  38. package/dist/config-mutator-C5BMIBZO.js +2 -0
  39. package/dist/{contributions-3ZE2TK24.js → contributions-KHGGVSR6.js} +2 -2
  40. package/dist/{doctor-TP4GSLZV.js → doctor-KNCRQ3YO.js} +2 -2
  41. package/dist/{follow-up-tool-L3QXZIU2.js → follow-up-tool-TGKEPA5C.js} +2 -2
  42. package/dist/{hub-U65U7SE6.js → hub-HQUAH5H6.js} +2 -2
  43. package/dist/index.js +1 -1
  44. package/dist/{program-7WISM624.js → program-CYOAZ43O.js} +23 -23
  45. package/dist/{promote-GP2MZX7S.js → promote-VD4OVQGL.js} +2 -2
  46. package/dist/{query-WHNB46XD.js → query-5CPK6G2H.js} +2 -2
  47. package/dist/{query-settings-U5ZMQREP.js → query-settings-35GDM3HU.js} +2 -2
  48. package/dist/{registry-GXGHPROE.js → registry-JCHKHCRE.js} +2 -2
  49. package/dist/{request-planner-HALSGCA5.js → request-planner-ZIG4YVXC.js} +2 -2
  50. package/dist/{review-candidates-WIXZZCF7.js → review-candidates-LPZWOR2K.js} +2 -2
  51. package/dist/{routing-U543HNNU.js → routing-BLOYDLU4.js} +2 -2
  52. package/dist/schedule-tool-7KFO3NPD.js +2 -0
  53. package/dist/{scheduler-OEKYXZPJ.js → scheduler-BEJRDQR3.js} +2 -2
  54. package/dist/{seat-FWF2HKWS.js → seat-NU3UJC6C.js} +2 -2
  55. package/dist/{select-QDSG7NQX.js → select-IWAFX4XJ.js} +2 -2
  56. package/dist/{set-enabled-W7U5SXYX.js → set-enabled-JF75TSFU.js} +2 -2
  57. package/dist/{tool-VN7W6QGC.js → tool-PQBQJWM5.js} +2 -2
  58. package/dist/{tool-QIFV7Q4M.js → tool-WTOOPTGC.js} +2 -2
  59. package/dist/{wiki-TN5WFJ5P.js → wiki-DXG655NP.js} +2 -2
  60. package/dist/wiki-enrich-5VQCT6BT.js +2 -0
  61. package/package.json +2 -1
  62. package/dist/chunk-GVJMPSE2.js.map +0 -1
  63. package/dist/config-mutator-R75BQXMB.js +0 -2
  64. package/dist/schedule-tool-FIKDTGXF.js +0 -2
  65. package/dist/wiki-enrich-GEHA6NJQ.js +0 -2
  66. /package/dist/{App-OL5GYZBS.js.map → App-6T6NVB7O.js.map} +0 -0
  67. /package/dist/{ChatApp-EEHKOZQX.js.map → ChatApp-QZBJ4NHC.js.map} +0 -0
  68. /package/dist/{absorb-eval-PVCA7UE6.js.map → absorb-eval-EVX7LDXR.js.map} +0 -0
  69. /package/dist/{agent-3ETFZSEZ.js.map → agent-F2NT6B25.js.map} +0 -0
  70. /package/dist/{board-dashboard-RUO6R5NI.js.map → board-dashboard-642BO7GV.js.map} +0 -0
  71. /package/dist/{chunk-GDNKUNT7.js.map → chunk-37I654UJ.js.map} +0 -0
  72. /package/dist/{chunk-BMZK232D.js.map → chunk-4CWACHEH.js.map} +0 -0
  73. /package/dist/{chunk-CJKN4APJ.js.map → chunk-67DWBJEO.js.map} +0 -0
  74. /package/dist/{chunk-FFPQS2C4.js.map → chunk-743RAKLP.js.map} +0 -0
  75. /package/dist/{chunk-M5TMFCPA.js.map → chunk-ABCQ6QMJ.js.map} +0 -0
  76. /package/dist/{chunk-HOLJZIVJ.js.map → chunk-AKCEMKQM.js.map} +0 -0
  77. /package/dist/{chunk-HF55LKFC.js.map → chunk-B75BLZ2M.js.map} +0 -0
  78. /package/dist/{chunk-TDMX6HTT.js.map → chunk-CUAS4ITR.js.map} +0 -0
  79. /package/dist/{chunk-U3PHNPIJ.js.map → chunk-E76HREC7.js.map} +0 -0
  80. /package/dist/{chunk-ABKEGNY4.js.map → chunk-EGTANAFI.js.map} +0 -0
  81. /package/dist/{chunk-2FH4TULF.js.map → chunk-GFRAHUAQ.js.map} +0 -0
  82. /package/dist/{chunk-NUMWHIFL.js.map → chunk-GRVTLUQ6.js.map} +0 -0
  83. /package/dist/{chunk-4FKFEWCE.js.map → chunk-HSCZSNOX.js.map} +0 -0
  84. /package/dist/{chunk-5NTEGDXT.js.map → chunk-HUN6COOF.js.map} +0 -0
  85. /package/dist/{chunk-VCAVVCXT.js.map → chunk-IA4J3YLB.js.map} +0 -0
  86. /package/dist/{chunk-RTXFDYFR.js.map → chunk-IWWEUXZQ.js.map} +0 -0
  87. /package/dist/{chunk-RARXW4KB.js.map → chunk-KA2NV7H4.js.map} +0 -0
  88. /package/dist/{chunk-NKTBJHIF.js.map → chunk-MLC5INGD.js.map} +0 -0
  89. /package/dist/{chunk-F5KWRBTF.js.map → chunk-S3EX64LR.js.map} +0 -0
  90. /package/dist/{chunk-IYL4YUXQ.js.map → chunk-SD3CC4EX.js.map} +0 -0
  91. /package/dist/{chunk-IRDPIQRR.js.map → chunk-U4YTTWR6.js.map} +0 -0
  92. /package/dist/{chunk-JXY7EEAR.js.map → chunk-VRF4YW46.js.map} +0 -0
  93. /package/dist/{chunk-USCFJVVI.js.map → chunk-W2RB5XG7.js.map} +0 -0
  94. /package/dist/{chunk-2K2QDTGP.js.map → chunk-XOUK5ZIQ.js.map} +0 -0
  95. /package/dist/{chunk-MKIJAGES.js.map → chunk-YJNUVAM4.js.map} +0 -0
  96. /package/dist/{chunk-UWUJVING.js.map → chunk-YL26FRKJ.js.map} +0 -0
  97. /package/dist/{client-WBAWHYAY.js.map → client-OCLSGJYQ.js.map} +0 -0
  98. /package/dist/{config-VXXKMXHH.js.map → config-FZTWI3VG.js.map} +0 -0
  99. /package/dist/{config-mutate-MMTHEXWM.js.map → config-mutate-X5IKMROK.js.map} +0 -0
  100. /package/dist/{config-mutator-R75BQXMB.js.map → config-mutator-C5BMIBZO.js.map} +0 -0
  101. /package/dist/{contributions-3ZE2TK24.js.map → contributions-KHGGVSR6.js.map} +0 -0
  102. /package/dist/{doctor-TP4GSLZV.js.map → doctor-KNCRQ3YO.js.map} +0 -0
  103. /package/dist/{follow-up-tool-L3QXZIU2.js.map → follow-up-tool-TGKEPA5C.js.map} +0 -0
  104. /package/dist/{hub-U65U7SE6.js.map → hub-HQUAH5H6.js.map} +0 -0
  105. /package/dist/{program-7WISM624.js.map → program-CYOAZ43O.js.map} +0 -0
  106. /package/dist/{promote-GP2MZX7S.js.map → promote-VD4OVQGL.js.map} +0 -0
  107. /package/dist/{query-WHNB46XD.js.map → query-5CPK6G2H.js.map} +0 -0
  108. /package/dist/{query-settings-U5ZMQREP.js.map → query-settings-35GDM3HU.js.map} +0 -0
  109. /package/dist/{registry-GXGHPROE.js.map → registry-JCHKHCRE.js.map} +0 -0
  110. /package/dist/{request-planner-HALSGCA5.js.map → request-planner-ZIG4YVXC.js.map} +0 -0
  111. /package/dist/{review-candidates-WIXZZCF7.js.map → review-candidates-LPZWOR2K.js.map} +0 -0
  112. /package/dist/{routing-U543HNNU.js.map → routing-BLOYDLU4.js.map} +0 -0
  113. /package/dist/{schedule-tool-FIKDTGXF.js.map → schedule-tool-7KFO3NPD.js.map} +0 -0
  114. /package/dist/{scheduler-OEKYXZPJ.js.map → scheduler-BEJRDQR3.js.map} +0 -0
  115. /package/dist/{seat-FWF2HKWS.js.map → seat-NU3UJC6C.js.map} +0 -0
  116. /package/dist/{select-QDSG7NQX.js.map → select-IWAFX4XJ.js.map} +0 -0
  117. /package/dist/{set-enabled-W7U5SXYX.js.map → set-enabled-JF75TSFU.js.map} +0 -0
  118. /package/dist/{tool-VN7W6QGC.js.map → tool-PQBQJWM5.js.map} +0 -0
  119. /package/dist/{tool-QIFV7Q4M.js.map → tool-WTOOPTGC.js.map} +0 -0
  120. /package/dist/{wiki-TN5WFJ5P.js.map → wiki-DXG655NP.js.map} +0 -0
  121. /package/dist/{wiki-enrich-GEHA6NJQ.js.map → wiki-enrich-5VQCT6BT.js.map} +0 -0
@@ -1,4 +1,4 @@
1
- import{A as Lo,Ba as Mg,D as Hh,F as Ss,Fa as Og,Ga as Rs,H as sg,Ha as Bo,Ia as Dg,Ja as Ng,K as rg,Ka as Lg,La as jg,M as ig,Na as Fg,O as og,P as Fo,Q as ag,R as Ke,S as cg,T as $s,Ua as Wg,V as Wo,Va as Ug,W as dg,X as Go,Y as ct,Z as wg,_ as kg,a as gh,b as Eo,ba as dt,ca as bg,cb as qo,da as vg,db as Xo,ea as Sg,f as Co,fa as $g,fb as Gg,g as ph,ga as Ig,h as fh,ha as Tg,i as Je,j as mh,ja as Se,k as yh,ka as Is,la as Ho,m as wh,ma as xg,na as fn,o as kh,oa as Rg,p as Nt,pa as Oe,q as _o,qa as Ag,r as Oh,ra as Eg,s as Dh,sa as Cg,t as Nh,ta as Ts,u as Lh,ua as xs,v as jh,va as Pg,w as Fh,wa as _g,x as Wh,y as Uh,z as Gh}from"./chunk-4FKFEWCE.js";import{d as lh,g as uh,h as hh}from"./chunk-2FH4TULF.js";import{B as ys,C as Mo,D as ws,E as Lt,I as Bh,c as eh,e as th,f as nh,g as ms,h as Ro,i as sh,j as Xe,x as $h,y as Ih,z as Th}from"./chunk-2K2QDTGP.js";import{b as yg}from"./chunk-7LN4VKDU.js";import{a as bh}from"./chunk-ZVP6GB4G.js";import{g as Rh}from"./chunk-LQE73AZR.js";import{b as Ah,c as Eh}from"./chunk-2D3RYIDU.js";import{b as qh}from"./chunk-MRIVENBY.js";import{i as Xh,m as jo,n as Vh,p as Jh,q as Kh,r as zh,s as Yh,t as Qh,u as Zh}from"./chunk-BNOGNRAM.js";import{e as Oo,k as Do,l as Ch,m as bs,n as jt,o as Ft,p as Me,r as Ph,s as _h,t as Mh,u as No,v as vs}from"./chunk-LQS27HSV.js";import{a as eg}from"./chunk-PPUN7YHA.js";import{a as tg,b as ng}from"./chunk-VZLIBDLH.js";import{b as lg,c as ug,d as Uo,e as hg,f as gg,g as pg,h as fg,i as mg}from"./chunk-EKJG63EJ.js";import{o as Po}from"./chunk-F5KWRBTF.js";import{b as ks}from"./chunk-EMGB23H5.js";import{d as xh}from"./chunk-JAML6222.js";import{a as Ve}from"./chunk-MNG2AMKZ.js";import{b as ch,c as dh}from"./chunk-X7UQY7CH.js";import{a as rh,b as at,c as ih,d as oh,e as ah}from"./chunk-PYHR4HXO.js";import{c as Dt}from"./chunk-KP7KDLZ2.js";import{a as vh,b as Sh}from"./chunk-A5GYG56I.js";import{$ as ps,B as Xl,C as Vl,D as Jl,E as Kl,F as ge,G as Yl,H as Ql,I as Zl,J as eu,K as tu,L as nu,M as su,N as Uu,O as Gu,P as Hu,Q as Bu,R as qu,S as Xu,U as pn,V as Vu,W as pe,X as qe,Y as To,Z as _t,_ as xo,a as wl,aa as Mt,b as po,ba as Ot,c as bl,ca as me,d as Al,da as ot,e as El,ea as oe,f as hn,h as mo,ha as zu,i as yo,j as wo,k as ko,l as Cl,ra as Yu,s as _l,t as Dl,u as rt,v as Nl,w as Ll,x as Ct,y as Wl,z as X}from"./chunk-NKTBJHIF.js";import{A as Cu,B as Pu,C as _u,D as Mu,E as Ou,F as Du,H as Nu,K as Lu,P as ju,Q as Fu,T as Wu,X as Ju,a as Ml,ba as Ku,c as jl,d as Fl,e as it,f as _e,l as ru,n as iu,p as ku,q as bu,r as Iu,s as Tu,t as xu,u as Ru,w as Io,x as gs,y as Au,z as Eu}from"./chunk-UWUJVING.js";import{a as bo,b as Ol}from"./chunk-MEFPXHQJ.js";import{A as Qu,B as fs,C as Zu,h as Cd,n as Pd,o as Ki}from"./chunk-MKIJAGES.js";import{b as Rd}from"./chunk-SFQUP3BP.js";import{a as Ao}from"./chunk-6TTGRTDO.js";import{a as ou,b as vo,c as au,d as cu,e as du,i as lu,j as uu}from"./chunk-VE3SSOQX.js";import{b as zl}from"./chunk-W4YR2RO2.js";import{b as gu,c as pu,d as So,f as us,g as fu,h as mu,i as yu,j as gn,k as hs,m as wu}from"./chunk-5TTHN7DP.js";import{b as he,d as Pt,f as Ge,g as ds,i as fe,j as hu,k as He,l as Be,m as $u,s as $o}from"./chunk-USCFJVVI.js";import{a as vu,b as Su}from"./chunk-NUMWHIFL.js";import{d as Ul,e as Gl,f as Hl,g as Bl,h as ql,j as ls}from"./chunk-X5C5W3E4.js";import{c as cs}from"./chunk-OWNQ2FD4.js";import{c as Pl}from"./chunk-MWNCS57L.js";import{d as Md,e as aS,m as pl,n as kS,q as fl,v as ml,x as go,y as Ue,z as un}from"./chunk-FFPQS2C4.js";import{a as Pe,b as ln,f as os}from"./chunk-72SZI2UW.js";import{a as cn,b as _d}from"./chunk-FCPTN6NF.js";import{c as yl}from"./chunk-MYVHVJWZ.js";import{e as kl}from"./chunk-6TURWSMN.js";import{d as vl,e as Sl,f as fo,g as as,h as $l,i as Il,j as Tl,k as xl,q as Rl}from"./chunk-AV7T3SYT.js";import{o as xd,p as oS}from"./chunk-JNG3P5V2.js";import{a as es,b as iS}from"./chunk-7I7IEX4S.js";import{b as Ad,e as Ed}from"./chunk-JHCI6XCJ.js";import{e as tt}from"./chunk-DSYKYZMT.js";import{$ as dn,A as hS,B as el,C as gS,D as tl,E as pS,G as Rt,H as nl,J as ro,K as io,L as At,La as ho,M as Et,N as oo,Na as gl,O as ao,S as sl,T as is,U as co,Ua as wS,W as lo,Y as rl,Z as il,aa as ol,ba as al,ca as cl,d as xt,da as dl,e as Dd,ea as fS,f as Yi,g as cS,h as ts,ha as ll,i as Qi,j as ns,ka as ul,l as nt,la as hl,m as Zi,n as Nd,o as dS,p as ss,pa as mS,q as lS,r as rs,ra as uo,s as Ld,t as uS,ta as yS,u as jd,v as Fd,w as Wd,z as Zd}from"./chunk-GVJMPSE2.js";import{a as Ud,e as st,f as Gd,g as Hd,h as eo}from"./chunk-BRK6M6LA.js";import{a as Bd,b as qd,c as Xd,e as Vd,f as to,g as Jd,h as Kd,i as no,j as zd,k as Yd,m as so,n as Qd}from"./chunk-UIBUZ2N3.js";import{b as zi,e as Od}from"./chunk-2QNT5JDS.js";import{d as Tt}from"./chunk-QIJLFPWE.js";import{existsSync as Zo,readFileSync as ea}from"fs";Wd();var Hg=["answer","narration","line"],Bg=5e3;function qg(r){return r==="/voice/queue"||r.startsWith("/voice/queue/")}async function Xg(r,e,t,n,s,i){if(n==="/voice/queue"){if(t==="GET")return{status:200,body:{...r.view(),...i?{floor:i.view()}:{}}};if(t!=="POST")return{status:405,body:{error:"GET or POST"}};let d=String(s.text??"").trim(),l=String(s.agentId??s.agent??""),u=String(s.kind??"line");if(!d||!l||!Hg.includes(u))return{status:400,body:{error:`Required: text and agentId; kind is ${Hg.join(" | ")}`}};if(d.length>Bg)return{status:413,body:{error:`text is over ${Bg} characters`}};let g=e(l);if(!g)return{status:404,body:{error:`Unknown agent: ${l}`}};let{item:m,done:p}=r.enqueue({voice:g,text:d,agentId:l,kind:u,...typeof s.floor=="string"?{floor:s.floor}:{}});return s.wait!==!0?{status:202,body:{item:m}}:{status:200,body:{item:m,played:await p}}}if(t==="POST"&&n==="/voice/queue/pause")return r.pause(),{status:200,body:r.view()};if(t==="POST"&&n==="/voice/queue/resume")return r.resume(),{status:200,body:r.view()};let[,,,o,a,c]=n.split("/");if(t!=="POST"||!o||c!==void 0)return{status:404,body:{error:"Not found"}};switch(a){case"skip":return r.skip(o)?{status:200,body:r.view()}:Vo(o);case"front":return r.front(o)?{status:200,body:r.view()}:Vo(o);case"replay":{let d=r.replay(o);return d?{status:202,body:{item:d}}:Vo(o)}default:return{status:404,body:{error:"Not found"}}}}function Vg(r){let e=n=>`${n.agentId??"someone"} (${n.kind}): "${n.text.length>80?`${n.text.slice(0,79)}\u2026`:n.text}" [${n.id}]`,t=r.playing?`Speaking: ${e(r.playing)}`:r.paused?"Paused: the listener is speaking; the queue plays on after.":"Nothing is speaking.";return[...r.floor?.held?[Fd(r.floor)]:[],t,...r.waiting.map((n,s)=>`${s+1}. waiting: ${e(n)}`)].join(`
1
+ import{A as Lo,Ba as Mg,D as Hh,F as Ss,Fa as Og,Ga as Rs,H as sg,Ha as Bo,Ia as Dg,Ja as Ng,K as rg,Ka as Lg,La as jg,M as ig,Na as Fg,O as og,P as Fo,Q as ag,R as Ke,S as cg,T as $s,Ua as Wg,V as Wo,Va as Ug,W as dg,X as Go,Y as ct,Z as wg,_ as kg,a as gh,b as Eo,ba as dt,ca as bg,cb as qo,da as vg,db as Xo,ea as Sg,f as Co,fa as $g,fb as Gg,g as ph,ga as Ig,h as fh,ha as Tg,i as Je,j as mh,ja as Se,k as yh,ka as Is,la as Ho,m as wh,ma as xg,na as fn,o as kh,oa as Rg,p as Nt,pa as Oe,q as _o,qa as Ag,r as Oh,ra as Eg,s as Dh,sa as Cg,t as Nh,ta as Ts,u as Lh,ua as xs,v as jh,va as Pg,w as Fh,wa as _g,x as Wh,y as Uh,z as Gh}from"./chunk-HSCZSNOX.js";import{d as lh,g as uh,h as hh}from"./chunk-GFRAHUAQ.js";import{B as ys,C as Mo,D as ws,E as Lt,I as Bh,c as eh,e as th,f as nh,g as ms,h as Ro,i as sh,j as Xe,x as $h,y as Ih,z as Th}from"./chunk-XOUK5ZIQ.js";import{b as yg}from"./chunk-7LN4VKDU.js";import{a as bh}from"./chunk-ZVP6GB4G.js";import{g as Rh}from"./chunk-LQE73AZR.js";import{b as Ah,c as Eh}from"./chunk-2D3RYIDU.js";import{b as qh}from"./chunk-MRIVENBY.js";import{i as Xh,m as jo,n as Vh,p as Jh,q as Kh,r as zh,s as Yh,t as Qh,u as Zh}from"./chunk-BNOGNRAM.js";import{e as Oo,k as Do,l as Ch,m as bs,n as jt,o as Ft,p as Me,r as Ph,s as _h,t as Mh,u as No,v as vs}from"./chunk-LQS27HSV.js";import{a as eg}from"./chunk-PPUN7YHA.js";import{a as tg,b as ng}from"./chunk-VZLIBDLH.js";import{b as lg,c as ug,d as Uo,e as hg,f as gg,g as pg,h as fg,i as mg}from"./chunk-EKJG63EJ.js";import{o as Po}from"./chunk-S3EX64LR.js";import{b as ks}from"./chunk-EMGB23H5.js";import{d as xh}from"./chunk-JAML6222.js";import{a as Ve}from"./chunk-MNG2AMKZ.js";import{b as ch,c as dh}from"./chunk-X7UQY7CH.js";import{a as rh,b as at,c as ih,d as oh,e as ah}from"./chunk-PYHR4HXO.js";import{c as Dt}from"./chunk-KP7KDLZ2.js";import{a as vh,b as Sh}from"./chunk-A5GYG56I.js";import{$ as ps,B as Xl,C as Vl,D as Jl,E as Kl,F as ge,G as Yl,H as Ql,I as Zl,J as eu,K as tu,L as nu,M as su,N as Uu,O as Gu,P as Hu,Q as Bu,R as qu,S as Xu,U as pn,V as Vu,W as pe,X as qe,Y as To,Z as _t,_ as xo,a as wl,aa as Mt,b as po,ba as Ot,c as bl,ca as me,d as Al,da as ot,e as El,ea as oe,f as hn,h as mo,ha as zu,i as yo,j as wo,k as ko,l as Cl,ra as Yu,s as _l,t as Dl,u as rt,v as Nl,w as Ll,x as Ct,y as Wl,z as X}from"./chunk-MLC5INGD.js";import{A as Cu,B as Pu,C as _u,D as Mu,E as Ou,F as Du,H as Nu,K as Lu,P as ju,Q as Fu,T as Wu,X as Ju,a as Ml,ba as Ku,c as jl,d as Fl,e as it,f as _e,l as ru,n as iu,p as ku,q as bu,r as Iu,s as Tu,t as xu,u as Ru,w as Io,x as gs,y as Au,z as Eu}from"./chunk-YL26FRKJ.js";import{a as bo,b as Ol}from"./chunk-MEFPXHQJ.js";import{A as Qu,B as fs,C as Zu,h as Cd,n as Pd,o as Ki}from"./chunk-YJNUVAM4.js";import{b as Rd}from"./chunk-SFQUP3BP.js";import{a as Ao}from"./chunk-6TTGRTDO.js";import{a as ou,b as vo,c as au,d as cu,e as du,i as lu,j as uu}from"./chunk-VE3SSOQX.js";import{b as zl}from"./chunk-W4YR2RO2.js";import{b as gu,c as pu,d as So,f as us,g as fu,h as mu,i as yu,j as gn,k as hs,m as wu}from"./chunk-5TTHN7DP.js";import{b as he,d as Pt,f as Ge,g as ds,i as fe,j as hu,k as He,l as Be,m as $u,s as $o}from"./chunk-W2RB5XG7.js";import{a as vu,b as Su}from"./chunk-GRVTLUQ6.js";import{d as Ul,e as Gl,f as Hl,g as Bl,h as ql,j as ls}from"./chunk-X5C5W3E4.js";import{c as cs}from"./chunk-OWNQ2FD4.js";import{c as Pl}from"./chunk-MWNCS57L.js";import{d as Md,e as aS,m as pl,n as kS,q as fl,v as ml,x as go,y as Ue,z as un}from"./chunk-743RAKLP.js";import{a as Pe,b as ln,f as os}from"./chunk-72SZI2UW.js";import{a as cn,b as _d}from"./chunk-FCPTN6NF.js";import{c as yl}from"./chunk-MYVHVJWZ.js";import{e as kl}from"./chunk-6TURWSMN.js";import{d as vl,e as Sl,f as fo,g as as,h as $l,i as Il,j as Tl,k as xl,q as Rl}from"./chunk-AV7T3SYT.js";import{o as xd,p as oS}from"./chunk-JNG3P5V2.js";import{a as es,b as iS}from"./chunk-7I7IEX4S.js";import{b as Ad,e as Ed}from"./chunk-JHCI6XCJ.js";import{e as tt}from"./chunk-DSYKYZMT.js";import{$ as dn,A as hS,B as el,C as gS,D as tl,E as pS,G as Rt,H as nl,J as ro,K as io,L as At,La as ho,M as Et,N as oo,Na as gl,O as ao,S as sl,T as is,U as co,Ua as wS,W as lo,Y as rl,Z as il,aa as ol,ba as al,ca as cl,d as xt,da as dl,e as Dd,ea as fS,f as Yi,g as cS,h as ts,ha as ll,i as Qi,j as ns,ka as ul,l as nt,la as hl,m as Zi,n as Nd,o as dS,p as ss,pa as mS,q as lS,r as rs,ra as uo,s as Ld,t as uS,ta as yS,u as jd,v as Fd,w as Wd,z as Zd}from"./chunk-VKEH4IBA.js";import{a as Ud,e as st,f as Gd,g as Hd,h as eo}from"./chunk-BRK6M6LA.js";import{a as Bd,b as qd,c as Xd,e as Vd,f as to,g as Jd,h as Kd,i as no,j as zd,k as Yd,m as so,n as Qd}from"./chunk-UIBUZ2N3.js";import{b as zi,e as Od}from"./chunk-2QNT5JDS.js";import{d as Tt}from"./chunk-QIJLFPWE.js";import{existsSync as Zo,readFileSync as ea}from"fs";Wd();var Hg=["answer","narration","line"],Bg=5e3;function qg(r){return r==="/voice/queue"||r.startsWith("/voice/queue/")}async function Xg(r,e,t,n,s,i){if(n==="/voice/queue"){if(t==="GET")return{status:200,body:{...r.view(),...i?{floor:i.view()}:{}}};if(t!=="POST")return{status:405,body:{error:"GET or POST"}};let d=String(s.text??"").trim(),l=String(s.agentId??s.agent??""),u=String(s.kind??"line");if(!d||!l||!Hg.includes(u))return{status:400,body:{error:`Required: text and agentId; kind is ${Hg.join(" | ")}`}};if(d.length>Bg)return{status:413,body:{error:`text is over ${Bg} characters`}};let g=e(l);if(!g)return{status:404,body:{error:`Unknown agent: ${l}`}};let{item:m,done:p}=r.enqueue({voice:g,text:d,agentId:l,kind:u,...typeof s.floor=="string"?{floor:s.floor}:{}});return s.wait!==!0?{status:202,body:{item:m}}:{status:200,body:{item:m,played:await p}}}if(t==="POST"&&n==="/voice/queue/pause")return r.pause(),{status:200,body:r.view()};if(t==="POST"&&n==="/voice/queue/resume")return r.resume(),{status:200,body:r.view()};let[,,,o,a,c]=n.split("/");if(t!=="POST"||!o||c!==void 0)return{status:404,body:{error:"Not found"}};switch(a){case"skip":return r.skip(o)?{status:200,body:r.view()}:Vo(o);case"front":return r.front(o)?{status:200,body:r.view()}:Vo(o);case"replay":{let d=r.replay(o);return d?{status:202,body:{item:d}}:Vo(o)}default:return{status:404,body:{error:"Not found"}}}}function Vg(r){let e=n=>`${n.agentId??"someone"} (${n.kind}): "${n.text.length>80?`${n.text.slice(0,79)}\u2026`:n.text}" [${n.id}]`,t=r.playing?`Speaking: ${e(r.playing)}`:r.paused?"Paused: the listener is speaking; the queue plays on after.":"Nothing is speaking.";return[...r.floor?.held?[Fd(r.floor)]:[],t,...r.waiting.map((n,s)=>`${s+1}. waiting: ${e(n)}`)].join(`
2
2
  `)}var Vo=r=>({status:404,body:{error:`No such line in the queue: ${r}`}});var bS=20,Jo=120,vS=80,SS=new Set(["waiting_owner","needs_attention"]);function Ko(r,e){let t=String(r??"").replace(/\s+/g," ").trim();return t.length>e?`${t.slice(0,e-1)}\u2026`:t}function As(r){return{total:r.length,items:r.slice(0,bS)}}var zo=r=>new Date(r).toISOString();function Jg(r){return{id:r.id,agentId:r.agentId,kind:r.kind,text:Ko(r.text,vS),enqueuedAt:zo(r.enqueuedAt)}}function Kg(r){let e=r.cards.filter(i=>i.status==="pending").sort((i,o)=>String(i.created_at??"").localeCompare(String(o.created_at??""))).map(i=>({id:i.id,title:Ko(i.title,Jo),raised_by:i.raised_by,node:i.node??null,createdAt:i.created_at})),t=[...r.held].sort((i,o)=>i.at.localeCompare(o.at)).map(i=>({id:i.id,title:Ko(i.title,Jo),from:i.from,at:i.at,heldBecause:i.heldBecause})),n=(r.requests??[]).filter(i=>SS.has(i.state)).sort((i,o)=>i.createdAt-o.createdAt).map(i=>({id:i.id,title:Xe(i,Jo).headline,agentId:i.agentId,state:i.state,since:zo(i.stateChangedAt??i.updatedAt)})),s=r.voice;return{ts:zo(r.now),cards:As(e),held:As(t),voice:s?{paused:s.paused,reserved:s.reserved,playing:s.playing?Jg(s.playing):null,waiting:As(s.waiting.map(Jg))}:null,requests:As(n),errors:r.errors??[]}}function zg(r){let e=[],t=n=>n.total>n.items.length?[` \u2026 and ${n.total-n.items.length} more`]:[];e.push(`Decision cards waiting for an answer: ${r.cards.total}`);for(let n of r.cards.items)e.push(` - ${n.title} (by ${n.raised_by}${n.node?` on ${n.node}`:""}, ${n.createdAt}, ${n.id})`);e.push(...t(r.cards)),e.push(`Notices held by Focus or a call: ${r.held.total}`);for(let n of r.held.items)e.push(` - ${n.title} (from ${n.from}, ${n.at})`);if(e.push(...t(r.held)),r.voice){let n=r.voice.paused?", paused":r.voice.reserved?", the floor is held":"";e.push(`Speaking now: ${r.voice.playing?`${r.voice.playing.agentId??"the host"}: ${r.voice.playing.text}`:"nothing"}${n}`),e.push(`Lines waiting to be spoken: ${r.voice.waiting.total}`);for(let s of r.voice.waiting.items)e.push(` - ${s.agentId??"the host"} (${s.kind}): ${s.text}`);e.push(...t(r.voice.waiting))}e.push(`Open requests waiting on the owner: ${r.requests.total}`);for(let n of r.requests.items)e.push(` - ${n.title} (${n.agentId}, ${n.state.replace("_"," ")} since ${n.since}, ${n.id})`);e.push(...t(r.requests));for(let n of r.errors)e.push(`Could not read: ${n}`);return e.join(`
3
3
  `)}import{resolve as ta}from"path";yS();var $S={name:"agentx",version:"0.1.0"},IS=["2024-11-05","2025-03-26","2025-06-18","2025-11-25"],TS="2024-11-05";function xS(r){return typeof r=="string"&&IS.includes(r)?r:TS}var RS={tools:{},elicitation:{form:{}}},AS=0;async function Yg(r,e){let t=++AS;return lt({jsonrpc:"2.0",id:`elicit-${t}`,method:"elicitation/create",params:{mode:"form",message:r,requestedSchema:e}}),new Promise(n=>{mn.set(`elicit-${t}`,s=>{s?.action==="accept"&&s.content?n(s.content):n(null)}),setTimeout(()=>{mn.has(`elicit-${t}`)&&(mn.delete(`elicit-${t}`),n(null))},6e4)})}var mn=new Map,ES="http://localhost:18800",Yo;function CS(){if(process.env.AGENTX_DAEMON_URL)return process.env.AGENTX_DAEMON_URL;for(let r of["agentx.json",".agentx/config.json"])try{let e=ta(process.cwd(),r);if(!Zo(e))continue;let t=JSON.parse(ea(e,"utf-8"))?.node?.bind;if(typeof t!="string"||!t.includes(":"))continue;{let n=t.lastIndexOf(":"),s=t.slice(0,n),i=t.slice(n+1),o=!s||s==="0.0.0.0"||s==="::"||s==="*"?"127.0.0.1":s;if(i)return`http://${o}:${i}`}}catch{}return ES}function V(){return Yo===void 0&&(Yo=CS()),Yo}var Qo;function PS(r){try{let e=ta(process.cwd(),".env");if(!Zo(e))return"";for(let t of ea(e,"utf-8").split(`
4
4
  `)){let n=t.trim().replace(/^export\s+/,"");if(!n.startsWith(`${r}=`))continue;let s=n.slice(r.length+1).trim();return/^(["']).*\1$/.test(s)?s.slice(1,-1):s}}catch{}return""}function _S(r=process.env){if(r.AGENTX_TOKEN)return r.AGENTX_TOKEN;if(r.MESH_TOKEN)return r.MESH_TOKEN;let e=PS("MESH_TOKEN");if(e)return e;for(let t of["agentx.json",".agentx/config.json"])try{let n=ta(process.cwd(),t);if(!Zo(n))continue;let s=JSON.parse(ea(n,"utf-8"))?.dashboard?.token;if(typeof s=="string"&&s)return s}catch{}return""}function MS(){return Qo===void 0&&(Qo=_S()),Qo}var J=(r,e)=>{let t=MS();if(!t)return fetch(r,e);let n=new Headers(e?.headers);return n.has("Authorization")||n.set("Authorization",`Bearer ${t}`),fetch(r,{...e,headers:n})};function Es(r=process.env){let e={};return r.AGENTX_TASK_ID&&(e.callerTaskId=r.AGENTX_TASK_ID),r.AGENTX_CHANNEL&&(e.callerChannel=r.AGENTX_CHANNEL),r.AGENTX_CHAT_ID&&(e.callerChatId=r.AGENTX_CHAT_ID),e}async function OS(){let r=process.env.AGENTX_AGENT_ID,e=Es();if(!(!r||!e.callerChannel||!e.callerChatId))try{let t=new URLSearchParams({channel:e.callerChannel,chatId:e.callerChatId}),n=await J(`${V()}/agents/${encodeURIComponent(r)}/intent-path?${t}`,{signal:AbortSignal.timeout(2e3)});if(!n.ok)return;let s=await n.json();return{...Array.isArray(s.path)&&s.path.length?{path:s.path}:{},...typeof s.graphWeight=="number"?{graphWeight:s.graphWeight}:{}}}catch{return}}var DS=1e4,NS=new Set(["ECONNREFUSED","ENOTFOUND","EAI_AGAIN","EHOSTUNREACH","ENETUNREACH"]);function LS(r,e){let t=e,n=t?.cause?.code??t?.code;if(n&&NS.has(n))return`Error: the AgentX daemon could not be reached (${n}); the message to ${r} was not sent.`;let s=t?.name==="TimeoutError"||t?.name==="AbortError"?"no answer in time":t?.message||String(e);return`Probably delivered to ${r}: the daemon did not confirm (${s}), but the request was sent and is most likely queued. Do not treat this as a failure. If unsure, send the same message again: within 10 minutes a repeat returns the existing task id instead of a second task, and delivers it if the first never arrived. A busy ${r} shows no trace until its turn starts; later, \`agentx trace list --agent ${r} --since 1h\` or the daemon log ("[send/agent]") shows it.`}var jS=/\x1B\[[0-9;]*[A-Za-z]/g;function Wt(r){return r.replace(jS,"")}async function FS(r,e,t){let n=await J(`${V()}/recall`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:r,channel:e,limit:Math.min(Math.max(t??30,1),100)})}),s=await n.json().catch(()=>({}));if(!n.ok)return{content:[{type:"text",text:`Error: ${s.error||n.statusText}`}]};let i=s.turns||[],o=e?`on ${e}`:"on any channel";return i.length===0?{content:[{type:"text",text:`No other messages ${o} today for ${r}.`}]}:{content:[{type:"text",text:WS(i,!!s.hasMore)}]}}function WS(r,e){let t=new Map;for(let s of r){let i=`${s.channel}/${s.chatId}`;t.has(i)||t.set(i,[]),t.get(i).push(s)}let n=[];for(let[s,i]of t){let o=[...i].sort((a,c)=>a.ts.localeCompare(c.ts)).map(a=>{let c=a.role==="agent"?"you":a.senderName||"user";return` [${a.ts.slice(11,16)}] ${c}: ${a.content.slice(0,300)}`});n.push(`From ${s}:
@@ -41,7 +41,7 @@ ${String(v.plan.text).split(`
41
41
  `)}]}:{content:[{type:"text",text:"No stopped tasks."}]}}if(n!=="stop"&&n!=="resume")return{content:[{type:"text",text:"Error: action must be stop, resume or list."}]};let a=n==="stop"?{taskId:o(e.taskId),agentId:o(e.agentId),channel:o(e.channel),chatId:o(e.chatId),reason:o(e.reason),node:o(e.node),from:s}:{id:o(e.id),reason:o(e.reason),node:o(e.node),from:s},c=await J(`${V()}/api/signals/${n}`,{method:"POST",headers:{"Content-Type":"application/json",...i},body:JSON.stringify(a),signal:AbortSignal.timeout(3e4)}),d=await c.json().catch(()=>({}));return c.ok?{content:[{type:"text",text:n==="stop"?`Stopped task ${d.id} of ${d.agentId}. It is writing its resume plan; resume it with agentx_signal action=resume id=${d.id}.`:`Resumed task ${d.id} of ${d.agentId}. Its answer goes to ${d.delivery??"the chat it came from"}.`}]}:{content:[{type:"text",text:`Signal not sent: ${d.error||`HTTP ${c.status}`}`}]}}case"agentx_crons":{let s=await(await J(`${V()}/crons/health`)).json(),i=`Healthy: ${s.healthy}, Failing: ${s.failing}, Disabled: ${s.disabled}, Missed: ${s.missed}`,o=(s.jobs||[]).map(a=>` ${a.id}: ${a.status}${a.consecutiveErrors?` (${a.consecutiveErrors} errors)`:""}${a.lastError?` \u2014 ${a.lastError.slice(0,100)}`:""}`).join(`
42
42
  `);return{content:[{type:"text",text:`${i}
43
43
 
44
- ${o}`}]}}case"agentx_schedule":{let{runScheduleTool:n,resolveScheduleCaller:s}=await import("./schedule-tool-FIKDTGXF.js");return{content:[{type:"text",text:await n(e,s(e),{notifyOperator:async(o,a)=>{let c=await J(`${V()}/send`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({channel:o.channel,chatId:o.chatId,accountId:o.accountId,text:a}),signal:AbortSignal.timeout(1e4)});if(!c.ok){let d=await c.json().catch(()=>({}));throw new Error(d?.error||`HTTP ${c.status}`)}}})}]}}case"agentx_approval":{let{runApprovalTool:n}=await import("./tool-VN7W6QGC.js");return{content:[{type:"text",text:await n(e,{daemonUrl:V(),fetch:J})}]}}case"agentx_note":{let{runNoteTool:n}=await import("./note-tool-EZWSB3J3.js");return{content:[{type:"text",text:await n(e,{daemonUrl:V(),fetch:J})}]}}case"agentx_request":{let{runRequestTool:n}=await import("./tool-QIFV7Q4M.js");return{content:[{type:"text",text:await n(e,{daemonUrl:V(),fetch:J})}]}}case"agentx_workflow":{let{runWorkflowTool:n}=await import("./follow-up-tool-L3QXZIU2.js");return{content:[{type:"text",text:await n(e,{daemonUrl:V()})}]}}case"agentx_wiki_query":{let n=String(e.question||"").trim();if(!n)return{content:[{type:"text",text:"Error: `question` is required."}]};let{WikiHub:s}=await import("./wiki-TN5WFJ5P.js"),{agenticQuery:i,sharedQueryEnabled:o}=await import("./query-WHNB46XD.js"),{loadQuerySettings:a,toolNoteSourceFor:c}=await import("./query-settings-U5ZMQREP.js"),{resolve:d}=await import("path"),l=e.wiki_dir||d(process.cwd(),".agentx/wiki"),u=new s(l,void 0,"graph"),g=e.agent||process.env.AGENTX_AGENT_ID||"";if(!g){let{existsSync:f}=await import("fs");for(let k of u.listAgents()){let S=d(u.getAgentWiki(k).baseDir,"_index.md");if(f(S)){g=k;break}}}let{QUERY_RUNS_FILE:m,recordQueryRun:p,timedQuery:y}=await import("./query-runs-VXS572PQ.js"),v=d(u.getBaseDir(),m);if(!g)return p(v,{at:new Date().toISOString(),agent:"",status:"no-catalog",source:"tool",wallMs:0}),{content:[{type:"text",text:"Error: no agent has a wiki catalog yet. Run `agentx wiki absorb` first."}]};let w=u.getAgentWiki(g),$=typeof e.max_hops=="number"?Math.min(3,Math.max(0,e.max_hops)):2,b=await OS(),T=await a(),_=await o()?u.sharedScope(g):void 0,A=await y(v,g,"tool",()=>i(n,w,g,{maxHops:$,shared:_,messagePath:b?.path,...b?.graphWeight!==void 0?{graphWeight:b.graphWeight}:{},method:T.method,summaries:T.summaries,notes:c(T,g)}));if(A.status!=="ok")return{content:[{type:"text",text:`Query returned status "${A.status}"${A.error?`: ${A.error}`:""}`}]};let R=A.citations.map(f=>` - ${f.title} [${f.type||"?"}] (${f.path})`).join(`
44
+ ${o}`}]}}case"agentx_schedule":{let{runScheduleTool:n,resolveScheduleCaller:s}=await import("./schedule-tool-7KFO3NPD.js");return{content:[{type:"text",text:await n(e,s(e),{notifyOperator:async(o,a)=>{let c=await J(`${V()}/send`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({channel:o.channel,chatId:o.chatId,accountId:o.accountId,text:a}),signal:AbortSignal.timeout(1e4)});if(!c.ok){let d=await c.json().catch(()=>({}));throw new Error(d?.error||`HTTP ${c.status}`)}}})}]}}case"agentx_approval":{let{runApprovalTool:n}=await import("./tool-PQBQJWM5.js");return{content:[{type:"text",text:await n(e,{daemonUrl:V(),fetch:J})}]}}case"agentx_note":{let{runNoteTool:n}=await import("./note-tool-EZWSB3J3.js");return{content:[{type:"text",text:await n(e,{daemonUrl:V(),fetch:J})}]}}case"agentx_request":{let{runRequestTool:n}=await import("./tool-WTOOPTGC.js");return{content:[{type:"text",text:await n(e,{daemonUrl:V(),fetch:J})}]}}case"agentx_workflow":{let{runWorkflowTool:n}=await import("./follow-up-tool-TGKEPA5C.js");return{content:[{type:"text",text:await n(e,{daemonUrl:V()})}]}}case"agentx_wiki_query":{let n=String(e.question||"").trim();if(!n)return{content:[{type:"text",text:"Error: `question` is required."}]};let{WikiHub:s}=await import("./wiki-DXG655NP.js"),{agenticQuery:i,sharedQueryEnabled:o}=await import("./query-5CPK6G2H.js"),{loadQuerySettings:a,toolNoteSourceFor:c}=await import("./query-settings-35GDM3HU.js"),{resolve:d}=await import("path"),l=e.wiki_dir||d(process.cwd(),".agentx/wiki"),u=new s(l,void 0,"graph"),g=e.agent||process.env.AGENTX_AGENT_ID||"";if(!g){let{existsSync:f}=await import("fs");for(let k of u.listAgents()){let S=d(u.getAgentWiki(k).baseDir,"_index.md");if(f(S)){g=k;break}}}let{QUERY_RUNS_FILE:m,recordQueryRun:p,timedQuery:y}=await import("./query-runs-VXS572PQ.js"),v=d(u.getBaseDir(),m);if(!g)return p(v,{at:new Date().toISOString(),agent:"",status:"no-catalog",source:"tool",wallMs:0}),{content:[{type:"text",text:"Error: no agent has a wiki catalog yet. Run `agentx wiki absorb` first."}]};let w=u.getAgentWiki(g),$=typeof e.max_hops=="number"?Math.min(3,Math.max(0,e.max_hops)):2,b=await OS(),T=await a(),_=await o()?u.sharedScope(g):void 0,A=await y(v,g,"tool",()=>i(n,w,g,{maxHops:$,shared:_,messagePath:b?.path,...b?.graphWeight!==void 0?{graphWeight:b.graphWeight}:{},method:T.method,summaries:T.summaries,notes:c(T,g)}));if(A.status!=="ok")return{content:[{type:"text",text:`Query returned status "${A.status}"${A.error?`: ${A.error}`:""}`}]};let R=A.citations.map(f=>` - ${f.title} [${f.type||"?"}] (${f.path})`).join(`
45
45
  `),O=A.walked.length,L=A.live?.length?`
46
46
 
47
47
  Read live at the source just now:
@@ -552,7 +552,7 @@ ${d}`)}let $={agentId:o,message:w,context:{channel:y,sender:p?"opencode":"openai
552
552
 
553
553
  `)}}function wf(r){r.writeHead(200,{"Content-Type":"text/event-stream; charset=utf-8","Cache-Control":"no-cache",Connection:"keep-alive","X-Accel-Buffering":"no"})}function kf(r,e,t,n,s,i){r.write(`data: ${JSON.stringify({id:e,object:"chat.completion.chunk",created:t,model:n,choices:[{index:0,delta:s,finish_reason:i}]})}
554
554
 
555
- `)}function bf(r,e,t,n,s,i){let o=i?.usage?.inputTokens??0,a=i?.usage?.outputTokens??Math.ceil(s.length/4);Ra(r,200,{id:e,object:"chat.completion",created:t,model:n,choices:[{index:0,message:{role:"assistant",content:s},finish_reason:"stop"}],usage:{prompt_tokens:o,completion_tokens:a,total_tokens:o+a}})}function Ra(r,e,t){r.writeHead(e,{"Content-Type":"application/json"}),r.end(JSON.stringify(t))}var Rn=class{module;minLevel;constructor(e,t="info"){this.module=e,this.minLevel=t}child(e){return new Rn(`${this.module}:${e}`,this.minLevel)}debug(e,t){this.emit("debug",e,t)}info(e,t){this.emit("info",e,t)}warn(e,t){this.emit("warn",e,t)}error(e,t){this.emit("error",e,t)}asConsoleLog(){return(...e)=>{let n=e.map(s=>typeof s=="string"?s:JSON.stringify(s)).join(" ").replace(/^\[agentx\]\s*/,"");n&&this.info(n)}}emit(e,t,n){if(Rn.levelOrder[e]<Rn.levelOrder[this.minLevel])return;let s={time:new Date().toISOString(),level:e,module:this.module,msg:t,...n},i=e==="error"?"ERROR":e==="warn"?"WARN":"",o=`[${this.module}]`,a=i?`${o} ${i}: ${t}`:`${o} ${t}`;console.error(a)}},xn=Rn;Tt(xn,"levelOrder",{debug:0,info:1,warn:2,error:3});import{realpathSync as Z$,statSync as eI}from"fs";var yt={version:"0.154.0",commit:"273f08d",startedAt:new Date(Date.now()-process.uptime()*1e3).toISOString()};function tI(r,e){let t=e.mtimeMs!==null&&e.mtimeMs>Date.parse(r.startedAt),n=!!e.version&&!!r.version&&e.version!==r.version;return{newer:t||n,changedAt:e.mtimeMs===null?null:new Date(e.mtimeMs).toISOString(),version:e.version}}function Sf(){let r=null;try{r=eI(Z$(process.argv[1])).mtimeMs}catch{}let e=Gp().version;return tI(yt,{mtimeMs:r,version:e&&e!=="0.0.0"?e:null})}import{randomUUID as nI}from"crypto";var ir=class{constructor(e=new Wl){this.core=e}count=0;subscribe(e,t){this.count++;let n=this.core.subscribe((i,o)=>{if(!o||!sI.includes(o.kind))return;let a={...o,rootId:i.rootId,node:i.node};iI(e,a)&&t(a)}),s=!0;return()=>{s&&(s=!1,this.count--,n())}}publish(e){let t={id:typeof e.id=="string"?e.id:nI(),at:typeof e.at=="string"?e.at:new Date().toISOString(),...e},{type:n,summary:s,ref:i,agentId:o}=rI(t);this.core.publish({id:t.id,at:t.at,kind:t.kind,type:n,summary:s,ref:i,agentId:o,rootId:typeof e.rootId=="string"?e.rootId:void 0,data:t})}get size(){return this.count}},sI=["run","task","signal","mesh","channel","status"];function rI(r){switch(r.kind){case"run":return{type:r.phase,ref:r.runId,summary:[r.workflowId,r.nodeId,r.phase,r.note].filter(Boolean).join(" ")};case"task":return{type:r.phase,ref:r.taskId,summary:`${r.title??r.taskId} ${r.phase}`};case"signal":return{type:"emitted",summary:`signal ${r.name} (${r.scope})`};case"mesh":return{type:r.delta,summary:`peer ${r.peer} ${r.delta}`};case"channel":return{type:r.direction,ref:r.messageId,agentId:r.agentId,summary:`${r.channel} ${r.direction==="in"?"inbound":"outbound"}`};case"status":return{type:"status",summary:r.message}}}function iI(r,e){return!(r.kinds&&r.kinds.length>0&&!r.kinds.includes(e.kind)||r.workflowId&&(e.kind==="run"&&e.workflowId!==r.workflowId||e.kind==="task"&&e.workflowId!==r.workflowId||e.kind==="signal"&&e.workflowId&&e.workflowId!==r.workflowId)||r.runId&&(e.kind==="run"&&e.runId!==r.runId||e.kind==="task"&&e.runId!==r.runId)||r.actor&&(e.kind!=="task"||!(e.assignedTo?.includes(r.actor)||e.submittedBy===r.actor))||r.channel&&(e.kind!=="channel"||e.channel!==r.channel))}function $f(r){if(!r)return;let e=["run","task","signal","mesh","channel","status"],n=r.split(",").map(s=>s.trim()).filter(Boolean).filter(s=>e.includes(s));return n.length?n:void 0}import{createHmac as or,timingSafeEqual as If}from"crypto";var ar=class{registry;config;mesh;webhookEntries;log;workflowDispatcher;hooks;constructor(e,t={},n=console.error.bind(console,"[webhook]"),s,i=[],o){this.registry=e,this.config=t,this.log=n,this.mesh=s,this.webhookEntries=i,this.hooks=o}hookEventFor(e,t){if(e==="stripe")return"on:stripe-event";if(e==="sentry")return"on:sentry-issue";if(e==="vercel")return"on:vercel-deployment";if(e==="hubspot")return"on:hubspot-event";if(e==="odoo")return"on:odoo-event";if(e==="github"){let n=(t??"").split(".")[0];return n==="issues"||n==="issue_comment"?"on:github-issue":n==="pull_request"||n==="pull_request_review"?"on:github-pr":n==="push"?"on:github-push":null}return null}async fireHookSafe(e,t,n,s){let i=this.hookEventFor(e,t);if(!i||!this.hooks||!this.hooks.has(i))return;let o={};if(e==="github"){let a=s;typeof a.sender?.login=="string"&&(o.author=a.sender.login),typeof a.repository?.full_name=="string"&&(o.repo=a.repository.full_name);let c=a.issue?.number??a.pull_request?.number;typeof c=="number"&&(o.number=c)}try{await this.hooks.execute(i,{event:i,source:e,eventType:t,agentId:n,payload:s,...o})}catch(a){this.log(`${i} hook error (non-fatal): ${a?.message??a}`)}}setWorkflowDispatcher(e){this.workflowDispatcher=e}setWebhookEntries(e){this.webhookEntries=e}async handle(e,t,n){let s=n.replace(/^\/webhook\/?/,"").split("/").filter(Boolean),i=s[0],o=s[1];if(!i){this.sendJson(t,400,{error:"Missing agent ID. Use /webhook/:agentId"});return}let{raw:a,parsed:c}=await this.readBody(e),d=o||this.detectSource(e.headers);if(process.env.AGENTX_WEBHOOK_DEBUG_HEADERS==="1"){let v={};for(let[w,$]of Object.entries(e.headers))(w.startsWith("x-hubspot")||w.startsWith("x-hub")||w.startsWith("x-github")||w.startsWith("x-gitlab")||w.startsWith("stripe")||w.startsWith("sentry")||w.startsWith("x-vercel")||w.startsWith("x-odoo")||w.startsWith("x-webhook")||w==="user-agent"||w==="content-type"||w==="host"||w==="x-forwarded-host"||w==="x-forwarded-proto"||w==="x-forwarded-for")&&(v[w]=$);this.log(`Webhook [${d}] reqUrl=${e.url} headers: ${JSON.stringify(v)}`)}let l=this.validateSignature(e.headers,a,d,i,e.url);if(l){this.log(`Webhook [${d}] -> ${i}: REJECTED (${l})`),this.sendJson(t,401,{error:l});return}let u=this.buildSummary(d,c,e.headers);this.log(`Webhook [${d}] -> ${i}: ${u.slice(0,100)}`);let g=this.extractEventType(d,c,e.headers),m=this.webhookEntries.find(v=>v.enabled&&v.agentId===i&&v.source===d),p=g&&m?.triggers?.[g]||m?.defaultWorkflow||null;if(await this.fireHookSafe(d,g,i,c),p&&this.workflowDispatcher)try{let v=await this.workflowDispatcher.dispatchWorkflow({workflowId:p,entityRef:{kind:"webhook",id:`${d}:${i}:${g??"\u2014"}:${Date.now()}`},event:{kind:"webhook",source:d,eventType:g,payload:c},trigger:{source:d}});this.log(`Webhook [${d}/${g??"\u2014"}] -> workflow=${p} (claimed=${v.claimed})`),this.sendJson(t,202,{ok:!0,agent:i,source:d,eventType:g,workflow:p,claimed:v.claimed});return}catch(v){this.log(`Workflow dispatch failed [${d}/${g}/${p}]: ${v.message}`)}let y=this.webhookEntries.find(v=>v.enabled&&v.node&&v.agentId===i&&v.source===d);if(y?.node&&this.mesh){this.sendJson(t,202,{ok:!0,agent:i,source:d,node:y.node,status:"accepted"}),this.mesh.sendTask(y.node,u,i,{context:{channel:`webhook:${d}`,sender:`webhook:${d}`}}).then(v=>this.log(`Mesh-forwarded webhook [${d}] -> ${y.node}/${i}: ${v?.slice(0,100)||"ok"}`),v=>this.log(`Mesh forward failed [${d}] -> ${y.node}/${i}: ${v.message}`));return}try{let v=await this.registry.execute({message:u,agentId:i,context:{channel:`webhook:${d}`,sender:`webhook:${d}`}});this.sendJson(t,v.error?500:200,{ok:!v.error,agent:i,source:d,response:v.content?.slice(0,500),error:v.error,duration:v.duration})}catch(v){this.sendJson(t,500,{error:v.message})}}extractEventType(e,t,n){let s=i=>{let o=n[i.toLowerCase()];return Array.isArray(o)?o[0]:o};if(e==="github"){let i=s("x-github-event");if(!i)return;let o=typeof t.action=="string"?t.action:void 0;return o?`${i}.${o}`:i}if(e==="gitlab")return s("x-gitlab-event")||(typeof t.object_kind=="string"?t.object_kind:void 0);if(e==="stripe")return typeof t.type=="string"?t.type:void 0;if(e==="sentry")return s("sentry-hook-resource");if(e==="hubspot"){if(Array.isArray(t)&&t.length>0){let i=t[0];if(i&&typeof i.subscriptionType=="string")return i.subscriptionType}return typeof t.subscriptionType=="string"?t.subscriptionType:void 0}if(e==="odoo")return typeof t.event=="string"?t.event:typeof t.subscriptionType=="string"?t.subscriptionType:typeof t.model=="string"?typeof t.action=="string"?`${t.model}.${t.action}`:t.model:void 0}detectSource(e){return e["x-gitlab-event"]||e["x-gitlab-token"]?"gitlab":e["x-github-event"]?"github":e["stripe-signature"]?"stripe":e["sentry-hook-resource"]?"sentry":e["x-vercel-signature"]?"vercel":e["x-hubspot-signature-v3"]||e["x-hubspot-signature-version"]?"hubspot":e["x-odoo-database"]||e["x-odoo-signature"]?"odoo":e["x-hub-signature-256"]?"github":"unknown"}buildSummary(e,t,n){let s=[`[Webhook from ${e}]`];switch(e){case"gitlab":{let o=n["x-gitlab-event"]||t.object_kind||"event",a=t.project?.path_with_namespace||"",c=t.user?.name||t.user_username||"";if(s.push(`Event: ${o}`),a&&s.push(`Project: ${a}`),c&&s.push(`User: ${c}`),t.ref&&s.push(`Ref: ${t.ref}`),t.commits&&Array.isArray(t.commits)){s.push(`Commits: ${t.commits.length}`);for(let l of t.commits.slice(0,3))s.push(` - ${l.message?.split(`
555
+ `)}function bf(r,e,t,n,s,i){let o=i?.usage?.inputTokens??0,a=i?.usage?.outputTokens??Math.ceil(s.length/4);Ra(r,200,{id:e,object:"chat.completion",created:t,model:n,choices:[{index:0,message:{role:"assistant",content:s},finish_reason:"stop"}],usage:{prompt_tokens:o,completion_tokens:a,total_tokens:o+a}})}function Ra(r,e,t){r.writeHead(e,{"Content-Type":"application/json"}),r.end(JSON.stringify(t))}var Rn=class{module;minLevel;constructor(e,t="info"){this.module=e,this.minLevel=t}child(e){return new Rn(`${this.module}:${e}`,this.minLevel)}debug(e,t){this.emit("debug",e,t)}info(e,t){this.emit("info",e,t)}warn(e,t){this.emit("warn",e,t)}error(e,t){this.emit("error",e,t)}asConsoleLog(){return(...e)=>{let n=e.map(s=>typeof s=="string"?s:JSON.stringify(s)).join(" ").replace(/^\[agentx\]\s*/,"");n&&this.info(n)}}emit(e,t,n){if(Rn.levelOrder[e]<Rn.levelOrder[this.minLevel])return;let s={time:new Date().toISOString(),level:e,module:this.module,msg:t,...n},i=e==="error"?"ERROR":e==="warn"?"WARN":"",o=`[${this.module}]`,a=i?`${o} ${i}: ${t}`:`${o} ${t}`;console.error(a)}},xn=Rn;Tt(xn,"levelOrder",{debug:0,info:1,warn:2,error:3});import{realpathSync as Z$,statSync as eI}from"fs";var yt={version:"0.154.2",commit:"468764a",startedAt:new Date(Date.now()-process.uptime()*1e3).toISOString()};function tI(r,e){let t=e.mtimeMs!==null&&e.mtimeMs>Date.parse(r.startedAt),n=!!e.version&&!!r.version&&e.version!==r.version;return{newer:t||n,changedAt:e.mtimeMs===null?null:new Date(e.mtimeMs).toISOString(),version:e.version}}function Sf(){let r=null;try{r=eI(Z$(process.argv[1])).mtimeMs}catch{}let e=Gp().version;return tI(yt,{mtimeMs:r,version:e&&e!=="0.0.0"?e:null})}import{randomUUID as nI}from"crypto";var ir=class{constructor(e=new Wl){this.core=e}count=0;subscribe(e,t){this.count++;let n=this.core.subscribe((i,o)=>{if(!o||!sI.includes(o.kind))return;let a={...o,rootId:i.rootId,node:i.node};iI(e,a)&&t(a)}),s=!0;return()=>{s&&(s=!1,this.count--,n())}}publish(e){let t={id:typeof e.id=="string"?e.id:nI(),at:typeof e.at=="string"?e.at:new Date().toISOString(),...e},{type:n,summary:s,ref:i,agentId:o}=rI(t);this.core.publish({id:t.id,at:t.at,kind:t.kind,type:n,summary:s,ref:i,agentId:o,rootId:typeof e.rootId=="string"?e.rootId:void 0,data:t})}get size(){return this.count}},sI=["run","task","signal","mesh","channel","status"];function rI(r){switch(r.kind){case"run":return{type:r.phase,ref:r.runId,summary:[r.workflowId,r.nodeId,r.phase,r.note].filter(Boolean).join(" ")};case"task":return{type:r.phase,ref:r.taskId,summary:`${r.title??r.taskId} ${r.phase}`};case"signal":return{type:"emitted",summary:`signal ${r.name} (${r.scope})`};case"mesh":return{type:r.delta,summary:`peer ${r.peer} ${r.delta}`};case"channel":return{type:r.direction,ref:r.messageId,agentId:r.agentId,summary:`${r.channel} ${r.direction==="in"?"inbound":"outbound"}`};case"status":return{type:"status",summary:r.message}}}function iI(r,e){return!(r.kinds&&r.kinds.length>0&&!r.kinds.includes(e.kind)||r.workflowId&&(e.kind==="run"&&e.workflowId!==r.workflowId||e.kind==="task"&&e.workflowId!==r.workflowId||e.kind==="signal"&&e.workflowId&&e.workflowId!==r.workflowId)||r.runId&&(e.kind==="run"&&e.runId!==r.runId||e.kind==="task"&&e.runId!==r.runId)||r.actor&&(e.kind!=="task"||!(e.assignedTo?.includes(r.actor)||e.submittedBy===r.actor))||r.channel&&(e.kind!=="channel"||e.channel!==r.channel))}function $f(r){if(!r)return;let e=["run","task","signal","mesh","channel","status"],n=r.split(",").map(s=>s.trim()).filter(Boolean).filter(s=>e.includes(s));return n.length?n:void 0}import{createHmac as or,timingSafeEqual as If}from"crypto";var ar=class{registry;config;mesh;webhookEntries;log;workflowDispatcher;hooks;constructor(e,t={},n=console.error.bind(console,"[webhook]"),s,i=[],o){this.registry=e,this.config=t,this.log=n,this.mesh=s,this.webhookEntries=i,this.hooks=o}hookEventFor(e,t){if(e==="stripe")return"on:stripe-event";if(e==="sentry")return"on:sentry-issue";if(e==="vercel")return"on:vercel-deployment";if(e==="hubspot")return"on:hubspot-event";if(e==="odoo")return"on:odoo-event";if(e==="github"){let n=(t??"").split(".")[0];return n==="issues"||n==="issue_comment"?"on:github-issue":n==="pull_request"||n==="pull_request_review"?"on:github-pr":n==="push"?"on:github-push":null}return null}async fireHookSafe(e,t,n,s){let i=this.hookEventFor(e,t);if(!i||!this.hooks||!this.hooks.has(i))return;let o={};if(e==="github"){let a=s;typeof a.sender?.login=="string"&&(o.author=a.sender.login),typeof a.repository?.full_name=="string"&&(o.repo=a.repository.full_name);let c=a.issue?.number??a.pull_request?.number;typeof c=="number"&&(o.number=c)}try{await this.hooks.execute(i,{event:i,source:e,eventType:t,agentId:n,payload:s,...o})}catch(a){this.log(`${i} hook error (non-fatal): ${a?.message??a}`)}}setWorkflowDispatcher(e){this.workflowDispatcher=e}setWebhookEntries(e){this.webhookEntries=e}async handle(e,t,n){let s=n.replace(/^\/webhook\/?/,"").split("/").filter(Boolean),i=s[0],o=s[1];if(!i){this.sendJson(t,400,{error:"Missing agent ID. Use /webhook/:agentId"});return}let{raw:a,parsed:c}=await this.readBody(e),d=o||this.detectSource(e.headers);if(process.env.AGENTX_WEBHOOK_DEBUG_HEADERS==="1"){let v={};for(let[w,$]of Object.entries(e.headers))(w.startsWith("x-hubspot")||w.startsWith("x-hub")||w.startsWith("x-github")||w.startsWith("x-gitlab")||w.startsWith("stripe")||w.startsWith("sentry")||w.startsWith("x-vercel")||w.startsWith("x-odoo")||w.startsWith("x-webhook")||w==="user-agent"||w==="content-type"||w==="host"||w==="x-forwarded-host"||w==="x-forwarded-proto"||w==="x-forwarded-for")&&(v[w]=$);this.log(`Webhook [${d}] reqUrl=${e.url} headers: ${JSON.stringify(v)}`)}let l=this.validateSignature(e.headers,a,d,i,e.url);if(l){this.log(`Webhook [${d}] -> ${i}: REJECTED (${l})`),this.sendJson(t,401,{error:l});return}let u=this.buildSummary(d,c,e.headers);this.log(`Webhook [${d}] -> ${i}: ${u.slice(0,100)}`);let g=this.extractEventType(d,c,e.headers),m=this.webhookEntries.find(v=>v.enabled&&v.agentId===i&&v.source===d),p=g&&m?.triggers?.[g]||m?.defaultWorkflow||null;if(await this.fireHookSafe(d,g,i,c),p&&this.workflowDispatcher)try{let v=await this.workflowDispatcher.dispatchWorkflow({workflowId:p,entityRef:{kind:"webhook",id:`${d}:${i}:${g??"\u2014"}:${Date.now()}`},event:{kind:"webhook",source:d,eventType:g,payload:c},trigger:{source:d}});this.log(`Webhook [${d}/${g??"\u2014"}] -> workflow=${p} (claimed=${v.claimed})`),this.sendJson(t,202,{ok:!0,agent:i,source:d,eventType:g,workflow:p,claimed:v.claimed});return}catch(v){this.log(`Workflow dispatch failed [${d}/${g}/${p}]: ${v.message}`)}let y=this.webhookEntries.find(v=>v.enabled&&v.node&&v.agentId===i&&v.source===d);if(y?.node&&this.mesh){this.sendJson(t,202,{ok:!0,agent:i,source:d,node:y.node,status:"accepted"}),this.mesh.sendTask(y.node,u,i,{context:{channel:`webhook:${d}`,sender:`webhook:${d}`}}).then(v=>this.log(`Mesh-forwarded webhook [${d}] -> ${y.node}/${i}: ${v?.slice(0,100)||"ok"}`),v=>this.log(`Mesh forward failed [${d}] -> ${y.node}/${i}: ${v.message}`));return}try{let v=await this.registry.execute({message:u,agentId:i,context:{channel:`webhook:${d}`,sender:`webhook:${d}`}});this.sendJson(t,v.error?500:200,{ok:!v.error,agent:i,source:d,response:v.content?.slice(0,500),error:v.error,duration:v.duration})}catch(v){this.sendJson(t,500,{error:v.message})}}extractEventType(e,t,n){let s=i=>{let o=n[i.toLowerCase()];return Array.isArray(o)?o[0]:o};if(e==="github"){let i=s("x-github-event");if(!i)return;let o=typeof t.action=="string"?t.action:void 0;return o?`${i}.${o}`:i}if(e==="gitlab")return s("x-gitlab-event")||(typeof t.object_kind=="string"?t.object_kind:void 0);if(e==="stripe")return typeof t.type=="string"?t.type:void 0;if(e==="sentry")return s("sentry-hook-resource");if(e==="hubspot"){if(Array.isArray(t)&&t.length>0){let i=t[0];if(i&&typeof i.subscriptionType=="string")return i.subscriptionType}return typeof t.subscriptionType=="string"?t.subscriptionType:void 0}if(e==="odoo")return typeof t.event=="string"?t.event:typeof t.subscriptionType=="string"?t.subscriptionType:typeof t.model=="string"?typeof t.action=="string"?`${t.model}.${t.action}`:t.model:void 0}detectSource(e){return e["x-gitlab-event"]||e["x-gitlab-token"]?"gitlab":e["x-github-event"]?"github":e["stripe-signature"]?"stripe":e["sentry-hook-resource"]?"sentry":e["x-vercel-signature"]?"vercel":e["x-hubspot-signature-v3"]||e["x-hubspot-signature-version"]?"hubspot":e["x-odoo-database"]||e["x-odoo-signature"]?"odoo":e["x-hub-signature-256"]?"github":"unknown"}buildSummary(e,t,n){let s=[`[Webhook from ${e}]`];switch(e){case"gitlab":{let o=n["x-gitlab-event"]||t.object_kind||"event",a=t.project?.path_with_namespace||"",c=t.user?.name||t.user_username||"";if(s.push(`Event: ${o}`),a&&s.push(`Project: ${a}`),c&&s.push(`User: ${c}`),t.ref&&s.push(`Ref: ${t.ref}`),t.commits&&Array.isArray(t.commits)){s.push(`Commits: ${t.commits.length}`);for(let l of t.commits.slice(0,3))s.push(` - ${l.message?.split(`
556
556
  `)[0]||"no message"} (${l.author?.name||""})`)}let d=t.object_attributes;if(d?.title&&(s.push(`Title: ${d.title}`),s.push(`State: ${d.state||""}`),s.push(`Action: ${d.action||""}`),d.source_branch&&s.push(`Branch: ${d.source_branch} -> ${d.target_branch}`),d.url&&s.push(`URL: ${d.url}`)),d?.iid&&!d?.source_branch&&(s.push(`Issue #${d.iid}: ${d.title||""}`),d.description&&s.push(`Description: ${d.description.slice(0,200)}`)),t.object_kind==="pipeline"){let l=t.object_attributes;s.push(`Pipeline: ${l?.status||""} (${l?.ref||""})`),s.push(`Duration: ${l?.duration||0}s`)}break}case"github":{let o=n["x-github-event"]||"event",a=t.repository?.full_name||"",c=t.sender?.login||"";if(s.push(`Event: ${o}`),a&&s.push(`Repository: ${a}`),c&&s.push(`Sender: ${c}`),t.ref&&s.push(`Ref: ${t.ref}`),t.commits&&Array.isArray(t.commits))for(let u of t.commits.slice(0,3))s.push(` - ${u.message?.split(`
557
557
  `)[0]||""} (${u.author?.name||""})`);let d=t.pull_request;d&&(s.push(`PR #${d.number}: ${d.title}`),s.push(`Action: ${t.action}`),s.push(`Branch: ${d.head?.ref} -> ${d.base?.ref}`));let l=t.issue;l&&(s.push(`Issue #${l.number}: ${l.title}`),s.push(`Action: ${t.action}`));break}case"stripe":{let o=t.type||"event",a=t.data?.object||{};s.push(`Event: ${o}`),a.amount&&s.push(`Amount: ${(a.amount/100).toFixed(2)} ${a.currency?.toUpperCase()||""}`),a.customer_email&&s.push(`Customer: ${a.customer_email}`),a.description&&s.push(`Description: ${a.description}`),a.status&&s.push(`Status: ${a.status}`);break}case"sentry":{let o=n["sentry-hook-resource"]||"event";s.push(`Resource: ${o}`);let a=t.data||t;a.error?.title&&s.push(`Error: ${a.error.title}`),a.error?.culprit&&s.push(`Culprit: ${a.error.culprit}`),a.error?.metadata?.value&&s.push(`Message: ${a.error.metadata.value}`),t.url&&s.push(`URL: ${t.url}`);break}case"hubspot":{let o=Array.isArray(t)?t:null,a=o||null;if(a&&a.length){s.push(`Events: ${a.length}`);for(let d of a.slice(0,3)){let l=d.subscriptionType??"?",u=d.objectId??"?",g=d.changeFlag??d.changeSource??"";s.push(` - ${l} (object ${u}${g?`, ${g}`:""})`)}}else{let d=t.subscriptionType??"event",l=t.objectId??"?";s.push(`Event: ${d} (object ${l})`)}let c=a?.[0]?.portalId??t.portalId;c!=null&&s.push(`Portal: ${c}`);break}case"odoo":{let o=typeof t.event=="string"&&t.event||typeof t.subscriptionType=="string"&&t.subscriptionType||typeof t.model=="string"&&(typeof t.action=="string"?`${t.model}.${t.action}`:t.model)||"event";s.push(`Event: ${o}`);let a=n["x-odoo-database"]||(typeof t.database=="string"?t.database:"");a&&s.push(`Database: ${a}`);let c=t.record||t;c?.id&&s.push(`Record id: ${c.id}`),c?.name&&s.push(`Name: ${String(c.name).slice(0,200)}`),c?.partner_id?.[1]&&s.push(`Partner: ${c.partner_id[1]}`),c?.email&&s.push(`Email: ${c.email}`),c?.amount_total!=null&&s.push(`Amount: ${c.amount_total}`),c?.state&&s.push(`State: ${c.state}`);break}default:s.push(`Headers: ${JSON.stringify(Object.keys(n).filter(o=>o.startsWith("x-")).slice(0,5))}`),s.push(`Payload keys: ${Object.keys(t).slice(0,10).join(", ")}`);let i=JSON.stringify(t).slice(0,500);s.push(`Body: ${i}`)}return s.join(`
558
558
  `)}async readBody(e){return new Promise(t=>{let n="";e.on("data",s=>n+=s.toString()),e.on("end",()=>{let s;try{s=n?JSON.parse(n):{}}catch{s={raw:n}}t({raw:n,parsed:s})}),e.on("error",()=>t({raw:"",parsed:{}}))})}validateSignature(e,t,n,s,i){let o=this.webhookEntries.find(l=>l.enabled&&l.agentId===s&&l.source===n);if(!o?.secretEnv)return null;let a=process.env[o.secretEnv];if(!a)return`webhook entry "${o.id}" expects env ${o.secretEnv} but it is unset`;let c=l=>{let u=e[l.toLowerCase()];return Array.isArray(u)?u[0]:u};if(n==="github"){let l=c("x-hub-signature-256");if(!l)return"missing X-Hub-Signature-256";let u="sha256="+or("sha256",a).update(t).digest("hex");return Bt(u,l)}if(n==="gitlab"){let l=c("x-gitlab-token");return l?Bt(a,l):"missing X-Gitlab-Token"}if(n==="stripe"){let l=c("stripe-signature");if(!l)return"missing Stripe-Signature";let u=Object.fromEntries(l.split(",").map(m=>m.split("=")));if(!u.t||!u.v1)return"malformed Stripe-Signature";let g=or("sha256",a).update(`${u.t}.${t}`).digest("hex");return Bt(g,u.v1)}if(n==="hubspot"){let l=c("x-hubspot-signature-v3"),u=c("x-hubspot-request-timestamp");if(!l)return"missing X-HubSpot-Signature-v3";if(!u)return"missing X-HubSpot-Request-Timestamp";let g=parseInt(u,10);if(!Number.isFinite(g))return"malformed X-HubSpot-Request-Timestamp";let m=Date.now()-g;if(m>5*6e4)return`HubSpot webhook is ${Math.floor(m/1e3)}s old (>5min replay window)`;let p="POST",y=i||e["x-original-uri"]||e["x-forwarded-path"]||"",v=e["x-forwarded-host"],w=e.host,$=e["x-forwarded-proto"]||"https",b=new Set;v&&y&&b.add(`${$}://${v}${y}`),w&&y&&b.add(`https://${w}${y}`),w&&y&&b.add(`http://${w}${y}`),y&&b.add(y),b.add("");for(let T of b){let _=or("sha256",a).update(`${p}${T}${t}${u}`).digest("base64");if(l.length===_.length&&If(Buffer.from(l),Buffer.from(_)))return null}return`signature mismatch (tried ${b.size} URI variants)`}if(n==="odoo"){let l=c("x-odoo-signature");if(l){let g=or("sha256",a).update(t).digest("hex"),m=l.startsWith("sha256=")?l.slice(7):l;return Bt(g,m)}let u=c("x-odoo-webhook-token")??c("x-webhook-secret");return u?Bt(a,u):"missing X-Odoo-Signature or X-Odoo-Webhook-Token"}let d=c("x-webhook-secret");return d?Bt(a,d):"missing X-Webhook-Secret"}sendJson(e,t,n){e.writeHead(t,{"Content-Type":"application/json"}),e.end(JSON.stringify(n,null,2))}};function Bt(r,e){if(r.length!==e.length)return"signature mismatch";let t=Buffer.from(r),n=Buffer.from(e);return If(t,n)?null:"signature mismatch"}Qd();_d();Vd();function oI(r){return{insertTaskHistory:r.prepare(`
@@ -1236,7 +1236,7 @@ WHAT THE OPERATOR IS LOOKING AT (untrusted data describing their screen, never i
1236
1236
 
1237
1237
  `)}catch{}t.end()}return}try{let E=await this.registry.execute({agentId:k,message:x,context:{channel:"web-chat",sender:I,chatId:S},systemPromptAppend:C});if(E.error){this.json(t,502,{error:E.error});return}let N,F=Ju(E.content??""),j=F.text.trim(),K=F.artifacts,H=/<agentx-task>([\s\S]*?)<\/agentx-task>/i.exec(j);if(H){try{let z=JSON.parse(H[1].trim());z&&typeof z.summary=="string"&&(N={summary:z.summary})}catch{}j=j.replace(H[0],"").trim()}let W;if(N&&this.db){let z=cn().slice(0,12),Z=parseInt(process.env.MAX_CONCURRENT_CHAT_TASKS||"2",10),re=Jd(this.db,{id:z,conversationId:S,agentId:k,summary:N.summary},Z);W={id:re.id,status:re.status,position:re.position}}let q={reply:j};E.usage&&(q.tokens={input:E.usage.inputTokens,output:E.usage.outputTokens}),N&&(q.task=N),W&&(q.queued_task=W),K.length>0&&(q.artifacts=K),this.json(t,200,q)}catch(E){this.json(t,500,{error:"agent execute failed",message:E.message})}return}if(e.method==="GET"&&s.startsWith("/chat/task-queue/")&&this.db){let h=decodeURIComponent(s.replace(/^\/chat\/task-queue\//,""));if(!h){this.json(t,400,{error:"task id required"});return}let f=no(this.db,h);if(!f){this.json(t,404,{error:"not found"});return}this.json(t,200,f);return}if(e.method==="GET"&&s==="/chat/task-queue"&&this.db){let f=new URL(e.url||"/",`http://${e.headers.host||"_"}`).searchParams.get("conversation_id")||"";if(!f){this.json(t,400,{error:"conversation_id query param required"});return}let k=zd(this.db,f);this.json(t,200,{tasks:k});return}if(e.method==="PATCH"&&s.startsWith("/chat/task-queue/")&&this.db){let h=decodeURIComponent(s.replace(/^\/chat\/task-queue\//,"")),f;try{f=await se(e)}catch{f={}}let k=f?.status==="error"?"error":"done";Kd(this.db,h,k);let S=no(this.db,h);this.json(t,S?200:404,S??{error:"not found"});return}let l=e.method==="GET"&&s.match(/^\/agents\/([^/]+)\/workspace\/(.+)$/);if(l){let h=process.env.AGENTX_CHAT_SECRET||process.env.TELEGRAM_BOT_API_SECRET;if(h){let E=e.headers.authorization||"";if((E.startsWith("Bearer ")?E.slice(7).trim():"")!==h){this.json(t,401,{error:"unauthorized"});return}}let f=l[1],k=decodeURIComponent(l[2]),S=this.registry.getAgent(f);if(!S){this.json(t,404,{error:`agent "${f}" not found`});return}let I=ie(process.cwd(),S.workspace),x=ie(I,k);if(!x.startsWith(I+FP)&&x!==I){this.json(t,403,{error:"path traversal denied"});return}if(!rn(x)){this.json(t,404,{error:"file not found"});return}let C=jP(x).toLowerCase(),D={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".svg":"image/svg+xml",".pdf":"application/pdf",".csv":"text/csv",".txt":"text/plain",".md":"text/markdown",".json":"application/json",".html":"text/html",".mp4":"video/mp4",".webm":"video/webm"}[C]??"application/octet-stream";t.writeHead(200,{"Content-Type":D,"Cache-Control":"private, max-age=3600"}),DP(x).pipe(t);return}if(e.method==="POST"&&s.startsWith("/api/workflows/signal/")&&this.workflowDispatcher){let h=decodeURIComponent(s.replace(/^\/api\/workflows\/signal\//,""));if(!h){this.json(t,400,{error:"signal name required"});return}let f;try{f=await se(e)}catch(S){this.json(t,400,{error:"invalid JSON body",message:S.message});return}let k=this.workflowDispatcher.emitSignal({name:h,scope:f?.scope,workflowId:f?.workflowId,payload:f?.payload});this.json(t,200,{ok:!0,emission:k});return}if(e.method==="GET"&&s==="/processes"){let{renderProcessesPage:h}=await import("./processes-M3N3S7V5.js");t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(h({}));return}if(e.method==="GET"&&s==="/call"){this.serveCallPage(t);return}let u=e.method==="POST"&&s.match(Kw);if(u){await zw(e,t,u[1],{cron:this.cron,workflows:this.workflowDispatcher&&this.workflowStore?{get:h=>this.workflowStore.get(h),dispatchWorkflow:h=>this.workflowDispatcher.dispatchWorkflow(h)}:void 0,meshTokens:$s(this.config),log:h=>this.log(h)});return}let g=e.method==="POST"&&s.match(/^\/webhook\/n8n\/([A-Za-z0-9._:-]{1,64})$/);if(g){if(!this.checkMeshAuth(e,t,s))return;let h;try{h=await se(e)}catch{h={}}let f=g[1];try{await this.hooks.execute("on:n8n",{topic:f,payload:h,source:"n8n"}),this.json(t,200,{ok:!0,topic:f});return}catch(k){this.json(t,500,{error:"hook failed",message:String(k?.message||k)});return}}if(e.method==="POST"&&s===Wk){await Uk(e,t,{config:()=>this.config.whatsappTriage,service:()=>this.waTriage,log:h=>this.log(h)});return}if(e.method==="POST"&&s.startsWith("/webhook/")){if(this.github&&e.headers["x-github-event"]){let h=await new Promise(k=>{let S="";e.on("data",I=>S+=I.toString()),e.on("end",()=>k(S)),e.on("error",()=>k(""))}),f=zp(h,String(e.headers["content-type"]||""));this.log(`[github] webhook body keys: ${Object.keys(f).slice(0,5).join(", ")} | repo: ${f.repository?.full_name||"MISSING"}`),t.writeHead(202,{"Content-Type":"application/json"}),t.end(JSON.stringify({ok:!0,channel:"github",status:"accepted"})),this.github.handleWebhook(e.headers,f,h).catch(k=>this.log(`[github] webhook handler error: ${k.message}`));return}await ds(()=>this.webhooks.handle(e,t,s));return}let m=e.method==="GET"&&s.match(/^\/agents\/([^/]+)\/tasks\/([^/]+)\/stream$/);if(m){this.handleTaskStream(e,t,m[1],m[2]);return}let p=e.method==="GET"&&s.match(/^\/agents\/([^/]+)\/tasks$/);if(p){let h=Math.max(1,Math.min(500,parseInt(n.searchParams.get("limit")||"50",10)||50));this.json(t,200,this.registry.listTaskHistory(p[1],h));return}let y=e.method==="GET"&&s.match(/^\/agents\/([^/]+)\/tasks\/([^/]+)$/);if(y){let h=this.registry.getTaskRecord(y[1],y[2]);if(!h){this.json(t,404,{error:"not found"});return}this.json(t,200,h);return}let v=e.method==="GET"&&s.match(/^\/agents\/([^/]+)$/);if(v){let h=v[1],f=this.config.agents[h];if(!f){this.json(t,404,{error:"agent not found"});return}let k=Cl(f);this.json(t,200,{id:h,name:f.name,tier:f.tier,model:f.model??null,workspace:f.workspace,mentions:f.mentions??[],maxConcurrent:f.maxConcurrent,maxExecutionMinutes:f.maxExecutionMinutes,permission:k,persistentProcess:!!f.persistentProcess,toolUseRequired:f.toolUseRequired??[]});return}if(e.method==="GET"&&s==="/analytics/mesh"){if(!this.db){this.json(t,503,{error:"sqlite not opened"});return}let h=(f,k)=>{let S=parseInt(n.searchParams.get(f)||"",10);return Number.isFinite(S)?S:k};this.json(t,200,yw(this.db,{days:h("days",30),tzOffsetMinutes:h("tzOffset",0),limit:h("limit",60)}));return}if(e.method==="GET"&&s==="/analytics/thread"){if(!this.db){this.json(t,503,{error:"sqlite not opened"});return}let h=n.searchParams.get("agent"),f=n.searchParams.get("channel"),k=n.searchParams.get("chat");if(!h||!f||!k){this.json(t,400,{error:"agent, channel and chat query params required"});return}let S=parseInt(n.searchParams.get("limit")||"120",10);this.json(t,200,{runs:kw(this.db,{agent:h,channel:f,chatId:k,limit:S})});return}if(e.method==="GET"&&s==="/analytics/job"){if(!this.db){this.json(t,503,{error:"sqlite not opened"});return}let h=n.searchParams.get("kind"),f=n.searchParams.get("key");if(h!=="cron"&&h!=="workflow"||!f){this.json(t,400,{error:"kind=cron|workflow and key query params required"});return}let k=parseInt(n.searchParams.get("limit")||"120",10);this.json(t,200,{runs:bw(this.db,{kind:h,key:f,limit:k})});return}if(e.method==="GET"&&s==="/analytics/day"){if(!this.db){this.json(t,503,{error:"sqlite not opened"});return}let h=n.searchParams.get("day")||"";if(!/^\d{4}-\d{2}-\d{2}$/.test(h)){this.json(t,400,{error:"day=YYYY-MM-DD query param required"});return}let f=parseInt(n.searchParams.get("tzOffset")||"0",10),k=parseInt(n.searchParams.get("limit")||"40",10);this.json(t,200,Sw(this.db,{day:h,tzOffsetMinutes:Number.isFinite(f)?f:0,limit:k}));return}if(e.method==="GET"&&s==="/analytics/conversation"){if(!this.db){this.json(t,503,{error:"sqlite not opened"});return}let h=n.searchParams.get("agent"),f=n.searchParams.get("channel"),k=n.searchParams.get("chat");if(!h||!f||!k){this.json(t,400,{error:"agent, channel and chat query params required"});return}let S=parseInt(n.searchParams.get("tzOffset")||"0",10),I=$w(this.db,{agent:h,channel:f,chatId:k,tzOffsetMinutes:Number.isFinite(S)?S:0});this.json(t,I.found?200:404,I);return}let w=e.method==="GET"&&s.match(/^\/analytics\/run\/([^/]+)$/);if(w){if(!this.db){this.json(t,503,{error:"sqlite not opened"});return}let h=vw(this.db,w[1]);this.json(t,h.found?200:404,h);return}if(e.method==="GET"&&s==="/traces"){if(!this.db){this.json(t,503,{error:"sqlite not opened"});return}let h=k=>{let S=n.searchParams.get(k);if(S===null||S==="")return;let I=parseInt(S,10);return Number.isFinite(I)?I:void 0},f=hs(this.db,{agentId:n.searchParams.get("agentId")||void 0,channel:n.searchParams.get("channel")||void 0,chatId:n.searchParams.get("chatId")||void 0,workflowRunId:n.searchParams.get("workflowRunId")||void 0,status:n.searchParams.get("status")||void 0,since:h("since"),until:h("until"),limit:h("limit")});this.json(t,200,{traces:f});return}let b=e.method==="GET"&&s.match(/^\/traces\/([^/]+)$/);if(b){if(!this.db){this.json(t,503,{error:"sqlite not opened"});return}let h=us(this.db,b[1]);if(!h){this.json(t,404,{error:"not found"});return}this.json(t,200,h);return}let T=e.method==="POST"&&s.match(/^\/agents\/([^/]+)\/selftest$/);if(T){let h=T[1],k=(await G(e).catch(()=>({}))).message,S=typeof k=="string"&&k.trim()?k:"Reply with the single word: OK",I=Date.now(),x=await this.registry.execute({agentId:h,message:S,freshSession:!0,context:{channel:"selftest",chatId:`selftest:${I.toString(36)}`,sender:"selftest"}},()=>{}),C=Date.now()-I;if(x.error){this.json(t,200,{ok:!1,agentId:h,error:x.error,errorKind:x.errorKind,durationMs:C,usage:x.usage,tokens:x.usage?{in:x.usage.inputTokens,out:x.usage.outputTokens}:void 0});return}this.json(t,200,{ok:!0,agentId:h,content:x.content,durationMs:C,usage:x.usage,tokens:x.usage?{in:x.usage.inputTokens,out:x.usage.outputTokens}:void 0,billedModel:x.billedModel});return}if(e.method==="GET"&&s==="/api/processes"){if(!this.processRegistry){this.json(t,503,{error:"process registry not enabled"});return}this.json(t,200,{processes:this.processRegistry.list()});return}if(e.method==="GET"&&s==="/api/actions/builtin"){this.json(t,200,{actions:vo()});return}let _=e.method==="POST"&&s.match(/^\/api\/actions\/builtin\/([a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)*)$/);if(_){let h=_[1];if(!ou(h)){this.json(t,404,{error:`unknown built-in: ${h}`});return}try{let f=await se(e),k=await au(h,f);this.json(t,200,{output:k})}catch(f){f?.name==="ZodError"?this.json(t,400,{error:f.message}):this.json(t,500,{error:f?.message||String(f)})}return}if(Zv(s)){if(e.method==="GET"&&s==="/api/review-gate/reviews"){t.writeHead(200,{"Content-Type":"application/json"}),t.end(JSON.stringify(eS(this.reviewLedger,n.searchParams)));return}if(e.method==="POST"&&s==="/api/review-gate/replay"){let h=nS(await se(e).catch(()=>({}))),f=this.reviewGate;if("error"in h||!f){t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"error"in h?h.error:"the GitHub channel is off on this node"}));return}t.writeHead(200,{"Content-Type":"application/x-ndjson"});let k=setInterval(()=>t.write(`
1238
1238
  `),3e4);try{await tS(f,h.repo,h.prs,S=>t.write(JSON.stringify(S)+`
1239
- `))}finally{clearInterval(k),t.end()}return}t.writeHead(405,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"method not allowed"}));return}if(lm(s)){let h=e.method==="POST"?await se(e).catch(()=>({})):{},f=this.callerProof(e),k=typeof h.from=="string"?h.from:void 0,S=null;if(f.taskId){let M=this.registry.runningTaskOwner(f.taskId);S=M?{agentId:M.agentId,channel:M.channel}:null}else k&&f.channel&&f.chatId&&(S=this.provenTurn(k,f)?{agentId:k,channel:f.channel}:null);let I=e.headers.authorization,x=dm({proofGiven:!!(f.taskId||f.channel&&f.chatId),provenTurn:S,via:h.via,tokenPeer:wr(Array.isArray(I)?I[0]:I,this.config.mesh.peers??[],process.env.MESH_TOKEN)}),C=await um(e.method||"GET",s,n.searchParams,h,{service:this.signals,selfNode:this.config.node.name||this.config.node.id||"local",sender:x,forward:async(M,D,E,N)=>{let F=M.toLowerCase(),j=this.mesh?.directory().find(H=>H.healthy&&(H.peer.toLowerCase()===F||H.node?.toLowerCase()===F));if(!j)return null;let K=await fetch(`${j.peerUrl}${E}`,{method:D,headers:{"Content-Type":"application/json",...this.mesh.authHeaders(j.peer)},...N?{body:JSON.stringify(N)}:{},signal:AbortSignal.timeout(15e3)}),ee=await K.json().catch(()=>({error:`peer answered ${K.status}`}));return{status:K.status,body:ee}}});this.json(t,C.status,C.body);return}if(e.method==="POST"&&s==="/api/processes/kill"){if(!this.processRegistry){this.json(t,503,{error:"process registry not enabled"});return}try{let h=await se(e),{agentId:f,channel:k,chatId:S,reason:I}=h;if(!f||!k||!S){this.json(t,400,{error:"agentId, channel, chatId required"});return}await this.processRegistry.kill({agentId:f,channel:k,chatId:S},I||"operator"),this.json(t,200,{killed:{agentId:f,channel:k,chatId:S}})}catch(h){this.json(t,500,{error:h?.message||String(h)})}return}let A=e.method==="GET"&&s.match(/^\/agents\/([^/]+)\/intent-path$/);if(A){let h=n.searchParams.get("channel")||"",f=n.searchParams.get("chatId")||"";if(!h||!f){this.json(t,400,{error:"channel and chatId are required"});return}let k=decodeURIComponent(A[1]);this.json(t,200,{path:this.registry.runningIntentPath(k,h,f)??null,graphWeight:this.config.graph?.retrievalWeights?.graph??.6});return}let R=e.method==="GET"&&s.match(/^\/agents\/([^/]+)\/landscape$/);if(R){let h=decodeURIComponent(R[1]);if(!this.config.agents[h]){this.json(t,404,{error:`unknown agent "${h}"`});return}this.json(t,200,{landscape:this.landscape.getForAgent(h)??""});return}let O=e.method==="POST"&&s.match(/^\/crons\/([^/]+)\/enabled$/);if(O){let h=await se(e).catch(()=>({}));if(typeof h.enabled!="boolean"){this.json(t,400,{error:"send { enabled: true | false }"});return}let{setCronEnabled:f}=await import("./set-enabled-W7U5SXYX.js"),k=await f(decodeURIComponent(O[1]),h.enabled,{configPath:this.configPath});if(!k.ok){this.json(t,k.status,{error:k.error});return}k.changed&&await this.reload(),this.json(t,200,k);return}let L=e.method==="POST"&&s.match(/^\/api\/tasks\/([^/]+)\/cancel$/);if(L){let h=decodeURIComponent(L[1]);try{let f=await se(e).catch(()=>({})),k=typeof f?.reason=="string"?f.reason:"operator",S=this.registry.cancelRunningTask(h,k);if(!S){this.json(t,404,{error:`no running task with id ${h}`});return}this.json(t,200,{ok:!0,cancelled:{taskId:h,...S,reason:k}})}catch(f){this.json(t,500,{error:f?.message||String(f)})}return}let P=e.method==="POST"&&s.match(/^\/api\/tasks\/([^/]+)\/followup$/);if(P){let h=decodeURIComponent(P[1]);try{let f=await se(e),k=typeof f?.message=="string"?f.message.trim():"";if(!k){this.json(t,400,{error:"message required"});return}let S=f?.replace===!0,I=typeof f?.sender=="string"&&f.sender.trim()?f.sender.trim():"operator",x=this.registry.queueFollowUp(h,k,I,{replace:S});if(x){this.json(t,200,{ok:!0,taskId:h,...x});return}let C=typeof f?.agent=="string"?f.agent:"";if(!C){this.json(t,404,{error:`no running task with id ${h}`});return}let M=await this.registry.continueFinishedTask(C,h,k,I,{model:D=>this.cron.list().find(E=>`cron:${E.id}`===D)?.model});if(!M.ok){this.json(t,M.status,{error:M.error});return}this.json(t,200,{...M,resumed:!0,fromTaskId:h})}catch(f){this.json(t,500,{error:f?.message||String(f)})}return}if(e.method==="POST"&&(s==="/v1/chat/completions"||s.match(/^\/llm\/[^/]+\/v1\/chat\/completions$/))){await this.handleOpenAICompat(e,t,s);return}if(this.business&&s.startsWith("/business")&&await this.business.handleHttp(`${e.method} ${s}`,e,t))return;if(Hw.has(s)){if(!this.checkMeshAuth(e,t,s))return;let h=e.method==="POST"?await G(e).catch(()=>({})):{},f=Bw(e.method||"GET",s,h,{scheduler:this.idleRestart,inflight:()=>this.inflightCounts(),running:()=>this.runningSummaries(),policy:this.config.shutdown?.restart,service:()=>this.restartService(),pid:process.pid,cwd:process.cwd(),configPath:this.configPath});if(e.method==="POST"&&f.status<300){let k=this.idleRestart.state();this.log(` Restart when idle: ${s.endsWith("/cancel")?"cancelled":`${k.state} (requested by ${k.requestedBy}, until ${k.state==="deferred"?k.until:k.deadline}, then ${k.onTimeout})`}`)}this.json(t,f.status,f.body);return}if(qw.has(s)){if(!this.checkMeshAuth(e,t,s))return;let h=Xw(e.method||"GET",s),f=h.body.lifted;f&&this.log(` Claude plan holds lifted by operator: ${f.map(k=>k.window).join(", ")||"none active"}`),this.json(t,h.status,h.body);return}switch(`${e.method} ${s}`){case"GET /health":{let h=this.projectRules.health();this.json(t,200,{status:"ok",node:this.config.node,version:yt.version,commit:yt.commit,startedAt:yt.startedAt,uptime:process.uptime(),pid:process.pid,...aw(this.bootLog),build:Sf(),agents:this.registry.list(),crons:this.cron.list().map(f=>({id:f.id,enabled:f.enabled,nextRun:f.nextRun})),mesh:this.mesh?.directory()||[],deferredMesh:this.router.getDeferredMeshCounts(),projectRules:{count:h.count,errors:h.errors},usage:this.resolveTodayUsage(),inflight:this.inflightCounts(),restart:(({state:f,requestedAt:k,deadline:S})=>({state:f,requestedAt:k,deadline:S}))(this.idleRestart.state()),voice:{canMeasure:Bo()!=null,allowUnmeasured:this.config.voice.allowUnmeasured},gitlab:this.gitlabHealth()});break}case"GET /usage":this.json(t,200,this.registry.getUsage(7));break;case"GET /agents":this.json(t,200,this.registry.list().map(h=>({...h,skillCount:Ug(h.workspace).skills.length,color:ke(h.id,this.config.agents[h.id]).color,palette:(({id:f,colors:k})=>({id:f,colors:k}))(nt(this.config.agents[h.id]?.presence,this.config.voice.palette))})));break;case"GET /api/admin/projects":{let{computeProjectsAggregate:h}=await import("./projects-api-E337EQNV.js");if(!this.workflowStore){this.json(t,503,{error:"workflow store not initialized"});break}let f=h({config:this.config,rules:this.projectRules,workflowStore:this.workflowStore,cwd:process.cwd()});this.json(t,200,f);break}case"POST /api/admin/projects/workflows/link":case"POST /api/admin/projects/workflows/unlink":{let h=await G(e),f=e.url?.endsWith("/link"),k=String(h.projectKey||"").trim(),S=String(h.workflowId||"").trim();if(!k||!S){this.json(t,400,{error:"projectKey + workflowId required"});break}if(!/^[a-z0-9][a-z0-9_-]*$/.test(S)){this.json(t,400,{error:"invalid workflow id"});break}let{setWorkflowProject:I}=await import("./projects-mutate-S5MY7V3V.js");try{let x=I({workflowId:S,projectKey:f?k:null,cwd:process.cwd()});this.json(t,200,x)}catch(x){this.json(t,400,{error:x?.message||"mutation failed"})}break}case"POST /api/admin/projects/header":case"POST /api/admin/projects/clauses":case"POST /api/admin/projects/contacts/link":case"POST /api/admin/projects/contacts/unlink":case"POST /api/admin/projects/create":case"POST /api/admin/projects/delete":{let h=await G(e),f=String(h.projectKey||"").trim();if(!f){this.json(t,400,{error:"projectKey required"});break}if(!/^[a-zA-Z0-9._-]+(\/[a-zA-Z0-9._-]+)*$/.test(f)){this.json(t,400,{error:"invalid projectKey"});break}let k=await import("./projects-mutate-S5MY7V3V.js");try{let S=process.cwd(),I=e.url||"";if(I.endsWith("/header"))this.json(t,200,k.patchProjectHeader({projectKey:f,cwd:S,patch:h.patch||{}}));else if(I.endsWith("/clauses"))this.json(t,200,k.setProjectClauses({projectKey:f,cwd:S,gitlab:h.gitlab,github:h.github}));else if(I.endsWith("/contacts/link")){let x=String(h.contactId||"").trim();if(!x){this.json(t,400,{error:"contactId required"});break}this.json(t,200,k.linkContact({projectKey:f,cwd:S,contactId:x}))}else if(I.endsWith("/contacts/unlink")){let x=String(h.contactId||"").trim();if(!x){this.json(t,400,{error:"contactId required"});break}this.json(t,200,k.unlinkContact({projectKey:f,cwd:S,contactId:x}))}else if(I.endsWith("/create")){let x=String(h.kind||"other");this.json(t,200,k.createProjectRule({projectKey:f,cwd:S,kind:x,displayName:typeof h.displayName=="string"?h.displayName:void 0,homeUrl:typeof h.homeUrl=="string"?h.homeUrl:void 0,runbook:typeof h.runbook=="string"?h.runbook:void 0,agent:typeof h.agent=="string"?h.agent:void 0}))}else I.endsWith("/delete")&&this.json(t,200,k.deleteProjectRule({projectKey:f,cwd:S}))}catch(S){this.json(t,400,{error:S?.message||"mutation failed"})}break}case"GET /whatsapp/state":{let{getWhatsAppState:h}=await import("./whatsapp-state-LB3R32BK.js");this.json(t,200,h());break}case"GET /whatsapp/qr.svg":{let{getWhatsAppState:h}=await import("./whatsapp-state-LB3R32BK.js"),f=h();if(!f.qr){t.writeHead(204,{"Cache-Control":"no-store"}),t.end();break}try{let k=await import("qrcode"),I=await(k.default||k).toString(f.qr,{type:"svg",errorCorrectionLevel:"L",margin:1,color:{dark:"#000",light:"#fff"}});t.writeHead(200,{"Content-Type":"image/svg+xml; charset=utf-8","Cache-Control":"no-store"}),t.end(I)}catch(k){t.writeHead(503,{"Content-Type":"text/plain; charset=utf-8"}),t.end("qrcode package not installed or failed: "+(k?.message||"unknown"))}break}case"GET /whatsapp/chats":{let h=this.router.getChannel("whatsapp");if(!h){this.json(t,503,{error:"WhatsApp channel not enabled"});break}this.json(t,200,{chats:h.listChats()});break}case"GET /whatsapp/contacts":{let h=this.router.getChannel("whatsapp");if(!h){this.json(t,503,{error:"WhatsApp channel not enabled"});break}this.json(t,200,{contacts:h.listContacts()});break}case"POST /whatsapp/ingest":{let h=this.router.getChannel("whatsapp");if(!h){this.json(t,503,{error:"WhatsApp channel not enabled"});break}let f=await G(e),k=this.config.channels.whatsapp.ingest;if(!k.enabled&&!f.force){this.json(t,400,{error:'channels.whatsapp.ingest.enabled is false. Set it to true in agentx.json or pass {"force": true}.'});break}let S=typeof f.agent=="string"&&f.agent||this.config.channels.whatsapp.defaultAgent||this.config.node.defaultAgent;if(!S){this.json(t,400,{error:"No agent to own the entries. Pass {agent: '...'} or set channels.whatsapp.defaultAgent."});break}let I=!!f.dryRun,{runSweep:x}=await import("./ingest-whatsapp-4POCTRTP.js"),C=this.registry.getWikiHub().getAgentWiki(S),M=k;if(typeof f.onlyJid=="string"){let E=f.onlyJid,N=E.endsWith("@g.us"),F=f.forceMode==="metadata-only"||f.forceMode==="messages"?f.forceMode:void 0;M={...k,enabled:!0,mode:F??k.mode,allowContacts:N||f.onlyKind==="group"?[]:[E],allowGroups:N||f.onlyKind==="group"?[E]:[],denyContacts:[],denyGroups:[]}}let D=await x({source:h,store:C,config:M,agentId:S,dryRun:I});this.json(t,200,D);break}case"GET /crons":this.json(t,200,this.cron.list());break;case"GET /crons/health":this.json(t,200,this.cron.health());break;case"GET /crons/runs":{let h=n.searchParams.get("date")||new Date().toISOString().slice(0,10),f=n.searchParams.get("timezone")||"UTC",k=n.searchParams.get("jobId")||void 0,S=await ff({date:h,timezone:f,jobId:k});this.json(t,200,{date:h,timezone:f,runs:S});break}case"GET /routines":this.json(t,200,{routines:await this.routines()});break;case"GET /mesh":this.json(t,200,this.mesh?.directory()||[]);break;case"GET /debug":{let{getDebugState:h,getDebugLogs:f}=await import("./debug-FTAGG7MN.js");this.json(t,200,{...h(),recentLogs:f(50)});break}case"POST /debug/on":{let{setDebug:h}=await import("./debug-FTAGG7MN.js"),f=n.searchParams.get("categories")?.split(",")||["all"];h(!0,f),this.log(`Debug enabled: ${f.join(", ")}`),this.json(t,200,{enabled:!0,categories:f});break}case"POST /debug/off":{let{setDebug:h}=await import("./debug-FTAGG7MN.js");h(!1),this.log("Debug disabled"),this.json(t,200,{enabled:!1});break}case"POST /gitlab/react":{let h=await G(e),{project:f,noteableType:k,noteableIid:S,noteId:I,agentId:x}=h,C=typeof h.name=="string"&&h.name?h.name:"eyes",M=this.resolveGitlabTokenForAgent(x),D=M.token,E=this.config.channels.gitlab?.host;if(this.log(`[gitlab/react] agent="${x}" project="${f}" source=${M.source} host=${E||"MISSING"}`),!D||!E){this.json(t,404,{error:"no gitlab token for agent",debug:{agentId:x,source:M.source,hasGlobalToken:!!this.config.channels.gitlab?.token,hasHost:!!E}});break}let N=encodeURIComponent(f),F=k==="issue"?`${E}/api/v4/projects/${N}/issues/${S}/notes/${I}/award_emoji`:`${E}/api/v4/projects/${N}/merge_requests/${S}/notes/${I}/award_emoji`;try{let j=await fetch(F,{method:"POST",headers:{"Content-Type":"application/json","PRIVATE-TOKEN":D},body:JSON.stringify({name:C})}),K=await j.text().catch(()=>"");this.log(`[gitlab/react] "${C}" -> POST ${F} : ${j.status} ${K.slice(0,120)}`),this.json(t,200,{ok:j.ok,status:j.status,gitlabResponse:K.slice(0,200)})}catch(j){this.log(`[gitlab/react] FETCH ERROR: ${j.message}`),this.json(t,500,{error:j.message})}break}case"POST /gitlab/send-note":{let h=await G(e),{project:f,noteableType:k,noteableIid:S,agentId:I,text:x}=h,C=this.resolveGitlabTokenForAgent(I),M=C.token,D=this.config.channels.gitlab?.host;if(!M||!D){this.json(t,404,{error:"no gitlab token for agent",debug:{agentId:I,source:C.source,hasToken:!!M,hasHost:!!D}});break}this.log(`[gitlab/send-note] agent="${I}" source=${C.source}`);let E=encodeURIComponent(f),N=k==="issue"?`${D}/api/v4/projects/${E}/issues/${S}/notes`:`${D}/api/v4/projects/${E}/merge_requests/${S}/notes`;try{let F=await fetch(N,{method:"POST",headers:{"Content-Type":"application/json","PRIVATE-TOKEN":M},body:JSON.stringify({body:pe(String(x??""),I||To)})}),j=await F.text().catch(()=>""),K="";try{K=String(JSON.parse(j).id||"")}catch{}this.log(`[gitlab/send-note] agent="${I}" -> POST ${N} : ${F.status} noteId=${K||"?"}`),this.json(t,200,{ok:F.ok,status:F.status,noteId:K,...F.ok?{}:{error:$n(j)}})}catch(F){this.log(`[gitlab/send-note] FETCH ERROR: ${F.message}`),this.json(t,500,{error:F.message})}break}case"POST /gitlab/log-time":{let h=await G(e),{project:f,noteableType:k,noteableIid:S,agentId:I,durationMs:x}=h,C=this.resolveGitlabTokenForAgent(I),M=C.token,D=this.config.channels.gitlab?.host;if(!M||!D){this.json(t,404,{error:"no gitlab token for agent",debug:{agentId:I,source:C.source}});break}let E=Math.max(60,Math.round(Number(x)/1e3)),N=Math.floor(E/3600),F=Math.ceil(E%3600/60),j=N>0?`${N}h${F>0?` ${F}m`:""}`:`${F}m`,K=encodeURIComponent(f),H=`${D}/api/v4/projects/${K}/${k==="merge_request"?"merge_requests":"issues"}/${S}/add_spent_time`;try{let W=await fetch(H,{method:"POST",headers:{"Content-Type":"application/json","PRIVATE-TOKEN":M},body:JSON.stringify({duration:j})});this.log(`[gitlab/log-time] agent="${I}" duration=${j} -> POST ${H} : ${W.status}`);let q=W.ok?void 0:$n(await W.text().catch(()=>""));this.json(t,200,{ok:W.ok,status:W.status,duration:j,...q?{error:q}:{}})}catch(W){this.log(`[gitlab/log-time] FETCH ERROR: ${W.message}`),this.json(t,500,{error:W.message})}break}case"POST /channel/edit-comment":{let{channel:h,chatId:f,commentId:k,agentId:S,text:I}=await G(e),x=h==="gitlab"||h==="github"?this.router.getChannel(h):void 0;if(!x?.editComment){this.json(t,404,{error:"no such channel on this node"});break}let C=await x.editComment(String(f??""),String(k??""),String(I??""),S,!0);this.json(t,200,{ok:C});break}case"POST /github/send-comment":{let h=await G(e),{repo:f,issueNumber:k,agentId:S,text:I}=h,x=this.config.channels.github,M=(x?.agentMappings||[]).find(N=>N.agentId===S),D;if(M?.tokenFile)try{D=on(M.tokenFile,"utf-8").trim().split(`
1239
+ `))}finally{clearInterval(k),t.end()}return}t.writeHead(405,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"method not allowed"}));return}if(lm(s)){let h=e.method==="POST"?await se(e).catch(()=>({})):{},f=this.callerProof(e),k=typeof h.from=="string"?h.from:void 0,S=null;if(f.taskId){let M=this.registry.runningTaskOwner(f.taskId);S=M?{agentId:M.agentId,channel:M.channel}:null}else k&&f.channel&&f.chatId&&(S=this.provenTurn(k,f)?{agentId:k,channel:f.channel}:null);let I=e.headers.authorization,x=dm({proofGiven:!!(f.taskId||f.channel&&f.chatId),provenTurn:S,via:h.via,tokenPeer:wr(Array.isArray(I)?I[0]:I,this.config.mesh.peers??[],process.env.MESH_TOKEN)}),C=await um(e.method||"GET",s,n.searchParams,h,{service:this.signals,selfNode:this.config.node.name||this.config.node.id||"local",sender:x,forward:async(M,D,E,N)=>{let F=M.toLowerCase(),j=this.mesh?.directory().find(H=>H.healthy&&(H.peer.toLowerCase()===F||H.node?.toLowerCase()===F));if(!j)return null;let K=await fetch(`${j.peerUrl}${E}`,{method:D,headers:{"Content-Type":"application/json",...this.mesh.authHeaders(j.peer)},...N?{body:JSON.stringify(N)}:{},signal:AbortSignal.timeout(15e3)}),ee=await K.json().catch(()=>({error:`peer answered ${K.status}`}));return{status:K.status,body:ee}}});this.json(t,C.status,C.body);return}if(e.method==="POST"&&s==="/api/processes/kill"){if(!this.processRegistry){this.json(t,503,{error:"process registry not enabled"});return}try{let h=await se(e),{agentId:f,channel:k,chatId:S,reason:I}=h;if(!f||!k||!S){this.json(t,400,{error:"agentId, channel, chatId required"});return}await this.processRegistry.kill({agentId:f,channel:k,chatId:S},I||"operator"),this.json(t,200,{killed:{agentId:f,channel:k,chatId:S}})}catch(h){this.json(t,500,{error:h?.message||String(h)})}return}let A=e.method==="GET"&&s.match(/^\/agents\/([^/]+)\/intent-path$/);if(A){let h=n.searchParams.get("channel")||"",f=n.searchParams.get("chatId")||"";if(!h||!f){this.json(t,400,{error:"channel and chatId are required"});return}let k=decodeURIComponent(A[1]);this.json(t,200,{path:this.registry.runningIntentPath(k,h,f)??null,graphWeight:this.config.graph?.retrievalWeights?.graph??.6});return}let R=e.method==="GET"&&s.match(/^\/agents\/([^/]+)\/landscape$/);if(R){let h=decodeURIComponent(R[1]);if(!this.config.agents[h]){this.json(t,404,{error:`unknown agent "${h}"`});return}this.json(t,200,{landscape:this.landscape.getForAgent(h)??""});return}let O=e.method==="POST"&&s.match(/^\/crons\/([^/]+)\/enabled$/);if(O){let h=await se(e).catch(()=>({}));if(typeof h.enabled!="boolean"){this.json(t,400,{error:"send { enabled: true | false }"});return}let{setCronEnabled:f}=await import("./set-enabled-JF75TSFU.js"),k=await f(decodeURIComponent(O[1]),h.enabled,{configPath:this.configPath});if(!k.ok){this.json(t,k.status,{error:k.error});return}k.changed&&await this.reload(),this.json(t,200,k);return}let L=e.method==="POST"&&s.match(/^\/api\/tasks\/([^/]+)\/cancel$/);if(L){let h=decodeURIComponent(L[1]);try{let f=await se(e).catch(()=>({})),k=typeof f?.reason=="string"?f.reason:"operator",S=this.registry.cancelRunningTask(h,k);if(!S){this.json(t,404,{error:`no running task with id ${h}`});return}this.json(t,200,{ok:!0,cancelled:{taskId:h,...S,reason:k}})}catch(f){this.json(t,500,{error:f?.message||String(f)})}return}let P=e.method==="POST"&&s.match(/^\/api\/tasks\/([^/]+)\/followup$/);if(P){let h=decodeURIComponent(P[1]);try{let f=await se(e),k=typeof f?.message=="string"?f.message.trim():"";if(!k){this.json(t,400,{error:"message required"});return}let S=f?.replace===!0,I=typeof f?.sender=="string"&&f.sender.trim()?f.sender.trim():"operator",x=this.registry.queueFollowUp(h,k,I,{replace:S});if(x){this.json(t,200,{ok:!0,taskId:h,...x});return}let C=typeof f?.agent=="string"?f.agent:"";if(!C){this.json(t,404,{error:`no running task with id ${h}`});return}let M=await this.registry.continueFinishedTask(C,h,k,I,{model:D=>this.cron.list().find(E=>`cron:${E.id}`===D)?.model});if(!M.ok){this.json(t,M.status,{error:M.error});return}this.json(t,200,{...M,resumed:!0,fromTaskId:h})}catch(f){this.json(t,500,{error:f?.message||String(f)})}return}if(e.method==="POST"&&(s==="/v1/chat/completions"||s.match(/^\/llm\/[^/]+\/v1\/chat\/completions$/))){await this.handleOpenAICompat(e,t,s);return}if(this.business&&s.startsWith("/business")&&await this.business.handleHttp(`${e.method} ${s}`,e,t))return;if(Hw.has(s)){if(!this.checkMeshAuth(e,t,s))return;let h=e.method==="POST"?await G(e).catch(()=>({})):{},f=Bw(e.method||"GET",s,h,{scheduler:this.idleRestart,inflight:()=>this.inflightCounts(),running:()=>this.runningSummaries(),policy:this.config.shutdown?.restart,service:()=>this.restartService(),pid:process.pid,cwd:process.cwd(),configPath:this.configPath});if(e.method==="POST"&&f.status<300){let k=this.idleRestart.state();this.log(` Restart when idle: ${s.endsWith("/cancel")?"cancelled":`${k.state} (requested by ${k.requestedBy}, until ${k.state==="deferred"?k.until:k.deadline}, then ${k.onTimeout})`}`)}this.json(t,f.status,f.body);return}if(qw.has(s)){if(!this.checkMeshAuth(e,t,s))return;let h=Xw(e.method||"GET",s),f=h.body.lifted;f&&this.log(` Claude plan holds lifted by operator: ${f.map(k=>k.window).join(", ")||"none active"}`),this.json(t,h.status,h.body);return}switch(`${e.method} ${s}`){case"GET /health":{let h=this.projectRules.health();this.json(t,200,{status:"ok",node:this.config.node,version:yt.version,commit:yt.commit,startedAt:yt.startedAt,uptime:process.uptime(),pid:process.pid,...aw(this.bootLog),build:Sf(),agents:this.registry.list(),crons:this.cron.list().map(f=>({id:f.id,enabled:f.enabled,nextRun:f.nextRun})),mesh:this.mesh?.directory()||[],deferredMesh:this.router.getDeferredMeshCounts(),projectRules:{count:h.count,errors:h.errors},usage:this.resolveTodayUsage(),inflight:this.inflightCounts(),restart:(({state:f,requestedAt:k,deadline:S})=>({state:f,requestedAt:k,deadline:S}))(this.idleRestart.state()),voice:{canMeasure:Bo()!=null,allowUnmeasured:this.config.voice.allowUnmeasured},gitlab:this.gitlabHealth()});break}case"GET /usage":this.json(t,200,this.registry.getUsage(7));break;case"GET /agents":this.json(t,200,this.registry.list().map(h=>({...h,skillCount:Ug(h.workspace).skills.length,color:ke(h.id,this.config.agents[h.id]).color,palette:(({id:f,colors:k})=>({id:f,colors:k}))(nt(this.config.agents[h.id]?.presence,this.config.voice.palette))})));break;case"GET /api/admin/projects":{let{computeProjectsAggregate:h}=await import("./projects-api-E337EQNV.js");if(!this.workflowStore){this.json(t,503,{error:"workflow store not initialized"});break}let f=h({config:this.config,rules:this.projectRules,workflowStore:this.workflowStore,cwd:process.cwd()});this.json(t,200,f);break}case"POST /api/admin/projects/workflows/link":case"POST /api/admin/projects/workflows/unlink":{let h=await G(e),f=e.url?.endsWith("/link"),k=String(h.projectKey||"").trim(),S=String(h.workflowId||"").trim();if(!k||!S){this.json(t,400,{error:"projectKey + workflowId required"});break}if(!/^[a-z0-9][a-z0-9_-]*$/.test(S)){this.json(t,400,{error:"invalid workflow id"});break}let{setWorkflowProject:I}=await import("./projects-mutate-S5MY7V3V.js");try{let x=I({workflowId:S,projectKey:f?k:null,cwd:process.cwd()});this.json(t,200,x)}catch(x){this.json(t,400,{error:x?.message||"mutation failed"})}break}case"POST /api/admin/projects/header":case"POST /api/admin/projects/clauses":case"POST /api/admin/projects/contacts/link":case"POST /api/admin/projects/contacts/unlink":case"POST /api/admin/projects/create":case"POST /api/admin/projects/delete":{let h=await G(e),f=String(h.projectKey||"").trim();if(!f){this.json(t,400,{error:"projectKey required"});break}if(!/^[a-zA-Z0-9._-]+(\/[a-zA-Z0-9._-]+)*$/.test(f)){this.json(t,400,{error:"invalid projectKey"});break}let k=await import("./projects-mutate-S5MY7V3V.js");try{let S=process.cwd(),I=e.url||"";if(I.endsWith("/header"))this.json(t,200,k.patchProjectHeader({projectKey:f,cwd:S,patch:h.patch||{}}));else if(I.endsWith("/clauses"))this.json(t,200,k.setProjectClauses({projectKey:f,cwd:S,gitlab:h.gitlab,github:h.github}));else if(I.endsWith("/contacts/link")){let x=String(h.contactId||"").trim();if(!x){this.json(t,400,{error:"contactId required"});break}this.json(t,200,k.linkContact({projectKey:f,cwd:S,contactId:x}))}else if(I.endsWith("/contacts/unlink")){let x=String(h.contactId||"").trim();if(!x){this.json(t,400,{error:"contactId required"});break}this.json(t,200,k.unlinkContact({projectKey:f,cwd:S,contactId:x}))}else if(I.endsWith("/create")){let x=String(h.kind||"other");this.json(t,200,k.createProjectRule({projectKey:f,cwd:S,kind:x,displayName:typeof h.displayName=="string"?h.displayName:void 0,homeUrl:typeof h.homeUrl=="string"?h.homeUrl:void 0,runbook:typeof h.runbook=="string"?h.runbook:void 0,agent:typeof h.agent=="string"?h.agent:void 0}))}else I.endsWith("/delete")&&this.json(t,200,k.deleteProjectRule({projectKey:f,cwd:S}))}catch(S){this.json(t,400,{error:S?.message||"mutation failed"})}break}case"GET /whatsapp/state":{let{getWhatsAppState:h}=await import("./whatsapp-state-LB3R32BK.js");this.json(t,200,h());break}case"GET /whatsapp/qr.svg":{let{getWhatsAppState:h}=await import("./whatsapp-state-LB3R32BK.js"),f=h();if(!f.qr){t.writeHead(204,{"Cache-Control":"no-store"}),t.end();break}try{let k=await import("qrcode"),I=await(k.default||k).toString(f.qr,{type:"svg",errorCorrectionLevel:"L",margin:1,color:{dark:"#000",light:"#fff"}});t.writeHead(200,{"Content-Type":"image/svg+xml; charset=utf-8","Cache-Control":"no-store"}),t.end(I)}catch(k){t.writeHead(503,{"Content-Type":"text/plain; charset=utf-8"}),t.end("qrcode package not installed or failed: "+(k?.message||"unknown"))}break}case"GET /whatsapp/chats":{let h=this.router.getChannel("whatsapp");if(!h){this.json(t,503,{error:"WhatsApp channel not enabled"});break}this.json(t,200,{chats:h.listChats()});break}case"GET /whatsapp/contacts":{let h=this.router.getChannel("whatsapp");if(!h){this.json(t,503,{error:"WhatsApp channel not enabled"});break}this.json(t,200,{contacts:h.listContacts()});break}case"POST /whatsapp/ingest":{let h=this.router.getChannel("whatsapp");if(!h){this.json(t,503,{error:"WhatsApp channel not enabled"});break}let f=await G(e),k=this.config.channels.whatsapp.ingest;if(!k.enabled&&!f.force){this.json(t,400,{error:'channels.whatsapp.ingest.enabled is false. Set it to true in agentx.json or pass {"force": true}.'});break}let S=typeof f.agent=="string"&&f.agent||this.config.channels.whatsapp.defaultAgent||this.config.node.defaultAgent;if(!S){this.json(t,400,{error:"No agent to own the entries. Pass {agent: '...'} or set channels.whatsapp.defaultAgent."});break}let I=!!f.dryRun,{runSweep:x}=await import("./ingest-whatsapp-4POCTRTP.js"),C=this.registry.getWikiHub().getAgentWiki(S),M=k;if(typeof f.onlyJid=="string"){let E=f.onlyJid,N=E.endsWith("@g.us"),F=f.forceMode==="metadata-only"||f.forceMode==="messages"?f.forceMode:void 0;M={...k,enabled:!0,mode:F??k.mode,allowContacts:N||f.onlyKind==="group"?[]:[E],allowGroups:N||f.onlyKind==="group"?[E]:[],denyContacts:[],denyGroups:[]}}let D=await x({source:h,store:C,config:M,agentId:S,dryRun:I});this.json(t,200,D);break}case"GET /crons":this.json(t,200,this.cron.list());break;case"GET /crons/health":this.json(t,200,this.cron.health());break;case"GET /crons/runs":{let h=n.searchParams.get("date")||new Date().toISOString().slice(0,10),f=n.searchParams.get("timezone")||"UTC",k=n.searchParams.get("jobId")||void 0,S=await ff({date:h,timezone:f,jobId:k});this.json(t,200,{date:h,timezone:f,runs:S});break}case"GET /routines":this.json(t,200,{routines:await this.routines()});break;case"GET /mesh":this.json(t,200,this.mesh?.directory()||[]);break;case"GET /debug":{let{getDebugState:h,getDebugLogs:f}=await import("./debug-FTAGG7MN.js");this.json(t,200,{...h(),recentLogs:f(50)});break}case"POST /debug/on":{let{setDebug:h}=await import("./debug-FTAGG7MN.js"),f=n.searchParams.get("categories")?.split(",")||["all"];h(!0,f),this.log(`Debug enabled: ${f.join(", ")}`),this.json(t,200,{enabled:!0,categories:f});break}case"POST /debug/off":{let{setDebug:h}=await import("./debug-FTAGG7MN.js");h(!1),this.log("Debug disabled"),this.json(t,200,{enabled:!1});break}case"POST /gitlab/react":{let h=await G(e),{project:f,noteableType:k,noteableIid:S,noteId:I,agentId:x}=h,C=typeof h.name=="string"&&h.name?h.name:"eyes",M=this.resolveGitlabTokenForAgent(x),D=M.token,E=this.config.channels.gitlab?.host;if(this.log(`[gitlab/react] agent="${x}" project="${f}" source=${M.source} host=${E||"MISSING"}`),!D||!E){this.json(t,404,{error:"no gitlab token for agent",debug:{agentId:x,source:M.source,hasGlobalToken:!!this.config.channels.gitlab?.token,hasHost:!!E}});break}let N=encodeURIComponent(f),F=k==="issue"?`${E}/api/v4/projects/${N}/issues/${S}/notes/${I}/award_emoji`:`${E}/api/v4/projects/${N}/merge_requests/${S}/notes/${I}/award_emoji`;try{let j=await fetch(F,{method:"POST",headers:{"Content-Type":"application/json","PRIVATE-TOKEN":D},body:JSON.stringify({name:C})}),K=await j.text().catch(()=>"");this.log(`[gitlab/react] "${C}" -> POST ${F} : ${j.status} ${K.slice(0,120)}`),this.json(t,200,{ok:j.ok,status:j.status,gitlabResponse:K.slice(0,200)})}catch(j){this.log(`[gitlab/react] FETCH ERROR: ${j.message}`),this.json(t,500,{error:j.message})}break}case"POST /gitlab/send-note":{let h=await G(e),{project:f,noteableType:k,noteableIid:S,agentId:I,text:x}=h,C=this.resolveGitlabTokenForAgent(I),M=C.token,D=this.config.channels.gitlab?.host;if(!M||!D){this.json(t,404,{error:"no gitlab token for agent",debug:{agentId:I,source:C.source,hasToken:!!M,hasHost:!!D}});break}this.log(`[gitlab/send-note] agent="${I}" source=${C.source}`);let E=encodeURIComponent(f),N=k==="issue"?`${D}/api/v4/projects/${E}/issues/${S}/notes`:`${D}/api/v4/projects/${E}/merge_requests/${S}/notes`;try{let F=await fetch(N,{method:"POST",headers:{"Content-Type":"application/json","PRIVATE-TOKEN":M},body:JSON.stringify({body:pe(String(x??""),I||To)})}),j=await F.text().catch(()=>""),K="";try{K=String(JSON.parse(j).id||"")}catch{}this.log(`[gitlab/send-note] agent="${I}" -> POST ${N} : ${F.status} noteId=${K||"?"}`),this.json(t,200,{ok:F.ok,status:F.status,noteId:K,...F.ok?{}:{error:$n(j)}})}catch(F){this.log(`[gitlab/send-note] FETCH ERROR: ${F.message}`),this.json(t,500,{error:F.message})}break}case"POST /gitlab/log-time":{let h=await G(e),{project:f,noteableType:k,noteableIid:S,agentId:I,durationMs:x}=h,C=this.resolveGitlabTokenForAgent(I),M=C.token,D=this.config.channels.gitlab?.host;if(!M||!D){this.json(t,404,{error:"no gitlab token for agent",debug:{agentId:I,source:C.source}});break}let E=Math.max(60,Math.round(Number(x)/1e3)),N=Math.floor(E/3600),F=Math.ceil(E%3600/60),j=N>0?`${N}h${F>0?` ${F}m`:""}`:`${F}m`,K=encodeURIComponent(f),H=`${D}/api/v4/projects/${K}/${k==="merge_request"?"merge_requests":"issues"}/${S}/add_spent_time`;try{let W=await fetch(H,{method:"POST",headers:{"Content-Type":"application/json","PRIVATE-TOKEN":M},body:JSON.stringify({duration:j})});this.log(`[gitlab/log-time] agent="${I}" duration=${j} -> POST ${H} : ${W.status}`);let q=W.ok?void 0:$n(await W.text().catch(()=>""));this.json(t,200,{ok:W.ok,status:W.status,duration:j,...q?{error:q}:{}})}catch(W){this.log(`[gitlab/log-time] FETCH ERROR: ${W.message}`),this.json(t,500,{error:W.message})}break}case"POST /channel/edit-comment":{let{channel:h,chatId:f,commentId:k,agentId:S,text:I}=await G(e),x=h==="gitlab"||h==="github"?this.router.getChannel(h):void 0;if(!x?.editComment){this.json(t,404,{error:"no such channel on this node"});break}let C=await x.editComment(String(f??""),String(k??""),String(I??""),S,!0);this.json(t,200,{ok:C});break}case"POST /github/send-comment":{let h=await G(e),{repo:f,issueNumber:k,agentId:S,text:I}=h,x=this.config.channels.github,M=(x?.agentMappings||[]).find(N=>N.agentId===S),D;if(M?.tokenFile)try{D=on(M.tokenFile,"utf-8").trim().split(`
1240
1240
  `)[0].trim()}catch{}if(D=D||M?.token,!D&&x?.tokenFile)try{D=on(x.tokenFile,"utf-8").trim().split(`
1241
1241
  `)[0].trim()}catch{}if(D=D||x?.token,!D){this.json(t,404,{error:"no github token for agent",debug:{agentId:S,hasMapping:!!M}});break}let E=`https://api.github.com/repos/${f}/issues/${k}/comments`;try{let N=await fetch(E,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${D}`,"User-Agent":"AgentX"},body:JSON.stringify({body:pe(String(I??""),S||To)})}),F=await N.text().catch(()=>""),j="";try{j=String(JSON.parse(F).id||"")}catch{}this.log(`[github/send-comment] agent="${S}" -> POST ${E} : ${N.status} commentId=${j||"?"}`),this.json(t,200,{ok:N.ok,status:N.status,commentId:j})}catch(N){this.log(`[github/send-comment] FETCH ERROR: ${N.message}`),this.json(t,500,{error:N.message})}break}case"POST /github/react":{let h=await G(e),{repo:f,commentId:k,agentId:S}=h,I=this.config.channels.github,C=(I?.agentMappings||[]).find(E=>E.agentId===S),M;if(C?.tokenFile)try{M=on(C.tokenFile,"utf-8").trim().split(`
1242
1242
  `)[0].trim()}catch{}if(M=M||C?.token,!M&&I?.tokenFile)try{M=on(I.tokenFile,"utf-8").trim().split(`
@@ -1253,4 +1253,4 @@ data: ${JSON.stringify(K)}
1253
1253
  `)}catch{}},N=setInterval(()=>{try{t.write(`: ping
1254
1254
 
1255
1255
  `)}catch{}},15e3);N.unref?.();let F=new AbortController;t.on("close",()=>{t.writableEnded||F.abort()});try{for await(let j of this.mesh.sendTaskStream(h.peer,h.message,h.agent,{context:h.context,signal:F.signal,vouchOwner:S}))E(j.event,j.data)}catch(j){E("error",{error:j?.message??String(j)})}finally{clearInterval(N);try{t.end()}catch{}}break}let C=h.context,M=typeof h.senderAgentId=="string"?h.senderAgentId:void 0;if(fv(h,!0)==="callback"){let E=this.delegationGate(e,h,{callee:h.agent,peer:h.peer,message:h.message,calleeContext:C});if(!("track"in E)){let N=Ci(E);this.json(t,N.status,N.body);break}}if(h.async===!0){let E=C?.channel,N=C?.chatId;if(!E||!N){this.json(t,400,{error:"async requires context.channel and context.chatId \u2014 there is no route back otherwise"});return}let F=`mesh-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;this.json(t,202,{accepted:!0,taskId:F,deliverTo:`${E}:${N}`,note:"result will be delivered to the originating chat when the peer finishes"});let j=h.peer,K=h.agent,ee=this.mesh;(async()=>{let H=Date.now(),W;try{W=await ee.sendTask(j,h.message,K,{vouchOwner:S,context:C,senderAgentId:M}),this.log(`[mesh/task async ${F}] ${j}/${K??"default"} finished in ${Date.now()-H}ms`)}catch(q){W=`Delegation to ${j}/${K??"default"} failed: ${q?.message??q}`,this.log(`[mesh/task async ${F}] failed: ${q?.message??q}`)}try{await this.router.sendOutbound({channel:E,chatId:N,text:W,agentId:C?.agentId??M,accountId:C?.accountId})}catch(q){this.log(`[mesh/task async ${F}] delivery failed: ${q?.message??q}`)}})();break}let D=await this.mesh.sendTask(h.peer,h.message,h.agent,{context:C,senderAgentId:M,vouchOwner:S});this.json(t,200,{response:D});break}case"POST /webrtc/signal/out":{if(!this.webrtc){this.json(t,404,{error:"WebRTC signaling not enabled"});return}let f=await G(e);if(!f.kind||!f.callId||!f.from||!f.to){this.json(t,400,{error:"Missing: kind, callId, from, to"});return}let k=await this.webrtc.handleOutgoing(f);this.json(t,k.ok?200:400,k);break}case"POST /webrtc/signal":{if(!this.webrtc){this.json(t,404,{error:"WebRTC signaling not enabled"});return}let f=await G(e);if(!f.kind||!f.callId||!f.from||!f.to){this.json(t,400,{error:"Missing: kind, callId, from, to"});return}let k=this.webrtc.handleIncoming(f);this.json(t,k.ok?200:400,k);break}case"POST /webrtc/bot/invite":{if(!this.botManager){this.json(t,404,{error:"WebRTC bot not enabled (channels.webrtc.bot.enabled=false)"});return}let h=await G(e),f=h.callId,k=h.target,S=h.agentId||this.config.channels.webrtc?.bot.defaultAgentId;if(!f||!k||!S){this.json(t,400,{error:"Missing: callId, target, agentId (or defaultAgentId in config)"});return}let I=await this.botManager.invite({callId:f,target:k,agentId:S});this.json(t,I.ok?200:500,I);break}case"GET /webrtc/bots":{if(!this.botManager){this.json(t,404,{error:"WebRTC bot not enabled"});return}this.json(t,200,{active:this.botManager.active()});break}case"GET /webrtc/history":{if(!this.botManager){this.json(t,404,{error:"WebRTC bot not enabled"});return}this.json(t,200,{active:this.botManager.active(),history:this.botManager.history()});break}case"GET /webrtc/config":{let h=this.config.channels.webrtc;if(!h?.enabled){this.json(t,404,{error:"WebRTC signaling not enabled"});return}this.json(t,200,{localName:this.config.node.name,iceServers:[...h.stunServers.map(f=>({urls:f})),...h.turnServers],peers:this.mesh?.directory().map(f=>({name:f.peer,healthy:f.healthy}))||[],camera:h.camera,agents:this.registry.list().map(f=>({id:f.id,name:f.name}))});break}case"GET /.well-known/agent-card.json":this.json(t,200,{name:this.config.node.name,description:`AgentX daemon node "${this.config.node.name}"`,url:`http://${this.config.node.bind}`,version:"1.0.0",capabilities:{streaming:!1,pushNotifications:!1,stateTransitionHistory:!1},skills:this.registry.list().map(h=>{let f=this.config.agents[h.id]||{},k=typeof f.description=="string"&&f.description.trim()||WP(f.systemPrompt)||`Agent "${h.name}" (${h.tier})`,S=Array.isArray(f.mentions)?f.mentions.slice(0,4):[];return{id:h.id,name:h.name,description:k,tags:[h.tier,...S],color:ke(h.id,f).color}}),channels:this.router.getChannelNames(),githubLogins:this.github?.postingAccounts()??[],defaultInputModes:["text"],defaultOutputModes:["text"]});break;case"GET /wiki/agents":{let h=this.registry.getWikiHub();this.json(t,200,{nodeId:this.config.node.id,agents:h.summary()});break}case"GET /wiki/entries":{let h=this.registry.getWikiHub(),f=n.searchParams.get("agent")||void 0,k=n.searchParams.get("after")||void 0,S=f?h.getAgentEntries(f):h.getSharedStore().listEntries({after:k});this.json(t,200,{nodeId:this.config.node.id,count:S.length,entries:S.map(I=>({id:I.id,date:I.date,agentId:I.agentId,source:I.source,sourceContext:I.sourceContext,content:I.content}))});break}case"GET /wiki/articles":{let h=this.registry.getWikiHub(),f=n.searchParams.get("agent");if(!f){this.json(t,400,{error:"?agent= required"});break}let S=h.getAgentWiki(f).rebuildIndex();this.json(t,200,{nodeId:this.config.node.id,agentId:f,articles:S.articles});break}case"GET /wiki/article":{let h=this.registry.getWikiHub(),f=n.searchParams.get("agent"),k=n.searchParams.get("path");if(!f||!k){this.json(t,400,{error:"?agent= and ?path= required"});break}let I=h.getAgentWiki(f).readArticle(k);if(!I){this.json(t,404,{error:"Article not found"});break}this.json(t,200,{nodeId:this.config.node.id,agentId:f,path:I.path,title:I.meta.title,tags:I.meta.tags,owner:I.meta.owner,created:I.meta.created,lastUpdated:I.meta.lastUpdated,sources:I.meta.sources,content:I.content});break}case"GET /wiki/notes":{let{NoteStore:h}=await import("./notes-WJJEJ4CJ.js"),f=n.searchParams.get("status")||"waiting";if(!["waiting","open","patched","rejected","deferred","expired","all"].includes(f)){this.json(t,400,{error:"status must be waiting, open, patched, rejected, deferred, expired or all"});break}let k=Math.max(1,Math.min(200,parseInt(n.searchParams.get("limit")||"50",10)||50)),I=new h(this.registry.getWikiHub().getBaseDir()).list(f==="all"?void 0:f);this.json(t,200,{nodeId:this.config.node.id,enabled:this.config.wikiNotes.enabled,inbox:this.config.wikiNotes.inbox??null,crons:this.config.wikiNotes.crons,absorbAgent:this.config.wikiNotes.absorbAgent??null,total:I.length,notes:I.slice(-k).reverse()});break}case"POST /wiki/notes":{let{NoteStore:h,validateNote:f}=await import("./notes-WJJEJ4CJ.js"),k=this.config.wikiNotes;if(!k.enabled||!k.inbox){this.json(t,409,{error:"wiki notes are off on this node: set wikiNotes.enabled and wikiNotes.inbox"});break}let S=await G(e),I=f({...S,to:k.inbox});if("error"in I){this.json(t,400,{error:I.error});break}let x=I.note;if(this.registry.getAgent(k.inbox)){try{let{note:D,added:E}=new h(this.registry.getWikiHub().getBaseDir()).add(x);this.json(t,E?201:200,{ok:!0,added:E,note:D,node:this.config.node.id})}catch(D){this.json(t,507,{error:D?.message??String(D)})}break}if(S.forwarded===!0){this.json(t,404,{error:`inbox agent "${k.inbox}" is not on this node`});break}let C=this.mesh?.findAgentPeer(k.inbox);if(!C){this.json(t,404,{error:`inbox agent "${k.inbox}" is not on this node or any known peer`});break}let M=this.mesh.directory().find(D=>D.peer===C.peer)?.peerUrl;if(!C.healthy||!M){this.json(t,503,{error:`the node hosting "${k.inbox}" (${C.peer}) is unreachable; try again later`});break}try{let D=await fetch(`${M.replace(/\/$/,"")}/wiki/notes`,{method:"POST",headers:{"Content-Type":"application/json",...this.mesh.authHeaders(C.peer)},body:JSON.stringify({...x,fromNode:x.fromNode||this.config.node.id,forwarded:!0}),signal:AbortSignal.timeout(1e4)}),E=await D.json().catch(()=>({}));this.json(t,D.status,{...E,peer:C.peer})}catch(D){this.json(t,502,{error:`forward to ${C.peer} failed: ${D?.message??D}`,peer:C.peer})}break}case"GET /graph/schema":{let h=this.registry.getGraphStore();if(!h){this.json(t,404,{error:"graph disabled on this node"});break}this.json(t,200,{nodeId:this.config.node.id,schema:h.loadSchema()});break}case"GET /graph/nodes":{let h=this.registry.getGraphStore();if(!h){this.json(t,404,{error:"graph disabled on this node"});break}this.json(t,200,{nodeId:this.config.node.id,...h.loadNodes()});break}case"GET /graph/classifications":{let h=this.registry.getGraphStore();if(!h){this.json(t,404,{error:"graph disabled on this node"});break}let f=n.searchParams.get("status")||"approved",k=Math.max(1,Math.min(1e3,parseInt(n.searchParams.get("limit")||"200",10)||200)),S=h.listByStatus(f,k);this.json(t,200,{nodeId:this.config.node.id,status:f,count:S.length,classifications:S});break}default:this.json(t,404,{error:"Not found",endpoints:["GET /health","GET /agents","GET /crons","GET /routines \u2014 schedules + cron/hook workflows with staleness flags","GET /mesh","GET /wiki/agents","GET /wiki/entries[?agent=X&after=YYYY-MM-DD]","GET /wiki/articles?agent=X","GET /wiki/notes[?status=waiting|open|patched|rejected|deferred|expired|all&limit=N]","POST /wiki/notes { from, change, source, date? } \u2014 a note for the wiki observe/sweep run","GET /graph/schema","GET /graph/nodes","GET /graph/classifications[?status=approved|pending|rejected&limit=N]","POST /task { agent, message, context?, freshSession?: bool }","GET /agents/:id \u2014 resolved agent config (permission, tier, model, persistentProcess, toolUseRequired)","POST /agents/:id/selftest { message? } \u2014 canary probe; runs a fresh-session task and reports {ok, durationMs, tokens, billedModel}","GET /traces[?agentId=&channel=&chatId=&workflowRunId=&status=&since=&until=&limit=]","GET /traces/:taskId \u2014 full per-task execution trace (steps + tokens)","GET /voice/history[?agent=&limit=&before=] \u2014 past voice exchanges, bounded summaries","GET /voice/history/:id \u2014 one voice exchange in full; POST /voice/history/:id/replay","GET /api/processes \u2014 live persistent claude processes (JSON)","POST /api/processes/kill { agentId, channel, chatId, reason? }","GET /api/actions/builtin \u2014 list shipped built-in typed actions","POST /api/actions/builtin/:name \u2014 run a built-in with JSON body input","POST /mesh/task { peer, message }","POST /webhook/:agentId[/:source] \u2014 webhook callback","POST /reload \u2014 re-read agentx.json (hot-swaps crons)","GET /usage/plan \u2014 Claude plan windows, cold-dispatch counters, active holds","POST /usage/plan/lift \u2014 drop the active Claude plan holds","GET /daemon/restart \u2014 in-flight count, service manager, pending restart","POST /daemon/restart \u2014 restart when idle { timeoutMinutes?, onTimeout? }","POST /daemon/restart/cancel","GET /.well-known/agent-card.json","GET /call \u2014 browser UI for P2P A/V calls (requires channels.webrtc.enabled)","GET /webrtc/config \u2014 ICE servers + peer directory for the call page","GET /webrtc/events?callId=&as= \u2014 SSE stream of signaling events","POST /webrtc/signal/out \u2014 browser-originated signal, forwarded to remote peer","POST /webrtc/signal \u2014 remote-peer-originated signal, fanned out to local browser","POST /webrtc/bot/invite { callId, target, agentId } \u2014 spawn a transcribing bot peer for a call","GET /webrtc/bots \u2014 active bot sessions","POST /webrtc/camera/watch { callId, agentId } \u2014 an agent watches the phone camera share","GET /webrtc/camera/watch \u2014 agents watching a camera now","POST /webrtc/camera/watch/:id/look { note? } \u2014 ask the watching agent what it sees","POST /webrtc/camera/watch/:id/stream { seconds, note? } \u2014 the agent keeps watching for a while (0 stops)","POST /webrtc/camera/look { agentId } \u2014 from an agent's run: the newest frame as a PNG path"]})}}catch(i){this.json(t,500,{error:i.message})}}async handleOpenAICompat(e,t,n){let s=await G(e);await vf(e,t,n,s,{execute:(i,o,a,c)=>this.registry.execute(i,o,a,c),agentIds:Object.keys(this.config.agents),cancel:(i,o,a,c)=>{let d=this.registry.list().find(l=>l.id===i)?.runningTasks.filter(l=>l.channel===o&&l.chatId===a)||[];for(let l of d)this.registry.cancelRunningTask(l.id,c)},log:i=>this.log(i)})}json(e,t,n){e.writeHead(t,{"Content-Type":"application/json"}),e.end(JSON.stringify(n,null,2))}resolveGitlabTokenForAgent(e){if(!e)return{token:this.config.channels.gitlab?.token,source:"global"};let t=(this.config.channels.gitlab?.agentMappings||[]).find(s=>s.agentId===e);if(t?.token)return{token:t.token,source:"agentMappings"};let n=Qw(this.config,e,"gitlab-user","tokenEnv");return n.status==="ok"&&n.value?{token:n.value,source:`integrations(${n.envVar})`}:this.config.channels.gitlab?.token?{token:this.config.channels.gitlab.token,source:"global"}:{token:void 0,source:n.status}}resolveTodayUsage(){let e=Kf();if(e==="json")return this.registry.getTodayUsage();let t=Jf(this.db);return e==="sqlite"||Object.keys(t.agents).length>0?t:this.registry.getTodayUsage()}installAgentMemorySurface(){let e=parseInt(this.config.node.bind.split(":")[1]||"18800",10);for(let t of this.registry.list()){let n=t.workspace;if(!(!n||!rn(n)))try{let s=ie(n,".claude","skills");sS(s,{recursive:!0});let i=ie(s,Zw);if(!rn(i))Sd(i,kc(e)),this.log(` memory-skill: installed remember.md \u2192 ${t.id}`);else{let o=tk(on(i,"utf-8"),e);o&&(Sd(i,o),this.log(` memory-skill: updated remember.md \u2192 ${t.id}`))}this.agentMemory.syncToWorkspace(t.id,n,this.config.session.memoryIndexMaxChars)}catch(s){this.log(` memory-skill: ${t.id} install failed \u2014 ${s?.message??s}`)}}}installAgentMcpConfig(){for(let[e,t]of Object.entries(this.config.agents)){let n=t.workspace;if(!n||!rn(n))continue;let s=this.config.workflows.enabled&&(this.config.workflows.followUp.enabled&&(this.config.workflows.followUp.agents[e]??!0)||Nu(this.config.workflows,e)),i=nu(vl(t),this.config.requests.enabled||s?tu():null);try{switch(su(n,i)){case"installed":this.log(` mcp: installed ${Object.keys(i).length} server(s) \u2192 ${e}`);break;case"updated":this.log(` mcp: updated .mcp.json (${Object.keys(i).length} server(s)) \u2192 ${e}`);break;case"removed":this.log(` mcp: removed managed .mcp.json (config now empty) \u2192 ${e}`);break;case"skipped-operator-owned":Object.keys(i).length>0&&this.log(` mcp: ${e} has operator-owned .mcp.json \u2014 skipping (delete file or marker to let agentx manage)`);break;case"noop":break}}catch(o){this.log(` mcp: ${e} install failed \u2014 ${o?.message??o}`)}}}workspaceFor(e){for(let t of this.registry.list())if(t.id===e)return t.workspace;return null}handleMemoryApi(e,t,n,s){return Pw(e,t,n,s,{mem:this.agentMemory,workspaceFor:i=>this.workspaceFor(i),runningTaskOwner:i=>this.registry.runningTaskOwner(i),indexMaxChars:()=>this.config.session.memoryIndexMaxChars})}async handleWorkflowEvent(e,t){if(!this.workflowDispatcher){this.json(t,503,{error:"workflow engine not enabled on this node"});return}let n;try{n=await se(e)}catch(c){this.json(t,400,{error:"invalid JSON body",message:c.message});return}let s=n?.payload??n,i=s?.event,o=s?.entityRef;if(!i?.id||!o?.backend||!o?.id){this.json(t,400,{error:"missing event or entityRef"});return}let a=n?.kind;try{if(a==="trigger"&&s.trigger){let g=typeof n?.fromPeer=="string"?n.fromPeer:"unknown";this.log(`[workflows/mesh] received trigger from "${g}" source="${s.trigger.source}" chat="${s.trigger.chat??"*"}"`);let m=await this.workflowDispatcher.dispatch({trigger:s.trigger,entityRef:o,event:i,fromRemote:{peer:g}});this.log(`[workflows/mesh] dispatched broadcast: matched=${m.claimed.length} ${m.claimed.length?`(${m.claimed.map(p=>p.id).join(", ")})`:"[none \u2014 no workflow with mesh.allowRemote matched]"}`),this.json(t,202,{ok:!0,mode:"trigger-broadcast",matched:m.claimed.map(p=>p.id)});return}let l=(s.workflowId?this.workflowStore?.get(s.workflowId):null)?.nodes.find(g=>g.type.startsWith("trigger."))?.config??{},u={source:String(l.source??"hook"),project:l.filter?.project,repo:l.filter?.repo,chat:l.filter?.chat,labels:l.filter?.labels};await this.workflowDispatcher.dispatch({trigger:u,entityRef:o,event:i}),this.json(t,202,{ok:!0})}catch(c){this.log(`[workflows] /workflow/event failed: ${c.message}`),this.json(t,500,{error:c.message})}}async postToPushHost(e,t,n){let s=e.toLowerCase(),i=this.mesh?.directory().find(c=>c.peer.toLowerCase()===s);if(!i)throw new Error(`push: channels.push.relayTo "${e}" is not a mesh peer of this node`);let o=await fetch(`${i.peerUrl}${t}`,{method:"POST",headers:{"Content-Type":"application/json",...this.mesh.authHeaders(i.peer)},body:JSON.stringify(n),signal:AbortSignal.timeout(15e3)});if(!o.ok)throw new Error(`push: ${i.peer} ${t} -> ${o.status} ${(await o.text().catch(()=>"")).slice(0,200)}`);let a=await o.json().catch(()=>({}));if(t==="/channel/send")return a.messageId??void 0;if(typeof a.status!="number")throw new Error(`push: ${i.peer} ${t} gave no answer`);return{status:a.status,body:a.body??{}}}async handlePushApp(e,t){let n;try{n=await se(e)}catch(c){this.json(t,400,{error:"invalid JSON body",message:c.message});return}let{handlePushBridge:s,pushOrigin:i}=await import("./push-bridge-P7HH25VN.js"),o=this.config.channels.push;if(!o?.enabled){this.json(t,200,{status:503,body:{error:`Notifications are off on ${this.config.node.name}.`}});return}if(o.relayTo){if(n?.origin!==void 0){this.json(t,200,{status:409,body:{error:`${this.config.node.name} relays its notifications too (channels.push.relayTo = ${o.relayTo})`}});return}if(n?.op!=="app"){this.json(t,400,{error:"op must be app"});return}try{this.json(t,200,await this.postToPushHost(o.relayTo,"/push/app",{op:"app",origin:i(this.config.node.name),call:n.call}))}catch(c){this.log(`[push] /push/app to ${o.relayTo} failed: ${c.message}`),this.json(t,502,{error:c.message})}return}let a=this.pushBridgeCaller(e);"error"in a&&n?.op!=="roster"&&this.log(`[push] /push/app from ${e.socket?.remoteAddress||"?"} refused: ${a.error}`),this.json(t,200,s(n,a,this.pushHost??null,this.pushHost?void 0:`Notifications are not running on ${this.config.node.name}. Check channels.push.subject and the database there.`))}pushBridgeCaller(e){return xh(String(e.headers.authorization||""),this.config.mesh.peers,process.env.MESH_TOKEN)}async handleChannelSend(e,t){let n;try{n=await se(e)}catch(d){this.json(t,400,{error:"invalid JSON body",message:d.message});return}let s=String(n?.channel??""),i=String(n?.chatId??""),o=String(n?.text??"");if(!s||!i||!o){this.json(t,400,{error:"channel, chatId, and text are required"});return}if(!this.router.getChannel(s)){this.json(t,404,{error:`channel "${s}" not hosted on this node`});return}let c;if(n.relayed===!0&&n.origin!==void 0){let d=this.pushBridgeCaller(e);if("origin"in d)c=d.origin;else if(i!=="default"){this.json(t,403,{error:d.error});return}}if(s==="push"&&i.includes(":")){let{scopedPushTarget:d}=await import("./push-bridge-P7HH25VN.js"),l=d(i,this.pushBridgeCaller(e));if("error"in l){this.json(t,403,{error:l.error});return}}try{let d=await this.router.sendOutbound({channel:s,chatId:i,text:o,accountId:typeof n.accountId=="string"?n.accountId:void 0,parseMode:typeof n.parseMode=="string"?n.parseMode:void 0,replyTo:typeof n.replyTo=="string"?n.replyTo:void 0,buttons:Array.isArray(n.buttons)?n.buttons:void 0,agentId:typeof n.agentId=="string"?n.agentId:void 0,relayed:n.relayed===!0?!0:void 0,...n.relayed===!0?{told:{passed:!0}}:{},origin:c},{recordInSession:!1});this.json(t,200,{ok:!0,messageId:d??null})}catch(d){this.log(`[mesh] /channel/send "${s}" failed: ${d.message}`),this.json(t,500,{error:d.message})}}async handleChannelChats(e,t,n={}){let s=new Set,i=[],o=[],a=(d,l)=>{let u=0;for(let g of d)!g.id||s.has(g.id)||(s.add(g.id),i.push({...g,source:l}),u++);u>0&&o.push(`${l}:${u}`)},c=this.router.getChannel(t);if(c?.listKnownChats)try{a(c.listKnownChats(),"local")}catch{}else if(c?.listChats)try{a(c.listChats().map(d=>({id:d.jid,name:d.name,kind:d.isGroup?"group":"dm"})),"local")}catch{}if(!n.localOnly&&this.mesh){let d=this.mesh.directory().filter(l=>l.healthy&&l.channels?.includes(t));await Promise.allSettled(d.map(async l=>{try{let u=await fetch(`${l.peerUrl}/channels/${encodeURIComponent(t)}/chats?local=1`,{headers:this.mesh.authHeaders(l.peer),signal:AbortSignal.timeout(5e3)});if(!u.ok)return;let g=await u.json();Array.isArray(g.chats)&&a(g.chats.map(m=>({id:m.id,name:m.name,kind:m.kind??"dm",accountId:m.accountId})),`mesh:${l.peer}`)}catch{}}))}this.json(e,200,{channel:t,source:o.join(", ")||"none",chats:i})}async handleWorkflowManualRun(e,t,n){if(!this.workflowDispatcher||!this.workflowStore){this.json(t,503,{error:"workflow engine not enabled on this node"});return}let s;try{s=await se(e)}catch{s={}}try{let i=await Yw({get:o=>this.workflowStore.get(o),dispatchWorkflow:o=>this.workflowDispatcher.dispatchWorkflow(o),startRun:o=>this.workflowDispatcher.startRun(o)},n,s);this.json(t,i.status,i.body)}catch(i){this.log(`[workflows] manual run "${n}" failed: ${i.message}`),this.json(t,500,{error:i.message})}}},$d=Id;Tt($d,"MESH_PROTECTED_PATHS",new Set(["/task","/ask","/mesh/task","/mesh/inbox/send","/workflow/event","/workflow/transition","/channel/send","/push/app","/webrtc/signal","/gitlab/react","/gitlab/send-note","/gitlab/log-time","/channel/edit-comment","/github/send-comment"]));function WP(r){if(typeof r!="string")return"";let e=r.trim();if(!e)return"";let t=e.match(/^[^.!?\n]+[.!?]?/),n=(t?t[0]:e).trim();return n.length>140?n.slice(0,137)+"\u2026":n}function se(r){return new Promise((e,t)=>{let n="";r.setEncoding("utf8"),r.on("data",s=>{n+=s}),r.on("end",()=>{try{e(n?JSON.parse(n):{})}catch(s){t(s)}}),r.on("error",t)})}function UP(r,e){let t=["model","workspace","tier","permissionMode","mcpServers"],n=new Set,s=new Set([...Object.keys(r),...Object.keys(e)]);for(let i of s){let o=r[i],a=e[i];if(!o||!a){n.add("add/remove");continue}for(let c of t)JSON.stringify(o[c])!==JSON.stringify(a[c])&&n.add(`${i}.${c}`)}return Array.from(n).slice(0,6)}async function G(r){return new Promise((e,t)=>{let n="";r.on("data",s=>n+=s.toString()),r.on("end",()=>{try{e(n?JSON.parse(n):{})}catch{e({})}}),r.on("error",t)})}iS();function Tq(r){typeof r=="string"&&(es.error(r),process.exit(1)),r instanceof Error&&(es.error(r.message),process.exit(1)),es.error("Something went wrong. Please try again."),process.exit(1)}export{i_ as a,na as b,ut as c,wn as d,vn as e,pt as f,Gs as g,Gp as h,Lf as i,mI as j,yI as k,Gf as l,Te as m,qf as n,Xf as o,Wa as p,ZD as q,eN as r,Ba as s,yT as t,wT as u,Ha as v,wm as w,jN as x,Rm as y,bT as z,Am as A,Em as B,Cm as C,FN as D,WN as E,UN as F,Le as G,FL as H,Ex as I,dR as J,hc as K,l1 as L,u1 as M,h1 as N,Ww as O,UR as P,y1 as Q,w1 as R,Dn as S,Qt as T,Nn as U,B1 as V,wk as W,_A as X,NF as Y,ni as Z,_c as _,Mc as $,ai as aa,ke as ba,db as ca,ui as da,EE as ea,Sb as fa,PE as ga,xb as ha,pi as ia,Bn as ja,wi as ka,bi as la,_b as ma,Vc as na,jb as oa,et as pa,Ee as qa,Hb as ra,Bb as sa,qb as ta,Xb as ua,Fi as va,Ov as wa,fd as xa,Nv as ya,iP as za,tG as Aa,$d as Ba,Tq as Ca};
1256
- //# sourceMappingURL=chunk-CJKN4APJ.js.map
1256
+ //# sourceMappingURL=chunk-67DWBJEO.js.map
@@ -1,4 +1,4 @@
1
- import{a as rt,b as ot,c as st,d as x,e as A,f as v}from"./chunk-72SZI2UW.js";import{a as ne,b as et}from"./chunk-FCPTN6NF.js";import{a as Te,b as ht}from"./chunk-MCI3DIWW.js";import{o as we,p as Ze}from"./chunk-JNG3P5V2.js";import{Ta as tt,Ua as nt}from"./chunk-GVJMPSE2.js";import{a as it,b as at,c as ct,d as ut,e as lt,f as dt,g as pt,h as mt,i as bt,j as ft,k as gt,l as yt}from"./chunk-RGDKHYY2.js";import{a as E,b as We,c as he}from"./chunk-QIJLFPWE.js";function R(e,t){$.set(e,t),X.delete(e)}function D(e){let t=X.get(e);if(t)return t;let r=$.get(e);if(!r){let o=Ee();throw new Error(`unknown decision backend "${e}"`+(o.length>0?` \u2014 registered: ${o.join(", ")}`:" \u2014 none registered"))}let n=r();return X.set(e,n),n}function Ee(){return[...$.keys()].sort()}function wt(){$.clear(),X.clear()}var $,X,C=E(()=>{"use strict";$=new Map,X=new Map});import Tt from"better-sqlite3";import{createHash as Et}from"crypto";import{mkdirSync as kt}from"fs";import{dirname as St,resolve as xt}from"path";function Q(e){if(e.type==="noul"){let r=e.noul,n={yes:r,no:1-r},o=r>=.5?"yes":"no",s=Math.abs(r-.5)*2;return{predicted:o,confidence:s,probabilities:n,topLabel:o,topProb:Math.max(r,1-r),expectedScore:null,pMax:Math.max(r,1-r),negEntropy:s}}if(e.type==="choice")return{predicted:e.choice,confidence:e.confidence,probabilities:{...e.probabilities},topLabel:e.choice,topProb:e.probabilities[e.choice]??0,expectedScore:null,pMax:e.pMax,negEntropy:e.negEntropy};let t=String(Math.round(e.score));return{predicted:t,confidence:e.confidence,probabilities:{...e.probabilities},topLabel:t,topProb:e.probabilities[t]??0,expectedScore:e.score,pMax:e.pMax,negEntropy:e.negEntropy}}function At(e){if(typeof e!="string"||e.length===0)return{};try{let t=JSON.parse(e);return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}catch{return{}}}function Rt(e){e.exec("CREATE TABLE IF NOT EXISTS schema_version (v INTEGER PRIMARY KEY);");let t=e.prepare("SELECT MAX(v) AS v FROM schema_version").get().v??0;t<1&&vt(e),t<2&&Ot(e),t<3&&_t(e)}function _t(e){e.exec(`
1
+ import{a as rt,b as ot,c as st,d as x,e as A,f as v}from"./chunk-72SZI2UW.js";import{a as ne,b as et}from"./chunk-FCPTN6NF.js";import{a as Te,b as ht}from"./chunk-MCI3DIWW.js";import{o as we,p as Ze}from"./chunk-JNG3P5V2.js";import{Ta as tt,Ua as nt}from"./chunk-VKEH4IBA.js";import{a as it,b as at,c as ct,d as ut,e as lt,f as dt,g as pt,h as mt,i as bt,j as ft,k as gt,l as yt}from"./chunk-RGDKHYY2.js";import{a as E,b as We,c as he}from"./chunk-QIJLFPWE.js";function R(e,t){$.set(e,t),X.delete(e)}function D(e){let t=X.get(e);if(t)return t;let r=$.get(e);if(!r){let o=Ee();throw new Error(`unknown decision backend "${e}"`+(o.length>0?` \u2014 registered: ${o.join(", ")}`:" \u2014 none registered"))}let n=r();return X.set(e,n),n}function Ee(){return[...$.keys()].sort()}function wt(){$.clear(),X.clear()}var $,X,C=E(()=>{"use strict";$=new Map,X=new Map});import Tt from"better-sqlite3";import{createHash as Et}from"crypto";import{mkdirSync as kt}from"fs";import{dirname as St,resolve as xt}from"path";function Q(e){if(e.type==="noul"){let r=e.noul,n={yes:r,no:1-r},o=r>=.5?"yes":"no",s=Math.abs(r-.5)*2;return{predicted:o,confidence:s,probabilities:n,topLabel:o,topProb:Math.max(r,1-r),expectedScore:null,pMax:Math.max(r,1-r),negEntropy:s}}if(e.type==="choice")return{predicted:e.choice,confidence:e.confidence,probabilities:{...e.probabilities},topLabel:e.choice,topProb:e.probabilities[e.choice]??0,expectedScore:null,pMax:e.pMax,negEntropy:e.negEntropy};let t=String(Math.round(e.score));return{predicted:t,confidence:e.confidence,probabilities:{...e.probabilities},topLabel:t,topProb:e.probabilities[t]??0,expectedScore:e.score,pMax:e.pMax,negEntropy:e.negEntropy}}function At(e){if(typeof e!="string"||e.length===0)return{};try{let t=JSON.parse(e);return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}catch{return{}}}function Rt(e){e.exec("CREATE TABLE IF NOT EXISTS schema_version (v INTEGER PRIMARY KEY);");let t=e.prepare("SELECT MAX(v) AS v FROM schema_version").get().v??0;t<1&&vt(e),t<2&&Ot(e),t<3&&_t(e)}function _t(e){e.exec(`
2
2
  ALTER TABLE decision_calls ADD COLUMN features_json TEXT;
3
3
  INSERT INTO schema_version (v) VALUES (3);
4
4
  `)}function Ot(e){e.exec(`
@@ -111,4 +111,4 @@ import{a as rt,b as ot,c as st,d as x,e as A,f as v}from"./chunk-72SZI2UW.js";im
111
111
  `)}if(!m)throw new Error(`local decision backend could not get a valid answer after ${f+1} attempt(s): ${w}`);let M={},L=!1;for(let[k,q]of Object.entries(s.questions)){let S=_(q,m[k],{normalize:e.normalizeProbabilities??!0});M[k]=S.answer,S.repaired&&(L=!0)}return{model:a,answers:M,usage:h,meta:{backend:"local",structureMode:c,answerMode:"probabilities",repaired:L,retries:f,stateTruncated:l.truncated,latencyMs:Date.now()-i}}}finally{b()}}}}async function Jt(e,t,r,n,o){if(!e.generateRaw)throw new Error(`provider "${e.name}" has no generateRaw(); use structureMode "text"`);let s=[{role:"user",content:r},...n?[{role:"user",content:n}]:[]],i=await e.generateRaw(s,J,[{name:F,description:"Report a probability distribution for every question.",input_schema:se(t)}],{...o,toolChoice:{type:"tool",name:F}}),a=i.content.find(c=>c.type==="tool_use"&&c.name===F),u=a&&a.type==="tool_use"?a.input:null;return{answers:Be(u),usage:{inputTokens:i.usage.input_tokens,outputTokens:i.usage.output_tokens}}}async function Gt(e,t,r,n,o){let s=[r,ae(t)].join(`
112
112
  `),i=[{role:"system",content:J},{role:"user",content:s},...n?[{role:"user",content:n}]:[]],a=await e.generate(i,o);return{answers:Be(Te(a.content??"")),usage:{inputTokens:0,outputTokens:a.tokensUsed??0}}}function Be(e){if(e&&typeof e=="object"&&!Array.isArray(e)){let t=e;if(t.answers&&typeof t.answers=="object")return t.answers}return e}function Yt(e,t){return e!=="auto"?e:t.generateRaw&&me[t.name]?.structuredOutput?"tool":"text"}function Kt(e,t){let r=new AbortController,n=setTimeout(()=>r.abort(new Error(`decision timed out after ${t}ms`)),t),o=()=>r.abort(e?.reason);return e&&(e.aborted?o():e.addEventListener("abort",o,{once:!0})),{signal:r.signal,dispose:()=>{clearTimeout(n),e?.removeEventListener("abort",o)}}}var Xt,$t,Vt,Fe,zt,be=E(()=>{"use strict";Ze();Ue();ht();j();Y();v();z();Xt="claude-code",$t="claude-haiku-4-5-20251001",Vt=24e3,Fe=2e3,zt=3e4});import{readFileSync as Ht}from"fs";import{homedir as Wt}from"os";import{join as Zt}from"path";function N(e={}){let t=(e.baseUrl??en).replace(/\/+$/,""),r=e.path??"/classifier",n=e.name??"simple-jev",o=e.maxStateChars??nn,s=e.maxChoiceOptions??rn,i={probabilitySource:e.probabilitySource??"logits",calibratedProbabilities:!1,maxChoiceOptions:s,maxStateChars:o,parallelQuestions:!0,images:!1};return{name:n,capabilities:i,async decide(a){A(a.questions),cn(a.questions,s);let u=Date.now(),c=a.model??e.model;if(!c)throw new Error("simple-jev backend needs a model id");let l=G(a.state,o),p=e.fetchImpl??fetch,{signal:g,dispose:d}=un(a.abortSignal,a.timeoutMs??e.timeoutMs??tn);try{let b={"Content-Type":"application/json"},h=an(e.apiKeyEnv,e.apiKeyFile);h&&(b.Authorization=`Bearer ${h}`);let T=await qe(p(`${t}${r}`,{method:"POST",headers:b,body:JSON.stringify({model:c,state:l.text,questions:sn(a.questions)}),signal:g}),g);if(!T.ok){let k=await T.text().catch(()=>"");throw new Error(`${n} ${T.status}: ${k.slice(0,300)}`)}let f=await qe(T.json(),g),m=P(a.questions).safeParse(f.answers);if(!m.success)throw new Error(`${n} returned a response that does not match the requested questions (contract drift, not a model slip \u2014 retrying will not help):
113
113
  ${U(m.error)}`);let w=m.data,M={},L=!1;for(let[k,q]of Object.entries(a.questions)){let S=_(q,w[k]);M[k]=S.answer,S.repaired&&(L=!0)}return{model:f.model??c,answers:M,usage:{inputTokens:f.usage?.input_tokens??0,outputTokens:f.usage?.output_tokens??0},meta:{backend:n,structureMode:i.probabilitySource==="native"?"native":"logprobs",answerMode:"probabilities",repaired:L,retries:0,stateTruncated:l.truncated,latencyMs:Date.now()-u}}}finally{d()}}}}function sn(e){let t={};for(let[r,n]of Object.entries(e))t[r]=n.instructions?n:{...n,instructions:on[n.type]};return t}function an(e,t){let r=e?process.env[e]:void 0;if(r)return r;if(!t)return;let n=t.startsWith("~/")?Zt(Wt(),t.slice(2)):t;if(!Z.has(n))try{let o=Ht(n,"utf-8").trim();Z.set(n,o.length>0?o:null)}catch{Z.set(n,null)}return Z.get(n)??void 0}function cn(e,t){for(let[r,n]of Object.entries(e))if(n.type==="choice"){let o=Object.keys(n.criteria).length;if(o>t)throw new Error(`question "${r}": accepts at most ${t} choice options, got ${o}`)}else if(n.type==="score"&&n.criteria.length>t)throw new Error(`question "${r}": accepts at most ${t} score levels, got ${n.criteria.length}`)}function qe(e,t){return t.aborted?Promise.reject(t.reason??new Error("aborted")):new Promise((r,n)=>{let o=()=>n(t.reason??new Error("aborted"));t.addEventListener("abort",o,{once:!0}),e.then(s=>{t.removeEventListener("abort",o),r(s)},s=>{t.removeEventListener("abort",o),n(s)})})}function un(e,t){let r=new AbortController,n=setTimeout(()=>r.abort(new Error(`decision timed out after ${t}ms`)),t),o=()=>r.abort(e?.reason);return e&&(e.aborted?o():e.addEventListener("abort",o,{once:!0})),{signal:r.signal,dispose:()=>{clearTimeout(n),e?.removeEventListener("abort",o)}}}var en,tn,nn,rn,on,Z,fe=E(()=>{"use strict";j();v();z();Y();en="http://127.0.0.1:8000/v1",tn=3e4,nn=6e3,rn=50;on={choice:"Which option best fits?",score:"Which level best fits?",noul:"Is this true of the state?"};Z=new Map});var Xe={};We(Xe,{DEFAULT_SEAT_TIMEOUT_MS:()=>Ve,DecisionStore:()=>I,MAX_CHOICE_OPTIONS:()=>MAX_CHOICE_OPTIONS,SYSTEM_PROMPT:()=>J,TOOL_NAME:()=>F,UNCERTAINTY_HIGH:()=>Ce,UNCERTAINTY_LOW:()=>De,_resetDecisionBackendsForTesting:()=>wt,agreement:()=>it,answerView:()=>Q,applyRecalibrator:()=>ue,applyTemperature:()=>mt,askSeat:()=>yn,band:()=>Ie,bootstrapInterval:()=>ft,brier:()=>lt,buildDesign:()=>ve,calibrationReport:()=>gt,choice:()=>ot,compareCalibrators:()=>It,confidenceFor:()=>re,configureDecisions:()=>pn,configuredSeatTimeout:()=>dn,coverageCurve:()=>pt,createLocalDecisionBackend:()=>W,createMockDecisionBackend:()=>H,createSimpleJevBackend:()=>N,decisionsRuntime:()=>bn,describeIssues:()=>U,ece:()=>ct,expectedScore:()=>Ae,finalizeAnswer:()=>_,fitLogistic:()=>Ne,fitRecalibrator:()=>B,fitTemperature:()=>bt,getDecisionBackend:()=>D,getSeatMode:()=>Je,labelSeatCall:()=>fn,labelsOf:()=>x,listDecisionBackends:()=>Ee,logLoss:()=>dt,logit:()=>le,mce:()=>ut,measureConsistency:()=>Ut,normalizeDistribution:()=>Se,normalizedNegEntropy:()=>oe,noul:()=>rt,pMax:()=>xe,parseSeatMode:()=>ge,rawAnswerSchema:()=>Re,rawAnswersSchema:()=>P,recordSeatOutcome:()=>gn,registerBuiltinDecisionBackends:()=>ln,registerDecisionBackend:()=>R,reliabilityBins:()=>at,renderQuestions:()=>_e,renderShapeInstructions:()=>ae,renderState:()=>G,renderUserPrompt:()=>ie,resetDecisionsRuntime:()=>mn,score:()=>st,seatEnvVar:()=>ze,sigmoid:()=>de,toolInputSchema:()=>se,validateQuestions:()=>A,withUid:()=>Qe});function ln(e={},t={},r={},n={}){R("mock",()=>H()),R("local",()=>W(e)),R("simple-jev",()=>N(t)),R("jev",()=>N({name:"jev",baseUrl:"https://openrouter.ai/api/alpha",path:"/decisions",model:"jev-latest",apiKeyEnv:"OPENROUTER_API_KEY",apiKeyFile:"~/.agentx/openrouter-key.txt",probabilitySource:"native",maxChoiceOptions:255,maxStateChars:9e4,...r})),R("typesafe",()=>N({name:"typesafe",baseUrl:"https://api.typesafe.ai/v1",path:"/systemone",model:"jev-latest",apiKeyEnv:"TYPESAFE_API_KEY",apiKeyFile:"~/.agentx/typesafe-key.txt",probabilitySource:"native",maxChoiceOptions:255,maxStateChars:9e4,...n}))}var $e=E(()=>{"use strict";ke();v();j();z();C();Y();V();yt();Me();je();Ge();pe();be();fe();C();pe();be();fe()});function dn(e){return Ke(),y.seats[e]?.timeoutMs}function pn(e){y={...ye,...y,...e},ee=!0}function mn(){y={...ye,seats:{}},ee=!1}function Ke(){if(!ee){ee=!0;try{let{loadDaemonConfig:e}=(nt(),he(tt)),t=e()?.decisions;if(!t?.enabled)return;let{registerBuiltinDecisionBackends:r}=($e(),he(Xe)),n=t.backends??{};r(n.local,n.simpleJev,n.jev,n.typesafe);let o=null;try{o=new I({path:t.dbPath})}catch{}y={enabled:!0,defaultBackend:t.defaultBackend,store:o,seats:Object.fromEntries(Object.entries(t.seats??{}).map(([s,i])=>[s,{...i,redactState:t.redactState,keepStateRows:t.keepStateRows}]))}}catch{}}}function bn(){return y}function ge(e){if(typeof e!="string")return null;let t=e.trim().toLowerCase();return hn.includes(t)?t:null}function ze(e){return`AGENTX_DECISION_SEAT_${e.toUpperCase().replace(/[^A-Z0-9]+/g,"_")}`}function Je(e,t=process.env){Ke();let r=ge(t[ze(e)]);return r||(y.enabled?ge(y.seats[e]?.mode)??"off":"off")}function fn(e,t,r,n={}){if(!(!e||!y.store))try{y.store.label(e,t,r,n)}catch{}}function gn(e,t,r=!1){if(!(!e||!y.store))try{y.store.recordOutcome(e,t,r)}catch{}}async function yn(e,t,r,n={}){let o=Je(e);if(o==="off")return null;let s=y.seats[e]??{mode:o},i=n.backend??s.backend??y.defaultBackend,a=Date.now();try{let c=await D(i).decide({state:t,questions:r,model:n.model??s.model,abortSignal:n.signal,timeoutMs:n.timeoutMs??s.timeoutMs??(y.seats[e]?Ve:void 0)}),l=wn(e,o,t,r,c,n,s);return{answers:c.answers,callId:l,mode:o}}catch(u){return Tn(e,o,t,r,i,n,s,a,u),En(e,i,u),null}}function wn(e,t,r,n,o,s,i){if(!y.store)return null;try{return y.store.recordCall({seat:e,mode:t,backend:o.meta.backend,model:o.model,meta:o.meta,state:r,questions:n,answers:o.answers,usage:o.usage,incumbent:He(s.incumbent),links:s.links,features:s.features,keepState:!i.redactState})}catch{return null}}function Tn(e,t,r,n,o,s,i,a,u){if(y.store)try{y.store.recordCall({seat:e,mode:t,backend:o,model:s.model??i.model??"unknown",meta:{structureMode:"text",answerMode:"probabilities",retries:0,stateTruncated:!1,latencyMs:Date.now()-a},state:r,questions:n,answers:{},incumbent:He(s.incumbent),links:s.links,features:s.features,error:String(u?.message??u).slice(0,500),keepState:!i.redactState})}catch{}}function He(e){if(!e)return;let t={};for(let[r,n]of Object.entries(e))n!==void 0&&(t[r]={value:n});return t}function En(e,t,r){let n=Date.now();n-Ye<6e4||(Ye=n,console.warn(`[decisions] seat "${e}" on backend "${t}" failed: ${r?.message??r}`))}var Ve,ye,y,ee,hn,Ye,Ge=E(()=>{C();V();Ve=1e4;ye={enabled:!1,defaultBackend:"local",seats:{},store:null},y={...ye},ee=!1;hn=["off","shadow","active"];Ye=0});export{D as a,Ee as b,C as c,I as d,V as e,It as f,Me as g,Ut as h,je as i,me as j,Xn as k,Ue as l,ln as m,$e as n,Ve as o,dn as p,pn as q,mn as r,bn as s,ge as t,ze as u,Je as v,fn as w,gn as x,yn as y,Ge as z};
114
- //# sourceMappingURL=chunk-FFPQS2C4.js.map
114
+ //# sourceMappingURL=chunk-743RAKLP.js.map
@@ -1,4 +1,4 @@
1
- import{c as w}from"./chunk-HF55LKFC.js";function T(t){let r=1779033703^t.length;for(let s=0;s<t.length;s++)r=Math.imul(r^t.charCodeAt(s),3432918353),r=r<<13|r>>>19;let o=r>>>0;return()=>{o=o+1831565813>>>0;let s=o;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}function _(t,r,o){let s=T(o),i=[...t].sort((e,u)=>e.path.localeCompare(u.path));for(let e=i.length-1;e>0;e--){let u=Math.floor(s()*(e+1));[i[e],i[u]]=[i[u],i[e]]}return i.slice(0,Math.max(0,r)).sort((e,u)=>e.path.localeCompare(u.path))}var R=new Set("about after again also because been before being between could does doing during each from have having here into just more most only other over same should some such than that their them then there these they this those through under until very were what when where which while will with would your yours user assistant agent message entry please thanks".split(" "));function k(t){let r=new Set;for(let o of t.toLowerCase().matchAll(/[\p{L}\p{N}][\p{L}\p{N}_-]{3,}/gu))R.has(o[0])||r.add(o[0]);return r}function E(t,r){let o=k(t);if(o.size===0)return 1;let s=k(r),i=0;for(let e of o)s.has(e)&&i++;return i/o.size}var W=.15;function $(t){let r=w(t);return{commits:r.commits,urls:r.urls,numbers:r.numbers}}function j(t,r,o){return t.includes(r)||o.some(s=>s.startsWith(r)||r.startsWith(s))}var y=t=>t.toLowerCase().replace(/\/+$/,"");function N(t,r,o){let s=t.sources.map(a=>r.get(a)).filter(a=>!!a),i=t.sources.filter(a=>!r.has(a)),e=s.filter(a=>k(a.content).size>=5&&E(a.content,t.content)<W).map(a=>a.id),u=[...s.map(a=>`${a.date??""}
1
+ import{c as w}from"./chunk-B75BLZ2M.js";function T(t){let r=1779033703^t.length;for(let s=0;s<t.length;s++)r=Math.imul(r^t.charCodeAt(s),3432918353),r=r<<13|r>>>19;let o=r>>>0;return()=>{o=o+1831565813>>>0;let s=o;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}function _(t,r,o){let s=T(o),i=[...t].sort((e,u)=>e.path.localeCompare(u.path));for(let e=i.length-1;e>0;e--){let u=Math.floor(s()*(e+1));[i[e],i[u]]=[i[u],i[e]]}return i.slice(0,Math.max(0,r)).sort((e,u)=>e.path.localeCompare(u.path))}var R=new Set("about after again also because been before being between could does doing during each from have having here into just more most only other over same should some such than that their them then there these they this those through under until very were what when where which while will with would your yours user assistant agent message entry please thanks".split(" "));function k(t){let r=new Set;for(let o of t.toLowerCase().matchAll(/[\p{L}\p{N}][\p{L}\p{N}_-]{3,}/gu))R.has(o[0])||r.add(o[0]);return r}function E(t,r){let o=k(t);if(o.size===0)return 1;let s=k(r),i=0;for(let e of o)s.has(e)&&i++;return i/o.size}var W=.15;function $(t){let r=w(t);return{commits:r.commits,urls:r.urls,numbers:r.numbers}}function j(t,r,o){return t.includes(r)||o.some(s=>s.startsWith(r)||r.startsWith(s))}var y=t=>t.toLowerCase().replace(/\/+$/,"");function N(t,r,o){let s=t.sources.map(a=>r.get(a)).filter(a=>!!a),i=t.sources.filter(a=>!r.has(a)),e=s.filter(a=>k(a.content).size>=5&&E(a.content,t.content)<W).map(a=>a.id),u=[...s.map(a=>`${a.date??""}
2
2
  ${a.content}`),t.previous??""].join(`
3
3
  `),l=u.toLowerCase(),d=$(u),p=new Set(d.urls.map(y)),g=new Set(d.numbers),n=$(t.content),c=[];for(let a of n.commits)j(l,a,d.commits)||c.push(`commit ${a}`);for(let a of n.urls)!p.has(y(a))&&!l.includes(y(a))&&c.push(`link ${a}`);for(let a of n.numbers)/^\d{1,2}$/.test(a)||!g.has(a)&&!l.includes(a)&&c.push(`number ${a}`);let h=[];for(let a of s){let m=$(a.content);if(m.commits.length===0&&m.urls.length===0)continue;let v=o(a.id),S=(v.length>0?v:[t.content]).join(`
4
4
  `).toLowerCase(),x=$(S);for(let b of m.commits)j(S,b,x.commits)||h.push({entry:a.id,fact:`commit ${b}`});for(let b of m.urls)S.includes(y(b))||h.push({entry:a.id,fact:`link ${b}`})}return{path:t.path,title:t.title,type:t.type,sources:t.sources.length,missingSources:i,weakSources:e,ungrounded:c,lost:h}}function U(t,r){let o=r.toLowerCase(),s=w(r).commits,i=[];for(let e of t){let u=w(e.content),l=[...u.commits.filter(d=>!j(o,d,s)).map(d=>`commit ${d}`),...u.urls.filter(d=>!o.includes(y(d))).map(d=>`link ${d}`)];l.length>0&&i.push({entry:e.id,facts:l})}return i}var P=new Set("the and for with from into of on in at to by an a".split(" "));function L(t){return new Set((t||"").toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(r=>(r.length>1||/\d/.test(r))&&!P.has(r)&&!R.has(r)))}function M(t,r){if(t.size===0||r.size===0)return 0;let o=0;for(let s of t)r.has(s)&&o++;return o/(t.size+r.size-o)}function D(t,r,o={}){let s=o.titleMin??.75,i=o.sourcesMin??.5,e=t.map(l=>({...l,tt:L(l.title),ss:new Set(l.sources??[])})),u=[];for(let l=0;l<e.length;l++)for(let d=l+1;d<e.length;d++){let p=e[l],g=e[d];if(r&&!r.has(p.path)&&!r.has(g.path))continue;let n=(p.type??"")===(g.type??"")?M(p.tt,g.tt):0;if(n>=s){u.push({a:p.path,b:g.path,reason:"title",score:n});continue}if(p.ss.size>=2&&g.ss.size>=2){let c=M(p.ss,g.ss);c>=i&&u.push({a:p.path,b:g.path,reason:"sources",score:c})}}return u.sort((l,d)=>d.score-l.score||l.a.localeCompare(d.a))}var A=4e3;function J(t,r){let o=r.map(i=>{let e=i.content.length>A?`${i.content.slice(0,A)}
@@ -33,4 +33,4 @@ Reply with JSON only, no fencing:
33
33
  {"claims": 0, "supported": 0, "unsupported": [], "contradicted": [], "off_subject": [], "missing": [], "verdict": "good"}`}function z(t){if(!t||typeof t!="object"||Array.isArray(t))return null;let r=t,o=l=>Array.isArray(l)?l.map(d=>String(d)):[],s=l=>typeof l=="number"&&Number.isFinite(l)&&l>=0?Math.round(l):NaN,i=s(r.claims);if(Number.isNaN(i))return null;let e=Math.min(i,Number.isNaN(s(r.supported))?i-o(r.unsupported).length:s(r.supported)),u=r.verdict==="good"||r.verdict==="minor"||r.verdict==="major"?r.verdict:null;return u?{claims:i,supported:Math.max(0,e),unsupported:o(r.unsupported),contradicted:o(r.contradicted),offSubject:o(r.off_subject??r.offSubject),missing:o(r.missing),verdict:u}:null}function I(t,r,o,s=[],i=5,e){let u={};for(let n of t)u[n.type??"untyped"]=(u[n.type??"untyped"]??0)+1;let l=new Set,d=new Set;for(let n of t)for(let c of n.lost)l.add(c.entry),d.add(`${c.entry}|${c.fact}`);let p=new Set(r.flatMap(n=>[n.a,n.b]).filter(n=>t.some(c=>c.path===n))),g={sample:{articles:t.length,seed:o.seed,since:o.since,byType:u},citations:{withSources:t.filter(n=>n.sources>0).length,missingSources:t.reduce((n,c)=>n+c.missingSources.length,0),weakSources:t.reduce((n,c)=>n+c.weakSources.length,0),articlesWithWeak:t.filter(n=>n.weakSources.length>0).length},grounding:{articlesWithUngrounded:t.filter(n=>n.ungrounded.length>0).length,ungroundedFacts:t.reduce((n,c)=>n+c.ungrounded.length,0)},lost:{entriesWithLostFacts:l.size,lostFacts:d.size},duplicates:{pairs:r.length,articlesInPair:p.size},...e?{uncited:{entries:e.entries,withLostFacts:e.lost.length}}:{},examples:{ungrounded:t.filter(n=>n.ungrounded.length>0).slice(0,i).map(n=>({path:n.path,facts:n.ungrounded.slice(0,6)})),lost:t.flatMap(n=>n.lost.map(c=>({path:n.path,...c}))).slice(0,i),weak:t.filter(n=>n.weakSources.length>0).slice(0,i).map(n=>({path:n.path,entries:n.weakSources})),duplicates:r.slice(0,i),uncited:(e?.lost??[]).slice(0,i).map(n=>({entry:n.entry,facts:n.facts.slice(0,4)})),judged:s.filter(n=>n.verdict.verdict!=="good").slice(0,i).map(n=>({path:n.path,verdict:n.verdict.verdict,unsupported:n.verdict.unsupported.slice(0,4),contradicted:n.verdict.contradicted.slice(0,4),offSubject:n.verdict.offSubject,missing:n.verdict.missing.slice(0,4)}))}};if(s.length>0){let n=s.map(a=>a.verdict),c=n.reduce((a,m)=>a+m.claims,0),h=n.reduce((a,m)=>a+m.supported,0);g.judge={judged:n.length,claims:c,supported:h,supportRate:c>0?h/c:1,unsupported:n.reduce((a,m)=>a+m.unsupported.length,0),contradicted:n.reduce((a,m)=>a+m.contradicted.length,0),articlesWithWrongMerge:n.filter(a=>a.offSubject.length>0).length,missingFacts:n.reduce((a,m)=>a+m.missing.length,0),verdicts:{good:n.filter(a=>a.verdict==="good").length,minor:n.filter(a=>a.verdict==="minor").length,major:n.filter(a=>a.verdict==="major").length}}}return g}var f=(t,r)=>r>0?`${Math.round(t/r*100)}%`:"\u2013";function O(t){let r=t.sample.articles,o=["# Wiki absorb scorecard","",`Sample: ${r} articles (seed \`${t.sample.seed}\`${t.sample.since?`, changed since ${t.sample.since}`:""}). Types: ${Object.entries(t.sample.byType).map(([e,u])=>`${e} ${u}`).join(", ")||"\u2013"}.`,"","| Check | Result | Lower is better? |","|---|---|---|",`| Articles citing at least one entry | ${t.citations.withSources}/${r} (${f(t.citations.withSources,r)}) | no |`,`| Cited ids with no entry | ${t.citations.missingSources} | yes |`,`| Articles with a weak citation (entry shares <${Math.round(W*100)}% of its words) | ${t.citations.articlesWithWeak}/${r} (${f(t.citations.articlesWithWeak,r)}) | yes |`,`| Articles with an ungrounded commit, link or number | ${t.grounding.articlesWithUngrounded}/${r} (${f(t.grounding.articlesWithUngrounded,r)}) | yes |`,`| Ungrounded facts | ${t.grounding.ungroundedFacts} | yes |`,`| Commits or links lost from cited entries | ${t.lost.lostFacts} across ${t.lost.entriesWithLostFacts} entries | yes |`,`| Sampled articles in a likely duplicate pair | ${t.duplicates.articlesInPair}/${r} (${f(t.duplicates.articlesInPair,r)}) | yes |`];if(t.uncited&&o.push(`| Entries read in the window but cited by no article | ${t.uncited.entries} | \u2013 |`,`| \u2026of which carry a commit or link no article has | ${t.uncited.withLostFacts} | yes |`),t.judge){let e=t.judge;o.push(`| Judge: claims supported by the cited entries | ${e.supported}/${e.claims} (${f(e.supported,e.claims)}) | no |`,`| Judge: unsupported / contradicted claims | ${e.unsupported} / ${e.contradicted} | yes |`,`| Judge: articles with an off-subject source (wrong merge) | ${e.articlesWithWrongMerge}/${e.judged} (${f(e.articlesWithWrongMerge,e.judged)}) | yes |`,`| Judge: facts missing from the article | ${e.missingFacts} | yes |`,`| Judge verdicts good / minor / major | ${e.verdicts.good} / ${e.verdicts.minor} / ${e.verdicts.major} | \u2013 |`)}let s=t.examples,i=(e,u)=>{u.length!==0&&o.push("",`## ${e}`,"",...u)};return i("Examples: ungrounded facts",s.ungrounded.map(e=>`- \`${e.path}\`: ${e.facts.join("; ")}`)),i("Examples: lost facts",s.lost.map(e=>`- \`${e.path}\` \u2190 entry \`${e.entry}\`: ${e.fact}`)),i("Examples: weak citations",s.weak.map(e=>`- \`${e.path}\`: ${e.entries.map(u=>`\`${u}\``).join(", ")}`)),i("Examples: uncited entries with facts no article has",s.uncited.map(e=>`- \`${e.entry}\`: ${e.facts.join("; ")}`)),i("Examples: likely duplicates",s.duplicates.map(e=>`- \`${e.a}\` \u2194 \`${e.b}\` (${e.reason}, ${e.score.toFixed(2)})`)),i("Examples: judge findings",s.judged.map(e=>{let u=[e.unsupported.length?`unsupported: ${e.unsupported.join(" | ")}`:"",e.contradicted.length?`contradicted: ${e.contradicted.join(" | ")}`:"",e.offSubject.length?`off-subject: ${e.offSubject.join(", ")}`:"",e.missing.length?`missing: ${e.missing.join(" | ")}`:""].filter(Boolean);return`- \`${e.path}\` (${e.verdict}): ${u.join("; ")}`})),o.push("","## Method","","- The sample is drawn with a seeded shuffle from the articles changed in the window, so the same seed and window give the same articles.","- Ungrounded: a commit hash, link or number (three digits or more, or a date) in the article that no cited entry and no earlier version of the article contains.","- Lost: a commit hash or link in a cited entry that no article citing that entry contains.","- Uncited: entries the absorb ledger marks as read in the window that no article cites; those carrying a commit or link that no article on the node has are counted as lost, since absorb will not offer them again.","- Weak citation: a cited entry sharing fewer than 15% of its distinctive words with the article.","- Duplicate: two articles of the same type whose titles share at least 75% of their words, or which share at least half their sources.","- Judge (optional): one model call per article reads the article and its cited entries and lists unsupported, contradicted, off-subject and missing items."),o.join(`
34
34
  `)+`
35
35
  `}function V(t){if(!t||typeof t!="object")return{};let r=t,o=r.usage??{},s=i=>typeof i=="number"&&Number.isFinite(i)?i:void 0;return{costUsd:s(r.total_cost_usd)??s(r.cost_usd),apiMs:s(r.duration_api_ms),inputTokens:s(o.input_tokens),outputTokens:s(o.output_tokens),cacheReadTokens:s(o.cache_read_input_tokens),cacheWriteTokens:s(o.cache_creation_input_tokens)}}function C(t,r){return t.length===0?0:t[Math.min(t.length-1,Math.floor(r*t.length))]}function Y(t){let r=new Map,o=i=>{let e=i||"(none)",u=r.get(e);return u||r.set(e,u={calls:[],runs:[]}),u};for(let i of t)i.kind==="call"?o(i.label).calls.push(i):i.kind==="run"&&o(i.label).runs.push(i);let s=[];for(let[i,{calls:e,runs:u}]of r){if(e.length===0)continue;let l=e.map(n=>n.wallMs).sort((n,c)=>n-c),d;if(u.length>0)d=u.reduce((n,c)=>n+(Date.parse(c.endedAt)-Date.parse(c.startedAt)),0);else{let n=e.map(h=>Date.parse(h.at)-h.wallMs),c=e.map(h=>Date.parse(h.at));d=Math.max(...c)-Math.min(...n)}let p=e.reduce((n,c)=>n+c.entries,0),g=e.reduce((n,c)=>n+(c.costUsd??0),0);s.push({label:i,calls:e.length,failed:e.filter(n=>n.failed).length,entries:p,articles:e.reduce((n,c)=>n+c.articles,0),refused:e.reduce((n,c)=>n+c.refused,0),heldCited:e.reduce((n,c)=>n+(c.heldCited??0),0),wallMs:d,callMsP50:C(l,.5),callMsP95:C(l,.95),prepMs:e.reduce((n,c)=>n+(c.prepMs??0),0),costUsd:g,costPerEntry:p>0?g/p:0,entriesPerMinute:d>0?p/d*6e4:0,promptChars:e.reduce((n,c)=>n+c.promptChars,0)})}return s.sort((i,e)=>i.label.localeCompare(e.label))}export{T as a,_ as b,k as c,E as d,W as e,N as f,U as g,D as h,A as i,J as j,z as k,I as l,O as m,V as n,Y as o};
36
- //# sourceMappingURL=chunk-M5TMFCPA.js.map
36
+ //# sourceMappingURL=chunk-ABCQ6QMJ.js.map
@@ -1,2 +1,2 @@
1
- import{q as d}from"./chunk-USCFJVVI.js";import{b as i,c as u,d as l,e as c}from"./chunk-NUMWHIFL.js";import f from"cronstrue";var p=Intl.DateTimeFormat().resolvedOptions().timeZone,m=600,E='Try: "every morning at 9", "weekdays at 6pm", "every 15 minutes", "every monday at 10am", "1st of every month at noon", "daily at 9:30am", "every hour"',g=/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;function w(e){return g.test(e)}function x(e){try{return new Intl.DateTimeFormat("en-US",{timeZone:e}),!0}catch{return!1}}function $(e){return e?e.split(",").map(r=>r.trim().toLowerCase()).filter(r=>r==="log"||r==="notify"||r==="disable"):["log"]}function S(e){let r=[...e.onError??["log"]];e.notify&&!r.includes("notify")&&r.push("notify");let t={enabled:e.enabled??!0,schedule:e.parsed.cron,timezone:e.timezone||p,agent:e.agent,prompt:e.prompt,timeout:e.timeout??m,onError:r};return e.model&&(t.model=e.model),e.notify&&(t.notify=e.notify),e.notify&&e.deliverResult===!1&&(t.deliverResult=!1),e.createdBy&&(t.createdBy=e.createdBy),e.approval&&(t.approval=e.approval),t}function P(e){try{return f.toString(e,{use24HourTimeFormat:!1})}catch{return e}}function T(e,r,t=new Date){try{return d(e,t,r)}catch{return null}}function A(e,r){if(!e)return"unknown (no match within a year)";try{return`${new Intl.DateTimeFormat("en-GB",{timeZone:r,weekday:"short",day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit",hour12:!1}).format(e)} (${r})`}catch{return e.toISOString()}}function h(e){return e?.approval?.action==="create"}async function D(e,r={}){let t="",o=await i(n=>{let a=l(n,`crons.${e}`);if(!a)throw new Error(`cron "${e}" not found`);let s=a.approval;if(!s)throw new Error(`cron "${e}" has no pending request`);s.action==="create"?(delete a.approval,a.enabled=!0,t=`${e} approved and enabled (requested by ${s.requestedBy})`):(c(n,`crons.${e}`),t=`${e} deletion approved; job removed (requested by ${s.requestedBy})`)},{configPath:r.configPath,reload:r.reload});return o.success?{success:!0,message:t,result:o}:{success:!1,message:o.error||"failed",result:o}}async function I(e,r={}){let t="",o=await i(n=>{let a=l(n,`crons.${e}`);if(!a)throw new Error(`cron "${e}" not found`);let s=a.approval;if(!s)throw new Error(`cron "${e}" has no pending request`);s.action==="create"?(c(n,`crons.${e}`),t=`${e} rejected; pending job removed`):(delete a.approval,t=`${e} deletion rejected; job kept`)},{configPath:r.configPath,reload:r.reload});return o.success?{success:!0,message:t,result:o}:{success:!1,message:o.error||"failed",result:o}}async function O(e,r,t={}){return i(o=>{let n=l(o,`crons.${e}`);if(!n)throw new Error(`cron "${e}" not found`);if(r&&h(n))throw new Error(`cron "${e}" is awaiting approval; run \`agentx schedule approve ${e}\``);u(o,`crons.${e}.enabled`,r)},{configPath:t.configPath,reload:t.reload})}export{p as a,E as b,w as c,x as d,$ as e,S as f,P as g,T as h,A as i,h as j,D as k,I as l,O as m};
2
- //# sourceMappingURL=chunk-HOLJZIVJ.js.map
1
+ import{q as d}from"./chunk-W2RB5XG7.js";import{b as i,c as u,d as l,e as c}from"./chunk-GRVTLUQ6.js";import f from"cronstrue";var p=Intl.DateTimeFormat().resolvedOptions().timeZone,m=600,E='Try: "every morning at 9", "weekdays at 6pm", "every 15 minutes", "every monday at 10am", "1st of every month at noon", "daily at 9:30am", "every hour"',g=/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;function w(e){return g.test(e)}function x(e){try{return new Intl.DateTimeFormat("en-US",{timeZone:e}),!0}catch{return!1}}function $(e){return e?e.split(",").map(r=>r.trim().toLowerCase()).filter(r=>r==="log"||r==="notify"||r==="disable"):["log"]}function S(e){let r=[...e.onError??["log"]];e.notify&&!r.includes("notify")&&r.push("notify");let t={enabled:e.enabled??!0,schedule:e.parsed.cron,timezone:e.timezone||p,agent:e.agent,prompt:e.prompt,timeout:e.timeout??m,onError:r};return e.model&&(t.model=e.model),e.notify&&(t.notify=e.notify),e.notify&&e.deliverResult===!1&&(t.deliverResult=!1),e.createdBy&&(t.createdBy=e.createdBy),e.approval&&(t.approval=e.approval),t}function P(e){try{return f.toString(e,{use24HourTimeFormat:!1})}catch{return e}}function T(e,r,t=new Date){try{return d(e,t,r)}catch{return null}}function A(e,r){if(!e)return"unknown (no match within a year)";try{return`${new Intl.DateTimeFormat("en-GB",{timeZone:r,weekday:"short",day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit",hour12:!1}).format(e)} (${r})`}catch{return e.toISOString()}}function h(e){return e?.approval?.action==="create"}async function D(e,r={}){let t="",o=await i(n=>{let a=l(n,`crons.${e}`);if(!a)throw new Error(`cron "${e}" not found`);let s=a.approval;if(!s)throw new Error(`cron "${e}" has no pending request`);s.action==="create"?(delete a.approval,a.enabled=!0,t=`${e} approved and enabled (requested by ${s.requestedBy})`):(c(n,`crons.${e}`),t=`${e} deletion approved; job removed (requested by ${s.requestedBy})`)},{configPath:r.configPath,reload:r.reload});return o.success?{success:!0,message:t,result:o}:{success:!1,message:o.error||"failed",result:o}}async function I(e,r={}){let t="",o=await i(n=>{let a=l(n,`crons.${e}`);if(!a)throw new Error(`cron "${e}" not found`);let s=a.approval;if(!s)throw new Error(`cron "${e}" has no pending request`);s.action==="create"?(c(n,`crons.${e}`),t=`${e} rejected; pending job removed`):(delete a.approval,t=`${e} deletion rejected; job kept`)},{configPath:r.configPath,reload:r.reload});return o.success?{success:!0,message:t,result:o}:{success:!1,message:o.error||"failed",result:o}}async function O(e,r,t={}){return i(o=>{let n=l(o,`crons.${e}`);if(!n)throw new Error(`cron "${e}" not found`);if(r&&h(n))throw new Error(`cron "${e}" is awaiting approval; run \`agentx schedule approve ${e}\``);u(o,`crons.${e}.enabled`,r)},{configPath:t.configPath,reload:t.reload})}export{p as a,E as b,w as c,x as d,$ as e,S as f,P as g,T as h,A as i,h as j,D as k,I as l,O as m};
2
+ //# sourceMappingURL=chunk-AKCEMKQM.js.map
@@ -1,4 +1,4 @@
1
- import{e as g}from"./chunk-U3PHNPIJ.js";async function $(e,i,r,n,o={}){let a=o.retrieve??g,c=o.perEntry??2,s=o.maxArticles??8,f=o.queryChars??1500,h=new Map;for(let t of e){let l=[];try{l=await a(t.content.slice(0,f),i,r,{pool:n,maxCandidates:c,maxHops:1,maxArticles:c*2,stage:"absorb-covering"})}catch{}for(let u of l){let p=h.get(u.path);p?(p.hop=Math.min(p.hop,u.hop),p.entries.includes(t.id)||p.entries.push(t.id)):h.set(u.path,{...u,entries:[t.id]})}}return[...h.values()].sort((t,l)=>t.hop-l.hop||l.entries.length-t.entries.length||t.path.localeCompare(l.path)).slice(0,s)}function x(e){if(e.length===0)return"";let i=e.map(r=>{let n=`### ${r.meta.title} \u2014 ${r.meta.type||"untyped"} (${r.path})`,o=`Found for entries: ${r.entries.join(", ")}${r.hop>0?" (linked from a match)":""}`,a=r.meta.related?.length?`Related: ${r.meta.related.join(", ")}`:"";return[n,o,a,"",r.content].filter(c=>c!=="").join(`
1
+ import{e as g}from"./chunk-E76HREC7.js";async function $(e,i,r,n,o={}){let a=o.retrieve??g,c=o.perEntry??2,s=o.maxArticles??8,f=o.queryChars??1500,h=new Map;for(let t of e){let l=[];try{l=await a(t.content.slice(0,f),i,r,{pool:n,maxCandidates:c,maxHops:1,maxArticles:c*2,stage:"absorb-covering"})}catch{}for(let u of l){let p=h.get(u.path);p?(p.hop=Math.min(p.hop,u.hop),p.entries.includes(t.id)||p.entries.push(t.id)):h.set(u.path,{...u,entries:[t.id]})}}return[...h.values()].sort((t,l)=>t.hop-l.hop||l.entries.length-t.entries.length||t.path.localeCompare(l.path)).slice(0,s)}function x(e){if(e.length===0)return"";let i=e.map(r=>{let n=`### ${r.meta.title} \u2014 ${r.meta.type||"untyped"} (${r.path})`,o=`Found for entries: ${r.entries.join(", ")}${r.hop>0?" (linked from a match)":""}`,a=r.meta.related?.length?`Related: ${r.meta.related.join(", ")}`:"";return[n,o,a,"",r.content].filter(c=>c!=="").join(`
2
2
  `)}).join(`
3
3
 
4
4
  ---
@@ -14,4 +14,4 @@ These ${e.length} articles were found by searching the wiki for each entry below
14
14
 
15
15
  ${i}
16
16
  `}var d=/\bhttps?:\/\/[^\s<>"'`)\]]+/gi,y=/\[\[([^\]|]+)(?:\|[^\]]*)?\]\]/g,w=/(?<![\w-])(?=[0-9a-f]*[0-9])(?=[0-9a-f]*[a-f])[0-9a-f]{7,40}(?![\w-])/gi,k=/(?<![\w.,:/-])\d+(?:[.,:\-/]\d+)*(?![\w])/g,C=/^\s*\d+[.)]\s/gm;function A(e){let i=[...e.matchAll(d)].map(s=>s[0].replace(/[.,;:!?'"]+$/,"")),r=[...e.matchAll(y)].map(s=>s[1].trim()),n=e.replace(d," ").replace(y," ").replace(C," "),o=[...n.matchAll(w)].map(s=>s[0].toLowerCase()),c=[...n.replace(w," ").matchAll(k)].map(s=>v(s[0]));return{commits:m(o),urls:m(i),wikilinks:m(r),numbers:m(c)}}function R(e,i){let r=A(e),n=A(i),o=i.toLowerCase(),a=[];for(let t of r.commits)!o.includes(t)&&!n.commits.some(l=>l.startsWith(t)||t.startsWith(l))&&a.push(`commit ${t}`);let c=t=>t.toLowerCase().replace(/\/+$/,""),s=new Set(n.urls.map(c));for(let t of r.urls)s.has(c(t))||a.push(`link ${t}`);let f=new Set(n.wikilinks.map(t=>t.toLowerCase()));for(let t of r.wikilinks)f.has(t.toLowerCase())||a.push(`link [[${t}]]`);let h=new Set(n.numbers);for(let t of r.numbers)h.has(t)||a.push(`number ${t}`);return a}function v(e){return/^\d{1,3}(,\d{3})+$/.test(e)?e.replace(/,/g,""):e}function m(e){return[...new Set(e)]}function L(e,i){if(i.some(n=>n.path===e.path))return e.path;let r=b(e.title);return r?i.find(n=>b(n.title)===r)?.path??e.path:e.path}function b(e){return(e||"").toLowerCase().replace(/[^\p{L}\p{N}]+/gu," ").trim()}export{$ as a,x as b,A as c,R as d,L as e};
17
- //# sourceMappingURL=chunk-HF55LKFC.js.map
17
+ //# sourceMappingURL=chunk-B75BLZ2M.js.map
@@ -1,4 +1,4 @@
1
- import{La as l,Ua as m}from"./chunk-GVJMPSE2.js";m();import{existsSync as g,readFileSync as u,writeFileSync as a,copyFileSync as y}from"fs";import{resolve as p}from"path";function P(e,n={}){let t=n.configPath||p(process.cwd(),"agentx.json");if(!g(t))throw new Error(`agentx.json not found at ${t}`);let i=JSON.parse(u(t,"utf-8")),o=e(i),s=typeof o=="string"?{summary:o}:o,c=JSON.stringify(i,null,2)+`
1
+ import{La as l,Ua as m}from"./chunk-VKEH4IBA.js";m();import{existsSync as g,readFileSync as u,writeFileSync as a,copyFileSync as y}from"fs";import{resolve as p}from"path";function P(e,n={}){let t=n.configPath||p(process.cwd(),"agentx.json");if(!g(t))throw new Error(`agentx.json not found at ${t}`);let i=JSON.parse(u(t,"utf-8")),o=e(i),s=typeof o=="string"?{summary:o}:o,c=JSON.stringify(i,null,2)+`
2
2
  `,f=t+".tmp";a(f,c,"utf-8");try{JSON.parse(u(f,"utf-8"))}catch(d){throw new Error(`config did not round-trip cleanly: ${d.message}`)}let r;return n.skipBackup||(r=`${t}.bak.${Date.now()}`,y(t,r)),a(t,c,"utf-8"),n.skipReload||h().catch(()=>{}),{summary:s.summary,payload:s.payload,backupPath:r}}function S(e,n={}){let t=n.configPath||p(process.cwd(),"agentx.json");if(g(t)&&!n.overwrite)throw new Error(`agentx.json already exists at ${t}. Pass overwrite=true to replace it.`);return a(t,JSON.stringify(e,null,2)+`
3
3
  `,"utf-8"),{file:t}}async function h(){try{let n=l().dashboard.daemonUrl?.replace(/\/+$/,"")||"http://127.0.0.1:18800";await fetch(`${n}/reload`,{method:"POST"}).catch(()=>null)}catch{}}export{P as a,S as b};
4
- //# sourceMappingURL=chunk-TDMX6HTT.js.map
4
+ //# sourceMappingURL=chunk-CUAS4ITR.js.map
@@ -1,4 +1,4 @@
1
- import{a as _,b as F,c as K,d as z,e as J}from"./chunk-SKSYII3K.js";import{a as j,b as I,c as Y,d as V,e as B,j as G}from"./chunk-RARXW4KB.js";import{a as H}from"./chunk-MWNCS57L.js";import{y as N,z as ot}from"./chunk-FFPQS2C4.js";import{g as Q}from"./chunk-6TURWSMN.js";import{b as E,c as L}from"./chunk-QOYAX2FT.js";import{readFileSync as lt,existsSync as X}from"fs";ot();import{resolve as R}from"path";import{execSync as ct}from"child_process";var ht="haiku",dt="sonnet",pt=.8;function mt(e,r,o,t){if(t.size===0)return 0;let c=e.listArticles(r||"").map(l=>l.path).filter(l=>!l.includes("/_versions/"));return c.length===0&&(c=o.sharedPool.map(l=>l.path)),c.length===0?0:c.filter(l=>t.has(l)).length/c.length}async function _t(e,r,o,t={}){let c=t.selectorModel??ht,l=t.synthModel??dt,m=t.maxCandidates??3,g=t.maxHops??2,d=t.maxArticles??8,i=t.timeoutMs??6e4,s=t.log??console.error.bind(console,"[wiki-query]"),h=t.messagePath?.length?t.messagePath:void 0,n=t.graphWeight??W,a=R(r.baseDir,"_index.md"),p=tt(r,o,t.shared),b=t.method??"catalog";if(b!=="catalog"){let u=z(r,t.shared);if(b==="summaries"||mt(r,o,p,u)>=pt){let f=t.summaries??K,P=t.notes&&o&&t.notes.owner===o?F(t.notes):void 0,y=await J(e,P?gt(p,P):p,P?new Map([...u,...P.summaries]):u,{...f,navigatorModel:t.selectorModel??f.navigatorModel,answerModel:t.synthModel??f.answerModel},{call:t.call??H,fetch:t.fetch,timeoutMs:i,log:s}),$=y.picked.map(w=>({title:w.meta.title,path:w.path,type:_(w.path)?"note":w.meta.type,hop:w.hop}));return{answer:y.answer,citations:y.status==="ok"?$.map(({hop:w,...v})=>v):[],candidates:$.filter(w=>w.hop===0).map(({title:w,path:v})=>({title:w,path:v})),walked:$,status:y.status,method:"summaries",basis:y.basis,live:y.live,liveAsked:y.liveAsked,trace:y.trace,...y.error?{error:y.error}:{}}}}if(!X(a)&&p.sharedPool.length===0)return M("no-catalog",e,"No _index.md found \u2014 run `agentx wiki status` to rebuild.");let it=(X(a)?lt(a,"utf-8"):"")+yt(e,p.sharedPool,h,n),T=Date.now(),A=[],S="";try{let u=await nt(e,p.pool,o,m,h,n);u?(A=u,S=`[wiki-rerank seat] ${u.map(f=>f.title).join(" | ")}`):(S=await Z(wt(e,it,m,h),c,i),A=bt(S))}catch(u){return s("selector failed:",u?.message),{...M("error",e,`Selector: ${u?.message||"unknown"}`),trace:{selectorMs:Date.now()-T,synthesisMs:0,selectorOutput:S}}}let x=Date.now()-T;if(A.length===0)return{...M("no-candidates",e,"Selector returned no candidates."),trace:{selectorMs:x,synthesisMs:0,selectorOutput:S}};let C=rt(A,p,g,d);if(C.length===0)return{...M("no-candidates",e,"Candidates did not resolve to readable articles."),candidates:A,trace:{selectorMs:x,synthesisMs:0,selectorOutput:S}};let D=Date.now(),U="";try{U=await Z(kt(e,C),l,i*2)}catch(u){return s("synthesis failed:",u?.message),{...M("error",e,`Synthesis: ${u?.message||"unknown"}`),candidates:A,walked:C.map(f=>({title:f.meta.title,path:f.path,type:f.meta.type,hop:f.hop??0})),trace:{selectorMs:x,synthesisMs:Date.now()-D,selectorOutput:S}}}let st=Date.now()-D;return{answer:U.trim(),citations:C.map(u=>({title:u.meta.title,path:u.path,type:u.meta.type})),candidates:A,walked:C.map(u=>({title:u.meta.title,path:u.path,type:u.meta.type,hop:u.hop??0})),status:"ok",trace:{selectorMs:x,synthesisMs:st,selectorOutput:S}}}async function Rt(e,r,o,t={}){let c=t.maxCandidates??3,l=t.graphWeight??W,m=t.messagePath?.length?t.messagePath:void 0,g=t.pool??q(r);if(g.length===0||!e.trim())return[];let d=await nt(e,g,o,c,m,l,t.stage??"retrieve");if(!d){let i=new Set(L(e,E(g.map(at))).map(s=>s.docIndex));d=O(e,g,m,l).filter(s=>i.has(s)).slice(0,c).map(s=>({title:g[s].title,path:g[s].path}))}return d.length===0?[]:rt(d,tt(r,o),t.maxHops??1,t.maxArticles??6)}function q(e){try{return(e.rebuildIndex().articles??[]).filter(r=>r.path&&!r.path.includes("/_versions/"))}catch{return[]}}function M(e,r,o){return{answer:"",citations:[],candidates:[],walked:[],status:e,error:o}}function tt(e,r,o=[]){let t=new Map,c=[];for(let i of e.listArticles(r||""))t.set(i.meta.title.toLowerCase(),i.path),c.push({path:i.path,related:i.meta.related??[],lastUpdated:i.meta.lastUpdated??""});let l=[],m=new Map;for(let i of o)if(i.store.baseDir!==e.baseDir){m.set(i.id,i);for(let s of i.store.listArticles(r||"")){if(s.path.includes("/_versions/")||i.skip?.(s.path))continue;let h=`@${i.id}/${s.path}`;l.push(ut(s,h)),c.push({path:h,related:s.meta.related??[],lastUpdated:s.meta.lastUpdated??""});let n=s.meta.title.toLowerCase();t.has(n)||t.set(n,h)}}let g=new Map;if(m.size>0)for(let i of[...c].sort((s,h)=>h.lastUpdated.localeCompare(s.lastUpdated)))for(let s of i.related){let h=s.toLowerCase(),n=g.get(h)??[];n.includes(i.path)||n.push(i.path),g.set(h,n)}let d;return{backlinks:g,readable:new Set(c.map(i=>i.path)),get pool(){return d??=[...q(e),...l]},sharedPool:l,titleIndex:t,read(i){let s=i.match(/^@([^/]+)\/(.+)$/),h=s?m.get(s[1]):void 0;if(s&&!h)return null;let n=h?.store??e,a=s?s[2]:i,p=r?n.readArticleAs(a,r):n.readArticle(a);return p?{...p,path:i}:null},links(i){let s=(i.meta.related??[]).map(a=>t.get(a.toLowerCase())).filter(a=>!!a),h=[i.meta.title,...i.meta.aliases??[]].map(a=>a.toLowerCase()),n=[...new Set(h.flatMap(a=>g.get(a)??[]))].filter(a=>a!==i.path).slice(0,et);return[...new Set([...s,...n])].filter(a=>a!==i.path)}}}function gt(e,r){return{...e,pool:[...e.pool,...r.pool],readable:new Set([...e.readable,...r.pool.map(o=>o.path)]),read:o=>_(o)?r.read(o):e.read(o)}}function ut(e,r){return{path:r,title:e.meta.title,type:e.meta.type,related:e.meta.related,tags:e.meta.tags||[],owner:e.meta.owner,access:e.meta.access,sharedWith:e.meta.sharedWith,aliases:[e.meta.title.toLowerCase(),...(e.meta.aliases??[]).map(o=>o.toLowerCase())],backlinks:0,sources:e.meta.sources,lastUpdated:e.meta.lastUpdated,graphPath:e.meta.graphPath}}var ft=150;function yt(e,r,o,t){return r.length===0?"":`
1
+ import{a as _,b as F,c as K,d as z,e as J}from"./chunk-SKSYII3K.js";import{a as j,b as I,c as Y,d as V,e as B,j as G}from"./chunk-KA2NV7H4.js";import{a as H}from"./chunk-MWNCS57L.js";import{y as N,z as ot}from"./chunk-743RAKLP.js";import{g as Q}from"./chunk-6TURWSMN.js";import{b as E,c as L}from"./chunk-QOYAX2FT.js";import{readFileSync as lt,existsSync as X}from"fs";ot();import{resolve as R}from"path";import{execSync as ct}from"child_process";var ht="haiku",dt="sonnet",pt=.8;function mt(e,r,o,t){if(t.size===0)return 0;let c=e.listArticles(r||"").map(l=>l.path).filter(l=>!l.includes("/_versions/"));return c.length===0&&(c=o.sharedPool.map(l=>l.path)),c.length===0?0:c.filter(l=>t.has(l)).length/c.length}async function _t(e,r,o,t={}){let c=t.selectorModel??ht,l=t.synthModel??dt,m=t.maxCandidates??3,g=t.maxHops??2,d=t.maxArticles??8,i=t.timeoutMs??6e4,s=t.log??console.error.bind(console,"[wiki-query]"),h=t.messagePath?.length?t.messagePath:void 0,n=t.graphWeight??W,a=R(r.baseDir,"_index.md"),p=tt(r,o,t.shared),b=t.method??"catalog";if(b!=="catalog"){let u=z(r,t.shared);if(b==="summaries"||mt(r,o,p,u)>=pt){let f=t.summaries??K,P=t.notes&&o&&t.notes.owner===o?F(t.notes):void 0,y=await J(e,P?gt(p,P):p,P?new Map([...u,...P.summaries]):u,{...f,navigatorModel:t.selectorModel??f.navigatorModel,answerModel:t.synthModel??f.answerModel},{call:t.call??H,fetch:t.fetch,timeoutMs:i,log:s}),$=y.picked.map(w=>({title:w.meta.title,path:w.path,type:_(w.path)?"note":w.meta.type,hop:w.hop}));return{answer:y.answer,citations:y.status==="ok"?$.map(({hop:w,...v})=>v):[],candidates:$.filter(w=>w.hop===0).map(({title:w,path:v})=>({title:w,path:v})),walked:$,status:y.status,method:"summaries",basis:y.basis,live:y.live,liveAsked:y.liveAsked,trace:y.trace,...y.error?{error:y.error}:{}}}}if(!X(a)&&p.sharedPool.length===0)return M("no-catalog",e,"No _index.md found \u2014 run `agentx wiki status` to rebuild.");let it=(X(a)?lt(a,"utf-8"):"")+yt(e,p.sharedPool,h,n),T=Date.now(),A=[],S="";try{let u=await nt(e,p.pool,o,m,h,n);u?(A=u,S=`[wiki-rerank seat] ${u.map(f=>f.title).join(" | ")}`):(S=await Z(wt(e,it,m,h),c,i),A=bt(S))}catch(u){return s("selector failed:",u?.message),{...M("error",e,`Selector: ${u?.message||"unknown"}`),trace:{selectorMs:Date.now()-T,synthesisMs:0,selectorOutput:S}}}let x=Date.now()-T;if(A.length===0)return{...M("no-candidates",e,"Selector returned no candidates."),trace:{selectorMs:x,synthesisMs:0,selectorOutput:S}};let C=rt(A,p,g,d);if(C.length===0)return{...M("no-candidates",e,"Candidates did not resolve to readable articles."),candidates:A,trace:{selectorMs:x,synthesisMs:0,selectorOutput:S}};let D=Date.now(),U="";try{U=await Z(kt(e,C),l,i*2)}catch(u){return s("synthesis failed:",u?.message),{...M("error",e,`Synthesis: ${u?.message||"unknown"}`),candidates:A,walked:C.map(f=>({title:f.meta.title,path:f.path,type:f.meta.type,hop:f.hop??0})),trace:{selectorMs:x,synthesisMs:Date.now()-D,selectorOutput:S}}}let st=Date.now()-D;return{answer:U.trim(),citations:C.map(u=>({title:u.meta.title,path:u.path,type:u.meta.type})),candidates:A,walked:C.map(u=>({title:u.meta.title,path:u.path,type:u.meta.type,hop:u.hop??0})),status:"ok",trace:{selectorMs:x,synthesisMs:st,selectorOutput:S}}}async function Rt(e,r,o,t={}){let c=t.maxCandidates??3,l=t.graphWeight??W,m=t.messagePath?.length?t.messagePath:void 0,g=t.pool??q(r);if(g.length===0||!e.trim())return[];let d=await nt(e,g,o,c,m,l,t.stage??"retrieve");if(!d){let i=new Set(L(e,E(g.map(at))).map(s=>s.docIndex));d=O(e,g,m,l).filter(s=>i.has(s)).slice(0,c).map(s=>({title:g[s].title,path:g[s].path}))}return d.length===0?[]:rt(d,tt(r,o),t.maxHops??1,t.maxArticles??6)}function q(e){try{return(e.rebuildIndex().articles??[]).filter(r=>r.path&&!r.path.includes("/_versions/"))}catch{return[]}}function M(e,r,o){return{answer:"",citations:[],candidates:[],walked:[],status:e,error:o}}function tt(e,r,o=[]){let t=new Map,c=[];for(let i of e.listArticles(r||""))t.set(i.meta.title.toLowerCase(),i.path),c.push({path:i.path,related:i.meta.related??[],lastUpdated:i.meta.lastUpdated??""});let l=[],m=new Map;for(let i of o)if(i.store.baseDir!==e.baseDir){m.set(i.id,i);for(let s of i.store.listArticles(r||"")){if(s.path.includes("/_versions/")||i.skip?.(s.path))continue;let h=`@${i.id}/${s.path}`;l.push(ut(s,h)),c.push({path:h,related:s.meta.related??[],lastUpdated:s.meta.lastUpdated??""});let n=s.meta.title.toLowerCase();t.has(n)||t.set(n,h)}}let g=new Map;if(m.size>0)for(let i of[...c].sort((s,h)=>h.lastUpdated.localeCompare(s.lastUpdated)))for(let s of i.related){let h=s.toLowerCase(),n=g.get(h)??[];n.includes(i.path)||n.push(i.path),g.set(h,n)}let d;return{backlinks:g,readable:new Set(c.map(i=>i.path)),get pool(){return d??=[...q(e),...l]},sharedPool:l,titleIndex:t,read(i){let s=i.match(/^@([^/]+)\/(.+)$/),h=s?m.get(s[1]):void 0;if(s&&!h)return null;let n=h?.store??e,a=s?s[2]:i,p=r?n.readArticleAs(a,r):n.readArticle(a);return p?{...p,path:i}:null},links(i){let s=(i.meta.related??[]).map(a=>t.get(a.toLowerCase())).filter(a=>!!a),h=[i.meta.title,...i.meta.aliases??[]].map(a=>a.toLowerCase()),n=[...new Set(h.flatMap(a=>g.get(a)??[]))].filter(a=>a!==i.path).slice(0,et);return[...new Set([...s,...n])].filter(a=>a!==i.path)}}}function gt(e,r){return{...e,pool:[...e.pool,...r.pool],readable:new Set([...e.readable,...r.pool.map(o=>o.path)]),read:o=>_(o)?r.read(o):e.read(o)}}function ut(e,r){return{path:r,title:e.meta.title,type:e.meta.type,related:e.meta.related,tags:e.meta.tags||[],owner:e.meta.owner,access:e.meta.access,sharedWith:e.meta.sharedWith,aliases:[e.meta.title.toLowerCase(),...(e.meta.aliases??[]).map(o=>o.toLowerCase())],backlinks:0,sources:e.meta.sources,lastUpdated:e.meta.lastUpdated,graphPath:e.meta.graphPath}}var ft=150;function yt(e,r,o,t){return r.length===0?"":`
2
2
 
3
3
  ## Shared wiki (other agents' articles)
4
4
 
@@ -51,5 +51,5 @@ ${o}
51
51
 
52
52
  Answer the question in 2\u20136 sentences. Cite articles by their title in square brackets like [Article Title]. When two articles disagree, prefer the one updated more recently, and say which agent's page and date the answer comes from. If the articles do not answer the question, say so plainly (do not invent). Prefer concrete facts over hedging.
53
53
 
54
- Output ONLY the answer \u2014 no preamble, no "here is my answer:", no markdown fencing.`}function bt(e){let r=e.match(/\[[\s\S]*?\]/);if(!r)return[];try{let o=JSON.parse(r[0]);return Array.isArray(o)?o.filter(t=>t&&typeof t.title=="string"&&typeof t.path=="string").map(t=>({title:t.title,path:t.path})):[]}catch{return[]}}async function Z(e,r,o){let{writeFileSync:t,mkdirSync:c,rmSync:l}=await import("fs"),{tmpdir:m}=await import("os"),g=R(m(),`agentx-wiki-query-${process.pid}`);c(g,{recursive:!0});let d=R(g,`prompt-${Date.now()}.txt`);t(d,e);try{let i=`cat '${d}' | claude -p - --output-format json --max-turns 1 --model ${r} --disallowedTools "Bash Read Write Edit Glob Grep Agent WebSearch WebFetch NotebookEdit"`,s=ct(i,{env:Q(),encoding:"utf-8",timeout:o,maxBuffer:4*1024*1024});try{let h=JSON.parse(s);return String(h.result||h.content||"")}catch{return s}}finally{try{l(d,{force:!0})}catch{}}}async function Ot(e){try{let{loadDaemonConfig:r}=await import("./config-VXXKMXHH.js");return r(e).wiki.query.shared}catch{return!0}}export{ht as a,dt as b,pt as c,_t as d,Rt as e,q as f,ft as g,W as h,O as i,Ot as j};
55
- //# sourceMappingURL=chunk-U3PHNPIJ.js.map
54
+ Output ONLY the answer \u2014 no preamble, no "here is my answer:", no markdown fencing.`}function bt(e){let r=e.match(/\[[\s\S]*?\]/);if(!r)return[];try{let o=JSON.parse(r[0]);return Array.isArray(o)?o.filter(t=>t&&typeof t.title=="string"&&typeof t.path=="string").map(t=>({title:t.title,path:t.path})):[]}catch{return[]}}async function Z(e,r,o){let{writeFileSync:t,mkdirSync:c,rmSync:l}=await import("fs"),{tmpdir:m}=await import("os"),g=R(m(),`agentx-wiki-query-${process.pid}`);c(g,{recursive:!0});let d=R(g,`prompt-${Date.now()}.txt`);t(d,e);try{let i=`cat '${d}' | claude -p - --output-format json --max-turns 1 --model ${r} --disallowedTools "Bash Read Write Edit Glob Grep Agent WebSearch WebFetch NotebookEdit"`,s=ct(i,{env:Q(),encoding:"utf-8",timeout:o,maxBuffer:4*1024*1024});try{let h=JSON.parse(s);return String(h.result||h.content||"")}catch{return s}}finally{try{l(d,{force:!0})}catch{}}}async function Ot(e){try{let{loadDaemonConfig:r}=await import("./config-FZTWI3VG.js");return r(e).wiki.query.shared}catch{return!0}}export{ht as a,dt as b,pt as c,_t as d,Rt as e,q as f,ft as g,W as h,O as i,Ot as j};
55
+ //# sourceMappingURL=chunk-E76HREC7.js.map