@mmmbuto/nexuscrew 0.9.35 → 0.9.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,10 @@ All notable changes to NexusCrew are tracked here.
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
## 0.9.36 — 2026-09-20
|
|
8
|
+
|
|
9
|
+
- **Fleet definitions: capability profiles are now preserved across cell edits (they were dropped or made the file unwritable) and exposed in the definitions view.**
|
|
10
|
+
|
|
7
11
|
## 0.9.35 — 2026-09-20
|
|
8
12
|
|
|
9
13
|
- **Federated topology: per-hop budget; slow transitive peers are served from the last good snapshot and marked stale instead of disappearing.** A hub used to answer a topology request only after its whole fan-out completed, so a single slow child pushed the hub's answer past the caller's budget and the caller dropped the entire transitive branch. A peer request now carries its remaining budget, the hub keeps a 500 ms margin for itself, and a child that misses the hop budget is served from the last good snapshot marked `stale` with `lastSeen`; a response that arrives but fails identity binding still drops the branch. Stale owners stay addressable on their cached route in the deck and VL owner lists.
|
|
@@ -164,4 +164,4 @@ Minimum version required to store current data is: `+H+`.
|
|
|
164
164
|
`).filter(s=>s!==""),promptMode:t.promptMode};return t.modelFlag&&(i.model={flag:t.modelFlag,value:t.modelValue||""}),t.promptMode==="flag"&&(i.promptFlag=t.promptFlag),e&&(i.env=Object.fromEntries(t.envRows.filter(s=>!s.remove&&s.key).map(s=>[s.key,s.value]))),Xb(i,t,e)}function Er({children:t,onClose:e,label:n,error:i=""}){const s=k.useRef(null),a=k.useRef(null),c=k.useRef(e);return c.current=e,k.useEffect(()=>{const d=document.activeElement,h=s.current,f=()=>Array.from((h==null?void 0:h.querySelectorAll('button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [href], [tabindex]:not([tabindex="-1"])'))||[]).filter(_=>_.offsetParent!==null),g=requestAnimationFrame(()=>{var _;return(_=f()[0]||h)==null?void 0:_.focus({preventScroll:!0})}),y=_=>{var C;if(_.key==="Escape"){_.preventDefault(),(C=c.current)==null||C.call(c);return}if(_.key!=="Tab")return;const w=f();if(!w.length){_.preventDefault(),h==null||h.focus();return}const S=w[0],N=w[w.length-1];_.shiftKey&&document.activeElement===S?(_.preventDefault(),N.focus()):!_.shiftKey&&document.activeElement===N&&(_.preventDefault(),S.focus())};return document.addEventListener("keydown",y),()=>{cancelAnimationFrame(g),document.removeEventListener("keydown",y),d&&d.isConnected&&typeof d.focus=="function"&&d.focus({preventScroll:!0})}},[]),k.useEffect(()=>{i&&requestAnimationFrame(()=>{var d;return(d=a.current)==null?void 0:d.scrollIntoView({block:"nearest"})})},[i]),l.jsx("div",{className:"nc-fleet-modal",role:"presentation",onMouseDown:d=>{d.target===d.currentTarget&&e()},children:l.jsxs("div",{ref:s,className:"nc-fleet-modal-dialog",role:"dialog","aria-modal":"true","aria-label":n||m("settings"),tabIndex:-1,children:[t,i&&l.jsx("div",{ref:a,className:"nc-err nc-fleet-modal-error",role:"alert","aria-live":"assertive",children:i})]})})}function ep({token:t,targets:e=[],readonly:n=!1,onPower:i,onImport:s}){const[a,c]=k.useState([]),[d,h]=k.useState(0);k.useEffect(()=>{let C=!0;async function E(){const M=[{route:[],label:m("local")}].concat((e||[]).map(U=>({route:Array.isArray(U.route)?U.route:[],label:U.label||(U.route||[]).join(" › ")}))),T=await Promise.all(M.map(async U=>{const z={...U,available:!1,readonly:!1,capabilities:[],provider:null,cells:[],unmanaged:[],err:""};try{const K=await Dr(t,U.route);z.available=!!K.available,z.capabilities=K.capabilities||[],z.provider=K.provider||null,z.cells=(K.cells||[]).map(Q=>({...Q,route:U.route}));try{z.readonly=!!(await km(t,U.route)).readonlyDefault}catch{}try{const Q=await Cm(t,U.route),q=new Set(z.cells.map(G=>G.tmuxSession).filter(Boolean));z.unmanaged=(Q.sessions||[]).filter(G=>G&&!q.has(G.name))}catch{}}catch(K){z.err=String(K&&K.message||K)}return z}));C&&c(T)}E();const x=setInterval(E,6e3);return()=>{C=!1,clearInterval(x)}},[t,e,d]);const f=(C,E)=>Array.isArray(C.capabilities)&&C.capabilities.includes(E)&&!n&&!C.readonly,g=()=>h(C=>C+1),y=(C,E)=>{i&&i({...C,route:E})},_=(C,E)=>{i&&i({...C,route:E})},w=async(C,E)=>{try{await ml(t,C.cell,E)}catch{}g()},S=async(C,E)=>{if(window.confirm(m("fleet-remove-cell").replace("{id}",C.cell))){try{await _0(t,C.cell,!0,E)}catch{}g()}},N=async(C,E)=>{if(window.confirm(m("terminate-confirm").replace("{name}",C.name))){try{await Sm(t,C.name,E)}catch{}g()}};return l.jsxs("div",{className:"nc-fleet-inventory",children:[l.jsxs("div",{className:"nc-fleet-section-head",children:[l.jsx("b",{children:m("fleet-inventory")}),l.jsx("small",{children:m("fleet-inventory-help")})]}),a.map(C=>{const E=C.route.length?C.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 ${C.available?"on":"warn"}`}),l.jsx("b",{children:C.label}),l.jsx("small",{children:C.available?`${C.cells.length} ${m("fleet-cells")} · ${C.unmanaged.length} ${m("fleet-tmux")}`:C.err||m("fleet-not-available")})]}),C.cells.map(x=>l.jsxs("div",{className:"nc-fleet-item nc-fleet-cell",children:[l.jsxs("span",{children:[l.jsx("b",{children:x.cell}),l.jsx("small",{children:`${x.engine||""}${x.key?`·${x.key}`:""}${x.active?"":` · ${m("cell-off")}`}`})]}),l.jsxs("span",{className:"nc-fleet-cell-actions",children:[x.active&&f(C,"down")&&l.jsx("button",{className:"nc-btn ghost",title:m("power-off"),onClick:()=>_(x,C.route),children:m("stop")}),!x.active&&f(C,"up")&&l.jsx("button",{className:"nc-btn ghost",title:m("power-on"),onClick:()=>y(x,C.route),children:m("start")}),f(C,"restart")&&x.active&&l.jsx("button",{className:"nc-btn ghost",title:m("restart"),onClick:()=>w(x,C.route),children:m("restart")}),f(C,"remove")&&l.jsx("button",{className:"nc-btn danger",title:m("delete"),onClick:()=>S(x,C.route),children:"×"})]})]},`${E}:${x.cell}`)),C.unmanaged.map(x=>l.jsxs("div",{className:"nc-fleet-item nc-fleet-unmanaged",children:[l.jsxs("span",{children:[l.jsx("b",{children:x.name}),l.jsx("small",{children:m("fleet-tmux")})]}),l.jsxs("span",{className:"nc-fleet-cell-actions",children:[f(C,"import")&&s&&l.jsx("button",{className:"nc-btn ghost",title:m("import-as-cell"),onClick:()=>s(x,C.route),children:m("import-as-cell")}),l.jsx("button",{className:"nc-btn danger",title:m("terminate"),onClick:()=>N(x,C.route),children:"×"})]})]},`${E}:u:${x.name}`)),C.available&&C.cells.length===0&&C.unmanaged.length===0&&l.jsx("div",{className:"nc-empty",children:m("fleet-inventory-empty")})]},E)})]})}function QP({cells:t=[],engines:e=[],models:n=[],busy:i,canRestore:s=!1,onRestore:a,onClose:c}){const[d,h]=k.useState("export"),[f,g]=k.useState([]),[y,_]=k.useState(()=>new Set(t.map(O=>O.id))),[w,S]=k.useState(()=>new Set(e.map(O=>O.id))),[N,C]=k.useState([]),[E,x]=k.useState([]),[M,T]=k.useState(""),U=new Set(e.map(O=>O.id)),z=new Set(t.map(O=>O.id)),K=(O,R)=>O(A=>{const j=new Set(A);return j.has(R)?j.delete(R):j.add(R),j}),Q=()=>{const O=WP(t,y,e,w,new Date,n);if(O.ok===!1){T(m(`fleet-backup-${O.error}`));return}const R=t.filter(W=>y.has(W.id)).length,A=e.filter(W=>w.has(W.id)).length;if(O.cells.length!==R){T(m("fleet-backup-invalid-cell"));return}if(O.engines.length!==A){T(m("fleet-backup-invalid-engine"));return}if(!O.cells.length&&!O.engines.length){T(m("fleet-backup-select-one"));return}const j=new Blob([`${JSON.stringify(O,null,2)}
|
|
165
165
|
`],{type:"application/json"}),F=URL.createObjectURL(j),$=document.createElement("a");$.href=F,$.download=`nexuscrew-fleet-${new Date().toISOString().slice(0,10)}.json`,document.body.appendChild($),$.click(),$.remove(),setTimeout(()=>URL.revokeObjectURL(F),0),T("")},q=async O=>{if(T(""),C([]),x([]),!!O){if(O.size>1024*1024){T(m("fleet-backup-too-large"));return}try{const R=qP(await O.text());if(!R.ok){T(m(`fleet-backup-${R.error}`));return}g(Array.isArray(R.models)?R.models:[]);const A=new Set(R.engines.map(j=>j.id));x(R.engines.map(j=>({engine:j,exists:U.has(j.id),selected:!U.has(j.id)}))),C(R.cells.map(j=>{const F=U.has(j.engine)||A.has(j.engine),$=z.has(j.id);return{cell:j,engine:F?j.engine:"",selected:F&&!$,exists:$}}))}catch(R){T(String(R.message||R))}}},G=(O,R)=>C(A=>A.map((j,F)=>F===O?{...j,...R}:j)),H=(O,R)=>x(A=>A.map((j,F)=>F===O?{...j,...R}:j)),P=new Set([...U,...E.filter(O=>O.selected).map(O=>O.engine.id)]),L=N.filter(O=>O.selected&&O.engine&&P.has(O.engine)),I=E.filter(O=>O.selected),D=[...new Map([...e.map(O=>[O.id,O.label||O.id]),...E.filter(O=>O.selected).map(O=>[O.engine.id,O.engine.label||O.engine.id])]).entries()];return l.jsxs("div",{className:"nc-set-form nc-fleet-form nc-backup-dialog",children:[l.jsx("b",{children:m("fleet-backup")}),l.jsx("small",{children:m("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:()=>{h("export"),T("")},children:m("fleet-backup-export")}),l.jsx("button",{type:"button",className:`nc-set-tabbtn${d==="import"?" on":""}`,disabled:!s,title:s?"":m("fleet-backup-restore-unavailable"),onClick:()=>{h("import"),T("")},children:m("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:()=>{_(new Set(t.map(O=>O.id))),S(new Set(e.map(O=>O.id)))},children:m("select-all")}),l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:()=>{_(new Set),S(new Set)},children:m("select-none")})]}),l.jsxs("div",{className:"nc-backup-list",children:[l.jsx("b",{children:m("fleet-engines")}),e.map(O=>{var R;return l.jsxs("label",{className:"nc-check nc-backup-row",children:[l.jsx("input",{type:"checkbox",checked:w.has(O.id),onChange:()=>K(S,O.id)}),l.jsxs("span",{children:[l.jsx("b",{children:O.label||O.id}),l.jsxs("small",{children:[O.id,(R=O.envKeys)!=null&&R.length?` · ${O.envKeys.length} ${m("fleet-backup-env-names")}`:""]})]})]},O.id)}),l.jsx("b",{children:m("fleet-cells")}),t.map(O=>l.jsxs("label",{className:"nc-check nc-backup-row",children:[l.jsx("input",{type:"checkbox",checked:y.has(O.id),onChange:()=>K(_,O.id)}),l.jsxs("span",{children:[l.jsx("b",{children:O.id}),l.jsxs("small",{children:[O.engine," · ",m("fleet-system-prompt")," ",(O.prompt||"").length," ",m("characters")]})]})]},O.id)),!t.length&&!e.length&&l.jsx("div",{className:"nc-empty",children:m("fleet-backup-empty")})]}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:c,children:m("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:!y.size&&!w.size,onClick:Q,children:m("fleet-backup-download")})]})]}):l.jsxs(l.Fragment,{children:[l.jsx("input",{type:"file",accept:"application/json,.json",disabled:i,onChange:O=>q(O.target.files&&O.target.files[0])}),l.jsx("small",{children:m("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:()=>{x(O=>O.map(R=>({...R,selected:!0}))),C(O=>O.map(R=>({...R,selected:!!R.engine})))},children:m("select-all")}),l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:()=>{x(O=>O.map(R=>({...R,selected:!1}))),C(O=>O.map(R=>({...R,selected:!1})))},children:m("select-none")})]}),l.jsxs("div",{className:"nc-backup-list",children:[!!E.length&&l.jsx("b",{children:m("fleet-engines")}),E.map((O,R)=>{var A;return l.jsx("div",{className:"nc-backup-import-row",children:l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:O.selected,onChange:j=>H(R,{selected:j.target.checked})}),l.jsxs("span",{children:[l.jsx("b",{children:O.engine.label||O.engine.id}),l.jsxs("small",{children:[O.engine.id," · ",O.exists?m("fleet-backup-overwrite"):m("fleet-backup-new"),(A=O.engine.envKeys)!=null&&A.length?` · ${m("fleet-backup-env-values-required")}`:""]})]})]})},O.engine.id)}),!!N.length&&l.jsx("b",{children:m("fleet-cells")}),N.map((O,R)=>l.jsxs("div",{className:"nc-backup-import-row",children:[l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:O.selected,disabled:!O.engine||!P.has(O.engine),onChange:A=>G(R,{selected:A.target.checked})}),l.jsxs("span",{children:[l.jsx("b",{children:O.cell.id}),l.jsxs("small",{children:[O.exists?m("fleet-backup-overwrite"):m("fleet-backup-new")," · ",m("fleet-system-prompt")," ",O.cell.systemPrompt.length," ",m("characters")]})]})]}),l.jsxs("select",{value:O.engine,onChange:A=>G(R,{engine:A.target.value,selected:!!A.target.value}),children:[l.jsx("option",{value:"",children:m("fleet-backup-engine-missing")}),D.map(([A,j])=>l.jsx("option",{value:A,children:j},A))]})]},O.cell.id))]}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:c,children:m("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:i||!L.length&&!I.length,onClick:()=>a({engineRows:E,cellRows:N,models:f}),children:m("fleet-backup-restore")})]})]}),M&&l.jsx("div",{className:"nc-err",children:M})]})}function JP({state:t,setState:e,busy:n,onSave:i,catalog:s}){var E;const a=t.form,c=x=>e({...t,form:{...a,...x}}),d=a.envRows||[],h=[...new Map(s.map(x=>[x.client,x.clientLabel||x.client])).entries()],f=s.filter(x=>x.client===a.client),g=Dl(s,a),y=typeof(g==null?void 0:g.credentialEnv)=="string"?g.credentialEnv:"",_=Array.isArray(g==null?void 0:g.credentialUsedBy)?g.credentialUsedBy:[],w=(g==null?void 0:g.credentialSource)||"missing",S=!!(g!=null&&g.credentialEnv)||a.credentialProfile==="a"||a.credentialProfile==="p",N=!!y&&t.mode==="new"&&(g==null?void 0:g.authConfigured)!==!0&&!a.credentialValue&&!a.allowMissingCredential,C=x=>{x&&c({client:x.client,provider:x.provider,credentialProfile:x.credentialProfile||"",managedModel:x.model||"",protocol:x.protocol||"",permissionPolicy:x.permissionPolicyDefault||"standard",credentialSourcePolicy:"auto",rc:!!x.rc,displayName:x.custom?m("fleet-custom-provider-default"):"",baseUrl:x.custom?"":x.endpoint||"",envKey:x.defaultEnvKey||"",providerId:"nexuscrew-custom",credentialValue:"",credentialReveal:!1,allowMissingCredential:!1,...t.mode==="new"?{id:x.id,label:""}:{}})};return l.jsxs("div",{className:"nc-set-form nc-fleet-form",children:[l.jsx("b",{children:t.mode==="new"?m("fleet-new-engine"):`${m("edit")} ${a.id}`}),l.jsx("input",{value:a.id,disabled:t.mode!=="new",placeholder:"id",onChange:x=>c({id:x.target.value})}),l.jsx("input",{value:a.label,placeholder:m("label"),onChange:x=>c({label:x.target.value})}),l.jsxs("select",{value:a.kind,disabled:t.mode!=="new",onChange:x=>c({kind:x.target.value}),children:[l.jsx("option",{value:"managed",children:m("fleet-managed")}),l.jsx("option",{value:"custom",children:m("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:t.mode!=="new",onChange:x=>C(s.find(M=>M.client===x.target.value&&M.default)||s.find(M=>M.client===x.target.value)),children:h.map(([x,M])=>l.jsx("option",{value:x,children:M},x))}),l.jsx("select",{value:((E=Dl(s,a))==null?void 0:E.id)||"",disabled:t.mode!=="new",onChange:x=>C(s.find(M=>M.id===x.target.value)),children:f.map(x=>l.jsx("option",{value:x.id,children:x.label},x.id))})]}),a.client!=="shell"&&l.jsxs(l.Fragment,{children:[l.jsx("input",{value:a.managedModel,list:"nc-managed-models",placeholder:m(g!=null&&g.requiresModel?"fleet-model-required":"fleet-model-default"),onChange:x=>c({managedModel:x.target.value})}),l.jsx("datalist",{id:"nc-managed-models",children:[...(g==null?void 0:g.models)||[],...a.modelOptions||[]].filter((x,M,T)=>x&&T.indexOf(x)===M).map(x=>l.jsx("option",{value:x},x))})]}),g!=null&&g.supportsUnsafe?l.jsxs("select",{value:a.permissionPolicy,onChange:x=>c({permissionPolicy:x.target.value}),children:[l.jsx("option",{value:"standard",children:m("fleet-standard-permissions")}),l.jsx("option",{value:"unsafe",children:m("fleet-unsafe-permissions")})]}):l.jsx("small",{children:m("fleet-standard-permissions")}),(g==null?void 0:g.supportsUnsafe)&&a.permissionPolicy==="unsafe"&&l.jsx("small",{className:"nc-err",children:m("fleet-unsafe-warning")}),S&&l.jsxs("select",{"aria-label":m("fleet-credential-source-policy"),value:a.credentialSourcePolicy||"auto",onChange:x=>c({credentialSourcePolicy:x.target.value}),children:[l.jsx("option",{value:"auto",children:m("fleet-credential-source-policy-auto")}),l.jsx("option",{value:"nexuscrew-store",children:m("fleet-credential-source-policy-nexuscrew-store")}),l.jsx("option",{value:"environment",children:m("fleet-credential-source-policy-environment")})]}),(g==null?void 0:g.credentialEnv)===!0&&l.jsxs(l.Fragment,{children:[l.jsx("input",{value:a.envKey,placeholder:m("fleet-api-key-env"),onChange:x=>c({envKey:x.target.value})}),l.jsx("small",{children:m("fleet-custom-secret-help")})]}),y&&l.jsxs("section",{className:"nc-fleet-key","aria-label":m("fleet-key-section"),children:[l.jsxs("div",{className:"nc-fleet-key-head",children:[l.jsx("b",{children:m("fleet-key-section")}),l.jsx("span",{children:m(`fleet-credential-source-${w}`)})]}),l.jsxs("label",{className:"nc-field",children:[m("fleet-key-variable"),l.jsx("input",{value:y,readOnly:!0,"aria-label":m("fleet-key-variable")})]}),l.jsx("small",{children:_.length?m("fleet-key-used-by").replace("{engines}",_.join(", ")):m("fleet-key-used-by-none")}),_.length>0&&l.jsx("small",{children:m("fleet-key-shared-impact").replace("{key}",y).replace("{engines}",_.join(", "))}),l.jsxs("div",{className:"nc-fleet-key-input",children:[l.jsx("input",{type:a.credentialReveal?"text":"password",value:a.credentialValue||"","aria-label":m("fleet-key-value").replace("{key}",y),autoComplete:"new-password",spellCheck:!1,autoCapitalize:"none",autoCorrect:"off",placeholder:g!=null&&g.authConfigured||t.mode==="edit"?m("fleet-key-blank-keeps"):m("fleet-key-enter"),onChange:x=>c({credentialValue:x.target.value,allowMissingCredential:x.target.value?!1:a.allowMissingCredential})}),l.jsx("button",{type:"button",className:"nc-btn ghost","aria-label":m(a.credentialReveal?"fleet-key-hide":"fleet-key-reveal"),onClick:()=>c({credentialReveal:!a.credentialReveal}),children:m(a.credentialReveal?"fleet-key-hide":"fleet-key-reveal")})]}),l.jsx("small",{children:m("fleet-key-local-help")}),t.mode==="new"&&(g==null?void 0:g.authConfigured)!==!0&&!a.credentialValue&&l.jsxs("label",{className:"nc-check nc-fleet-key-missing",children:[l.jsx("input",{type:"checkbox",checked:!!a.allowMissingCredential,onChange:x=>c({allowMissingCredential:x.target.checked})}),m("fleet-key-create-missing")]}),(g==null?void 0:g.notice)&&l.jsx("small",{className:"nc-fleet-provider-notice",children:m(`fleet-provider-notice-${g.notice}`)})]}),(g==null?void 0:g.notice)&&!y&&l.jsx("small",{className:"nc-fleet-provider-notice",children:m(`fleet-provider-notice-${g.notice}`)}),a.provider==="custom"&&l.jsxs(l.Fragment,{children:[l.jsx("input",{value:a.displayName,placeholder:m("fleet-provider-display"),onChange:x=>c({displayName:x.target.value})}),l.jsx("input",{value:a.baseUrl,placeholder:"https://api.example.com/v1",onChange:x=>c({baseUrl:x.target.value})}),((g==null?void 0:g.protocols)||[]).length>1&&l.jsx("select",{value:a.protocol,onChange:x=>c({protocol:x.target.value}),children:g.protocols.map(x=>l.jsx("option",{value:x,children:x},x))}),l.jsxs("div",{className:"nc-fleet-pair",children:[l.jsx("input",{value:a.envKey,placeholder:m("fleet-api-key-env"),onChange:x=>c({envKey:x.target.value})}),l.jsx("input",{value:a.providerId,placeholder:m("fleet-provider-id"),onChange:x=>c({providerId:x.target.value})})]}),l.jsxs("small",{children:[a.protocol," · ",m("fleet-custom-secret-help")]})]}),l.jsx("small",{children:m(a.client==="shell"?"fleet-shell-engine-help":"fleet-managed-help")})]}):l.jsxs(l.Fragment,{children:[l.jsx("input",{value:a.command,placeholder:m("command-path"),onChange:x=>c({command:x.target.value})}),l.jsx("textarea",{value:a.argsText,placeholder:m("args-lines"),onChange:x=>c({argsText:x.target.value})}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:a.rc,onChange:x=>c({rc:x.target.checked})})," ",m("fleet-remote-control")]}),l.jsxs("select",{value:a.promptMode,onChange:x=>c({promptMode:x.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:x=>c({promptFlag:x.target.value})}),l.jsxs("div",{className:"nc-fleet-pair",children:[l.jsx("input",{value:a.modelFlag,placeholder:"model flag",onChange:x=>c({modelFlag:x.target.value})}),l.jsx("input",{value:a.modelValue,placeholder:"model default",onChange:x=>c({modelValue:x.target.value})})]}),l.jsx("small",{children:m("env-write-only")}),d.map((x,M)=>l.jsxs("div",{className:"nc-fleet-env",children:[l.jsx("input",{value:x.key,disabled:x.configured,placeholder:"ENV_KEY",onChange:T=>{const U=d.slice();U[M]={...x,key:T.target.value},c({envRows:U})}}),l.jsx("input",{type:"password",value:x.value,placeholder:x.configured?"•••••• (unchanged)":"value",onChange:T=>{const U=d.slice();U[M]={...x,value:T.target.value},c({envRows:U})}}),l.jsx("button",{className:"nc-btn danger",onClick:()=>c({envRows:d.filter((T,U)=>U!==M)}),children:"×"})]},`${x.key}-${M}`)),l.jsx("button",{className:"nc-btn ghost",onClick:()=>c({envRows:[...d,{key:"",value:"",configured:!1}]}),children:"+ env"})]}),l.jsx("input",{value:a.panelUrl||"",maxLength:512,placeholder:m("fleet-panel-url"),onChange:x=>c({panelUrl:x.target.value})}),l.jsx("small",{children:m("fleet-panel-url-help")}),a.panelUrl&&!pg(a.panelUrl)&&l.jsx("small",{className:"nc-err",children:m("fleet-panel-url-invalid")}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{className:"nc-btn ghost",onClick:()=>e(null),children:m("cancel")}),l.jsx("button",{className:"nc-btn primary",disabled:n||!a.id||N||a.kind==="custom"&&!a.command||a.kind==="managed"&&(g==null?void 0:g.requiresModel)&&!a.managedModel||a.kind==="managed"&&(g==null?void 0:g.credentialEnv)===!0&&!a.envKey||a.kind==="managed"&&a.provider==="custom"&&(!a.displayName||!a.baseUrl||!a.envKey||!a.providerId),onClick:i,children:m("save")})]})]})}function ZP({state:t,setState:e,busy:n,onSave:i,onTest:s,profiles:a=[],canTest:c=!0}){const[d,h]=k.useState(null),[f,g]=k.useState(!1),y=t.form,_=C=>e({...t,form:{...y,...C}}),w=/^[^\x00-\x1f\x7f]{1,128}$/.test(y.id||""),S=!!(y.id||"").trim()&&!!(y.engine||"").trim()&&w,N=async()=>{h(null),g(!0);try{h(await s(y.engine,y.id))}catch(C){h({outcome:"unverified",detail:String(C&&C.message||C)})}g(!1)};return l.jsxs("div",{className:"nc-fleet-form",children:[l.jsxs("label",{className:"nc-field",children:[m("model-editor-engine"),l.jsxs("select",{value:y.engine||"",disabled:n||t.mode==="edit",onChange:C=>{h(null),_({engine:C.target.value})},children:[l.jsx("option",{value:"",children:"—"}),a.map(C=>l.jsx("option",{value:C.id,children:C.label?`${C.id} · ${C.label}`:C.id},C.id))]})]}),l.jsxs("label",{className:"nc-field",children:[m("model-editor-id"),l.jsx("input",{value:y.id||"",disabled:n||t.mode==="edit",placeholder:"qwen3.9-max",onChange:C=>{h(null),_({id:C.target.value})}})]}),l.jsx("small",{className:"nc-set-hint",children:m("model-editor-id-help")}),l.jsxs("label",{className:"nc-field",children:[m("model-editor-context"),l.jsx("input",{inputMode:"numeric",value:y.contextWindow||"",disabled:n,onChange:C=>_({contextWindow:C.target.value.replace(/[^0-9]/g,"").slice(0,9)})})]}),l.jsxs("label",{className:"nc-field",children:[m("model-editor-max-tokens"),l.jsx("input",{inputMode:"numeric",value:y.maxTokens||"",disabled:n,onChange:C=>_({maxTokens:C.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:C=>_({reasoning:C.target.checked})})," ",m("model-editor-reasoning")]}),l.jsxs("div",{className:"nc-set-row",children:[c&&l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||f||!S,onClick:N,children:m(f?"model-test-running":"model-test")}),d&&l.jsxs("span",{className:`nc-model-test ${d.outcome}`,children:[m(`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:m("model-test-unverified-help")}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:()=>e(null),children:m("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||!S,onClick:()=>i(y),children:m("save")})]})]})}function eT({token:t,route:e,targets:n=[],location:i,setLocation:s,state:a,setState:c,engines:d,mcpServers:h=[],managedCatalog:f=[],busy:g,onSave:y}){var I,D,O;const[_,w]=k.useState(null),[S,N]=k.useState(""),C=a.form,E=R=>c({...a,form:{...C,...R}}),x=d.find(R=>R.id===C.engine),M=((I=x==null?void 0:x.managed)==null?void 0:I.client)==="shell",T=((D=x==null?void 0:x.managed)==null?void 0:D.client)||"",U=((O=f.find(R=>R.client===T))==null?void 0:O.mcpManaged)!==!1,z=R=>{var F,$,W,le;const A=d.find(ve=>ve.id===R),j={...C.commands||{}};((F=x==null?void 0:x.managed)==null?void 0:F.client)==="shell"&&(C.command?j[C.engine]=C.command:delete j[C.engine]),E({engine:R,model:(($=C.models)==null?void 0:$[R])||((W=A==null?void 0:A.managed)==null?void 0:W.model)||((le=A==null?void 0:A.model)==null?void 0:le.value)||"",commands:j,command:j[R]||""})},K=R=>{const A={...C.commands||{}};R?A[C.engine]=R:delete A[C.engine],E({command:R,commands:A})},Q=M&&/[|&;<>()`$*?{}\[\]~]/.test(C.command||""),q=[...new Set([...h||[],...Array.isArray(C.mcp)?C.mcp:[]])].sort(),G=Array.isArray(C.mcp)?C.mcp.length?"some":"none":"all",H=R=>{var A;return E({mcp:R==="all"?void 0:R==="none"?[]:(A=C.mcp)!=null&&A.length?C.mcp:[...q]})},P=R=>{const A=Array.isArray(C.mcp)?C.mcp:[];E({mcp:A.includes(R)?A.filter(j=>j!==R):[...A,R].sort()})},L=async R=>{try{const A=await xm(t,R,e);w(A),E({cwd:A.path}),N("")}catch(A){N(String(A.message||A))}};return l.jsxs("div",{className:"nc-set-form nc-fleet-form",children:[l.jsx("b",{children:a.mode==="new"?m("fleet-new-cell"):`${m("edit")} ${C.id}`}),a.mode==="new"&&l.jsxs("label",{className:"nc-field",children:[m("location"),l.jsx("span",{className:"nc-req",children:" *"}),l.jsxs("select",{value:i,onChange:R=>{s(R.target.value),E({engine:""})},children:[l.jsx("option",{value:"",children:m("local")}),n.map(R=>l.jsxs("option",{value:R.route.join("/"),disabled:R.status&&R.status!=="up",children:[R.label,R.status&&R.status!=="up"?` · ${m("node-offline")}`:""]},R.route.join("/")))]})]}),l.jsx("input",{value:C.id,disabled:a.mode!=="new",placeholder:"id",onChange:R=>E({id:R.target.value})}),l.jsx("input",{value:C.label||"",maxLength:64,placeholder:m("fleet-cell-label"),onChange:R=>E({label:R.target.value})}),l.jsxs("div",{className:"nc-fleet-pair",children:[l.jsx("input",{value:C.cwd,placeholder:m("cwd"),onChange:R=>E({cwd:R.target.value})}),l.jsx("button",{className:"nc-btn ghost",onClick:()=>_?w(null):L(C.cwd),children:m("browse")})]}),_&&l.jsxs("div",{className:"nc-fs",children:[l.jsx("div",{className:"nc-fs-path",children:_.path}),l.jsxs("div",{className:"nc-fs-list",children:[_.parent&&l.jsxs("button",{className:"nc-fs-item nc-fs-nav",onClick:()=>L(_.parent),children:["↑ ",m("fs-parent")]}),(_.dirs||[]).map(R=>l.jsxs("button",{className:"nc-fs-item",onClick:()=>L(`${_.path.replace(/\/$/,"")}/${R}`),children:["📁 ",R]},R))]})]}),S&&l.jsx("div",{className:"nc-err",children:S}),l.jsx("select",{value:C.engine,onChange:R=>z(R.target.value),children:d.map(R=>l.jsx("option",{value:R.id,children:R.label},R.id))}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:!!C.boot,onChange:R=>E({boot:R.target.checked})})," ",m("fleet-boot")]}),l.jsx("input",{value:C.panelUrl||"",maxLength:512,placeholder:m("fleet-panel-url"),onChange:R=>E({panelUrl:R.target.value})}),l.jsx("small",{children:m("fleet-panel-url-help")}),C.panelUrl&&!pg(C.panelUrl)&&l.jsx("small",{className:"nc-err",children:m("fleet-panel-url-invalid")}),M?l.jsxs(l.Fragment,{children:[l.jsx("input",{value:C.command||"",maxLength:4096,placeholder:m("fleet-shell-command-placeholder"),onChange:R=>K(R.target.value)}),l.jsx("small",{children:C.command?m("fleet-shell-command-help"):m("fleet-shell-interactive")}),Q&&l.jsx("small",{className:"nc-note",children:m("fleet-shell-command-metachar")})]}):l.jsxs(l.Fragment,{children:[l.jsx("input",{value:C.model||"",list:"nc-cell-models",placeholder:m("fleet-model-override"),onChange:R=>E({model:R.target.value})}),l.jsx("datalist",{id:"nc-cell-models",children:((x==null?void 0:x.availableModels)||[]).map(R=>l.jsx("option",{value:R},R))}),l.jsx("textarea",{value:C.prompt||"",placeholder:m("cell-prompt"),onChange:R=>E({prompt:R.target.value})}),l.jsx("small",{children:m("cell-prompt-help")}),l.jsxs("label",{className:"nc-field",children:[m("cell-mcp"),l.jsxs("select",{value:G,onChange:R=>H(R.target.value),children:[l.jsx("option",{value:"all",children:m("cell-mcp-all")}),l.jsx("option",{value:"none",children:m("cell-mcp-none")}),l.jsx("option",{value:"some",children:m("cell-mcp-some")})]})]}),!U&&l.jsx("small",{className:"nc-note",children:m("cell-mcp-inert")}),G==="some"&&l.jsx("div",{className:"nc-fleet-mcp-list",children:q.map(R=>l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:(C.mcp||[]).includes(R),onChange:()=>P(R)})," ",R]},R))}),l.jsx("small",{children:m("cell-mcp-help")})]}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{className:"nc-btn ghost",onClick:()=>c(null),children:m("cancel")}),l.jsx("button",{className:"nc-btn primary",disabled:g||!C.id||!C.cwd||!C.engine,onClick:y,children:m("save")})]})]})}function Qb({token:t,route:e=[],state:n,setState:i,busy:s,onSave:a}){const[c,d]=k.useState(null),[h,f]=k.useState([]),[g,y]=k.useState(""),_=Array.isArray(e)?e.join("/"):"";k.useEffect(()=>{let E=!0;return Ju(t,_?_.split("/"):[]).then(x=>{E&&(f(x.engines||[]),y(""))}).catch(x=>{E&&(f([]),y(String(x.message||x)))}),()=>{E=!1}},[t,_]);const w=n.form,S=E=>i({...n,form:{...w,...E}}),N=async E=>{try{const x=await xm(t,E,e);d(x),S({cwd:x.path})}catch{}},C=!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:[m("import-as-cell")," · ",w.tmuxSession]}),l.jsx("small",{children:m("import-help")}),l.jsx("input",{value:w.tmuxSession,disabled:!0,placeholder:"tmux session",readOnly:!0}),l.jsx("input",{value:w.id,placeholder:m("name"),onChange:E=>S({id:E.target.value})}),l.jsxs("div",{className:"nc-fleet-pair",children:[l.jsx("input",{value:w.cwd,placeholder:m("cwd"),onChange:E=>S({cwd:E.target.value})}),l.jsx("button",{className:"nc-btn ghost",type:"button",onClick:()=>c?d(null):N(w.cwd),children:m("browse")})]}),c&&l.jsxs("div",{className:"nc-fs",children:[l.jsx("div",{className:"nc-fs-path",children:c.path}),l.jsxs("div",{className:"nc-fs-list",children:[c.parent&&l.jsxs("button",{className:"nc-fs-item nc-fs-nav",onClick:()=>N(c.parent),children:["↑ ",m("fs-parent")]}),(c.dirs||[]).map(E=>l.jsxs("button",{className:"nc-fs-item",onClick:()=>N(`${c.path.replace(/\/$/,"")}/${E}`),children:["📁 ",E]},E))]})]}),l.jsxs("select",{value:w.engine,onChange:E=>S({engine:E.target.value}),children:[l.jsx("option",{value:"",children:m("import-engine-required")}),h.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=>S({boot:E.target.checked})})," ",m("fleet-boot")]}),(n.err||g)&&l.jsx("div",{className:"nc-err",children:n.err||g}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{className:"nc-btn ghost",onClick:()=>i(null),children:m("cancel")}),l.jsx("button",{className:"nc-btn primary",disabled:s||!w.tmuxSession||!w.engine||!h.length,onClick:a,children:m(C?"import-as-cell":"save")})]})]})}function fu(t){const e=oo(t);return e===null?`~/${t}`:e?`~/${e}`:"~"}function tT(t){if(!t||typeof t.path!="string"||typeof t.home!="string")return"";const{path:e,home:n}=t;return!n||e===n||!e.startsWith(n+"/")?"":e.slice(n.length+1).replace(/\/+$/,"")}function nT({token:t,route:e,cell:n,busy:i=!1,onSaved:s,onClose:a}){const[c,d]=k.useState(""),[h,f]=k.useState(null),[g,y]=k.useState(!1),[_,w]=k.useState(""),S=typeof(n==null?void 0:n.cwdSuggestion)=="string"&&oo(n.cwdSuggestion)!==null?oo(n.cwdSuggestion):null,[N,C]=k.useState(S),E=n==null?void 0:n.id,x=i||g,M=async q=>{const G=oo(q);if(G===null){f({rel:"",dirs:[],loading:!1,err:m("fleet-cwd-repair-invalid")});return}f({rel:G,dirs:[],loading:!0,err:""});try{const H=await xm(t,G,e),P=tT(H);f({rel:P,dirs:Array.isArray(H.dirs)?H.dirs:[],loading:!1,err:""})}catch(H){f({rel:G,dirs:[],loading:!1,err:String(H&&H.message||H)})}},T=q=>{if(!h)return;const G=h.rel?`${h.rel}/${q}`:q;M(G)},U=()=>{h!=null&&h.rel&&M(h.rel.split("/").slice(0,-1).join("/"))},z=()=>{h&&(d(h.rel||""),f(null),w(""),C(null))},K=()=>{N!==null&&(d(N),C(null),w(""))},Q=async()=>{if(x)return;const q=oo(c);if(q===null){w(m("fleet-cwd-repair-invalid"));return}const G=fu(q);let H=!0;try{H=window.confirm(m("fleet-cwd-repair-confirm").replace("{id}",String(E||"")).replace("{path}",G))}catch{H=!1}if(H){y(!0),w(""),C(null);try{const P=await v0(t,E,{cwdRel:q},e);s==null||s(P)}catch(P){const L=P&&P.data||{};if(L.code==="unportable-cwd"){w(m("fleet-cwd-repair-unportable"));const I=Array.isArray(L.cells)?L.cells.find(O=>O&&O.id===E):null,D=I&&typeof I.suggestion=="string"?I.suggestion:null;D!==null&&oo(D)!==null&&C(D)}else w(String(P&&P.message||P))}finally{y(!1)}}};return l.jsxs("div",{className:"nc-set-form nc-fleet-form nc-cwd-repair",children:[l.jsx("b",{children:m("fleet-cwd-repair-title").replace("{id}",String(E||""))}),l.jsx("small",{className:"nc-set-info",children:m("fleet-cwd-repair-help")}),l.jsx("small",{className:"nc-cwd-no-source",children:m("fleet-cwd-repair-no-source-path")}),l.jsxs("label",{className:"nc-field",children:[m("cwd"),l.jsxs("div",{className:"nc-cwd-rel-row",children:[l.jsx("span",{className:"nc-cwd-rel-prefix",children:"~/"}),l.jsx("input",{value:c,placeholder:m("fleet-cwd-repair-placeholder"),autoComplete:"off",spellCheck:"false",autoCapitalize:"none",onChange:q=>d(q.target.value)}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:x,onClick:()=>h?f(null):M(""),children:m(h?"close":"fleet-cwd-repair-browse")})]})]}),l.jsx("div",{className:"nc-cwd-preview",children:m("fleet-cwd-repair-preview").replace("{path}",fu(c))}),h&&l.jsxs("div",{className:"nc-fs",children:[l.jsx("div",{className:"nc-fs-path",children:fu(h.rel)}),l.jsxs("div",{className:"nc-fs-list",children:[h.rel&&l.jsxs("button",{type:"button",className:"nc-fs-item nc-fs-nav",onClick:U,children:["↑ ",m("fs-parent")]}),h.loading&&l.jsx("div",{className:"nc-fs-empty",children:"…"}),!h.loading&&h.dirs.length===0&&l.jsx("div",{className:"nc-fs-empty",children:m("fleet-cwd-repair-fs-empty")}),!h.loading&&h.dirs.map(q=>l.jsxs("button",{type:"button",className:"nc-fs-item",onClick:()=>T(q),children:["📁 ",q]},q))]}),h.err&&l.jsx("div",{className:"nc-err",children:h.err}),l.jsx("div",{className:"nc-sheet-actions",children:l.jsx("button",{type:"button",className:"nc-btn primary",disabled:x||h.loading||!!h.err,onClick:z,children:m("fleet-cwd-repair-use-current")})})]}),_&&l.jsx("div",{className:"nc-err",role:"alert",children:_}),N!==null&&l.jsxs("div",{className:"nc-cwd-suggestion",role:"status",children:[l.jsx("span",{children:m("fleet-cwd-repair-suggestion")}),l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:K,children:m("fleet-cwd-repair-use-suggestion").replace("{path}",fu(N))})]}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:g,onClick:a,children:m("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:x,onClick:Q,children:g?"…":m("save")})]})]})}function iT({token:t,readonly:e,targets:n=[],startNewCell:i=!1,initialLocation:s=""}){const[a,c]=k.useState({engines:[],cells:[],managedCatalog:[]}),[d,h]=k.useState({available:!1,capabilities:[]}),[f,g]=k.useState(!1),[y,_]=k.useState(null),[w,S]=k.useState(null),[N,C]=k.useState({}),[E,x]=k.useState(null),[M,T]=k.useState(!1),[U,z]=k.useState(""),[K,Q]=k.useState(""),[q,G]=k.useState(s),[H,P]=k.useState(!1),[L,I]=k.useState(null),[D,O]=k.useState(null),[R,A]=k.useState(null),[j,F]=k.useState(!1),[$,W]=k.useState([]),[le,ve]=k.useState(null),[ie,ue]=k.useState("manage"),ne=k.useRef(!1),J=q?q.split("/"):[],ce=k.useCallback(async()=>{try{const ae=await Dr(t,J);h(ae);try{const re=await km(t,J);P(!!re.readonlyDefault)}catch{P(!1)}if(ae.provider==="builtin"&&(ae.capabilities||[]).includes("definitions")){const re=await Ju(t,J),Z=new Map((ae.engines||[]).map(_e=>[_e.id,_e]));if(re.engines=(re.engines||[]).map(_e=>{var ke;return{..._e,availableModels:((ke=Z.get(_e.id))==null?void 0:ke.models)||[]}}),c(re),(ae.capabilities||[]).includes("credentials"))try{W((await kk(t,J)).credentials||[])}catch{W([])}else W([])}z("")}catch(ae){z(String(ae.message||ae))}finally{g(!0)}},[t,q]);k.useEffect(()=>{ce();const ae=setInterval(ce,5e3);return()=>clearInterval(ae)},[ce]);const Ce=new Set((d.cells||[]).filter(ae=>ae.active).map(ae=>ae.cell)),Be=d.provider==="builtin"&&(d.capabilities||[]).includes("edit"),de=(d.capabilities||[]).includes("restore");k.useEffect(()=>{!i||ne.current||!Be||!a.engines.length||(ne.current=!0,x({mode:"new",form:Gb(a.engines[0].id)}))},[i,Be,a.engines]);const ye=async ae=>{T(!0),z(""),Q("");try{await ae(),await ce()}catch(re){z(String(re.message||re))}T(!1)},we=async(ae,re)=>{const Z=await jk(t,ae,re,J);return C(_e=>({..._e,[`${ae}::${re}`]:Z})),Z},Ue=ae=>ye(async()=>{const re={id:String(ae.id||"").trim(),engine:String(ae.engine||"").trim()};for(const Z of["contextWindow","maxTokens"]){const _e=String(ae[Z]||"").trim();_e&&(re[Z]=Number(_e))}ae.reasoning===!0&&(re.reasoning=!0),await Ak(t,re,J),S(null),await ce()}),mt=()=>ye(async()=>{var Lt;const ae=y.mode==="new",re=y.form,Z=a.managedCatalog||[],_e=re.kind==="managed"?Dl(Z,re):null,ke=typeof(_e==null?void 0:_e.credentialEnv)=="string"?_e.credentialEnv:"",rt=ke&&re.credentialValue||"",ct=XP(re,ae,Z);!ae&&y.form.kind==="custom"&&!y.form.modelFlag&&(ct.model=null),!ae&&y.form.kind==="custom"&&y.form.promptMode!=="flag"&&(ct.promptFlag=null);let pt;if(ae)pt=await Nk(t,ct,J);else{const X=y.original,xe=new Set(y.form.envRows.filter(Qe=>!Qe.remove).map(Qe=>Qe.key)),ze=(X.envKeys||[]).filter(Qe=>!xe.has(Qe)),Ke=Object.fromEntries(y.form.envRows.filter(Qe=>!Qe.remove&&Qe.key&&(!Qe.configured||Qe.value!=="")).map(Qe=>[Qe.key,Qe.value]));pt=await Lk(t,X.id,ct,y.form.kind==="custom"?{set:Ke,remove:ze}:void 0,J)}let At=null;if(ke&&rt)try{At=await K_(t,ke,rt,J),W(At.credentials||[])}catch{throw await ce(),ae&&_({mode:"edit",original:{...ct,id:re.id},form:{...re,credentialReveal:!1}}),new Error(m(ae?"fleet-key-partial-create":"fleet-key-partial-edit"))}await ce(),_(null),Q(m("fleet-saved"));const Wt=((Lt=((At==null?void 0:At.credentials)||[]).find(X=>X.envKey===ke))==null?void 0:Lt.activeCells)||[],Nt=[...new Set([...(pt==null?void 0:pt.activeCells)||[],...Wt])];if(Nt.length&&window.confirm(m("fleet-restart-confirm").replace("{cells}",Nt.join(", "))))for(const X of Nt)await ml(t,X,J)}),gt=()=>ye(async()=>{var Wt,Nt,Lt,X,xe,ze;const ae=E.mode==="new",re=E.form,Z={...ae?{id:re.id}:{},cwd:re.cwd,engine:re.engine,boot:!!re.boot},_e={...re.commands||{}},ke=a.engines.find(Ke=>Ke.id===re.engine);((Wt=ke==null?void 0:ke.managed)==null?void 0:Wt.client)==="shell"&&typeof re.command=="string"&&re.command.length?_e[re.engine]=re.command:((Nt=ke==null?void 0:ke.managed)==null?void 0:Nt.client)==="shell"&&delete _e[re.engine],(Object.keys(_e).length||!ae)&&(Z.commands=_e);const rt=(re.label||"").trim();ae?rt&&(Z.label=rt):Z.label=rt||null;const ct=(re.panelUrl||"").trim();ae?ct&&(Z.panelUrl=ct):Z.panelUrl=ct||null,ae?Array.isArray(re.mcp)&&(Z.mcp=re.mcp):Z.mcp=Array.isArray(re.mcp)?re.mcp:null,ae?(((Lt=ke==null?void 0:ke.managed)==null?void 0:Lt.client)!=="shell"&&re.model&&(Z.model=re.model),((X=ke==null?void 0:ke.managed)==null?void 0:X.client)!=="shell"&&re.prompt&&(Z.prompt=re.prompt)):(Z.model=((xe=ke==null?void 0:ke.managed)==null?void 0:xe.client)==="shell"?null:re.model||null,((ze=ke==null?void 0:ke.managed)==null?void 0:ze.client)!=="shell"&&(Z.prompt=re.prompt||null));const pt=ae?await Pk(t,Z,J):await v0(t,E.original.id,Z,J),At=ae?re.id:E.original.id;x(null),Q(m("fleet-saved")),!ae&&(pt!=null&&pt.active)&&window.confirm(m("fleet-restart-confirm").replace("{cells}",At))&&await ml(t,At,J)}),st=e||H,vt=d.capabilities||[],Et=J.length>0&&st,it=ae=>$.find(re=>{var Z;return(Z=re.engines)==null?void 0:Z.includes(ae.id)})||null,Dt=()=>ye(async()=>{var Z;const ae=await K_(t,le.envKey,le.value,J);W(ae.credentials||[]),ve(null),Q(m("fleet-credential-saved"));const re=((Z=(ae.credentials||[]).find(_e=>_e.envKey===le.envKey))==null?void 0:Z.activeCells)||[];if(re.length&&window.confirm(m("fleet-restart-confirm").replace("{cells}",re.join(", "))))for(const _e of re)await ml(t,_e,J)}),Ut=ae=>ye(async()=>{if(!window.confirm(m("fleet-credential-remove-confirm").replace("{key}",ae.envKey)))return;const re=await Ek(t,ae.envKey,J);W(re.credentials||[]),Q(m("fleet-credential-removed"))}),Bt=ae=>I({...ae,route:Array.isArray(ae==null?void 0:ae.route)?ae.route:J}),_t=async ae=>{if(!L)return;const re=L.cell||L.id,Z=Array.isArray(L.route)?L.route:J;if(ae.action==="up"){const _e=await bm(t,{cell:re,boot:!!ae.boot,...ae.engine?{engine:ae.engine}:{},...ae.model!==void 0?{model:ae.model}:{},...ae.permissionPolicy?{permissionPolicy:ae.permissionPolicy}:{}},Z),ke=Tm(_e);ke&&Q(ke.text)}else await Nu(t,{cell:re,boot:!!ae.boot},Z)},yt=(ae,re)=>{z(""),O({mode:"new",route:Array.isArray(re)?re:J,form:{tmuxSession:ae.name,id:"",engine:"",cwd:"",boot:!1},err:""})},un=()=>ye(async()=>{const ae=D.form;if(!ae.engine){O({...D,err:m("import-engine-required")});return}await Tk(t,{tmuxSession:ae.tmuxSession,id:ae.id||void 0,engine:ae.engine,cwd:ae.cwd||void 0,boot:!!ae.boot},ae.route||J),O(null),Q(m("fleet-saved"))}),oe=({engineRows:ae=[],cellRows:re=[],models:Z=[]})=>ye(async()=>{const _e=ae.filter(X=>X.selected),ke=_e.map(X=>bx(X.engine));if(ke.some(X=>!X))throw new Error(m("fleet-backup-invalid-engine"));const rt=_e.filter(X=>X.exists).map(X=>X.engine.id);if(rt.length&&!window.confirm(m("fleet-backup-confirm-engine-overwrite").replace("{engines}",rt.join(", "))))return;const ct=[...new Set([...a.engines.map(X=>X.id),...ke.map(X=>X.id)])],pt=[];for(const X of re.filter(xe=>xe.selected)){const xe=KP(X.cell,X.engine,ct);if(!xe)throw new Error(`${X.cell.id}: ${m("fleet-backup-engine-missing")}`);pt.push(xe)}const At=re.filter(X=>X.selected&&X.exists).map(X=>X.cell.id);if(At.length&&!window.confirm(m("fleet-backup-confirm-overwrite").replace("{cells}",At.join(", "))))return;const Wt=ke.length?await Dk(t,ke,rt.length>0,J,Z):{needsRestart:[]},Nt=pt.length?await Ik(t,pt,J):{needsRestart:[]},Lt=[...new Set([...Wt.needsRestart||[],...Nt.needsRestart||[]])];F(!1),Q(`${m("fleet-backup-restored").replace("{n}",String(pt.length))}${ke.length?` · ${ke.length} ${m("fleet-engines").toLowerCase()}`:""}${Lt.length?` · ${m("fleet-backup-needs-restart").replace("{cells}",Lt.join(", "))}`:""}`)}),et=l.jsxs("label",{className:"nc-field",children:[m("location"),l.jsxs("select",{value:q,onChange:ae=>{G(ae.target.value),_(null),x(null),z(""),Q(""),P(!1),g(!1),h({available:!1,capabilities:[]}),c({engines:[],cells:[],managedCatalog:[]}),W([]),ve(null)},children:[l.jsx("option",{value:"",children:m("local")}),n.map(ae=>l.jsxs("option",{value:ae.route.join("/"),disabled:ae.status&&ae.status!=="up",children:[ae.label,ae.status&&ae.status!=="up"?` · ${m("node-offline")}`:""]},ae.route.join("/")))]})]}),jt=l.jsxs("div",{className:"nc-fleet-view-tabs",role:"tablist","aria-label":m("tab-fleet"),children:[l.jsx("button",{type:"button",role:"tab","aria-selected":ie==="manage",className:`nc-set-tabbtn${ie==="manage"?" on":""}`,onClick:()=>ue("manage"),children:m("fleet-manage-location")}),l.jsx("button",{type:"button",role:"tab","aria-selected":ie==="overview",className:`nc-set-tabbtn${ie==="overview"?" on":""}`,onClick:()=>ue("overview"),children:m("fleet-network-overview")})]});return f?Be?l.jsxs("div",{className:"nc-set-tab nc-fleet-editor",children:[jt,ie==="overview"?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-set-info",children:m("fleet-overview-help")}),l.jsx(ep,{token:t,targets:n,readonly:e,onPower:Bt,onImport:yt})]}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-set-info",children:m("fleet-manage-help")}),et,l.jsxs("div",{className:"nc-set-row nc-fleet-backup-actions",children:[l.jsx("button",{className:"nc-btn ghost",disabled:st||M,onClick:()=>{z(""),F(!0)},children:m("fleet-backup")}),l.jsx("small",{children:m("fleet-backup-help")})]}),l.jsxs("div",{className:"nc-fleet-section-head",children:[l.jsx("b",{children:m("fleet-cells")}),l.jsx("span",{className:"nc-fleet-head-actions",children:l.jsxs("button",{className:"nc-btn primary",disabled:st||M||!a.engines.length,onClick:()=>{var ae;z(""),x({mode:"new",form:Gb((ae=a.engines[0])==null?void 0:ae.id)})},children:["+ ",m("add")]})})]}),a.cells.map(ae=>{const re=Ce.has(ae.id),Z=ae.needsRepair===!0;return l.jsxs("div",{className:"nc-fleet-item",children:[l.jsxs("span",{children:[l.jsx("b",{children:ae.id}),ae.label?l.jsxs("small",{className:"nc-fleet-label",children:[" ",ae.label]}):null,l.jsxs("small",{children:[ae.engine," · ",Z?l.jsx("span",{className:"nc-fleet-tag nc-fleet-tag-warn",children:m("fleet-cwd-needs-repair")}):ae.cwd,re?` · ${m("service-active")}`:` · ${m("cell-off")}`]})]}),l.jsxs("span",{children:[re&&vt.includes("down")&&l.jsx("button",{className:"nc-btn ghost",disabled:st||M,onClick:()=>ye(()=>Nu(t,{cell:ae.id},J)),children:m("stop")}),!re&&vt.includes("up")&&l.jsx("button",{className:"nc-btn primary",disabled:st||M,onClick:()=>Bt({cell:ae.id,id:ae.id,engine:ae.engine,model:ae.model,models:ae.models,permissionPolicies:ae.permissionPolicies,active:!1,boot:ae.boot}),children:m("start")}),re&&vt.includes("restart")&&l.jsx("button",{className:"nc-btn ghost",disabled:st||M,onClick:()=>ye(()=>ml(t,ae.id,J)),children:m("restart")}),Z?l.jsx("button",{className:"nc-btn ghost",disabled:st||M,onClick:()=>{z(""),A(ae)},children:m("fleet-cwd-repair")}):l.jsx("button",{className:"nc-btn ghost",disabled:st||M,onClick:()=>{var _e;z(""),x({mode:"edit",original:ae,form:{...ae,commands:{...ae.commands||{}},command:((_e=ae.commands)==null?void 0:_e[ae.engine])||""}})},children:m("edit")}),l.jsx("button",{className:"nc-btn danger",disabled:st||M,onClick:()=>ye(async()=>{window.confirm(m("fleet-remove-cell").replace("{id}",ae.id))&&await _0(t,ae.id,!0,J)}),children:"×"})]})]},ae.id)}),l.jsxs("div",{className:"nc-fleet-section-head",children:[l.jsx("b",{children:m("fleet-engines")}),l.jsxs("button",{className:"nc-btn primary",disabled:st||M,onClick:()=>{z(""),_({mode:"new",form:VP()})},children:["+ ",m("add")]})]}),a.engines.map(ae=>{var Z,_e;const re=it(ae);return l.jsxs("div",{className:"nc-fleet-item",children:[l.jsxs("span",{children:[l.jsx("b",{children:ae.label}),l.jsx("small",{children:ae.managed?`${ae.id} · ${ae.managed.client} / ${ae.managed.provider} · ${(Z=ae.managedInfo)!=null&&Z.configured?m("fleet-ready"):((_e=ae.managedInfo)==null?void 0:_e.reason)||m("fleet-not-ready")}`:`${ae.id} · ${ae.command}`}),re&&l.jsxs("small",{children:[re.envKey," · ",m(`fleet-credential-source-${re.source||"missing"}`)]})]}),l.jsxs("span",{children:[re&&l.jsx("button",{className:"nc-btn ghost",disabled:st||M,onClick:()=>{z(""),ve({envKey:re.envKey,value:""})},children:re.configured?m("fleet-credential-change"):m("fleet-credential-set")}),(re==null?void 0:re.source)==="local"&&l.jsx("button",{className:"nc-btn danger",disabled:st||M,onClick:()=>Ut(re),children:m("fleet-credential-forget")}),l.jsx("button",{className:"nc-btn ghost",disabled:st||M,onClick:()=>{z(""),_({mode:"edit",original:ae,form:GP(ae)})},children:m("edit")}),l.jsx("button",{className:"nc-btn danger",disabled:st||M,onClick:()=>ye(async()=>{window.confirm(m("fleet-remove-engine").replace("{id}",ae.id))&&await Rk(t,ae.id,J)}),children:"×"})]})]},ae.id)}),l.jsxs("div",{className:"nc-fleet-section-head",children:[l.jsx("b",{children:m("fleet-models")}),l.jsxs("button",{className:"nc-btn primary",disabled:st||M,onClick:()=>{z(""),S({mode:"new",form:{id:"",engine:""}})},children:["+ ",m("add")]})]}),!(a.models||[]).length&&l.jsx("small",{className:"nc-set-hint",children:m("fleet-no-models")}),(a.models||[]).map(ae=>{const re=`${ae.engine}::${ae.id}`,Z=N[re],_e=(a.engines||[]).some(ke=>ke.managed&&ke.managed.model===ae.id);return l.jsxs("div",{className:"nc-fleet-item",children:[l.jsxs("span",{children:[l.jsx("b",{children:ae.id}),l.jsxs("small",{children:[ae.engine,ae.contextWindow?` · ${ae.contextWindow}`:"",_e?` · ${m("model-in-use")}`:""]}),Z&&l.jsxs("small",{className:`nc-model-test ${Z.outcome}`,children:[m(`model-test-${Z.outcome}`),Z.outcome==="ok"&&Number.isInteger(Z.latencyMs)?` · ${Z.latencyMs}ms`:""]})]}),l.jsxs("span",{children:[vt.includes("model-test")&&l.jsx("button",{className:"nc-btn ghost",disabled:M||Et,onClick:()=>ye(()=>we(ae.engine,ae.id)),children:m("model-test")}),l.jsx("button",{className:"nc-btn danger",disabled:st||M,onClick:()=>ye(()=>Mk(t,ae.id,ae.engine,J)),children:"×"})]})]},re)})]}),w&&l.jsx(Er,{onClose:()=>S(null),label:m("fleet-models"),error:U,children:l.jsx(ZP,{state:w,setState:S,busy:M,onSave:Ue,onTest:we,profiles:a.managedCatalog||[],canTest:vt.includes("model-test")&&!Et})}),y&&l.jsx(Er,{onClose:()=>_(null),label:m("fleet-new-engine"),error:U,children:l.jsx(JP,{state:y,setState:_,busy:M,onSave:mt,catalog:a.managedCatalog||[]})}),E&&l.jsx(Er,{onClose:()=>x(null),label:m("fleet-new-cell"),error:U,children:l.jsx(eT,{token:t,route:J,targets:n,location:q,setLocation:G,state:E,setState:x,engines:a.engines,mcpServers:a.mcpServers||[],managedCatalog:a.managedCatalog||[],busy:M,onSave:gt})}),R&&l.jsx(Er,{onClose:()=>A(null),label:m("fleet-cwd-repair-title").replace("{id}",R.id),error:"",children:l.jsx(nT,{token:t,route:J,cell:R,busy:M,onSaved:async()=>{A(null),Q(m("fleet-cwd-repaired")),await ce()},onClose:()=>A(null)})}),K&&l.jsx("div",{className:"nc-set-note",children:K}),U&&l.jsx("div",{className:"nc-err",children:U}),j&&l.jsx(Er,{onClose:()=>F(!1),label:m("fleet-backup"),error:U,children:l.jsx(QP,{cells:a.cells,engines:a.engines,models:a.models||[],busy:M,canRestore:de,onRestore:oe,onClose:()=>F(!1)})}),le&&l.jsx(Er,{onClose:()=>ve(null),label:m("fleet-credential-title"),error:U,children:l.jsxs("div",{className:"nc-fleet-form nc-credential-form",children:[l.jsx("b",{children:m("fleet-credential-title")}),l.jsx("small",{children:m("fleet-credential-help")}),l.jsxs("label",{className:"nc-field",children:[le.envKey,l.jsx("input",{type:"password",autoComplete:"off",spellCheck:"false",autoCapitalize:"none",value:le.value,onChange:ae=>ve({...le,value:ae.target.value})})]}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{className:"nc-btn ghost",onClick:()=>ve(null),children:m("cancel")}),l.jsx("button",{className:"nc-btn primary",disabled:M||!le.value,onClick:Dt,children:m("save")})]})]})}),D&&l.jsx(Er,{onClose:()=>O(null),label:m("import-as-cell"),error:U,children:l.jsx(Qb,{token:t,route:D.route||J,state:D,setState:O,busy:M,onSave:un})}),L&&l.jsx(ju,{cell:L,token:t,route:Array.isArray(L.route)?L.route:J,onConfirm:async ae=>{try{await _t(ae)}finally{await ce()}},onClose:()=>I(null)})]}):l.jsxs("div",{className:"nc-set-tab",children:[jt,ie==="overview"?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-set-info",children:m("fleet-overview-help")}),l.jsx(ep,{token:t,targets:n,readonly:e,onPower:Bt,onImport:yt})]}):l.jsxs(l.Fragment,{children:[et,l.jsxs("div",{className:"nc-set-info",children:[m(U?"fleet-editor-load-error":"fleet-editor-unavailable"),!U&&d.reason?` ${d.reason}`:""]})]}),U&&l.jsx("div",{className:"nc-err",children:U}),D&&l.jsx(Er,{onClose:()=>O(null),label:m("import-as-cell"),error:U,children:l.jsx(Qb,{token:t,route:D.route||J,state:D,setState:O,busy:M,onSave:un})}),L&&l.jsx(ju,{cell:L,token:t,route:Array.isArray(L.route)?L.route:J,onConfirm:async ae=>{try{await _t(ae)}finally{await ce()}},onClose:()=>I(null)})]}):l.jsxs("div",{className:"nc-set-tab",children:[jt,ie==="overview"?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-set-info",children:m("fleet-overview-help")}),l.jsx(ep,{token:t,targets:n,readonly:e,onPower:Bt,onImport:yt})]}):l.jsxs(l.Fragment,{children:[et,l.jsx("div",{className:"nc-set-info",children:m("fleet-editor-loading")})]})]})}const gg="nc_notification_speech_v1",pu="nc-notification-speech",mm="nc-notification-speech-preview",sT=320,rT=2,oT=3e4,aT=1e4,lT=6e4,cT=64,Jb=Object.freeze({enabled:!1}),uT=Object.freeze({it:"it-IT",en:"en-US",es:"es-ES"}),dT=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"])}),vg=new WeakSet;function _g(t){return{enabled:(t&&typeof t=="object"&&!Array.isArray(t)?t:{}).enabled===!0}}function xx(){try{return typeof localStorage<"u"?localStorage:null}catch{return null}}function Zb(t=xx()){if(!t)return{...Jb};try{return _g(JSON.parse(t.getItem(gg)||"null"))}catch{return{...Jb}}}function hT(t,e=xx()){const n=_g(t);if(e)try{e.setItem(gg,JSON.stringify(n))}catch{}return n}function ya(){try{return typeof window<"u"?window:null}catch{return null}}function Bl(t=ya()){try{return!!(t&&t.speechSynthesis&&typeof t.speechSynthesis.speak=="function"&&typeof t.SpeechSynthesisUtterance=="function")}catch{return!1}}function Cx(t=ya()){return!!(t&&(typeof t=="object"||typeof t=="function")&&vg.has(t))}function gm(t=ya()){t&&(typeof t=="object"||typeof t=="function")&&vg.delete(t)}function oa(t){const e=String(t||"").trim().toLowerCase().split("-")[0];return uT[e]||""}function fd(t){return String(t||"").normalize("NFC").replace(/[\p{Cc}\p{Cf}]+/gu," ").replace(/\s+/g," ").trim()}function fT(t){const e=fd(t).normalize("NFD").replace(new RegExp("\\p{M}+","gu"),"").toLowerCase(),n=new Set(e.match(new RegExp("\\p{L}+","gu"))||[]);if(n.size<4)return"";const i=Object.entries(dT).map(([s,a])=>({lang:s,score:[...n].reduce((c,d)=>c+(a.has(d)?1:0),0)})).sort((s,a)=>a.score-s.score);return i[0].score>=3&&i[0].score-i[1].score>=2?i[0].lang:""}function pT(t,e){const n=oa(t&&t.lang);return n||oa(fT(t&&t.body))||oa(e)}function kx(t){try{const e=t&&t.speechSynthesis&&t.speechSynthesis.getVoices;return typeof e=="function"?Array.from(e.call(t.speechSynthesis)||[]).filter(Boolean):[]}catch{return[]}}function Ex(t,e){const n=oa(e);if(!n)return null;const i=Array.from(t||[]).filter(d=>d&&typeof d.lang=="string"&&d.lang.trim()),s=i.filter(d=>d.lang.trim().toLowerCase()===n.toLowerCase()),a=n.slice(0,2).toLowerCase(),c=i.filter(d=>d.lang.trim().toLowerCase().split("-")[0]===a);return s.find(d=>d.default===!0)||s[0]||c.find(d=>d.default===!0)||c[0]||null}function e0(t){return fd(t).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 mT(t,e=sT){const n=e0(t&&t.title),i=e0(t&&t.body),s=[n,i&&i!==n?i:""].filter(Boolean).join(". "),a=Array.from(s);return a.length<=e?s:`${a.slice(0,Math.max(0,e-1)).join("").trimEnd()}…`}function gT(t){try{return!!(t&&t.visibilityState==="visible"&&typeof t.hasFocus=="function"&&t.hasFocus())}catch{return!1}}function Nx(t=ya()){if(!Bl(t))return!1;try{return t.speechSynthesis.cancel(),!0}catch{return!1}}function vT(t){try{t&&typeof t.dispatchEvent=="function"&&typeof t.Event=="function"&&t.dispatchEvent(new t.Event(mm))}catch{}}function _T(t,e,n=ya(),i={}){var f;if(gm(n),!Bl(n))return Promise.resolve(!1);const s=fd(t);if(!s||(f=i.signal)!=null&&f.aborted)return Promise.resolve(!1);const a=Number.isFinite(i.timeoutMs)&&i.timeoutMs>0?i.timeoutMs:aT,c=i.setTimer||((g,y)=>setTimeout(g,y)),d=i.clearTimer||(g=>clearTimeout(g)),h=i.signal;return vT(n),new Promise(g=>{let y=!1,_=!1,w=null,S=null;const N=C=>{if(!y){if(y=!0,h&&S&&h.removeEventListener("abort",S),w!==null&&d(w),C!==!0)try{n.speechSynthesis.cancel()}catch{}else vg.add(n);g(C)}};S=()=>N("no-activation"),h&&h.addEventListener("abort",S,{once:!0});try{n.speechSynthesis.cancel();const C=new n.SpeechSynthesisUtterance(s);C.lang=oa(e);const E=Ex(kx(n),C.lang);E&&(C.voice=E),C.onstart=()=>{_=!0},C.onend=()=>N(_?!0:"no-activation"),C.onerror=()=>N("voice-error"),w=c(()=>N("timeout"),a),n.speechSynthesis.speak(C)}catch{N("no-activation")}})}function yT(t={}){const e=t.scope||ya(),n=t.document||e&&e.document,i=Number.isInteger(t.maxPending)&&t.maxPending>=0?t.maxPending:rT,s=Number.isFinite(t.watchdogMs)&&t.watchdogMs>0?t.watchdogMs:oT,a=Number.isFinite(t.dedupWindowMs)&&t.dedupWindowMs>0?t.dedupWindowMs:lT,c=Number.isInteger(t.maxDedup)&&t.maxDedup>0?t.maxDedup:cT,d=t.now||Date.now,h=t.setTimer||((H,P)=>setTimeout(H,P)),f=t.clearTimer||(H=>clearTimeout(H)),g=t.isPrimed||(()=>Cx(e)),y=e&&e.speechSynthesis;let _=null,w=null,S=[],N=[],C=()=>{};const E=new Map,x=()=>{N=kx(e)};if(x(),y&&typeof y.addEventListener=="function")y.addEventListener("voiceschanged",x),C=()=>y.removeEventListener("voiceschanged",x);else if(y&&"onvoiceschanged"in y){const H=y.onvoiceschanged,P=(...L)=>{x(),typeof H=="function"&&H.apply(y,L)};y.onvoiceschanged=P,C=()=>{y.onvoiceschanged===P&&(y.onvoiceschanged=H)}}const M=H=>{if(H&&typeof H.id=="string"&&H.id)return`id:${H.id}`;const P=Number(H&&H.ts),L=fd(H&&H.title);return Number.isFinite(P)&&L?`frame:${P}:${L}`:""},T=H=>{if(!H)return!0;const P=d();for(const[L,I]of E)P-I>=a&&E.delete(L);if(E.has(H))return!1;for(E.set(H,P);E.size>c;)E.delete(E.keys().next().value);return!0},U=()=>{w!==null&&f(w),w=null},z=()=>{U(),_&&(_.onend=null,_.onerror=null,_=null),Nx(e)},K=H=>{if(!Bl(e))return S=[],"unsupported";let P;try{P=new e.SpeechSynthesisUtterance(H.text),P.lang=oa(H.lang);const I=Ex(N,P.lang);I&&(P.voice=I)}catch{return S=[],"error"}_=P;const L=()=>{if(_!==P)return;U(),_=null,P.onend=null,P.onerror=null;const I=S.shift();I&&K(I)};P.onend=L,P.onerror=L;try{return w=h(()=>{if(_!==P)return;_=null,P.onend=null,P.onerror=null;try{e.speechSynthesis.cancel()}catch{}U();const I=S.shift();I&&K(I)},s),e.speechSynthesis.speak(P),"speaking"}catch{return L(),"error"}},Q=(H,P)=>{if(!Bl(e))return"unsupported";const L=mT(H);if(!L)return"empty";if(!T(M(H)))return"duplicate";if(!gT(n))return"inactive";if(!g())return"unprimed";const I={text:L,lang:P};return H&&H.urgency==="high"?(S=[],z(),K(I)):_?i===0?"dropped":(S.length>=i&&S.shift(),S.push(I),"queued"):K(I)},q=()=>{S=[],z()};return{enqueue:Q,stop:q,dispose:()=>{q(),C(),C=()=>{}}}}function Lx(){const[t,e]=k.useState(Zb);k.useEffect(()=>{const i=s=>{if((s==null?void 0:s.type)==="storage"&&s.key!==gg&&s.key!==null)return;const a=(s==null?void 0:s.type)===pu?_g(s.detail):Zb();e(a)};return window.addEventListener(pu,i),window.addEventListener("storage",i),()=>{window.removeEventListener(pu,i),window.removeEventListener("storage",i)}},[]);const n=k.useCallback(i=>{const s=hT({enabled:i===!0});return e(s),window.dispatchEvent(new CustomEvent(pu,{detail:s})),s.enabled},[]);return[t.enabled,n]}function wT({text:t}){const[e,n]=k.useState(!1),i=async()=>{try{await navigator.clipboard.writeText(t),n(!0),setTimeout(()=>n(!1),1500)}catch{}};return l.jsxs("div",{className:"nc-set-copyline",children:[l.jsx("code",{children:t}),l.jsxs("button",{type:"button",className:"nc-btn ghost",onClick:i,children:[l.jsx(ht,{name:"copy",size:14})," ",m(e?"copied":"copy")]})]})}function bT({value:t}){const[e,n]=k.useState("");return k.useEffect(()=>{let i=!0;return Wj.toDataURL(t,{margin:1,width:220}).then(s=>{i&&n(s)}).catch(()=>{}),()=>{i=!1}},[t]),e?l.jsx("img",{src:e,width:"220",height:"220",alt:"NexusCrew pairing QR"}):null}function ST({token:t,nodes:e,roster:n,settings:i,readonly:s,refresh:a,refreshAliases:c,vlUnavailable:d=[],accessRevision:h=null}){const[f,g]=k.useState(null),[y,_]=k.useState(null),[w,S]=k.useState(null),[N,C]=k.useState({ssh:"",sshPort:"",name:""}),[E,x]=k.useState(""),[M,T]=k.useState(""),[U,z]=k.useState(!1),[K,Q]=k.useState(null),q=Date.now(),G=i&&i.deviceName||"",H=(e||[]).filter(j=>j&&j.direction==="outbound"&&j.name&&j.ssh),P=H.find(j=>j.name===E)||H[0]||null,L=P?hp(P.tunnel,q):null,I=P!=null&&P.shared?L!=null&&L.up?"share-local-active":"share-local-pending":L!=null&&L.up?"share-local-private":"share-local-private-down",D=[{key:"peer-group-hubs",rows:(e||[]).filter(j=>j.kind!=="transitive"&&j.kind!=="vl"&&j.relation!=="client")},{key:"peer-group-clients",rows:(e||[]).filter(j=>j.kind!=="transitive"&&j.kind!=="vl"&&j.relation==="client")},{key:"peer-group-routed",rows:(e||[]).filter(j=>j.kind==="transitive")},{key:"peer-group-vl",rows:(e||[]).filter(j=>j.kind==="vl")}],O=K&&(e||[]).find(j=>`${j.kind||"direct"}:${j.nodeId||j.name}`===K)||null,R=async j=>{if(P){g(null),_(`${P.name}:share`);try{const F=await Kk(t,P.name,j);await a(),F&&F.reversePoolPending===!0&&g(`${P.name}: ${m("share-reverse-pool-pending")}`)}catch(F){const $=F!=null&&F.data&&F.data.shared===!1?F.data:null;if($)try{await a()}catch{}const W=F!=null&&F.data&&typeof F.data.hint=="string"?F.data.hint:"",le=($==null?void 0:$.revoked)===!0&&($==null?void 0:$.localReconcilePending)===!0?m("share-off-local-reconcile-pending"):($==null?void 0:$.revoked)===!1&&($==null?void 0:$.reconcilePending)===!0?m("share-off-hub-reconcile-pending"):"",ve=F!=null&&F.data&&F.data.reversePoolPending===!0?m("share-reverse-pool-pending"):"",ie=F!=null&&F.data&&typeof F.data.code=="string"?F.data.code:"",ue=F!=null&&F.data&&typeof F.data.detail=="string"?F.data.detail.trim():"",ne=ue&&ue!==String(F.message||"")?ue:"";g(`${P.name}: ${String(F.message||F)}${ie?` [${ie}]`:""}${ne?` — ${ne}`:""}${W?` — ${W}`:""}${le?` — ${le}`:""}${ve?` — ${ve}`:""}`)}_(null)}},A=async()=>{g(null);const j=Tr(N.name||M||G||"NexusCrew"),F=c5({name:j,ssh:N.ssh,sshPort:N.sshPort});if(!F.ok){g(m(F.error));return}_("invite");try{S(await Hk(t,{...M||G?{label:M||G}:{},name:j,ssh:F.value.ssh,...F.value.sshPort?{sshPort:F.value.sshPort}:{}}))}catch($){g(String($.message||$))}_(null)};return l.jsxs("div",{className:"nc-set-tab",children:[l.jsx("div",{className:"nc-sheet-label",children:m("peer-inventory-title")}),(e||[]).length===0&&l.jsx("div",{className:"nc-empty",children:m("no-nodes")}),D.map(j=>j.rows.length>0&&l.jsxs("div",{className:"nc-peer-group",children:[l.jsxs("div",{className:"nc-peer-group-title",children:[m(j.key)," ",l.jsx("span",{children:j.rows.length})]}),j.rows.map(F=>{const $=nP(F);if(!$)return null;const W=`${F.kind||"direct"}:${F.nodeId||F.name}`,le=$.routed?{up:$.reach.up,since:null}:hp(F.tunnel,q);return l.jsxs("button",{type:"button",className:`nc-set-node nc-node-row${$.routed?" routed":""}`,"aria-label":`${$.title} — ${m("node-detail-open")}`,onClick:()=>Q(W),children:[l.jsx("span",{className:`nc-dot ${$.reach.up?"on":""}`}),l.jsxs("span",{className:"nc-node-row-text",children:[l.jsx("b",{children:$.title}),l.jsxs("small",{children:[$.routed?$.routeLabel:`${$.subtitle} · ${m($.exposure.shortKey)}`,!$.routed&&$.exposure.shortKey==="visibility-selected"?` (${$.exposure.count})`:""]})]}),l.jsxs("span",{className:`nc-set-tunnel${$.reach.up?" up":""}`,children:[m($.reach.key),le.since?` · ${le.since}`:""]}),l.jsx("span",{className:"nc-node-row-more",children:l.jsx(ht,{name:"chevronDown",size:14})})]},W)})]},j.key)),d.length>0&&l.jsxs("div",{className:"nc-err",children:[m("vl-owners-unavailable"),": ",d.map(j=>j.label||j.route.join("/")).join(", ")]}),O&&l.jsx(SP,{node:O,nodes:e||[],token:t,readonly:s,refresh:a,onClose:()=>Q(null),peerAccessRevision:h}),(n||[]).some(j=>!j.direct&&j.instanceId)&&l.jsxs("div",{className:"nc-set-form",children:[l.jsx("div",{className:"nc-sheet-label",children:m("routed-node-aliases")}),l.jsx("small",{className:"nc-set-hint",children:m("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:s||!!y,onClick:async()=>{const F=window.prompt(m("node-local-alias"),j.alias||"");if(F!=null){if(F.trim()&&!ca(F.normalize("NFC"))){g(m("err-label"));return}_(`${j.instanceId}:alias`),g(null);try{F.trim()?await Wk(t,j.instanceId,F):await G_(t,j.instanceId),c()}catch($){g(String($.message||$))}_(null)}},children:m("alias-on-device")}),j.alias&&l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:s||!!y,onClick:async()=>{_(`${j.instanceId}:alias-reset`),g(null);try{await G_(t,j.instanceId),c()}catch(F){g(String(F.message||F))}_(null)},children:m("reset-alias")})]})]},j.instanceId))]}),P&&l.jsxs("div",{className:"nc-set-form nc-local-share",children:[l.jsx("div",{className:"nc-sheet-label",children:m("share-local-heading")}),H.length>1&&l.jsxs("label",{className:"nc-field",children:[m("share-local-hub"),l.jsx("select",{value:P.name,disabled:s||!!y,onChange:j=>x(j.target.value),children:H.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:P.shared===!0,disabled:s||!!y,onChange:j=>R(j.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:m("share-local-through").replace("{device}",G||m("local")).replace("{hub}",P.label||P.name)}),l.jsx("small",{children:m(P.shared?"share-node-on-desc":"share-node-off-desc")})]})]}),l.jsx("div",{className:`nc-set-test${P.shared&&(L!=null&&L.up)?" ok":L!=null&&L.up?"":" ko"}`,children:m(I)}),!(L!=null&&L.up)&&l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:s||!!y,onClick:()=>R(P.shared===!0),children:m("share-local-reconnect")})]}),l.jsx(lx,{token:t,deviceDefault:G,localNodeId:i&&i.nodeId||"",localNameDefault:i&&i.localName||"",readonly:s,onSuccess:a}),l.jsxs("div",{className:"nc-set-form",children:[l.jsx("div",{className:"nc-sheet-label",children:m("invite-node")}),l.jsx("small",{className:"nc-set-hint",children:m("invite-v2-hint")}),l.jsxs("div",{className:"nc-set-info nc-invite-endpoint",children:[m("invite-target-local"),": ",l.jsx("b",{children:G||m("invite-target-this")})]}),l.jsxs("label",{className:"nc-field",children:[m("invite-endpoint-label"),l.jsx("input",{placeholder:"user@host",value:N.ssh,disabled:s,onChange:j=>C({...N,ssh:j.target.value})}),l.jsx("small",{className:"nc-set-hint",children:m("invite-endpoint-needed")})]}),H.length>0&&l.jsx("small",{className:"nc-set-hint nc-invite-hub-hint",children:m("invite-hub-only")}),U&&l.jsxs("div",{className:"nc-invite-advanced",children:[l.jsxs("label",{className:"nc-field",children:[m("node-ssh-port-label"),l.jsx("input",{inputMode:"numeric",placeholder:"22",value:N.sshPort,disabled:s,onChange:j=>C({...N,sshPort:j.target.value.replace(/[^0-9]/g,"").slice(0,5)})})]}),l.jsxs("label",{className:"nc-field",children:[m("device-name-label"),l.jsx("input",{placeholder:G||"NexusCrew",value:M,disabled:s,onChange:j=>T(j.target.value)}),l.jsx("small",{className:"nc-set-hint",children:m("device-name-hint")})]}),l.jsxs("label",{className:"nc-field",children:[m("node-name-label"),l.jsx("input",{placeholder:Tr(M||G||m("node-name-ph")),value:N.name,disabled:s,onChange:j=>C({...N,name:j.target.value?Tr(j.target.value):""})})]})]}),l.jsxs("div",{className:"nc-set-row nc-invite-actions",children:[l.jsx("button",{type:"button",className:"nc-btn primary",disabled:s||!!y||!N.ssh.trim(),onClick:A,children:m("create-pairing-link")}),l.jsxs("button",{type:"button",className:"nc-btn ghost",disabled:!!y,onClick:()=>z(j=>!j),children:[U?"▾":"▸"," ",m("pair-advanced")]})]}),w&&l.jsxs(l.Fragment,{children:[l.jsx(bT,{value:w.pairingUrl}),l.jsx(wT,{text:w.pairingUrl}),l.jsx("div",{className:"nc-set-info",children:m("invite-next-steps")})]})]}),f&&l.jsx("div",{className:"nc-err",children:f})]})}function xT({token:t,readonly:e}){const[n,i]=k.useState("idle"),[s,a]=k.useState(()=>fx()),[c,d]=k.useState(!1),[h,f]=k.useState(null);k.useEffect(()=>{let _=!1;return EP().then(w=>{_||i(w)}),()=>{_=!0}},[]);const g=async()=>{f(null),d(!0);try{n==="subscribed"?(await Yb(t),i("idle")):(await NP(t),i("subscribed"))}catch(_){const w=String(_.message||_);w==="push-denied"?(i("denied"),f(m("push-denied"))):w==="push-unsupported"?(i("unsupported"),f(m("push-unsupported"))):f(w==="push-disabled-local"?m("push-local-disabled"):w)}d(!1)},y=async()=>{const _=xP({enabled:s.enabled!==!1});if(a(_),f(null),_.enabled===!1&&n==="subscribed"){d(!0);try{await Yb(t),i("idle")}catch{}d(!1)}};return n==="unsupported"?l.jsx("div",{className:"nc-set-info",children:m("push-unsupported")}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:y,disabled:c,children:s.enabled===!1?m("push-local-on"):m("push-local-off")}),l.jsx("span",{className:"nc-set-info",children:s.enabled===!1?m("push-local-off-note"):m("push-local-help")})]}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:e||c||n==="denied",title:e?m("settings-readonly"):"",onClick:g,children:m(n==="subscribed"?"push-disable":"push-enable")}),l.jsx("span",{className:"nc-set-info",children:m(n==="subscribed"?"push-on":n==="denied"?"push-denied":"push-off")})]}),h&&l.jsx("div",{className:"nc-err",children:h})]})}function CT(){const[t,e]=Lx(),[n,i]=k.useState(""),[s,a]=k.useState(""),[c,d]=k.useState(!1),[h,f]=k.useState(Cx),g=k.useRef(0),y=k.useRef(!1),_=k.useRef(null),w=Bl();k.useEffect(()=>()=>{var C;g.current+=1,y.current&&((C=_.current)==null||C.abort(),_.current=null,y.current=!1,gm())},[]);const S=async()=>{const C=g.current+=1,E=typeof AbortController=="function"?new AbortController:null;i(""),a(""),d(!0),f(!1),y.current=!0,_.current=E;const x=await _T(m("notification-speech-preview"),Lu(),void 0,E?{signal:E.signal}:{});return C!==g.current||(_.current=null,y.current=!1,d(!1),f(x===!0),x===!0?a(m("notification-speech-preview-ok")):i(m(x==="voice-error"?"notification-speech-preview-voice-error":x==="timeout"?"notification-speech-preview-timeout":"notification-speech-preview-failed"))),x},N=C=>{var E;if(e(C),i(""),a(""),C)S();else{g.current+=1;const x=y.current;(E=_.current)==null||E.abort(),_.current=null,y.current=!1,d(!1),f(!1),gm(),x||Nx()}};return l.jsxs("div",{className:"nc-set-form",children:[l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox","aria-label":m("notification-speech-enable"),checked:t,disabled:!w,onChange:C=>N(C.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:m("notification-speech-enable")}),l.jsx("small",{children:m("notification-speech-help")})]})]}),w?l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:!t||c,onClick:()=>{S()},children:m(c?"notification-speech-testing":"notification-speech-test")})}):l.jsx("div",{className:"nc-set-info",children:m("notification-speech-unsupported")}),t&&!h&&!c&&!n&&l.jsx("div",{className:"nc-set-info",children:m("notification-speech-needs-test")}),s&&l.jsx("div",{className:"nc-set-info",role:"status",children:s}),n&&l.jsx("div",{className:"nc-err",children:n})]})}function kT({token:t,readonly:e,nodes:n=[],settings:i=null}){const[s,a]=k.useState(null),[c,d]=k.useState([]),[h,f]=k.useState({name:"",mode:"primary-failover",targets:[]}),[g,y]=k.useState(null),[_,w]=k.useState(!1),[S,N]=k.useState(null),[C,E]=k.useState(""),x=k.useCallback(async()=>{try{const[R,A]=await Promise.all([Yk(t),Jk(t)]);a(R),d(Array.isArray(A==null?void 0:A.groups)?A.groups:[]),E("")}catch(R){E(String(R.message||R))}},[t]);k.useEffect(()=>{x()},[x]);const M=async R=>{w(!0),N(null),E("");try{a(await Gk(t,R))}catch(A){E(String(A.message||A))}w(!1)},T=async()=>{w(!0),N(null),E("");try{N({kind:"test",...await Xk(t)})}catch(R){E(String(R.message||R))}w(!1)},U=async()=>{w(!0),N(null),E("");try{N({kind:"stop",...await Qk(t)})}catch(R){E(String(R.message||R))}w(!1)},z=[],K=new Set,Q=(R,A)=>{const j=typeof R=="string"?R.toLowerCase():"";!/^[a-f0-9]{32}$/.test(j)||K.has(j)||(K.add(j),z.push({id:j,label:A||j}))};Q(i==null?void 0:i.nodeId,m("audio-group-local"));for(const R of n||[])Q((R==null?void 0:R.nodeId)||(R==null?void 0:R.instanceId),(R==null?void 0:R.label)||(R==null?void 0:R.name)||(R==null?void 0:R.nodeId));for(const R of h.targets)Q(R,`${R} (${m("audio-group-unavailable-target")})`);const q=(R=null)=>{E(""),R?(y(R.name),f({name:R.name,mode:R.mode,targets:[...R.targets||[]]})):(y(null),f({name:"",mode:"primary-failover",targets:[]}))},G=(R,A)=>f(j=>({...j,targets:A?[...new Set([...j.targets,R])]:j.targets.filter(F=>F!==R)})),H=async()=>{const R=h.name.trim().toLowerCase();if(!/^[a-z0-9][a-z0-9-]{0,31}$/.test(R)||h.targets.length<1){E(m("audio-group-invalid"));return}w(!0),E("");try{const A=await Zk(t,R,{targets:h.targets,mode:h.mode}),j=A==null?void 0:A.group;if(!j||!j.name)throw new Error(m("audio-group-save-failed"));d(F=>[...F.filter($=>$.name!==j.name),j].sort(($,W)=>$.name.localeCompare(W.name))),q(null)}catch(A){E(String(A.message||A))}w(!1)},P=async R=>{w(!0),E("");try{await e2(t,R),d(A=>A.filter(j=>j.name!==R)),g===R&&q(null)}catch(A){E(String(A.message||A))}w(!1)},L=(s==null?void 0:s.installed)===!0,I=(s==null?void 0:s.liveness)==="ready",D=(s==null?void 0:s.consent)===!0&&L&&I,O=S?S.kind==="stop"?m(S.stopped?"audio-stop-stopped":"audio-stop-idle"):S.status==="accepted"||S.status==="spoken"?m("audio-test-accepted"):S.status==="unknown"?m("audio-test-unknown"):`${m("audio-test-refused")}${S.reason?` (${S.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:m("audio-title")}),l.jsx("br",{}),m("audio-help")]}),s?l.jsxs(l.Fragment,{children:[l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox","aria-label":m("audio-consent"),checked:s.consent===!0,disabled:e||_,onChange:R=>{M(R.target.checked)}}),l.jsxs("span",{children:[l.jsx("b",{children:m("audio-consent")}),l.jsx("small",{children:m("audio-consent-help")})]})]}),l.jsxs("div",{className:"nc-set-form",children:[l.jsx("div",{className:"nc-sheet-label",children:m("audio-capability")}),l.jsxs("div",{className:"nc-set-info",children:[m("audio-adapter"),": ",s.adapter||m("audio-adapter-none"),l.jsx("br",{}),m("audio-installed"),": ",m(L?"audio-installed-yes":"audio-installed-no"),l.jsx("br",{}),m("audio-liveness"),": ",m(I?"audio-liveness-ready":"audio-liveness-unavailable"),Array.isArray(s.languages)&&s.languages.length>0&&l.jsxs(l.Fragment,{children:[l.jsx("br",{}),m("audio-languages"),": ",s.languages.join(", ")]})]}),s.limits&&l.jsxs("small",{className:"nc-set-hint",children:[m("audio-limits"),": ",s.limits]})]}),!s.consent&&l.jsx("div",{className:"nc-set-info",children:m("audio-test-needs-consent")}),!L&&l.jsx("div",{className:"nc-set-info",children:m("audio-unavailable")}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn primary",disabled:e||_||!D,title:e?m("settings-readonly"):"",onClick:()=>{T()},children:m(_?"audio-testing":"audio-test")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:_,onClick:()=>{U()},children:m(_?"audio-stopping":"audio-stop")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:_,onClick:()=>{x()},children:m("refresh")})]}),l.jsxs("div",{className:"nc-set-form",children:[l.jsx("div",{className:"nc-sheet-label",children:m("audio-groups-title")}),l.jsx("small",{className:"nc-set-hint",children:m("audio-groups-help")}),c.length===0&&l.jsx("div",{className:"nc-set-info",children:m("audio-groups-empty")}),c.map(R=>{var A;return l.jsxs("div",{className:"nc-set-row",children:[l.jsxs("span",{children:[l.jsx("b",{children:R.name})," ",l.jsxs("small",{children:["· ",R.mode==="fanout"?m("audio-group-fanout"):m("audio-group-primary")," · ",((A=R.targets)==null?void 0:A.length)||0]})]}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:e||_,onClick:()=>q(R),children:m("audio-group-edit")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:e||_,onClick:()=>{P(R.name)},children:m("audio-group-delete")})]},R.name)}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:e||_,onClick:()=>q(null),children:m("audio-group-new")})}),l.jsxs("label",{className:"nc-field",children:[m("audio-group-name"),l.jsx("input",{"aria-label":m("audio-group-name"),value:h.name,maxLength:"32",disabled:e||_,onChange:R=>f(A=>({...A,name:R.target.value}))})]}),l.jsxs("label",{className:"nc-field",children:[m("audio-group-mode"),l.jsxs("select",{"aria-label":m("audio-group-mode"),value:h.mode,disabled:e||_,onChange:R=>f(A=>({...A,mode:R.target.value})),children:[l.jsx("option",{value:"primary-failover",children:m("audio-group-primary")}),l.jsx("option",{value:"fanout",children:m("audio-group-fanout")})]})]}),l.jsx("div",{className:"nc-set-info",children:m("audio-group-targets")}),z.length===0?l.jsx("small",{className:"nc-set-hint",children:m("audio-group-no-targets")}):z.map(R=>l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:h.targets.includes(R.id),disabled:e||_,onChange:A=>G(R.id,A.target.checked)}),l.jsxs("span",{children:[R.label,l.jsx("small",{children:R.id})]})]},R.id)),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn primary",disabled:e||_,onClick:()=>{H()},children:m("audio-group-save")}),g&&l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:_,onClick:()=>q(null),children:m("audio-group-cancel")})]})]})]}):l.jsx("div",{className:"nc-set-info",children:m("audio-loading")}),O&&l.jsx("div",{className:"nc-set-note",role:"status",children:O}),C&&l.jsx("div",{className:"nc-err",children:C})]})}function ET(){const[t,e]=eg();return l.jsxs("div",{className:"nc-set-tab nc-input-settings",children:[l.jsx("div",{className:"nc-set-info",children:m("input-settings-local")}),l.jsxs("div",{className:"nc-set-form",children:[l.jsxs("label",{className:"nc-field",children:[m("terminal-keyboard-gesture"),l.jsx("select",{"aria-label":m("terminal-keyboard-gesture"),value:t.terminalKeyboardGesture,onChange:n=>e({terminalKeyboardGesture:n.target.value}),children:O1.map(n=>l.jsx("option",{value:n,children:m(`terminal-keyboard-${n}`)},n))}),l.jsx("small",{children:m("terminal-keyboard-gesture-help")})]}),l.jsxs("label",{className:"nc-field",children:[m("keybar-layout"),l.jsx("select",{"aria-label":m("keybar-layout"),value:t.keybarLayout,onChange:n=>e({keybarLayout:n.target.value}),children:$1.map(n=>l.jsx("option",{value:n,children:m(`keybar-layout-${n}`)},n))}),l.jsx("small",{children:m("keybar-layout-help")})]})]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:t.keybarKeepsKeyboardClosed,onChange:n=>e({keybarKeepsKeyboardClosed:n.target.checked})}),l.jsxs("span",{children:[l.jsx("b",{children:m("keybar-ime-lock")}),l.jsx("small",{children:m("keybar-ime-lock-help")})]})]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:t.voiceKeepsKeyboardClosed,onChange:n=>e({voiceKeepsKeyboardClosed:n.target.checked})}),l.jsxs("span",{children:[l.jsx("b",{children:m("voice-ime-lock")}),l.jsx("small",{children:m("voice-ime-lock-help")})]})]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:t.showKeybarEnter,onChange:n=>e({showKeybarEnter:n.target.checked})}),l.jsxs("span",{children:[l.jsx("b",{children:m("keybar-enter-show")}),l.jsx("small",{children:m("keybar-enter-show-help")})]})]}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:()=>e(Mr),children:m("input-settings-reset")})})]})}function NT({token:t,roster:e=[],readonly:n}){const i=[{key:"local",route:[],label:m("diagnostics-local"),status:"up"},...e.filter(D=>Array.isArray(D.route)&&D.route.length).map(D=>({key:D.route.join("/"),route:D.route,label:D.label||D.name,status:D.status}))],[s,a]=k.useState("local"),c=i.find(D=>D.key===s)||i[0],[d,h]=k.useState(null),[f,g]=k.useState([]),[y,_]=k.useState(""),[w,S]=k.useState(!1),[N,C]=k.useState(!0),[E,x]=k.useState(900),[M,T]=k.useState("all"),[U,z]=k.useState(""),K=k.useRef(0),Q=k.useRef(null),q=k.useCallback(async()=>{try{const D=await s2(t,c.route);if(h(D),_(""),!w){const O=await r2(t,{after:K.current,limit:200},c.route);Array.isArray(O.records)&&O.records.length&&(K.current=O.cursor,g(R=>[...R,...O.records].slice(-500)))}}catch(D){_(D&&D.status===404?m("diagnostics-unsupported"):String(D.message||D))}},[t,c.key,w]);k.useEffect(()=>{K.current=0,g([]),h(null),_("")},[c.key]),k.useEffect(()=>{let D=null,O=!0;const R=()=>{!O||document.visibilityState==="hidden"||q()},A=()=>{D&&clearInterval(D),D=document.visibilityState==="hidden"?null:setInterval(R,2e3),document.visibilityState!=="hidden"&&R()};return document.addEventListener("visibilitychange",A),A(),()=>{O=!1,D&&clearInterval(D),document.removeEventListener("visibilitychange",A)}},[q]),k.useEffect(()=>{N&&Q.current&&(Q.current.scrollTop=Q.current.scrollHeight)},[f,N]);const G=f.filter(D=>(M==="all"||D.level===M)&&(!U||String(D.component||"").toLowerCase().includes(U.toLowerCase()))),H=G.map(D=>`${D.ts} ${D.level.toUpperCase()} ${D.component} ${D.code} ${D.message}${Object.keys(D.meta||{}).length?` ${JSON.stringify(D.meta)}`:""}`).join(`
|
|
166
166
|
`),P=async D=>{_("");try{const O=await D();h(O),await q()}catch(O){_(String(O.message||O))}},L=async()=>{try{await navigator.clipboard.writeText(H)}catch{_(m("copy-manual"))}},I=()=>{try{const D=new Blob([`${JSON.stringify(G,null,2)}
|
|
167
|
-
`],{type:"application/json"}),O=URL.createObjectURL(D),R=document.createElement("a");R.href=O,R.download="nexuscrew-diagnostics.json",R.click(),URL.revokeObjectURL(O)}catch{_(m("diagnostics-export-failed"))}};return l.jsxs("div",{className:"nc-set-tab nc-diagnostics",children:[l.jsxs("label",{className:"nc-field",children:[m("diagnostics-target"),l.jsx("select",{value:c.key,onChange:D=>a(D.target.value),children:i.map(D=>l.jsxs("option",{value:D.key,children:[D.label,D.status!=="up"?` · ${D.status}`:""]},D.key))})]}),l.jsxs("div",{className:"nc-set-form nc-diag-controls",children:[l.jsx("div",{className:"nc-sheet-label",children:m("diagnostics-verbose")}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("select",{"aria-label":m("diagnostics-duration"),value:E,onChange:D=>x(Number(D.target.value)),disabled:n,children:[300,900,1800,3600].map(D=>l.jsxs("option",{value:D,children:[D/60," min"]},D))}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||(d==null?void 0:d.verbose)===!0,onClick:()=>P(()=>X_(t,!0,E,c.route)),children:m("enable")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||(d==null?void 0:d.verbose)!==!0,onClick:()=>P(()=>X_(t,!1,E,c.route)),children:m("stop")})]}),l.jsx("small",{className:"nc-set-hint",children:d!=null&&d.verbose?m("diagnostics-expires").replace("{time}",new Date(d.expiresAt).toLocaleTimeString()):m("diagnostics-off")})]}),l.jsxs("div",{className:"nc-diag-filters",children:[l.jsxs("select",{"aria-label":m("diagnostics-level"),value:M,onChange:D=>T(D.target.value),children:[l.jsx("option",{value:"all",children:m("diagnostics-all-levels")}),["debug","info","warn","error"].map(D=>l.jsx("option",{value:D,children:D},D))]}),l.jsx("input",{"aria-label":m("diagnostics-component"),placeholder:m("diagnostics-component"),value:U,onChange:D=>z(D.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:D=>S(D.target.checked)})," ",m("diagnostics-pause")]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:N,onChange:D=>C(D.target.checked)})," ",m("diagnostics-autoscroll")]})]}),l.jsx("pre",{ref:Q,className:"nc-diag-log","aria-label":m("diagnostics-log"),children:H||m("diagnostics-empty")}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:L,children:m("copy")}),l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:I,children:m("diagnostics-export")}),l.jsx("button",{type:"button",className:"nc-btn danger",disabled:n,onClick:()=>{window.confirm(m("diagnostics-clear-confirm"))&&P(async()=>{const D=await o2(t,c.route);return K.current=0,g([]),D})},children:m("diagnostics-clear")})]}),y&&l.jsx("div",{className:"nc-err",children:y})]})}function LT({token:t,settings:e,readonly:n,refresh:i,roster:s,section:a,setSection:c}){const[d,h]=k.useState(null),[f,g]=k.useState(null),[y,_]=k.useState(!1),[w,S]=k.useState(!1),[N,C]=k.useState(null),[E,x]=k.useState(!0),[M,T]=k.useState(!1);k.useEffect(()=>{C(e&&e.update||null),x(!e||e.autoUpdate!==!1),T(!!(e&&e.alternateScreen))},[e]);const U=async()=>{h(null),g(null),S(!0);try{const L=await zk(t);g(L.note||"ok"),_(!1)}catch(L){h(String(L.message||L))}S(!1)},z=async()=>{h(null),g(null),S(!0);try{const L=await t2(t);g(`${L.note||"ok"}${L.target?` (${L.target})`:""}`)}catch(L){h(String(L.message||L))}S(!1)},K=async L=>{h(null),g(null),S(!0);try{await sp(t,{autoUpdate:L}),x(L),i&&await i()}catch(I){h(String(I.message||I))}S(!1)},Q=async L=>{h(null),g(null),S(!0);try{await sp(t,{alternateScreen:L}),T(L),i&&await i()}catch(I){h(String(I.message||I))}S(!1)},q=async()=>{h(null),g(null),S(!0);try{C(await n2(t))}catch(L){h(String(L.message||L))}S(!1)},G=async()=>{h(null),g(null),S(!0);try{const L=await i2(t);C(L),g(m("npm-update-restarting"))}catch(L){h(String(L.message||L))}S(!1)},H=()=>{window.confirm(m("composer-clear-confirm"))&&(h(null),yM()?(window.dispatchEvent(new Event(am)),g(m("composer-clear-done"))):h(m("composer-clear-failed")))},P=e&&e.service;return l.jsxs("div",{className:"nc-set-tab",children:[l.jsx("div",{className:"nc-system-tabs",role:"tablist","aria-label":m("tab-system"),children:["general","diagnostics"].map(L=>l.jsx("button",{type:"button",role:"tab","aria-selected":a===L,className:`nc-set-tabbtn${a===L?" on":""}`,onClick:()=>c(L),children:m(`system-${L}`)},L))}),a==="general"&&l.jsxs(l.Fragment,{children:[l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:m("system-this-node")}),e&&l.jsxs("div",{className:"nc-set-info",children:["v",e.version," · ",e.platform," · :",e.port,l.jsx("br",{}),P&&P.installed?m("service-installed"):m("service-missing"),P&&P.installed?` · ${P.active?m("service-active"):m("service-inactive")}`:"",P?` · boot ${P.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?m("settings-readonly"):"",onClick:z,children:m("service-regenerate")})}),l.jsx(xT,{token:t,readonly:n}),l.jsx(CT,{})]}),l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:m("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:L=>K(L.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:m("npm-auto-update")}),l.jsx("small",{children:m("npm-auto-update-help")})]})]}),N&&l.jsxs("div",{className:"nc-set-info",children:[m("npm-update-current")," v",N.current,N.latest?` · ${m("npm-update-latest")} v${N.latest}`:""," · ",m(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:q,children:m("npm-update-check")}),N&&N.available&&l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||w||N.phase==="installing",onClick:G,children:m("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:m("system-security")}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||w,title:n?m("settings-readonly"):"",onClick:()=>{h(null),g(null),_(!0)},children:m("token-rotate")})})]}),l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:m("system-local-data")}),l.jsxs("div",{className:"nc-set-form",children:[l.jsx("div",{className:"nc-sheet-label",children:m("composer-clear-data")}),l.jsx("small",{className:"nc-set-hint",children:m("composer-clear-data-help")}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:H,children:m("composer-clear-data")})})]})]})]}),a==="diagnostics"&&l.jsxs("section",{className:"nc-system-group nc-system-diagnostics",children:[l.jsx("h3",{children:m("system-diagnostics")}),l.jsxs("div",{className:"nc-set-form nc-alternate-screen-settings",children:[l.jsx("div",{className:"nc-sheet-label",children:m("system-terminal")}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox","aria-label":m("alternate-screen"),checked:M,disabled:n||w,onChange:L=>Q(L.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:m("alternate-screen")}),l.jsx("small",{children:m("alternate-screen-help")})]})]})]}),l.jsx(NT,{token:t,roster:s,readonly:n})]}),y&&l.jsxs("div",{className:"nc-set-confirm",children:[l.jsx("div",{children:m("token-rotate-explain")}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:w,onClick:()=>_(!1),children:m("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:w,onClick:U,children:m("confirm")})]})]}),f&&l.jsx("div",{className:"nc-set-note",children:f}),d&&l.jsx("div",{className:"nc-err",children:d})]})}function RT({token:t,onClose:e,initialTab:n="nodes",initialLocation:i="",startNewCell:s=!1}){ui();const a=n==="diagnostics"?"diagnostics":"general",[c,d]=k.useState(n==="diagnostics"?"system":n),h=k.useRef(null),f=k.useRef(null),[g,y]=k.useState({start:!1,end:!1}),[_,w]=k.useState(a),[S,N]=k.useState(null),[C,E]=k.useState([]),[x,M]=k.useState(null),[T,U]=k.useState([]),[z,K]=k.useState(!1),[Q,q]=k.useState(null),[G,H]=k.useState(0),P=Rm(t,!0,G),L=k.useCallback(()=>{const D=h.current;if(!D)return;const O=D.scrollWidth>D.clientWidth+1,R={start:O&&D.scrollLeft>1,end:O&&D.scrollLeft+D.clientWidth<D.scrollWidth-1};y(A=>A.start===R.start&&A.end===R.end?A:R)},[]);k.useEffect(()=>{const D=h.current;if(!D)return;const O=typeof ResizeObserver=="function"?new ResizeObserver(L):null;return O==null||O.observe(D),window.addEventListener("resize",L),L(),()=>{O==null||O.disconnect(),window.removeEventListener("resize",L)}},[L]),k.useEffect(()=>{var O,R;(R=(O=f.current)==null?void 0:O.scrollIntoView)==null||R.call(O,{behavior:"smooth",block:"nearest",inline:"nearest"});const D=window.requestAnimationFrame?window.requestAnimationFrame(L):setTimeout(L,0);return()=>{window.cancelAnimationFrame?window.cancelAnimationFrame(D):clearTimeout(D)}},[c,L]);const I=k.useCallback(async()=>{var D;try{const O=await w0(t);N(O),q(null)}catch(O){q(String(O.message||O))}try{const O=await Ok(t),R=O.peers||[];M(Number.isInteger(O.accessRevision)?O.accessRevision:null);let A=[],j=[];try{const[F,$]=await Promise.all([cn("/api/config",t).then(ie=>ie.json()).catch(()=>null),S0(t).catch(()=>null)]),W=F&&typeof F.instanceId=="string"?F.instanceId:"",le=[{instanceId:W||null,route:[],label:null},...O0($,W)],ve=await Promise.all(le.map(async ie=>{try{return{ok:!0,peers:((await b0(t,ie.route)).nodes||[]).map(J=>B0(J,ie)).filter(Boolean)}}catch(ue){return{ok:!1,owner:ie,error:ue}}}));for(const ie of ve){if(ie.ok){A.push(...ie.peers);continue}ie.owner.route.length!==0&&j.push({instanceId:ie.owner.instanceId,label:ie.owner.label,route:ie.owner.route,failure:/timeout/i.test(String(((D=ie.error)==null?void 0:D.message)||ie.error))?"timeout":"unreachable"})}}catch{}U(j),E([...R,...A])}catch(O){q(String(O.message||O))}},[t]);return k.useEffect(()=>{I();const D=setInterval(I,5e3);return()=>clearInterval(D)},[I]),k.useEffect(()=>{let D=!1;return cn("/api/config",t).then(O=>O.json()).then(O=>{D||K(!!O.readonlyDefault)}).catch(()=>{}),()=>{D=!0}},[t]),l.jsx("div",{className:"nc-set-overlay",onClick:e,children:l.jsxs("div",{className:"nc-set-panel",onClick:D=>D.stopPropagation(),children:[l.jsxs("div",{className:"nc-set-head",children:[l.jsx(ht,{name:"gear",size:18}),l.jsx("b",{children:m("settings")}),l.jsx("button",{type:"button",className:"nc-set-close",onClick:e,title:m("close"),children:l.jsx(ht,{name:"x",size:18})})]}),z&&l.jsx("div",{className:"nc-set-readonly",children:m("settings-readonly")}),Q&&l.jsx("div",{className:"nc-err",children:Q}),l.jsx("div",{className:`nc-set-tabs-wrap${g.start?" has-start-overflow":""}${g.end?" has-end-overflow":""}`,children:l.jsx("div",{className:"nc-set-tabs",ref:h,onScroll:L,children:["nodes","fleet","audio","input","system"].map(D=>l.jsx("button",{ref:c===D?f:null,type:"button",className:`nc-set-tabbtn${c===D?" on":""}`,onClick:()=>d(D),children:m(`tab-${D}`)},D))})}),l.jsxs("div",{className:"nc-set-body",children:[c==="nodes"&&l.jsx(ST,{token:t,nodes:C,roster:P,settings:S,readonly:z,vlUnavailable:T,accessRevision:x,refresh:I,refreshAliases:()=>H(D=>D+1)}),c==="fleet"&&l.jsx(iT,{token:t,readonly:z,startNewCell:s,initialLocation:i,targets:P.map(D=>({route:D.route,label:D.label||D.name,status:D.status}))}),c==="audio"&&l.jsx(kT,{token:t,readonly:z,nodes:C,settings:S}),c==="input"&&l.jsx(ET,{}),c==="system"&&l.jsx(LT,{token:t,settings:S,readonly:z,refresh:I,roster:P,section:_,setSection:w})]})]})})}function AT({token:t,initialPair:e,deviceDefault:n="",localNodeId:i="",localNameDefault:s="",onPairDone:a,onDone:c}){ui();const[d,h]=k.useState(e?"pair":"welcome"),[f,g]=k.useState(!1),[y,_]=k.useState(null),[w,S]=k.useState(null),N=async()=>{g(!0),_(null);try{await sp(t,{wizardDone:!0}),a&&a(),c()}catch(C){_(String(C.message||C)),g(!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:m("wizard-title")}),l.jsx("small",{children:m("hydra-simple")})]}),d==="welcome"&&l.jsxs("div",{className:"nc-wiz-body",children:[l.jsx("div",{className:"nc-wiz-done",children:m("local-ready")}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{className:"nc-btn ghost",disabled:f,onClick:N,children:m("local-only")}),l.jsx("button",{className:"nc-btn primary",disabled:f,onClick:()=>h("pair"),children:m("add-node")})]})]}),d==="pair"&&l.jsxs("div",{className:"nc-wiz-body",children:[l.jsx(lx,{token:t,initial:e||"",autoStart:!!e,deviceDefault:n,localNodeId:i,localNameDefault:s,onBusyChange:g,onSuccess:async C=>{S(C&&C.authorizedKeys?{line:C.authorizedKeys,note:C.authorizedKeysNote||""}:null),a&&a(),h("done")}}),l.jsx("div",{className:"nc-sheet-actions",children:l.jsx("button",{className:"nc-btn ghost",disabled:f,onClick:()=>{a&&a(),h("welcome")},children:m("back")})})]}),d==="done"&&l.jsxs("div",{className:"nc-wiz-body",children:[l.jsx("div",{className:"nc-wiz-done",children:m("node-connected")}),w&&l.jsx(ug,{line:w.line,note:w.note}),l.jsx("div",{className:"nc-sheet-actions",children:l.jsx("button",{className:"nc-btn primary",disabled:f,onClick:N,children:m("finish")})})]}),y&&l.jsx("div",{className:"nc-err",children:y})]})})}function MT(t,e){if(typeof EventSource>"u"||!t)return()=>{};const n=new EventSource(`/api/events?token=${encodeURIComponent(t)}`);return n.onmessage=i=>{try{const s=JSON.parse(i.data);s&&typeof s=="object"&&typeof s.type=="string"&&e(s)}catch{}},()=>{try{n.close()}catch{}}}const jT=6e3,PT=12e3,Gs=(t,e,n)=>`${e||""}:${n||t}`;function Rx(t,e){const n=new Set(t.map(s=>Gs(s.id,s.ownerId,s.ownerAskId))),i=(e||[]).filter(s=>s&&s.id&&!n.has(Gs(s.id,s.ownerId,s.ownerAskId)));return i.length?[...t,...i]:t}function TT(t,e){const n=Rx([],t.filter(a=>a.imported)),i=new Set(n.map(a=>Gs(a.id,a.ownerId,a.ownerAskId)));return[...(e||[]).filter(a=>a&&a.id&&!i.has(Gs(a.id,a.ownerId,a.ownerAskId))),...n]}function IT({n:t,onClose:e}){return l.jsxs("div",{className:`nc-ntf-toast${t.urgency==="high"?" high":""}`,role:"status","aria-live":"polite",children:[l.jsxs("div",{className:"nc-ntf-toast-txt",children:[l.jsx("b",{children:t.title}),t.body&&l.jsx("small",{children:t.body}),t.session&&l.jsx("span",{className:"nc-ntf-from",children:t.session}),t.ownerId&&l.jsx("span",{className:"nc-ntf-from",children:m("feed-owner")})]}),l.jsx("button",{type:"button",className:"nc-ntf-x",onClick:e,title:m("close"),children:l.jsx(ht,{name:"x",size:14})})]})}function DT({ask:t,token:e,onAnswered:n,onDismiss:i,askReplyAccess:s=!1}){const[a,c]=k.useState(""),[d,h]=k.useState(!1),[f,g]=k.useState(null),[y,_]=k.useState(!1),[w,S]=k.useState(null),[N,C]=k.useState(!1),E=async M=>{const T=String(M||"").trim();if(!(!T||d)){g(null),h(!0);try{if(t.ownerId){const U=t.ownerAskId||t.id,z=await u2(e,{ownerId:t.ownerId,askId:U,text:T});if(z&&z.uncertain){S(z.requestId);return}n(t.id,t.ownerId)}else await l2(e,t.id,T),n(t.id)}catch(U){g(String(U.message||U))}h(!1)}},x=async()=>{if(!y){_(!0);try{if(t.ownerId){if(w)return;await h2(e,{ownerId:t.ownerId,askId:t.ownerAskId||t.id}),i(t.id,t.ownerId)}else await c2(e,t.id),i(t.id)}catch{_(!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:t.session}),t.ownerId&&l.jsx("span",{className:"nc-ntf-from",children:m("feed-owner")}),l.jsxs("code",{className:"nc-ask-id",children:["#",t.id]}),l.jsx("button",{type:"button",className:"nc-ask-dismiss",title:m("ask-dismiss"),"aria-label":m("ask-dismiss"),disabled:y||!!t.ownerId&&s===!1,onClick:x,children:l.jsx(ht,{name:"x",size:14})})]}),l.jsx("div",{className:"nc-ask-q",children:t.question}),t.ownerId&&s===!1&&l.jsx("small",{className:"nc-set-hint",children:m("ask-remote-readonly")}),w&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-err",children:m("ask-uncertain")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:N,onClick:async()=>{C(!0);try{const M=await d2(e,{ownerId:t.ownerId,askId:t.id,requestId:w});M&&(M.state==="committed"||M.state==="failed")&&i(t.id,t.ownerId)}finally{C(!1)}},children:m("ask-verify")})]}),(!t.ownerId||s===!0)&&l.jsxs(l.Fragment,{children:[Array.isArray(t.options)&&t.options.length>0&&l.jsx("div",{className:"nc-ask-opts",children:t.options.map(M=>l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:d,onClick:()=>E(M),children:M},M))}),l.jsxs("div",{className:"nc-ask-reply",children:[l.jsx("textarea",{rows:2,placeholder:m("ask-reply-ph"),value:a,disabled:d,onChange:M=>c(M.target.value)}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:d||!a.trim(),onClick:()=>E(a),children:m("send")})]})]}),f&&l.jsx("div",{className:"nc-err",children:f})]})}function BT({token:t}){const[e]=ui(),[n]=Lx(),[i,s]=k.useState([]),[a,c]=k.useState([]),[d,h]=k.useState(()=>{try{return/(?:^|[#&])ask=/.test(location.hash)}catch{return!1}}),f=k.useRef(0),g=k.useRef(null);g.current||(g.current=yT());const y=k.useRef({enabled:n,lang:e});y.current={enabled:n,lang:e};const _=k.useCallback(E=>{s(x=>x.filter(M=>M.key!==E))},[]),w=k.useCallback(E=>{const x=`t${f.current+=1}`;s(T=>[...T.slice(-3),{...E,key:x}]),setTimeout(()=>_(x),E.urgency==="high"?PT:jT);const M=y.current;if(M.enabled)try{g.current.enqueue(E,pT(E,M.lang))}catch{}},[_]);k.useEffect(()=>{n||g.current.stop()},[n]),k.useEffect(()=>{const E=()=>{(document.visibilityState!=="visible"||!document.hasFocus())&&g.current.stop()},x=()=>g.current.stop();return document.addEventListener("visibilitychange",E),window.addEventListener("blur",E),window.addEventListener(mm,x),()=>{document.removeEventListener("visibilitychange",E),window.removeEventListener("blur",E),window.removeEventListener(mm,x),typeof g.current.dispose=="function"?g.current.dispose():g.current.stop()}},[]);const S=(E,x)=>c(M=>M.filter(T=>Gs(T.id,T.ownerId)!==Gs(E,x)));k.useEffect(()=>{if(!t)return;let E=!1;a2(t).then(M=>{E||c(T=>TT(T,M.asks))}).catch(()=>{});const x=MT(t,M=>{if(M.type==="notify")w(M);else if(M.type==="ask"&&M.ask&&M.ask.id){const T=Gs(M.ask.id,M.ask.ownerId);c(U=>U.some(z=>Gs(z.id,z.ownerId)===T)?U:[...U,M.ask])}else(M.type==="ask-answered"&&M.id||M.type==="ask-dismissed"&&M.id)&&S(M.id,M.ownerId)});return()=>{E=!0,x()}},[t,w]);const[N,C]=k.useState({});return k.useEffect(()=>{let E=!0;return f2(t).then(x=>{if(!E)return;const M={},T=[];for(const U of x&&x.views||[]){M[U.ownerId]=U.askReplyAccess===!0;for(const z of U.asks||[])z&&z.id&&T.push({...z,ownerId:U.ownerId,imported:!0})}C(M),T.length&&c(U=>Rx(U,T))}).catch(()=>{}),()=>{E=!1}},[t]),l.jsxs(l.Fragment,{children:[i.length>0&&l.jsx("div",{className:"nc-ntf-toasts",children:i.map(E=>l.jsx(IT,{n:E,onClose:()=>_(E.key)},E.key))}),a.length>0&&!d&&l.jsxs("button",{type:"button",className:"nc-ask-badge",onClick:()=>h(!0),title:m("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:m("asks-title")}),l.jsx("span",{className:"nc-ask-count",children:a.length}),l.jsx("button",{type:"button",className:"nc-ntf-x",onClick:()=>h(!1),title:m("close"),children:l.jsx(ht,{name:"x",size:16})})]}),l.jsx("div",{className:"nc-ask-panel-body",children:a.map(E=>l.jsx(DT,{ask:E,token:t,askReplyAccess:!E.ownerId||N[E.ownerId]===!0,onAnswered:S,onDismiss:S},Gs(E.id,E.ownerId)))})]})]})}const OT=4e3;async function $T(t){const e=await cn("/api/sessions",t);if((e==null?void 0:e.ok)===!1)throw new Error(`HTTP ${e.status}`);const n=await e.json();if(!Array.isArray(n==null?void 0:n.sessions))throw new Error("invalid sessions payload");return n.sessions}async function tp(t,e=[]){var d;const[n,i]=await Promise.allSettled([e.length?Cm(t,e):$T(t),Dr(t,e)]),s=n.status==="fulfilled"&&Array.isArray((d=n.value)==null?void 0:d.sessions)?n.value.sessions:Array.isArray(n.value)?n.value:null,a=i.status==="fulfilled"?i.value:null,c=(a==null?void 0:a.available)===!0&&Array.isArray(a.cells)?a.cells:null;return{sessions:s,cells:c,fresh:Array.isArray(s)&&Array.isArray(c)}}function Ax(t,e,n){return n===!0&&(t==null?void 0:t.degraded)!==!0&&(t==null?void 0:t.active)===!0&&t.tmux!==!1&&!!t.tmuxSession&&(e||[]).some(i=>(i==null?void 0:i.name)===t.tmuxSession)}function zT(t){const e=new Map((t.sessions||[]).map(s=>[s.name,s])),n=[],i=(s,a,c,d=[],h="")=>{const f=new Map((a||[]).map(g=>[g.name,g]));for(const g of s||[]){const y=f.get(g.tmuxSession)||{},_=jm(g,y),w=Ax(g,a,c);n.push({key:Ll(d,g.tmuxSession||g.cell),session:g.tmuxSession,route:d,cellName:g.cell,label:g.cell,node:d.length?d.join("/"):"",nodeLabel:h,live:w,selectable:w,verified:c===!0,working:_.working,degraded:!!g.degraded,active:g.active===!0,activity:y.activity||g.activity||0,subtitle:_.subtitle,preview:y.preview||g.preview||"",telemetry:y.telemetry||null,panelUrl:g.panelUrl||""})}};i(t.cells,[...e.values()],t.localFresh===!0);for(const s of t.nodeGroups||[]){const a=Array.isArray(s.route)?s.route:[];s.kind==="vl"||!a.length||i(s.cells,s.sessions,s.switcherFresh===!0,a,s.label||s.name||"")}return n}function FT(t){const e=new Map,n=Array.isArray(t.sessions)?t.sessions:[],i=Array.isArray(t.cells)?t.cells:[],s=new Map(n.map(c=>[c.name,c])),a=new Set(i.map(c=>c.tmuxSession).filter(Boolean));e.set("local",Pm(i,n.filter(c=>!a.has(c.name)),s));for(const c of t.nodeGroups||[]){const d=Array.isArray(c.route)?c.route:[];if(c.kind==="vl"||!d.length)continue;const h=Array.isArray(c.cells)?c.cells:[],f=Array.isArray(c.sessions)?c.sessions:[],g=new Set(h.map(y=>y.tmuxSession).filter(Boolean));e.set(d.join("/"),Iu({...c,route:d,cells:h,sessions:f,unmanaged:f.filter(y=>!g.has(y.name))}).rawItems)}return e}function HT(t,e,n,i){return[...new Set(t.map(a=>a.node||"local"))].flatMap(a=>{const c=t.filter(g=>(g.node||"local")===a),d=new Map((e.get(a)||[]).map(g=>[g.key,g])),h=new Map(c.map(g=>[g.key,g])),f=c.map(g=>{const y=d.get(g.key);return{...g,label:(y==null?void 0:y.label)||g.label,live:(y==null?void 0:y.live)??g.live,fresh:(y==null?void 0:y.fresh)===!0,activity:(y==null?void 0:y.activity)??g.activity}});return Pr(f,n,"all",Js(i,a)).map(g=>h.get(g.key))})}function UT({token:t,current:e,onPick:n,onClose:i,panelPort:s=0,nodePanelPorts:a={},hostByRoute:c={},onDesignateCell:d,onClearHostCell:h,onLiveHostApplied:f}){const[g,y]=k.useState(hy),[_,w]=k.useState(!1),[S,N]=k.useState(!1),[C,E]=k.useState(""),[x,M]=k.useState(null),[T,U]=k.useState(""),[z,K]=k.useState(""),Q=k.useRef(null),q=k.useRef(null),G=k.useMemo(()=>zT(g),[g]),H=k.useMemo(()=>FT(g),[g]),{pins:P,orders:L,togglePin:I,removePin:D,pinError:O,canMoveRoster:R,moveRoster:A,stepRoster:j}=Mm(),F=k.useMemo(()=>HT(G,H,P,L),[G,H,P,L]),$=k.useMemo(()=>_?F:F.filter(de=>de.selectable||de.degraded&&de.active),[F,_]),W=k.useMemo(()=>G.find(de=>de.key===T&&de.selectable),[G,T]),le=k.useMemo(()=>x?G.find(de=>de.key===x.key):null,[G,x]);k.useEffect(()=>{O&&O.message&&E(O.message)},[O]),k.useEffect(()=>{var we;const de=document.activeElement;(we=q.current)==null||we.focus();const ye=Ue=>{Ue.key==="Escape"&&i()};return document.addEventListener("keydown",ye),()=>{var Ue;document.removeEventListener("keydown",ye),(Ue=de==null?void 0:de.focus)==null||Ue.call(de)}},[i]),k.useEffect(()=>{let de=!0,ye=!1;const we=async()=>{if(ye)return;ye=!0;const mt=hy(),gt=Array.isArray(mt.nodeGroups)?mt.nodeGroups:[],st=tp(t),vt=_t=>_t.kind!=="vl"&&Array.isArray(_t.route)&&_t.route.length>0,Et=await Promise.all(gt.filter(vt).map(async _t=>({group:_t,result:await tp(t,_t.route)}))),it=await st;if(!de)return;const Dt=new Map(Et.map(({group:_t,result:yt})=>[JSON.stringify(_t.route||[]),yt])),Ut=gt.map(_t=>{if(!vt(_t))return{..._t,switcherFresh:!1};const yt=Dt.get(JSON.stringify(_t.route||[]));return yt?{..._t,sessions:yt.sessions||_t.sessions||[],cells:yt.cells||_t.cells||[],switcherFresh:yt.fresh}:{..._t,switcherFresh:!1}}),Bt=tS({...mt,sessions:it.sessions||mt.sessions||[],cells:it.cells||mt.cells||[],localFresh:it.fresh,nodeGroups:Ut,refreshedAt:Date.now()});y(Bt),N(!0),ye=!1};we();const Ue=setInterval(we,OT);return()=>{de=!1,clearInterval(Ue)}},[t]);const[ve,ie]=k.useState(""),ue={getLiveHost:de=>ed(t,de),designateHostCell:(de,ye,we)=>td(t,de,ye,we),clearHostCell:(de,ye)=>nd(t,de,ye)},ne=de=>(c[Di(de)]||{}).hostCell||null,J=async(de,ye)=>{ie(de.key);const we=await D1({action:ye?"remove":"use",cellId:de.cellName,route:de.route||[],api:ue});ie(""),E(m(we.messageKey).replace("{cell}",we.hostCell||de.cellName)),we.ok&&f&&f({route:de.route||[],hostCell:we.hostCell,revision:we.revision})},ce=de=>de.degraded?m("cell-degraded"):de.verified?de.selectable?de.working?m("cell-working"):m("cell-idle"):m("cell-off"):m("cell-switcher-not-confirmed"),Ce=de=>{if(E(""),!de.selectable){E(de.verified?m("cell-switcher-not-active"):m("cell-switcher-not-confirmed"));return}U(de.key)},Be=async()=>{const de=W;if(!de){E(m("cell-switcher-select"));return}E(""),K(de.key);try{const ye=await tp(t,de.route),we=(ye.cells||[]).find(Ue=>(Ue==null?void 0:Ue.cell)===de.cellName&&(Ue==null?void 0:Ue.tmuxSession)===de.session);if(ye.fresh!==!0){E(m("cell-switcher-verify-failed"));return}if(!Ax(we,ye.sessions,ye.fresh)){E(m("cell-switcher-not-active"));return}n({session:de.session,...de.node?{node:de.node}:{},cellName:de.cellName}),i()}catch{E(m("cell-switcher-verify-failed"))}finally{K("")}};return l.jsx("div",{className:"nc-cell-switcher-backdrop",onClick:i,children:l.jsxs("aside",{ref:Q,className:"nc-cell-switcher",role:"dialog","aria-label":m("fleet-cells"),tabIndex:-1,onClick:de=>de.stopPropagation(),children:[l.jsxs("div",{className:"nc-cell-switcher-list",children:[l.jsx(P1,{className:"nc-cell-switcher-live-host",view:Ku({liveHost:c[Di([])],cells:g.cells||[]})}),!S&&l.jsx("div",{className:"nc-empty",role:"status",children:m("cell-switcher-refreshing")}),S&&$.length===0&&l.jsx("div",{className:"nc-empty",role:"status",children:m("cell-switcher-empty-active")}),$.map(de=>{const ye=(e==null?void 0:e.session)===de.session&&((e==null?void 0:e.node)||"")===de.node,we=T===de.key,Ue=ce(de),mt=cm(m,de.activity),gt=um(m,de.telemetry),st=[mt,gt].filter(Boolean).join(" · "),vt=de.node||"local",Et=H.get(vt)||G.filter(it=>(it.node||"local")===vt);return l.jsxs("div",{className:`nc-cell-switcher-row${ye?" current":""}${we?" selected":""}${de.selectable?"":" off"}`,"data-roster-key":de.key,"data-position":vt,children:[l.jsx(xs,{position:vt,itemKey:de.key,label:de.cellName,canMove:R,onMove:(it,Dt)=>A(vt,it,Dt,Et),onStep:it=>j(vt,de.key,it,Et)}),l.jsx("button",{type:"button",className:"nc-cell-switcher-peek",title:m("cell-peek"),"aria-label":`${m("cell-peek")}: ${de.cellName}`,onClick:it=>{it.stopPropagation(),M({key:de.key,source:"preview"})},children:l.jsx("span",{className:`nc-cell-switcher-dot${de.degraded?" warn":de.live?` on${de.working?" working":""}`:""}`})}),l.jsxs("span",{className:"nc-cell-switcher-acts",children:[l.jsx("button",{type:"button",className:"nc-cell-switcher-act",title:m("cell-peek-stream"),"aria-label":`${m("cell-peek-stream")}: ${de.cellName}`,onClick:it=>{it.stopPropagation(),M({key:de.key,source:"stream"})},children:"▶"}),de.panelUrl&&l.jsx("button",{type:"button",className:"nc-cell-switcher-act",title:m("cell-peek-panel"),"aria-label":`${m("cell-peek-panel")}: ${de.cellName}`,onClick:it=>{it.stopPropagation(),M({key:de.key,source:"panel"})},children:"▣"})]}),l.jsx("button",{type:"button",className:"nc-cell-switcher-row-select","aria-current":ye?"true":void 0,"aria-pressed":we,"aria-disabled":!de.selectable,disabled:z===de.key,onClick:()=>Ce(de),children:l.jsxs("span",{className:"nc-cell-switcher-copy",children:[l.jsx("b",{children:de.cellName}),l.jsx("small",{className:"nc-cell-switcher-state",children:Ue}),l.jsx("small",{children:[de.nodeLabel,de.subtitle].filter(Boolean).join(" · ")}),st&&l.jsx("small",{className:"nc-cell-switcher-telemetry",children:st})]})}),l.jsx(Mu,{item:{key:de.key,value:{cell:de.cellName}},pins:P,hostByRoute:c,route:de.route||[],cellName:de.cellName,baseClassName:"nc-cell-switcher-star",togglePin:I,removePin:D,onOutcome:it=>{it.ok||E(m(Au(it.error)))}}),l.jsx("button",{type:"button",className:`nc-cell-switcher-act nc-cell-switcher-host${ne(de.route||[])===de.cellName?" on":""}`,"data-testid":`live-host-command-${de.key}`,"data-live-host-state":ne(de.route||[])===de.cellName?"host":"idle",disabled:ve===de.key,title:ne(de.route||[])===de.cellName?m("live-host-action-remove"):m("live-host-action-use"),"aria-label":`${ne(de.route||[])===de.cellName?m("live-host-action-remove"):m("live-host-action-use")}: ${de.cellName}`,onClick:it=>{it.stopPropagation(),J(de,ne(de.route||[])===de.cellName)},children:l.jsx(ht,{name:"broadcast",size:18})})]},de.key)})]}),C&&l.jsx("div",{className:"nc-cell-switcher-notice",role:"status",children:C}),x&&le&&l.jsx(B1,{row:le,token:t,initialSource:x.source,panelPort:Vu(le.route||[],a,s),liveHost:Ku({liveHost:c[Di(le.route||[])],cells:g.cells||[]}),onLiveHostApplied:f,onClose:()=>M(null)}),l.jsx("div",{className:"nc-cell-switcher-actions",children:l.jsx("button",{type:"button",className:"nc-cell-switcher-open",disabled:!W||!!z,onClick:Be,children:W?`${m("cell-switcher-open")}: ${W.cellName}`:m("cell-switcher-select")})}),l.jsxs("div",{className:"nc-cell-switcher-controls",children:[l.jsx("b",{children:m("fleet-cells")}),l.jsx("button",{type:"button",className:"nc-cell-switcher-filter","aria-pressed":_,onClick:()=>{E(""),w(de=>!de)},children:m(_?"cell-switcher-show-active":"cell-switcher-show-all")}),l.jsx("button",{ref:q,type:"button",className:"nc-cell-switcher-close","aria-label":m("cell-switcher-close"),title:m("cell-switcher-close"),onClick:i,children:"×"})]})]})})}const WT=2e3;function qT(t){if(t.kind==="gap")return`${m("vl-events-gap")} ${t.count||"?"}`;if(t.kind==="truncate")return m("vl-events-truncated");if(t.kind==="turn_end")return m("vl-events-turn-end");if(t.kind==="done")return m("vl-events-done");if(t.kind==="writer_epoch")return m("vl-events-writer-epoch");if(t.kind==="tool_start")return`${m("vl-events-tool")} ${t.name||""}`.trim();if(t.kind==="tool_end"){const e=t.isError?m("vl-events-tool-failed"):m("vl-events-tool-ok");return`${m("vl-events-tool")} ${t.name||""} — ${e}`.trim()}return t.kind==="usage"?t.text||m("vl-events-usage"):t.text||""}function KT({token:t,nodeId:e,route:n=[]}){const[i,s]=k.useState([]),[a,c]=k.useState(!1),d=k.useRef(0),h=k.useRef(!1);return k.useEffect(()=>{let f=!0;d.current=0,h.current=!1,s([]);const g=async()=>{if(!h.current){h.current=!0;try{const w=await $k(t,e,d.current,n);if(!f)return;c(!1);const N=(Array.isArray(w==null?void 0:w.events)?w.events:[]).filter(C=>Number.isSafeInteger(C==null?void 0:C.seq)&&C.seq>d.current);N.length&&(s(C=>C.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{f&&c(!0)}finally{h.current=!1}}},y=()=>{g().catch(()=>{})};y();const _=setInterval(y,WT);return()=>{f=!1,clearInterval(_)}},[t,e,JSON.stringify(n)]),l.jsxs("div",{className:"nc-vl-events",children:[a&&l.jsx("div",{className:"nc-set-hint nc-vl-events-stale",children:m("vl-events-stale")}),i.length===0&&!a&&l.jsx("small",{className:"nc-set-hint","data-testid":"vl-events-empty",children:m("vl-events-empty")}),i.length>0&&l.jsx("ol",{className:"nc-vl-events-list",children:i.map(f=>l.jsx("li",{"data-testid":`vl-ev-${f.seq}`,className:`nc-vl-ev nc-vl-ev-${f.kind}${f.isError?" error":""}${f.kind==="gap"?" gap":""}`,children:qT(f)},`${f.seq}-${f.kind}`))})]})}function t0({peer:t,token:e,onBack:n}){var i;return ui(),t?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:m("back"),children:[l.jsx(ht,{name:"chevronLeft",size:18}),l.jsx("span",{className:"nc-bar-label",children:m("back")})]}),l.jsxs("span",{className:"nc-bar-center",children:[l.jsx("b",{title:t.label,children:t.label}),((i=t.session)==null?void 0:i.profile)&&l.jsxs("small",{className:"nc-bar-sub",children:[t.session.profile," · ",m("vl-events-title")]})]}),l.jsx("span",{className:"nc-bar-right"})]}),l.jsx("div",{className:"nc-vl-session-body",children:l.jsx(KT,{token:e,nodeId:t.nodeId,route:t.route||[]})})]}):null}const np=t=>Bi(ls(t)).length===0,ip=t=>Array.isArray(t)?t.join("/"):"";function VT(t){const e=new Set,n=[];for(const i of Array.isArray(t)?t:[])!i||!Ei.test(String(i.instanceId||""))||!Array.isArray(i.route)||!i.route.length||e.has(i.instanceId)||(e.add(i.instanceId),n.push({instanceId:i.instanceId,route:[...i.route],label:String(i.label||i.name||i.route.join(" › ")),status:i.status||"offline",stale:i.stale===!0}));return n.sort((i,s)=>i.label.localeCompare(s.label))}function pl(t){return{instanceId:t.ownerId,route:t.ownerRoute||[],label:t.ownerLabel,status:t.available===!1?"offline":"up"}}function io(t,e,n,i=!1,s=!0){const a=e.instanceId;return{...t,id:po(i?null:a,t.name),ownerId:a,ownerRoute:i?[]:[...e.route],ownerLabel:i?"Local":e.label,local:i,available:s,ownerTopology:Array.isArray(n)?n:[],layout:dm(t.layout,a,n)}}function YT(t,e,n,i,s=[]){const[a,c]=k.useState([]),[d,h]=k.useState(!1),[f,g]=k.useState("idle"),[y,_]=k.useState(""),[w,S]=k.useState(!1),[N,C]=k.useState(""),E=k.useRef([]),x=k.useRef([]),M=k.useRef(""),T=k.useRef(e),U=k.useRef(n),z=k.useRef(!1),K=k.useRef(!0),Q=k.useRef(""),q=k.useMemo(()=>VT(s),[s]),G=q.map(ue=>`${ue.instanceId}:${ip(ue.route)}:${ue.status}:${ue.label}`).join("|");x.current=q,U.current=n,T.current=e,E.current=a;const H=k.useCallback(ue=>hm(ue.layout,M.current,x.current),[]),P=k.useCallback(()=>hl(T.current,M.current),[]),L=k.useCallback(ue=>(Array.isArray(ue)?ue:[]).find(ne=>ne.id===P()),[P]),I=k.useCallback((ue,ne=!0,J)=>{const ce=J===void 0?P():hl(J,M.current),Ce=sb(ue,cu()),Be=E.current.some(ye=>ye.id===ce);E.current=Ce,c(Ce);const de=Ce.find(ye=>ye.id===ce);if(ne&&de){K.current=!0;const ye=H(de);i(ye),de.local&&ij(de.name,ls(ye))}else Be&&!de&&(K.current=!0,i(sa()),_("deck non più condiviso dal nodo owner"));ZM(Ce.filter(ye=>ye.local).map(ye=>ye.name))},[i,H]),D=k.useCallback(async ue=>{let ne=await Xc(t);const J=ne.decks.find(ce=>ce.name==="main");if(ne.decks.length===1&&J&&J.revision===0&&np(J.layout)){const ce=JM(),Ce=ls(fm("main")||sa());if(!np(Ce)){const Be=dm(Ce,ue,[]);ne.decks[0]=await Qc(t,"main",Be,0,[])}for(const Be of ce.filter(de=>de!=="main"))try{let de=await Q_(t,Be,[]);const ye=ls(fm(Be)||sa());np(ye)||(de=await Qc(t,Be,dm(ye,ue,[]),de.revision,[]))}catch{}ne=await Xc(t)}return ne},[t]),O=k.useCallback(async({migrate:ue=!1}={})=>{const ne=await km(t,[]),J=Ei.test(String(ne.instanceId||""))?ne.instanceId:"";if(!J)throw new Error("instanceId locale non disponibile");M.current=J,C(J);const[ce,Ce]=await Promise.all([ue?D(J):Xc(t),Y_(t,[]).catch(()=>({nodes:[]}))]),Be={instanceId:J,route:[],label:"Local"},de=ce.decks.map(we=>io(we,Be,Ce.nodes,!0,!0)),ye=E.current;return await Promise.all(x.current.map(async we=>{if(we.status!=="up"){de.push(...ye.filter(Ue=>!Ue.local&&Ue.ownerId===we.instanceId).map(Ue=>({...Ue,ownerRoute:[...we.route],ownerLabel:we.label,available:!1})));return}try{const[Ue,mt]=await Promise.all([Xc(t,we.route),Y_(t,we.route).catch(()=>({nodes:[]}))]);de.push(...Ue.decks.map(gt=>io(gt,we,mt.nodes,!1,!0)))}catch{de.push(...ye.filter(mt=>!mt.local&&mt.ownerId===we.instanceId).map(mt=>({...mt,ownerRoute:[...we.route],ownerLabel:we.label,available:!1})))}})),de.sort((we,Ue)=>we.local===Ue.local?we.ownerLabel.localeCompare(Ue.ownerLabel)||(we.name==="main"?-1:Ue.name==="main"?1:we.name.localeCompare(Ue.name)):we.local?-1:1),de},[t,D,G]);k.useEffect(()=>{if(!t)return;let ue=!1;const ne=Q.current!==t;return Q.current=t,O({migrate:ne}).then(J=>{if(ue)return;const ce=L(E.current),Ce=L(J),Be=Ce&&(!ce||Ce.revision>ce.revision||ce.available!==Ce.available||ip(ce.ownerRoute)!==ip(Ce.ownerRoute));I(J,ne||!!Be&&!z.current),h(!0),Ce&&_("")}).catch(J=>{ue||(h(!0),_(String(J.message||J)))}),()=>{ue=!0}},[I,O,G,t,L]);const R=k.useCallback(async(ue,ne=!0)=>{if(!d||!z.current)return!0;const J=ue===void 0?P():hl(ue,M.current),ce=E.current.find(Ce=>Ce.id===J);if(!ce)return _(`deck inesistente: ${J}`),!1;if(ce.available===!1)return _(`nodo owner offline: ${ce.ownerLabel}`),!1;g("saving");try{const Ce=Nf(ls(U.current),ce.ownerId,ce.ownerTopology),Be=await Qc(t,ce.name,Ce,ce.revision,ce.ownerRoute),de=io(Be,pl(ce),ce.ownerTopology,ce.local,!0);return I(E.current.map(ye=>ye.id===J?de:ye),!1),z.current=!1,g("saved"),_(""),S(!1),setTimeout(()=>g("idle"),1500),!0}catch(Ce){if(ne&&Ce.status===409&&Ce.data&&Ce.data.current){const Be=E.current.find(de=>de.id===J);if(Be){const de=io(Ce.data.current,pl(Be),Be.ownerTopology,Be.local,!0);return I(E.current.map(ye=>ye.id===J?de:ye),!1),z.current=!0,R(J,!1)}}return g("error"),_(String(Ce.message||Ce)),Ce.status===409&&S(!0),!1}},[d,t,I]),A=k.useCallback(async()=>{try{const ue=await O();z.current=!1,S(!1),I(ue,!0),_("")}catch(ue){_(String(ue.message||ue))}},[O,I]);k.useEffect(()=>{if(!d)return;const ue=K.current&&!z.current;if(K.current=!1,ue)return;z.current=!0,g("saving");const ne=setTimeout(R,650);return()=>clearTimeout(ne)},[n,d,R]),k.useEffect(()=>{if(!d)return;const ue=()=>{if(!z.current)return;const ne=E.current.find(ce=>ce.id===P());if(!ne||ne.available===!1)return;const J=Nf(ls(U.current),ne.ownerId,ne.ownerTopology);p2(t,ne.name,J,ne.revision,ne.ownerRoute)};return window.addEventListener("pagehide",ue),window.addEventListener("beforeunload",ue),()=>{window.removeEventListener("pagehide",ue),window.removeEventListener("beforeunload",ue)}},[d,t,P]),k.useEffect(()=>{if(!d)return;const ue=setInterval(async()=>{try{const ne=await O(),J=L(E.current),ce=L(ne),Ce=!!(ce&&J&&ce.revision>J.revision),Be=!!(ce&&(!J||Ce||J.available!==ce.available));if(Ce&&z.current&&ce){const de=s5(H(ce),U.current);I(ne,!1),i(de);return}I(ne,Be&&!z.current)}catch{}},5e3);return()=>clearInterval(ue)},[d,O,I,H,i]);const j=k.useCallback(ue=>{i(ne=>{const J=ue(ne);return J!==ne&&(K.current=!0),J})},[]);return{decks:a,records:a,localNodeId:N,ready:d,saveState:f,error:y,setError:_,conflict:w,reloadCurrent:A,saveNow:R,select:async ue=>{if(z.current&&!await R(P()))throw new Error("salvataggio del deck corrente fallito: cambio annullato");const ne=E.current.find(J=>J.id===ue);if(!ne)throw new Error(`deck inesistente: ${ue}`);return z.current=!1,K.current=!0,H(ne)},add:async(ue,ne=null)=>{const J=ne===Cs?E.current.find(Be=>Be.local):ne?E.current.find(Be=>Be.ownerId===ne):null;if(!J||J.available===!1)throw new Error("nodo owner non disponibile");const ce=await Q_(t,ue,J.ownerRoute),Ce=io(ce,pl(J),J.ownerTopology,J.local,!0);return I([...E.current,Ce],!1),Ce},rename:async(ue,ne)=>{const J=E.current.find(ye=>ye.id===ue);if(!J)throw new Error("deck inesistente");if(hl(ue,M.current)===P()&&z.current&&!await R(ue))throw new Error(`salvataggio di "${J.name}" fallito: rinomina annullata`);const ce=E.current.find(ye=>ye.id===ue);if(!ce)throw new Error("deck inesistente");const Ce=await m2(t,ce.name,ne,ce.revision,ce.ownerRoute),Be=io(Ce,pl(ce),ce.ownerTopology,ce.local,!0),de=ce.local?Cs:ce.ownerId;return Rf(tj(cu(),de,ue,Be.id)),I(E.current.map(ye=>ye.id===ue?Be:ye),!1),Be},remove:async ue=>{const ne=E.current.find(ce=>ce.id===ue);if(!ne)throw new Error("deck inesistente");hl(ue,M.current)===P()&&(z.current=!1),await g2(t,ne.name,ne.revision,ne.ownerRoute);const J=ne.local?Cs:ne.ownerId;Rf(nj(cu(),J,ue)),I(E.current.filter(ce=>ce.id!==ue),!1)},reorder:(ue,ne)=>{const J=E.current.find(we=>we.id===ue),ce=E.current.find(we=>we.id===ne);if(!J||!ce)return!1;const Ce=J.local?Cs:J.ownerId,Be=ce.local?Cs:ce.ownerId;if(Ce!==Be)return!1;const de=E.current.filter(we=>(we.local?Cs:we.ownerId)===Ce).map(we=>we.id),ye=Rf(ej(cu(),Ce,ue,ne,de));return I(sb(E.current,ye),!1),!0},addTileTo:async(ue,ne)=>{const J=E.current.find(we=>we.id===ue);if(!J)throw new Error("deck inesistente");if(J.available===!1)throw new Error(`nodo owner offline: ${J.ownerLabel}`);const ce=W1(ne,M.current,x.current);if(!ce)throw new Error("riferimento sessione non valido");const Ce=H(J),Be=Nf(J0(Ce,ce),J.ownerId,J.ownerTopology),de=await Qc(t,J.name,Be,J.revision,J.ownerRoute),ye=io(de,pl(J),J.ownerTopology,J.local,!0);return I(E.current.map(we=>we.id===ue?ye:we),!1),ye},viewUpdate:j,localMainId:po(null,"main"),parseDeckId:ql}}const GT="/sw.js",vm="nc-sw-update";let Ol=null,Gu=!1,Xu=null,Mx=Object.freeze({needed:!1,kind:null,version:"",browserVersion:""}),jx=!1;function yg(){typeof window<"u"&&window.dispatchEvent(new Event(vm))}function wg(){const t=Xu||(Gu?{kind:"reload",version:"",browserVersion:""}:null);Mx=Object.freeze({needed:!!t,kind:(t==null?void 0:t.kind)||null,version:(t==null?void 0:t.version)||"",browserVersion:(t==null?void 0:t.browserVersion)||""})}function n0(){return Mx}function XT(t){return typeof window>"u"?()=>{}:(window.addEventListener(vm,t),()=>window.removeEventListener(vm,t))}function bg(t){Gu!==t&&(Gu=t,wg(),yg())}const mu="nc-auto-reload",Qu="nc-reload";function Sg(){try{return typeof location<"u"?location:null}catch{return null}}function Px(){try{return typeof history<"u"?history:null}catch{return null}}function QT(t){const e=t===void 0?Sg():t;if(!e||typeof e.search!="string")return null;try{return new URLSearchParams(e.search).get(Qu)}catch{return null}}function JT(t,{location:e,history:n}={}){const i=e===void 0?Sg():e,s=n===void 0?Px():n;if(!i||!s||typeof s.replaceState!="function")return!1;try{const a=new URLSearchParams(i.search||"");return a.set(Qu,t),s.replaceState(s.state??null,"",`${i.pathname||"/"}?${a.toString()}${i.hash||""}`),!0}catch{return!1}}function ZT({location:t,history:e}={}){const n=t===void 0?Sg():t,i=e===void 0?Px():e;if(!n||!i||typeof i.replaceState!="function")return!1;try{const s=new URLSearchParams(n.search||"");if(!s.has(Qu))return!1;s.delete(Qu);const a=s.toString();return i.replaceState(i.state??null,"",`${n.pathname||"/"}${a?`?${a}`:""}${n.hash||""}`),!0}catch{return!1}}const Tx="nc-update-dismissed";function Ix(){try{return typeof sessionStorage<"u"?sessionStorage:null}catch{return null}}function e3(t,e,n){return[t,e,n].map(i=>i||"").join("|")}let _m=null;function t3(t,e,n){const i=n;return t&&e&&t!==e&&t!==i?{kind:"install",version:t,browserVersion:i}:e&&i&&e!==i?{kind:"stale",version:e,browserVersion:i}:null}function n3(t,e){if(!t)return!1;try{return t.getItem(Tx)===e}catch{return!1}}function i3(t={}){const e=t.storage===void 0?Ix():t.storage;if(_m&&e)try{e.setItem(Tx,_m)}catch{}Gu=!1,Xu=null,wg(),yg()}function s3(t,e,n,i={}){const s=i.storage===void 0?Ix():i.storage,a=n,c=e3(t,e,a);_m=c;const d=t3(t,e,a);let h=n3(s,c)?null:d;if(h&&h.kind==="stale"){const g=`${e}|${a}`,y=QT(i.location)===g;let _=!1;if(!y&&s&&s.getItem(mu)!==g){try{s.setItem(mu,g)}catch{}_=s.getItem(mu)===g}_&&(JT(g,{location:i.location,history:i.history}),(i.applyImpl||Dx)(),h=null)}const f=JSON.stringify(h)===JSON.stringify(Xu);if(Xu=h,wg(),f||yg(),!d){try{s&&s.removeItem(mu)}catch{}ZT({location:i.location,history:i.history})}}const r3=1200;async function i0(t){if(typeof fetch=="function")try{await Promise.race([fetch(t,{cache:"reload"}),new Promise(e=>setTimeout(e,r3))])}catch{}}async function Dx(){try{Ol&&await Ol.update()}catch{}typeof location<"u"&&(await i0(location.pathname),await i0("/version.json"),location.reload())}function o3(t){t.addEventListener("statechange",()=>{t.state==="installed"&&navigator.serviceWorker.controller&&bg(!0)})}function a3(){typeof navigator>"u"||!("serviceWorker"in navigator)||(navigator.serviceWorker.addEventListener("controllerchange",()=>{jx&&location.reload()}),navigator.serviceWorker.register(GT).then(t=>{Ol=t,t.waiting&&bg(!0),t.addEventListener("updatefound",()=>{const e=t.installing;e&&o3(e)}),setInterval(()=>{t.update().catch(()=>{})},3600*1e3)}).catch(()=>{}))}function l3(){jx=!0,bg(!1);const t=Ol&&Ol.waiting;t?(t.postMessage({type:"SKIP_WAITING"}),setTimeout(()=>location.reload(),4e3)):location.reload()}function c3({hash:t="",origin:e="",pathname:n="",search:i=""}={}){const s=String(t||"").replace(/^#/,""),a=`${n||""}${i||""}`;if(!s)return{token:"",pair:"",nextUrl:a};const c=new URLSearchParams(s),d=c.get("token")||"",h=c.get("pair")||"",f=h?`${e||""}${n||""}#pair=${h}`:"";return{token:d,pair:f,nextUrl:a}}const Bx=9,Ox=24,$x="nc_side_w",s0="nc_side_min",u3=240,r0=new Set(["absent","present","active","unknown"]);function d3(){const t=Number(localStorage.getItem($x));return t>=180&&t<=480?t:u3}function h3(){const t=Number(localStorage.getItem("nc_fontsize"));return t>=Bx&&t<=Ox?t:13}function f3(){const t={token:"",pair:""};try{const{token:e,pair:n,nextUrl:i}=c3({hash:location.hash,origin:location.origin,pathname:location.pathname,search:location.search});if(e){t.token=e;try{localStorage.setItem("nc_token",e)}catch{}}if(n){t.pair=n;try{sessionStorage.setItem("nc_pair",n)}catch{}}if(location.hash)try{history.replaceState(null,"",i)}catch{}}catch{}if(t.token||(t.token=sessionStorage.getItem("nc_token")||localStorage.getItem("nc_token")||""),!t.pair){const e=sessionStorage.getItem("nc_pair");e&&(t.pair=e)}return t}function o0(t){try{return ls(fm(t))}catch{return sa()}}function a0(t){if(!t)return"";const e=Math.floor(Date.now()/1e3)-t;return e<0||e<60?"ora":e<3600?`${Math.floor(e/60)}m`:e<86400?`${Math.floor(e/3600)}h`:`${Math.floor(e/86400)}g`}function l0({session:t,node:e,ownerId:n,cellName:i,token:s,readonly:a=!1,panelPort:c=0,onBack:d,onCellSwitcher:h,cellSwitcherOpen:f=!1,liveHost:g=null}){ui();const[y]=eg(),[_,w]=k.useState(!1),[S,N]=k.useState(()=>window.matchMedia("(pointer: coarse)").matches),[C,E]=k.useState(null),[x,M]=k.useState(h3),[T,U]=k.useState(kl),[z,K]=k.useState(()=>kl()),Q=()=>{const ce=_A(yA(kl()));U(ce),typeof window<"u"&&window.location.reload()},[q,G]=k.useState(i||t),[H,P]=k.useState(""),[L,I]=k.useState(""),[D,O]=k.useState(""),[R,A]=k.useState(!1),j=ce=>M(Ce=>{const Be=Math.max(Bx,Math.min(Ox,Ce+ce));return localStorage.setItem("nc_fontsize",String(Be)),Be}),F=k.useRef(()=>{}),$=k.useRef(()=>!1),W=k.useRef(()=>{}),le=k.useRef(!1),[ve,ie]=k.useState(!1),[ue,ne]=k.useState(!1),J=()=>{le.current=!le.current,ie(le.current)};return k.useEffect(()=>{G(i||t),A(!1)},[i,t]),k.useEffect(()=>{let ce=!0;const Ce=e?e.split("/"):[],Be=e?`/api/route/${e.split("/").map(encodeURIComponent).join("/")}/_`:"/api";async function de(){let we=null,Ue=null;try{const st=await(await cn(`${Be}/sessions`,s)).json();Array.isArray(st.sessions)&&(we=st.sessions.find(vt=>vt.name===t))}catch{}try{const gt=await Dr(s,Ce);gt.available&&Array.isArray(gt.cells)&&(Ue=gt.cells.find(st=>st.tmuxSession===t))}catch{}if(!ce)return;G(tg({session:t,cell:Ue||(i?{cell:i}:null)})),I(typeof(Ue==null?void 0:Ue.panelUrl)=="string"?Ue.panelUrl.trim():""),O(typeof(Ue==null?void 0:Ue.cell)=="string"?Ue.cell:"");let mt="";Ue?mt=`${Ue.engine}${Ue.key?`·${Ue.key}`:""}`:we&&(mt=we.attached?`attached · ${a0(we.activity)}`:we.activity?a0(we.activity):""),P(mt)}de();const ye=setInterval(de,4e3);return()=>{ce=!1,clearInterval(ye)}},[t,e,s]),l.jsxs("div",{className:"nc-app",children:[l.jsxs("header",{className:"nc-bar nc-bar-single",children:[l.jsxs("button",{onClick:d,title:m("sessions"),children:[l.jsx(ht,{name:"chevronLeft",size:18}),l.jsx("span",{className:"nc-bar-label",children:m("sessions")})]}),l.jsxs("span",{className:"nc-bar-center",children:[l.jsx("b",{title:e?`${q} · ${e}`:q,children:q}),g&&g.cell&&g.cell===i?l.jsx("span",{className:`nc-live-host-dot ${j1(g)} nc-live-host-dot-header`,"data-testid":"live-host-header-dot",title:m("live-host-indicator").replace("{cell}",g.cell).replace("{mode}",m(g.mode?`live-host-mode-${g.mode}`:"live-host-mode-unknown")).replace("{state}",m(`live-host-state-${g.state}`))}):null,H&&l.jsx("small",{className:"nc-bar-sub",children:H})]}),l.jsxs("span",{className:"nc-bar-right",children:[l.jsx("button",{onClick:()=>j(-1),title:m("zoom-out"),children:l.jsx(ht,{name:"zoomOut",size:18})}),l.jsx("button",{onClick:()=>j(1),title:m("zoom-in"),children:l.jsx(ht,{name:"zoomIn",size:18})}),l.jsx("button",{type:"button",className:`nc-renderer-toggle${z==="webgl"?" on":""}`,onClick:Q,"aria-pressed":z==="webgl",title:m("terminal-renderer-switch").replace("{requested}",m(T==="dom"?"terminal-renderer-dom":"terminal-renderer-webgl")).replace("{effective}",m(z==="dom"?"terminal-renderer-dom":"terminal-renderer-webgl")),"aria-label":m("terminal-renderer-switch").replace("{requested}",m(T==="dom"?"terminal-renderer-dom":"terminal-renderer-webgl")).replace("{effective}",m(z==="dom"?"terminal-renderer-dom":"terminal-renderer-webgl")),children:l.jsx(ht,{name:"gpu",size:18})}),l.jsx("button",{onClick:()=>N(ce=>!ce),title:m("composer"),children:l.jsx(ht,{name:"keyboard",size:20})}),l.jsx("button",{onClick:()=>w(ce=>!ce),title:m("files"),children:l.jsx(ht,{name:"folder",size:20})}),L&&l.jsx("button",{onClick:()=>A(ce=>!ce),title:m("panel"),"aria-pressed":R,children:l.jsx(ht,{name:"monitor",size:20})})]})]}),l.jsxs("div",{className:"nc-termwrap",children:[l.jsx(Ym,{session:t,node:e,token:s,readonly:a,takeSize:!0,sendRef:F,composerRef:$,actionRef:W,ctrlRef:le,setCtrlArmed:ie,onFiles:E,fontSize:x,selectionMode:ue,onSelectionModeChange:ne,keyboardGesture:y.terminalKeyboardGesture,onRendererChange:K}),R&&L&&D&&l.jsx(Qm,{cellId:D,panelUrl:L,route:e?e.split("/"):[],panelPort:c,token:s,title:q})]}),l.jsx(lM,{onKeyboard:()=>N(ce=>!ce),onCellSwitcher:h,cellSwitcherOpen:f,send:ce=>F.current(ce),action:ce=>W.current(ce),ctrlArmed:ve,onCtrl:J,selectionMode:ue,onSelectionMode:ne,keepKeyboardClosed:y.keybarKeepsKeyboardClosed,showEnter:y.showKeybarEnter,keybarLayout:y.keybarLayout}),S&&l.jsx(M1,{submitText:ce=>$.current(ce),token:s,session:t,node:e,ownerId:n,readonly:a,keepKeyboardClosedOnVoice:y.voiceKeepsKeyboardClosed}),_&&l.jsx(S1,{session:t,node:e,token:s,filesEvent:C,onClose:()=>w(!1)})]})}function p3(){ui();const[t]=k.useState(f3),[e,n]=k.useState(t.token),[i,s]=k.useState(t.pair||""),a=k.useCallback(()=>{s("");try{sessionStorage.removeItem("nc_pair")}catch{}},[]),[c,d]=k.useState(!1),h=zA(),[f]=k.useState(()=>QM(typeof location<"u"?location.pathname:"/")),[g,y]=k.useState(f.id),_=g===po(null,Oi),[w,S]=k.useState(null),N=me=>{const Ee=Zs(me);S(Ee?{...Ee,...typeof(me==null?void 0:me.cellName)=="string"&&me.cellName?{cellName:me.cellName}:{}}:null)},[C,E]=k.useState([]),[x,M]=k.useState([]),[T,U]=k.useState([]),[z,K]=k.useState(!1),[Q,q]=k.useState(null),[G,H]=k.useState(()=>f.ownerId?sa():o0(f.name)),[P,L]=k.useState(null),[I,D]=k.useState(null),O=me=>D(Zs(me)),[R,A]=k.useState(null),j=Rm(e,h),F=k.useMemo(()=>(j||[]).filter(me=>me.instanceId).map(me=>({instanceId:me.instanceId,route:me.route,label:me.label,status:me.status,stale:me.stale===!0})),[j]),$=YT(e,g,G,H,F),W=$.decks;k.useEffect(()=>{const me=new Map;for(const Ee of j||[]){const Me=(Ee.route||[Ee.name]).join("/"),Ze=new Set((Ee.sessions||[]).map(at=>at.name));for(const at of Ee.cells||[])!at.cell||!at.tmuxSession||at.cell===at.tmuxSession||Ze.has(at.cell)||me.set(`${Me}:${at.cell}`,`${Me}:${at.tmuxSession}`)}H(Ee=>Z2(Ee,me))},[j]),k.useEffect(()=>{$.localNodeId&&f.ownerId&&f.ownerId===$.localNodeId&&H(me=>me.columns.some(Ee=>Ee.tiles.length)?me:o0(f.name))},[$.localNodeId]),k.useEffect(()=>{$.localNodeId&&(KM(F),$.viewUpdate(me=>{const Ee=hm(me,$.localNodeId,F);return JSON.stringify(Ee)===JSON.stringify(me)?me:Ee}))},[F,$.localNodeId,$.viewUpdate]);const[le,ve]=k.useState(null),[ie,ue]=k.useState(null),ne=k.useRef(0),[J,ce]=k.useState(!1),[Ce,Be]=k.useState(d3),[de,ye]=k.useState(!_),[we,Ue]=k.useState(()=>_?localStorage.getItem(s0)==="1":!0),[mt,gt]=k.useState(!1),[st,vt]=k.useState("nodes"),[Et,it]=k.useState(!1),[Dt,Ut]=k.useState(""),[Bt,_t]=k.useState(!1),yt=(me="nodes",Ee=!1,Me="")=>{vt(me),it(Ee),Ut(Me),gt(!0)},[un,oe]=k.useState(!1),[et,jt]=k.useState({deviceDefault:"",localNodeId:"",localNameDefault:""}),[ae,re]=k.useState(!1),[Z,_e]=k.useState(0),[ke,rt]=k.useState({});k.useEffect(()=>{try{localStorage.setItem($x,String(Ce))}catch{}},[Ce]),k.useEffect(()=>{try{localStorage.setItem(s0,we?"1":"")}catch{}},[we]),k.useEffect(()=>{if(!e)return;let me=!1;return Promise.all([w0(e),cn("/api/config",e).then(Ee=>Ee.json())]).then(([Ee,Me])=>{me||(jt({deviceDefault:Ee.deviceName||"",localNodeId:Ee.nodeId||"",localNameDefault:Ee.localName||""}),re(!!Me.readonlyDefault),_e(Number.isInteger(Me.panelPort)?Me.panelPort:0),rt(Me.nodePanelPorts&&typeof Me.nodePanelPorts=="object"&&!Array.isArray(Me.nodePanelPorts)?Me.nodePanelPorts:{}),(Ee.firstRun===!0&&!Me.readonlyDefault||i)&&oe(!0))}).catch(()=>{}),()=>{me=!0}},[e,i]);const[ct,pt]=k.useState({}),At=k.useCallback(({route:me,hostCell:Ee,revision:Me})=>{const Ze=Di(me);pt(at=>({...at,[Ze]:{hostCell:Ee||null,hostLease:null,hostRevision:Number.isInteger(Me)?Me:(at[Ze]||{}).hostRevision||0,threadStatus:"absent"}}))},[]),Wt=me=>{const Ee=Di(me),Me=me.length?((j||[]).find(Ze=>Di(Array.isArray(Ze.route)?Ze.route:[])===Ee)||{}).cells||[]:x;return Ku({liveHost:ct[Ee]||null,cells:Me,localNodeId:$.localNodeId,ownerId:me.length?Ee:$.localNodeId})},Nt=k.useRef(j);k.useEffect(()=>{Nt.current=j},[j]);const Lt=k.useCallback(async()=>{try{const at=await(await cn("/api/sessions",e)).json();at.error||E(at.sessions||[])}catch{}let me=null,Ee=null;try{me=await Dr(e)}catch(Ze){Ee=Ze}const Me=Lm({fs:me,error:Ee});Me.kind==="data"?(M(Me.cells),U(Me.capabilities),K(!1),q(null)):Me.kind==="stale"?(K(!0),q(null)):(M([]),U([]),K(!1),q(Me.reason||""))},[e]);k.useEffect(()=>{let me=!1;const Ee=async()=>{const Ze=[[],...(Nt.current||[]).filter(Ot=>Ot.kind!=="vl"&&Ot.status==="up").map(Ot=>Array.isArray(Ot.route)&&Ot.route.length?Ot.route:[Ot.name])],at=await Promise.all(Ze.map(async Ot=>{const $t=Di(Ot);try{const sn=await ed(e,Ot);return[$t,{hostCell:sn&&typeof sn.hostCell=="string"?sn.hostCell:null,hostLease:sn&&sn.host&&typeof sn.host.lease=="string"?sn.host.lease:null,hostRevision:Number.isInteger(sn&&sn.revision)?sn.revision:0,threadStatus:sn&&r0.has(sn.threadStatus)?sn.threadStatus:"unknown"}]}catch{return[$t,{error:!0}]}}));me||pt(Ot=>{let $t=!1;const sn={...Ot};for(const $i of at){if(!$i)continue;const[fi,Ms]=$i;sn[fi]=Ms.error?{...Ot[fi]||{},threadStatus:"unknown"}:Ms,$t=!0}return $t?sn:Ot})};Ee();const Me=setInterval(Ee,4e3);return()=>{me=!0,clearInterval(Me)}},[e]),k.useEffect(()=>{if(!h)return;Lt();const me=setInterval(Lt,4e3);return()=>clearInterval(me)},[h,Lt]);const X=k.useCallback(async(me,Ee=[])=>{const Me=Di(Ee),Ze=ct[Me]&&ct[Me].hostRevision||0;try{const at=await td(e,me,Ze,Ee);return pt(Ot=>({...Ot,[Me]:{hostCell:at.hostCell||null,hostLease:at.host&&typeof at.host.lease=="string"?at.host.lease:null,hostRevision:Number.isInteger(at.revision)?at.revision:Ze,threadStatus:r0.has(at.threadStatus)?at.threadStatus:"unknown"}})),{ok:!0}}catch(at){return{ok:!1,error:at}}},[e,ct]),xe=k.useCallback(async(me,Ee=[])=>{const Me=await X(me,Ee);return Me.ok||window.alert(m(Au(Me.error))),Me.ok},[X]),ze=k.useCallback(async(me=[])=>{const Ee=Di(me),Me=ct[Ee]&&ct[Ee].hostRevision||0;try{const Ze=await nd(e,Me,me);return pt(at=>({...at,[Ee]:{hostCell:Ze.hostCell||null,hostLease:null,hostRevision:Number.isInteger(Ze.revision)?Ze.revision:Me,threadStatus:"unknown"}})),{ok:!0}}catch(Ze){return{ok:!1,error:Ze}}},[e,ct]),Ke=k.useCallback(async(me=[])=>{const Ee=await ze(me);return Ee.ok||window.alert(m(Au(Ee.error))),Ee.ok},[ze]);k.useEffect(()=>{let me=!1;const Ee=()=>{cn("/api/config",e).then(Ze=>Ze.json()).then(Ze=>{me||s3(Ze.version,Ze.uiVersion,"0.9.35")}).catch(()=>{})};Ee();const Me=setInterval(Ee,6e4);return()=>{me=!0,clearInterval(Me)}},[e]);const Qe=new Set([...C.map(me=>me.name),...j.flatMap(me=>me.sessions.map(Ee=>Ee.key))]),Pt=Bi(G),Tt=me=>H(Ee=>{const Me=W1(me,$.localNodeId,F)||me,Ze=J0(Ee,Me);return Ze===Ee&&Bi(Ee).length>=9&&$.setError(m("grid-full")),Ze}),Y=async(me,Ee=[])=>{try{await Sm(e,me,Ee)}catch{return}const Me=Ee.length?`${Ee.join("/")}:${me}`:me;H(Ze=>Du(Ze,Me)),Lt()},te=async(me,Ee,Me=[])=>{try{await y0(e,me,Ee,Me)}catch{return}Lt()},Se=async(me,Ee,Me=[])=>{await g0(e,{cell:me,enabled:!!Ee},Me),Lt()},Ye=async me=>{if(!le)return;const{cell:Ee}=le,Me=Array.isArray(le.route)?le.route:[];if(me.action==="up"){const at=await bm(e,{cell:Ee,boot:!!me.boot,...me.engine?{engine:me.engine}:{},...me.model!==void 0?{model:me.model}:{},...me.permissionPolicy?{permissionPolicy:me.permissionPolicy}:{}},Me),Ot=Tm(at);Ot&&$.setError(Ot.text)}else await Nu(e,{cell:Ee,boot:!!me.boot},Me);const Ze=me.action==="up"?!!me.boot:me.boot?!1:!!le.boot;ue({id:++ne.current,cell:Ee,route:Me,enabled:Ze}),Lt()},Oe=k.useCallback(me=>{ue(Ee=>(Ee==null?void 0:Ee.id)===me?null:Ee)},[]),Ae=async me=>{if(!(!(me!=null&&me.direct)||J)){ce(!0);try{await Em(e,me.name,me.tunnelStatus==="up"?"down":"up")}finally{ce(!1)}}},ot=async(me,Ee)=>{const Me=String(Ee||"").trim();return!(me!=null&&me.direct)||!ca(Me)?!1:(await x0(e,me.name,Me),!0)},zt=me=>{const Ee=W.find(Me=>Me.id===me);if(!Ee)return!1;try{const Me=window.open(Lf(Ee,e),"_blank");return Me&&(Me.opener=null),!!Me}catch{return!1}},nn=async me=>{if(!me||me===g)return;const Ee=await $.select(me),Me=$.records.find(Ze=>Ze.id===me);y(me),H(Ee),L(null),D(null);try{history.replaceState(null,"",Lf(Me||me,null))}catch{}},We=async(me,Ee)=>{const Me=await $.add(me,Ee);await nn(Me.id)},$e=async(me,Ee)=>{const Me=await $.rename(me,Ee);if(me===g){y(Me.id),H(hm(Me.layout,$.localNodeId,F)),L(null),D(null);try{history.replaceState(null,"",Lf(Me,null))}catch{}}},Ct=async me=>{await $.remove(me),me===g&&await nn($.localMainId)},Un=async(me,Ee)=>{!Ee||Ee===g||(await $.addTileTo(Ee,me),H(Me=>Du(Me,me)))};if(!e)return l.jsxs("div",{className:"nc-auth",children:[l.jsx("p",{children:m("auth-prompt")}),l.jsx("input",{onChange:me=>n(me.target.value.trim()),placeholder:"token"}),l.jsxs("label",{children:[l.jsx("input",{type:"checkbox",checked:c,onChange:me=>d(me.target.checked)})," ",m("remember-device")]}),l.jsx("button",{onClick:()=>{(c?localStorage:sessionStorage).setItem("nc_token",e)},children:"ok"})]});const Xn=l.jsxs(l.Fragment,{children:[mt&&l.jsx(RT,{token:e,initialTab:st,initialLocation:Dt,startNewCell:Et,onClose:()=>{gt(!1),it(!1),Ut("")}}),un&&l.jsx(AT,{token:e,initialPair:i,...et,onPairDone:a,onDone:()=>oe(!1)}),l.jsx(BT,{token:e})]});if(!h)return R?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-single-overlay",children:l.jsx(t0,{peer:R,token:e,onBack:()=>A(null)})}),Xn]}):w?l.jsxs(l.Fragment,{children:[l.jsx(l0,{session:w.session,node:w.node,ownerId:w.ownerId,cellName:w.cellName,token:e,readonly:ae,liveHost:Wt(w.node?w.node.split("/"):[]),panelPort:Vu(w.node?w.node.split("/"):[],ke,Z),onBack:()=>S(null),onCellSwitcher:()=>_t(!0),cellSwitcherOpen:Bt}),Bt&&l.jsx(UT,{token:e,current:w,panelPort:Z,nodePanelPorts:ke,hostByRoute:ct,onDesignateCell:X,onClearHostCell:ze,onLiveHostApplied:At,onPick:me=>{N(me),_t(!1)},onClose:()=>_t(!1)}),Xn]}):l.jsxs(l.Fragment,{children:[l.jsx(_5,{onPick:N,token:e,onSettings:yt,onOpenVlSession:A,hostByRoute:ct,onDesignateCell:xe,onClearHostCell:Ke}),Xn]});const Cn=_||!de;return l.jsxs("div",{className:"nc-workspace",children:[Cn&&l.jsx(BM,{sessions:C,cells:x,activeSessions:Pt,nodeGroups:j,token:e,onPeekOpen:()=>_t(!1),overlayOpen:Bt,fleetCapabilities:T,fleetStale:z,fleetOff:Q,bootSettlement:ie,onBootSettlementApplied:Oe,localNodeId:$.localNodeId,hostByRoute:ct,onDesignateCell:xe,onClearHostCell:Ke,onPick:O,onAddTile:Tt,onPower:ve,onBoot:Se,onBootError:me=>$.setError(String((me==null?void 0:me.message)||me)),onNodePower:Ae,onNodeRename:ot,onKill:Y,onVisibility:te,onNew:()=>yt("fleet",!0),onSettings:yt,onOpenVlSession:A,width:Ce,collapsed:we,onResize:Be,onToggleCollapse:()=>Ue(me=>!me)}),l.jsxs("div",{className:"nc-workspace-main",children:[l.jsx(wj,{decks:W,currentDeck:g,onCreate:We,onRename:$e,onDelete:Ct,onReorder:$.reorder,onOpenWindow:zt,onNavigate:nn,saveState:$.saveState,error:$.error,conflict:$.conflict,onReloadDeck:$.reloadCurrent,sidebarVisible:Cn,onToggleSidebar:_?null:()=>ye(me=>!me)}),l.jsx(qM,{layout:G,onLayoutChange:H,onResizeEnd:()=>{$.saveNow()},token:e,readonly:ae,sessionsAlive:Qe,focusSession:P,onFocus:L,onOpenSingle:O,decks:W,currentDeck:g,onSendToDeck:Un,cells:x,nodeGroups:j,panelPort:Z,nodePanelPorts:ke})]}),R&&l.jsx("div",{className:"nc-single-overlay",children:l.jsx(t0,{peer:R,token:e,onBack:()=>A(null)})}),I&&l.jsx("div",{className:"nc-single-overlay",children:l.jsx(l0,{session:I.session,node:I.node,ownerId:I.ownerId,cellName:tg({session:I.session,node:I.node,ownerId:I.ownerId,cells:x,nodeGroups:j}),token:e,readonly:ae,liveHost:Wt(I.node?I.node.split("/"):[]),panelPort:Vu(I.node?I.node.split("/"):[],ke,Z),onBack:()=>D(null)})}),le&&l.jsx(ju,{cell:le,token:e,route:Array.isArray(le.route)?le.route:[],onConfirm:Ye,onClose:()=>ve(null)}),Xn]})}function m3(t){return t.kind==="install"?m("update-installed-restart").replace("{v}",t.version):t.kind==="stale"?m("update-stale").replace("{ui}",t.version).replace("{browser}",t.browserVersion):m("update-available").replace("{v}",t.version).replace(" "," ").trim()}function g3(){ui();const t=k.useSyncExternalStore(XT,n0,n0);return t.needed?l.jsxs("div",{className:"nc-update",role:"status","aria-live":"polite",children:[l.jsx("span",{className:"nc-update-msg",children:m3(t)}),t.kind==="stale"&&l.jsx("button",{className:"nc-update-btn",onClick:Dx,children:m("reload-no-cache")}),t.kind==="reload"&&l.jsx("button",{className:"nc-update-btn",onClick:l3,children:m("reload")}),l.jsx("button",{className:"nc-update-close",onClick:i3,"aria-label":m("update-dismiss"),title:m("update-dismiss"),children:"×"})]}):null}a3();xk.createRoot(document.getElementById("root")).render(l.jsxs(gk.StrictMode,{children:[l.jsx(p3,{}),l.jsx(g3,{})]}));
|
|
167
|
+
`],{type:"application/json"}),O=URL.createObjectURL(D),R=document.createElement("a");R.href=O,R.download="nexuscrew-diagnostics.json",R.click(),URL.revokeObjectURL(O)}catch{_(m("diagnostics-export-failed"))}};return l.jsxs("div",{className:"nc-set-tab nc-diagnostics",children:[l.jsxs("label",{className:"nc-field",children:[m("diagnostics-target"),l.jsx("select",{value:c.key,onChange:D=>a(D.target.value),children:i.map(D=>l.jsxs("option",{value:D.key,children:[D.label,D.status!=="up"?` · ${D.status}`:""]},D.key))})]}),l.jsxs("div",{className:"nc-set-form nc-diag-controls",children:[l.jsx("div",{className:"nc-sheet-label",children:m("diagnostics-verbose")}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("select",{"aria-label":m("diagnostics-duration"),value:E,onChange:D=>x(Number(D.target.value)),disabled:n,children:[300,900,1800,3600].map(D=>l.jsxs("option",{value:D,children:[D/60," min"]},D))}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||(d==null?void 0:d.verbose)===!0,onClick:()=>P(()=>X_(t,!0,E,c.route)),children:m("enable")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||(d==null?void 0:d.verbose)!==!0,onClick:()=>P(()=>X_(t,!1,E,c.route)),children:m("stop")})]}),l.jsx("small",{className:"nc-set-hint",children:d!=null&&d.verbose?m("diagnostics-expires").replace("{time}",new Date(d.expiresAt).toLocaleTimeString()):m("diagnostics-off")})]}),l.jsxs("div",{className:"nc-diag-filters",children:[l.jsxs("select",{"aria-label":m("diagnostics-level"),value:M,onChange:D=>T(D.target.value),children:[l.jsx("option",{value:"all",children:m("diagnostics-all-levels")}),["debug","info","warn","error"].map(D=>l.jsx("option",{value:D,children:D},D))]}),l.jsx("input",{"aria-label":m("diagnostics-component"),placeholder:m("diagnostics-component"),value:U,onChange:D=>z(D.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:D=>S(D.target.checked)})," ",m("diagnostics-pause")]}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox",checked:N,onChange:D=>C(D.target.checked)})," ",m("diagnostics-autoscroll")]})]}),l.jsx("pre",{ref:Q,className:"nc-diag-log","aria-label":m("diagnostics-log"),children:H||m("diagnostics-empty")}),l.jsxs("div",{className:"nc-set-row",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:L,children:m("copy")}),l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:I,children:m("diagnostics-export")}),l.jsx("button",{type:"button",className:"nc-btn danger",disabled:n,onClick:()=>{window.confirm(m("diagnostics-clear-confirm"))&&P(async()=>{const D=await o2(t,c.route);return K.current=0,g([]),D})},children:m("diagnostics-clear")})]}),y&&l.jsx("div",{className:"nc-err",children:y})]})}function LT({token:t,settings:e,readonly:n,refresh:i,roster:s,section:a,setSection:c}){const[d,h]=k.useState(null),[f,g]=k.useState(null),[y,_]=k.useState(!1),[w,S]=k.useState(!1),[N,C]=k.useState(null),[E,x]=k.useState(!0),[M,T]=k.useState(!1);k.useEffect(()=>{C(e&&e.update||null),x(!e||e.autoUpdate!==!1),T(!!(e&&e.alternateScreen))},[e]);const U=async()=>{h(null),g(null),S(!0);try{const L=await zk(t);g(L.note||"ok"),_(!1)}catch(L){h(String(L.message||L))}S(!1)},z=async()=>{h(null),g(null),S(!0);try{const L=await t2(t);g(`${L.note||"ok"}${L.target?` (${L.target})`:""}`)}catch(L){h(String(L.message||L))}S(!1)},K=async L=>{h(null),g(null),S(!0);try{await sp(t,{autoUpdate:L}),x(L),i&&await i()}catch(I){h(String(I.message||I))}S(!1)},Q=async L=>{h(null),g(null),S(!0);try{await sp(t,{alternateScreen:L}),T(L),i&&await i()}catch(I){h(String(I.message||I))}S(!1)},q=async()=>{h(null),g(null),S(!0);try{C(await n2(t))}catch(L){h(String(L.message||L))}S(!1)},G=async()=>{h(null),g(null),S(!0);try{const L=await i2(t);C(L),g(m("npm-update-restarting"))}catch(L){h(String(L.message||L))}S(!1)},H=()=>{window.confirm(m("composer-clear-confirm"))&&(h(null),yM()?(window.dispatchEvent(new Event(am)),g(m("composer-clear-done"))):h(m("composer-clear-failed")))},P=e&&e.service;return l.jsxs("div",{className:"nc-set-tab",children:[l.jsx("div",{className:"nc-system-tabs",role:"tablist","aria-label":m("tab-system"),children:["general","diagnostics"].map(L=>l.jsx("button",{type:"button",role:"tab","aria-selected":a===L,className:`nc-set-tabbtn${a===L?" on":""}`,onClick:()=>c(L),children:m(`system-${L}`)},L))}),a==="general"&&l.jsxs(l.Fragment,{children:[l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:m("system-this-node")}),e&&l.jsxs("div",{className:"nc-set-info",children:["v",e.version," · ",e.platform," · :",e.port,l.jsx("br",{}),P&&P.installed?m("service-installed"):m("service-missing"),P&&P.installed?` · ${P.active?m("service-active"):m("service-inactive")}`:"",P?` · boot ${P.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?m("settings-readonly"):"",onClick:z,children:m("service-regenerate")})}),l.jsx(xT,{token:t,readonly:n}),l.jsx(CT,{})]}),l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:m("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:L=>K(L.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:m("npm-auto-update")}),l.jsx("small",{children:m("npm-auto-update-help")})]})]}),N&&l.jsxs("div",{className:"nc-set-info",children:[m("npm-update-current")," v",N.current,N.latest?` · ${m("npm-update-latest")} v${N.latest}`:""," · ",m(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:q,children:m("npm-update-check")}),N&&N.available&&l.jsx("button",{type:"button",className:"nc-btn primary",disabled:n||w||N.phase==="installing",onClick:G,children:m("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:m("system-security")}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:n||w,title:n?m("settings-readonly"):"",onClick:()=>{h(null),g(null),_(!0)},children:m("token-rotate")})})]}),l.jsxs("section",{className:"nc-system-group",children:[l.jsx("h3",{children:m("system-local-data")}),l.jsxs("div",{className:"nc-set-form",children:[l.jsx("div",{className:"nc-sheet-label",children:m("composer-clear-data")}),l.jsx("small",{className:"nc-set-hint",children:m("composer-clear-data-help")}),l.jsx("div",{className:"nc-set-row",children:l.jsx("button",{type:"button",className:"nc-btn ghost",onClick:H,children:m("composer-clear-data")})})]})]})]}),a==="diagnostics"&&l.jsxs("section",{className:"nc-system-group nc-system-diagnostics",children:[l.jsx("h3",{children:m("system-diagnostics")}),l.jsxs("div",{className:"nc-set-form nc-alternate-screen-settings",children:[l.jsx("div",{className:"nc-sheet-label",children:m("system-terminal")}),l.jsxs("label",{className:"nc-check",children:[l.jsx("input",{type:"checkbox","aria-label":m("alternate-screen"),checked:M,disabled:n||w,onChange:L=>Q(L.target.checked)}),l.jsxs("span",{children:[l.jsx("b",{children:m("alternate-screen")}),l.jsx("small",{children:m("alternate-screen-help")})]})]})]}),l.jsx(NT,{token:t,roster:s,readonly:n})]}),y&&l.jsxs("div",{className:"nc-set-confirm",children:[l.jsx("div",{children:m("token-rotate-explain")}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:w,onClick:()=>_(!1),children:m("cancel")}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:w,onClick:U,children:m("confirm")})]})]}),f&&l.jsx("div",{className:"nc-set-note",children:f}),d&&l.jsx("div",{className:"nc-err",children:d})]})}function RT({token:t,onClose:e,initialTab:n="nodes",initialLocation:i="",startNewCell:s=!1}){ui();const a=n==="diagnostics"?"diagnostics":"general",[c,d]=k.useState(n==="diagnostics"?"system":n),h=k.useRef(null),f=k.useRef(null),[g,y]=k.useState({start:!1,end:!1}),[_,w]=k.useState(a),[S,N]=k.useState(null),[C,E]=k.useState([]),[x,M]=k.useState(null),[T,U]=k.useState([]),[z,K]=k.useState(!1),[Q,q]=k.useState(null),[G,H]=k.useState(0),P=Rm(t,!0,G),L=k.useCallback(()=>{const D=h.current;if(!D)return;const O=D.scrollWidth>D.clientWidth+1,R={start:O&&D.scrollLeft>1,end:O&&D.scrollLeft+D.clientWidth<D.scrollWidth-1};y(A=>A.start===R.start&&A.end===R.end?A:R)},[]);k.useEffect(()=>{const D=h.current;if(!D)return;const O=typeof ResizeObserver=="function"?new ResizeObserver(L):null;return O==null||O.observe(D),window.addEventListener("resize",L),L(),()=>{O==null||O.disconnect(),window.removeEventListener("resize",L)}},[L]),k.useEffect(()=>{var O,R;(R=(O=f.current)==null?void 0:O.scrollIntoView)==null||R.call(O,{behavior:"smooth",block:"nearest",inline:"nearest"});const D=window.requestAnimationFrame?window.requestAnimationFrame(L):setTimeout(L,0);return()=>{window.cancelAnimationFrame?window.cancelAnimationFrame(D):clearTimeout(D)}},[c,L]);const I=k.useCallback(async()=>{var D;try{const O=await w0(t);N(O),q(null)}catch(O){q(String(O.message||O))}try{const O=await Ok(t),R=O.peers||[];M(Number.isInteger(O.accessRevision)?O.accessRevision:null);let A=[],j=[];try{const[F,$]=await Promise.all([cn("/api/config",t).then(ie=>ie.json()).catch(()=>null),S0(t).catch(()=>null)]),W=F&&typeof F.instanceId=="string"?F.instanceId:"",le=[{instanceId:W||null,route:[],label:null},...O0($,W)],ve=await Promise.all(le.map(async ie=>{try{return{ok:!0,peers:((await b0(t,ie.route)).nodes||[]).map(J=>B0(J,ie)).filter(Boolean)}}catch(ue){return{ok:!1,owner:ie,error:ue}}}));for(const ie of ve){if(ie.ok){A.push(...ie.peers);continue}ie.owner.route.length!==0&&j.push({instanceId:ie.owner.instanceId,label:ie.owner.label,route:ie.owner.route,failure:/timeout/i.test(String(((D=ie.error)==null?void 0:D.message)||ie.error))?"timeout":"unreachable"})}}catch{}U(j),E([...R,...A])}catch(O){q(String(O.message||O))}},[t]);return k.useEffect(()=>{I();const D=setInterval(I,5e3);return()=>clearInterval(D)},[I]),k.useEffect(()=>{let D=!1;return cn("/api/config",t).then(O=>O.json()).then(O=>{D||K(!!O.readonlyDefault)}).catch(()=>{}),()=>{D=!0}},[t]),l.jsx("div",{className:"nc-set-overlay",onClick:e,children:l.jsxs("div",{className:"nc-set-panel",onClick:D=>D.stopPropagation(),children:[l.jsxs("div",{className:"nc-set-head",children:[l.jsx(ht,{name:"gear",size:18}),l.jsx("b",{children:m("settings")}),l.jsx("button",{type:"button",className:"nc-set-close",onClick:e,title:m("close"),children:l.jsx(ht,{name:"x",size:18})})]}),z&&l.jsx("div",{className:"nc-set-readonly",children:m("settings-readonly")}),Q&&l.jsx("div",{className:"nc-err",children:Q}),l.jsx("div",{className:`nc-set-tabs-wrap${g.start?" has-start-overflow":""}${g.end?" has-end-overflow":""}`,children:l.jsx("div",{className:"nc-set-tabs",ref:h,onScroll:L,children:["nodes","fleet","audio","input","system"].map(D=>l.jsx("button",{ref:c===D?f:null,type:"button",className:`nc-set-tabbtn${c===D?" on":""}`,onClick:()=>d(D),children:m(`tab-${D}`)},D))})}),l.jsxs("div",{className:"nc-set-body",children:[c==="nodes"&&l.jsx(ST,{token:t,nodes:C,roster:P,settings:S,readonly:z,vlUnavailable:T,accessRevision:x,refresh:I,refreshAliases:()=>H(D=>D+1)}),c==="fleet"&&l.jsx(iT,{token:t,readonly:z,startNewCell:s,initialLocation:i,targets:P.map(D=>({route:D.route,label:D.label||D.name,status:D.status}))}),c==="audio"&&l.jsx(kT,{token:t,readonly:z,nodes:C,settings:S}),c==="input"&&l.jsx(ET,{}),c==="system"&&l.jsx(LT,{token:t,settings:S,readonly:z,refresh:I,roster:P,section:_,setSection:w})]})]})})}function AT({token:t,initialPair:e,deviceDefault:n="",localNodeId:i="",localNameDefault:s="",onPairDone:a,onDone:c}){ui();const[d,h]=k.useState(e?"pair":"welcome"),[f,g]=k.useState(!1),[y,_]=k.useState(null),[w,S]=k.useState(null),N=async()=>{g(!0),_(null);try{await sp(t,{wizardDone:!0}),a&&a(),c()}catch(C){_(String(C.message||C)),g(!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:m("wizard-title")}),l.jsx("small",{children:m("hydra-simple")})]}),d==="welcome"&&l.jsxs("div",{className:"nc-wiz-body",children:[l.jsx("div",{className:"nc-wiz-done",children:m("local-ready")}),l.jsxs("div",{className:"nc-sheet-actions",children:[l.jsx("button",{className:"nc-btn ghost",disabled:f,onClick:N,children:m("local-only")}),l.jsx("button",{className:"nc-btn primary",disabled:f,onClick:()=>h("pair"),children:m("add-node")})]})]}),d==="pair"&&l.jsxs("div",{className:"nc-wiz-body",children:[l.jsx(lx,{token:t,initial:e||"",autoStart:!!e,deviceDefault:n,localNodeId:i,localNameDefault:s,onBusyChange:g,onSuccess:async C=>{S(C&&C.authorizedKeys?{line:C.authorizedKeys,note:C.authorizedKeysNote||""}:null),a&&a(),h("done")}}),l.jsx("div",{className:"nc-sheet-actions",children:l.jsx("button",{className:"nc-btn ghost",disabled:f,onClick:()=>{a&&a(),h("welcome")},children:m("back")})})]}),d==="done"&&l.jsxs("div",{className:"nc-wiz-body",children:[l.jsx("div",{className:"nc-wiz-done",children:m("node-connected")}),w&&l.jsx(ug,{line:w.line,note:w.note}),l.jsx("div",{className:"nc-sheet-actions",children:l.jsx("button",{className:"nc-btn primary",disabled:f,onClick:N,children:m("finish")})})]}),y&&l.jsx("div",{className:"nc-err",children:y})]})})}function MT(t,e){if(typeof EventSource>"u"||!t)return()=>{};const n=new EventSource(`/api/events?token=${encodeURIComponent(t)}`);return n.onmessage=i=>{try{const s=JSON.parse(i.data);s&&typeof s=="object"&&typeof s.type=="string"&&e(s)}catch{}},()=>{try{n.close()}catch{}}}const jT=6e3,PT=12e3,Gs=(t,e,n)=>`${e||""}:${n||t}`;function Rx(t,e){const n=new Set(t.map(s=>Gs(s.id,s.ownerId,s.ownerAskId))),i=(e||[]).filter(s=>s&&s.id&&!n.has(Gs(s.id,s.ownerId,s.ownerAskId)));return i.length?[...t,...i]:t}function TT(t,e){const n=Rx([],t.filter(a=>a.imported)),i=new Set(n.map(a=>Gs(a.id,a.ownerId,a.ownerAskId)));return[...(e||[]).filter(a=>a&&a.id&&!i.has(Gs(a.id,a.ownerId,a.ownerAskId))),...n]}function IT({n:t,onClose:e}){return l.jsxs("div",{className:`nc-ntf-toast${t.urgency==="high"?" high":""}`,role:"status","aria-live":"polite",children:[l.jsxs("div",{className:"nc-ntf-toast-txt",children:[l.jsx("b",{children:t.title}),t.body&&l.jsx("small",{children:t.body}),t.session&&l.jsx("span",{className:"nc-ntf-from",children:t.session}),t.ownerId&&l.jsx("span",{className:"nc-ntf-from",children:m("feed-owner")})]}),l.jsx("button",{type:"button",className:"nc-ntf-x",onClick:e,title:m("close"),children:l.jsx(ht,{name:"x",size:14})})]})}function DT({ask:t,token:e,onAnswered:n,onDismiss:i,askReplyAccess:s=!1}){const[a,c]=k.useState(""),[d,h]=k.useState(!1),[f,g]=k.useState(null),[y,_]=k.useState(!1),[w,S]=k.useState(null),[N,C]=k.useState(!1),E=async M=>{const T=String(M||"").trim();if(!(!T||d)){g(null),h(!0);try{if(t.ownerId){const U=t.ownerAskId||t.id,z=await u2(e,{ownerId:t.ownerId,askId:U,text:T});if(z&&z.uncertain){S(z.requestId);return}n(t.id,t.ownerId)}else await l2(e,t.id,T),n(t.id)}catch(U){g(String(U.message||U))}h(!1)}},x=async()=>{if(!y){_(!0);try{if(t.ownerId){if(w)return;await h2(e,{ownerId:t.ownerId,askId:t.ownerAskId||t.id}),i(t.id,t.ownerId)}else await c2(e,t.id),i(t.id)}catch{_(!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:t.session}),t.ownerId&&l.jsx("span",{className:"nc-ntf-from",children:m("feed-owner")}),l.jsxs("code",{className:"nc-ask-id",children:["#",t.id]}),l.jsx("button",{type:"button",className:"nc-ask-dismiss",title:m("ask-dismiss"),"aria-label":m("ask-dismiss"),disabled:y||!!t.ownerId&&s===!1,onClick:x,children:l.jsx(ht,{name:"x",size:14})})]}),l.jsx("div",{className:"nc-ask-q",children:t.question}),t.ownerId&&s===!1&&l.jsx("small",{className:"nc-set-hint",children:m("ask-remote-readonly")}),w&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-err",children:m("ask-uncertain")}),l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:N,onClick:async()=>{C(!0);try{const M=await d2(e,{ownerId:t.ownerId,askId:t.id,requestId:w});M&&(M.state==="committed"||M.state==="failed")&&i(t.id,t.ownerId)}finally{C(!1)}},children:m("ask-verify")})]}),(!t.ownerId||s===!0)&&l.jsxs(l.Fragment,{children:[Array.isArray(t.options)&&t.options.length>0&&l.jsx("div",{className:"nc-ask-opts",children:t.options.map(M=>l.jsx("button",{type:"button",className:"nc-btn ghost",disabled:d,onClick:()=>E(M),children:M},M))}),l.jsxs("div",{className:"nc-ask-reply",children:[l.jsx("textarea",{rows:2,placeholder:m("ask-reply-ph"),value:a,disabled:d,onChange:M=>c(M.target.value)}),l.jsx("button",{type:"button",className:"nc-btn primary",disabled:d||!a.trim(),onClick:()=>E(a),children:m("send")})]})]}),f&&l.jsx("div",{className:"nc-err",children:f})]})}function BT({token:t}){const[e]=ui(),[n]=Lx(),[i,s]=k.useState([]),[a,c]=k.useState([]),[d,h]=k.useState(()=>{try{return/(?:^|[#&])ask=/.test(location.hash)}catch{return!1}}),f=k.useRef(0),g=k.useRef(null);g.current||(g.current=yT());const y=k.useRef({enabled:n,lang:e});y.current={enabled:n,lang:e};const _=k.useCallback(E=>{s(x=>x.filter(M=>M.key!==E))},[]),w=k.useCallback(E=>{const x=`t${f.current+=1}`;s(T=>[...T.slice(-3),{...E,key:x}]),setTimeout(()=>_(x),E.urgency==="high"?PT:jT);const M=y.current;if(M.enabled)try{g.current.enqueue(E,pT(E,M.lang))}catch{}},[_]);k.useEffect(()=>{n||g.current.stop()},[n]),k.useEffect(()=>{const E=()=>{(document.visibilityState!=="visible"||!document.hasFocus())&&g.current.stop()},x=()=>g.current.stop();return document.addEventListener("visibilitychange",E),window.addEventListener("blur",E),window.addEventListener(mm,x),()=>{document.removeEventListener("visibilitychange",E),window.removeEventListener("blur",E),window.removeEventListener(mm,x),typeof g.current.dispose=="function"?g.current.dispose():g.current.stop()}},[]);const S=(E,x)=>c(M=>M.filter(T=>Gs(T.id,T.ownerId)!==Gs(E,x)));k.useEffect(()=>{if(!t)return;let E=!1;a2(t).then(M=>{E||c(T=>TT(T,M.asks))}).catch(()=>{});const x=MT(t,M=>{if(M.type==="notify")w(M);else if(M.type==="ask"&&M.ask&&M.ask.id){const T=Gs(M.ask.id,M.ask.ownerId);c(U=>U.some(z=>Gs(z.id,z.ownerId)===T)?U:[...U,M.ask])}else(M.type==="ask-answered"&&M.id||M.type==="ask-dismissed"&&M.id)&&S(M.id,M.ownerId)});return()=>{E=!0,x()}},[t,w]);const[N,C]=k.useState({});return k.useEffect(()=>{let E=!0;return f2(t).then(x=>{if(!E)return;const M={},T=[];for(const U of x&&x.views||[]){M[U.ownerId]=U.askReplyAccess===!0;for(const z of U.asks||[])z&&z.id&&T.push({...z,ownerId:U.ownerId,imported:!0})}C(M),T.length&&c(U=>Rx(U,T))}).catch(()=>{}),()=>{E=!1}},[t]),l.jsxs(l.Fragment,{children:[i.length>0&&l.jsx("div",{className:"nc-ntf-toasts",children:i.map(E=>l.jsx(IT,{n:E,onClose:()=>_(E.key)},E.key))}),a.length>0&&!d&&l.jsxs("button",{type:"button",className:"nc-ask-badge",onClick:()=>h(!0),title:m("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:m("asks-title")}),l.jsx("span",{className:"nc-ask-count",children:a.length}),l.jsx("button",{type:"button",className:"nc-ntf-x",onClick:()=>h(!1),title:m("close"),children:l.jsx(ht,{name:"x",size:16})})]}),l.jsx("div",{className:"nc-ask-panel-body",children:a.map(E=>l.jsx(DT,{ask:E,token:t,askReplyAccess:!E.ownerId||N[E.ownerId]===!0,onAnswered:S,onDismiss:S},Gs(E.id,E.ownerId)))})]})]})}const OT=4e3;async function $T(t){const e=await cn("/api/sessions",t);if((e==null?void 0:e.ok)===!1)throw new Error(`HTTP ${e.status}`);const n=await e.json();if(!Array.isArray(n==null?void 0:n.sessions))throw new Error("invalid sessions payload");return n.sessions}async function tp(t,e=[]){var d;const[n,i]=await Promise.allSettled([e.length?Cm(t,e):$T(t),Dr(t,e)]),s=n.status==="fulfilled"&&Array.isArray((d=n.value)==null?void 0:d.sessions)?n.value.sessions:Array.isArray(n.value)?n.value:null,a=i.status==="fulfilled"?i.value:null,c=(a==null?void 0:a.available)===!0&&Array.isArray(a.cells)?a.cells:null;return{sessions:s,cells:c,fresh:Array.isArray(s)&&Array.isArray(c)}}function Ax(t,e,n){return n===!0&&(t==null?void 0:t.degraded)!==!0&&(t==null?void 0:t.active)===!0&&t.tmux!==!1&&!!t.tmuxSession&&(e||[]).some(i=>(i==null?void 0:i.name)===t.tmuxSession)}function zT(t){const e=new Map((t.sessions||[]).map(s=>[s.name,s])),n=[],i=(s,a,c,d=[],h="")=>{const f=new Map((a||[]).map(g=>[g.name,g]));for(const g of s||[]){const y=f.get(g.tmuxSession)||{},_=jm(g,y),w=Ax(g,a,c);n.push({key:Ll(d,g.tmuxSession||g.cell),session:g.tmuxSession,route:d,cellName:g.cell,label:g.cell,node:d.length?d.join("/"):"",nodeLabel:h,live:w,selectable:w,verified:c===!0,working:_.working,degraded:!!g.degraded,active:g.active===!0,activity:y.activity||g.activity||0,subtitle:_.subtitle,preview:y.preview||g.preview||"",telemetry:y.telemetry||null,panelUrl:g.panelUrl||""})}};i(t.cells,[...e.values()],t.localFresh===!0);for(const s of t.nodeGroups||[]){const a=Array.isArray(s.route)?s.route:[];s.kind==="vl"||!a.length||i(s.cells,s.sessions,s.switcherFresh===!0,a,s.label||s.name||"")}return n}function FT(t){const e=new Map,n=Array.isArray(t.sessions)?t.sessions:[],i=Array.isArray(t.cells)?t.cells:[],s=new Map(n.map(c=>[c.name,c])),a=new Set(i.map(c=>c.tmuxSession).filter(Boolean));e.set("local",Pm(i,n.filter(c=>!a.has(c.name)),s));for(const c of t.nodeGroups||[]){const d=Array.isArray(c.route)?c.route:[];if(c.kind==="vl"||!d.length)continue;const h=Array.isArray(c.cells)?c.cells:[],f=Array.isArray(c.sessions)?c.sessions:[],g=new Set(h.map(y=>y.tmuxSession).filter(Boolean));e.set(d.join("/"),Iu({...c,route:d,cells:h,sessions:f,unmanaged:f.filter(y=>!g.has(y.name))}).rawItems)}return e}function HT(t,e,n,i){return[...new Set(t.map(a=>a.node||"local"))].flatMap(a=>{const c=t.filter(g=>(g.node||"local")===a),d=new Map((e.get(a)||[]).map(g=>[g.key,g])),h=new Map(c.map(g=>[g.key,g])),f=c.map(g=>{const y=d.get(g.key);return{...g,label:(y==null?void 0:y.label)||g.label,live:(y==null?void 0:y.live)??g.live,fresh:(y==null?void 0:y.fresh)===!0,activity:(y==null?void 0:y.activity)??g.activity}});return Pr(f,n,"all",Js(i,a)).map(g=>h.get(g.key))})}function UT({token:t,current:e,onPick:n,onClose:i,panelPort:s=0,nodePanelPorts:a={},hostByRoute:c={},onDesignateCell:d,onClearHostCell:h,onLiveHostApplied:f}){const[g,y]=k.useState(hy),[_,w]=k.useState(!1),[S,N]=k.useState(!1),[C,E]=k.useState(""),[x,M]=k.useState(null),[T,U]=k.useState(""),[z,K]=k.useState(""),Q=k.useRef(null),q=k.useRef(null),G=k.useMemo(()=>zT(g),[g]),H=k.useMemo(()=>FT(g),[g]),{pins:P,orders:L,togglePin:I,removePin:D,pinError:O,canMoveRoster:R,moveRoster:A,stepRoster:j}=Mm(),F=k.useMemo(()=>HT(G,H,P,L),[G,H,P,L]),$=k.useMemo(()=>_?F:F.filter(de=>de.selectable||de.degraded&&de.active),[F,_]),W=k.useMemo(()=>G.find(de=>de.key===T&&de.selectable),[G,T]),le=k.useMemo(()=>x?G.find(de=>de.key===x.key):null,[G,x]);k.useEffect(()=>{O&&O.message&&E(O.message)},[O]),k.useEffect(()=>{var we;const de=document.activeElement;(we=q.current)==null||we.focus();const ye=Ue=>{Ue.key==="Escape"&&i()};return document.addEventListener("keydown",ye),()=>{var Ue;document.removeEventListener("keydown",ye),(Ue=de==null?void 0:de.focus)==null||Ue.call(de)}},[i]),k.useEffect(()=>{let de=!0,ye=!1;const we=async()=>{if(ye)return;ye=!0;const mt=hy(),gt=Array.isArray(mt.nodeGroups)?mt.nodeGroups:[],st=tp(t),vt=_t=>_t.kind!=="vl"&&Array.isArray(_t.route)&&_t.route.length>0,Et=await Promise.all(gt.filter(vt).map(async _t=>({group:_t,result:await tp(t,_t.route)}))),it=await st;if(!de)return;const Dt=new Map(Et.map(({group:_t,result:yt})=>[JSON.stringify(_t.route||[]),yt])),Ut=gt.map(_t=>{if(!vt(_t))return{..._t,switcherFresh:!1};const yt=Dt.get(JSON.stringify(_t.route||[]));return yt?{..._t,sessions:yt.sessions||_t.sessions||[],cells:yt.cells||_t.cells||[],switcherFresh:yt.fresh}:{..._t,switcherFresh:!1}}),Bt=tS({...mt,sessions:it.sessions||mt.sessions||[],cells:it.cells||mt.cells||[],localFresh:it.fresh,nodeGroups:Ut,refreshedAt:Date.now()});y(Bt),N(!0),ye=!1};we();const Ue=setInterval(we,OT);return()=>{de=!1,clearInterval(Ue)}},[t]);const[ve,ie]=k.useState(""),ue={getLiveHost:de=>ed(t,de),designateHostCell:(de,ye,we)=>td(t,de,ye,we),clearHostCell:(de,ye)=>nd(t,de,ye)},ne=de=>(c[Di(de)]||{}).hostCell||null,J=async(de,ye)=>{ie(de.key);const we=await D1({action:ye?"remove":"use",cellId:de.cellName,route:de.route||[],api:ue});ie(""),E(m(we.messageKey).replace("{cell}",we.hostCell||de.cellName)),we.ok&&f&&f({route:de.route||[],hostCell:we.hostCell,revision:we.revision})},ce=de=>de.degraded?m("cell-degraded"):de.verified?de.selectable?de.working?m("cell-working"):m("cell-idle"):m("cell-off"):m("cell-switcher-not-confirmed"),Ce=de=>{if(E(""),!de.selectable){E(de.verified?m("cell-switcher-not-active"):m("cell-switcher-not-confirmed"));return}U(de.key)},Be=async()=>{const de=W;if(!de){E(m("cell-switcher-select"));return}E(""),K(de.key);try{const ye=await tp(t,de.route),we=(ye.cells||[]).find(Ue=>(Ue==null?void 0:Ue.cell)===de.cellName&&(Ue==null?void 0:Ue.tmuxSession)===de.session);if(ye.fresh!==!0){E(m("cell-switcher-verify-failed"));return}if(!Ax(we,ye.sessions,ye.fresh)){E(m("cell-switcher-not-active"));return}n({session:de.session,...de.node?{node:de.node}:{},cellName:de.cellName}),i()}catch{E(m("cell-switcher-verify-failed"))}finally{K("")}};return l.jsx("div",{className:"nc-cell-switcher-backdrop",onClick:i,children:l.jsxs("aside",{ref:Q,className:"nc-cell-switcher",role:"dialog","aria-label":m("fleet-cells"),tabIndex:-1,onClick:de=>de.stopPropagation(),children:[l.jsxs("div",{className:"nc-cell-switcher-list",children:[l.jsx(P1,{className:"nc-cell-switcher-live-host",view:Ku({liveHost:c[Di([])],cells:g.cells||[]})}),!S&&l.jsx("div",{className:"nc-empty",role:"status",children:m("cell-switcher-refreshing")}),S&&$.length===0&&l.jsx("div",{className:"nc-empty",role:"status",children:m("cell-switcher-empty-active")}),$.map(de=>{const ye=(e==null?void 0:e.session)===de.session&&((e==null?void 0:e.node)||"")===de.node,we=T===de.key,Ue=ce(de),mt=cm(m,de.activity),gt=um(m,de.telemetry),st=[mt,gt].filter(Boolean).join(" · "),vt=de.node||"local",Et=H.get(vt)||G.filter(it=>(it.node||"local")===vt);return l.jsxs("div",{className:`nc-cell-switcher-row${ye?" current":""}${we?" selected":""}${de.selectable?"":" off"}`,"data-roster-key":de.key,"data-position":vt,children:[l.jsx(xs,{position:vt,itemKey:de.key,label:de.cellName,canMove:R,onMove:(it,Dt)=>A(vt,it,Dt,Et),onStep:it=>j(vt,de.key,it,Et)}),l.jsx("button",{type:"button",className:"nc-cell-switcher-peek",title:m("cell-peek"),"aria-label":`${m("cell-peek")}: ${de.cellName}`,onClick:it=>{it.stopPropagation(),M({key:de.key,source:"preview"})},children:l.jsx("span",{className:`nc-cell-switcher-dot${de.degraded?" warn":de.live?` on${de.working?" working":""}`:""}`})}),l.jsxs("span",{className:"nc-cell-switcher-acts",children:[l.jsx("button",{type:"button",className:"nc-cell-switcher-act",title:m("cell-peek-stream"),"aria-label":`${m("cell-peek-stream")}: ${de.cellName}`,onClick:it=>{it.stopPropagation(),M({key:de.key,source:"stream"})},children:"▶"}),de.panelUrl&&l.jsx("button",{type:"button",className:"nc-cell-switcher-act",title:m("cell-peek-panel"),"aria-label":`${m("cell-peek-panel")}: ${de.cellName}`,onClick:it=>{it.stopPropagation(),M({key:de.key,source:"panel"})},children:"▣"})]}),l.jsx("button",{type:"button",className:"nc-cell-switcher-row-select","aria-current":ye?"true":void 0,"aria-pressed":we,"aria-disabled":!de.selectable,disabled:z===de.key,onClick:()=>Ce(de),children:l.jsxs("span",{className:"nc-cell-switcher-copy",children:[l.jsx("b",{children:de.cellName}),l.jsx("small",{className:"nc-cell-switcher-state",children:Ue}),l.jsx("small",{children:[de.nodeLabel,de.subtitle].filter(Boolean).join(" · ")}),st&&l.jsx("small",{className:"nc-cell-switcher-telemetry",children:st})]})}),l.jsx(Mu,{item:{key:de.key,value:{cell:de.cellName}},pins:P,hostByRoute:c,route:de.route||[],cellName:de.cellName,baseClassName:"nc-cell-switcher-star",togglePin:I,removePin:D,onOutcome:it=>{it.ok||E(m(Au(it.error)))}}),l.jsx("button",{type:"button",className:`nc-cell-switcher-act nc-cell-switcher-host${ne(de.route||[])===de.cellName?" on":""}`,"data-testid":`live-host-command-${de.key}`,"data-live-host-state":ne(de.route||[])===de.cellName?"host":"idle",disabled:ve===de.key,title:ne(de.route||[])===de.cellName?m("live-host-action-remove"):m("live-host-action-use"),"aria-label":`${ne(de.route||[])===de.cellName?m("live-host-action-remove"):m("live-host-action-use")}: ${de.cellName}`,onClick:it=>{it.stopPropagation(),J(de,ne(de.route||[])===de.cellName)},children:l.jsx(ht,{name:"broadcast",size:18})})]},de.key)})]}),C&&l.jsx("div",{className:"nc-cell-switcher-notice",role:"status",children:C}),x&&le&&l.jsx(B1,{row:le,token:t,initialSource:x.source,panelPort:Vu(le.route||[],a,s),liveHost:Ku({liveHost:c[Di(le.route||[])],cells:g.cells||[]}),onLiveHostApplied:f,onClose:()=>M(null)}),l.jsx("div",{className:"nc-cell-switcher-actions",children:l.jsx("button",{type:"button",className:"nc-cell-switcher-open",disabled:!W||!!z,onClick:Be,children:W?`${m("cell-switcher-open")}: ${W.cellName}`:m("cell-switcher-select")})}),l.jsxs("div",{className:"nc-cell-switcher-controls",children:[l.jsx("b",{children:m("fleet-cells")}),l.jsx("button",{type:"button",className:"nc-cell-switcher-filter","aria-pressed":_,onClick:()=>{E(""),w(de=>!de)},children:m(_?"cell-switcher-show-active":"cell-switcher-show-all")}),l.jsx("button",{ref:q,type:"button",className:"nc-cell-switcher-close","aria-label":m("cell-switcher-close"),title:m("cell-switcher-close"),onClick:i,children:"×"})]})]})})}const WT=2e3;function qT(t){if(t.kind==="gap")return`${m("vl-events-gap")} ${t.count||"?"}`;if(t.kind==="truncate")return m("vl-events-truncated");if(t.kind==="turn_end")return m("vl-events-turn-end");if(t.kind==="done")return m("vl-events-done");if(t.kind==="writer_epoch")return m("vl-events-writer-epoch");if(t.kind==="tool_start")return`${m("vl-events-tool")} ${t.name||""}`.trim();if(t.kind==="tool_end"){const e=t.isError?m("vl-events-tool-failed"):m("vl-events-tool-ok");return`${m("vl-events-tool")} ${t.name||""} — ${e}`.trim()}return t.kind==="usage"?t.text||m("vl-events-usage"):t.text||""}function KT({token:t,nodeId:e,route:n=[]}){const[i,s]=k.useState([]),[a,c]=k.useState(!1),d=k.useRef(0),h=k.useRef(!1);return k.useEffect(()=>{let f=!0;d.current=0,h.current=!1,s([]);const g=async()=>{if(!h.current){h.current=!0;try{const w=await $k(t,e,d.current,n);if(!f)return;c(!1);const N=(Array.isArray(w==null?void 0:w.events)?w.events:[]).filter(C=>Number.isSafeInteger(C==null?void 0:C.seq)&&C.seq>d.current);N.length&&(s(C=>C.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{f&&c(!0)}finally{h.current=!1}}},y=()=>{g().catch(()=>{})};y();const _=setInterval(y,WT);return()=>{f=!1,clearInterval(_)}},[t,e,JSON.stringify(n)]),l.jsxs("div",{className:"nc-vl-events",children:[a&&l.jsx("div",{className:"nc-set-hint nc-vl-events-stale",children:m("vl-events-stale")}),i.length===0&&!a&&l.jsx("small",{className:"nc-set-hint","data-testid":"vl-events-empty",children:m("vl-events-empty")}),i.length>0&&l.jsx("ol",{className:"nc-vl-events-list",children:i.map(f=>l.jsx("li",{"data-testid":`vl-ev-${f.seq}`,className:`nc-vl-ev nc-vl-ev-${f.kind}${f.isError?" error":""}${f.kind==="gap"?" gap":""}`,children:qT(f)},`${f.seq}-${f.kind}`))})]})}function t0({peer:t,token:e,onBack:n}){var i;return ui(),t?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:m("back"),children:[l.jsx(ht,{name:"chevronLeft",size:18}),l.jsx("span",{className:"nc-bar-label",children:m("back")})]}),l.jsxs("span",{className:"nc-bar-center",children:[l.jsx("b",{title:t.label,children:t.label}),((i=t.session)==null?void 0:i.profile)&&l.jsxs("small",{className:"nc-bar-sub",children:[t.session.profile," · ",m("vl-events-title")]})]}),l.jsx("span",{className:"nc-bar-right"})]}),l.jsx("div",{className:"nc-vl-session-body",children:l.jsx(KT,{token:e,nodeId:t.nodeId,route:t.route||[]})})]}):null}const np=t=>Bi(ls(t)).length===0,ip=t=>Array.isArray(t)?t.join("/"):"";function VT(t){const e=new Set,n=[];for(const i of Array.isArray(t)?t:[])!i||!Ei.test(String(i.instanceId||""))||!Array.isArray(i.route)||!i.route.length||e.has(i.instanceId)||(e.add(i.instanceId),n.push({instanceId:i.instanceId,route:[...i.route],label:String(i.label||i.name||i.route.join(" › ")),status:i.status||"offline",stale:i.stale===!0}));return n.sort((i,s)=>i.label.localeCompare(s.label))}function pl(t){return{instanceId:t.ownerId,route:t.ownerRoute||[],label:t.ownerLabel,status:t.available===!1?"offline":"up"}}function io(t,e,n,i=!1,s=!0){const a=e.instanceId;return{...t,id:po(i?null:a,t.name),ownerId:a,ownerRoute:i?[]:[...e.route],ownerLabel:i?"Local":e.label,local:i,available:s,ownerTopology:Array.isArray(n)?n:[],layout:dm(t.layout,a,n)}}function YT(t,e,n,i,s=[]){const[a,c]=k.useState([]),[d,h]=k.useState(!1),[f,g]=k.useState("idle"),[y,_]=k.useState(""),[w,S]=k.useState(!1),[N,C]=k.useState(""),E=k.useRef([]),x=k.useRef([]),M=k.useRef(""),T=k.useRef(e),U=k.useRef(n),z=k.useRef(!1),K=k.useRef(!0),Q=k.useRef(""),q=k.useMemo(()=>VT(s),[s]),G=q.map(ue=>`${ue.instanceId}:${ip(ue.route)}:${ue.status}:${ue.label}`).join("|");x.current=q,U.current=n,T.current=e,E.current=a;const H=k.useCallback(ue=>hm(ue.layout,M.current,x.current),[]),P=k.useCallback(()=>hl(T.current,M.current),[]),L=k.useCallback(ue=>(Array.isArray(ue)?ue:[]).find(ne=>ne.id===P()),[P]),I=k.useCallback((ue,ne=!0,J)=>{const ce=J===void 0?P():hl(J,M.current),Ce=sb(ue,cu()),Be=E.current.some(ye=>ye.id===ce);E.current=Ce,c(Ce);const de=Ce.find(ye=>ye.id===ce);if(ne&&de){K.current=!0;const ye=H(de);i(ye),de.local&&ij(de.name,ls(ye))}else Be&&!de&&(K.current=!0,i(sa()),_("deck non più condiviso dal nodo owner"));ZM(Ce.filter(ye=>ye.local).map(ye=>ye.name))},[i,H]),D=k.useCallback(async ue=>{let ne=await Xc(t);const J=ne.decks.find(ce=>ce.name==="main");if(ne.decks.length===1&&J&&J.revision===0&&np(J.layout)){const ce=JM(),Ce=ls(fm("main")||sa());if(!np(Ce)){const Be=dm(Ce,ue,[]);ne.decks[0]=await Qc(t,"main",Be,0,[])}for(const Be of ce.filter(de=>de!=="main"))try{let de=await Q_(t,Be,[]);const ye=ls(fm(Be)||sa());np(ye)||(de=await Qc(t,Be,dm(ye,ue,[]),de.revision,[]))}catch{}ne=await Xc(t)}return ne},[t]),O=k.useCallback(async({migrate:ue=!1}={})=>{const ne=await km(t,[]),J=Ei.test(String(ne.instanceId||""))?ne.instanceId:"";if(!J)throw new Error("instanceId locale non disponibile");M.current=J,C(J);const[ce,Ce]=await Promise.all([ue?D(J):Xc(t),Y_(t,[]).catch(()=>({nodes:[]}))]),Be={instanceId:J,route:[],label:"Local"},de=ce.decks.map(we=>io(we,Be,Ce.nodes,!0,!0)),ye=E.current;return await Promise.all(x.current.map(async we=>{if(we.status!=="up"){de.push(...ye.filter(Ue=>!Ue.local&&Ue.ownerId===we.instanceId).map(Ue=>({...Ue,ownerRoute:[...we.route],ownerLabel:we.label,available:!1})));return}try{const[Ue,mt]=await Promise.all([Xc(t,we.route),Y_(t,we.route).catch(()=>({nodes:[]}))]);de.push(...Ue.decks.map(gt=>io(gt,we,mt.nodes,!1,!0)))}catch{de.push(...ye.filter(mt=>!mt.local&&mt.ownerId===we.instanceId).map(mt=>({...mt,ownerRoute:[...we.route],ownerLabel:we.label,available:!1})))}})),de.sort((we,Ue)=>we.local===Ue.local?we.ownerLabel.localeCompare(Ue.ownerLabel)||(we.name==="main"?-1:Ue.name==="main"?1:we.name.localeCompare(Ue.name)):we.local?-1:1),de},[t,D,G]);k.useEffect(()=>{if(!t)return;let ue=!1;const ne=Q.current!==t;return Q.current=t,O({migrate:ne}).then(J=>{if(ue)return;const ce=L(E.current),Ce=L(J),Be=Ce&&(!ce||Ce.revision>ce.revision||ce.available!==Ce.available||ip(ce.ownerRoute)!==ip(Ce.ownerRoute));I(J,ne||!!Be&&!z.current),h(!0),Ce&&_("")}).catch(J=>{ue||(h(!0),_(String(J.message||J)))}),()=>{ue=!0}},[I,O,G,t,L]);const R=k.useCallback(async(ue,ne=!0)=>{if(!d||!z.current)return!0;const J=ue===void 0?P():hl(ue,M.current),ce=E.current.find(Ce=>Ce.id===J);if(!ce)return _(`deck inesistente: ${J}`),!1;if(ce.available===!1)return _(`nodo owner offline: ${ce.ownerLabel}`),!1;g("saving");try{const Ce=Nf(ls(U.current),ce.ownerId,ce.ownerTopology),Be=await Qc(t,ce.name,Ce,ce.revision,ce.ownerRoute),de=io(Be,pl(ce),ce.ownerTopology,ce.local,!0);return I(E.current.map(ye=>ye.id===J?de:ye),!1),z.current=!1,g("saved"),_(""),S(!1),setTimeout(()=>g("idle"),1500),!0}catch(Ce){if(ne&&Ce.status===409&&Ce.data&&Ce.data.current){const Be=E.current.find(de=>de.id===J);if(Be){const de=io(Ce.data.current,pl(Be),Be.ownerTopology,Be.local,!0);return I(E.current.map(ye=>ye.id===J?de:ye),!1),z.current=!0,R(J,!1)}}return g("error"),_(String(Ce.message||Ce)),Ce.status===409&&S(!0),!1}},[d,t,I]),A=k.useCallback(async()=>{try{const ue=await O();z.current=!1,S(!1),I(ue,!0),_("")}catch(ue){_(String(ue.message||ue))}},[O,I]);k.useEffect(()=>{if(!d)return;const ue=K.current&&!z.current;if(K.current=!1,ue)return;z.current=!0,g("saving");const ne=setTimeout(R,650);return()=>clearTimeout(ne)},[n,d,R]),k.useEffect(()=>{if(!d)return;const ue=()=>{if(!z.current)return;const ne=E.current.find(ce=>ce.id===P());if(!ne||ne.available===!1)return;const J=Nf(ls(U.current),ne.ownerId,ne.ownerTopology);p2(t,ne.name,J,ne.revision,ne.ownerRoute)};return window.addEventListener("pagehide",ue),window.addEventListener("beforeunload",ue),()=>{window.removeEventListener("pagehide",ue),window.removeEventListener("beforeunload",ue)}},[d,t,P]),k.useEffect(()=>{if(!d)return;const ue=setInterval(async()=>{try{const ne=await O(),J=L(E.current),ce=L(ne),Ce=!!(ce&&J&&ce.revision>J.revision),Be=!!(ce&&(!J||Ce||J.available!==ce.available));if(Ce&&z.current&&ce){const de=s5(H(ce),U.current);I(ne,!1),i(de);return}I(ne,Be&&!z.current)}catch{}},5e3);return()=>clearInterval(ue)},[d,O,I,H,i]);const j=k.useCallback(ue=>{i(ne=>{const J=ue(ne);return J!==ne&&(K.current=!0),J})},[]);return{decks:a,records:a,localNodeId:N,ready:d,saveState:f,error:y,setError:_,conflict:w,reloadCurrent:A,saveNow:R,select:async ue=>{if(z.current&&!await R(P()))throw new Error("salvataggio del deck corrente fallito: cambio annullato");const ne=E.current.find(J=>J.id===ue);if(!ne)throw new Error(`deck inesistente: ${ue}`);return z.current=!1,K.current=!0,H(ne)},add:async(ue,ne=null)=>{const J=ne===Cs?E.current.find(Be=>Be.local):ne?E.current.find(Be=>Be.ownerId===ne):null;if(!J||J.available===!1)throw new Error("nodo owner non disponibile");const ce=await Q_(t,ue,J.ownerRoute),Ce=io(ce,pl(J),J.ownerTopology,J.local,!0);return I([...E.current,Ce],!1),Ce},rename:async(ue,ne)=>{const J=E.current.find(ye=>ye.id===ue);if(!J)throw new Error("deck inesistente");if(hl(ue,M.current)===P()&&z.current&&!await R(ue))throw new Error(`salvataggio di "${J.name}" fallito: rinomina annullata`);const ce=E.current.find(ye=>ye.id===ue);if(!ce)throw new Error("deck inesistente");const Ce=await m2(t,ce.name,ne,ce.revision,ce.ownerRoute),Be=io(Ce,pl(ce),ce.ownerTopology,ce.local,!0),de=ce.local?Cs:ce.ownerId;return Rf(tj(cu(),de,ue,Be.id)),I(E.current.map(ye=>ye.id===ue?Be:ye),!1),Be},remove:async ue=>{const ne=E.current.find(ce=>ce.id===ue);if(!ne)throw new Error("deck inesistente");hl(ue,M.current)===P()&&(z.current=!1),await g2(t,ne.name,ne.revision,ne.ownerRoute);const J=ne.local?Cs:ne.ownerId;Rf(nj(cu(),J,ue)),I(E.current.filter(ce=>ce.id!==ue),!1)},reorder:(ue,ne)=>{const J=E.current.find(we=>we.id===ue),ce=E.current.find(we=>we.id===ne);if(!J||!ce)return!1;const Ce=J.local?Cs:J.ownerId,Be=ce.local?Cs:ce.ownerId;if(Ce!==Be)return!1;const de=E.current.filter(we=>(we.local?Cs:we.ownerId)===Ce).map(we=>we.id),ye=Rf(ej(cu(),Ce,ue,ne,de));return I(sb(E.current,ye),!1),!0},addTileTo:async(ue,ne)=>{const J=E.current.find(we=>we.id===ue);if(!J)throw new Error("deck inesistente");if(J.available===!1)throw new Error(`nodo owner offline: ${J.ownerLabel}`);const ce=W1(ne,M.current,x.current);if(!ce)throw new Error("riferimento sessione non valido");const Ce=H(J),Be=Nf(J0(Ce,ce),J.ownerId,J.ownerTopology),de=await Qc(t,J.name,Be,J.revision,J.ownerRoute),ye=io(de,pl(J),J.ownerTopology,J.local,!0);return I(E.current.map(we=>we.id===ue?ye:we),!1),ye},viewUpdate:j,localMainId:po(null,"main"),parseDeckId:ql}}const GT="/sw.js",vm="nc-sw-update";let Ol=null,Gu=!1,Xu=null,Mx=Object.freeze({needed:!1,kind:null,version:"",browserVersion:""}),jx=!1;function yg(){typeof window<"u"&&window.dispatchEvent(new Event(vm))}function wg(){const t=Xu||(Gu?{kind:"reload",version:"",browserVersion:""}:null);Mx=Object.freeze({needed:!!t,kind:(t==null?void 0:t.kind)||null,version:(t==null?void 0:t.version)||"",browserVersion:(t==null?void 0:t.browserVersion)||""})}function n0(){return Mx}function XT(t){return typeof window>"u"?()=>{}:(window.addEventListener(vm,t),()=>window.removeEventListener(vm,t))}function bg(t){Gu!==t&&(Gu=t,wg(),yg())}const mu="nc-auto-reload",Qu="nc-reload";function Sg(){try{return typeof location<"u"?location:null}catch{return null}}function Px(){try{return typeof history<"u"?history:null}catch{return null}}function QT(t){const e=t===void 0?Sg():t;if(!e||typeof e.search!="string")return null;try{return new URLSearchParams(e.search).get(Qu)}catch{return null}}function JT(t,{location:e,history:n}={}){const i=e===void 0?Sg():e,s=n===void 0?Px():n;if(!i||!s||typeof s.replaceState!="function")return!1;try{const a=new URLSearchParams(i.search||"");return a.set(Qu,t),s.replaceState(s.state??null,"",`${i.pathname||"/"}?${a.toString()}${i.hash||""}`),!0}catch{return!1}}function ZT({location:t,history:e}={}){const n=t===void 0?Sg():t,i=e===void 0?Px():e;if(!n||!i||typeof i.replaceState!="function")return!1;try{const s=new URLSearchParams(n.search||"");if(!s.has(Qu))return!1;s.delete(Qu);const a=s.toString();return i.replaceState(i.state??null,"",`${n.pathname||"/"}${a?`?${a}`:""}${n.hash||""}`),!0}catch{return!1}}const Tx="nc-update-dismissed";function Ix(){try{return typeof sessionStorage<"u"?sessionStorage:null}catch{return null}}function e3(t,e,n){return[t,e,n].map(i=>i||"").join("|")}let _m=null;function t3(t,e,n){const i=n;return t&&e&&t!==e&&t!==i?{kind:"install",version:t,browserVersion:i}:e&&i&&e!==i?{kind:"stale",version:e,browserVersion:i}:null}function n3(t,e){if(!t)return!1;try{return t.getItem(Tx)===e}catch{return!1}}function i3(t={}){const e=t.storage===void 0?Ix():t.storage;if(_m&&e)try{e.setItem(Tx,_m)}catch{}Gu=!1,Xu=null,wg(),yg()}function s3(t,e,n,i={}){const s=i.storage===void 0?Ix():i.storage,a=n,c=e3(t,e,a);_m=c;const d=t3(t,e,a);let h=n3(s,c)?null:d;if(h&&h.kind==="stale"){const g=`${e}|${a}`,y=QT(i.location)===g;let _=!1;if(!y&&s&&s.getItem(mu)!==g){try{s.setItem(mu,g)}catch{}_=s.getItem(mu)===g}_&&(JT(g,{location:i.location,history:i.history}),(i.applyImpl||Dx)(),h=null)}const f=JSON.stringify(h)===JSON.stringify(Xu);if(Xu=h,wg(),f||yg(),!d){try{s&&s.removeItem(mu)}catch{}ZT({location:i.location,history:i.history})}}const r3=1200;async function i0(t){if(typeof fetch=="function")try{await Promise.race([fetch(t,{cache:"reload"}),new Promise(e=>setTimeout(e,r3))])}catch{}}async function Dx(){try{Ol&&await Ol.update()}catch{}typeof location<"u"&&(await i0(location.pathname),await i0("/version.json"),location.reload())}function o3(t){t.addEventListener("statechange",()=>{t.state==="installed"&&navigator.serviceWorker.controller&&bg(!0)})}function a3(){typeof navigator>"u"||!("serviceWorker"in navigator)||(navigator.serviceWorker.addEventListener("controllerchange",()=>{jx&&location.reload()}),navigator.serviceWorker.register(GT).then(t=>{Ol=t,t.waiting&&bg(!0),t.addEventListener("updatefound",()=>{const e=t.installing;e&&o3(e)}),setInterval(()=>{t.update().catch(()=>{})},3600*1e3)}).catch(()=>{}))}function l3(){jx=!0,bg(!1);const t=Ol&&Ol.waiting;t?(t.postMessage({type:"SKIP_WAITING"}),setTimeout(()=>location.reload(),4e3)):location.reload()}function c3({hash:t="",origin:e="",pathname:n="",search:i=""}={}){const s=String(t||"").replace(/^#/,""),a=`${n||""}${i||""}`;if(!s)return{token:"",pair:"",nextUrl:a};const c=new URLSearchParams(s),d=c.get("token")||"",h=c.get("pair")||"",f=h?`${e||""}${n||""}#pair=${h}`:"";return{token:d,pair:f,nextUrl:a}}const Bx=9,Ox=24,$x="nc_side_w",s0="nc_side_min",u3=240,r0=new Set(["absent","present","active","unknown"]);function d3(){const t=Number(localStorage.getItem($x));return t>=180&&t<=480?t:u3}function h3(){const t=Number(localStorage.getItem("nc_fontsize"));return t>=Bx&&t<=Ox?t:13}function f3(){const t={token:"",pair:""};try{const{token:e,pair:n,nextUrl:i}=c3({hash:location.hash,origin:location.origin,pathname:location.pathname,search:location.search});if(e){t.token=e;try{localStorage.setItem("nc_token",e)}catch{}}if(n){t.pair=n;try{sessionStorage.setItem("nc_pair",n)}catch{}}if(location.hash)try{history.replaceState(null,"",i)}catch{}}catch{}if(t.token||(t.token=sessionStorage.getItem("nc_token")||localStorage.getItem("nc_token")||""),!t.pair){const e=sessionStorage.getItem("nc_pair");e&&(t.pair=e)}return t}function o0(t){try{return ls(fm(t))}catch{return sa()}}function a0(t){if(!t)return"";const e=Math.floor(Date.now()/1e3)-t;return e<0||e<60?"ora":e<3600?`${Math.floor(e/60)}m`:e<86400?`${Math.floor(e/3600)}h`:`${Math.floor(e/86400)}g`}function l0({session:t,node:e,ownerId:n,cellName:i,token:s,readonly:a=!1,panelPort:c=0,onBack:d,onCellSwitcher:h,cellSwitcherOpen:f=!1,liveHost:g=null}){ui();const[y]=eg(),[_,w]=k.useState(!1),[S,N]=k.useState(()=>window.matchMedia("(pointer: coarse)").matches),[C,E]=k.useState(null),[x,M]=k.useState(h3),[T,U]=k.useState(kl),[z,K]=k.useState(()=>kl()),Q=()=>{const ce=_A(yA(kl()));U(ce),typeof window<"u"&&window.location.reload()},[q,G]=k.useState(i||t),[H,P]=k.useState(""),[L,I]=k.useState(""),[D,O]=k.useState(""),[R,A]=k.useState(!1),j=ce=>M(Ce=>{const Be=Math.max(Bx,Math.min(Ox,Ce+ce));return localStorage.setItem("nc_fontsize",String(Be)),Be}),F=k.useRef(()=>{}),$=k.useRef(()=>!1),W=k.useRef(()=>{}),le=k.useRef(!1),[ve,ie]=k.useState(!1),[ue,ne]=k.useState(!1),J=()=>{le.current=!le.current,ie(le.current)};return k.useEffect(()=>{G(i||t),A(!1)},[i,t]),k.useEffect(()=>{let ce=!0;const Ce=e?e.split("/"):[],Be=e?`/api/route/${e.split("/").map(encodeURIComponent).join("/")}/_`:"/api";async function de(){let we=null,Ue=null;try{const st=await(await cn(`${Be}/sessions`,s)).json();Array.isArray(st.sessions)&&(we=st.sessions.find(vt=>vt.name===t))}catch{}try{const gt=await Dr(s,Ce);gt.available&&Array.isArray(gt.cells)&&(Ue=gt.cells.find(st=>st.tmuxSession===t))}catch{}if(!ce)return;G(tg({session:t,cell:Ue||(i?{cell:i}:null)})),I(typeof(Ue==null?void 0:Ue.panelUrl)=="string"?Ue.panelUrl.trim():""),O(typeof(Ue==null?void 0:Ue.cell)=="string"?Ue.cell:"");let mt="";Ue?mt=`${Ue.engine}${Ue.key?`·${Ue.key}`:""}`:we&&(mt=we.attached?`attached · ${a0(we.activity)}`:we.activity?a0(we.activity):""),P(mt)}de();const ye=setInterval(de,4e3);return()=>{ce=!1,clearInterval(ye)}},[t,e,s]),l.jsxs("div",{className:"nc-app",children:[l.jsxs("header",{className:"nc-bar nc-bar-single",children:[l.jsxs("button",{onClick:d,title:m("sessions"),children:[l.jsx(ht,{name:"chevronLeft",size:18}),l.jsx("span",{className:"nc-bar-label",children:m("sessions")})]}),l.jsxs("span",{className:"nc-bar-center",children:[l.jsx("b",{title:e?`${q} · ${e}`:q,children:q}),g&&g.cell&&g.cell===i?l.jsx("span",{className:`nc-live-host-dot ${j1(g)} nc-live-host-dot-header`,"data-testid":"live-host-header-dot",title:m("live-host-indicator").replace("{cell}",g.cell).replace("{mode}",m(g.mode?`live-host-mode-${g.mode}`:"live-host-mode-unknown")).replace("{state}",m(`live-host-state-${g.state}`))}):null,H&&l.jsx("small",{className:"nc-bar-sub",children:H})]}),l.jsxs("span",{className:"nc-bar-right",children:[l.jsx("button",{onClick:()=>j(-1),title:m("zoom-out"),children:l.jsx(ht,{name:"zoomOut",size:18})}),l.jsx("button",{onClick:()=>j(1),title:m("zoom-in"),children:l.jsx(ht,{name:"zoomIn",size:18})}),l.jsx("button",{type:"button",className:`nc-renderer-toggle${z==="webgl"?" on":""}`,onClick:Q,"aria-pressed":z==="webgl",title:m("terminal-renderer-switch").replace("{requested}",m(T==="dom"?"terminal-renderer-dom":"terminal-renderer-webgl")).replace("{effective}",m(z==="dom"?"terminal-renderer-dom":"terminal-renderer-webgl")),"aria-label":m("terminal-renderer-switch").replace("{requested}",m(T==="dom"?"terminal-renderer-dom":"terminal-renderer-webgl")).replace("{effective}",m(z==="dom"?"terminal-renderer-dom":"terminal-renderer-webgl")),children:l.jsx(ht,{name:"gpu",size:18})}),l.jsx("button",{onClick:()=>N(ce=>!ce),title:m("composer"),children:l.jsx(ht,{name:"keyboard",size:20})}),l.jsx("button",{onClick:()=>w(ce=>!ce),title:m("files"),children:l.jsx(ht,{name:"folder",size:20})}),L&&l.jsx("button",{onClick:()=>A(ce=>!ce),title:m("panel"),"aria-pressed":R,children:l.jsx(ht,{name:"monitor",size:20})})]})]}),l.jsxs("div",{className:"nc-termwrap",children:[l.jsx(Ym,{session:t,node:e,token:s,readonly:a,takeSize:!0,sendRef:F,composerRef:$,actionRef:W,ctrlRef:le,setCtrlArmed:ie,onFiles:E,fontSize:x,selectionMode:ue,onSelectionModeChange:ne,keyboardGesture:y.terminalKeyboardGesture,onRendererChange:K}),R&&L&&D&&l.jsx(Qm,{cellId:D,panelUrl:L,route:e?e.split("/"):[],panelPort:c,token:s,title:q})]}),l.jsx(lM,{onKeyboard:()=>N(ce=>!ce),onCellSwitcher:h,cellSwitcherOpen:f,send:ce=>F.current(ce),action:ce=>W.current(ce),ctrlArmed:ve,onCtrl:J,selectionMode:ue,onSelectionMode:ne,keepKeyboardClosed:y.keybarKeepsKeyboardClosed,showEnter:y.showKeybarEnter,keybarLayout:y.keybarLayout}),S&&l.jsx(M1,{submitText:ce=>$.current(ce),token:s,session:t,node:e,ownerId:n,readonly:a,keepKeyboardClosedOnVoice:y.voiceKeepsKeyboardClosed}),_&&l.jsx(S1,{session:t,node:e,token:s,filesEvent:C,onClose:()=>w(!1)})]})}function p3(){ui();const[t]=k.useState(f3),[e,n]=k.useState(t.token),[i,s]=k.useState(t.pair||""),a=k.useCallback(()=>{s("");try{sessionStorage.removeItem("nc_pair")}catch{}},[]),[c,d]=k.useState(!1),h=zA(),[f]=k.useState(()=>QM(typeof location<"u"?location.pathname:"/")),[g,y]=k.useState(f.id),_=g===po(null,Oi),[w,S]=k.useState(null),N=me=>{const Ee=Zs(me);S(Ee?{...Ee,...typeof(me==null?void 0:me.cellName)=="string"&&me.cellName?{cellName:me.cellName}:{}}:null)},[C,E]=k.useState([]),[x,M]=k.useState([]),[T,U]=k.useState([]),[z,K]=k.useState(!1),[Q,q]=k.useState(null),[G,H]=k.useState(()=>f.ownerId?sa():o0(f.name)),[P,L]=k.useState(null),[I,D]=k.useState(null),O=me=>D(Zs(me)),[R,A]=k.useState(null),j=Rm(e,h),F=k.useMemo(()=>(j||[]).filter(me=>me.instanceId).map(me=>({instanceId:me.instanceId,route:me.route,label:me.label,status:me.status,stale:me.stale===!0})),[j]),$=YT(e,g,G,H,F),W=$.decks;k.useEffect(()=>{const me=new Map;for(const Ee of j||[]){const Me=(Ee.route||[Ee.name]).join("/"),Ze=new Set((Ee.sessions||[]).map(at=>at.name));for(const at of Ee.cells||[])!at.cell||!at.tmuxSession||at.cell===at.tmuxSession||Ze.has(at.cell)||me.set(`${Me}:${at.cell}`,`${Me}:${at.tmuxSession}`)}H(Ee=>Z2(Ee,me))},[j]),k.useEffect(()=>{$.localNodeId&&f.ownerId&&f.ownerId===$.localNodeId&&H(me=>me.columns.some(Ee=>Ee.tiles.length)?me:o0(f.name))},[$.localNodeId]),k.useEffect(()=>{$.localNodeId&&(KM(F),$.viewUpdate(me=>{const Ee=hm(me,$.localNodeId,F);return JSON.stringify(Ee)===JSON.stringify(me)?me:Ee}))},[F,$.localNodeId,$.viewUpdate]);const[le,ve]=k.useState(null),[ie,ue]=k.useState(null),ne=k.useRef(0),[J,ce]=k.useState(!1),[Ce,Be]=k.useState(d3),[de,ye]=k.useState(!_),[we,Ue]=k.useState(()=>_?localStorage.getItem(s0)==="1":!0),[mt,gt]=k.useState(!1),[st,vt]=k.useState("nodes"),[Et,it]=k.useState(!1),[Dt,Ut]=k.useState(""),[Bt,_t]=k.useState(!1),yt=(me="nodes",Ee=!1,Me="")=>{vt(me),it(Ee),Ut(Me),gt(!0)},[un,oe]=k.useState(!1),[et,jt]=k.useState({deviceDefault:"",localNodeId:"",localNameDefault:""}),[ae,re]=k.useState(!1),[Z,_e]=k.useState(0),[ke,rt]=k.useState({});k.useEffect(()=>{try{localStorage.setItem($x,String(Ce))}catch{}},[Ce]),k.useEffect(()=>{try{localStorage.setItem(s0,we?"1":"")}catch{}},[we]),k.useEffect(()=>{if(!e)return;let me=!1;return Promise.all([w0(e),cn("/api/config",e).then(Ee=>Ee.json())]).then(([Ee,Me])=>{me||(jt({deviceDefault:Ee.deviceName||"",localNodeId:Ee.nodeId||"",localNameDefault:Ee.localName||""}),re(!!Me.readonlyDefault),_e(Number.isInteger(Me.panelPort)?Me.panelPort:0),rt(Me.nodePanelPorts&&typeof Me.nodePanelPorts=="object"&&!Array.isArray(Me.nodePanelPorts)?Me.nodePanelPorts:{}),(Ee.firstRun===!0&&!Me.readonlyDefault||i)&&oe(!0))}).catch(()=>{}),()=>{me=!0}},[e,i]);const[ct,pt]=k.useState({}),At=k.useCallback(({route:me,hostCell:Ee,revision:Me})=>{const Ze=Di(me);pt(at=>({...at,[Ze]:{hostCell:Ee||null,hostLease:null,hostRevision:Number.isInteger(Me)?Me:(at[Ze]||{}).hostRevision||0,threadStatus:"absent"}}))},[]),Wt=me=>{const Ee=Di(me),Me=me.length?((j||[]).find(Ze=>Di(Array.isArray(Ze.route)?Ze.route:[])===Ee)||{}).cells||[]:x;return Ku({liveHost:ct[Ee]||null,cells:Me,localNodeId:$.localNodeId,ownerId:me.length?Ee:$.localNodeId})},Nt=k.useRef(j);k.useEffect(()=>{Nt.current=j},[j]);const Lt=k.useCallback(async()=>{try{const at=await(await cn("/api/sessions",e)).json();at.error||E(at.sessions||[])}catch{}let me=null,Ee=null;try{me=await Dr(e)}catch(Ze){Ee=Ze}const Me=Lm({fs:me,error:Ee});Me.kind==="data"?(M(Me.cells),U(Me.capabilities),K(!1),q(null)):Me.kind==="stale"?(K(!0),q(null)):(M([]),U([]),K(!1),q(Me.reason||""))},[e]);k.useEffect(()=>{let me=!1;const Ee=async()=>{const Ze=[[],...(Nt.current||[]).filter(Ot=>Ot.kind!=="vl"&&Ot.status==="up").map(Ot=>Array.isArray(Ot.route)&&Ot.route.length?Ot.route:[Ot.name])],at=await Promise.all(Ze.map(async Ot=>{const $t=Di(Ot);try{const sn=await ed(e,Ot);return[$t,{hostCell:sn&&typeof sn.hostCell=="string"?sn.hostCell:null,hostLease:sn&&sn.host&&typeof sn.host.lease=="string"?sn.host.lease:null,hostRevision:Number.isInteger(sn&&sn.revision)?sn.revision:0,threadStatus:sn&&r0.has(sn.threadStatus)?sn.threadStatus:"unknown"}]}catch{return[$t,{error:!0}]}}));me||pt(Ot=>{let $t=!1;const sn={...Ot};for(const $i of at){if(!$i)continue;const[fi,Ms]=$i;sn[fi]=Ms.error?{...Ot[fi]||{},threadStatus:"unknown"}:Ms,$t=!0}return $t?sn:Ot})};Ee();const Me=setInterval(Ee,4e3);return()=>{me=!0,clearInterval(Me)}},[e]),k.useEffect(()=>{if(!h)return;Lt();const me=setInterval(Lt,4e3);return()=>clearInterval(me)},[h,Lt]);const X=k.useCallback(async(me,Ee=[])=>{const Me=Di(Ee),Ze=ct[Me]&&ct[Me].hostRevision||0;try{const at=await td(e,me,Ze,Ee);return pt(Ot=>({...Ot,[Me]:{hostCell:at.hostCell||null,hostLease:at.host&&typeof at.host.lease=="string"?at.host.lease:null,hostRevision:Number.isInteger(at.revision)?at.revision:Ze,threadStatus:r0.has(at.threadStatus)?at.threadStatus:"unknown"}})),{ok:!0}}catch(at){return{ok:!1,error:at}}},[e,ct]),xe=k.useCallback(async(me,Ee=[])=>{const Me=await X(me,Ee);return Me.ok||window.alert(m(Au(Me.error))),Me.ok},[X]),ze=k.useCallback(async(me=[])=>{const Ee=Di(me),Me=ct[Ee]&&ct[Ee].hostRevision||0;try{const Ze=await nd(e,Me,me);return pt(at=>({...at,[Ee]:{hostCell:Ze.hostCell||null,hostLease:null,hostRevision:Number.isInteger(Ze.revision)?Ze.revision:Me,threadStatus:"unknown"}})),{ok:!0}}catch(Ze){return{ok:!1,error:Ze}}},[e,ct]),Ke=k.useCallback(async(me=[])=>{const Ee=await ze(me);return Ee.ok||window.alert(m(Au(Ee.error))),Ee.ok},[ze]);k.useEffect(()=>{let me=!1;const Ee=()=>{cn("/api/config",e).then(Ze=>Ze.json()).then(Ze=>{me||s3(Ze.version,Ze.uiVersion,"0.9.36")}).catch(()=>{})};Ee();const Me=setInterval(Ee,6e4);return()=>{me=!0,clearInterval(Me)}},[e]);const Qe=new Set([...C.map(me=>me.name),...j.flatMap(me=>me.sessions.map(Ee=>Ee.key))]),Pt=Bi(G),Tt=me=>H(Ee=>{const Me=W1(me,$.localNodeId,F)||me,Ze=J0(Ee,Me);return Ze===Ee&&Bi(Ee).length>=9&&$.setError(m("grid-full")),Ze}),Y=async(me,Ee=[])=>{try{await Sm(e,me,Ee)}catch{return}const Me=Ee.length?`${Ee.join("/")}:${me}`:me;H(Ze=>Du(Ze,Me)),Lt()},te=async(me,Ee,Me=[])=>{try{await y0(e,me,Ee,Me)}catch{return}Lt()},Se=async(me,Ee,Me=[])=>{await g0(e,{cell:me,enabled:!!Ee},Me),Lt()},Ye=async me=>{if(!le)return;const{cell:Ee}=le,Me=Array.isArray(le.route)?le.route:[];if(me.action==="up"){const at=await bm(e,{cell:Ee,boot:!!me.boot,...me.engine?{engine:me.engine}:{},...me.model!==void 0?{model:me.model}:{},...me.permissionPolicy?{permissionPolicy:me.permissionPolicy}:{}},Me),Ot=Tm(at);Ot&&$.setError(Ot.text)}else await Nu(e,{cell:Ee,boot:!!me.boot},Me);const Ze=me.action==="up"?!!me.boot:me.boot?!1:!!le.boot;ue({id:++ne.current,cell:Ee,route:Me,enabled:Ze}),Lt()},Oe=k.useCallback(me=>{ue(Ee=>(Ee==null?void 0:Ee.id)===me?null:Ee)},[]),Ae=async me=>{if(!(!(me!=null&&me.direct)||J)){ce(!0);try{await Em(e,me.name,me.tunnelStatus==="up"?"down":"up")}finally{ce(!1)}}},ot=async(me,Ee)=>{const Me=String(Ee||"").trim();return!(me!=null&&me.direct)||!ca(Me)?!1:(await x0(e,me.name,Me),!0)},zt=me=>{const Ee=W.find(Me=>Me.id===me);if(!Ee)return!1;try{const Me=window.open(Lf(Ee,e),"_blank");return Me&&(Me.opener=null),!!Me}catch{return!1}},nn=async me=>{if(!me||me===g)return;const Ee=await $.select(me),Me=$.records.find(Ze=>Ze.id===me);y(me),H(Ee),L(null),D(null);try{history.replaceState(null,"",Lf(Me||me,null))}catch{}},We=async(me,Ee)=>{const Me=await $.add(me,Ee);await nn(Me.id)},$e=async(me,Ee)=>{const Me=await $.rename(me,Ee);if(me===g){y(Me.id),H(hm(Me.layout,$.localNodeId,F)),L(null),D(null);try{history.replaceState(null,"",Lf(Me,null))}catch{}}},Ct=async me=>{await $.remove(me),me===g&&await nn($.localMainId)},Un=async(me,Ee)=>{!Ee||Ee===g||(await $.addTileTo(Ee,me),H(Me=>Du(Me,me)))};if(!e)return l.jsxs("div",{className:"nc-auth",children:[l.jsx("p",{children:m("auth-prompt")}),l.jsx("input",{onChange:me=>n(me.target.value.trim()),placeholder:"token"}),l.jsxs("label",{children:[l.jsx("input",{type:"checkbox",checked:c,onChange:me=>d(me.target.checked)})," ",m("remember-device")]}),l.jsx("button",{onClick:()=>{(c?localStorage:sessionStorage).setItem("nc_token",e)},children:"ok"})]});const Xn=l.jsxs(l.Fragment,{children:[mt&&l.jsx(RT,{token:e,initialTab:st,initialLocation:Dt,startNewCell:Et,onClose:()=>{gt(!1),it(!1),Ut("")}}),un&&l.jsx(AT,{token:e,initialPair:i,...et,onPairDone:a,onDone:()=>oe(!1)}),l.jsx(BT,{token:e})]});if(!h)return R?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"nc-single-overlay",children:l.jsx(t0,{peer:R,token:e,onBack:()=>A(null)})}),Xn]}):w?l.jsxs(l.Fragment,{children:[l.jsx(l0,{session:w.session,node:w.node,ownerId:w.ownerId,cellName:w.cellName,token:e,readonly:ae,liveHost:Wt(w.node?w.node.split("/"):[]),panelPort:Vu(w.node?w.node.split("/"):[],ke,Z),onBack:()=>S(null),onCellSwitcher:()=>_t(!0),cellSwitcherOpen:Bt}),Bt&&l.jsx(UT,{token:e,current:w,panelPort:Z,nodePanelPorts:ke,hostByRoute:ct,onDesignateCell:X,onClearHostCell:ze,onLiveHostApplied:At,onPick:me=>{N(me),_t(!1)},onClose:()=>_t(!1)}),Xn]}):l.jsxs(l.Fragment,{children:[l.jsx(_5,{onPick:N,token:e,onSettings:yt,onOpenVlSession:A,hostByRoute:ct,onDesignateCell:xe,onClearHostCell:Ke}),Xn]});const Cn=_||!de;return l.jsxs("div",{className:"nc-workspace",children:[Cn&&l.jsx(BM,{sessions:C,cells:x,activeSessions:Pt,nodeGroups:j,token:e,onPeekOpen:()=>_t(!1),overlayOpen:Bt,fleetCapabilities:T,fleetStale:z,fleetOff:Q,bootSettlement:ie,onBootSettlementApplied:Oe,localNodeId:$.localNodeId,hostByRoute:ct,onDesignateCell:xe,onClearHostCell:Ke,onPick:O,onAddTile:Tt,onPower:ve,onBoot:Se,onBootError:me=>$.setError(String((me==null?void 0:me.message)||me)),onNodePower:Ae,onNodeRename:ot,onKill:Y,onVisibility:te,onNew:()=>yt("fleet",!0),onSettings:yt,onOpenVlSession:A,width:Ce,collapsed:we,onResize:Be,onToggleCollapse:()=>Ue(me=>!me)}),l.jsxs("div",{className:"nc-workspace-main",children:[l.jsx(wj,{decks:W,currentDeck:g,onCreate:We,onRename:$e,onDelete:Ct,onReorder:$.reorder,onOpenWindow:zt,onNavigate:nn,saveState:$.saveState,error:$.error,conflict:$.conflict,onReloadDeck:$.reloadCurrent,sidebarVisible:Cn,onToggleSidebar:_?null:()=>ye(me=>!me)}),l.jsx(qM,{layout:G,onLayoutChange:H,onResizeEnd:()=>{$.saveNow()},token:e,readonly:ae,sessionsAlive:Qe,focusSession:P,onFocus:L,onOpenSingle:O,decks:W,currentDeck:g,onSendToDeck:Un,cells:x,nodeGroups:j,panelPort:Z,nodePanelPorts:ke})]}),R&&l.jsx("div",{className:"nc-single-overlay",children:l.jsx(t0,{peer:R,token:e,onBack:()=>A(null)})}),I&&l.jsx("div",{className:"nc-single-overlay",children:l.jsx(l0,{session:I.session,node:I.node,ownerId:I.ownerId,cellName:tg({session:I.session,node:I.node,ownerId:I.ownerId,cells:x,nodeGroups:j}),token:e,readonly:ae,liveHost:Wt(I.node?I.node.split("/"):[]),panelPort:Vu(I.node?I.node.split("/"):[],ke,Z),onBack:()=>D(null)})}),le&&l.jsx(ju,{cell:le,token:e,route:Array.isArray(le.route)?le.route:[],onConfirm:Ye,onClose:()=>ve(null)}),Xn]})}function m3(t){return t.kind==="install"?m("update-installed-restart").replace("{v}",t.version):t.kind==="stale"?m("update-stale").replace("{ui}",t.version).replace("{browser}",t.browserVersion):m("update-available").replace("{v}",t.version).replace(" "," ").trim()}function g3(){ui();const t=k.useSyncExternalStore(XT,n0,n0);return t.needed?l.jsxs("div",{className:"nc-update",role:"status","aria-live":"polite",children:[l.jsx("span",{className:"nc-update-msg",children:m3(t)}),t.kind==="stale"&&l.jsx("button",{className:"nc-update-btn",onClick:Dx,children:m("reload-no-cache")}),t.kind==="reload"&&l.jsx("button",{className:"nc-update-btn",onClick:l3,children:m("reload")}),l.jsx("button",{className:"nc-update-close",onClick:i3,"aria-label":m("update-dismiss"),title:m("update-dismiss"),children:"×"})]}):null}a3();xk.createRoot(document.getElementById("root")).render(l.jsxs(gk.StrictMode,{children:[l.jsx(p3,{}),l.jsx(g3,{})]}));
|
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-DS1VyIuo.js"></script>
|
|
15
15
|
<link rel="stylesheet" crossorigin href="/assets/index-XusWm2UG.css">
|
|
16
16
|
</head>
|
|
17
17
|
<body>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.9.
|
|
1
|
+
{"version":"0.9.36"}
|
package/lib/fleet/builtin.js
CHANGED
|
@@ -72,6 +72,24 @@ function draftFrom(defs) {
|
|
|
72
72
|
...(Array.isArray(defs.models) && defs.models.length
|
|
73
73
|
? { models: defs.models.map((m) => ({ ...m })) }
|
|
74
74
|
: {}),
|
|
75
|
+
// Gli capabilityProfiles dichiarati vanno RIPORTATI come i models: la
|
|
76
|
+
// bozza e' la base di ogni scrittura, e una chiave non copiata o sparisce
|
|
77
|
+
// (nessun riferimento) o rende il file non scrivibile (una cella che
|
|
78
|
+
// riferisce un profilo non piu' dichiarato). Copia profonda: per ogni
|
|
79
|
+
// profilo, per ogni chiave array, array copiato.
|
|
80
|
+
...(defs.capabilityProfiles && Object.keys(defs.capabilityProfiles).length
|
|
81
|
+
? {
|
|
82
|
+
capabilityProfiles: Object.fromEntries(Object.entries(defs.capabilityProfiles).map(([nome, profilo]) => [
|
|
83
|
+
nome,
|
|
84
|
+
{
|
|
85
|
+
...profilo,
|
|
86
|
+
...(Array.isArray(profilo.mcp) ? { mcp: [...profilo.mcp] } : {}),
|
|
87
|
+
...(Array.isArray(profilo.skills) ? { skills: [...profilo.skills] } : {}),
|
|
88
|
+
...(Array.isArray(profilo.ondemand) ? { ondemand: [...profilo.ondemand] } : {}),
|
|
89
|
+
},
|
|
90
|
+
])),
|
|
91
|
+
}
|
|
92
|
+
: {}),
|
|
75
93
|
engines: defs.engines.map((e) => ({
|
|
76
94
|
...e,
|
|
77
95
|
...(e.managed ? { managed: { ...e.managed } } : {}),
|
|
@@ -1433,6 +1451,12 @@ async function createBuiltinFleet(cfg = {}) {
|
|
|
1433
1451
|
// vuoto — si poteva dichiarare un modello e non vederlo mai, ne' ritirarlo.
|
|
1434
1452
|
// I test CRUD non se ne accorgevano perche' leggevano fleet.json diretto.
|
|
1435
1453
|
...(Array.isArray(defs.models) && defs.models.length ? { models: defs.models } : {}),
|
|
1454
|
+
// I capabilityProfiles dichiarati escono dalla VISTA come dal file: la
|
|
1455
|
+
// finestra li legge da qui per vederli e ritirarli, e la API li conferma
|
|
1456
|
+
// senza rileggere fleet.json.
|
|
1457
|
+
...(defs.capabilityProfiles && Object.keys(defs.capabilityProfiles).length
|
|
1458
|
+
? { capabilityProfiles: defs.capabilityProfiles }
|
|
1459
|
+
: {}),
|
|
1436
1460
|
managedCatalog,
|
|
1437
1461
|
// I NOMI dei server MCP disponibili, per la finestra che sceglie quali
|
|
1438
1462
|
// strumenti dare a una cella. Solo nomi: le definizioni non escono di qui,
|