@camstack/addon-admin-ui 1.2.46 → 1.2.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/dist/assets/AddLocationWizard-D8Izx1gh.js +1 -0
  2. package/dist/assets/{AddonCollectionPage-C61Ba_jl.js → AddonCollectionPage-DqaifWMB.js} +1 -1
  3. package/dist/assets/Addons-Cbum2Ue7.js +1 -0
  4. package/dist/assets/{AdminTabs-D9PvjiYm.js → AdminTabs-qMC1WN7t.js} +1 -1
  5. package/dist/assets/{AiProfiles-BI5AXKgn.js → AiProfiles-CkaDb5G-.js} +1 -1
  6. package/dist/assets/{BrokerForm-DrER3lQQ.js → BrokerForm-nGOoPwcx.js} +1 -1
  7. package/dist/assets/{Build-CTIT9BGb.js → Build-D4A-vNUJ.js} +4 -4
  8. package/dist/assets/{Capabilities-CSob3jHL.js → Capabilities-BvTJQt-3.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-DA5xGzac.js → CapabilityBadges-74hb8M82.js} +1 -1
  10. package/dist/assets/Cluster-BdYYMi89.js +1 -0
  11. package/dist/assets/Data-D8MGzmyj.js +1 -0
  12. package/dist/assets/DetectionIntelligence-E410sfaW.js +1 -0
  13. package/dist/assets/{DeviceAggregateSection-BjrIcNw5.js → DeviceAggregateSection-Tq3TjsO-.js} +1 -1
  14. package/dist/assets/DeviceDetail-Cyp63o9e.js +2 -0
  15. package/dist/assets/{Devices-DNRW-8PQ.js → Devices-DQeFVfTP.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-DLVxEE8V.js → EmbedPlayerPage-B2geI7HH.js} +1 -1
  17. package/dist/assets/Events-tUp70vOo.js +1 -0
  18. package/dist/assets/{FormBuilder-CaOtuJSH.js → FormBuilder-_oFQtE7x.js} +1 -1
  19. package/dist/assets/Identity-B9xM3PPQ.js +1 -0
  20. package/dist/assets/{IntegrationDetail-B9tT_bEN.js → IntegrationDetail-D6srOD52.js} +1 -1
  21. package/dist/assets/{Integrations-Chux0qyd.js → Integrations-BMDYnEUm.js} +1 -1
  22. package/dist/assets/{Integrations-BaAY-YyW.js → Integrations-D5GsA0v6.js} +1 -1
  23. package/dist/assets/{Logs-DCNSzdru.js → Logs-Cr3usRtb.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-DrBBWPoz.js → MotionZonesSettings-BgF0ipHJ.js} +1 -1
  25. package/dist/assets/{MyAccess-QP2TUc-A.js → MyAccess-COg9lyIf.js} +1 -1
  26. package/dist/assets/{Network-D64kmZrd.js → Network-DzuA8p3Z.js} +1 -1
  27. package/dist/assets/{NodeAddonsSettingsPanel-BQ5YizD8.js → NodeAddonsSettingsPanel-BAVG1LEY.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-B1Q3HPcp.js → NodeInferenceDevices-CcxOtvMd.js} +1 -1
  29. package/dist/assets/{Notifications-Bp-wIyj-.js → Notifications-mGunk-af.js} +1 -1
  30. package/dist/assets/Pipeline-YdFX0pzB.js +1 -0
  31. package/dist/assets/{Plates-prSedkIB.js → Plates-BZ8XXBRF.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-BftWrajB.js → PrivacyMaskSettings-yOIEXwrU.js} +1 -1
  33. package/dist/assets/{ProviderIcon-BvSrSHNr.js → ProviderIcon-Ck_2pUvf.js} +1 -1
  34. package/dist/assets/Recordings-DN2qpsF8.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-DvfWoDmr.js → ScanNetworkModal-D2dbax7J.js} +1 -1
  36. package/dist/assets/{Settings-CERfXjAi.js → Settings-n3YjyvD9.js} +1 -1
  37. package/dist/assets/{Showroom-Ddvb8Jd_.js → Showroom-kb37ihHy.js} +1 -1
  38. package/dist/assets/{Terminal-DniNTjLQ.js → Terminal-DPgh1LOa.js} +2 -2
  39. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DDeAxTIu.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DD9SArM5.js} +1 -1
  40. package/dist/assets/{boxes-s5PDMY2A.js → boxes-0BrwpGRK.js} +1 -1
  41. package/dist/assets/{build-cluster-graph-BytpMQQU.js → build-cluster-graph-CNmW9-To.js} +2 -2
  42. package/dist/assets/circle-check-big-CX86TDQ3.js +1 -0
  43. package/dist/assets/{circle-x-B04aLzqg.js → circle-x-CeSEyt9j.js} +1 -1
  44. package/dist/assets/clock-dbqOPTlc.js +1 -0
  45. package/dist/assets/{copy-B4xsDuLU.js → copy-CLkoN4vv.js} +1 -1
  46. package/dist/assets/{debounced-invalidate-p5oNNGBJ.js → debounced-invalidate-CjozCZrp.js} +1 -1
  47. package/dist/assets/{dist-BrD5LzQi.js → dist-5MqZUHpg.js} +1 -1
  48. package/dist/assets/dist-Bayrm69X.js +345 -0
  49. package/dist/assets/{download-CkwHHo3N.js → download-D2kk10ws.js} +1 -1
  50. package/dist/assets/{face-bbox-CvH_zToL.js → face-bbox-Dd_CKaP5.js} +1 -1
  51. package/dist/assets/hard-drive-YgwGO7Iy.js +1 -0
  52. package/dist/assets/{hostInit-4NWTvHjq.js → hostInit-DQHnlGm4.js} +1 -1
  53. package/dist/assets/index-DfbxOmzG.css +2 -0
  54. package/dist/assets/index-qYnug9Qs.js +4 -0
  55. package/dist/assets/{key-round-C3DZqNmk.js → key-round-58wJWtml.js} +1 -1
  56. package/dist/assets/{mf-entry-bootstrap-0-4bae07af.js → mf-entry-bootstrap-0-d57082e0.js} +2 -2
  57. package/dist/assets/{pencil-DxgsOdJ_.js → pencil-DDNEW9Yb.js} +1 -1
  58. package/dist/assets/play-rmom08n0.js +1 -0
  59. package/dist/assets/{player-overlays-BfbNCp8v.js → player-overlays-BzwYRH08.js} +1 -1
  60. package/dist/assets/plus-DW_KHfhe.js +1 -0
  61. package/dist/assets/power-DV05ZWPi.js +1 -0
  62. package/dist/assets/{radio-BlLvi9V1.js → radio-M8jdl_tl.js} +1 -1
  63. package/dist/assets/{refresh-cw-BPInWufq.js → refresh-cw-CYEUy6Ve.js} +1 -1
  64. package/dist/assets/remoteEntry-BAJ0ezfD.js +1 -0
  65. package/dist/assets/rotate-ccw-DTUvT-HV.js +1 -0
  66. package/dist/assets/rotate-cw-DWJibY6w.js +1 -0
  67. package/dist/assets/search-BVDP_pJD.js +1 -0
  68. package/dist/assets/{send-C2cA2Q14.js → send-DeNrNMe8.js} +1 -1
  69. package/dist/assets/{server-BirjNPM2.js → server-C3tpWUwZ.js} +1 -1
  70. package/dist/assets/square-C5l0pveB.js +1 -0
  71. package/dist/assets/{square-check-big-B6ik3PVg.js → square-check-big-DEqd8dem.js} +1 -1
  72. package/dist/assets/{src-C0ryWGb4.js → src-BoczRE1G.js} +10 -10
  73. package/dist/assets/src-Bok3PEiz.js +345 -0
  74. package/dist/assets/{undo-2-Di2YLM4r.js → undo-2-BnRU8pkW.js} +1 -1
  75. package/dist/assets/{upload-TBTRaU-e.js → upload--4mqPfVH.js} +1 -1
  76. package/dist/assets/{useEventInvalidation-BGgWKSKY.js → useEventInvalidation-XgGxFYwt.js} +1 -1
  77. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BT5icCYa.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Cl2xnNlc.js} +2 -2
  78. package/dist/assets/{wifi-B5JFrHzB.js → wifi-C8Oz0yjQ.js} +1 -1
  79. package/dist/assets/{zap-n9Ifudx7.js → zap-BQjibRA6.js} +1 -1
  80. package/dist/index.html +6 -6
  81. package/dist/server/addon.js +295 -32
  82. package/package.json +1 -1
  83. package/dist/assets/AddLocationWizard-DjfJYSAe.js +0 -1
  84. package/dist/assets/Addons-B4-dAnTQ.js +0 -1
  85. package/dist/assets/Cluster-C963n9uC.js +0 -1
  86. package/dist/assets/ClusterRecordingTab-ColxtGy-.js +0 -1
  87. package/dist/assets/Data-AxuhT9pH.js +0 -1
  88. package/dist/assets/DetectionIntelligence-DQ6ulYLd.js +0 -1
  89. package/dist/assets/DeviceDetail-BVNUGmo4.js +0 -2
  90. package/dist/assets/Events-CkzWtqso.js +0 -1
  91. package/dist/assets/Identity-BsPwdwu7.js +0 -1
  92. package/dist/assets/Pipeline-DgmPtFWh.js +0 -1
  93. package/dist/assets/Recordings-C7FQ4l7_.js +0 -1
  94. package/dist/assets/circle-check-big-DFEJsytm.js +0 -1
  95. package/dist/assets/clock-Cxmlo9g4.js +0 -1
  96. package/dist/assets/dist-CLRQNGYv.js +0 -345
  97. package/dist/assets/index-BpMOZW4i.js +0 -4
  98. package/dist/assets/index-De-QPGLo.css +0 -2
  99. package/dist/assets/play-D8WA4Wcj.js +0 -1
  100. package/dist/assets/plus-CRlbDvh8.js +0 -1
  101. package/dist/assets/remoteEntry-CtynHQrW.js +0 -1
  102. package/dist/assets/rotate-ccw-BNBM91kv.js +0 -1
  103. package/dist/assets/rotate-cw-kVxZiDR4.js +0 -1
  104. package/dist/assets/search-D29mAFs2.js +0 -1
  105. package/dist/assets/square-DvCXYnil.js +0 -1
  106. package/dist/assets/src-B0nZ9rxd.js +0 -345
