local-operator-ui 0.31.34 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/main/index.js +23 -0
- package/out/renderer/assets/{_basePickBy-BGuZGQlL.js → _basePickBy-DRT8mURG.js} +1 -1
- package/out/renderer/assets/{_baseUniq-avrxGYhI.js → _baseUniq-CIOjpfWF.js} +1 -1
- package/out/renderer/assets/{agent-details-page-CSjm9_q7.js → agent-details-page-BBAgSKbU.js} +1 -1
- package/out/renderer/assets/{agent-hub-page-BXiVDudt.js → agent-hub-page-HG8d0q6h.js} +1 -1
- package/out/renderer/assets/{agents-page-CDuIQEse.js → agents-page-DTA47rf7.js} +3 -3
- package/out/renderer/assets/{arc-CQRcxcOn.js → arc-Bevww3yK.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-IEHRJDOE-CkwuxGbl.js → architectureDiagram-IEHRJDOE-CEnq5TT8.js} +1 -1
- package/out/renderer/assets/{blockDiagram-JOT3LUYC-DErhLlTs.js → blockDiagram-JOT3LUYC-K3xa6m3w.js} +1 -1
- package/out/renderer/assets/{book-open-CueO0nwZ.js → book-open-D5MeCdw_.js} +1 -1
- package/out/renderer/assets/{browser-page-BH9k2DzV.js → browser-page-BNCBisfY.js} +1 -1
- package/out/renderer/assets/{browser-webauthn-prompt-D5Ca5EtW.js → browser-webauthn-prompt-BV2bzF8P.js} +1 -1
- package/out/renderer/assets/{c4Diagram-VJAJSXHY-Bvg0BHpF.js → c4Diagram-VJAJSXHY-os41x4WA.js} +1 -1
- package/out/renderer/assets/channel-sCVkoHKF.js +1 -0
- package/out/renderer/assets/{chunk-4BMEZGHF-EIhFYl3X.js → chunk-4BMEZGHF-DxKznC1E.js} +1 -1
- package/out/renderer/assets/{chunk-A2AXSNBT-xwy-uUTS.js → chunk-A2AXSNBT-Db9UnhTg.js} +1 -1
- package/out/renderer/assets/{chunk-AEK57VVT-Br1voKIL.js → chunk-AEK57VVT-D2U_alKj.js} +1 -1
- package/out/renderer/assets/{chunk-D6G4REZN-C4Dh_tJf.js → chunk-D6G4REZN-CqzqKJ-4.js} +1 -1
- package/out/renderer/assets/{chunk-RZ5BOZE2-bSGVs_Tb.js → chunk-RZ5BOZE2-CUx4xiz9.js} +1 -1
- package/out/renderer/assets/{chunk-XZIHB7SX-CN1-qcAy.js → chunk-XZIHB7SX-DjD7wu1d.js} +1 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-D7ZemIB3.js +1 -0
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-D7ZemIB3.js +1 -0
- package/out/renderer/assets/clone-JfI-y0gA.js +1 -0
- package/out/renderer/assets/{conversation-input-sync-QxTZG_kn.js → conversation-input-sync-BW_UGWKP.js} +129 -129
- package/out/renderer/assets/{dagre-OKDRZEBW-BY039iHz.js → dagre-OKDRZEBW-Dj_wtrdP.js} +1 -1
- package/out/renderer/assets/{diagram-SSKATNLV-bB3dlGcF.js → diagram-SSKATNLV-CWXvBT_I.js} +1 -1
- package/out/renderer/assets/{diagram-VNBRO52H-Cyhtu1_5.js → diagram-VNBRO52H-B8-Il89w.js} +1 -1
- package/out/renderer/assets/{erDiagram-Q7BY3M3F-CNtBW35e.js → erDiagram-Q7BY3M3F-BwKwqiQY.js} +1 -1
- package/out/renderer/assets/{error-boundary-BCN3_4Dn.js → error-boundary-9syfMgM3.js} +1 -1
- package/out/renderer/assets/{flowDiagram-4HSFHLVR-DpPSE1IC.js → flowDiagram-4HSFHLVR-FGlmzDKl.js} +1 -1
- package/out/renderer/assets/{ganttDiagram-APWFNJXF-xMxTMO4B.js → ganttDiagram-APWFNJXF-TchvnIff.js} +1 -1
- package/out/renderer/assets/{gitGraphDiagram-7IBYFJ6S-B7-mMQYk.js → gitGraphDiagram-7IBYFJ6S-Co26gdlj.js} +1 -1
- package/out/renderer/assets/{graph-By5Jgx_F.js → graph-CvvOmP6Y.js} +1 -1
- package/out/renderer/assets/{index-DE0OwCyE.js → index-BpABOauh.js} +1 -1
- package/out/renderer/assets/{index-CL3E7OEw.js → index-C024E3U7.js} +78 -78
- package/out/renderer/assets/{index-jwwX9AyN.js → index-_QUiqVbu.js} +1 -1
- package/out/renderer/assets/{infoDiagram-PH2N3AL5-DX8aEhB8.js → infoDiagram-PH2N3AL5-CN23wDMW.js} +1 -1
- package/out/renderer/assets/{installer-DovMkJto.js → installer-D0Jz9VHA.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-U35MCT3I-CH_A0wDP.js → journeyDiagram-U35MCT3I-HV2jfVJT.js} +1 -1
- package/out/renderer/assets/{kanban-definition-NDS4AKOZ-DtwsMDtl.js → kanban-definition-NDS4AKOZ-BQu-qphz.js} +1 -1
- package/out/renderer/assets/{layout-HO9_Xm1P.js → layout-MYedaf7A.js} +1 -1
- package/out/renderer/assets/{legacy-agents-page-D6fK_4tD.js → legacy-agents-page-DCtoJwsh.js} +1 -1
- package/out/renderer/assets/{mermaid.core-w9t0zfcx.js → mermaid.core-C1M4biFs.js} +5 -5
- package/out/renderer/assets/{mesh-page-D4paHK3u.js → mesh-page-CRwc_0Bf.js} +1 -1
- package/out/renderer/assets/{mindmap-definition-ALO5MXBD-B76wJgpo.js → mindmap-definition-ALO5MXBD-B0qKqswI.js} +1 -1
- package/out/renderer/assets/{mini-BUYwiX1L.js → mini-qY60RaMD.js} +1 -1
- package/out/renderer/assets/{org-surface-gate-CoX7en0B.js → org-surface-gate-D2GQhf_o.js} +1 -1
- package/out/renderer/assets/{pieDiagram-IB7DONF6-DBCDwb5q.js → pieDiagram-IB7DONF6-DJlTqIhZ.js} +1 -1
- package/out/renderer/assets/{projects-page-agDoCBOh.js → projects-page-BTq_jLmk.js} +1 -1
- package/out/renderer/assets/{quadrantDiagram-7GDLP6J5-OWbzuMt_.js → quadrantDiagram-7GDLP6J5-DU9HBTR5.js} +1 -1
- package/out/renderer/assets/{radar-MK3ICKWK-CRLok0av.js → radar-MK3ICKWK-D4UgxYCc.js} +1 -1
- package/out/renderer/assets/{radient-auth-buttons-BuYF7pw2.js → radient-auth-buttons-BvFFkaXp.js} +1 -1
- package/out/renderer/assets/{requirementDiagram-KVF5MWMF-Ct-Jg5Jo.js → requirementDiagram-KVF5MWMF-B7PaS_mq.js} +1 -1
- package/out/renderer/assets/{sankeyDiagram-QLVOVGJD-BJ0V1pBE.js → sankeyDiagram-QLVOVGJD-umwUfQuz.js} +1 -1
- package/out/renderer/assets/{schedules-page-BjwANHEZ.js → schedules-page-BkDhaIK1.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-X6HHIX6F-CqLGptQb.js → sequenceDiagram-X6HHIX6F-ChhSJ-Dd.js} +1 -1
- package/out/renderer/assets/settings-page-Cw012Hb0.js +292 -0
- package/out/renderer/assets/{settings-section-8d2ITQC3.js → settings-section-AlEM_Xkt.js} +1 -1
- package/out/renderer/assets/{stateDiagram-DGXRK772-B-WRbN_h.js → stateDiagram-DGXRK772-CTemFlyh.js} +1 -1
- package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-D81WdJ5C.js +1 -0
- package/out/renderer/assets/{timeline-definition-BDJGKUSR-Cdvoj120.js → timeline-definition-BDJGKUSR-D8qcgZDU.js} +1 -1
- package/out/renderer/assets/{use-download-agent-mutation-BEa3kVfY.js → use-download-agent-mutation-B_t9rwmc.js} +1 -1
- package/out/renderer/assets/{use-memberships-query-TpnxzBRP.js → use-memberships-query-HW4ts4RC.js} +1 -1
- package/out/renderer/assets/{xychartDiagram-VJFVF3MP-c6md61_B.js → xychartDiagram-VJFVF3MP-PSEehwvd.js} +1 -1
- package/out/renderer/index.html +3 -3
- package/out/renderer/installer.html +2 -2
- package/out/renderer/mini.html +3 -3
- package/package.json +2 -2
- package/out/renderer/assets/channel-238GQ5wt.js +0 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-BFR--RB2.js +0 -1
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-BFR--RB2.js +0 -1
- package/out/renderer/assets/clone-DJut1uh5.js +0 -1
- package/out/renderer/assets/settings-page-NSosCB_S.js +0 -292
- package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-CzCtqiki.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as f,j as t,c as R}from"./index-DvjcW_EJ.js";import{aW as we,aX as Xe,aY as Oe,a as qe,aZ as xe,ah as Ze,a_ as Je}from"./conversation-input-sync-QxTZG_kn.js";import{P as Qe}from"./page-header-ouA0fPx9.js";import{B as U,j as Ie,A as he,k as et,a as ne,D as tt,l as st,m as nt,n as at,o as Ce,p as Se,e as Me}from"./error-boundary-BCN3_4Dn.js";import{i as it,d as rt,e as lt,f as ot,g as dt,h as ct,j as ut,k as mt,l as ht,m as pt,n as ft,o as xt,p as bt,q as gt,r as vt,N as kt,s as je,t as wt,u as oe,D as jt,v as yt,w as Nt,x as ye,y as ke,R as It,z as de,C as We,E as ze,F as Ct,G as me,H as be,I as St,J as Mt,K as pe,L as De,M as Dt,O as Et,Q as ge,T as At,U as He,V as _t,W as Be,X as Rt,Y as $t,Z as Lt,_ as Pt,$ as Tt,a0 as Ot,a1 as Wt,a2 as zt,a3 as Ht,a4 as Bt,a5 as Yt,a6 as Ft,a7 as Ut,a8 as Gt,a9 as Vt,aa as Kt,ab as Xt,ac as qt,ad as Zt,ae as le,af as Jt}from"./index-CL3E7OEw.js";import"./ui-preferences-store-ClQPCzID.js";import"./console-mirror-D3uHRfYy.js";function Qt(e){return e==="requested"?"attention":e==="failed"?"danger":e==="connected"?"success":"neutral"}function es(e){switch(e){case"requested":return"Approving signs with this machine's operator key; the system may ask for it.";case"approved":return"An agent runs the install and connect (lop network approvals run).";case"connecting":return"Denying now stops it at its next step.";case"failed":return"The runner stopped. Denying abandons it; an agent can retry it.";default:return null}}function ts(e){switch(e){case"requested":return"Signing";case"approved":return"Next";case"connecting":return"Stop";case"failed":return"After a stop";default:return"What this means"}}function ss(e){return e==="connected"?"connected":e==="denied"?"denied":"expired"}const ns=({rows:e,error:s,pending:r,refusal:a,onDecide:d,onRetry:c,nowSeconds:m,networkNames:l})=>{const x=r!==null,v=f.useMemo(()=>e.filter(i=>it(i.state)),[e]),[y,I]=f.useState([]),N=f.useRef(new Map);f.useEffect(()=>{const i=new Map;for(const g of v)i.set(g.approvalId,rt(g));const h=[];for(const[g,j]of N.current){if(i.has(g))continue;const C=e.find(M=>M.approvalId===g)?.state??"";(C==="connected"||C==="denied"||C==="expired")&&h.push({key:`${g}:${C}`,text:`${j} — ${ss(C)}`})}h.length&&I(g=>[...g,...h].slice(-3)),N.current=i},[v,e]);const o=a!==null&&v.some(i=>i.approvalId===a.approvalId);return v.length===0&&y.length===0&&!s&&!a?null:t.jsxs("section",{"aria-label":"Approvals","data-tour-tag":"mesh-approvals-tray",className:"flex flex-col gap-3 rounded-lg border border-hairline bg-surface p-3",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(lt,{"aria-hidden":"true",className:"size-4 text-ink-muted"}),t.jsx("h2",{className:"text-body-sm text-ink",children:"Approvals"}),v.length>0&&t.jsx("span",{className:"text-meta text-ink-dim",children:v.length===1?"1 waiting":`${v.length} waiting`})]}),s&&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:s}),t.jsx(U,{variant:"secondary",size:"sm",onClick:c,children:"Ask again"})]}),v.length>0&&t.jsx("ul",{className:"flex flex-col divide-y divide-hairline",children:v.map(i=>t.jsx(as,{row:i,pending:r?.approvalId===i.approvalId?r:null,busy:x,refusal:a?.approvalId===i.approvalId?a:null,onDecide:d,nowSeconds:m,networkNames:l},i.approvalId))}),a&&!o&&t.jsx(Ye,{refusal:a}),y.length>0&&t.jsx("ul",{className:"flex flex-col gap-0.5 text-meta text-ink-dim","data-tour-tag":"mesh-approvals-resolved",children:y.map(i=>t.jsx("li",{children:i.text},i.key))})]})},as=({row:e,pending:s,busy:r,refusal:a,onDecide:d,nowSeconds:c,networkNames:m})=>{const l=ot(e),x=dt(e),v=ct(e),y=ut(e,m),I=mt(e),N=ht(e.expiresAt,c),o=es(e.state),i=pt(e.state),h=ft(e.state);return t.jsxs("li",{className:"flex flex-col gap-2 py-3 first:pt-0 last:pb-0","data-tour-tag":"mesh-approval-card",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(Ie,{variant:Qt(e.state),children:xt(e.state)}),t.jsx("span",{className:"text-body-sm text-ink",children:bt(e)}),t.jsx("div",{className:"grow"}),N&&t.jsx("span",{className:"text-meta text-ink-dim",children:N})]}),(l||x)&&t.jsxs("p",{className:"text-meta text-ink-muted",children:[l&&t.jsx("span",{children:l}),l&&x&&t.jsx("span",{children:" · "}),x&&t.jsx("span",{className:"font-mono",children:x})]}),y.length>0&&t.jsx("ul",{className:"flex flex-wrap gap-1",children:y.map(g=>t.jsx("li",{children:t.jsx(Ie,{variant:gt(g),children:g})},g))}),v&&t.jsx("p",{className:"text-meta text-ink-dim",children:v}),I.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-scope-glosses",children:I.map(g=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:g.term}),t.jsx("dd",{children:g.gloss})]},g.term))}),o&&t.jsxs("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta","data-tour-tag":"mesh-approval-consequence",children:[t.jsx("dt",{className:"text-ink-muted",children:ts(e.state)}),t.jsx("dd",{className:"text-ink-muted",children:o})]}),(i||h)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i&&t.jsx(U,{variant:"primary",size:"sm",disabled:r,onClick:()=>d(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:"Approve"}),h&&t.jsx(U,{variant:i?"ghost":"secondary",size:"sm",disabled:r,onClick:()=>d(e.approvalId,"deny"),"data-tour-tag":"mesh-approval-deny",children:"Deny"}),s&&t.jsx("span",{className:"text-meta text-ink-dim",children:s.decision==="approve"?"Waiting for the signing prompt…":"Writing the decision…"})]}),a&&t.jsx(Ye,{refusal:a})]})},Ye=({refusal:e})=>t.jsxs(he,{variant:"warning",className:"text-meta",children:[t.jsx("span",{className:"min-w-0 flex-1",children:e.sentence}),t.jsx("span",{className:"shrink-0 font-mono text-ink-dim",children:e.code})]}),is=4,fe={kind:"idle"};function rs(e){switch(e.kind){case"dragging":case"settling":return e.payload.session.id;case"pressing":return null;default:return null}}function Q(e,s){switch(s.kind){case"press":return e.kind!=="idle"?e:{kind:"pressing",payload:s.payload,originX:s.x,originY:s.y,pointerId:s.pointerId};case"move":return e.kind==="pressing"?Math.max(Math.abs(s.x-e.originX),Math.abs(s.y-e.originY))<is?e:{kind:"dragging",payload:e.payload,x:s.x,y:s.y,target:s.target,pointerId:e.pointerId}:e.kind==="dragging"?{...e,x:s.x,y:s.y,target:s.target}:e;case"release":return e.kind==="dragging"?{kind:"settling",payload:e.payload,target:e.target}:e.kind==="pressing"?fe:e;case"cancel":case"settled":return fe;default:return e}}const ls=({edges:e,geometry:s,selectedDeviceId:r})=>t.jsx("svg",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0 overflow-visible",width:s.bounds.width,height:s.bounds.height,children:e.map(a=>{const d=s.networks.get(a.networkId),c=s.devices.get(a.deviceId);if(!d||!c)return null;const m=r!==null&&a.deviceId===r;return t.jsx("path",{"data-mesh-edge":a.key,d:vt(d,c),fill:"none",strokeWidth:m?2:1.5,strokeDasharray:a.active?void 0:"4 4",className:m?"stroke-ink":"stroke-ink-dim"},a.key)})}),os={self:"border-l-hairline",reached:"border-l-hairline",unanswered:"border-l-warning","not-attempted":"border-l-hairline",unknown:"border-l-hairline"};function ds(e){return e.suspect?"border-l-danger":os[oe(e)]}const cs={self:"ring-2 ring-accent",reachable:null,unreachable:null,suspect:null},us={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function ms(e,s,r){return[e.label,ze(e,s),r].filter(Boolean).join(", ")}function ae(e){return e.name.trim()||e.id.slice(-6)}function Fe(e,s,r){if(r!=="reached"&&r!=="self"){const a=de(r);return e.unreachable_reason?`${a} (${e.unreachable_reason})`:a}return e.live_state.trim()?e.live_state.trim():e.locality==="local"?"on this device":`on ${s}`}const hs={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},ps=({network:e,x:s,y:r,refused:a})=>t.jsxs("li",{"data-mesh-network":e.id,"data-mesh-network-refused":a?"true":void 0,className:R("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",a?"border-warning":"border-hairline"),style:{left:s,top:r,width:je,height:kt},children:[t.jsx(we,{"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:`epoch ${e.epoch}`,className:"block truncate text-meta text-ink-dim",children:[e.memberCount," ",e.memberCount===1?"device":"devices",e.revokedCount>0?` · ${e.revokedCount} revoked`:""]})]})]}),fs=({device:e,x:s,y:r,nowSeconds:a,selected:d,sessions:c,sessionTotal:m,dropState:l,movingSessionId:x,draggedSessionId:v,onOpen:y,onChipPointerDown:I,onChipClick:N,onShowAllSessions:o})=>{const{activity:i}=wt(e,c.rows),h=i==="working",g=ms(e,a,h?"working":null),j=oe(e);return t.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":l??void 0,"aria-current":d?"true":void 0,className:R("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",ds(e),cs[e.state],l&&us[l]),style:{left:s,top:r,width:je,height:jt},children:[t.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":j,"aria-label":g,title:Nt(e),onClick:()=>y(e.id),className:R("flex w-full flex-col justify-between rounded-t-[5px] px-3 pt-2 pb-2 text-left","cursor-pointer","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),style:{height:yt},children:[t.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2",children:[t.jsx(Xe,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",children:e.label}),e.suspect&&t.jsx(ye,{"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:R("min-w-0 truncate text-meta",e.sessionCount===null?"text-ink-dim":"text-ink-muted"),children:ke(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:It[j]}),t.jsx("span",{className:R("shrink-0",We[j]),children:de(j)}),h&&t.jsx("span",{"data-mesh-working":"",className:"shrink-0 text-info",children:"working"}),e.memberships.length>1&&t.jsxs("span",{className:"min-w-0 truncate text-ink-dim",children:["· ",e.memberships.length," networks"]})]})]}),t.jsxs("ul",{"aria-label":`Conversations on ${e.label}`,className:R("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",l==="accept"&&"opacity-40"),children:[c.shown.map(p=>t.jsx(xs,{session:p,ownerLabel:e.label,ownerReach:j,ownerReachable:e.reachable,moving:x===p.id,dragging:v===p.id,onPointerDown:I,onClick:()=>N(p)},p.id)),c.hidden>0&&t.jsx("li",{className:"shrink-0",children:t.jsxs("button",{type:"button","data-mesh-more":e.id,onClick:()=>o(e.id),className:R("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:`Showing ${c.shown.length} of ${m} conversations`,"aria-label":`Show all ${m} conversations`,children:["+",c.hidden]})})]})]})},xs=({session:e,ownerLabel:s,ownerReach:r,ownerReachable:a,moving:d,dragging:c,onPointerDown:m,onClick:l})=>{const x=Fe(e,s,r);return d?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:"moving…"})}):t.jsx("li",{className:"min-w-0 flex-1","data-mesh-session-item":e.id,"data-mesh-dragging":c?"true":void 0,children:t.jsx("button",{type:"button","data-mesh-session":e.id,style:{touchAction:"none"},title:`${ae(e)} · ${x}`,"aria-label":`${ae(e)}, ${x}. Opens ${s}.`,onPointerDown:v=>m(v,e),onClick:()=>l(e),className:R("flex min-h-6 w-full max-w-32 items-center rounded-sm border border-hairline bg-surface px-1.5 text-left text-meta text-ink-muted","cursor-grab active:cursor-grabbing","hover:text-ink",hs[Ct(e,a)],c&&"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 [direction:rtl]",children:ae(e)})})})};function Ee(e){const s=e.trim();if(!s)return null;if(s.startsWith("[")){const a=s.indexOf("]");if(a<=1)return null;const d=s.slice(1,a),c=s.slice(a+1);if(!c)return{host:d,port:null};if(!c.startsWith(":"))return null;const m=Number(c.slice(1));return{host:d,port:Number.isInteger(m)?m:null}}const r=s.lastIndexOf(":");if(r>0){const a=s.slice(r+1);if(/^\d+$/.test(a))return{host:s.slice(0,r),port:Number(a)}}return{host:s,port:null}}function Ae(e){const s=e.trim().split(".");if(s.length!==4)return null;for(const r of s)if(!/^\d{1,3}$/.test(r)||Number(r)>255)return null;return`${s[0]}.${s[1]}.${s[2]}`}function bs(e){return`${e}.x`}function gs(e){const s=new Map;for(const a of e.values())for(const d of a)s.set(d,(s.get(d)??0)+1);const r=new Set;for(const[a,d]of s)d>1&&r.add(a);return r}function ve(e){return new Set(e.endpoints.map(s=>s.trim()).filter(Boolean))}function vs(e,s){const r=e.filter(o=>o.id!==s),a=e.find(o=>o.id===s)??null,d=new Map;for(const o of e)d.set(o.id,ve(o));const c=gs(d),m=new Set;for(const o of a?ve(a):[]){if(c.has(o))continue;const i=Ee(o),h=i?Ae(i.host):null;h&&m.add(h)}const l=o=>{const i=new Set;for(const h of ve(o)){if(c.has(h))continue;const g=Ee(h),j=g?Ae(g.host):null;j&&i.add(j)}return i},x=new Map,v=new Map;for(const o of r){const i=ks(o);if(i){x.set(i,[...x.get(i)??[],o.id]);continue}for(const h of l(o))v.set(h,[...v.get(h)??[],o.id])}const y=new Map(e.map((o,i)=>[o.id,i])),I=o=>[...o].sort((i,h)=>(y.get(i)??0)-(y.get(h)??0)),N=[];for(const[o,i]of x)N.push({prefix:o,tier:"declared",deviceIds:I(i),words:"declared"});for(const[o,i]of v)m.has(o)?N.push({prefix:o,tier:"shared",deviceIds:I(i),words:"shared with this device"}):i.length>1&&N.push({prefix:o,tier:"probable",deviceIds:I(i),words:"same prefix"});return N.sort((o,i)=>o.tier.localeCompare(i.tier)||o.prefix.localeCompare(i.prefix))}function ks(e){for(const s of e.memberships){const r=s.scope.trim();if(r)return r}return""}const _e={declared:0,shared:1,probable:2};function ws(e,s){const r=new Map;for(const d of e){let c=null;for(const l of d.deviceIds){const x=s.get(l);x!==void 0&&(c===null||x<c.slot)&&(c={id:l,slot:x})}if(c===null)continue;const m=r.get(c.id);m===void 0?r.set(c.id,{slot:c.slot,groups:[d]}):m.groups.push(d)}const a=d=>{let c=-1;for(const m of d.deviceIds){const l=s.get(m);l!==void 0&&l>c&&(c=l)}return c};return[...r.entries()].sort((d,c)=>d[1].slot-c[1].slot).map(([d,c])=>({deviceId:d,groups:c.groups.sort((m,l)=>a(l)-a(m)||_e[m.tier]-_e[l.tier]||m.prefix.localeCompare(l.prefix))}))}function js(e){return new Map(e.map(s=>[s.deviceId,s.groups.length]))}function ys(e){return`${e.tier==="declared"?e.prefix:bs(e.prefix)} · ${e.words}`}const Re=(e,s)=>e.deviceIds.map(r=>s.devices.get(r)).filter(r=>r!==void 0),Ns=({stacks:e,geometry:s})=>t.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(r=>{const a=r.groups.length,d=new Array(a).fill(0);let c=null;for(let l=a-1;l>=0;l-=1){const x=Re(r.groups[l],s),v=(x.length===0?0:Math.max(...x.map(y=>y.y+y.height)))+me;c=c===null?v:Math.max(v,c+be),d[l]=c}const m=s.devices.get(r.deviceId);return r.groups.map((l,x)=>{const v=Re(l,s);if(v.length===0)return null;const y=a-1-x,I=Math.min(...v.map(j=>j.x)),N=Math.max(...v.map(j=>j.x)),i=(m?.y??Math.min(...v.map(j=>j.y)))-me-St*y,h=l.tier==="declared",g=ys(l);return t.jsx("div",{"data-mesh-scope":`${l.tier}:${l.prefix}`,"data-mesh-scope-level":x,className:R("absolute rounded-lg",l.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:I-me-be*y,top:i,width:N+je-I+(me+be*y)*2,height:d[x]-i},children:t.jsx("span",{"data-mesh-scope-label":"",className:R("absolute bottom-full left-1 mb-0.5 whitespace-nowrap text-meta",l.tier==="probable"?"text-ink-dim":"text-ink-muted",h&&"font-medium"),children:g})},`${l.tier}:${l.prefix}`)})})}),$e=48,Le=1.25,Is=.0015,Cs=({graph:e,slots:s,nowSeconds:r,selectedDeviceId:a,sessions:d,sessionTotals:c,movingSessionId:m,canMove:l,onOpenDevice:x,onAskMove:v,onDropRefused:y,onShowAllSessions:I,summaryId:N})=>{const o=f.useRef(null),[i,h]=f.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[g,j]=f.useState({k:1,tx:0,ty:0}),p=f.useRef(!1),C=f.useRef(!1),M=f.useRef(null),P=f.useMemo(()=>vs(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),S=f.useMemo(()=>ws(P,s.devices),[P,s]),D=f.useMemo(()=>Mt(s,js(S)),[s,S]),B=f.useMemo(()=>({selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(n=>[n.id,n])),networks:new Map(e.networks.map(n=>[n.id,n]))}),[e]),[w,W]=f.useState(fe),ee=f.useRef({kind:"ground"}),z=f.useCallback((n,u)=>{const b=document.elementFromPoint(n,u),A=b?.closest("[data-mesh-device]");if(A){const V=A.getAttribute("data-mesh-device");if(V)return{kind:"device",deviceId:V}}const O=b?.closest("[data-mesh-network]");if(O){const V=O.getAttribute("data-mesh-network");if(V)return{kind:"network",networkId:V}}return{kind:"ground"}},[]),L=f.useMemo(()=>w.kind!=="dragging"&&w.kind!=="settling"?null:pe(w.payload,w.target,B),[w,B]),te=f.useCallback(n=>{if(!L)return null;if(L.kind==="plan"){const u=w.kind==="dragging"||w.kind==="settling"?w.target:null;return u&&u.kind==="device"&&u.deviceId===n?"accept":null}if(L.kind==="refused"){const u=w.kind==="dragging"||w.kind==="settling"?w.target:null;return u&&u.kind==="device"&&u.deviceId===n?"refuse":null}return null},[L,w]),se=f.useCallback((n,u)=>{if(!l||n.button!==0)return;C.current=!1;const b=u.locality==="local"?e.selfDeviceId??"":u.owner_device,A=B.devices.get(b),O={session:u,ownerDeviceId:b,ownerLabel:A?.label??u.owner_device_name};try{n.currentTarget.setPointerCapture(n.pointerId)}catch{}W(V=>Q(V,{kind:"press",payload:O,x:n.clientX,y:n.clientY,pointerId:n.pointerId}))},[l,B,e.selfDeviceId]),ie=n=>{if(w.kind==="pressing"||w.kind==="dragging"){const u=z(n.clientX,n.clientY);ee.current=u,W(b=>Q(b,{kind:"move",x:n.clientX,y:n.clientY,target:u}));return}ce(n)},re=n=>{if(J(n),w.kind!=="pressing"&&w.kind!=="dragging")return;if(w.kind==="pressing"){W(b=>Q(b,{kind:"cancel"}));return}const u=pe(w.payload,w.target,B);C.current=!0,W(b=>Q(b,{kind:"release"})),u.kind==="plan"?v({plan:u.plan,alternatives:u.alternatives,risky:u.risky}):u.kind==="refused"&&y({code:u.code,sentence:u.sentence,remedy:u.remedy,plan:u.plan??null}),W(b=>Q(b,{kind:"settled"}))};f.useEffect(()=>()=>W(fe),[]);const Z=f.useCallback(()=>{j(De(D.bounds,i))},[D.bounds,i]);f.useEffect(()=>{const n=o.current;if(!n)return;const u=()=>{const A=n.getBoundingClientRect();h({width:A.width,height:A.height,clipWidth:n.clientWidth,clipHeight:n.clientHeight,left:A.left,top:A.top})};u();const b=new ResizeObserver(u);return b.observe(n),()=>b.disconnect()},[]),f.useEffect(()=>{p.current||i.width<=0||i.height<=0||(p.current=!0,j(De(D.bounds,i)))},[i,D.bounds]),f.useEffect(()=>{const n=M.current;if(M.current={width:i.width,height:i.height},!n||!p.current||i.width<=0||i.height<=0||i.width>=n.width&&i.height>=n.height||!a)return;const u=D.devices.get(a);u&&j(b=>{const A={width:i.clipWidth,height:i.clipHeight},O=Math.max(0,Math.min(A.width-D.bounds.width*b.k,A.height-D.bounds.height*b.k));return Dt(b,u,A,Math.min(At,O))})},[i,a,D]);const Y=w.kind==="dragging"?{x:w.x-i.left+12,y:w.y-i.top+12}:{x:0,y:0},X=L?Et(L):null,k=f.useRef(null),E=f.useRef(null),$=f.useRef(null),T=f.useRef(null),_=f.useCallback(()=>{$.current=null;const n=k.current,u=E.current;if(k.current=null,E.current=null,n){const b=T.current;if(!b)return;j({k:b.transform.k,tx:b.transform.tx+(n.x-b.x),ty:b.transform.ty+(n.y-b.y)});return}u&&j(b=>ge(b,{x:u.x,y:u.y},b.k*Math.exp(-u.deltaY*Is)))},[]),F=f.useCallback(()=>{$.current===null&&($.current=requestAnimationFrame(_))},[_]);f.useEffect(()=>()=>{$.current!==null&&cancelAnimationFrame($.current)},[]);const G=n=>{!(n.target===n.currentTarget)&&n.button!==1||n.button!==0&&n.button!==1||(T.current={x:n.clientX,y:n.clientY,transform:g},n.currentTarget.setPointerCapture(n.pointerId),n.preventDefault())},ce=n=>{T.current&&(k.current={x:n.clientX,y:n.clientY},F())},J=n=>{T.current&&(T.current=null,k.current=null,n.currentTarget.hasPointerCapture(n.pointerId)&&n.currentTarget.releasePointerCapture(n.pointerId))},q=f.useCallback(n=>{if(n.deltaY===0)return;n.preventDefault();const u=n.currentTarget.getBoundingClientRect();E.current={x:n.clientX-u.left,y:n.clientY-u.top,deltaY:n.deltaY},F()},[F]);f.useEffect(()=>{const n=o.current;if(n)return n.addEventListener("wheel",q,{passive:!1}),()=>n.removeEventListener("wheel",q)},[q]);const ue=n=>{const u=n.shiftKey?$e*4:$e;switch(n.key){case"Escape":if(w.kind!=="pressing"&&w.kind!=="dragging")return;n.preventDefault(),w.kind==="dragging"&&(C.current=!0),W(b=>Q(b,{kind:"cancel"}));return;case"0":n.preventDefault(),Z();return;case"+":case"=":n.preventDefault(),j(b=>ge(b,{x:i.width/2,y:i.height/2},b.k*Le));return;case"-":case"_":n.preventDefault(),j(b=>ge(b,{x:i.width/2,y:i.height/2},b.k/Le));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{n.preventDefault();const b=n.key==="ArrowLeft"?u:n.key==="ArrowRight"?-u:0,A=n.key==="ArrowUp"?u:n.key==="ArrowDown"?-u:0;j(O=>({...O,tx:O.tx+b,ty:O.ty+A}));return}}};return t.jsxs("div",{ref:o,"data-mesh-canvas":"",role:"group","aria-labelledby":N,tabIndex:0,onPointerDown:G,onPointerMove:ie,onPointerUp:re,onPointerCancel:n=>{w.kind==="dragging"&&(C.current=!0),W(u=>Q(u,{kind:"cancel"})),J(n)},"data-mesh-gesture":w.kind,onKeyDown:ue,onDoubleClick:n=>{n.target===n.currentTarget&&Z()},className:R("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:`${g.tx}px ${g.ty}px`}}),t.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${g.tx}px, ${g.ty}px, 0) scale(${g.k})`,transformOrigin:"0 0",width:D.bounds.width,height:D.bounds.height},children:[t.jsx(Ns,{stacks:S,geometry:D}),t.jsx(ls,{edges:e.edges,geometry:D,selectedDeviceId:a}),t.jsx("ul",{"aria-label":"Networks",className:"m-0 list-none p-0",children:e.networks.map(n=>{const u=D.networks.get(n.id);return u?t.jsx(ps,{network:n,x:u.x,y:u.y,refused:L?.kind==="refused"&&w.kind==="dragging"&&w.target.kind==="network"&&w.target.networkId===n.id},n.id):null})}),t.jsx("ul",{"aria-label":"Devices",className:"m-0 list-none p-0",children:e.devices.map(n=>{const u=D.devices.get(n.id);return u?t.jsx(fs,{device:n,x:u.x,y:u.y,nowSeconds:r,selected:n.id===a,sessions:d.get(n.id)??{rows:[],shown:[],hidden:0},sessionTotal:c.get(n.id)??n.sessionCount??0,dropState:te(n.id),movingSessionId:m,draggedSessionId:rs(w),onOpen:x,onChipPointerDown:se,onChipClick:()=>{if(C.current){C.current=!1;return}x(n.id)},onShowAllSessions:I},n.id):null})})]}),w.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:Y.x,top:Y.y},children:w.payload.session.name||"untitled"}),w.kind==="dragging"&&X&&t.jsx("div",{"data-mesh-indicator":"",className:R("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",L?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:Y.x,maxWidth:Math.max(160,i.width-Y.x-12),...Y.y>i.height*.6?{bottom:Math.max(12,i.height-Y.y+8)}:{top:Y.y+24}},children:X})]})};function Ss(e,s,r,a){const d=r.locality==="local"?s:r.owner_device,c=[];for(const m of e)if(m.id!==d){if(m.id===s){c.push({deviceId:m.id,label:a,verb:"Recall to this device",keepVerb:"Copy here, leave it there"});continue}c.push({deviceId:m.id,label:m.label,verb:`Move to ${m.label}`,keepVerb:`Copy to ${m.label}`})}return c}function Ms(e,s,r){return Ss(e.devices,e.selfDeviceId,s,r)}function Ue(e,s,r){const a=Ms(e,s,r),d={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(l=>[l.id,l])),networks:new Map(e.networks.map(l=>[l.id,l]))},c=s.locality==="local"?e.selfDeviceId??"":s.owner_device,m=d.devices.get(c);return a.map(l=>{const x=pe({session:s,ownerDeviceId:c,ownerLabel:m?.label??s.owner_device_name},{kind:"device",deviceId:l.deviceId},d);return{...l,refused:x.kind==="refused"&&x.code!=="busy"?x.sentence:null}})}const Ge=({session:e,destinations:s,disabled:r,onChoose:a,onOpenChange:d,trigger:c,triggerLabel:m})=>t.jsxs(tt,{onOpenChange:d,children:[t.jsx(st,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":m,"data-mesh-session-menu":e.id,disabled:r||s.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:c})}),t.jsxs(nt,{align:"start",className:"min-w-56",children:[t.jsx(at,{children:ae(e)}),t.jsx(Ce,{}),s.map(l=>t.jsx(Se,{"data-mesh-move-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>a(l,!1),children:l.verb},l.deviceId)),t.jsx(Ce,{}),s.map(l=>t.jsx(Se,{"data-mesh-copy-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>a(l,!0),children:l.keepVerb},`keep-${l.deviceId}`))]})]}),Ds=({device:e,sessions:s,sessionTotal:r,nowSeconds:a,destinationsFor:d,movingSessionId:c,canMove:m,canInvite:l,onClose:x,onMove:v,onShowInList:y,onInvite:I,onRemoveMember:N})=>{const o=oe(e);f.useEffect(()=>{const p=C=>{C.key!=="Escape"||C.defaultPrevented||C.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),x())};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[e.id,x]);const i=e.memberships.every(p=>!p.active),h=e.sessionCount===null?ke(null):`${e.sessionCount} ${ke(e.sessionCount)}`,g=e.suspect?He:[i?"revoked membership":h,de(o)].filter(Boolean).join(" · "),j=r>s.rows.length?`${s.rows.length} of ${r}`:`${s.rows.length}`;return t.jsxs("aside",{"aria-label":`${e.label} details`,"data-mesh-panel":e.id,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(U,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:x,children:"Close"}),t.jsx("h2",{className:"text-body-sm text-ink",children:e.label}),t.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[e.suspect&&t.jsx(ye,{"aria-hidden":"true",className:"size-3.5 text-danger"}),!e.suspect&&o==="unanswered"&&t.jsx(et,{"aria-hidden":"true",className:"size-3.5 text-warning"}),g]})]}),t.jsx(ne,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:"Memberships"}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:e.memberships.map(p=>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(we,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),p.networkName]}),t.jsxs("span",{className:"text-meta text-ink-dim",children:[p.role||"member",p.capabilities.length>0?` · ${p.capabilities.join(", ")}`:"",p.active?"":" · revoked"]}),l&&p.active&&t.jsxs(U,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${p.networkId}:${e.id}`,onClick:()=>N(e,p.networkId),children:["Remove from ",p.networkName,"…"]})]},p.networkId))}),l&&t.jsx(U,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":e.id,onClick:()=>I(e),children:"Invite to a network…"})]}),t.jsx(ne,{}),t.jsxs("section",{className:"flex min-h-0 flex-col gap-2",children:[t.jsxs("h3",{className:"text-meta text-ink-dim",children:["Conversations ",t.jsxs("span",{className:"text-ink-disabled",children:["(",j,")"]})]}),s.rows.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:e.sessionCount===null?"This device did not report its conversations.":"No conversations here."}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:s.rows.map(p=>t.jsxs("li",{"data-mesh-panel-session":p.id,className:R("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",c===p.id&&"border-control"),children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",children:ae(p)}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:Fe(p,e.label,oe(e))}),c===p.id?t.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:"moving…"}):t.jsx(Ge,{session:p,destinations:d(p),disabled:!m,onChoose:(C,M)=>v(p,C,M),trigger:t.jsx(Oe,{"aria-hidden":"true",className:"size-4"}),triggerLabel:`Move ${ae(p)}`})]},p.id))})]}),t.jsx(ne,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:"Network addresses"}),e.endpoints.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:"No address published."}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:e.endpoints.map(p=>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:p}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:"advertised"})]},p))})]}),t.jsx(ne,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:"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:"Reach"}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:de(o)})]}),t.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("dt",{className:"text-meta text-ink-dim",children:"Last status frame"}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:e.lastSeenAt===null?"never":_t(a-e.lastSeenAt)})]})]}),e.reason&&t.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),t.jsx(ne,{}),t.jsx(U,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>y(e.id),children:"Show in list"})]})},Es=["name","chats","state"],As={name:"Name",chats:"Conversations",state:"State"},Pe={suspect:0,unreachable:1,self:2,reachable:3};function _s(e,s){const r=[...e];switch(s){case"chats":return r.sort((a,d)=>(d.sessionCount??-1)-(a.sessionCount??-1)||a.label.localeCompare(d.label)),r;case"state":return r.sort((a,d)=>Pe[a.state]-Pe[d.state]||a.label.localeCompare(d.label)),r;default:return r.sort((a,d)=>a.label.localeCompare(d.label))}}const Te=8;function Rs(e,s){if(e.locality==="local")return e.live_state||"here";const r=e.owner_device_name||s,a=e.live_state?` · ${e.live_state}`:"";return e.reachable?`on ${r}${a}`:`on ${r} (not answering)`}const $s=({graph:e,nowSeconds:s,selectedDeviceId:r,sessions:a,selfLabel:d,canMove:c,onSelect:m,onMove:l,onInvite:x,onRemove:v})=>{const[y,I]=f.useState("name"),N=f.useMemo(()=>e.networks.map(o=>({network:o,members:_s(e.devices.filter(i=>i.memberships.some(h=>h.networkId===o.id)),y)})),[e,y]);return t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pr-1",children:[t.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[t.jsx("legend",{className:"sr-only",children:"Sort devices by"}),t.jsx("div",{className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Es.map(o=>t.jsx("button",{type:"button","aria-pressed":y===o,onClick:()=>I(o),className:R("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===o&&"bg-surface text-ink"),children:As[o]},o))})]}),N.map(({network:o,members:i})=>t.jsxs("section",{"data-mesh-network-group":o.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:`epoch ${o.epoch}`,children:[o.label,t.jsxs("span",{className:"text-meta text-ink-dim",children:[o.trust," · ",o.memberCount," ",o.memberCount===1?"device":"devices",o.revokedCount>0?` · ${o.revokedCount} revoked`:""]})]}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:i.map(h=>{const g=h.memberships.find(S=>S.networkId===o.id),j=h.id===r,p=a.get(h.id),C=p?.rows??[],M=p?Be(p,h.sessionCount):h.sessionCount??0,P=oe(h);return t.jsxs("li",{"data-mesh-device-row":h.id,"data-mesh-state":h.state,"aria-current":j?"true":void 0,className:R("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",j&&"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":h.id,onClick:()=>m(h.id),className:R("min-w-0 flex-1 truncate text-left 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:h.label}),t.jsxs("span",{className:R("flex shrink-0 items-center gap-1 text-meta",We[P]),"data-mesh-reach":P,children:[h.suspect&&t.jsx(ye,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),h.suspect?de(P):ze(h,s),h.suspect&&t.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:He})]}),t.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[g?.role?`${g.role} · `:"",g&&!g.active?"revoked":"member"]})]}),C.length>0?t.jsxs(t.Fragment,{children:[t.jsx(ne,{className:"my-1"}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:C.slice(0,Te).map(S=>t.jsxs("li",{"data-mesh-row-session":S.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:S.name||S.id}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:Rs(S,d)}),t.jsx(Ge,{session:S,destinations:Ue(e,S,d),disabled:!c,onChoose:(D,B)=>l(S,D,B),trigger:t.jsx(Oe,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:`Move ${S.name||S.id}`})]},S.id))}),M>C.slice(0,Te).length&&t.jsx("button",{type:"button",onClick:()=>m(h.id),className:"w-fit text-meta text-ink-dim hover:text-ink",children:`show all ${M} in the panel`})]}):t.jsx("span",{className:"text-meta text-ink-dim",children:M===0?"no conversations":M===1?"1 conversation":`${M} conversations`}),(g?.active||h.state!=="self")&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(U,{size:"sm",variant:"ghost","data-mesh-invite":h.id,onClick:()=>x({deviceId:h.id,deviceLabel:h.label}),children:"Invite to a network…"}),g?.active&&t.jsxs(U,{size:"sm",variant:"ghost","data-mesh-remove-member":`${o.id}:${h.id}`,onClick:()=>v({networkId:o.id,networkLabel:o.label,deviceId:h.id,deviceLabel:h.label}),children:["Remove from ",o.label,"…"]})]})]},h.id)})})]},o.id)),e.unmatchedPeers.length>0&&t.jsxs("p",{className:"text-meta text-warning",children:[e.unmatchedPeers.length," ",e.unmatchedPeers.length===1?"device":"devices"," answered the peer read but is in no network this app can name."]})]})},Ls=["canvas","list"],Ps={canvas:"Canvas",list:"List"},Ts=({state:e,graph:s,nowSeconds:r,checking:a,staleError:d,onRetry:c,approvals:m,sessions:l,sessionError:x,selfLabel:v,movingSessionId:y,canMove:I,pendingMove:N,onAskMove:o,onDropRefused:i,onChooseMove:h,onCancelMove:g,moveBusy:j,moveReport:p,onDismissReport:C,onWaitForIdle:M,onUndoCopy:P,invite:S,onOpenInvite:D,onInvite:B,onCloseInvite:w,inviteBusy:W,inviteReceipt:ee,inviteRefusal:z,remove:L,onOpenRemove:te,onRemove:se,onCloseRemove:ie,removeBusy:re,removeRefusal:Z,removed:Y})=>{const[X,k]=f.useState("canvas"),[E,$]=f.useState(null),T=s?Rt(s):"",_="mesh-summary",F=$t(s),G=Lt(s,l,s?.selfDeviceId??null),ce=f.useMemo(()=>{const n=new Map;for(const u of s?.devices??[]){const b=G.byDevice.get(u.id);n.set(u.id,b?Be(b,u.sessionCount):u.sessionCount??0)}return n},[s,G]),J=f.useCallback(n=>{$(n)},[]),q=s?s.devices.find(n=>n.id===E)??null:null,ue=f.useCallback((n,u,b)=>{if(!s)return null;const A={selfDeviceId:s.selfDeviceId,devices:new Map(s.devices.map(K=>[K.id,K])),networks:new Map(s.networks.map(K=>[K.id,K]))},O=n.locality==="local"?s.selfDeviceId??"":n.owner_device,V=A.devices.get(O),H=pe({session:n,ownerDeviceId:O,ownerLabel:V?.label??n.owner_device_name},{kind:"device",deviceId:u.deviceId},A);if(H.kind==="refused")return i({code:H.code,sentence:H.sentence,remedy:H.remedy,plan:H.plan??null}),null;if(H.kind==="none")return null;const Ne=b?H.alternatives.find(K=>K.keep)??H.plan:H.plan,Ve=[H.plan,...H.alternatives].filter(K=>K.keep!==Ne.keep),Ke={plan:Ne,alternatives:Ve,risky:H.risky};o(Ke)},[s,o,i]);return t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[t.jsx(Qe,{title:"Mesh",icon:we,subtitle:"Devices this app is paired with, and the networks that hold them.",children:t.jsxs("div",{className:"flex items-center gap-4",children:[a&&t.jsx("output",{className:"text-meta text-ink-dim",children:"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:"Presentation"}),t.jsx("div",{className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Ls.map(n=>t.jsx("button",{type:"button","aria-pressed":X===n,disabled:e.kind!=="ready",onClick:()=>k(n),className:R("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",X===n&&"bg-surface text-ink"),children:Ps[n]},n))})]})]})}),t.jsx(ns,{rows:m.rows,error:m.error,pending:m.pending,refusal:m.decisionRefusal,onDecide:m.onDecide,onRetry:m.onRetry,nowSeconds:m.nowSeconds,networkNames:new Map((s?.networks??[]).map(n=>[n.id,n.label]))}),e.kind==="loading"&&t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[t.jsx(Me,{className:"h-4 w-64"}),t.jsx(Me,{className:"min-h-40 w-full flex-1"})]}),e.kind==="error"&&t.jsxs(he,{variant:"warning",className:"flex-col items-start gap-2",children:[t.jsx("p",{children:e.message}),t.jsx(U,{variant:"secondary",size:"sm",onClick:c,className:"w-fit",children:"Ask again"})]}),e.kind==="empty"&&t.jsx("div",{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:"No network on this device"}),t.jsx("p",{className:"max-w-140 text-body-sm text-ink-muted",children:"This device is not in any network, so there is no mesh to draw. Create one on this machine:"}),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:"A network appears here once this device has joined one."})]})}),e.kind==="ready"&&s&&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.jsx("p",{id:_,className:"text-meta text-ink-muted","data-mesh-summary":"",children:T}),d&&t.jsx(he,{variant:"warning",children:t.jsx("p",{children:d})}),x&&t.jsx(he,{variant:"warning",children:t.jsx("p",{children:x})}),p&&t.jsx(Pt,{receipt:p.kind==="moved"?{verb:p.verb,detail:p.detail,undo:p.undo}:null,refusal:p.kind==="refused"?p.refusal:null,canWait:p.kind==="refused"&&p.plan!==null,onWait:M,onRecheck:c,onUndo:P,onDismiss:C,pending:j}),X==="canvas"?t.jsx(Cs,{graph:s,slots:F,nowSeconds:r,selectedDeviceId:E,sessions:G.byDevice,sessionTotals:ce,movingSessionId:y,canMove:I,onOpenDevice:J,onAskMove:o,onDropRefused:i,onShowAllSessions:J,summaryId:_}):t.jsx($s,{graph:s,nowSeconds:r,selectedDeviceId:E,sessions:G.byDevice,selfLabel:v,canMove:I,onSelect:J,onMove:ue,onInvite:D,onRemove:te})]}),q&&t.jsx(Ds,{device:q,sessions:G.byDevice.get(q.id)??{rows:[],shown:[],hidden:0},sessionTotal:ce.get(q.id)??0,nowSeconds:r,canMove:I,canInvite:e.kind==="ready",movingSessionId:y,destinationsFor:n=>Ue(s,n,v),onClose:()=>$(null),onMove:ue,onInvite:n=>D({deviceId:n.id,deviceLabel:n.label}),onRemoveMember:(n,u)=>{const b=s.networks.find(A=>A.id===u);te({networkId:u,networkLabel:b?.label??u,deviceId:n.id,deviceLabel:n.label})},onShowInList:n=>{J(n),k("list")}})]})}),t.jsx(Tt,{open:N!==null,plan:N?.plan??Os,alternatives:N?.alternatives??[],risky:N?.risky??!1,busy:j,onCancel:g,onChoose:h}),S&&t.jsx(Ot,{open:S.open,options:S.options,deviceId:S.deviceId,deviceLabel:S.deviceLabel,onClose:w,onInvite:B,pending:W,receipt:ee,refusal:z}),L&&t.jsx(Wt,{open:L.open,networkLabel:L.networkLabel,deviceLabel:L.deviceLabel,onClose:ie,onConfirm:se,pending:re,refusal:Z,removed:Y})]})},Os={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},Vs=()=>{const e=qe(),s=xe(e.data,"peers")==="enabled",r=xe(e.data,"session_transfer")==="enabled",a=zt(s),d=Ht(s),c=Bt(s),m=f.useMemo(()=>({peers:a,networks:d}),[a,d]),l=Yt(m),x=Ft(m),v=Ut(),y=xe(e.data,"approvals")==="enabled",I=Gt(s&&y,{poll:!1}),N=Vt(),o=N.isError?{approvalId:N.variables?.approvalId??null,...Kt(N.error)}:null,i=f.useMemo(()=>Math.floor((I.dataUpdatedAt||Date.now())/1e3),[I.dataUpdatedAt]),h=Ze(k=>k.settlePlacement),g=Xt(),j=qt(),[p,C]=f.useState(null),[M,P]=f.useState(null),[S,D]=f.useState(null),[B,w]=f.useState(null),[W,ee]=f.useState(null),[z,L]=f.useState(null),[te,se]=f.useState(null),ie=f.useMemo(()=>{const k=Math.max(a.dataUpdatedAt,d.dataUpdatedAt);return Math.floor((k||Date.now())/1e3)},[a.dataUpdatedAt,d.dataUpdatedAt]),re=f.useCallback(()=>{a.refetch(),d.refetch(),c.refetch()},[a,d,c]),Z=f.useCallback((k,E)=>{C(null);const $={sessionId:k.sessionId,to:k.to,keep:k.keep,waitS:E??k.waitS};v.mutate($,{onSuccess:T=>{if(T.kind==="moved"){const{receipt:_}=T;h(k.sessionId,_);const F=_.locality==="local"?"this device":x?.devices.find(G=>G.id===_.owner_device)?.label??_.owner_device;P({kind:"moved",verb:_.mode==="keep"?"Copied":"Moved",detail:_.mode==="keep"?`${F} holds a copy as ${_.new_session_id.slice(-6)}; the original is still here.`:`${F} holds it now${_.source_retired?"; the copy here is gone":""}.`,undo:_.mode==="keep"?{sessionId:_.new_session_id,to:"local",keep:!1,verb:`Bring the copy back from ${F}`,waitS:0,lost:Zt(F,"this device")}:null});return}P({kind:"refused",refusal:T.refusal,plan:k})},onError:()=>{P({kind:"refused",refusal:{code:"move_failed",sentence:"The move could not be sent. Nothing here changed; the list has been read again.",status:null,unconfirmed:!1},plan:k})}})},[x,v,h]),Y=f.useMemo(()=>{if(!x)return[];const k=S?.deviceId,E=k?x.devices.find($=>$.id===k):void 0;return x.networks.filter($=>{if(!E)return!0;const T=E.memberships.find(_=>_.networkId===$.id);return!T||!T.active}).map($=>({id:$.id,label:$.label}))},[x,S]);if(!s)return t.jsx(Je,{to:"/chat",replace:!0});const X=l.kind==="ready"?a.error?le(a.error):d.error?le(d.error):null:null;return t.jsx(Ts,{state:l,graph:x,nowSeconds:ie,checking:a.isFetching||d.isFetching,staleError:X,onRetry:re,approvals:{rows:I.data??[],error:I.isError?Jt(I.error):null,pending:N.isPending?N.variables??null:null,decisionRefusal:o,onDecide:(k,E)=>N.mutate({approvalId:k,decision:E}),onRetry:()=>void I.refetch(),nowSeconds:i},sessions:c.data??[],movingSessionId:v.isPending?v.variables?.sessionId??null:null,sessionError:c.isError?le(c.error):null,selfLabel:x?.devices.find(k=>k.state==="self")?.label??"this device",canMove:r,pendingMove:p,onAskMove:C,onDropRefused:k=>P({kind:"refused",refusal:{code:k.code,sentence:k.sentence,status:null,unconfirmed:!1},plan:k.plan}),onChooseMove:k=>Z(k),onCancelMove:()=>C(null),moveBusy:v.isPending,moveReport:M,onDismissReport:()=>P(null),onWaitForIdle:()=>{M?.kind!=="refused"||!M.plan||Z(M.plan,Ws)},onUndoCopy:()=>{M?.kind!=="moved"||!M.undo||C({plan:M.undo,alternatives:[],risky:!1})},invite:S===null?null:{open:!0,deviceId:S.deviceId,deviceLabel:S.deviceLabel,options:Y},onOpenInvite:k=>{w(null),ee(null),D(k)},onInvite:k=>{g.mutate(k,{onSuccess:E=>w(E),onError:E=>ee({code:"invite_refused",sentence:le(E),status:null,unconfirmed:!1})})},onCloseInvite:()=>D(null),inviteBusy:g.isPending,inviteReceipt:B,inviteRefusal:W,remove:z===null?null:{open:!0,networkId:z.networkId,networkLabel:z.networkLabel,deviceId:z.deviceId,deviceLabel:z.deviceLabel},onOpenRemove:k=>{se(null),L(k)},onRemove:k=>{z&&j.mutate({networkId:z.networkId,deviceId:z.deviceId,confirm:k},{onSuccess:E=>se(E)})},onCloseRemove:()=>L(null),removeBusy:j.isPending,removeRefusal:j.isError?{code:"remove_refused",sentence:le(j.error),status:null,unconfirmed:!1}:null,removed:te})},Ws=300;export{Vs as MeshPage,Ts as MeshSurface,Vs as default};
|
|
1
|
+
import{r as f,j as t,c as R}from"./index-DvjcW_EJ.js";import{aW as we,aX as Xe,aY as Oe,a as qe,aZ as xe,ah as Ze,a_ as Je}from"./conversation-input-sync-BW_UGWKP.js";import{P as Qe}from"./page-header-ouA0fPx9.js";import{B as U,j as Ie,A as he,k as et,a as ne,D as tt,l as st,m as nt,n as at,o as Ce,p as Se,e as Me}from"./error-boundary-9syfMgM3.js";import{i as it,d as rt,e as lt,f as ot,g as dt,h as ct,j as ut,k as mt,l as ht,m as pt,n as ft,o as xt,p as bt,q as gt,r as vt,N as kt,s as je,t as wt,u as oe,D as jt,v as yt,w as Nt,x as ye,y as ke,R as It,z as de,C as We,E as ze,F as Ct,G as me,H as be,I as St,J as Mt,K as pe,L as De,M as Dt,O as Et,Q as ge,T as At,U as He,V as _t,W as Be,X as Rt,Y as $t,Z as Lt,_ as Pt,$ as Tt,a0 as Ot,a1 as Wt,a2 as zt,a3 as Ht,a4 as Bt,a5 as Yt,a6 as Ft,a7 as Ut,a8 as Gt,a9 as Vt,aa as Kt,ab as Xt,ac as qt,ad as Zt,ae as le,af as Jt}from"./index-C024E3U7.js";import"./ui-preferences-store-ClQPCzID.js";import"./console-mirror-D3uHRfYy.js";function Qt(e){return e==="requested"?"attention":e==="failed"?"danger":e==="connected"?"success":"neutral"}function es(e){switch(e){case"requested":return"Approving signs with this machine's operator key; the system may ask for it.";case"approved":return"An agent runs the install and connect (lop network approvals run).";case"connecting":return"Denying now stops it at its next step.";case"failed":return"The runner stopped. Denying abandons it; an agent can retry it.";default:return null}}function ts(e){switch(e){case"requested":return"Signing";case"approved":return"Next";case"connecting":return"Stop";case"failed":return"After a stop";default:return"What this means"}}function ss(e){return e==="connected"?"connected":e==="denied"?"denied":"expired"}const ns=({rows:e,error:s,pending:r,refusal:a,onDecide:d,onRetry:c,nowSeconds:m,networkNames:l})=>{const x=r!==null,v=f.useMemo(()=>e.filter(i=>it(i.state)),[e]),[y,I]=f.useState([]),N=f.useRef(new Map);f.useEffect(()=>{const i=new Map;for(const g of v)i.set(g.approvalId,rt(g));const h=[];for(const[g,j]of N.current){if(i.has(g))continue;const C=e.find(M=>M.approvalId===g)?.state??"";(C==="connected"||C==="denied"||C==="expired")&&h.push({key:`${g}:${C}`,text:`${j} — ${ss(C)}`})}h.length&&I(g=>[...g,...h].slice(-3)),N.current=i},[v,e]);const o=a!==null&&v.some(i=>i.approvalId===a.approvalId);return v.length===0&&y.length===0&&!s&&!a?null:t.jsxs("section",{"aria-label":"Approvals","data-tour-tag":"mesh-approvals-tray",className:"flex flex-col gap-3 rounded-lg border border-hairline bg-surface p-3",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(lt,{"aria-hidden":"true",className:"size-4 text-ink-muted"}),t.jsx("h2",{className:"text-body-sm text-ink",children:"Approvals"}),v.length>0&&t.jsx("span",{className:"text-meta text-ink-dim",children:v.length===1?"1 waiting":`${v.length} waiting`})]}),s&&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:s}),t.jsx(U,{variant:"secondary",size:"sm",onClick:c,children:"Ask again"})]}),v.length>0&&t.jsx("ul",{className:"flex flex-col divide-y divide-hairline",children:v.map(i=>t.jsx(as,{row:i,pending:r?.approvalId===i.approvalId?r:null,busy:x,refusal:a?.approvalId===i.approvalId?a:null,onDecide:d,nowSeconds:m,networkNames:l},i.approvalId))}),a&&!o&&t.jsx(Ye,{refusal:a}),y.length>0&&t.jsx("ul",{className:"flex flex-col gap-0.5 text-meta text-ink-dim","data-tour-tag":"mesh-approvals-resolved",children:y.map(i=>t.jsx("li",{children:i.text},i.key))})]})},as=({row:e,pending:s,busy:r,refusal:a,onDecide:d,nowSeconds:c,networkNames:m})=>{const l=ot(e),x=dt(e),v=ct(e),y=ut(e,m),I=mt(e),N=ht(e.expiresAt,c),o=es(e.state),i=pt(e.state),h=ft(e.state);return t.jsxs("li",{className:"flex flex-col gap-2 py-3 first:pt-0 last:pb-0","data-tour-tag":"mesh-approval-card",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(Ie,{variant:Qt(e.state),children:xt(e.state)}),t.jsx("span",{className:"text-body-sm text-ink",children:bt(e)}),t.jsx("div",{className:"grow"}),N&&t.jsx("span",{className:"text-meta text-ink-dim",children:N})]}),(l||x)&&t.jsxs("p",{className:"text-meta text-ink-muted",children:[l&&t.jsx("span",{children:l}),l&&x&&t.jsx("span",{children:" · "}),x&&t.jsx("span",{className:"font-mono",children:x})]}),y.length>0&&t.jsx("ul",{className:"flex flex-wrap gap-1",children:y.map(g=>t.jsx("li",{children:t.jsx(Ie,{variant:gt(g),children:g})},g))}),v&&t.jsx("p",{className:"text-meta text-ink-dim",children:v}),I.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-scope-glosses",children:I.map(g=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:g.term}),t.jsx("dd",{children:g.gloss})]},g.term))}),o&&t.jsxs("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta","data-tour-tag":"mesh-approval-consequence",children:[t.jsx("dt",{className:"text-ink-muted",children:ts(e.state)}),t.jsx("dd",{className:"text-ink-muted",children:o})]}),(i||h)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i&&t.jsx(U,{variant:"primary",size:"sm",disabled:r,onClick:()=>d(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:"Approve"}),h&&t.jsx(U,{variant:i?"ghost":"secondary",size:"sm",disabled:r,onClick:()=>d(e.approvalId,"deny"),"data-tour-tag":"mesh-approval-deny",children:"Deny"}),s&&t.jsx("span",{className:"text-meta text-ink-dim",children:s.decision==="approve"?"Waiting for the signing prompt…":"Writing the decision…"})]}),a&&t.jsx(Ye,{refusal:a})]})},Ye=({refusal:e})=>t.jsxs(he,{variant:"warning",className:"text-meta",children:[t.jsx("span",{className:"min-w-0 flex-1",children:e.sentence}),t.jsx("span",{className:"shrink-0 font-mono text-ink-dim",children:e.code})]}),is=4,fe={kind:"idle"};function rs(e){switch(e.kind){case"dragging":case"settling":return e.payload.session.id;case"pressing":return null;default:return null}}function Q(e,s){switch(s.kind){case"press":return e.kind!=="idle"?e:{kind:"pressing",payload:s.payload,originX:s.x,originY:s.y,pointerId:s.pointerId};case"move":return e.kind==="pressing"?Math.max(Math.abs(s.x-e.originX),Math.abs(s.y-e.originY))<is?e:{kind:"dragging",payload:e.payload,x:s.x,y:s.y,target:s.target,pointerId:e.pointerId}:e.kind==="dragging"?{...e,x:s.x,y:s.y,target:s.target}:e;case"release":return e.kind==="dragging"?{kind:"settling",payload:e.payload,target:e.target}:e.kind==="pressing"?fe:e;case"cancel":case"settled":return fe;default:return e}}const ls=({edges:e,geometry:s,selectedDeviceId:r})=>t.jsx("svg",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0 overflow-visible",width:s.bounds.width,height:s.bounds.height,children:e.map(a=>{const d=s.networks.get(a.networkId),c=s.devices.get(a.deviceId);if(!d||!c)return null;const m=r!==null&&a.deviceId===r;return t.jsx("path",{"data-mesh-edge":a.key,d:vt(d,c),fill:"none",strokeWidth:m?2:1.5,strokeDasharray:a.active?void 0:"4 4",className:m?"stroke-ink":"stroke-ink-dim"},a.key)})}),os={self:"border-l-hairline",reached:"border-l-hairline",unanswered:"border-l-warning","not-attempted":"border-l-hairline",unknown:"border-l-hairline"};function ds(e){return e.suspect?"border-l-danger":os[oe(e)]}const cs={self:"ring-2 ring-accent",reachable:null,unreachable:null,suspect:null},us={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function ms(e,s,r){return[e.label,ze(e,s),r].filter(Boolean).join(", ")}function ae(e){return e.name.trim()||e.id.slice(-6)}function Fe(e,s,r){if(r!=="reached"&&r!=="self"){const a=de(r);return e.unreachable_reason?`${a} (${e.unreachable_reason})`:a}return e.live_state.trim()?e.live_state.trim():e.locality==="local"?"on this device":`on ${s}`}const hs={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},ps=({network:e,x:s,y:r,refused:a})=>t.jsxs("li",{"data-mesh-network":e.id,"data-mesh-network-refused":a?"true":void 0,className:R("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",a?"border-warning":"border-hairline"),style:{left:s,top:r,width:je,height:kt},children:[t.jsx(we,{"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:`epoch ${e.epoch}`,className:"block truncate text-meta text-ink-dim",children:[e.memberCount," ",e.memberCount===1?"device":"devices",e.revokedCount>0?` · ${e.revokedCount} revoked`:""]})]})]}),fs=({device:e,x:s,y:r,nowSeconds:a,selected:d,sessions:c,sessionTotal:m,dropState:l,movingSessionId:x,draggedSessionId:v,onOpen:y,onChipPointerDown:I,onChipClick:N,onShowAllSessions:o})=>{const{activity:i}=wt(e,c.rows),h=i==="working",g=ms(e,a,h?"working":null),j=oe(e);return t.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":l??void 0,"aria-current":d?"true":void 0,className:R("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",ds(e),cs[e.state],l&&us[l]),style:{left:s,top:r,width:je,height:jt},children:[t.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":j,"aria-label":g,title:Nt(e),onClick:()=>y(e.id),className:R("flex w-full flex-col justify-between rounded-t-[5px] px-3 pt-2 pb-2 text-left","cursor-pointer","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),style:{height:yt},children:[t.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2",children:[t.jsx(Xe,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",children:e.label}),e.suspect&&t.jsx(ye,{"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:R("min-w-0 truncate text-meta",e.sessionCount===null?"text-ink-dim":"text-ink-muted"),children:ke(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:It[j]}),t.jsx("span",{className:R("shrink-0",We[j]),children:de(j)}),h&&t.jsx("span",{"data-mesh-working":"",className:"shrink-0 text-info",children:"working"}),e.memberships.length>1&&t.jsxs("span",{className:"min-w-0 truncate text-ink-dim",children:["· ",e.memberships.length," networks"]})]})]}),t.jsxs("ul",{"aria-label":`Conversations on ${e.label}`,className:R("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",l==="accept"&&"opacity-40"),children:[c.shown.map(p=>t.jsx(xs,{session:p,ownerLabel:e.label,ownerReach:j,ownerReachable:e.reachable,moving:x===p.id,dragging:v===p.id,onPointerDown:I,onClick:()=>N(p)},p.id)),c.hidden>0&&t.jsx("li",{className:"shrink-0",children:t.jsxs("button",{type:"button","data-mesh-more":e.id,onClick:()=>o(e.id),className:R("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:`Showing ${c.shown.length} of ${m} conversations`,"aria-label":`Show all ${m} conversations`,children:["+",c.hidden]})})]})]})},xs=({session:e,ownerLabel:s,ownerReach:r,ownerReachable:a,moving:d,dragging:c,onPointerDown:m,onClick:l})=>{const x=Fe(e,s,r);return d?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:"moving…"})}):t.jsx("li",{className:"min-w-0 flex-1","data-mesh-session-item":e.id,"data-mesh-dragging":c?"true":void 0,children:t.jsx("button",{type:"button","data-mesh-session":e.id,style:{touchAction:"none"},title:`${ae(e)} · ${x}`,"aria-label":`${ae(e)}, ${x}. Opens ${s}.`,onPointerDown:v=>m(v,e),onClick:()=>l(e),className:R("flex min-h-6 w-full max-w-32 items-center rounded-sm border border-hairline bg-surface px-1.5 text-left text-meta text-ink-muted","cursor-grab active:cursor-grabbing","hover:text-ink",hs[Ct(e,a)],c&&"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 [direction:rtl]",children:ae(e)})})})};function Ee(e){const s=e.trim();if(!s)return null;if(s.startsWith("[")){const a=s.indexOf("]");if(a<=1)return null;const d=s.slice(1,a),c=s.slice(a+1);if(!c)return{host:d,port:null};if(!c.startsWith(":"))return null;const m=Number(c.slice(1));return{host:d,port:Number.isInteger(m)?m:null}}const r=s.lastIndexOf(":");if(r>0){const a=s.slice(r+1);if(/^\d+$/.test(a))return{host:s.slice(0,r),port:Number(a)}}return{host:s,port:null}}function Ae(e){const s=e.trim().split(".");if(s.length!==4)return null;for(const r of s)if(!/^\d{1,3}$/.test(r)||Number(r)>255)return null;return`${s[0]}.${s[1]}.${s[2]}`}function bs(e){return`${e}.x`}function gs(e){const s=new Map;for(const a of e.values())for(const d of a)s.set(d,(s.get(d)??0)+1);const r=new Set;for(const[a,d]of s)d>1&&r.add(a);return r}function ve(e){return new Set(e.endpoints.map(s=>s.trim()).filter(Boolean))}function vs(e,s){const r=e.filter(o=>o.id!==s),a=e.find(o=>o.id===s)??null,d=new Map;for(const o of e)d.set(o.id,ve(o));const c=gs(d),m=new Set;for(const o of a?ve(a):[]){if(c.has(o))continue;const i=Ee(o),h=i?Ae(i.host):null;h&&m.add(h)}const l=o=>{const i=new Set;for(const h of ve(o)){if(c.has(h))continue;const g=Ee(h),j=g?Ae(g.host):null;j&&i.add(j)}return i},x=new Map,v=new Map;for(const o of r){const i=ks(o);if(i){x.set(i,[...x.get(i)??[],o.id]);continue}for(const h of l(o))v.set(h,[...v.get(h)??[],o.id])}const y=new Map(e.map((o,i)=>[o.id,i])),I=o=>[...o].sort((i,h)=>(y.get(i)??0)-(y.get(h)??0)),N=[];for(const[o,i]of x)N.push({prefix:o,tier:"declared",deviceIds:I(i),words:"declared"});for(const[o,i]of v)m.has(o)?N.push({prefix:o,tier:"shared",deviceIds:I(i),words:"shared with this device"}):i.length>1&&N.push({prefix:o,tier:"probable",deviceIds:I(i),words:"same prefix"});return N.sort((o,i)=>o.tier.localeCompare(i.tier)||o.prefix.localeCompare(i.prefix))}function ks(e){for(const s of e.memberships){const r=s.scope.trim();if(r)return r}return""}const _e={declared:0,shared:1,probable:2};function ws(e,s){const r=new Map;for(const d of e){let c=null;for(const l of d.deviceIds){const x=s.get(l);x!==void 0&&(c===null||x<c.slot)&&(c={id:l,slot:x})}if(c===null)continue;const m=r.get(c.id);m===void 0?r.set(c.id,{slot:c.slot,groups:[d]}):m.groups.push(d)}const a=d=>{let c=-1;for(const m of d.deviceIds){const l=s.get(m);l!==void 0&&l>c&&(c=l)}return c};return[...r.entries()].sort((d,c)=>d[1].slot-c[1].slot).map(([d,c])=>({deviceId:d,groups:c.groups.sort((m,l)=>a(l)-a(m)||_e[m.tier]-_e[l.tier]||m.prefix.localeCompare(l.prefix))}))}function js(e){return new Map(e.map(s=>[s.deviceId,s.groups.length]))}function ys(e){return`${e.tier==="declared"?e.prefix:bs(e.prefix)} · ${e.words}`}const Re=(e,s)=>e.deviceIds.map(r=>s.devices.get(r)).filter(r=>r!==void 0),Ns=({stacks:e,geometry:s})=>t.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(r=>{const a=r.groups.length,d=new Array(a).fill(0);let c=null;for(let l=a-1;l>=0;l-=1){const x=Re(r.groups[l],s),v=(x.length===0?0:Math.max(...x.map(y=>y.y+y.height)))+me;c=c===null?v:Math.max(v,c+be),d[l]=c}const m=s.devices.get(r.deviceId);return r.groups.map((l,x)=>{const v=Re(l,s);if(v.length===0)return null;const y=a-1-x,I=Math.min(...v.map(j=>j.x)),N=Math.max(...v.map(j=>j.x)),i=(m?.y??Math.min(...v.map(j=>j.y)))-me-St*y,h=l.tier==="declared",g=ys(l);return t.jsx("div",{"data-mesh-scope":`${l.tier}:${l.prefix}`,"data-mesh-scope-level":x,className:R("absolute rounded-lg",l.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:I-me-be*y,top:i,width:N+je-I+(me+be*y)*2,height:d[x]-i},children:t.jsx("span",{"data-mesh-scope-label":"",className:R("absolute bottom-full left-1 mb-0.5 whitespace-nowrap text-meta",l.tier==="probable"?"text-ink-dim":"text-ink-muted",h&&"font-medium"),children:g})},`${l.tier}:${l.prefix}`)})})}),$e=48,Le=1.25,Is=.0015,Cs=({graph:e,slots:s,nowSeconds:r,selectedDeviceId:a,sessions:d,sessionTotals:c,movingSessionId:m,canMove:l,onOpenDevice:x,onAskMove:v,onDropRefused:y,onShowAllSessions:I,summaryId:N})=>{const o=f.useRef(null),[i,h]=f.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[g,j]=f.useState({k:1,tx:0,ty:0}),p=f.useRef(!1),C=f.useRef(!1),M=f.useRef(null),P=f.useMemo(()=>vs(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),S=f.useMemo(()=>ws(P,s.devices),[P,s]),D=f.useMemo(()=>Mt(s,js(S)),[s,S]),B=f.useMemo(()=>({selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(n=>[n.id,n])),networks:new Map(e.networks.map(n=>[n.id,n]))}),[e]),[w,W]=f.useState(fe),ee=f.useRef({kind:"ground"}),z=f.useCallback((n,u)=>{const b=document.elementFromPoint(n,u),A=b?.closest("[data-mesh-device]");if(A){const V=A.getAttribute("data-mesh-device");if(V)return{kind:"device",deviceId:V}}const O=b?.closest("[data-mesh-network]");if(O){const V=O.getAttribute("data-mesh-network");if(V)return{kind:"network",networkId:V}}return{kind:"ground"}},[]),L=f.useMemo(()=>w.kind!=="dragging"&&w.kind!=="settling"?null:pe(w.payload,w.target,B),[w,B]),te=f.useCallback(n=>{if(!L)return null;if(L.kind==="plan"){const u=w.kind==="dragging"||w.kind==="settling"?w.target:null;return u&&u.kind==="device"&&u.deviceId===n?"accept":null}if(L.kind==="refused"){const u=w.kind==="dragging"||w.kind==="settling"?w.target:null;return u&&u.kind==="device"&&u.deviceId===n?"refuse":null}return null},[L,w]),se=f.useCallback((n,u)=>{if(!l||n.button!==0)return;C.current=!1;const b=u.locality==="local"?e.selfDeviceId??"":u.owner_device,A=B.devices.get(b),O={session:u,ownerDeviceId:b,ownerLabel:A?.label??u.owner_device_name};try{n.currentTarget.setPointerCapture(n.pointerId)}catch{}W(V=>Q(V,{kind:"press",payload:O,x:n.clientX,y:n.clientY,pointerId:n.pointerId}))},[l,B,e.selfDeviceId]),ie=n=>{if(w.kind==="pressing"||w.kind==="dragging"){const u=z(n.clientX,n.clientY);ee.current=u,W(b=>Q(b,{kind:"move",x:n.clientX,y:n.clientY,target:u}));return}ce(n)},re=n=>{if(J(n),w.kind!=="pressing"&&w.kind!=="dragging")return;if(w.kind==="pressing"){W(b=>Q(b,{kind:"cancel"}));return}const u=pe(w.payload,w.target,B);C.current=!0,W(b=>Q(b,{kind:"release"})),u.kind==="plan"?v({plan:u.plan,alternatives:u.alternatives,risky:u.risky}):u.kind==="refused"&&y({code:u.code,sentence:u.sentence,remedy:u.remedy,plan:u.plan??null}),W(b=>Q(b,{kind:"settled"}))};f.useEffect(()=>()=>W(fe),[]);const Z=f.useCallback(()=>{j(De(D.bounds,i))},[D.bounds,i]);f.useEffect(()=>{const n=o.current;if(!n)return;const u=()=>{const A=n.getBoundingClientRect();h({width:A.width,height:A.height,clipWidth:n.clientWidth,clipHeight:n.clientHeight,left:A.left,top:A.top})};u();const b=new ResizeObserver(u);return b.observe(n),()=>b.disconnect()},[]),f.useEffect(()=>{p.current||i.width<=0||i.height<=0||(p.current=!0,j(De(D.bounds,i)))},[i,D.bounds]),f.useEffect(()=>{const n=M.current;if(M.current={width:i.width,height:i.height},!n||!p.current||i.width<=0||i.height<=0||i.width>=n.width&&i.height>=n.height||!a)return;const u=D.devices.get(a);u&&j(b=>{const A={width:i.clipWidth,height:i.clipHeight},O=Math.max(0,Math.min(A.width-D.bounds.width*b.k,A.height-D.bounds.height*b.k));return Dt(b,u,A,Math.min(At,O))})},[i,a,D]);const Y=w.kind==="dragging"?{x:w.x-i.left+12,y:w.y-i.top+12}:{x:0,y:0},X=L?Et(L):null,k=f.useRef(null),E=f.useRef(null),$=f.useRef(null),T=f.useRef(null),_=f.useCallback(()=>{$.current=null;const n=k.current,u=E.current;if(k.current=null,E.current=null,n){const b=T.current;if(!b)return;j({k:b.transform.k,tx:b.transform.tx+(n.x-b.x),ty:b.transform.ty+(n.y-b.y)});return}u&&j(b=>ge(b,{x:u.x,y:u.y},b.k*Math.exp(-u.deltaY*Is)))},[]),F=f.useCallback(()=>{$.current===null&&($.current=requestAnimationFrame(_))},[_]);f.useEffect(()=>()=>{$.current!==null&&cancelAnimationFrame($.current)},[]);const G=n=>{!(n.target===n.currentTarget)&&n.button!==1||n.button!==0&&n.button!==1||(T.current={x:n.clientX,y:n.clientY,transform:g},n.currentTarget.setPointerCapture(n.pointerId),n.preventDefault())},ce=n=>{T.current&&(k.current={x:n.clientX,y:n.clientY},F())},J=n=>{T.current&&(T.current=null,k.current=null,n.currentTarget.hasPointerCapture(n.pointerId)&&n.currentTarget.releasePointerCapture(n.pointerId))},q=f.useCallback(n=>{if(n.deltaY===0)return;n.preventDefault();const u=n.currentTarget.getBoundingClientRect();E.current={x:n.clientX-u.left,y:n.clientY-u.top,deltaY:n.deltaY},F()},[F]);f.useEffect(()=>{const n=o.current;if(n)return n.addEventListener("wheel",q,{passive:!1}),()=>n.removeEventListener("wheel",q)},[q]);const ue=n=>{const u=n.shiftKey?$e*4:$e;switch(n.key){case"Escape":if(w.kind!=="pressing"&&w.kind!=="dragging")return;n.preventDefault(),w.kind==="dragging"&&(C.current=!0),W(b=>Q(b,{kind:"cancel"}));return;case"0":n.preventDefault(),Z();return;case"+":case"=":n.preventDefault(),j(b=>ge(b,{x:i.width/2,y:i.height/2},b.k*Le));return;case"-":case"_":n.preventDefault(),j(b=>ge(b,{x:i.width/2,y:i.height/2},b.k/Le));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{n.preventDefault();const b=n.key==="ArrowLeft"?u:n.key==="ArrowRight"?-u:0,A=n.key==="ArrowUp"?u:n.key==="ArrowDown"?-u:0;j(O=>({...O,tx:O.tx+b,ty:O.ty+A}));return}}};return t.jsxs("div",{ref:o,"data-mesh-canvas":"",role:"group","aria-labelledby":N,tabIndex:0,onPointerDown:G,onPointerMove:ie,onPointerUp:re,onPointerCancel:n=>{w.kind==="dragging"&&(C.current=!0),W(u=>Q(u,{kind:"cancel"})),J(n)},"data-mesh-gesture":w.kind,onKeyDown:ue,onDoubleClick:n=>{n.target===n.currentTarget&&Z()},className:R("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:`${g.tx}px ${g.ty}px`}}),t.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${g.tx}px, ${g.ty}px, 0) scale(${g.k})`,transformOrigin:"0 0",width:D.bounds.width,height:D.bounds.height},children:[t.jsx(Ns,{stacks:S,geometry:D}),t.jsx(ls,{edges:e.edges,geometry:D,selectedDeviceId:a}),t.jsx("ul",{"aria-label":"Networks",className:"m-0 list-none p-0",children:e.networks.map(n=>{const u=D.networks.get(n.id);return u?t.jsx(ps,{network:n,x:u.x,y:u.y,refused:L?.kind==="refused"&&w.kind==="dragging"&&w.target.kind==="network"&&w.target.networkId===n.id},n.id):null})}),t.jsx("ul",{"aria-label":"Devices",className:"m-0 list-none p-0",children:e.devices.map(n=>{const u=D.devices.get(n.id);return u?t.jsx(fs,{device:n,x:u.x,y:u.y,nowSeconds:r,selected:n.id===a,sessions:d.get(n.id)??{rows:[],shown:[],hidden:0},sessionTotal:c.get(n.id)??n.sessionCount??0,dropState:te(n.id),movingSessionId:m,draggedSessionId:rs(w),onOpen:x,onChipPointerDown:se,onChipClick:()=>{if(C.current){C.current=!1;return}x(n.id)},onShowAllSessions:I},n.id):null})})]}),w.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:Y.x,top:Y.y},children:w.payload.session.name||"untitled"}),w.kind==="dragging"&&X&&t.jsx("div",{"data-mesh-indicator":"",className:R("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",L?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:Y.x,maxWidth:Math.max(160,i.width-Y.x-12),...Y.y>i.height*.6?{bottom:Math.max(12,i.height-Y.y+8)}:{top:Y.y+24}},children:X})]})};function Ss(e,s,r,a){const d=r.locality==="local"?s:r.owner_device,c=[];for(const m of e)if(m.id!==d){if(m.id===s){c.push({deviceId:m.id,label:a,verb:"Recall to this device",keepVerb:"Copy here, leave it there"});continue}c.push({deviceId:m.id,label:m.label,verb:`Move to ${m.label}`,keepVerb:`Copy to ${m.label}`})}return c}function Ms(e,s,r){return Ss(e.devices,e.selfDeviceId,s,r)}function Ue(e,s,r){const a=Ms(e,s,r),d={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(l=>[l.id,l])),networks:new Map(e.networks.map(l=>[l.id,l]))},c=s.locality==="local"?e.selfDeviceId??"":s.owner_device,m=d.devices.get(c);return a.map(l=>{const x=pe({session:s,ownerDeviceId:c,ownerLabel:m?.label??s.owner_device_name},{kind:"device",deviceId:l.deviceId},d);return{...l,refused:x.kind==="refused"&&x.code!=="busy"?x.sentence:null}})}const Ge=({session:e,destinations:s,disabled:r,onChoose:a,onOpenChange:d,trigger:c,triggerLabel:m})=>t.jsxs(tt,{onOpenChange:d,children:[t.jsx(st,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":m,"data-mesh-session-menu":e.id,disabled:r||s.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:c})}),t.jsxs(nt,{align:"start",className:"min-w-56",children:[t.jsx(at,{children:ae(e)}),t.jsx(Ce,{}),s.map(l=>t.jsx(Se,{"data-mesh-move-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>a(l,!1),children:l.verb},l.deviceId)),t.jsx(Ce,{}),s.map(l=>t.jsx(Se,{"data-mesh-copy-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>a(l,!0),children:l.keepVerb},`keep-${l.deviceId}`))]})]}),Ds=({device:e,sessions:s,sessionTotal:r,nowSeconds:a,destinationsFor:d,movingSessionId:c,canMove:m,canInvite:l,onClose:x,onMove:v,onShowInList:y,onInvite:I,onRemoveMember:N})=>{const o=oe(e);f.useEffect(()=>{const p=C=>{C.key!=="Escape"||C.defaultPrevented||C.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),x())};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[e.id,x]);const i=e.memberships.every(p=>!p.active),h=e.sessionCount===null?ke(null):`${e.sessionCount} ${ke(e.sessionCount)}`,g=e.suspect?He:[i?"revoked membership":h,de(o)].filter(Boolean).join(" · "),j=r>s.rows.length?`${s.rows.length} of ${r}`:`${s.rows.length}`;return t.jsxs("aside",{"aria-label":`${e.label} details`,"data-mesh-panel":e.id,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(U,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:x,children:"Close"}),t.jsx("h2",{className:"text-body-sm text-ink",children:e.label}),t.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[e.suspect&&t.jsx(ye,{"aria-hidden":"true",className:"size-3.5 text-danger"}),!e.suspect&&o==="unanswered"&&t.jsx(et,{"aria-hidden":"true",className:"size-3.5 text-warning"}),g]})]}),t.jsx(ne,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:"Memberships"}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:e.memberships.map(p=>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(we,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),p.networkName]}),t.jsxs("span",{className:"text-meta text-ink-dim",children:[p.role||"member",p.capabilities.length>0?` · ${p.capabilities.join(", ")}`:"",p.active?"":" · revoked"]}),l&&p.active&&t.jsxs(U,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${p.networkId}:${e.id}`,onClick:()=>N(e,p.networkId),children:["Remove from ",p.networkName,"…"]})]},p.networkId))}),l&&t.jsx(U,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":e.id,onClick:()=>I(e),children:"Invite to a network…"})]}),t.jsx(ne,{}),t.jsxs("section",{className:"flex min-h-0 flex-col gap-2",children:[t.jsxs("h3",{className:"text-meta text-ink-dim",children:["Conversations ",t.jsxs("span",{className:"text-ink-disabled",children:["(",j,")"]})]}),s.rows.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:e.sessionCount===null?"This device did not report its conversations.":"No conversations here."}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:s.rows.map(p=>t.jsxs("li",{"data-mesh-panel-session":p.id,className:R("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",c===p.id&&"border-control"),children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",children:ae(p)}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:Fe(p,e.label,oe(e))}),c===p.id?t.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:"moving…"}):t.jsx(Ge,{session:p,destinations:d(p),disabled:!m,onChoose:(C,M)=>v(p,C,M),trigger:t.jsx(Oe,{"aria-hidden":"true",className:"size-4"}),triggerLabel:`Move ${ae(p)}`})]},p.id))})]}),t.jsx(ne,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:"Network addresses"}),e.endpoints.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:"No address published."}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:e.endpoints.map(p=>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:p}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:"advertised"})]},p))})]}),t.jsx(ne,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:"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:"Reach"}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:de(o)})]}),t.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("dt",{className:"text-meta text-ink-dim",children:"Last status frame"}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:e.lastSeenAt===null?"never":_t(a-e.lastSeenAt)})]})]}),e.reason&&t.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),t.jsx(ne,{}),t.jsx(U,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>y(e.id),children:"Show in list"})]})},Es=["name","chats","state"],As={name:"Name",chats:"Conversations",state:"State"},Pe={suspect:0,unreachable:1,self:2,reachable:3};function _s(e,s){const r=[...e];switch(s){case"chats":return r.sort((a,d)=>(d.sessionCount??-1)-(a.sessionCount??-1)||a.label.localeCompare(d.label)),r;case"state":return r.sort((a,d)=>Pe[a.state]-Pe[d.state]||a.label.localeCompare(d.label)),r;default:return r.sort((a,d)=>a.label.localeCompare(d.label))}}const Te=8;function Rs(e,s){if(e.locality==="local")return e.live_state||"here";const r=e.owner_device_name||s,a=e.live_state?` · ${e.live_state}`:"";return e.reachable?`on ${r}${a}`:`on ${r} (not answering)`}const $s=({graph:e,nowSeconds:s,selectedDeviceId:r,sessions:a,selfLabel:d,canMove:c,onSelect:m,onMove:l,onInvite:x,onRemove:v})=>{const[y,I]=f.useState("name"),N=f.useMemo(()=>e.networks.map(o=>({network:o,members:_s(e.devices.filter(i=>i.memberships.some(h=>h.networkId===o.id)),y)})),[e,y]);return t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pr-1",children:[t.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[t.jsx("legend",{className:"sr-only",children:"Sort devices by"}),t.jsx("div",{className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Es.map(o=>t.jsx("button",{type:"button","aria-pressed":y===o,onClick:()=>I(o),className:R("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===o&&"bg-surface text-ink"),children:As[o]},o))})]}),N.map(({network:o,members:i})=>t.jsxs("section",{"data-mesh-network-group":o.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:`epoch ${o.epoch}`,children:[o.label,t.jsxs("span",{className:"text-meta text-ink-dim",children:[o.trust," · ",o.memberCount," ",o.memberCount===1?"device":"devices",o.revokedCount>0?` · ${o.revokedCount} revoked`:""]})]}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:i.map(h=>{const g=h.memberships.find(S=>S.networkId===o.id),j=h.id===r,p=a.get(h.id),C=p?.rows??[],M=p?Be(p,h.sessionCount):h.sessionCount??0,P=oe(h);return t.jsxs("li",{"data-mesh-device-row":h.id,"data-mesh-state":h.state,"aria-current":j?"true":void 0,className:R("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",j&&"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":h.id,onClick:()=>m(h.id),className:R("min-w-0 flex-1 truncate text-left 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:h.label}),t.jsxs("span",{className:R("flex shrink-0 items-center gap-1 text-meta",We[P]),"data-mesh-reach":P,children:[h.suspect&&t.jsx(ye,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),h.suspect?de(P):ze(h,s),h.suspect&&t.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:He})]}),t.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[g?.role?`${g.role} · `:"",g&&!g.active?"revoked":"member"]})]}),C.length>0?t.jsxs(t.Fragment,{children:[t.jsx(ne,{className:"my-1"}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:C.slice(0,Te).map(S=>t.jsxs("li",{"data-mesh-row-session":S.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:S.name||S.id}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:Rs(S,d)}),t.jsx(Ge,{session:S,destinations:Ue(e,S,d),disabled:!c,onChoose:(D,B)=>l(S,D,B),trigger:t.jsx(Oe,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:`Move ${S.name||S.id}`})]},S.id))}),M>C.slice(0,Te).length&&t.jsx("button",{type:"button",onClick:()=>m(h.id),className:"w-fit text-meta text-ink-dim hover:text-ink",children:`show all ${M} in the panel`})]}):t.jsx("span",{className:"text-meta text-ink-dim",children:M===0?"no conversations":M===1?"1 conversation":`${M} conversations`}),(g?.active||h.state!=="self")&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(U,{size:"sm",variant:"ghost","data-mesh-invite":h.id,onClick:()=>x({deviceId:h.id,deviceLabel:h.label}),children:"Invite to a network…"}),g?.active&&t.jsxs(U,{size:"sm",variant:"ghost","data-mesh-remove-member":`${o.id}:${h.id}`,onClick:()=>v({networkId:o.id,networkLabel:o.label,deviceId:h.id,deviceLabel:h.label}),children:["Remove from ",o.label,"…"]})]})]},h.id)})})]},o.id)),e.unmatchedPeers.length>0&&t.jsxs("p",{className:"text-meta text-warning",children:[e.unmatchedPeers.length," ",e.unmatchedPeers.length===1?"device":"devices"," answered the peer read but is in no network this app can name."]})]})},Ls=["canvas","list"],Ps={canvas:"Canvas",list:"List"},Ts=({state:e,graph:s,nowSeconds:r,checking:a,staleError:d,onRetry:c,approvals:m,sessions:l,sessionError:x,selfLabel:v,movingSessionId:y,canMove:I,pendingMove:N,onAskMove:o,onDropRefused:i,onChooseMove:h,onCancelMove:g,moveBusy:j,moveReport:p,onDismissReport:C,onWaitForIdle:M,onUndoCopy:P,invite:S,onOpenInvite:D,onInvite:B,onCloseInvite:w,inviteBusy:W,inviteReceipt:ee,inviteRefusal:z,remove:L,onOpenRemove:te,onRemove:se,onCloseRemove:ie,removeBusy:re,removeRefusal:Z,removed:Y})=>{const[X,k]=f.useState("canvas"),[E,$]=f.useState(null),T=s?Rt(s):"",_="mesh-summary",F=$t(s),G=Lt(s,l,s?.selfDeviceId??null),ce=f.useMemo(()=>{const n=new Map;for(const u of s?.devices??[]){const b=G.byDevice.get(u.id);n.set(u.id,b?Be(b,u.sessionCount):u.sessionCount??0)}return n},[s,G]),J=f.useCallback(n=>{$(n)},[]),q=s?s.devices.find(n=>n.id===E)??null:null,ue=f.useCallback((n,u,b)=>{if(!s)return null;const A={selfDeviceId:s.selfDeviceId,devices:new Map(s.devices.map(K=>[K.id,K])),networks:new Map(s.networks.map(K=>[K.id,K]))},O=n.locality==="local"?s.selfDeviceId??"":n.owner_device,V=A.devices.get(O),H=pe({session:n,ownerDeviceId:O,ownerLabel:V?.label??n.owner_device_name},{kind:"device",deviceId:u.deviceId},A);if(H.kind==="refused")return i({code:H.code,sentence:H.sentence,remedy:H.remedy,plan:H.plan??null}),null;if(H.kind==="none")return null;const Ne=b?H.alternatives.find(K=>K.keep)??H.plan:H.plan,Ve=[H.plan,...H.alternatives].filter(K=>K.keep!==Ne.keep),Ke={plan:Ne,alternatives:Ve,risky:H.risky};o(Ke)},[s,o,i]);return t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[t.jsx(Qe,{title:"Mesh",icon:we,subtitle:"Devices this app is paired with, and the networks that hold them.",children:t.jsxs("div",{className:"flex items-center gap-4",children:[a&&t.jsx("output",{className:"text-meta text-ink-dim",children:"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:"Presentation"}),t.jsx("div",{className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Ls.map(n=>t.jsx("button",{type:"button","aria-pressed":X===n,disabled:e.kind!=="ready",onClick:()=>k(n),className:R("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",X===n&&"bg-surface text-ink"),children:Ps[n]},n))})]})]})}),t.jsx(ns,{rows:m.rows,error:m.error,pending:m.pending,refusal:m.decisionRefusal,onDecide:m.onDecide,onRetry:m.onRetry,nowSeconds:m.nowSeconds,networkNames:new Map((s?.networks??[]).map(n=>[n.id,n.label]))}),e.kind==="loading"&&t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[t.jsx(Me,{className:"h-4 w-64"}),t.jsx(Me,{className:"min-h-40 w-full flex-1"})]}),e.kind==="error"&&t.jsxs(he,{variant:"warning",className:"flex-col items-start gap-2",children:[t.jsx("p",{children:e.message}),t.jsx(U,{variant:"secondary",size:"sm",onClick:c,className:"w-fit",children:"Ask again"})]}),e.kind==="empty"&&t.jsx("div",{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:"No network on this device"}),t.jsx("p",{className:"max-w-140 text-body-sm text-ink-muted",children:"This device is not in any network, so there is no mesh to draw. Create one on this machine:"}),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:"A network appears here once this device has joined one."})]})}),e.kind==="ready"&&s&&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.jsx("p",{id:_,className:"text-meta text-ink-muted","data-mesh-summary":"",children:T}),d&&t.jsx(he,{variant:"warning",children:t.jsx("p",{children:d})}),x&&t.jsx(he,{variant:"warning",children:t.jsx("p",{children:x})}),p&&t.jsx(Pt,{receipt:p.kind==="moved"?{verb:p.verb,detail:p.detail,undo:p.undo}:null,refusal:p.kind==="refused"?p.refusal:null,canWait:p.kind==="refused"&&p.plan!==null,onWait:M,onRecheck:c,onUndo:P,onDismiss:C,pending:j}),X==="canvas"?t.jsx(Cs,{graph:s,slots:F,nowSeconds:r,selectedDeviceId:E,sessions:G.byDevice,sessionTotals:ce,movingSessionId:y,canMove:I,onOpenDevice:J,onAskMove:o,onDropRefused:i,onShowAllSessions:J,summaryId:_}):t.jsx($s,{graph:s,nowSeconds:r,selectedDeviceId:E,sessions:G.byDevice,selfLabel:v,canMove:I,onSelect:J,onMove:ue,onInvite:D,onRemove:te})]}),q&&t.jsx(Ds,{device:q,sessions:G.byDevice.get(q.id)??{rows:[],shown:[],hidden:0},sessionTotal:ce.get(q.id)??0,nowSeconds:r,canMove:I,canInvite:e.kind==="ready",movingSessionId:y,destinationsFor:n=>Ue(s,n,v),onClose:()=>$(null),onMove:ue,onInvite:n=>D({deviceId:n.id,deviceLabel:n.label}),onRemoveMember:(n,u)=>{const b=s.networks.find(A=>A.id===u);te({networkId:u,networkLabel:b?.label??u,deviceId:n.id,deviceLabel:n.label})},onShowInList:n=>{J(n),k("list")}})]})}),t.jsx(Tt,{open:N!==null,plan:N?.plan??Os,alternatives:N?.alternatives??[],risky:N?.risky??!1,busy:j,onCancel:g,onChoose:h}),S&&t.jsx(Ot,{open:S.open,options:S.options,deviceId:S.deviceId,deviceLabel:S.deviceLabel,onClose:w,onInvite:B,pending:W,receipt:ee,refusal:z}),L&&t.jsx(Wt,{open:L.open,networkLabel:L.networkLabel,deviceLabel:L.deviceLabel,onClose:ie,onConfirm:se,pending:re,refusal:Z,removed:Y})]})},Os={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},Vs=()=>{const e=qe(),s=xe(e.data,"peers")==="enabled",r=xe(e.data,"session_transfer")==="enabled",a=zt(s),d=Ht(s),c=Bt(s),m=f.useMemo(()=>({peers:a,networks:d}),[a,d]),l=Yt(m),x=Ft(m),v=Ut(),y=xe(e.data,"approvals")==="enabled",I=Gt(s&&y,{poll:!1}),N=Vt(),o=N.isError?{approvalId:N.variables?.approvalId??null,...Kt(N.error)}:null,i=f.useMemo(()=>Math.floor((I.dataUpdatedAt||Date.now())/1e3),[I.dataUpdatedAt]),h=Ze(k=>k.settlePlacement),g=Xt(),j=qt(),[p,C]=f.useState(null),[M,P]=f.useState(null),[S,D]=f.useState(null),[B,w]=f.useState(null),[W,ee]=f.useState(null),[z,L]=f.useState(null),[te,se]=f.useState(null),ie=f.useMemo(()=>{const k=Math.max(a.dataUpdatedAt,d.dataUpdatedAt);return Math.floor((k||Date.now())/1e3)},[a.dataUpdatedAt,d.dataUpdatedAt]),re=f.useCallback(()=>{a.refetch(),d.refetch(),c.refetch()},[a,d,c]),Z=f.useCallback((k,E)=>{C(null);const $={sessionId:k.sessionId,to:k.to,keep:k.keep,waitS:E??k.waitS};v.mutate($,{onSuccess:T=>{if(T.kind==="moved"){const{receipt:_}=T;h(k.sessionId,_);const F=_.locality==="local"?"this device":x?.devices.find(G=>G.id===_.owner_device)?.label??_.owner_device;P({kind:"moved",verb:_.mode==="keep"?"Copied":"Moved",detail:_.mode==="keep"?`${F} holds a copy as ${_.new_session_id.slice(-6)}; the original is still here.`:`${F} holds it now${_.source_retired?"; the copy here is gone":""}.`,undo:_.mode==="keep"?{sessionId:_.new_session_id,to:"local",keep:!1,verb:`Bring the copy back from ${F}`,waitS:0,lost:Zt(F,"this device")}:null});return}P({kind:"refused",refusal:T.refusal,plan:k})},onError:()=>{P({kind:"refused",refusal:{code:"move_failed",sentence:"The move could not be sent. Nothing here changed; the list has been read again.",status:null,unconfirmed:!1},plan:k})}})},[x,v,h]),Y=f.useMemo(()=>{if(!x)return[];const k=S?.deviceId,E=k?x.devices.find($=>$.id===k):void 0;return x.networks.filter($=>{if(!E)return!0;const T=E.memberships.find(_=>_.networkId===$.id);return!T||!T.active}).map($=>({id:$.id,label:$.label}))},[x,S]);if(!s)return t.jsx(Je,{to:"/chat",replace:!0});const X=l.kind==="ready"?a.error?le(a.error):d.error?le(d.error):null:null;return t.jsx(Ts,{state:l,graph:x,nowSeconds:ie,checking:a.isFetching||d.isFetching,staleError:X,onRetry:re,approvals:{rows:I.data??[],error:I.isError?Jt(I.error):null,pending:N.isPending?N.variables??null:null,decisionRefusal:o,onDecide:(k,E)=>N.mutate({approvalId:k,decision:E}),onRetry:()=>void I.refetch(),nowSeconds:i},sessions:c.data??[],movingSessionId:v.isPending?v.variables?.sessionId??null:null,sessionError:c.isError?le(c.error):null,selfLabel:x?.devices.find(k=>k.state==="self")?.label??"this device",canMove:r,pendingMove:p,onAskMove:C,onDropRefused:k=>P({kind:"refused",refusal:{code:k.code,sentence:k.sentence,status:null,unconfirmed:!1},plan:k.plan}),onChooseMove:k=>Z(k),onCancelMove:()=>C(null),moveBusy:v.isPending,moveReport:M,onDismissReport:()=>P(null),onWaitForIdle:()=>{M?.kind!=="refused"||!M.plan||Z(M.plan,Ws)},onUndoCopy:()=>{M?.kind!=="moved"||!M.undo||C({plan:M.undo,alternatives:[],risky:!1})},invite:S===null?null:{open:!0,deviceId:S.deviceId,deviceLabel:S.deviceLabel,options:Y},onOpenInvite:k=>{w(null),ee(null),D(k)},onInvite:k=>{g.mutate(k,{onSuccess:E=>w(E),onError:E=>ee({code:"invite_refused",sentence:le(E),status:null,unconfirmed:!1})})},onCloseInvite:()=>D(null),inviteBusy:g.isPending,inviteReceipt:B,inviteRefusal:W,remove:z===null?null:{open:!0,networkId:z.networkId,networkLabel:z.networkLabel,deviceId:z.deviceId,deviceLabel:z.deviceLabel},onOpenRemove:k=>{se(null),L(k)},onRemove:k=>{z&&j.mutate({networkId:z.networkId,deviceId:z.deviceId,confirm:k},{onSuccess:E=>se(E)})},onCloseRemove:()=>L(null),removeBusy:j.isPending,removeRefusal:j.isError?{code:"remove_refused",sentence:le(j.error),status:null,unconfirmed:!1}:null,removed:te})},Ws=300;export{Vs as MeshPage,Ts as MeshSurface,Vs as default};
|