@mmmbuto/nexuscrew 0.9.11 → 0.9.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  All notable changes to NexusCrew are tracked here.
4
4
 
5
+ ## 0.9.12 — 2026-08-22 — "Build After The Bump"
6
+
7
+ - **Fixes 0.9.11, which would not start.** `frontend/dist/version.json` said
8
+ `0.9.10` while the server said `0.9.11`, so the UI refused with «incomplete
9
+ installation: frontend and server do not match». Everything else in that
10
+ package was consistent; that one byte was enough. The cause is ordering:
11
+ `vite.config.js` writes that file from `pkg.version` **at build time**, and
12
+ the bundle had been built before the version was raised. **Use 0.9.12; 0.9.11
13
+ is deprecated.**
14
+
15
+ - **A test now asserts what a checklist used to.** The frontend/package version
16
+ match had been verified by hand at every release since 0.8.2 — and a check
17
+ that lives only in a list is skipped the day someone is in a hurry. It now
18
+ fails on its own, and it was seen failing on a wrong value before it was
19
+ trusted on the right one.
20
+
5
21
  ## 0.9.11 — 2026-08-22 — "The Cell Gets Its Own Words"
6
22
 
7
23
  - **A `vl` cell now starts with its own prompt and the model you picked in the
@@ -90,4 +90,4 @@ Minimum version required to store current data is: `+U+`.
90
90
  `).filter(o=>o!==""),promptMode:e.promptMode};return e.modelFlag&&(s.model={flag:e.modelFlag,value:e.modelValue||""}),e.promptMode==="flag"&&(s.promptFlag=e.promptFlag),t&&(s.env=Object.fromEntries(e.envRows.filter(o=>!o.remove&&o.key).map(o=>[o.key,o.value]))),xy(s,e,t)}function Fs({children:e,onClose:t,label:n,error:s=""}){const o=x.useRef(null),a=x.useRef(null),u=x.useRef(t);return u.current=t,x.useEffect(()=>{const d=document.activeElement,p=o.current,m=()=>Array.from((p==null?void 0:p.querySelectorAll('button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [href], [tabindex]:not([tabindex="-1"])'))||[]).filter(b=>b.offsetParent!==null),v=requestAnimationFrame(()=>{var b;return(b=m()[0]||p)==null?void 0:b.focus({preventScroll:!0})}),y=b=>{var w;if(b.key==="Escape"){b.preventDefault(),(w=u.current)==null||w.call(u);return}if(b.key!=="Tab")return;const S=m();if(!S.length){b.preventDefault(),p==null||p.focus();return}const k=S[0],E=S[S.length-1];b.shiftKey&&document.activeElement===k?(b.preventDefault(),E.focus()):!b.shiftKey&&document.activeElement===E&&(b.preventDefault(),k.focus())};return document.addEventListener("keydown",y),()=>{cancelAnimationFrame(v),document.removeEventListener("keydown",y),d&&d.isConnected&&typeof d.focus=="function"&&d.focus({preventScroll:!0})}},[]),x.useEffect(()=>{s&&requestAnimationFrame(()=>{var d;return(d=a.current)==null?void 0:d.scrollIntoView({block:"nearest"})})},[s]),l.jsx("div",{className:"nc-fleet-modal",role:"presentation",onMouseDown:d=>{d.target===d.currentTarget&&t()},children:l.jsxs("div",{ref:o,className:"nc-fleet-modal-dialog",role:"dialog","aria-modal":"true","aria-label":n||f("settings"),tabIndex:-1,children:[e,s&&l.jsx("div",{ref:a,className:"nc-err nc-fleet-modal-error",role:"alert","aria-live":"assertive",children:s})]})})}function ch({token:e,targets:t=[],readonly:n=!1,onPower:s,onImport:o}){const[a,u]=x.useState([]),[d,p]=x.useState(0);x.useEffect(()=>{let w=!0;async function N(){const M=[{route:[],label:f("local")}].concat((t||[]).map(G=>({route:Array.isArray(G.route)?G.route:[],label:G.label||(G.route||[]).join(" › ")}))),I=await Promise.all(M.map(async G=>{const W={...G,available:!1,readonly:!1,capabilities:[],provider:null,cells:[],unmanaged:[],err:""};try{const V=await Gs(e,G.route);W.available=!!V.available,W.capabilities=V.capabilities||[],W.provider=V.provider||null,W.cells=(V.cells||[]).map(K=>({...K,route:G.route}));try{W.readonly=!!(await Lf(e,G.route)).readonlyDefault}catch{}try{const K=await Pf(e,G.route),Y=new Set(W.cells.map(Z=>Z.tmuxSession).filter(Boolean));W.unmanaged=(K.sessions||[]).filter(Z=>Z&&!Y.has(Z.name))}catch{}}catch(V){W.err=String(V&&V.message||V)}return W}));w&&u(I)}N();const C=setInterval(N,6e3);return()=>{w=!1,clearInterval(C)}},[e,t,d]);const m=(w,N)=>Array.isArray(w.capabilities)&&w.capabilities.includes(N)&&!n&&!w.readonly,v=()=>p(w=>w+1),y=(w,N)=>{s&&s({...w,route:N})},b=(w,N)=>{s&&s({...w,route:N})},S=async(w,N)=>{try{await ha(e,w.cell,N)}catch{}v()},k=async(w,N)=>{if(window.confirm(f("fleet-remove-cell").replace("{id}",w.cell))){try{await zy(e,w.cell,!0,N)}catch{}v()}},E=async(w,N)=>{if(window.confirm(f("terminate-confirm").replace("{name}",w.name))){try{await jf(e,w.name,N)}catch{}v()}};return l.jsxs("div",{className:"nc-fleet-inventory",children:[l.jsxs("div",{className:"nc-fleet-section-head",children:[l.jsx("b",{children:f("fleet-inventory")}),l.jsx("small",{children:f("fleet-inventory-help")})]}),a.map(w=>{const N=w.route.length?w.route.join("/"):"local";return l.jsxs("div",{className:"nc-fleet-pos",children:[l.jsxs("div",{className:"nc-fleet-pos-title",children:[l.jsx("span",{className:`dot ${w.available?"on":"warn"}`}),l.jsx("b",{children:w.label}),l.jsx("small",{children:w.available?`${w.cells.length} ${f("fleet-cells")} · ${w.unmanaged.length} ${f("fleet-tmux")}`:w.err||f("fleet-not-available")})]}),w.cells.map(C=>l.jsxs("div",{className:"nc-fleet-item nc-fleet-cell",children:[l.jsxs("span",{children:[l.jsx("b",{children:C.cell}),l.jsx("small",{children:`${C.engine||""}${C.key?`·${C.key}`:""}${C.active?"":` · ${f("cell-off")}`}`})]}),l.jsxs("span",{className:"nc-fleet-cell-actions",children:[C.active&&m(w,"down")&&l.jsx("button",{className:"nc-btn ghost",title:f("power-off"),onClick:()=>b(C,w.route),children:f("stop")}),!C.active&&m(w,"up")&&l.jsx("button",{className:"nc-btn ghost",title:f("power-on"),onClick:()=>y(C,w.route),children:f("start")}),m(w,"restart")&&C.active&&l.jsx("button",{className:"nc-btn ghost",title:f("restart"),onClick:()=>S(C,w.route),children:f("restart")}),m(w,"remove")&&l.jsx("button",{className:"nc-btn danger",title:f("delete"),onClick:()=>k(C,w.route),children:"×"})]})]},`${N}:${C.cell}`)),w.unmanaged.map(C=>l.jsxs("div",{className:"nc-fleet-item nc-fleet-unmanaged",children:[l.jsxs("span",{children:[l.jsx("b",{children:C.name}),l.jsx("small",{children:f("fleet-tmux")})]}),l.jsxs("span",{className:"nc-fleet-cell-actions",children:[m(w,"import")&&o&&l.jsx("button",{className:"nc-btn ghost",title:f("import-as-cell"),onClick:()=>o(C,w.route),children:f("import-as-cell")}),l.jsx("button",{className:"nc-btn danger",title:f("terminate"),onClick:()=>E(C,w.route),children:"×"})]})]},`${N}:u:${C.name}`)),w.available&&w.cells.length===0&&w.unmanaged.length===0&&l.jsx("div",{className:"nc-empty",children:f("fleet-inventory-empty")})]},N)})]})}function xR({cells:e=[],engines:t=[],models:n=[],busy:s,canRestore:o=!1,onRestore:a,onClose:u}){const[d,p]=x.useState("export"),[m,v]=x.useState([]),[y,b]=x.useState(()=>new Set(e.map(L=>L.id))),[S,k]=x.useState(()=>new Set(t.map(L=>L.id))),[E,w]=x.useState([]),[N,C]=x.useState([]),[M,I]=x.useState(""),G=new Set(t.map(L=>L.id)),W=new Set(e.map(L=>L.id)),V=(L,T)=>L(j=>{const B=new Set(j);return B.has(T)?B.delete(T):B.add(T),B}),K=()=>{const L=gR(e,y,t,S,new Date,n);if(L.ok===!1){I(f(`fleet-backup-${L.error}`));return}const T=e.filter(O=>y.has(O.id)).length,j=t.filter(O=>S.has(O.id)).length;if(L.cells.length!==T){I(f("fleet-backup-invalid-cell"));return}if(L.engines.length!==j){I(f("fleet-backup-invalid-engine"));return}if(!L.cells.length&&!L.engines.length){I(f("fleet-backup-select-one"));return}const B=new Blob([`${JSON.stringify(L,null,2)}
