agentix-cli 0.185.0 → 0.185.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{board-dashboard-TCZ3RAQR.js → board-dashboard-BIERRXDD.js} +12 -8
- package/dist/{board-dashboard-TCZ3RAQR.js.map → board-dashboard-BIERRXDD.js.map} +1 -1
- package/dist/{chunk-JJ7FHH53.js → chunk-BIYEGA7Q.js} +2 -2
- package/dist/{chunk-LZVQ4N2Z.js → chunk-BXTSO66H.js} +2 -2
- package/dist/{chunk-Z5DHUJIL.js → chunk-MYFTR4NH.js} +2 -2
- package/dist/{chunk-P7K5ZQVT.js → chunk-TAZIS2VP.js} +2 -2
- package/dist/{chunk-2HZXLYWQ.js → chunk-UXWG4DMD.js} +3 -3
- package/dist/{chunk-BLWVMGSJ.js → chunk-XPZSEDE3.js} +1 -1
- package/dist/chunk-XPZSEDE3.js.map +1 -0
- package/dist/{chunk-DSIPKP2D.js → chunk-ZRC2ZHHE.js} +2 -2
- package/dist/cli.js +1 -1
- package/dist/{doctor-DKW3EP3O.js → doctor-NPHNPYHR.js} +2 -2
- package/dist/{grants-COGXFWO3.js → grants-3UVDASRI.js} +2 -2
- package/dist/index.js +1 -1
- package/dist/{program-2DFU4DCC.js → program-GQ3YWR5W.js} +5 -5
- package/package.json +1 -1
- package/dist/chunk-BLWVMGSJ.js.map +0 -1
- /package/dist/{chunk-JJ7FHH53.js.map → chunk-BIYEGA7Q.js.map} +0 -0
- /package/dist/{chunk-LZVQ4N2Z.js.map → chunk-BXTSO66H.js.map} +0 -0
- /package/dist/{chunk-Z5DHUJIL.js.map → chunk-MYFTR4NH.js.map} +0 -0
- /package/dist/{chunk-P7K5ZQVT.js.map → chunk-TAZIS2VP.js.map} +0 -0
- /package/dist/{chunk-2HZXLYWQ.js.map → chunk-UXWG4DMD.js.map} +0 -0
- /package/dist/{chunk-DSIPKP2D.js.map → chunk-ZRC2ZHHE.js.map} +0 -0
- /package/dist/{doctor-DKW3EP3O.js.map → doctor-NPHNPYHR.js.map} +0 -0
- /package/dist/{grants-COGXFWO3.js.map → grants-3UVDASRI.js.map} +0 -0
- /package/dist/{program-2DFU4DCC.js.map → program-GQ3YWR5W.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{C as $i,D as ji,E as Ze,F as zn,G as Di,H as Ni,I as La,K as Hi,Q as Bi,R as qi,S as Wi,T as zi,U as Fi,Y as Ui,Z as Gi,a as We,aa as Xi,b as X,ba as Ki,c as z,d as ze,e as Pa,f as ve,fa as Oa,g as se,ga as Qi,h as Ma,ha as Zi,i as _i,ia as el,j as Si,k as Ai,ka as tl,l as Ti,la as al,n as Ei,o as Ci,p as Ri,q as Ii,r as Pi,s as Mi,t as Li,u as Oi}from"./chunk-
|
|
1
|
+
import{C as $i,D as ji,E as Ze,F as zn,G as Di,H as Ni,I as La,K as Hi,Q as Bi,R as qi,S as Wi,T as zi,U as Fi,Y as Ui,Z as Gi,a as We,aa as Xi,b as X,ba as Ki,c as z,d as ze,e as Pa,f as ve,fa as Oa,g as se,ga as Qi,h as Ma,ha as Zi,i as _i,ia as el,j as Si,k as Ai,ka as tl,l as Ti,la as al,n as Ei,o as Ci,p as Ri,q as Ii,r as Pi,s as Mi,t as Li,u as Oi}from"./chunk-TAZIS2VP.js";import"./chunk-EFGAPAYZ.js";import{a as Vi}from"./chunk-TADIDWYZ.js";import{a as Ji,b as Yi}from"./chunk-NZQBS7GN.js";import"./chunk-QAWKN2N4.js";import"./chunk-DODL5POT.js";import{a as O}from"./chunk-A4PW7EIK.js";import{a as ki}from"./chunk-LNY6N73E.js";import{$ as Qs,A as Fs,Aa as J,Ba as ri,Ca as oi,Da as si,Db as gi,Ea as ii,Fb as Qe,Ga as li,Ha as Aa,Ib as hi,Kb as gt,La as di,Lb as Ta,M as Xs,Mb as Ea,Nb as Ca,Ob as Ra,Pb as bi,Qb as xi,Rb as vi,S as Le,Sb as Ia,T as Ks,U as ue,Ub as wi,V as wa,W as ya,X as ka,Xb as yi,Y as Vs,Z as Js,_ as Ys,a as Is,aa as qn,ba as _a,c as ha,ca as Sa,d as Nn,da as Zs,e as Ps,fa as Bt,ja as Oe,ma as ei,na as Wn,o as ba,qb as ci,r as Ht,sa as ti,sb as pi,t as Ms,ta as ai,tb as ui,ub as fi,wb as mi,xa as ni,y as zs}from"./chunk-BXTSO66H.js";import"./chunk-GTJIKXDB.js";import{h as Cs,i as Rs}from"./chunk-NBWSZ53L.js";import{F as Ls,H as Os,a as ys,b as ks,c as _s,d as Ss,k as Ts,l as qe,m as Es}from"./chunk-ZRC2ZHHE.js";import{a as ga}from"./chunk-IMLAPB7G.js";import"./chunk-NHW4IY6N.js";import{a as Ns,b as mt,d as Hs,e as Bs,f as xa}from"./chunk-2VDO2HEK.js";import{g as va}from"./chunk-LQE73AZR.js";import{b as qs,c as Ws}from"./chunk-2D3RYIDU.js";import"./chunk-MRIVENBY.js";import{b as Us,c as Gs,r as Bn}from"./chunk-XPZSEDE3.js";import"./chunk-2V6ZGE74.js";import"./chunk-2AXFYDWF.js";import"./chunk-AQASR6KR.js";import{a as $s,b as Q,c as Ee,d as js,e as Hn}from"./chunk-UKUH662W.js";import{b as Ds}from"./chunk-JWDJMFU6.js";import"./chunk-MNG2AMKZ.js";import"./chunk-RX5O5637.js";import"./chunk-5ELIX7BQ.js";import{d as As}from"./chunk-QPABR72X.js";import"./chunk-V4IOGISL.js";import"./chunk-KP7KDLZ2.js";import{$ as xs,A as da,Aa as ws,B as os,C as ss,D as is,E as ls,F as ca,G as ds,H as cs,I as jn,J as Dn,N as ps,P as us,Q as fs,a as Yo,f as Qo,fa as vs,g as Zo,h as es,o as ts,q as as,r as Nt,s as $n,t as ns,u as rs,wa as ua,xa as fa,y as ia,ya as ma,z as la,za as Te}from"./chunk-2GIYVYIM.js";import"./chunk-MEFPXHQJ.js";import"./chunk-SZDACK6O.js";import"./chunk-AFRHKA7B.js";import{n as ms,o as gs,p as hs}from"./chunk-VJVXEVZ7.js";import"./chunk-RTIGD4NG.js";import{a as pa,b as bs}from"./chunk-NS2HSAHF.js";import"./chunk-3UOTLMXD.js";import"./chunk-PE5V2LI7.js";import"./chunk-GQ76J72O.js";import"./chunk-ILEC3IAV.js";import"./chunk-GV7S5BAX.js";import"./chunk-GSX4NK2N.js";import"./chunk-FJMTCU4S.js";import"./chunk-BITVUKT7.js";import"./chunk-OWNQ2FD4.js";import"./chunk-KEXBEUSU.js";import"./chunk-ROLSSYXE.js";import{g as Jo}from"./chunk-56F5UTTA.js";import{b as Vo}from"./chunk-WPNRDEHW.js";import"./chunk-LR4QUAJT.js";import"./chunk-72SZI2UW.js";import"./chunk-FCPTN6NF.js";import"./chunk-MCI3DIWW.js";import"./chunk-QUFIUXMQ.js";import{c as U}from"./chunk-BERWTVG2.js";import"./chunk-AHWWJ7AF.js";import"./chunk-DCIYOPJF.js";import"./chunk-7I7IEX4S.js";import{Gb as Dt,H as ta,I as jg,Ia as ra,La as oa,Pa as Wo,Ra as ft,S as Do,Sa as zo,T as No,U as Ho,Ua as Fo,V as Bo,Wa as Uo,_ as Pn,_a as sa,a as Zt,b as To,c as Cn,d as Me,da as Hg,e as Ae,ea as Z,f as jt,fa as Mn,g as ea,ha as Ln,i as Eo,j as Rn,k as Co,ka as qo,l as Ro,la as On,m as $g,pa as Be,vb as Go,wb as Xo,xb as re,yb as Ko}from"./chunk-BZJF7DJR.js";import{a as Io,b as aa,c as In,d as Po,h as Mo}from"./chunk-VJ5HC63R.js";import{d as Lo,e as Dg,g as Oo,h as $o,i as Ng,j as na,r as jo}from"./chunk-UEEB3UTU.js";import"./chunk-VQRY4IDI.js";import"./chunk-RGDKHYY2.js";import"./chunk-QIJLFPWE.js";To();function Fn(e,t,a=Date.now()){let r=Math.max(0,a-(e.updatedAt||a)),n=e.clientId?t[e.clientId]:void 0;if(!n)return{score:r/864e5,ageMs:r,rising:!1,overdue:!1};let o=r/(n*6e4);return{score:1e3+o,ageMs:r,rising:!0,overdue:o>=1}}function nl(e,t,a=Date.now()){return e.map((r,n)=>({i:n,s:Fn(r,t,a).score})).sort((r,n)=>n.s-r.s||r.i-n.i).map(r=>r.i)}var we={refresh:'<path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15-6.7L21 8"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 0 1-15 6.7L3 16"/>',clock:'<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>',alert:'<path d="M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z"/><path d="M12 9v4"/><path d="M12 17h.01"/>',gavel:'<path d="M12 3 6 9"/><path d="m9 6 6 6"/><path d="M15 9 9 15"/><path d="m12 12 6 6"/><path d="M4 21h10"/>',loop:'<path d="M17 2l4 4-4 4"/><path d="M3 11V9a4 4 0 0 1 4-4h14"/><path d="M7 22l-4-4 4-4"/><path d="M21 13v2a4 4 0 0 1-4 4H3"/>',broom:'<path d="M3 21h18"/><path d="M12 3v9"/><path d="m7 12 5-3 5 3-1.5 6h-7Z"/>',server:'<rect x="2" y="3" width="20" height="7" rx="2"/><rect x="2" y="14" width="20" height="7" rx="2"/><path d="M6 6.5h.01"/><path d="M6 17.5h.01"/>',inbox:'<path d="M21 12h-6l-2 3h-2l-2-3H3"/><path d="M5 5h14l2 7v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-5Z"/>',cross:'<circle cx="12" cy="12" r="9"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/>',file:'<path d="M14 2H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7Z"/><path d="M14 2v5h5"/>',search:'<circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/>',chev:'<path d="m6 9 6 6 6-6"/>',chevr:'<path d="m9 6 6 6-6 6"/>',ext:'<path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>',pulse:'<path d="M3 12h4l3-8 4 16 3-8h4"/>',plug:'<path d="M9 2v6"/><path d="M15 2v6"/><path d="M6 8h12v3a6 6 0 0 1-12 0Z"/><path d="M12 17v5"/>',check:'<path d="M20 6 9 17l-5-5"/>',route:'<circle cx="6" cy="19" r="3"/><circle cx="18" cy="5" r="3"/><path d="M9 19h6a4 4 0 0 0 0-8H9a4 4 0 0 1 0-8h6"/>',branch:'<circle cx="6" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="8" r="3"/><path d="M18 11v1a3 3 0 0 1-3 3H9"/><path d="M6 9v6"/>',send:'<path d="M22 2 11 13"/><path d="M22 2l-7 20-4-9-9-4Z"/>',msg:'<path d="M21 11.5a8.4 8.4 0 0 1-12.9 7.5L3 21l2-5.1A8.4 8.4 0 1 1 21 11.5Z"/>',code:'<path d="m9 18-6-6 6-6"/><path d="m15 6 6 6-6 6"/>',hash:'<path d="M4 9h16"/><path d="M4 15h16"/><path d="M10 3 8 21"/><path d="M16 3l-2 18"/>',x:'<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',trace:'<path d="M4 4v16h16"/><path d="m7 15 4-4 3 3 5-6"/>'},et=(e,t=14)=>'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="'+t+'" height="'+t+'" aria-hidden="true">'+e+"</svg>",$a=(e,t,a,r="")=>'<div class="ax-sec-label"><h3>'+et(e,13)+t+(a?'<span class="ax-sec-label__n" id="'+a+'"></span>':"")+"</h3>"+r+"</div>";function rl(e={}){return z({title:"AgentX \xB7 Monitor",activeTab:"monitor",subtitle:"Monitor",peers:e.peers,body:`<div class="bf">
|
|
2
2
|
|
|
3
3
|
<div class="bf-head">
|
|
4
4
|
<div>
|
|
@@ -10731,12 +10731,17 @@ loadAgent();
|
|
|
10731
10731
|
return '<button type="button" data-dkind="' + t[0] + '" class="wdc__chip' + (on ? ' is-on' : '') + '" aria-pressed="' + (on ? 'true' : 'false') + '">' + t[1] + ' <span class="n">' + t[2] + '</span></button>';
|
|
10732
10732
|
}).join('') + '</div>';
|
|
10733
10733
|
}
|
|
10734
|
+
/** One answered line's word, the same on the Answered tab and in Answered today. */
|
|
10735
|
+
function decVerb(a) {
|
|
10736
|
+
if (a.answer === 'closed') return 'Closed';
|
|
10737
|
+
if (a.kind === 'memory') return a.answer === 'yes' ? 'Kept' : 'Dropped';
|
|
10738
|
+
return a.answer === 'yes' ? 'Yes' : 'No';
|
|
10739
|
+
}
|
|
10734
10740
|
function decAnsweredHtml(list, since) {
|
|
10735
10741
|
var start = since ? 'History starts ' + stamp(Date.parse(since)).slice(0, 10) + '. ' : '';
|
|
10736
|
-
if (!list.length) return '<div class="wdc__empty"><h2>Nothing answered yet</h2><p>' + esc(start) + 'Your answers show here, from this page, the Desk, the phone app and the Mac card.</p></div>';
|
|
10742
|
+
if (!list.length) return '<div class="wdc__empty"><h2>Nothing answered yet</h2><p>' + esc(start) + 'Your yes and no answers show here, from this page, the Desk, the phone app and the Mac card. Reviews and request replies are not listed.</p></div>';
|
|
10737
10743
|
return '<ol class="wdc__done">' + list.map(function (a) {
|
|
10738
|
-
|
|
10739
|
-
return '<li><b>' + verb + '</b>' + (a.choice ? ' (' + esc(a.choice) + ')' : '') + ' · ' + esc(nameOf(a.raised_by)) + ' · <span dir="auto">' + esc(a.title) + '</span>' +
|
|
10744
|
+
return '<li><b>' + decVerb(a) + '</b>' + (a.choice ? ' (' + esc(a.choice) + ')' : '') + ' · ' + esc(nameOf(a.raised_by)) + ' · <span dir="auto">' + esc(a.title) + '</span>' +
|
|
10740
10745
|
(a.text ? ' · <span dir="auto" class="k">' + esc(a.text) + '</span>' : '') + ' · <time title="' + esc(stamp(Date.parse(a.at))) + '">' + esc(stamp(Date.parse(a.at))) + '</time>' +
|
|
10741
10746
|
'<span class="k"> by ' + esc(a.by) + '</span></li>';
|
|
10742
10747
|
}).join('') + '</ol>';
|
|
@@ -10782,9 +10787,8 @@ loadAgent();
|
|
|
10782
10787
|
var today = new Date().toDateString();
|
|
10783
10788
|
var done = (v.answered || []).filter(function (a) { return new Date(Date.parse(a.at)).toDateString() === today; });
|
|
10784
10789
|
var answered = '<section class="ax-wall__box"><h2>Answered today</h2>' + (done.length ? done.slice(0, 5).map(function (a) {
|
|
10785
|
-
var verb = a.kind === 'memory' ? (a.answer === 'yes' ? 'Kept' : 'Dropped') : a.answer === 'yes' ? 'Yes' : 'No';
|
|
10786
10790
|
var t = new Date(Date.parse(a.at));
|
|
10787
|
-
return '<p><b>' +
|
|
10791
|
+
return '<p><b>' + decVerb(a) + '</b> · ' + esc(nameOf(a.raised_by)) + ' · ' + esc(a.title) + ' · ' + String(t.getHours()).padStart(2, '0') + ':' + String(t.getMinutes()).padStart(2, '0') + '</p>';
|
|
10788
10792
|
}).join('') : '<p class="k">Nothing yet today.</p>') + '<p><button type="button" class="wa-more" data-dtab="answered">All answered →</button></p></section>';
|
|
10789
10793
|
var s = v.settings || {}, d = s.desk || {}, dg = s.digest || {};
|
|
10790
10794
|
var reach = '<section class="ax-wall__box"><h2>Reaching ' + (decOwner() ? 'you' : 'the owner') + '</h2><p>Phone: ' + esc(DEC_REACH[d.phone] || 'off') + '. Computer: ' + esc(DEC_REACH[d.computer] || 'off') + '. ' +
|
|
@@ -24280,7 +24284,7 @@ td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
|
|
|
24280
24284
|
`))if(n.trim())try{let o=Vo.safeParse(JSON.parse(n));o.success&&a.push(o.data)}catch{}return co={key:t,rows:a},a}function kk(e){if(!Um(e))return[];try{let t=JSON.parse(Gm(e,"utf-8"));return Array.isArray(t?.nodes)?t.nodes:[]}catch{return[]}}function Vm(e,t){if(e.status==="pending")return null;let a=t?.preview??"",r=e.preview??"",n=a&&r.startsWith(a)?r.slice(a.length):"";if(!n){let s=r.lastIndexOf(" \xB7 reviewer=");n=s>=0?r.slice(s):""}let o=n.match(/^ · (?:reviewer=(\S+))?(?: · ([\s\S]*))?$/);return{verdict:e.status,by:o?.[1]??null,reason:o?.[2]?Km(o[2],200):null,at:mn(e.ts)}}function _k(e,t,a){let r=new Map(a.map(n=>[n.id,n]));return e.path.map(n=>{let o=r.get(n);return o?{op:n in e.proposedAxes&&mn(o.createdAt)>=t?"add":"keep",id:n,level:o.level,parentId:o.parentId,axes:o.axes??{}}:{op:"missing",id:n,level:null,parentId:null,axes:e.proposedAxes[n]??{}}})}function Sk(e){let t=new Map;for(let n of e){let o=t.get(n.msgHash)??[];o.push(n),t.set(n.msgHash,o)}let a=new Map,r=0;for(let[n,o]of t)o.some(s=>s.status==="pending")?a.set(n,o):r++;return{groups:a,autoApproved:r}}function Ak(e,t){let a=new Map(t.map(r=>[r.id,r]));return e.path.map(r=>a.get(r)?.axes?.name||e.proposedAxes[r]?.name||r).join(" ").slice(0,200)}function Fm(e,t){let a=e.find(s=>s.status==="pending")??e[0],r=e[e.length-1],n=mn(a.ts),o=Vm(r,e.length>1?e[e.length-2]:null);return{id:r.msgHash,status:r.status,path:r.path,proposedAxes:r.proposedAxes,confidence:typeof a.confidence=="number"?a.confidence:null,source:a.source,agentId:a.agentId??null,channel:a.channel??null,message:Km(a.preview),proposedAt:n,decision:o,taxonomy:r.status==="approved"?_k(r,n,t):[],wikiQuery:Ak(r,t)}}function Tk(e){return e.map((t,a)=>{if(t.status==="pending"){let n=typeof t.confidence=="number"?`, confidence ${t.confidence.toFixed(2)}`:"";return{at:mn(t.ts),status:t.status,who:t.agentId??null,text:`Proposed ${t.path.join(" \u203A ")} (${t.source}${n})`}}let r=Vm(t,a>0?e[a-1]:null);return{at:r.at,status:t.status,who:r.by,text:`${t.status==="approved"?"Approved":"Rejected"}${r.reason?`: ${r.reason}`:""}`}})}function Jm(e,t,a,r){let n={node:a,syncedAt:r,enabled:t.enabled},o=t.baseDir?yk(Wm(t.baseDir,"classifications.jsonl")):[],{groups:s,autoApproved:i}=Sk(o),l=t.baseDir&&s.size?kk(Wm(t.baseDir,"nodes.json")):[],d=e.get("id");if(d){let f=s.get(d);return f?{status:200,body:{...n,review:Fm(f,l),events:Tk(f)}}:{status:404,body:{error:"no review for that classification id"}}}let c=e.get("status")??"all",p=Math.max(1,Math.min(vk,Number(e.get("limit")??zm)||zm)),u=[...s.values()].map(f=>Fm(f,l)),m={pending:u.filter(f=>f.status==="pending").length,approved:u.filter(f=>f.status==="approved").length,rejected:u.filter(f=>f.status==="rejected").length,autoApproved:i},x=u.filter(f=>c==="all"||(c==="decided"?f.status!=="pending":f.status===c)).sort((f,_)=>(_.decision?.at??_.proposedAt)-(f.decision?.at??f.proposedAt)).slice(0,p);return{status:200,body:{...n,counts:m,reviews:x}}}import{randomUUID as po}from"crypto";Be();var Se="/api/admin/wall",eg=`${Se}/comment`,tg=`${Se}/call`,ag=`${Se}/post`,It=`${Se}/space`,ng=`${Se}/budget`,rg=`${Se}/decide`,Ek=`${rg}/popup`,Ym=`${Se}/review`,Ck=`${Se}/request`;function og(e,t){if(e!=="POST")return null;if(t===rg)return"/api/admin/approvals/decide";if(t===Ek)return"/api/admin/approvals/popup";if(t===`${Ym}/approve`)return"/api/admin/graph/classifications/approve";if(t===`${Ym}/reject`)return"/api/admin/graph/classifications/reject";for(let a of["reply","handoff","close"])if(t===`${Ck}/${a}`)return`/api/admin/approvals/requests/${a}`;return null}var Qm=`${Se}/settings`,Rk=new Set(["POST /org/hold","POST /agents","PATCH /agents","DELETE /agents","POST /agents/access","POST /agents/integrations","DELETE /agents/integrations","POST /agents/test","PUT /files","POST /files/skill","DELETE /files/skill","POST /wiki/curator"]);function sg(e,t){if(!t.startsWith(`${Qm}/`))return null;let a=t.slice(Qm.length);return Rk.has(`${e} ${a}`)?`/api/admin${a}`:null}var gn=/^[A-Za-z0-9_.:-]{1,64}$/,Ik=200,Pk=1500,Mk=200;function ig(e,t){return e==="GET"||e==="HEAD"||e==="OPTIONS"?!1:t===Se||t.startsWith(`${Se}/`)}function uo(e){return e===eg||e===ag||e===tg||e===It||e.startsWith(`${It}/`)}var be=e=>typeof e=="string"?e.trim():"";function Zm(e){if(!e||typeof e!="object")return e;let t=e,a={...t};return Array.isArray(t.transcript)&&(a.transcript=t.transcript.map(r=>({name:String(r?.name??""),text:U(String(r?.text??""))}))),typeof t.saying=="string"&&(a.saying=U(t.saying)),typeof t.goal=="string"&&(a.goal=U(t.goal)),a}async function lg(e,t,a,r){if(!uo(t))return null;let n=r.now?.()??Date.now();if(t===eg){if(e!=="POST")return{status:405,body:{error:"POST"}};let o=be(a.id),s=be(a.text);if(!o||!s)return{status:400,body:{error:"send { id, text }"}};if(s.length>Ln)return{status:400,body:{error:`the comment is longer than ${Ln} characters`}};let i=ue(r.inbox),l=i?.get(o);if(!i||!l||l.state==="candidate")return{status:404,body:{error:`no post "${o}" on this computer`}};if(!Z.includes(l.state))return Le(r.inbox.configPath).enabled?i.reopen(o,s,n)?(i.comment(o,`wc-${n}-${po().slice(0,8)}`,s,n),{status:200,body:{ok:!0,agentId:l.agentId,reopened:!0,message:`Sent to ${l.agentId}: the post was ${l.state}, so it opens again, and its answer shows in the thread.`}}):{status:409,body:{error:`${o} changed while sending; try again`}}:{status:409,body:{error:"Requests are off on this computer, so nothing would give the agent the comment."}};let d=await St("POST",`${ke}/reply`,{id:o,text:s},{...r.inbox,now:n});return d.status!==200?d:(i.comment(o,`wc-${n}-${po().slice(0,8)}`,s,n),{status:200,body:{ok:!0,agentId:l.agentId,message:`Sent to ${l.agentId}: it goes on with this post within a minute, and its answer shows in the thread.`}})}if(t===ag){if(e!=="POST")return{status:405,body:{error:"POST"}};let o=be(a.agent),s=be(a.text);if(!gn.test(o)||!s)return{status:400,body:{error:"send { agent, text }"}};if(s.length>On)return{status:400,body:{error:`the post is longer than ${On} characters`}};let i=Ft(r.inbox.configPath).find(c=>c.id===o);if(!i)return{status:404,body:{error:`"${o}" is not an agent on this computer`}};if(!Le(r.inbox.configPath).enabled)return{status:409,body:{error:"Requests are off on this computer, so nothing would give the agent the post."}};let l=ue(r.inbox);if(!l)return{status:503,body:{error:"the requests store is not available"}};let d=`wp-${n}-${po().slice(0,8)}`;return l.addWallPost({id:d,agentId:o,text:s,now:n}),{status:200,body:{ok:!0,id:d,agentId:o,message:`Posted: ${i.name} gets it within a minute, and its answer shows on the post.`}}}if(t===tg){if(e!=="POST")return{status:405,body:{error:"POST"}};let o=be(a.id),s=be(a.agent);if(!o&&s)return(gn.test(s)?Ft(r.inbox.configPath).find(u=>u.id===s):null)?r.daemon("POST","/calls/owner",{agentId:s,reason:"The owner called from the Wall"}):{status:404,body:{error:`"${s}" is not an agent on this computer`}};if(!o)return{status:400,body:{error:"send { id } or { agent }"}};let i=ue(r.inbox),l=i?.get(o);if(!i||!l||l.state==="candidate")return{status:404,body:{error:`no post "${o}" on this computer`}};let d=(l.headline??qe(l.text,140)).replace(/\s+/g," ").trim(),c=`Wall post ${o}: ${d}`.slice(0,Mk);return r.daemon("POST","/calls/owner",{agentId:l.agentId,reason:c})}if(t===It&&e==="GET"){let o=await r.daemon("GET","/talk");return{status:o.status,body:Zm(o.body)}}if(t===It&&e==="POST"){let o=be(a.agent),s=be(a.with),i=be(a.topic).replace(/\s+/g," ").slice(0,Ik);if(!gn.test(o)||!gn.test(s))return{status:400,body:{error:"send { agent, with }: two agent ids"}};if(o===s)return{status:400,body:{error:"pick another agent to talk with"}};if(!i)return{status:400,body:{error:"send { topic }: what the post is about"}};let l=be(a.id),d=U([l?`This talk is about Wall post ${l}.`:"",be(a.context).slice(0,Pk)].filter(Boolean).join(`
|
|
24281
24285
|
`)),c=await r.daemon("POST","/talk",{agents:[o,s],topic:i,context:d,maxTurns:10});return{status:c.status,body:Zm(c.body)}}if(t===`${It}/say`){if(e!=="POST")return{status:405,body:{error:"POST"}};let o=be(a.text).slice(0,1e3);return o?r.daemon("POST","/voice/door",{text:o}):{status:400,body:{error:"send { text }"}}}return t===`${It}/stop`?e!=="POST"?{status:405,body:{error:"POST"}}:r.daemon("POST","/talk/stop",{}):{status:404,body:{error:"not found"}}}import{existsSync as Lk,readFileSync as Ok}from"fs";import{resolve as hn}from"path";var mo="/api/admin/model-ready",go="/api/admin/model-key";function $k(e){for(let t of[hn(e,"agentx.json"),hn(e,".agentx/config.json")])if(Lk(t))return JSON.parse(Ok(t,"utf-8"));return{}}function fo(e,t){return Ii({rawConfig:$k(t.dir),agentId:e,env:t.env??process.env,dotenv:Pi(hn(t.dir,".env")),hasBinary:t.hasBinary??(a=>!!mi(a)),cliLoggedIn:t.cliLoggedIn??Li})}function Pe(e,t,a){return e.writeHead(t,{"Content-Type":"application/json"}),e.end(JSON.stringify(a)),!0}async function dg(e,t,a,r,n){let o=e.method||"GET";if(o==="GET"&&a===mo){let s=r.get("agent")||"";if(!s)return Pe(t,400,{error:"agent is required"});try{return Pe(t,200,fo(s,n))}catch(i){return Pe(t,500,{error:i.message})}}if(o==="POST"&&a===go){let s=await n.readBody(e).catch(()=>null)||{},i=typeof s.agent=="string"?s.agent:"",l=typeof s.key=="string"?s.key.trim():"";if(!i||!l)return Pe(t,400,{error:"agent and key are required"});if(/\s/.test(l)||l.length>500)return Pe(t,400,{error:"That does not look like an API key (one line, no spaces)."});let d=fo(i,n);if(d.ready)return Pe(t,200,d);if(d.need!=="key"||!d.envVar)return Pe(t,409,{error:d.hint||"This agent does not take a key."});if(!Mi(hn(n.dir,".env"),d.envVar,l))return Pe(t,409,{error:`${d.envVar} is already in .env. Edit it there.`});try{await n.reloadDaemon()}catch(p){return Pe(t,502,{error:`Saved to .env, but the daemon did not reload: ${p.message}. Restart it with: agentx daemon restart`})}return Pe(t,200,fo(i,n))}return!1}var jk="/api/admin/agent-chat";function bn(e,t,a){return e.writeHead(t,{"Content-Type":"application/json"}),e.end(JSON.stringify(a)),!0}async function cg(e,t,a,r){if(a!==jk||e.method!=="POST")return!1;let n=await r.readBody(e).catch(()=>null)||{},o=typeof n.agent=="string"?n.agent:"",s=typeof n.message=="string"?n.message.trim():"";if(!o||!s)return bn(t,400,{error:"agent and message are required"});let i={"Content-Type":"application/json"};r.token&&(i.Authorization=`Bearer ${r.token}`);try{let l=await(r.fetch??fetch)(r.daemonUrl.replace(/\/+$/,"")+"/task",{method:"POST",headers:i,body:JSON.stringify({agent:o,message:s,context:{channel:"test-drive",sender:"admin-ui"}}),signal:AbortSignal.timeout(6e5)}),d=await l.json().catch(()=>({}));return!l.ok||d.error?bn(t,l.ok?502:l.status,{error:String(d.error||`daemon /task HTTP ${l.status}`)}):bn(t,200,{content:String(d.content??"")})}catch(l){return bn(t,502,{error:`The daemon did not answer: ${l?.message||l}. Is it running? Try: agentx start`})}}function Je(){let e=na();return e&&Ge(e,"dashboard"),e}function DP(e){let t=e.dashboard,a=e.boards,r=t.port,n=t.bind,o=t.token,s=new Map;for(let m of a)try{s.set(m.id,Vk(m,e))}catch(x){console.error(` Board "${m.id}" failed to initialize: ${x.message}`)}let i=e.node?.id||"local",l=e.workflows?.dir?Pt(process.cwd(),e.workflows.dir):void 0,d=new ps(l?{baseDir:l}:void 0),c=new us(l?{baseDir:l,nodeId:i}:{nodeId:i}),p=new fs(l?{baseDir:l}:void 0);Cc(e),Je(),li({business:e.business?.enabled===!0});let u=Dk(async(m,x)=>{try{await Uk(m,x,{boards:a,sources:s,token:o,config:e,workflowStore:d,workflowRuns:c,workflowLayouts:p})}catch(f){E(x,500,{error:f.message||"internal error"})}});h0(e).start(),u.listen(r,n,()=>{console.log(`
|
|
24282
24286
|
Dashboard: http://${n==="0.0.0.0"?"localhost":n}:${r}
|
|
24283
|
-
`),n==="127.0.0.1"&&!o?console.log(" (bound to localhost; no auth token \u2014 safe default)"):n!=="127.0.0.1"&&!o&&console.log(" \u26A0 bound to a non-loopback address without a token \u2014 writes are UNAUTHENTICATED")})}var zk=new Set(["/","/live","/wall","/mesh","/monitor","/activity","/workflows","/workflows/editor","/graph","/setup","/admin","/admin/graph","/approvals","/people","/org","/admin/health","/admin/observability","/admin/ledger","/admin/projects","/admin/wiki"]),Fk={"/boards":"/wall#status=open&view=projects","/glossary":"/wall","/procedures":"/wall#page=agents","/processes":"/wall#status=open&view=jobs","/places":"/wall"};async function Uk(e,t,a){let r=new URL(e.url||"/","http://localhost"),n=r.pathname,o=(e.method||"GET").toUpperCase();if((e.url||"/").split(/[?#]/)[0]!==n){E(t,404,{error:"not found"});return}if(ri(e.headers)==="foreign"&&oi(o)){E(t,403,{error:"Forbidden: request from a page on another origin"});return}if(o==="OPTIONS"){t.writeHead(204),t.end();return}if(ig(o,n)&&!hg(e,a)){E(t,401,{error:"Only the owner writes on the Wall: sign in, or send the dashboard token."});return}if(await vl(e,t,r,o,a.token)||await dd(e,t,n,o,{nodeName:a.config.node?.name,root:process.cwd(),people:()=>yt(a.config.people),members:gg(a.config.members.logRetentionDays),db:()=>Je(),linkFor:(g,y)=>Pl(g,y,{gitlab:a.config.channels.gitlab?.host})})||await qm(e,t,n,o,{node:An(a.config),dashboardToken:a.token,posts:g=>yg(new URLSearchParams({days:String(g)}),a)})||await Gf(e,t,n,o,{nodeName:a.config.node?.name,fleet:So(a.config),desk:p0(a.config),push:_o(a.config),announce:su(a.config),chat:Rg(a.config),voice:b0(a.config),camera:x0(a.config),places:mg(a.config),pins:$i(a.config,process.cwd()),reach:Eg(),assetLinks:()=>zu(a.config)}))return;let s=o==="GET"?Cl(n):null;if(s){t.writeHead(200,{"Content-Type":s.type,"Cache-Control":"public, max-age=86400"}),t.end(s.body);return}if(si(e,t,n,r,process.cwd()))return;if(o==="GET"&&zk.has(n)&&Vi("page",n),o==="GET"&&n==="/"){let g=Ti();if(!g.configExists||g.agentCount===0){t.writeHead(302,{Location:"/setup"}),t.end();return}if(!xe(e,t,a,n))return;t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(Lr(wg(e,a)));return}let i=o==="GET"?Fk[n]:void 0;if(i){t.writeHead(302,{Location:i}),t.end();return}if(o==="GET"&&n==="/wall"){if(!xe(e,t,a,n))return;t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(Lr(wg(e,a)));return}if(o==="GET"&&n==="/live"){t.writeHead(302,{Location:Cp}),t.end();return}if(o==="POST"&&n.match(/^\/webhook\/n8n\/[A-Za-z0-9._:-]{1,64}$/)){try{let[g]=await Ve(a.config);if(!g){E(t,503,{error:"no node available"});return}let y=await new Promise(k=>{let C="";e.on("data",w=>C+=w),e.on("end",()=>k(C)),e.on("error",()=>k(""))}),S=await fetch(g.url+n,{method:"POST",headers:{"Content-Type":"application/json",...g.token?{Authorization:`Bearer ${g.token}`}:{}},body:y||"{}"});t.writeHead(S.status,{"Content-Type":"application/json"}),t.end(await S.text())}catch(g){E(t,502,{error:"could not reach the node",message:String(g?.message||g)})}return}if(n==="/api/assistant"||n.startsWith("/api/assistant/")){try{let g=await Ve(a.config),y=o==="POST"?void 0:r.searchParams.get("node"),S=o==="POST"?await ne(e):void 0,k=S?.node??y,C=k?g.find(D=>D.url===k):g[0];if(!C){E(t,400,{error:"unknown node"});return}let w=r.search?r.search.replace(/([?&])node=[^&]*/,"$1").replace(/[?&]$/,""):"",R=await fetch(C.url+n+w,{method:o,headers:{"Content-Type":"application/json",...C.token?{Authorization:`Bearer ${C.token}`}:{}},...o==="POST"?{body:JSON.stringify({...S,node:void 0})}:{}});E(t,R.status,await R.json().catch(()=>({error:`HTTP ${R.status}`})))}catch(g){E(t,502,{error:"could not reach the node",message:g?.message||String(g)})}return}if(o==="POST"&&n==="/api/workflows/editor/chat"){try{let g=await ne(e),y={"Content-Type":"application/json"};a.config.dashboard.token&&(y.Authorization=`Bearer ${a.config.dashboard.token}`);let S=a.config.dashboard.daemonUrl.replace(/\/+$/,""),k=await fetch(`${S}/api/workflows/editor/chat`,{method:"POST",headers:y,body:JSON.stringify(g??{})}),C=await k.json().catch(()=>({error:`HTTP ${k.status}`}));E(t,k.status,C)}catch(g){E(t,502,{error:"daemon unreachable",message:g.message||String(g)})}return}if(o==="GET"&&n==="/api/n8n/workflows"){try{let[g]=await Ve(a.config);if(!g){E(t,200,{configured:!1,workflows:[]});return}let y=await fetch(g.url+"/api/n8n/workflows",{headers:g.token?{Authorization:`Bearer ${g.token}`}:{}});E(t,y.status,await y.json().catch(()=>({configured:!1,workflows:[]})))}catch{E(t,200,{configured:!1,workflows:[]})}return}if(o==="GET"&&n==="/workflows/editor"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(dl({peers:ae(a.config)}));return}if(o==="GET"&&n==="/activity"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(ll({peers:ae(a.config),view:r.searchParams.get("view"),localToken:fe(e,a.token)}));return}if(o==="GET"&&n==="/monitor"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(rl({peers:ae(a.config)}));return}let d=o==="POST"&&n===u0,c=d?"/api/monitor/register":o==="GET"&&n===f0?"/api/monitor/discover":n;if(c==="/api/monitor"||c.startsWith("/api/monitor/")){if(d&&e.headers["x-requested-with"]!=="agentx-board"){E(t,400,{error:"missing X-Requested-With: agentx-board"});return}let g=new AbortController,y=setTimeout(()=>g.abort(),8e3);try{let S=Rs(await Ve(a.config,g.signal),a.config.mesh.peers);if(o==="GET"&&c==="/api/monitor"){let D=await Promise.all(S.map(async $=>{try{let B=await fetch($.url+"/monitor",{headers:$.token?{Authorization:`Bearer ${$.token}`}:{},signal:g.signal});if(!B.ok)throw new Error(`HTTP ${B.status}`);return{name:$.name,url:$.url,ok:!0,data:await B.json()}}catch(B){return{name:$.name,url:$.url,ok:!1,error:B.message}}}));E(t,200,{nodes:D});return}let k=S.find(D=>D.url===r.searchParams.get("node"));if(!k){E(t,400,{error:"Select a known node"});return}let C=c.slice(13);if(!(o==="GET"&&["discover","actions","activity"].includes(C)||o==="POST"&&["register","ended","action","retry","clear"].includes(C))){E(t,405,{error:"Unknown monitor operation"});return}let w=o==="POST"?JSON.stringify(await Cs(e)):void 0,R=await fetch(k.url+"/monitor/"+C+(C==="actions"?"?offset="+encodeURIComponent(r.searchParams.get("offset")||"0"):C==="activity"?"?hours="+encodeURIComponent(r.searchParams.get("hours")||"24"):""),{method:o,body:w,signal:g.signal,headers:{"Content-Type":"application/json",...k.token?{Authorization:`Bearer ${k.token}`}:{}}});E(t,R.status,await R.json())}catch(S){E(t,502,{error:S.message})}finally{clearTimeout(y)}return}if(o==="GET"&&n==="/mesh"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(zp({peers:ae(a.config)}));return}if(o==="GET"&&n==="/guests"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(Fp({peers:ae(a.config)}));return}if(o==="GET"&&n==="/api/guests"||o==="POST"&&/^\/api\/guests\/[^/]+\/(pause|resume|end|update)$/.test(n)){try{let g={"Content-Type":"application/json"};a.config.dashboard.token&&(g.Authorization=`Bearer ${a.config.dashboard.token}`);let y=a.config.dashboard.daemonUrl.replace(/\/+$/,""),S=o==="POST"?await ne(e).catch(()=>({})):void 0,k=await fetch(`${y}${n.replace(/^\/api\/guests/,"/mesh/guests")}`,{method:o,headers:g,...S!==void 0?{body:JSON.stringify(S??{})}:{}});E(t,k.status,await k.json().catch(()=>({error:`HTTP ${k.status}`})))}catch(g){E(t,502,{error:"daemon unreachable",message:g.message||String(g)})}return}if(o==="GET"&&n==="/workflows"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(Kp({peers:ae(a.config)}));return}if(o==="GET"&&n.match(/^\/tasks\/([^/]+)$/)){let g=Vp(n,r.searchParams,a.config.dashboard.daemonUrl);if(!g){t.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),t.end("<p>Missing <code>?agent=</code>. Open this task from the Wall's Live page.</p>");return}if(!xe(e,t,a,g))return;t.writeHead(302,{Location:g}),t.end();return}let u=o==="GET"&&n.match(/^\/agents\/([^/]+)\/history$/);if(u){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(Jp({agentId:decodeURIComponent(u[1]),agentName:r.searchParams.get("name")||void 0,nodeUrl:r.searchParams.get("node")||a.config.dashboard.daemonUrl,peers:ae(a.config)}));return}if(o==="GET"&&n==="/graph"){t.writeHead(302,{Location:"/admin/graph"}),t.end();return}if(o==="GET"&&n==="/setup"){Ei(e,t);return}if(o==="POST"&&n==="/api/setup"){await Ci(e,t);return}if(o==="POST"&&n==="/api/setup/start-daemon"){await Ri(e,t);return}if(o==="GET"&&n==="/admin"){if(!xe(e,t,a,n))return;Id(e,t,ae(a.config),fe(e,a.token));return}if(o==="GET"&&n==="/approvals"){if(!xe(e,t,a,n))return;Fd(t,ae(a.config),fe(e,a.token));return}if(o==="GET"&&n==="/admin/graph"){if(!xe(e,t,a,n))return;Dd(e,t,ae(a.config),fe(e,a.token));return}if(o==="GET"&&(n==="/admin/health"||n==="/admin/observability")){if(n==="/admin/observability"){t.writeHead(302,{Location:"/admin/health"}),t.end();return}if(!xe(e,t,a,n))return;ec(e,t,ae(a.config),fe(e,a.token));return}if(n.startsWith("/api/admin/")&&n!==bg||n.startsWith("/api/workflows")||n.startsWith("/api/agents")){let g=r.searchParams.get("peer")==="fleet"?"fleet":String(e.headers["x-agentx-peer"]||"").trim()||r.searchParams.get("peer")||"";if(g&&g!=="primary"&&!(o==="GET"&&n==="/api/agents")&&!Lt(e,a)&&!xg(e,a,o,n)){E(t,401,{error:"unauthorized"});return}if(g==="fleet"){if(n==="/api/admin/activity-graph"){await S0(e,t,a);return}if(n===ee&&o==="GET"){E(t,200,await yg(r.searchParams,a));return}if(n===`${ee}/throughput`&&o==="GET"){E(t,200,await N0(a));return}if(n==="/api/admin/activity-graph/stream"){await Ir(e,t,n,k=>Mg(k,a.config));return}let S=n.match(/^\/api\/admin\/activity-graph\/dispatch\/(.+)$/);if(S){let k=decodeURIComponent(S[1]),C=k.indexOf("::");if(C>0){let w=k.slice(0,C),R=k.slice(C+2),D=a.config.node?.id||a.config.node?.name||"local";if(w===D)e.url=`/api/admin/activity-graph/dispatch/${encodeURIComponent(R)}`;else{let $=(a.config.dashboard?.daemons||[]).find(B=>(B.name||B.url)===w);if($){let B=ut($.url.replace(/\/+$/,""),a.config);if(B){await kg(e,t,B,`/api/admin/activity-graph/dispatch/${encodeURIComponent(R)}`);return}}E(t,404,{error:`unknown node "${w}" in fleet dispatch id`});return}}}}else if(g&&g!=="primary"){let S=ut(g,a.config);if(!S){E(t,404,{error:`unknown peer: ${g}`});return}let k=(r.search||"").replace(/[?&]peer=[^&]*/g,w=>w.startsWith("?")?"?":"");await kg(e,t,S,n+(k==="?"?"":k));return}}if(o==="GET"&&n==="/admin/ledger"){if(!xe(e,t,a,n))return;t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(oc({peers:ae(a.config),localToken:fe(e,a.token)}));return}if(o==="GET"&&n==="/admin/cost"){if(!xe(e,t,a,n))return;t.writeHead(302,{Location:Mr}),t.end();return}if(o==="GET"&&n==="/admin/projects"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(sc({peers:ae(a.config)}));return}if(o==="GET"&&(n==="/admin/wiki"||n.startsWith("/admin/wiki/"))){if(n==="/admin/wiki"){t.writeHead(302,{Location:"/admin/wiki/"}),t.end();return}await Qk(a)(e,t);return}if(o==="GET"&&n==="/admin/activity-graph"){t.writeHead(302,{Location:"/activity?view=map"}),t.end();return}let m=o==="GET"&&n.match(/^\/admin\/agents\/([a-z0-9][a-z0-9_-]*)$/);if(m){if(!xe(e,t,a,n))return;Oc(e,t,m[1],ae(a.config),fe(e,a.token));return}if(n.startsWith("/api/admin/")&&!Lt(e,a)&&!xg(e,a,o,n)){E(t,401,{error:"unauthorized"});return}if(o==="POST"&&n===bg){E(t,200,a.token?{ticket:hl(a.token),expiresInS:Vn}:{ticket:""});return}if(o==="GET"&&n==="/api/admin/logs/stream"){await H0(e,t);return}if(o==="GET"&&n==="/api/admin/activity-graph"&&await Rc(e,t,n)||o==="GET"&&n.startsWith("/api/admin/activity-graph/stream")&&await Ir(e,t,n)||o==="GET"&&n.startsWith("/api/admin/activity-graph/dispatch/")&&await Pc(e,t,n)||o==="GET"&&n.startsWith("/api/admin/observability/")&&await tc(e,t,n,a.config))return;if(o==="GET"&&n==="/api/admin/doctor"){try{let{runDoctorChecks:g}=await import("./doctor-DKW3EP3O.js"),S=new URL(e.url||"/","http://_").searchParams.get("running")!=="false",k=await g({running:S});E(t,200,k)}catch(g){E(t,500,{error:g?.message||String(g)})}return}if(o==="GET"&&n.startsWith("/api/admin/ledger/")&&await rc(e,t,n))return;if(o==="POST"&&(n==="/api/admin/budgets"||n===ng)){let g=await ne(e).catch(()=>({})),y=Zp(g);if(y){E(t,400,{error:y});return}let S=await eu(g);if(!S.success){E(t,400,{error:S.error});return}E(t,200,{ok:!0,reloaded:!!S.reloaded});return}if(await cg(e,t,n,{daemonUrl:a.config.dashboard.daemonUrl,token:a.config.dashboard.token,readBody:ne})||(n===mo||n===go)&&await dg(e,t,n,r.searchParams,{dir:process.cwd(),readBody:ne,reloadDaemon:async()=>{let g={};a.config.dashboard.token&&(g.Authorization=`Bearer ${a.config.dashboard.token}`);let y=await fetch(a.config.dashboard.daemonUrl.replace(/\/+$/,"")+"/reload",{method:"POST",headers:g,signal:AbortSignal.timeout(1e4)});if(!y.ok)throw new Error(`HTTP ${y.status}`)}}))return;if(o==="GET"&&n==="/api/admin/config"){await Pd(e,t);return}if(o==="GET"&&n==="/api/admin/voice-health"){E(t,200,ci()??{checkedAt:null,missing:[]});return}if(o==="GET"&&n===Xm){let g=a.config.graph,y=Jm(r.searchParams,{baseDir:g?.baseDir?Pt(process.cwd(),g.baseDir):null,enabled:!!g?.enabled},An(a.config),Date.now());E(t,y.status,y.body);return}let x=o==="POST"&&n.startsWith(`${Sn}/`)?m0.get(n.slice(Sn.length+1)):void 0;if(x){if(e.headers["x-requested-with"]!=="agentx-board"){E(t,400,{error:"missing X-Requested-With: agentx-board"});return}let g=r.searchParams.get("node");if(!g){E(t,400,{error:"node query param required"});return}await Qt(e,t,a,g,x);return}if(uo(n)){let g=o==="POST"?await ne(e):{},y=await lg(o,n,g,{inbox:{root:process.cwd()},daemon:D0(a.config)});E(t,y.status,y.body);return}let f=sg(o,n);if(f){await gr(e,t,f,{owner:vg(e,a)});return}if(o==="GET"&&(n===ee||n.startsWith(`${ee}/`))){let g=await Pg(n,r.searchParams,a);E(t,g.status,g.body);return}let _=og(o,n);if(_?.startsWith("/api/admin/graph/")){await xr(e,t,_);return}if(n.startsWith("/api/admin/approvals")||_){await Ud(e,t,_??n,r,{node:{url:a.config.dashboard.daemonUrl.replace(/\/+$/,""),name:a.config.node?.name||"this computer"},owner:hg(e,a)});return}if(o==="GET"&&n==="/org"){if(!xe(e,t,a,n))return;t.writeHead(200,{"Content-Type":"text/html; charset=utf-8","Cache-Control":"no-store"}),t.end(Lp({peers:ae(a.config),localToken:fe(e,a.token)}));return}if(await ii(e,t,n,{root:process.cwd(),agentIds:()=>Object.keys(E0(a.config)),personIds:()=>[ft,...yt(a.config.people).map(g=>g.id)]})||o==="GET"&&n==="/people"&&!xe(e,t,a,n)||await Gd(e,t,n,{people:()=>yt(a.config.people),members:gg(a.config.members.logRetentionDays),root:process.cwd(),db:()=>Je()}))return;if(n.startsWith("/api/admin/graph/")){await xr(e,t,n);return}if(n.startsWith("/api/admin/agent/")){await $c(e,t,n);return}if(n.startsWith("/api/admin/")){await gr(e,t,n,{owner:vg(e,a)});return}if(o==="GET"&&n==="/sortable.min.js"){t.writeHead(200,{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"public, max-age=86400"}),t.end(cd);return}if(o==="GET"&&n.startsWith("/assets/")){let g=n.slice(8);if(!/^[a-zA-Z0-9._-]+\.(js|map|css)$/.test(g)){E(t,400,{error:"invalid asset name"});return}let y=k0("web/"+g);try{let S=await _0(y),k=g.endsWith(".map")?"application/json; charset=utf-8":g.endsWith(".css")?"text/css; charset=utf-8":"application/javascript; charset=utf-8",C=r.searchParams.has("v");t.writeHead(200,{"Content-Type":k,"Cache-Control":C?"public, max-age=31536000, immutable":"public, max-age=60"}),t.end(S)}catch{E(t,404,{error:"asset not found",hint:"run: npm run build:web"})}return}if(o==="GET"&&n==="/api/live"){try{let g=await Mt(a.config,void 0,r.searchParams.get("quick")==="1");E(t,200,g)}catch(g){E(t,502,{error:g.message})}return}if(o==="GET"&&n==="/api/mesh"){try{let g=r.searchParams.get("date")||new Date().toISOString().slice(0,10),y=r.searchParams.get("timezone")||"UTC",S=await Mt(a.config,{date:g,timezone:y});E(t,200,S)}catch(g){E(t,502,{error:g.message})}return}if(o==="GET"&&n==="/api/mesh/analytics"){let g=(y,S,k,C)=>{let w=parseInt(r.searchParams.get(y)||"",10);return Number.isFinite(w)?Math.max(k,Math.min(C,w)):S};try{let y=await Ve(a.config);E(t,200,await Up(y,{days:g("days",30,0,180),tzOffsetMinutes:g("tzOffset",0,-840,840),limit:g("limit",60,1,200)}))}catch(y){E(t,502,{error:y.message})}return}if(o==="GET"&&n==="/api/mesh/day"){let g=r.searchParams.get("day")||"";if(!/^\d{4}-\d{2}-\d{2}$/.test(g)){E(t,400,{error:"day=YYYY-MM-DD query param required"});return}let y=(S,k,C,w)=>{let R=parseInt(r.searchParams.get(S)||"",10);return Number.isFinite(R)?Math.max(C,Math.min(w,R)):k};try{let S=await Ve(a.config);E(t,200,await Xp(S,{day:g,tzOffsetMinutes:y("tzOffset",0,-840,840),limit:y("limit",40,1,200)}))}catch(S){E(t,502,{error:S.message})}return}if(o==="GET"&&(n==="/api/mesh/thread"||n==="/api/mesh/job"||n==="/api/mesh/run"||n==="/api/mesh/conversation")){let g=r.searchParams.get("node");if(!g){E(t,400,{error:"node query param required"});return}let y=r.searchParams,S;if(n==="/api/mesh/thread"){let[k,C,w]=[y.get("agent"),y.get("channel"),y.get("chat")];if(!k||!C||!w){E(t,400,{error:"agent, channel, chat required"});return}S=`/analytics/thread?agent=${encodeURIComponent(k)}&channel=${encodeURIComponent(C)}&chat=${encodeURIComponent(w)}&limit=${encodeURIComponent(y.get("limit")||"120")}`}else if(n==="/api/mesh/job"){let[k,C]=[y.get("kind"),y.get("key")];if(!k||!C){E(t,400,{error:"kind and key required"});return}S=`/analytics/job?kind=${encodeURIComponent(k)}&key=${encodeURIComponent(C)}&limit=${encodeURIComponent(y.get("limit")||"120")}`}else if(n==="/api/mesh/conversation"){let[k,C,w]=[y.get("agent"),y.get("channel"),y.get("chat")];if(!k||!C||!w){E(t,400,{error:"agent, channel, chat required"});return}S=`/analytics/conversation?agent=${encodeURIComponent(k)}&channel=${encodeURIComponent(C)}&chat=${encodeURIComponent(w)}&tzOffset=${encodeURIComponent(y.get("tzOffset")||"0")}`}else{let k=y.get("task");if(!k){E(t,400,{error:"task required"});return}S=`/analytics/run/${encodeURIComponent(k)}`}try{await Gp(t,await Ve(a.config),g,S)}catch(k){E(t,502,{error:k.message})}return}if(o==="GET"&&n==="/api/live/stream"){o0(e,t,a.config);return}if(o==="GET"&&n==="/api/task/stream"){let g=new URL(e.url||"/","http://localhost"),y=g.searchParams.get("node"),S=g.searchParams.get("agent"),k=g.searchParams.get("task");if(!y||!S||!k){E(t,400,{error:"node, agent, task query params required"});return}await s0(e,t,a,y,S,k);return}if(o==="GET"&&n==="/api/task/history"){let g=new URL(e.url||"/","http://localhost"),y=g.searchParams.get("node"),S=g.searchParams.get("agent"),k=g.searchParams.get("task"),C=g.searchParams.get("limit")||"50";if(!y||!S){E(t,400,{error:"node and agent query params required"});return}await d0(t,a,y,S,k,C);return}if(o==="POST"&&n==="/api/task/action"){let g=new URL(e.url||"/","http://localhost"),y=g.searchParams.get("node"),S=g.searchParams.get("task"),k=g.searchParams.get("kind");if(!y||!S||k!=="cancel"&&k!=="followup"){E(t,400,{error:"node, task, kind=cancel|followup query params required"});return}await c0(e,t,a,y,S,k);return}if(o==="POST"&&n==="/api/voice/stop"){let g=new URL(e.url||"/","http://localhost").searchParams.get("node");if(!g){E(t,400,{error:"node query param required"});return}await Qt(e,t,a,g,"/voice/stop");return}if(o==="GET"&&n==="/api/agents"){try{let g={};a.config.dashboard.token&&(g.Authorization=`Bearer ${a.config.dashboard.token}`);let y=await fetch(a.config.dashboard.daemonUrl.replace(/\/+$/,"")+"/agents",{headers:g});if(!y.ok)throw new Error(`HTTP ${y.status}`);let S=await y.json();E(t,200,S)}catch(g){E(t,502,{error:g.message||"agents fetch failed"})}return}if(o==="GET"&&n==="/api/business/status"){try{let g={};a.config.dashboard.token&&(g.Authorization=`Bearer ${a.config.dashboard.token}`);let y=await fetch(a.config.dashboard.daemonUrl.replace(/\/+$/,"")+"/business/status",{headers:g});if(!y.ok){E(t,y.status,{error:`HTTP ${y.status}`});return}E(t,200,await y.json())}catch(g){E(t,502,{error:g.message||"business status fetch failed"})}return}if(o==="POST"&&n==="/api/draft"){let g=await ne(e);try{let y=await w0(a.config,g);E(t,200,y)}catch(y){E(t,502,{error:y.message||"draft failed"})}return}let b=n.match(/^\/api\/public\/agents\/([^/]+)\/messages$/);if(b&&o==="POST"){let g=b[1];if(!i0(e,t,[`agent:${g}`]))return;await l0(e,t,a.config,g);return}if(o==="GET"&&n==="/api/node/build"){try{let g={};a.config.dashboard.token&&(g.Authorization=`Bearer ${a.config.dashboard.token}`);let y=await fetch(a.config.dashboard.daemonUrl.replace(/\/+$/,"")+"/health",{headers:g,signal:AbortSignal.timeout(3e3)});if(!y.ok)throw new Error(`HTTP ${y.status}`);E(t,200,di(await y.json()))}catch(g){E(t,502,{error:g.message||"daemon not reachable"})}return}if(n.startsWith("/api/")&&a.token){let g=e.headers.authorization||"",y=g.startsWith("Bearer ")?g.slice(7):"";if(!(y===a.token||Kn(e,a.token))){let S=new Q,k=y?S.verify(y):null;if(!k||!Ee(k,"dashboard:write")){E(t,401,{error:"unauthorized"});return}}}if(o==="GET"&&n==="/api/mesh/feed"){await Zk(t,a.config,r.searchParams);return}if((o==="POST"||o==="PATCH"||o==="DELETE"||o==="PUT")&&n.startsWith("/api/")&&e.headers["x-requested-with"]!=="agentx-board"){E(t,400,{error:"missing X-Requested-With: agentx-board"});return}if(n==="/api/wiki/curate"||n==="/api/wiki/curate/restore"){try{let g={"Content-Type":"application/json"};a.config.dashboard.token&&(g.Authorization=`Bearer ${a.config.dashboard.token}`);let y=a.config.dashboard.daemonUrl.replace(/\/+$/,""),S=o==="POST"?JSON.stringify(await ne(e)??{}):void 0,k=await fetch(`${y}${n}${r.search}`,{method:o,headers:g,...S?{body:S}:{}});E(t,k.status,await k.json().catch(()=>({error:`HTTP ${k.status}`})))}catch(g){E(t,502,{error:"daemon unreachable",message:g?.message||String(g)})}return}if(await Bu(e,t,n,o,mg(a.config)))return;if(o==="POST"&&(n==="/api/signals/stop"||n==="/api/signals/resume"||n==="/api/signals/drop")){let g=new URL(e.url||"/","http://localhost").searchParams.get("node");if(!g){E(t,400,{error:"node query param required"});return}await Qt(e,t,a,g,n);return}if(o==="POST"&&(n==="/api/node/restart"||n==="/api/node/restart/cancel")){let g=r.searchParams.get("node");if(!g){E(t,400,{error:"node query param required"});return}await Qt(e,t,a,g,n==="/api/node/restart"?"/daemon/restart":"/daemon/restart/cancel");return}if(o==="GET"&&n==="/events"){let y=new URL(e.url||"/","http://localhost").searchParams.toString();t.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});let S=[{name:a.config.node.name||"local",url:a.config.dashboard.daemonUrl,token:a.config.dashboard.token},...(a.config.dashboard.daemons||[]).map(R=>({name:R.name,url:R.url,token:R.token}))],k={flag:!1},C=[];e.on("close",()=>{k.flag=!0;for(let R of C)try{R.abort()}catch{}});let w=setInterval(()=>{if(!k.flag)try{t.write(`: ping
|
|
24287
|
+
`),n==="127.0.0.1"&&!o?console.log(" (bound to localhost; no auth token \u2014 safe default)"):n!=="127.0.0.1"&&!o&&console.log(" \u26A0 bound to a non-loopback address without a token \u2014 writes are UNAUTHENTICATED")})}var zk=new Set(["/","/live","/wall","/mesh","/monitor","/activity","/workflows","/workflows/editor","/graph","/setup","/admin","/admin/graph","/approvals","/people","/org","/admin/health","/admin/observability","/admin/ledger","/admin/projects","/admin/wiki"]),Fk={"/boards":"/wall#status=open&view=projects","/glossary":"/wall","/procedures":"/wall#page=agents","/processes":"/wall#status=open&view=jobs","/places":"/wall"};async function Uk(e,t,a){let r=new URL(e.url||"/","http://localhost"),n=r.pathname,o=(e.method||"GET").toUpperCase();if((e.url||"/").split(/[?#]/)[0]!==n){E(t,404,{error:"not found"});return}if(ri(e.headers)==="foreign"&&oi(o)){E(t,403,{error:"Forbidden: request from a page on another origin"});return}if(o==="OPTIONS"){t.writeHead(204),t.end();return}if(ig(o,n)&&!hg(e,a)){E(t,401,{error:"Only the owner writes on the Wall: sign in, or send the dashboard token."});return}if(await vl(e,t,r,o,a.token)||await dd(e,t,n,o,{nodeName:a.config.node?.name,root:process.cwd(),people:()=>yt(a.config.people),members:gg(a.config.members.logRetentionDays),db:()=>Je(),linkFor:(g,y)=>Pl(g,y,{gitlab:a.config.channels.gitlab?.host})})||await qm(e,t,n,o,{node:An(a.config),dashboardToken:a.token,posts:g=>yg(new URLSearchParams({days:String(g)}),a)})||await Gf(e,t,n,o,{nodeName:a.config.node?.name,fleet:So(a.config),desk:p0(a.config),push:_o(a.config),announce:su(a.config),chat:Rg(a.config),voice:b0(a.config),camera:x0(a.config),places:mg(a.config),pins:$i(a.config,process.cwd()),reach:Eg(),assetLinks:()=>zu(a.config)}))return;let s=o==="GET"?Cl(n):null;if(s){t.writeHead(200,{"Content-Type":s.type,"Cache-Control":"public, max-age=86400"}),t.end(s.body);return}if(si(e,t,n,r,process.cwd()))return;if(o==="GET"&&zk.has(n)&&Vi("page",n),o==="GET"&&n==="/"){let g=Ti();if(!g.configExists||g.agentCount===0){t.writeHead(302,{Location:"/setup"}),t.end();return}if(!xe(e,t,a,n))return;t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(Lr(wg(e,a)));return}let i=o==="GET"?Fk[n]:void 0;if(i){t.writeHead(302,{Location:i}),t.end();return}if(o==="GET"&&n==="/wall"){if(!xe(e,t,a,n))return;t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(Lr(wg(e,a)));return}if(o==="GET"&&n==="/live"){t.writeHead(302,{Location:Cp}),t.end();return}if(o==="POST"&&n.match(/^\/webhook\/n8n\/[A-Za-z0-9._:-]{1,64}$/)){try{let[g]=await Ve(a.config);if(!g){E(t,503,{error:"no node available"});return}let y=await new Promise(k=>{let C="";e.on("data",w=>C+=w),e.on("end",()=>k(C)),e.on("error",()=>k(""))}),S=await fetch(g.url+n,{method:"POST",headers:{"Content-Type":"application/json",...g.token?{Authorization:`Bearer ${g.token}`}:{}},body:y||"{}"});t.writeHead(S.status,{"Content-Type":"application/json"}),t.end(await S.text())}catch(g){E(t,502,{error:"could not reach the node",message:String(g?.message||g)})}return}if(n==="/api/assistant"||n.startsWith("/api/assistant/")){try{let g=await Ve(a.config),y=o==="POST"?void 0:r.searchParams.get("node"),S=o==="POST"?await ne(e):void 0,k=S?.node??y,C=k?g.find(D=>D.url===k):g[0];if(!C){E(t,400,{error:"unknown node"});return}let w=r.search?r.search.replace(/([?&])node=[^&]*/,"$1").replace(/[?&]$/,""):"",R=await fetch(C.url+n+w,{method:o,headers:{"Content-Type":"application/json",...C.token?{Authorization:`Bearer ${C.token}`}:{}},...o==="POST"?{body:JSON.stringify({...S,node:void 0})}:{}});E(t,R.status,await R.json().catch(()=>({error:`HTTP ${R.status}`})))}catch(g){E(t,502,{error:"could not reach the node",message:g?.message||String(g)})}return}if(o==="POST"&&n==="/api/workflows/editor/chat"){try{let g=await ne(e),y={"Content-Type":"application/json"};a.config.dashboard.token&&(y.Authorization=`Bearer ${a.config.dashboard.token}`);let S=a.config.dashboard.daemonUrl.replace(/\/+$/,""),k=await fetch(`${S}/api/workflows/editor/chat`,{method:"POST",headers:y,body:JSON.stringify(g??{})}),C=await k.json().catch(()=>({error:`HTTP ${k.status}`}));E(t,k.status,C)}catch(g){E(t,502,{error:"daemon unreachable",message:g.message||String(g)})}return}if(o==="GET"&&n==="/api/n8n/workflows"){try{let[g]=await Ve(a.config);if(!g){E(t,200,{configured:!1,workflows:[]});return}let y=await fetch(g.url+"/api/n8n/workflows",{headers:g.token?{Authorization:`Bearer ${g.token}`}:{}});E(t,y.status,await y.json().catch(()=>({configured:!1,workflows:[]})))}catch{E(t,200,{configured:!1,workflows:[]})}return}if(o==="GET"&&n==="/workflows/editor"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(dl({peers:ae(a.config)}));return}if(o==="GET"&&n==="/activity"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(ll({peers:ae(a.config),view:r.searchParams.get("view"),localToken:fe(e,a.token)}));return}if(o==="GET"&&n==="/monitor"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(rl({peers:ae(a.config)}));return}let d=o==="POST"&&n===u0,c=d?"/api/monitor/register":o==="GET"&&n===f0?"/api/monitor/discover":n;if(c==="/api/monitor"||c.startsWith("/api/monitor/")){if(d&&e.headers["x-requested-with"]!=="agentx-board"){E(t,400,{error:"missing X-Requested-With: agentx-board"});return}let g=new AbortController,y=setTimeout(()=>g.abort(),8e3);try{let S=Rs(await Ve(a.config,g.signal),a.config.mesh.peers);if(o==="GET"&&c==="/api/monitor"){let D=await Promise.all(S.map(async $=>{try{let B=await fetch($.url+"/monitor",{headers:$.token?{Authorization:`Bearer ${$.token}`}:{},signal:g.signal});if(!B.ok)throw new Error(`HTTP ${B.status}`);return{name:$.name,url:$.url,ok:!0,data:await B.json()}}catch(B){return{name:$.name,url:$.url,ok:!1,error:B.message}}}));E(t,200,{nodes:D});return}let k=S.find(D=>D.url===r.searchParams.get("node"));if(!k){E(t,400,{error:"Select a known node"});return}let C=c.slice(13);if(!(o==="GET"&&["discover","actions","activity"].includes(C)||o==="POST"&&["register","ended","action","retry","clear"].includes(C))){E(t,405,{error:"Unknown monitor operation"});return}let w=o==="POST"?JSON.stringify(await Cs(e)):void 0,R=await fetch(k.url+"/monitor/"+C+(C==="actions"?"?offset="+encodeURIComponent(r.searchParams.get("offset")||"0"):C==="activity"?"?hours="+encodeURIComponent(r.searchParams.get("hours")||"24"):""),{method:o,body:w,signal:g.signal,headers:{"Content-Type":"application/json",...k.token?{Authorization:`Bearer ${k.token}`}:{}}});E(t,R.status,await R.json())}catch(S){E(t,502,{error:S.message})}finally{clearTimeout(y)}return}if(o==="GET"&&n==="/mesh"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(zp({peers:ae(a.config)}));return}if(o==="GET"&&n==="/guests"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(Fp({peers:ae(a.config)}));return}if(o==="GET"&&n==="/api/guests"||o==="POST"&&/^\/api\/guests\/[^/]+\/(pause|resume|end|update)$/.test(n)){try{let g={"Content-Type":"application/json"};a.config.dashboard.token&&(g.Authorization=`Bearer ${a.config.dashboard.token}`);let y=a.config.dashboard.daemonUrl.replace(/\/+$/,""),S=o==="POST"?await ne(e).catch(()=>({})):void 0,k=await fetch(`${y}${n.replace(/^\/api\/guests/,"/mesh/guests")}`,{method:o,headers:g,...S!==void 0?{body:JSON.stringify(S??{})}:{}});E(t,k.status,await k.json().catch(()=>({error:`HTTP ${k.status}`})))}catch(g){E(t,502,{error:"daemon unreachable",message:g.message||String(g)})}return}if(o==="GET"&&n==="/workflows"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(Kp({peers:ae(a.config)}));return}if(o==="GET"&&n.match(/^\/tasks\/([^/]+)$/)){let g=Vp(n,r.searchParams,a.config.dashboard.daemonUrl);if(!g){t.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),t.end("<p>Missing <code>?agent=</code>. Open this task from the Wall's Live page.</p>");return}if(!xe(e,t,a,g))return;t.writeHead(302,{Location:g}),t.end();return}let u=o==="GET"&&n.match(/^\/agents\/([^/]+)\/history$/);if(u){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(Jp({agentId:decodeURIComponent(u[1]),agentName:r.searchParams.get("name")||void 0,nodeUrl:r.searchParams.get("node")||a.config.dashboard.daemonUrl,peers:ae(a.config)}));return}if(o==="GET"&&n==="/graph"){t.writeHead(302,{Location:"/admin/graph"}),t.end();return}if(o==="GET"&&n==="/setup"){Ei(e,t);return}if(o==="POST"&&n==="/api/setup"){await Ci(e,t);return}if(o==="POST"&&n==="/api/setup/start-daemon"){await Ri(e,t);return}if(o==="GET"&&n==="/admin"){if(!xe(e,t,a,n))return;Id(e,t,ae(a.config),fe(e,a.token));return}if(o==="GET"&&n==="/approvals"){if(!xe(e,t,a,n))return;Fd(t,ae(a.config),fe(e,a.token));return}if(o==="GET"&&n==="/admin/graph"){if(!xe(e,t,a,n))return;Dd(e,t,ae(a.config),fe(e,a.token));return}if(o==="GET"&&(n==="/admin/health"||n==="/admin/observability")){if(n==="/admin/observability"){t.writeHead(302,{Location:"/admin/health"}),t.end();return}if(!xe(e,t,a,n))return;ec(e,t,ae(a.config),fe(e,a.token));return}if(n.startsWith("/api/admin/")&&n!==bg||n.startsWith("/api/workflows")||n.startsWith("/api/agents")){let g=r.searchParams.get("peer")==="fleet"?"fleet":String(e.headers["x-agentx-peer"]||"").trim()||r.searchParams.get("peer")||"";if(g&&g!=="primary"&&!(o==="GET"&&n==="/api/agents")&&!Lt(e,a)&&!xg(e,a,o,n)){E(t,401,{error:"unauthorized"});return}if(g==="fleet"){if(n==="/api/admin/activity-graph"){await S0(e,t,a);return}if(n===ee&&o==="GET"){E(t,200,await yg(r.searchParams,a));return}if(n===`${ee}/throughput`&&o==="GET"){E(t,200,await N0(a));return}if(n==="/api/admin/activity-graph/stream"){await Ir(e,t,n,k=>Mg(k,a.config));return}let S=n.match(/^\/api\/admin\/activity-graph\/dispatch\/(.+)$/);if(S){let k=decodeURIComponent(S[1]),C=k.indexOf("::");if(C>0){let w=k.slice(0,C),R=k.slice(C+2),D=a.config.node?.id||a.config.node?.name||"local";if(w===D)e.url=`/api/admin/activity-graph/dispatch/${encodeURIComponent(R)}`;else{let $=(a.config.dashboard?.daemons||[]).find(B=>(B.name||B.url)===w);if($){let B=ut($.url.replace(/\/+$/,""),a.config);if(B){await kg(e,t,B,`/api/admin/activity-graph/dispatch/${encodeURIComponent(R)}`);return}}E(t,404,{error:`unknown node "${w}" in fleet dispatch id`});return}}}}else if(g&&g!=="primary"){let S=ut(g,a.config);if(!S){E(t,404,{error:`unknown peer: ${g}`});return}let k=(r.search||"").replace(/[?&]peer=[^&]*/g,w=>w.startsWith("?")?"?":"");await kg(e,t,S,n+(k==="?"?"":k));return}}if(o==="GET"&&n==="/admin/ledger"){if(!xe(e,t,a,n))return;t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(oc({peers:ae(a.config),localToken:fe(e,a.token)}));return}if(o==="GET"&&n==="/admin/cost"){if(!xe(e,t,a,n))return;t.writeHead(302,{Location:Mr}),t.end();return}if(o==="GET"&&n==="/admin/projects"){t.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),t.end(sc({peers:ae(a.config)}));return}if(o==="GET"&&(n==="/admin/wiki"||n.startsWith("/admin/wiki/"))){if(n==="/admin/wiki"){t.writeHead(302,{Location:"/admin/wiki/"}),t.end();return}await Qk(a)(e,t);return}if(o==="GET"&&n==="/admin/activity-graph"){t.writeHead(302,{Location:"/activity?view=map"}),t.end();return}let m=o==="GET"&&n.match(/^\/admin\/agents\/([a-z0-9][a-z0-9_-]*)$/);if(m){if(!xe(e,t,a,n))return;Oc(e,t,m[1],ae(a.config),fe(e,a.token));return}if(n.startsWith("/api/admin/")&&!Lt(e,a)&&!xg(e,a,o,n)){E(t,401,{error:"unauthorized"});return}if(o==="POST"&&n===bg){E(t,200,a.token?{ticket:hl(a.token),expiresInS:Vn}:{ticket:""});return}if(o==="GET"&&n==="/api/admin/logs/stream"){await H0(e,t);return}if(o==="GET"&&n==="/api/admin/activity-graph"&&await Rc(e,t,n)||o==="GET"&&n.startsWith("/api/admin/activity-graph/stream")&&await Ir(e,t,n)||o==="GET"&&n.startsWith("/api/admin/activity-graph/dispatch/")&&await Pc(e,t,n)||o==="GET"&&n.startsWith("/api/admin/observability/")&&await tc(e,t,n,a.config))return;if(o==="GET"&&n==="/api/admin/doctor"){try{let{runDoctorChecks:g}=await import("./doctor-NPHNPYHR.js"),S=new URL(e.url||"/","http://_").searchParams.get("running")!=="false",k=await g({running:S});E(t,200,k)}catch(g){E(t,500,{error:g?.message||String(g)})}return}if(o==="GET"&&n.startsWith("/api/admin/ledger/")&&await rc(e,t,n))return;if(o==="POST"&&(n==="/api/admin/budgets"||n===ng)){let g=await ne(e).catch(()=>({})),y=Zp(g);if(y){E(t,400,{error:y});return}let S=await eu(g);if(!S.success){E(t,400,{error:S.error});return}E(t,200,{ok:!0,reloaded:!!S.reloaded});return}if(await cg(e,t,n,{daemonUrl:a.config.dashboard.daemonUrl,token:a.config.dashboard.token,readBody:ne})||(n===mo||n===go)&&await dg(e,t,n,r.searchParams,{dir:process.cwd(),readBody:ne,reloadDaemon:async()=>{let g={};a.config.dashboard.token&&(g.Authorization=`Bearer ${a.config.dashboard.token}`);let y=await fetch(a.config.dashboard.daemonUrl.replace(/\/+$/,"")+"/reload",{method:"POST",headers:g,signal:AbortSignal.timeout(1e4)});if(!y.ok)throw new Error(`HTTP ${y.status}`)}}))return;if(o==="GET"&&n==="/api/admin/config"){await Pd(e,t);return}if(o==="GET"&&n==="/api/admin/voice-health"){E(t,200,ci()??{checkedAt:null,missing:[]});return}if(o==="GET"&&n===Xm){let g=a.config.graph,y=Jm(r.searchParams,{baseDir:g?.baseDir?Pt(process.cwd(),g.baseDir):null,enabled:!!g?.enabled},An(a.config),Date.now());E(t,y.status,y.body);return}let x=o==="POST"&&n.startsWith(`${Sn}/`)?m0.get(n.slice(Sn.length+1)):void 0;if(x){if(e.headers["x-requested-with"]!=="agentx-board"){E(t,400,{error:"missing X-Requested-With: agentx-board"});return}let g=r.searchParams.get("node");if(!g){E(t,400,{error:"node query param required"});return}await Qt(e,t,a,g,x);return}if(uo(n)){let g=o==="POST"?await ne(e):{},y=await lg(o,n,g,{inbox:{root:process.cwd()},daemon:D0(a.config)});E(t,y.status,y.body);return}let f=sg(o,n);if(f){await gr(e,t,f,{owner:vg(e,a)});return}if(o==="GET"&&(n===ee||n.startsWith(`${ee}/`))){let g=await Pg(n,r.searchParams,a);E(t,g.status,g.body);return}let _=og(o,n);if(_?.startsWith("/api/admin/graph/")){await xr(e,t,_);return}if(n.startsWith("/api/admin/approvals")||_){await Ud(e,t,_??n,r,{node:{url:a.config.dashboard.daemonUrl.replace(/\/+$/,""),name:a.config.node?.name||"this computer"},owner:hg(e,a)});return}if(o==="GET"&&n==="/org"){if(!xe(e,t,a,n))return;t.writeHead(200,{"Content-Type":"text/html; charset=utf-8","Cache-Control":"no-store"}),t.end(Lp({peers:ae(a.config),localToken:fe(e,a.token)}));return}if(await ii(e,t,n,{root:process.cwd(),agentIds:()=>Object.keys(E0(a.config)),personIds:()=>[ft,...yt(a.config.people).map(g=>g.id)]})||o==="GET"&&n==="/people"&&!xe(e,t,a,n)||await Gd(e,t,n,{people:()=>yt(a.config.people),members:gg(a.config.members.logRetentionDays),root:process.cwd(),db:()=>Je()}))return;if(n.startsWith("/api/admin/graph/")){await xr(e,t,n);return}if(n.startsWith("/api/admin/agent/")){await $c(e,t,n);return}if(n.startsWith("/api/admin/")){await gr(e,t,n,{owner:vg(e,a)});return}if(o==="GET"&&n==="/sortable.min.js"){t.writeHead(200,{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"public, max-age=86400"}),t.end(cd);return}if(o==="GET"&&n.startsWith("/assets/")){let g=n.slice(8);if(!/^[a-zA-Z0-9._-]+\.(js|map|css)$/.test(g)){E(t,400,{error:"invalid asset name"});return}let y=k0("web/"+g);try{let S=await _0(y),k=g.endsWith(".map")?"application/json; charset=utf-8":g.endsWith(".css")?"text/css; charset=utf-8":"application/javascript; charset=utf-8",C=r.searchParams.has("v");t.writeHead(200,{"Content-Type":k,"Cache-Control":C?"public, max-age=31536000, immutable":"public, max-age=60"}),t.end(S)}catch{E(t,404,{error:"asset not found",hint:"run: npm run build:web"})}return}if(o==="GET"&&n==="/api/live"){try{let g=await Mt(a.config,void 0,r.searchParams.get("quick")==="1");E(t,200,g)}catch(g){E(t,502,{error:g.message})}return}if(o==="GET"&&n==="/api/mesh"){try{let g=r.searchParams.get("date")||new Date().toISOString().slice(0,10),y=r.searchParams.get("timezone")||"UTC",S=await Mt(a.config,{date:g,timezone:y});E(t,200,S)}catch(g){E(t,502,{error:g.message})}return}if(o==="GET"&&n==="/api/mesh/analytics"){let g=(y,S,k,C)=>{let w=parseInt(r.searchParams.get(y)||"",10);return Number.isFinite(w)?Math.max(k,Math.min(C,w)):S};try{let y=await Ve(a.config);E(t,200,await Up(y,{days:g("days",30,0,180),tzOffsetMinutes:g("tzOffset",0,-840,840),limit:g("limit",60,1,200)}))}catch(y){E(t,502,{error:y.message})}return}if(o==="GET"&&n==="/api/mesh/day"){let g=r.searchParams.get("day")||"";if(!/^\d{4}-\d{2}-\d{2}$/.test(g)){E(t,400,{error:"day=YYYY-MM-DD query param required"});return}let y=(S,k,C,w)=>{let R=parseInt(r.searchParams.get(S)||"",10);return Number.isFinite(R)?Math.max(C,Math.min(w,R)):k};try{let S=await Ve(a.config);E(t,200,await Xp(S,{day:g,tzOffsetMinutes:y("tzOffset",0,-840,840),limit:y("limit",40,1,200)}))}catch(S){E(t,502,{error:S.message})}return}if(o==="GET"&&(n==="/api/mesh/thread"||n==="/api/mesh/job"||n==="/api/mesh/run"||n==="/api/mesh/conversation")){let g=r.searchParams.get("node");if(!g){E(t,400,{error:"node query param required"});return}let y=r.searchParams,S;if(n==="/api/mesh/thread"){let[k,C,w]=[y.get("agent"),y.get("channel"),y.get("chat")];if(!k||!C||!w){E(t,400,{error:"agent, channel, chat required"});return}S=`/analytics/thread?agent=${encodeURIComponent(k)}&channel=${encodeURIComponent(C)}&chat=${encodeURIComponent(w)}&limit=${encodeURIComponent(y.get("limit")||"120")}`}else if(n==="/api/mesh/job"){let[k,C]=[y.get("kind"),y.get("key")];if(!k||!C){E(t,400,{error:"kind and key required"});return}S=`/analytics/job?kind=${encodeURIComponent(k)}&key=${encodeURIComponent(C)}&limit=${encodeURIComponent(y.get("limit")||"120")}`}else if(n==="/api/mesh/conversation"){let[k,C,w]=[y.get("agent"),y.get("channel"),y.get("chat")];if(!k||!C||!w){E(t,400,{error:"agent, channel, chat required"});return}S=`/analytics/conversation?agent=${encodeURIComponent(k)}&channel=${encodeURIComponent(C)}&chat=${encodeURIComponent(w)}&tzOffset=${encodeURIComponent(y.get("tzOffset")||"0")}`}else{let k=y.get("task");if(!k){E(t,400,{error:"task required"});return}S=`/analytics/run/${encodeURIComponent(k)}`}try{await Gp(t,await Ve(a.config),g,S)}catch(k){E(t,502,{error:k.message})}return}if(o==="GET"&&n==="/api/live/stream"){o0(e,t,a.config);return}if(o==="GET"&&n==="/api/task/stream"){let g=new URL(e.url||"/","http://localhost"),y=g.searchParams.get("node"),S=g.searchParams.get("agent"),k=g.searchParams.get("task");if(!y||!S||!k){E(t,400,{error:"node, agent, task query params required"});return}await s0(e,t,a,y,S,k);return}if(o==="GET"&&n==="/api/task/history"){let g=new URL(e.url||"/","http://localhost"),y=g.searchParams.get("node"),S=g.searchParams.get("agent"),k=g.searchParams.get("task"),C=g.searchParams.get("limit")||"50";if(!y||!S){E(t,400,{error:"node and agent query params required"});return}await d0(t,a,y,S,k,C);return}if(o==="POST"&&n==="/api/task/action"){let g=new URL(e.url||"/","http://localhost"),y=g.searchParams.get("node"),S=g.searchParams.get("task"),k=g.searchParams.get("kind");if(!y||!S||k!=="cancel"&&k!=="followup"){E(t,400,{error:"node, task, kind=cancel|followup query params required"});return}await c0(e,t,a,y,S,k);return}if(o==="POST"&&n==="/api/voice/stop"){let g=new URL(e.url||"/","http://localhost").searchParams.get("node");if(!g){E(t,400,{error:"node query param required"});return}await Qt(e,t,a,g,"/voice/stop");return}if(o==="GET"&&n==="/api/agents"){try{let g={};a.config.dashboard.token&&(g.Authorization=`Bearer ${a.config.dashboard.token}`);let y=await fetch(a.config.dashboard.daemonUrl.replace(/\/+$/,"")+"/agents",{headers:g});if(!y.ok)throw new Error(`HTTP ${y.status}`);let S=await y.json();E(t,200,S)}catch(g){E(t,502,{error:g.message||"agents fetch failed"})}return}if(o==="GET"&&n==="/api/business/status"){try{let g={};a.config.dashboard.token&&(g.Authorization=`Bearer ${a.config.dashboard.token}`);let y=await fetch(a.config.dashboard.daemonUrl.replace(/\/+$/,"")+"/business/status",{headers:g});if(!y.ok){E(t,y.status,{error:`HTTP ${y.status}`});return}E(t,200,await y.json())}catch(g){E(t,502,{error:g.message||"business status fetch failed"})}return}if(o==="POST"&&n==="/api/draft"){let g=await ne(e);try{let y=await w0(a.config,g);E(t,200,y)}catch(y){E(t,502,{error:y.message||"draft failed"})}return}let b=n.match(/^\/api\/public\/agents\/([^/]+)\/messages$/);if(b&&o==="POST"){let g=b[1];if(!i0(e,t,[`agent:${g}`]))return;await l0(e,t,a.config,g);return}if(o==="GET"&&n==="/api/node/build"){try{let g={};a.config.dashboard.token&&(g.Authorization=`Bearer ${a.config.dashboard.token}`);let y=await fetch(a.config.dashboard.daemonUrl.replace(/\/+$/,"")+"/health",{headers:g,signal:AbortSignal.timeout(3e3)});if(!y.ok)throw new Error(`HTTP ${y.status}`);E(t,200,di(await y.json()))}catch(g){E(t,502,{error:g.message||"daemon not reachable"})}return}if(n.startsWith("/api/")&&a.token){let g=e.headers.authorization||"",y=g.startsWith("Bearer ")?g.slice(7):"";if(!(y===a.token||Kn(e,a.token))){let S=new Q,k=y?S.verify(y):null;if(!k||!Ee(k,"dashboard:write")){E(t,401,{error:"unauthorized"});return}}}if(o==="GET"&&n==="/api/mesh/feed"){await Zk(t,a.config,r.searchParams);return}if((o==="POST"||o==="PATCH"||o==="DELETE"||o==="PUT")&&n.startsWith("/api/")&&e.headers["x-requested-with"]!=="agentx-board"){E(t,400,{error:"missing X-Requested-With: agentx-board"});return}if(n==="/api/wiki/curate"||n==="/api/wiki/curate/restore"){try{let g={"Content-Type":"application/json"};a.config.dashboard.token&&(g.Authorization=`Bearer ${a.config.dashboard.token}`);let y=a.config.dashboard.daemonUrl.replace(/\/+$/,""),S=o==="POST"?JSON.stringify(await ne(e)??{}):void 0,k=await fetch(`${y}${n}${r.search}`,{method:o,headers:g,...S?{body:S}:{}});E(t,k.status,await k.json().catch(()=>({error:`HTTP ${k.status}`})))}catch(g){E(t,502,{error:"daemon unreachable",message:g?.message||String(g)})}return}if(await Bu(e,t,n,o,mg(a.config)))return;if(o==="POST"&&(n==="/api/signals/stop"||n==="/api/signals/resume"||n==="/api/signals/drop")){let g=new URL(e.url||"/","http://localhost").searchParams.get("node");if(!g){E(t,400,{error:"node query param required"});return}await Qt(e,t,a,g,n);return}if(o==="POST"&&(n==="/api/node/restart"||n==="/api/node/restart/cancel")){let g=r.searchParams.get("node");if(!g){E(t,400,{error:"node query param required"});return}await Qt(e,t,a,g,n==="/api/node/restart"?"/daemon/restart":"/daemon/restart/cancel");return}if(o==="GET"&&n==="/events"){let y=new URL(e.url||"/","http://localhost").searchParams.toString();t.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});let S=[{name:a.config.node.name||"local",url:a.config.dashboard.daemonUrl,token:a.config.dashboard.token},...(a.config.dashboard.daemons||[]).map(R=>({name:R.name,url:R.url,token:R.token}))],k={flag:!1},C=[];e.on("close",()=>{k.flag=!0;for(let R of C)try{R.abort()}catch{}});let w=setInterval(()=>{if(!k.flag)try{t.write(`: ping
|
|
24284
24288
|
|
|
24285
24289
|
`)}catch{}},15e3);e.on("close",()=>clearInterval(w));for(let R of S)(async()=>{let D={Accept:"text/event-stream"};R.token&&(D.Authorization=`Bearer ${R.token}`);let $=new AbortController;C.push($);try{let B=await fetch(`${R.url.replace(/\/+$/,"")}/events${y?`?${y}`:""}`,{headers:D,signal:$.signal});if(!B.ok||!B.body)return;let G=B.body.getReader(),F=new TextDecoder,T="";for(;!k.flag;){let{done:L,value:N}=await G.read();if(L)break;T+=F.decode(N,{stream:!0});let W;for(;(W=T.indexOf(`
|
|
24286
24290
|
|
|
@@ -24336,4 +24340,4 @@ data: ${m.replace(/\n/g," ")}
|
|
|
24336
24340
|
`)}catch{}}};s.stdout?.on("data",l),s.stderr?.on("data",l);let d=setInterval(()=>{try{t.write(`: hb
|
|
24337
24341
|
|
|
24338
24342
|
`)}catch{}},15e3),c=()=>{clearInterval(d);try{s.kill()}catch{}try{t.end()}catch{}};e.on("close",c),s.on("exit",c),s.on("error",c)}async function kg(e,t,a,r){let n=a.url+r,o=(e.method||"GET").toUpperCase(),i=o!=="GET"&&o!=="HEAD"?await new Promise((p,u)=>{let m=[];e.on("data",x=>m.push(x)),e.on("end",()=>p(Buffer.concat(m))),e.on("error",u)}):void 0,l={},d=e.headers["content-type"];d&&(l["Content-Type"]=Array.isArray(d)?d[0]:d);let c=e.headers["x-requested-with"];c&&(l["X-Requested-With"]=Array.isArray(c)?c[0]:c),a.token&&(l.Authorization=`Bearer ${a.token}`),l["X-Agentx-Peer"]="primary";try{let p=await fetch(n,{method:o,headers:l,body:i&&i.length>0?i:void 0}),u=Buffer.from(await p.arrayBuffer());t.writeHead(p.status,{"Content-Type":p.headers.get("content-type")||"application/json","Cache-Control":"no-store"}),t.end(u)}catch(p){E(t,502,{error:`proxy to peer failed: ${p?.message||p}`,target:n})}}function ut(e,t){let a=e.replace(/\/+$/,""),r=(t.dashboard?.daemons||[]).find(n=>n.url.replace(/\/+$/,"")===a);return r?{url:Ig(r),token:r.dashboardToken||r.token}:null}export{Fk as RETIRED_PAGES,r0 as applyAttachSessions,pg as fetchDaemonAgents,Uk as handleBoardRequest,Jk as liveOverlaps,NP as resetLiveCaches,HP as resetWallFleetCaches,Ve as resolveNodeTargets,DP as startBoardDashboard,n0 as withLastGood};
|
|
24339
|
-
//# sourceMappingURL=board-dashboard-
|
|
24343
|
+
//# sourceMappingURL=board-dashboard-BIERRXDD.js.map
|