tide-commander 1.110.2 → 1.110.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/assets/{BossLogsModal-DBeMak5-.js → BossLogsModal-BBO4P4qG.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-DDl6qgnq.js → BossSpawnModal-DJ1DmEWp.js} +1 -1
  3. package/dist/assets/{ControlsModal-BBUukX-p.js → ControlsModal-DeRColMt.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-BWf3XDEI.js → DockerLogsModal-DGpatLiw.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-CIOdhnaW.js → EmbeddedEditor-Dsgf6hMF.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-qG-_WeOb.js → GmailOAuthSetup-CGis0yjA.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-BK3lzU4n.js → GoogleOAuthSetup-Bnhf_nts.js} +1 -1
  8. package/dist/assets/{IframeModal-D_NEs_Ld.js → IframeModal-BahnrxAm.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-yphWX1ZD.js → IntegrationsPanel-BUs_7XBA.js} +2 -2
  10. package/dist/assets/{LogViewerModal-B0h9NNRk.js → LogViewerModal-DXxjS8NR.js} +1 -1
  11. package/dist/assets/{MonitoringModal-Ciw7KnXH.js → MonitoringModal-DPeyASIV.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-C1dYQaff.js → PM2LogsModal-kNNjOmdB.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-DOwzfu-D.js → RestoreArchivedAreaModal-CVHj28LX.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-MHfv4Rzg.js → Scene2DCanvas-BShs3yx7.js} +1 -1
  15. package/dist/assets/{SceneManager-cm1Kj0YD.js → SceneManager-CF89Ktyf.js} +1 -1
  16. package/dist/assets/{SkillsPanel-DLwMkORc.js → SkillsPanel-BVRP74vV.js} +1 -1
  17. package/dist/assets/{SlackMultiInstanceSetup-Dql_wPMX.js → SlackMultiInstanceSetup-f6boDwm1.js} +1 -1
  18. package/dist/assets/{SpawnModal-DzPTSOKV.js → SpawnModal-Bm8rg45q.js} +1 -1
  19. package/dist/assets/StatisticsModal-DuNj8UzS.js +1 -0
  20. package/dist/assets/{SubordinateAssignmentModal-CoLzD3z2.js → SubordinateAssignmentModal-Cn3e2lNE.js} +1 -1
  21. package/dist/assets/{TriggerManagerPanel-BOi2zr7N.js → TriggerManagerPanel-Deo2dE4T.js} +1 -1
  22. package/dist/assets/{WorkflowEditorPanel-DB1ygPDS.js → WorkflowEditorPanel-D-_duRlu.js} +1 -1
  23. package/dist/assets/{index-DKASWGtq.js → index-Bb-7Dvp1.js} +1 -1
  24. package/dist/assets/{index-C6EHHgC0.js → index-BsykE0PB.js} +1 -1
  25. package/dist/assets/{index-D4XW6MSF.js → index-C9A7qvBF.js} +2 -2
  26. package/dist/assets/{index-DKdZI-Ar.js → index-CZGINGY-.js} +1 -1
  27. package/dist/assets/{index-6Wak7CPm.js → index-DZu9t3BI.js} +1 -1
  28. package/dist/assets/{index-BZsQOteM.js → index-DeeuvLUM.js} +1 -1
  29. package/dist/assets/index-v1ImDk7h.js +11 -0
  30. package/dist/assets/{index-BXJSMT4a.js → index-y3mA_lBK.js} +3 -3
  31. package/dist/assets/{index-ThbMNdRp.js → index-zphXsHhS.js} +1 -1
  32. package/dist/assets/{main-BxA3Bhkv.js → main-CyZg1kKu.js} +94 -94
  33. package/dist/assets/{main-BLrGoeQ_.css → main-VciFPjA1.css} +1 -1
  34. package/dist/assets/{web-zdygXcYu.js → web-BKgFBlgl.js} +1 -1
  35. package/dist/assets/{web-BskC98UQ.js → web-BZcyP_IR.js} +1 -1
  36. package/dist/assets/{web-CSRmX8Ge.js → web-VEWFSkZI.js} +1 -1
  37. package/dist/index.html +2 -2
  38. package/dist/src/packages/server/data/builtin-skills/send-message-to-agent.js +54 -1
  39. package/dist/src/packages/server/routes/agents.js +43 -0
  40. package/dist/src/packages/server/services/collapse-context.js +72 -0
  41. package/dist/src/packages/server/services/runtime-service.js +46 -0
  42. package/dist/src/packages/server/websocket/handlers/agent-handler.js +27 -12
  43. package/package.json +1 -1
  44. package/dist/assets/index-BP6ukiYG.js +0 -11
