local-operator-ui 0.54.4 → 0.54.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/out/renderer/assets/{_basePickBy-B3xt3Hm3.js → _basePickBy-DZaFrUMm.js} +1 -1
  2. package/out/renderer/assets/{_baseUniq-1pJjxjt2.js → _baseUniq-DqCgwxpO.js} +1 -1
  3. package/out/renderer/assets/{agent-details-page-BhFyhOGB.js → agent-details-page-t7-pZk2W.js} +1 -1
  4. package/out/renderer/assets/{agent-hub-page-BFvHoklr.js → agent-hub-page-DoFvojYM.js} +1 -1
  5. package/out/renderer/assets/{agents-page-B4zlrdr_.js → agents-page-DbU68lGa.js} +3 -3
  6. package/out/renderer/assets/{appearance-C0lPtfkY.js → appearance-CB5X23Pc.js} +35 -35
  7. package/out/renderer/assets/{arc-DsmiYIPI.js → arc-BMRMvVxq.js} +1 -1
  8. package/out/renderer/assets/{architectureDiagram-IEHRJDOE-l-eL9acY.js → architectureDiagram-IEHRJDOE-D-KJMV11.js} +1 -1
  9. package/out/renderer/assets/{avatar-cropper-pHmeKLyi.js → avatar-cropper-B0SvTl8W.js} +1 -1
  10. package/out/renderer/assets/{blockDiagram-JOT3LUYC-xQ3Xse8W.js → blockDiagram-JOT3LUYC-CMfOx4K5.js} +1 -1
  11. package/out/renderer/assets/{book-open-CurIwRfe.js → book-open-CjfQcb_6.js} +1 -1
  12. package/out/renderer/assets/browser-page-WgEm1Xnj.js +1 -0
  13. package/out/renderer/assets/{browser-webauthn-prompt-DSn7BuqK.js → browser-webauthn-prompt-DEq582Iy.js} +1 -1
  14. package/out/renderer/assets/{c4Diagram-VJAJSXHY-DK3mZwLN.js → c4Diagram-VJAJSXHY-DFZQpr6B.js} +1 -1
  15. package/out/renderer/assets/channel-biJ1kQzU.js +1 -0
  16. package/out/renderer/assets/{chunk-4BMEZGHF-BxS694e8.js → chunk-4BMEZGHF-BS36jJLt.js} +1 -1
  17. package/out/renderer/assets/{chunk-A2AXSNBT-DhazzPck.js → chunk-A2AXSNBT-hZaV-sxd.js} +1 -1
  18. package/out/renderer/assets/{chunk-AEK57VVT-DAzMOtBv.js → chunk-AEK57VVT-aTLD2maD.js} +1 -1
  19. package/out/renderer/assets/{chunk-D6G4REZN-DQ0Y9bJZ.js → chunk-D6G4REZN-BFayHuJJ.js} +1 -1
  20. package/out/renderer/assets/{chunk-RZ5BOZE2-ByJtdR6O.js → chunk-RZ5BOZE2-VgkA_iSV.js} +1 -1
  21. package/out/renderer/assets/{chunk-XZIHB7SX-DDCRuqfN.js → chunk-XZIHB7SX-Bvcutn92.js} +1 -1
  22. package/out/renderer/assets/classDiagram-GIVACNV2-ZQSWLdsu.js +1 -0
  23. package/out/renderer/assets/classDiagram-v2-COTLJTTW-ZQSWLdsu.js +1 -0
  24. package/out/renderer/assets/clone-DlCgJMd-.js +1 -0
  25. package/out/renderer/assets/{console-mirror-DNf7G2I0.js → console-mirror-XM_5bSKF.js} +1 -1
  26. package/out/renderer/assets/{consoleCapture-4P65rdq4.js → consoleCapture-Bn1Se_Qu.js} +1 -1
  27. package/out/renderer/assets/{conversation-input-sync-uyyuExNW.js → conversation-input-sync-Btmg29tU.js} +185 -185
  28. package/out/renderer/assets/{dagre-OKDRZEBW-DMkRFzm8.js → dagre-OKDRZEBW-D3hmNQbR.js} +1 -1
  29. package/out/renderer/assets/{diagram-SSKATNLV-4BGyMBO2.js → diagram-SSKATNLV-Bo5ny4Px.js} +1 -1
  30. package/out/renderer/assets/{diagram-VNBRO52H-DE1S-9qp.js → diagram-VNBRO52H-BsbyAzN9.js} +1 -1
  31. package/out/renderer/assets/{erDiagram-Q7BY3M3F-BOWvsXlh.js → erDiagram-Q7BY3M3F-BTP2_iSu.js} +1 -1
  32. package/out/renderer/assets/{error-boundary-VQD4FYpL.js → error-boundary-CHZZV6GH.js} +1 -1
  33. package/out/renderer/assets/{flowDiagram-4HSFHLVR-DvlZwtKD.js → flowDiagram-4HSFHLVR-Ud_0FNud.js} +1 -1
  34. package/out/renderer/assets/{ganttDiagram-APWFNJXF-Nq3e8H0P.js → ganttDiagram-APWFNJXF-BNqH0XOA.js} +1 -1
  35. package/out/renderer/assets/{gitGraphDiagram-7IBYFJ6S-Jy8L5k7r.js → gitGraphDiagram-7IBYFJ6S-D8aBZ0Km.js} +1 -1
  36. package/out/renderer/assets/{graph-DPEEIY8Z.js → graph-DPAIIwRY.js} +1 -1
  37. package/out/renderer/assets/{heart-oZzzojv0.js → heart-DULszDIp.js} +1 -1
  38. package/out/renderer/assets/index-4MqHfoFs.css +1 -0
  39. package/out/renderer/assets/{index-DKfxb0W8.js → index-8UdhbmJT.js} +1 -1
  40. package/out/renderer/assets/{index-DngV7CIb.js → index-DprObCAh.js} +1 -1
  41. package/out/renderer/assets/index-_Gw7RTII.js +812 -0
  42. package/out/renderer/assets/infoDiagram-PH2N3AL5-cBpoGRcb.js +2 -0
  43. package/out/renderer/assets/{inline-error-boundary-PRBq4Lqq.js → inline-error-boundary-PXvAlMsd.js} +1 -1
  44. package/out/renderer/assets/{installer-DS58Bksf.js → installer-Co-o1h4D.js} +1 -1
  45. package/out/renderer/assets/{journeyDiagram-U35MCT3I-DwaiHfaH.js → journeyDiagram-U35MCT3I-DTzB73Ea.js} +1 -1
  46. package/out/renderer/assets/{kanban-definition-NDS4AKOZ-htfXUeZE.js → kanban-definition-NDS4AKOZ-1Xh0pBhh.js} +1 -1
  47. package/out/renderer/assets/{layout-DvTgSYYH.js → layout-DK-wlGb7.js} +1 -1
  48. package/out/renderer/assets/{legacy-agents-page-r1Y-kucK.js → legacy-agents-page-DKqjGO62.js} +1 -1
  49. package/out/renderer/assets/{library-page-BDCo022s.js → library-page-Cw50EiPO.js} +3 -3
  50. package/out/renderer/assets/{log-in-D0YxNJPh.js → log-in-zdV-V-md.js} +1 -1
  51. package/out/renderer/assets/{mermaid.core-BlHNEBaL.js → mermaid.core-D0jgYait.js} +5 -5
  52. package/out/renderer/assets/{mesh-page-DB5MLSgb.js → mesh-page-DYLY4u02.js} +1 -1
  53. package/out/renderer/assets/{mindmap-definition-ALO5MXBD-BSjLrA1R.js → mindmap-definition-ALO5MXBD-BYoEyGWU.js} +1 -1
  54. package/out/renderer/assets/{mini-3O_1fVj2.js → mini-BU9tnv5T.js} +1 -1
  55. package/out/renderer/assets/{notebook-pen-DDEgcfZg.js → notebook-pen-8ebpH8lM.js} +1 -1
  56. package/out/renderer/assets/{notifications-page-RZypnGHj.js → notifications-page-LZJYoumt.js} +1 -1
  57. package/out/renderer/assets/{org-access-BMbZPErU.js → org-access-DxK2DWEw.js} +1 -1
  58. package/out/renderer/assets/{org-surface-gate-CoL4bFMI.js → org-surface-gate-BfmgsJlA.js} +1 -1
  59. package/out/renderer/assets/{page-header-B8wJOF6S.js → page-header-D6f_9LyG.js} +1 -1
  60. package/out/renderer/assets/{pieDiagram-IB7DONF6-ZPW8fXB0.js → pieDiagram-IB7DONF6-CDWzyqOF.js} +1 -1
  61. package/out/renderer/assets/{project-markdown-C7oljPaw.js → project-markdown-XWo6y3uc.js} +1 -1
  62. package/out/renderer/assets/{projects-page-CI9lrQGZ.js → projects-page-n8lpgytN.js} +1 -1
  63. package/out/renderer/assets/{publication-validation-CASp138d.js → publication-validation-DguACpdw.js} +1 -1
  64. package/out/renderer/assets/{quadrantDiagram-7GDLP6J5-CNkizv5T.js → quadrantDiagram-7GDLP6J5-CpgfH2XB.js} +1 -1
  65. package/out/renderer/assets/{radar-MK3ICKWK-BV48_bSd.js → radar-MK3ICKWK-AP9ZUX29.js} +1 -1
  66. package/out/renderer/assets/{radient-auth-buttons-Bj7oxOXt.js → radient-auth-buttons-BxfXvDEx.js} +1 -1
  67. package/out/renderer/assets/{requirementDiagram-KVF5MWMF-Dq3xa1rx.js → requirementDiagram-KVF5MWMF-BBtc7gSJ.js} +1 -1
  68. package/out/renderer/assets/{sankeyDiagram-QLVOVGJD-z5QAURtH.js → sankeyDiagram-QLVOVGJD-r7BhZc0f.js} +1 -1
  69. package/out/renderer/assets/{schedules-page-ZPRVVT5B.js → schedules-page-DGiVl8mF.js} +1 -1
  70. package/out/renderer/assets/{sequenceDiagram-X6HHIX6F-C6Y-stRE.js → sequenceDiagram-X6HHIX6F-CkNyv10e.js} +1 -1
  71. package/out/renderer/assets/{settings-page-1tmm-IEy.js → settings-page-xgfLf7N7.js} +1 -1
  72. package/out/renderer/assets/{smartart-C2NxGaUI.js → smartart-BmcJjsFr.js} +1 -1
  73. package/out/renderer/assets/{stateDiagram-DGXRK772-C3KntpLD.js → stateDiagram-DGXRK772-kRpoDgVb.js} +1 -1
  74. package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-BQDla68w.js +1 -0
  75. package/out/renderer/assets/{team-bridge-page-CkVWtil3.js → team-bridge-page-zJNV9h6-.js} +1 -1
  76. package/out/renderer/assets/{team-bridge-scope-preference-DXWQxPWW.js → team-bridge-scope-preference-B9T6Qfv4.js} +1 -1
  77. package/out/renderer/assets/{timeline-definition-BDJGKUSR-Dx9fTROE.js → timeline-definition-BDJGKUSR-Bjyd4RWc.js} +1 -1
  78. package/out/renderer/assets/{use-download-agent-mutation-CqJJZFQx.js → use-download-agent-mutation-C1BhoJl3.js} +1 -1
  79. package/out/renderer/assets/{use-session-snapshot-31ExJ3hP.js → use-session-snapshot-DutdCMMH.js} +1 -1
  80. package/out/renderer/assets/{xychartDiagram-VJFVF3MP-BczgRDpX.js → xychartDiagram-VJFVF3MP-1TFByBzX.js} +1 -1
  81. package/out/renderer/console-capture.html +5 -5
  82. package/out/renderer/index.html +7 -7
  83. package/out/renderer/installer.html +4 -4
  84. package/out/renderer/mini.html +7 -7
  85. package/package.json +1 -1
  86. package/out/renderer/assets/browser-page-DG87TZbD.js +0 -1
  87. package/out/renderer/assets/channel-CVH_R33H.js +0 -1
  88. package/out/renderer/assets/classDiagram-GIVACNV2-BmyF-xYp.js +0 -1
  89. package/out/renderer/assets/classDiagram-v2-COTLJTTW-BmyF-xYp.js +0 -1
  90. package/out/renderer/assets/clone-T1tJd2zj.js +0 -1
  91. package/out/renderer/assets/index-Gls4i-Rf.js +0 -812
  92. package/out/renderer/assets/index-WCL2AOPk.css +0 -1
  93. package/out/renderer/assets/infoDiagram-PH2N3AL5-CZznGhUy.js +0 -2
  94. package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-Bm1UW0iD.js +0 -1
  95. /package/out/renderer/assets/{index-nXNEayCN.js → index-kEyWW56d.js} +0 -0