@@ -1 +0,0 @@
1
- import{$r as e,Go as t,Gr as n,Jo as r,Jr as i,K as a,Ko as o,Lo as s,Mn as c,Nr as l,Qr as u,R as d,Ro as f,Yo as p,Yr as m,Zr as h,ai as g,bt as _,ci as v,co as y,di as b,ei as x,ii as S,li as C,mo as w,ni as T,no as E,qo as D,qr as O,ri as k,si as ee,ui as A,z as j}from"./src-C0ryWGb4.js";import{I as M,K as N,Q as P,S as F,U as I,W as L,a as te,b as ne,i as R,o as re,q as z,x as B,z as V}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{$ as H,E as U,P as W}from"./src-B0nZ9rxd.js";import{p as G}from"./player-overlays-BfbNCp8v.js";import{t as ie}from"./clock-Cxmlo9g4.js";import{t as ae}from"./copy-B4xsDuLU.js";import{t as oe}from"./download-CkwHHo3N.js";import{a as se,c as K,d as ce,f as le,i as ue,m as de,n as fe,o as pe,p as me,r as he,s as ge,t as _e}from"./debounced-invalidate-p5oNNGBJ.js";import{t as ve}from"./refresh-cw-BPInWufq.js";import{t as ye}from"./search-D29mAFs2.js";import{t as be}from"./square-check-big-B6ik3PVg.js";import{t as xe}from"./square-DvCXYnil.js";import{t as Se}from"./undo-2-Di2YLM4r.js";import{E as Ce,I as we,L as Te,M as Ee,P as De,S as q,U as Oe,W as J,i as ke,l as Ae,s as je,t as Me}from"./index-BpMOZW4i.js";import{t as Ne}from"./AdminPage-Dq33XE9j.js";import{i as Pe,n as Fe,t as Ie}from"./authed-media-B8T1dsFh.js";import{t as Le}from"./AdminTabs-D9PvjiYm.js";var Re=J(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),ze=J(`bug`,[[`path`,{d:`m8 2 1.88 1.88`,key:`fmnt4t`}],[`path`,{d:`M14.12 3.88 16 2`,key:`qol33r`}],[`path`,{d:`M9 7.13v-1a3.003 3.003 0 1 1 6 0v1`,key:`d7y7pr`}],[`path`,{d:`M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6`,key:`xs1cw7`}],[`path`,{d:`M12 20v-9`,key:`1qisl0`}],[`path`,{d:`M6.53 9C4.6 8.8 3 7.1 3 5`,key:`32zzws`}],[`path`,{d:`M6 13H2`,key:`82j7cp`}],[`path`,{d:`M3 21c0-2.1 1.7-3.9 3.8-4`,key:`4p0ekp`}],[`path`,{d:`M20.97 5c0 2.1-1.6 3.8-3.5 4`,key:`18gb23`}],[`path`,{d:`M22 13h-4`,key:`1jl80f`}],[`path`,{d:`M17.2 17c2.1.1 3.8 1.9 3.8 4`,key:`k3fwyw`}]]),Be=J(`circle-dashed`,[[`path`,{d:`M10.1 2.182a10 10 0 0 1 3.8 0`,key:`5ilxe3`}],[`path`,{d:`M13.9 21.818a10 10 0 0 1-3.8 0`,key:`11zvb9`}],[`path`,{d:`M17.609 3.721a10 10 0 0 1 2.69 2.7`,key:`1iw5b2`}],[`path`,{d:`M2.182 13.9a10 10 0 0 1 0-3.8`,key:`c0bmvh`}],[`path`,{d:`M20.279 17.609a10 10 0 0 1-2.7 2.69`,key:`1ruxm7`}],[`path`,{d:`M21.818 10.1a10 10 0 0 1 0 3.8`,key:`qkgqxc`}],[`path`,{d:`M3.721 6.391a10 10 0 0 1 2.7-2.69`,key:`1mcia2`}],[`path`,{d:`M6.391 20.279a10 10 0 0 1-2.69-2.7`,key:`1fvljs`}]]),Ve=J(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),He=J(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),Ue=J(`graduation-cap`,[[`path`,{d:`M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z`,key:`j76jl0`}],[`path`,{d:`M22 10v6`,key:`1lu8f3`}],[`path`,{d:`M6 12.5V16a6 3 0 0 0 12 0v-3.5`,key:`1r8lef`}]]),We=J(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]),Ge=J(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);P();var Ke=`pipeline-analytics`,qe=`debug.listTracks`,Je=`debug.analyze`,Ye=`/addon/pipeline-analytics/debug-export`;function Xe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ze(e,t){let n=e[t];return typeof n==`string`?n:null}function Y(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Qe(e,t){let n=e[t];return typeof n==`boolean`?n:null}function $e(e){return e===`error`||e===`warn`||e===`info`}function et(e){if(!Xe(e))return null;let t=Ze(e,`code`),n=Ze(e,`detail`),r=e.severity;return t===null||n===null||!$e(r)?null:{code:t,severity:r,detail:n}}function tt(e){if(!Xe(e))return null;let t=Ze(e,`trackId`),n=Y(e,`deviceId`),r=Ze(e,`className`),i=Y(e,`firstSeen`),a=Y(e,`lastSeen`),o=Y(e,`durationMs`),s=Qe(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Ze(e,`label`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},firstSeen:i,lastSeen:a,durationMs:o,active:s}}function nt(e){let t=tt(e);if(t===null||!Xe(e))return null;let n=Y(e,`mediaCount`),r=Y(e,`eventCount`),i=Y(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=et(e);t!==null&&c.push(t)}return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c}}function rt(e){if(!Xe(e))return null;let t=Qe(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=tt(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function it(e){if(!Xe(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=nt(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var at={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`};function ot(e){return at[e]??e}var st={error:0,warn:1,info:2};function ct(e){return e.toSorted((e,t)=>st[e.severity]-st[t.severity]||e.code.localeCompare(t.code))}function lt(e){return e.length===0?Ye:`${Ye}?deviceIds=${e.join(`,`)}`}function ut(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}var dt=`all`,ft=`The server answered in a shape this build does not understand.`,pt={error:`danger`,warn:`warning`,info:`info`};function mt({findings:e}){return e.length===0?B(r,{variant:`success`,children:`no anomaly found`}):B(`div`,{className:`flex flex-wrap gap-1`,children:ct(e).map(e=>B(r,{variant:pt[e.severity],title:e.detail,children:ot(e.code)},e.code))})}function ht({track:e,report:t,cameraName:n,analyzing:i}){return F(`div`,{className:`flex flex-col gap-1.5 border-b border-border px-3 py-2.5 last:border-b-0`,children:[F(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[B(`span`,{className:`font-medium text-foreground`,children:n}),B(`span`,{className:`text-foreground-subtle`,children:e.label??e.className}),F(`span`,{className:`text-foreground-subtle`,children:[new Date(e.lastSeen).toLocaleString(),` · `,ut(e.durationMs)]}),e.active&&B(r,{variant:`default`,children:`still open`}),t!==void 0&&F(`span`,{className:`text-foreground-subtle`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),B(`div`,{className:`flex items-center gap-2`,children:t===void 0?B(`span`,{className:`text-xs text-foreground-subtle`,children:i?`analysing…`:`not analysed`}):B(mt,{findings:t.findings})}),B(`code`,{className:`text-[10px] text-foreground-subtle`,children:e.trackId})]})}function gt(){let e=G(),[n,r]=z(dt),[i,a]=z(!1),[o,s]=z(null),l=c({}),u=L(()=>[{value:dt,label:`All cameras`},...(l.data??[]).map(e=>({value:String(e.id),label:e.name}))],[l.data]),d=L(()=>{let e=new Map;for(let t of l.data??[])e.set(t.id,t.name);return e},[l.data]),f=L(()=>n===dt?[]:[Number.parseInt(n,10)],[n]),m=te({queryKey:[`events-debug`,`list`,f],queryFn:async()=>rt(await e.trpcClient.addons.custom.mutate({addonId:Ke,action:qe,input:f.length===0?{}:{deviceIds:f}}))}),h=L(()=>(m.data?.tracks??[]).map(e=>e.trackId),[m.data]),g=te({queryKey:[`events-debug`,`analyze`,h],enabled:h.length>0,queryFn:async()=>it(await e.trpcClient.addons.custom.mutate({addonId:Ke,action:Je,input:{trackIds:h}}))}),_=L(()=>{let e=new Map;for(let t of g.data?.reports??[])e.set(t.trackId,t);return e},[g.data]),v=()=>{m.refetch(),g.refetch()},b=async()=>{a(!0),s(null);try{await Fe(lt(f),`camstack-debug.zip`)}catch(e){s(e instanceof Error?e.message:`Export failed.`)}finally{a(!1)}},x=m.data?.tracks??[],S=m.data===null||g.data===null;return B(Ne,{children:F(`section`,{className:`space-y-3`,children:[F(`div`,{className:`flex flex-wrap items-center gap-2`,children:[B(`div`,{className:`w-44`,children:B(t,{value:n,options:u,onChange:e=>r(e.target.value)})}),F(p,{variant:`secondary`,onClick:v,disabled:m.isFetching,children:[m.isFetching?B(q,{className:`h-3.5 w-3.5 animate-spin`}):B(ve,{className:`h-3.5 w-3.5`}),`Refresh`]}),F(p,{onClick:()=>void b(),disabled:i||x.length===0,children:[i?B(q,{className:`h-3.5 w-3.5 animate-spin`}):B(oe,{className:`h-3.5 w-3.5`}),`Export all (`,String(x.length),`)`]})]}),F(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,B(`code`,{children:`debug`}),` mark does not pin retention — this lists the marked tracks that still exist. A track whose media was evicted shows as missing media.`]}),m.isError&&B(y,{message:`Could not load the marked tracks.`}),S&&!m.isError&&B(y,{message:ft}),o!==null&&B(y,{message:o}),m.data?.truncated===!0&&B(y,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(g.data?.vanished.length??0)>0&&F(`p`,{className:`text-xs text-foreground-subtle`,children:[String(g.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),B(D,{children:m.isLoading?B(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`}):x.length===0?F(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[B(ze,{className:`h-5 w-5 text-foreground-subtle`}),B(`p`,{className:`text-xs text-foreground-subtle`,children:`No track is marked for debug. Mark one from a track's actions to see it here.`})]}):x.map(e=>B(ht,{track:e,report:_.get(e.trackId),cameraName:d.get(e.deviceId)??`Camera ${String(e.deviceId)}`,analyzing:g.isFetching},e.trackId))})]})})}function _t(e){return e.subLabel??e.label}var vt=720*60*60*1e3;function yt(e){let t=[];for(let n of e)t.push(...n);return t}function bt(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function xt(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function St(e,t){return`${String(e)}:${t}`}function Ct(e,t){let n=new Map,r=new Set;for(let i of e){let e=St(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function wt(e,t){return{since:e.fromMs??t-vt,until:e.toMs??t}}var Tt=typeof O==`function`,Et=`Track deletion arrives with the next server update`;function Dt(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Ot=Tt?O:Dt,kt=200,At=3e4;function jt(e){let t=G(),n=R({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:At,refetchInterval:At,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:kt,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:bt(yt(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}P();var Mt=[`events-feed`],Nt=2e3;function Pt(e){let t=re(),n=e?.paused===!0,r=N(t);r.current=t;let i=N(n);i.current=n;let[a,o]=z(!1),s=M(()=>{r.current.invalidateQueries({queryKey:Mt})},[]),c=N(void 0);c.current||=_e({delayMs:Nt,invalidate:()=>{i.current?o(!0):s()}}),V(()=>()=>c.current?.cancel(),[]),V(()=>{n||!a||(o(!1),s())},[n,a,s]);let l=M(()=>{o(!1),s()},[s]);return w(H.PipelineAnalyticsDetectionEvent,()=>{c.current?.trigger()}),w(H.PipelineAnalyticsTrackEnded,()=>{c.current?.trigger()}),{pending:a,refreshNow:l}}P();function Ft({groups:e,selected:t,onChange:n,loading:r=!1}){let{t:i}=Me(),[a,o]=z(!1),[s,c]=z(``),[l,u]=z(new Set),f=s.trim().toLowerCase(),p=e=>f.length===0||d(e,i).toLowerCase().includes(f),m=L(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>p(t)||p(e.macro))})).filter(e=>p(e.macro)||e.subs.length>0),[e,f]),h=e=>u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),g=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},_=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},v=()=>n(new Set),y=t.size;return F(`div`,{className:`relative`,children:[F(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${y>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[B(Ge,{className:`h-3.5 w-3.5`}),y>0?`Kinds (${String(y)})`:`Kinds`,B(we,{className:`h-3 w-3`})]}),a&&F(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[F(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[B(ye,{className:`h-3.5 w-3.5 text-foreground-subtle`}),B(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),y>0&&B(`button`,{type:`button`,onClick:v,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),m.length===0&&B(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:r?`Loading kinds…`:f.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),m.map(e=>{let n=j(e.macro.iconId),r=l.has(e.macro.kind)||f.length>0,a=t.has(e.macro.kind);return F(`div`,{className:`mb-0.5`,children:[F(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?B(`button`,{type:`button`,onClick:()=>h(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:B(r?we:De,{className:`h-3 w-3`})}):B(`span`,{className:`w-3`}),F(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[B(`input`,{type:`checkbox`,checked:a,onChange:()=>g(e),className:`accent-primary`}),B(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),B(`span`,{className:`font-medium`,children:d(e.macro,i)})]})]}),r&&e.subs.map(e=>{let n=j(e.iconId);return F(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[B(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>_(e.kind),className:`accent-primary`}),B(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),B(`span`,{children:d(e,i)})]},e.kind)})]},e.macro.kind)})]})]})}function It(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function Lt(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var Rt=new Set([`detection`,`package`]);function zt(e,t){return[...It(e,t).values()].filter(e=>e.parentKind===null&&Rt.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Bt(e,t){let n=It(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,Lt(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}P();var Vt=1400,Ht=`Admin-gated URL — opens only inside an authenticated session`;function Ut({label:e,value:t,title:n}){let[r,i]=z(!1);return V(()=>{if(!r)return;let e=setTimeout(()=>i(!1),Vt);return()=>clearTimeout(e)},[r]),F(`button`,{type:`button`,onClick:M(()=>{(async()=>{try{await navigator.clipboard.writeText(t),i(!0)}catch{window.prompt(`Copy the media URL:`,t)}})()},[t]),title:n,"aria-label":`Copy ${e} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${r?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[B(r?Te:ae,{className:`h-2.5 w-2.5 shrink-0`}),B(`span`,{className:`truncate`,children:r?`Copied`:e})]})}function Wt({localUrl:e,publicUrl:t}){return F(`div`,{className:`flex flex-wrap gap-1`,children:[B(Ut,{label:`Local`,value:e,title:`Copy LAN URL — ${Ht}`}),t&&B(Ut,{label:`Public`,value:t,title:`Copy public URL — ${Ht}`})]})}var Gt={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function Kt(e){return e in Gt}function qt(e){return Kt(e)?Gt[e]:e}function Jt(e,t){return`${e}${Ie}/${encodeURIComponent(t)}`}P();var Yt=3e4;function Xt(e){let[t,n]=z(null),r=M(e=>{n(t=>t??e)},[]);return V(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?B(Zt,{onOrigin:r}):null}}function Zt({onOrigin:e}){let{data:t}=_({capName:`network-access`});return B(ne,{children:(t??[]).map(t=>B(Qt,{addonId:t.addonId,onOrigin:e},t.addonId))})}function Qt({addonId:e,onOrigin:t}){let{data:n}=l({addonId:e},{refetchInterval:Yt,retry:!1});return V(()=>{let e=n?U.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var $t=typeof b==`function`,en=`Track flags arrive with the next server update`;function tn(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var nn=$t?b:tn;function rn(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e))return null;let{trackId:t,markForTrain:n,debug:r}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`?null:{trackId:t,markForTrain:n,debug:r}}P();function an({label:e,hint:t,checked:n,disabled:r,title:i,icon:a,onToggle:o}){return F(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:r,title:i,onClick:o,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[B(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:a}),F(`span`,{className:`min-w-0 flex-1`,children:[B(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),B(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),B(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:B(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function on({deviceId:e,trackId:t,markForTrain:n,debug:r,onChange:i}){let a=nn(),[o,s]=z(null),c=o?.markForTrain??n===!0,l=o?.debug??r===!0,u=!$t||a.isPending,d=$t?void 0:en,f=n=>{u||(async()=>{try{let r=rn(await a.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;s(r),i?.(r)}catch(e){let t=e instanceof Error?e.message:``;window.alert(t===``?`Could not update this track. Check the server logs.`:`Could not update this track — ${t}`)}})()};return F(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[B(an,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:c,disabled:u,...d===void 0?{}:{title:d},icon:B(Ue,{className:`h-4 w-4`}),onToggle:()=>f({markForTrain:!c})}),B(an,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:l,disabled:u,...d===void 0?{}:{title:d},icon:B(ze,{className:`h-4 w-4`}),onToggle:()=>f({debug:!l})})]})}var X=100,sn=120,cn={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function ln(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function un(e,t,n){if(e.length===0||t===null)return cn;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return cn;let a=ln(e,n?.maxPoints??sn).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}P();var dn=15e3,fn=window.location.origin,pn=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),mn=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function hn(e){let[t,n]=z(null);return V(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function gn({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:F(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&B(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&B(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>B(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>B(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:B(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&B(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&B(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function $({label:e,value:t,mono:n}){return F(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[B(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),B(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function _n({row:t,cameraName:n,deleteAvailable:r,onClose:i,onDeleted:a,onFlagsChanged:o}){let c=G(),l=Ot(),d=t!==null,h=t?.deviceId??0,g=t?.trackId??``,_=t?.bestEventId??``,v=t?.timestamp??0,y=t?.windowMs??0,{data:b}=u({deviceId:h,trackId:g},{enabled:d}),{data:x}=e({trackId:g},{enabled:d}),{data:S}=m({eventId:_},{enabled:d&&_!==``}),{data:C}=E({deviceId:h,since:v-dn,until:v+y+dn},{enabled:d}),[w,T]=z(null),[D,O]=z(!1),{publicOrigin:k,probes:ee}=Xt(d);V(()=>{T(null)},[h,g]);let A=L(()=>{let e=x??[],t=S??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[x,S]),j=Pe(A?`${Ie}/${encodeURIComponent(A.key)}`:void 0),N=L(()=>{let e=new Set,t=[];for(let n of[...S??[],...x??[]])!n.base64||e.has(n.key)||(e.add(n.key),t.push(n));return t},[S,x]),P=L(()=>N.find(e=>pn.has(e.kind))??null,[N]),I=hn(P?`data:image/jpeg;base64,${P.base64}`:null),te=L(()=>un(b?.positions??[],I,{snapshots:(b?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[b?.positions,b?.snapshots,I]),R=M(e=>{let t=N.find(t=>t.key===e);t&&T(t)},[N]);if(t===null)return null;let re=w?`data:image/jpeg;base64,${w.base64}`:j.src,H=w?.kind??A?.kind,U=H!==void 0&&mn.has(H)&&I!==null&&(b?.positions.length??0)>=2,W=C&&C.length>0?C[0]:null,ie=()=>{W&&(O(!0),(async()=>{try{let e=await c.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:W.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{O(!1)}})())},ae=()=>{!r||l.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await l.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),a()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},oe=Math.round(t.importance*100),se=b?.importanceReason?`${String(oe)}% · ${b.importanceReason}`:`${String(oe)}%`,K=b?.zonesVisited&&b.zonesVisited.length>0?b.zonesVisited.join(`, `):`—`,le=b?.audioLabels&&b.audioLabels.length>0?b.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,ue=b?b.totalDistance.toFixed(2):`—`,pe=me(b?b.firstSeen:v),he=b?me(b.lastSeen):`—`;return B(s,{open:!0,onOpenChange:e=>!e&&i(),children:F(f,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex 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:h-auto 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:[F(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[F(`div`,{className:`min-w-0`,children:[F(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,_t(t)?F(`span`,{className:`text-foreground-subtle`,children:[` · `,_t(t)]}):null]}),B(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),B(`button`,{type:`button`,onClick:i,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:B(ke,{className:`h-4 w-4`})})]}),F(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[re?B(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:B(fe,{src:re,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:U?B(gn,{overlay:te,onPickSnapshot:R}):void 0})}):B(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:j.failed?F(ne,{children:[B(de,{className:`h-8 w-8 opacity-60`}),B(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):B(q,{className:`h-6 w-6 animate-spin opacity-70`})}),N.length>0&&B(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:N.map(e=>{let t=`data:image/jpeg;base64,${e.base64}`,n=qt(e.kind),r=Jt(fn,e.key),i=k?Jt(k,e.key):null;return F(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[B(`button`,{type:`button`,onClick:()=>T(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${me(e.timestamp)}`,children:B(`img`,{src:t,alt:n,className:`h-full w-full object-cover`})}),F(`figcaption`,{className:`min-w-0 px-0.5`,children:[B(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),B(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:me(e.timestamp),children:ce(e.timestamp)})]}),B(Wt,{localUrl:r,publicUrl:i})]},e.key)})}),ee,W&&F(p,{variant:`secondary`,onClick:ie,disabled:D,children:[D?B(q,{className:`h-3.5 w-3.5 animate-spin`}):B(Ce,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),B(on,{deviceId:t.deviceId,trackId:t.trackId,...(b?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:b?.markForTrain??t.markForTrain},...(b?.debug??t.debug)===void 0?{}:{debug:b?.debug??t.debug},onChange:o}),F(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[B($,{label:`Camera`,value:n}),B($,{label:`Class`,value:t.className}),B($,{label:`Label`,value:t.label??`—`}),B($,{label:`Sub-label`,value:t.subLabel??`—`}),B($,{label:`Importance`,value:se}),B($,{label:`Zones visited`,value:K}),B($,{label:`Audio heard`,value:le}),B($,{label:`Total distance`,value:ue}),B($,{label:`First seen`,value:pe}),B($,{label:`Last seen`,value:he}),B($,{label:`Track`,value:t.trackId,mono:!0})]})]}),B(`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:B(`span`,{title:r?void 0:Et,children:F(p,{variant:`secondary`,onClick:ae,disabled:!r||l.isPending,children:[l.isPending?B(q,{className:`h-3.5 w-3.5 animate-spin`}):B(je,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function vn(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function yn({row:e,cameraName:t,nowMs:n,onOpenDetail:r,selected:i=!1,onToggleSelect:a,score:o}){let s=Pe(e.bestEventId?`${Ie}/${e.bestEventId}`:void 0),c=Math.round(e.importance*100),l=o===void 0?void 0:Math.round(o*100),u=vn(e.windowMs),d=()=>r(e);return F(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[F(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[s.src?B(`img`,{src:s.src,alt:`Event from ${t}`,onClick:d,className:`h-full w-full cursor-zoom-in object-cover`}):B(`button`,{type:`button`,onClick:d,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:s.failed?`Key-event media unavailable`:`No key-event media`,children:B(de,{className:`h-6 w-6 opacity-60`})}),a&&B(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(St(e.deviceId,e.trackId))},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?B(be,{className:`h-4 w-4 text-primary`}):B(xe,{className:`h-4 w-4`})}),l!==void 0&&F(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(l),`%`]}),c>0&&B(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(c)}),(e.markForTrain===!0||e.debug===!0)&&F(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&B(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:B(Ue,{className:`h-3 w-3`})}),e.debug===!0&&B(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:B(ze,{className:`h-3 w-3`})})]})]}),F(`button`,{type:`button`,onClick:d,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[F(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,_t(e)?F(`span`,{className:`text-foreground-subtle`,children:[` · `,_t(e)]}):null]}),B(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),F(`div`,{className:`flex items-center justify-between gap-2`,children:[B(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:le(e.timestamp,n)}),u&&B(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:u})]})]})]})}P();function bn(){let[e,t]=z(!1),n=N(null),[r,i]=z(0),a=M(e=>{n.current!==e&&(n.current=e,i(e=>e+1))},[]);return V(()=>{let e=n.current;if(!e||typeof IntersectionObserver>`u`){t(!1);return}let r=new IntersectionObserver(e=>{let n=e[e.length-1];n&&t(!n.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return r.observe(e),()=>r.disconnect()},[r]),{ref:a,scrolledPast:e}}P();var xn=[`events-feed`],Sn=60,Cn=[{value:`importance`,label:`Importance`,icon:Re},{value:`time`,label:`Recent`,icon:ie}];function wn(){let e=re(),[t,n]=z(ge),[r,i]=z(new Set),[a,o]=z(new Set),[s,l]=z(0),[u,d]=z(`time`),[f,m]=z(new Set),[h,g]=z(null),[_,v]=z(()=>Date.now());V(()=>{let e=setInterval(()=>v(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:y,until:b}=L(()=>wt({fromMs:t.fromMs,toMs:t.toMs},_),[t.fromMs,t.toMs,_]),S=bn(),{pending:C,refreshNow:w}=Pt({paused:h!==null||f.size>0||S.scrolledPast}),{data:T}=c({}),E=L(()=>(T??[]).filter(e=>e.type===W.Camera),[T]),D=L(()=>E.map(e=>e.id),[E]),{data:O,isLoading:k}=x({deviceIds:D},{enabled:D.length>0,staleTime:5*6e4}),ee=L(()=>Bt(O??[],r),[O,r]),A=Ot(),j=A.isPending,{rows:M,isLoading:N}=jt({deviceIds:D,since:y,until:b,minImportance:s>0?s:void 0,classFilter:a.size===1?[...a][0]:void 0}),P=L(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),I=e=>P.get(e)??`Camera #${String(e)}`,te=L(()=>K(M).map(e=>({id:e,name:I(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[M,P]),R=L(()=>bt(xt(M,{cameras:r,classes:a,minImportance:s}),u),[M,r,a,s,u]),H=pe(R,Sn,L(()=>JSON.stringify([[...r].sort((e,t)=>e-t),[...a].sort(),s,u,y,b]),[r,a,s,u,y,b])),U=()=>{e.invalidateQueries({queryKey:xn})},G=()=>m(new Set);function ie(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ae(){if(f.size===0||!Tt)return;let e=Ct(M,f),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>A.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{U();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(St(o,e));else t.push(o)}),m(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>I(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let oe=R.length!==M.length;return F(`div`,{className:`relative space-y-3`,children:[F(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[B(he,{onChange:n}),B(ue,{cameras:te,selected:r,onChange:i}),B(Ft,{groups:ee,selected:a,onChange:o,loading:k}),F(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[B(`span`,{children:`Min score`}),B(`input`,{type:`range`,min:0,max:1,step:.05,value:s,onChange:e=>l(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),B(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(s*100)})]}),B(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Cn.map(e=>{let t=e.icon;return F(`button`,{type:`button`,onClick:()=>d(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${u===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[B(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!N&&B(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:oe?`${String(R.length)} of ${String(M.length)} events`:`${String(R.length)} event${R.length===1?``:`s`}`})]}),f.size>0&&F(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[F(`span`,{className:`text-xs font-medium text-foreground`,children:[f.size,` selected`]}),F(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[B(`span`,{title:Tt?void 0:`Track deletion arrives with the next server update`,children:F(p,{variant:`secondary`,onClick:ae,disabled:!Tt||j,children:[j?B(q,{className:`h-3.5 w-3.5 animate-spin`}):B(je,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),B(p,{variant:`ghost`,onClick:G,disabled:j,children:B(ke,{className:`h-3.5 w-3.5`})})]})]}),N&&F(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[B(q,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!N&&R.length===0&&B(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),C&&B(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:B(`button`,{type:`button`,onClick:w,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!N&&R.length>0&&F(ne,{children:[B(`div`,{ref:S.ref,"aria-hidden":!0,className:`h-0`}),B(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:H.pageItems.map(e=>B(yn,{row:e,cameraName:I(e.deviceId),nowMs:_,selected:f.has(St(e.deviceId,e.trackId)),onToggleSelect:ie,onOpenDetail:g},St(e.deviceId,e.trackId)))}),B(se,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`events`})]}),h&&B(_n,{row:h,cameraName:I(h.deviceId),deleteAvailable:Tt,onClose:()=>g(null),onDeleted:()=>{U(),g(null)},onFlagsChanged:e=>{g(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug}:t)}})]})}P();var Tn=50,En=350,Dn=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function On(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function kn({onActiveChange:e}){let[t,n]=z(``),[r,i]=z(.2),[o,s]=z(null),[l,u]=z(null),[f,p]=z(null),m=a(t,En).trim(),h=m.length>0;V(()=>{e(h)},[h,e]);let[g,_]=z(()=>Date.now());V(()=>{let e=setInterval(()=>_(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:v}=c({}),y=L(()=>(v??[]).filter(e=>e.type===W.Camera),[v]),b=L(()=>{let e=new Map;for(let t of v??[])e.set(t.id,t.name);return e},[v]),S=e=>b.get(e)??`Camera #${String(e)}`,w=L(()=>y.map(e=>e.id),[y]),{data:T}=x({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),E=L(()=>zt(T??[],new Set(l===null?[]:[l])),[T,l]);V(()=>{o!==null&&(E.some(e=>e.kind===o)||s(null))},[E,o]);let{data:D,isFetching:O,isError:k,error:ee}=C({text:m,minScore:r,limit:Tn,classFilter:o??void 0,deviceId:l??void 0},{enabled:h}),A=L(()=>[...D??[]].sort((e,t)=>t.score-e.score).map(e=>({...On(e),score:e.score})),[D]);function j(e){s(t=>t===e?null:e)}return F(`div`,{className:`space-y-3`,children:[F(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[F(`div`,{className:`flex flex-wrap items-center gap-2`,children:[F(`div`,{className:`relative min-w-[16rem] flex-1`,children:[B(ye,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),B(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&B(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:B(ke,{className:`h-3.5 w-3.5`})})]}),O&&h&&B(q,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),F(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[B(`div`,{className:`flex items-center gap-1`,children:E.map(e=>B(`button`,{type:`button`,onClick:()=>j(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${o===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:d(e)},e.kind))}),F(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[B(`span`,{children:`Camera`}),F(`select`,{value:l===null?``:String(l),onChange:e=>u(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[B(`option`,{value:``,children:`All`}),y.map(e=>B(`option`,{value:String(e.id),children:e.name},e.id))]})]}),F(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[B(`span`,{children:`Match`}),B(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Dn.map(e=>B(`button`,{type:`button`,onClick:()=>i(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${r===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),h&&!O&&!k&&F(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[A.length,` match`,A.length===1?``:`es`]})]})]}),h&&F(`div`,{className:`space-y-3`,children:[k&&F(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,ee instanceof Error?ee.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!k&&O&&A.length===0&&F(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[B(q,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!k&&!O&&A.length===0&&F(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,m,`”. Try a looser match threshold or a different phrasing.`]}),!k&&A.length>0&&B(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:A.map(e=>B(yn,{row:e,cameraName:S(e.deviceId),nowMs:g,score:e.score,onOpenDetail:p},e.id))})]}),f&&B(_n,{row:f,cameraName:S(f.deviceId),deleteAvailable:Tt,onClose:()=>p(null),onDeleted:()=>p(null)})]})}var An=15e3;function jn(e){let t=G(),n=R({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:An,refetchInterval:An,queryFn:async()=>((await t.trpcClient.zoneAnalytics.getCurrentSnapshot.query({deviceId:e}))?.stationaryObjects??[]).map(t=>({...t,deviceId:e}))}))});return{rows:n.flatMap(e=>e.data??[]).toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n.some(e=>e.isLoading)}}P();function Mn(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function Nn({row:e,cameraName:t,nowMs:n}){let r=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,i=Pe(r?`${Ie}/${r}`:void 0);return F(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[F(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?B(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):B(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:B(We,{className:`h-6 w-6`})}),B(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),F(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[B(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),F(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Mn(n,e.becameStationaryAt)]})]})]})}function Pn(){let[e,t]=z(!1),n=Date.now(),{data:r}=c({}),i=L(()=>(r??[]).filter(e=>e.type===W.Camera),[r]),a=L(()=>i.map(e=>e.id),[i]),o=L(()=>{let e=new Map;for(let t of i)e.set(t.id,t.name);return e},[i]),{rows:s}=jn(a);return s.length===0?null:F(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[F(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[B(e?we:De,{className:`h-4 w-4 text-foreground-subtle`}),B(We,{className:`h-4 w-4 text-foreground-subtle`}),B(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),B(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:s.length}),B(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&B(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:s.map(e=>B(Nn,{row:e,cameraName:o.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}P();function Fn(){let[e,t]=z(!1);return B(Ne,{children:F(`section`,{className:`space-y-3`,children:[B(kn,{onActiveChange:t}),!e&&B(Pn,{}),!e&&B(wn,{})]})})}var In=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Ln=new Set(In);function Rn(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Ln.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function zn({annotations:e,selectedIndex:n,onSelect:i,onChange:a,onDelete:s}){return e.length===0?F(`p`,{className:`text-[11px] text-foreground-subtle p-3`,children:[`No subject on this frame yet. Drag on the image to draw one, or ask the pipeline for a proposal. Annotate `,B(`strong`,{children:`every`}),` subject — a frame with one box and three unlabelled people teaches the model that two thirds of the people in it are background.`]}):B(`ul`,{className:`divide-y divide-border`,children:e.map((e,c)=>{let l=c===n,u=Rn(e.label),d=Rn(e.subLabel);return F(`li`,{className:`p-2.5 space-y-1.5 ${l?`bg-surface-hover`:``}`,onFocus:()=>{i(c)},children:[F(`div`,{className:`flex items-center gap-2`,children:[B(t,{className:`w-28`,value:e.macroClass,options:In.map(e=>({value:e,label:e})),onChange:e=>{let t=In.find(t=>t===e.target.value);t!==void 0&&a(c,{macroClass:t})}}),B(t,{className:`w-32`,value:e.kind,options:[{value:`subject`,label:`subject`},{value:`model_error`,label:`model error`}],onChange:e=>{a(c,{kind:e.target.value===`model_error`?`model_error`:`subject`})}}),e.source===`assist`&&F(r,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),B(p,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{s(c)},children:B(je,{className:`h-3 w-3`})})]}),F(`div`,{className:`flex items-center gap-2`,children:[B(o,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{a(c,{label:e.target.value})}}),B(o,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:e=>{a(c,{subLabel:e.target.value})}})]}),u!==null&&B(`p`,{className:`text-[11px] text-danger`,children:u}),d!==null&&B(`p`,{className:`text-[11px] text-danger`,children:d})]},`${String(c)}-${String(e.bbox.x)}`)})})}function Bn(e){return e.every(e=>Rn(e.label)===null&&Rn(e.subLabel)===null&&Ln.has(e.macroClass))}function Vn(e){return e<0?0:e>1?1:e}function Hn(e,t,n,r){if(!(e>0)||!(t>0)||!(n>0)||!(r>0))return null;let i=Math.min(e/n,t/r),a=n*i,o=r*i;return{left:(e-a)/2,top:(t-o)/2,width:a,height:o}}function Un(e,t,n){return{x:Vn((e-n.left)/n.width),y:Vn((t-n.top)/n.height)}}function Wn(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function Gn(e){return e.w>=.01&&e.h>=.01}function Kn(e,t){return{left:t.left+e.x*t.width,top:t.top+e.y*t.height,width:e.w*t.width,height:e.h*t.height}}function qn(e,t){let n=-1,r=1/0;return e.forEach((e,i)=>{if(!(t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h))return;let a=e.w*e.h;a<r&&(n=i,r=a)}),n}P();function Jn({imageSrc:e,imageWidth:t,imageHeight:n,boxes:r,selectedIndex:i,onSelect:a,onDraw:o}){let s=N(null),[c,l]=z({w:0,h:0}),[u,d]=z(null);I(()=>{let e=s.current;if(e===null)return;let t=new ResizeObserver(()=>{l({w:e.clientWidth,h:e.clientHeight})});return t.observe(e),l({w:e.clientWidth,h:e.clientHeight}),()=>{t.disconnect()}},[]);let f=Hn(c.w,c.h,t,n),p=M(e=>{let t=s.current;if(t===null||f===null)return null;let n=t.getBoundingClientRect();return Un(e.clientX-n.left,e.clientY-n.top,f)},[f]);return F(`div`,{ref:s,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none`,onPointerDown:e=>{let t=p(e);t!==null&&(e.currentTarget.setPointerCapture(e.pointerId),d({start:t,current:Wn(t,t)}))},onPointerMove:e=>{if(u===null)return;let t=p(e);t!==null&&d({start:u.start,current:Wn(u.start,t)})},onPointerUp:()=>{if(u===null)return;let e=u.current;d(null),Gn(e)?o(e):a(qn(r.map(e=>e.bbox),u.start))},children:[B(`img`,{src:e,alt:`Frame being annotated`,className:`absolute inset-0 w-full h-full object-contain pointer-events-none`}),f!==null&&r.map((e,t)=>{let n=Kn(e.bbox,f),r=e.kind===`model_error`,a=t===i,o=r?`#ef4444`:a?`#22c55e`:`#3b82f6`;return B(`div`,{className:`absolute pointer-events-none`,style:{left:n.left,top:n.top,width:n.width,height:n.height,border:`${a?`2px`:`1px`} ${r?`dashed`:`solid`} ${o}`,opacity:e.source===`assist`&&!a?.65:1},children:F(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded`,style:{background:o,color:`#08121f`},children:[e.label??e.macroClass,r?` ✕`:``]})},`${String(t)}-${String(e.bbox.x)}-${String(e.bbox.y)}`)}),u!==null&&f!==null&&B(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:Kn(u.current,f)})]})}function Yn(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function Xn({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c}){let l=new Set(t.map(e=>e.sourceMediaKey)),u=e.filter(e=>!l.has(e.mediaKey));return F(`div`,{className:`space-y-3`,children:[F(`section`,{children:[F(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`In the dataset (`,t.length,`)`]}),t.length===0?B(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No frame copied yet. Selecting a frame copies it into retrain storage immediately — the dataset stops depending on the track's own media from that moment.`}):B(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>B(`li`,{children:F(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[F(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{s(e.frameId)},children:[B(Te,{className:`h-3 w-3 text-success`}),B(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),F(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,Yn(e.sizeBytes)]})]}),F(`button`,{type:`button`,"aria-label":`Remove this frame from the dataset`,className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-danger`,onClick:()=>{c(e.frameId)},children:[B(je,{className:`h-3 w-3`}),`remove`]})]})},e.frameId))})]}),F(`section`,{children:[F(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,u.length,`)`]}),u.length===0?B(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.length===0?`This track has no whole, unannotated frame left — its media aged out before it was marked. Anything already copied above is still usable.`:`Every available frame is already in the dataset.`}):B(`ul`,{className:`flex flex-wrap gap-2`,children:u.map(e=>{let t=i.get(e.mediaKey);return F(`li`,{children:[F(p,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaKey)},children:[a?B(q,{className:`h-3 w-3 animate-spin`}):B(t===void 0?He:de,{className:`h-3 w-3`}),B(`span`,{className:`ml-1`,children:e.kind}),B(`span`,{className:`ml-1 text-foreground-subtle`,children:Yn(e.sizeBytes)})]}),t!==void 0&&B(r,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaKey)})})]})]})}function Zn(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var Qn={untouched:{icon:Ve,label:`to do`,variant:`default`},started:{icon:Be,label:`frames only`,variant:`info`},ready:{icon:Ee,label:`annotated`,variant:`success`}};function $n(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function er({tracks:e,isLoading:t,selectedTrackId:n,deviceNames:i,onSelect:a}){return t?F(`div`,{className:`flex items-center gap-2 p-4 text-xs text-foreground-subtle`,children:[B(q,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?B(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Nothing in staging. Mark a track for training from the viewer or the Events grid and it appears here.`}):B(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=Qn[Zn(e)],o=t.icon;return B(`li`,{children:F(`button`,{type:`button`,onClick:()=>{a(e)},className:`w-full text-left px-3 py-2 flex items-start gap-2 hover:bg-surface-hover ${e.trackId===n?`bg-surface-hover`:``}`,children:[B(o,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),F(`span`,{className:`min-w-0 flex-1`,children:[F(`span`,{className:`flex items-center gap-2`,children:[B(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),B(r,{variant:t.variant,children:t.label})]}),F(`span`,{className:`block text-[11px] text-foreground-subtle truncate`,children:[i.get(e.deviceId)??`Camera ${String(e.deviceId)}`,` ·`,` `,$n(e.lastSeen)]}),F(`span`,{className:`block text-[11px] text-foreground-muted`,children:[e.frameCount,` frame`,e.frameCount===1?``:`s`,` ·`,` `,e.annotationCount,` subject`,e.annotationCount===1?``:`s`]})]})]})},e.trackId)})})}P();var tr=`person`;function nr(){let[e,t]=z(null),[a,o]=z(null),[s,l]=z([]),[u,d]=z(-1),[f,m]=z(new Map),[_,y]=z(null),b=c({projection:`slim`,isCamera:!0}),x=L(()=>{let e=new Map;for(let t of b.data??[])e.set(t.id,t.name);return e},[b.data]),C=S({}),w=k({trackId:e?.trackId??``},{enabled:e!==null}),E=T({trackId:e?.trackId??``},{enabled:e!==null}),D=h({frameId:a??``},{enabled:a!==null}),O=A(),j=i(),N=g(),P=v(),I=n(),te=ee();V(()=>{if(a===null){l([]);return}l((E.data??[]).filter(e=>e.mediaKey===a).map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))),d(-1)},[a,E.data]),V(()=>{let e=w.data?.copies??[];a===null&&e.length>0&&o(e[0].frameId)},[w.data,a]);let R=M(e=>{t(e),o(null),l([]),m(new Map),y(null)},[]),re=M(async t=>{if(e===null)return;let n=await O.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,mediaKeys:[t]});if(n.refused.length>0){let e=new Map(f);for(let t of n.refused)e.set(t.sourceMediaKey,t.reason);m(e)}n.copied.length>0&&o(n.copied[0].frameId),await w.refetch(),await C.refetch()},[e,O,f,w,C]),H=M(async t=>{e!==null&&(await j.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,frameId:t}),a===t&&o(null),await w.refetch(),await E.refetch(),await C.refetch())},[e,j,a,w,E,C]),U=M(async t=>{if(e===null||a===null)return;y(null);let n=await N.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,frameId:a,subject:t===`package`?{kind:`package`}:{kind:`objects`,modelId:`yolo26n`,minScore:.3}});if(n.kind===`refused`){y(n.reason===`no-zone`?`A package proposal runs on the zone crop only — this camera has no zone, and running the detector on the whole frame at 0.35 proposes furniture.`:`The pipeline refused: ${n.reason}${n.detail===void 0?``:` — ${n.detail}`}`);return}l(e=>[...e,...n.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))]),y(`${n.proposals.length} proposal${n.proposals.length===1?``:`s`} from ${n.modelId}`+(n.belowThreshold>0?` — ${n.belowThreshold} more were below ${n.minScore.toFixed(2)}`:``))},[e,a,N]),W=M(e=>{l(t=>[...t,{bbox:e,macroClass:tr,kind:`subject`,source:`operator`}]),d(s.length)},[s.length]),G=M((e,t)=>{l(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),ie=M(e=>{l(t=>t.filter((t,n)=>n!==e)),d(-1)},[]),ae=M(async()=>{e===null||a===null||(await P.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,frameId:a,annotations:s.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{},...e.subLabel!==void 0&&e.subLabel!==``?{subLabel:e.subLabel}:{},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))}),await E.refetch(),await C.refetch(),y(`Annotations saved.`))},[e,a,s,P,E,C]),oe=M(async()=>{if(e===null)return;let n=await I.mutateAsync({deviceId:e.deviceId,trackId:e.trackId});y(n.changed?`Track completed — it is now trained, and its own media is evictable again.`:n.reason===`no-frames-copied`?`Refused: no frame was ever copied into the dataset. Completing would let retention delete material nothing was extracted from.`:`Refused: ${n.reason??`unknown`}`),await C.refetch(),n.changed&&t(null)},[e,I,C]),se=M(async()=>{if(e===null)return;let t=await te.mutateAsync({deviceId:e.deviceId,trackId:e.trackId});y(t.changed?`Track returned to staging. Its copies and annotations were left alone.`:`Refused: ${t.reason??`unknown`}`),await C.refetch()},[e,te,C]),K=D.data,ce=Bn(s)&&a!==null;return F(Ne,{subtitle:`Turn the tracks you marked for training into an annotated dataset. Selecting a frame copies it — the dataset never depends on media that can be swept.`,actions:e===null?null:F(`div`,{className:`flex items-center gap-2`,children:[F(p,{variant:`secondary`,size:`sm`,onClick:()=>void se(),children:[B(Se,{className:`h-3 w-3`}),B(`span`,{className:`ml-1`,children:`Back to staging`})]}),F(p,{size:`sm`,onClick:()=>void oe(),children:[B(Ue,{className:`h-3 w-3`}),B(`span`,{className:`ml-1`,children:`Complete track`})]})]}),children:[_!==null&&B(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:_}),F(`div`,{className:`grid grid-cols-1 lg:grid-cols-[minmax(0,260px)_minmax(0,1fr)] gap-4`,children:[F(`aside`,{className:`rounded-md border border-border bg-surface overflow-hidden`,children:[F(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between`,children:[B(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Staging`}),B(r,{children:C.data?.length??0})]}),B(er,{tracks:C.data??[],isLoading:C.isLoading,selectedTrackId:e?.trackId??null,deviceNames:x,onSelect:R})]}),B(`section`,{className:`space-y-3 min-w-0`,children:e===null?B(`p`,{className:`text-xs text-foreground-subtle`,children:`Pick a track from the staging list to start annotating it.`}):F(ne,{children:[B(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:B(Xn,{candidates:w.data?.candidates??[],copies:w.data?.copies??[],activeFrameId:a,refusals:f,isSelecting:O.isPending,onSelectCandidate:e=>void re(e),onOpenCopy:o,onRemoveCopy:e=>void H(e)})}),a!==null&&F(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[B(`div`,{className:`rounded-md border border-border overflow-hidden`,children:K===void 0?F(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[B(q,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):B(Jn,{imageSrc:`data:image/jpeg;base64,${K.base64}`,imageWidth:K.width,imageHeight:K.height,boxes:s,selectedIndex:u,onSelect:d,onDraw:W})}),F(`div`,{className:`rounded-md border border-border bg-surface flex flex-col min-h-0`,children:[F(`div`,{className:`px-3 py-2 border-b border-border flex items-center gap-2`,children:[B(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),F(p,{variant:`secondary`,size:`sm`,disabled:N.isPending,onClick:()=>void U(`objects`),children:[B(Ae,{className:`h-3 w-3`}),B(`span`,{className:`ml-1`,children:`Propose`})]}),F(p,{variant:`secondary`,size:`sm`,disabled:N.isPending,onClick:()=>void U(`package`),children:[B(Ae,{className:`h-3 w-3`}),B(`span`,{className:`ml-1`,children:`Packages`})]})]}),B(`div`,{className:`flex-1 overflow-y-auto`,children:B(zn,{annotations:s,selectedIndex:u,onSelect:d,onChange:G,onDelete:ie})}),F(`div`,{className:`px-3 py-2 border-t border-border flex items-center justify-between`,children:[F(`span`,{className:`text-[11px] text-foreground-subtle`,children:[s.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),B(p,{size:`sm`,disabled:!ce||P.isPending,onClick:()=>void ae(),children:`Save frame`})]})]})]})]})})]})]})}function rr(){return B(`div`,{className:`flex flex-col p-4`,children:B(Le,{tabs:[{id:`feed`,label:`Feed`,icon:Oe,content:B(Fn,{})},{id:`retrain`,label:`Retrain`,icon:Ue,content:B(nr,{})},{id:`debug`,label:`Debug`,icon:ze,content:B(gt,{})}]})})}export{rr as EventsPage};
@@ -1 +0,0 @@
1
- import{$a as e,Ga as t,Ha as n,Ja as r,Ka as i,Qa as a,Ua as o,Va as s,Wa as c,Xa as l,Ya as u,Yo as d,Za as f,bt as p,c as m,eo as h,qa as g,s as _,so as v,to as y,xo as b,yt as x}from"./src-C0ryWGb4.js";import{Q as S,S as C,W as w,b as T,o as E,q as D,x as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as k}from"./circle-check-big-DFEJsytm.js";import{t as A}from"./copy-B4xsDuLU.js";import{t as j}from"./key-round-C3DZqNmk.js";import{t as ee}from"./plus-CRlbDvh8.js";import{C as M,L as N,S as P,T as F,W as I,f as L,i as R,r as z,s as B,u as V}from"./index-BpMOZW4i.js";import{t as H}from"./AdminPage-Dq33XE9j.js";import{t as U}from"./AdminTabs-D9PvjiYm.js";import{t as W}from"./AddonCollectionPage-C61Ba_jl.js";import{t as G}from"./addon-display-names-DvSEQty-.js";var te=I(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),ne=I(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),re=I(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),K=I(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),ie=I(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);S();function ae({userId:e,username:n,onClose:r}){let i=E(),a=v(),o=t({userId:e}),s=o.data,l=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),u=c({onSuccess:()=>{l(),r()}}),f=o.isLoading?`loading`:s?.enabled?`enrolled`:`not_enrolled`;return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[C(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[C(`div`,{className:`flex items-center gap-2`,children:[O(V,{className:`h-4 w-4 text-primary`}),C(`div`,{children:[O(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),C(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,O(`span`,{className:`font-mono`,children:n})]})]})]}),O(`button`,{onClick:r,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:O(R,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4 space-y-4`,children:[f===`loading`&&C(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[O(P,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),f===`not_enrolled`&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[O(M,{className:`h-4 w-4 mt-0.5 shrink-0`}),C(`div`,{children:[O(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),O(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),f===`enrolled`&&s&&C(T,{children:[C(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[O(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),C(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[O(`div`,{className:`font-medium`,children:`2FA is active`}),C(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,s.confirmedAt?new Date(s.confirmedAt).toLocaleString():`—`]})]})]}),O(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),C(`div`,{className:`flex justify-end gap-2`,children:[O(d,{onClick:r,variant:`secondary`,children:`Close`}),C(`button`,{onClick:async()=>{await a({title:`Remove 2FA`,message:`Remove two-factor authentication for "${n}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&u.mutate({userId:e})},disabled:u.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[u.isPending?O(P,{className:`h-3 w-3 animate-spin`}):O(R,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function oe(){let e=E(),{user:t}=z(),[r,i]=D(!1),[a,s]=D(``),[c,d]=D(``),[f,p]=D(!1),[m,g]=D(null),{data:_,isLoading:x,isError:S}=u(),w=v(),T=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=n({onSuccess:()=>{T(),i(!1),s(``),d(``),p(!1),g(null)},onError:e=>{g(e instanceof Error?e.message:`Failed to create user`)}}),A=o({onSuccess:T}),j=y({onSuccess:T}),M=l({onSuccess:T}),N=h({onSuccess:()=>{T(),I(null)}}),[F,I]=D(null),[U,W]=D(null),G=_??[];async function te(e){await w({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&A.mutate({id:e.id})}async function ne(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await w({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}}function K(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function ie(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return C(H,{children:[O(`div`,{className:`flex items-center justify-end`,children:C(`button`,{onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[O(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),r&&C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-center justify-between`,children:[O(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),O(`button`,{onClick:()=>i(!1),className:`text-foreground-subtle hover:text-foreground`,children:O(R,{className:`h-4 w-4`})})]}),C(`div`,{className:`grid grid-cols-3 gap-3`,children:[C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),O(`input`,{type:`text`,value:a,onChange:e=>s(e.target.value),placeholder:`john`,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`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),O(`input`,{type:`password`,value:c,onChange:e=>d(e.target.value),placeholder:`••••••••`,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`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),C(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[O(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked),className:`rounded border-border focus:ring-primary`}),O(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),m&&O(`p`,{className:`text-[10px] text-danger`,children:m}),C(`div`,{className:`flex justify-end gap-2`,children:[O(`button`,{onClick:()=>i(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>k.mutate({username:a,password:c,isAdmin:f}),disabled:k.isPending||!a||!c,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:k.isPending?`Creating...`:`Create`})]})]}),x&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),S&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!S&&G.length===0&&O(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return O(b,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>C(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[O(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>K(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),O(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return O(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return C(`button`,{onClick:()=>I(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[O(L,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>O(`span`,{className:`text-foreground-subtle`,children:ie(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:n=>{let r=e(n);return C(`div`,{className:`flex items-center justify-end gap-1`,children:[n.id!==t?.id&&n.totpEnabled&&C(`button`,{onClick:()=>W(n),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[O(V,{className:`h-3 w-3`}),`Remove 2FA`]}),C(`button`,{onClick:()=>ne(n),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[O(re,{className:`h-3 w-3`}),`Reset password`]}),C(`button`,{onClick:()=>te(n),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[r?O(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),U&&O(ae,{userId:U.id,username:U.username,onClose:()=>W(null)}),F&&O(se,{user:F,onClose:()=>I(null),onSubmit:e=>N.mutate({userId:F.id,scopes:e}),submitting:N.isPending})]})}function se(e){let{user:t}=z(),n=t?.isAdmin===!0;return O(ce,{...e,callerScopes:n?null:t?.scopes??[]})}function ce({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=D(w(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=m(a);return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:C(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[C(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[C(`div`,{children:[C(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),O(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(R,{className:`h-4 w-4`})})]}),C(`div`,{className:`px-4 py-4`,children:[O(_,{value:a,onChange:o,clampToParent:i,emptyHint:C(T,{children:[`No scopes granted.`,` `,O(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&O(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),C(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?O(P,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}S();var le=`bg-primary/10 text-primary`,ue=`bg-foreground-subtle/10 text-foreground-subtle`;function q(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function de(e){return e?e===`*`?`*`:e.join(`, `):``}function fe(){let t=E(),n=v(),{data:r,isLoading:a}=i(),{data:o}=u(),c=w(()=>r??[],[r]),l=w(()=>o??[],[o]),d=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),p=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[m,h]=D(!1),[g,_]=D(null),y=f({onSuccess:d}),b=s({onSuccess:({token:e,record:t})=>{p(),h(!1),_({token:e,label:t.name})}}),x=e({onSuccess:p}),S=async(e,t)=>{await n({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&y.mutate({id:e})},T=async(e,t)=>{await n({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&x.mutate({id:e})};return C(H,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),C(`button`,{onClick:()=>h(!0),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 disabled:opacity-50`,disabled:l.length===0,title:l.length===0?`Create a user first`:`Issue a scoped token`,children:[O(L,{className:`h-3.5 w-3.5`}),`New token`]})]}),C(J,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[l.length===0&&O(me,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),l.map(e=>O(ge,{userId:e.id,username:e.username,onRevoke:(e,t)=>{T(e,t)},revokePending:x.isPending,revokeId:x.variables?.id},e.id))]}),c.length>0&&O(J,{title:`Legacy API keys`,subtitle:`${c.length} pre-existing — revoke only`,children:O(he,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:c.map(e=>{let t=!!e.isAdmin,n=y.isPending&&y.variables?.id===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?le:ue}`,children:t?`admin`:`regular`})}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:de(e.allowedProviders)||`all`}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>{S(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?O(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),a&&O(pe,{}),m&&O(_e,{users:l.map(e=>({id:e.id,username:e.username})),onClose:()=>h(!1),onSubmit:e=>b.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:b.isPending}),g&&O(ve,{token:g.token,label:g.label,onClose:()=>_(null)})]})}function J({title:e,subtitle:t,children:n}){return C(`div`,{className:`space-y-2`,children:[C(`div`,{className:`flex items-baseline justify-between`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&O(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function pe(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function me({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function he({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),O(`tbody`,{children:t})]})})}function ge({userId:e,username:t,onRevoke:n,revokePending:i,revokeId:a}){let{data:o,isLoading:s}=r({userId:e}),c=o??[];return s||c.length===0?null:C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),O(he,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:c.map(e=>{let t=i&&a===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.expiresAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.createdAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?O(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function _e({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=z(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=D(e[0]?.id??``),[c,l]=D(``),[u,d]=D([{type:`capability`,target:``,access:[`view`,`create`]}]),[f,p]=D(``),h=m(u),g=o!==``&&c.trim().length>0&&u.length>0&&h===null&&!r;return C(ye,{title:`Create scoped token`,onClose:t,children:[C(`div`,{className:`space-y-3`,children:[O(Y,{label:`On behalf of user`,children:O(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>O(`option`,{value:e.id,children:e.username},e.id))})}),O(Y,{label:`Name`,children:O(`input`,{value:c,onChange:e=>l(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),C(Y,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[O(_,{value:u,onChange:d,clampToParent:a}),h&&O(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),O(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:O(`input`,{type:`number`,min:1,value:f,onChange:e=>p(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),C(be,{children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),C(`button`,{onClick:()=>{let e=parseInt(f,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:u,expiresAt:t})},disabled:!g,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:[r?O(P,{className:`h-3.5 w-3.5 animate-spin`}):O(L,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function ve({token:e,label:t,onClose:n}){let[r,i]=D(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return C(ye,{title:`Token: ${t}`,onClose:n,children:[C(`div`,{className:`space-y-3`,children:[O(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),O(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),C(be,{children:[C(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded 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:[r?O(N,{className:`h-3.5 w-3.5 text-primary`}):O(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),O(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function ye({title:e,onClose:t,children:n}){return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(R,{className:`h-4 w-4`})})]}),O(`div`,{className:`p-4`,children:n})]})})}function be({children:e}){return O(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:t,children:n}){return C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&O(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}S();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function xe(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Se(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Ce({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function we({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),O(`tbody`,{children:t})]})})}function Te(){let e=E(),t=v(),{data:n,isLoading:r}=g(),i=w(()=>n??[],[n]),o=a({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),s=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&o.mutate({id:e})};return C(H,{icon:K,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[r&&O(Se,{}),!r&&i.length===0&&O(Ce,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!r&&i.length>0&&O(we,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:i.map(e=>{let t=e.revokedAt!==null,n=(o.isPending?o.variables?.id:void 0)===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>O(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:xe(e)},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border`,children:t?C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):O(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&C(`button`,{onClick:()=>{s(e.id,e.integrationId)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?O(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}S();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/disable each independently. Disabling one only removes that method; local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Ee(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:ne,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:F,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:F,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:V,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:V,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:L,bullets:[`Generic authentication provider. No additional hints registered.`]}}function De(){let e=p({capName:Q[0].capName},{refetchInterval:Z}),t=p({capName:Q[1].capName},{refetchInterval:Z}),n=x(void 0,{refetchInterval:Z}),r=w(()=>G(n.data??[]),[n.data]),i=w(()=>{let n=[],i=[e.data??[],t.data??[]];for(let[e,t]of Q.entries())for(let a of i[e]??[])n.push({addonId:a.addonId,displayName:r.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,r]);return O(W,{title:$.title,subtitle:$.subtitle,pageIcon:L,itemIcon:L,capability:Q[0].capName,installButtonLabel:$.installLabel,items:i,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:O(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>O(Oe,{addonId:e.addonId})})}function Oe({addonId:e}){let t=Ee(e),n=t.icon;return C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-start gap-2.5`,children:[O(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),O(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),O(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>O(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[C(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[O(te,{className:`h-3 w-3`}),`Setup steps`]}),O(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>O(`li`,{children:e},t))})]}),e===`local-auth`&&C(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[O(M,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),C(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,O(`a`,{href:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,O(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function ke(){return O(`div`,{className:`flex flex-col p-4`,children:O(U,{tabs:[{id:`users`,label:`Users`,icon:ie,content:O(oe,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:O(fe,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:K,content:O(Te,{})},{id:`authentication`,label:`Authentication`,icon:L,content:O(De,{})}]})})}export{ke as IdentityPage};
@@ -1 +0,0 @@
1
- import{Bi as e,Ci as t,Fi as n,Ii as r,Ji as i,Jo as a,Li as o,Mi as s,Ni as c,Pi as l,Qi as u,Ri as d,Si as f,T as p,Ti as m,Ur as h,Vi as g,Xi as _,Yi as v,_ as y,_i as b,_o as x,as as S,bi as C,bo as w,ct as T,do as E,dt as D,es as O,fi as k,fo as A,g as j,gi as ee,go as te,hi as ne,is as re,ji as M,ki as N,lt as ie,mi as ae,mo as P,ns as oe,pi as se,po as ce,qi as le,rs as ue,so as de,ts as fe,vi as pe,xi as me,yi as he,yo as ge,zi as _e}from"./src-C0ryWGb4.js";import{I as ve,K as ye,Q as F,S as I,T as be,W as L,b as R,o as z,q as B,x as V,z as H}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{$ as xe,B as Se,Q as Ce}from"./src-B0nZ9rxd.js";import{i as we}from"./AddLocationWizard-DjfJYSAe.js";import{c as Te,i as Ee,l as De,n as U,r as Oe,s as ke,t as Ae}from"./NodeInferenceDevices-B1Q3HPcp.js";import{t as je}from"./download-CkwHHo3N.js";import{n as Me,r as Ne,t as Pe}from"./zap-n9Ifudx7.js";import{t as Fe}from"./pencil-DxgsOdJ_.js";import{t as Ie}from"./plus-CRlbDvh8.js";import{t as Le}from"./radio-BlLvi9V1.js";import{t as Re}from"./refresh-cw-BPInWufq.js";import{t as ze}from"./search-D29mAFs2.js";import{t as Be}from"./server-BirjNPM2.js";import{t as Ve}from"./square-check-big-B6ik3PVg.js";import{t as He}from"./square-DvCXYnil.js";import{E as Ue,I as We,J as Ge,L as Ke,M as qe,N as Je,P as Ye,S as W,T as Xe,W as Ze,i as Qe,j as G,o as $e,s as et}from"./index-BpMOZW4i.js";import{t as tt}from"./AdminPage-Dq33XE9j.js";import{t as nt}from"./useEventInvalidation-BGgWKSKY.js";import{r as rt,t as it}from"./build-cluster-graph-BytpMQQU.js";import{n as at}from"./format-size-CO9d3C3-.js";import{t as ot}from"./NodeAddonsSettingsPanel-BQ5YizD8.js";import{n as st,t as ct}from"./ClusterRecordingTab-ColxtGy-.js";var lt=Ze(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),ut=Ze(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),dt=Ze(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);F();function ft(e){return e}function pt(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function mt(e,t){return typeof e==`boolean`?e:ft(t)}function ht(e,t){return{pipeline:mt(pt(e,`detect`),t),audio:mt(pt(e,`audio`),t),ingest:mt(pt(e,`ingest`),t)}}function gt(e,t,n){let r=e?.find(e=>e.nodeId===t);return ht(r?.settings,n)}function _t({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:r}=h(void 0),{data:i}=M(void 0),{data:o}=c(void 0),s=new Map;for(let e of i??[])s.set(e.agentNodeId,(s.get(e.agentNodeId)??0)+1);let l=r??[],u=l.filter(e=>e.isOnline).length,d=l.filter(e=>!e.isOnline).length;return I(`div`,{className:`flex flex-col h-full`,children:[I(`button`,{type:`button`,onClick:()=>t(Or),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[V(Xe,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[V(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),V(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(n=>{let r=e===n.id,i=s.get(n.id)??0,c=n.isHub?Be:G,l=gt(o,n.id,n.isHub),u=n.isOnline?null:S(rt(n.lastSeen));return I(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[V(c,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),I(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[I(`span`,{children:[n.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),i>0&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[V(Me,{className:`h-2.5 w-2.5`}),i]})]}),!n.isOnline&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`text-destructive`,children:[`offline`,u===null?``:` · ${u}`]})]})]}),I(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[V(a,{variant:l.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),V(a,{variant:l.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),I(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[I(`span`,{children:[u,` online`]}),d>0&&I(`span`,{className:`text-destructive`,children:[d,` offline`]})]})]})}function vt({nodeId:e,refreshToken:t}){let{data:n}=h(void 0),r=n?.find(t=>t.id===e),i=A(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?I(`div`,{className:`px-6 py-4 border-b border-border`,children:[I(`div`,{className:`flex items-center gap-2 mb-1`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[V(`span`,{children:r.cpuModel??`CPU`}),V(`span`,{children:`•`}),I(`span`,{children:[r.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),i&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{children:[i.attachedCameras,` cameras (`,i.activeCameras,` active)`]}),V(`span`,{children:`•`}),I(`span`,{children:[i.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),V(`span`,{children:`•`}),I(`span`,{children:[`queue `,i.queueDepthTotal]}),i.hardware.hasGpu&&I(R,{children:[V(`span`,{children:`•`}),V(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):V(`div`,{className:`px-6 py-4 border-b border-border`,children:I(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function yt({refreshToken:e,nodeId:n}){let[r,i]=B(new Map),{nodes:a}=E();P(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&i(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:o}=t(void 0),s=L(()=>{let e=new Map;for(let t of o??[])e.set(t.nodeId,t.deviceCount);return e},[o]),c=L(()=>{let e=new Map,t=Date.now()-3e4;for(let n of r.values()){if(n.timestamp<t)continue;let r=n.nodeId??`hub`,i=e.get(r)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,n.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=n.metrics.actualFps,i.totalInferenceWeighted+=n.metrics.avgInferenceTimeMs,i.queueDepth+=n.metrics.queueDepth,e.set(r,i)}return e},[r]),l=L(()=>{let e=new Map;for(let t of a)e.set(t.id,t.shortName);return e},[a]),u=L(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of c.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let o=e>0?r/e:0;return{totalAgents:a.length,onlineAgents:a.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:o,queueDepth:i,totalFps:n}},[c,a]);if(n){let e=c.get(n);return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[V(K,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),V(K,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),V(K,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),V(K,{label:`Queue`,value:e?String(e.queueDepth):`—`}),V(K,{label:`Audio`,value:String(s.get(n)??`—`)})]})]})}let d=[...c.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[V(K,{label:`Total agents`,value:`${u.onlineAgents}/${u.totalAgents}`}),V(K,{label:`Active / Attached`,value:`${u.activeCameras}/${u.attachedCameras}`}),V(K,{label:`Total FPS`,value:u.totalFps.toFixed(1)}),V(K,{label:`Avg inference ms`,value:u.avgInferenceTimeMs.toFixed(0)}),V(K,{label:`Queue depth`,value:String(u.queueDepth)})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[480px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),V(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),V(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),V(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),V(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),V(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),I(`tbody`,{children:[d.map(([e,t])=>I(`tr`,{className:`border-t border-border`,children:[V(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:l.get(e)??e}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:s.get(e)??`—`})]},e)),d.length===0&&V(`tr`,{children:V(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function K({label:e,value:t}){return I(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[V(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),V(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}F();var bt={active:!1,pinned:!1,nodeId:null,reason:``},xt=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],St={pipeline:G,decoder:Ue,audio:Ne},Ct={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function wt({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let r=z(),[a,o]=B(null),[s,c]=B(null),[l,u]=B(new Map);nt([`pipelineOrchestrator`,`getPipelineAssignments`],xt),nt([`pipelineOrchestrator`,`getAudioAssignments`],xt),nt([`pipelineOrchestrator`,`getCameraStatuses`],xt);let{data:d}=M(void 0),{data:h}=f(void 0),{data:g}=m({},{enabled:e===`agent`}),{nodes:_}=E(),{data:y}=ke();P(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&u(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),H(()=>{if(l.size===0)return;let e=setInterval(()=>{u(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[l.size]);let b=L(()=>{let e=new Map;for(let t of y??[])e.set(t.id,t.name);return e},[y]),x=L(()=>{if(e===`agent`){let e=[];for(let n of g??[]){let r=n.assignment,i=(e,n,r)=>({active:e!==null&&e===t,pinned:n,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:n.deviceId,deviceName:b.get(n.deviceId)??`Device ${n.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:b.get(e)??`Device ${e}`,pipeline:bt,decoder:bt,audio:bt};return n.set(e,r),r};for(let i of d??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let e of h??[]){let t=r(e.deviceId);n.set(e.deviceId,{...t,audio:{active:!0,pinned:e.pinned,nodeId:e.nodeId,reason:`capacity`}})}let i=[...n.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[d,h,g,b,e,t]),S=L(()=>(_??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[_]),w=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},T=C({onSuccess:w}),D=v({onSuccess:w}),O=he({onSuccess:w}),k=i({onSuccess:w}),A=(e,t,n)=>{t===`pipeline`?T.mutate({deviceId:e,agentNodeId:n}):O.mutate({deviceId:e,nodeId:n}),o(null)},j=(e,t)=>{t===`pipeline`?D.mutate({deviceId:e}):k.mutate({deviceId:e}),o(null)};return V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&V(`th`,{className:`w-10`}),V(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?I(R,{children:[V(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),V(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):I(R,{children:[V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),V(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),I(`tbody`,{children:[x.map(t=>{let r=l.get(t.deviceId),i=s===t.deviceId;return I(be.Fragment,{children:[I(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&V(`td`,{className:`px-2 py-2 align-middle`,children:V(`button`,{type:`button`,onClick:()=>c(i?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":i?`Collapse broker details`:`Expand broker details`,children:V(i?We:Ye,{className:`h-3.5 w-3.5`})})}),I(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[V(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?I(R,{children:[V(`td`,{className:`px-3 py-2 align-middle`,children:V(Et,{state:t.pipeline,onlineNodes:S,pending:T.isPending||D.isPending,onChange:e=>{e===`auto`?j(t.deviceId,`pipeline`):A(t.deviceId,`pipeline`,e)}})}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(Dt,{state:t.pipeline,deviceId:t.deviceId})})]}):I(R,{children:[V(kt,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:S,isMenuOpen:a?.deviceId===t.deviceId&&a.role===`pipeline`,onToggleMenu:()=>o(a?.deviceId===t.deviceId&&a.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>o(null),onMove:e=>A(t.deviceId,`pipeline`,e),onUnpin:()=>j(t.deviceId,`pipeline`)}),V(kt,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:S,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),V(kt,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:S,isMenuOpen:a?.deviceId===t.deviceId&&a.role===`audio`,onToggleMenu:()=>o(a?.deviceId===t.deviceId&&a.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>o(null),onMove:e=>A(t.deviceId,`audio`,e),onUnpin:()=>j(t.deviceId,`audio`)})]}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(Nt,{snap:r})})]}),i&&!n&&I(`tr`,{className:`bg-surface/50`,children:[V(`td`,{}),I(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&V(Tt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),V(p,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})]})]})]},t.deviceId)}),x.length===0&&V(`tr`,{children:V(`td`,{colSpan:n?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function Tt({deviceId:e,nodeId:t}){let n=z(),{data:r}=N({nodeId:t}),{data:i}=s({deviceId:e}),a=le({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),o=r?.devices??[],c=i?.deviceKey??`auto`,l=c!==`auto`&&!o.some(e=>e.key===c);return I(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[V(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),I(`select`,{value:c,disabled:a.isPending,"aria-label":`Inference device pin`,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[V(`option`,{value:`auto`,children:`Auto (balanced)`}),l&&I(`option`,{value:c,children:[`Pin → `,c,` (not on this node)`]}),o.map(e=>I(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),a.isPending&&V(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function Et({state:e,onlineNodes:t,pending:n,onChange:r}){let i=e.pinned&&e.nodeId?e.nodeId:`auto`,a=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return I(`select`,{value:i,disabled:n,"aria-label":`Pipeline placement pin`,onChange:e=>r(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[V(`option`,{value:`auto`,children:`Auto`}),a.map(e=>I(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function Dt({state:e,deviceId:t}){if(!e.active||!e.nodeId)return V(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let n=e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`;return I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,title:e.nodeId,children:e.nodeId}),V(`span`,{className:`truncate ${e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:n,children:n}),V(Ot,{deviceId:t,nodeId:e.nodeId})]})}function Ot({deviceId:e,nodeId:t}){let n=z(),{data:r}=s({deviceId:e},{refetchOnMount:`always`}),{data:i}=N({nodeId:t},{refetchOnMount:`always`}),a=le({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||i===void 0)return V(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let o=i.devices??[],c=o.filter(e=>e.enabled),l=r.deviceKey??`auto`,u=l!==`auto`&&!c.some(e=>e.key===l),d=o.find(e=>e.key===l);return I(`select`,{value:l,disabled:a.isPending,"aria-label":`Inference device pin`,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value}),className:`mt-0.5 w-full min-w-0 rounded border border-border bg-background px-1 py-0.5 text-[10px] text-foreground disabled:opacity-50`,children:[V(`option`,{value:`auto`,children:`Auto (balanced)`}),u&&I(`option`,{value:l,children:[d?`${U(d).label} (${l})`:l,` (not enabled)`]}),c.map(e=>I(`option`,{value:e.key,children:[U(e).label,` · `,e.format]},e.key))]})}function kt({role:e,state:t,mode:n,onlineNodes:r,readOnly:i=!1,isMenuOpen:a,onToggleMenu:o,onCloseMenu:s,onMove:c,onUnpin:l}){let u=St[e],d=r.filter(e=>e.id!==(t.nodeId??``)),f=!i&&(t.active||n===`cluster`)&&(d.length>0||t.pinned);return I(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[I(`div`,{className:`flex items-center gap-2 min-w-0`,children:[V(n===`agent`?At:jt,{state:t,Icon:u}),V(`div`,{className:`ml-auto shrink-0`,children:f&&V(`button`,{type:`button`,onClick:o,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${Ct[e]} actions`,children:V(lt,{className:`h-3 w-3 text-foreground-subtle`})})})]}),a&&f&&V(Pt,{title:Ct[e],targets:d,pinned:t.pinned,onMove:c,onUnpin:l,onClose:s})]})}function At({state:e,Icon:t}){return I(`div`,{className:`flex items-center gap-1.5`,children:[V(e.active?Ve:He,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),V(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&V(dt,{className:`h-2.5 w-2.5 text-amber-400`})]})}function jt({state:e,Icon:t}){return!e.active||!e.nodeId?I(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[V(t,{className:`h-3 w-3`}),V(`span`,{className:`text-[10px] italic`,children:`—`})]}):I(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[V(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),V(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?I(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[V(dt,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Mt=`min-h-[3.25rem]`;function Nt({snap:e}){if(!e)return V(`div`,{className:`flex items-center ${Mt}`,children:V(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:i,configuredFps:a,droppedFrames:o}=e.metrics,s=O(t);return I(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Mt}`,children:[I(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${s.textColor}`,children:[V(y,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),V(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:s.label})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:n.toFixed(1)}),I(`span`,{children:[`/`,a.toFixed(0),` fps`]})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:r.toFixed(0)}),V(`span`,{children:` ms`}),i>0&&I(`span`,{className:`text-warning ml-1`,children:[`q`,i]})]}),I(`span`,{className:`whitespace-nowrap truncate ${o>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,V(`span`,{className:`text-foreground`,children:o})]})]})}function Pt({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=ye(null);return H(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),I(`div`,{ref:o,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[V(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&V(`div`,{className:`py-1`,children:t.map(e=>I(`button`,{type:`button`,onClick:()=>r(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),n&&I(`button`,{type:`button`,onClick:i,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,e.toLowerCase()]}),t.length===0&&!n&&V(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Ft({nodeId:e,refreshToken:t}){return I(`div`,{className:`space-y-6`,children:[V(yt,{refreshToken:t,nodeId:e}),I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),V(wt,{mode:`agent`,nodeId:e,compact:!0})]})}F();function It(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Lt({nodeId:e,refreshToken:t}){let n=z(),r=b({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:i}=pe({nodeId:e}),a=A(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??i??null,o=a===null;nt([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:s}=u({nodeId:e}),{values:c}=ce(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),l=L(()=>c.filter(e=>e.metrics.phase===`active`).length,[c]),d=t=>{let n=s??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||r.mutate({nodeId:e,engine:t,force:n.length>0})};return I(`div`,{className:`space-y-6`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(a??[]).length,` engine(s) resident in RAM. `,(s??[]).length,` `,`camera(s) attached, `,l,` actively dispatching frames. Refreshes every 5s.`]})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[640px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),V(`th`,{className:`text-left px-3 py-2`,children:`Models`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),V(`th`,{className:`w-20`})]})}),I(`tbody`,{children:[o&&V(`tr`,{children:V(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!o&&(a??[]).map(e=>{let t=e.kind===`warm-override`,n=e.kind===`device-pool`;return I(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:n?`bg-primary/[0.05]`:``}`,children:[V(`td`,{className:`px-3 py-2`,children:I(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:n?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[V(t?ut:n?De:G,{className:`h-3 w-3`}),t?`warm`:n?`pool`:`runtime`]})}),V(`td`,{className:`px-3 py-2`,children:I(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[V(Pe,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),V(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?V(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>V(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),V(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),V(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?V(`span`,{className:`text-foreground-subtle`,children:It(e.idleMs,e.idleTtlMs)}):V(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(s??[]).length}),V(`td`,{className:`px-3 py-2 text-right`,children:n?V(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):I(`button`,{type:`button`,disabled:r.isPending,onClick:()=>d(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[V(et,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!o&&(a??[]).length===0&&V(`tr`,{children:V(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[V(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,V(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,V(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),r.isError&&I(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,r.error instanceof Error?r.error.message:`unknown`]})]})}F();var Rt=new Set(Se);function zt(e){return Rt.has(e)}function Bt(e,t,n){return`${e}/${t}/${n}`}function Vt(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function Ht(e){return{coreml:`Apple Neural Engine / GPU — .mlpackage`,openvino:`Intel CPU / GPU / NPU — .xml`,onnx:`CPU, CUDA, Node.js — .onnx`}[e.format]??`.${e.format}`}function q(e){return e.format}function Ut(e,t){let n=0,r=0,i=0;for(let a of e)for(let e of a.addons)for(let a of e.models){let e=a.formats[t];e&&(n++,e.downloaded&&(r++,i+=e.sizeMB))}return{total:n,downloaded:r,downloadedSizeMB:i}}function Wt({addonId:e,model:t,format:n,isActive:r,progress:i,errorMsg:a,onDownload:o,onDelete:s}){let c=t.formats[n];return c?I(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors`,children:[V(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),I(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&I(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[V(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:V(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),I(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),V(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:at(c.sizeMB)}),a&&I(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[V(Je,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?I(`button`,{onClick:s,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[r?V(W,{className:`h-3 w-3 animate-spin`}):V(et,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):I(`button`,{onClick:o,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[r?V(W,{className:`h-3 w-3 animate-spin`}):V(je,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function Gt({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=B(!1);return I(`div`,{className:`relative`,children:[I(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[V(G,{className:`h-4 w-4 text-primary shrink-0`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:Vt(n)}),q(n)===q(t)&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:Ht(n)})]}),V(We,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&V(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let i=q(e)===q(n),o=q(e)===q(t);return I(`button`,{type:`button`,onClick:()=>{r(e),a(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${i?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[V(G,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),I(`div`,{className:`flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:Vt(e)}),o&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:Ht(e)})]}),i&&V(qe,{className:`h-4 w-4 text-primary shrink-0`})]},q(e))})})]})}function Kt({embedded:e=!1,nodeId:t}={}){let n=z(),r=t??`hub`,[i,a]=B(null),[o,s]=B(new Set),[c,l]=B(new Map),[u,d]=B(new Map),[f,p]=B(``),{data:m=[]}=ae({nodeId:r}),h=m.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:g}=ee({nodeId:r}),_=g,{data:v,isLoading:y}=ne({nodeId:r}),b=se(),x=k();P(`model.download.progress`,e=>{let t=e.data,r=typeof t.modelId==`string`?t.modelId:void 0,i=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;r===void 0||i===void 0||(l(e=>{let t=new Map(e);return i===100||i===-1?t.delete(r):t.set(r,{modelId:r,progress:i,totalMB:a}),t}),i===100&&n.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let S=_??{runtime:`node`,backend:`cpu`,format:`onnx`},C=h.find(e=>e.format===i)??S,w=C.format,T=e=>e.formats[w]?.downloaded===!0,E=v?.slots??[],D=E.map(e=>({...e,addons:e.addons.map(e=>({...e,models:re(e.models,w)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),O=Ut(D,w),A=ve(async(e,t,i)=>{if(!zt(i))return;let a=Bt(e,t,i);s(e=>new Set([...e,a])),d(e=>{let t=new Map(e);return t.delete(a),t});try{await b.mutateAsync({addonId:e,modelId:t,format:i,nodeId:r}),n.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){d(t=>new Map([...t,[a,e instanceof Error?e.message:`Download failed`]]))}finally{s(e=>{let t=new Set(e);return t.delete(a),t})}},[b,n,r]),j=ve(async(e,t,i)=>{if(!zt(i))return;let a=Bt(e,t,i);s(e=>new Set([...e,a])),d(e=>{let t=new Map(e);return t.delete(a),t});try{await x.mutateAsync({addonId:e,modelId:t,format:i,nodeId:r}),n.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){d(t=>new Map([...t,[a,e instanceof Error?e.message:`Delete failed`]]))}finally{s(e=>{let t=new Set(e);return t.delete(a),t})}},[x,n,r]),te=ve(e=>{a(e.format)},[]),M=f.trim()?D.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(f.toLowerCase())||t.id.toLowerCase().includes(f.toLowerCase())||e.name.toLowerCase().includes(f.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):D,N=I(R,{children:[y&&V(`div`,{className:`flex items-center justify-center py-16`,children:V(W,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!y&&E.length===0&&I(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[V(we,{className:`h-8 w-8 mb-3 opacity-30`}),V(`span`,{className:`text-sm`,children:`No pipeline steps available`}),V(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!y&&E.length>0&&I(R,{children:[V(Gt,{engines:h,activeEngine:S,viewEngine:C,onSelect:te}),I(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground tabular-nums`,children:O.total}),V(`span`,{className:`ml-1`,children:`compatible models`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success tabular-nums`,children:O.downloaded}),V(`span`,{className:`ml-1`,children:`downloaded`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{className:`tabular-nums`,children:[at(O.downloadedSizeMB),V(`span`,{className:`ml-1`,children:`on disk`})]})]}),O.total>5&&I(`div`,{className:`relative`,children:[V(ze,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),V(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`Search models...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary`})]}),M.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+re(t.models,w).filter(T).length,0);return I(`div`,{children:[I(`div`,{className:`flex items-center gap-2 mb-2`,children:[V(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),V(`div`,{className:`flex-1 h-px bg-border`}),I(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=Bt(e.id,t.id,w);return V(Wt,{addonId:e.id,model:t,format:w,isActive:o.has(n),progress:c.get(t.id),errorMsg:u.get(n),onDownload:()=>A(e.id,t.id,w),onDelete:()=>j(e.id,t.id,w)},`${e.id}/${t.id}`)}))})]},e.id)}),M.length===0&&V(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:f.trim()?I(R,{children:[`No models matching “`,f,`”`]}):I(R,{children:[`No models available for `,Vt(C),` format`]})})]})]});return e?V(`div`,{className:`space-y-4`,children:N}):V(tt,{children:N})}function qt({nodeId:e,refreshToken:t}){return V(Kt,{embedded:!0,nodeId:e})}var Jt=`pipeline-runner`,Yt=200;function Xt({nodeId:e}){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(j,{agentId:e,addonId:Jt,limit:Yt,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F(),F();function Zt({nodeId:e,title:t}){let{data:n}=ke(),{data:r}=M(void 0),i=L(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),a=L(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),[o,s]=B(new Map);P(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||s(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),H(()=>{if(o.size===0)return;let e=setInterval(()=>{s(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[o.size]);let c=L(()=>{let e=[];for(let t of o.values())a&&!a.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[o,a]);return c.length===0?I(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):I(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[I(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[V(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),V(`span`,{className:`text-[10px] text-foreground-subtle`,children:c.length})]}),V(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>{let t=i.get(e.deviceId)??`#${e.deviceId}`,n=O(e.metrics.phase);return I(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[V(y,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),V(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),V(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),V(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}F();function J(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Qt(e){if(!e)return null;let t=e.modelId!==void 0&&e.modelId!==``?e.modelId:void 0,n=e.settings&&Object.keys(e.settings).length>0?e.settings:void 0;return t===void 0&&n===void 0?null:{...t===void 0?{}:{modelId:t},...n===void 0?{}:{settings:n}}}function $t({nodeId:t,refreshToken:n}){let r=z(),[i,a]=B(null),[o,s]=B(null),[c,l]=B(``),[u,d]=B(null),f=N({nodeId:t},{refetchOnMount:`always`}),p=ne({nodeId:t},{refetchOnMount:`always`}),m=f.data?.devices??[],h=e({onSuccess:()=>{r.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),g=L(()=>p.data?ge(p.data):[],[p.data]),_=L(()=>m.map(e=>({agentNodeId:t,engineLabel:e.format,deviceKey:e.key,deviceLabel:U(e).label})),[m,t]),v=e=>m.find(t=>t.key===e)??null,y=L(()=>m.filter(e=>e.enabled),[m]),b=y.length>=2,S=(e,t)=>ue(J(p.data??null,e)?.models??[],t?.format),C=e=>{let t=v(e);return t?U(t).label:e},T=(e,t)=>y.filter(n=>n.key!==t&&S(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,E=e=>{let t=J(p.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},D=(e,t)=>{let n=J(p.data??null,e);if(n)return fe(n,t)},O=(e,t)=>{let n=E(e),r=n.kind===`gate`?n.effectiveOn:!1,i=J(p.data??null,e),a=t.deviceKey===void 0?null:v(t.deviceKey),o=ue(i?.models??[],a?.format),s=a?.steps?.[e];if(!o){if(!r)return{kind:`na`};let n=s?.jumpDeviceKey,i=n!==void 0&&y.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:T(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:C(i)}}return{kind:`enabled`,modelId:(i?oe({catalog:i,device:a,base:s?.modelId}):void 0)??`Auto`,...s?.jumpDeviceKey!==void 0&&y.some(e=>e.key===s.jumpDeviceKey)?{jumpTo:C(s.jumpDeviceKey)}:{}}},k=i&&p.data?J(p.data,i.addonId):null,A=i?v(i.deviceKey):null,j=A?.format??`coreml`,ee=i?D(i.addonId,A):void 0,re=()=>{a(null),s(null),l(``)},M=(e,t)=>{if(t.deviceKey===void 0)return;let n=v(t.deviceKey)?.steps?.[e];a({addonId:e,deviceKey:t.deviceKey}),s({enabled:!0,...n?.modelId===void 0?{}:{modelId:n.modelId},settings:n?.settings??{}}),l(n?.jumpDeviceKey??``)},ie=()=>{if(!i)return;let e=Qt(o),n=c!==``&&c!==i.deviceKey?c:void 0,r=e||n!==void 0?{...e,...n===void 0?{}:{jumpDeviceKey:n}}:null,a=m.map(e=>{let t={...e.steps};return e.key===i.deviceKey&&(r?t[i.addonId]=r:delete t[i.addonId]),{key:e.key,enabled:e.key===i.deviceKey?!0:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:t}});h.mutate({agentNodeId:t,inferenceDevices:Ee(a)},{onSuccess:re})};if(f.isLoading||p.isLoading)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(m.length===0)return V(`div`,{className:`rounded-md border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`});if(!p.data)return V(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ae=i!==null&&k!==null&&A!==null;return I(`div`,{className:`relative h-full w-full space-y-3`,children:[I(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[`Each column is one of this node's inference accelerators. A cell shows the`,` `,V(`span`,{className:`font-medium text-foreground`,children:`base model`}),` every camera landing on that accelerator runs; click to change it. Whether a camera runs a step is set per-camera on that camera's Detection pipeline tab — there is no gate here.`]}),V(`div`,{className:ae?`md:pr-[360px]`:``,children:g.length>0?V(te,{tree:g,agents:_,gateFor:E,getCellState:O,onCellClick:M,selectedCell:i?{addonId:i.addonId,agentNodeId:t,deviceKey:i.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:u,onFallbackNodeChange:d,hideGate:!0}):V(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),V(w,{open:ae,onClose:re,title:k?.name??``,subtitle:i&&A?`${t} · ${U(A).label} · ${A.format}`:``,footer:I(R,{children:[V(`div`,{className:`flex-1`}),V(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:re,children:`Cancel`}),V(`button`,{type:`button`,disabled:!i||!o||h.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:ie,children:h.isPending?`Saving…`:`Save`})]}),children:k&&i&&o?I(`div`,{className:`space-y-3`,children:[b&&I(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[V(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),I(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:c,onChange:e=>l(e.target.value),children:[V(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),y.filter(e=>e.key!==i.deviceKey).map(e=>I(`option`,{value:e.key,children:[U(e).label,` · `,e.format]},e.key))]}),V(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),V(x,{mode:`agent`,addon:k,agentDefault:o,agentNodeId:t,engineFormat:j,effectiveModelId:ee,onChangeAgentConfig:s})]}):V(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}F();var en=[`pipeline-orchestrator`],tn=[`decoder`],nn=!1;function rn({nodeId:e,refreshToken:t}){let n=de(),[i,a]=B(null),[o,s]=B(null),c=(h(void 0).data??[]).find(t=>t.id===e),l=c?.name??e,u=c?.isOnline??!1,d=r({onSuccess:e=>{s(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${l} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(s(null),d.mutate({agentNodeId:e}))};return I(`div`,{className:`relative h-full w-full space-y-3`,children:[I(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[o&&V(`span`,{className:`text-emerald-400`,children:o}),d.isError&&V(`span`,{className:`text-red-400`,children:d.error instanceof Error?d.error.message:`Reset failed`}),V(`button`,{type:`button`,onClick:()=>{f()},disabled:d.isPending,className:`rounded border border-amber-500/40 bg-surface px-2 py-0.5 text-amber-300 hover:bg-surface-hover disabled:opacity-50`,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:d.isPending?`Resetting…`:`Reset to default`})]}),V(Zt,{nodeId:e}),V(ot,{nodeId:e,addonIds:en,level:`global`,sectionIds:tn}),nn,nn,I(`div`,{children:[V(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),V(Ae,{nodeId:e,nodeName:l,isOnline:u})]}),I(`div`,{children:[V(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),V($t,{nodeId:e,refreshToken:t})]})]})}var an=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],on=`decoder-nodeav`;function sn({nodeId:e,refreshToken:t}){let{data:n}=h(void 0),r=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??on,i=[...an,r];return I(`div`,{className:`flex flex-col h-full`,children:[V(vt,{nodeId:e,refreshToken:t}),V(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:V(ot,{nodeId:e,addonIds:i,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:V(Ft,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:V(rn,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:V(Lt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:V(qt,{nodeId:e,refreshToken:t})},{id:`logs`,label:`Logs`,order:300,content:V(Xt,{nodeId:e})}]})})]})}function cn(){return I(`div`,{className:`space-y-6`,children:[V(Zt,{title:`Cluster cameras`}),I(`div`,{className:`min-w-0`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Use the Auto | Pin control to pin a camera to a node, the inference-device select to pin it to an accelerator, or the kebab to move a role; expand the chevron for the per-camera broker drill-down. Cluster load, inference-device weights, and Rebalance live on the Balancer tab.`})]}),V(wt,{mode:`cluster`})]})}var ln=`pipeline-orchestrator`,un=`recorder`,dn=`recordingNodeId`,fn=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],pn=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function mn(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function hn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function gn(e,t,n){let r=mn(e,t);return typeof r==`string`&&r.length>0?r:n}function _n(e,t,n){let r=mn(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function vn(e,t){let n=hn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function yn(e,t){let n=hn(e,t);return typeof n==`string`&&n.length>0?n:null}function bn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function xn(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function Sn(e,t){switch(t){case`detect`:return e.pipeline}}function Cn(e){return e instanceof Error?e.message:`Failed to save`}function wn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function Tn({capability:e,label:t,hint:n,nodeId:r,active:i,pending:a,layout:o,onToggle:s}){let c=i?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,l=o===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,u=i?Ke:Te;return I(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":`${t} capability for ${r}`,title:`${t} — ${n}`,disabled:a,onClick:()=>s(e,!i),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${c} ${l}`,children:[V(u,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),V(`span`,{children:t})]})}function En({node:e,emphasis:t=!1}){let n=e.isHub?Be:G;return I(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[V(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),V(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),I(`div`,{className:`min-w-0`,children:[I(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[V(`span`,{className:`truncate`,children:e.name}),e.isHub&&V(a,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&V(a,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),V(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}F();function Dn({nodeId:e,value:t,detectedHosts:n,status:r,errorMessage:i,onCommit:a}){let[o,s]=B(t??``);H(()=>{s(t??``)},[t]);let c=n[0],l=c===void 0?`auto-detect`:`auto: ${c}`,u=r===`pending`,d=o.trim(),f=d!==(t??``),p=f&&!u,m=()=>{p&&a(e,d.length>0?d:null)};return I(`div`,{className:`flex items-center gap-1.5`,children:[V(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:l,value:o,disabled:u,onChange:e=>s(e.target.value),onBlur:m,onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&s(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),I(`button`,{type:`button`,onClick:m,disabled:!p,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[u?V(W,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):V(Ke,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!f&&!u&&r===`success`&&V(Ke,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),r===`error`&&V(`span`,{title:i??`Failed to save reachable host`,children:V(Je,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":i??`Failed to save reachable host`,role:`img`})})]})}function On({label:e,children:t}){return I(`div`,{className:`flex items-center justify-between gap-3`,children:[V(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function kn({node:e,actions:t}){return I(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[V(En,{node:e,emphasis:!0}),V(`div`,{className:`grid grid-cols-2 gap-2`,children:pn.map(n=>V(Tn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Sn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),V(`div`,{className:`space-y-3 border-t border-border pt-3`,children:V(On,{label:`Reachable host`,children:V(Dn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function An(){return I(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function jn({nodes:e,actions:t}){return V(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:I(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[V(`thead`,{children:I(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),pn.map(e=>V(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),V(`tbody`,{children:e.map(e=>I(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[V(`td`,{className:`px-4 py-3 align-middle`,children:V(En,{node:e})}),pn.map(n=>V(`td`,{className:`px-3 py-3 text-center align-middle`,children:V(Tn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Sn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),V(`td`,{className:`px-4 py-3 align-middle`,children:V(Dn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})]},e.id))})]})})}function Mn({role:e,value:t,options:n,pending:r,onChange:i}){return I(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[V(`span`,{className:`text-xs font-semibold text-foreground`,children:bn(e)}),V(`select`,{value:t,disabled:r,onChange:t=>i(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:n.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),V(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:xn(e)})]})}function Nn({roleValues:e,options:t,pending:n,lowFpsEnabled:r,fpsMinThreshold:i,onRoleChange:a,onLowFpsToggle:o}){return I(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[fn.map(r=>V(Mn,{role:r,value:e[r],options:t,pending:n,onChange:a},r)),I(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[V(`input`,{type:`checkbox`,checked:r,disabled:n,onChange:e=>o(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),I(`span`,{className:`flex flex-col gap-0.5`,children:[V(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),I(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,r?`${i} fps`:`disabled`]})]})]})]})}F();function Pn(){let e=z(),{nodes:t}=E(),n=c(void 0),r=ie({addonId:ln}),i=ie({addonId:un}),a=()=>wn(e),o=d({onSuccess:a}),s=_e(),l=g({onSuccess:a}),u=D({onSuccess:a}),[f,p]=B(!1),m=L(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),h=L(()=>t.map(e=>{let t=m.get(e.id),n=ht(t,e.isHub),r=vn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:vn(t,`maxCameras`),reachableHost:yn(t,`reachableHost`),detectedHosts:e.localIps}}),[t,m]),_=h.filter(e=>e.effective.pipeline),v={ingestNode:gn(r.data,`ingestNode`,`hub`),recordingNode:gn(i.data,dn,`hub`),audioNode:gn(r.data,`audioNode`,`hub`),motionNode:gn(r.data,`motionNode`,`hub`)},y=L(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...fn.map(e=>v[e]),...e])].filter(e=>e.length>0)},[t,v]),b=_n(r.data,`fpsMinThreshold`,0),x=b>0,S=n.isLoading||r.isLoading||i.isLoading,C=(e,t,n)=>{o.mutate({agentNodeId:e,[t]:n})},w=(e,t)=>{if(e===`recordingNode`){u.mutate({addonId:un,patch:{[dn]:t}});return}u.mutate({addonId:ln,patch:{[e]:t}})},T=e=>{u.mutate({addonId:ln,patch:{fpsMinThreshold:e?Math.max(1,b):0}})},O=e=>l.variables?.agentNodeId===e?l.isPending?`pending`:l.isError?`error`:l.isSuccess?`success`:`idle`:`idle`,k=e=>O(e)===`error`?Cn(l.error):null,A=async e=>{p(!0);try{for(let t of e)await s.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{p(!1),a()}},j={capabilityPending:o.isPending,onToggleCapability:C,onCommitReachableHost:(e,t)=>l.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:O,reachableHostErrorMessage:k};return I(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[I(`header`,{className:`flex items-start justify-between gap-4`,children:[I(`div`,{className:`space-y-1`,children:[V(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),V(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, distribute detection weight across detect-capable nodes, and choose the singleton cluster roles.`})]}),S&&V(W,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),V(Nn,{roleValues:v,options:y,pending:u.isPending,lowFpsEnabled:x,fpsMinThreshold:b,onRoleChange:w,onLowFpsToggle:T})]}),I(`div`,{className:`space-y-3`,children:[I(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),V(An,{})]}),h.length===0?V(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):I(R,{children:[V(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:h.map(e=>V(kn,{node:e,actions:j},e.id))}),V(`div`,{className:`hidden @3xl/clustertab:block`,children:V(jn,{nodes:h,actions:j})})]})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),V(Oe,{nodes:_,pending:f,onCommitWeights:e=>void A(e)})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),_.length===0?V(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):V(`div`,{className:`space-y-2`,children:_.map(e=>V(Ae,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}F();var Fn=!1;function In({refreshToken:e}){let t=z(),{data:r}=h(void 0);L(()=>it(r??[]),[r]);let i=n({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return I(`div`,{className:`space-y-6`,children:[V(yt,{refreshToken:e}),V(Pn,{}),Fn,I(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[I(`div`,{className:`min-w-0`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Recompute the optimal node for every assigned camera from current load + hardware affinity, and migrate the ones no longer on their best node. Pinned cameras never move.`})]}),I(`button`,{type:`button`,onClick:()=>i.mutate(void 0),disabled:i.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[V(Pe,{className:`h-3.5 w-3.5`}),i.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var Ln=[`pipeline-orchestrator`];function Rn({refreshToken:e}){return V(`div`,{className:`space-y-4 max-w-3xl`,children:V(ot,{nodeId:`hub`,addonIds:Ln,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer thresholds, and failover policy. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`})})}F();function zn({refreshToken:e}){let t=z(),{data:n,isLoading:r}=l(),[i,a]=B(null),[o,s]=B(``),[c,u]=B(``),d=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},f=_({onSuccess:()=>{a(null),d()}}),p=me({onSuccess:d}),m=e=>{a(e.id),s(e.name),u(e.description??``)},h=()=>{a(null),s(``),u(``)},g=()=>{if(!i)return;let e=c.trim();f.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let v=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return V(`div`,{className:`space-y-6 max-w-4xl`,children:I(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[I(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),V(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle`,children:[v.length,` template`,v.length===1?``:`s`]})]}),v.length===0?I(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[V(Ie,{className:`h-6 w-6 opacity-40`}),V(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):V(`ul`,{className:`divide-y divide-border`,children:v.map(e=>{let t=i===e.id;return V(`li`,{className:`px-4 py-3 text-xs`,children:I(`div`,{className:`flex items-start gap-3`,children:[V(`div`,{className:`flex-1 min-w-0`,children:t?I(`div`,{className:`space-y-2`,children:[V(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:o,onChange:e=>s(e.target.value),placeholder:`Template name`,autoFocus:!0}),V(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:c,onChange:e=>u(e.target.value),placeholder:`Description (optional)`})]}):I(R,{children:[V(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&V(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),I(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,I(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),V(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?I(R,{children:[I(`button`,{type:`button`,onClick:g,disabled:f.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[V(Ke,{className:`h-3 w-3`}),`Save`]}),I(`button`,{type:`button`,onClick:h,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[V(Qe,{className:`h-3 w-3`}),`Cancel`]})]}):I(R,{children:[V(`button`,{type:`button`,onClick:()=>m(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:V(Fe,{className:`h-3 w-3`})}),V(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&p.mutate({id:e.id})},disabled:p.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:V(et,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}F();var Bn=`pipeline-analytics`;function Vn(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function Hn(){let e=z(),{data:t}=h(void 0),{data:n,isLoading:r}=ie({addonId:Bn}),i=Vn(n),a=D({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),o=L(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return I(`div`,{className:`flex flex-col gap-6`,children:[I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),V(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),I(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?V(W,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):V(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:Bn,patch:{postProcessingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:o.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&V(W,{className:`h-4 w-4 animate-spin text-primary`})]})]}),I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),V(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),V(st,{types:[`eventMedia`]})]})]})}var Un=`pipeline-orchestrator`,Wn=200;function Gn(){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(j,{addonId:Un,limit:Wn,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F();var Kn=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function qn({refreshToken:e}){let[t,n]=B(`assignments`);return I(`div`,{className:`flex flex-col h-full`,children:[I(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),V(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Per-camera assignments, the load balancer (live load + inference-device weights), cluster-wide settings, and the pipeline template library.`})]}),V(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Kn.map(e=>V(`button`,{type:`button`,onClick:()=>n(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),I(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&V(cn,{}),t===`balancer`&&V(In,{refreshToken:e}),t===`events`&&V(Hn,{}),t===`recording`&&V(ct,{}),t===`settings`&&V(Rn,{refreshToken:e}),t===`templates`&&V(zn,{refreshToken:e}),t===`logs`&&V(Gn,{})]})]})}var Jn=`armed:`;function Yn(e){return e.assignment.reasons.detection?.startsWith(Jn)===!0}function Xn(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!Yn(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function Zn(e){let t=[],n=[],{assignment:r,detection:i,decoder:a,broker:o}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),i!==null&&i.phase===`active`&&a!==null&&a.shm.framesWritten===0&&t.push({code:`decoder-black-hole`,severity:`error`,message:`Decoder on ${a.nodeId} has written 0 frames to the shared-memory plane while detection is active — the decode path is stalled`}),r.detectionNodeId===null&&i===null&&!Yn(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let s=e.degraded??[];if(s.length>0){let e=[...new Set(s.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:`Could not read ${e} for this camera — those blocks are unknown, not empty (a switch read that failed does NOT mean nothing is switched off)`})}for(let e of o?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function Qn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function $n(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function er(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function tr(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var nr={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function rr(e){if(!Qn(e)||!Array.isArray(e.sections))return nr;let t=Ce(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)tr(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:$n(n(`detectionFps`)),motionSources:er(n(`motionSources`)),motionFps:$n(n(`motionFps`)),motionCooldownMs:$n(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function ir(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...ir(r.children,t+1));return n}function X({title:e,children:t}){return I(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[V(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),V(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return I(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[V(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),V(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&V(ar,{})]})}function ar(){return V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var or={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return V(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${or[e]}`,children:t})}function $({children:e}){return V(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function sr({icon:e,label:t,nodeId:n,pinned:r,reason:i,overridden:a}){return I(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[V(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),V(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?V(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):I(R,{children:[V(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?I(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[V(dt,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,i!==void 0&&i.length>0?i:`capacity`]}),a&&V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function cr({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:i}){let a=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,o=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return I(X,{title:`Where it runs`,children:[V(sr,{icon:G,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),V(sr,{icon:Ue,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),V(sr,{icon:Ne,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),V(sr,{icon:Le,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),V(`div`,{className:`mt-1.5`,children:I(`select`,{value:a,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>i(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[V(`option`,{value:`auto`,children:`Auto (load balanced)`}),o.map(e=>I(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function lr(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function ur(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function dr(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function fr({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:i}){let a=ur(t,n.detectionStreamProfile),o=ur(t,n.motionStreamProfile),s=n.motionSources.includes(`analyzer`);return I(X,{title:`Streams & motion`,children:[I(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,a!==void 0&&` · ${a.width}×${a.height} ${a.codec}`]}),V(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:dr(n.detectionFps)}),I(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.join(` + `):`none`,r===!1&&` · inactive`]}),s&&I(R,{children:[I(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,o!==void 0&&` · ${o.width}×${o.height} ${o.codec}`]}),I(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[dr(n.motionFps),i!==null&&` · live ${i.toFixed(1)}`]})]}),V(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),V(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?V($,{children:`No streams registered`}):e.map(e=>I(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[V(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,lr(e)]},e.camStreamId))})]})}function pr({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return I(X,{title:`Pipeline steps`,children:[e===void 0?V($,{children:`Resolving…`}):e.length===0?V($,{children:`No steps configured`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>V(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:I(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&V(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&I(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),V(`div`,{className:`mt-1`,children:I(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var mr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function hr({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return I(X,{title:`Detection runtime`,children:[V(Z,{label:`Mode`,overridden:r,children:n??`—`}),V($,{children:`Detection stage inactive or unreachable`})]});let i=t?.phase??e.phase,a=t?.actualFps??e.actualFps,o=t?.configuredFps??e.configuredFps,s=t?.avgInferenceTimeMs??e.avgInferenceMs,c=t?.queueDepth??e.queueDepth,l=O(i),u=i===`active`&&a===0;return I(X,{title:`Detection runtime`,children:[I(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[I(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${l.badgeClass}`,children:[V(y,{phase:i,className:`h-2.5 w-2.5`}),l.label]}),t!==void 0&&V(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),V(Z,{label:`Mode`,overridden:r,children:n??`—`}),I(Z,{label:`FPS`,children:[V(`span`,{className:u?`text-danger font-semibold`:``,children:a.toFixed(1)}),I(`span`,{className:`text-foreground-subtle`,children:[` / `,o.toFixed(0),` configured`]})]}),I(Z,{label:`Inference`,children:[s.toFixed(0),` ms`,c>0&&I(`span`,{className:`text-warning`,children:[` · queue `,c]}),t!==void 0&&t.droppedFrames>0&&I(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),I(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),I(Z,{label:`Provisioning`,children:[V(Q,{tone:mr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&I(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function gr({broker:e}){return e===null?V(X,{title:`Stream broker`,children:V($,{children:`Broker stage inactive or unreachable`})}):I(X,{title:`Stream broker`,children:[e.profiles.length===0?V($,{children:`No broker profiles`}):V(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return I(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),V(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),I(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),I(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),I(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),I(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[I(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),I(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function _r({decoder:e,detectionActive:t}){if(e===null)return V(X,{title:`Decoder`,children:V($,{children:`Decoder stage inactive or unreachable`})});let n=t&&e.shm.framesWritten===0;return I(X,{title:`Decoder`,children:[V(Z,{label:`Node`,children:e.nodeId}),V(Z,{label:`Sessions`,children:e.sessionCount}),I(Z,{label:`SHM frames`,children:[V(`span`,{className:n?`text-danger font-semibold`:``,children:e.shm.framesWritten}),V(`span`,{className:`text-foreground-subtle`,children:` written`})]}),I(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&I(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),I(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&V(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}F();var vr=`pipeline-orchestrator`,yr={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},br={healthy:`Healthy`,idle:`Idle`,error:`Error`};function xr({problems:e}){return V(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>I(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[V($e,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),V(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function Sr({deviceId:e,name:t,online:n,status:r,live:i,onlineNodes:a}){let s=z(),{data:c}=T({addonId:vr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:l}=o({deviceId:e},{staleTime:3e4}),u=L(()=>rr(c),[c]),d=L(()=>l===void 0?void 0:ir(l.steps),[l]),f=L(()=>r===void 0?[]:Zn(r),[r]),p=()=>{s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},m=C({onSuccess:p}),h=v({onSuccess:p}),g=t=>{t===`auto`?h.mutate({deviceId:e}):m.mutate({deviceId:e,agentNodeId:t})},_=r===void 0?`idle`:Xn(r),y=f.some(e=>e.severity===`error`),b=f.length>0,x=y?`border-danger/50`:b?`border-warning/40`:`border-border`;return I(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${x} bg-background overflow-hidden`,children:[I(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[V(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${y?`bg-danger`:yr[_]}`,title:y?`Error`:br[_],"aria-label":y?`Error`:br[_],role:`img`}),V(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&V(Q,{tone:`danger`,children:`offline`}),I(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[u.detectionMode!==null&&V(Q,{tone:u.detectionMode===`disabled`?`warning`:u.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:u.detectionMode===`disabled`?`detection off`:u.detectionMode}),r?.recording!=null&&(r.recording.active?I(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&I(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),f.length>0&&V(xr,{problems:f}),r===void 0?V(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):I(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[V(cr,{assignment:r.assignment,settings:u,onlineNodes:a,pinPending:m.isPending||h.isPending,onDetectionPinChange:g}),V(hr,{detection:r.detection,live:i,detectionMode:u.detectionMode,modeOverridden:u.overriddenKeys.has(`detectionMode`)}),V(pr,{steps:d,audioModelId:l?.audio?.modelId??null,audioEnabled:r.audio?.enabled??l?.audio?.enabled??null,audioMode:u.audioMode}),V(fr,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:u,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null}),V(gr,{broker:r.broker}),V(_r,{decoder:r.decoder,detectionActive:r.detection?.phase===`active`})]})]})}F();var Cr=5e3,wr=1e4,Tr=5e3;function Er(e){let t=z(),{data:n,isLoading:r}=ke(),{data:i,isLoading:a}=m({},{refetchInterval:Cr}),{nodes:o}=E();H(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[s,c]=B(new Map);P(xe.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&c(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),H(()=>{if(s.size===0)return;let e=setInterval(()=>{c(e=>{let t=Date.now()-wr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},Tr);return()=>clearInterval(e)},[s.size]);let l=L(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:L(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:l.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]),liveMetrics:s,onlineNodes:L(()=>(o??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[o]),isLoading:r||a}}F();function Dr({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:i}=Er(e),a=L(()=>[...t.map(e=>{let t=e.status===void 0?[]:Zn(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),o=L(()=>{let e=0,t=0;for(let r of a)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:a.length,active:e,issues:t}},[a,n]);return i&&t.length===0?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):V(`div`,{className:`h-full overflow-y-auto`,children:I(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[I(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground`,children:o.total}),` cameras`]}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success`,children:o.active}),` actively inferring`]}),I(`span`,{children:[V(`span`,{className:`font-semibold ${o.issues>0?`text-danger`:`text-foreground`}`,children:o.issues}),` `,`with issues`]}),V(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),a.map(({row:e})=>V(Sr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}F();var Or=`__cluster__`;function kr(e){return e===`cameras`?`cameras`:`nodes`}function Ar(){let[e,t]=Ge(),n=kr(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[i,a]=B(0),[o,s]=B(!1);return H(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Or},{replace:!0})},[n,e,t]),I(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[I(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[I(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[V(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:r},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),V(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),I(`button`,{type:`button`,onClick:()=>a(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[V(Re,{className:`h-3.5 w-3.5`}),`Refresh`]})]}),n===`nodes`&&I(`button`,{type:`button`,onClick:()=>s(e=>!e),"aria-expanded":o,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[I(`span`,{children:[o?`Hide`:`Show`,` node list`]}),V(We,{className:[`h-4 w-4 transition-transform`,o?`rotate-180`:``].join(` `)})]}),V(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?I(R,{children:[V(`aside`,{className:[o?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:V(_t,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),s(!1)},refreshToken:i})}),V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?V(qn,{refreshToken:i}):V(sn,{nodeId:r,refreshToken:i})})]}):V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:V(Dr,{refreshToken:i})})})]})}export{Ar as PipelinePage};
@@ -1 +0,0 @@
1
- import{Kr as e,M as t,Mn as n,Xr as r,_a as i,ba as a,ga as o,ha as s,lo as c,ma as l,oi as u,pa as d,po as f,so as p,ti as m,va as h,xo as g,ya as _}from"./src-C0ryWGb4.js";import{I as v,Q as y,S as b,W as x,o as S,q as C,x as w,z as T}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{$ as E,P as D}from"./src-B0nZ9rxd.js";import{o as O,p as k}from"./player-overlays-BfbNCp8v.js";import{i as A}from"./AddLocationWizard-DjfJYSAe.js";import{t as j}from"./circle-x-B04aLzqg.js";import{t as ee}from"./download-CkwHHo3N.js";import{A as M,E as N,S as P,U as F,W as te,i as I,s as L,z as R}from"./index-BpMOZW4i.js";import{t as z}from"./AdminPage-Dq33XE9j.js";import{r as B}from"./authed-media-B8T1dsFh.js";import{t as ne}from"./DeviceAggregateSection-BjrIcNw5.js";import{t as V}from"./AdminTabs-D9PvjiYm.js";import{t as H}from"./format-size-CO9d3C3-.js";import{t as U}from"./ClusterRecordingTab-ColxtGy-.js";var W=te(`scissors`,[[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M8.12 8.12 12 12`,key:`1alkpv`}],[`path`,{d:`M20 4 8.12 15.88`,key:`xgtan2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M14.8 14.8 20 20`,key:`ptml3r`}]]);y();function G(){let e=n({}),r=x(()=>(e.data??[]).filter(e=>e.type===D.Camera).sort((e,t)=>e.name.localeCompare(t.name)),[e.data]),[i,a]=C(null),o=i??r[0]?.id??null;return!e.isLoading&&r.length===0?w(c,{icon:R,title:`No cameras`,description:`Add a camera first.`}):b(`div`,{className:`space-y-3`,children:[b(`div`,{className:`flex items-center gap-2`,children:[w(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Camera`}),w(`select`,{value:o??``,onChange:e=>a(Number(e.target.value)),className:`rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:r.map(e=>w(`option`,{value:e.id,children:e.name},e.id))})]}),o!==null&&w(t,{deviceId:o,children:w(ne,{deviceId:o,sectionFilter:e=>e.location===`top-tab`&&e.tab===`recording`})},o)]})}y();var K=[`high`,`mid`,`low`],q=[{value:1,label:`Real time (1×)`},{value:2,label:`2×`},{value:4,label:`4×`},{value:8,label:`8×`},{value:16,label:`16×`}],J=10080*60*1e3;function Y(e){let t=new Date(Date.now()-e*6e4),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function X({onClose:e,onCreated:t}){let r=n({}),i=x(()=>(r.data??[]).filter(e=>e.type===D.Camera).sort((e,t)=>e.name.localeCompare(t.name)),[r.data]),[a,o]=C(``),[c,l]=C(`high`),[u,d]=C(Y(60)),[f,p]=C(Y(0)),[m,h]=C(1),[g,_]=C(!0),[v,y]=C(``),[S,T]=C(null),E=a===``?i[0]?.id??null:a,O=new Date(u).getTime(),k=new Date(f).getTime(),A=Number.isFinite(O)&&Number.isFinite(k)&&O<k,j=s({onSuccess:()=>{t(),e()},onError:e=>T(e instanceof Error?e.message:String(e))});return w(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:e,children:b(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[b(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[b(`h2`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[w(N,{className:`h-3.5 w-3.5`}),`New export`]}),w(`button`,{onClick:e,className:`text-foreground-subtle hover:text-foreground`,children:w(I,{className:`h-4 w-4`})})]}),b(`div`,{className:`p-4 space-y-3`,children:[b(`div`,{className:`grid grid-cols-2 gap-3`,children:[b(`div`,{className:`space-y-1`,children:[w(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Camera`}),w(`select`,{value:E??``,onChange:e=>o(Number(e.target.value)),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:i.map(e=>w(`option`,{value:e.id,children:e.name},e.id))})]}),b(`div`,{className:`space-y-1`,children:[w(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Profile`}),w(`select`,{value:c,onChange:e=>l(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:K.map(e=>w(`option`,{value:e,children:e},e))})]})]}),b(`div`,{className:`grid grid-cols-2 gap-3`,children:[b(`div`,{className:`space-y-1`,children:[w(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`From`}),w(`input`,{type:`datetime-local`,value:u,onChange:e=>d(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`})]}),b(`div`,{className:`space-y-1`,children:[w(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`To`}),w(`input`,{type:`datetime-local`,value:f,onChange:e=>p(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`})]})]}),b(`div`,{className:`grid grid-cols-2 gap-3`,children:[b(`div`,{className:`space-y-1`,children:[w(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Speed`}),w(`select`,{value:m,onChange:e=>h(Number(e.target.value)),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:q.map(e=>w(`option`,{value:e.value,children:e.label},e.value))})]}),b(`div`,{className:`space-y-1`,children:[w(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Title (optional)`}),w(`input`,{type:`text`,value:v,onChange:e=>y(e.target.value),placeholder:`e.g. courier at the gate`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle`})]})]}),b(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[w(`input`,{type:`checkbox`,checked:g,disabled:m!==1,onChange:e=>_(e.target.checked),className:`accent-primary`}),`Include audio`,m===1?``:` (real-time only)`]}),!A&&w(`p`,{className:`text-[11px] text-danger`,children:`"From" must be before "To".`}),S&&w(`p`,{className:`text-[11px] text-danger`,children:S})]}),b(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[w(`button`,{onClick:e,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),w(`button`,{onClick:()=>{if(E===null||!A)return;T(null);let e=v.trim();j.mutate({deviceId:E,profile:c,fromMs:O,toMs:k,options:{includeAudio:g,maxLifeMs:J,deleteAfterDownload:!1,...m===1?{}:{speed:m},...e.length>0?{title:e}:{}}})},disabled:E===null||!A||j.isPending,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:j.isPending?`Queuing…`:`Create export`})]})]})})}function Z(e){let t=[];return e.timelapse?t.push(`timelapse ${String(e.timelapse.everyMs/1e3)}s`):(t.push(`${String(e.speed??1)}×`),e.includeAudio&&t.push(`+ audio`)),t.join(` `)}function Q(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function re(e,t){let n=Math.max(0,Math.round((t-e)/1e3)),r=Math.floor(n/3600),i=Math.floor(n%3600/60),a=n%60,o=r>0?`${String(r)}:${String(i).padStart(2,`0`)}:${String(a).padStart(2,`0`)}`:`${String(i)}:${String(a).padStart(2,`0`)}`;return`${Q(e)} · ${o}`}function ie(e,t){let n=e-t;if(n<=0)return`expired`;let r=Math.floor(n/6e4);if(r<60)return`in ${String(r)}m`;let i=Math.floor(r/60);return i<24?`in ${String(i)}h`:`in ${String(Math.floor(i/24))}d`}function ae(e,t,n,r){return e.map(e=>{if(e.state===`expired`||e.state===`deleted`)return e;let i=r.get(e.id);if(i)return{...e,state:`failed`,error:i.error,progressPct:null};let a=n.get(e.id);if(a)return{...e,state:`ready`,fileBytes:a.fileBytes,progressPct:100};let o=t.get(e.id);return o&&(e.state===`queued`||e.state===`rendering`)?{...e,state:`rendering`,progressPct:o.progressPct}:e})}y();var oe=[[`recordingExport`]],se={queued:{cls:`bg-muted text-foreground-subtle`,label:`queued`},rendering:{cls:`bg-primary/10 text-primary`,label:`rendering`,spin:!0},ready:{cls:`bg-success/10 text-success`,label:`ready`},failed:{cls:`bg-danger/10 text-danger`,label:`failed`},expired:{cls:`bg-muted text-foreground-subtle`,label:`expired`},deleted:{cls:`bg-muted text-foreground-subtle`,label:`deleted`}};function ce(){let{data:e,isLoading:t}=i({},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`queued`||e.state===`rendering`)?3e3:!1}),{map:n}=f(E.RecordingExportProgress,e=>e.exportId),{map:r}=f(E.RecordingExportCompleted,e=>e.exportId),{map:a}=f(E.RecordingExportFailed,e=>e.exportId);return{rows:x(()=>ae(e??[],n,r,a),[e,n,r,a]),isLoading:t}}function le(e){let[t,n]=C(()=>Date.now());return T(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function ue(){let e=S(),[t,r]=C(!1),i=()=>{e.invalidateQueries({queryKey:[[`recordingExport`,`listExports`]]})},a=p(),s=k().trpcClient,u=le(6e4),{rows:d,isLoading:f}=ce(),{data:m}=n({}),h=x(()=>{let e=new Map;for(let t of m??[])e.set(t.id,t.name);return e},[m]),_=v(()=>{e.invalidateQueries({queryKey:oe})},[e]),y=l({onSuccess:_}),T=o({onSuccess:_}),[E,D]=C(null),O=v(async e=>{D(e.id);try{let{url:t}=await s.recordingExport.getDownloadUrl.query({exportId:e.id}),n=await B(t),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.options.title??e.id}.mp4`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r),_()}finally{D(null)}},[s,_]),A=v(async e=>{await a({title:`Cancel this export?`,message:`Stops the render. The partial file is discarded.`,confirmLabel:`Cancel export`,variant:`danger`})&&y.mutate({exportId:e.id})},[a,y]),M=v(async e=>{await a({title:`Delete this export?`,message:`Permanently removes the rendered file and its history row.`,confirmLabel:`Delete`,variant:`danger`})&&T.mutate({exportId:e.id})},[a,T]),F=x(()=>[{key:`camera`,header:`Camera`,render:e=>w(`span`,{className:`text-foreground`,children:h.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`range`,header:`Range`,nowrap:!0,render:e=>w(`span`,{className:`tabular-nums`,children:re(e.fromMs,e.toMs)})},{key:`variant`,header:`Variant`,render:e=>w(`span`,{className:`text-foreground-subtle`,children:Z(e.options)})},{key:`state`,header:`State`,render:e=>{let t=se[e.state];return b(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${t.cls}`,children:[t.spin&&w(P,{className:`h-2.5 w-2.5 animate-spin`}),t.label,e.state===`rendering`&&e.progressPct!==null&&b(`span`,{className:`tabular-nums`,children:[e.progressPct,`%`]})]})}},{key:`expiry`,header:`Expires`,nowrap:!0,render:e=>e.state===`deleted`?w(`span`,{className:`text-foreground-subtle`,children:`—`}):w(`span`,{className:`text-foreground-subtle tabular-nums`,children:ie(e.expiresAt,u)})},{key:`size`,header:`Size`,align:`right`,nowrap:!0,render:e=>w(`span`,{className:`tabular-nums`,children:e.fileBytes===null?`—`:H(e.fileBytes)})},{key:`actions`,header:``,align:`right`,render:e=>{let t=e.state===`ready`,n=e.state===`queued`||e.state===`rendering`,r=e.state!==`deleted`;return b(`div`,{className:`flex items-center justify-end gap-1`,children:[t&&b(`button`,{onClick:()=>{O(e)},disabled:E===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-primary/10 hover:text-foreground disabled:opacity-50`,title:`Download MP4`,children:[E===e.id?w(P,{className:`h-3 w-3 animate-spin`}):w(ee,{className:`h-3 w-3`}),`Download`]}),n&&b(`button`,{onClick:()=>{A(e)},disabled:y.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:`Cancel render`,children:[w(j,{className:`h-3 w-3`}),`Cancel`]}),r&&w(`button`,{onClick:()=>{M(e)},disabled:T.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 export`,children:w(L,{className:`h-3 w-3`})})]})}}],[h,u,E,y.isPending,T.isPending,O,A,M]);return f&&d.length===0?b(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[w(P,{className:`h-4 w-4 animate-spin`}),`Loading exports…`]}):b(`div`,{className:`space-y-3`,children:[w(`div`,{className:`flex justify-end`,children:b(`button`,{onClick:()=>r(!0),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground`,children:[w(N,{className:`h-3.5 w-3.5`}),`New export`]})}),d.length===0?w(c,{icon:N,title:`No exports yet`,description:`Create one here (New export) or from a camera's timeline in the viewer. Rendered clips show up here to download or manage.`}):w(g,{columns:F,rows:d,rowKey:e=>e.id,minWidthPx:720}),t&&w(X,{onClose:()=>r(!1),onCreated:i})]})}y();var de=[[`recording`]],$=[{value:`retention`,label:`Retention policy`},{value:`quota`,label:`Quota / disk pressure`},{value:`operator`,label:`Operator`}];function fe(e){return e.totalBytes===null||e.totalBytes<=0?null:Math.min(1,Math.max(0,e.usedBytes/e.totalBytes))}function pe(){let e=S(),t=p(),[r,i]=C(`retention`),{data:o,isLoading:s}=h({},{refetchOnWindowFocus:!1}),{data:l}=n({}),u=x(()=>{let e=new Map;for(let t of l??[])e.set(t.id,t.name);return e},[l]),f=v(()=>{e.invalidateQueries({queryKey:de})},[e]),m=a({onSuccess:f}),_=d({onSuccess:f}),y=v(async e=>{await t({title:`Prune ${u.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Applies the retention policy now (reason: ${r}). Footage beyond the policy is permanently deleted.`,confirmLabel:`Prune now`,variant:`danger`})&&m.mutate({deviceId:e.deviceId,reason:r})},[t,m,r,u]),T=v(async e=>{await t({title:`Delete all footage for ${u.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${H(e.usedBytes)} of recorded footage for this camera. This cannot be undone.`,confirmLabel:`Delete ${H(e.usedBytes)}`,variant:`danger`})&&_.mutate({deviceId:e.deviceId})},[t,_,u]),E=x(()=>[{key:`camera`,header:`Camera`,render:e=>w(`span`,{className:`text-foreground`,children:u.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`used`,header:`Used`,align:`right`,nowrap:!0,render:e=>w(`span`,{className:`tabular-nums`,children:H(e.usedBytes)})},{key:`actions`,header:``,align:`right`,render:e=>b(`div`,{className:`flex items-center justify-end gap-1`,children:[b(`button`,{onClick:()=>{y(e)},disabled:m.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:`Apply retention policy now`,children:[w(W,{className:`h-3 w-3`}),`Prune`]}),b(`button`,{onClick:()=>{T(e)},disabled:_.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 all footage`,children:[w(L,{className:`h-3 w-3`}),`Delete`]})]})}],[u,y,T,m.isPending,_.isPending]);if(s&&!o)return b(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[w(P,{className:`h-4 w-4 animate-spin`}),`Loading storage usage…`]});if(!o)return w(c,{icon:A,title:`No storage data`,description:`The recording node has not reported any storage usage yet.`});let D=o.devices.length;return b(`div`,{className:`flex flex-col gap-6`,children:[b(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[w(O,{label:`Total used`,icon:w(A,{className:`h-3 w-3`}),footer:`${String(D)} camera${D===1?``:`s`} on ${o.nodeId}`,children:H(o.totalUsedBytes)}),o.locations.map(e=>{let t=fe(e),n=e.locationId??`default`;return w(O,{label:`Disk: ${(e.locationIds??[n]).join(` + `)}`,footer:e.availableBytes===null?`${H(e.usedBytes)} used (capacity unknown)`:`${H(e.availableBytes)} free${e.totalBytes===null?``:` of ${H(e.totalBytes)}`}`,children:t===null?w(`span`,{className:`tabular-nums`,children:H(e.usedBytes)}):b(`div`,{className:`flex items-center gap-2`,children:[w(`div`,{className:`h-2 flex-1 overflow-hidden rounded bg-muted`,children:w(`div`,{className:`h-full rounded ${t>.9?`bg-danger`:t>.75?`bg-amber-500`:`bg-primary`}`,style:{width:`${String(Math.round(t*100))}%`}})}),b(`span`,{className:`tabular-nums text-xs`,children:[Math.round(t*100),`%`]})]})},n)})]}),b(`section`,{className:`flex items-center gap-2 text-xs`,children:[w(`label`,{htmlFor:`prune-reason`,className:`text-foreground-subtle`,children:`Prune reason`}),w(`select`,{id:`prune-reason`,value:r,onChange:e=>{let t=$.find(t=>t.value===e.target.value);t&&i(t.value)},className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:$.map(e=>w(`option`,{value:e.value,children:e.label},e.value))})]}),D===0?w(c,{icon:A,title:`No recorded footage`,description:`No camera has recorded footage on this node yet.`}):w(g,{columns:E,rows:[...o.devices],rowKey:e=>e.deviceId,minWidthPx:480})]})}y();var me=[[`pipelineAnalytics`]],he=1440*60*1e3,ge=[{days:1,label:`1 day`},{days:7,label:`7 days`},{days:30,label:`30 days`},{days:90,label:`90 days`}];function _e(){let t=S(),i=p(),[a,o]=C(30),{data:s,isLoading:l}=r({},{refetchOnWindowFocus:!1}),{data:d}=n({}),f=x(()=>{let e=new Map;for(let t of d??[])e.set(t.id,t.name);return e},[d]),m=v(()=>{t.invalidateQueries({queryKey:me})},[t]),h=u({onSuccess:m}),_=e({onSuccess:m}),y=v(async()=>{await i({title:`Prune events older than ${String(a)} day${a===1?``:`s`}?`,message:`Permanently deletes every event (motion / object / audio) older than the cutoff across all cameras, and their media. This cannot be undone.`,confirmLabel:`Prune events`,variant:`danger`})&&h.mutate({olderThanMs:Date.now()-a*he,reason:`retention`})},[i,h,a]),T=v(async e=>{await i({title:`Delete all events for ${f.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${String(e.rows)} event${e.rows===1?``:`s`} (${H(e.bytes)} of media) for this camera. This cannot be undone.`,confirmLabel:`Delete events`,variant:`danger`})&&_.mutate({deviceId:e.deviceId})},[i,_,f]),E=x(()=>[{key:`camera`,header:`Camera`,render:e=>w(`span`,{className:`text-foreground`,children:f.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`rows`,header:`Events`,align:`right`,nowrap:!0,render:e=>w(`span`,{className:`tabular-nums`,children:e.rows.toLocaleString()})},{key:`bytes`,header:`Media`,align:`right`,nowrap:!0,render:e=>w(`span`,{className:`tabular-nums`,children:H(e.bytes)})},{key:`actions`,header:``,align:`right`,render:e=>b(`button`,{onClick:()=>{T(e)},disabled:_.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 all events for this camera`,children:[w(L,{className:`h-3 w-3`}),`Delete`]})}],[f,T,_.isPending]);return l&&!s?b(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[w(P,{className:`h-4 w-4 animate-spin`}),`Loading event-store footprint…`]}):s?b(`div`,{className:`flex flex-col gap-6`,children:[b(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[w(O,{label:`Total events`,icon:w(M,{className:`h-3 w-3`}),footer:`across ${String(s.devices.length)} camera${s.devices.length===1?``:`s`}`,children:s.totalRows.toLocaleString()}),w(O,{label:`Event media on disk`,children:H(s.totalBytes)})]}),b(`section`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[w(`span`,{className:`text-foreground-subtle`,children:`Prune events older than`}),w(`select`,{value:a,onChange:e=>o(Number(e.target.value)),className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:ge.map(e=>w(`option`,{value:e.days,children:e.label},e.days))}),b(`button`,{onClick:()=>{y()},disabled:h.isPending,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-xs font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,children:[h.isPending?w(P,{className:`h-3 w-3 animate-spin`}):w(W,{className:`h-3 w-3`}),`Prune now`]})]}),s.devices.length===0?w(c,{icon:M,title:`No stored events`,description:`No camera has persisted events yet.`}):w(g,{columns:E,rows:[...s.devices],rowKey:e=>e.deviceId,minWidthPx:480})]}):w(c,{icon:M,title:`No event data`,description:`Pipeline analytics has not reported any event-store footprint yet.`})}y();var ve=[{value:`all`,label:`All`},{value:`recording`,label:`Recordings`},{value:`events`,label:`Events`}],ye={recording:`bg-primary/10 text-primary`,events:`bg-violet-500/10 text-violet-400`};function be(e){return new Date(e).toLocaleString()}function xe(){let[e,t]=C(`all`),{data:r,isLoading:i}=_({},{refetchOnWindowFocus:!1}),{data:a,isLoading:o}=m({},{refetchOnWindowFocus:!1}),{data:s}=n({}),l=x(()=>{let e=new Map;for(let t of s??[])e.set(t.id,t.name);return e},[s]),u=x(()=>{let t=[...r??[],...a??[]];return(e===`all`?t:t.filter(t=>t.domain===e)).toSorted((e,t)=>t.at-e.at)},[r,a,e]),d=x(()=>[{key:`at`,header:`When`,nowrap:!0,render:e=>w(`span`,{className:`text-foreground-subtle tabular-nums`,children:be(e.at)})},{key:`domain`,header:`Domain`,render:e=>w(`span`,{className:`inline-flex rounded px-1.5 py-0.5 text-[10px] font-medium ${ye[e.domain]}`,children:e.domain})},{key:`op`,header:`Operation`,render:e=>w(`span`,{className:`text-foreground`,children:e.op})},{key:`reason`,header:`Reason`,render:e=>w(`span`,{className:`text-foreground-subtle`,children:e.reason})},{key:`device`,header:`Camera`,render:e=>e.deviceId===null?w(`span`,{className:`text-foreground-subtle`,children:`cluster`}):w(`span`,{className:`text-foreground`,children:l.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`items`,header:`Items`,align:`right`,nowrap:!0,render:e=>w(`span`,{className:`tabular-nums`,children:e.itemsAffected.toLocaleString()})},{key:`bytes`,header:`Reclaimed`,align:`right`,nowrap:!0,render:e=>w(`span`,{className:`tabular-nums`,children:e.bytesReclaimed>0?H(e.bytesReclaimed):`—`})}],[l]),f=i||o;return b(`div`,{className:`flex flex-col gap-4`,children:[w(`div`,{className:`flex items-center gap-1`,children:ve.map(n=>w(`button`,{onClick:()=>t(n.value),className:`rounded px-2 py-1 text-xs font-medium ${e===n.value?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-muted`}`,children:n.label},n.value))}),f&&u.length===0?b(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[w(P,{className:`h-4 w-4 animate-spin`}),`Loading activity…`]}):u.length===0?w(c,{icon:F,title:`No activity yet`,description:`Prune, delete and rescan operations across recordings and events show up here.`}):w(g,{columns:d,rows:u,rowKey:e=>e.id,minWidthPx:720})]})}function Se(){return w(z,{icon:N,title:`Recordings`,subtitle:`Recording node & storage, event-store management, exported clips, and an activity log.`,children:w(V,{tabs:[{id:`recordings`,label:`Recordings`,icon:A,content:w(U,{})},{id:`cameras`,label:`Cameras`,icon:R,content:w(G,{})},{id:`storage`,label:`Storage`,icon:A,content:w(pe,{})},{id:`events`,label:`Events`,icon:M,content:w(_e,{})},{id:`exports`,label:`Exports`,icon:N,content:w(ue,{})},{id:`activity`,label:`Activity`,icon:F,content:w(xe,{})}]})})}export{Se as RecordingsPage};
@@ -1 +0,0 @@
1
- import{W as e}from"./index-BpMOZW4i.js";var t=e(`circle-check-big`,[[`path`,{d:`M21.801 10A10 10 0 1 1 17 3.335`,key:`yps3ct`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]);export{t};
@@ -1 +0,0 @@
1
- import{W as e}from"./index-BpMOZW4i.js";var t=e(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`polyline`,{points:`12 6 12 12 16 14`,key:`68esgv`}]]);export{t};