tide-commander 1.111.2 → 1.113.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/assets/{BossLogsModal-DLTh_jKZ.js → BossLogsModal-Bc0DqA9X.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-DzivoRl1.js → BossSpawnModal-D-HI5-Rm.js} +1 -1
  3. package/dist/assets/{ControlsModal-B8j6My0t.js → ControlsModal-CTIbjWJQ.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-BNwx7lVp.js → DockerLogsModal-CZrAeIrY.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-CBoOoGL8.js → EmbeddedEditor-DeNPLdlN.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-BACIjX54.js → GmailOAuthSetup-CVE2MUNk.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-BuASGyWh.js → GoogleOAuthSetup-DPVaJm-J.js} +1 -1
  8. package/dist/assets/{IframeModal-ckpeQpQB.js → IframeModal-D0Njx7nV.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-Dh7UOnTC.js → IntegrationsPanel-N8GC9dFw.js} +2 -2
  10. package/dist/assets/{LogViewerModal-Cj7Hv-mD.js → LogViewerModal-DXfAOI0h.js} +1 -1
  11. package/dist/assets/{MonitoringModal-Bx4vcjBr.js → MonitoringModal-uCFkCztW.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-RBIjfi4J.js → PM2LogsModal-DGW_92OG.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-BBYlYIso.js → RestoreArchivedAreaModal-DWyz3iM2.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-CYB1Y5Wa.js → Scene2DCanvas-CNpWfkXW.js} +1 -1
  15. package/dist/assets/{SceneManager-6vk047Kd.js → SceneManager-EwY3yHEm.js} +1 -1
  16. package/dist/assets/{SkillsPanel-CRRypqdy.js → SkillsPanel-YTLlXzWr.js} +1 -1
  17. package/dist/assets/{SlackMultiInstanceSetup-DisMBGxX.js → SlackMultiInstanceSetup-bAWpygC_.js} +1 -1
  18. package/dist/assets/{SpawnModal-qiu5nT-F.js → SpawnModal-BWuxUbwF.js} +1 -1
  19. package/dist/assets/StatisticsModal-fsomOWqv.js +1 -0
  20. package/dist/assets/{SubordinateAssignmentModal-AUCAiGkE.js → SubordinateAssignmentModal-Cyhy71yX.js} +1 -1
  21. package/dist/assets/{TriggerManagerPanel-56SuYzNh.js → TriggerManagerPanel-BCDVqT8Q.js} +1 -1
  22. package/dist/assets/{WorkflowEditorPanel-H0IGkyMd.js → WorkflowEditorPanel-Btq2XPt5.js} +1 -1
  23. package/dist/assets/{index-94AqwQn0.js → index-BEm8Kg82.js} +1 -1
  24. package/dist/assets/{index-9NugNkE4.js → index-BPAwPCsE.js} +1 -1
  25. package/dist/assets/{index-DY395tVJ.js → index-C1Y50w20.js} +2 -2
  26. package/dist/assets/{index--3sQ1gHE.js → index-CMa6Bc5_.js} +3 -3
  27. package/dist/assets/{index-C-kx99MP.js → index-Cn-EYfAP.js} +1 -1
  28. package/dist/assets/{index-DFWA70Lq.js → index-DvzFVxNn.js} +1 -1
  29. package/dist/assets/{index-DZP3fZ3b.js → index-Glbq4ytE.js} +1 -1
  30. package/dist/assets/{index-pRI5GcXd.js → index-aMq5H0fp.js} +1 -1
  31. package/dist/assets/{index-Dv0tQnLX.js → index-qAdi3D_H.js} +1 -1
  32. package/dist/assets/main-BEfBoz8e.css +1 -0
  33. package/dist/assets/main-vfMoYhg1.js +214 -0
  34. package/dist/assets/{web-CccJFC0m.js → web-CMiQoHZs.js} +1 -1
  35. package/dist/assets/{web-CdhZGenV.js → web-DN5Nx28H.js} +1 -1
  36. package/dist/assets/{web-RZLwjKCT.js → web-ZMOcyRHy.js} +1 -1
  37. package/dist/index.html +2 -2
  38. package/dist/locales/de/terminal.json +1 -0
  39. package/dist/locales/en/terminal.json +1 -0
  40. package/dist/locales/es/terminal.json +1 -0
  41. package/dist/locales/fr/terminal.json +1 -0
  42. package/dist/locales/hi/terminal.json +1 -0
  43. package/dist/locales/it/terminal.json +1 -0
  44. package/dist/locales/ja/terminal.json +1 -0
  45. package/dist/locales/pt/terminal.json +1 -0
  46. package/dist/locales/ru/terminal.json +1 -0
  47. package/dist/locales/zh-CN/terminal.json +1 -0
  48. package/dist/src/packages/server/claude/backend.js +2 -0
  49. package/dist/src/packages/server/data/builtin-skills/boss-instructions.js +1 -1
  50. package/dist/src/packages/server/routes/agents.js +17 -1
  51. package/dist/src/packages/server/services/claude-usage-service.js +164 -9
  52. package/dist/src/packages/server/services/llm-matcher-service.js +5 -0
  53. package/dist/src/packages/shared/agent-types.js +2 -0
  54. package/package.json +1 -1
  55. package/dist/assets/StatisticsModal-Bzk7qqOd.js +0 -1
  56. package/dist/assets/main-BUSv52j9.css +0 -1
  57. package/dist/assets/main-Bon1sZAi.js +0 -214