91
91
  `],{type:"application/json"}),A=URL.createObjectURL(B),D=document.createElement("a");D.href=A,D.download=`nexuscrew-fleet-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild(D),D.click(),D.remove(),setTimeout(()=>URL.revokeObjectURL(A),0),I("")},Y=async L=>{if(I(""),w([]),C([]),!!L){if(L.size>1024*1024){I(f("fleet-backup-too-large"));return}try{const T=vR(await L.text());if(!T.ok){I(f(`fleet-backup-${T.error}`));return}v(Array.isArray(T.models)?T.models:[]);const j=new Set(T.engines.map(B=>B.id));C(T.engines.map(B=>({engine:B,exists:G.has(B.id),selected:!G.has(B.id)}))),w(T.cells.map(B=>{const A=G.has(B.engine)||j.has(B.engine),D=W.has(B.id);return{cell:B,engine:A?B.engine:"",selected:A&&!D,exists:D}}))}catch(T){I(String(T.message||T))}}},Z=(L,T)=>w(j=>j.map((B,A)=>A===L?{...B,...T}:B)),U=(L,T)=>C(j=>j.map((B,A)=>A===L?{...B,...T}:B)),$=new Set([...G,...N.filter(L=>L.selected).map(L=>L.engine.id)]),R=E.filter(L=>L.selected&&L.engine&&$.has(L.engine)),z=N.filter(L=>L.selected),F=[...new Map([...t.map(L=>[L.id,L.label||L.id]),...N.filter(L=>L.selected).map(L=>[L.engine.id,L.engine.label||L.engine.id])]).entries()];return l.jsxs("div",{className:"nc-set-form nc-fleet-form nc-backup-dialog",children:[l.jsx("b",{children:f("fleet-backup")}),l.jsx("small",{children:f("fleet-backup-help")}),l.jsxs("div",{className:"nc-set-tabs nc-backup-tabs",children:[l.jsx("button",{type:"button",className:`nc-set-tabbtn${d==="export"?" on":""}`,onClick:()=>{p("export"),I("")},children:f("fleet-backup-export")}),l.jsx("button",{type:"button",className:`nc-set-tabbtn${d==="import"?" on":""}`,disabled:!o,title:o?"":f("fleet-backup-restore-unavailable"),onClick:()=>{p("import"),I("")},children:f("fleet-backup-import")})]}),d==="export"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:()=>{b(new Set(e.map(L=>L.id))),k(new Set(t.map(L=>L.id)))},children:f("select-all")}),l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:()=>{b(new Set),k(new Set)},children:f("select-none")})]}),l.jsxs("div",{className:"nc-backup-list",children:[l.jsx("b",{children:f("fleet-engines")}),t.map(L=>{var T;return l.jsxs("label",{className:"nc-check nc-backup-row",children:[l.jsx("input",{type:"checkbox",checked:S.has(L.id),onChange:()=>V(k,L.id)}),l.jsxs("span",{children:[l.jsx("b",{children:L.label||L.id}),l.jsxs("small",{children:[L.id,(T=L.envKeys)!=null&&T.length?` · ${L.envKeys.length} ${f("fleet-backup-env-names")}`:""]})]})]},L.id)}),l.jsx("b",{children:f("fleet-cells")}),e.map(L=>l.jsxs("label",{className:"nc-check nc-backup-row",children:[l.jsx("input",{type:"checkbox",checked:y.has(L.id),onChange:()=>V(b,L.id)}),l.jsxs("span",{children:[l.jsx("b",{children:L.id}),l.jsxs("small",{children:[L.engine," · ",f("fleet-system-prompt")," ",(L.prompt||"").length," ",f("characters")]})]})]},L.id)),!e.length&&!t.length&&l.jsx("div",{className:"nc-empty",children:f("fleet-backup-empty")})]}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:u,children:f("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:!y.size&&!S.size,onClick:K,children:f("fleet-backup-download")})]})]}):l.jsxs(l.Fragment,{children:[l.jsx("input",{type:"file",accept:"application/json,.json",disabled:s,onChange:L=>Y(L.target.files&&L.target.files[0])}),l.jsx("small",{children:f("fleet-backup-import-help")}),!!(E.length||N.length)&&l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:()=>{C(L=>L.map(T=>({...T,selected:!0}))),w(L=>L.map(T=>({...T,selected:!!T.engine})))},children:f("select-all")}),l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:()=>{C(L=>L.map(T=>({...T,selected:!1}))),w(L=>L.map(T=>({...T,selected:!1})))},children:f("select-none")})]}),l.jsxs("div",{className:"nc-backup-list",children:[!!N.length&&l.jsx("b",{children:f("fleet-engines")}),N.map((L,T)=>{var j;return l.jsx("div",{className:"nc-backup-import-row",children:l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:L.selected,onChange:B=>U(T,{selected:B.target.checked})}),l.jsxs("span",{children:[l.jsx("b",{children:L.engine.label||L.engine.id}),l.jsxs("small",{children:[L.engine.id," · ",L.exists?f("fleet-backup-overwrite"):f("fleet-backup-new"),(j=L.engine.envKeys)!=null&&j.length?` · ${f("fleet-backup-env-values-required")}`:""]})]})]})},L.engine.id)}),!!E.length&&l.jsx("b",{children:f("fleet-cells")}),E.map((L,T)=>l.jsxs("div",{className:"nc-backup-import-row",children:[l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:L.selected,disabled:!L.engine||!$.has(L.engine),onChange:j=>Z(T,{selected:j.target.checked})}),l.jsxs("span",{children:[l.jsx("b",{children:L.cell.id}),l.jsxs("small",{children:[L.exists?f("fleet-backup-overwrite"):f("fleet-backup-new")," · ",f("fleet-system-prompt")," ",L.cell.systemPrompt.length," ",f("characters")]})]})]}),l.jsxs("select",{value:L.engine,onChange:j=>Z(T,{engine:j.target.value,selected:!!j.target.value}),children:[l.jsx("option",{value:"",children:f("fleet-backup-engine-missing")}),F.map(([j,B])=>l.jsx("option",{value:j,children:B},j))]})]},L.cell.id))]}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:u,children:f("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:s||!R.length&&!z.length,onClick:()=>a({engineRows:N,cellRows:E,models:m}),children:f("fleet-backup-restore")})]})]}),M&&l.jsx("div",{className:"nc-err",children:M})]})}function kR({state:e,setState:t,busy:n,onSave:s,catalog:o}){var N;const a=e.form,u=C=>t({...e,form:{...a,...C}}),d=a.envRows||[],p=[...new Map(o.map(C=>[C.client,C.clientLabel||C.client])).entries()],m=o.filter(C=>C.client===a.client),v=Na(o,a),y=typeof(v==null?void 0:v.credentialEnv)=="string"?v.credentialEnv:"",b=Array.isArray(v==null?void 0:v.credentialUsedBy)?v.credentialUsedBy:[],S=(v==null?void 0:v.credentialSource)||"missing",k=!!(v!=null&&v.credentialEnv)||a.credentialProfile==="a"||a.credentialProfile==="p",E=!!y&&e.mode==="new"&&(v==null?void 0:v.authConfigured)!==!0&&!a.credentialValue&&!a.allowMissingCredential,w=C=>{C&&u({client:C.client,provider:C.provider,credentialProfile:C.credentialProfile||"",managedModel:C.model||"",protocol:C.protocol||"",permissionPolicy:C.permissionPolicyDefault||"standard",credentialSourcePolicy:"auto",rc:!!C.rc,displayName:C.custom?f("fleet-custom-provider-default"):"",baseUrl:C.custom?"":C.endpoint||"",envKey:C.defaultEnvKey||"",providerId:"nexuscrew-custom",credentialValue:"",credentialReveal:!1,allowMissingCredential:!1,...e.mode==="new"?{id:C.id,label:""}:{}})};return l.jsxs("div",{className:"nc-set-form nc-fleet-form",children:[l.jsx("b",{children:e.mode==="new"?f("fleet-new-engine"):`${f("edit")} ${a.id}`}),l.jsx("input",{value:a.id,disabled:e.mode!=="new",placeholder:"id",onChange:C=>u({id:C.target.value})}),l.jsx("input",{value:a.label,placeholder:f("label"),onChange:C=>u({label:C.target.value})}),l.jsxs("select",{value:a.kind,disabled:e.mode!=="new",onChange:C=>u({kind:C.target.value}),children:[l.jsx("option",{value:"managed",children:f("fleet-managed")}),l.jsx("option",{value:"custom",children:f("fleet-custom")})]}),a.kind==="managed"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"nc-fleet-pair",children:[l.jsx("select",{value:a.client,disabled:e.mode!=="new",onChange:C=>w(o.find(M=>M.client===C.target.value&&M.default)||o.find(M=>M.client===C.target.value)),children:p.map(([C,M])=>l.jsx("option",{value:C,children:M},C))}),l.jsx("select",{value:((N=Na(o,a))==null?void 0:N.id)||"",disabled:e.mode!=="new",onChange:C=>w(o.find(M=>M.id===C.target.value)),children:m.map(C=>l.jsx("option",{value:C.id,children:C.label},C.id))})]}),a.client!=="shell"&&l.jsxs(l.Fragment,{children:[l.jsx("input",{value:a.managedModel,list:"nc-managed-models",placeholder:f(v!=null&&v.requiresModel?"fleet-model-required":"fleet-model-default"),onChange:C=>u({managedModel:C.target.value})}),l.jsx("datalist",{id:"nc-managed-models",children:[...(v==null?void 0:v.models)||[],...a.modelOptions||[]].filter((C,M,I)=>C&&I.indexOf(C)===M).map(C=>l.jsx("option",{value:C},C))})]}),v!=null&&v.supportsUnsafe?l.jsxs("select",{value:a.permissionPolicy,onChange:C=>u({permissionPolicy:C.target.value}),children:[l.jsx("option",{value:"standard",children:f("fleet-standard-permissions")}),l.jsx("option",{value:"unsafe",children:f("fleet-unsafe-permissions")})]}):l.jsx("small",{children:f("fleet-standard-permissions")}),(v==null?void 0:v.supportsUnsafe)&&a.permissionPolicy==="unsafe"&&l.jsx("small",{className:"nc-err",children:f("fleet-unsafe-warning")}),k&&l.jsxs("select",{"aria-label":f("fleet-credential-source-policy"),value:a.credentialSourcePolicy||"auto",onChange:C=>u({credentialSourcePolicy:C.target.value}),children:[l.jsx("option",{value:"auto",children:f("fleet-credential-source-policy-auto")}),l.jsx("option",{value:"nexuscrew-store",children:f("fleet-credential-source-policy-nexuscrew-store")}),l.jsx("option",{value:"environment",children:f("fleet-credential-source-policy-environment")})]}),(v==null?void 0:v.credentialEnv)===!0&&l.jsxs(l.Fragment,{children:[l.jsx("input",{value:a.envKey,placeholder:f("fleet-api-key-env"),onChange:C=>u({envKey:C.target.value})}),l.jsx("small",{children:f("fleet-custom-secret-help")})]}),y&&l.jsxs("section",{className:"nc-fleet-key","aria-label":f("fleet-key-section"),children:[l.jsxs("div",{className:"nc-fleet-key-head",children:[l.jsx("b",{children:f("fleet-key-section")}),l.jsx("span",{children:f(`fleet-credential-source-${S}`)})]}),l.jsxs("label",{className:"nc-field",children:[f("fleet-key-variable"),l.jsx("input",{value:y,readOnly:!0,"aria-label":f("fleet-key-variable")})]}),l.jsx("small",{children:b.length?f("fleet-key-used-by").replace("{engines}",b.join(", ")):f("fleet-key-used-by-none")}),b.length>0&&l.jsx("small",{children:f("fleet-key-shared-impact").replace("{key}",y).replace("{engines}",b.join(", "))}),l.jsxs("div",{className:"nc-fleet-key-input",children:[l.jsx("input",{type:a.credentialReveal?"text":"password",value:a.credentialValue||"","aria-label":f("fleet-key-value").replace("{key}",y),autoComplete:"new-password",spellCheck:!1,autoCapitalize:"none",autoCorrect:"off",placeholder:v!=null&&v.authConfigured||e.mode==="edit"?f("fleet-key-blank-keeps"):f("fleet-key-enter"),onChange:C=>u({credentialValue:C.target.value,allowMissingCredential:C.target.value?!1:a.allowMissingCredential})}),l.jsx("button",{type:"button",className:"nc-btn ghost","aria-label":f(a.credentialReveal?"fleet-key-hide":"fleet-key-reveal"),onClick:()=>u({credentialReveal:!a.credentialReveal}),children:f(a.credentialReveal?"fleet-key-hide":"fleet-key-reveal")})]}),l.jsx("small",{children:f("fleet-key-local-help")}),e.mode==="new"&&(v==null?void 0:v.authConfigured)!==!0&&!a.credentialValue&&l.jsxs("label",{className:"nc-check nc-fleet-key-missing",children:[l.jsx("input",{type:"checkbox",checked:!!a.allowMissingCredential,onChange:C=>u({allowMissingCredential:C.target.checked})}),f("fleet-key-create-missing")]}),(v==null?void 0:v.notice)&&l.jsx("small",{className:"nc-fleet-provider-notice",children:f(`fleet-provider-notice-${v.notice}`)})]}),(v==null?void 0:v.notice)&&!y&&l.jsx("small",{className:"nc-fleet-provider-notice",children:f(`fleet-provider-notice-${v.notice}`)}),a.provider==="custom"&&l.jsxs(l.Fragment,{children:[l.jsx("input",{value:a.displayName,placeholder:f("fleet-provider-display"),onChange:C=>u({displayName:C.target.value})}),l.jsx("input",{value:a.baseUrl,placeholder:"https://api.example.com/v1",onChange:C=>u({baseUrl:C.target.value})}),((v==null?void 0:v.protocols)||[]).length>1&&l.jsx("select",{value:a.protocol,onChange:C=>u({protocol:C.target.value}),children:v.protocols.map(C=>l.jsx("option",{value:C,children:C},C))}),l.jsxs("div",{className:"nc-fleet-pair",children:[l.jsx("input",{value:a.envKey,placeholder:f("fleet-api-key-env"),onChange:C=>u({envKey:C.target.value})}),l.jsx("input",{value:a.providerId,placeholder:f("fleet-provider-id"),onChange:C=>u({providerId:C.target.value})})]}),l.jsxs("small",{children:[a.protocol," · ",f("fleet-custom-secret-help")]})]}),l.jsx("small",{children:f(a.client==="shell"?"fleet-shell-engine-help":"fleet-managed-help")})]}):l.jsxs(l.Fragment,{children:[l.jsx("input",{value:a.command,placeholder:f("command-path"),onChange:C=>u({command:C.target.value})}),l.jsx("textarea",{value:a.argsText,placeholder:f("args-lines"),onChange:C=>u({argsText:C.target.value})}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:a.rc,onChange:C=>u({rc:C.target.checked})})," ",f("fleet-remote-control")]}),l.jsxs("select",{value:a.promptMode,onChange:C=>u({promptMode:C.target.value}),children:[l.jsx("option",{value:"send-keys",children:"send-keys"}),l.jsx("option",{value:"flag",children:"flag"})]}),a.promptMode==="flag"&&l.jsx("input",{value:a.promptFlag,placeholder:"prompt flag",onChange:C=>u({promptFlag:C.target.value})}),l.jsxs("div",{className:"nc-fleet-pair",children:[l.jsx("input",{value:a.modelFlag,placeholder:"model flag",onChange:C=>u({modelFlag:C.target.value})}),l.jsx("input",{value:a.modelValue,placeholder:"model default",onChange:C=>u({modelValue:C.target.value})})]}),l.jsx("small",{children:f("env-write-only")}),d.map((C,M)=>l.jsxs("div",{className:"nc-fleet-env",children:[l.jsx("input",{value:C.key,disabled:C.configured,placeholder:"ENV_KEY",onChange:I=>{const G=d.slice();G[M]={...C,key:I.target.value},u({envRows:G})}}),l.jsx("input",{type:"password",value:C.value,placeholder:C.configured?"•••••• (unchanged)":"value",onChange:I=>{const G=d.slice();G[M]={...C,value:I.target.value},u({envRows:G})}}),l.jsx("button",{className:"nc-btn danger",onClick:()=>u({envRows:d.filter((I,G)=>G!==M)}),children:"×"})]},`${C.key}-${M}`)),l.jsx("button",{className:"nc-btn ghost",onClick:()=>u({envRows:[...d,{key:"",value:"",configured:!1}]}),children:"+ env"})]}),l.jsx("input",{value:a.panelUrl||"",maxLength:512,placeholder:f("fleet-panel-url"),onChange:C=>u({panelUrl:C.target.value})}),l.jsx("small",{children:f("fleet-panel-url-help")}),a.panelUrl&&!_p(a.panelUrl)&&l.jsx("small",{className:"nc-err",children:f("fleet-panel-url-invalid")}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{className:"nc-btn ghost",onClick:()=>t(null),children:f("cancel")}),l.jsx("button",{className:"nc-btn primary",disabled:n||!a.id||E||a.kind==="custom"&&!a.command||a.kind==="managed"&&(v==null?void 0:v.requiresModel)&&!a.managedModel||a.kind==="managed"&&(v==null?void 0:v.credentialEnv)===!0&&!a.envKey||a.kind==="managed"&&a.provider==="custom"&&(!a.displayName||!a.baseUrl||!a.envKey||!a.providerId),onClick:s,children:f("save")})]})]})}function CR({state:e,setState:t,busy:n,onSave:s,onTest:o,profiles:a=[],canTest:u=!0}){const[d,p]=x.useState(null),[m,v]=x.useState(!1),y=e.form,b=w=>t({...e,form:{...y,...w}}),S=/^[^\x00-\x1f\x7f]{1,128}$/.test(y.id||""),k=!!(y.id||"").trim()&&!!(y.engine||"").trim()&&S,E=async()=>{p(null),v(!0);try{p(await o(y.engine,y.id))}catch(w){p({outcome:"unverified",detail:String(w&&w.message||w)})}v(!1)};return l.jsxs("div",{className:"nc-fleet-form",children:[l.jsxs("label",{className:"nc-field",children:[f("model-editor-engine"),l.jsxs("select",{value:y.engine||"",disabled:n||e.mode==="edit",onChange:w=>{p(null),b({engine:w.target.value})},children:[l.jsx("option",{value:"",children:"—"}),a.map(w=>l.jsx("option",{value:w.id,children:w.label?`${w.id} · ${w.label}`:w.id},w.id))]})]}),l.jsxs("label",{className:"nc-field",children:[f("model-editor-id"),l.jsx("input",{value:y.id||"",disabled:n||e.mode==="edit",placeholder:"qwen3.9-max",onChange:w=>{p(null),b({id:w.target.value})}})]}),l.jsx("small",{className:"nc-set-hint",children:f("model-editor-id-help")}),l.jsxs("label",{className:"nc-field",children:[f("model-editor-context"),l.jsx("input",{inputMode:"numeric",value:y.contextWindow||"",disabled:n,onChange:w=>b({contextWindow:w.target.value.replace(/[^0-9]/g,"").slice(0,9)})})]}),l.jsxs("label",{className:"nc-field",children:[f("model-editor-max-tokens"),l.jsx("input",{inputMode:"numeric",value:y.maxTokens||"",disabled:n,onChange:w=>b({maxTokens:w.target.value.replace(/[^0-9]/g,"").slice(0,9)})})]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:y.reasoning===!0,disabled:n,onChange:w=>b({reasoning:w.target.checked})})," ",f("model-editor-reasoning")]}),l.jsxs("div",{className:"nc-set-row",children:[u&&l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||m||!k,onClick:E,children:f(m?"model-test-running":"model-test")}),d&&l.jsxs("span",{className:`nc-model-test ${d.outcome}`,children:[f(`model-test-${d.outcome}`),d.outcome==="ok"&&Number.isInteger(d.latencyMs)?` · ${d.latencyMs}ms`:""]})]}),d&&d.detail&&l.jsx("small",{className:"nc-set-hint",children:d.detail}),d&&d.outcome==="unverified"&&l.jsx("small",{className:"nc-set-hint",children:f("model-test-unverified-help")}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:()=>t(null),children:f("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||!k,onClick:()=>s(y),children:f("save")})]})]})}function ER({token:e,route:t,targets:n=[],location:s,setLocation:o,state:a,setState:u,engines:d,mcpServers:p=[],managedCatalog:m=[],busy:v,onSave:y}){var z,F,L;const[b,S]=x.useState(null),[k,E]=x.useState(""),w=a.form,N=T=>u({...a,form:{...w,...T}}),C=d.find(T=>T.id===w.engine),M=((z=C==null?void 0:C.managed)==null?void 0:z.client)==="shell",I=((F=C==null?void 0:C.managed)==null?void 0:F.client)||"",G=((L=m.find(T=>T.client===I))==null?void 0:L.mcpManaged)!==!1,W=T=>{var A,D,O,H;const j=d.find(ie=>ie.id===T),B={...w.commands||{}};((A=C==null?void 0:C.managed)==null?void 0:A.client)==="shell"&&(w.command?B[w.engine]=w.command:delete B[w.engine]),N({engine:T,model:((D=w.models)==null?void 0:D[T])||((O=j==null?void 0:j.managed)==null?void 0:O.model)||((H=j==null?void 0:j.model)==null?void 0:H.value)||"",commands:B,command:B[T]||""})},V=T=>{const j={...w.commands||{}};T?j[w.engine]=T:delete j[w.engine],N({command:T,commands:j})},K=M&&/[|&;<>()`$*?{}\[\]~]/.test(w.command||""),Y=[...new Set([...p||[],...Array.isArray(w.mcp)?w.mcp:[]])].sort(),Z=Array.isArray(w.mcp)?w.mcp.length?"some":"none":"all",U=T=>{var j;return N({mcp:T==="all"?void 0:T==="none"?[]:(j=w.mcp)!=null&&j.length?w.mcp:[...Y]})},$=T=>{const j=Array.isArray(w.mcp)?w.mcp:[];N({mcp:j.includes(T)?j.filter(B=>B!==T):[...j,T].sort()})},R=async T=>{try{const j=await Rf(e,T,t);S(j),N({cwd:j.path}),E("")}catch(j){E(String(j.message||j))}};return l.jsxs("div",{className:"nc-set-form nc-fleet-form",children:[l.jsx("b",{children:a.mode==="new"?f("fleet-new-cell"):`${f("edit")} ${w.id}`}),a.mode==="new"&&l.jsxs("label",{className:"nc-field",children:[f("location"),l.jsx("span",{className:"nc-req",children:" *"}),l.jsxs("select",{value:s,onChange:T=>{o(T.target.value),N({engine:""})},children:[l.jsx("option",{value:"",children:f("local")}),n.map(T=>l.jsxs("option",{value:T.route.join("/"),disabled:T.status&&T.status!=="up",children:[T.label,T.status&&T.status!=="up"?` · ${f("node-offline")}`:""]},T.route.join("/")))]})]}),l.jsx("input",{value:w.id,disabled:a.mode!=="new",placeholder:"id",onChange:T=>N({id:T.target.value})}),l.jsx("input",{value:w.label||"",maxLength:64,placeholder:f("fleet-cell-label"),onChange:T=>N({label:T.target.value})}),l.jsxs("div",{className:"nc-fleet-pair",children:[l.jsx("input",{value:w.cwd,placeholder:f("cwd"),onChange:T=>N({cwd:T.target.value})}),l.jsx("button",{className:"nc-btn ghost",onClick:()=>b?S(null):R(w.cwd),children:f("browse")})]}),b&&l.jsxs("div",{className:"nc-fs",children:[l.jsx("div",{className:"nc-fs-path",children:b.path}),l.jsxs("div",{className:"nc-fs-list",children:[b.parent&&l.jsxs("button",{className:"nc-fs-item nc-fs-nav",onClick:()=>R(b.parent),children:["↑ ",f("fs-parent")]}),(b.dirs||[]).map(T=>l.jsxs("button",{className:"nc-fs-item",onClick:()=>R(`${b.path.replace(/\/$/,"")}/${T}`),children:["📁 ",T]},T))]})]}),k&&l.jsx("div",{className:"nc-err",children:k}),l.jsx("select",{value:w.engine,onChange:T=>W(T.target.value),children:d.map(T=>l.jsx("option",{value:T.id,children:T.label},T.id))}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:!!w.boot,onChange:T=>N({boot:T.target.checked})})," ",f("fleet-boot")]}),l.jsx("input",{value:w.panelUrl||"",maxLength:512,placeholder:f("fleet-panel-url"),onChange:T=>N({panelUrl:T.target.value})}),l.jsx("small",{children:f("fleet-panel-url-help")}),w.panelUrl&&!_p(w.panelUrl)&&l.jsx("small",{className:"nc-err",children:f("fleet-panel-url-invalid")}),M?l.jsxs(l.Fragment,{children:[l.jsx("input",{value:w.command||"",maxLength:4096,placeholder:f("fleet-shell-command-placeholder"),onChange:T=>V(T.target.value)}),l.jsx("small",{children:w.command?f("fleet-shell-command-help"):f("fleet-shell-interactive")}),K&&l.jsx("small",{className:"nc-note",children:f("fleet-shell-command-metachar")})]}):l.jsxs(l.Fragment,{children:[l.jsx("input",{value:w.model||"",list:"nc-cell-models",placeholder:f("fleet-model-override"),onChange:T=>N({model:T.target.value})}),l.jsx("datalist",{id:"nc-cell-models",children:((C==null?void 0:C.availableModels)||[]).map(T=>l.jsx("option",{value:T},T))}),l.jsx("textarea",{value:w.prompt||"",placeholder:f("cell-prompt"),onChange:T=>N({prompt:T.target.value})}),l.jsx("small",{children:f("cell-prompt-help")}),l.jsxs("label",{className:"nc-field",children:[f("cell-mcp"),l.jsxs("select",{value:Z,onChange:T=>U(T.target.value),children:[l.jsx("option",{value:"all",children:f("cell-mcp-all")}),l.jsx("option",{value:"none",children:f("cell-mcp-none")}),l.jsx("option",{value:"some",children:f("cell-mcp-some")})]})]}),!G&&l.jsx("small",{className:"nc-note",children:f("cell-mcp-inert")}),Z==="some"&&l.jsx("div",{className:"nc-fleet-mcp-list",children:Y.map(T=>l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:(w.mcp||[]).includes(T),onChange:()=>$(T)})," ",T]},T))}),l.jsx("small",{children:f("cell-mcp-help")})]}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{className:"nc-btn ghost",onClick:()=>u(null),children:f("cancel")}),l.jsx("button",{className:"nc-btn primary",disabled:v||!w.id||!w.cwd||!w.engine,onClick:y,children:f("save")})]})]})}function ky({token:e,route:t=[],state:n,setState:s,busy:o,onSave:a}){const[u,d]=x.useState(null),[p,m]=x.useState([]),[v,y]=x.useState(""),b=Array.isArray(t)?t.join("/"):"";x.useEffect(()=>{let N=!0;return kc(e,b?b.split("/"):[]).then(C=>{N&&(m(C.engines||[]),y(""))}).catch(C=>{N&&(m([]),y(String(C.message||C)))}),()=>{N=!1}},[e,b]);const S=n.form,k=N=>s({...n,form:{...S,...N}}),E=async N=>{try{const C=await Rf(e,N,t);d(C),k({cwd:C.path})}catch{}},w=!S.id&&S.tmuxSession?S.tmuxSession.replace(/[^A-Za-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,32):S.id;return l.jsxs("div",{className:"nc-set-form nc-fleet-form",children:[l.jsxs("b",{children:[f("import-as-cell")," · ",S.tmuxSession]}),l.jsx("small",{children:f("import-help")}),l.jsx("input",{value:S.tmuxSession,disabled:!0,placeholder:"tmux session",readOnly:!0}),l.jsx("input",{value:S.id,placeholder:f("name"),onChange:N=>k({id:N.target.value})}),l.jsxs("div",{className:"nc-fleet-pair",children:[l.jsx("input",{value:S.cwd,placeholder:f("cwd"),onChange:N=>k({cwd:N.target.value})}),l.jsx("button",{className:"nc-btn ghost",type:"button",onClick:()=>u?d(null):E(S.cwd),children:f("browse")})]}),u&&l.jsxs("div",{className:"nc-fs",children:[l.jsx("div",{className:"nc-fs-path",children:u.path}),l.jsxs("div",{className:"nc-fs-list",children:[u.parent&&l.jsxs("button",{className:"nc-fs-item nc-fs-nav",onClick:()=>E(u.parent),children:["↑ ",f("fs-parent")]}),(u.dirs||[]).map(N=>l.jsxs("button",{className:"nc-fs-item",onClick:()=>E(`${u.path.replace(/\/$/,"")}/${N}`),children:["📁 ",N]},N))]})]}),l.jsxs("select",{value:S.engine,onChange:N=>k({engine:N.target.value}),children:[l.jsx("option",{value:"",children:f("import-engine-required")}),p.map(N=>l.jsx("option",{value:N.id,children:N.label},N.id))]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:!!S.boot,onChange:N=>k({boot:N.target.checked})})," ",f("fleet-boot")]}),(n.err||v)&&l.jsx("div",{className:"nc-err",children:n.err||v}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{className:"nc-btn ghost",onClick:()=>s(null),children:f("cancel")}),l.jsx("button",{className:"nc-btn primary",disabled:o||!S.tmuxSession||!S.engine||!p.length,onClick:a,children:f(w?"import-as-cell":"save")})]})]})}function Ql(e){const t=br(e);return t===null?`~/${e}`:t?`~/${t}`:"~"}function NR(e){if(!e||typeof e.path!="string"||typeof e.home!="string")return"";const{path:t,home:n}=e;return!n||t===n||!t.startsWith(n+"/")?"":t.slice(n.length+1).replace(/\/+$/,"")}function jR({token:e,route:t,cell:n,busy:s=!1,onSaved:o,onClose:a}){const[u,d]=x.useState(""),[p,m]=x.useState(null),[v,y]=x.useState(!1),[b,S]=x.useState(""),k=typeof(n==null?void 0:n.cwdSuggestion)=="string"&&br(n.cwdSuggestion)!==null?br(n.cwdSuggestion):null,[E,w]=x.useState(k),N=n==null?void 0:n.id,C=s||v,M=async Y=>{const Z=br(Y);if(Z===null){m({rel:"",dirs:[],loading:!1,err:f("fleet-cwd-repair-invalid")});return}m({rel:Z,dirs:[],loading:!0,err:""});try{const U=await Rf(e,Z,t),$=NR(U);m({rel:$,dirs:Array.isArray(U.dirs)?U.dirs:[],loading:!1,err:""})}catch(U){m({rel:Z,dirs:[],loading:!1,err:String(U&&U.message||U)})}},I=Y=>{if(!p)return;const Z=p.rel?`${p.rel}/${Y}`:Y;M(Z)},G=()=>{p!=null&&p.rel&&M(p.rel.split("/").slice(0,-1).join("/"))},W=()=>{p&&(d(p.rel||""),m(null),S(""),w(null))},V=()=>{E!==null&&(d(E),w(null),S(""))},K=async()=>{if(C)return;const Y=br(u);if(Y===null){S(f("fleet-cwd-repair-invalid"));return}const Z=Ql(Y);let U=!0;try{U=window.confirm(f("fleet-cwd-repair-confirm").replace("{id}",String(N||"")).replace("{path}",Z))}catch{U=!1}if(U){y(!0),S(""),w(null);try{const $=await By(e,N,{cwdRel:Y},t);o==null||o($)}catch($){const R=$&&$.data||{};if(R.code==="unportable-cwd"){S(f("fleet-cwd-repair-unportable"));const z=Array.isArray(R.cells)?R.cells.find(L=>L&&L.id===N):null,F=z&&typeof z.suggestion=="string"?z.suggestion:null;F!==null&&br(F)!==null&&w(F)}else S(String($&&$.message||$))}finally{y(!1)}}};return l.jsxs("div",{className:"nc-set-form nc-fleet-form nc-cwd-repair",children:[l.jsx("b",{children:f("fleet-cwd-repair-title").replace("{id}",String(N||""))}),l.jsx("small",{className:"nc-set-info",children:f("fleet-cwd-repair-help")}),l.jsx("small",{className:"nc-cwd-no-source",children:f("fleet-cwd-repair-no-source-path")}),l.jsxs("label",{className:"nc-field",children:[f("cwd"),l.jsxs("div",{className:"nc-cwd-rel-row",children:[l.jsx("span",{className:"nc-cwd-rel-prefix",children:"~/"}),l.jsx("input",{value:u,placeholder:f("fleet-cwd-repair-placeholder"),autoComplete:"off",spellCheck:"false",autoCapitalize:"none",onChange:Y=>d(Y.target.value)}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:C,onClick:()=>p?m(null):M(""),children:f(p?"close":"fleet-cwd-repair-browse")})]})]}),l.jsx("div",{className:"nc-cwd-preview",children:f("fleet-cwd-repair-preview").replace("{path}",Ql(u))}),p&&l.jsxs("div",{className:"nc-fs",children:[l.jsx("div",{className:"nc-fs-path",children:Ql(p.rel)}),l.jsxs("div",{className:"nc-fs-list",children:[p.rel&&l.jsxs("button",{type:"button",className:"nc-fs-item nc-fs-nav",onClick:G,children:["↑ ",f("fs-parent")]}),p.loading&&l.jsx("div",{className:"nc-fs-empty",children:"…"}),!p.loading&&p.dirs.length===0&&l.jsx("div",{className:"nc-fs-empty",children:f("fleet-cwd-repair-fs-empty")}),!p.loading&&p.dirs.map(Y=>l.jsxs("button",{type:"button",className:"nc-fs-item",onClick:()=>I(Y),children:["📁 ",Y]},Y))]}),p.err&&l.jsx("div",{className:"nc-err",children:p.err}),l.jsx("div",{className:"nc-sheet-actions",children:l.jsx("button",{type:"button",className:"nc-btn primary",disabled:C||p.loading||!!p.err,onClick:W,children:f("fleet-cwd-repair-use-current")})})]}),b&&l.jsx("div",{className:"nc-err",role:"alert",children:b}),E!==null&&l.jsxs("div",{className:"nc-cwd-suggestion",role:"status",children:[l.jsx("span",{children:f("fleet-cwd-repair-suggestion")}),l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:V,children:f("fleet-cwd-repair-use-suggestion").replace("{path}",Ql(E))})]}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:v,onClick:a,children:f("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:C,onClick:K,children:v?"…":f("save")})]})]})}function RR({token:e,readonly:t,targets:n=[],startNewCell:s=!1,initialLocation:o=""}){const[a,u]=x.useState({engines:[],cells:[],managedCatalog:[]}),[d,p]=x.useState({available:!1,capabilities:[]}),[m,v]=x.useState(!1),[y,b]=x.useState(null),[S,k]=x.useState(null),[E,w]=x.useState({}),[N,C]=x.useState(null),[M,I]=x.useState(!1),[G,W]=x.useState(""),[V,K]=x.useState(""),[Y,Z]=x.useState(o),[U,$]=x.useState(!1),[R,z]=x.useState(null),[F,L]=x.useState(null),[T,j]=x.useState(null),[B,A]=x.useState(!1),[D,O]=x.useState([]),[H,ie]=x.useState(null),[ee,ue]=x.useState("manage"),ve=x.useRef(!1),fe=Y?Y.split("/"):[],pe=x.useCallback(async()=>{try{const re=await Gs(e,fe);p(re);try{const ne=await Lf(e,fe);$(!!ne.readonlyDefault)}catch{$(!1)}if(re.provider==="builtin"&&(re.capabilities||[]).includes("definitions")){const ne=await kc(e,fe),_e=new Map((re.engines||[]).map(ye=>[ye.id,ye]));if(ne.engines=(ne.engines||[]).map(ye=>{var xe;return{...ye,availableModels:((xe=_e.get(ye.id))==null?void 0:xe.models)||[]}}),u(ne),(re.capabilities||[]).includes("credentials"))try{O((await rx(e,fe)).credentials||[])}catch{O([])}else O([])}W("")}catch(re){W(String(re.message||re))}finally{v(!0)}},[e,Y]);x.useEffect(()=>{pe();const re=setInterval(pe,5e3);return()=>clearInterval(re)},[pe]);const Ye=new Set((d.cells||[]).filter(re=>re.active).map(re=>re.cell)),ht=d.provider==="builtin"&&(d.capabilities||[]).includes("edit"),yt=(d.capabilities||[]).includes("restore");x.useEffect(()=>{!s||ve.current||!ht||!a.engines.length||(ve.current=!0,C({mode:"new",form:Sy(a.engines[0].id)}))},[s,ht,a.engines]);const Ne=async re=>{I(!0),W(""),K("");try{await re(),await pe()}catch(ne){W(String(ne.message||ne))}I(!1)},Ct=async(re,ne)=>{const _e=await hx(e,re,ne,fe);return w(ye=>({...ye,[`${re}::${ne}`]:_e})),_e},hn=re=>Ne(async()=>{const ne={id:String(re.id||"").trim(),engine:String(re.engine||"").trim()};for(const _e of["contextWindow","maxTokens"]){const ye=String(re[_e]||"").trim();ye&&(ne[_e]=Number(ye))}re.reasoning===!0&&(ne.reasoning=!0),await ux(e,ne,fe),k(null),await pe()}),vn=()=>Ne(async()=>{var $t;const re=y.mode==="new",ne=y.form,_e=a.managedCatalog||[],ye=ne.kind==="managed"?Na(_e,ne):null,xe=typeof(ye==null?void 0:ye.credentialEnv)=="string"?ye.credentialEnv:"",st=xe&&ne.credentialValue||"",pt=SR(ne,re,_e);!re&&y.form.kind==="custom"&&!y.form.modelFlag&&(pt.model=null),!re&&y.form.kind==="custom"&&y.form.promptMode!=="flag"&&(pt.promptFlag=null);let ft;if(re)ft=await ax(e,pt,fe);else{const Ze=y.original,J=new Set(y.form.envRows.filter(ze=>!ze.remove).map(ze=>ze.key)),Ee=(Ze.envKeys||[]).filter(ze=>!J.has(ze)),We=Object.fromEntries(y.form.envRows.filter(ze=>!ze.remove&&ze.key&&(!ze.configured||ze.value!=="")).map(ze=>[ze.key,ze.value]));ft=await lx(e,Ze.id,pt,y.form.kind==="custom"?{set:We,remove:Ee}:void 0,fe)}let Rt=null;if(xe&&st)try{Rt=await Yg(e,xe,st,fe),O(Rt.credentials||[])}catch{throw await pe(),re&&b({mode:"edit",original:{...pt,id:ne.id},form:{...ne,credentialReveal:!1}}),new Error(f(re?"fleet-key-partial-create":"fleet-key-partial-edit"))}await pe(),b(null),K(f("fleet-saved"));const St=(($t=((Rt==null?void 0:Rt.credentials)||[]).find(Ze=>Ze.envKey===xe))==null?void 0:$t.activeCells)||[],bt=[...new Set([...(ft==null?void 0:ft.activeCells)||[],...St])];if(bt.length&&window.confirm(f("fleet-restart-confirm").replace("{cells}",bt.join(", "))))for(const Ze of bt)await ha(e,Ze,fe)}),Gt=()=>Ne(async()=>{var St,bt,$t,Ze,J,Ee;const re=N.mode==="new",ne=N.form,_e={...re?{id:ne.id}:{},cwd:ne.cwd,engine:ne.engine,boot:!!ne.boot},ye={...ne.commands||{}},xe=a.engines.find(We=>We.id===ne.engine);((St=xe==null?void 0:xe.managed)==null?void 0:St.client)==="shell"&&typeof ne.command=="string"&&ne.command.length?ye[ne.engine]=ne.command:((bt=xe==null?void 0:xe.managed)==null?void 0:bt.client)==="shell"&&delete ye[ne.engine],(Object.keys(ye).length||!re)&&(_e.commands=ye);const st=(ne.label||"").trim();re?st&&(_e.label=st):_e.label=st||null;const pt=(ne.panelUrl||"").trim();re?pt&&(_e.panelUrl=pt):_e.panelUrl=pt||null,re?Array.isArray(ne.mcp)&&(_e.mcp=ne.mcp):_e.mcp=Array.isArray(ne.mcp)?ne.mcp:null,re?((($t=xe==null?void 0:xe.managed)==null?void 0:$t.client)!=="shell"&&ne.model&&(_e.model=ne.model),((Ze=xe==null?void 0:xe.managed)==null?void 0:Ze.client)!=="shell"&&ne.prompt&&(_e.prompt=ne.prompt)):(_e.model=((J=xe==null?void 0:xe.managed)==null?void 0:J.client)==="shell"?null:ne.model||null,((Ee=xe==null?void 0:xe.managed)==null?void 0:Ee.client)!=="shell"&&(_e.prompt=ne.prompt||null));const ft=re?await fx(e,_e,fe):await By(e,N.original.id,_e,fe),Rt=re?ne.id:N.original.id;C(null),K(f("fleet-saved")),!re&&(ft!=null&&ft.active)&&window.confirm(f("fleet-restart-confirm").replace("{cells}",Rt))&&await ha(e,Rt,fe)}),kt=t||U,Bt=d.capabilities||[],Ut=fe.length>0&&kt,Nt=re=>D.find(ne=>{var _e;return(_e=ne.engines)==null?void 0:_e.includes(re.id)})||null,Dt=()=>Ne(async()=>{var _e;const re=await Yg(e,H.envKey,H.value,fe);O(re.credentials||[]),ie(null),K(f("fleet-credential-saved"));const ne=((_e=(re.credentials||[]).find(ye=>ye.envKey===H.envKey))==null?void 0:_e.activeCells)||[];if(ne.length&&window.confirm(f("fleet-restart-confirm").replace("{cells}",ne.join(", "))))for(const ye of ne)await ha(e,ye,fe)}),Mt=re=>Ne(async()=>{if(!window.confirm(f("fleet-credential-remove-confirm").replace("{key}",re.envKey)))return;const ne=await ox(e,re.envKey,fe);O(ne.credentials||[]),K(f("fleet-credential-removed"))}),jt=re=>z({...re,route:Array.isArray(re==null?void 0:re.route)?re.route:fe}),fn=async re=>{if(!R)return;const ne=R.cell||R.id,_e=Array.isArray(R.route)?R.route:fe;if(re.action==="up"){const ye=await Nf(e,{cell:ne,boot:!!re.boot,...re.engine?{engine:re.engine}:{},...re.model!==void 0?{model:re.model}:{},...re.permissionPolicy?{permissionPolicy:re.permissionPolicy}:{}},_e),xe=Hf(ye);xe&&K(xe.text)}else await ac(e,{cell:ne,boot:!!re.boot},_e)},se=(re,ne)=>{W(""),L({mode:"new",route:Array.isArray(ne)?ne:fe,form:{tmuxSession:re.name,id:"",engine:"",cwd:"",boot:!1},err:""})},Qe=()=>Ne(async()=>{const re=F.form;if(!re.engine){L({...F,err:f("import-engine-required")});return}await px(e,{tmuxSession:re.tmuxSession,id:re.id||void 0,engine:re.engine,cwd:re.cwd||void 0,boot:!!re.boot},re.route||fe),L(null),K(f("fleet-saved"))}),me=({engineRows:re=[],cellRows:ne=[],models:_e=[]})=>Ne(async()=>{const ye=re.filter(Ze=>Ze.selected),xe=ye.map(Ze=>nS(Ze.engine));if(xe.some(Ze=>!Ze))throw new Error(f("fleet-backup-invalid-engine"));const st=ye.filter(Ze=>Ze.exists).map(Ze=>Ze.engine.id);if(st.length&&!window.confirm(f("fleet-backup-confirm-engine-overwrite").replace("{engines}",st.join(", "))))return;const pt=[...new Set([...a.engines.map(Ze=>Ze.id),...xe.map(Ze=>Ze.id)])],ft=[];for(const Ze of ne.filter(J=>J.selected)){const J=_R(Ze.cell,Ze.engine,pt);if(!J)throw new Error(`${Ze.cell.id}: ${f("fleet-backup-engine-missing")}`);ft.push(J)}const Rt=ne.filter(Ze=>Ze.selected&&Ze.exists).map(Ze=>Ze.cell.id);if(Rt.length&&!window.confirm(f("fleet-backup-confirm-overwrite").replace("{cells}",Rt.join(", "))))return;const St=xe.length?await gx(e,xe,st.length>0,fe,_e):{needsRestart:[]},bt=ft.length?await mx(e,ft,fe):{needsRestart:[]},$t=[...new Set([...St.needsRestart||[],...bt.needsRestart||[]])];A(!1),K(`${f("fleet-backup-restored").replace("{n}",String(ft.length))}${xe.length?` · ${xe.length} ${f("fleet-engines").toLowerCase()}`:""}${$t.length?` · ${f("fleet-backup-needs-restart").replace("{cells}",$t.join(", "))}`:""}`)}),Xe=l.jsxs("label",{className:"nc-field",children:[f("location"),l.jsxs("select",{value:Y,onChange:re=>{Z(re.target.value),b(null),C(null),W(""),K(""),$(!1),v(!1),p({available:!1,capabilities:[]}),u({engines:[],cells:[],managedCatalog:[]}),O([]),ie(null)},children:[l.jsx("option",{value:"",children:f("local")}),n.map(re=>l.jsxs("option",{value:re.route.join("/"),disabled:re.status&&re.status!=="up",children:[re.label,re.status&&re.status!=="up"?` · ${f("node-offline")}`:""]},re.route.join("/")))]})]}),dt=l.jsxs("div",{className:"nc-fleet-view-tabs",role:"tablist","aria-label":f("tab-fleet"),children:[l.jsx("button",{type:"button",role:"tab","aria-selected":ee==="manage",className:`nc-set-tabbtn${ee==="manage"?" on":""}`,onClick:()=>ue("manage"),children:f("fleet-manage-location")}),l.jsx("button",{type:"button",role:"tab","aria-selected":ee==="overview",className:`nc-set-tabbtn${ee==="overview"?" on":""}`,onClick:()=>ue("overview"),children:f("fleet-network-overview")})]});return m?ht?l.jsxs("div",{className:"nc-set-tab nc-fleet-editor",children:[dt,ee==="overview"?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-set-info",children:f("fleet-overview-help")}),l.jsx(ch,{token:e,targets:n,readonly:t,onPower:jt,onImport:se})]}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-set-info",children:f("fleet-manage-help")}),Xe,l.jsxs("div",{className:"nc-set-row nc-fleet-backup-actions",children:[l.jsx("button",{className:"nc-btn ghost",disabled:kt||M,onClick:()=>{W(""),A(!0)},children:f("fleet-backup")}),l.jsx("small",{children:f("fleet-backup-help")})]}),l.jsxs("div",{className:"nc-fleet-section-head",children:[l.jsx("b",{children:f("fleet-cells")}),l.jsx("span",{className:"nc-fleet-head-actions",children:l.jsxs("button",{className:"nc-btn primary",disabled:kt||M||!a.engines.length,onClick:()=>{var re;W(""),C({mode:"new",form:Sy((re=a.engines[0])==null?void 0:re.id)})},children:["+ ",f("add")]})})]}),a.cells.map(re=>{const ne=Ye.has(re.id),_e=re.needsRepair===!0;return l.jsxs("div",{className:"nc-fleet-item",children:[l.jsxs("span",{children:[l.jsx("b",{children:re.id}),re.label?l.jsxs("small",{className:"nc-fleet-label",children:[" ",re.label]}):null,l.jsxs("small",{children:[re.engine," · ",_e?l.jsx("span",{className:"nc-fleet-tag nc-fleet-tag-warn",children:f("fleet-cwd-needs-repair")}):re.cwd,ne?` · ${f("service-active")}`:` · ${f("cell-off")}`]})]}),l.jsxs("span",{children:[ne&&Bt.includes("down")&&l.jsx("button",{className:"nc-btn ghost",disabled:kt||M,onClick:()=>Ne(()=>ac(e,{cell:re.id},fe)),children:f("stop")}),!ne&&Bt.includes("up")&&l.jsx("button",{className:"nc-btn primary",disabled:kt||M,onClick:()=>jt({cell:re.id,id:re.id,engine:re.engine,model:re.model,models:re.models,permissionPolicies:re.permissionPolicies,active:!1,boot:re.boot}),children:f("start")}),ne&&Bt.includes("restart")&&l.jsx("button",{className:"nc-btn ghost",disabled:kt||M,onClick:()=>Ne(()=>ha(e,re.id,fe)),children:f("restart")}),_e?l.jsx("button",{className:"nc-btn ghost",disabled:kt||M,onClick:()=>{W(""),j(re)},children:f("fleet-cwd-repair")}):l.jsx("button",{className:"nc-btn ghost",disabled:kt||M,onClick:()=>{var ye;W(""),C({mode:"edit",original:re,form:{...re,commands:{...re.commands||{}},command:((ye=re.commands)==null?void 0:ye[re.engine])||""}})},children:f("edit")}),l.jsx("button",{className:"nc-btn danger",disabled:kt||M,onClick:()=>Ne(async()=>{window.confirm(f("fleet-remove-cell").replace("{id}",re.id))&&await zy(e,re.id,!0,fe)}),children:"×"})]})]},re.id)}),l.jsxs("div",{className:"nc-fleet-section-head",children:[l.jsx("b",{children:f("fleet-engines")}),l.jsxs("button",{className:"nc-btn primary",disabled:kt||M,onClick:()=>{W(""),b({mode:"new",form:yR()})},children:["+ ",f("add")]})]}),a.engines.map(re=>{var _e,ye;const ne=Nt(re);return l.jsxs("div",{className:"nc-fleet-item",children:[l.jsxs("span",{children:[l.jsx("b",{children:re.label}),l.jsx("small",{children:re.managed?`${re.id} · ${re.managed.client} / ${re.managed.provider} · ${(_e=re.managedInfo)!=null&&_e.configured?f("fleet-ready"):((ye=re.managedInfo)==null?void 0:ye.reason)||f("fleet-not-ready")}`:`${re.id} · ${re.command}`}),ne&&l.jsxs("small",{children:[ne.envKey," · ",f(`fleet-credential-source-${ne.source||"missing"}`)]})]}),l.jsxs("span",{children:[ne&&l.jsx("button",{className:"nc-btn ghost",disabled:kt||M,onClick:()=>{W(""),ie({envKey:ne.envKey,value:""})},children:ne.configured?f("fleet-credential-change"):f("fleet-credential-set")}),(ne==null?void 0:ne.source)==="local"&&l.jsx("button",{className:"nc-btn danger",disabled:kt||M,onClick:()=>Mt(ne),children:f("fleet-credential-forget")}),l.jsx("button",{className:"nc-btn ghost",disabled:kt||M,onClick:()=>{W(""),b({mode:"edit",original:re,form:wR(re)})},children:f("edit")}),l.jsx("button",{className:"nc-btn danger",disabled:kt||M,onClick:()=>Ne(async()=>{window.confirm(f("fleet-remove-engine").replace("{id}",re.id))&&await cx(e,re.id,fe)}),children:"×"})]})]},re.id)}),l.jsxs("div",{className:"nc-fleet-section-head",children:[l.jsx("b",{children:f("fleet-models")}),l.jsxs("button",{className:"nc-btn primary",disabled:kt||M,onClick:()=>{W(""),k({mode:"new",form:{id:"",engine:""}})},children:["+ ",f("add")]})]}),!(a.models||[]).length&&l.jsx("small",{className:"nc-set-hint",children:f("fleet-no-models")}),(a.models||[]).map(re=>{const ne=`${re.engine}::${re.id}`,_e=E[ne],ye=(a.engines||[]).some(xe=>xe.managed&&xe.managed.model===re.id);return l.jsxs("div",{className:"nc-fleet-item",children:[l.jsxs("span",{children:[l.jsx("b",{children:re.id}),l.jsxs("small",{children:[re.engine,re.contextWindow?` · ${re.contextWindow}`:"",ye?` · ${f("model-in-use")}`:""]}),_e&&l.jsxs("small",{className:`nc-model-test ${_e.outcome}`,children:[f(`model-test-${_e.outcome}`),_e.outcome==="ok"&&Number.isInteger(_e.latencyMs)?` · ${_e.latencyMs}ms`:""]})]}),l.jsxs("span",{children:[Bt.includes("model-test")&&l.jsx("button",{className:"nc-btn ghost",disabled:M||Ut,onClick:()=>Ne(()=>Ct(re.engine,re.id)),children:f("model-test")}),l.jsx("button",{className:"nc-btn danger",disabled:kt||M,onClick:()=>Ne(()=>dx(e,re.id,re.engine,fe)),children:"×"})]})]},ne)})]}),S&&l.jsx(Fs,{onClose:()=>k(null),label:f("fleet-models"),error:G,children:l.jsx(CR,{state:S,setState:k,busy:M,onSave:hn,onTest:Ct,profiles:a.managedCatalog||[],canTest:Bt.includes("model-test")&&!Ut})}),y&&l.jsx(Fs,{onClose:()=>b(null),label:f("fleet-new-engine"),error:G,children:l.jsx(kR,{state:y,setState:b,busy:M,onSave:vn,catalog:a.managedCatalog||[]})}),N&&l.jsx(Fs,{onClose:()=>C(null),label:f("fleet-new-cell"),error:G,children:l.jsx(ER,{token:e,route:fe,targets:n,location:Y,setLocation:Z,state:N,setState:C,engines:a.engines,mcpServers:a.mcpServers||[],managedCatalog:a.managedCatalog||[],busy:M,onSave:Gt})}),T&&l.jsx(Fs,{onClose:()=>j(null),label:f("fleet-cwd-repair-title").replace("{id}",T.id),error:"",children:l.jsx(jR,{token:e,route:fe,cell:T,busy:M,onSaved:async()=>{j(null),K(f("fleet-cwd-repaired")),await pe()},onClose:()=>j(null)})}),V&&l.jsx("div",{className:"nc-set-note",children:V}),G&&l.jsx("div",{className:"nc-err",children:G}),B&&l.jsx(Fs,{onClose:()=>A(!1),label:f("fleet-backup"),error:G,children:l.jsx(xR,{cells:a.cells,engines:a.engines,models:a.models||[],busy:M,canRestore:yt,onRestore:me,onClose:()=>A(!1)})}),H&&l.jsx(Fs,{onClose:()=>ie(null),label:f("fleet-credential-title"),error:G,children:l.jsxs("div",{className:"nc-fleet-form nc-credential-form",children:[l.jsx("b",{children:f("fleet-credential-title")}),l.jsx("small",{children:f("fleet-credential-help")}),l.jsxs("label",{className:"nc-field",children:[H.envKey,l.jsx("input",{type:"password",autoComplete:"off",spellCheck:"false",autoCapitalize:"none",value:H.value,onChange:re=>ie({...H,value:re.target.value})})]}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{className:"nc-btn ghost",onClick:()=>ie(null),children:f("cancel")}),l.jsx("button",{className:"nc-btn primary",disabled:M||!H.value,onClick:Dt,children:f("save")})]})]})}),F&&l.jsx(Fs,{onClose:()=>L(null),label:f("import-as-cell"),error:G,children:l.jsx(ky,{token:e,route:F.route||fe,state:F,setState:L,busy:M,onSave:Qe})}),R&&l.jsx(cc,{cell:R,token:e,route:Array.isArray(R.route)?R.route:fe,onConfirm:async re=>{try{await fn(re)}finally{await pe()}},onClose:()=>z(null)})]}):l.jsxs("div",{className:"nc-set-tab",children:[dt,ee==="overview"?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-set-info",children:f("fleet-overview-help")}),l.jsx(ch,{token:e,targets:n,readonly:t,onPower:jt,onImport:se})]}):l.jsxs(l.Fragment,{children:[Xe,l.jsxs("div",{className:"nc-set-info",children:[f(G?"fleet-editor-load-error":"fleet-editor-unavailable"),!G&&d.reason?` ${d.reason}`:""]})]}),G&&l.jsx("div",{className:"nc-err",children:G}),F&&l.jsx(Fs,{onClose:()=>L(null),label:f("import-as-cell"),error:G,children:l.jsx(ky,{token:e,route:F.route||fe,state:F,setState:L,busy:M,onSave:Qe})}),R&&l.jsx(cc,{cell:R,token:e,route:Array.isArray(R.route)?R.route:fe,onConfirm:async re=>{try{await fn(re)}finally{await pe()}},onClose:()=>z(null)})]}):l.jsxs("div",{className:"nc-set-tab",children:[dt,ee==="overview"?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-set-info",children:f("fleet-overview-help")}),l.jsx(ch,{token:e,targets:n,readonly:t,onPower:jt,onImport:se})]}):l.jsxs(l.Fragment,{children:[Xe,l.jsx("div",{className:"nc-set-info",children:f("fleet-editor-loading")})]})]})}const bp="nc_notification_speech_v1",Jl="nc-notification-speech",yf="nc-notification-speech-preview",PR=320,LR=2,AR=3e4,MR=1e4,TR=6e4,DR=64,Cy=Object.freeze({enabled:!1}),IR=Object.freeze({it:"it-IT",en:"en-US",es:"es-ES"}),OR=Object.freeze({it:new Set(["che","con","correzione","della","delle","difetto","il","lavoro","nessun","non","per","pronto","pubblicata","pubblicato","rilascio","sono","stato","tutti","verificata","verificato","versione","completata","completato","riepilogo"]),en:new Set(["all","and","completed","fix","for","issue","no","published","ready","release","summary","the","verified","version","with","work"]),es:new Set(["con","correccion","defecto","el","esta","para","publicada","publicado","resumen","sin","todos","trabajo","verificada","verificado","version","y"])}),wp=new WeakSet;function Sp(e){return{enabled:(e&&typeof e=="object"&&!Array.isArray(e)?e:{}).enabled===!0}}function sS(){try{return typeof localStorage<"u"?localStorage:null}catch{return null}}function Ey(e=sS()){if(!e)return{...Cy};try{return Sp(JSON.parse(e.getItem(bp)||"null"))}catch{return{...Cy}}}function BR(e,t=sS()){const n=Sp(e);if(t)try{t.setItem(bp,JSON.stringify(n))}catch{}return n}function Eo(){try{return typeof window<"u"?window:null}catch{return null}}function ja(e=Eo()){try{return!!(e&&e.speechSynthesis&&typeof e.speechSynthesis.speak=="function"&&typeof e.SpeechSynthesisUtterance=="function")}catch{return!1}}function rS(e=Eo()){return!!(e&&(typeof e=="object"||typeof e=="function")&&wp.has(e))}function bf(e=Eo()){e&&(typeof e=="object"||typeof e=="function")&&wp.delete(e)}function mo(e){const t=String(e||"").trim().toLowerCase().split("-")[0];return IR[t]||""}function Ic(e){return String(e||"").normalize("NFC").replace(/[\p{Cc}\p{Cf}]+/gu," ").replace(/\s+/g," ").trim()}function zR(e){const t=Ic(e).normalize("NFD").replace(new RegExp("\\p{M}+","gu"),"").toLowerCase(),n=new Set(t.match(new RegExp("\\p{L}+","gu"))||[]);if(n.size<4)return"";const s=Object.entries(OR).map(([o,a])=>({lang:o,score:[...n].reduce((u,d)=>u+(a.has(d)?1:0),0)})).sort((o,a)=>a.score-o.score);return s[0].score>=3&&s[0].score-s[1].score>=2?s[0].lang:""}function $R(e,t){const n=mo(e&&e.lang);return n||mo(zR(e&&e.body))||mo(t)}function oS(e){try{const t=e&&e.speechSynthesis&&e.speechSynthesis.getVoices;return typeof t=="function"?Array.from(t.call(e.speechSynthesis)||[]).filter(Boolean):[]}catch{return[]}}function aS(e,t){const n=mo(t);if(!n)return null;const s=Array.from(e||[]).filter(d=>d&&typeof d.lang=="string"&&d.lang.trim()),o=s.filter(d=>d.lang.trim().toLowerCase()===n.toLowerCase()),a=n.slice(0,2).toLowerCase(),u=s.filter(d=>d.lang.trim().toLowerCase().split("-")[0]===a);return o.find(d=>d.default===!0)||o[0]||u.find(d=>d.default===!0)||u[0]||null}function Ny(e){return Ic(e).replace(/\bBearer\s+\S+/gi,"Bearer [redacted]").replace(/\b(?:sk|hf|zai|xox[baprs]|gh[pousr]|npm)[_-][A-Za-z0-9._-]{8,}\b/gi,"[redacted]").replace(/\b(?:token|password|secret|credential|api[_-]?key)\s*[=:]\s*(?:"[^"]*"|'[^']*'|\S+)/gi,"[redacted]").replace(/\b[A-Z][A-Z0-9_]{2,}\s*=\s*(?:"[^"]*"|'[^']*'|\S+)/g,"[redacted]").replace(/(?:\/home\/[^/\s]+|\/Users\/[^/\s]+|\/data\/(?:data|user\/\d+)\/[^/\s]+)(?:\/[^\s]*)?/g,"[private path]").replace(/\b[A-Za-z]:\\Users\\[^\\\s]+(?:\\[^\s]*)?/g,"[private path]")}function FR(e,t=PR){const n=Ny(e&&e.title),s=Ny(e&&e.body),o=[n,s&&s!==n?s:""].filter(Boolean).join(". "),a=Array.from(o);return a.length<=t?o:`${a.slice(0,Math.max(0,t-1)).join("").trimEnd()}…`}function HR(e){try{return!!(e&&e.visibilityState==="visible"&&typeof e.hasFocus=="function"&&e.hasFocus())}catch{return!1}}function lS(e=Eo()){if(!ja(e))return!1;try{return e.speechSynthesis.cancel(),!0}catch{return!1}}function UR(e){try{e&&typeof e.dispatchEvent=="function"&&typeof e.Event=="function"&&e.dispatchEvent(new e.Event(yf))}catch{}}function WR(e,t,n=Eo(),s={}){var m;if(bf(n),!ja(n))return Promise.resolve(!1);const o=Ic(e);if(!o||(m=s.signal)!=null&&m.aborted)return Promise.resolve(!1);const a=Number.isFinite(s.timeoutMs)&&s.timeoutMs>0?s.timeoutMs:MR,u=s.setTimer||((v,y)=>setTimeout(v,y)),d=s.clearTimer||(v=>clearTimeout(v)),p=s.signal;return UR(n),new Promise(v=>{let y=!1,b=!1,S=null,k=null;const E=w=>{if(!y){if(y=!0,p&&k&&p.removeEventListener("abort",k),S!==null&&d(S),w!==!0)try{n.speechSynthesis.cancel()}catch{}else wp.add(n);v(w)}};k=()=>E("no-activation"),p&&p.addEventListener("abort",k,{once:!0});try{n.speechSynthesis.cancel();const w=new n.SpeechSynthesisUtterance(o);w.lang=mo(t);const N=aS(oS(n),w.lang);N&&(w.voice=N),w.onstart=()=>{b=!0},w.onend=()=>E(b?!0:"no-activation"),w.onerror=()=>E("voice-error"),S=u(()=>E("timeout"),a),n.speechSynthesis.speak(w)}catch{E("no-activation")}})}function KR(e={}){const t=e.scope||Eo(),n=e.document||t&&t.document,s=Number.isInteger(e.maxPending)&&e.maxPending>=0?e.maxPending:LR,o=Number.isFinite(e.watchdogMs)&&e.watchdogMs>0?e.watchdogMs:AR,a=Number.isFinite(e.dedupWindowMs)&&e.dedupWindowMs>0?e.dedupWindowMs:TR,u=Number.isInteger(e.maxDedup)&&e.maxDedup>0?e.maxDedup:DR,d=e.now||Date.now,p=e.setTimer||((U,$)=>setTimeout(U,$)),m=e.clearTimer||(U=>clearTimeout(U)),v=e.isPrimed||(()=>rS(t)),y=t&&t.speechSynthesis;let b=null,S=null,k=[],E=[],w=()=>{};const N=new Map,C=()=>{E=oS(t)};if(C(),y&&typeof y.addEventListener=="function")y.addEventListener("voiceschanged",C),w=()=>y.removeEventListener("voiceschanged",C);else if(y&&"onvoiceschanged"in y){const U=y.onvoiceschanged,$=(...R)=>{C(),typeof U=="function"&&U.apply(y,R)};y.onvoiceschanged=$,w=()=>{y.onvoiceschanged===$&&(y.onvoiceschanged=U)}}const M=U=>{if(U&&typeof U.id=="string"&&U.id)return`id:${U.id}`;const $=Number(U&&U.ts),R=Ic(U&&U.title);return Number.isFinite($)&&R?`frame:${$}:${R}`:""},I=U=>{if(!U)return!0;const $=d();for(const[R,z]of N)$-z>=a&&N.delete(R);if(N.has(U))return!1;for(N.set(U,$);N.size>u;)N.delete(N.keys().next().value);return!0},G=()=>{S!==null&&m(S),S=null},W=()=>{G(),b&&(b.onend=null,b.onerror=null,b=null),lS(t)},V=U=>{if(!ja(t))return k=[],"unsupported";let $;try{$=new t.SpeechSynthesisUtterance(U.text),$.lang=mo(U.lang);const z=aS(E,$.lang);z&&($.voice=z)}catch{return k=[],"error"}b=$;const R=()=>{if(b!==$)return;G(),b=null,$.onend=null,$.onerror=null;const z=k.shift();z&&V(z)};$.onend=R,$.onerror=R;try{return S=p(()=>{if(b!==$)return;b=null,$.onend=null,$.onerror=null;try{t.speechSynthesis.cancel()}catch{}G();const z=k.shift();z&&V(z)},o),t.speechSynthesis.speak($),"speaking"}catch{return R(),"error"}},K=(U,$)=>{if(!ja(t))return"unsupported";const R=FR(U);if(!R)return"empty";if(!I(M(U)))return"duplicate";if(!HR(n))return"inactive";if(!v())return"unprimed";const z={text:R,lang:$};return U&&U.urgency==="high"?(k=[],W(),V(z)):b?s===0?"dropped":(k.length>=s&&k.shift(),k.push(z),"queued"):V(z)},Y=()=>{k=[],W()};return{enqueue:K,stop:Y,dispose:()=>{Y(),w(),w=()=>{}}}}function cS(){const[e,t]=x.useState(Ey);x.useEffect(()=>{const s=o=>{if((o==null?void 0:o.type)==="storage"&&o.key!==bp&&o.key!==null)return;const a=(o==null?void 0:o.type)===Jl?Sp(o.detail):Ey();t(a)};return window.addEventListener(Jl,s),window.addEventListener("storage",s),()=>{window.removeEventListener(Jl,s),window.removeEventListener("storage",s)}},[]);const n=x.useCallback(s=>{const o=BR({enabled:s===!0});return t(o),window.dispatchEvent(new CustomEvent(Jl,{detail:o})),o.enabled},[]);return[e.enabled,n]}function qR({text:e}){const[t,n]=x.useState(!1),s=async()=>{try{await navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)}catch{}};return l.jsxs("div",{className:"nc-set-copyline",children:[l.jsx("code",{children:e}),l.jsxs("button",{type:"button",className:"nc-btn ghost",onClick:s,children:[l.jsx(ut,{name:"copy",size:14})," ",f(t?"copied":"copy")]})]})}function VR({value:e}){const[t,n]=x.useState("");return x.useEffect(()=>{let s=!0;return Sj.toDataURL(e,{margin:1,width:220}).then(o=>{s&&n(o)}).catch(()=>{}),()=>{s=!1}},[e]),t?l.jsx("img",{src:t,width:"220",height:"220",alt:"NexusCrew pairing QR"}):null}function YR({token:e,nodes:t,roster:n,settings:s,readonly:o,refresh:a,refreshAliases:u,vlUnavailable:d=[]}){const[p,m]=x.useState(null),[v,y]=x.useState(null),[b,S]=x.useState(null),[k,E]=x.useState({ssh:"",sshPort:"",name:""}),[w,N]=x.useState(""),[C,M]=x.useState(""),[I,G]=x.useState(!1),[W,V]=x.useState(null),K=Date.now(),Y=s&&s.deviceName||"",Z=(t||[]).filter(j=>j&&j.direction==="outbound"&&j.name&&j.ssh),U=Z.find(j=>j.name===w)||Z[0]||null,$=U?wh(U.tunnel,K):null,R=U!=null&&U.shared?$!=null&&$.up?"share-local-active":"share-local-pending":$!=null&&$.up?"share-local-private":"share-local-private-down",z=[{key:"peer-group-hubs",rows:(t||[]).filter(j=>j.kind!=="transitive"&&j.kind!=="vl"&&j.relation!=="client")},{key:"peer-group-clients",rows:(t||[]).filter(j=>j.kind!=="transitive"&&j.kind!=="vl"&&j.relation==="client")},{key:"peer-group-routed",rows:(t||[]).filter(j=>j.kind==="transitive")},{key:"peer-group-vl",rows:(t||[]).filter(j=>j.kind==="vl")}],F=W&&(t||[]).find(j=>`${j.kind||"direct"}:${j.nodeId||j.name}`===W)||null,L=async j=>{if(U){m(null),y(`${U.name}:share`);try{const B=await Ex(e,U.name,j);await a(),B&&B.reversePoolPending===!0&&m(`${U.name}: ${f("share-reverse-pool-pending")}`)}catch(B){const A=B!=null&&B.data&&B.data.shared===!1?B.data:null;if(A)try{await a()}catch{}const D=B!=null&&B.data&&typeof B.data.hint=="string"?B.data.hint:"",O=(A==null?void 0:A.revoked)===!0&&(A==null?void 0:A.localReconcilePending)===!0?f("share-off-local-reconcile-pending"):(A==null?void 0:A.revoked)===!1&&(A==null?void 0:A.reconcilePending)===!0?f("share-off-hub-reconcile-pending"):"",H=B!=null&&B.data&&B.data.reversePoolPending===!0?f("share-reverse-pool-pending"):"",ie=B!=null&&B.data&&typeof B.data.code=="string"?B.data.code:"",ee=B!=null&&B.data&&typeof B.data.detail=="string"?B.data.detail.trim():"",ue=ee&&ee!==String(B.message||"")?ee:"";m(`${U.name}: ${String(B.message||B)}${ie?` [${ie}]`:""}${ue?` — ${ue}`:""}${D?` — ${D}`:""}${O?` — ${O}`:""}${H?` — ${H}`:""}`)}y(null)}},T=async()=>{m(null);const j=qs(k.name||C||Y||"NexusCrew"),B=Ok({name:j,ssh:k.ssh,sshPort:k.sshPort});if(!B.ok){m(f(B.error));return}y("invite");try{S(await Sx(e,{...C||Y?{label:C||Y}:{},name:j,ssh:B.value.ssh,...B.value.sshPort?{sshPort:B.value.sshPort}:{}}))}catch(A){m(String(A.message||A))}y(null)};return l.jsxs("div",{className:"nc-set-tab",children:[l.jsx("div",{className:"nc-sheet-label",children:f("peer-inventory-title")}),(t||[]).length===0&&l.jsx("div",{className:"nc-empty",children:f("no-nodes")}),z.map(j=>j.rows.length>0&&l.jsxs("div",{className:"nc-peer-group",children:[l.jsxs("div",{className:"nc-peer-group-title",children:[f(j.key)," ",l.jsx("span",{children:j.rows.length})]}),j.rows.map(B=>{const A=Tj(B);if(!A)return null;const D=`${B.kind||"direct"}:${B.nodeId||B.name}`,O=A.routed?{up:A.reach.up,since:null}:wh(B.tunnel,K);return l.jsxs("button",{type:"button",className:`nc-set-node nc-node-row${A.routed?" routed":""}`,"aria-label":`${A.title} — ${f("node-detail-open")}`,onClick:()=>V(D),children:[l.jsx("span",{className:`nc-dot ${A.reach.up?"on":""}`}),l.jsxs("span",{className:"nc-node-row-text",children:[l.jsx("b",{children:A.title}),l.jsxs("small",{children:[A.routed?A.routeLabel:`${A.subtitle} · ${f(A.exposure.shortKey)}`,!A.routed&&A.exposure.shortKey==="visibility-selected"?` (${A.exposure.count})`:""]})]}),l.jsxs("span",{className:`nc-set-tunnel${A.reach.up?" up":""}`,children:[f(A.reach.key),O.since?` · ${O.since}`:""]}),l.jsx("span",{className:"nc-node-row-more",children:l.jsx(ut,{name:"chevronDown",size:14})})]},D)})]},j.key)),d.length>0&&l.jsxs("div",{className:"nc-err",children:[f("vl-owners-unavailable"),": ",d.map(j=>j.label||j.route.join("/")).join(", ")]}),F&&l.jsx(Gj,{node:F,nodes:t||[],token:e,readonly:o,refresh:a,onClose:()=>V(null)}),(n||[]).some(j=>!j.direct&&j.instanceId)&&l.jsxs("div",{className:"nc-set-form",children:[l.jsx("div",{className:"nc-sheet-label",children:f("routed-node-aliases")}),l.jsx("small",{className:"nc-set-hint",children:f("routed-node-aliases-help")}),(n||[]).filter(j=>!j.direct&&j.instanceId).map(j=>l.jsxs("div",{className:"nc-set-node",children:[l.jsxs("div",{className:"nc-set-node-head",children:[l.jsx("span",{className:`nc-dot ${j.status==="up"?"on":""}`}),l.jsx("b",{children:j.label||j.name}),l.jsx("small",{children:(j.route||[]).join(" › ")})]}),l.jsxs("div",{className:"nc-set-node-actions",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:o||!!v,onClick:async()=>{const B=window.prompt(f("node-local-alias"),j.alias||"");if(B!=null){if(B.trim()&&!_o(B.normalize("NFC"))){m(f("err-label"));return}y(`${j.instanceId}:alias`),m(null);try{B.trim()?await kx(e,j.instanceId,B):await Qg(e,j.instanceId),u()}catch(A){m(String(A.message||A))}y(null)}},children:f("alias-on-device")}),j.alias&&l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:o||!!v,onClick:async()=>{y(`${j.instanceId}:alias-reset`),m(null);try{await Qg(e,j.instanceId),u()}catch(B){m(String(B.message||B))}y(null)},children:f("reset-alias")})]})]},j.instanceId))]}),U&&l.jsxs("div",{className:"nc-set-form nc-local-share",children:[l.jsx("div",{className:"nc-sheet-label",children:f("share-local-heading")}),Z.length>1&&l.jsxs("label",{className:"nc-field",children:[f("share-local-hub"),l.jsx("select",{value:U.name,disabled:o||!!v,onChange:j=>N(j.target.value),children:Z.map(j=>l.jsx("option",{value:j.name,children:j.label||j.name},j.name))})]}),l.jsxs("label",{className:"nc-check nc-node-share",children:[l.jsx("input",{type:"checkbox",checked:U.shared===!0,disabled:o||!!v,onChange:j=>L(j.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:f("share-local-through").replace("{device}",Y||f("local")).replace("{hub}",U.label||U.name)}),l.jsx("small",{children:f(U.shared?"share-node-on-desc":"share-node-off-desc")})]})]}),l.jsx("div",{className:`nc-set-test${U.shared&&($!=null&&$.up)?" ok":$!=null&&$.up?"":" ko"}`,children:f(R)}),!($!=null&&$.up)&&l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:o||!!v,onClick:()=>L(U.shared===!0),children:f("share-local-reconnect")})]}),l.jsx(qw,{token:e,deviceDefault:Y,localNodeId:s&&s.nodeId||"",localNameDefault:s&&s.localName||"",readonly:o,onSuccess:a}),l.jsxs("div",{className:"nc-set-form",children:[l.jsx("div",{className:"nc-sheet-label",children:f("invite-node")}),l.jsx("small",{className:"nc-set-hint",children:f("invite-v2-hint")}),l.jsxs("div",{className:"nc-set-info nc-invite-endpoint",children:[f("invite-target-local"),": ",l.jsx("b",{children:Y||f("invite-target-this")})]}),l.jsxs("label",{className:"nc-field",children:[f("invite-endpoint-label"),l.jsx("input",{placeholder:"user@host",value:k.ssh,disabled:o,onChange:j=>E({...k,ssh:j.target.value})}),l.jsx("small",{className:"nc-set-hint",children:f("invite-endpoint-needed")})]}),Z.length>0&&l.jsx("small",{className:"nc-set-hint nc-invite-hub-hint",children:f("invite-hub-only")}),I&&l.jsxs("div",{className:"nc-invite-advanced",children:[l.jsxs("label",{className:"nc-field",children:[f("node-ssh-port-label"),l.jsx("input",{inputMode:"numeric",placeholder:"22",value:k.sshPort,disabled:o,onChange:j=>E({...k,sshPort:j.target.value.replace(/[^0-9]/g,"").slice(0,5)})})]}),l.jsxs("label",{className:"nc-field",children:[f("device-name-label"),l.jsx("input",{placeholder:Y||"NexusCrew",value:C,disabled:o,onChange:j=>M(j.target.value)}),l.jsx("small",{className:"nc-set-hint",children:f("device-name-hint")})]}),l.jsxs("label",{className:"nc-field",children:[f("node-name-label"),l.jsx("input",{placeholder:qs(C||Y||f("node-name-ph")),value:k.name,disabled:o,onChange:j=>E({...k,name:j.target.value?qs(j.target.value):""})})]})]}),l.jsxs("div",{className:"nc-set-row nc-invite-actions",children:[l.jsx("button",{type:"button",className:"nc-btn primary",disabled:o||!!v||!k.ssh.trim(),onClick:T,children:f("create-pairing-link")}),l.jsxs("button",{type:"button",className:"nc-btn ghost",disabled:!!v,onClick:()=>G(j=>!j),children:[I?"▾":"▸"," ",f("pair-advanced")]})]}),b&&l.jsxs(l.Fragment,{children:[l.jsx(VR,{value:b.pairingUrl}),l.jsx(qR,{text:b.pairingUrl}),l.jsx("div",{className:"nc-set-info",children:f("invite-next-steps")})]})]}),p&&l.jsx("div",{className:"nc-err",children:p})]})}function GR({token:e,readonly:t}){const[n,s]=x.useState("idle"),[o,a]=x.useState(!1),[u,d]=x.useState(null);x.useEffect(()=>{let m=!1;return Qj().then(v=>{m||s(v)}),()=>{m=!0}},[]);const p=async()=>{d(null),a(!0);try{n==="subscribed"?(await Zj(e),s("idle")):(await Jj(e),s("subscribed"))}catch(m){const v=String(m.message||m);v==="push-denied"?(s("denied"),d(f("push-denied"))):v==="push-unsupported"?(s("unsupported"),d(f("push-unsupported"))):d(v)}a(!1)};return n==="unsupported"?l.jsx("div",{className:"nc-set-info",children:f("push-unsupported")}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:t||o||n==="denied",title:t?f("settings-readonly"):"",onClick:p,children:f(n==="subscribed"?"push-disable":"push-enable")}),l.jsx("span",{className:"nc-set-info",children:f(n==="subscribed"?"push-on":n==="denied"?"push-denied":"push-off")})]}),u&&l.jsx("div",{className:"nc-err",children:u})]})}function XR(){const[e,t]=cS(),[n,s]=x.useState(""),[o,a]=x.useState(""),[u,d]=x.useState(!1),[p,m]=x.useState(rS),v=x.useRef(0),y=x.useRef(!1),b=x.useRef(null),S=ja();x.useEffect(()=>()=>{var w;v.current+=1,y.current&&((w=b.current)==null||w.abort(),b.current=null,y.current=!1,bf())},[]);const k=async()=>{const w=v.current+=1,N=typeof AbortController=="function"?new AbortController:null;s(""),a(""),d(!0),m(!1),y.current=!0,b.current=N;const C=await WR(f("notification-speech-preview"),lc(),void 0,N?{signal:N.signal}:{});return w!==v.current||(b.current=null,y.current=!1,d(!1),m(C===!0),C===!0?a(f("notification-speech-preview-ok")):s(f(C==="voice-error"?"notification-speech-preview-voice-error":C==="timeout"?"notification-speech-preview-timeout":"notification-speech-preview-failed"))),C},E=w=>{var N;if(t(w),s(""),a(""),w)k();else{v.current+=1;const C=y.current;(N=b.current)==null||N.abort(),b.current=null,y.current=!1,d(!1),m(!1),bf(),C||lS()}};return l.jsxs("div",{className:"nc-set-form",children:[l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox","aria-label":f("notification-speech-enable"),checked:e,disabled:!S,onChange:w=>E(w.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:f("notification-speech-enable")}),l.jsx("small",{children:f("notification-speech-help")})]})]}),S?l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:!e||u,onClick:()=>{k()},children:f(u?"notification-speech-testing":"notification-speech-test")})}):l.jsx("div",{className:"nc-set-info",children:f("notification-speech-unsupported")}),e&&!p&&!u&&!n&&l.jsx("div",{className:"nc-set-info",children:f("notification-speech-needs-test")}),o&&l.jsx("div",{className:"nc-set-info",role:"status",children:o}),n&&l.jsx("div",{className:"nc-err",children:n})]})}function QR({token:e,readonly:t,nodes:n=[],settings:s=null}){const[o,a]=x.useState(null),[u,d]=x.useState([]),[p,m]=x.useState({name:"",mode:"primary-failover",targets:[]}),[v,y]=x.useState(null),[b,S]=x.useState(!1),[k,E]=x.useState(null),[w,N]=x.useState(""),C=x.useCallback(async()=>{try{const[T,j]=await Promise.all([jx(e),Ax(e)]);a(T),d(Array.isArray(j==null?void 0:j.groups)?j.groups:[]),N("")}catch(T){N(String(T.message||T))}},[e]);x.useEffect(()=>{C()},[C]);const M=async T=>{S(!0),E(null),N("");try{a(await Rx(e,T))}catch(j){N(String(j.message||j))}S(!1)},I=async()=>{S(!0),E(null),N("");try{E({kind:"test",...await Px(e)})}catch(T){N(String(T.message||T))}S(!1)},G=async()=>{S(!0),E(null),N("");try{E({kind:"stop",...await Lx(e)})}catch(T){N(String(T.message||T))}S(!1)},W=[],V=new Set,K=(T,j)=>{const B=typeof T=="string"?T.toLowerCase():"";!/^[a-f0-9]{32}$/.test(B)||V.has(B)||(V.add(B),W.push({id:B,label:j||B}))};K(s==null?void 0:s.nodeId,f("audio-group-local"));for(const T of n||[])K((T==null?void 0:T.nodeId)||(T==null?void 0:T.instanceId),(T==null?void 0:T.label)||(T==null?void 0:T.name)||(T==null?void 0:T.nodeId));for(const T of p.targets)K(T,`${T} (${f("audio-group-unavailable-target")})`);const Y=(T=null)=>{N(""),T?(y(T.name),m({name:T.name,mode:T.mode,targets:[...T.targets||[]]})):(y(null),m({name:"",mode:"primary-failover",targets:[]}))},Z=(T,j)=>m(B=>({...B,targets:j?[...new Set([...B.targets,T])]:B.targets.filter(A=>A!==T)})),U=async()=>{const T=p.name.trim().toLowerCase();if(!/^[a-z0-9][a-z0-9-]{0,31}$/.test(T)||p.targets.length<1){N(f("audio-group-invalid"));return}S(!0),N("");try{const j=await Mx(e,T,{targets:p.targets,mode:p.mode}),B=j==null?void 0:j.group;if(!B||!B.name)throw new Error(f("audio-group-save-failed"));d(A=>[...A.filter(D=>D.name!==B.name),B].sort((D,O)=>D.name.localeCompare(O.name))),Y(null)}catch(j){N(String(j.message||j))}S(!1)},$=async T=>{S(!0),N("");try{await Tx(e,T),d(j=>j.filter(B=>B.name!==T)),v===T&&Y(null)}catch(j){N(String(j.message||j))}S(!1)},R=(o==null?void 0:o.installed)===!0,z=(o==null?void 0:o.liveness)==="ready",F=(o==null?void 0:o.consent)===!0&&R&&z,L=k?k.kind==="stop"?f(k.stopped?"audio-stop-stopped":"audio-stop-idle"):k.status==="accepted"||k.status==="spoken"?f("audio-test-accepted"):k.status==="unknown"?f("audio-test-unknown"):`${f("audio-test-refused")}${k.reason?` (${k.reason})`:""}`:"";return l.jsxs("div",{className:"nc-set-tab nc-audio-settings",children:[l.jsxs("div",{className:"nc-set-info",children:[l.jsx("b",{children:f("audio-title")}),l.jsx("br",{}),f("audio-help")]}),o?l.jsxs(l.Fragment,{children:[l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox","aria-label":f("audio-consent"),checked:o.consent===!0,disabled:t||b,onChange:T=>{M(T.target.checked)}}),l.jsxs("span",{children:[l.jsx("b",{children:f("audio-consent")}),l.jsx("small",{children:f("audio-consent-help")})]})]}),l.jsxs("div",{className:"nc-set-form",children:[l.jsx("div",{className:"nc-sheet-label",children:f("audio-capability")}),l.jsxs("div",{className:"nc-set-info",children:[f("audio-adapter"),": ",o.adapter||f("audio-adapter-none"),l.jsx("br",{}),f("audio-installed"),": ",f(R?"audio-installed-yes":"audio-installed-no"),l.jsx("br",{}),f("audio-liveness"),": ",f(z?"audio-liveness-ready":"audio-liveness-unavailable"),Array.isArray(o.languages)&&o.languages.length>0&&l.jsxs(l.Fragment,{children:[l.jsx("br",{}),f("audio-languages"),": ",o.languages.join(", ")]})]}),o.limits&&l.jsxs("small",{className:"nc-set-hint",children:[f("audio-limits"),": ",o.limits]})]}),!o.consent&&l.jsx("div",{className:"nc-set-info",children:f("audio-test-needs-consent")}),!R&&l.jsx("div",{className:"nc-set-info",children:f("audio-unavailable")}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn primary",disabled:t||b||!F,title:t?f("settings-readonly"):"",onClick:()=>{I()},children:f(b?"audio-testing":"audio-test")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:b,onClick:()=>{G()},children:f(b?"audio-stopping":"audio-stop")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:b,onClick:()=>{C()},children:f("refresh")})]}),l.jsxs("div",{className:"nc-set-form",children:[l.jsx("div",{className:"nc-sheet-label",children:f("audio-groups-title")}),l.jsx("small",{className:"nc-set-hint",children:f("audio-groups-help")}),u.length===0&&l.jsx("div",{className:"nc-set-info",children:f("audio-groups-empty")}),u.map(T=>{var j;return l.jsxs("div",{className:"nc-set-row",children:[l.jsxs("span",{children:[l.jsx("b",{children:T.name})," ",l.jsxs("small",{children:["· ",T.mode==="fanout"?f("audio-group-fanout"):f("audio-group-primary")," · ",((j=T.targets)==null?void 0:j.length)||0]})]}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:t||b,onClick:()=>Y(T),children:f("audio-group-edit")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:t||b,onClick:()=>{$(T.name)},children:f("audio-group-delete")})]},T.name)}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:t||b,onClick:()=>Y(null),children:f("audio-group-new")})}),l.jsxs("label",{className:"nc-field",children:[f("audio-group-name"),l.jsx("input",{"aria-label":f("audio-group-name"),value:p.name,maxLength:"32",disabled:t||b,onChange:T=>m(j=>({...j,name:T.target.value}))})]}),l.jsxs("label",{className:"nc-field",children:[f("audio-group-mode"),l.jsxs("select",{"aria-label":f("audio-group-mode"),value:p.mode,disabled:t||b,onChange:T=>m(j=>({...j,mode:T.target.value})),children:[l.jsx("option",{value:"primary-failover",children:f("audio-group-primary")}),l.jsx("option",{value:"fanout",children:f("audio-group-fanout")})]})]}),l.jsx("div",{className:"nc-set-info",children:f("audio-group-targets")}),W.length===0?l.jsx("small",{className:"nc-set-hint",children:f("audio-group-no-targets")}):W.map(T=>l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:p.targets.includes(T.id),disabled:t||b,onChange:j=>Z(T.id,j.target.checked)}),l.jsxs("span",{children:[T.label,l.jsx("small",{children:T.id})]})]},T.id)),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn primary",disabled:t||b,onClick:()=>{U()},children:f("audio-group-save")}),v&&l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:b,onClick:()=>Y(null),children:f("audio-group-cancel")})]})]})]}):l.jsx("div",{className:"nc-set-info",children:f("audio-loading")}),L&&l.jsx("div",{className:"nc-set-note",role:"status",children:L}),w&&l.jsx("div",{className:"nc-err",children:w})]})}function JR(){const[e,t]=rp();return l.jsxs("div",{className:"nc-set-tab nc-input-settings",children:[l.jsx("div",{className:"nc-set-info",children:f("input-settings-local")}),l.jsxs("div",{className:"nc-set-form",children:[l.jsxs("label",{className:"nc-field",children:[f("terminal-keyboard-gesture"),l.jsx("select",{"aria-label":f("terminal-keyboard-gesture"),value:e.terminalKeyboardGesture,onChange:n=>t({terminalKeyboardGesture:n.target.value}),children:xw.map(n=>l.jsx("option",{value:n,children:f(`terminal-keyboard-${n}`)},n))}),l.jsx("small",{children:f("terminal-keyboard-gesture-help")})]}),l.jsxs("label",{className:"nc-field",children:[f("keybar-layout"),l.jsx("select",{"aria-label":f("keybar-layout"),value:e.keybarLayout,onChange:n=>t({keybarLayout:n.target.value}),children:kw.map(n=>l.jsx("option",{value:n,children:f(`keybar-layout-${n}`)},n))}),l.jsx("small",{children:f("keybar-layout-help")})]})]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:e.keybarKeepsKeyboardClosed,onChange:n=>t({keybarKeepsKeyboardClosed:n.target.checked})}),l.jsxs("span",{children:[l.jsx("b",{children:f("keybar-ime-lock")}),l.jsx("small",{children:f("keybar-ime-lock-help")})]})]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:e.voiceKeepsKeyboardClosed,onChange:n=>t({voiceKeepsKeyboardClosed:n.target.checked})}),l.jsxs("span",{children:[l.jsx("b",{children:f("voice-ime-lock")}),l.jsx("small",{children:f("voice-ime-lock-help")})]})]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:e.showKeybarEnter,onChange:n=>t({showKeybarEnter:n.target.checked})}),l.jsxs("span",{children:[l.jsx("b",{children:f("keybar-enter-show")}),l.jsx("small",{children:f("keybar-enter-show-help")})]})]}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:()=>t(Us),children:f("input-settings-reset")})})]})}function ZR({token:e,roster:t=[],readonly:n}){const s=[{key:"local",route:[],label:f("diagnostics-local"),status:"up"},...t.filter(F=>Array.isArray(F.route)&&F.route.length).map(F=>({key:F.route.join("/"),route:F.route,label:F.label||F.name,status:F.status}))],[o,a]=x.useState("local"),u=s.find(F=>F.key===o)||s[0],[d,p]=x.useState(null),[m,v]=x.useState([]),[y,b]=x.useState(""),[S,k]=x.useState(!1),[E,w]=x.useState(!0),[N,C]=x.useState(900),[M,I]=x.useState("all"),[G,W]=x.useState(""),V=x.useRef(0),K=x.useRef(null),Y=x.useCallback(async()=>{try{const F=await Bx(e,u.route);if(p(F),b(""),!S){const L=await zx(e,{after:V.current,limit:200},u.route);Array.isArray(L.records)&&L.records.length&&(V.current=L.cursor,v(T=>[...T,...L.records].slice(-500)))}}catch(F){b(F&&F.status===404?f("diagnostics-unsupported"):String(F.message||F))}},[e,u.key,S]);x.useEffect(()=>{V.current=0,v([]),p(null),b("")},[u.key]),x.useEffect(()=>{let F=null,L=!0;const T=()=>{!L||document.visibilityState==="hidden"||Y()},j=()=>{F&&clearInterval(F),F=document.visibilityState==="hidden"?null:setInterval(T,2e3),document.visibilityState!=="hidden"&&T()};return document.addEventListener("visibilitychange",j),j(),()=>{L=!1,F&&clearInterval(F),document.removeEventListener("visibilitychange",j)}},[Y]),x.useEffect(()=>{E&&K.current&&(K.current.scrollTop=K.current.scrollHeight)},[m,E]);const Z=m.filter(F=>(M==="all"||F.level===M)&&(!G||String(F.component||"").toLowerCase().includes(G.toLowerCase()))),U=Z.map(F=>`${F.ts} ${F.level.toUpperCase()} ${F.component} ${F.code} ${F.message}${Object.keys(F.meta||{}).length?` ${JSON.stringify(F.meta)}`:""}`).join(`
92
92
  `),$=async F=>{b("");try{const L=await F();p(L),await Y()}catch(L){b(String(L.message||L))}},R=async()=>{try{await navigator.clipboard.writeText(U)}catch{b(f("copy-manual"))}},z=()=>{try{const F=new Blob([`${JSON.stringify(Z,null,2)}
93
- `],{type:"application/json"}),L=URL.createObjectURL(F),T=document.createElement("a");T.href=L,T.download="nexuscrew-diagnostics.json",T.click(),URL.revokeObjectURL(L)}catch{b(f("diagnostics-export-failed"))}};return l.jsxs("div",{className:"nc-set-tab nc-diagnostics",children:[l.jsxs("label",{className:"nc-field",children:[f("diagnostics-target"),l.jsx("select",{value:u.key,onChange:F=>a(F.target.value),children:s.map(F=>l.jsxs("option",{value:F.key,children:[F.label,F.status!=="up"?` · ${F.status}`:""]},F.key))})]}),l.jsxs("div",{className:"nc-set-form nc-diag-controls",children:[l.jsx("div",{className:"nc-sheet-label",children:f("diagnostics-verbose")}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("select",{"aria-label":f("diagnostics-duration"),value:N,onChange:F=>C(Number(F.target.value)),disabled:n,children:[300,900,1800,3600].map(F=>l.jsxs("option",{value:F,children:[F/60," min"]},F))}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||(d==null?void 0:d.verbose)===!0,onClick:()=>$(()=>Zg(e,!0,N,u.route)),children:f("enable")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||(d==null?void 0:d.verbose)!==!0,onClick:()=>$(()=>Zg(e,!1,N,u.route)),children:f("stop")})]}),l.jsx("small",{className:"nc-set-hint",children:d!=null&&d.verbose?f("diagnostics-expires").replace("{time}",new Date(d.expiresAt).toLocaleTimeString()):f("diagnostics-off")})]}),l.jsxs("div",{className:"nc-diag-filters",children:[l.jsxs("select",{"aria-label":f("diagnostics-level"),value:M,onChange:F=>I(F.target.value),children:[l.jsx("option",{value:"all",children:f("diagnostics-all-levels")}),["debug","info","warn","error"].map(F=>l.jsx("option",{value:F,children:F},F))]}),l.jsx("input",{"aria-label":f("diagnostics-component"),placeholder:f("diagnostics-component"),value:G,onChange:F=>W(F.target.value)})]}),l.jsxs("div",{className:"nc-set-row",children:[l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:S,onChange:F=>k(F.target.checked)})," ",f("diagnostics-pause")]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:E,onChange:F=>w(F.target.checked)})," ",f("diagnostics-autoscroll")]})]}),l.jsx("pre",{ref:K,className:"nc-diag-log","aria-label":f("diagnostics-log"),children:U||f("diagnostics-empty")}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:R,children:f("copy")}),l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:z,children:f("diagnostics-export")}),l.jsx("button",{type:"button",className:"nc-btn danger",disabled:n,onClick:()=>{window.confirm(f("diagnostics-clear-confirm"))&&$(async()=>{const F=await $x(e,u.route);return V.current=0,v([]),F})},children:f("diagnostics-clear")})]}),y&&l.jsx("div",{className:"nc-err",children:y})]})}function eP({token:e,settings:t,readonly:n,refresh:s,roster:o,section:a,setSection:u}){const[d,p]=x.useState(null),[m,v]=x.useState(null),[y,b]=x.useState(!1),[S,k]=x.useState(!1),[E,w]=x.useState(null),[N,C]=x.useState(!0),[M,I]=x.useState(!1);x.useEffect(()=>{w(t&&t.update||null),C(!t||t.autoUpdate!==!1),I(!!(t&&t.alternateScreen))},[t]);const G=async()=>{p(null),v(null),k(!0);try{const R=await bx(e);v(R.note||"ok"),b(!1)}catch(R){p(String(R.message||R))}k(!1)},W=async()=>{p(null),v(null),k(!0);try{const R=await Dx(e);v(`${R.note||"ok"}${R.target?` (${R.target})`:""}`)}catch(R){p(String(R.message||R))}k(!1)},V=async R=>{p(null),v(null),k(!0);try{await ph(e,{autoUpdate:R}),C(R),s&&await s()}catch(z){p(String(z.message||z))}k(!1)},K=async R=>{p(null),v(null),k(!0);try{await ph(e,{alternateScreen:R}),I(R),s&&await s()}catch(z){p(String(z.message||z))}k(!1)},Y=async()=>{p(null),v(null),k(!0);try{w(await Ix(e))}catch(R){p(String(R.message||R))}k(!1)},Z=async()=>{p(null),v(null),k(!0);try{const R=await Ox(e);w(R),v(f("npm-update-restarting"))}catch(R){p(String(R.message||R))}k(!1)},U=()=>{window.confirm(f("composer-clear-confirm"))&&(p(null),s2()?(window.dispatchEvent(new Event(df)),v(f("composer-clear-done"))):p(f("composer-clear-failed")))},$=t&&t.service;return l.jsxs("div",{className:"nc-set-tab",children:[l.jsx("div",{className:"nc-system-tabs",role:"tablist","aria-label":f("tab-system"),children:["general","diagnostics"].map(R=>l.jsx("button",{type:"button",role:"tab","aria-selected":a===R,className:`nc-set-tabbtn${a===R?" on":""}`,onClick:()=>u(R),children:f(`system-${R}`)},R))}),a==="general"&&l.jsxs(l.Fragment,{children:[l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:f("system-this-node")}),t&&l.jsxs("div",{className:"nc-set-info",children:["v",t.version," · ",t.platform," · :",t.port,l.jsx("br",{}),$&&$.installed?f("service-installed"):f("service-missing"),$&&$.installed?` · ${$.active?f("service-active"):f("service-inactive")}`:"",$?` · boot ${$.boot?"on":"off"}`:""]}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||S,title:n?f("settings-readonly"):"",onClick:W,children:f("service-regenerate")})}),l.jsx(GR,{token:e,readonly:n}),l.jsx(XR,{})]}),l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:f("system-updates")}),l.jsxs("div",{className:"nc-set-form nc-update-settings",children:[l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:N,disabled:n||S||E&&!E.supported,onChange:R=>V(R.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:f("npm-auto-update")}),l.jsx("small",{children:f("npm-auto-update-help")})]})]}),E&&l.jsxs("div",{className:"nc-set-info",children:[f("npm-update-current")," v",E.current,E.latest?` · ${f("npm-update-latest")} v${E.latest}`:""," · ",f(E.supported?E.phase==="idle"&&E.checked!==!0?"npm-update-never":`npm-update-${E.phase}`:"unsupported")]}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||S||!E||!E.supported,onClick:Y,children:f("npm-update-check")}),E&&E.available&&l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||S||E.phase==="installing",onClick:Z,children:f("npm-update-install")})]}),E&&E.lastError&&l.jsx("div",{className:"nc-err",children:E.lastError})]})]}),l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:f("system-security")}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||S,title:n?f("settings-readonly"):"",onClick:()=>{p(null),v(null),b(!0)},children:f("token-rotate")})})]}),l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:f("system-local-data")}),l.jsxs("div",{className:"nc-set-form",children:[l.jsx("div",{className:"nc-sheet-label",children:f("composer-clear-data")}),l.jsx("small",{className:"nc-set-hint",children:f("composer-clear-data-help")}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:U,children:f("composer-clear-data")})})]})]})]}),a==="diagnostics"&&l.jsxs("section",{className:"nc-system-group nc-system-diagnostics",children:[l.jsx("h3",{children:f("system-diagnostics")}),l.jsxs("div",{className:"nc-set-form nc-alternate-screen-settings",children:[l.jsx("div",{className:"nc-sheet-label",children:f("system-terminal")}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox","aria-label":f("alternate-screen"),checked:M,disabled:n||S,onChange:R=>K(R.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:f("alternate-screen")}),l.jsx("small",{children:f("alternate-screen-help")})]})]})]}),l.jsx(ZR,{token:e,roster:o,readonly:n})]}),y&&l.jsxs("div",{className:"nc-set-confirm",children:[l.jsx("div",{children:f("token-rotate-explain")}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:S,onClick:()=>b(!1),children:f("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:S,onClick:G,children:f("confirm")})]})]}),m&&l.jsx("div",{className:"nc-set-note",children:m}),d&&l.jsx("div",{className:"nc-err",children:d})]})}function tP({token:e,onClose:t,initialTab:n="nodes",initialLocation:s="",startNewCell:o=!1}){Vn();const a=n==="diagnostics"?"diagnostics":"general",[u,d]=x.useState(n==="diagnostics"?"system":n),p=x.useRef(null),m=x.useRef(null),[v,y]=x.useState({start:!1,end:!1}),[b,S]=x.useState(a),[k,E]=x.useState(null),[w,N]=x.useState([]),[C,M]=x.useState([]),[I,G]=x.useState(!1),[W,V]=x.useState(null),[K,Y]=x.useState(0),Z=Tf(e,!0,K),U=x.useCallback(()=>{const R=p.current;if(!R)return;const z=R.scrollWidth>R.clientWidth+1,F={start:z&&R.scrollLeft>1,end:z&&R.scrollLeft+R.clientWidth<R.scrollWidth-1};y(L=>L.start===F.start&&L.end===F.end?L:F)},[]);x.useEffect(()=>{const R=p.current;if(!R)return;const z=typeof ResizeObserver=="function"?new ResizeObserver(U):null;return z==null||z.observe(R),window.addEventListener("resize",U),U(),()=>{z==null||z.disconnect(),window.removeEventListener("resize",U)}},[U]),x.useEffect(()=>{var z,F;(F=(z=m.current)==null?void 0:z.scrollIntoView)==null||F.call(z,{behavior:"smooth",block:"nearest",inline:"nearest"});const R=window.requestAnimationFrame?window.requestAnimationFrame(U):setTimeout(U,0);return()=>{window.cancelAnimationFrame?window.cancelAnimationFrame(R):clearTimeout(R)}},[u,U]);const $=x.useCallback(async()=>{var R;try{const z=await Fy(e);E(z),V(null)}catch(z){V(String(z.message||z))}try{const F=(await _x(e)).peers||[];let L=[],T=[];try{const[j,B]=await Promise.all([an("/api/config",e).then(H=>H.json()).catch(()=>null),Uy(e).catch(()=>null)]),A=j&&typeof j.instanceId=="string"?j.instanceId:"",D=[{instanceId:A||null,route:[],label:null},...Jy(B,A)],O=await Promise.all(D.map(async H=>{try{return{ok:!0,peers:((await Hy(e,H.route)).nodes||[]).map(ue=>Qy(ue,H)).filter(Boolean)}}catch(ie){return{ok:!1,owner:H,error:ie}}}));for(const H of O){if(H.ok){L.push(...H.peers);continue}H.owner.route.length!==0&&T.push({instanceId:H.owner.instanceId,label:H.owner.label,route:H.owner.route,failure:/timeout/i.test(String(((R=H.error)==null?void 0:R.message)||H.error))?"timeout":"unreachable"})}}catch{}M(T),N([...F,...L])}catch(z){V(String(z.message||z))}},[e]);return x.useEffect(()=>{$();const R=setInterval($,5e3);return()=>clearInterval(R)},[$]),x.useEffect(()=>{let R=!1;return an("/api/config",e).then(z=>z.json()).then(z=>{R||G(!!z.readonlyDefault)}).catch(()=>{}),()=>{R=!0}},[e]),l.jsx("div",{className:"nc-set-overlay",onClick:t,children:l.jsxs("div",{className:"nc-set-panel",onClick:R=>R.stopPropagation(),children:[l.jsxs("div",{className:"nc-set-head",children:[l.jsx(ut,{name:"gear",size:18}),l.jsx("b",{children:f("settings")}),l.jsx("button",{type:"button",className:"nc-set-close",onClick:t,title:f("close"),children:l.jsx(ut,{name:"x",size:18})})]}),I&&l.jsx("div",{className:"nc-set-readonly",children:f("settings-readonly")}),W&&l.jsx("div",{className:"nc-err",children:W}),l.jsx("div",{className:`nc-set-tabs-wrap${v.start?" has-start-overflow":""}${v.end?" has-end-overflow":""}`,children:l.jsx("div",{className:"nc-set-tabs",ref:p,onScroll:U,children:["nodes","fleet","audio","input","system"].map(R=>l.jsx("button",{ref:u===R?m:null,type:"button",className:`nc-set-tabbtn${u===R?" on":""}`,onClick:()=>d(R),children:f(`tab-${R}`)},R))})}),l.jsxs("div",{className:"nc-set-body",children:[u==="nodes"&&l.jsx(YR,{token:e,nodes:w,roster:Z,settings:k,readonly:I,vlUnavailable:C,refresh:$,refreshAliases:()=>Y(R=>R+1)}),u==="fleet"&&l.jsx(RR,{token:e,readonly:I,startNewCell:o,initialLocation:s,targets:Z.map(R=>({route:R.route,label:R.label||R.name,status:R.status}))}),u==="audio"&&l.jsx(QR,{token:e,readonly:I,nodes:w,settings:k}),u==="input"&&l.jsx(JR,{}),u==="system"&&l.jsx(eP,{token:e,settings:k,readonly:I,refresh:$,roster:Z,section:b,setSection:S})]})]})})}function nP({token:e,initialPair:t,deviceDefault:n="",localNodeId:s="",localNameDefault:o="",onPairDone:a,onDone:u}){Vn();const[d,p]=x.useState(t?"pair":"welcome"),[m,v]=x.useState(!1),[y,b]=x.useState(null),[S,k]=x.useState(null),E=async()=>{v(!0),b(null);try{await ph(e,{wizardDone:!0}),a&&a(),u()}catch(w){b(String(w.message||w)),v(!1)}};return l.jsx("div",{className:"nc-wiz-overlay",children:l.jsxs("div",{className:"nc-wiz",children:[l.jsxs("div",{className:"nc-wiz-head",children:[l.jsx("b",{children:f("wizard-title")}),l.jsx("small",{children:f("hydra-simple")})]}),d==="welcome"&&l.jsxs("div",{className:"nc-wiz-body",children:[l.jsx("div",{className:"nc-wiz-done",children:f("local-ready")}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{className:"nc-btn ghost",disabled:m,onClick:E,children:f("local-only")}),l.jsx("button",{className:"nc-btn primary",disabled:m,onClick:()=>p("pair"),children:f("add-node")})]})]}),d==="pair"&&l.jsxs("div",{className:"nc-wiz-body",children:[l.jsx(qw,{token:e,initial:t||"",autoStart:!!t,deviceDefault:n,localNodeId:s,localNameDefault:o,onBusyChange:v,onSuccess:async w=>{k(w&&w.authorizedKeys?{line:w.authorizedKeys,note:w.authorizedKeysNote||""}:null),a&&a(),p("done")}}),l.jsx("div",{className:"nc-sheet-actions",children:l.jsx("button",{className:"nc-btn ghost",disabled:m,onClick:()=>{a&&a(),p("welcome")},children:f("back")})})]}),d==="done"&&l.jsxs("div",{className:"nc-wiz-body",children:[l.jsx("div",{className:"nc-wiz-done",children:f("node-connected")}),S&&l.jsx(mp,{line:S.line,note:S.note}),l.jsx("div",{className:"nc-sheet-actions",children:l.jsx("button",{className:"nc-btn primary",disabled:m,onClick:E,children:f("finish")})})]}),y&&l.jsx("div",{className:"nc-err",children:y})]})})}function iP(e,t){if(typeof EventSource>"u"||!e)return()=>{};const n=new EventSource(`/api/events?token=${encodeURIComponent(e)}`);return n.onmessage=s=>{try{const o=JSON.parse(s.data);o&&typeof o=="object"&&typeof o.type=="string"&&t(o)}catch{}},()=>{try{n.close()}catch{}}}const sP=6e3,rP=12e3;function oP({n:e,onClose:t}){return l.jsxs("div",{className:`nc-ntf-toast${e.urgency==="high"?" high":""}`,role:"status","aria-live":"polite",children:[l.jsxs("div",{className:"nc-ntf-toast-txt",children:[l.jsx("b",{children:e.title}),e.body&&l.jsx("small",{children:e.body}),e.session&&l.jsx("span",{className:"nc-ntf-from",children:e.session})]}),l.jsx("button",{type:"button",className:"nc-ntf-x",onClick:t,title:f("close"),children:l.jsx(ut,{name:"x",size:14})})]})}function aP({ask:e,token:t,onAnswered:n,onDismiss:s}){const[o,a]=x.useState(""),[u,d]=x.useState(!1),[p,m]=x.useState(null),[v,y]=x.useState(!1),b=async k=>{const E=String(k||"").trim();if(!(!E||u)){m(null),d(!0);try{await Hx(t,e.id,E),n(e.id)}catch(w){m(String(w.message||w))}d(!1)}},S=async()=>{if(!v){y(!0);try{await Ux(t,e.id),s(e.id)}catch{y(!1)}}};return l.jsxs("div",{className:"nc-ask-card",children:[l.jsxs("div",{className:"nc-ask-head",children:[l.jsx("span",{className:"nc-ntf-from",children:e.session}),l.jsxs("code",{className:"nc-ask-id",children:["#",e.id]}),l.jsx("button",{type:"button",className:"nc-ask-dismiss",title:f("ask-dismiss"),"aria-label":f("ask-dismiss"),disabled:v,onClick:S,children:l.jsx(ut,{name:"x",size:14})})]}),l.jsx("div",{className:"nc-ask-q",children:e.question}),Array.isArray(e.options)&&e.options.length>0&&l.jsx("div",{className:"nc-ask-opts",children:e.options.map(k=>l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:u,onClick:()=>b(k),children:k},k))}),l.jsxs("div",{className:"nc-ask-reply",children:[l.jsx("textarea",{rows:2,placeholder:f("ask-reply-ph"),value:o,disabled:u,onChange:k=>a(k.target.value)}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:u||!o.trim(),onClick:()=>b(o),children:f("send")})]}),p&&l.jsx("div",{className:"nc-err",children:p})]})}function lP({token:e}){const[t]=Vn(),[n]=cS(),[s,o]=x.useState([]),[a,u]=x.useState([]),[d,p]=x.useState(()=>{try{return/(?:^|[#&])ask=/.test(location.hash)}catch{return!1}}),m=x.useRef(0),v=x.useRef(null);v.current||(v.current=KR());const y=x.useRef({enabled:n,lang:t});y.current={enabled:n,lang:t};const b=x.useCallback(w=>{o(N=>N.filter(C=>C.key!==w))},[]),S=x.useCallback(w=>{const N=`t${m.current+=1}`;o(M=>[...M.slice(-3),{...w,key:N}]),setTimeout(()=>b(N),w.urgency==="high"?rP:sP);const C=y.current;if(C.enabled)try{v.current.enqueue(w,$R(w,C.lang))}catch{}},[b]);x.useEffect(()=>{n||v.current.stop()},[n]),x.useEffect(()=>{const w=()=>{(document.visibilityState!=="visible"||!document.hasFocus())&&v.current.stop()},N=()=>v.current.stop();return document.addEventListener("visibilitychange",w),window.addEventListener("blur",w),window.addEventListener(yf,N),()=>{document.removeEventListener("visibilitychange",w),window.removeEventListener("blur",w),window.removeEventListener(yf,N),typeof v.current.dispose=="function"?v.current.dispose():v.current.stop()}},[]),x.useEffect(()=>{if(!e)return;let w=!1;Fx(e).then(C=>{w||u(C.asks||[])}).catch(()=>{});const N=iP(e,C=>{C.type==="notify"?S(C):C.type==="ask"&&C.ask&&C.ask.id?u(M=>M.some(I=>I.id===C.ask.id)?M:[...M,C.ask]):C.type==="ask-answered"&&C.id?u(M=>M.filter(I=>I.id!==C.id)):C.type==="ask-dismissed"&&C.id&&u(M=>M.filter(I=>I.id!==C.id))});return()=>{w=!0,N()}},[e,S]);const k=w=>u(N=>N.filter(C=>C.id!==w)),E=w=>u(N=>N.filter(C=>C.id!==w));return l.jsxs(l.Fragment,{children:[s.length>0&&l.jsx("div",{className:"nc-ntf-toasts",children:s.map(w=>l.jsx(oP,{n:w,onClose:()=>b(w.key)},w.key))}),a.length>0&&!d&&l.jsxs("button",{type:"button",className:"nc-ask-badge",onClick:()=>p(!0),title:f("asks-title"),children:["? ",l.jsx("span",{className:"nc-ask-count",children:a.length})]}),a.length>0&&d&&l.jsxs("div",{className:"nc-ask-panel",children:[l.jsxs("div",{className:"nc-ask-panel-head",children:[l.jsx("b",{children:f("asks-title")}),l.jsx("span",{className:"nc-ask-count",children:a.length}),l.jsx("button",{type:"button",className:"nc-ntf-x",onClick:()=>p(!1),title:f("close"),children:l.jsx(ut,{name:"x",size:16})})]}),l.jsx("div",{className:"nc-ask-panel-body",children:a.map(w=>l.jsx(aP,{ask:w,token:e,onAnswered:k,onDismiss:E},w.id))})]})]})}const cP=4e3;async function uP(e){const t=await an("/api/sessions",e);if((t==null?void 0:t.ok)===!1)throw new Error(`HTTP ${t.status}`);const n=await t.json();if(!Array.isArray(n==null?void 0:n.sessions))throw new Error("invalid sessions payload");return n.sessions}async function uh(e,t=[]){var d;const[n,s]=await Promise.allSettled([t.length?Pf(e,t):uP(e),Gs(e,t)]),o=n.status==="fulfilled"&&Array.isArray((d=n.value)==null?void 0:d.sessions)?n.value.sessions:Array.isArray(n.value)?n.value:null,a=s.status==="fulfilled"?s.value:null,u=(a==null?void 0:a.available)===!0&&Array.isArray(a.cells)?a.cells:null;return{sessions:o,cells:u,fresh:Array.isArray(o)&&Array.isArray(u)}}function uS(e,t,n){return n===!0&&(e==null?void 0:e.degraded)!==!0&&(e==null?void 0:e.active)===!0&&e.tmux!==!1&&!!e.tmuxSession&&(t||[]).some(s=>(s==null?void 0:s.name)===e.tmuxSession)}function dP(e){const t=new Map((e.sessions||[]).map(o=>[o.name,o])),n=[],s=(o,a,u,d=[],p="")=>{const m=new Map((a||[]).map(v=>[v.name,v]));for(const v of o||[]){const y=m.get(v.tmuxSession)||{},b=Bf(v,y),S=uS(v,a,u);n.push({key:xa(d,v.tmuxSession||v.cell),session:v.tmuxSession,route:d,cellName:v.cell,label:v.cell,node:d.length?d.join("/"):"",nodeLabel:p,live:S,selectable:S,verified:u===!0,working:b.working,degraded:!!v.degraded,active:v.active===!0,activity:y.activity||v.activity||0,subtitle:b.subtitle,preview:y.preview||v.preview||"",telemetry:y.telemetry||null,panelUrl:v.panelUrl||""})}};s(e.cells,[...t.values()],e.localFresh===!0);for(const o of e.nodeGroups||[]){const a=Array.isArray(o.route)?o.route:[];o.kind==="vl"||!a.length||s(o.cells,o.sessions,o.switcherFresh===!0,a,o.label||o.name||"")}return n}function hP(e){const t=new Map,n=Array.isArray(e.sessions)?e.sessions:[],s=Array.isArray(e.cells)?e.cells:[],o=new Map(n.map(u=>[u.name,u])),a=new Set(s.map(u=>u.tmuxSession).filter(Boolean));t.set("local",zf(s,n.filter(u=>!a.has(u.name)),o));for(const u of e.nodeGroups||[]){const d=Array.isArray(u.route)?u.route:[];if(u.kind==="vl"||!d.length)continue;const p=Array.isArray(u.cells)?u.cells:[],m=Array.isArray(u.sessions)?u.sessions:[],v=new Set(p.map(y=>y.tmuxSession).filter(Boolean));t.set(d.join("/"),dc({...u,route:d,cells:p,sessions:m,unmanaged:m.filter(y=>!v.has(y.name))}).rawItems)}return t}function fP(e,t,n,s){return[...new Set(e.map(a=>a.node||"local"))].flatMap(a=>{const u=e.filter(v=>(v.node||"local")===a),d=new Map((t.get(a)||[]).map(v=>[v.key,v])),p=new Map(u.map(v=>[v.key,v])),m=u.map(v=>{const y=d.get(v.key);return{...v,label:(y==null?void 0:y.label)||v.label,live:(y==null?void 0:y.live)??v.live,fresh:(y==null?void 0:y.fresh)===!0,activity:(y==null?void 0:y.activity)??v.activity}});return Ks(m,n,"all",ps(s,a)).map(v=>p.get(v.key))})}function pP({token:e,current:t,onPick:n,onClose:s,panelPort:o=0,nodePanelPorts:a={}}){const[u,d]=x.useState(vv),[p,m]=x.useState(!1),[v,y]=x.useState(!1),[b,S]=x.useState(""),[k,E]=x.useState(null),[w,N]=x.useState(""),[C,M]=x.useState(""),I=x.useRef(null),G=x.useRef(null),W=x.useMemo(()=>dP(u),[u]),V=x.useMemo(()=>hP(u),[u]),{pins:K,orders:Y,canMoveRoster:Z,moveRoster:U,stepRoster:$}=If(),R=x.useMemo(()=>fP(W,V,K,Y),[W,V,K,Y]),z=x.useMemo(()=>p?R:R.filter(A=>A.selectable||A.degraded&&A.active),[R,p]),F=x.useMemo(()=>W.find(A=>A.key===w&&A.selectable),[W,w]),L=x.useMemo(()=>k?W.find(A=>A.key===k.key):null,[W,k]);x.useEffect(()=>{var O;const A=document.activeElement;(O=G.current)==null||O.focus();const D=H=>{H.key==="Escape"&&s()};return document.addEventListener("keydown",D),()=>{var H;document.removeEventListener("keydown",D),(H=A==null?void 0:A.focus)==null||H.call(A)}},[s]),x.useEffect(()=>{let A=!0,D=!1;const O=async()=>{if(D)return;D=!0;const ie=vv(),ee=Array.isArray(ie.nodeGroups)?ie.nodeGroups:[],ue=uh(e),ve=Ne=>Ne.kind!=="vl"&&Array.isArray(Ne.route)&&Ne.route.length>0,fe=await Promise.all(ee.filter(ve).map(async Ne=>({group:Ne,result:await uh(e,Ne.route)}))),pe=await ue;if(!A)return;const Ye=new Map(fe.map(({group:Ne,result:Ct})=>[JSON.stringify(Ne.route||[]),Ct])),ht=ee.map(Ne=>{if(!ve(Ne))return{...Ne,switcherFresh:!1};const Ct=Ye.get(JSON.stringify(Ne.route||[]));return Ct?{...Ne,sessions:Ct.sessions||Ne.sessions||[],cells:Ct.cells||Ne.cells||[],switcherFresh:Ct.fresh}:{...Ne,switcherFresh:!1}}),yt=vb({...ie,sessions:pe.sessions||ie.sessions||[],cells:pe.cells||ie.cells||[],localFresh:pe.fresh,nodeGroups:ht,refreshedAt:Date.now()});d(yt),y(!0),D=!1};O();const H=setInterval(O,cP);return()=>{A=!1,clearInterval(H)}},[e]);const T=A=>A.degraded?f("cell-degraded"):A.verified?A.selectable?A.working?f("cell-working"):f("cell-idle"):f("cell-off"):f("cell-switcher-not-confirmed"),j=A=>{if(S(""),!A.selectable){S(A.verified?f("cell-switcher-not-active"):f("cell-switcher-not-confirmed"));return}N(A.key)},B=async()=>{const A=F;if(!A){S(f("cell-switcher-select"));return}S(""),M(A.key);try{const D=await uh(e,A.route),O=(D.cells||[]).find(H=>(H==null?void 0:H.cell)===A.cellName&&(H==null?void 0:H.tmuxSession)===A.session);if(D.fresh!==!0){S(f("cell-switcher-verify-failed"));return}if(!uS(O,D.sessions,D.fresh)){S(f("cell-switcher-not-active"));return}n({session:A.session,...A.node?{node:A.node}:{},cellName:A.cellName}),s()}catch{S(f("cell-switcher-verify-failed"))}finally{M("")}};return l.jsx("div",{className:"nc-cell-switcher-backdrop",onClick:s,children:l.jsxs("aside",{ref:I,className:"nc-cell-switcher",role:"dialog","aria-label":f("fleet-cells"),tabIndex:-1,onClick:A=>A.stopPropagation(),children:[l.jsxs("div",{className:"nc-cell-switcher-list",children:[!v&&l.jsx("div",{className:"nc-empty",role:"status",children:f("cell-switcher-refreshing")}),v&&z.length===0&&l.jsx("div",{className:"nc-empty",role:"status",children:f("cell-switcher-empty-active")}),z.map(A=>{const D=(t==null?void 0:t.session)===A.session&&((t==null?void 0:t.node)||"")===A.node,O=w===A.key,H=T(A),ie=ff(f,A.activity),ee=pf(f,A.telemetry),ue=[ie,ee].filter(Boolean).join(" · "),ve=A.node||"local",fe=V.get(ve)||W.filter(pe=>(pe.node||"local")===ve);return l.jsxs("div",{className:`nc-cell-switcher-row${D?" current":""}${O?" selected":""}${A.selectable?"":" off"}`,"data-roster-key":A.key,"data-position":ve,children:[l.jsx(Vi,{position:ve,itemKey:A.key,label:A.cellName,canMove:Z,onMove:(pe,Ye)=>U(ve,pe,Ye,fe),onStep:pe=>$(ve,A.key,pe,fe)}),l.jsx("button",{type:"button",className:"nc-cell-switcher-peek",title:f("cell-peek"),"aria-label":`${f("cell-peek")}: ${A.cellName}`,onClick:pe=>{pe.stopPropagation(),E({key:A.key,source:"preview"})},children:l.jsx("span",{className:`nc-cell-switcher-dot${A.degraded?" warn":A.live?` on${A.working?" working":""}`:""}`})}),l.jsxs("span",{className:"nc-cell-switcher-acts",children:[l.jsx("button",{type:"button",className:"nc-cell-switcher-act",title:f("cell-peek-stream"),"aria-label":`${f("cell-peek-stream")}: ${A.cellName}`,onClick:pe=>{pe.stopPropagation(),E({key:A.key,source:"stream"})},children:"▶"}),A.panelUrl&&l.jsx("button",{type:"button",className:"nc-cell-switcher-act",title:f("cell-peek-panel"),"aria-label":`${f("cell-peek-panel")}: ${A.cellName}`,onClick:pe=>{pe.stopPropagation(),E({key:A.key,source:"panel"})},children:"▣"})]}),l.jsx("button",{type:"button",className:"nc-cell-switcher-row-select","aria-current":D?"true":void 0,"aria-pressed":O,"aria-disabled":!A.selectable,disabled:C===A.key,onClick:()=>j(A),children:l.jsxs("span",{className:"nc-cell-switcher-copy",children:[l.jsx("b",{children:A.cellName}),l.jsx("small",{className:"nc-cell-switcher-state",children:H}),l.jsx("small",{children:[A.nodeLabel,A.subtitle].filter(Boolean).join(" · ")}),ue&&l.jsx("small",{className:"nc-cell-switcher-telemetry",children:ue})]})})]},A.key)})]}),b&&l.jsx("div",{className:"nc-cell-switcher-notice",role:"status",children:b}),k&&L&&l.jsx(Sw,{row:L,token:e,initialSource:k.source,panelPort:Sc(L.route||[],a,o),onClose:()=>E(null)}),l.jsx("div",{className:"nc-cell-switcher-actions",children:l.jsx("button",{type:"button",className:"nc-cell-switcher-open",disabled:!F||!!C,onClick:B,children:F?`${f("cell-switcher-open")}: ${F.cellName}`:f("cell-switcher-select")})}),l.jsxs("div",{className:"nc-cell-switcher-controls",children:[l.jsx("b",{children:f("fleet-cells")}),l.jsx("button",{type:"button",className:"nc-cell-switcher-filter","aria-pressed":p,onClick:()=>{S(""),m(A=>!A)},children:f(p?"cell-switcher-show-active":"cell-switcher-show-all")}),l.jsx("button",{ref:G,type:"button",className:"nc-cell-switcher-close","aria-label":f("cell-switcher-close"),title:f("cell-switcher-close"),onClick:s,children:"×"})]})]})})}const mP=2e3;function gP(e){if(e.kind==="gap")return`${f("vl-events-gap")} ${e.count||"?"}`;if(e.kind==="truncate")return f("vl-events-truncated");if(e.kind==="turn_end")return f("vl-events-turn-end");if(e.kind==="done")return f("vl-events-done");if(e.kind==="writer_epoch")return f("vl-events-writer-epoch");if(e.kind==="tool_start")return`${f("vl-events-tool")} ${e.name||""}`.trim();if(e.kind==="tool_end"){const t=e.isError?f("vl-events-tool-failed"):f("vl-events-tool-ok");return`${f("vl-events-tool")} ${e.name||""} — ${t}`.trim()}return e.kind==="usage"?e.text||f("vl-events-usage"):e.text||""}function vP({token:e,nodeId:t,route:n=[]}){const[s,o]=x.useState([]),[a,u]=x.useState(!1),d=x.useRef(0),p=x.useRef(!1);return x.useEffect(()=>{let m=!0;d.current=0,p.current=!1,o([]);const v=async()=>{if(!p.current){p.current=!0;try{const S=await yx(e,t,d.current,n);if(!m)return;u(!1);const E=(Array.isArray(S==null?void 0:S.events)?S.events:[]).filter(w=>Number.isSafeInteger(w==null?void 0:w.seq)&&w.seq>d.current);E.length&&(o(w=>w.concat(E).slice(-500)),d.current=E[E.length-1].seq),Number.isSafeInteger(S==null?void 0:S.cursor)&&S.cursor>d.current&&(d.current=S.cursor)}catch{m&&u(!0)}finally{p.current=!1}}},y=()=>{v().catch(()=>{})};y();const b=setInterval(y,mP);return()=>{m=!1,clearInterval(b)}},[e,t,JSON.stringify(n)]),l.jsxs("div",{className:"nc-vl-events",children:[a&&l.jsx("div",{className:"nc-set-hint nc-vl-events-stale",children:f("vl-events-stale")}),s.length===0&&!a&&l.jsx("small",{className:"nc-set-hint","data-testid":"vl-events-empty",children:f("vl-events-empty")}),s.length>0&&l.jsx("ol",{className:"nc-vl-events-list",children:s.map(m=>l.jsx("li",{"data-testid":`vl-ev-${m.seq}`,className:`nc-vl-ev nc-vl-ev-${m.kind}${m.isError?" error":""}${m.kind==="gap"?" gap":""}`,children:gP(m)},`${m.seq}-${m.kind}`))})]})}function jy({peer:e,token:t,onBack:n}){var s;return Vn(),e?l.jsxs("section",{className:"nc-vl-session-view",children:[l.jsxs("header",{className:"nc-bar nc-bar-single",children:[l.jsxs("button",{onClick:n,title:f("back"),children:[l.jsx(ut,{name:"chevronLeft",size:18}),l.jsx("span",{className:"nc-bar-label",children:f("back")})]}),l.jsxs("span",{className:"nc-bar-center",children:[l.jsx("b",{title:e.label,children:e.label}),((s=e.session)==null?void 0:s.profile)&&l.jsxs("small",{className:"nc-bar-sub",children:[e.session.profile," · ",f("vl-events-title")]})]}),l.jsx("span",{className:"nc-bar-right"})]}),l.jsx("div",{className:"nc-vl-session-body",children:l.jsx(vP,{token:t,nodeId:e.nodeId,route:e.route||[]})})]}):null}const dh=e=>Xi(xr(e)).length===0,hh=e=>Array.isArray(e)?e.join("/"):"";function _P(e){const t=new Set,n=[];for(const s of Array.isArray(e)?e:[])!s||!mi.test(String(s.instanceId||""))||!Array.isArray(s.route)||!s.route.length||t.has(s.instanceId)||(t.add(s.instanceId),n.push({instanceId:s.instanceId,route:[...s.route],label:String(s.label||s.name||s.route.join(" › ")),status:s.status||"offline"}));return n.sort((s,o)=>s.label.localeCompare(o.label))}function da(e){return{instanceId:e.ownerId,route:e.ownerRoute||[],label:e.ownerLabel,status:e.available===!1?"offline":"up"}}function vr(e,t,n,s=!1,o=!0){const a=t.instanceId;return{...e,id:po(s?null:a,e.name),ownerId:a,ownerRoute:s?[]:[...t.route],ownerLabel:s?"Local":t.label,local:s,available:o,ownerTopology:Array.isArray(n)?n:[],layout:mf(e.layout,a,n)}}function yP(e,t,n,s,o=[]){const[a,u]=x.useState([]),[d,p]=x.useState(!1),[m,v]=x.useState("idle"),[y,b]=x.useState(""),[S,k]=x.useState(""),E=x.useRef([]),w=x.useRef([]),N=x.useRef(""),C=x.useRef(t),M=x.useRef(n),I=x.useRef(!1),G=x.useRef(!0),W=x.useRef(""),V=x.useMemo(()=>_P(o),[o]),K=V.map(A=>`${A.instanceId}:${hh(A.route)}:${A.status}:${A.label}`).join("|");w.current=V,M.current=n,C.current=t,E.current=a;const Y=x.useCallback(A=>gf(A.layout,N.current,w.current),[]),Z=x.useCallback((A,D=!0,O=C.current)=>{const H=M_(A,Yl()),ie=E.current.some(ue=>ue.id===O);E.current=H,u(H);const ee=H.find(ue=>ue.id===O);if(D&&ee){G.current=!0;const ue=Y(ee);s(ue),ee.local&&D2(ee.name,ue)}else ie&&!ee&&(G.current=!0,s(fo()),b("deck non più condiviso dal nodo owner"));L2(H.filter(ue=>ue.local).map(ue=>ue.name))},[s,Y]),U=x.useCallback(async A=>{let D=await zl(e);const O=D.decks.find(H=>H.name==="main");if(D.decks.length===1&&O&&O.revision===0&&dh(O.layout)){const H=P2(),ie=xr(vf("main")||fo());if(!dh(ie)){const ee=mf(ie,A,[]);D.decks[0]=await $l(e,"main",ee,0,[])}for(const ee of H.filter(ue=>ue!=="main"))try{let ue=await ev(e,ee,[]);const ve=xr(vf(ee)||fo());dh(ve)||(ue=await $l(e,ee,mf(ve,A,[]),ue.revision,[]))}catch{}D=await zl(e)}return D},[e]),$=x.useCallback(async({migrate:A=!1}={})=>{const D=await Lf(e,[]),O=mi.test(String(D.instanceId||""))?D.instanceId:"";if(!O)throw new Error("instanceId locale non disponibile");N.current=O,k(O);const[H,ie]=await Promise.all([A?U(O):zl(e),Xg(e,[]).catch(()=>({nodes:[]}))]),ee={instanceId:O,route:[],label:"Local"},ue=H.decks.map(fe=>vr(fe,ee,ie.nodes,!0,!0)),ve=E.current;return await Promise.all(w.current.map(async fe=>{if(fe.status!=="up"){ue.push(...ve.filter(pe=>!pe.local&&pe.ownerId===fe.instanceId).map(pe=>({...pe,ownerRoute:[...fe.route],ownerLabel:fe.label,available:!1})));return}try{const[pe,Ye]=await Promise.all([zl(e,fe.route),Xg(e,fe.route).catch(()=>({nodes:[]}))]);ue.push(...pe.decks.map(ht=>vr(ht,fe,Ye.nodes,!1,!0)))}catch{ue.push(...ve.filter(Ye=>!Ye.local&&Ye.ownerId===fe.instanceId).map(Ye=>({...Ye,ownerRoute:[...fe.route],ownerLabel:fe.label,available:!1})))}})),ue.sort((fe,pe)=>fe.local===pe.local?fe.ownerLabel.localeCompare(pe.ownerLabel)||(fe.name==="main"?-1:pe.name==="main"?1:fe.name.localeCompare(pe.name)):fe.local?-1:1),ue},[e,U,K]);x.useEffect(()=>{if(!e)return;let A=!1;const D=W.current!==e;return W.current=e,$({migrate:D}).then(O=>{if(A)return;const H=E.current.find(ue=>ue.id===C.current),ie=O.find(ue=>ue.id===C.current),ee=ie&&(!H||ie.revision>H.revision||H.available!==ie.available||hh(H.ownerRoute)!==hh(ie.ownerRoute));Z(O,D||!!ee&&!I.current),p(!0),ie&&b("")}).catch(O=>{A||(p(!0),b(String(O.message||O)))}),()=>{A=!0}},[Z,$,K,e]);const R=x.useCallback(async(A=C.current)=>{if(!d||!I.current)return!0;const D=E.current.find(O=>O.id===A);if(!D)return b(`deck inesistente: ${A}`),!1;if(D.available===!1)return b(`nodo owner offline: ${D.ownerLabel}`),!1;v("saving");try{const O=L_(xr(M.current),D.ownerId,D.ownerTopology),H=await $l(e,D.name,O,D.revision,D.ownerRoute),ie=vr(H,da(D),D.ownerTopology,D.local,!0);return Z(E.current.map(ee=>ee.id===A?ie:ee),!1),I.current=!1,v("saved"),b(""),setTimeout(()=>v("idle"),1500),!0}catch(O){if(v("error"),b(String(O.message||O)),O.status===409&&O.data&&O.data.current){const H=E.current.find(ee=>ee.id===A),ie=vr(O.data.current,da(H),H.ownerTopology,H.local,!0);Z(E.current.map(ee=>ee.id===A?ie:ee),!1)}return!1}},[d,e,Z]);return x.useEffect(()=>{if(!d)return;if(G.current){G.current=!1;return}I.current=!0,v("saving");const A=setTimeout(R,650);return()=>clearTimeout(A)},[n,d,R]),x.useEffect(()=>{if(!d)return;const A=setInterval(async()=>{try{const D=await $(),O=E.current.find(ee=>ee.id===C.current),H=D.find(ee=>ee.id===C.current),ie=H&&(!O||H.revision>O.revision||O.available!==H.available);Z(D,ie&&!I.current)}catch{}},5e3);return()=>clearInterval(A)},[d,$,Z]),{decks:a,records:a,localNodeId:S,ready:d,saveState:m,error:y,setError:b,saveNow:R,select:async A=>{if(I.current&&!await R(C.current))throw new Error("salvataggio del deck corrente fallito: cambio annullato");const D=E.current.find(O=>O.id===A);if(!D)throw new Error(`deck inesistente: ${A}`);return I.current=!1,G.current=!0,Y(D)},add:async(A,D=null)=>{const O=D===Yi?E.current.find(ee=>ee.local):D?E.current.find(ee=>ee.ownerId===D):null;if(!O||O.available===!1)throw new Error("nodo owner non disponibile");const H=await ev(e,A,O.ownerRoute),ie=vr(H,da(O),O.ownerTopology,O.local,!0);return Z([...E.current,ie],!1),ie},rename:async(A,D)=>{const O=E.current.find(ve=>ve.id===A);if(!O)throw new Error("deck inesistente");if(A===C.current&&I.current&&!await R(A))throw new Error(`salvataggio di "${O.name}" fallito: rinomina annullata`);const H=E.current.find(ve=>ve.id===A);if(!H)throw new Error("deck inesistente");const ie=await Wx(e,H.name,D,H.revision,H.ownerRoute),ee=vr(ie,da(H),H.ownerTopology,H.local,!0),ue=H.local?Yi:H.ownerId;return Bd(M2(Yl(),ue,A,ee.id)),Z(E.current.map(ve=>ve.id===A?ee:ve),!1),ee},remove:async A=>{const D=E.current.find(H=>H.id===A);if(!D)throw new Error("deck inesistente");A===C.current&&(I.current=!1),await Kx(e,D.name,D.revision,D.ownerRoute);const O=D.local?Yi:D.ownerId;Bd(T2(Yl(),O,A)),Z(E.current.filter(H=>H.id!==A),!1)},reorder:(A,D)=>{const O=E.current.find(fe=>fe.id===A),H=E.current.find(fe=>fe.id===D);if(!O||!H)return!1;const ie=O.local?Yi:O.ownerId,ee=H.local?Yi:H.ownerId;if(ie!==ee)return!1;const ue=E.current.filter(fe=>(fe.local?Yi:fe.ownerId)===ie).map(fe=>fe.id),ve=Bd(A2(Yl(),ie,A,D,ue));return Z(M_(E.current,ve),!1),!0},addTileTo:async(A,D)=>{const O=E.current.find(fe=>fe.id===A);if(!O)throw new Error("deck inesistente");if(O.available===!1)throw new Error(`nodo owner offline: ${O.ownerLabel}`);const H=jw(D,N.current,w.current);if(!H)throw new Error("riferimento sessione non valido");const ie=Y(O),ee=L_(fb(ie,H),O.ownerId,O.ownerTopology),ue=await $l(e,O.name,ee,O.revision,O.ownerRoute),ve=vr(ue,da(O),O.ownerTopology,O.local,!0);return Z(E.current.map(fe=>fe.id===A?ve:fe),!1),ve},localMainId:po(null,"main"),parseDeckId:Lc}}const bP="/sw.js",wf="nc-sw-update";let Sf=null,xf=!1,kf=null,dS=Object.freeze({needed:!1,kind:null,version:""}),hS=!1;function fS(){typeof window<"u"&&window.dispatchEvent(new Event(wf))}function pS(){const e=kf||(xf?{kind:"reload",version:""}:null);dS=Object.freeze({needed:!!e,kind:(e==null?void 0:e.kind)||null,version:(e==null?void 0:e.version)||""})}function Ry(){return dS}function wP(e){return typeof window>"u"?()=>{}:(window.addEventListener(wf,e),()=>window.removeEventListener(wf,e))}function xp(e){xf!==e&&(xf=e,pS(),fS())}const fh="nc-auto-reload";function SP(){try{return typeof sessionStorage<"u"?sessionStorage:null}catch{return null}}function xP(e,t,n,s={}){let o=null;e&&t&&e!==t?o={kind:"install",version:e}:t&&n&&t!==n&&(o={kind:"reload",version:t});const a=JSON.stringify(o)===JSON.stringify(kf);kf=o,pS(),a||fS();const u=s.storage===void 0?SP():s.storage;if(!o){try{u&&u.removeItem(fh)}catch{}return}if(o.kind!=="reload"||!u)return;const d=`${t}|${n}`;try{if(u.getItem(fh)===d)return;u.setItem(fh,d)}catch{return}(s.applyImpl||mS)()}function kP(e){e.addEventListener("statechange",()=>{e.state==="installed"&&navigator.serviceWorker.controller&&xp(!0)})}function CP(){typeof navigator>"u"||!("serviceWorker"in navigator)||(navigator.serviceWorker.addEventListener("controllerchange",()=>{hS&&location.reload()}),navigator.serviceWorker.register(bP).then(e=>{Sf=e,e.waiting&&xp(!0),e.addEventListener("updatefound",()=>{const t=e.installing;t&&kP(t)}),setInterval(()=>{e.update().catch(()=>{})},3600*1e3)}).catch(()=>{}))}function mS(){hS=!0,xp(!1);const e=Sf&&Sf.waiting;e?(e.postMessage({type:"SKIP_WAITING"}),setTimeout(()=>location.reload(),4e3)):location.reload()}function EP({hash:e="",origin:t="",pathname:n="",search:s=""}={}){const o=String(e||"").replace(/^#/,""),a=`${n||""}${s||""}`;if(!o)return{token:"",pair:"",nextUrl:a};const u=new URLSearchParams(o),d=u.get("token")||"",p=u.get("pair")||"",m=p?`${t||""}${n||""}#pair=${p}`:"";return{token:d,pair:m,nextUrl:a}}const gS=9,vS=24,_S="nc_side_w",Py="nc_side_min",NP=240;function jP(){const e=Number(localStorage.getItem(_S));return e>=180&&e<=480?e:NP}function RP(){const e=Number(localStorage.getItem("nc_fontsize"));return e>=gS&&e<=vS?e:13}function PP(){const e={token:"",pair:""};try{const{token:t,pair:n,nextUrl:s}=EP({hash:location.hash,origin:location.origin,pathname:location.pathname,search:location.search});if(t){e.token=t;try{localStorage.setItem("nc_token",t)}catch{}}if(n){e.pair=n;try{sessionStorage.setItem("nc_pair",n)}catch{}}if(location.hash)try{history.replaceState(null,"",s)}catch{}}catch{}if(e.token||(e.token=sessionStorage.getItem("nc_token")||localStorage.getItem("nc_token")||""),!e.pair){const t=sessionStorage.getItem("nc_pair");t&&(e.pair=t)}return e}function LP(e){try{return xr(vf(e))}catch{return fo()}}function Ly(e){if(!e)return"";const t=Math.floor(Date.now()/1e3)-e;return t<0||t<60?"ora":t<3600?`${Math.floor(t/60)}m`:t<86400?`${Math.floor(t/3600)}h`:`${Math.floor(t/86400)}g`}function Ay({session:e,node:t,ownerId:n,cellName:s,token:o,readonly:a=!1,panelPort:u=0,onBack:d,onCellSwitcher:p,cellSwitcherOpen:m=!1}){Vn();const[v]=rp(),[y,b]=x.useState(!1),[S,k]=x.useState(()=>window.matchMedia("(pointer: coarse)").matches),[E,w]=x.useState(null),[N,C]=x.useState(RP),[M,I]=x.useState(s||e),[G,W]=x.useState(""),[V,K]=x.useState(""),[Y,Z]=x.useState(""),[U,$]=x.useState(!1),R=H=>C(ie=>{const ee=Math.max(gS,Math.min(vS,ie+H));return localStorage.setItem("nc_fontsize",String(ee)),ee}),z=x.useRef(()=>{}),F=x.useRef(()=>!1),L=x.useRef(()=>{}),T=x.useRef(!1),[j,B]=x.useState(!1),[A,D]=x.useState(!1),O=()=>{T.current=!T.current,B(T.current)};return x.useEffect(()=>{I(s||e),$(!1)},[s,e]),x.useEffect(()=>{let H=!0;const ie=t?t.split("/"):[],ee=t?`/api/route/${t.split("/").map(encodeURIComponent).join("/")}/_`:"/api";async function ue(){let fe=null,pe=null;try{const yt=await(await an(`${ee}/sessions`,o)).json();Array.isArray(yt.sessions)&&(fe=yt.sessions.find(Ne=>Ne.name===e))}catch{}try{const ht=await Gs(o,ie);ht.available&&Array.isArray(ht.cells)&&(pe=ht.cells.find(yt=>yt.tmuxSession===e))}catch{}if(!H)return;I(op({session:e,cell:pe||(s?{cell:s}:null)})),K(typeof(pe==null?void 0:pe.panelUrl)=="string"?pe.panelUrl.trim():""),Z(typeof(pe==null?void 0:pe.cell)=="string"?pe.cell:"");let Ye="";pe?Ye=`${pe.engine}${pe.key?`·${pe.key}`:""}`:fe&&(Ye=fe.attached?`attached · ${Ly(fe.activity)}`:fe.activity?Ly(fe.activity):""),W(Ye)}ue();const ve=setInterval(ue,4e3);return()=>{H=!1,clearInterval(ve)}},[e,t,o]),l.jsxs("div",{className:"nc-app",children:[l.jsxs("header",{className:"nc-bar nc-bar-single",children:[l.jsxs("button",{onClick:d,title:f("sessions"),children:[l.jsx(ut,{name:"chevronLeft",size:18}),l.jsx("span",{className:"nc-bar-label",children:f("sessions")})]}),l.jsxs("span",{className:"nc-bar-center",children:[l.jsx("b",{title:t?`${M} · ${t}`:M,children:M}),G&&l.jsx("small",{className:"nc-bar-sub",children:G})]}),l.jsxs("span",{className:"nc-bar-right",children:[l.jsx("button",{onClick:()=>R(-1),title:f("zoom-out"),children:l.jsx(ut,{name:"zoomOut",size:18})}),l.jsx("button",{onClick:()=>R(1),title:f("zoom-in"),children:l.jsx(ut,{name:"zoomIn",size:18})}),l.jsx("button",{onClick:()=>k(H=>!H),title:f("composer"),children:l.jsx(ut,{name:"keyboard",size:20})}),l.jsx("button",{onClick:()=>b(H=>!H),title:f("files"),children:l.jsx(ut,{name:"folder",size:20})}),V&&l.jsx("button",{onClick:()=>$(H=>!H),title:f("panel"),"aria-pressed":U,children:l.jsx(ut,{name:"monitor",size:20})})]})]}),l.jsxs("div",{className:"nc-termwrap",children:[l.jsx(Zf,{session:e,node:t,token:o,readonly:a,takeSize:!0,sendRef:z,composerRef:F,actionRef:L,ctrlRef:T,setCtrlArmed:B,onFiles:w,fontSize:N,selectionMode:A,onSelectionModeChange:D,keyboardGesture:v.terminalKeyboardGesture}),U&&V&&Y&&l.jsx(np,{cellId:Y,panelUrl:V,route:t?t.split("/"):[],panelPort:u,token:o,title:M})]}),l.jsx(VN,{onKeyboard:()=>k(H=>!H),onCellSwitcher:p,cellSwitcherOpen:m,send:H=>z.current(H),action:H=>L.current(H),ctrlArmed:j,onCtrl:O,selectionMode:A,onSelectionMode:D,keepKeyboardClosed:v.keybarKeepsKeyboardClosed,showEnter:v.showKeybarEnter,keybarLayout:v.keybarLayout}),S&&l.jsx(yw,{submitText:H=>F.current(H),token:o,session:e,node:t,ownerId:n,readonly:a,keepKeyboardClosedOnVoice:v.voiceKeepsKeyboardClosed}),y&&l.jsx(uw,{session:e,node:t,token:o,filesEvent:E,onClose:()=>b(!1)})]})}function AP(){Vn();const[e]=x.useState(PP),[t,n]=x.useState(e.token),[s,o]=x.useState(e.pair||""),a=x.useCallback(()=>{o("");try{sessionStorage.removeItem("nc_pair")}catch{}},[]),[u,d]=x.useState(!1),p=CN(),[m]=x.useState(()=>R2(typeof location<"u"?location.pathname:"/")),[v,y]=x.useState(m.id),b=v===po(null,gi),[S,k]=x.useState(null),E=de=>{const Ce=Ys(de);k(Ce?{...Ce,...typeof(de==null?void 0:de.cellName)=="string"&&de.cellName?{cellName:de.cellName}:{}}:null)},[w,N]=x.useState([]),[C,M]=x.useState([]),[I,G]=x.useState([]),[W,V]=x.useState(!1),[K,Y]=x.useState(null),[Z,U]=x.useState(()=>m.ownerId?fo():LP(m.name)),[$,R]=x.useState(null),[z,F]=x.useState(null),L=de=>F(Ys(de)),[T,j]=x.useState(null),B=Tf(t,p),A=x.useMemo(()=>(B||[]).filter(de=>de.instanceId).map(de=>({instanceId:de.instanceId,route:de.route,label:de.label,status:de.status})),[B]),D=yP(t,v,Z,U,A),O=D.decks;x.useEffect(()=>{const de=new Map;for(const Ce of B||[]){const Oe=(Ce.route||[Ce.name]).join("/"),nt=new Set((Ce.sessions||[]).map(it=>it.name));for(const it of Ce.cells||[])!it.cell||!it.tmuxSession||it.cell===it.tmuxSession||nt.has(it.cell)||de.set(`${Oe}:${it.cell}`,`${Oe}:${it.tmuxSession}`)}U(Ce=>jk(Ce,de))},[B]),x.useEffect(()=>{D.localNodeId&&U(de=>{const Ce=gf(de,D.localNodeId,A);return JSON.stringify(Ce)===JSON.stringify(de)?de:Ce})},[A,D.localNodeId]);const[H,ie]=x.useState(null),[ee,ue]=x.useState(null),ve=x.useRef(0),[fe,pe]=x.useState(!1),[Ye,ht]=x.useState(jP),[yt,Ne]=x.useState(!b),[Ct,hn]=x.useState(()=>b?localStorage.getItem(Py)==="1":!0),[vn,Gt]=x.useState(!1),[kt,Bt]=x.useState("nodes"),[Ut,Nt]=x.useState(!1),[Dt,Mt]=x.useState(""),[jt,fn]=x.useState(!1),se=(de="nodes",Ce=!1,Oe="")=>{Bt(de),Nt(Ce),Mt(Oe),Gt(!0)},[Qe,me]=x.useState(!1),[Xe,dt]=x.useState({deviceDefault:"",localNodeId:"",localNameDefault:""}),[re,ne]=x.useState(!1),[_e,ye]=x.useState(0),[xe,st]=x.useState({});x.useEffect(()=>{try{localStorage.setItem(_S,String(Ye))}catch{}},[Ye]),x.useEffect(()=>{try{localStorage.setItem(Py,Ct?"1":"")}catch{}},[Ct]),x.useEffect(()=>{if(!t)return;let de=!1;return Promise.all([Fy(t),an("/api/config",t).then(Ce=>Ce.json())]).then(([Ce,Oe])=>{de||(dt({deviceDefault:Ce.deviceName||"",localNodeId:Ce.nodeId||"",localNameDefault:Ce.localName||""}),ne(!!Oe.readonlyDefault),ye(Number.isInteger(Oe.panelPort)?Oe.panelPort:0),st(Oe.nodePanelPorts&&typeof Oe.nodePanelPorts=="object"&&!Array.isArray(Oe.nodePanelPorts)?Oe.nodePanelPorts:{}),(Ce.firstRun===!0&&!Oe.readonlyDefault||s)&&me(!0))}).catch(()=>{}),()=>{de=!0}},[t,s]);const[pt,ft]=x.useState({}),Rt=x.useRef(B);x.useEffect(()=>{Rt.current=B},[B]);const St=x.useCallback(async()=>{try{const it=await(await an("/api/sessions",t)).json();it.error||N(it.sessions||[])}catch{}let de=null,Ce=null;try{de=await Gs(t)}catch(nt){Ce=nt}const Oe=gb({fs:de,error:Ce});Oe.kind==="data"?(M(Oe.cells),G(Oe.capabilities),V(!1),Y(null)):Oe.kind==="stale"?(V(!0),Y(null)):(M([]),G([]),V(!1),Y(Oe.reason||""))},[t]);x.useEffect(()=>{let de=!1;const Ce=async()=>{const nt=[[],...(Rt.current||[]).filter(Pt=>Pt.kind!=="vl"&&Pt.status==="up").map(Pt=>Array.isArray(Pt.route)&&Pt.route.length?Pt.route:[Pt.name])],it=await Promise.all(nt.map(async Pt=>{try{const Ot=await qx(t,Pt);return[ya(Pt),{hostCell:Ot&&typeof Ot.hostCell=="string"?Ot.hostCell:null,hostLease:Ot&&Ot.host&&typeof Ot.host.lease=="string"?Ot.host.lease:null,hostRevision:Number.isInteger(Ot&&Ot.revision)?Ot.revision:0}]}catch{return null}}));de||ft(Pt=>{let Ot=!1;const Wt={...Pt};for(const si of it)si&&(Wt[si[0]]=si[1],Ot=!0);return Ot?Wt:Pt})};Ce();const Oe=setInterval(Ce,4e3);return()=>{de=!0,clearInterval(Oe)}},[t]),x.useEffect(()=>{if(!p)return;St();const de=setInterval(St,4e3);return()=>clearInterval(de)},[p,St]);const bt=x.useCallback(async(de,Ce=[])=>{const Oe=ya(Ce),nt=pt[Oe]&&pt[Oe].hostRevision||0;try{const it=await Vx(t,de,nt,Ce);ft(Pt=>({...Pt,[Oe]:{hostCell:it.hostCell||null,hostLease:it.host&&typeof it.host.lease=="string"?it.host.lease:null,hostRevision:Number.isInteger(it.revision)?it.revision:nt}}))}catch(it){window.alert(f(pv(it)))}},[t,pt]),$t=x.useCallback(async(de=[])=>{const Ce=ya(de),Oe=pt[Ce]&&pt[Ce].hostRevision||0;try{const nt=await Yx(t,Oe,de);return ft(it=>({...it,[Ce]:{hostCell:nt.hostCell||null,hostLease:null,hostRevision:Number.isInteger(nt.revision)?nt.revision:Oe}})),!0}catch(nt){return window.alert(f(pv(nt))),!1}},[t,pt]);x.useEffect(()=>{let de=!1;const Ce=()=>{an("/api/config",t).then(nt=>nt.json()).then(nt=>{de||xP(nt.version,nt.uiVersion,"0.9.10")}).catch(()=>{})};Ce();const Oe=setInterval(Ce,6e4);return()=>{de=!0,clearInterval(Oe)}},[t]);const Ze=new Set([...w.map(de=>de.name),...B.flatMap(de=>de.sessions.map(Ce=>Ce.key))]),J=Xi(Z),Ee=de=>U(Ce=>{const Oe=jw(de,D.localNodeId,A)||de,nt=fb(Ce,Oe);return nt===Ce&&Xi(Ce).length>=9&&D.setError(f("grid-full")),nt}),We=async(de,Ce=[])=>{try{await jf(t,de,Ce)}catch{return}const Oe=Ce.length?`${Ce.join("/")}:${de}`:de;U(nt=>fc(nt,Oe)),St()},ze=async(de,Ce,Oe=[])=>{try{await $y(t,de,Ce,Oe)}catch{return}St()},Te=async(de,Ce,Oe=[])=>{await Oy(t,{cell:de,enabled:!!Ce},Oe),St()},ct=async de=>{if(!H)return;const{cell:Ce}=H,Oe=Array.isArray(H.route)?H.route:[];if(de.action==="up"){const it=await Nf(t,{cell:Ce,boot:!!de.boot,...de.engine?{engine:de.engine}:{},...de.model!==void 0?{model:de.model}:{},...de.permissionPolicy?{permissionPolicy:de.permissionPolicy}:{}},Oe),Pt=Hf(it);Pt&&D.setError(Pt.text)}else await ac(t,{cell:Ce,boot:!!de.boot},Oe);const nt=de.action==="up"?!!de.boot:de.boot?!1:!!H.boot;ue({id:++ve.current,cell:Ce,route:Oe,enabled:nt}),St()},Et=x.useCallback(de=>{ue(Ce=>(Ce==null?void 0:Ce.id)===de?null:Ce)},[]),X=async de=>{if(!(!(de!=null&&de.direct)||fe)){pe(!0);try{await Af(t,de.name,de.tunnelStatus==="up"?"down":"up")}finally{pe(!1)}}},oe=async(de,Ce)=>{const Oe=String(Ce||"").trim();return!(de!=null&&de.direct)||!_o(Oe)?!1:(await Wy(t,de.name,Oe),!0)},we=de=>{const Ce=O.find(Oe=>Oe.id===de);if(!Ce)return!1;try{const Oe=window.open(Od(Ce,t),"_blank");return Oe&&(Oe.opener=null),!!Oe}catch{return!1}},De=async de=>{if(!de||de===v)return;const Ce=await D.select(de),Oe=D.records.find(nt=>nt.id===de);y(de),U(Ce),R(null),F(null);try{history.replaceState(null,"",Od(Oe||de,null))}catch{}},je=async(de,Ce)=>{const Oe=await D.add(de,Ce);await De(Oe.id)},Me=async(de,Ce)=>{const Oe=await D.rename(de,Ce);if(de===v){y(Oe.id),U(gf(Oe.layout,D.localNodeId,A)),R(null),F(null);try{history.replaceState(null,"",Od(Oe,null))}catch{}}},Je=async de=>{await D.remove(de),de===v&&await De(D.localMainId)},Pe=async(de,Ce)=>{!Ce||Ce===v||(await D.addTileTo(Ce,de),U(Oe=>fc(Oe,de)))};if(!t)return l.jsxs("div",{className:"nc-auth",children:[l.jsx("p",{children:f("auth-prompt")}),l.jsx("input",{onChange:de=>n(de.target.value.trim()),placeholder:"token"}),l.jsxs("label",{children:[l.jsx("input",{type:"checkbox",checked:u,onChange:de=>d(de.target.checked)})," ",f("remember-device")]}),l.jsx("button",{onClick:()=>{(u?localStorage:sessionStorage).setItem("nc_token",t)},children:"ok"})]});const Ie=l.jsxs(l.Fragment,{children:[vn&&l.jsx(tP,{token:t,initialTab:kt,initialLocation:Dt,startNewCell:Ut,onClose:()=>{Gt(!1),Nt(!1),Mt("")}}),Qe&&l.jsx(nP,{token:t,initialPair:s,...Xe,onPairDone:a,onDone:()=>me(!1)}),l.jsx(lP,{token:t})]});if(!p)return T?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-single-overlay",children:l.jsx(jy,{peer:T,token:t,onBack:()=>j(null)})}),Ie]}):S?l.jsxs(l.Fragment,{children:[l.jsx(Ay,{session:S.session,node:S.node,ownerId:S.ownerId,cellName:S.cellName,token:t,readonly:re,panelPort:Sc(S.node?S.node.split("/"):[],xe,_e),onBack:()=>k(null),onCellSwitcher:()=>fn(!0),cellSwitcherOpen:jt}),jt&&l.jsx(pP,{token:t,current:S,panelPort:_e,nodePanelPorts:xe,onPick:de=>{E(de),fn(!1)},onClose:()=>fn(!1)}),Ie]}):l.jsxs(l.Fragment,{children:[l.jsx(Vk,{onPick:E,token:t,onSettings:se,onOpenVlSession:j,hostByRoute:pt,onDesignateCell:bt,onClearHostCell:$t}),Ie]});const xt=b||!yt;return l.jsxs("div",{className:"nc-workspace",children:[xt&&l.jsx(_2,{sessions:w,cells:C,activeSessions:J,nodeGroups:B,token:t,onPeekOpen:()=>fn(!1),overlayOpen:jt,fleetCapabilities:I,fleetStale:W,fleetOff:K,bootSettlement:ee,onBootSettlementApplied:Et,localNodeId:D.localNodeId,hostByRoute:pt,onDesignateCell:bt,onClearHostCell:$t,onPick:L,onAddTile:Ee,onPower:ie,onBoot:Te,onBootError:de=>D.setError(String((de==null?void 0:de.message)||de)),onNodePower:X,onNodeRename:oe,onKill:We,onVisibility:ze,onNew:()=>se("fleet",!0),onSettings:se,onOpenVlSession:j,width:Ye,collapsed:Ct,onResize:ht,onToggleCollapse:()=>hn(de=>!de)}),l.jsxs("div",{className:"nc-workspace-main",children:[l.jsx(J2,{decks:O,currentDeck:v,onCreate:je,onRename:Me,onDelete:Je,onReorder:D.reorder,onOpenWindow:we,onNavigate:De,saveState:D.saveState,error:D.error,sidebarVisible:xt,onToggleSidebar:b?null:()=>Ne(de=>!de)}),l.jsx(k2,{layout:Z,onLayoutChange:U,token:t,readonly:re,sessionsAlive:Ze,focusSession:$,onFocus:R,onOpenSingle:L,decks:O,currentDeck:v,onSendToDeck:Pe,cells:C,nodeGroups:B,panelPort:_e,nodePanelPorts:xe})]}),T&&l.jsx("div",{className:"nc-single-overlay",children:l.jsx(jy,{peer:T,token:t,onBack:()=>j(null)})}),z&&l.jsx("div",{className:"nc-single-overlay",children:l.jsx(Ay,{session:z.session,node:z.node,ownerId:z.ownerId,cellName:op({session:z.session,node:z.node,ownerId:z.ownerId,cells:C,nodeGroups:B}),token:t,readonly:re,panelPort:Sc(z.node?z.node.split("/"):[],xe,_e),onBack:()=>F(null)})}),H&&l.jsx(cc,{cell:H,token:t,route:Array.isArray(H.route)?H.route:[],onConfirm:ct,onClose:()=>ie(null)}),Ie]})}function MP(){Vn();const e=x.useSyncExternalStore(wP,Ry,Ry);if(!e.needed)return null;const t=e.kind==="install"?f("install-version-mismatch").replace("{v}",e.version):f("update-available").replace("{v}",e.version).replace(" "," ").trim();return l.jsxs("div",{className:"nc-update",role:"status","aria-live":"polite",children:[l.jsx("span",{className:"nc-update-msg",children:t}),e.kind==="reload"&&l.jsx("button",{className:"nc-update-btn",onClick:mS,children:f("reload")})]})}CP();ix.createRoot(document.getElementById("root")).render(l.jsxs(X0.StrictMode,{children:[l.jsx(AP,{}),l.jsx(MP,{})]}));
93
+ `],{type:"application/json"}),L=URL.createObjectURL(F),T=document.createElement("a");T.href=L,T.download="nexuscrew-diagnostics.json",T.click(),URL.revokeObjectURL(L)}catch{b(f("diagnostics-export-failed"))}};return l.jsxs("div",{className:"nc-set-tab nc-diagnostics",children:[l.jsxs("label",{className:"nc-field",children:[f("diagnostics-target"),l.jsx("select",{value:u.key,onChange:F=>a(F.target.value),children:s.map(F=>l.jsxs("option",{value:F.key,children:[F.label,F.status!=="up"?` · ${F.status}`:""]},F.key))})]}),l.jsxs("div",{className:"nc-set-form nc-diag-controls",children:[l.jsx("div",{className:"nc-sheet-label",children:f("diagnostics-verbose")}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("select",{"aria-label":f("diagnostics-duration"),value:N,onChange:F=>C(Number(F.target.value)),disabled:n,children:[300,900,1800,3600].map(F=>l.jsxs("option",{value:F,children:[F/60," min"]},F))}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||(d==null?void 0:d.verbose)===!0,onClick:()=>$(()=>Zg(e,!0,N,u.route)),children:f("enable")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||(d==null?void 0:d.verbose)!==!0,onClick:()=>$(()=>Zg(e,!1,N,u.route)),children:f("stop")})]}),l.jsx("small",{className:"nc-set-hint",children:d!=null&&d.verbose?f("diagnostics-expires").replace("{time}",new Date(d.expiresAt).toLocaleTimeString()):f("diagnostics-off")})]}),l.jsxs("div",{className:"nc-diag-filters",children:[l.jsxs("select",{"aria-label":f("diagnostics-level"),value:M,onChange:F=>I(F.target.value),children:[l.jsx("option",{value:"all",children:f("diagnostics-all-levels")}),["debug","info","warn","error"].map(F=>l.jsx("option",{value:F,children:F},F))]}),l.jsx("input",{"aria-label":f("diagnostics-component"),placeholder:f("diagnostics-component"),value:G,onChange:F=>W(F.target.value)})]}),l.jsxs("div",{className:"nc-set-row",children:[l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:S,onChange:F=>k(F.target.checked)})," ",f("diagnostics-pause")]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:E,onChange:F=>w(F.target.checked)})," ",f("diagnostics-autoscroll")]})]}),l.jsx("pre",{ref:K,className:"nc-diag-log","aria-label":f("diagnostics-log"),children:U||f("diagnostics-empty")}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:R,children:f("copy")}),l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:z,children:f("diagnostics-export")}),l.jsx("button",{type:"button",className:"nc-btn danger",disabled:n,onClick:()=>{window.confirm(f("diagnostics-clear-confirm"))&&$(async()=>{const F=await $x(e,u.route);return V.current=0,v([]),F})},children:f("diagnostics-clear")})]}),y&&l.jsx("div",{className:"nc-err",children:y})]})}function eP({token:e,settings:t,readonly:n,refresh:s,roster:o,section:a,setSection:u}){const[d,p]=x.useState(null),[m,v]=x.useState(null),[y,b]=x.useState(!1),[S,k]=x.useState(!1),[E,w]=x.useState(null),[N,C]=x.useState(!0),[M,I]=x.useState(!1);x.useEffect(()=>{w(t&&t.update||null),C(!t||t.autoUpdate!==!1),I(!!(t&&t.alternateScreen))},[t]);const G=async()=>{p(null),v(null),k(!0);try{const R=await bx(e);v(R.note||"ok"),b(!1)}catch(R){p(String(R.message||R))}k(!1)},W=async()=>{p(null),v(null),k(!0);try{const R=await Dx(e);v(`${R.note||"ok"}${R.target?` (${R.target})`:""}`)}catch(R){p(String(R.message||R))}k(!1)},V=async R=>{p(null),v(null),k(!0);try{await ph(e,{autoUpdate:R}),C(R),s&&await s()}catch(z){p(String(z.message||z))}k(!1)},K=async R=>{p(null),v(null),k(!0);try{await ph(e,{alternateScreen:R}),I(R),s&&await s()}catch(z){p(String(z.message||z))}k(!1)},Y=async()=>{p(null),v(null),k(!0);try{w(await Ix(e))}catch(R){p(String(R.message||R))}k(!1)},Z=async()=>{p(null),v(null),k(!0);try{const R=await Ox(e);w(R),v(f("npm-update-restarting"))}catch(R){p(String(R.message||R))}k(!1)},U=()=>{window.confirm(f("composer-clear-confirm"))&&(p(null),s2()?(window.dispatchEvent(new Event(df)),v(f("composer-clear-done"))):p(f("composer-clear-failed")))},$=t&&t.service;return l.jsxs("div",{className:"nc-set-tab",children:[l.jsx("div",{className:"nc-system-tabs",role:"tablist","aria-label":f("tab-system"),children:["general","diagnostics"].map(R=>l.jsx("button",{type:"button",role:"tab","aria-selected":a===R,className:`nc-set-tabbtn${a===R?" on":""}`,onClick:()=>u(R),children:f(`system-${R}`)},R))}),a==="general"&&l.jsxs(l.Fragment,{children:[l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:f("system-this-node")}),t&&l.jsxs("div",{className:"nc-set-info",children:["v",t.version," · ",t.platform," · :",t.port,l.jsx("br",{}),$&&$.installed?f("service-installed"):f("service-missing"),$&&$.installed?` · ${$.active?f("service-active"):f("service-inactive")}`:"",$?` · boot ${$.boot?"on":"off"}`:""]}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||S,title:n?f("settings-readonly"):"",onClick:W,children:f("service-regenerate")})}),l.jsx(GR,{token:e,readonly:n}),l.jsx(XR,{})]}),l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:f("system-updates")}),l.jsxs("div",{className:"nc-set-form nc-update-settings",children:[l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:N,disabled:n||S||E&&!E.supported,onChange:R=>V(R.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:f("npm-auto-update")}),l.jsx("small",{children:f("npm-auto-update-help")})]})]}),E&&l.jsxs("div",{className:"nc-set-info",children:[f("npm-update-current")," v",E.current,E.latest?` · ${f("npm-update-latest")} v${E.latest}`:""," · ",f(E.supported?E.phase==="idle"&&E.checked!==!0?"npm-update-never":`npm-update-${E.phase}`:"unsupported")]}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||S||!E||!E.supported,onClick:Y,children:f("npm-update-check")}),E&&E.available&&l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||S||E.phase==="installing",onClick:Z,children:f("npm-update-install")})]}),E&&E.lastError&&l.jsx("div",{className:"nc-err",children:E.lastError})]})]}),l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:f("system-security")}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||S,title:n?f("settings-readonly"):"",onClick:()=>{p(null),v(null),b(!0)},children:f("token-rotate")})})]}),l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:f("system-local-data")}),l.jsxs("div",{className:"nc-set-form",children:[l.jsx("div",{className:"nc-sheet-label",children:f("composer-clear-data")}),l.jsx("small",{className:"nc-set-hint",children:f("composer-clear-data-help")}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:U,children:f("composer-clear-data")})})]})]})]}),a==="diagnostics"&&l.jsxs("section",{className:"nc-system-group nc-system-diagnostics",children:[l.jsx("h3",{children:f("system-diagnostics")}),l.jsxs("div",{className:"nc-set-form nc-alternate-screen-settings",children:[l.jsx("div",{className:"nc-sheet-label",children:f("system-terminal")}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox","aria-label":f("alternate-screen"),checked:M,disabled:n||S,onChange:R=>K(R.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:f("alternate-screen")}),l.jsx("small",{children:f("alternate-screen-help")})]})]})]}),l.jsx(ZR,{token:e,roster:o,readonly:n})]}),y&&l.jsxs("div",{className:"nc-set-confirm",children:[l.jsx("div",{children:f("token-rotate-explain")}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:S,onClick:()=>b(!1),children:f("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:S,onClick:G,children:f("confirm")})]})]}),m&&l.jsx("div",{className:"nc-set-note",children:m}),d&&l.jsx("div",{className:"nc-err",children:d})]})}function tP({token:e,onClose:t,initialTab:n="nodes",initialLocation:s="",startNewCell:o=!1}){Vn();const a=n==="diagnostics"?"diagnostics":"general",[u,d]=x.useState(n==="diagnostics"?"system":n),p=x.useRef(null),m=x.useRef(null),[v,y]=x.useState({start:!1,end:!1}),[b,S]=x.useState(a),[k,E]=x.useState(null),[w,N]=x.useState([]),[C,M]=x.useState([]),[I,G]=x.useState(!1),[W,V]=x.useState(null),[K,Y]=x.useState(0),Z=Tf(e,!0,K),U=x.useCallback(()=>{const R=p.current;if(!R)return;const z=R.scrollWidth>R.clientWidth+1,F={start:z&&R.scrollLeft>1,end:z&&R.scrollLeft+R.clientWidth<R.scrollWidth-1};y(L=>L.start===F.start&&L.end===F.end?L:F)},[]);x.useEffect(()=>{const R=p.current;if(!R)return;const z=typeof ResizeObserver=="function"?new ResizeObserver(U):null;return z==null||z.observe(R),window.addEventListener("resize",U),U(),()=>{z==null||z.disconnect(),window.removeEventListener("resize",U)}},[U]),x.useEffect(()=>{var z,F;(F=(z=m.current)==null?void 0:z.scrollIntoView)==null||F.call(z,{behavior:"smooth",block:"nearest",inline:"nearest"});const R=window.requestAnimationFrame?window.requestAnimationFrame(U):setTimeout(U,0);return()=>{window.cancelAnimationFrame?window.cancelAnimationFrame(R):clearTimeout(R)}},[u,U]);const $=x.useCallback(async()=>{var R;try{const z=await Fy(e);E(z),V(null)}catch(z){V(String(z.message||z))}try{const F=(await _x(e)).peers||[];let L=[],T=[];try{const[j,B]=await Promise.all([an("/api/config",e).then(H=>H.json()).catch(()=>null),Uy(e).catch(()=>null)]),A=j&&typeof j.instanceId=="string"?j.instanceId:"",D=[{instanceId:A||null,route:[],label:null},...Jy(B,A)],O=await Promise.all(D.map(async H=>{try{return{ok:!0,peers:((await Hy(e,H.route)).nodes||[]).map(ue=>Qy(ue,H)).filter(Boolean)}}catch(ie){return{ok:!1,owner:H,error:ie}}}));for(const H of O){if(H.ok){L.push(...H.peers);continue}H.owner.route.length!==0&&T.push({instanceId:H.owner.instanceId,label:H.owner.label,route:H.owner.route,failure:/timeout/i.test(String(((R=H.error)==null?void 0:R.message)||H.error))?"timeout":"unreachable"})}}catch{}M(T),N([...F,...L])}catch(z){V(String(z.message||z))}},[e]);return x.useEffect(()=>{$();const R=setInterval($,5e3);return()=>clearInterval(R)},[$]),x.useEffect(()=>{let R=!1;return an("/api/config",e).then(z=>z.json()).then(z=>{R||G(!!z.readonlyDefault)}).catch(()=>{}),()=>{R=!0}},[e]),l.jsx("div",{className:"nc-set-overlay",onClick:t,children:l.jsxs("div",{className:"nc-set-panel",onClick:R=>R.stopPropagation(),children:[l.jsxs("div",{className:"nc-set-head",children:[l.jsx(ut,{name:"gear",size:18}),l.jsx("b",{children:f("settings")}),l.jsx("button",{type:"button",className:"nc-set-close",onClick:t,title:f("close"),children:l.jsx(ut,{name:"x",size:18})})]}),I&&l.jsx("div",{className:"nc-set-readonly",children:f("settings-readonly")}),W&&l.jsx("div",{className:"nc-err",children:W}),l.jsx("div",{className:`nc-set-tabs-wrap${v.start?" has-start-overflow":""}${v.end?" has-end-overflow":""}`,children:l.jsx("div",{className:"nc-set-tabs",ref:p,onScroll:U,children:["nodes","fleet","audio","input","system"].map(R=>l.jsx("button",{ref:u===R?m:null,type:"button",className:`nc-set-tabbtn${u===R?" on":""}`,onClick:()=>d(R),children:f(`tab-${R}`)},R))})}),l.jsxs("div",{className:"nc-set-body",children:[u==="nodes"&&l.jsx(YR,{token:e,nodes:w,roster:Z,settings:k,readonly:I,vlUnavailable:C,refresh:$,refreshAliases:()=>Y(R=>R+1)}),u==="fleet"&&l.jsx(RR,{token:e,readonly:I,startNewCell:o,initialLocation:s,targets:Z.map(R=>({route:R.route,label:R.label||R.name,status:R.status}))}),u==="audio"&&l.jsx(QR,{token:e,readonly:I,nodes:w,settings:k}),u==="input"&&l.jsx(JR,{}),u==="system"&&l.jsx(eP,{token:e,settings:k,readonly:I,refresh:$,roster:Z,section:b,setSection:S})]})]})})}function nP({token:e,initialPair:t,deviceDefault:n="",localNodeId:s="",localNameDefault:o="",onPairDone:a,onDone:u}){Vn();const[d,p]=x.useState(t?"pair":"welcome"),[m,v]=x.useState(!1),[y,b]=x.useState(null),[S,k]=x.useState(null),E=async()=>{v(!0),b(null);try{await ph(e,{wizardDone:!0}),a&&a(),u()}catch(w){b(String(w.message||w)),v(!1)}};return l.jsx("div",{className:"nc-wiz-overlay",children:l.jsxs("div",{className:"nc-wiz",children:[l.jsxs("div",{className:"nc-wiz-head",children:[l.jsx("b",{children:f("wizard-title")}),l.jsx("small",{children:f("hydra-simple")})]}),d==="welcome"&&l.jsxs("div",{className:"nc-wiz-body",children:[l.jsx("div",{className:"nc-wiz-done",children:f("local-ready")}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{className:"nc-btn ghost",disabled:m,onClick:E,children:f("local-only")}),l.jsx("button",{className:"nc-btn primary",disabled:m,onClick:()=>p("pair"),children:f("add-node")})]})]}),d==="pair"&&l.jsxs("div",{className:"nc-wiz-body",children:[l.jsx(qw,{token:e,initial:t||"",autoStart:!!t,deviceDefault:n,localNodeId:s,localNameDefault:o,onBusyChange:v,onSuccess:async w=>{k(w&&w.authorizedKeys?{line:w.authorizedKeys,note:w.authorizedKeysNote||""}:null),a&&a(),p("done")}}),l.jsx("div",{className:"nc-sheet-actions",children:l.jsx("button",{className:"nc-btn ghost",disabled:m,onClick:()=>{a&&a(),p("welcome")},children:f("back")})})]}),d==="done"&&l.jsxs("div",{className:"nc-wiz-body",children:[l.jsx("div",{className:"nc-wiz-done",children:f("node-connected")}),S&&l.jsx(mp,{line:S.line,note:S.note}),l.jsx("div",{className:"nc-sheet-actions",children:l.jsx("button",{className:"nc-btn primary",disabled:m,onClick:E,children:f("finish")})})]}),y&&l.jsx("div",{className:"nc-err",children:y})]})})}function iP(e,t){if(typeof EventSource>"u"||!e)return()=>{};const n=new EventSource(`/api/events?token=${encodeURIComponent(e)}`);return n.onmessage=s=>{try{const o=JSON.parse(s.data);o&&typeof o=="object"&&typeof o.type=="string"&&t(o)}catch{}},()=>{try{n.close()}catch{}}}const sP=6e3,rP=12e3;function oP({n:e,onClose:t}){return l.jsxs("div",{className:`nc-ntf-toast${e.urgency==="high"?" high":""}`,role:"status","aria-live":"polite",children:[l.jsxs("div",{className:"nc-ntf-toast-txt",children:[l.jsx("b",{children:e.title}),e.body&&l.jsx("small",{children:e.body}),e.session&&l.jsx("span",{className:"nc-ntf-from",children:e.session})]}),l.jsx("button",{type:"button",className:"nc-ntf-x",onClick:t,title:f("close"),children:l.jsx(ut,{name:"x",size:14})})]})}function aP({ask:e,token:t,onAnswered:n,onDismiss:s}){const[o,a]=x.useState(""),[u,d]=x.useState(!1),[p,m]=x.useState(null),[v,y]=x.useState(!1),b=async k=>{const E=String(k||"").trim();if(!(!E||u)){m(null),d(!0);try{await Hx(t,e.id,E),n(e.id)}catch(w){m(String(w.message||w))}d(!1)}},S=async()=>{if(!v){y(!0);try{await Ux(t,e.id),s(e.id)}catch{y(!1)}}};return l.jsxs("div",{className:"nc-ask-card",children:[l.jsxs("div",{className:"nc-ask-head",children:[l.jsx("span",{className:"nc-ntf-from",children:e.session}),l.jsxs("code",{className:"nc-ask-id",children:["#",e.id]}),l.jsx("button",{type:"button",className:"nc-ask-dismiss",title:f("ask-dismiss"),"aria-label":f("ask-dismiss"),disabled:v,onClick:S,children:l.jsx(ut,{name:"x",size:14})})]}),l.jsx("div",{className:"nc-ask-q",children:e.question}),Array.isArray(e.options)&&e.options.length>0&&l.jsx("div",{className:"nc-ask-opts",children:e.options.map(k=>l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:u,onClick:()=>b(k),children:k},k))}),l.jsxs("div",{className:"nc-ask-reply",children:[l.jsx("textarea",{rows:2,placeholder:f("ask-reply-ph"),value:o,disabled:u,onChange:k=>a(k.target.value)}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:u||!o.trim(),onClick:()=>b(o),children:f("send")})]}),p&&l.jsx("div",{className:"nc-err",children:p})]})}function lP({token:e}){const[t]=Vn(),[n]=cS(),[s,o]=x.useState([]),[a,u]=x.useState([]),[d,p]=x.useState(()=>{try{return/(?:^|[#&])ask=/.test(location.hash)}catch{return!1}}),m=x.useRef(0),v=x.useRef(null);v.current||(v.current=KR());const y=x.useRef({enabled:n,lang:t});y.current={enabled:n,lang:t};const b=x.useCallback(w=>{o(N=>N.filter(C=>C.key!==w))},[]),S=x.useCallback(w=>{const N=`t${m.current+=1}`;o(M=>[...M.slice(-3),{...w,key:N}]),setTimeout(()=>b(N),w.urgency==="high"?rP:sP);const C=y.current;if(C.enabled)try{v.current.enqueue(w,$R(w,C.lang))}catch{}},[b]);x.useEffect(()=>{n||v.current.stop()},[n]),x.useEffect(()=>{const w=()=>{(document.visibilityState!=="visible"||!document.hasFocus())&&v.current.stop()},N=()=>v.current.stop();return document.addEventListener("visibilitychange",w),window.addEventListener("blur",w),window.addEventListener(yf,N),()=>{document.removeEventListener("visibilitychange",w),window.removeEventListener("blur",w),window.removeEventListener(yf,N),typeof v.current.dispose=="function"?v.current.dispose():v.current.stop()}},[]),x.useEffect(()=>{if(!e)return;let w=!1;Fx(e).then(C=>{w||u(C.asks||[])}).catch(()=>{});const N=iP(e,C=>{C.type==="notify"?S(C):C.type==="ask"&&C.ask&&C.ask.id?u(M=>M.some(I=>I.id===C.ask.id)?M:[...M,C.ask]):C.type==="ask-answered"&&C.id?u(M=>M.filter(I=>I.id!==C.id)):C.type==="ask-dismissed"&&C.id&&u(M=>M.filter(I=>I.id!==C.id))});return()=>{w=!0,N()}},[e,S]);const k=w=>u(N=>N.filter(C=>C.id!==w)),E=w=>u(N=>N.filter(C=>C.id!==w));return l.jsxs(l.Fragment,{children:[s.length>0&&l.jsx("div",{className:"nc-ntf-toasts",children:s.map(w=>l.jsx(oP,{n:w,onClose:()=>b(w.key)},w.key))}),a.length>0&&!d&&l.jsxs("button",{type:"button",className:"nc-ask-badge",onClick:()=>p(!0),title:f("asks-title"),children:["? ",l.jsx("span",{className:"nc-ask-count",children:a.length})]}),a.length>0&&d&&l.jsxs("div",{className:"nc-ask-panel",children:[l.jsxs("div",{className:"nc-ask-panel-head",children:[l.jsx("b",{children:f("asks-title")}),l.jsx("span",{className:"nc-ask-count",children:a.length}),l.jsx("button",{type:"button",className:"nc-ntf-x",onClick:()=>p(!1),title:f("close"),children:l.jsx(ut,{name:"x",size:16})})]}),l.jsx("div",{className:"nc-ask-panel-body",children:a.map(w=>l.jsx(aP,{ask:w,token:e,onAnswered:k,onDismiss:E},w.id))})]})]})}const cP=4e3;async function uP(e){const t=await an("/api/sessions",e);if((t==null?void 0:t.ok)===!1)throw new Error(`HTTP ${t.status}`);const n=await t.json();if(!Array.isArray(n==null?void 0:n.sessions))throw new Error("invalid sessions payload");return n.sessions}async function uh(e,t=[]){var d;const[n,s]=await Promise.allSettled([t.length?Pf(e,t):uP(e),Gs(e,t)]),o=n.status==="fulfilled"&&Array.isArray((d=n.value)==null?void 0:d.sessions)?n.value.sessions:Array.isArray(n.value)?n.value:null,a=s.status==="fulfilled"?s.value:null,u=(a==null?void 0:a.available)===!0&&Array.isArray(a.cells)?a.cells:null;return{sessions:o,cells:u,fresh:Array.isArray(o)&&Array.isArray(u)}}function uS(e,t,n){return n===!0&&(e==null?void 0:e.degraded)!==!0&&(e==null?void 0:e.active)===!0&&e.tmux!==!1&&!!e.tmuxSession&&(t||[]).some(s=>(s==null?void 0:s.name)===e.tmuxSession)}function dP(e){const t=new Map((e.sessions||[]).map(o=>[o.name,o])),n=[],s=(o,a,u,d=[],p="")=>{const m=new Map((a||[]).map(v=>[v.name,v]));for(const v of o||[]){const y=m.get(v.tmuxSession)||{},b=Bf(v,y),S=uS(v,a,u);n.push({key:xa(d,v.tmuxSession||v.cell),session:v.tmuxSession,route:d,cellName:v.cell,label:v.cell,node:d.length?d.join("/"):"",nodeLabel:p,live:S,selectable:S,verified:u===!0,working:b.working,degraded:!!v.degraded,active:v.active===!0,activity:y.activity||v.activity||0,subtitle:b.subtitle,preview:y.preview||v.preview||"",telemetry:y.telemetry||null,panelUrl:v.panelUrl||""})}};s(e.cells,[...t.values()],e.localFresh===!0);for(const o of e.nodeGroups||[]){const a=Array.isArray(o.route)?o.route:[];o.kind==="vl"||!a.length||s(o.cells,o.sessions,o.switcherFresh===!0,a,o.label||o.name||"")}return n}function hP(e){const t=new Map,n=Array.isArray(e.sessions)?e.sessions:[],s=Array.isArray(e.cells)?e.cells:[],o=new Map(n.map(u=>[u.name,u])),a=new Set(s.map(u=>u.tmuxSession).filter(Boolean));t.set("local",zf(s,n.filter(u=>!a.has(u.name)),o));for(const u of e.nodeGroups||[]){const d=Array.isArray(u.route)?u.route:[];if(u.kind==="vl"||!d.length)continue;const p=Array.isArray(u.cells)?u.cells:[],m=Array.isArray(u.sessions)?u.sessions:[],v=new Set(p.map(y=>y.tmuxSession).filter(Boolean));t.set(d.join("/"),dc({...u,route:d,cells:p,sessions:m,unmanaged:m.filter(y=>!v.has(y.name))}).rawItems)}return t}function fP(e,t,n,s){return[...new Set(e.map(a=>a.node||"local"))].flatMap(a=>{const u=e.filter(v=>(v.node||"local")===a),d=new Map((t.get(a)||[]).map(v=>[v.key,v])),p=new Map(u.map(v=>[v.key,v])),m=u.map(v=>{const y=d.get(v.key);return{...v,label:(y==null?void 0:y.label)||v.label,live:(y==null?void 0:y.live)??v.live,fresh:(y==null?void 0:y.fresh)===!0,activity:(y==null?void 0:y.activity)??v.activity}});return Ks(m,n,"all",ps(s,a)).map(v=>p.get(v.key))})}function pP({token:e,current:t,onPick:n,onClose:s,panelPort:o=0,nodePanelPorts:a={}}){const[u,d]=x.useState(vv),[p,m]=x.useState(!1),[v,y]=x.useState(!1),[b,S]=x.useState(""),[k,E]=x.useState(null),[w,N]=x.useState(""),[C,M]=x.useState(""),I=x.useRef(null),G=x.useRef(null),W=x.useMemo(()=>dP(u),[u]),V=x.useMemo(()=>hP(u),[u]),{pins:K,orders:Y,canMoveRoster:Z,moveRoster:U,stepRoster:$}=If(),R=x.useMemo(()=>fP(W,V,K,Y),[W,V,K,Y]),z=x.useMemo(()=>p?R:R.filter(A=>A.selectable||A.degraded&&A.active),[R,p]),F=x.useMemo(()=>W.find(A=>A.key===w&&A.selectable),[W,w]),L=x.useMemo(()=>k?W.find(A=>A.key===k.key):null,[W,k]);x.useEffect(()=>{var O;const A=document.activeElement;(O=G.current)==null||O.focus();const D=H=>{H.key==="Escape"&&s()};return document.addEventListener("keydown",D),()=>{var H;document.removeEventListener("keydown",D),(H=A==null?void 0:A.focus)==null||H.call(A)}},[s]),x.useEffect(()=>{let A=!0,D=!1;const O=async()=>{if(D)return;D=!0;const ie=vv(),ee=Array.isArray(ie.nodeGroups)?ie.nodeGroups:[],ue=uh(e),ve=Ne=>Ne.kind!=="vl"&&Array.isArray(Ne.route)&&Ne.route.length>0,fe=await Promise.all(ee.filter(ve).map(async Ne=>({group:Ne,result:await uh(e,Ne.route)}))),pe=await ue;if(!A)return;const Ye=new Map(fe.map(({group:Ne,result:Ct})=>[JSON.stringify(Ne.route||[]),Ct])),ht=ee.map(Ne=>{if(!ve(Ne))return{...Ne,switcherFresh:!1};const Ct=Ye.get(JSON.stringify(Ne.route||[]));return Ct?{...Ne,sessions:Ct.sessions||Ne.sessions||[],cells:Ct.cells||Ne.cells||[],switcherFresh:Ct.fresh}:{...Ne,switcherFresh:!1}}),yt=vb({...ie,sessions:pe.sessions||ie.sessions||[],cells:pe.cells||ie.cells||[],localFresh:pe.fresh,nodeGroups:ht,refreshedAt:Date.now()});d(yt),y(!0),D=!1};O();const H=setInterval(O,cP);return()=>{A=!1,clearInterval(H)}},[e]);const T=A=>A.degraded?f("cell-degraded"):A.verified?A.selectable?A.working?f("cell-working"):f("cell-idle"):f("cell-off"):f("cell-switcher-not-confirmed"),j=A=>{if(S(""),!A.selectable){S(A.verified?f("cell-switcher-not-active"):f("cell-switcher-not-confirmed"));return}N(A.key)},B=async()=>{const A=F;if(!A){S(f("cell-switcher-select"));return}S(""),M(A.key);try{const D=await uh(e,A.route),O=(D.cells||[]).find(H=>(H==null?void 0:H.cell)===A.cellName&&(H==null?void 0:H.tmuxSession)===A.session);if(D.fresh!==!0){S(f("cell-switcher-verify-failed"));return}if(!uS(O,D.sessions,D.fresh)){S(f("cell-switcher-not-active"));return}n({session:A.session,...A.node?{node:A.node}:{},cellName:A.cellName}),s()}catch{S(f("cell-switcher-verify-failed"))}finally{M("")}};return l.jsx("div",{className:"nc-cell-switcher-backdrop",onClick:s,children:l.jsxs("aside",{ref:I,className:"nc-cell-switcher",role:"dialog","aria-label":f("fleet-cells"),tabIndex:-1,onClick:A=>A.stopPropagation(),children:[l.jsxs("div",{className:"nc-cell-switcher-list",children:[!v&&l.jsx("div",{className:"nc-empty",role:"status",children:f("cell-switcher-refreshing")}),v&&z.length===0&&l.jsx("div",{className:"nc-empty",role:"status",children:f("cell-switcher-empty-active")}),z.map(A=>{const D=(t==null?void 0:t.session)===A.session&&((t==null?void 0:t.node)||"")===A.node,O=w===A.key,H=T(A),ie=ff(f,A.activity),ee=pf(f,A.telemetry),ue=[ie,ee].filter(Boolean).join(" · "),ve=A.node||"local",fe=V.get(ve)||W.filter(pe=>(pe.node||"local")===ve);return l.jsxs("div",{className:`nc-cell-switcher-row${D?" current":""}${O?" selected":""}${A.selectable?"":" off"}`,"data-roster-key":A.key,"data-position":ve,children:[l.jsx(Vi,{position:ve,itemKey:A.key,label:A.cellName,canMove:Z,onMove:(pe,Ye)=>U(ve,pe,Ye,fe),onStep:pe=>$(ve,A.key,pe,fe)}),l.jsx("button",{type:"button",className:"nc-cell-switcher-peek",title:f("cell-peek"),"aria-label":`${f("cell-peek")}: ${A.cellName}`,onClick:pe=>{pe.stopPropagation(),E({key:A.key,source:"preview"})},children:l.jsx("span",{className:`nc-cell-switcher-dot${A.degraded?" warn":A.live?` on${A.working?" working":""}`:""}`})}),l.jsxs("span",{className:"nc-cell-switcher-acts",children:[l.jsx("button",{type:"button",className:"nc-cell-switcher-act",title:f("cell-peek-stream"),"aria-label":`${f("cell-peek-stream")}: ${A.cellName}`,onClick:pe=>{pe.stopPropagation(),E({key:A.key,source:"stream"})},children:"▶"}),A.panelUrl&&l.jsx("button",{type:"button",className:"nc-cell-switcher-act",title:f("cell-peek-panel"),"aria-label":`${f("cell-peek-panel")}: ${A.cellName}`,onClick:pe=>{pe.stopPropagation(),E({key:A.key,source:"panel"})},children:"▣"})]}),l.jsx("button",{type:"button",className:"nc-cell-switcher-row-select","aria-current":D?"true":void 0,"aria-pressed":O,"aria-disabled":!A.selectable,disabled:C===A.key,onClick:()=>j(A),children:l.jsxs("span",{className:"nc-cell-switcher-copy",children:[l.jsx("b",{children:A.cellName}),l.jsx("small",{className:"nc-cell-switcher-state",children:H}),l.jsx("small",{children:[A.nodeLabel,A.subtitle].filter(Boolean).join(" · ")}),ue&&l.jsx("small",{className:"nc-cell-switcher-telemetry",children:ue})]})})]},A.key)})]}),b&&l.jsx("div",{className:"nc-cell-switcher-notice",role:"status",children:b}),k&&L&&l.jsx(Sw,{row:L,token:e,initialSource:k.source,panelPort:Sc(L.route||[],a,o),onClose:()=>E(null)}),l.jsx("div",{className:"nc-cell-switcher-actions",children:l.jsx("button",{type:"button",className:"nc-cell-switcher-open",disabled:!F||!!C,onClick:B,children:F?`${f("cell-switcher-open")}: ${F.cellName}`:f("cell-switcher-select")})}),l.jsxs("div",{className:"nc-cell-switcher-controls",children:[l.jsx("b",{children:f("fleet-cells")}),l.jsx("button",{type:"button",className:"nc-cell-switcher-filter","aria-pressed":p,onClick:()=>{S(""),m(A=>!A)},children:f(p?"cell-switcher-show-active":"cell-switcher-show-all")}),l.jsx("button",{ref:G,type:"button",className:"nc-cell-switcher-close","aria-label":f("cell-switcher-close"),title:f("cell-switcher-close"),onClick:s,children:"×"})]})]})})}const mP=2e3;function gP(e){if(e.kind==="gap")return`${f("vl-events-gap")} ${e.count||"?"}`;if(e.kind==="truncate")return f("vl-events-truncated");if(e.kind==="turn_end")return f("vl-events-turn-end");if(e.kind==="done")return f("vl-events-done");if(e.kind==="writer_epoch")return f("vl-events-writer-epoch");if(e.kind==="tool_start")return`${f("vl-events-tool")} ${e.name||""}`.trim();if(e.kind==="tool_end"){const t=e.isError?f("vl-events-tool-failed"):f("vl-events-tool-ok");return`${f("vl-events-tool")} ${e.name||""} — ${t}`.trim()}return e.kind==="usage"?e.text||f("vl-events-usage"):e.text||""}function vP({token:e,nodeId:t,route:n=[]}){const[s,o]=x.useState([]),[a,u]=x.useState(!1),d=x.useRef(0),p=x.useRef(!1);return x.useEffect(()=>{let m=!0;d.current=0,p.current=!1,o([]);const v=async()=>{if(!p.current){p.current=!0;try{const S=await yx(e,t,d.current,n);if(!m)return;u(!1);const E=(Array.isArray(S==null?void 0:S.events)?S.events:[]).filter(w=>Number.isSafeInteger(w==null?void 0:w.seq)&&w.seq>d.current);E.length&&(o(w=>w.concat(E).slice(-500)),d.current=E[E.length-1].seq),Number.isSafeInteger(S==null?void 0:S.cursor)&&S.cursor>d.current&&(d.current=S.cursor)}catch{m&&u(!0)}finally{p.current=!1}}},y=()=>{v().catch(()=>{})};y();const b=setInterval(y,mP);return()=>{m=!1,clearInterval(b)}},[e,t,JSON.stringify(n)]),l.jsxs("div",{className:"nc-vl-events",children:[a&&l.jsx("div",{className:"nc-set-hint nc-vl-events-stale",children:f("vl-events-stale")}),s.length===0&&!a&&l.jsx("small",{className:"nc-set-hint","data-testid":"vl-events-empty",children:f("vl-events-empty")}),s.length>0&&l.jsx("ol",{className:"nc-vl-events-list",children:s.map(m=>l.jsx("li",{"data-testid":`vl-ev-${m.seq}`,className:`nc-vl-ev nc-vl-ev-${m.kind}${m.isError?" error":""}${m.kind==="gap"?" gap":""}`,children:gP(m)},`${m.seq}-${m.kind}`))})]})}function jy({peer:e,token:t,onBack:n}){var s;return Vn(),e?l.jsxs("section",{className:"nc-vl-session-view",children:[l.jsxs("header",{className:"nc-bar nc-bar-single",children:[l.jsxs("button",{onClick:n,title:f("back"),children:[l.jsx(ut,{name:"chevronLeft",size:18}),l.jsx("span",{className:"nc-bar-label",children:f("back")})]}),l.jsxs("span",{className:"nc-bar-center",children:[l.jsx("b",{title:e.label,children:e.label}),((s=e.session)==null?void 0:s.profile)&&l.jsxs("small",{className:"nc-bar-sub",children:[e.session.profile," · ",f("vl-events-title")]})]}),l.jsx("span",{className:"nc-bar-right"})]}),l.jsx("div",{className:"nc-vl-session-body",children:l.jsx(vP,{token:t,nodeId:e.nodeId,route:e.route||[]})})]}):null}const dh=e=>Xi(xr(e)).length===0,hh=e=>Array.isArray(e)?e.join("/"):"";function _P(e){const t=new Set,n=[];for(const s of Array.isArray(e)?e:[])!s||!mi.test(String(s.instanceId||""))||!Array.isArray(s.route)||!s.route.length||t.has(s.instanceId)||(t.add(s.instanceId),n.push({instanceId:s.instanceId,route:[...s.route],label:String(s.label||s.name||s.route.join(" › ")),status:s.status||"offline"}));return n.sort((s,o)=>s.label.localeCompare(o.label))}function da(e){return{instanceId:e.ownerId,route:e.ownerRoute||[],label:e.ownerLabel,status:e.available===!1?"offline":"up"}}function vr(e,t,n,s=!1,o=!0){const a=t.instanceId;return{...e,id:po(s?null:a,e.name),ownerId:a,ownerRoute:s?[]:[...t.route],ownerLabel:s?"Local":t.label,local:s,available:o,ownerTopology:Array.isArray(n)?n:[],layout:mf(e.layout,a,n)}}function yP(e,t,n,s,o=[]){const[a,u]=x.useState([]),[d,p]=x.useState(!1),[m,v]=x.useState("idle"),[y,b]=x.useState(""),[S,k]=x.useState(""),E=x.useRef([]),w=x.useRef([]),N=x.useRef(""),C=x.useRef(t),M=x.useRef(n),I=x.useRef(!1),G=x.useRef(!0),W=x.useRef(""),V=x.useMemo(()=>_P(o),[o]),K=V.map(A=>`${A.instanceId}:${hh(A.route)}:${A.status}:${A.label}`).join("|");w.current=V,M.current=n,C.current=t,E.current=a;const Y=x.useCallback(A=>gf(A.layout,N.current,w.current),[]),Z=x.useCallback((A,D=!0,O=C.current)=>{const H=M_(A,Yl()),ie=E.current.some(ue=>ue.id===O);E.current=H,u(H);const ee=H.find(ue=>ue.id===O);if(D&&ee){G.current=!0;const ue=Y(ee);s(ue),ee.local&&D2(ee.name,ue)}else ie&&!ee&&(G.current=!0,s(fo()),b("deck non più condiviso dal nodo owner"));L2(H.filter(ue=>ue.local).map(ue=>ue.name))},[s,Y]),U=x.useCallback(async A=>{let D=await zl(e);const O=D.decks.find(H=>H.name==="main");if(D.decks.length===1&&O&&O.revision===0&&dh(O.layout)){const H=P2(),ie=xr(vf("main")||fo());if(!dh(ie)){const ee=mf(ie,A,[]);D.decks[0]=await $l(e,"main",ee,0,[])}for(const ee of H.filter(ue=>ue!=="main"))try{let ue=await ev(e,ee,[]);const ve=xr(vf(ee)||fo());dh(ve)||(ue=await $l(e,ee,mf(ve,A,[]),ue.revision,[]))}catch{}D=await zl(e)}return D},[e]),$=x.useCallback(async({migrate:A=!1}={})=>{const D=await Lf(e,[]),O=mi.test(String(D.instanceId||""))?D.instanceId:"";if(!O)throw new Error("instanceId locale non disponibile");N.current=O,k(O);const[H,ie]=await Promise.all([A?U(O):zl(e),Xg(e,[]).catch(()=>({nodes:[]}))]),ee={instanceId:O,route:[],label:"Local"},ue=H.decks.map(fe=>vr(fe,ee,ie.nodes,!0,!0)),ve=E.current;return await Promise.all(w.current.map(async fe=>{if(fe.status!=="up"){ue.push(...ve.filter(pe=>!pe.local&&pe.ownerId===fe.instanceId).map(pe=>({...pe,ownerRoute:[...fe.route],ownerLabel:fe.label,available:!1})));return}try{const[pe,Ye]=await Promise.all([zl(e,fe.route),Xg(e,fe.route).catch(()=>({nodes:[]}))]);ue.push(...pe.decks.map(ht=>vr(ht,fe,Ye.nodes,!1,!0)))}catch{ue.push(...ve.filter(Ye=>!Ye.local&&Ye.ownerId===fe.instanceId).map(Ye=>({...Ye,ownerRoute:[...fe.route],ownerLabel:fe.label,available:!1})))}})),ue.sort((fe,pe)=>fe.local===pe.local?fe.ownerLabel.localeCompare(pe.ownerLabel)||(fe.name==="main"?-1:pe.name==="main"?1:fe.name.localeCompare(pe.name)):fe.local?-1:1),ue},[e,U,K]);x.useEffect(()=>{if(!e)return;let A=!1;const D=W.current!==e;return W.current=e,$({migrate:D}).then(O=>{if(A)return;const H=E.current.find(ue=>ue.id===C.current),ie=O.find(ue=>ue.id===C.current),ee=ie&&(!H||ie.revision>H.revision||H.available!==ie.available||hh(H.ownerRoute)!==hh(ie.ownerRoute));Z(O,D||!!ee&&!I.current),p(!0),ie&&b("")}).catch(O=>{A||(p(!0),b(String(O.message||O)))}),()=>{A=!0}},[Z,$,K,e]);const R=x.useCallback(async(A=C.current)=>{if(!d||!I.current)return!0;const D=E.current.find(O=>O.id===A);if(!D)return b(`deck inesistente: ${A}`),!1;if(D.available===!1)return b(`nodo owner offline: ${D.ownerLabel}`),!1;v("saving");try{const O=L_(xr(M.current),D.ownerId,D.ownerTopology),H=await $l(e,D.name,O,D.revision,D.ownerRoute),ie=vr(H,da(D),D.ownerTopology,D.local,!0);return Z(E.current.map(ee=>ee.id===A?ie:ee),!1),I.current=!1,v("saved"),b(""),setTimeout(()=>v("idle"),1500),!0}catch(O){if(v("error"),b(String(O.message||O)),O.status===409&&O.data&&O.data.current){const H=E.current.find(ee=>ee.id===A),ie=vr(O.data.current,da(H),H.ownerTopology,H.local,!0);Z(E.current.map(ee=>ee.id===A?ie:ee),!1)}return!1}},[d,e,Z]);return x.useEffect(()=>{if(!d)return;if(G.current){G.current=!1;return}I.current=!0,v("saving");const A=setTimeout(R,650);return()=>clearTimeout(A)},[n,d,R]),x.useEffect(()=>{if(!d)return;const A=setInterval(async()=>{try{const D=await $(),O=E.current.find(ee=>ee.id===C.current),H=D.find(ee=>ee.id===C.current),ie=H&&(!O||H.revision>O.revision||O.available!==H.available);Z(D,ie&&!I.current)}catch{}},5e3);return()=>clearInterval(A)},[d,$,Z]),{decks:a,records:a,localNodeId:S,ready:d,saveState:m,error:y,setError:b,saveNow:R,select:async A=>{if(I.current&&!await R(C.current))throw new Error("salvataggio del deck corrente fallito: cambio annullato");const D=E.current.find(O=>O.id===A);if(!D)throw new Error(`deck inesistente: ${A}`);return I.current=!1,G.current=!0,Y(D)},add:async(A,D=null)=>{const O=D===Yi?E.current.find(ee=>ee.local):D?E.current.find(ee=>ee.ownerId===D):null;if(!O||O.available===!1)throw new Error("nodo owner non disponibile");const H=await ev(e,A,O.ownerRoute),ie=vr(H,da(O),O.ownerTopology,O.local,!0);return Z([...E.current,ie],!1),ie},rename:async(A,D)=>{const O=E.current.find(ve=>ve.id===A);if(!O)throw new Error("deck inesistente");if(A===C.current&&I.current&&!await R(A))throw new Error(`salvataggio di "${O.name}" fallito: rinomina annullata`);const H=E.current.find(ve=>ve.id===A);if(!H)throw new Error("deck inesistente");const ie=await Wx(e,H.name,D,H.revision,H.ownerRoute),ee=vr(ie,da(H),H.ownerTopology,H.local,!0),ue=H.local?Yi:H.ownerId;return Bd(M2(Yl(),ue,A,ee.id)),Z(E.current.map(ve=>ve.id===A?ee:ve),!1),ee},remove:async A=>{const D=E.current.find(H=>H.id===A);if(!D)throw new Error("deck inesistente");A===C.current&&(I.current=!1),await Kx(e,D.name,D.revision,D.ownerRoute);const O=D.local?Yi:D.ownerId;Bd(T2(Yl(),O,A)),Z(E.current.filter(H=>H.id!==A),!1)},reorder:(A,D)=>{const O=E.current.find(fe=>fe.id===A),H=E.current.find(fe=>fe.id===D);if(!O||!H)return!1;const ie=O.local?Yi:O.ownerId,ee=H.local?Yi:H.ownerId;if(ie!==ee)return!1;const ue=E.current.filter(fe=>(fe.local?Yi:fe.ownerId)===ie).map(fe=>fe.id),ve=Bd(A2(Yl(),ie,A,D,ue));return Z(M_(E.current,ve),!1),!0},addTileTo:async(A,D)=>{const O=E.current.find(fe=>fe.id===A);if(!O)throw new Error("deck inesistente");if(O.available===!1)throw new Error(`nodo owner offline: ${O.ownerLabel}`);const H=jw(D,N.current,w.current);if(!H)throw new Error("riferimento sessione non valido");const ie=Y(O),ee=L_(fb(ie,H),O.ownerId,O.ownerTopology),ue=await $l(e,O.name,ee,O.revision,O.ownerRoute),ve=vr(ue,da(O),O.ownerTopology,O.local,!0);return Z(E.current.map(fe=>fe.id===A?ve:fe),!1),ve},localMainId:po(null,"main"),parseDeckId:Lc}}const bP="/sw.js",wf="nc-sw-update";let Sf=null,xf=!1,kf=null,dS=Object.freeze({needed:!1,kind:null,version:""}),hS=!1;function fS(){typeof window<"u"&&window.dispatchEvent(new Event(wf))}function pS(){const e=kf||(xf?{kind:"reload",version:""}:null);dS=Object.freeze({needed:!!e,kind:(e==null?void 0:e.kind)||null,version:(e==null?void 0:e.version)||""})}function Ry(){return dS}function wP(e){return typeof window>"u"?()=>{}:(window.addEventListener(wf,e),()=>window.removeEventListener(wf,e))}function xp(e){xf!==e&&(xf=e,pS(),fS())}const fh="nc-auto-reload";function SP(){try{return typeof sessionStorage<"u"?sessionStorage:null}catch{return null}}function xP(e,t,n,s={}){let o=null;e&&t&&e!==t?o={kind:"install",version:e}:t&&n&&t!==n&&(o={kind:"reload",version:t});const a=JSON.stringify(o)===JSON.stringify(kf);kf=o,pS(),a||fS();const u=s.storage===void 0?SP():s.storage;if(!o){try{u&&u.removeItem(fh)}catch{}return}if(o.kind!=="reload"||!u)return;const d=`${t}|${n}`;try{if(u.getItem(fh)===d)return;u.setItem(fh,d)}catch{return}(s.applyImpl||mS)()}function kP(e){e.addEventListener("statechange",()=>{e.state==="installed"&&navigator.serviceWorker.controller&&xp(!0)})}function CP(){typeof navigator>"u"||!("serviceWorker"in navigator)||(navigator.serviceWorker.addEventListener("controllerchange",()=>{hS&&location.reload()}),navigator.serviceWorker.register(bP).then(e=>{Sf=e,e.waiting&&xp(!0),e.addEventListener("updatefound",()=>{const t=e.installing;t&&kP(t)}),setInterval(()=>{e.update().catch(()=>{})},3600*1e3)}).catch(()=>{}))}function mS(){hS=!0,xp(!1);const e=Sf&&Sf.waiting;e?(e.postMessage({type:"SKIP_WAITING"}),setTimeout(()=>location.reload(),4e3)):location.reload()}function EP({hash:e="",origin:t="",pathname:n="",search:s=""}={}){const o=String(e||"").replace(/^#/,""),a=`${n||""}${s||""}`;if(!o)return{token:"",pair:"",nextUrl:a};const u=new URLSearchParams(o),d=u.get("token")||"",p=u.get("pair")||"",m=p?`${t||""}${n||""}#pair=${p}`:"";return{token:d,pair:m,nextUrl:a}}const gS=9,vS=24,_S="nc_side_w",Py="nc_side_min",NP=240;function jP(){const e=Number(localStorage.getItem(_S));return e>=180&&e<=480?e:NP}function RP(){const e=Number(localStorage.getItem("nc_fontsize"));return e>=gS&&e<=vS?e:13}function PP(){const e={token:"",pair:""};try{const{token:t,pair:n,nextUrl:s}=EP({hash:location.hash,origin:location.origin,pathname:location.pathname,search:location.search});if(t){e.token=t;try{localStorage.setItem("nc_token",t)}catch{}}if(n){e.pair=n;try{sessionStorage.setItem("nc_pair",n)}catch{}}if(location.hash)try{history.replaceState(null,"",s)}catch{}}catch{}if(e.token||(e.token=sessionStorage.getItem("nc_token")||localStorage.getItem("nc_token")||""),!e.pair){const t=sessionStorage.getItem("nc_pair");t&&(e.pair=t)}return e}function LP(e){try{return xr(vf(e))}catch{return fo()}}function Ly(e){if(!e)return"";const t=Math.floor(Date.now()/1e3)-e;return t<0||t<60?"ora":t<3600?`${Math.floor(t/60)}m`:t<86400?`${Math.floor(t/3600)}h`:`${Math.floor(t/86400)}g`}function Ay({session:e,node:t,ownerId:n,cellName:s,token:o,readonly:a=!1,panelPort:u=0,onBack:d,onCellSwitcher:p,cellSwitcherOpen:m=!1}){Vn();const[v]=rp(),[y,b]=x.useState(!1),[S,k]=x.useState(()=>window.matchMedia("(pointer: coarse)").matches),[E,w]=x.useState(null),[N,C]=x.useState(RP),[M,I]=x.useState(s||e),[G,W]=x.useState(""),[V,K]=x.useState(""),[Y,Z]=x.useState(""),[U,$]=x.useState(!1),R=H=>C(ie=>{const ee=Math.max(gS,Math.min(vS,ie+H));return localStorage.setItem("nc_fontsize",String(ee)),ee}),z=x.useRef(()=>{}),F=x.useRef(()=>!1),L=x.useRef(()=>{}),T=x.useRef(!1),[j,B]=x.useState(!1),[A,D]=x.useState(!1),O=()=>{T.current=!T.current,B(T.current)};return x.useEffect(()=>{I(s||e),$(!1)},[s,e]),x.useEffect(()=>{let H=!0;const ie=t?t.split("/"):[],ee=t?`/api/route/${t.split("/").map(encodeURIComponent).join("/")}/_`:"/api";async function ue(){let fe=null,pe=null;try{const yt=await(await an(`${ee}/sessions`,o)).json();Array.isArray(yt.sessions)&&(fe=yt.sessions.find(Ne=>Ne.name===e))}catch{}try{const ht=await Gs(o,ie);ht.available&&Array.isArray(ht.cells)&&(pe=ht.cells.find(yt=>yt.tmuxSession===e))}catch{}if(!H)return;I(op({session:e,cell:pe||(s?{cell:s}:null)})),K(typeof(pe==null?void 0:pe.panelUrl)=="string"?pe.panelUrl.trim():""),Z(typeof(pe==null?void 0:pe.cell)=="string"?pe.cell:"");let Ye="";pe?Ye=`${pe.engine}${pe.key?`·${pe.key}`:""}`:fe&&(Ye=fe.attached?`attached · ${Ly(fe.activity)}`:fe.activity?Ly(fe.activity):""),W(Ye)}ue();const ve=setInterval(ue,4e3);return()=>{H=!1,clearInterval(ve)}},[e,t,o]),l.jsxs("div",{className:"nc-app",children:[l.jsxs("header",{className:"nc-bar nc-bar-single",children:[l.jsxs("button",{onClick:d,title:f("sessions"),children:[l.jsx(ut,{name:"chevronLeft",size:18}),l.jsx("span",{className:"nc-bar-label",children:f("sessions")})]}),l.jsxs("span",{className:"nc-bar-center",children:[l.jsx("b",{title:t?`${M} · ${t}`:M,children:M}),G&&l.jsx("small",{className:"nc-bar-sub",children:G})]}),l.jsxs("span",{className:"nc-bar-right",children:[l.jsx("button",{onClick:()=>R(-1),title:f("zoom-out"),children:l.jsx(ut,{name:"zoomOut",size:18})}),l.jsx("button",{onClick:()=>R(1),title:f("zoom-in"),children:l.jsx(ut,{name:"zoomIn",size:18})}),l.jsx("button",{onClick:()=>k(H=>!H),title:f("composer"),children:l.jsx(ut,{name:"keyboard",size:20})}),l.jsx("button",{onClick:()=>b(H=>!H),title:f("files"),children:l.jsx(ut,{name:"folder",size:20})}),V&&l.jsx("button",{onClick:()=>$(H=>!H),title:f("panel"),"aria-pressed":U,children:l.jsx(ut,{name:"monitor",size:20})})]})]}),l.jsxs("div",{className:"nc-termwrap",children:[l.jsx(Zf,{session:e,node:t,token:o,readonly:a,takeSize:!0,sendRef:z,composerRef:F,actionRef:L,ctrlRef:T,setCtrlArmed:B,onFiles:w,fontSize:N,selectionMode:A,onSelectionModeChange:D,keyboardGesture:v.terminalKeyboardGesture}),U&&V&&Y&&l.jsx(np,{cellId:Y,panelUrl:V,route:t?t.split("/"):[],panelPort:u,token:o,title:M})]}),l.jsx(VN,{onKeyboard:()=>k(H=>!H),onCellSwitcher:p,cellSwitcherOpen:m,send:H=>z.current(H),action:H=>L.current(H),ctrlArmed:j,onCtrl:O,selectionMode:A,onSelectionMode:D,keepKeyboardClosed:v.keybarKeepsKeyboardClosed,showEnter:v.showKeybarEnter,keybarLayout:v.keybarLayout}),S&&l.jsx(yw,{submitText:H=>F.current(H),token:o,session:e,node:t,ownerId:n,readonly:a,keepKeyboardClosedOnVoice:v.voiceKeepsKeyboardClosed}),y&&l.jsx(uw,{session:e,node:t,token:o,filesEvent:E,onClose:()=>b(!1)})]})}function AP(){Vn();const[e]=x.useState(PP),[t,n]=x.useState(e.token),[s,o]=x.useState(e.pair||""),a=x.useCallback(()=>{o("");try{sessionStorage.removeItem("nc_pair")}catch{}},[]),[u,d]=x.useState(!1),p=CN(),[m]=x.useState(()=>R2(typeof location<"u"?location.pathname:"/")),[v,y]=x.useState(m.id),b=v===po(null,gi),[S,k]=x.useState(null),E=de=>{const Ce=Ys(de);k(Ce?{...Ce,...typeof(de==null?void 0:de.cellName)=="string"&&de.cellName?{cellName:de.cellName}:{}}:null)},[w,N]=x.useState([]),[C,M]=x.useState([]),[I,G]=x.useState([]),[W,V]=x.useState(!1),[K,Y]=x.useState(null),[Z,U]=x.useState(()=>m.ownerId?fo():LP(m.name)),[$,R]=x.useState(null),[z,F]=x.useState(null),L=de=>F(Ys(de)),[T,j]=x.useState(null),B=Tf(t,p),A=x.useMemo(()=>(B||[]).filter(de=>de.instanceId).map(de=>({instanceId:de.instanceId,route:de.route,label:de.label,status:de.status})),[B]),D=yP(t,v,Z,U,A),O=D.decks;x.useEffect(()=>{const de=new Map;for(const Ce of B||[]){const Oe=(Ce.route||[Ce.name]).join("/"),nt=new Set((Ce.sessions||[]).map(it=>it.name));for(const it of Ce.cells||[])!it.cell||!it.tmuxSession||it.cell===it.tmuxSession||nt.has(it.cell)||de.set(`${Oe}:${it.cell}`,`${Oe}:${it.tmuxSession}`)}U(Ce=>jk(Ce,de))},[B]),x.useEffect(()=>{D.localNodeId&&U(de=>{const Ce=gf(de,D.localNodeId,A);return JSON.stringify(Ce)===JSON.stringify(de)?de:Ce})},[A,D.localNodeId]);const[H,ie]=x.useState(null),[ee,ue]=x.useState(null),ve=x.useRef(0),[fe,pe]=x.useState(!1),[Ye,ht]=x.useState(jP),[yt,Ne]=x.useState(!b),[Ct,hn]=x.useState(()=>b?localStorage.getItem(Py)==="1":!0),[vn,Gt]=x.useState(!1),[kt,Bt]=x.useState("nodes"),[Ut,Nt]=x.useState(!1),[Dt,Mt]=x.useState(""),[jt,fn]=x.useState(!1),se=(de="nodes",Ce=!1,Oe="")=>{Bt(de),Nt(Ce),Mt(Oe),Gt(!0)},[Qe,me]=x.useState(!1),[Xe,dt]=x.useState({deviceDefault:"",localNodeId:"",localNameDefault:""}),[re,ne]=x.useState(!1),[_e,ye]=x.useState(0),[xe,st]=x.useState({});x.useEffect(()=>{try{localStorage.setItem(_S,String(Ye))}catch{}},[Ye]),x.useEffect(()=>{try{localStorage.setItem(Py,Ct?"1":"")}catch{}},[Ct]),x.useEffect(()=>{if(!t)return;let de=!1;return Promise.all([Fy(t),an("/api/config",t).then(Ce=>Ce.json())]).then(([Ce,Oe])=>{de||(dt({deviceDefault:Ce.deviceName||"",localNodeId:Ce.nodeId||"",localNameDefault:Ce.localName||""}),ne(!!Oe.readonlyDefault),ye(Number.isInteger(Oe.panelPort)?Oe.panelPort:0),st(Oe.nodePanelPorts&&typeof Oe.nodePanelPorts=="object"&&!Array.isArray(Oe.nodePanelPorts)?Oe.nodePanelPorts:{}),(Ce.firstRun===!0&&!Oe.readonlyDefault||s)&&me(!0))}).catch(()=>{}),()=>{de=!0}},[t,s]);const[pt,ft]=x.useState({}),Rt=x.useRef(B);x.useEffect(()=>{Rt.current=B},[B]);const St=x.useCallback(async()=>{try{const it=await(await an("/api/sessions",t)).json();it.error||N(it.sessions||[])}catch{}let de=null,Ce=null;try{de=await Gs(t)}catch(nt){Ce=nt}const Oe=gb({fs:de,error:Ce});Oe.kind==="data"?(M(Oe.cells),G(Oe.capabilities),V(!1),Y(null)):Oe.kind==="stale"?(V(!0),Y(null)):(M([]),G([]),V(!1),Y(Oe.reason||""))},[t]);x.useEffect(()=>{let de=!1;const Ce=async()=>{const nt=[[],...(Rt.current||[]).filter(Pt=>Pt.kind!=="vl"&&Pt.status==="up").map(Pt=>Array.isArray(Pt.route)&&Pt.route.length?Pt.route:[Pt.name])],it=await Promise.all(nt.map(async Pt=>{try{const Ot=await qx(t,Pt);return[ya(Pt),{hostCell:Ot&&typeof Ot.hostCell=="string"?Ot.hostCell:null,hostLease:Ot&&Ot.host&&typeof Ot.host.lease=="string"?Ot.host.lease:null,hostRevision:Number.isInteger(Ot&&Ot.revision)?Ot.revision:0}]}catch{return null}}));de||ft(Pt=>{let Ot=!1;const Wt={...Pt};for(const si of it)si&&(Wt[si[0]]=si[1],Ot=!0);return Ot?Wt:Pt})};Ce();const Oe=setInterval(Ce,4e3);return()=>{de=!0,clearInterval(Oe)}},[t]),x.useEffect(()=>{if(!p)return;St();const de=setInterval(St,4e3);return()=>clearInterval(de)},[p,St]);const bt=x.useCallback(async(de,Ce=[])=>{const Oe=ya(Ce),nt=pt[Oe]&&pt[Oe].hostRevision||0;try{const it=await Vx(t,de,nt,Ce);ft(Pt=>({...Pt,[Oe]:{hostCell:it.hostCell||null,hostLease:it.host&&typeof it.host.lease=="string"?it.host.lease:null,hostRevision:Number.isInteger(it.revision)?it.revision:nt}}))}catch(it){window.alert(f(pv(it)))}},[t,pt]),$t=x.useCallback(async(de=[])=>{const Ce=ya(de),Oe=pt[Ce]&&pt[Ce].hostRevision||0;try{const nt=await Yx(t,Oe,de);return ft(it=>({...it,[Ce]:{hostCell:nt.hostCell||null,hostLease:null,hostRevision:Number.isInteger(nt.revision)?nt.revision:Oe}})),!0}catch(nt){return window.alert(f(pv(nt))),!1}},[t,pt]);x.useEffect(()=>{let de=!1;const Ce=()=>{an("/api/config",t).then(nt=>nt.json()).then(nt=>{de||xP(nt.version,nt.uiVersion,"0.9.12")}).catch(()=>{})};Ce();const Oe=setInterval(Ce,6e4);return()=>{de=!0,clearInterval(Oe)}},[t]);const Ze=new Set([...w.map(de=>de.name),...B.flatMap(de=>de.sessions.map(Ce=>Ce.key))]),J=Xi(Z),Ee=de=>U(Ce=>{const Oe=jw(de,D.localNodeId,A)||de,nt=fb(Ce,Oe);return nt===Ce&&Xi(Ce).length>=9&&D.setError(f("grid-full")),nt}),We=async(de,Ce=[])=>{try{await jf(t,de,Ce)}catch{return}const Oe=Ce.length?`${Ce.join("/")}:${de}`:de;U(nt=>fc(nt,Oe)),St()},ze=async(de,Ce,Oe=[])=>{try{await $y(t,de,Ce,Oe)}catch{return}St()},Te=async(de,Ce,Oe=[])=>{await Oy(t,{cell:de,enabled:!!Ce},Oe),St()},ct=async de=>{if(!H)return;const{cell:Ce}=H,Oe=Array.isArray(H.route)?H.route:[];if(de.action==="up"){const it=await Nf(t,{cell:Ce,boot:!!de.boot,...de.engine?{engine:de.engine}:{},...de.model!==void 0?{model:de.model}:{},...de.permissionPolicy?{permissionPolicy:de.permissionPolicy}:{}},Oe),Pt=Hf(it);Pt&&D.setError(Pt.text)}else await ac(t,{cell:Ce,boot:!!de.boot},Oe);const nt=de.action==="up"?!!de.boot:de.boot?!1:!!H.boot;ue({id:++ve.current,cell:Ce,route:Oe,enabled:nt}),St()},Et=x.useCallback(de=>{ue(Ce=>(Ce==null?void 0:Ce.id)===de?null:Ce)},[]),X=async de=>{if(!(!(de!=null&&de.direct)||fe)){pe(!0);try{await Af(t,de.name,de.tunnelStatus==="up"?"down":"up")}finally{pe(!1)}}},oe=async(de,Ce)=>{const Oe=String(Ce||"").trim();return!(de!=null&&de.direct)||!_o(Oe)?!1:(await Wy(t,de.name,Oe),!0)},we=de=>{const Ce=O.find(Oe=>Oe.id===de);if(!Ce)return!1;try{const Oe=window.open(Od(Ce,t),"_blank");return Oe&&(Oe.opener=null),!!Oe}catch{return!1}},De=async de=>{if(!de||de===v)return;const Ce=await D.select(de),Oe=D.records.find(nt=>nt.id===de);y(de),U(Ce),R(null),F(null);try{history.replaceState(null,"",Od(Oe||de,null))}catch{}},je=async(de,Ce)=>{const Oe=await D.add(de,Ce);await De(Oe.id)},Me=async(de,Ce)=>{const Oe=await D.rename(de,Ce);if(de===v){y(Oe.id),U(gf(Oe.layout,D.localNodeId,A)),R(null),F(null);try{history.replaceState(null,"",Od(Oe,null))}catch{}}},Je=async de=>{await D.remove(de),de===v&&await De(D.localMainId)},Pe=async(de,Ce)=>{!Ce||Ce===v||(await D.addTileTo(Ce,de),U(Oe=>fc(Oe,de)))};if(!t)return l.jsxs("div",{className:"nc-auth",children:[l.jsx("p",{children:f("auth-prompt")}),l.jsx("input",{onChange:de=>n(de.target.value.trim()),placeholder:"token"}),l.jsxs("label",{children:[l.jsx("input",{type:"checkbox",checked:u,onChange:de=>d(de.target.checked)})," ",f("remember-device")]}),l.jsx("button",{onClick:()=>{(u?localStorage:sessionStorage).setItem("nc_token",t)},children:"ok"})]});const Ie=l.jsxs(l.Fragment,{children:[vn&&l.jsx(tP,{token:t,initialTab:kt,initialLocation:Dt,startNewCell:Ut,onClose:()=>{Gt(!1),Nt(!1),Mt("")}}),Qe&&l.jsx(nP,{token:t,initialPair:s,...Xe,onPairDone:a,onDone:()=>me(!1)}),l.jsx(lP,{token:t})]});if(!p)return T?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-single-overlay",children:l.jsx(jy,{peer:T,token:t,onBack:()=>j(null)})}),Ie]}):S?l.jsxs(l.Fragment,{children:[l.jsx(Ay,{session:S.session,node:S.node,ownerId:S.ownerId,cellName:S.cellName,token:t,readonly:re,panelPort:Sc(S.node?S.node.split("/"):[],xe,_e),onBack:()=>k(null),onCellSwitcher:()=>fn(!0),cellSwitcherOpen:jt}),jt&&l.jsx(pP,{token:t,current:S,panelPort:_e,nodePanelPorts:xe,onPick:de=>{E(de),fn(!1)},onClose:()=>fn(!1)}),Ie]}):l.jsxs(l.Fragment,{children:[l.jsx(Vk,{onPick:E,token:t,onSettings:se,onOpenVlSession:j,hostByRoute:pt,onDesignateCell:bt,onClearHostCell:$t}),Ie]});const xt=b||!yt;return l.jsxs("div",{className:"nc-workspace",children:[xt&&l.jsx(_2,{sessions:w,cells:C,activeSessions:J,nodeGroups:B,token:t,onPeekOpen:()=>fn(!1),overlayOpen:jt,fleetCapabilities:I,fleetStale:W,fleetOff:K,bootSettlement:ee,onBootSettlementApplied:Et,localNodeId:D.localNodeId,hostByRoute:pt,onDesignateCell:bt,onClearHostCell:$t,onPick:L,onAddTile:Ee,onPower:ie,onBoot:Te,onBootError:de=>D.setError(String((de==null?void 0:de.message)||de)),onNodePower:X,onNodeRename:oe,onKill:We,onVisibility:ze,onNew:()=>se("fleet",!0),onSettings:se,onOpenVlSession:j,width:Ye,collapsed:Ct,onResize:ht,onToggleCollapse:()=>hn(de=>!de)}),l.jsxs("div",{className:"nc-workspace-main",children:[l.jsx(J2,{decks:O,currentDeck:v,onCreate:je,onRename:Me,onDelete:Je,onReorder:D.reorder,onOpenWindow:we,onNavigate:De,saveState:D.saveState,error:D.error,sidebarVisible:xt,onToggleSidebar:b?null:()=>Ne(de=>!de)}),l.jsx(k2,{layout:Z,onLayoutChange:U,token:t,readonly:re,sessionsAlive:Ze,focusSession:$,onFocus:R,onOpenSingle:L,decks:O,currentDeck:v,onSendToDeck:Pe,cells:C,nodeGroups:B,panelPort:_e,nodePanelPorts:xe})]}),T&&l.jsx("div",{className:"nc-single-overlay",children:l.jsx(jy,{peer:T,token:t,onBack:()=>j(null)})}),z&&l.jsx("div",{className:"nc-single-overlay",children:l.jsx(Ay,{session:z.session,node:z.node,ownerId:z.ownerId,cellName:op({session:z.session,node:z.node,ownerId:z.ownerId,cells:C,nodeGroups:B}),token:t,readonly:re,panelPort:Sc(z.node?z.node.split("/"):[],xe,_e),onBack:()=>F(null)})}),H&&l.jsx(cc,{cell:H,token:t,route:Array.isArray(H.route)?H.route:[],onConfirm:ct,onClose:()=>ie(null)}),Ie]})}function MP(){Vn();const e=x.useSyncExternalStore(wP,Ry,Ry);if(!e.needed)return null;const t=e.kind==="install"?f("install-version-mismatch").replace("{v}",e.version):f("update-available").replace("{v}",e.version).replace(" "," ").trim();return l.jsxs("div",{className:"nc-update",role:"status","aria-live":"polite",children:[l.jsx("span",{className:"nc-update-msg",children:t}),e.kind==="reload"&&l.jsx("button",{className:"nc-update-btn",onClick:mS,children:f("reload")})]})}CP();ix.createRoot(document.getElementById("root")).render(l.jsxs(X0.StrictMode,{children:[l.jsx(AP,{}),l.jsx(MP,{})]}));
@@ -11,7 +11,7 @@
11
11
  <meta name="apple-mobile-web-app-title" content="NexusCrew" />
12
12
  <link rel="manifest" href="/manifest.json" />
13
13
  <title>NexusCrew</title>
14
- <script type="module" crossorigin src="/assets/index-DKu9YXqO.js"></script>
14
+ <script type="module" crossorigin src="/assets/index-CBoobbt_.js"></script>
15
15
  <link rel="stylesheet" crossorigin href="/assets/index-CWMKoCx-.css">
16
16
  </head>
17
17
  <body>
@@ -1 +1 @@
1
- {"version":"0.9.10"}
1
+ {"version":"0.9.12"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmmbuto/nexuscrew",
3
- "version": "0.9.11",
3
+ "version": "0.9.12",
4
4
  "description": "Faithful browser tmux client — attach to live sessions over a real PTY, localhost-only, mobile-easy",
5
5
  "main": "lib/server.js",
6
6
  "bin": {