tide-commander 1.136.2 → 1.137.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{BossLogsModal-B4p16n9B.js → BossLogsModal-CpuefTyK.js} +1 -1
- package/dist/assets/{BossSpawnModal-BHQ7sxeu.js → BossSpawnModal-DBYWz7ah.js} +1 -1
- package/dist/assets/{ControlsModal-BcP5-m0h.js → ControlsModal-C3GRWgGe.js} +1 -1
- package/dist/assets/{DockerLogsModal-C_Gd6YLn.js → DockerLogsModal-DaRM5UiK.js} +1 -1
- package/dist/assets/{EmbeddedEditor-GHVeXIn5.js → EmbeddedEditor-CX-nzneN.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-VjAKcJf9.js → GmailOAuthSetup-CR7okjRo.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-DFbaN0Ry.js → GoogleOAuthSetup-SwPiACBu.js} +1 -1
- package/dist/assets/{IframeModal-BaoVOZTf.js → IframeModal-Cxtp-ueE.js} +1 -1
- package/dist/assets/{IntegrationsPanel-Cg4TxOfh.js → IntegrationsPanel-CxQNBUbz.js} +2 -2
- package/dist/assets/{LogViewerModal-CN2GYpgr.js → LogViewerModal-C-v5KNZB.js} +1 -1
- package/dist/assets/{MonitoringModal-oN_JjoC2.js → MonitoringModal-D4lsbxyv.js} +1 -1
- package/dist/assets/{PM2LogsModal-BOQ1Im-i.js → PM2LogsModal-D2aMvfE8.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-DYcjqjbA.js → RestoreArchivedAreaModal-DN1dfoEV.js} +1 -1
- package/dist/assets/{Scene2DCanvas-CsBA5ERQ.js → Scene2DCanvas-Vh46WP-a.js} +1 -1
- package/dist/assets/{SceneManager-BqVfBAQc.js → SceneManager-xCUdKUef.js} +1 -1
- package/dist/assets/{SkillsPanel-CtfixcgQ.js → SkillsPanel-UKPyruKQ.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-3nGO_xs6.js → SlackMultiInstanceSetup-CYP8zyzf.js} +1 -1
- package/dist/assets/{SpawnModal-BvUHN-Q1.js → SpawnModal-D-zYj2M1.js} +1 -1
- package/dist/assets/{StatisticsModal-DIx8l3F0.js → StatisticsModal-Bi8uR8cs.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-Bw-V4i4-.js → SubordinateAssignmentModal-LM86Vilv.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-C2Mz8wVK.js → TriggerManagerPanel-D_LhL4en.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-C2RHV8Dx.js → WorkflowEditorPanel-DltPT1Ro.js} +1 -1
- package/dist/assets/{area-logos-aaW_jqzI.js → area-logos-D-61IPfo.js} +1 -1
- package/dist/assets/{index-BGz62M0g.js → index-3OpJhUCJ.js} +1 -1
- package/dist/assets/{index-BvR0it5l.js → index-B6YEcn8f.js} +3 -3
- package/dist/assets/{index-D6r1xAEg.js → index-BTEbN23z.js} +1 -1
- package/dist/assets/{index-BIUEhCXu.js → index-Bff5Z_AU.js} +1 -1
- package/dist/assets/{index-BzCUPOjQ.js → index-BimTXVqB.js} +1 -1
- package/dist/assets/{index-B4JG--zt.js → index-C9cjD5mx.js} +2 -2
- package/dist/assets/{index-DidVGiaJ.js → index-CibDE82j.js} +1 -1
- package/dist/assets/index-DTWKufiJ.js +11 -0
- package/dist/assets/{index-CmGwjdPh.js → index-NiaRnbPo.js} +1 -1
- package/dist/assets/{main-rDQDtv_U.js → main-BVsJe5cx.js} +5 -5
- package/dist/assets/{web-Dy1328BB.js → web-CVeNIuF9.js} +1 -1
- package/dist/assets/{web-DojkIxYY.js → web-D70qwA27.js} +1 -1
- package/dist/assets/{web-B5Ma_-eu.js → web-DcEvjmf6.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/locales/en/config.json +2 -1
- package/dist/src/packages/server/cli.js +8 -1
- package/dist/src/packages/server/routes/system.js +28 -11
- package/dist/src/packages/server/services/self-update-service.js +52 -0
- package/package.json +1 -1
- package/dist/assets/index-BT7u2ftY.js +0 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h as At,i as yt,aw as Et,a1 as xt,a2 as Ct,c9 as Mt,ca as Ft,aF as wt,r as d,X as St,S as me,cb as vt,cc as fe,s as J,cd as Bt,j as f,I as ne,ce as Ve,cf as It,a6 as _t,cg as Dt,ch as kt,ci as Ee,al as Be,W as Rt,p as nt,u as Fe,cj as Je}from"./main-rDQDtv_U.js";import{ck as Ls,cl as $s,cm as js,cn as Ns,co as Ps}from"./main-rDQDtv_U.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function re(t){return Array.isArray?Array.isArray(t):it(t)==="[object Array]"}function bt(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Tt(t){return t==null?"":bt(t)}function q(t){return typeof t=="string"}function rt(t){return typeof t=="number"}function Lt(t){return t===!0||t===!1||$t(t)&&it(t)=="[object Boolean]"}function ct(t){return typeof t=="object"}function $t(t){return ct(t)&&t!==null}function G(t){return t!=null}function Ie(t){return!t.trim().length}function it(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const jt="Incorrect 'index' type",Nt=t=>`Invalid value for key ${t}`,Pt=t=>`Pattern length exceeds max of ${t}.`,Kt=t=>`Missing ${t} property in key`,Ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Xe=Object.prototype.hasOwnProperty;class zt{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let c=ot(r);this._keys.push(c),this._keyMap[c.id]=c,n+=c.weight}),this._keys.forEach(r=>{r.weight/=n})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ot(t){let e=null,n=null,r=null,c=1,i=null;if(q(t)||re(t))r=t,e=Ze(t),n=_e(t);else{if(!Xe.call(t,"name"))throw new Error(Kt("name"));const o=t.name;if(r=o,Xe.call(t,"weight")&&(c=t.weight,c<=0))throw new Error(Ot(o));e=Ze(o),n=_e(o),i=t.getFn}return{path:e,id:n,weight:c,src:r,getFn:i}}function Ze(t){return re(t)?t:t.split(".")}function _e(t){return re(t)?t.join("."):t}function Gt(t,e){let n=[],r=!1;const c=(i,o,a)=>{if(G(i))if(!o[a])n.push(i);else{let u=o[a];const l=i[u];if(!G(l))return;if(a===o.length-1&&(q(l)||rt(l)||Lt(l)))n.push(Tt(l));else if(re(l)){r=!0;for(let h=0,E=l.length;h<E;h+=1)c(l[h],o,a+1)}else o.length&&c(l,o,a+1)}};return c(t,q(e)?e.split("."):e,0),r?n:n[0]}const Qt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Wt={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},Ht={location:0,threshold:.6,distance:100},Ut={useExtendedSearch:!1,getFn:Gt,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var y={...Wt,...Qt,...Ht,...Ut};const Yt=/[^ ]+/g;function Vt(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(c){const i=c.match(Yt).length;if(n.has(i))return n.get(i);const o=1/Math.pow(i,.5*t),a=parseFloat(Math.round(o*r)/r);return n.set(i,a),a},clear(){n.clear()}}}class Le{constructor({getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){this.norm=Vt(n,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((n,r)=>{this._keysMap[n.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,q(this.docs[0])?this.docs.forEach((e,n)=>{this._addString(e,n)}):this.docs.forEach((e,n)=>{this._addObject(e,n)}),this.norm.clear())}add(e){const n=this.size();q(e)?this._addString(e,n):this._addObject(e,n)}removeAt(e){this.records.splice(e,1);for(let n=e,r=this.size();n<r;n+=1)this.records[n].i-=1}getValueForItemAtKeyId(e,n){return e[this._keysMap[n]]}size(){return this.records.length}_addString(e,n){if(!G(e)||Ie(e))return;let r={v:e,i:n,n:this.norm.get(e)};this.records.push(r)}_addObject(e,n){let r={i:n,$:{}};this.keys.forEach((c,i)=>{let o=c.getFn?c.getFn(e):this.getFn(e,c.path);if(G(o)){if(re(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(G(h))if(q(h)&&!Ie(h)){let E={v:h,i:l,n:this.norm.get(h)};a.push(E)}else re(h)&&h.forEach((E,x)=>{u.push({nestedArrIndex:x,value:E})})}r.$[i]=a}else if(q(o)&&!Ie(o)){let a={v:o,n:this.norm.get(o)};r.$[i]=a}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function at(t,e,{getFn:n=y.getFn,fieldNormWeight:r=y.fieldNormWeight}={}){const c=new Le({getFn:n,fieldNormWeight:r});return c.setKeys(t.map(ot)),c.setSources(e),c.create(),c}function Jt(t,{getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){const{keys:r,records:c}=t,i=new Le({getFn:e,fieldNormWeight:n});return i.setKeys(r),i.setIndexRecords(c),i}function xe(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:c=y.distance,ignoreLocation:i=y.ignoreLocation}={}){const o=e/t.length;if(i)return o;const a=Math.abs(r-n);return c?o+a/c:a?1:o}function Xt(t=[],e=y.minMatchCharLength){let n=[],r=-1,c=-1,i=0;for(let o=t.length;i<o;i+=1){let a=t[i];a&&r===-1?r=i:!a&&r!==-1&&(c=i-1,c-r+1>=e&&n.push([r,c]),r=-1)}return t[i-1]&&i-r>=e&&n.push([r,i-1]),n}const le=32;function Zt(t,e,n,{location:r=y.location,distance:c=y.distance,threshold:i=y.threshold,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,includeMatches:u=y.includeMatches,ignoreLocation:l=y.ignoreLocation}={}){if(e.length>le)throw new Error(Pt(le));const h=e.length,E=t.length,x=Math.max(0,Math.min(r,E));let g=i,m=x;const S=a>1||u,w=S?Array(E):[];let T;for(;(T=t.indexOf(e,m))>-1;){let $=xe(e,{currentLocation:T,expectedLocation:x,distance:c,ignoreLocation:l});if(g=Math.min($,g),m=T+h,S){let N=0;for(;N<h;)w[T+N]=1,N+=1}}m=-1;let j=[],Q=1,W=h+E;const oe=1<<h-1;for(let $=0;$<h;$+=1){let N=0,D=W;for(;N<D;)xe(e,{errors:$,currentLocation:x+D,expectedLocation:x,distance:c,ignoreLocation:l})<=g?N=D:W=D,D=Math.floor((W-N)/2+N);W=D;let ae=Math.max(1,x-D+1),H=o?E:Math.min(x+D,E)+h,v=Array(H+2);v[H+1]=(1<<$)-1;for(let R=H;R>=ae;R-=1){let X=R-1,O=n[t.charAt(X)];if(S&&(w[X]=+!!O),v[R]=(v[R+1]<<1|1)&O,$&&(v[R]|=(j[R+1]|j[R])<<1|1|j[R+1]),v[R]&oe&&(Q=xe(e,{errors:$,currentLocation:X,expectedLocation:x,distance:c,ignoreLocation:l}),Q<=g)){if(g=Q,m=X,m<=x)break;ae=Math.max(1,2*x-m)}}if(xe(e,{errors:$+1,currentLocation:x,expectedLocation:x,distance:c,ignoreLocation:l})>g)break;j=v}const ce={isMatch:m>=0,score:Math.max(.001,Q)};if(S){const $=Xt(w,a);$.length?u&&(ce.indices=$):ce.isMatch=!1}return ce}function qt(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const c=t.charAt(n);e[c]=(e[c]||0)|1<<r-n-1}return e}const Ce=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class ut{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?Ce(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const E=(g,m)=>{this.chunks.push({pattern:g,alphabet:qt(g),startIndex:m})},x=this.pattern.length;if(x>le){let g=0;const m=x%le,S=x-m;for(;g<S;)E(this.pattern.substr(g,le),g),g+=le;if(m){const w=x-le;E(this.pattern.substr(w),w)}}else E(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c}=this.options;if(e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern===e){let S={isMatch:!0,score:0};return c&&(S.indices=[[0,e.length-1]]),S}const{location:i,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let E=[],x=0,g=!1;this.chunks.forEach(({pattern:S,alphabet:w,startIndex:T})=>{const{isMatch:j,score:Q,indices:W}=Zt(e,S,w,{location:i+T,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:c,ignoreLocation:h});j&&(g=!0),x+=Q,j&&W&&(E=[...E,...W])});let m={isMatch:g,score:g?x/this.chunks.length:1};return g&&c&&(m.indices=E),m}}class ie{constructor(e){this.pattern=e}static isMultiMatch(e){return qe(e,this.multiRegex)}static isSingleMatch(e){return qe(e,this.singleRegex)}search(){}}function qe(t,e){const n=t.match(e);return n?n[1]:null}class es extends ie{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const n=e===this.pattern;return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ts extends ie{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class ss extends ie{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const n=e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ns extends ie{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const n=!e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class rs extends ie{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const n=e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class cs extends ie{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const n=!e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class lt extends ie{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){super(e),this._bitapSearch=new ut(e,{location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class ht extends ie{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const c=[],i=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+i,c.push([r,n-1]);const o=!!c.length;return{isMatch:o,score:o?0:1,indices:c}}}const De=[es,ht,ss,ns,cs,rs,ts,lt],et=De.length,is=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,os="|";function as(t,e={}){return t.split(os).map(n=>{let r=n.trim().split(is).filter(i=>i&&!!i.trim()),c=[];for(let i=0,o=r.length;i<o;i+=1){const a=r[i];let u=!1,l=-1;for(;!u&&++l<et;){const h=De[l];let E=h.isMultiMatch(a);E&&(c.push(new h(E,e)),u=!0)}if(!u)for(l=-1;++l<et;){const h=De[l];let E=h.isSingleMatch(a);if(E){c.push(new h(E,e));break}}}return c})}const us=new Set([lt.type,ht.type]);class ls{constructor(e,{isCaseSensitive:n=y.isCaseSensitive,ignoreDiacritics:r=y.ignoreDiacritics,includeMatches:c=y.includeMatches,minMatchCharLength:i=y.minMatchCharLength,ignoreLocation:o=y.ignoreLocation,findAllMatches:a=y.findAllMatches,location:u=y.location,threshold:l=y.threshold,distance:h=y.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c,minMatchCharLength:i,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern=e,this.query=as(this.pattern,this.options)}static condition(e,n){return n.useExtendedSearch}searchIn(e){const n=this.query;if(!n)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:c,ignoreDiacritics:i}=this.options;e=c?e:e.toLowerCase(),e=i?Ce(e):e;let o=0,a=[],u=0;for(let l=0,h=n.length;l<h;l+=1){const E=n[l];a.length=0,o=0;for(let x=0,g=E.length;x<g;x+=1){const m=E[x],{isMatch:S,indices:w,score:T}=m.search(e);if(S){if(o+=1,u+=T,r){const j=m.constructor.type;us.has(j)?a=[...a,...w]:a.push(w)}}else{u=0,o=0,a.length=0;break}}if(o){let x={isMatch:!0,score:u/o};return r&&(x.indices=a),x}}return{isMatch:!1,score:1}}}const ke=[];function hs(...t){ke.push(...t)}function Re(t,e){for(let n=0,r=ke.length;n<r;n+=1){let c=ke[n];if(c.condition(t,e))return new c(t,e)}return new ut(t,e)}const Me={AND:"$and",OR:"$or"},be={PATH:"$path",PATTERN:"$val"},Te=t=>!!(t[Me.AND]||t[Me.OR]),ds=t=>!!t[be.PATH],fs=t=>!re(t)&&ct(t)&&!Te(t),tt=t=>({[Me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function dt(t,e,{auto:n=!0}={}){const r=c=>{let i=Object.keys(c);const o=ds(c);if(!o&&i.length>1&&!Te(c))return r(tt(c));if(fs(c)){const u=o?c[be.PATH]:i[0],l=o?c[be.PATTERN]:c[u];if(!q(l))throw new Error(Nt(u));const h={keyId:_e(u),pattern:l};return n&&(h.searcher=Re(l,e)),h}let a={children:[],operator:i[0]};return i.forEach(u=>{const l=c[u];re(l)&&l.forEach(h=>{a.children.push(r(h))})}),a};return Te(t)||(t=tt(t)),r(t)}function gs(t,{ignoreFieldNorm:e=y.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:c,norm:i,score:o})=>{const a=c?c.weight:null;r*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:i))}),n.score=r})}function ms(t,e){const n=t.matches;e.matches=[],G(n)&&n.forEach(r=>{if(!G(r.indices)||!r.indices.length)return;const{indices:c,value:i}=r;let o={indices:c,value:i};r.key&&(o.key=r.key.src),r.idx>-1&&(o.refIndex=r.idx),e.matches.push(o)})}function ps(t,e){e.score=t.score}function As(t,e,{includeMatches:n=y.includeMatches,includeScore:r=y.includeScore}={}){const c=[];return n&&c.push(ms),r&&c.push(ps),t.map(i=>{const{idx:o}=i,a={item:e[o],refIndex:o};return c.length&&c.forEach(u=>{u(i,a)}),a})}class Z{constructor(e,n={},r){this.options={...y,...n},this.options.useExtendedSearch,this._keyStore=new zt(this.options.keys),this.setCollection(e,r)}setCollection(e,n){if(this._docs=e,n&&!(n instanceof Le))throw new Error(jt);this._myIndex=n||at(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){G(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const n=[];for(let r=0,c=this._docs.length;r<c;r+=1){const i=this._docs[r];e(i,r)&&(this.removeAt(r),r-=1,c-=1,n.push(i))}return n}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:n=-1}={}){const{includeMatches:r,includeScore:c,shouldSort:i,sortFn:o,ignoreFieldNorm:a}=this.options;let u=q(e)?q(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return gs(u,{ignoreFieldNorm:a}),i&&u.sort(o),rt(n)&&n>-1&&(u=u.slice(0,n)),As(u,this._docs,{includeMatches:r,includeScore:c})}_searchStringList(e){const n=Re(e,this.options),{records:r}=this._myIndex,c=[];return r.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=n.searchIn(i);u&&c.push({item:i,idx:o,matches:[{score:l,value:i,norm:a,indices:h}]})}),c}_searchLogical(e){const n=dt(e,this.options),r=(a,u,l)=>{if(!a.children){const{keyId:E,searcher:x}=a,g=this._findMatches({key:this._keyStore.get(E),value:this._myIndex.getValueForItemAtKeyId(u,E),searcher:x});return g&&g.length?[{idx:l,item:u,matches:g}]:[]}const h=[];for(let E=0,x=a.children.length;E<x;E+=1){const g=a.children[E],m=r(g,u,l);if(m.length)h.push(...m);else if(a.operator===Me.AND)return[]}return h},c=this._myIndex.records,i={},o=[];return c.forEach(({$:a,i:u})=>{if(G(a)){let l=r(n,a,u);l.length&&(i[u]||(i[u]={idx:u,item:a,matches:[]},o.push(i[u])),l.forEach(({matches:h})=>{i[u].matches.push(...h)}))}}),o}_searchObjectList(e){const n=Re(e,this.options),{keys:r,records:c}=this._myIndex,i=[];return c.forEach(({$:o,i:a})=>{if(!G(o))return;let u=[];r.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:n}))}),u.length&&i.push({idx:a,item:o,matches:u})}),i}_findMatches({key:e,value:n,searcher:r}){if(!G(n))return[];let c=[];if(re(n))n.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=r.searchIn(i);u&&c.push({score:l,key:e,value:i,idx:o,norm:a,indices:h})});else{const{v:i,n:o}=n,{isMatch:a,score:u,indices:l}=r.searchIn(i);a&&c.push({score:u,key:e,value:i,norm:o,indices:l})}return c}}Z.version="7.1.0";Z.createIndex=at;Z.parseIndex=Jt;Z.config=y;Z.parseQuery=dt;hs(ls);async function ys(t){const e=new URLSearchParams({q:t}),n=await At(yt(`/api/folders/search?${e.toString()}`));if(!n.ok){const c=await n.json().catch(()=>({}));throw new Error(c.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Es=["command","agent","building","area","folder","modified-file"],xs=2;function Cs(){const t=nt(me.SPOTLIGHT_TAB,"all");return fe.includes(t)?t:"all"}function st(){return Rt(me.SPOTLIGHT_QUERY,"")}function Ms(){const t=nt(me.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Et(),E=xt(),x=Ct(),g=Mt(),m=Ft(),S=wt(),w=d.useRef(e);w.current=e;const T=d.useRef(n);T.current=n;const j=d.useRef(r);j.current=r;const Q=d.useRef(c);Q.current=c;const W=d.useRef(i);W.current=i;const oe=d.useRef(o);oe.current=o;const ce=d.useRef(a);ce.current=a;const $=d.useRef(u);$.current=u;const N=d.useRef(l);N.current=l;const[D,ae]=d.useState(st),[H,v]=d.useState(0),[M,R]=d.useState(Cs),[X,O]=d.useState([]),ft=d.useCallback(s=>{ae(s),St(me.SPOTLIGHT_QUERY,s)},[]);d.useEffect(()=>{t&&(ae(st()),v(0))},[t]),d.useEffect(()=>{if(!t){O([]);return}const s=D.trim();if(s.length<xs){O([]);return}let p=!1;const C=setTimeout(()=>{ys(s).then(F=>{p||O(F)}).catch(()=>{p||O([])})},250);return()=>{p=!0,clearTimeout(C)}},[t,D]);const we=d.useCallback(s=>{R(s),vt(me.SPOTLIGHT_TAB,s)},[]),$e=d.useRef(M);$e.current=M;const gt=d.useCallback(s=>{const p=fe.indexOf($e.current),C=fe[(p+s+fe.length)%fe.length];we(C)},[we]);d.useEffect(()=>{v(0)},[M]);const Se=J.getShortcuts(),ge=d.useMemo(()=>t?Bt():{},[t]),pe=d.useMemo(()=>{if(!t)return[];const s=Se.find(C=>C.id==="spawn-agent"),p=Se.find(C=>C.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?Ve(s):"Alt+N",icon:f.jsx(ne,{name:"plus",size:16}),action:()=>{w.current(),T.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:p?Ve(p):"Ctrl+K",icon:f.jsx(ne,{name:"dashboard",size:16}),action:()=>{w.current(),j.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:f.jsx(ne,{name:"gear",size:16}),action:()=>{w.current(),Q.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:f.jsx(ne,{name:"chart-line",size:16}),action:()=>{var C;w.current(),(C=N.current)==null||C.call(N)}}]},[t,Se]),he=d.useMemo(()=>t?Array.from(h.values()).map(s=>{const p=(g||[]).filter(Y=>Y.agentId===s.id).map(Y=>Y.filePath),C=[...new Set(p)],F=C.map(Y=>Y.split("/").pop()||Y),B=[];s.lastAssignedTask&&B.push(s.lastAssignedTask);const L=`${s.class} • ${s.cwd}`;let k=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(k+=` ${s.taskLabel}`),F.length>0&&(k+=` ${F.join(" ")} ${C.join(" ")}`),B.length>0&&(k+=` ${B.join(" ")}`);const P=Date.now()-s.lastActivity;let U;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?U=s.lastAssignedTask.slice(0,150)+"...":U=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:L,lastUserInput:U,timeAway:P,icon:f.jsx(_t,{agent:s,size:20}),_searchText:k,_modifiedFiles:C,_userQueries:B,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,action:()=>{w.current(),It(s.id),J.selectAgent(s.id),J.getState().viewMode!=="flat"&&J.requestTerminalExpand()}}}):[],[t,h,g]),Ae=d.useMemo(()=>t?Array.from(E.values()).map(s=>{var p;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((p=s.directories)==null?void 0:p.length)||0} folders`,icon:f.jsx(ne,{name:"map",size:16}),action:()=>{w.current(),J.selectArea(s.id)}}}):[],[t,E]),je=d.useMemo(()=>{const s=new Map;for(const p of he)p._agentId&&s.set(p._agentId,p);return s},[he]),Ne=d.useMemo(()=>{const s=new Map;if(!t)return s;for(const p of h.values()){const C=J.getAreaForAgent(p.id);if(!C||C.archived)continue;const F=s.get(C.id);F?F.push(p):s.set(C.id,[p])}return s},[t,h,E]),Pe=d.useMemo(()=>{const s=new Map;for(const p of m)s.has(p.agentId)||s.set(p.agentId,p.timestamp);return s},[m]),ve=d.useMemo(()=>{if(!t)return[];const s=D.trim().toLowerCase(),p=Dt({sortMode:Ms(),agentsWithUnseenOutput:S,getLatestToolTimestamp:B=>Pe.get(B)}),C=Array.from(E.values()).filter(B=>!B.archived).filter(B=>s?B.name.toLowerCase().includes(s):!0).sort((B,L)=>B.name.localeCompare(L.name,void 0,{sensitivity:"base"})),F=[];for(const B of C){const k=(Ne.get(B.id)||[]).slice().sort(p).map(P=>je.get(P.id)).filter(P=>!!P);!s&&k.length===0||F.push({areaId:B.id,areaName:B.name,areaColor:B.color,agents:k})}return F},[t,D,E,Ne,je,S,Pe]),ye=d.useMemo(()=>t?Array.from(x.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var P,U,Y,ue,ee;const p=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",C=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",F=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let B=`${F} • ${s.status}`;if(s.type==="database"&&((U=(P=s.database)==null?void 0:P.connections)!=null&&U.length)){const z=s.database.connections[0];B+=` • ${z.engine} @ ${z.host}`}else s.type==="tests"&&s.folderPath?B=`${F} • ${s.folderPath}`:s.cwd&&(B+=` • ${s.cwd}`);const L=((Y=s.pm2Status)==null?void 0:Y.ports)||[];let k=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((ue=s.pm2)==null?void 0:ue.name)||""}`;if(s.type==="tests"&&(k+=` ${s.folderPath||""} tests junit maven`),L.length>0&&(k+=` ${L.join(" ")}`),s.type==="database"&&((ee=s.database)!=null&&ee.connections))for(const z of s.database.connections)k+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:B,_ports:L,icon:f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[f.jsx(ne,{name:"status-pending",size:10,weight:"fill",color:p}),f.jsx(ne,{name:C,size:16})]}),_searchText:k,action:()=>{var z;w.current(),s.type==="boss"?ce.current(s.id):s.type==="database"?$.current(s.id):s.type==="tests"?J.openTestsBuilding(s.id):(z=s.pm2)!=null&&z.enabled&&oe.current(s.id)}}}):[],[t,x]),Ke=d.useMemo(()=>{if(!t)return[];const s=g||[],p=new Set,C=[];for(const F of s){if(p.has(F.filePath))continue;p.add(F.filePath);const B=F.filePath.split("/").pop()||F.filePath,L=F.action==="created"?"Created":F.action==="modified"?"Modified":F.action==="deleted"?"Deleted":"Read";if(C.push({id:`modified-${F.filePath}-${F.timestamp}`,type:"modified-file",title:B,subtitle:`${L} by ${F.agentName} • ${F.filePath}`,matchedText:F.filePath,icon:F.action==="deleted"?f.jsx(ne,{name:"trash",size:16}):kt(F.filePath),action:()=>{w.current();const k=Array.from(J.getState().areas.values());for(const P of k)for(const U of P.directories||[])if(F.filePath.startsWith(U)){J.setFileViewerPath(F.filePath),W.current(P.id);return}J.selectAgent(F.agentId)}}),C.length>=50)break}return C},[t,g]),Oe=d.useMemo(()=>t?X.map(s=>{const p=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:p,matchedText:s.path,icon:f.jsx(ne,{name:s.isGitRepo?"git-branch":"folder",size:16}),_searchText:`${s.name} ${s.path}`,_isGitRepo:s.isGitRepo,_gitBranch:s.gitBranch,action:()=>{w.current(),J.openFileExplorer(s.path)}}}):[],[t,X]),ze=d.useMemo(()=>new Z(he,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[he]),Ge=d.useMemo(()=>new Z(pe,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[pe]),Qe=d.useMemo(()=>new Z(Ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Ae]),We=d.useMemo(()=>new Z(Ke,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ke]),He=d.useMemo(()=>new Z(ye,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ye]),de=d.useMemo(()=>{if(!D.trim()){const A=[];A.push(...ye);const I=[...he].sort((b,K)=>{const te=Ee(b._agentId,b._lastActivity,ge);return Ee(K._agentId,K._lastActivity,ge)-te});A.push(...I),A.push(...pe.slice(0,2)),A.push(...Ae.slice(0,2));const _={};return Es.forEach((b,K)=>{_[b]=K}),A.sort((b,K)=>(_[b.type]??999)-(_[K.type]??999)),A}const s=D.trim().toLowerCase(),p=ze.search(D).slice(0,8),C=Ge.search(D).slice(0,3),F=Qe.search(D).slice(0,2),B=We.search(D).slice(0,3),L=Oe.slice(0,8),k=He.search(D).filter(A=>{const I=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(s)||I<=.2}).slice(0,4),P={agent:6,building:5,folder:4,command:3,area:2,"modified-file":1},U=A=>{if(!s)return 1;const I=A.title.toLowerCase();return I===s?6:I.startsWith(s)?5:I.split(/[^a-z0-9]+/i).includes(s)?4:I.includes(s)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(s)?2:1},Y=(A,I)=>{const _=(1-Math.min(1,I??1))*4;return U(A)*100+(P[A.type]??0)*5+_},ue=new Map,ee=(A,I)=>{const _=ue.get(A.type),b={item:A,score:Y(A,I)};_?_.push(b):ue.set(A.type,[b])};for(const A of p){const I={...A.item};if(I._modifiedFiles&&I._modifiedFiles.length>0){const _=I._modifiedFiles.filter(b=>{var se;const K=((se=b.split("/").pop())==null?void 0:se.toLowerCase())||"",te=b.toLowerCase();return K.includes(s)||te.includes(s)});_.length>0&&(I.matchedFiles=_)}if(I._userQueries&&I._userQueries.length>0){const _=I._userQueries.find(b=>b.toLowerCase().includes(s));if(_)if(_.length>200){const K=_.toLowerCase().indexOf(s),te=Math.max(0,K-60),se=Math.min(_.length,K+s.length+100);I.matchedQuery=(te>0?"...":"")+_.slice(te,se)+(se<_.length?"...":"")}else I.matchedQuery=_}ee(I,A.score)}for(const A of k)ee(A.item,A.score);for(const A of C)ee(A.item,A.score);for(const A of F)ee(A.item,A.score);for(const A of B)ee(A.item,A.score);for(const A of L)ee(A,void 0);for(const[A,I]of ue)A==="agent"?I.sort((_,b)=>{const K=U(_.item),te=U(b.item);if(te!==K)return te-K;const se=Ee(_.item._agentId,_.item._lastActivity,ge),Ye=Ee(b.item._agentId,b.item._lastActivity,ge);return Ye!==se?Ye-se:b.score-_.score}):I.sort((_,b)=>b.score-_.score);const z=A=>A.reduce((I,_)=>Math.max(I,_.score),-1),Ue=[];return Array.from(ue.values()).sort((A,I)=>z(I)-z(A)).forEach(A=>{for(const I of A)Ue.push(I.item)}),Ue},[D,ze,Ge,Qe,We,He,pe,he,Ae,ye,Oe,ge]),V=d.useMemo(()=>{switch(M){case"agents":return de.filter(s=>s.type==="agent");case"buildings":return de.filter(s=>s.type==="building");case"commands":return de.filter(s=>s.type==="command");case"folders":return de.filter(s=>s.type==="folder");case"areas":return ve.flatMap(s=>s.agents);case"all":default:return de}},[M,de,ve]);d.useEffect(()=>{H>=V.length&&v(Math.max(0,V.length-1))},[V.length,H]);const mt=d.useCallback(s=>{if(s.altKey&&!s.ctrlKey&&!s.metaKey&&(s.key==="p"||s.key==="n"||s.key==="P"||s.key==="N")){s.preventDefault(),s.stopPropagation(),s.nativeEvent.stopImmediatePropagation();const p=s.key.toLowerCase();v(p==="p"?C=>C>0?C-1:V.length-1:C=>C<V.length-1?C+1:0);return}switch(s.key){case"Escape":s.preventDefault(),w.current();break;case"ArrowUp":s.preventDefault(),v(p=>p>0?p-1:V.length-1);break;case"ArrowDown":s.preventDefault(),v(p=>p<V.length-1?p+1:0);break;case"Enter":s.preventDefault(),V[H]&&V[H].action();break}},[V,H]),pt=d.useCallback((s,p)=>{if(!p||!s)return s;const C=s.toLowerCase(),F=p.toLowerCase(),B=[];let L=0,k=C.indexOf(F),P=0;for(;k!==-1;)k>L&&B.push(s.slice(L,k)),B.push(Be.createElement("mark",{key:P++,className:"spotlight-highlight"},s.slice(k,k+p.length))),L=k+p.length,k=C.indexOf(F,L);return L<s.length&&B.push(s.slice(L)),B.length>0?Be.createElement(Be.Fragment,null,...B):s},[]);return{query:D,setQuery:ft,selectedIndex:H,setSelectedIndex:v,results:V,activeTab:M,setActiveTab:we,cycleTab:gt,areaSections:ve,handleKeyDown:mt,highlightMatch:pt}}const ws=d.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:c},i){const{t:o}=Fe(["common"]);return f.jsxs("div",{className:"spotlight-input-wrapper",children:[f.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),f.jsx("input",{ref:i,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{n(a.target.value),c()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),f.jsxs("div",{className:"spotlight-input-hints",children:[f.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Ss=d.memo(function({activeTab:e,onSelect:n}){const{t:r}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[fe.map(c=>f.jsx("button",{type:"button",role:"tab","aria-selected":c===e,tabIndex:-1,className:`spotlight-tab${c===e?" active":""}`,onClick:()=>n(c),children:r(`terminal:spotlight.tabs.${c}`)},c)),f.jsx("span",{className:"spotlight-tabs-hint",children:f.jsx("kbd",{children:"Tab"})})]})}),vs=d.forwardRef(function({results:e,selectedIndex:n,query:r,activeTab:c,areaSections:i,highlightMatch:o,onSelectIndex:a},u){const{t:l}=Fe(["terminal"]),h=d.useRef(!1);d.useEffect(()=>{h.current=!1},[e]),d.useEffect(()=>{const g=typeof u=="function"?null:u==null?void 0:u.current;if(!g)return;const m=()=>{h.current=!0};return g.addEventListener("mousemove",m),()=>{g.removeEventListener("mousemove",m)}},[u,e]);const E={command:l("terminal:spotlight.categories.commands"),agent:l("terminal:spotlight.categories.agents"),building:l("terminal:spotlight.categories.infrastructure"),area:l("terminal:spotlight.categories.areas"),folder:l("terminal:spotlight.categories.folders"),"modified-file":l("terminal:spotlight.categories.modifiedFiles")},x=d.useMemo(()=>{const g=[];let m=null,S=[];return e.forEach((w,T)=>{w.type!==m&&(m!==null&&S.length>0&&g.push([m,S]),m=w.type,S=[]),S.push({result:w,index:T})}),m!==null&&S.length>0&&g.push([m,S]),g},[e]);if(d.useEffect(()=>{if(!u||typeof u=="function")return;const g=u.current;if(!g)return;const m=g.querySelector(".spotlight-item.selected");m&&m.scrollIntoView({block:"nearest",behavior:"smooth"})},[n,u]),c==="areas"){if(i.length===0)return f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})});let g=0;return f.jsx("div",{className:"spotlight-results",ref:u,children:i.map(m=>f.jsxs("div",{children:[f.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[f.jsx("span",{className:"spotlight-area-dot",style:{background:m.areaColor},"aria-hidden":"true"}),f.jsx("span",{className:"spotlight-area-name",children:m.areaName}),f.jsx("span",{className:"spotlight-area-count",children:m.agents.length})]}),m.agents.length===0?f.jsx("div",{className:"spotlight-area-empty",children:l("terminal:spotlight.noAgentsInArea")}):m.agents.map(S=>{const w=g++;return f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id)})]},m.areaId))})}return e.length===0?f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})}):f.jsx("div",{className:"spotlight-results",ref:u,children:x.map(([g,m])=>f.jsxs("div",{children:[x.length>1&&f.jsx("div",{className:"spotlight-category-header",children:E[g]||g}),m.map(({result:S,index:w})=>f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id))]},g))})}),Bs=d.memo(function(){const{t:e}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-footer",children:[f.jsxs("div",{className:"spotlight-footer-left",children:[f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"↑"}),f.jsx("kbd",{children:"↓"})," ",f.jsx("kbd",{children:"Alt+N"}),f.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),f.jsx("div",{className:"spotlight-footer-right",children:f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Is=768;function Rs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=d.useRef(null),E=d.useRef(null),x=d.useRef(null),g=d.useRef(0),{query:m,setQuery:S,selectedIndex:w,setSelectedIndex:T,results:j,activeTab:Q,setActiveTab:W,cycleTab:oe,areaSections:ce,handleKeyDown:$,highlightMatch:N}=Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});g.current=j.length;const D=d.useRef(oe);D.current=oe,d.useEffect(()=>{t&&setTimeout(()=>{var v,M;(v=h.current)==null||v.focus(),(M=h.current)==null||M.select()},50)},[t]),d.useEffect(()=>{if(!t)return;const v=window.visualViewport;if(!v||window.innerWidth>Is)return;const M=()=>{const R=E.current;R&&(R.style.height=`${v.height}px`,R.style.top=`${v.offsetTop}px`)};return M(),v.addEventListener("resize",M),v.addEventListener("scroll",M),()=>{v.removeEventListener("resize",M),v.removeEventListener("scroll",M);const R=E.current;R&&(R.style.height="",R.style.top="")}},[t]),d.useEffect(()=>{if(!t)return;const v=M=>{if(M.key==="Escape"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),e();return}if(M.key==="Tab"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),D.current(M.shiftKey?-1:1);return}if(M.altKey&&!M.ctrlKey&&!M.metaKey&&(M.key==="n"||M.key==="p"||M.key==="N"||M.key==="P")){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation();const R=M.key.toLowerCase(),X=g.current;T(R==="p"?O=>O>0?O-1:X-1:O=>O<X-1?O+1:0);return}};return window.addEventListener("keydown",v,{capture:!0}),()=>{window.removeEventListener("keydown",v,{capture:!0})}},[t,e]);const ae=d.useCallback(v=>{v.target===v.currentTarget&&e()},[e]),H=d.useCallback(()=>{T(0)},[T]);return t?f.jsx("div",{ref:E,className:"spotlight-overlay",onClick:ae,children:f.jsxs("div",{className:"spotlight-modal",children:[f.jsx(ws,{ref:h,query:m,onQueryChange:S,onKeyDown:$,onResetSelection:H}),f.jsx(Ss,{activeTab:Q,onSelect:W}),f.jsx(vs,{ref:x,results:j,selectedIndex:w,query:m,activeTab:Q,areaSections:ce,highlightMatch:N,onSelectIndex:T}),f.jsx(Bs,{})]})}):null}export{Ls as FILE_ICON_NAMES,Rs as Spotlight,Bs as SpotlightFooter,ws as SpotlightInput,Je as SpotlightItem,vs as SpotlightResults,$s as formatDuration,js as formatRelativeTime,Ns as getAgentIcon,kt as getFileIconFromPath,Ps as getTypeLabel,Fs as useSpotlightSearch};
|
|
1
|
+
import{h as At,i as yt,aw as Et,a1 as xt,a2 as Ct,c9 as Mt,ca as Ft,aF as wt,r as d,X as St,S as me,cb as vt,cc as fe,s as J,cd as Bt,j as f,I as ne,ce as Ve,cf as It,a6 as _t,cg as Dt,ch as kt,ci as Ee,al as Be,W as Rt,p as nt,u as Fe,cj as Je}from"./main-BVsJe5cx.js";import{ck as Ls,cl as $s,cm as js,cn as Ns,co as Ps}from"./main-BVsJe5cx.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function re(t){return Array.isArray?Array.isArray(t):it(t)==="[object Array]"}function bt(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Tt(t){return t==null?"":bt(t)}function q(t){return typeof t=="string"}function rt(t){return typeof t=="number"}function Lt(t){return t===!0||t===!1||$t(t)&&it(t)=="[object Boolean]"}function ct(t){return typeof t=="object"}function $t(t){return ct(t)&&t!==null}function G(t){return t!=null}function Ie(t){return!t.trim().length}function it(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const jt="Incorrect 'index' type",Nt=t=>`Invalid value for key ${t}`,Pt=t=>`Pattern length exceeds max of ${t}.`,Kt=t=>`Missing ${t} property in key`,Ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Xe=Object.prototype.hasOwnProperty;class zt{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let c=ot(r);this._keys.push(c),this._keyMap[c.id]=c,n+=c.weight}),this._keys.forEach(r=>{r.weight/=n})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ot(t){let e=null,n=null,r=null,c=1,i=null;if(q(t)||re(t))r=t,e=Ze(t),n=_e(t);else{if(!Xe.call(t,"name"))throw new Error(Kt("name"));const o=t.name;if(r=o,Xe.call(t,"weight")&&(c=t.weight,c<=0))throw new Error(Ot(o));e=Ze(o),n=_e(o),i=t.getFn}return{path:e,id:n,weight:c,src:r,getFn:i}}function Ze(t){return re(t)?t:t.split(".")}function _e(t){return re(t)?t.join("."):t}function Gt(t,e){let n=[],r=!1;const c=(i,o,a)=>{if(G(i))if(!o[a])n.push(i);else{let u=o[a];const l=i[u];if(!G(l))return;if(a===o.length-1&&(q(l)||rt(l)||Lt(l)))n.push(Tt(l));else if(re(l)){r=!0;for(let h=0,E=l.length;h<E;h+=1)c(l[h],o,a+1)}else o.length&&c(l,o,a+1)}};return c(t,q(e)?e.split("."):e,0),r?n:n[0]}const Qt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Wt={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},Ht={location:0,threshold:.6,distance:100},Ut={useExtendedSearch:!1,getFn:Gt,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var y={...Wt,...Qt,...Ht,...Ut};const Yt=/[^ ]+/g;function Vt(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(c){const i=c.match(Yt).length;if(n.has(i))return n.get(i);const o=1/Math.pow(i,.5*t),a=parseFloat(Math.round(o*r)/r);return n.set(i,a),a},clear(){n.clear()}}}class Le{constructor({getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){this.norm=Vt(n,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((n,r)=>{this._keysMap[n.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,q(this.docs[0])?this.docs.forEach((e,n)=>{this._addString(e,n)}):this.docs.forEach((e,n)=>{this._addObject(e,n)}),this.norm.clear())}add(e){const n=this.size();q(e)?this._addString(e,n):this._addObject(e,n)}removeAt(e){this.records.splice(e,1);for(let n=e,r=this.size();n<r;n+=1)this.records[n].i-=1}getValueForItemAtKeyId(e,n){return e[this._keysMap[n]]}size(){return this.records.length}_addString(e,n){if(!G(e)||Ie(e))return;let r={v:e,i:n,n:this.norm.get(e)};this.records.push(r)}_addObject(e,n){let r={i:n,$:{}};this.keys.forEach((c,i)=>{let o=c.getFn?c.getFn(e):this.getFn(e,c.path);if(G(o)){if(re(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(G(h))if(q(h)&&!Ie(h)){let E={v:h,i:l,n:this.norm.get(h)};a.push(E)}else re(h)&&h.forEach((E,x)=>{u.push({nestedArrIndex:x,value:E})})}r.$[i]=a}else if(q(o)&&!Ie(o)){let a={v:o,n:this.norm.get(o)};r.$[i]=a}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function at(t,e,{getFn:n=y.getFn,fieldNormWeight:r=y.fieldNormWeight}={}){const c=new Le({getFn:n,fieldNormWeight:r});return c.setKeys(t.map(ot)),c.setSources(e),c.create(),c}function Jt(t,{getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){const{keys:r,records:c}=t,i=new Le({getFn:e,fieldNormWeight:n});return i.setKeys(r),i.setIndexRecords(c),i}function xe(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:c=y.distance,ignoreLocation:i=y.ignoreLocation}={}){const o=e/t.length;if(i)return o;const a=Math.abs(r-n);return c?o+a/c:a?1:o}function Xt(t=[],e=y.minMatchCharLength){let n=[],r=-1,c=-1,i=0;for(let o=t.length;i<o;i+=1){let a=t[i];a&&r===-1?r=i:!a&&r!==-1&&(c=i-1,c-r+1>=e&&n.push([r,c]),r=-1)}return t[i-1]&&i-r>=e&&n.push([r,i-1]),n}const le=32;function Zt(t,e,n,{location:r=y.location,distance:c=y.distance,threshold:i=y.threshold,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,includeMatches:u=y.includeMatches,ignoreLocation:l=y.ignoreLocation}={}){if(e.length>le)throw new Error(Pt(le));const h=e.length,E=t.length,x=Math.max(0,Math.min(r,E));let g=i,m=x;const S=a>1||u,w=S?Array(E):[];let T;for(;(T=t.indexOf(e,m))>-1;){let $=xe(e,{currentLocation:T,expectedLocation:x,distance:c,ignoreLocation:l});if(g=Math.min($,g),m=T+h,S){let N=0;for(;N<h;)w[T+N]=1,N+=1}}m=-1;let j=[],Q=1,W=h+E;const oe=1<<h-1;for(let $=0;$<h;$+=1){let N=0,D=W;for(;N<D;)xe(e,{errors:$,currentLocation:x+D,expectedLocation:x,distance:c,ignoreLocation:l})<=g?N=D:W=D,D=Math.floor((W-N)/2+N);W=D;let ae=Math.max(1,x-D+1),H=o?E:Math.min(x+D,E)+h,v=Array(H+2);v[H+1]=(1<<$)-1;for(let R=H;R>=ae;R-=1){let X=R-1,O=n[t.charAt(X)];if(S&&(w[X]=+!!O),v[R]=(v[R+1]<<1|1)&O,$&&(v[R]|=(j[R+1]|j[R])<<1|1|j[R+1]),v[R]&oe&&(Q=xe(e,{errors:$,currentLocation:X,expectedLocation:x,distance:c,ignoreLocation:l}),Q<=g)){if(g=Q,m=X,m<=x)break;ae=Math.max(1,2*x-m)}}if(xe(e,{errors:$+1,currentLocation:x,expectedLocation:x,distance:c,ignoreLocation:l})>g)break;j=v}const ce={isMatch:m>=0,score:Math.max(.001,Q)};if(S){const $=Xt(w,a);$.length?u&&(ce.indices=$):ce.isMatch=!1}return ce}function qt(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const c=t.charAt(n);e[c]=(e[c]||0)|1<<r-n-1}return e}const Ce=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class ut{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?Ce(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const E=(g,m)=>{this.chunks.push({pattern:g,alphabet:qt(g),startIndex:m})},x=this.pattern.length;if(x>le){let g=0;const m=x%le,S=x-m;for(;g<S;)E(this.pattern.substr(g,le),g),g+=le;if(m){const w=x-le;E(this.pattern.substr(w),w)}}else E(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c}=this.options;if(e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern===e){let S={isMatch:!0,score:0};return c&&(S.indices=[[0,e.length-1]]),S}const{location:i,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let E=[],x=0,g=!1;this.chunks.forEach(({pattern:S,alphabet:w,startIndex:T})=>{const{isMatch:j,score:Q,indices:W}=Zt(e,S,w,{location:i+T,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:c,ignoreLocation:h});j&&(g=!0),x+=Q,j&&W&&(E=[...E,...W])});let m={isMatch:g,score:g?x/this.chunks.length:1};return g&&c&&(m.indices=E),m}}class ie{constructor(e){this.pattern=e}static isMultiMatch(e){return qe(e,this.multiRegex)}static isSingleMatch(e){return qe(e,this.singleRegex)}search(){}}function qe(t,e){const n=t.match(e);return n?n[1]:null}class es extends ie{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const n=e===this.pattern;return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ts extends ie{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class ss extends ie{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const n=e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ns extends ie{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const n=!e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class rs extends ie{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const n=e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class cs extends ie{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const n=!e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class lt extends ie{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){super(e),this._bitapSearch=new ut(e,{location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class ht extends ie{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const c=[],i=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+i,c.push([r,n-1]);const o=!!c.length;return{isMatch:o,score:o?0:1,indices:c}}}const De=[es,ht,ss,ns,cs,rs,ts,lt],et=De.length,is=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,os="|";function as(t,e={}){return t.split(os).map(n=>{let r=n.trim().split(is).filter(i=>i&&!!i.trim()),c=[];for(let i=0,o=r.length;i<o;i+=1){const a=r[i];let u=!1,l=-1;for(;!u&&++l<et;){const h=De[l];let E=h.isMultiMatch(a);E&&(c.push(new h(E,e)),u=!0)}if(!u)for(l=-1;++l<et;){const h=De[l];let E=h.isSingleMatch(a);if(E){c.push(new h(E,e));break}}}return c})}const us=new Set([lt.type,ht.type]);class ls{constructor(e,{isCaseSensitive:n=y.isCaseSensitive,ignoreDiacritics:r=y.ignoreDiacritics,includeMatches:c=y.includeMatches,minMatchCharLength:i=y.minMatchCharLength,ignoreLocation:o=y.ignoreLocation,findAllMatches:a=y.findAllMatches,location:u=y.location,threshold:l=y.threshold,distance:h=y.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c,minMatchCharLength:i,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern=e,this.query=as(this.pattern,this.options)}static condition(e,n){return n.useExtendedSearch}searchIn(e){const n=this.query;if(!n)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:c,ignoreDiacritics:i}=this.options;e=c?e:e.toLowerCase(),e=i?Ce(e):e;let o=0,a=[],u=0;for(let l=0,h=n.length;l<h;l+=1){const E=n[l];a.length=0,o=0;for(let x=0,g=E.length;x<g;x+=1){const m=E[x],{isMatch:S,indices:w,score:T}=m.search(e);if(S){if(o+=1,u+=T,r){const j=m.constructor.type;us.has(j)?a=[...a,...w]:a.push(w)}}else{u=0,o=0,a.length=0;break}}if(o){let x={isMatch:!0,score:u/o};return r&&(x.indices=a),x}}return{isMatch:!1,score:1}}}const ke=[];function hs(...t){ke.push(...t)}function Re(t,e){for(let n=0,r=ke.length;n<r;n+=1){let c=ke[n];if(c.condition(t,e))return new c(t,e)}return new ut(t,e)}const Me={AND:"$and",OR:"$or"},be={PATH:"$path",PATTERN:"$val"},Te=t=>!!(t[Me.AND]||t[Me.OR]),ds=t=>!!t[be.PATH],fs=t=>!re(t)&&ct(t)&&!Te(t),tt=t=>({[Me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function dt(t,e,{auto:n=!0}={}){const r=c=>{let i=Object.keys(c);const o=ds(c);if(!o&&i.length>1&&!Te(c))return r(tt(c));if(fs(c)){const u=o?c[be.PATH]:i[0],l=o?c[be.PATTERN]:c[u];if(!q(l))throw new Error(Nt(u));const h={keyId:_e(u),pattern:l};return n&&(h.searcher=Re(l,e)),h}let a={children:[],operator:i[0]};return i.forEach(u=>{const l=c[u];re(l)&&l.forEach(h=>{a.children.push(r(h))})}),a};return Te(t)||(t=tt(t)),r(t)}function gs(t,{ignoreFieldNorm:e=y.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:c,norm:i,score:o})=>{const a=c?c.weight:null;r*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:i))}),n.score=r})}function ms(t,e){const n=t.matches;e.matches=[],G(n)&&n.forEach(r=>{if(!G(r.indices)||!r.indices.length)return;const{indices:c,value:i}=r;let o={indices:c,value:i};r.key&&(o.key=r.key.src),r.idx>-1&&(o.refIndex=r.idx),e.matches.push(o)})}function ps(t,e){e.score=t.score}function As(t,e,{includeMatches:n=y.includeMatches,includeScore:r=y.includeScore}={}){const c=[];return n&&c.push(ms),r&&c.push(ps),t.map(i=>{const{idx:o}=i,a={item:e[o],refIndex:o};return c.length&&c.forEach(u=>{u(i,a)}),a})}class Z{constructor(e,n={},r){this.options={...y,...n},this.options.useExtendedSearch,this._keyStore=new zt(this.options.keys),this.setCollection(e,r)}setCollection(e,n){if(this._docs=e,n&&!(n instanceof Le))throw new Error(jt);this._myIndex=n||at(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){G(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const n=[];for(let r=0,c=this._docs.length;r<c;r+=1){const i=this._docs[r];e(i,r)&&(this.removeAt(r),r-=1,c-=1,n.push(i))}return n}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:n=-1}={}){const{includeMatches:r,includeScore:c,shouldSort:i,sortFn:o,ignoreFieldNorm:a}=this.options;let u=q(e)?q(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return gs(u,{ignoreFieldNorm:a}),i&&u.sort(o),rt(n)&&n>-1&&(u=u.slice(0,n)),As(u,this._docs,{includeMatches:r,includeScore:c})}_searchStringList(e){const n=Re(e,this.options),{records:r}=this._myIndex,c=[];return r.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=n.searchIn(i);u&&c.push({item:i,idx:o,matches:[{score:l,value:i,norm:a,indices:h}]})}),c}_searchLogical(e){const n=dt(e,this.options),r=(a,u,l)=>{if(!a.children){const{keyId:E,searcher:x}=a,g=this._findMatches({key:this._keyStore.get(E),value:this._myIndex.getValueForItemAtKeyId(u,E),searcher:x});return g&&g.length?[{idx:l,item:u,matches:g}]:[]}const h=[];for(let E=0,x=a.children.length;E<x;E+=1){const g=a.children[E],m=r(g,u,l);if(m.length)h.push(...m);else if(a.operator===Me.AND)return[]}return h},c=this._myIndex.records,i={},o=[];return c.forEach(({$:a,i:u})=>{if(G(a)){let l=r(n,a,u);l.length&&(i[u]||(i[u]={idx:u,item:a,matches:[]},o.push(i[u])),l.forEach(({matches:h})=>{i[u].matches.push(...h)}))}}),o}_searchObjectList(e){const n=Re(e,this.options),{keys:r,records:c}=this._myIndex,i=[];return c.forEach(({$:o,i:a})=>{if(!G(o))return;let u=[];r.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:n}))}),u.length&&i.push({idx:a,item:o,matches:u})}),i}_findMatches({key:e,value:n,searcher:r}){if(!G(n))return[];let c=[];if(re(n))n.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=r.searchIn(i);u&&c.push({score:l,key:e,value:i,idx:o,norm:a,indices:h})});else{const{v:i,n:o}=n,{isMatch:a,score:u,indices:l}=r.searchIn(i);a&&c.push({score:u,key:e,value:i,norm:o,indices:l})}return c}}Z.version="7.1.0";Z.createIndex=at;Z.parseIndex=Jt;Z.config=y;Z.parseQuery=dt;hs(ls);async function ys(t){const e=new URLSearchParams({q:t}),n=await At(yt(`/api/folders/search?${e.toString()}`));if(!n.ok){const c=await n.json().catch(()=>({}));throw new Error(c.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Es=["command","agent","building","area","folder","modified-file"],xs=2;function Cs(){const t=nt(me.SPOTLIGHT_TAB,"all");return fe.includes(t)?t:"all"}function st(){return Rt(me.SPOTLIGHT_QUERY,"")}function Ms(){const t=nt(me.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Et(),E=xt(),x=Ct(),g=Mt(),m=Ft(),S=wt(),w=d.useRef(e);w.current=e;const T=d.useRef(n);T.current=n;const j=d.useRef(r);j.current=r;const Q=d.useRef(c);Q.current=c;const W=d.useRef(i);W.current=i;const oe=d.useRef(o);oe.current=o;const ce=d.useRef(a);ce.current=a;const $=d.useRef(u);$.current=u;const N=d.useRef(l);N.current=l;const[D,ae]=d.useState(st),[H,v]=d.useState(0),[M,R]=d.useState(Cs),[X,O]=d.useState([]),ft=d.useCallback(s=>{ae(s),St(me.SPOTLIGHT_QUERY,s)},[]);d.useEffect(()=>{t&&(ae(st()),v(0))},[t]),d.useEffect(()=>{if(!t){O([]);return}const s=D.trim();if(s.length<xs){O([]);return}let p=!1;const C=setTimeout(()=>{ys(s).then(F=>{p||O(F)}).catch(()=>{p||O([])})},250);return()=>{p=!0,clearTimeout(C)}},[t,D]);const we=d.useCallback(s=>{R(s),vt(me.SPOTLIGHT_TAB,s)},[]),$e=d.useRef(M);$e.current=M;const gt=d.useCallback(s=>{const p=fe.indexOf($e.current),C=fe[(p+s+fe.length)%fe.length];we(C)},[we]);d.useEffect(()=>{v(0)},[M]);const Se=J.getShortcuts(),ge=d.useMemo(()=>t?Bt():{},[t]),pe=d.useMemo(()=>{if(!t)return[];const s=Se.find(C=>C.id==="spawn-agent"),p=Se.find(C=>C.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?Ve(s):"Alt+N",icon:f.jsx(ne,{name:"plus",size:16}),action:()=>{w.current(),T.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:p?Ve(p):"Ctrl+K",icon:f.jsx(ne,{name:"dashboard",size:16}),action:()=>{w.current(),j.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:f.jsx(ne,{name:"gear",size:16}),action:()=>{w.current(),Q.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:f.jsx(ne,{name:"chart-line",size:16}),action:()=>{var C;w.current(),(C=N.current)==null||C.call(N)}}]},[t,Se]),he=d.useMemo(()=>t?Array.from(h.values()).map(s=>{const p=(g||[]).filter(Y=>Y.agentId===s.id).map(Y=>Y.filePath),C=[...new Set(p)],F=C.map(Y=>Y.split("/").pop()||Y),B=[];s.lastAssignedTask&&B.push(s.lastAssignedTask);const L=`${s.class} • ${s.cwd}`;let k=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(k+=` ${s.taskLabel}`),F.length>0&&(k+=` ${F.join(" ")} ${C.join(" ")}`),B.length>0&&(k+=` ${B.join(" ")}`);const P=Date.now()-s.lastActivity;let U;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?U=s.lastAssignedTask.slice(0,150)+"...":U=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:L,lastUserInput:U,timeAway:P,icon:f.jsx(_t,{agent:s,size:20}),_searchText:k,_modifiedFiles:C,_userQueries:B,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,action:()=>{w.current(),It(s.id),J.selectAgent(s.id),J.getState().viewMode!=="flat"&&J.requestTerminalExpand()}}}):[],[t,h,g]),Ae=d.useMemo(()=>t?Array.from(E.values()).map(s=>{var p;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((p=s.directories)==null?void 0:p.length)||0} folders`,icon:f.jsx(ne,{name:"map",size:16}),action:()=>{w.current(),J.selectArea(s.id)}}}):[],[t,E]),je=d.useMemo(()=>{const s=new Map;for(const p of he)p._agentId&&s.set(p._agentId,p);return s},[he]),Ne=d.useMemo(()=>{const s=new Map;if(!t)return s;for(const p of h.values()){const C=J.getAreaForAgent(p.id);if(!C||C.archived)continue;const F=s.get(C.id);F?F.push(p):s.set(C.id,[p])}return s},[t,h,E]),Pe=d.useMemo(()=>{const s=new Map;for(const p of m)s.has(p.agentId)||s.set(p.agentId,p.timestamp);return s},[m]),ve=d.useMemo(()=>{if(!t)return[];const s=D.trim().toLowerCase(),p=Dt({sortMode:Ms(),agentsWithUnseenOutput:S,getLatestToolTimestamp:B=>Pe.get(B)}),C=Array.from(E.values()).filter(B=>!B.archived).filter(B=>s?B.name.toLowerCase().includes(s):!0).sort((B,L)=>B.name.localeCompare(L.name,void 0,{sensitivity:"base"})),F=[];for(const B of C){const k=(Ne.get(B.id)||[]).slice().sort(p).map(P=>je.get(P.id)).filter(P=>!!P);!s&&k.length===0||F.push({areaId:B.id,areaName:B.name,areaColor:B.color,agents:k})}return F},[t,D,E,Ne,je,S,Pe]),ye=d.useMemo(()=>t?Array.from(x.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var P,U,Y,ue,ee;const p=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",C=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",F=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let B=`${F} • ${s.status}`;if(s.type==="database"&&((U=(P=s.database)==null?void 0:P.connections)!=null&&U.length)){const z=s.database.connections[0];B+=` • ${z.engine} @ ${z.host}`}else s.type==="tests"&&s.folderPath?B=`${F} • ${s.folderPath}`:s.cwd&&(B+=` • ${s.cwd}`);const L=((Y=s.pm2Status)==null?void 0:Y.ports)||[];let k=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((ue=s.pm2)==null?void 0:ue.name)||""}`;if(s.type==="tests"&&(k+=` ${s.folderPath||""} tests junit maven`),L.length>0&&(k+=` ${L.join(" ")}`),s.type==="database"&&((ee=s.database)!=null&&ee.connections))for(const z of s.database.connections)k+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:B,_ports:L,icon:f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[f.jsx(ne,{name:"status-pending",size:10,weight:"fill",color:p}),f.jsx(ne,{name:C,size:16})]}),_searchText:k,action:()=>{var z;w.current(),s.type==="boss"?ce.current(s.id):s.type==="database"?$.current(s.id):s.type==="tests"?J.openTestsBuilding(s.id):(z=s.pm2)!=null&&z.enabled&&oe.current(s.id)}}}):[],[t,x]),Ke=d.useMemo(()=>{if(!t)return[];const s=g||[],p=new Set,C=[];for(const F of s){if(p.has(F.filePath))continue;p.add(F.filePath);const B=F.filePath.split("/").pop()||F.filePath,L=F.action==="created"?"Created":F.action==="modified"?"Modified":F.action==="deleted"?"Deleted":"Read";if(C.push({id:`modified-${F.filePath}-${F.timestamp}`,type:"modified-file",title:B,subtitle:`${L} by ${F.agentName} • ${F.filePath}`,matchedText:F.filePath,icon:F.action==="deleted"?f.jsx(ne,{name:"trash",size:16}):kt(F.filePath),action:()=>{w.current();const k=Array.from(J.getState().areas.values());for(const P of k)for(const U of P.directories||[])if(F.filePath.startsWith(U)){J.setFileViewerPath(F.filePath),W.current(P.id);return}J.selectAgent(F.agentId)}}),C.length>=50)break}return C},[t,g]),Oe=d.useMemo(()=>t?X.map(s=>{const p=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:p,matchedText:s.path,icon:f.jsx(ne,{name:s.isGitRepo?"git-branch":"folder",size:16}),_searchText:`${s.name} ${s.path}`,_isGitRepo:s.isGitRepo,_gitBranch:s.gitBranch,action:()=>{w.current(),J.openFileExplorer(s.path)}}}):[],[t,X]),ze=d.useMemo(()=>new Z(he,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[he]),Ge=d.useMemo(()=>new Z(pe,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[pe]),Qe=d.useMemo(()=>new Z(Ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Ae]),We=d.useMemo(()=>new Z(Ke,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ke]),He=d.useMemo(()=>new Z(ye,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ye]),de=d.useMemo(()=>{if(!D.trim()){const A=[];A.push(...ye);const I=[...he].sort((b,K)=>{const te=Ee(b._agentId,b._lastActivity,ge);return Ee(K._agentId,K._lastActivity,ge)-te});A.push(...I),A.push(...pe.slice(0,2)),A.push(...Ae.slice(0,2));const _={};return Es.forEach((b,K)=>{_[b]=K}),A.sort((b,K)=>(_[b.type]??999)-(_[K.type]??999)),A}const s=D.trim().toLowerCase(),p=ze.search(D).slice(0,8),C=Ge.search(D).slice(0,3),F=Qe.search(D).slice(0,2),B=We.search(D).slice(0,3),L=Oe.slice(0,8),k=He.search(D).filter(A=>{const I=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(s)||I<=.2}).slice(0,4),P={agent:6,building:5,folder:4,command:3,area:2,"modified-file":1},U=A=>{if(!s)return 1;const I=A.title.toLowerCase();return I===s?6:I.startsWith(s)?5:I.split(/[^a-z0-9]+/i).includes(s)?4:I.includes(s)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(s)?2:1},Y=(A,I)=>{const _=(1-Math.min(1,I??1))*4;return U(A)*100+(P[A.type]??0)*5+_},ue=new Map,ee=(A,I)=>{const _=ue.get(A.type),b={item:A,score:Y(A,I)};_?_.push(b):ue.set(A.type,[b])};for(const A of p){const I={...A.item};if(I._modifiedFiles&&I._modifiedFiles.length>0){const _=I._modifiedFiles.filter(b=>{var se;const K=((se=b.split("/").pop())==null?void 0:se.toLowerCase())||"",te=b.toLowerCase();return K.includes(s)||te.includes(s)});_.length>0&&(I.matchedFiles=_)}if(I._userQueries&&I._userQueries.length>0){const _=I._userQueries.find(b=>b.toLowerCase().includes(s));if(_)if(_.length>200){const K=_.toLowerCase().indexOf(s),te=Math.max(0,K-60),se=Math.min(_.length,K+s.length+100);I.matchedQuery=(te>0?"...":"")+_.slice(te,se)+(se<_.length?"...":"")}else I.matchedQuery=_}ee(I,A.score)}for(const A of k)ee(A.item,A.score);for(const A of C)ee(A.item,A.score);for(const A of F)ee(A.item,A.score);for(const A of B)ee(A.item,A.score);for(const A of L)ee(A,void 0);for(const[A,I]of ue)A==="agent"?I.sort((_,b)=>{const K=U(_.item),te=U(b.item);if(te!==K)return te-K;const se=Ee(_.item._agentId,_.item._lastActivity,ge),Ye=Ee(b.item._agentId,b.item._lastActivity,ge);return Ye!==se?Ye-se:b.score-_.score}):I.sort((_,b)=>b.score-_.score);const z=A=>A.reduce((I,_)=>Math.max(I,_.score),-1),Ue=[];return Array.from(ue.values()).sort((A,I)=>z(I)-z(A)).forEach(A=>{for(const I of A)Ue.push(I.item)}),Ue},[D,ze,Ge,Qe,We,He,pe,he,Ae,ye,Oe,ge]),V=d.useMemo(()=>{switch(M){case"agents":return de.filter(s=>s.type==="agent");case"buildings":return de.filter(s=>s.type==="building");case"commands":return de.filter(s=>s.type==="command");case"folders":return de.filter(s=>s.type==="folder");case"areas":return ve.flatMap(s=>s.agents);case"all":default:return de}},[M,de,ve]);d.useEffect(()=>{H>=V.length&&v(Math.max(0,V.length-1))},[V.length,H]);const mt=d.useCallback(s=>{if(s.altKey&&!s.ctrlKey&&!s.metaKey&&(s.key==="p"||s.key==="n"||s.key==="P"||s.key==="N")){s.preventDefault(),s.stopPropagation(),s.nativeEvent.stopImmediatePropagation();const p=s.key.toLowerCase();v(p==="p"?C=>C>0?C-1:V.length-1:C=>C<V.length-1?C+1:0);return}switch(s.key){case"Escape":s.preventDefault(),w.current();break;case"ArrowUp":s.preventDefault(),v(p=>p>0?p-1:V.length-1);break;case"ArrowDown":s.preventDefault(),v(p=>p<V.length-1?p+1:0);break;case"Enter":s.preventDefault(),V[H]&&V[H].action();break}},[V,H]),pt=d.useCallback((s,p)=>{if(!p||!s)return s;const C=s.toLowerCase(),F=p.toLowerCase(),B=[];let L=0,k=C.indexOf(F),P=0;for(;k!==-1;)k>L&&B.push(s.slice(L,k)),B.push(Be.createElement("mark",{key:P++,className:"spotlight-highlight"},s.slice(k,k+p.length))),L=k+p.length,k=C.indexOf(F,L);return L<s.length&&B.push(s.slice(L)),B.length>0?Be.createElement(Be.Fragment,null,...B):s},[]);return{query:D,setQuery:ft,selectedIndex:H,setSelectedIndex:v,results:V,activeTab:M,setActiveTab:we,cycleTab:gt,areaSections:ve,handleKeyDown:mt,highlightMatch:pt}}const ws=d.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:c},i){const{t:o}=Fe(["common"]);return f.jsxs("div",{className:"spotlight-input-wrapper",children:[f.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),f.jsx("input",{ref:i,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{n(a.target.value),c()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),f.jsxs("div",{className:"spotlight-input-hints",children:[f.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Ss=d.memo(function({activeTab:e,onSelect:n}){const{t:r}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[fe.map(c=>f.jsx("button",{type:"button",role:"tab","aria-selected":c===e,tabIndex:-1,className:`spotlight-tab${c===e?" active":""}`,onClick:()=>n(c),children:r(`terminal:spotlight.tabs.${c}`)},c)),f.jsx("span",{className:"spotlight-tabs-hint",children:f.jsx("kbd",{children:"Tab"})})]})}),vs=d.forwardRef(function({results:e,selectedIndex:n,query:r,activeTab:c,areaSections:i,highlightMatch:o,onSelectIndex:a},u){const{t:l}=Fe(["terminal"]),h=d.useRef(!1);d.useEffect(()=>{h.current=!1},[e]),d.useEffect(()=>{const g=typeof u=="function"?null:u==null?void 0:u.current;if(!g)return;const m=()=>{h.current=!0};return g.addEventListener("mousemove",m),()=>{g.removeEventListener("mousemove",m)}},[u,e]);const E={command:l("terminal:spotlight.categories.commands"),agent:l("terminal:spotlight.categories.agents"),building:l("terminal:spotlight.categories.infrastructure"),area:l("terminal:spotlight.categories.areas"),folder:l("terminal:spotlight.categories.folders"),"modified-file":l("terminal:spotlight.categories.modifiedFiles")},x=d.useMemo(()=>{const g=[];let m=null,S=[];return e.forEach((w,T)=>{w.type!==m&&(m!==null&&S.length>0&&g.push([m,S]),m=w.type,S=[]),S.push({result:w,index:T})}),m!==null&&S.length>0&&g.push([m,S]),g},[e]);if(d.useEffect(()=>{if(!u||typeof u=="function")return;const g=u.current;if(!g)return;const m=g.querySelector(".spotlight-item.selected");m&&m.scrollIntoView({block:"nearest",behavior:"smooth"})},[n,u]),c==="areas"){if(i.length===0)return f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})});let g=0;return f.jsx("div",{className:"spotlight-results",ref:u,children:i.map(m=>f.jsxs("div",{children:[f.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[f.jsx("span",{className:"spotlight-area-dot",style:{background:m.areaColor},"aria-hidden":"true"}),f.jsx("span",{className:"spotlight-area-name",children:m.areaName}),f.jsx("span",{className:"spotlight-area-count",children:m.agents.length})]}),m.agents.length===0?f.jsx("div",{className:"spotlight-area-empty",children:l("terminal:spotlight.noAgentsInArea")}):m.agents.map(S=>{const w=g++;return f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id)})]},m.areaId))})}return e.length===0?f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})}):f.jsx("div",{className:"spotlight-results",ref:u,children:x.map(([g,m])=>f.jsxs("div",{children:[x.length>1&&f.jsx("div",{className:"spotlight-category-header",children:E[g]||g}),m.map(({result:S,index:w})=>f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id))]},g))})}),Bs=d.memo(function(){const{t:e}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-footer",children:[f.jsxs("div",{className:"spotlight-footer-left",children:[f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"↑"}),f.jsx("kbd",{children:"↓"})," ",f.jsx("kbd",{children:"Alt+N"}),f.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),f.jsx("div",{className:"spotlight-footer-right",children:f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Is=768;function Rs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=d.useRef(null),E=d.useRef(null),x=d.useRef(null),g=d.useRef(0),{query:m,setQuery:S,selectedIndex:w,setSelectedIndex:T,results:j,activeTab:Q,setActiveTab:W,cycleTab:oe,areaSections:ce,handleKeyDown:$,highlightMatch:N}=Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});g.current=j.length;const D=d.useRef(oe);D.current=oe,d.useEffect(()=>{t&&setTimeout(()=>{var v,M;(v=h.current)==null||v.focus(),(M=h.current)==null||M.select()},50)},[t]),d.useEffect(()=>{if(!t)return;const v=window.visualViewport;if(!v||window.innerWidth>Is)return;const M=()=>{const R=E.current;R&&(R.style.height=`${v.height}px`,R.style.top=`${v.offsetTop}px`)};return M(),v.addEventListener("resize",M),v.addEventListener("scroll",M),()=>{v.removeEventListener("resize",M),v.removeEventListener("scroll",M);const R=E.current;R&&(R.style.height="",R.style.top="")}},[t]),d.useEffect(()=>{if(!t)return;const v=M=>{if(M.key==="Escape"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),e();return}if(M.key==="Tab"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),D.current(M.shiftKey?-1:1);return}if(M.altKey&&!M.ctrlKey&&!M.metaKey&&(M.key==="n"||M.key==="p"||M.key==="N"||M.key==="P")){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation();const R=M.key.toLowerCase(),X=g.current;T(R==="p"?O=>O>0?O-1:X-1:O=>O<X-1?O+1:0);return}};return window.addEventListener("keydown",v,{capture:!0}),()=>{window.removeEventListener("keydown",v,{capture:!0})}},[t,e]);const ae=d.useCallback(v=>{v.target===v.currentTarget&&e()},[e]),H=d.useCallback(()=>{T(0)},[T]);return t?f.jsx("div",{ref:E,className:"spotlight-overlay",onClick:ae,children:f.jsxs("div",{className:"spotlight-modal",children:[f.jsx(ws,{ref:h,query:m,onQueryChange:S,onKeyDown:$,onResetSelection:H}),f.jsx(Ss,{activeTab:Q,onSelect:W}),f.jsx(vs,{ref:x,results:j,selectedIndex:w,query:m,activeTab:Q,areaSections:ce,highlightMatch:N,onSelectIndex:T}),f.jsx(Bs,{})]})}):null}export{Ls as FILE_ICON_NAMES,Rs as Spotlight,Bs as SpotlightFooter,ws as SpotlightInput,Je as SpotlightItem,vs as SpotlightResults,$s as formatDuration,js as formatRelativeTime,Ns as getAgentIcon,kt as getFileIconFromPath,Ps as getTypeLabel,Fs as useSpotlightSearch};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-
|
|
2
|
-
import{cD as e,bL as o}from"./main-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-DcEvjmf6.js","assets/main-BVsJe5cx.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-Ba3wdQK_.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{cD as e,bL as o}from"./main-BVsJe5cx.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";var i;(function(r){r.Heavy="HEAVY",r.Medium="MEDIUM",r.Light="LIGHT"})(i||(i={}));var t;(function(r){r.Success="SUCCESS",r.Warning="WARNING",r.Error="ERROR"})(t||(t={}));const c=e("Haptics",{web:()=>o(()=>import("./web-DcEvjmf6.js"),__vite__mapDeps([0,1,2,3,4])).then(r=>new r.HapticsWeb)});export{c as Haptics,i as ImpactStyle,t as NotificationType};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as a,B as mn,E as Bt,G as Zt,H as Jt,j as e,J as Qt,K as fn,u as Rt,L as hn,M as gn,N as xn,O as bn,V as _n,P as wn,U as vn,W as Ft,S,X as Wt,Y as Dt,Z as Ht,_ as xt,$ as ge,a0 as Cn,s as b,a1 as en,a2 as tn,a3 as jn,w as Ut,x as Vt,I as p,a4 as Nn,n as kn,a5 as yn,a6 as nn,a7 as an,a8 as An,a9 as Sn,aa as En,ab as Mn,ac as In,ad as Tn,ae as Pn,af as Ln,ag as Dn,ah as Rn,ai as $n,aj as zn,ak as Xt,C as On,al as Bn,am as Gt,an as Fn,ao as Wn,ap as Hn,aq as Un,ar as Vn,as as Xn,at as Gn,au as qn,av as Yn,aw as Kn,ax as Zn,ay as Jn,az as Qn,aA as ea,aB as ta,aC as na,aD as aa,aE as sa}from"./main-rDQDtv_U.js";import{g as ia}from"./area-logos-aaW_jqzI.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function la(u){const r=a.useRef(u);r.current=u,a.useEffect(()=>{if(!mn())return;let m=null,h=!1;return Bt.addListener("backButton",()=>{r.current()==="exit"&&Bt.exitApp()}).then(N=>{h?N.remove():m=N}),()=>{h=!0,m&&(m.remove(),m=null)}},[])}async function ra(u){const r=Zt(),m=await fetch(`${Jt()}/api/agents/${u}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!m.ok){const h=await m.json().catch(()=>({}));throw new Error((h==null?void 0:h.error)||`Failed to start terminal (${m.status})`)}return m.json()}async function oa(u){const r=Zt();await fetch(`${Jt()}/api/agents/${u}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const at=new Map;function ca({agentId:u}){const[r,m]=a.useState(null),[h,N]=a.useState(null);return a.useEffect(()=>{let P=!1;const M=at.get(u);return M&&(clearTimeout(M),at.delete(u)),m(null),N(null),ra(u).then(L=>{P||m(L.url)}).catch(L=>{P||N(L instanceof Error?L.message:"Failed to start terminal")}),()=>{P=!0;const L=at.get(u);L&&clearTimeout(L),at.set(u,setTimeout(()=>{at.delete(u),oa(u)},2500))}},[u]),h?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:h})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(Qt,{terminalUrl:r,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Pt=new Map,da=6e4;function ua({agentId:u,contextSummary:r}){const{t:m}=Rt(["terminal","common"]),[h,N]=a.useState(()=>{var I;return((I=Pt.get(u))==null?void 0:I.snapshot)??null}),[P,M]=a.useState(!1),[L,G]=a.useState(null),_=a.useRef(0);a.useEffect(()=>{const I=Pt.get(u);if(I&&Date.now()-I.fetchedAt<da){N(I.snapshot);return}const W=++_.current;M(!0),G(null),hn(u).then(U=>{W===_.current&&(Pt.set(u,{snapshot:U,fetchedAt:Date.now()}),N(U),M(!1))}).catch(U=>{W===_.current&&(G(U.message||"Failed to load plan limits"),M(!1))})},[u]);const D=[];if(h!=null&&h.rateLimits){const I=[{key:"fiveHour",label:m("terminal:usage.currentSession"),window:h.rateLimits.fiveHour},{key:"sevenDay",label:m("terminal:usage.currentWeekAll"),window:h.rateLimits.sevenDay},{key:"sevenDayOpus",label:m("terminal:usage.currentWeekOpus"),window:h.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:m("terminal:usage.currentWeekSonnet"),window:h.rateLimits.sevenDaySonnet}];for(const W of I)W.window&&D.push({...W,window:W.window})}return e.jsxs("div",{className:"plan-limits-tooltip",children:[r&&e.jsx("div",{className:"plan-limits-tooltip__context",children:r}),e.jsx("div",{className:"plan-limits-tooltip__title",children:m("terminal:usage.limits")}),P&&!h&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[m("common:status.loading"),"…"]}),!P&&L&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:m("terminal:usage.limitsError",{message:L})}),D.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:D.map(({key:I,label:W,window:U})=>{const xe=Math.max(0,Math.min(100,U.utilization)),Z=xn(xe);return e.jsxs("div",{className:"plan-limits-tooltip__gauge",children:[e.jsxs("div",{className:"plan-limits-tooltip__gauge-head",children:[e.jsx("span",{className:"plan-limits-tooltip__gauge-label",children:W}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:Z},children:m("terminal:usage.percentUsed",{percent:Math.round(xe)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${xe}%`,background:Z}})}),e.jsx("div",{className:"plan-limits-tooltip__reset",children:m("terminal:usage.resets",{time:gn(U.resetsAt)})})]},I)})}):h&&!P&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?m("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function pa({agentId:u,disabled:r,contextSummary:m,children:h}){return e.jsx(fn,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(ua,{agentId:u,contextSummary:m}),children:h})}const ma=a.memo(function({className:r=""}){const{t:m}=Rt(["common"]),[h,N]=bn(),P=a.useRef(null),[M,L]=a.useState(null);a.useLayoutEffect(()=>{const _=P.current;if(!_)return;const D=_.querySelector(".view-mode-toggle__btn--active");D&&L({left:D.offsetLeft,width:D.offsetWidth})},[h]);const G=a.useCallback(_=>{if(_!==h){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:_}})),_==="3d"){requestAnimationFrame(()=>N(_));return}N(_)}},[h,N]);return e.jsxs("div",{className:`view-mode-toggle ${r}`,ref:P,children:[M&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:M.left,width:M.width}}),_n.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>G(_),title:m(`common:viewMode.descriptions.${_}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[_==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),_==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),_==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),_==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:m(`common:viewMode.labels.${_}`)})]},_))]})}),bt=3,_t=280,qt=320,Lt=240,Yt=64,fa=["simple","chat","advanced"],ha={simple:"Simple",chat:"Chat",advanced:"Advanced"},ga={simple:"○",chat:"◐",advanced:"◉"},xa={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Kt="flat-clear-context";function ba(u){const r=u.split("/").filter(Boolean);return r.length===0?u:r.slice(-2).join("/")}function _a(u){if(u.provider==="codex"){const P=u.codexModel||"gpt-5.3-codex",M=na[P];return{model:(M==null?void 0:M.label)||P}}if(u.provider==="opencode")return{model:u.opencodeModel||"opencode"};const r=u.model||"sonnet",m=sa[r],h=u.effort,N=h?aa[h]:void 0;return{model:(m==null?void 0:m.label)||r,effort:N==null?void 0:N.label}}function wa(u,r){if(r.type==="rectangle"&&r.width&&r.height){const m=r.width/2,h=r.height/2;return u.x>=r.center.x-m&&u.x<=r.center.x+m&&u.z>=r.center.z-h&&u.z<=r.center.z+h}if(r.type==="circle"&&r.radius){const m=u.x-r.center.x,h=u.z-r.center.z;return m*m+h*h<=r.radius*r.radius}return!1}const va=Bn.memo(function({agentId:r,terminalViewMode:m,onTerminalViewModeChange:h,inspectorOpen:N,onToggleInspector:P,onImageClick:M,onFileClick:L,onBashClick:G,onViewMarkdown:_,onRequestClearSubordinates:D,onOpenBuilding:I,keyboard:W,canNavigateBack:U,canNavigateForward:xe,onNavigateBack:Z,onNavigateForward:be,agentInfoOpen:Ee,onToggleAgentInfo:st,onHeaderContextMenu:ae,onBuildingContextMenu:_e}){var ut,pt,K,Ye;const f=Gt(r),H=tn(),we=Fn(),Me=a.useRef(null),We=a.useRef(null),{displayedAgentId:ve,fadingOut:wt}=Wn(r),it=Gt(ve),He=!!we.interactiveMode&&((f==null?void 0:f.provider)??"claude")==="claude"&&!!(f!=null&&f.sessionId),[J,Ue]=a.useState(!1);a.useEffect(()=>{Ue(!1)},[r]),a.useEffect(()=>{!He&&J&&Ue(!1)},[He,J]),a.useEffect(()=>{const s=We.current;if(!s)return;const l=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),Z()):d.button===4&&(d.preventDefault(),d.stopPropagation(),be())},c=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return s.addEventListener("mouseup",l),s.addEventListener("mousedown",c),()=>{s.removeEventListener("mouseup",l),s.removeEventListener("mousedown",c)}},[Z,be]),a.useEffect(()=>{const s=We.current;if(!s)return;let l=0,c=0,d=0;const Se=250,ze=600,Ke=80,he=1.5,Et=X=>{let $=X instanceof HTMLElement?X:null;for(;$&&$!==s;){const Ze=window.getComputedStyle($).overflowX;if((Ze==="auto"||Ze==="scroll")&&$.scrollWidth>$.clientWidth)return!0;$=$.parentElement}return!1},Oe=X=>{const $=Date.now();if($<d){X.preventDefault();return}if(Math.abs(X.deltaX)<=Math.abs(X.deltaY)*he){l=0;return}if(Et(X.target)){l=0;return}$-c>Se&&(l=0),c=$,l+=X.deltaX,l<=-Ke?(l=0,d=$+ze,X.preventDefault(),Z()):l>=Ke&&(l=0,d=$+ze,X.preventDefault(),be())};return s.addEventListener("wheel",Oe,{passive:!1}),()=>s.removeEventListener("wheel",Oe)},[Z,be]);const Ce=en(),se=a.useMemo(()=>{if(!f)return null;const s=new Set,l=[];for(const c of Ce.values())c.archived||c.directories.length===0||c.assignedAgentIds.includes(r)&&(s.add(c.id),l.push(c));for(const c of Ce.values())c.archived||c.directories.length===0||s.has(c.id)||wa({x:f.position.x,z:f.position.z},c)&&(s.add(c.id),l.push(c));return l.length===0?null:l.flatMap(c=>c.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:c.id,areaName:c.name,dir:d})))},[f,r,Ce]),{branches:ie,fetchRemote:le,fetchingDirs:lt}=Hn(se),Ve=a.useMemo(()=>{var c;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const d of H.values())d.type==="terminal"&&b.isPositionInArea(d.position,s)&&l.push({id:d.id,name:d.name,hasUrl:!!((c=d.terminalStatus)!=null&&c.url)});return l},[r,H]),Ie=a.useMemo(()=>{var c;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const d of H.values())d.type==="server"&&((c=d.pm2)!=null&&c.enabled)&&b.isPositionInArea(d.position,s)&&l.push({id:d.id,name:d.name});return l},[r,H]),je=a.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const c of H.values())c.type==="database"&&c.database&&b.isPositionInArea(c.position,s)&&l.push({id:c.id,name:c.name});return l},[r,H]),Ne=Un(),Te=a.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const c of H.values())if(c.type==="tests"&&b.isPositionInArea(c.position,s)){const d=!!c.folderPath&&Ne.some(Se=>Vn(Se,c.folderPath));l.push({id:c.id,name:c.name,working:d})}return l},[r,H,Ne]),[,Q]=a.useReducer(s=>s+1,0),re=((ut=Me.current)==null?void 0:ut.search.searchMode)??!1,ke=a.useCallback(()=>{var s;(s=Me.current)==null||s.search.toggleSearch(),Q()},[]),oe=Xn(),Je=oe.isPending(Kt),[ye,Pe]=a.useState(null),q=ye?H.get(ye):null,{height:vt,onResizeStart:Ct}=Gn(),{sidePanelWidth:Le,handleSidePanelResizeStart:jt}=qn(),[Ae,rt]=a.useState(()=>Dt(S.GIT_PANEL_OPEN,!1)),[ce,ot]=a.useState(()=>Dt(S.BUILDINGS_PANEL_OPEN,!1)),[De,ct]=a.useState(!1),Nt=a.useCallback(()=>{ct(s=>{const l=!s;return l&&Yn.setEnabled(!0),l})},[]),kt=a.useCallback(()=>ct(!1),[]),yt=a.useCallback(()=>{rt(s=>{const l=!s;return ge(S.GIT_PANEL_OPEN,l),l})},[]),Xe=a.useCallback(()=>{ot(s=>{const l=!s;return ge(S.BUILDINGS_PANEL_OPEN,l),l})},[]),v=a.useCallback(()=>{rt(!1),ge(S.GIT_PANEL_OPEN,!1)},[]),de=a.useCallback(()=>{ot(!1),ge(S.BUILDINGS_PANEL_OPEN,!1)},[]),Y=Kn();a.useEffect(()=>{if(!ye)return;Ve.some(l=>l.id===ye)||Pe(null)},[ye,Ve]);const[ee,ue]=a.useState(!1),Qe=a.useRef(null);if(a.useEffect(()=>{if(!ee)return;const s=l=>{Qe.current&&!Qe.current.contains(l.target)&&ue(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[ee]),!f)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const pe=f.contextStats,et=!!pe,dt=pe?pe.totalTokens:f.contextUsed||0,Ge=pe?pe.contextWindow:f.contextLimit||2e5,Re=pe?pe.usedPercent:Math.round(dt/Ge*100),te=Math.max(0,Math.min(100,Re)),me=Math.round(te*10)/10,At=Math.round((100-te)*10)/10,V=te>=80?"#ff4a4a":te>=60?"#ff9e4a":te>=40?"#ffd700":"#4aff9e",ne=(dt/1e3).toFixed(1),tt=(Ge/1e3).toFixed(1),fe=f.cwd,qe=fe?ba(fe):null,$e=((pt=f.subordinateIds)==null?void 0:pt.length)||0,St=$e>0;return e.jsxs("div",{ref:We,className:`flat-terminal-wrapper ${Ae||ce||De?"flat-terminal-wrapper--with-side-panel":""} ${wt?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${Le}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Ee?"flat-terminal-wrapper__header-main--active":""}`,onClick:st,onContextMenu:s=>{s.preventDefault(),s.stopPropagation(),ae({x:s.clientX,y:s.clientY})},title:Ee?"Hide agent info":"Show agent info","aria-pressed":Ee,children:[e.jsx(nn,{agent:f,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:an(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:f.provider==="codex"?"/assets/codex.png":f.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:f.provider==="codex"?"Codex Agent":f.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:s,effort:l}=_a(f);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:l?`Model: ${s} · Effort: ${l}`:`Model: ${s}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:s}),l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:l})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsxs("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:[fa.map(s=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!J&&m===s?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Ue(!1),h(s)},title:xa[s],"aria-pressed":!J&&m===s,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:ga[s]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:ha[s]})]},s)),He&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${J?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Ue(s=>!s),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":J,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(p,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:Z,disabled:!U,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(p,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:be,disabled:!xe,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(p,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${re?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ke,title:re?"Close search":"Search messages","aria-pressed":re,children:e.jsx(p,{name:re?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Je?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>oe.handleClick(Kt,()=>{var s;b.clearContext(r),(s=Me.current)==null||s.historyLoader.clearHistory()}),title:Je?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:Je?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Ae?"flat-terminal-wrapper__action-btn--active":""}`,onClick:yt,title:Ae?"Hide git panel":"Show git changes","aria-pressed":Ae,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ce?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Xe,title:ce?"Hide buildings panel":"Show area buildings","aria-pressed":ce,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Qe,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ee?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>ue(s=>!s),title:"More actions","aria-expanded":ee,children:"⋮"}),ee&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${De?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Nt(),ue(!1)},title:De?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:De?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{b.collapseContext(r),ue(!1)},disabled:f.status!=="idle",title:f.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(p,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),St&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{D(r,$e),ue(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",$e," subordinate",$e===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{b.killAgent(r),ue(!1)},children:[e.jsx(p,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${N?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:P,title:N?"Hide inspector panel":"Show inspector panel","aria-label":N?"Hide inspector panel":"Show inspector panel","aria-pressed":N,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>b.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(p,{name:"cross",size:14})})]})]}),J&&He?e.jsx(ca,{agentId:r}):ve&&it?e.jsx(Zn,{ref:Me,agentId:ve,agent:it,viewMode:m,isOpen:!0,onImageClick:M,onFileClick:L,onBashClick:G,onViewMarkdown:_,keyboard:W,hasModalOpen:!1},ve):null,q&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Ct,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${q.name}`,style:{height:vt},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(p,{name:"terminal",size:12}),e.jsx("span",{children:q.name}),!((K=q.terminalStatus)!=null&&K.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>Pe(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(p,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(Ye=q.terminalStatus)!=null&&Ye.url?e.jsx(Qt,{terminalUrl:q.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(p,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),fe&&qe&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${fe}`,"aria-label":`Open ${fe} in file explorer`,role:"button",tabIndex:0,onClick:()=>b.openFileExplorer(fe),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b.openFileExplorer(fe))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(p,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:qe})]}),se&&se.map(({areaId:s,areaName:l,dir:c})=>{const d=ie.get(c),Se=lt.has(c),ze=c.split("/").filter(Boolean).pop()||c;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${l}: ${c}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>b.openFileExplorerForAreaFolder(s,c),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:ze}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",d.branch]}),d.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${d.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),d.ahead]}),d.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${d.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Se?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Ke=>{Ke.stopPropagation(),le(c)},children:e.jsx(p,{name:Se?"hourglass":"download",size:12})})]})]},`${s}:${c}`)}),e.jsx(pa,{agentId:r,disabled:((f==null?void 0:f.provider)??"claude")!=="claude",contextSummary:et?`Context: ${ne}k / ${tt}k tokens (${me}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>b.setContextModalAgentId(r),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b.setContextModalAgentId(r))},title:((f==null?void 0:f.provider)??"claude")!=="claude"?et?`Context usage: ${ne}k / ${tt}k tokens (${me}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(p,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${te}%`,backgroundColor:V}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:V},children:[ne,"k/",tt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",At,"% free)"]}),!et&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(p,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),Ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:Ve.map(s=>{const l=ye===s.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${l?"flat-terminal-wrapper__building-btn--active":""} ${s.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${l?"Hide":"Show"} terminal: ${s.name}${s.hasUrl?"":" (starting...)"}`,onClick:()=>{if(l){Pe(null);return}s.hasUrl||b.sendBuildingCommand(s.id,"start"),Pe(s.id)},onContextMenu:c=>{c.preventDefault(),c.stopPropagation(),_e(s.id,{x:c.clientX,y:c.clientY})},children:e.jsx(p,{name:"terminal",size:14})},s.id)})}),Ie.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Ie.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"scroll",size:14})},s.id))}),je.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:je.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"hard-drives",size:14})},s.id))}),Te.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:Te.map(s=>e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${s.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:s.working?`Running tests: ${s.name}`:`Open tests: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"flask",size:14})},s.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Jn,{})})]}),Ae&&e.jsx(Qn,{agentId:r,agents:Y,onClose:v,branchInfoMap:ie,fetchRemote:le,fetchingDirs:lt,onResizeStart:s=>jt(s,"right")}),ce&&e.jsx(ea,{agentId:r,onClose:de}),De&&e.jsx(ta,{agentId:r,onClose:kt})]})});function ya({onAgentClick:u,onBuildingClick:r,onBuildingDoubleClick:m,onBuildingPopup:h,onAreaContextMenu:N,onOpenSpawnModal:P,onOpenBossSpawnModal:M,onOpenAreaModal:L}){const{t:G}=Rt(["common"]),_=wn(),D=vn(),[I,W]=a.useState(null),[U,xe]=a.useState(null),[Z,be]=a.useState(null),[Ee,st]=a.useState(null),[ae,_e]=a.useState(null),[f,H]=a.useState(null),[we,Me]=a.useState(null),[We,ve]=a.useState(!1),wt=a.useCallback(()=>{ve(t=>!t)},[]),it=a.useCallback(()=>{ve(!1)},[]),[He,J]=a.useState(()=>{const t=Ft(S.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ue=a.useCallback(t=>{J(t),Wt(S.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==S.VIEW_MODE)return;const i=n.newValue;(i==="simple"||i==="chat"||i==="advanced")&&J(i)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[Ce,se]=a.useState(()=>Dt(S.FLAT_INSPECTOR_OPEN,!1)),[ie,le]=a.useState(!1),lt=a.useCallback(()=>le(t=>!t),[]),Ve=a.useCallback(()=>le(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:ie}}))},[ie]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:Ce}}))},[Ce]),a.useEffect(()=>{const t=()=>le(C=>!C),n=()=>{se(C=>{const k=!C;return ge(S.FLAT_INSPECTOR_OPEN,k),k})},i=()=>{le(!1),se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)},g=()=>le(!1),x=()=>{se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",i),window.addEventListener("tide-close-flat-agents-drawer-only",g),window.addEventListener("tide-close-flat-inspector-only",x),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",i),window.removeEventListener("tide-close-flat-agents-drawer-only",g),window.removeEventListener("tide-close-flat-inspector-only",x)}},[]);const Ie=a.useRef(null),je=a.useRef(null),[Ne,Te]=a.useState(()=>{const t=Ht(S.FLAT_MIDDLE_WIDTH,0);return t>=_t?t:null}),[Q,re]=a.useState(()=>{const t=Ht(S.FLAT_INSPECTOR_WIDTH,0);return t>=Lt?t:null}),ke=a.useCallback(t=>{if(typeof window>"u")return t;const n=Q!==null?bt+Q:0,i=window.innerWidth-Yt-bt-qt-n;return Math.max(_t,Math.min(Math.max(i,_t),t))},[Q]),oe=a.useCallback(t=>{var x;if(typeof window>"u")return t;const n=(x=Ie.current)==null?void 0:x.querySelector(".flat-middle"),i=(n==null?void 0:n.getBoundingClientRect().width)??_t,g=window.innerWidth-Yt-i-bt-qt-bt;return Math.max(Lt,Math.min(Math.max(g,Lt),t))},[]);a.useEffect(()=>{if(Ne===null&&Q===null)return;const t=()=>{Te(n=>{if(n===null)return n;const i=ke(n);return i===n?n:i}),re(n=>{if(n===null)return n;const i=oe(n);return i===n?n:i})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[Ne,Q,ke,oe]);const Je=a.useCallback(t=>{var i;if(t.button!==0)return;const n=(i=Ie.current)==null?void 0:i.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),je.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),ye=a.useCallback(t=>{var i;if(t.button!==0)return;const n=(i=Ie.current)==null?void 0:i.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),je.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Pe=a.useCallback(t=>{const n=je.current;if(!n||t.pointerId!==n.pointerId)return;const i=t.clientX-n.startX;n.kind==="middle"?Te(ke(n.startWidth+i)):re(oe(n.startWidth-i))},[ke,oe]),q=a.useCallback(t=>{const n=je.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(je.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const g=t.clientX-n.startX;if(n.kind==="middle"){const x=ke(n.startWidth+g);Te(x),xt(S.FLAT_MIDDLE_WIDTH,x)}else{const x=oe(n.startWidth-g);re(x),xt(S.FLAT_INSPECTOR_WIDTH,x)}},[ke,oe]),vt=a.useCallback(()=>{Te(null),xt(S.FLAT_MIDDLE_WIDTH,0)},[]),Ct=a.useCallback(()=>{re(null),xt(S.FLAT_INSPECTOR_WIDTH,0)},[]),[Le,jt]=a.useState(()=>Ft(S.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Ae=a.useCallback(t=>{jt(t),Wt(S.FLAT_INSPECTOR_VIEW,t)},[]),rt=a.useCallback(()=>{se(t=>{const n=!t;return ge(S.FLAT_INSPECTOR_OPEN,n),n})},[]),ce=a.useCallback(()=>{se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)},[]),ot=Cn(),De=a.useCallback((t,n)=>{W({url:t,name:n})},[]),ct=a.useCallback((t,n)=>{xe({command:t,output:n,isLive:!1})},[]),Nt=a.useCallback((t,n)=>{var x;const i=D.size>0?Array.from(D)[0]:null,g=i?(x=b.getState().agents.get(i))==null?void 0:x.cwd:void 0;b.setFileViewerPath(t,n,g)},[D]),kt=a.useCallback(t=>{be(t)},[]),yt=a.useCallback((t,n)=>{st({agentId:t,count:n})},[]),Xe=a.useCallback(t=>{m?m(t):r(t)},[r,m]),v=a.useMemo(()=>D.size>0?Array.from(D)[0]:null,[D]);a.useEffect(()=>{ve(!1)},[v]);const de=a.useRef([]),Y=a.useRef(-1),ee=a.useRef(!1),ue=a.useRef(null),[Qe,pe]=a.useState(!1),[et,dt]=a.useState(!1),Ge=a.useRef(!1),Re=a.useRef(null),te=a.useRef(!1),me=a.useMemo(()=>new Set(_.map(t=>t.id)),[_]),At=a.useMemo(()=>{const t=new Map(_.map(i=>[i.id,i])),n=new Map;for(const i of _)if((i.isBoss||i.class==="boss")&&i.subordinateIds&&i.subordinateIds.length>0){const g=i.subordinateIds.map(x=>t.get(x)).filter(x=>x!==void 0);g.length>0&&n.set(i.id,g)}return n},[_]),V=a.useCallback(()=>{const t=de.current,n=Y.current;pe(n>0),dt(n>=0&&n<t.length-1)},[]),ne=a.useCallback(t=>{const n=de.current;if(n.length===0)return;let i=Y.current+t;for(;i>=0&&i<n.length;){const g=n[i];if(me.has(g)){ee.current=!0,Y.current=i,V(),b.selectAgent(g);return}i+=t}},[me,V]),tt=a.useCallback(()=>ne(-1),[ne]),fe=a.useCallback(()=>ne(1),[ne]);la(a.useCallback(()=>{const t=de.current,n=Y.current;return t.length>0&&n>0?(ne(-1),"handled"):"exit"},[ne]));const qe=a.useCallback((t,n)=>{if(typeof window>"u")return;const i=window.history.state,x={...typeof i=="object"&&i!==null?i:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(x,"",window.location.href):window.history.pushState(x,"",window.location.href)},[]);a.useEffect(()=>{if(!v){Ge.current=!1,Re.current=null;return}if(!Ge.current){qe(v,"replace"),Ge.current=!0,Re.current=v;return}if(te.current){te.current=!1,Re.current=v;return}Re.current!==v&&(qe(v,"push"),Re.current=v)},[v,qe]),a.useEffect(()=>{const t=n=>{var C,k;const i=(k=(C=n.state)==null?void 0:C.__flatAgentNav)==null?void 0:k.agentId;if(!i||typeof i!="string"||!me.has(i)||i===v)return;te.current=!0,ee.current=!0;const g=de.current,x=g.lastIndexOf(i);x>=0?Y.current=x:(g.push(i),Y.current=g.length-1),V(),b.selectAgent(i)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[me,v,V]),a.useEffect(()=>{if(!v){de.current=[],Y.current=-1,V();return}if(ue.current=v,ee.current){ee.current=!1,V();return}const t=de.current,n=Y.current;if(n>=0&&t[n]===v){V();return}const i=n<t.length-1?t.slice(0,n+1):t.slice();i.push(v),i.length>100&&i.shift(),de.current=i,Y.current=i.length-1,V()},[v,V]);const $e=a.useCallback(t=>{u(t),le(!1)},[u]),St=v??"",ut=a.useCallback(()=>{},[]),pt=a.useCallback(t=>{$e(t)},[$e]),K=Ce,[Ye,s]=a.useState(K),[l,c]=a.useState(K);a.useEffect(()=>{if(K){s(!0);return}c(!1);const t=setTimeout(()=>s(!1),240);return()=>clearTimeout(t)},[K]),a.useEffect(()=>{if(!Ye||!K)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>c(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[Ye,K]);const d=a.useRef(null);a.useEffect(()=>{if(v)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const i=n.target;if(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)return;const g=ue.current;!g||!me.has(g)||(n.preventDefault(),b.selectAgent(g))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[v,me]);const[Se,ze]=a.useState(new Set),Ke=a.useCallback(t=>{ze(n=>{const i=new Set(n);return i.has(t)?i.delete(t):i.add(t),i})},[]),[he,Et]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),n=i=>Et(i.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[Oe,X]=a.useState(null),$=a.useCallback(t=>{X(n=>n===t?null:t)},[]),Ze=en(),mt=tn(),[sn]=jn(),Be=a.useMemo(()=>{const t=new Map,n=[];for(const w of _){const A=b.getAreaForAgent(w.id);if(!Ut((A==null?void 0:A.id)??null))continue;if(!A||A.archived){n.push(w);continue}const E=t.get(A.id);E?E.push(w):t.set(A.id,[w])}const i=new Map,g=[];for(const w of mt.values()){let A=!1;for(const E of Ze.values())if(!E.archived&&Vt(E.id)&&b.isPositionInArea(w.position,E)){const O=i.get(E.id);O?O.push(w):i.set(E.id,[w]),A=!0;break}!A&&Ut(null)&&g.push(w)}const x=[];for(const[,w]of Ze){if(w.archived||!Vt(w.id))continue;const A=t.get(w.id),E=i.get(w.id)??[];(A&&A.length>0||E.length>0)&&x.push({area:w,agents:A??[],buildings:E})}(n.length>0||g.length>0)&&x.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:g});const C=x.filter(w=>w.area.id!=="__unassigned__"),k=x.filter(w=>w.area.id==="__unassigned__");let o=1,y=1;const z=new Map;if(C.length>1){let w=1/0,A=-1/0,E=1/0,O=-1/0;for(const B of C)w=Math.min(w,B.area.center.x),A=Math.max(A,B.area.center.x),E=Math.min(E,B.area.center.z),O=Math.max(O,B.area.center.z);const ft=A-w||1,ht=O-E||1;if(C.length<=4){o=C.length,y=1;const B=[...C].sort((F,Mt)=>F.area.center.x-Mt.area.center.x);for(let F=0;F<B.length;F++)z.set(B[F].area.id,{row:1,col:F+1})}else{const B=[...C].sort((j,R)=>j.area.center.x-R.area.center.x),F=[];for(let j=1;j<B.length;j++)F.push(B[j].area.center.x-B[j-1].area.center.x);const Mt=F.reduce((j,R)=>j+R,0)/F.length||1;let $t=1;for(const j of F)j>Mt*1.3&&$t++;o=Math.max(2,Math.min($t,C.length));const It=[...C].sort((j,R)=>j.area.center.z-R.area.center.z),gt=[];for(let j=1;j<It.length;j++)gt.push(It[j].area.center.z-It[j-1].area.center.z);const cn=gt.reduce((j,R)=>j+R,0)/gt.length||1;let zt=1;for(const j of gt)j>cn*1.3&&zt++;y=Math.max(2,Math.min(zt,C.length)),o=Math.max(o,Math.ceil(C.length/y)),y=Math.max(y,Math.ceil(C.length/o));const dn=ft/o,un=ht/y,Tt=new Set;for(const j of C){let R=Math.min(o-1,Math.max(0,Math.floor((j.area.center.x-w)/dn))),Fe=Math.min(y-1,Math.max(0,Math.floor((j.area.center.z-E)/un))),nt=`${Fe},${R}`,Ot=0;const pn=y*o;for(;Tt.has(nt)&&Ot<pn;)R++,R>=o&&(R=0,Fe=(Fe+1)%y),nt=`${Fe},${R}`,Ot++;Tt.has(nt)&&(Fe=y,R=0,nt=`${Fe},${R}`,y++),Tt.add(nt),z.set(j.area.id,{row:Fe+1,col:R+1})}}}const T=w=>{w.sort((A,E)=>{var ft,ht,B,F;const O=(((ft=A.position)==null?void 0:ft.z)??0)-(((ht=E.position)==null?void 0:ht.z)??0);return O!==0?O:(((B=A.position)==null?void 0:B.x)??0)-(((F=E.position)==null?void 0:F.x)??0)})};for(const w of C)T(w.agents);for(const w of k)T(w.agents);return{groups:[...C,...k],gridCols:o,gridRows:y,positions:z}},[_,Ze,mt,sn]),ln=a.useMemo(()=>{if(!ae)return[];const t=_.find(n=>n.id===ae.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(p,{name:"chat",size:14}),onClick:()=>u(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(p,{name:"clipboard",size:14}),onClick:()=>b.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(p,{name:"git-branch",size:14}),onClick:()=>b.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>{Me({agentId:t.id,name:t.name})}}]:[]},[ae,_,u]),rn=a.useMemo(()=>{var C;if(!f)return[];const t=mt.get(f.buildingId);if(!t)return[];const n=[],i=t.type==="server"||t.type==="docker"||t.type==="terminal",g=t.status==="running",x=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="tests"?"Open Tests":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((C=t.pm2)!=null&&C.enabled)?"View PM2 Logs":"Open",icon:e.jsx(p,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="tests"?"flask":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>Xe(t.id)}),i&&(g||n.push({id:"start",label:"Start",icon:e.jsx(p,{name:"play",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"start")}),g&&(n.push({id:"restart",label:"Restart",icon:e.jsx(p,{name:"refresh",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(p,{name:"stop",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"stop")}))),x&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(p,{name:"launch",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(p,{name:"pause",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(p,{name:"restart",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"restart")}})),i&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(p,{name:"health",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),n.push({id:"clone",label:"Clone Building",icon:e.jsx(p,{name:"copy",size:14}),onClick:()=>{b.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const k of t.urls)n.push({id:`url-${k.label}`,label:k.label,icon:e.jsx(p,{name:"link",size:14}),onClick:()=>window.open(k.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>b.deleteBuilding(t.id)}),n},[f,mt,Xe]),on=a.useCallback(t=>{const n=new Set(Be.groups.map(i=>i.area.id));n.delete(t),ze(n),requestAnimationFrame(()=>{const i=d.current;if(!i)return;const g=i.querySelector(`[data-area-id="${t}"]`);if(!g)return;const x=i.getBoundingClientRect(),k=g.getBoundingClientRect().top-x.top+i.scrollTop-8;i.scrollTo({top:Math.max(0,k),behavior:"smooth"})})},[Be]);return e.jsxs("div",{ref:Ie,className:`flat-view ${K?"flat-view--with-inspector":""} ${v?"flat-view--has-chat":""} ${ie?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(Ne===null&&Q===null)return;const t={};return Ne!==null&&(t["--flat-middle-width"]=`${Ne}px`),Q!==null&&(t["--flat-inspector-width"]=`${Q}px`),t})(),children:[ie&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ve,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:P,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:M,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:L,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(Nn,{activeAgentId:St,onClose:ut,onSelectAgent:pt,collapsedAreas:Se,onToggleArea:Ke,agentListRef:d})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:Je,onPointerMove:Pe,onPointerUp:q,onPointerCancel:q,onDoubleClick:vt}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":ie?"Close agents sidebar":"Open agents sidebar","aria-expanded":ie,onClick:lt,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),v?e.jsx(va,{agentId:v,terminalViewMode:He,onTerminalViewModeChange:Ue,inspectorOpen:Ce,onToggleInspector:rt,onImageClick:De,onFileClick:Nt,onBashClick:ct,onViewMarkdown:kt,onRequestClearSubordinates:yt,onOpenBuilding:Xe,keyboard:ot,canNavigateBack:Qe,canNavigateForward:et,onNavigateBack:tt,onNavigateForward:fe,agentInfoOpen:We,onToggleAgentInfo:wt,onHeaderContextMenu:t=>{v&&_e({agentId:v,position:t})},onBuildingContextMenu:(t,n)=>{H({buildingId:t,position:n})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(ma,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Be.gridCols}, 1fr)`},children:Be.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=he&&Oe?((n=Be.positions.get(Oe))==null?void 0:n.row)??null:null;return Be.groups.map(i=>{var k;const g=i.area.id,x=Be.positions.get(g),C=he&&Oe!==g;return he&&t!=null&&(x==null?void 0:x.row)===t&&g!==Oe?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":i.area.color,gridRow:x==null?void 0:x.row,gridColumn:x==null?void 0:x.col},onContextMenu:o=>{N&&(o.preventDefault(),o.stopPropagation(),N(g,{x:o.clientX,y:o.clientY}))},children:[((k=i.area.logo)==null?void 0:k.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:ia(i.area.logo.filename),alt:"","aria-hidden":"true",onError:o=>{o.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>he?$(g):on(g),title:he?C?`Expand ${i.area.name}`:`Collapse ${i.area.name}`:`Focus ${i.area.name} in left panel`,"aria-expanded":he?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:i.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:i.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:i.agents.length}),he&&e.jsx(p,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:i.agents.map(o=>{const y=o.isBoss||o.class==="boss",z=y?At.get(o.id):void 0,T=kn(o),w=T.usedPercent>=80?"#ff4a4a":T.usedPercent>=60?"#ff9e4a":T.usedPercent>=40?"#ffd700":"#4aff9e",A=`Context: ${(T.totalTokens/1e3).toFixed(1)}k / ${(T.contextWindow/1e3).toFixed(1)}k (${T.usedPercent}% used, ${T.freePercent}% free)`,E=o.latestTodos&&o.latestTodos.length>0||z&&z.length>0;return e.jsx(yn,{todos:o.latestTodos,subordinates:z,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${o.status}`,onClick:()=>u(o.id),onContextMenu:O=>{O.preventDefault(),O.stopPropagation(),_e({agentId:o.id,position:{x:O.clientX,y:O.clientY}})},title:E?void 0:`${y?"Boss · ":""}Open chat with ${o.name}
|
|
1
|
+
import{r as a,B as mn,E as Bt,G as Zt,H as Jt,j as e,J as Qt,K as fn,u as Rt,L as hn,M as gn,N as xn,O as bn,V as _n,P as wn,U as vn,W as Ft,S,X as Wt,Y as Dt,Z as Ht,_ as xt,$ as ge,a0 as Cn,s as b,a1 as en,a2 as tn,a3 as jn,w as Ut,x as Vt,I as p,a4 as Nn,n as kn,a5 as yn,a6 as nn,a7 as an,a8 as An,a9 as Sn,aa as En,ab as Mn,ac as In,ad as Tn,ae as Pn,af as Ln,ag as Dn,ah as Rn,ai as $n,aj as zn,ak as Xt,C as On,al as Bn,am as Gt,an as Fn,ao as Wn,ap as Hn,aq as Un,ar as Vn,as as Xn,at as Gn,au as qn,av as Yn,aw as Kn,ax as Zn,ay as Jn,az as Qn,aA as ea,aB as ta,aC as na,aD as aa,aE as sa}from"./main-BVsJe5cx.js";import{g as ia}from"./area-logos-D-61IPfo.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function la(u){const r=a.useRef(u);r.current=u,a.useEffect(()=>{if(!mn())return;let m=null,h=!1;return Bt.addListener("backButton",()=>{r.current()==="exit"&&Bt.exitApp()}).then(N=>{h?N.remove():m=N}),()=>{h=!0,m&&(m.remove(),m=null)}},[])}async function ra(u){const r=Zt(),m=await fetch(`${Jt()}/api/agents/${u}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!m.ok){const h=await m.json().catch(()=>({}));throw new Error((h==null?void 0:h.error)||`Failed to start terminal (${m.status})`)}return m.json()}async function oa(u){const r=Zt();await fetch(`${Jt()}/api/agents/${u}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const at=new Map;function ca({agentId:u}){const[r,m]=a.useState(null),[h,N]=a.useState(null);return a.useEffect(()=>{let P=!1;const M=at.get(u);return M&&(clearTimeout(M),at.delete(u)),m(null),N(null),ra(u).then(L=>{P||m(L.url)}).catch(L=>{P||N(L instanceof Error?L.message:"Failed to start terminal")}),()=>{P=!0;const L=at.get(u);L&&clearTimeout(L),at.set(u,setTimeout(()=>{at.delete(u),oa(u)},2500))}},[u]),h?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:h})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(Qt,{terminalUrl:r,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Pt=new Map,da=6e4;function ua({agentId:u,contextSummary:r}){const{t:m}=Rt(["terminal","common"]),[h,N]=a.useState(()=>{var I;return((I=Pt.get(u))==null?void 0:I.snapshot)??null}),[P,M]=a.useState(!1),[L,G]=a.useState(null),_=a.useRef(0);a.useEffect(()=>{const I=Pt.get(u);if(I&&Date.now()-I.fetchedAt<da){N(I.snapshot);return}const W=++_.current;M(!0),G(null),hn(u).then(U=>{W===_.current&&(Pt.set(u,{snapshot:U,fetchedAt:Date.now()}),N(U),M(!1))}).catch(U=>{W===_.current&&(G(U.message||"Failed to load plan limits"),M(!1))})},[u]);const D=[];if(h!=null&&h.rateLimits){const I=[{key:"fiveHour",label:m("terminal:usage.currentSession"),window:h.rateLimits.fiveHour},{key:"sevenDay",label:m("terminal:usage.currentWeekAll"),window:h.rateLimits.sevenDay},{key:"sevenDayOpus",label:m("terminal:usage.currentWeekOpus"),window:h.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:m("terminal:usage.currentWeekSonnet"),window:h.rateLimits.sevenDaySonnet}];for(const W of I)W.window&&D.push({...W,window:W.window})}return e.jsxs("div",{className:"plan-limits-tooltip",children:[r&&e.jsx("div",{className:"plan-limits-tooltip__context",children:r}),e.jsx("div",{className:"plan-limits-tooltip__title",children:m("terminal:usage.limits")}),P&&!h&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[m("common:status.loading"),"…"]}),!P&&L&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:m("terminal:usage.limitsError",{message:L})}),D.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:D.map(({key:I,label:W,window:U})=>{const xe=Math.max(0,Math.min(100,U.utilization)),Z=xn(xe);return e.jsxs("div",{className:"plan-limits-tooltip__gauge",children:[e.jsxs("div",{className:"plan-limits-tooltip__gauge-head",children:[e.jsx("span",{className:"plan-limits-tooltip__gauge-label",children:W}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:Z},children:m("terminal:usage.percentUsed",{percent:Math.round(xe)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${xe}%`,background:Z}})}),e.jsx("div",{className:"plan-limits-tooltip__reset",children:m("terminal:usage.resets",{time:gn(U.resetsAt)})})]},I)})}):h&&!P&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?m("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function pa({agentId:u,disabled:r,contextSummary:m,children:h}){return e.jsx(fn,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(ua,{agentId:u,contextSummary:m}),children:h})}const ma=a.memo(function({className:r=""}){const{t:m}=Rt(["common"]),[h,N]=bn(),P=a.useRef(null),[M,L]=a.useState(null);a.useLayoutEffect(()=>{const _=P.current;if(!_)return;const D=_.querySelector(".view-mode-toggle__btn--active");D&&L({left:D.offsetLeft,width:D.offsetWidth})},[h]);const G=a.useCallback(_=>{if(_!==h){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:_}})),_==="3d"){requestAnimationFrame(()=>N(_));return}N(_)}},[h,N]);return e.jsxs("div",{className:`view-mode-toggle ${r}`,ref:P,children:[M&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:M.left,width:M.width}}),_n.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>G(_),title:m(`common:viewMode.descriptions.${_}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[_==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),_==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),_==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),_==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:m(`common:viewMode.labels.${_}`)})]},_))]})}),bt=3,_t=280,qt=320,Lt=240,Yt=64,fa=["simple","chat","advanced"],ha={simple:"Simple",chat:"Chat",advanced:"Advanced"},ga={simple:"○",chat:"◐",advanced:"◉"},xa={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Kt="flat-clear-context";function ba(u){const r=u.split("/").filter(Boolean);return r.length===0?u:r.slice(-2).join("/")}function _a(u){if(u.provider==="codex"){const P=u.codexModel||"gpt-5.3-codex",M=na[P];return{model:(M==null?void 0:M.label)||P}}if(u.provider==="opencode")return{model:u.opencodeModel||"opencode"};const r=u.model||"sonnet",m=sa[r],h=u.effort,N=h?aa[h]:void 0;return{model:(m==null?void 0:m.label)||r,effort:N==null?void 0:N.label}}function wa(u,r){if(r.type==="rectangle"&&r.width&&r.height){const m=r.width/2,h=r.height/2;return u.x>=r.center.x-m&&u.x<=r.center.x+m&&u.z>=r.center.z-h&&u.z<=r.center.z+h}if(r.type==="circle"&&r.radius){const m=u.x-r.center.x,h=u.z-r.center.z;return m*m+h*h<=r.radius*r.radius}return!1}const va=Bn.memo(function({agentId:r,terminalViewMode:m,onTerminalViewModeChange:h,inspectorOpen:N,onToggleInspector:P,onImageClick:M,onFileClick:L,onBashClick:G,onViewMarkdown:_,onRequestClearSubordinates:D,onOpenBuilding:I,keyboard:W,canNavigateBack:U,canNavigateForward:xe,onNavigateBack:Z,onNavigateForward:be,agentInfoOpen:Ee,onToggleAgentInfo:st,onHeaderContextMenu:ae,onBuildingContextMenu:_e}){var ut,pt,K,Ye;const f=Gt(r),H=tn(),we=Fn(),Me=a.useRef(null),We=a.useRef(null),{displayedAgentId:ve,fadingOut:wt}=Wn(r),it=Gt(ve),He=!!we.interactiveMode&&((f==null?void 0:f.provider)??"claude")==="claude"&&!!(f!=null&&f.sessionId),[J,Ue]=a.useState(!1);a.useEffect(()=>{Ue(!1)},[r]),a.useEffect(()=>{!He&&J&&Ue(!1)},[He,J]),a.useEffect(()=>{const s=We.current;if(!s)return;const l=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),Z()):d.button===4&&(d.preventDefault(),d.stopPropagation(),be())},c=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return s.addEventListener("mouseup",l),s.addEventListener("mousedown",c),()=>{s.removeEventListener("mouseup",l),s.removeEventListener("mousedown",c)}},[Z,be]),a.useEffect(()=>{const s=We.current;if(!s)return;let l=0,c=0,d=0;const Se=250,ze=600,Ke=80,he=1.5,Et=X=>{let $=X instanceof HTMLElement?X:null;for(;$&&$!==s;){const Ze=window.getComputedStyle($).overflowX;if((Ze==="auto"||Ze==="scroll")&&$.scrollWidth>$.clientWidth)return!0;$=$.parentElement}return!1},Oe=X=>{const $=Date.now();if($<d){X.preventDefault();return}if(Math.abs(X.deltaX)<=Math.abs(X.deltaY)*he){l=0;return}if(Et(X.target)){l=0;return}$-c>Se&&(l=0),c=$,l+=X.deltaX,l<=-Ke?(l=0,d=$+ze,X.preventDefault(),Z()):l>=Ke&&(l=0,d=$+ze,X.preventDefault(),be())};return s.addEventListener("wheel",Oe,{passive:!1}),()=>s.removeEventListener("wheel",Oe)},[Z,be]);const Ce=en(),se=a.useMemo(()=>{if(!f)return null;const s=new Set,l=[];for(const c of Ce.values())c.archived||c.directories.length===0||c.assignedAgentIds.includes(r)&&(s.add(c.id),l.push(c));for(const c of Ce.values())c.archived||c.directories.length===0||s.has(c.id)||wa({x:f.position.x,z:f.position.z},c)&&(s.add(c.id),l.push(c));return l.length===0?null:l.flatMap(c=>c.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:c.id,areaName:c.name,dir:d})))},[f,r,Ce]),{branches:ie,fetchRemote:le,fetchingDirs:lt}=Hn(se),Ve=a.useMemo(()=>{var c;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const d of H.values())d.type==="terminal"&&b.isPositionInArea(d.position,s)&&l.push({id:d.id,name:d.name,hasUrl:!!((c=d.terminalStatus)!=null&&c.url)});return l},[r,H]),Ie=a.useMemo(()=>{var c;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const d of H.values())d.type==="server"&&((c=d.pm2)!=null&&c.enabled)&&b.isPositionInArea(d.position,s)&&l.push({id:d.id,name:d.name});return l},[r,H]),je=a.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const c of H.values())c.type==="database"&&c.database&&b.isPositionInArea(c.position,s)&&l.push({id:c.id,name:c.name});return l},[r,H]),Ne=Un(),Te=a.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const c of H.values())if(c.type==="tests"&&b.isPositionInArea(c.position,s)){const d=!!c.folderPath&&Ne.some(Se=>Vn(Se,c.folderPath));l.push({id:c.id,name:c.name,working:d})}return l},[r,H,Ne]),[,Q]=a.useReducer(s=>s+1,0),re=((ut=Me.current)==null?void 0:ut.search.searchMode)??!1,ke=a.useCallback(()=>{var s;(s=Me.current)==null||s.search.toggleSearch(),Q()},[]),oe=Xn(),Je=oe.isPending(Kt),[ye,Pe]=a.useState(null),q=ye?H.get(ye):null,{height:vt,onResizeStart:Ct}=Gn(),{sidePanelWidth:Le,handleSidePanelResizeStart:jt}=qn(),[Ae,rt]=a.useState(()=>Dt(S.GIT_PANEL_OPEN,!1)),[ce,ot]=a.useState(()=>Dt(S.BUILDINGS_PANEL_OPEN,!1)),[De,ct]=a.useState(!1),Nt=a.useCallback(()=>{ct(s=>{const l=!s;return l&&Yn.setEnabled(!0),l})},[]),kt=a.useCallback(()=>ct(!1),[]),yt=a.useCallback(()=>{rt(s=>{const l=!s;return ge(S.GIT_PANEL_OPEN,l),l})},[]),Xe=a.useCallback(()=>{ot(s=>{const l=!s;return ge(S.BUILDINGS_PANEL_OPEN,l),l})},[]),v=a.useCallback(()=>{rt(!1),ge(S.GIT_PANEL_OPEN,!1)},[]),de=a.useCallback(()=>{ot(!1),ge(S.BUILDINGS_PANEL_OPEN,!1)},[]),Y=Kn();a.useEffect(()=>{if(!ye)return;Ve.some(l=>l.id===ye)||Pe(null)},[ye,Ve]);const[ee,ue]=a.useState(!1),Qe=a.useRef(null);if(a.useEffect(()=>{if(!ee)return;const s=l=>{Qe.current&&!Qe.current.contains(l.target)&&ue(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[ee]),!f)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const pe=f.contextStats,et=!!pe,dt=pe?pe.totalTokens:f.contextUsed||0,Ge=pe?pe.contextWindow:f.contextLimit||2e5,Re=pe?pe.usedPercent:Math.round(dt/Ge*100),te=Math.max(0,Math.min(100,Re)),me=Math.round(te*10)/10,At=Math.round((100-te)*10)/10,V=te>=80?"#ff4a4a":te>=60?"#ff9e4a":te>=40?"#ffd700":"#4aff9e",ne=(dt/1e3).toFixed(1),tt=(Ge/1e3).toFixed(1),fe=f.cwd,qe=fe?ba(fe):null,$e=((pt=f.subordinateIds)==null?void 0:pt.length)||0,St=$e>0;return e.jsxs("div",{ref:We,className:`flat-terminal-wrapper ${Ae||ce||De?"flat-terminal-wrapper--with-side-panel":""} ${wt?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${Le}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Ee?"flat-terminal-wrapper__header-main--active":""}`,onClick:st,onContextMenu:s=>{s.preventDefault(),s.stopPropagation(),ae({x:s.clientX,y:s.clientY})},title:Ee?"Hide agent info":"Show agent info","aria-pressed":Ee,children:[e.jsx(nn,{agent:f,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:an(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:f.provider==="codex"?"/assets/codex.png":f.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:f.provider==="codex"?"Codex Agent":f.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:s,effort:l}=_a(f);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:l?`Model: ${s} · Effort: ${l}`:`Model: ${s}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:s}),l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:l})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsxs("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:[fa.map(s=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!J&&m===s?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Ue(!1),h(s)},title:xa[s],"aria-pressed":!J&&m===s,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:ga[s]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:ha[s]})]},s)),He&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${J?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Ue(s=>!s),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":J,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(p,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:Z,disabled:!U,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(p,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:be,disabled:!xe,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(p,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${re?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ke,title:re?"Close search":"Search messages","aria-pressed":re,children:e.jsx(p,{name:re?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Je?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>oe.handleClick(Kt,()=>{var s;b.clearContext(r),(s=Me.current)==null||s.historyLoader.clearHistory()}),title:Je?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:Je?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Ae?"flat-terminal-wrapper__action-btn--active":""}`,onClick:yt,title:Ae?"Hide git panel":"Show git changes","aria-pressed":Ae,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ce?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Xe,title:ce?"Hide buildings panel":"Show area buildings","aria-pressed":ce,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Qe,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ee?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>ue(s=>!s),title:"More actions","aria-expanded":ee,children:"⋮"}),ee&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${De?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Nt(),ue(!1)},title:De?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:De?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{b.collapseContext(r),ue(!1)},disabled:f.status!=="idle",title:f.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(p,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),St&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{D(r,$e),ue(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",$e," subordinate",$e===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{b.killAgent(r),ue(!1)},children:[e.jsx(p,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${N?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:P,title:N?"Hide inspector panel":"Show inspector panel","aria-label":N?"Hide inspector panel":"Show inspector panel","aria-pressed":N,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>b.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(p,{name:"cross",size:14})})]})]}),J&&He?e.jsx(ca,{agentId:r}):ve&&it?e.jsx(Zn,{ref:Me,agentId:ve,agent:it,viewMode:m,isOpen:!0,onImageClick:M,onFileClick:L,onBashClick:G,onViewMarkdown:_,keyboard:W,hasModalOpen:!1},ve):null,q&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Ct,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${q.name}`,style:{height:vt},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(p,{name:"terminal",size:12}),e.jsx("span",{children:q.name}),!((K=q.terminalStatus)!=null&&K.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>Pe(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(p,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(Ye=q.terminalStatus)!=null&&Ye.url?e.jsx(Qt,{terminalUrl:q.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(p,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),fe&&qe&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${fe}`,"aria-label":`Open ${fe} in file explorer`,role:"button",tabIndex:0,onClick:()=>b.openFileExplorer(fe),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b.openFileExplorer(fe))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(p,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:qe})]}),se&&se.map(({areaId:s,areaName:l,dir:c})=>{const d=ie.get(c),Se=lt.has(c),ze=c.split("/").filter(Boolean).pop()||c;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${l}: ${c}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>b.openFileExplorerForAreaFolder(s,c),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:ze}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",d.branch]}),d.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${d.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),d.ahead]}),d.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${d.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Se?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Ke=>{Ke.stopPropagation(),le(c)},children:e.jsx(p,{name:Se?"hourglass":"download",size:12})})]})]},`${s}:${c}`)}),e.jsx(pa,{agentId:r,disabled:((f==null?void 0:f.provider)??"claude")!=="claude",contextSummary:et?`Context: ${ne}k / ${tt}k tokens (${me}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>b.setContextModalAgentId(r),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b.setContextModalAgentId(r))},title:((f==null?void 0:f.provider)??"claude")!=="claude"?et?`Context usage: ${ne}k / ${tt}k tokens (${me}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(p,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${te}%`,backgroundColor:V}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:V},children:[ne,"k/",tt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",At,"% free)"]}),!et&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(p,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),Ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:Ve.map(s=>{const l=ye===s.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${l?"flat-terminal-wrapper__building-btn--active":""} ${s.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${l?"Hide":"Show"} terminal: ${s.name}${s.hasUrl?"":" (starting...)"}`,onClick:()=>{if(l){Pe(null);return}s.hasUrl||b.sendBuildingCommand(s.id,"start"),Pe(s.id)},onContextMenu:c=>{c.preventDefault(),c.stopPropagation(),_e(s.id,{x:c.clientX,y:c.clientY})},children:e.jsx(p,{name:"terminal",size:14})},s.id)})}),Ie.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Ie.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"scroll",size:14})},s.id))}),je.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:je.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"hard-drives",size:14})},s.id))}),Te.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:Te.map(s=>e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${s.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:s.working?`Running tests: ${s.name}`:`Open tests: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"flask",size:14})},s.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Jn,{})})]}),Ae&&e.jsx(Qn,{agentId:r,agents:Y,onClose:v,branchInfoMap:ie,fetchRemote:le,fetchingDirs:lt,onResizeStart:s=>jt(s,"right")}),ce&&e.jsx(ea,{agentId:r,onClose:de}),De&&e.jsx(ta,{agentId:r,onClose:kt})]})});function ya({onAgentClick:u,onBuildingClick:r,onBuildingDoubleClick:m,onBuildingPopup:h,onAreaContextMenu:N,onOpenSpawnModal:P,onOpenBossSpawnModal:M,onOpenAreaModal:L}){const{t:G}=Rt(["common"]),_=wn(),D=vn(),[I,W]=a.useState(null),[U,xe]=a.useState(null),[Z,be]=a.useState(null),[Ee,st]=a.useState(null),[ae,_e]=a.useState(null),[f,H]=a.useState(null),[we,Me]=a.useState(null),[We,ve]=a.useState(!1),wt=a.useCallback(()=>{ve(t=>!t)},[]),it=a.useCallback(()=>{ve(!1)},[]),[He,J]=a.useState(()=>{const t=Ft(S.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ue=a.useCallback(t=>{J(t),Wt(S.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==S.VIEW_MODE)return;const i=n.newValue;(i==="simple"||i==="chat"||i==="advanced")&&J(i)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[Ce,se]=a.useState(()=>Dt(S.FLAT_INSPECTOR_OPEN,!1)),[ie,le]=a.useState(!1),lt=a.useCallback(()=>le(t=>!t),[]),Ve=a.useCallback(()=>le(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:ie}}))},[ie]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:Ce}}))},[Ce]),a.useEffect(()=>{const t=()=>le(C=>!C),n=()=>{se(C=>{const k=!C;return ge(S.FLAT_INSPECTOR_OPEN,k),k})},i=()=>{le(!1),se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)},g=()=>le(!1),x=()=>{se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",i),window.addEventListener("tide-close-flat-agents-drawer-only",g),window.addEventListener("tide-close-flat-inspector-only",x),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",i),window.removeEventListener("tide-close-flat-agents-drawer-only",g),window.removeEventListener("tide-close-flat-inspector-only",x)}},[]);const Ie=a.useRef(null),je=a.useRef(null),[Ne,Te]=a.useState(()=>{const t=Ht(S.FLAT_MIDDLE_WIDTH,0);return t>=_t?t:null}),[Q,re]=a.useState(()=>{const t=Ht(S.FLAT_INSPECTOR_WIDTH,0);return t>=Lt?t:null}),ke=a.useCallback(t=>{if(typeof window>"u")return t;const n=Q!==null?bt+Q:0,i=window.innerWidth-Yt-bt-qt-n;return Math.max(_t,Math.min(Math.max(i,_t),t))},[Q]),oe=a.useCallback(t=>{var x;if(typeof window>"u")return t;const n=(x=Ie.current)==null?void 0:x.querySelector(".flat-middle"),i=(n==null?void 0:n.getBoundingClientRect().width)??_t,g=window.innerWidth-Yt-i-bt-qt-bt;return Math.max(Lt,Math.min(Math.max(g,Lt),t))},[]);a.useEffect(()=>{if(Ne===null&&Q===null)return;const t=()=>{Te(n=>{if(n===null)return n;const i=ke(n);return i===n?n:i}),re(n=>{if(n===null)return n;const i=oe(n);return i===n?n:i})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[Ne,Q,ke,oe]);const Je=a.useCallback(t=>{var i;if(t.button!==0)return;const n=(i=Ie.current)==null?void 0:i.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),je.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),ye=a.useCallback(t=>{var i;if(t.button!==0)return;const n=(i=Ie.current)==null?void 0:i.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),je.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Pe=a.useCallback(t=>{const n=je.current;if(!n||t.pointerId!==n.pointerId)return;const i=t.clientX-n.startX;n.kind==="middle"?Te(ke(n.startWidth+i)):re(oe(n.startWidth-i))},[ke,oe]),q=a.useCallback(t=>{const n=je.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(je.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const g=t.clientX-n.startX;if(n.kind==="middle"){const x=ke(n.startWidth+g);Te(x),xt(S.FLAT_MIDDLE_WIDTH,x)}else{const x=oe(n.startWidth-g);re(x),xt(S.FLAT_INSPECTOR_WIDTH,x)}},[ke,oe]),vt=a.useCallback(()=>{Te(null),xt(S.FLAT_MIDDLE_WIDTH,0)},[]),Ct=a.useCallback(()=>{re(null),xt(S.FLAT_INSPECTOR_WIDTH,0)},[]),[Le,jt]=a.useState(()=>Ft(S.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Ae=a.useCallback(t=>{jt(t),Wt(S.FLAT_INSPECTOR_VIEW,t)},[]),rt=a.useCallback(()=>{se(t=>{const n=!t;return ge(S.FLAT_INSPECTOR_OPEN,n),n})},[]),ce=a.useCallback(()=>{se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)},[]),ot=Cn(),De=a.useCallback((t,n)=>{W({url:t,name:n})},[]),ct=a.useCallback((t,n)=>{xe({command:t,output:n,isLive:!1})},[]),Nt=a.useCallback((t,n)=>{var x;const i=D.size>0?Array.from(D)[0]:null,g=i?(x=b.getState().agents.get(i))==null?void 0:x.cwd:void 0;b.setFileViewerPath(t,n,g)},[D]),kt=a.useCallback(t=>{be(t)},[]),yt=a.useCallback((t,n)=>{st({agentId:t,count:n})},[]),Xe=a.useCallback(t=>{m?m(t):r(t)},[r,m]),v=a.useMemo(()=>D.size>0?Array.from(D)[0]:null,[D]);a.useEffect(()=>{ve(!1)},[v]);const de=a.useRef([]),Y=a.useRef(-1),ee=a.useRef(!1),ue=a.useRef(null),[Qe,pe]=a.useState(!1),[et,dt]=a.useState(!1),Ge=a.useRef(!1),Re=a.useRef(null),te=a.useRef(!1),me=a.useMemo(()=>new Set(_.map(t=>t.id)),[_]),At=a.useMemo(()=>{const t=new Map(_.map(i=>[i.id,i])),n=new Map;for(const i of _)if((i.isBoss||i.class==="boss")&&i.subordinateIds&&i.subordinateIds.length>0){const g=i.subordinateIds.map(x=>t.get(x)).filter(x=>x!==void 0);g.length>0&&n.set(i.id,g)}return n},[_]),V=a.useCallback(()=>{const t=de.current,n=Y.current;pe(n>0),dt(n>=0&&n<t.length-1)},[]),ne=a.useCallback(t=>{const n=de.current;if(n.length===0)return;let i=Y.current+t;for(;i>=0&&i<n.length;){const g=n[i];if(me.has(g)){ee.current=!0,Y.current=i,V(),b.selectAgent(g);return}i+=t}},[me,V]),tt=a.useCallback(()=>ne(-1),[ne]),fe=a.useCallback(()=>ne(1),[ne]);la(a.useCallback(()=>{const t=de.current,n=Y.current;return t.length>0&&n>0?(ne(-1),"handled"):"exit"},[ne]));const qe=a.useCallback((t,n)=>{if(typeof window>"u")return;const i=window.history.state,x={...typeof i=="object"&&i!==null?i:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(x,"",window.location.href):window.history.pushState(x,"",window.location.href)},[]);a.useEffect(()=>{if(!v){Ge.current=!1,Re.current=null;return}if(!Ge.current){qe(v,"replace"),Ge.current=!0,Re.current=v;return}if(te.current){te.current=!1,Re.current=v;return}Re.current!==v&&(qe(v,"push"),Re.current=v)},[v,qe]),a.useEffect(()=>{const t=n=>{var C,k;const i=(k=(C=n.state)==null?void 0:C.__flatAgentNav)==null?void 0:k.agentId;if(!i||typeof i!="string"||!me.has(i)||i===v)return;te.current=!0,ee.current=!0;const g=de.current,x=g.lastIndexOf(i);x>=0?Y.current=x:(g.push(i),Y.current=g.length-1),V(),b.selectAgent(i)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[me,v,V]),a.useEffect(()=>{if(!v){de.current=[],Y.current=-1,V();return}if(ue.current=v,ee.current){ee.current=!1,V();return}const t=de.current,n=Y.current;if(n>=0&&t[n]===v){V();return}const i=n<t.length-1?t.slice(0,n+1):t.slice();i.push(v),i.length>100&&i.shift(),de.current=i,Y.current=i.length-1,V()},[v,V]);const $e=a.useCallback(t=>{u(t),le(!1)},[u]),St=v??"",ut=a.useCallback(()=>{},[]),pt=a.useCallback(t=>{$e(t)},[$e]),K=Ce,[Ye,s]=a.useState(K),[l,c]=a.useState(K);a.useEffect(()=>{if(K){s(!0);return}c(!1);const t=setTimeout(()=>s(!1),240);return()=>clearTimeout(t)},[K]),a.useEffect(()=>{if(!Ye||!K)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>c(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[Ye,K]);const d=a.useRef(null);a.useEffect(()=>{if(v)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const i=n.target;if(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)return;const g=ue.current;!g||!me.has(g)||(n.preventDefault(),b.selectAgent(g))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[v,me]);const[Se,ze]=a.useState(new Set),Ke=a.useCallback(t=>{ze(n=>{const i=new Set(n);return i.has(t)?i.delete(t):i.add(t),i})},[]),[he,Et]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),n=i=>Et(i.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[Oe,X]=a.useState(null),$=a.useCallback(t=>{X(n=>n===t?null:t)},[]),Ze=en(),mt=tn(),[sn]=jn(),Be=a.useMemo(()=>{const t=new Map,n=[];for(const w of _){const A=b.getAreaForAgent(w.id);if(!Ut((A==null?void 0:A.id)??null))continue;if(!A||A.archived){n.push(w);continue}const E=t.get(A.id);E?E.push(w):t.set(A.id,[w])}const i=new Map,g=[];for(const w of mt.values()){let A=!1;for(const E of Ze.values())if(!E.archived&&Vt(E.id)&&b.isPositionInArea(w.position,E)){const O=i.get(E.id);O?O.push(w):i.set(E.id,[w]),A=!0;break}!A&&Ut(null)&&g.push(w)}const x=[];for(const[,w]of Ze){if(w.archived||!Vt(w.id))continue;const A=t.get(w.id),E=i.get(w.id)??[];(A&&A.length>0||E.length>0)&&x.push({area:w,agents:A??[],buildings:E})}(n.length>0||g.length>0)&&x.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:g});const C=x.filter(w=>w.area.id!=="__unassigned__"),k=x.filter(w=>w.area.id==="__unassigned__");let o=1,y=1;const z=new Map;if(C.length>1){let w=1/0,A=-1/0,E=1/0,O=-1/0;for(const B of C)w=Math.min(w,B.area.center.x),A=Math.max(A,B.area.center.x),E=Math.min(E,B.area.center.z),O=Math.max(O,B.area.center.z);const ft=A-w||1,ht=O-E||1;if(C.length<=4){o=C.length,y=1;const B=[...C].sort((F,Mt)=>F.area.center.x-Mt.area.center.x);for(let F=0;F<B.length;F++)z.set(B[F].area.id,{row:1,col:F+1})}else{const B=[...C].sort((j,R)=>j.area.center.x-R.area.center.x),F=[];for(let j=1;j<B.length;j++)F.push(B[j].area.center.x-B[j-1].area.center.x);const Mt=F.reduce((j,R)=>j+R,0)/F.length||1;let $t=1;for(const j of F)j>Mt*1.3&&$t++;o=Math.max(2,Math.min($t,C.length));const It=[...C].sort((j,R)=>j.area.center.z-R.area.center.z),gt=[];for(let j=1;j<It.length;j++)gt.push(It[j].area.center.z-It[j-1].area.center.z);const cn=gt.reduce((j,R)=>j+R,0)/gt.length||1;let zt=1;for(const j of gt)j>cn*1.3&&zt++;y=Math.max(2,Math.min(zt,C.length)),o=Math.max(o,Math.ceil(C.length/y)),y=Math.max(y,Math.ceil(C.length/o));const dn=ft/o,un=ht/y,Tt=new Set;for(const j of C){let R=Math.min(o-1,Math.max(0,Math.floor((j.area.center.x-w)/dn))),Fe=Math.min(y-1,Math.max(0,Math.floor((j.area.center.z-E)/un))),nt=`${Fe},${R}`,Ot=0;const pn=y*o;for(;Tt.has(nt)&&Ot<pn;)R++,R>=o&&(R=0,Fe=(Fe+1)%y),nt=`${Fe},${R}`,Ot++;Tt.has(nt)&&(Fe=y,R=0,nt=`${Fe},${R}`,y++),Tt.add(nt),z.set(j.area.id,{row:Fe+1,col:R+1})}}}const T=w=>{w.sort((A,E)=>{var ft,ht,B,F;const O=(((ft=A.position)==null?void 0:ft.z)??0)-(((ht=E.position)==null?void 0:ht.z)??0);return O!==0?O:(((B=A.position)==null?void 0:B.x)??0)-(((F=E.position)==null?void 0:F.x)??0)})};for(const w of C)T(w.agents);for(const w of k)T(w.agents);return{groups:[...C,...k],gridCols:o,gridRows:y,positions:z}},[_,Ze,mt,sn]),ln=a.useMemo(()=>{if(!ae)return[];const t=_.find(n=>n.id===ae.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(p,{name:"chat",size:14}),onClick:()=>u(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(p,{name:"clipboard",size:14}),onClick:()=>b.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(p,{name:"git-branch",size:14}),onClick:()=>b.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>{Me({agentId:t.id,name:t.name})}}]:[]},[ae,_,u]),rn=a.useMemo(()=>{var C;if(!f)return[];const t=mt.get(f.buildingId);if(!t)return[];const n=[],i=t.type==="server"||t.type==="docker"||t.type==="terminal",g=t.status==="running",x=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="tests"?"Open Tests":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((C=t.pm2)!=null&&C.enabled)?"View PM2 Logs":"Open",icon:e.jsx(p,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="tests"?"flask":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>Xe(t.id)}),i&&(g||n.push({id:"start",label:"Start",icon:e.jsx(p,{name:"play",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"start")}),g&&(n.push({id:"restart",label:"Restart",icon:e.jsx(p,{name:"refresh",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(p,{name:"stop",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"stop")}))),x&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(p,{name:"launch",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(p,{name:"pause",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(p,{name:"restart",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"restart")}})),i&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(p,{name:"health",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),n.push({id:"clone",label:"Clone Building",icon:e.jsx(p,{name:"copy",size:14}),onClick:()=>{b.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const k of t.urls)n.push({id:`url-${k.label}`,label:k.label,icon:e.jsx(p,{name:"link",size:14}),onClick:()=>window.open(k.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>b.deleteBuilding(t.id)}),n},[f,mt,Xe]),on=a.useCallback(t=>{const n=new Set(Be.groups.map(i=>i.area.id));n.delete(t),ze(n),requestAnimationFrame(()=>{const i=d.current;if(!i)return;const g=i.querySelector(`[data-area-id="${t}"]`);if(!g)return;const x=i.getBoundingClientRect(),k=g.getBoundingClientRect().top-x.top+i.scrollTop-8;i.scrollTo({top:Math.max(0,k),behavior:"smooth"})})},[Be]);return e.jsxs("div",{ref:Ie,className:`flat-view ${K?"flat-view--with-inspector":""} ${v?"flat-view--has-chat":""} ${ie?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(Ne===null&&Q===null)return;const t={};return Ne!==null&&(t["--flat-middle-width"]=`${Ne}px`),Q!==null&&(t["--flat-inspector-width"]=`${Q}px`),t})(),children:[ie&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ve,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:P,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:M,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:L,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(Nn,{activeAgentId:St,onClose:ut,onSelectAgent:pt,collapsedAreas:Se,onToggleArea:Ke,agentListRef:d})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:Je,onPointerMove:Pe,onPointerUp:q,onPointerCancel:q,onDoubleClick:vt}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":ie?"Close agents sidebar":"Open agents sidebar","aria-expanded":ie,onClick:lt,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),v?e.jsx(va,{agentId:v,terminalViewMode:He,onTerminalViewModeChange:Ue,inspectorOpen:Ce,onToggleInspector:rt,onImageClick:De,onFileClick:Nt,onBashClick:ct,onViewMarkdown:kt,onRequestClearSubordinates:yt,onOpenBuilding:Xe,keyboard:ot,canNavigateBack:Qe,canNavigateForward:et,onNavigateBack:tt,onNavigateForward:fe,agentInfoOpen:We,onToggleAgentInfo:wt,onHeaderContextMenu:t=>{v&&_e({agentId:v,position:t})},onBuildingContextMenu:(t,n)=>{H({buildingId:t,position:n})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(ma,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Be.gridCols}, 1fr)`},children:Be.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=he&&Oe?((n=Be.positions.get(Oe))==null?void 0:n.row)??null:null;return Be.groups.map(i=>{var k;const g=i.area.id,x=Be.positions.get(g),C=he&&Oe!==g;return he&&t!=null&&(x==null?void 0:x.row)===t&&g!==Oe?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":i.area.color,gridRow:x==null?void 0:x.row,gridColumn:x==null?void 0:x.col},onContextMenu:o=>{N&&(o.preventDefault(),o.stopPropagation(),N(g,{x:o.clientX,y:o.clientY}))},children:[((k=i.area.logo)==null?void 0:k.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:ia(i.area.logo.filename),alt:"","aria-hidden":"true",onError:o=>{o.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>he?$(g):on(g),title:he?C?`Expand ${i.area.name}`:`Collapse ${i.area.name}`:`Focus ${i.area.name} in left panel`,"aria-expanded":he?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:i.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:i.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:i.agents.length}),he&&e.jsx(p,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:i.agents.map(o=>{const y=o.isBoss||o.class==="boss",z=y?At.get(o.id):void 0,T=kn(o),w=T.usedPercent>=80?"#ff4a4a":T.usedPercent>=60?"#ff9e4a":T.usedPercent>=40?"#ffd700":"#4aff9e",A=`Context: ${(T.totalTokens/1e3).toFixed(1)}k / ${(T.contextWindow/1e3).toFixed(1)}k (${T.usedPercent}% used, ${T.freePercent}% free)`,E=o.latestTodos&&o.latestTodos.length>0||z&&z.length>0;return e.jsx(yn,{todos:o.latestTodos,subordinates:z,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${o.status}`,onClick:()=>u(o.id),onContextMenu:O=>{O.preventDefault(),O.stopPropagation(),_e({agentId:o.id,position:{x:O.clientX,y:O.clientY}})},title:E?void 0:`${y?"Boss · ":""}Open chat with ${o.name}
|
|
2
2
|
${A}`,children:[e.jsx(nn,{agent:o,size:16}),y&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(p,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:o.name}),e.jsx("img",{src:o.provider==="codex"?"/assets/codex.png":o.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:o.provider,className:"flat-map-agent-chip__provider-icon",title:o.provider==="codex"?"Codex Agent":o.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:an(o.status)}}),o.latestTodos&&o.latestTodos.length>0&&e.jsx(An,{todos:o.latestTodos,maxDots:6}),y&&z&&z.length>0&&e.jsx(Sn,{subordinates:z,maxDots:6}),e.jsx("span",{className:"flat-map-agent-chip__context-bar","aria-hidden":"true",children:e.jsx("span",{className:"flat-map-agent-chip__context-bar-fill",style:{width:`${T.usedPercent}%`,backgroundColor:w}})})]})},o.id)})}),i.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${i.area.name} folders`,children:i.area.directories.map(o=>{const y=o.split("/").filter(Boolean).pop()||o;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:z=>{z.stopPropagation(),b.openFileExplorerForAreaFolder(g,o)},title:`Open in file explorer: ${o}`,children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:y})]},o)})}),i.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:i.buildings.map(o=>{var z;const y=(z=En[o.type])==null?void 0:z.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${o.status}`,style:y?{"--building-type-color":y}:void 0,onClick:T=>{if(h){const w=T.currentTarget.getBoundingClientRect();h(o.id,{x:w.right,y:w.top+w.height/2})}else Xe(o.id)},onContextMenu:T=>{T.preventDefault(),T.stopPropagation(),H({buildingId:o.id,position:{x:T.clientX,y:T.clientY}})},title:`${o.name} · ${o.type} · ${o.status}`,children:[e.jsx(p,{name:Mn(o.type),size:12,color:y}),e.jsx("span",{className:"flat-map-building-chip__name",children:o.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:In(o.status)}})]},o.id)})})]},g)})})()})]})})]}),K&&e.jsx("div",{className:"flat-splitter flat-splitter--inspector",role:"separator","aria-orientation":"vertical","aria-label":"Resize inspector panel",title:"Drag to resize · Double-click to reset",onPointerDown:ye,onPointerMove:Pe,onPointerUp:q,onPointerCancel:q,onDoubleClick:Ct}),Ye&&e.jsxs("aside",{className:`flat-inspector ${l?"flat-inspector--open":"flat-inspector--closing"}`,"aria-label":"Inspector panel",children:[e.jsxs("div",{className:"flat-inspector__header",children:[e.jsxs("div",{className:"flat-inspector__tabs",role:"tablist","aria-label":"Inspector view",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":Le==="agent",className:`flat-inspector__tab ${Le==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>Ae("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":Le==="tracking",className:`flat-inspector__tab ${Le==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>Ae("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:ce,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:Le==="tracking"?e.jsx(Tn,{activeAgentId:v??"",onSelectAgent:t=>{u(t),window.innerWidth<=768&&ce()}}):(()=>{if(!v)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=_.find(n=>n.id===v);return t?e.jsx(Pn,{agent:t,onFocusAgent:n=>{u(n),window.innerWidth<=768&&ce()},onKillAgent:n=>b.killAgent(n)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),I&&e.jsx(Ln,{url:I.url,name:I.name,onClose:()=>W(null)}),U&&e.jsx(Dn,{state:U,onClose:()=>xe(null)}),e.jsx(Rn,{agent:v?_.find(t=>t.id===v)??null:null,content:Z,onClose:()=>be(null)}),Ee&&e.jsx($n,{action:"clear-subordinates",selectedAgentId:Ee.agentId,subordinateCount:Ee.count,onClose:()=>st(null),onClearHistory:()=>{}}),e.jsx(zn,{agent:v?_.find(t=>t.id===v)??null:null,isOpen:We&&!!v,onClose:it}),e.jsx(Xt,{isOpen:ae!==null,position:(ae==null?void 0:ae.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:ln,onClose:()=>_e(null)}),e.jsx(Xt,{isOpen:f!==null,position:(f==null?void 0:f.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:rn,onClose:()=>H(null)}),e.jsx(On,{isOpen:we!==null,title:G("common:confirm.removeAgentTitle"),message:G("common:confirm.removeAgentMessage",{name:(we==null?void 0:we.name)??""}),confirmLabel:G("common:buttons.remove"),cancelLabel:G("common:buttons.cancel"),variant:"danger",onConfirm:()=>{we&&b.removeAgentFromServer(we.agentId)},onClose:()=>Me(null)})]})}export{ya as FlatView};
|