local-operator-ui 0.46.6 → 0.46.7

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 (23) hide show
  1. package/out/renderer/assets/{agent-details-page-K289NUHT.js → agent-details-page-DxOcBjpW.js} +1 -1
  2. package/out/renderer/assets/{agent-hub-page-CSCc9Lee.js → agent-hub-page-Q9_X5CFP.js} +1 -1
  3. package/out/renderer/assets/{agents-page-D2CGjR5l.js → agents-page-D_twoMKH.js} +3 -3
  4. package/out/renderer/assets/{browser-page-Svij-U5I.js → browser-page-GBlF_XiR.js} +1 -1
  5. package/out/renderer/assets/{browser-webauthn-prompt-9XHhkc9I.js → browser-webauthn-prompt-DkqSn3Sr.js} +1 -1
  6. package/out/renderer/assets/{index-D9MeD_9S.js → index-pRJvOEvT.js} +2 -2
  7. package/out/renderer/assets/{legacy-agents-page-nvsx5uoH.js → legacy-agents-page-Bawvdt7h.js} +1 -1
  8. package/out/renderer/assets/{library-page-CTLf85Ok.js → library-page--nTYgR0k.js} +3 -3
  9. package/out/renderer/assets/{mesh-page-DE_mrX94.js → mesh-page-D1ZsRm8r.js} +1 -1
  10. package/out/renderer/assets/{notifications-page-CanxxkH0.js → notifications-page-Be_zCnpp.js} +1 -1
  11. package/out/renderer/assets/{org-access-BkIFhKI0.js → org-access-gAZxCRYK.js} +1 -1
  12. package/out/renderer/assets/{projects-page-DLiIT4z_.js → projects-page-CsaCVH12.js} +1 -1
  13. package/out/renderer/assets/{publication-validation-DAe6s6FK.js → publication-validation-CEPmXg_x.js} +1 -1
  14. package/out/renderer/assets/{radient-auth-buttons-DYdBNC_-.js → radient-auth-buttons-B6UxMMyL.js} +1 -1
  15. package/out/renderer/assets/{schedules-page-C8mqRXQe.js → schedules-page-Bis3PAo0.js} +1 -1
  16. package/out/renderer/assets/{settings-page-BVO85tKx.js → settings-page-t3dHQ3rA.js} +1 -1
  17. package/out/renderer/assets/{smartart-x0vHjcLD.js → smartart-BbzXlcrh.js} +1 -1
  18. package/out/renderer/assets/team-bridge-page-jEjSR01Y.js +36 -0
  19. package/out/renderer/assets/{use-default-on-banner-9GIy0N8O.js → use-default-on-banner-Dh8MzHSc.js} +1 -1
  20. package/out/renderer/assets/{use-download-agent-mutation-CDplGp13.js → use-download-agent-mutation-Bbx3LX_Y.js} +1 -1
  21. package/out/renderer/index.html +1 -1
  22. package/package.json +2 -2
  23. package/out/renderer/assets/team-bridge-page-DK2oXcTp.js +0 -36
