local-operator-ui 0.31.19 → 0.31.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/main/index.js +225 -119
- package/out/preload/index.js +0 -11
- package/out/renderer/assets/{_basePickBy-BjXXwW6E.js → _basePickBy-Zhw1A9vv.js} +1 -1
- package/out/renderer/assets/{_baseUniq-xIg3idQF.js → _baseUniq-CKugqUpl.js} +1 -1
- package/out/renderer/assets/{agent-details-page-D2QdVqJp.js → agent-details-page-B9z7id-t.js} +1 -1
- package/out/renderer/assets/{agent-hub-page-BitfELv8.js → agent-hub-page-B152l61i.js} +1 -1
- package/out/renderer/assets/{agents-page-Cl1j7rwO.js → agents-page-oukP9zNZ.js} +2 -2
- package/out/renderer/assets/{aida-control-BqbEHtVs.js → aida-control-DVTI-DZP.js} +1 -1
- package/out/renderer/assets/{arc-Ceouzeia.js → arc-Tsm4QoKk.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-IEHRJDOE-BGSLJh-o.js → architectureDiagram-IEHRJDOE-CMjwNRUR.js} +1 -1
- package/out/renderer/assets/{blockDiagram-JOT3LUYC-BmQJgCM-.js → blockDiagram-JOT3LUYC-DTJthkeu.js} +1 -1
- package/out/renderer/assets/{book-open-tLP18D-k.js → book-open-BWKY7M9P.js} +1 -1
- package/out/renderer/assets/browser-page-CGOSNZc9.js +1 -0
- package/out/renderer/assets/{browser-webauthn-prompt-k5jzjWeZ.js → browser-webauthn-prompt-PdNx9Oqz.js} +1 -1
- package/out/renderer/assets/{c4Diagram-VJAJSXHY-Yk9CQYyQ.js → c4Diagram-VJAJSXHY-VsUZ4bEe.js} +1 -1
- package/out/renderer/assets/channel-BfF7Hl0z.js +1 -0
- package/out/renderer/assets/{chunk-4BMEZGHF-DizR_fDb.js → chunk-4BMEZGHF-BPF1k4F2.js} +1 -1
- package/out/renderer/assets/{chunk-A2AXSNBT-BtTz6zUt.js → chunk-A2AXSNBT-CRnYQofd.js} +1 -1
- package/out/renderer/assets/{chunk-AEK57VVT-D1a4VfuY.js → chunk-AEK57VVT-CSuBzhGu.js} +1 -1
- package/out/renderer/assets/{chunk-D6G4REZN-bed23kTE.js → chunk-D6G4REZN-DjYQJlYy.js} +1 -1
- package/out/renderer/assets/{chunk-RZ5BOZE2-KfGYL-ag.js → chunk-RZ5BOZE2-hD7OnoEc.js} +1 -1
- package/out/renderer/assets/{chunk-XZIHB7SX-B1igQQgc.js → chunk-XZIHB7SX-C7vHPsrP.js} +1 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-DumIl0Dw.js +1 -0
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-DumIl0Dw.js +1 -0
- package/out/renderer/assets/clone-JPx4tzv5.js +1 -0
- package/out/renderer/assets/{console-mirror-CqlxE8VR.js → console-mirror-CG9RcMIb.js} +1 -1
- package/out/renderer/assets/{consoleCapture-Bgq6O6hd.js → consoleCapture-CpTo2RAv.js} +1 -1
- package/out/renderer/assets/{dagre-OKDRZEBW-BlwfTwwA.js → dagre-OKDRZEBW-BUFW-oLD.js} +1 -1
- package/out/renderer/assets/{diagram-SSKATNLV-jsDlGkgc.js → diagram-SSKATNLV-B5BTfBOJ.js} +1 -1
- package/out/renderer/assets/{diagram-VNBRO52H-DP8qnarm.js → diagram-VNBRO52H-DEhJtMfk.js} +1 -1
- package/out/renderer/assets/{erDiagram-Q7BY3M3F-Tc8DPglp.js → erDiagram-Q7BY3M3F-jA5a5rTH.js} +1 -1
- package/out/renderer/assets/{error-boundary-X9vF0zez.js → error-boundary-DVk48CIF.js} +1 -1
- package/out/renderer/assets/{flowDiagram-4HSFHLVR-C0iWuz_e.js → flowDiagram-4HSFHLVR-BtOAhdxy.js} +1 -1
- package/out/renderer/assets/{ganttDiagram-APWFNJXF-CXzAhOwO.js → ganttDiagram-APWFNJXF-Bnb-ky5F.js} +1 -1
- package/out/renderer/assets/{gitGraphDiagram-7IBYFJ6S-c3OKkh69.js → gitGraphDiagram-7IBYFJ6S-BmlKDZ8c.js} +1 -1
- package/out/renderer/assets/{graph-BNpclJqw.js → graph-kRpVwnR5.js} +1 -1
- package/out/renderer/assets/{index-D4_JjH_R.js → index-CB738EdW.js} +1 -1
- package/out/renderer/assets/{index-BgDCWTEy.js → index-Dq95EP_0.js} +1 -1
- package/out/renderer/assets/index-FjyWTJXV.css +1 -0
- package/out/renderer/assets/{index-BsveCKct.js → index-NVdUA6ab.js} +381 -376
- package/out/renderer/assets/infoDiagram-PH2N3AL5-B2wdu6t1.js +2 -0
- package/out/renderer/assets/{installer-Durl4Nt6.js → installer-BgW1Tkr8.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-U35MCT3I-DdWl9wJG.js → journeyDiagram-U35MCT3I-B3PfEJQg.js} +1 -1
- package/out/renderer/assets/{kanban-definition-NDS4AKOZ-D6rkiZvG.js → kanban-definition-NDS4AKOZ-CsXkpaMh.js} +1 -1
- package/out/renderer/assets/{layout-BQqWsgv9.js → layout-Bi30CWUZ.js} +1 -1
- package/out/renderer/assets/{legacy-agents-page-xSUV6wUg.js → legacy-agents-page-CXrEJpIR.js} +1 -1
- package/out/renderer/assets/{mermaid.core-DLc2GDBk.js → mermaid.core-DZ2ArDvy.js} +5 -5
- package/out/renderer/assets/{mesh-page-D1Hn61zc.js → mesh-page-4ltLSofD.js} +1 -1
- package/out/renderer/assets/{mindmap-definition-ALO5MXBD-BPp31SFM.js → mindmap-definition-ALO5MXBD-Dsk8wxvZ.js} +1 -1
- package/out/renderer/assets/{mini-dIYd4lBf.js → mini-D1QQjR0V.js} +1 -1
- package/out/renderer/assets/{org-surface-gate-CQZDYvz1.js → org-surface-gate-DLFy-TFQ.js} +1 -1
- package/out/renderer/assets/{page-header-Ct_E4hXM.js → page-header-B3RA2AMB.js} +1 -1
- package/out/renderer/assets/{pieDiagram-IB7DONF6-InajJAb7.js → pieDiagram-IB7DONF6-DCNiDxv9.js} +1 -1
- package/out/renderer/assets/{projects-page-Cq4-43oz.js → projects-page-XFuffJqs.js} +1 -1
- package/out/renderer/assets/{quadrantDiagram-7GDLP6J5-DllpcIGZ.js → quadrantDiagram-7GDLP6J5-Dh3JI18Y.js} +1 -1
- package/out/renderer/assets/{radar-MK3ICKWK-o49sXvJd.js → radar-MK3ICKWK-BejqW4lD.js} +1 -1
- package/out/renderer/assets/{radient-auth-buttons-DCKuV_IZ.js → radient-auth-buttons-1NHl0Yg_.js} +1 -1
- package/out/renderer/assets/{requirementDiagram-KVF5MWMF-DEB_P2Er.js → requirementDiagram-KVF5MWMF-DBxc-ygO.js} +1 -1
- package/out/renderer/assets/{sankeyDiagram-QLVOVGJD-1sqsEoj5.js → sankeyDiagram-QLVOVGJD-Bw1A9gfs.js} +1 -1
- package/out/renderer/assets/{schedules-page-D6uKCgBE.js → schedules-page-B9N9G1_d.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-X6HHIX6F-DBKLSCMO.js → sequenceDiagram-X6HHIX6F-2oIXuc4E.js} +1 -1
- package/out/renderer/assets/{settings-page-DuO8dHwe.js → settings-page-Dbkkxdut.js} +1 -1
- package/out/renderer/assets/{settings-section-yg8wX_kN.js → settings-section-D3WEX0WK.js} +1 -1
- package/out/renderer/assets/{stateDiagram-DGXRK772-CirIxYQ4.js → stateDiagram-DGXRK772-Bp0p7RkX.js} +1 -1
- package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-82koWMp5.js +1 -0
- package/out/renderer/assets/{textarea-CPyoWJfR.js → textarea-BX6EeK34.js} +1 -1
- package/out/renderer/assets/{timeline-definition-BDJGKUSR-HxrDshvA.js → timeline-definition-BDJGKUSR-DywM5xU1.js} +1 -1
- package/out/renderer/assets/{ui-preferences-store-CyKvDymq.js → ui-preferences-store-DjUQd2R7.js} +1 -1
- package/out/renderer/assets/{use-download-agent-mutation-CJP2OhpP.js → use-download-agent-mutation-CMfq8GnB.js} +1 -1
- package/out/renderer/assets/{use-memberships-query-Q96GogTV.js → use-memberships-query-BYC7TJ2S.js} +1 -1
- package/out/renderer/assets/{xychartDiagram-VJFVF3MP-BXsPMfju.js → xychartDiagram-VJFVF3MP-CVi-fDV_.js} +1 -1
- package/out/renderer/console-capture.html +5 -5
- package/out/renderer/index.html +8 -8
- package/out/renderer/installer.html +5 -5
- package/out/renderer/mini.html +6 -6
- package/package.json +2 -2
- package/out/renderer/assets/browser-page-ChmnhnuO.js +0 -1
- package/out/renderer/assets/channel-CoXp_5DQ.js +0 -1
- package/out/renderer/assets/classDiagram-GIVACNV2-DLxyNS1q.js +0 -1
- package/out/renderer/assets/classDiagram-v2-COTLJTTW-DLxyNS1q.js +0 -1
- package/out/renderer/assets/clone-1ZAhWRhd.js +0 -1
- package/out/renderer/assets/index-R0cHU6YS.css +0 -1
- package/out/renderer/assets/infoDiagram-PH2N3AL5-C6rpQuUJ.js +0 -2
- package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-BektpfMe.js +0 -1
- /package/out/renderer/assets/{index-C17iOszj.js → index-VKe88JN9.js} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as e,r as c,c as _}from"./index-C17iOszj.js";import{u as Je,I as Ie}from"./aida-control-BqbEHtVs.js";import{P as Qe}from"./page-header-Ct_E4hXM.js";import{j as et,B as $,D as pe,l as be,m as ke,n as ve,o as ge,A as ee,p as we,L as fe,q as Ce,r as Se,s as De,t as Me,u as $e,I as tt,T as nt,b as oe,g as st,v as it,w as at,x as rt,y as lt,z as _e,E as Re,f as Te}from"./textarea-CPyoWJfR.js";import{al as ot,am as dt,an as ct,ao as je,ap as ut,aq as ht,ar as mt,as as He,at as ye,au as ue,av as xt,aw as ft,ax as pt,ay as Be,az as bt,aA as kt,aB as Ee,aC as vt,aD as me,aE as gt,aF as wt,aG as Ye,aH as Ve,aI as jt,aJ as yt,aK as Nt,aL as It,aM as Ct,aN as St,aO as Dt,aP as Mt,aQ as $t,aR as _t,aS as Rt,aT as Tt,aU as ae}from"./index-BsveCKct.js";import"./ui-preferences-store-CyKvDymq.js";import"./error-boundary-X9vF0zez.js";import"./console-mirror-CqlxE8VR.js";function xe(t){return t.live_state.trim().toLowerCase()==="attached"}function Et(t,n){return t.keep||!t.lost?null:{body:t.lost,confirmLabel:t.to==="local"?"Recall it":"Move it",risky:n}}function re(t,n){return`The copy on ${t} is deleted once ${n} has it.`}function Le(t,n){return`${t.name||"This conversation"} is running ${n} right now.`}function Ae(t,n){return t?.label||n.slice(-6)}function Lt(t,n){return t.suspect?{kind:"refused",code:"suspect_device",sentence:`${t.label} has a duplicated key${t.reason?` (${t.reason})`:""}, so nothing is moved to it until that is resolved.`,remedy:{kind:"open",label:"See this device",deviceId:n}}:t.memberships.every(l=>!l.active)?{kind:"refused",code:"revoked_membership",sentence:`${t.label} is no longer a member of any network this device shares.`,remedy:{kind:"open",label:"See this device",deviceId:n}}:t.reachable?null:{kind:"refused",code:"unreachable",sentence:`${t.label} is not answering${t.reason?` (${t.reason})`:""}, so nothing was moved.`,remedy:{kind:"resume",label:"Check again"}}}function de(t,n,l){const{session:a,ownerDeviceId:d,ownerLabel:u}=t,{selfDeviceId:m,devices:o,networks:k}=l;if(n.kind==="ground")return{kind:"none"};if(n.kind==="network")return{kind:"refused",code:"not_a_device",sentence:`A conversation lives on a device. ${k.get(n.networkId)?.label??"A network"} holds devices, not conversations.`,remedy:null};if(ot(a))return{kind:"refused",code:"busy",sentence:`${a.name||"This conversation"} has a turn in flight, so it is not moved — the refusal changes nothing.`,remedy:{kind:"wait",label:"Wait for the turn to finish",waitS:300},plan:{sessionId:a.id,to:n.deviceId===m?"local":n.deviceId,keep:!1,verb:n.deviceId===m?"Recall to this device":`Move to ${Ae(o.get(n.deviceId),n.deviceId)}`,waitS:0,lost:null}};if(d===n.deviceId)return{kind:"none"};const N=o.get(n.deviceId),g=N?Lt(N,n.deviceId):{code:"unknown_device",sentence:"That device is no longer in any network this tab can read.",remedy:null};if(g)return{kind:"refused",...g};const j=Ae(N,n.deviceId);if(!(a.locality==="local")){const r=o.get(d);if(r&&!r.reachable)return{kind:"refused",code:"unreachable",sentence:`${u} is not answering${r.reason?` (${r.reason})`:""}, so it could not hand this conversation over.`,remedy:{kind:"resume",label:"Check again"}};if(n.deviceId!==m)return{kind:"refused",code:"third_device",sentence:`This conversation is on ${u}. It has to travel through this device: recall it here first.`,remedy:null}}if(n.deviceId===m){const r={sessionId:a.id,to:"local",keep:!1,verb:"Recall to this device",waitS:0,lost:xe(a)?`${Le(a,`on ${u}`)} ${re(u,"this device")}`:re(u,"this device")};return{kind:"plan",plan:r,risky:xe(a),alternatives:[{...r,keep:!0,verb:"Copy here, leave it there",lost:null}]}}if(a.locality==="local"&&n.deviceId===d)return{kind:"none"};const x=xe(a),f={sessionId:a.id,to:n.deviceId,keep:!1,verb:`Move to ${j}`,waitS:0,lost:x?`${Le(a,"on this device")} ${re("this device",j)}`:re("this device",j)};return{kind:"plan",plan:f,risky:x,alternatives:[{...f,keep:!0,verb:`Copy to ${j}`,lost:null}]}}function At(t){return t.kind==="refused"?`Drop will be refused: ${t.sentence}`:t.kind==="plan"?t.plan.verb:null}const Pt=({open:t,plan:n,alternatives:l,risky:a,busy:d,onCancel:u,onChoose:m})=>{const o=Et(n,a),[k,N]=c.useState(n);c.useEffect(()=>{t&&N(n)},[t,n]);const g=l.some(I=>I.keep===k.keep)?k:n,j=g.keep;return e.jsx(pe,{open:t,onOpenChange:I=>!I&&u(),children:e.jsxs(be,{className:"max-w-md",children:[e.jsxs(ke,{children:[e.jsx(ve,{children:g.verb}),e.jsx(ge,{children:j?`A copy is made on the destination with a new id, and ${g.to==="local"?"the other device keeps":"this device keeps"} its own. The copy can be erased again from the session list.`:o?.body??"This moves the conversation."})]}),l.length>0&&e.jsxs("fieldset",{className:"m-0 flex flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"sr-only",children:"Which operation"}),[n,...l].map(I=>e.jsxs("label",{className:_("flex cursor-pointer items-start gap-2 rounded-md border border-control px-3 py-2","hover:bg-row-hover",g.keep===I.keep&&"border-ink bg-row-selected"),children:[e.jsx("input",{type:"radio",name:"mesh-move-mode",className:"mt-1",checked:g.keep===I.keep,onChange:()=>N(I)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-2 text-body-sm text-ink",children:[I.keep?e.jsx(dt,{"aria-hidden":"true",className:"size-3.5"}):e.jsx(ct,{"aria-hidden":"true",className:"size-3.5"}),I.verb]}),e.jsx("span",{className:"mt-0.5 block text-meta text-ink-dim",children:I.keep?"the original stays where it is":"the copy here is deleted once it arrives"})]})]},I.keep?"copy":"move"))]}),a&&e.jsx(ee,{variant:"warning",className:"text-meta",children:g.keep?"It is open on the other end, and the copy does not interrupt it.":"It is open elsewhere right now: whatever that runtime is holding is not carried across."}),e.jsxs(we,{children:[e.jsx($,{variant:"ghost",onClick:u,disabled:d,children:"Cancel"}),e.jsxs($,{onClick:()=>m(g),disabled:d,variant:j?"secondary":"primary",children:[d&&e.jsx(je,{"aria-hidden":"true",className:"mr-2 size-3.5 animate-spin"}),g.verb]})]})]})})},zt=({open:t,options:n,deviceLabel:l,onClose:a,onInvite:d,pending:u,receipt:m,refusal:o,deviceId:k})=>{const[N,g]=c.useState("drive"),[j,I]=c.useState(null),x=n.find(b=>b.id===j)?.id??n[0]?.id??null,f=c.useId(),r=c.useId();return e.jsx(pe,{open:t,onOpenChange:b=>!b&&a(),children:e.jsxs(be,{className:"max-w-md",children:[e.jsxs(ke,{children:[e.jsx(ve,{children:"Invite to a network…"}),e.jsxs(ge,{children:["Admission is two-sided, so this mints a single-use token instead of adding anything: ",l??"the device"," proves the short authentication string when it redeems the token, and only then does it appear as a member."]})]}),m?e.jsxs("div",{className:"flex flex-col gap-2 rounded-md border border-control bg-sunken px-3 py-2",children:[e.jsx("span",{className:"text-body-sm text-ink",children:"Invited — the device appears once it redeems this."}),e.jsx("span",{className:"text-meta text-ink-dim",children:"The token was written here, and this app never reads it:"}),e.jsx("code",{className:"break-words font-mono text-meta text-ink",children:m.token_path?e.jsx(Wt,{path:m.token_path}):"(the route did not name a path)"})]}):e.jsxs("div",{className:"flex flex-col gap-1",children:[n.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{htmlFor:r,children:"Network to invite it to"}),e.jsxs(Ce,{value:x??void 0,onValueChange:b=>I(b),children:[e.jsx(Se,{id:r,className:"w-56",children:e.jsx(De,{})}),e.jsx(Me,{children:n.map(b=>e.jsx($e,{value:b.id,children:b.label},b.id))})]})]}),n.length===1&&e.jsxs("span",{className:"text-meta text-ink-dim",children:["Inviting to ",n[0]?.label]}),e.jsx(fe,{htmlFor:f,children:"Role the device will have"}),e.jsxs(Ce,{value:N,onValueChange:b=>g(b),children:[e.jsx(Se,{id:f,className:"w-48",children:e.jsx(De,{})}),e.jsx(Me,{children:ut.map(b=>e.jsx($e,{value:b,children:b},b))})]}),e.jsx("span",{className:"text-meta text-ink-dim",children:"read sees sessions, drive may ask this device for one, admin may also change the membership."})]}),o&&e.jsx(ee,{variant:"warning",className:"text-meta",children:o.sentence}),e.jsxs(we,{children:[e.jsx($,{variant:"ghost",onClick:a,children:m?"Close":"Cancel"}),!m&&e.jsxs($,{disabled:u||x===null,onClick:()=>x&&d({networkId:x,role:N,deviceId:k}),children:[u&&e.jsx(je,{"aria-hidden":"true",className:"mr-2 size-3.5 animate-spin"}),"Mint the token"]})]})]})})},Ot=({open:t,networkLabel:n,deviceLabel:l,onClose:a,onConfirm:d,pending:u,refusal:m,removed:o})=>{const[k,N]=c.useState(""),g=c.useId();return c.useEffect(()=>{t&&N("")},[t]),e.jsx(pe,{open:t,onOpenChange:j=>!j&&a(),children:e.jsxs(be,{className:"max-w-md",children:[e.jsxs(ke,{children:[e.jsxs(ve,{children:["Remove ",l," from ",n,"?"]}),e.jsxs(ge,{children:["Every device in the network is rekeyed and ",l," is locked out on its next handshake. A removed device id is never admitted again."]})]}),o?e.jsxs("p",{className:"text-body-sm text-ink",children:["Removed. The membership epoch is now ",o.epoch,"."]}):e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs(fe,{htmlFor:g,children:["Type the network's name to confirm: ",n]}),e.jsx(tt,{id:g,value:k,onChange:j=>N(j.target.value),autoComplete:"off",spellCheck:!1})]}),m&&e.jsx(ee,{variant:"warning",className:"text-meta",children:m.sentence}),e.jsxs(we,{children:[e.jsx($,{variant:"ghost",onClick:a,children:o?"Close":"Cancel"}),!o&&e.jsxs($,{variant:"danger",disabled:u||k.length===0,onClick:()=>d(k),children:[u&&e.jsx(je,{"aria-hidden":"true",className:"mr-2 size-3.5 animate-spin"}),"Remove the device"]})]})]})})};function Wt({path:t}){let n=0;return t.split("/").flatMap(l=>{const a=n;n+=l.length+1;const d=e.jsx("span",{className:"whitespace-nowrap",children:l},`path-segment-${a}`);return a===0?[d]:[e.jsx("wbr",{},`path-break-${a}`),"/",d]})}const Ft=({receipt:t,canWait:n,refusal:l,onWait:a,onRecheck:d,onUndo:u,onDismiss:m,pending:o})=>!t&&!l?null:e.jsxs("output",{"data-mesh-notice":t?"moved":l?.unconfirmed?"unconfirmed":"refused",className:"flex flex-wrap items-center gap-2 rounded-md border border-hairline bg-sunken px-3 py-2",children:[t?e.jsx(et,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}):null,e.jsx("span",{className:"min-w-0 flex-1 text-body-sm text-ink",children:t?t.verb:l?.sentence}),t?e.jsx("span",{className:"text-meta text-ink-dim",children:t.detail}):e.jsx("span",{className:"font-mono text-meta text-ink-dim",children:l?.code}),l?.code==="busy"&&n&&e.jsx($,{size:"sm",variant:"secondary",onClick:a,disabled:o,children:"Wait for the turn to finish"}),(l?.unconfirmed||l?.code==="unreachable")&&e.jsx($,{size:"sm",variant:"secondary",onClick:d,disabled:o,children:"Check again"}),t?.undo&&e.jsx($,{size:"sm",variant:"secondary",onClick:u,disabled:o,children:t.undo.verb}),e.jsx($,{size:"sm",variant:"ghost",onClick:m,children:"Dismiss"})]}),Ht=4,ce={kind:"idle"};function Bt(t){switch(t.kind){case"dragging":case"settling":return t.payload.session.id;case"pressing":return null;default:return null}}function K(t,n){switch(n.kind){case"press":return t.kind!=="idle"?t:{kind:"pressing",payload:n.payload,originX:n.x,originY:n.y,pointerId:n.pointerId};case"move":return t.kind==="pressing"?Math.max(Math.abs(n.x-t.originX),Math.abs(n.y-t.originY))<Ht?t:{kind:"dragging",payload:t.payload,x:n.x,y:n.y,target:n.target,pointerId:t.pointerId}:t.kind==="dragging"?{...t,x:n.x,y:n.y,target:n.target}:t;case"release":return t.kind==="dragging"?{kind:"settling",payload:t.payload,target:t.target}:t.kind==="pressing"?ce:t;case"cancel":case"settled":return ce;default:return t}}const Yt=({edges:t,geometry:n,selectedDeviceId:l})=>e.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:t.map(a=>{const d=n.networks.get(a.networkId),u=n.devices.get(a.deviceId);if(!d||!u)return null;const m=l!==null&&a.deviceId===l;return e.jsx("path",{"data-mesh-edge":a.key,d:ht(d,u),fill:"none",strokeWidth:m?2:1.5,strokeDasharray:a.active?void 0:"4 4",className:m?"stroke-ink":"stroke-ink-dim"},a.key)})}),Vt={self:"border-l-hairline",reachable:"border-l-hairline",unreachable:"border-l-warning",suspect:"border-l-danger"},Xt={self:"ring-2 ring-accent",reachable:null,unreachable:null,suspect:null},Gt={self:"text-accent",reachable:"text-ink-muted",unreachable:"text-warning",suspect:"text-danger"},Ut={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function Kt(t,n){const l=Be(t);return[t.label,l||null,ue(t,n)].filter(Boolean).join(", ")}function te(t){return t.name.trim()||t.id.slice(-6)}function Xe(t,n,l){return l?t.live_state.trim()?t.live_state.trim():t.locality==="local"?"on this device":`on ${n}`:`unreachable${t.unreachable_reason?` (${t.unreachable_reason})`:""}`}const qt={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},Zt=({network:t,x:n,y:l,refused:a})=>e.jsxs("li",{"data-mesh-network":t.id,"data-mesh-network-refused":a?"true":void 0,className:_("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",a?"border-warning":"border-hairline"),style:{left:n,top:l,width:He,height:mt},children:[e.jsx(ye,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-body-sm text-ink",children:t.label}),e.jsxs("span",{title:`epoch ${t.epoch}`,className:"block truncate text-meta text-ink-dim",children:[t.memberCount," ",t.memberCount===1?"device":"devices",t.revokedCount>0?` · ${t.revokedCount} revoked`:""]})]})]}),Jt=({device:t,x:n,y:l,nowSeconds:a,selected:d,sessions:u,sessionTotal:m,dropState:o,movingSessionId:k,draggedSessionId:N,onOpen:g,onChipPointerDown:j,onChipClick:I,onShowAllSessions:x})=>{const f=ue(t,a),r=xt(t,a),b=Kt(t,a);return e.jsxs("li",{"data-mesh-device":t.id,"data-mesh-state":t.state,"data-mesh-drop":o??void 0,"aria-current":d?"true":void 0,className:_("absolute flex flex-col rounded-md border border-l-4 border-control bg-elevated","hover:bg-row-hover",d&&"border-y-ink border-r-ink bg-row-selected",Vt[t.state],Xt[t.state],o&&Ut[o]),style:{left:n,top:l,width:He,height:ft},children:[e.jsxs("button",{type:"button","data-mesh-device-open":t.id,"aria-label":b,onClick:()=>g(t.id),className:_("flex w-full items-center gap-2 rounded-t-[5px] px-3 pt-2 pb-1 text-left","cursor-pointer","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),children:[e.jsx(pt,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-body-sm text-ink",children:t.label}),e.jsxs("span",{title:f,className:_("block truncate text-meta",Gt[t.state]),children:[r,t.memberships.length>1?` · ${t.memberships.length} networks`:""]})]})]}),e.jsxs("ul",{"aria-label":`Conversations on ${t.label}`,className:_("m-0 flex list-none items-center gap-1 overflow-hidden px-3 pb-2",o==="accept"&&"opacity-40"),children:[u.shown.map(w=>e.jsx(Qt,{session:w,ownerLabel:t.label,ownerReachable:t.reachable,moving:k===w.id,dragging:N===w.id,onPointerDown:j,onClick:()=>I(w)},w.id)),u.hidden>0&&e.jsx("li",{className:"shrink-0",children:e.jsxs("button",{type:"button","data-mesh-more":t.id,onClick:()=>x(t.id),className:_("rounded-sm px-1.5 py-0.5 text-meta text-ink-dim","hover:bg-row-hover hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),title:`Showing ${u.shown.length} of ${m} conversations`,"aria-label":`Show all ${m} conversations`,children:["+",u.hidden]})}),u.rows.length===0&&Pe(t)!==null&&e.jsx("li",{className:"text-meta text-ink-dim",children:Pe(t)})]})]})};function Pe(t){return t.state==="self"?"no conversations here":t.sessionCount===0?"no conversations":null}const Qt=({session:t,ownerLabel:n,ownerReachable:l,moving:a,dragging:d,onPointerDown:u,onClick:m})=>{const o=Xe(t,n,l);return a?e.jsx("li",{role:"status","data-mesh-session":t.id,"data-mesh-moving":"true",children:e.jsx("span",{className:"rounded-sm bg-sunken px-1.5 py-0.5 text-meta text-ink-muted",children:"moving…"})}):e.jsx("li",{className:"min-w-0 flex-1","data-mesh-session-item":t.id,"data-mesh-dragging":d?"true":void 0,children:e.jsx("button",{type:"button","data-mesh-session":t.id,style:{touchAction:"none"},title:`${te(t)} · ${o}`,"aria-label":`${te(t)}, ${o}. Opens ${n}.`,onPointerDown:k=>u(k,t),onClick:()=>m(t),className:_("w-full max-w-32 truncate rounded-sm border border-hairline bg-surface px-1.5 py-0.5 text-left text-meta text-ink-muted","[direction:rtl]","cursor-grab active:cursor-grabbing","hover:text-ink",qt[bt(t,l)],d&&"opacity-60","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:te(t)})})},ze=48,Oe=1.25,en=.0015,tn=({graph:t,slots:n,nowSeconds:l,selectedDeviceId:a,sessions:d,sessionTotals:u,movingSessionId:m,canMove:o,onOpenDevice:k,onAskMove:N,onDropRefused:g,onShowAllSessions:j,summaryId:I})=>{const x=c.useRef(null),[f,r]=c.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[b,w]=c.useState({k:1,tx:0,ty:0}),O=c.useRef(!1),R=c.useRef(!1),L=c.useRef(null),v=c.useMemo(()=>kt(n),[n]),D=c.useMemo(()=>({selfDeviceId:t.selfDeviceId,devices:new Map(t.devices.map(s=>[s.id,s])),networks:new Map(t.networks.map(s=>[s.id,s]))}),[t]),[p,A]=c.useState(ce),q=c.useRef({kind:"ground"}),ne=c.useCallback((s,i)=>{const h=document.elementFromPoint(s,i),C=h?.closest("[data-mesh-device]");if(C){const B=C.getAttribute("data-mesh-device");if(B)return{kind:"device",deviceId:B}}const E=h?.closest("[data-mesh-network]");if(E){const B=E.getAttribute("data-mesh-network");if(B)return{kind:"network",networkId:B}}return{kind:"ground"}},[]),P=c.useMemo(()=>p.kind!=="dragging"&&p.kind!=="settling"?null:de(p.payload,p.target,D),[p,D]),Y=c.useCallback(s=>{if(!P)return null;if(P.kind==="plan"){const i=p.kind==="dragging"||p.kind==="settling"?p.target:null;return i&&i.kind==="device"&&i.deviceId===s?"accept":null}if(P.kind==="refused"){const i=p.kind==="dragging"||p.kind==="settling"?p.target:null;return i&&i.kind==="device"&&i.deviceId===s?"refuse":null}return null},[P,p]),Z=c.useCallback((s,i)=>{if(!o||s.button!==0)return;R.current=!1;const h=i.locality==="local"?t.selfDeviceId??"":i.owner_device,C=D.devices.get(h),E={session:i,ownerDeviceId:h,ownerLabel:C?.label??i.owner_device_name};try{s.currentTarget.setPointerCapture(s.pointerId)}catch{}A(B=>K(B,{kind:"press",payload:E,x:s.clientX,y:s.clientY,pointerId:s.pointerId}))},[o,D,t.selfDeviceId]),se=s=>{if(p.kind==="pressing"||p.kind==="dragging"){const i=ne(s.clientX,s.clientY);q.current=i,A(h=>K(h,{kind:"move",x:s.clientX,y:s.clientY,target:i}));return}U(s)},y=s=>{if(ie(s),p.kind!=="pressing"&&p.kind!=="dragging")return;if(p.kind==="pressing"){A(h=>K(h,{kind:"cancel"}));return}const i=de(p.payload,p.target,D);R.current=!0,A(h=>K(h,{kind:"release"})),i.kind==="plan"?N({plan:i.plan,alternatives:i.alternatives,risky:i.risky}):i.kind==="refused"&&g({code:i.code,sentence:i.sentence,remedy:i.remedy,plan:i.plan??null}),A(h=>K(h,{kind:"settled"}))};c.useEffect(()=>()=>A(ce),[]);const T=c.useCallback(()=>{w(Ee(v.bounds,f))},[v.bounds,f]);c.useEffect(()=>{const s=x.current;if(!s)return;const i=()=>{const C=s.getBoundingClientRect();r({width:C.width,height:C.height,clipWidth:s.clientWidth,clipHeight:s.clientHeight,left:C.left,top:C.top})};i();const h=new ResizeObserver(i);return h.observe(s),()=>h.disconnect()},[]),c.useEffect(()=>{O.current||f.width<=0||f.height<=0||(O.current=!0,w(Ee(v.bounds,f)))},[f,v.bounds]),c.useEffect(()=>{const s=L.current;if(L.current={width:f.width,height:f.height},!s||!O.current||f.width<=0||f.height<=0||f.width>=s.width&&f.height>=s.height||!a)return;const i=v.devices.get(a);i&&w(h=>{const C={width:f.clipWidth,height:f.clipHeight},E=Math.max(0,Math.min(C.width-v.bounds.width*h.k,C.height-v.bounds.height*h.k));return vt(h,i,C,Math.min(gt,E))})},[f,a,v]);const M=p.kind==="dragging"?{x:p.x-f.left+12,y:p.y-f.top+12}:{x:0,y:0},W=P?At(P):null,S=c.useRef(null),F=c.useRef(null),H=c.useRef(null),X=c.useRef(null),le=c.useCallback(()=>{H.current=null;const s=S.current,i=F.current;if(S.current=null,F.current=null,s){const h=X.current;if(!h)return;w({k:h.transform.k,tx:h.transform.tx+(s.x-h.x),ty:h.transform.ty+(s.y-h.y)});return}i&&w(h=>me(h,{x:i.x,y:i.y},h.k*Math.exp(-i.deltaY*en)))},[]),J=c.useCallback(()=>{H.current===null&&(H.current=requestAnimationFrame(le))},[le]);c.useEffect(()=>()=>{H.current!==null&&cancelAnimationFrame(H.current)},[]);const he=s=>{!(s.target===s.currentTarget)&&s.button!==1||s.button!==0&&s.button!==1||(X.current={x:s.clientX,y:s.clientY,transform:b},s.currentTarget.setPointerCapture(s.pointerId),s.preventDefault())},U=s=>{X.current&&(S.current={x:s.clientX,y:s.clientY},J())},ie=s=>{X.current&&(X.current=null,S.current=null,s.currentTarget.hasPointerCapture(s.pointerId)&&s.currentTarget.releasePointerCapture(s.pointerId))},G=c.useCallback(s=>{if(s.deltaY===0)return;s.preventDefault();const i=s.currentTarget.getBoundingClientRect();F.current={x:s.clientX-i.left,y:s.clientY-i.top,deltaY:s.deltaY},J()},[J]);c.useEffect(()=>{const s=x.current;if(s)return s.addEventListener("wheel",G,{passive:!1}),()=>s.removeEventListener("wheel",G)},[G]);const Q=s=>{const i=s.shiftKey?ze*4:ze;switch(s.key){case"Escape":if(p.kind!=="pressing"&&p.kind!=="dragging")return;s.preventDefault(),p.kind==="dragging"&&(R.current=!0),A(h=>K(h,{kind:"cancel"}));return;case"0":s.preventDefault(),T();return;case"+":case"=":s.preventDefault(),w(h=>me(h,{x:f.width/2,y:f.height/2},h.k*Oe));return;case"-":case"_":s.preventDefault(),w(h=>me(h,{x:f.width/2,y:f.height/2},h.k/Oe));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{s.preventDefault();const h=s.key==="ArrowLeft"?i:s.key==="ArrowRight"?-i:0,C=s.key==="ArrowUp"?i:s.key==="ArrowDown"?-i:0;w(E=>({...E,tx:E.tx+h,ty:E.ty+C}));return}}};return e.jsxs("div",{ref:x,"data-mesh-canvas":"",role:"group","aria-labelledby":I,tabIndex:0,onPointerDown:he,onPointerMove:se,onPointerUp:y,onPointerCancel:s=>{p.kind==="dragging"&&(R.current=!0),A(i=>K(i,{kind:"cancel"})),ie(s)},"data-mesh-gesture":p.kind,onKeyDown:Q,onDoubleClick:s=>{s.target===s.currentTarget&&T()},className:_("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:[e.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${b.tx}px, ${b.ty}px, 0) scale(${b.k})`,transformOrigin:"0 0",width:v.bounds.width,height:v.bounds.height},children:[e.jsx(Yt,{edges:t.edges,geometry:v,selectedDeviceId:a}),e.jsx("ul",{"aria-label":"Networks",className:"m-0 list-none p-0",children:t.networks.map(s=>{const i=v.networks.get(s.id);return i?e.jsx(Zt,{network:s,x:i.x,y:i.y,refused:P?.kind==="refused"&&p.kind==="dragging"&&p.target.kind==="network"&&p.target.networkId===s.id},s.id):null})}),e.jsx("ul",{"aria-label":"Devices",className:"m-0 list-none p-0",children:t.devices.map(s=>{const i=v.devices.get(s.id);return i?e.jsx(Jt,{device:s,x:i.x,y:i.y,nowSeconds:l,selected:s.id===a,sessions:d.get(s.id)??{rows:[],shown:[],hidden:0},sessionTotal:u.get(s.id)??s.sessionCount??0,dropState:Y(s.id),movingSessionId:m,draggedSessionId:Bt(p),onOpen:k,onChipPointerDown:Z,onChipClick:()=>{if(R.current){R.current=!1;return}k(s.id)},onShowAllSessions:j},s.id):null})})]}),p.kind==="dragging"&&e.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:M.x,top:M.y},children:p.payload.session.name||"untitled"}),p.kind==="dragging"&&W&&e.jsx("div",{"data-mesh-indicator":"",className:_("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",P?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:M.x,maxWidth:Math.max(160,f.width-M.x-12),...M.y>f.height*.6?{bottom:Math.max(12,f.height-M.y+8)}:{top:M.y+24}},children:W})]})};function nn(t,n,l,a){const d=l.locality==="local"?n:l.owner_device,u=[];for(const m of t)if(m.id!==d){if(m.id===n){u.push({deviceId:m.id,label:a,verb:"Recall to this device",keepVerb:"Copy here, leave it there"});continue}u.push({deviceId:m.id,label:m.label,verb:`Move to ${m.label}`,keepVerb:`Copy to ${m.label}`})}return u}function sn(t,n,l){return nn(t.devices,t.selfDeviceId,n,l)}function Ge(t,n,l){const a=sn(t,n,l),d={selfDeviceId:t.selfDeviceId,devices:new Map(t.devices.map(o=>[o.id,o])),networks:new Map(t.networks.map(o=>[o.id,o]))},u=n.locality==="local"?t.selfDeviceId??"":n.owner_device,m=d.devices.get(u);return a.map(o=>{const k=de({session:n,ownerDeviceId:u,ownerLabel:m?.label??n.owner_device_name},{kind:"device",deviceId:o.deviceId},d);return{...o,refused:k.kind==="refused"&&k.code!=="busy"?k.sentence:null}})}const Ue=({session:t,destinations:n,disabled:l,onChoose:a,onOpenChange:d,trigger:u,triggerLabel:m})=>e.jsxs(it,{onOpenChange:d,children:[e.jsx(at,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":m,"data-mesh-session-menu":t.id,disabled:l||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:u})}),e.jsxs(rt,{align:"start",className:"min-w-56",children:[e.jsx(lt,{children:te(t)}),e.jsx(_e,{}),n.map(o=>e.jsx(Re,{"data-mesh-move-to":o.deviceId,disabled:!!o.refused,title:o.refused??void 0,onSelect:()=>a(o,!1),children:o.verb},o.deviceId)),e.jsx(_e,{}),n.map(o=>e.jsx(Re,{"data-mesh-copy-to":o.deviceId,disabled:!!o.refused,title:o.refused??void 0,onSelect:()=>a(o,!0),children:o.keepVerb},`keep-${o.deviceId}`))]})]}),an=({device:t,sessions:n,sessionTotal:l,nowSeconds:a,destinationsFor:d,movingSessionId:u,canMove:m,canInvite:o,onClose:k,onMove:N,onShowInList:g,onInvite:j,onRemoveMember:I})=>{const x=Be(t),f=l>n.rows.length?`${n.rows.length} of ${l}`:`${n.rows.length}`;return e.jsxs("aside",{"aria-label":`${t.label} details`,"data-mesh-panel":t.id,className:"flex w-80 shrink-0 flex-col gap-3 overflow-y-auto rounded-md border border-hairline bg-surface p-4",children:[e.jsxs("header",{className:"flex flex-col gap-1",children:[e.jsx($,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:k,children:"Close"}),e.jsx("h2",{className:"text-body-sm text-ink",children:t.label}),e.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[t.state==="suspect"&&e.jsx(wt,{"aria-hidden":"true",className:"size-3.5 text-danger"}),t.state==="unreachable"&&e.jsx(nt,{"aria-hidden":"true",className:"size-3.5 text-warning"}),x||ue(t,a)]}),t.reason&&e.jsx("p",{className:"text-meta text-warning",children:t.reason})]}),e.jsx(oe,{}),e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsx("h3",{className:"text-meta text-ink-dim",children:"Memberships"}),e.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:t.memberships.map(r=>e.jsxs("li",{className:"flex flex-col gap-1",children:[e.jsxs("span",{className:"flex items-center gap-2 text-body-sm text-ink",children:[e.jsx(ye,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),r.networkName]}),e.jsxs("span",{className:"text-meta text-ink-dim",children:[r.role||"member",r.capabilities.length>0?` · ${r.capabilities.join(", ")}`:"",r.active?"":" · revoked"]}),o&&r.active&&e.jsxs($,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${r.networkId}:${t.id}`,onClick:()=>I(t,r.networkId),children:["Remove from ",r.networkName,"…"]})]},r.networkId))}),o&&e.jsx($,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":t.id,onClick:()=>j(t),children:"Invite to a network…"})]}),e.jsx(oe,{}),e.jsxs("section",{className:"flex min-h-0 flex-col gap-2",children:[e.jsxs("h3",{className:"text-meta text-ink-dim",children:["Conversations ",e.jsxs("span",{className:"text-ink-disabled",children:["(",f,")"]})]}),n.rows.length===0?e.jsx("p",{className:"text-meta text-ink-dim",children:t.sessionCount===null?"This device did not report its conversations.":"No conversations here."}):e.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:n.rows.map(r=>e.jsxs("li",{"data-mesh-panel-session":r.id,className:_("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",u===r.id&&"border-control"),children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",children:te(r)}),e.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:Xe(r,t.label,t.reachable)}),u===r.id?e.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:"moving…"}):e.jsx(Ue,{session:r,destinations:d(r),disabled:!m,onChoose:(b,w)=>N(r,b,w),trigger:e.jsx(Ye,{"aria-hidden":"true",className:"size-4"}),triggerLabel:`Move ${te(r)}`})]},r.id))}),t.endpoints.length>0&&e.jsx(st,{content:t.endpoints.join(`
|
|
1
|
+
import{j as e,r as c,c as _}from"./index-VKe88JN9.js";import{u as Je,I as Ie}from"./aida-control-DVTI-DZP.js";import{P as Qe}from"./page-header-B3RA2AMB.js";import{j as et,B as $,D as pe,l as be,m as ke,n as ve,o as ge,A as ee,p as we,L as fe,q as Ce,r as Se,s as De,t as Me,u as $e,I as tt,T as nt,b as oe,g as st,v as it,w as at,x as rt,y as lt,z as _e,E as Re,f as Te}from"./textarea-BX6EeK34.js";import{al as ot,am as dt,an as ct,ao as je,ap as ut,aq as ht,ar as mt,as as He,at as ye,au as ue,av as xt,aw as ft,ax as pt,ay as Be,az as bt,aA as kt,aB as Ee,aC as vt,aD as me,aE as gt,aF as wt,aG as Ye,aH as Ve,aI as jt,aJ as yt,aK as Nt,aL as It,aM as Ct,aN as St,aO as Dt,aP as Mt,aQ as $t,aR as _t,aS as Rt,aT as Tt,aU as ae}from"./index-NVdUA6ab.js";import"./ui-preferences-store-DjUQd2R7.js";import"./error-boundary-DVk48CIF.js";import"./console-mirror-CG9RcMIb.js";function xe(t){return t.live_state.trim().toLowerCase()==="attached"}function Et(t,n){return t.keep||!t.lost?null:{body:t.lost,confirmLabel:t.to==="local"?"Recall it":"Move it",risky:n}}function re(t,n){return`The copy on ${t} is deleted once ${n} has it.`}function Le(t,n){return`${t.name||"This conversation"} is running ${n} right now.`}function Ae(t,n){return t?.label||n.slice(-6)}function Lt(t,n){return t.suspect?{kind:"refused",code:"suspect_device",sentence:`${t.label} has a duplicated key${t.reason?` (${t.reason})`:""}, so nothing is moved to it until that is resolved.`,remedy:{kind:"open",label:"See this device",deviceId:n}}:t.memberships.every(l=>!l.active)?{kind:"refused",code:"revoked_membership",sentence:`${t.label} is no longer a member of any network this device shares.`,remedy:{kind:"open",label:"See this device",deviceId:n}}:t.reachable?null:{kind:"refused",code:"unreachable",sentence:`${t.label} is not answering${t.reason?` (${t.reason})`:""}, so nothing was moved.`,remedy:{kind:"resume",label:"Check again"}}}function de(t,n,l){const{session:a,ownerDeviceId:d,ownerLabel:u}=t,{selfDeviceId:m,devices:o,networks:k}=l;if(n.kind==="ground")return{kind:"none"};if(n.kind==="network")return{kind:"refused",code:"not_a_device",sentence:`A conversation lives on a device. ${k.get(n.networkId)?.label??"A network"} holds devices, not conversations.`,remedy:null};if(ot(a))return{kind:"refused",code:"busy",sentence:`${a.name||"This conversation"} has a turn in flight, so it is not moved — the refusal changes nothing.`,remedy:{kind:"wait",label:"Wait for the turn to finish",waitS:300},plan:{sessionId:a.id,to:n.deviceId===m?"local":n.deviceId,keep:!1,verb:n.deviceId===m?"Recall to this device":`Move to ${Ae(o.get(n.deviceId),n.deviceId)}`,waitS:0,lost:null}};if(d===n.deviceId)return{kind:"none"};const N=o.get(n.deviceId),g=N?Lt(N,n.deviceId):{code:"unknown_device",sentence:"That device is no longer in any network this tab can read.",remedy:null};if(g)return{kind:"refused",...g};const j=Ae(N,n.deviceId);if(!(a.locality==="local")){const r=o.get(d);if(r&&!r.reachable)return{kind:"refused",code:"unreachable",sentence:`${u} is not answering${r.reason?` (${r.reason})`:""}, so it could not hand this conversation over.`,remedy:{kind:"resume",label:"Check again"}};if(n.deviceId!==m)return{kind:"refused",code:"third_device",sentence:`This conversation is on ${u}. It has to travel through this device: recall it here first.`,remedy:null}}if(n.deviceId===m){const r={sessionId:a.id,to:"local",keep:!1,verb:"Recall to this device",waitS:0,lost:xe(a)?`${Le(a,`on ${u}`)} ${re(u,"this device")}`:re(u,"this device")};return{kind:"plan",plan:r,risky:xe(a),alternatives:[{...r,keep:!0,verb:"Copy here, leave it there",lost:null}]}}if(a.locality==="local"&&n.deviceId===d)return{kind:"none"};const x=xe(a),f={sessionId:a.id,to:n.deviceId,keep:!1,verb:`Move to ${j}`,waitS:0,lost:x?`${Le(a,"on this device")} ${re("this device",j)}`:re("this device",j)};return{kind:"plan",plan:f,risky:x,alternatives:[{...f,keep:!0,verb:`Copy to ${j}`,lost:null}]}}function At(t){return t.kind==="refused"?`Drop will be refused: ${t.sentence}`:t.kind==="plan"?t.plan.verb:null}const Pt=({open:t,plan:n,alternatives:l,risky:a,busy:d,onCancel:u,onChoose:m})=>{const o=Et(n,a),[k,N]=c.useState(n);c.useEffect(()=>{t&&N(n)},[t,n]);const g=l.some(I=>I.keep===k.keep)?k:n,j=g.keep;return e.jsx(pe,{open:t,onOpenChange:I=>!I&&u(),children:e.jsxs(be,{className:"max-w-md",children:[e.jsxs(ke,{children:[e.jsx(ve,{children:g.verb}),e.jsx(ge,{children:j?`A copy is made on the destination with a new id, and ${g.to==="local"?"the other device keeps":"this device keeps"} its own. The copy can be erased again from the session list.`:o?.body??"This moves the conversation."})]}),l.length>0&&e.jsxs("fieldset",{className:"m-0 flex flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"sr-only",children:"Which operation"}),[n,...l].map(I=>e.jsxs("label",{className:_("flex cursor-pointer items-start gap-2 rounded-md border border-control px-3 py-2","hover:bg-row-hover",g.keep===I.keep&&"border-ink bg-row-selected"),children:[e.jsx("input",{type:"radio",name:"mesh-move-mode",className:"mt-1",checked:g.keep===I.keep,onChange:()=>N(I)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-2 text-body-sm text-ink",children:[I.keep?e.jsx(dt,{"aria-hidden":"true",className:"size-3.5"}):e.jsx(ct,{"aria-hidden":"true",className:"size-3.5"}),I.verb]}),e.jsx("span",{className:"mt-0.5 block text-meta text-ink-dim",children:I.keep?"the original stays where it is":"the copy here is deleted once it arrives"})]})]},I.keep?"copy":"move"))]}),a&&e.jsx(ee,{variant:"warning",className:"text-meta",children:g.keep?"It is open on the other end, and the copy does not interrupt it.":"It is open elsewhere right now: whatever that runtime is holding is not carried across."}),e.jsxs(we,{children:[e.jsx($,{variant:"ghost",onClick:u,disabled:d,children:"Cancel"}),e.jsxs($,{onClick:()=>m(g),disabled:d,variant:j?"secondary":"primary",children:[d&&e.jsx(je,{"aria-hidden":"true",className:"mr-2 size-3.5 animate-spin"}),g.verb]})]})]})})},zt=({open:t,options:n,deviceLabel:l,onClose:a,onInvite:d,pending:u,receipt:m,refusal:o,deviceId:k})=>{const[N,g]=c.useState("drive"),[j,I]=c.useState(null),x=n.find(b=>b.id===j)?.id??n[0]?.id??null,f=c.useId(),r=c.useId();return e.jsx(pe,{open:t,onOpenChange:b=>!b&&a(),children:e.jsxs(be,{className:"max-w-md",children:[e.jsxs(ke,{children:[e.jsx(ve,{children:"Invite to a network…"}),e.jsxs(ge,{children:["Admission is two-sided, so this mints a single-use token instead of adding anything: ",l??"the device"," proves the short authentication string when it redeems the token, and only then does it appear as a member."]})]}),m?e.jsxs("div",{className:"flex flex-col gap-2 rounded-md border border-control bg-sunken px-3 py-2",children:[e.jsx("span",{className:"text-body-sm text-ink",children:"Invited — the device appears once it redeems this."}),e.jsx("span",{className:"text-meta text-ink-dim",children:"The token was written here, and this app never reads it:"}),e.jsx("code",{className:"break-words font-mono text-meta text-ink",children:m.token_path?e.jsx(Wt,{path:m.token_path}):"(the route did not name a path)"})]}):e.jsxs("div",{className:"flex flex-col gap-1",children:[n.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{htmlFor:r,children:"Network to invite it to"}),e.jsxs(Ce,{value:x??void 0,onValueChange:b=>I(b),children:[e.jsx(Se,{id:r,className:"w-56",children:e.jsx(De,{})}),e.jsx(Me,{children:n.map(b=>e.jsx($e,{value:b.id,children:b.label},b.id))})]})]}),n.length===1&&e.jsxs("span",{className:"text-meta text-ink-dim",children:["Inviting to ",n[0]?.label]}),e.jsx(fe,{htmlFor:f,children:"Role the device will have"}),e.jsxs(Ce,{value:N,onValueChange:b=>g(b),children:[e.jsx(Se,{id:f,className:"w-48",children:e.jsx(De,{})}),e.jsx(Me,{children:ut.map(b=>e.jsx($e,{value:b,children:b},b))})]}),e.jsx("span",{className:"text-meta text-ink-dim",children:"read sees sessions, drive may ask this device for one, admin may also change the membership."})]}),o&&e.jsx(ee,{variant:"warning",className:"text-meta",children:o.sentence}),e.jsxs(we,{children:[e.jsx($,{variant:"ghost",onClick:a,children:m?"Close":"Cancel"}),!m&&e.jsxs($,{disabled:u||x===null,onClick:()=>x&&d({networkId:x,role:N,deviceId:k}),children:[u&&e.jsx(je,{"aria-hidden":"true",className:"mr-2 size-3.5 animate-spin"}),"Mint the token"]})]})]})})},Ot=({open:t,networkLabel:n,deviceLabel:l,onClose:a,onConfirm:d,pending:u,refusal:m,removed:o})=>{const[k,N]=c.useState(""),g=c.useId();return c.useEffect(()=>{t&&N("")},[t]),e.jsx(pe,{open:t,onOpenChange:j=>!j&&a(),children:e.jsxs(be,{className:"max-w-md",children:[e.jsxs(ke,{children:[e.jsxs(ve,{children:["Remove ",l," from ",n,"?"]}),e.jsxs(ge,{children:["Every device in the network is rekeyed and ",l," is locked out on its next handshake. A removed device id is never admitted again."]})]}),o?e.jsxs("p",{className:"text-body-sm text-ink",children:["Removed. The membership epoch is now ",o.epoch,"."]}):e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs(fe,{htmlFor:g,children:["Type the network's name to confirm: ",n]}),e.jsx(tt,{id:g,value:k,onChange:j=>N(j.target.value),autoComplete:"off",spellCheck:!1})]}),m&&e.jsx(ee,{variant:"warning",className:"text-meta",children:m.sentence}),e.jsxs(we,{children:[e.jsx($,{variant:"ghost",onClick:a,children:o?"Close":"Cancel"}),!o&&e.jsxs($,{variant:"danger",disabled:u||k.length===0,onClick:()=>d(k),children:[u&&e.jsx(je,{"aria-hidden":"true",className:"mr-2 size-3.5 animate-spin"}),"Remove the device"]})]})]})})};function Wt({path:t}){let n=0;return t.split("/").flatMap(l=>{const a=n;n+=l.length+1;const d=e.jsx("span",{className:"whitespace-nowrap",children:l},`path-segment-${a}`);return a===0?[d]:[e.jsx("wbr",{},`path-break-${a}`),"/",d]})}const Ft=({receipt:t,canWait:n,refusal:l,onWait:a,onRecheck:d,onUndo:u,onDismiss:m,pending:o})=>!t&&!l?null:e.jsxs("output",{"data-mesh-notice":t?"moved":l?.unconfirmed?"unconfirmed":"refused",className:"flex flex-wrap items-center gap-2 rounded-md border border-hairline bg-sunken px-3 py-2",children:[t?e.jsx(et,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}):null,e.jsx("span",{className:"min-w-0 flex-1 text-body-sm text-ink",children:t?t.verb:l?.sentence}),t?e.jsx("span",{className:"text-meta text-ink-dim",children:t.detail}):e.jsx("span",{className:"font-mono text-meta text-ink-dim",children:l?.code}),l?.code==="busy"&&n&&e.jsx($,{size:"sm",variant:"secondary",onClick:a,disabled:o,children:"Wait for the turn to finish"}),(l?.unconfirmed||l?.code==="unreachable")&&e.jsx($,{size:"sm",variant:"secondary",onClick:d,disabled:o,children:"Check again"}),t?.undo&&e.jsx($,{size:"sm",variant:"secondary",onClick:u,disabled:o,children:t.undo.verb}),e.jsx($,{size:"sm",variant:"ghost",onClick:m,children:"Dismiss"})]}),Ht=4,ce={kind:"idle"};function Bt(t){switch(t.kind){case"dragging":case"settling":return t.payload.session.id;case"pressing":return null;default:return null}}function K(t,n){switch(n.kind){case"press":return t.kind!=="idle"?t:{kind:"pressing",payload:n.payload,originX:n.x,originY:n.y,pointerId:n.pointerId};case"move":return t.kind==="pressing"?Math.max(Math.abs(n.x-t.originX),Math.abs(n.y-t.originY))<Ht?t:{kind:"dragging",payload:t.payload,x:n.x,y:n.y,target:n.target,pointerId:t.pointerId}:t.kind==="dragging"?{...t,x:n.x,y:n.y,target:n.target}:t;case"release":return t.kind==="dragging"?{kind:"settling",payload:t.payload,target:t.target}:t.kind==="pressing"?ce:t;case"cancel":case"settled":return ce;default:return t}}const Yt=({edges:t,geometry:n,selectedDeviceId:l})=>e.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:t.map(a=>{const d=n.networks.get(a.networkId),u=n.devices.get(a.deviceId);if(!d||!u)return null;const m=l!==null&&a.deviceId===l;return e.jsx("path",{"data-mesh-edge":a.key,d:ht(d,u),fill:"none",strokeWidth:m?2:1.5,strokeDasharray:a.active?void 0:"4 4",className:m?"stroke-ink":"stroke-ink-dim"},a.key)})}),Vt={self:"border-l-hairline",reachable:"border-l-hairline",unreachable:"border-l-warning",suspect:"border-l-danger"},Xt={self:"ring-2 ring-accent",reachable:null,unreachable:null,suspect:null},Gt={self:"text-accent",reachable:"text-ink-muted",unreachable:"text-warning",suspect:"text-danger"},Ut={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function Kt(t,n){const l=Be(t);return[t.label,l||null,ue(t,n)].filter(Boolean).join(", ")}function te(t){return t.name.trim()||t.id.slice(-6)}function Xe(t,n,l){return l?t.live_state.trim()?t.live_state.trim():t.locality==="local"?"on this device":`on ${n}`:`unreachable${t.unreachable_reason?` (${t.unreachable_reason})`:""}`}const qt={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},Zt=({network:t,x:n,y:l,refused:a})=>e.jsxs("li",{"data-mesh-network":t.id,"data-mesh-network-refused":a?"true":void 0,className:_("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",a?"border-warning":"border-hairline"),style:{left:n,top:l,width:He,height:mt},children:[e.jsx(ye,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-body-sm text-ink",children:t.label}),e.jsxs("span",{title:`epoch ${t.epoch}`,className:"block truncate text-meta text-ink-dim",children:[t.memberCount," ",t.memberCount===1?"device":"devices",t.revokedCount>0?` · ${t.revokedCount} revoked`:""]})]})]}),Jt=({device:t,x:n,y:l,nowSeconds:a,selected:d,sessions:u,sessionTotal:m,dropState:o,movingSessionId:k,draggedSessionId:N,onOpen:g,onChipPointerDown:j,onChipClick:I,onShowAllSessions:x})=>{const f=ue(t,a),r=xt(t,a),b=Kt(t,a);return e.jsxs("li",{"data-mesh-device":t.id,"data-mesh-state":t.state,"data-mesh-drop":o??void 0,"aria-current":d?"true":void 0,className:_("absolute flex flex-col rounded-md border border-l-4 border-control bg-elevated","hover:bg-row-hover",d&&"border-y-ink border-r-ink bg-row-selected",Vt[t.state],Xt[t.state],o&&Ut[o]),style:{left:n,top:l,width:He,height:ft},children:[e.jsxs("button",{type:"button","data-mesh-device-open":t.id,"aria-label":b,onClick:()=>g(t.id),className:_("flex w-full items-center gap-2 rounded-t-[5px] px-3 pt-2 pb-1 text-left","cursor-pointer","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]"),children:[e.jsx(pt,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-body-sm text-ink",children:t.label}),e.jsxs("span",{title:f,className:_("block truncate text-meta",Gt[t.state]),children:[r,t.memberships.length>1?` · ${t.memberships.length} networks`:""]})]})]}),e.jsxs("ul",{"aria-label":`Conversations on ${t.label}`,className:_("m-0 flex list-none items-center gap-1 overflow-hidden px-3 pb-2",o==="accept"&&"opacity-40"),children:[u.shown.map(w=>e.jsx(Qt,{session:w,ownerLabel:t.label,ownerReachable:t.reachable,moving:k===w.id,dragging:N===w.id,onPointerDown:j,onClick:()=>I(w)},w.id)),u.hidden>0&&e.jsx("li",{className:"shrink-0",children:e.jsxs("button",{type:"button","data-mesh-more":t.id,onClick:()=>x(t.id),className:_("rounded-sm px-1.5 py-0.5 text-meta text-ink-dim","hover:bg-row-hover hover:text-ink","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),title:`Showing ${u.shown.length} of ${m} conversations`,"aria-label":`Show all ${m} conversations`,children:["+",u.hidden]})}),u.rows.length===0&&Pe(t)!==null&&e.jsx("li",{className:"text-meta text-ink-dim",children:Pe(t)})]})]})};function Pe(t){return t.state==="self"?"no conversations here":t.sessionCount===0?"no conversations":null}const Qt=({session:t,ownerLabel:n,ownerReachable:l,moving:a,dragging:d,onPointerDown:u,onClick:m})=>{const o=Xe(t,n,l);return a?e.jsx("li",{role:"status","data-mesh-session":t.id,"data-mesh-moving":"true",children:e.jsx("span",{className:"rounded-sm bg-sunken px-1.5 py-0.5 text-meta text-ink-muted",children:"moving…"})}):e.jsx("li",{className:"min-w-0 flex-1","data-mesh-session-item":t.id,"data-mesh-dragging":d?"true":void 0,children:e.jsx("button",{type:"button","data-mesh-session":t.id,style:{touchAction:"none"},title:`${te(t)} · ${o}`,"aria-label":`${te(t)}, ${o}. Opens ${n}.`,onPointerDown:k=>u(k,t),onClick:()=>m(t),className:_("w-full max-w-32 truncate rounded-sm border border-hairline bg-surface px-1.5 py-0.5 text-left text-meta text-ink-muted","[direction:rtl]","cursor-grab active:cursor-grabbing","hover:text-ink",qt[bt(t,l)],d&&"opacity-60","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:te(t)})})},ze=48,Oe=1.25,en=.0015,tn=({graph:t,slots:n,nowSeconds:l,selectedDeviceId:a,sessions:d,sessionTotals:u,movingSessionId:m,canMove:o,onOpenDevice:k,onAskMove:N,onDropRefused:g,onShowAllSessions:j,summaryId:I})=>{const x=c.useRef(null),[f,r]=c.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[b,w]=c.useState({k:1,tx:0,ty:0}),O=c.useRef(!1),R=c.useRef(!1),L=c.useRef(null),v=c.useMemo(()=>kt(n),[n]),D=c.useMemo(()=>({selfDeviceId:t.selfDeviceId,devices:new Map(t.devices.map(s=>[s.id,s])),networks:new Map(t.networks.map(s=>[s.id,s]))}),[t]),[p,A]=c.useState(ce),q=c.useRef({kind:"ground"}),ne=c.useCallback((s,i)=>{const h=document.elementFromPoint(s,i),C=h?.closest("[data-mesh-device]");if(C){const B=C.getAttribute("data-mesh-device");if(B)return{kind:"device",deviceId:B}}const E=h?.closest("[data-mesh-network]");if(E){const B=E.getAttribute("data-mesh-network");if(B)return{kind:"network",networkId:B}}return{kind:"ground"}},[]),P=c.useMemo(()=>p.kind!=="dragging"&&p.kind!=="settling"?null:de(p.payload,p.target,D),[p,D]),Y=c.useCallback(s=>{if(!P)return null;if(P.kind==="plan"){const i=p.kind==="dragging"||p.kind==="settling"?p.target:null;return i&&i.kind==="device"&&i.deviceId===s?"accept":null}if(P.kind==="refused"){const i=p.kind==="dragging"||p.kind==="settling"?p.target:null;return i&&i.kind==="device"&&i.deviceId===s?"refuse":null}return null},[P,p]),Z=c.useCallback((s,i)=>{if(!o||s.button!==0)return;R.current=!1;const h=i.locality==="local"?t.selfDeviceId??"":i.owner_device,C=D.devices.get(h),E={session:i,ownerDeviceId:h,ownerLabel:C?.label??i.owner_device_name};try{s.currentTarget.setPointerCapture(s.pointerId)}catch{}A(B=>K(B,{kind:"press",payload:E,x:s.clientX,y:s.clientY,pointerId:s.pointerId}))},[o,D,t.selfDeviceId]),se=s=>{if(p.kind==="pressing"||p.kind==="dragging"){const i=ne(s.clientX,s.clientY);q.current=i,A(h=>K(h,{kind:"move",x:s.clientX,y:s.clientY,target:i}));return}U(s)},y=s=>{if(ie(s),p.kind!=="pressing"&&p.kind!=="dragging")return;if(p.kind==="pressing"){A(h=>K(h,{kind:"cancel"}));return}const i=de(p.payload,p.target,D);R.current=!0,A(h=>K(h,{kind:"release"})),i.kind==="plan"?N({plan:i.plan,alternatives:i.alternatives,risky:i.risky}):i.kind==="refused"&&g({code:i.code,sentence:i.sentence,remedy:i.remedy,plan:i.plan??null}),A(h=>K(h,{kind:"settled"}))};c.useEffect(()=>()=>A(ce),[]);const T=c.useCallback(()=>{w(Ee(v.bounds,f))},[v.bounds,f]);c.useEffect(()=>{const s=x.current;if(!s)return;const i=()=>{const C=s.getBoundingClientRect();r({width:C.width,height:C.height,clipWidth:s.clientWidth,clipHeight:s.clientHeight,left:C.left,top:C.top})};i();const h=new ResizeObserver(i);return h.observe(s),()=>h.disconnect()},[]),c.useEffect(()=>{O.current||f.width<=0||f.height<=0||(O.current=!0,w(Ee(v.bounds,f)))},[f,v.bounds]),c.useEffect(()=>{const s=L.current;if(L.current={width:f.width,height:f.height},!s||!O.current||f.width<=0||f.height<=0||f.width>=s.width&&f.height>=s.height||!a)return;const i=v.devices.get(a);i&&w(h=>{const C={width:f.clipWidth,height:f.clipHeight},E=Math.max(0,Math.min(C.width-v.bounds.width*h.k,C.height-v.bounds.height*h.k));return vt(h,i,C,Math.min(gt,E))})},[f,a,v]);const M=p.kind==="dragging"?{x:p.x-f.left+12,y:p.y-f.top+12}:{x:0,y:0},W=P?At(P):null,S=c.useRef(null),F=c.useRef(null),H=c.useRef(null),X=c.useRef(null),le=c.useCallback(()=>{H.current=null;const s=S.current,i=F.current;if(S.current=null,F.current=null,s){const h=X.current;if(!h)return;w({k:h.transform.k,tx:h.transform.tx+(s.x-h.x),ty:h.transform.ty+(s.y-h.y)});return}i&&w(h=>me(h,{x:i.x,y:i.y},h.k*Math.exp(-i.deltaY*en)))},[]),J=c.useCallback(()=>{H.current===null&&(H.current=requestAnimationFrame(le))},[le]);c.useEffect(()=>()=>{H.current!==null&&cancelAnimationFrame(H.current)},[]);const he=s=>{!(s.target===s.currentTarget)&&s.button!==1||s.button!==0&&s.button!==1||(X.current={x:s.clientX,y:s.clientY,transform:b},s.currentTarget.setPointerCapture(s.pointerId),s.preventDefault())},U=s=>{X.current&&(S.current={x:s.clientX,y:s.clientY},J())},ie=s=>{X.current&&(X.current=null,S.current=null,s.currentTarget.hasPointerCapture(s.pointerId)&&s.currentTarget.releasePointerCapture(s.pointerId))},G=c.useCallback(s=>{if(s.deltaY===0)return;s.preventDefault();const i=s.currentTarget.getBoundingClientRect();F.current={x:s.clientX-i.left,y:s.clientY-i.top,deltaY:s.deltaY},J()},[J]);c.useEffect(()=>{const s=x.current;if(s)return s.addEventListener("wheel",G,{passive:!1}),()=>s.removeEventListener("wheel",G)},[G]);const Q=s=>{const i=s.shiftKey?ze*4:ze;switch(s.key){case"Escape":if(p.kind!=="pressing"&&p.kind!=="dragging")return;s.preventDefault(),p.kind==="dragging"&&(R.current=!0),A(h=>K(h,{kind:"cancel"}));return;case"0":s.preventDefault(),T();return;case"+":case"=":s.preventDefault(),w(h=>me(h,{x:f.width/2,y:f.height/2},h.k*Oe));return;case"-":case"_":s.preventDefault(),w(h=>me(h,{x:f.width/2,y:f.height/2},h.k/Oe));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{s.preventDefault();const h=s.key==="ArrowLeft"?i:s.key==="ArrowRight"?-i:0,C=s.key==="ArrowUp"?i:s.key==="ArrowDown"?-i:0;w(E=>({...E,tx:E.tx+h,ty:E.ty+C}));return}}};return e.jsxs("div",{ref:x,"data-mesh-canvas":"",role:"group","aria-labelledby":I,tabIndex:0,onPointerDown:he,onPointerMove:se,onPointerUp:y,onPointerCancel:s=>{p.kind==="dragging"&&(R.current=!0),A(i=>K(i,{kind:"cancel"})),ie(s)},"data-mesh-gesture":p.kind,onKeyDown:Q,onDoubleClick:s=>{s.target===s.currentTarget&&T()},className:_("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:[e.jsxs("div",{"data-mesh-world":"",className:"absolute top-0 left-0",style:{transform:`translate3d(${b.tx}px, ${b.ty}px, 0) scale(${b.k})`,transformOrigin:"0 0",width:v.bounds.width,height:v.bounds.height},children:[e.jsx(Yt,{edges:t.edges,geometry:v,selectedDeviceId:a}),e.jsx("ul",{"aria-label":"Networks",className:"m-0 list-none p-0",children:t.networks.map(s=>{const i=v.networks.get(s.id);return i?e.jsx(Zt,{network:s,x:i.x,y:i.y,refused:P?.kind==="refused"&&p.kind==="dragging"&&p.target.kind==="network"&&p.target.networkId===s.id},s.id):null})}),e.jsx("ul",{"aria-label":"Devices",className:"m-0 list-none p-0",children:t.devices.map(s=>{const i=v.devices.get(s.id);return i?e.jsx(Jt,{device:s,x:i.x,y:i.y,nowSeconds:l,selected:s.id===a,sessions:d.get(s.id)??{rows:[],shown:[],hidden:0},sessionTotal:u.get(s.id)??s.sessionCount??0,dropState:Y(s.id),movingSessionId:m,draggedSessionId:Bt(p),onOpen:k,onChipPointerDown:Z,onChipClick:()=>{if(R.current){R.current=!1;return}k(s.id)},onShowAllSessions:j},s.id):null})})]}),p.kind==="dragging"&&e.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:M.x,top:M.y},children:p.payload.session.name||"untitled"}),p.kind==="dragging"&&W&&e.jsx("div",{"data-mesh-indicator":"",className:_("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",P?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:M.x,maxWidth:Math.max(160,f.width-M.x-12),...M.y>f.height*.6?{bottom:Math.max(12,f.height-M.y+8)}:{top:M.y+24}},children:W})]})};function nn(t,n,l,a){const d=l.locality==="local"?n:l.owner_device,u=[];for(const m of t)if(m.id!==d){if(m.id===n){u.push({deviceId:m.id,label:a,verb:"Recall to this device",keepVerb:"Copy here, leave it there"});continue}u.push({deviceId:m.id,label:m.label,verb:`Move to ${m.label}`,keepVerb:`Copy to ${m.label}`})}return u}function sn(t,n,l){return nn(t.devices,t.selfDeviceId,n,l)}function Ge(t,n,l){const a=sn(t,n,l),d={selfDeviceId:t.selfDeviceId,devices:new Map(t.devices.map(o=>[o.id,o])),networks:new Map(t.networks.map(o=>[o.id,o]))},u=n.locality==="local"?t.selfDeviceId??"":n.owner_device,m=d.devices.get(u);return a.map(o=>{const k=de({session:n,ownerDeviceId:u,ownerLabel:m?.label??n.owner_device_name},{kind:"device",deviceId:o.deviceId},d);return{...o,refused:k.kind==="refused"&&k.code!=="busy"?k.sentence:null}})}const Ue=({session:t,destinations:n,disabled:l,onChoose:a,onOpenChange:d,trigger:u,triggerLabel:m})=>e.jsxs(it,{onOpenChange:d,children:[e.jsx(at,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":m,"data-mesh-session-menu":t.id,disabled:l||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:u})}),e.jsxs(rt,{align:"start",className:"min-w-56",children:[e.jsx(lt,{children:te(t)}),e.jsx(_e,{}),n.map(o=>e.jsx(Re,{"data-mesh-move-to":o.deviceId,disabled:!!o.refused,title:o.refused??void 0,onSelect:()=>a(o,!1),children:o.verb},o.deviceId)),e.jsx(_e,{}),n.map(o=>e.jsx(Re,{"data-mesh-copy-to":o.deviceId,disabled:!!o.refused,title:o.refused??void 0,onSelect:()=>a(o,!0),children:o.keepVerb},`keep-${o.deviceId}`))]})]}),an=({device:t,sessions:n,sessionTotal:l,nowSeconds:a,destinationsFor:d,movingSessionId:u,canMove:m,canInvite:o,onClose:k,onMove:N,onShowInList:g,onInvite:j,onRemoveMember:I})=>{const x=Be(t),f=l>n.rows.length?`${n.rows.length} of ${l}`:`${n.rows.length}`;return e.jsxs("aside",{"aria-label":`${t.label} details`,"data-mesh-panel":t.id,className:"flex w-80 shrink-0 flex-col gap-3 overflow-y-auto rounded-md border border-hairline bg-surface p-4",children:[e.jsxs("header",{className:"flex flex-col gap-1",children:[e.jsx($,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:k,children:"Close"}),e.jsx("h2",{className:"text-body-sm text-ink",children:t.label}),e.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[t.state==="suspect"&&e.jsx(wt,{"aria-hidden":"true",className:"size-3.5 text-danger"}),t.state==="unreachable"&&e.jsx(nt,{"aria-hidden":"true",className:"size-3.5 text-warning"}),x||ue(t,a)]}),t.reason&&e.jsx("p",{className:"text-meta text-warning",children:t.reason})]}),e.jsx(oe,{}),e.jsxs("section",{className:"flex flex-col gap-2",children:[e.jsx("h3",{className:"text-meta text-ink-dim",children:"Memberships"}),e.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:t.memberships.map(r=>e.jsxs("li",{className:"flex flex-col gap-1",children:[e.jsxs("span",{className:"flex items-center gap-2 text-body-sm text-ink",children:[e.jsx(ye,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),r.networkName]}),e.jsxs("span",{className:"text-meta text-ink-dim",children:[r.role||"member",r.capabilities.length>0?` · ${r.capabilities.join(", ")}`:"",r.active?"":" · revoked"]}),o&&r.active&&e.jsxs($,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${r.networkId}:${t.id}`,onClick:()=>I(t,r.networkId),children:["Remove from ",r.networkName,"…"]})]},r.networkId))}),o&&e.jsx($,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":t.id,onClick:()=>j(t),children:"Invite to a network…"})]}),e.jsx(oe,{}),e.jsxs("section",{className:"flex min-h-0 flex-col gap-2",children:[e.jsxs("h3",{className:"text-meta text-ink-dim",children:["Conversations ",e.jsxs("span",{className:"text-ink-disabled",children:["(",f,")"]})]}),n.rows.length===0?e.jsx("p",{className:"text-meta text-ink-dim",children:t.sessionCount===null?"This device did not report its conversations.":"No conversations here."}):e.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:n.rows.map(r=>e.jsxs("li",{"data-mesh-panel-session":r.id,className:_("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",u===r.id&&"border-control"),children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",children:te(r)}),e.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:Xe(r,t.label,t.reachable)}),u===r.id?e.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:"moving…"}):e.jsx(Ue,{session:r,destinations:d(r),disabled:!m,onChoose:(b,w)=>N(r,b,w),trigger:e.jsx(Ye,{"aria-hidden":"true",className:"size-4"}),triggerLabel:`Move ${te(r)}`})]},r.id))}),t.endpoints.length>0&&e.jsx(st,{content:t.endpoints.join(`
|
|
2
2
|
`),children:e.jsxs("span",{className:"w-fit text-meta text-ink-dim",children:[t.endpoints.length," ",t.endpoints.length===1?"address":"addresses"]})})]}),e.jsx(oe,{}),e.jsx($,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":t.id,onClick:()=>g(t.id),children:"Show in list"})]})},rn=["name","chats","state"],ln={name:"Name",chats:"Conversations",state:"State"},We={suspect:0,unreachable:1,self:2,reachable:3};function on(t,n){const l=[...t];switch(n){case"chats":return l.sort((a,d)=>(d.sessionCount??-1)-(a.sessionCount??-1)||a.label.localeCompare(d.label)),l;case"state":return l.sort((a,d)=>We[a.state]-We[d.state]||a.label.localeCompare(d.label)),l;default:return l.sort((a,d)=>a.label.localeCompare(d.label))}}const Fe=8;function dn(t,n){if(t.locality==="local")return t.live_state||"here";const l=t.owner_device_name||n,a=t.live_state?` · ${t.live_state}`:"";return t.reachable?`on ${l}${a}`:`on ${l} (not answering)`}const cn=({graph:t,nowSeconds:n,selectedDeviceId:l,sessions:a,selfLabel:d,canMove:u,onSelect:m,onMove:o,onInvite:k,onRemove:N})=>{const[g,j]=c.useState("name"),I=c.useMemo(()=>t.networks.map(x=>({network:x,members:on(t.devices.filter(f=>f.memberships.some(r=>r.networkId===x.id)),g)})),[t,g]);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pr-1",children:[e.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[e.jsx("legend",{className:"sr-only",children:"Sort devices by"}),e.jsx("div",{className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:rn.map(x=>e.jsx("button",{type:"button","aria-pressed":g===x,onClick:()=>j(x),className:_("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",g===x&&"bg-surface text-ink"),children:ln[x]},x))})]}),I.map(({network:x,members:f})=>e.jsxs("section",{"data-mesh-network-group":x.id,className:"flex flex-col gap-2",children:[e.jsxs("h2",{className:"flex flex-wrap items-baseline gap-2 text-body-sm text-ink",title:`epoch ${x.epoch}`,children:[x.label,e.jsxs("span",{className:"text-meta text-ink-dim",children:[x.trust," · ",x.memberCount," ",x.memberCount===1?"device":"devices",x.revokedCount>0?` · ${x.revokedCount} revoked`:""]})]}),e.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:f.map(r=>{const b=r.memberships.find(v=>v.networkId===x.id),w=r.id===l,O=a.get(r.id),R=O?.rows??[],L=O?Ve(O,r.sessionCount):r.sessionCount??0;return e.jsxs("li",{"data-mesh-device-row":r.id,"data-mesh-state":r.state,"aria-current":w?"true":void 0,className:_("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",w&&"border-ink bg-row-selected"),children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[e.jsx("button",{type:"button","data-mesh-device-open":r.id,onClick:()=>m(r.id),className:_("min-w-0 flex-1 truncate text-left text-body-sm text-ink","hover:text-ink-muted","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:r.label}),e.jsx("span",{className:_("shrink-0 text-meta",r.state==="unreachable"&&"text-warning",r.state==="suspect"&&"text-danger",r.state==="self"&&"text-accent",r.state==="reachable"&&"text-ink-muted"),children:ue(r,n)}),e.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[b?.role?`${b.role} · `:"",b&&!b.active?"revoked":"member"]})]}),R.length>0?e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"my-1"}),e.jsx("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:R.slice(0,Fe).map(v=>e.jsxs("li",{"data-mesh-row-session":v.id,className:"flex items-center gap-2 py-0.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-meta text-ink-muted",children:v.name||v.id}),e.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:dn(v,d)}),e.jsx(Ue,{session:v,destinations:Ge(t,v,d),disabled:!u,onChoose:(D,p)=>o(v,D,p),trigger:e.jsx(Ye,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:`Move ${v.name||v.id}`})]},v.id))}),L>R.slice(0,Fe).length&&e.jsx("button",{type:"button",onClick:()=>m(r.id),className:"w-fit text-meta text-ink-dim hover:text-ink",children:`show all ${L} in the panel`})]}):e.jsx("span",{className:"text-meta text-ink-dim",children:L===0?"no conversations":L===1?"1 conversation":`${L} conversations`}),(b?.active||r.state!=="self")&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[e.jsx($,{size:"sm",variant:"ghost","data-mesh-invite":r.id,onClick:()=>k({deviceId:r.id,deviceLabel:r.label}),children:"Invite to a network…"}),b?.active&&e.jsxs($,{size:"sm",variant:"ghost","data-mesh-remove-member":`${x.id}:${r.id}`,onClick:()=>N({networkId:x.id,networkLabel:x.label,deviceId:r.id,deviceLabel:r.label}),children:["Remove from ",x.label,"…"]})]})]},r.id)})})]},x.id)),t.unmatchedPeers.length>0&&e.jsxs("p",{className:"text-meta text-warning",children:[t.unmatchedPeers.length," ",t.unmatchedPeers.length===1?"device":"devices"," answered the peer read but is in no network this app can name."]})]})},un=["canvas","list"],hn={canvas:"Canvas",list:"List"},mn=({state:t,graph:n,nowSeconds:l,checking:a,staleError:d,onRetry:u,sessions:m,sessionError:o,selfLabel:k,movingSessionId:N,canMove:g,pendingMove:j,onAskMove:I,onDropRefused:x,onChooseMove:f,onCancelMove:r,moveBusy:b,moveReport:w,onDismissReport:O,onWaitForIdle:R,onUndoCopy:L,invite:v,onOpenInvite:D,onInvite:p,onCloseInvite:A,inviteBusy:q,inviteReceipt:ne,inviteRefusal:P,remove:Y,onOpenRemove:Z,onRemove:se,onCloseRemove:y,removeBusy:T,removeRefusal:M,removed:W})=>{const[S,F]=c.useState("canvas"),[H,X]=c.useState(null),le=n?jt(n):"",J="mesh-summary",he=yt(n),U=Nt(n,m,n?.selfDeviceId??null),ie=c.useMemo(()=>{const i=new Map;for(const h of n?.devices??[]){const C=U.byDevice.get(h.id);i.set(h.id,C?Ve(C,h.sessionCount):h.sessionCount??0)}return i},[n,U]),G=c.useCallback(i=>{X(i)},[]),Q=n?n.devices.find(i=>i.id===H)??null:null,s=c.useCallback((i,h,C)=>{if(!n)return null;const E={selfDeviceId:n.selfDeviceId,devices:new Map(n.devices.map(V=>[V.id,V])),networks:new Map(n.networks.map(V=>[V.id,V]))},B=i.locality==="local"?n.selfDeviceId??"":i.owner_device,Ke=E.devices.get(B),z=de({session:i,ownerDeviceId:B,ownerLabel:Ke?.label??i.owner_device_name},{kind:"device",deviceId:h.deviceId},E);if(z.kind==="refused")return x({code:z.code,sentence:z.sentence,remedy:z.remedy,plan:z.plan??null}),null;if(z.kind==="none")return null;const Ne=C?z.alternatives.find(V=>V.keep)??z.plan:z.plan,qe=[z.plan,...z.alternatives].filter(V=>V.keep!==Ne.keep),Ze={plan:Ne,alternatives:qe,risky:z.risky};I(Ze)},[n,I,x]);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 p-6",children:[e.jsx(Qe,{title:"Mesh",icon:ye,subtitle:"Devices this app is paired with, and the networks that hold them.",children:e.jsxs("div",{className:"flex items-center gap-4",children:[a&&e.jsx("output",{className:"text-meta text-ink-dim",children:"checking…"}),(t.kind==="ready"||t.kind==="loading")&&e.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[e.jsx("legend",{className:"sr-only",children:"Presentation"}),e.jsx("div",{className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:un.map(i=>e.jsx("button",{type:"button","aria-pressed":S===i,disabled:t.kind!=="ready",onClick:()=>F(i),className:_("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",S===i&&"bg-surface text-ink"),children:hn[i]},i))})]})]})}),t.kind==="loading"&&e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[e.jsx(Te,{className:"h-4 w-64"}),e.jsx(Te,{className:"min-h-40 w-full flex-1"})]}),t.kind==="error"&&e.jsxs(ee,{variant:"warning",className:"flex-col items-start gap-2",children:[e.jsx("p",{children:t.message}),e.jsx($,{variant:"secondary",size:"sm",onClick:u,className:"w-fit",children:"Ask again"})]}),t.kind==="empty"&&e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center rounded-lg border border-hairline bg-surface p-6",children:e.jsxs("div",{className:"flex flex-col items-start gap-3",children:[e.jsx("h2",{className:"text-heading text-ink",children:"No network on this device"}),e.jsx("p",{className:"max-w-140 text-body-sm text-ink-muted",children:"This device is not in any network, so there is no mesh to draw. Create one on this machine:"}),e.jsx("code",{className:"rounded-sm bg-sunken px-2 py-1 font-mono text-meta text-ink",children:"lop network init <name>"}),e.jsx("p",{className:"text-meta text-ink-dim",children:"A network appears here once this device has joined one."})]})}),t.kind==="ready"&&n&&e.jsxs("div",{className:"flex min-h-0 flex-1 gap-4",children:[e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-3",children:[e.jsx("p",{id:J,className:"text-meta text-ink-muted","data-mesh-summary":"",children:le}),d&&e.jsx(ee,{variant:"warning",children:e.jsx("p",{children:d})}),o&&e.jsx(ee,{variant:"warning",children:e.jsx("p",{children:o})}),w&&e.jsx(Ft,{receipt:w.kind==="moved"?{verb:w.verb,detail:w.detail,undo:w.undo}:null,refusal:w.kind==="refused"?w.refusal:null,canWait:w.kind==="refused"&&w.plan!==null,onWait:R,onRecheck:u,onUndo:L,onDismiss:O,pending:b}),S==="canvas"?e.jsx(tn,{graph:n,slots:he,nowSeconds:l,selectedDeviceId:H,sessions:U.byDevice,sessionTotals:ie,movingSessionId:N,canMove:g,onOpenDevice:G,onAskMove:I,onDropRefused:x,onShowAllSessions:G,summaryId:J}):e.jsx(cn,{graph:n,nowSeconds:l,selectedDeviceId:H,sessions:U.byDevice,selfLabel:k,canMove:g,onSelect:G,onMove:s,onInvite:D,onRemove:Z})]}),Q&&e.jsx(an,{device:Q,sessions:U.byDevice.get(Q.id)??{rows:[],shown:[],hidden:0},sessionTotal:ie.get(Q.id)??0,nowSeconds:l,canMove:g,canInvite:t.kind==="ready",movingSessionId:N,destinationsFor:i=>Ge(n,i,k),onClose:()=>X(null),onMove:s,onInvite:i=>D({deviceId:i.id,deviceLabel:i.label}),onRemoveMember:(i,h)=>{const C=n.networks.find(E=>E.id===h);Z({networkId:h,networkLabel:C?.label??h,deviceId:i.id,deviceLabel:i.label})},onShowInList:i=>{G(i),F("list")}})]}),e.jsx(Pt,{open:j!==null,plan:j?.plan??xn,alternatives:j?.alternatives??[],risky:j?.risky??!1,busy:b,onCancel:r,onChoose:f}),v&&e.jsx(zt,{open:v.open,options:v.options,deviceId:v.deviceId,deviceLabel:v.deviceLabel,onClose:A,onInvite:p,pending:q,receipt:ne,refusal:P}),Y&&e.jsx(Ot,{open:Y.open,networkLabel:Y.networkLabel,deviceLabel:Y.deviceLabel,onClose:y,onConfirm:se,pending:T,refusal:M,removed:W})]})},xn={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},Nn=()=>{const t=Je(),n=Ie(t.data,"peers")==="enabled",l=Ie(t.data,"session_transfer")==="enabled",a=It(n),d=Ct(n),u=St(n),m=c.useMemo(()=>({peers:a,networks:d}),[a,d]),o=Dt(m),k=Mt(m),N=$t(),g=_t(),j=Rt(),[I,x]=c.useState(null),[f,r]=c.useState(null),[b,w]=c.useState(null),[O,R]=c.useState(null),[L,v]=c.useState(null),[D,p]=c.useState(null),[A,q]=c.useState(null),ne=c.useMemo(()=>{const y=Math.max(a.dataUpdatedAt,d.dataUpdatedAt);return Math.floor((y||Date.now())/1e3)},[a.dataUpdatedAt,d.dataUpdatedAt]),P=c.useCallback(()=>{a.refetch(),d.refetch(),u.refetch()},[a,d,u]),Y=c.useCallback((y,T)=>{x(null);const M={sessionId:y.sessionId,to:y.to,keep:y.keep,waitS:T??y.waitS};N.mutate(M,{onSuccess:W=>{if(W.kind==="moved"){const{receipt:S}=W,F=S.locality==="local"?"this device":k?.devices.find(H=>H.id===S.owner_device)?.label??S.owner_device;r({kind:"moved",verb:S.mode==="keep"?"Copied":"Moved",detail:S.mode==="keep"?`${F} holds a copy as ${S.new_session_id.slice(-6)}; the original is still here.`:`${F} holds it now${S.source_retired?"; the copy here is gone":""}.`,undo:S.mode==="keep"?{sessionId:S.new_session_id,to:"local",keep:!1,verb:`Bring the copy back from ${F}`,waitS:0,lost:re(F,"this device")}:null});return}r({kind:"refused",refusal:W.refusal,plan:y})},onError:()=>{r({kind:"refused",refusal:{code:"move_failed",sentence:"The move could not be sent. Nothing here changed; the list has been read again.",status:null,unconfirmed:!1},plan:y})}})},[k,N]),Z=c.useMemo(()=>{if(!k)return[];const y=b?.deviceId,T=y?k.devices.find(M=>M.id===y):void 0;return k.networks.filter(M=>{if(!T)return!0;const W=T.memberships.find(S=>S.networkId===M.id);return!W||!W.active}).map(M=>({id:M.id,label:M.label}))},[k,b]);if(!n)return e.jsx(Tt,{to:"/chat",replace:!0});const se=o.kind==="ready"?a.error?ae(a.error):d.error?ae(d.error):null:null;return e.jsx(mn,{state:o,graph:k,nowSeconds:ne,checking:a.isFetching||d.isFetching,staleError:se,onRetry:P,sessions:u.data??[],movingSessionId:N.isPending?N.variables?.sessionId??null:null,sessionError:u.isError?ae(u.error):null,selfLabel:k?.devices.find(y=>y.state==="self")?.label??"this device",canMove:l,pendingMove:I,onAskMove:x,onDropRefused:y=>r({kind:"refused",refusal:{code:y.code,sentence:y.sentence,status:null,unconfirmed:!1},plan:y.plan}),onChooseMove:y=>Y(y),onCancelMove:()=>x(null),moveBusy:N.isPending,moveReport:f,onDismissReport:()=>r(null),onWaitForIdle:()=>{f?.kind!=="refused"||!f.plan||Y(f.plan,fn)},onUndoCopy:()=>{f?.kind!=="moved"||!f.undo||x({plan:f.undo,alternatives:[],risky:!1})},invite:b===null?null:{open:!0,deviceId:b.deviceId,deviceLabel:b.deviceLabel,options:Z},onOpenInvite:y=>{R(null),v(null),w(y)},onInvite:y=>{g.mutate(y,{onSuccess:T=>R(T),onError:T=>v({code:"invite_refused",sentence:ae(T),status:null,unconfirmed:!1})})},onCloseInvite:()=>w(null),inviteBusy:g.isPending,inviteReceipt:O,inviteRefusal:L,remove:D===null?null:{open:!0,networkId:D.networkId,networkLabel:D.networkLabel,deviceId:D.deviceId,deviceLabel:D.deviceLabel},onOpenRemove:y=>{q(null),p(y)},onRemove:y=>{D&&j.mutate({networkId:D.networkId,deviceId:D.deviceId,confirm:y},{onSuccess:T=>q(T)})},onCloseRemove:()=>p(null),removeBusy:j.isPending,removeRefusal:j.isError?{code:"remove_refused",sentence:ae(j.error),status:null,unconfirmed:!1}:null,removed:A})},fn=300;export{Nn as MeshPage,mn as MeshSurface,Nn as default};
|