@@ -1 +1 @@
1
- import{j as d,I as J,aj as Ge,U as He,W as Je,bY as Xe,r as y,s as te,bZ as ve,_ as Ze,ad as de,u as Ee}from"./main-BxA3Bhkv.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function ee(t){return Array.isArray?Array.isArray(t):Te(t)==="[object Array]"}function qe(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function et(t){return t==null?"":qe(t)}function Z(t){return typeof t=="string"}function $e(t){return typeof t=="number"}function tt(t){return t===!0||t===!1||st(t)&&Te(t)=="[object Boolean]"}function Le(t){return typeof t=="object"}function st(t){return Le(t)&&t!==null}function O(t){return t!=null}function fe(t){return!t.trim().length}function Te(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const nt="Incorrect 'index' type",rt=t=>`Invalid value for key ${t}`,it=t=>`Pattern length exceeds max of ${t}.`,ct=t=>`Missing ${t} property in key`,ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Se=Object.prototype.hasOwnProperty;class at{constructor(e){this._keys=[],this._keyMap={};let s=0;e.forEach(n=>{let r=Pe(n);this._keys.push(r),this._keyMap[r.id]=r,s+=r.weight}),this._keys.forEach(n=>{n.weight/=s})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function Pe(t){let e=null,s=null,n=null,r=1,c=null;if(Z(t)||ee(t))n=t,e=be(t),s=me(t);else{if(!Se.call(t,"name"))throw new Error(ct("name"));const o=t.name;if(n=o,Se.call(t,"weight")&&(r=t.weight,r<=0))throw new Error(ot(o));e=be(o),s=me(o),c=t.getFn}return{path:e,id:s,weight:r,src:n,getFn:c}}function be(t){return ee(t)?t:t.split(".")}function me(t){return ee(t)?t.join("."):t}function ut(t,e){let s=[],n=!1;const r=(c,o,a)=>{if(O(c))if(!o[a])s.push(c);else{let u=o[a];const l=c[u];if(!O(l))return;if(a===o.length-1&&(Z(l)||$e(l)||tt(l)))s.push(et(l));else if(ee(l)){n=!0;for(let h=0,f=l.length;h<f;h+=1)r(l[h],o,a+1)}else o.length&&r(l,o,a+1)}};return r(t,Z(e)?e.split("."):e,0),n?s:s[0]}const lt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},ht={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},dt={location:0,threshold:.6,distance:100},ft={useExtendedSearch:!1,getFn:ut,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var p={...ht,...lt,...dt,...ft};const mt=/[^ ]+/g;function pt(t=1,e=3){const s=new Map,n=Math.pow(10,e);return{get(r){const c=r.match(mt).length;if(s.has(c))return s.get(c);const o=1/Math.pow(c,.5*t),a=parseFloat(Math.round(o*n)/n);return s.set(c,a),a},clear(){s.clear()}}}class Ce{constructor({getFn:e=p.getFn,fieldNormWeight:s=p.fieldNormWeight}={}){this.norm=pt(s,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((s,n)=>{this._keysMap[s.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,Z(this.docs[0])?this.docs.forEach((e,s)=>{this._addString(e,s)}):this.docs.forEach((e,s)=>{this._addObject(e,s)}),this.norm.clear())}add(e){const s=this.size();Z(e)?this._addString(e,s):this._addObject(e,s)}removeAt(e){this.records.splice(e,1);for(let s=e,n=this.size();s<n;s+=1)this.records[s].i-=1}getValueForItemAtKeyId(e,s){return e[this._keysMap[s]]}size(){return this.records.length}_addString(e,s){if(!O(e)||fe(e))return;let n={v:e,i:s,n:this.norm.get(e)};this.records.push(n)}_addObject(e,s){let n={i:s,$:{}};this.keys.forEach((r,c)=>{let o=r.getFn?r.getFn(e):this.getFn(e,r.path);if(O(o)){if(ee(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(O(h))if(Z(h)&&!fe(h)){let f={v:h,i:l,n:this.norm.get(h)};a.push(f)}else ee(h)&&h.forEach((f,m)=>{u.push({nestedArrIndex:m,value:f})})}n.$[c]=a}else if(Z(o)&&!fe(o)){let a={v:o,n:this.norm.get(o)};n.$[c]=a}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function Ke(t,e,{getFn:s=p.getFn,fieldNormWeight:n=p.fieldNormWeight}={}){const r=new Ce({getFn:s,fieldNormWeight:n});return r.setKeys(t.map(Pe)),r.setSources(e),r.create(),r}function gt(t,{getFn:e=p.getFn,fieldNormWeight:s=p.fieldNormWeight}={}){const{keys:n,records:r}=t,c=new Ce({getFn:e,fieldNormWeight:s});return c.setKeys(n),c.setIndexRecords(r),c}function ue(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:r=p.distance,ignoreLocation:c=p.ignoreLocation}={}){const o=e/t.length;if(c)return o;const a=Math.abs(n-s);return r?o+a/r:a?1:o}function At(t=[],e=p.minMatchCharLength){let s=[],n=-1,r=-1,c=0;for(let o=t.length;c<o;c+=1){let a=t[c];a&&n===-1?n=c:!a&&n!==-1&&(r=c-1,r-n+1>=e&&s.push([n,r]),n=-1)}return t[c-1]&&c-n>=e&&s.push([n,c-1]),s}const re=32;function yt(t,e,s,{location:n=p.location,distance:r=p.distance,threshold:c=p.threshold,findAllMatches:o=p.findAllMatches,minMatchCharLength:a=p.minMatchCharLength,includeMatches:u=p.includeMatches,ignoreLocation:l=p.ignoreLocation}={}){if(e.length>re)throw new Error(it(re));const h=e.length,f=t.length,m=Math.max(0,Math.min(n,f));let g=c,x=m;const S=a>1||u,N=S?Array(f):[];let j;for(;(j=t.indexOf(e,x))>-1;){let E=ue(e,{currentLocation:j,expectedLocation:m,distance:r,ignoreLocation:l});if(g=Math.min(E,g),x=j+h,S){let C=0;for(;C<h;)N[j+C]=1,C+=1}}x=-1;let L=[],Q=1,z=h+f;const ie=1<<h-1;for(let E=0;E<h;E+=1){let C=0,B=z;for(;C<B;)ue(e,{errors:E,currentLocation:m+B,expectedLocation:m,distance:r,ignoreLocation:l})<=g?C=B:z=B,B=Math.floor((z-C)/2+C);z=B;let P=Math.max(1,m-B+1),K=o?f:Math.min(m+B,f)+h,W=Array(K+2);W[K+1]=(1<<E)-1;for(let _=K;_>=P;_-=1){let q=_-1,ae=s[t.charAt(q)];if(S&&(N[q]=+!!ae),W[_]=(W[_+1]<<1|1)&ae,E&&(W[_]|=(L[_+1]|L[_])<<1|1|L[_+1]),W[_]&ie&&(Q=ue(e,{errors:E,currentLocation:q,expectedLocation:m,distance:r,ignoreLocation:l}),Q<=g)){if(g=Q,x=q,x<=m)break;P=Math.max(1,2*m-x)}}if(ue(e,{errors:E+1,currentLocation:m,expectedLocation:m,distance:r,ignoreLocation:l})>g)break;L=W}const U={isMatch:x>=0,score:Math.max(.001,Q)};if(S){const E=At(N,a);E.length?u&&(U.indices=E):U.isMatch=!1}return U}function xt(t){let e={};for(let s=0,n=t.length;s<n;s+=1){const r=t.charAt(s);e[r]=(e[r]||0)|1<<n-s-1}return e}const le=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 Oe{constructor(e,{location:s=p.location,threshold:n=p.threshold,distance:r=p.distance,includeMatches:c=p.includeMatches,findAllMatches:o=p.findAllMatches,minMatchCharLength:a=p.minMatchCharLength,isCaseSensitive:u=p.isCaseSensitive,ignoreDiacritics:l=p.ignoreDiacritics,ignoreLocation:h=p.ignoreLocation}={}){if(this.options={location:s,threshold:n,distance:r,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?le(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const f=(g,x)=>{this.chunks.push({pattern:g,alphabet:xt(g),startIndex:x})},m=this.pattern.length;if(m>re){let g=0;const x=m%re,S=m-x;for(;g<S;)f(this.pattern.substr(g,re),g),g+=re;if(x){const N=m-re;f(this.pattern.substr(N),N)}}else f(this.pattern,0)}searchIn(e){const{isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=s?e:e.toLowerCase(),e=n?le(e):e,this.pattern===e){let S={isMatch:!0,score:0};return r&&(S.indices=[[0,e.length-1]]),S}const{location:c,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let f=[],m=0,g=!1;this.chunks.forEach(({pattern:S,alphabet:N,startIndex:j})=>{const{isMatch:L,score:Q,indices:z}=yt(e,S,N,{location:c+j,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:r,ignoreLocation:h});L&&(g=!0),m+=Q,L&&z&&(f=[...f,...z])});let x={isMatch:g,score:g?m/this.chunks.length:1};return g&&r&&(x.indices=f),x}}class se{constructor(e){this.pattern=e}static isMultiMatch(e){return ke(e,this.multiRegex)}static isSingleMatch(e){return ke(e,this.singleRegex)}search(){}}function ke(t,e){const s=t.match(e);return s?s[1]:null}class Et extends se{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const s=e===this.pattern;return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class Ct extends se{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const n=e.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class wt extends se{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const s=e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class Ft extends se{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const s=!e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class Mt extends se{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const s=e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class It extends se{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const s=!e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class ze extends se{constructor(e,{location:s=p.location,threshold:n=p.threshold,distance:r=p.distance,includeMatches:c=p.includeMatches,findAllMatches:o=p.findAllMatches,minMatchCharLength:a=p.minMatchCharLength,isCaseSensitive:u=p.isCaseSensitive,ignoreDiacritics:l=p.ignoreDiacritics,ignoreLocation:h=p.ignoreLocation}={}){super(e),this._bitapSearch=new Oe(e,{location:s,threshold:n,distance:r,includeMatches:c,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 Qe extends se{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let s=0,n;const r=[],c=this.pattern.length;for(;(n=e.indexOf(this.pattern,s))>-1;)s=n+c,r.push([n,s-1]);const o=!!r.length;return{isMatch:o,score:o?0:1,indices:r}}}const pe=[Et,Qe,wt,Ft,It,Mt,Ct,ze],je=pe.length,Dt=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Bt="|";function vt(t,e={}){return t.split(Bt).map(s=>{let n=s.trim().split(Dt).filter(c=>c&&!!c.trim()),r=[];for(let c=0,o=n.length;c<o;c+=1){const a=n[c];let u=!1,l=-1;for(;!u&&++l<je;){const h=pe[l];let f=h.isMultiMatch(a);f&&(r.push(new h(f,e)),u=!0)}if(!u)for(l=-1;++l<je;){const h=pe[l];let f=h.isSingleMatch(a);if(f){r.push(new h(f,e));break}}}return r})}const St=new Set([ze.type,Qe.type]);class bt{constructor(e,{isCaseSensitive:s=p.isCaseSensitive,ignoreDiacritics:n=p.ignoreDiacritics,includeMatches:r=p.includeMatches,minMatchCharLength:c=p.minMatchCharLength,ignoreLocation:o=p.ignoreLocation,findAllMatches:a=p.findAllMatches,location:u=p.location,threshold:l=p.threshold,distance:h=p.distance}={}){this.query=null,this.options={isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:c,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=s?e:e.toLowerCase(),e=n?le(e):e,this.pattern=e,this.query=vt(this.pattern,this.options)}static condition(e,s){return s.useExtendedSearch}searchIn(e){const s=this.query;if(!s)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:c}=this.options;e=r?e:e.toLowerCase(),e=c?le(e):e;let o=0,a=[],u=0;for(let l=0,h=s.length;l<h;l+=1){const f=s[l];a.length=0,o=0;for(let m=0,g=f.length;m<g;m+=1){const x=f[m],{isMatch:S,indices:N,score:j}=x.search(e);if(S){if(o+=1,u+=j,n){const L=x.constructor.type;St.has(L)?a=[...a,...N]:a.push(N)}}else{u=0,o=0,a.length=0;break}}if(o){let m={isMatch:!0,score:u/o};return n&&(m.indices=a),m}}return{isMatch:!1,score:1}}}const ge=[];function kt(...t){ge.push(...t)}function Ae(t,e){for(let s=0,n=ge.length;s<n;s+=1){let r=ge[s];if(r.condition(t,e))return new r(t,e)}return new Oe(t,e)}const he={AND:"$and",OR:"$or"},ye={PATH:"$path",PATTERN:"$val"},xe=t=>!!(t[he.AND]||t[he.OR]),jt=t=>!!t[ye.PATH],Nt=t=>!ee(t)&&Le(t)&&!xe(t),Ne=t=>({[he.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function We(t,e,{auto:s=!0}={}){const n=r=>{let c=Object.keys(r);const o=jt(r);if(!o&&c.length>1&&!xe(r))return n(Ne(r));if(Nt(r)){const u=o?r[ye.PATH]:c[0],l=o?r[ye.PATTERN]:r[u];if(!Z(l))throw new Error(rt(u));const h={keyId:me(u),pattern:l};return s&&(h.searcher=Ae(l,e)),h}let a={children:[],operator:c[0]};return c.forEach(u=>{const l=r[u];ee(l)&&l.forEach(h=>{a.children.push(n(h))})}),a};return xe(t)||(t=Ne(t)),n(t)}function _t(t,{ignoreFieldNorm:e=p.ignoreFieldNorm}){t.forEach(s=>{let n=1;s.matches.forEach(({key:r,norm:c,score:o})=>{const a=r?r.weight:null;n*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:c))}),s.score=n})}function Rt(t,e){const s=t.matches;e.matches=[],O(s)&&s.forEach(n=>{if(!O(n.indices)||!n.indices.length)return;const{indices:r,value:c}=n;let o={indices:r,value:c};n.key&&(o.key=n.key.src),n.idx>-1&&(o.refIndex=n.idx),e.matches.push(o)})}function $t(t,e){e.score=t.score}function Lt(t,e,{includeMatches:s=p.includeMatches,includeScore:n=p.includeScore}={}){const r=[];return s&&r.push(Rt),n&&r.push($t),t.map(c=>{const{idx:o}=c,a={item:e[o],refIndex:o};return r.length&&r.forEach(u=>{u(c,a)}),a})}class X{constructor(e,s={},n){this.options={...p,...s},this.options.useExtendedSearch,this._keyStore=new at(this.options.keys),this.setCollection(e,n)}setCollection(e,s){if(this._docs=e,s&&!(s instanceof Ce))throw new Error(nt);this._myIndex=s||Ke(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){O(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const s=[];for(let n=0,r=this._docs.length;n<r;n+=1){const c=this._docs[n];e(c,n)&&(this.removeAt(n),n-=1,r-=1,s.push(c))}return s}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:s=-1}={}){const{includeMatches:n,includeScore:r,shouldSort:c,sortFn:o,ignoreFieldNorm:a}=this.options;let u=Z(e)?Z(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return _t(u,{ignoreFieldNorm:a}),c&&u.sort(o),$e(s)&&s>-1&&(u=u.slice(0,s)),Lt(u,this._docs,{includeMatches:n,includeScore:r})}_searchStringList(e){const s=Ae(e,this.options),{records:n}=this._myIndex,r=[];return n.forEach(({v:c,i:o,n:a})=>{if(!O(c))return;const{isMatch:u,score:l,indices:h}=s.searchIn(c);u&&r.push({item:c,idx:o,matches:[{score:l,value:c,norm:a,indices:h}]})}),r}_searchLogical(e){const s=We(e,this.options),n=(a,u,l)=>{if(!a.children){const{keyId:f,searcher:m}=a,g=this._findMatches({key:this._keyStore.get(f),value:this._myIndex.getValueForItemAtKeyId(u,f),searcher:m});return g&&g.length?[{idx:l,item:u,matches:g}]:[]}const h=[];for(let f=0,m=a.children.length;f<m;f+=1){const g=a.children[f],x=n(g,u,l);if(x.length)h.push(...x);else if(a.operator===he.AND)return[]}return h},r=this._myIndex.records,c={},o=[];return r.forEach(({$:a,i:u})=>{if(O(a)){let l=n(s,a,u);l.length&&(c[u]||(c[u]={idx:u,item:a,matches:[]},o.push(c[u])),l.forEach(({matches:h})=>{c[u].matches.push(...h)}))}}),o}_searchObjectList(e){const s=Ae(e,this.options),{keys:n,records:r}=this._myIndex,c=[];return r.forEach(({$:o,i:a})=>{if(!O(o))return;let u=[];n.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:s}))}),u.length&&c.push({idx:a,item:o,matches:u})}),c}_findMatches({key:e,value:s,searcher:n}){if(!O(s))return[];let r=[];if(ee(s))s.forEach(({v:c,i:o,n:a})=>{if(!O(c))return;const{isMatch:u,score:l,indices:h}=n.searchIn(c);u&&r.push({score:l,key:e,value:c,idx:o,norm:a,indices:h})});else{const{v:c,n:o}=s,{isMatch:a,score:u,indices:l}=n.searchIn(c);a&&r.push({score:u,key:e,value:c,norm:o,indices:l})}return r}}X.version="7.1.0";X.createIndex=Ke;X.parseIndex=gt;X.config=p;X.parseQuery=We;kt(bt);const _e={".ts":"file-code",".tsx":"atom",".js":"file-code",".jsx":"atom",".py":"file-code",".rs":"file-code",".go":"file-code",".md":"file-text",".json":"clipboard",".yaml":"gear",".yml":"gear",".css":"palette",".scss":"palette",".html":"globe",".sql":"database",".sh":"terminal",".env":"lock",".toml":"gear",".lock":"lock",default:"file-text"};function Tt(t){switch(t){case"scout":return"class-scout";case"builder":return"class-builder";case"debugger":return"class-debugger";case"architect":return"class-architect";case"warrior":return"class-warrior";case"support":return"class-support";case"boss":return"class-boss";default:return"class-default"}}function Pt(t,e=16){var r;const s="."+(((r=t.split(".").pop())==null?void 0:r.toLowerCase())??""),n=_e[s]||_e.default;return d.jsx(J,{name:n,size:e})}function Jt(t,e=16){return d.jsx(J,{name:Tt(t),size:e,weight:"fill"})}function Ve(t){const e=Math.floor(t/1e3),s=Math.floor(e/60),n=Math.floor(s/60),r=Math.floor(n/24);return r>0?`${r}d ${n%24}h ago`:n>0?`${n}h ${s%60}m ago`:s>0?`${s}m ago`:"just now"}function Xt(t){const s=Date.now()-t;return Ve(s)}function Re(t){switch(t){case"agent":return"Agent";case"command":return"Command";case"area":return"Area";case"modified-file":return"Changed";case"building":return"Server";default:return t}}const Kt=["command","agent","building","area","modified-file"];function Ot({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Ge(),f=He(),m=Je(),g=Xe(),x=y.useRef(e);x.current=e;const S=y.useRef(s);S.current=s;const N=y.useRef(n);N.current=n;const j=y.useRef(r);j.current=r;const L=y.useRef(c);L.current=c;const Q=y.useRef(o);Q.current=o;const z=y.useRef(a);z.current=a;const ie=y.useRef(u);ie.current=u;const U=y.useRef(l);U.current=l;const[E,C]=y.useState(""),[B,P]=y.useState(0);y.useEffect(()=>{t&&(C(""),P(0))},[t]);const K=te.getShortcuts(),W=y.useMemo(()=>{if(!t)return[];const i=K.find(I=>I.id==="spawn-agent"),M=K.find(I=>I.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:i?ve(i):"Alt+N",icon:d.jsx(J,{name:"plus",size:16}),action:()=>{x.current(),S.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:M?ve(M):"Ctrl+K",icon:d.jsx(J,{name:"dashboard",size:16}),action:()=>{x.current(),N.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:d.jsx(J,{name:"gear",size:16}),action:()=>{x.current(),j.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:d.jsx(J,{name:"chart-line",size:16}),action:()=>{var I;x.current(),(I=U.current)==null||I.call(U)}}]},[t,K]),oe=y.useMemo(()=>t?Array.from(h.values()).map(i=>{const M=(g||[]).filter(T=>T.agentId===i.id).map(T=>T.filePath),I=[...new Set(M)],D=I.map(T=>T.split("/").pop()||T),b=[];i.lastAssignedTask&&b.push(i.lastAssignedTask);const R=`${i.class} • ${i.status} • ${i.cwd}`;let k=`${i.name} ${R}`;D.length>0&&(k+=` ${D.join(" ")} ${I.join(" ")}`),b.length>0&&(k+=` ${b.join(" ")}`);const Y=Date.now()-i.lastActivity;let G;return i.lastAssignedTask&&(i.lastAssignedTask.length>150?G=i.lastAssignedTask.slice(0,150)+"...":G=i.lastAssignedTask),{id:`agent-${i.id}`,type:"agent",title:i.name,subtitle:R,lastUserInput:G,timeAway:Y,icon:d.jsx(Ze,{agent:i,size:20}),_searchText:k,_modifiedFiles:I,_userQueries:b,action:()=>{x.current(),te.selectAgent(i.id),te.getState().viewMode!=="flat"&&te.requestTerminalExpand()}}}):[],[t,h,g]),_=y.useMemo(()=>t?Array.from(f.values()).map(i=>{var M;return{id:`area-${i.id}`,type:"area",title:i.name,subtitle:`${i.assignedAgentIds.length} agents • ${((M=i.directories)==null?void 0:M.length)||0} folders`,icon:d.jsx(J,{name:"map",size:16}),action:()=>{x.current(),te.selectArea(i.id)}}}):[],[t,f]),q=y.useMemo(()=>t?Array.from(m.values()).filter(i=>i.type==="server"||i.type==="boss"||i.type==="database").map(i=>{var k,Y,G,T;const M=i.status==="running"?"#4ade80":i.status==="stopped"?"#f87171":"#facc15",I=i.type==="boss"?"crown":i.type==="database"?"database":"desktop";let b=`${i.type==="boss"?"Boss":i.type==="database"?"Database":"Server"} • ${i.status}`;if(i.type==="database"&&((Y=(k=i.database)==null?void 0:k.connections)!=null&&Y.length)){const $=i.database.connections[0];b+=` • ${$.engine} @ ${$.host}`}else i.cwd&&(b+=` • ${i.cwd}`);let R=`${i.name} ${i.type} ${i.status} ${i.cwd||""} ${((G=i.pm2)==null?void 0:G.name)||""}`;if(i.type==="database"&&((T=i.database)!=null&&T.connections))for(const $ of i.database.connections)R+=` ${$.name} ${$.engine} ${$.host} ${$.database||""} mysql postgresql sql`;return{id:`building-${i.id}`,type:"building",title:i.name,subtitle:b,icon:d.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[d.jsx(J,{name:"status-pending",size:10,weight:"fill",color:M}),d.jsx(J,{name:I,size:16})]}),_searchText:R,action:()=>{var $;x.current(),i.type==="boss"?z.current(i.id):i.type==="database"?ie.current(i.id):($=i.pm2)!=null&&$.enabled&&Q.current(i.id)}}}):[],[t,m]),ae=y.useMemo(()=>{if(!t)return[];const i=g||[],M=new Set,I=[];for(const D of i){if(M.has(D.filePath))continue;M.add(D.filePath);const b=D.filePath.split("/").pop()||D.filePath,R=D.action==="created"?"Created":D.action==="modified"?"Modified":D.action==="deleted"?"Deleted":"Read";if(I.push({id:`modified-${D.filePath}-${D.timestamp}`,type:"modified-file",title:b,subtitle:`${R} by ${D.agentName} • ${D.filePath}`,matchedText:D.filePath,icon:D.action==="deleted"?d.jsx(J,{name:"trash",size:16}):Pt(D.filePath),action:()=>{x.current();const k=Array.from(te.getState().areas.values());for(const Y of k)for(const G of Y.directories||[])if(D.filePath.startsWith(G)){te.setFileViewerPath(D.filePath),L.current(Y.id);return}te.selectAgent(D.agentId)}}),I.length>=50)break}return I},[t,g]),we=y.useMemo(()=>new X(oe,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[oe]),Fe=y.useMemo(()=>new X(W,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[W]),Me=y.useMemo(()=>new X(_,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[_]),Ie=y.useMemo(()=>new X(ae,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ae]),De=y.useMemo(()=>new X(q,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[q]),V=y.useMemo(()=>{if(!E.trim()){const A=[];A.push(...q);const w=[...oe].sort((v,H)=>{const ce=v.timeAway??0,ne=H.timeAway??0;return ce-ne});A.push(...w),A.push(...W.slice(0,2)),A.push(..._.slice(0,2));const F={};return Kt.forEach((v,H)=>{F[v]=H}),A.sort((v,H)=>(F[v.type]??999)-(F[H.type]??999)),A}const i=E.trim().toLowerCase(),M=we.search(E).slice(0,8),I=Fe.search(E).slice(0,3),D=Me.search(E).slice(0,2),b=Ie.search(E).slice(0,3),R=De.search(E).filter(A=>{const w=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(i)||w<=.2}).slice(0,4),k={agent:5,building:4,command:3,area:2,"modified-file":1},Y=A=>{if(!i)return 1;const w=A.title.toLowerCase();return w===i?6:w.startsWith(i)?5:w.split(/[^a-z0-9]+/i).includes(i)?4:w.includes(i)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(i)?2:1},G=(A,w)=>{const F=(1-Math.min(1,w??1))*4;return Y(A)*100+(k[A.type]??0)*5+F},T=new Map,$=(A,w)=>{const F=T.get(A.type),v={item:A,score:G(A,w)};F?F.push(v):T.set(A.type,[v])};for(const A of M){const w={...A.item};if(w._modifiedFiles&&w._modifiedFiles.length>0){const F=w._modifiedFiles.filter(v=>{var ne;const H=((ne=v.split("/").pop())==null?void 0:ne.toLowerCase())||"",ce=v.toLowerCase();return H.includes(i)||ce.includes(i)});F.length>0&&(w.matchedFiles=F)}if(w._userQueries&&w._userQueries.length>0){const F=w._userQueries.find(v=>v.toLowerCase().includes(i));if(F)if(F.length>200){const H=F.toLowerCase().indexOf(i),ce=Math.max(0,H-60),ne=Math.min(F.length,H+i.length+100);w.matchedQuery=(ce>0?"...":"")+F.slice(ce,ne)+(ne<F.length?"...":"")}else w.matchedQuery=F}$(w,A.score)}for(const A of R)$(A.item,A.score);for(const A of I)$(A.item,A.score);for(const A of D)$(A.item,A.score);for(const A of b)$(A.item,A.score);for(const[A,w]of T)w.sort((F,v)=>v.score!==F.score?v.score-F.score:A==="agent"?(F.item.timeAway??Number.POSITIVE_INFINITY)-(v.item.timeAway??Number.POSITIVE_INFINITY):0);const Be=[];return Array.from(T.values()).sort((A,w)=>{var F,v;return(((F=w[0])==null?void 0:F.score)??-1)-(((v=A[0])==null?void 0:v.score)??-1)}).forEach(A=>{for(const w of A)Be.push(w.item)}),Be},[E,we,Fe,Me,Ie,De,W,oe,_,q]);y.useEffect(()=>{B>=V.length&&P(Math.max(0,V.length-1))},[V.length,B]);const Ye=y.useCallback(i=>{if(i.altKey&&!i.ctrlKey&&!i.metaKey&&(i.key==="p"||i.key==="n"||i.key==="P"||i.key==="N")){i.preventDefault(),i.stopPropagation(),i.nativeEvent.stopImmediatePropagation();const M=i.key.toLowerCase();P(M==="p"?I=>I>0?I-1:V.length-1:I=>I<V.length-1?I+1:0);return}switch(i.key){case"Escape":i.preventDefault(),x.current();break;case"ArrowUp":i.preventDefault(),P(M=>M>0?M-1:V.length-1);break;case"ArrowDown":i.preventDefault(),P(M=>M<V.length-1?M+1:0);break;case"Enter":i.preventDefault(),V[B]&&V[B].action();break}},[V,B]),Ue=y.useCallback((i,M)=>{if(!M||!i)return i;const I=i.toLowerCase(),D=M.toLowerCase(),b=[];let R=0,k=I.indexOf(D),Y=0;for(;k!==-1;)k>R&&b.push(i.slice(R,k)),b.push(de.createElement("mark",{key:Y++,className:"spotlight-highlight"},i.slice(k,k+M.length))),R=k+M.length,k=I.indexOf(D,R);return R<i.length&&b.push(i.slice(R)),b.length>0?de.createElement(de.Fragment,null,...b):i},[]);return{query:E,setQuery:C,selectedIndex:B,setSelectedIndex:P,results:V,handleKeyDown:Ye,highlightMatch:Ue}}const zt=y.forwardRef(function({query:e,onQueryChange:s,onKeyDown:n,onResetSelection:r},c){const{t:o}=Ee(["common"]);return d.jsxs("div",{className:"spotlight-input-wrapper",children:[d.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),d.jsx("input",{ref:c,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{s(a.target.value),r()},onKeyDown:n,autoFocus:!0,spellCheck:!1}),d.jsxs("div",{className:"spotlight-input-hints",children:[d.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Qt=y.memo(function({result:e,isSelected:s,query:n,highlightMatch:r,onClick:c,onMouseEnter:o}){const a=e.activityText||e.matchedFiles&&e.matchedFiles.length>0||e.matchedQuery;return d.jsxs("div",{className:`spotlight-item ${s?"selected":""} ${e.activityText?"has-activity":""}`,onClick:c,onMouseEnter:o,role:"option","aria-selected":s,children:[d.jsx("span",{className:"spotlight-item-icon","aria-hidden":"true",children:e.icon}),d.jsxs("div",{className:"spotlight-item-content",children:[d.jsxs("div",{className:"spotlight-item-header",children:[d.jsx("span",{className:"spotlight-item-title",children:r(e.title,n)}),d.jsx("span",{className:`spotlight-item-type ${e.type}`,"aria-label":Re(e.type),children:Re(e.type)})]}),e.subtitle&&d.jsx("span",{className:"spotlight-item-subtitle",children:r(e.subtitle,n)}),e.activityText&&d.jsx("span",{className:"spotlight-item-activity",children:r(e.activityText,n)}),a&&d.jsxs("div",{className:"spotlight-item-details",children:[e.matchedFiles&&e.matchedFiles.length>0&&d.jsx("span",{className:"spotlight-item-files",children:e.matchedFiles.map((u,l)=>d.jsxs("span",{className:"file-badge",children:[l>0&&d.jsx("span",{className:"file-separator",children:"•"}),r(u.split("/").pop()||u,n)]},u))}),e.matchedQuery&&d.jsx("span",{className:"spotlight-item-query",children:r(e.matchedQuery,n)})]}),e.timeAway!==void 0&&d.jsx("span",{className:"spotlight-item-time",children:d.jsxs("span",{className:"spotlight-time-away",children:["Idle: ",Ve(e.timeAway)]})}),e.lastUserInput&&!e.matchedQuery&&d.jsxs("span",{className:"spotlight-item-last-input",children:['"',r(e.lastUserInput,n),'"']})]})]})}),Wt=y.forwardRef(function({results:e,selectedIndex:s,query:n,highlightMatch:r,onSelectIndex:c},o){const{t:a}=Ee(["terminal"]),u=y.useRef(!1);y.useEffect(()=>{u.current=!1},[e]),y.useEffect(()=>{const f=typeof o=="function"?null:o==null?void 0:o.current;if(!f)return;const m=()=>{u.current=!0};return f.addEventListener("mousemove",m),()=>{f.removeEventListener("mousemove",m)}},[o,e]);const l={command:a("terminal:spotlight.categories.commands"),agent:a("terminal:spotlight.categories.agents"),building:a("terminal:spotlight.categories.infrastructure"),area:a("terminal:spotlight.categories.areas"),"modified-file":a("terminal:spotlight.categories.modifiedFiles")},h=y.useMemo(()=>{const f=[];let m=null,g=[];return e.forEach((x,S)=>{x.type!==m&&(m!==null&&g.length>0&&f.push([m,g]),m=x.type,g=[]),g.push({result:x,index:S})}),m!==null&&g.length>0&&f.push([m,g]),f},[e]);return y.useEffect(()=>{if(!o||typeof o=="function")return;const f=o.current;if(!f)return;const m=f.querySelector(".spotlight-item.selected");m&&m.scrollIntoView({block:"nearest",behavior:"smooth"})},[s,o]),e.length===0?d.jsx("div",{className:"spotlight-results",ref:o,children:d.jsx("div",{className:"spotlight-empty",children:a("terminal:spotlight.noResults")})}):d.jsx("div",{className:"spotlight-results",ref:o,children:h.map(([f,m])=>d.jsxs("div",{children:[h.length>1&&d.jsx("div",{className:"spotlight-category-header",children:l[f]||f}),m.map(({result:g,index:x})=>d.jsx(Qt,{result:g,isSelected:x===s,query:n,highlightMatch:r,onClick:()=>g.action(),onMouseEnter:()=>{u.current&&c(x)}},g.id))]},f))})}),Vt=y.memo(function(){const{t:e}=Ee(["terminal"]);return d.jsxs("div",{className:"spotlight-footer",children:[d.jsxs("div",{className:"spotlight-footer-left",children:[d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"↑"}),d.jsx("kbd",{children:"↓"})," ",d.jsx("kbd",{children:"Alt+N"}),d.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]})]}),d.jsx("div",{className:"spotlight-footer-right",children:d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Yt=768;function Zt({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=y.useRef(null),f=y.useRef(null),m=y.useRef(null),g=y.useRef(0),{query:x,setQuery:S,selectedIndex:N,setSelectedIndex:j,results:L,handleKeyDown:Q,highlightMatch:z}=Ot({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});g.current=L.length,y.useEffect(()=>{t&&setTimeout(()=>{var E;(E=h.current)==null||E.focus()},50)},[t]),y.useEffect(()=>{if(!t)return;const E=window.visualViewport;if(!E||window.innerWidth>Yt)return;const C=()=>{const B=f.current;B&&(B.style.height=`${E.height}px`,B.style.top=`${E.offsetTop}px`)};return C(),E.addEventListener("resize",C),E.addEventListener("scroll",C),()=>{E.removeEventListener("resize",C),E.removeEventListener("scroll",C);const B=f.current;B&&(B.style.height="",B.style.top="")}},[t]),y.useEffect(()=>{if(!t)return;const E=C=>{if(C.key==="Escape"){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation(),e();return}if(C.altKey&&!C.ctrlKey&&!C.metaKey&&(C.key==="n"||C.key==="p"||C.key==="N"||C.key==="P")){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation();const B=C.key.toLowerCase(),P=g.current;j(B==="p"?K=>K>0?K-1:P-1:K=>K<P-1?K+1:0);return}};return window.addEventListener("keydown",E,{capture:!0}),()=>{window.removeEventListener("keydown",E,{capture:!0})}},[t,e]);const ie=y.useCallback(E=>{E.target===E.currentTarget&&e()},[e]),U=y.useCallback(()=>{j(0)},[j]);return t?d.jsx("div",{ref:f,className:"spotlight-overlay",onClick:ie,children:d.jsxs("div",{className:"spotlight-modal",children:[d.jsx(zt,{ref:h,query:x,onQueryChange:S,onKeyDown:Q,onResetSelection:U}),d.jsx(Wt,{ref:m,results:L,selectedIndex:N,query:x,highlightMatch:z,onSelectIndex:j}),d.jsx(Vt,{})]})}):null}export{_e as FILE_ICON_NAMES,Zt as Spotlight,Vt as SpotlightFooter,zt as SpotlightInput,Qt as SpotlightItem,Wt as SpotlightResults,Ve as formatDuration,Xt as formatRelativeTime,Jt as getAgentIcon,Pt as getFileIconFromPath,Re as getTypeLabel,Ot as useSpotlightSearch};
1
+ import{j as d,I as J,aj as Ge,U as He,W as Je,bY as Xe,r as y,s as te,bZ as ve,_ as Ze,ad as de,u as Ee}from"./main-CyZg1kKu.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function ee(t){return Array.isArray?Array.isArray(t):Te(t)==="[object Array]"}function qe(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function et(t){return t==null?"":qe(t)}function Z(t){return typeof t=="string"}function $e(t){return typeof t=="number"}function tt(t){return t===!0||t===!1||st(t)&&Te(t)=="[object Boolean]"}function Le(t){return typeof t=="object"}function st(t){return Le(t)&&t!==null}function O(t){return t!=null}function fe(t){return!t.trim().length}function Te(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const nt="Incorrect 'index' type",rt=t=>`Invalid value for key ${t}`,it=t=>`Pattern length exceeds max of ${t}.`,ct=t=>`Missing ${t} property in key`,ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Se=Object.prototype.hasOwnProperty;class at{constructor(e){this._keys=[],this._keyMap={};let s=0;e.forEach(n=>{let r=Pe(n);this._keys.push(r),this._keyMap[r.id]=r,s+=r.weight}),this._keys.forEach(n=>{n.weight/=s})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function Pe(t){let e=null,s=null,n=null,r=1,c=null;if(Z(t)||ee(t))n=t,e=be(t),s=me(t);else{if(!Se.call(t,"name"))throw new Error(ct("name"));const o=t.name;if(n=o,Se.call(t,"weight")&&(r=t.weight,r<=0))throw new Error(ot(o));e=be(o),s=me(o),c=t.getFn}return{path:e,id:s,weight:r,src:n,getFn:c}}function be(t){return ee(t)?t:t.split(".")}function me(t){return ee(t)?t.join("."):t}function ut(t,e){let s=[],n=!1;const r=(c,o,a)=>{if(O(c))if(!o[a])s.push(c);else{let u=o[a];const l=c[u];if(!O(l))return;if(a===o.length-1&&(Z(l)||$e(l)||tt(l)))s.push(et(l));else if(ee(l)){n=!0;for(let h=0,f=l.length;h<f;h+=1)r(l[h],o,a+1)}else o.length&&r(l,o,a+1)}};return r(t,Z(e)?e.split("."):e,0),n?s:s[0]}const lt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},ht={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},dt={location:0,threshold:.6,distance:100},ft={useExtendedSearch:!1,getFn:ut,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var p={...ht,...lt,...dt,...ft};const mt=/[^ ]+/g;function pt(t=1,e=3){const s=new Map,n=Math.pow(10,e);return{get(r){const c=r.match(mt).length;if(s.has(c))return s.get(c);const o=1/Math.pow(c,.5*t),a=parseFloat(Math.round(o*n)/n);return s.set(c,a),a},clear(){s.clear()}}}class Ce{constructor({getFn:e=p.getFn,fieldNormWeight:s=p.fieldNormWeight}={}){this.norm=pt(s,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((s,n)=>{this._keysMap[s.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,Z(this.docs[0])?this.docs.forEach((e,s)=>{this._addString(e,s)}):this.docs.forEach((e,s)=>{this._addObject(e,s)}),this.norm.clear())}add(e){const s=this.size();Z(e)?this._addString(e,s):this._addObject(e,s)}removeAt(e){this.records.splice(e,1);for(let s=e,n=this.size();s<n;s+=1)this.records[s].i-=1}getValueForItemAtKeyId(e,s){return e[this._keysMap[s]]}size(){return this.records.length}_addString(e,s){if(!O(e)||fe(e))return;let n={v:e,i:s,n:this.norm.get(e)};this.records.push(n)}_addObject(e,s){let n={i:s,$:{}};this.keys.forEach((r,c)=>{let o=r.getFn?r.getFn(e):this.getFn(e,r.path);if(O(o)){if(ee(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(O(h))if(Z(h)&&!fe(h)){let f={v:h,i:l,n:this.norm.get(h)};a.push(f)}else ee(h)&&h.forEach((f,m)=>{u.push({nestedArrIndex:m,value:f})})}n.$[c]=a}else if(Z(o)&&!fe(o)){let a={v:o,n:this.norm.get(o)};n.$[c]=a}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function Ke(t,e,{getFn:s=p.getFn,fieldNormWeight:n=p.fieldNormWeight}={}){const r=new Ce({getFn:s,fieldNormWeight:n});return r.setKeys(t.map(Pe)),r.setSources(e),r.create(),r}function gt(t,{getFn:e=p.getFn,fieldNormWeight:s=p.fieldNormWeight}={}){const{keys:n,records:r}=t,c=new Ce({getFn:e,fieldNormWeight:s});return c.setKeys(n),c.setIndexRecords(r),c}function ue(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:r=p.distance,ignoreLocation:c=p.ignoreLocation}={}){const o=e/t.length;if(c)return o;const a=Math.abs(n-s);return r?o+a/r:a?1:o}function At(t=[],e=p.minMatchCharLength){let s=[],n=-1,r=-1,c=0;for(let o=t.length;c<o;c+=1){let a=t[c];a&&n===-1?n=c:!a&&n!==-1&&(r=c-1,r-n+1>=e&&s.push([n,r]),n=-1)}return t[c-1]&&c-n>=e&&s.push([n,c-1]),s}const re=32;function yt(t,e,s,{location:n=p.location,distance:r=p.distance,threshold:c=p.threshold,findAllMatches:o=p.findAllMatches,minMatchCharLength:a=p.minMatchCharLength,includeMatches:u=p.includeMatches,ignoreLocation:l=p.ignoreLocation}={}){if(e.length>re)throw new Error(it(re));const h=e.length,f=t.length,m=Math.max(0,Math.min(n,f));let g=c,x=m;const S=a>1||u,N=S?Array(f):[];let j;for(;(j=t.indexOf(e,x))>-1;){let E=ue(e,{currentLocation:j,expectedLocation:m,distance:r,ignoreLocation:l});if(g=Math.min(E,g),x=j+h,S){let C=0;for(;C<h;)N[j+C]=1,C+=1}}x=-1;let L=[],Q=1,z=h+f;const ie=1<<h-1;for(let E=0;E<h;E+=1){let C=0,B=z;for(;C<B;)ue(e,{errors:E,currentLocation:m+B,expectedLocation:m,distance:r,ignoreLocation:l})<=g?C=B:z=B,B=Math.floor((z-C)/2+C);z=B;let P=Math.max(1,m-B+1),K=o?f:Math.min(m+B,f)+h,W=Array(K+2);W[K+1]=(1<<E)-1;for(let _=K;_>=P;_-=1){let q=_-1,ae=s[t.charAt(q)];if(S&&(N[q]=+!!ae),W[_]=(W[_+1]<<1|1)&ae,E&&(W[_]|=(L[_+1]|L[_])<<1|1|L[_+1]),W[_]&ie&&(Q=ue(e,{errors:E,currentLocation:q,expectedLocation:m,distance:r,ignoreLocation:l}),Q<=g)){if(g=Q,x=q,x<=m)break;P=Math.max(1,2*m-x)}}if(ue(e,{errors:E+1,currentLocation:m,expectedLocation:m,distance:r,ignoreLocation:l})>g)break;L=W}const U={isMatch:x>=0,score:Math.max(.001,Q)};if(S){const E=At(N,a);E.length?u&&(U.indices=E):U.isMatch=!1}return U}function xt(t){let e={};for(let s=0,n=t.length;s<n;s+=1){const r=t.charAt(s);e[r]=(e[r]||0)|1<<n-s-1}return e}const le=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 Oe{constructor(e,{location:s=p.location,threshold:n=p.threshold,distance:r=p.distance,includeMatches:c=p.includeMatches,findAllMatches:o=p.findAllMatches,minMatchCharLength:a=p.minMatchCharLength,isCaseSensitive:u=p.isCaseSensitive,ignoreDiacritics:l=p.ignoreDiacritics,ignoreLocation:h=p.ignoreLocation}={}){if(this.options={location:s,threshold:n,distance:r,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?le(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const f=(g,x)=>{this.chunks.push({pattern:g,alphabet:xt(g),startIndex:x})},m=this.pattern.length;if(m>re){let g=0;const x=m%re,S=m-x;for(;g<S;)f(this.pattern.substr(g,re),g),g+=re;if(x){const N=m-re;f(this.pattern.substr(N),N)}}else f(this.pattern,0)}searchIn(e){const{isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=s?e:e.toLowerCase(),e=n?le(e):e,this.pattern===e){let S={isMatch:!0,score:0};return r&&(S.indices=[[0,e.length-1]]),S}const{location:c,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let f=[],m=0,g=!1;this.chunks.forEach(({pattern:S,alphabet:N,startIndex:j})=>{const{isMatch:L,score:Q,indices:z}=yt(e,S,N,{location:c+j,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:r,ignoreLocation:h});L&&(g=!0),m+=Q,L&&z&&(f=[...f,...z])});let x={isMatch:g,score:g?m/this.chunks.length:1};return g&&r&&(x.indices=f),x}}class se{constructor(e){this.pattern=e}static isMultiMatch(e){return ke(e,this.multiRegex)}static isSingleMatch(e){return ke(e,this.singleRegex)}search(){}}function ke(t,e){const s=t.match(e);return s?s[1]:null}class Et extends se{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const s=e===this.pattern;return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class Ct extends se{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const n=e.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class wt extends se{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const s=e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class Ft extends se{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const s=!e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class Mt extends se{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const s=e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class It extends se{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const s=!e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class ze extends se{constructor(e,{location:s=p.location,threshold:n=p.threshold,distance:r=p.distance,includeMatches:c=p.includeMatches,findAllMatches:o=p.findAllMatches,minMatchCharLength:a=p.minMatchCharLength,isCaseSensitive:u=p.isCaseSensitive,ignoreDiacritics:l=p.ignoreDiacritics,ignoreLocation:h=p.ignoreLocation}={}){super(e),this._bitapSearch=new Oe(e,{location:s,threshold:n,distance:r,includeMatches:c,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 Qe extends se{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let s=0,n;const r=[],c=this.pattern.length;for(;(n=e.indexOf(this.pattern,s))>-1;)s=n+c,r.push([n,s-1]);const o=!!r.length;return{isMatch:o,score:o?0:1,indices:r}}}const pe=[Et,Qe,wt,Ft,It,Mt,Ct,ze],je=pe.length,Dt=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Bt="|";function vt(t,e={}){return t.split(Bt).map(s=>{let n=s.trim().split(Dt).filter(c=>c&&!!c.trim()),r=[];for(let c=0,o=n.length;c<o;c+=1){const a=n[c];let u=!1,l=-1;for(;!u&&++l<je;){const h=pe[l];let f=h.isMultiMatch(a);f&&(r.push(new h(f,e)),u=!0)}if(!u)for(l=-1;++l<je;){const h=pe[l];let f=h.isSingleMatch(a);if(f){r.push(new h(f,e));break}}}return r})}const St=new Set([ze.type,Qe.type]);class bt{constructor(e,{isCaseSensitive:s=p.isCaseSensitive,ignoreDiacritics:n=p.ignoreDiacritics,includeMatches:r=p.includeMatches,minMatchCharLength:c=p.minMatchCharLength,ignoreLocation:o=p.ignoreLocation,findAllMatches:a=p.findAllMatches,location:u=p.location,threshold:l=p.threshold,distance:h=p.distance}={}){this.query=null,this.options={isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:c,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=s?e:e.toLowerCase(),e=n?le(e):e,this.pattern=e,this.query=vt(this.pattern,this.options)}static condition(e,s){return s.useExtendedSearch}searchIn(e){const s=this.query;if(!s)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:c}=this.options;e=r?e:e.toLowerCase(),e=c?le(e):e;let o=0,a=[],u=0;for(let l=0,h=s.length;l<h;l+=1){const f=s[l];a.length=0,o=0;for(let m=0,g=f.length;m<g;m+=1){const x=f[m],{isMatch:S,indices:N,score:j}=x.search(e);if(S){if(o+=1,u+=j,n){const L=x.constructor.type;St.has(L)?a=[...a,...N]:a.push(N)}}else{u=0,o=0,a.length=0;break}}if(o){let m={isMatch:!0,score:u/o};return n&&(m.indices=a),m}}return{isMatch:!1,score:1}}}const ge=[];function kt(...t){ge.push(...t)}function Ae(t,e){for(let s=0,n=ge.length;s<n;s+=1){let r=ge[s];if(r.condition(t,e))return new r(t,e)}return new Oe(t,e)}const he={AND:"$and",OR:"$or"},ye={PATH:"$path",PATTERN:"$val"},xe=t=>!!(t[he.AND]||t[he.OR]),jt=t=>!!t[ye.PATH],Nt=t=>!ee(t)&&Le(t)&&!xe(t),Ne=t=>({[he.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function We(t,e,{auto:s=!0}={}){const n=r=>{let c=Object.keys(r);const o=jt(r);if(!o&&c.length>1&&!xe(r))return n(Ne(r));if(Nt(r)){const u=o?r[ye.PATH]:c[0],l=o?r[ye.PATTERN]:r[u];if(!Z(l))throw new Error(rt(u));const h={keyId:me(u),pattern:l};return s&&(h.searcher=Ae(l,e)),h}let a={children:[],operator:c[0]};return c.forEach(u=>{const l=r[u];ee(l)&&l.forEach(h=>{a.children.push(n(h))})}),a};return xe(t)||(t=Ne(t)),n(t)}function _t(t,{ignoreFieldNorm:e=p.ignoreFieldNorm}){t.forEach(s=>{let n=1;s.matches.forEach(({key:r,norm:c,score:o})=>{const a=r?r.weight:null;n*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:c))}),s.score=n})}function Rt(t,e){const s=t.matches;e.matches=[],O(s)&&s.forEach(n=>{if(!O(n.indices)||!n.indices.length)return;const{indices:r,value:c}=n;let o={indices:r,value:c};n.key&&(o.key=n.key.src),n.idx>-1&&(o.refIndex=n.idx),e.matches.push(o)})}function $t(t,e){e.score=t.score}function Lt(t,e,{includeMatches:s=p.includeMatches,includeScore:n=p.includeScore}={}){const r=[];return s&&r.push(Rt),n&&r.push($t),t.map(c=>{const{idx:o}=c,a={item:e[o],refIndex:o};return r.length&&r.forEach(u=>{u(c,a)}),a})}class X{constructor(e,s={},n){this.options={...p,...s},this.options.useExtendedSearch,this._keyStore=new at(this.options.keys),this.setCollection(e,n)}setCollection(e,s){if(this._docs=e,s&&!(s instanceof Ce))throw new Error(nt);this._myIndex=s||Ke(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){O(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const s=[];for(let n=0,r=this._docs.length;n<r;n+=1){const c=this._docs[n];e(c,n)&&(this.removeAt(n),n-=1,r-=1,s.push(c))}return s}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:s=-1}={}){const{includeMatches:n,includeScore:r,shouldSort:c,sortFn:o,ignoreFieldNorm:a}=this.options;let u=Z(e)?Z(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return _t(u,{ignoreFieldNorm:a}),c&&u.sort(o),$e(s)&&s>-1&&(u=u.slice(0,s)),Lt(u,this._docs,{includeMatches:n,includeScore:r})}_searchStringList(e){const s=Ae(e,this.options),{records:n}=this._myIndex,r=[];return n.forEach(({v:c,i:o,n:a})=>{if(!O(c))return;const{isMatch:u,score:l,indices:h}=s.searchIn(c);u&&r.push({item:c,idx:o,matches:[{score:l,value:c,norm:a,indices:h}]})}),r}_searchLogical(e){const s=We(e,this.options),n=(a,u,l)=>{if(!a.children){const{keyId:f,searcher:m}=a,g=this._findMatches({key:this._keyStore.get(f),value:this._myIndex.getValueForItemAtKeyId(u,f),searcher:m});return g&&g.length?[{idx:l,item:u,matches:g}]:[]}const h=[];for(let f=0,m=a.children.length;f<m;f+=1){const g=a.children[f],x=n(g,u,l);if(x.length)h.push(...x);else if(a.operator===he.AND)return[]}return h},r=this._myIndex.records,c={},o=[];return r.forEach(({$:a,i:u})=>{if(O(a)){let l=n(s,a,u);l.length&&(c[u]||(c[u]={idx:u,item:a,matches:[]},o.push(c[u])),l.forEach(({matches:h})=>{c[u].matches.push(...h)}))}}),o}_searchObjectList(e){const s=Ae(e,this.options),{keys:n,records:r}=this._myIndex,c=[];return r.forEach(({$:o,i:a})=>{if(!O(o))return;let u=[];n.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:s}))}),u.length&&c.push({idx:a,item:o,matches:u})}),c}_findMatches({key:e,value:s,searcher:n}){if(!O(s))return[];let r=[];if(ee(s))s.forEach(({v:c,i:o,n:a})=>{if(!O(c))return;const{isMatch:u,score:l,indices:h}=n.searchIn(c);u&&r.push({score:l,key:e,value:c,idx:o,norm:a,indices:h})});else{const{v:c,n:o}=s,{isMatch:a,score:u,indices:l}=n.searchIn(c);a&&r.push({score:u,key:e,value:c,norm:o,indices:l})}return r}}X.version="7.1.0";X.createIndex=Ke;X.parseIndex=gt;X.config=p;X.parseQuery=We;kt(bt);const _e={".ts":"file-code",".tsx":"atom",".js":"file-code",".jsx":"atom",".py":"file-code",".rs":"file-code",".go":"file-code",".md":"file-text",".json":"clipboard",".yaml":"gear",".yml":"gear",".css":"palette",".scss":"palette",".html":"globe",".sql":"database",".sh":"terminal",".env":"lock",".toml":"gear",".lock":"lock",default:"file-text"};function Tt(t){switch(t){case"scout":return"class-scout";case"builder":return"class-builder";case"debugger":return"class-debugger";case"architect":return"class-architect";case"warrior":return"class-warrior";case"support":return"class-support";case"boss":return"class-boss";default:return"class-default"}}function Pt(t,e=16){var r;const s="."+(((r=t.split(".").pop())==null?void 0:r.toLowerCase())??""),n=_e[s]||_e.default;return d.jsx(J,{name:n,size:e})}function Jt(t,e=16){return d.jsx(J,{name:Tt(t),size:e,weight:"fill"})}function Ve(t){const e=Math.floor(t/1e3),s=Math.floor(e/60),n=Math.floor(s/60),r=Math.floor(n/24);return r>0?`${r}d ${n%24}h ago`:n>0?`${n}h ${s%60}m ago`:s>0?`${s}m ago`:"just now"}function Xt(t){const s=Date.now()-t;return Ve(s)}function Re(t){switch(t){case"agent":return"Agent";case"command":return"Command";case"area":return"Area";case"modified-file":return"Changed";case"building":return"Server";default:return t}}const Kt=["command","agent","building","area","modified-file"];function Ot({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Ge(),f=He(),m=Je(),g=Xe(),x=y.useRef(e);x.current=e;const S=y.useRef(s);S.current=s;const N=y.useRef(n);N.current=n;const j=y.useRef(r);j.current=r;const L=y.useRef(c);L.current=c;const Q=y.useRef(o);Q.current=o;const z=y.useRef(a);z.current=a;const ie=y.useRef(u);ie.current=u;const U=y.useRef(l);U.current=l;const[E,C]=y.useState(""),[B,P]=y.useState(0);y.useEffect(()=>{t&&(C(""),P(0))},[t]);const K=te.getShortcuts(),W=y.useMemo(()=>{if(!t)return[];const i=K.find(I=>I.id==="spawn-agent"),M=K.find(I=>I.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:i?ve(i):"Alt+N",icon:d.jsx(J,{name:"plus",size:16}),action:()=>{x.current(),S.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:M?ve(M):"Ctrl+K",icon:d.jsx(J,{name:"dashboard",size:16}),action:()=>{x.current(),N.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:d.jsx(J,{name:"gear",size:16}),action:()=>{x.current(),j.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:d.jsx(J,{name:"chart-line",size:16}),action:()=>{var I;x.current(),(I=U.current)==null||I.call(U)}}]},[t,K]),oe=y.useMemo(()=>t?Array.from(h.values()).map(i=>{const M=(g||[]).filter(T=>T.agentId===i.id).map(T=>T.filePath),I=[...new Set(M)],D=I.map(T=>T.split("/").pop()||T),b=[];i.lastAssignedTask&&b.push(i.lastAssignedTask);const R=`${i.class} • ${i.status} • ${i.cwd}`;let k=`${i.name} ${R}`;D.length>0&&(k+=` ${D.join(" ")} ${I.join(" ")}`),b.length>0&&(k+=` ${b.join(" ")}`);const Y=Date.now()-i.lastActivity;let G;return i.lastAssignedTask&&(i.lastAssignedTask.length>150?G=i.lastAssignedTask.slice(0,150)+"...":G=i.lastAssignedTask),{id:`agent-${i.id}`,type:"agent",title:i.name,subtitle:R,lastUserInput:G,timeAway:Y,icon:d.jsx(Ze,{agent:i,size:20}),_searchText:k,_modifiedFiles:I,_userQueries:b,action:()=>{x.current(),te.selectAgent(i.id),te.getState().viewMode!=="flat"&&te.requestTerminalExpand()}}}):[],[t,h,g]),_=y.useMemo(()=>t?Array.from(f.values()).map(i=>{var M;return{id:`area-${i.id}`,type:"area",title:i.name,subtitle:`${i.assignedAgentIds.length} agents • ${((M=i.directories)==null?void 0:M.length)||0} folders`,icon:d.jsx(J,{name:"map",size:16}),action:()=>{x.current(),te.selectArea(i.id)}}}):[],[t,f]),q=y.useMemo(()=>t?Array.from(m.values()).filter(i=>i.type==="server"||i.type==="boss"||i.type==="database").map(i=>{var k,Y,G,T;const M=i.status==="running"?"#4ade80":i.status==="stopped"?"#f87171":"#facc15",I=i.type==="boss"?"crown":i.type==="database"?"database":"desktop";let b=`${i.type==="boss"?"Boss":i.type==="database"?"Database":"Server"} • ${i.status}`;if(i.type==="database"&&((Y=(k=i.database)==null?void 0:k.connections)!=null&&Y.length)){const $=i.database.connections[0];b+=` • ${$.engine} @ ${$.host}`}else i.cwd&&(b+=` • ${i.cwd}`);let R=`${i.name} ${i.type} ${i.status} ${i.cwd||""} ${((G=i.pm2)==null?void 0:G.name)||""}`;if(i.type==="database"&&((T=i.database)!=null&&T.connections))for(const $ of i.database.connections)R+=` ${$.name} ${$.engine} ${$.host} ${$.database||""} mysql postgresql sql`;return{id:`building-${i.id}`,type:"building",title:i.name,subtitle:b,icon:d.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[d.jsx(J,{name:"status-pending",size:10,weight:"fill",color:M}),d.jsx(J,{name:I,size:16})]}),_searchText:R,action:()=>{var $;x.current(),i.type==="boss"?z.current(i.id):i.type==="database"?ie.current(i.id):($=i.pm2)!=null&&$.enabled&&Q.current(i.id)}}}):[],[t,m]),ae=y.useMemo(()=>{if(!t)return[];const i=g||[],M=new Set,I=[];for(const D of i){if(M.has(D.filePath))continue;M.add(D.filePath);const b=D.filePath.split("/").pop()||D.filePath,R=D.action==="created"?"Created":D.action==="modified"?"Modified":D.action==="deleted"?"Deleted":"Read";if(I.push({id:`modified-${D.filePath}-${D.timestamp}`,type:"modified-file",title:b,subtitle:`${R} by ${D.agentName} • ${D.filePath}`,matchedText:D.filePath,icon:D.action==="deleted"?d.jsx(J,{name:"trash",size:16}):Pt(D.filePath),action:()=>{x.current();const k=Array.from(te.getState().areas.values());for(const Y of k)for(const G of Y.directories||[])if(D.filePath.startsWith(G)){te.setFileViewerPath(D.filePath),L.current(Y.id);return}te.selectAgent(D.agentId)}}),I.length>=50)break}return I},[t,g]),we=y.useMemo(()=>new X(oe,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[oe]),Fe=y.useMemo(()=>new X(W,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[W]),Me=y.useMemo(()=>new X(_,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[_]),Ie=y.useMemo(()=>new X(ae,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ae]),De=y.useMemo(()=>new X(q,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[q]),V=y.useMemo(()=>{if(!E.trim()){const A=[];A.push(...q);const w=[...oe].sort((v,H)=>{const ce=v.timeAway??0,ne=H.timeAway??0;return ce-ne});A.push(...w),A.push(...W.slice(0,2)),A.push(..._.slice(0,2));const F={};return Kt.forEach((v,H)=>{F[v]=H}),A.sort((v,H)=>(F[v.type]??999)-(F[H.type]??999)),A}const i=E.trim().toLowerCase(),M=we.search(E).slice(0,8),I=Fe.search(E).slice(0,3),D=Me.search(E).slice(0,2),b=Ie.search(E).slice(0,3),R=De.search(E).filter(A=>{const w=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(i)||w<=.2}).slice(0,4),k={agent:5,building:4,command:3,area:2,"modified-file":1},Y=A=>{if(!i)return 1;const w=A.title.toLowerCase();return w===i?6:w.startsWith(i)?5:w.split(/[^a-z0-9]+/i).includes(i)?4:w.includes(i)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(i)?2:1},G=(A,w)=>{const F=(1-Math.min(1,w??1))*4;return Y(A)*100+(k[A.type]??0)*5+F},T=new Map,$=(A,w)=>{const F=T.get(A.type),v={item:A,score:G(A,w)};F?F.push(v):T.set(A.type,[v])};for(const A of M){const w={...A.item};if(w._modifiedFiles&&w._modifiedFiles.length>0){const F=w._modifiedFiles.filter(v=>{var ne;const H=((ne=v.split("/").pop())==null?void 0:ne.toLowerCase())||"",ce=v.toLowerCase();return H.includes(i)||ce.includes(i)});F.length>0&&(w.matchedFiles=F)}if(w._userQueries&&w._userQueries.length>0){const F=w._userQueries.find(v=>v.toLowerCase().includes(i));if(F)if(F.length>200){const H=F.toLowerCase().indexOf(i),ce=Math.max(0,H-60),ne=Math.min(F.length,H+i.length+100);w.matchedQuery=(ce>0?"...":"")+F.slice(ce,ne)+(ne<F.length?"...":"")}else w.matchedQuery=F}$(w,A.score)}for(const A of R)$(A.item,A.score);for(const A of I)$(A.item,A.score);for(const A of D)$(A.item,A.score);for(const A of b)$(A.item,A.score);for(const[A,w]of T)w.sort((F,v)=>v.score!==F.score?v.score-F.score:A==="agent"?(F.item.timeAway??Number.POSITIVE_INFINITY)-(v.item.timeAway??Number.POSITIVE_INFINITY):0);const Be=[];return Array.from(T.values()).sort((A,w)=>{var F,v;return(((F=w[0])==null?void 0:F.score)??-1)-(((v=A[0])==null?void 0:v.score)??-1)}).forEach(A=>{for(const w of A)Be.push(w.item)}),Be},[E,we,Fe,Me,Ie,De,W,oe,_,q]);y.useEffect(()=>{B>=V.length&&P(Math.max(0,V.length-1))},[V.length,B]);const Ye=y.useCallback(i=>{if(i.altKey&&!i.ctrlKey&&!i.metaKey&&(i.key==="p"||i.key==="n"||i.key==="P"||i.key==="N")){i.preventDefault(),i.stopPropagation(),i.nativeEvent.stopImmediatePropagation();const M=i.key.toLowerCase();P(M==="p"?I=>I>0?I-1:V.length-1:I=>I<V.length-1?I+1:0);return}switch(i.key){case"Escape":i.preventDefault(),x.current();break;case"ArrowUp":i.preventDefault(),P(M=>M>0?M-1:V.length-1);break;case"ArrowDown":i.preventDefault(),P(M=>M<V.length-1?M+1:0);break;case"Enter":i.preventDefault(),V[B]&&V[B].action();break}},[V,B]),Ue=y.useCallback((i,M)=>{if(!M||!i)return i;const I=i.toLowerCase(),D=M.toLowerCase(),b=[];let R=0,k=I.indexOf(D),Y=0;for(;k!==-1;)k>R&&b.push(i.slice(R,k)),b.push(de.createElement("mark",{key:Y++,className:"spotlight-highlight"},i.slice(k,k+M.length))),R=k+M.length,k=I.indexOf(D,R);return R<i.length&&b.push(i.slice(R)),b.length>0?de.createElement(de.Fragment,null,...b):i},[]);return{query:E,setQuery:C,selectedIndex:B,setSelectedIndex:P,results:V,handleKeyDown:Ye,highlightMatch:Ue}}const zt=y.forwardRef(function({query:e,onQueryChange:s,onKeyDown:n,onResetSelection:r},c){const{t:o}=Ee(["common"]);return d.jsxs("div",{className:"spotlight-input-wrapper",children:[d.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),d.jsx("input",{ref:c,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{s(a.target.value),r()},onKeyDown:n,autoFocus:!0,spellCheck:!1}),d.jsxs("div",{className:"spotlight-input-hints",children:[d.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Qt=y.memo(function({result:e,isSelected:s,query:n,highlightMatch:r,onClick:c,onMouseEnter:o}){const a=e.activityText||e.matchedFiles&&e.matchedFiles.length>0||e.matchedQuery;return d.jsxs("div",{className:`spotlight-item ${s?"selected":""} ${e.activityText?"has-activity":""}`,onClick:c,onMouseEnter:o,role:"option","aria-selected":s,children:[d.jsx("span",{className:"spotlight-item-icon","aria-hidden":"true",children:e.icon}),d.jsxs("div",{className:"spotlight-item-content",children:[d.jsxs("div",{className:"spotlight-item-header",children:[d.jsx("span",{className:"spotlight-item-title",children:r(e.title,n)}),d.jsx("span",{className:`spotlight-item-type ${e.type}`,"aria-label":Re(e.type),children:Re(e.type)})]}),e.subtitle&&d.jsx("span",{className:"spotlight-item-subtitle",children:r(e.subtitle,n)}),e.activityText&&d.jsx("span",{className:"spotlight-item-activity",children:r(e.activityText,n)}),a&&d.jsxs("div",{className:"spotlight-item-details",children:[e.matchedFiles&&e.matchedFiles.length>0&&d.jsx("span",{className:"spotlight-item-files",children:e.matchedFiles.map((u,l)=>d.jsxs("span",{className:"file-badge",children:[l>0&&d.jsx("span",{className:"file-separator",children:"•"}),r(u.split("/").pop()||u,n)]},u))}),e.matchedQuery&&d.jsx("span",{className:"spotlight-item-query",children:r(e.matchedQuery,n)})]}),e.timeAway!==void 0&&d.jsx("span",{className:"spotlight-item-time",children:d.jsxs("span",{className:"spotlight-time-away",children:["Idle: ",Ve(e.timeAway)]})}),e.lastUserInput&&!e.matchedQuery&&d.jsxs("span",{className:"spotlight-item-last-input",children:['"',r(e.lastUserInput,n),'"']})]})]})}),Wt=y.forwardRef(function({results:e,selectedIndex:s,query:n,highlightMatch:r,onSelectIndex:c},o){const{t:a}=Ee(["terminal"]),u=y.useRef(!1);y.useEffect(()=>{u.current=!1},[e]),y.useEffect(()=>{const f=typeof o=="function"?null:o==null?void 0:o.current;if(!f)return;const m=()=>{u.current=!0};return f.addEventListener("mousemove",m),()=>{f.removeEventListener("mousemove",m)}},[o,e]);const l={command:a("terminal:spotlight.categories.commands"),agent:a("terminal:spotlight.categories.agents"),building:a("terminal:spotlight.categories.infrastructure"),area:a("terminal:spotlight.categories.areas"),"modified-file":a("terminal:spotlight.categories.modifiedFiles")},h=y.useMemo(()=>{const f=[];let m=null,g=[];return e.forEach((x,S)=>{x.type!==m&&(m!==null&&g.length>0&&f.push([m,g]),m=x.type,g=[]),g.push({result:x,index:S})}),m!==null&&g.length>0&&f.push([m,g]),f},[e]);return y.useEffect(()=>{if(!o||typeof o=="function")return;const f=o.current;if(!f)return;const m=f.querySelector(".spotlight-item.selected");m&&m.scrollIntoView({block:"nearest",behavior:"smooth"})},[s,o]),e.length===0?d.jsx("div",{className:"spotlight-results",ref:o,children:d.jsx("div",{className:"spotlight-empty",children:a("terminal:spotlight.noResults")})}):d.jsx("div",{className:"spotlight-results",ref:o,children:h.map(([f,m])=>d.jsxs("div",{children:[h.length>1&&d.jsx("div",{className:"spotlight-category-header",children:l[f]||f}),m.map(({result:g,index:x})=>d.jsx(Qt,{result:g,isSelected:x===s,query:n,highlightMatch:r,onClick:()=>g.action(),onMouseEnter:()=>{u.current&&c(x)}},g.id))]},f))})}),Vt=y.memo(function(){const{t:e}=Ee(["terminal"]);return d.jsxs("div",{className:"spotlight-footer",children:[d.jsxs("div",{className:"spotlight-footer-left",children:[d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"↑"}),d.jsx("kbd",{children:"↓"})," ",d.jsx("kbd",{children:"Alt+N"}),d.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]})]}),d.jsx("div",{className:"spotlight-footer-right",children:d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Yt=768;function Zt({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=y.useRef(null),f=y.useRef(null),m=y.useRef(null),g=y.useRef(0),{query:x,setQuery:S,selectedIndex:N,setSelectedIndex:j,results:L,handleKeyDown:Q,highlightMatch:z}=Ot({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});g.current=L.length,y.useEffect(()=>{t&&setTimeout(()=>{var E;(E=h.current)==null||E.focus()},50)},[t]),y.useEffect(()=>{if(!t)return;const E=window.visualViewport;if(!E||window.innerWidth>Yt)return;const C=()=>{const B=f.current;B&&(B.style.height=`${E.height}px`,B.style.top=`${E.offsetTop}px`)};return C(),E.addEventListener("resize",C),E.addEventListener("scroll",C),()=>{E.removeEventListener("resize",C),E.removeEventListener("scroll",C);const B=f.current;B&&(B.style.height="",B.style.top="")}},[t]),y.useEffect(()=>{if(!t)return;const E=C=>{if(C.key==="Escape"){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation(),e();return}if(C.altKey&&!C.ctrlKey&&!C.metaKey&&(C.key==="n"||C.key==="p"||C.key==="N"||C.key==="P")){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation();const B=C.key.toLowerCase(),P=g.current;j(B==="p"?K=>K>0?K-1:P-1:K=>K<P-1?K+1:0);return}};return window.addEventListener("keydown",E,{capture:!0}),()=>{window.removeEventListener("keydown",E,{capture:!0})}},[t,e]);const ie=y.useCallback(E=>{E.target===E.currentTarget&&e()},[e]),U=y.useCallback(()=>{j(0)},[j]);return t?d.jsx("div",{ref:f,className:"spotlight-overlay",onClick:ie,children:d.jsxs("div",{className:"spotlight-modal",children:[d.jsx(zt,{ref:h,query:x,onQueryChange:S,onKeyDown:Q,onResetSelection:U}),d.jsx(Wt,{ref:m,results:L,selectedIndex:N,query:x,highlightMatch:z,onSelectIndex:j}),d.jsx(Vt,{})]})}):null}export{_e as FILE_ICON_NAMES,Zt as Spotlight,Vt as SpotlightFooter,zt as SpotlightInput,Qt as SpotlightItem,Wt as SpotlightResults,Ve as formatDuration,Xt as formatRelativeTime,Jt as getAgentIcon,Pt as getFileIconFromPath,Re as getTypeLabel,Ot as useSpotlightSearch};
@@ -1,2 +1,2 @@
1
- import{r as a,z as rn,B as Tt,u as Wt,E as on,j as e,V as cn,G as dn,H as un,J as Pt,S as y,K as Lt,L as kt,M as Dt,N as ut,O as se,P as pn,s as x,U as Ht,W as Vt,X as mn,v as Rt,w as zt,I as u,Y as fn,m as hn,Z as gn,_ as Xt,$ as Gt,a0 as xn,a1 as bn,a2 as _n,a3 as wn,a4 as vn,a5 as Cn,a6 as jn,a7 as Nn,a8 as kn,a9 as yn,aa as An,ab as In,ac as Ot,C as En,ad as Sn,ae as Mn,af as Tn,ag as Pn,ah as Ln,ai as Dn,aj as Rn,ak as zn,al as On,am as $n,an as Bn,ao as Fn,ap as Wn,aq as Hn,ar as Vn,as as Xn}from"./main-BxA3Bhkv.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Gn(w){const c=a.useRef(w);c.current=w,a.useEffect(()=>{if(!rn())return;let v=null,A=!1;return Tt.addListener("backButton",()=>{c.current()==="exit"&&Tt.exitApp()}).then(S=>{A?S.remove():v=S}),()=>{A=!0,v&&(v.remove(),v=null)}},[])}const Un=a.memo(function({className:c=""}){const{t:v}=Wt(["common"]),[A,S]=on(),q=a.useRef(null),[O,De]=a.useState(null);a.useLayoutEffect(()=>{const g=q.current;if(!g)return;const Y=g.querySelector(".view-mode-toggle__btn--active");Y&&De({left:Y.offsetLeft,width:Y.offsetWidth})},[A]);const le=a.useCallback(g=>{if(g!==A){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:g}})),g==="3d"){requestAnimationFrame(()=>S(g));return}S(g)}},[A,S]);return e.jsxs("div",{className:`view-mode-toggle ${c}`,ref:q,children:[O&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:O.left,width:O.width}}),cn.map(g=>e.jsxs("button",{className:`view-mode-toggle__btn ${A===g?"view-mode-toggle__btn--active":""}`,onClick:()=>le(g),title:v(`common:viewMode.descriptions.${g}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[g==="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"})]}),g==="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"})]}),g==="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"})]}),g==="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:v(`common:viewMode.labels.${g}`)})]},g))]})}),pt=3,mt=280,$t=320,Nt=240,Bt=64,qn=["simple","chat","advanced"],Yn={simple:"Simple",chat:"Chat",advanced:"Advanced"},Kn={simple:"○",chat:"◐",advanced:"◉"},Zn={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Ft="flat-clear-context";function Jn(w){const c=w.split("/").filter(Boolean);return c.length===0?w:c.slice(-2).join("/")}function Qn(w){if(w.provider==="codex"){const q=w.codexModel||"gpt-5.3-codex",O=Hn[q];return{model:(O==null?void 0:O.label)||q}}if(w.provider==="opencode")return{model:w.opencodeModel||"opencode"};const c=w.model||"sonnet",v=Xn[c],A=w.effort,S=A?Vn[A]:void 0;return{model:(v==null?void 0:v.label)||c,effort:S==null?void 0:S.label}}function ea(w,c){if(c.type==="rectangle"&&c.width&&c.height){const v=c.width/2,A=c.height/2;return w.x>=c.center.x-v&&w.x<=c.center.x+v&&w.z>=c.center.z-A&&w.z<=c.center.z+A}if(c.type==="circle"&&c.radius){const v=w.x-c.center.x,A=w.z-c.center.z;return v*v+A*A<=c.radius*c.radius}return!1}const ta=Sn.memo(function({agentId:c,terminalViewMode:v,onTerminalViewModeChange:A,inspectorOpen:S,onToggleInspector:q,onImageClick:O,onFileClick:De,onBashClick:le,onViewMarkdown:g,onRequestClearSubordinates:Y,onOpenBuilding:ye,keyboard:We,canNavigateBack:He,canNavigateForward:Ve,onNavigateBack:pe,onNavigateForward:ie,agentInfoOpen:me,onToggleAgentInfo:Xe,onHeaderContextMenu:K,onBuildingContextMenu:fe}){var ce,Pe,ne,st;const h=Mn(c),$=Vt(),B=a.useRef(null),Ae=a.useRef(null);a.useEffect(()=>{const l=Ae.current;if(!l)return;const r=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),pe()):d.button===4&&(d.preventDefault(),d.stopPropagation(),ie())},o=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return l.addEventListener("mouseup",r),l.addEventListener("mousedown",o),()=>{l.removeEventListener("mouseup",r),l.removeEventListener("mousedown",o)}},[pe,ie]),a.useEffect(()=>{const l=Ae.current;if(!l)return;let r=0,o=0,d=0;const de=250,Ce=600,Le=80,bt=1.5,_t=P=>{let M=P instanceof HTMLElement?P:null;for(;M&&M!==l;){const lt=window.getComputedStyle(M).overflowX;if((lt==="auto"||lt==="scroll")&&M.scrollWidth>M.clientWidth)return!0;M=M.parentElement}return!1},V=P=>{const M=Date.now();if(M<d){P.preventDefault();return}if(Math.abs(P.deltaX)<=Math.abs(P.deltaY)*bt){r=0;return}if(_t(P.target)){r=0;return}M-o>de&&(r=0),o=M,r+=P.deltaX,r<=-Le?(r=0,d=M+Ce,P.preventDefault(),pe()):r>=Le&&(r=0,d=M+Ce,P.preventDefault(),ie())};return l.addEventListener("wheel",V,{passive:!1}),()=>l.removeEventListener("wheel",V)},[pe,ie]);const Ie=Ht(),he=a.useMemo(()=>{if(!h)return null;const l=new Set,r=[];for(const o of Ie.values())o.archived||o.directories.length===0||o.assignedAgentIds.includes(c)&&(l.add(o.id),r.push(o));for(const o of Ie.values())o.archived||o.directories.length===0||l.has(o.id)||ea({x:h.position.x,z:h.position.z},o)&&(l.add(o.id),r.push(o));return r.length===0?null:r.flatMap(o=>o.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:o.id,areaName:o.name,dir:d})))},[h,c,Ie]),{branches:Ge,fetchRemote:Ue,fetchingDirs:qe}=Tn(he),ge=a.useMemo(()=>{var o;const l=x.getAreaForAgent(c);if(!l)return[];const r=[];for(const d of $.values())d.type==="terminal"&&x.isPositionInArea(d.position,l)&&r.push({id:d.id,name:d.name,hasUrl:!!((o=d.terminalStatus)!=null&&o.url)});return r},[c,$]),Ye=a.useMemo(()=>{var o;const l=x.getAreaForAgent(c);if(!l)return[];const r=[];for(const d of $.values())d.type==="server"&&((o=d.pm2)!=null&&o.enabled)&&x.isPositionInArea(d.position,l)&&r.push({id:d.id,name:d.name});return r},[c,$]),xe=a.useMemo(()=>{const l=x.getAreaForAgent(c);if(!l)return[];const r=[];for(const o of $.values())o.type==="database"&&o.database&&x.isPositionInArea(o.position,l)&&r.push({id:o.id,name:o.name});return r},[c,$]),[,be]=a.useReducer(l=>l+1,0),F=((ce=B.current)==null?void 0:ce.search.searchMode)??!1,re=a.useCallback(()=>{var l;(l=B.current)==null||l.search.toggleSearch(),be()},[]),Ke=Pn(),Re=Ke.isPending(Ft),[W,X]=a.useState(null),R=W?$.get(W):null,{height:Ee,onResizeStart:G}=Ln(),[U,Z]=a.useState(()=>kt(y.GIT_PANEL_OPEN,!1)),[z,Ze]=a.useState(()=>kt(y.BUILDINGS_PANEL_OPEN,!1)),[_e,ze]=a.useState(!1),Se=a.useCallback(()=>{ze(l=>{const r=!l;return r&&Dn.setEnabled(!0),r})},[]),ft=a.useCallback(()=>ze(!1),[]),ht=a.useCallback(()=>{Z(l=>{const r=!l;return se(y.GIT_PANEL_OPEN,r),r})},[]),we=a.useCallback(()=>{Ze(l=>{const r=!l;return se(y.BUILDINGS_PANEL_OPEN,r),r})},[]),gt=a.useCallback(()=>{Z(!1),se(y.GIT_PANEL_OPEN,!1)},[]),Je=a.useCallback(()=>{Ze(!1),se(y.BUILDINGS_PANEL_OPEN,!1)},[]),xt=Rn();a.useEffect(()=>{if(!W)return;ge.some(r=>r.id===W)||X(null)},[W,ge]);const[J,oe]=a.useState(!1),Oe=a.useRef(null);if(a.useEffect(()=>{if(!J)return;const l=r=>{Oe.current&&!Oe.current.contains(r.target)&&oe(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[J]),!h)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 Q=h.contextStats,Qe=!!Q,et=Q?Q.totalTokens:h.contextUsed||0,tt=Q?Q.contextWindow:h.contextLimit||2e5,Me=Q?Q.usedPercent:Math.round(et/tt*100),f=Math.max(0,Math.min(100,Me)),ee=Math.round(f*10)/10,H=Math.round((100-f)*10)/10,ve=f>=80?"#ff4a4a":f>=60?"#ff9e4a":f>=40?"#ffd700":"#4aff9e",$e=(et/1e3).toFixed(1),nt=(tt/1e3).toFixed(1),te=h.cwd,at=te?Jn(te):null,Te=((Pe=h.subordinateIds)==null?void 0:Pe.length)||0,Be=Te>0;return e.jsxs("div",{ref:Ae,className:`flat-terminal-wrapper ${U||z||_e?"flat-terminal-wrapper--with-side-panel":""}`,children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${me?"flat-terminal-wrapper__header-main--active":""}`,onClick:Xe,onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K({x:l.clientX,y:l.clientY})},title:me?"Hide agent info":"Show agent info","aria-pressed":me,children:[e.jsx(Xt,{agent:h,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:h.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Gt(h.status)},children:h.status})]}),h.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:h.taskLabel,children:["📋 ",h.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:h.provider==="codex"?"/assets/codex.png":h.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:h.provider,className:"flat-terminal-wrapper__header-provider-icon",title:h.provider==="codex"?"Codex Agent":h.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:l,effort:r}=Qn(h);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:r?`Model: ${l} · Effort: ${r}`:`Model: ${l}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:l}),r&&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:r})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsx("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:qn.map(l=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${v===l?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>A(l),title:Zn[l],"aria-pressed":v===l,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Kn[l]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Yn[l]})]},l))}),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:pe,disabled:!He,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(u,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:ie,disabled:!Ve,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(u,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${F?"flat-terminal-wrapper__action-btn--active":""}`,onClick:re,title:F?"Close search":"Search messages","aria-pressed":F,children:e.jsx(u,{name:F?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Re?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Ke.handleClick(Ft,()=>{var l;x.clearContext(c),(l=B.current)==null||l.historyLoader.clearHistory()}),title:Re?"Click again to confirm clear context":"Clear context",children:e.jsx(u,{name:Re?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${U?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ht,title:U?"Hide git panel":"Show git changes","aria-pressed":U,children:e.jsx(u,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${z?"flat-terminal-wrapper__action-btn--active":""}`,onClick:we,title:z?"Hide buildings panel":"Show area buildings","aria-pressed":z,children:e.jsx(u,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Oe,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${J?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>oe(l=>!l),title:"More actions","aria-expanded":J,children:"⋮"}),J&&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 ${_e?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Se(),oe(!1)},title:_e?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(u,{name:"bug",size:14}),e.jsx("span",{children:_e?"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:()=>{x.collapseContext(c),oe(!1)},disabled:h.status!=="idle",title:h.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(u,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),Be&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{Y(c,Te),oe(!1)},children:[e.jsx(u,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",Te," subordinate",Te===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:()=>{x.killAgent(c),oe(!1)},children:[e.jsx(u,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${S?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:q,title:S?"Hide inspector panel":"Show inspector panel","aria-label":S?"Hide inspector panel":"Show inspector panel","aria-pressed":S,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:()=>x.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(u,{name:"cross",size:14})})]})]}),e.jsx(zn,{ref:B,agentId:c,agent:h,viewMode:v,isOpen:!0,onImageClick:O,onFileClick:De,onBashClick:le,onViewMarkdown:g,keyboard:We,hasModalOpen:!1}),R&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:G,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${R.name}`,style:{height:Ee},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(u,{name:"terminal",size:12}),e.jsx("span",{children:R.name}),!((ne=R.terminalStatus)!=null&&ne.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>X(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(u,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(st=R.terminalStatus)!=null&&st.url?e.jsx(On,{terminalUrl:R.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:[h.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(u,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),te&&at&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${te}`,"aria-label":`Open ${te} in file explorer`,role:"button",tabIndex:0,onClick:()=>x.openFileExplorer(te),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),x.openFileExplorer(te))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(u,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:at})]}),he&&he.map(({areaId:l,areaName:r,dir:o})=>{const d=Ge.get(o),de=qe.has(o),Ce=o.split("/").filter(Boolean).pop()||o;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${o}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>x.openFileExplorerForAreaFolder(l,o),children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Ce}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(u,{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(u,{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(u,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${de?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Le=>{Le.stopPropagation(),Ue(o)},children:e.jsx(u,{name:de?"hourglass":"download",size:12})})]})]},`${l}:${o}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>x.setContextModalAgentId(c),title:Qe?`Context usage: ${$e}k / ${nt}k tokens (${ee}% used). Click to view stats.`:"Click to fetch context stats",children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(u,{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:`${f}%`,backgroundColor:ve}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:ve},children:[$e,"k/",nt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",H,"% free)"]}),!Qe&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(u,{name:"warn",size:12})})]}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),ge.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:ge.map(l=>{const r=W===l.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${l.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${r?"Hide":"Show"} terminal: ${l.name}${l.hasUrl?"":" (starting...)"}`,onClick:()=>{if(r){X(null);return}l.hasUrl||x.sendBuildingCommand(l.id,"start"),X(l.id)},onContextMenu:o=>{o.preventDefault(),o.stopPropagation(),fe(l.id,{x:o.clientX,y:o.clientY})},children:e.jsx(u,{name:"terminal",size:14})},l.id)})}),Ye.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Ye.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${l.name}`,onClick:()=>ye(l.id),onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),fe(l.id,{x:r.clientX,y:r.clientY})},children:e.jsx(u,{name:"scroll",size:14})},l.id))}),xe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:xe.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${l.name}`,onClick:()=>ye(l.id),onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),fe(l.id,{x:r.clientX,y:r.clientY})},children:e.jsx(u,{name:"hard-drives",size:14})},l.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx($n,{})})]}),U&&e.jsx(Bn,{agentId:c,agents:xt,onClose:gt,branchInfoMap:Ge,fetchRemote:Ue,fetchingDirs:qe}),z&&e.jsx(Fn,{agentId:c,onClose:Je}),_e&&e.jsx(Wn,{agentId:c,onClose:ft})]})});function la({onAgentClick:w,onBuildingClick:c,onBuildingDoubleClick:v,onBuildingPopup:A,onAreaContextMenu:S,onOpenSpawnModal:q,onOpenBossSpawnModal:O,onOpenAreaModal:De}){const{t:le}=Wt(["common"]),g=dn(),Y=un(),[ye,We]=a.useState(null),[He,Ve]=a.useState(null),[pe,ie]=a.useState(null),[me,Xe]=a.useState(null),[K,fe]=a.useState(null),[h,$]=a.useState(null),[B,Ae]=a.useState(null),[Ie,he]=a.useState(!1),Ge=a.useCallback(()=>{he(t=>!t)},[]),Ue=a.useCallback(()=>{he(!1)},[]),[qe,ge]=a.useState(()=>{const t=Pt(y.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ye=a.useCallback(t=>{ge(t),Lt(y.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==y.VIEW_MODE)return;const s=n.newValue;(s==="simple"||s==="chat"||s==="advanced")&&ge(s)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[xe,be]=a.useState(()=>kt(y.FLAT_INSPECTOR_OPEN,!1)),[F,re]=a.useState(!1),Ke=a.useCallback(()=>re(t=>!t),[]),Re=a.useCallback(()=>re(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:F}}))},[F]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:xe}}))},[xe]),a.useEffect(()=>{const t=()=>re(_=>!_),n=()=>{be(_=>{const i=!_;return se(y.FLAT_INSPECTOR_OPEN,i),i})},s=()=>{re(!1),be(!1),se(y.FLAT_INSPECTOR_OPEN,!1)},p=()=>re(!1),m=()=>{be(!1),se(y.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",s),window.addEventListener("tide-close-flat-agents-drawer-only",p),window.addEventListener("tide-close-flat-inspector-only",m),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",s),window.removeEventListener("tide-close-flat-agents-drawer-only",p),window.removeEventListener("tide-close-flat-inspector-only",m)}},[]);const W=a.useRef(null),X=a.useRef(null),[R,Ee]=a.useState(()=>{const t=Dt(y.FLAT_MIDDLE_WIDTH,0);return t>=mt?t:null}),[G,U]=a.useState(()=>{const t=Dt(y.FLAT_INSPECTOR_WIDTH,0);return t>=Nt?t:null}),Z=a.useCallback(t=>{if(typeof window>"u")return t;const n=G!==null?pt+G:0,s=window.innerWidth-Bt-pt-$t-n;return Math.max(mt,Math.min(Math.max(s,mt),t))},[G]),z=a.useCallback(t=>{var m;if(typeof window>"u")return t;const n=(m=W.current)==null?void 0:m.querySelector(".flat-middle"),s=(n==null?void 0:n.getBoundingClientRect().width)??mt,p=window.innerWidth-Bt-s-pt-$t-pt;return Math.max(Nt,Math.min(Math.max(p,Nt),t))},[]);a.useEffect(()=>{if(R===null&&G===null)return;const t=()=>{Ee(n=>{if(n===null)return n;const s=Z(n);return s===n?n:s}),U(n=>{if(n===null)return n;const s=z(n);return s===n?n:s})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[R,G,Z,z]);const Ze=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=W.current)==null?void 0:s.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),_e=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=W.current)==null?void 0:s.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),ze=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;const s=t.clientX-n.startX;n.kind==="middle"?Ee(Z(n.startWidth+s)):U(z(n.startWidth-s))},[Z,z]),Se=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(X.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const p=t.clientX-n.startX;if(n.kind==="middle"){const m=Z(n.startWidth+p);Ee(m),ut(y.FLAT_MIDDLE_WIDTH,m)}else{const m=z(n.startWidth-p);U(m),ut(y.FLAT_INSPECTOR_WIDTH,m)}},[Z,z]),ft=a.useCallback(()=>{Ee(null),ut(y.FLAT_MIDDLE_WIDTH,0)},[]),ht=a.useCallback(()=>{U(null),ut(y.FLAT_INSPECTOR_WIDTH,0)},[]),[we,gt]=a.useState(()=>Pt(y.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Je=a.useCallback(t=>{gt(t),Lt(y.FLAT_INSPECTOR_VIEW,t)},[]),xt=a.useCallback(()=>{be(t=>{const n=!t;return se(y.FLAT_INSPECTOR_OPEN,n),n})},[]),J=a.useCallback(()=>{be(!1),se(y.FLAT_INSPECTOR_OPEN,!1)},[]),oe=pn(),Oe=a.useCallback((t,n)=>{We({url:t,name:n})},[]),Q=a.useCallback((t,n)=>{Ve({command:t,output:n,isLive:!1})},[]),Qe=a.useCallback((t,n)=>{x.setFileViewerPath(t,n)},[]),et=a.useCallback(t=>{ie(t)},[]),tt=a.useCallback((t,n)=>{Xe({agentId:t,count:n})},[]),Me=a.useCallback(t=>{v?v(t):c(t)},[c,v]),f=a.useMemo(()=>Y.size>0?Array.from(Y)[0]:null,[Y]);a.useEffect(()=>{he(!1)},[f]);const ee=a.useRef([]),H=a.useRef(-1),ve=a.useRef(!1),$e=a.useRef(null),[nt,te]=a.useState(!1),[at,Te]=a.useState(!1),Be=a.useRef(!1),ce=a.useRef(null),Pe=a.useRef(!1),ne=a.useMemo(()=>new Set(g.map(t=>t.id)),[g]),st=a.useMemo(()=>{const t=new Map(g.map(s=>[s.id,s])),n=new Map;for(const s of g)if((s.isBoss||s.class==="boss")&&s.subordinateIds&&s.subordinateIds.length>0){const p=s.subordinateIds.map(m=>t.get(m)).filter(m=>m!==void 0);p.length>0&&n.set(s.id,p)}return n},[g]),l=a.useCallback(()=>{const t=ee.current,n=H.current;te(n>0),Te(n>=0&&n<t.length-1)},[]),r=a.useCallback(t=>{const n=ee.current;if(n.length===0)return;let s=H.current+t;for(;s>=0&&s<n.length;){const p=n[s];if(ne.has(p)){ve.current=!0,H.current=s,l(),x.selectAgent(p);return}s+=t}},[ne,l]),o=a.useCallback(()=>r(-1),[r]),d=a.useCallback(()=>r(1),[r]);Gn(a.useCallback(()=>{const t=ee.current,n=H.current;return t.length>0&&n>0?(r(-1),"handled"):"exit"},[r]));const de=a.useCallback((t,n)=>{if(typeof window>"u")return;const s=window.history.state,m={...typeof s=="object"&&s!==null?s:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(m,"",window.location.href):window.history.pushState(m,"",window.location.href)},[]);a.useEffect(()=>{if(!f){Be.current=!1,ce.current=null;return}if(!Be.current){de(f,"replace"),Be.current=!0,ce.current=f;return}if(Pe.current){Pe.current=!1,ce.current=f;return}ce.current!==f&&(de(f,"push"),ce.current=f)},[f,de]),a.useEffect(()=>{const t=n=>{var _,i;const s=(i=(_=n.state)==null?void 0:_.__flatAgentNav)==null?void 0:i.agentId;if(!s||typeof s!="string"||!ne.has(s)||s===f)return;Pe.current=!0,ve.current=!0;const p=ee.current,m=p.lastIndexOf(s);m>=0?H.current=m:(p.push(s),H.current=p.length-1),l(),x.selectAgent(s)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ne,f,l]),a.useEffect(()=>{if(!f){ee.current=[],H.current=-1,l();return}if($e.current=f,ve.current){ve.current=!1,l();return}const t=ee.current,n=H.current;if(n>=0&&t[n]===f){l();return}const s=n<t.length-1?t.slice(0,n+1):t.slice();s.push(f),s.length>100&&s.shift(),ee.current=s,H.current=s.length-1,l()},[f,l]);const Ce=a.useCallback(t=>{w(t),re(!1)},[w]),Le=f??"",bt=a.useCallback(()=>{},[]),_t=a.useCallback(t=>{Ce(t)},[Ce]),V=xe,[P,M]=a.useState(V),[lt,yt]=a.useState(V);a.useEffect(()=>{if(V){M(!0);return}yt(!1);const t=setTimeout(()=>M(!1),240);return()=>clearTimeout(t)},[V]),a.useEffect(()=>{if(!P||!V)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>yt(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[P,V]);const At=a.useRef(null);a.useEffect(()=>{if(f)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const s=n.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const p=$e.current;!p||!ne.has(p)||(n.preventDefault(),x.selectAgent(p))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[f,ne]);const[Ut,It]=a.useState(new Set),qt=a.useCallback(t=>{It(n=>{const s=new Set(n);return s.has(t)?s.delete(t):s.add(t),s})},[]),[je,Yt]=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=s=>Yt(s.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[it,Kt]=a.useState(null),Zt=a.useCallback(t=>{Kt(n=>n===t?null:t)},[]),wt=Ht(),rt=Vt(),[Jt]=mn(),Ne=a.useMemo(()=>{const t=new Map,n=[];for(const b of g){const k=x.getAreaForAgent(b.id);if(!Rt((k==null?void 0:k.id)??null))continue;if(!k||k.archived){n.push(b);continue}const N=t.get(k.id);N?N.push(b):t.set(k.id,[b])}const s=new Map,p=[];for(const b of rt.values()){let k=!1;for(const N of wt.values())if(!N.archived&&zt(N.id)&&x.isPositionInArea(b.position,N)){const ae=s.get(N.id);ae?ae.push(b):s.set(N.id,[b]),k=!0;break}!k&&Rt(null)&&p.push(b)}const m=[];for(const[,b]of wt){if(b.archived||!zt(b.id))continue;const k=t.get(b.id),N=s.get(b.id)??[];(k&&k.length>0||N.length>0)&&m.push({area:b,agents:k??[],buildings:N})}(n.length>0||p.length>0)&&m.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:p});const _=m.filter(b=>b.area.id!=="__unassigned__"),i=m.filter(b=>b.area.id==="__unassigned__");let I=1,j=1;const E=new Map;if(_.length>1){let b=1/0,k=-1/0,N=1/0,ae=-1/0;for(const L of _)b=Math.min(b,L.area.center.x),k=Math.max(k,L.area.center.x),N=Math.min(N,L.area.center.z),ae=Math.max(ae,L.area.center.z);const ot=k-b||1,ct=ae-N||1;if(_.length<=4){I=_.length,j=1;const L=[..._].sort((D,vt)=>D.area.center.x-vt.area.center.x);for(let D=0;D<L.length;D++)E.set(L[D].area.id,{row:1,col:D+1})}else{const L=[..._].sort((C,T)=>C.area.center.x-T.area.center.x),D=[];for(let C=1;C<L.length;C++)D.push(L[C].area.center.x-L[C-1].area.center.x);const vt=D.reduce((C,T)=>C+T,0)/D.length||1;let Et=1;for(const C of D)C>vt*1.3&&Et++;I=Math.max(2,Math.min(Et,_.length));const Ct=[..._].sort((C,T)=>C.area.center.z-T.area.center.z),dt=[];for(let C=1;C<Ct.length;C++)dt.push(Ct[C].area.center.z-Ct[C-1].area.center.z);const nn=dt.reduce((C,T)=>C+T,0)/dt.length||1;let St=1;for(const C of dt)C>nn*1.3&&St++;j=Math.max(2,Math.min(St,_.length)),I=Math.max(I,Math.ceil(_.length/j)),j=Math.max(j,Math.ceil(_.length/I));const an=ot/I,sn=ct/j,jt=new Set;for(const C of _){let T=Math.min(I-1,Math.max(0,Math.floor((C.area.center.x-b)/an))),ke=Math.min(j-1,Math.max(0,Math.floor((C.area.center.z-N)/sn))),Fe=`${ke},${T}`,Mt=0;const ln=j*I;for(;jt.has(Fe)&&Mt<ln;)T++,T>=I&&(T=0,ke=(ke+1)%j),Fe=`${ke},${T}`,Mt++;jt.has(Fe)&&(ke=j,T=0,Fe=`${ke},${T}`,j++),jt.add(Fe),E.set(C.area.id,{row:ke+1,col:T+1})}}}const ue=b=>{b.sort((k,N)=>{var ot,ct,L,D;const ae=(((ot=k.position)==null?void 0:ot.z)??0)-(((ct=N.position)==null?void 0:ct.z)??0);return ae!==0?ae:(((L=k.position)==null?void 0:L.x)??0)-(((D=N.position)==null?void 0:D.x)??0)})};for(const b of _)ue(b.agents);for(const b of i)ue(b.agents);return{groups:[..._,...i],gridCols:I,gridRows:j,positions:E}},[g,wt,rt,Jt]),Qt=a.useMemo(()=>{if(!K)return[];const t=g.find(n=>n.id===K.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(u,{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(u,{name:"chat",size:14}),onClick:()=>w(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>{Ae({agentId:t.id,name:t.name})}}]:[]},[K,g,w]),en=a.useMemo(()=>{var _;if(!h)return[];const t=rt.get(h.buildingId);if(!t)return[];const n=[],s=t.type==="server"||t.type==="docker"||t.type==="terminal",p=t.status==="running",m=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((_=t.pm2)!=null&&_.enabled)?"View PM2 Logs":"Open",icon:e.jsx(u,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>Me(t.id)}),s&&(p||n.push({id:"start",label:"Start",icon:e.jsx(u,{name:"play",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"start")}),p&&(n.push({id:"restart",label:"Restart",icon:e.jsx(u,{name:"refresh",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(u,{name:"stop",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"stop")}))),m&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(u,{name:"launch",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(u,{name:"pause",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(u,{name:"restart",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"restart")}})),s&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(u,{name:"health",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(u,{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(u,{name:"copy",size:14}),onClick:()=>{x.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 i of t.urls)n.push({id:`url-${i.label}`,label:i.label,icon:e.jsx(u,{name:"link",size:14}),onClick:()=>window.open(i.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>x.deleteBuilding(t.id)}),n},[h,rt,Me]),tn=a.useCallback(t=>{const n=new Set(Ne.groups.map(s=>s.area.id));n.delete(t),It(n),requestAnimationFrame(()=>{const s=At.current;if(!s)return;const p=s.querySelector(`[data-area-id="${t}"]`);if(!p)return;const m=s.getBoundingClientRect(),i=p.getBoundingClientRect().top-m.top+s.scrollTop-8;s.scrollTo({top:Math.max(0,i),behavior:"smooth"})})},[Ne]);return e.jsxs("div",{ref:W,className:`flat-view ${V?"flat-view--with-inspector":""} ${f?"flat-view--has-chat":""} ${F?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(R===null&&G===null)return;const t={};return R!==null&&(t["--flat-middle-width"]=`${R}px`),G!==null&&(t["--flat-inspector-width"]=`${G}px`),t})(),children:[F&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Re,"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:q,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:O,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:De,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(fn,{activeAgentId:Le,onClose:bt,onSelectAgent:_t,collapsedAreas:Ut,onToggleArea:qt,agentListRef:At})})]}),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:Ze,onPointerMove:ze,onPointerUp:Se,onPointerCancel:Se,onDoubleClick:ft}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":F?"Close agents sidebar":"Open agents sidebar","aria-expanded":F,onClick:Ke,children:[e.jsx(u,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),f?e.jsx(ta,{agentId:f,terminalViewMode:qe,onTerminalViewModeChange:Ye,inspectorOpen:xe,onToggleInspector:xt,onImageClick:Oe,onFileClick:Qe,onBashClick:Q,onViewMarkdown:et,onRequestClearSubordinates:tt,onOpenBuilding:Me,keyboard:oe,canNavigateBack:nt,canNavigateForward:at,onNavigateBack:o,onNavigateForward:d,agentInfoOpen:Ie,onToggleAgentInfo:Ge,onHeaderContextMenu:t=>{f&&fe({agentId:f,position:t})},onBuildingContextMenu:(t,n)=>{$({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(Un,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Ne.gridCols}, 1fr)`},children:Ne.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=je&&it?((n=Ne.positions.get(it))==null?void 0:n.row)??null:null;return Ne.groups.map(s=>{const p=s.area.id,m=Ne.positions.get(p),_=je&&it!==p;return je&&t!=null&&(m==null?void 0:m.row)===t&&p!==it?null:e.jsxs("div",{className:`flat-map-area-card${_?" flat-map-area-card--collapsed":""}`,style:{"--area-color":s.area.color,gridRow:m==null?void 0:m.row,gridColumn:m==null?void 0:m.col},onContextMenu:i=>{S&&(i.preventDefault(),i.stopPropagation(),S(p,{x:i.clientX,y:i.clientY}))},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>je?Zt(p):tn(p),title:je?_?`Expand ${s.area.name}`:`Collapse ${s.area.name}`:`Focus ${s.area.name} in left panel`,"aria-expanded":je?!_:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:s.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:s.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:s.agents.length}),je&&e.jsx(u,{name:_?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:s.agents.map(i=>{const I=i.isBoss||i.class==="boss",j=I?st.get(i.id):void 0,E=hn(i),ue=E.usedPercent>=80?"#ff4a4a":E.usedPercent>=60?"#ff9e4a":E.usedPercent>=40?"#ffd700":"#4aff9e",b=`Context: ${(E.totalTokens/1e3).toFixed(1)}k / ${(E.contextWindow/1e3).toFixed(1)}k (${E.usedPercent}% used, ${E.freePercent}% free)`,k=i.latestTodos&&i.latestTodos.length>0||j&&j.length>0;return e.jsx(gn,{todos:i.latestTodos,subordinates:j,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${i.status}`,onClick:()=>w(i.id),onContextMenu:N=>{N.preventDefault(),N.stopPropagation(),fe({agentId:i.id,position:{x:N.clientX,y:N.clientY}})},title:k?void 0:`${I?"Boss · ":""}Open chat with ${i.name}
1
+ import{r as a,z as rn,B as Tt,u as Wt,E as on,j as e,V as cn,G as dn,H as un,J as Pt,S as y,K as Lt,L as kt,M as Dt,N as ut,O as se,P as pn,s as x,U as Ht,W as Vt,X as mn,v as Rt,w as zt,I as u,Y as fn,m as hn,Z as gn,_ as Xt,$ as Gt,a0 as xn,a1 as bn,a2 as _n,a3 as wn,a4 as vn,a5 as Cn,a6 as jn,a7 as Nn,a8 as kn,a9 as yn,aa as An,ab as In,ac as Ot,C as En,ad as Sn,ae as Mn,af as Tn,ag as Pn,ah as Ln,ai as Dn,aj as Rn,ak as zn,al as On,am as $n,an as Bn,ao as Fn,ap as Wn,aq as Hn,ar as Vn,as as Xn}from"./main-CyZg1kKu.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Gn(w){const c=a.useRef(w);c.current=w,a.useEffect(()=>{if(!rn())return;let v=null,A=!1;return Tt.addListener("backButton",()=>{c.current()==="exit"&&Tt.exitApp()}).then(S=>{A?S.remove():v=S}),()=>{A=!0,v&&(v.remove(),v=null)}},[])}const Un=a.memo(function({className:c=""}){const{t:v}=Wt(["common"]),[A,S]=on(),q=a.useRef(null),[O,De]=a.useState(null);a.useLayoutEffect(()=>{const g=q.current;if(!g)return;const Y=g.querySelector(".view-mode-toggle__btn--active");Y&&De({left:Y.offsetLeft,width:Y.offsetWidth})},[A]);const le=a.useCallback(g=>{if(g!==A){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:g}})),g==="3d"){requestAnimationFrame(()=>S(g));return}S(g)}},[A,S]);return e.jsxs("div",{className:`view-mode-toggle ${c}`,ref:q,children:[O&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:O.left,width:O.width}}),cn.map(g=>e.jsxs("button",{className:`view-mode-toggle__btn ${A===g?"view-mode-toggle__btn--active":""}`,onClick:()=>le(g),title:v(`common:viewMode.descriptions.${g}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[g==="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"})]}),g==="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"})]}),g==="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"})]}),g==="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:v(`common:viewMode.labels.${g}`)})]},g))]})}),pt=3,mt=280,$t=320,Nt=240,Bt=64,qn=["simple","chat","advanced"],Yn={simple:"Simple",chat:"Chat",advanced:"Advanced"},Kn={simple:"○",chat:"◐",advanced:"◉"},Zn={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Ft="flat-clear-context";function Jn(w){const c=w.split("/").filter(Boolean);return c.length===0?w:c.slice(-2).join("/")}function Qn(w){if(w.provider==="codex"){const q=w.codexModel||"gpt-5.3-codex",O=Hn[q];return{model:(O==null?void 0:O.label)||q}}if(w.provider==="opencode")return{model:w.opencodeModel||"opencode"};const c=w.model||"sonnet",v=Xn[c],A=w.effort,S=A?Vn[A]:void 0;return{model:(v==null?void 0:v.label)||c,effort:S==null?void 0:S.label}}function ea(w,c){if(c.type==="rectangle"&&c.width&&c.height){const v=c.width/2,A=c.height/2;return w.x>=c.center.x-v&&w.x<=c.center.x+v&&w.z>=c.center.z-A&&w.z<=c.center.z+A}if(c.type==="circle"&&c.radius){const v=w.x-c.center.x,A=w.z-c.center.z;return v*v+A*A<=c.radius*c.radius}return!1}const ta=Sn.memo(function({agentId:c,terminalViewMode:v,onTerminalViewModeChange:A,inspectorOpen:S,onToggleInspector:q,onImageClick:O,onFileClick:De,onBashClick:le,onViewMarkdown:g,onRequestClearSubordinates:Y,onOpenBuilding:ye,keyboard:We,canNavigateBack:He,canNavigateForward:Ve,onNavigateBack:pe,onNavigateForward:ie,agentInfoOpen:me,onToggleAgentInfo:Xe,onHeaderContextMenu:K,onBuildingContextMenu:fe}){var ce,Pe,ne,st;const h=Mn(c),$=Vt(),B=a.useRef(null),Ae=a.useRef(null);a.useEffect(()=>{const l=Ae.current;if(!l)return;const r=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),pe()):d.button===4&&(d.preventDefault(),d.stopPropagation(),ie())},o=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return l.addEventListener("mouseup",r),l.addEventListener("mousedown",o),()=>{l.removeEventListener("mouseup",r),l.removeEventListener("mousedown",o)}},[pe,ie]),a.useEffect(()=>{const l=Ae.current;if(!l)return;let r=0,o=0,d=0;const de=250,Ce=600,Le=80,bt=1.5,_t=P=>{let M=P instanceof HTMLElement?P:null;for(;M&&M!==l;){const lt=window.getComputedStyle(M).overflowX;if((lt==="auto"||lt==="scroll")&&M.scrollWidth>M.clientWidth)return!0;M=M.parentElement}return!1},V=P=>{const M=Date.now();if(M<d){P.preventDefault();return}if(Math.abs(P.deltaX)<=Math.abs(P.deltaY)*bt){r=0;return}if(_t(P.target)){r=0;return}M-o>de&&(r=0),o=M,r+=P.deltaX,r<=-Le?(r=0,d=M+Ce,P.preventDefault(),pe()):r>=Le&&(r=0,d=M+Ce,P.preventDefault(),ie())};return l.addEventListener("wheel",V,{passive:!1}),()=>l.removeEventListener("wheel",V)},[pe,ie]);const Ie=Ht(),he=a.useMemo(()=>{if(!h)return null;const l=new Set,r=[];for(const o of Ie.values())o.archived||o.directories.length===0||o.assignedAgentIds.includes(c)&&(l.add(o.id),r.push(o));for(const o of Ie.values())o.archived||o.directories.length===0||l.has(o.id)||ea({x:h.position.x,z:h.position.z},o)&&(l.add(o.id),r.push(o));return r.length===0?null:r.flatMap(o=>o.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:o.id,areaName:o.name,dir:d})))},[h,c,Ie]),{branches:Ge,fetchRemote:Ue,fetchingDirs:qe}=Tn(he),ge=a.useMemo(()=>{var o;const l=x.getAreaForAgent(c);if(!l)return[];const r=[];for(const d of $.values())d.type==="terminal"&&x.isPositionInArea(d.position,l)&&r.push({id:d.id,name:d.name,hasUrl:!!((o=d.terminalStatus)!=null&&o.url)});return r},[c,$]),Ye=a.useMemo(()=>{var o;const l=x.getAreaForAgent(c);if(!l)return[];const r=[];for(const d of $.values())d.type==="server"&&((o=d.pm2)!=null&&o.enabled)&&x.isPositionInArea(d.position,l)&&r.push({id:d.id,name:d.name});return r},[c,$]),xe=a.useMemo(()=>{const l=x.getAreaForAgent(c);if(!l)return[];const r=[];for(const o of $.values())o.type==="database"&&o.database&&x.isPositionInArea(o.position,l)&&r.push({id:o.id,name:o.name});return r},[c,$]),[,be]=a.useReducer(l=>l+1,0),F=((ce=B.current)==null?void 0:ce.search.searchMode)??!1,re=a.useCallback(()=>{var l;(l=B.current)==null||l.search.toggleSearch(),be()},[]),Ke=Pn(),Re=Ke.isPending(Ft),[W,X]=a.useState(null),R=W?$.get(W):null,{height:Ee,onResizeStart:G}=Ln(),[U,Z]=a.useState(()=>kt(y.GIT_PANEL_OPEN,!1)),[z,Ze]=a.useState(()=>kt(y.BUILDINGS_PANEL_OPEN,!1)),[_e,ze]=a.useState(!1),Se=a.useCallback(()=>{ze(l=>{const r=!l;return r&&Dn.setEnabled(!0),r})},[]),ft=a.useCallback(()=>ze(!1),[]),ht=a.useCallback(()=>{Z(l=>{const r=!l;return se(y.GIT_PANEL_OPEN,r),r})},[]),we=a.useCallback(()=>{Ze(l=>{const r=!l;return se(y.BUILDINGS_PANEL_OPEN,r),r})},[]),gt=a.useCallback(()=>{Z(!1),se(y.GIT_PANEL_OPEN,!1)},[]),Je=a.useCallback(()=>{Ze(!1),se(y.BUILDINGS_PANEL_OPEN,!1)},[]),xt=Rn();a.useEffect(()=>{if(!W)return;ge.some(r=>r.id===W)||X(null)},[W,ge]);const[J,oe]=a.useState(!1),Oe=a.useRef(null);if(a.useEffect(()=>{if(!J)return;const l=r=>{Oe.current&&!Oe.current.contains(r.target)&&oe(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[J]),!h)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 Q=h.contextStats,Qe=!!Q,et=Q?Q.totalTokens:h.contextUsed||0,tt=Q?Q.contextWindow:h.contextLimit||2e5,Me=Q?Q.usedPercent:Math.round(et/tt*100),f=Math.max(0,Math.min(100,Me)),ee=Math.round(f*10)/10,H=Math.round((100-f)*10)/10,ve=f>=80?"#ff4a4a":f>=60?"#ff9e4a":f>=40?"#ffd700":"#4aff9e",$e=(et/1e3).toFixed(1),nt=(tt/1e3).toFixed(1),te=h.cwd,at=te?Jn(te):null,Te=((Pe=h.subordinateIds)==null?void 0:Pe.length)||0,Be=Te>0;return e.jsxs("div",{ref:Ae,className:`flat-terminal-wrapper ${U||z||_e?"flat-terminal-wrapper--with-side-panel":""}`,children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${me?"flat-terminal-wrapper__header-main--active":""}`,onClick:Xe,onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K({x:l.clientX,y:l.clientY})},title:me?"Hide agent info":"Show agent info","aria-pressed":me,children:[e.jsx(Xt,{agent:h,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:h.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Gt(h.status)},children:h.status})]}),h.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:h.taskLabel,children:["📋 ",h.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:h.provider==="codex"?"/assets/codex.png":h.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:h.provider,className:"flat-terminal-wrapper__header-provider-icon",title:h.provider==="codex"?"Codex Agent":h.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:l,effort:r}=Qn(h);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:r?`Model: ${l} · Effort: ${r}`:`Model: ${l}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:l}),r&&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:r})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsx("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:qn.map(l=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${v===l?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>A(l),title:Zn[l],"aria-pressed":v===l,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Kn[l]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Yn[l]})]},l))}),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:pe,disabled:!He,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(u,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:ie,disabled:!Ve,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(u,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${F?"flat-terminal-wrapper__action-btn--active":""}`,onClick:re,title:F?"Close search":"Search messages","aria-pressed":F,children:e.jsx(u,{name:F?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Re?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Ke.handleClick(Ft,()=>{var l;x.clearContext(c),(l=B.current)==null||l.historyLoader.clearHistory()}),title:Re?"Click again to confirm clear context":"Clear context",children:e.jsx(u,{name:Re?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${U?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ht,title:U?"Hide git panel":"Show git changes","aria-pressed":U,children:e.jsx(u,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${z?"flat-terminal-wrapper__action-btn--active":""}`,onClick:we,title:z?"Hide buildings panel":"Show area buildings","aria-pressed":z,children:e.jsx(u,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Oe,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${J?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>oe(l=>!l),title:"More actions","aria-expanded":J,children:"⋮"}),J&&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 ${_e?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Se(),oe(!1)},title:_e?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(u,{name:"bug",size:14}),e.jsx("span",{children:_e?"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:()=>{x.collapseContext(c),oe(!1)},disabled:h.status!=="idle",title:h.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(u,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),Be&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{Y(c,Te),oe(!1)},children:[e.jsx(u,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",Te," subordinate",Te===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:()=>{x.killAgent(c),oe(!1)},children:[e.jsx(u,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${S?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:q,title:S?"Hide inspector panel":"Show inspector panel","aria-label":S?"Hide inspector panel":"Show inspector panel","aria-pressed":S,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:()=>x.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(u,{name:"cross",size:14})})]})]}),e.jsx(zn,{ref:B,agentId:c,agent:h,viewMode:v,isOpen:!0,onImageClick:O,onFileClick:De,onBashClick:le,onViewMarkdown:g,keyboard:We,hasModalOpen:!1}),R&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:G,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${R.name}`,style:{height:Ee},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(u,{name:"terminal",size:12}),e.jsx("span",{children:R.name}),!((ne=R.terminalStatus)!=null&&ne.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>X(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(u,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(st=R.terminalStatus)!=null&&st.url?e.jsx(On,{terminalUrl:R.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:[h.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(u,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),te&&at&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${te}`,"aria-label":`Open ${te} in file explorer`,role:"button",tabIndex:0,onClick:()=>x.openFileExplorer(te),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),x.openFileExplorer(te))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(u,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:at})]}),he&&he.map(({areaId:l,areaName:r,dir:o})=>{const d=Ge.get(o),de=qe.has(o),Ce=o.split("/").filter(Boolean).pop()||o;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${o}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>x.openFileExplorerForAreaFolder(l,o),children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Ce}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(u,{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(u,{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(u,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${de?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Le=>{Le.stopPropagation(),Ue(o)},children:e.jsx(u,{name:de?"hourglass":"download",size:12})})]})]},`${l}:${o}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>x.setContextModalAgentId(c),title:Qe?`Context usage: ${$e}k / ${nt}k tokens (${ee}% used). Click to view stats.`:"Click to fetch context stats",children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(u,{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:`${f}%`,backgroundColor:ve}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:ve},children:[$e,"k/",nt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",H,"% free)"]}),!Qe&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(u,{name:"warn",size:12})})]}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),ge.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:ge.map(l=>{const r=W===l.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${l.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${r?"Hide":"Show"} terminal: ${l.name}${l.hasUrl?"":" (starting...)"}`,onClick:()=>{if(r){X(null);return}l.hasUrl||x.sendBuildingCommand(l.id,"start"),X(l.id)},onContextMenu:o=>{o.preventDefault(),o.stopPropagation(),fe(l.id,{x:o.clientX,y:o.clientY})},children:e.jsx(u,{name:"terminal",size:14})},l.id)})}),Ye.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Ye.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${l.name}`,onClick:()=>ye(l.id),onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),fe(l.id,{x:r.clientX,y:r.clientY})},children:e.jsx(u,{name:"scroll",size:14})},l.id))}),xe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:xe.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${l.name}`,onClick:()=>ye(l.id),onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),fe(l.id,{x:r.clientX,y:r.clientY})},children:e.jsx(u,{name:"hard-drives",size:14})},l.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx($n,{})})]}),U&&e.jsx(Bn,{agentId:c,agents:xt,onClose:gt,branchInfoMap:Ge,fetchRemote:Ue,fetchingDirs:qe}),z&&e.jsx(Fn,{agentId:c,onClose:Je}),_e&&e.jsx(Wn,{agentId:c,onClose:ft})]})});function la({onAgentClick:w,onBuildingClick:c,onBuildingDoubleClick:v,onBuildingPopup:A,onAreaContextMenu:S,onOpenSpawnModal:q,onOpenBossSpawnModal:O,onOpenAreaModal:De}){const{t:le}=Wt(["common"]),g=dn(),Y=un(),[ye,We]=a.useState(null),[He,Ve]=a.useState(null),[pe,ie]=a.useState(null),[me,Xe]=a.useState(null),[K,fe]=a.useState(null),[h,$]=a.useState(null),[B,Ae]=a.useState(null),[Ie,he]=a.useState(!1),Ge=a.useCallback(()=>{he(t=>!t)},[]),Ue=a.useCallback(()=>{he(!1)},[]),[qe,ge]=a.useState(()=>{const t=Pt(y.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ye=a.useCallback(t=>{ge(t),Lt(y.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==y.VIEW_MODE)return;const s=n.newValue;(s==="simple"||s==="chat"||s==="advanced")&&ge(s)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[xe,be]=a.useState(()=>kt(y.FLAT_INSPECTOR_OPEN,!1)),[F,re]=a.useState(!1),Ke=a.useCallback(()=>re(t=>!t),[]),Re=a.useCallback(()=>re(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:F}}))},[F]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:xe}}))},[xe]),a.useEffect(()=>{const t=()=>re(_=>!_),n=()=>{be(_=>{const i=!_;return se(y.FLAT_INSPECTOR_OPEN,i),i})},s=()=>{re(!1),be(!1),se(y.FLAT_INSPECTOR_OPEN,!1)},p=()=>re(!1),m=()=>{be(!1),se(y.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",s),window.addEventListener("tide-close-flat-agents-drawer-only",p),window.addEventListener("tide-close-flat-inspector-only",m),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",s),window.removeEventListener("tide-close-flat-agents-drawer-only",p),window.removeEventListener("tide-close-flat-inspector-only",m)}},[]);const W=a.useRef(null),X=a.useRef(null),[R,Ee]=a.useState(()=>{const t=Dt(y.FLAT_MIDDLE_WIDTH,0);return t>=mt?t:null}),[G,U]=a.useState(()=>{const t=Dt(y.FLAT_INSPECTOR_WIDTH,0);return t>=Nt?t:null}),Z=a.useCallback(t=>{if(typeof window>"u")return t;const n=G!==null?pt+G:0,s=window.innerWidth-Bt-pt-$t-n;return Math.max(mt,Math.min(Math.max(s,mt),t))},[G]),z=a.useCallback(t=>{var m;if(typeof window>"u")return t;const n=(m=W.current)==null?void 0:m.querySelector(".flat-middle"),s=(n==null?void 0:n.getBoundingClientRect().width)??mt,p=window.innerWidth-Bt-s-pt-$t-pt;return Math.max(Nt,Math.min(Math.max(p,Nt),t))},[]);a.useEffect(()=>{if(R===null&&G===null)return;const t=()=>{Ee(n=>{if(n===null)return n;const s=Z(n);return s===n?n:s}),U(n=>{if(n===null)return n;const s=z(n);return s===n?n:s})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[R,G,Z,z]);const Ze=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=W.current)==null?void 0:s.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),_e=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=W.current)==null?void 0:s.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),ze=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;const s=t.clientX-n.startX;n.kind==="middle"?Ee(Z(n.startWidth+s)):U(z(n.startWidth-s))},[Z,z]),Se=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(X.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const p=t.clientX-n.startX;if(n.kind==="middle"){const m=Z(n.startWidth+p);Ee(m),ut(y.FLAT_MIDDLE_WIDTH,m)}else{const m=z(n.startWidth-p);U(m),ut(y.FLAT_INSPECTOR_WIDTH,m)}},[Z,z]),ft=a.useCallback(()=>{Ee(null),ut(y.FLAT_MIDDLE_WIDTH,0)},[]),ht=a.useCallback(()=>{U(null),ut(y.FLAT_INSPECTOR_WIDTH,0)},[]),[we,gt]=a.useState(()=>Pt(y.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Je=a.useCallback(t=>{gt(t),Lt(y.FLAT_INSPECTOR_VIEW,t)},[]),xt=a.useCallback(()=>{be(t=>{const n=!t;return se(y.FLAT_INSPECTOR_OPEN,n),n})},[]),J=a.useCallback(()=>{be(!1),se(y.FLAT_INSPECTOR_OPEN,!1)},[]),oe=pn(),Oe=a.useCallback((t,n)=>{We({url:t,name:n})},[]),Q=a.useCallback((t,n)=>{Ve({command:t,output:n,isLive:!1})},[]),Qe=a.useCallback((t,n)=>{x.setFileViewerPath(t,n)},[]),et=a.useCallback(t=>{ie(t)},[]),tt=a.useCallback((t,n)=>{Xe({agentId:t,count:n})},[]),Me=a.useCallback(t=>{v?v(t):c(t)},[c,v]),f=a.useMemo(()=>Y.size>0?Array.from(Y)[0]:null,[Y]);a.useEffect(()=>{he(!1)},[f]);const ee=a.useRef([]),H=a.useRef(-1),ve=a.useRef(!1),$e=a.useRef(null),[nt,te]=a.useState(!1),[at,Te]=a.useState(!1),Be=a.useRef(!1),ce=a.useRef(null),Pe=a.useRef(!1),ne=a.useMemo(()=>new Set(g.map(t=>t.id)),[g]),st=a.useMemo(()=>{const t=new Map(g.map(s=>[s.id,s])),n=new Map;for(const s of g)if((s.isBoss||s.class==="boss")&&s.subordinateIds&&s.subordinateIds.length>0){const p=s.subordinateIds.map(m=>t.get(m)).filter(m=>m!==void 0);p.length>0&&n.set(s.id,p)}return n},[g]),l=a.useCallback(()=>{const t=ee.current,n=H.current;te(n>0),Te(n>=0&&n<t.length-1)},[]),r=a.useCallback(t=>{const n=ee.current;if(n.length===0)return;let s=H.current+t;for(;s>=0&&s<n.length;){const p=n[s];if(ne.has(p)){ve.current=!0,H.current=s,l(),x.selectAgent(p);return}s+=t}},[ne,l]),o=a.useCallback(()=>r(-1),[r]),d=a.useCallback(()=>r(1),[r]);Gn(a.useCallback(()=>{const t=ee.current,n=H.current;return t.length>0&&n>0?(r(-1),"handled"):"exit"},[r]));const de=a.useCallback((t,n)=>{if(typeof window>"u")return;const s=window.history.state,m={...typeof s=="object"&&s!==null?s:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(m,"",window.location.href):window.history.pushState(m,"",window.location.href)},[]);a.useEffect(()=>{if(!f){Be.current=!1,ce.current=null;return}if(!Be.current){de(f,"replace"),Be.current=!0,ce.current=f;return}if(Pe.current){Pe.current=!1,ce.current=f;return}ce.current!==f&&(de(f,"push"),ce.current=f)},[f,de]),a.useEffect(()=>{const t=n=>{var _,i;const s=(i=(_=n.state)==null?void 0:_.__flatAgentNav)==null?void 0:i.agentId;if(!s||typeof s!="string"||!ne.has(s)||s===f)return;Pe.current=!0,ve.current=!0;const p=ee.current,m=p.lastIndexOf(s);m>=0?H.current=m:(p.push(s),H.current=p.length-1),l(),x.selectAgent(s)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ne,f,l]),a.useEffect(()=>{if(!f){ee.current=[],H.current=-1,l();return}if($e.current=f,ve.current){ve.current=!1,l();return}const t=ee.current,n=H.current;if(n>=0&&t[n]===f){l();return}const s=n<t.length-1?t.slice(0,n+1):t.slice();s.push(f),s.length>100&&s.shift(),ee.current=s,H.current=s.length-1,l()},[f,l]);const Ce=a.useCallback(t=>{w(t),re(!1)},[w]),Le=f??"",bt=a.useCallback(()=>{},[]),_t=a.useCallback(t=>{Ce(t)},[Ce]),V=xe,[P,M]=a.useState(V),[lt,yt]=a.useState(V);a.useEffect(()=>{if(V){M(!0);return}yt(!1);const t=setTimeout(()=>M(!1),240);return()=>clearTimeout(t)},[V]),a.useEffect(()=>{if(!P||!V)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>yt(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[P,V]);const At=a.useRef(null);a.useEffect(()=>{if(f)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const s=n.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const p=$e.current;!p||!ne.has(p)||(n.preventDefault(),x.selectAgent(p))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[f,ne]);const[Ut,It]=a.useState(new Set),qt=a.useCallback(t=>{It(n=>{const s=new Set(n);return s.has(t)?s.delete(t):s.add(t),s})},[]),[je,Yt]=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=s=>Yt(s.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[it,Kt]=a.useState(null),Zt=a.useCallback(t=>{Kt(n=>n===t?null:t)},[]),wt=Ht(),rt=Vt(),[Jt]=mn(),Ne=a.useMemo(()=>{const t=new Map,n=[];for(const b of g){const k=x.getAreaForAgent(b.id);if(!Rt((k==null?void 0:k.id)??null))continue;if(!k||k.archived){n.push(b);continue}const N=t.get(k.id);N?N.push(b):t.set(k.id,[b])}const s=new Map,p=[];for(const b of rt.values()){let k=!1;for(const N of wt.values())if(!N.archived&&zt(N.id)&&x.isPositionInArea(b.position,N)){const ae=s.get(N.id);ae?ae.push(b):s.set(N.id,[b]),k=!0;break}!k&&Rt(null)&&p.push(b)}const m=[];for(const[,b]of wt){if(b.archived||!zt(b.id))continue;const k=t.get(b.id),N=s.get(b.id)??[];(k&&k.length>0||N.length>0)&&m.push({area:b,agents:k??[],buildings:N})}(n.length>0||p.length>0)&&m.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:p});const _=m.filter(b=>b.area.id!=="__unassigned__"),i=m.filter(b=>b.area.id==="__unassigned__");let I=1,j=1;const E=new Map;if(_.length>1){let b=1/0,k=-1/0,N=1/0,ae=-1/0;for(const L of _)b=Math.min(b,L.area.center.x),k=Math.max(k,L.area.center.x),N=Math.min(N,L.area.center.z),ae=Math.max(ae,L.area.center.z);const ot=k-b||1,ct=ae-N||1;if(_.length<=4){I=_.length,j=1;const L=[..._].sort((D,vt)=>D.area.center.x-vt.area.center.x);for(let D=0;D<L.length;D++)E.set(L[D].area.id,{row:1,col:D+1})}else{const L=[..._].sort((C,T)=>C.area.center.x-T.area.center.x),D=[];for(let C=1;C<L.length;C++)D.push(L[C].area.center.x-L[C-1].area.center.x);const vt=D.reduce((C,T)=>C+T,0)/D.length||1;let Et=1;for(const C of D)C>vt*1.3&&Et++;I=Math.max(2,Math.min(Et,_.length));const Ct=[..._].sort((C,T)=>C.area.center.z-T.area.center.z),dt=[];for(let C=1;C<Ct.length;C++)dt.push(Ct[C].area.center.z-Ct[C-1].area.center.z);const nn=dt.reduce((C,T)=>C+T,0)/dt.length||1;let St=1;for(const C of dt)C>nn*1.3&&St++;j=Math.max(2,Math.min(St,_.length)),I=Math.max(I,Math.ceil(_.length/j)),j=Math.max(j,Math.ceil(_.length/I));const an=ot/I,sn=ct/j,jt=new Set;for(const C of _){let T=Math.min(I-1,Math.max(0,Math.floor((C.area.center.x-b)/an))),ke=Math.min(j-1,Math.max(0,Math.floor((C.area.center.z-N)/sn))),Fe=`${ke},${T}`,Mt=0;const ln=j*I;for(;jt.has(Fe)&&Mt<ln;)T++,T>=I&&(T=0,ke=(ke+1)%j),Fe=`${ke},${T}`,Mt++;jt.has(Fe)&&(ke=j,T=0,Fe=`${ke},${T}`,j++),jt.add(Fe),E.set(C.area.id,{row:ke+1,col:T+1})}}}const ue=b=>{b.sort((k,N)=>{var ot,ct,L,D;const ae=(((ot=k.position)==null?void 0:ot.z)??0)-(((ct=N.position)==null?void 0:ct.z)??0);return ae!==0?ae:(((L=k.position)==null?void 0:L.x)??0)-(((D=N.position)==null?void 0:D.x)??0)})};for(const b of _)ue(b.agents);for(const b of i)ue(b.agents);return{groups:[..._,...i],gridCols:I,gridRows:j,positions:E}},[g,wt,rt,Jt]),Qt=a.useMemo(()=>{if(!K)return[];const t=g.find(n=>n.id===K.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(u,{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(u,{name:"chat",size:14}),onClick:()=>w(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>{Ae({agentId:t.id,name:t.name})}}]:[]},[K,g,w]),en=a.useMemo(()=>{var _;if(!h)return[];const t=rt.get(h.buildingId);if(!t)return[];const n=[],s=t.type==="server"||t.type==="docker"||t.type==="terminal",p=t.status==="running",m=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((_=t.pm2)!=null&&_.enabled)?"View PM2 Logs":"Open",icon:e.jsx(u,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>Me(t.id)}),s&&(p||n.push({id:"start",label:"Start",icon:e.jsx(u,{name:"play",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"start")}),p&&(n.push({id:"restart",label:"Restart",icon:e.jsx(u,{name:"refresh",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(u,{name:"stop",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"stop")}))),m&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(u,{name:"launch",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(u,{name:"pause",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(u,{name:"restart",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"restart")}})),s&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(u,{name:"health",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(u,{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(u,{name:"copy",size:14}),onClick:()=>{x.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 i of t.urls)n.push({id:`url-${i.label}`,label:i.label,icon:e.jsx(u,{name:"link",size:14}),onClick:()=>window.open(i.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>x.deleteBuilding(t.id)}),n},[h,rt,Me]),tn=a.useCallback(t=>{const n=new Set(Ne.groups.map(s=>s.area.id));n.delete(t),It(n),requestAnimationFrame(()=>{const s=At.current;if(!s)return;const p=s.querySelector(`[data-area-id="${t}"]`);if(!p)return;const m=s.getBoundingClientRect(),i=p.getBoundingClientRect().top-m.top+s.scrollTop-8;s.scrollTo({top:Math.max(0,i),behavior:"smooth"})})},[Ne]);return e.jsxs("div",{ref:W,className:`flat-view ${V?"flat-view--with-inspector":""} ${f?"flat-view--has-chat":""} ${F?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(R===null&&G===null)return;const t={};return R!==null&&(t["--flat-middle-width"]=`${R}px`),G!==null&&(t["--flat-inspector-width"]=`${G}px`),t})(),children:[F&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Re,"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:q,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:O,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:De,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(fn,{activeAgentId:Le,onClose:bt,onSelectAgent:_t,collapsedAreas:Ut,onToggleArea:qt,agentListRef:At})})]}),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:Ze,onPointerMove:ze,onPointerUp:Se,onPointerCancel:Se,onDoubleClick:ft}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":F?"Close agents sidebar":"Open agents sidebar","aria-expanded":F,onClick:Ke,children:[e.jsx(u,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),f?e.jsx(ta,{agentId:f,terminalViewMode:qe,onTerminalViewModeChange:Ye,inspectorOpen:xe,onToggleInspector:xt,onImageClick:Oe,onFileClick:Qe,onBashClick:Q,onViewMarkdown:et,onRequestClearSubordinates:tt,onOpenBuilding:Me,keyboard:oe,canNavigateBack:nt,canNavigateForward:at,onNavigateBack:o,onNavigateForward:d,agentInfoOpen:Ie,onToggleAgentInfo:Ge,onHeaderContextMenu:t=>{f&&fe({agentId:f,position:t})},onBuildingContextMenu:(t,n)=>{$({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(Un,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Ne.gridCols}, 1fr)`},children:Ne.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=je&&it?((n=Ne.positions.get(it))==null?void 0:n.row)??null:null;return Ne.groups.map(s=>{const p=s.area.id,m=Ne.positions.get(p),_=je&&it!==p;return je&&t!=null&&(m==null?void 0:m.row)===t&&p!==it?null:e.jsxs("div",{className:`flat-map-area-card${_?" flat-map-area-card--collapsed":""}`,style:{"--area-color":s.area.color,gridRow:m==null?void 0:m.row,gridColumn:m==null?void 0:m.col},onContextMenu:i=>{S&&(i.preventDefault(),i.stopPropagation(),S(p,{x:i.clientX,y:i.clientY}))},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>je?Zt(p):tn(p),title:je?_?`Expand ${s.area.name}`:`Collapse ${s.area.name}`:`Focus ${s.area.name} in left panel`,"aria-expanded":je?!_:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:s.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:s.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:s.agents.length}),je&&e.jsx(u,{name:_?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:s.agents.map(i=>{const I=i.isBoss||i.class==="boss",j=I?st.get(i.id):void 0,E=hn(i),ue=E.usedPercent>=80?"#ff4a4a":E.usedPercent>=60?"#ff9e4a":E.usedPercent>=40?"#ffd700":"#4aff9e",b=`Context: ${(E.totalTokens/1e3).toFixed(1)}k / ${(E.contextWindow/1e3).toFixed(1)}k (${E.usedPercent}% used, ${E.freePercent}% free)`,k=i.latestTodos&&i.latestTodos.length>0||j&&j.length>0;return e.jsx(gn,{todos:i.latestTodos,subordinates:j,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${i.status}`,onClick:()=>w(i.id),onContextMenu:N=>{N.preventDefault(),N.stopPropagation(),fe({agentId:i.id,position:{x:N.clientX,y:N.clientY}})},title:k?void 0:`${I?"Boss · ":""}Open chat with ${i.name}
2
2
  ${b}`,children:[e.jsx(Xt,{agent:i,size:16}),I&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(u,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:i.name}),e.jsx("img",{src:i.provider==="codex"?"/assets/codex.png":i.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:i.provider,className:"flat-map-agent-chip__provider-icon",title:i.provider==="codex"?"Codex Agent":i.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:Gt(i.status)}}),i.latestTodos&&i.latestTodos.length>0&&e.jsx(xn,{todos:i.latestTodos,maxDots:6}),I&&j&&j.length>0&&e.jsx(bn,{subordinates:j,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:`${E.usedPercent}%`,backgroundColor:ue}})})]})},i.id)})}),s.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${s.area.name} folders`,children:s.area.directories.map(i=>{const I=i.split("/").filter(Boolean).pop()||i;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:j=>{j.stopPropagation(),x.openFileExplorerForAreaFolder(p,i)},title:`Open in file explorer: ${i}`,children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:I})]},i)})}),s.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:s.buildings.map(i=>{var j;const I=(j=_n[i.type])==null?void 0:j.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${i.status}`,style:I?{"--building-type-color":I}:void 0,onClick:E=>{if(A){const ue=E.currentTarget.getBoundingClientRect();A(i.id,{x:ue.right,y:ue.top+ue.height/2})}else Me(i.id)},onContextMenu:E=>{E.preventDefault(),E.stopPropagation(),$({buildingId:i.id,position:{x:E.clientX,y:E.clientY}})},title:`${i.name} · ${i.type} · ${i.status}`,children:[e.jsx(u,{name:wn(i.type),size:12,color:I}),e.jsx("span",{className:"flat-map-building-chip__name",children:i.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:vn(i.status)}})]},i.id)})})]},p)})})()})]})})]}),V&&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:_e,onPointerMove:ze,onPointerUp:Se,onPointerCancel:Se,onDoubleClick:ht}),P&&e.jsxs("aside",{className:`flat-inspector ${lt?"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":we==="agent",className:`flat-inspector__tab ${we==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>Je("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":we==="tracking",className:`flat-inspector__tab ${we==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>Je("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:J,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:we==="tracking"?e.jsx(Cn,{activeAgentId:f??"",onSelectAgent:t=>{w(t),window.innerWidth<=768&&J()}}):(()=>{if(!f)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=g.find(n=>n.id===f);return t?e.jsx(jn,{agent:t,onFocusAgent:n=>{w(n),window.innerWidth<=768&&J()},onKillAgent:n=>x.killAgent(n)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),ye&&e.jsx(Nn,{url:ye.url,name:ye.name,onClose:()=>We(null)}),He&&e.jsx(kn,{state:He,onClose:()=>Ve(null)}),e.jsx(yn,{agent:f?g.find(t=>t.id===f)??null:null,content:pe,onClose:()=>ie(null)}),me&&e.jsx(An,{action:"clear-subordinates",selectedAgentId:me.agentId,subordinateCount:me.count,onClose:()=>Xe(null),onClearHistory:()=>{}}),e.jsx(In,{agent:f?g.find(t=>t.id===f)??null:null,isOpen:Ie&&!!f,onClose:Ue}),e.jsx(Ot,{isOpen:K!==null,position:(K==null?void 0:K.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:Qt,onClose:()=>fe(null)}),e.jsx(Ot,{isOpen:h!==null,position:(h==null?void 0:h.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:en,onClose:()=>$(null)}),e.jsx(En,{isOpen:B!==null,title:le("common:confirm.removeAgentTitle"),message:le("common:confirm.removeAgentMessage",{name:(B==null?void 0:B.name)??""}),confirmLabel:le("common:buttons.remove"),cancelLabel:le("common:buttons.cancel"),variant:"danger",onConfirm:()=>{B&&x.removeAgentFromServer(B.agentId)},onClose:()=>Ae(null)})]})}export{la as FlatView};
@@ -1 +1 @@
1
- import{u as J,a as Z,r,s as h,j as e,D as de,I as H,C as oe,b as me,c as be,d as ue,g as he,e as _e,Q as pe,R as xe}from"./main-BxA3Bhkv.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fe=({building:a,connections:x,activeConnectionId:l,activeDatabase:c,collapsed:y,onToggleCollapse:f,onConnectionChange:Q,onDatabaseChange:S,onInsertTable:L,onSelectTableQuery:P})=>{const{t:m}=J(["terminal"]),q=Z(a.id),[I,R]=r.useState(new Set),[k,n]=r.useState(""),[d,g]=r.useState(""),[$,w]=r.useState(!1),[U,F]=r.useState(null),K=r.useRef(null),C=r.useRef(null),O=r.useRef(null),N=l?q.databases.get(l)??[]:[],G=l&&c?`${l}:${c}`:"",j=G?q.tables.get(G)??[]:[],p=l?q.connectionStatus.get(l):void 0,D=r.useMemo(()=>{if(!k.trim())return N;const t=k.toLowerCase();return N.filter(o=>o.toLowerCase().includes(t))},[N,k]),b=r.useMemo(()=>{if(!d.trim())return j;const t=d.toLowerCase();return j.filter(o=>o.name.toLowerCase().includes(t))},[j,d]);r.useEffect(()=>{const t=o=>{C.current&&!C.current.contains(o.target)&&w(!1)};return $&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[$]),r.useEffect(()=>{l&&!p&&h.testDatabaseConnection(a.id,l)},[a.id,l,p]),r.useEffect(()=>{l&&(p!=null&&p.connected)&&N.length===0&&h.listDatabases(a.id,l)},[a.id,l,p==null?void 0:p.connected,N.length]),r.useEffect(()=>{l&&c&&j.length===0&&h.listTables(a.id,l,c)},[a.id,l,c,j.length]),r.useEffect(()=>{F(null),g("")},[l,c]);const _=r.useCallback(t=>{R(o=>{const T=new Set(o);if(T.has(t))T.delete(t);else if(T.add(t),l&&c){const v=`${l}:${c}:${t}`;q.tableSchemas.has(v)||h.getTableSchema(a.id,l,c,t)}return T})},[a.id,l,c,q.tableSchemas]),z=t=>{if(!l||!c)return null;const o=`${l}:${c}:${t}`;return q.tableSchemas.get(o)};return y?e.jsx("div",{className:"database-sidebar database-sidebar--collapsed",children:e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.expandSidebar"),children:"»"})}):e.jsxs("div",{className:"database-sidebar",children:[e.jsxs("div",{className:"database-sidebar__header",children:[e.jsx("span",{children:m("terminal:database.explorer")}),e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.collapseSidebar"),children:"«"})]}),e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.connection")}),e.jsx("select",{className:"database-sidebar__select",value:l||"",onChange:t=>Q(t.target.value),children:x.length===0?e.jsx("option",{value:"",children:m("terminal:database.noConnections")}):x.map(t=>{var o;return e.jsxs("option",{value:t.id,children:[((o=de[t.engine])==null?void 0:o.icon)??"🗄️"," ",t.name]},t.id)})}),p&&e.jsx("div",{className:`database-sidebar__status ${p.connected?"database-sidebar__status--connected":"database-sidebar__status--error"}`,children:p.connected?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✓"}),m("terminal:database.connected"),p.serverVersion&&e.jsxs("span",{className:"database-sidebar__version",children:["(",p.serverVersion,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✗"}),p.error||m("terminal:database.disconnected")]})})]}),N.length>0&&e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.databaseTitle")}),e.jsxs("div",{className:"database-sidebar__searchable-select",ref:C,children:[e.jsx("input",{ref:K,className:"database-sidebar__search-input",type:"text",value:$?k:c||"",placeholder:m("terminal:database.selectDatabase"),onChange:t=>{n(t.target.value),$||w(!0)},onFocus:()=>{w(!0),n("")},onKeyDown:t=>{var o,T;t.key==="Escape"?(w(!1),n(""),(o=K.current)==null||o.blur()):t.key==="Enter"&&D.length===1&&(S(D[0]),w(!1),n(""),(T=K.current)==null||T.blur())}}),$&&e.jsx("div",{className:"database-sidebar__dropdown",children:D.length===0?e.jsx("div",{className:"database-sidebar__dropdown-empty",children:"No matches"}):D.map(t=>e.jsx("div",{className:`database-sidebar__dropdown-item ${t===c?"database-sidebar__dropdown-item--active":""}`,onMouseDown:o=>{o.preventDefault(),S(t),w(!1),n("")},children:t},t))})]})]}),j.length>0&&e.jsxs("div",{className:"database-sidebar__section database-sidebar__section--tables",children:[e.jsx("div",{className:"database-sidebar__section-title",children:d.trim()?m("terminal:database.tablesCount",{count:b.length})+` / ${j.length}`:m("terminal:database.tablesCount",{count:j.length})}),e.jsxs("div",{className:"database-sidebar__table-filter",children:[e.jsx("input",{ref:O,className:"database-sidebar__table-filter-input",type:"text",value:d,placeholder:m("terminal:database.filterTables"),onChange:t=>g(t.target.value),onKeyDown:t=>{var o;t.key==="Escape"&&(d?g(""):(o=O.current)==null||o.blur(),t.stopPropagation())}}),d&&e.jsx("button",{className:"database-sidebar__table-filter-clear",onClick:()=>{var t;g(""),(t=O.current)==null||t.focus()},title:"Clear filter",children:"×"})]}),e.jsxs("div",{className:"database-sidebar__tables",children:[d.trim()&&b.length===0&&e.jsx("div",{className:"database-sidebar__tables-empty",children:m("terminal:database.noTablesMatch")}),b.map(t=>{const o=I.has(t.name),T=o?z(t.name):null;return e.jsxs("div",{className:"database-sidebar__table",children:[e.jsxs("div",{className:"database-sidebar__table-header",children:[e.jsx("button",{className:"database-sidebar__table-expand",onClick:()=>_(t.name),title:o?"Collapse table schema":"Expand table schema",children:e.jsx(H,{name:o?"caret-down":"caret-right",size:10})}),e.jsx("span",{className:"database-sidebar__table-icon",children:e.jsx(H,{name:t.type==="view"?"eye":"clipboard",size:12})}),e.jsx("span",{className:`database-sidebar__table-name ${U===t.name?"database-sidebar__table-name--selected":""}`,onClick:()=>F(t.name),onDoubleClick:()=>{F(t.name),P(t.name)},children:t.name}),e.jsx("button",{className:"database-sidebar__table-insert",onClick:v=>{v.stopPropagation(),L(t.name)},title:m("terminal:database.insertTableName"),children:"+"})]}),o&&T&&e.jsx("div",{className:"database-sidebar__table-columns",children:T.columns.map(v=>e.jsxs("div",{className:"database-sidebar__column",onClick:()=>L(v.name),title:`${v.type}${v.nullable?" NULL":" NOT NULL"}${v.primaryKey?" PK":""}`,children:[e.jsx("span",{className:"database-sidebar__column-icon",children:v.primaryKey?e.jsx(H,{name:"key",size:11}):null}),e.jsx("span",{className:"database-sidebar__column-name",children:v.name}),e.jsx("span",{className:"database-sidebar__column-type",children:v.type})]},v.name))})]},t.name)})]})]})]})},je=({buildingId:a,history:x,onLoadQuery:l})=>{const{t:c}=J(["terminal","common"]),[y,f]=r.useState(""),[Q,S]=r.useState(!1),[L,P]=r.useState(!1),m=r.useMemo(()=>{let n=x;if(Q&&(n=n.filter(d=>d.favorite)),y.trim()){const d=y.toLowerCase();n=n.filter(g=>g.query.toLowerCase().includes(d)||g.database.toLowerCase().includes(d))}return n},[x,Q,y]),q=n=>{const d=new Date(n),$=new Date().getTime()-d.getTime();return $<1440*60*1e3?d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):$<10080*60*1e3?d.toLocaleDateString([],{weekday:"short"})+" "+d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):d.toLocaleDateString([],{month:"short",day:"numeric"})},I=r.useCallback((n,d)=>{d.stopPropagation(),h.toggleQueryFavorite(a,n)},[a]),R=r.useCallback((n,d)=>{d.stopPropagation(),h.deleteQueryFromHistory(a,n)},[a]),k=r.useCallback(()=>{P(!0)},[]);return x.length===0?e.jsxs("div",{className:"query-history query-history--empty",children:[e.jsx("p",{children:c("terminal:database.noHistory")}),e.jsx("p",{children:c("terminal:database.queriesAppearHere")})]}):e.jsxs("div",{className:"query-history",children:[e.jsxs("div",{className:"query-history__toolbar",children:[e.jsx("input",{type:"text",className:"query-history__search",placeholder:c("terminal:database.searchQueries"),value:y,onChange:n=>f(n.target.value)}),e.jsxs("label",{className:"query-history__filter",children:[e.jsx("input",{type:"checkbox",checked:Q,onChange:n=>S(n.target.checked)}),c("terminal:database.favoritesOnly")]}),e.jsx("button",{className:"query-history__clear",onClick:k,title:c("terminal:database.clearAll"),children:c("terminal:database.clearAll")})]}),e.jsxs("div",{className:"query-history__list",children:[m.map(n=>e.jsxs("div",{className:`query-history__item ${n.status==="error"?"query-history__item--error":""}`,onClick:()=>l(n.query),children:[e.jsxs("div",{className:"query-history__item-header",children:[e.jsx("span",{className:`query-history__status ${n.status==="success"?"query-history__status--success":"query-history__status--error"}`,children:e.jsx(H,{name:n.status==="success"?"check":"cross",size:12})}),e.jsx("span",{className:"query-history__database",children:n.database}),e.jsx("span",{className:"query-history__date",children:q(n.executedAt)}),e.jsxs("span",{className:"query-history__duration",children:[n.duration,"ms"]}),n.rowCount!==void 0&&e.jsx("span",{className:"query-history__row-count",children:c("terminal:database.rowCount",{count:n.rowCount})})]}),e.jsx("div",{className:"query-history__query",children:e.jsx("code",{children:n.query.length>200?n.query.substring(0,200)+"...":n.query})}),n.error&&e.jsx("div",{className:"query-history__error",children:n.error}),e.jsxs("div",{className:"query-history__actions",children:[e.jsx("button",{className:`query-history__favorite ${n.favorite?"query-history__favorite--active":""}`,onClick:d=>I(n.id,d),title:n.favorite?c("terminal:database.removeFromFavorites"):c("terminal:database.addToFavorites"),children:e.jsx(H,{name:"star",size:12,weight:n.favorite?"fill":"regular",color:n.favorite?"#facc15":void 0})}),e.jsx("button",{className:"query-history__delete",onClick:d=>R(n.id,d),title:c("terminal:database.deleteFromHistory"),children:e.jsx(H,{name:"trash",size:12})})]})]},n.id)),m.length===0&&e.jsx("div",{className:"query-history__no-results",children:c("terminal:database.noQueriesMatch")})]}),e.jsx(oe,{isOpen:L,title:c("terminal:database.clearAll"),message:c("terminal:database.confirmClearHistory"),confirmLabel:c("terminal:database.clearAll"),cancelLabel:c("common:buttons.cancel"),variant:"danger",onConfirm:()=>h.clearQueryHistory(a),onClose:()=>P(!1)})]})},ye=({tabs:a,activeTabId:x,onTabClick:l,onTabClose:c})=>{const{t:y}=J(["terminal"]);return e.jsx("div",{className:"database-tabs",children:a.map(f=>e.jsxs("div",{className:`database-tabs__tab ${x===f.id?"database-tabs__tab--active":""}`,children:[e.jsxs("button",{className:"database-tabs__tab-label",onClick:()=>l(f),title:`${f.connectionName} / ${f.database}`,children:[f.database,e.jsx("span",{className:"database-tabs__tab-connection",children:f.connectionName})]}),e.jsx("button",{className:"database-tabs__tab-close",onClick:()=>c(f.id),title:y("terminal:database.closeTab"),"aria-label":`Close ${f.database} tab`,children:"×"})]},f.id))})},ee=a=>`db-panel-${a}`;function Ne(a){try{const x=localStorage.getItem(ee(a));return x?JSON.parse(x):{}}catch{return{}}}function ve(a,x){try{localStorage.setItem(ee(a),JSON.stringify(x))}catch{}}const ge=({building:a,onClose:x})=>{var B,W,Y,X;const{t:l}=J(["terminal","common"]),c=Z(a.id),y=me(a.id),f=be(a.id),Q=ue(a.id),S=r.useRef(Ne(a.id)),L=r.useRef(null),P=r.useRef(0),m=((B=a.database)==null?void 0:B.connections)??[],q=(s,i)=>`${s}:${i}`,I=s=>s?(S.current.queries??{})[s]??"":S.current.generalQuery??"",[R,k]=r.useState("results"),[n,d]=r.useState(0),[g,$]=r.useState(!1),[w,U]=r.useState(!1),[F,K]=r.useState(()=>(S.current.openTabs??[]).map(i=>{var u;return{id:`${i.connectionId}:${i.database}`,connectionId:i.connectionId,connectionName:((u=m.find(A=>A.id===i.connectionId))==null?void 0:u.name)??i.connectionId,database:i.database}})),[C,O]=r.useState(S.current.activeTabId??null),[N,G]=r.useState(()=>{const s=S.current.queries??{};return S.current.generalQuery,s}),[j,p]=r.useState(I(C)),D=r.useCallback(s=>{p(i=>{const u=typeof s=="function"?s(i):s;return G(A=>{const E={...A};return C&&(E[C]=u),E}),u})},[C]),b=c.activeConnectionId??S.current.connectionId??((W=a.database)==null?void 0:W.activeConnectionId)??((Y=m[0])==null?void 0:Y.id),_=c.activeDatabase??S.current.database??((X=a.database)==null?void 0:X.activeDatabase),z=m.find(s=>s.id===b),t=b&&_?`${b}:${_}`:"",o=t?c.tables.get(t)??[]:[],T=r.useMemo(()=>{const s=new Map;return!b||!_||o.forEach(i=>{const u=c.tableSchemas.get(`${b}:${_}:${i.name}`);u&&s.set(i.name,{columns:u.columns})}),s},[b,_,o,c.tableSchemas]),v=r.useCallback((s,i)=>{var E;const u=q(s,i),A=((E=m.find(M=>M.id===s))==null?void 0:E.name)??s;K(M=>{if(M.some(ie=>ie.id===u))return M;const ce={id:u,connectionId:s,connectionName:A,database:i};return[...M,ce]}),O(u),p(N[u]??""),h.setActiveConnection(a.id,s),h.setActiveDatabase(a.id,i)},[a.id,m,N]),ae=r.useCallback(s=>{K(i=>i.filter(u=>u.id!==s)),C===s&&K(i=>{if(i.length>0){const u=i[0];O(u.id),p(N[u.id]??""),h.setActiveConnection(a.id,u.connectionId),h.setActiveDatabase(a.id,u.database)}else O(null),p("");return i})},[C,a.id,N]),se=r.useCallback(s=>{O(s.id),p(N[s.id]??""),h.setActiveConnection(a.id,s.connectionId),h.setActiveDatabase(a.id,s.database)},[a.id,N]);r.useEffect(()=>{if(!w&&m.length>0){const s=S.current;s.connectionId&&m.some(i=>i.id===s.connectionId)&&(h.setActiveConnection(a.id,s.connectionId),h.listDatabases(a.id,s.connectionId),s.database&&(h.setActiveDatabase(a.id,s.database),h.listTables(a.id,s.connectionId,s.database))),U(!0)}},[a.id,m,w]),r.useEffect(()=>{h.requestQueryHistory(a.id)},[a.id]),r.useEffect(()=>{const s=i=>{i.key==="Escape"&&(i.preventDefault(),i.stopPropagation(),x())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[x]),r.useEffect(()=>{w&&b&&ve(a.id,{connectionId:b,database:_,lastQuery:j,queries:N,generalQuery:"",openTabs:F.map(s=>({connectionId:s.connectionId,database:s.database})),activeTabId:C??void 0})},[a.id,b,_,j,w,F,C,N]);const te=r.useCallback(s=>{var i;if(!(!b||!_||!j.trim()||Q))if(s==="cursor"){const u=(i=L.current)==null?void 0:i.querySelector(".query-editor__textarea"),A=(u==null?void 0:u.selectionStart)??P.current,E=he(j,A);E&&h.executeQuery(a.id,b,_,E)}else{const u=_e(j);if(u.length<=1)h.executeQuery(a.id,b,_,j.trim());else{const A=b,E=_;(async()=>{for(const M of u)await h.executeQueryAndWait(a.id,A,E,M.sql)})()}}},[a.id,b,_,j,Q]),ne=r.useCallback(s=>{D(s),k("results")},[]),re=r.useCallback(s=>{h.setActiveConnection(a.id,s),h.listDatabases(a.id,s)},[a.id]),le=r.useCallback(s=>{b&&(v(b,s),h.listTables(a.id,b,s))},[a.id,b,v]),V=y[n];return m.length===0?e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:e.jsx(H,{name:"database",size:16})}),e.jsx("span",{className:"database-panel__name",children:a.name})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsx("div",{className:"database-panel__body",children:e.jsxs("div",{className:"database-panel__no-connections",children:[e.jsx("div",{className:"database-panel__no-connections-icon",children:e.jsx(H,{name:"plug",size:32})}),e.jsx("h3",{children:l("terminal:database.noConnections")}),e.jsx("p",{children:l("terminal:database.noConnectionsDesc")}),e.jsx("p",{children:l("terminal:database.toGetStarted")}),e.jsxs("ol",{children:[e.jsx("li",{children:l("terminal:database.step1Close")}),e.jsx("li",{children:l("terminal:database.step2Settings")}),e.jsx("li",{children:l("terminal:database.step3AddConnection")}),e.jsx("li",{children:l("terminal:database.step4Reopen")})]})]})})]}):e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:(z==null?void 0:z.engine)==="mysql"?"🐬":"🐘"}),e.jsx("span",{className:"database-panel__name",children:a.name}),z&&e.jsxs("span",{className:"database-panel__connection-info",children:[z.name," / ",_||l("terminal:database.noDatabaseSelected")]})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsxs("div",{className:"database-panel__body",children:[e.jsx(fe,{building:a,connections:m,activeConnectionId:b,activeDatabase:_,collapsed:g,onToggleCollapse:()=>$(!g),onConnectionChange:re,onDatabaseChange:le,onInsertTable:s=>D(i=>i+` ${s}`),onSelectTableQuery:s=>{const i=`SELECT * FROM ${s}`;D(i),b&&_&&h.executeQuery(a.id,b,_,i)}}),e.jsxs("div",{className:"database-panel__main",children:[F.length>0&&e.jsx(ye,{tabs:F,activeTabId:C,onTabClick:se,onTabClose:ae}),e.jsx(pe,{query:j,onChange:D,onExecute:te,isExecuting:Q,disabled:!b||!_,tables:o,tableSchemas:T,onRequestTableSchema:s=>{b&&_&&h.getTableSchema(a.id,b,_,s)}}),e.jsxs("div",{className:"database-panel__tabs",children:[e.jsxs("button",{className:`database-panel__tab ${R==="results"?"database-panel__tab--active":""}`,onClick:()=>k("results"),children:[l("terminal:database.results"),y.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:y.length})]}),e.jsxs("button",{className:`database-panel__tab ${R==="history"?"database-panel__tab--active":""}`,onClick:()=>k("history"),children:[l("terminal:database.history"),f.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:f.length})]}),R==="results"&&y.length>1&&e.jsxs("div",{className:"database-panel__result-nav",children:[e.jsxs("button",{disabled:n>=y.length-1,onClick:()=>d(s=>s+1),children:["← ",l("terminal:database.older")]}),e.jsxs("span",{children:[n+1," / ",y.length]}),e.jsxs("button",{disabled:n<=0,onClick:()=>d(s=>s-1),children:[l("terminal:database.newer")," →"]})]})]}),e.jsx("div",{className:"database-panel__tab-content",children:R==="results"?V?e.jsx(xe,{result:V,buildingId:a.id,building:a}):e.jsxs("div",{className:"database-panel__empty",children:[e.jsx("p",{children:l("terminal:database.noResultsYet")}),e.jsx("p",{children:l("terminal:database.selectDbAndRun")})]}):e.jsx(je,{buildingId:a.id,history:f,onLoadQuery:ne})})]})]})]})};export{ge as DatabasePanel,fe as DatabaseSidebar,ye as DatabaseTabs,pe as QueryEditor,je as QueryHistoryPanel,xe as ResultsTable};
1
+ import{u as J,a as Z,r,s as h,j as e,D as de,I as H,C as oe,b as me,c as be,d as ue,g as he,e as _e,Q as pe,R as xe}from"./main-CyZg1kKu.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fe=({building:a,connections:x,activeConnectionId:l,activeDatabase:c,collapsed:y,onToggleCollapse:f,onConnectionChange:Q,onDatabaseChange:S,onInsertTable:L,onSelectTableQuery:P})=>{const{t:m}=J(["terminal"]),q=Z(a.id),[I,R]=r.useState(new Set),[k,n]=r.useState(""),[d,g]=r.useState(""),[$,w]=r.useState(!1),[U,F]=r.useState(null),K=r.useRef(null),C=r.useRef(null),O=r.useRef(null),N=l?q.databases.get(l)??[]:[],G=l&&c?`${l}:${c}`:"",j=G?q.tables.get(G)??[]:[],p=l?q.connectionStatus.get(l):void 0,D=r.useMemo(()=>{if(!k.trim())return N;const t=k.toLowerCase();return N.filter(o=>o.toLowerCase().includes(t))},[N,k]),b=r.useMemo(()=>{if(!d.trim())return j;const t=d.toLowerCase();return j.filter(o=>o.name.toLowerCase().includes(t))},[j,d]);r.useEffect(()=>{const t=o=>{C.current&&!C.current.contains(o.target)&&w(!1)};return $&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[$]),r.useEffect(()=>{l&&!p&&h.testDatabaseConnection(a.id,l)},[a.id,l,p]),r.useEffect(()=>{l&&(p!=null&&p.connected)&&N.length===0&&h.listDatabases(a.id,l)},[a.id,l,p==null?void 0:p.connected,N.length]),r.useEffect(()=>{l&&c&&j.length===0&&h.listTables(a.id,l,c)},[a.id,l,c,j.length]),r.useEffect(()=>{F(null),g("")},[l,c]);const _=r.useCallback(t=>{R(o=>{const T=new Set(o);if(T.has(t))T.delete(t);else if(T.add(t),l&&c){const v=`${l}:${c}:${t}`;q.tableSchemas.has(v)||h.getTableSchema(a.id,l,c,t)}return T})},[a.id,l,c,q.tableSchemas]),z=t=>{if(!l||!c)return null;const o=`${l}:${c}:${t}`;return q.tableSchemas.get(o)};return y?e.jsx("div",{className:"database-sidebar database-sidebar--collapsed",children:e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.expandSidebar"),children:"»"})}):e.jsxs("div",{className:"database-sidebar",children:[e.jsxs("div",{className:"database-sidebar__header",children:[e.jsx("span",{children:m("terminal:database.explorer")}),e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.collapseSidebar"),children:"«"})]}),e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.connection")}),e.jsx("select",{className:"database-sidebar__select",value:l||"",onChange:t=>Q(t.target.value),children:x.length===0?e.jsx("option",{value:"",children:m("terminal:database.noConnections")}):x.map(t=>{var o;return e.jsxs("option",{value:t.id,children:[((o=de[t.engine])==null?void 0:o.icon)??"🗄️"," ",t.name]},t.id)})}),p&&e.jsx("div",{className:`database-sidebar__status ${p.connected?"database-sidebar__status--connected":"database-sidebar__status--error"}`,children:p.connected?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✓"}),m("terminal:database.connected"),p.serverVersion&&e.jsxs("span",{className:"database-sidebar__version",children:["(",p.serverVersion,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✗"}),p.error||m("terminal:database.disconnected")]})})]}),N.length>0&&e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.databaseTitle")}),e.jsxs("div",{className:"database-sidebar__searchable-select",ref:C,children:[e.jsx("input",{ref:K,className:"database-sidebar__search-input",type:"text",value:$?k:c||"",placeholder:m("terminal:database.selectDatabase"),onChange:t=>{n(t.target.value),$||w(!0)},onFocus:()=>{w(!0),n("")},onKeyDown:t=>{var o,T;t.key==="Escape"?(w(!1),n(""),(o=K.current)==null||o.blur()):t.key==="Enter"&&D.length===1&&(S(D[0]),w(!1),n(""),(T=K.current)==null||T.blur())}}),$&&e.jsx("div",{className:"database-sidebar__dropdown",children:D.length===0?e.jsx("div",{className:"database-sidebar__dropdown-empty",children:"No matches"}):D.map(t=>e.jsx("div",{className:`database-sidebar__dropdown-item ${t===c?"database-sidebar__dropdown-item--active":""}`,onMouseDown:o=>{o.preventDefault(),S(t),w(!1),n("")},children:t},t))})]})]}),j.length>0&&e.jsxs("div",{className:"database-sidebar__section database-sidebar__section--tables",children:[e.jsx("div",{className:"database-sidebar__section-title",children:d.trim()?m("terminal:database.tablesCount",{count:b.length})+` / ${j.length}`:m("terminal:database.tablesCount",{count:j.length})}),e.jsxs("div",{className:"database-sidebar__table-filter",children:[e.jsx("input",{ref:O,className:"database-sidebar__table-filter-input",type:"text",value:d,placeholder:m("terminal:database.filterTables"),onChange:t=>g(t.target.value),onKeyDown:t=>{var o;t.key==="Escape"&&(d?g(""):(o=O.current)==null||o.blur(),t.stopPropagation())}}),d&&e.jsx("button",{className:"database-sidebar__table-filter-clear",onClick:()=>{var t;g(""),(t=O.current)==null||t.focus()},title:"Clear filter",children:"×"})]}),e.jsxs("div",{className:"database-sidebar__tables",children:[d.trim()&&b.length===0&&e.jsx("div",{className:"database-sidebar__tables-empty",children:m("terminal:database.noTablesMatch")}),b.map(t=>{const o=I.has(t.name),T=o?z(t.name):null;return e.jsxs("div",{className:"database-sidebar__table",children:[e.jsxs("div",{className:"database-sidebar__table-header",children:[e.jsx("button",{className:"database-sidebar__table-expand",onClick:()=>_(t.name),title:o?"Collapse table schema":"Expand table schema",children:e.jsx(H,{name:o?"caret-down":"caret-right",size:10})}),e.jsx("span",{className:"database-sidebar__table-icon",children:e.jsx(H,{name:t.type==="view"?"eye":"clipboard",size:12})}),e.jsx("span",{className:`database-sidebar__table-name ${U===t.name?"database-sidebar__table-name--selected":""}`,onClick:()=>F(t.name),onDoubleClick:()=>{F(t.name),P(t.name)},children:t.name}),e.jsx("button",{className:"database-sidebar__table-insert",onClick:v=>{v.stopPropagation(),L(t.name)},title:m("terminal:database.insertTableName"),children:"+"})]}),o&&T&&e.jsx("div",{className:"database-sidebar__table-columns",children:T.columns.map(v=>e.jsxs("div",{className:"database-sidebar__column",onClick:()=>L(v.name),title:`${v.type}${v.nullable?" NULL":" NOT NULL"}${v.primaryKey?" PK":""}`,children:[e.jsx("span",{className:"database-sidebar__column-icon",children:v.primaryKey?e.jsx(H,{name:"key",size:11}):null}),e.jsx("span",{className:"database-sidebar__column-name",children:v.name}),e.jsx("span",{className:"database-sidebar__column-type",children:v.type})]},v.name))})]},t.name)})]})]})]})},je=({buildingId:a,history:x,onLoadQuery:l})=>{const{t:c}=J(["terminal","common"]),[y,f]=r.useState(""),[Q,S]=r.useState(!1),[L,P]=r.useState(!1),m=r.useMemo(()=>{let n=x;if(Q&&(n=n.filter(d=>d.favorite)),y.trim()){const d=y.toLowerCase();n=n.filter(g=>g.query.toLowerCase().includes(d)||g.database.toLowerCase().includes(d))}return n},[x,Q,y]),q=n=>{const d=new Date(n),$=new Date().getTime()-d.getTime();return $<1440*60*1e3?d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):$<10080*60*1e3?d.toLocaleDateString([],{weekday:"short"})+" "+d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):d.toLocaleDateString([],{month:"short",day:"numeric"})},I=r.useCallback((n,d)=>{d.stopPropagation(),h.toggleQueryFavorite(a,n)},[a]),R=r.useCallback((n,d)=>{d.stopPropagation(),h.deleteQueryFromHistory(a,n)},[a]),k=r.useCallback(()=>{P(!0)},[]);return x.length===0?e.jsxs("div",{className:"query-history query-history--empty",children:[e.jsx("p",{children:c("terminal:database.noHistory")}),e.jsx("p",{children:c("terminal:database.queriesAppearHere")})]}):e.jsxs("div",{className:"query-history",children:[e.jsxs("div",{className:"query-history__toolbar",children:[e.jsx("input",{type:"text",className:"query-history__search",placeholder:c("terminal:database.searchQueries"),value:y,onChange:n=>f(n.target.value)}),e.jsxs("label",{className:"query-history__filter",children:[e.jsx("input",{type:"checkbox",checked:Q,onChange:n=>S(n.target.checked)}),c("terminal:database.favoritesOnly")]}),e.jsx("button",{className:"query-history__clear",onClick:k,title:c("terminal:database.clearAll"),children:c("terminal:database.clearAll")})]}),e.jsxs("div",{className:"query-history__list",children:[m.map(n=>e.jsxs("div",{className:`query-history__item ${n.status==="error"?"query-history__item--error":""}`,onClick:()=>l(n.query),children:[e.jsxs("div",{className:"query-history__item-header",children:[e.jsx("span",{className:`query-history__status ${n.status==="success"?"query-history__status--success":"query-history__status--error"}`,children:e.jsx(H,{name:n.status==="success"?"check":"cross",size:12})}),e.jsx("span",{className:"query-history__database",children:n.database}),e.jsx("span",{className:"query-history__date",children:q(n.executedAt)}),e.jsxs("span",{className:"query-history__duration",children:[n.duration,"ms"]}),n.rowCount!==void 0&&e.jsx("span",{className:"query-history__row-count",children:c("terminal:database.rowCount",{count:n.rowCount})})]}),e.jsx("div",{className:"query-history__query",children:e.jsx("code",{children:n.query.length>200?n.query.substring(0,200)+"...":n.query})}),n.error&&e.jsx("div",{className:"query-history__error",children:n.error}),e.jsxs("div",{className:"query-history__actions",children:[e.jsx("button",{className:`query-history__favorite ${n.favorite?"query-history__favorite--active":""}`,onClick:d=>I(n.id,d),title:n.favorite?c("terminal:database.removeFromFavorites"):c("terminal:database.addToFavorites"),children:e.jsx(H,{name:"star",size:12,weight:n.favorite?"fill":"regular",color:n.favorite?"#facc15":void 0})}),e.jsx("button",{className:"query-history__delete",onClick:d=>R(n.id,d),title:c("terminal:database.deleteFromHistory"),children:e.jsx(H,{name:"trash",size:12})})]})]},n.id)),m.length===0&&e.jsx("div",{className:"query-history__no-results",children:c("terminal:database.noQueriesMatch")})]}),e.jsx(oe,{isOpen:L,title:c("terminal:database.clearAll"),message:c("terminal:database.confirmClearHistory"),confirmLabel:c("terminal:database.clearAll"),cancelLabel:c("common:buttons.cancel"),variant:"danger",onConfirm:()=>h.clearQueryHistory(a),onClose:()=>P(!1)})]})},ye=({tabs:a,activeTabId:x,onTabClick:l,onTabClose:c})=>{const{t:y}=J(["terminal"]);return e.jsx("div",{className:"database-tabs",children:a.map(f=>e.jsxs("div",{className:`database-tabs__tab ${x===f.id?"database-tabs__tab--active":""}`,children:[e.jsxs("button",{className:"database-tabs__tab-label",onClick:()=>l(f),title:`${f.connectionName} / ${f.database}`,children:[f.database,e.jsx("span",{className:"database-tabs__tab-connection",children:f.connectionName})]}),e.jsx("button",{className:"database-tabs__tab-close",onClick:()=>c(f.id),title:y("terminal:database.closeTab"),"aria-label":`Close ${f.database} tab`,children:"×"})]},f.id))})},ee=a=>`db-panel-${a}`;function Ne(a){try{const x=localStorage.getItem(ee(a));return x?JSON.parse(x):{}}catch{return{}}}function ve(a,x){try{localStorage.setItem(ee(a),JSON.stringify(x))}catch{}}const ge=({building:a,onClose:x})=>{var B,W,Y,X;const{t:l}=J(["terminal","common"]),c=Z(a.id),y=me(a.id),f=be(a.id),Q=ue(a.id),S=r.useRef(Ne(a.id)),L=r.useRef(null),P=r.useRef(0),m=((B=a.database)==null?void 0:B.connections)??[],q=(s,i)=>`${s}:${i}`,I=s=>s?(S.current.queries??{})[s]??"":S.current.generalQuery??"",[R,k]=r.useState("results"),[n,d]=r.useState(0),[g,$]=r.useState(!1),[w,U]=r.useState(!1),[F,K]=r.useState(()=>(S.current.openTabs??[]).map(i=>{var u;return{id:`${i.connectionId}:${i.database}`,connectionId:i.connectionId,connectionName:((u=m.find(A=>A.id===i.connectionId))==null?void 0:u.name)??i.connectionId,database:i.database}})),[C,O]=r.useState(S.current.activeTabId??null),[N,G]=r.useState(()=>{const s=S.current.queries??{};return S.current.generalQuery,s}),[j,p]=r.useState(I(C)),D=r.useCallback(s=>{p(i=>{const u=typeof s=="function"?s(i):s;return G(A=>{const E={...A};return C&&(E[C]=u),E}),u})},[C]),b=c.activeConnectionId??S.current.connectionId??((W=a.database)==null?void 0:W.activeConnectionId)??((Y=m[0])==null?void 0:Y.id),_=c.activeDatabase??S.current.database??((X=a.database)==null?void 0:X.activeDatabase),z=m.find(s=>s.id===b),t=b&&_?`${b}:${_}`:"",o=t?c.tables.get(t)??[]:[],T=r.useMemo(()=>{const s=new Map;return!b||!_||o.forEach(i=>{const u=c.tableSchemas.get(`${b}:${_}:${i.name}`);u&&s.set(i.name,{columns:u.columns})}),s},[b,_,o,c.tableSchemas]),v=r.useCallback((s,i)=>{var E;const u=q(s,i),A=((E=m.find(M=>M.id===s))==null?void 0:E.name)??s;K(M=>{if(M.some(ie=>ie.id===u))return M;const ce={id:u,connectionId:s,connectionName:A,database:i};return[...M,ce]}),O(u),p(N[u]??""),h.setActiveConnection(a.id,s),h.setActiveDatabase(a.id,i)},[a.id,m,N]),ae=r.useCallback(s=>{K(i=>i.filter(u=>u.id!==s)),C===s&&K(i=>{if(i.length>0){const u=i[0];O(u.id),p(N[u.id]??""),h.setActiveConnection(a.id,u.connectionId),h.setActiveDatabase(a.id,u.database)}else O(null),p("");return i})},[C,a.id,N]),se=r.useCallback(s=>{O(s.id),p(N[s.id]??""),h.setActiveConnection(a.id,s.connectionId),h.setActiveDatabase(a.id,s.database)},[a.id,N]);r.useEffect(()=>{if(!w&&m.length>0){const s=S.current;s.connectionId&&m.some(i=>i.id===s.connectionId)&&(h.setActiveConnection(a.id,s.connectionId),h.listDatabases(a.id,s.connectionId),s.database&&(h.setActiveDatabase(a.id,s.database),h.listTables(a.id,s.connectionId,s.database))),U(!0)}},[a.id,m,w]),r.useEffect(()=>{h.requestQueryHistory(a.id)},[a.id]),r.useEffect(()=>{const s=i=>{i.key==="Escape"&&(i.preventDefault(),i.stopPropagation(),x())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[x]),r.useEffect(()=>{w&&b&&ve(a.id,{connectionId:b,database:_,lastQuery:j,queries:N,generalQuery:"",openTabs:F.map(s=>({connectionId:s.connectionId,database:s.database})),activeTabId:C??void 0})},[a.id,b,_,j,w,F,C,N]);const te=r.useCallback(s=>{var i;if(!(!b||!_||!j.trim()||Q))if(s==="cursor"){const u=(i=L.current)==null?void 0:i.querySelector(".query-editor__textarea"),A=(u==null?void 0:u.selectionStart)??P.current,E=he(j,A);E&&h.executeQuery(a.id,b,_,E)}else{const u=_e(j);if(u.length<=1)h.executeQuery(a.id,b,_,j.trim());else{const A=b,E=_;(async()=>{for(const M of u)await h.executeQueryAndWait(a.id,A,E,M.sql)})()}}},[a.id,b,_,j,Q]),ne=r.useCallback(s=>{D(s),k("results")},[]),re=r.useCallback(s=>{h.setActiveConnection(a.id,s),h.listDatabases(a.id,s)},[a.id]),le=r.useCallback(s=>{b&&(v(b,s),h.listTables(a.id,b,s))},[a.id,b,v]),V=y[n];return m.length===0?e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:e.jsx(H,{name:"database",size:16})}),e.jsx("span",{className:"database-panel__name",children:a.name})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsx("div",{className:"database-panel__body",children:e.jsxs("div",{className:"database-panel__no-connections",children:[e.jsx("div",{className:"database-panel__no-connections-icon",children:e.jsx(H,{name:"plug",size:32})}),e.jsx("h3",{children:l("terminal:database.noConnections")}),e.jsx("p",{children:l("terminal:database.noConnectionsDesc")}),e.jsx("p",{children:l("terminal:database.toGetStarted")}),e.jsxs("ol",{children:[e.jsx("li",{children:l("terminal:database.step1Close")}),e.jsx("li",{children:l("terminal:database.step2Settings")}),e.jsx("li",{children:l("terminal:database.step3AddConnection")}),e.jsx("li",{children:l("terminal:database.step4Reopen")})]})]})})]}):e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:(z==null?void 0:z.engine)==="mysql"?"🐬":"🐘"}),e.jsx("span",{className:"database-panel__name",children:a.name}),z&&e.jsxs("span",{className:"database-panel__connection-info",children:[z.name," / ",_||l("terminal:database.noDatabaseSelected")]})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsxs("div",{className:"database-panel__body",children:[e.jsx(fe,{building:a,connections:m,activeConnectionId:b,activeDatabase:_,collapsed:g,onToggleCollapse:()=>$(!g),onConnectionChange:re,onDatabaseChange:le,onInsertTable:s=>D(i=>i+` ${s}`),onSelectTableQuery:s=>{const i=`SELECT * FROM ${s}`;D(i),b&&_&&h.executeQuery(a.id,b,_,i)}}),e.jsxs("div",{className:"database-panel__main",children:[F.length>0&&e.jsx(ye,{tabs:F,activeTabId:C,onTabClick:se,onTabClose:ae}),e.jsx(pe,{query:j,onChange:D,onExecute:te,isExecuting:Q,disabled:!b||!_,tables:o,tableSchemas:T,onRequestTableSchema:s=>{b&&_&&h.getTableSchema(a.id,b,_,s)}}),e.jsxs("div",{className:"database-panel__tabs",children:[e.jsxs("button",{className:`database-panel__tab ${R==="results"?"database-panel__tab--active":""}`,onClick:()=>k("results"),children:[l("terminal:database.results"),y.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:y.length})]}),e.jsxs("button",{className:`database-panel__tab ${R==="history"?"database-panel__tab--active":""}`,onClick:()=>k("history"),children:[l("terminal:database.history"),f.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:f.length})]}),R==="results"&&y.length>1&&e.jsxs("div",{className:"database-panel__result-nav",children:[e.jsxs("button",{disabled:n>=y.length-1,onClick:()=>d(s=>s+1),children:["← ",l("terminal:database.older")]}),e.jsxs("span",{children:[n+1," / ",y.length]}),e.jsxs("button",{disabled:n<=0,onClick:()=>d(s=>s-1),children:[l("terminal:database.newer")," →"]})]})]}),e.jsx("div",{className:"database-panel__tab-content",children:R==="results"?V?e.jsx(xe,{result:V,buildingId:a.id,building:a}):e.jsxs("div",{className:"database-panel__empty",children:[e.jsx("p",{children:l("terminal:database.noResultsYet")}),e.jsx("p",{children:l("terminal:database.selectDbAndRun")})]}):e.jsx(je,{buildingId:a.id,history:f,onLoadQuery:ne})})]})]})]})};export{ge as DatabasePanel,fe as DatabaseSidebar,ye as DatabaseTabs,pe as QueryEditor,je as QueryHistoryPanel,xe as ResultsTable};