@@ -1 +1 @@
1
- import{r as x,j as s,c as L}from"./index-C4ae8MIc.js";import{H as Ge,I as os,J as ds,K as se,L as cs,R as ms,M as xe,N as Ue,O as Q,Q as Ke,T as Ve,V as Xe,a as us,C as ke,q as we,W as hs}from"./path-utils-BqTfmiT0.js";import{P as ps}from"./page-header-BnTa4LRQ.js";import{u as z,B as V,A as ge,w as xs,G as fs,s as de,D as gs,d as vs,e as bs,H as _s,I as Re,f as Pe,g as Le}from"./error-boundary-BcPKKbP5.js";import{t as a}from"./messages-DoRCUI0R.js";import{T as pe,U as ks,V as ws,W as js,X as ys,Y as Ns,Z as Is,_ as Cs,$ as Ss,a0 as Ms,a1 as Ds,a2 as Es,a3 as As,a4 as Rs,a5 as Ie,a6 as Ps,a7 as Ls,a8 as Ce,a9 as Ze,aa as Je,ab as Ts,ac as fe,ad as je,ae as $s,af as Os,ag as ve,ah as Te,ai as Hs,aj as Ws,ak as ye,al as zs,am as Qe,an as be,ao as Fs,ap as es,aq as qs,ar as Bs,as as Ys,at as Gs,au as Us,av as Ks,aw as Vs,ax as Xs,ay as Zs,az as Js,aA as Qs,aB as et,aC as st,aD as tt,aE as nt,aF as at,aG as it,aH as rt,aI as lt,aJ as he,aK as ot}from"./index-D9MeD_9S.js";import{bh as Se,bi as Me,bj as dt,aA as ss}from"./conversation-input-sync-BwcOsVjK.js";import"./console-mirror-C-hKgNgn.js";function ct(e){return e==="failed"?"text-danger":pe(e)?"text-ink-muted":"text-ink-dim"}function mt(e){return e==="failed"?a("ui.mesh.mesh_approvals_tray.abandon"):a("ui.mesh.mesh_approvals_tray.stop")}function ut(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 ht=({rows:e,error:n,pending:t,refusal:d,onDecide:m,onRetry:h,nowSeconds:f,networkNames:l})=>{z();const b=t!==null,v=x.useMemo(()=>e.filter(o=>pe(o.state)),[e]),w=x.useMemo(()=>e.filter(o=>!pe(o.state)),[e]),[E,C]=x.useState(!1),c=x.useRef(null),u=x.useRef(null),p=x.useRef(null),j=(o,I)=>{I==="deny"&&v.some(A=>A.approvalId===o&&A.kind==="credential")&&(p.current={id:o,origin:document.activeElement,sawPending:!1}),m(o,I)};x.useLayoutEffect(()=>{const o=p.current;if(!o)return;if(t?.approvalId===o.id&&(o.sawPending=!0),d?.approvalId===o.id){p.current=null;return}const I=e.find(S=>S.approvalId===o.id);if(I?.state==="requested"){!t&&o.sawPending&&(p.current=null);return}if(I?.state==="denied"&&t||(p.current=null,I?.state!=="denied"||document.activeElement!==document.body&&document.activeElement!==o.origin))return;(v.length?c.current?.querySelector('[data-tour-tag="mesh-approval-controls"] button:not(:disabled)'):u.current?.querySelector("button"))?.focus({preventScroll:!0})},[e,t,d,v.length]);const N=w.some(o=>o.state==="failed"),D=w.filter(o=>o.state==="failed").length,y=d!==null&&e.some(o=>o.approvalId===d.approvalId&&(pe(o.state)||E));return v.length===0&&w.length===0&&!n&&!d?null:s.jsxs("section",{ref:c,"aria-label":a("ui.mesh.mesh_approvals_tray.approvals"),"data-tour-tag":"mesh-approvals-tray",className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(ks,{"aria-hidden":"true",className:"size-4 text-ink-muted"}),s.jsx("h2",{className:"text-body-sm text-ink",children:a("ui.mesh.mesh_approvals_tray.approvals")}),v.length>0&&s.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_approvals_tray.waiting_count",{count:v.length})})]}),n&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("p",{className:"min-w-0 flex-1 text-meta text-ink-muted",children:n}),s.jsx(V,{variant:"secondary",size:"sm",onClick:h,children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),v.length>0&&s.jsx("ul",{className:"flex flex-col divide-y divide-hairline",children:v.map(o=>s.jsx($e,{row:o,pending:t?.approvalId===o.approvalId?t:null,busy:b,refusal:d?.approvalId===o.approvalId?d:null,onDecide:j,nowSeconds:f,networkNames:l},o.approvalId))}),d&&!y&&s.jsx(ts,{refusal:d}),w.length>0&&s.jsx("div",{ref:u,children:s.jsx(Se,{open:E,onOpenChange:C,chevronClassName:"text-ink-dim",className:L(v.length>0&&"border-hairline border-t pt-3"),summary:s.jsxs("span",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[a("ui.mesh.mesh_approvals_tray.settled_approvals"),s.jsxs("span",{className:"text-ink-dim",children:["(",w.length,")"]}),N&&s.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-danger"}),D>0&&s.jsx("span",{className:"text-danger",children:a("ui.mesh.mesh_approvals_tray.failed_count",{count:D})})]}),children:s.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-records",children:w.map(o=>s.jsx($e,{row:o,pending:t?.approvalId===o.approvalId?t:null,busy:b,refusal:d?.approvalId===o.approvalId?d:null,onDecide:j,nowSeconds:f,networkNames:l},o.approvalId))})})})]})},$e=({row:e,pending:n,busy:t,refusal:d,onDecide:m,nowSeconds:h,networkNames:f})=>{z();const l=pe(e.state),b=ws(e),v=js(e,f),w=ys(e,f),E=Ns(e),C=Is(e),c=Cs(e),u=Ss(e.expiresAt,h),p=e.kind==="credential"||e.kind==="unknown",j=p||e.canApproveHere===!1,N=j?[]:ut(e.state),D=Ms(e),y=Ds(e.state);return s.jsxs("li",{className:"flex flex-col gap-2 py-3 first:pt-0 last:pb-0","data-tour-tag":"mesh-approval-card",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:L("text-meta",ct(e.state)),children:e.kind==="credential"&&e.state==="approved"?a("ui.mesh.approval.approved_pending_apply"):Es(e.state)}),s.jsx("div",{className:"grow"}),l&&u&&s.jsx("span",{className:"text-meta text-ink-dim",children:e.kind==="credential"?a("ui.mesh.approval.request_window",{remaining:u}):u})]}),s.jsx("p",{className:"text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-summary",children:l?v:b}),!j&&e.state==="failed"&&s.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")}),l&&j&&s.jsx("p",{className:"text-meta text-ink-muted whitespace-pre-wrap [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-cli-remedy",children:e.approveRemedy||a("ui.mesh.approval.cli_review")}),e.kind==="credential"&&e.state==="approved"&&s.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-apply-hint",children:e.details?.length?a("ui.mesh.approval.approved_apply_hint"):a("ui.mesh.approval.approved_details_missing")}),(D||y)&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[D&&s.jsx(V,{variant:"primary",size:"sm",disabled:t,onClick:()=>m(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:a("ui.mesh.mesh_approvals_tray.approve")}),y&&s.jsx(V,{variant:"ghost",size:"sm",disabled:t,onClick:()=>m(e.approvalId,"deny"),"data-tour-tag":l?"mesh-approval-deny":"mesh-approval-stop",children:l?a("ui.mesh.mesh_approvals_tray.deny"):mt(e.state)}),n&&s.jsx("span",{className:"text-meta text-ink-dim",children:n.decision==="approve"?a("ui.mesh.mesh_approvals_tray.waiting_for_the_signing_prompt"):a("ui.mesh.mesh_approvals_tray.writing_the_decision")})]}),s.jsxs(Se,{chevronClassName:"text-ink-dim",summary:s.jsx("span",{className:"text-meta",children:a("ui.mesh.mesh_approvals_tray.details")}),children:[p&&(e.details?.length?s.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((o,I)=>s.jsx("li",{className:"whitespace-pre-wrap",children:o},`${I}:${o}`))}):s.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.details_unavailable")})),w.length>0&&s.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:w.map(o=>s.jsxs(x.Fragment,{children:[s.jsx("dt",{className:"text-ink-muted",children:o.term}),s.jsx("dd",{children:o.consequence})]},o.term))}),(E||C)&&s.jsxs("p",{className:"text-meta text-ink-muted",children:[E&&s.jsx("span",{children:E}),E&&C&&s.jsx("span",{children:" · "}),C&&s.jsx("span",{className:"font-mono",children:C})]}),c&&s.jsx("p",{className:"text-meta text-ink-dim",children:c}),N.length>0&&s.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:N.map(o=>s.jsxs(x.Fragment,{children:[s.jsx("dt",{className:"text-ink-muted",children:o.term}),s.jsx("dd",{className:"text-ink-muted",children:o.text})]},o.term))})]}),d&&s.jsx(ts,{refusal:d})]})},ts=({refusal:e})=>(z(),s.jsx(ge,{variant:"warning",className:"text-meta","data-tour-tag":"mesh-approval-refusal",children:s.jsxs("span",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1",children:e.sentence}),s.jsx("span",{className:"shrink-0 font-mono text-ink-dim",children:e.code})]})})),pt=4,_e={kind:"idle"};function xt(e){switch(e.kind){case"dragging":case"settling":return e.payload.session.id;case"pressing":return null;default:return null}}function ee(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))<pt?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"?_e:e;case"cancel":case"settled":return _e;default:return e}}const ft=({edges:e,geometry:n,selectedDeviceId:t})=>s.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(d=>{const m=n.networks.get(d.networkId),h=n.devices.get(d.deviceId);if(!m||!h)return null;const f=t!==null&&d.deviceId===t;return s.jsx("path",{"data-mesh-edge":d.key,d:As(m,h),fill:"none",strokeWidth:f?2:1.5,className:f?"stroke-ink":"stroke-ink-dim"},d.key)})}),De=({deviceId:e,name:n,compact:t=!1,deviceIds:d,className:m})=>{z();const h=Ge({name:n});return s.jsxs("span",{className:L("flex min-w-0 items-baseline gap-2",m),"data-mesh-device-identity":e,children:[s.jsx(xs,{content:n?.trim()?h:null,children:s.jsx("span",{className:"min-w-0 flex-1 truncate text-start","data-mesh-device-name":"",children:h})}),s.jsx("span",{className:"shrink-0 font-mono text-meta text-ink-muted","data-mesh-device-id":"",title:e,children:t?os(e,d):e})]})},gt={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 vt(e){return e.suspect?"border-l-danger":gt[se(e)]}const bt={self:"ring-2 ring-accent",reachable:null,relay_down:null,handshake_refused:null,unreachable:null,suspect:null},_t={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function kt(e,n,t){return[Ge(e),e.id,Je(e,n),t].filter(Boolean).join(", ")}function te(e){return e.name.trim()||e.id.slice(-6)}function ns(e,n,t){if(t!=="reached"&&t!=="self"){const d=xe(t);return e.unreachable_reason?`${d} (${e.unreachable_reason})`:d}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 wt={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},jt=({network:e,x:n,y:t,refused:d})=>(z(),s.jsxs("li",{"data-mesh-network":e.id,"data-mesh-network-refused":d?"true":void 0,"data-glass-block":"",className:L("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",d?"border-warning":"border-hairline"),style:{left:n,top:t,width:Ie,height:Rs},children:[s.jsx(Me,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block truncate text-body-sm text-ink",children:e.label}),s.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?s.jsxs(s.Fragment,{children:[" · ",a("ui.mesh.mesh_list.revoked_count",{count:e.revokedCount})]}):null]})]})]})),yt=({device:e,deviceIds:n,x:t,y:d,nowSeconds:m,selected:h,sessions:f,sessionTotal:l,dropState:b,movingSessionId:v,draggedSessionId:w,onOpen:E,onChipPointerDown:C,onChipClick:c,onShowAllSessions:u})=>{z();const{activity:p}=ds(e,f.rows),j=p==="working",N=kt(e,m,j?"working":null),D=se(e);return s.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":b??void 0,"aria-current":h?"true":void 0,"data-glass-block":"",className:L("absolute flex flex-col rounded-md border border-l-4 border-control bg-elevated","hover:bg-row-hover",h&&"border-y-ink border-r-ink bg-row-selected",vt(e),bt[e.state],b&&_t[b]),style:{left:t,top:d,width:Ie,height:Ps},children:[s.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":D,"aria-label":N,title:cs(e),onClick:()=>E(e.id),className:L("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:Ls},children:[s.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2",children:[s.jsx(dt,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),s.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&&s.jsx(Ce,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"})]}),s.jsxs("span",{className:"flex w-full min-w-0 items-baseline gap-1",children:[s.jsx("span",{className:"w-3 shrink-0 font-mono text-body-sm text-ink tabular-nums",children:e.sessionCount??"–"}),s.jsx("span",{className:L("min-w-0 truncate text-meta",e.sessionCount===null?"text-ink-dim":"text-ink-muted"),children:Ze(e.sessionCount)})]}),s.jsxs("span",{"data-mesh-state-line":"",className:"flex w-full min-w-0 items-baseline gap-1.5 text-meta",children:[s.jsx("span",{"aria-hidden":"true",className:"shrink-0 text-ink-dim",children:ms[D]}),s.jsx("span",{className:L("shrink-0",Ue[D]),children:xe(D)}),j&&s.jsx("span",{"data-mesh-working":"",className:"shrink-0 text-info",children:a("ui.mesh.mesh_node.working")}),e.memberships.length>1&&s.jsx("span",{className:"min-w-0 truncate text-ink-dim",children:a("ui.mesh.mesh_node.memberships",{count:e.memberships.length})})]})]}),s.jsxs("ul",{"aria-label":a("ui.mesh.mesh_node.conversations_on",{device:Q(e,n,!0)}),className:L("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",b==="accept"&&"opacity-40"),children:[f.shown.map(y=>s.jsx(Nt,{session:y,ownerLabel:Q(e,n,!0),ownerReach:D,ownerReachable:e.reachable,moving:v===y.id,dragging:w===y.id,onPointerDown:C,onClick:()=>c(y)},y.id)),f.hidden>0&&s.jsx("li",{className:"shrink-0",children:s.jsxs("button",{type:"button","data-mesh-more":e.id,onClick:()=>u(e.id),className:L("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:l}),"aria-label":a("ui.mesh.mesh_node.show_all_conversations",{count:l}),children:["+",f.hidden]})})]})]})},Nt=({session:e,ownerLabel:n,ownerReach:t,ownerReachable:d,moving:m,dragging:h,onPointerDown:f,onClick:l})=>{z();const b=ns(e,n,t);return m?s.jsx("li",{role:"status","data-mesh-session":e.id,"data-mesh-moving":"true",children:s.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")})}):s.jsx("li",{className:"min-w-0 flex-1","data-mesh-session-item":e.id,"data-mesh-dragging":h?"true":void 0,children:s.jsx("button",{type:"button","data-mesh-session":e.id,style:{touchAction:"none"},title:`${te(e)} · ${b}`,"aria-label":a("ui.mesh.mesh_node.open_conversation",{conversation:te(e),fact:b,owner:n}),onPointerDown:v=>f(v,e),onClick:()=>l(e),className:L("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",wt[Ts(e,d)],h&&"opacity-60","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:s.jsx("span",{className:"min-w-0 flex-1 truncate",children:te(e)})})})};function Oe(e){const n=e.trim();if(!n)return null;if(n.startsWith("[")){const d=n.indexOf("]");if(d<=1)return null;const m=n.slice(1,d),h=n.slice(d+1);if(!h)return{host:m,port:null};if(!h.startsWith(":"))return null;const f=Number(h.slice(1));return{host:m,port:Number.isInteger(f)?f:null}}const t=n.lastIndexOf(":");if(t>0){const d=n.slice(t+1);if(/^\d+$/.test(d))return{host:n.slice(0,t),port:Number(d)}}return{host:n,port:null}}function He(e){const n=e.trim().split(".");if(n.length!==4)return null;for(const t of n)if(!/^\d{1,3}$/.test(t)||Number(t)>255)return null;return`${n[0]}.${n[1]}.${n[2]}`}function It(e){return`${e}.x`}function Ct(e){const n=new Map;for(const d of e.values())for(const m of d)n.set(m,(n.get(m)??0)+1);const t=new Set;for(const[d,m]of n)m>1&&t.add(d);return t}function Ne(e){return new Set(e.endpoints.map(n=>n.trim()).filter(Boolean))}function St(e,n){const t=e.filter(c=>c.id!==n),d=e.find(c=>c.id===n)??null,m=new Map;for(const c of e)m.set(c.id,Ne(c));const h=Ct(m),f=new Set;for(const c of d?Ne(d):[]){if(h.has(c))continue;const u=Oe(c),p=u?He(u.host):null;p&&f.add(p)}const l=c=>{const u=new Set;for(const p of Ne(c)){if(h.has(p))continue;const j=Oe(p),N=j?He(j.host):null;N&&u.add(N)}return u},b=new Map,v=new Map;for(const c of t){const u=Mt(c);if(u){b.set(u,[...b.get(u)??[],c.id]);continue}for(const p of l(c))v.set(p,[...v.get(p)??[],c.id])}const w=new Map(e.map((c,u)=>[c.id,u])),E=c=>[...c].sort((u,p)=>(w.get(u)??0)-(w.get(p)??0)),C=[];for(const[c,u]of b)C.push({prefix:c,tier:"declared",deviceIds:E(u),get words(){return a("ui.mesh.mesh_scope.declared")}});for(const[c,u]of v)f.has(c)?C.push({prefix:c,tier:"shared",deviceIds:E(u),get words(){return a("ui.mesh.mesh_scope.shared_with_this_device")}}):u.length>1&&C.push({prefix:c,tier:"probable",deviceIds:E(u),get words(){return a("ui.mesh.mesh_scope.same_prefix")}});return C.sort((c,u)=>c.tier.localeCompare(u.tier)||c.prefix.localeCompare(u.prefix))}function Mt(e){for(const n of e.memberships){const t=n.scope.trim();if(t)return t}return""}const We={declared:0,shared:1,probable:2};function Dt(e,n){const t=new Map;for(const m of e){let h=null;for(const l of m.deviceIds){const b=n.get(l);b!==void 0&&(h===null||b<h.slot)&&(h={id:l,slot:b})}if(h===null)continue;const f=t.get(h.id);f===void 0?t.set(h.id,{slot:h.slot,groups:[m]}):f.groups.push(m)}const d=m=>{let h=-1;for(const f of m.deviceIds){const l=n.get(f);l!==void 0&&l>h&&(h=l)}return h};return[...t.entries()].sort((m,h)=>m[1].slot-h[1].slot).map(([m,h])=>({deviceId:m,groups:h.groups.sort((f,l)=>d(l)-d(f)||We[f.tier]-We[l.tier]||f.prefix.localeCompare(l.prefix))}))}function Et(e){return new Map(e.map(n=>[n.deviceId,n.groups.length]))}function At(e){return`${e.tier==="declared"?e.prefix:It(e.prefix)} · ${e.words}`}const ze=(e,n)=>e.deviceIds.map(t=>n.devices.get(t)).filter(t=>t!==void 0),Rt=({stacks:e,geometry:n})=>(z(),s.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(t=>{const d=t.groups.length,m=new Array(d).fill(0);let h=null;for(let l=d-1;l>=0;l-=1){const b=ze(t.groups[l],n),v=(b.length===0?0:Math.max(...b.map(w=>w.y+w.height)))+fe;h=h===null?v:Math.max(v,h+je),m[l]=h}const f=n.devices.get(t.deviceId);return t.groups.map((l,b)=>{const v=ze(l,n);if(v.length===0)return null;const w=d-1-b,E=Math.min(...v.map(N=>N.x)),C=Math.max(...v.map(N=>N.x)),u=(f?.y??Math.min(...v.map(N=>N.y)))-fe-$s*w,p=l.tier==="declared",j=At(l);return s.jsx("div",{"data-mesh-scope":`${l.tier}:${l.prefix}`,"data-mesh-scope-level":b,className:L("absolute rounded-lg",l.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:E-fe-je*w,top:u,width:C+Ie-E+(fe+je*w)*2,height:m[b]-u},children:s.jsx("span",{"data-mesh-scope-label":"",className:L("absolute bottom-full left-1 mb-0.5 whitespace-nowrap text-meta",l.tier==="probable"?"text-ink-dim":"text-ink-muted",p&&"font-medium"),children:j})},`${l.tier}:${l.prefix}`)})})})),Fe=48,qe=1.25,Pt=.0015,Lt=({graph:e,slots:n,nowSeconds:t,selectedDeviceId:d,sessions:m,sessionTotals:h,movingSessionId:f,canMove:l,onOpenDevice:b,onAskMove:v,onDropRefused:w,onShowAllSessions:E,summaryId:C})=>{z();const c=x.useRef(null),[u,p]=x.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[j,N]=x.useState({k:1,tx:0,ty:0}),D=x.useRef(!1),y=x.useRef(!1),o=x.useRef(null),I=x.useMemo(()=>St(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),A=x.useMemo(()=>Dt(I,n.devices),[I,n]),S=x.useMemo(()=>Os(n,Et(A)),[n,A]),M=x.useMemo(()=>({selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(i=>[i.id,i])),networks:new Map(e.networks.map(i=>[i.id,i]))}),[e]),[_,$]=x.useState(_e),ce=x.useRef({kind:"ground"}),ne=x.useCallback((i,r)=>{const g=document.elementFromPoint(i,r),R=g?.closest("[data-mesh-device]");if(R){const K=R.getAttribute("data-mesh-device");if(K)return{kind:"device",deviceId:K}}const W=g?.closest("[data-mesh-network]");if(W){const K=W.getAttribute("data-mesh-network");if(K)return{kind:"network",networkId:K}}return{kind:"ground"}},[]),T=x.useMemo(()=>_.kind!=="dragging"&&_.kind!=="settling"?null:ve(_.payload,_.target,M),[_,M]),Y=x.useCallback(i=>{if(!T)return null;if(T.kind==="plan"){const r=_.kind==="dragging"||_.kind==="settling"?_.target:null;return r&&r.kind==="device"&&r.deviceId===i?"accept":null}if(T.kind==="refused"){const r=_.kind==="dragging"||_.kind==="settling"?_.target:null;return r&&r.kind==="device"&&r.deviceId===i?"refuse":null}return null},[T,_]),ae=x.useCallback((i,r)=>{if(!l||i.button!==0)return;y.current=!1;const g=r.locality==="local"?e.selfDeviceId??"":r.owner_device,R=M.devices.get(g),W={session:r,ownerDeviceId:g,ownerLabel:R?Q(R,[...M.devices.keys()],!0):r.owner_device_name};try{i.currentTarget.setPointerCapture(i.pointerId)}catch{}$(K=>ee(K,{kind:"press",payload:W,x:i.clientX,y:i.clientY,pointerId:i.pointerId}))},[l,M,e.selfDeviceId]),ie=i=>{if(_.kind==="pressing"||_.kind==="dragging"){const r=ne(i.clientX,i.clientY);ce.current=r,$(g=>ee(g,{kind:"move",x:i.clientX,y:i.clientY,target:r}));return}X(i)},me=i=>{if(ue(i),_.kind!=="pressing"&&_.kind!=="dragging")return;if(_.kind==="pressing"){$(g=>ee(g,{kind:"cancel"}));return}const r=ve(_.payload,_.target,M);y.current=!0,$(g=>ee(g,{kind:"release"})),r.kind==="plan"?v({plan:r.plan,alternatives:r.alternatives,risky:r.risky}):r.kind==="refused"&&w({code:r.code,sentence:r.sentence,reach:r.reach,remedy:r.remedy,plan:r.plan??null}),$(g=>ee(g,{kind:"settled"}))};x.useEffect(()=>()=>$(_e),[]);const re=x.useCallback(()=>{N(Te(S.bounds,u))},[S.bounds,u]);x.useEffect(()=>{const i=c.current;if(!i)return;const r=()=>{const R=i.getBoundingClientRect();p({width:R.width,height:R.height,clipWidth:i.clientWidth,clipHeight:i.clientHeight,left:R.left,top:R.top})};r();const g=new ResizeObserver(r);return g.observe(i),()=>g.disconnect()},[]),x.useEffect(()=>{D.current||u.width<=0||u.height<=0||(D.current=!0,N(Te(S.bounds,u)))},[u,S.bounds]),x.useEffect(()=>{const i=o.current;if(o.current={width:u.width,height:u.height},!i||!D.current||u.width<=0||u.height<=0||u.width>=i.width&&u.height>=i.height||!d)return;const r=S.devices.get(d);r&&N(g=>{const R={width:u.clipWidth,height:u.clipHeight},W=Math.max(0,Math.min(R.width-S.bounds.width*g.k,R.height-S.bounds.height*g.k));return Hs(g,r,R,Math.min(zs,W))})},[u,d,S]);const q=_.kind==="dragging"?{x:_.x-u.left+12,y:_.y-u.top+12}:{x:0,y:0},le=T?Ws(T):null,G=x.useRef(null),k=x.useRef(null),P=x.useRef(null),O=x.useRef(null),U=x.useCallback(()=>{P.current=null;const i=G.current,r=k.current;if(G.current=null,k.current=null,i){const g=O.current;if(!g)return;N({k:g.transform.k,tx:g.transform.tx+(i.x-g.x),ty:g.transform.ty+(i.y-g.y)});return}r&&N(g=>ye(g,{x:r.x,y:r.y},g.k*Math.exp(-r.deltaY*Pt)))},[]),H=x.useCallback(()=>{P.current===null&&(P.current=requestAnimationFrame(U))},[U]);x.useEffect(()=>()=>{P.current!==null&&cancelAnimationFrame(P.current)},[]);const Z=i=>{!(i.target===i.currentTarget)&&i.button!==1||i.button!==0&&i.button!==1||(O.current={x:i.clientX,y:i.clientY,transform:j},i.currentTarget.setPointerCapture(i.pointerId),i.preventDefault())},X=i=>{O.current&&(G.current={x:i.clientX,y:i.clientY},H())},ue=i=>{O.current&&(O.current=null,G.current=null,i.currentTarget.hasPointerCapture(i.pointerId)&&i.currentTarget.releasePointerCapture(i.pointerId))},J=x.useCallback(i=>{if(i.deltaY===0)return;i.preventDefault();const r=i.currentTarget.getBoundingClientRect();k.current={x:i.clientX-r.left,y:i.clientY-r.top,deltaY:i.deltaY},H()},[H]);x.useEffect(()=>{const i=c.current;if(i)return i.addEventListener("wheel",J,{passive:!1}),()=>i.removeEventListener("wheel",J)},[J]);const oe=i=>{const r=i.shiftKey?Fe*4:Fe;switch(i.key){case"Escape":if(_.kind!=="pressing"&&_.kind!=="dragging")return;i.preventDefault(),_.kind==="dragging"&&(y.current=!0),$(g=>ee(g,{kind:"cancel"}));return;case"0":i.preventDefault(),re();return;case"+":case"=":i.preventDefault(),N(g=>ye(g,{x:u.width/2,y:u.height/2},g.k*qe));return;case"-":case"_":i.preventDefault(),N(g=>ye(g,{x:u.width/2,y:u.height/2},g.k/qe));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{i.preventDefault();const g=i.key==="ArrowLeft"?r:i.key==="ArrowRight"?-r:0,R=i.key==="ArrowUp"?r:i.key==="ArrowDown"?-r:0;N(W=>({...W,tx:W.tx+g,ty:W.ty+R}));return}}};return s.jsxs("div",{ref:c,"data-mesh-canvas":"",role:"group","aria-labelledby":C,tabIndex:0,onPointerDown:Z,onPointerMove:ie,onPointerUp:me,onPointerCancel:i=>{_.kind==="dragging"&&(y.current=!0),$(r=>ee(r,{kind:"cancel"})),ue(i)},"data-mesh-gesture":_.kind,"data-glass-well":"clear",onKeyDown:oe,onDoubleClick:i=>{i.target===i.currentTarget&&re()},className:L("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:[s.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`}}),s.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:S.bounds.width,height:S.bounds.height},children:[s.jsx(Rt,{stacks:A,geometry:S}),s.jsx(ft,{edges:e.edges,geometry:S,selectedDeviceId:d}),s.jsx("ul",{"aria-label":a("ui.mesh.mesh_canvas.networks"),className:"m-0 list-none p-0",children:e.networks.map(i=>{const r=S.networks.get(i.id);return r?s.jsx(jt,{network:i,x:r.x,y:r.y,refused:T?.kind==="refused"&&_.kind==="dragging"&&_.target.kind==="network"&&_.target.networkId===i.id},i.id):null})}),s.jsx("ul",{"aria-label":a("ui.mesh.mesh_canvas.devices"),className:"m-0 list-none p-0",children:e.devices.map(i=>{const r=S.devices.get(i.id);return r?s.jsx(yt,{device:i,deviceIds:e.devices.map(g=>g.id),x:r.x,y:r.y,nowSeconds:t,selected:i.id===d,sessions:m.get(i.id)??{rows:[],shown:[],hidden:0},sessionTotal:h.get(i.id)??i.sessionCount??0,dropState:Y(i.id),movingSessionId:f,draggedSessionId:xt(_),onOpen:b,onChipPointerDown:ae,onChipClick:()=>{if(y.current){y.current=!1;return}b(i.id)},onShowAllSessions:E},i.id):null})})]}),_.kind==="dragging"&&s.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:_.payload.session.name||"untitled"}),_.kind==="dragging"&&le&&s.jsx("div",{"data-mesh-indicator":"",className:L("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",T?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:q.x,maxWidth:Math.max(160,u.width-q.x-12),...q.y>u.height*.6?{bottom:Math.max(12,u.height-q.y+8)}:{top:q.y+24}},children:le})]})};function Tt(e,n,t,d){const m=t.locality==="local"?n:t.owner_device,h=[],f=e.map(l=>l.id);for(const l of e){if(l.id===m)continue;if(l.id===n){h.push({deviceId:l.id,label:d,verb:a("ui.mesh.mesh_card.recall_to_this_device"),keepVerb:a("ui.mesh.mesh_card.copy_here_leave_it_there")});continue}const b=Q(l,f,!0);h.push({deviceId:l.id,label:b,verb:a("ui.mesh.mesh_card.move_to",{device:b}),keepVerb:a("ui.mesh.mesh_card.copy_to",{device:b})})}return h}function $t(e,n,t){return Tt(e.devices,e.selfDeviceId,n,t)}function as(e,n,t){const d=$t(e,n,t),m={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(l=>[l.id,l])),networks:new Map(e.networks.map(l=>[l.id,l]))},h=n.locality==="local"?e.selfDeviceId??"":n.owner_device,f=m.devices.get(h);return d.map(l=>{const b=ve({session:n,ownerDeviceId:h,ownerLabel:f?Q(f,e.devices.map(v=>v.id),!0):n.owner_device_name},{kind:"device",deviceId:l.deviceId},m);return{...l,refused:b.kind==="refused"&&b.code!=="busy"?b.sentence:null}})}const is=({session:e,destinations:n,disabled:t,onChoose:d,onOpenChange:m,trigger:h,triggerLabel:f})=>(z(),s.jsxs(gs,{onOpenChange:m,children:[s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":f,"data-mesh-session-menu":e.id,disabled:t||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:h})}),s.jsxs(bs,{align:"start",className:"min-w-56",children:[s.jsx(_s,{children:te(e)}),s.jsx(Re,{}),n.map(l=>s.jsx(Pe,{"data-mesh-move-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>d(l,!1),children:l.verb},l.deviceId)),s.jsx(Re,{}),n.map(l=>s.jsx(Pe,{"data-mesh-copy-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>d(l,!0),children:l.keepVerb},`keep-${l.deviceId}`))]})]})),Ot=({device:e,deviceIds:n,sessions:t,sessionTotal:d,nowSeconds:m,destinationsFor:h,movingSessionId:f,canMove:l,canInvite:b,onClose:v,onMove:w,onShowInList:E,onInvite:C,onRemoveMember:c})=>{z();const u=se(e),p=Ke(e),j=e.reachable?[]:e.attempts??[];x.useEffect(()=>{const o=I=>{I.key!=="Escape"||I.defaultPrevented||I.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),v())};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[e.id,v]);const N=e.sessionCount===null?Ze(null):a("ui.mesh.mesh_card.conversation_count",{count:e.sessionCount}),D=e.suspect?Ve():[N,xe(u)].filter(Boolean).join(" · "),y=d>t.rows.length?a("ui.mesh.mesh_card.shown_of",{shown:t.rows.length,total:d}):`${t.rows.length}`;return s.jsxs("aside",{"aria-label":a("ui.mesh.mesh_card.device_details",{device:Q(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:[s.jsxs("header",{className:"flex flex-col gap-1",children:[s.jsx(V,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:v,children:a("ui.mesh.mesh_actions.close")}),s.jsx("h2",{className:"text-body-sm text-ink",children:s.jsx(De,{deviceId:e.id,deviceIds:n,name:e.name,compact:!0})}),s.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[e.suspect&&s.jsx(Ce,{"aria-hidden":"true",className:"size-3.5 text-danger"}),!e.suspect&&u==="unanswered"&&s.jsx(fs,{"aria-hidden":"true",className:"size-3.5 text-warning"}),D]})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex flex-col gap-2",children:[s.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.memberships")}),s.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:e.memberships.map(o=>s.jsxs("li",{className:"flex flex-col gap-1",children:[s.jsxs("span",{className:"flex items-center gap-2 text-body-sm text-ink",children:[s.jsx(Me,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),o.networkName]}),s.jsxs("span",{className:"text-meta text-ink-dim",children:[o.role||"member",o.capabilities.length>0?` · ${o.capabilities.join(", ")}`:""]}),b&&s.jsxs(V,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${o.networkId}:${e.id}`,onClick:()=>c(e,o.networkId),children:[a("ui.mesh.mesh_card.remove_from"),o.networkName,"…"]})]},o.networkId))}),b&&s.jsx(V,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":e.id,onClick:()=>C(e),children:a("ui.mesh.mesh_actions.invite_to_a_network")})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex shrink-0 flex-col gap-2",children:[s.jsxs("h3",{className:"text-meta text-ink-dim",children:[a("ui.mesh.mesh_card.conversations"),s.jsxs("span",{className:"text-ink-disabled",children:["(",se(e)!=="self"&&se(e)!=="reached"?Qe(null):y,")"]})]}),be(e,m)?s.jsx("p",{className:"text-meta text-warning",children:be(e,m)}):t.rows.length===0?s.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")}):s.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:t.rows.map(o=>s.jsxs("li",{"data-mesh-panel-session":o.id,className:L("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",f===o.id&&"border-control"),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",title:te(o),children:te(o)}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:ns(o,Q(e,n,!0),se(e))}),f===o.id?s.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:a("ui.mesh.mesh_card.moving")}):s.jsx(is,{session:o,destinations:h(o),disabled:!l,onChoose:(I,A)=>w(o,I,A),trigger:s.jsx(ss,{"aria-hidden":"true",className:"size-4"}),triggerLabel:a("ui.mesh.mesh_card.move_conversation",{conversation:te(o)})})]},o.id))})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex flex-col gap-2",children:[s.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.network_addresses")}),e.endpoints.length===0?s.jsx("p",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.no_address_published")}):s.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:e.endpoints.map(o=>s.jsxs("li",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-body-sm text-ink",children:o}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_card.advertised")})]},o))})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex flex-col gap-2",children:[s.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.status")}),s.jsxs("dl",{className:"m-0 flex flex-col gap-1",children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("dt",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.reach")}),s.jsx("dd",{className:"m-0 text-body-sm text-ink",children:xe(u)})]}),s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("dt",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.last_status_frame")}),s.jsx("dd",{className:"m-0 text-body-sm text-ink",children:e.lastSeenAt===null?a("ui.mesh.mesh_card.never"):Fs(m-e.lastSeenAt)})]})]}),!e.reachable&&(p!==""||j.length>0)&&s.jsxs("div",{className:"flex flex-col gap-1",children:[p&&s.jsx("p",{className:"m-0 text-meta text-warning",children:p}),e.linkState==="handshake_refused"&&s.jsx("p",{className:"m-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.handshake_refused_hint")}),j.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{id:`mesh-attempts-label-${e.id}`,className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.addresses_tried")}),s.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((o,I)=>{const A=Xe(o.detail);return s.jsxs("li",{"data-mesh-attempt":o.endpoint,className:"flex items-baseline justify-between gap-2",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-meta text-ink",children:o.endpoint}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:A})]},`${o.endpoint}:${I}`)})})]})]}),!p&&j.length===0&&e.reason&&s.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),s.jsx(de,{}),s.jsx(V,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>E(e.id),children:a("ui.mesh.mesh_card.show_in_list")})]})},Ht=["name","chats","state"],Wt={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")}},Be={suspect:0,relay_down:1,handshake_refused:2,unreachable:3,self:4,reachable:5};function zt(e,n){const t=[...e];switch(n){case"chats":return t.sort((d,m)=>(m.sessionCount??-1)-(d.sessionCount??-1)||d.label.localeCompare(m.label)),t;case"state":return t.sort((d,m)=>Be[d.state]-Be[m.state]||d.label.localeCompare(m.label)),t;default:return t.sort((d,m)=>d.label.localeCompare(m.label))}}const Ye=8;function Ft(e,n){if(e.locality==="local")return e.live_state||"here";const t=e.owner_device_name||n,d=e.live_state?` · ${e.live_state}`:"";return e.reachable?a("ui.mesh.mesh_list.on_device_state",{device:t,state:d}):a("ui.mesh.mesh_list.on_device_no_answer",{device:t})}const qt=({graph:e,nowSeconds:n,selectedDeviceId:t,sessions:d,selfLabel:m,canMove:h,onSelect:f,onMove:l,onInvite:b,onRemove:v})=>{z();const[w,E]=x.useState("name"),C=x.useMemo(()=>e.networks.map(c=>({network:c,members:zt(e.devices.filter(u=>u.memberships.some(p=>p.networkId===c.id)),w)})),[e,w]);return s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pe-1",children:[s.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[s.jsx("legend",{className:"sr-only",children:a("ui.mesh.mesh_list.sort_devices_by")}),s.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Ht.map(c=>s.jsx("button",{type:"button","aria-pressed":w===c,onClick:()=>E(c),className:L("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",w===c&&"bg-surface text-ink"),children:Wt[c]},c))})]}),C.map(({network:c,members:u})=>s.jsxs("section",{"data-mesh-network-group":c.id,className:"flex flex-col gap-2",children:[s.jsxs("h2",{className:"flex flex-wrap items-baseline gap-2 text-body-sm text-ink",title:a("ui.mesh.mesh_list.epoch",{epoch:c.epoch}),children:[c.label,s.jsxs("span",{className:"text-meta text-ink-dim",children:[c.trust," ·"," ",a("ui.mesh.mesh_graph.device_count",{count:c.memberCount}),c.revokedCount>0?s.jsxs(s.Fragment,{children:[" · ",a("ui.mesh.mesh_list.revoked_count",{count:c.revokedCount})]}):null]})]}),s.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:u.map(p=>{const j=p.memberships.find(M=>M.networkId===c.id),N=p.id===t,D=d.get(p.id),y=D?.rows??[],o=D?es(D,p.sessionCount):p.sessionCount??0,I=se(p),A=Ke(p),S=p.reachable?[]:p.attempts??[];return s.jsxs("li",{"data-mesh-device-row":p.id,"data-mesh-state":p.state,"aria-current":N?"true":void 0,className:L("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",N&&"border-ink bg-row-selected"),children:[s.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[s.jsx("button",{type:"button","data-mesh-device-open":p.id,onClick:()=>f(p.id),className:L("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:s.jsx(De,{deviceId:p.id,name:p.name})}),s.jsxs("span",{className:L("flex shrink-0 items-center gap-1 text-meta",Ue[I]),"data-mesh-reach":I,children:[p.suspect&&s.jsx(Ce,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),p.suspect?xe(I):Je(p,n),p.suspect&&s.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:Ve()})]}),s.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[j?.role?`${j.role} · `:"",a("ui.mesh.mesh_list.member")]})]}),(A!==""||S.length>0)&&!p.reachable&&s.jsxs("div",{className:"flex flex-col gap-0.5",children:[A&&s.jsx("span",{className:"text-meta text-warning",children:A}),S.map((M,_)=>{const $=Xe(M.detail);return s.jsx("span",{"data-mesh-attempt":M.endpoint,className:"text-meta text-ink-dim",children:$?`${M.endpoint} — ${$}`:M.endpoint},`${M.endpoint}:${_}`)})]}),be(p,n)?s.jsxs("span",{className:"text-meta text-warning",children:[a("ui.mesh.mesh_card.conversations")," (",Qe(null),") ·"," ",be(p,n)]}):y.length>0?s.jsxs(s.Fragment,{children:[s.jsx(de,{className:"my-1"}),s.jsx("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:y.slice(0,Ye).map(M=>s.jsxs("li",{"data-mesh-row-session":M.id,className:"flex items-center gap-2 py-0.5",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-meta text-ink-muted",children:M.name||M.id}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:Ft(M,m)}),s.jsx(is,{session:M,destinations:as(e,M,m),disabled:!h,onChoose:(_,$)=>l(M,_,$),trigger:s.jsx(ss,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:a("ui.mesh.mesh_list.move_conversation",{conversation:M.name||M.id})})]},M.id))}),o>y.slice(0,Ye).length&&s.jsx("button",{type:"button",onClick:()=>f(p.id),className:"w-fit text-meta text-ink-dim hover:text-ink",children:a("ui.mesh.mesh_list.show_all_panel",{count:o})})]}):s.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_list.conversation_count",{count:o})}),(j||p.state!=="self")&&s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(V,{size:"sm",variant:"ghost","data-mesh-invite":p.id,onClick:()=>b({deviceId:p.id,deviceName:p.name}),children:a("ui.mesh.mesh_actions.invite_to_a_network")}),j&&s.jsxs(V,{size:"sm",variant:"ghost","data-mesh-remove-member":`${c.id}:${p.id}`,onClick:()=>v({networkId:c.id,networkLabel:c.label,deviceId:p.id,deviceName:p.name}),children:[a("ui.mesh.mesh_card.remove_from"),c.label,"…"]})]})]},p.id)})})]},c.id)),e.unmatchedPeers.length>0&&s.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")]})]})},Bt=({revoked:e})=>{if(e.length===0)return null;const n=a("ui.mesh.mesh_list.revoked_count",{count:e.length});return s.jsx(Se,{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:s.jsxs(s.Fragment,{children:[s.jsx("span",{"aria-hidden":"true",className:"inline-block whitespace-pre",children:" · "}),n]}),children:s.jsx("ul",{"data-mesh-revoked":"",className:"m-0 flex list-none flex-col gap-1 p-0",children:e.map(t=>s.jsxs("li",{"data-mesh-revoked-member":t.deviceId,className:"flex flex-wrap items-baseline gap-x-2 text-meta text-ink-dim",children:[s.jsx("span",{children:t.networkName}),s.jsx("span",{className:"font-mono text-body-sm text-ink",children:t.deviceId}),s.jsx("span",{className:"text-body-sm text-ink-muted",children:t.label}),s.jsxs("span",{children:[t.role?`${t.role} · `:"",a("ui.mesh.mesh_graph.revoked_membership")]})]},`${t.networkId}:${t.deviceId}`))})})},Yt=["canvas","list"],Gt={get canvas(){return a("ui.mesh.mesh_page.canvas")},get list(){return a("ui.mesh.mesh_page.list")}},Ut=({state:e,initialPresentation:n="canvas",graph:t,nowSeconds:d,checking:m,staleError:h,onRetry:f,approvals:l,sessions:b,sessionError:v,selfLabel:w,movingSessionId:E,canMove:C,pendingMove:c,onAskMove:u,onDropRefused:p,onChooseMove:j,onCancelMove:N,moveBusy:D,moveReport:y,onDismissReport:o,onWaitForIdle:I,onUndoCopy:A,invite:S,onOpenInvite:M,onInvite:_,onCloseInvite:$,inviteBusy:ce,inviteReceipt:ne,inviteRefusal:T,remove:Y,onOpenRemove:ae,onRemove:ie,onCloseRemove:me,removeBusy:re,removeRefusal:q,removed:le})=>{z();const[G,k]=x.useState(n),[P,O]=x.useState(null),U=t?qs(t):"",H="mesh-summary",Z=Bs(t),X=Ys(t,b,t?.selfDeviceId??null),ue=x.useMemo(()=>{const r=new Map;for(const g of t?.devices??[]){const R=X.byDevice.get(g.id);r.set(g.id,R?es(R,g.sessionCount):g.sessionCount??0)}return r},[t,X]),J=x.useCallback(r=>{O(r)},[]),oe=t?t.devices.find(r=>r.id===P)??null:null,i=x.useCallback((r,g,R)=>{if(!t)return null;const W={selfDeviceId:t.selfDeviceId,devices:new Map(t.devices.map(B=>[B.id,B])),networks:new Map(t.networks.map(B=>[B.id,B]))},K=r.locality==="local"?t.selfDeviceId??"":r.owner_device,Ee=W.devices.get(K),F=ve({session:r,ownerDeviceId:K,ownerLabel:Ee?Q(Ee,t.devices.map(B=>B.id),!0):r.owner_device_name},{kind:"device",deviceId:g.deviceId},W);if(F.kind==="refused")return p({code:F.code,sentence:F.sentence,reach:F.reach,remedy:F.remedy,plan:F.plan??null}),null;if(F.kind==="none")return null;const Ae=R?F.alternatives.find(B=>B.keep)??F.plan:F.plan,rs=[F.plan,...F.alternatives].filter(B=>B.keep!==Ae.keep),ls={plan:Ae,alternatives:rs,risky:F.risky};u(ls)},[t,u,p]);return s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[s.jsx(ps,{title:a("ui.mesh.mesh_page.mesh"),icon:Me,subtitle:a("ui.mesh.mesh_page.devices_this_app_is_paired_with_and"),children:s.jsxs("div",{className:"flex items-center gap-4",children:[m&&s.jsx("output",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_page.checking")}),(e.kind==="ready"||e.kind==="loading")&&s.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[s.jsx("legend",{className:"sr-only",children:a("ui.mesh.mesh_page.presentation")}),s.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Yt.map(r=>s.jsx("button",{type:"button","data-mesh-presentation":r,"aria-pressed":G===r,disabled:e.kind!=="ready",onClick:()=>k(r),className:L("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",G===r&&"bg-surface text-ink"),children:Gt[r]},r))})]})]})}),s.jsx(ht,{rows:l.rows,error:l.error,pending:l.pending,refusal:l.decisionRefusal,onDecide:l.onDecide,onRetry:l.onRetry,nowSeconds:l.nowSeconds,networkNames:new Map((t?.networks??[]).map(r=>[r.id,r.label]))}),e.kind==="loading"&&s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[s.jsx(Le,{className:"h-4 w-64"}),s.jsx(Le,{className:"min-h-40 w-full flex-1"})]}),e.kind==="error"&&s.jsxs(ge,{variant:"warning",className:"flex-col items-start gap-2",children:[s.jsx("p",{children:e.message}),s.jsx(V,{variant:"secondary",size:"sm",onClick:f,className:"w-fit",children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),e.kind==="empty"&&s.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:s.jsxs("div",{className:"flex flex-col items-start gap-3",children:[s.jsx("h2",{className:"text-heading text-ink",children:a("ui.mesh.mesh_page.no_network_on_this_device")}),s.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")}),s.jsx("code",{className:"rounded-sm bg-sunken px-2 py-1 font-mono text-meta text-ink",children:"lop network init <name>"}),s.jsx("p",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_page.a_network_appears_here_once_this_device")})]})}),e.kind==="ready"&&t&&s.jsx(s.Fragment,{children:s.jsxs("div",{className:"flex min-h-[22rem] flex-1 gap-4",children:[s.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-3",children:[s.jsxs("div",{id:H,className:"text-meta text-ink-muted","data-mesh-summary":"",children:[s.jsx("span",{children:U}),s.jsx(Bt,{revoked:t.revoked})]}),h&&s.jsx(ge,{variant:"warning",children:s.jsx("p",{children:h})}),v&&s.jsx(ge,{variant:"warning",children:s.jsx("p",{children:v})}),y&&s.jsx(Gs,{receipt:y.kind==="moved"?{verb:y.verb,detail:y.detail,undo:y.undo}:null,refusal:y.kind==="refused"?y.refusal:null,canWait:y.kind==="refused"&&y.plan!==null,onWait:I,onRecheck:f,onUndo:A,onDismiss:o,pending:D}),G==="canvas"?s.jsx(Lt,{graph:t,slots:Z,nowSeconds:d,selectedDeviceId:P,sessions:X.byDevice,sessionTotals:ue,movingSessionId:E,canMove:C,onOpenDevice:J,onAskMove:u,onDropRefused:p,onShowAllSessions:J,summaryId:H}):s.jsx(qt,{graph:t,nowSeconds:d,selectedDeviceId:P,sessions:X.byDevice,selfLabel:w,canMove:C,onSelect:J,onMove:i,onInvite:M,onRemove:ae})]}),oe&&s.jsx(Ot,{device:oe,deviceIds:t.devices.map(r=>r.id),sessions:X.byDevice.get(oe.id)??{rows:[],shown:[],hidden:0},sessionTotal:ue.get(oe.id)??0,nowSeconds:d,canMove:C,canInvite:e.kind==="ready",movingSessionId:E,destinationsFor:r=>as(t,r,w),onClose:()=>O(null),onMove:i,onInvite:r=>M({deviceId:r.id,deviceName:r.name}),onRemoveMember:(r,g)=>{const R=t.networks.find(W=>W.id===g);ae({networkId:g,networkLabel:R?.label??g,deviceId:r.id,deviceName:r.name})},onShowInList:r=>{J(r),k("list")}})]})}),s.jsx(Us,{open:c!==null,plan:c?.plan??Kt,alternatives:c?.alternatives??[],risky:c?.risky??!1,busy:D,onCancel:N,onChoose:j}),S&&s.jsx(Ks,{open:S.open,options:S.options,deviceId:S.deviceId,deviceName:S.deviceName,onClose:$,onInvite:_,pending:ce,receipt:ne,refusal:T}),Y&&s.jsx(Vs,{open:Y.open,networkLabel:Y.networkLabel,deviceId:Y.deviceId,deviceName:Y.deviceName,onClose:me,onConfirm:ie,pending:re,refusal:q,removed:le})]})},Kt={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},an=({initialPresentation:e})=>{z();const n=us(),t=ke(n.data,"peers")==="enabled",d=ke(n.data,"session_transfer")==="enabled",m=Xs(t,{stamp:()=>we.getState().beginAnswer()}),h=Zs(t),f=Js(t,{poll:!1,stamp:()=>we.getState().beginAnswer()}),l=x.useMemo(()=>({peers:m,networks:h}),[m,h]),b=Qs(l),v=et(l),w=st(),E=ke(n.data,"approvals")==="enabled",C=tt(t&&E,{poll:!1}),c=nt(),u=c.isError?{approvalId:c.variables?.approvalId??null,...at(c.error)}:null,p=x.useMemo(()=>Math.floor((C.dataUpdatedAt||Date.now())/1e3),[C.dataUpdatedAt]),j=we(k=>k.settlePlacement),N=it(),D=rt(),[y,o]=x.useState(null),[I,A]=x.useState(null),[S,M]=x.useState(null),[_,$]=x.useState(null),[ce,ne]=x.useState(null),[T,Y]=x.useState(null),[ae,ie]=x.useState(null),me=x.useMemo(()=>{const k=Math.max(m.dataUpdatedAt,h.dataUpdatedAt);return Math.floor((k||Date.now())/1e3)},[m.dataUpdatedAt,h.dataUpdatedAt]),re=x.useCallback(()=>{m.refetch(),h.refetch(),f.refetch()},[m,h,f]),q=x.useCallback((k,P)=>{o(null);const O={sessionId:k.sessionId,to:k.to,keep:k.keep,waitS:P??k.waitS};w.mutate(O,{onSuccess:U=>{if(U.kind==="moved"){const{receipt:H}=U;j(k.sessionId,H);const Z=H.locality==="local"?a("ui.mesh.mesh_drop.this_device"):v?.devices.find(X=>X.id===H.owner_device)?.label??H.owner_device;A({kind:"moved",verb:H.mode==="keep"?a("ui.mesh.mesh_page.copied"):a("ui.mesh.mesh_page.moved"),detail:H.mode==="keep"?a("ui.mesh.mesh_page.copy_receipt",{destination:Z,suffix:H.new_session_id.slice(-6)}):a("ui.mesh.mesh_page.move_receipt",{destination:Z,retirement:H.source_retired?a("ui.mesh.mesh_page.the_copy_here_is_gone"):""}),undo:H.mode==="keep"?{sessionId:H.new_session_id,to:"local",keep:!1,verb:a("ui.mesh.mesh_page.bring_copy_back",{device:Z}),waitS:0,lost:lt(Z,a("ui.mesh.mesh_drop.this_device"))}:null});return}A({kind:"refused",refusal:U.refusal,plan:k})},onError:()=>{A({kind:"refused",refusal:{code:"move_failed",sentence:a("ui.mesh.mesh_page.the_move_could_not_be_sent_nothing"),status:null,unconfirmed:!1},plan:k})}})},[v,w,j]),le=x.useMemo(()=>{if(!v)return[];const k=S?.deviceId,P=k?v.devices.find(O=>O.id===k):void 0;return v.networks.filter(O=>P?!P.memberships.some(U=>U.networkId===O.id):!0).map(O=>({id:O.id,label:O.label}))},[v,S]);if(!t)return s.jsx(hs,{to:"/chat",replace:!0});const G=b.kind==="ready"?m.error?he(m.error):h.error?he(h.error):null:null;return s.jsx(Ut,{initialPresentation:e,state:b,graph:v,nowSeconds:me,checking:m.isFetching||h.isFetching,staleError:G,onRetry:re,approvals:{rows:C.data??[],error:C.isError?ot(C.error):null,pending:c.isPending?c.variables??null:null,decisionRefusal:u,onDecide:(k,P)=>c.mutate({approvalId:k,decision:P}),onRetry:()=>void C.refetch(),nowSeconds:p},sessions:f.data?.rows??[],movingSessionId:w.isPending?w.variables?.sessionId??null:null,sessionError:f.isError?he(f.error):null,selfLabel:v?.devices.find(k=>k.state==="self")?.label??a("ui.mesh.mesh_drop.this_device"),canMove:d,pendingMove:y,onAskMove:o,onDropRefused:k=>A({kind:"refused",refusal:{code:k.code,sentence:k.sentence,reach:k.reach,status:null,unconfirmed:!1},plan:k.plan}),onChooseMove:k=>q(k),onCancelMove:()=>o(null),moveBusy:w.isPending,moveReport:I,onDismissReport:()=>A(null),onWaitForIdle:()=>{I?.kind!=="refused"||!I.plan||q(I.plan,Vt)},onUndoCopy:()=>{I?.kind!=="moved"||!I.undo||o({plan:I.undo,alternatives:[],risky:!1})},invite:S===null?null:{open:!0,deviceId:S.deviceId,deviceName:S.deviceName,options:le},onOpenInvite:k=>{$(null),ne(null),M(k)},onInvite:k=>{N.mutate(k,{onSuccess:P=>$(P),onError:P=>ne({code:"invite_refused",sentence:he(P),status:null,unconfirmed:!1})})},onCloseInvite:()=>M(null),inviteBusy:N.isPending,inviteReceipt:_,inviteRefusal:ce,remove:T===null?null:{open:!0,networkId:T.networkId,networkLabel:T.networkLabel,deviceId:T.deviceId,deviceName:T.deviceName},onOpenRemove:k=>{ie(null),Y(k)},onRemove:k=>{T&&D.mutate({networkId:T.networkId,deviceId:T.deviceId,confirm:k},{onSuccess:P=>ie(P)})},onCloseRemove:()=>Y(null),removeBusy:D.isPending,removeRefusal:D.isError?{code:"remove_refused",sentence:he(D.error),status:null,unconfirmed:!1}:null,removed:ae})},Vt=300;export{an as MeshPage,Ut as MeshSurface,an as default};
1
+ import{r as x,j as s,c as L}from"./index-C4ae8MIc.js";import{H as Ge,I as os,J as ds,K as se,L as cs,R as ms,M as xe,N as Ue,O as Q,Q as Ke,T as Ve,V as Xe,a as us,C as ke,q as we,W as hs}from"./path-utils-BqTfmiT0.js";import{P as ps}from"./page-header-BnTa4LRQ.js";import{u as z,B as V,A as ge,w as xs,G as fs,s as de,D as gs,d as vs,e as bs,H as _s,I as Re,f as Pe,g as Le}from"./error-boundary-BcPKKbP5.js";import{t as a}from"./messages-DoRCUI0R.js";import{T as pe,U as ks,V as ws,W as js,X as ys,Y as Ns,Z as Is,_ as Cs,$ as Ss,a0 as Ms,a1 as Ds,a2 as Es,a3 as As,a4 as Rs,a5 as Ie,a6 as Ps,a7 as Ls,a8 as Ce,a9 as Ze,aa as Je,ab as Ts,ac as fe,ad as je,ae as $s,af as Os,ag as ve,ah as Te,ai as Hs,aj as Ws,ak as ye,al as zs,am as Qe,an as be,ao as Fs,ap as es,aq as qs,ar as Bs,as as Ys,at as Gs,au as Us,av as Ks,aw as Vs,ax as Xs,ay as Zs,az as Js,aA as Qs,aB as et,aC as st,aD as tt,aE as nt,aF as at,aG as it,aH as rt,aI as lt,aJ as he,aK as ot}from"./index-pRJvOEvT.js";import{bh as Se,bi as Me,bj as dt,aA as ss}from"./conversation-input-sync-BwcOsVjK.js";import"./console-mirror-C-hKgNgn.js";function ct(e){return e==="failed"?"text-danger":pe(e)?"text-ink-muted":"text-ink-dim"}function mt(e){return e==="failed"?a("ui.mesh.mesh_approvals_tray.abandon"):a("ui.mesh.mesh_approvals_tray.stop")}function ut(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 ht=({rows:e,error:n,pending:t,refusal:d,onDecide:m,onRetry:h,nowSeconds:f,networkNames:l})=>{z();const b=t!==null,v=x.useMemo(()=>e.filter(o=>pe(o.state)),[e]),w=x.useMemo(()=>e.filter(o=>!pe(o.state)),[e]),[E,C]=x.useState(!1),c=x.useRef(null),u=x.useRef(null),p=x.useRef(null),j=(o,I)=>{I==="deny"&&v.some(A=>A.approvalId===o&&A.kind==="credential")&&(p.current={id:o,origin:document.activeElement,sawPending:!1}),m(o,I)};x.useLayoutEffect(()=>{const o=p.current;if(!o)return;if(t?.approvalId===o.id&&(o.sawPending=!0),d?.approvalId===o.id){p.current=null;return}const I=e.find(S=>S.approvalId===o.id);if(I?.state==="requested"){!t&&o.sawPending&&(p.current=null);return}if(I?.state==="denied"&&t||(p.current=null,I?.state!=="denied"||document.activeElement!==document.body&&document.activeElement!==o.origin))return;(v.length?c.current?.querySelector('[data-tour-tag="mesh-approval-controls"] button:not(:disabled)'):u.current?.querySelector("button"))?.focus({preventScroll:!0})},[e,t,d,v.length]);const N=w.some(o=>o.state==="failed"),D=w.filter(o=>o.state==="failed").length,y=d!==null&&e.some(o=>o.approvalId===d.approvalId&&(pe(o.state)||E));return v.length===0&&w.length===0&&!n&&!d?null:s.jsxs("section",{ref:c,"aria-label":a("ui.mesh.mesh_approvals_tray.approvals"),"data-tour-tag":"mesh-approvals-tray",className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(ks,{"aria-hidden":"true",className:"size-4 text-ink-muted"}),s.jsx("h2",{className:"text-body-sm text-ink",children:a("ui.mesh.mesh_approvals_tray.approvals")}),v.length>0&&s.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_approvals_tray.waiting_count",{count:v.length})})]}),n&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("p",{className:"min-w-0 flex-1 text-meta text-ink-muted",children:n}),s.jsx(V,{variant:"secondary",size:"sm",onClick:h,children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),v.length>0&&s.jsx("ul",{className:"flex flex-col divide-y divide-hairline",children:v.map(o=>s.jsx($e,{row:o,pending:t?.approvalId===o.approvalId?t:null,busy:b,refusal:d?.approvalId===o.approvalId?d:null,onDecide:j,nowSeconds:f,networkNames:l},o.approvalId))}),d&&!y&&s.jsx(ts,{refusal:d}),w.length>0&&s.jsx("div",{ref:u,children:s.jsx(Se,{open:E,onOpenChange:C,chevronClassName:"text-ink-dim",className:L(v.length>0&&"border-hairline border-t pt-3"),summary:s.jsxs("span",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[a("ui.mesh.mesh_approvals_tray.settled_approvals"),s.jsxs("span",{className:"text-ink-dim",children:["(",w.length,")"]}),N&&s.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-danger"}),D>0&&s.jsx("span",{className:"text-danger",children:a("ui.mesh.mesh_approvals_tray.failed_count",{count:D})})]}),children:s.jsx("ul",{className:"flex flex-col divide-y divide-hairline","data-tour-tag":"mesh-approvals-records",children:w.map(o=>s.jsx($e,{row:o,pending:t?.approvalId===o.approvalId?t:null,busy:b,refusal:d?.approvalId===o.approvalId?d:null,onDecide:j,nowSeconds:f,networkNames:l},o.approvalId))})})})]})},$e=({row:e,pending:n,busy:t,refusal:d,onDecide:m,nowSeconds:h,networkNames:f})=>{z();const l=pe(e.state),b=ws(e),v=js(e,f),w=ys(e,f),E=Ns(e),C=Is(e),c=Cs(e),u=Ss(e.expiresAt,h),p=e.kind==="credential"||e.kind==="unknown",j=p||e.canApproveHere===!1,N=j?[]:ut(e.state),D=Ms(e),y=Ds(e.state);return s.jsxs("li",{className:"flex flex-col gap-2 py-3 first:pt-0 last:pb-0","data-tour-tag":"mesh-approval-card",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:L("text-meta",ct(e.state)),children:e.kind==="credential"&&e.state==="approved"?a("ui.mesh.approval.approved_pending_apply"):Es(e.state)}),s.jsx("div",{className:"grow"}),l&&u&&s.jsx("span",{className:"text-meta text-ink-dim",children:e.kind==="credential"?a("ui.mesh.approval.request_window",{remaining:u}):u})]}),s.jsx("p",{className:"text-body-sm text-ink [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-summary",children:l?v:b}),!j&&e.state==="failed"&&s.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")}),l&&j&&s.jsx("p",{className:"text-meta text-ink-muted whitespace-pre-wrap [overflow-wrap:anywhere]","data-tour-tag":"mesh-approval-cli-remedy",children:e.approveRemedy||a("ui.mesh.approval.cli_review")}),e.kind==="credential"&&e.state==="approved"&&s.jsx("p",{className:"text-meta text-ink-muted","data-tour-tag":"mesh-approval-apply-hint",children:e.details?.length?a("ui.mesh.approval.approved_apply_hint"):a("ui.mesh.approval.approved_details_missing")}),(D||y)&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[D&&s.jsx(V,{variant:"primary",size:"sm",disabled:t,onClick:()=>m(e.approvalId,"approve"),"data-tour-tag":"mesh-approval-approve",children:a("ui.mesh.mesh_approvals_tray.approve")}),y&&s.jsx(V,{variant:"ghost",size:"sm",disabled:t,onClick:()=>m(e.approvalId,"deny"),"data-tour-tag":l?"mesh-approval-deny":"mesh-approval-stop",children:l?a("ui.mesh.mesh_approvals_tray.deny"):mt(e.state)}),n&&s.jsx("span",{className:"text-meta text-ink-dim",children:n.decision==="approve"?a("ui.mesh.mesh_approvals_tray.waiting_for_the_signing_prompt"):a("ui.mesh.mesh_approvals_tray.writing_the_decision")})]}),s.jsxs(Se,{chevronClassName:"text-ink-dim",summary:s.jsx("span",{className:"text-meta",children:a("ui.mesh.mesh_approvals_tray.details")}),children:[p&&(e.details?.length?s.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((o,I)=>s.jsx("li",{className:"whitespace-pre-wrap",children:o},`${I}:${o}`))}):s.jsx("p",{className:"text-meta text-ink-muted",children:a("ui.mesh.approval.details_unavailable")})),w.length>0&&s.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:w.map(o=>s.jsxs(x.Fragment,{children:[s.jsx("dt",{className:"text-ink-muted",children:o.term}),s.jsx("dd",{children:o.consequence})]},o.term))}),(E||C)&&s.jsxs("p",{className:"text-meta text-ink-muted",children:[E&&s.jsx("span",{children:E}),E&&C&&s.jsx("span",{children:" · "}),C&&s.jsx("span",{className:"font-mono",children:C})]}),c&&s.jsx("p",{className:"text-meta text-ink-dim",children:c}),N.length>0&&s.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:N.map(o=>s.jsxs(x.Fragment,{children:[s.jsx("dt",{className:"text-ink-muted",children:o.term}),s.jsx("dd",{className:"text-ink-muted",children:o.text})]},o.term))})]}),d&&s.jsx(ts,{refusal:d})]})},ts=({refusal:e})=>(z(),s.jsx(ge,{variant:"warning",className:"text-meta","data-tour-tag":"mesh-approval-refusal",children:s.jsxs("span",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1",children:e.sentence}),s.jsx("span",{className:"shrink-0 font-mono text-ink-dim",children:e.code})]})})),pt=4,_e={kind:"idle"};function xt(e){switch(e.kind){case"dragging":case"settling":return e.payload.session.id;case"pressing":return null;default:return null}}function ee(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))<pt?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"?_e:e;case"cancel":case"settled":return _e;default:return e}}const ft=({edges:e,geometry:n,selectedDeviceId:t})=>s.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(d=>{const m=n.networks.get(d.networkId),h=n.devices.get(d.deviceId);if(!m||!h)return null;const f=t!==null&&d.deviceId===t;return s.jsx("path",{"data-mesh-edge":d.key,d:As(m,h),fill:"none",strokeWidth:f?2:1.5,className:f?"stroke-ink":"stroke-ink-dim"},d.key)})}),De=({deviceId:e,name:n,compact:t=!1,deviceIds:d,className:m})=>{z();const h=Ge({name:n});return s.jsxs("span",{className:L("flex min-w-0 items-baseline gap-2",m),"data-mesh-device-identity":e,children:[s.jsx(xs,{content:n?.trim()?h:null,children:s.jsx("span",{className:"min-w-0 flex-1 truncate text-start","data-mesh-device-name":"",children:h})}),s.jsx("span",{className:"shrink-0 font-mono text-meta text-ink-muted","data-mesh-device-id":"",title:e,children:t?os(e,d):e})]})},gt={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 vt(e){return e.suspect?"border-l-danger":gt[se(e)]}const bt={self:"ring-2 ring-accent",reachable:null,relay_down:null,handshake_refused:null,unreachable:null,suspect:null},_t={accept:"border-accent bg-accent-wash",refuse:"border-warning"};function kt(e,n,t){return[Ge(e),e.id,Je(e,n),t].filter(Boolean).join(", ")}function te(e){return e.name.trim()||e.id.slice(-6)}function ns(e,n,t){if(t!=="reached"&&t!=="self"){const d=xe(t);return e.unreachable_reason?`${d} (${e.unreachable_reason})`:d}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 wt={resting:"border-l-2 border-l-hairline",attention:"border-l-2 border-l-warning"},jt=({network:e,x:n,y:t,refused:d})=>(z(),s.jsxs("li",{"data-mesh-network":e.id,"data-mesh-network-refused":d?"true":void 0,"data-glass-block":"",className:L("absolute flex items-center gap-2 rounded-md border bg-elevated px-3",d?"border-warning":"border-hairline"),style:{left:n,top:t,width:Ie,height:Rs},children:[s.jsx(Me,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),s.jsxs("span",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block truncate text-body-sm text-ink",children:e.label}),s.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?s.jsxs(s.Fragment,{children:[" · ",a("ui.mesh.mesh_list.revoked_count",{count:e.revokedCount})]}):null]})]})]})),yt=({device:e,deviceIds:n,x:t,y:d,nowSeconds:m,selected:h,sessions:f,sessionTotal:l,dropState:b,movingSessionId:v,draggedSessionId:w,onOpen:E,onChipPointerDown:C,onChipClick:c,onShowAllSessions:u})=>{z();const{activity:p}=ds(e,f.rows),j=p==="working",N=kt(e,m,j?"working":null),D=se(e);return s.jsxs("li",{"data-mesh-device":e.id,"data-mesh-state":e.state,"data-mesh-drop":b??void 0,"aria-current":h?"true":void 0,"data-glass-block":"",className:L("absolute flex flex-col rounded-md border border-l-4 border-control bg-elevated","hover:bg-row-hover",h&&"border-y-ink border-r-ink bg-row-selected",vt(e),bt[e.state],b&&_t[b]),style:{left:t,top:d,width:Ie,height:Ps},children:[s.jsxs("button",{type:"button","data-mesh-device-open":e.id,"data-mesh-reach":D,"aria-label":N,title:cs(e),onClick:()=>E(e.id),className:L("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:Ls},children:[s.jsxs("span",{className:"flex w-full min-w-0 items-center gap-2",children:[s.jsx(dt,{"aria-hidden":"true",className:"size-4 shrink-0 text-ink-muted"}),s.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&&s.jsx(Ce,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"})]}),s.jsxs("span",{className:"flex w-full min-w-0 items-baseline gap-1",children:[s.jsx("span",{className:"w-3 shrink-0 font-mono text-body-sm text-ink tabular-nums",children:e.sessionCount??"–"}),s.jsx("span",{className:L("min-w-0 truncate text-meta",e.sessionCount===null?"text-ink-dim":"text-ink-muted"),children:Ze(e.sessionCount)})]}),s.jsxs("span",{"data-mesh-state-line":"",className:"flex w-full min-w-0 items-baseline gap-1.5 text-meta",children:[s.jsx("span",{"aria-hidden":"true",className:"shrink-0 text-ink-dim",children:ms[D]}),s.jsx("span",{className:L("shrink-0",Ue[D]),children:xe(D)}),j&&s.jsx("span",{"data-mesh-working":"",className:"shrink-0 text-info",children:a("ui.mesh.mesh_node.working")}),e.memberships.length>1&&s.jsx("span",{className:"min-w-0 truncate text-ink-dim",children:a("ui.mesh.mesh_node.memberships",{count:e.memberships.length})})]})]}),s.jsxs("ul",{"aria-label":a("ui.mesh.mesh_node.conversations_on",{device:Q(e,n,!0)}),className:L("m-0 flex h-6 list-none items-center gap-1 overflow-hidden px-3",b==="accept"&&"opacity-40"),children:[f.shown.map(y=>s.jsx(Nt,{session:y,ownerLabel:Q(e,n,!0),ownerReach:D,ownerReachable:e.reachable,moving:v===y.id,dragging:w===y.id,onPointerDown:C,onClick:()=>c(y)},y.id)),f.hidden>0&&s.jsx("li",{className:"shrink-0",children:s.jsxs("button",{type:"button","data-mesh-more":e.id,onClick:()=>u(e.id),className:L("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:l}),"aria-label":a("ui.mesh.mesh_node.show_all_conversations",{count:l}),children:["+",f.hidden]})})]})]})},Nt=({session:e,ownerLabel:n,ownerReach:t,ownerReachable:d,moving:m,dragging:h,onPointerDown:f,onClick:l})=>{z();const b=ns(e,n,t);return m?s.jsx("li",{role:"status","data-mesh-session":e.id,"data-mesh-moving":"true",children:s.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")})}):s.jsx("li",{className:"min-w-0 flex-1","data-mesh-session-item":e.id,"data-mesh-dragging":h?"true":void 0,children:s.jsx("button",{type:"button","data-mesh-session":e.id,style:{touchAction:"none"},title:`${te(e)} · ${b}`,"aria-label":a("ui.mesh.mesh_node.open_conversation",{conversation:te(e),fact:b,owner:n}),onPointerDown:v=>f(v,e),onClick:()=>l(e),className:L("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",wt[Ts(e,d)],h&&"opacity-60","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"),children:s.jsx("span",{className:"min-w-0 flex-1 truncate",children:te(e)})})})};function Oe(e){const n=e.trim();if(!n)return null;if(n.startsWith("[")){const d=n.indexOf("]");if(d<=1)return null;const m=n.slice(1,d),h=n.slice(d+1);if(!h)return{host:m,port:null};if(!h.startsWith(":"))return null;const f=Number(h.slice(1));return{host:m,port:Number.isInteger(f)?f:null}}const t=n.lastIndexOf(":");if(t>0){const d=n.slice(t+1);if(/^\d+$/.test(d))return{host:n.slice(0,t),port:Number(d)}}return{host:n,port:null}}function He(e){const n=e.trim().split(".");if(n.length!==4)return null;for(const t of n)if(!/^\d{1,3}$/.test(t)||Number(t)>255)return null;return`${n[0]}.${n[1]}.${n[2]}`}function It(e){return`${e}.x`}function Ct(e){const n=new Map;for(const d of e.values())for(const m of d)n.set(m,(n.get(m)??0)+1);const t=new Set;for(const[d,m]of n)m>1&&t.add(d);return t}function Ne(e){return new Set(e.endpoints.map(n=>n.trim()).filter(Boolean))}function St(e,n){const t=e.filter(c=>c.id!==n),d=e.find(c=>c.id===n)??null,m=new Map;for(const c of e)m.set(c.id,Ne(c));const h=Ct(m),f=new Set;for(const c of d?Ne(d):[]){if(h.has(c))continue;const u=Oe(c),p=u?He(u.host):null;p&&f.add(p)}const l=c=>{const u=new Set;for(const p of Ne(c)){if(h.has(p))continue;const j=Oe(p),N=j?He(j.host):null;N&&u.add(N)}return u},b=new Map,v=new Map;for(const c of t){const u=Mt(c);if(u){b.set(u,[...b.get(u)??[],c.id]);continue}for(const p of l(c))v.set(p,[...v.get(p)??[],c.id])}const w=new Map(e.map((c,u)=>[c.id,u])),E=c=>[...c].sort((u,p)=>(w.get(u)??0)-(w.get(p)??0)),C=[];for(const[c,u]of b)C.push({prefix:c,tier:"declared",deviceIds:E(u),get words(){return a("ui.mesh.mesh_scope.declared")}});for(const[c,u]of v)f.has(c)?C.push({prefix:c,tier:"shared",deviceIds:E(u),get words(){return a("ui.mesh.mesh_scope.shared_with_this_device")}}):u.length>1&&C.push({prefix:c,tier:"probable",deviceIds:E(u),get words(){return a("ui.mesh.mesh_scope.same_prefix")}});return C.sort((c,u)=>c.tier.localeCompare(u.tier)||c.prefix.localeCompare(u.prefix))}function Mt(e){for(const n of e.memberships){const t=n.scope.trim();if(t)return t}return""}const We={declared:0,shared:1,probable:2};function Dt(e,n){const t=new Map;for(const m of e){let h=null;for(const l of m.deviceIds){const b=n.get(l);b!==void 0&&(h===null||b<h.slot)&&(h={id:l,slot:b})}if(h===null)continue;const f=t.get(h.id);f===void 0?t.set(h.id,{slot:h.slot,groups:[m]}):f.groups.push(m)}const d=m=>{let h=-1;for(const f of m.deviceIds){const l=n.get(f);l!==void 0&&l>h&&(h=l)}return h};return[...t.entries()].sort((m,h)=>m[1].slot-h[1].slot).map(([m,h])=>({deviceId:m,groups:h.groups.sort((f,l)=>d(l)-d(f)||We[f.tier]-We[l.tier]||f.prefix.localeCompare(l.prefix))}))}function Et(e){return new Map(e.map(n=>[n.deviceId,n.groups.length]))}function At(e){return`${e.tier==="declared"?e.prefix:It(e.prefix)} · ${e.words}`}const ze=(e,n)=>e.deviceIds.map(t=>n.devices.get(t)).filter(t=>t!==void 0),Rt=({stacks:e,geometry:n})=>(z(),s.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute top-0 left-0",children:e.map(t=>{const d=t.groups.length,m=new Array(d).fill(0);let h=null;for(let l=d-1;l>=0;l-=1){const b=ze(t.groups[l],n),v=(b.length===0?0:Math.max(...b.map(w=>w.y+w.height)))+fe;h=h===null?v:Math.max(v,h+je),m[l]=h}const f=n.devices.get(t.deviceId);return t.groups.map((l,b)=>{const v=ze(l,n);if(v.length===0)return null;const w=d-1-b,E=Math.min(...v.map(N=>N.x)),C=Math.max(...v.map(N=>N.x)),u=(f?.y??Math.min(...v.map(N=>N.y)))-fe-$s*w,p=l.tier==="declared",j=At(l);return s.jsx("div",{"data-mesh-scope":`${l.tier}:${l.prefix}`,"data-mesh-scope-level":b,className:L("absolute rounded-lg",l.tier==="probable"?"border border-dashed border-hairline-strong":"border border-control"),style:{left:E-fe-je*w,top:u,width:C+Ie-E+(fe+je*w)*2,height:m[b]-u},children:s.jsx("span",{"data-mesh-scope-label":"",className:L("absolute bottom-full left-1 mb-0.5 whitespace-nowrap text-meta",l.tier==="probable"?"text-ink-dim":"text-ink-muted",p&&"font-medium"),children:j})},`${l.tier}:${l.prefix}`)})})})),Fe=48,qe=1.25,Pt=.0015,Lt=({graph:e,slots:n,nowSeconds:t,selectedDeviceId:d,sessions:m,sessionTotals:h,movingSessionId:f,canMove:l,onOpenDevice:b,onAskMove:v,onDropRefused:w,onShowAllSessions:E,summaryId:C})=>{z();const c=x.useRef(null),[u,p]=x.useState({width:0,height:0,clipWidth:0,clipHeight:0,left:0,top:0}),[j,N]=x.useState({k:1,tx:0,ty:0}),D=x.useRef(!1),y=x.useRef(!1),o=x.useRef(null),I=x.useMemo(()=>St(e.devices,e.selfDeviceId),[e.devices,e.selfDeviceId]),A=x.useMemo(()=>Dt(I,n.devices),[I,n]),S=x.useMemo(()=>Os(n,Et(A)),[n,A]),M=x.useMemo(()=>({selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(i=>[i.id,i])),networks:new Map(e.networks.map(i=>[i.id,i]))}),[e]),[_,$]=x.useState(_e),ce=x.useRef({kind:"ground"}),ne=x.useCallback((i,r)=>{const g=document.elementFromPoint(i,r),R=g?.closest("[data-mesh-device]");if(R){const K=R.getAttribute("data-mesh-device");if(K)return{kind:"device",deviceId:K}}const W=g?.closest("[data-mesh-network]");if(W){const K=W.getAttribute("data-mesh-network");if(K)return{kind:"network",networkId:K}}return{kind:"ground"}},[]),T=x.useMemo(()=>_.kind!=="dragging"&&_.kind!=="settling"?null:ve(_.payload,_.target,M),[_,M]),Y=x.useCallback(i=>{if(!T)return null;if(T.kind==="plan"){const r=_.kind==="dragging"||_.kind==="settling"?_.target:null;return r&&r.kind==="device"&&r.deviceId===i?"accept":null}if(T.kind==="refused"){const r=_.kind==="dragging"||_.kind==="settling"?_.target:null;return r&&r.kind==="device"&&r.deviceId===i?"refuse":null}return null},[T,_]),ae=x.useCallback((i,r)=>{if(!l||i.button!==0)return;y.current=!1;const g=r.locality==="local"?e.selfDeviceId??"":r.owner_device,R=M.devices.get(g),W={session:r,ownerDeviceId:g,ownerLabel:R?Q(R,[...M.devices.keys()],!0):r.owner_device_name};try{i.currentTarget.setPointerCapture(i.pointerId)}catch{}$(K=>ee(K,{kind:"press",payload:W,x:i.clientX,y:i.clientY,pointerId:i.pointerId}))},[l,M,e.selfDeviceId]),ie=i=>{if(_.kind==="pressing"||_.kind==="dragging"){const r=ne(i.clientX,i.clientY);ce.current=r,$(g=>ee(g,{kind:"move",x:i.clientX,y:i.clientY,target:r}));return}X(i)},me=i=>{if(ue(i),_.kind!=="pressing"&&_.kind!=="dragging")return;if(_.kind==="pressing"){$(g=>ee(g,{kind:"cancel"}));return}const r=ve(_.payload,_.target,M);y.current=!0,$(g=>ee(g,{kind:"release"})),r.kind==="plan"?v({plan:r.plan,alternatives:r.alternatives,risky:r.risky}):r.kind==="refused"&&w({code:r.code,sentence:r.sentence,reach:r.reach,remedy:r.remedy,plan:r.plan??null}),$(g=>ee(g,{kind:"settled"}))};x.useEffect(()=>()=>$(_e),[]);const re=x.useCallback(()=>{N(Te(S.bounds,u))},[S.bounds,u]);x.useEffect(()=>{const i=c.current;if(!i)return;const r=()=>{const R=i.getBoundingClientRect();p({width:R.width,height:R.height,clipWidth:i.clientWidth,clipHeight:i.clientHeight,left:R.left,top:R.top})};r();const g=new ResizeObserver(r);return g.observe(i),()=>g.disconnect()},[]),x.useEffect(()=>{D.current||u.width<=0||u.height<=0||(D.current=!0,N(Te(S.bounds,u)))},[u,S.bounds]),x.useEffect(()=>{const i=o.current;if(o.current={width:u.width,height:u.height},!i||!D.current||u.width<=0||u.height<=0||u.width>=i.width&&u.height>=i.height||!d)return;const r=S.devices.get(d);r&&N(g=>{const R={width:u.clipWidth,height:u.clipHeight},W=Math.max(0,Math.min(R.width-S.bounds.width*g.k,R.height-S.bounds.height*g.k));return Hs(g,r,R,Math.min(zs,W))})},[u,d,S]);const q=_.kind==="dragging"?{x:_.x-u.left+12,y:_.y-u.top+12}:{x:0,y:0},le=T?Ws(T):null,G=x.useRef(null),k=x.useRef(null),P=x.useRef(null),O=x.useRef(null),U=x.useCallback(()=>{P.current=null;const i=G.current,r=k.current;if(G.current=null,k.current=null,i){const g=O.current;if(!g)return;N({k:g.transform.k,tx:g.transform.tx+(i.x-g.x),ty:g.transform.ty+(i.y-g.y)});return}r&&N(g=>ye(g,{x:r.x,y:r.y},g.k*Math.exp(-r.deltaY*Pt)))},[]),H=x.useCallback(()=>{P.current===null&&(P.current=requestAnimationFrame(U))},[U]);x.useEffect(()=>()=>{P.current!==null&&cancelAnimationFrame(P.current)},[]);const Z=i=>{!(i.target===i.currentTarget)&&i.button!==1||i.button!==0&&i.button!==1||(O.current={x:i.clientX,y:i.clientY,transform:j},i.currentTarget.setPointerCapture(i.pointerId),i.preventDefault())},X=i=>{O.current&&(G.current={x:i.clientX,y:i.clientY},H())},ue=i=>{O.current&&(O.current=null,G.current=null,i.currentTarget.hasPointerCapture(i.pointerId)&&i.currentTarget.releasePointerCapture(i.pointerId))},J=x.useCallback(i=>{if(i.deltaY===0)return;i.preventDefault();const r=i.currentTarget.getBoundingClientRect();k.current={x:i.clientX-r.left,y:i.clientY-r.top,deltaY:i.deltaY},H()},[H]);x.useEffect(()=>{const i=c.current;if(i)return i.addEventListener("wheel",J,{passive:!1}),()=>i.removeEventListener("wheel",J)},[J]);const oe=i=>{const r=i.shiftKey?Fe*4:Fe;switch(i.key){case"Escape":if(_.kind!=="pressing"&&_.kind!=="dragging")return;i.preventDefault(),_.kind==="dragging"&&(y.current=!0),$(g=>ee(g,{kind:"cancel"}));return;case"0":i.preventDefault(),re();return;case"+":case"=":i.preventDefault(),N(g=>ye(g,{x:u.width/2,y:u.height/2},g.k*qe));return;case"-":case"_":i.preventDefault(),N(g=>ye(g,{x:u.width/2,y:u.height/2},g.k/qe));return;case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{i.preventDefault();const g=i.key==="ArrowLeft"?r:i.key==="ArrowRight"?-r:0,R=i.key==="ArrowUp"?r:i.key==="ArrowDown"?-r:0;N(W=>({...W,tx:W.tx+g,ty:W.ty+R}));return}}};return s.jsxs("div",{ref:c,"data-mesh-canvas":"",role:"group","aria-labelledby":C,tabIndex:0,onPointerDown:Z,onPointerMove:ie,onPointerUp:me,onPointerCancel:i=>{_.kind==="dragging"&&(y.current=!0),$(r=>ee(r,{kind:"cancel"})),ue(i)},"data-mesh-gesture":_.kind,"data-glass-well":"clear",onKeyDown:oe,onDoubleClick:i=>{i.target===i.currentTarget&&re()},className:L("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:[s.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`}}),s.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:S.bounds.width,height:S.bounds.height},children:[s.jsx(Rt,{stacks:A,geometry:S}),s.jsx(ft,{edges:e.edges,geometry:S,selectedDeviceId:d}),s.jsx("ul",{"aria-label":a("ui.mesh.mesh_canvas.networks"),className:"m-0 list-none p-0",children:e.networks.map(i=>{const r=S.networks.get(i.id);return r?s.jsx(jt,{network:i,x:r.x,y:r.y,refused:T?.kind==="refused"&&_.kind==="dragging"&&_.target.kind==="network"&&_.target.networkId===i.id},i.id):null})}),s.jsx("ul",{"aria-label":a("ui.mesh.mesh_canvas.devices"),className:"m-0 list-none p-0",children:e.devices.map(i=>{const r=S.devices.get(i.id);return r?s.jsx(yt,{device:i,deviceIds:e.devices.map(g=>g.id),x:r.x,y:r.y,nowSeconds:t,selected:i.id===d,sessions:m.get(i.id)??{rows:[],shown:[],hidden:0},sessionTotal:h.get(i.id)??i.sessionCount??0,dropState:Y(i.id),movingSessionId:f,draggedSessionId:xt(_),onOpen:b,onChipPointerDown:ae,onChipClick:()=>{if(y.current){y.current=!1;return}b(i.id)},onShowAllSessions:E},i.id):null})})]}),_.kind==="dragging"&&s.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:_.payload.session.name||"untitled"}),_.kind==="dragging"&&le&&s.jsx("div",{"data-mesh-indicator":"",className:L("pointer-events-none absolute z-10 rounded-sm border bg-surface px-2 py-1 text-meta",T?.kind==="refused"?"border-warning text-warning":"border-control text-ink"),style:{left:q.x,maxWidth:Math.max(160,u.width-q.x-12),...q.y>u.height*.6?{bottom:Math.max(12,u.height-q.y+8)}:{top:q.y+24}},children:le})]})};function Tt(e,n,t,d){const m=t.locality==="local"?n:t.owner_device,h=[],f=e.map(l=>l.id);for(const l of e){if(l.id===m)continue;if(l.id===n){h.push({deviceId:l.id,label:d,verb:a("ui.mesh.mesh_card.recall_to_this_device"),keepVerb:a("ui.mesh.mesh_card.copy_here_leave_it_there")});continue}const b=Q(l,f,!0);h.push({deviceId:l.id,label:b,verb:a("ui.mesh.mesh_card.move_to",{device:b}),keepVerb:a("ui.mesh.mesh_card.copy_to",{device:b})})}return h}function $t(e,n,t){return Tt(e.devices,e.selfDeviceId,n,t)}function as(e,n,t){const d=$t(e,n,t),m={selfDeviceId:e.selfDeviceId,devices:new Map(e.devices.map(l=>[l.id,l])),networks:new Map(e.networks.map(l=>[l.id,l]))},h=n.locality==="local"?e.selfDeviceId??"":n.owner_device,f=m.devices.get(h);return d.map(l=>{const b=ve({session:n,ownerDeviceId:h,ownerLabel:f?Q(f,e.devices.map(v=>v.id),!0):n.owner_device_name},{kind:"device",deviceId:l.deviceId},m);return{...l,refused:b.kind==="refused"&&b.code!=="busy"?b.sentence:null}})}const is=({session:e,destinations:n,disabled:t,onChoose:d,onOpenChange:m,trigger:h,triggerLabel:f})=>(z(),s.jsxs(gs,{onOpenChange:m,children:[s.jsx(vs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":f,"data-mesh-session-menu":e.id,disabled:t||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:h})}),s.jsxs(bs,{align:"start",className:"min-w-56",children:[s.jsx(_s,{children:te(e)}),s.jsx(Re,{}),n.map(l=>s.jsx(Pe,{"data-mesh-move-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>d(l,!1),children:l.verb},l.deviceId)),s.jsx(Re,{}),n.map(l=>s.jsx(Pe,{"data-mesh-copy-to":l.deviceId,disabled:!!l.refused,title:l.refused??void 0,onSelect:()=>d(l,!0),children:l.keepVerb},`keep-${l.deviceId}`))]})]})),Ot=({device:e,deviceIds:n,sessions:t,sessionTotal:d,nowSeconds:m,destinationsFor:h,movingSessionId:f,canMove:l,canInvite:b,onClose:v,onMove:w,onShowInList:E,onInvite:C,onRemoveMember:c})=>{z();const u=se(e),p=Ke(e),j=e.reachable?[]:e.attempts??[];x.useEffect(()=>{const o=I=>{I.key!=="Escape"||I.defaultPrevented||I.target?.closest('[role="menu"],[role="dialog"]')||(document.querySelector(`[data-mesh-device-open="${e.id}"]`)?.focus(),v())};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[e.id,v]);const N=e.sessionCount===null?Ze(null):a("ui.mesh.mesh_card.conversation_count",{count:e.sessionCount}),D=e.suspect?Ve():[N,xe(u)].filter(Boolean).join(" · "),y=d>t.rows.length?a("ui.mesh.mesh_card.shown_of",{shown:t.rows.length,total:d}):`${t.rows.length}`;return s.jsxs("aside",{"aria-label":a("ui.mesh.mesh_card.device_details",{device:Q(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:[s.jsxs("header",{className:"flex flex-col gap-1",children:[s.jsx(V,{size:"sm",variant:"ghost",className:"w-fit self-end","data-mesh-panel-close":"",onClick:v,children:a("ui.mesh.mesh_actions.close")}),s.jsx("h2",{className:"text-body-sm text-ink",children:s.jsx(De,{deviceId:e.id,deviceIds:n,name:e.name,compact:!0})}),s.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-ink-muted",children:[e.suspect&&s.jsx(Ce,{"aria-hidden":"true",className:"size-3.5 text-danger"}),!e.suspect&&u==="unanswered"&&s.jsx(fs,{"aria-hidden":"true",className:"size-3.5 text-warning"}),D]})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex flex-col gap-2",children:[s.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.memberships")}),s.jsx("ul",{className:"m-0 flex list-none flex-col gap-2 p-0",children:e.memberships.map(o=>s.jsxs("li",{className:"flex flex-col gap-1",children:[s.jsxs("span",{className:"flex items-center gap-2 text-body-sm text-ink",children:[s.jsx(Me,{"aria-hidden":"true",className:"size-3.5 text-ink-muted"}),o.networkName]}),s.jsxs("span",{className:"text-meta text-ink-dim",children:[o.role||"member",o.capabilities.length>0?` · ${o.capabilities.join(", ")}`:""]}),b&&s.jsxs(V,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-remove-member":`${o.networkId}:${e.id}`,onClick:()=>c(e,o.networkId),children:[a("ui.mesh.mesh_card.remove_from"),o.networkName,"…"]})]},o.networkId))}),b&&s.jsx(V,{size:"sm",variant:"secondary",className:"w-fit","data-mesh-invite":e.id,onClick:()=>C(e),children:a("ui.mesh.mesh_actions.invite_to_a_network")})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex shrink-0 flex-col gap-2",children:[s.jsxs("h3",{className:"text-meta text-ink-dim",children:[a("ui.mesh.mesh_card.conversations"),s.jsxs("span",{className:"text-ink-disabled",children:["(",se(e)!=="self"&&se(e)!=="reached"?Qe(null):y,")"]})]}),be(e,m)?s.jsx("p",{className:"text-meta text-warning",children:be(e,m)}):t.rows.length===0?s.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")}):s.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:t.rows.map(o=>s.jsxs("li",{"data-mesh-panel-session":o.id,className:L("flex items-center gap-2 rounded-sm px-2 py-1","border border-hairline bg-elevated",f===o.id&&"border-control"),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-body-sm text-ink",title:te(o),children:te(o)}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:ns(o,Q(e,n,!0),se(e))}),f===o.id?s.jsx("span",{className:"shrink-0 text-meta text-ink-muted",children:a("ui.mesh.mesh_card.moving")}):s.jsx(is,{session:o,destinations:h(o),disabled:!l,onChoose:(I,A)=>w(o,I,A),trigger:s.jsx(ss,{"aria-hidden":"true",className:"size-4"}),triggerLabel:a("ui.mesh.mesh_card.move_conversation",{conversation:te(o)})})]},o.id))})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex flex-col gap-2",children:[s.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.network_addresses")}),e.endpoints.length===0?s.jsx("p",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.no_address_published")}):s.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:e.endpoints.map(o=>s.jsxs("li",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-body-sm text-ink",children:o}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_card.advertised")})]},o))})]}),s.jsx(de,{}),s.jsxs("section",{className:"flex flex-col gap-2",children:[s.jsx("h3",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.status")}),s.jsxs("dl",{className:"m-0 flex flex-col gap-1",children:[s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("dt",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.reach")}),s.jsx("dd",{className:"m-0 text-body-sm text-ink",children:xe(u)})]}),s.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[s.jsx("dt",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_card.last_status_frame")}),s.jsx("dd",{className:"m-0 text-body-sm text-ink",children:e.lastSeenAt===null?a("ui.mesh.mesh_card.never"):Fs(m-e.lastSeenAt)})]})]}),!e.reachable&&(p!==""||j.length>0)&&s.jsxs("div",{className:"flex flex-col gap-1",children:[p&&s.jsx("p",{className:"m-0 text-meta text-warning",children:p}),e.linkState==="handshake_refused"&&s.jsx("p",{className:"m-0 text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.handshake_refused_hint")}),j.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{id:`mesh-attempts-label-${e.id}`,className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_reach.addresses_tried")}),s.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((o,I)=>{const A=Xe(o.detail);return s.jsxs("li",{"data-mesh-attempt":o.endpoint,className:"flex items-baseline justify-between gap-2",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-meta text-ink",children:o.endpoint}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:A})]},`${o.endpoint}:${I}`)})})]})]}),!p&&j.length===0&&e.reason&&s.jsx("p",{className:"text-meta text-warning",children:e.reason})]}),s.jsx(de,{}),s.jsx(V,{size:"sm",variant:"ghost",className:"w-fit","data-mesh-show-in-list":e.id,onClick:()=>E(e.id),children:a("ui.mesh.mesh_card.show_in_list")})]})},Ht=["name","chats","state"],Wt={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")}},Be={suspect:0,relay_down:1,handshake_refused:2,unreachable:3,self:4,reachable:5};function zt(e,n){const t=[...e];switch(n){case"chats":return t.sort((d,m)=>(m.sessionCount??-1)-(d.sessionCount??-1)||d.label.localeCompare(m.label)),t;case"state":return t.sort((d,m)=>Be[d.state]-Be[m.state]||d.label.localeCompare(m.label)),t;default:return t.sort((d,m)=>d.label.localeCompare(m.label))}}const Ye=8;function Ft(e,n){if(e.locality==="local")return e.live_state||"here";const t=e.owner_device_name||n,d=e.live_state?` · ${e.live_state}`:"";return e.reachable?a("ui.mesh.mesh_list.on_device_state",{device:t,state:d}):a("ui.mesh.mesh_list.on_device_no_answer",{device:t})}const qt=({graph:e,nowSeconds:n,selectedDeviceId:t,sessions:d,selfLabel:m,canMove:h,onSelect:f,onMove:l,onInvite:b,onRemove:v})=>{z();const[w,E]=x.useState("name"),C=x.useMemo(()=>e.networks.map(c=>({network:c,members:zt(e.devices.filter(u=>u.memberships.some(p=>p.networkId===c.id)),w)})),[e,w]);return s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pe-1",children:[s.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[s.jsx("legend",{className:"sr-only",children:a("ui.mesh.mesh_list.sort_devices_by")}),s.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Ht.map(c=>s.jsx("button",{type:"button","aria-pressed":w===c,onClick:()=>E(c),className:L("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",w===c&&"bg-surface text-ink"),children:Wt[c]},c))})]}),C.map(({network:c,members:u})=>s.jsxs("section",{"data-mesh-network-group":c.id,className:"flex flex-col gap-2",children:[s.jsxs("h2",{className:"flex flex-wrap items-baseline gap-2 text-body-sm text-ink",title:a("ui.mesh.mesh_list.epoch",{epoch:c.epoch}),children:[c.label,s.jsxs("span",{className:"text-meta text-ink-dim",children:[c.trust," ·"," ",a("ui.mesh.mesh_graph.device_count",{count:c.memberCount}),c.revokedCount>0?s.jsxs(s.Fragment,{children:[" · ",a("ui.mesh.mesh_list.revoked_count",{count:c.revokedCount})]}):null]})]}),s.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0",children:u.map(p=>{const j=p.memberships.find(M=>M.networkId===c.id),N=p.id===t,D=d.get(p.id),y=D?.rows??[],o=D?es(D,p.sessionCount):p.sessionCount??0,I=se(p),A=Ke(p),S=p.reachable?[]:p.attempts??[];return s.jsxs("li",{"data-mesh-device-row":p.id,"data-mesh-state":p.state,"aria-current":N?"true":void 0,className:L("flex flex-col gap-1 rounded-md px-3 py-2","border border-hairline bg-surface",N&&"border-ink bg-row-selected"),children:[s.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[s.jsx("button",{type:"button","data-mesh-device-open":p.id,onClick:()=>f(p.id),className:L("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:s.jsx(De,{deviceId:p.id,name:p.name})}),s.jsxs("span",{className:L("flex shrink-0 items-center gap-1 text-meta",Ue[I]),"data-mesh-reach":I,children:[p.suspect&&s.jsx(Ce,{"aria-hidden":"true",className:"size-3.5 shrink-0 text-danger"}),p.suspect?xe(I):Je(p,n),p.suspect&&s.jsx("span",{className:"shrink-0 rounded-sm border border-danger px-1 text-danger",children:Ve()})]}),s.jsxs("span",{className:"shrink-0 text-meta text-ink-dim",children:[j?.role?`${j.role} · `:"",a("ui.mesh.mesh_list.member")]})]}),(A!==""||S.length>0)&&!p.reachable&&s.jsxs("div",{className:"flex flex-col gap-0.5",children:[A&&s.jsx("span",{className:"text-meta text-warning",children:A}),S.map((M,_)=>{const $=Xe(M.detail);return s.jsx("span",{"data-mesh-attempt":M.endpoint,className:"text-meta text-ink-dim",children:$?`${M.endpoint} — ${$}`:M.endpoint},`${M.endpoint}:${_}`)})]}),be(p,n)?s.jsxs("span",{className:"text-meta text-warning",children:[a("ui.mesh.mesh_card.conversations")," (",Qe(null),") ·"," ",be(p,n)]}):y.length>0?s.jsxs(s.Fragment,{children:[s.jsx(de,{className:"my-1"}),s.jsx("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:y.slice(0,Ye).map(M=>s.jsxs("li",{"data-mesh-row-session":M.id,className:"flex items-center gap-2 py-0.5",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-meta text-ink-muted",children:M.name||M.id}),s.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:Ft(M,m)}),s.jsx(is,{session:M,destinations:as(e,M,m),disabled:!h,onChoose:(_,$)=>l(M,_,$),trigger:s.jsx(ss,{"aria-hidden":"true",className:"size-3.5"}),triggerLabel:a("ui.mesh.mesh_list.move_conversation",{conversation:M.name||M.id})})]},M.id))}),o>y.slice(0,Ye).length&&s.jsx("button",{type:"button",onClick:()=>f(p.id),className:"w-fit text-meta text-ink-dim hover:text-ink",children:a("ui.mesh.mesh_list.show_all_panel",{count:o})})]}):s.jsx("span",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_list.conversation_count",{count:o})}),(j||p.state!=="self")&&s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(V,{size:"sm",variant:"ghost","data-mesh-invite":p.id,onClick:()=>b({deviceId:p.id,deviceName:p.name}),children:a("ui.mesh.mesh_actions.invite_to_a_network")}),j&&s.jsxs(V,{size:"sm",variant:"ghost","data-mesh-remove-member":`${c.id}:${p.id}`,onClick:()=>v({networkId:c.id,networkLabel:c.label,deviceId:p.id,deviceName:p.name}),children:[a("ui.mesh.mesh_card.remove_from"),c.label,"…"]})]})]},p.id)})})]},c.id)),e.unmatchedPeers.length>0&&s.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")]})]})},Bt=({revoked:e})=>{if(e.length===0)return null;const n=a("ui.mesh.mesh_list.revoked_count",{count:e.length});return s.jsx(Se,{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:s.jsxs(s.Fragment,{children:[s.jsx("span",{"aria-hidden":"true",className:"inline-block whitespace-pre",children:" · "}),n]}),children:s.jsx("ul",{"data-mesh-revoked":"",className:"m-0 flex list-none flex-col gap-1 p-0",children:e.map(t=>s.jsxs("li",{"data-mesh-revoked-member":t.deviceId,className:"flex flex-wrap items-baseline gap-x-2 text-meta text-ink-dim",children:[s.jsx("span",{children:t.networkName}),s.jsx("span",{className:"font-mono text-body-sm text-ink",children:t.deviceId}),s.jsx("span",{className:"text-body-sm text-ink-muted",children:t.label}),s.jsxs("span",{children:[t.role?`${t.role} · `:"",a("ui.mesh.mesh_graph.revoked_membership")]})]},`${t.networkId}:${t.deviceId}`))})})},Yt=["canvas","list"],Gt={get canvas(){return a("ui.mesh.mesh_page.canvas")},get list(){return a("ui.mesh.mesh_page.list")}},Ut=({state:e,initialPresentation:n="canvas",graph:t,nowSeconds:d,checking:m,staleError:h,onRetry:f,approvals:l,sessions:b,sessionError:v,selfLabel:w,movingSessionId:E,canMove:C,pendingMove:c,onAskMove:u,onDropRefused:p,onChooseMove:j,onCancelMove:N,moveBusy:D,moveReport:y,onDismissReport:o,onWaitForIdle:I,onUndoCopy:A,invite:S,onOpenInvite:M,onInvite:_,onCloseInvite:$,inviteBusy:ce,inviteReceipt:ne,inviteRefusal:T,remove:Y,onOpenRemove:ae,onRemove:ie,onCloseRemove:me,removeBusy:re,removeRefusal:q,removed:le})=>{z();const[G,k]=x.useState(n),[P,O]=x.useState(null),U=t?qs(t):"",H="mesh-summary",Z=Bs(t),X=Ys(t,b,t?.selfDeviceId??null),ue=x.useMemo(()=>{const r=new Map;for(const g of t?.devices??[]){const R=X.byDevice.get(g.id);r.set(g.id,R?es(R,g.sessionCount):g.sessionCount??0)}return r},[t,X]),J=x.useCallback(r=>{O(r)},[]),oe=t?t.devices.find(r=>r.id===P)??null:null,i=x.useCallback((r,g,R)=>{if(!t)return null;const W={selfDeviceId:t.selfDeviceId,devices:new Map(t.devices.map(B=>[B.id,B])),networks:new Map(t.networks.map(B=>[B.id,B]))},K=r.locality==="local"?t.selfDeviceId??"":r.owner_device,Ee=W.devices.get(K),F=ve({session:r,ownerDeviceId:K,ownerLabel:Ee?Q(Ee,t.devices.map(B=>B.id),!0):r.owner_device_name},{kind:"device",deviceId:g.deviceId},W);if(F.kind==="refused")return p({code:F.code,sentence:F.sentence,reach:F.reach,remedy:F.remedy,plan:F.plan??null}),null;if(F.kind==="none")return null;const Ae=R?F.alternatives.find(B=>B.keep)??F.plan:F.plan,rs=[F.plan,...F.alternatives].filter(B=>B.keep!==Ae.keep),ls={plan:Ae,alternatives:rs,risky:F.risky};u(ls)},[t,u,p]);return s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-6 overflow-y-auto p-6",children:[s.jsx(ps,{title:a("ui.mesh.mesh_page.mesh"),icon:Me,subtitle:a("ui.mesh.mesh_page.devices_this_app_is_paired_with_and"),children:s.jsxs("div",{className:"flex items-center gap-4",children:[m&&s.jsx("output",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_page.checking")}),(e.kind==="ready"||e.kind==="loading")&&s.jsxs("fieldset",{className:"m-0 w-fit border-0 p-0",children:[s.jsx("legend",{className:"sr-only",children:a("ui.mesh.mesh_page.presentation")}),s.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Yt.map(r=>s.jsx("button",{type:"button","data-mesh-presentation":r,"aria-pressed":G===r,disabled:e.kind!=="ready",onClick:()=>k(r),className:L("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",G===r&&"bg-surface text-ink"),children:Gt[r]},r))})]})]})}),s.jsx(ht,{rows:l.rows,error:l.error,pending:l.pending,refusal:l.decisionRefusal,onDecide:l.onDecide,onRetry:l.onRetry,nowSeconds:l.nowSeconds,networkNames:new Map((t?.networks??[]).map(r=>[r.id,r.label]))}),e.kind==="loading"&&s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[s.jsx(Le,{className:"h-4 w-64"}),s.jsx(Le,{className:"min-h-40 w-full flex-1"})]}),e.kind==="error"&&s.jsxs(ge,{variant:"warning",className:"flex-col items-start gap-2",children:[s.jsx("p",{children:e.message}),s.jsx(V,{variant:"secondary",size:"sm",onClick:f,className:"w-fit",children:a("ui.mesh.mesh_approvals_tray.ask_again")})]}),e.kind==="empty"&&s.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:s.jsxs("div",{className:"flex flex-col items-start gap-3",children:[s.jsx("h2",{className:"text-heading text-ink",children:a("ui.mesh.mesh_page.no_network_on_this_device")}),s.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")}),s.jsx("code",{className:"rounded-sm bg-sunken px-2 py-1 font-mono text-meta text-ink",children:"lop network init <name>"}),s.jsx("p",{className:"text-meta text-ink-dim",children:a("ui.mesh.mesh_page.a_network_appears_here_once_this_device")})]})}),e.kind==="ready"&&t&&s.jsx(s.Fragment,{children:s.jsxs("div",{className:"flex min-h-[22rem] flex-1 gap-4",children:[s.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-3",children:[s.jsxs("div",{id:H,className:"text-meta text-ink-muted","data-mesh-summary":"",children:[s.jsx("span",{children:U}),s.jsx(Bt,{revoked:t.revoked})]}),h&&s.jsx(ge,{variant:"warning",children:s.jsx("p",{children:h})}),v&&s.jsx(ge,{variant:"warning",children:s.jsx("p",{children:v})}),y&&s.jsx(Gs,{receipt:y.kind==="moved"?{verb:y.verb,detail:y.detail,undo:y.undo}:null,refusal:y.kind==="refused"?y.refusal:null,canWait:y.kind==="refused"&&y.plan!==null,onWait:I,onRecheck:f,onUndo:A,onDismiss:o,pending:D}),G==="canvas"?s.jsx(Lt,{graph:t,slots:Z,nowSeconds:d,selectedDeviceId:P,sessions:X.byDevice,sessionTotals:ue,movingSessionId:E,canMove:C,onOpenDevice:J,onAskMove:u,onDropRefused:p,onShowAllSessions:J,summaryId:H}):s.jsx(qt,{graph:t,nowSeconds:d,selectedDeviceId:P,sessions:X.byDevice,selfLabel:w,canMove:C,onSelect:J,onMove:i,onInvite:M,onRemove:ae})]}),oe&&s.jsx(Ot,{device:oe,deviceIds:t.devices.map(r=>r.id),sessions:X.byDevice.get(oe.id)??{rows:[],shown:[],hidden:0},sessionTotal:ue.get(oe.id)??0,nowSeconds:d,canMove:C,canInvite:e.kind==="ready",movingSessionId:E,destinationsFor:r=>as(t,r,w),onClose:()=>O(null),onMove:i,onInvite:r=>M({deviceId:r.id,deviceName:r.name}),onRemoveMember:(r,g)=>{const R=t.networks.find(W=>W.id===g);ae({networkId:g,networkLabel:R?.label??g,deviceId:r.id,deviceName:r.name})},onShowInList:r=>{J(r),k("list")}})]})}),s.jsx(Us,{open:c!==null,plan:c?.plan??Kt,alternatives:c?.alternatives??[],risky:c?.risky??!1,busy:D,onCancel:N,onChoose:j}),S&&s.jsx(Ks,{open:S.open,options:S.options,deviceId:S.deviceId,deviceName:S.deviceName,onClose:$,onInvite:_,pending:ce,receipt:ne,refusal:T}),Y&&s.jsx(Vs,{open:Y.open,networkLabel:Y.networkLabel,deviceId:Y.deviceId,deviceName:Y.deviceName,onClose:me,onConfirm:ie,pending:re,refusal:q,removed:le})]})},Kt={sessionId:"",to:"",keep:!1,verb:"",waitS:0,lost:null},an=({initialPresentation:e})=>{z();const n=us(),t=ke(n.data,"peers")==="enabled",d=ke(n.data,"session_transfer")==="enabled",m=Xs(t,{stamp:()=>we.getState().beginAnswer()}),h=Zs(t),f=Js(t,{poll:!1,stamp:()=>we.getState().beginAnswer()}),l=x.useMemo(()=>({peers:m,networks:h}),[m,h]),b=Qs(l),v=et(l),w=st(),E=ke(n.data,"approvals")==="enabled",C=tt(t&&E,{poll:!1}),c=nt(),u=c.isError?{approvalId:c.variables?.approvalId??null,...at(c.error)}:null,p=x.useMemo(()=>Math.floor((C.dataUpdatedAt||Date.now())/1e3),[C.dataUpdatedAt]),j=we(k=>k.settlePlacement),N=it(),D=rt(),[y,o]=x.useState(null),[I,A]=x.useState(null),[S,M]=x.useState(null),[_,$]=x.useState(null),[ce,ne]=x.useState(null),[T,Y]=x.useState(null),[ae,ie]=x.useState(null),me=x.useMemo(()=>{const k=Math.max(m.dataUpdatedAt,h.dataUpdatedAt);return Math.floor((k||Date.now())/1e3)},[m.dataUpdatedAt,h.dataUpdatedAt]),re=x.useCallback(()=>{m.refetch(),h.refetch(),f.refetch()},[m,h,f]),q=x.useCallback((k,P)=>{o(null);const O={sessionId:k.sessionId,to:k.to,keep:k.keep,waitS:P??k.waitS};w.mutate(O,{onSuccess:U=>{if(U.kind==="moved"){const{receipt:H}=U;j(k.sessionId,H);const Z=H.locality==="local"?a("ui.mesh.mesh_drop.this_device"):v?.devices.find(X=>X.id===H.owner_device)?.label??H.owner_device;A({kind:"moved",verb:H.mode==="keep"?a("ui.mesh.mesh_page.copied"):a("ui.mesh.mesh_page.moved"),detail:H.mode==="keep"?a("ui.mesh.mesh_page.copy_receipt",{destination:Z,suffix:H.new_session_id.slice(-6)}):a("ui.mesh.mesh_page.move_receipt",{destination:Z,retirement:H.source_retired?a("ui.mesh.mesh_page.the_copy_here_is_gone"):""}),undo:H.mode==="keep"?{sessionId:H.new_session_id,to:"local",keep:!1,verb:a("ui.mesh.mesh_page.bring_copy_back",{device:Z}),waitS:0,lost:lt(Z,a("ui.mesh.mesh_drop.this_device"))}:null});return}A({kind:"refused",refusal:U.refusal,plan:k})},onError:()=>{A({kind:"refused",refusal:{code:"move_failed",sentence:a("ui.mesh.mesh_page.the_move_could_not_be_sent_nothing"),status:null,unconfirmed:!1},plan:k})}})},[v,w,j]),le=x.useMemo(()=>{if(!v)return[];const k=S?.deviceId,P=k?v.devices.find(O=>O.id===k):void 0;return v.networks.filter(O=>P?!P.memberships.some(U=>U.networkId===O.id):!0).map(O=>({id:O.id,label:O.label}))},[v,S]);if(!t)return s.jsx(hs,{to:"/chat",replace:!0});const G=b.kind==="ready"?m.error?he(m.error):h.error?he(h.error):null:null;return s.jsx(Ut,{initialPresentation:e,state:b,graph:v,nowSeconds:me,checking:m.isFetching||h.isFetching,staleError:G,onRetry:re,approvals:{rows:C.data??[],error:C.isError?ot(C.error):null,pending:c.isPending?c.variables??null:null,decisionRefusal:u,onDecide:(k,P)=>c.mutate({approvalId:k,decision:P}),onRetry:()=>void C.refetch(),nowSeconds:p},sessions:f.data?.rows??[],movingSessionId:w.isPending?w.variables?.sessionId??null:null,sessionError:f.isError?he(f.error):null,selfLabel:v?.devices.find(k=>k.state==="self")?.label??a("ui.mesh.mesh_drop.this_device"),canMove:d,pendingMove:y,onAskMove:o,onDropRefused:k=>A({kind:"refused",refusal:{code:k.code,sentence:k.sentence,reach:k.reach,status:null,unconfirmed:!1},plan:k.plan}),onChooseMove:k=>q(k),onCancelMove:()=>o(null),moveBusy:w.isPending,moveReport:I,onDismissReport:()=>A(null),onWaitForIdle:()=>{I?.kind!=="refused"||!I.plan||q(I.plan,Vt)},onUndoCopy:()=>{I?.kind!=="moved"||!I.undo||o({plan:I.undo,alternatives:[],risky:!1})},invite:S===null?null:{open:!0,deviceId:S.deviceId,deviceName:S.deviceName,options:le},onOpenInvite:k=>{$(null),ne(null),M(k)},onInvite:k=>{N.mutate(k,{onSuccess:P=>$(P),onError:P=>ne({code:"invite_refused",sentence:he(P),status:null,unconfirmed:!1})})},onCloseInvite:()=>M(null),inviteBusy:N.isPending,inviteReceipt:_,inviteRefusal:ce,remove:T===null?null:{open:!0,networkId:T.networkId,networkLabel:T.networkLabel,deviceId:T.deviceId,deviceName:T.deviceName},onOpenRemove:k=>{ie(null),Y(k)},onRemove:k=>{T&&D.mutate({networkId:T.networkId,deviceId:T.deviceId,confirm:k},{onSuccess:P=>ie(P)})},onCloseRemove:()=>Y(null),removeBusy:D.isPending,removeRefusal:D.isError?{code:"remove_refused",sentence:he(D.error),status:null,unconfirmed:!1}:null,removed:ae})},Vt=300;export{an as MeshPage,Ut as MeshSurface,an as default};
@@ -1 +1 @@
1
- import{r as o,j as e,c as J}from"./index-C4ae8MIc.js";import{o as Gt}from"./console-mirror-C-hKgNgn.js";import{d as fe,A as Vt,B as Xt,a as Yt,C as Jt,E as Zt,i as ei,r as ti}from"./path-utils-BqTfmiT0.js";import{P as lt}from"./page-header-BnTa4LRQ.js";import{B as v,X as He,A as Se,b as Ct,C as _t,D as ve,d as be,e as we,f as ct,g as ee,u as Dt,S as dt,h as Rt,i as ii,j as si,k as ni,l as Ne,m as qe,n as ue,o as ai,p as oi,q as ri}from"./error-boundary-BcPKKbP5.js";import{as as We,at as li,au as ci,av as di,aw as ut,ax as ft,ay as Tt,az as ui,aA as fi,aB as W,aC as mi,aD as hi,aE as xi,aF as pi,aG as gi,aH as ki,aI as ji,aJ as At,aK as yi,aL as $e,aM as vi,aN as bi,aO as wi,aP as Ni,aQ as Si,aR as mt,aS as Ci,aT as _i,aU as Di,aV as Ri,aW as Ti,aX as Le,aY as ht,aZ as xt,a_ as je,a$ as pt,b0 as Be,b1 as Et,W as gt,b2 as Ai,b3 as kt,b4 as It,b5 as ye,b6 as Ei,b7 as Ii,b8 as zi}from"./conversation-input-sync-BwcOsVjK.js";import{t as i}from"./messages-DoRCUI0R.js";import{P as Mi}from"./project-markdown-B-gfCIgA.js";import{A as Fi,F as Oi,h as jt,R as qi,C as zt}from"./index-D9MeD_9S.js";async function yt(s,n){const f=Object.freeze({...n.scope}),r=n.throughSeq,l=new Map;if(n.verb==="read"&&"all"in f)for(const d of n.waiting)l.set(d.id,Object.freeze({...d}));let p;const g=new Set;do{const d=await s({state:n.verb==="read"?"unread":"all",limit:100,throughSeq:r,source:"notify",..."sessionId"in f?{sessionId:f.sessionId}:{},...p?{cursor:p}:{}});for(const m of d.observed)!m.id.startsWith("ask:")&&!l.has(m.id)&&l.set(m.id,Object.freeze({...m}));if(p=d.next_cursor||void 0,p&&g.has(p))throw new Error("Notification cursor did not advance");p&&g.add(p)}while(p);return Object.freeze({scope:f,throughSeq:r,tokens:Object.freeze([...l.values()])})}const Ce=s=>({changed:s.changed.length,skipped:s.skipped.length,pending:s.pending.length}),Li=(s,n)=>s.changed.length===n&&s.skipped.length===0&&s.pending.length===0&&s.error===void 0,Bi=s=>s==="read"?"unread":s==="unread"?"read":s==="dismiss"?"undismiss":"dismiss";async function vt(s,n,f,r,l){const p=[...new Map(f.map(m=>[m.id,{...m}])).values()],g={changed:[],skipped:[],pending:p},d=new Set;l?.(Ce(g));for(let m=0;m<p.length;m+=500){const _=p.slice(m,m+500),z=new Map(_.map(S=>[S.id,S]));try{const S=await s(n,r?{...r.scope,throughSeq:r.throughSeq,observed:_}:{items:_});for(const C of S.changed){const b=z.get(C);b&&!d.has(C)&&(g.changed.push(b),d.add(C))}for(const C of S.skipped)z.has(C.id)&&!d.has(C.id)&&(g.skipped.push(C),d.add(C.id))}catch(S){g.error=S}if(g.pending=p.filter(S=>!d.has(S.id)),l?.(Ce(g)),g.error)break}return g}const Ki={},Pi=({item:s,detail:n,loading:f,error:r,nowMs:l,narrow:p,writesPaused:g,sessionDismissCount:d,onClose:m,onOpenConversation:_,onToggleRead:z,onDismiss:S,onDismissSession:C,onCopyLink:b,onOpenProject:R,onAsksSettled:T})=>{const x=n?.item??s,B=x.dismissed,$=We(x),M=g||B,O=x.session.title||i("ui.notifications.group.untitled"),h=x.repeat_count>1?x.repeat_count:0,[N,H]=o.useState(!1),P=n?.history??[],G=N?P:P.slice(0,5),V=n?.projects??x.projects??[],F=n?.item.body_md??"";return e.jsxs("section",{"aria-label":i("ui.notifications.detail.label"),"data-notification-detail":x.id,className:"flex min-h-0 flex-1 flex-col overflow-y-auto overflow-x-hidden px-6 py-4 [scrollbar-gutter:stable]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[p?e.jsxs(v,{variant:"ghost",size:"sm",onClick:m,children:[e.jsx(Fi,{className:"rtl:-scale-x-100","aria-hidden":"true"}),i("ui.notifications.detail.back")]}):e.jsxs("span",{className:"flex items-center gap-2 text-meta",children:[x.source==="ask"?e.jsx(li,{size:14,"aria-hidden":"true",className:"text-info"}):e.jsx(ci,{priority:x.priority}),e.jsx("span",{className:J(x.priority==="high"?"text-warning":"text-ink-muted"),children:di(x)}),e.jsx("span",{"aria-hidden":"true",className:"text-ink-dim",children:"·"}),e.jsx("span",{className:"text-ink-muted",children:x.source==="ask"?i("ui.notifications.detail.kind.ask"):i("ui.notifications.detail.kind.update")})]}),!p&&e.jsx(v,{variant:"ghost",size:"icon-sm","aria-label":i("ui.notifications.detail.close"),title:i("ui.notifications.detail.close"),onClick:m,children:e.jsx(He,{"aria-hidden":"true"})})]}),e.jsx("h2",{className:"mt-3 text-heading text-ink","data-notification-detail-title":"",tabIndex:-1,children:x.title}),e.jsxs("p",{className:"mt-1 flex flex-wrap items-center gap-x-1.5 text-ink-dim text-meta",children:[e.jsx("span",{className:"text-ink-muted",children:O}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:ut(ft(x.updated_at,l))}),h>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:i("ui.notifications.detail.meta.updates_since",{count:h,time:Tt(x.created_at,{hour:"2-digit",minute:"2-digit"})})})]})]}),B&&e.jsx(Se,{variant:"neutral",className:"mt-3",role:"status",children:i("ui.notifications.detail.gone.dismissed")}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[e.jsxs(v,{variant:"primary",size:"sm",onClick:()=>_(x.session.id),"data-notification-open-conversation":"",children:[e.jsx(ui,{"aria-hidden":"true",className:"rtl:-scale-x-100"}),i("ui.notifications.detail.open_conversation")]}),e.jsxs(v,{variant:"secondary",size:"sm","aria-disabled":M||void 0,className:M?"text-ink-disabled":void 0,title:g?i("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{M||z(x)},"data-notification-toggle-read":"",children:[x.read?e.jsx(Ct,{"aria-hidden":"true"}):e.jsx(_t,{"aria-hidden":"true"}),x.read?i("ui.notifications.row.mark_unread"):i("ui.notifications.row.mark_read")]}),!$&&e.jsxs(v,{variant:"secondary",size:"sm","aria-disabled":M||void 0,className:M?"text-ink-disabled":void 0,title:g?i("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{M||S(x)},"data-notification-dismiss":"",children:[e.jsx(He,{"aria-hidden":"true"}),i("ui.notifications.detail.dismiss")]}),e.jsxs(ve,{children:[e.jsx(be,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"icon-sm","aria-label":i("ui.notifications.row.more"),title:i("ui.notifications.row.more"),children:e.jsx(fi,{"aria-hidden":"true"})})}),e.jsxs(we,{align:"end",children:[e.jsx(ct,{disabled:M||(d===null?!1:d===0),onSelect:()=>C(x.session.id,O),children:i("ui.notifications.detail.more.dismiss_session",{source:O})}),e.jsx(ct,{onSelect:()=>b(x),children:i("ui.notifications.detail.more.copy_link")})]})]})]}),r&&!n&&e.jsx(Se,{variant:"danger",className:"mt-4",role:"alert",children:i("ui.notifications.detail.error")}),f&&!n?e.jsxs("div",{className:"mt-4 flex flex-col gap-2",role:"status","aria-label":i("ui.notifications.detail.loading"),children:[e.jsx(ee,{className:"h-3 w-full bg-elevated"}),e.jsx(ee,{className:"h-3 w-5/6 bg-elevated"}),e.jsx(ee,{className:"h-3 w-2/3 bg-elevated"})]}):F?e.jsx(Mi,{className:"mt-4 text-body text-ink",children:F}):x.excerpt?e.jsx("p",{className:"mt-4 text-body text-ink",children:x.excerpt}):null,(n?.item.links?.length??0)>0&&e.jsx(oe,{title:i("ui.notifications.detail.section.links"),children:e.jsx("ul",{className:"flex flex-col gap-1",children:n?.item.links?.map(k=>e.jsx("li",{children:e.jsx("a",{href:k.url,target:"_blank",rel:"noreferrer",className:"text-accent text-body-sm underline-offset-2 hover:underline",children:k.label||k.url})},k.url))})}),n?.anchor?.excerpt&&e.jsx(oe,{title:i("ui.notifications.detail.section.context"),children:e.jsx("p",{className:"line-clamp-4 text-body-sm text-ink-muted",children:n.anchor.excerpt})}),(n?.asks?.length??0)>0&&e.jsx(oe,{title:i("ui.notifications.detail.section.waiting"),children:e.jsx(Qi,{sessionId:x.session.id,asks:n?.asks??[],nowMs:l,onSettled:T})}),e.jsx(oe,{title:i("ui.notifications.detail.section.from"),children:e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md bg-surface px-3 py-2",children:[e.jsx("button",{type:"button",onClick:()=>_(x.session.id),className:"min-w-0 truncate text-start text-body-sm text-ink hover:underline",children:n?.session.title||O}),d!==0&&e.jsx(v,{variant:"ghost",size:"sm",className:"min-w-[6.5rem] shrink-0 tabular-nums","data-detail-dismiss-all":d===null?"counting":"ready","aria-busy":d===null||void 0,"aria-disabled":M||d===null||void 0,onClick:()=>{M||d===null||C(x.session.id,O)},children:i("ui.notifications.detail.from.dismiss_all",{count:d===null?"…":W(d)})})]})}),V.length>0&&e.jsx(oe,{title:i("ui.notifications.detail.section.projects"),children:e.jsx("ul",{className:"flex flex-col gap-1",children:V.map(k=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>R(k.key),className:"flex items-center gap-2 rounded-sm px-2 py-1 text-start text-body-sm text-ink hover:bg-row-hover",children:[e.jsx(Oi,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-muted"}),e.jsx("span",{className:"min-w-0 truncate",children:k.name}),k.status&&e.jsx("span",{className:"text-ink-dim text-meta",children:k.status})]})},k.key))})}),P.length>0&&e.jsxs(oe,{title:i("ui.notifications.detail.section.history"),children:[e.jsx("ol",{className:"flex flex-col gap-2",children:G.map(k=>e.jsxs("li",{className:"flex flex-col gap-0.5","data-history-revision":k.revision,children:[e.jsxs("span",{className:"flex items-baseline justify-between gap-2 text-body-sm text-ink",children:[e.jsx("span",{className:"min-w-0 truncate",children:k.title}),e.jsx("span",{className:"shrink-0 text-ink-dim text-meta tabular-nums",children:ut(ft(k.at,l))})]}),k.excerpt&&e.jsx("span",{className:"truncate text-ink-dim text-meta",children:k.excerpt})]},k.revision))}),P.length>5&&!N&&e.jsx(v,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>H(!0),children:i("ui.notifications.detail.history.show_all",{count:W(P.length)})})]})]})},oe=({title:s,children:n})=>e.jsxs("div",{className:"mt-6 flex flex-col gap-2",children:[e.jsx("h3",{className:"text-ink-muted text-meta",children:s}),n]}),Qi=({sessionId:s,asks:n,nowMs:f,onSettled:r})=>{const l=o.useRef(mi()).current,[p,g]=o.useState(Ki),[d,m]=o.useState({}),[_,z]=o.useState(!1),S=o.useMemo(()=>hi({asks:n,asks_open:n.filter(b=>b.status==="open").length,asks_truncated:!1},d),[n,d]),C=o.useCallback((b,R)=>{l.held||(z(!0),m(T=>({...T,[b]:{sending:!0,refused:null}})),(async()=>{let T;try{T=await R()}finally{z(!1)}m(x=>({...x,[b]:{sending:!1,refused:T.status==="failed"?xi(T.error):null}})),T.status==="sent"&&r()})())},[l,r]);return e.jsx(pi,{view:S,nowMs:f,answering:_,outcomes:d,drafts:p,onDraftChange:(b,R)=>g(T=>({...T,[b]:R})),onAnswer:(b,R)=>C(b.ask_id,()=>ji({taskId:b.ask_id,answers:R,sessionId:s,lock:l},T=>fe(T))),onDecline:b=>C(b.ask_id,()=>ki({taskId:b.ask_id,sessionId:s,lock:l},R=>fe(R))),onDismiss:(b,R)=>C(b.ask_id,()=>gi({taskId:b.ask_id,reason:R,sessionId:s,lock:l},T=>fe(T)))})},Ke=120,Pe=180,Ui=({exiting:s,children:n,onExited:f})=>{const r=At("(prefers-reduced-motion: reduce)"),[l,p]=o.useState("idle"),[g,d]=o.useState(null),m=o.useRef(null),_=o.useRef(!1);o.useLayoutEffect(()=>{if(s&&!_.current){if(_.current=!0,r){f();return}d(m.current?.getBoundingClientRect().height??56),p("leaving")}else!s&&_.current&&(_.current=!1,p("idle"),d(null))},[s,r,f]),o.useEffect(()=>{if(!s||r||l==="idle")return;if(l==="leaving"){const C=setTimeout(()=>p("collapsing"),Ke);return()=>clearTimeout(C)}const S=setTimeout(f,Pe);return()=>clearTimeout(S)},[s,l,r,f]);const z={height:l==="collapsing"?0:g??void 0,overflow:l==="idle"?void 0:"hidden",transition:l==="idle"||r?void 0:l==="leaving"?`opacity ${Ke}ms var(--ease-out-quart), transform ${Ke}ms var(--ease-out-quart)`:`height ${Pe}ms var(--ease-out-quart), opacity ${Pe}ms var(--ease-out-quart)`,opacity:l==="idle"?void 0:0,transform:l==="leaving"?"translateY(-8px)":void 0,pointerEvents:l==="idle"?void 0:"none"};return e.jsx("div",{ref:m,style:z,className:J("shrink-0",l!=="idle"&&"motion-reduce:hidden"),"aria-hidden":l!=="idle"||void 0,...l!=="idle"?{inert:""}:{},"data-notification-exit":l==="idle"?void 0:l,children:n})},Hi=({progress:s})=>(Dt(),e.jsx("output",{className:"shrink-0 px-6 py-1 text-meta text-ink-muted","data-notification-operation":"",children:i("ui.notifications.operation.progress",s)})),bt=(s,n)=>{s&&(s.pending.length>0||s.error!==void 0)||n(null)},Wi=(s,n,f)=>{const r=o.useRef(s);r.current=s;const l=ei({queryKey:["desktop","notifications","session-scope-counts",f],enabled:n&&s!==void 0,queryFn:()=>Ii(zi(r.current)),retry:ti,staleTime:5e3,refetchOnWindowFocus:!1});return{counts:l.data,pending:s===void 0||l.data===void 0}},wt=s=>i("ui.notifications.operation.progress",s),Qe="notifications-read-state",Mt="notifications-grouping",Nt=(s,n,f)=>{try{const r=localStorage.getItem(s);return n.includes(r)?r:f}catch{return f}},Ge=(s,n)=>{try{localStorage.setItem(s,n)}catch{}},cs=({nowMs:s})=>{Dt();const{notificationId:n}=Vt(),f=Xt(),r=Yt(),p=Jt(r.data,"notifications",1)==="enabled",g=s??Date.now(),d=!At("(min-width: 1100px)"),{client:m}=Zt(),[_,z]=o.useState(()=>Nt(Qe,["unread","all"],"unread")),[S,C]=o.useState(()=>Nt(Mt,["time","conversation"],"time")),[b]=yi(),[R,T]=o.useState(()=>({...$e,from:b.get("from")||null})),[x,B]=o.useState(()=>new Set),[$,M]=o.useState(null),[O,h]=o.useState(null),[N,H]=o.useState(null),[P,G]=o.useState(null),[V,F]=o.useState(!1),k=o.useRef(!1),[_e,te]=o.useState(()=>new Map),De=o.useRef(new Map),[Ft,Ve]=o.useState(0),[Xe,Ot]=o.useState(null),[qt,Ye]=o.useState(!0),me=o.useRef(null),E=vi(_,p,{atTop:qt}),Je=bi(),U=wi(n??null,p),Lt=Ni(U.data?.item.session.id??null,p&&!!U.data?.item.session.id);o.useEffect(()=>{E.isSuccess&&!E.isFetching&&Ot(E.dataUpdatedAt)},[E.isSuccess,E.isFetching,E.dataUpdatedAt]);const I=E.data,ie=o.useMemo(()=>{const t=Si(I?.items??[],De.current);if(_!=="unread"||_e.size===0)return t;const a=new Set(t.map(c=>c.id));return[...t,...[..._e.values()].filter(c=>!a.has(c.id))]},[I,_,_e,Ft]),se=I?.waiting??[],Re=o.useMemo(()=>mt(ie,R),[ie,R]),Te=o.useMemo(()=>mt(se,R),[se,R]),Bt=Re.filter(t=>!t.read).length+Te.filter(t=>!t.read).length,Ae=o.useMemo(()=>Ci(Re,Te,S,g),[Re,Te,S,g]),w=o.useMemo(()=>_i(Ae),[Ae]),Ee=o.useMemo(()=>{const t=new Map;for(const a of[...se,...ie])t.set(a.id,a);return t},[ie,se]),Kt=o.useMemo(()=>{const t=new Map;for(const a of[...se,...ie]){const c=t.get(a.session.id)??[a.session.id,a.session.title||i("ui.notifications.group.untitled"),0];c[2]+=1,t.set(a.session.id,c)}return[...t.values()].sort((a,c)=>c[2]-a[2])},[ie,se]),Ze=E.isError&&!!I,et=Wi(I?.high_water,!!I&&Ti(S,!!n),[Di(I?.items??[],U.data?.item.session.id??""),Ri(U.data?.item.session.id?Lt.data:void 0)].join("|")).counts,K=Ze||V,[Pt,Ie]=o.useState(()=>new Set),he=o.useCallback(t=>{Ie(a=>new Set([...a,...t]))},[]),tt=o.useCallback(t=>{Ie(a=>{const c=new Set(a);for(const u of t)c.delete(u);return c})},[]),Qt=o.useCallback(t=>{Ie(a=>{const c=new Set(a);return c.delete(t),c})},[]),ne=n?Ee.get(n)??U.data?.item??null:null,ze=o.useRef(null);o.useEffect(()=>{if(!n){ze.current=null;return}const t=U.data?.item;!t||t.id!==n||ze.current===t.id||(ze.current=t.id,!(t.read||t.dismissed||K)&&Je.mutate({verb:"read",target:{items:Le([t])}}))},[n,U.data,Je,K]);const xe=o.useCallback(()=>{B(new Set),M(null)},[]),Z=o.useRef(null),Me=o.useCallback(async(t,a)=>{if(k.current)return;k.current=!0,F(!0),Z.current=null;let c=null;try{const u=await vt(ht,t,a,void 0,G),D=Ce(u);t==="unread"&&te(j=>{const q=new Map(j);for(const y of u.changed)q.delete(y.id);return q}),Li(u,a.length)?xt(i("ui.notifications.toast.undone")):je(wt(D)),c=u,pt(m,t,u.changed.map(j=>j.id))}finally{k.current=!1,F(!1),bt(c,G)}},[m]),X=o.useCallback(async(t,a,c,u,D=!1)=>{if(k.current&&!D)return;k.current=!0,F(!0);let j=null;Z.current=null;try{const q="items"in a?void 0:{scope:"sessionId"in a?{sessionId:a.sessionId}:{all:!0},throughSeq:a.throughSeq,tokens:c},y=await vt(ht,t,c,q,G),A=Ce(y);t==="read"?(te(Q=>{const de=new Map(Q);for(const ae of y.changed){const Oe=Ee.get(ae.id);Oe?de.set(Oe.id,{...Oe,read:!0,read_via:"explicit"}):De.current.set(ae.id,ae.revision)}return de}),Ve(Q=>Q+1)):t==="unread"&&(te(Q=>{const de=new Map(Q);for(const ae of y.changed)de.delete(ae.id),De.current.delete(ae.id);return de}),Ve(Q=>Q+1));const L=y.changed.length?{verb:Bi(t),items:y.changed,at:Date.now()}:null;Z.current=L;const Y=u({changed:y.changed.map(Q=>Q.id),skipped:y.skipped}),ce=A.pending>0||A.skipped>0;je([Y,ce?wt(A):null].filter(Boolean).join(". "),{duration:Be,action:L?{label:i("ui.notifications.toast.undo"),onClick:()=>{Z.current===L&&Date.now()-L.at<=Be&&Me(L.verb,L.items)}}:void 0}),j=y,pt(m,t,y.changed.map(Q=>Q.id))}finally{k.current=!1,F(!1),j?.error&&tt(new Set(c.map(q=>q.id))),bt(j,G)}},[m,Ee,tt,Me]),pe=o.useCallback(t=>{if(t.length===0||K)return;const a=t.some(j=>!j.read),c=a?"read":"unread",u=t.filter(j=>a?!j.read:j.read),D=Le(u);X(c,{items:D},D,j=>c==="read"?i("ui.notifications.toast.marked_read",{count:W(j.changed.length)}):i("ui.notifications.toast.marked_unread",{count:W(j.changed.length)}))},[X,K]),ge=o.useCallback(t=>{if(K)return;const{dismissable:a,asksStaying:c}=Et(t);if(a.length===0){c>0&&je(i("ui.notifications.ask.stays"));return}const u=Le(a),D=new Set(a.map(y=>y.id));he(D);const j=w.findIndex(y=>D.has(y.id)),q=w.slice(j+1).find(y=>!D.has(y.id))??[...w.slice(0,j)].reverse().find(y=>!D.has(y.id));h(q?.id??null),n&&D.has(n)&&f("/notifications"),xe(),X("dismiss",{items:u},u,y=>{const A=y.skipped.filter(ce=>ce.reason==="live_ask").length,L=i("ui.notifications.toast.dismissed",{count:y.changed.length}),Y=c+A;return Y>0?`${L}. ${i("ui.notifications.select.asks_stay",{count:Y})}`:L})},[he,xe,f,n,w,X,K]),Fe=o.useCallback(async(t,a)=>{if(!(!I||K||k.current)){k.current=!0,F(!0);try{const c=await yt(u=>fe({op:"notifications.list",...u}),{scope:{sessionId:t},throughSeq:I.high_water,waiting:[],verb:"dismiss"});c.tokens.length&&H({sessionId:t,title:a,count:c.tokens.length,snapshot:c})}catch{gt(i("ui.notifications.error.load.title"))}finally{k.current=!1,F(!1)}}},[I,K]),Ut=o.useCallback(()=>{if(!N)return;const{snapshot:t}=N;H(null),n&&t.tokens.some(a=>a.id===n)&&f("/notifications"),X("dismiss",{...t.scope,throughSeq:t.throughSeq,observed:[...t.tokens]},[...t.tokens],a=>{const c=new Set(w.map(D=>D.id)),u=Ai(c,a.changed);return u.size>0&&(he(u),te(D=>{const j=new Map(D);for(const q of u)j.delete(q);return j})),i("ui.notifications.toast.dismissed",{count:a.changed.length})})},[N,f,n,X,w,he]),Ht=o.useCallback(async()=>{if(!(!I||K||k.current)){k.current=!0,F(!0);try{const t=new Set((I.waiting??[]).filter(c=>!c.read).map(c=>c.id)),a=await yt(c=>fe({op:"notifications.list",...c}),{scope:{all:!0},throughSeq:I.high_water,waiting:I.observed.filter(c=>t.has(c.id)),verb:"read"});await X("read",{all:!0,throughSeq:a.throughSeq,observed:[...a.tokens]},[...a.tokens],c=>i("ui.notifications.toast.marked_read",{count:W(c.changed.length)}),!0)}catch{gt(i("ui.notifications.error.load.title"))}finally{k.current=!1,F(!1)}}},[I,X,K]),re=o.useCallback(t=>{h(t.id),f(`/notifications/${encodeURIComponent(t.id)}`)},[f]),it=o.useCallback(()=>{const t=n;f("/notifications"),t&&h(t)},[f,n]),st=o.useCallback(t=>{Gt(f,t)},[f]),nt=o.useCallback((t,a)=>{B(c=>{if(a)return kt(w,$,t.id,c);const u=new Set(c);return u.has(t.id)?u.delete(t.id):u.add(t.id),u}),M(t.id)},[$,w]),at=o.useCallback(t=>{re(t),je(i("ui.notifications.ask.stays"))},[re]),ot=O&&w.some(t=>t.id===O)?O:w[0]?.id??null;o.useEffect(()=>{if(!O)return;const t=me.current?.querySelector(`[data-notification-row="${CSS.escape(O)}"]`);t&&me.current?.contains(document.activeElement)&&t.focus()},[O]);const Wt=t=>{if(t.target.closest("input, textarea, [contenteditable='true']"))return;const c=w.findIndex(A=>A.id===ot),u=c>=0?w[c]:void 0,D=A=>{const L=Math.max(0,Math.min(w.length-1,A)),Y=w[L];Y&&(t.shiftKey&&u&&B(ce=>kt(w,u.id,Y.id,ce)),h(Y.id))},j=t.metaKey||t.ctrlKey,q=w.filter(A=>x.has(A.id)),y=q.length>0?q:u?[u]:[];switch(t.key){case"ArrowDown":case"j":case"J":if(j)return;t.preventDefault(),D(c+1);return;case"ArrowUp":case"k":case"K":if(j)return;t.preventDefault(),D(c-1);return;case"Home":t.preventDefault(),D(0);return;case"End":t.preventDefault(),D(w.length-1);return;case"Enter":u&&(t.preventDefault(),re(u));return;case"o":case"O":u&&!j&&(t.preventDefault(),st(u.session.id));return;case"x":case"X":u&&!j&&(t.preventDefault(),nt(u,!1));return;case"a":case"A":if(j){t.preventDefault(),B(new Set(w.map(A=>A.id)));return}if(u){t.preventDefault();const A=w.find(L=>L.session.id===u.session.id&&We(L));re(A??u)}return;case"e":case"E":if(j||!u)return;if(t.preventDefault(),t.shiftKey){Fe(u.session.id,u.session.title||i("ui.notifications.group.untitled"));return}if(q.length===0&&We(u)){at(u);return}ge(y);return;case"u":case"U":if(j)return;t.preventDefault(),pe(y);return;case"z":case"Z":if(j&&Z.current){t.preventDefault();const A=Z.current;Z.current=null,Date.now()-A.at<=Be&&A.items.length>0&&Me(A.verb,A.items)}return;case"Escape":if(x.size>0){t.preventDefault(),xe();return}n&&(t.preventDefault(),it());return}};if(!p)return e.jsxs("div",{className:"flex h-full flex-col gap-8 p-6",children:[e.jsx(lt,{title:i("ui.notifications.page.title"),icon:jt}),r.isLoading?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(dt,{label:i("ui.notifications.page.checking")})}):e.jsx(Se,{variant:"warning",children:i("ui.notifications.page.unavailable")})]});const le=w.filter(t=>x.has(t.id)),ke=!!(n&&ne),$t=d&&ke,rt=I&&w.length===0?It(R)?"filtered":_==="unread"?"caught_up":"none":null;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-notifications-page":"",children:[e.jsxs("div",{className:"flex shrink-0 flex-col gap-4 px-6 pt-6",children:[e.jsx(lt,{title:i("ui.notifications.page.title"),icon:jt,subtitle:i("ui.notifications.page.subtitle"),children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[E.newerCount>0&&e.jsxs(v,{size:"sm",variant:"secondary","data-notifications-back-to-top":"",onClick:()=>{me.current?.scrollTo({top:0}),Ye(!0),E.resetToTop()},children:[e.jsx(Rt,{"aria-hidden":"true"}),i("ui.notifications.new_pill",{count:W(E.newerCount)})]}),e.jsx(v,{variant:"ghost",size:"icon","aria-label":i("ui.notifications.page.refresh"),title:i("ui.notifications.page.refresh"),"aria-busy":E.isFetching||void 0,disabled:E.isFetching,onClick:()=>{te(new Map),E.resetToTop()},children:e.jsx(qi,{})})]})}),e.jsx(Xi,{loaded:I,readState:_,onReadState:t=>{z(t),te(new Map),Ge(Qe,t)},filters:R,setFilters:T,grouping:S,setGrouping:C,sources:Kt,writesPaused:K,markAllRead:Ht,selection:le,visibleCount:w.length,visibleUnread:Bt,onSelectAll:()=>B(le.length===w.length?new Set:new Set(w.map(t=>t.id))),onClearSelection:xe,onBulkRead:t=>pe(t==="read"?le.filter(a=>!a.read):le.filter(a=>a.read)),onBulkDismiss:()=>ge(le)})]}),Ze&&e.jsx("div",{className:"px-6 pt-3",children:e.jsxs(Se,{variant:"danger",role:"alert","data-notifications-refresh-error":"",children:[e.jsx("span",{className:"font-medium",children:i("ui.notifications.error.refresh.title")})," ",i("ui.notifications.error.refresh.body",{time:Xe?Tt(Xe,{hour:"2-digit",minute:"2-digit"}):""})]})}),e.jsxs("div",{className:"mt-3 flex min-h-0 flex-1",children:[!$t&&e.jsx("div",{className:J("flex min-h-0 flex-col",ke||!d?"w-[min(560px,46%)] shrink-0":"flex-1",d&&"w-full"),children:E.isError&&!I?e.jsxs("div",{className:"flex flex-col items-start gap-3 px-6 py-6",role:"alert",children:[e.jsx("p",{className:"text-body text-ink",children:i("ui.notifications.error.load.title")}),e.jsx(v,{variant:"secondary",onClick:()=>void E.refetch(),children:i("ui.notifications.error.retry")})]}):I?rt?e.jsx(Gi,{kind:rt,onShowAll:()=>{z("all"),Ge(Qe,"all")},onClearFilters:()=>T($e)}):e.jsx("div",{ref:me,role:"grid","aria-multiselectable":"true","aria-label":i("ui.notifications.page.list_label"),onKeyDown:Wt,onScroll:t=>{const a=t.currentTarget;Ye(a.scrollTop<=24),E.hasNextPage&&!E.isFetchingNextPage&&a.scrollHeight-a.scrollTop-a.clientHeight<160&&E.fetchNextPage()},className:"flex min-h-0 flex-1 flex-col overflow-y-auto overflow-x-hidden pb-6 [scrollbar-gutter:stable]","data-notifications-list":"",children:Ae.map(t=>e.jsx($i,{group:t,nowMs:g,openId:n??null,selected:x,focusedId:ot,writesPaused:K,exitingIds:Pt,onExitFinished:Qt,onOpen:re,onToggleSelect:nt,onToggleRead:a=>pe([a]),onDismiss:a=>ge([a]),onAnswer:at,onFocusRow:a=>h(a.id),onDismissSession:Fe,sessionCount:a=>et?.[a]??null},t.key))}):e.jsx(Ji,{})}),!d||ke?e.jsx("div",{className:J("flex min-h-0 flex-1 flex-col bg-surface",d&&"w-full"),children:ke&&ne?e.jsx(Pi,{item:ne,detail:U.data,loading:U.isLoading,error:U.isError,nowMs:g,narrow:d,writesPaused:K,sessionDismissCount:et?.[ne.session.id]??null,onClose:it,onOpenConversation:st,onToggleRead:t=>pe([t]),onDismiss:t=>ge([t]),onDismissSession:Fe,onCopyLink:t=>{navigator.clipboard?.writeText(`/notifications/${t.id}`).then(()=>xt(i("ui.notifications.toast.copied")))},onOpenProject:t=>f(`/projects/${encodeURIComponent(t)}`),onAsksSettled:()=>{m.invalidateQueries({queryKey:ye.factsRoot}),m.invalidateQueries({queryKey:ye.sessionFactsAll}),m.invalidateQueries({queryKey:ye.count}),m.invalidateQueries({queryKey:ye.detail(ne.id)})}},ne.id):e.jsx(Yi,{})}):null]}),V&&!P&&e.jsx(dt,{label:i("ui.notifications.page.loading")}),P&&e.jsx(Hi,{progress:P}),N&&e.jsx(Vi,{title:N.title,count:N.count,onConfirm:Ut,onCancel:()=>H(null)})]})},St=s=>{switch(s.kind){case"waiting":return i("ui.notifications.group.waiting");case"conversation":return s.title||i("ui.notifications.group.untitled");case"time":return s.key==="today"?i("ui.notifications.group.today"):s.key==="yesterday"?i("ui.notifications.group.yesterday"):s.key==="week"?i("ui.notifications.group.week"):i("ui.notifications.group.older")}},$i=({group:s,onDismissSession:n,sessionCount:f,...r})=>{const[l,p]=o.useState(s.kind==="time"&&s.key==="older"),g=s.kind==="conversation"?f(s.sessionId):0;return e.jsxs("div",{role:"rowgroup","data-notification-group":s.key,children:[e.jsxs("div",{role:"row",tabIndex:-1,className:"sticky top-0 z-[1] flex h-8 items-center gap-2 bg-canvas px-3 text-ink-muted text-meta",children:[e.jsx("span",{role:"rowheader",className:"flex min-w-0 items-center gap-1.5",children:s.kind==="time"&&s.key==="older"?e.jsxs("button",{type:"button",className:"inline-flex min-h-6 items-center gap-1 hover:text-ink","aria-expanded":!l,onClick:()=>p(d=>!d),children:[St(s),e.jsx("span",{className:"text-ink-dim tabular-nums",children:s.items.length}),l?e.jsx(Ne,{size:12}):e.jsx(Rt,{size:12})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate",children:St(s)}),e.jsx("span",{className:"text-ink-dim tabular-nums",children:s.items.length})]})}),s.kind==="conversation"&&g!==null&&g>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:"h-px flex-1 bg-hairline"}),e.jsx(v,{variant:"ghost",size:"sm",onClick:()=>n(s.sessionId,s.title),children:i("ui.notifications.group.dismiss_session",{count:W(g)})})]})]}),!l&&s.items.map(d=>e.jsx(Ui,{exiting:r.exitingIds.has(d.id),onExited:()=>r.onExitFinished(d.id),children:e.jsx(Ei,{item:d,nowMs:r.nowMs,open:r.openId===d.id,picked:r.selected.has(d.id),selecting:r.selected.size>0,focused:r.focusedId===d.id,writesPaused:r.writesPaused,onOpen:r.onOpen,onToggleSelect:r.onToggleSelect,onToggleRead:r.onToggleRead,onDismiss:r.onDismiss,onAnswer:r.onAnswer,onFocusRow:r.onFocusRow})},d.id))]})},Gi=({kind:s,onShowAll:n,onClearFilters:f})=>e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 py-16 text-center","data-notifications-empty":s,children:[s==="caught_up"&&e.jsx(zt,{size:24,"aria-hidden":"true",className:"text-ink-muted"}),e.jsx("p",{className:"text-heading text-ink",children:s==="caught_up"?i("ui.notifications.empty.caught_up.title"):s==="none"?i("ui.notifications.empty.none.title"):i("ui.notifications.empty.filtered.title")}),s!=="filtered"&&e.jsx("p",{className:"max-w-96 text-body-sm text-ink-muted",children:s==="caught_up"?i("ui.notifications.empty.caught_up.body"):i("ui.notifications.empty.none.body")}),s==="caught_up"&&e.jsx(v,{variant:"secondary",onClick:n,children:i("ui.notifications.empty.caught_up.show_all")}),s==="filtered"&&e.jsx(v,{variant:"secondary",onClick:f,children:i("ui.notifications.filter.clear")})]}),Vi=({title:s,count:n,onConfirm:f,onCancel:r})=>e.jsx(ai,{open:!0,onOpenChange:l=>!l&&r(),children:e.jsxs(oi,{className:"max-w-sm",children:[e.jsx(ri,{children:i("ui.notifications.confirm.dismiss_session",{count:n,source:s})}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx(v,{variant:"secondary",onClick:r,children:i("ui.notifications.confirm.cancel")}),e.jsx(v,{variant:"primary",autoFocus:!0,onClick:f,"data-notifications-confirm":"",children:i("ui.notifications.confirm.dismiss_session_ok")})]})]})}),Xi=({loaded:s,readState:n,onReadState:f,filters:r,setFilters:l,grouping:p,setGrouping:g,sources:d,writesPaused:m,markAllRead:_,selection:z,visibleCount:S,visibleUnread:C,onSelectAll:b,onClearSelection:R,onBulkRead:T,onBulkDismiss:x})=>{const{dismissable:B,asksStaying:$}=Et(z),M=z.length>0,O=z.length===0?!1:z.length===S?!0:"indeterminate";return e.jsx("div",{className:"flex min-h-11 shrink-0 flex-wrap items-center gap-2 border-hairline border-b py-2","data-notifications-toolbar":M?"selection":"filters",children:M?e.jsxs(e.Fragment,{children:[e.jsx(ii,{checked:O,"aria-label":i("ui.notifications.select.all"),onCheckedChange:b}),e.jsx("span",{className:"font-medium text-body-sm text-ink",children:i("ui.notifications.select.count",{count:W(z.length)})}),e.jsxs(v,{variant:"secondary",size:"sm","aria-disabled":m||void 0,onClick:()=>!m&&T("read"),children:[e.jsx(_t,{}),i("ui.notifications.select.mark_read")]}),e.jsxs(v,{variant:"secondary",size:"sm","aria-disabled":m||void 0,onClick:()=>!m&&T("unread"),children:[e.jsx(Ct,{}),i("ui.notifications.select.mark_unread")]}),e.jsxs(v,{variant:"secondary",size:"sm","aria-disabled":m||B.length===0||void 0,onClick:()=>!m&&B.length>0&&x(),"data-notifications-bulk-dismiss":B.length,children:[e.jsx(He,{}),i("ui.notifications.select.dismiss",{count:W(B.length)})]}),$>0&&e.jsx("span",{className:"text-ink-dim text-meta",role:"status","data-notifications-asks-stay":$,children:i("ui.notifications.select.asks_stay",{count:$})}),e.jsx("span",{className:"flex-1"}),e.jsxs(v,{variant:"ghost",size:"sm",onClick:R,children:[i("ui.notifications.select.clear"),e.jsx("kbd",{className:"ms-1 text-ink-dim text-meta",children:"Esc"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{role:"radiogroup","aria-label":i("ui.notifications.filter.read_state"),className:"flex items-center gap-0.5 rounded-sm bg-sunken p-0.5",children:["unread","all"].map(h=>e.jsxs("button",{type:"button",role:"radio","aria-checked":n===h,onClick:()=>f(h),className:J("flex h-7 items-center gap-1.5 rounded-xs px-2.5 text-body-sm",n===h?"bg-elevated text-ink":"text-ink-muted hover:text-ink"),children:[h==="unread"?i("ui.notifications.filter.unread"):i("ui.notifications.filter.all"),h==="unread"&&C>0&&e.jsx(si,{variant:"neutral",size:"count",children:ni(C,99)})]},h))}),[{label:i("ui.notifications.filter.kind"),value:r.kind,options:["all","asks","updates"],isDefault:r.kind==="all",set:h=>l(N=>({...N,kind:h})),optionLabel:h=>h==="asks"?i("ui.notifications.filter.kind_asks"):h==="updates"?i("ui.notifications.filter.kind_updates"):i("ui.notifications.filter.kind_all")},{label:i("ui.notifications.filter.priority"),value:r.priority,options:["any","high","normal_up"],isDefault:r.priority==="any",set:h=>l(N=>({...N,priority:h})),optionLabel:h=>h==="high"?i("ui.notifications.filter.priority_high"):h==="normal_up"?i("ui.notifications.filter.priority_normal_up"):i("ui.notifications.filter.priority_any")}].map(({label:h,value:N,options:H,isDefault:P,set:G,optionLabel:V})=>e.jsxs(ve,{children:[e.jsx(be,{asChild:!0,children:e.jsxs(v,{variant:"secondary",size:"sm",disabled:!s,children:[e.jsx(Ue,{label:h,value:V(N),emphasised:!P}),e.jsx(Ne,{})]})}),e.jsx(we,{align:"start",children:e.jsx(qe,{value:N,onValueChange:G,children:H.map(F=>e.jsx(ue,{value:F,children:V(F)},F))})})]},h)),d.length>0&&e.jsxs(ve,{children:[e.jsx(be,{asChild:!0,children:e.jsxs(v,{variant:"secondary",size:"sm",disabled:!s,children:[e.jsx(Ue,{label:i("ui.notifications.filter.from"),value:r.from===null?i("ui.notifications.filter.from_all"):d.find(([h])=>h===r.from)?.[1]??i("ui.notifications.group.untitled"),emphasised:r.from!==null}),e.jsx(Ne,{})]})}),e.jsx(we,{align:"start",children:e.jsxs(qe,{value:r.from??"",onValueChange:h=>l(N=>({...N,from:h||null})),children:[e.jsx(ue,{value:"",children:i("ui.notifications.filter.from_all")}),d.map(([h,N,H])=>e.jsxs(ue,{value:h,children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:N}),e.jsx("span",{className:"ms-3 text-ink-dim text-meta tabular-nums",children:H})]},h))]})})]}),It(r)&&e.jsx(v,{variant:"ghost",size:"sm",onClick:()=>l(()=>$e),children:i("ui.notifications.filter.clear")}),e.jsx("span",{className:"flex-1"}),e.jsxs(ve,{children:[e.jsx(be,{asChild:!0,children:e.jsxs(v,{variant:"secondary",size:"sm",children:[e.jsx(Ue,{label:i("ui.notifications.filter.group"),value:p==="time"?i("ui.notifications.filter.group_time"):i("ui.notifications.filter.group_conversation"),emphasised:p!=="time"}),e.jsx(Ne,{})]})}),e.jsx(we,{align:"end",children:e.jsxs(qe,{value:p,onValueChange:h=>{const N=h==="conversation"?"conversation":"time";g(N),Ge(Mt,N)},children:[e.jsx(ue,{value:"time",children:i("ui.notifications.filter.group_time")}),e.jsx(ue,{value:"conversation",children:i("ui.notifications.filter.group_conversation")})]})})]}),e.jsxs(v,{variant:"secondary",size:"sm",disabled:!s||(s?.unread_count??0)+(s?.waiting_unread_count??0)===0,"aria-disabled":m||void 0,title:m?i("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{!s||m||s.unread_count+s.waiting_unread_count===0||_()},"data-notifications-mark-all":"",children:[e.jsx(zt,{}),i("ui.notifications.action.mark_all_read")]})]})})},Ue=({label:s,value:n,emphasised:f})=>{const r=i("ui.notifications.filter.chip",{label:s,value:n}),l=r.lastIndexOf(n);return l<0?e.jsx("span",{children:r}):e.jsxs("span",{children:[r.slice(0,l),e.jsx("span",{className:J(f&&"font-semibold"),children:n}),r.slice(l+n.length)]})},Yi=()=>e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-ink-dim text-body-sm",children:i("ui.notifications.detail.empty")}),Ji=()=>e.jsx("div",{role:"status","aria-label":i("ui.notifications.page.loading"),className:"flex flex-col",children:Array.from({length:7},(s,n)=>e.jsxs("div",{className:"flex h-14 items-center gap-3 px-3","data-notification-skeleton":"",children:[e.jsx(ee,{className:"size-1.5 rounded-full bg-elevated"}),e.jsx(ee,{className:"size-4 bg-elevated"}),e.jsxs("div",{className:"flex flex-1 flex-col gap-1.5",children:[e.jsx(ee,{className:J("h-3 bg-elevated",n%2?"w-2/3":"w-1/2")}),e.jsx(ee,{className:J("h-2.5 bg-elevated",n%3?"w-1/3":"w-2/5")})]})]},n))});export{cs as NotificationsPage,Be as UNDO_WINDOW_MS};
1
+ import{r as o,j as e,c as J}from"./index-C4ae8MIc.js";import{o as Gt}from"./console-mirror-C-hKgNgn.js";import{d as fe,A as Vt,B as Xt,a as Yt,C as Jt,E as Zt,i as ei,r as ti}from"./path-utils-BqTfmiT0.js";import{P as lt}from"./page-header-BnTa4LRQ.js";import{B as v,X as He,A as Se,b as Ct,C as _t,D as ve,d as be,e as we,f as ct,g as ee,u as Dt,S as dt,h as Rt,i as ii,j as si,k as ni,l as Ne,m as qe,n as ue,o as ai,p as oi,q as ri}from"./error-boundary-BcPKKbP5.js";import{as as We,at as li,au as ci,av as di,aw as ut,ax as ft,ay as Tt,az as ui,aA as fi,aB as W,aC as mi,aD as hi,aE as xi,aF as pi,aG as gi,aH as ki,aI as ji,aJ as At,aK as yi,aL as $e,aM as vi,aN as bi,aO as wi,aP as Ni,aQ as Si,aR as mt,aS as Ci,aT as _i,aU as Di,aV as Ri,aW as Ti,aX as Le,aY as ht,aZ as xt,a_ as je,a$ as pt,b0 as Be,b1 as Et,W as gt,b2 as Ai,b3 as kt,b4 as It,b5 as ye,b6 as Ei,b7 as Ii,b8 as zi}from"./conversation-input-sync-BwcOsVjK.js";import{t as i}from"./messages-DoRCUI0R.js";import{P as Mi}from"./project-markdown-B-gfCIgA.js";import{A as Fi,F as Oi,h as jt,R as qi,C as zt}from"./index-pRJvOEvT.js";async function yt(s,n){const f=Object.freeze({...n.scope}),r=n.throughSeq,l=new Map;if(n.verb==="read"&&"all"in f)for(const d of n.waiting)l.set(d.id,Object.freeze({...d}));let p;const g=new Set;do{const d=await s({state:n.verb==="read"?"unread":"all",limit:100,throughSeq:r,source:"notify",..."sessionId"in f?{sessionId:f.sessionId}:{},...p?{cursor:p}:{}});for(const m of d.observed)!m.id.startsWith("ask:")&&!l.has(m.id)&&l.set(m.id,Object.freeze({...m}));if(p=d.next_cursor||void 0,p&&g.has(p))throw new Error("Notification cursor did not advance");p&&g.add(p)}while(p);return Object.freeze({scope:f,throughSeq:r,tokens:Object.freeze([...l.values()])})}const Ce=s=>({changed:s.changed.length,skipped:s.skipped.length,pending:s.pending.length}),Li=(s,n)=>s.changed.length===n&&s.skipped.length===0&&s.pending.length===0&&s.error===void 0,Bi=s=>s==="read"?"unread":s==="unread"?"read":s==="dismiss"?"undismiss":"dismiss";async function vt(s,n,f,r,l){const p=[...new Map(f.map(m=>[m.id,{...m}])).values()],g={changed:[],skipped:[],pending:p},d=new Set;l?.(Ce(g));for(let m=0;m<p.length;m+=500){const _=p.slice(m,m+500),z=new Map(_.map(S=>[S.id,S]));try{const S=await s(n,r?{...r.scope,throughSeq:r.throughSeq,observed:_}:{items:_});for(const C of S.changed){const b=z.get(C);b&&!d.has(C)&&(g.changed.push(b),d.add(C))}for(const C of S.skipped)z.has(C.id)&&!d.has(C.id)&&(g.skipped.push(C),d.add(C.id))}catch(S){g.error=S}if(g.pending=p.filter(S=>!d.has(S.id)),l?.(Ce(g)),g.error)break}return g}const Ki={},Pi=({item:s,detail:n,loading:f,error:r,nowMs:l,narrow:p,writesPaused:g,sessionDismissCount:d,onClose:m,onOpenConversation:_,onToggleRead:z,onDismiss:S,onDismissSession:C,onCopyLink:b,onOpenProject:R,onAsksSettled:T})=>{const x=n?.item??s,B=x.dismissed,$=We(x),M=g||B,O=x.session.title||i("ui.notifications.group.untitled"),h=x.repeat_count>1?x.repeat_count:0,[N,H]=o.useState(!1),P=n?.history??[],G=N?P:P.slice(0,5),V=n?.projects??x.projects??[],F=n?.item.body_md??"";return e.jsxs("section",{"aria-label":i("ui.notifications.detail.label"),"data-notification-detail":x.id,className:"flex min-h-0 flex-1 flex-col overflow-y-auto overflow-x-hidden px-6 py-4 [scrollbar-gutter:stable]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[p?e.jsxs(v,{variant:"ghost",size:"sm",onClick:m,children:[e.jsx(Fi,{className:"rtl:-scale-x-100","aria-hidden":"true"}),i("ui.notifications.detail.back")]}):e.jsxs("span",{className:"flex items-center gap-2 text-meta",children:[x.source==="ask"?e.jsx(li,{size:14,"aria-hidden":"true",className:"text-info"}):e.jsx(ci,{priority:x.priority}),e.jsx("span",{className:J(x.priority==="high"?"text-warning":"text-ink-muted"),children:di(x)}),e.jsx("span",{"aria-hidden":"true",className:"text-ink-dim",children:"·"}),e.jsx("span",{className:"text-ink-muted",children:x.source==="ask"?i("ui.notifications.detail.kind.ask"):i("ui.notifications.detail.kind.update")})]}),!p&&e.jsx(v,{variant:"ghost",size:"icon-sm","aria-label":i("ui.notifications.detail.close"),title:i("ui.notifications.detail.close"),onClick:m,children:e.jsx(He,{"aria-hidden":"true"})})]}),e.jsx("h2",{className:"mt-3 text-heading text-ink","data-notification-detail-title":"",tabIndex:-1,children:x.title}),e.jsxs("p",{className:"mt-1 flex flex-wrap items-center gap-x-1.5 text-ink-dim text-meta",children:[e.jsx("span",{className:"text-ink-muted",children:O}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:ut(ft(x.updated_at,l))}),h>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:i("ui.notifications.detail.meta.updates_since",{count:h,time:Tt(x.created_at,{hour:"2-digit",minute:"2-digit"})})})]})]}),B&&e.jsx(Se,{variant:"neutral",className:"mt-3",role:"status",children:i("ui.notifications.detail.gone.dismissed")}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[e.jsxs(v,{variant:"primary",size:"sm",onClick:()=>_(x.session.id),"data-notification-open-conversation":"",children:[e.jsx(ui,{"aria-hidden":"true",className:"rtl:-scale-x-100"}),i("ui.notifications.detail.open_conversation")]}),e.jsxs(v,{variant:"secondary",size:"sm","aria-disabled":M||void 0,className:M?"text-ink-disabled":void 0,title:g?i("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{M||z(x)},"data-notification-toggle-read":"",children:[x.read?e.jsx(Ct,{"aria-hidden":"true"}):e.jsx(_t,{"aria-hidden":"true"}),x.read?i("ui.notifications.row.mark_unread"):i("ui.notifications.row.mark_read")]}),!$&&e.jsxs(v,{variant:"secondary",size:"sm","aria-disabled":M||void 0,className:M?"text-ink-disabled":void 0,title:g?i("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{M||S(x)},"data-notification-dismiss":"",children:[e.jsx(He,{"aria-hidden":"true"}),i("ui.notifications.detail.dismiss")]}),e.jsxs(ve,{children:[e.jsx(be,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"icon-sm","aria-label":i("ui.notifications.row.more"),title:i("ui.notifications.row.more"),children:e.jsx(fi,{"aria-hidden":"true"})})}),e.jsxs(we,{align:"end",children:[e.jsx(ct,{disabled:M||(d===null?!1:d===0),onSelect:()=>C(x.session.id,O),children:i("ui.notifications.detail.more.dismiss_session",{source:O})}),e.jsx(ct,{onSelect:()=>b(x),children:i("ui.notifications.detail.more.copy_link")})]})]})]}),r&&!n&&e.jsx(Se,{variant:"danger",className:"mt-4",role:"alert",children:i("ui.notifications.detail.error")}),f&&!n?e.jsxs("div",{className:"mt-4 flex flex-col gap-2",role:"status","aria-label":i("ui.notifications.detail.loading"),children:[e.jsx(ee,{className:"h-3 w-full bg-elevated"}),e.jsx(ee,{className:"h-3 w-5/6 bg-elevated"}),e.jsx(ee,{className:"h-3 w-2/3 bg-elevated"})]}):F?e.jsx(Mi,{className:"mt-4 text-body text-ink",children:F}):x.excerpt?e.jsx("p",{className:"mt-4 text-body text-ink",children:x.excerpt}):null,(n?.item.links?.length??0)>0&&e.jsx(oe,{title:i("ui.notifications.detail.section.links"),children:e.jsx("ul",{className:"flex flex-col gap-1",children:n?.item.links?.map(k=>e.jsx("li",{children:e.jsx("a",{href:k.url,target:"_blank",rel:"noreferrer",className:"text-accent text-body-sm underline-offset-2 hover:underline",children:k.label||k.url})},k.url))})}),n?.anchor?.excerpt&&e.jsx(oe,{title:i("ui.notifications.detail.section.context"),children:e.jsx("p",{className:"line-clamp-4 text-body-sm text-ink-muted",children:n.anchor.excerpt})}),(n?.asks?.length??0)>0&&e.jsx(oe,{title:i("ui.notifications.detail.section.waiting"),children:e.jsx(Qi,{sessionId:x.session.id,asks:n?.asks??[],nowMs:l,onSettled:T})}),e.jsx(oe,{title:i("ui.notifications.detail.section.from"),children:e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md bg-surface px-3 py-2",children:[e.jsx("button",{type:"button",onClick:()=>_(x.session.id),className:"min-w-0 truncate text-start text-body-sm text-ink hover:underline",children:n?.session.title||O}),d!==0&&e.jsx(v,{variant:"ghost",size:"sm",className:"min-w-[6.5rem] shrink-0 tabular-nums","data-detail-dismiss-all":d===null?"counting":"ready","aria-busy":d===null||void 0,"aria-disabled":M||d===null||void 0,onClick:()=>{M||d===null||C(x.session.id,O)},children:i("ui.notifications.detail.from.dismiss_all",{count:d===null?"…":W(d)})})]})}),V.length>0&&e.jsx(oe,{title:i("ui.notifications.detail.section.projects"),children:e.jsx("ul",{className:"flex flex-col gap-1",children:V.map(k=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>R(k.key),className:"flex items-center gap-2 rounded-sm px-2 py-1 text-start text-body-sm text-ink hover:bg-row-hover",children:[e.jsx(Oi,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-muted"}),e.jsx("span",{className:"min-w-0 truncate",children:k.name}),k.status&&e.jsx("span",{className:"text-ink-dim text-meta",children:k.status})]})},k.key))})}),P.length>0&&e.jsxs(oe,{title:i("ui.notifications.detail.section.history"),children:[e.jsx("ol",{className:"flex flex-col gap-2",children:G.map(k=>e.jsxs("li",{className:"flex flex-col gap-0.5","data-history-revision":k.revision,children:[e.jsxs("span",{className:"flex items-baseline justify-between gap-2 text-body-sm text-ink",children:[e.jsx("span",{className:"min-w-0 truncate",children:k.title}),e.jsx("span",{className:"shrink-0 text-ink-dim text-meta tabular-nums",children:ut(ft(k.at,l))})]}),k.excerpt&&e.jsx("span",{className:"truncate text-ink-dim text-meta",children:k.excerpt})]},k.revision))}),P.length>5&&!N&&e.jsx(v,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>H(!0),children:i("ui.notifications.detail.history.show_all",{count:W(P.length)})})]})]})},oe=({title:s,children:n})=>e.jsxs("div",{className:"mt-6 flex flex-col gap-2",children:[e.jsx("h3",{className:"text-ink-muted text-meta",children:s}),n]}),Qi=({sessionId:s,asks:n,nowMs:f,onSettled:r})=>{const l=o.useRef(mi()).current,[p,g]=o.useState(Ki),[d,m]=o.useState({}),[_,z]=o.useState(!1),S=o.useMemo(()=>hi({asks:n,asks_open:n.filter(b=>b.status==="open").length,asks_truncated:!1},d),[n,d]),C=o.useCallback((b,R)=>{l.held||(z(!0),m(T=>({...T,[b]:{sending:!0,refused:null}})),(async()=>{let T;try{T=await R()}finally{z(!1)}m(x=>({...x,[b]:{sending:!1,refused:T.status==="failed"?xi(T.error):null}})),T.status==="sent"&&r()})())},[l,r]);return e.jsx(pi,{view:S,nowMs:f,answering:_,outcomes:d,drafts:p,onDraftChange:(b,R)=>g(T=>({...T,[b]:R})),onAnswer:(b,R)=>C(b.ask_id,()=>ji({taskId:b.ask_id,answers:R,sessionId:s,lock:l},T=>fe(T))),onDecline:b=>C(b.ask_id,()=>ki({taskId:b.ask_id,sessionId:s,lock:l},R=>fe(R))),onDismiss:(b,R)=>C(b.ask_id,()=>gi({taskId:b.ask_id,reason:R,sessionId:s,lock:l},T=>fe(T)))})},Ke=120,Pe=180,Ui=({exiting:s,children:n,onExited:f})=>{const r=At("(prefers-reduced-motion: reduce)"),[l,p]=o.useState("idle"),[g,d]=o.useState(null),m=o.useRef(null),_=o.useRef(!1);o.useLayoutEffect(()=>{if(s&&!_.current){if(_.current=!0,r){f();return}d(m.current?.getBoundingClientRect().height??56),p("leaving")}else!s&&_.current&&(_.current=!1,p("idle"),d(null))},[s,r,f]),o.useEffect(()=>{if(!s||r||l==="idle")return;if(l==="leaving"){const C=setTimeout(()=>p("collapsing"),Ke);return()=>clearTimeout(C)}const S=setTimeout(f,Pe);return()=>clearTimeout(S)},[s,l,r,f]);const z={height:l==="collapsing"?0:g??void 0,overflow:l==="idle"?void 0:"hidden",transition:l==="idle"||r?void 0:l==="leaving"?`opacity ${Ke}ms var(--ease-out-quart), transform ${Ke}ms var(--ease-out-quart)`:`height ${Pe}ms var(--ease-out-quart), opacity ${Pe}ms var(--ease-out-quart)`,opacity:l==="idle"?void 0:0,transform:l==="leaving"?"translateY(-8px)":void 0,pointerEvents:l==="idle"?void 0:"none"};return e.jsx("div",{ref:m,style:z,className:J("shrink-0",l!=="idle"&&"motion-reduce:hidden"),"aria-hidden":l!=="idle"||void 0,...l!=="idle"?{inert:""}:{},"data-notification-exit":l==="idle"?void 0:l,children:n})},Hi=({progress:s})=>(Dt(),e.jsx("output",{className:"shrink-0 px-6 py-1 text-meta text-ink-muted","data-notification-operation":"",children:i("ui.notifications.operation.progress",s)})),bt=(s,n)=>{s&&(s.pending.length>0||s.error!==void 0)||n(null)},Wi=(s,n,f)=>{const r=o.useRef(s);r.current=s;const l=ei({queryKey:["desktop","notifications","session-scope-counts",f],enabled:n&&s!==void 0,queryFn:()=>Ii(zi(r.current)),retry:ti,staleTime:5e3,refetchOnWindowFocus:!1});return{counts:l.data,pending:s===void 0||l.data===void 0}},wt=s=>i("ui.notifications.operation.progress",s),Qe="notifications-read-state",Mt="notifications-grouping",Nt=(s,n,f)=>{try{const r=localStorage.getItem(s);return n.includes(r)?r:f}catch{return f}},Ge=(s,n)=>{try{localStorage.setItem(s,n)}catch{}},cs=({nowMs:s})=>{Dt();const{notificationId:n}=Vt(),f=Xt(),r=Yt(),p=Jt(r.data,"notifications",1)==="enabled",g=s??Date.now(),d=!At("(min-width: 1100px)"),{client:m}=Zt(),[_,z]=o.useState(()=>Nt(Qe,["unread","all"],"unread")),[S,C]=o.useState(()=>Nt(Mt,["time","conversation"],"time")),[b]=yi(),[R,T]=o.useState(()=>({...$e,from:b.get("from")||null})),[x,B]=o.useState(()=>new Set),[$,M]=o.useState(null),[O,h]=o.useState(null),[N,H]=o.useState(null),[P,G]=o.useState(null),[V,F]=o.useState(!1),k=o.useRef(!1),[_e,te]=o.useState(()=>new Map),De=o.useRef(new Map),[Ft,Ve]=o.useState(0),[Xe,Ot]=o.useState(null),[qt,Ye]=o.useState(!0),me=o.useRef(null),E=vi(_,p,{atTop:qt}),Je=bi(),U=wi(n??null,p),Lt=Ni(U.data?.item.session.id??null,p&&!!U.data?.item.session.id);o.useEffect(()=>{E.isSuccess&&!E.isFetching&&Ot(E.dataUpdatedAt)},[E.isSuccess,E.isFetching,E.dataUpdatedAt]);const I=E.data,ie=o.useMemo(()=>{const t=Si(I?.items??[],De.current);if(_!=="unread"||_e.size===0)return t;const a=new Set(t.map(c=>c.id));return[...t,...[..._e.values()].filter(c=>!a.has(c.id))]},[I,_,_e,Ft]),se=I?.waiting??[],Re=o.useMemo(()=>mt(ie,R),[ie,R]),Te=o.useMemo(()=>mt(se,R),[se,R]),Bt=Re.filter(t=>!t.read).length+Te.filter(t=>!t.read).length,Ae=o.useMemo(()=>Ci(Re,Te,S,g),[Re,Te,S,g]),w=o.useMemo(()=>_i(Ae),[Ae]),Ee=o.useMemo(()=>{const t=new Map;for(const a of[...se,...ie])t.set(a.id,a);return t},[ie,se]),Kt=o.useMemo(()=>{const t=new Map;for(const a of[...se,...ie]){const c=t.get(a.session.id)??[a.session.id,a.session.title||i("ui.notifications.group.untitled"),0];c[2]+=1,t.set(a.session.id,c)}return[...t.values()].sort((a,c)=>c[2]-a[2])},[ie,se]),Ze=E.isError&&!!I,et=Wi(I?.high_water,!!I&&Ti(S,!!n),[Di(I?.items??[],U.data?.item.session.id??""),Ri(U.data?.item.session.id?Lt.data:void 0)].join("|")).counts,K=Ze||V,[Pt,Ie]=o.useState(()=>new Set),he=o.useCallback(t=>{Ie(a=>new Set([...a,...t]))},[]),tt=o.useCallback(t=>{Ie(a=>{const c=new Set(a);for(const u of t)c.delete(u);return c})},[]),Qt=o.useCallback(t=>{Ie(a=>{const c=new Set(a);return c.delete(t),c})},[]),ne=n?Ee.get(n)??U.data?.item??null:null,ze=o.useRef(null);o.useEffect(()=>{if(!n){ze.current=null;return}const t=U.data?.item;!t||t.id!==n||ze.current===t.id||(ze.current=t.id,!(t.read||t.dismissed||K)&&Je.mutate({verb:"read",target:{items:Le([t])}}))},[n,U.data,Je,K]);const xe=o.useCallback(()=>{B(new Set),M(null)},[]),Z=o.useRef(null),Me=o.useCallback(async(t,a)=>{if(k.current)return;k.current=!0,F(!0),Z.current=null;let c=null;try{const u=await vt(ht,t,a,void 0,G),D=Ce(u);t==="unread"&&te(j=>{const q=new Map(j);for(const y of u.changed)q.delete(y.id);return q}),Li(u,a.length)?xt(i("ui.notifications.toast.undone")):je(wt(D)),c=u,pt(m,t,u.changed.map(j=>j.id))}finally{k.current=!1,F(!1),bt(c,G)}},[m]),X=o.useCallback(async(t,a,c,u,D=!1)=>{if(k.current&&!D)return;k.current=!0,F(!0);let j=null;Z.current=null;try{const q="items"in a?void 0:{scope:"sessionId"in a?{sessionId:a.sessionId}:{all:!0},throughSeq:a.throughSeq,tokens:c},y=await vt(ht,t,c,q,G),A=Ce(y);t==="read"?(te(Q=>{const de=new Map(Q);for(const ae of y.changed){const Oe=Ee.get(ae.id);Oe?de.set(Oe.id,{...Oe,read:!0,read_via:"explicit"}):De.current.set(ae.id,ae.revision)}return de}),Ve(Q=>Q+1)):t==="unread"&&(te(Q=>{const de=new Map(Q);for(const ae of y.changed)de.delete(ae.id),De.current.delete(ae.id);return de}),Ve(Q=>Q+1));const L=y.changed.length?{verb:Bi(t),items:y.changed,at:Date.now()}:null;Z.current=L;const Y=u({changed:y.changed.map(Q=>Q.id),skipped:y.skipped}),ce=A.pending>0||A.skipped>0;je([Y,ce?wt(A):null].filter(Boolean).join(". "),{duration:Be,action:L?{label:i("ui.notifications.toast.undo"),onClick:()=>{Z.current===L&&Date.now()-L.at<=Be&&Me(L.verb,L.items)}}:void 0}),j=y,pt(m,t,y.changed.map(Q=>Q.id))}finally{k.current=!1,F(!1),j?.error&&tt(new Set(c.map(q=>q.id))),bt(j,G)}},[m,Ee,tt,Me]),pe=o.useCallback(t=>{if(t.length===0||K)return;const a=t.some(j=>!j.read),c=a?"read":"unread",u=t.filter(j=>a?!j.read:j.read),D=Le(u);X(c,{items:D},D,j=>c==="read"?i("ui.notifications.toast.marked_read",{count:W(j.changed.length)}):i("ui.notifications.toast.marked_unread",{count:W(j.changed.length)}))},[X,K]),ge=o.useCallback(t=>{if(K)return;const{dismissable:a,asksStaying:c}=Et(t);if(a.length===0){c>0&&je(i("ui.notifications.ask.stays"));return}const u=Le(a),D=new Set(a.map(y=>y.id));he(D);const j=w.findIndex(y=>D.has(y.id)),q=w.slice(j+1).find(y=>!D.has(y.id))??[...w.slice(0,j)].reverse().find(y=>!D.has(y.id));h(q?.id??null),n&&D.has(n)&&f("/notifications"),xe(),X("dismiss",{items:u},u,y=>{const A=y.skipped.filter(ce=>ce.reason==="live_ask").length,L=i("ui.notifications.toast.dismissed",{count:y.changed.length}),Y=c+A;return Y>0?`${L}. ${i("ui.notifications.select.asks_stay",{count:Y})}`:L})},[he,xe,f,n,w,X,K]),Fe=o.useCallback(async(t,a)=>{if(!(!I||K||k.current)){k.current=!0,F(!0);try{const c=await yt(u=>fe({op:"notifications.list",...u}),{scope:{sessionId:t},throughSeq:I.high_water,waiting:[],verb:"dismiss"});c.tokens.length&&H({sessionId:t,title:a,count:c.tokens.length,snapshot:c})}catch{gt(i("ui.notifications.error.load.title"))}finally{k.current=!1,F(!1)}}},[I,K]),Ut=o.useCallback(()=>{if(!N)return;const{snapshot:t}=N;H(null),n&&t.tokens.some(a=>a.id===n)&&f("/notifications"),X("dismiss",{...t.scope,throughSeq:t.throughSeq,observed:[...t.tokens]},[...t.tokens],a=>{const c=new Set(w.map(D=>D.id)),u=Ai(c,a.changed);return u.size>0&&(he(u),te(D=>{const j=new Map(D);for(const q of u)j.delete(q);return j})),i("ui.notifications.toast.dismissed",{count:a.changed.length})})},[N,f,n,X,w,he]),Ht=o.useCallback(async()=>{if(!(!I||K||k.current)){k.current=!0,F(!0);try{const t=new Set((I.waiting??[]).filter(c=>!c.read).map(c=>c.id)),a=await yt(c=>fe({op:"notifications.list",...c}),{scope:{all:!0},throughSeq:I.high_water,waiting:I.observed.filter(c=>t.has(c.id)),verb:"read"});await X("read",{all:!0,throughSeq:a.throughSeq,observed:[...a.tokens]},[...a.tokens],c=>i("ui.notifications.toast.marked_read",{count:W(c.changed.length)}),!0)}catch{gt(i("ui.notifications.error.load.title"))}finally{k.current=!1,F(!1)}}},[I,X,K]),re=o.useCallback(t=>{h(t.id),f(`/notifications/${encodeURIComponent(t.id)}`)},[f]),it=o.useCallback(()=>{const t=n;f("/notifications"),t&&h(t)},[f,n]),st=o.useCallback(t=>{Gt(f,t)},[f]),nt=o.useCallback((t,a)=>{B(c=>{if(a)return kt(w,$,t.id,c);const u=new Set(c);return u.has(t.id)?u.delete(t.id):u.add(t.id),u}),M(t.id)},[$,w]),at=o.useCallback(t=>{re(t),je(i("ui.notifications.ask.stays"))},[re]),ot=O&&w.some(t=>t.id===O)?O:w[0]?.id??null;o.useEffect(()=>{if(!O)return;const t=me.current?.querySelector(`[data-notification-row="${CSS.escape(O)}"]`);t&&me.current?.contains(document.activeElement)&&t.focus()},[O]);const Wt=t=>{if(t.target.closest("input, textarea, [contenteditable='true']"))return;const c=w.findIndex(A=>A.id===ot),u=c>=0?w[c]:void 0,D=A=>{const L=Math.max(0,Math.min(w.length-1,A)),Y=w[L];Y&&(t.shiftKey&&u&&B(ce=>kt(w,u.id,Y.id,ce)),h(Y.id))},j=t.metaKey||t.ctrlKey,q=w.filter(A=>x.has(A.id)),y=q.length>0?q:u?[u]:[];switch(t.key){case"ArrowDown":case"j":case"J":if(j)return;t.preventDefault(),D(c+1);return;case"ArrowUp":case"k":case"K":if(j)return;t.preventDefault(),D(c-1);return;case"Home":t.preventDefault(),D(0);return;case"End":t.preventDefault(),D(w.length-1);return;case"Enter":u&&(t.preventDefault(),re(u));return;case"o":case"O":u&&!j&&(t.preventDefault(),st(u.session.id));return;case"x":case"X":u&&!j&&(t.preventDefault(),nt(u,!1));return;case"a":case"A":if(j){t.preventDefault(),B(new Set(w.map(A=>A.id)));return}if(u){t.preventDefault();const A=w.find(L=>L.session.id===u.session.id&&We(L));re(A??u)}return;case"e":case"E":if(j||!u)return;if(t.preventDefault(),t.shiftKey){Fe(u.session.id,u.session.title||i("ui.notifications.group.untitled"));return}if(q.length===0&&We(u)){at(u);return}ge(y);return;case"u":case"U":if(j)return;t.preventDefault(),pe(y);return;case"z":case"Z":if(j&&Z.current){t.preventDefault();const A=Z.current;Z.current=null,Date.now()-A.at<=Be&&A.items.length>0&&Me(A.verb,A.items)}return;case"Escape":if(x.size>0){t.preventDefault(),xe();return}n&&(t.preventDefault(),it());return}};if(!p)return e.jsxs("div",{className:"flex h-full flex-col gap-8 p-6",children:[e.jsx(lt,{title:i("ui.notifications.page.title"),icon:jt}),r.isLoading?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(dt,{label:i("ui.notifications.page.checking")})}):e.jsx(Se,{variant:"warning",children:i("ui.notifications.page.unavailable")})]});const le=w.filter(t=>x.has(t.id)),ke=!!(n&&ne),$t=d&&ke,rt=I&&w.length===0?It(R)?"filtered":_==="unread"?"caught_up":"none":null;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-notifications-page":"",children:[e.jsxs("div",{className:"flex shrink-0 flex-col gap-4 px-6 pt-6",children:[e.jsx(lt,{title:i("ui.notifications.page.title"),icon:jt,subtitle:i("ui.notifications.page.subtitle"),children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[E.newerCount>0&&e.jsxs(v,{size:"sm",variant:"secondary","data-notifications-back-to-top":"",onClick:()=>{me.current?.scrollTo({top:0}),Ye(!0),E.resetToTop()},children:[e.jsx(Rt,{"aria-hidden":"true"}),i("ui.notifications.new_pill",{count:W(E.newerCount)})]}),e.jsx(v,{variant:"ghost",size:"icon","aria-label":i("ui.notifications.page.refresh"),title:i("ui.notifications.page.refresh"),"aria-busy":E.isFetching||void 0,disabled:E.isFetching,onClick:()=>{te(new Map),E.resetToTop()},children:e.jsx(qi,{})})]})}),e.jsx(Xi,{loaded:I,readState:_,onReadState:t=>{z(t),te(new Map),Ge(Qe,t)},filters:R,setFilters:T,grouping:S,setGrouping:C,sources:Kt,writesPaused:K,markAllRead:Ht,selection:le,visibleCount:w.length,visibleUnread:Bt,onSelectAll:()=>B(le.length===w.length?new Set:new Set(w.map(t=>t.id))),onClearSelection:xe,onBulkRead:t=>pe(t==="read"?le.filter(a=>!a.read):le.filter(a=>a.read)),onBulkDismiss:()=>ge(le)})]}),Ze&&e.jsx("div",{className:"px-6 pt-3",children:e.jsxs(Se,{variant:"danger",role:"alert","data-notifications-refresh-error":"",children:[e.jsx("span",{className:"font-medium",children:i("ui.notifications.error.refresh.title")})," ",i("ui.notifications.error.refresh.body",{time:Xe?Tt(Xe,{hour:"2-digit",minute:"2-digit"}):""})]})}),e.jsxs("div",{className:"mt-3 flex min-h-0 flex-1",children:[!$t&&e.jsx("div",{className:J("flex min-h-0 flex-col",ke||!d?"w-[min(560px,46%)] shrink-0":"flex-1",d&&"w-full"),children:E.isError&&!I?e.jsxs("div",{className:"flex flex-col items-start gap-3 px-6 py-6",role:"alert",children:[e.jsx("p",{className:"text-body text-ink",children:i("ui.notifications.error.load.title")}),e.jsx(v,{variant:"secondary",onClick:()=>void E.refetch(),children:i("ui.notifications.error.retry")})]}):I?rt?e.jsx(Gi,{kind:rt,onShowAll:()=>{z("all"),Ge(Qe,"all")},onClearFilters:()=>T($e)}):e.jsx("div",{ref:me,role:"grid","aria-multiselectable":"true","aria-label":i("ui.notifications.page.list_label"),onKeyDown:Wt,onScroll:t=>{const a=t.currentTarget;Ye(a.scrollTop<=24),E.hasNextPage&&!E.isFetchingNextPage&&a.scrollHeight-a.scrollTop-a.clientHeight<160&&E.fetchNextPage()},className:"flex min-h-0 flex-1 flex-col overflow-y-auto overflow-x-hidden pb-6 [scrollbar-gutter:stable]","data-notifications-list":"",children:Ae.map(t=>e.jsx($i,{group:t,nowMs:g,openId:n??null,selected:x,focusedId:ot,writesPaused:K,exitingIds:Pt,onExitFinished:Qt,onOpen:re,onToggleSelect:nt,onToggleRead:a=>pe([a]),onDismiss:a=>ge([a]),onAnswer:at,onFocusRow:a=>h(a.id),onDismissSession:Fe,sessionCount:a=>et?.[a]??null},t.key))}):e.jsx(Ji,{})}),!d||ke?e.jsx("div",{className:J("flex min-h-0 flex-1 flex-col bg-surface",d&&"w-full"),children:ke&&ne?e.jsx(Pi,{item:ne,detail:U.data,loading:U.isLoading,error:U.isError,nowMs:g,narrow:d,writesPaused:K,sessionDismissCount:et?.[ne.session.id]??null,onClose:it,onOpenConversation:st,onToggleRead:t=>pe([t]),onDismiss:t=>ge([t]),onDismissSession:Fe,onCopyLink:t=>{navigator.clipboard?.writeText(`/notifications/${t.id}`).then(()=>xt(i("ui.notifications.toast.copied")))},onOpenProject:t=>f(`/projects/${encodeURIComponent(t)}`),onAsksSettled:()=>{m.invalidateQueries({queryKey:ye.factsRoot}),m.invalidateQueries({queryKey:ye.sessionFactsAll}),m.invalidateQueries({queryKey:ye.count}),m.invalidateQueries({queryKey:ye.detail(ne.id)})}},ne.id):e.jsx(Yi,{})}):null]}),V&&!P&&e.jsx(dt,{label:i("ui.notifications.page.loading")}),P&&e.jsx(Hi,{progress:P}),N&&e.jsx(Vi,{title:N.title,count:N.count,onConfirm:Ut,onCancel:()=>H(null)})]})},St=s=>{switch(s.kind){case"waiting":return i("ui.notifications.group.waiting");case"conversation":return s.title||i("ui.notifications.group.untitled");case"time":return s.key==="today"?i("ui.notifications.group.today"):s.key==="yesterday"?i("ui.notifications.group.yesterday"):s.key==="week"?i("ui.notifications.group.week"):i("ui.notifications.group.older")}},$i=({group:s,onDismissSession:n,sessionCount:f,...r})=>{const[l,p]=o.useState(s.kind==="time"&&s.key==="older"),g=s.kind==="conversation"?f(s.sessionId):0;return e.jsxs("div",{role:"rowgroup","data-notification-group":s.key,children:[e.jsxs("div",{role:"row",tabIndex:-1,className:"sticky top-0 z-[1] flex h-8 items-center gap-2 bg-canvas px-3 text-ink-muted text-meta",children:[e.jsx("span",{role:"rowheader",className:"flex min-w-0 items-center gap-1.5",children:s.kind==="time"&&s.key==="older"?e.jsxs("button",{type:"button",className:"inline-flex min-h-6 items-center gap-1 hover:text-ink","aria-expanded":!l,onClick:()=>p(d=>!d),children:[St(s),e.jsx("span",{className:"text-ink-dim tabular-nums",children:s.items.length}),l?e.jsx(Ne,{size:12}):e.jsx(Rt,{size:12})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate",children:St(s)}),e.jsx("span",{className:"text-ink-dim tabular-nums",children:s.items.length})]})}),s.kind==="conversation"&&g!==null&&g>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:"h-px flex-1 bg-hairline"}),e.jsx(v,{variant:"ghost",size:"sm",onClick:()=>n(s.sessionId,s.title),children:i("ui.notifications.group.dismiss_session",{count:W(g)})})]})]}),!l&&s.items.map(d=>e.jsx(Ui,{exiting:r.exitingIds.has(d.id),onExited:()=>r.onExitFinished(d.id),children:e.jsx(Ei,{item:d,nowMs:r.nowMs,open:r.openId===d.id,picked:r.selected.has(d.id),selecting:r.selected.size>0,focused:r.focusedId===d.id,writesPaused:r.writesPaused,onOpen:r.onOpen,onToggleSelect:r.onToggleSelect,onToggleRead:r.onToggleRead,onDismiss:r.onDismiss,onAnswer:r.onAnswer,onFocusRow:r.onFocusRow})},d.id))]})},Gi=({kind:s,onShowAll:n,onClearFilters:f})=>e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 py-16 text-center","data-notifications-empty":s,children:[s==="caught_up"&&e.jsx(zt,{size:24,"aria-hidden":"true",className:"text-ink-muted"}),e.jsx("p",{className:"text-heading text-ink",children:s==="caught_up"?i("ui.notifications.empty.caught_up.title"):s==="none"?i("ui.notifications.empty.none.title"):i("ui.notifications.empty.filtered.title")}),s!=="filtered"&&e.jsx("p",{className:"max-w-96 text-body-sm text-ink-muted",children:s==="caught_up"?i("ui.notifications.empty.caught_up.body"):i("ui.notifications.empty.none.body")}),s==="caught_up"&&e.jsx(v,{variant:"secondary",onClick:n,children:i("ui.notifications.empty.caught_up.show_all")}),s==="filtered"&&e.jsx(v,{variant:"secondary",onClick:f,children:i("ui.notifications.filter.clear")})]}),Vi=({title:s,count:n,onConfirm:f,onCancel:r})=>e.jsx(ai,{open:!0,onOpenChange:l=>!l&&r(),children:e.jsxs(oi,{className:"max-w-sm",children:[e.jsx(ri,{children:i("ui.notifications.confirm.dismiss_session",{count:n,source:s})}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx(v,{variant:"secondary",onClick:r,children:i("ui.notifications.confirm.cancel")}),e.jsx(v,{variant:"primary",autoFocus:!0,onClick:f,"data-notifications-confirm":"",children:i("ui.notifications.confirm.dismiss_session_ok")})]})]})}),Xi=({loaded:s,readState:n,onReadState:f,filters:r,setFilters:l,grouping:p,setGrouping:g,sources:d,writesPaused:m,markAllRead:_,selection:z,visibleCount:S,visibleUnread:C,onSelectAll:b,onClearSelection:R,onBulkRead:T,onBulkDismiss:x})=>{const{dismissable:B,asksStaying:$}=Et(z),M=z.length>0,O=z.length===0?!1:z.length===S?!0:"indeterminate";return e.jsx("div",{className:"flex min-h-11 shrink-0 flex-wrap items-center gap-2 border-hairline border-b py-2","data-notifications-toolbar":M?"selection":"filters",children:M?e.jsxs(e.Fragment,{children:[e.jsx(ii,{checked:O,"aria-label":i("ui.notifications.select.all"),onCheckedChange:b}),e.jsx("span",{className:"font-medium text-body-sm text-ink",children:i("ui.notifications.select.count",{count:W(z.length)})}),e.jsxs(v,{variant:"secondary",size:"sm","aria-disabled":m||void 0,onClick:()=>!m&&T("read"),children:[e.jsx(_t,{}),i("ui.notifications.select.mark_read")]}),e.jsxs(v,{variant:"secondary",size:"sm","aria-disabled":m||void 0,onClick:()=>!m&&T("unread"),children:[e.jsx(Ct,{}),i("ui.notifications.select.mark_unread")]}),e.jsxs(v,{variant:"secondary",size:"sm","aria-disabled":m||B.length===0||void 0,onClick:()=>!m&&B.length>0&&x(),"data-notifications-bulk-dismiss":B.length,children:[e.jsx(He,{}),i("ui.notifications.select.dismiss",{count:W(B.length)})]}),$>0&&e.jsx("span",{className:"text-ink-dim text-meta",role:"status","data-notifications-asks-stay":$,children:i("ui.notifications.select.asks_stay",{count:$})}),e.jsx("span",{className:"flex-1"}),e.jsxs(v,{variant:"ghost",size:"sm",onClick:R,children:[i("ui.notifications.select.clear"),e.jsx("kbd",{className:"ms-1 text-ink-dim text-meta",children:"Esc"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{role:"radiogroup","aria-label":i("ui.notifications.filter.read_state"),className:"flex items-center gap-0.5 rounded-sm bg-sunken p-0.5",children:["unread","all"].map(h=>e.jsxs("button",{type:"button",role:"radio","aria-checked":n===h,onClick:()=>f(h),className:J("flex h-7 items-center gap-1.5 rounded-xs px-2.5 text-body-sm",n===h?"bg-elevated text-ink":"text-ink-muted hover:text-ink"),children:[h==="unread"?i("ui.notifications.filter.unread"):i("ui.notifications.filter.all"),h==="unread"&&C>0&&e.jsx(si,{variant:"neutral",size:"count",children:ni(C,99)})]},h))}),[{label:i("ui.notifications.filter.kind"),value:r.kind,options:["all","asks","updates"],isDefault:r.kind==="all",set:h=>l(N=>({...N,kind:h})),optionLabel:h=>h==="asks"?i("ui.notifications.filter.kind_asks"):h==="updates"?i("ui.notifications.filter.kind_updates"):i("ui.notifications.filter.kind_all")},{label:i("ui.notifications.filter.priority"),value:r.priority,options:["any","high","normal_up"],isDefault:r.priority==="any",set:h=>l(N=>({...N,priority:h})),optionLabel:h=>h==="high"?i("ui.notifications.filter.priority_high"):h==="normal_up"?i("ui.notifications.filter.priority_normal_up"):i("ui.notifications.filter.priority_any")}].map(({label:h,value:N,options:H,isDefault:P,set:G,optionLabel:V})=>e.jsxs(ve,{children:[e.jsx(be,{asChild:!0,children:e.jsxs(v,{variant:"secondary",size:"sm",disabled:!s,children:[e.jsx(Ue,{label:h,value:V(N),emphasised:!P}),e.jsx(Ne,{})]})}),e.jsx(we,{align:"start",children:e.jsx(qe,{value:N,onValueChange:G,children:H.map(F=>e.jsx(ue,{value:F,children:V(F)},F))})})]},h)),d.length>0&&e.jsxs(ve,{children:[e.jsx(be,{asChild:!0,children:e.jsxs(v,{variant:"secondary",size:"sm",disabled:!s,children:[e.jsx(Ue,{label:i("ui.notifications.filter.from"),value:r.from===null?i("ui.notifications.filter.from_all"):d.find(([h])=>h===r.from)?.[1]??i("ui.notifications.group.untitled"),emphasised:r.from!==null}),e.jsx(Ne,{})]})}),e.jsx(we,{align:"start",children:e.jsxs(qe,{value:r.from??"",onValueChange:h=>l(N=>({...N,from:h||null})),children:[e.jsx(ue,{value:"",children:i("ui.notifications.filter.from_all")}),d.map(([h,N,H])=>e.jsxs(ue,{value:h,children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:N}),e.jsx("span",{className:"ms-3 text-ink-dim text-meta tabular-nums",children:H})]},h))]})})]}),It(r)&&e.jsx(v,{variant:"ghost",size:"sm",onClick:()=>l(()=>$e),children:i("ui.notifications.filter.clear")}),e.jsx("span",{className:"flex-1"}),e.jsxs(ve,{children:[e.jsx(be,{asChild:!0,children:e.jsxs(v,{variant:"secondary",size:"sm",children:[e.jsx(Ue,{label:i("ui.notifications.filter.group"),value:p==="time"?i("ui.notifications.filter.group_time"):i("ui.notifications.filter.group_conversation"),emphasised:p!=="time"}),e.jsx(Ne,{})]})}),e.jsx(we,{align:"end",children:e.jsxs(qe,{value:p,onValueChange:h=>{const N=h==="conversation"?"conversation":"time";g(N),Ge(Mt,N)},children:[e.jsx(ue,{value:"time",children:i("ui.notifications.filter.group_time")}),e.jsx(ue,{value:"conversation",children:i("ui.notifications.filter.group_conversation")})]})})]}),e.jsxs(v,{variant:"secondary",size:"sm",disabled:!s||(s?.unread_count??0)+(s?.waiting_unread_count??0)===0,"aria-disabled":m||void 0,title:m?i("ui.notifications.writes_paused_tip"):void 0,onClick:()=>{!s||m||s.unread_count+s.waiting_unread_count===0||_()},"data-notifications-mark-all":"",children:[e.jsx(zt,{}),i("ui.notifications.action.mark_all_read")]})]})})},Ue=({label:s,value:n,emphasised:f})=>{const r=i("ui.notifications.filter.chip",{label:s,value:n}),l=r.lastIndexOf(n);return l<0?e.jsx("span",{children:r}):e.jsxs("span",{children:[r.slice(0,l),e.jsx("span",{className:J(f&&"font-semibold"),children:n}),r.slice(l+n.length)]})},Yi=()=>e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-ink-dim text-body-sm",children:i("ui.notifications.detail.empty")}),Ji=()=>e.jsx("div",{role:"status","aria-label":i("ui.notifications.page.loading"),className:"flex flex-col",children:Array.from({length:7},(s,n)=>e.jsxs("div",{className:"flex h-14 items-center gap-3 px-3","data-notification-skeleton":"",children:[e.jsx(ee,{className:"size-1.5 rounded-full bg-elevated"}),e.jsx(ee,{className:"size-4 bg-elevated"}),e.jsxs("div",{className:"flex flex-1 flex-col gap-1.5",children:[e.jsx(ee,{className:J("h-3 bg-elevated",n%2?"w-2/3":"w-1/2")}),e.jsx(ee,{className:J("h-2.5 bg-elevated",n%3?"w-1/3":"w-2/5")})]})]},n))});export{cs as NotificationsPage,Be as UNDO_WINDOW_MS};
@@ -1 +1 @@
1
- import{r as v,j as s,c as R}from"./index-C4ae8MIc.js";import{x as z,y as G,z as J,D as Y,E as C,H as K,G as V,I as O,J as U,K as X,L as Z,M as ee,O as E,Q as ie}from"./index-D9MeD_9S.js";import{u as j,B as g,i as te,o as se,p as ae,y as ne,q as le,z as re,F as ue}from"./error-boundary-BcPKKbP5.js";import{t as l}from"./messages-DoRCUI0R.js";import{i as w,u as y,a as M,c as F,r as B,d as I,F as A,G as oe}from"./path-utils-BqTfmiT0.js";import{bg as Q,a7 as m,ba as P}from"./conversation-input-sync-BwcOsVjK.js";const _=e=>e==null?"":typeof e=="string"?e:JSON.stringify(e,null,2),ce={available:"border-hairline",updating:"border-hairline",applied:"border-hairline",review:"border-warning-border",failed:"border-danger-border"};function de(e){const i=[];for(const t of e??[])for(const n of t.fields??[])for(const a of n.regions??[])(a.provenance==="unresolved"||_(a.local)!==_(a.remote))&&i.push({field:n.field,region:a});return i}function be({regions:e}){return j(),e.length?s.jsx("ul",{className:"space-y-3","data-testid":"hub-update-preview",children:e.map(({field:i,region:t},n)=>s.jsxs("li",{className:"space-y-1 text-meta",children:[s.jsx("p",{className:"font-medium text-ink",children:t.heading||t.name||i}),s.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-ink-muted",children:l("ui.agents.navigation.updates.preview.local")}),s.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap rounded-sm border border-hairline p-2 text-ink",children:_(t.local)||l("ui.agents.navigation.updates.preview.nothing")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"text-ink-muted",children:l("ui.agents.navigation.updates.preview.remote")}),s.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap rounded-sm border border-hairline p-2 text-ink",children:_(t.remote)||l("ui.agents.navigation.updates.preview.nothing")})]})]})]},`${i}:${t.id??n}`))}):s.jsx("p",{className:"text-meta text-ink-muted",children:l("ui.agents.navigation.updates.preview.empty")})}function Ee({kind:e,name:i,enabled:t}){j();const n=z(t),a=G(),[d,b]=v.useState(null),h=Y(e,i),k=J(n.data).get(h),o=C(k),c=a.notes[h],r=a.pending.has(h);if(!k||!o)return c?s.jsx("section",{"data-testid":"hub-update-panel","aria-label":l("ui.agents.navigation.updates.accessible"),className:"mb-8 rounded-md border border-hairline p-3 text-body-sm",children:s.jsx("p",{role:c.tone==="error"?"alert":"status",className:c.tone==="error"?"text-danger":"text-ink",children:c.message})}):null;const p=o.kind==="review",u=k.classification==="baseline-unknown",f=q=>({prefer:q,acknowledgeUnknownBaseline:u}),$=async()=>{const q=await a.applyItem(e,i,{...f(),dryRun:!0});b(q??[])};return s.jsxs("section",{"data-testid":"hub-update-panel","aria-label":l("ui.agents.navigation.updates.accessible"),className:R("mb-8 space-y-2 rounded-md border p-3 text-body-sm",ce[o.kind]),children:[s.jsxs("p",{className:"flex items-start gap-2 text-ink",children:[s.jsx(K,{mark:o,className:"mt-0.5"}),s.jsx("span",{className:R(o.kind==="failed"&&"text-danger"),children:V(k,o)})]}),a.upgradeMessage&&s.jsx("output",{className:"block text-meta text-warning","data-hub-core-upgrade":!0,children:a.upgradeMessage}),p&&u&&s.jsx("p",{className:"text-meta text-ink-muted",children:l("ui.agents.navigation.updates.baseline_unknown")}),p&&!u&&s.jsx("p",{className:"text-meta text-ink-muted",children:l("ui.agents.navigation.updates.merge_guidance")}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.kind==="available"&&s.jsx(g,{size:"sm",variant:"outline","aria-disabled":r||!a.canWrite||void 0,onClick:()=>!r&&a.canWrite&&void a.applyItem(e,i),children:r?l("ui.agents.navigation.updates.action.updating"):l("ui.agents.navigation.updates.action.update")}),o.kind==="failed"&&o.retryable&&s.jsx(g,{size:"sm",variant:"outline","aria-disabled":r||!a.canWrite||void 0,onClick:()=>!r&&a.canWrite&&void a.retryItem(e,i),children:r?l("ui.agents.navigation.updates.action.retrying"):l("ui.agents.navigation.updates.action.retry")}),p&&s.jsxs(s.Fragment,{children:[s.jsx(g,{size:"sm",variant:"outline","aria-disabled":r||!a.canWrite||void 0,onClick:()=>!r&&a.canWrite&&void $(),children:r&&!d?l("ui.agents.navigation.updates.action.loading"):l("ui.agents.navigation.updates.action.preview")}),s.jsx(g,{size:"sm",variant:"ghost","aria-disabled":r||!a.canWrite||void 0,onClick:()=>!r&&a.canWrite&&void a.applyItem(e,i,f("local")),children:l("ui.agents.navigation.updates.action.keep_local")}),s.jsx(g,{size:"sm",variant:"ghost","aria-disabled":r||!a.canWrite||void 0,onClick:()=>!r&&a.canWrite&&void a.applyItem(e,i,f("remote")),children:l("ui.agents.navigation.updates.action.use_remote")})]})]}),d&&p&&s.jsx(be,{regions:de(d)}),c&&s.jsx("p",{role:c.tone==="error"?"alert":"status",className:c.tone==="error"?"text-meta text-danger":"text-meta text-ink-muted",children:c.message})]})}const pe=/\/+$/;function W(e){const i=e.replace(pe,"");try{const{pathname:t}=new URL(i);return t===""||t==="/"?`${i}/v1`:i}catch{return`${i}/v1`}}const Fe=e=>e?.skills===1&&e.revision_cas===1;function he(e,i=1,t=20){const n=new URL(O(e,"skills"));return n.searchParams.set("page",String(i)),n.searchParams.set("per_page",String(t)),U(n.toString())}function me(e,i){return U(O(e,"skills",i))}function ke(e){return Q({operation:"org_skills.list",tenantId:e})}function ge(e,i){return Q({operation:"org_skill.get",tenantId:e,skillId:i})}const fe=12,S={all:["public-teams"],list:(e,i)=>[...S.all,"list",{page:e,perPage:i}],detail:e=>[...S.all,"detail",e]},N=(e,i)=>i instanceof X?i.status===null?!1:i.status>=500&&e<1:e<1,Te=({page:e=1,perPage:i=fe,enabled:t=!0}={})=>{const n=w({queryKey:S.list(e,i),queryFn:()=>Z(m.radientBaseUrl,e,i),select:a=>a.result,enabled:t,retry:N,staleTime:3e5,gcTime:6e5,refetchOnWindowFocus:!1,placeholderData:a=>a});return{...n,teams:n.data?.records??[],isRefreshing:n.isFetching&&n.data!==void 0,pagination:n.data?{page:n.data.page,perPage:n.data.per_page,totalPages:n.data.total_pages,totalRecords:n.data.total_records}:void 0}},De=({teamId:e,enabled:i=!0})=>{const t=w({queryKey:S.detail(e??""),queryFn:()=>ee(m.radientBaseUrl,e),select:n=>n.result,enabled:i&&!!e,retry:N,staleTime:3e5,gcTime:6e5,refetchOnWindowFocus:!1,retryOnMount:!1});return{...t,team:t.data}};function x(e){if(e.getQueryState(A.capabilities)?.status!=="success"||!F(e.getQueryData(A.capabilities),"hub_skills"))throw new Error("This backend does not support the complete Hub Skills adapter.")}function Ae(e,i,t){const n=y(),a=M();return w({queryKey:["hub-skills",m.radientBaseUrl,e.visibility,e.tenantId,i],enabled:t&&!a.isError&&F(a.data,"hub_skills"),queryFn:async()=>{if(x(n),e.visibility==="org"){const b=(await ke(e.tenantId)).result;return{rows:b.skills,pages:1,total:b.skills.length,contract:b.sync_contract}}const d=(await he(m.radientBaseUrl,i,20)).result;return{rows:d.records,pages:d.total_pages,total:d.total_records,contract:d.sync_contract}},staleTime:3e4,retry:e.visibility==="org"?B:N,retryOnMount:!1,refetchOnWindowFocus:!1})}function He(e,i,t){const n=y(),a=M();return w({queryKey:["hub-skill",m.radientBaseUrl,e.visibility,e.tenantId,i],enabled:t&&i!==null&&!a.isError&&F(a.data,"hub_skills"),queryFn:async()=>(x(n),(e.visibility==="org"?await ge(e.tenantId,i):await me(m.radientBaseUrl,i)).result),staleTime:3e4,retry:e.visibility==="org"?B:N,retryOnMount:!1})}function T(e,i){e.setQueryData(E,i.links)}function D(e){e.invalidateQueries({queryKey:E}),e.invalidateQueries({queryKey:["desktop","skills"]})}function Ce(e={}){const i=y();return P({...e.retry===void 0?{}:{retry:e.retry},mutationFn:t=>(x(i),I({op:"hub.skillPull",requestId:t.requestId,hubId:t.remoteId,hubSource:W(m.radientBaseUrl),visibility:t.scope.visibility,tenantId:t.scope.tenantId,localAlias:t.alias,subscribe:t.subscribe,autoPush:t.autoPush,confirmPublicEgress:t.consent})),onSuccess:t=>{T(i,t)},onSettled:()=>{D(i)}})}function Ke(){const e=y();return P({mutationFn:i=>(x(e),I({op:"hub.skillSubscribe",requestId:i.requestId,hubId:i.remoteId,hubSource:W(m.radientBaseUrl),visibility:i.scope.visibility,tenantId:i.scope.tenantId,localAlias:i.alias})),onSuccess:i=>{T(e,i)},onSettled:()=>{D(e)}})}function Oe(){const e=y();return P({mutationFn:i=>(x(e),I({op:"hub.skillUnpull",requestId:i.requestId,linkId:i.linkId})),onSuccess:i=>{T(e,i)},onSettled:()=>{D(e)}})}function Ue(){const e=y();return P({mutationFn:i=>(x(e),I({op:"hub.skillPublish",requestId:i.requestId,...i.draft,dryRun:i.previewReceipt===void 0,...i.previewReceipt?{previewReceipt:i.previewReceipt,confirmPublish:!0}:{}})),onSuccess:i=>{i.local_link_receipt?.state==="complete"&&(e.invalidateQueries({queryKey:E}),e.invalidateQueries({queryKey:["desktop","skills"]}),e.invalidateQueries({queryKey:["hub-skills"]}))}})}const ye=/\/+$/;function H(e){return e.replace(ye,"")}function Me(e,i){return i.visibility==="public"?e.visibility==="public"&&!e.tenant_id:e.visibility==="org"&&e.tenant_id===i.tenantId}function xe(e){const i=e.id??e.hub_id??"",t=e.tenantId??e.tenant_id??"";return`${i}\0${e.visibility}\0${t}`}function Be(e,i){const t=H(i),n=new Map;for(const a of e??[])a.kind==="skill"&&H(a.hub_source)===t&&n.set(xe({hub_id:a.hub_id,visibility:a.visibility,tenantId:a.tenant_id}),a);return n}function Qe(e,i,t=!0){if(!t)return{kind:"unknown"};if(!e)return{kind:"not-present"};const n=ie(e);return n==="present"&&(e.pull.state==="available"||i?.state==="available"&&!i.error_class)?{kind:"update",link:e,automatic:i?.auto_will_apply===!0||e.auto_will_apply}:n==="absent"?e.policy.subscribe?{kind:"subscribed",link:e}:{kind:"detached",link:e}:e.policy.subscribe?{kind:"pulled",link:e}:{kind:"manual",link:e}}function We(e){return e?"policy":"create"}function Le(e){return JSON.stringify({op:"pull",selected:e.selected,scope:e.scope,localAlias:e.localAlias,subscribe:e.subscribe,autoPush:e.autoPush,consent:e.consent})}const ve={available:"text-accent",applied:"text-success",failed:"text-danger",review:"text-warning",updating:"text-ink-muted"},_e={available:"ui.hub.skills.update_available",applied:"ui.hub.skills.update_applied",failed:"ui.hub.skills.update_failed",review:"ui.hub.links.mark_review",updating:"ui.hub.links.mark_busy"},Se={"not-present":"ui.hub.skills.not_downloaded",subscribed:"ui.hub.skills.subscribed_absent",pulled:"ui.hub.skills.pulled",manual:"ui.hub.skills.manual",detached:"ui.hub.skills.detached"};function $e(e,i,t){const n=i?C(i):null;return n&&(e.kind==="update"||t&&(i?.state==="applied"||i?.state==="failed"||i?.error_class))?n:e.kind==="update"?{kind:"available",auto:e.automatic}:null}function ze(e,i){return e.kind==="unknown"?i:e.kind!=="update"?l(Se[e.kind]):l(e.link.policy.subscribe?"ui.hub.skills.pulled":"ui.hub.skills.manual")}function Ge({mark:e,className:i,labels:t}){return j(),e?s.jsxs("span",{"data-hub-mark-state":e.kind,className:R("flex shrink-0 items-center gap-1 text-meta",ve[e.kind],i),children:[s.jsx(K,{mark:e}),s.jsx("span",{children:l(t?.[e.kind]??_e[e.kind])})]}):null}const Je=()=>({subscribe:!0,autoPush:!1,confirmPublicEgress:!1});function Ye({value:e,onChange:i,source:t,item:n,visibility:a,organization:d,destinationKey:b,canEnableAutoPush:h,disabled:k=!1}){j();const o=v.useId(),c=v.useRef(null),[r,p]=v.useState(null);return v.useEffect(()=>{r!==null&&r!==b&&p(null)},[r,b]),s.jsxs("div",{className:"flex flex-col gap-3","data-initial-hub-policy":!0,children:[s.jsx("p",{className:"text-meta text-ink-muted",children:l("ui.hub.skills.initial_policy_description")}),["subscribe","autoPush"].map(u=>s.jsxs("label",{htmlFor:`${o}-${u}`,className:"flex items-start gap-3 text-body-sm text-ink",children:[s.jsx(te,{id:`${o}-${u}`,checked:e[u],disabled:k||u==="autoPush"&&!h&&!e.autoPush,onCheckedChange:f=>{u==="subscribe"?i({...e,subscribe:f===!0}):f!==!0?i({...e,autoPush:!1,confirmPublicEgress:!1}):h&&p(b)}}),s.jsxs("span",{children:[s.jsx("span",{className:"block",children:l(u==="subscribe"?"ui.hub.subscriptions.subscribe":"ui.hub.subscriptions.auto_push")}),s.jsx("span",{className:"block text-meta text-ink-muted",children:l(u==="subscribe"?"ui.hub.subscriptions.subscribe_description":"ui.hub.subscriptions.auto_push_description",{source:t})})]})]},u)),!h&&s.jsx("p",{className:"text-meta text-ink-muted",children:l("ui.hub.subscriptions.unsupported")}),s.jsx(se,{open:r!==null,onOpenChange:u=>{u||p(null)},children:s.jsxs(ae,{onOpenAutoFocus:u=>{u.preventDefault(),c.current?.focus()},children:[s.jsxs(ne,{children:[s.jsx(le,{children:l("ui.hub.subscriptions.enable_title",{source:t})}),s.jsx(re,{children:a==="public"?l("ui.hub.subscriptions.enable_public",{item:n}):l("ui.hub.subscriptions.enable_private",{item:n,organization:d??t})})]}),s.jsx("p",{className:"text-body-sm text-ink-muted",children:l("ui.hub.subscriptions.enable_safety")}),s.jsxs(ue,{children:[s.jsx(g,{ref:c,"data-testid":"hub-policy-cancel",variant:"outline",onClick:()=>p(null),children:l("ui.hub.subscriptions.cancel")}),s.jsx(g,{"data-testid":"hub-policy-enable",disabled:k||!h||r!==b,onClick:()=>{i({...e,autoPush:!0,confirmPublicEgress:a==="public"}),p(null)},children:l("ui.hub.subscriptions.enable")})]})]})})]})}function Ve(e,i,t=Date.now()){return e.can_confirm===!0&&e.kind==="skill"&&e.direction==="push"&&e.publication==="create"&&e.proposal?.kind==="skill"&&e.proposal.fields?.document_version===1&&e.preview_receipt.length>0&&e.local_fingerprint.length>0&&e.draft_fingerprint.length>0&&e.proposal_fingerprint.length>0&&e.source_skill===i.sourceSkill&&e.local_alias===i.localAlias&&e.visibility===i.visibility&&e.tenant_id===i.tenantId&&e.policy?.subscribe===i.subscribe&&e.policy?.auto_push===i.autoPush&&e.policy?.confirm_public_egress===i.confirmPublicEgress&&Number.isFinite(Date.parse(e.expires_at))&&Date.parse(e.expires_at)>t}function Xe(e){return e.local_link_receipt?.state==="complete"&&!!e.link&&e.local_link_receipt.link_id===e.link.link_id&&typeof e.link.policy?.subscribe=="boolean"&&typeof e.link.policy.auto_push=="boolean"&&typeof e.link.policy.revision=="string"&&e.link.policy.revision.length>0}const je=e=>e==="active"||e==="past_due",L=e=>e.status!=="active"?"no_access":je(e.plan.status)?"available":"plan_inactive",Ze=e=>e.filter(i=>L(i)==="available"),ei=e=>e.filter(i=>L(i)==="plan_inactive"),ii=e=>{if(!(e instanceof oe))return null;switch(e.code){case"team_plan_required":return"plan";case"not_a_member":case"insufficient_role":return"no_access";default:return null}};export{Ye as H,fe as P,Ge as S,Ae as a,He as b,Ce as c,Ke as d,Oe as e,Be as f,W as g,Fe as h,Ve as i,xe as j,Qe as k,$e as l,ze as m,Je as n,Ee as o,Xe as p,Le as q,We as r,Me as s,ii as t,Ue as u,Te as v,De as w,Ze as x,ei as y};
1
+ import{r as v,j as s,c as R}from"./index-C4ae8MIc.js";import{x as z,y as G,z as J,D as Y,E as C,H as K,G as V,I as O,J as U,K as X,L as Z,M as ee,O as E,Q as ie}from"./index-pRJvOEvT.js";import{u as j,B as g,i as te,o as se,p as ae,y as ne,q as le,z as re,F as ue}from"./error-boundary-BcPKKbP5.js";import{t as l}from"./messages-DoRCUI0R.js";import{i as w,u as y,a as M,c as F,r as B,d as I,F as A,G as oe}from"./path-utils-BqTfmiT0.js";import{bg as Q,a7 as m,ba as P}from"./conversation-input-sync-BwcOsVjK.js";const _=e=>e==null?"":typeof e=="string"?e:JSON.stringify(e,null,2),ce={available:"border-hairline",updating:"border-hairline",applied:"border-hairline",review:"border-warning-border",failed:"border-danger-border"};function de(e){const i=[];for(const t of e??[])for(const n of t.fields??[])for(const a of n.regions??[])(a.provenance==="unresolved"||_(a.local)!==_(a.remote))&&i.push({field:n.field,region:a});return i}function be({regions:e}){return j(),e.length?s.jsx("ul",{className:"space-y-3","data-testid":"hub-update-preview",children:e.map(({field:i,region:t},n)=>s.jsxs("li",{className:"space-y-1 text-meta",children:[s.jsx("p",{className:"font-medium text-ink",children:t.heading||t.name||i}),s.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-ink-muted",children:l("ui.agents.navigation.updates.preview.local")}),s.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap rounded-sm border border-hairline p-2 text-ink",children:_(t.local)||l("ui.agents.navigation.updates.preview.nothing")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"text-ink-muted",children:l("ui.agents.navigation.updates.preview.remote")}),s.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap rounded-sm border border-hairline p-2 text-ink",children:_(t.remote)||l("ui.agents.navigation.updates.preview.nothing")})]})]})]},`${i}:${t.id??n}`))}):s.jsx("p",{className:"text-meta text-ink-muted",children:l("ui.agents.navigation.updates.preview.empty")})}function Ee({kind:e,name:i,enabled:t}){j();const n=z(t),a=G(),[d,b]=v.useState(null),h=Y(e,i),k=J(n.data).get(h),o=C(k),c=a.notes[h],r=a.pending.has(h);if(!k||!o)return c?s.jsx("section",{"data-testid":"hub-update-panel","aria-label":l("ui.agents.navigation.updates.accessible"),className:"mb-8 rounded-md border border-hairline p-3 text-body-sm",children:s.jsx("p",{role:c.tone==="error"?"alert":"status",className:c.tone==="error"?"text-danger":"text-ink",children:c.message})}):null;const p=o.kind==="review",u=k.classification==="baseline-unknown",f=q=>({prefer:q,acknowledgeUnknownBaseline:u}),$=async()=>{const q=await a.applyItem(e,i,{...f(),dryRun:!0});b(q??[])};return s.jsxs("section",{"data-testid":"hub-update-panel","aria-label":l("ui.agents.navigation.updates.accessible"),className:R("mb-8 space-y-2 rounded-md border p-3 text-body-sm",ce[o.kind]),children:[s.jsxs("p",{className:"flex items-start gap-2 text-ink",children:[s.jsx(K,{mark:o,className:"mt-0.5"}),s.jsx("span",{className:R(o.kind==="failed"&&"text-danger"),children:V(k,o)})]}),a.upgradeMessage&&s.jsx("output",{className:"block text-meta text-warning","data-hub-core-upgrade":!0,children:a.upgradeMessage}),p&&u&&s.jsx("p",{className:"text-meta text-ink-muted",children:l("ui.agents.navigation.updates.baseline_unknown")}),p&&!u&&s.jsx("p",{className:"text-meta text-ink-muted",children:l("ui.agents.navigation.updates.merge_guidance")}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.kind==="available"&&s.jsx(g,{size:"sm",variant:"outline","aria-disabled":r||!a.canWrite||void 0,onClick:()=>!r&&a.canWrite&&void a.applyItem(e,i),children:r?l("ui.agents.navigation.updates.action.updating"):l("ui.agents.navigation.updates.action.update")}),o.kind==="failed"&&o.retryable&&s.jsx(g,{size:"sm",variant:"outline","aria-disabled":r||!a.canWrite||void 0,onClick:()=>!r&&a.canWrite&&void a.retryItem(e,i),children:r?l("ui.agents.navigation.updates.action.retrying"):l("ui.agents.navigation.updates.action.retry")}),p&&s.jsxs(s.Fragment,{children:[s.jsx(g,{size:"sm",variant:"outline","aria-disabled":r||!a.canWrite||void 0,onClick:()=>!r&&a.canWrite&&void $(),children:r&&!d?l("ui.agents.navigation.updates.action.loading"):l("ui.agents.navigation.updates.action.preview")}),s.jsx(g,{size:"sm",variant:"ghost","aria-disabled":r||!a.canWrite||void 0,onClick:()=>!r&&a.canWrite&&void a.applyItem(e,i,f("local")),children:l("ui.agents.navigation.updates.action.keep_local")}),s.jsx(g,{size:"sm",variant:"ghost","aria-disabled":r||!a.canWrite||void 0,onClick:()=>!r&&a.canWrite&&void a.applyItem(e,i,f("remote")),children:l("ui.agents.navigation.updates.action.use_remote")})]})]}),d&&p&&s.jsx(be,{regions:de(d)}),c&&s.jsx("p",{role:c.tone==="error"?"alert":"status",className:c.tone==="error"?"text-meta text-danger":"text-meta text-ink-muted",children:c.message})]})}const pe=/\/+$/;function W(e){const i=e.replace(pe,"");try{const{pathname:t}=new URL(i);return t===""||t==="/"?`${i}/v1`:i}catch{return`${i}/v1`}}const Fe=e=>e?.skills===1&&e.revision_cas===1;function he(e,i=1,t=20){const n=new URL(O(e,"skills"));return n.searchParams.set("page",String(i)),n.searchParams.set("per_page",String(t)),U(n.toString())}function me(e,i){return U(O(e,"skills",i))}function ke(e){return Q({operation:"org_skills.list",tenantId:e})}function ge(e,i){return Q({operation:"org_skill.get",tenantId:e,skillId:i})}const fe=12,S={all:["public-teams"],list:(e,i)=>[...S.all,"list",{page:e,perPage:i}],detail:e=>[...S.all,"detail",e]},N=(e,i)=>i instanceof X?i.status===null?!1:i.status>=500&&e<1:e<1,Te=({page:e=1,perPage:i=fe,enabled:t=!0}={})=>{const n=w({queryKey:S.list(e,i),queryFn:()=>Z(m.radientBaseUrl,e,i),select:a=>a.result,enabled:t,retry:N,staleTime:3e5,gcTime:6e5,refetchOnWindowFocus:!1,placeholderData:a=>a});return{...n,teams:n.data?.records??[],isRefreshing:n.isFetching&&n.data!==void 0,pagination:n.data?{page:n.data.page,perPage:n.data.per_page,totalPages:n.data.total_pages,totalRecords:n.data.total_records}:void 0}},De=({teamId:e,enabled:i=!0})=>{const t=w({queryKey:S.detail(e??""),queryFn:()=>ee(m.radientBaseUrl,e),select:n=>n.result,enabled:i&&!!e,retry:N,staleTime:3e5,gcTime:6e5,refetchOnWindowFocus:!1,retryOnMount:!1});return{...t,team:t.data}};function x(e){if(e.getQueryState(A.capabilities)?.status!=="success"||!F(e.getQueryData(A.capabilities),"hub_skills"))throw new Error("This backend does not support the complete Hub Skills adapter.")}function Ae(e,i,t){const n=y(),a=M();return w({queryKey:["hub-skills",m.radientBaseUrl,e.visibility,e.tenantId,i],enabled:t&&!a.isError&&F(a.data,"hub_skills"),queryFn:async()=>{if(x(n),e.visibility==="org"){const b=(await ke(e.tenantId)).result;return{rows:b.skills,pages:1,total:b.skills.length,contract:b.sync_contract}}const d=(await he(m.radientBaseUrl,i,20)).result;return{rows:d.records,pages:d.total_pages,total:d.total_records,contract:d.sync_contract}},staleTime:3e4,retry:e.visibility==="org"?B:N,retryOnMount:!1,refetchOnWindowFocus:!1})}function He(e,i,t){const n=y(),a=M();return w({queryKey:["hub-skill",m.radientBaseUrl,e.visibility,e.tenantId,i],enabled:t&&i!==null&&!a.isError&&F(a.data,"hub_skills"),queryFn:async()=>(x(n),(e.visibility==="org"?await ge(e.tenantId,i):await me(m.radientBaseUrl,i)).result),staleTime:3e4,retry:e.visibility==="org"?B:N,retryOnMount:!1})}function T(e,i){e.setQueryData(E,i.links)}function D(e){e.invalidateQueries({queryKey:E}),e.invalidateQueries({queryKey:["desktop","skills"]})}function Ce(e={}){const i=y();return P({...e.retry===void 0?{}:{retry:e.retry},mutationFn:t=>(x(i),I({op:"hub.skillPull",requestId:t.requestId,hubId:t.remoteId,hubSource:W(m.radientBaseUrl),visibility:t.scope.visibility,tenantId:t.scope.tenantId,localAlias:t.alias,subscribe:t.subscribe,autoPush:t.autoPush,confirmPublicEgress:t.consent})),onSuccess:t=>{T(i,t)},onSettled:()=>{D(i)}})}function Ke(){const e=y();return P({mutationFn:i=>(x(e),I({op:"hub.skillSubscribe",requestId:i.requestId,hubId:i.remoteId,hubSource:W(m.radientBaseUrl),visibility:i.scope.visibility,tenantId:i.scope.tenantId,localAlias:i.alias})),onSuccess:i=>{T(e,i)},onSettled:()=>{D(e)}})}function Oe(){const e=y();return P({mutationFn:i=>(x(e),I({op:"hub.skillUnpull",requestId:i.requestId,linkId:i.linkId})),onSuccess:i=>{T(e,i)},onSettled:()=>{D(e)}})}function Ue(){const e=y();return P({mutationFn:i=>(x(e),I({op:"hub.skillPublish",requestId:i.requestId,...i.draft,dryRun:i.previewReceipt===void 0,...i.previewReceipt?{previewReceipt:i.previewReceipt,confirmPublish:!0}:{}})),onSuccess:i=>{i.local_link_receipt?.state==="complete"&&(e.invalidateQueries({queryKey:E}),e.invalidateQueries({queryKey:["desktop","skills"]}),e.invalidateQueries({queryKey:["hub-skills"]}))}})}const ye=/\/+$/;function H(e){return e.replace(ye,"")}function Me(e,i){return i.visibility==="public"?e.visibility==="public"&&!e.tenant_id:e.visibility==="org"&&e.tenant_id===i.tenantId}function xe(e){const i=e.id??e.hub_id??"",t=e.tenantId??e.tenant_id??"";return`${i}\0${e.visibility}\0${t}`}function Be(e,i){const t=H(i),n=new Map;for(const a of e??[])a.kind==="skill"&&H(a.hub_source)===t&&n.set(xe({hub_id:a.hub_id,visibility:a.visibility,tenantId:a.tenant_id}),a);return n}function Qe(e,i,t=!0){if(!t)return{kind:"unknown"};if(!e)return{kind:"not-present"};const n=ie(e);return n==="present"&&(e.pull.state==="available"||i?.state==="available"&&!i.error_class)?{kind:"update",link:e,automatic:i?.auto_will_apply===!0||e.auto_will_apply}:n==="absent"?e.policy.subscribe?{kind:"subscribed",link:e}:{kind:"detached",link:e}:e.policy.subscribe?{kind:"pulled",link:e}:{kind:"manual",link:e}}function We(e){return e?"policy":"create"}function Le(e){return JSON.stringify({op:"pull",selected:e.selected,scope:e.scope,localAlias:e.localAlias,subscribe:e.subscribe,autoPush:e.autoPush,consent:e.consent})}const ve={available:"text-accent",applied:"text-success",failed:"text-danger",review:"text-warning",updating:"text-ink-muted"},_e={available:"ui.hub.skills.update_available",applied:"ui.hub.skills.update_applied",failed:"ui.hub.skills.update_failed",review:"ui.hub.links.mark_review",updating:"ui.hub.links.mark_busy"},Se={"not-present":"ui.hub.skills.not_downloaded",subscribed:"ui.hub.skills.subscribed_absent",pulled:"ui.hub.skills.pulled",manual:"ui.hub.skills.manual",detached:"ui.hub.skills.detached"};function $e(e,i,t){const n=i?C(i):null;return n&&(e.kind==="update"||t&&(i?.state==="applied"||i?.state==="failed"||i?.error_class))?n:e.kind==="update"?{kind:"available",auto:e.automatic}:null}function ze(e,i){return e.kind==="unknown"?i:e.kind!=="update"?l(Se[e.kind]):l(e.link.policy.subscribe?"ui.hub.skills.pulled":"ui.hub.skills.manual")}function Ge({mark:e,className:i,labels:t}){return j(),e?s.jsxs("span",{"data-hub-mark-state":e.kind,className:R("flex shrink-0 items-center gap-1 text-meta",ve[e.kind],i),children:[s.jsx(K,{mark:e}),s.jsx("span",{children:l(t?.[e.kind]??_e[e.kind])})]}):null}const Je=()=>({subscribe:!0,autoPush:!1,confirmPublicEgress:!1});function Ye({value:e,onChange:i,source:t,item:n,visibility:a,organization:d,destinationKey:b,canEnableAutoPush:h,disabled:k=!1}){j();const o=v.useId(),c=v.useRef(null),[r,p]=v.useState(null);return v.useEffect(()=>{r!==null&&r!==b&&p(null)},[r,b]),s.jsxs("div",{className:"flex flex-col gap-3","data-initial-hub-policy":!0,children:[s.jsx("p",{className:"text-meta text-ink-muted",children:l("ui.hub.skills.initial_policy_description")}),["subscribe","autoPush"].map(u=>s.jsxs("label",{htmlFor:`${o}-${u}`,className:"flex items-start gap-3 text-body-sm text-ink",children:[s.jsx(te,{id:`${o}-${u}`,checked:e[u],disabled:k||u==="autoPush"&&!h&&!e.autoPush,onCheckedChange:f=>{u==="subscribe"?i({...e,subscribe:f===!0}):f!==!0?i({...e,autoPush:!1,confirmPublicEgress:!1}):h&&p(b)}}),s.jsxs("span",{children:[s.jsx("span",{className:"block",children:l(u==="subscribe"?"ui.hub.subscriptions.subscribe":"ui.hub.subscriptions.auto_push")}),s.jsx("span",{className:"block text-meta text-ink-muted",children:l(u==="subscribe"?"ui.hub.subscriptions.subscribe_description":"ui.hub.subscriptions.auto_push_description",{source:t})})]})]},u)),!h&&s.jsx("p",{className:"text-meta text-ink-muted",children:l("ui.hub.subscriptions.unsupported")}),s.jsx(se,{open:r!==null,onOpenChange:u=>{u||p(null)},children:s.jsxs(ae,{onOpenAutoFocus:u=>{u.preventDefault(),c.current?.focus()},children:[s.jsxs(ne,{children:[s.jsx(le,{children:l("ui.hub.subscriptions.enable_title",{source:t})}),s.jsx(re,{children:a==="public"?l("ui.hub.subscriptions.enable_public",{item:n}):l("ui.hub.subscriptions.enable_private",{item:n,organization:d??t})})]}),s.jsx("p",{className:"text-body-sm text-ink-muted",children:l("ui.hub.subscriptions.enable_safety")}),s.jsxs(ue,{children:[s.jsx(g,{ref:c,"data-testid":"hub-policy-cancel",variant:"outline",onClick:()=>p(null),children:l("ui.hub.subscriptions.cancel")}),s.jsx(g,{"data-testid":"hub-policy-enable",disabled:k||!h||r!==b,onClick:()=>{i({...e,autoPush:!0,confirmPublicEgress:a==="public"}),p(null)},children:l("ui.hub.subscriptions.enable")})]})]})})]})}function Ve(e,i,t=Date.now()){return e.can_confirm===!0&&e.kind==="skill"&&e.direction==="push"&&e.publication==="create"&&e.proposal?.kind==="skill"&&e.proposal.fields?.document_version===1&&e.preview_receipt.length>0&&e.local_fingerprint.length>0&&e.draft_fingerprint.length>0&&e.proposal_fingerprint.length>0&&e.source_skill===i.sourceSkill&&e.local_alias===i.localAlias&&e.visibility===i.visibility&&e.tenant_id===i.tenantId&&e.policy?.subscribe===i.subscribe&&e.policy?.auto_push===i.autoPush&&e.policy?.confirm_public_egress===i.confirmPublicEgress&&Number.isFinite(Date.parse(e.expires_at))&&Date.parse(e.expires_at)>t}function Xe(e){return e.local_link_receipt?.state==="complete"&&!!e.link&&e.local_link_receipt.link_id===e.link.link_id&&typeof e.link.policy?.subscribe=="boolean"&&typeof e.link.policy.auto_push=="boolean"&&typeof e.link.policy.revision=="string"&&e.link.policy.revision.length>0}const je=e=>e==="active"||e==="past_due",L=e=>e.status!=="active"?"no_access":je(e.plan.status)?"available":"plan_inactive",Ze=e=>e.filter(i=>L(i)==="available"),ei=e=>e.filter(i=>L(i)==="plan_inactive"),ii=e=>{if(!(e instanceof oe))return null;switch(e.code){case"team_plan_required":return"plan";case"not_a_member":case"insufficient_role":return"no_access";default:return null}};export{Ye as H,fe as P,Ge as S,Ae as a,He as b,Ce as c,Ke as d,Oe as e,Be as f,W as g,Fe as h,Ve as i,xe as j,Qe as k,$e as l,ze as m,Je as n,Ee as o,Xe as p,Le as q,We as r,Me as s,ii as t,Ue as u,Te as v,De as w,Ze as x,ei as y};