@mmmbuto/nexuscrew 0.9.20 → 0.9.22
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 +33 -0
- package/frontend/dist/assets/{index-VdGL6XJ8.js → index-D5snoCdN.js} +1 -1
- package/frontend/dist/index.html +1 -1
- package/frontend/dist/version.json +1 -1
- package/lib/audio/routes.js +27 -0
- package/lib/cells/routes.js +30 -2
- package/lib/cli/commands.js +11 -1
- package/lib/files/routes.js +31 -4
- package/lib/fleet/builtin.js +26 -4
- package/lib/fleet/cell-exec.js +251 -7
- package/lib/fleet/cell-lease-server.js +161 -6
- package/lib/fleet/definitions.js +16 -1
- package/lib/fleet/identity-authority.js +367 -0
- package/lib/fleet/identity-transport.js +68 -0
- package/lib/fleet/launch-broker.js +26 -1
- package/lib/fleet/lease-client.js +168 -1
- package/lib/fleet/lease-routes.js +96 -24
- package/lib/fleet/managed.js +52 -3
- package/lib/fleet/runtime.js +24 -1
- package/lib/identity/binding-guard.js +128 -0
- package/lib/live-host/bridge.js +69 -0
- package/lib/live-host/routes.js +9 -5
- package/lib/mcp/identity-provider.js +132 -0
- package/lib/mcp/identity-schema.js +168 -0
- package/lib/mcp/server.js +123 -6
- package/lib/mcp/tools.js +38 -6
- package/lib/notify/asks.js +1 -0
- package/lib/notify/routes.js +29 -1
- package/lib/server.js +24 -4
- package/package.json +1 -3
- package/docs/img/fleet-deck-desktop.png +0 -0
- package/docs/img/session-mobile.png +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to NexusCrew are tracked here.
|
|
4
4
|
|
|
5
|
+
## 0.9.22 — 2026-09-11
|
|
6
|
+
|
|
7
|
+
- **Fleet Ollama Cloud: `deepseek-v4.1-flash`** aggiunto ai modelli dell'engine
|
|
8
|
+
(contesto dichiarato 1M → 1048576; capacità text+image, reasoning; parallel
|
|
9
|
+
tool calls non dichiarato finché non misurato su device) e promosso a
|
|
10
|
+
**modello di default dei tre engine ollama-cloud** (`claude`, `codex-vl`,
|
|
11
|
+
`codex`), al posto di `glm-5.2` (che resta disponibile in lista).
|
|
12
|
+
- Il tarball npm non include più gli screenshot di `docs/img/` (restano nel
|
|
13
|
+
repository GitHub, referenziati dal README): il pacchetto 0.9.21 li
|
|
14
|
+
spediva per errore mostrando nomi di ambiente interno.
|
|
15
|
+
- **Fleet codex-vl app-server identity policy.** Managed `codex-vl.*` cells now
|
|
16
|
+
pass `CODEX_APP_SERVER_IDENTITY_REQUIRED=1` through the child environment so
|
|
17
|
+
the app-server daemon started by the TUI enforces the Fleet identity policy;
|
|
18
|
+
an explicit per-engine override remains authoritative.
|
|
19
|
+
|
|
20
|
+
## 0.9.21 — 2026-09-10
|
|
21
|
+
|
|
22
|
+
- **Identity channel generation gate is fail-closed.** The per-cell supervisor
|
|
23
|
+
now inspects the resolved generation announcement before opening the identity
|
|
24
|
+
channel of a new generation: only an explicit positive acknowledgement for
|
|
25
|
+
the matching generation opens it. Refused, failed, timed-out or exited
|
|
26
|
+
announcements keep the channel closed with a specific diagnostic, so a child
|
|
27
|
+
can no longer receive identity proofs after a failed announcement.
|
|
28
|
+
|
|
29
|
+
- **Catalog update.** Declare kimi-k3 in the ollama-cloud catalog
|
|
30
|
+
(`openrouter-kimi-k3.json`, `managed.js`), so cells on the ollama-cloud
|
|
31
|
+
engine resolve the model with the right context window and metadata
|
|
32
|
+
instead of falling back to defaults.
|
|
33
|
+
|
|
34
|
+
- **Ollama Cloud web_search disabled.** Disable the built-in web_search tool
|
|
35
|
+
for Codex/Codex-VL on Ollama Cloud (the Responses endpoint rejects it before
|
|
36
|
+
the first turn); MCP web search stays available.
|
|
37
|
+
|
|
5
38
|
## 0.9.20 — 2026-09-06
|
|
6
39
|
|
|
7
40
|
- **Each cell derives its own MCP device.** `MCP_DEVICE` is set from the cell
|
|
@@ -90,4 +90,4 @@ Minimum version required to store current data is: `+F+`.
|
|
|
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]))),Ry(s,e,t)}function Us({children:e,onClose:t,label:n,error:s=""}){const o=k.useRef(null),a=k.useRef(null),u=k.useRef(t);return u.current=t,k.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 S;if(b.key==="Escape"){b.preventDefault(),(S=u.current)==null||S.call(u);return}if(b.key!=="Tab")return;const w=m();if(!w.length){b.preventDefault(),p==null||p.focus();return}const x=w[0],N=w[w.length-1];b.shiftKey&&document.activeElement===x?(b.preventDefault(),N.focus()):!b.shiftKey&&document.activeElement===N&&(b.preventDefault(),x.focus())};return document.addEventListener("keydown",y),()=>{cancelAnimationFrame(v),document.removeEventListener("keydown",y),d&&d.isConnected&&typeof d.focus=="function"&&d.focus({preventScroll:!0})}},[]),k.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 fh({token:e,targets:t=[],readonly:n=!1,onPower:s,onImport:o}){const[a,u]=k.useState([]),[d,p]=k.useState(0);k.useEffect(()=>{let S=!0;async function E(){const A=[{route:[],label:f("local")}].concat((t||[]).map(V=>({route:Array.isArray(V.route)?V.route:[],label:V.label||(V.route||[]).join(" › ")}))),I=await Promise.all(A.map(async V=>{const W={...V,available:!1,readonly:!1,capabilities:[],provider:null,cells:[],unmanaged:[],err:""};try{const X=await Qs(e,V.route);W.available=!!X.available,W.capabilities=X.capabilities||[],W.provider=X.provider||null,W.cells=(X.cells||[]).map(Z=>({...Z,route:V.route}));try{W.readonly=!!(await Of(e,V.route)).readonlyDefault}catch{}try{const Z=await If(e,V.route),K=new Set(W.cells.map(G=>G.tmuxSession).filter(Boolean));W.unmanaged=(Z.sessions||[]).filter(G=>G&&!K.has(G.name))}catch{}}catch(X){W.err=String(X&&X.message||X)}return W}));S&&u(I)}E();const C=setInterval(E,6e3);return()=>{S=!1,clearInterval(C)}},[e,t,d]);const m=(S,E)=>Array.isArray(S.capabilities)&&S.capabilities.includes(E)&&!n&&!S.readonly,v=()=>p(S=>S+1),y=(S,E)=>{s&&s({...S,route:E})},b=(S,E)=>{s&&s({...S,route:E})},w=async(S,E)=>{try{await pa(e,S.cell,E)}catch{}v()},x=async(S,E)=>{if(window.confirm(f("fleet-remove-cell").replace("{id}",S.cell))){try{await qy(e,S.cell,!0,E)}catch{}v()}},N=async(S,E)=>{if(window.confirm(f("terminate-confirm").replace("{name}",S.name))){try{await Mf(e,S.name,E)}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(S=>{const E=S.route.length?S.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 ${S.available?"on":"warn"}`}),l.jsx("b",{children:S.label}),l.jsx("small",{children:S.available?`${S.cells.length} ${f("fleet-cells")} · ${S.unmanaged.length} ${f("fleet-tmux")}`:S.err||f("fleet-not-available")})]}),S.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(S,"down")&&l.jsx("button",{className:"nc-btn ghost",title:f("power-off"),onClick:()=>b(C,S.route),children:f("stop")}),!C.active&&m(S,"up")&&l.jsx("button",{className:"nc-btn ghost",title:f("power-on"),onClick:()=>y(C,S.route),children:f("start")}),m(S,"restart")&&C.active&&l.jsx("button",{className:"nc-btn ghost",title:f("restart"),onClick:()=>w(C,S.route),children:f("restart")}),m(S,"remove")&&l.jsx("button",{className:"nc-btn danger",title:f("delete"),onClick:()=>x(C,S.route),children:"×"})]})]},`${E}:${C.cell}`)),S.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(S,"import")&&o&&l.jsx("button",{className:"nc-btn ghost",title:f("import-as-cell"),onClick:()=>o(C,S.route),children:f("import-as-cell")}),l.jsx("button",{className:"nc-btn danger",title:f("terminate"),onClick:()=>N(C,S.route),children:"×"})]})]},`${E}:u:${C.name}`)),S.available&&S.cells.length===0&&S.unmanaged.length===0&&l.jsx("div",{className:"nc-empty",children:f("fleet-inventory-empty")})]},E)})]})}function DR({cells:e=[],engines:t=[],models:n=[],busy:s,canRestore:o=!1,onRestore:a,onClose:u}){const[d,p]=k.useState("export"),[m,v]=k.useState([]),[y,b]=k.useState(()=>new Set(e.map(L=>L.id))),[w,x]=k.useState(()=>new Set(t.map(L=>L.id))),[N,S]=k.useState([]),[E,C]=k.useState([]),[A,I]=k.useState(""),V=new Set(t.map(L=>L.id)),W=new Set(e.map(L=>L.id)),X=(L,T)=>L(j=>{const z=new Set(j);return z.has(T)?z.delete(T):z.add(T),z}),Z=()=>{const L=jR(e,y,t,w,new Date,n);if(L.ok===!1){I(f(`fleet-backup-${L.error}`));return}const T=e.filter($=>y.has($.id)).length,j=t.filter($=>w.has($.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 z=new Blob([`${JSON.stringify(L,null,2)}
|
|
91
91
|
`],{type:"application/json"}),M=URL.createObjectURL(z),D=document.createElement("a");D.href=M,D.download=`nexuscrew-fleet-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild(D),D.click(),D.remove(),setTimeout(()=>URL.revokeObjectURL(M),0),I("")},K=async L=>{if(I(""),S([]),C([]),!!L){if(L.size>1024*1024){I(f("fleet-backup-too-large"));return}try{const T=RR(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(z=>z.id));C(T.engines.map(z=>({engine:z,exists:V.has(z.id),selected:!V.has(z.id)}))),S(T.cells.map(z=>{const M=V.has(z.engine)||j.has(z.engine),D=W.has(z.id);return{cell:z,engine:M?z.engine:"",selected:M&&!D,exists:D}}))}catch(T){I(String(T.message||T))}}},G=(L,T)=>S(j=>j.map((z,M)=>M===L?{...z,...T}:z)),F=(L,T)=>C(j=>j.map((z,M)=>M===L?{...z,...T}:z)),O=new Set([...V,...E.filter(L=>L.selected).map(L=>L.engine.id)]),R=N.filter(L=>L.selected&&L.engine&&O.has(L.engine)),B=E.filter(L=>L.selected),H=[...new Map([...t.map(L=>[L.id,L.label||L.id]),...E.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))),x(new Set(t.map(L=>L.id)))},children:f("select-all")}),l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:()=>{b(new Set),x(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:w.has(L.id),onChange:()=>X(x,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:()=>X(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&&!w.size,onClick:Z,children:f("fleet-backup-download")})]})]}):l.jsxs(l.Fragment,{children:[l.jsx("input",{type:"file",accept:"application/json,.json",disabled:s,onChange:L=>K(L.target.files&&L.target.files[0])}),l.jsx("small",{children:f("fleet-backup-import-help")}),!!(N.length||E.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}))),S(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}))),S(L=>L.map(T=>({...T,selected:!1})))},children:f("select-none")})]}),l.jsxs("div",{className:"nc-backup-list",children:[!!E.length&&l.jsx("b",{children:f("fleet-engines")}),E.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:z=>F(T,{selected:z.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)}),!!N.length&&l.jsx("b",{children:f("fleet-cells")}),N.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||!O.has(L.engine),onChange:j=>G(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=>G(T,{engine:j.target.value,selected:!!j.target.value}),children:[l.jsx("option",{value:"",children:f("fleet-backup-engine-missing")}),H.map(([j,z])=>l.jsx("option",{value:j,children:z},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&&!B.length,onClick:()=>a({engineRows:E,cellRows:N,models:m}),children:f("fleet-backup-restore")})]})]}),A&&l.jsx("div",{className:"nc-err",children:A})]})}function IR({state:e,setState:t,busy:n,onSave:s,catalog:o}){var E;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=Ra(o,a),y=typeof(v==null?void 0:v.credentialEnv)=="string"?v.credentialEnv:"",b=Array.isArray(v==null?void 0:v.credentialUsedBy)?v.credentialUsedBy:[],w=(v==null?void 0:v.credentialSource)||"missing",x=!!(v!=null&&v.credentialEnv)||a.credentialProfile==="a"||a.credentialProfile==="p",N=!!y&&e.mode==="new"&&(v==null?void 0:v.authConfigured)!==!0&&!a.credentialValue&&!a.allowMissingCredential,S=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=>S(o.find(A=>A.client===C.target.value&&A.default)||o.find(A=>A.client===C.target.value)),children:p.map(([C,A])=>l.jsx("option",{value:C,children:A},C))}),l.jsx("select",{value:((E=Ra(o,a))==null?void 0:E.id)||"",disabled:e.mode!=="new",onChange:C=>S(o.find(A=>A.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,A,I)=>C&&I.indexOf(C)===A).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")}),x&&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-${w}`)})]}),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,A)=>l.jsxs("div",{className:"nc-fleet-env",children:[l.jsx("input",{value:C.key,disabled:C.configured,placeholder:"ENV_KEY",onChange:I=>{const V=d.slice();V[A]={...C,key:I.target.value},u({envRows:V})}}),l.jsx("input",{type:"password",value:C.value,placeholder:C.configured?"•••••• (unchanged)":"value",onChange:I=>{const V=d.slice();V[A]={...C,value:I.target.value},u({envRows:V})}}),l.jsx("button",{className:"nc-btn danger",onClick:()=>u({envRows:d.filter((I,V)=>V!==A)}),children:"×"})]},`${C.key}-${A}`)),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&&!Cp(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||N||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 OR({state:e,setState:t,busy:n,onSave:s,onTest:o,profiles:a=[],canTest:u=!0}){const[d,p]=k.useState(null),[m,v]=k.useState(!1),y=e.form,b=S=>t({...e,form:{...y,...S}}),w=/^[^\x00-\x1f\x7f]{1,128}$/.test(y.id||""),x=!!(y.id||"").trim()&&!!(y.engine||"").trim()&&w,N=async()=>{p(null),v(!0);try{p(await o(y.engine,y.id))}catch(S){p({outcome:"unverified",detail:String(S&&S.message||S)})}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:S=>{p(null),b({engine:S.target.value})},children:[l.jsx("option",{value:"",children:"—"}),a.map(S=>l.jsx("option",{value:S.id,children:S.label?`${S.id} · ${S.label}`:S.id},S.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:S=>{p(null),b({id:S.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:S=>b({contextWindow:S.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:S=>b({maxTokens:S.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:S=>b({reasoning:S.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||!x,onClick:N,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||!x,onClick:()=>s(y),children:f("save")})]})]})}function BR({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 B,H,L;const[b,w]=k.useState(null),[x,N]=k.useState(""),S=a.form,E=T=>u({...a,form:{...S,...T}}),C=d.find(T=>T.id===S.engine),A=((B=C==null?void 0:C.managed)==null?void 0:B.client)==="shell",I=((H=C==null?void 0:C.managed)==null?void 0:H.client)||"",V=((L=m.find(T=>T.client===I))==null?void 0:L.mcpManaged)!==!1,W=T=>{var M,D,$,U;const j=d.find(se=>se.id===T),z={...S.commands||{}};((M=C==null?void 0:C.managed)==null?void 0:M.client)==="shell"&&(S.command?z[S.engine]=S.command:delete z[S.engine]),E({engine:T,model:((D=S.models)==null?void 0:D[T])||(($=j==null?void 0:j.managed)==null?void 0:$.model)||((U=j==null?void 0:j.model)==null?void 0:U.value)||"",commands:z,command:z[T]||""})},X=T=>{const j={...S.commands||{}};T?j[S.engine]=T:delete j[S.engine],E({command:T,commands:j})},Z=A&&/[|&;<>()`$*?{}\[\]~]/.test(S.command||""),K=[...new Set([...p||[],...Array.isArray(S.mcp)?S.mcp:[]])].sort(),G=Array.isArray(S.mcp)?S.mcp.length?"some":"none":"all",F=T=>{var j;return E({mcp:T==="all"?void 0:T==="none"?[]:(j=S.mcp)!=null&&j.length?S.mcp:[...K]})},O=T=>{const j=Array.isArray(S.mcp)?S.mcp:[];E({mcp:j.includes(T)?j.filter(z=>z!==T):[...j,T].sort()})},R=async T=>{try{const j=await Df(e,T,t);w(j),E({cwd:j.path}),N("")}catch(j){N(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")} ${S.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),E({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:S.id,disabled:a.mode!=="new",placeholder:"id",onChange:T=>E({id:T.target.value})}),l.jsx("input",{value:S.label||"",maxLength:64,placeholder:f("fleet-cell-label"),onChange:T=>E({label:T.target.value})}),l.jsxs("div",{className:"nc-fleet-pair",children:[l.jsx("input",{value:S.cwd,placeholder:f("cwd"),onChange:T=>E({cwd:T.target.value})}),l.jsx("button",{className:"nc-btn ghost",onClick:()=>b?w(null):R(S.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))]})]}),x&&l.jsx("div",{className:"nc-err",children:x}),l.jsx("select",{value:S.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:!!S.boot,onChange:T=>E({boot:T.target.checked})})," ",f("fleet-boot")]}),l.jsx("input",{value:S.panelUrl||"",maxLength:512,placeholder:f("fleet-panel-url"),onChange:T=>E({panelUrl:T.target.value})}),l.jsx("small",{children:f("fleet-panel-url-help")}),S.panelUrl&&!Cp(S.panelUrl)&&l.jsx("small",{className:"nc-err",children:f("fleet-panel-url-invalid")}),A?l.jsxs(l.Fragment,{children:[l.jsx("input",{value:S.command||"",maxLength:4096,placeholder:f("fleet-shell-command-placeholder"),onChange:T=>X(T.target.value)}),l.jsx("small",{children:S.command?f("fleet-shell-command-help"):f("fleet-shell-interactive")}),Z&&l.jsx("small",{className:"nc-note",children:f("fleet-shell-command-metachar")})]}):l.jsxs(l.Fragment,{children:[l.jsx("input",{value:S.model||"",list:"nc-cell-models",placeholder:f("fleet-model-override"),onChange:T=>E({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:S.prompt||"",placeholder:f("cell-prompt"),onChange:T=>E({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:G,onChange:T=>F(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")})]})]}),!V&&l.jsx("small",{className:"nc-note",children:f("cell-mcp-inert")}),G==="some"&&l.jsx("div",{className:"nc-fleet-mcp-list",children:K.map(T=>l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:(S.mcp||[]).includes(T),onChange:()=>O(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||!S.id||!S.cwd||!S.engine,onClick:y,children:f("save")})]})]})}function Py({token:e,route:t=[],state:n,setState:s,busy:o,onSave:a}){const[u,d]=k.useState(null),[p,m]=k.useState([]),[v,y]=k.useState(""),b=Array.isArray(t)?t.join("/"):"";k.useEffect(()=>{let E=!0;return jc(e,b?b.split("/"):[]).then(C=>{E&&(m(C.engines||[]),y(""))}).catch(C=>{E&&(m([]),y(String(C.message||C)))}),()=>{E=!1}},[e,b]);const w=n.form,x=E=>s({...n,form:{...w,...E}}),N=async E=>{try{const C=await Df(e,E,t);d(C),x({cwd:C.path})}catch{}},S=!w.id&&w.tmuxSession?w.tmuxSession.replace(/[^A-Za-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,32):w.id;return l.jsxs("div",{className:"nc-set-form nc-fleet-form",children:[l.jsxs("b",{children:[f("import-as-cell")," · ",w.tmuxSession]}),l.jsx("small",{children:f("import-help")}),l.jsx("input",{value:w.tmuxSession,disabled:!0,placeholder:"tmux session",readOnly:!0}),l.jsx("input",{value:w.id,placeholder:f("name"),onChange:E=>x({id:E.target.value})}),l.jsxs("div",{className:"nc-fleet-pair",children:[l.jsx("input",{value:w.cwd,placeholder:f("cwd"),onChange:E=>x({cwd:E.target.value})}),l.jsx("button",{className:"nc-btn ghost",type:"button",onClick:()=>u?d(null):N(w.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:()=>N(u.parent),children:["↑ ",f("fs-parent")]}),(u.dirs||[]).map(E=>l.jsxs("button",{className:"nc-fs-item",onClick:()=>N(`${u.path.replace(/\/$/,"")}/${E}`),children:["📁 ",E]},E))]})]}),l.jsxs("select",{value:w.engine,onChange:E=>x({engine:E.target.value}),children:[l.jsx("option",{value:"",children:f("import-engine-required")}),p.map(E=>l.jsx("option",{value:E.id,children:E.label},E.id))]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:!!w.boot,onChange:E=>x({boot:E.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||!w.tmuxSession||!w.engine||!p.length,onClick:a,children:f(S?"import-as-cell":"save")})]})]})}function ec(e){const t=wr(e);return t===null?`~/${e}`:t?`~/${t}`:"~"}function zR(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 $R({token:e,route:t,cell:n,busy:s=!1,onSaved:o,onClose:a}){const[u,d]=k.useState(""),[p,m]=k.useState(null),[v,y]=k.useState(!1),[b,w]=k.useState(""),x=typeof(n==null?void 0:n.cwdSuggestion)=="string"&&wr(n.cwdSuggestion)!==null?wr(n.cwdSuggestion):null,[N,S]=k.useState(x),E=n==null?void 0:n.id,C=s||v,A=async K=>{const G=wr(K);if(G===null){m({rel:"",dirs:[],loading:!1,err:f("fleet-cwd-repair-invalid")});return}m({rel:G,dirs:[],loading:!0,err:""});try{const F=await Df(e,G,t),O=zR(F);m({rel:O,dirs:Array.isArray(F.dirs)?F.dirs:[],loading:!1,err:""})}catch(F){m({rel:G,dirs:[],loading:!1,err:String(F&&F.message||F)})}},I=K=>{if(!p)return;const G=p.rel?`${p.rel}/${K}`:K;A(G)},V=()=>{p!=null&&p.rel&&A(p.rel.split("/").slice(0,-1).join("/"))},W=()=>{p&&(d(p.rel||""),m(null),w(""),S(null))},X=()=>{N!==null&&(d(N),S(null),w(""))},Z=async()=>{if(C)return;const K=wr(u);if(K===null){w(f("fleet-cwd-repair-invalid"));return}const G=ec(K);let F=!0;try{F=window.confirm(f("fleet-cwd-repair-confirm").replace("{id}",String(E||"")).replace("{path}",G))}catch{F=!1}if(F){y(!0),w(""),S(null);try{const O=await Ky(e,E,{cwdRel:K},t);o==null||o(O)}catch(O){const R=O&&O.data||{};if(R.code==="unportable-cwd"){w(f("fleet-cwd-repair-unportable"));const B=Array.isArray(R.cells)?R.cells.find(L=>L&&L.id===E):null,H=B&&typeof B.suggestion=="string"?B.suggestion:null;H!==null&&wr(H)!==null&&S(H)}else w(String(O&&O.message||O))}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(E||""))}),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:K=>d(K.target.value)}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:C,onClick:()=>p?m(null):A(""),children:f(p?"close":"fleet-cwd-repair-browse")})]})]}),l.jsx("div",{className:"nc-cwd-preview",children:f("fleet-cwd-repair-preview").replace("{path}",ec(u))}),p&&l.jsxs("div",{className:"nc-fs",children:[l.jsx("div",{className:"nc-fs-path",children:ec(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:V,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(K=>l.jsxs("button",{type:"button",className:"nc-fs-item",onClick:()=>I(K),children:["📁 ",K]},K))]}),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}),N!==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:X,children:f("fleet-cwd-repair-use-suggestion").replace("{path}",ec(N))})]}),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:Z,children:v?"…":f("save")})]})]})}function FR({token:e,readonly:t,targets:n=[],startNewCell:s=!1,initialLocation:o=""}){const[a,u]=k.useState({engines:[],cells:[],managedCatalog:[]}),[d,p]=k.useState({available:!1,capabilities:[]}),[m,v]=k.useState(!1),[y,b]=k.useState(null),[w,x]=k.useState(null),[N,S]=k.useState({}),[E,C]=k.useState(null),[A,I]=k.useState(!1),[V,W]=k.useState(""),[X,Z]=k.useState(""),[K,G]=k.useState(o),[F,O]=k.useState(!1),[R,B]=k.useState(null),[H,L]=k.useState(null),[T,j]=k.useState(null),[z,M]=k.useState(!1),[D,$]=k.useState([]),[U,se]=k.useState(null),[ce,oe]=k.useState("manage"),pe=k.useRef(!1),he=K?K.split("/"):[],me=k.useCallback(async()=>{try{const re=await Qs(e,he);p(re);try{const ne=await Of(e,he);O(!!ne.readonlyDefault)}catch{O(!1)}if(re.provider==="builtin"&&(re.capabilities||[]).includes("definitions")){const ne=await jc(e,he),_e=new Map((re.engines||[]).map(be=>[be.id,be]));if(ne.engines=(ne.engines||[]).map(be=>{var ke;return{...be,availableModels:((ke=_e.get(be.id))==null?void 0:ke.models)||[]}}),u(ne),(re.capabilities||[]).includes("credentials"))try{$((await mx(e,he)).credentials||[])}catch{$([])}else $([])}W("")}catch(re){W(String(re.message||re))}finally{v(!0)}},[e,K]);k.useEffect(()=>{me();const re=setInterval(me,5e3);return()=>clearInterval(re)},[me]);const Ve=new Set((d.cells||[]).filter(re=>re.active).map(re=>re.cell)),ut=d.provider==="builtin"&&(d.capabilities||[]).includes("edit"),_t=(d.capabilities||[]).includes("restore");k.useEffect(()=>{!s||pe.current||!ut||!a.engines.length||(pe.current=!0,C({mode:"new",form:jy(a.engines[0].id)}))},[s,ut,a.engines]);const je=async re=>{I(!0),W(""),Z("");try{await re(),await me()}catch(ne){W(String(ne.message||ne))}I(!1)},Ct=async(re,ne)=>{const _e=await Sx(e,re,ne,he);return S(be=>({...be,[`${re}::${ne}`]:_e})),_e},hn=re=>je(async()=>{const ne={id:String(re.id||"").trim(),engine:String(re.engine||"").trim()};for(const _e of["contextWindow","maxTokens"]){const be=String(re[_e]||"").trim();be&&(ne[_e]=Number(be))}re.reasoning===!0&&(ne.reasoning=!0),await bx(e,ne,he),x(null),await me()}),_n=()=>je(async()=>{var zt;const re=y.mode==="new",ne=y.form,_e=a.managedCatalog||[],be=ne.kind==="managed"?Ra(_e,ne):null,ke=typeof(be==null?void 0:be.credentialEnv)=="string"?be.credentialEnv:"",it=ke&&ne.credentialValue||"",ht=MR(ne,re,_e);!re&&y.form.kind==="custom"&&!y.form.modelFlag&&(ht.model=null),!re&&y.form.kind==="custom"&&y.form.promptMode!=="flag"&&(ht.promptFlag=null);let dt;if(re)dt=await vx(e,ht,he);else{const Ze=y.original,Q=new Set(y.form.envRows.filter(Oe=>!Oe.remove).map(Oe=>Oe.key)),Ne=(Ze.envKeys||[]).filter(Oe=>!Q.has(Oe)),Ue=Object.fromEntries(y.form.envRows.filter(Oe=>!Oe.remove&&Oe.key&&(!Oe.configured||Oe.value!=="")).map(Oe=>[Oe.key,Oe.value]));dt=await _x(e,Ze.id,ht,y.form.kind==="custom"?{set:Ue,remove:Ne}:void 0,he)}let Pt=null;if(ke&&it)try{Pt=await tv(e,ke,it,he),$(Pt.credentials||[])}catch{throw await me(),re&&b({mode:"edit",original:{...ht,id:ne.id},form:{...ne,credentialReveal:!1}}),new Error(f(re?"fleet-key-partial-create":"fleet-key-partial-edit"))}await me(),b(null),Z(f("fleet-saved"));const St=((zt=((Pt==null?void 0:Pt.credentials)||[]).find(Ze=>Ze.envKey===ke))==null?void 0:zt.activeCells)||[],yt=[...new Set([...(dt==null?void 0:dt.activeCells)||[],...St])];if(yt.length&&window.confirm(f("fleet-restart-confirm").replace("{cells}",yt.join(", "))))for(const Ze of yt)await pa(e,Ze,he)}),Yt=()=>je(async()=>{var St,yt,zt,Ze,Q,Ne;const re=E.mode==="new",ne=E.form,_e={...re?{id:ne.id}:{},cwd:ne.cwd,engine:ne.engine,boot:!!ne.boot},be={...ne.commands||{}},ke=a.engines.find(Ue=>Ue.id===ne.engine);((St=ke==null?void 0:ke.managed)==null?void 0:St.client)==="shell"&&typeof ne.command=="string"&&ne.command.length?be[ne.engine]=ne.command:((yt=ke==null?void 0:ke.managed)==null?void 0:yt.client)==="shell"&&delete be[ne.engine],(Object.keys(be).length||!re)&&(_e.commands=be);const it=(ne.label||"").trim();re?it&&(_e.label=it):_e.label=it||null;const ht=(ne.panelUrl||"").trim();re?ht&&(_e.panelUrl=ht):_e.panelUrl=ht||null,re?Array.isArray(ne.mcp)&&(_e.mcp=ne.mcp):_e.mcp=Array.isArray(ne.mcp)?ne.mcp:null,re?(((zt=ke==null?void 0:ke.managed)==null?void 0:zt.client)!=="shell"&&ne.model&&(_e.model=ne.model),((Ze=ke==null?void 0:ke.managed)==null?void 0:Ze.client)!=="shell"&&ne.prompt&&(_e.prompt=ne.prompt)):(_e.model=((Q=ke==null?void 0:ke.managed)==null?void 0:Q.client)==="shell"?null:ne.model||null,((Ne=ke==null?void 0:ke.managed)==null?void 0:Ne.client)!=="shell"&&(_e.prompt=ne.prompt||null));const dt=re?await xx(e,_e,he):await Ky(e,E.original.id,_e,he),Pt=re?ne.id:E.original.id;C(null),Z(f("fleet-saved")),!re&&(dt!=null&&dt.active)&&window.confirm(f("fleet-restart-confirm").replace("{cells}",Pt))&&await pa(e,Pt,he)}),xt=t||F,Ot=d.capabilities||[],Ut=he.length>0&&xt,jt=re=>D.find(ne=>{var _e;return(_e=ne.engines)==null?void 0:_e.includes(re.id)})||null,It=()=>je(async()=>{var _e;const re=await tv(e,U.envKey,U.value,he);$(re.credentials||[]),se(null),Z(f("fleet-credential-saved"));const ne=((_e=(re.credentials||[]).find(be=>be.envKey===U.envKey))==null?void 0:_e.activeCells)||[];if(ne.length&&window.confirm(f("fleet-restart-confirm").replace("{cells}",ne.join(", "))))for(const be of ne)await pa(e,be,he)}),Mt=re=>je(async()=>{if(!window.confirm(f("fleet-credential-remove-confirm").replace("{key}",re.envKey)))return;const ne=await gx(e,re.envKey,he);$(ne.credentials||[]),Z(f("fleet-credential-removed"))}),Rt=re=>B({...re,route:Array.isArray(re==null?void 0:re.route)?re.route:he}),fn=async re=>{if(!R)return;const ne=R.cell||R.id,_e=Array.isArray(R.route)?R.route:he;if(re.action==="up"){const be=await Tf(e,{cell:ne,boot:!!re.boot,...re.engine?{engine:re.engine}:{},...re.model!==void 0?{model:re.model}:{},...re.permissionPolicy?{permissionPolicy:re.permissionPolicy}:{}},_e),ke=Gf(be);ke&&Z(ke.text)}else await uc(e,{cell:ne,boot:!!re.boot},_e)},ie=(re,ne)=>{W(""),L({mode:"new",route:Array.isArray(ne)?ne:he,form:{tmuxSession:re.name,id:"",engine:"",cwd:"",boot:!1},err:""})},Qe=()=>je(async()=>{const re=H.form;if(!re.engine){L({...H,err:f("import-engine-required")});return}await kx(e,{tmuxSession:re.tmuxSession,id:re.id||void 0,engine:re.engine,cwd:re.cwd||void 0,boot:!!re.boot},re.route||he),L(null),Z(f("fleet-saved"))}),ge=({engineRows:re=[],cellRows:ne=[],models:_e=[]})=>je(async()=>{const be=re.filter(Ze=>Ze.selected),ke=be.map(Ze=>hS(Ze.engine));if(ke.some(Ze=>!Ze))throw new Error(f("fleet-backup-invalid-engine"));const it=be.filter(Ze=>Ze.exists).map(Ze=>Ze.engine.id);if(it.length&&!window.confirm(f("fleet-backup-confirm-engine-overwrite").replace("{engines}",it.join(", "))))return;const ht=[...new Set([...a.engines.map(Ze=>Ze.id),...ke.map(Ze=>Ze.id)])],dt=[];for(const Ze of ne.filter(Q=>Q.selected)){const Q=PR(Ze.cell,Ze.engine,ht);if(!Q)throw new Error(`${Ze.cell.id}: ${f("fleet-backup-engine-missing")}`);dt.push(Q)}const Pt=ne.filter(Ze=>Ze.selected&&Ze.exists).map(Ze=>Ze.cell.id);if(Pt.length&&!window.confirm(f("fleet-backup-confirm-overwrite").replace("{cells}",Pt.join(", "))))return;const St=ke.length?await Ex(e,ke,it.length>0,he,_e):{needsRestart:[]},yt=dt.length?await Cx(e,dt,he):{needsRestart:[]},zt=[...new Set([...St.needsRestart||[],...yt.needsRestart||[]])];M(!1),Z(`${f("fleet-backup-restored").replace("{n}",String(dt.length))}${ke.length?` · ${ke.length} ${f("fleet-engines").toLowerCase()}`:""}${zt.length?` · ${f("fleet-backup-needs-restart").replace("{cells}",zt.join(", "))}`:""}`)}),Ge=l.jsxs("label",{className:"nc-field",children:[f("location"),l.jsxs("select",{value:K,onChange:re=>{G(re.target.value),b(null),C(null),W(""),Z(""),O(!1),v(!1),p({available:!1,capabilities:[]}),u({engines:[],cells:[],managedCatalog:[]}),$([]),se(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("/")))]})]}),ct=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":ce==="manage",className:`nc-set-tabbtn${ce==="manage"?" on":""}`,onClick:()=>oe("manage"),children:f("fleet-manage-location")}),l.jsx("button",{type:"button",role:"tab","aria-selected":ce==="overview",className:`nc-set-tabbtn${ce==="overview"?" on":""}`,onClick:()=>oe("overview"),children:f("fleet-network-overview")})]});return m?ut?l.jsxs("div",{className:"nc-set-tab nc-fleet-editor",children:[ct,ce==="overview"?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-set-info",children:f("fleet-overview-help")}),l.jsx(fh,{token:e,targets:n,readonly:t,onPower:Rt,onImport:ie})]}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-set-info",children:f("fleet-manage-help")}),Ge,l.jsxs("div",{className:"nc-set-row nc-fleet-backup-actions",children:[l.jsx("button",{className:"nc-btn ghost",disabled:xt||A,onClick:()=>{W(""),M(!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:xt||A||!a.engines.length,onClick:()=>{var re;W(""),C({mode:"new",form:jy((re=a.engines[0])==null?void 0:re.id)})},children:["+ ",f("add")]})})]}),a.cells.map(re=>{const ne=Ve.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&&Ot.includes("down")&&l.jsx("button",{className:"nc-btn ghost",disabled:xt||A,onClick:()=>je(()=>uc(e,{cell:re.id},he)),children:f("stop")}),!ne&&Ot.includes("up")&&l.jsx("button",{className:"nc-btn primary",disabled:xt||A,onClick:()=>Rt({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&&Ot.includes("restart")&&l.jsx("button",{className:"nc-btn ghost",disabled:xt||A,onClick:()=>je(()=>pa(e,re.id,he)),children:f("restart")}),_e?l.jsx("button",{className:"nc-btn ghost",disabled:xt||A,onClick:()=>{W(""),j(re)},children:f("fleet-cwd-repair")}):l.jsx("button",{className:"nc-btn ghost",disabled:xt||A,onClick:()=>{var be;W(""),C({mode:"edit",original:re,form:{...re,commands:{...re.commands||{}},command:((be=re.commands)==null?void 0:be[re.engine])||""}})},children:f("edit")}),l.jsx("button",{className:"nc-btn danger",disabled:xt||A,onClick:()=>je(async()=>{window.confirm(f("fleet-remove-cell").replace("{id}",re.id))&&await qy(e,re.id,!0,he)}),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:xt||A,onClick:()=>{W(""),b({mode:"new",form:AR()})},children:["+ ",f("add")]})]}),a.engines.map(re=>{var _e,be;const ne=jt(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"):((be=re.managedInfo)==null?void 0:be.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:xt||A,onClick:()=>{W(""),se({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:xt||A,onClick:()=>Mt(ne),children:f("fleet-credential-forget")}),l.jsx("button",{className:"nc-btn ghost",disabled:xt||A,onClick:()=>{W(""),b({mode:"edit",original:re,form:TR(re)})},children:f("edit")}),l.jsx("button",{className:"nc-btn danger",disabled:xt||A,onClick:()=>je(async()=>{window.confirm(f("fleet-remove-engine").replace("{id}",re.id))&&await yx(e,re.id,he)}),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:xt||A,onClick:()=>{W(""),x({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=N[ne],be=(a.engines||[]).some(ke=>ke.managed&&ke.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}`:"",be?` · ${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:[Ot.includes("model-test")&&l.jsx("button",{className:"nc-btn ghost",disabled:A||Ut,onClick:()=>je(()=>Ct(re.engine,re.id)),children:f("model-test")}),l.jsx("button",{className:"nc-btn danger",disabled:xt||A,onClick:()=>je(()=>wx(e,re.id,re.engine,he)),children:"×"})]})]},ne)})]}),w&&l.jsx(Us,{onClose:()=>x(null),label:f("fleet-models"),error:V,children:l.jsx(OR,{state:w,setState:x,busy:A,onSave:hn,onTest:Ct,profiles:a.managedCatalog||[],canTest:Ot.includes("model-test")&&!Ut})}),y&&l.jsx(Us,{onClose:()=>b(null),label:f("fleet-new-engine"),error:V,children:l.jsx(IR,{state:y,setState:b,busy:A,onSave:_n,catalog:a.managedCatalog||[]})}),E&&l.jsx(Us,{onClose:()=>C(null),label:f("fleet-new-cell"),error:V,children:l.jsx(BR,{token:e,route:he,targets:n,location:K,setLocation:G,state:E,setState:C,engines:a.engines,mcpServers:a.mcpServers||[],managedCatalog:a.managedCatalog||[],busy:A,onSave:Yt})}),T&&l.jsx(Us,{onClose:()=>j(null),label:f("fleet-cwd-repair-title").replace("{id}",T.id),error:"",children:l.jsx($R,{token:e,route:he,cell:T,busy:A,onSaved:async()=>{j(null),Z(f("fleet-cwd-repaired")),await me()},onClose:()=>j(null)})}),X&&l.jsx("div",{className:"nc-set-note",children:X}),V&&l.jsx("div",{className:"nc-err",children:V}),z&&l.jsx(Us,{onClose:()=>M(!1),label:f("fleet-backup"),error:V,children:l.jsx(DR,{cells:a.cells,engines:a.engines,models:a.models||[],busy:A,canRestore:_t,onRestore:ge,onClose:()=>M(!1)})}),U&&l.jsx(Us,{onClose:()=>se(null),label:f("fleet-credential-title"),error:V,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:[U.envKey,l.jsx("input",{type:"password",autoComplete:"off",spellCheck:"false",autoCapitalize:"none",value:U.value,onChange:re=>se({...U,value:re.target.value})})]}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{className:"nc-btn ghost",onClick:()=>se(null),children:f("cancel")}),l.jsx("button",{className:"nc-btn primary",disabled:A||!U.value,onClick:It,children:f("save")})]})]})}),H&&l.jsx(Us,{onClose:()=>L(null),label:f("import-as-cell"),error:V,children:l.jsx(Py,{token:e,route:H.route||he,state:H,setState:L,busy:A,onSave:Qe})}),R&&l.jsx(hc,{cell:R,token:e,route:Array.isArray(R.route)?R.route:he,onConfirm:async re=>{try{await fn(re)}finally{await me()}},onClose:()=>B(null)})]}):l.jsxs("div",{className:"nc-set-tab",children:[ct,ce==="overview"?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-set-info",children:f("fleet-overview-help")}),l.jsx(fh,{token:e,targets:n,readonly:t,onPower:Rt,onImport:ie})]}):l.jsxs(l.Fragment,{children:[Ge,l.jsxs("div",{className:"nc-set-info",children:[f(V?"fleet-editor-load-error":"fleet-editor-unavailable"),!V&&d.reason?` ${d.reason}`:""]})]}),V&&l.jsx("div",{className:"nc-err",children:V}),H&&l.jsx(Us,{onClose:()=>L(null),label:f("import-as-cell"),error:V,children:l.jsx(Py,{token:e,route:H.route||he,state:H,setState:L,busy:A,onSave:Qe})}),R&&l.jsx(hc,{cell:R,token:e,route:Array.isArray(R.route)?R.route:he,onConfirm:async re=>{try{await fn(re)}finally{await me()}},onClose:()=>B(null)})]}):l.jsxs("div",{className:"nc-set-tab",children:[ct,ce==="overview"?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-set-info",children:f("fleet-overview-help")}),l.jsx(fh,{token:e,targets:n,readonly:t,onPower:Rt,onImport:ie})]}):l.jsxs(l.Fragment,{children:[Ge,l.jsx("div",{className:"nc-set-info",children:f("fleet-editor-loading")})]})]})}const Np="nc_notification_speech_v1",tc="nc-notification-speech",Cf="nc-notification-speech-preview",HR=320,UR=2,WR=3e4,KR=1e4,qR=6e4,VR=64,Ay=Object.freeze({enabled:!1}),YR=Object.freeze({it:"it-IT",en:"en-US",es:"es-ES"}),GR=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"])}),jp=new WeakSet;function Rp(e){return{enabled:(e&&typeof e=="object"&&!Array.isArray(e)?e:{}).enabled===!0}}function pS(){try{return typeof localStorage<"u"?localStorage:null}catch{return null}}function Ly(e=pS()){if(!e)return{...Ay};try{return Rp(JSON.parse(e.getItem(Np)||"null"))}catch{return{...Ay}}}function XR(e,t=pS()){const n=Rp(e);if(t)try{t.setItem(Np,JSON.stringify(n))}catch{}return n}function No(){try{return typeof window<"u"?window:null}catch{return null}}function Pa(e=No()){try{return!!(e&&e.speechSynthesis&&typeof e.speechSynthesis.speak=="function"&&typeof e.SpeechSynthesisUtterance=="function")}catch{return!1}}function mS(e=No()){return!!(e&&(typeof e=="object"||typeof e=="function")&&jp.has(e))}function Ef(e=No()){e&&(typeof e=="object"||typeof e=="function")&&jp.delete(e)}function go(e){const t=String(e||"").trim().toLowerCase().split("-")[0];return YR[t]||""}function $c(e){return String(e||"").normalize("NFC").replace(/[\p{Cc}\p{Cf}]+/gu," ").replace(/\s+/g," ").trim()}function QR(e){const t=$c(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(GR).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 JR(e,t){const n=go(e&&e.lang);return n||go(QR(e&&e.body))||go(t)}function gS(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 vS(e,t){const n=go(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 Ty(e){return $c(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 ZR(e,t=HR){const n=Ty(e&&e.title),s=Ty(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 eP(e){try{return!!(e&&e.visibilityState==="visible"&&typeof e.hasFocus=="function"&&e.hasFocus())}catch{return!1}}function _S(e=No()){if(!Pa(e))return!1;try{return e.speechSynthesis.cancel(),!0}catch{return!1}}function tP(e){try{e&&typeof e.dispatchEvent=="function"&&typeof e.Event=="function"&&e.dispatchEvent(new e.Event(Cf))}catch{}}function nP(e,t,n=No(),s={}){var m;if(Ef(n),!Pa(n))return Promise.resolve(!1);const o=$c(e);if(!o||(m=s.signal)!=null&&m.aborted)return Promise.resolve(!1);const a=Number.isFinite(s.timeoutMs)&&s.timeoutMs>0?s.timeoutMs:KR,u=s.setTimer||((v,y)=>setTimeout(v,y)),d=s.clearTimer||(v=>clearTimeout(v)),p=s.signal;return tP(n),new Promise(v=>{let y=!1,b=!1,w=null,x=null;const N=S=>{if(!y){if(y=!0,p&&x&&p.removeEventListener("abort",x),w!==null&&d(w),S!==!0)try{n.speechSynthesis.cancel()}catch{}else jp.add(n);v(S)}};x=()=>N("no-activation"),p&&p.addEventListener("abort",x,{once:!0});try{n.speechSynthesis.cancel();const S=new n.SpeechSynthesisUtterance(o);S.lang=go(t);const E=vS(gS(n),S.lang);E&&(S.voice=E),S.onstart=()=>{b=!0},S.onend=()=>N(b?!0:"no-activation"),S.onerror=()=>N("voice-error"),w=u(()=>N("timeout"),a),n.speechSynthesis.speak(S)}catch{N("no-activation")}})}function iP(e={}){const t=e.scope||No(),n=e.document||t&&t.document,s=Number.isInteger(e.maxPending)&&e.maxPending>=0?e.maxPending:UR,o=Number.isFinite(e.watchdogMs)&&e.watchdogMs>0?e.watchdogMs:WR,a=Number.isFinite(e.dedupWindowMs)&&e.dedupWindowMs>0?e.dedupWindowMs:qR,u=Number.isInteger(e.maxDedup)&&e.maxDedup>0?e.maxDedup:VR,d=e.now||Date.now,p=e.setTimer||((F,O)=>setTimeout(F,O)),m=e.clearTimer||(F=>clearTimeout(F)),v=e.isPrimed||(()=>mS(t)),y=t&&t.speechSynthesis;let b=null,w=null,x=[],N=[],S=()=>{};const E=new Map,C=()=>{N=gS(t)};if(C(),y&&typeof y.addEventListener=="function")y.addEventListener("voiceschanged",C),S=()=>y.removeEventListener("voiceschanged",C);else if(y&&"onvoiceschanged"in y){const F=y.onvoiceschanged,O=(...R)=>{C(),typeof F=="function"&&F.apply(y,R)};y.onvoiceschanged=O,S=()=>{y.onvoiceschanged===O&&(y.onvoiceschanged=F)}}const A=F=>{if(F&&typeof F.id=="string"&&F.id)return`id:${F.id}`;const O=Number(F&&F.ts),R=$c(F&&F.title);return Number.isFinite(O)&&R?`frame:${O}:${R}`:""},I=F=>{if(!F)return!0;const O=d();for(const[R,B]of E)O-B>=a&&E.delete(R);if(E.has(F))return!1;for(E.set(F,O);E.size>u;)E.delete(E.keys().next().value);return!0},V=()=>{w!==null&&m(w),w=null},W=()=>{V(),b&&(b.onend=null,b.onerror=null,b=null),_S(t)},X=F=>{if(!Pa(t))return x=[],"unsupported";let O;try{O=new t.SpeechSynthesisUtterance(F.text),O.lang=go(F.lang);const B=vS(N,O.lang);B&&(O.voice=B)}catch{return x=[],"error"}b=O;const R=()=>{if(b!==O)return;V(),b=null,O.onend=null,O.onerror=null;const B=x.shift();B&&X(B)};O.onend=R,O.onerror=R;try{return w=p(()=>{if(b!==O)return;b=null,O.onend=null,O.onerror=null;try{t.speechSynthesis.cancel()}catch{}V();const B=x.shift();B&&X(B)},o),t.speechSynthesis.speak(O),"speaking"}catch{return R(),"error"}},Z=(F,O)=>{if(!Pa(t))return"unsupported";const R=ZR(F);if(!R)return"empty";if(!I(A(F)))return"duplicate";if(!eP(n))return"inactive";if(!v())return"unprimed";const B={text:R,lang:O};return F&&F.urgency==="high"?(x=[],W(),X(B)):b?s===0?"dropped":(x.length>=s&&x.shift(),x.push(B),"queued"):X(B)},K=()=>{x=[],W()};return{enqueue:Z,stop:K,dispose:()=>{K(),S(),S=()=>{}}}}function yS(){const[e,t]=k.useState(Ly);k.useEffect(()=>{const s=o=>{if((o==null?void 0:o.type)==="storage"&&o.key!==Np&&o.key!==null)return;const a=(o==null?void 0:o.type)===tc?Rp(o.detail):Ly();t(a)};return window.addEventListener(tc,s),window.addEventListener("storage",s),()=>{window.removeEventListener(tc,s),window.removeEventListener("storage",s)}},[]);const n=k.useCallback(s=>{const o=XR({enabled:s===!0});return t(o),window.dispatchEvent(new CustomEvent(tc,{detail:o})),o.enabled},[]);return[e.enabled,n]}function sP({text:e}){const[t,n]=k.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(lt,{name:"copy",size:14})," ",f(t?"copied":"copy")]})]})}function rP({value:e}){const[t,n]=k.useState("");return k.useEffect(()=>{let s=!0;return Dj.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 oP({token:e,nodes:t,roster:n,settings:s,readonly:o,refresh:a,refreshAliases:u,vlUnavailable:d=[]}){const[p,m]=k.useState(null),[v,y]=k.useState(null),[b,w]=k.useState(null),[x,N]=k.useState({ssh:"",sshPort:"",name:""}),[S,E]=k.useState(""),[C,A]=k.useState(""),[I,V]=k.useState(!1),[W,X]=k.useState(null),Z=Date.now(),K=s&&s.deviceName||"",G=(t||[]).filter(j=>j&&j.direction==="outbound"&&j.name&&j.ssh),F=G.find(j=>j.name===S)||G[0]||null,O=F?Nh(F.tunnel,Z):null,R=F!=null&&F.shared?O!=null&&O.up?"share-local-active":"share-local-pending":O!=null&&O.up?"share-local-private":"share-local-private-down",B=[{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")}],H=W&&(t||[]).find(j=>`${j.kind||"direct"}:${j.nodeId||j.name}`===W)||null,L=async j=>{if(F){m(null),y(`${F.name}:share`);try{const z=await Ix(e,F.name,j);await a(),z&&z.reversePoolPending===!0&&m(`${F.name}: ${f("share-reverse-pool-pending")}`)}catch(z){const M=z!=null&&z.data&&z.data.shared===!1?z.data:null;if(M)try{await a()}catch{}const D=z!=null&&z.data&&typeof z.data.hint=="string"?z.data.hint:"",$=(M==null?void 0:M.revoked)===!0&&(M==null?void 0:M.localReconcilePending)===!0?f("share-off-local-reconcile-pending"):(M==null?void 0:M.revoked)===!1&&(M==null?void 0:M.reconcilePending)===!0?f("share-off-hub-reconcile-pending"):"",U=z!=null&&z.data&&z.data.reversePoolPending===!0?f("share-reverse-pool-pending"):"",se=z!=null&&z.data&&typeof z.data.code=="string"?z.data.code:"",ce=z!=null&&z.data&&typeof z.data.detail=="string"?z.data.detail.trim():"",oe=ce&&ce!==String(z.message||"")?ce:"";m(`${F.name}: ${String(z.message||z)}${se?` [${se}]`:""}${oe?` — ${oe}`:""}${D?` — ${D}`:""}${$?` — ${$}`:""}${U?` — ${U}`:""}`)}y(null)}},T=async()=>{m(null);const j=Ys(x.name||C||K||"NexusCrew"),z=Gk({name:j,ssh:x.ssh,sshPort:x.sshPort});if(!z.ok){m(f(z.error));return}y("invite");try{w(await Lx(e,{...C||K?{label:C||K}:{},name:j,ssh:z.value.ssh,...z.value.sshPort?{sshPort:z.value.sshPort}:{}}))}catch(M){m(String(M.message||M))}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")}),B.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(z=>{const M=Vj(z);if(!M)return null;const D=`${z.kind||"direct"}:${z.nodeId||z.name}`,$=M.routed?{up:M.reach.up,since:null}:Nh(z.tunnel,Z);return l.jsxs("button",{type:"button",className:`nc-set-node nc-node-row${M.routed?" routed":""}`,"aria-label":`${M.title} — ${f("node-detail-open")}`,onClick:()=>X(D),children:[l.jsx("span",{className:`nc-dot ${M.reach.up?"on":""}`}),l.jsxs("span",{className:"nc-node-row-text",children:[l.jsx("b",{children:M.title}),l.jsxs("small",{children:[M.routed?M.routeLabel:`${M.subtitle} · ${f(M.exposure.shortKey)}`,!M.routed&&M.exposure.shortKey==="visibility-selected"?` (${M.exposure.count})`:""]})]}),l.jsxs("span",{className:`nc-set-tunnel${M.reach.up?" up":""}`,children:[f(M.reach.key),$.since?` · ${$.since}`:""]}),l.jsx("span",{className:"nc-node-row-more",children:l.jsx(lt,{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(", ")]}),H&&l.jsx(lR,{node:H,nodes:t||[],token:e,readonly:o,refresh:a,onClose:()=>X(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 z=window.prompt(f("node-local-alias"),j.alias||"");if(z!=null){if(z.trim()&&!yo(z.normalize("NFC"))){m(f("err-label"));return}y(`${j.instanceId}:alias`),m(null);try{z.trim()?await Mx(e,j.instanceId,z):await sv(e,j.instanceId),u()}catch(M){m(String(M.message||M))}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 sv(e,j.instanceId),u()}catch(z){m(String(z.message||z))}y(null)},children:f("reset-alias")})]})]},j.instanceId))]}),F&&l.jsxs("div",{className:"nc-set-form nc-local-share",children:[l.jsx("div",{className:"nc-sheet-label",children:f("share-local-heading")}),G.length>1&&l.jsxs("label",{className:"nc-field",children:[f("share-local-hub"),l.jsx("select",{value:F.name,disabled:o||!!v,onChange:j=>E(j.target.value),children:G.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:F.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}",K||f("local")).replace("{hub}",F.label||F.name)}),l.jsx("small",{children:f(F.shared?"share-node-on-desc":"share-node-off-desc")})]})]}),l.jsx("div",{className:`nc-set-test${F.shared&&(O!=null&&O.up)?" ok":O!=null&&O.up?"":" ko"}`,children:f(R)}),!(O!=null&&O.up)&&l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:o||!!v,onClick:()=>L(F.shared===!0),children:f("share-local-reconnect")})]}),l.jsx(nS,{token:e,deviceDefault:K,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:K||f("invite-target-this")})]}),l.jsxs("label",{className:"nc-field",children:[f("invite-endpoint-label"),l.jsx("input",{placeholder:"user@host",value:x.ssh,disabled:o,onChange:j=>N({...x,ssh:j.target.value})}),l.jsx("small",{className:"nc-set-hint",children:f("invite-endpoint-needed")})]}),G.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:x.sshPort,disabled:o,onChange:j=>N({...x,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:K||"NexusCrew",value:C,disabled:o,onChange:j=>A(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:Ys(C||K||f("node-name-ph")),value:x.name,disabled:o,onChange:j=>N({...x,name:j.target.value?Ys(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||!x.ssh.trim(),onClick:T,children:f("create-pairing-link")}),l.jsxs("button",{type:"button",className:"nc-btn ghost",disabled:!!v,onClick:()=>V(j=>!j),children:[I?"▾":"▸"," ",f("pair-advanced")]})]}),b&&l.jsxs(l.Fragment,{children:[l.jsx(rP,{value:b.pairingUrl}),l.jsx(sP,{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 aP({token:e,readonly:t}){const[n,s]=k.useState("idle"),[o,a]=k.useState(!1),[u,d]=k.useState(null);k.useEffect(()=>{let m=!1;return uR().then(v=>{m||s(v)}),()=>{m=!0}},[]);const p=async()=>{d(null),a(!0);try{n==="subscribed"?(await hR(e),s("idle")):(await dR(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 lP(){const[e,t]=yS(),[n,s]=k.useState(""),[o,a]=k.useState(""),[u,d]=k.useState(!1),[p,m]=k.useState(mS),v=k.useRef(0),y=k.useRef(!1),b=k.useRef(null),w=Pa();k.useEffect(()=>()=>{var S;v.current+=1,y.current&&((S=b.current)==null||S.abort(),b.current=null,y.current=!1,Ef())},[]);const x=async()=>{const S=v.current+=1,E=typeof AbortController=="function"?new AbortController:null;s(""),a(""),d(!0),m(!1),y.current=!0,b.current=E;const C=await nP(f("notification-speech-preview"),dc(),void 0,E?{signal:E.signal}:{});return S!==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},N=S=>{var E;if(t(S),s(""),a(""),S)x();else{v.current+=1;const C=y.current;(E=b.current)==null||E.abort(),b.current=null,y.current=!1,d(!1),m(!1),Ef(),C||_S()}};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:!w,onChange:S=>N(S.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:f("notification-speech-enable")}),l.jsx("small",{children:f("notification-speech-help")})]})]}),w?l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:!e||u,onClick:()=>{x()},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 cP({token:e,readonly:t,nodes:n=[],settings:s=null}){const[o,a]=k.useState(null),[u,d]=k.useState([]),[p,m]=k.useState({name:"",mode:"primary-failover",targets:[]}),[v,y]=k.useState(null),[b,w]=k.useState(!1),[x,N]=k.useState(null),[S,E]=k.useState(""),C=k.useCallback(async()=>{try{const[T,j]=await Promise.all([Bx(e),Hx(e)]);a(T),d(Array.isArray(j==null?void 0:j.groups)?j.groups:[]),E("")}catch(T){E(String(T.message||T))}},[e]);k.useEffect(()=>{C()},[C]);const A=async T=>{w(!0),N(null),E("");try{a(await zx(e,T))}catch(j){E(String(j.message||j))}w(!1)},I=async()=>{w(!0),N(null),E("");try{N({kind:"test",...await $x(e)})}catch(T){E(String(T.message||T))}w(!1)},V=async()=>{w(!0),N(null),E("");try{N({kind:"stop",...await Fx(e)})}catch(T){E(String(T.message||T))}w(!1)},W=[],X=new Set,Z=(T,j)=>{const z=typeof T=="string"?T.toLowerCase():"";!/^[a-f0-9]{32}$/.test(z)||X.has(z)||(X.add(z),W.push({id:z,label:j||z}))};Z(s==null?void 0:s.nodeId,f("audio-group-local"));for(const T of n||[])Z((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)Z(T,`${T} (${f("audio-group-unavailable-target")})`);const K=(T=null)=>{E(""),T?(y(T.name),m({name:T.name,mode:T.mode,targets:[...T.targets||[]]})):(y(null),m({name:"",mode:"primary-failover",targets:[]}))},G=(T,j)=>m(z=>({...z,targets:j?[...new Set([...z.targets,T])]:z.targets.filter(M=>M!==T)})),F=async()=>{const T=p.name.trim().toLowerCase();if(!/^[a-z0-9][a-z0-9-]{0,31}$/.test(T)||p.targets.length<1){E(f("audio-group-invalid"));return}w(!0),E("");try{const j=await Ux(e,T,{targets:p.targets,mode:p.mode}),z=j==null?void 0:j.group;if(!z||!z.name)throw new Error(f("audio-group-save-failed"));d(M=>[...M.filter(D=>D.name!==z.name),z].sort((D,$)=>D.name.localeCompare($.name))),K(null)}catch(j){E(String(j.message||j))}w(!1)},O=async T=>{w(!0),E("");try{await Wx(e,T),d(j=>j.filter(z=>z.name!==T)),v===T&&K(null)}catch(j){E(String(j.message||j))}w(!1)},R=(o==null?void 0:o.installed)===!0,B=(o==null?void 0:o.liveness)==="ready",H=(o==null?void 0:o.consent)===!0&&R&&B,L=x?x.kind==="stop"?f(x.stopped?"audio-stop-stopped":"audio-stop-idle"):x.status==="accepted"||x.status==="spoken"?f("audio-test-accepted"):x.status==="unknown"?f("audio-test-unknown"):`${f("audio-test-refused")}${x.reason?` (${x.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=>{A(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(B?"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||!H,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:()=>{V()},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:()=>K(T),children:f("audio-group-edit")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:t||b,onClick:()=>{O(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:()=>K(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=>G(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:()=>{F()},children:f("audio-group-save")}),v&&l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:b,onClick:()=>K(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}),S&&l.jsx("div",{className:"nc-err",children:S})]})}function uP(){const[e,t]=hp();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:Tw.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:Mw.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(Ks),children:f("input-settings-reset")})})]})}function dP({token:e,roster:t=[],readonly:n}){const s=[{key:"local",route:[],label:f("diagnostics-local"),status:"up"},...t.filter(H=>Array.isArray(H.route)&&H.route.length).map(H=>({key:H.route.join("/"),route:H.route,label:H.label||H.name,status:H.status}))],[o,a]=k.useState("local"),u=s.find(H=>H.key===o)||s[0],[d,p]=k.useState(null),[m,v]=k.useState([]),[y,b]=k.useState(""),[w,x]=k.useState(!1),[N,S]=k.useState(!0),[E,C]=k.useState(900),[A,I]=k.useState("all"),[V,W]=k.useState(""),X=k.useRef(0),Z=k.useRef(null),K=k.useCallback(async()=>{try{const H=await Yx(e,u.route);if(p(H),b(""),!w){const L=await Gx(e,{after:X.current,limit:200},u.route);Array.isArray(L.records)&&L.records.length&&(X.current=L.cursor,v(T=>[...T,...L.records].slice(-500)))}}catch(H){b(H&&H.status===404?f("diagnostics-unsupported"):String(H.message||H))}},[e,u.key,w]);k.useEffect(()=>{X.current=0,v([]),p(null),b("")},[u.key]),k.useEffect(()=>{let H=null,L=!0;const T=()=>{!L||document.visibilityState==="hidden"||K()},j=()=>{H&&clearInterval(H),H=document.visibilityState==="hidden"?null:setInterval(T,2e3),document.visibilityState!=="hidden"&&T()};return document.addEventListener("visibilitychange",j),j(),()=>{L=!1,H&&clearInterval(H),document.removeEventListener("visibilitychange",j)}},[K]),k.useEffect(()=>{N&&Z.current&&(Z.current.scrollTop=Z.current.scrollHeight)},[m,N]);const G=m.filter(H=>(A==="all"||H.level===A)&&(!V||String(H.component||"").toLowerCase().includes(V.toLowerCase()))),F=G.map(H=>`${H.ts} ${H.level.toUpperCase()} ${H.component} ${H.code} ${H.message}${Object.keys(H.meta||{}).length?` ${JSON.stringify(H.meta)}`:""}`).join(`
|
|
92
92
|
`),O=async H=>{b("");try{const L=await H();p(L),await K()}catch(L){b(String(L.message||L))}},R=async()=>{try{await navigator.clipboard.writeText(F)}catch{b(f("copy-manual"))}},B=()=>{try{const H=new Blob([`${JSON.stringify(G,null,2)}
|
|
93
|
-
`],{type:"application/json"}),L=URL.createObjectURL(H),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:H=>a(H.target.value),children:s.map(H=>l.jsxs("option",{value:H.key,children:[H.label,H.status!=="up"?` · ${H.status}`:""]},H.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:E,onChange:H=>C(Number(H.target.value)),disabled:n,children:[300,900,1800,3600].map(H=>l.jsxs("option",{value:H,children:[H/60," min"]},H))}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||(d==null?void 0:d.verbose)===!0,onClick:()=>O(()=>ov(e,!0,E,u.route)),children:f("enable")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||(d==null?void 0:d.verbose)!==!0,onClick:()=>O(()=>ov(e,!1,E,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:A,onChange:H=>I(H.target.value),children:[l.jsx("option",{value:"all",children:f("diagnostics-all-levels")}),["debug","info","warn","error"].map(H=>l.jsx("option",{value:H,children:H},H))]}),l.jsx("input",{"aria-label":f("diagnostics-component"),placeholder:f("diagnostics-component"),value:V,onChange:H=>W(H.target.value)})]}),l.jsxs("div",{className:"nc-set-row",children:[l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:w,onChange:H=>x(H.target.checked)})," ",f("diagnostics-pause")]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:N,onChange:H=>S(H.target.checked)})," ",f("diagnostics-autoscroll")]})]}),l.jsx("pre",{ref:Z,className:"nc-diag-log","aria-label":f("diagnostics-log"),children:F||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:B,children:f("diagnostics-export")}),l.jsx("button",{type:"button",className:"nc-btn danger",disabled:n,onClick:()=>{window.confirm(f("diagnostics-clear-confirm"))&&O(async()=>{const H=await Xx(e,u.route);return X.current=0,v([]),H})},children:f("diagnostics-clear")})]}),y&&l.jsx("div",{className:"nc-err",children:y})]})}function hP({token:e,settings:t,readonly:n,refresh:s,roster:o,section:a,setSection:u}){const[d,p]=k.useState(null),[m,v]=k.useState(null),[y,b]=k.useState(!1),[w,x]=k.useState(!1),[N,S]=k.useState(null),[E,C]=k.useState(!0),[A,I]=k.useState(!1);k.useEffect(()=>{S(t&&t.update||null),C(!t||t.autoUpdate!==!1),I(!!(t&&t.alternateScreen))},[t]);const V=async()=>{p(null),v(null),x(!0);try{const R=await Px(e);v(R.note||"ok"),b(!1)}catch(R){p(String(R.message||R))}x(!1)},W=async()=>{p(null),v(null),x(!0);try{const R=await Kx(e);v(`${R.note||"ok"}${R.target?` (${R.target})`:""}`)}catch(R){p(String(R.message||R))}x(!1)},X=async R=>{p(null),v(null),x(!0);try{await _h(e,{autoUpdate:R}),C(R),s&&await s()}catch(B){p(String(B.message||B))}x(!1)},Z=async R=>{p(null),v(null),x(!0);try{await _h(e,{alternateScreen:R}),I(R),s&&await s()}catch(B){p(String(B.message||B))}x(!1)},K=async()=>{p(null),v(null),x(!0);try{S(await qx(e))}catch(R){p(String(R.message||R))}x(!1)},G=async()=>{p(null),v(null),x(!0);try{const R=await Vx(e);S(R),v(f("npm-update-restarting"))}catch(R){p(String(R.message||R))}x(!1)},F=()=>{window.confirm(f("composer-clear-confirm"))&&(p(null),m2()?(window.dispatchEvent(new Event(vf)),v(f("composer-clear-done"))):p(f("composer-clear-failed")))},O=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",{}),O&&O.installed?f("service-installed"):f("service-missing"),O&&O.installed?` · ${O.active?f("service-active"):f("service-inactive")}`:"",O?` · boot ${O.boot?"on":"off"}`:""]}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||w,title:n?f("settings-readonly"):"",onClick:W,children:f("service-regenerate")})}),l.jsx(aP,{token:e,readonly:n}),l.jsx(lP,{})]}),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:E,disabled:n||w||N&&!N.supported,onChange:R=>X(R.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:f("npm-auto-update")}),l.jsx("small",{children:f("npm-auto-update-help")})]})]}),N&&l.jsxs("div",{className:"nc-set-info",children:[f("npm-update-current")," v",N.current,N.latest?` · ${f("npm-update-latest")} v${N.latest}`:""," · ",f(N.supported?N.phase==="idle"&&N.checked!==!0?"npm-update-never":`npm-update-${N.phase}`:"unsupported")]}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||w||!N||!N.supported,onClick:K,children:f("npm-update-check")}),N&&N.available&&l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||w||N.phase==="installing",onClick:G,children:f("npm-update-install")})]}),N&&N.lastError&&l.jsx("div",{className:"nc-err",children:N.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||w,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:F,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:A,disabled:n||w,onChange:R=>Z(R.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:f("alternate-screen")}),l.jsx("small",{children:f("alternate-screen-help")})]})]})]}),l.jsx(dP,{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:w,onClick:()=>b(!1),children:f("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:w,onClick:V,children:f("confirm")})]})]}),m&&l.jsx("div",{className:"nc-set-note",children:m}),d&&l.jsx("div",{className:"nc-err",children:d})]})}function fP({token:e,onClose:t,initialTab:n="nodes",initialLocation:s="",startNewCell:o=!1}){Yn();const a=n==="diagnostics"?"diagnostics":"general",[u,d]=k.useState(n==="diagnostics"?"system":n),p=k.useRef(null),m=k.useRef(null),[v,y]=k.useState({start:!1,end:!1}),[b,w]=k.useState(a),[x,N]=k.useState(null),[S,E]=k.useState([]),[C,A]=k.useState([]),[I,V]=k.useState(!1),[W,X]=k.useState(null),[Z,K]=k.useState(0),G=Ff(e,!0,Z),F=k.useCallback(()=>{const R=p.current;if(!R)return;const B=R.scrollWidth>R.clientWidth+1,H={start:B&&R.scrollLeft>1,end:B&&R.scrollLeft+R.clientWidth<R.scrollWidth-1};y(L=>L.start===H.start&&L.end===H.end?L:H)},[]);k.useEffect(()=>{const R=p.current;if(!R)return;const B=typeof ResizeObserver=="function"?new ResizeObserver(F):null;return B==null||B.observe(R),window.addEventListener("resize",F),F(),()=>{B==null||B.disconnect(),window.removeEventListener("resize",F)}},[F]),k.useEffect(()=>{var B,H;(H=(B=m.current)==null?void 0:B.scrollIntoView)==null||H.call(B,{behavior:"smooth",block:"nearest",inline:"nearest"});const R=window.requestAnimationFrame?window.requestAnimationFrame(F):setTimeout(F,0);return()=>{window.cancelAnimationFrame?window.cancelAnimationFrame(R):clearTimeout(R)}},[u,F]);const O=k.useCallback(async()=>{var R;try{const B=await Yy(e);N(B),X(null)}catch(B){X(String(B.message||B))}try{const H=(await jx(e)).peers||[];let L=[],T=[];try{const[j,z]=await Promise.all([on("/api/config",e).then(U=>U.json()).catch(()=>null),Xy(e).catch(()=>null)]),M=j&&typeof j.instanceId=="string"?j.instanceId:"",D=[{instanceId:M||null,route:[],label:null},...rb(z,M)],$=await Promise.all(D.map(async U=>{try{return{ok:!0,peers:((await Gy(e,U.route)).nodes||[]).map(oe=>sb(oe,U)).filter(Boolean)}}catch(se){return{ok:!1,owner:U,error:se}}}));for(const U of $){if(U.ok){L.push(...U.peers);continue}U.owner.route.length!==0&&T.push({instanceId:U.owner.instanceId,label:U.owner.label,route:U.owner.route,failure:/timeout/i.test(String(((R=U.error)==null?void 0:R.message)||U.error))?"timeout":"unreachable"})}}catch{}A(T),E([...H,...L])}catch(B){X(String(B.message||B))}},[e]);return k.useEffect(()=>{O();const R=setInterval(O,5e3);return()=>clearInterval(R)},[O]),k.useEffect(()=>{let R=!1;return on("/api/config",e).then(B=>B.json()).then(B=>{R||V(!!B.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(lt,{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(lt,{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:F,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(oP,{token:e,nodes:S,roster:G,settings:x,readonly:I,vlUnavailable:C,refresh:O,refreshAliases:()=>K(R=>R+1)}),u==="fleet"&&l.jsx(FR,{token:e,readonly:I,startNewCell:o,initialLocation:s,targets:G.map(R=>({route:R.route,label:R.label||R.name,status:R.status}))}),u==="audio"&&l.jsx(cP,{token:e,readonly:I,nodes:S,settings:x}),u==="input"&&l.jsx(uP,{}),u==="system"&&l.jsx(hP,{token:e,settings:x,readonly:I,refresh:O,roster:G,section:b,setSection:w})]})]})})}function pP({token:e,initialPair:t,deviceDefault:n="",localNodeId:s="",localNameDefault:o="",onPairDone:a,onDone:u}){Yn();const[d,p]=k.useState(t?"pair":"welcome"),[m,v]=k.useState(!1),[y,b]=k.useState(null),[w,x]=k.useState(null),N=async()=>{v(!0),b(null);try{await _h(e,{wizardDone:!0}),a&&a(),u()}catch(S){b(String(S.message||S)),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:N,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(nS,{token:e,initial:t||"",autoStart:!!t,deviceDefault:n,localNodeId:s,localNameDefault:o,onBusyChange:v,onSuccess:async S=>{x(S&&S.authorizedKeys?{line:S.authorizedKeys,note:S.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")}),w&&l.jsx(Sp,{line:w.line,note:w.note}),l.jsx("div",{className:"nc-sheet-actions",children:l.jsx("button",{className:"nc-btn primary",disabled:m,onClick:N,children:f("finish")})})]}),y&&l.jsx("div",{className:"nc-err",children:y})]})})}function mP(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 gP=6e3,vP=12e3;function _P({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(lt,{name:"x",size:14})})]})}function yP({ask:e,token:t,onAnswered:n,onDismiss:s}){const[o,a]=k.useState(""),[u,d]=k.useState(!1),[p,m]=k.useState(null),[v,y]=k.useState(!1),b=async x=>{const N=String(x||"").trim();if(!(!N||u)){m(null),d(!0);try{await Jx(t,e.id,N),n(e.id)}catch(S){m(String(S.message||S))}d(!1)}},w=async()=>{if(!v){y(!0);try{await Zx(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:w,children:l.jsx(lt,{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(x=>l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:u,onClick:()=>b(x),children:x},x))}),l.jsxs("div",{className:"nc-ask-reply",children:[l.jsx("textarea",{rows:2,placeholder:f("ask-reply-ph"),value:o,disabled:u,onChange:x=>a(x.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 bP({token:e}){const[t]=Yn(),[n]=yS(),[s,o]=k.useState([]),[a,u]=k.useState([]),[d,p]=k.useState(()=>{try{return/(?:^|[#&])ask=/.test(location.hash)}catch{return!1}}),m=k.useRef(0),v=k.useRef(null);v.current||(v.current=iP());const y=k.useRef({enabled:n,lang:t});y.current={enabled:n,lang:t};const b=k.useCallback(S=>{o(E=>E.filter(C=>C.key!==S))},[]),w=k.useCallback(S=>{const E=`t${m.current+=1}`;o(A=>[...A.slice(-3),{...S,key:E}]),setTimeout(()=>b(E),S.urgency==="high"?vP:gP);const C=y.current;if(C.enabled)try{v.current.enqueue(S,JR(S,C.lang))}catch{}},[b]);k.useEffect(()=>{n||v.current.stop()},[n]),k.useEffect(()=>{const S=()=>{(document.visibilityState!=="visible"||!document.hasFocus())&&v.current.stop()},E=()=>v.current.stop();return document.addEventListener("visibilitychange",S),window.addEventListener("blur",S),window.addEventListener(Cf,E),()=>{document.removeEventListener("visibilitychange",S),window.removeEventListener("blur",S),window.removeEventListener(Cf,E),typeof v.current.dispose=="function"?v.current.dispose():v.current.stop()}},[]),k.useEffect(()=>{if(!e)return;let S=!1;Qx(e).then(C=>{S||u(C.asks||[])}).catch(()=>{});const E=mP(e,C=>{C.type==="notify"?w(C):C.type==="ask"&&C.ask&&C.ask.id?u(A=>A.some(I=>I.id===C.ask.id)?A:[...A,C.ask]):C.type==="ask-answered"&&C.id?u(A=>A.filter(I=>I.id!==C.id)):C.type==="ask-dismissed"&&C.id&&u(A=>A.filter(I=>I.id!==C.id))});return()=>{S=!0,E()}},[e,w]);const x=S=>u(E=>E.filter(C=>C.id!==S)),N=S=>u(E=>E.filter(C=>C.id!==S));return l.jsxs(l.Fragment,{children:[s.length>0&&l.jsx("div",{className:"nc-ntf-toasts",children:s.map(S=>l.jsx(_P,{n:S,onClose:()=>b(S.key)},S.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(lt,{name:"x",size:16})})]}),l.jsx("div",{className:"nc-ask-panel-body",children:a.map(S=>l.jsx(yP,{ask:S,token:e,onAnswered:x,onDismiss:N},S.id))})]})]})}const wP=4e3;async function SP(e){const t=await on("/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 ph(e,t=[]){var d;const[n,s]=await Promise.allSettled([t.length?If(e,t):SP(e),Qs(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 bS(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 xP(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=Kf(v,y),w=bS(v,a,u);n.push({key:Ca(d,v.tmuxSession||v.cell),session:v.tmuxSession,route:d,cellName:v.cell,label:v.cell,node:d.length?d.join("/"):"",nodeLabel:p,live:w,selectable:w,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 kP(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",qf(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("/"),mc({...u,route:d,cells:p,sessions:m,unmanaged:m.filter(y=>!v.has(y.name))}).rawItems)}return t}function CP(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 Vs(m,n,"all",gs(s,a)).map(v=>p.get(v.key))})}function EP({token:e,current:t,onPick:n,onClose:s,panelPort:o=0,nodePanelPorts:a={}}){const[u,d]=k.useState(xv),[p,m]=k.useState(!1),[v,y]=k.useState(!1),[b,w]=k.useState(""),[x,N]=k.useState(null),[S,E]=k.useState(""),[C,A]=k.useState(""),I=k.useRef(null),V=k.useRef(null),W=k.useMemo(()=>xP(u),[u]),X=k.useMemo(()=>kP(u),[u]),{pins:Z,orders:K,canMoveRoster:G,moveRoster:F,stepRoster:O}=Uf(),R=k.useMemo(()=>CP(W,X,Z,K),[W,X,Z,K]),B=k.useMemo(()=>p?R:R.filter(M=>M.selectable||M.degraded&&M.active),[R,p]),H=k.useMemo(()=>W.find(M=>M.key===S&&M.selectable),[W,S]),L=k.useMemo(()=>x?W.find(M=>M.key===x.key):null,[W,x]);k.useEffect(()=>{var $;const M=document.activeElement;($=V.current)==null||$.focus();const D=U=>{U.key==="Escape"&&s()};return document.addEventListener("keydown",D),()=>{var U;document.removeEventListener("keydown",D),(U=M==null?void 0:M.focus)==null||U.call(M)}},[s]),k.useEffect(()=>{let M=!0,D=!1;const $=async()=>{if(D)return;D=!0;const se=xv(),ce=Array.isArray(se.nodeGroups)?se.nodeGroups:[],oe=ph(e),pe=je=>je.kind!=="vl"&&Array.isArray(je.route)&&je.route.length>0,he=await Promise.all(ce.filter(pe).map(async je=>({group:je,result:await ph(e,je.route)}))),me=await oe;if(!M)return;const Ve=new Map(he.map(({group:je,result:Ct})=>[JSON.stringify(je.route||[]),Ct])),ut=ce.map(je=>{if(!pe(je))return{...je,switcherFresh:!1};const Ct=Ve.get(JSON.stringify(je.route||[]));return Ct?{...je,sessions:Ct.sessions||je.sessions||[],cells:Ct.cells||je.cells||[],switcherFresh:Ct.fresh}:{...je,switcherFresh:!1}}),_t=Nb({...se,sessions:me.sessions||se.sessions||[],cells:me.cells||se.cells||[],localFresh:me.fresh,nodeGroups:ut,refreshedAt:Date.now()});d(_t),y(!0),D=!1};$();const U=setInterval($,wP);return()=>{M=!1,clearInterval(U)}},[e]);const T=M=>M.degraded?f("cell-degraded"):M.verified?M.selectable?M.working?f("cell-working"):f("cell-idle"):f("cell-off"):f("cell-switcher-not-confirmed"),j=M=>{if(w(""),!M.selectable){w(M.verified?f("cell-switcher-not-active"):f("cell-switcher-not-confirmed"));return}E(M.key)},z=async()=>{const M=H;if(!M){w(f("cell-switcher-select"));return}w(""),A(M.key);try{const D=await ph(e,M.route),$=(D.cells||[]).find(U=>(U==null?void 0:U.cell)===M.cellName&&(U==null?void 0:U.tmuxSession)===M.session);if(D.fresh!==!0){w(f("cell-switcher-verify-failed"));return}if(!bS($,D.sessions,D.fresh)){w(f("cell-switcher-not-active"));return}n({session:M.session,...M.node?{node:M.node}:{},cellName:M.cellName}),s()}catch{w(f("cell-switcher-verify-failed"))}finally{A("")}};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:M=>M.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&&B.length===0&&l.jsx("div",{className:"nc-empty",role:"status",children:f("cell-switcher-empty-active")}),B.map(M=>{const D=(t==null?void 0:t.session)===M.session&&((t==null?void 0:t.node)||"")===M.node,$=S===M.key,U=T(M),se=yf(f,M.activity),ce=bf(f,M.telemetry),oe=[se,ce].filter(Boolean).join(" · "),pe=M.node||"local",he=X.get(pe)||W.filter(me=>(me.node||"local")===pe);return l.jsxs("div",{className:`nc-cell-switcher-row${D?" current":""}${$?" selected":""}${M.selectable?"":" off"}`,"data-roster-key":M.key,"data-position":pe,children:[l.jsx(Gi,{position:pe,itemKey:M.key,label:M.cellName,canMove:G,onMove:(me,Ve)=>F(pe,me,Ve,he),onStep:me=>O(pe,M.key,me,he)}),l.jsx("button",{type:"button",className:"nc-cell-switcher-peek",title:f("cell-peek"),"aria-label":`${f("cell-peek")}: ${M.cellName}`,onClick:me=>{me.stopPropagation(),N({key:M.key,source:"preview"})},children:l.jsx("span",{className:`nc-cell-switcher-dot${M.degraded?" warn":M.live?` on${M.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")}: ${M.cellName}`,onClick:me=>{me.stopPropagation(),N({key:M.key,source:"stream"})},children:"▶"}),M.panelUrl&&l.jsx("button",{type:"button",className:"nc-cell-switcher-act",title:f("cell-peek-panel"),"aria-label":`${f("cell-peek-panel")}: ${M.cellName}`,onClick:me=>{me.stopPropagation(),N({key:M.key,source:"panel"})},children:"▣"})]}),l.jsx("button",{type:"button",className:"nc-cell-switcher-row-select","aria-current":D?"true":void 0,"aria-pressed":$,"aria-disabled":!M.selectable,disabled:C===M.key,onClick:()=>j(M),children:l.jsxs("span",{className:"nc-cell-switcher-copy",children:[l.jsx("b",{children:M.cellName}),l.jsx("small",{className:"nc-cell-switcher-state",children:U}),l.jsx("small",{children:[M.nodeLabel,M.subtitle].filter(Boolean).join(" · ")}),oe&&l.jsx("small",{className:"nc-cell-switcher-telemetry",children:oe})]})})]},M.key)})]}),b&&l.jsx("div",{className:"nc-cell-switcher-notice",role:"status",children:b}),x&&L&&l.jsx(Lw,{row:L,token:e,initialSource:x.source,panelPort:Ec(L.route||[],a,o),onClose:()=>N(null)}),l.jsx("div",{className:"nc-cell-switcher-actions",children:l.jsx("button",{type:"button",className:"nc-cell-switcher-open",disabled:!H||!!C,onClick:z,children:H?`${f("cell-switcher-open")}: ${H.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:()=>{w(""),m(M=>!M)},children:f(p?"cell-switcher-show-active":"cell-switcher-show-all")}),l.jsx("button",{ref:V,type:"button",className:"nc-cell-switcher-close","aria-label":f("cell-switcher-close"),title:f("cell-switcher-close"),onClick:s,children:"×"})]})]})})}const NP=2e3;function jP(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 RP({token:e,nodeId:t,route:n=[]}){const[s,o]=k.useState([]),[a,u]=k.useState(!1),d=k.useRef(0),p=k.useRef(!1);return k.useEffect(()=>{let m=!0;d.current=0,p.current=!1,o([]);const v=async()=>{if(!p.current){p.current=!0;try{const w=await Rx(e,t,d.current,n);if(!m)return;u(!1);const N=(Array.isArray(w==null?void 0:w.events)?w.events:[]).filter(S=>Number.isSafeInteger(S==null?void 0:S.seq)&&S.seq>d.current);N.length&&(o(S=>S.concat(N).slice(-500)),d.current=N[N.length-1].seq),Number.isSafeInteger(w==null?void 0:w.cursor)&&w.cursor>d.current&&(d.current=w.cursor)}catch{m&&u(!0)}finally{p.current=!1}}},y=()=>{v().catch(()=>{})};y();const b=setInterval(y,NP);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:jP(m)},`${m.seq}-${m.kind}`))})]})}function My({peer:e,token:t,onBack:n}){var s;return Yn(),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(lt,{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(RP,{token:t,nodeId:e.nodeId,route:e.route||[]})})]}):null}const mh=e=>Ji(kr(e)).length===0,gh=e=>Array.isArray(e)?e.join("/"):"";function PP(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 fa(e){return{instanceId:e.ownerId,route:e.ownerRoute||[],label:e.ownerLabel,status:e.available===!1?"offline":"up"}}function _r(e,t,n,s=!1,o=!0){const a=t.instanceId;return{...e,id:mo(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:wf(e.layout,a,n)}}function AP(e,t,n,s,o=[]){const[a,u]=k.useState([]),[d,p]=k.useState(!1),[m,v]=k.useState("idle"),[y,b]=k.useState(""),[w,x]=k.useState(""),N=k.useRef([]),S=k.useRef([]),E=k.useRef(""),C=k.useRef(t),A=k.useRef(n),I=k.useRef(!1),V=k.useRef(!0),W=k.useRef(""),X=k.useMemo(()=>PP(o),[o]),Z=X.map(M=>`${M.instanceId}:${gh(M.route)}:${M.status}:${M.label}`).join("|");S.current=X,A.current=n,C.current=t,N.current=a;const K=k.useCallback(M=>Sf(M.layout,E.current,S.current),[]),G=k.useCallback((M,D=!0,$=C.current)=>{const U=z_(M,Xl()),se=N.current.some(oe=>oe.id===$);N.current=U,u(U);const ce=U.find(oe=>oe.id===$);if(D&&ce){V.current=!0;const oe=K(ce);s(oe),ce.local&&Y2(ce.name,oe)}else se&&!ce&&(V.current=!0,s(po()),b("deck non più condiviso dal nodo owner"));W2(U.filter(oe=>oe.local).map(oe=>oe.name))},[s,K]),F=k.useCallback(async M=>{let D=await Fl(e);const $=D.decks.find(U=>U.name==="main");if(D.decks.length===1&&$&&$.revision===0&&mh($.layout)){const U=U2(),se=kr(xf("main")||po());if(!mh(se)){const ce=wf(se,M,[]);D.decks[0]=await Hl(e,"main",ce,0,[])}for(const ce of U.filter(oe=>oe!=="main"))try{let oe=await av(e,ce,[]);const pe=kr(xf(ce)||po());mh(pe)||(oe=await Hl(e,ce,wf(pe,M,[]),oe.revision,[]))}catch{}D=await Fl(e)}return D},[e]),O=k.useCallback(async({migrate:M=!1}={})=>{const D=await Of(e,[]),$=mi.test(String(D.instanceId||""))?D.instanceId:"";if(!$)throw new Error("instanceId locale non disponibile");E.current=$,x($);const[U,se]=await Promise.all([M?F($):Fl(e),iv(e,[]).catch(()=>({nodes:[]}))]),ce={instanceId:$,route:[],label:"Local"},oe=U.decks.map(he=>_r(he,ce,se.nodes,!0,!0)),pe=N.current;return await Promise.all(S.current.map(async he=>{if(he.status!=="up"){oe.push(...pe.filter(me=>!me.local&&me.ownerId===he.instanceId).map(me=>({...me,ownerRoute:[...he.route],ownerLabel:he.label,available:!1})));return}try{const[me,Ve]=await Promise.all([Fl(e,he.route),iv(e,he.route).catch(()=>({nodes:[]}))]);oe.push(...me.decks.map(ut=>_r(ut,he,Ve.nodes,!1,!0)))}catch{oe.push(...pe.filter(Ve=>!Ve.local&&Ve.ownerId===he.instanceId).map(Ve=>({...Ve,ownerRoute:[...he.route],ownerLabel:he.label,available:!1})))}})),oe.sort((he,me)=>he.local===me.local?he.ownerLabel.localeCompare(me.ownerLabel)||(he.name==="main"?-1:me.name==="main"?1:he.name.localeCompare(me.name)):he.local?-1:1),oe},[e,F,Z]);k.useEffect(()=>{if(!e)return;let M=!1;const D=W.current!==e;return W.current=e,O({migrate:D}).then($=>{if(M)return;const U=N.current.find(oe=>oe.id===C.current),se=$.find(oe=>oe.id===C.current),ce=se&&(!U||se.revision>U.revision||U.available!==se.available||gh(U.ownerRoute)!==gh(se.ownerRoute));G($,D||!!ce&&!I.current),p(!0),se&&b("")}).catch($=>{M||(p(!0),b(String($.message||$)))}),()=>{M=!0}},[G,O,Z,e]);const R=k.useCallback(async(M=C.current)=>{if(!d||!I.current)return!0;const D=N.current.find($=>$.id===M);if(!D)return b(`deck inesistente: ${M}`),!1;if(D.available===!1)return b(`nodo owner offline: ${D.ownerLabel}`),!1;v("saving");try{const $=O_(kr(A.current),D.ownerId,D.ownerTopology),U=await Hl(e,D.name,$,D.revision,D.ownerRoute),se=_r(U,fa(D),D.ownerTopology,D.local,!0);return G(N.current.map(ce=>ce.id===M?se:ce),!1),I.current=!1,v("saved"),b(""),setTimeout(()=>v("idle"),1500),!0}catch($){if(v("error"),b(String($.message||$)),$.status===409&&$.data&&$.data.current){const U=N.current.find(ce=>ce.id===M),se=_r($.data.current,fa(U),U.ownerTopology,U.local,!0);G(N.current.map(ce=>ce.id===M?se:ce),!1)}return!1}},[d,e,G]);return k.useEffect(()=>{if(!d)return;if(V.current){V.current=!1;return}I.current=!0,v("saving");const M=setTimeout(R,650);return()=>clearTimeout(M)},[n,d,R]),k.useEffect(()=>{if(!d)return;const M=setInterval(async()=>{try{const D=await O(),$=N.current.find(ce=>ce.id===C.current),U=D.find(ce=>ce.id===C.current),se=U&&(!$||U.revision>$.revision||$.available!==U.available);G(D,se&&!I.current)}catch{}},5e3);return()=>clearInterval(M)},[d,O,G]),{decks:a,records:a,localNodeId:w,ready:d,saveState:m,error:y,setError:b,saveNow:R,select:async M=>{if(I.current&&!await R(C.current))throw new Error("salvataggio del deck corrente fallito: cambio annullato");const D=N.current.find($=>$.id===M);if(!D)throw new Error(`deck inesistente: ${M}`);return I.current=!1,V.current=!0,K(D)},add:async(M,D=null)=>{const $=D===Xi?N.current.find(ce=>ce.local):D?N.current.find(ce=>ce.ownerId===D):null;if(!$||$.available===!1)throw new Error("nodo owner non disponibile");const U=await av(e,M,$.ownerRoute),se=_r(U,fa($),$.ownerTopology,$.local,!0);return G([...N.current,se],!1),se},rename:async(M,D)=>{const $=N.current.find(pe=>pe.id===M);if(!$)throw new Error("deck inesistente");if(M===C.current&&I.current&&!await R(M))throw new Error(`salvataggio di "${$.name}" fallito: rinomina annullata`);const U=N.current.find(pe=>pe.id===M);if(!U)throw new Error("deck inesistente");const se=await ek(e,U.name,D,U.revision,U.ownerRoute),ce=_r(se,fa(U),U.ownerTopology,U.local,!0),oe=U.local?Xi:U.ownerId;return Hd(q2(Xl(),oe,M,ce.id)),G(N.current.map(pe=>pe.id===M?ce:pe),!1),ce},remove:async M=>{const D=N.current.find(U=>U.id===M);if(!D)throw new Error("deck inesistente");M===C.current&&(I.current=!1),await tk(e,D.name,D.revision,D.ownerRoute);const $=D.local?Xi:D.ownerId;Hd(V2(Xl(),$,M)),G(N.current.filter(U=>U.id!==M),!1)},reorder:(M,D)=>{const $=N.current.find(he=>he.id===M),U=N.current.find(he=>he.id===D);if(!$||!U)return!1;const se=$.local?Xi:$.ownerId,ce=U.local?Xi:U.ownerId;if(se!==ce)return!1;const oe=N.current.filter(he=>(he.local?Xi:he.ownerId)===se).map(he=>he.id),pe=Hd(K2(Xl(),se,M,D,oe));return G(z_(N.current,pe),!1),!0},addTileTo:async(M,D)=>{const $=N.current.find(he=>he.id===M);if(!$)throw new Error("deck inesistente");if($.available===!1)throw new Error(`nodo owner offline: ${$.ownerLabel}`);const U=Bw(D,E.current,S.current);if(!U)throw new Error("riferimento sessione non valido");const se=K($),ce=O_(kb(se,U),$.ownerId,$.ownerTopology),oe=await Hl(e,$.name,ce,$.revision,$.ownerRoute),pe=_r(oe,fa($),$.ownerTopology,$.local,!0);return G(N.current.map(he=>he.id===M?pe:he),!1),pe},localMainId:mo(null,"main"),parseDeckId:Dc}}const LP="/sw.js",Nf="nc-sw-update";let jf=null,Rf=!1,Pf=null,wS=Object.freeze({needed:!1,kind:null,version:""}),SS=!1;function xS(){typeof window<"u"&&window.dispatchEvent(new Event(Nf))}function kS(){const e=Pf||(Rf?{kind:"reload",version:""}:null);wS=Object.freeze({needed:!!e,kind:(e==null?void 0:e.kind)||null,version:(e==null?void 0:e.version)||""})}function Dy(){return wS}function TP(e){return typeof window>"u"?()=>{}:(window.addEventListener(Nf,e),()=>window.removeEventListener(Nf,e))}function Pp(e){Rf!==e&&(Rf=e,kS(),xS())}const vh="nc-auto-reload";function MP(){try{return typeof sessionStorage<"u"?sessionStorage:null}catch{return null}}function DP(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(Pf);Pf=o,kS(),a||xS();const u=s.storage===void 0?MP():s.storage;if(!o){try{u&&u.removeItem(vh)}catch{}return}if(o.kind!=="reload"||!u)return;const d=`${t}|${n}`;try{if(u.getItem(vh)===d)return;u.setItem(vh,d)}catch{return}(s.applyImpl||CS)()}function IP(e){e.addEventListener("statechange",()=>{e.state==="installed"&&navigator.serviceWorker.controller&&Pp(!0)})}function OP(){typeof navigator>"u"||!("serviceWorker"in navigator)||(navigator.serviceWorker.addEventListener("controllerchange",()=>{SS&&location.reload()}),navigator.serviceWorker.register(LP).then(e=>{jf=e,e.waiting&&Pp(!0),e.addEventListener("updatefound",()=>{const t=e.installing;t&&IP(t)}),setInterval(()=>{e.update().catch(()=>{})},3600*1e3)}).catch(()=>{}))}function CS(){SS=!0,Pp(!1);const e=jf&&jf.waiting;e?(e.postMessage({type:"SKIP_WAITING"}),setTimeout(()=>location.reload(),4e3)):location.reload()}function BP({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 ES=9,NS=24,jS="nc_side_w",Iy="nc_side_min",zP=240,Oy=new Set(["absent","present","active","unknown"]);function $P(){const e=Number(localStorage.getItem(jS));return e>=180&&e<=480?e:zP}function FP(){const e=Number(localStorage.getItem("nc_fontsize"));return e>=ES&&e<=NS?e:13}function HP(){const e={token:"",pair:""};try{const{token:t,pair:n,nextUrl:s}=BP({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 UP(e){try{return kr(xf(e))}catch{return po()}}function By(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 zy({session:e,node:t,ownerId:n,cellName:s,token:o,readonly:a=!1,panelPort:u=0,onBack:d,onCellSwitcher:p,cellSwitcherOpen:m=!1}){Yn();const[v]=hp(),[y,b]=k.useState(!1),[w,x]=k.useState(()=>window.matchMedia("(pointer: coarse)").matches),[N,S]=k.useState(null),[E,C]=k.useState(FP),[A,I]=k.useState(s||e),[V,W]=k.useState(""),[X,Z]=k.useState(""),[K,G]=k.useState(""),[F,O]=k.useState(!1),R=U=>C(se=>{const ce=Math.max(ES,Math.min(NS,se+U));return localStorage.setItem("nc_fontsize",String(ce)),ce}),B=k.useRef(()=>{}),H=k.useRef(()=>!1),L=k.useRef(()=>{}),T=k.useRef(!1),[j,z]=k.useState(!1),[M,D]=k.useState(!1),$=()=>{T.current=!T.current,z(T.current)};return k.useEffect(()=>{I(s||e),O(!1)},[s,e]),k.useEffect(()=>{let U=!0;const se=t?t.split("/"):[],ce=t?`/api/route/${t.split("/").map(encodeURIComponent).join("/")}/_`:"/api";async function oe(){let he=null,me=null;try{const _t=await(await on(`${ce}/sessions`,o)).json();Array.isArray(_t.sessions)&&(he=_t.sessions.find(je=>je.name===e))}catch{}try{const ut=await Qs(o,se);ut.available&&Array.isArray(ut.cells)&&(me=ut.cells.find(_t=>_t.tmuxSession===e))}catch{}if(!U)return;I(fp({session:e,cell:me||(s?{cell:s}:null)})),Z(typeof(me==null?void 0:me.panelUrl)=="string"?me.panelUrl.trim():""),G(typeof(me==null?void 0:me.cell)=="string"?me.cell:"");let Ve="";me?Ve=`${me.engine}${me.key?`·${me.key}`:""}`:he&&(Ve=he.attached?`attached · ${By(he.activity)}`:he.activity?By(he.activity):""),W(Ve)}oe();const pe=setInterval(oe,4e3);return()=>{U=!1,clearInterval(pe)}},[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(lt,{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?`${A} · ${t}`:A,children:A}),V&&l.jsx("small",{className:"nc-bar-sub",children:V})]}),l.jsxs("span",{className:"nc-bar-right",children:[l.jsx("button",{onClick:()=>R(-1),title:f("zoom-out"),children:l.jsx(lt,{name:"zoomOut",size:18})}),l.jsx("button",{onClick:()=>R(1),title:f("zoom-in"),children:l.jsx(lt,{name:"zoomIn",size:18})}),l.jsx("button",{onClick:()=>x(U=>!U),title:f("composer"),children:l.jsx(lt,{name:"keyboard",size:20})}),l.jsx("button",{onClick:()=>b(U=>!U),title:f("files"),children:l.jsx(lt,{name:"folder",size:20})}),X&&l.jsx("button",{onClick:()=>O(U=>!U),title:f("panel"),"aria-pressed":F,children:l.jsx(lt,{name:"monitor",size:20})})]})]}),l.jsxs("div",{className:"nc-termwrap",children:[l.jsx(op,{session:e,node:t,token:o,readonly:a,takeSize:!0,sendRef:B,composerRef:H,actionRef:L,ctrlRef:T,setCtrlArmed:z,onFiles:S,fontSize:E,selectionMode:M,onSelectionModeChange:D,keyboardGesture:v.terminalKeyboardGesture}),F&&X&&K&&l.jsx(cp,{cellId:K,panelUrl:X,route:t?t.split("/"):[],panelPort:u,token:o,title:A})]}),l.jsx(s2,{onKeyboard:()=>x(U=>!U),onCellSwitcher:p,cellSwitcherOpen:m,send:U=>B.current(U),action:U=>L.current(U),ctrlArmed:j,onCtrl:$,selectionMode:M,onSelectionMode:D,keepKeyboardClosed:v.keybarKeepsKeyboardClosed,showEnter:v.showKeybarEnter,keybarLayout:v.keybarLayout}),w&&l.jsx(Rw,{submitText:U=>H.current(U),token:o,session:e,node:t,ownerId:n,readonly:a,keepKeyboardClosedOnVoice:v.voiceKeepsKeyboardClosed}),y&&l.jsx(bw,{session:e,node:t,token:o,filesEvent:N,onClose:()=>b(!1)})]})}function WP(){Yn();const[e]=k.useState(HP),[t,n]=k.useState(e.token),[s,o]=k.useState(e.pair||""),a=k.useCallback(()=>{o("");try{sessionStorage.removeItem("nc_pair")}catch{}},[]),[u,d]=k.useState(!1),p=IN(),[m]=k.useState(()=>H2(typeof location<"u"?location.pathname:"/")),[v,y]=k.useState(m.id),b=v===mo(null,gi),[w,x]=k.useState(null),N=ee=>{const Se=Xs(ee);x(Se?{...Se,...typeof(ee==null?void 0:ee.cellName)=="string"&&ee.cellName?{cellName:ee.cellName}:{}}:null)},[S,E]=k.useState([]),[C,A]=k.useState([]),[I,V]=k.useState([]),[W,X]=k.useState(!1),[Z,K]=k.useState(null),[G,F]=k.useState(()=>m.ownerId?po():UP(m.name)),[O,R]=k.useState(null),[B,H]=k.useState(null),L=ee=>H(Xs(ee)),[T,j]=k.useState(null),z=Ff(t,p),M=k.useMemo(()=>(z||[]).filter(ee=>ee.instanceId).map(ee=>({instanceId:ee.instanceId,route:ee.route,label:ee.label,status:ee.status})),[z]),D=AP(t,v,G,F,M),$=D.decks;k.useEffect(()=>{const ee=new Map;for(const Se of z||[]){const Me=(Se.route||[Se.name]).join("/"),Je=new Set((Se.sessions||[]).map(et=>et.name));for(const et of Se.cells||[])!et.cell||!et.tmuxSession||et.cell===et.tmuxSession||Je.has(et.cell)||ee.set(`${Me}:${et.cell}`,`${Me}:${et.tmuxSession}`)}F(Se=>$k(Se,ee))},[z]),k.useEffect(()=>{D.localNodeId&&F(ee=>{const Se=Sf(ee,D.localNodeId,M);return JSON.stringify(Se)===JSON.stringify(ee)?ee:Se})},[M,D.localNodeId]);const[U,se]=k.useState(null),[ce,oe]=k.useState(null),pe=k.useRef(0),[he,me]=k.useState(!1),[Ve,ut]=k.useState($P),[_t,je]=k.useState(!b),[Ct,hn]=k.useState(()=>b?localStorage.getItem(Iy)==="1":!0),[_n,Yt]=k.useState(!1),[xt,Ot]=k.useState("nodes"),[Ut,jt]=k.useState(!1),[It,Mt]=k.useState(""),[Rt,fn]=k.useState(!1),ie=(ee="nodes",Se=!1,Me="")=>{Ot(ee),jt(Se),Mt(Me),Yt(!0)},[Qe,ge]=k.useState(!1),[Ge,ct]=k.useState({deviceDefault:"",localNodeId:"",localNameDefault:""}),[re,ne]=k.useState(!1),[_e,be]=k.useState(0),[ke,it]=k.useState({});k.useEffect(()=>{try{localStorage.setItem(jS,String(Ve))}catch{}},[Ve]),k.useEffect(()=>{try{localStorage.setItem(Iy,Ct?"1":"")}catch{}},[Ct]),k.useEffect(()=>{if(!t)return;let ee=!1;return Promise.all([Yy(t),on("/api/config",t).then(Se=>Se.json())]).then(([Se,Me])=>{ee||(ct({deviceDefault:Se.deviceName||"",localNodeId:Se.nodeId||"",localNameDefault:Se.localName||""}),ne(!!Me.readonlyDefault),be(Number.isInteger(Me.panelPort)?Me.panelPort:0),it(Me.nodePanelPorts&&typeof Me.nodePanelPorts=="object"&&!Array.isArray(Me.nodePanelPorts)?Me.nodePanelPorts:{}),(Se.firstRun===!0&&!Me.readonlyDefault||s)&&ge(!0))}).catch(()=>{}),()=>{ee=!0}},[t,s]);const[ht,dt]=k.useState({}),Pt=k.useRef(z);k.useEffect(()=>{Pt.current=z},[z]);const St=k.useCallback(async()=>{try{const et=await(await on("/api/sessions",t)).json();et.error||E(et.sessions||[])}catch{}let ee=null,Se=null;try{ee=await Qs(t)}catch(Je){Se=Je}const Me=$f({fs:ee,error:Se});Me.kind==="data"?(A(Me.cells),V(Me.capabilities),X(!1),K(null)):Me.kind==="stale"?(X(!0),K(null)):(A([]),V([]),X(!1),K(Me.reason||""))},[t]);k.useEffect(()=>{let ee=!1;const Se=async()=>{const Je=[[],...(Pt.current||[]).filter(bt=>bt.kind!=="vl"&&bt.status==="up").map(bt=>Array.isArray(bt.route)&&bt.route.length?bt.route:[bt.name])],et=await Promise.all(Je.map(async bt=>{const ln=Sa(bt);try{const At=await nk(t,bt);return[ln,{hostCell:At&&typeof At.hostCell=="string"?At.hostCell:null,hostLease:At&&At.host&&typeof At.host.lease=="string"?At.host.lease:null,hostRevision:Number.isInteger(At&&At.revision)?At.revision:0,threadStatus:At&&Oy.has(At.threadStatus)?At.threadStatus:"unknown"}]}catch{return[ln,{error:!0}]}}));ee||dt(bt=>{let ln=!1;const At={...bt};for(const vi of et){if(!vi)continue;const[pn,Nt]=vi;At[pn]=Nt.error?{...bt[pn]||{},threadStatus:"unknown"}:Nt,ln=!0}return ln?At:bt})};Se();const Me=setInterval(Se,4e3);return()=>{ee=!0,clearInterval(Me)}},[t]),k.useEffect(()=>{if(!p)return;St();const ee=setInterval(St,4e3);return()=>clearInterval(ee)},[p,St]);const yt=k.useCallback(async(ee,Se=[])=>{const Me=Sa(Se),Je=ht[Me]&&ht[Me].hostRevision||0;try{const et=await ik(t,ee,Je,Se);dt(bt=>({...bt,[Me]:{hostCell:et.hostCell||null,hostLease:et.host&&typeof et.host.lease=="string"?et.host.lease:null,hostRevision:Number.isInteger(et.revision)?et.revision:Je,threadStatus:Oy.has(et.threadStatus)?et.threadStatus:"unknown"}}))}catch(et){window.alert(f(bv(et)))}},[t,ht]),zt=k.useCallback(async(ee=[])=>{const Se=Sa(ee),Me=ht[Se]&&ht[Se].hostRevision||0;try{const Je=await sk(t,Me,ee);return dt(et=>({...et,[Se]:{hostCell:Je.hostCell||null,hostLease:null,hostRevision:Number.isInteger(Je.revision)?Je.revision:Me,threadStatus:"unknown"}})),!0}catch(Je){return window.alert(f(bv(Je))),!1}},[t,ht]);k.useEffect(()=>{let ee=!1;const Se=()=>{on("/api/config",t).then(Je=>Je.json()).then(Je=>{ee||DP(Je.version,Je.uiVersion,"0.9.20")}).catch(()=>{})};Se();const Me=setInterval(Se,6e4);return()=>{ee=!0,clearInterval(Me)}},[t]);const Ze=new Set([...S.map(ee=>ee.name),...z.flatMap(ee=>ee.sessions.map(Se=>Se.key))]),Q=Ji(G),Ne=ee=>F(Se=>{const Me=Bw(ee,D.localNodeId,M)||ee,Je=kb(Se,Me);return Je===Se&&Ji(Se).length>=9&&D.setError(f("grid-full")),Je}),Ue=async(ee,Se=[])=>{try{await Mf(t,ee,Se)}catch{return}const Me=Se.length?`${Se.join("/")}:${ee}`:ee;F(Je=>vc(Je,Me)),St()},Oe=async(ee,Se,Me=[])=>{try{await Vy(t,ee,Se,Me)}catch{return}St()},Ae=async(ee,Se,Me=[])=>{await Wy(t,{cell:ee,enabled:!!Se},Me),St()},Et=async ee=>{if(!U)return;const{cell:Se}=U,Me=Array.isArray(U.route)?U.route:[];if(ee.action==="up"){const et=await Tf(t,{cell:Se,boot:!!ee.boot,...ee.engine?{engine:ee.engine}:{},...ee.model!==void 0?{model:ee.model}:{},...ee.permissionPolicy?{permissionPolicy:ee.permissionPolicy}:{}},Me),bt=Gf(et);bt&&D.setError(bt.text)}else await uc(t,{cell:Se,boot:!!ee.boot},Me);const Je=ee.action==="up"?!!ee.boot:ee.boot?!1:!!U.boot;oe({id:++pe.current,cell:Se,route:Me,enabled:Je}),St()},kt=k.useCallback(ee=>{oe(Se=>(Se==null?void 0:Se.id)===ee?null:Se)},[]),Y=async ee=>{if(!(!(ee!=null&&ee.direct)||he)){me(!0);try{await Bf(t,ee.name,ee.tunnelStatus==="up"?"down":"up")}finally{me(!1)}}},ae=async(ee,Se)=>{const Me=String(Se||"").trim();return!(ee!=null&&ee.direct)||!yo(Me)?!1:(await Qy(t,ee.name,Me),!0)},ye=ee=>{const Se=$.find(Me=>Me.id===ee);if(!Se)return!1;try{const Me=window.open(Fd(Se,t),"_blank");return Me&&(Me.opener=null),!!Me}catch{return!1}},Le=async ee=>{if(!ee||ee===v)return;const Se=await D.select(ee),Me=D.records.find(Je=>Je.id===ee);y(ee),F(Se),R(null),H(null);try{history.replaceState(null,"",Fd(Me||ee,null))}catch{}},De=async(ee,Se)=>{const Me=await D.add(ee,Se);await Le(Me.id)},Ee=async(ee,Se)=>{const Me=await D.rename(ee,Se);if(ee===v){y(Me.id),F(Sf(Me.layout,D.localNodeId,M)),R(null),H(null);try{history.replaceState(null,"",Fd(Me,null))}catch{}}},Xe=async ee=>{await D.remove(ee),ee===v&&await Le(D.localMainId)},ft=async(ee,Se)=>{!Se||Se===v||(await D.addTileTo(Se,ee),F(Me=>vc(Me,ee)))};if(!t)return l.jsxs("div",{className:"nc-auth",children:[l.jsx("p",{children:f("auth-prompt")}),l.jsx("input",{onChange:ee=>n(ee.target.value.trim()),placeholder:"token"}),l.jsxs("label",{children:[l.jsx("input",{type:"checkbox",checked:u,onChange:ee=>d(ee.target.checked)})," ",f("remember-device")]}),l.jsx("button",{onClick:()=>{(u?localStorage:sessionStorage).setItem("nc_token",t)},children:"ok"})]});const $t=l.jsxs(l.Fragment,{children:[_n&&l.jsx(fP,{token:t,initialTab:xt,initialLocation:It,startNewCell:Ut,onClose:()=>{Yt(!1),jt(!1),Mt("")}}),Qe&&l.jsx(pP,{token:t,initialPair:s,...Ge,onPairDone:a,onDone:()=>ge(!1)}),l.jsx(bP,{token:t})]});if(!p)return T?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-single-overlay",children:l.jsx(My,{peer:T,token:t,onBack:()=>j(null)})}),$t]}):w?l.jsxs(l.Fragment,{children:[l.jsx(zy,{session:w.session,node:w.node,ownerId:w.ownerId,cellName:w.cellName,token:t,readonly:re,panelPort:Ec(w.node?w.node.split("/"):[],ke,_e),onBack:()=>x(null),onCellSwitcher:()=>fn(!0),cellSwitcherOpen:Rt}),Rt&&l.jsx(EP,{token:t,current:w,panelPort:_e,nodePanelPorts:ke,onPick:ee=>{N(ee),fn(!1)},onClose:()=>fn(!1)}),$t]}):l.jsxs(l.Fragment,{children:[l.jsx(s1,{onPick:N,token:t,onSettings:ie,onOpenVlSession:j,hostByRoute:ht,onDesignateCell:yt,onClearHostCell:zt}),$t]});const Be=b||!_t;return l.jsxs("div",{className:"nc-workspace",children:[Be&&l.jsx(R2,{sessions:S,cells:C,activeSessions:Q,nodeGroups:z,token:t,onPeekOpen:()=>fn(!1),overlayOpen:Rt,fleetCapabilities:I,fleetStale:W,fleetOff:Z,bootSettlement:ce,onBootSettlementApplied:kt,localNodeId:D.localNodeId,hostByRoute:ht,onDesignateCell:yt,onClearHostCell:zt,onPick:L,onAddTile:Ne,onPower:se,onBoot:Ae,onBootError:ee=>D.setError(String((ee==null?void 0:ee.message)||ee)),onNodePower:Y,onNodeRename:ae,onKill:Ue,onVisibility:Oe,onNew:()=>ie("fleet",!0),onSettings:ie,onOpenVlSession:j,width:Ve,collapsed:Ct,onResize:ut,onToggleCollapse:()=>hn(ee=>!ee)}),l.jsxs("div",{className:"nc-workspace-main",children:[l.jsx(dj,{decks:$,currentDeck:v,onCreate:De,onRename:Ee,onDelete:Xe,onReorder:D.reorder,onOpenWindow:ye,onNavigate:Le,saveState:D.saveState,error:D.error,sidebarVisible:Be,onToggleSidebar:b?null:()=>je(ee=>!ee)}),l.jsx(O2,{layout:G,onLayoutChange:F,token:t,readonly:re,sessionsAlive:Ze,focusSession:O,onFocus:R,onOpenSingle:L,decks:$,currentDeck:v,onSendToDeck:ft,cells:C,nodeGroups:z,panelPort:_e,nodePanelPorts:ke})]}),T&&l.jsx("div",{className:"nc-single-overlay",children:l.jsx(My,{peer:T,token:t,onBack:()=>j(null)})}),B&&l.jsx("div",{className:"nc-single-overlay",children:l.jsx(zy,{session:B.session,node:B.node,ownerId:B.ownerId,cellName:fp({session:B.session,node:B.node,ownerId:B.ownerId,cells:C,nodeGroups:z}),token:t,readonly:re,panelPort:Ec(B.node?B.node.split("/"):[],ke,_e),onBack:()=>H(null)})}),U&&l.jsx(hc,{cell:U,token:t,route:Array.isArray(U.route)?U.route:[],onConfirm:Et,onClose:()=>se(null)}),$t]})}function KP(){Yn();const e=k.useSyncExternalStore(TP,Dy,Dy);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:CS,children:f("reload")})]})}OP();fx.createRoot(document.getElementById("root")).render(l.jsxs(ox.StrictMode,{children:[l.jsx(WP,{}),l.jsx(KP,{})]}));
|
|
93
|
+
`],{type:"application/json"}),L=URL.createObjectURL(H),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:H=>a(H.target.value),children:s.map(H=>l.jsxs("option",{value:H.key,children:[H.label,H.status!=="up"?` · ${H.status}`:""]},H.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:E,onChange:H=>C(Number(H.target.value)),disabled:n,children:[300,900,1800,3600].map(H=>l.jsxs("option",{value:H,children:[H/60," min"]},H))}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||(d==null?void 0:d.verbose)===!0,onClick:()=>O(()=>ov(e,!0,E,u.route)),children:f("enable")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||(d==null?void 0:d.verbose)!==!0,onClick:()=>O(()=>ov(e,!1,E,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:A,onChange:H=>I(H.target.value),children:[l.jsx("option",{value:"all",children:f("diagnostics-all-levels")}),["debug","info","warn","error"].map(H=>l.jsx("option",{value:H,children:H},H))]}),l.jsx("input",{"aria-label":f("diagnostics-component"),placeholder:f("diagnostics-component"),value:V,onChange:H=>W(H.target.value)})]}),l.jsxs("div",{className:"nc-set-row",children:[l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:w,onChange:H=>x(H.target.checked)})," ",f("diagnostics-pause")]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:N,onChange:H=>S(H.target.checked)})," ",f("diagnostics-autoscroll")]})]}),l.jsx("pre",{ref:Z,className:"nc-diag-log","aria-label":f("diagnostics-log"),children:F||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:B,children:f("diagnostics-export")}),l.jsx("button",{type:"button",className:"nc-btn danger",disabled:n,onClick:()=>{window.confirm(f("diagnostics-clear-confirm"))&&O(async()=>{const H=await Xx(e,u.route);return X.current=0,v([]),H})},children:f("diagnostics-clear")})]}),y&&l.jsx("div",{className:"nc-err",children:y})]})}function hP({token:e,settings:t,readonly:n,refresh:s,roster:o,section:a,setSection:u}){const[d,p]=k.useState(null),[m,v]=k.useState(null),[y,b]=k.useState(!1),[w,x]=k.useState(!1),[N,S]=k.useState(null),[E,C]=k.useState(!0),[A,I]=k.useState(!1);k.useEffect(()=>{S(t&&t.update||null),C(!t||t.autoUpdate!==!1),I(!!(t&&t.alternateScreen))},[t]);const V=async()=>{p(null),v(null),x(!0);try{const R=await Px(e);v(R.note||"ok"),b(!1)}catch(R){p(String(R.message||R))}x(!1)},W=async()=>{p(null),v(null),x(!0);try{const R=await Kx(e);v(`${R.note||"ok"}${R.target?` (${R.target})`:""}`)}catch(R){p(String(R.message||R))}x(!1)},X=async R=>{p(null),v(null),x(!0);try{await _h(e,{autoUpdate:R}),C(R),s&&await s()}catch(B){p(String(B.message||B))}x(!1)},Z=async R=>{p(null),v(null),x(!0);try{await _h(e,{alternateScreen:R}),I(R),s&&await s()}catch(B){p(String(B.message||B))}x(!1)},K=async()=>{p(null),v(null),x(!0);try{S(await qx(e))}catch(R){p(String(R.message||R))}x(!1)},G=async()=>{p(null),v(null),x(!0);try{const R=await Vx(e);S(R),v(f("npm-update-restarting"))}catch(R){p(String(R.message||R))}x(!1)},F=()=>{window.confirm(f("composer-clear-confirm"))&&(p(null),m2()?(window.dispatchEvent(new Event(vf)),v(f("composer-clear-done"))):p(f("composer-clear-failed")))},O=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",{}),O&&O.installed?f("service-installed"):f("service-missing"),O&&O.installed?` · ${O.active?f("service-active"):f("service-inactive")}`:"",O?` · boot ${O.boot?"on":"off"}`:""]}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||w,title:n?f("settings-readonly"):"",onClick:W,children:f("service-regenerate")})}),l.jsx(aP,{token:e,readonly:n}),l.jsx(lP,{})]}),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:E,disabled:n||w||N&&!N.supported,onChange:R=>X(R.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:f("npm-auto-update")}),l.jsx("small",{children:f("npm-auto-update-help")})]})]}),N&&l.jsxs("div",{className:"nc-set-info",children:[f("npm-update-current")," v",N.current,N.latest?` · ${f("npm-update-latest")} v${N.latest}`:""," · ",f(N.supported?N.phase==="idle"&&N.checked!==!0?"npm-update-never":`npm-update-${N.phase}`:"unsupported")]}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||w||!N||!N.supported,onClick:K,children:f("npm-update-check")}),N&&N.available&&l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||w||N.phase==="installing",onClick:G,children:f("npm-update-install")})]}),N&&N.lastError&&l.jsx("div",{className:"nc-err",children:N.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||w,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:F,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:A,disabled:n||w,onChange:R=>Z(R.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:f("alternate-screen")}),l.jsx("small",{children:f("alternate-screen-help")})]})]})]}),l.jsx(dP,{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:w,onClick:()=>b(!1),children:f("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:w,onClick:V,children:f("confirm")})]})]}),m&&l.jsx("div",{className:"nc-set-note",children:m}),d&&l.jsx("div",{className:"nc-err",children:d})]})}function fP({token:e,onClose:t,initialTab:n="nodes",initialLocation:s="",startNewCell:o=!1}){Yn();const a=n==="diagnostics"?"diagnostics":"general",[u,d]=k.useState(n==="diagnostics"?"system":n),p=k.useRef(null),m=k.useRef(null),[v,y]=k.useState({start:!1,end:!1}),[b,w]=k.useState(a),[x,N]=k.useState(null),[S,E]=k.useState([]),[C,A]=k.useState([]),[I,V]=k.useState(!1),[W,X]=k.useState(null),[Z,K]=k.useState(0),G=Ff(e,!0,Z),F=k.useCallback(()=>{const R=p.current;if(!R)return;const B=R.scrollWidth>R.clientWidth+1,H={start:B&&R.scrollLeft>1,end:B&&R.scrollLeft+R.clientWidth<R.scrollWidth-1};y(L=>L.start===H.start&&L.end===H.end?L:H)},[]);k.useEffect(()=>{const R=p.current;if(!R)return;const B=typeof ResizeObserver=="function"?new ResizeObserver(F):null;return B==null||B.observe(R),window.addEventListener("resize",F),F(),()=>{B==null||B.disconnect(),window.removeEventListener("resize",F)}},[F]),k.useEffect(()=>{var B,H;(H=(B=m.current)==null?void 0:B.scrollIntoView)==null||H.call(B,{behavior:"smooth",block:"nearest",inline:"nearest"});const R=window.requestAnimationFrame?window.requestAnimationFrame(F):setTimeout(F,0);return()=>{window.cancelAnimationFrame?window.cancelAnimationFrame(R):clearTimeout(R)}},[u,F]);const O=k.useCallback(async()=>{var R;try{const B=await Yy(e);N(B),X(null)}catch(B){X(String(B.message||B))}try{const H=(await jx(e)).peers||[];let L=[],T=[];try{const[j,z]=await Promise.all([on("/api/config",e).then(U=>U.json()).catch(()=>null),Xy(e).catch(()=>null)]),M=j&&typeof j.instanceId=="string"?j.instanceId:"",D=[{instanceId:M||null,route:[],label:null},...rb(z,M)],$=await Promise.all(D.map(async U=>{try{return{ok:!0,peers:((await Gy(e,U.route)).nodes||[]).map(oe=>sb(oe,U)).filter(Boolean)}}catch(se){return{ok:!1,owner:U,error:se}}}));for(const U of $){if(U.ok){L.push(...U.peers);continue}U.owner.route.length!==0&&T.push({instanceId:U.owner.instanceId,label:U.owner.label,route:U.owner.route,failure:/timeout/i.test(String(((R=U.error)==null?void 0:R.message)||U.error))?"timeout":"unreachable"})}}catch{}A(T),E([...H,...L])}catch(B){X(String(B.message||B))}},[e]);return k.useEffect(()=>{O();const R=setInterval(O,5e3);return()=>clearInterval(R)},[O]),k.useEffect(()=>{let R=!1;return on("/api/config",e).then(B=>B.json()).then(B=>{R||V(!!B.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(lt,{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(lt,{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:F,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(oP,{token:e,nodes:S,roster:G,settings:x,readonly:I,vlUnavailable:C,refresh:O,refreshAliases:()=>K(R=>R+1)}),u==="fleet"&&l.jsx(FR,{token:e,readonly:I,startNewCell:o,initialLocation:s,targets:G.map(R=>({route:R.route,label:R.label||R.name,status:R.status}))}),u==="audio"&&l.jsx(cP,{token:e,readonly:I,nodes:S,settings:x}),u==="input"&&l.jsx(uP,{}),u==="system"&&l.jsx(hP,{token:e,settings:x,readonly:I,refresh:O,roster:G,section:b,setSection:w})]})]})})}function pP({token:e,initialPair:t,deviceDefault:n="",localNodeId:s="",localNameDefault:o="",onPairDone:a,onDone:u}){Yn();const[d,p]=k.useState(t?"pair":"welcome"),[m,v]=k.useState(!1),[y,b]=k.useState(null),[w,x]=k.useState(null),N=async()=>{v(!0),b(null);try{await _h(e,{wizardDone:!0}),a&&a(),u()}catch(S){b(String(S.message||S)),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:N,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(nS,{token:e,initial:t||"",autoStart:!!t,deviceDefault:n,localNodeId:s,localNameDefault:o,onBusyChange:v,onSuccess:async S=>{x(S&&S.authorizedKeys?{line:S.authorizedKeys,note:S.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")}),w&&l.jsx(Sp,{line:w.line,note:w.note}),l.jsx("div",{className:"nc-sheet-actions",children:l.jsx("button",{className:"nc-btn primary",disabled:m,onClick:N,children:f("finish")})})]}),y&&l.jsx("div",{className:"nc-err",children:y})]})})}function mP(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 gP=6e3,vP=12e3;function _P({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(lt,{name:"x",size:14})})]})}function yP({ask:e,token:t,onAnswered:n,onDismiss:s}){const[o,a]=k.useState(""),[u,d]=k.useState(!1),[p,m]=k.useState(null),[v,y]=k.useState(!1),b=async x=>{const N=String(x||"").trim();if(!(!N||u)){m(null),d(!0);try{await Jx(t,e.id,N),n(e.id)}catch(S){m(String(S.message||S))}d(!1)}},w=async()=>{if(!v){y(!0);try{await Zx(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:w,children:l.jsx(lt,{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(x=>l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:u,onClick:()=>b(x),children:x},x))}),l.jsxs("div",{className:"nc-ask-reply",children:[l.jsx("textarea",{rows:2,placeholder:f("ask-reply-ph"),value:o,disabled:u,onChange:x=>a(x.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 bP({token:e}){const[t]=Yn(),[n]=yS(),[s,o]=k.useState([]),[a,u]=k.useState([]),[d,p]=k.useState(()=>{try{return/(?:^|[#&])ask=/.test(location.hash)}catch{return!1}}),m=k.useRef(0),v=k.useRef(null);v.current||(v.current=iP());const y=k.useRef({enabled:n,lang:t});y.current={enabled:n,lang:t};const b=k.useCallback(S=>{o(E=>E.filter(C=>C.key!==S))},[]),w=k.useCallback(S=>{const E=`t${m.current+=1}`;o(A=>[...A.slice(-3),{...S,key:E}]),setTimeout(()=>b(E),S.urgency==="high"?vP:gP);const C=y.current;if(C.enabled)try{v.current.enqueue(S,JR(S,C.lang))}catch{}},[b]);k.useEffect(()=>{n||v.current.stop()},[n]),k.useEffect(()=>{const S=()=>{(document.visibilityState!=="visible"||!document.hasFocus())&&v.current.stop()},E=()=>v.current.stop();return document.addEventListener("visibilitychange",S),window.addEventListener("blur",S),window.addEventListener(Cf,E),()=>{document.removeEventListener("visibilitychange",S),window.removeEventListener("blur",S),window.removeEventListener(Cf,E),typeof v.current.dispose=="function"?v.current.dispose():v.current.stop()}},[]),k.useEffect(()=>{if(!e)return;let S=!1;Qx(e).then(C=>{S||u(C.asks||[])}).catch(()=>{});const E=mP(e,C=>{C.type==="notify"?w(C):C.type==="ask"&&C.ask&&C.ask.id?u(A=>A.some(I=>I.id===C.ask.id)?A:[...A,C.ask]):C.type==="ask-answered"&&C.id?u(A=>A.filter(I=>I.id!==C.id)):C.type==="ask-dismissed"&&C.id&&u(A=>A.filter(I=>I.id!==C.id))});return()=>{S=!0,E()}},[e,w]);const x=S=>u(E=>E.filter(C=>C.id!==S)),N=S=>u(E=>E.filter(C=>C.id!==S));return l.jsxs(l.Fragment,{children:[s.length>0&&l.jsx("div",{className:"nc-ntf-toasts",children:s.map(S=>l.jsx(_P,{n:S,onClose:()=>b(S.key)},S.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(lt,{name:"x",size:16})})]}),l.jsx("div",{className:"nc-ask-panel-body",children:a.map(S=>l.jsx(yP,{ask:S,token:e,onAnswered:x,onDismiss:N},S.id))})]})]})}const wP=4e3;async function SP(e){const t=await on("/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 ph(e,t=[]){var d;const[n,s]=await Promise.allSettled([t.length?If(e,t):SP(e),Qs(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 bS(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 xP(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=Kf(v,y),w=bS(v,a,u);n.push({key:Ca(d,v.tmuxSession||v.cell),session:v.tmuxSession,route:d,cellName:v.cell,label:v.cell,node:d.length?d.join("/"):"",nodeLabel:p,live:w,selectable:w,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 kP(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",qf(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("/"),mc({...u,route:d,cells:p,sessions:m,unmanaged:m.filter(y=>!v.has(y.name))}).rawItems)}return t}function CP(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 Vs(m,n,"all",gs(s,a)).map(v=>p.get(v.key))})}function EP({token:e,current:t,onPick:n,onClose:s,panelPort:o=0,nodePanelPorts:a={}}){const[u,d]=k.useState(xv),[p,m]=k.useState(!1),[v,y]=k.useState(!1),[b,w]=k.useState(""),[x,N]=k.useState(null),[S,E]=k.useState(""),[C,A]=k.useState(""),I=k.useRef(null),V=k.useRef(null),W=k.useMemo(()=>xP(u),[u]),X=k.useMemo(()=>kP(u),[u]),{pins:Z,orders:K,canMoveRoster:G,moveRoster:F,stepRoster:O}=Uf(),R=k.useMemo(()=>CP(W,X,Z,K),[W,X,Z,K]),B=k.useMemo(()=>p?R:R.filter(M=>M.selectable||M.degraded&&M.active),[R,p]),H=k.useMemo(()=>W.find(M=>M.key===S&&M.selectable),[W,S]),L=k.useMemo(()=>x?W.find(M=>M.key===x.key):null,[W,x]);k.useEffect(()=>{var $;const M=document.activeElement;($=V.current)==null||$.focus();const D=U=>{U.key==="Escape"&&s()};return document.addEventListener("keydown",D),()=>{var U;document.removeEventListener("keydown",D),(U=M==null?void 0:M.focus)==null||U.call(M)}},[s]),k.useEffect(()=>{let M=!0,D=!1;const $=async()=>{if(D)return;D=!0;const se=xv(),ce=Array.isArray(se.nodeGroups)?se.nodeGroups:[],oe=ph(e),pe=je=>je.kind!=="vl"&&Array.isArray(je.route)&&je.route.length>0,he=await Promise.all(ce.filter(pe).map(async je=>({group:je,result:await ph(e,je.route)}))),me=await oe;if(!M)return;const Ve=new Map(he.map(({group:je,result:Ct})=>[JSON.stringify(je.route||[]),Ct])),ut=ce.map(je=>{if(!pe(je))return{...je,switcherFresh:!1};const Ct=Ve.get(JSON.stringify(je.route||[]));return Ct?{...je,sessions:Ct.sessions||je.sessions||[],cells:Ct.cells||je.cells||[],switcherFresh:Ct.fresh}:{...je,switcherFresh:!1}}),_t=Nb({...se,sessions:me.sessions||se.sessions||[],cells:me.cells||se.cells||[],localFresh:me.fresh,nodeGroups:ut,refreshedAt:Date.now()});d(_t),y(!0),D=!1};$();const U=setInterval($,wP);return()=>{M=!1,clearInterval(U)}},[e]);const T=M=>M.degraded?f("cell-degraded"):M.verified?M.selectable?M.working?f("cell-working"):f("cell-idle"):f("cell-off"):f("cell-switcher-not-confirmed"),j=M=>{if(w(""),!M.selectable){w(M.verified?f("cell-switcher-not-active"):f("cell-switcher-not-confirmed"));return}E(M.key)},z=async()=>{const M=H;if(!M){w(f("cell-switcher-select"));return}w(""),A(M.key);try{const D=await ph(e,M.route),$=(D.cells||[]).find(U=>(U==null?void 0:U.cell)===M.cellName&&(U==null?void 0:U.tmuxSession)===M.session);if(D.fresh!==!0){w(f("cell-switcher-verify-failed"));return}if(!bS($,D.sessions,D.fresh)){w(f("cell-switcher-not-active"));return}n({session:M.session,...M.node?{node:M.node}:{},cellName:M.cellName}),s()}catch{w(f("cell-switcher-verify-failed"))}finally{A("")}};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:M=>M.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&&B.length===0&&l.jsx("div",{className:"nc-empty",role:"status",children:f("cell-switcher-empty-active")}),B.map(M=>{const D=(t==null?void 0:t.session)===M.session&&((t==null?void 0:t.node)||"")===M.node,$=S===M.key,U=T(M),se=yf(f,M.activity),ce=bf(f,M.telemetry),oe=[se,ce].filter(Boolean).join(" · "),pe=M.node||"local",he=X.get(pe)||W.filter(me=>(me.node||"local")===pe);return l.jsxs("div",{className:`nc-cell-switcher-row${D?" current":""}${$?" selected":""}${M.selectable?"":" off"}`,"data-roster-key":M.key,"data-position":pe,children:[l.jsx(Gi,{position:pe,itemKey:M.key,label:M.cellName,canMove:G,onMove:(me,Ve)=>F(pe,me,Ve,he),onStep:me=>O(pe,M.key,me,he)}),l.jsx("button",{type:"button",className:"nc-cell-switcher-peek",title:f("cell-peek"),"aria-label":`${f("cell-peek")}: ${M.cellName}`,onClick:me=>{me.stopPropagation(),N({key:M.key,source:"preview"})},children:l.jsx("span",{className:`nc-cell-switcher-dot${M.degraded?" warn":M.live?` on${M.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")}: ${M.cellName}`,onClick:me=>{me.stopPropagation(),N({key:M.key,source:"stream"})},children:"▶"}),M.panelUrl&&l.jsx("button",{type:"button",className:"nc-cell-switcher-act",title:f("cell-peek-panel"),"aria-label":`${f("cell-peek-panel")}: ${M.cellName}`,onClick:me=>{me.stopPropagation(),N({key:M.key,source:"panel"})},children:"▣"})]}),l.jsx("button",{type:"button",className:"nc-cell-switcher-row-select","aria-current":D?"true":void 0,"aria-pressed":$,"aria-disabled":!M.selectable,disabled:C===M.key,onClick:()=>j(M),children:l.jsxs("span",{className:"nc-cell-switcher-copy",children:[l.jsx("b",{children:M.cellName}),l.jsx("small",{className:"nc-cell-switcher-state",children:U}),l.jsx("small",{children:[M.nodeLabel,M.subtitle].filter(Boolean).join(" · ")}),oe&&l.jsx("small",{className:"nc-cell-switcher-telemetry",children:oe})]})})]},M.key)})]}),b&&l.jsx("div",{className:"nc-cell-switcher-notice",role:"status",children:b}),x&&L&&l.jsx(Lw,{row:L,token:e,initialSource:x.source,panelPort:Ec(L.route||[],a,o),onClose:()=>N(null)}),l.jsx("div",{className:"nc-cell-switcher-actions",children:l.jsx("button",{type:"button",className:"nc-cell-switcher-open",disabled:!H||!!C,onClick:z,children:H?`${f("cell-switcher-open")}: ${H.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:()=>{w(""),m(M=>!M)},children:f(p?"cell-switcher-show-active":"cell-switcher-show-all")}),l.jsx("button",{ref:V,type:"button",className:"nc-cell-switcher-close","aria-label":f("cell-switcher-close"),title:f("cell-switcher-close"),onClick:s,children:"×"})]})]})})}const NP=2e3;function jP(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 RP({token:e,nodeId:t,route:n=[]}){const[s,o]=k.useState([]),[a,u]=k.useState(!1),d=k.useRef(0),p=k.useRef(!1);return k.useEffect(()=>{let m=!0;d.current=0,p.current=!1,o([]);const v=async()=>{if(!p.current){p.current=!0;try{const w=await Rx(e,t,d.current,n);if(!m)return;u(!1);const N=(Array.isArray(w==null?void 0:w.events)?w.events:[]).filter(S=>Number.isSafeInteger(S==null?void 0:S.seq)&&S.seq>d.current);N.length&&(o(S=>S.concat(N).slice(-500)),d.current=N[N.length-1].seq),Number.isSafeInteger(w==null?void 0:w.cursor)&&w.cursor>d.current&&(d.current=w.cursor)}catch{m&&u(!0)}finally{p.current=!1}}},y=()=>{v().catch(()=>{})};y();const b=setInterval(y,NP);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:jP(m)},`${m.seq}-${m.kind}`))})]})}function My({peer:e,token:t,onBack:n}){var s;return Yn(),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(lt,{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(RP,{token:t,nodeId:e.nodeId,route:e.route||[]})})]}):null}const mh=e=>Ji(kr(e)).length===0,gh=e=>Array.isArray(e)?e.join("/"):"";function PP(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 fa(e){return{instanceId:e.ownerId,route:e.ownerRoute||[],label:e.ownerLabel,status:e.available===!1?"offline":"up"}}function _r(e,t,n,s=!1,o=!0){const a=t.instanceId;return{...e,id:mo(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:wf(e.layout,a,n)}}function AP(e,t,n,s,o=[]){const[a,u]=k.useState([]),[d,p]=k.useState(!1),[m,v]=k.useState("idle"),[y,b]=k.useState(""),[w,x]=k.useState(""),N=k.useRef([]),S=k.useRef([]),E=k.useRef(""),C=k.useRef(t),A=k.useRef(n),I=k.useRef(!1),V=k.useRef(!0),W=k.useRef(""),X=k.useMemo(()=>PP(o),[o]),Z=X.map(M=>`${M.instanceId}:${gh(M.route)}:${M.status}:${M.label}`).join("|");S.current=X,A.current=n,C.current=t,N.current=a;const K=k.useCallback(M=>Sf(M.layout,E.current,S.current),[]),G=k.useCallback((M,D=!0,$=C.current)=>{const U=z_(M,Xl()),se=N.current.some(oe=>oe.id===$);N.current=U,u(U);const ce=U.find(oe=>oe.id===$);if(D&&ce){V.current=!0;const oe=K(ce);s(oe),ce.local&&Y2(ce.name,oe)}else se&&!ce&&(V.current=!0,s(po()),b("deck non più condiviso dal nodo owner"));W2(U.filter(oe=>oe.local).map(oe=>oe.name))},[s,K]),F=k.useCallback(async M=>{let D=await Fl(e);const $=D.decks.find(U=>U.name==="main");if(D.decks.length===1&&$&&$.revision===0&&mh($.layout)){const U=U2(),se=kr(xf("main")||po());if(!mh(se)){const ce=wf(se,M,[]);D.decks[0]=await Hl(e,"main",ce,0,[])}for(const ce of U.filter(oe=>oe!=="main"))try{let oe=await av(e,ce,[]);const pe=kr(xf(ce)||po());mh(pe)||(oe=await Hl(e,ce,wf(pe,M,[]),oe.revision,[]))}catch{}D=await Fl(e)}return D},[e]),O=k.useCallback(async({migrate:M=!1}={})=>{const D=await Of(e,[]),$=mi.test(String(D.instanceId||""))?D.instanceId:"";if(!$)throw new Error("instanceId locale non disponibile");E.current=$,x($);const[U,se]=await Promise.all([M?F($):Fl(e),iv(e,[]).catch(()=>({nodes:[]}))]),ce={instanceId:$,route:[],label:"Local"},oe=U.decks.map(he=>_r(he,ce,se.nodes,!0,!0)),pe=N.current;return await Promise.all(S.current.map(async he=>{if(he.status!=="up"){oe.push(...pe.filter(me=>!me.local&&me.ownerId===he.instanceId).map(me=>({...me,ownerRoute:[...he.route],ownerLabel:he.label,available:!1})));return}try{const[me,Ve]=await Promise.all([Fl(e,he.route),iv(e,he.route).catch(()=>({nodes:[]}))]);oe.push(...me.decks.map(ut=>_r(ut,he,Ve.nodes,!1,!0)))}catch{oe.push(...pe.filter(Ve=>!Ve.local&&Ve.ownerId===he.instanceId).map(Ve=>({...Ve,ownerRoute:[...he.route],ownerLabel:he.label,available:!1})))}})),oe.sort((he,me)=>he.local===me.local?he.ownerLabel.localeCompare(me.ownerLabel)||(he.name==="main"?-1:me.name==="main"?1:he.name.localeCompare(me.name)):he.local?-1:1),oe},[e,F,Z]);k.useEffect(()=>{if(!e)return;let M=!1;const D=W.current!==e;return W.current=e,O({migrate:D}).then($=>{if(M)return;const U=N.current.find(oe=>oe.id===C.current),se=$.find(oe=>oe.id===C.current),ce=se&&(!U||se.revision>U.revision||U.available!==se.available||gh(U.ownerRoute)!==gh(se.ownerRoute));G($,D||!!ce&&!I.current),p(!0),se&&b("")}).catch($=>{M||(p(!0),b(String($.message||$)))}),()=>{M=!0}},[G,O,Z,e]);const R=k.useCallback(async(M=C.current)=>{if(!d||!I.current)return!0;const D=N.current.find($=>$.id===M);if(!D)return b(`deck inesistente: ${M}`),!1;if(D.available===!1)return b(`nodo owner offline: ${D.ownerLabel}`),!1;v("saving");try{const $=O_(kr(A.current),D.ownerId,D.ownerTopology),U=await Hl(e,D.name,$,D.revision,D.ownerRoute),se=_r(U,fa(D),D.ownerTopology,D.local,!0);return G(N.current.map(ce=>ce.id===M?se:ce),!1),I.current=!1,v("saved"),b(""),setTimeout(()=>v("idle"),1500),!0}catch($){if(v("error"),b(String($.message||$)),$.status===409&&$.data&&$.data.current){const U=N.current.find(ce=>ce.id===M),se=_r($.data.current,fa(U),U.ownerTopology,U.local,!0);G(N.current.map(ce=>ce.id===M?se:ce),!1)}return!1}},[d,e,G]);return k.useEffect(()=>{if(!d)return;if(V.current){V.current=!1;return}I.current=!0,v("saving");const M=setTimeout(R,650);return()=>clearTimeout(M)},[n,d,R]),k.useEffect(()=>{if(!d)return;const M=setInterval(async()=>{try{const D=await O(),$=N.current.find(ce=>ce.id===C.current),U=D.find(ce=>ce.id===C.current),se=U&&(!$||U.revision>$.revision||$.available!==U.available);G(D,se&&!I.current)}catch{}},5e3);return()=>clearInterval(M)},[d,O,G]),{decks:a,records:a,localNodeId:w,ready:d,saveState:m,error:y,setError:b,saveNow:R,select:async M=>{if(I.current&&!await R(C.current))throw new Error("salvataggio del deck corrente fallito: cambio annullato");const D=N.current.find($=>$.id===M);if(!D)throw new Error(`deck inesistente: ${M}`);return I.current=!1,V.current=!0,K(D)},add:async(M,D=null)=>{const $=D===Xi?N.current.find(ce=>ce.local):D?N.current.find(ce=>ce.ownerId===D):null;if(!$||$.available===!1)throw new Error("nodo owner non disponibile");const U=await av(e,M,$.ownerRoute),se=_r(U,fa($),$.ownerTopology,$.local,!0);return G([...N.current,se],!1),se},rename:async(M,D)=>{const $=N.current.find(pe=>pe.id===M);if(!$)throw new Error("deck inesistente");if(M===C.current&&I.current&&!await R(M))throw new Error(`salvataggio di "${$.name}" fallito: rinomina annullata`);const U=N.current.find(pe=>pe.id===M);if(!U)throw new Error("deck inesistente");const se=await ek(e,U.name,D,U.revision,U.ownerRoute),ce=_r(se,fa(U),U.ownerTopology,U.local,!0),oe=U.local?Xi:U.ownerId;return Hd(q2(Xl(),oe,M,ce.id)),G(N.current.map(pe=>pe.id===M?ce:pe),!1),ce},remove:async M=>{const D=N.current.find(U=>U.id===M);if(!D)throw new Error("deck inesistente");M===C.current&&(I.current=!1),await tk(e,D.name,D.revision,D.ownerRoute);const $=D.local?Xi:D.ownerId;Hd(V2(Xl(),$,M)),G(N.current.filter(U=>U.id!==M),!1)},reorder:(M,D)=>{const $=N.current.find(he=>he.id===M),U=N.current.find(he=>he.id===D);if(!$||!U)return!1;const se=$.local?Xi:$.ownerId,ce=U.local?Xi:U.ownerId;if(se!==ce)return!1;const oe=N.current.filter(he=>(he.local?Xi:he.ownerId)===se).map(he=>he.id),pe=Hd(K2(Xl(),se,M,D,oe));return G(z_(N.current,pe),!1),!0},addTileTo:async(M,D)=>{const $=N.current.find(he=>he.id===M);if(!$)throw new Error("deck inesistente");if($.available===!1)throw new Error(`nodo owner offline: ${$.ownerLabel}`);const U=Bw(D,E.current,S.current);if(!U)throw new Error("riferimento sessione non valido");const se=K($),ce=O_(kb(se,U),$.ownerId,$.ownerTopology),oe=await Hl(e,$.name,ce,$.revision,$.ownerRoute),pe=_r(oe,fa($),$.ownerTopology,$.local,!0);return G(N.current.map(he=>he.id===M?pe:he),!1),pe},localMainId:mo(null,"main"),parseDeckId:Dc}}const LP="/sw.js",Nf="nc-sw-update";let jf=null,Rf=!1,Pf=null,wS=Object.freeze({needed:!1,kind:null,version:""}),SS=!1;function xS(){typeof window<"u"&&window.dispatchEvent(new Event(Nf))}function kS(){const e=Pf||(Rf?{kind:"reload",version:""}:null);wS=Object.freeze({needed:!!e,kind:(e==null?void 0:e.kind)||null,version:(e==null?void 0:e.version)||""})}function Dy(){return wS}function TP(e){return typeof window>"u"?()=>{}:(window.addEventListener(Nf,e),()=>window.removeEventListener(Nf,e))}function Pp(e){Rf!==e&&(Rf=e,kS(),xS())}const vh="nc-auto-reload";function MP(){try{return typeof sessionStorage<"u"?sessionStorage:null}catch{return null}}function DP(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(Pf);Pf=o,kS(),a||xS();const u=s.storage===void 0?MP():s.storage;if(!o){try{u&&u.removeItem(vh)}catch{}return}if(o.kind!=="reload"||!u)return;const d=`${t}|${n}`;try{if(u.getItem(vh)===d)return;u.setItem(vh,d)}catch{return}(s.applyImpl||CS)()}function IP(e){e.addEventListener("statechange",()=>{e.state==="installed"&&navigator.serviceWorker.controller&&Pp(!0)})}function OP(){typeof navigator>"u"||!("serviceWorker"in navigator)||(navigator.serviceWorker.addEventListener("controllerchange",()=>{SS&&location.reload()}),navigator.serviceWorker.register(LP).then(e=>{jf=e,e.waiting&&Pp(!0),e.addEventListener("updatefound",()=>{const t=e.installing;t&&IP(t)}),setInterval(()=>{e.update().catch(()=>{})},3600*1e3)}).catch(()=>{}))}function CS(){SS=!0,Pp(!1);const e=jf&&jf.waiting;e?(e.postMessage({type:"SKIP_WAITING"}),setTimeout(()=>location.reload(),4e3)):location.reload()}function BP({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 ES=9,NS=24,jS="nc_side_w",Iy="nc_side_min",zP=240,Oy=new Set(["absent","present","active","unknown"]);function $P(){const e=Number(localStorage.getItem(jS));return e>=180&&e<=480?e:zP}function FP(){const e=Number(localStorage.getItem("nc_fontsize"));return e>=ES&&e<=NS?e:13}function HP(){const e={token:"",pair:""};try{const{token:t,pair:n,nextUrl:s}=BP({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 UP(e){try{return kr(xf(e))}catch{return po()}}function By(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 zy({session:e,node:t,ownerId:n,cellName:s,token:o,readonly:a=!1,panelPort:u=0,onBack:d,onCellSwitcher:p,cellSwitcherOpen:m=!1}){Yn();const[v]=hp(),[y,b]=k.useState(!1),[w,x]=k.useState(()=>window.matchMedia("(pointer: coarse)").matches),[N,S]=k.useState(null),[E,C]=k.useState(FP),[A,I]=k.useState(s||e),[V,W]=k.useState(""),[X,Z]=k.useState(""),[K,G]=k.useState(""),[F,O]=k.useState(!1),R=U=>C(se=>{const ce=Math.max(ES,Math.min(NS,se+U));return localStorage.setItem("nc_fontsize",String(ce)),ce}),B=k.useRef(()=>{}),H=k.useRef(()=>!1),L=k.useRef(()=>{}),T=k.useRef(!1),[j,z]=k.useState(!1),[M,D]=k.useState(!1),$=()=>{T.current=!T.current,z(T.current)};return k.useEffect(()=>{I(s||e),O(!1)},[s,e]),k.useEffect(()=>{let U=!0;const se=t?t.split("/"):[],ce=t?`/api/route/${t.split("/").map(encodeURIComponent).join("/")}/_`:"/api";async function oe(){let he=null,me=null;try{const _t=await(await on(`${ce}/sessions`,o)).json();Array.isArray(_t.sessions)&&(he=_t.sessions.find(je=>je.name===e))}catch{}try{const ut=await Qs(o,se);ut.available&&Array.isArray(ut.cells)&&(me=ut.cells.find(_t=>_t.tmuxSession===e))}catch{}if(!U)return;I(fp({session:e,cell:me||(s?{cell:s}:null)})),Z(typeof(me==null?void 0:me.panelUrl)=="string"?me.panelUrl.trim():""),G(typeof(me==null?void 0:me.cell)=="string"?me.cell:"");let Ve="";me?Ve=`${me.engine}${me.key?`·${me.key}`:""}`:he&&(Ve=he.attached?`attached · ${By(he.activity)}`:he.activity?By(he.activity):""),W(Ve)}oe();const pe=setInterval(oe,4e3);return()=>{U=!1,clearInterval(pe)}},[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(lt,{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?`${A} · ${t}`:A,children:A}),V&&l.jsx("small",{className:"nc-bar-sub",children:V})]}),l.jsxs("span",{className:"nc-bar-right",children:[l.jsx("button",{onClick:()=>R(-1),title:f("zoom-out"),children:l.jsx(lt,{name:"zoomOut",size:18})}),l.jsx("button",{onClick:()=>R(1),title:f("zoom-in"),children:l.jsx(lt,{name:"zoomIn",size:18})}),l.jsx("button",{onClick:()=>x(U=>!U),title:f("composer"),children:l.jsx(lt,{name:"keyboard",size:20})}),l.jsx("button",{onClick:()=>b(U=>!U),title:f("files"),children:l.jsx(lt,{name:"folder",size:20})}),X&&l.jsx("button",{onClick:()=>O(U=>!U),title:f("panel"),"aria-pressed":F,children:l.jsx(lt,{name:"monitor",size:20})})]})]}),l.jsxs("div",{className:"nc-termwrap",children:[l.jsx(op,{session:e,node:t,token:o,readonly:a,takeSize:!0,sendRef:B,composerRef:H,actionRef:L,ctrlRef:T,setCtrlArmed:z,onFiles:S,fontSize:E,selectionMode:M,onSelectionModeChange:D,keyboardGesture:v.terminalKeyboardGesture}),F&&X&&K&&l.jsx(cp,{cellId:K,panelUrl:X,route:t?t.split("/"):[],panelPort:u,token:o,title:A})]}),l.jsx(s2,{onKeyboard:()=>x(U=>!U),onCellSwitcher:p,cellSwitcherOpen:m,send:U=>B.current(U),action:U=>L.current(U),ctrlArmed:j,onCtrl:$,selectionMode:M,onSelectionMode:D,keepKeyboardClosed:v.keybarKeepsKeyboardClosed,showEnter:v.showKeybarEnter,keybarLayout:v.keybarLayout}),w&&l.jsx(Rw,{submitText:U=>H.current(U),token:o,session:e,node:t,ownerId:n,readonly:a,keepKeyboardClosedOnVoice:v.voiceKeepsKeyboardClosed}),y&&l.jsx(bw,{session:e,node:t,token:o,filesEvent:N,onClose:()=>b(!1)})]})}function WP(){Yn();const[e]=k.useState(HP),[t,n]=k.useState(e.token),[s,o]=k.useState(e.pair||""),a=k.useCallback(()=>{o("");try{sessionStorage.removeItem("nc_pair")}catch{}},[]),[u,d]=k.useState(!1),p=IN(),[m]=k.useState(()=>H2(typeof location<"u"?location.pathname:"/")),[v,y]=k.useState(m.id),b=v===mo(null,gi),[w,x]=k.useState(null),N=ee=>{const Se=Xs(ee);x(Se?{...Se,...typeof(ee==null?void 0:ee.cellName)=="string"&&ee.cellName?{cellName:ee.cellName}:{}}:null)},[S,E]=k.useState([]),[C,A]=k.useState([]),[I,V]=k.useState([]),[W,X]=k.useState(!1),[Z,K]=k.useState(null),[G,F]=k.useState(()=>m.ownerId?po():UP(m.name)),[O,R]=k.useState(null),[B,H]=k.useState(null),L=ee=>H(Xs(ee)),[T,j]=k.useState(null),z=Ff(t,p),M=k.useMemo(()=>(z||[]).filter(ee=>ee.instanceId).map(ee=>({instanceId:ee.instanceId,route:ee.route,label:ee.label,status:ee.status})),[z]),D=AP(t,v,G,F,M),$=D.decks;k.useEffect(()=>{const ee=new Map;for(const Se of z||[]){const Me=(Se.route||[Se.name]).join("/"),Je=new Set((Se.sessions||[]).map(et=>et.name));for(const et of Se.cells||[])!et.cell||!et.tmuxSession||et.cell===et.tmuxSession||Je.has(et.cell)||ee.set(`${Me}:${et.cell}`,`${Me}:${et.tmuxSession}`)}F(Se=>$k(Se,ee))},[z]),k.useEffect(()=>{D.localNodeId&&F(ee=>{const Se=Sf(ee,D.localNodeId,M);return JSON.stringify(Se)===JSON.stringify(ee)?ee:Se})},[M,D.localNodeId]);const[U,se]=k.useState(null),[ce,oe]=k.useState(null),pe=k.useRef(0),[he,me]=k.useState(!1),[Ve,ut]=k.useState($P),[_t,je]=k.useState(!b),[Ct,hn]=k.useState(()=>b?localStorage.getItem(Iy)==="1":!0),[_n,Yt]=k.useState(!1),[xt,Ot]=k.useState("nodes"),[Ut,jt]=k.useState(!1),[It,Mt]=k.useState(""),[Rt,fn]=k.useState(!1),ie=(ee="nodes",Se=!1,Me="")=>{Ot(ee),jt(Se),Mt(Me),Yt(!0)},[Qe,ge]=k.useState(!1),[Ge,ct]=k.useState({deviceDefault:"",localNodeId:"",localNameDefault:""}),[re,ne]=k.useState(!1),[_e,be]=k.useState(0),[ke,it]=k.useState({});k.useEffect(()=>{try{localStorage.setItem(jS,String(Ve))}catch{}},[Ve]),k.useEffect(()=>{try{localStorage.setItem(Iy,Ct?"1":"")}catch{}},[Ct]),k.useEffect(()=>{if(!t)return;let ee=!1;return Promise.all([Yy(t),on("/api/config",t).then(Se=>Se.json())]).then(([Se,Me])=>{ee||(ct({deviceDefault:Se.deviceName||"",localNodeId:Se.nodeId||"",localNameDefault:Se.localName||""}),ne(!!Me.readonlyDefault),be(Number.isInteger(Me.panelPort)?Me.panelPort:0),it(Me.nodePanelPorts&&typeof Me.nodePanelPorts=="object"&&!Array.isArray(Me.nodePanelPorts)?Me.nodePanelPorts:{}),(Se.firstRun===!0&&!Me.readonlyDefault||s)&&ge(!0))}).catch(()=>{}),()=>{ee=!0}},[t,s]);const[ht,dt]=k.useState({}),Pt=k.useRef(z);k.useEffect(()=>{Pt.current=z},[z]);const St=k.useCallback(async()=>{try{const et=await(await on("/api/sessions",t)).json();et.error||E(et.sessions||[])}catch{}let ee=null,Se=null;try{ee=await Qs(t)}catch(Je){Se=Je}const Me=$f({fs:ee,error:Se});Me.kind==="data"?(A(Me.cells),V(Me.capabilities),X(!1),K(null)):Me.kind==="stale"?(X(!0),K(null)):(A([]),V([]),X(!1),K(Me.reason||""))},[t]);k.useEffect(()=>{let ee=!1;const Se=async()=>{const Je=[[],...(Pt.current||[]).filter(bt=>bt.kind!=="vl"&&bt.status==="up").map(bt=>Array.isArray(bt.route)&&bt.route.length?bt.route:[bt.name])],et=await Promise.all(Je.map(async bt=>{const ln=Sa(bt);try{const At=await nk(t,bt);return[ln,{hostCell:At&&typeof At.hostCell=="string"?At.hostCell:null,hostLease:At&&At.host&&typeof At.host.lease=="string"?At.host.lease:null,hostRevision:Number.isInteger(At&&At.revision)?At.revision:0,threadStatus:At&&Oy.has(At.threadStatus)?At.threadStatus:"unknown"}]}catch{return[ln,{error:!0}]}}));ee||dt(bt=>{let ln=!1;const At={...bt};for(const vi of et){if(!vi)continue;const[pn,Nt]=vi;At[pn]=Nt.error?{...bt[pn]||{},threadStatus:"unknown"}:Nt,ln=!0}return ln?At:bt})};Se();const Me=setInterval(Se,4e3);return()=>{ee=!0,clearInterval(Me)}},[t]),k.useEffect(()=>{if(!p)return;St();const ee=setInterval(St,4e3);return()=>clearInterval(ee)},[p,St]);const yt=k.useCallback(async(ee,Se=[])=>{const Me=Sa(Se),Je=ht[Me]&&ht[Me].hostRevision||0;try{const et=await ik(t,ee,Je,Se);dt(bt=>({...bt,[Me]:{hostCell:et.hostCell||null,hostLease:et.host&&typeof et.host.lease=="string"?et.host.lease:null,hostRevision:Number.isInteger(et.revision)?et.revision:Je,threadStatus:Oy.has(et.threadStatus)?et.threadStatus:"unknown"}}))}catch(et){window.alert(f(bv(et)))}},[t,ht]),zt=k.useCallback(async(ee=[])=>{const Se=Sa(ee),Me=ht[Se]&&ht[Se].hostRevision||0;try{const Je=await sk(t,Me,ee);return dt(et=>({...et,[Se]:{hostCell:Je.hostCell||null,hostLease:null,hostRevision:Number.isInteger(Je.revision)?Je.revision:Me,threadStatus:"unknown"}})),!0}catch(Je){return window.alert(f(bv(Je))),!1}},[t,ht]);k.useEffect(()=>{let ee=!1;const Se=()=>{on("/api/config",t).then(Je=>Je.json()).then(Je=>{ee||DP(Je.version,Je.uiVersion,"0.9.21")}).catch(()=>{})};Se();const Me=setInterval(Se,6e4);return()=>{ee=!0,clearInterval(Me)}},[t]);const Ze=new Set([...S.map(ee=>ee.name),...z.flatMap(ee=>ee.sessions.map(Se=>Se.key))]),Q=Ji(G),Ne=ee=>F(Se=>{const Me=Bw(ee,D.localNodeId,M)||ee,Je=kb(Se,Me);return Je===Se&&Ji(Se).length>=9&&D.setError(f("grid-full")),Je}),Ue=async(ee,Se=[])=>{try{await Mf(t,ee,Se)}catch{return}const Me=Se.length?`${Se.join("/")}:${ee}`:ee;F(Je=>vc(Je,Me)),St()},Oe=async(ee,Se,Me=[])=>{try{await Vy(t,ee,Se,Me)}catch{return}St()},Ae=async(ee,Se,Me=[])=>{await Wy(t,{cell:ee,enabled:!!Se},Me),St()},Et=async ee=>{if(!U)return;const{cell:Se}=U,Me=Array.isArray(U.route)?U.route:[];if(ee.action==="up"){const et=await Tf(t,{cell:Se,boot:!!ee.boot,...ee.engine?{engine:ee.engine}:{},...ee.model!==void 0?{model:ee.model}:{},...ee.permissionPolicy?{permissionPolicy:ee.permissionPolicy}:{}},Me),bt=Gf(et);bt&&D.setError(bt.text)}else await uc(t,{cell:Se,boot:!!ee.boot},Me);const Je=ee.action==="up"?!!ee.boot:ee.boot?!1:!!U.boot;oe({id:++pe.current,cell:Se,route:Me,enabled:Je}),St()},kt=k.useCallback(ee=>{oe(Se=>(Se==null?void 0:Se.id)===ee?null:Se)},[]),Y=async ee=>{if(!(!(ee!=null&&ee.direct)||he)){me(!0);try{await Bf(t,ee.name,ee.tunnelStatus==="up"?"down":"up")}finally{me(!1)}}},ae=async(ee,Se)=>{const Me=String(Se||"").trim();return!(ee!=null&&ee.direct)||!yo(Me)?!1:(await Qy(t,ee.name,Me),!0)},ye=ee=>{const Se=$.find(Me=>Me.id===ee);if(!Se)return!1;try{const Me=window.open(Fd(Se,t),"_blank");return Me&&(Me.opener=null),!!Me}catch{return!1}},Le=async ee=>{if(!ee||ee===v)return;const Se=await D.select(ee),Me=D.records.find(Je=>Je.id===ee);y(ee),F(Se),R(null),H(null);try{history.replaceState(null,"",Fd(Me||ee,null))}catch{}},De=async(ee,Se)=>{const Me=await D.add(ee,Se);await Le(Me.id)},Ee=async(ee,Se)=>{const Me=await D.rename(ee,Se);if(ee===v){y(Me.id),F(Sf(Me.layout,D.localNodeId,M)),R(null),H(null);try{history.replaceState(null,"",Fd(Me,null))}catch{}}},Xe=async ee=>{await D.remove(ee),ee===v&&await Le(D.localMainId)},ft=async(ee,Se)=>{!Se||Se===v||(await D.addTileTo(Se,ee),F(Me=>vc(Me,ee)))};if(!t)return l.jsxs("div",{className:"nc-auth",children:[l.jsx("p",{children:f("auth-prompt")}),l.jsx("input",{onChange:ee=>n(ee.target.value.trim()),placeholder:"token"}),l.jsxs("label",{children:[l.jsx("input",{type:"checkbox",checked:u,onChange:ee=>d(ee.target.checked)})," ",f("remember-device")]}),l.jsx("button",{onClick:()=>{(u?localStorage:sessionStorage).setItem("nc_token",t)},children:"ok"})]});const $t=l.jsxs(l.Fragment,{children:[_n&&l.jsx(fP,{token:t,initialTab:xt,initialLocation:It,startNewCell:Ut,onClose:()=>{Yt(!1),jt(!1),Mt("")}}),Qe&&l.jsx(pP,{token:t,initialPair:s,...Ge,onPairDone:a,onDone:()=>ge(!1)}),l.jsx(bP,{token:t})]});if(!p)return T?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-single-overlay",children:l.jsx(My,{peer:T,token:t,onBack:()=>j(null)})}),$t]}):w?l.jsxs(l.Fragment,{children:[l.jsx(zy,{session:w.session,node:w.node,ownerId:w.ownerId,cellName:w.cellName,token:t,readonly:re,panelPort:Ec(w.node?w.node.split("/"):[],ke,_e),onBack:()=>x(null),onCellSwitcher:()=>fn(!0),cellSwitcherOpen:Rt}),Rt&&l.jsx(EP,{token:t,current:w,panelPort:_e,nodePanelPorts:ke,onPick:ee=>{N(ee),fn(!1)},onClose:()=>fn(!1)}),$t]}):l.jsxs(l.Fragment,{children:[l.jsx(s1,{onPick:N,token:t,onSettings:ie,onOpenVlSession:j,hostByRoute:ht,onDesignateCell:yt,onClearHostCell:zt}),$t]});const Be=b||!_t;return l.jsxs("div",{className:"nc-workspace",children:[Be&&l.jsx(R2,{sessions:S,cells:C,activeSessions:Q,nodeGroups:z,token:t,onPeekOpen:()=>fn(!1),overlayOpen:Rt,fleetCapabilities:I,fleetStale:W,fleetOff:Z,bootSettlement:ce,onBootSettlementApplied:kt,localNodeId:D.localNodeId,hostByRoute:ht,onDesignateCell:yt,onClearHostCell:zt,onPick:L,onAddTile:Ne,onPower:se,onBoot:Ae,onBootError:ee=>D.setError(String((ee==null?void 0:ee.message)||ee)),onNodePower:Y,onNodeRename:ae,onKill:Ue,onVisibility:Oe,onNew:()=>ie("fleet",!0),onSettings:ie,onOpenVlSession:j,width:Ve,collapsed:Ct,onResize:ut,onToggleCollapse:()=>hn(ee=>!ee)}),l.jsxs("div",{className:"nc-workspace-main",children:[l.jsx(dj,{decks:$,currentDeck:v,onCreate:De,onRename:Ee,onDelete:Xe,onReorder:D.reorder,onOpenWindow:ye,onNavigate:Le,saveState:D.saveState,error:D.error,sidebarVisible:Be,onToggleSidebar:b?null:()=>je(ee=>!ee)}),l.jsx(O2,{layout:G,onLayoutChange:F,token:t,readonly:re,sessionsAlive:Ze,focusSession:O,onFocus:R,onOpenSingle:L,decks:$,currentDeck:v,onSendToDeck:ft,cells:C,nodeGroups:z,panelPort:_e,nodePanelPorts:ke})]}),T&&l.jsx("div",{className:"nc-single-overlay",children:l.jsx(My,{peer:T,token:t,onBack:()=>j(null)})}),B&&l.jsx("div",{className:"nc-single-overlay",children:l.jsx(zy,{session:B.session,node:B.node,ownerId:B.ownerId,cellName:fp({session:B.session,node:B.node,ownerId:B.ownerId,cells:C,nodeGroups:z}),token:t,readonly:re,panelPort:Ec(B.node?B.node.split("/"):[],ke,_e),onBack:()=>H(null)})}),U&&l.jsx(hc,{cell:U,token:t,route:Array.isArray(U.route)?U.route:[],onConfirm:Et,onClose:()=>se(null)}),$t]})}function KP(){Yn();const e=k.useSyncExternalStore(TP,Dy,Dy);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:CS,children:f("reload")})]})}OP();fx.createRoot(document.getElementById("root")).render(l.jsxs(ox.StrictMode,{children:[l.jsx(WP,{}),l.jsx(KP,{})]}));
|
package/frontend/dist/index.html
CHANGED
|
@@ -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-
|
|
14
|
+
<script type="module" crossorigin src="/assets/index-D5snoCdN.js"></script>
|
|
15
15
|
<link rel="stylesheet" crossorigin href="/assets/index-CprIQlC5.css">
|
|
16
16
|
</head>
|
|
17
17
|
<body>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.9.
|
|
1
|
+
{"version":"0.9.22"}
|