@@ -1 +1 @@
1
- import{r as p,j as t,c as H}from"./index-nXNEayCN.js";import{Q as Xe,R as ht,T as pt,V as ce,W as xt,X as ft,Y as ge,Z as Ze,_ as le,$ as Je,a0 as Qe,a1 as et,a as gt,t as xe,x as je,a2 as vt}from"./appearance-C0lPtfkY.js";import{P as bt}from"./page-header-B8wJOF6S.js";import{u as G,B as se,x as _t,T as kt,t as pe,D as yt,b as jt,d as wt,H as Nt,I as Pe,e as $e,f as Le,A as we}from"./error-boundary-VQD4FYpL.js";import{t as a}from"./messages-CUhxkxii.js";import{U as de,V as me,W as Te,X as It,Y as tt,Z as Ct,_ as St,$ as Mt,a0 as At,a1 as Dt,a2 as Rt,a3 as Et,a4 as Pt,a5 as Oe,a6 as He,a7 as $t,a8 as Lt,a9 as Tt,aa as Ot,ab as Ht,ac as Wt,ad as Ft,ae as qt,af as zt,ag as Bt,ah as Se,ai as Yt,aj as Ut,ak as Me,al as st,am as at,an as Vt,ao as ve,ap as Ne,aq as Gt,ar as Kt,as as be,at as We,au as Xt,av as Zt,aw as Ie,ax as Jt,ay as nt,az as _e,aA as Qt,aB as it,aC as es,aD as ts,aE as ss,aF as as,aG as ns,aH as is,aI as rs,aJ as ls,aK as os,aL as ds,aM as cs,aN as ms,aO as us,aP as hs,aQ as ps,aR as xs,aS as fs,aT as gs,aU as vs,aV as fe,aW as bs,aX as _s}from"./index-Gls4i-Rf.js";import{bD as ke,bE as ks,bF as ys,bG as js,bH as Ae,bI as ws,a1 as rt}from"./conversation-input-sync-uyyuExNW.js";import"./roles-D1pcbxAx.js";import"./console-mirror-DNf7G2I0.js";function Ns(e){return e==="failed"?"text-danger":de(e)?"text-ink-muted":"text-ink-dim"}function Is(e){return e==="failed"?a("ui.mesh.mesh_approvals_tray.abandon"):a("ui.mesh.mesh_approvals_tray.stop")}function Cs(e){switch(e){case"requested":return[{term:a("ui.mesh.mesh_approvals_tray.signing"),text:a("ui.mesh.mesh_approvals_tray.approving_signs_with_this_machine_s_operator")}];case"approved":return[{term:a("ui.mesh.mesh_approvals_tray.next"),text:a("ui.mesh.mesh_approvals_tray.an_agent_runs_the_install_and_connect")},{term:a("ui.mesh.mesh_approvals_tray.stop"),text:a("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_nothing_has")}];case"connecting":return[{term:a("ui.mesh.mesh_approvals_tray.stop"),text:a("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_the_runner")}];case"failed":return[{term:a("ui.mesh.mesh_approvals_tray.after_a_stop"),text:a("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_abandoning")}];default:return[]}}const Ss=({rows:e,error:n,pending:s,refusal:i,onDecide:m,onRetry:c,nowSeconds:f,networkNames:o,credentialApprovals:_=!1,profileApprovals:k=!1})=>{G();const S=s!==null,[A,M]=p.useState(""),d=p.useRef(null),h=i?JSON.stringify([i.approvalId,i.code,i.sentence]):null,u=p.useMemo(()=>e.filter(x=>de(x.state)||me(x)),[e]),j=p.useMemo(()=>e.filter(x=>!de(x.state)&&!me(x)),[e]),[C,D]=p.useState(!1),N=p.useRef(null),b=p.useRef(null),R=p.useRef(null),P=(x,T)=>{u.some(Y=>Y.approvalId===x&&Y.kind==="credential")&&(R.current={id:x,origin:document.activeElement,rowAtStart:e.find(Y=>Y.approvalId===x),refusalSubmittedAtStart:i?.submittedAt??0}),m(x,T)};p.useLayoutEffect(()=>{const x=R.current;if(!x)return;const T=e.find(U=>U.approvalId===x.id);if(s)return;const Y=i?.approvalId===x.id&&(i.submittedAt??0)>x.refusalSubmittedAtStart;if(T===x.rowAtStart&&!Y)return;R.current=null;const Z=u.find(U=>U.approvalId!==x.id),K=Z?N.current?.querySelector(`[data-tour-tag="mesh-approvals-live"] [data-approval-id="${CSS.escape(Z.approvalId)}"] ${de(Z.state)?'[data-tour-tag="mesh-approval-summary"]':'[data-tour-tag="mesh-approval-controls"] button:not(:disabled)'}`):null,q=(u.some(U=>U.approvalId===x.id)?N.current?.querySelector(`[data-approval-id="${CSS.escape(x.id)}"] [data-tour-tag="mesh-approval-refusal"]`):null)??K??b.current?.querySelector("button"),ae=i?N.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(i.approvalId??"")}"]`)??null:null;Te({document,target:q??null,refusalTarget:ae,origin:x.origin,allowFocus:!0,sentence:i?.sentence??""}).focused&&(d.current=h)},[e,s,i,u,h]),p.useLayoutEffect(()=>{if(!i||s){d.current=null,M("");return}if(d.current===h){M("");return}const x=N.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(i.approvalId??"")}"]`)??null,T=Te({document,target:null,refusalTarget:x,origin:null,allowFocus:!1,sentence:i.sentence});T.focused&&(d.current=h),M(T.announcement)},[i,h,s,e]);const I=u.filter(x=>de(x.state)).length,w=u.filter(me).length,g=j.filter(x=>x.kind==="credential"&&x.state==="connected").length,$=j.some(x=>x.state==="failed"),Q=j.filter(x=>x.state==="failed").length,W=i!==null&&e.some(x=>x.approvalId===i.approvalId&&(de(x.state)||me(x)||C)),O=e.find(x=>x.approvalId===i?.approvalId);return u.length===0&&j.length===0&&!n&&!i?null:t.jsxs("section",{ref:N,"aria-label":a("ui.mesh.mesh_approvals_tray.approvals"),"data-tour-tag":"mesh-approvals-tray",className:"flex flex-col gap-3",children:[t.jsx("output",{"aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a("ui.mesh.approval.result_status",{shared:g,attention:w})}),t.jsx("output",{"aria-live":"polite","aria-atomic":"true",className:"sr-only","data-tour-tag":"mesh-approval-announcement",children:t.jsx("bdi",{dir:"auto",children:A})}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(It,{"aria-hidden":"true",className:"size-4 text-ink-muted"}),t.jsx("h2",{className:"text-body-sm text-ink",children:a("ui.mesh.mesh_approvals_tray.approvals")}),I>0&&t.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_approvals_tray.waiting_count",{count:I})}),w>0&&t.jsx("span",{className:"text-meta text-warning",children:a("ui.mesh.approval.needs_attention",{count:w})})]}),n&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("p",{className:"min-w-0 flex-1 text-meta text-ink-muted",children:n}),t.jsx(se,{variant:"secondary",size:"sm",onClick:c,children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),u.length>0&&t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-live",children:u.map(x=>t.jsx(Fe,{row:x,pending:s?.approvalId===x.approvalId?s:null,busy:S,refusal:i?.approvalId===x.approvalId?i:null,onDecide:P,nowSeconds:f,networkNames:o,credentialApprovals:_,profileApprovals:k},x.approvalId))}),i&&!W&&t.jsx(lt,{approvalId:i.approvalId??"",requestIsBackendSummary:O?Ct(O):!1,refusal:i,request:O?tt(O):a("ui.mesh.approval.credential_title")}),j.length>0&&t.jsx("div",{ref:b,"data-tour-tag":"mesh-approvals-settled",children:t.jsx(ke,{open:C,onOpenChange:D,chevronClassName:"text-ink-dim",className:H(u.length>0&&"border-hairline border-t pt-3"),summary:t.jsxs("span",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[a("ui.mesh.mesh_approvals_tray.settled_approvals"),t.jsxs("span",{className:"text-ink-dim",children:["(",j.length,")"]}),$&&t.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-danger"}),g>0&&t.jsx("span",{className:"text-ink-muted",children:a("ui.mesh.approval.shared_count",{count:g})}),Q>0&&t.jsx("span",{className:"text-danger",children:a("ui.mesh.mesh_approvals_tray.failed_count",{count:Q})})]}),children:t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-records",children:j.map(x=>t.jsx(Fe,{row:x,pending:s?.approvalId===x.approvalId?s:null,busy:S,refusal:i?.approvalId===x.approvalId?i:null,onDecide:P,nowSeconds:f,networkNames:o,credentialApprovals:_,profileApprovals:k},x.approvalId))})})})]})},Fe=({row:e,pending:n,busy:s,refusal:i,onDecide:m,nowSeconds:c,networkNames:f,credentialApprovals:o,profileApprovals:_})=>{G();const k=de(e.state),S=St(e,i?.retryable),A=p.useId(),M=p.useId(),d=tt(e),h=Mt(e,f),u=At(e,f),j=Dt(e),C=Rt(e),D=Et(e),N=Pt(e.expiresAt,c,me(e)),b=e.kind==="credential"||e.kind==="unknown"||e.kind==="profile",R=b||e.canApproveHere===!1,P=R?[]:Cs(e.state),I={credentialApprovals:o,profileApprovals:_},w=Oe(e,I),g=He(e.state),$=$t(e,I,i?.retryable),Q=e.kind==="profile"?ks(e,{profileApprovals:_,canApprove:Oe(e,I),canDeny:He(e.state),canRetryApply:Lt(e,I,i?.retryable)}):null,W=o?e.typed:void 0,O=W?Tt(e):[],x=W?.disclosure?Ot(e):null,T=e.typed?.unprovenHuman===!0,Y=e.kind==="credential"&&["approved","failed","connecting","connected"].includes(e.state),Z=i?.sentence||(W?.applyOutcome?[W.applyOutcome.reason,W.applyOutcome.remedy].filter(Boolean).join(" "):""),K=i?.code||W?.applyOutcome?.code||W?.refusal,q=Ht(e),ae=(e.typed?.refusalMessage??"")||(e.typed?a("ui.mesh.approval.typed_review_unavailable"):e.approveRemedy||a("ui.mesh.approval.cli_review"));return t.jsxs("li",{className:"flex flex-col gap-2 py-3 first:pt-0 last:pb-0","data-tour-tag":"mesh-approval-card","data-approval-id":e.approvalId,children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:H("text-meta",me(e)?"text-warning":Ns(e.state)),children:S?a("ui.mesh.approval.could_not_apply"):e.kind==="credential"&&e.state==="connected"?a("ui.mesh.approval.shared"):e.kind==="credential"&&(e.state==="approved"||e.state==="failed")?a("ui.mesh.approval.approved_not_applied"):Wt(e.state)}),t.jsx("div",{className:"grow"}),!S&&(k||me(e))&&N&&t.jsx("span",{className:"text-meta text-ink-dim",children:N})]}),Q?t.jsx(ys,{view:Q}):t.jsx("p",{className:"text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-summary",tabIndex:-1,id:A,children:k?h:d}),q&&t.jsx("p",{id:M,className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-critical-facts",children:q}),!R&&e.state==="failed"&&t.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-stopped-note",children:a("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_it")}),k&&R&&!w&&t.jsx("p",{className:"text-meta text-ink-muted whitespace-pre-wrap [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-cli-remedy",children:ae}),e.kind==="credential"&&!e.typed&&e.state==="approved"&&t.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-apply-hint",children:a(e.details?.length?"ui.mesh.approval.approved_apply_hint":"ui.mesh.approval.approved_details_missing")}),T&&t.jsx("p",{className:"text-meta text-ink-dim","data-tour-tag":"mesh-approval-file-key",children:a(Y?"ui.mesh.approval.file_key_recorded":"ui.mesh.approval.file_key_disclosure")}),Z&&t.jsx(lt,{approvalId:e.approvalId,refusal:{code:K??"",sentence:Z}}),$&&t.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.retry_hint")}),Y&&g&&t.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.cancel_hint")}),(w||g||$)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-tour-tag":"mesh-approval-controls",children:[$&&t.jsx(se,{variant:"primary",size:"sm",disabled:s,"aria-describedby":q?`${A} ${M}`:A,onClick:()=>m(e.approvalId,"apply"),"data-tour-tag":"mesh-approval-retry-apply",children:a("ui.mesh.approval.try_again")}),w&&t.jsx(se,{variant:"primary",size:"sm",disabled:s,"aria-describedby":q?`${A} ${M}`:A,onClick:()=>m(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:a("ui.mesh.mesh_approvals_tray.approve")}),g&&t.jsx(se,{variant:"ghost",size:"sm",disabled:s,"aria-describedby":q?`${A} ${M}`:A,onClick:()=>m(e.approvalId,"deny"),"data-tour-tag":k?"mesh-approval-deny":"mesh-approval-stop",children:k?a("ui.mesh.mesh_approvals_tray.deny"):e.kind==="credential"?a("ui.mesh.approval.cancel_sharing"):Is(e.state)}),n&&t.jsx("span",{className:"text-meta text-ink-dim",children:n.decision==="approve"?e.typed?.unprovenHuman?a("ui.mesh.approval.signing_applying"):a("ui.mesh.mesh_approvals_tray.waiting_for_the_signing_prompt"):n.decision==="apply"?a("ui.mesh.approval.applying"):a("ui.mesh.mesh_approvals_tray.writing_the_decision")})]}),t.jsxs(ke,{chevronClassName:"text-ink-dim",summary:t.jsx("span",{className:"text-meta",children:a("ui.mesh.mesh_approvals_tray.details")}),children:[O.length>0&&t.jsx("ul",{className:"flex flex-col gap-1.5 text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-credential-consequences",children:O.map(E=>t.jsx("li",{children:E},E))}),x&&W?.disclosure?.recipient.keyFingerprint&&t.jsxs("p",{className:"text-meta text-ink-dim [overflow-wrap:anywhere]",children:[a("ui.mesh.approval.recipient_key",{device:x})," ",t.jsx("span",{className:"font-mono",children:W.disclosure.recipient.keyFingerprint})]}),K&&t.jsx("p",{className:"text-meta text-ink-dim font-mono",children:K}),W?.disclosure&&t.jsx(ke,{summary:t.jsx("span",{className:"text-meta",children:a("ui.mesh.approval.technical_request")}),children:t.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap text-meta text-ink-dim [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-signed-evidence",children:W.disclosure.evidence})}),b&&O.length===0&&(e.details?.length?t.jsx("ul",{className:"flex flex-col gap-1.5 text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-server-details",children:e.details.map((E,U)=>t.jsx("li",{className:"whitespace-pre-wrap",children:E},`${U}:${E}`))}):t.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.details_unavailable")})),u.length>0&&t.jsx("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta text-ink-dim","data-tour-tag":"mesh-approval-consequences",children:u.map(E=>t.jsxs(p.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{children:E.consequence})]},E.term))}),(j||C)&&t.jsxs("p",{className:"text-meta text-ink-muted",children:[j&&t.jsx("span",{children:j}),j&&C&&t.jsx("span",{children:" · "}),C&&t.jsx("span",{className:"font-mono",children:C})]}),D&&t.jsx("p",{className:"text-meta text-ink-dim",children:D}),P.length>0&&t.jsx("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta","data-tour-tag":"mesh-approval-consequence",children:P.map(E=>t.jsxs(p.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{className:"text-ink-muted",children:E.text})]},E.term))})]})]})},lt=({refusal:e,request:n,approvalId:s,requestIsBackendSummary:i=!1})=>{G();const m=js();return t.jsx("p",{tabIndex:-1,className:"text-meta text-warning [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-refusal","data-approval-refusal-id":s,children:n?Ft(n,e.sentence).map((c,f)=>c.kind==="literal"?t.jsx(p.Fragment,{children:c.text},`literal:${f}`):t.jsx("bdi",{dir:qt(c.kind,m,i),children:c.text},c.kind)):t.jsx("bdi",{dir:"auto",children:e.sentence})})},Ms=4,ye={kind:"idle"};function As(e){switch(e.kind){case"dragging":case"settling":return e.payload.session.id;case"pressing":return null;default:return null}}function oe(e,n){switch(n.kind){case"press":return e.kind!=="idle"?e:{kind:"pressing",payload:n.payload,originX:n.x,originY:n.y,pointerId:n.pointerId};case"move":return e.kind==="pressing"?Math.max(Math.abs(n.x-e.originX),Math.abs(n.y-e.originY))<Ms?e:{kind:"dragging",payload:e.payload,x:n.x,y:n.y,target:n.target,pointerId:e.pointerId}:e.kind==="dragging"?{...e,x:n.x,y:n.y,target:n.target}:e;case"release":return e.kind==="dragging"?{kind:"settling",payload:e.payload,target:e.target}:e.kind==="pressing"?ye:e;case"cancel":case"settled":return ye;default:return e}}const Ds=({edges:e,geometry:n,selectedDeviceId:s})=>t.jsx("svg",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0 overflow-visible",width:n.bounds.width,height:n.bounds.height,children:e.map(i=>{const m=n.networks.get(i.networkId),c=n.devices.get(i.deviceId);if(!m||!c)return null;const f=s!==null&&i.deviceId===s;return t.jsx("path",{"data-mesh-edge":i.key,d:zt(m,c),fill:"none",strokeWidth:f?2:1.5,className:f?"stroke-ink":"stroke-ink-dim"},i.key)})}),De=({deviceId:e,name:n,compact:s=!1,deviceIds:i,className:m})=>{G();const c=Xe({name:n});return t.jsxs("span",{className:H("flex min-w-0 items-baseline gap-2",m),"data-mesh-device-identity":e,children:[t.jsx(_t,{content:n?.trim()?c:null,children:t.jsx("span",{className:"min-w-0 flex-1 truncate text-start","data-mesh-device-name":"",children:c})}),t.jsx("span",{className:"shrink-0 font-mono text-meta text-ink-muted","data-mesh-device-id":"",title:e,children:s?ht(e,i):e})]})},Rs={self:"border-l-hairline",reached:"border-l-hairline","relay-down":"border-l-warning","handshake-refused":"border-l-warning","address-unreachable":"border-l-warning","no-endpoint":"border-l-hairline","not-a-member":"border-l-hairline",unanswered:"border-l-warning","not-attempted":"border-l-hairline",unknown:"border-l-hairline"};function Es(e){return e.suspect?"border-l-danger":Rs[ce(e)]}const Ps={self:"ring-2 ring-accent",reachable:null,relay_down:null,handshake_refused:null,unreachable:null,suspect:null},$s={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function Ls(e,n,s){return[Xe(e),e.id,at(e,n),s].filter(Boolean).join(", ")}function ue(e){return e.name.trim()||e.id.slice(-6)}function ot(e,n,s){if(s!=="reached"&&s!=="self"){const i=ge(s);return e.unreachable_reason?`${i} (${e.unreachable_reason})`:i}return e.live_state.trim()?e.live_state.trim():e.locality==="local"?a("ui.mesh.mesh_drop.on_this_device"):a("ui.mesh.mesh_node.on_device",{device:n})}const Ts={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},Os=({network:e,x:n,y:s,refused:i})=>(G(),t.jsxs("li",{"data-mesh-network":e.id,"data-mesh-network-refused":i?"true":void 0,"data-glass-block":"",className:H("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",i?"border-warning":"border-hairline"),style:{left:n,top:s,width:Se,height:Bt},children:[t.jsx(Ae,{"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:a("ui.mesh.mesh_list.epoch",{epoch:e.epoch}),className:"block truncate text-meta text-ink-dim",children:[a("ui.mesh.mesh_graph.device_count",{count:e.memberCount}),e.revokedCount>0?t.jsxs(t.Fragment,{children:[" · ",a("ui.mesh.mesh_list.revoked_count",{count:e.revokedCount})]}):null]})]})]})),Hs=({device:e,deviceIds:n,x:s,y:i,nowSeconds:m,selected:c,sessions:f,sessionTotal:o,dropState:_,movingSessionId:k,draggedSessionId:S,onOpen:A,onChipPointerDown:M,onChipClick:d,onShowAllSessions:h})=>{G();const{activity:u}=pt(e,f.rows),j=u==="working",C=Ls(e,m,j?"working":null),D=ce(e);return t.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":_??void 0,"aria-current":c?"true":void 0,"data-glass-block":"",className:H("absolute flex flex-col rounded-md border border-l-4 border-control bg-elevated","hover:bg-row-hover",c&&"border-y-ink border-r-ink bg-row-selected",Es(e),Ps[e.state],_&&$s[_]),style:{left:s,top:i,width:Se,height:Yt},children:[t.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":D,"aria-label":C,title:xt(e),onClick:()=>A(e.id),className:H("flex w-full flex-col justify-between rounded-t-[5px] px-3 pt-2 pb-2 text-start","cursor-pointer","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),style:{height:Ut},children:[t.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2",children:[t.jsx(ws,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),t.jsx(De,{className:"min-w-0 flex-1 text-body-sm text-ink",deviceId:e.id,deviceIds:n,name:e.name,compact:!0}),e.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"})]}),t.jsxs("span",{className:"flex w-full min-w-0 items-baseline gap-1",children:[t.jsx("span",{className:"w-3 shrink-0 font-mono text-body-sm text-ink tabular-nums",children:e.sessionCount??"–"}),t.jsx("span",{className:H("min-w-0 truncate text-meta",e.sessionCount===null?"text-ink-dim":"text-ink-muted"),children:st(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:ft[D]}),t.jsx("span",{className:H("shrink-0",Ze[D]),children:ge(D)}),j&&t.jsx("span",{"data-mesh-working":"",className:"shrink-0 text-info",children:a("ui.mesh.mesh_node.working")}),e.memberships.length>1&&t.jsx("span",{className:"min-w-0 truncate text-ink-dim",children:a("ui.mesh.mesh_node.memberships",{count:e.memberships.length})})]})]}),t.jsxs("ul",{"aria-label":a("ui.mesh.mesh_node.conversations_on",{device:le(e,n,!0)}),className:H("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",_==="accept"&&"opacity-40"),children:[f.shown.map(N=>t.jsx(Ws,{session:N,ownerLabel:le(e,n,!0),ownerReach:D,ownerReachable:e.reachable,moving:k===N.id,dragging:S===N.id,onPointerDown:M,onClick:()=>d(N)},N.id)),f.hidden>0&&t.jsx("li",{className:"shrink-0",children:t.jsxs("button",{type:"button","data-mesh-more":e.id,onClick:()=>h(e.id),className:H("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:a("ui.mesh.mesh_node.shown_conversations",{shown:f.shown.length,total:o}),"aria-label":a("ui.mesh.mesh_node.show_all_conversations",{count:o}),children:["+",f.hidden]})})]})]})},Ws=({session:e,ownerLabel:n,ownerReach:s,ownerReachable:i,moving:m,dragging:c,onPointerDown:f,onClick:o})=>{G();const _=ot(e,n,s);return m?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:a("ui.mesh.mesh_card.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:`${ue(e)} · ${_}`,"aria-label":a("ui.mesh.mesh_node.open_conversation",{conversation:ue(e),fact:_,owner:n}),onPointerDown:k=>f(k,e),onClick:()=>o(e),className:H("flex min-h-6 w-full max-w-32 items-center rounded-sm border border-hairline bg-surface px-1.5 text-start text-meta text-ink-muted","cursor-grab active:cursor-grabbing","hover:text-ink",Ts[Vt(e,i)],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",children:ue(e)})})})};function qe(e){const n=e.trim();if(!n)return null;if(n.startsWith("[")){const i=n.indexOf("]");if(i<=1)return null;const m=n.slice(1,i),c=n.slice(i+1);if(!c)return{host:m,port:null};if(!c.startsWith(":"))return null;const f=Number(c.slice(1));return{host:m,port:Number.isInteger(f)?f:null}}const s=n.lastIndexOf(":");if(s>0){const i=n.slice(s+1);if(/^\d+$/.test(i))return{host:n.slice(0,s),port:Number(i)}}return{host:n,port:null}}function ze(e){const n=e.trim().split(".");if(n.length!==4)return null;for(const s of n)if(!/^\d{1,3}$/.test(s)||Number(s)>255)return null;return`${n[0]}.${n[1]}.${n[2]}`}function Fs(e){return`${e}.x`}function qs(e){const n=new Map;for(const i of e.values())for(const m of i)n.set(m,(n.get(m)??0)+1);const s=new Set;for(const[i,m]of n)m>1&&s.add(i);return s}function Ce(e){return new Set(e.endpoints.map(n=>n.trim()).filter(Boolean))}function zs(e,n){const s=e.filter(d=>d.id!==n),i=e.find(d=>d.id===n)??null,m=new Map;for(const d of e)m.set(d.id,Ce(d));const c=qs(m),f=new Set;for(const d of i?Ce(i):[]){if(c.has(d))continue;const h=qe(d),u=h?ze(h.host):null;u&&f.add(u)}const o=d=>{const h=new Set;for(const u of Ce(d)){if(c.has(u))continue;const j=qe(u),C=j?ze(j.host):null;C&&h.add(C)}return h},_=new Map,k=new Map;for(const d of s){const h=Bs(d);if(h){_.set(h,[..._.get(h)??[],d.id]);continue}for(const u of o(d))k.set(u,[...k.get(u)??[],d.id])}const S=new Map(e.map((d,h)=>[d.id,h])),A=d=>[...d].sort((h,u)=>(S.get(h)??0)-(S.get(u)??0)),M=[];for(const[d,h]of _)M.push({prefix:d,tier:"declared",deviceIds:A(h),get words(){return a("ui.mesh.mesh_scope.declared")}});for(const[d,h]of k)f.has(d)?M.push({prefix:d,tier:"shared",deviceIds:A(h),get words(){return a("ui.mesh.mesh_scope.shared_with_this_device")}}):h.length>1&&M.push({prefix:d,tier:"probable",deviceIds:A(h),get words(){return a("ui.mesh.mesh_scope.same_prefix")}});return M.sort((d,h)=>d.tier.localeCompare(h.tier)||d.prefix.localeCompare(h.prefix))}function Bs(e){for(const n of e.memberships){const s=n.scope.trim();if(s)return s}return""}const Be={declared:0,shared:1,probable:2};function Ys(e,n){const s=new Map;for(const m of e){let c=null;for(const o of m.deviceIds){const _=n.get(o);_!==void 0&&(c===null||_<c.slot)&&(c={id:o,slot:_})}if(c===null)continue;const f=s.get(c.id);f===void 0?s.set(c.id,{slot:c.slot,groups:[m]}):f.groups.push(m)}const i=m=>{let c=-1;for(const f of m.deviceIds){const o=n.get(f);o!==void 0&&o>c&&(c=o)}return c};return[...s.entries()].sort((m,c)=>m[1].slot-c[1].slot).map(([m,c])=>({deviceId:m,groups:c.groups.sort((f,o)=>i(o)-i(f)||Be[f.tier]-Be[o.tier]||f.prefix.localeCompare(o.prefix))}))}function Us(e){return new Map(e.map(n=>[n.deviceId,n.groups.length]))}function Vs(e){return`${e.tier==="declared"?e.prefix:Fs(e.prefix)} · ${e.words}`}const Ye=(e,n)=>e.deviceIds.map(s=>n.devices.get(s)).filter(s=>s!==void 0),Gs=({stacks:e,geometry:n})=>(G(),t.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(s=>{const i=s.groups.length,m=new Array(i).fill(0);let c=null;for(let o=i-1;o>=0;o-=1){const _=Ye(s.groups[o],n),k=(_.length===0?0:Math.max(..._.map(S=>S.y+S.height)))+ve;c=c===null?k:Math.max(k,c+Ne),m[o]=c}const f=n.devices.get(s.deviceId);return s.groups.map((o,_)=>{const k=Ye(o,n);if(k.length===0)return null;const S=i-1-_,A=Math.min(...k.map(C=>C.x)),M=Math.max(...k.map(C=>C.x)),h=(f?.y??Math.min(...k.map(C=>C.y)))-ve-Gt*S,u=o.tier==="declared",j=Vs(o);return t.jsx("div",{"data-mesh-scope":`${o.tier}:${o.prefix}`,"data-mesh-scope-level":_,className:H("absolute rounded-lg",o.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:A-ve-Ne*S,top:h,width:M+Se-A+(ve+Ne*S)*2,height:m[_]-h},children:t.jsx("span",{"data-mesh-scope-label":"",className:H("absolute bottom-full left-1 mb-0.5 whitespace-nowrap text-meta",o.tier==="probable"?"text-ink-dim":"text-ink-muted",u&&"font-medium"),children:j})},`${o.tier}:${o.prefix}`)})})})),Ue=48,Ve=1.25,Ks=.0015,Xs=({graph:e,slots:n,nowSeconds:s,selectedDeviceId:i,sessions:m,sessionTotals:c,movingSessionId:f,canMove:o,onOpenDevice:_,onAskMove:k,onDropRefused:S,onShowAllSessions:A,summaryId:M})=>{G();const d=p.useRef(null),[h,u]=p.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[j,C]=p.useState({k:1,tx:0,ty:0}),D=p.useRef(!1),N=p.useRef(!1),b=p.useRef(null),R=p.useMemo(()=>zs(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),P=p.useMemo(()=>Ys(R,n.devices),[R,n]),I=p.useMemo(()=>Kt(n,Us(P)),[n,P]),w=p.useMemo(()=>({selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(r=>[r.id,r])),networks:new Map(e.networks.map(r=>[r.id,r]))}),[e]),[g,$]=p.useState(ye),Q=p.useRef({kind:"ground"}),W=p.useCallback((r,l)=>{const v=document.elementFromPoint(r,l),L=v?.closest("[data-mesh-device]");if(L){const re=L.getAttribute("data-mesh-device");if(re)return{kind:"device",deviceId:re}}const V=v?.closest("[data-mesh-network]");if(V){const re=V.getAttribute("data-mesh-network");if(re)return{kind:"network",networkId:re}}return{kind:"ground"}},[]),O=p.useMemo(()=>g.kind!=="dragging"&&g.kind!=="settling"?null:be(g.payload,g.target,w),[g,w]),x=p.useCallback(r=>{if(!O)return null;if(O.kind==="plan"){const l=g.kind==="dragging"||g.kind==="settling"?g.target:null;return l&&l.kind==="device"&&l.deviceId===r?"accept":null}if(O.kind==="refused"){const l=g.kind==="dragging"||g.kind==="settling"?g.target:null;return l&&l.kind==="device"&&l.deviceId===r?"refuse":null}return null},[O,g]),T=p.useCallback((r,l)=>{if(!o||r.button!==0)return;N.current=!1;const v=l.locality==="local"?e.selfDeviceId??"":l.owner_device,L=w.devices.get(v),V={session:l,ownerDeviceId:v,ownerLabel:L?le(L,[...w.devices.keys()],!0):l.owner_device_name};try{r.currentTarget.setPointerCapture(r.pointerId)}catch{}$(re=>oe(re,{kind:"press",payload:V,x:r.clientX,y:r.clientY,pointerId:r.pointerId}))},[o,w,e.selfDeviceId]),Y=r=>{if(g.kind==="pressing"||g.kind==="dragging"){const l=W(r.clientX,r.clientY);Q.current=l,$(v=>oe(v,{kind:"move",x:r.clientX,y:r.clientY,target:l}));return}F(r)},Z=r=>{if(ne(r),g.kind!=="pressing"&&g.kind!=="dragging")return;if(g.kind==="pressing"){$(v=>oe(v,{kind:"cancel"}));return}const l=be(g.payload,g.target,w);N.current=!0,$(v=>oe(v,{kind:"release"})),l.kind==="plan"?k({plan:l.plan,alternatives:l.alternatives,risky:l.risky}):l.kind==="refused"&&S({code:l.code,sentence:l.sentence,reach:l.reach,remedy:l.remedy,plan:l.plan??null}),$(v=>oe(v,{kind:"settled"}))};p.useEffect(()=>()=>$(ye),[]);const K=p.useCallback(()=>{C(We(I.bounds,h))},[I.bounds,h]);p.useEffect(()=>{const r=d.current;if(!r)return;const l=()=>{const L=r.getBoundingClientRect();u({width:L.width,height:L.height,clipWidth:r.clientWidth,clipHeight:r.clientHeight,left:L.left,top:L.top})};l();const v=new ResizeObserver(l);return v.observe(r),()=>v.disconnect()},[]),p.useEffect(()=>{D.current||h.width<=0||h.height<=0||(D.current=!0,C(We(I.bounds,h)))},[h,I.bounds]),p.useEffect(()=>{const r=b.current;if(b.current={width:h.width,height:h.height},!r||!D.current||h.width<=0||h.height<=0||h.width>=r.width&&h.height>=r.height||!i)return;const l=I.devices.get(i);l&&C(v=>{const L={width:h.clipWidth,height:h.clipHeight},V=Math.max(0,Math.min(L.width-I.bounds.width*v.k,L.height-I.bounds.height*v.k));return Xt(v,l,L,Math.min(Jt,V))})},[h,i,I]);const q=g.kind==="dragging"?{x:g.x-h.left+12,y:g.y-h.top+12}:{x:0,y:0},ae=O?Zt(O):null,E=p.useRef(null),U=p.useRef(null),ee=p.useRef(null),y=p.useRef(null),z=p.useCallback(()=>{ee.current=null;const r=E.current,l=U.current;if(E.current=null,U.current=null,r){const v=y.current;if(!v)return;C({k:v.transform.k,tx:v.transform.tx+(r.x-v.x),ty:v.transform.ty+(r.y-v.y)});return}l&&C(v=>Ie(v,{x:l.x,y:l.y},v.k*Math.exp(-l.deltaY*Ks)))},[]),B=p.useCallback(()=>{ee.current===null&&(ee.current=requestAnimationFrame(z))},[z]);p.useEffect(()=>()=>{ee.current!==null&&cancelAnimationFrame(ee.current)},[]);const J=r=>{!(r.target===r.currentTarget)&&r.button!==1||r.button!==0&&r.button!==1||(y.current={x:r.clientX,y:r.clientY,transform:j},r.currentTarget.setPointerCapture(r.pointerId),r.preventDefault())},F=r=>{y.current&&(E.current={x:r.clientX,y:r.clientY},B())},ne=r=>{y.current&&(y.current=null,E.current=null,r.currentTarget.hasPointerCapture(r.pointerId)&&r.currentTarget.releasePointerCapture(r.pointerId))},ie=p.useCallback(r=>{if(r.deltaY===0)return;r.preventDefault();const l=r.currentTarget.getBoundingClientRect();U.current={x:r.clientX-l.left,y:r.clientY-l.top,deltaY:r.deltaY},B()},[B]);p.useEffect(()=>{const r=d.current;if(r)return r.addEventListener("wheel",ie,{passive:!1}),()=>r.removeEventListener("wheel",ie)},[ie]);const he=r=>{const l=r.shiftKey?Ue*4:Ue;switch(r.key){case"Escape":if(g.kind!=="pressing"&&g.kind!=="dragging")return;r.preventDefault(),g.kind==="dragging"&&(N.current=!0),$(v=>oe(v,{kind:"cancel"}));return;case"0":r.preventDefault(),K();return;case"+":case"=":r.preventDefault(),C(v=>Ie(v,{x:h.width/2,y:h.height/2},v.k*Ve));return;case"-":case"_":r.preventDefault(),C(v=>Ie(v,{x:h.width/2,y:h.height/2},v.k/Ve));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{r.preventDefault();const v=r.key==="ArrowLeft"?l:r.key==="ArrowRight"?-l:0,L=r.key==="ArrowUp"?l:r.key==="ArrowDown"?-l:0;C(V=>({...V,tx:V.tx+v,ty:V.ty+L}));return}}};return t.jsxs("div",{ref:d,"data-mesh-canvas":"",role:"group","aria-labelledby":M,tabIndex:0,onPointerDown:J,onPointerMove:Y,onPointerUp:Z,onPointerCancel:r=>{g.kind==="dragging"&&(N.current=!0),$(l=>oe(l,{kind:"cancel"})),ne(r)},"data-mesh-gesture":g.kind,"data-glass-well":"clear",onKeyDown:he,onDoubleClick:r=>{r.target===r.currentTarget&&K()},className:H("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:`${j.tx}px ${j.ty}px`}}),t.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${j.tx}px, ${j.ty}px, 0) scale(${j.k})`,transformOrigin:"0 0",width:I.bounds.width,height:I.bounds.height},children:[t.jsx(Gs,{stacks:P,geometry:I}),t.jsx(Ds,{edges:e.edges,geometry:I,selectedDeviceId:i}),t.jsx("ul",{"aria-label":a("ui.mesh.mesh_canvas.networks"),className:"m-0 list-none p-0",children:e.networks.map(r=>{const l=I.networks.get(r.id);return l?t.jsx(Os,{network:r,x:l.x,y:l.y,refused:O?.kind==="refused"&&g.kind==="dragging"&&g.target.kind==="network"&&g.target.networkId===r.id},r.id):null})}),t.jsx("ul",{"aria-label":a("ui.mesh.mesh_canvas.devices"),className:"m-0 list-none p-0",children:e.devices.map(r=>{const l=I.devices.get(r.id);return l?t.jsx(Hs,{device:r,deviceIds:e.devices.map(v=>v.id),x:l.x,y:l.y,nowSeconds:s,selected:r.id===i,sessions:m.get(r.id)??{rows:[],shown:[],hidden:0},sessionTotal:c.get(r.id)??r.sessionCount??0,dropState:x(r.id),movingSessionId:f,draggedSessionId:As(g),onOpen:_,onChipPointerDown:T,onChipClick:()=>{if(N.current){N.current=!1;return}_(r.id)},onShowAllSessions:A},r.id):null})})]}),g.kind==="dragging"&&t.jsx("div",{"data-mesh-ghost":"","aria-hidden":"true",className:"pointer-events-none absolute z-10 max-w-40 truncate rounded-sm border border-ink-dim bg-surface px-1.5 py-0.5 text-meta text-ink",style:{left:q.x,top:q.y},children:g.payload.session.name||"untitled"}),g.kind==="dragging"&&ae&&t.jsx("div",{"data-mesh-indicator":"",className:H("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",O?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:q.x,maxWidth:Math.max(160,h.width-q.x-12),...q.y>h.height*.6?{bottom:Math.max(12,h.height-q.y+8)}:{top:q.y+24}},children:ae})]})};function Zs(e,n,s,i){const m=s.locality==="local"?n:s.owner_device,c=[],f=e.map(o=>o.id);for(const o of e){if(o.id===m)continue;if(o.id===n){c.push({deviceId:o.id,label:i,verb:a("ui.mesh.mesh_card.recall_to_this_device"),keepVerb:a("ui.mesh.mesh_card.copy_here_leave_it_there")});continue}const _=le(o,f,!0);c.push({deviceId:o.id,label:_,verb:a("ui.mesh.mesh_card.move_to",{device:_}),keepVerb:a("ui.mesh.mesh_card.copy_to",{device:_})})}return c}function Js(e,n,s){return Zs(e.devices,e.selfDeviceId,n,s)}function dt(e,n,s){const i=Js(e,n,s),m={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(o=>[o.id,o])),networks:new Map(e.networks.map(o=>[o.id,o]))},c=n.locality==="local"?e.selfDeviceId??"":n.owner_device,f=m.devices.get(c);return i.map(o=>{const _=be({session:n,ownerDeviceId:c,ownerLabel:f?le(f,e.devices.map(k=>k.id),!0):n.owner_device_name},{kind:"device",deviceId:o.deviceId},m);return{...o,refused:_.kind==="refused"&&_.code!=="busy"?_.sentence:null}})}const ct=({session:e,destinations:n,disabled:s,onChoose:i,onOpenChange:m,trigger:c,triggerLabel:f})=>(G(),t.jsxs(yt,{onOpenChange:m,children:[t.jsx(jt,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":f,"data-mesh-session-menu":e.id,disabled:s||n.length===0,className:"rounded-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2 disabled:text-ink-disabled",children:c})}),t.jsxs(wt,{align:"start",className:"min-w-56",children:[t.jsx(Nt,{children:ue(e)}),t.jsx(Pe,{}),n.map(o=>t.jsx($e,{"data-mesh-move-to":o.deviceId,disabled:!!o.refused,title:o.refused??void 0,onSelect:()=>i(o,!1),children:o.verb},o.deviceId)),t.jsx(Pe,{}),n.map(o=>t.jsx($e,{"data-mesh-copy-to":o.deviceId,disabled:!!o.refused,title:o.refused??void 0,onSelect:()=>i(o,!0),children:o.keepVerb},`keep-${o.deviceId}`))]})]})),Qs=({device:e,deviceIds:n,sessions:s,sessionTotal:i,nowSeconds:m,destinationsFor:c,movingSessionId:f,canMove:o,canInvite:_,onClose:k,onMove:S,onShowInList:A,onInvite:M,onRemoveMember:d})=>{G();const h=ce(e),u=Je(e),j=e.reachable?[]:e.attempts??[];p.useEffect(()=>{const b=R=>{R.key!=="Escape"||R.defaultPrevented||R.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),k())};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[e.id,k]);const C=e.sessionCount===null?st(null):a("ui.mesh.mesh_card.conversation_count",{count:e.sessionCount}),D=e.suspect?Qe():[C,ge(h)].filter(Boolean).join(" · "),N=i>s.rows.length?a("ui.mesh.mesh_card.shown_of",{shown:s.rows.length,total:i}):`${s.rows.length}`;return t.jsxs("aside",{"aria-label":a("ui.mesh.mesh_card.device_details",{device:le(e)}),"data-mesh-panel":e.id,"data-glass-block":"",className:"flex w-80 shrink-0 flex-col gap-3 overflow-y-auto rounded-md border border-hairline bg-surface p-4",children:[t.jsxs("header",{className:"flex flex-col gap-1",children:[t.jsx(se,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:k,children:a("ui.mesh.mesh_actions.close")}),t.jsx("h2",{className:"text-body-sm text-ink",children:t.jsx(De,{deviceId:e.id,deviceIds:n,name:e.name,compact:!0})}),t.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[e.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 text-danger"}),!e.suspect&&h==="unanswered"&&t.jsx(kt,{"aria-hidden":"true",className:"size-3.5 text-warning"}),D]})]}),t.jsx(pe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.memberships")}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:e.memberships.map(b=>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(Ae,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),b.networkName]}),t.jsxs("span",{className:"text-meta text-ink-dim",children:[b.role||"member",b.capabilities.length>0?` · ${b.capabilities.join(", ")}`:""]}),_&&t.jsxs(se,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${b.networkId}:${e.id}`,onClick:()=>d(e,b.networkId),children:[a("ui.mesh.mesh_card.remove_from"),b.networkName,"…"]})]},b.networkId))}),_&&t.jsx(se,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":e.id,onClick:()=>M(e),children:a("ui.mesh.mesh_actions.invite_to_a_network")})]}),t.jsx(pe,{}),t.jsxs("section",{className:"flex shrink-0 flex-col gap-2",children:[t.jsxs("h3",{className:"text-meta text-ink-dim",children:[a("ui.mesh.mesh_card.conversations"),t.jsxs("span",{className:"text-ink-disabled",children:["(",ce(e)!=="self"&&ce(e)!=="reached"?nt(null):N,")"]})]}),_e(e,m)?t.jsx("p",{className:"text-meta text-warning",children:_e(e,m)}):s.rows.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:e.sessionCount===null?a("ui.mesh.mesh_card.this_device_did_not_report_its_conversations"):a("ui.mesh.mesh_card.no_conversations_here")}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:s.rows.map(b=>t.jsxs("li",{"data-mesh-panel-session":b.id,className:H("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",f===b.id&&"border-control"),children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",title:ue(b),children:ue(b)}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:ot(b,le(e,n,!0),ce(e))}),f===b.id?t.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:a("ui.mesh.mesh_card.moving")}):t.jsx(ct,{session:b,destinations:c(b),disabled:!o,onChoose:(R,P)=>S(b,R,P),trigger:t.jsx(rt,{"aria-hidden":"true",className:"size-4"}),triggerLabel:a("ui.mesh.mesh_card.move_conversation",{conversation:ue(b)})})]},b.id))})]}),t.jsx(pe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.network_addresses")}),e.endpoints.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.no_address_published")}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:e.endpoints.map(b=>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:b}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_card.advertised")})]},b))})]}),t.jsx(pe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.status")}),t.jsxs("dl",{className:"m-0 flex flex-col gap-1",children:[t.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("dt",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.reach")}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:ge(h)})]}),t.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("dt",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.last_status_frame")}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:e.lastSeenAt===null?a("ui.mesh.mesh_card.never"):Qt(m-e.lastSeenAt)})]})]}),!e.reachable&&(u!==""||j.length>0)&&t.jsxs("div",{className:"flex flex-col gap-1",children:[u&&t.jsx("p",{className:"m-0 text-meta text-warning",children:u}),e.linkState==="handshake_refused"&&t.jsx("p",{className:"m-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.handshake_refused_hint")}),j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{id:`mesh-attempts-label-${e.id}`,className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.addresses_tried")}),t.jsx("ul",{role:"list","aria-labelledby":`mesh-attempts-label-${e.id}`,className:"m-0 flex list-none flex-col gap-0.5 p-0",children:j.map((b,R)=>{const P=et(b.detail);return t.jsxs("li",{"data-mesh-attempt":b.endpoint,className:"flex items-baseline justify-between gap-2",children:[t.jsx("span",{className:"min-w-0 truncate font-mono text-meta text-ink",children:b.endpoint}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:P})]},`${b.endpoint}:${R}`)})})]})]}),!u&&j.length===0&&e.reason&&t.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),t.jsx(pe,{}),t.jsx(se,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>A(e.id),children:a("ui.mesh.mesh_card.show_in_list")})]})},ea=["name","chats","state"],ta={get name(){return a("ui.mesh.mesh_list.name")},get chats(){return a("ui.mesh.mesh_list.sort_conversations")},get state(){return a("ui.mesh.mesh_list.state")}},Ge={suspect:0,relay_down:1,handshake_refused:2,unreachable:3,self:4,reachable:5};function sa(e,n){const s=[...e];switch(n){case"chats":return s.sort((i,m)=>(m.sessionCount??-1)-(i.sessionCount??-1)||i.label.localeCompare(m.label)),s;case"state":return s.sort((i,m)=>Ge[i.state]-Ge[m.state]||i.label.localeCompare(m.label)),s;default:return s.sort((i,m)=>i.label.localeCompare(m.label))}}const Ke=8;function aa(e,n){if(e.locality==="local")return e.live_state||"here";const s=e.owner_device_name||n,i=e.live_state?` · ${e.live_state}`:"";return e.reachable?a("ui.mesh.mesh_list.on_device_state",{device:s,state:i}):a("ui.mesh.mesh_list.on_device_no_answer",{device:s})}const na=({graph:e,nowSeconds:n,selectedDeviceId:s,sessions:i,selfLabel:m,canMove:c,onSelect:f,onMove:o,onInvite:_,onRemove:k})=>{G();const[S,A]=p.useState("name"),M=p.useMemo(()=>e.networks.map(d=>({network:d,members:sa(e.devices.filter(h=>h.memberships.some(u=>u.networkId===d.id)),S)})),[e,S]);return t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pe-1",children:[t.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[t.jsx("legend",{className:"sr-only",children:a("ui.mesh.mesh_list.sort_devices_by")}),t.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:ea.map(d=>t.jsx("button",{type:"button","aria-pressed":S===d,onClick:()=>A(d),className:H("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",S===d&&"bg-surface text-ink"),children:ta[d]},d))})]}),M.map(({network:d,members:h})=>t.jsxs("section",{"data-mesh-network-group":d.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:a("ui.mesh.mesh_list.epoch",{epoch:d.epoch}),children:[d.label,t.jsxs("span",{className:"text-meta text-ink-dim",children:[d.trust," ·"," ",a("ui.mesh.mesh_graph.device_count",{count:d.memberCount}),d.revokedCount>0?t.jsxs(t.Fragment,{children:[" · ",a("ui.mesh.mesh_list.revoked_count",{count:d.revokedCount})]}):null]})]}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:h.map(u=>{const j=u.memberships.find(w=>w.networkId===d.id),C=u.id===s,D=i.get(u.id),N=D?.rows??[],b=D?it(D,u.sessionCount):u.sessionCount??0,R=ce(u),P=Je(u),I=u.reachable?[]:u.attempts??[];return t.jsxs("li",{"data-mesh-device-row":u.id,"data-mesh-state":u.state,"aria-current":C?"true":void 0,className:H("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",C&&"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":u.id,onClick:()=>f(u.id),className:H("min-w-0 flex-1 text-start text-body-sm text-ink","hover:text-ink-muted","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:t.jsx(De,{deviceId:u.id,name:u.name})}),t.jsxs("span",{className:H("flex shrink-0 items-center gap-1 text-meta",Ze[R]),"data-mesh-reach":R,children:[u.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),u.suspect?ge(R):at(u,n),u.suspect&&t.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:Qe()})]}),t.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[j?.role?`${j.role} · `:"",a("ui.mesh.mesh_list.member")]})]}),(P!==""||I.length>0)&&!u.reachable&&t.jsxs("div",{className:"flex flex-col gap-0.5",children:[P&&t.jsx("span",{className:"text-meta text-warning",children:P}),I.map((w,g)=>{const $=et(w.detail);return t.jsx("span",{"data-mesh-attempt":w.endpoint,className:"text-meta text-ink-dim",children:$?`${w.endpoint} — ${$}`:w.endpoint},`${w.endpoint}:${g}`)})]}),_e(u,n)?t.jsxs("span",{className:"text-meta text-warning",children:[a("ui.mesh.mesh_card.conversations")," (",nt(null),") ·"," ",_e(u,n)]}):N.length>0?t.jsxs(t.Fragment,{children:[t.jsx(pe,{className:"my-1"}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:N.slice(0,Ke).map(w=>t.jsxs("li",{"data-mesh-row-session":w.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:w.name||w.id}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:aa(w,m)}),t.jsx(ct,{session:w,destinations:dt(e,w,m),disabled:!c,onChoose:(g,$)=>o(w,g,$),trigger:t.jsx(rt,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:a("ui.mesh.mesh_list.move_conversation",{conversation:w.name||w.id})})]},w.id))}),b>N.slice(0,Ke).length&&t.jsx("button",{type:"button",onClick:()=>f(u.id),className:"w-fit text-meta text-ink-dim hover:text-ink",children:a("ui.mesh.mesh_list.show_all_panel",{count:b})})]}):t.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_list.conversation_count",{count:b})}),(j||u.state!=="self")&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(se,{size:"sm",variant:"ghost","data-mesh-invite":u.id,onClick:()=>_({deviceId:u.id,deviceName:u.name}),children:a("ui.mesh.mesh_actions.invite_to_a_network")}),j&&t.jsxs(se,{size:"sm",variant:"ghost","data-mesh-remove-member":`${d.id}:${u.id}`,onClick:()=>k({networkId:d.id,networkLabel:d.label,deviceId:u.id,deviceName:u.name}),children:[a("ui.mesh.mesh_card.remove_from"),d.label,"…"]})]})]},u.id)})})]},d.id)),e.unmatchedPeers.length>0&&t.jsxs("p",{className:"text-meta text-warning",children:[a("ui.mesh.mesh_graph.device_count",{count:e.unmatchedPeers.length})," ",a("ui.mesh.mesh_list.answered_the_peer_read_but_is_in")]})]})},ia=({revoked:e})=>{if(e.length===0)return null;const n=a("ui.mesh.mesh_list.revoked_count",{count:e.length});return t.jsx(ke,{className:"contents",chevron:"trailing",chevronClassName:"text-ink-dim",rowClassName:"min-h-auto py-0",triggerClassName:"inline-flex w-auto items-center gap-1 align-baseline text-meta text-ink-dim hover:text-ink",triggerData:{"data-mesh-revoked-toggle":""},triggerLabel:a("ui.mesh.mesh_list.revoked_toggle_label"),summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",className:"inline-block whitespace-pre",children:" · "}),n]}),children:t.jsx("ul",{"data-mesh-revoked":"",className:"m-0 flex list-none flex-col gap-1 p-0",children:e.map(s=>t.jsxs("li",{"data-mesh-revoked-member":s.deviceId,className:"flex flex-wrap items-baseline gap-x-2 text-meta text-ink-dim",children:[t.jsx("span",{children:s.networkName}),t.jsx("span",{className:"font-mono text-body-sm text-ink",children:s.deviceId}),t.jsx("span",{className:"text-body-sm text-ink-muted",children:s.label}),t.jsxs("span",{children:[s.role?`${s.role} · `:"",a("ui.mesh.mesh_graph.revoked_membership")]})]},`${s.networkId}:${s.deviceId}`))})})},ra=["canvas","list"],la={get canvas(){return a("ui.mesh.mesh_page.canvas")},get list(){return a("ui.mesh.mesh_page.list")}},oa=({state:e,initialPresentation:n="canvas",graph:s,nowSeconds:i,checking:m,staleError:c,onRetry:f,approvals:o,sessions:_,sessionError:k,selfLabel:S,movingSessionId:A,canMove:M,pendingMove:d,onAskMove:h,onDropRefused:u,onChooseMove:j,onCancelMove:C,moveBusy:D,moveReport:N,onDismissReport:b,onWaitForIdle:R,onUndoCopy:P,invite:I,onOpenInvite:w,onInvite:g,onCloseInvite:$,inviteBusy:Q,inviteReceipt:W,inviteRefusal:O,remove:x,onOpenRemove:T,onRemove:Y,onCloseRemove:Z,removeBusy:K,removeRefusal:q,removed:ae})=>{G();const[E,U]=p.useState(n),[ee,y]=p.useState(null),z=s?es(s):"",B="mesh-summary",J=ts(s),F=ss(s,_,s?.selfDeviceId??null),ne=p.useMemo(()=>{const l=new Map;for(const v of s?.devices??[]){const L=F.byDevice.get(v.id);l.set(v.id,L?it(L,v.sessionCount):v.sessionCount??0)}return l},[s,F]),ie=p.useCallback(l=>{y(l)},[]),he=s?s.devices.find(l=>l.id===ee)??null:null,r=p.useCallback((l,v,L)=>{if(!s)return null;const V={selfDeviceId:s.selfDeviceId,devices:new Map(s.devices.map(te=>[te.id,te])),networks:new Map(s.networks.map(te=>[te.id,te]))},re=l.locality==="local"?s.selfDeviceId??"":l.owner_device,Re=V.devices.get(re),X=be({session:l,ownerDeviceId:re,ownerLabel:Re?le(Re,s.devices.map(te=>te.id),!0):l.owner_device_name},{kind:"device",deviceId:v.deviceId},V);if(X.kind==="refused")return u({code:X.code,sentence:X.sentence,reach:X.reach,remedy:X.remedy,plan:X.plan??null}),null;if(X.kind==="none")return null;const Ee=L?X.alternatives.find(te=>te.keep)??X.plan:X.plan,mt=[X.plan,...X.alternatives].filter(te=>te.keep!==Ee.keep),ut={plan:Ee,alternatives:mt,risky:X.risky};h(ut)},[s,h,u]);return t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[t.jsx(bt,{title:a("ui.mesh.mesh_page.mesh"),icon:Ae,subtitle:a("ui.mesh.mesh_page.devices_this_app_is_paired_with_and"),children:t.jsxs("div",{className:"flex items-center gap-4",children:[m&&t.jsx("output",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_page.checking")}),(e.kind==="ready"||e.kind==="loading")&&t.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[t.jsx("legend",{className:"sr-only",children:a("ui.mesh.mesh_page.presentation")}),t.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:ra.map(l=>t.jsx("button",{type:"button","data-mesh-presentation":l,"aria-pressed":E===l,disabled:e.kind!=="ready",onClick:()=>U(l),className:H("h-6 rounded-sm px-3 text-body-sm text-ink-muted transition-colors duration-fast ease-out-quart","hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2","disabled:text-ink-dim disabled:hover:text-ink-dim",E===l&&"bg-surface text-ink"),children:la[l]},l))})]})]})}),t.jsx(Ss,{rows:o.rows,error:o.error,pending:o.pending,refusal:o.decisionRefusal,onDecide:o.onDecide,onRetry:o.onRetry,nowSeconds:o.nowSeconds,credentialApprovals:o.credentialApprovals,profileApprovals:o.profileApprovals,networkNames:new Map((s?.networks??[]).map(l=>[l.id,l.label]))}),e.kind==="loading"&&t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[t.jsx(Le,{className:"h-4 w-64"}),t.jsx(Le,{className:"min-h-40 w-full flex-1"})]}),e.kind==="error"&&t.jsxs(we,{variant:"warning",className:"flex-col items-start gap-2",children:[t.jsx("p",{children:e.message}),t.jsx(se,{variant:"secondary",size:"sm",onClick:f,className:"w-fit",children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),e.kind==="empty"&&t.jsx("div",{"data-glass-block":"",className:"flex min-h-0 flex-1 items-center justify-center rounded-lg border border-hairline bg-surface p-6",children:t.jsxs("div",{className:"flex flex-col items-start gap-3",children:[t.jsx("h2",{className:"text-heading text-ink",children:a("ui.mesh.mesh_page.no_network_on_this_device")}),t.jsx("p",{className:"max-w-140 text-body-sm text-ink-muted",children:a("ui.mesh.mesh_page.this_device_is_not_in_any_network")}),t.jsx("code",{className:"rounded-sm bg-sunken px-2 py-1 font-mono text-meta text-ink",children:"lop network init <name>"}),t.jsx("p",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_page.a_network_appears_here_once_this_device")})]})}),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.jsxs("div",{id:B,className:"text-meta text-ink-muted","data-mesh-summary":"",children:[t.jsx("span",{children:z}),t.jsx(ia,{revoked:s.revoked})]}),c&&t.jsx(we,{variant:"warning",children:t.jsx("p",{children:c})}),k&&t.jsx(we,{variant:"warning",children:t.jsx("p",{children:k})}),N&&t.jsx(as,{receipt:N.kind==="moved"?{verb:N.verb,detail:N.detail,undo:N.undo}:null,refusal:N.kind==="refused"?N.refusal:null,canWait:N.kind==="refused"&&N.plan!==null,onWait:R,onRecheck:f,onUndo:P,onDismiss:b,pending:D}),E==="canvas"?t.jsx(Xs,{graph:s,slots:J,nowSeconds:i,selectedDeviceId:ee,sessions:F.byDevice,sessionTotals:ne,movingSessionId:A,canMove:M,onOpenDevice:ie,onAskMove:h,onDropRefused:u,onShowAllSessions:ie,summaryId:B}):t.jsx(na,{graph:s,nowSeconds:i,selectedDeviceId:ee,sessions:F.byDevice,selfLabel:S,canMove:M,onSelect:ie,onMove:r,onInvite:w,onRemove:T})]}),he&&t.jsx(Qs,{device:he,deviceIds:s.devices.map(l=>l.id),sessions:F.byDevice.get(he.id)??{rows:[],shown:[],hidden:0},sessionTotal:ne.get(he.id)??0,nowSeconds:i,canMove:M,canInvite:e.kind==="ready",movingSessionId:A,destinationsFor:l=>dt(s,l,S),onClose:()=>y(null),onMove:r,onInvite:l=>w({deviceId:l.id,deviceName:l.name}),onRemoveMember:(l,v)=>{const L=s.networks.find(V=>V.id===v);T({networkId:v,networkLabel:L?.label??v,deviceId:l.id,deviceName:l.name})},onShowInList:l=>{ie(l),U("list")}})]})}),t.jsx(ns,{open:d!==null,plan:d?.plan??da,alternatives:d?.alternatives??[],risky:d?.risky??!1,busy:D,onCancel:C,onChoose:j}),I&&t.jsx(is,{open:I.open,options:I.options,deviceId:I.deviceId,deviceName:I.deviceName,onClose:$,onInvite:g,pending:Q,receipt:W,refusal:O}),x&&t.jsx(rs,{open:x.open,networkLabel:x.networkLabel,deviceId:x.deviceId,deviceName:x.deviceName,onClose:Z,onConfirm:Y,pending:K,refusal:q,removed:ae})]})},da={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},_a=({initialPresentation:e})=>{G();const n=gt(),s=xe(n.data,"peers")==="enabled",i=xe(n.data,"session_transfer")==="enabled",m=ls(s,{stamp:()=>je.getState().beginAnswer()}),c=os(s),f=ds(s,{poll:!1,stamp:()=>je.getState().beginAnswer()}),o=p.useMemo(()=>({peers:m,networks:c}),[m,c]),_=cs(o),k=ms(o),S=us(),A=xe(n.data,"approvals")==="enabled",M=hs(s&&A,{poll:!1}),d=ps(),h=xe(n.data,"credential_approvals")==="enabled",u=xe(n.data,"profile_approvals")==="enabled",j=d.isError?{approvalId:d.variables?.approvalId??null,submittedAt:d.submittedAt,...xs(d.error)}:null,C=p.useMemo(()=>Math.floor((M.dataUpdatedAt||Date.now())/1e3),[M.dataUpdatedAt]),D=je(y=>y.settlePlacement),N=fs(),b=gs(),[R,P]=p.useState(null),[I,w]=p.useState(null),[g,$]=p.useState(null),[Q,W]=p.useState(null),[O,x]=p.useState(null),[T,Y]=p.useState(null),[Z,K]=p.useState(null),q=p.useMemo(()=>{const y=Math.max(m.dataUpdatedAt,c.dataUpdatedAt);return Math.floor((y||Date.now())/1e3)},[m.dataUpdatedAt,c.dataUpdatedAt]),ae=p.useCallback(()=>{m.refetch(),c.refetch(),f.refetch()},[m,c,f]),E=p.useCallback((y,z)=>{P(null);const B={sessionId:y.sessionId,to:y.to,keep:y.keep,waitS:z??y.waitS};S.mutate(B,{onSuccess:J=>{if(J.kind==="moved"){const{receipt:F}=J;D(y.sessionId,F);const ne=F.locality==="local"?a("ui.mesh.mesh_drop.this_device"):k?.devices.find(ie=>ie.id===F.owner_device)?.label??F.owner_device;w({kind:"moved",verb:F.mode==="keep"?a("ui.mesh.mesh_page.copied"):a("ui.mesh.mesh_page.moved"),detail:F.mode==="keep"?a("ui.mesh.mesh_page.copy_receipt",{destination:ne,suffix:F.new_session_id.slice(-6)}):a("ui.mesh.mesh_page.move_receipt",{destination:ne,retirement:F.source_retired?a("ui.mesh.mesh_page.the_copy_here_is_gone"):""}),undo:F.mode==="keep"?{sessionId:F.new_session_id,to:"local",keep:!1,verb:a("ui.mesh.mesh_page.bring_copy_back",{device:ne}),waitS:0,lost:vs(ne,a("ui.mesh.mesh_drop.this_device"))}:null});return}w({kind:"refused",refusal:J.refusal,plan:y})},onError:()=>{w({kind:"refused",refusal:{code:"move_failed",sentence:a("ui.mesh.mesh_page.the_move_could_not_be_sent_nothing"),status:null,unconfirmed:!1},plan:y})}})},[k,S,D]),U=p.useMemo(()=>{if(!k)return[];const y=g?.deviceId,z=y?k.devices.find(B=>B.id===y):void 0;return k.networks.filter(B=>z?!z.memberships.some(J=>J.networkId===B.id):!0).map(B=>({id:B.id,label:B.label}))},[k,g]);if(!s)return t.jsx(vt,{to:"/chat",replace:!0});const ee=_.kind==="ready"?m.error?fe(m.error):c.error?fe(c.error):null:null;return t.jsx(oa,{initialPresentation:e,state:_,graph:k,nowSeconds:q,checking:m.isFetching||c.isFetching,staleError:ee,onRetry:ae,approvals:{rows:M.data??[],error:M.isError?bs(M.error):null,pending:d.isPending?d.variables??null:null,decisionRefusal:j,credentialApprovals:h,profileApprovals:u,onDecide:(y,z)=>{const B=M.data?.find(F=>F.approvalId===y),J=B?_s(B,z,{credentialApprovals:h,profileApprovals:u},j?.approvalId===y?j.retryable:void 0):null;J&&d.mutate({approvalId:y,decision:z,request:J})},onRetry:()=>void M.refetch(),nowSeconds:C},sessions:f.data?.rows??[],movingSessionId:S.isPending?S.variables?.sessionId??null:null,sessionError:f.isError?fe(f.error):null,selfLabel:k?.devices.find(y=>y.state==="self")?.label??a("ui.mesh.mesh_drop.this_device"),canMove:i,pendingMove:R,onAskMove:P,onDropRefused:y=>w({kind:"refused",refusal:{code:y.code,sentence:y.sentence,reach:y.reach,status:null,unconfirmed:!1},plan:y.plan}),onChooseMove:y=>E(y),onCancelMove:()=>P(null),moveBusy:S.isPending,moveReport:I,onDismissReport:()=>w(null),onWaitForIdle:()=>{I?.kind!=="refused"||!I.plan||E(I.plan,ca)},onUndoCopy:()=>{I?.kind!=="moved"||!I.undo||P({plan:I.undo,alternatives:[],risky:!1})},invite:g===null?null:{open:!0,deviceId:g.deviceId,deviceName:g.deviceName,options:U},onOpenInvite:y=>{W(null),x(null),$(y)},onInvite:y=>{N.mutate(y,{onSuccess:z=>W(z),onError:z=>x({code:"invite_refused",sentence:fe(z),status:null,unconfirmed:!1})})},onCloseInvite:()=>$(null),inviteBusy:N.isPending,inviteReceipt:Q,inviteRefusal:O,remove:T===null?null:{open:!0,networkId:T.networkId,networkLabel:T.networkLabel,deviceId:T.deviceId,deviceName:T.deviceName},onOpenRemove:y=>{K(null),Y(y)},onRemove:y=>{T&&b.mutate({networkId:T.networkId,deviceId:T.deviceId,confirm:y},{onSuccess:z=>K(z)})},onCloseRemove:()=>Y(null),removeBusy:b.isPending,removeRefusal:b.isError?{code:"remove_refused",sentence:fe(b.error),status:null,unconfirmed:!1}:null,removed:Z})},ca=300;export{_a as MeshPage,oa as MeshSurface,_a as default};
1
+ import{r as p,j as t,c as H}from"./index-kEyWW56d.js";import{Q as Xe,R as ht,T as pt,V as ce,W as xt,X as ft,Y as ge,Z as Ze,_ as le,$ as Je,a0 as Qe,a1 as et,a as gt,t as xe,x as je,a2 as vt}from"./appearance-CB5X23Pc.js";import{P as bt}from"./page-header-D6f_9LyG.js";import{u as G,B as se,x as _t,T as kt,t as pe,D as yt,b as jt,d as wt,H as Nt,I as Pe,e as $e,f as Le,A as we}from"./error-boundary-CHZZV6GH.js";import{t as a}from"./messages-CUhxkxii.js";import{U as de,V as me,W as Te,X as It,Y as tt,Z as Ct,_ as St,$ as Mt,a0 as At,a1 as Dt,a2 as Rt,a3 as Et,a4 as Pt,a5 as Oe,a6 as He,a7 as $t,a8 as Lt,a9 as Tt,aa as Ot,ab as Ht,ac as Wt,ad as Ft,ae as qt,af as zt,ag as Bt,ah as Se,ai as Yt,aj as Ut,ak as Me,al as st,am as at,an as Vt,ao as ve,ap as Ne,aq as Gt,ar as Kt,as as be,at as We,au as Xt,av as Zt,aw as Ie,ax as Jt,ay as nt,az as _e,aA as Qt,aB as it,aC as es,aD as ts,aE as ss,aF as as,aG as ns,aH as is,aI as rs,aJ as ls,aK as os,aL as ds,aM as cs,aN as ms,aO as us,aP as hs,aQ as ps,aR as xs,aS as fs,aT as gs,aU as vs,aV as fe,aW as bs,aX as _s}from"./index-_Gw7RTII.js";import{bD as ke,bE as ks,bF as ys,bG as js,bH as Ae,bI as ws,a1 as rt}from"./conversation-input-sync-Btmg29tU.js";import"./roles-D1pcbxAx.js";import"./console-mirror-XM_5bSKF.js";function Ns(e){return e==="failed"?"text-danger":de(e)?"text-ink-muted":"text-ink-dim"}function Is(e){return e==="failed"?a("ui.mesh.mesh_approvals_tray.abandon"):a("ui.mesh.mesh_approvals_tray.stop")}function Cs(e){switch(e){case"requested":return[{term:a("ui.mesh.mesh_approvals_tray.signing"),text:a("ui.mesh.mesh_approvals_tray.approving_signs_with_this_machine_s_operator")}];case"approved":return[{term:a("ui.mesh.mesh_approvals_tray.next"),text:a("ui.mesh.mesh_approvals_tray.an_agent_runs_the_install_and_connect")},{term:a("ui.mesh.mesh_approvals_tray.stop"),text:a("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_nothing_has")}];case"connecting":return[{term:a("ui.mesh.mesh_approvals_tray.stop"),text:a("ui.mesh.mesh_approvals_tray.stopping_now_denies_the_request_the_runner")}];case"failed":return[{term:a("ui.mesh.mesh_approvals_tray.after_a_stop"),text:a("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_abandoning")}];default:return[]}}const Ss=({rows:e,error:n,pending:s,refusal:i,onDecide:m,onRetry:c,nowSeconds:f,networkNames:o,credentialApprovals:_=!1,profileApprovals:k=!1})=>{G();const S=s!==null,[A,M]=p.useState(""),d=p.useRef(null),h=i?JSON.stringify([i.approvalId,i.code,i.sentence]):null,u=p.useMemo(()=>e.filter(x=>de(x.state)||me(x)),[e]),j=p.useMemo(()=>e.filter(x=>!de(x.state)&&!me(x)),[e]),[C,D]=p.useState(!1),N=p.useRef(null),b=p.useRef(null),R=p.useRef(null),P=(x,T)=>{u.some(Y=>Y.approvalId===x&&Y.kind==="credential")&&(R.current={id:x,origin:document.activeElement,rowAtStart:e.find(Y=>Y.approvalId===x),refusalSubmittedAtStart:i?.submittedAt??0}),m(x,T)};p.useLayoutEffect(()=>{const x=R.current;if(!x)return;const T=e.find(U=>U.approvalId===x.id);if(s)return;const Y=i?.approvalId===x.id&&(i.submittedAt??0)>x.refusalSubmittedAtStart;if(T===x.rowAtStart&&!Y)return;R.current=null;const Z=u.find(U=>U.approvalId!==x.id),K=Z?N.current?.querySelector(`[data-tour-tag="mesh-approvals-live"] [data-approval-id="${CSS.escape(Z.approvalId)}"] ${de(Z.state)?'[data-tour-tag="mesh-approval-summary"]':'[data-tour-tag="mesh-approval-controls"] button:not(:disabled)'}`):null,q=(u.some(U=>U.approvalId===x.id)?N.current?.querySelector(`[data-approval-id="${CSS.escape(x.id)}"] [data-tour-tag="mesh-approval-refusal"]`):null)??K??b.current?.querySelector("button"),ae=i?N.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(i.approvalId??"")}"]`)??null:null;Te({document,target:q??null,refusalTarget:ae,origin:x.origin,allowFocus:!0,sentence:i?.sentence??""}).focused&&(d.current=h)},[e,s,i,u,h]),p.useLayoutEffect(()=>{if(!i||s){d.current=null,M("");return}if(d.current===h){M("");return}const x=N.current?.querySelector(`[data-approval-refusal-id="${CSS.escape(i.approvalId??"")}"]`)??null,T=Te({document,target:null,refusalTarget:x,origin:null,allowFocus:!1,sentence:i.sentence});T.focused&&(d.current=h),M(T.announcement)},[i,h,s,e]);const I=u.filter(x=>de(x.state)).length,w=u.filter(me).length,g=j.filter(x=>x.kind==="credential"&&x.state==="connected").length,$=j.some(x=>x.state==="failed"),Q=j.filter(x=>x.state==="failed").length,W=i!==null&&e.some(x=>x.approvalId===i.approvalId&&(de(x.state)||me(x)||C)),O=e.find(x=>x.approvalId===i?.approvalId);return u.length===0&&j.length===0&&!n&&!i?null:t.jsxs("section",{ref:N,"aria-label":a("ui.mesh.mesh_approvals_tray.approvals"),"data-tour-tag":"mesh-approvals-tray",className:"flex flex-col gap-3",children:[t.jsx("output",{"aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a("ui.mesh.approval.result_status",{shared:g,attention:w})}),t.jsx("output",{"aria-live":"polite","aria-atomic":"true",className:"sr-only","data-tour-tag":"mesh-approval-announcement",children:t.jsx("bdi",{dir:"auto",children:A})}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx(It,{"aria-hidden":"true",className:"size-4 text-ink-muted"}),t.jsx("h2",{className:"text-body-sm text-ink",children:a("ui.mesh.mesh_approvals_tray.approvals")}),I>0&&t.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_approvals_tray.waiting_count",{count:I})}),w>0&&t.jsx("span",{className:"text-meta text-warning",children:a("ui.mesh.approval.needs_attention",{count:w})})]}),n&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("p",{className:"min-w-0 flex-1 text-meta text-ink-muted",children:n}),t.jsx(se,{variant:"secondary",size:"sm",onClick:c,children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),u.length>0&&t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-live",children:u.map(x=>t.jsx(Fe,{row:x,pending:s?.approvalId===x.approvalId?s:null,busy:S,refusal:i?.approvalId===x.approvalId?i:null,onDecide:P,nowSeconds:f,networkNames:o,credentialApprovals:_,profileApprovals:k},x.approvalId))}),i&&!W&&t.jsx(lt,{approvalId:i.approvalId??"",requestIsBackendSummary:O?Ct(O):!1,refusal:i,request:O?tt(O):a("ui.mesh.approval.credential_title")}),j.length>0&&t.jsx("div",{ref:b,"data-tour-tag":"mesh-approvals-settled",children:t.jsx(ke,{open:C,onOpenChange:D,chevronClassName:"text-ink-dim",className:H(u.length>0&&"border-hairline border-t pt-3"),summary:t.jsxs("span",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[a("ui.mesh.mesh_approvals_tray.settled_approvals"),t.jsxs("span",{className:"text-ink-dim",children:["(",j.length,")"]}),$&&t.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-danger"}),g>0&&t.jsx("span",{className:"text-ink-muted",children:a("ui.mesh.approval.shared_count",{count:g})}),Q>0&&t.jsx("span",{className:"text-danger",children:a("ui.mesh.mesh_approvals_tray.failed_count",{count:Q})})]}),children:t.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-records",children:j.map(x=>t.jsx(Fe,{row:x,pending:s?.approvalId===x.approvalId?s:null,busy:S,refusal:i?.approvalId===x.approvalId?i:null,onDecide:P,nowSeconds:f,networkNames:o,credentialApprovals:_,profileApprovals:k},x.approvalId))})})})]})},Fe=({row:e,pending:n,busy:s,refusal:i,onDecide:m,nowSeconds:c,networkNames:f,credentialApprovals:o,profileApprovals:_})=>{G();const k=de(e.state),S=St(e,i?.retryable),A=p.useId(),M=p.useId(),d=tt(e),h=Mt(e,f),u=At(e,f),j=Dt(e),C=Rt(e),D=Et(e),N=Pt(e.expiresAt,c,me(e)),b=e.kind==="credential"||e.kind==="unknown"||e.kind==="profile",R=b||e.canApproveHere===!1,P=R?[]:Cs(e.state),I={credentialApprovals:o,profileApprovals:_},w=Oe(e,I),g=He(e.state),$=$t(e,I,i?.retryable),Q=e.kind==="profile"?ks(e,{profileApprovals:_,canApprove:Oe(e,I),canDeny:He(e.state),canRetryApply:Lt(e,I,i?.retryable)}):null,W=o?e.typed:void 0,O=W?Tt(e):[],x=W?.disclosure?Ot(e):null,T=e.typed?.unprovenHuman===!0,Y=e.kind==="credential"&&["approved","failed","connecting","connected"].includes(e.state),Z=i?.sentence||(W?.applyOutcome?[W.applyOutcome.reason,W.applyOutcome.remedy].filter(Boolean).join(" "):""),K=i?.code||W?.applyOutcome?.code||W?.refusal,q=Ht(e),ae=(e.typed?.refusalMessage??"")||(e.typed?a("ui.mesh.approval.typed_review_unavailable"):e.approveRemedy||a("ui.mesh.approval.cli_review"));return t.jsxs("li",{className:"flex flex-col gap-2 py-3 first:pt-0 last:pb-0","data-tour-tag":"mesh-approval-card","data-approval-id":e.approvalId,children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:H("text-meta",me(e)?"text-warning":Ns(e.state)),children:S?a("ui.mesh.approval.could_not_apply"):e.kind==="credential"&&e.state==="connected"?a("ui.mesh.approval.shared"):e.kind==="credential"&&(e.state==="approved"||e.state==="failed")?a("ui.mesh.approval.approved_not_applied"):Wt(e.state)}),t.jsx("div",{className:"grow"}),!S&&(k||me(e))&&N&&t.jsx("span",{className:"text-meta text-ink-dim",children:N})]}),Q?t.jsx(ys,{view:Q}):t.jsx("p",{className:"text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-summary",tabIndex:-1,id:A,children:k?h:d}),q&&t.jsx("p",{id:M,className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-critical-facts",children:q}),!R&&e.state==="failed"&&t.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-stopped-note",children:a("ui.mesh.mesh_approvals_tray.the_runner_stopped_before_it_finished_it")}),k&&R&&!w&&t.jsx("p",{className:"text-meta text-ink-muted whitespace-pre-wrap [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-cli-remedy",children:ae}),e.kind==="credential"&&!e.typed&&e.state==="approved"&&t.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-apply-hint",children:a(e.details?.length?"ui.mesh.approval.approved_apply_hint":"ui.mesh.approval.approved_details_missing")}),T&&t.jsx("p",{className:"text-meta text-ink-dim","data-tour-tag":"mesh-approval-file-key",children:a(Y?"ui.mesh.approval.file_key_recorded":"ui.mesh.approval.file_key_disclosure")}),Z&&t.jsx(lt,{approvalId:e.approvalId,refusal:{code:K??"",sentence:Z}}),$&&t.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.retry_hint")}),Y&&g&&t.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.cancel_hint")}),(w||g||$)&&t.jsxs("div",{className:"flex flex-wrap items-center gap-2","data-tour-tag":"mesh-approval-controls",children:[$&&t.jsx(se,{variant:"primary",size:"sm",disabled:s,"aria-describedby":q?`${A} ${M}`:A,onClick:()=>m(e.approvalId,"apply"),"data-tour-tag":"mesh-approval-retry-apply",children:a("ui.mesh.approval.try_again")}),w&&t.jsx(se,{variant:"primary",size:"sm",disabled:s,"aria-describedby":q?`${A} ${M}`:A,onClick:()=>m(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:a("ui.mesh.mesh_approvals_tray.approve")}),g&&t.jsx(se,{variant:"ghost",size:"sm",disabled:s,"aria-describedby":q?`${A} ${M}`:A,onClick:()=>m(e.approvalId,"deny"),"data-tour-tag":k?"mesh-approval-deny":"mesh-approval-stop",children:k?a("ui.mesh.mesh_approvals_tray.deny"):e.kind==="credential"?a("ui.mesh.approval.cancel_sharing"):Is(e.state)}),n&&t.jsx("span",{className:"text-meta text-ink-dim",children:n.decision==="approve"?e.typed?.unprovenHuman?a("ui.mesh.approval.signing_applying"):a("ui.mesh.mesh_approvals_tray.waiting_for_the_signing_prompt"):n.decision==="apply"?a("ui.mesh.approval.applying"):a("ui.mesh.mesh_approvals_tray.writing_the_decision")})]}),t.jsxs(ke,{chevronClassName:"text-ink-dim",summary:t.jsx("span",{className:"text-meta",children:a("ui.mesh.mesh_approvals_tray.details")}),children:[O.length>0&&t.jsx("ul",{className:"flex flex-col gap-1.5 text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-credential-consequences",children:O.map(E=>t.jsx("li",{children:E},E))}),x&&W?.disclosure?.recipient.keyFingerprint&&t.jsxs("p",{className:"text-meta text-ink-dim [overflow-wrap:anywhere]",children:[a("ui.mesh.approval.recipient_key",{device:x})," ",t.jsx("span",{className:"font-mono",children:W.disclosure.recipient.keyFingerprint})]}),K&&t.jsx("p",{className:"text-meta text-ink-dim font-mono",children:K}),W?.disclosure&&t.jsx(ke,{summary:t.jsx("span",{className:"text-meta",children:a("ui.mesh.approval.technical_request")}),children:t.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap text-meta text-ink-dim [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-signed-evidence",children:W.disclosure.evidence})}),b&&O.length===0&&(e.details?.length?t.jsx("ul",{className:"flex flex-col gap-1.5 text-meta text-ink-muted [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-server-details",children:e.details.map((E,U)=>t.jsx("li",{className:"whitespace-pre-wrap",children:E},`${U}:${E}`))}):t.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.details_unavailable")})),u.length>0&&t.jsx("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta text-ink-dim","data-tour-tag":"mesh-approval-consequences",children:u.map(E=>t.jsxs(p.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{children:E.consequence})]},E.term))}),(j||C)&&t.jsxs("p",{className:"text-meta text-ink-muted",children:[j&&t.jsx("span",{children:j}),j&&C&&t.jsx("span",{children:" · "}),C&&t.jsx("span",{className:"font-mono",children:C})]}),D&&t.jsx("p",{className:"text-meta text-ink-dim",children:D}),P.length>0&&t.jsx("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-0.5 text-meta","data-tour-tag":"mesh-approval-consequence",children:P.map(E=>t.jsxs(p.Fragment,{children:[t.jsx("dt",{className:"text-ink-muted",children:E.term}),t.jsx("dd",{className:"text-ink-muted",children:E.text})]},E.term))})]})]})},lt=({refusal:e,request:n,approvalId:s,requestIsBackendSummary:i=!1})=>{G();const m=js();return t.jsx("p",{tabIndex:-1,className:"text-meta text-warning [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-refusal","data-approval-refusal-id":s,children:n?Ft(n,e.sentence).map((c,f)=>c.kind==="literal"?t.jsx(p.Fragment,{children:c.text},`literal:${f}`):t.jsx("bdi",{dir:qt(c.kind,m,i),children:c.text},c.kind)):t.jsx("bdi",{dir:"auto",children:e.sentence})})},Ms=4,ye={kind:"idle"};function As(e){switch(e.kind){case"dragging":case"settling":return e.payload.session.id;case"pressing":return null;default:return null}}function oe(e,n){switch(n.kind){case"press":return e.kind!=="idle"?e:{kind:"pressing",payload:n.payload,originX:n.x,originY:n.y,pointerId:n.pointerId};case"move":return e.kind==="pressing"?Math.max(Math.abs(n.x-e.originX),Math.abs(n.y-e.originY))<Ms?e:{kind:"dragging",payload:e.payload,x:n.x,y:n.y,target:n.target,pointerId:e.pointerId}:e.kind==="dragging"?{...e,x:n.x,y:n.y,target:n.target}:e;case"release":return e.kind==="dragging"?{kind:"settling",payload:e.payload,target:e.target}:e.kind==="pressing"?ye:e;case"cancel":case"settled":return ye;default:return e}}const Ds=({edges:e,geometry:n,selectedDeviceId:s})=>t.jsx("svg",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0 overflow-visible",width:n.bounds.width,height:n.bounds.height,children:e.map(i=>{const m=n.networks.get(i.networkId),c=n.devices.get(i.deviceId);if(!m||!c)return null;const f=s!==null&&i.deviceId===s;return t.jsx("path",{"data-mesh-edge":i.key,d:zt(m,c),fill:"none",strokeWidth:f?2:1.5,className:f?"stroke-ink":"stroke-ink-dim"},i.key)})}),De=({deviceId:e,name:n,compact:s=!1,deviceIds:i,className:m})=>{G();const c=Xe({name:n});return t.jsxs("span",{className:H("flex min-w-0 items-baseline gap-2",m),"data-mesh-device-identity":e,children:[t.jsx(_t,{content:n?.trim()?c:null,children:t.jsx("span",{className:"min-w-0 flex-1 truncate text-start","data-mesh-device-name":"",children:c})}),t.jsx("span",{className:"shrink-0 font-mono text-meta text-ink-muted","data-mesh-device-id":"",title:e,children:s?ht(e,i):e})]})},Rs={self:"border-l-hairline",reached:"border-l-hairline","relay-down":"border-l-warning","handshake-refused":"border-l-warning","address-unreachable":"border-l-warning","no-endpoint":"border-l-hairline","not-a-member":"border-l-hairline",unanswered:"border-l-warning","not-attempted":"border-l-hairline",unknown:"border-l-hairline"};function Es(e){return e.suspect?"border-l-danger":Rs[ce(e)]}const Ps={self:"ring-2 ring-accent",reachable:null,relay_down:null,handshake_refused:null,unreachable:null,suspect:null},$s={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function Ls(e,n,s){return[Xe(e),e.id,at(e,n),s].filter(Boolean).join(", ")}function ue(e){return e.name.trim()||e.id.slice(-6)}function ot(e,n,s){if(s!=="reached"&&s!=="self"){const i=ge(s);return e.unreachable_reason?`${i} (${e.unreachable_reason})`:i}return e.live_state.trim()?e.live_state.trim():e.locality==="local"?a("ui.mesh.mesh_drop.on_this_device"):a("ui.mesh.mesh_node.on_device",{device:n})}const Ts={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},Os=({network:e,x:n,y:s,refused:i})=>(G(),t.jsxs("li",{"data-mesh-network":e.id,"data-mesh-network-refused":i?"true":void 0,"data-glass-block":"",className:H("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",i?"border-warning":"border-hairline"),style:{left:n,top:s,width:Se,height:Bt},children:[t.jsx(Ae,{"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:a("ui.mesh.mesh_list.epoch",{epoch:e.epoch}),className:"block truncate text-meta text-ink-dim",children:[a("ui.mesh.mesh_graph.device_count",{count:e.memberCount}),e.revokedCount>0?t.jsxs(t.Fragment,{children:[" · ",a("ui.mesh.mesh_list.revoked_count",{count:e.revokedCount})]}):null]})]})]})),Hs=({device:e,deviceIds:n,x:s,y:i,nowSeconds:m,selected:c,sessions:f,sessionTotal:o,dropState:_,movingSessionId:k,draggedSessionId:S,onOpen:A,onChipPointerDown:M,onChipClick:d,onShowAllSessions:h})=>{G();const{activity:u}=pt(e,f.rows),j=u==="working",C=Ls(e,m,j?"working":null),D=ce(e);return t.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":_??void 0,"aria-current":c?"true":void 0,"data-glass-block":"",className:H("absolute flex flex-col rounded-md border border-l-4 border-control bg-elevated","hover:bg-row-hover",c&&"border-y-ink border-r-ink bg-row-selected",Es(e),Ps[e.state],_&&$s[_]),style:{left:s,top:i,width:Se,height:Yt},children:[t.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":D,"aria-label":C,title:xt(e),onClick:()=>A(e.id),className:H("flex w-full flex-col justify-between rounded-t-[5px] px-3 pt-2 pb-2 text-start","cursor-pointer","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),style:{height:Ut},children:[t.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2",children:[t.jsx(ws,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),t.jsx(De,{className:"min-w-0 flex-1 text-body-sm text-ink",deviceId:e.id,deviceIds:n,name:e.name,compact:!0}),e.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"})]}),t.jsxs("span",{className:"flex w-full min-w-0 items-baseline gap-1",children:[t.jsx("span",{className:"w-3 shrink-0 font-mono text-body-sm text-ink tabular-nums",children:e.sessionCount??"–"}),t.jsx("span",{className:H("min-w-0 truncate text-meta",e.sessionCount===null?"text-ink-dim":"text-ink-muted"),children:st(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:ft[D]}),t.jsx("span",{className:H("shrink-0",Ze[D]),children:ge(D)}),j&&t.jsx("span",{"data-mesh-working":"",className:"shrink-0 text-info",children:a("ui.mesh.mesh_node.working")}),e.memberships.length>1&&t.jsx("span",{className:"min-w-0 truncate text-ink-dim",children:a("ui.mesh.mesh_node.memberships",{count:e.memberships.length})})]})]}),t.jsxs("ul",{"aria-label":a("ui.mesh.mesh_node.conversations_on",{device:le(e,n,!0)}),className:H("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",_==="accept"&&"opacity-40"),children:[f.shown.map(N=>t.jsx(Ws,{session:N,ownerLabel:le(e,n,!0),ownerReach:D,ownerReachable:e.reachable,moving:k===N.id,dragging:S===N.id,onPointerDown:M,onClick:()=>d(N)},N.id)),f.hidden>0&&t.jsx("li",{className:"shrink-0",children:t.jsxs("button",{type:"button","data-mesh-more":e.id,onClick:()=>h(e.id),className:H("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:a("ui.mesh.mesh_node.shown_conversations",{shown:f.shown.length,total:o}),"aria-label":a("ui.mesh.mesh_node.show_all_conversations",{count:o}),children:["+",f.hidden]})})]})]})},Ws=({session:e,ownerLabel:n,ownerReach:s,ownerReachable:i,moving:m,dragging:c,onPointerDown:f,onClick:o})=>{G();const _=ot(e,n,s);return m?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:a("ui.mesh.mesh_card.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:`${ue(e)} · ${_}`,"aria-label":a("ui.mesh.mesh_node.open_conversation",{conversation:ue(e),fact:_,owner:n}),onPointerDown:k=>f(k,e),onClick:()=>o(e),className:H("flex min-h-6 w-full max-w-32 items-center rounded-sm border border-hairline bg-surface px-1.5 text-start text-meta text-ink-muted","cursor-grab active:cursor-grabbing","hover:text-ink",Ts[Vt(e,i)],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",children:ue(e)})})})};function qe(e){const n=e.trim();if(!n)return null;if(n.startsWith("[")){const i=n.indexOf("]");if(i<=1)return null;const m=n.slice(1,i),c=n.slice(i+1);if(!c)return{host:m,port:null};if(!c.startsWith(":"))return null;const f=Number(c.slice(1));return{host:m,port:Number.isInteger(f)?f:null}}const s=n.lastIndexOf(":");if(s>0){const i=n.slice(s+1);if(/^\d+$/.test(i))return{host:n.slice(0,s),port:Number(i)}}return{host:n,port:null}}function ze(e){const n=e.trim().split(".");if(n.length!==4)return null;for(const s of n)if(!/^\d{1,3}$/.test(s)||Number(s)>255)return null;return`${n[0]}.${n[1]}.${n[2]}`}function Fs(e){return`${e}.x`}function qs(e){const n=new Map;for(const i of e.values())for(const m of i)n.set(m,(n.get(m)??0)+1);const s=new Set;for(const[i,m]of n)m>1&&s.add(i);return s}function Ce(e){return new Set(e.endpoints.map(n=>n.trim()).filter(Boolean))}function zs(e,n){const s=e.filter(d=>d.id!==n),i=e.find(d=>d.id===n)??null,m=new Map;for(const d of e)m.set(d.id,Ce(d));const c=qs(m),f=new Set;for(const d of i?Ce(i):[]){if(c.has(d))continue;const h=qe(d),u=h?ze(h.host):null;u&&f.add(u)}const o=d=>{const h=new Set;for(const u of Ce(d)){if(c.has(u))continue;const j=qe(u),C=j?ze(j.host):null;C&&h.add(C)}return h},_=new Map,k=new Map;for(const d of s){const h=Bs(d);if(h){_.set(h,[..._.get(h)??[],d.id]);continue}for(const u of o(d))k.set(u,[...k.get(u)??[],d.id])}const S=new Map(e.map((d,h)=>[d.id,h])),A=d=>[...d].sort((h,u)=>(S.get(h)??0)-(S.get(u)??0)),M=[];for(const[d,h]of _)M.push({prefix:d,tier:"declared",deviceIds:A(h),get words(){return a("ui.mesh.mesh_scope.declared")}});for(const[d,h]of k)f.has(d)?M.push({prefix:d,tier:"shared",deviceIds:A(h),get words(){return a("ui.mesh.mesh_scope.shared_with_this_device")}}):h.length>1&&M.push({prefix:d,tier:"probable",deviceIds:A(h),get words(){return a("ui.mesh.mesh_scope.same_prefix")}});return M.sort((d,h)=>d.tier.localeCompare(h.tier)||d.prefix.localeCompare(h.prefix))}function Bs(e){for(const n of e.memberships){const s=n.scope.trim();if(s)return s}return""}const Be={declared:0,shared:1,probable:2};function Ys(e,n){const s=new Map;for(const m of e){let c=null;for(const o of m.deviceIds){const _=n.get(o);_!==void 0&&(c===null||_<c.slot)&&(c={id:o,slot:_})}if(c===null)continue;const f=s.get(c.id);f===void 0?s.set(c.id,{slot:c.slot,groups:[m]}):f.groups.push(m)}const i=m=>{let c=-1;for(const f of m.deviceIds){const o=n.get(f);o!==void 0&&o>c&&(c=o)}return c};return[...s.entries()].sort((m,c)=>m[1].slot-c[1].slot).map(([m,c])=>({deviceId:m,groups:c.groups.sort((f,o)=>i(o)-i(f)||Be[f.tier]-Be[o.tier]||f.prefix.localeCompare(o.prefix))}))}function Us(e){return new Map(e.map(n=>[n.deviceId,n.groups.length]))}function Vs(e){return`${e.tier==="declared"?e.prefix:Fs(e.prefix)} · ${e.words}`}const Ye=(e,n)=>e.deviceIds.map(s=>n.devices.get(s)).filter(s=>s!==void 0),Gs=({stacks:e,geometry:n})=>(G(),t.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(s=>{const i=s.groups.length,m=new Array(i).fill(0);let c=null;for(let o=i-1;o>=0;o-=1){const _=Ye(s.groups[o],n),k=(_.length===0?0:Math.max(..._.map(S=>S.y+S.height)))+ve;c=c===null?k:Math.max(k,c+Ne),m[o]=c}const f=n.devices.get(s.deviceId);return s.groups.map((o,_)=>{const k=Ye(o,n);if(k.length===0)return null;const S=i-1-_,A=Math.min(...k.map(C=>C.x)),M=Math.max(...k.map(C=>C.x)),h=(f?.y??Math.min(...k.map(C=>C.y)))-ve-Gt*S,u=o.tier==="declared",j=Vs(o);return t.jsx("div",{"data-mesh-scope":`${o.tier}:${o.prefix}`,"data-mesh-scope-level":_,className:H("absolute rounded-lg",o.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:A-ve-Ne*S,top:h,width:M+Se-A+(ve+Ne*S)*2,height:m[_]-h},children:t.jsx("span",{"data-mesh-scope-label":"",className:H("absolute bottom-full left-1 mb-0.5 whitespace-nowrap text-meta",o.tier==="probable"?"text-ink-dim":"text-ink-muted",u&&"font-medium"),children:j})},`${o.tier}:${o.prefix}`)})})})),Ue=48,Ve=1.25,Ks=.0015,Xs=({graph:e,slots:n,nowSeconds:s,selectedDeviceId:i,sessions:m,sessionTotals:c,movingSessionId:f,canMove:o,onOpenDevice:_,onAskMove:k,onDropRefused:S,onShowAllSessions:A,summaryId:M})=>{G();const d=p.useRef(null),[h,u]=p.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[j,C]=p.useState({k:1,tx:0,ty:0}),D=p.useRef(!1),N=p.useRef(!1),b=p.useRef(null),R=p.useMemo(()=>zs(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),P=p.useMemo(()=>Ys(R,n.devices),[R,n]),I=p.useMemo(()=>Kt(n,Us(P)),[n,P]),w=p.useMemo(()=>({selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(r=>[r.id,r])),networks:new Map(e.networks.map(r=>[r.id,r]))}),[e]),[g,$]=p.useState(ye),Q=p.useRef({kind:"ground"}),W=p.useCallback((r,l)=>{const v=document.elementFromPoint(r,l),L=v?.closest("[data-mesh-device]");if(L){const re=L.getAttribute("data-mesh-device");if(re)return{kind:"device",deviceId:re}}const V=v?.closest("[data-mesh-network]");if(V){const re=V.getAttribute("data-mesh-network");if(re)return{kind:"network",networkId:re}}return{kind:"ground"}},[]),O=p.useMemo(()=>g.kind!=="dragging"&&g.kind!=="settling"?null:be(g.payload,g.target,w),[g,w]),x=p.useCallback(r=>{if(!O)return null;if(O.kind==="plan"){const l=g.kind==="dragging"||g.kind==="settling"?g.target:null;return l&&l.kind==="device"&&l.deviceId===r?"accept":null}if(O.kind==="refused"){const l=g.kind==="dragging"||g.kind==="settling"?g.target:null;return l&&l.kind==="device"&&l.deviceId===r?"refuse":null}return null},[O,g]),T=p.useCallback((r,l)=>{if(!o||r.button!==0)return;N.current=!1;const v=l.locality==="local"?e.selfDeviceId??"":l.owner_device,L=w.devices.get(v),V={session:l,ownerDeviceId:v,ownerLabel:L?le(L,[...w.devices.keys()],!0):l.owner_device_name};try{r.currentTarget.setPointerCapture(r.pointerId)}catch{}$(re=>oe(re,{kind:"press",payload:V,x:r.clientX,y:r.clientY,pointerId:r.pointerId}))},[o,w,e.selfDeviceId]),Y=r=>{if(g.kind==="pressing"||g.kind==="dragging"){const l=W(r.clientX,r.clientY);Q.current=l,$(v=>oe(v,{kind:"move",x:r.clientX,y:r.clientY,target:l}));return}F(r)},Z=r=>{if(ne(r),g.kind!=="pressing"&&g.kind!=="dragging")return;if(g.kind==="pressing"){$(v=>oe(v,{kind:"cancel"}));return}const l=be(g.payload,g.target,w);N.current=!0,$(v=>oe(v,{kind:"release"})),l.kind==="plan"?k({plan:l.plan,alternatives:l.alternatives,risky:l.risky}):l.kind==="refused"&&S({code:l.code,sentence:l.sentence,reach:l.reach,remedy:l.remedy,plan:l.plan??null}),$(v=>oe(v,{kind:"settled"}))};p.useEffect(()=>()=>$(ye),[]);const K=p.useCallback(()=>{C(We(I.bounds,h))},[I.bounds,h]);p.useEffect(()=>{const r=d.current;if(!r)return;const l=()=>{const L=r.getBoundingClientRect();u({width:L.width,height:L.height,clipWidth:r.clientWidth,clipHeight:r.clientHeight,left:L.left,top:L.top})};l();const v=new ResizeObserver(l);return v.observe(r),()=>v.disconnect()},[]),p.useEffect(()=>{D.current||h.width<=0||h.height<=0||(D.current=!0,C(We(I.bounds,h)))},[h,I.bounds]),p.useEffect(()=>{const r=b.current;if(b.current={width:h.width,height:h.height},!r||!D.current||h.width<=0||h.height<=0||h.width>=r.width&&h.height>=r.height||!i)return;const l=I.devices.get(i);l&&C(v=>{const L={width:h.clipWidth,height:h.clipHeight},V=Math.max(0,Math.min(L.width-I.bounds.width*v.k,L.height-I.bounds.height*v.k));return Xt(v,l,L,Math.min(Jt,V))})},[h,i,I]);const q=g.kind==="dragging"?{x:g.x-h.left+12,y:g.y-h.top+12}:{x:0,y:0},ae=O?Zt(O):null,E=p.useRef(null),U=p.useRef(null),ee=p.useRef(null),y=p.useRef(null),z=p.useCallback(()=>{ee.current=null;const r=E.current,l=U.current;if(E.current=null,U.current=null,r){const v=y.current;if(!v)return;C({k:v.transform.k,tx:v.transform.tx+(r.x-v.x),ty:v.transform.ty+(r.y-v.y)});return}l&&C(v=>Ie(v,{x:l.x,y:l.y},v.k*Math.exp(-l.deltaY*Ks)))},[]),B=p.useCallback(()=>{ee.current===null&&(ee.current=requestAnimationFrame(z))},[z]);p.useEffect(()=>()=>{ee.current!==null&&cancelAnimationFrame(ee.current)},[]);const J=r=>{!(r.target===r.currentTarget)&&r.button!==1||r.button!==0&&r.button!==1||(y.current={x:r.clientX,y:r.clientY,transform:j},r.currentTarget.setPointerCapture(r.pointerId),r.preventDefault())},F=r=>{y.current&&(E.current={x:r.clientX,y:r.clientY},B())},ne=r=>{y.current&&(y.current=null,E.current=null,r.currentTarget.hasPointerCapture(r.pointerId)&&r.currentTarget.releasePointerCapture(r.pointerId))},ie=p.useCallback(r=>{if(r.deltaY===0)return;r.preventDefault();const l=r.currentTarget.getBoundingClientRect();U.current={x:r.clientX-l.left,y:r.clientY-l.top,deltaY:r.deltaY},B()},[B]);p.useEffect(()=>{const r=d.current;if(r)return r.addEventListener("wheel",ie,{passive:!1}),()=>r.removeEventListener("wheel",ie)},[ie]);const he=r=>{const l=r.shiftKey?Ue*4:Ue;switch(r.key){case"Escape":if(g.kind!=="pressing"&&g.kind!=="dragging")return;r.preventDefault(),g.kind==="dragging"&&(N.current=!0),$(v=>oe(v,{kind:"cancel"}));return;case"0":r.preventDefault(),K();return;case"+":case"=":r.preventDefault(),C(v=>Ie(v,{x:h.width/2,y:h.height/2},v.k*Ve));return;case"-":case"_":r.preventDefault(),C(v=>Ie(v,{x:h.width/2,y:h.height/2},v.k/Ve));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{r.preventDefault();const v=r.key==="ArrowLeft"?l:r.key==="ArrowRight"?-l:0,L=r.key==="ArrowUp"?l:r.key==="ArrowDown"?-l:0;C(V=>({...V,tx:V.tx+v,ty:V.ty+L}));return}}};return t.jsxs("div",{ref:d,"data-mesh-canvas":"",role:"group","aria-labelledby":M,tabIndex:0,onPointerDown:J,onPointerMove:Y,onPointerUp:Z,onPointerCancel:r=>{g.kind==="dragging"&&(N.current=!0),$(l=>oe(l,{kind:"cancel"})),ne(r)},"data-mesh-gesture":g.kind,"data-glass-well":"clear",onKeyDown:he,onDoubleClick:r=>{r.target===r.currentTarget&&K()},className:H("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:`${j.tx}px ${j.ty}px`}}),t.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${j.tx}px, ${j.ty}px, 0) scale(${j.k})`,transformOrigin:"0 0",width:I.bounds.width,height:I.bounds.height},children:[t.jsx(Gs,{stacks:P,geometry:I}),t.jsx(Ds,{edges:e.edges,geometry:I,selectedDeviceId:i}),t.jsx("ul",{"aria-label":a("ui.mesh.mesh_canvas.networks"),className:"m-0 list-none p-0",children:e.networks.map(r=>{const l=I.networks.get(r.id);return l?t.jsx(Os,{network:r,x:l.x,y:l.y,refused:O?.kind==="refused"&&g.kind==="dragging"&&g.target.kind==="network"&&g.target.networkId===r.id},r.id):null})}),t.jsx("ul",{"aria-label":a("ui.mesh.mesh_canvas.devices"),className:"m-0 list-none p-0",children:e.devices.map(r=>{const l=I.devices.get(r.id);return l?t.jsx(Hs,{device:r,deviceIds:e.devices.map(v=>v.id),x:l.x,y:l.y,nowSeconds:s,selected:r.id===i,sessions:m.get(r.id)??{rows:[],shown:[],hidden:0},sessionTotal:c.get(r.id)??r.sessionCount??0,dropState:x(r.id),movingSessionId:f,draggedSessionId:As(g),onOpen:_,onChipPointerDown:T,onChipClick:()=>{if(N.current){N.current=!1;return}_(r.id)},onShowAllSessions:A},r.id):null})})]}),g.kind==="dragging"&&t.jsx("div",{"data-mesh-ghost":"","aria-hidden":"true",className:"pointer-events-none absolute z-10 max-w-40 truncate rounded-sm border border-ink-dim bg-surface px-1.5 py-0.5 text-meta text-ink",style:{left:q.x,top:q.y},children:g.payload.session.name||"untitled"}),g.kind==="dragging"&&ae&&t.jsx("div",{"data-mesh-indicator":"",className:H("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",O?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:q.x,maxWidth:Math.max(160,h.width-q.x-12),...q.y>h.height*.6?{bottom:Math.max(12,h.height-q.y+8)}:{top:q.y+24}},children:ae})]})};function Zs(e,n,s,i){const m=s.locality==="local"?n:s.owner_device,c=[],f=e.map(o=>o.id);for(const o of e){if(o.id===m)continue;if(o.id===n){c.push({deviceId:o.id,label:i,verb:a("ui.mesh.mesh_card.recall_to_this_device"),keepVerb:a("ui.mesh.mesh_card.copy_here_leave_it_there")});continue}const _=le(o,f,!0);c.push({deviceId:o.id,label:_,verb:a("ui.mesh.mesh_card.move_to",{device:_}),keepVerb:a("ui.mesh.mesh_card.copy_to",{device:_})})}return c}function Js(e,n,s){return Zs(e.devices,e.selfDeviceId,n,s)}function dt(e,n,s){const i=Js(e,n,s),m={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(o=>[o.id,o])),networks:new Map(e.networks.map(o=>[o.id,o]))},c=n.locality==="local"?e.selfDeviceId??"":n.owner_device,f=m.devices.get(c);return i.map(o=>{const _=be({session:n,ownerDeviceId:c,ownerLabel:f?le(f,e.devices.map(k=>k.id),!0):n.owner_device_name},{kind:"device",deviceId:o.deviceId},m);return{...o,refused:_.kind==="refused"&&_.code!=="busy"?_.sentence:null}})}const ct=({session:e,destinations:n,disabled:s,onChoose:i,onOpenChange:m,trigger:c,triggerLabel:f})=>(G(),t.jsxs(yt,{onOpenChange:m,children:[t.jsx(jt,{asChild:!0,children:t.jsx("button",{type:"button","aria-label":f,"data-mesh-session-menu":e.id,disabled:s||n.length===0,className:"rounded-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2 disabled:text-ink-disabled",children:c})}),t.jsxs(wt,{align:"start",className:"min-w-56",children:[t.jsx(Nt,{children:ue(e)}),t.jsx(Pe,{}),n.map(o=>t.jsx($e,{"data-mesh-move-to":o.deviceId,disabled:!!o.refused,title:o.refused??void 0,onSelect:()=>i(o,!1),children:o.verb},o.deviceId)),t.jsx(Pe,{}),n.map(o=>t.jsx($e,{"data-mesh-copy-to":o.deviceId,disabled:!!o.refused,title:o.refused??void 0,onSelect:()=>i(o,!0),children:o.keepVerb},`keep-${o.deviceId}`))]})]})),Qs=({device:e,deviceIds:n,sessions:s,sessionTotal:i,nowSeconds:m,destinationsFor:c,movingSessionId:f,canMove:o,canInvite:_,onClose:k,onMove:S,onShowInList:A,onInvite:M,onRemoveMember:d})=>{G();const h=ce(e),u=Je(e),j=e.reachable?[]:e.attempts??[];p.useEffect(()=>{const b=R=>{R.key!=="Escape"||R.defaultPrevented||R.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),k())};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[e.id,k]);const C=e.sessionCount===null?st(null):a("ui.mesh.mesh_card.conversation_count",{count:e.sessionCount}),D=e.suspect?Qe():[C,ge(h)].filter(Boolean).join(" · "),N=i>s.rows.length?a("ui.mesh.mesh_card.shown_of",{shown:s.rows.length,total:i}):`${s.rows.length}`;return t.jsxs("aside",{"aria-label":a("ui.mesh.mesh_card.device_details",{device:le(e)}),"data-mesh-panel":e.id,"data-glass-block":"",className:"flex w-80 shrink-0 flex-col gap-3 overflow-y-auto rounded-md border border-hairline bg-surface p-4",children:[t.jsxs("header",{className:"flex flex-col gap-1",children:[t.jsx(se,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:k,children:a("ui.mesh.mesh_actions.close")}),t.jsx("h2",{className:"text-body-sm text-ink",children:t.jsx(De,{deviceId:e.id,deviceIds:n,name:e.name,compact:!0})}),t.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[e.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 text-danger"}),!e.suspect&&h==="unanswered"&&t.jsx(kt,{"aria-hidden":"true",className:"size-3.5 text-warning"}),D]})]}),t.jsx(pe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.memberships")}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:e.memberships.map(b=>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(Ae,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),b.networkName]}),t.jsxs("span",{className:"text-meta text-ink-dim",children:[b.role||"member",b.capabilities.length>0?` · ${b.capabilities.join(", ")}`:""]}),_&&t.jsxs(se,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${b.networkId}:${e.id}`,onClick:()=>d(e,b.networkId),children:[a("ui.mesh.mesh_card.remove_from"),b.networkName,"…"]})]},b.networkId))}),_&&t.jsx(se,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":e.id,onClick:()=>M(e),children:a("ui.mesh.mesh_actions.invite_to_a_network")})]}),t.jsx(pe,{}),t.jsxs("section",{className:"flex shrink-0 flex-col gap-2",children:[t.jsxs("h3",{className:"text-meta text-ink-dim",children:[a("ui.mesh.mesh_card.conversations"),t.jsxs("span",{className:"text-ink-disabled",children:["(",ce(e)!=="self"&&ce(e)!=="reached"?nt(null):N,")"]})]}),_e(e,m)?t.jsx("p",{className:"text-meta text-warning",children:_e(e,m)}):s.rows.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:e.sessionCount===null?a("ui.mesh.mesh_card.this_device_did_not_report_its_conversations"):a("ui.mesh.mesh_card.no_conversations_here")}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:s.rows.map(b=>t.jsxs("li",{"data-mesh-panel-session":b.id,className:H("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",f===b.id&&"border-control"),children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",title:ue(b),children:ue(b)}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:ot(b,le(e,n,!0),ce(e))}),f===b.id?t.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:a("ui.mesh.mesh_card.moving")}):t.jsx(ct,{session:b,destinations:c(b),disabled:!o,onChoose:(R,P)=>S(b,R,P),trigger:t.jsx(rt,{"aria-hidden":"true",className:"size-4"}),triggerLabel:a("ui.mesh.mesh_card.move_conversation",{conversation:ue(b)})})]},b.id))})]}),t.jsx(pe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.network_addresses")}),e.endpoints.length===0?t.jsx("p",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.no_address_published")}):t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:e.endpoints.map(b=>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:b}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_card.advertised")})]},b))})]}),t.jsx(pe,{}),t.jsxs("section",{className:"flex flex-col gap-2",children:[t.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.status")}),t.jsxs("dl",{className:"m-0 flex flex-col gap-1",children:[t.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("dt",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.reach")}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:ge(h)})]}),t.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[t.jsx("dt",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.last_status_frame")}),t.jsx("dd",{className:"m-0 text-body-sm text-ink",children:e.lastSeenAt===null?a("ui.mesh.mesh_card.never"):Qt(m-e.lastSeenAt)})]})]}),!e.reachable&&(u!==""||j.length>0)&&t.jsxs("div",{className:"flex flex-col gap-1",children:[u&&t.jsx("p",{className:"m-0 text-meta text-warning",children:u}),e.linkState==="handshake_refused"&&t.jsx("p",{className:"m-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.handshake_refused_hint")}),j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{id:`mesh-attempts-label-${e.id}`,className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.addresses_tried")}),t.jsx("ul",{role:"list","aria-labelledby":`mesh-attempts-label-${e.id}`,className:"m-0 flex list-none flex-col gap-0.5 p-0",children:j.map((b,R)=>{const P=et(b.detail);return t.jsxs("li",{"data-mesh-attempt":b.endpoint,className:"flex items-baseline justify-between gap-2",children:[t.jsx("span",{className:"min-w-0 truncate font-mono text-meta text-ink",children:b.endpoint}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:P})]},`${b.endpoint}:${R}`)})})]})]}),!u&&j.length===0&&e.reason&&t.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),t.jsx(pe,{}),t.jsx(se,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>A(e.id),children:a("ui.mesh.mesh_card.show_in_list")})]})},ea=["name","chats","state"],ta={get name(){return a("ui.mesh.mesh_list.name")},get chats(){return a("ui.mesh.mesh_list.sort_conversations")},get state(){return a("ui.mesh.mesh_list.state")}},Ge={suspect:0,relay_down:1,handshake_refused:2,unreachable:3,self:4,reachable:5};function sa(e,n){const s=[...e];switch(n){case"chats":return s.sort((i,m)=>(m.sessionCount??-1)-(i.sessionCount??-1)||i.label.localeCompare(m.label)),s;case"state":return s.sort((i,m)=>Ge[i.state]-Ge[m.state]||i.label.localeCompare(m.label)),s;default:return s.sort((i,m)=>i.label.localeCompare(m.label))}}const Ke=8;function aa(e,n){if(e.locality==="local")return e.live_state||"here";const s=e.owner_device_name||n,i=e.live_state?` · ${e.live_state}`:"";return e.reachable?a("ui.mesh.mesh_list.on_device_state",{device:s,state:i}):a("ui.mesh.mesh_list.on_device_no_answer",{device:s})}const na=({graph:e,nowSeconds:n,selectedDeviceId:s,sessions:i,selfLabel:m,canMove:c,onSelect:f,onMove:o,onInvite:_,onRemove:k})=>{G();const[S,A]=p.useState("name"),M=p.useMemo(()=>e.networks.map(d=>({network:d,members:sa(e.devices.filter(h=>h.memberships.some(u=>u.networkId===d.id)),S)})),[e,S]);return t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pe-1",children:[t.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[t.jsx("legend",{className:"sr-only",children:a("ui.mesh.mesh_list.sort_devices_by")}),t.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:ea.map(d=>t.jsx("button",{type:"button","aria-pressed":S===d,onClick:()=>A(d),className:H("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",S===d&&"bg-surface text-ink"),children:ta[d]},d))})]}),M.map(({network:d,members:h})=>t.jsxs("section",{"data-mesh-network-group":d.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:a("ui.mesh.mesh_list.epoch",{epoch:d.epoch}),children:[d.label,t.jsxs("span",{className:"text-meta text-ink-dim",children:[d.trust," ·"," ",a("ui.mesh.mesh_graph.device_count",{count:d.memberCount}),d.revokedCount>0?t.jsxs(t.Fragment,{children:[" · ",a("ui.mesh.mesh_list.revoked_count",{count:d.revokedCount})]}):null]})]}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:h.map(u=>{const j=u.memberships.find(w=>w.networkId===d.id),C=u.id===s,D=i.get(u.id),N=D?.rows??[],b=D?it(D,u.sessionCount):u.sessionCount??0,R=ce(u),P=Je(u),I=u.reachable?[]:u.attempts??[];return t.jsxs("li",{"data-mesh-device-row":u.id,"data-mesh-state":u.state,"aria-current":C?"true":void 0,className:H("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",C&&"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":u.id,onClick:()=>f(u.id),className:H("min-w-0 flex-1 text-start text-body-sm text-ink","hover:text-ink-muted","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:t.jsx(De,{deviceId:u.id,name:u.name})}),t.jsxs("span",{className:H("flex shrink-0 items-center gap-1 text-meta",Ze[R]),"data-mesh-reach":R,children:[u.suspect&&t.jsx(Me,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),u.suspect?ge(R):at(u,n),u.suspect&&t.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:Qe()})]}),t.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[j?.role?`${j.role} · `:"",a("ui.mesh.mesh_list.member")]})]}),(P!==""||I.length>0)&&!u.reachable&&t.jsxs("div",{className:"flex flex-col gap-0.5",children:[P&&t.jsx("span",{className:"text-meta text-warning",children:P}),I.map((w,g)=>{const $=et(w.detail);return t.jsx("span",{"data-mesh-attempt":w.endpoint,className:"text-meta text-ink-dim",children:$?`${w.endpoint} — ${$}`:w.endpoint},`${w.endpoint}:${g}`)})]}),_e(u,n)?t.jsxs("span",{className:"text-meta text-warning",children:[a("ui.mesh.mesh_card.conversations")," (",nt(null),") ·"," ",_e(u,n)]}):N.length>0?t.jsxs(t.Fragment,{children:[t.jsx(pe,{className:"my-1"}),t.jsx("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:N.slice(0,Ke).map(w=>t.jsxs("li",{"data-mesh-row-session":w.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:w.name||w.id}),t.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:aa(w,m)}),t.jsx(ct,{session:w,destinations:dt(e,w,m),disabled:!c,onChoose:(g,$)=>o(w,g,$),trigger:t.jsx(rt,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:a("ui.mesh.mesh_list.move_conversation",{conversation:w.name||w.id})})]},w.id))}),b>N.slice(0,Ke).length&&t.jsx("button",{type:"button",onClick:()=>f(u.id),className:"w-fit text-meta text-ink-dim hover:text-ink",children:a("ui.mesh.mesh_list.show_all_panel",{count:b})})]}):t.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_list.conversation_count",{count:b})}),(j||u.state!=="self")&&t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(se,{size:"sm",variant:"ghost","data-mesh-invite":u.id,onClick:()=>_({deviceId:u.id,deviceName:u.name}),children:a("ui.mesh.mesh_actions.invite_to_a_network")}),j&&t.jsxs(se,{size:"sm",variant:"ghost","data-mesh-remove-member":`${d.id}:${u.id}`,onClick:()=>k({networkId:d.id,networkLabel:d.label,deviceId:u.id,deviceName:u.name}),children:[a("ui.mesh.mesh_card.remove_from"),d.label,"…"]})]})]},u.id)})})]},d.id)),e.unmatchedPeers.length>0&&t.jsxs("p",{className:"text-meta text-warning",children:[a("ui.mesh.mesh_graph.device_count",{count:e.unmatchedPeers.length})," ",a("ui.mesh.mesh_list.answered_the_peer_read_but_is_in")]})]})},ia=({revoked:e})=>{if(e.length===0)return null;const n=a("ui.mesh.mesh_list.revoked_count",{count:e.length});return t.jsx(ke,{className:"contents",chevron:"trailing",chevronClassName:"text-ink-dim",rowClassName:"min-h-auto py-0",triggerClassName:"inline-flex w-auto items-center gap-1 align-baseline text-meta text-ink-dim hover:text-ink",triggerData:{"data-mesh-revoked-toggle":""},triggerLabel:a("ui.mesh.mesh_list.revoked_toggle_label"),summary:t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",className:"inline-block whitespace-pre",children:" · "}),n]}),children:t.jsx("ul",{"data-mesh-revoked":"",className:"m-0 flex list-none flex-col gap-1 p-0",children:e.map(s=>t.jsxs("li",{"data-mesh-revoked-member":s.deviceId,className:"flex flex-wrap items-baseline gap-x-2 text-meta text-ink-dim",children:[t.jsx("span",{children:s.networkName}),t.jsx("span",{className:"font-mono text-body-sm text-ink",children:s.deviceId}),t.jsx("span",{className:"text-body-sm text-ink-muted",children:s.label}),t.jsxs("span",{children:[s.role?`${s.role} · `:"",a("ui.mesh.mesh_graph.revoked_membership")]})]},`${s.networkId}:${s.deviceId}`))})})},ra=["canvas","list"],la={get canvas(){return a("ui.mesh.mesh_page.canvas")},get list(){return a("ui.mesh.mesh_page.list")}},oa=({state:e,initialPresentation:n="canvas",graph:s,nowSeconds:i,checking:m,staleError:c,onRetry:f,approvals:o,sessions:_,sessionError:k,selfLabel:S,movingSessionId:A,canMove:M,pendingMove:d,onAskMove:h,onDropRefused:u,onChooseMove:j,onCancelMove:C,moveBusy:D,moveReport:N,onDismissReport:b,onWaitForIdle:R,onUndoCopy:P,invite:I,onOpenInvite:w,onInvite:g,onCloseInvite:$,inviteBusy:Q,inviteReceipt:W,inviteRefusal:O,remove:x,onOpenRemove:T,onRemove:Y,onCloseRemove:Z,removeBusy:K,removeRefusal:q,removed:ae})=>{G();const[E,U]=p.useState(n),[ee,y]=p.useState(null),z=s?es(s):"",B="mesh-summary",J=ts(s),F=ss(s,_,s?.selfDeviceId??null),ne=p.useMemo(()=>{const l=new Map;for(const v of s?.devices??[]){const L=F.byDevice.get(v.id);l.set(v.id,L?it(L,v.sessionCount):v.sessionCount??0)}return l},[s,F]),ie=p.useCallback(l=>{y(l)},[]),he=s?s.devices.find(l=>l.id===ee)??null:null,r=p.useCallback((l,v,L)=>{if(!s)return null;const V={selfDeviceId:s.selfDeviceId,devices:new Map(s.devices.map(te=>[te.id,te])),networks:new Map(s.networks.map(te=>[te.id,te]))},re=l.locality==="local"?s.selfDeviceId??"":l.owner_device,Re=V.devices.get(re),X=be({session:l,ownerDeviceId:re,ownerLabel:Re?le(Re,s.devices.map(te=>te.id),!0):l.owner_device_name},{kind:"device",deviceId:v.deviceId},V);if(X.kind==="refused")return u({code:X.code,sentence:X.sentence,reach:X.reach,remedy:X.remedy,plan:X.plan??null}),null;if(X.kind==="none")return null;const Ee=L?X.alternatives.find(te=>te.keep)??X.plan:X.plan,mt=[X.plan,...X.alternatives].filter(te=>te.keep!==Ee.keep),ut={plan:Ee,alternatives:mt,risky:X.risky};h(ut)},[s,h,u]);return t.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[t.jsx(bt,{title:a("ui.mesh.mesh_page.mesh"),icon:Ae,subtitle:a("ui.mesh.mesh_page.devices_this_app_is_paired_with_and"),children:t.jsxs("div",{className:"flex items-center gap-4",children:[m&&t.jsx("output",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_page.checking")}),(e.kind==="ready"||e.kind==="loading")&&t.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[t.jsx("legend",{className:"sr-only",children:a("ui.mesh.mesh_page.presentation")}),t.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:ra.map(l=>t.jsx("button",{type:"button","data-mesh-presentation":l,"aria-pressed":E===l,disabled:e.kind!=="ready",onClick:()=>U(l),className:H("h-6 rounded-sm px-3 text-body-sm text-ink-muted transition-colors duration-fast ease-out-quart","hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2","disabled:text-ink-dim disabled:hover:text-ink-dim",E===l&&"bg-surface text-ink"),children:la[l]},l))})]})]})}),t.jsx(Ss,{rows:o.rows,error:o.error,pending:o.pending,refusal:o.decisionRefusal,onDecide:o.onDecide,onRetry:o.onRetry,nowSeconds:o.nowSeconds,credentialApprovals:o.credentialApprovals,profileApprovals:o.profileApprovals,networkNames:new Map((s?.networks??[]).map(l=>[l.id,l.label]))}),e.kind==="loading"&&t.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[t.jsx(Le,{className:"h-4 w-64"}),t.jsx(Le,{className:"min-h-40 w-full flex-1"})]}),e.kind==="error"&&t.jsxs(we,{variant:"warning",className:"flex-col items-start gap-2",children:[t.jsx("p",{children:e.message}),t.jsx(se,{variant:"secondary",size:"sm",onClick:f,className:"w-fit",children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),e.kind==="empty"&&t.jsx("div",{"data-glass-block":"",className:"flex min-h-0 flex-1 items-center justify-center rounded-lg border border-hairline bg-surface p-6",children:t.jsxs("div",{className:"flex flex-col items-start gap-3",children:[t.jsx("h2",{className:"text-heading text-ink",children:a("ui.mesh.mesh_page.no_network_on_this_device")}),t.jsx("p",{className:"max-w-140 text-body-sm text-ink-muted",children:a("ui.mesh.mesh_page.this_device_is_not_in_any_network")}),t.jsx("code",{className:"rounded-sm bg-sunken px-2 py-1 font-mono text-meta text-ink",children:"lop network init <name>"}),t.jsx("p",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_page.a_network_appears_here_once_this_device")})]})}),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.jsxs("div",{id:B,className:"text-meta text-ink-muted","data-mesh-summary":"",children:[t.jsx("span",{children:z}),t.jsx(ia,{revoked:s.revoked})]}),c&&t.jsx(we,{variant:"warning",children:t.jsx("p",{children:c})}),k&&t.jsx(we,{variant:"warning",children:t.jsx("p",{children:k})}),N&&t.jsx(as,{receipt:N.kind==="moved"?{verb:N.verb,detail:N.detail,undo:N.undo}:null,refusal:N.kind==="refused"?N.refusal:null,canWait:N.kind==="refused"&&N.plan!==null,onWait:R,onRecheck:f,onUndo:P,onDismiss:b,pending:D}),E==="canvas"?t.jsx(Xs,{graph:s,slots:J,nowSeconds:i,selectedDeviceId:ee,sessions:F.byDevice,sessionTotals:ne,movingSessionId:A,canMove:M,onOpenDevice:ie,onAskMove:h,onDropRefused:u,onShowAllSessions:ie,summaryId:B}):t.jsx(na,{graph:s,nowSeconds:i,selectedDeviceId:ee,sessions:F.byDevice,selfLabel:S,canMove:M,onSelect:ie,onMove:r,onInvite:w,onRemove:T})]}),he&&t.jsx(Qs,{device:he,deviceIds:s.devices.map(l=>l.id),sessions:F.byDevice.get(he.id)??{rows:[],shown:[],hidden:0},sessionTotal:ne.get(he.id)??0,nowSeconds:i,canMove:M,canInvite:e.kind==="ready",movingSessionId:A,destinationsFor:l=>dt(s,l,S),onClose:()=>y(null),onMove:r,onInvite:l=>w({deviceId:l.id,deviceName:l.name}),onRemoveMember:(l,v)=>{const L=s.networks.find(V=>V.id===v);T({networkId:v,networkLabel:L?.label??v,deviceId:l.id,deviceName:l.name})},onShowInList:l=>{ie(l),U("list")}})]})}),t.jsx(ns,{open:d!==null,plan:d?.plan??da,alternatives:d?.alternatives??[],risky:d?.risky??!1,busy:D,onCancel:C,onChoose:j}),I&&t.jsx(is,{open:I.open,options:I.options,deviceId:I.deviceId,deviceName:I.deviceName,onClose:$,onInvite:g,pending:Q,receipt:W,refusal:O}),x&&t.jsx(rs,{open:x.open,networkLabel:x.networkLabel,deviceId:x.deviceId,deviceName:x.deviceName,onClose:Z,onConfirm:Y,pending:K,refusal:q,removed:ae})]})},da={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},_a=({initialPresentation:e})=>{G();const n=gt(),s=xe(n.data,"peers")==="enabled",i=xe(n.data,"session_transfer")==="enabled",m=ls(s,{stamp:()=>je.getState().beginAnswer()}),c=os(s),f=ds(s,{poll:!1,stamp:()=>je.getState().beginAnswer()}),o=p.useMemo(()=>({peers:m,networks:c}),[m,c]),_=cs(o),k=ms(o),S=us(),A=xe(n.data,"approvals")==="enabled",M=hs(s&&A,{poll:!1}),d=ps(),h=xe(n.data,"credential_approvals")==="enabled",u=xe(n.data,"profile_approvals")==="enabled",j=d.isError?{approvalId:d.variables?.approvalId??null,submittedAt:d.submittedAt,...xs(d.error)}:null,C=p.useMemo(()=>Math.floor((M.dataUpdatedAt||Date.now())/1e3),[M.dataUpdatedAt]),D=je(y=>y.settlePlacement),N=fs(),b=gs(),[R,P]=p.useState(null),[I,w]=p.useState(null),[g,$]=p.useState(null),[Q,W]=p.useState(null),[O,x]=p.useState(null),[T,Y]=p.useState(null),[Z,K]=p.useState(null),q=p.useMemo(()=>{const y=Math.max(m.dataUpdatedAt,c.dataUpdatedAt);return Math.floor((y||Date.now())/1e3)},[m.dataUpdatedAt,c.dataUpdatedAt]),ae=p.useCallback(()=>{m.refetch(),c.refetch(),f.refetch()},[m,c,f]),E=p.useCallback((y,z)=>{P(null);const B={sessionId:y.sessionId,to:y.to,keep:y.keep,waitS:z??y.waitS};S.mutate(B,{onSuccess:J=>{if(J.kind==="moved"){const{receipt:F}=J;D(y.sessionId,F);const ne=F.locality==="local"?a("ui.mesh.mesh_drop.this_device"):k?.devices.find(ie=>ie.id===F.owner_device)?.label??F.owner_device;w({kind:"moved",verb:F.mode==="keep"?a("ui.mesh.mesh_page.copied"):a("ui.mesh.mesh_page.moved"),detail:F.mode==="keep"?a("ui.mesh.mesh_page.copy_receipt",{destination:ne,suffix:F.new_session_id.slice(-6)}):a("ui.mesh.mesh_page.move_receipt",{destination:ne,retirement:F.source_retired?a("ui.mesh.mesh_page.the_copy_here_is_gone"):""}),undo:F.mode==="keep"?{sessionId:F.new_session_id,to:"local",keep:!1,verb:a("ui.mesh.mesh_page.bring_copy_back",{device:ne}),waitS:0,lost:vs(ne,a("ui.mesh.mesh_drop.this_device"))}:null});return}w({kind:"refused",refusal:J.refusal,plan:y})},onError:()=>{w({kind:"refused",refusal:{code:"move_failed",sentence:a("ui.mesh.mesh_page.the_move_could_not_be_sent_nothing"),status:null,unconfirmed:!1},plan:y})}})},[k,S,D]),U=p.useMemo(()=>{if(!k)return[];const y=g?.deviceId,z=y?k.devices.find(B=>B.id===y):void 0;return k.networks.filter(B=>z?!z.memberships.some(J=>J.networkId===B.id):!0).map(B=>({id:B.id,label:B.label}))},[k,g]);if(!s)return t.jsx(vt,{to:"/chat",replace:!0});const ee=_.kind==="ready"?m.error?fe(m.error):c.error?fe(c.error):null:null;return t.jsx(oa,{initialPresentation:e,state:_,graph:k,nowSeconds:q,checking:m.isFetching||c.isFetching,staleError:ee,onRetry:ae,approvals:{rows:M.data??[],error:M.isError?bs(M.error):null,pending:d.isPending?d.variables??null:null,decisionRefusal:j,credentialApprovals:h,profileApprovals:u,onDecide:(y,z)=>{const B=M.data?.find(F=>F.approvalId===y),J=B?_s(B,z,{credentialApprovals:h,profileApprovals:u},j?.approvalId===y?j.retryable:void 0):null;J&&d.mutate({approvalId:y,decision:z,request:J})},onRetry:()=>void M.refetch(),nowSeconds:C},sessions:f.data?.rows??[],movingSessionId:S.isPending?S.variables?.sessionId??null:null,sessionError:f.isError?fe(f.error):null,selfLabel:k?.devices.find(y=>y.state==="self")?.label??a("ui.mesh.mesh_drop.this_device"),canMove:i,pendingMove:R,onAskMove:P,onDropRefused:y=>w({kind:"refused",refusal:{code:y.code,sentence:y.sentence,reach:y.reach,status:null,unconfirmed:!1},plan:y.plan}),onChooseMove:y=>E(y),onCancelMove:()=>P(null),moveBusy:S.isPending,moveReport:I,onDismissReport:()=>w(null),onWaitForIdle:()=>{I?.kind!=="refused"||!I.plan||E(I.plan,ca)},onUndoCopy:()=>{I?.kind!=="moved"||!I.undo||P({plan:I.undo,alternatives:[],risky:!1})},invite:g===null?null:{open:!0,deviceId:g.deviceId,deviceName:g.deviceName,options:U},onOpenInvite:y=>{W(null),x(null),$(y)},onInvite:y=>{N.mutate(y,{onSuccess:z=>W(z),onError:z=>x({code:"invite_refused",sentence:fe(z),status:null,unconfirmed:!1})})},onCloseInvite:()=>$(null),inviteBusy:N.isPending,inviteReceipt:Q,inviteRefusal:O,remove:T===null?null:{open:!0,networkId:T.networkId,networkLabel:T.networkLabel,deviceId:T.deviceId,deviceName:T.deviceName},onOpenRemove:y=>{K(null),Y(y)},onRemove:y=>{T&&b.mutate({networkId:T.networkId,deviceId:T.deviceId,confirm:y},{onSuccess:z=>K(z)})},onCloseRemove:()=>Y(null),removeBusy:b.isPending,removeRefusal:b.isError?{code:"remove_refused",sentence:fe(b.error),status:null,unconfirmed:!1}:null,removed:Z})},ca=300;export{_a as MeshPage,oa as MeshSurface,_a as default};