tide-commander 1.133.2 → 1.134.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 (38) hide show
  1. package/dist/assets/{BossLogsModal-DwuIK9m6.js → BossLogsModal-RefxNov0.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-Dj3RAYvK.js → BossSpawnModal-6YdVtXsV.js} +1 -1
  3. package/dist/assets/{ControlsModal-2RYmmfrr.js → ControlsModal-CzNNwFvF.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-CtK69VXz.js → DockerLogsModal-CKu0t2zp.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-D4dyGPWp.js → EmbeddedEditor-DZt6t0pq.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-D4WIJQPh.js → GmailOAuthSetup-CzwdXXpj.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-CeOoPjBn.js → GoogleOAuthSetup-BSitbOF_.js} +1 -1
  8. package/dist/assets/{IframeModal-Czpk8nNY.js → IframeModal-BQH5btbe.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-BTWvtUqh.js → IntegrationsPanel-Cgj96DLZ.js} +2 -2
  10. package/dist/assets/{LogViewerModal-BoFD-vk1.js → LogViewerModal-DWq3ch0_.js} +1 -1
  11. package/dist/assets/{MonitoringModal-ChR0ELIz.js → MonitoringModal-DJan0ZfF.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-CoCnLncV.js → PM2LogsModal-BEg-S2UN.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-DPTPKLHh.js → RestoreArchivedAreaModal-DETyJSSk.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-BH-47TIq.js → Scene2DCanvas-Dvtx-tTF.js} +1 -1
  15. package/dist/assets/{SceneManager-IluWBEFk.js → SceneManager-D0YNBVvC.js} +1 -1
  16. package/dist/assets/{SkillsPanel-XcUykivP.js → SkillsPanel-CY1MGXiv.js} +1 -1
  17. package/dist/assets/{SlackMultiInstanceSetup-DeLiUle3.js → SlackMultiInstanceSetup-x3J1T2CL.js} +1 -1
  18. package/dist/assets/{SpawnModal-BZfIZTdq.js → SpawnModal-BuXvCAro.js} +1 -1
  19. package/dist/assets/{StatisticsModal-C0Ets4vl.js → StatisticsModal-JguU4fHR.js} +1 -1
  20. package/dist/assets/{SubordinateAssignmentModal-BMT6EK_E.js → SubordinateAssignmentModal-TyPQN6G4.js} +1 -1
  21. package/dist/assets/{TriggerManagerPanel-Bnwo6pTt.js → TriggerManagerPanel-Co7nZrm5.js} +1 -1
  22. package/dist/assets/{WorkflowEditorPanel-D0G14Ebq.js → WorkflowEditorPanel-DxDbJWw3.js} +1 -1
  23. package/dist/assets/{area-logos-C5XZBFfj.js → area-logos-Cmo2TPRg.js} +1 -1
  24. package/dist/assets/{index-AlXP8uuc.js → index-BWe3rGsu.js} +3 -3
  25. package/dist/assets/{index-GtO7k8QG.js → index-BgzCW06Y.js} +1 -1
  26. package/dist/assets/{index-BV42oiJT.js → index-BxEYSlj-.js} +1 -1
  27. package/dist/assets/{index-bY0k_5jo.js → index-Byqe2ALL.js} +1 -1
  28. package/dist/assets/{index-D5ufwk7t.js → index-C0PTjSKV.js} +1 -1
  29. package/dist/assets/{index-D_shYCrx.js → index-C1drJm1h.js} +1 -1
  30. package/dist/assets/{index-D-ETqZcB.js → index-DH6zCU8H.js} +2 -2
  31. package/dist/assets/{index-Bd5JKG69.js → index-DiZqkOIm.js} +1 -1
  32. package/dist/assets/{index-B3k628ul.js → index-DmAPUqcW.js} +1 -1
  33. package/dist/assets/{main-DZgTocNE.js → main-BVwUBAk3.js} +99 -99
  34. package/dist/assets/{web-i9NDpV0L.js → web-B_mn8Bop.js} +1 -1
  35. package/dist/assets/{web-CwRGXDj6.js → web-D4QqghkZ.js} +1 -1
  36. package/dist/assets/{web-zQ3wpRl0.js → web-DuThEbz0.js} +1 -1
  37. package/dist/index.html +1 -1
  38. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import{r as l,b4 as Ue,b5 as Je,j as e,I as $,u as X,b6 as ns,ab as is,f as Ke,s as _,b7 as ms,b8 as gs,aZ as fs,b9 as xs,C as he,G as se,H as Y,h as je,i as ke,m as bs,ba as js,bb as ws,bc as ys,bd as vs,P as Ns,be as Se,a6 as ks,bf as os,bg as Ss,bh as Ve,bi as Cs,bj as As,bk as Ts,bl as _s,bm as Is,bn as Es,bo as Ps,aT as Ls,W as $s,S as Ne,bp as Ds,bq as Os,aV as Fs,br as ze,X as Ee,b1 as Rs,bs as Me,bt as Us}from"./main-DZgTocNE.js";import{g as zs,d as Ms,u as Bs}from"./area-logos-C5XZBFfj.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const He="deivid11/tide-commander",Vs=`https://api.github.com/repos/${He}/releases/latest`,Ks=`https://api.github.com/repos/${He}/releases?per_page=3`,Hs=3600*1e3,Ze="app_update_dismissed_version",Xe="1.133.2";function Ws(){var N,S;const[s,a]=l.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:Xe}),t=((S=(N=Ue)==null?void 0:N.getPlatform)==null?void 0:S.call(N))==="android"||!1,o=u=>u.replace(/^v/,"").split(".").map(m=>parseInt(m,10)||0),d=(u,p)=>{const m=o(u),j=o(p),b=Math.max(m.length,j.length);for(let h=0;h<b;h++){const y=m[h]||0,P=j[h]||0;if(y>P)return 1;if(y<P)return-1}return 0},r=async u=>{var m,j;if(Ue&&Je&&((j=(m=Ue).isNativePlatform)==null?void 0:j.call(m))===!0){const b=await Je.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([r(Vs),r(Ks)]);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(w=>({version:w.tag_name,name:w.name,publishedAt:w.published_at,releaseUrl:w.html_url})));const y=localStorage.getItem(Ze);if(!u&&y===b)return a(w=>({...w,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;if(!(d(b,Xe)>0))return a(w=>({...w,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;const I=j.assets.find(w=>w.name.endsWith(".apk")&&w.content_type==="application/vnd.android.package-archive"),H={version:b,name:j.name,changelog:j.body,releaseUrl:j.html_url,apkUrl:(I==null?void 0:I.browser_download_url)||null,apkSize:(I==null?void 0:I.size)||null,publishedAt:j.published_at};return a(w=>({...w,isChecking:!1,updateAvailable:!0,updateInfo:H,recentReleases:h})),H}catch(p){const m=p instanceof Error?p.message:"Failed to check for updates";return a(j=>({...j,isChecking:!1,error:m})),null}},[]),x=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(Ze,s.updateInfo.version),a(u=>({...u,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),g=l.useCallback(()=>{var u;(u=s.updateInfo)!=null&&u.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${He}/releases`,"_blank")},[s.updateInfo]);return l.useEffect(()=>{if(!t)return;const u=setTimeout(()=>{c()},5e3),p=setInterval(()=>{c()},Hs);return()=>{clearTimeout(u),clearInterval(p)}},[t,c]),{...s,isAndroid:t,checkForUpdate:c,downloadAndInstall:x,dismissUpdate:n,openReleasePage:g}}const ls="tide-toolbox-collapse";function qs(s,a){try{const t=localStorage.getItem(`${ls}-${s}`);if(t!==null)return t==="true"}catch{}return a}function Gs(s,a){try{localStorage.setItem(`${ls}-${s}`,String(a))}catch{}}function G({title:s,storageKey:a,defaultOpen:t=!1,forceOpen:o=!1,children:d,headerExtra:r}){const[c,x]=l.useState(()=>a?qs(a,t):t),n=()=>{const N=!c;x(N),a&&Gs(a,N)},g=o||c;return e.jsxs("div",{className:`collapsible-section ${g?"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:[r,e.jsx("span",{className:"collapsible-arrow",children:e.jsx($,{name:g?"caret-down":"caret-right",size:10})})]})]}),g&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Ys({area:s,isSelected:a,onClick:t,onDelete:o}){const{t:d}=X(["config","common"]),r=s.assignedAgentIds.length,c=s.type==="rectangle"?d("config:areas.rect"):d("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," ",r>0&&`• ${r} ${r>1?d("common:labels.agents").toLowerCase():d("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:d("config:areas.deleteArea"),children:"×"})]})}function Js({building:s,isSelected:a,onClick:t,onEdit:o}){var x;const{t:d}=X(["config"]),r=((x=s.pm2Status)==null?void 0:x.ports)||[],c=(n,g)=>{n.stopPropagation(),window.open(`http://${window.location.hostname}:${g}`,"_blank")};return e.jsxs("div",{className:`building-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:ns[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx($,{name:is(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,r.length>0&&e.jsx("span",{className:"building-ports",children:r.map(n=>e.jsxs("a",{href:`http://${window.location.hostname}:${n}`,className:"building-port-link",onClick:g=>c(g,n),title:`Open :${n}`,children:[":",n]},n))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:n=>{n.stopPropagation(),o()},title:d("config:buildings.editBuilding"),children:e.jsx($,{name:"gear",size:14})})]})}function Zs({building:s,onClose:a,onOpenModal:t}){var g,N,S,u,p,m,j,b;const{t:o}=X(["config","common"]),{buildingLogs:d}=Ke(),r=_.getBuildingLogs(s.id),c=ms[s.style||"server-rack"],x=h=>{_.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($,{name:is(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:ns[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:()=>x("start"),disabled:!((g=s.commands)!=null&&g.start)||s.status==="running",title:((N=s.commands)==null?void 0:N.start)||o("config:buildings.noStartCommand"),children:[e.jsx($,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>x("stop"),disabled:!((S=s.commands)!=null&&S.stop)||s.status==="stopped",title:((u=s.commands)==null?void 0:u.stop)||o("config:buildings.noStopCommand"),children:[e.jsx($,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>x("restart"),disabled:!((p=s.commands)!=null&&p.restart),title:((m=s.commands)==null?void 0:m.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx($,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>x("healthCheck"),disabled:!((j=s.commands)!=null&&j.healthCheck),title:((b=s.commands)==null?void 0:b.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx($,{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,y)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>n(h.url),title:h.url,children:[e.jsx($,{name:"link",size:12})," ",h.label||h.url]},y))})]}),r.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:()=>_.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:r.slice(-5).map((h,y)=>e.jsx("div",{className:"building-editor-log-entry",children:h},y))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx($,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}const Xs=[{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 Qs({area:s,onClose:a,onOpenFolder:t}){var te;const{t:o}=X(["config","common"]),[d,r]=l.useState(s.name),[c,x]=l.useState(s.prompt||""),[n,g]=l.useState(!1),[N,S]=l.useState(""),[u,p]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{r(s.name)},[s.id,s.name]),l.useEffect(()=>{x(s.prompt||"")},[s.id,s.prompt]);const j=k=>{const O=k.target.value;r(O),_.updateArea(s.id,{name:O})},b=k=>{_.updateArea(s.id,{color:k})},h=k=>{const O=k.target.value;x(O),_.updateArea(s.id,{prompt:O})},y=()=>{N.trim()&&(_.addDirectoryToArea(s.id,N.trim()),S(""),g(!1))},P=(k,O)=>{O.stopPropagation(),_.removeDirectoryFromArea(s.id,k)},I=()=>{_.bringAreaToFront(s.id)},H=()=>{_.sendAreaToBack(s.id)},w=l.useCallback(()=>{let k=2,O=2;s.type==="rectangle"&&s.width&&s.height?(k=s.width,O=s.height):s.type==="circle"&&s.radius&&(k=s.radius*1.414,O=s.radius*1.414);const V=Math.min(k,O)*.4;return{width:Math.round(V*10)/10,height:Math.round(V*10)/10}},[s.type,s.width,s.height,s.radius]),z=async k=>{var V;const O=(V=k.target.files)==null?void 0:V[0];if(O){p(!0);try{const v=await Bs(s.id,O),D=w();_.updateArea(s.id,{logo:{filename:v.filename,position:"center",width:D.width,height:D.height,keepAspectRatio:!0,opacity:.8}})}catch(v){console.error("Failed to upload logo:",v)}finally{p(!1),m.current&&(m.current.value="")}}},B=async()=>{try{await Ms(s.id),_.updateArea(s.id,{logo:void 0})}catch(k){console.error("Failed to remove logo:",k)}},q=k=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,position:k}})},C=k=>{if(!s.logo)return;const O=parseFloat(k.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const V=s.logo.height/s.logo.width;_.updateArea(s.id,{logo:{...s.logo,width:O,height:Math.round(O*V*10)/10}})}else _.updateArea(s.id,{logo:{...s.logo,width:O}})},R=k=>{if(!s.logo)return;const O=parseFloat(k.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const V=s.logo.width/s.logo.height;_.updateArea(s.id,{logo:{...s.logo,height:O,width:Math.round(O*V*10)/10}})}else _.updateArea(s.id,{logo:{...s.logo,height:O}})},K=()=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},W=k=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(k.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:d,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(k=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===k?"selected":""}`,style:{backgroundColor:k},onClick:()=>b(k),"aria-label":`Set area color ${k}`,"aria-pressed":s.color===k,title:k},k))})]}),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:I,title:o("config:areas.bringToFront"),children:[e.jsx($,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:H,title:o("config:areas.sendToBack"),children:[e.jsx($,{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:[(te=s.logo)!=null&&te.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:zs(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 k;return(k=m.current)==null?void 0:k.click()},disabled:u,children:u?"...":e.jsx($,{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:Xs.map(({key:k,labelKey:O})=>{var V;return e.jsx("button",{className:`area-logo-pos-btn ${((V=s.logo)==null?void 0:V.position)===k?"active":""}`,onClick:()=>q(k),children:o(`config:areas.${O}`)},k)})})]}),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:C,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:R,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:K}),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:W,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 k;return(k=m.current)==null?void 0:k.click()},disabled:u,children:u?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:m,type:"file",accept:"image/*",style:{display:"none"},onChange:z})]})]}),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(k=>e.jsxs("div",{className:"area-folder-item",title:k,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($,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:k.split("/").pop()||k}),e.jsx("button",{className:"area-folder-remove",onClick:O=>P(k,O),title:o("config:areas.removeFolder"),children:"×"})]},k)),n?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(fs,{value:N,onChange:S,onSubmit:y,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:y,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>g(!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 et(){const{t:s}=X(["config","common"]),a=xs(),[t,o]=l.useState(!1),[d,r]=l.useState(null),[c,x]=l.useState({name:"",key:"",value:"",description:""}),[n,g]=l.useState(null),N=()=>{o(!0),r(null),x({name:"",key:"",value:"",description:""})},S=h=>{r(h.id),o(!1),x({name:h.name,key:h.key,value:h.value,description:h.description||""})},u=()=>{o(!1),r(null),x({name:"",key:"",value:"",description:""})},p=()=>{!c.name.trim()||!c.key.trim()||(d?_.updateSecret(d,{name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}):_.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=>{g(h)},j=()=>{n&&(_.deleteSecret(n),d===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 ${d===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:()=>S(h),title:s("common:buttons.edit"),children:e.jsx($,{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||d)&&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=>x({...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=>x({...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=>x({...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=>x({...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(d?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!d&&e.jsx("button",{className:"secrets-add-btn",onClick:N,children:s("config:secrets.addSecret")}),e.jsx(he,{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:()=>g(null)})]})}async function st(){const s=se(),a=await fetch(`${Y()}/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 tt(s){const a=se(),t=await fetch(`${Y()}/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 at(){const s=se(),a=await fetch(`${Y()}/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 nt(){const s=se(),a=await fetch(`${Y()}/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 it(s){const a=se(),t=await fetch(`${Y()}/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 ot(){const s=se(),a=await fetch(`${Y()}/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 lt(s){const a=se(),t=await fetch(`${Y()}/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 ct(){const s=se(),a=await fetch(`${Y()}/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 rt(s){const a=se(),t=await fetch(`${Y()}/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 dt(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch interactive mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function ut(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/interactive-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 interactive mode setting: ${t.statusText}`)}async function pt(){const s=se(),a=await fetch(`${Y()}/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 ht(s){const a=se(),t=await fetch(`${Y()}/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 mt({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 gt(){const{t:s}=X(["config","common"]),[a,t]=l.useState([]),[o,d]=l.useState(new Set),[r,c]=l.useState(new Set),[x,n]=l.useState(!1),[g,N]=l.useState(!1),[S,u]=l.useState(null),[p,m]=l.useState(null),[j,b]=l.useState(null),[h,y]=l.useState(null),[P,I]=l.useState(!1),[H,w]=l.useState(null);l.useEffect(()=>{je(ke("/api/config/categories")).then(v=>v.json()).then(v=>{const D=Array.isArray(v)?v:[];t(D),d(new Set(D.map(F=>F.id)))}).catch(v=>console.error("Failed to fetch config categories:",v))},[]),l.useEffect(()=>{pt().then(y).catch(v=>{console.error("Failed to fetch backup status:",v),w(v.message||"Failed to fetch backup status")})},[]);const z=async v=>{if(!P){I(!0),w(null);try{const D=await ht(v);y(D)}catch(D){w(D.message||"Failed to update backup setting")}finally{I(!1)}}},B=v=>{d(D=>{const F=new Set(D);return F.has(v)?F.delete(v):F.add(v),F})},q=v=>{c(D=>{const F=new Set(D);return F.has(v)?F.delete(v):F.add(v),F})},C=()=>d(new Set(a.map(v=>v.id))),R=()=>d(new Set),K=()=>{p&&c(new Set(p.categories.map(v=>v.id)))},W=()=>c(new Set),te=async()=>{var v;if(o.size!==0){n(!0),b(null);try{const D=Array.from(o).join(","),F=await je(ke(`/api/config/export?categories=${D}`));if(!F.ok)throw new Error("Export failed");const Q=await F.blob(),ee=window.URL.createObjectURL(Q),T=document.createElement("a");T.href=ee;const A=F.headers.get("Content-Disposition"),J=((v=A==null?void 0:A.match(/filename="(.+)"/))==null?void 0:v[1])||"tide-commander-config.zip";T.download=J,document.body.appendChild(T),T.click(),document.body.removeChild(T),window.URL.revokeObjectURL(ee),b({type:"success",text:s("config:data.exportSuccess")})}catch(D){b({type:"error",text:D.message||"Export failed"})}finally{n(!1)}}},k=async v=>{var F;const D=(F=v.target.files)==null?void 0:F[0];if(D){u(D),b(null),m(null),c(new Set);try{const Q=await je(ke("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await D.arrayBuffer()});if(!Q.ok){const A=await Q.json();throw new Error(A.error||"Failed to preview config file")}const ee=await Q.json(),T=Array.isArray(ee.categories)?ee.categories:[];m({...ee,categories:T}),c(new Set(T.map(A=>A.id)))}catch(Q){b({type:"error",text:Q.message||"Failed to read config file"}),u(null)}}},O=async()=>{if(!(!S||r.size===0)){N(!0),b(null);try{const v=Array.from(r).join(","),D=await je(ke(`/api/config/import?categories=${v}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await S.arrayBuffer()}),F=await D.json();if(!D.ok)throw new Error(F.error||"Import failed");b({type:"success",text:F.message||s("config:data.importSuccess")}),u(null),m(null),c(new Set)}catch(v){b({type:"error",text:v.message||"Import failed"})}finally{N(!1)}}},V=()=>{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(mt,{checked:!!(h!=null&&h.enabled),disabled:P||!h,onChange:z})]}),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…"}),H&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:H})]})]}),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:C,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:R,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:a.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(v.id),onChange:()=>B(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name})]},v.id))}),e.jsx("button",{className:"data-action-btn export",onClick:te,disabled:x||o.size===0,children:x?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")})}),S?p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:S.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:K,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:W,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:p.categories.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:r.has(v.id),onChange:()=>q(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name}),v.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",v.fileCount," ",s("config:data.files"),")"]})]},v.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:V,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:O,disabled:g||r.size===0,children:g?s("config:data.importing"):s("config:data.importCount",{count:r.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:k,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}async function ft(){const s=await je(`${Y()}/api/system/install-info`);if(!s.ok)throw new Error(`Failed to fetch install info: ${s.statusText}`);return s.json()}function xt(s,a){const t=new AbortController;return(async()=>{try{const o=await fetch(bs(`${Y()}/api/system/self-update`),{method:"POST",signal:t.signal,headers:{Accept:"text/event-stream"}});if(!o.ok||!o.body){const x=await o.text().catch(()=>"");let n=null;try{n=JSON.parse(x)}catch{}const g=n&&typeof n=="object"&&"error"in n&&typeof n.error=="string"?n.error:`Self-update failed: ${o.status} ${o.statusText}`;s({type:"error",message:g}),a(new Error(g));return}const d=o.body.getReader(),r=new TextDecoder("utf-8");let c="";for(;;){const{value:x,done:n}=await d.read();if(n)break;c+=r.decode(x,{stream:!0});let g=c.indexOf(`
1
+ import{r as l,b4 as Ue,b5 as Je,j as e,I as $,u as X,b6 as ns,ab as is,f as Ke,s as _,b7 as ms,b8 as gs,aZ as fs,b9 as xs,C as he,G as se,H as Y,h as je,i as ke,m as bs,ba as js,bb as ws,bc as ys,bd as vs,P as Ns,be as Se,a6 as ks,bf as os,bg as Ss,bh as Ve,bi as Cs,bj as As,bk as Ts,bl as _s,bm as Is,bn as Es,bo as Ps,aT as Ls,W as $s,S as Ne,bp as Ds,bq as Os,aV as Fs,br as ze,X as Ee,b1 as Rs,bs as Me,bt as Us}from"./main-BVwUBAk3.js";import{g as zs,d as Ms,u as Bs}from"./area-logos-Cmo2TPRg.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const He="deivid11/tide-commander",Vs=`https://api.github.com/repos/${He}/releases/latest`,Ks=`https://api.github.com/repos/${He}/releases?per_page=3`,Hs=3600*1e3,Ze="app_update_dismissed_version",Xe="1.134.0";function Ws(){var N,S;const[s,a]=l.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:Xe}),t=((S=(N=Ue)==null?void 0:N.getPlatform)==null?void 0:S.call(N))==="android"||!1,o=u=>u.replace(/^v/,"").split(".").map(m=>parseInt(m,10)||0),d=(u,p)=>{const m=o(u),j=o(p),b=Math.max(m.length,j.length);for(let h=0;h<b;h++){const y=m[h]||0,P=j[h]||0;if(y>P)return 1;if(y<P)return-1}return 0},r=async u=>{var m,j;if(Ue&&Je&&((j=(m=Ue).isNativePlatform)==null?void 0:j.call(m))===!0){const b=await Je.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([r(Vs),r(Ks)]);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(w=>({version:w.tag_name,name:w.name,publishedAt:w.published_at,releaseUrl:w.html_url})));const y=localStorage.getItem(Ze);if(!u&&y===b)return a(w=>({...w,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;if(!(d(b,Xe)>0))return a(w=>({...w,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;const I=j.assets.find(w=>w.name.endsWith(".apk")&&w.content_type==="application/vnd.android.package-archive"),H={version:b,name:j.name,changelog:j.body,releaseUrl:j.html_url,apkUrl:(I==null?void 0:I.browser_download_url)||null,apkSize:(I==null?void 0:I.size)||null,publishedAt:j.published_at};return a(w=>({...w,isChecking:!1,updateAvailable:!0,updateInfo:H,recentReleases:h})),H}catch(p){const m=p instanceof Error?p.message:"Failed to check for updates";return a(j=>({...j,isChecking:!1,error:m})),null}},[]),x=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(Ze,s.updateInfo.version),a(u=>({...u,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),g=l.useCallback(()=>{var u;(u=s.updateInfo)!=null&&u.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${He}/releases`,"_blank")},[s.updateInfo]);return l.useEffect(()=>{if(!t)return;const u=setTimeout(()=>{c()},5e3),p=setInterval(()=>{c()},Hs);return()=>{clearTimeout(u),clearInterval(p)}},[t,c]),{...s,isAndroid:t,checkForUpdate:c,downloadAndInstall:x,dismissUpdate:n,openReleasePage:g}}const ls="tide-toolbox-collapse";function qs(s,a){try{const t=localStorage.getItem(`${ls}-${s}`);if(t!==null)return t==="true"}catch{}return a}function Gs(s,a){try{localStorage.setItem(`${ls}-${s}`,String(a))}catch{}}function G({title:s,storageKey:a,defaultOpen:t=!1,forceOpen:o=!1,children:d,headerExtra:r}){const[c,x]=l.useState(()=>a?qs(a,t):t),n=()=>{const N=!c;x(N),a&&Gs(a,N)},g=o||c;return e.jsxs("div",{className:`collapsible-section ${g?"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:[r,e.jsx("span",{className:"collapsible-arrow",children:e.jsx($,{name:g?"caret-down":"caret-right",size:10})})]})]}),g&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Ys({area:s,isSelected:a,onClick:t,onDelete:o}){const{t:d}=X(["config","common"]),r=s.assignedAgentIds.length,c=s.type==="rectangle"?d("config:areas.rect"):d("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," ",r>0&&`• ${r} ${r>1?d("common:labels.agents").toLowerCase():d("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:d("config:areas.deleteArea"),children:"×"})]})}function Js({building:s,isSelected:a,onClick:t,onEdit:o}){var x;const{t:d}=X(["config"]),r=((x=s.pm2Status)==null?void 0:x.ports)||[],c=(n,g)=>{n.stopPropagation(),window.open(`http://${window.location.hostname}:${g}`,"_blank")};return e.jsxs("div",{className:`building-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:ns[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx($,{name:is(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,r.length>0&&e.jsx("span",{className:"building-ports",children:r.map(n=>e.jsxs("a",{href:`http://${window.location.hostname}:${n}`,className:"building-port-link",onClick:g=>c(g,n),title:`Open :${n}`,children:[":",n]},n))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:n=>{n.stopPropagation(),o()},title:d("config:buildings.editBuilding"),children:e.jsx($,{name:"gear",size:14})})]})}function Zs({building:s,onClose:a,onOpenModal:t}){var g,N,S,u,p,m,j,b;const{t:o}=X(["config","common"]),{buildingLogs:d}=Ke(),r=_.getBuildingLogs(s.id),c=ms[s.style||"server-rack"],x=h=>{_.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($,{name:is(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:ns[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:()=>x("start"),disabled:!((g=s.commands)!=null&&g.start)||s.status==="running",title:((N=s.commands)==null?void 0:N.start)||o("config:buildings.noStartCommand"),children:[e.jsx($,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>x("stop"),disabled:!((S=s.commands)!=null&&S.stop)||s.status==="stopped",title:((u=s.commands)==null?void 0:u.stop)||o("config:buildings.noStopCommand"),children:[e.jsx($,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>x("restart"),disabled:!((p=s.commands)!=null&&p.restart),title:((m=s.commands)==null?void 0:m.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx($,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>x("healthCheck"),disabled:!((j=s.commands)!=null&&j.healthCheck),title:((b=s.commands)==null?void 0:b.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx($,{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,y)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>n(h.url),title:h.url,children:[e.jsx($,{name:"link",size:12})," ",h.label||h.url]},y))})]}),r.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:()=>_.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:r.slice(-5).map((h,y)=>e.jsx("div",{className:"building-editor-log-entry",children:h},y))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx($,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}const Xs=[{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 Qs({area:s,onClose:a,onOpenFolder:t}){var te;const{t:o}=X(["config","common"]),[d,r]=l.useState(s.name),[c,x]=l.useState(s.prompt||""),[n,g]=l.useState(!1),[N,S]=l.useState(""),[u,p]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{r(s.name)},[s.id,s.name]),l.useEffect(()=>{x(s.prompt||"")},[s.id,s.prompt]);const j=k=>{const O=k.target.value;r(O),_.updateArea(s.id,{name:O})},b=k=>{_.updateArea(s.id,{color:k})},h=k=>{const O=k.target.value;x(O),_.updateArea(s.id,{prompt:O})},y=()=>{N.trim()&&(_.addDirectoryToArea(s.id,N.trim()),S(""),g(!1))},P=(k,O)=>{O.stopPropagation(),_.removeDirectoryFromArea(s.id,k)},I=()=>{_.bringAreaToFront(s.id)},H=()=>{_.sendAreaToBack(s.id)},w=l.useCallback(()=>{let k=2,O=2;s.type==="rectangle"&&s.width&&s.height?(k=s.width,O=s.height):s.type==="circle"&&s.radius&&(k=s.radius*1.414,O=s.radius*1.414);const V=Math.min(k,O)*.4;return{width:Math.round(V*10)/10,height:Math.round(V*10)/10}},[s.type,s.width,s.height,s.radius]),z=async k=>{var V;const O=(V=k.target.files)==null?void 0:V[0];if(O){p(!0);try{const v=await Bs(s.id,O),D=w();_.updateArea(s.id,{logo:{filename:v.filename,position:"center",width:D.width,height:D.height,keepAspectRatio:!0,opacity:.8}})}catch(v){console.error("Failed to upload logo:",v)}finally{p(!1),m.current&&(m.current.value="")}}},B=async()=>{try{await Ms(s.id),_.updateArea(s.id,{logo:void 0})}catch(k){console.error("Failed to remove logo:",k)}},q=k=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,position:k}})},C=k=>{if(!s.logo)return;const O=parseFloat(k.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const V=s.logo.height/s.logo.width;_.updateArea(s.id,{logo:{...s.logo,width:O,height:Math.round(O*V*10)/10}})}else _.updateArea(s.id,{logo:{...s.logo,width:O}})},R=k=>{if(!s.logo)return;const O=parseFloat(k.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const V=s.logo.width/s.logo.height;_.updateArea(s.id,{logo:{...s.logo,height:O,width:Math.round(O*V*10)/10}})}else _.updateArea(s.id,{logo:{...s.logo,height:O}})},K=()=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},W=k=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(k.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:d,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(k=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===k?"selected":""}`,style:{backgroundColor:k},onClick:()=>b(k),"aria-label":`Set area color ${k}`,"aria-pressed":s.color===k,title:k},k))})]}),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:I,title:o("config:areas.bringToFront"),children:[e.jsx($,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:H,title:o("config:areas.sendToBack"),children:[e.jsx($,{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:[(te=s.logo)!=null&&te.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:zs(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 k;return(k=m.current)==null?void 0:k.click()},disabled:u,children:u?"...":e.jsx($,{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:Xs.map(({key:k,labelKey:O})=>{var V;return e.jsx("button",{className:`area-logo-pos-btn ${((V=s.logo)==null?void 0:V.position)===k?"active":""}`,onClick:()=>q(k),children:o(`config:areas.${O}`)},k)})})]}),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:C,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:R,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:K}),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:W,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 k;return(k=m.current)==null?void 0:k.click()},disabled:u,children:u?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:m,type:"file",accept:"image/*",style:{display:"none"},onChange:z})]})]}),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(k=>e.jsxs("div",{className:"area-folder-item",title:k,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($,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:k.split("/").pop()||k}),e.jsx("button",{className:"area-folder-remove",onClick:O=>P(k,O),title:o("config:areas.removeFolder"),children:"×"})]},k)),n?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(fs,{value:N,onChange:S,onSubmit:y,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:y,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>g(!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 et(){const{t:s}=X(["config","common"]),a=xs(),[t,o]=l.useState(!1),[d,r]=l.useState(null),[c,x]=l.useState({name:"",key:"",value:"",description:""}),[n,g]=l.useState(null),N=()=>{o(!0),r(null),x({name:"",key:"",value:"",description:""})},S=h=>{r(h.id),o(!1),x({name:h.name,key:h.key,value:h.value,description:h.description||""})},u=()=>{o(!1),r(null),x({name:"",key:"",value:"",description:""})},p=()=>{!c.name.trim()||!c.key.trim()||(d?_.updateSecret(d,{name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}):_.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=>{g(h)},j=()=>{n&&(_.deleteSecret(n),d===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 ${d===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:()=>S(h),title:s("common:buttons.edit"),children:e.jsx($,{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||d)&&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=>x({...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=>x({...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=>x({...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=>x({...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(d?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!d&&e.jsx("button",{className:"secrets-add-btn",onClick:N,children:s("config:secrets.addSecret")}),e.jsx(he,{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:()=>g(null)})]})}async function st(){const s=se(),a=await fetch(`${Y()}/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 tt(s){const a=se(),t=await fetch(`${Y()}/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 at(){const s=se(),a=await fetch(`${Y()}/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 nt(){const s=se(),a=await fetch(`${Y()}/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 it(s){const a=se(),t=await fetch(`${Y()}/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 ot(){const s=se(),a=await fetch(`${Y()}/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 lt(s){const a=se(),t=await fetch(`${Y()}/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 ct(){const s=se(),a=await fetch(`${Y()}/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 rt(s){const a=se(),t=await fetch(`${Y()}/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 dt(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch interactive mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function ut(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/interactive-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 interactive mode setting: ${t.statusText}`)}async function pt(){const s=se(),a=await fetch(`${Y()}/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 ht(s){const a=se(),t=await fetch(`${Y()}/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 mt({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 gt(){const{t:s}=X(["config","common"]),[a,t]=l.useState([]),[o,d]=l.useState(new Set),[r,c]=l.useState(new Set),[x,n]=l.useState(!1),[g,N]=l.useState(!1),[S,u]=l.useState(null),[p,m]=l.useState(null),[j,b]=l.useState(null),[h,y]=l.useState(null),[P,I]=l.useState(!1),[H,w]=l.useState(null);l.useEffect(()=>{je(ke("/api/config/categories")).then(v=>v.json()).then(v=>{const D=Array.isArray(v)?v:[];t(D),d(new Set(D.map(F=>F.id)))}).catch(v=>console.error("Failed to fetch config categories:",v))},[]),l.useEffect(()=>{pt().then(y).catch(v=>{console.error("Failed to fetch backup status:",v),w(v.message||"Failed to fetch backup status")})},[]);const z=async v=>{if(!P){I(!0),w(null);try{const D=await ht(v);y(D)}catch(D){w(D.message||"Failed to update backup setting")}finally{I(!1)}}},B=v=>{d(D=>{const F=new Set(D);return F.has(v)?F.delete(v):F.add(v),F})},q=v=>{c(D=>{const F=new Set(D);return F.has(v)?F.delete(v):F.add(v),F})},C=()=>d(new Set(a.map(v=>v.id))),R=()=>d(new Set),K=()=>{p&&c(new Set(p.categories.map(v=>v.id)))},W=()=>c(new Set),te=async()=>{var v;if(o.size!==0){n(!0),b(null);try{const D=Array.from(o).join(","),F=await je(ke(`/api/config/export?categories=${D}`));if(!F.ok)throw new Error("Export failed");const Q=await F.blob(),ee=window.URL.createObjectURL(Q),T=document.createElement("a");T.href=ee;const A=F.headers.get("Content-Disposition"),J=((v=A==null?void 0:A.match(/filename="(.+)"/))==null?void 0:v[1])||"tide-commander-config.zip";T.download=J,document.body.appendChild(T),T.click(),document.body.removeChild(T),window.URL.revokeObjectURL(ee),b({type:"success",text:s("config:data.exportSuccess")})}catch(D){b({type:"error",text:D.message||"Export failed"})}finally{n(!1)}}},k=async v=>{var F;const D=(F=v.target.files)==null?void 0:F[0];if(D){u(D),b(null),m(null),c(new Set);try{const Q=await je(ke("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await D.arrayBuffer()});if(!Q.ok){const A=await Q.json();throw new Error(A.error||"Failed to preview config file")}const ee=await Q.json(),T=Array.isArray(ee.categories)?ee.categories:[];m({...ee,categories:T}),c(new Set(T.map(A=>A.id)))}catch(Q){b({type:"error",text:Q.message||"Failed to read config file"}),u(null)}}},O=async()=>{if(!(!S||r.size===0)){N(!0),b(null);try{const v=Array.from(r).join(","),D=await je(ke(`/api/config/import?categories=${v}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await S.arrayBuffer()}),F=await D.json();if(!D.ok)throw new Error(F.error||"Import failed");b({type:"success",text:F.message||s("config:data.importSuccess")}),u(null),m(null),c(new Set)}catch(v){b({type:"error",text:v.message||"Import failed"})}finally{N(!1)}}},V=()=>{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(mt,{checked:!!(h!=null&&h.enabled),disabled:P||!h,onChange:z})]}),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…"}),H&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:H})]})]}),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:C,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:R,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:a.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(v.id),onChange:()=>B(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name})]},v.id))}),e.jsx("button",{className:"data-action-btn export",onClick:te,disabled:x||o.size===0,children:x?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")})}),S?p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:S.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:K,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:W,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:p.categories.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:r.has(v.id),onChange:()=>q(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name}),v.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",v.fileCount," ",s("config:data.files"),")"]})]},v.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:V,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:O,disabled:g||r.size===0,children:g?s("config:data.importing"):s("config:data.importCount",{count:r.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:k,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}async function ft(){const s=await je(`${Y()}/api/system/install-info`);if(!s.ok)throw new Error(`Failed to fetch install info: ${s.statusText}`);return s.json()}function xt(s,a){const t=new AbortController;return(async()=>{try{const o=await fetch(bs(`${Y()}/api/system/self-update`),{method:"POST",signal:t.signal,headers:{Accept:"text/event-stream"}});if(!o.ok||!o.body){const x=await o.text().catch(()=>"");let n=null;try{n=JSON.parse(x)}catch{}const g=n&&typeof n=="object"&&"error"in n&&typeof n.error=="string"?n.error:`Self-update failed: ${o.status} ${o.statusText}`;s({type:"error",message:g}),a(new Error(g));return}const d=o.body.getReader(),r=new TextDecoder("utf-8");let c="";for(;;){const{value:x,done:n}=await d.read();if(n)break;c+=r.decode(x,{stream:!0});let g=c.indexOf(`
2
2
 
3
3
  `);for(;g!==-1;){const N=c.slice(0,g);c=c.slice(g+2);const S=N.split(`
4
4
  `);let u="message",p="";for(const m of S)m.startsWith(":")||(m.startsWith("event:")?u=m.slice(6).trim():m.startsWith("data:")&&(p+=(p?`