@@ -1 +1 @@
1
- import{j as d,I as Z,ak as st,U as nt,W as rt,bZ as it,r as y,s as ne,b_ as Re,_ as ct,ad as ge,u as Fe}from"./main-Bon1sZAi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function se(t){return Array.isArray?Array.isArray(t):We(t)==="[object Array]"}function ot(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function at(t){return t==null?"":ot(t)}function ee(t){return typeof t=="string"}function ze(t){return typeof t=="number"}function ut(t){return t===!0||t===!1||lt(t)&&We(t)=="[object Boolean]"}function Qe(t){return typeof t=="object"}function lt(t){return Qe(t)&&t!==null}function Q(t){return t!=null}function pe(t){return!t.trim().length}function We(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const ht="Incorrect 'index' type",dt=t=>`Invalid value for key ${t}`,ft=t=>`Pattern length exceeds max of ${t}.`,mt=t=>`Missing ${t} property in key`,gt=t=>`Property 'weight' in key '${t}' must be a positive integer`,je=Object.prototype.hasOwnProperty;class pt{constructor(e){this._keys=[],this._keyMap={};let s=0;e.forEach(n=>{let r=Ve(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 Ve(t){let e=null,s=null,n=null,r=1,c=null;if(ee(t)||se(t))n=t,e=$e(t),s=Ae(t);else{if(!je.call(t,"name"))throw new Error(mt("name"));const o=t.name;if(n=o,je.call(t,"weight")&&(r=t.weight,r<=0))throw new Error(gt(o));e=$e(o),s=Ae(o),c=t.getFn}return{path:e,id:s,weight:r,src:n,getFn:c}}function $e(t){return se(t)?t:t.split(".")}function Ae(t){return se(t)?t.join("."):t}function At(t,e){let s=[],n=!1;const r=(c,o,a)=>{if(Q(c))if(!o[a])s.push(c);else{let u=o[a];const l=c[u];if(!Q(l))return;if(a===o.length-1&&(ee(l)||ze(l)||ut(l)))s.push(at(l));else if(se(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,ee(e)?e.split("."):e,0),n?s:s[0]}const yt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Et={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},xt={location:0,threshold:.6,distance:100},Ct={useExtendedSearch:!1,getFn:At,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var g={...Et,...yt,...xt,...Ct};const wt=/[^ ]+/g;function Ft(t=1,e=3){const s=new Map,n=Math.pow(10,e);return{get(r){const c=r.match(wt).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 Me{constructor({getFn:e=g.getFn,fieldNormWeight:s=g.fieldNormWeight}={}){this.norm=Ft(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,ee(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();ee(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(!Q(e)||pe(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(Q(o)){if(se(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(Q(h))if(ee(h)&&!pe(h)){let f={v:h,i:l,n:this.norm.get(h)};a.push(f)}else se(h)&&h.forEach((f,m)=>{u.push({nestedArrIndex:m,value:f})})}n.$[c]=a}else if(ee(o)&&!pe(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 Ye(t,e,{getFn:s=g.getFn,fieldNormWeight:n=g.fieldNormWeight}={}){const r=new Me({getFn:s,fieldNormWeight:n});return r.setKeys(t.map(Ve)),r.setSources(e),r.create(),r}function Mt(t,{getFn:e=g.getFn,fieldNormWeight:s=g.fieldNormWeight}={}){const{keys:n,records:r}=t,c=new Me({getFn:e,fieldNormWeight:s});return c.setKeys(n),c.setIndexRecords(r),c}function he(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:r=g.distance,ignoreLocation:c=g.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 It(t=[],e=g.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 ce=32;function St(t,e,s,{location:n=g.location,distance:r=g.distance,threshold:c=g.threshold,findAllMatches:o=g.findAllMatches,minMatchCharLength:a=g.minMatchCharLength,includeMatches:u=g.includeMatches,ignoreLocation:l=g.ignoreLocation}={}){if(e.length>ce)throw new Error(ft(ce));const h=e.length,f=t.length,m=Math.max(0,Math.min(n,f));let A=c,E=m;const k=a>1||u,v=k?Array(f):[];let b;for(;(b=t.indexOf(e,E))>-1;){let x=he(e,{currentLocation:b,expectedLocation:m,distance:r,ignoreLocation:l});if(A=Math.min(x,A),E=b+h,k){let C=0;for(;C<h;)v[b+C]=1,C+=1}}E=-1;let L=[],Y=1,W=h+f;const oe=1<<h-1;for(let x=0;x<h;x+=1){let C=0,B=W;for(;C<B;)he(e,{errors:x,currentLocation:m+B,expectedLocation:m,distance:r,ignoreLocation:l})<=A?C=B:W=B,B=Math.floor((W-C)/2+C);W=B;let O=Math.max(1,m-B+1),K=o?f:Math.min(m+B,f)+h,V=Array(K+2);V[K+1]=(1<<x)-1;for(let R=K;R>=O;R-=1){let te=R-1,ie=s[t.charAt(te)];if(k&&(v[te]=+!!ie),V[R]=(V[R+1]<<1|1)&ie,x&&(V[R]|=(L[R+1]|L[R])<<1|1|L[R+1]),V[R]&oe&&(Y=he(e,{errors:x,currentLocation:te,expectedLocation:m,distance:r,ignoreLocation:l}),Y<=A)){if(A=Y,E=te,E<=m)break;O=Math.max(1,2*m-E)}}if(he(e,{errors:x+1,currentLocation:m,expectedLocation:m,distance:r,ignoreLocation:l})>A)break;L=V}const H={isMatch:E>=0,score:Math.max(.001,Y)};if(k){const x=It(v,a);x.length?u&&(H.indices=x):H.isMatch=!1}return H}function Bt(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 fe=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 Ge{constructor(e,{location:s=g.location,threshold:n=g.threshold,distance:r=g.distance,includeMatches:c=g.includeMatches,findAllMatches:o=g.findAllMatches,minMatchCharLength:a=g.minMatchCharLength,isCaseSensitive:u=g.isCaseSensitive,ignoreDiacritics:l=g.ignoreDiacritics,ignoreLocation:h=g.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?fe(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const f=(A,E)=>{this.chunks.push({pattern:A,alphabet:Bt(A),startIndex:E})},m=this.pattern.length;if(m>ce){let A=0;const E=m%ce,k=m-E;for(;A<k;)f(this.pattern.substr(A,ce),A),A+=ce;if(E){const v=m-ce;f(this.pattern.substr(v),v)}}else f(this.pattern,0)}searchIn(e){const{isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=s?e:e.toLowerCase(),e=n?fe(e):e,this.pattern===e){let k={isMatch:!0,score:0};return r&&(k.indices=[[0,e.length-1]]),k}const{location:c,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let f=[],m=0,A=!1;this.chunks.forEach(({pattern:k,alphabet:v,startIndex:b})=>{const{isMatch:L,score:Y,indices:W}=St(e,k,v,{location:c+b,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:r,ignoreLocation:h});L&&(A=!0),m+=Y,L&&W&&(f=[...f,...W])});let E={isMatch:A,score:A?m/this.chunks.length:1};return A&&r&&(E.indices=f),E}}class re{constructor(e){this.pattern=e}static isMultiMatch(e){return Le(e,this.multiRegex)}static isSingleMatch(e){return Le(e,this.singleRegex)}search(){}}function Le(t,e){const s=t.match(e);return s?s[1]:null}class Dt extends re{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 kt extends re{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 Nt extends re{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 _t extends re{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 bt extends re{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 vt extends re{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 Ue extends re{constructor(e,{location:s=g.location,threshold:n=g.threshold,distance:r=g.distance,includeMatches:c=g.includeMatches,findAllMatches:o=g.findAllMatches,minMatchCharLength:a=g.minMatchCharLength,isCaseSensitive:u=g.isCaseSensitive,ignoreDiacritics:l=g.ignoreDiacritics,ignoreLocation:h=g.ignoreLocation}={}){super(e),this._bitapSearch=new Ge(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 He extends re{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 ye=[Dt,He,Nt,_t,vt,bt,kt,Ue],Te=ye.length,Rt=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,jt="|";function $t(t,e={}){return t.split(jt).map(s=>{let n=s.trim().split(Rt).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<Te;){const h=ye[l];let f=h.isMultiMatch(a);f&&(r.push(new h(f,e)),u=!0)}if(!u)for(l=-1;++l<Te;){const h=ye[l];let f=h.isSingleMatch(a);if(f){r.push(new h(f,e));break}}}return r})}const Lt=new Set([Ue.type,He.type]);class Tt{constructor(e,{isCaseSensitive:s=g.isCaseSensitive,ignoreDiacritics:n=g.ignoreDiacritics,includeMatches:r=g.includeMatches,minMatchCharLength:c=g.minMatchCharLength,ignoreLocation:o=g.ignoreLocation,findAllMatches:a=g.findAllMatches,location:u=g.location,threshold:l=g.threshold,distance:h=g.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?fe(e):e,this.pattern=e,this.query=$t(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?fe(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,A=f.length;m<A;m+=1){const E=f[m],{isMatch:k,indices:v,score:b}=E.search(e);if(k){if(o+=1,u+=b,n){const L=E.constructor.type;Lt.has(L)?a=[...a,...v]:a.push(v)}}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 Ee=[];function Pt(...t){Ee.push(...t)}function xe(t,e){for(let s=0,n=Ee.length;s<n;s+=1){let r=Ee[s];if(r.condition(t,e))return new r(t,e)}return new Ge(t,e)}const me={AND:"$and",OR:"$or"},Ce={PATH:"$path",PATTERN:"$val"},we=t=>!!(t[me.AND]||t[me.OR]),Ot=t=>!!t[Ce.PATH],Kt=t=>!se(t)&&Qe(t)&&!we(t),Pe=t=>({[me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function Je(t,e,{auto:s=!0}={}){const n=r=>{let c=Object.keys(r);const o=Ot(r);if(!o&&c.length>1&&!we(r))return n(Pe(r));if(Kt(r)){const u=o?r[Ce.PATH]:c[0],l=o?r[Ce.PATTERN]:r[u];if(!ee(l))throw new Error(dt(u));const h={keyId:Ae(u),pattern:l};return s&&(h.searcher=xe(l,e)),h}let a={children:[],operator:c[0]};return c.forEach(u=>{const l=r[u];se(l)&&l.forEach(h=>{a.children.push(n(h))})}),a};return we(t)||(t=Pe(t)),n(t)}function zt(t,{ignoreFieldNorm:e=g.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 Qt(t,e){const s=t.matches;e.matches=[],Q(s)&&s.forEach(n=>{if(!Q(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 Wt(t,e){e.score=t.score}function Vt(t,e,{includeMatches:s=g.includeMatches,includeScore:n=g.includeScore}={}){const r=[];return s&&r.push(Qt),n&&r.push(Wt),t.map(c=>{const{idx:o}=c,a={item:e[o],refIndex:o};return r.length&&r.forEach(u=>{u(c,a)}),a})}class q{constructor(e,s={},n){this.options={...g,...s},this.options.useExtendedSearch,this._keyStore=new pt(this.options.keys),this.setCollection(e,n)}setCollection(e,s){if(this._docs=e,s&&!(s instanceof Me))throw new Error(ht);this._myIndex=s||Ye(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){Q(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=ee(e)?ee(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return zt(u,{ignoreFieldNorm:a}),c&&u.sort(o),ze(s)&&s>-1&&(u=u.slice(0,s)),Vt(u,this._docs,{includeMatches:n,includeScore:r})}_searchStringList(e){const s=xe(e,this.options),{records:n}=this._myIndex,r=[];return n.forEach(({v:c,i:o,n:a})=>{if(!Q(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=Je(e,this.options),n=(a,u,l)=>{if(!a.children){const{keyId:f,searcher:m}=a,A=this._findMatches({key:this._keyStore.get(f),value:this._myIndex.getValueForItemAtKeyId(u,f),searcher:m});return A&&A.length?[{idx:l,item:u,matches:A}]:[]}const h=[];for(let f=0,m=a.children.length;f<m;f+=1){const A=a.children[f],E=n(A,u,l);if(E.length)h.push(...E);else if(a.operator===me.AND)return[]}return h},r=this._myIndex.records,c={},o=[];return r.forEach(({$:a,i:u})=>{if(Q(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=xe(e,this.options),{keys:n,records:r}=this._myIndex,c=[];return r.forEach(({$:o,i:a})=>{if(!Q(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(!Q(s))return[];let r=[];if(se(s))s.forEach(({v:c,i:o,n:a})=>{if(!Q(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}}q.version="7.1.0";q.createIndex=Ye;q.parseIndex=Mt;q.config=g;q.parseQuery=Je;Pt(Tt);const Oe={".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 Yt(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 Gt(t,e=16){var r;const s="."+(((r=t.split(".").pop())==null?void 0:r.toLowerCase())??""),n=Oe[s]||Oe.default;return d.jsx(Z,{name:n,size:e})}function cs(t,e=16){return d.jsx(Z,{name:Yt(t),size:e,weight:"fill"})}function Xe(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 os(t){const s=Date.now()-t;return Xe(s)}const Ze="tide-commander:spotlight-recent-agents",Ut=15;function qe(){try{const t=localStorage.getItem(Ze);if(!t)return[];const e=JSON.parse(t);return Array.isArray(e)?e.filter(s=>typeof s=="string"):[]}catch{return[]}}function Ht(t){try{const e=[t,...qe().filter(s=>s!==t)].slice(0,Ut);localStorage.setItem(Ze,JSON.stringify(e))}catch{}}function de(t,e){if(!t)return Number.POSITIVE_INFINITY;const s=e.indexOf(t);return s===-1?Number.POSITIVE_INFINITY:s}function Ke(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 Jt=["command","agent","building","area","modified-file"];function Xt({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=st(),f=nt(),m=rt(),A=it(),E=y.useRef(e);E.current=e;const k=y.useRef(s);k.current=s;const v=y.useRef(n);v.current=n;const b=y.useRef(r);b.current=r;const L=y.useRef(c);L.current=c;const Y=y.useRef(o);Y.current=o;const W=y.useRef(a);W.current=a;const oe=y.useRef(u);oe.current=u;const H=y.useRef(l);H.current=l;const[x,C]=y.useState(""),[B,O]=y.useState(0);y.useEffect(()=>{t&&(C(""),O(0))},[t]);const K=ne.getShortcuts(),V=y.useMemo(()=>t?qe():[],[t]),ae=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?Re(i):"Alt+N",icon:d.jsx(Z,{name:"plus",size:16}),action:()=>{E.current(),k.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:M?Re(M):"Ctrl+K",icon:d.jsx(Z,{name:"dashboard",size:16}),action:()=>{E.current(),v.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:d.jsx(Z,{name:"gear",size:16}),action:()=>{E.current(),b.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:d.jsx(Z,{name:"chart-line",size:16}),action:()=>{var I;E.current(),(I=H.current)==null||I.call(H)}}]},[t,K]),R=y.useMemo(()=>t?Array.from(h.values()).map(i=>{const M=(A||[]).filter(T=>T.agentId===i.id).map(T=>T.filePath),I=[...new Set(M)],S=I.map(T=>T.split("/").pop()||T),N=[];i.lastAssignedTask&&N.push(i.lastAssignedTask);const j=`${i.class} • ${i.status} • ${i.cwd}`;let _=`${i.name} ${j}`;S.length>0&&(_+=` ${S.join(" ")} ${I.join(" ")}`),N.length>0&&(_+=` ${N.join(" ")}`);const z=Date.now()-i.lastActivity;let J;return i.lastAssignedTask&&(i.lastAssignedTask.length>150?J=i.lastAssignedTask.slice(0,150)+"...":J=i.lastAssignedTask),{id:`agent-${i.id}`,type:"agent",title:i.name,subtitle:j,lastUserInput:J,timeAway:z,icon:d.jsx(ct,{agent:i,size:20}),_searchText:_,_modifiedFiles:I,_userQueries:N,_agentId:i.id,action:()=>{E.current(),Ht(i.id),ne.selectAgent(i.id),ne.getState().viewMode!=="flat"&&ne.requestTerminalExpand()}}}):[],[t,h,A]),te=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(Z,{name:"map",size:16}),action:()=>{E.current(),ne.selectArea(i.id)}}}):[],[t,f]),ie=y.useMemo(()=>t?Array.from(m.values()).filter(i=>i.type==="server"||i.type==="boss"||i.type==="database").map(i=>{var _,z,J,T;const M=i.status==="running"?"#4ade80":i.status==="stopped"?"#f87171":"#facc15",I=i.type==="boss"?"crown":i.type==="database"?"database":"desktop";let N=`${i.type==="boss"?"Boss":i.type==="database"?"Database":"Server"} • ${i.status}`;if(i.type==="database"&&((z=(_=i.database)==null?void 0:_.connections)!=null&&z.length)){const $=i.database.connections[0];N+=` • ${$.engine} @ ${$.host}`}else i.cwd&&(N+=` • ${i.cwd}`);let j=`${i.name} ${i.type} ${i.status} ${i.cwd||""} ${((J=i.pm2)==null?void 0:J.name)||""}`;if(i.type==="database"&&((T=i.database)!=null&&T.connections))for(const $ of i.database.connections)j+=` ${$.name} ${$.engine} ${$.host} ${$.database||""} mysql postgresql sql`;return{id:`building-${i.id}`,type:"building",title:i.name,subtitle:N,icon:d.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[d.jsx(Z,{name:"status-pending",size:10,weight:"fill",color:M}),d.jsx(Z,{name:I,size:16})]}),_searchText:j,action:()=>{var $;E.current(),i.type==="boss"?W.current(i.id):i.type==="database"?oe.current(i.id):($=i.pm2)!=null&&$.enabled&&Y.current(i.id)}}}):[],[t,m]),Ie=y.useMemo(()=>{if(!t)return[];const i=A||[],M=new Set,I=[];for(const S of i){if(M.has(S.filePath))continue;M.add(S.filePath);const N=S.filePath.split("/").pop()||S.filePath,j=S.action==="created"?"Created":S.action==="modified"?"Modified":S.action==="deleted"?"Deleted":"Read";if(I.push({id:`modified-${S.filePath}-${S.timestamp}`,type:"modified-file",title:N,subtitle:`${j} by ${S.agentName} • ${S.filePath}`,matchedText:S.filePath,icon:S.action==="deleted"?d.jsx(Z,{name:"trash",size:16}):Gt(S.filePath),action:()=>{E.current();const _=Array.from(ne.getState().areas.values());for(const z of _)for(const J of z.directories||[])if(S.filePath.startsWith(J)){ne.setFileViewerPath(S.filePath),L.current(z.id);return}ne.selectAgent(S.agentId)}}),I.length>=50)break}return I},[t,A]),Se=y.useMemo(()=>new q(R,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[R]),Be=y.useMemo(()=>new q(ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[ae]),De=y.useMemo(()=>new q(te,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[te]),ke=y.useMemo(()=>new q(Ie,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ie]),Ne=y.useMemo(()=>new q(ie,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ie]),G=y.useMemo(()=>{if(!x.trim()){const p=[];p.push(...ie);const w=[...R].sort((D,P)=>{const X=de(D._agentId,V),U=de(P._agentId,V);if(X!==U)return X-U;const ue=D.timeAway??0,le=P.timeAway??0;return ue-le});p.push(...w),p.push(...ae.slice(0,2)),p.push(...te.slice(0,2));const F={};return Jt.forEach((D,P)=>{F[D]=P}),p.sort((D,P)=>(F[D.type]??999)-(F[P.type]??999)),p}const i=x.trim().toLowerCase(),M=Se.search(x).slice(0,8),I=Be.search(x).slice(0,3),S=De.search(x).slice(0,2),N=ke.search(x).slice(0,3),j=Ne.search(x).filter(p=>{const w=p.score??1;return`${p.item.title} ${p.item.subtitle||""} ${p.item._searchText||""}`.toLowerCase().includes(i)||w<=.2}).slice(0,4),_={agent:5,building:4,command:3,area:2,"modified-file":1},z=p=>{if(!i)return 1;const w=p.title.toLowerCase();return w===i?6:w.startsWith(i)?5:w.split(/[^a-z0-9]+/i).includes(i)?4:w.includes(i)?3:`${p.subtitle||""} ${p._searchText||""} ${p.matchedText||""}`.toLowerCase().includes(i)?2:1},J=(p,w)=>{const F=(1-Math.min(1,w??1))*4;return z(p)*100+(_[p.type]??0)*5+F},T=new Map,$=(p,w)=>{const F=T.get(p.type),D={item:p,score:J(p,w)};F?F.push(D):T.set(p.type,[D])};for(const p of M){const w={...p.item};if(w._modifiedFiles&&w._modifiedFiles.length>0){const F=w._modifiedFiles.filter(D=>{var U;const P=((U=D.split("/").pop())==null?void 0:U.toLowerCase())||"",X=D.toLowerCase();return P.includes(i)||X.includes(i)});F.length>0&&(w.matchedFiles=F)}if(w._userQueries&&w._userQueries.length>0){const F=w._userQueries.find(D=>D.toLowerCase().includes(i));if(F)if(F.length>200){const P=F.toLowerCase().indexOf(i),X=Math.max(0,P-60),U=Math.min(F.length,P+i.length+100);w.matchedQuery=(X>0?"...":"")+F.slice(X,U)+(U<F.length?"...":"")}else w.matchedQuery=F}$(w,p.score)}for(const p of j)$(p.item,p.score);for(const p of I)$(p.item,p.score);for(const p of S)$(p.item,p.score);for(const p of N)$(p.item,p.score);for(const[p,w]of T)p==="agent"?w.sort((F,D)=>{const P=z(F.item),X=z(D.item);if(X!==P)return X-P;const U=de(F.item._agentId,V),ue=de(D.item._agentId,V);if(U!==ue)return U-ue;const le=F.item.timeAway??Number.POSITIVE_INFINITY,ve=D.item.timeAway??Number.POSITIVE_INFINITY;return le!==ve?le-ve:D.score-F.score}):w.sort((F,D)=>D.score-F.score);const _e=p=>p.reduce((w,F)=>Math.max(w,F.score),-1),be=[];return Array.from(T.values()).sort((p,w)=>_e(w)-_e(p)).forEach(p=>{for(const w of p)be.push(w.item)}),be},[x,Se,Be,De,ke,Ne,ae,R,te,ie,V]);y.useEffect(()=>{B>=G.length&&O(Math.max(0,G.length-1))},[G.length,B]);const et=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();O(M==="p"?I=>I>0?I-1:G.length-1:I=>I<G.length-1?I+1:0);return}switch(i.key){case"Escape":i.preventDefault(),E.current();break;case"ArrowUp":i.preventDefault(),O(M=>M>0?M-1:G.length-1);break;case"ArrowDown":i.preventDefault(),O(M=>M<G.length-1?M+1:0);break;case"Enter":i.preventDefault(),G[B]&&G[B].action();break}},[G,B]),tt=y.useCallback((i,M)=>{if(!M||!i)return i;const I=i.toLowerCase(),S=M.toLowerCase(),N=[];let j=0,_=I.indexOf(S),z=0;for(;_!==-1;)_>j&&N.push(i.slice(j,_)),N.push(ge.createElement("mark",{key:z++,className:"spotlight-highlight"},i.slice(_,_+M.length))),j=_+M.length,_=I.indexOf(S,j);return j<i.length&&N.push(i.slice(j)),N.length>0?ge.createElement(ge.Fragment,null,...N):i},[]);return{query:x,setQuery:C,selectedIndex:B,setSelectedIndex:O,results:G,handleKeyDown:et,highlightMatch:tt}}const Zt=y.forwardRef(function({query:e,onQueryChange:s,onKeyDown:n,onResetSelection:r},c){const{t:o}=Fe(["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":Ke(e.type),children:Ke(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: ",Xe(e.timeAway)]})}),e.lastUserInput&&!e.matchedQuery&&d.jsxs("span",{className:"spotlight-item-last-input",children:['"',r(e.lastUserInput,n),'"']})]})]})}),es=y.forwardRef(function({results:e,selectedIndex:s,query:n,highlightMatch:r,onSelectIndex:c},o){const{t:a}=Fe(["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,A=[];return e.forEach((E,k)=>{E.type!==m&&(m!==null&&A.length>0&&f.push([m,A]),m=E.type,A=[]),A.push({result:E,index:k})}),m!==null&&A.length>0&&f.push([m,A]),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:A,index:E})=>d.jsx(qt,{result:A,isSelected:E===s,query:n,highlightMatch:r,onClick:()=>A.action(),onMouseEnter:()=>{u.current&&c(E)}},A.id))]},f))})}),ts=y.memo(function(){const{t:e}=Fe(["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")]})})]})}),ss=768;function as({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),A=y.useRef(0),{query:E,setQuery:k,selectedIndex:v,setSelectedIndex:b,results:L,handleKeyDown:Y,highlightMatch:W}=Xt({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});A.current=L.length,y.useEffect(()=>{t&&setTimeout(()=>{var x;(x=h.current)==null||x.focus()},50)},[t]),y.useEffect(()=>{if(!t)return;const x=window.visualViewport;if(!x||window.innerWidth>ss)return;const C=()=>{const B=f.current;B&&(B.style.height=`${x.height}px`,B.style.top=`${x.offsetTop}px`)};return C(),x.addEventListener("resize",C),x.addEventListener("scroll",C),()=>{x.removeEventListener("resize",C),x.removeEventListener("scroll",C);const B=f.current;B&&(B.style.height="",B.style.top="")}},[t]),y.useEffect(()=>{if(!t)return;const x=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(),O=A.current;b(B==="p"?K=>K>0?K-1:O-1:K=>K<O-1?K+1:0);return}};return window.addEventListener("keydown",x,{capture:!0}),()=>{window.removeEventListener("keydown",x,{capture:!0})}},[t,e]);const oe=y.useCallback(x=>{x.target===x.currentTarget&&e()},[e]),H=y.useCallback(()=>{b(0)},[b]);return t?d.jsx("div",{ref:f,className:"spotlight-overlay",onClick:oe,children:d.jsxs("div",{className:"spotlight-modal",children:[d.jsx(Zt,{ref:h,query:E,onQueryChange:k,onKeyDown:Y,onResetSelection:H}),d.jsx(es,{ref:m,results:L,selectedIndex:v,query:E,highlightMatch:W,onSelectIndex:b}),d.jsx(ts,{})]})}):null}export{Oe as FILE_ICON_NAMES,as as Spotlight,ts as SpotlightFooter,Zt as SpotlightInput,qt as SpotlightItem,es as SpotlightResults,Xe as formatDuration,os as formatRelativeTime,cs as getAgentIcon,Gt as getFileIconFromPath,Ke as getTypeLabel,Xt as useSpotlightSearch};
1
+ import{j as d,I as Z,ak as st,U as nt,W as rt,bZ as it,r as y,s as ne,b_ as Re,_ as ct,ad as ge,u as Fe}from"./main-vfMoYhg1.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function se(t){return Array.isArray?Array.isArray(t):We(t)==="[object Array]"}function ot(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function at(t){return t==null?"":ot(t)}function ee(t){return typeof t=="string"}function ze(t){return typeof t=="number"}function ut(t){return t===!0||t===!1||lt(t)&&We(t)=="[object Boolean]"}function Qe(t){return typeof t=="object"}function lt(t){return Qe(t)&&t!==null}function Q(t){return t!=null}function pe(t){return!t.trim().length}function We(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const ht="Incorrect 'index' type",dt=t=>`Invalid value for key ${t}`,ft=t=>`Pattern length exceeds max of ${t}.`,mt=t=>`Missing ${t} property in key`,gt=t=>`Property 'weight' in key '${t}' must be a positive integer`,je=Object.prototype.hasOwnProperty;class pt{constructor(e){this._keys=[],this._keyMap={};let s=0;e.forEach(n=>{let r=Ve(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 Ve(t){let e=null,s=null,n=null,r=1,c=null;if(ee(t)||se(t))n=t,e=$e(t),s=Ae(t);else{if(!je.call(t,"name"))throw new Error(mt("name"));const o=t.name;if(n=o,je.call(t,"weight")&&(r=t.weight,r<=0))throw new Error(gt(o));e=$e(o),s=Ae(o),c=t.getFn}return{path:e,id:s,weight:r,src:n,getFn:c}}function $e(t){return se(t)?t:t.split(".")}function Ae(t){return se(t)?t.join("."):t}function At(t,e){let s=[],n=!1;const r=(c,o,a)=>{if(Q(c))if(!o[a])s.push(c);else{let u=o[a];const l=c[u];if(!Q(l))return;if(a===o.length-1&&(ee(l)||ze(l)||ut(l)))s.push(at(l));else if(se(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,ee(e)?e.split("."):e,0),n?s:s[0]}const yt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Et={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},xt={location:0,threshold:.6,distance:100},Ct={useExtendedSearch:!1,getFn:At,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var g={...Et,...yt,...xt,...Ct};const wt=/[^ ]+/g;function Ft(t=1,e=3){const s=new Map,n=Math.pow(10,e);return{get(r){const c=r.match(wt).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 Me{constructor({getFn:e=g.getFn,fieldNormWeight:s=g.fieldNormWeight}={}){this.norm=Ft(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,ee(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();ee(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(!Q(e)||pe(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(Q(o)){if(se(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(Q(h))if(ee(h)&&!pe(h)){let f={v:h,i:l,n:this.norm.get(h)};a.push(f)}else se(h)&&h.forEach((f,m)=>{u.push({nestedArrIndex:m,value:f})})}n.$[c]=a}else if(ee(o)&&!pe(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 Ye(t,e,{getFn:s=g.getFn,fieldNormWeight:n=g.fieldNormWeight}={}){const r=new Me({getFn:s,fieldNormWeight:n});return r.setKeys(t.map(Ve)),r.setSources(e),r.create(),r}function Mt(t,{getFn:e=g.getFn,fieldNormWeight:s=g.fieldNormWeight}={}){const{keys:n,records:r}=t,c=new Me({getFn:e,fieldNormWeight:s});return c.setKeys(n),c.setIndexRecords(r),c}function he(t,{errors:e=0,currentLocation:s=0,expectedLocation:n=0,distance:r=g.distance,ignoreLocation:c=g.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 It(t=[],e=g.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 ce=32;function St(t,e,s,{location:n=g.location,distance:r=g.distance,threshold:c=g.threshold,findAllMatches:o=g.findAllMatches,minMatchCharLength:a=g.minMatchCharLength,includeMatches:u=g.includeMatches,ignoreLocation:l=g.ignoreLocation}={}){if(e.length>ce)throw new Error(ft(ce));const h=e.length,f=t.length,m=Math.max(0,Math.min(n,f));let A=c,E=m;const k=a>1||u,v=k?Array(f):[];let b;for(;(b=t.indexOf(e,E))>-1;){let x=he(e,{currentLocation:b,expectedLocation:m,distance:r,ignoreLocation:l});if(A=Math.min(x,A),E=b+h,k){let C=0;for(;C<h;)v[b+C]=1,C+=1}}E=-1;let L=[],Y=1,W=h+f;const oe=1<<h-1;for(let x=0;x<h;x+=1){let C=0,B=W;for(;C<B;)he(e,{errors:x,currentLocation:m+B,expectedLocation:m,distance:r,ignoreLocation:l})<=A?C=B:W=B,B=Math.floor((W-C)/2+C);W=B;let O=Math.max(1,m-B+1),K=o?f:Math.min(m+B,f)+h,V=Array(K+2);V[K+1]=(1<<x)-1;for(let R=K;R>=O;R-=1){let te=R-1,ie=s[t.charAt(te)];if(k&&(v[te]=+!!ie),V[R]=(V[R+1]<<1|1)&ie,x&&(V[R]|=(L[R+1]|L[R])<<1|1|L[R+1]),V[R]&oe&&(Y=he(e,{errors:x,currentLocation:te,expectedLocation:m,distance:r,ignoreLocation:l}),Y<=A)){if(A=Y,E=te,E<=m)break;O=Math.max(1,2*m-E)}}if(he(e,{errors:x+1,currentLocation:m,expectedLocation:m,distance:r,ignoreLocation:l})>A)break;L=V}const H={isMatch:E>=0,score:Math.max(.001,Y)};if(k){const x=It(v,a);x.length?u&&(H.indices=x):H.isMatch=!1}return H}function Bt(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 fe=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 Ge{constructor(e,{location:s=g.location,threshold:n=g.threshold,distance:r=g.distance,includeMatches:c=g.includeMatches,findAllMatches:o=g.findAllMatches,minMatchCharLength:a=g.minMatchCharLength,isCaseSensitive:u=g.isCaseSensitive,ignoreDiacritics:l=g.ignoreDiacritics,ignoreLocation:h=g.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?fe(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const f=(A,E)=>{this.chunks.push({pattern:A,alphabet:Bt(A),startIndex:E})},m=this.pattern.length;if(m>ce){let A=0;const E=m%ce,k=m-E;for(;A<k;)f(this.pattern.substr(A,ce),A),A+=ce;if(E){const v=m-ce;f(this.pattern.substr(v),v)}}else f(this.pattern,0)}searchIn(e){const{isCaseSensitive:s,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=s?e:e.toLowerCase(),e=n?fe(e):e,this.pattern===e){let k={isMatch:!0,score:0};return r&&(k.indices=[[0,e.length-1]]),k}const{location:c,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let f=[],m=0,A=!1;this.chunks.forEach(({pattern:k,alphabet:v,startIndex:b})=>{const{isMatch:L,score:Y,indices:W}=St(e,k,v,{location:c+b,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:r,ignoreLocation:h});L&&(A=!0),m+=Y,L&&W&&(f=[...f,...W])});let E={isMatch:A,score:A?m/this.chunks.length:1};return A&&r&&(E.indices=f),E}}class re{constructor(e){this.pattern=e}static isMultiMatch(e){return Le(e,this.multiRegex)}static isSingleMatch(e){return Le(e,this.singleRegex)}search(){}}function Le(t,e){const s=t.match(e);return s?s[1]:null}class Dt extends re{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 kt extends re{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 Nt extends re{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 _t extends re{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 bt extends re{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 vt extends re{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 Ue extends re{constructor(e,{location:s=g.location,threshold:n=g.threshold,distance:r=g.distance,includeMatches:c=g.includeMatches,findAllMatches:o=g.findAllMatches,minMatchCharLength:a=g.minMatchCharLength,isCaseSensitive:u=g.isCaseSensitive,ignoreDiacritics:l=g.ignoreDiacritics,ignoreLocation:h=g.ignoreLocation}={}){super(e),this._bitapSearch=new Ge(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 He extends re{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 ye=[Dt,He,Nt,_t,vt,bt,kt,Ue],Te=ye.length,Rt=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,jt="|";function $t(t,e={}){return t.split(jt).map(s=>{let n=s.trim().split(Rt).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<Te;){const h=ye[l];let f=h.isMultiMatch(a);f&&(r.push(new h(f,e)),u=!0)}if(!u)for(l=-1;++l<Te;){const h=ye[l];let f=h.isSingleMatch(a);if(f){r.push(new h(f,e));break}}}return r})}const Lt=new Set([Ue.type,He.type]);class Tt{constructor(e,{isCaseSensitive:s=g.isCaseSensitive,ignoreDiacritics:n=g.ignoreDiacritics,includeMatches:r=g.includeMatches,minMatchCharLength:c=g.minMatchCharLength,ignoreLocation:o=g.ignoreLocation,findAllMatches:a=g.findAllMatches,location:u=g.location,threshold:l=g.threshold,distance:h=g.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?fe(e):e,this.pattern=e,this.query=$t(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?fe(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,A=f.length;m<A;m+=1){const E=f[m],{isMatch:k,indices:v,score:b}=E.search(e);if(k){if(o+=1,u+=b,n){const L=E.constructor.type;Lt.has(L)?a=[...a,...v]:a.push(v)}}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 Ee=[];function Pt(...t){Ee.push(...t)}function xe(t,e){for(let s=0,n=Ee.length;s<n;s+=1){let r=Ee[s];if(r.condition(t,e))return new r(t,e)}return new Ge(t,e)}const me={AND:"$and",OR:"$or"},Ce={PATH:"$path",PATTERN:"$val"},we=t=>!!(t[me.AND]||t[me.OR]),Ot=t=>!!t[Ce.PATH],Kt=t=>!se(t)&&Qe(t)&&!we(t),Pe=t=>({[me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function Je(t,e,{auto:s=!0}={}){const n=r=>{let c=Object.keys(r);const o=Ot(r);if(!o&&c.length>1&&!we(r))return n(Pe(r));if(Kt(r)){const u=o?r[Ce.PATH]:c[0],l=o?r[Ce.PATTERN]:r[u];if(!ee(l))throw new Error(dt(u));const h={keyId:Ae(u),pattern:l};return s&&(h.searcher=xe(l,e)),h}let a={children:[],operator:c[0]};return c.forEach(u=>{const l=r[u];se(l)&&l.forEach(h=>{a.children.push(n(h))})}),a};return we(t)||(t=Pe(t)),n(t)}function zt(t,{ignoreFieldNorm:e=g.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 Qt(t,e){const s=t.matches;e.matches=[],Q(s)&&s.forEach(n=>{if(!Q(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 Wt(t,e){e.score=t.score}function Vt(t,e,{includeMatches:s=g.includeMatches,includeScore:n=g.includeScore}={}){const r=[];return s&&r.push(Qt),n&&r.push(Wt),t.map(c=>{const{idx:o}=c,a={item:e[o],refIndex:o};return r.length&&r.forEach(u=>{u(c,a)}),a})}class q{constructor(e,s={},n){this.options={...g,...s},this.options.useExtendedSearch,this._keyStore=new pt(this.options.keys),this.setCollection(e,n)}setCollection(e,s){if(this._docs=e,s&&!(s instanceof Me))throw new Error(ht);this._myIndex=s||Ye(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){Q(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=ee(e)?ee(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return zt(u,{ignoreFieldNorm:a}),c&&u.sort(o),ze(s)&&s>-1&&(u=u.slice(0,s)),Vt(u,this._docs,{includeMatches:n,includeScore:r})}_searchStringList(e){const s=xe(e,this.options),{records:n}=this._myIndex,r=[];return n.forEach(({v:c,i:o,n:a})=>{if(!Q(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=Je(e,this.options),n=(a,u,l)=>{if(!a.children){const{keyId:f,searcher:m}=a,A=this._findMatches({key:this._keyStore.get(f),value:this._myIndex.getValueForItemAtKeyId(u,f),searcher:m});return A&&A.length?[{idx:l,item:u,matches:A}]:[]}const h=[];for(let f=0,m=a.children.length;f<m;f+=1){const A=a.children[f],E=n(A,u,l);if(E.length)h.push(...E);else if(a.operator===me.AND)return[]}return h},r=this._myIndex.records,c={},o=[];return r.forEach(({$:a,i:u})=>{if(Q(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=xe(e,this.options),{keys:n,records:r}=this._myIndex,c=[];return r.forEach(({$:o,i:a})=>{if(!Q(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(!Q(s))return[];let r=[];if(se(s))s.forEach(({v:c,i:o,n:a})=>{if(!Q(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}}q.version="7.1.0";q.createIndex=Ye;q.parseIndex=Mt;q.config=g;q.parseQuery=Je;Pt(Tt);const Oe={".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 Yt(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 Gt(t,e=16){var r;const s="."+(((r=t.split(".").pop())==null?void 0:r.toLowerCase())??""),n=Oe[s]||Oe.default;return d.jsx(Z,{name:n,size:e})}function cs(t,e=16){return d.jsx(Z,{name:Yt(t),size:e,weight:"fill"})}function Xe(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 os(t){const s=Date.now()-t;return Xe(s)}const Ze="tide-commander:spotlight-recent-agents",Ut=15;function qe(){try{const t=localStorage.getItem(Ze);if(!t)return[];const e=JSON.parse(t);return Array.isArray(e)?e.filter(s=>typeof s=="string"):[]}catch{return[]}}function Ht(t){try{const e=[t,...qe().filter(s=>s!==t)].slice(0,Ut);localStorage.setItem(Ze,JSON.stringify(e))}catch{}}function de(t,e){if(!t)return Number.POSITIVE_INFINITY;const s=e.indexOf(t);return s===-1?Number.POSITIVE_INFINITY:s}function Ke(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 Jt=["command","agent","building","area","modified-file"];function Xt({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=st(),f=nt(),m=rt(),A=it(),E=y.useRef(e);E.current=e;const k=y.useRef(s);k.current=s;const v=y.useRef(n);v.current=n;const b=y.useRef(r);b.current=r;const L=y.useRef(c);L.current=c;const Y=y.useRef(o);Y.current=o;const W=y.useRef(a);W.current=a;const oe=y.useRef(u);oe.current=u;const H=y.useRef(l);H.current=l;const[x,C]=y.useState(""),[B,O]=y.useState(0);y.useEffect(()=>{t&&(C(""),O(0))},[t]);const K=ne.getShortcuts(),V=y.useMemo(()=>t?qe():[],[t]),ae=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?Re(i):"Alt+N",icon:d.jsx(Z,{name:"plus",size:16}),action:()=>{E.current(),k.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:M?Re(M):"Ctrl+K",icon:d.jsx(Z,{name:"dashboard",size:16}),action:()=>{E.current(),v.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:d.jsx(Z,{name:"gear",size:16}),action:()=>{E.current(),b.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:d.jsx(Z,{name:"chart-line",size:16}),action:()=>{var I;E.current(),(I=H.current)==null||I.call(H)}}]},[t,K]),R=y.useMemo(()=>t?Array.from(h.values()).map(i=>{const M=(A||[]).filter(T=>T.agentId===i.id).map(T=>T.filePath),I=[...new Set(M)],S=I.map(T=>T.split("/").pop()||T),N=[];i.lastAssignedTask&&N.push(i.lastAssignedTask);const j=`${i.class} • ${i.status} • ${i.cwd}`;let _=`${i.name} ${j}`;S.length>0&&(_+=` ${S.join(" ")} ${I.join(" ")}`),N.length>0&&(_+=` ${N.join(" ")}`);const z=Date.now()-i.lastActivity;let J;return i.lastAssignedTask&&(i.lastAssignedTask.length>150?J=i.lastAssignedTask.slice(0,150)+"...":J=i.lastAssignedTask),{id:`agent-${i.id}`,type:"agent",title:i.name,subtitle:j,lastUserInput:J,timeAway:z,icon:d.jsx(ct,{agent:i,size:20}),_searchText:_,_modifiedFiles:I,_userQueries:N,_agentId:i.id,action:()=>{E.current(),Ht(i.id),ne.selectAgent(i.id),ne.getState().viewMode!=="flat"&&ne.requestTerminalExpand()}}}):[],[t,h,A]),te=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(Z,{name:"map",size:16}),action:()=>{E.current(),ne.selectArea(i.id)}}}):[],[t,f]),ie=y.useMemo(()=>t?Array.from(m.values()).filter(i=>i.type==="server"||i.type==="boss"||i.type==="database").map(i=>{var _,z,J,T;const M=i.status==="running"?"#4ade80":i.status==="stopped"?"#f87171":"#facc15",I=i.type==="boss"?"crown":i.type==="database"?"database":"desktop";let N=`${i.type==="boss"?"Boss":i.type==="database"?"Database":"Server"} • ${i.status}`;if(i.type==="database"&&((z=(_=i.database)==null?void 0:_.connections)!=null&&z.length)){const $=i.database.connections[0];N+=` • ${$.engine} @ ${$.host}`}else i.cwd&&(N+=` • ${i.cwd}`);let j=`${i.name} ${i.type} ${i.status} ${i.cwd||""} ${((J=i.pm2)==null?void 0:J.name)||""}`;if(i.type==="database"&&((T=i.database)!=null&&T.connections))for(const $ of i.database.connections)j+=` ${$.name} ${$.engine} ${$.host} ${$.database||""} mysql postgresql sql`;return{id:`building-${i.id}`,type:"building",title:i.name,subtitle:N,icon:d.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[d.jsx(Z,{name:"status-pending",size:10,weight:"fill",color:M}),d.jsx(Z,{name:I,size:16})]}),_searchText:j,action:()=>{var $;E.current(),i.type==="boss"?W.current(i.id):i.type==="database"?oe.current(i.id):($=i.pm2)!=null&&$.enabled&&Y.current(i.id)}}}):[],[t,m]),Ie=y.useMemo(()=>{if(!t)return[];const i=A||[],M=new Set,I=[];for(const S of i){if(M.has(S.filePath))continue;M.add(S.filePath);const N=S.filePath.split("/").pop()||S.filePath,j=S.action==="created"?"Created":S.action==="modified"?"Modified":S.action==="deleted"?"Deleted":"Read";if(I.push({id:`modified-${S.filePath}-${S.timestamp}`,type:"modified-file",title:N,subtitle:`${j} by ${S.agentName} • ${S.filePath}`,matchedText:S.filePath,icon:S.action==="deleted"?d.jsx(Z,{name:"trash",size:16}):Gt(S.filePath),action:()=>{E.current();const _=Array.from(ne.getState().areas.values());for(const z of _)for(const J of z.directories||[])if(S.filePath.startsWith(J)){ne.setFileViewerPath(S.filePath),L.current(z.id);return}ne.selectAgent(S.agentId)}}),I.length>=50)break}return I},[t,A]),Se=y.useMemo(()=>new q(R,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[R]),Be=y.useMemo(()=>new q(ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[ae]),De=y.useMemo(()=>new q(te,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[te]),ke=y.useMemo(()=>new q(Ie,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ie]),Ne=y.useMemo(()=>new q(ie,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ie]),G=y.useMemo(()=>{if(!x.trim()){const p=[];p.push(...ie);const w=[...R].sort((D,P)=>{const X=de(D._agentId,V),U=de(P._agentId,V);if(X!==U)return X-U;const ue=D.timeAway??0,le=P.timeAway??0;return ue-le});p.push(...w),p.push(...ae.slice(0,2)),p.push(...te.slice(0,2));const F={};return Jt.forEach((D,P)=>{F[D]=P}),p.sort((D,P)=>(F[D.type]??999)-(F[P.type]??999)),p}const i=x.trim().toLowerCase(),M=Se.search(x).slice(0,8),I=Be.search(x).slice(0,3),S=De.search(x).slice(0,2),N=ke.search(x).slice(0,3),j=Ne.search(x).filter(p=>{const w=p.score??1;return`${p.item.title} ${p.item.subtitle||""} ${p.item._searchText||""}`.toLowerCase().includes(i)||w<=.2}).slice(0,4),_={agent:5,building:4,command:3,area:2,"modified-file":1},z=p=>{if(!i)return 1;const w=p.title.toLowerCase();return w===i?6:w.startsWith(i)?5:w.split(/[^a-z0-9]+/i).includes(i)?4:w.includes(i)?3:`${p.subtitle||""} ${p._searchText||""} ${p.matchedText||""}`.toLowerCase().includes(i)?2:1},J=(p,w)=>{const F=(1-Math.min(1,w??1))*4;return z(p)*100+(_[p.type]??0)*5+F},T=new Map,$=(p,w)=>{const F=T.get(p.type),D={item:p,score:J(p,w)};F?F.push(D):T.set(p.type,[D])};for(const p of M){const w={...p.item};if(w._modifiedFiles&&w._modifiedFiles.length>0){const F=w._modifiedFiles.filter(D=>{var U;const P=((U=D.split("/").pop())==null?void 0:U.toLowerCase())||"",X=D.toLowerCase();return P.includes(i)||X.includes(i)});F.length>0&&(w.matchedFiles=F)}if(w._userQueries&&w._userQueries.length>0){const F=w._userQueries.find(D=>D.toLowerCase().includes(i));if(F)if(F.length>200){const P=F.toLowerCase().indexOf(i),X=Math.max(0,P-60),U=Math.min(F.length,P+i.length+100);w.matchedQuery=(X>0?"...":"")+F.slice(X,U)+(U<F.length?"...":"")}else w.matchedQuery=F}$(w,p.score)}for(const p of j)$(p.item,p.score);for(const p of I)$(p.item,p.score);for(const p of S)$(p.item,p.score);for(const p of N)$(p.item,p.score);for(const[p,w]of T)p==="agent"?w.sort((F,D)=>{const P=z(F.item),X=z(D.item);if(X!==P)return X-P;const U=de(F.item._agentId,V),ue=de(D.item._agentId,V);if(U!==ue)return U-ue;const le=F.item.timeAway??Number.POSITIVE_INFINITY,ve=D.item.timeAway??Number.POSITIVE_INFINITY;return le!==ve?le-ve:D.score-F.score}):w.sort((F,D)=>D.score-F.score);const _e=p=>p.reduce((w,F)=>Math.max(w,F.score),-1),be=[];return Array.from(T.values()).sort((p,w)=>_e(w)-_e(p)).forEach(p=>{for(const w of p)be.push(w.item)}),be},[x,Se,Be,De,ke,Ne,ae,R,te,ie,V]);y.useEffect(()=>{B>=G.length&&O(Math.max(0,G.length-1))},[G.length,B]);const et=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();O(M==="p"?I=>I>0?I-1:G.length-1:I=>I<G.length-1?I+1:0);return}switch(i.key){case"Escape":i.preventDefault(),E.current();break;case"ArrowUp":i.preventDefault(),O(M=>M>0?M-1:G.length-1);break;case"ArrowDown":i.preventDefault(),O(M=>M<G.length-1?M+1:0);break;case"Enter":i.preventDefault(),G[B]&&G[B].action();break}},[G,B]),tt=y.useCallback((i,M)=>{if(!M||!i)return i;const I=i.toLowerCase(),S=M.toLowerCase(),N=[];let j=0,_=I.indexOf(S),z=0;for(;_!==-1;)_>j&&N.push(i.slice(j,_)),N.push(ge.createElement("mark",{key:z++,className:"spotlight-highlight"},i.slice(_,_+M.length))),j=_+M.length,_=I.indexOf(S,j);return j<i.length&&N.push(i.slice(j)),N.length>0?ge.createElement(ge.Fragment,null,...N):i},[]);return{query:x,setQuery:C,selectedIndex:B,setSelectedIndex:O,results:G,handleKeyDown:et,highlightMatch:tt}}const Zt=y.forwardRef(function({query:e,onQueryChange:s,onKeyDown:n,onResetSelection:r},c){const{t:o}=Fe(["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":Ke(e.type),children:Ke(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: ",Xe(e.timeAway)]})}),e.lastUserInput&&!e.matchedQuery&&d.jsxs("span",{className:"spotlight-item-last-input",children:['"',r(e.lastUserInput,n),'"']})]})]})}),es=y.forwardRef(function({results:e,selectedIndex:s,query:n,highlightMatch:r,onSelectIndex:c},o){const{t:a}=Fe(["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,A=[];return e.forEach((E,k)=>{E.type!==m&&(m!==null&&A.length>0&&f.push([m,A]),m=E.type,A=[]),A.push({result:E,index:k})}),m!==null&&A.length>0&&f.push([m,A]),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:A,index:E})=>d.jsx(qt,{result:A,isSelected:E===s,query:n,highlightMatch:r,onClick:()=>A.action(),onMouseEnter:()=>{u.current&&c(E)}},A.id))]},f))})}),ts=y.memo(function(){const{t:e}=Fe(["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")]})})]})}),ss=768;function as({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),A=y.useRef(0),{query:E,setQuery:k,selectedIndex:v,setSelectedIndex:b,results:L,handleKeyDown:Y,highlightMatch:W}=Xt({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:n,onOpenToolbox:r,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});A.current=L.length,y.useEffect(()=>{t&&setTimeout(()=>{var x;(x=h.current)==null||x.focus()},50)},[t]),y.useEffect(()=>{if(!t)return;const x=window.visualViewport;if(!x||window.innerWidth>ss)return;const C=()=>{const B=f.current;B&&(B.style.height=`${x.height}px`,B.style.top=`${x.offsetTop}px`)};return C(),x.addEventListener("resize",C),x.addEventListener("scroll",C),()=>{x.removeEventListener("resize",C),x.removeEventListener("scroll",C);const B=f.current;B&&(B.style.height="",B.style.top="")}},[t]),y.useEffect(()=>{if(!t)return;const x=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(),O=A.current;b(B==="p"?K=>K>0?K-1:O-1:K=>K<O-1?K+1:0);return}};return window.addEventListener("keydown",x,{capture:!0}),()=>{window.removeEventListener("keydown",x,{capture:!0})}},[t,e]);const oe=y.useCallback(x=>{x.target===x.currentTarget&&e()},[e]),H=y.useCallback(()=>{b(0)},[b]);return t?d.jsx("div",{ref:f,className:"spotlight-overlay",onClick:oe,children:d.jsxs("div",{className:"spotlight-modal",children:[d.jsx(Zt,{ref:h,query:E,onQueryChange:k,onKeyDown:Y,onResetSelection:H}),d.jsx(es,{ref:m,results:L,selectedIndex:v,query:E,highlightMatch:W,onSelectIndex:b}),d.jsx(ts,{})]})}):null}export{Oe as FILE_ICON_NAMES,as as Spotlight,ts as SpotlightFooter,Zt as SpotlightInput,qt as SpotlightItem,es as SpotlightResults,Xe as formatDuration,os as formatRelativeTime,cs as getAgentIcon,Gt as getFileIconFromPath,Ke as getTypeLabel,Xt as useSpotlightSearch};
@@ -1,4 +1,4 @@
1
- import{bj as ta,u as B,j as e,aO as j,bm as Ms,bn as Fs,aP as Ue,s as D,bo as $s,r as d,D as Z,I as F,a3 as Us,aY as qe,f as na,bp as la,J as ia,S as oa,h as ra,a2 as Ks,aZ as He}from"./main-Bon1sZAi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const ca=[{value:"",labelKey:"terminal:building.colorDefault"},{value:"#2a2a3a",labelKey:"terminal:building.colorDarkGray"},{value:"#3a2a2a",labelKey:"terminal:building.colorDarkRed"},{value:"#2a3a2a",labelKey:"terminal:building.colorDarkGreen"},{value:"#2a2a4a",labelKey:"terminal:building.colorDarkBlue"},{value:"#3a3a2a",labelKey:"terminal:building.colorDarkYellow"},{value:"#3a2a3a",labelKey:"terminal:building.colorDarkPurple"},{value:"#2a3a3a",labelKey:"terminal:building.colorDarkCyan"},{value:"#4a3a3a",labelKey:"terminal:building.colorWarmBrown"},{value:"#3a4a4a",labelKey:"terminal:building.colorCoolSteel"}];function ma(o){return ta.t(o)}function Ve(o){if(o===0)return"0 B";const p=1024,u=["B","KB","MB","GB"],x=Math.floor(Math.log(o)/Math.log(p));return parseFloat((o/Math.pow(p,x)).toFixed(1))+" "+u[x]}function da(o){const u=Date.now()-o,x=Math.floor(u/(1e3*60*60)),n=Math.floor(u%(1e3*60*60)/(1e3*60));return x>0?`${x}h ${n}m`:`${n}m`}const Hs={30:"#1a1a1a",31:"#e74c3c",32:"#2ecc71",33:"#f39c12",34:"#3498db",35:"#9b59b6",36:"#00bcd4",37:"#ecf0f1",90:"#7f8c8d",91:"#ff6b6b",92:"#4ade80",93:"#fbbf24",94:"#60a5fa",95:"#c084fc",96:"#22d3ee",97:"#ffffff"};function qs(o){const p=[],u=/\x1B\[([0-9;]*)m/g;let x=0,n=null,y;for(;(y=u.exec(o))!==null;){if(y.index>x){const g=o.slice(x,y.index);n?p.push(e.jsx("span",{style:{color:n},children:g},p.length)):p.push(g)}const C=y[1].split(";").map(Number);for(const g of C)g===0||g===39?n=null:Hs[g]&&(n=Hs[g]);x=u.lastIndex}if(x<o.length){const C=o.slice(x);n?p.push(e.jsx("span",{style:{color:n},children:C},p.length)):p.push(C)}return p.length>0?p:[o]}function ua({buildingName:o,onClose:p,onConfirm:u}){const{t:x}=B(["terminal","common"]);return e.jsx("div",{className:"modal-overlay visible",onClick:p,children:e.jsxs("div",{className:"modal confirm-modal",onClick:n=>n.stopPropagation(),children:[e.jsx("div",{className:"modal-header",children:x("terminal:building.deleteBuilding")}),e.jsxs("div",{className:"modal-body confirm-modal-body",children:[e.jsx("p",{children:x("terminal:building.deleteConfirm",{name:o})}),e.jsx("p",{className:"confirm-modal-note",children:x("terminal:building.deleteNote")})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{className:"btn btn-secondary",onClick:p,children:x("common:buttons.cancel")}),e.jsx("button",{className:"btn btn-danger",onClick:u,autoFocus:!0,children:x("common:buttons.delete")})]})]})})}function pa({usePM2:o,setUsePM2:p}){const{t:u}=B(["terminal"]);return e.jsxs("div",{className:"form-section pm2-toggle-section",children:[e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",className:"toggle-input",checked:o,onChange:x=>p(x.target.checked)}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})}),e.jsxs("span",{className:"toggle-label",children:[e.jsx("span",{className:"pm2-badge",children:"PM2"}),u("terminal:building.usePM2")]})]}),e.jsx("div",{className:"form-hint",children:u("terminal:building.pm2Hint")})]})}function ha({usePM2:o,pm2Script:p,setPm2Script:u,pm2Args:x,setPm2Args:n,pm2Interpreter:y,setPm2Interpreter:C,pm2InterpreterArgs:g,setPm2InterpreterArgs:v,pm2Env:s,setPm2Env:h,isEditMode:a,building:t,handleCommand:r}){var N;const{t:i}=B(["terminal","common"]);return o?e.jsxs("div",{className:"form-section pm2-config-section",children:[e.jsx("label",{className:"form-label",children:i("terminal:building.pm2Configuration")}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Script"),e.jsx(j,{text:i("terminal:building.helpPm2Script"),title:i("terminal:building.pm2Script"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:p,onChange:b=>u(b.target.value),placeholder:"npm, java, python, ./app.js",required:o})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Arguments"),e.jsx(j,{text:i("terminal:building.helpPm2Arguments"),title:i("terminal:building.pm2Arguments"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:x,onChange:b=>n(b.target.value),placeholder:"run dev, -jar app.jar, app.py"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Interpreter"),e.jsx(j,{text:i("terminal:building.helpPm2Interpreter"),title:i("terminal:building.pm2Interpreter"),position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:y,onChange:b=>C(b.target.value),children:Object.keys(Ms).map(b=>e.jsx("option",{value:b,children:Ms[b].label},b))})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2InterpArgs"),e.jsx(j,{text:i("terminal:building.helpPm2InterpArgs"),title:i("terminal:building.pm2InterpArgs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:g,onChange:b=>v(b.target.value),placeholder:"-jar (for Java)"})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Environment"),e.jsx(j,{text:i("terminal:building.helpPm2Environment"),title:i("terminal:building.pm2Environment"),position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:s,onChange:b=>h(b.target.value),placeholder:`KEY=value
1
+ import{bj as ta,u as B,j as e,aO as j,bm as Ms,bn as Fs,aP as Ue,s as D,bo as $s,r as d,D as Z,I as F,a3 as Us,aY as qe,f as na,bp as la,J as ia,S as oa,h as ra,a2 as Ks,aZ as He}from"./main-vfMoYhg1.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const ca=[{value:"",labelKey:"terminal:building.colorDefault"},{value:"#2a2a3a",labelKey:"terminal:building.colorDarkGray"},{value:"#3a2a2a",labelKey:"terminal:building.colorDarkRed"},{value:"#2a3a2a",labelKey:"terminal:building.colorDarkGreen"},{value:"#2a2a4a",labelKey:"terminal:building.colorDarkBlue"},{value:"#3a3a2a",labelKey:"terminal:building.colorDarkYellow"},{value:"#3a2a3a",labelKey:"terminal:building.colorDarkPurple"},{value:"#2a3a3a",labelKey:"terminal:building.colorDarkCyan"},{value:"#4a3a3a",labelKey:"terminal:building.colorWarmBrown"},{value:"#3a4a4a",labelKey:"terminal:building.colorCoolSteel"}];function ma(o){return ta.t(o)}function Ve(o){if(o===0)return"0 B";const p=1024,u=["B","KB","MB","GB"],x=Math.floor(Math.log(o)/Math.log(p));return parseFloat((o/Math.pow(p,x)).toFixed(1))+" "+u[x]}function da(o){const u=Date.now()-o,x=Math.floor(u/(1e3*60*60)),n=Math.floor(u%(1e3*60*60)/(1e3*60));return x>0?`${x}h ${n}m`:`${n}m`}const Hs={30:"#1a1a1a",31:"#e74c3c",32:"#2ecc71",33:"#f39c12",34:"#3498db",35:"#9b59b6",36:"#00bcd4",37:"#ecf0f1",90:"#7f8c8d",91:"#ff6b6b",92:"#4ade80",93:"#fbbf24",94:"#60a5fa",95:"#c084fc",96:"#22d3ee",97:"#ffffff"};function qs(o){const p=[],u=/\x1B\[([0-9;]*)m/g;let x=0,n=null,y;for(;(y=u.exec(o))!==null;){if(y.index>x){const g=o.slice(x,y.index);n?p.push(e.jsx("span",{style:{color:n},children:g},p.length)):p.push(g)}const C=y[1].split(";").map(Number);for(const g of C)g===0||g===39?n=null:Hs[g]&&(n=Hs[g]);x=u.lastIndex}if(x<o.length){const C=o.slice(x);n?p.push(e.jsx("span",{style:{color:n},children:C},p.length)):p.push(C)}return p.length>0?p:[o]}function ua({buildingName:o,onClose:p,onConfirm:u}){const{t:x}=B(["terminal","common"]);return e.jsx("div",{className:"modal-overlay visible",onClick:p,children:e.jsxs("div",{className:"modal confirm-modal",onClick:n=>n.stopPropagation(),children:[e.jsx("div",{className:"modal-header",children:x("terminal:building.deleteBuilding")}),e.jsxs("div",{className:"modal-body confirm-modal-body",children:[e.jsx("p",{children:x("terminal:building.deleteConfirm",{name:o})}),e.jsx("p",{className:"confirm-modal-note",children:x("terminal:building.deleteNote")})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{className:"btn btn-secondary",onClick:p,children:x("common:buttons.cancel")}),e.jsx("button",{className:"btn btn-danger",onClick:u,autoFocus:!0,children:x("common:buttons.delete")})]})]})})}function pa({usePM2:o,setUsePM2:p}){const{t:u}=B(["terminal"]);return e.jsxs("div",{className:"form-section pm2-toggle-section",children:[e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",className:"toggle-input",checked:o,onChange:x=>p(x.target.checked)}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})}),e.jsxs("span",{className:"toggle-label",children:[e.jsx("span",{className:"pm2-badge",children:"PM2"}),u("terminal:building.usePM2")]})]}),e.jsx("div",{className:"form-hint",children:u("terminal:building.pm2Hint")})]})}function ha({usePM2:o,pm2Script:p,setPm2Script:u,pm2Args:x,setPm2Args:n,pm2Interpreter:y,setPm2Interpreter:C,pm2InterpreterArgs:g,setPm2InterpreterArgs:v,pm2Env:s,setPm2Env:h,isEditMode:a,building:t,handleCommand:r}){var N;const{t:i}=B(["terminal","common"]);return o?e.jsxs("div",{className:"form-section pm2-config-section",children:[e.jsx("label",{className:"form-label",children:i("terminal:building.pm2Configuration")}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Script"),e.jsx(j,{text:i("terminal:building.helpPm2Script"),title:i("terminal:building.pm2Script"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:p,onChange:b=>u(b.target.value),placeholder:"npm, java, python, ./app.js",required:o})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Arguments"),e.jsx(j,{text:i("terminal:building.helpPm2Arguments"),title:i("terminal:building.pm2Arguments"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:x,onChange:b=>n(b.target.value),placeholder:"run dev, -jar app.jar, app.py"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Interpreter"),e.jsx(j,{text:i("terminal:building.helpPm2Interpreter"),title:i("terminal:building.pm2Interpreter"),position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:y,onChange:b=>C(b.target.value),children:Object.keys(Ms).map(b=>e.jsx("option",{value:b,children:Ms[b].label},b))})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2InterpArgs"),e.jsx(j,{text:i("terminal:building.helpPm2InterpArgs"),title:i("terminal:building.pm2InterpArgs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:g,onChange:b=>v(b.target.value),placeholder:"-jar (for Java)"})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Environment"),e.jsx(j,{text:i("terminal:building.helpPm2Environment"),title:i("terminal:building.pm2Environment"),position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:s,onChange:b=>h(b.target.value),placeholder:`KEY=value
2
2
  SERVER_PORT=7201
