local-operator-ui 0.57.4 → 0.57.5
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/out/main/index.js +375 -46
- package/out/preload/index.js +46 -20
- package/out/renderer/assets/{_basePickBy-CqOK9I5a.js → _basePickBy-D2upKftS.js} +1 -1
- package/out/renderer/assets/{_baseUniq-Dfknltze.js → _baseUniq-BGD19KIN.js} +1 -1
- package/out/renderer/assets/{agent-details-page-DKOAeAlz.js → agent-details-page-OPyFw_dI.js} +1 -1
- package/out/renderer/assets/{agent-hub-page-D75ZCD-T.js → agent-hub-page-B3V1y16n.js} +1 -1
- package/out/renderer/assets/{agents-page-Dy9dT2J6.js → agents-page-CowgZsSO.js} +3 -3
- package/out/renderer/assets/appearance-DO4VPBSi.js +65 -0
- package/out/renderer/assets/{approvalsOverlay-BxwEca1y.js → approvalsOverlay-CBPXn0ct.js} +1 -1
- package/out/renderer/assets/{arc-CJgGs8E0.js → arc-Cv6N9gTJ.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-IEHRJDOE-BO-PVfmy.js → architectureDiagram-IEHRJDOE-DHtB5fE0.js} +1 -1
- package/out/renderer/assets/{avatar-cropper-IPFrNOZH.js → avatar-cropper-Bjo9zUPg.js} +1 -1
- package/out/renderer/assets/{blockDiagram-JOT3LUYC-D4kISdJw.js → blockDiagram-JOT3LUYC-4WEK73Je.js} +1 -1
- package/out/renderer/assets/{book-open-DSEz_hQQ.js → book-open-CmfjhXrg.js} +1 -1
- package/out/renderer/assets/browser-page-2S7sbehs.js +1 -0
- package/out/renderer/assets/{browser-webauthn-prompt-DUTEBHSl.js → browser-webauthn-prompt-D8Tgtg83.js} +1 -1
- package/out/renderer/assets/{c4Diagram-VJAJSXHY-jrrji_Tt.js → c4Diagram-VJAJSXHY-kaGHtOK6.js} +1 -1
- package/out/renderer/assets/channel-DRHru1K8.js +1 -0
- package/out/renderer/assets/{chunk-4BMEZGHF-34jCJWgL.js → chunk-4BMEZGHF-CpC8J2AT.js} +1 -1
- package/out/renderer/assets/{chunk-A2AXSNBT-D2utPfjC.js → chunk-A2AXSNBT-DKmX4atq.js} +1 -1
- package/out/renderer/assets/{chunk-AEK57VVT-Chv6UTYK.js → chunk-AEK57VVT-Dtej3BD4.js} +1 -1
- package/out/renderer/assets/{chunk-D6G4REZN-8au1oDUE.js → chunk-D6G4REZN-DUXxF-pw.js} +1 -1
- package/out/renderer/assets/{chunk-RZ5BOZE2-DCRrSym3.js → chunk-RZ5BOZE2-DeeJjU3w.js} +1 -1
- package/out/renderer/assets/{chunk-XZIHB7SX-BFp6lbut.js → chunk-XZIHB7SX-D4R6kzHb.js} +1 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-Cs0VSRpc.js +1 -0
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-Cs0VSRpc.js +1 -0
- package/out/renderer/assets/clone-_NlCUljT.js +1 -0
- package/out/renderer/assets/{console-mirror-COvJr604.js → console-mirror-Bp3thuUi.js} +1 -1
- package/out/renderer/assets/{consoleCapture-Cl0JWwqq.js → consoleCapture-BJR8BDEY.js} +1 -1
- package/out/renderer/assets/{conversation-input-sync-bGjigx3Z.js → conversation-input-sync-FnnZiNnd.js} +4 -4
- package/out/renderer/assets/{dagre-OKDRZEBW-WWu0Yua1.js → dagre-OKDRZEBW-DDY_IkmM.js} +1 -1
- package/out/renderer/assets/{diagram-SSKATNLV-CS9Mvsr2.js → diagram-SSKATNLV-D7AGoSSj.js} +1 -1
- package/out/renderer/assets/{diagram-VNBRO52H-qqdP8fjP.js → diagram-VNBRO52H-CcgAGaBN.js} +1 -1
- package/out/renderer/assets/{erDiagram-Q7BY3M3F-Dcxo6XZi.js → erDiagram-Q7BY3M3F-LEYxek3-.js} +1 -1
- package/out/renderer/assets/{error-boundary-BQ911DnY.js → error-boundary-BsWceBKP.js} +1 -1
- package/out/renderer/assets/{flowDiagram-4HSFHLVR-CrxBDmsr.js → flowDiagram-4HSFHLVR-CQLUaH8T.js} +1 -1
- package/out/renderer/assets/{ganttDiagram-APWFNJXF-Bx-sfLxO.js → ganttDiagram-APWFNJXF-Ole27PT-.js} +1 -1
- package/out/renderer/assets/{gitGraphDiagram-7IBYFJ6S-CJxWCbNe.js → gitGraphDiagram-7IBYFJ6S-BNYa___9.js} +1 -1
- package/out/renderer/assets/{graph-BNSj1GHJ.js → graph-Bibb0aeq.js} +1 -1
- package/out/renderer/assets/{heart-i91yzAwW.js → heart-Cix0tXFr.js} +1 -1
- package/out/renderer/assets/index-BKLUTBo0.css +1 -0
- package/out/renderer/assets/{index-CdTxr8VM.js → index-BKh47kLl.js} +199 -194
- package/out/renderer/assets/{index-BxFcVHbG.js → index-C9UzsV82.js} +1 -1
- package/out/renderer/assets/{index-BvbUVrcK.js → index-CMJfInon.js} +1 -1
- package/out/renderer/assets/{index-CxNjWpOb.js → index-D0qlrLIs.js} +1 -1
- package/out/renderer/assets/infoDiagram-PH2N3AL5-BXhry1Gr.js +2 -0
- package/out/renderer/assets/{inline-error-boundary-CEz9_z6I.js → inline-error-boundary-Ba_FWBMT.js} +1 -1
- package/out/renderer/assets/{installer-G-5Vi1J-.js → installer-bmE_RNOZ.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-U35MCT3I-DoNy_9X6.js → journeyDiagram-U35MCT3I-DI32aDKT.js} +1 -1
- package/out/renderer/assets/{kanban-definition-NDS4AKOZ-DdvklVql.js → kanban-definition-NDS4AKOZ-CZ-ELIdr.js} +1 -1
- package/out/renderer/assets/{layout-qfLIC44U.js → layout-Dza9PMRJ.js} +1 -1
- package/out/renderer/assets/{legacy-agents-page-vNWqLnJO.js → legacy-agents-page-CPFGYWOZ.js} +1 -1
- package/out/renderer/assets/{library-page-CsKdpZoN.js → library-page-DiaLon0b.js} +3 -3
- package/out/renderer/assets/{log-in-ge87dxtE.js → log-in-Bd6fDqyJ.js} +1 -1
- package/out/renderer/assets/{mermaid.core-34ehUt9F.js → mermaid.core-BcJdc-X6.js} +5 -5
- package/out/renderer/assets/{mesh-page-Drazw6sy.js → mesh-page-7T5BtRTh.js} +1 -1
- package/out/renderer/assets/{messages-B7aIuFuF.js → messages-BYDbMAVA.js} +10 -10
- package/out/renderer/assets/{mindmap-definition-ALO5MXBD-DS9A7X_9.js → mindmap-definition-ALO5MXBD-D2CXGzTD.js} +1 -1
- package/out/renderer/assets/{mini-CiYAeR9E.js → mini-CJlFVLUZ.js} +1 -1
- package/out/renderer/assets/{notebook-pen-6_thWw32.js → notebook-pen-D05OGtSm.js} +1 -1
- package/out/renderer/assets/{notifications-page-B9lBzyI_.js → notifications-page-BjrfZb8l.js} +1 -1
- package/out/renderer/assets/{org-access-LWjiDIPH.js → org-access-B9_h9w7n.js} +1 -1
- package/out/renderer/assets/{org-surface-gate-DGeVPoHg.js → org-surface-gate-sm4xQvjq.js} +1 -1
- package/out/renderer/assets/{page-header-DsXvFR6j.js → page-header-DXwYxMB-.js} +1 -1
- package/out/renderer/assets/{pieDiagram-IB7DONF6-BzNpgGTh.js → pieDiagram-IB7DONF6-DUG4cv-v.js} +1 -1
- package/out/renderer/assets/{projects-page-BJV0JVfL.js → projects-page-DlCYJUiP.js} +1 -1
- package/out/renderer/assets/{publication-validation-BIxxMtE8.js → publication-validation-Bn7rmCS6.js} +1 -1
- package/out/renderer/assets/{quadrantDiagram-7GDLP6J5-BGFLFl2M.js → quadrantDiagram-7GDLP6J5-DaYms9_B.js} +1 -1
- package/out/renderer/assets/{radar-MK3ICKWK-QP0xpCZj.js → radar-MK3ICKWK-B97TgRmB.js} +1 -1
- package/out/renderer/assets/{radient-auth-buttons-GwvFtoOd.js → radient-auth-buttons-CEfTJcvg.js} +1 -1
- package/out/renderer/assets/{requirementDiagram-KVF5MWMF-d1hwIQYi.js → requirementDiagram-KVF5MWMF-DgyICZXf.js} +1 -1
- package/out/renderer/assets/{sankeyDiagram-QLVOVGJD-Bel2U3qO.js → sankeyDiagram-QLVOVGJD-DHgZL_Zc.js} +1 -1
- package/out/renderer/assets/{schedules-page-CJV3Oiiy.js → schedules-page-CNdkudlY.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-X6HHIX6F-Et2XMzpI.js → sequenceDiagram-X6HHIX6F-pU2H-s2W.js} +1 -1
- package/out/renderer/assets/settings-page-B9GORgXK.js +319 -0
- package/out/renderer/assets/{smartart-Csc0zQan.js → smartart-gFtvTNRW.js} +1 -1
- package/out/renderer/assets/{stateDiagram-DGXRK772-D2GwxW6w.js → stateDiagram-DGXRK772-HwW2OpHh.js} +1 -1
- package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-BwCPC1S5.js +1 -0
- package/out/renderer/assets/{team-bridge-page-CW5zV9mz.js → team-bridge-page-ChcIcnje.js} +17 -17
- package/out/renderer/assets/{timeline-definition-BDJGKUSR-BUZLWyEg.js → timeline-definition-BDJGKUSR-CPNzpTN8.js} +1 -1
- package/out/renderer/assets/{use-default-on-banner-CsqO83vJ.js → use-default-on-banner-CuXTqN3l.js} +1 -1
- package/out/renderer/assets/{use-download-agent-mutation-F8kNbCPE.js → use-download-agent-mutation-BCbr9wLe.js} +1 -1
- package/out/renderer/assets/{xychartDiagram-VJFVF3MP-C9F7-D_T.js → xychartDiagram-VJFVF3MP-TZFrKw4j.js} +1 -1
- package/out/renderer/browser-approvals-overlay.html +2 -2
- package/out/renderer/console-capture.html +6 -6
- package/out/renderer/index.html +8 -8
- package/out/renderer/installer.html +5 -5
- package/out/renderer/mini.html +7 -7
- package/package.json +1 -1
- package/out/renderer/assets/appearance-RPtl24uV.js +0 -65
- package/out/renderer/assets/browser-page-4rUf9E5f.js +0 -1
- package/out/renderer/assets/channel-DSbKlaIM.js +0 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-B3UBTKI6.js +0 -1
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-B3UBTKI6.js +0 -1
- package/out/renderer/assets/clone-CI0Pk6Pw.js +0 -1
- package/out/renderer/assets/index-BlC0KBYH.css +0 -1
- package/out/renderer/assets/infoDiagram-PH2N3AL5-PsB_DDDA.js +0 -2
- package/out/renderer/assets/settings-page-sfk5JVcx.js +0 -319
- package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-BHUZ7x6j.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as x,j as t,c as O}from"./index-CxNjWpOb.js";import{R as ft,T as vt,V as Je,W as gt,X as _t,Y as ue,Z as bt,_ as kt,$ as ge,a0 as Qe,a1 as le,a2 as et,a3 as tt,a4 as st,a as yt,g as fe,A as we,a5 as jt}from"./appearance-RPtl24uV.js";import{P as wt}from"./page-header-DsXvFR6j.js";import{u as K,B as Q,w as Nt,T as It,s as xe,D as Ct,g as St,i as At,G as Mt,H as Le,I as $e,l as Te,A as Ne}from"./error-boundary-BQ911DnY.js";import{t as s}from"./messages-B7aIuFuF.js";import{Q as ce,T as me,U as Oe,V as Rt,W as at,X as Dt,Y as Et,Z as Pt,_ as Lt,$ as $t,a0 as Tt,a1 as Ot,a2 as Ft,a3 as Fe,a4 as qe,a5 as qt,a6 as Ht,a7 as zt,a8 as Wt,a9 as Bt,aa as Vt,ab as Yt,ac as Ut,ad as Kt,ae as Gt,af as Ae,ag as Xt,ah as Zt,ai as Me,aj as nt,ak as rt,al as Jt,am as _e,an as Ie,ao as Qt,ap as es,aq as He,ar as ts,as as Ce,at as ss,au as it,av as be,aw as as,ax as lt,ay as ns,az as rs,aA as is,aB as ls,aC as os,aD as ds,aE as cs,aF as us,aG as ms,aH as ps,aI as hs,aJ as xs,aK as fs,aL as vs,aM as gs,aN as _s,aO as bs,aP as ks,aQ as ve,aR as ys,aS as js}from"./index-CdTxr8VM.js";import{bn as ke,bo as ws,bp as Re,bq as Ns,br as ye,bs as Is,bt as ot,bu as Cs}from"./conversation-input-sync-bGjigx3Z.js";import"./roles-D1pcbxAx.js";import"./console-mirror-COvJr604.js";function dt(){return{state:"unavailable",enabled:!1,label:s("ui.mesh.mesh_approvals.profile_revert"),note:s("ui.mesh.mesh_approvals.profile_revert_unavailable"),descriptor:null}}function Ss(e){return e==="agent"?s("ui.mesh.mesh_approvals.profile_kind_agent"):s("ui.mesh.mesh_approvals.profile_kind_team")}function As(e){switch(e){case"create":return s("ui.mesh.mesh_approvals.profile_operation_create");case"update":return s("ui.mesh.mesh_approvals.profile_operation_update");default:return s("ui.mesh.mesh_approvals.profile_operation_revert")}}function Ms(e,n){switch(e.state){case"requested":return{state:"waiting",note:oe("waiting")};case"approved":return{state:"approved_not_saved",note:oe("approved_not_saved")};case"connected":return{state:"saved",note:oe("saved")};case"denied":return{state:"denied",note:oe("denied")};case"expired":return{state:"expired",note:oe("expired")};case"failed":return{state:"stopped",note:oe("stopped")};default:return{state:"unknown",note:oe("unknown")}}}function Rs(e,{profileApprovals:n=!1,canApprove:a=!1,canDeny:r=!1,canRetryApply:c=!1,revert:d=null}={}){const h=e.profile?.disclosure??null,l=e.state==="requested",v=h?.profile_kind??null,b=h?ft(h):[],y=Ms(e),M=l&&!a?n?s("ui.mesh.mesh_approvals.profile_approval_unavailable"):s("ui.mesh.mesh_approvals.profile_unavailable"):null;return{kind:v,name:h?.profile_name??"",operation:h?.profile_operation??null,scope:h?.scope??null,fields:b,changesIncluded:h!==null,diffLines:[],changedFieldNames:[],state:y.state,stateNote:y.note,canApprove:a,canDeny:r,canRetryApply:c,unavailableReason:M,revert:d?Ds(d):dt()}}function Ds(e,n={}){if(!e)return dt();const a=vt({descriptor:e,descriptorVerified:!0,...n});return{state:a.state,enabled:a.enabled,label:e.label||s("ui.mesh.mesh_approvals.profile_revert"),note:Es(a.state),descriptor:e}}function Es(e){switch(e){case"available":return null;case"pending":return s("ui.mesh.mesh_approvals.profile_revert_pending");case"saved":return s("ui.mesh.mesh_approvals.profile_revert_done");case"stale":return s("ui.mesh.mesh_approvals.profile_revert_stale");case"failed":return s("ui.mesh.mesh_approvals.profile_revert_failed");case"unconfirmed":return s("ui.mesh.mesh_approvals.profile_revert_unconfirmed");default:return s("ui.mesh.mesh_approvals.profile_revert_unavailable")}}function oe(e){switch(e){case"waiting":return s("ui.mesh.mesh_approvals.profile_outcome_waiting");case"saved":return s("ui.mesh.mesh_approvals.profile_outcome_saved");case"approved_not_saved":return s("ui.mesh.mesh_approvals.profile_outcome_approved_not_saved");case"denied":return s("ui.mesh.mesh_approvals.profile_outcome_denied");case"expired":return s("ui.mesh.mesh_approvals.profile_outcome_expired");case"stopped":return s("ui.mesh.mesh_approvals.profile_outcome_stopped");default:return s("ui.mesh.mesh_approvals.profile_outcome_unknown")}}function ze(e,n){const a=n==="before"?e.before:e.after;return a.presence==="set"?a.text:a.presence==="unset"?s("ui.mesh.mesh_approvals.profile_cleared"):s("ui.mesh.mesh_approvals.profile_not_set")}function Ps({view:e,actions:n,onRevert:a,className:r}){K();const c=x.useId(),d=x.useId(),h=x.useId(),l=e.revert??null,v=!l||!l.enabled||!a,b=l?l.note??(a===void 0?s("ui.mesh.mesh_approvals.profile_revert_no_handler"):v?s("ui.mesh.mesh_approvals.profile_revert_reason_unknown"):null):null;return t.jsxs("section",{className:O("flex flex-col gap-3 rounded-md bg-sunken p-3 text-body-sm text-ink",r),"aria-labelledby":c,"data-tour-tag":"profile-consent-card","data-profile-state":e.state,"data-profile-revert":l?.state??"absent",children:[t.jsxs("header",{className:"flex flex-col gap-1",children:[t.jsxs("span",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-meta text-ink-dim",children:[e.kind&&t.jsx("span",{children:Ss(e.kind)}),e.operation&&t.jsx("span",{"data-tour-tag":"profile-consent-operation",children:As(e.operation)}),e.scope==="global"&&t.jsx("span",{children:s("ui.mesh.mesh_approvals.profile_scope_global")})]}),t.jsx("h3",{id:c,className:"font-mono text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-name",children:e.name}),e.stateNote&&t.jsx("p",{className:"text-meta text-ink-muted",children:e.stateNote})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("h4",{id:d,className:"text-meta text-ink-muted",children:s("ui.mesh.mesh_approvals.profile_changes")}),e.fields.length>0?t.jsxs("table",{className:"w-full border-collapse text-left text-meta","aria-labelledby":d,"data-tour-tag":"profile-consent-diff",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"text-ink-dim",children:[t.jsx("th",{scope:"col",className:"py-1 pr-2 font-normal",children:s("ui.mesh.mesh_approvals.profile_field")}),t.jsx("th",{scope:"col",className:"py-1 pr-2 font-normal",children:s("ui.mesh.mesh_approvals.profile_column_before")}),t.jsx("th",{scope:"col",className:"py-1 font-normal",children:s("ui.mesh.mesh_approvals.profile_column_after")})]})}),t.jsx("tbody",{children:e.fields.map(y=>t.jsxs("tr",{className:"border-hairline border-t align-top","data-profile-field":y.field,children:[t.jsx("th",{scope:"row",className:"py-1 pr-2 font-mono font-normal text-ink-muted",children:y.field}),t.jsx("td",{className:"py-1 pr-2 text-ink-dim [overflow-wrap:anywhere]",children:ze(y,"before")}),t.jsx("td",{className:"py-1 text-ink [overflow-wrap:anywhere]",children:ze(y,"after")})]},y.field))})]}):e.diffLines.length>0?t.jsx("ul",{className:"flex flex-col gap-1 text-meta text-ink [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-diff-lines",children:e.diffLines.map(y=>t.jsx("li",{children:y},y))}):e.changedFieldNames.length>0?t.jsx("p",{className:"font-mono text-meta text-ink [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-changed-fields",children:e.changedFieldNames.join(", ")}):t.jsx("p",{className:"text-meta text-ink-dim","data-tour-tag":e.changesIncluded?"profile-consent-no-changes":"profile-consent-changes-not-included",children:e.changesIncluded?s("ui.mesh.mesh_approvals.profile_changes_none"):s("ui.mesh.mesh_approvals.profile_changes_not_in_receipt")})]}),e.unavailableReason&&t.jsx("p",{className:"text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-unavailable",children:e.unavailableReason}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n,l&&t.jsxs("span",{className:"inline-flex items-center gap-2",children:[t.jsx(Q,{type:"button",variant:"ghost",size:"sm",disabled:v,"aria-describedby":b?h:void 0,onClick:a,"data-tour-tag":"profile-consent-revert",children:l.label}),b&&t.jsx("span",{id:h,className:"text-meta text-ink-dim [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-revert-note",children:b})]})]})]})}function Ls(e){return e==="failed"?"text-danger":ce(e)?"text-ink-muted":"text-ink-dim"}function $s(e){return e==="failed"?s("ui.mesh.mesh_approvals_tray.abandon"):s("ui.mesh.mesh_approvals_tray.stop")}function Ts(e){switch(e){case"requested":return[{term:s("ui.mesh.mesh_approvals_tray.signing"),text:s("ui.mesh.mesh_approvals_tray.approving_signs_with_this_machine_s_operator")}];case"approved":return[{term:s("ui.mesh.mesh_approvals_tray.next"),text:s("ui.mesh.mesh_approvals_tray.an_agent_runs_the_install_and_connect")},{term:s("ui.mesh.mesh_approvals_tray.stop"),text:s("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_nothing_has")}];case"connecting":return[{term:s("ui.mesh.mesh_approvals_tray.stop"),text:s("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_the_runner")}];case"failed":return[{term:s("ui.mesh.mesh_approvals_tray.after_a_stop"),text:s("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_abandoning")}];default:return[]}}const Os=({rows:e,error:n,pending:a,refusal:r,onDecide:c,onRetry:d,nowSeconds:h,networkNames:l,credentialApprovals:v=!1,profileApprovals:b=!1})=>{K();const y=a!==null,[M,A]=x.useState(""),u=x.useRef(null),p=r?JSON.stringify([r.approvalId,r.code,r.sentence]):null,m=x.useMemo(()=>e.filter(f=>ce(f.state)||me(f)),[e]),w=x.useMemo(()=>e.filter(f=>!ce(f.state)&&!me(f)),[e]),[S,R]=x.useState(!1),I=x.useRef(null),k=x.useRef(null),D=x.useRef(null),P=(f,T)=>{m.some(V=>V.approvalId===f&&V.kind==="credential")&&(D.current={id:f,origin:document.activeElement,rowAtStart:e.find(V=>V.approvalId===f),refusalSubmittedAtStart:r?.submittedAt??0}),c(f,T)};x.useLayoutEffect(()=>{const f=D.current;if(!f)return;const T=e.find(Y=>Y.approvalId===f.id);if(a)return;const V=r?.approvalId===f.id&&(r.submittedAt??0)>f.refusalSubmittedAtStart;if(T===f.rowAtStart&&!V)return;D.current=null;const Z=m.find(Y=>Y.approvalId!==f.id),G=Z?I.current?.querySelector(`[data-tour-tag="mesh-approvals-live"] [data-approval-id="${CSS.escape(Z.approvalId)}"] ${ce(Z.state)?'[data-tour-tag="mesh-approval-summary"]':'[data-tour-tag="mesh-approval-controls"] button:not(:disabled)'}`):null,z=(m.some(Y=>Y.approvalId===f.id)?I.current?.querySelector(`[data-approval-id="${CSS.escape(f.id)}"] [data-tour-tag="mesh-approval-refusal"]`):null)??G??k.current?.querySelector("button"),ae=r?I.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(r.approvalId??"")}"]`)??null:null;Oe({document,target:z??null,refusalTarget:ae,origin:f.origin,allowFocus:!0,sentence:r?.sentence??""}).focused&&(u.current=p)},[e,a,r,m,p]),x.useLayoutEffect(()=>{if(!r||a){u.current=null,A("");return}if(u.current===p){A("");return}const f=I.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(r.approvalId??"")}"]`)??null,T=Oe({document,target:null,refusalTarget:f,origin:null,allowFocus:!1,sentence:r.sentence});T.focused&&(u.current=p),A(T.announcement)},[r,p,a,e]);const C=m.filter(f=>ce(f.state)).length,N=m.filter(me).length,g=w.filter(f=>f.kind==="credential"&&f.state==="connected").length,L=w.some(f=>f.state==="failed"),ee=w.filter(f=>f.state==="failed").length,q=r!==null&&e.some(f=>f.approvalId===r.approvalId&&(ce(f.state)||me(f)||S)),F=e.find(f=>f.approvalId===r?.approvalId);return m.length===0&&w.length===0&&!n&&!r?null:t.jsxs("section",{ref:I,"aria-label":s("ui.mesh.mesh_approvals_tray.approvals"),"data-tour-tag":"mesh-approvals-tray",className:"flex flex-col gap-3",children:[t.jsx("output",{"aria-live":"polite","aria-atomic":"true",className:"sr-only",children:s("ui.mesh.approval.result_status",{shared:g,attention:N})}),t.jsx("output",{"aria-live":"polite","aria-atomic":"true",className:"sr-only","data-tour-tag":"mesh-approval-announcement",children:t.jsx("bdi",{dir:"auto",children:M})}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(Rt,{"aria-hidden":"true",className:"size-4 text-ink-muted"}),t.jsx("h2",{className:"text-body-sm text-ink",children:s("ui.mesh.mesh_approvals_tray.approvals")}),C>0&&t.jsx("span",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_approvals_tray.waiting_count",{count:C})}),N>0&&t.jsx("span",{className:"text-meta text-warning",children:s("ui.mesh.approval.needs_attention",{count:N})})]}),n&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("p",{className:"min-w-0 flex-1 text-meta text-ink-muted",children:n}),t.jsx(Q,{variant:"secondary",size:"sm",onClick:d,children:s("ui.mesh.mesh_approvals_tray.ask_again")})]}),m.length>0&&t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-live",children:m.map(f=>t.jsx(We,{row:f,pending:a?.approvalId===f.approvalId?a:null,busy:y,refusal:r?.approvalId===f.approvalId?r:null,onDecide:P,nowSeconds:h,networkNames:l,credentialApprovals:v,profileApprovals:b},f.approvalId))}),r&&!q&&t.jsx(ct,{approvalId:r.approvalId??"",requestIsBackendSummary:F?Dt(F):!1,refusal:r,request:F?at(F):s("ui.mesh.approval.credential_title")}),w.length>0&&t.jsx("div",{ref:k,"data-tour-tag":"mesh-approvals-settled",children:t.jsx(ke,{open:S,onOpenChange:R,chevronClassName:"text-ink-dim",className:O(m.length>0&&"border-hairline border-t pt-3"),summary:t.jsxs("span",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[s("ui.mesh.mesh_approvals_tray.settled_approvals"),t.jsxs("span",{className:"text-ink-dim",children:["(",w.length,")"]}),L&&t.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-danger"}),g>0&&t.jsx("span",{className:"text-ink-muted",children:s("ui.mesh.approval.shared_count",{count:g})}),ee>0&&t.jsx("span",{className:"text-danger",children:s("ui.mesh.mesh_approvals_tray.failed_count",{count:ee})})]}),children:t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-records",children:w.map(f=>t.jsx(We,{row:f,pending:a?.approvalId===f.approvalId?a:null,busy:y,refusal:r?.approvalId===f.approvalId?r:null,onDecide:P,nowSeconds:h,networkNames:l,credentialApprovals:v,profileApprovals:b},f.approvalId))})})})]})},We=({row:e,pending:n,busy:a,refusal:r,onDecide:c,nowSeconds:d,networkNames:h,credentialApprovals:l,profileApprovals:v})=>{K();const b=ce(e.state),y=Et(e,r?.retryable),M=x.useId(),A=x.useId(),u=at(e),p=Pt(e,h),m=Lt(e,h),w=$t(e),S=Tt(e),R=Ot(e),I=Ft(e.expiresAt,d,me(e)),k=e.kind==="credential"||e.kind==="unknown"||e.kind==="profile",D=k||e.canApproveHere===!1,P=D?[]:Ts(e.state),C={credentialApprovals:l,profileApprovals:v},N=Fe(e,C),g=qe(e.state),L=qt(e,C,r?.retryable),ee=e.kind==="profile"?Rs(e,{profileApprovals:v,canApprove:Fe(e,C),canDeny:qe(e.state),canRetryApply:Ht(e,C,r?.retryable)}):null,q=l?e.typed:void 0,F=q?zt(e):[],f=q?.disclosure?Wt(e):null,T=e.typed?.unprovenHuman===!0,V=e.kind==="credential"&&["approved","failed","connecting","connected"].includes(e.state),Z=r?.sentence||(q?.applyOutcome?[q.applyOutcome.reason,q.applyOutcome.remedy].filter(Boolean).join(" "):""),G=r?.code||q?.applyOutcome?.code||q?.refusal,z=Bt(e),ae=(e.typed?.refusalMessage??"")||(e.typed?s("ui.mesh.approval.typed_review_unavailable"):e.approveRemedy||s("ui.mesh.approval.cli_review"));return t.jsxs("li",{className:"flex flex-col gap-2 py-3 first:pt-0 last:pb-0","data-tour-tag":"mesh-approval-card","data-approval-id":e.approvalId,children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:O("text-meta",me(e)?"text-warning":Ls(e.state)),children:y?s("ui.mesh.approval.could_not_apply"):e.kind==="credential"&&e.state==="connected"?s("ui.mesh.approval.shared"):e.kind==="credential"&&(e.state==="approved"||e.state==="failed")?s("ui.mesh.approval.approved_not_applied"):Vt(e.state)}),t.jsx("div",{className:"grow"}),!y&&(b||me(e))&&I&&t.jsx("span",{className:"text-meta text-ink-dim",children:I})]}),ee?t.jsx(Ps,{view:ee}):t.jsx("p",{className:"text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-summary",tabIndex:-1,id:M,children:b?p:u}),z&&t.jsx("p",{id:A,className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-critical-facts",children:z}),!D&&e.state==="failed"&&t.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-stopped-note",children:s("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_it")}),b&&D&&!N&&t.jsx("p",{className:"text-meta text-ink-muted whitespace-pre-wrap [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-cli-remedy",children:ae}),e.kind==="credential"&&!e.typed&&e.state==="approved"&&t.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-apply-hint",children:s(e.details?.length?"ui.mesh.approval.approved_apply_hint":"ui.mesh.approval.approved_details_missing")}),T&&t.jsx("p",{className:"text-meta text-ink-dim","data-tour-tag":"mesh-approval-file-key",children:s(V?"ui.mesh.approval.file_key_recorded":"ui.mesh.approval.file_key_disclosure")}),Z&&t.jsx(ct,{approvalId:e.approvalId,refusal:{code:G??"",sentence:Z}}),L&&t.jsx("p",{className:"text-meta text-ink-muted",children:s("ui.mesh.approval.retry_hint")}),V&&g&&t.jsx("p",{className:"text-meta text-ink-muted",children:s("ui.mesh.approval.cancel_hint")}),(N||g||L)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-tour-tag":"mesh-approval-controls",children:[L&&t.jsx(Q,{variant:"primary",size:"sm",disabled:a,"aria-describedby":z?`${M} ${A}`:M,onClick:()=>c(e.approvalId,"apply"),"data-tour-tag":"mesh-approval-retry-apply",children:s("ui.mesh.approval.try_again")}),N&&t.jsx(Q,{variant:"primary",size:"sm",disabled:a,"aria-describedby":z?`${M} ${A}`:M,onClick:()=>c(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:s("ui.mesh.mesh_approvals_tray.approve")}),g&&t.jsx(Q,{variant:"ghost",size:"sm",disabled:a,"aria-describedby":z?`${M} ${A}`:M,onClick:()=>c(e.approvalId,"deny"),"data-tour-tag":b?"mesh-approval-deny":"mesh-approval-stop",children:b?s("ui.mesh.mesh_approvals_tray.deny"):e.kind==="credential"?s("ui.mesh.approval.cancel_sharing"):$s(e.state)}),n&&t.jsx("span",{className:"text-meta text-ink-dim",children:n.decision==="approve"?e.typed?.unprovenHuman?s("ui.mesh.approval.signing_applying"):s("ui.mesh.mesh_approvals_tray.waiting_for_the_signing_prompt"):n.decision==="apply"?s("ui.mesh.approval.applying"):s("ui.mesh.mesh_approvals_tray.writing_the_decision")})]}),t.jsxs(ke,{chevronClassName:"text-ink-dim",summary:t.jsx("span",{className:"text-meta",children:s("ui.mesh.mesh_approvals_tray.details")}),children:[F.length>0&&t.jsx("ul",{className:"flex flex-col gap-1.5 text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-credential-consequences",children:F.map(E=>t.jsx("li",{children:E},E))}),f&&q?.disclosure?.recipient.keyFingerprint&&t.jsxs("p",{className:"text-meta text-ink-dim [overflow-wrap:anywhere]",children:[s("ui.mesh.approval.recipient_key",{device:f})," ",t.jsx("span",{className:"font-mono",children:q.disclosure.recipient.keyFingerprint})]}),G&&t.jsx("p",{className:"text-meta text-ink-dim font-mono",children:G}),q?.disclosure&&t.jsx(ke,{summary:t.jsx("span",{className:"text-meta",children:s("ui.mesh.approval.technical_request")}),children:t.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap text-meta text-ink-dim [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-signed-evidence",children:q.disclosure.evidence})}),k&&F.length===0&&(e.details?.length?t.jsx("ul",{className:"flex flex-col gap-1.5 text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-server-details",children:e.details.map((E,Y)=>t.jsx("li",{className:"whitespace-pre-wrap",children:E},`${Y}:${E}`))}):t.jsx("p",{className:"text-meta text-ink-muted",children:s("ui.mesh.approval.details_unavailable")})),m.length>0&&t.jsx("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta text-ink-dim","data-tour-tag":"mesh-approval-consequences",children:m.map(E=>t.jsxs(x.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{children:E.consequence})]},E.term))}),(w||S)&&t.jsxs("p",{className:"text-meta text-ink-muted",children:[w&&t.jsx("span",{children:w}),w&&S&&t.jsx("span",{children:" · "}),S&&t.jsx("span",{className:"font-mono",children:S})]}),R&&t.jsx("p",{className:"text-meta text-ink-dim",children:R}),P.length>0&&t.jsx("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta","data-tour-tag":"mesh-approval-consequence",children:P.map(E=>t.jsxs(x.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{className:"text-ink-muted",children:E.text})]},E.term))})]})]})},ct=({refusal:e,request:n,approvalId:a,requestIsBackendSummary:r=!1})=>{K();const c=ws();return t.jsx("p",{tabIndex:-1,className:"text-meta text-warning [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-refusal","data-approval-refusal-id":a,children:n?Yt(n,e.sentence).map((d,h)=>d.kind==="literal"?t.jsx(x.Fragment,{children:d.text},`literal:${h}`):t.jsx("bdi",{dir:Ut(d.kind,c,r),children:d.text},d.kind)):t.jsx("bdi",{dir:"auto",children:e.sentence})})},Fs=4,je={kind:"idle"};function qs(e){switch(e.kind){case"dragging":case"settling":return e.payload.session.id;case"pressing":return null;default:return null}}function de(e,n){switch(n.kind){case"press":return e.kind!=="idle"?e:{kind:"pressing",payload:n.payload,originX:n.x,originY:n.y,pointerId:n.pointerId};case"move":return e.kind==="pressing"?Math.max(Math.abs(n.x-e.originX),Math.abs(n.y-e.originY))<Fs?e:{kind:"dragging",payload:e.payload,x:n.x,y:n.y,target:n.target,pointerId:e.pointerId}:e.kind==="dragging"?{...e,x:n.x,y:n.y,target:n.target}:e;case"release":return e.kind==="dragging"?{kind:"settling",payload:e.payload,target:e.target}:e.kind==="pressing"?je:e;case"cancel":case"settled":return je;default:return e}}const Hs=({edges:e,geometry:n,selectedDeviceId:a})=>t.jsx("svg",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0 overflow-visible",width:n.bounds.width,height:n.bounds.height,children:e.map(r=>{const c=n.networks.get(r.networkId),d=n.devices.get(r.deviceId);if(!c||!d)return null;const h=a!==null&&r.deviceId===a;return t.jsx("path",{"data-mesh-edge":r.key,d:Kt(c,d),fill:"none",strokeWidth:h?2:1.5,className:h?"stroke-ink":"stroke-ink-dim"},r.key)})}),De=({deviceId:e,name:n,compact:a=!1,deviceIds:r,className:c})=>{K();const d=Je({name:n});return t.jsxs("span",{className:O("flex min-w-0 items-baseline gap-2",c),"data-mesh-device-identity":e,children:[t.jsx(Nt,{content:n?.trim()?d:null,children:t.jsx("span",{className:"min-w-0 flex-1 truncate text-start","data-mesh-device-name":"",children:d})}),t.jsx("span",{className:"shrink-0 font-mono text-meta text-ink-muted","data-mesh-device-id":"",title:e,children:a?gt(e,r):e})]})},zs={self:"border-l-hairline",reached:"border-l-hairline","relay-down":"border-l-warning","handshake-refused":"border-l-warning","address-unreachable":"border-l-warning","no-endpoint":"border-l-hairline","not-a-member":"border-l-hairline",unanswered:"border-l-warning","not-attempted":"border-l-hairline",unknown:"border-l-hairline"};function Ws(e){return e.suspect?"border-l-danger":zs[ue(e)]}const Bs={self:"ring-2 ring-accent",reachable:null,relay_down:null,handshake_refused:null,unreachable:null,suspect:null},Vs={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function Ys(e,n,a){return[Je(e),e.id,rt(e,n),a].filter(Boolean).join(", ")}function pe(e){return e.name.trim()||e.id.slice(-6)}function ut(e,n,a){if(a!=="reached"&&a!=="self"){const r=ge(a);return e.unreachable_reason?`${r} (${e.unreachable_reason})`:r}return e.live_state.trim()?e.live_state.trim():e.locality==="local"?s("ui.mesh.mesh_drop.on_this_device"):s("ui.mesh.mesh_node.on_device",{device:n})}const Us={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},Ks=({network:e,x:n,y:a,refused:r})=>(K(),t.jsxs("li",{"data-mesh-network":e.id,"data-mesh-network-refused":r?"true":void 0,"data-glass-block":"",className:O("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",r?"border-warning":"border-hairline"),style:{left:n,top:a,width:Ae,height:Gt},children:[t.jsx(Re,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate text-body-sm text-ink",children:e.label}),t.jsxs("span",{title:s("ui.mesh.mesh_list.epoch",{epoch:e.epoch}),className:"block truncate text-meta text-ink-dim",children:[s("ui.mesh.mesh_graph.device_count",{count:e.memberCount}),e.revokedCount>0?t.jsxs(t.Fragment,{children:[" · ",s("ui.mesh.mesh_list.revoked_count",{count:e.revokedCount})]}):null]})]})]})),Gs=({device:e,deviceIds:n,x:a,y:r,nowSeconds:c,selected:d,sessions:h,sessionTotal:l,dropState:v,movingSessionId:b,draggedSessionId:y,onOpen:M,onChipPointerDown:A,onChipClick:u,onShowAllSessions:p})=>{K();const{activity:m}=_t(e,h.rows),w=m==="working",S=Ys(e,c,w?"working":null),R=ue(e);return t.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":v??void 0,"aria-current":d?"true":void 0,"data-glass-block":"",className:O("absolute flex flex-col rounded-md border border-l-4 border-control bg-elevated","hover:bg-row-hover",d&&"border-y-ink border-r-ink bg-row-selected",Ws(e),Bs[e.state],v&&Vs[v]),style:{left:a,top:r,width:Ae,height:Xt},children:[t.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":R,"aria-label":S,title:bt(e),onClick:()=>M(e.id),className:O("flex w-full flex-col justify-between rounded-t-[5px] px-3 pt-2 pb-2 text-start","cursor-pointer","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),style:{height:Zt},children:[t.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2",children:[t.jsx(Ns,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),t.jsx(De,{className:"min-w-0 flex-1 text-body-sm text-ink",deviceId:e.id,deviceIds:n,name:e.name,compact:!0}),e.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"})]}),t.jsxs("span",{className:"flex w-full min-w-0 items-baseline gap-1",children:[t.jsx("span",{className:"w-3 shrink-0 font-mono text-body-sm text-ink tabular-nums",children:e.sessionCount??"–"}),t.jsx("span",{className:O("min-w-0 truncate text-meta",e.sessionCount===null?"text-ink-dim":"text-ink-muted"),children:nt(e.sessionCount)})]}),t.jsxs("span",{"data-mesh-state-line":"",className:"flex w-full min-w-0 items-baseline gap-1.5 text-meta",children:[t.jsx("span",{"aria-hidden":"true",className:"shrink-0 text-ink-dim",children:kt[R]}),t.jsx("span",{className:O("shrink-0",Qe[R]),children:ge(R)}),w&&t.jsx("span",{"data-mesh-working":"",className:"shrink-0 text-info",children:s("ui.mesh.mesh_node.working")}),e.memberships.length>1&&t.jsx("span",{className:"min-w-0 truncate text-ink-dim",children:s("ui.mesh.mesh_node.memberships",{count:e.memberships.length})})]})]}),t.jsxs("ul",{"aria-label":s("ui.mesh.mesh_node.conversations_on",{device:le(e,n,!0)}),className:O("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",v==="accept"&&"opacity-40"),children:[h.shown.map(I=>t.jsx(Xs,{session:I,ownerLabel:le(e,n,!0),ownerReach:R,ownerReachable:e.reachable,moving:b===I.id,dragging:y===I.id,onPointerDown:A,onClick:()=>u(I)},I.id)),h.hidden>0&&t.jsx("li",{className:"shrink-0",children:t.jsxs("button",{type:"button","data-mesh-more":e.id,onClick:()=>p(e.id),className:O("flex min-h-6 items-center rounded-sm px-1.5 text-meta text-ink-dim","hover:bg-row-hover hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),title:s("ui.mesh.mesh_node.shown_conversations",{shown:h.shown.length,total:l}),"aria-label":s("ui.mesh.mesh_node.show_all_conversations",{count:l}),children:["+",h.hidden]})})]})]})},Xs=({session:e,ownerLabel:n,ownerReach:a,ownerReachable:r,moving:c,dragging:d,onPointerDown:h,onClick:l})=>{K();const v=ut(e,n,a);return c?t.jsx("li",{role:"status","data-mesh-session":e.id,"data-mesh-moving":"true",children:t.jsx("span",{className:"flex min-h-6 items-center rounded-sm bg-sunken px-1.5 text-meta text-ink-muted",children:s("ui.mesh.mesh_card.moving")})}):t.jsx("li",{className:"min-w-0 flex-1","data-mesh-session-item":e.id,"data-mesh-dragging":d?"true":void 0,children:t.jsx("button",{type:"button","data-mesh-session":e.id,style:{touchAction:"none"},title:`${pe(e)} · ${v}`,"aria-label":s("ui.mesh.mesh_node.open_conversation",{conversation:pe(e),fact:v,owner:n}),onPointerDown:b=>h(b,e),onClick:()=>l(e),className:O("flex min-h-6 w-full max-w-32 items-center rounded-sm border border-hairline bg-surface px-1.5 text-start text-meta text-ink-muted","cursor-grab active:cursor-grabbing","hover:text-ink",Us[Jt(e,r)],d&&"opacity-60","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:t.jsx("span",{className:"min-w-0 flex-1 truncate",children:pe(e)})})})};function Be(e){const n=e.trim();if(!n)return null;if(n.startsWith("[")){const r=n.indexOf("]");if(r<=1)return null;const c=n.slice(1,r),d=n.slice(r+1);if(!d)return{host:c,port:null};if(!d.startsWith(":"))return null;const h=Number(d.slice(1));return{host:c,port:Number.isInteger(h)?h:null}}const a=n.lastIndexOf(":");if(a>0){const r=n.slice(a+1);if(/^\d+$/.test(r))return{host:n.slice(0,a),port:Number(r)}}return{host:n,port:null}}function Ve(e){const n=e.trim().split(".");if(n.length!==4)return null;for(const a of n)if(!/^\d{1,3}$/.test(a)||Number(a)>255)return null;return`${n[0]}.${n[1]}.${n[2]}`}function Zs(e){return`${e}.x`}function Js(e){const n=new Map;for(const r of e.values())for(const c of r)n.set(c,(n.get(c)??0)+1);const a=new Set;for(const[r,c]of n)c>1&&a.add(r);return a}function Se(e){return new Set(e.endpoints.map(n=>n.trim()).filter(Boolean))}function Qs(e,n){const a=e.filter(u=>u.id!==n),r=e.find(u=>u.id===n)??null,c=new Map;for(const u of e)c.set(u.id,Se(u));const d=Js(c),h=new Set;for(const u of r?Se(r):[]){if(d.has(u))continue;const p=Be(u),m=p?Ve(p.host):null;m&&h.add(m)}const l=u=>{const p=new Set;for(const m of Se(u)){if(d.has(m))continue;const w=Be(m),S=w?Ve(w.host):null;S&&p.add(S)}return p},v=new Map,b=new Map;for(const u of a){const p=ea(u);if(p){v.set(p,[...v.get(p)??[],u.id]);continue}for(const m of l(u))b.set(m,[...b.get(m)??[],u.id])}const y=new Map(e.map((u,p)=>[u.id,p])),M=u=>[...u].sort((p,m)=>(y.get(p)??0)-(y.get(m)??0)),A=[];for(const[u,p]of v)A.push({prefix:u,tier:"declared",deviceIds:M(p),get words(){return s("ui.mesh.mesh_scope.declared")}});for(const[u,p]of b)h.has(u)?A.push({prefix:u,tier:"shared",deviceIds:M(p),get words(){return s("ui.mesh.mesh_scope.shared_with_this_device")}}):p.length>1&&A.push({prefix:u,tier:"probable",deviceIds:M(p),get words(){return s("ui.mesh.mesh_scope.same_prefix")}});return A.sort((u,p)=>u.tier.localeCompare(p.tier)||u.prefix.localeCompare(p.prefix))}function ea(e){for(const n of e.memberships){const a=n.scope.trim();if(a)return a}return""}const Ye={declared:0,shared:1,probable:2};function ta(e,n){const a=new Map;for(const c of e){let d=null;for(const l of c.deviceIds){const v=n.get(l);v!==void 0&&(d===null||v<d.slot)&&(d={id:l,slot:v})}if(d===null)continue;const h=a.get(d.id);h===void 0?a.set(d.id,{slot:d.slot,groups:[c]}):h.groups.push(c)}const r=c=>{let d=-1;for(const h of c.deviceIds){const l=n.get(h);l!==void 0&&l>d&&(d=l)}return d};return[...a.entries()].sort((c,d)=>c[1].slot-d[1].slot).map(([c,d])=>({deviceId:c,groups:d.groups.sort((h,l)=>r(l)-r(h)||Ye[h.tier]-Ye[l.tier]||h.prefix.localeCompare(l.prefix))}))}function sa(e){return new Map(e.map(n=>[n.deviceId,n.groups.length]))}function aa(e){return`${e.tier==="declared"?e.prefix:Zs(e.prefix)} · ${e.words}`}const Ue=(e,n)=>e.deviceIds.map(a=>n.devices.get(a)).filter(a=>a!==void 0),na=({stacks:e,geometry:n})=>(K(),t.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(a=>{const r=a.groups.length,c=new Array(r).fill(0);let d=null;for(let l=r-1;l>=0;l-=1){const v=Ue(a.groups[l],n),b=(v.length===0?0:Math.max(...v.map(y=>y.y+y.height)))+_e;d=d===null?b:Math.max(b,d+Ie),c[l]=d}const h=n.devices.get(a.deviceId);return a.groups.map((l,v)=>{const b=Ue(l,n);if(b.length===0)return null;const y=r-1-v,M=Math.min(...b.map(S=>S.x)),A=Math.max(...b.map(S=>S.x)),p=(h?.y??Math.min(...b.map(S=>S.y)))-_e-Qt*y,m=l.tier==="declared",w=aa(l);return t.jsx("div",{"data-mesh-scope":`${l.tier}:${l.prefix}`,"data-mesh-scope-level":v,className:O("absolute rounded-lg",l.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:M-_e-Ie*y,top:p,width:A+Ae-M+(_e+Ie*y)*2,height:c[v]-p},children:t.jsx("span",{"data-mesh-scope-label":"",className:O("absolute bottom-full left-1 mb-0.5 whitespace-nowrap text-meta",l.tier==="probable"?"text-ink-dim":"text-ink-muted",m&&"font-medium"),children:w})},`${l.tier}:${l.prefix}`)})})})),Ke=48,Ge=1.25,ra=.0015,ia=({graph:e,slots:n,nowSeconds:a,selectedDeviceId:r,sessions:c,sessionTotals:d,movingSessionId:h,canMove:l,onOpenDevice:v,onAskMove:b,onDropRefused:y,onShowAllSessions:M,summaryId:A})=>{K();const u=x.useRef(null),[p,m]=x.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[w,S]=x.useState({k:1,tx:0,ty:0}),R=x.useRef(!1),I=x.useRef(!1),k=x.useRef(null),D=x.useMemo(()=>Qs(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),P=x.useMemo(()=>ta(D,n.devices),[D,n]),C=x.useMemo(()=>es(n,sa(P)),[n,P]),N=x.useMemo(()=>({selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(i=>[i.id,i])),networks:new Map(e.networks.map(i=>[i.id,i]))}),[e]),[g,L]=x.useState(je),ee=x.useRef({kind:"ground"}),q=x.useCallback((i,o)=>{const _=document.elementFromPoint(i,o),$=_?.closest("[data-mesh-device]");if($){const ie=$.getAttribute("data-mesh-device");if(ie)return{kind:"device",deviceId:ie}}const U=_?.closest("[data-mesh-network]");if(U){const ie=U.getAttribute("data-mesh-network");if(ie)return{kind:"network",networkId:ie}}return{kind:"ground"}},[]),F=x.useMemo(()=>g.kind!=="dragging"&&g.kind!=="settling"?null:ye(g.payload,g.target,N),[g,N]),f=x.useCallback(i=>{if(!F)return null;if(F.kind==="plan"){const o=g.kind==="dragging"||g.kind==="settling"?g.target:null;return o&&o.kind==="device"&&o.deviceId===i?"accept":null}if(F.kind==="refused"){const o=g.kind==="dragging"||g.kind==="settling"?g.target:null;return o&&o.kind==="device"&&o.deviceId===i?"refuse":null}return null},[F,g]),T=x.useCallback((i,o)=>{if(!l||i.button!==0)return;I.current=!1;const _=o.locality==="local"?e.selfDeviceId??"":o.owner_device,$=N.devices.get(_),U={session:o,ownerDeviceId:_,ownerLabel:$?le($,[...N.devices.keys()],!0):o.owner_device_name};try{i.currentTarget.setPointerCapture(i.pointerId)}catch{}L(ie=>de(ie,{kind:"press",payload:U,x:i.clientX,y:i.clientY,pointerId:i.pointerId}))},[l,N,e.selfDeviceId]),V=i=>{if(g.kind==="pressing"||g.kind==="dragging"){const o=q(i.clientX,i.clientY);ee.current=o,L(_=>de(_,{kind:"move",x:i.clientX,y:i.clientY,target:o}));return}H(i)},Z=i=>{if(ne(i),g.kind!=="pressing"&&g.kind!=="dragging")return;if(g.kind==="pressing"){L(_=>de(_,{kind:"cancel"}));return}const o=ye(g.payload,g.target,N);I.current=!0,L(_=>de(_,{kind:"release"})),o.kind==="plan"?b({plan:o.plan,alternatives:o.alternatives,risky:o.risky}):o.kind==="refused"&&y({code:o.code,sentence:o.sentence,reach:o.reach,remedy:o.remedy,plan:o.plan??null}),L(_=>de(_,{kind:"settled"}))};x.useEffect(()=>()=>L(je),[]);const G=x.useCallback(()=>{S(He(C.bounds,p))},[C.bounds,p]);x.useEffect(()=>{const i=u.current;if(!i)return;const o=()=>{const $=i.getBoundingClientRect();m({width:$.width,height:$.height,clipWidth:i.clientWidth,clipHeight:i.clientHeight,left:$.left,top:$.top})};o();const _=new ResizeObserver(o);return _.observe(i),()=>_.disconnect()},[]),x.useEffect(()=>{R.current||p.width<=0||p.height<=0||(R.current=!0,S(He(C.bounds,p)))},[p,C.bounds]),x.useEffect(()=>{const i=k.current;if(k.current={width:p.width,height:p.height},!i||!R.current||p.width<=0||p.height<=0||p.width>=i.width&&p.height>=i.height||!r)return;const o=C.devices.get(r);o&&S(_=>{const $={width:p.clipWidth,height:p.clipHeight},U=Math.max(0,Math.min($.width-C.bounds.width*_.k,$.height-C.bounds.height*_.k));return ts(_,o,$,Math.min(ss,U))})},[p,r,C]);const z=g.kind==="dragging"?{x:g.x-p.left+12,y:g.y-p.top+12}:{x:0,y:0},ae=F?Is(F):null,E=x.useRef(null),Y=x.useRef(null),te=x.useRef(null),j=x.useRef(null),W=x.useCallback(()=>{te.current=null;const i=E.current,o=Y.current;if(E.current=null,Y.current=null,i){const _=j.current;if(!_)return;S({k:_.transform.k,tx:_.transform.tx+(i.x-_.x),ty:_.transform.ty+(i.y-_.y)});return}o&&S(_=>Ce(_,{x:o.x,y:o.y},_.k*Math.exp(-o.deltaY*ra)))},[]),B=x.useCallback(()=>{te.current===null&&(te.current=requestAnimationFrame(W))},[W]);x.useEffect(()=>()=>{te.current!==null&&cancelAnimationFrame(te.current)},[]);const J=i=>{!(i.target===i.currentTarget)&&i.button!==1||i.button!==0&&i.button!==1||(j.current={x:i.clientX,y:i.clientY,transform:w},i.currentTarget.setPointerCapture(i.pointerId),i.preventDefault())},H=i=>{j.current&&(E.current={x:i.clientX,y:i.clientY},B())},ne=i=>{j.current&&(j.current=null,E.current=null,i.currentTarget.hasPointerCapture(i.pointerId)&&i.currentTarget.releasePointerCapture(i.pointerId))},re=x.useCallback(i=>{if(i.deltaY===0)return;i.preventDefault();const o=i.currentTarget.getBoundingClientRect();Y.current={x:i.clientX-o.left,y:i.clientY-o.top,deltaY:i.deltaY},B()},[B]);x.useEffect(()=>{const i=u.current;if(i)return i.addEventListener("wheel",re,{passive:!1}),()=>i.removeEventListener("wheel",re)},[re]);const he=i=>{const o=i.shiftKey?Ke*4:Ke;switch(i.key){case"Escape":if(g.kind!=="pressing"&&g.kind!=="dragging")return;i.preventDefault(),g.kind==="dragging"&&(I.current=!0),L(_=>de(_,{kind:"cancel"}));return;case"0":i.preventDefault(),G();return;case"+":case"=":i.preventDefault(),S(_=>Ce(_,{x:p.width/2,y:p.height/2},_.k*Ge));return;case"-":case"_":i.preventDefault(),S(_=>Ce(_,{x:p.width/2,y:p.height/2},_.k/Ge));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{i.preventDefault();const _=i.key==="ArrowLeft"?o:i.key==="ArrowRight"?-o:0,$=i.key==="ArrowUp"?o:i.key==="ArrowDown"?-o:0;S(U=>({...U,tx:U.tx+_,ty:U.ty+$}));return}}};return t.jsxs("div",{ref:u,"data-mesh-canvas":"",role:"group","aria-labelledby":A,tabIndex:0,onPointerDown:J,onPointerMove:V,onPointerUp:Z,onPointerCancel:i=>{g.kind==="dragging"&&(I.current=!0),L(o=>de(o,{kind:"cancel"})),ne(i)},"data-mesh-gesture":g.kind,"data-glass-well":"clear",onKeyDown:he,onDoubleClick:i=>{i.target===i.currentTarget&&G()},className:O("relative min-h-0 flex-1 overflow-hidden rounded-lg border border-hairline bg-sunken","[touch-action:none]","cursor-grab active:cursor-grabbing","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),children:[t.jsx("div",{"data-mesh-ground":"","aria-hidden":"true",className:"mesh-ground pointer-events-none absolute inset-0",style:{backgroundPosition:`${w.tx}px ${w.ty}px`}}),t.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${w.tx}px, ${w.ty}px, 0) scale(${w.k})`,transformOrigin:"0 0",width:C.bounds.width,height:C.bounds.height},children:[t.jsx(na,{stacks:P,geometry:C}),t.jsx(Hs,{edges:e.edges,geometry:C,selectedDeviceId:r}),t.jsx("ul",{"aria-label":s("ui.mesh.mesh_canvas.networks"),className:"m-0 list-none p-0",children:e.networks.map(i=>{const o=C.networks.get(i.id);return o?t.jsx(Ks,{network:i,x:o.x,y:o.y,refused:F?.kind==="refused"&&g.kind==="dragging"&&g.target.kind==="network"&&g.target.networkId===i.id},i.id):null})}),t.jsx("ul",{"aria-label":s("ui.mesh.mesh_canvas.devices"),className:"m-0 list-none p-0",children:e.devices.map(i=>{const o=C.devices.get(i.id);return o?t.jsx(Gs,{device:i,deviceIds:e.devices.map(_=>_.id),x:o.x,y:o.y,nowSeconds:a,selected:i.id===r,sessions:c.get(i.id)??{rows:[],shown:[],hidden:0},sessionTotal:d.get(i.id)??i.sessionCount??0,dropState:f(i.id),movingSessionId:h,draggedSessionId:qs(g),onOpen:v,onChipPointerDown:T,onChipClick:()=>{if(I.current){I.current=!1;return}v(i.id)},onShowAllSessions:M},i.id):null})})]}),g.kind==="dragging"&&t.jsx("div",{"data-mesh-ghost":"","aria-hidden":"true",className:"pointer-events-none absolute z-10 max-w-40 truncate rounded-sm border border-ink-dim bg-surface px-1.5 py-0.5 text-meta text-ink",style:{left:z.x,top:z.y},children:g.payload.session.name||"untitled"}),g.kind==="dragging"&&ae&&t.jsx("div",{"data-mesh-indicator":"",className:O("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",F?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:z.x,maxWidth:Math.max(160,p.width-z.x-12),...z.y>p.height*.6?{bottom:Math.max(12,p.height-z.y+8)}:{top:z.y+24}},children:ae})]})};function la(e,n,a,r){const c=a.locality==="local"?n:a.owner_device,d=[],h=e.map(l=>l.id);for(const l of e){if(l.id===c)continue;if(l.id===n){d.push({deviceId:l.id,label:r,verb:s("ui.mesh.mesh_card.recall_to_this_device"),keepVerb:s("ui.mesh.mesh_card.copy_here_leave_it_there")});continue}const v=le(l,h,!0);d.push({deviceId:l.id,label:v,verb:s("ui.mesh.mesh_card.move_to",{device:v}),keepVerb:s("ui.mesh.mesh_card.copy_to",{device:v})})}return d}function oa(e,n,a){return la(e.devices,e.selfDeviceId,n,a)}function mt(e,n,a){const r=oa(e,n,a),c={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(l=>[l.id,l])),networks:new Map(e.networks.map(l=>[l.id,l]))},d=n.locality==="local"?e.selfDeviceId??"":n.owner_device,h=c.devices.get(d);return r.map(l=>{const v=ye({session:n,ownerDeviceId:d,ownerLabel:h?le(h,e.devices.map(b=>b.id),!0):n.owner_device_name},{kind:"device",deviceId:l.deviceId},c);return{...l,refused:v.kind==="refused"&&v.code!=="busy"?v.sentence:null}})}const pt=({session:e,destinations:n,disabled:a,onChoose:r,onOpenChange:c,trigger:d,triggerLabel:h})=>(K(),t.jsxs(Ct,{onOpenChange:c,children:[t.jsx(St,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":h,"data-mesh-session-menu":e.id,disabled:a||n.length===0,className:"rounded-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2 disabled:text-ink-disabled",children:d})}),t.jsxs(At,{align:"start",className:"min-w-56",children:[t.jsx(Mt,{children:pe(e)}),t.jsx(Le,{}),n.map(l=>t.jsx($e,{"data-mesh-move-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>r(l,!1),children:l.verb},l.deviceId)),t.jsx(Le,{}),n.map(l=>t.jsx($e,{"data-mesh-copy-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>r(l,!0),children:l.keepVerb},`keep-${l.deviceId}`))]})]})),da=({device:e,deviceIds:n,sessions:a,sessionTotal:r,nowSeconds:c,destinationsFor:d,movingSessionId:h,canMove:l,canInvite:v,onClose:b,onMove:y,onShowInList:M,onInvite:A,onRemoveMember:u})=>{K();const p=ue(e),m=et(e),w=e.reachable?[]:e.attempts??[];x.useEffect(()=>{const k=D=>{D.key!=="Escape"||D.defaultPrevented||D.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),b())};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[e.id,b]);const S=e.sessionCount===null?nt(null):s("ui.mesh.mesh_card.conversation_count",{count:e.sessionCount}),R=e.suspect?tt():[S,ge(p)].filter(Boolean).join(" · "),I=r>a.rows.length?s("ui.mesh.mesh_card.shown_of",{shown:a.rows.length,total:r}):`${a.rows.length}`;return t.jsxs("aside",{"aria-label":s("ui.mesh.mesh_card.device_details",{device:le(e)}),"data-mesh-panel":e.id,"data-glass-block":"",className:"flex w-80 shrink-0 flex-col gap-3 overflow-y-auto rounded-md border border-hairline bg-surface p-4",children:[t.jsxs("header",{className:"flex flex-col gap-1",children:[t.jsx(Q,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:b,children:s("ui.mesh.mesh_actions.close")}),t.jsx("h2",{className:"text-body-sm text-ink",children:t.jsx(De,{deviceId:e.id,deviceIds:n,name:e.name,compact:!0})}),t.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[e.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 text-danger"}),!e.suspect&&p==="unanswered"&&t.jsx(It,{"aria-hidden":"true",className:"size-3.5 text-warning"}),R]})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.memberships")}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:e.memberships.map(k=>t.jsxs("li",{className:"flex flex-col gap-1",children:[t.jsxs("span",{className:"flex items-center gap-2 text-body-sm text-ink",children:[t.jsx(Re,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),k.networkName]}),t.jsxs("span",{className:"text-meta text-ink-dim",children:[k.role||"member",k.capabilities.length>0?` · ${k.capabilities.join(", ")}`:""]}),v&&t.jsxs(Q,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${k.networkId}:${e.id}`,onClick:()=>u(e,k.networkId),children:[s("ui.mesh.mesh_card.remove_from"),k.networkName,"…"]})]},k.networkId))}),v&&t.jsx(Q,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":e.id,onClick:()=>A(e),children:s("ui.mesh.mesh_actions.invite_to_a_network")})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex shrink-0 flex-col gap-2",children:[t.jsxs("h3",{className:"text-meta text-ink-dim",children:[s("ui.mesh.mesh_card.conversations"),t.jsxs("span",{className:"text-ink-disabled",children:["(",ue(e)!=="self"&&ue(e)!=="reached"?it(null):I,")"]})]}),be(e,c)?t.jsx("p",{className:"text-meta text-warning",children:be(e,c)}):a.rows.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:e.sessionCount===null?s("ui.mesh.mesh_card.this_device_did_not_report_its_conversations"):s("ui.mesh.mesh_card.no_conversations_here")}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:a.rows.map(k=>t.jsxs("li",{"data-mesh-panel-session":k.id,className:O("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",h===k.id&&"border-control"),children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",title:pe(k),children:pe(k)}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:ut(k,le(e,n,!0),ue(e))}),h===k.id?t.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:s("ui.mesh.mesh_card.moving")}):t.jsx(pt,{session:k,destinations:d(k),disabled:!l,onChoose:(D,P)=>y(k,D,P),trigger:t.jsx(ot,{"aria-hidden":"true",className:"size-4"}),triggerLabel:s("ui.mesh.mesh_card.move_conversation",{conversation:pe(k)})})]},k.id))})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.network_addresses")}),e.endpoints.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.no_address_published")}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:e.endpoints.map(k=>t.jsxs("li",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("span",{className:"min-w-0 truncate font-mono text-body-sm text-ink",children:k}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:s("ui.mesh.mesh_card.advertised")})]},k))})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.status")}),t.jsxs("dl",{className:"m-0 flex flex-col gap-1",children:[t.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("dt",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.reach")}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:ge(p)})]}),t.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("dt",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.last_status_frame")}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:e.lastSeenAt===null?s("ui.mesh.mesh_card.never"):as(c-e.lastSeenAt)})]})]}),!e.reachable&&(m!==""||w.length>0)&&t.jsxs("div",{className:"flex flex-col gap-1",children:[m&&t.jsx("p",{className:"m-0 text-meta text-warning",children:m}),e.linkState==="handshake_refused"&&t.jsx("p",{className:"m-0 text-meta text-ink-dim",children:s("ui.mesh.mesh_reach.handshake_refused_hint")}),w.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{id:`mesh-attempts-label-${e.id}`,className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_reach.addresses_tried")}),t.jsx("ul",{role:"list","aria-labelledby":`mesh-attempts-label-${e.id}`,className:"m-0 flex list-none flex-col gap-0.5 p-0",children:w.map((k,D)=>{const P=st(k.detail);return t.jsxs("li",{"data-mesh-attempt":k.endpoint,className:"flex items-baseline justify-between gap-2",children:[t.jsx("span",{className:"min-w-0 truncate font-mono text-meta text-ink",children:k.endpoint}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:P})]},`${k.endpoint}:${D}`)})})]})]}),!m&&w.length===0&&e.reason&&t.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),t.jsx(xe,{}),t.jsx(Q,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>M(e.id),children:s("ui.mesh.mesh_card.show_in_list")})]})},ca=["name","chats","state"],ua={get name(){return s("ui.mesh.mesh_list.name")},get chats(){return s("ui.mesh.mesh_list.sort_conversations")},get state(){return s("ui.mesh.mesh_list.state")}},Xe={suspect:0,relay_down:1,handshake_refused:2,unreachable:3,self:4,reachable:5};function ma(e,n){const a=[...e];switch(n){case"chats":return a.sort((r,c)=>(c.sessionCount??-1)-(r.sessionCount??-1)||r.label.localeCompare(c.label)),a;case"state":return a.sort((r,c)=>Xe[r.state]-Xe[c.state]||r.label.localeCompare(c.label)),a;default:return a.sort((r,c)=>r.label.localeCompare(c.label))}}const Ze=8;function pa(e,n){if(e.locality==="local")return e.live_state||"here";const a=e.owner_device_name||n,r=e.live_state?` · ${e.live_state}`:"";return e.reachable?s("ui.mesh.mesh_list.on_device_state",{device:a,state:r}):s("ui.mesh.mesh_list.on_device_no_answer",{device:a})}const ha=({graph:e,nowSeconds:n,selectedDeviceId:a,sessions:r,selfLabel:c,canMove:d,onSelect:h,onMove:l,onInvite:v,onRemove:b})=>{K();const[y,M]=x.useState("name"),A=x.useMemo(()=>e.networks.map(u=>({network:u,members:ma(e.devices.filter(p=>p.memberships.some(m=>m.networkId===u.id)),y)})),[e,y]);return t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pe-1",children:[t.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[t.jsx("legend",{className:"sr-only",children:s("ui.mesh.mesh_list.sort_devices_by")}),t.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:ca.map(u=>t.jsx("button",{type:"button","aria-pressed":y===u,onClick:()=>M(u),className:O("h-6 rounded-sm px-3 text-body-sm text-ink-muted transition-colors duration-fast ease-out-quart","hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2",y===u&&"bg-surface text-ink"),children:ua[u]},u))})]}),A.map(({network:u,members:p})=>t.jsxs("section",{"data-mesh-network-group":u.id,className:"flex flex-col gap-2",children:[t.jsxs("h2",{className:"flex flex-wrap items-baseline gap-2 text-body-sm text-ink",title:s("ui.mesh.mesh_list.epoch",{epoch:u.epoch}),children:[u.label,t.jsxs("span",{className:"text-meta text-ink-dim",children:[u.trust," ·"," ",s("ui.mesh.mesh_graph.device_count",{count:u.memberCount}),u.revokedCount>0?t.jsxs(t.Fragment,{children:[" · ",s("ui.mesh.mesh_list.revoked_count",{count:u.revokedCount})]}):null]})]}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:p.map(m=>{const w=m.memberships.find(N=>N.networkId===u.id),S=m.id===a,R=r.get(m.id),I=R?.rows??[],k=R?lt(R,m.sessionCount):m.sessionCount??0,D=ue(m),P=et(m),C=m.reachable?[]:m.attempts??[];return t.jsxs("li",{"data-mesh-device-row":m.id,"data-mesh-state":m.state,"aria-current":S?"true":void 0,className:O("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",S&&"border-ink bg-row-selected"),children:[t.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[t.jsx("button",{type:"button","data-mesh-device-open":m.id,onClick:()=>h(m.id),className:O("min-w-0 flex-1 text-start text-body-sm text-ink","hover:text-ink-muted","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:t.jsx(De,{deviceId:m.id,name:m.name})}),t.jsxs("span",{className:O("flex shrink-0 items-center gap-1 text-meta",Qe[D]),"data-mesh-reach":D,children:[m.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),m.suspect?ge(D):rt(m,n),m.suspect&&t.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:tt()})]}),t.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[w?.role?`${w.role} · `:"",s("ui.mesh.mesh_list.member")]})]}),(P!==""||C.length>0)&&!m.reachable&&t.jsxs("div",{className:"flex flex-col gap-0.5",children:[P&&t.jsx("span",{className:"text-meta text-warning",children:P}),C.map((N,g)=>{const L=st(N.detail);return t.jsx("span",{"data-mesh-attempt":N.endpoint,className:"text-meta text-ink-dim",children:L?`${N.endpoint} — ${L}`:N.endpoint},`${N.endpoint}:${g}`)})]}),be(m,n)?t.jsxs("span",{className:"text-meta text-warning",children:[s("ui.mesh.mesh_card.conversations")," (",it(null),") ·"," ",be(m,n)]}):I.length>0?t.jsxs(t.Fragment,{children:[t.jsx(xe,{className:"my-1"}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:I.slice(0,Ze).map(N=>t.jsxs("li",{"data-mesh-row-session":N.id,className:"flex items-center gap-2 py-0.5",children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-meta text-ink-muted",children:N.name||N.id}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:pa(N,c)}),t.jsx(pt,{session:N,destinations:mt(e,N,c),disabled:!d,onChoose:(g,L)=>l(N,g,L),trigger:t.jsx(ot,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:s("ui.mesh.mesh_list.move_conversation",{conversation:N.name||N.id})})]},N.id))}),k>I.slice(0,Ze).length&&t.jsx("button",{type:"button",onClick:()=>h(m.id),className:"w-fit text-meta text-ink-dim hover:text-ink",children:s("ui.mesh.mesh_list.show_all_panel",{count:k})})]}):t.jsx("span",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_list.conversation_count",{count:k})}),(w||m.state!=="self")&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(Q,{size:"sm",variant:"ghost","data-mesh-invite":m.id,onClick:()=>v({deviceId:m.id,deviceName:m.name}),children:s("ui.mesh.mesh_actions.invite_to_a_network")}),w&&t.jsxs(Q,{size:"sm",variant:"ghost","data-mesh-remove-member":`${u.id}:${m.id}`,onClick:()=>b({networkId:u.id,networkLabel:u.label,deviceId:m.id,deviceName:m.name}),children:[s("ui.mesh.mesh_card.remove_from"),u.label,"…"]})]})]},m.id)})})]},u.id)),e.unmatchedPeers.length>0&&t.jsxs("p",{className:"text-meta text-warning",children:[s("ui.mesh.mesh_graph.device_count",{count:e.unmatchedPeers.length})," ",s("ui.mesh.mesh_list.answered_the_peer_read_but_is_in")]})]})},xa=({revoked:e})=>{if(e.length===0)return null;const n=s("ui.mesh.mesh_list.revoked_count",{count:e.length});return t.jsx(ke,{className:"contents",chevron:"trailing",chevronClassName:"text-ink-dim",rowClassName:"min-h-auto py-0",triggerClassName:"inline-flex w-auto items-center gap-1 align-baseline text-meta text-ink-dim hover:text-ink",triggerData:{"data-mesh-revoked-toggle":""},triggerLabel:s("ui.mesh.mesh_list.revoked_toggle_label"),summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",className:"inline-block whitespace-pre",children:" · "}),n]}),children:t.jsx("ul",{"data-mesh-revoked":"",className:"m-0 flex list-none flex-col gap-1 p-0",children:e.map(a=>t.jsxs("li",{"data-mesh-revoked-member":a.deviceId,className:"flex flex-wrap items-baseline gap-x-2 text-meta text-ink-dim",children:[t.jsx("span",{children:a.networkName}),t.jsx("span",{className:"font-mono text-body-sm text-ink",children:a.deviceId}),t.jsx("span",{className:"text-body-sm text-ink-muted",children:a.label}),t.jsxs("span",{children:[a.role?`${a.role} · `:"",s("ui.mesh.mesh_graph.revoked_membership")]})]},`${a.networkId}:${a.deviceId}`))})})},fa=["canvas","list"],va={get canvas(){return s("ui.mesh.mesh_page.canvas")},get list(){return s("ui.mesh.mesh_page.list")}},ga=({state:e,initialPresentation:n="canvas",graph:a,nowSeconds:r,checking:c,staleError:d,onRetry:h,approvals:l,sessions:v,sessionError:b,selfLabel:y,movingSessionId:M,canMove:A,pendingMove:u,onAskMove:p,onDropRefused:m,onChooseMove:w,onCancelMove:S,moveBusy:R,moveReport:I,onDismissReport:k,onWaitForIdle:D,onUndoCopy:P,invite:C,onOpenInvite:N,onInvite:g,onCloseInvite:L,inviteBusy:ee,inviteReceipt:q,inviteRefusal:F,remove:f,onOpenRemove:T,onRemove:V,onCloseRemove:Z,removeBusy:G,removeRefusal:z,removed:ae})=>{K();const[E,Y]=x.useState(n),[te,j]=x.useState(null),W=a?ns(a):"",B="mesh-summary",J=rs(a),H=is(a,v,a?.selfDeviceId??null),ne=x.useMemo(()=>{const o=new Map;for(const _ of a?.devices??[]){const $=H.byDevice.get(_.id);o.set(_.id,$?lt($,_.sessionCount):_.sessionCount??0)}return o},[a,H]),re=x.useCallback(o=>{j(o)},[]),he=a?a.devices.find(o=>o.id===te)??null:null,i=x.useCallback((o,_,$)=>{if(!a)return null;const U={selfDeviceId:a.selfDeviceId,devices:new Map(a.devices.map(se=>[se.id,se])),networks:new Map(a.networks.map(se=>[se.id,se]))},ie=o.locality==="local"?a.selfDeviceId??"":o.owner_device,Ee=U.devices.get(ie),X=ye({session:o,ownerDeviceId:ie,ownerLabel:Ee?le(Ee,a.devices.map(se=>se.id),!0):o.owner_device_name},{kind:"device",deviceId:_.deviceId},U);if(X.kind==="refused")return m({code:X.code,sentence:X.sentence,reach:X.reach,remedy:X.remedy,plan:X.plan??null}),null;if(X.kind==="none")return null;const Pe=$?X.alternatives.find(se=>se.keep)??X.plan:X.plan,ht=[X.plan,...X.alternatives].filter(se=>se.keep!==Pe.keep),xt={plan:Pe,alternatives:ht,risky:X.risky};p(xt)},[a,p,m]);return t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[t.jsx(wt,{title:s("ui.mesh.mesh_page.mesh"),icon:Re,subtitle:s("ui.mesh.mesh_page.devices_this_app_is_paired_with_and"),children:t.jsxs("div",{className:"flex items-center gap-4",children:[c&&t.jsx("output",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_page.checking")}),(e.kind==="ready"||e.kind==="loading")&&t.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[t.jsx("legend",{className:"sr-only",children:s("ui.mesh.mesh_page.presentation")}),t.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:fa.map(o=>t.jsx("button",{type:"button","data-mesh-presentation":o,"aria-pressed":E===o,disabled:e.kind!=="ready",onClick:()=>Y(o),className:O("h-6 rounded-sm px-3 text-body-sm text-ink-muted transition-colors duration-fast ease-out-quart","hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2","disabled:text-ink-dim disabled:hover:text-ink-dim",E===o&&"bg-surface text-ink"),children:va[o]},o))})]})]})}),t.jsx(Os,{rows:l.rows,error:l.error,pending:l.pending,refusal:l.decisionRefusal,onDecide:l.onDecide,onRetry:l.onRetry,nowSeconds:l.nowSeconds,credentialApprovals:l.credentialApprovals,profileApprovals:l.profileApprovals,networkNames:new Map((a?.networks??[]).map(o=>[o.id,o.label]))}),e.kind==="loading"&&t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[t.jsx(Te,{className:"h-4 w-64"}),t.jsx(Te,{className:"min-h-40 w-full flex-1"})]}),e.kind==="error"&&t.jsxs(Ne,{variant:"warning",className:"flex-col items-start gap-2",children:[t.jsx("p",{children:e.message}),t.jsx(Q,{variant:"secondary",size:"sm",onClick:h,className:"w-fit",children:s("ui.mesh.mesh_approvals_tray.ask_again")})]}),e.kind==="empty"&&t.jsx("div",{"data-glass-block":"",className:"flex min-h-0 flex-1 items-center justify-center rounded-lg border border-hairline bg-surface p-6",children:t.jsxs("div",{className:"flex flex-col items-start gap-3",children:[t.jsx("h2",{className:"text-heading text-ink",children:s("ui.mesh.mesh_page.no_network_on_this_device")}),t.jsx("p",{className:"max-w-140 text-body-sm text-ink-muted",children:s("ui.mesh.mesh_page.this_device_is_not_in_any_network")}),t.jsx("code",{className:"rounded-sm bg-sunken px-2 py-1 font-mono text-meta text-ink",children:"lop network init <name>"}),t.jsx("p",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_page.a_network_appears_here_once_this_device")})]})}),e.kind==="ready"&&a&&t.jsx(t.Fragment,{children:t.jsxs("div",{className:"flex min-h-[22rem] flex-1 gap-4",children:[t.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-3",children:[t.jsxs("div",{id:B,className:"text-meta text-ink-muted","data-mesh-summary":"",children:[t.jsx("span",{children:W}),t.jsx(xa,{revoked:a.revoked})]}),d&&t.jsx(Ne,{variant:"warning",children:t.jsx("p",{children:d})}),b&&t.jsx(Ne,{variant:"warning",children:t.jsx("p",{children:b})}),I&&t.jsx(ls,{receipt:I.kind==="moved"?{verb:I.verb,detail:I.detail,undo:I.undo}:null,refusal:I.kind==="refused"?I.refusal:null,canWait:I.kind==="refused"&&I.plan!==null,onWait:D,onRecheck:h,onUndo:P,onDismiss:k,pending:R}),E==="canvas"?t.jsx(ia,{graph:a,slots:J,nowSeconds:r,selectedDeviceId:te,sessions:H.byDevice,sessionTotals:ne,movingSessionId:M,canMove:A,onOpenDevice:re,onAskMove:p,onDropRefused:m,onShowAllSessions:re,summaryId:B}):t.jsx(ha,{graph:a,nowSeconds:r,selectedDeviceId:te,sessions:H.byDevice,selfLabel:y,canMove:A,onSelect:re,onMove:i,onInvite:N,onRemove:T})]}),he&&t.jsx(da,{device:he,deviceIds:a.devices.map(o=>o.id),sessions:H.byDevice.get(he.id)??{rows:[],shown:[],hidden:0},sessionTotal:ne.get(he.id)??0,nowSeconds:r,canMove:A,canInvite:e.kind==="ready",movingSessionId:M,destinationsFor:o=>mt(a,o,y),onClose:()=>j(null),onMove:i,onInvite:o=>N({deviceId:o.id,deviceName:o.name}),onRemoveMember:(o,_)=>{const $=a.networks.find(U=>U.id===_);T({networkId:_,networkLabel:$?.label??_,deviceId:o.id,deviceName:o.name})},onShowInList:o=>{re(o),Y("list")}})]})}),t.jsx(os,{open:u!==null,plan:u?.plan??_a,alternatives:u?.alternatives??[],risky:u?.risky??!1,busy:R,onCancel:S,onChoose:w}),C&&t.jsx(ds,{open:C.open,options:C.options,deviceId:C.deviceId,deviceName:C.deviceName,onClose:L,onInvite:g,pending:ee,receipt:q,refusal:F}),f&&t.jsx(cs,{open:f.open,networkLabel:f.networkLabel,deviceId:f.deviceId,deviceName:f.deviceName,onClose:Z,onConfirm:V,pending:G,refusal:z,removed:ae})]})},_a={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},Ma=({initialPresentation:e})=>{K();const n=yt(),a=fe(n.data,"peers")==="enabled",r=fe(n.data,"session_transfer")==="enabled",c=us(a,{stamp:()=>we.getState().beginAnswer()}),d=ms(a),h=ps(a,{poll:!1,stamp:()=>we.getState().beginAnswer()}),l=x.useMemo(()=>({peers:c,networks:d}),[c,d]),v=hs(l),b=xs(l),y=fs(),M=fe(n.data,"approvals")==="enabled",A=vs(a&&M,{poll:!1}),u=gs(),p=fe(n.data,"credential_approvals")==="enabled",m=fe(n.data,"profile_approvals")==="enabled",w=u.isError?{approvalId:u.variables?.approvalId??null,submittedAt:u.submittedAt,..._s(u.error)}:null,S=x.useMemo(()=>Math.floor((A.dataUpdatedAt||Date.now())/1e3),[A.dataUpdatedAt]),R=we(j=>j.settlePlacement),I=bs(),k=ks(),[D,P]=x.useState(null),[C,N]=x.useState(null),[g,L]=x.useState(null),[ee,q]=x.useState(null),[F,f]=x.useState(null),[T,V]=x.useState(null),[Z,G]=x.useState(null),z=x.useMemo(()=>{const j=Math.max(c.dataUpdatedAt,d.dataUpdatedAt);return Math.floor((j||Date.now())/1e3)},[c.dataUpdatedAt,d.dataUpdatedAt]),ae=x.useCallback(()=>{c.refetch(),d.refetch(),h.refetch()},[c,d,h]),E=x.useCallback((j,W)=>{P(null);const B={sessionId:j.sessionId,to:j.to,keep:j.keep,waitS:W??j.waitS};y.mutate(B,{onSuccess:J=>{if(J.kind==="moved"){const{receipt:H}=J;R(j.sessionId,H);const ne=H.locality==="local"?s("ui.mesh.mesh_drop.this_device"):b?.devices.find(re=>re.id===H.owner_device)?.label??H.owner_device;N({kind:"moved",verb:H.mode==="keep"?s("ui.mesh.mesh_page.copied"):s("ui.mesh.mesh_page.moved"),detail:H.mode==="keep"?s("ui.mesh.mesh_page.copy_receipt",{destination:ne,suffix:H.new_session_id.slice(-6)}):s("ui.mesh.mesh_page.move_receipt",{destination:ne,retirement:H.source_retired?s("ui.mesh.mesh_page.the_copy_here_is_gone"):""}),undo:H.mode==="keep"?{sessionId:H.new_session_id,to:"local",keep:!1,verb:s("ui.mesh.mesh_page.bring_copy_back",{device:ne}),waitS:0,lost:Cs(ne,s("ui.mesh.mesh_drop.this_device"))}:null});return}N({kind:"refused",refusal:J.refusal,plan:j})},onError:()=>{N({kind:"refused",refusal:{code:"move_failed",sentence:s("ui.mesh.mesh_page.the_move_could_not_be_sent_nothing"),status:null,unconfirmed:!1},plan:j})}})},[b,y,R]),Y=x.useMemo(()=>{if(!b)return[];const j=g?.deviceId,W=j?b.devices.find(B=>B.id===j):void 0;return b.networks.filter(B=>W?!W.memberships.some(J=>J.networkId===B.id):!0).map(B=>({id:B.id,label:B.label}))},[b,g]);if(!a)return t.jsx(jt,{to:"/chat",replace:!0});const te=v.kind==="ready"?c.error?ve(c.error):d.error?ve(d.error):null:null;return t.jsx(ga,{initialPresentation:e,state:v,graph:b,nowSeconds:z,checking:c.isFetching||d.isFetching,staleError:te,onRetry:ae,approvals:{rows:A.data??[],error:A.isError?ys(A.error):null,pending:u.isPending?u.variables??null:null,decisionRefusal:w,credentialApprovals:p,profileApprovals:m,onDecide:(j,W)=>{const B=A.data?.find(H=>H.approvalId===j),J=B?js(B,W,{credentialApprovals:p,profileApprovals:m},w?.approvalId===j?w.retryable:void 0):null;J&&u.mutate({approvalId:j,decision:W,request:J})},onRetry:()=>void A.refetch(),nowSeconds:S},sessions:h.data?.rows??[],movingSessionId:y.isPending?y.variables?.sessionId??null:null,sessionError:h.isError?ve(h.error):null,selfLabel:b?.devices.find(j=>j.state==="self")?.label??s("ui.mesh.mesh_drop.this_device"),canMove:r,pendingMove:D,onAskMove:P,onDropRefused:j=>N({kind:"refused",refusal:{code:j.code,sentence:j.sentence,reach:j.reach,status:null,unconfirmed:!1},plan:j.plan}),onChooseMove:j=>E(j),onCancelMove:()=>P(null),moveBusy:y.isPending,moveReport:C,onDismissReport:()=>N(null),onWaitForIdle:()=>{C?.kind!=="refused"||!C.plan||E(C.plan,ba)},onUndoCopy:()=>{C?.kind!=="moved"||!C.undo||P({plan:C.undo,alternatives:[],risky:!1})},invite:g===null?null:{open:!0,deviceId:g.deviceId,deviceName:g.deviceName,options:Y},onOpenInvite:j=>{q(null),f(null),L(j)},onInvite:j=>{I.mutate(j,{onSuccess:W=>q(W),onError:W=>f({code:"invite_refused",sentence:ve(W),status:null,unconfirmed:!1})})},onCloseInvite:()=>L(null),inviteBusy:I.isPending,inviteReceipt:ee,inviteRefusal:F,remove:T===null?null:{open:!0,networkId:T.networkId,networkLabel:T.networkLabel,deviceId:T.deviceId,deviceName:T.deviceName},onOpenRemove:j=>{G(null),V(j)},onRemove:j=>{T&&k.mutate({networkId:T.networkId,deviceId:T.deviceId,confirm:j},{onSuccess:W=>G(W)})},onCloseRemove:()=>V(null),removeBusy:k.isPending,removeRefusal:k.isError?{code:"remove_refused",sentence:ve(k.error),status:null,unconfirmed:!1}:null,removed:Z})},ba=300;export{Ma as MeshPage,ga as MeshSurface,Ma as default};
|
|
1
|
+
import{r as x,j as t,c as O}from"./index-D0qlrLIs.js";import{R as ft,T as vt,V as Je,W as gt,X as _t,Y as ue,Z as bt,_ as kt,$ as ge,a0 as Qe,a1 as le,a2 as et,a3 as tt,a4 as st,a as yt,g as fe,A as we,a5 as jt}from"./appearance-DO4VPBSi.js";import{P as wt}from"./page-header-DXwYxMB-.js";import{u as K,B as Q,w as Nt,T as It,s as xe,D as Ct,g as St,i as At,G as Mt,H as Le,I as $e,l as Te,A as Ne}from"./error-boundary-BsWceBKP.js";import{t as s}from"./messages-BYDbMAVA.js";import{Q as ce,T as me,U as Oe,V as Rt,W as at,X as Dt,Y as Et,Z as Pt,_ as Lt,$ as $t,a0 as Tt,a1 as Ot,a2 as Ft,a3 as Fe,a4 as qe,a5 as qt,a6 as Ht,a7 as zt,a8 as Wt,a9 as Bt,aa as Vt,ab as Yt,ac as Ut,ad as Kt,ae as Gt,af as Ae,ag as Xt,ah as Zt,ai as Me,aj as nt,ak as rt,al as Jt,am as _e,an as Ie,ao as Qt,ap as es,aq as He,ar as ts,as as Ce,at as ss,au as it,av as be,aw as as,ax as lt,ay as ns,az as rs,aA as is,aB as ls,aC as os,aD as ds,aE as cs,aF as us,aG as ms,aH as ps,aI as hs,aJ as xs,aK as fs,aL as vs,aM as gs,aN as _s,aO as bs,aP as ks,aQ as ve,aR as ys,aS as js}from"./index-BKh47kLl.js";import{bn as ke,bo as ws,bp as Re,bq as Ns,br as ye,bs as Is,bt as ot,bu as Cs}from"./conversation-input-sync-FnnZiNnd.js";import"./roles-D1pcbxAx.js";import"./console-mirror-Bp3thuUi.js";function dt(){return{state:"unavailable",enabled:!1,label:s("ui.mesh.mesh_approvals.profile_revert"),note:s("ui.mesh.mesh_approvals.profile_revert_unavailable"),descriptor:null}}function Ss(e){return e==="agent"?s("ui.mesh.mesh_approvals.profile_kind_agent"):s("ui.mesh.mesh_approvals.profile_kind_team")}function As(e){switch(e){case"create":return s("ui.mesh.mesh_approvals.profile_operation_create");case"update":return s("ui.mesh.mesh_approvals.profile_operation_update");default:return s("ui.mesh.mesh_approvals.profile_operation_revert")}}function Ms(e,n){switch(e.state){case"requested":return{state:"waiting",note:oe("waiting")};case"approved":return{state:"approved_not_saved",note:oe("approved_not_saved")};case"connected":return{state:"saved",note:oe("saved")};case"denied":return{state:"denied",note:oe("denied")};case"expired":return{state:"expired",note:oe("expired")};case"failed":return{state:"stopped",note:oe("stopped")};default:return{state:"unknown",note:oe("unknown")}}}function Rs(e,{profileApprovals:n=!1,canApprove:a=!1,canDeny:r=!1,canRetryApply:c=!1,revert:d=null}={}){const h=e.profile?.disclosure??null,l=e.state==="requested",v=h?.profile_kind??null,b=h?ft(h):[],y=Ms(e),M=l&&!a?n?s("ui.mesh.mesh_approvals.profile_approval_unavailable"):s("ui.mesh.mesh_approvals.profile_unavailable"):null;return{kind:v,name:h?.profile_name??"",operation:h?.profile_operation??null,scope:h?.scope??null,fields:b,changesIncluded:h!==null,diffLines:[],changedFieldNames:[],state:y.state,stateNote:y.note,canApprove:a,canDeny:r,canRetryApply:c,unavailableReason:M,revert:d?Ds(d):dt()}}function Ds(e,n={}){if(!e)return dt();const a=vt({descriptor:e,descriptorVerified:!0,...n});return{state:a.state,enabled:a.enabled,label:e.label||s("ui.mesh.mesh_approvals.profile_revert"),note:Es(a.state),descriptor:e}}function Es(e){switch(e){case"available":return null;case"pending":return s("ui.mesh.mesh_approvals.profile_revert_pending");case"saved":return s("ui.mesh.mesh_approvals.profile_revert_done");case"stale":return s("ui.mesh.mesh_approvals.profile_revert_stale");case"failed":return s("ui.mesh.mesh_approvals.profile_revert_failed");case"unconfirmed":return s("ui.mesh.mesh_approvals.profile_revert_unconfirmed");default:return s("ui.mesh.mesh_approvals.profile_revert_unavailable")}}function oe(e){switch(e){case"waiting":return s("ui.mesh.mesh_approvals.profile_outcome_waiting");case"saved":return s("ui.mesh.mesh_approvals.profile_outcome_saved");case"approved_not_saved":return s("ui.mesh.mesh_approvals.profile_outcome_approved_not_saved");case"denied":return s("ui.mesh.mesh_approvals.profile_outcome_denied");case"expired":return s("ui.mesh.mesh_approvals.profile_outcome_expired");case"stopped":return s("ui.mesh.mesh_approvals.profile_outcome_stopped");default:return s("ui.mesh.mesh_approvals.profile_outcome_unknown")}}function ze(e,n){const a=n==="before"?e.before:e.after;return a.presence==="set"?a.text:a.presence==="unset"?s("ui.mesh.mesh_approvals.profile_cleared"):s("ui.mesh.mesh_approvals.profile_not_set")}function Ps({view:e,actions:n,onRevert:a,className:r}){K();const c=x.useId(),d=x.useId(),h=x.useId(),l=e.revert??null,v=!l||!l.enabled||!a,b=l?l.note??(a===void 0?s("ui.mesh.mesh_approvals.profile_revert_no_handler"):v?s("ui.mesh.mesh_approvals.profile_revert_reason_unknown"):null):null;return t.jsxs("section",{className:O("flex flex-col gap-3 rounded-md bg-sunken p-3 text-body-sm text-ink",r),"aria-labelledby":c,"data-tour-tag":"profile-consent-card","data-profile-state":e.state,"data-profile-revert":l?.state??"absent",children:[t.jsxs("header",{className:"flex flex-col gap-1",children:[t.jsxs("span",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-meta text-ink-dim",children:[e.kind&&t.jsx("span",{children:Ss(e.kind)}),e.operation&&t.jsx("span",{"data-tour-tag":"profile-consent-operation",children:As(e.operation)}),e.scope==="global"&&t.jsx("span",{children:s("ui.mesh.mesh_approvals.profile_scope_global")})]}),t.jsx("h3",{id:c,className:"font-mono text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-name",children:e.name}),e.stateNote&&t.jsx("p",{className:"text-meta text-ink-muted",children:e.stateNote})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("h4",{id:d,className:"text-meta text-ink-muted",children:s("ui.mesh.mesh_approvals.profile_changes")}),e.fields.length>0?t.jsxs("table",{className:"w-full border-collapse text-left text-meta","aria-labelledby":d,"data-tour-tag":"profile-consent-diff",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"text-ink-dim",children:[t.jsx("th",{scope:"col",className:"py-1 pr-2 font-normal",children:s("ui.mesh.mesh_approvals.profile_field")}),t.jsx("th",{scope:"col",className:"py-1 pr-2 font-normal",children:s("ui.mesh.mesh_approvals.profile_column_before")}),t.jsx("th",{scope:"col",className:"py-1 font-normal",children:s("ui.mesh.mesh_approvals.profile_column_after")})]})}),t.jsx("tbody",{children:e.fields.map(y=>t.jsxs("tr",{className:"border-hairline border-t align-top","data-profile-field":y.field,children:[t.jsx("th",{scope:"row",className:"py-1 pr-2 font-mono font-normal text-ink-muted",children:y.field}),t.jsx("td",{className:"py-1 pr-2 text-ink-dim [overflow-wrap:anywhere]",children:ze(y,"before")}),t.jsx("td",{className:"py-1 text-ink [overflow-wrap:anywhere]",children:ze(y,"after")})]},y.field))})]}):e.diffLines.length>0?t.jsx("ul",{className:"flex flex-col gap-1 text-meta text-ink [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-diff-lines",children:e.diffLines.map(y=>t.jsx("li",{children:y},y))}):e.changedFieldNames.length>0?t.jsx("p",{className:"font-mono text-meta text-ink [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-changed-fields",children:e.changedFieldNames.join(", ")}):t.jsx("p",{className:"text-meta text-ink-dim","data-tour-tag":e.changesIncluded?"profile-consent-no-changes":"profile-consent-changes-not-included",children:e.changesIncluded?s("ui.mesh.mesh_approvals.profile_changes_none"):s("ui.mesh.mesh_approvals.profile_changes_not_in_receipt")})]}),e.unavailableReason&&t.jsx("p",{className:"text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-unavailable",children:e.unavailableReason}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n,l&&t.jsxs("span",{className:"inline-flex items-center gap-2",children:[t.jsx(Q,{type:"button",variant:"ghost",size:"sm",disabled:v,"aria-describedby":b?h:void 0,onClick:a,"data-tour-tag":"profile-consent-revert",children:l.label}),b&&t.jsx("span",{id:h,className:"text-meta text-ink-dim [overflow-wrap:anywhere]","data-tour-tag":"profile-consent-revert-note",children:b})]})]})]})}function Ls(e){return e==="failed"?"text-danger":ce(e)?"text-ink-muted":"text-ink-dim"}function $s(e){return e==="failed"?s("ui.mesh.mesh_approvals_tray.abandon"):s("ui.mesh.mesh_approvals_tray.stop")}function Ts(e){switch(e){case"requested":return[{term:s("ui.mesh.mesh_approvals_tray.signing"),text:s("ui.mesh.mesh_approvals_tray.approving_signs_with_this_machine_s_operator")}];case"approved":return[{term:s("ui.mesh.mesh_approvals_tray.next"),text:s("ui.mesh.mesh_approvals_tray.an_agent_runs_the_install_and_connect")},{term:s("ui.mesh.mesh_approvals_tray.stop"),text:s("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_nothing_has")}];case"connecting":return[{term:s("ui.mesh.mesh_approvals_tray.stop"),text:s("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_the_runner")}];case"failed":return[{term:s("ui.mesh.mesh_approvals_tray.after_a_stop"),text:s("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_abandoning")}];default:return[]}}const Os=({rows:e,error:n,pending:a,refusal:r,onDecide:c,onRetry:d,nowSeconds:h,networkNames:l,credentialApprovals:v=!1,profileApprovals:b=!1})=>{K();const y=a!==null,[M,A]=x.useState(""),u=x.useRef(null),p=r?JSON.stringify([r.approvalId,r.code,r.sentence]):null,m=x.useMemo(()=>e.filter(f=>ce(f.state)||me(f)),[e]),w=x.useMemo(()=>e.filter(f=>!ce(f.state)&&!me(f)),[e]),[S,R]=x.useState(!1),I=x.useRef(null),k=x.useRef(null),D=x.useRef(null),P=(f,T)=>{m.some(V=>V.approvalId===f&&V.kind==="credential")&&(D.current={id:f,origin:document.activeElement,rowAtStart:e.find(V=>V.approvalId===f),refusalSubmittedAtStart:r?.submittedAt??0}),c(f,T)};x.useLayoutEffect(()=>{const f=D.current;if(!f)return;const T=e.find(Y=>Y.approvalId===f.id);if(a)return;const V=r?.approvalId===f.id&&(r.submittedAt??0)>f.refusalSubmittedAtStart;if(T===f.rowAtStart&&!V)return;D.current=null;const Z=m.find(Y=>Y.approvalId!==f.id),G=Z?I.current?.querySelector(`[data-tour-tag="mesh-approvals-live"] [data-approval-id="${CSS.escape(Z.approvalId)}"] ${ce(Z.state)?'[data-tour-tag="mesh-approval-summary"]':'[data-tour-tag="mesh-approval-controls"] button:not(:disabled)'}`):null,z=(m.some(Y=>Y.approvalId===f.id)?I.current?.querySelector(`[data-approval-id="${CSS.escape(f.id)}"] [data-tour-tag="mesh-approval-refusal"]`):null)??G??k.current?.querySelector("button"),ae=r?I.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(r.approvalId??"")}"]`)??null:null;Oe({document,target:z??null,refusalTarget:ae,origin:f.origin,allowFocus:!0,sentence:r?.sentence??""}).focused&&(u.current=p)},[e,a,r,m,p]),x.useLayoutEffect(()=>{if(!r||a){u.current=null,A("");return}if(u.current===p){A("");return}const f=I.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(r.approvalId??"")}"]`)??null,T=Oe({document,target:null,refusalTarget:f,origin:null,allowFocus:!1,sentence:r.sentence});T.focused&&(u.current=p),A(T.announcement)},[r,p,a,e]);const C=m.filter(f=>ce(f.state)).length,N=m.filter(me).length,g=w.filter(f=>f.kind==="credential"&&f.state==="connected").length,L=w.some(f=>f.state==="failed"),ee=w.filter(f=>f.state==="failed").length,q=r!==null&&e.some(f=>f.approvalId===r.approvalId&&(ce(f.state)||me(f)||S)),F=e.find(f=>f.approvalId===r?.approvalId);return m.length===0&&w.length===0&&!n&&!r?null:t.jsxs("section",{ref:I,"aria-label":s("ui.mesh.mesh_approvals_tray.approvals"),"data-tour-tag":"mesh-approvals-tray",className:"flex flex-col gap-3",children:[t.jsx("output",{"aria-live":"polite","aria-atomic":"true",className:"sr-only",children:s("ui.mesh.approval.result_status",{shared:g,attention:N})}),t.jsx("output",{"aria-live":"polite","aria-atomic":"true",className:"sr-only","data-tour-tag":"mesh-approval-announcement",children:t.jsx("bdi",{dir:"auto",children:M})}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(Rt,{"aria-hidden":"true",className:"size-4 text-ink-muted"}),t.jsx("h2",{className:"text-body-sm text-ink",children:s("ui.mesh.mesh_approvals_tray.approvals")}),C>0&&t.jsx("span",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_approvals_tray.waiting_count",{count:C})}),N>0&&t.jsx("span",{className:"text-meta text-warning",children:s("ui.mesh.approval.needs_attention",{count:N})})]}),n&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("p",{className:"min-w-0 flex-1 text-meta text-ink-muted",children:n}),t.jsx(Q,{variant:"secondary",size:"sm",onClick:d,children:s("ui.mesh.mesh_approvals_tray.ask_again")})]}),m.length>0&&t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-live",children:m.map(f=>t.jsx(We,{row:f,pending:a?.approvalId===f.approvalId?a:null,busy:y,refusal:r?.approvalId===f.approvalId?r:null,onDecide:P,nowSeconds:h,networkNames:l,credentialApprovals:v,profileApprovals:b},f.approvalId))}),r&&!q&&t.jsx(ct,{approvalId:r.approvalId??"",requestIsBackendSummary:F?Dt(F):!1,refusal:r,request:F?at(F):s("ui.mesh.approval.credential_title")}),w.length>0&&t.jsx("div",{ref:k,"data-tour-tag":"mesh-approvals-settled",children:t.jsx(ke,{open:S,onOpenChange:R,chevronClassName:"text-ink-dim",className:O(m.length>0&&"border-hairline border-t pt-3"),summary:t.jsxs("span",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[s("ui.mesh.mesh_approvals_tray.settled_approvals"),t.jsxs("span",{className:"text-ink-dim",children:["(",w.length,")"]}),L&&t.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-danger"}),g>0&&t.jsx("span",{className:"text-ink-muted",children:s("ui.mesh.approval.shared_count",{count:g})}),ee>0&&t.jsx("span",{className:"text-danger",children:s("ui.mesh.mesh_approvals_tray.failed_count",{count:ee})})]}),children:t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-records",children:w.map(f=>t.jsx(We,{row:f,pending:a?.approvalId===f.approvalId?a:null,busy:y,refusal:r?.approvalId===f.approvalId?r:null,onDecide:P,nowSeconds:h,networkNames:l,credentialApprovals:v,profileApprovals:b},f.approvalId))})})})]})},We=({row:e,pending:n,busy:a,refusal:r,onDecide:c,nowSeconds:d,networkNames:h,credentialApprovals:l,profileApprovals:v})=>{K();const b=ce(e.state),y=Et(e,r?.retryable),M=x.useId(),A=x.useId(),u=at(e),p=Pt(e,h),m=Lt(e,h),w=$t(e),S=Tt(e),R=Ot(e),I=Ft(e.expiresAt,d,me(e)),k=e.kind==="credential"||e.kind==="unknown"||e.kind==="profile",D=k||e.canApproveHere===!1,P=D?[]:Ts(e.state),C={credentialApprovals:l,profileApprovals:v},N=Fe(e,C),g=qe(e.state),L=qt(e,C,r?.retryable),ee=e.kind==="profile"?Rs(e,{profileApprovals:v,canApprove:Fe(e,C),canDeny:qe(e.state),canRetryApply:Ht(e,C,r?.retryable)}):null,q=l?e.typed:void 0,F=q?zt(e):[],f=q?.disclosure?Wt(e):null,T=e.typed?.unprovenHuman===!0,V=e.kind==="credential"&&["approved","failed","connecting","connected"].includes(e.state),Z=r?.sentence||(q?.applyOutcome?[q.applyOutcome.reason,q.applyOutcome.remedy].filter(Boolean).join(" "):""),G=r?.code||q?.applyOutcome?.code||q?.refusal,z=Bt(e),ae=(e.typed?.refusalMessage??"")||(e.typed?s("ui.mesh.approval.typed_review_unavailable"):e.approveRemedy||s("ui.mesh.approval.cli_review"));return t.jsxs("li",{className:"flex flex-col gap-2 py-3 first:pt-0 last:pb-0","data-tour-tag":"mesh-approval-card","data-approval-id":e.approvalId,children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:O("text-meta",me(e)?"text-warning":Ls(e.state)),children:y?s("ui.mesh.approval.could_not_apply"):e.kind==="credential"&&e.state==="connected"?s("ui.mesh.approval.shared"):e.kind==="credential"&&(e.state==="approved"||e.state==="failed")?s("ui.mesh.approval.approved_not_applied"):Vt(e.state)}),t.jsx("div",{className:"grow"}),!y&&(b||me(e))&&I&&t.jsx("span",{className:"text-meta text-ink-dim",children:I})]}),ee?t.jsx(Ps,{view:ee}):t.jsx("p",{className:"text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-summary",tabIndex:-1,id:M,children:b?p:u}),z&&t.jsx("p",{id:A,className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-critical-facts",children:z}),!D&&e.state==="failed"&&t.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-stopped-note",children:s("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_it")}),b&&D&&!N&&t.jsx("p",{className:"text-meta text-ink-muted whitespace-pre-wrap [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-cli-remedy",children:ae}),e.kind==="credential"&&!e.typed&&e.state==="approved"&&t.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-apply-hint",children:s(e.details?.length?"ui.mesh.approval.approved_apply_hint":"ui.mesh.approval.approved_details_missing")}),T&&t.jsx("p",{className:"text-meta text-ink-dim","data-tour-tag":"mesh-approval-file-key",children:s(V?"ui.mesh.approval.file_key_recorded":"ui.mesh.approval.file_key_disclosure")}),Z&&t.jsx(ct,{approvalId:e.approvalId,refusal:{code:G??"",sentence:Z}}),L&&t.jsx("p",{className:"text-meta text-ink-muted",children:s("ui.mesh.approval.retry_hint")}),V&&g&&t.jsx("p",{className:"text-meta text-ink-muted",children:s("ui.mesh.approval.cancel_hint")}),(N||g||L)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-tour-tag":"mesh-approval-controls",children:[L&&t.jsx(Q,{variant:"primary",size:"sm",disabled:a,"aria-describedby":z?`${M} ${A}`:M,onClick:()=>c(e.approvalId,"apply"),"data-tour-tag":"mesh-approval-retry-apply",children:s("ui.mesh.approval.try_again")}),N&&t.jsx(Q,{variant:"primary",size:"sm",disabled:a,"aria-describedby":z?`${M} ${A}`:M,onClick:()=>c(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:s("ui.mesh.mesh_approvals_tray.approve")}),g&&t.jsx(Q,{variant:"ghost",size:"sm",disabled:a,"aria-describedby":z?`${M} ${A}`:M,onClick:()=>c(e.approvalId,"deny"),"data-tour-tag":b?"mesh-approval-deny":"mesh-approval-stop",children:b?s("ui.mesh.mesh_approvals_tray.deny"):e.kind==="credential"?s("ui.mesh.approval.cancel_sharing"):$s(e.state)}),n&&t.jsx("span",{className:"text-meta text-ink-dim",children:n.decision==="approve"?e.typed?.unprovenHuman?s("ui.mesh.approval.signing_applying"):s("ui.mesh.mesh_approvals_tray.waiting_for_the_signing_prompt"):n.decision==="apply"?s("ui.mesh.approval.applying"):s("ui.mesh.mesh_approvals_tray.writing_the_decision")})]}),t.jsxs(ke,{chevronClassName:"text-ink-dim",summary:t.jsx("span",{className:"text-meta",children:s("ui.mesh.mesh_approvals_tray.details")}),children:[F.length>0&&t.jsx("ul",{className:"flex flex-col gap-1.5 text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-credential-consequences",children:F.map(E=>t.jsx("li",{children:E},E))}),f&&q?.disclosure?.recipient.keyFingerprint&&t.jsxs("p",{className:"text-meta text-ink-dim [overflow-wrap:anywhere]",children:[s("ui.mesh.approval.recipient_key",{device:f})," ",t.jsx("span",{className:"font-mono",children:q.disclosure.recipient.keyFingerprint})]}),G&&t.jsx("p",{className:"text-meta text-ink-dim font-mono",children:G}),q?.disclosure&&t.jsx(ke,{summary:t.jsx("span",{className:"text-meta",children:s("ui.mesh.approval.technical_request")}),children:t.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap text-meta text-ink-dim [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-signed-evidence",children:q.disclosure.evidence})}),k&&F.length===0&&(e.details?.length?t.jsx("ul",{className:"flex flex-col gap-1.5 text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-server-details",children:e.details.map((E,Y)=>t.jsx("li",{className:"whitespace-pre-wrap",children:E},`${Y}:${E}`))}):t.jsx("p",{className:"text-meta text-ink-muted",children:s("ui.mesh.approval.details_unavailable")})),m.length>0&&t.jsx("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta text-ink-dim","data-tour-tag":"mesh-approval-consequences",children:m.map(E=>t.jsxs(x.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{children:E.consequence})]},E.term))}),(w||S)&&t.jsxs("p",{className:"text-meta text-ink-muted",children:[w&&t.jsx("span",{children:w}),w&&S&&t.jsx("span",{children:" · "}),S&&t.jsx("span",{className:"font-mono",children:S})]}),R&&t.jsx("p",{className:"text-meta text-ink-dim",children:R}),P.length>0&&t.jsx("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta","data-tour-tag":"mesh-approval-consequence",children:P.map(E=>t.jsxs(x.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{className:"text-ink-muted",children:E.text})]},E.term))})]})]})},ct=({refusal:e,request:n,approvalId:a,requestIsBackendSummary:r=!1})=>{K();const c=ws();return t.jsx("p",{tabIndex:-1,className:"text-meta text-warning [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-refusal","data-approval-refusal-id":a,children:n?Yt(n,e.sentence).map((d,h)=>d.kind==="literal"?t.jsx(x.Fragment,{children:d.text},`literal:${h}`):t.jsx("bdi",{dir:Ut(d.kind,c,r),children:d.text},d.kind)):t.jsx("bdi",{dir:"auto",children:e.sentence})})},Fs=4,je={kind:"idle"};function qs(e){switch(e.kind){case"dragging":case"settling":return e.payload.session.id;case"pressing":return null;default:return null}}function de(e,n){switch(n.kind){case"press":return e.kind!=="idle"?e:{kind:"pressing",payload:n.payload,originX:n.x,originY:n.y,pointerId:n.pointerId};case"move":return e.kind==="pressing"?Math.max(Math.abs(n.x-e.originX),Math.abs(n.y-e.originY))<Fs?e:{kind:"dragging",payload:e.payload,x:n.x,y:n.y,target:n.target,pointerId:e.pointerId}:e.kind==="dragging"?{...e,x:n.x,y:n.y,target:n.target}:e;case"release":return e.kind==="dragging"?{kind:"settling",payload:e.payload,target:e.target}:e.kind==="pressing"?je:e;case"cancel":case"settled":return je;default:return e}}const Hs=({edges:e,geometry:n,selectedDeviceId:a})=>t.jsx("svg",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0 overflow-visible",width:n.bounds.width,height:n.bounds.height,children:e.map(r=>{const c=n.networks.get(r.networkId),d=n.devices.get(r.deviceId);if(!c||!d)return null;const h=a!==null&&r.deviceId===a;return t.jsx("path",{"data-mesh-edge":r.key,d:Kt(c,d),fill:"none",strokeWidth:h?2:1.5,className:h?"stroke-ink":"stroke-ink-dim"},r.key)})}),De=({deviceId:e,name:n,compact:a=!1,deviceIds:r,className:c})=>{K();const d=Je({name:n});return t.jsxs("span",{className:O("flex min-w-0 items-baseline gap-2",c),"data-mesh-device-identity":e,children:[t.jsx(Nt,{content:n?.trim()?d:null,children:t.jsx("span",{className:"min-w-0 flex-1 truncate text-start","data-mesh-device-name":"",children:d})}),t.jsx("span",{className:"shrink-0 font-mono text-meta text-ink-muted","data-mesh-device-id":"",title:e,children:a?gt(e,r):e})]})},zs={self:"border-l-hairline",reached:"border-l-hairline","relay-down":"border-l-warning","handshake-refused":"border-l-warning","address-unreachable":"border-l-warning","no-endpoint":"border-l-hairline","not-a-member":"border-l-hairline",unanswered:"border-l-warning","not-attempted":"border-l-hairline",unknown:"border-l-hairline"};function Ws(e){return e.suspect?"border-l-danger":zs[ue(e)]}const Bs={self:"ring-2 ring-accent",reachable:null,relay_down:null,handshake_refused:null,unreachable:null,suspect:null},Vs={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function Ys(e,n,a){return[Je(e),e.id,rt(e,n),a].filter(Boolean).join(", ")}function pe(e){return e.name.trim()||e.id.slice(-6)}function ut(e,n,a){if(a!=="reached"&&a!=="self"){const r=ge(a);return e.unreachable_reason?`${r} (${e.unreachable_reason})`:r}return e.live_state.trim()?e.live_state.trim():e.locality==="local"?s("ui.mesh.mesh_drop.on_this_device"):s("ui.mesh.mesh_node.on_device",{device:n})}const Us={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},Ks=({network:e,x:n,y:a,refused:r})=>(K(),t.jsxs("li",{"data-mesh-network":e.id,"data-mesh-network-refused":r?"true":void 0,"data-glass-block":"",className:O("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",r?"border-warning":"border-hairline"),style:{left:n,top:a,width:Ae,height:Gt},children:[t.jsx(Re,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block truncate text-body-sm text-ink",children:e.label}),t.jsxs("span",{title:s("ui.mesh.mesh_list.epoch",{epoch:e.epoch}),className:"block truncate text-meta text-ink-dim",children:[s("ui.mesh.mesh_graph.device_count",{count:e.memberCount}),e.revokedCount>0?t.jsxs(t.Fragment,{children:[" · ",s("ui.mesh.mesh_list.revoked_count",{count:e.revokedCount})]}):null]})]})]})),Gs=({device:e,deviceIds:n,x:a,y:r,nowSeconds:c,selected:d,sessions:h,sessionTotal:l,dropState:v,movingSessionId:b,draggedSessionId:y,onOpen:M,onChipPointerDown:A,onChipClick:u,onShowAllSessions:p})=>{K();const{activity:m}=_t(e,h.rows),w=m==="working",S=Ys(e,c,w?"working":null),R=ue(e);return t.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":v??void 0,"aria-current":d?"true":void 0,"data-glass-block":"",className:O("absolute flex flex-col rounded-md border border-l-4 border-control bg-elevated","hover:bg-row-hover",d&&"border-y-ink border-r-ink bg-row-selected",Ws(e),Bs[e.state],v&&Vs[v]),style:{left:a,top:r,width:Ae,height:Xt},children:[t.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":R,"aria-label":S,title:bt(e),onClick:()=>M(e.id),className:O("flex w-full flex-col justify-between rounded-t-[5px] px-3 pt-2 pb-2 text-start","cursor-pointer","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),style:{height:Zt},children:[t.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2",children:[t.jsx(Ns,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),t.jsx(De,{className:"min-w-0 flex-1 text-body-sm text-ink",deviceId:e.id,deviceIds:n,name:e.name,compact:!0}),e.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"})]}),t.jsxs("span",{className:"flex w-full min-w-0 items-baseline gap-1",children:[t.jsx("span",{className:"w-3 shrink-0 font-mono text-body-sm text-ink tabular-nums",children:e.sessionCount??"–"}),t.jsx("span",{className:O("min-w-0 truncate text-meta",e.sessionCount===null?"text-ink-dim":"text-ink-muted"),children:nt(e.sessionCount)})]}),t.jsxs("span",{"data-mesh-state-line":"",className:"flex w-full min-w-0 items-baseline gap-1.5 text-meta",children:[t.jsx("span",{"aria-hidden":"true",className:"shrink-0 text-ink-dim",children:kt[R]}),t.jsx("span",{className:O("shrink-0",Qe[R]),children:ge(R)}),w&&t.jsx("span",{"data-mesh-working":"",className:"shrink-0 text-info",children:s("ui.mesh.mesh_node.working")}),e.memberships.length>1&&t.jsx("span",{className:"min-w-0 truncate text-ink-dim",children:s("ui.mesh.mesh_node.memberships",{count:e.memberships.length})})]})]}),t.jsxs("ul",{"aria-label":s("ui.mesh.mesh_node.conversations_on",{device:le(e,n,!0)}),className:O("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",v==="accept"&&"opacity-40"),children:[h.shown.map(I=>t.jsx(Xs,{session:I,ownerLabel:le(e,n,!0),ownerReach:R,ownerReachable:e.reachable,moving:b===I.id,dragging:y===I.id,onPointerDown:A,onClick:()=>u(I)},I.id)),h.hidden>0&&t.jsx("li",{className:"shrink-0",children:t.jsxs("button",{type:"button","data-mesh-more":e.id,onClick:()=>p(e.id),className:O("flex min-h-6 items-center rounded-sm px-1.5 text-meta text-ink-dim","hover:bg-row-hover hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),title:s("ui.mesh.mesh_node.shown_conversations",{shown:h.shown.length,total:l}),"aria-label":s("ui.mesh.mesh_node.show_all_conversations",{count:l}),children:["+",h.hidden]})})]})]})},Xs=({session:e,ownerLabel:n,ownerReach:a,ownerReachable:r,moving:c,dragging:d,onPointerDown:h,onClick:l})=>{K();const v=ut(e,n,a);return c?t.jsx("li",{role:"status","data-mesh-session":e.id,"data-mesh-moving":"true",children:t.jsx("span",{className:"flex min-h-6 items-center rounded-sm bg-sunken px-1.5 text-meta text-ink-muted",children:s("ui.mesh.mesh_card.moving")})}):t.jsx("li",{className:"min-w-0 flex-1","data-mesh-session-item":e.id,"data-mesh-dragging":d?"true":void 0,children:t.jsx("button",{type:"button","data-mesh-session":e.id,style:{touchAction:"none"},title:`${pe(e)} · ${v}`,"aria-label":s("ui.mesh.mesh_node.open_conversation",{conversation:pe(e),fact:v,owner:n}),onPointerDown:b=>h(b,e),onClick:()=>l(e),className:O("flex min-h-6 w-full max-w-32 items-center rounded-sm border border-hairline bg-surface px-1.5 text-start text-meta text-ink-muted","cursor-grab active:cursor-grabbing","hover:text-ink",Us[Jt(e,r)],d&&"opacity-60","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:t.jsx("span",{className:"min-w-0 flex-1 truncate",children:pe(e)})})})};function Be(e){const n=e.trim();if(!n)return null;if(n.startsWith("[")){const r=n.indexOf("]");if(r<=1)return null;const c=n.slice(1,r),d=n.slice(r+1);if(!d)return{host:c,port:null};if(!d.startsWith(":"))return null;const h=Number(d.slice(1));return{host:c,port:Number.isInteger(h)?h:null}}const a=n.lastIndexOf(":");if(a>0){const r=n.slice(a+1);if(/^\d+$/.test(r))return{host:n.slice(0,a),port:Number(r)}}return{host:n,port:null}}function Ve(e){const n=e.trim().split(".");if(n.length!==4)return null;for(const a of n)if(!/^\d{1,3}$/.test(a)||Number(a)>255)return null;return`${n[0]}.${n[1]}.${n[2]}`}function Zs(e){return`${e}.x`}function Js(e){const n=new Map;for(const r of e.values())for(const c of r)n.set(c,(n.get(c)??0)+1);const a=new Set;for(const[r,c]of n)c>1&&a.add(r);return a}function Se(e){return new Set(e.endpoints.map(n=>n.trim()).filter(Boolean))}function Qs(e,n){const a=e.filter(u=>u.id!==n),r=e.find(u=>u.id===n)??null,c=new Map;for(const u of e)c.set(u.id,Se(u));const d=Js(c),h=new Set;for(const u of r?Se(r):[]){if(d.has(u))continue;const p=Be(u),m=p?Ve(p.host):null;m&&h.add(m)}const l=u=>{const p=new Set;for(const m of Se(u)){if(d.has(m))continue;const w=Be(m),S=w?Ve(w.host):null;S&&p.add(S)}return p},v=new Map,b=new Map;for(const u of a){const p=ea(u);if(p){v.set(p,[...v.get(p)??[],u.id]);continue}for(const m of l(u))b.set(m,[...b.get(m)??[],u.id])}const y=new Map(e.map((u,p)=>[u.id,p])),M=u=>[...u].sort((p,m)=>(y.get(p)??0)-(y.get(m)??0)),A=[];for(const[u,p]of v)A.push({prefix:u,tier:"declared",deviceIds:M(p),get words(){return s("ui.mesh.mesh_scope.declared")}});for(const[u,p]of b)h.has(u)?A.push({prefix:u,tier:"shared",deviceIds:M(p),get words(){return s("ui.mesh.mesh_scope.shared_with_this_device")}}):p.length>1&&A.push({prefix:u,tier:"probable",deviceIds:M(p),get words(){return s("ui.mesh.mesh_scope.same_prefix")}});return A.sort((u,p)=>u.tier.localeCompare(p.tier)||u.prefix.localeCompare(p.prefix))}function ea(e){for(const n of e.memberships){const a=n.scope.trim();if(a)return a}return""}const Ye={declared:0,shared:1,probable:2};function ta(e,n){const a=new Map;for(const c of e){let d=null;for(const l of c.deviceIds){const v=n.get(l);v!==void 0&&(d===null||v<d.slot)&&(d={id:l,slot:v})}if(d===null)continue;const h=a.get(d.id);h===void 0?a.set(d.id,{slot:d.slot,groups:[c]}):h.groups.push(c)}const r=c=>{let d=-1;for(const h of c.deviceIds){const l=n.get(h);l!==void 0&&l>d&&(d=l)}return d};return[...a.entries()].sort((c,d)=>c[1].slot-d[1].slot).map(([c,d])=>({deviceId:c,groups:d.groups.sort((h,l)=>r(l)-r(h)||Ye[h.tier]-Ye[l.tier]||h.prefix.localeCompare(l.prefix))}))}function sa(e){return new Map(e.map(n=>[n.deviceId,n.groups.length]))}function aa(e){return`${e.tier==="declared"?e.prefix:Zs(e.prefix)} · ${e.words}`}const Ue=(e,n)=>e.deviceIds.map(a=>n.devices.get(a)).filter(a=>a!==void 0),na=({stacks:e,geometry:n})=>(K(),t.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(a=>{const r=a.groups.length,c=new Array(r).fill(0);let d=null;for(let l=r-1;l>=0;l-=1){const v=Ue(a.groups[l],n),b=(v.length===0?0:Math.max(...v.map(y=>y.y+y.height)))+_e;d=d===null?b:Math.max(b,d+Ie),c[l]=d}const h=n.devices.get(a.deviceId);return a.groups.map((l,v)=>{const b=Ue(l,n);if(b.length===0)return null;const y=r-1-v,M=Math.min(...b.map(S=>S.x)),A=Math.max(...b.map(S=>S.x)),p=(h?.y??Math.min(...b.map(S=>S.y)))-_e-Qt*y,m=l.tier==="declared",w=aa(l);return t.jsx("div",{"data-mesh-scope":`${l.tier}:${l.prefix}`,"data-mesh-scope-level":v,className:O("absolute rounded-lg",l.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:M-_e-Ie*y,top:p,width:A+Ae-M+(_e+Ie*y)*2,height:c[v]-p},children:t.jsx("span",{"data-mesh-scope-label":"",className:O("absolute bottom-full left-1 mb-0.5 whitespace-nowrap text-meta",l.tier==="probable"?"text-ink-dim":"text-ink-muted",m&&"font-medium"),children:w})},`${l.tier}:${l.prefix}`)})})})),Ke=48,Ge=1.25,ra=.0015,ia=({graph:e,slots:n,nowSeconds:a,selectedDeviceId:r,sessions:c,sessionTotals:d,movingSessionId:h,canMove:l,onOpenDevice:v,onAskMove:b,onDropRefused:y,onShowAllSessions:M,summaryId:A})=>{K();const u=x.useRef(null),[p,m]=x.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[w,S]=x.useState({k:1,tx:0,ty:0}),R=x.useRef(!1),I=x.useRef(!1),k=x.useRef(null),D=x.useMemo(()=>Qs(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),P=x.useMemo(()=>ta(D,n.devices),[D,n]),C=x.useMemo(()=>es(n,sa(P)),[n,P]),N=x.useMemo(()=>({selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(i=>[i.id,i])),networks:new Map(e.networks.map(i=>[i.id,i]))}),[e]),[g,L]=x.useState(je),ee=x.useRef({kind:"ground"}),q=x.useCallback((i,o)=>{const _=document.elementFromPoint(i,o),$=_?.closest("[data-mesh-device]");if($){const ie=$.getAttribute("data-mesh-device");if(ie)return{kind:"device",deviceId:ie}}const U=_?.closest("[data-mesh-network]");if(U){const ie=U.getAttribute("data-mesh-network");if(ie)return{kind:"network",networkId:ie}}return{kind:"ground"}},[]),F=x.useMemo(()=>g.kind!=="dragging"&&g.kind!=="settling"?null:ye(g.payload,g.target,N),[g,N]),f=x.useCallback(i=>{if(!F)return null;if(F.kind==="plan"){const o=g.kind==="dragging"||g.kind==="settling"?g.target:null;return o&&o.kind==="device"&&o.deviceId===i?"accept":null}if(F.kind==="refused"){const o=g.kind==="dragging"||g.kind==="settling"?g.target:null;return o&&o.kind==="device"&&o.deviceId===i?"refuse":null}return null},[F,g]),T=x.useCallback((i,o)=>{if(!l||i.button!==0)return;I.current=!1;const _=o.locality==="local"?e.selfDeviceId??"":o.owner_device,$=N.devices.get(_),U={session:o,ownerDeviceId:_,ownerLabel:$?le($,[...N.devices.keys()],!0):o.owner_device_name};try{i.currentTarget.setPointerCapture(i.pointerId)}catch{}L(ie=>de(ie,{kind:"press",payload:U,x:i.clientX,y:i.clientY,pointerId:i.pointerId}))},[l,N,e.selfDeviceId]),V=i=>{if(g.kind==="pressing"||g.kind==="dragging"){const o=q(i.clientX,i.clientY);ee.current=o,L(_=>de(_,{kind:"move",x:i.clientX,y:i.clientY,target:o}));return}H(i)},Z=i=>{if(ne(i),g.kind!=="pressing"&&g.kind!=="dragging")return;if(g.kind==="pressing"){L(_=>de(_,{kind:"cancel"}));return}const o=ye(g.payload,g.target,N);I.current=!0,L(_=>de(_,{kind:"release"})),o.kind==="plan"?b({plan:o.plan,alternatives:o.alternatives,risky:o.risky}):o.kind==="refused"&&y({code:o.code,sentence:o.sentence,reach:o.reach,remedy:o.remedy,plan:o.plan??null}),L(_=>de(_,{kind:"settled"}))};x.useEffect(()=>()=>L(je),[]);const G=x.useCallback(()=>{S(He(C.bounds,p))},[C.bounds,p]);x.useEffect(()=>{const i=u.current;if(!i)return;const o=()=>{const $=i.getBoundingClientRect();m({width:$.width,height:$.height,clipWidth:i.clientWidth,clipHeight:i.clientHeight,left:$.left,top:$.top})};o();const _=new ResizeObserver(o);return _.observe(i),()=>_.disconnect()},[]),x.useEffect(()=>{R.current||p.width<=0||p.height<=0||(R.current=!0,S(He(C.bounds,p)))},[p,C.bounds]),x.useEffect(()=>{const i=k.current;if(k.current={width:p.width,height:p.height},!i||!R.current||p.width<=0||p.height<=0||p.width>=i.width&&p.height>=i.height||!r)return;const o=C.devices.get(r);o&&S(_=>{const $={width:p.clipWidth,height:p.clipHeight},U=Math.max(0,Math.min($.width-C.bounds.width*_.k,$.height-C.bounds.height*_.k));return ts(_,o,$,Math.min(ss,U))})},[p,r,C]);const z=g.kind==="dragging"?{x:g.x-p.left+12,y:g.y-p.top+12}:{x:0,y:0},ae=F?Is(F):null,E=x.useRef(null),Y=x.useRef(null),te=x.useRef(null),j=x.useRef(null),W=x.useCallback(()=>{te.current=null;const i=E.current,o=Y.current;if(E.current=null,Y.current=null,i){const _=j.current;if(!_)return;S({k:_.transform.k,tx:_.transform.tx+(i.x-_.x),ty:_.transform.ty+(i.y-_.y)});return}o&&S(_=>Ce(_,{x:o.x,y:o.y},_.k*Math.exp(-o.deltaY*ra)))},[]),B=x.useCallback(()=>{te.current===null&&(te.current=requestAnimationFrame(W))},[W]);x.useEffect(()=>()=>{te.current!==null&&cancelAnimationFrame(te.current)},[]);const J=i=>{!(i.target===i.currentTarget)&&i.button!==1||i.button!==0&&i.button!==1||(j.current={x:i.clientX,y:i.clientY,transform:w},i.currentTarget.setPointerCapture(i.pointerId),i.preventDefault())},H=i=>{j.current&&(E.current={x:i.clientX,y:i.clientY},B())},ne=i=>{j.current&&(j.current=null,E.current=null,i.currentTarget.hasPointerCapture(i.pointerId)&&i.currentTarget.releasePointerCapture(i.pointerId))},re=x.useCallback(i=>{if(i.deltaY===0)return;i.preventDefault();const o=i.currentTarget.getBoundingClientRect();Y.current={x:i.clientX-o.left,y:i.clientY-o.top,deltaY:i.deltaY},B()},[B]);x.useEffect(()=>{const i=u.current;if(i)return i.addEventListener("wheel",re,{passive:!1}),()=>i.removeEventListener("wheel",re)},[re]);const he=i=>{const o=i.shiftKey?Ke*4:Ke;switch(i.key){case"Escape":if(g.kind!=="pressing"&&g.kind!=="dragging")return;i.preventDefault(),g.kind==="dragging"&&(I.current=!0),L(_=>de(_,{kind:"cancel"}));return;case"0":i.preventDefault(),G();return;case"+":case"=":i.preventDefault(),S(_=>Ce(_,{x:p.width/2,y:p.height/2},_.k*Ge));return;case"-":case"_":i.preventDefault(),S(_=>Ce(_,{x:p.width/2,y:p.height/2},_.k/Ge));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{i.preventDefault();const _=i.key==="ArrowLeft"?o:i.key==="ArrowRight"?-o:0,$=i.key==="ArrowUp"?o:i.key==="ArrowDown"?-o:0;S(U=>({...U,tx:U.tx+_,ty:U.ty+$}));return}}};return t.jsxs("div",{ref:u,"data-mesh-canvas":"",role:"group","aria-labelledby":A,tabIndex:0,onPointerDown:J,onPointerMove:V,onPointerUp:Z,onPointerCancel:i=>{g.kind==="dragging"&&(I.current=!0),L(o=>de(o,{kind:"cancel"})),ne(i)},"data-mesh-gesture":g.kind,"data-glass-well":"clear",onKeyDown:he,onDoubleClick:i=>{i.target===i.currentTarget&&G()},className:O("relative min-h-0 flex-1 overflow-hidden rounded-lg border border-hairline bg-sunken","[touch-action:none]","cursor-grab active:cursor-grabbing","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),children:[t.jsx("div",{"data-mesh-ground":"","aria-hidden":"true",className:"mesh-ground pointer-events-none absolute inset-0",style:{backgroundPosition:`${w.tx}px ${w.ty}px`}}),t.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${w.tx}px, ${w.ty}px, 0) scale(${w.k})`,transformOrigin:"0 0",width:C.bounds.width,height:C.bounds.height},children:[t.jsx(na,{stacks:P,geometry:C}),t.jsx(Hs,{edges:e.edges,geometry:C,selectedDeviceId:r}),t.jsx("ul",{"aria-label":s("ui.mesh.mesh_canvas.networks"),className:"m-0 list-none p-0",children:e.networks.map(i=>{const o=C.networks.get(i.id);return o?t.jsx(Ks,{network:i,x:o.x,y:o.y,refused:F?.kind==="refused"&&g.kind==="dragging"&&g.target.kind==="network"&&g.target.networkId===i.id},i.id):null})}),t.jsx("ul",{"aria-label":s("ui.mesh.mesh_canvas.devices"),className:"m-0 list-none p-0",children:e.devices.map(i=>{const o=C.devices.get(i.id);return o?t.jsx(Gs,{device:i,deviceIds:e.devices.map(_=>_.id),x:o.x,y:o.y,nowSeconds:a,selected:i.id===r,sessions:c.get(i.id)??{rows:[],shown:[],hidden:0},sessionTotal:d.get(i.id)??i.sessionCount??0,dropState:f(i.id),movingSessionId:h,draggedSessionId:qs(g),onOpen:v,onChipPointerDown:T,onChipClick:()=>{if(I.current){I.current=!1;return}v(i.id)},onShowAllSessions:M},i.id):null})})]}),g.kind==="dragging"&&t.jsx("div",{"data-mesh-ghost":"","aria-hidden":"true",className:"pointer-events-none absolute z-10 max-w-40 truncate rounded-sm border border-ink-dim bg-surface px-1.5 py-0.5 text-meta text-ink",style:{left:z.x,top:z.y},children:g.payload.session.name||"untitled"}),g.kind==="dragging"&&ae&&t.jsx("div",{"data-mesh-indicator":"",className:O("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",F?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:z.x,maxWidth:Math.max(160,p.width-z.x-12),...z.y>p.height*.6?{bottom:Math.max(12,p.height-z.y+8)}:{top:z.y+24}},children:ae})]})};function la(e,n,a,r){const c=a.locality==="local"?n:a.owner_device,d=[],h=e.map(l=>l.id);for(const l of e){if(l.id===c)continue;if(l.id===n){d.push({deviceId:l.id,label:r,verb:s("ui.mesh.mesh_card.recall_to_this_device"),keepVerb:s("ui.mesh.mesh_card.copy_here_leave_it_there")});continue}const v=le(l,h,!0);d.push({deviceId:l.id,label:v,verb:s("ui.mesh.mesh_card.move_to",{device:v}),keepVerb:s("ui.mesh.mesh_card.copy_to",{device:v})})}return d}function oa(e,n,a){return la(e.devices,e.selfDeviceId,n,a)}function mt(e,n,a){const r=oa(e,n,a),c={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(l=>[l.id,l])),networks:new Map(e.networks.map(l=>[l.id,l]))},d=n.locality==="local"?e.selfDeviceId??"":n.owner_device,h=c.devices.get(d);return r.map(l=>{const v=ye({session:n,ownerDeviceId:d,ownerLabel:h?le(h,e.devices.map(b=>b.id),!0):n.owner_device_name},{kind:"device",deviceId:l.deviceId},c);return{...l,refused:v.kind==="refused"&&v.code!=="busy"?v.sentence:null}})}const pt=({session:e,destinations:n,disabled:a,onChoose:r,onOpenChange:c,trigger:d,triggerLabel:h})=>(K(),t.jsxs(Ct,{onOpenChange:c,children:[t.jsx(St,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":h,"data-mesh-session-menu":e.id,disabled:a||n.length===0,className:"rounded-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2 disabled:text-ink-disabled",children:d})}),t.jsxs(At,{align:"start",className:"min-w-56",children:[t.jsx(Mt,{children:pe(e)}),t.jsx(Le,{}),n.map(l=>t.jsx($e,{"data-mesh-move-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>r(l,!1),children:l.verb},l.deviceId)),t.jsx(Le,{}),n.map(l=>t.jsx($e,{"data-mesh-copy-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>r(l,!0),children:l.keepVerb},`keep-${l.deviceId}`))]})]})),da=({device:e,deviceIds:n,sessions:a,sessionTotal:r,nowSeconds:c,destinationsFor:d,movingSessionId:h,canMove:l,canInvite:v,onClose:b,onMove:y,onShowInList:M,onInvite:A,onRemoveMember:u})=>{K();const p=ue(e),m=et(e),w=e.reachable?[]:e.attempts??[];x.useEffect(()=>{const k=D=>{D.key!=="Escape"||D.defaultPrevented||D.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),b())};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[e.id,b]);const S=e.sessionCount===null?nt(null):s("ui.mesh.mesh_card.conversation_count",{count:e.sessionCount}),R=e.suspect?tt():[S,ge(p)].filter(Boolean).join(" · "),I=r>a.rows.length?s("ui.mesh.mesh_card.shown_of",{shown:a.rows.length,total:r}):`${a.rows.length}`;return t.jsxs("aside",{"aria-label":s("ui.mesh.mesh_card.device_details",{device:le(e)}),"data-mesh-panel":e.id,"data-glass-block":"",className:"flex w-80 shrink-0 flex-col gap-3 overflow-y-auto rounded-md border border-hairline bg-surface p-4",children:[t.jsxs("header",{className:"flex flex-col gap-1",children:[t.jsx(Q,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:b,children:s("ui.mesh.mesh_actions.close")}),t.jsx("h2",{className:"text-body-sm text-ink",children:t.jsx(De,{deviceId:e.id,deviceIds:n,name:e.name,compact:!0})}),t.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[e.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 text-danger"}),!e.suspect&&p==="unanswered"&&t.jsx(It,{"aria-hidden":"true",className:"size-3.5 text-warning"}),R]})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.memberships")}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:e.memberships.map(k=>t.jsxs("li",{className:"flex flex-col gap-1",children:[t.jsxs("span",{className:"flex items-center gap-2 text-body-sm text-ink",children:[t.jsx(Re,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),k.networkName]}),t.jsxs("span",{className:"text-meta text-ink-dim",children:[k.role||"member",k.capabilities.length>0?` · ${k.capabilities.join(", ")}`:""]}),v&&t.jsxs(Q,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${k.networkId}:${e.id}`,onClick:()=>u(e,k.networkId),children:[s("ui.mesh.mesh_card.remove_from"),k.networkName,"…"]})]},k.networkId))}),v&&t.jsx(Q,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":e.id,onClick:()=>A(e),children:s("ui.mesh.mesh_actions.invite_to_a_network")})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex shrink-0 flex-col gap-2",children:[t.jsxs("h3",{className:"text-meta text-ink-dim",children:[s("ui.mesh.mesh_card.conversations"),t.jsxs("span",{className:"text-ink-disabled",children:["(",ue(e)!=="self"&&ue(e)!=="reached"?it(null):I,")"]})]}),be(e,c)?t.jsx("p",{className:"text-meta text-warning",children:be(e,c)}):a.rows.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:e.sessionCount===null?s("ui.mesh.mesh_card.this_device_did_not_report_its_conversations"):s("ui.mesh.mesh_card.no_conversations_here")}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:a.rows.map(k=>t.jsxs("li",{"data-mesh-panel-session":k.id,className:O("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",h===k.id&&"border-control"),children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",title:pe(k),children:pe(k)}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:ut(k,le(e,n,!0),ue(e))}),h===k.id?t.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:s("ui.mesh.mesh_card.moving")}):t.jsx(pt,{session:k,destinations:d(k),disabled:!l,onChoose:(D,P)=>y(k,D,P),trigger:t.jsx(ot,{"aria-hidden":"true",className:"size-4"}),triggerLabel:s("ui.mesh.mesh_card.move_conversation",{conversation:pe(k)})})]},k.id))})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.network_addresses")}),e.endpoints.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.no_address_published")}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:e.endpoints.map(k=>t.jsxs("li",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("span",{className:"min-w-0 truncate font-mono text-body-sm text-ink",children:k}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:s("ui.mesh.mesh_card.advertised")})]},k))})]}),t.jsx(xe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.status")}),t.jsxs("dl",{className:"m-0 flex flex-col gap-1",children:[t.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("dt",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.reach")}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:ge(p)})]}),t.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("dt",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_card.last_status_frame")}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:e.lastSeenAt===null?s("ui.mesh.mesh_card.never"):as(c-e.lastSeenAt)})]})]}),!e.reachable&&(m!==""||w.length>0)&&t.jsxs("div",{className:"flex flex-col gap-1",children:[m&&t.jsx("p",{className:"m-0 text-meta text-warning",children:m}),e.linkState==="handshake_refused"&&t.jsx("p",{className:"m-0 text-meta text-ink-dim",children:s("ui.mesh.mesh_reach.handshake_refused_hint")}),w.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{id:`mesh-attempts-label-${e.id}`,className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_reach.addresses_tried")}),t.jsx("ul",{role:"list","aria-labelledby":`mesh-attempts-label-${e.id}`,className:"m-0 flex list-none flex-col gap-0.5 p-0",children:w.map((k,D)=>{const P=st(k.detail);return t.jsxs("li",{"data-mesh-attempt":k.endpoint,className:"flex items-baseline justify-between gap-2",children:[t.jsx("span",{className:"min-w-0 truncate font-mono text-meta text-ink",children:k.endpoint}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:P})]},`${k.endpoint}:${D}`)})})]})]}),!m&&w.length===0&&e.reason&&t.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),t.jsx(xe,{}),t.jsx(Q,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>M(e.id),children:s("ui.mesh.mesh_card.show_in_list")})]})},ca=["name","chats","state"],ua={get name(){return s("ui.mesh.mesh_list.name")},get chats(){return s("ui.mesh.mesh_list.sort_conversations")},get state(){return s("ui.mesh.mesh_list.state")}},Xe={suspect:0,relay_down:1,handshake_refused:2,unreachable:3,self:4,reachable:5};function ma(e,n){const a=[...e];switch(n){case"chats":return a.sort((r,c)=>(c.sessionCount??-1)-(r.sessionCount??-1)||r.label.localeCompare(c.label)),a;case"state":return a.sort((r,c)=>Xe[r.state]-Xe[c.state]||r.label.localeCompare(c.label)),a;default:return a.sort((r,c)=>r.label.localeCompare(c.label))}}const Ze=8;function pa(e,n){if(e.locality==="local")return e.live_state||"here";const a=e.owner_device_name||n,r=e.live_state?` · ${e.live_state}`:"";return e.reachable?s("ui.mesh.mesh_list.on_device_state",{device:a,state:r}):s("ui.mesh.mesh_list.on_device_no_answer",{device:a})}const ha=({graph:e,nowSeconds:n,selectedDeviceId:a,sessions:r,selfLabel:c,canMove:d,onSelect:h,onMove:l,onInvite:v,onRemove:b})=>{K();const[y,M]=x.useState("name"),A=x.useMemo(()=>e.networks.map(u=>({network:u,members:ma(e.devices.filter(p=>p.memberships.some(m=>m.networkId===u.id)),y)})),[e,y]);return t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pe-1",children:[t.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[t.jsx("legend",{className:"sr-only",children:s("ui.mesh.mesh_list.sort_devices_by")}),t.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:ca.map(u=>t.jsx("button",{type:"button","aria-pressed":y===u,onClick:()=>M(u),className:O("h-6 rounded-sm px-3 text-body-sm text-ink-muted transition-colors duration-fast ease-out-quart","hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2",y===u&&"bg-surface text-ink"),children:ua[u]},u))})]}),A.map(({network:u,members:p})=>t.jsxs("section",{"data-mesh-network-group":u.id,className:"flex flex-col gap-2",children:[t.jsxs("h2",{className:"flex flex-wrap items-baseline gap-2 text-body-sm text-ink",title:s("ui.mesh.mesh_list.epoch",{epoch:u.epoch}),children:[u.label,t.jsxs("span",{className:"text-meta text-ink-dim",children:[u.trust," ·"," ",s("ui.mesh.mesh_graph.device_count",{count:u.memberCount}),u.revokedCount>0?t.jsxs(t.Fragment,{children:[" · ",s("ui.mesh.mesh_list.revoked_count",{count:u.revokedCount})]}):null]})]}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:p.map(m=>{const w=m.memberships.find(N=>N.networkId===u.id),S=m.id===a,R=r.get(m.id),I=R?.rows??[],k=R?lt(R,m.sessionCount):m.sessionCount??0,D=ue(m),P=et(m),C=m.reachable?[]:m.attempts??[];return t.jsxs("li",{"data-mesh-device-row":m.id,"data-mesh-state":m.state,"aria-current":S?"true":void 0,className:O("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",S&&"border-ink bg-row-selected"),children:[t.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[t.jsx("button",{type:"button","data-mesh-device-open":m.id,onClick:()=>h(m.id),className:O("min-w-0 flex-1 text-start text-body-sm text-ink","hover:text-ink-muted","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:t.jsx(De,{deviceId:m.id,name:m.name})}),t.jsxs("span",{className:O("flex shrink-0 items-center gap-1 text-meta",Qe[D]),"data-mesh-reach":D,children:[m.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),m.suspect?ge(D):rt(m,n),m.suspect&&t.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:tt()})]}),t.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[w?.role?`${w.role} · `:"",s("ui.mesh.mesh_list.member")]})]}),(P!==""||C.length>0)&&!m.reachable&&t.jsxs("div",{className:"flex flex-col gap-0.5",children:[P&&t.jsx("span",{className:"text-meta text-warning",children:P}),C.map((N,g)=>{const L=st(N.detail);return t.jsx("span",{"data-mesh-attempt":N.endpoint,className:"text-meta text-ink-dim",children:L?`${N.endpoint} — ${L}`:N.endpoint},`${N.endpoint}:${g}`)})]}),be(m,n)?t.jsxs("span",{className:"text-meta text-warning",children:[s("ui.mesh.mesh_card.conversations")," (",it(null),") ·"," ",be(m,n)]}):I.length>0?t.jsxs(t.Fragment,{children:[t.jsx(xe,{className:"my-1"}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:I.slice(0,Ze).map(N=>t.jsxs("li",{"data-mesh-row-session":N.id,className:"flex items-center gap-2 py-0.5",children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-meta text-ink-muted",children:N.name||N.id}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:pa(N,c)}),t.jsx(pt,{session:N,destinations:mt(e,N,c),disabled:!d,onChoose:(g,L)=>l(N,g,L),trigger:t.jsx(ot,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:s("ui.mesh.mesh_list.move_conversation",{conversation:N.name||N.id})})]},N.id))}),k>I.slice(0,Ze).length&&t.jsx("button",{type:"button",onClick:()=>h(m.id),className:"w-fit text-meta text-ink-dim hover:text-ink",children:s("ui.mesh.mesh_list.show_all_panel",{count:k})})]}):t.jsx("span",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_list.conversation_count",{count:k})}),(w||m.state!=="self")&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(Q,{size:"sm",variant:"ghost","data-mesh-invite":m.id,onClick:()=>v({deviceId:m.id,deviceName:m.name}),children:s("ui.mesh.mesh_actions.invite_to_a_network")}),w&&t.jsxs(Q,{size:"sm",variant:"ghost","data-mesh-remove-member":`${u.id}:${m.id}`,onClick:()=>b({networkId:u.id,networkLabel:u.label,deviceId:m.id,deviceName:m.name}),children:[s("ui.mesh.mesh_card.remove_from"),u.label,"…"]})]})]},m.id)})})]},u.id)),e.unmatchedPeers.length>0&&t.jsxs("p",{className:"text-meta text-warning",children:[s("ui.mesh.mesh_graph.device_count",{count:e.unmatchedPeers.length})," ",s("ui.mesh.mesh_list.answered_the_peer_read_but_is_in")]})]})},xa=({revoked:e})=>{if(e.length===0)return null;const n=s("ui.mesh.mesh_list.revoked_count",{count:e.length});return t.jsx(ke,{className:"contents",chevron:"trailing",chevronClassName:"text-ink-dim",rowClassName:"min-h-auto py-0",triggerClassName:"inline-flex w-auto items-center gap-1 align-baseline text-meta text-ink-dim hover:text-ink",triggerData:{"data-mesh-revoked-toggle":""},triggerLabel:s("ui.mesh.mesh_list.revoked_toggle_label"),summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",className:"inline-block whitespace-pre",children:" · "}),n]}),children:t.jsx("ul",{"data-mesh-revoked":"",className:"m-0 flex list-none flex-col gap-1 p-0",children:e.map(a=>t.jsxs("li",{"data-mesh-revoked-member":a.deviceId,className:"flex flex-wrap items-baseline gap-x-2 text-meta text-ink-dim",children:[t.jsx("span",{children:a.networkName}),t.jsx("span",{className:"font-mono text-body-sm text-ink",children:a.deviceId}),t.jsx("span",{className:"text-body-sm text-ink-muted",children:a.label}),t.jsxs("span",{children:[a.role?`${a.role} · `:"",s("ui.mesh.mesh_graph.revoked_membership")]})]},`${a.networkId}:${a.deviceId}`))})})},fa=["canvas","list"],va={get canvas(){return s("ui.mesh.mesh_page.canvas")},get list(){return s("ui.mesh.mesh_page.list")}},ga=({state:e,initialPresentation:n="canvas",graph:a,nowSeconds:r,checking:c,staleError:d,onRetry:h,approvals:l,sessions:v,sessionError:b,selfLabel:y,movingSessionId:M,canMove:A,pendingMove:u,onAskMove:p,onDropRefused:m,onChooseMove:w,onCancelMove:S,moveBusy:R,moveReport:I,onDismissReport:k,onWaitForIdle:D,onUndoCopy:P,invite:C,onOpenInvite:N,onInvite:g,onCloseInvite:L,inviteBusy:ee,inviteReceipt:q,inviteRefusal:F,remove:f,onOpenRemove:T,onRemove:V,onCloseRemove:Z,removeBusy:G,removeRefusal:z,removed:ae})=>{K();const[E,Y]=x.useState(n),[te,j]=x.useState(null),W=a?ns(a):"",B="mesh-summary",J=rs(a),H=is(a,v,a?.selfDeviceId??null),ne=x.useMemo(()=>{const o=new Map;for(const _ of a?.devices??[]){const $=H.byDevice.get(_.id);o.set(_.id,$?lt($,_.sessionCount):_.sessionCount??0)}return o},[a,H]),re=x.useCallback(o=>{j(o)},[]),he=a?a.devices.find(o=>o.id===te)??null:null,i=x.useCallback((o,_,$)=>{if(!a)return null;const U={selfDeviceId:a.selfDeviceId,devices:new Map(a.devices.map(se=>[se.id,se])),networks:new Map(a.networks.map(se=>[se.id,se]))},ie=o.locality==="local"?a.selfDeviceId??"":o.owner_device,Ee=U.devices.get(ie),X=ye({session:o,ownerDeviceId:ie,ownerLabel:Ee?le(Ee,a.devices.map(se=>se.id),!0):o.owner_device_name},{kind:"device",deviceId:_.deviceId},U);if(X.kind==="refused")return m({code:X.code,sentence:X.sentence,reach:X.reach,remedy:X.remedy,plan:X.plan??null}),null;if(X.kind==="none")return null;const Pe=$?X.alternatives.find(se=>se.keep)??X.plan:X.plan,ht=[X.plan,...X.alternatives].filter(se=>se.keep!==Pe.keep),xt={plan:Pe,alternatives:ht,risky:X.risky};p(xt)},[a,p,m]);return t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[t.jsx(wt,{title:s("ui.mesh.mesh_page.mesh"),icon:Re,subtitle:s("ui.mesh.mesh_page.devices_this_app_is_paired_with_and"),children:t.jsxs("div",{className:"flex items-center gap-4",children:[c&&t.jsx("output",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_page.checking")}),(e.kind==="ready"||e.kind==="loading")&&t.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[t.jsx("legend",{className:"sr-only",children:s("ui.mesh.mesh_page.presentation")}),t.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:fa.map(o=>t.jsx("button",{type:"button","data-mesh-presentation":o,"aria-pressed":E===o,disabled:e.kind!=="ready",onClick:()=>Y(o),className:O("h-6 rounded-sm px-3 text-body-sm text-ink-muted transition-colors duration-fast ease-out-quart","hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2","disabled:text-ink-dim disabled:hover:text-ink-dim",E===o&&"bg-surface text-ink"),children:va[o]},o))})]})]})}),t.jsx(Os,{rows:l.rows,error:l.error,pending:l.pending,refusal:l.decisionRefusal,onDecide:l.onDecide,onRetry:l.onRetry,nowSeconds:l.nowSeconds,credentialApprovals:l.credentialApprovals,profileApprovals:l.profileApprovals,networkNames:new Map((a?.networks??[]).map(o=>[o.id,o.label]))}),e.kind==="loading"&&t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[t.jsx(Te,{className:"h-4 w-64"}),t.jsx(Te,{className:"min-h-40 w-full flex-1"})]}),e.kind==="error"&&t.jsxs(Ne,{variant:"warning",className:"flex-col items-start gap-2",children:[t.jsx("p",{children:e.message}),t.jsx(Q,{variant:"secondary",size:"sm",onClick:h,className:"w-fit",children:s("ui.mesh.mesh_approvals_tray.ask_again")})]}),e.kind==="empty"&&t.jsx("div",{"data-glass-block":"",className:"flex min-h-0 flex-1 items-center justify-center rounded-lg border border-hairline bg-surface p-6",children:t.jsxs("div",{className:"flex flex-col items-start gap-3",children:[t.jsx("h2",{className:"text-heading text-ink",children:s("ui.mesh.mesh_page.no_network_on_this_device")}),t.jsx("p",{className:"max-w-140 text-body-sm text-ink-muted",children:s("ui.mesh.mesh_page.this_device_is_not_in_any_network")}),t.jsx("code",{className:"rounded-sm bg-sunken px-2 py-1 font-mono text-meta text-ink",children:"lop network init <name>"}),t.jsx("p",{className:"text-meta text-ink-dim",children:s("ui.mesh.mesh_page.a_network_appears_here_once_this_device")})]})}),e.kind==="ready"&&a&&t.jsx(t.Fragment,{children:t.jsxs("div",{className:"flex min-h-[22rem] flex-1 gap-4",children:[t.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-3",children:[t.jsxs("div",{id:B,className:"text-meta text-ink-muted","data-mesh-summary":"",children:[t.jsx("span",{children:W}),t.jsx(xa,{revoked:a.revoked})]}),d&&t.jsx(Ne,{variant:"warning",children:t.jsx("p",{children:d})}),b&&t.jsx(Ne,{variant:"warning",children:t.jsx("p",{children:b})}),I&&t.jsx(ls,{receipt:I.kind==="moved"?{verb:I.verb,detail:I.detail,undo:I.undo}:null,refusal:I.kind==="refused"?I.refusal:null,canWait:I.kind==="refused"&&I.plan!==null,onWait:D,onRecheck:h,onUndo:P,onDismiss:k,pending:R}),E==="canvas"?t.jsx(ia,{graph:a,slots:J,nowSeconds:r,selectedDeviceId:te,sessions:H.byDevice,sessionTotals:ne,movingSessionId:M,canMove:A,onOpenDevice:re,onAskMove:p,onDropRefused:m,onShowAllSessions:re,summaryId:B}):t.jsx(ha,{graph:a,nowSeconds:r,selectedDeviceId:te,sessions:H.byDevice,selfLabel:y,canMove:A,onSelect:re,onMove:i,onInvite:N,onRemove:T})]}),he&&t.jsx(da,{device:he,deviceIds:a.devices.map(o=>o.id),sessions:H.byDevice.get(he.id)??{rows:[],shown:[],hidden:0},sessionTotal:ne.get(he.id)??0,nowSeconds:r,canMove:A,canInvite:e.kind==="ready",movingSessionId:M,destinationsFor:o=>mt(a,o,y),onClose:()=>j(null),onMove:i,onInvite:o=>N({deviceId:o.id,deviceName:o.name}),onRemoveMember:(o,_)=>{const $=a.networks.find(U=>U.id===_);T({networkId:_,networkLabel:$?.label??_,deviceId:o.id,deviceName:o.name})},onShowInList:o=>{re(o),Y("list")}})]})}),t.jsx(os,{open:u!==null,plan:u?.plan??_a,alternatives:u?.alternatives??[],risky:u?.risky??!1,busy:R,onCancel:S,onChoose:w}),C&&t.jsx(ds,{open:C.open,options:C.options,deviceId:C.deviceId,deviceName:C.deviceName,onClose:L,onInvite:g,pending:ee,receipt:q,refusal:F}),f&&t.jsx(cs,{open:f.open,networkLabel:f.networkLabel,deviceId:f.deviceId,deviceName:f.deviceName,onClose:Z,onConfirm:V,pending:G,refusal:z,removed:ae})]})},_a={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},Ma=({initialPresentation:e})=>{K();const n=yt(),a=fe(n.data,"peers")==="enabled",r=fe(n.data,"session_transfer")==="enabled",c=us(a,{stamp:()=>we.getState().beginAnswer()}),d=ms(a),h=ps(a,{poll:!1,stamp:()=>we.getState().beginAnswer()}),l=x.useMemo(()=>({peers:c,networks:d}),[c,d]),v=hs(l),b=xs(l),y=fs(),M=fe(n.data,"approvals")==="enabled",A=vs(a&&M,{poll:!1}),u=gs(),p=fe(n.data,"credential_approvals")==="enabled",m=fe(n.data,"profile_approvals")==="enabled",w=u.isError?{approvalId:u.variables?.approvalId??null,submittedAt:u.submittedAt,..._s(u.error)}:null,S=x.useMemo(()=>Math.floor((A.dataUpdatedAt||Date.now())/1e3),[A.dataUpdatedAt]),R=we(j=>j.settlePlacement),I=bs(),k=ks(),[D,P]=x.useState(null),[C,N]=x.useState(null),[g,L]=x.useState(null),[ee,q]=x.useState(null),[F,f]=x.useState(null),[T,V]=x.useState(null),[Z,G]=x.useState(null),z=x.useMemo(()=>{const j=Math.max(c.dataUpdatedAt,d.dataUpdatedAt);return Math.floor((j||Date.now())/1e3)},[c.dataUpdatedAt,d.dataUpdatedAt]),ae=x.useCallback(()=>{c.refetch(),d.refetch(),h.refetch()},[c,d,h]),E=x.useCallback((j,W)=>{P(null);const B={sessionId:j.sessionId,to:j.to,keep:j.keep,waitS:W??j.waitS};y.mutate(B,{onSuccess:J=>{if(J.kind==="moved"){const{receipt:H}=J;R(j.sessionId,H);const ne=H.locality==="local"?s("ui.mesh.mesh_drop.this_device"):b?.devices.find(re=>re.id===H.owner_device)?.label??H.owner_device;N({kind:"moved",verb:H.mode==="keep"?s("ui.mesh.mesh_page.copied"):s("ui.mesh.mesh_page.moved"),detail:H.mode==="keep"?s("ui.mesh.mesh_page.copy_receipt",{destination:ne,suffix:H.new_session_id.slice(-6)}):s("ui.mesh.mesh_page.move_receipt",{destination:ne,retirement:H.source_retired?s("ui.mesh.mesh_page.the_copy_here_is_gone"):""}),undo:H.mode==="keep"?{sessionId:H.new_session_id,to:"local",keep:!1,verb:s("ui.mesh.mesh_page.bring_copy_back",{device:ne}),waitS:0,lost:Cs(ne,s("ui.mesh.mesh_drop.this_device"))}:null});return}N({kind:"refused",refusal:J.refusal,plan:j})},onError:()=>{N({kind:"refused",refusal:{code:"move_failed",sentence:s("ui.mesh.mesh_page.the_move_could_not_be_sent_nothing"),status:null,unconfirmed:!1},plan:j})}})},[b,y,R]),Y=x.useMemo(()=>{if(!b)return[];const j=g?.deviceId,W=j?b.devices.find(B=>B.id===j):void 0;return b.networks.filter(B=>W?!W.memberships.some(J=>J.networkId===B.id):!0).map(B=>({id:B.id,label:B.label}))},[b,g]);if(!a)return t.jsx(jt,{to:"/chat",replace:!0});const te=v.kind==="ready"?c.error?ve(c.error):d.error?ve(d.error):null:null;return t.jsx(ga,{initialPresentation:e,state:v,graph:b,nowSeconds:z,checking:c.isFetching||d.isFetching,staleError:te,onRetry:ae,approvals:{rows:A.data??[],error:A.isError?ys(A.error):null,pending:u.isPending?u.variables??null:null,decisionRefusal:w,credentialApprovals:p,profileApprovals:m,onDecide:(j,W)=>{const B=A.data?.find(H=>H.approvalId===j),J=B?js(B,W,{credentialApprovals:p,profileApprovals:m},w?.approvalId===j?w.retryable:void 0):null;J&&u.mutate({approvalId:j,decision:W,request:J})},onRetry:()=>void A.refetch(),nowSeconds:S},sessions:h.data?.rows??[],movingSessionId:y.isPending?y.variables?.sessionId??null:null,sessionError:h.isError?ve(h.error):null,selfLabel:b?.devices.find(j=>j.state==="self")?.label??s("ui.mesh.mesh_drop.this_device"),canMove:r,pendingMove:D,onAskMove:P,onDropRefused:j=>N({kind:"refused",refusal:{code:j.code,sentence:j.sentence,reach:j.reach,status:null,unconfirmed:!1},plan:j.plan}),onChooseMove:j=>E(j),onCancelMove:()=>P(null),moveBusy:y.isPending,moveReport:C,onDismissReport:()=>N(null),onWaitForIdle:()=>{C?.kind!=="refused"||!C.plan||E(C.plan,ba)},onUndoCopy:()=>{C?.kind!=="moved"||!C.undo||P({plan:C.undo,alternatives:[],risky:!1})},invite:g===null?null:{open:!0,deviceId:g.deviceId,deviceName:g.deviceName,options:Y},onOpenInvite:j=>{q(null),f(null),L(j)},onInvite:j=>{I.mutate(j,{onSuccess:W=>q(W),onError:W=>f({code:"invite_refused",sentence:ve(W),status:null,unconfirmed:!1})})},onCloseInvite:()=>L(null),inviteBusy:I.isPending,inviteReceipt:ee,inviteRefusal:F,remove:T===null?null:{open:!0,networkId:T.networkId,networkLabel:T.networkLabel,deviceId:T.deviceId,deviceName:T.deviceName},onOpenRemove:j=>{G(null),V(j)},onRemove:j=>{T&&k.mutate({networkId:T.networkId,deviceId:T.deviceId,confirm:j},{onSuccess:W=>G(W)})},onCloseRemove:()=>V(null),removeBusy:k.isPending,removeRefusal:k.isError?{code:"remove_refused",sentence:ve(k.error),status:null,unconfirmed:!1}:null,removed:Z})},ba=300;export{Ma as MeshPage,ga as MeshSurface,Ma as default};
|