@camstack/addon-admin-ui 1.2.168 → 1.2.170
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonCollectionPage-Bq1BZDbI.js → AddonCollectionPage-Dzu7if7X.js} +1 -1
- package/dist/assets/Addons-cmY_BeHx.js +1 -0
- package/dist/assets/{AdminTabs-CP8s-xwD.js → AdminTabs-KbDahb5g.js} +1 -1
- package/dist/assets/{AiProfiles-CLg0JvOt.js → AiProfiles-G3iTDdFi.js} +1 -1
- package/dist/assets/{BrokerForm-OAq0B61g.js → BrokerForm-Cnlcd0iS.js} +1 -1
- package/dist/assets/{Build-D9zSW4UB.js → Build-CLJkQ8d1.js} +1 -1
- package/dist/assets/{Capabilities-DzD-O01_.js → Capabilities-ChYuK5bi.js} +1 -1
- package/dist/assets/{CapabilityBadges-OFEks7tj.js → CapabilityBadges-CX6rtH_Z.js} +1 -1
- package/dist/assets/Cluster-LQa_PfIs.js +11 -0
- package/dist/assets/Data-qmgCHWst.js +1 -0
- package/dist/assets/{DetectionIntelligence-BnmyQSh3.js → DetectionIntelligence-DHjzD_xY.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-CcU8lz-n.js → DeviceAggregateSection-BYV9beqX.js} +1 -1
- package/dist/assets/DeviceDetail-1sBb391Z.js +2 -0
- package/dist/assets/{Devices-BatZyq9B.js → Devices-BklvFBhA.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-B9BQnkt_.js → EmbedPlayerPage-D5rXh9NK.js} +1 -1
- package/dist/assets/{Events-Cg2w7Z73.js → Events-C8XTJKuj.js} +1 -1
- package/dist/assets/{FormBuilder-Cok9Ggwo.js → FormBuilder-BqDI8IF8.js} +1 -1
- package/dist/assets/{Identity-eUScgjjW.js → Identity-BMyE1TSF.js} +1 -1
- package/dist/assets/{IntegrationDetail-CXkStOjj.js → IntegrationDetail-CVecwBfB.js} +1 -1
- package/dist/assets/{Integrations-C4C2GotZ.js → Integrations-DgiUN8WI.js} +1 -1
- package/dist/assets/{Integrations-CRhWDVyt.js → Integrations-DoyN_2ix.js} +1 -1
- package/dist/assets/{Locations-j0-nR3Fy.js → Locations-Dqtm7049.js} +1 -1
- package/dist/assets/{Logs-1b2wtMIP.js → Logs-D3T5VqXU.js} +1 -1
- package/dist/assets/{MotionZonesSettings-Dj8sh_Mh.js → MotionZonesSettings-CeiqMsOP.js} +1 -1
- package/dist/assets/{MyAccess-D0cAUoLS.js → MyAccess-DnaLAFgi.js} +1 -1
- package/dist/assets/{Network-DxLntEOc.js → Network-CC3nkKu6.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-D120MZAG.js → NodeAddonsSettingsPanel-C-NPPWAc.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-DXPbWU2j.js → NodeInferenceDevices-oEPHvzHv.js} +1 -1
- package/dist/assets/{Notifications-CvO8QFj0.js → Notifications-D_qXhtY3.js} +1 -1
- package/dist/assets/Pipeline-D2u6gpex.js +1 -0
- package/dist/assets/{Plates-DrBihP9I.js → Plates-Dfe3UFiw.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DBwYQNQl.js → PrivacyMaskSettings-B5j9CVpD.js} +1 -1
- package/dist/assets/{ProviderIcon-DsvO_i4v.js → ProviderIcon-BhtIEbgI.js} +1 -1
- package/dist/assets/Recordings-DO23vw2_.js +1 -0
- package/dist/assets/{ScanNetworkModal-BpRTGxHZ.js → ScanNetworkModal-CA-OArEA.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-C_V9C8OP.js → SceneMonitorEditor-BB4kENsO.js} +1 -1
- package/dist/assets/{Scenes-p9MPTcdv.js → Scenes-DAfrrTj_.js} +1 -1
- package/dist/assets/{Settings-DfqqpKzH.js → Settings-BvMSL-Rl.js} +1 -1
- package/dist/assets/{Showroom-qnQMoYty.js → Showroom-CAwb6Ck8.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-DUAjHG9E.js → StorageLocationsPanel-DL0p6Cgw.js} +1 -1
- package/dist/assets/{Terminal-DqUxL7ym.js → Terminal-DNX5eu6E.js} +3 -3
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DKYqOaz2.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-fHqNX4tQ.js} +1 -1
- package/dist/assets/{authed-media-Cvs7l9rz.js → authed-media-DOXm0tcZ.js} +1 -1
- package/dist/assets/{bell-off-CDNdnZ19.js → bell-off-Ts2x4_io.js} +1 -1
- package/dist/assets/{bell-ring-DUqe0kvT.js → bell-ring-ColLr5Sv.js} +1 -1
- package/dist/assets/{boxes-Dk28bZrK.js → boxes-DLBOZdEv.js} +1 -1
- package/dist/assets/circle-check-big-Cm7khd5f.js +1 -0
- package/dist/assets/circle-dot-B4DfqCOD.js +1 -0
- package/dist/assets/circle-slash-IyU_gVDG.js +1 -0
- package/dist/assets/{circle-x-CR4ad_rL.js → circle-x-D4XhwphR.js} +1 -1
- package/dist/assets/clock-Czi0ZaPo.js +1 -0
- package/dist/assets/{copy-DR8R2_HR.js → copy-Cr3rjCTp.js} +1 -1
- package/dist/assets/{debounced-invalidate-BW0isPZ1.js → debounced-invalidate-Bh2p192d.js} +1 -1
- package/dist/assets/{dist-Cw2ieLbS.js → dist-B3d-1omx.js} +1 -1
- package/dist/assets/{dist-NfRpOqkA.js → dist-DrjaRpaz.js} +3 -3
- package/dist/assets/{download-CPGYFNbo.js → download-DlHJFiX_.js} +1 -1
- package/dist/assets/{face-bbox-292APeBO.js → face-bbox-BkUtqpif.js} +1 -1
- package/dist/assets/{flame-Cs9ylxDs.js → flame-0-uiutPM.js} +1 -1
- package/dist/assets/{format-size-CAEr-F_e.js → format-size-DoXWOpar.js} +1 -1
- package/dist/assets/{hard-drive-E7g9cBQS.js → hard-drive-C4Gwi3hi.js} +1 -1
- package/dist/assets/{hostInit-CZPsA9-3.js → hostInit-CKZ6nc-d.js} +1 -1
- package/dist/assets/{index-CG76NtTM.js → index-g356Z7K8.js} +3 -3
- package/dist/assets/{key-round-CCvvsAXv.js → key-round-Bf8UD3ir.js} +1 -1
- package/dist/assets/{layers-Yn7zbw1b.js → layers-BxwjXR1w.js} +1 -1
- package/dist/assets/{location-owned-usage-v9yH0_Uz.js → location-owned-usage-RXMicHPP.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-03979c96.js → mf-entry-bootstrap-0-62b76ab1.js} +2 -2
- package/dist/assets/{pencil-BHUkVqws.js → pencil-GpDj1Q2p.js} +1 -1
- package/dist/assets/play-JJtA4mLK.js +1 -0
- package/dist/assets/{player-overlays-BpDQQutT.js → player-overlays-BOHd-BQW.js} +1 -1
- package/dist/assets/plus-Ce-u1cy0.js +1 -0
- package/dist/assets/power-DHeS0c53.js +1 -0
- package/dist/assets/{radio-tEvnz1YW.js → radio-CkABc76L.js} +1 -1
- package/dist/assets/{refresh-cw-BGLHgQjL.js → refresh-cw-CGsZO3dv.js} +1 -1
- package/dist/assets/remoteEntry-DIWyDOfS.js +1 -0
- package/dist/assets/rotate-ccw-CNXGqau-.js +1 -0
- package/dist/assets/rotate-cw-CLl0fQTC.js +1 -0
- package/dist/assets/{send-CtFLaK0p.js → send-VTRrGOSw.js} +1 -1
- package/dist/assets/{server-CnMC4dNi.js → server-B7kfcasJ.js} +1 -1
- package/dist/assets/{shield-DQwxYnJd.js → shield-CQ4OLCaq.js} +1 -1
- package/dist/assets/{shield-alert-Dx2eIRFq.js → shield-alert-B5lZ5qPg.js} +1 -1
- package/dist/assets/square-D5_FHQhn.js +1 -0
- package/dist/assets/{square-check-big-BzavY7zY.js → square-check-big-CYG6mqRn.js} +1 -1
- package/dist/assets/{src-C7ah6wxj.js → src-BmPEyOJ9.js} +17 -17
- package/dist/assets/src-DGE3vmjp.js +349 -0
- package/dist/assets/{undo-2-By8IwmwV.js → undo-2-B4kJBBZH.js} +1 -1
- package/dist/assets/{use-scenes-feed-wCDqoLJr.js → use-scenes-feed-BRjVzclh.js} +1 -1
- package/dist/assets/useEventInvalidation-BO1Mqzp4.js +1 -0
- package/dist/assets/{useNodeUrlSelection-DQcugosE.js → useNodeUrlSelection-DGIGjgUa.js} +1 -1
- package/dist/assets/user-round-CJoGmSnV.js +1 -0
- package/dist/assets/{video-BTNCj0ya.js → video-vgosx6J5.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D3L7eEpM.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DMsOet1U.js} +2 -2
- package/dist/assets/{wifi-KoON0qN2.js → wifi-DtqTmADb.js} +1 -1
- package/dist/assets/{zap-CsEPgdEy.js → zap-BsoxkPxV.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +61 -2
- package/package.json +1 -1
- package/dist/assets/Addons-BGGsoGOA.js +0 -1
- package/dist/assets/Cluster-5P5fvxqc.js +0 -11
- package/dist/assets/Data-7dVT38Kt.js +0 -1
- package/dist/assets/DeviceDetail-BYx3AwSC.js +0 -2
- package/dist/assets/Pipeline-TCZqOIpn.js +0 -1
- package/dist/assets/Recordings-D4dIK-GM.js +0 -1
- package/dist/assets/circle-check-big-BoAN0Pqi.js +0 -1
- package/dist/assets/circle-dot-7Ot7Hk1p.js +0 -1
- package/dist/assets/circle-slash-C-e40toi.js +0 -1
- package/dist/assets/clock-DwkKgcTZ.js +0 -1
- package/dist/assets/play-ZkBt6fCi.js +0 -1
- package/dist/assets/plus-B_s-mxBM.js +0 -1
- package/dist/assets/power-DZPpdhIY.js +0 -1
- package/dist/assets/remoteEntry-7VRsdXIk.js +0 -1
- package/dist/assets/rotate-ccw-5xNQStDV.js +0 -1
- package/dist/assets/rotate-cw-DKJX5UTY.js +0 -1
- package/dist/assets/square-D82yd7G6.js +0 -1
- package/dist/assets/src-C2j9sEfa.js +0 -349
- package/dist/assets/useEventInvalidation-CjMIICCC.js +0 -1
- package/dist/assets/user-round-Ccl_m9QC.js +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,V as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as d}from"./player-overlays-BOHd-BQW.js";import{$s as f,Go as p,J as m,Ja as h,Jo as g,Jr as _,Ko as v,Y as y,da as b,ec as x,fa as S,fn as C,hn as w,hs as T,la as E,mn as D,mo as O,na as k,nt as A,pn as ee,qo as te,ra as ne,rt as re,sn as j,ua as ie}from"./src-BmPEyOJ9.js";import{Ot as ae}from"./src-DGE3vmjp.js";import{n as oe,t as M}from"./format-size-DoXWOpar.js";import{t as se}from"./pencil-GpDj1Q2p.js";import{t as ce}from"./radio-CkABc76L.js";import{t as le}from"./refresh-cw-CGsZO3dv.js";import{t as N}from"./rotate-cw-CLl0fQTC.js";import{t as ue}from"./server-B7kfcasJ.js";import{B as de,J as fe,L as pe,P as me,U as he,a as P,m as ge,o as _e,p as ve,r as F,t as I,w as L,z as ye}from"./index-g356Z7K8.js";import{t as be}from"./NodeAddonsSettingsPanel-C-NPPWAc.js";import{n as xe,r as Se,t as Ce}from"./useNodeUrlSelection-DGIGjgUa.js";var R=fe(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),z=fe(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]);n();function we(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function Te({state:e}){return l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var Ee=[`trace`,`debug`,`info`,`warn`,`error`];function De({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:a}){let o=e.services??[],s=o.length===1,[u,d]=c(s||n),[f,p]=c(null),[h,g]=c(`info`),_=e.name.includes(`(core)`),v=ie(),x=b(),T=S(),E=async e=>{p(e);try{await v.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{p(null)}},O=async()=>{p(e.name);try{await x.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{p(null)}},k=async n=>{let r=`${t}/${e.name}`;try{await T.mutateAsync({nodeId:r,level:n}),g(n)}catch(e){console.error(`Failed to set log level:`,e)}};return r(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[r(`div`,{role:s?void 0:`button`,tabIndex:s?void 0:0,onClick:s?void 0:()=>d(!u),onKeyDown:s?void 0:e=>{(e.key===`Enter`||e.key===` `)&&d(!u)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${s?``:`hover:bg-muted/40 cursor-pointer`}`,children:[s?l(`span`,{className:`h-3 w-3 shrink-0`}):l(u?ye:pe,{className:`h-3 w-3 text-muted-foreground shrink-0`}),_?l(ue,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(he,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),l(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),l(Te,{state:e.state}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:M(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:we(e.uptimeSeconds)}),!_&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(C,{children:[l(w,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:h}),l(ee,{align:`end`,className:`min-w-[70px] py-0.5`,children:Ee.map(e=>l(D,{onClick:()=>k(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===h?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:O,disabled:f===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:l(N,{className:`h-3 w-3 ${f===e.name?`animate-spin`:``}`})})]})]}),u&&o.length>0&&l(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),l(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&r(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&r(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[l(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:l(ge,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:l(ce,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>E(e.addonId),disabled:f===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:l(N,{className:`h-3 w-3 ${f===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(y,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(m,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),u&&o.length===0&&l(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function Oe({nodeId:e,processes:t}){let[n,r]=c(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):l(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>l(De,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}var ke={system:0,managed:1,root:2};n();function Ae(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function je(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Me({nodeId:e}){let t=s(),n=x(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:i}=ne({nodeId:e}),o=n?.processes??i,c=a(()=>o?[...o]:[],[o]),u=a(()=>[{key:`classification`,header:`Class`,sortValue:e=>ke[e.classification],render:e=>l(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})},{key:`pid`,header:`PID`,align:`right`,sortValue:e=>e.pid,render:e=>l(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>l(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:`Addon`,sortValue:e=>e.addonId,render:e=>l(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:`Command`,nowrap:!1,render:e=>l(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:je(e.command)})},{key:`cpuPercent`,header:`CPU%`,align:`right`,sortValue:e=>e.cpuPercent,render:e=>e.cpuPercent.toFixed(1)},{key:`memoryRssBytes`,header:`RSS`,align:`right`,sortValue:e=>e.memoryRssBytes,render:e=>M(e.memoryRssBytes)},{key:`uptimeSec`,header:`Uptime`,align:`right`,sortValue:e=>e.uptimeSec,render:e=>l(`span`,{className:`text-foreground-subtle`,children:Ae(e.uptimeSec)})}],[]);return r(`div`,{className:`space-y-4`,children:[l(`div`,{className:`flex items-start justify-end gap-4`,children:r(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[l(le,{className:`h-3 w-3`}),` Refresh`]})}),l(A,{columns:u,rows:c,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`scroll`,maxBodyHeight:re,emptyMessage:`Scanning…`})]})}var B={width:320,height:64},V=.8,H=Math.ceil(8*V-3)+1,U=B.width+34,W=B.height+H+1+11,Ne=H+B.height+1+3+Math.ceil(8*V),Pe=[1,2,5,10],Fe=[1,2,4,8,16,32,64,128,256,512,1024],Ie=[1,1.5,2,2.5,3,4,5],G=[4,3,5,2],Le=1e-9;function Re(e,t){if(!Number.isFinite(e)||e<=0)return!1;if(t===`bytes`){if(!Number.isInteger(e))return!1;let t=e/1024**Math.floor(Math.log(e)/Math.log(1024));return Ie.some(e=>Math.abs(t-e)<Le)}let n=e/10**Math.floor(Math.log10(e));return Ie.some(e=>Math.abs(n-e)<Le)}function ze(e,t,n){let r=0;for(let t of e)t!==null&&t>r&&(r=t);if(r<=t)return t;if(n===`bytes`){let e=1024**Math.floor(Math.log(r)/Math.log(1024));for(let t of Fe){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of Pe){let t=e*i;if(t>=r)return t}return 10*i}function Be(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=G.find(n=>Re(e/n,t))??G[G.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var Ve=2.5;function He(e){return e*Ve}function K(e,t,n,r){if(e.length===0)return[];let i=e[0].atMs,a=e.at(-1).atMs-i,o=n<=0?1:n,s=r!==void 0&&r>0?r:null;return e.map((r,c)=>{let l=a>0?(r.atMs-i)/a*t.width:c/Math.max(1,e.length-1)*t.width,u=c>0?e[c-1]:void 0;return{x:l,y:r.value===null?null:t.height-Math.min(r.value,n)/o*t.height,gapBefore:s!==null&&u!==void 0&&r.atMs-u.atMs>s}})}function Ue(e){let t=[],n=!1;for(let r of e){if(r.y===null){n=!1;continue}r.gapBefore&&(n=!1),t.push(`${n?`L`:`M`}${r.x.toFixed(1)},${r.y.toFixed(1)}`),n=!0}return t.join(` `)}function We(e,t){let n=[],r=[],i=()=>{if(r.length<2){r=[];return}let e=r.map((e,t)=>`${t===0?`M`:`L`}${e.x.toFixed(1)},${e.top.toFixed(1)}`),t=[...r].reverse().map(e=>`L${e.x.toFixed(1)},${e.bottom.toFixed(1)}`);n.push(`${e.join(` `)} ${t.join(` `)} Z`),r=[]};for(let n=0;n<e.length;n++){let a=e[n],o=t[n];if(!a||!o||a.y===null||o.y===null){i();continue}(a.gapBefore||o.gapBefore)&&i(),r.push({x:a.x,top:a.y,bottom:o.y})}return i(),n.join(` `)}function Ge(e,t,n=3){if(e.length<2||n<2)return[];let r=e[0].atMs,i=e.at(-1).atMs-r;if(i<=0)return[];let a=[];for(let e=0;e<n;e++){let o=e/(n-1);a.push({atMs:r+i*o,x:o*t.width,anchor:e===0?`start`:e===n-1?`end`:`middle`})}return a}function Ke(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function qe(e){let t=[];for(let n=1;n<e.length;n++){let r=e[n];r.gapBefore&&t.push({fromX:e[n-1].x,toX:r.x})}return t}function Je(e,t){if(e.length===0)return null;let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=Math.abs(e[i].x-t);a<r&&(r=a,n=i)}return n}n();var q={main:`var(--load-series-main)`,gc:`var(--load-series-gc)`},Ye=`
|
|
2
|
+
.load-chart-scope { --load-series-main: #2a78d6; --load-series-gc: #e87ba4; }
|
|
3
|
+
@media (prefers-color-scheme: dark) {
|
|
4
|
+
:root:not([data-theme="light"]) .load-chart-scope {
|
|
5
|
+
--load-series-main: #3987e5; --load-series-gc: #d55181;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
:root[data-theme="dark"] .load-chart-scope {
|
|
9
|
+
--load-series-main: #3987e5; --load-series-gc: #d55181;
|
|
10
|
+
}
|
|
11
|
+
`,J=B,Xe={height:W};function Ze({title:e,points:n,mainLabel:s,gcLabel:u,formatValue:d,emptyMessage:f,gapMs:p}){let m=i(),h=t(null),[g,_]=c(null),v=a(()=>{let e=n.map(e=>({atMs:e.atMs,value:e.main===null||e.gc===null?null:e.main+e.gc})),t=n.map(e=>({atMs:e.atMs,value:e.main})),r=ze(e.map(e=>e.value),25,`linear`),i=K(e,J,r,p),a=K(t,J,r,p),o=a.map(e=>({x:e.x,y:e.y===null?null:J.height,gapBefore:e.gapBefore}));return{max:r,ticks:Be(r,`linear`),upper:i,middle:a,base:o,gaps:qe(i),times:Ge(e,J),spanMs:Ke(e)}},[n,p]),y=n.at(-1),b=g===null?void 0:n[g.index],x=b??y;return n.length===0||v.upper.every(e=>e.y===null)?l(X,{title:e,children:l(st,{message:f})}):l(X,{title:e,legend:r(o,{children:[l(ot,{color:q.main,label:s}),l(ot,{color:q.gc,label:u})]}),readout:x&&x.main!==null&&x.gc!==null?r(o,{children:[b!==void 0&&l(at,{atMs:b.atMs,spanMs:v.spanMs}),l(Z,{color:q.main,text:d(x.main)}),l(Z,{color:q.gc,text:d(x.gc)})]}):null,children:r(`svg`,{ref:h,viewBox:`0 0 ${U} ${W}`,preserveAspectRatio:`none`,className:`w-full`,style:Xe,role:`img`,"aria-label":`${e}: ${s} and ${u} over time`,onMouseLeave:()=>_(null),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();if(t.width===0)return;let n=(e.clientX-t.left)/t.width*U-34,r=Je(v.upper,n);r!==null&&_({index:r,xPx:v.upper[r].x})},children:[l(Qe,{ticks:v.ticks,max:v.max,formatValue:d}),l(it,{ticks:v.times,spanMs:v.spanMs}),r(`g`,{transform:`translate(34,${H})`,clipPath:`url(#${m})`,children:[l(`clipPath`,{id:m,children:l(`rect`,{x:0,y:0,width:J.width,height:J.height})}),l($e,{spans:v.gaps}),l(`path`,{d:We(v.middle,v.base),fill:q.main,fillOpacity:.85}),l(`path`,{d:We(v.upper,v.middle),fill:q.gc,fillOpacity:.85,stroke:`var(--color-surface, transparent)`,strokeWidth:2}),l(`path`,{d:Ue(v.upper),fill:`none`,stroke:q.gc,strokeWidth:2}),g!==null&&l(`line`,{x1:g.xPx,x2:g.xPx,y1:0,y2:J.height,stroke:`currentColor`,strokeWidth:1,className:`text-foreground-subtle`})]})]})})}function Y({title:e,points:n,formatValue:i,emptyMessage:s,axisFloor:u,axisScale:d=`linear`,gapMs:f}){let p=t(null),[m,h]=c(null),g=a(()=>{let e=ze(n.map(e=>e.value),u,d),t=K(n,J,e,f);return{max:e,ticks:Be(e,d),projected:t,gaps:qe(t),times:Ge(n,J),spanMs:Ke(n)}},[n,u,d,f]),_=m===null?void 0:n[m.index],v=_??n.at(-1)??void 0;return n.length===0||g.projected.every(e=>e.y===null)?l(X,{title:e,children:l(st,{message:s})}):l(X,{title:e,readout:v&&v.value!==null?r(o,{children:[_!==void 0&&l(at,{atMs:_.atMs,spanMs:g.spanMs}),l(Z,{color:q.main,text:i(v.value)})]}):null,children:r(`svg`,{ref:p,viewBox:`0 0 ${U} ${W}`,preserveAspectRatio:`none`,className:`w-full`,style:Xe,role:`img`,"aria-label":e,onMouseLeave:()=>h(null),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();if(t.width===0)return;let n=(e.clientX-t.left)/t.width*U-34,r=Je(g.projected,n);r!==null&&h({index:r,xPx:g.projected[r].x})},children:[l(Qe,{ticks:g.ticks,max:g.max,formatValue:i}),l(it,{ticks:g.times,spanMs:g.spanMs}),r(`g`,{transform:`translate(34,${H})`,children:[l($e,{spans:g.gaps}),l(`path`,{d:Ue(g.projected),fill:`none`,stroke:q.main,strokeWidth:2}),m!==null&&l(`line`,{x1:m.xPx,x2:m.xPx,y1:0,y2:J.height,stroke:`currentColor`,strokeWidth:1,className:`text-foreground-subtle`})]})]})})}function Qe({ticks:e,max:t,formatValue:n}){let i=t<=0?1:t;return l(`g`,{className:`text-foreground-subtle`,children:e.map(e=>{let t=H+J.height-e/i*J.height;return r(`g`,{children:[l(`line`,{x1:34,x2:34+J.width,y1:t,y2:t,stroke:`currentColor`,strokeWidth:.5,strokeOpacity:.3}),l(`text`,{x:0,y:t+3,fontSize:8,fill:`currentColor`,children:n(e)})]},e)})})}function $e({spans:e}){return e.length===0?null:l(`g`,{className:`text-foreground-subtle`,children:e.map(e=>l(`rect`,{x:e.fromX,y:0,width:Math.max(1,e.toX-e.fromX),height:J.height,fill:`currentColor`,fillOpacity:.12,children:l(`title`,{children:`No samples in this interval — nothing was measured, nothing is drawn.`})},`${e.fromX}-${e.toX}`))})}var et=10*6e4,tt={hour:`2-digit`,minute:`2-digit`},nt={hour:`2-digit`,minute:`2-digit`,second:`2-digit`};function rt(e,t){return new Date(e).toLocaleTimeString(void 0,t<et?nt:tt)}function it({ticks:e,spanMs:t}){return e.length===0?null:l(`g`,{className:`text-foreground-subtle`,children:e.map(e=>l(`text`,{x:34+e.x,y:Ne,fontSize:8,textAnchor:e.anchor,fill:`currentColor`,children:rt(e.atMs,t)},e.atMs))})}function at({atMs:e,spanMs:t}){return l(`span`,{className:`text-[10px] tabular-nums text-foreground-subtle`,children:rt(e,t)})}function X({title:e,legend:t,readout:n,children:i}){return r(`div`,{className:`load-chart-scope min-w-0`,children:[r(`div`,{className:`flex items-baseline justify-between gap-2 mb-1`,children:[l(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:e}),l(`div`,{className:`flex items-center gap-2`,children:n})]}),i,t&&l(`div`,{className:`flex items-center gap-3 mt-1`,children:t})]})}function ot({color:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1 text-[9px] text-foreground-subtle`,children:[l(`span`,{className:`inline-block h-2 w-2 rounded-[2px]`,style:{backgroundColor:e}}),t]})}function Z({color:e,text:t}){return r(`span`,{className:`inline-flex items-center gap-1 text-[11px] tabular-nums text-foreground`,children:[l(`span`,{className:`inline-block h-2 w-2 rounded-[2px]`,style:{backgroundColor:e}}),t]})}function st({message:e}){return l(`div`,{className:`h-16 flex items-center justify-center rounded border border-dashed border-border text-[10px] text-foreground-subtle text-center px-2`,children:e})}function ct(e,t){let n=e.at(-1);return n===void 0?[t]:t.atMs>n.atMs?[...e,t]:e.some(e=>e.atMs===t.atMs)?e:[...e,t].toSorted((e,t)=>e.atMs-t.atMs)}function lt(e,t,n,r){let i=e.get(t),a=ct(i?.points??[],r);if(i!==void 0&&a===i.points)return e;let o=new Map(e);return o.set(t,{key:t,kind:n,points:a.slice(Math.max(0,a.length-720))}),o}function ut(e,t,n){let r=e;for(let e of ae(t,n))r=lt(r,e.key,e.kind,e.point);return r}function dt(e,t){let n=e;for(let e of t)for(let t of e.points)n=lt(n,e.key,e.kind,t);return n}function ft(e){let t=null;for(let n of e.values()){let e=n.points.at(-1);e!==void 0&&(t===null||e.atMs>t)&&(t=e.atMs)}return t}var pt=12e4;function mt(e,t){return e===null?!1:t-e>pt}function ht(e){let t=e=>{let t=e.points.at(-1);return t===void 0?-1:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.key.localeCompare(n.key):r})}function gt(e){for(let t of e.values()){let e=t.points.at(-1);if(e&&e.cpuMainPercent!==null)return!0}return!1}var _t={key:`cpu`,dir:`desc`};function vt(e){let t=e.points.at(-1);return t===void 0?null:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent}function yt(e){return e.points.at(-1)?.memoryRssBytes??null}function bt(e,t,n){let r=n.trim().toLowerCase();return r===``?!0:e.toLowerCase().includes(r)||t.toLowerCase().includes(r)}function xt(e,t){return t===`memory`?yt(e):vt(e)}function St(e,t,n){let r=e.filter(e=>t.selectedKeys.size>0&&!t.selectedKeys.has(e.key)?!1:bt(n(e),e.key,t.search)),i=(e,t)=>e.key.localeCompare(t.key);return[...r].toSorted((e,r)=>{if(t.sort.key===`name`){let a=n(e).localeCompare(n(r)),o=t.sort.dir===`asc`?a:-a;return o===0?i(e,r):o}let a=xt(e,t.sort.key),o=xt(r,t.sort.key);if(a===null&&o===null)return i(e,r);if(a===null)return 1;if(o===null)return-1;let s=t.sort.dir===`desc`?o-a:a-o;return s===0?i(e,r):s})}n();function Ct(e,n=720){let r=x(`metrics.node-processes-snapshot`,t=>t.nodeId===e),[i,a]=c(new Map),[o,s]=c(void 0),l=t(null),{data:d,isPending:f}=k({forNodeId:e,sinceMs:o,maxPoints:n});u(()=>{d!==void 0&&a(e=>{let t=dt(e,d.series);return l.current=ft(t),t})},[d]);let p=r?.timestamp;u(()=>{r==null||p===void 0||(mt(l.current,p)&&s(l.current??0),a(e=>{let t=ut(e,r.processes,p);return l.current=ft(t),t}))},[p]),u(()=>{a(new Map),s(void 0),l.current=null},[e]);let m=0;for(let e of i.values())m=Math.max(m,e.points.length);return{series:ht(i),sampleCount:m,threadSplitAvailable:gt(i),loadingRetained:f,durable:d?.durable??null,bucketMs:d?.bucketMs??null,cadenceMs:d?.cadenceMs??null,retainedSamples:d?.retainedSamples??null}}var wt=`__unclaimed__`;function Tt(e,t){return{kind:e,deviceId:t,cpu:0,cpuKnown:!0,rss:0,rssKnown:!0,count:0,roles:new Set}}function Et(e,t){return{key:e,kind:t.kind,deviceId:t.deviceId,cpuSeconds:t.cpuKnown?Math.round(t.cpu*100)/100:null,rssBytes:t.rssKnown?t.rss:null,unitCount:t.count,roles:[...t.roles].sort()}}function Dt(e,t){let n=new Map,r=new Set;for(let t of e){t.pid!==void 0&&r.add(t.pid);let e=t.deviceId!==null&&t.attribution!==`unattributable`,i=e?`device:${t.deviceId}`:`shared:${t.role}`,a=n.get(i)??Tt(e?`camera`:`shared`,e?t.deviceId:null);a.count+=1,a.roles.add(t.role),t.cpuSeconds===void 0?a.cpuKnown=!1:a.cpu+=t.cpuSeconds,t.rssBytes===void 0?a.rssKnown=!1:a.rss+=t.rssBytes,n.set(i,a)}let i=[...n.entries()].map(([e,t])=>Et(e,t));if(t===void 0)return i;let a=t.filter(e=>!r.has(e.pid));if(a.length===0)return i;let o=Tt(`unclaimed`,null);for(let e of a)o.count+=1,o.rss+=e.memoryRssBytes;return o.cpuKnown=!1,[...i,Et(wt,o)]}var Ot=[{family:`decode`,attribution:`measured`,unit:`one forked decode-worker child per decode SESSION`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:118`,`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:131`,`packages/addon-pipeline/src/pipeline-runner/index.ts:2765`,`packages/types/src/process/child-cost-registry.ts:188`]},{family:`transcode`,attribution:`measured`,unit:`one ffmpeg child per (camera, encode plan)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/egress-transcode-manager.ts:960`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:282`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:324`,`packages/types/src/ffmpeg/sharing-key.ts:139`]},{family:`recording`,attribution:`measured`,unit:`one passthrough ffmpeg per (camera, profile)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:33`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:217`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:279`,`packages/addon-pipeline/src/recorder/addon/recording-controller.ts:1710`]},{family:`detection`,attribution:`accounted`,unit:`a SHARED inference pool per (node, runtime, device) — no per-camera process`,perCamera:!1,wiredToday:!0,missingLink:"Nothing is missing for COUNTING — per-camera inference milliseconds, processed/shed frames and bytes-to-pool are already accumulated. What is missing is any basis for CPU seconds: `deviceId` reaches the pool as a diagnostic label and selects nothing, so cost can only ever be apportioned, never measured. Since 2026-08-27 the pool DECLARES this itself, contributing `deviceId: null` + `attribution: unattributable` rather than leaving an observer to infer it — the renunciation is data, and it is still refused by the chart gate.",evidence:[`packages/addon-pipeline/src/detection-pipeline/provider.ts:540`,`packages/addon-pipeline/src/detection-pipeline/engine/shared-inference-pool.ts:413`,`packages/types/src/interfaces/inference-engine.ts:24`,`packages/addon-pipeline/src/pipeline-runner/timing-sampler.ts:63`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:353`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:849`,`packages/addon-pipeline/src/pipeline-runner/frame-lazy-metrics.ts:100`]},{family:`streaming`,attribution:`measured`,unit:"one StreamBroker per `${deviceId}/${camStreamId}`, with an exact RTP ring byte counter",perCamera:!0,wiredToday:!1,missingLink:"The ffmpeg-backed ingest is now reported per camera, but that is the minority path. `rtpRingBytes` — the exact figure for the in-process case — is maintained on every push and drop and is still private and absent from `getStats()`. The three `EncodedRingBuffer`s track packets and duration and have no byte accumulator at all; the only byte figure they offer is `preRollBudgetBytes`, which is a BUDGET, not an occupancy.",evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2895`,`packages/addon-pipeline/src/stream-broker/rtsp/ffmpeg-push-reader.ts:189`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:494`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:498`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2505`,`packages/addon-pipeline/src/stream-broker/stream-broker/pre-roll.ts:269`]}];function kt(e){return e.attribution===`measured`&&e.wiredToday}function At(){let e=new Set;for(let t of Ot)kt(t)&&e.add(t.family);return e}var jt=At();function Mt(e){return!jt.has(e.role)||e.deviceId===null?!1:e.attribution===`measured`}function Nt(e){return`${e.addonId}${e.role}${e.unit}${e.pid??`-`}`}function Pt(){return{cpuSeconds:0,cpuKnown:!0,rssBytes:0,rssKnown:!0,unitCount:0,roles:new Set}}function Ft(e,t,n){if(t.cpuSeconds===void 0)return null;if(e===void 0)return t.startedAtMs===void 0||t.startedAtMs<n?null:t.cpuSeconds;if(e.cpuSeconds===void 0||e.startedAtMs===void 0||t.startedAtMs===void 0||e.startedAtMs!==t.startedAtMs)return null;let r=t.cpuSeconds-e.cpuSeconds;return r<0?null:r}function It(e){return Math.round(e*10)/10}function Lt(e,t){let n=t.atMs-e.atMs;if(n<=0)return[];let r=n/1e3,i=new Map;for(let t of e.entries)Mt(t)&&i.set(Nt(t),t);let a=new Map,o=new Set;for(let n of t.entries){if(!Mt(n)||n.deviceId===null)continue;let t=Nt(n);o.add(t);let r=a.get(n.deviceId)??Pt();r.unitCount+=1,r.roles.add(n.role);let s=Ft(i.get(t),n,e.atMs);s===null?r.cpuKnown=!1:r.cpuSeconds+=s,n.rssBytes===void 0?r.rssKnown=!1:r.rssBytes+=n.rssBytes,a.set(n.deviceId,r)}for(let[e,t]of i){if(o.has(e)||t.deviceId===null)continue;let n=a.get(t.deviceId);n!==void 0&&(n.cpuKnown=!1)}return[...a.entries()].map(([e,n])=>({deviceId:e,point:{atMs:t.atMs,cpuPercent:n.cpuKnown?It(n.cpuSeconds/r*100):null,rssBytes:n.rssKnown?n.rssBytes:null,unitCount:n.unitCount,roles:[...n.roles].toSorted()}}))}function Rt(e,t){if(t.length===0)return e;let n=new Map(e);for(let e of t){let t=n.get(e.deviceId),r=t?.points.at(-1);if(r!==void 0&&e.point.atMs<=r.atMs)continue;let i=[...t?.points??[],e.point];n.set(e.deviceId,{deviceId:e.deviceId,points:i.slice(Math.max(0,i.length-720))})}return n}function zt(e){let t=e=>{for(let t=e.points.length-1;t>=0;t--){let n=e.points[t]?.cpuPercent;if(n!=null)return n}return-1};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.deviceId-n.deviceId:r})}function Bt(e){let t=e.indexOf(`@`);return t===-1?{addonId:e,nodeId:null}:{addonId:e.slice(0,t),nodeId:e.slice(t+1)}}function Vt(e,t){let n=Bt(e);return n.nodeId===null?t.isHub:n.nodeId===t.nodeId}function Ht(e,t){return e.filter(e=>Vt(e.addonId,t))}n();function Ut(e){let n=x(`metrics.node-processes-snapshot`,t=>t.nodeId===e.nodeId),r=T(void 0,{staleTime:1/0,refetchOnWindowFocus:!1}),[i,a]=c(new Map),o=t(null),s=t(r.refetch);s.current=r.refetch;let l=n?.timestamp;u(()=>{l!==void 0&&s.current()},[l]),u(()=>{a(new Map),o.current=null},[e.nodeId,e.isHub]);let d=r.data,f=r.dataUpdatedAt;u(()=>{if(d===void 0||f===0)return;let t={atMs:f,entries:Ht(d,e)},n=o.current;if(o.current=t,n===null)return;let r=Lt(n,t);r.length!==0&&a(e=>Rt(e,r))},[d,f,e.nodeId,e.isHub]);let p=d===void 0?[]:Ht(d,e),m=n?.processes,h=Dt(p,m);return{series:zt(i),unclaimed:h.find(e=>e.kind===`unclaimed`)??null,loading:r.isPending,error:r.error===null?null:r.error.message}}function Wt(e){let t=new Map;for(let n of e){let e=n.name?.trim();e===void 0||e===``||t.set(n.id,e)}return t}var Gt=25,Kt=64*1024*1024,qt=1e4;function Jt({scope:e,cadenceMs:t}){let{t:n}=I(),i=Ut(e),{data:a=[]}=_({isCamera:!0,projection:`slim`}),o=Wt(a),s=He(t??qt);return r(`section`,{className:`space-y-3`,children:[i.error!==null&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[l(P,{className:`h-3 w-3 mt-0.5 shrink-0`}),l(`span`,{children:n(`cameraLoad.readFailed`,`Could not read the load contributions: {{error}}. This is a failed read, NOT an idle cluster.`,{error:i.error})})]}),l(Xt,{unclaimed:i.unclaimed}),i.series.length===0&&i.error===null&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:i.loading?n(`cameraLoad.loading`,`Reading what the addons report…`):n(`cameraLoad.waitingWindow`,`No per-camera window yet.`)}),l(`div`,{className:`space-y-3`,children:i.series.map(e=>r(`div`,{className:`rounded-lg border border-border p-3`,children:[r(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[l(Yt,{deviceId:e.deviceId,name:o.get(e.deviceId)}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`cameraLoad.unitCount`,`{{count}} unit(s): {{roles}}`,{count:e.points.at(-1)?.unitCount??0,roles:(e.points.at(-1)?.roles??[]).join(`, `)})})]}),r(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[l(Y,{title:n(`cameraLoad.cpuTitle`,`CPU % of one core (delta)`),points:e.points.map(e=>({atMs:e.atMs,value:e.cpuPercent})),formatValue:e=>`${e.toFixed(1)}%`,axisFloor:Gt,gapMs:s,emptyMessage:n(`cameraLoad.cpuUnavailable`,`No measurable window yet.`)}),l(Y,{title:n(`cameraLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.rssBytes})),formatValue:M,axisFloor:Kt,axisScale:`bytes`,gapMs:s,emptyMessage:n(`cameraLoad.memoryUnavailable`,`No memory reported.`)})]})]},e.deviceId))})]})}function Yt({deviceId:e,name:t}){let{t:n}=I();return t===void 0?l(`span`,{className:`text-xs font-medium text-foreground`,children:n(`cameraLoad.deviceLabel`,`Camera {{deviceId}}`,{deviceId:e})}):r(`span`,{className:`flex items-baseline gap-1.5 min-w-0`,children:[l(`span`,{className:`text-xs font-medium text-foreground truncate`,children:t}),r(`span`,{className:`shrink-0 text-[10px] font-mono text-foreground-subtle`,children:[`#`,e]})]})}function Xt({unclaimed:e}){let{t}=I();return e===null||e.unitCount===0?null:l(`div`,{className:`flex items-center gap-2`,children:l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full bg-amber-500/10 text-amber-400 font-medium tabular-nums`,children:t(`cameraLoad.unclaimedBadge`,`{{count}} unclaimed · {{rss}}`,{count:e.unitCount,rss:e.rssBytes===null?`—`:M(e.rssBytes)})})})}n();var Zt=256*1024*1024,Qt=1e4;function $t({nodeId:e,isHub:t}){let{t:n}=I(),{series:i,sampleCount:o,threadSplitAvailable:s,loadingRetained:u,bucketMs:d,cadenceMs:f}=Ct(e),[p,m]=c(``),[h,g]=c(new Set),[_,v]=c(_t),y=e=>e.key===`__root__`?n(`clusterLoad.bucketRoot`,`Node supervisor`):e.key===`__unattributed__`?n(`clusterLoad.bucketUnattributed`,`Unattributed processes`):e.key,b=He(d??f??Qt),x=a(()=>St(i,{search:p,selectedKeys:h,sort:_},y),[i,p,h,_]),S=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return r(`div`,{className:`space-y-4`,children:[l(`style`,{children:Ye}),l(en,{bucketMs:d,cadenceMs:f}),!s&&o>0&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-amber-500/40 bg-amber-500/5 px-3 py-2 text-[11px] text-amber-400`,children:[l(P,{className:`h-3 w-3 mt-0.5 shrink-0`}),l(`span`,{children:n(`clusterLoad.noThreadSplit`,`No thread-level CPU split on this node — /proc/<pid>/task is Linux-only, and the first sample after a restart has no window to measure. CPU below falls back to the ps lifetime AVERAGE, which is not a rate.`)})]}),o===0&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:u?n(`clusterLoad.loadingRetained`,`Reading the retained series from this node…`):n(`clusterLoad.waitingFirstSample`,`No retained samples for this node — waiting for the next snapshot (up to 20s). The chart needs two to draw a rate.`)}),i.length>0&&r(`div`,{className:`space-y-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`label`,{className:`relative flex-1 min-w-[160px]`,children:[l(ve,{className:`pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-foreground-subtle`}),l(`input`,{type:`search`,value:p,onChange:e=>m(e.target.value),placeholder:n(`clusterLoad.searchPlaceholder`,`Find a runner…`),"aria-label":n(`clusterLoad.searchLabel`,`Find a runner`),className:`w-full rounded border border-border bg-background py-1 pl-7 pr-2 text-[11px] text-foreground placeholder:text-foreground-subtle`})]}),l(tn,{sort:_,onChange:v})]}),r(`div`,{className:`flex flex-wrap items-center gap-1`,children:[i.map(e=>{let t=h.has(e.key);return l(`button`,{type:`button`,"aria-pressed":t,onClick:()=>S(e.key),className:`rounded-full border px-2 py-0.5 text-[10px] transition-colors ${t?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:y(e)},e.key)}),h.size>0&&r(`button`,{type:`button`,onClick:()=>g(new Set),className:`inline-flex items-center gap-1 rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground`,children:[l(F,{className:`h-2.5 w-2.5`}),n(`clusterLoad.clearFilter`,`All runners`)]})]})]}),i.length>0&&x.length===0&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:n(`clusterLoad.noMatches`,`No runner matches this search on {{count}} present. The node is reporting — the filter is hiding them.`,{count:i.length})}),l(`div`,{className:`space-y-3`,children:x.map(e=>r(`div`,{className:`rounded-lg border border-border p-3`,children:[r(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[l(`span`,{className:`text-xs font-medium text-foreground`,children:y(e)}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`clusterLoad.processCount`,`{{count}} process(es)`,{count:e.points.at(-1)?.processCount??0})})]}),r(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[l(Ze,{title:s?n(`clusterLoad.cpuTitle`,`CPU % of one core`):n(`clusterLoad.cpuTitleLifetime`,`CPU % (ps lifetime average)`),mainLabel:n(`clusterLoad.seriesMain`,`Main threads`),gcLabel:n(`clusterLoad.seriesGc`,`GC / V8 helpers`),points:e.points.map(e=>({atMs:e.atMs,main:e.cpuMainPercent,gc:e.cpuGcPercent})),formatValue:e=>`${e.toFixed(0)}%`,gapMs:b,emptyMessage:n(`clusterLoad.cpuUnavailable`,`No thread split on this node. Lifetime average: {{avg}}%`,{avg:(e.points.at(-1)?.cpuLifetimePercent??0).toFixed(1)})}),l(Y,{title:n(`clusterLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.memoryRssBytes})),formatValue:M,axisFloor:Zt,axisScale:`bytes`,gapMs:b,emptyMessage:n(`clusterLoad.memoryUnavailable`,`No memory samples yet.`)})]})]},e.key))}),l(Jt,{scope:{nodeId:e,isHub:t},cadenceMs:f})]})}function en({bucketMs:e,cadenceMs:t}){let{t:n}=I();return e===null?null:l(`p`,{className:`text-[10px] text-foreground-subtle`,children:t!==null&&e>t?n(`clusterLoad.captionBucket`,`1 point = {{bucket}}s (bucket MAXIMUM, not a mean)`,{bucket:Math.round(e/1e3)}):n(`clusterLoad.captionRaw`,`1 point = 1 snapshot`)})}function tn({sort:e,onChange:t}){let{t:n}=I(),i=[{key:`cpu`,label:n(`clusterLoad.sortCpu`,`CPU`)},{key:`memory`,label:n(`clusterLoad.sortMemory`,`Memory`)},{key:`name`,label:n(`clusterLoad.sortName`,`Name`)}];return r(`div`,{className:`flex items-center gap-1`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`clusterLoad.sortBy`,`Sort by`)}),i.map(n=>{let i=e.key===n.key;return r(`button`,{type:`button`,"aria-pressed":i,onClick:()=>t(i?{key:n.key,dir:e.dir===`desc`?`asc`:`desc`}:{key:n.key,dir:n.key===`name`?`asc`:`desc`}),className:`rounded border px-1.5 py-0.5 text-[10px] transition-colors ${i?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:[n.label,i&&(e.dir===`desc`?` ↓`:` ↑`)]},n.key)})]})}var nn=`No per-node settings on this node. Every other setting these addons expose is one value for the whole cluster — edit those in System → Settings, not here.`;function rn({nodeId:e,addonIds:t}){return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):l(`div`,{className:`w-full py-2`,children:l(be,{nodeId:e,addonIds:t,level:`global`,fieldScope:`perNode`,emptyMessage:nn,selfTabbed:!0})})}n();function an({nodeId:e,addons:t}){let n=s(),{data:r,isLoading:i}=h({nodeId:e}),o=a(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),c=O({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return o.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):l(A,{columns:[{key:`capName`,header:`Capability`,width:`w-1/2`,sortValue:e=>e.capName,render:e=>l(`span`,{className:`font-medium`,children:e.capName})},{key:`provider`,header:`Bound provider`,render:t=>{let n=r?.[t.capName]??t.providers[0]??``,a=t.providers.length===1;return l(`select`,{value:n,onChange:n=>c.mutate({nodeId:e,capName:t.capName,addonId:n.target.value}),disabled:a||c.isPending||i,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:a?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:t.providers.map(e=>l(`option`,{value:e,children:e},e))})}}],rows:o,rowKey:e=>e.capName,minWidthPx:520,mobileMode:`scroll`,maxBodyHeight:re})}n();function on(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function sn(e){let[t,n]=c(!1),[i,a]=c(e.name),o=s(),u=E({onSuccess:()=>{o.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),d=(e.localIps??[]).filter(e=>!e.includes(`:`)),f=(e.localIps??[]).filter(e=>e.includes(`:`)),p=async()=>{if(!i.trim()||i===e.name){n(!1);return}try{await u.mutateAsync({nodeId:e.nodeId,name:i.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},m=[[`Node ID`,l(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?r(`div`,{className:`flex items-center gap-1.5`,children:[l(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&p(),e.key===`Escape`&&n(!1)},disabled:u.isPending,autoFocus:!0}),l(`button`,{onClick:()=>void p(),disabled:u.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:l(de,{className:`h-3.5 w-3.5`})}),l(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:l(F,{className:`h-3.5 w-3.5`})})]}):r(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&l(`button`,{onClick:()=>{a(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:l(se,{className:`h-3 w-3`})})]})],[`Hostname`,l(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Root Package`,e.rootPackage?r(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):l(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,r(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,r(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,l(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,l(`span`,{className:`text-xs`,children:on(e.uptime)})],[`Engines`,e.engines.length>0?l(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):l(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return d.length>0&&m.push([`IPv4`,l(`div`,{className:`flex flex-wrap gap-1.5`,children:d.map((e,t)=>l(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),f.length>0&&m.push([`IPv6`,l(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map((e,t)=>l(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),l(`div`,{className:`py-2`,children:l(`table`,{className:`w-full text-sm`,children:l(`tbody`,{children:m.map(([e,t],n)=>r(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[l(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),l(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}n();var cn=[[`serverManagement`,`getServerPackageStatus`]];function ln({label:e,tone:t}){return l(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-emerald-500/15 text-emerald-500`,info:`bg-sky-500/15 text-sky-500`,warn:`bg-amber-500/15 text-amber-500`,error:`bg-red-500/15 text-red-500`}[t]}`,children:e})}function Q({label:e,value:t}){return r(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[l(`span`,{className:`text-foreground-subtle`,children:e}),l(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function un(e,t){let n=t instanceof Error?t.message:String(t);return`${e(`serverManagement.outcomeDropped`,`The connection dropped and the result could not be confirmed. The node may be restarting — re-check the version above.`)} — ${n}`}function dn({node:t}){let{t:n}=I(),i=s(),a=j(),[o,u]=c(!1),[d,f]=c(null),m=t.isHub?void 0:{nodeId:t.id},h=te(m,{refetchInterval:1e4,enabled:t.isOnline,retry:1}),_=h.data??null,y=e(()=>{i.invalidateQueries({queryKey:cn})},[i]),b=v({onSettled:y}),x=p({onSettled:y}),S=g({onSettled:y}),C=e(async()=>{if(_?.latestVersion==null){f({tone:`warn`,text:n(`serverManagement.outcomeNoTarget`,`No target version is known for this node — run "Check for update" first.`)});return}if(await a({title:n(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:n(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:_.packageName,version:_.latestVersion,node:t.name}),confirmLabel:n(`serverManagement.confirmUpdateAction`,`Update & restart`)})){f(null);try{let e=await x.mutateAsync({version:_.latestVersion,...m});f({tone:e.accepted?`ok`:`warn`,text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:un(n,e)})}}},[x,a,t.name,m,_,n]),w=e(async()=>{if(await a({title:n(`serverManagement.confirmRestartTitle`,`Restart node`),message:n(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:t.name}),confirmLabel:n(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})){f(null);try{let e=await S.mutateAsync(m);f({tone:e.accepted?`ok`:`warn`,text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:un(n,e)})}}},[a,t.name,S,m,n]),T=()=>{switch(_?.bootMode){case`data-root`:return{label:n(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:n(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:n(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},E=()=>{if(_==null)return null;switch(_.updateState){case`checking`:return{label:n(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:n(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:n(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return _.updateAvailable?{label:n(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:n(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},D=_?.bootMode===`workspace`,O=t.isOnline&&_!=null&&!D&&_.updateAvailable&&_.updateState===`idle`&&!x.isPending,k=t.isOnline&&_!=null&&_.updateState===`idle`&&!S.isPending,A=t.isOnline?E():null;return r(`div`,{className:`space-y-4 py-2`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[l(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:_?.packageName??t.rootPackage?.name??`@camstack/server`}),t.isOnline&&_!=null&&l(ln,{...T()})]}),A!=null&&l(ln,{...A})]}),!t.isOnline&&l(Q,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage?.version??null}),t.isOnline&&h.isLoading&&r(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[l(L,{className:`h-4 w-4 animate-spin`}),n(`common.loading`,`Loading…`)]}),t.isOnline&&h.isError&&r(`div`,{className:`space-y-1.5`,children:[l(`p`,{className:`text-sm text-red-500`,children:n(`serverManagement.loadError`,`Could not load the node root-package status.`)}),t.rootPackage!=null&&l(Q,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage.version})]}),t.isOnline&&_!=null&&r(`div`,{className:`space-y-1.5`,children:[l(Q,{label:n(`serverManagement.runningVersion`,`Running version`),value:_.runningVersion}),l(Q,{label:n(`serverManagement.latestVersion`,`Latest on registry`),value:_.latestVersion}),l(Q,{label:n(`serverManagement.imageSeedVersion`,`Image seed (baked)`),value:_.seedVersion}),l(Q,{label:n(`serverManagement.nodeRuntimeVersion`,`Node.js runtime`),value:_.nodeRuntimeVersion}),_.pendingVersion!=null&&l(Q,{label:n(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:_.pendingVersion})]}),t.isOnline&&_?.imageContract?.state===`behind-series`&&r(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-xs leading-relaxed text-red-500`,children:[l(`p`,{className:`mb-0.5 font-semibold`,children:n(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),l(`p`,{children:_.imageContract.message})]}),t.isOnline&&D&&l(`p`,{className:`text-xs text-foreground-subtle`,children:n(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),d!=null&&l(`p`,{role:`status`,className:`rounded border px-2 py-1.5 text-xs leading-relaxed ${d.tone===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-500`:`border-amber-500/40 bg-amber-500/10 text-amber-500`}`,children:d.text}),o&&r(`div`,{className:`flex items-center gap-2 text-sm text-amber-500`,children:[l(L,{className:`h-4 w-4 animate-spin`}),n(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),t.isOnline&&r(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:b.isPending||_?.updateState===`staging`,onClick:()=>b.mutate(m),children:[b.isPending?l(L,{className:`h-3.5 w-3.5 animate-spin`}):l(le,{className:`h-3.5 w-3.5`}),n(`serverManagement.checkForUpdate`,`Check for update`)]}),O&&r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void C(),children:[x.isPending?l(L,{className:`h-3.5 w-3.5 animate-spin`}):l(R,{className:`h-3.5 w-3.5`}),n(`serverManagement.updateTo`,`Update to {{version}}`,{version:_?.latestVersion??``})]}),r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!k,onClick:()=>void w(),children:[S.isPending?l(L,{className:`h-3.5 w-3.5 animate-spin`}):l(N,{className:`h-3.5 w-3.5`}),n(`serverManagement.restart`,`Restart`)]})]}),t.isOnline&&_?.lastCheckedAtMs!=null&&r(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[l(oe,{className:`h-3 w-3`}),n(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(_.lastCheckedAtMs).toLocaleString()})]})]})}n();function fn({node:e}){let t=d(),[n,i]=c(`info`),[a,o]=c(!1),[s,u]=c(null),f=e.processes??[],p=e.addons.map(e=>e.id),m=async()=>{if(!a){o(!0),u(null);try{await t.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}).catch(()=>void 0);let n=await t.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id});u({tone:n.stillListed?`warn`:`ok`,text:n.message})}catch(e){u({tone:`warn`,text:`Forget failed: ${e instanceof Error?e.message:String(e)}`})}finally{o(!1)}}};return e.isOnline?r(`div`,{className:`border border-border rounded-xl`,children:[r(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[l(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),l(`span`,{className:`text-sm font-semibold`,children:e.name}),r(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),r(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[r(`span`,{className:`flex items-center gap-1`,children:[l(me,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),r(`span`,{className:`flex items-center gap-1`,children:[l(z,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),l(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`forks`,`processes`,`load`,`settings`,`capabilities`].map(e=>l(`button`,{onClick:()=>i(e),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n===e?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:e===`info`?`General`:e===`forks`?`Forks (${f.length})`:e===`processes`?`Processes`:e===`load`?`Load`:e===`settings`?`Settings`:`Capabilities`},e))}),r(`div`,{className:`px-4 py-2`,children:[n===`info`&&r(`div`,{className:`space-y-3`,children:[l(sn,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps,rootPackage:e.rootPackage}),l(`div`,{className:`border-t border-border pt-1`,children:l(dn,{node:{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}})})]}),n===`forks`&&l(Oe,{nodeId:e.id,processes:f}),n===`processes`&&l(Me,{nodeId:e.id}),n===`load`&&l($t,{nodeId:e.id,isHub:e.isHub}),n===`settings`&&l(rn,{nodeId:e.id,addonIds:p}),n===`capabilities`&&l(an,{nodeId:e.id,addons:e.addons})]})]}):r(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[r(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[l(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),l(`span`,{className:`text-sm font-semibold`,children:e.name}),r(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),e.rootPackage&&r(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}),l(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),r(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[r(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?`Last seen ${new Date(e.lastSeen).toLocaleString()} — `:``,e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned; will resume when node reconnects`]}),r(`button`,{type:`button`,onClick:()=>void m(),disabled:a,title:`Forget this node — removes its saved history and pipeline assignments`,className:`flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border text-muted-foreground hover:text-destructive hover:border-destructive/50 disabled:opacity-50 transition-colors`,children:[l(_e,{className:`h-3 w-3`}),a?`Forgetting…`:`Forget node`]})]}),s!=null&&l(`p`,{role:`status`,className:`px-4 pb-3 text-xs leading-relaxed ${s.tone===`ok`?`text-emerald-500`:`text-amber-500`}`,children:s.text})]})}function pn({nodes:e,selected:t,onSelect:n}){let{t:i}=I(),a=xe(e);return t===null?l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-xs text-foreground-subtle`,children:i(`cluster.noNodes`,`No nodes in this cluster yet.`)}):r(`div`,{className:`flex flex-col gap-3`,children:[a.length>1&&l(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`tablist`,"aria-label":i(`cluster.nodeSelectorLabel`,`Nodes`),children:a.map(e=>l(mn,{node:e,active:e.id===t.id,onSelect:()=>n(e.id)},e.id))}),l(fn,{node:t})]})}function mn({node:e,active:t,onSelect:n}){let{t:i}=I();return r(`button`,{type:`button`,role:`tab`,"aria-selected":t,onClick:n,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs transition-colors ${t?`border-primary bg-primary/10 text-primary`:`border-border text-muted-foreground hover:text-foreground`}`,children:[l(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-destructive`}`}),l(`span`,{className:`font-medium`,children:e.name}),e.isOnline?r(`span`,{className:`inline-flex items-center gap-1 text-[10px] tabular-nums text-muted-foreground`,children:[l(me,{className:`h-3 w-3`}),e.cpuPercent,`%`,l(z,{className:`h-3 w-3`}),e.memoryPercent,`%`]}):l(`span`,{className:`text-[10px] text-destructive`,children:i(`cluster.offline`,`offline`)})]})}var $=3,hn=7e3;function gn(e){return[...e].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1)}function _n(e){return e.isHub?{}:{nodeId:e.id}}function vn(e){return e.updateState===`staging`||e.updateState===`pending-restart`||e.pendingVersion!==null?!0:!e.updateAvailable}async function yn(e,t){let n=_n(e),r=`no answer`;for(let i=1;i<=$;i+=1)try{let r=await t.readStatus(n);return vn(r)?{nodeId:e.id,nodeName:e.name,outcome:`applied`,detail:`Connection dropped, and the node confirms the update landed (state ${r.updateState}, running ${r.runningVersion??`unknown`}).`}:{nodeId:e.id,nodeName:e.name,outcome:`failed`,detail:`Connection dropped and the node came back unchanged (still ${r.runningVersion??`unknown`}, update still available). Nothing was staged.`}}catch(e){r=e instanceof Error?e.message:String(e),i<$&&await t.wait(hn)}return{nodeId:e.id,nodeName:e.name,outcome:`unconfirmed`,detail:`Connection dropped and the node could not be confirmed after ${$} attempts (${r}). It may be restarting — re-check this node.`}}async function bn(e,t){let n=[];for(let r of gn(e))try{let e=await t.apply(_n(r));n.push({nodeId:r.id,nodeName:r.name,outcome:e.accepted?`applied`:`refused`,detail:e.message})}catch{n.push(await yn(r,t))}return n}n();function xn(){let{nodes:e,isLoading:t}=f(),n=a(()=>e??[],[e]);return{nodes:n,isLoading:t&&n.length===0}}var Sn={applied:`border-emerald-500/40 bg-emerald-500/10 text-emerald-500`,refused:`border-amber-500/40 bg-amber-500/10 text-amber-500`,failed:`border-red-500/40 bg-red-500/10 text-red-500`,unconfirmed:`border-amber-500/40 bg-amber-500/10 text-amber-500`};function Cn(){let{t}=I(),n=j(),{nodes:i,isLoading:o}=xn(),{selection:s,selectNode:u}=Ce(i),f=s.node,m=a(()=>i.filter(e=>e.isOnline),[i]),h=m.length,g=i.filter(e=>!e.isOnline).length,_=p(),v=d(),[y,b]=c(!1),[x,S]=c([]),C=e(async()=>{let e=m.map(e=>({id:e.id,name:e.name,isHub:e.isHub}));if(await n({title:t(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:t(`serverManagement.confirmUpdateAllBody`,`Update and restart every online node, agents first, hub last. Up-to-date nodes are skipped; this page reconnects when the hub comes back.`),confirmLabel:t(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){b(!0),S([]);try{S(await bn(e,{apply:e=>_.mutateAsync(e),readStatus:e=>v.trpcClient.serverManagement.getServerPackageStatus.query(e),wait:e=>new Promise(t=>setTimeout(t,e))}))}finally{b(!1)}}},[_,n,m,v,t]);return r(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[r(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[r(`div`,{className:`flex items-center gap-2`,children:[h>0&&r(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[h,` online`]}),g>0&&r(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[g,` offline`]})]}),l(`div`,{className:`flex items-center gap-2`,children:h>1&&r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,disabled:y,title:t(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void C(),children:[y?l(L,{className:`h-3.5 w-3.5 animate-spin`}):l(R,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateAll`,`Update all nodes`)]})})]}),x.length>0&&l(`ul`,{"aria-label":`update-all-report`,className:`flex flex-col gap-1 text-xs`,children:x.map(e=>r(`li`,{"data-outcome":e.outcome,className:`rounded border px-2 py-1 ${Sn[e.outcome]}`,children:[l(`span`,{className:`font-medium`,children:e.nodeName}),l(`span`,{className:`mx-1 uppercase tracking-wide`,children:e.outcome}),l(`span`,{className:`opacity-80`,children:e.detail})]},e.nodeId))}),o?l(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):r(`div`,{className:`flex-1 overflow-auto flex flex-col gap-3`,children:[l(Se,{staleNodeId:s.staleNodeId,shownNodeName:f?.name??``}),l(pn,{nodes:i,selected:f,onSelect:u})]})]})}export{Cn as ClusterPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-BOHd-BQW.js";import{$n as u,Ln as d,Qo as f,Vo as p,Xo as m,Yo as h,Zo as g,ar as _,cr as v,ds as y,er as b,ir as x,lr as S,nr as C,or as w,rr as T,sn as E,sr as D,tr as O,ur as k}from"./src-BmPEyOJ9.js";import{a as A,c as j,d as M,l as N,n as P,o as F,s as ee,t as te,u as ne}from"./location-owned-usage-RXMicHPP.js";import{t as I}from"./circle-slash-IyU_gVDG.js";import{t as L}from"./circle-x-D4XhwphR.js";import{t as R}from"./clock-Czi0ZaPo.js";import{t as z}from"./download-DlHJFiX_.js";import{n as re,t as B}from"./format-size-DoXWOpar.js";import{t as ie}from"./hard-drive-C4Gwi3hi.js";import{t as ae}from"./pencil-GpDj1Q2p.js";import{t as oe}from"./play-JJtA4mLK.js";import{t as se}from"./plus-Ce-u1cy0.js";import{t as V}from"./rotate-cw-CLl0fQTC.js";import{F as ce,J as H,K as le,L as U,o as W,r as G,w as K,z as ue}from"./index-g356Z7K8.js";import{t as q}from"./AdminPage-CCD07UMs.js";import{i as de}from"./authed-media-DOXm0tcZ.js";import{t as fe}from"./AdminTabs-KbDahb5g.js";var pe=H(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),me=H(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m4.9 4.9 14.2 14.2`,key:`1m5liu`}]]),he=H(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),ge=H(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]);t();function _e(){let e=a(),t=E(),{data:i,isLoading:c,isError:l}=f({}),u=g(),d=r(()=>u.data??[],[u.data]),{data:_}=p({},{refetchOnWindowFocus:!1}),v=r(()=>te(i??[],_?.locations),[i,_?.locations]),{data:b}=m({},{refetchOnWindowFocus:!1}),x=r(()=>A(b),[b]),[S,C]=o(null),[w,T]=o(null),D=h({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),O=y({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),k=async(e,n)=>{N(n)&&!await t({title:`Disable "${e.displayName}"?`,message:`${j(n).consequence}\n\nNothing is deleted — set the location back to Read-only or Active to bring its footage back.`,confirmLabel:`Disable`,variant:`danger`})||O.mutate(ee(e,{mode:n}))},M=async e=>{if(await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`}))try{await D.mutateAsync({id:e.id})}catch(n){await t({title:`Delete anyway?`,message:`${n instanceof Error?n.message:String(n)}\n\nForcing the delete removes the record only. Anything still on that location becomes unreachable — index rows naming it stop resolving, and playback of those segments goes silently black rather than erroring.`,confirmLabel:`Force delete`,variant:`danger`})&&D.mutate({id:e.id,force:!0})}},I=r(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),L=c||u.isLoading,R=l||u.isError;return n(q,{children:[L&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),R&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!L&&!R&&n(`div`,{className:`space-y-3`,children:[d.length===0&&s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),d.map(e=>s(P,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:I.get(e.id)??[],onAdd:e=>C(e),onEdit:e=>T(e),onDelete:e=>{M(e)},ownedBytesById:v,drainById:x,onSetMode:(e,t)=>{k(e,t)}},e.id))]}),S!==null&&s(ne,{initialType:S,onClose:()=>C(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C(null)}}),w!==null&&s(F,{location:w,onClose:()=>T(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),T(null)}})]})}t();var ve=[[`backup`,`listDestinations`]],ye=[`backup`,`listArchives`];function be({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),u=E(),{data:d,isLoading:f,isError:p}=T({destinationId:t}),m=d??[],h=b({onSuccess:()=>{l.invalidateQueries({queryKey:[[...ye]]}),l.invalidateQueries({queryKey:ve})}}),g=e(async e=>{await u({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${B(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&h.mutate({destinationId:t,backupId:e.id})},[u,t,h]),[_,v]=o(null),y=e(async e=>{v(e.id);try{let n=await de(xe(t,e.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.label??e.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{v(null)}},[t]),x=r(()=>[...m].toSorted((e,t)=>t.createdAt-e.createdAt),[m]);return f?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):p?s(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):x.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):s(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:x.map(e=>n(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:Se(e.createdAt)}),s(`td`,{className:`px-3 py-1.5 text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),s(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:e.locations.join(`, `)}),s(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:B(e.sizeBytes)}),s(`td`,{className:`px-3 py-1.5`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{y(e)},disabled:_===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[_===e.id?s(K,{className:`h-3 w-3 animate-spin`}):s(z,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(`button`,{onClick:()=>c({destinationId:t,archiveId:e.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[s(V,{className:`h-3 w-3`}),`Restore`]}),s(`button`,{onClick:()=>{g(e)},disabled:h.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:h.isPending?s(K,{className:`h-3 w-3 animate-spin`}):s(W,{className:`h-3 w-3`})})]})})]},e.id))})]})})}function xe(e,t){return l(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function Se(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var J=[[`backup`,`listSchedules`]];function Ce({onEdit:e,onOpenRestoreWizard:t}){let{data:i,isLoading:a,isError:c}=w(),l=i??[],u=x().data??[],d=r(()=>{let e=new Map;for(let t of u)e.set(t.id,t);return e},[u]),[f,p]=o(null),m=e=>{p(t=>t===e?null:e)};return a?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading backup entries…`}):c?s(`div`,{className:`text-xs text-danger`,children:`Failed to load backup entries`}):l.length===0?s(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:s(`p`,{className:`text-xs text-foreground-subtle`,children:`No backup entries yet. Create one to schedule backups across one or more storage locations.`})}):s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[820px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[s(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Entry`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Locations`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-24`,children:`Retention`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-48`,children:`Schedule`}),s(`th`,{className:`text-right px-3 py-2 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:l.map(n=>s(we,{row:n,destById:d,isOpen:f===n.id,onToggle:()=>m(n.id),onEdit:()=>e(n),...t?{onOpenRestoreWizard:t}:{}},n.id))})]})})}function we({row:t,destById:l,isOpen:u,onToggle:d,onEdit:f,onOpenRestoreWizard:p}){let m=a(),h=E(),g=k({onSuccess:()=>{m.invalidateQueries({queryKey:J})}}),_=O({onSuccess:()=>{m.invalidateQueries({queryKey:J})}}),v=S({onMutate:()=>{m.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{m.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),m.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),m.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),[y,b]=o(String(t.retentionCount));c(()=>{b(String(t.retentionCount))},[t.retentionCount]);let x=r(()=>({id:t.id,label:t.label,cron:t.cron,locationIds:[...t.locationIds],retentionCount:t.retentionCount,...t.dataSources?{dataSources:[...t.dataSources]}:{}}),[t]),C=e(e=>{g.mutate({...x,enabled:e})},[g,x]),w=e(()=>{let e=Number.parseInt(y,10);if(Number.isNaN(e)||e<1){b(String(t.retentionCount));return}e!==t.retentionCount&&g.mutate({...x,enabled:t.enabled,retentionCount:e})},[g,x,y,t.retentionCount,t.enabled]),T=e(()=>{t.locationIds.length!==0&&v.mutate({destinations:[...t.locationIds],...t.dataSources&&t.dataSources.length>0?{locations:[...t.dataSources]}:{},label:t.label,retentionCount:t.retentionCount})},[v,t]),D=e(async()=>{await h({title:`Delete backup entry?`,message:`"${t.label||t.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&_.mutate({id:t.id})},[h,_,t.id,t.label]),A=t.cron.trim().length>0,j=g.isPending||_.isPending;return n(i,{children:[n(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[s(`td`,{className:`px-2 py-2`,children:s(`button`,{onClick:d,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:u?`Hide archives`:`Show archives`,children:s(u?ue:U,{className:`h-3.5 w-3.5`})})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:f,className:`text-left hover:underline focus:outline-none`,children:[s(`div`,{className:`text-foreground font-medium`,children:t.label||`(unnamed)`}),t.lastRunAt!==void 0&&n(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`last run `,new Date(t.lastRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:s(`label`,{className:`inline-flex items-center cursor-pointer`,children:s(`input`,{type:`checkbox`,className:`accent-primary`,checked:t.enabled,disabled:j,onChange:e=>C(e.target.checked)})})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex flex-wrap gap-1`,children:[t.locationIds.length===0&&s(`span`,{className:`text-[11px] text-danger italic`,children:`No locations`}),t.locationIds.map(e=>s(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:l.get(e)?.displayName??e},e))]})}),s(`td`,{className:`px-3 py-2`,children:s(`input`,{type:`number`,min:1,max:1e3,value:y,disabled:j,onChange:e=>b(e.target.value),onBlur:w,onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&b(String(t.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:f,className:`group flex flex-col items-start gap-0.5 text-left`,title:`Edit schedule`,children:[n(`span`,{className:`inline-flex items-center gap-1`,children:[s(he,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),s(`span`,{className:`font-mono text-[11px] text-foreground`,children:A?t.cron:`Manual`})]}),A&&t.nextRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(t.nextRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex items-center justify-end gap-1.5`,children:[n(`button`,{onClick:T,disabled:v.isPending||t.locationIds.length===0,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,title:`Run this entry now`,children:[v.isPending?s(K,{className:`h-3 w-3 animate-spin`}):s(oe,{className:`h-3 w-3`}),`Run now`]}),s(`button`,{onClick:f,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-foreground hover:bg-primary/5`,title:`Edit entry`,children:s(ae,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>{D()},disabled:j,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-danger hover:border-danger/40 disabled:opacity-50`,title:`Delete entry`,children:s(W,{className:`h-3 w-3`})})]})})]}),u&&s(`tr`,{className:`border-t border-border bg-background/30`,children:n(`td`,{colSpan:7,className:`px-4 py-3 space-y-4`,children:[t.locationIds.length===0&&s(`p`,{className:`text-xs text-foreground-subtle italic`,children:`This entry has no locations selected.`}),t.locationIds.map(e=>n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:l.get(e)?.displayName??e}),s(be,{destinationId:e,restoreSupported:l.get(e)?.restoreSupported??!0,...p?{onOpenRestoreWizard:p}:{}})]},e))]})})]})}t();var Y=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function Te(e){let t=e.trim();for(let e of Y)if(e.cron===t)return e.id;return`custom`}function Ee({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=Te(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=ke(e,250),f=D({cron:d,count:r},{enabled:d.trim().length>0}),p=f.data??null,m=e=>{u(!1),t(e.cron)},h=l||a===`custom`;return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),n(`div`,{className:`flex flex-wrap gap-1.5`,children:[Y.map(e=>s(`button`,{type:`button`,onClick:()=>m(e),disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!l&&a===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),s(`button`,{type:`button`,onClick:()=>{u(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(h?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),h&&n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),s(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:i,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,s(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),s(De,{cron:d,preview:p,loading:f.isFetching})]})}function De({cron:e,preview:t,loading:r}){return r&&t===null?n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[s(K,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?s(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),s(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>n(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[s(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),s(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:Oe(e)})]},`${e}-${t}`))})]}):s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function Oe(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function ke(e,t){let[n,i]=o(e),a=r(()=>e,[e]);return c(()=>{let e=setTimeout(()=>i(a),t);return()=>clearTimeout(e)},[a,t]),n}t();var Ae=[[`backup`,`listSchedules`]];function je({entry:e,onClose:t,onSaved:i}){let c=a(),l=x(),u=l.data??[],[d,f]=o(e?.label??``),[p,m]=o(e?.cron??`0 3 * * *`),[h,g]=o(e?.enabled??!0),[_,v]=o(String(e?.retentionCount??7)),[y,b]=o(new Set(e?.locationIds??[])),S=k({onSuccess:()=>{c.invalidateQueries({queryKey:Ae}),i()}}),C=e=>{b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},w=Number.parseInt(_,10),T=r(()=>d.trim().length>0&&y.size>0&&!Number.isNaN(w)&&w>=1&&w<=1e3,[d,y,w]),E=()=>{T&&S.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:h,locationIds:Array.from(y),retentionCount:w})},D=S.error instanceof Error?S.error.message:null;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:n(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3 sticky top-0 bg-surface`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e?`Edit backup entry`:`New backup entry`}),s(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:s(G,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-4`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Name`}),s(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Nightly offsite`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1.5`,children:[n(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:[`Locations (`,y.size,` selected)`]}),l.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!l.isLoading&&u.length===0&&s(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),u.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-52 overflow-y-auto`,children:u.map(e=>n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:y.has(e.id),onChange:()=>C(e.id),className:`accent-primary`}),s(`span`,{className:`text-foreground`,children:e.displayName})]}),n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-surface border border-border rounded px-1.5 py-0.5`,children:e.kind}),s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]},e.id))})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Retention (archives kept)`}),s(`input`,{type:`number`,min:1,max:1e3,value:_,onChange:e=>v(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Enabled`}),n(`label`,{className:`inline-flex items-center gap-2 py-1.5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`accent-primary`}),s(`span`,{className:`text-xs text-foreground-subtle`,children:`Run on schedule`})]})]})]}),n(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Schedule`}),s(Ee,{value:p,onChange:m,disabled:S.isPending})]}),D&&s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:D})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3 sticky bottom-0 bg-surface`,children:[s(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),n(`button`,{onClick:E,disabled:!T||S.isPending,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[S.isPending&&s(K,{className:`h-3.5 w-3.5 animate-spin`}),e?`Save`:`Create entry`]})]})]})})}t();var Me=2e3,Ne=5e3;function X(e){return e.state===`queued`||e.state===`running`}function Pe(e){if(e.state===`queued`)return{title:`Cancel queued backup run?`,message:`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`,confirmLabel:`Cancel run`,variant:`warning`};let t=e.completedDestinationIds.length;return{title:`Stop this backup run?`,message:`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. ${t>0?`${t===1?`The 1 destination`:`The ${t} destinations`} that already completed KEEP${t===1?`S`:``} the archive.`:`No destination has completed yet, so nothing will be kept.`}`,confirmLabel:`Stop run`,variant:`danger`}}function Fe(){let t=E(),[n,r]=o(null),i=_(void 0,{refetchInterval:e=>(e.state.data??[]).some(X)?Me:Ne}),a=u({onSettled:()=>{r(null),i.refetch()}}),c=e(async e=>{await t(Pe(e))&&(r(e.id),a.mutate({runId:e.id}))},[t,a]);return s(Ie,{queryState:i.isError?`error`:i.data===void 0?`pending`:`ready`,runs:i.data??[],cancelingId:n,onCancelRequest:e=>{c(e)},now:Date.now()})}function Ie({queryState:e,runs:t,cancelingId:r,onCancelRequest:i,now:a}){let o=e===`ready`&&t.some(X),c=t.filter(e=>e.state===`running`),l=t.filter(e=>e.state===`queued`),u=t.filter(e=>!X(e)),d=[...c,...l,...u];return n(`section`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[s(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Runs`}),o&&n(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:`A backup run is in progress`,children:[s(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),`live`]}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:`One run executes at a time — queued runs wait in line.`})]}),e===`pending`&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:`Checking for backup runs…`}),e===`error`&&s(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:`Could not read backup runs — the orchestrator did not answer.`}),e===`ready`&&t.length===0&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`}),e===`ready`&&t.length>0&&s(`div`,{className:`overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[720px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Run`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`State`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Progress`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Destinations`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Timing`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:`Actions`})]})}),s(`tbody`,{children:d.map(e=>s(Le,{run:e,canceling:r===e.id,onCancelRequest:i,now:a},e.id))})]})})]})}function Le({run:e,canceling:t,onCancelRequest:r,now:i}){let a=X(e);return n(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[n(`td`,{className:`px-3 py-2`,children:[s(`div`,{className:`text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`manual`})}),s(`div`,{className:`text-[10px] text-foreground-subtle font-mono`,title:e.id,children:e.id.slice(0,8)})]}),n(`td`,{className:`px-3 py-2`,children:[s(Re,{run:e}),e.state===`failed`&&e.error!==void 0&&s(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:e.error,children:e.error})]}),s(`td`,{className:`px-3 py-2`,children:s(ze,{run:e})}),s(`td`,{className:`px-3 py-2`,children:s(Be,{run:e})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:s(Ve,{run:e,now:i})}),s(`td`,{className:`px-3 py-2`,children:s(`div`,{className:`flex justify-end`,children:a&&n(`button`,{onClick:()=>r(e),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:e.state===`queued`?`Remove this run from the queue before it starts`:`Stop this run — the half-written archive is discarded`,children:[t?s(K,{className:`h-3 w-3 animate-spin`}):s(me,{className:`h-3 w-3`}),e.state===`queued`?`Cancel`:`Stop`]})})})]})}function Re({run:e}){switch(e.state){case`queued`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[s(R,{className:`h-3 w-3`}),`Queued`]});case`running`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:[s(K,{className:`h-3 w-3 animate-spin`}),e.phase===`uploading`?`Uploading`:`Building archive`]});case`succeeded`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-success/10 px-1.5 py-0.5 text-[10px] font-medium text-success`,children:[s(ce,{className:`h-3 w-3`}),`Succeeded`]});case`failed`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 text-[10px] font-medium text-danger`,children:[s(L,{className:`h-3 w-3`}),`Failed`]});case`cancelled`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300`,title:`Stopped before completing every destination — not a success`,children:[s(I,{className:`h-3 w-3`}),`Stopped`]})}}function ze({run:e}){if(e.state===`queued`)return s(`span`,{className:`text-foreground-subtle`,children:e.queuePosition===void 0?s(`span`,{className:`italic`,children:`waiting its turn`}):n(`span`,{className:`inline-flex items-center gap-1`,children:[s(`span`,{className:e.queuePosition===1?`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`:`rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium`,children:He(e.queuePosition)}),`in line`]})});if(e.state===`running`&&e.phase===`building`)return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(re,{className:`h-3 w-3 text-primary`}),s(`span`,{className:`tabular-nums font-medium animate-pulse`,children:B(e.stagedBytes)}),s(`span`,{className:`text-foreground-subtle`,children:`staged so far`})]});if(e.state===`running`){let t=e.archiveSizeBytes;return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(ge,{className:`h-3 w-3 text-primary`}),n(`span`,{className:`tabular-nums font-medium`,children:[B(e.uploadedBytes),t===void 0?``:` / ${B(t)}`]}),s(`span`,{className:`text-foreground-subtle`,children:`to current destination`})]})}let t=e.archiveSizeBytes??(e.stagedBytes>0?e.stagedBytes:void 0);return t===void 0?s(`span`,{className:`text-foreground-subtle italic`,children:`—`}):n(`span`,{className:`tabular-nums text-foreground`,children:[B(t),` archive`]})}function Be({run:e}){let t=e.destinationIds.length,r=e.completedDestinationIds.length,i=e.failedDestinationIds.length;return t===0?s(`span`,{className:`text-foreground-subtle italic`,children:`not resolved yet`}):n(`div`,{className:`flex flex-col gap-0.5`,children:[n(`span`,{className:`text-foreground-subtle`,title:e.destinationIds.join(`, `),children:[t,` target`,t===1?``:`s`]}),n(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[r>0&&n(`span`,{className:`text-success`,title:`Kept their archive: ${e.completedDestinationIds.join(`, `)}`,children:[`✓ `,r,` completed`]}),i>0&&n(`span`,{className:`text-danger`,title:`Failed: ${e.failedDestinationIds.join(`, `)}`,children:[`✗ `,i,` failed`]})]})]})}function Ve({run:e,now:t}){return e.state===`queued`?n(`span`,{children:[`queued `,Z(t-e.requestedAt),` ago`]}):e.startedAt===void 0?s(`span`,{children:`—`}):e.finishedAt===void 0?n(`span`,{children:[`running for `,Z(t-e.startedAt)]}):n(`div`,{className:`flex flex-col gap-0.5`,children:[s(`span`,{children:Q(e.finishedAt)}),n(`span`,{className:`text-[10px]`,children:[`took `,Z(e.finishedAt-e.startedAt)]})]})}function He(e){if(e<=1)return`next`;let t=e%100;if(t>=11&&t<=13)return`${e}th`;switch(e%10){case 1:return`${e}st`;case 2:return`${e}nd`;case 3:return`${e}rd`;default:return`${e}th`}}function Z(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${String(n%60).padStart(2,`0`)}m`}function Q(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}t();var Ue=[[`backup`,`list`]];function We({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,f]=o(e&&t?2:1),[p,m]=o(e),[h,g]=o(t),[_,y]=o(new Set),{data:b}=x(),S=b??[],{data:w,isLoading:E}=T({destinationId:p??``},{enabled:!!p}),D=w??[];c(()=>{if(p!==void 0)return;let e=S.filter(e=>e.restoreSupported);e.length===1&&m(e[0].id)},[p,S]);let{data:O}=C({destinationId:p??``,backupId:h??``},{enabled:!!p&&!!h}),k=r(()=>O?.locations??[],[O]);c(()=>{k.length!==0&&y(e=>e.size===0?new Set(k):e)},[k]);let A=v({onSuccess:()=>{u.invalidateQueries({queryKey:Ue}),l(),i()}}),j=e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=!!p&&!!h,N=_.size>0,P=M&&N&&!A.isPending,F=()=>{!p||!h||A.mutate({destinationId:p,backupId:h,locations:[..._]})};return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`div`,{className:`space-y-0.5`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,d,` of 3 —`,` `,d===1?`pick source`:d===2?`pick locations`:`confirm`]})]}),s(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:s(G,{className:`h-4 w-4`})})]}),d===1&&s(Ge,{destinations:S,destinationId:p,onPickDestination:e=>{m(e),g(void 0),y(new Set)},archives:D,archivesLoading:E,archiveId:h,onPickArchive:g}),d===2&&s(Ke,{locations:k,picked:_,onToggle:j}),d===3&&s(qe,{destinationName:S.find(e=>e.id===p)?.displayName??p??``,archive:D.find(e=>e.id===h),picked:[..._]}),n(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[s(`div`,{children:d>1&&n(`button`,{onClick:()=>f(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[s(le,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),d<3?n(`button`,{disabled:d===1&&!M||d===2&&!N,onClick:()=>f(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,s(pe,{className:`h-3 w-3`})]}):n(`button`,{onClick:F,disabled:!P,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[A.isPending?s(K,{className:`h-3.5 w-3.5 animate-spin`}):s(V,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Ge({destinations:e,destinationId:t,onPickDestination:r,archives:i,archivesLoading:a,archiveId:o,onPickArchive:c}){let l=e.filter(e=>e.restoreSupported);return n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),n(`select`,{value:t??``,onChange:e=>r(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[s(`option`,{value:``,disabled:!0,children:`Select destination…`}),l.map(e=>n(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:B(e.sizeBytes)})]},e.id)})})]})]})}function Ke({locations:e,picked:t,onToggle:r}){return e.length===0?s(`div`,{className:`p-4`,children:s(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):n(`div`,{className:`p-4 space-y-3`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>n(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>r(e),className:`accent-primary`}),s(`span`,{className:`font-mono text-foreground`,children:e}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ye(e)})]},e))})]})]})}function qe({destinationName:e,archive:t,picked:r}){return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),n(`dl`,{className:`space-y-1.5`,children:[s($,{term:`Destination`,value:e}),s($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&s($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${B(t.sizeBytes)}`}),s($,{term:`Locations`,value:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function $({term:e,value:t}){return n(`div`,{className:`flex justify-between gap-3`,children:[s(`dt`,{className:`text-foreground-subtle`,children:e}),s(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Je={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ye(e){return Je[e]??``}t();function Xe(){let e=E(),t=d(),[r,i]=o(null),[a,c]=o(!1),[l,u]=o(!1),[f,p]=o(void 0),m=async()=>{await e({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&t.mutate({confirm:!0})};return n(q,{children:[n(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[n(`button`,{onClick:()=>c(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[s(V,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(`button`,{onClick:()=>p(null),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[s(se,{className:`h-3.5 w-3.5`}),`New entry`]})]}),l&&s(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(V,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(`button`,{onClick:()=>{m()},disabled:t.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[t.isPending?s(K,{className:`h-3.5 w-3.5 animate-spin`}):s(V,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(Fe,{}),s(Ce,{onEdit:e=>p(e),onOpenRestoreWizard:e=>i(e)}),f!==void 0&&s(je,{entry:f,onClose:()=>p(void 0),onSaved:()=>p(void 0)}),(r||a)&&s(We,{...r?{initialDestinationId:r.destinationId,initialArchiveId:r.archiveId}:{},onClose:()=>{i(null),c(!1)},onScheduled:()=>u(!0)})]})}function Ze(){return s(`div`,{className:`flex flex-col p-4`,children:s(fe,{tabs:[{id:`storage`,label:`Storage`,icon:ie,content:s(_e,{})},{id:`backup`,label:`Backup`,icon:M,content:s(Xe,{})}]})})}export{Ze as DataPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as u}from"./player-overlays-BpDQQutT.js";import{Ci as d,Ct as f,Dt as p,Et as m,Ft as h,It as g,Jr as _,Mt as v,Nt as y,Ot as b,Si as x,Tt as S,_i as C,bi as w,fi as T,gi as E,hi as D,kt as O,mi as k,pi as A,sn as j,tc as M,vi as N,wi as P,xi as F,yi as I}from"./src-C7ah6wxj.js";import{Kt as L}from"./src-C2j9sEfa.js";import{a as R,i as z,n as B,o as V,r as H,t as U}from"./face-bbox-292APeBO.js";import{a as ee,c as W,f as G,i as te,l as ne,m as re,n as K,o as ie,p as ae,r as oe,s as se,t as ce,u as le}from"./debounced-invalidate-BW0isPZ1.js";import{t as ue}from"./pencil-BHUkVqws.js";import{t as q}from"./plus-B_s-mxBM.js";import{t as de}from"./refresh-cw-BGLHgQjL.js";import{t as fe}from"./rotate-cw-DKJX5UTY.js";import{t as pe}from"./square-check-big-BzavY7zY.js";import{t as me}from"./square-D82yd7G6.js";import{t as J}from"./undo-2-By8IwmwV.js";import{t as Y}from"./user-round-Ccl_m9QC.js";import{B as he,J as ge,L as _e,a as ve,c as ye,h as be,o as xe,r as X,w as Z,z as Se}from"./index-CG76NtTM.js";import{t as Ce}from"./AdminPage-CCD07UMs.js";import{i as we,t as Te}from"./authed-media-Cvs7l9rz.js";var Ee=ge(`image-plus`,[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]);n();var De=`pipeline-analytics`,Oe=`photo.analyze`,ke=`photo.enroll`,Ae=`photo.discard`,je=18*1024*1024;function Me(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Ne(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Pe(e){if(!Me(e))return null;let t=$(e,`x`),n=$(e,`y`),r=$(e,`width`),i=$(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function Fe(e){if(!Me(e))return null;let t=$(e,`detectionShortSidePx`),n=$(e,`score`);if(t===null||n===null)return null;let r=$(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function Ie(e){if(!Me(e))return null;let t=$(e,`faceIndex`),n=$(e,`score`),r=Ne(e,`enrollable`),i=Pe(e.bbox),a=Fe(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Q(e,`refusedReason`),s=Q(e,`alignedCropBase64`),c=Q(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function Le(e){if(!Me(e))return null;let t=Q(e,`sessionId`),n=Q(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=Ie(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function Re(e){if(!Me(e))return null;let t=Q(e,`sampleId`),n=Q(e,`identityId`),r=Q(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function ze(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function Be(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function Ve(e,t,n){let r=[];for(let i of t){if(!i.enrollable)continue;let t=n[i.faceIndex];t!==void 0&&r.push({sessionId:e,faceIndex:i.faceIndex,identityId:t})}return r}function He(e){switch(e){case`no-embedding`:return`Too small or too indistinct for the recognizer to measure — try a photo where this face is larger.`;case`no-model-id`:return`The recognizer did not report which model it used, so this face cannot be enrolled safely.`;case`no-aligned-crop`:return`The recognizer produced no aligned crop for this face, so there is nothing to store.`;case`magnitude`:return`Refused by the quality gate: the features look degenerate, and a sample like this matches everybody.`;default:return`This face is not usable as a sample.`}}function Ue(e,t){let n=[],r=[];for(let i of e)i.size>t.maxBytes?n.push(i.name):r.push(i);return{accepted:r.slice(0,t.maxCount),oversize:n,overflow:r.slice(t.maxCount).map(e=>e.name)}}async function We(e,t,n){let r=Array(e.length),i=e.map((e,t)=>({item:e,index:t})),a=0,o=async()=>{for(;;){let e=i[a];if(a+=1,e===void 0)return;r[e.index]=await n(e.item,e.index)}},s=Array.from({length:Math.max(1,Math.min(t,e.length))},()=>o());return await Promise.all(s),r}function Ge(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function Ke(e,t){return`${e}:${t}`}function qe(e,t,n,r){let i=ze(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function Je(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=Be(r.analysis.faces,t[r.photoIndex]??{}));return n}var Ye=`__new__`;function Xe(e,t,n){let r=[];for(let i of e){if(i.analysis===void 0)continue;let e=t[i.photoIndex]??{};for(let t of i.analysis.faces){if(!t.enrollable||e[t.faceIndex]!==`__new__`)continue;let a=(n[Ke(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:`${i.filename}: face ${t.faceIndex+1} is set to a new person but has no name.`};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function Ze(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=Number(i),o={};for(let[r,i]of Object.entries(a)){let a=Number(r);if(i!==`__new__`){o[a]=i;continue}let s=n[(t[Ke(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function Qe(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=Ve(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function $e(e){return/expired/i.test(e)}function et(e){return e instanceof Error?e.message:String(e)}async function tt(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>`${r.get(e)?.filename??`photo ${e+1}`}, face ${t+1}`;for(let l of Qe(e,t)){let e=i[l.photoIndex],t=e===void 0?l.request:{...l.request,sessionId:e.sessionId};try{let e=await n.enroll(t);o+=1,s=e.modelId}catch(t){let u=et(t);if(!$e(u)||e!==void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let d=r.get(l.photoIndex);if(d===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let f;try{f=await n.reanalyze(d)}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired and re-analysing failed (${et(e)})`);continue}if(i[l.photoIndex]=f,f.faces.find(e=>e.faceIndex===l.request.faceIndex&&e.enrollable)===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired, and re-analysing no longer finds this face — assign it again from the fresh result`);continue}try{let e=await n.enroll({...l.request,sessionId:f.sessionId});o+=1,s=e.modelId}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${et(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var nt=[[`faceGallery`]],rt=``;function it(e){return new Promise((t,n)=>{let r=new FileReader;r.addEventListener(`error`,()=>n(Error(`the file could not be read`)),{once:!0}),r.addEventListener(`load`,()=>{let e=r.result;if(typeof e!=`string`){n(Error(`the file could not be read`));return}let i=e.indexOf(`,`);t(i>=0?e.slice(i+1):e)},{once:!0}),r.readAsDataURL(e)})}function at(e){return e instanceof Error?e.message:String(e)}function ot({face:e,identities:t,value:n,onChange:o,disabled:s}){let l=i(()=>[{value:rt,label:`Ignore this face`},...t.map(e=>({value:e.id,label:e.name})),{value:Ye,label:`+ New person…`}],[t]);return r(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[c(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:e.alignedCropBase64?c(`img`,{src:`data:image/jpeg;base64,${e.alignedCropBase64}`,alt:`Face ${e.faceIndex+1}`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Y,{className:`h-8 w-8`})})}),e.enrollable?r(a,{children:[c(v,{options:l,value:n,disabled:s,onChange:e=>o(e.target.value),"aria-label":`Assign face ${e.faceIndex+1}`}),r(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(e.quality.detectionShortSidePx),` px`,e.modelId?` · ${e.modelId}`:``]})]}):r(`div`,{className:`space-y-1`,children:[c(h,{variant:`warning`,className:`text-[10px]`,children:`Not usable`}),c(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:He(e.refusedReason)})]})]})}function st({photo:e,identities:t,draft:n,newNames:i,disabled:a,onAssign:o,onNameChange:s,onRetry:l}){let u=e.analysis?.faces??[],d=n[e.photoIndex]??{};return r(`div`,{className:`space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.filename}),e.status===`analyzing`||e.status===`queued`?r(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[c(Z,{className:`h-3 w-3 animate-spin`}),` analysing…`]}):null,e.status===`analyzed`&&e.analysis!==void 0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[u.length,` face`,u.length===1?``:`s`,` · analysed on`,` `,e.analysis.ranOnNodeId]}),e.status===`failed`&&r(g,{variant:`secondary`,size:`sm`,disabled:a,onClick:l,children:[c(fe,{className:`h-3 w-3`}),` Retry`]})]}),e.status===`failed`&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[c(ve,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),r(`span`,{children:[`This photo could not be analysed: `,e.error??`unknown error`,`. The other photos are unaffected.`]})]}),e.status===`analyzed`&&u.length===0&&c(`p`,{className:`text-xs text-foreground-subtle`,children:`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`}),u.length>0&&c(`div`,{className:`grid grid-cols-3 gap-3 sm:grid-cols-4 md:grid-cols-5`,children:u.map(e=>c(ot,{face:e,identities:t,value:d[e.faceIndex]??rt,disabled:a,onChange:t=>o(e.faceIndex,t)},e.faceIndex))}),u.filter(e=>d[e.faceIndex]===Ye).map(t=>r(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:[`Face `,t.faceIndex+1]}),c(`input`,{className:`h-7 flex-1 rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:`New person name… (type the same name under another face to reuse it)`,value:i[Ke(e.photoIndex,t.faceIndex)]??``,onChange:e=>s(t.faceIndex,e.target.value)})]},t.faceIndex))]})}function ct({open:n,onOpenChange:a}){let l=u(),d=o(),h=t(null),{data:_}=C(),v=A(),[y,x]=s([]),[w,T]=s(!1),[E,D]=s(null),[k,j]=s({}),[M,N]=s({}),[P,F]=s(null),I=i(()=>(_??[]).map(e=>({id:e.id,name:e.name})),[_]),L=y.some(e=>e.status===`queued`||e.status===`analyzing`),R=L||w,z=e(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&l.trpcClient.addons.custom.mutate({addonId:De,action:Ae,input:{sessionId:e}}).catch(()=>void 0)}},[l]),B=e(()=>{x([]),j({}),N({}),D(null),F(null),h.current&&(h.current.value=``)},[]),V=e(()=>{z(y),B(),a(!1)},[z,a,y,B]),H=e(async e=>{let t=Le(await l.trpcClient.addons.custom.mutate({addonId:De,action:Oe,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[l]),U=e(async e=>{x(t=>Ge(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await H(e);x(n=>Ge(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){x(n=>Ge(n,e.photoIndex,{status:`failed`,error:at(t)}))}},[H]),ee=e(async e=>{if(e.length===0)return;z(y),B();let t=Ue(e,{maxCount:12,maxBytes:je}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(je/(1024*1024))} MB limit and skipped: ${t.oversize.join(`, `)}.`),t.overflow.length>0&&n.push(`A batch holds at most 12 photos — not analysed: ${t.overflow.join(`, `)}. Enrol them in a second round.`),n.length>0&&D(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await it(e),status:`queued`})))}catch(e){D(at(e));return}x(r),await We(r,2,e=>U(e))},[z,y,B,U]),W=Je(y,k),G=e(async()=>{T(!0),D(null),F(null);try{let e=Xe(y,k,M);if(e.kind===`error`){D(e.message);return}let t={};for(let n of e.names)t[n]=(await v.mutateAsync({name:n})).id;let n=await tt(y,Ze(k,M,t),{enroll:async e=>{let t=Re(await l.trpcClient.addons.custom.mutate({addonId:De,action:ke,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>H(e)});Object.keys(n.refreshedAnalyses).length>0&&x(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),d.invalidateQueries({queryKey:nt}),n.failures.length>0&&D(n.failures.join(` · `)),F(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){D(at(e))}finally{T(!1)}},[H,v,k,M,y,d,l]),te=y.filter(e=>e.status===`analyzed`).length;return c(f,{open:n,onOpenChange:e=>e?a(!0):V(),children:r(S,{className:`max-w-3xl`,children:[r(b,{children:[c(O,{children:`Enrol from photos`}),c(m,{children:`Every photo is analysed with the same face detector the cameras use, and all the faces found are reviewed below in one pass, grouped by photo. Assign each face to a person, or leave it ignored.`})]}),r(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:[`For reliable recognition use `,c(`strong`,{children:`at least 3 photos per person`}),`, taken at different times, with different poses and lighting — you can select them all at once. Several frames from the same moment count as one — they do not add information.`]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{ref:h,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void ee(Array.from(e.target.files??[]))}),r(g,{variant:`secondary`,size:`sm`,disabled:R,onClick:()=>h.current?.click(),children:[L?c(Z,{className:`h-3.5 w-3.5 animate-spin`}):c(Ee,{className:`h-3.5 w-3.5`}),`Choose photos`]}),y.length>0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[te,`/`,y.length,` photo`,y.length===1?``:`s`,` analysed`]})]}),E!==null&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[c(ve,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),c(`span`,{children:E})]}),P!==null&&c(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:P}),y.length>0&&c(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:y.map(e=>c(st,{photo:e,identities:I,draft:k,newNames:M,disabled:R,onAssign:(t,n)=>j(r=>qe(r,e.photoIndex,t,n===rt?null:n)),onNameChange:(t,n)=>N(r=>({...r,[Ke(e.photoIndex,t)]:n})),onRetry:()=>void U(e)},e.photoIndex))}),r(p,{children:[c(g,{variant:`secondary`,onClick:V,disabled:w,children:`Close`}),r(g,{variant:`primary`,onClick:()=>void G(),disabled:R||W===0,children:[w?c(Z,{className:`h-3.5 w-3.5 animate-spin`}):null,`Enrol `,W,` face`,W===1?``:`s`]})]})]})})}n();var lt=[[`faceGallery`]];function ut({identityId:e}){let t=o(),{data:n,isLoading:i}=N({identityId:e}),a=w();function s(n){a.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:lt})}})}return i?r(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[c(Z,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):c(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:n.map(e=>r(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?c(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Y,{className:`h-6 w-6`})}),e.source===`photo`&&c(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:`Enrolled from an uploaded photo`,children:c(Ee,{className:`h-3 w-3`})}),c(`button`,{type:`button`,onClick:()=>s(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:c(X,{className:`h-4 w-4 text-white`})})]},e.id))})}function dt({identity:e,expanded:t,onToggle:n}){let i=o(),[l,u]=s(``),[d,_]=s(!1),[v,x]=s(!1),C=F(),w=D();function T(){u(e.name),_(!0)}function E(){_(!1),u(``)}function k(){let t=l.trim();if(!t||t===e.name){E();return}C.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:lt}),E()}})}function A(){w.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:lt}),x(!1)}})}return r(`div`,{className:`rounded-md border border-border bg-surface`,children:[r(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[c(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:c(B,{mediaKey:e.coverMediaKey,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:c(`div`,{className:`flex h-full w-full items-center justify-center`,children:c(Y,{className:`h-4 w-4 text-foreground-subtle`})})})}),c(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:d?r(a,{children:[c(y,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&k(),e.key===`Escape`&&E()},className:`h-6 text-xs`,autoFocus:!0}),c(`button`,{type:`button`,onClick:k,disabled:C.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:c(he,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:E,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:c(X,{className:`h-3.5 w-3.5`})})]}):c(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),c(h,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!d&&r(`div`,{className:`flex items-center gap-1`,children:[c(`button`,{type:`button`,onClick:T,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:c(ue,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:()=>x(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:c(xe,{className:`h-3.5 w-3.5`})})]}),c(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:c(t?Se:_e,{className:`h-3.5 w-3.5`})})]}),t&&c(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:c(ut,{identityId:e.id})}),c(f,{open:v,onOpenChange:e=>!e&&x(!1),children:r(S,{children:[r(b,{children:[c(O,{children:`Delete person`}),r(m,{children:[`Delete `,c(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),r(p,{children:[c(g,{variant:`secondary`,onClick:()=>x(!1),children:`Cancel`}),r(g,{variant:`danger`,onClick:A,disabled:w.isPending,children:[w.isPending?c(Z,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ft(){let e=o(),[t,n]=s(``),i=A();function a(){let r=t.trim();r&&i.mutate({name:r},{onSettled:()=>{e.invalidateQueries({queryKey:lt}),n(``)}})}return r(`div`,{className:`flex items-center gap-2 pt-2`,children:[c(y,{placeholder:`New person name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a()},className:`h-7 text-xs flex-1`}),r(g,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?c(Z,{className:`h-3.5 w-3.5 animate-spin`}):c(q,{className:`h-3.5 w-3.5`}),`Add`]})]})}function pt(){let{data:e,isLoading:t}=C(),[n,i]=s(null),[a,o]=s(!1);function l(e){i(t=>t===e?null:e)}return t?r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(Z,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):r(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>c(dt,{identity:e,expanded:n===e.id,onToggle:()=>l(e.id)},e.id)),c(ft,{}),c(`div`,{className:`pt-1`,children:r(g,{variant:`secondary`,size:`sm`,onClick:()=>o(!0),children:[c(Ee,{className:`h-3.5 w-3.5`}),`Enrol from a photo`]})}),c(ct,{open:a,onOpenChange:o})]})}function mt(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function ht(e){return e.filter(mt).map(e=>e.faceId)}function gt(e){let t=0;for(let n of e)mt(n)&&(t+=1);return t}function _t(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}n();var vt=[[`faceGallery`]];function yt({faceIds:e,identities:t,onDone:n}){let i=o(),a=T(),l=A(),[u,d]=s(``),[h,_]=s(!1),[v,x]=s(null),C=e!==null&&e.length>0,w=e?.length??0;function E(){_(!1),d(``),x(null)}function D(){E(),n()}function k(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:vt}),D()}})}function j(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&k(e.id)},onError:()=>{i.invalidateQueries({queryKey:vt}),D()}})}let M=a.isPending||l.isPending;return c(f,{open:C,onOpenChange:e=>!e&&D(),children:r(S,{children:[r(b,{children:[c(O,{children:w>1?`Assign ${String(w)} faces to person`:`Assign face to person`}),c(m,{children:`Select an existing person or create a new one.`})]}),c(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>r(`button`,{type:`button`,onClick:()=>x(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${v===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[c(`span`,{className:`font-medium`,children:e.name}),r(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),h?c(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:c(y,{placeholder:`New person name…`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j()},autoFocus:!0,className:`flex-1`})}):c(`button`,{type:`button`,onClick:()=>{x(null),_(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New person…`}),r(p,{children:[c(g,{variant:`secondary`,onClick:D,disabled:M,children:`Cancel`}),h?r(g,{variant:`primary`,onClick:j,disabled:M||!u.trim(),children:[M&&c(Z,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):r(g,{variant:`primary`,onClick:()=>v&&k(v),disabled:M||!v,children:[M&&c(Z,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,w>1?` ${String(w)}`:``]})]})]})})}n();function bt(e){let[t,n]=s(null),[r,i]=s(null),[a,o]=s(!1);return l(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await we(`${Te}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),l(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function xt(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function St({label:e,value:t}){return r(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[c(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),c(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function Ct({box:e}){return c(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:c(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function wt({face:e,cameraName:t,onClose:n,onAssign:a,onUnassign:o,onDelete:l,actionsPending:u}){let{data:d,isFetching:p}=E({faceId:e?.faceId??``},{enabled:e!==null}),[m,h]=s(`frame`),{frameSrc:_,naturalWidth:v,naturalHeight:y,failed:b}=bt(e?.keyFrameMediaKey),x=i(()=>{let t=xt(d??[]);return t?t.url:_t(e)},[d,e]),C=i(()=>!e?.faceBbox||v===null||y===null?null:U(e.faceBbox,v,y),[e?.faceBbox,v,y]);if(e===null)return null;let w=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!b,T=w&&m===`frame`,D=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return c(f,{open:!0,onOpenChange:e=>!e&&n(),children:r(S,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Face detail`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),c(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),c(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(X,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[w&&r(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[r(`button`,{type:`button`,onClick:()=>h(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(R,{className:`h-3.5 w-3.5`}),` Full frame`]}),r(`button`,{type:`button`,onClick:()=>h(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(V,{className:`h-3.5 w-3.5`}),` Crop`]})]}),T&&_?c(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:c(K,{src:_,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:C?c(Ct,{box:C}):void 0})}):x?r(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[c(K,{src:x,alt:`Detected face`,className:`h-full w-full`}),p&&c(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:c(Z,{className:`h-3.5 w-3.5 animate-spin`})})]}):r(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[c(re,{className:`h-8 w-8 text-warning/70`}),c(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),c(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[c(St,{label:`Camera`,value:t}),c(St,{label:`Captured`,value:ae(e.timestamp)}),c(St,{label:`Track`,value:e.trackId}),c(St,{label:`Identity`,value:D})]})]}),r(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?r(g,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:u,children:[c(H,{className:`h-3.5 w-3.5`}),` Detach`]}):r(g,{variant:`primary`,onClick:()=>a(e.faceId),disabled:u,children:[c(z,{className:`h-3.5 w-3.5`}),` Assign`]}),r(g,{variant:`secondary`,onClick:()=>l(e.faceId),disabled:u,children:[c(xe,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}function Tt(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Et(e,t){return e.faceIds.filter(e=>!t.has(e))}function Dt(e,t){return e.faceIds.filter(e=>t(e))}n();var Ot=[[`faceGallery`]],kt=20,At=.3,jt=.9,Mt=.05,Nt=.5,Pt=2,Ft=10,It=2;function Lt({cluster:e,face:t,active:n,onSelect:i}){let a=_t(t);return r(`button`,{type:`button`,onClick:i,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${n?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[c(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:a===null?c(re,{className:`h-24 w-24 p-6 text-foreground-subtle`}):c(`img`,{src:a,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),r(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]})]})}function Rt({face:e,cameraName:t,nowMs:n,excluded:i,onToggleExclude:a,onDelete:o,deletePending:s}){let l=_t(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[l===null?r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[c(re,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(K,{src:l,alt:`Face from ${t}`,className:`h-full w-full`}),c(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Include face`:`Exclude face`,title:i?`Include`:`Exclude`,children:c(i?J:X,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:G(e.timestamp,n)})]}),c(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:c(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:s,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:s?c(Z,{className:`h-4 w-4 animate-spin`}):c(xe,{className:`h-4 w-4`})})})]})}function zt({open:e,onClose:t,byId:n,cameraName:u,nowMs:d,identities:p,selectMany:m}){let h=o(),_=j(),v=k(),[y,b]=s(Nt),[C,w]=s(It),[T,E]=s(null),[D,O]=s({}),[A,M]=s(null),{data:N,isFetching:P,refetch:F}=x({threshold:y,minClusterSize:C,limit:kt},{enabled:e}),I=N??[];l(()=>{O({})},[y,C]),l(()=>{if(I.length===0){E(null);return}I.some(e=>e.representativeFaceId===T)||E(I[0]?.representativeFaceId??null)},[I]);let L=i(()=>I.find(e=>e.representativeFaceId===T)??null,[I,T]),R=L?D[L.representativeFaceId]??new Set:new Set,B=i(()=>L?Dt(L,e=>n.has(e)):[],[L,n]),V=L?L.faceIds.length-B.length:0,H=L?Et({...L,faceIds:B},R):[];function U(e){if(!L)return;let t=L.representativeFaceId;O(n=>({...n,[t]:Tt(n[t]??new Set,e)}))}function ee(){h.invalidateQueries({queryKey:Ot})}async function W(e){await _({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&v.mutate({faceId:e},{onSettled:ee})}function G(){M(null),t()}function te(){H.length!==0&&(m(H),G())}return r(f,{open:e,onOpenChange:e=>!e&&G(),children:[r(S,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":`Look-alike groups`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[r(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[c(ye,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),c(`button`,{type:`button`,onClick:G,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(X,{className:`h-4 w-4`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,c(`input`,{type:`range`,min:At,max:jt,step:Mt,value:y,onChange:e=>b(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),c(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:y.toFixed(2)})]}),r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,c(`input`,{type:`number`,min:Pt,max:Ft,step:1,value:C,onChange:e=>w(Math.min(Ft,Math.max(Pt,Number(e.target.value)||Pt))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),r(g,{variant:`secondary`,onClick:()=>{O({}),F()},disabled:P,children:[P?c(Z,{className:`h-3.5 w-3.5 animate-spin`}):c(de,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),c(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:P&&I.length===0?r(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(Z,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):I.length===0?c(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):r(a,{children:[c(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:I.map(e=>c(Lt,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===T,onSelect:()=>E(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:I.map(e=>c(Lt,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===T,onSelect:()=>E(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&r(a,{children:[V>0&&r(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[V,` not loaded — excluded from actions`]}),c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:B.map(e=>{let t=n.get(e);return t?c(Rt,{face:t,cameraName:u(t.deviceId),nowMs:d,excluded:R.has(e),onToggleExclude:()=>U(e),onDelete:()=>void W(e),deletePending:v.isPending&&v.variables?.faceId===e},e):null})})]})})]})}),r(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[c(g,{variant:`secondary`,onClick:te,disabled:H.length===0,children:`Select in gallery`}),r(g,{variant:`primary`,onClick:()=>M(H),disabled:H.length===0,children:[c(z,{className:`h-3.5 w-3.5`}),` Adopt (`,H.length,`)`]})]})]}),c(yt,{faceIds:A,identities:p,onDone:()=>M(null)})]})}n();var Bt=[[`faceGallery`]],Vt=500,Ht=120;function Ut({face:e,cameraName:t,nowMs:n,selected:i,onToggleSelect:a,onAssign:s,onOpenDetail:l}){let u=o(),f=d(),p=k(),m=()=>{u.invalidateQueries({queryKey:Bt})},h=()=>l(e.faceId),g=_t(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[g===null?r(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`,children:[c(re,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(`img`,{src:g,alt:`Face from ${t}`,onClick:h,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(e.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?c(pe,{className:`h-4 w-4 text-primary`}):c(me,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:G(e.timestamp,n)}),e.identityName&&c(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),r(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),f.mutate({faceId:e.faceId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach face`,title:`Detach`,children:f.isPending?c(Z,{className:`h-4 w-4 animate-spin`}):c(H,{className:`h-4 w-4`})}):c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign face to person`,title:`Assign to person`,children:c(z,{className:`h-4 w-4`})}),c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),p.mutate({faceId:e.faceId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:p.isPending?c(Z,{className:`h-4 w-4 animate-spin`}):c(xe,{className:`h-4 w-4`})})]})]})}var Wt=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function Gt(){let e=o(),[t,n]=s(`all`),[l,u]=s(se),[f,p]=s(new Set),[m,h]=s(new Set),[v,y]=s(null),[b,x]=s(!1),[S,w]=s(null),{data:E,isLoading:D}=I({limit:Vt,filter:t,includeCrops:!1},{refetchInterval:3e4}),{data:O=[]}=C(),{data:A}=_({isCamera:!0,projection:`slim`}),j=T(),M=d(),N=P(),F=k(),L=Date.now(),R=E??[],B=i(()=>{let e=new Map;for(let t of A??[])e.set(t.id,t.name);return e},[A]),V=e=>B.get(e)??`Camera #${String(e)}`,U=i(()=>W(R).map(e=>({id:e,name:V(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,B]),G=i(()=>ne(le(R,l),f),[R,l,f]),K=ie(G,Ht,i(()=>JSON.stringify([t,l.fromMs,l.toMs,[...f].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,f])),ae=i(()=>new Map(R.map(e=>[e.faceId,e])),[R]),ce=i(()=>gt(G),[G]),ue=S===null?null:ae.get(S)??null,q=()=>{e.invalidateQueries({queryKey:Bt})},de=()=>h(new Set);function fe(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function pe(e){h(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function me(){pe(ht(G))}let J=[...m],Y=j.isPending||N.isPending||F.isPending,he=M.isPending||F.isPending;function ge(){J.length!==0&&N.mutate({faceIds:J},{onSettled:()=>{q(),de()}})}function _e(){J.length!==0&&Promise.allSettled(J.map(e=>F.mutateAsync({faceId:e}))).then(()=>{q(),de()})}function ve(e){w(null),y([e])}function be(e){M.mutate({faceId:e},{onSettled:q}),w(null)}function Se(e){F.mutate({faceId:e},{onSettled:q}),w(null)}let Ce=G.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c(`div`,{className:`flex items-center gap-1`,children:Wt.map(e=>c(`button`,{type:`button`,onClick:()=>n(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),c(oe,{onChange:u}),c(te,{cameras:U,selected:f,onChange:p}),r(`button`,{type:`button`,onClick:()=>x(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${b?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(ye,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!D&&ce>0&&r(`button`,{type:`button`,onClick:me,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:`Select every visible face whose crop image is missing so you can delete the orphans in one pass`,children:[c(re,{className:`h-3.5 w-3.5`}),` Select `,ce,` crop-less`]}),!D&&c(`span`,{className:`text-[10px] text-foreground-subtle ${ce>0?`ml-2`:`ml-auto`}`,children:Ce?`${String(G.length)} of ${String(R.length)} faces`:`${String(G.length)} face${G.length===1?``:`s`}`})]}),m.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[m.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[r(g,{variant:`primary`,onClick:()=>y(J),disabled:Y,children:[c(z,{className:`h-3.5 w-3.5`}),` Assign`]}),r(g,{variant:`secondary`,onClick:ge,disabled:Y,children:[N.isPending?c(Z,{className:`h-3.5 w-3.5 animate-spin`}):c(H,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),r(g,{variant:`secondary`,onClick:_e,disabled:Y,children:[c(xe,{className:`h-3.5 w-3.5`}),` Delete`]}),c(g,{variant:`ghost`,onClick:de,disabled:Y,children:c(X,{className:`h-3.5 w-3.5`})})]})]}),D&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(Z,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!D&&G.length===0&&c(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:R.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!D&&G.length>0&&r(a,{children:[c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:K.pageItems.map(e=>c(Ut,{face:e,cameraName:V(e.deviceId),nowMs:L,selected:m.has(e.faceId),onToggleSelect:fe,onAssign:e=>y([e]),onOpenDetail:w},e.faceId))}),c(ee,{currentPage:K.page,totalItems:K.totalItems,pageSize:K.pageSize,onPageChange:K.setPage,itemNoun:`faces`})]}),c(wt,{face:ue,cameraName:ue?V(ue.deviceId):``,onClose:()=>w(null),onAssign:ve,onUnassign:be,onDelete:Se,actionsPending:he}),c(yt,{faceIds:v,identities:O,onDone:()=>{y(null),de()}}),c(zt,{open:b,onClose:()=>x(!1),byId:ae,cameraName:V,nowMs:L,identities:O,selectMany:pe})]})}n();var Kt=[[`faceGallery`]],qt=2e3;function Jt(){let e=o(),n=t(e);n.current=e;let r=t(void 0);r.current||=ce({delayMs:qt,invalidate:()=>{n.current.invalidateQueries({queryKey:Kt})}}),l(()=>()=>r.current?.cancel(),[]),M(L.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Yt(){return Jt(),c(Ce,{icon:be,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:r(`section`,{className:`space-y-3`,children:[r(`div`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled identities used for face recognition. Expand a row to view or remove training samples.`}),c(pt,{})]}),r(`div`,{className:`pt-4 border-t border-border`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`}),c(Gt,{})]})]})})}export{Yt as DetectionIntelligencePage};
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as u}from"./player-overlays-BOHd-BQW.js";import{Ci as d,Ct as f,Dt as p,Et as m,Ft as h,It as g,Jr as _,Mt as v,Nt as y,Ot as b,Si as x,Tt as S,_i as C,bi as w,fi as T,gi as E,hi as D,kt as O,mi as k,nc as A,pi as j,sn as M,vi as N,wi as P,xi as F,yi as I}from"./src-BmPEyOJ9.js";import{Kt as L}from"./src-DGE3vmjp.js";import{a as R,i as z,n as B,o as V,r as H,t as U}from"./face-bbox-BkUtqpif.js";import{a as ee,c as W,f as G,i as te,l as ne,m as re,n as K,o as ie,p as ae,r as oe,s as se,t as ce,u as le}from"./debounced-invalidate-Bh2p192d.js";import{t as ue}from"./pencil-GpDj1Q2p.js";import{t as q}from"./plus-Ce-u1cy0.js";import{t as de}from"./refresh-cw-CGsZO3dv.js";import{t as fe}from"./rotate-cw-CLl0fQTC.js";import{t as pe}from"./square-check-big-CYG6mqRn.js";import{t as me}from"./square-D5_FHQhn.js";import{t as J}from"./undo-2-B4kJBBZH.js";import{t as Y}from"./user-round-CJoGmSnV.js";import{B as he,J as ge,L as _e,a as ve,c as ye,h as be,o as xe,r as X,w as Z,z as Se}from"./index-g356Z7K8.js";import{t as Ce}from"./AdminPage-CCD07UMs.js";import{i as we,t as Te}from"./authed-media-DOXm0tcZ.js";var Ee=ge(`image-plus`,[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]);n();var De=`pipeline-analytics`,Oe=`photo.analyze`,ke=`photo.enroll`,Ae=`photo.discard`,je=18*1024*1024;function Me(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Ne(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Pe(e){if(!Me(e))return null;let t=$(e,`x`),n=$(e,`y`),r=$(e,`width`),i=$(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function Fe(e){if(!Me(e))return null;let t=$(e,`detectionShortSidePx`),n=$(e,`score`);if(t===null||n===null)return null;let r=$(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function Ie(e){if(!Me(e))return null;let t=$(e,`faceIndex`),n=$(e,`score`),r=Ne(e,`enrollable`),i=Pe(e.bbox),a=Fe(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Q(e,`refusedReason`),s=Q(e,`alignedCropBase64`),c=Q(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function Le(e){if(!Me(e))return null;let t=Q(e,`sessionId`),n=Q(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=Ie(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function Re(e){if(!Me(e))return null;let t=Q(e,`sampleId`),n=Q(e,`identityId`),r=Q(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function ze(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function Be(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function Ve(e,t,n){let r=[];for(let i of t){if(!i.enrollable)continue;let t=n[i.faceIndex];t!==void 0&&r.push({sessionId:e,faceIndex:i.faceIndex,identityId:t})}return r}function He(e){switch(e){case`no-embedding`:return`Too small or too indistinct for the recognizer to measure — try a photo where this face is larger.`;case`no-model-id`:return`The recognizer did not report which model it used, so this face cannot be enrolled safely.`;case`no-aligned-crop`:return`The recognizer produced no aligned crop for this face, so there is nothing to store.`;case`magnitude`:return`Refused by the quality gate: the features look degenerate, and a sample like this matches everybody.`;default:return`This face is not usable as a sample.`}}function Ue(e,t){let n=[],r=[];for(let i of e)i.size>t.maxBytes?n.push(i.name):r.push(i);return{accepted:r.slice(0,t.maxCount),oversize:n,overflow:r.slice(t.maxCount).map(e=>e.name)}}async function We(e,t,n){let r=Array(e.length),i=e.map((e,t)=>({item:e,index:t})),a=0,o=async()=>{for(;;){let e=i[a];if(a+=1,e===void 0)return;r[e.index]=await n(e.item,e.index)}},s=Array.from({length:Math.max(1,Math.min(t,e.length))},()=>o());return await Promise.all(s),r}function Ge(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function Ke(e,t){return`${e}:${t}`}function qe(e,t,n,r){let i=ze(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function Je(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=Be(r.analysis.faces,t[r.photoIndex]??{}));return n}var Ye=`__new__`;function Xe(e,t,n){let r=[];for(let i of e){if(i.analysis===void 0)continue;let e=t[i.photoIndex]??{};for(let t of i.analysis.faces){if(!t.enrollable||e[t.faceIndex]!==`__new__`)continue;let a=(n[Ke(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:`${i.filename}: face ${t.faceIndex+1} is set to a new person but has no name.`};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function Ze(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=Number(i),o={};for(let[r,i]of Object.entries(a)){let a=Number(r);if(i!==`__new__`){o[a]=i;continue}let s=n[(t[Ke(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function Qe(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=Ve(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function $e(e){return/expired/i.test(e)}function et(e){return e instanceof Error?e.message:String(e)}async function tt(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>`${r.get(e)?.filename??`photo ${e+1}`}, face ${t+1}`;for(let l of Qe(e,t)){let e=i[l.photoIndex],t=e===void 0?l.request:{...l.request,sessionId:e.sessionId};try{let e=await n.enroll(t);o+=1,s=e.modelId}catch(t){let u=et(t);if(!$e(u)||e!==void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let d=r.get(l.photoIndex);if(d===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let f;try{f=await n.reanalyze(d)}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired and re-analysing failed (${et(e)})`);continue}if(i[l.photoIndex]=f,f.faces.find(e=>e.faceIndex===l.request.faceIndex&&e.enrollable)===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired, and re-analysing no longer finds this face — assign it again from the fresh result`);continue}try{let e=await n.enroll({...l.request,sessionId:f.sessionId});o+=1,s=e.modelId}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${et(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var nt=[[`faceGallery`]],rt=``;function it(e){return new Promise((t,n)=>{let r=new FileReader;r.addEventListener(`error`,()=>n(Error(`the file could not be read`)),{once:!0}),r.addEventListener(`load`,()=>{let e=r.result;if(typeof e!=`string`){n(Error(`the file could not be read`));return}let i=e.indexOf(`,`);t(i>=0?e.slice(i+1):e)},{once:!0}),r.readAsDataURL(e)})}function at(e){return e instanceof Error?e.message:String(e)}function ot({face:e,identities:t,value:n,onChange:o,disabled:s}){let l=i(()=>[{value:rt,label:`Ignore this face`},...t.map(e=>({value:e.id,label:e.name})),{value:Ye,label:`+ New person…`}],[t]);return r(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[c(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:e.alignedCropBase64?c(`img`,{src:`data:image/jpeg;base64,${e.alignedCropBase64}`,alt:`Face ${e.faceIndex+1}`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Y,{className:`h-8 w-8`})})}),e.enrollable?r(a,{children:[c(v,{options:l,value:n,disabled:s,onChange:e=>o(e.target.value),"aria-label":`Assign face ${e.faceIndex+1}`}),r(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(e.quality.detectionShortSidePx),` px`,e.modelId?` · ${e.modelId}`:``]})]}):r(`div`,{className:`space-y-1`,children:[c(h,{variant:`warning`,className:`text-[10px]`,children:`Not usable`}),c(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:He(e.refusedReason)})]})]})}function st({photo:e,identities:t,draft:n,newNames:i,disabled:a,onAssign:o,onNameChange:s,onRetry:l}){let u=e.analysis?.faces??[],d=n[e.photoIndex]??{};return r(`div`,{className:`space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.filename}),e.status===`analyzing`||e.status===`queued`?r(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[c(Z,{className:`h-3 w-3 animate-spin`}),` analysing…`]}):null,e.status===`analyzed`&&e.analysis!==void 0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[u.length,` face`,u.length===1?``:`s`,` · analysed on`,` `,e.analysis.ranOnNodeId]}),e.status===`failed`&&r(g,{variant:`secondary`,size:`sm`,disabled:a,onClick:l,children:[c(fe,{className:`h-3 w-3`}),` Retry`]})]}),e.status===`failed`&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[c(ve,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),r(`span`,{children:[`This photo could not be analysed: `,e.error??`unknown error`,`. The other photos are unaffected.`]})]}),e.status===`analyzed`&&u.length===0&&c(`p`,{className:`text-xs text-foreground-subtle`,children:`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`}),u.length>0&&c(`div`,{className:`grid grid-cols-3 gap-3 sm:grid-cols-4 md:grid-cols-5`,children:u.map(e=>c(ot,{face:e,identities:t,value:d[e.faceIndex]??rt,disabled:a,onChange:t=>o(e.faceIndex,t)},e.faceIndex))}),u.filter(e=>d[e.faceIndex]===Ye).map(t=>r(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:[`Face `,t.faceIndex+1]}),c(`input`,{className:`h-7 flex-1 rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:`New person name… (type the same name under another face to reuse it)`,value:i[Ke(e.photoIndex,t.faceIndex)]??``,onChange:e=>s(t.faceIndex,e.target.value)})]},t.faceIndex))]})}function ct({open:n,onOpenChange:a}){let l=u(),d=o(),h=t(null),{data:_}=C(),v=j(),[y,x]=s([]),[w,T]=s(!1),[E,D]=s(null),[k,A]=s({}),[M,N]=s({}),[P,F]=s(null),I=i(()=>(_??[]).map(e=>({id:e.id,name:e.name})),[_]),L=y.some(e=>e.status===`queued`||e.status===`analyzing`),R=L||w,z=e(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&l.trpcClient.addons.custom.mutate({addonId:De,action:Ae,input:{sessionId:e}}).catch(()=>void 0)}},[l]),B=e(()=>{x([]),A({}),N({}),D(null),F(null),h.current&&(h.current.value=``)},[]),V=e(()=>{z(y),B(),a(!1)},[z,a,y,B]),H=e(async e=>{let t=Le(await l.trpcClient.addons.custom.mutate({addonId:De,action:Oe,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[l]),U=e(async e=>{x(t=>Ge(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await H(e);x(n=>Ge(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){x(n=>Ge(n,e.photoIndex,{status:`failed`,error:at(t)}))}},[H]),ee=e(async e=>{if(e.length===0)return;z(y),B();let t=Ue(e,{maxCount:12,maxBytes:je}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(je/(1024*1024))} MB limit and skipped: ${t.oversize.join(`, `)}.`),t.overflow.length>0&&n.push(`A batch holds at most 12 photos — not analysed: ${t.overflow.join(`, `)}. Enrol them in a second round.`),n.length>0&&D(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await it(e),status:`queued`})))}catch(e){D(at(e));return}x(r),await We(r,2,e=>U(e))},[z,y,B,U]),W=Je(y,k),G=e(async()=>{T(!0),D(null),F(null);try{let e=Xe(y,k,M);if(e.kind===`error`){D(e.message);return}let t={};for(let n of e.names)t[n]=(await v.mutateAsync({name:n})).id;let n=await tt(y,Ze(k,M,t),{enroll:async e=>{let t=Re(await l.trpcClient.addons.custom.mutate({addonId:De,action:ke,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>H(e)});Object.keys(n.refreshedAnalyses).length>0&&x(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),d.invalidateQueries({queryKey:nt}),n.failures.length>0&&D(n.failures.join(` · `)),F(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){D(at(e))}finally{T(!1)}},[H,v,k,M,y,d,l]),te=y.filter(e=>e.status===`analyzed`).length;return c(f,{open:n,onOpenChange:e=>e?a(!0):V(),children:r(S,{className:`max-w-3xl`,children:[r(b,{children:[c(O,{children:`Enrol from photos`}),c(m,{children:`Every photo is analysed with the same face detector the cameras use, and all the faces found are reviewed below in one pass, grouped by photo. Assign each face to a person, or leave it ignored.`})]}),r(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:[`For reliable recognition use `,c(`strong`,{children:`at least 3 photos per person`}),`, taken at different times, with different poses and lighting — you can select them all at once. Several frames from the same moment count as one — they do not add information.`]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{ref:h,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void ee(Array.from(e.target.files??[]))}),r(g,{variant:`secondary`,size:`sm`,disabled:R,onClick:()=>h.current?.click(),children:[L?c(Z,{className:`h-3.5 w-3.5 animate-spin`}):c(Ee,{className:`h-3.5 w-3.5`}),`Choose photos`]}),y.length>0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[te,`/`,y.length,` photo`,y.length===1?``:`s`,` analysed`]})]}),E!==null&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[c(ve,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),c(`span`,{children:E})]}),P!==null&&c(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:P}),y.length>0&&c(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:y.map(e=>c(st,{photo:e,identities:I,draft:k,newNames:M,disabled:R,onAssign:(t,n)=>A(r=>qe(r,e.photoIndex,t,n===rt?null:n)),onNameChange:(t,n)=>N(r=>({...r,[Ke(e.photoIndex,t)]:n})),onRetry:()=>void U(e)},e.photoIndex))}),r(p,{children:[c(g,{variant:`secondary`,onClick:V,disabled:w,children:`Close`}),r(g,{variant:`primary`,onClick:()=>void G(),disabled:R||W===0,children:[w?c(Z,{className:`h-3.5 w-3.5 animate-spin`}):null,`Enrol `,W,` face`,W===1?``:`s`]})]})]})})}n();var lt=[[`faceGallery`]];function ut({identityId:e}){let t=o(),{data:n,isLoading:i}=N({identityId:e}),a=w();function s(n){a.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:lt})}})}return i?r(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[c(Z,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):c(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:n.map(e=>r(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?c(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(Y,{className:`h-6 w-6`})}),e.source===`photo`&&c(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:`Enrolled from an uploaded photo`,children:c(Ee,{className:`h-3 w-3`})}),c(`button`,{type:`button`,onClick:()=>s(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:c(X,{className:`h-4 w-4 text-white`})})]},e.id))})}function dt({identity:e,expanded:t,onToggle:n}){let i=o(),[l,u]=s(``),[d,_]=s(!1),[v,x]=s(!1),C=F(),w=D();function T(){u(e.name),_(!0)}function E(){_(!1),u(``)}function k(){let t=l.trim();if(!t||t===e.name){E();return}C.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:lt}),E()}})}function A(){w.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:lt}),x(!1)}})}return r(`div`,{className:`rounded-md border border-border bg-surface`,children:[r(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[c(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:c(B,{mediaKey:e.coverMediaKey,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:c(`div`,{className:`flex h-full w-full items-center justify-center`,children:c(Y,{className:`h-4 w-4 text-foreground-subtle`})})})}),c(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:d?r(a,{children:[c(y,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&k(),e.key===`Escape`&&E()},className:`h-6 text-xs`,autoFocus:!0}),c(`button`,{type:`button`,onClick:k,disabled:C.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:c(he,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:E,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:c(X,{className:`h-3.5 w-3.5`})})]}):c(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),c(h,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!d&&r(`div`,{className:`flex items-center gap-1`,children:[c(`button`,{type:`button`,onClick:T,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:c(ue,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:()=>x(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:c(xe,{className:`h-3.5 w-3.5`})})]}),c(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:c(t?Se:_e,{className:`h-3.5 w-3.5`})})]}),t&&c(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:c(ut,{identityId:e.id})}),c(f,{open:v,onOpenChange:e=>!e&&x(!1),children:r(S,{children:[r(b,{children:[c(O,{children:`Delete person`}),r(m,{children:[`Delete `,c(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),r(p,{children:[c(g,{variant:`secondary`,onClick:()=>x(!1),children:`Cancel`}),r(g,{variant:`danger`,onClick:A,disabled:w.isPending,children:[w.isPending?c(Z,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ft(){let e=o(),[t,n]=s(``),i=j();function a(){let r=t.trim();r&&i.mutate({name:r},{onSettled:()=>{e.invalidateQueries({queryKey:lt}),n(``)}})}return r(`div`,{className:`flex items-center gap-2 pt-2`,children:[c(y,{placeholder:`New person name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a()},className:`h-7 text-xs flex-1`}),r(g,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?c(Z,{className:`h-3.5 w-3.5 animate-spin`}):c(q,{className:`h-3.5 w-3.5`}),`Add`]})]})}function pt(){let{data:e,isLoading:t}=C(),[n,i]=s(null),[a,o]=s(!1);function l(e){i(t=>t===e?null:e)}return t?r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(Z,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):r(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>c(dt,{identity:e,expanded:n===e.id,onToggle:()=>l(e.id)},e.id)),c(ft,{}),c(`div`,{className:`pt-1`,children:r(g,{variant:`secondary`,size:`sm`,onClick:()=>o(!0),children:[c(Ee,{className:`h-3.5 w-3.5`}),`Enrol from a photo`]})}),c(ct,{open:a,onOpenChange:o})]})}function mt(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function ht(e){return e.filter(mt).map(e=>e.faceId)}function gt(e){let t=0;for(let n of e)mt(n)&&(t+=1);return t}function _t(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}n();var vt=[[`faceGallery`]];function yt({faceIds:e,identities:t,onDone:n}){let i=o(),a=T(),l=j(),[u,d]=s(``),[h,_]=s(!1),[v,x]=s(null),C=e!==null&&e.length>0,w=e?.length??0;function E(){_(!1),d(``),x(null)}function D(){E(),n()}function k(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:vt}),D()}})}function A(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&k(e.id)},onError:()=>{i.invalidateQueries({queryKey:vt}),D()}})}let M=a.isPending||l.isPending;return c(f,{open:C,onOpenChange:e=>!e&&D(),children:r(S,{children:[r(b,{children:[c(O,{children:w>1?`Assign ${String(w)} faces to person`:`Assign face to person`}),c(m,{children:`Select an existing person or create a new one.`})]}),c(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>r(`button`,{type:`button`,onClick:()=>x(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${v===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[c(`span`,{className:`font-medium`,children:e.name}),r(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),h?c(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:c(y,{placeholder:`New person name…`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&A()},autoFocus:!0,className:`flex-1`})}):c(`button`,{type:`button`,onClick:()=>{x(null),_(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New person…`}),r(p,{children:[c(g,{variant:`secondary`,onClick:D,disabled:M,children:`Cancel`}),h?r(g,{variant:`primary`,onClick:A,disabled:M||!u.trim(),children:[M&&c(Z,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):r(g,{variant:`primary`,onClick:()=>v&&k(v),disabled:M||!v,children:[M&&c(Z,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,w>1?` ${String(w)}`:``]})]})]})})}n();function bt(e){let[t,n]=s(null),[r,i]=s(null),[a,o]=s(!1);return l(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await we(`${Te}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),l(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function xt(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function St({label:e,value:t}){return r(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[c(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),c(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function Ct({box:e}){return c(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:c(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function wt({face:e,cameraName:t,onClose:n,onAssign:a,onUnassign:o,onDelete:l,actionsPending:u}){let{data:d,isFetching:p}=E({faceId:e?.faceId??``},{enabled:e!==null}),[m,h]=s(`frame`),{frameSrc:_,naturalWidth:v,naturalHeight:y,failed:b}=bt(e?.keyFrameMediaKey),x=i(()=>{let t=xt(d??[]);return t?t.url:_t(e)},[d,e]),C=i(()=>!e?.faceBbox||v===null||y===null?null:U(e.faceBbox,v,y),[e?.faceBbox,v,y]);if(e===null)return null;let w=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!b,T=w&&m===`frame`,D=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return c(f,{open:!0,onOpenChange:e=>!e&&n(),children:r(S,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Face detail`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),c(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),c(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(X,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[w&&r(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[r(`button`,{type:`button`,onClick:()=>h(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(R,{className:`h-3.5 w-3.5`}),` Full frame`]}),r(`button`,{type:`button`,onClick:()=>h(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(V,{className:`h-3.5 w-3.5`}),` Crop`]})]}),T&&_?c(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:c(K,{src:_,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:C?c(Ct,{box:C}):void 0})}):x?r(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[c(K,{src:x,alt:`Detected face`,className:`h-full w-full`}),p&&c(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:c(Z,{className:`h-3.5 w-3.5 animate-spin`})})]}):r(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[c(re,{className:`h-8 w-8 text-warning/70`}),c(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),c(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[c(St,{label:`Camera`,value:t}),c(St,{label:`Captured`,value:ae(e.timestamp)}),c(St,{label:`Track`,value:e.trackId}),c(St,{label:`Identity`,value:D})]})]}),r(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?r(g,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:u,children:[c(H,{className:`h-3.5 w-3.5`}),` Detach`]}):r(g,{variant:`primary`,onClick:()=>a(e.faceId),disabled:u,children:[c(z,{className:`h-3.5 w-3.5`}),` Assign`]}),r(g,{variant:`secondary`,onClick:()=>l(e.faceId),disabled:u,children:[c(xe,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}function Tt(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Et(e,t){return e.faceIds.filter(e=>!t.has(e))}function Dt(e,t){return e.faceIds.filter(e=>t(e))}n();var Ot=[[`faceGallery`]],kt=20,At=.3,jt=.9,Mt=.05,Nt=.5,Pt=2,Ft=10,It=2;function Lt({cluster:e,face:t,active:n,onSelect:i}){let a=_t(t);return r(`button`,{type:`button`,onClick:i,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${n?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[c(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:a===null?c(re,{className:`h-24 w-24 p-6 text-foreground-subtle`}):c(`img`,{src:a,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),r(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]})]})}function Rt({face:e,cameraName:t,nowMs:n,excluded:i,onToggleExclude:a,onDelete:o,deletePending:s}){let l=_t(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[l===null?r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[c(re,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(K,{src:l,alt:`Face from ${t}`,className:`h-full w-full`}),c(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Include face`:`Exclude face`,title:i?`Include`:`Exclude`,children:c(i?J:X,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:G(e.timestamp,n)})]}),c(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:c(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:s,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:s?c(Z,{className:`h-4 w-4 animate-spin`}):c(xe,{className:`h-4 w-4`})})})]})}function zt({open:e,onClose:t,byId:n,cameraName:u,nowMs:d,identities:p,selectMany:m}){let h=o(),_=M(),v=k(),[y,b]=s(Nt),[C,w]=s(It),[T,E]=s(null),[D,O]=s({}),[A,j]=s(null),{data:N,isFetching:P,refetch:F}=x({threshold:y,minClusterSize:C,limit:kt},{enabled:e}),I=N??[];l(()=>{O({})},[y,C]),l(()=>{if(I.length===0){E(null);return}I.some(e=>e.representativeFaceId===T)||E(I[0]?.representativeFaceId??null)},[I]);let L=i(()=>I.find(e=>e.representativeFaceId===T)??null,[I,T]),R=L?D[L.representativeFaceId]??new Set:new Set,B=i(()=>L?Dt(L,e=>n.has(e)):[],[L,n]),V=L?L.faceIds.length-B.length:0,H=L?Et({...L,faceIds:B},R):[];function U(e){if(!L)return;let t=L.representativeFaceId;O(n=>({...n,[t]:Tt(n[t]??new Set,e)}))}function ee(){h.invalidateQueries({queryKey:Ot})}async function W(e){await _({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&v.mutate({faceId:e},{onSettled:ee})}function G(){j(null),t()}function te(){H.length!==0&&(m(H),G())}return r(f,{open:e,onOpenChange:e=>!e&&G(),children:[r(S,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":`Look-alike groups`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[r(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[c(ye,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),c(`button`,{type:`button`,onClick:G,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(X,{className:`h-4 w-4`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,c(`input`,{type:`range`,min:At,max:jt,step:Mt,value:y,onChange:e=>b(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),c(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:y.toFixed(2)})]}),r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,c(`input`,{type:`number`,min:Pt,max:Ft,step:1,value:C,onChange:e=>w(Math.min(Ft,Math.max(Pt,Number(e.target.value)||Pt))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),r(g,{variant:`secondary`,onClick:()=>{O({}),F()},disabled:P,children:[P?c(Z,{className:`h-3.5 w-3.5 animate-spin`}):c(de,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),c(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:P&&I.length===0?r(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(Z,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):I.length===0?c(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):r(a,{children:[c(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:I.map(e=>c(Lt,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===T,onSelect:()=>E(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:I.map(e=>c(Lt,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===T,onSelect:()=>E(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&r(a,{children:[V>0&&r(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[V,` not loaded — excluded from actions`]}),c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:B.map(e=>{let t=n.get(e);return t?c(Rt,{face:t,cameraName:u(t.deviceId),nowMs:d,excluded:R.has(e),onToggleExclude:()=>U(e),onDelete:()=>void W(e),deletePending:v.isPending&&v.variables?.faceId===e},e):null})})]})})]})}),r(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[c(g,{variant:`secondary`,onClick:te,disabled:H.length===0,children:`Select in gallery`}),r(g,{variant:`primary`,onClick:()=>j(H),disabled:H.length===0,children:[c(z,{className:`h-3.5 w-3.5`}),` Adopt (`,H.length,`)`]})]})]}),c(yt,{faceIds:A,identities:p,onDone:()=>j(null)})]})}n();var Bt=[[`faceGallery`]],Vt=500,Ht=120;function Ut({face:e,cameraName:t,nowMs:n,selected:i,onToggleSelect:a,onAssign:s,onOpenDetail:l}){let u=o(),f=d(),p=k(),m=()=>{u.invalidateQueries({queryKey:Bt})},h=()=>l(e.faceId),g=_t(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[g===null?r(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`,children:[c(re,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(`img`,{src:g,alt:`Face from ${t}`,onClick:h,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(e.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?c(pe,{className:`h-4 w-4 text-primary`}):c(me,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:G(e.timestamp,n)}),e.identityName&&c(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),r(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),f.mutate({faceId:e.faceId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach face`,title:`Detach`,children:f.isPending?c(Z,{className:`h-4 w-4 animate-spin`}):c(H,{className:`h-4 w-4`})}):c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign face to person`,title:`Assign to person`,children:c(z,{className:`h-4 w-4`})}),c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),p.mutate({faceId:e.faceId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:p.isPending?c(Z,{className:`h-4 w-4 animate-spin`}):c(xe,{className:`h-4 w-4`})})]})]})}var Wt=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function Gt(){let e=o(),[t,n]=s(`all`),[l,u]=s(se),[f,p]=s(new Set),[m,h]=s(new Set),[v,y]=s(null),[b,x]=s(!1),[S,w]=s(null),{data:E,isLoading:D}=I({limit:Vt,filter:t,includeCrops:!1},{refetchInterval:3e4}),{data:O=[]}=C(),{data:A}=_({isCamera:!0,projection:`slim`}),j=T(),M=d(),N=P(),F=k(),L=Date.now(),R=E??[],B=i(()=>{let e=new Map;for(let t of A??[])e.set(t.id,t.name);return e},[A]),V=e=>B.get(e)??`Camera #${String(e)}`,U=i(()=>W(R).map(e=>({id:e,name:V(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,B]),G=i(()=>ne(le(R,l),f),[R,l,f]),K=ie(G,Ht,i(()=>JSON.stringify([t,l.fromMs,l.toMs,[...f].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,f])),ae=i(()=>new Map(R.map(e=>[e.faceId,e])),[R]),ce=i(()=>gt(G),[G]),ue=S===null?null:ae.get(S)??null,q=()=>{e.invalidateQueries({queryKey:Bt})},de=()=>h(new Set);function fe(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function pe(e){h(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function me(){pe(ht(G))}let J=[...m],Y=j.isPending||N.isPending||F.isPending,he=M.isPending||F.isPending;function ge(){J.length!==0&&N.mutate({faceIds:J},{onSettled:()=>{q(),de()}})}function _e(){J.length!==0&&Promise.allSettled(J.map(e=>F.mutateAsync({faceId:e}))).then(()=>{q(),de()})}function ve(e){w(null),y([e])}function be(e){M.mutate({faceId:e},{onSettled:q}),w(null)}function Se(e){F.mutate({faceId:e},{onSettled:q}),w(null)}let Ce=G.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c(`div`,{className:`flex items-center gap-1`,children:Wt.map(e=>c(`button`,{type:`button`,onClick:()=>n(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),c(oe,{onChange:u}),c(te,{cameras:U,selected:f,onChange:p}),r(`button`,{type:`button`,onClick:()=>x(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${b?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(ye,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!D&&ce>0&&r(`button`,{type:`button`,onClick:me,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:`Select every visible face whose crop image is missing so you can delete the orphans in one pass`,children:[c(re,{className:`h-3.5 w-3.5`}),` Select `,ce,` crop-less`]}),!D&&c(`span`,{className:`text-[10px] text-foreground-subtle ${ce>0?`ml-2`:`ml-auto`}`,children:Ce?`${String(G.length)} of ${String(R.length)} faces`:`${String(G.length)} face${G.length===1?``:`s`}`})]}),m.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[m.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[r(g,{variant:`primary`,onClick:()=>y(J),disabled:Y,children:[c(z,{className:`h-3.5 w-3.5`}),` Assign`]}),r(g,{variant:`secondary`,onClick:ge,disabled:Y,children:[N.isPending?c(Z,{className:`h-3.5 w-3.5 animate-spin`}):c(H,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),r(g,{variant:`secondary`,onClick:_e,disabled:Y,children:[c(xe,{className:`h-3.5 w-3.5`}),` Delete`]}),c(g,{variant:`ghost`,onClick:de,disabled:Y,children:c(X,{className:`h-3.5 w-3.5`})})]})]}),D&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(Z,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!D&&G.length===0&&c(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:R.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!D&&G.length>0&&r(a,{children:[c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:K.pageItems.map(e=>c(Ut,{face:e,cameraName:V(e.deviceId),nowMs:L,selected:m.has(e.faceId),onToggleSelect:fe,onAssign:e=>y([e]),onOpenDetail:w},e.faceId))}),c(ee,{currentPage:K.page,totalItems:K.totalItems,pageSize:K.pageSize,onPageChange:K.setPage,itemNoun:`faces`})]}),c(wt,{face:ue,cameraName:ue?V(ue.deviceId):``,onClose:()=>w(null),onAssign:ve,onUnassign:be,onDelete:Se,actionsPending:he}),c(yt,{faceIds:v,identities:O,onDone:()=>{y(null),de()}}),c(zt,{open:b,onClose:()=>x(!1),byId:ae,cameraName:V,nowMs:L,identities:O,selectMany:pe})]})}n();var Kt=[[`faceGallery`]],qt=2e3;function Jt(){let e=o(),n=t(e);n.current=e;let r=t(void 0);r.current||=ce({delayMs:qt,invalidate:()=>{n.current.invalidateQueries({queryKey:Kt})}}),l(()=>()=>r.current?.cancel(),[]),A(L.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Yt(){return Jt(),c(Ce,{icon:be,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:r(`section`,{className:`space-y-3`,children:[r(`div`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled identities used for face recognition. Expand a row to view or remove training samples.`}),c(pt,{})]}),r(`div`,{className:`pt-4 border-t border-border`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`}),c(Gt,{})]})]})})}export{Yt as DetectionIntelligencePage};
|
package/dist/assets/{DeviceAggregateSection-CcU8lz-n.js → DeviceAggregateSection-BYV9beqX.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Gr as c,Wr as l,di as u,
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Gr as c,Wr as l,di as u,fs as d,ps as f,ri as p,ui as m}from"./src-BmPEyOJ9.js";import{zt as h}from"./src-DGE3vmjp.js";import{n as g,w as _}from"./index-g356Z7K8.js";import{n as v,r as y,t as b}from"./SchemaTabBar-DC28nb9j.js";import{t as x}from"./FormBuilder-BqDI8IF8.js";import{t as S}from"./StableTabPanel-Dc954AQl.js";n();function C({schema:e,values:t,pendingKeys:n,onChange:a,onAction:c,onSave:l,onDiscard:u,disabled:d,activeSubTab:f,onSubTabChange:p,flattenTabs:m=!1,deviceId:h}){let g=e.tabs??[],_=i(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),y=new Set(g.map(e=>e.id)),C=[...g,...[..._.keys()].filter(e=>!y.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],w=C[0]?.id??`general`,[T,E]=o(w),D=p!==void 0,O=new Set(C.map(e=>e.id)),k=D?f&&O.has(f)?f:w:O.has(T)?T:w,A=e=>{D?p(e):E(e)},j=_.get(k)??[],M={sections:j.length<=1?j.length===1?[{...j[0],title:``}]:j:j.every(e=>!e.title)?[{...j[0],title:``,fields:j.flatMap(e=>e.fields)}]:j},N=s(v,{pendingCount:n.length,onSave:()=>l(n),onDiscard:()=>u(n),saving:d});if(m||C.length<=1)return r(`div`,{className:`flex flex-col gap-3`,children:[s(x,{schema:e,values:t,onChange:a,onAction:c,disabled:d,deviceId:h}),N]});let P=new Map,F=new Map;for(let[e,t]of _){P.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&F.set(e,a)}return r(`div`,{className:`flex flex-col gap-3`,children:[s(b,{tabs:C.map(e=>({id:e.id,label:e.label})),activeId:k,onChange:A,countByTab:P,pendingByTab:F}),s(S,{tabKey:k,children:s(x,{schema:M,values:t,onChange:a,onAction:c,disabled:d,deviceId:h})}),N]})}var w=`device-export`,T=`export`,E=`Export`;function D(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(D):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(D)):e.writerCapName===w}function O(e){return e.tab===`export`?!0:e.fields.some(D)}n();function k(e,t){return t&&t===`admin`?e:!0}function A(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?O(e)&&O(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function j(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function M(e){return e.key}function N(e){if(!j(e))return e.value}function P(e){return j(e)?null:e}function F(e,t){for(let n of e)if(t(n),n.type===`group`)F(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)F(e.fields,t)}function I(e){if(!e)return{};let t={};for(let n of e.sections)F(n.fields,e=>{let n=M(e);n!==null&&(t[n]=N(e))});return t}function L(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(F(r.fields,e=>{if(n!==null||M(e)!==t)return;let r=P(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function R(e){return{...e,fields:e.fields.map(z)}}function z(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function B(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=P(e);return n?k(t,n.minRole)?e:z(e):e})}))}}function V({deviceId:n,sectionFilter:o,activeSubTab:v,onSubTabChange:b,flattenSubTabs:x,subTabGrouping:S}){let w=a(),{user:T}=g(),E=T?.isAdmin===!0,D=t(!1),{data:k,isLoading:j}=c({deviceId:n},{refetchInterval:()=>D.current?!1:2500,enabled:Number.isFinite(n)}),{data:M}=l({deviceId:n},{enabled:Number.isFinite(n)}),N=k?.settings??null,P=k?.live??null,F=i(()=>{if(!N&&!P)return null;let e=N?.sections??[],t=(P?.sections??[]).map(R),n=[...e,...t],r=o?n.filter(o):n.filter(e=>e.location!==`top-tab`&&!O(e));if(r.length===0)return null;if(S){let e=r.map(e=>({...e,tab:S.groupOf(e)})),t=new Set(e.map(e=>e.tab)),n=S.tabs.filter(e=>t.has(e.id));return n.length>0?{tabs:n,sections:e}:{sections:e}}let i=new Set;for(let e of r)i.add(e.tab??`general`);let a=[...N?.tabs??[],...(P?.tabs??[]).filter(e=>!(N?.tabs??[]).some(t=>t.id===e.id))].filter(e=>i.has(e.id));return a.length>0?{tabs:a,sections:r}:{sections:r}},[N,P,o,S]),z=i(()=>A(F),[F]),V=i(()=>B(z,E),[z,E]),H=i(()=>I(V),[V]),U=f(),W=d(),G=m(),K=p(),q=u({onSuccess:()=>{w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),J={isPending:q.isPending,mutate:e=>{q.mutate({deviceId:n,changes:[...e]})}},Y=y({schema:V,serverValues:H,onImmediateSave:e(e=>{let t=Object.entries(e).map(([e,t])=>{let n=L(V,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&J.mutate(t)},[V,J]),onDeferredSave:e(e=>{let t=Object.entries(e).map(([e,t])=>{let n=L(V,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&J.mutate(t)},[V,J])}),{values:X,pendingKeys:Z,handleChange:Q,handleSave:$,handleDiscard:ee}=Y;if(D.current=Y.editingPaused,j)return r(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[s(_,{className:`h-4 w-4 animate-spin mr-2`}),s(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!V||V.sections.length===0)return s(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function te(e,t,r){if(e===`regenerate-rtsp-token`){let e=[`rtspUrl:`,`regenerateToken:`].find(e=>t.startsWith(e));if(!e)throw Error(`regenerate-rtsp-token: unrecognised key "${t}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=t.slice(e.length);if(!r)throw Error(`regenerate-rtsp-token: key "${t}" has no streamId after prefix`);let i=h(n,r);await U.mutateAsync({brokerId:i}),w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(e===`test-probe`){if(!M)return{status:`error`,error:`Device metadata not loaded yet`};try{return await G.mutateAsync({addonId:M.addonId,type:M.type,key:t,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(e===`refresh-probe`){if(!t.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${t}" (expected "probedInfo:<streamId>")`);let e=t.slice(11);if(!e)throw Error(`refresh-probe: key "${t}" has no streamId after prefix`);let r=h(n,e),i=await W.mutateAsync({brokerId:r});return w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(e===`device-custom-action`){let e=await K.mutateAsync({deviceId:n,action:t,input:r});return w.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),e}throw Error(`[device-aggregate] unknown action "${e}"`)}return s(C,{schema:V,values:X,pendingKeys:Z,onChange:Q,onAction:te,onSave:$,onDiscard:ee,disabled:J.isPending,activeSubTab:v,onSubTabChange:b,flattenTabs:x,deviceId:n})}export{O as i,T as n,E as r,V as t};
|