3
3
  NODE_ENV=production`,rows:3})]}),e.jsx("div",{className:"pm2-examples",children:e.jsxs("details",{children:[e.jsx("summary",{children:i("terminal:building.pm2Examples")}),e.jsxs("div",{className:"pm2-examples-content",children:[e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Node.js:"})," Script: ",e.jsx("code",{children:"npm"}),", Args: ",e.jsx("code",{children:"run dev"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Symfony:"})," Script: ",e.jsx("code",{children:"symfony"}),", Args: ",e.jsx("code",{children:"serve --no-daemon"}),", Interpreter: ",e.jsx("code",{children:"None"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Java JAR:"})," Script: ",e.jsx("code",{children:"app.jar"}),", Interpreter: ",e.jsx("code",{children:"Java"}),", Interp. Args: ",e.jsx("code",{children:"-jar"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Python:"})," Script: ",e.jsx("code",{children:"app.py"}),", Interpreter: ",e.jsx("code",{children:"Python 3"})]})]})]})}),a&&(t==null?void 0:t.pm2Status)&&e.jsx("div",{className:"pm2-status-display",children:e.jsxs("div",{className:"pm2-status-row",children:[e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"PID"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.pid||"-"})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"CPU"}),e.jsxs("span",{className:"pm2-metric-value",children:[((N=t.pm2Status.cpu)==null?void 0:N.toFixed(1))||"0","%"]})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"MEM"}),e.jsx("span",{className:"pm2-metric-value",children:Ve(t.pm2Status.memory||0)})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Restarts"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.restarts||0})]}),t.pm2Status.uptime&&e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Uptime"}),e.jsx("span",{className:"pm2-metric-value",children:da(t.pm2Status.uptime)})]})]})}),a&&e.jsxs("div",{className:"pm2-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>r("start"),children:i("common:buttons.start")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>r("stop"),children:i("common:buttons.stop")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>r("restart"),children:i("terminal:buildingAction.restart")}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>r("logs"),children:i("terminal:logs.title")})]})]}):null}function xa({dockerMode:o,setDockerMode:p,dockerImage:u,setDockerImage:x,dockerContainerName:n,setDockerContainerName:y,dockerCommand:C,setDockerCommand:g,dockerPorts:v,setDockerPorts:s,dockerVolumes:h,setDockerVolumes:a,dockerNetwork:t,setDockerNetwork:r,dockerRestart:i,setDockerRestart:N,dockerPull:b,setDockerPull:L,dockerEnv:T,setDockerEnv:A,dockerComposePath:$,setDockerComposePath:R,dockerComposeProject:K,setDockerComposeProject:I,dockerComposeServices:H,setDockerComposeServices:O,selectedExistingContainer:c,setSelectedExistingContainer:E,dockerContainersList:q,isEditMode:V,building:k,handleCommand:_}){const{t:M}=B(["config","common"]);return e.jsxs("div",{className:"form-section docker-config-section",children:[e.jsx("label",{className:"form-label",children:M("config:buildings.dockerConfig")}),e.jsxs("div",{className:"docker-mode-selector",children:[e.jsxs("label",{className:`docker-mode-option ${o==="container"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"container",checked:o==="container",onChange:()=>p("container")}),e.jsx("span",{className:"docker-mode-icon",children:"📦"}),e.jsx("span",{className:"docker-mode-label",children:"Container"}),e.jsx("span",{className:"docker-mode-desc",children:"Create a new container"})]}),e.jsxs("label",{className:`docker-mode-option ${o==="compose"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"compose",checked:o==="compose",onChange:()=>p("compose")}),e.jsx("span",{className:"docker-mode-icon",children:"🛠"}),e.jsx("span",{className:"docker-mode-label",children:"Compose"}),e.jsx("span",{className:"docker-mode-desc",children:"Manage multiple services"})]}),e.jsxs("label",{className:`docker-mode-option ${o==="existing"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"existing",checked:o==="existing",onChange:()=>p("existing")}),e.jsx("span",{className:"docker-mode-icon",children:"🔎"}),e.jsx("span",{className:"docker-mode-label",children:"Existing"}),e.jsx("span",{className:"docker-mode-desc",children:"Adopt existing container"})]})]}),o==="container"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Image:",e.jsx(j,{text:"Docker image to run, e.g., nginx:latest, redis:alpine, my-app:v1",title:"Image",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:u,onChange:l=>x(l.target.value),placeholder:"nginx:latest",required:!0})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Container Name:",e.jsx(j,{text:"Custom name for the container. If empty, auto-generated based on building name.",title:"Container Name",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:n,onChange:l=>y(l.target.value),placeholder:"Auto-generated (tc-{name}-{id})"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Command:",e.jsx(j,{text:"Override the default container command. Leave empty to use image's CMD.",title:"Command Override",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:l=>g(l.target.value),placeholder:"Optional command override"})]}),e.jsxs("div",{className:"form-section docker-ports-section",children:[e.jsxs("label",{className:"form-label",children:["Port Mappings",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>s([...v,""]),children:"+ Add"})]}),v.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const z=[...v];z[S]=U.target.value,s(z)},placeholder:"8080:80 or 3000"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>s(v.filter((U,z)=>z!==S)),children:"x"})]},S)),v.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host:container (e.g., 8080:80) or same port (e.g., 3000)"})]}),e.jsxs("div",{className:"form-section docker-volumes-section",children:[e.jsxs("label",{className:"form-label",children:["Volume Mounts",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>a([...h,""]),children:"+ Add"})]}),h.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const z=[...h];z[S]=U.target.value,a(z)},placeholder:"./data:/app/data or /host/path:/container/path"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>a(h.filter((U,z)=>z!==S)),children:"x"})]},S)),h.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host_path:container_path (relative paths resolved from working directory)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Network:",e.jsx(j,{text:"Docker network to connect to. Leave empty for default bridge network.",title:"Network",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:t,onChange:l=>r(l.target.value),placeholder:"bridge (default)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Restart Policy:",e.jsx(j,{text:"When should Docker restart the container automatically?",title:"Restart Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:i,onChange:l=>N(l.target.value),children:Object.keys(Fs).map(l=>e.jsx("option",{value:l,children:Fs[l].label},l))})]})]}),o==="compose"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Compose File:",e.jsx(j,{text:"Path to docker-compose.yml file, relative to working directory.",title:"Compose File",position:"top",size:"sm"})]}),e.jsx(Ue,{value:$,onChange:R,placeholder:"docker-compose.yml",className:"form-input",directoriesOnly:!1})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Project Name:",e.jsx(j,{text:"Override the compose project name. Leave empty for auto-generated name.",title:"Project Name",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:K,onChange:l=>I(l.target.value),placeholder:"Auto-generated"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Services:",e.jsx(j,{text:"Specific services to manage (comma-separated). Leave empty for all services.",title:"Services",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:H,onChange:l=>O(l.target.value),placeholder:"All services (or: api, db, redis)"})]})]}),o==="existing"&&e.jsxs("div",{className:"docker-existing-section",children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Select Container:",e.jsx(j,{text:"Choose an existing Docker container to monitor and control. The container will not be deleted when removing the building.",title:"Existing Container",position:"top",size:"sm"})]}),e.jsxs("div",{className:"docker-existing-select-wrapper",children:[e.jsxs("select",{className:"form-input form-select",value:c,onChange:l=>E(l.target.value),required:o==="existing",children:[e.jsx("option",{value:"",children:"Select a container..."}),q.map(l=>e.jsxs("option",{value:l.name,children:[l.name," (",l.image,") - ",l.state]},l.id))]}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.requestDockerContainersList(),title:"Refresh container list",children:"↻"})]})]}),q.length===0&&e.jsx("div",{className:"form-hint docker-existing-hint",children:"No containers found. Make sure Docker is running and you have containers available."}),c&&e.jsx("div",{className:"docker-existing-info",children:(()=>{const l=q.find(S=>S.name===c);return l?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Image:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.image})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Status:"}),e.jsx("span",{className:`docker-existing-info-value docker-status-${l.status}`,children:l.state})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"ID:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.id.slice(0,12)})]}),l.ports.length>0&&e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Ports:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.ports.map(S=>`${S.host}:${S.container}/${S.protocol}`).join(", ")})]})]}):null})()}),e.jsx("div",{className:"form-hint",children:"Note: Existing containers will not be deleted when you remove this building."})]}),o!=="existing"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Pull Policy:",e.jsx(j,{text:"When to pull images: always, only if missing, or never.",title:"Pull Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:b,onChange:l=>L(l.target.value),children:Object.keys($s).map(l=>e.jsx("option",{value:l,children:$s[l].label},l))})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:["Environment:",e.jsx(j,{text:"Environment variables in KEY=value format, one per line.",title:"Environment Variables",position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:T,onChange:l=>A(l.target.value),placeholder:`KEY=value
4
4
  DATABASE_URL=postgres://...
@@ -1,4 +1,4 @@
1
- import{bq as Oe,r as t,s as I,l as ye,br as Ee,aM as _e,j as e,I as z,u as fe,bs as ze,bt as Te,bu as Ue,bv as Be,m as Ke,bw as We,bx as De,by as Ve,a7 as qe,a8 as Ge,a9 as Je,aV as Ye,J as Me,S as ce,aP as Xe,aL as Qe,_ as Ze,K as Ie,ak as et,U as tt,bz as st,n as X,bA as nt}from"./main-Bon1sZAi.js";import{FileExplorerPanel as at}from"./index--3sQ1gHE.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ne={status:"all",activity:"all",sort:"activity"},lt={"1h":3600*1e3,"6h":360*60*1e3,"24h":1440*60*1e3},Ae=20,me=3,ct={idle:"#4aff9e",working:"#4a9eff",waiting:"#ff9e4a",waiting_permission:"#ffcc00",error:"#ff4a4a",offline:"#888888",orphaned:"#ff9e4a"},ot=12e4;function rt(s){return s.trim().replace(/\r\n/g,`
1
+ import{bq as Oe,r as t,s as I,l as ye,br as Ee,aM as _e,j as e,I as z,u as fe,bs as ze,bt as Te,bu as Ue,bv as Be,m as Ke,bw as We,bx as De,by as Ve,a7 as qe,a8 as Ge,a9 as Je,aV as Ye,J as Me,S as ce,aP as Xe,aL as Qe,_ as Ze,K as Ie,ak as et,U as tt,bz as st,n as X,bA as nt}from"./main-vfMoYhg1.js";import{FileExplorerPanel as at}from"./index-CMa6Bc5_.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ne={status:"all",activity:"all",sort:"activity"},lt={"1h":3600*1e3,"6h":360*60*1e3,"24h":1440*60*1e3},Ae=20,me=3,ct={idle:"#4aff9e",working:"#4a9eff",waiting:"#ff9e4a",waiting_permission:"#ffcc00",error:"#ff4a4a",offline:"#888888",orphaned:"#ff9e4a"},ot=12e4;function rt(s){return s.trim().replace(/\r\n/g,`
2
2
  `)}function $e(s,a){return`${s}:${rt(a)}`}function it(s,a,l,f){if(s.uuid&&a.has(s.uuid))return!1;if(s.uuid)return!0;const p=s.isUserPrompt?"user":"assistant",d=$e(p,s.text),M=s.timestamp||0,A=l.get(d);return A!==void 0&&Math.abs(M-A)<=ot?!1:M>f}function dt({isOpen:s,agents:a}){const l=Oe(),[f,p]=t.useState(new Map),d=t.useRef(new Set);t.useRef(a);const M=t.useMemo(()=>Array.from(a.keys()).sort().join(","),[a]),A=t.useMemo(()=>Array.from(a.values()).map(j=>`${j.id}:${j.sessionId||""}`).sort().join(","),[a]);t.useEffect(()=>{s||(d.current.clear(),p(new Map))},[s]),t.useEffect(()=>{if(!s)return;const j=new Set(Array.from(a.keys()));for(const i of d.current)j.has(i)||d.current.delete(i);let h=null;l>0&&(h=I.preserveOutputs(),d.current.clear());const v=async(i,C,F=0)=>{if(d.current.add(i.id),F>0&&await new Promise(x=>setTimeout(x,F)),p(x=>{const k=new Map(x);return k.set(i.id,{agentId:i.id,messages:[],loading:!0,hasMore:!1,totalCount:0}),k}),!i.sessionId){C&&C.length>0&&I.mergeOutputsWithHistory(i.id,[],C),p(x=>{const k=new Map(x);return k.set(i.id,{agentId:i.id,messages:[],loading:!1,hasMore:!1,totalCount:0}),k});return}try{const k=await(await _e(ye(`/api/agents/${i.id}/history?limit=${Ee}&offset=0`))).json(),P=k.messages||[],W=P.length>0?Math.max(...P.map(w=>w.timestamp?new Date(w.timestamp).getTime():0)):0,J=new Set(P.map(w=>w.uuid).filter(w=>!!w)),V=new Map;for(const w of P){if(w.type!=="user"&&w.type!=="assistant")continue;const o=$e(w.type,w.content),L=w.timestamp?new Date(w.timestamp).getTime():0,K=V.get(o)??0;L>K&&V.set(o,L)}const q=I.getOutputs(i.id),B=(C&&C.length>0?[...C,...q]:q).filter(w=>it(w,J,V,W));I.clearOutputs(i.id);for(const w of B)I.addOutput(i.id,w);p(w=>{const o=new Map(w);return o.set(i.id,{agentId:i.id,messages:P,loading:!1,hasMore:k.hasMore||!1,totalCount:k.totalCount||0}),o})}catch(x){if(console.error(`Failed to load history for ${i.name}:`,x),C&&C.length>0){I.clearOutputs(i.id);for(const k of C)I.addOutput(i.id,k)}p(k=>{const P=new Map(k);return P.set(i.id,{agentId:i.id,messages:[],loading:!1,hasMore:!1,totalCount:0}),P})}},u=l>0?500:0,D=Array.from(a.values());for(const i of D)if(!d.current.has(i.id)){const C=h==null?void 0:h.get(i.id);v(i,C,u)}},[s,M,A,l]);const R=t.useRef(a),N=t.useRef(f);R.current=a,N.current=f;const b=t.useCallback(async j=>{const h=R.current.get(j),v=N.current.get(j);if(!(h!=null&&h.sessionId)||!v||!v.hasMore)return;const u=v.messages.length;try{const i=await(await fetch(ye(`/api/agents/${j}/history?limit=${Ee}&offset=${u}`))).json();i.messages&&i.messages.length>0&&p(C=>{const F=new Map(C),x=C.get(j);return x&&F.set(j,{...x,messages:[...i.messages,...x.messages],hasMore:i.hasMore||!1}),F})}catch(D){console.error(`Failed to load more history for agent ${j}:`,D)}},[]),E=t.useCallback(j=>{d.current.delete(j),p(h=>{const v=new Map(h),u=h.get(j);return u&&v.set(j,{...u,messages:[],hasMore:!1,totalCount:0,loading:!1}),v})},[]);return{histories:f,loadMoreHistory:b,clearAgentHistory:E}}function ut({command:s,onCommandChange:a,useTextarea:l,forceTextarea:f,onForceTextarea:p,onSend:d,canSend:M,attachedFiles:A,onAddFile:R,onRemoveFile:N,uploadFile:b,onAddPastedText:E,placeholder:j="Message...",className:h="",compact:v=!1,inputRef:u}){const D=t.useRef(null),i=t.useRef(null),C=t.useRef(l);t.useEffect(()=>{if(l&&!C.current&&i.current){const o=i.current;o.focus(),o.selectionStart=o.selectionEnd=o.value.length}C.current=l},[l]),t.useEffect(()=>{const o=i.current;if(!o||!l)return;o.style.height="auto";const L=v?120:180,K=Math.min(o.scrollHeight,L);o.style.height=`${K}px`},[s,l,v]);const F=t.useCallback(async o=>{const L=o.clipboardData.items;for(const _ of L)if(_.type.startsWith("image/")){o.preventDefault();const $=_.getAsFile();if($){const H=await b($);H&&R(H)}return}const K=o.clipboardData.files;if(K.length>0){o.preventDefault();for(const _ of K){const $=await b(_);$&&R($)}return}const U=o.clipboardData.getData("text"),te=(U.match(/\n/g)||[]).length+1;if(te>5){o.preventDefault();const $=`[Pasted text #${E(U)} +${te} lines]`,H=o.target,se=H.selectionStart||0,ae=H.selectionEnd||0,ne=s.slice(0,se)+$+s.slice(ae);a(ne),l||p(!0)}},[s,a,l,p,b,R,E]),x=t.useCallback(async o=>{const L=o.target.files;if(L){for(const K of L){const U=await b(K);U&&R(U)}D.current&&(D.current.value="")}},[b,R]),k=t.useCallback(o=>{if(o.key==="Enter"&&o.shiftKey){l||(o.preventDefault(),p(!0));return}o.key==="Enter"&&(o.preventDefault(),d())},[l,p,d]),P=t.useCallback(o=>{},[]),W=t.useCallback(o=>{o.button===1&&(o.preventDefault(),o.stopPropagation())},[]),J=t.useCallback(o=>{i.current=o,u==null||u(o)},[u]),V=v?"agent-panel-input":"guake-input",q=v?"agent-panel-input-container":"guake-input-container",Q=v?"agent-panel-attach-btn":"guake-attach-btn",B=v?"agent-panel-send-btn":"",w=l?v?"agent-panel-input-expanded":"guake-input-expanded":"";return e.jsxs(e.Fragment,{children:[A.length>0&&e.jsx("div",{className:v?"agent-panel-attachments":"guake-attachments",children:A.map(o=>e.jsxs("div",{className:`${v?"agent-panel-attachment":"guake-attachment"} ${o.isImage?"is-image":""}`,children:[e.jsx("span",{className:v?"agent-panel-attachment-icon":"guake-attachment-icon",children:e.jsx(z,{name:o.isImage?"file":"paperclip",size:12})}),e.jsx("span",{className:v?"agent-panel-attachment-name":"guake-attachment-name",title:o.path,children:o.name}),!v&&e.jsxs("span",{className:"guake-attachment-size",children:["(",Math.round(o.size/1024),"KB)"]}),e.jsx("button",{className:v?"agent-panel-attachment-remove":"guake-attachment-remove",onClick:()=>N(o.id),title:"Remove",children:"×"})]},o.id))}),e.jsxs("div",{className:`${V} ${w} ${h}`,children:[e.jsx("input",{ref:D,type:"file",multiple:!0,onChange:x,style:{display:"none"},accept:"*"}),e.jsxs("div",{className:q,onAuxClick:W,children:[e.jsx("button",{className:Q,onClick:()=>{var o;return(o=D.current)==null?void 0:o.click()},title:"Attach file (or paste image)",children:e.jsx(z,{name:"paperclip",size:14})}),l?e.jsx("textarea",{ref:J,placeholder:j,value:s,onChange:o=>a(o.target.value),onKeyDown:k,onPaste:F,onMouseDown:P}):e.jsx("input",{ref:u,type:"text",placeholder:j,value:s,onChange:o=>a(o.target.value),onKeyDown:k,onPaste:F,onMouseDown:P}),e.jsx("button",{className:B,onClick:d,disabled:!M,title:"Send",children:e.jsx(z,{name:"send",size:14})})]})]})]})}function mt(s){const a=Math.floor(s/1e3),l=Math.floor(a/60),f=a%60;return`${l}:${f.toString().padStart(2,"0")}`}const ft=t.memo(function({agentId:a,isWorking:l,timestamp:f}){const{t:p}=fe(["terminal"]),[d,M]=t.useState(0);return t.useEffect(()=>{if(!l||!f){M(0);return}M(Date.now()-f);const A=setInterval(()=>{M(Date.now()-f)},1e3);return()=>clearInterval(A)},[l,f]),l?e.jsxs("div",{className:"guake-stop-bar",children:[e.jsx("span",{className:"guake-elapsed-timer",children:mt(d)}),e.jsxs("button",{className:"guake-stop-btn",onClick:()=>I.stopAgent(a),title:p("terminal:input.stopOperation"),children:[e.jsx("span",{className:"stop-icon",children:e.jsx(z,{name:"stop",size:12,weight:"fill"})}),e.jsx("span",{className:"stop-label",children:p("terminal:input.stop")})]})]}):null});function pt({agent:s,history:a,outputs:l,isExpanded:f,isFocused:p,advancedView:d,onExpand:M,onFocus:A,inputRef:R,onLoadMore:N,onClearHistory:b}){const{t:E}=fe(["terminal","common"]),j=ze(s.id),h=t.useRef(null),[v,u]=t.useState(!1),D=t.useRef(0),i=t.useRef(!1),[C,F]=t.useState(!0),[x,k]=t.useState(!1),[P,W]=t.useState(null),[J,V]=t.useState(null),[q,Q]=t.useState(null);Te(`commander-image-modal-${s.id}`,P!==null,()=>W(null));const{command:B,setCommand:w,forceTextarea:o,setForceTextarea:L,useTextarea:K,setPastedTexts:U,incrementPastedCount:te,resetPastedCount:_,attachedFiles:$,setAttachedFiles:H,removeAttachedFile:se,uploadFile:ae,expandPastedTexts:ne}=Ue({selectedAgentId:s.id}),le=B.trim().length>0||$.length>0,n=Be({outputs:l,viewMode:d?"advanced":"simple"}),c=t.useMemo(()=>{const S=Ke(s);return{usedPercent:S.usedPercent,freePercent:S.freePercent,hasData:!!s.contextStats,totalTokens:S.totalTokens,contextWindow:S.contextWindow}},[s.contextStats,s.contextUsed,s.contextLimit]),g=t.useCallback(()=>{!v&&(a!=null&&a.hasMore)&&N&&(u(!0),D.current=h.current?h.current.scrollHeight-h.current.scrollTop:0,N())},[v,a==null?void 0:a.hasMore,N]);t.useEffect(()=>{v&&a&&!a.loading&&u(!1)},[a,v]);const m=t.useCallback(()=>{i.current=!0,F(!1)},[]),T=t.useRef(f),Z=t.useRef(p);t.useEffect(()=>{(f&&!T.current||p&&!Z.current)&&(i.current=!1,F(!0),k(!0)),T.current=f,Z.current=p},[f,p]);const ee=t.useRef(a==null?void 0:a.loading);t.useEffect(()=>{ee.current&&!(a!=null&&a.loading)&&(i.current=!1,F(!0),k(!0)),ee.current=a==null?void 0:a.loading},[a==null?void 0:a.loading]),t.useEffect(()=>{if(!x)return;const S=h.current;if(!S)return;const y=performance.now();let O=0,ue=-1,ke;const Re=()=>{const{scrollTop:Fe,scrollHeight:Se,clientHeight:Le}=S,He=Se-Fe-Le<=2;if(Math.abs(Se-ue)<=1&&He?O+=1:O=0,ue=Se,O>=3){k(!1);return}if(performance.now()-y>5e3){k(!1);return}ke=requestAnimationFrame(Re)};return ke=requestAnimationFrame(Re),()=>cancelAnimationFrame(ke)},[x]),t.useEffect(()=>{i.current||F(!0)},[n.length]);const G=t.useCallback(()=>!1,[]),ie=t.useCallback(S=>{const y=te();return U(O=>new Map(O).set(y,S)),y},[te,U]),he=t.useCallback(S=>{H(y=>[...y,S])},[H]),xe=t.useCallback(()=>{if(!le)return;if(B.trim()==="/clear"&&$.length===0){I.clearContext(s.id),b(),w(""),L(!1),U(new Map),H([]),_();return}let S=ne(B.trim());if($.length>0){const y=$.map(O=>O.isImage?`[Image: ${O.path}]`:`[File: ${O.path}]`).join(`
3
3
  `);S=S?`${S}
4
4
 
@@ -1,4 +1,4 @@
1
- import{r as l,aW as Re,aX as Ye,j as e,I as L,u as Y,aY as as,a3 as ns,f as Ve,s as E,aZ as ms,k as is,l as he,a_ as Z,a$ as gs,aP as fs,b0 as xs,C as me,b1 as J,aM as we,b2 as bs,b3 as js,b4 as ws,b5 as ys,b6 as Se,b7 as os,b8 as Ns,b9 as Me,ba as vs,bb as ks,bc as Ss,bd as Cs,be as Ts,bf as As,bg as _s,aI as Es,J as Is,S as ke,bh as Ps,bi as $s,aK as Ls,bj as Ue,K as Ie,aT as Ds,bk as ze,bl as Fs}from"./main-Bon1sZAi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ke="deivid11/tide-commander",Os=`https://api.github.com/repos/${Ke}/releases/latest`,Rs=`https://api.github.com/repos/${Ke}/releases?per_page=3`,Us=3600*1e3,Je="app_update_dismissed_version",Ze="1.111.2";function zs(){var w,C;const[s,a]=l.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:Ze}),t=((C=(w=Re)==null?void 0:w.getPlatform)==null?void 0:C.call(w))==="android"||!1,o=u=>u.replace(/^v/,"").split(".").map(m=>parseInt(m,10)||0),r=(u,p)=>{const m=o(u),j=o(p),b=Math.max(m.length,j.length);for(let h=0;h<b;h++){const k=m[h]||0,$=j[h]||0;if(k>$)return 1;if(k<$)return-1}return 0},d=async u=>{var m,j;if(Re&&Ye&&((j=(m=Re).isNativePlatform)==null?void 0:j.call(m))===!0){const b=await Ye.get({url:u,headers:{Accept:"application/vnd.github.v3+json"}});return{data:b.data,status:b.status}}else{const b=await fetch(u,{headers:{Accept:"application/vnd.github.v3+json"}});return b.ok?{data:await b.json(),status:b.status}:{data:null,status:b.status}}},c=l.useCallback(async(u=!1)=>{a(p=>({...p,isChecking:!0,error:null}));try{const[p,m]=await Promise.all([d(Os),d(Rs)]);if(p.status!==200)throw new Error(`GitHub API error: ${p.status}`);const j=p.data,b=j.tag_name;let h=[];m.status===200&&m.data&&(h=m.data.map(y=>({version:y.tag_name,name:y.name,publishedAt:y.published_at,releaseUrl:y.html_url})));const k=localStorage.getItem(Je);if(!u&&k===b)return a(y=>({...y,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;if(!(r(b,Ze)>0))return a(y=>({...y,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;const P=j.assets.find(y=>y.name.endsWith(".apk")&&y.content_type==="application/vnd.android.package-archive"),K={version:b,name:j.name,changelog:j.body,releaseUrl:j.html_url,apkUrl:(P==null?void 0:P.browser_download_url)||null,apkSize:(P==null?void 0:P.size)||null,publishedAt:j.published_at};return a(y=>({...y,isChecking:!1,updateAvailable:!0,updateInfo:K,recentReleases:h})),K}catch(p){const m=p instanceof Error?p.message:"Failed to check for updates";return a(j=>({...j,isChecking:!1,error:m})),null}},[]),g=l.useCallback(async()=>{var u,p,m;if(!((u=s.updateInfo)!=null&&u.apkUrl)){(p=s.updateInfo)!=null&&p.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}if(!t){(m=s.updateInfo)!=null&&m.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}try{window.open(s.updateInfo.apkUrl,"_system"),a(j=>({...j,error:null}))}catch(j){const b=j instanceof Error?j.message:"Failed to open download";a(h=>({...h,error:b}))}},[s.updateInfo,t]),n=l.useCallback(()=>{s.updateInfo&&localStorage.setItem(Je,s.updateInfo.version),a(u=>({...u,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),x=l.useCallback(()=>{var u;(u=s.updateInfo)!=null&&u.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${Ke}/releases`,"_blank")},[s.updateInfo]);return l.useEffect(()=>{if(!t)return;const u=setTimeout(()=>{c()},5e3),p=setInterval(()=>{c()},Us);return()=>{clearTimeout(u),clearInterval(p)}},[t,c]),{...s,isAndroid:t,checkForUpdate:c,downloadAndInstall:g,dismissUpdate:n,openReleasePage:x}}const ls="tide-toolbox-collapse";function Bs(s,a){try{const t=localStorage.getItem(`${ls}-${s}`);if(t!==null)return t==="true"}catch{}return a}function Ms(s,a){try{localStorage.setItem(`${ls}-${s}`,String(a))}catch{}}function W({title:s,storageKey:a,defaultOpen:t=!1,forceOpen:o=!1,children:r,headerExtra:d}){const[c,g]=l.useState(()=>a?Bs(a,t):t),n=()=>{const w=!c;g(w),a&&Ms(a,w)},x=o||c;return e.jsxs("div",{className:`collapsible-section ${x?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:n,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[d,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(L,{name:x?"caret-down":"caret-right",size:10})})]})]}),x&&e.jsx("div",{className:"collapsible-content",children:r})]})}function Vs({area:s,isSelected:a,onClick:t,onDelete:o}){const{t:r}=Y(["config","common"]),d=s.assignedAgentIds.length,c=s.type==="rectangle"?r("config:areas.rect"):r("config:areas.circle");return e.jsxs("div",{className:`area-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"area-color-dot",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"area-info",children:[e.jsx("div",{className:"area-name",children:s.name}),e.jsxs("div",{className:"area-meta",children:[c," ",d>0&&`• ${d} ${d>1?r("common:labels.agents").toLowerCase():r("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:r("config:areas.deleteArea"),children:"×"})]})}function Ks({building:s,isSelected:a,onClick:t,onEdit:o}){var g;const{t:r}=Y(["config"]),d=((g=s.pm2Status)==null?void 0:g.ports)||[],c=(n,x)=>{n.stopPropagation(),window.open(`http://${window.location.hostname}:${x}`,"_blank")};return e.jsxs("div",{className:`building-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:as[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(L,{name:ns(s.type),size:16})}),e.jsxs("div",{className:"building-info",children:[e.jsx("div",{className:"building-name",children:s.name}),e.jsxs("div",{className:"building-meta",children:[s.type,d.length>0&&e.jsx("span",{className:"building-ports",children:d.map(n=>e.jsxs("a",{href:`http://${window.location.hostname}:${n}`,className:"building-port-link",onClick:x=>c(x,n),title:`Open :${n}`,children:[":",n]},n))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:n=>{n.stopPropagation(),o()},title:r("config:buildings.editBuilding"),children:e.jsx(L,{name:"gear",size:14})})]})}function Hs({building:s,onClose:a,onOpenModal:t}){var x,w,C,u,p,m,j,b;const{t:o}=Y(["config","common"]),{buildingLogs:r}=Ve(),d=E.getBuildingLogs(s.id),c=ms[s.style||"server-rack"],g=h=>{E.sendBuildingCommand(s.id,h)},n=h=>{window.open(h,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:e.jsx(L,{name:ns(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:as[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:a,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("common:labels.type")}),e.jsx("span",{className:"building-editor-info-value",children:s.type})]}),e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:c.label})]}),s.cwd&&e.jsxs("div",{className:"building-editor-info-item building-editor-info-wide",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.directory")}),e.jsx("span",{className:"building-editor-info-value building-editor-cwd",title:s.cwd,children:s.cwd.split("/").pop()||s.cwd})]})]})}),s.type==="server"&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>g("start"),disabled:!((x=s.commands)!=null&&x.start)||s.status==="running",title:((w=s.commands)==null?void 0:w.start)||o("config:buildings.noStartCommand"),children:[e.jsx(L,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>g("stop"),disabled:!((C=s.commands)!=null&&C.stop)||s.status==="stopped",title:((u=s.commands)==null?void 0:u.stop)||o("config:buildings.noStopCommand"),children:[e.jsx(L,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>g("restart"),disabled:!((p=s.commands)!=null&&p.restart),title:((m=s.commands)==null?void 0:m.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx(L,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>g("healthCheck"),disabled:!((j=s.commands)!=null&&j.healthCheck),title:((b=s.commands)==null?void 0:b.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx(L,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((h,k)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>n(h.url),title:h.url,children:[e.jsx(L,{name:"link",size:12})," ",h.label||h.url]},k))})]}),d.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[o("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>E.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:d.slice(-5).map((h,k)=>e.jsx("div",{className:"building-editor-log-entry",children:h},k))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(L,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}async function Ws(s,a){const t=Z(),o=await fetch(he(`/api/areas/${s}/logo`),{method:"POST",headers:{"Content-Type":a.type||"image/png","X-Filename":encodeURIComponent(a.name),...t?{Authorization:`Bearer ${t}`}:{}},body:a});if(!o.ok){const r=await o.json().catch(()=>({error:o.statusText}));throw new Error(r.error||`Upload failed: ${o.statusText}`)}return o.json()}async function qs(s){const a=Z(),t=await fetch(he(`/api/areas/${s}/logo`),{method:"DELETE",headers:{...a?{Authorization:`Bearer ${a}`}:{}}});if(!t.ok)throw new Error(`Failed to delete logo: ${t.statusText}`)}function Gs(s){return is(he(`/api/areas/logos/${s}`))}const Ys=[{key:"center",labelKey:"posCenter"},{key:"top-left",labelKey:"posTopLeft"},{key:"top-right",labelKey:"posTopRight"},{key:"bottom-left",labelKey:"posBottomLeft"},{key:"bottom-right",labelKey:"posBottomRight"}];function Js({area:s,onClose:a,onOpenFolder:t}){var ie;const{t:o}=Y(["config","common"]),[r,d]=l.useState(s.name),[c,g]=l.useState(s.prompt||""),[n,x]=l.useState(!1),[w,C]=l.useState(""),[u,p]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{d(s.name)},[s.id,s.name]),l.useEffect(()=>{g(s.prompt||"")},[s.id,s.prompt]);const j=v=>{const F=v.target.value;d(F),E.updateArea(s.id,{name:F})},b=v=>{E.updateArea(s.id,{color:v})},h=v=>{const F=v.target.value;g(F),E.updateArea(s.id,{prompt:F})},k=()=>{w.trim()&&(E.addDirectoryToArea(s.id,w.trim()),C(""),x(!1))},$=(v,F)=>{F.stopPropagation(),E.removeDirectoryFromArea(s.id,v)},P=()=>{E.bringAreaToFront(s.id)},K=()=>{E.sendAreaToBack(s.id)},y=l.useCallback(()=>{let v=2,F=2;s.type==="rectangle"&&s.width&&s.height?(v=s.width,F=s.height):s.type==="circle"&&s.radius&&(v=s.radius*1.414,F=s.radius*1.414);const M=Math.min(v,F)*.4;return{width:Math.round(M*10)/10,height:Math.round(M*10)/10}},[s.type,s.width,s.height,s.radius]),U=async v=>{var M;const F=(M=v.target.files)==null?void 0:M[0];if(F){p(!0);try{const N=await Ws(s.id,F),D=y();E.updateArea(s.id,{logo:{filename:N.filename,position:"center",width:D.width,height:D.height,keepAspectRatio:!0,opacity:.8}})}catch(N){console.error("Failed to upload logo:",N)}finally{p(!1),m.current&&(m.current.value="")}}},B=async()=>{try{await qs(s.id),E.updateArea(s.id,{logo:void 0})}catch(v){console.error("Failed to remove logo:",v)}},V=v=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,position:v}})},S=v=>{if(!s.logo)return;const F=parseFloat(v.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const M=s.logo.height/s.logo.width;E.updateArea(s.id,{logo:{...s.logo,width:F,height:Math.round(F*M*10)/10}})}else E.updateArea(s.id,{logo:{...s.logo,width:F}})},T=v=>{if(!s.logo)return;const F=parseFloat(v.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const M=s.logo.width/s.logo.height;E.updateArea(s.id,{logo:{...s.logo,height:F,width:Math.round(F*M*10)/10}})}else E.updateArea(s.id,{logo:{...s.logo,height:F}})},H=()=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},X=v=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(v.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children:o("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:a,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:r,onChange:j,placeholder:o("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:gs.map(v=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===v?"selected":""}`,style:{backgroundColor:v},onClick:()=>b(v),"aria-label":`Set area color ${v}`,"aria-pressed":s.color===v,title:v},v))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:P,title:o("config:areas.bringToFront"),children:[e.jsx(L,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:K,title:o("config:areas.sendToBack"),children:[e.jsx(L,{name:"arrow-down",size:12})," ",o("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(ie=s.logo)!=null&&ie.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:Gs(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:B,children:o("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var v;return(v=m.current)==null?void 0:v.click()},disabled:u,children:u?"...":e.jsx(L,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:Ys.map(({key:v,labelKey:F})=>{var M;return e.jsx("button",{className:`area-logo-pos-btn ${((M=s.logo)==null?void 0:M.position)===v?"active":""}`,onClick:()=>V(v),children:o(`config:areas.${F}`)},v)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoSize")}),e.jsxs("div",{className:"area-logo-size-row",children:[e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:S,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:T,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:o("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:H}),o("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoOpacity")}),e.jsxs("div",{className:"area-logo-opacity-row",children:[e.jsx("input",{type:"range",min:0,max:1,step:.05,value:s.logo.opacity??.8,onChange:X,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var v;return(v=m.current)==null?void 0:v.click()},disabled:u,children:u?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:m,type:"file",accept:"image/*",style:{display:"none"},onChange:U})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(v=>e.jsxs("div",{className:"area-folder-item",title:v,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:o("config:areas.openFolder"),children:e.jsx(L,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:v.split("/").pop()||v}),e.jsx("button",{className:"area-folder-remove",onClick:F=>$(v,F),title:o("config:areas.removeFolder"),children:"×"})]},v)),n?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(fs,{value:w,onChange:C,onSubmit:k,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:k,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>x(!0),children:o("config:areas.addFolder")})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:c,onChange:h,placeholder:o("config:areas.promptPlaceholder","System prompt for agents in this area..."),rows:4,style:{resize:"vertical",fontFamily:"monospace",fontSize:12}}),e.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:o("config:areas.promptHint","This prompt is injected into agents assigned to this area. Takes effect on next context refresh.")})]}),s.assignedAgentIds.length>0&&e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:o("config:areas.rightClickUnassign")})]})]})}function Zs(){const{t:s}=Y(["config","common"]),a=xs(),[t,o]=l.useState(!1),[r,d]=l.useState(null),[c,g]=l.useState({name:"",key:"",value:"",description:""}),[n,x]=l.useState(null),w=()=>{o(!0),d(null),g({name:"",key:"",value:"",description:""})},C=h=>{d(h.id),o(!1),g({name:h.name,key:h.key,value:h.value,description:h.description||""})},u=()=>{o(!1),d(null),g({name:"",key:"",value:"",description:""})},p=()=>{!c.name.trim()||!c.key.trim()||(r?E.updateSecret(r,{name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}):E.createSecret({name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}),u())},m=h=>{x(h)},j=()=>{n&&(E.deleteSecret(n),r===n&&u())},b=h=>{navigator.clipboard.writeText(`{{${h}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children:a.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):a.map(h=>e.jsxs("div",{className:`secret-item ${r===h.id?"editing":""}`,children:[e.jsxs("div",{className:"secret-item-header",children:[e.jsxs("div",{className:"secret-item-info",children:[e.jsx("span",{className:"secret-item-name",children:h.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>b(h.key),title:s("config:secrets.copyPlaceholder"),children:`{{${h.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>C(h),title:s("common:buttons.edit"),children:e.jsx(L,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>m(h.id),title:s("common:buttons.delete"),children:"×"})]})]}),h.description&&e.jsx("div",{className:"secret-item-description",children:h.description})]},h.id))}),(t||r)&&e.jsxs("div",{className:"secret-form",children:[e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.name")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.namePlaceholder"),value:c.name,onChange:h=>g({...c,name:h.target.value}),autoFocus:!0})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:"Key"}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.keyPlaceholder"),value:c.key,onChange:h=>g({...c,key:h.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${c.key||"KEY"}}}`})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("config:secrets.secretValue")}),e.jsx("input",{type:"password",className:"secret-form-input",placeholder:s("config:secrets.valuePlaceholder"),value:c.value,onChange:h=>g({...c,value:h.target.value})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.description")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.descriptionPlaceholder"),value:c.description,onChange:h=>g({...c,description:h.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:u,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:p,disabled:!c.name.trim()||!c.key.trim(),children:s(r?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!r&&e.jsx("button",{className:"secrets-add-btn",onClick:w,children:s("config:secrets.addSecret")}),e.jsx(me,{isOpen:n!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:j,onClose:()=>x(null)})]})}async function Xs(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch system prompt: ${a.statusText}`);return(await a.json()).prompt||""}async function Qs(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function et(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to clear system prompt: ${a.statusText}`)}async function st(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch echo prompt setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function tt(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function at(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch codex binary path: ${a.statusText}`);return(await a.json()).path||""}async function nt(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function it(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch tmux mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function ot(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function lt(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch backup status: ${a.statusText}`);return a.json()}async function ct(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function rt({checked:s,onChange:a,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:o=>a(o.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function dt(){const{t:s}=Y(["config","common"]),[a,t]=l.useState([]),[o,r]=l.useState(new Set),[d,c]=l.useState(new Set),[g,n]=l.useState(!1),[x,w]=l.useState(!1),[C,u]=l.useState(null),[p,m]=l.useState(null),[j,b]=l.useState(null),[h,k]=l.useState(null),[$,P]=l.useState(!1),[K,y]=l.useState(null);l.useEffect(()=>{we(he("/api/config/categories")).then(N=>N.json()).then(N=>{const D=Array.isArray(N)?N:[];t(D),r(new Set(D.map(O=>O.id)))}).catch(N=>console.error("Failed to fetch config categories:",N))},[]),l.useEffect(()=>{lt().then(k).catch(N=>{console.error("Failed to fetch backup status:",N),y(N.message||"Failed to fetch backup status")})},[]);const U=async N=>{if(!$){P(!0),y(null);try{const D=await ct(N);k(D)}catch(D){y(D.message||"Failed to update backup setting")}finally{P(!1)}}},B=N=>{r(D=>{const O=new Set(D);return O.has(N)?O.delete(N):O.add(N),O})},V=N=>{c(D=>{const O=new Set(D);return O.has(N)?O.delete(N):O.add(N),O})},S=()=>r(new Set(a.map(N=>N.id))),T=()=>r(new Set),H=()=>{p&&c(new Set(p.categories.map(N=>N.id)))},X=()=>c(new Set),ie=async()=>{var N;if(o.size!==0){n(!0),b(null);try{const D=Array.from(o).join(","),O=await we(he(`/api/config/export?categories=${D}`));if(!O.ok)throw new Error("Export failed");const ee=await O.blob(),se=window.URL.createObjectURL(ee),Q=document.createElement("a");Q.href=se;const A=O.headers.get("Content-Disposition"),q=((N=A==null?void 0:A.match(/filename="(.+)"/))==null?void 0:N[1])||"tide-commander-config.zip";Q.download=q,document.body.appendChild(Q),Q.click(),document.body.removeChild(Q),window.URL.revokeObjectURL(se),b({type:"success",text:s("config:data.exportSuccess")})}catch(D){b({type:"error",text:D.message||"Export failed"})}finally{n(!1)}}},v=async N=>{var O;const D=(O=N.target.files)==null?void 0:O[0];if(D){u(D),b(null),m(null),c(new Set);try{const ee=await we(he("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await D.arrayBuffer()});if(!ee.ok){const A=await ee.json();throw new Error(A.error||"Failed to preview config file")}const se=await ee.json(),Q=Array.isArray(se.categories)?se.categories:[];m({...se,categories:Q}),c(new Set(Q.map(A=>A.id)))}catch(ee){b({type:"error",text:ee.message||"Failed to read config file"}),u(null)}}},F=async()=>{if(!(!C||d.size===0)){w(!0),b(null);try{const N=Array.from(d).join(","),D=await we(he(`/api/config/import?categories=${N}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await C.arrayBuffer()}),O=await D.json();if(!D.ok)throw new Error(O.error||"Import failed");b({type:"success",text:O.message||s("config:data.importSuccess")}),u(null),m(null),c(new Set)}catch(N){b({type:"error",text:N.message||"Import failed"})}finally{w(!1)}}},M=()=>{u(null),m(null),c(new Set),b(null)};return e.jsxs("div",{className:"data-section",children:[j&&e.jsx("div",{className:`data-message data-message-${j.type}`,children:j.text}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:"Hourly Backups"}),e.jsx(rt,{checked:!!(h!=null&&h.enabled),disabled:$||!h,onChange:U})]}),e.jsxs("div",{className:"data-backup-info",children:[h?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:h.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!h.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:h.scriptPath})]}),h.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(h.lastRunAt).toLocaleString(),h.lastRunOk===!0&&" — ok",h.lastRunOk===!1&&h.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",h.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),K&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:K})]})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:S,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:T,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:a.map(N=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(N.id),onChange:()=>B(N.id)}),e.jsx("span",{className:"data-category-name",children:N.name})]},N.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ie,disabled:g||o.size===0,children:g?s("config:data.exporting"):s("config:data.exportCount",{count:o.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),C?p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:C.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(p.exportedAt).toLocaleDateString()]})]}),e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-subtitle",children:s("config:data.selectToImport")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:H,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:X,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:p.categories.map(N=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:d.has(N.id),onChange:()=>V(N.id)}),e.jsx("span",{className:"data-category-name",children:N.name}),N.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",N.fileCount," ",s("config:data.files"),")"]})]},N.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:M,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:F,disabled:x||d.size===0,children:x?s("config:data.importing"):s("config:data.importCount",{count:d.size})})]})]}):e.jsx("div",{className:"data-loading",children:s("config:data.readingFile")}):e.jsxs("label",{className:"data-file-input",children:[e.jsx("input",{type:"file",accept:".zip",onChange:v,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}async function ut(){const s=await we(`${J()}/api/system/install-info`);if(!s.ok)throw new Error(`Failed to fetch install info: ${s.statusText}`);return s.json()}function pt(s,a){const t=new AbortController;return(async()=>{try{const o=await fetch(is(`${J()}/api/system/self-update`),{method:"POST",signal:t.signal,headers:{Accept:"text/event-stream"}});if(!o.ok||!o.body){const g=await o.text().catch(()=>"");let n=null;try{n=JSON.parse(g)}catch{}const x=n&&typeof n=="object"&&"error"in n&&typeof n.error=="string"?n.error:`Self-update failed: ${o.status} ${o.statusText}`;s({type:"error",message:x}),a(new Error(x));return}const r=o.body.getReader(),d=new TextDecoder("utf-8");let c="";for(;;){const{value:g,done:n}=await r.read();if(n)break;c+=d.decode(g,{stream:!0});let x=c.indexOf(`
1
+ import{r as l,aW as Re,aX as Ye,j as e,I as L,u as Y,aY as as,a3 as ns,f as Ve,s as E,aZ as ms,k as is,l as he,a_ as Z,a$ as gs,aP as fs,b0 as xs,C as me,b1 as J,aM as we,b2 as bs,b3 as js,b4 as ws,b5 as ys,b6 as Se,b7 as os,b8 as Ns,b9 as Me,ba as vs,bb as ks,bc as Ss,bd as Cs,be as Ts,bf as As,bg as _s,aI as Es,J as Is,S as ke,bh as Ps,bi as $s,aK as Ls,bj as Ue,K as Ie,aT as Ds,bk as ze,bl as Fs}from"./main-vfMoYhg1.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ke="deivid11/tide-commander",Os=`https://api.github.com/repos/${Ke}/releases/latest`,Rs=`https://api.github.com/repos/${Ke}/releases?per_page=3`,Us=3600*1e3,Je="app_update_dismissed_version",Ze="1.113.0";function zs(){var w,C;const[s,a]=l.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:Ze}),t=((C=(w=Re)==null?void 0:w.getPlatform)==null?void 0:C.call(w))==="android"||!1,o=u=>u.replace(/^v/,"").split(".").map(m=>parseInt(m,10)||0),r=(u,p)=>{const m=o(u),j=o(p),b=Math.max(m.length,j.length);for(let h=0;h<b;h++){const k=m[h]||0,$=j[h]||0;if(k>$)return 1;if(k<$)return-1}return 0},d=async u=>{var m,j;if(Re&&Ye&&((j=(m=Re).isNativePlatform)==null?void 0:j.call(m))===!0){const b=await Ye.get({url:u,headers:{Accept:"application/vnd.github.v3+json"}});return{data:b.data,status:b.status}}else{const b=await fetch(u,{headers:{Accept:"application/vnd.github.v3+json"}});return b.ok?{data:await b.json(),status:b.status}:{data:null,status:b.status}}},c=l.useCallback(async(u=!1)=>{a(p=>({...p,isChecking:!0,error:null}));try{const[p,m]=await Promise.all([d(Os),d(Rs)]);if(p.status!==200)throw new Error(`GitHub API error: ${p.status}`);const j=p.data,b=j.tag_name;let h=[];m.status===200&&m.data&&(h=m.data.map(y=>({version:y.tag_name,name:y.name,publishedAt:y.published_at,releaseUrl:y.html_url})));const k=localStorage.getItem(Je);if(!u&&k===b)return a(y=>({...y,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;if(!(r(b,Ze)>0))return a(y=>({...y,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;const P=j.assets.find(y=>y.name.endsWith(".apk")&&y.content_type==="application/vnd.android.package-archive"),K={version:b,name:j.name,changelog:j.body,releaseUrl:j.html_url,apkUrl:(P==null?void 0:P.browser_download_url)||null,apkSize:(P==null?void 0:P.size)||null,publishedAt:j.published_at};return a(y=>({...y,isChecking:!1,updateAvailable:!0,updateInfo:K,recentReleases:h})),K}catch(p){const m=p instanceof Error?p.message:"Failed to check for updates";return a(j=>({...j,isChecking:!1,error:m})),null}},[]),g=l.useCallback(async()=>{var u,p,m;if(!((u=s.updateInfo)!=null&&u.apkUrl)){(p=s.updateInfo)!=null&&p.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}if(!t){(m=s.updateInfo)!=null&&m.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}try{window.open(s.updateInfo.apkUrl,"_system"),a(j=>({...j,error:null}))}catch(j){const b=j instanceof Error?j.message:"Failed to open download";a(h=>({...h,error:b}))}},[s.updateInfo,t]),n=l.useCallback(()=>{s.updateInfo&&localStorage.setItem(Je,s.updateInfo.version),a(u=>({...u,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),x=l.useCallback(()=>{var u;(u=s.updateInfo)!=null&&u.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${Ke}/releases`,"_blank")},[s.updateInfo]);return l.useEffect(()=>{if(!t)return;const u=setTimeout(()=>{c()},5e3),p=setInterval(()=>{c()},Us);return()=>{clearTimeout(u),clearInterval(p)}},[t,c]),{...s,isAndroid:t,checkForUpdate:c,downloadAndInstall:g,dismissUpdate:n,openReleasePage:x}}const ls="tide-toolbox-collapse";function Bs(s,a){try{const t=localStorage.getItem(`${ls}-${s}`);if(t!==null)return t==="true"}catch{}return a}function Ms(s,a){try{localStorage.setItem(`${ls}-${s}`,String(a))}catch{}}function W({title:s,storageKey:a,defaultOpen:t=!1,forceOpen:o=!1,children:r,headerExtra:d}){const[c,g]=l.useState(()=>a?Bs(a,t):t),n=()=>{const w=!c;g(w),a&&Ms(a,w)},x=o||c;return e.jsxs("div",{className:`collapsible-section ${x?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:n,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[d,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(L,{name:x?"caret-down":"caret-right",size:10})})]})]}),x&&e.jsx("div",{className:"collapsible-content",children:r})]})}function Vs({area:s,isSelected:a,onClick:t,onDelete:o}){const{t:r}=Y(["config","common"]),d=s.assignedAgentIds.length,c=s.type==="rectangle"?r("config:areas.rect"):r("config:areas.circle");return e.jsxs("div",{className:`area-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"area-color-dot",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"area-info",children:[e.jsx("div",{className:"area-name",children:s.name}),e.jsxs("div",{className:"area-meta",children:[c," ",d>0&&`• ${d} ${d>1?r("common:labels.agents").toLowerCase():r("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:r("config:areas.deleteArea"),children:"×"})]})}function Ks({building:s,isSelected:a,onClick:t,onEdit:o}){var g;const{t:r}=Y(["config"]),d=((g=s.pm2Status)==null?void 0:g.ports)||[],c=(n,x)=>{n.stopPropagation(),window.open(`http://${window.location.hostname}:${x}`,"_blank")};return e.jsxs("div",{className:`building-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:as[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(L,{name:ns(s.type),size:16})}),e.jsxs("div",{className:"building-info",children:[e.jsx("div",{className:"building-name",children:s.name}),e.jsxs("div",{className:"building-meta",children:[s.type,d.length>0&&e.jsx("span",{className:"building-ports",children:d.map(n=>e.jsxs("a",{href:`http://${window.location.hostname}:${n}`,className:"building-port-link",onClick:x=>c(x,n),title:`Open :${n}`,children:[":",n]},n))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:n=>{n.stopPropagation(),o()},title:r("config:buildings.editBuilding"),children:e.jsx(L,{name:"gear",size:14})})]})}function Hs({building:s,onClose:a,onOpenModal:t}){var x,w,C,u,p,m,j,b;const{t:o}=Y(["config","common"]),{buildingLogs:r}=Ve(),d=E.getBuildingLogs(s.id),c=ms[s.style||"server-rack"],g=h=>{E.sendBuildingCommand(s.id,h)},n=h=>{window.open(h,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:e.jsx(L,{name:ns(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:as[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:a,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("common:labels.type")}),e.jsx("span",{className:"building-editor-info-value",children:s.type})]}),e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:c.label})]}),s.cwd&&e.jsxs("div",{className:"building-editor-info-item building-editor-info-wide",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.directory")}),e.jsx("span",{className:"building-editor-info-value building-editor-cwd",title:s.cwd,children:s.cwd.split("/").pop()||s.cwd})]})]})}),s.type==="server"&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>g("start"),disabled:!((x=s.commands)!=null&&x.start)||s.status==="running",title:((w=s.commands)==null?void 0:w.start)||o("config:buildings.noStartCommand"),children:[e.jsx(L,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>g("stop"),disabled:!((C=s.commands)!=null&&C.stop)||s.status==="stopped",title:((u=s.commands)==null?void 0:u.stop)||o("config:buildings.noStopCommand"),children:[e.jsx(L,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>g("restart"),disabled:!((p=s.commands)!=null&&p.restart),title:((m=s.commands)==null?void 0:m.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx(L,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>g("healthCheck"),disabled:!((j=s.commands)!=null&&j.healthCheck),title:((b=s.commands)==null?void 0:b.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx(L,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((h,k)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>n(h.url),title:h.url,children:[e.jsx(L,{name:"link",size:12})," ",h.label||h.url]},k))})]}),d.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[o("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>E.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:d.slice(-5).map((h,k)=>e.jsx("div",{className:"building-editor-log-entry",children:h},k))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(L,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}async function Ws(s,a){const t=Z(),o=await fetch(he(`/api/areas/${s}/logo`),{method:"POST",headers:{"Content-Type":a.type||"image/png","X-Filename":encodeURIComponent(a.name),...t?{Authorization:`Bearer ${t}`}:{}},body:a});if(!o.ok){const r=await o.json().catch(()=>({error:o.statusText}));throw new Error(r.error||`Upload failed: ${o.statusText}`)}return o.json()}async function qs(s){const a=Z(),t=await fetch(he(`/api/areas/${s}/logo`),{method:"DELETE",headers:{...a?{Authorization:`Bearer ${a}`}:{}}});if(!t.ok)throw new Error(`Failed to delete logo: ${t.statusText}`)}function Gs(s){return is(he(`/api/areas/logos/${s}`))}const Ys=[{key:"center",labelKey:"posCenter"},{key:"top-left",labelKey:"posTopLeft"},{key:"top-right",labelKey:"posTopRight"},{key:"bottom-left",labelKey:"posBottomLeft"},{key:"bottom-right",labelKey:"posBottomRight"}];function Js({area:s,onClose:a,onOpenFolder:t}){var ie;const{t:o}=Y(["config","common"]),[r,d]=l.useState(s.name),[c,g]=l.useState(s.prompt||""),[n,x]=l.useState(!1),[w,C]=l.useState(""),[u,p]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{d(s.name)},[s.id,s.name]),l.useEffect(()=>{g(s.prompt||"")},[s.id,s.prompt]);const j=v=>{const F=v.target.value;d(F),E.updateArea(s.id,{name:F})},b=v=>{E.updateArea(s.id,{color:v})},h=v=>{const F=v.target.value;g(F),E.updateArea(s.id,{prompt:F})},k=()=>{w.trim()&&(E.addDirectoryToArea(s.id,w.trim()),C(""),x(!1))},$=(v,F)=>{F.stopPropagation(),E.removeDirectoryFromArea(s.id,v)},P=()=>{E.bringAreaToFront(s.id)},K=()=>{E.sendAreaToBack(s.id)},y=l.useCallback(()=>{let v=2,F=2;s.type==="rectangle"&&s.width&&s.height?(v=s.width,F=s.height):s.type==="circle"&&s.radius&&(v=s.radius*1.414,F=s.radius*1.414);const M=Math.min(v,F)*.4;return{width:Math.round(M*10)/10,height:Math.round(M*10)/10}},[s.type,s.width,s.height,s.radius]),U=async v=>{var M;const F=(M=v.target.files)==null?void 0:M[0];if(F){p(!0);try{const N=await Ws(s.id,F),D=y();E.updateArea(s.id,{logo:{filename:N.filename,position:"center",width:D.width,height:D.height,keepAspectRatio:!0,opacity:.8}})}catch(N){console.error("Failed to upload logo:",N)}finally{p(!1),m.current&&(m.current.value="")}}},B=async()=>{try{await qs(s.id),E.updateArea(s.id,{logo:void 0})}catch(v){console.error("Failed to remove logo:",v)}},V=v=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,position:v}})},S=v=>{if(!s.logo)return;const F=parseFloat(v.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const M=s.logo.height/s.logo.width;E.updateArea(s.id,{logo:{...s.logo,width:F,height:Math.round(F*M*10)/10}})}else E.updateArea(s.id,{logo:{...s.logo,width:F}})},T=v=>{if(!s.logo)return;const F=parseFloat(v.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const M=s.logo.width/s.logo.height;E.updateArea(s.id,{logo:{...s.logo,height:F,width:Math.round(F*M*10)/10}})}else E.updateArea(s.id,{logo:{...s.logo,height:F}})},H=()=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},X=v=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(v.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children:o("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:a,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:r,onChange:j,placeholder:o("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:gs.map(v=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===v?"selected":""}`,style:{backgroundColor:v},onClick:()=>b(v),"aria-label":`Set area color ${v}`,"aria-pressed":s.color===v,title:v},v))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:P,title:o("config:areas.bringToFront"),children:[e.jsx(L,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:K,title:o("config:areas.sendToBack"),children:[e.jsx(L,{name:"arrow-down",size:12})," ",o("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(ie=s.logo)!=null&&ie.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:Gs(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:B,children:o("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var v;return(v=m.current)==null?void 0:v.click()},disabled:u,children:u?"...":e.jsx(L,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:Ys.map(({key:v,labelKey:F})=>{var M;return e.jsx("button",{className:`area-logo-pos-btn ${((M=s.logo)==null?void 0:M.position)===v?"active":""}`,onClick:()=>V(v),children:o(`config:areas.${F}`)},v)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoSize")}),e.jsxs("div",{className:"area-logo-size-row",children:[e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:S,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:T,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:o("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:H}),o("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoOpacity")}),e.jsxs("div",{className:"area-logo-opacity-row",children:[e.jsx("input",{type:"range",min:0,max:1,step:.05,value:s.logo.opacity??.8,onChange:X,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var v;return(v=m.current)==null?void 0:v.click()},disabled:u,children:u?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:m,type:"file",accept:"image/*",style:{display:"none"},onChange:U})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(v=>e.jsxs("div",{className:"area-folder-item",title:v,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:o("config:areas.openFolder"),children:e.jsx(L,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:v.split("/").pop()||v}),e.jsx("button",{className:"area-folder-remove",onClick:F=>$(v,F),title:o("config:areas.removeFolder"),children:"×"})]},v)),n?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(fs,{value:w,onChange:C,onSubmit:k,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:k,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>x(!0),children:o("config:areas.addFolder")})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:c,onChange:h,placeholder:o("config:areas.promptPlaceholder","System prompt for agents in this area..."),rows:4,style:{resize:"vertical",fontFamily:"monospace",fontSize:12}}),e.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:o("config:areas.promptHint","This prompt is injected into agents assigned to this area. Takes effect on next context refresh.")})]}),s.assignedAgentIds.length>0&&e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:o("config:areas.rightClickUnassign")})]})]})}function Zs(){const{t:s}=Y(["config","common"]),a=xs(),[t,o]=l.useState(!1),[r,d]=l.useState(null),[c,g]=l.useState({name:"",key:"",value:"",description:""}),[n,x]=l.useState(null),w=()=>{o(!0),d(null),g({name:"",key:"",value:"",description:""})},C=h=>{d(h.id),o(!1),g({name:h.name,key:h.key,value:h.value,description:h.description||""})},u=()=>{o(!1),d(null),g({name:"",key:"",value:"",description:""})},p=()=>{!c.name.trim()||!c.key.trim()||(r?E.updateSecret(r,{name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}):E.createSecret({name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}),u())},m=h=>{x(h)},j=()=>{n&&(E.deleteSecret(n),r===n&&u())},b=h=>{navigator.clipboard.writeText(`{{${h}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children:a.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):a.map(h=>e.jsxs("div",{className:`secret-item ${r===h.id?"editing":""}`,children:[e.jsxs("div",{className:"secret-item-header",children:[e.jsxs("div",{className:"secret-item-info",children:[e.jsx("span",{className:"secret-item-name",children:h.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>b(h.key),title:s("config:secrets.copyPlaceholder"),children:`{{${h.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>C(h),title:s("common:buttons.edit"),children:e.jsx(L,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>m(h.id),title:s("common:buttons.delete"),children:"×"})]})]}),h.description&&e.jsx("div",{className:"secret-item-description",children:h.description})]},h.id))}),(t||r)&&e.jsxs("div",{className:"secret-form",children:[e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.name")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.namePlaceholder"),value:c.name,onChange:h=>g({...c,name:h.target.value}),autoFocus:!0})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:"Key"}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.keyPlaceholder"),value:c.key,onChange:h=>g({...c,key:h.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${c.key||"KEY"}}}`})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("config:secrets.secretValue")}),e.jsx("input",{type:"password",className:"secret-form-input",placeholder:s("config:secrets.valuePlaceholder"),value:c.value,onChange:h=>g({...c,value:h.target.value})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.description")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.descriptionPlaceholder"),value:c.description,onChange:h=>g({...c,description:h.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:u,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:p,disabled:!c.name.trim()||!c.key.trim(),children:s(r?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!r&&e.jsx("button",{className:"secrets-add-btn",onClick:w,children:s("config:secrets.addSecret")}),e.jsx(me,{isOpen:n!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:j,onClose:()=>x(null)})]})}async function Xs(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch system prompt: ${a.statusText}`);return(await a.json()).prompt||""}async function Qs(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function et(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to clear system prompt: ${a.statusText}`)}async function st(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch echo prompt setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function tt(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function at(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch codex binary path: ${a.statusText}`);return(await a.json()).path||""}async function nt(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function it(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch tmux mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function ot(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function lt(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch backup status: ${a.statusText}`);return a.json()}async function ct(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function rt({checked:s,onChange:a,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:o=>a(o.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function dt(){const{t:s}=Y(["config","common"]),[a,t]=l.useState([]),[o,r]=l.useState(new Set),[d,c]=l.useState(new Set),[g,n]=l.useState(!1),[x,w]=l.useState(!1),[C,u]=l.useState(null),[p,m]=l.useState(null),[j,b]=l.useState(null),[h,k]=l.useState(null),[$,P]=l.useState(!1),[K,y]=l.useState(null);l.useEffect(()=>{we(he("/api/config/categories")).then(N=>N.json()).then(N=>{const D=Array.isArray(N)?N:[];t(D),r(new Set(D.map(O=>O.id)))}).catch(N=>console.error("Failed to fetch config categories:",N))},[]),l.useEffect(()=>{lt().then(k).catch(N=>{console.error("Failed to fetch backup status:",N),y(N.message||"Failed to fetch backup status")})},[]);const U=async N=>{if(!$){P(!0),y(null);try{const D=await ct(N);k(D)}catch(D){y(D.message||"Failed to update backup setting")}finally{P(!1)}}},B=N=>{r(D=>{const O=new Set(D);return O.has(N)?O.delete(N):O.add(N),O})},V=N=>{c(D=>{const O=new Set(D);return O.has(N)?O.delete(N):O.add(N),O})},S=()=>r(new Set(a.map(N=>N.id))),T=()=>r(new Set),H=()=>{p&&c(new Set(p.categories.map(N=>N.id)))},X=()=>c(new Set),ie=async()=>{var N;if(o.size!==0){n(!0),b(null);try{const D=Array.from(o).join(","),O=await we(he(`/api/config/export?categories=${D}`));if(!O.ok)throw new Error("Export failed");const ee=await O.blob(),se=window.URL.createObjectURL(ee),Q=document.createElement("a");Q.href=se;const A=O.headers.get("Content-Disposition"),q=((N=A==null?void 0:A.match(/filename="(.+)"/))==null?void 0:N[1])||"tide-commander-config.zip";Q.download=q,document.body.appendChild(Q),Q.click(),document.body.removeChild(Q),window.URL.revokeObjectURL(se),b({type:"success",text:s("config:data.exportSuccess")})}catch(D){b({type:"error",text:D.message||"Export failed"})}finally{n(!1)}}},v=async N=>{var O;const D=(O=N.target.files)==null?void 0:O[0];if(D){u(D),b(null),m(null),c(new Set);try{const ee=await we(he("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await D.arrayBuffer()});if(!ee.ok){const A=await ee.json();throw new Error(A.error||"Failed to preview config file")}const se=await ee.json(),Q=Array.isArray(se.categories)?se.categories:[];m({...se,categories:Q}),c(new Set(Q.map(A=>A.id)))}catch(ee){b({type:"error",text:ee.message||"Failed to read config file"}),u(null)}}},F=async()=>{if(!(!C||d.size===0)){w(!0),b(null);try{const N=Array.from(d).join(","),D=await we(he(`/api/config/import?categories=${N}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await C.arrayBuffer()}),O=await D.json();if(!D.ok)throw new Error(O.error||"Import failed");b({type:"success",text:O.message||s("config:data.importSuccess")}),u(null),m(null),c(new Set)}catch(N){b({type:"error",text:N.message||"Import failed"})}finally{w(!1)}}},M=()=>{u(null),m(null),c(new Set),b(null)};return e.jsxs("div",{className:"data-section",children:[j&&e.jsx("div",{className:`data-message data-message-${j.type}`,children:j.text}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:"Hourly Backups"}),e.jsx(rt,{checked:!!(h!=null&&h.enabled),disabled:$||!h,onChange:U})]}),e.jsxs("div",{className:"data-backup-info",children:[h?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:h.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!h.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:h.scriptPath})]}),h.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(h.lastRunAt).toLocaleString(),h.lastRunOk===!0&&" — ok",h.lastRunOk===!1&&h.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",h.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),K&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:K})]})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:S,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:T,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:a.map(N=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(N.id),onChange:()=>B(N.id)}),e.jsx("span",{className:"data-category-name",children:N.name})]},N.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ie,disabled:g||o.size===0,children:g?s("config:data.exporting"):s("config:data.exportCount",{count:o.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),C?p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:C.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(p.exportedAt).toLocaleDateString()]})]}),e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-subtitle",children:s("config:data.selectToImport")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:H,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:X,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:p.categories.map(N=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:d.has(N.id),onChange:()=>V(N.id)}),e.jsx("span",{className:"data-category-name",children:N.name}),N.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",N.fileCount," ",s("config:data.files"),")"]})]},N.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:M,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:F,disabled:x||d.size===0,children:x?s("config:data.importing"):s("config:data.importCount",{count:d.size})})]})]}):e.jsx("div",{className:"data-loading",children:s("config:data.readingFile")}):e.jsxs("label",{className:"data-file-input",children:[e.jsx("input",{type:"file",accept:".zip",onChange:v,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}async function ut(){const s=await we(`${J()}/api/system/install-info`);if(!s.ok)throw new Error(`Failed to fetch install info: ${s.statusText}`);return s.json()}function pt(s,a){const t=new AbortController;return(async()=>{try{const o=await fetch(is(`${J()}/api/system/self-update`),{method:"POST",signal:t.signal,headers:{Accept:"text/event-stream"}});if(!o.ok||!o.body){const g=await o.text().catch(()=>"");let n=null;try{n=JSON.parse(g)}catch{}const x=n&&typeof n=="object"&&"error"in n&&typeof n.error=="string"?n.error:`Self-update failed: ${o.status} ${o.statusText}`;s({type:"error",message:x}),a(new Error(x));return}const r=o.body.getReader(),d=new TextDecoder("utf-8");let c="";for(;;){const{value:g,done:n}=await r.read();if(n)break;c+=d.decode(g,{stream:!0});let x=c.indexOf(`
2
2
 
3
3
  `);for(;x!==-1;){const w=c.slice(0,x);c=c.slice(x+2);const C=w.split(`
4
4
  `);let u="message",p="";for(const m of C)m.startsWith(":")||(m.startsWith("event:")?u=m.slice(6).trim():m.startsWith("data:")&&(p+=(p?`