@camstack/addon-admin-ui 1.2.88 → 1.2.90

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 (110) hide show
  1. package/dist/assets/{AddLocationWizard-BntkKU2V.js → AddLocationWizard-Cfcvdso2.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-DfZQjIPJ.js → AddonCollectionPage-DgxQiC5R.js} +1 -1
  3. package/dist/assets/Addons-DIkbBQAN.js +1 -0
  4. package/dist/assets/{AdminTabs-FswV6m19.js → AdminTabs-DS0Srvsl.js} +1 -1
  5. package/dist/assets/{AiProfiles-Bol2xzPZ.js → AiProfiles-CxEToJhw.js} +1 -1
  6. package/dist/assets/{BrokerForm-rlgpgB9M.js → BrokerForm-C2Ffj2TP.js} +1 -1
  7. package/dist/assets/{Build--P11mU0s.js → Build-CjZnQDw-.js} +1 -1
  8. package/dist/assets/{Capabilities-Di_wIznW.js → Capabilities-DCCQTIe1.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-BOwdQNDH.js → CapabilityBadges-D5vvC1yi.js} +1 -1
  10. package/dist/assets/{Cluster-B58mM4Kr.js → Cluster-xCjfPks5.js} +1 -1
  11. package/dist/assets/{Data-uwnl2ZR0.js → Data-Bx3JEBlB.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-wpF45dZl.js → DetectionIntelligence-D0-LailW.js} +1 -1
  13. package/dist/assets/{DeviceAggregateSection-r5_ljoI1.js → DeviceAggregateSection-BCYifsQE.js} +1 -1
  14. package/dist/assets/DeviceDetail-l4ItEN2Q.js +2 -0
  15. package/dist/assets/{Devices-D3k50BRl.js → Devices-CrnIRovn.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-C2EWx5XY.js → EmbedPlayerPage-CZ6zyHHW.js} +1 -1
  17. package/dist/assets/Events-DQHeF8ak.js +1 -0
  18. package/dist/assets/{FormBuilder-QY4tah4S.js → FormBuilder-DoXEuyDl.js} +1 -1
  19. package/dist/assets/{Identity-BV8WXb2H.js → Identity-CyFJ39bP.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-ClwD7H7W.js → IntegrationDetail-D2BcdghA.js} +1 -1
  21. package/dist/assets/{Integrations-Dy_WWWKK.js → Integrations-DNlWMb_O.js} +1 -1
  22. package/dist/assets/{Integrations-BGbVMFT4.js → Integrations-sEcPRDl_.js} +1 -1
  23. package/dist/assets/{Logs-Dr2j0QZR.js → Logs-CkSiZEDd.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-Ds8nYWoN.js → MotionZonesSettings-Cswy44AX.js} +1 -1
  25. package/dist/assets/{MyAccess-Bsf24wbg.js → MyAccess-YfTGgX7y.js} +1 -1
  26. package/dist/assets/Network-BlbxdrNT.js +1 -0
  27. package/dist/assets/{NodeAddonsSettingsPanel-B3-jgI6Y.js → NodeAddonsSettingsPanel-DBFMTvCH.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-vixWXUkV.js → NodeInferenceDevices-B73NC03X.js} +1 -1
  29. package/dist/assets/{Notifications-DbYpUqwt.js → Notifications-ppv_emHc.js} +1 -1
  30. package/dist/assets/Pipeline-ujYtuLUK.js +1 -0
  31. package/dist/assets/{Plates-BIkYeFJp.js → Plates-BlLBjmm0.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-C2nmPqsf.js → PrivacyMaskSettings-DXTJ79bO.js} +1 -1
  33. package/dist/assets/{ProviderIcon-yuhuUjyO.js → ProviderIcon-MfX3M-Ob.js} +1 -1
  34. package/dist/assets/Recordings-Cb5e0T7R.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-B6Dhtqhv.js → ScanNetworkModal-BIIqnjlI.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-CpU_-6iK.js → SceneMonitorEditor-CGpMYdow.js} +1 -1
  37. package/dist/assets/{Scenes-Bp-HU3HC.js → Scenes-Bkv_F5Zt.js} +1 -1
  38. package/dist/assets/{Settings-CxNCTStH.js → Settings-DexyTMK3.js} +1 -1
  39. package/dist/assets/{Showroom-BfQj_ruk.js → Showroom-BXbcCAve.js} +1 -1
  40. package/dist/assets/{Terminal-COkGK9Eu.js → Terminal-ChyYT2Xd.js} +5 -5
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CtfWG-B0.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C7gqtZRe.js} +1 -1
  42. package/dist/assets/{bell-ring-BIkgL1EI.js → bell-ring-BSDAxanc.js} +1 -1
  43. package/dist/assets/{boxes-EqdcdFpg.js → boxes-OU9o0K_I.js} +1 -1
  44. package/dist/assets/{build-cluster-graph-C0MeCzJZ.js → build-cluster-graph-CkdrNOrw.js} +1 -1
  45. package/dist/assets/circle-check-big-B7_QKFSQ.js +1 -0
  46. package/dist/assets/{circle-x-CBZPec7u.js → circle-x-DgXg62nX.js} +1 -1
  47. package/dist/assets/clock-DrVdCcaX.js +1 -0
  48. package/dist/assets/{copy-BPgY4Eey.js → copy-DS7H6-em.js} +1 -1
  49. package/dist/assets/{debounced-invalidate-B1bc5kFD.js → debounced-invalidate-DX8r5XfG.js} +1 -1
  50. package/dist/assets/dist-BmzucNaP.js +349 -0
  51. package/dist/assets/dist-Cw4PMJs2.js +1 -0
  52. package/dist/assets/{download-Dq2bfdRX.js → download-FcOcOShY.js} +1 -1
  53. package/dist/assets/{face-bbox-DUGyLE43.js → face-bbox-C_ak-5Gz.js} +1 -1
  54. package/dist/assets/{hard-drive-COdkuHqf.js → hard-drive-JDbfX603.js} +1 -1
  55. package/dist/assets/{hostInit-BSakAGif.js → hostInit-XQNV3SQC.js} +1 -1
  56. package/dist/assets/index-B1t00qUp.js +4 -0
  57. package/dist/assets/{key-round-CfAFZkMw.js → key-round-DO25vFwm.js} +1 -1
  58. package/dist/assets/{mf-entry-bootstrap-0-e9ffa7b9.js → mf-entry-bootstrap-0-48e7c1b3.js} +2 -2
  59. package/dist/assets/{pencil-CfoKCBNv.js → pencil-C9e8FY_K.js} +1 -1
  60. package/dist/assets/play-DHOSTYVl.js +1 -0
  61. package/dist/assets/{player-overlays-CBKaIBph.js → player-overlays-DN_06_1T.js} +1 -1
  62. package/dist/assets/plus-5BBPoTgM.js +1 -0
  63. package/dist/assets/power-C-BBysAq.js +1 -0
  64. package/dist/assets/{radio-BOUTlTbE.js → radio-KghuZMQV.js} +1 -1
  65. package/dist/assets/{refresh-cw-CllqntzE.js → refresh-cw-S_IzGUwN.js} +1 -1
  66. package/dist/assets/remoteEntry-CrJWwg3y.js +1 -0
  67. package/dist/assets/rotate-ccw-CAAGiLAw.js +1 -0
  68. package/dist/assets/rotate-cw-DVJmPlX9.js +1 -0
  69. package/dist/assets/search-DXNVjwOG.js +1 -0
  70. package/dist/assets/{send-DcXtHjaz.js → send-BxpQV4uW.js} +1 -1
  71. package/dist/assets/{server-DbU7BgZv.js → server-CouJc0au.js} +1 -1
  72. package/dist/assets/{shield-BojVNBVL.js → shield-BLP_9cz7.js} +1 -1
  73. package/dist/assets/square-DO1rX5dt.js +1 -0
  74. package/dist/assets/{square-check-big-Ch-X3CcM.js → square-check-big-DGZA6wHf.js} +1 -1
  75. package/dist/assets/src-5IxHiQXr.js +349 -0
  76. package/dist/assets/src-Dw_YuA21.js +67 -0
  77. package/dist/assets/{star-BotqSaGv.js → star-COsLARFs.js} +1 -1
  78. package/dist/assets/{undo-2-CXIWJrgH.js → undo-2-CHGwpF3q.js} +1 -1
  79. package/dist/assets/{upload-CafOTsXz.js → upload-UbmWhfNy.js} +1 -1
  80. package/dist/assets/{use-scenes-feed-DTuzztEP.js → use-scenes-feed--CY2Z_u1.js} +1 -1
  81. package/dist/assets/useEventInvalidation-Co1T3fjc.js +1 -0
  82. package/dist/assets/{video-GQHe9bLG.js → video-7B-RN_5Z.js} +1 -1
  83. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-7s6IgvIP.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-xmN5U0v7.js} +2 -2
  84. package/dist/assets/{wifi-MOwlhPpo.js → wifi-B8upcnaM.js} +1 -1
  85. package/dist/assets/{zap-BiojyRpM.js → zap-qTa-8D3P.js} +1 -1
  86. package/dist/index.html +5 -5
  87. package/dist/server/addon.js +130 -17
  88. package/package.json +1 -1
  89. package/dist/assets/Addons-Cof7W-Ym.js +0 -1
  90. package/dist/assets/DeviceDetail-Bf3FJFNv.js +0 -2
  91. package/dist/assets/Events-DuXVjBmB.js +0 -1
  92. package/dist/assets/Network-D_OMCOsR.js +0 -1
  93. package/dist/assets/Pipeline-m823fIKM.js +0 -1
  94. package/dist/assets/Recordings-ChPRJj_w.js +0 -1
  95. package/dist/assets/circle-check-big-DGl1OsLR.js +0 -1
  96. package/dist/assets/clock-M4NiOyl_.js +0 -1
  97. package/dist/assets/dist-DjbCvztb.js +0 -1
  98. package/dist/assets/dist-IEXliP3K.js +0 -349
  99. package/dist/assets/index-LPwis6Rq.js +0 -4
  100. package/dist/assets/play-CqrjGyv7.js +0 -1
  101. package/dist/assets/plus-DHRgxEWi.js +0 -1
  102. package/dist/assets/power-DGhEdOiQ.js +0 -1
  103. package/dist/assets/remoteEntry-BsYVmvk8.js +0 -1
  104. package/dist/assets/rotate-ccw-CdTrnBTI.js +0 -1
  105. package/dist/assets/rotate-cw-Dre2EA6E.js +0 -1
  106. package/dist/assets/search-Dx_k5G37.js +0 -1
  107. package/dist/assets/square-DynbJcCj.js +0 -1
  108. package/dist/assets/src-0pbBUmTo.js +0 -349
  109. package/dist/assets/src-BLHY9yig.js +0 -67
  110. package/dist/assets/useEventInvalidation-BDOhX3vo.js +0 -1
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,U as i,W as a,a as o,b as s,i as c,o as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as p}from"./player-overlays-CBKaIBph.js";import{Br as m,Ca as h,Dn as g,Et as _,Ft as v,Gi as y,It as b,Ls as x,Lt as S,Ns as C,Nt as w,Pt as T,Sa as E,Ta as D,Yt as O,_a as k,aa as A,ca as j,da as M,dn as N,fa as P,fn as F,ga as ee,j as I,la as te,ma as L,pa as R,sa as z,va as ne,wa as B,wt as re,xa as V,ya as H}from"./src-BLHY9yig.js";import{Rt as U,at as ie,mt as W}from"./src-0pbBUmTo.js";import{t as ae}from"./clock-M4NiOyl_.js";import{t as oe}from"./copy-BPgY4Eey.js";import{t as se}from"./download-Dq2bfdRX.js";import{a as ce,c as G,d as le,f as ue,i as de,m as fe,n as pe,o as me,p as he,r as ge,s as _e,t as ve}from"./debounced-invalidate-B1bc5kFD.js";import{t as ye}from"./refresh-cw-CllqntzE.js";import{t as be}from"./search-Dx_k5G37.js";import{t as xe}from"./square-check-big-Ch-X3CcM.js";import{t as Se}from"./square-DynbJcCj.js";import{t as Ce}from"./star-BotqSaGv.js";import{t as we}from"./undo-2-CXIWJrgH.js";import{C as K,G as Te,I as Ee,K as q,O as De,P as Oe,R as ke,i as Ae,l as je,s as Me,t as Ne,z as Pe}from"./index-LPwis6Rq.js";import{t as Fe}from"./AdminPage-CCD07UMs.js";import{i as Ie,n as Le,t as Re}from"./authed-media-BPd_L9jr.js";import{t as ze}from"./AdminTabs-FswV6m19.js";var Be=q(`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`}]]),Ve=q(`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`}]]),He=q(`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`}]]),Ue=q(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),We=q(`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`}]]),Ge=q(`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`}]]),Ke=q(`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`}]]),qe=q(`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`}]]);n();var Je=`pipeline-analytics`,Ye=`debug.listTracks`,Xe=`debug.analyze`,Ze=`/addon/pipeline-analytics/debug-export`;function Qe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $e(e,t){let n=e[t];return typeof n==`string`?n:null}function J(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function et(e,t){let n=e[t];return typeof n==`boolean`?n:null}function tt(e){return e===`error`||e===`warn`||e===`info`}function nt(e){if(!Qe(e))return null;let t=$e(e,`code`),n=$e(e,`detail`),r=e.severity;return t===null||n===null||!tt(r)?null:{code:t,severity:r,detail:n}}function rt(e){if(!Qe(e))return null;let t=$e(e,`trackId`),n=J(e,`deviceId`),r=$e(e,`className`),i=J(e,`firstSeen`),a=J(e,`lastSeen`),o=J(e,`durationMs`),s=et(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=$e(e,`label`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},firstSeen:i,lastSeen:a,durationMs:o,active:s}}function it(e){let t=rt(e);if(t===null||!Qe(e))return null;let n=J(e,`mediaCount`),r=J(e,`eventCount`),i=J(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=nt(e);t!==null&&c.push(t)}return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c}}function at(e){if(!Qe(e))return null;let t=et(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=rt(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function ot(e){if(!Qe(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=it(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var st={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 ct(e){return st[e]??e}var lt={error:0,warn:1,info:2};function ut(e){return e.toSorted((e,t)=>lt[e.severity]-lt[t.severity]||e.code.localeCompare(t.code))}function dt(e){return e.length===0?Ze:`${Ze}?deviceIds=${e.join(`,`)}`}function ft(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 pt=`all`,mt=`The server answered in a shape this build does not understand.`,ht={error:`danger`,warn:`warning`,info:`info`};function gt({findings:e}){return e.length===0?d(b,{variant:`success`,children:`no anomaly found`}):d(`div`,{className:`flex flex-wrap gap-1`,children:ut(e).map(e=>d(b,{variant:ht[e.severity],title:e.detail,children:ct(e.code)},e.code))})}function _t({track:e,report:t,cameraName:n,analyzing:i}){return r(`div`,{className:`flex flex-col gap-1.5 border-b border-border px-3 py-2.5 last:border-b-0`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`span`,{className:`font-medium text-foreground`,children:n}),d(`span`,{className:`text-foreground-subtle`,children:e.label??e.className}),r(`span`,{className:`text-foreground-subtle`,children:[new Date(e.lastSeen).toLocaleString(),` · `,ft(e.durationMs)]}),e.active&&d(b,{variant:`default`,children:`still open`}),t!==void 0&&r(`span`,{className:`text-foreground-subtle`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),d(`div`,{className:`flex items-center gap-2`,children:t===void 0?d(`span`,{className:`text-xs text-foreground-subtle`,children:i?`analysing…`:`not analysed`}):d(gt,{findings:t.findings})}),d(`code`,{className:`text-[10px] text-foreground-subtle`,children:e.trackId})]})}function vt(){let e=p(),[t,n]=u(pt),[i,s]=u(!1),[c,l]=u(null),f=m({}),h=a(()=>[{value:pt,label:`All cameras`},...(f.data??[]).map(e=>({value:String(e.id),label:e.name}))],[f.data]),g=a(()=>{let e=new Map;for(let t of f.data??[])e.set(t.id,t.name);return e},[f.data]),_=a(()=>t===pt?[]:[Number.parseInt(t,10)],[t]),y=o({queryKey:[`events-debug`,`list`,_],queryFn:async()=>at(await e.trpcClient.addons.custom.mutate({addonId:Je,action:Ye,input:_.length===0?{}:{deviceIds:_}}))}),b=a(()=>(y.data?.tracks??[]).map(e=>e.trackId),[y.data]),x=o({queryKey:[`events-debug`,`analyze`,b],enabled:b.length>0,queryFn:async()=>ot(await e.trpcClient.addons.custom.mutate({addonId:Je,action:Xe,input:{trackIds:b}}))}),C=a(()=>{let e=new Map;for(let t of x.data?.reports??[])e.set(t.trackId,t);return e},[x.data]),T=()=>{y.refetch(),x.refetch()},E=async()=>{s(!0),l(null);try{await Le(dt(_),`camstack-debug.zip`)}catch(e){l(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},D=y.data?.tracks??[],k=y.data===null||x.data===null;return d(Fe,{children:r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`div`,{className:`w-44`,children:d(w,{value:t,options:h,onChange:e=>n(e.target.value)})}),r(S,{variant:`secondary`,onClick:T,disabled:y.isFetching,children:[y.isFetching?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(ye,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(S,{onClick:()=>void E(),disabled:i||D.length===0,children:[i?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(se,{className:`h-3.5 w-3.5`}),`Export all (`,String(D.length),`)`]})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,d(`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.`]}),y.isError&&d(O,{message:`Could not load the marked tracks.`}),k&&!y.isError&&d(O,{message:mt}),c!==null&&d(O,{message:c}),y.data?.truncated===!0&&d(O,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(x.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(x.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),d(v,{children:y.isLoading?d(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`}):D.length===0?r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[d(Ve,{className:`h-5 w-5 text-foreground-subtle`}),d(`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.`})]}):D.map(e=>d(_t,{track:e,report:C.get(e.trackId),cameraName:g.get(e.deviceId)??`Camera ${String(e.deviceId)}`,analyzing:x.isFetching},e.trackId))})]})})}function yt(e){return e.subLabel??e.label}var bt=720*60*60*1e3;function xt(e){let t=[];for(let n of e)t.push(...n);return t}function St(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Ct(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 wt(e,t){return`${String(e)}:${t}`}function Tt(e,t){let n=new Map,r=new Set;for(let i of e){let e=wt(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 Et(e,t){return{since:e.fromMs??t-bt,until:e.toMs??t}}var Y=typeof z==`function`,Dt=`Track deletion arrives with the next server update`;function Ot(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var kt=Y?z:Ot,At=200,jt=3e4;function Mt(e){let t=p(),n=c({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:jt,refetchInterval:jt,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:At,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:St(xt(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}n();var Nt=[`events-feed`],Pt=2e3;function Ft(n){let r=l(),i=n?.paused===!0,a=t(r);a.current=r;let o=t(i);o.current=i;let[s,c]=u(!1),d=e(()=>{a.current.invalidateQueries({queryKey:Nt})},[]),p=t(void 0);p.current||=ve({delayMs:Pt,invalidate:()=>{o.current?c(!0):d()}}),f(()=>()=>p.current?.cancel(),[]),f(()=>{i||!s||(c(!1),d())},[i,s,d]);let m=e(()=>{c(!1),d()},[d]);return x(U.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),x(U.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function It({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=Ne(),[s,c]=u(!1),[l,f]=u(``),[p,m]=u(new Set),h=l.trim().toLowerCase(),g=e=>h.length===0||N(e,o).toLowerCase().includes(h),_=a(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>g(t)||g(e.macro))})).filter(e=>g(e.macro)||e.subs.length>0),[e,h]),v=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),y=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)},b=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},x=()=>n(new Set),S=t.size;return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${S>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(qe,{className:`h-3.5 w-3.5`}),S>0?`Kinds (${String(S)})`:`Kinds`,d(ke,{className:`h-3 w-3`})]}),s&&r(`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:[r(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[d(be,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`input`,{type:`text`,value:l,onChange:e=>f(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),S>0&&d(`button`,{type:`button`,onClick:x,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),_.length===0&&d(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:i?`Loading kinds…`:h.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),_.map(e=>{let n=F(e.macro.iconId),i=p.has(e.macro.kind)||h.length>0,a=t.has(e.macro.kind);return r(`div`,{className:`mb-0.5`,children:[r(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?d(`button`,{type:`button`,onClick:()=>v(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:d(i?ke:Ee,{className:`h-3 w-3`})}):d(`span`,{className:`w-3`}),r(`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:[d(`input`,{type:`checkbox`,checked:a,onChange:()=>y(e),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),d(`span`,{className:`font-medium`,children:N(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=F(e.iconId);return r(`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:[d(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>b(e.kind),className:`accent-primary`}),d(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),d(`span`,{children:N(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function Lt(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 Rt(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var zt=new Set([`detection`,`package`]);function Bt(e,t){return[...Lt(e,t).values()].filter(e=>e.parentKind===null&&zt.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Vt(e,t){let n=Lt(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,Rt(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))}n();var Ht=1400,Ut=`Admin-gated URL — opens only inside an authenticated session`;function Wt({label:t,value:n,title:i}){let[a,o]=u(!1);return f(()=>{if(!a)return;let e=setTimeout(()=>o(!1),Ht);return()=>clearTimeout(e)},[a]),r(`button`,{type:`button`,onClick:e(()=>{(async()=>{try{await navigator.clipboard.writeText(n),o(!0)}catch{window.prompt(`Copy the media URL:`,n)}})()},[n]),title:i,"aria-label":`Copy ${t} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${a?`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:[d(a?Pe:oe,{className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function Gt({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[d(Wt,{label:`Local`,value:e,title:`Copy LAN URL — ${Ut}`}),t&&d(Wt,{label:`Public`,value:t,title:`Copy public URL — ${Ut}`})]})}var Kt={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 qt(e){return e in Kt}function Jt(e){return qt(e)?Kt[e]:e}function Yt(e,t){return`${e}${Re}/${encodeURIComponent(t)}`}n();var Xt=3e4;function Zt(t){let[n,r]=u(null),i=e(e=>{r(t=>t??e)},[]);return f(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?d(Qt,{onOrigin:i}):null}}function Qt({onOrigin:e}){let{data:t}=g({capName:`network-access`});return d(s,{children:(t??[]).map(t=>d($t,{addonId:t.addonId,onOrigin:e},t.addonId))})}function $t({addonId:e,onOrigin:t}){let{data:n}=y({addonId:e},{refetchInterval:Xt,retry:!1});return f(()=>{let e=n?ie.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 en=typeof D==`function`,tn=`Track flags arrive with the next server update`;function nn(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var rn=en?D:nn;function an(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e)||!(`favourited`in e))return null;let{trackId:t,markForTrain:n,debug:r,favourited:i}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`||typeof i!=`boolean`?null:{trackId:t,markForTrain:n,debug:r,favourited:i}}n();function on({label:e,hint:t,checked:n,disabled:i,title:a,icon:o,onToggle:s}){return r(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:i,title:a,onClick:s,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:[d(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),r(`span`,{className:`min-w-0 flex-1`,children:[d(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),d(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),d(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:d(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function sn({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=rn(),[c,l]=u(null),f=c?.markForTrain??n===!0,p=c?.debug??i===!0,m=c?.favourited??a===!0,h=!en||s.isPending,g=en?void 0:tn,_=n=>{h||(async()=>{try{let r=an(await s.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;l(r),o?.(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 r(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[d(on,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:f,disabled:h,...g===void 0?{}:{title:g},icon:d(Ge,{className:`h-4 w-4`}),onToggle:()=>_({markForTrain:!f})}),d(on,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:p,disabled:h,...g===void 0?{}:{title:g},icon:d(Ve,{className:`h-4 w-4`}),onToggle:()=>_({debug:!p})}),d(on,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:m,disabled:h,...g===void 0?{}:{title:g},icon:d(Ce,{className:`h-4 w-4`}),onToggle:()=>_({favourited:!m})})]})}var X=100,cn=120,ln={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 un(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 dn(e,t,n){if(e.length===0||t===null)return ln;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return ln;let a=un(e,n?.maxPoints??cn).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}}n();var fn=15e3,pn=window.location.origin,mn=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),hn=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function gn(e){let[t,n]=u(null);return f(()=>{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 _n({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:r(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&d(`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&&d(`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)=>d(`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)=>d(`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:d(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&d(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&d(`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 r(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[d(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function vn({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:l}){let m=p(),h=kt(),g=t!==null,v=t?.deviceId??0,y=t?.trackId??``,b=t?.bestEventId??``,x=t?.timestamp??0,w=t?.windowMs??0,{data:T}=P({deviceId:v,trackId:y},{enabled:g}),{data:E}=R({trackId:y,deviceId:v},{enabled:g}),{data:D}=te({eventId:b,deviceId:v},{enabled:g&&b!==``}),{data:O}=C({deviceId:v,since:x-fn,until:x+w+fn},{enabled:g}),[k,A]=u(null),[j,M]=u(!1),{publicOrigin:N,probes:F}=Zt(g);f(()=>{A(null)},[v,y]);let ee=a(()=>{let e=E??[],t=D??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,D]),I=Ie(ee?`${Re}/${encodeURIComponent(ee.key)}`:void 0),L=a(()=>{let e=new Set,t=[];for(let n of[...D??[],...E??[]])!n.base64||e.has(n.key)||(e.add(n.key),t.push(n));return t},[D,E]),z=a(()=>L.find(e=>mn.has(e.kind))??null,[L]),ne=gn(z?`data:image/jpeg;base64,${z.base64}`:null),B=a(()=>dn(T?.positions??[],ne,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[T?.positions,T?.snapshots,ne]),V=e(e=>{let t=L.find(t=>t.key===e);t&&A(t)},[L]);if(t===null)return null;let H=k?`data:image/jpeg;base64,${k.base64}`:I.src,U=k?.kind??ee?.kind,ie=U!==void 0&&hn.has(U)&&ne!==null&&(T?.positions.length??0)>=2,W=O&&O.length>0?O[0]:null,ae=()=>{W&&(M(!0),(async()=>{try{let e=await m.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{M(!1)}})())},oe=()=>{!i||h.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await h.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},se=Math.round(t.importance*100),ce=T?.importanceReason?`${String(se)}% · ${T.importanceReason}`:`${String(se)}%`,G=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,ue=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,de=T?T.totalDistance.toFixed(2):`—`,me=he(T?T.firstSeen:x),ge=T?he(T.lastSeen):`—`;return d(re,{open:!0,onOpenChange:e=>!e&&o(),children:r(_,{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:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,yt(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,yt(t)]}):null]}),d(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),d(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:d(Ae,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[H?d(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:d(pe,{src:H,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:ie?d(_n,{overlay:B,onPickSnapshot:V}):void 0})}):d(`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:I.failed?r(s,{children:[d(fe,{className:`h-8 w-8 opacity-60`}),d(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):d(K,{className:`h-6 w-6 animate-spin opacity-70`})}),L.length>0&&d(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:L.map(e=>{let t=`data:image/jpeg;base64,${e.base64}`,n=Jt(e.kind),i=Yt(pn,e.key),a=N?Yt(N,e.key):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[d(`button`,{type:`button`,onClick:()=>A(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${he(e.timestamp)}`,children:d(`img`,{src:t,alt:n,className:`h-full w-full object-cover`})}),r(`figcaption`,{className:`min-w-0 px-0.5`,children:[d(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),d(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:he(e.timestamp),children:le(e.timestamp)})]}),d(Gt,{localUrl:i,publicUrl:a})]},e.key)})}),F,W&&r(S,{variant:`secondary`,onClick:ae,disabled:j,children:[j?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(De,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),d(sn,{deviceId:t.deviceId,trackId:t.trackId,...(T?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??t.markForTrain},...(T?.debug??t.debug)===void 0?{}:{debug:T?.debug??t.debug},...(T?.favourited??t.favourited)===void 0?{}:{favourited:T?.favourited??t.favourited},onChange:l}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[d($,{label:`Camera`,value:n}),d($,{label:`Class`,value:t.className}),d($,{label:`Label`,value:t.label??`—`}),d($,{label:`Sub-label`,value:t.subLabel??`—`}),d($,{label:`Importance`,value:ce}),d($,{label:`Zones visited`,value:G}),d($,{label:`Audio heard`,value:ue}),d($,{label:`Total distance`,value:de}),d($,{label:`First seen`,value:me}),d($,{label:`Last seen`,value:ge}),d($,{label:`Track`,value:t.trackId,mono:!0})]})]}),d(`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:d(`span`,{title:i?void 0:Dt,children:r(S,{variant:`secondary`,onClick:oe,disabled:!i||h.isPending,children:[h.isPending?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(Me,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function yn(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 bn({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s}){let c=Ie(e.bestEventId?`${Re}/${e.bestEventId}`:void 0),l=Math.round(e.importance*100),u=s===void 0?void 0:Math.round(s*100),f=yn(e.windowMs),p=()=>i(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[c.src?d(`img`,{src:c.src,alt:`Event from ${t}`,onClick:p,className:`h-full w-full cursor-zoom-in object-cover`}):d(`button`,{type:`button`,onClick:p,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:c.failed?`Key-event media unavailable`:`No key-event media`,children:d(fe,{className:`h-6 w-6 opacity-60`})}),o&&d(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(wt(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":a?`Deselect`:`Select`,children:a?d(xe,{className:`h-4 w-4 text-primary`}):d(Se,{className:`h-4 w-4`})}),u!==void 0&&r(`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(u),`%`]}),l>0&&d(`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(l)}),(e.markForTrain===!0||e.debug===!0||e.favourited===!0)&&r(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:d(Ge,{className:`h-3 w-3`})}),e.debug===!0&&d(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:d(Ve,{className:`h-3 w-3`})}),e.favourited===!0&&d(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Favourited`,"aria-label":`Favourited`,children:d(Ce,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:p,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[r(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,yt(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,yt(e)]}):null]}),d(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[d(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:ue(e.timestamp,n)}),f&&d(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:f})]})]})]})}n();function xn(){let[n,r]=u(!1),i=t(null),[a,o]=u(0),s=e(e=>{i.current!==e&&(i.current=e,o(e=>e+1))},[]);return f(()=>{let e=i.current;if(!e||typeof IntersectionObserver>`u`){r(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:s,scrolledPast:n}}n();var Sn=[`events-feed`],Cn=60,wn=[{value:`importance`,label:`Importance`,icon:Be},{value:`time`,label:`Recent`,icon:ae}];function Tn(){let e=l(),[t,n]=u(_e),[i,o]=u(new Set),[c,p]=u(new Set),[h,g]=u(0),[_,v]=u(`time`),[y,b]=u(new Set),[x,C]=u(null),[w,T]=u(()=>Date.now());f(()=>{let e=setInterval(()=>T(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:E,until:D}=a(()=>Et({fromMs:t.fromMs,toMs:t.toMs},w),[t.fromMs,t.toMs,w]),O=xn(),{pending:k,refreshNow:A}=Ft({paused:x!==null||y.size>0||O.scrolledPast}),{data:j}=m({}),M=a(()=>(j??[]).filter(e=>e.type===W.Camera),[j]),N=a(()=>M.map(e=>e.id),[M]),{data:P,isLoading:F}=L({deviceIds:N},{enabled:N.length>0,staleTime:5*6e4}),ee=a(()=>Vt(P??[],i),[P,i]),I=kt(),te=I.isPending,{rows:R,isLoading:z}=Mt({deviceIds:N,since:E,until:D,minImportance:h>0?h:void 0,classFilter:c.size===1?[...c][0]:void 0}),ne=a(()=>{let e=new Map;for(let t of M??[])e.set(t.id,t.name);return e},[M]),B=e=>ne.get(e)??`Camera #${String(e)}`,re=a(()=>G(R).map(e=>({id:e,name:B(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,ne]),V=a(()=>St(Ct(R,{cameras:i,classes:c,minImportance:h}),_),[R,i,c,h,_]),H=me(V,Cn,a(()=>JSON.stringify([[...i].sort((e,t)=>e-t),[...c].sort(),h,_,E,D]),[i,c,h,_,E,D])),U=()=>{e.invalidateQueries({queryKey:Sn})},ie=()=>b(new Set);function ae(e){b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function oe(){if(y.size===0||!Y)return;let e=Tt(R,y),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])=>I.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(wt(o,e));else t.push(o)}),b(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>B(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let se=V.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(ge,{onChange:n}),d(de,{cameras:re,selected:i,onChange:o}),d(It,{groups:ee,selected:c,onChange:p,loading:F}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Min score`}),d(`input`,{type:`range`,min:0,max:1,step:.05,value:h,onChange:e=>g(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),d(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(h*100)})]}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:wn.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>v(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${_===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[d(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!z&&d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:se?`${String(V.length)} of ${String(R.length)} events`:`${String(V.length)} event${V.length===1?``:`s`}`})]}),y.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[y.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[d(`span`,{title:Y?void 0:`Track deletion arrives with the next server update`,children:r(S,{variant:`secondary`,onClick:oe,disabled:!Y||te,children:[te?d(K,{className:`h-3.5 w-3.5 animate-spin`}):d(Me,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),d(S,{variant:`ghost`,onClick:ie,disabled:te,children:d(Ae,{className:`h-3.5 w-3.5`})})]})]}),z&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(K,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!z&&V.length===0&&d(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),k&&d(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:d(`button`,{type:`button`,onClick:A,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`})}),!z&&V.length>0&&r(s,{children:[d(`div`,{ref:O.ref,"aria-hidden":!0,className:`h-0`}),d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:H.pageItems.map(e=>d(bn,{row:e,cameraName:B(e.deviceId),nowMs:w,selected:y.has(wt(e.deviceId,e.trackId)),onToggleSelect:ae,onOpenDetail:C},wt(e.deviceId,e.trackId)))}),d(ce,{currentPage:H.page,totalItems:H.totalItems,pageSize:H.pageSize,onPageChange:H.setPage,itemNoun:`events`})]}),x&&d(vn,{row:x,cameraName:B(x.deviceId),deleteAvailable:Y,onClose:()=>C(null),onDeleted:()=>{U(),C(null)},onFlagsChanged:e=>{C(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var En=50,Dn=350,On=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function kn(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 An({onActiveChange:e}){let[t,n]=u(``),[i,o]=u(.2),[s,c]=u(null),[l,p]=u(null),[g,_]=u(null),v=I(t,Dn).trim(),y=v.length>0;f(()=>{e(y)},[y,e]);let[b,x]=u(()=>Date.now());f(()=>{let e=setInterval(()=>x(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:S}=m({}),C=a(()=>(S??[]).filter(e=>e.type===W.Camera),[S]),w=a(()=>{let e=new Map;for(let t of S??[])e.set(t.id,t.name);return e},[S]),T=e=>w.get(e)??`Camera #${String(e)}`,E=a(()=>C.map(e=>e.id),[C]),{data:D}=L({deviceIds:E},{enabled:E.length>0,staleTime:5*6e4}),O=a(()=>Bt(D??[],new Set(l===null?[]:[l])),[D,l]);f(()=>{s!==null&&(O.some(e=>e.kind===s)||c(null))},[O,s]);let{data:k,isFetching:A,isError:j,error:M}=h({text:v,minScore:i,limit:En,classFilter:s??void 0,deviceId:l??void 0},{enabled:y}),P=a(()=>[...k??[]].sort((e,t)=>t.score-e.score).map(e=>({...kn(e),score:e.score})),[k]);function F(e){c(t=>t===e?null:e)}return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`div`,{className:`relative min-w-[16rem] flex-1`,children:[d(be,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),d(`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&&d(`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:d(Ae,{className:`h-3.5 w-3.5`})})]}),A&&y&&d(K,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[d(`div`,{className:`flex items-center gap-1`,children:O.map(e=>d(`button`,{type:`button`,onClick:()=>F(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${s===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:N(e)},e.kind))}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Camera`}),r(`select`,{value:l===null?``:String(l),onChange:e=>p(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:[d(`option`,{value:``,children:`All`}),C.map(e=>d(`option`,{value:String(e.id),children:e.name},e.id))]})]}),r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(`span`,{children:`Match`}),d(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:On.map(e=>d(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${i===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))})]}),y&&!A&&!j&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[P.length,` match`,P.length===1?``:`es`]})]})]}),y&&r(`div`,{className:`space-y-3`,children:[j&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,M instanceof Error?M.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!j&&A&&P.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[d(K,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!j&&!A&&P.length===0&&r(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,v,`”. Try a looser match threshold or a different phrasing.`]}),!j&&P.length>0&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:P.map(e=>d(bn,{row:e,cameraName:T(e.deviceId),nowMs:b,score:e.score,onOpenDetail:_},e.id))})]}),g&&d(vn,{row:g,cameraName:T(g.deviceId),deleteAvailable:Y,onClose:()=>_(null),onDeleted:()=>_(null)})]})}var jn=15e3;function Mn(e){let t=p(),n=c({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:jn,refetchInterval:jn,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)}}n();function Nn(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 Pn({row:e,cameraName:t,nowMs:n}){let i=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,a=Ie(i?`${Re}/${i}`:void 0);return r(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[r(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[a.src?d(`img`,{src:a.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):d(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:d(Ke,{className:`h-6 w-6`})}),d(`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})]}),r(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[d(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Nn(n,e.becameStationaryAt)]})]})]})}function Fn(){let[e,t]=u(!1),n=Date.now(),{data:i}=m({}),o=a(()=>(i??[]).filter(e=>e.type===W.Camera),[i]),s=a(()=>o.map(e=>e.id),[o]),c=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.name);return e},[o]),{rows:l}=Mn(s);return l.length===0?null:r(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[r(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[d(e?ke:Ee,{className:`h-4 w-4 text-foreground-subtle`}),d(Ke,{className:`h-4 w-4 text-foreground-subtle`}),d(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),d(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:l.length}),d(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&d(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:l.map(e=>d(Pn,{row:e,cameraName:c.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function In(){let[e,t]=u(!1);return d(Fe,{children:r(`section`,{className:`space-y-3`,children:[d(An,{onActiveChange:t}),!e&&d(Fn,{}),!e&&d(Tn,{})]})})}var Ln=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Rn=new Set(Ln);function zn(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Rn.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function Bn({annotations:e,selectedIndex:t,onSelect:n,onChange:i,onDelete:a}){return e.length===0?r(`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 `,d(`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.`]}):d(`ul`,{className:`divide-y divide-border`,children:e.map((e,o)=>{let s=o===t,c=zn(e.label),l=zn(e.subLabel);return r(`li`,{className:`p-2.5 space-y-1.5 ${s?`bg-surface-hover`:``}`,onFocus:()=>{n(o)},children:[r(`div`,{className:`flex items-center gap-2`,children:[d(w,{className:`w-28`,value:e.macroClass,options:Ln.map(e=>({value:e,label:e})),onChange:e=>{let t=Ln.find(t=>t===e.target.value);t!==void 0&&i(o,{macroClass:t})}}),d(w,{className:`w-32`,value:e.kind,options:[{value:`subject`,label:`subject`},{value:`model_error`,label:`model error`}],onChange:e=>{i(o,{kind:e.target.value===`model_error`?`model_error`:`subject`})}}),e.source===`assist`&&r(b,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),d(S,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:d(Me,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[d(T,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{i(o,{label:e.target.value})}}),d(T,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:e=>{i(o,{subLabel:e.target.value})}})]}),c!==null&&d(`p`,{className:`text-[11px] text-danger`,children:c}),l!==null&&d(`p`,{className:`text-[11px] text-danger`,children:l})]},`${String(o)}-${String(e.bbox.x)}`)})})}function Vn(e){return e.every(e=>zn(e.label)===null&&zn(e.subLabel)===null&&Rn.has(e.macroClass))}function Hn(e){return e<0?0:e>1?1:e}function Un(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 Wn(e,t,n){return{x:Hn((e-n.left)/n.width),y:Hn((t-n.top)/n.height)}}function Gn(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 Kn(e){return e.w>=.01&&e.h>=.01}function qn(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 Jn(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}n();function Yn({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedIndex:c,onSelect:l,onDraw:f}){let p=t(null),[m,h]=u({w:0,h:0}),[g,_]=u(null);i(()=>{let e=p.current;if(e===null)return;let t=new ResizeObserver(()=>{h({w:e.clientWidth,h:e.clientHeight})});return t.observe(e),h({w:e.clientWidth,h:e.clientHeight}),()=>{t.disconnect()}},[]);let v=Un(m.w,m.h,a,o),y=e(e=>{let t=p.current;if(t===null||v===null)return null;let n=t.getBoundingClientRect();return Wn(e.clientX-n.left,e.clientY-n.top,v)},[v]);return r(`div`,{ref:p,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none`,onPointerDown:e=>{let t=y(e);t!==null&&(e.currentTarget.setPointerCapture(e.pointerId),_({start:t,current:Gn(t,t)}))},onPointerMove:e=>{if(g===null)return;let t=y(e);t!==null&&_({start:g.start,current:Gn(g.start,t)})},onPointerUp:()=>{if(g===null)return;let e=g.current;_(null),Kn(e)?f(e):l(Jn(s.map(e=>e.bbox),g.start))},children:[d(`img`,{src:n,alt:`Frame being annotated`,className:`absolute inset-0 w-full h-full object-contain pointer-events-none`}),v!==null&&s.map((e,t)=>{let n=qn(e.bbox,v),i=e.kind===`model_error`,a=t===c,o=i?`#ef4444`:a?`#22c55e`:`#3b82f6`;return d(`div`,{className:`absolute pointer-events-none`,style:{left:n.left,top:n.top,width:n.width,height:n.height,border:`${a?`2px`:`1px`} ${i?`dashed`:`solid`} ${o}`,opacity:e.source===`assist`&&!a?.65:1},children:r(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded`,style:{background:o,color:`#08121f`},children:[e.label??e.macroClass,i?` ✕`:``]})},`${String(t)}-${String(e.bbox.x)}-${String(e.bbox.y)}`)}),g!==null&&v!==null&&d(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:qn(g.current,v)})]})}function Xn(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function Zn({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 r(`div`,{className:`space-y-3`,children:[r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`In the dataset (`,t.length,`)`]}),t.length===0?d(`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.`}):d(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>d(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[r(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{s(e.frameId)},children:[d(Pe,{className:`h-3 w-3 text-success`}),d(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),r(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,Xn(e.sizeBytes)]})]}),r(`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:[d(Me,{className:`h-3 w-3`}),`remove`]})]})},e.frameId))})]}),r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,u.length,`)`]}),u.length===0?d(`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.`}):d(`ul`,{className:`flex flex-wrap gap-2`,children:u.map(e=>{let t=i.get(e.mediaKey);return r(`li`,{children:[r(S,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaKey)},children:[a?d(K,{className:`h-3 w-3 animate-spin`}):d(t===void 0?We:fe,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:e.kind}),d(`span`,{className:`ml-1 text-foreground-subtle`,children:Xn(e.sizeBytes)})]}),t!==void 0&&d(b,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaKey)})})]})]})}function Qn(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var $n={untouched:{icon:Ue,label:`to do`,variant:`default`},started:{icon:He,label:`frames only`,variant:`info`},ready:{icon:Oe,label:`annotated`,variant:`success`}};function er(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function tr({tracks:e,isLoading:t,selectedTrackId:n,deviceNames:i,onSelect:a}){return t?r(`div`,{className:`flex items-center gap-2 p-4 text-xs text-foreground-subtle`,children:[d(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?d(`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.`}):d(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=$n[Qn(e)],o=t.icon;return d(`li`,{children:r(`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:[d(o,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),r(`span`,{className:`min-w-0 flex-1`,children:[r(`span`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),d(b,{variant:t.variant,children:t.label})]}),r(`span`,{className:`block text-[11px] text-foreground-subtle truncate`,children:[i.get(e.deviceId)??`Camera ${String(e.deviceId)}`,` ·`,` `,er(e.lastSeen)]}),r(`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)})})}n();var nr=`person`;function rr(){let[t,n]=u(null),[i,o]=u(null),[c,l]=u([]),[p,h]=u(-1),[g,_]=u(new Map),[v,y]=u(null),x=m({projection:`slim`,isCamera:!0}),C=a(()=>{let e=new Map;for(let t of x.data??[])e.set(t.id,t.name);return e},[x.data]),w=ne({}),T=k({trackId:t?.trackId??``},{enabled:t!==null}),D=ee({trackId:t?.trackId??``},{enabled:t!==null}),O=M({frameId:i??``},{enabled:i!==null}),N=B(),P=j(),F=H(),I=E(),te=A(),L=V();f(()=>{if(i===null){l([]);return}l((D.data??[]).filter(e=>e.mediaKey===i).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}}))),h(-1)},[i,D.data]),f(()=>{let e=T.data?.copies??[];i===null&&e.length>0&&o(e[0].frameId)},[T.data,i]);let R=e(e=>{n(e),o(null),l([]),_(new Map),y(null)},[]),z=e(async e=>{if(t===null)return;let n=await N.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,mediaKeys:[e]});if(n.refused.length>0){let e=new Map(g);for(let t of n.refused)e.set(t.sourceMediaKey,t.reason);_(e)}n.copied.length>0&&o(n.copied[0].frameId),await T.refetch(),await w.refetch()},[t,N,g,T,w]),re=e(async e=>{t!==null&&(await P.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:e}),i===e&&o(null),await T.refetch(),await D.refetch(),await w.refetch())},[t,P,i,T,D,w]),U=e(async e=>{if(t===null||i===null)return;y(null);let n=await F.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,subject:e===`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)}`:``))},[t,i,F]),ie=e(e=>{l(t=>[...t,{bbox:e,macroClass:nr,kind:`subject`,source:`operator`}]),h(c.length)},[c.length]),W=e((e,t)=>{l(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),ae=e(e=>{l(t=>t.filter((t,n)=>n!==e)),h(-1)},[]),oe=e(async()=>{t===null||i===null||(await I.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,annotations:c.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 D.refetch(),await w.refetch(),y(`Annotations saved.`))},[t,i,c,I,D,w]),se=e(async()=>{if(t===null)return;let e=await te.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});y(e.changed?`Track completed — it is now trained, and its own media is evictable again.`:e.reason===`no-frames-copied`?`Refused: no frame was ever copied into the dataset. Completing would let retention delete material nothing was extracted from.`:`Refused: ${e.reason??`unknown`}`),await w.refetch(),e.changed&&n(null)},[t,te,w]),ce=e(async()=>{if(t===null)return;let e=await L.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});y(e.changed?`Track returned to staging. Its copies and annotations were left alone.`:`Refused: ${e.reason??`unknown`}`),await w.refetch()},[t,L,w]),G=O.data,le=Vn(c)&&i!==null;return r(Fe,{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:t===null?null:r(`div`,{className:`flex items-center gap-2`,children:[r(S,{variant:`secondary`,size:`sm`,onClick:()=>void ce(),children:[d(we,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Back to staging`})]}),r(S,{size:`sm`,onClick:()=>void se(),children:[d(Ge,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Complete track`})]})]}),children:[v!==null&&d(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:v}),r(`div`,{className:`grid grid-cols-1 lg:grid-cols-[minmax(0,260px)_minmax(0,1fr)] gap-4`,children:[r(`aside`,{className:`rounded-md border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Staging`}),d(b,{children:w.data?.length??0})]}),d(tr,{tracks:w.data??[],isLoading:w.isLoading,selectedTrackId:t?.trackId??null,deviceNames:C,onSelect:R})]}),d(`section`,{className:`space-y-3 min-w-0`,children:t===null?d(`p`,{className:`text-xs text-foreground-subtle`,children:`Pick a track from the staging list to start annotating it.`}):r(s,{children:[d(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:d(Zn,{candidates:T.data?.candidates??[],copies:T.data?.copies??[],activeFrameId:i,refusals:g,isSelecting:N.isPending,onSelectCandidate:e=>void z(e),onOpenCopy:o,onRemoveCopy:e=>void re(e)})}),i!==null&&r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[d(`div`,{className:`rounded-md border border-border overflow-hidden`,children:G===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[d(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):d(Yn,{imageSrc:`data:image/jpeg;base64,${G.base64}`,imageWidth:G.width,imageHeight:G.height,boxes:c,selectedIndex:p,onSelect:h,onDraw:ie})}),r(`div`,{className:`rounded-md border border-border bg-surface flex flex-col min-h-0`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center gap-2`,children:[d(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),r(S,{variant:`secondary`,size:`sm`,disabled:F.isPending,onClick:()=>void U(`objects`),children:[d(je,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Propose`})]}),r(S,{variant:`secondary`,size:`sm`,disabled:F.isPending,onClick:()=>void U(`package`),children:[d(je,{className:`h-3 w-3`}),d(`span`,{className:`ml-1`,children:`Packages`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:d(Bn,{annotations:c,selectedIndex:p,onSelect:h,onChange:W,onDelete:ae})}),r(`div`,{className:`px-3 py-2 border-t border-border flex items-center justify-between`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:[c.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),d(S,{size:`sm`,disabled:!le||I.isPending,onClick:()=>void oe(),children:`Save frame`})]})]})]})]})})]})]})}function ir(){return d(`div`,{className:`flex flex-col p-4`,children:d(ze,{tabs:[{id:`feed`,label:`Feed`,icon:Te,content:d(In,{})},{id:`retrain`,label:`Retrain`,icon:Ge,content:d(rr,{})},{id:`debug`,label:`Debug`,icon:Ve,content:d(vt,{})}]})})}export{ir as EventsPage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-CBKaIBph.js";import{Ai as u,Bi as d,Di as f,Dn as p,En as m,Fi as h,Ft as g,Gi as _,Hi as v,Ii as y,It as b,Ki as x,Li as S,Lt as C,Mi as w,Ni as ee,Oi as te,Pi as T,Ri as E,Vi as D,Yt as O,_s as k,et as A,ji as ne,ki as re,nt as j,qi as M,zi as N}from"./src-BLHY9yig.js";import{at as P,et as F}from"./src-0pbBUmTo.js";import{t as I}from"./boxes-EqdcdFpg.js";import{t as L}from"./copy-BPgY4Eey.js";import{t as ie}from"./play-CqrjGyv7.js";import{t as ae}from"./refresh-cw-CllqntzE.js";import{t as oe}from"./rotate-ccw-CdTrnBTI.js";import{t as R}from"./server-DbU7BgZv.js";import{t as se}from"./shield-BojVNBVL.js";import{t as ce}from"./square-DynbJcCj.js";import{t as z}from"./wifi-MOwlhPpo.js";import{C as B,E as V,K as H,S as le,U as ue,i as de,j as U,l as fe,o as W,x as pe,y as G,z as me}from"./index-LPwis6Rq.js";import{t as he}from"./AdminPage-CCD07UMs.js";import{t as ge}from"./AdminTabs-FswV6m19.js";import{t as _e}from"./NodeAddonsSettingsPanel-B3-jgI6Y.js";import{t as K}from"./AddonCollectionPage-DfZQjIPJ.js";import{t as q}from"./addon-display-names-DvSEQty-.js";var ve=H(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),ye=H(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),J=H(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);t();var Y=5e3,be={connected:!1,endpoint:null};function xe(){let e=a(),t=p({capName:`network-access`},{refetchInterval:Y}),n=m(void 0,{refetchInterval:Y}),i=r(()=>q(n.data??[]),[n.data]),c=r(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,i]),[l,u]=o(null),[d,f]=o({}),h=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),u(null),f(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},g=(e,t)=>{u(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);f(e=>({...e,[n]:r}))},_=x({onSuccess:h,onError:g}),v=M({onSuccess:h,onError:g});return s(K,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:V,itemIcon:V,capability:`network-access`,installButtonLabel:`Add tunnel`,items:c,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>s(Se,{addonId:e.addonId}),itemError:e=>d[e.addonId]??null,renderPrimaryAction:e=>s(Ce,{addonId:e.addonId,busyId:l,onStart:e=>{u(e),_.mutate({addonId:e})},onStop:e=>{u(e),v.mutate({addonId:e})}})})}function X(e){let{data:t}=_({addonId:e},{refetchInterval:Y,retry:!1}),n=t?P.safeParse(t):null;return n?.success?n.data:be}function Se({addonId:e}){let t=X(e);return n(i,{children:[s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&n(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[s(U,{className:`h-3 w-3`}),t.endpoint.url]})]})}function Ce({addonId:e,busyId:t,onStart:r,onStop:i}){let a=X(e),o=t===e;return a.connected?n(C,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?s(B,{className:`h-3 w-3 animate-spin`}):s(ce,{className:`h-3 w-3`}),`Stop`]}):n(C,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>r(e),children:[o?s(B,{className:`h-3 w-3 animate-spin`}):s(ie,{className:`h-3 w-3`}),`Start`]})}t();var Z=3e4;function we(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Te(){let e=p({capName:`turn-provider`},{refetchInterval:Z}),t=m(void 0,{refetchInterval:Z}),i=k(),a=i.data??[],o=r(()=>q(t.data??[]),[t.data]);return s(K,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:G,itemIcon:G,capability:`turn-provider`,installButtonLabel:`Add provider`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:o.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,o]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>s(Ee,{addonId:e.addonId,enabled:e.isActive}),trailing:n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),s(C,{size:`sm`,variant:`secondary`,onClick:()=>i.refetch(),disabled:i.isFetching,children:`Refresh`})]}),s(`div`,{className:`p-4`,children:a.length===0?s(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):s(`div`,{className:`flex flex-col gap-3`,children:a.map((e,t)=>{let r=Array.isArray(e.urls)?e.urls:[e.urls];return n(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&n(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,s(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,s(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(e=>s(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function Ee({addonId:e,enabled:t}){let i=k({addonId:e},{enabled:t,retry:!1}),a=r(()=>we(i.data??[]),[i.data]);return!t||a.length===0?null:n(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[n(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,a.length,`)`]}),s(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>s(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}t();var De={lan:G,wifi:z,docker:I,vpn:le,loopback:R,other:R},Oe={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},ke=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Ae(e){let{interfaces:t,disabled:i,hideLoopback:a,ipv4Only:o,emptyMessage:c}=e,l=r(()=>t.filter(e=>!(a&&e.kind===`loopback`||o&&e.family!==`IPv4`)),[t,a,o]),u=r(()=>{let e=new Map;for(let t of l){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return ke.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[l]),d=t=>e.mode===`single`?e.value===t:e.value.includes(t),f=t=>{if(i||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let n=new Set(e.value);n.has(t.address)?n.delete(t.address):n.add(t.address),e.onChange([...n])};return l.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic`,children:c??`No addresses available.`}):s(`div`,{className:`flex flex-col gap-3`,children:u.map(({kind:t,items:r})=>n(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[s(De[t]??R,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Oe[t]??t}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=d(t.address),a=t.kind===`loopback`,o=!t.plausible&&!a;return n(`li`,{className:`flex items-center gap-3 px-3 py-2 ${a?`opacity-60 cursor-not-allowed`:i?`opacity-60`:o?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>f(t),children:[s(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&s(me,{className:`h-3 w-3`})}),n(`div`,{className:`flex-1 min-w-0 ${o?`text-foreground-subtle`:``}`,children:[n(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`span`,{className:`font-mono text-xs font-semibold ${o?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),s(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),a&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),o&&n(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[s(W,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),n(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}t();var je={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function Me(){let e=a(),t=l(),i=ne(void 0,{refetchInterval:3e4}),u=f(void 0),d=h({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),p=ee({onSuccess:t=>{b(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),m=r(()=>i.data?.interfaces??[],[i.data]),_=te({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[v,b]=o([]),[x,S]=o(!1);c(()=>{!x&&u.data&&(b(u.data.addresses),S(!0))},[u.data,x]);let w=u.data?.addresses??[],T=r(()=>{if(v.length!==w.length)return!0;let e=[...v].toSorted(),t=[...w].toSorted();return e.some((e,n)=>e!==t[n])},[v,w]),E=()=>{d.mutate({addresses:[...v]})},D=()=>{b(w)},O=()=>{b([])},k=()=>{i.refetch(),_.refetch(),u.refetch()},A=async()=>{try{let e=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},j=re(),M=y({onSuccess:()=>void j.refetch()}),N=_.data?.endpoints??[],P=j.data?.baseUrl??null,F=j.data?.resolved??null;return n(he,{children:[n(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),n(`div`,{className:`flex items-center gap-2 shrink-0`,children:[n(C,{size:`sm`,variant:`secondary`,onClick:k,disabled:i.isLoading,children:[s(ae,{className:`h-3 w-3 ${i.isLoading?`animate-spin`:``}`}),`Refresh`]}),s(C,{size:`sm`,variant:`secondary`,onClick:A,children:`Probe race`})]})]}),n(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:v.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${v.length} pinned`})]}),n(`div`,{className:`flex items-center gap-1`,children:[n(C,{size:`sm`,variant:`secondary`,onClick:()=>p.mutate(void 0),disabled:p.isPending||d.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[s(fe,{className:`h-3 w-3`}),p.isPending?`Detecting…`:`Best match`]}),n(C,{size:`sm`,variant:`secondary`,onClick:O,disabled:v.length===0||d.isPending,children:[s(oe,{className:`h-3 w-3`}),`Clear`]}),T&&s(C,{size:`sm`,variant:`secondary`,onClick:D,disabled:d.isPending,children:`Discard`}),n(C,{size:`sm`,variant:`primary`,onClick:E,disabled:!T||d.isPending,children:[s(ye,{className:`h-3 w-3`}),d.isPending?`Saving…`:`Save`]})]})]}),s(`div`,{className:`p-4`,children:s(Ae,{mode:`multiple`,interfaces:m,value:v,onChange:b,disabled:d.isPending,emptyMessage:i.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border`,children:[s(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`}),n(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-2 text-xs`,children:[s(`span`,{className:`text-foreground-subtle`,children:`Notification links use:`}),s(`span`,{className:`font-mono text-foreground`,children:P??`${F??`nothing reachable`} (auto)`}),P!==null&&s(`button`,{type:`button`,disabled:M.isPending,onClick:()=>M.mutate({baseUrl:null}),className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:`reset to auto`})]}),P===null&&F===null&&s(`p`,{className:`mt-1 text-[11px] text-amber-600 dark:text-amber-400`,children:`No public address is reachable, so notification media ships as bytes only — a backend that can only take links (WhatsApp, gotify) receives none.`})]}),s(`div`,{className:`p-4`,children:N.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic`,children:_.isLoading?`Loading…`:`No endpoints available.`}):s(`ul`,{className:`space-y-1 text-xs`,children:N.map(e=>n(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[s(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${je[e.kind]??je.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&s(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&n(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[s(W,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),s(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),n(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]}),e.kind===`loopback`?null:P===e.baseUrl?n(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/15 px-2 py-0.5 text-[10px] font-medium text-primary`,children:[s(ue,{className:`h-2.5 w-2.5`}),` notifications`]}):s(`button`,{type:`button`,disabled:M.isPending,onClick:()=>M.mutate({baseUrl:e.baseUrl}),className:`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:`use for notifications`})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}t();var Ne={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Q=5e3,Pe=3e4,Fe={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Ie(){let e=p({capName:`mesh-network`},{refetchInterval:Q}),t=m(void 0,{refetchInterval:Q}),n=r(()=>q(t.data??[]),[t.data]);return s(K,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:I,itemIcon:G,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>s(Le,{addonId:e.addonId}),renderPrimaryAction:e=>s(Re,{addonId:e.addonId}),renderExpandedPanel:e=>s(ze,{addonId:e.addonId})})}function $(e){let{data:t,isLoading:n}=E({addonId:e},{refetchInterval:Q,retry:!1}),r=t?F.safeParse(t):null;return{status:r?.success?r.data:Fe,isLoading:n}}function Le({addonId:e}){let{status:t}=$(e);return n(i,{children:[s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&n(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function Re({addonId:t}){let r=a(),[c,u]=o(!1),[d,f]=o(null),p=l(),{status:m}=$(t),h=e(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),g=v(),_=N({onSuccess:h}),y=D({onSuccess:h}),b=e(async()=>{u(!0);let e={cancelled:!1};f(e);try{let n=await g.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await Ke(2e3),!e.cancelled);){let e=await p.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?F.safeParse(e):null;if(n?.success&&n.data.joined){h();break}if(Date.now()-r>6e5)break}}finally{u(!1),f(null)}},[t,h,g,p]),x=e(()=>{d&&(d.cancelled=!0),u(!1),f(null)},[d]);return s(i,{children:m.joined?n(i,{children:[n(C,{size:`sm`,variant:`secondary`,disabled:_.isPending,onClick:()=>_.mutate({addonId:t}),children:[_.isPending?s(B,{className:`h-3 w-3 animate-spin`}):s(pe,{className:`h-3 w-3`}),`Disconnect`]}),n(C,{size:`sm`,variant:`ghost`,disabled:y.isPending,onClick:()=>y.mutate({addonId:t}),children:[y.isPending?s(B,{className:`h-3 w-3 animate-spin`}):s(J,{className:`h-3 w-3`}),`Log out`]})]}):c?n(C,{size:`sm`,variant:`ghost`,onClick:x,children:[s(de,{className:`h-3 w-3 mr-1`}),` Cancel`]}):n(i,{children:[n(C,{size:`sm`,variant:`primary`,onClick:()=>void b(),children:[s(ve,{className:`h-3 w-3`}),`Connect`]}),n(C,{size:`sm`,variant:`ghost`,disabled:y.isPending,onClick:()=>y.mutate({addonId:t}),children:[y.isPending?s(B,{className:`h-3 w-3 animate-spin`}):s(J,{className:`h-3 w-3`}),`Log out`]})]})})}function ze({addonId:e}){let{status:t}=$(e),r=d({addonId:e},{refetchInterval:Pe,retry:!1});return n(`div`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`p-4 space-y-4`,children:[t.error&&s(O,{message:t.error}),s(Be,{status:t}),t.endpoints.length>0&&n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>n(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[n(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Ne[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?s(V,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),n(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[s(U,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),s(`div`,{className:`border-t border-border`,children:s(He,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function Be({status:e}){return s(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Ve(e.keyExpiry):`—`}].map(e=>n(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[s(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),s(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ve(e){let t=e-Date.now();if(t<0)return`Expired ${Ge(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function He({peers:t,loading:i}){let a=r(()=>t.map(e=>({...e,_id:e.id})),[t]),o=e(e=>{e&&navigator.clipboard?.writeText(e)},[]),c=r(()=>[{key:`hostname`,header:`Hostname`,render:e=>n(`div`,{className:`flex flex-col`,children:[n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&s(b,{variant:`info`,children:`self`}),e.exitNodeOption&&s(b,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&s(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),s(`button`,{onClick:()=>o(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:s(L,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs`,children:t}),s(`button`,{onClick:()=>o(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:s(L,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>n(`div`,{className:`flex items-center gap-1.5`,children:[s(b,{variant:Ue(e.connection),children:e.connection}),e.relay&&s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?s(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>n(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,We(e.txBytes),` · ↓ `,We(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>s(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Ge(e.lastSeenMs):`—`})}],[o]);return i&&t.length===0?n(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[s(B,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):t.length===0?s(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):s(`div`,{className:`p-4`,children:s(A,{columns:c,rows:a,rowKey:e=>e._id,minWidthPx:820})})}function Ue(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function We(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function Ge(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function Ke(e){return new Promise(t=>setTimeout(t,e))}t();function qe(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Je(){let e=a(),t=u(void 0,{refetchInterval:15e3}),r=w({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),i=T({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),c=S({onSuccess:()=>{f(!1),m(``),_(``),y(``),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=t.data,[d,f]=o(!1),[p,m]=o(``),[h,_]=o(``),[v,y]=o(``),b=()=>{if(!l?.caCertPem)return;let e=new Blob([l.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},x=l?.mode===`uploaded`?`Uploaded`:l?.mode===`generated`?`Generated local CA`:`TLS disabled`;return n(`div`,{className:`flex flex-col gap-4`,children:[s(_e,{nodeId:`hub`,addonIds:[`local-network`],level:`global`,title:`LAN HTTP`,description:`Native apps on this Wi-Fi use http:// and skip the private certificate. The tunnel and this admin UI stay on HTTPS.`}),n(g,{className:`p-4 space-y-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(se,{className:`h-4 w-4 text-foreground-subtle`}),s(`h3`,{className:`text-sm font-semibold`,children:`Certificate`})]}),t.isError&&s(`p`,{className:`text-xs text-danger`,children:`Could not read TLS status.`}),l?.reissueError&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:l.reissueError}),l?.restartRequired&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Restart the hub to apply the new certificate.`}),n(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Mode`}),s(`dd`,{className:`font-medium`,children:x})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Valid to`}),s(`dd`,{className:`font-mono`,children:l?.validTo?new Date(l.validTo).toLocaleString():`—`})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Leaf SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.leafFingerprintSha256??void 0,children:qe(l?.leafFingerprintSha256??null)})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`CA SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.caFingerprintSha256??void 0,children:qe(l?.caFingerprintSha256??null)})]})]}),l&&l.sans.length>0&&s(`div`,{className:`flex flex-wrap gap-1`,children:l.sans.map(e=>s(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),n(`div`,{className:`flex flex-wrap gap-2`,children:[s(j,{label:`Regenerate`,title:`Issue a new leaf?`,description:`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`,confirmLabel:`Regenerate`,disabled:l?.mode===`uploaded`||r.isPending,action:()=>r.mutateAsync({})}),s(C,{size:`sm`,variant:`outline`,onClick:()=>f(e=>!e),children:`Upload`}),l?.caCertPem&&s(C,{size:`sm`,variant:`outline`,onClick:b,children:`Download CA`}),l?.mode===`uploaded`&&s(j,{label:`Revert to generated`,title:`Drop the uploaded certificate?`,description:`Deletes the uploaded pair and returns to the generated local CA.`,confirmLabel:`Revert`,confirmVariant:`danger`,disabled:i.isPending,action:()=>i.mutateAsync({})})]}),d&&n(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Certificate PEM`,s(`textarea`,{value:p,onChange:e=>m(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Private key PEM`,s(`textarea`,{value:h,onChange:e=>_(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`CA PEM (optional)`,s(`textarea`,{value:v,onChange:e=>y(e.target.value),rows:4,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),s(C,{size:`sm`,disabled:!p.trim()||!h.trim()||c.isPending,onClick:()=>c.mutate({certPem:p,keyPem:h,...v.trim()?{caPem:v}:{}}),children:`Save certificate`}),c.isError&&s(`p`,{className:`text-xs text-danger`,children:c.error instanceof Error?c.error.message:`Upload failed`})]})]})]})}function Ye(){return s(`div`,{className:`flex flex-col p-4`,children:s(ge,{defaultTab:`addresses`,tabs:[{id:`local-access`,label:`Local access`,icon:z,content:s(Je,{})},{id:`addresses`,label:`Network Addresses`,icon:R,content:s(Me,{})},{id:`remote-access`,label:`Remote Access`,icon:V,content:s(xe,{})},{id:`mesh`,label:`Mesh Networks`,icon:I,content:s(Ie,{})},{id:`turn`,label:`TURN Servers`,icon:G,content:s(Te,{})}]})})}export{Ye as NetworkPage};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,T as i,W as a,b as o,i as s,o as c,p as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as p}from"./player-overlays-CBKaIBph.js";import{$ as m,$a as h,Aa as g,B as _,Ba as v,Bt as y,Da as b,Ea as x,Fa as S,Fs as C,Ga as w,Ht as T,Ia as E,Is as D,It as O,J as k,Ja as A,Jt as ee,Ka as j,La as M,Ls as N,Ma as P,Na as F,Oa as I,Pa as L,Ps as R,Qa as z,Ra as te,Rs as ne,Rt as re,Ua as B,Vt as ie,Xa as ae,Ya as oe,b as se,co as ce,d as le,do as ue,eo as de,gn as fe,h as pe,hn as me,i as he,ja as ge,ka as _e,ln as ve,lo as ye,no as be,po as xe,ro as Se,ta as V,to as Ce,u as we,uo as Te,vn as Ee,zt as De}from"./src-BLHY9yig.js";import{n as Oe}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{Lt as ke,Rt as Ae,bt as je,f as Me,h as Ne,p as Pe}from"./src-0pbBUmTo.js";import{a as Fe,d as Ie,i as Le,l as Re,n as H,o as ze,r as Be,t as Ve,u as He}from"./NodeInferenceDevices-vixWXUkV.js";import{t as Ue}from"./download-Dq2bfdRX.js";import{t as We}from"./hard-drive-COdkuHqf.js";import{n as Ge,t as Ke}from"./video-GQHe9bLG.js";import{t as qe}from"./pencil-CfoKCBNv.js";import{t as Je}from"./plus-DHRgxEWi.js";import{t as Ye}from"./radio-BOUTlTbE.js";import{t as Xe}from"./refresh-cw-CllqntzE.js";import{t as Ze}from"./search-Dx_k5G37.js";import{t as Qe}from"./server-DbU7BgZv.js";import{t as $e}from"./square-check-big-Ch-X3CcM.js";import{t as et}from"./square-DynbJcCj.js";import{t as tt}from"./zap-BiojyRpM.js";import{C as U,D as nt,E as rt,F as it,I as at,K as ot,N as W,O as st,P as ct,R as lt,X as ut,a as dt,i as ft,o as pt,s as mt,z as ht}from"./index-LPwis6Rq.js";import{t as gt}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-BDOhX3vo.js";import{r as _t,t as vt}from"./build-cluster-graph-C0MeCzJZ.js";import{n as yt}from"./format-size-CO9d3C3-.js";import{t as bt}from"./NodeAddonsSettingsPanel-B3-jgI6Y.js";var xt=ot(`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`}]]),St=ot(`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`}]]),Ct=ot(`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`}]]);n();function wt(e){return e}function Tt(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function Et(e,t){return typeof e==`boolean`?e:wt(t)}function Dt(e,t){return{pipeline:Et(Tt(e,`detect`),t),audio:Et(Tt(e,`audio`),t),ingest:Et(Tt(e,`ingest`),t)}}function Ot(e,t,n){let r=e?.find(e=>e.nodeId===t);return Dt(r?.settings,n)}function kt({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:i}=V(void 0),{data:a}=w(void 0),{data:s}=A(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=i??[],u=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return r(`div`,{className:`flex flex-col h-full`,children:[r(`button`,{type:`button`,onClick:()=>t(ni),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:[d(rt,{className:`h-4 w-4 flex-shrink-0`}),r(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(n=>{let i=e===n.id,a=c.get(n.id)??0,l=n.isHub?Qe:W,u=Ot(s,n.id,n.isHub),f=n.isOnline?null:_(_t(n.lastSeen));return r(`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 ${i?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[d(l,{className:`h-4 w-4 flex-shrink-0`}),r(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),r(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[r(`span`,{children:[n.cpuCores,` cores`]}),d(`span`,{children:`•`}),r(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&r(o,{children:[d(`span`,{children:`•`}),r(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[d(Ke,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&r(o,{children:[d(`span`,{children:`•`}),r(`span`,{className:`text-destructive`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),r(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[d(O,{variant:u.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),d(O,{variant:u.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),r(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[r(`span`,{children:[u,` online`]}),f>0&&r(`span`,{className:`text-destructive`,children:[f,` offline`]})]})]})}function At({nodeId:e,refreshToken:t}){let{data:n}=V(void 0),i=n?.find(t=>t.id===e),a=C(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return i?r(`div`,{className:`px-6 py-4 border-b border-border`,children:[r(`div`,{className:`flex items-center gap-2 mb-1`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:i.name}),i.isOnline?d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),i.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),r(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[d(`span`,{children:i.cpuModel??`CPU`}),d(`span`,{children:`•`}),r(`span`,{children:[i.cpuCores,` cores`]}),d(`span`,{children:`•`}),r(`span`,{children:[Math.round(i.memoryMB/1024),` GB`]}),a&&r(o,{children:[d(`span`,{children:`•`}),r(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),d(`span`,{children:`•`}),r(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),d(`span`,{children:`•`}),r(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&r(o,{children:[d(`span`,{children:`•`}),d(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):d(`div`,{className:`px-6 py-4 border-b border-border`,children:r(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function jt({refreshToken:e,nodeId:t}){let[n,i]=u(new Map),{nodes:o}=R();N(`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:s}=te(void 0),c=a(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),l=a(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),f=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=a(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of l.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:o.length,onlineAgents:o.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[l,o]);if(t){let e=l.get(t);return r(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),r(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[d(G,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),d(G,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),d(G,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),d(G,{label:`Queue`,value:e?String(e.queueDepth):`—`}),d(G,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...l.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return r(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),r(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[d(G,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),d(G,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),d(G,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),d(G,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),d(G,{label:`Queue depth`,value:String(p.queueDepth)})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:r(`table`,{className:`w-full text-xs min-w-[480px]`,children:[d(`thead`,{className:`bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),d(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),d(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),d(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),d(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),d(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),r(`tbody`,{children:[m.map(([e,t])=>r(`tr`,{className:`border-t border-border`,children:[d(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&d(`tr`,{children:d(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function G({label:e,value:t}){return r(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),d(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}n();var Mt={active:!1,pinned:!1,nodeId:null,reason:``},Nt=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],Pt=3e5,Ft={pipeline:W,decoder:st,audio:Ge},It={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function Lt({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let s=c(),[l,p]=u(null),[m,h]=u(null),[g,_]=u(new Map);he([`pipelineOrchestrator`,`getPipelineAssignments`],Nt),he([`pipelineOrchestrator`,`getAudioAssignments`],Nt),he([`pipelineOrchestrator`,`getCameraStatuses`],Nt);let{data:y}=w(void 0),{data:b}=M(void 0),{data:x}=v({},{enabled:e===`agent`}),{nodes:S}=R(),{data:C}=Re();N(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&_(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),f(()=>{if(g.size===0)return;let e=setInterval(()=>{_(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)},[g.size]);let T=a(()=>{let e=new Map;for(let t of C??[])e.set(t.id,t.name);return e},[C]),E=a(()=>{if(e===`agent`){let e=[];for(let n of x??[]){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:T.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:T.get(e)??`Device ${e}`,pipeline:Mt,decoder:Mt,audio:Mt};return n.set(e,r),r};for(let i of y??[]){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 b??[]){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},[y,b,x,T,e,t]),D=a(()=>(S??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[S]),O=()=>{s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},k=L({onSuccess:O}),A=Te({onSuccess:O}),j=F({onSuccess:O}),P=ye({onSuccess:O}),I=(e,t,n)=>{t===`pipeline`?k.mutate({deviceId:e,agentNodeId:n}):j.mutate({deviceId:e,nodeId:n}),p(null)},z=(e,t)=>{t===`pipeline`?A.mutate({deviceId:e}):P.mutate({deviceId:e}),p(null)};return d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:r(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[d(`thead`,{className:`bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&d(`th`,{className:`w-10`}),d(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?r(o,{children:[d(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),d(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):r(o,{children:[d(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),d(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),d(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),d(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),r(`tbody`,{children:[E.map(t=>{let a=g.get(t.deviceId),s=m===t.deviceId;return r(i.Fragment,{children:[r(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&d(`td`,{className:`px-2 py-2 align-middle`,children:d(`button`,{type:`button`,onClick:()=>h(s?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":s?`Collapse broker details`:`Expand broker details`,children:d(s?lt:at,{className:`h-3.5 w-3.5`})})}),r(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[d(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),r(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?r(o,{children:[d(`td`,{className:`px-3 py-2 align-middle`,children:d(zt,{state:t.pipeline,onlineNodes:D,pending:k.isPending||A.isPending,onChange:e=>{e===`auto`?z(t.deviceId,`pipeline`):I(t.deviceId,`pipeline`,e)}})}),d(`td`,{className:`px-3 py-2 align-middle`,children:d(Vt,{state:t.pipeline,deviceId:t.deviceId})})]}):r(o,{children:[d(Ut,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:D,isMenuOpen:l?.deviceId===t.deviceId&&l.role===`pipeline`,onToggleMenu:()=>p(l?.deviceId===t.deviceId&&l.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>p(null),onMove:e=>I(t.deviceId,`pipeline`,e),onUnpin:()=>z(t.deviceId,`pipeline`)}),d(Ut,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:D,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),d(Ut,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:D,isMenuOpen:l?.deviceId===t.deviceId&&l.role===`audio`,onToggleMenu:()=>p(l?.deviceId===t.deviceId&&l.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>p(null),onMove:e=>I(t.deviceId,`audio`,e),onUnpin:()=>z(t.deviceId,`audio`)})]}),d(`td`,{className:`px-3 py-2 align-middle`,children:d(qt,{snap:a})})]}),s&&!n&&r(`tr`,{className:`bg-surface/50`,children:[d(`td`,{}),r(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&d(Rt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),d(ee,{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)}),E.length===0&&d(`tr`,{children:d(`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 Rt({deviceId:e,nodeId:t}){let n=c(),{data:i}=B({nodeId:t}),{data:a}=j({deviceId:e}),o=ce({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),s=i?.devices??[],l=a?.deviceKey??`auto`,u=l!==`auto`&&!s.some(e=>e.key===l);return r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[d(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),r(`select`,{value:l,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[d(`option`,{value:`auto`,children:`Auto (balanced)`}),u&&r(`option`,{value:l,children:[`Pin → `,l,` (not on this node)`]}),s.map(e=>r(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),o.isPending&&d(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function zt({state:e,onlineNodes:t,pending:n,onChange:i}){let a=e.pinned&&e.nodeId?e.nodeId:`auto`,o=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return r(`select`,{value:a,disabled:n,"aria-label":`Pipeline 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-xs text-foreground`,children:[d(`option`,{value:`auto`,children:`Auto`}),o.map(e=>r(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function Bt(e){let n=t(null);return e.nodeId!==null&&(n.current=e),n.current}function Vt({state:e,deviceId:t}){let n=Bt(e),i=e.active&&e.nodeId!==null;if(n===null||n.nodeId===null)return d(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`— · no session yet`});let a=n.pinned?`pinned · manual`:`auto · ${n.reason||`capacity`}`;return r(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[d(`span`,{className:`font-mono text-[11px] truncate ${i?`text-foreground`:`text-foreground-subtle`}`,title:n.pinned?n.nodeId:`${n.nodeId} — an unpinned camera is re-elected per on-motion session, so this can change between sessions`,children:n.nodeId}),d(`span`,{className:`truncate ${n.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:a,children:a}),d(`span`,{className:`truncate text-[10px] ${i?`text-emerald-400`:`text-foreground-subtle/70`}`,children:i?`● running here`:`○ idle · last session here`}),d(Ht,{deviceId:t,nodeId:n.nodeId})]})}function Ht({deviceId:e,nodeId:t}){let n=c(),{data:i}=j({deviceId:e},{refetchOnMount:`always`}),{data:a}=B({nodeId:t},{staleTime:Pt}),o=ce({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(i===void 0||a===void 0)return d(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let s=a.devices??[],l=s.filter(e=>e.enabled),u=i.deviceKey??`auto`,f=u!==`auto`&&!l.some(e=>e.key===u),p=s.find(e=>e.key===u);return r(`select`,{value:u,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.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:[d(`option`,{value:`auto`,children:`Auto (balanced)`}),f&&r(`option`,{value:u,children:[p?`${H(p).label} (${u})`:u,` (not enabled)`]}),l.map(e=>r(`option`,{value:e.key,children:[H(e).label,` · `,e.format]},e.key))]})}function Ut({role:e,state:t,mode:n,onlineNodes:i,readOnly:a=!1,isMenuOpen:o,onToggleMenu:s,onCloseMenu:c,onMove:l,onUnpin:u}){let f=Ft[e],p=i.filter(e=>e.id!==(t.nodeId??``)),m=!a&&(t.active||n===`cluster`)&&(p.length>0||t.pinned);return r(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[d(n===`agent`?Wt:Gt,{state:t,Icon:f}),d(`div`,{className:`ml-auto shrink-0`,children:m&&d(`button`,{type:`button`,onClick:s,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${It[e]} actions`,children:d(xt,{className:`h-3 w-3 text-foreground-subtle`})})})]}),o&&m&&d(Jt,{title:It[e],targets:p,pinned:t.pinned,onMove:l,onUnpin:u,onClose:c})]})}function Wt({state:e,Icon:t}){return r(`div`,{className:`flex items-center gap-1.5`,children:[d(e.active?$e:et,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),d(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&d(Ct,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Gt({state:e,Icon:t}){return!e.active||!e.nodeId?r(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[d(t,{className:`h-3 w-3`}),d(`span`,{className:`text-[10px] italic`,children:`—`})]}):r(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),r(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[d(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),d(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?r(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[d(Ct,{className:`h-2.5 w-2.5`}),` manual`]}):r(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Kt=`min-h-[3.25rem]`;function qt({snap:e}){if(!e)return d(`div`,{className:`flex items-center ${Kt}`,children:d(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:n,avgInferenceTimeMs:i,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=m(t);return r(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Kt}`,children:[r(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[d(pe,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),r(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[d(`span`,{className:`text-foreground`,children:n.toFixed(1)}),r(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),r(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[d(`span`,{className:`text-foreground`,children:i.toFixed(0)}),d(`span`,{children:` ms`}),a>0&&r(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),r(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,d(`span`,{className:`text-foreground`,children:s})]})]})}function Jt({title:e,targets:n,pinned:i,onMove:a,onUnpin:o,onClose:s}){let c=t(null);return f(()=>{let e=e=>{c.current?.contains(e.target)||s()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]),r(`div`,{ref:c,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[d(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),n.length>0&&d(`div`,{className:`py-1`,children:n.map(e=>r(`button`,{type:`button`,onClick:()=>a(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))}),i&&r(`button`,{type:`button`,onClick:o,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()]}),n.length===0&&!i&&d(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Yt({nodeId:e,refreshToken:t}){return r(`div`,{className:`space-y-6`,children:[d(jt,{refreshToken:t,nodeId:e}),r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),r(`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.`]})]}),d(Lt,{mode:`agent`,nodeId:e,compact:!0})]})}n();function Xt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Zt({nodeId:e,refreshToken:t}){let n=c(),i=ge({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:o}=P({nodeId:e}),s=C(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??o??null,l=s===null;he([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:u}=xe({nodeId:e}),{values:f}=D(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),p=a(()=>f.filter(e=>e.metrics.phase===`active`).length,[f]),m=t=>{let n=u??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||i.mutate({nodeId:e,engine:t,force:n.length>0})};return r(`div`,{className:`space-y-6`,children:[r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(s??[]).length,` engine(s) resident in RAM. `,(u??[]).length,` `,`camera(s) attached, `,p,` actively dispatching frames. Refreshes every 5s.`]})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:r(`table`,{className:`w-full text-xs min-w-[640px]`,children:[d(`thead`,{className:`bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),d(`th`,{className:`text-left px-3 py-2`,children:`Models`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),d(`th`,{className:`w-20`})]})}),r(`tbody`,{children:[l&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!l&&(s??[]).map(e=>{let t=e.kind===`warm-override`,n=e.kind===`device-pool`;return r(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:n?`bg-primary/[0.05]`:``}`,children:[d(`td`,{className:`px-3 py-2`,children:r(`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:[d(t?St:n?Ie:W,{className:`h-3 w-3`}),t?`warm`:n?`pool`:`runtime`]})}),d(`td`,{className:`px-3 py-2`,children:r(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[d(tt,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),d(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?d(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>d(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),d(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),d(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?d(`span`,{className:`text-foreground-subtle`,children:Xt(e.idleMs,e.idleTtlMs)}):d(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(u??[]).length}),d(`td`,{className:`px-3 py-2 text-right`,children:n?d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):r(`button`,{type:`button`,disabled:i.isPending,onClick:()=>m(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:[d(mt,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!l&&(s??[]).length===0&&d(`tr`,{children:d(`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.`})})]})]})}),r(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[d(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,d(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,d(`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.`]}),i.isError&&r(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,i.error instanceof Error?i.error.message:`unknown`]})]})}n();var Qt=new Set(je);function $t(e){return Qt.has(e)}function en(e,t,n){return`${e}/${t}/${n}`}function tn(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function nn(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 K(e){return e.format}function rn(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 an({addonId:e,model:t,format:n,isActive:i,progress:a,errorMsg:o,onDownload:s,onDelete:c}){let l=t.formats[n];return l?r(`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:[d(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${l.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),r(`div`,{className:`flex-1 min-w-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),a&&a.progress>=0&&a.progress<100&&r(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[d(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:d(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${a.progress}%`}})}),r(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(a.progress),`%`]})]})]}),d(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:yt(l.sizeMB)}),o&&r(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:o,children:[d(it,{className:`h-3 w-3 shrink-0`}),o]}),l.downloaded?r(`button`,{onClick:c,disabled:i,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:[i?d(U,{className:`h-3 w-3 animate-spin`}):d(mt,{className:`h-3 w-3`}),i?`Deleting...`:`Delete`]}):r(`button`,{onClick:s,disabled:i,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:[i?d(U,{className:`h-3 w-3 animate-spin`}):d(Ue,{className:`h-3 w-3`}),i?`Downloading...`:`Download`]})]}):null}function on({engines:e,activeEngine:t,viewEngine:n,onSelect:i}){let[a,o]=u(!1);return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>o(!a),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:[d(W,{className:`h-4 w-4 text-primary shrink-0`}),r(`div`,{className:`flex-1 min-w-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-sm font-medium text-foreground`,children:tn(n)}),K(n)===K(t)&&d(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:nn(n)})]}),d(lt,{className:`h-4 w-4 text-foreground-subtle transition-transform ${a?`rotate-180`:``}`})]}),a&&d(`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 a=K(e)===K(n),s=K(e)===K(t);return r(`button`,{type:`button`,onClick:()=>{i(e),o(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${a?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[d(W,{className:`h-4 w-4 shrink-0 ${a?`text-primary`:`text-foreground-subtle`}`}),r(`div`,{className:`flex-1`,children:[r(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-sm font-medium ${a?`text-primary`:`text-foreground`}`,children:tn(e)}),s&&d(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:nn(e)})]}),a&&d(ct,{className:`h-4 w-4 text-primary shrink-0`})]},K(e))})})]})}function sn({embedded:t=!1,nodeId:n}={}){let i=c(),a=n??`hub`,[s,l]=u(null),[f,p]=u(new Set),[m,h]=u(new Map),[_,v]=u(new Map),[y,S]=u(``),{data:C=[]}=I({nodeId:a}),w=C.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:E}=g({nodeId:a}),D=E,{data:O,isLoading:k}=_e({nodeId:a}),A=b(),ee=x();N(`model.download.progress`,e=>{let t=e.data,n=typeof t.modelId==`string`?t.modelId:void 0,r=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;n===void 0||r===void 0||(h(e=>{let t=new Map(e);return r===100||r===-1?t.delete(n):t.set(n,{modelId:n,progress:r,totalMB:a}),t}),r===100&&i.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let j=D??{runtime:`node`,backend:`cpu`,format:`onnx`},M=w.find(e=>e.format===s)??j,P=M.format,F=e=>e.formats[P]?.downloaded===!0,L=O?.slots??[],R=L.map(e=>({...e,addons:e.addons.map(e=>({...e,models:T(e.models,P)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),z=rn(R,P),te=e(async(e,t,n)=>{if(!$t(n))return;let r=en(e,t,n);p(e=>new Set([...e,r])),v(e=>{let t=new Map(e);return t.delete(r),t});try{await A.mutateAsync({addonId:e,modelId:t,format:n,nodeId:a}),i.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){v(t=>new Map([...t,[r,e instanceof Error?e.message:`Download failed`]]))}finally{p(e=>{let t=new Set(e);return t.delete(r),t})}},[A,i,a]),ne=e(async(e,t,n)=>{if(!$t(n))return;let r=en(e,t,n);p(e=>new Set([...e,r])),v(e=>{let t=new Map(e);return t.delete(r),t});try{await ee.mutateAsync({addonId:e,modelId:t,format:n,nodeId:a}),i.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){v(t=>new Map([...t,[r,e instanceof Error?e.message:`Delete failed`]]))}finally{p(e=>{let t=new Set(e);return t.delete(r),t})}},[ee,i,a]),re=e(e=>{l(e.format)},[]),B=y.trim()?R.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(y.toLowerCase())||t.id.toLowerCase().includes(y.toLowerCase())||e.name.toLowerCase().includes(y.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):R,ie=r(o,{children:[k&&d(`div`,{className:`flex items-center justify-center py-16`,children:d(U,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!k&&L.length===0&&r(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[d(We,{className:`h-8 w-8 mb-3 opacity-30`}),d(`span`,{className:`text-sm`,children:`No pipeline steps available`}),d(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!k&&L.length>0&&r(o,{children:[d(on,{engines:w,activeEngine:j,viewEngine:M,onSelect:re}),r(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[r(`span`,{children:[d(`span`,{className:`font-semibold text-foreground tabular-nums`,children:z.total}),d(`span`,{className:`ml-1`,children:`compatible models`})]}),d(`span`,{className:`text-border`,children:`|`}),r(`span`,{children:[d(`span`,{className:`font-semibold text-success tabular-nums`,children:z.downloaded}),d(`span`,{className:`ml-1`,children:`downloaded`})]}),d(`span`,{className:`text-border`,children:`|`}),r(`span`,{className:`tabular-nums`,children:[yt(z.downloadedSizeMB),d(`span`,{className:`ml-1`,children:`on disk`})]})]}),z.total>5&&r(`div`,{className:`relative`,children:[d(Ze,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),d(`input`,{type:`text`,value:y,onChange:e=>S(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`})]}),B.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+T(t.models,P).filter(F).length,0);return r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[d(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),d(`div`,{className:`flex-1 h-px bg-border`}),r(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=en(e.id,t.id,P);return d(an,{addonId:e.id,model:t,format:P,isActive:f.has(n),progress:m.get(t.id),errorMsg:_.get(n),onDownload:()=>te(e.id,t.id,P),onDelete:()=>ne(e.id,t.id,P)},`${e.id}/${t.id}`)}))})]},e.id)}),B.length===0&&d(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:y.trim()?r(o,{children:[`No models matching “`,y,`”`]}):r(o,{children:[`No models available for `,tn(M),` format`]})})]})]});return t?d(`div`,{className:`space-y-4`,children:ie}):d(gt,{children:ie})}function cn({nodeId:e,refreshToken:t}){return d(sn,{embedded:!0,nodeId:e})}var ln=`pipeline-runner`,un=200;function dn({nodeId:e}){return r(`div`,{className:`flex flex-col gap-3`,children:[r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),r(`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.`]})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(k,{agentId:e,addonId:ln,limit:un,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}n(),n();function fn({nodeId:e,title:t}){let{data:n}=Re(),{data:i}=w(void 0),o=a(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),s=a(()=>{if(!e)return null;let t=new Set;for(let n of i??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,i]),[c,l]=u(new Map);N(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||l(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),f(()=>{if(c.size===0)return;let e=setInterval(()=>{l(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)},[c.size]);let p=a(()=>{let e=[];for(let t of c.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[c,s]);return p.length===0?r(`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`]}):r(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[r(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[d(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:p.length})]}),d(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,n=m(e.metrics.phase);return r(`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:[d(pe,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),d(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),d(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),d(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var pn=`pipeline-orchestrator`;function mn(e){return Me.find(t=>t.stepId===e)??null}function hn({title:e}){return d(`span`,{title:e??`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`,className:`ml-1 rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:`cluster-wide`})}function gn({step:e,engineFormat:t,runnableModelIds:n}){let i=c(),{data:a,isLoading:o}=fe({addonId:pn}),s=Ee({onSuccess:()=>{i.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),l=Ne(a??null)[e.stepId]??e.defaultModelId,u=n.length>0&&!n.includes(l);return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[r(`div`,{className:`flex items-center text-[11px] font-medium text-foreground`,children:[e.label,d(hn,{})]}),r(`p`,{className:`mt-1 text-[10px] leading-snug text-foreground-subtle`,children:[`Applies to every node. Changing it does not corrupt `,e.indexName,` — every vector carries the model that produced it and only matches its own — but it STRANDS it: the existing vectors stay readable and match nothing until a re-embed pass has run.`]})]}),o?d(U,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):d(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:l,disabled:s.isPending,onChange:t=>{t.target.value!==l&&s.mutate({addonId:pn,patch:{[Pe(e.stepId)]:t.target.value}})},children:e.options.map(t=>r(`option`,{value:t.id,children:[t.label,t.id===e.defaultModelId?` (default)`:``]},t.id))}),u&&r(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[10px] leading-snug text-amber-300`,children:[`This node's engine (`,t,`) ships no build of `,d(`b`,{children:l}),`. It will REFUSE this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`. Either pick a model with a `,t,` build, or accept that this node contributes nothing to that index.`]}),d(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Stored once, in Pipeline → Cluster → Settings → Enrichment models. This editor writes that same row — there is no per-node copy of this value. Step knobs for this encoder (minimum face size, …) live on that same settings page.`})]})}n();function q(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 _n(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 vn({nodeId:e,refreshToken:t}){let n=c(),[i,s]=u(null),[l,f]=u(null),[p,m]=u(``),[h,g]=u(null),_=B({nodeId:e},{refetchOnMount:`always`}),v=_e({nodeId:e},{refetchOnMount:`always`}),b=Ne(fe({addonId:`pipeline-orchestrator`}).data??null),x=_.data?.devices??[],S=be({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),C=a(()=>v.data?we(v.data):[],[v.data]),w=a(()=>x.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:H(t).label})),[x,e]),E=e=>x.find(t=>t.key===e)??null,D=a(()=>x.filter(e=>e.enabled),[x]),O=D.length>=2,k=(e,t)=>ie(q(v.data??null,e)?.models??[],t?.format),A=e=>{let t=E(e);return t?H(t).label:e},ee=(e,t)=>D.filter(n=>n.key!==t&&k(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,j=e=>{let t=q(v.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},M=(e,t)=>{let n=q(v.data??null,e);if(n)return De(n,t)},N=(e,t)=>{let n=j(e),r=n.kind===`gate`?n.effectiveOn:!1,i=q(v.data??null,e),a=t.deviceKey===void 0?null:E(t.deviceKey),o=ie(i?.models??[],a?.format),s=a?.steps?.[e];if(!o){if(!r)return{kind:`na`};let n=s?.jumpDeviceKey,i=n!==void 0&&D.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:ee(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:A(i)}}let c=mn(e);return c?{kind:`enabled`,modelId:b[e]??c.defaultModelId,clusterWide:!0}:{kind:`enabled`,modelId:(i?y({catalog:i,device:a,base:s?.modelId}):void 0)??`Auto`,...s?.jumpDeviceKey!==void 0&&D.some(e=>e.key===s.jumpDeviceKey)?{jumpTo:A(s.jumpDeviceKey)}:{}}},P=i&&v.data?q(v.data,i.addonId):null,F=i?E(i.deviceKey):null,I=F?.format??`coreml`,L=i?M(i.addonId,F):void 0,R=()=>{s(null),f(null),m(``)},z=(e,t)=>{if(t.deviceKey===void 0)return;let n=E(t.deviceKey)?.steps?.[e];s({addonId:e,deviceKey:t.deviceKey});let r=n?.settings??Fe(x.map(e=>({key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}})),t.deviceKey,e)??{};f({enabled:!0,...n?.modelId===void 0?{}:{modelId:n.modelId},settings:r}),m(n?.jumpDeviceKey??``)},te=()=>{if(!i)return;let t=_n(l),n=p!==``&&p!==i.deviceKey?p:void 0,r=t||n!==void 0?{...t,...n===void 0?{}:{jumpDeviceKey:n}}:null,a=x.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}}),o=r?.settings!==void 0&&Object.keys(r.settings).length>0?ze(a,i.deviceKey,i.addonId):a;S.mutate({agentNodeId:e,inferenceDevices:Le(o)},{onSuccess:R})};if(_.isLoading||v.isLoading)return d(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(x.length===0)return d(`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(!v.data)return d(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ne=i!==null&&P!==null&&F!==null;return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`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`,` `,d(`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.`]}),d(`div`,{className:ne?`md:pr-[360px]`:``,children:C.length>0?d(se,{tree:C,agents:w,gateFor:j,getCellState:N,onCellClick:z,selectedCell:i?{addonId:i.addonId,agentNodeId:e,deviceKey:i.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:h,onFallbackNodeChange:g,hideGate:!0}):d(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),d(le,{open:ne,onClose:R,title:P?.name??``,subtitle:i&&F?`${e} · ${H(F).label} · ${F.format}`:``,footer:r(o,{children:[d(`div`,{className:`flex-1`}),d(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:R,children:`Cancel`}),d(`button`,{type:`button`,disabled:!i||!l||S.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:te,children:S.isPending?`Saving…`:`Save`})]}),children:P&&i&&mn(i.addonId)?d(gn,{step:mn(i.addonId),engineFormat:I,runnableModelIds:T(P.models??[],I).map(e=>e.id)}):P&&i&&l?r(`div`,{className:`space-y-3`,children:[O&&r(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[d(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),r(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:p,onChange:e=>m(e.target.value),children:[d(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),D.filter(e=>e.key!==i.deviceKey).map(e=>r(`option`,{value:e.key,children:[H(e).label,` · `,e.format]},e.key))]}),d(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),d(re,{mode:`agent`,addon:P,agentDefault:l,agentNodeId:e,engineFormat:I,effectiveModelId:L,onChangeAgentConfig:f})]}):d(`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.`})})]})}n();var yn=[`pipeline-orchestrator`],bn=[`decoder`],xn=!1;function Sn({nodeId:e,refreshToken:t}){let n=ve(),[i,a]=u(null),[o,s]=u(null),c=(V(void 0).data??[]).find(t=>t.id===e),l=c?.name??e,f=c?.isOnline??!1,p=z({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)`)}}),m=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),p.mutate({agentNodeId:e}))};return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[o&&d(`span`,{className:`text-emerald-400`,children:o}),p.isError&&d(`span`,{className:`text-red-400`,children:p.error instanceof Error?p.error.message:`Reset failed`}),d(`button`,{type:`button`,onClick:()=>{m()},disabled:p.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:p.isPending?`Resetting…`:`Reset to default`})]}),d(fn,{nodeId:e}),d(bt,{nodeId:e,addonIds:yn,level:`global`,sectionIds:bn}),xn,xn,r(`div`,{children:[d(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),d(Ve,{nodeId:e,nodeName:l,isOnline:f})]}),r(`div`,{children:[d(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),d(vn,{nodeId:e,refreshToken:t})]})]})}var Cn=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],wn=`decoder-nodeav`;function Tn({nodeId:e,refreshToken:t}){let{data:n}=V(void 0),i=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??wn,a=[...Cn,i];return r(`div`,{className:`flex flex-col h-full`,children:[d(At,{nodeId:e,refreshToken:t}),d(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:d(bt,{nodeId:e,addonIds:a,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:d(Yt,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:d(Sn,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:d(Zt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:d(cn,{nodeId:e,refreshToken:t})},{id:`logs`,label:`Logs`,order:300,content:d(dn,{nodeId:e})}]})})]})}function En(e){let t=e.backend.toLowerCase(),n=e.device.toLowerCase();return e.key===`cpu`||n===`cpu`?`CPU`:t===`openvino`&&n===`npu`?`Intel NPU`:t===`openvino`&&(n===`gpu`||n===`igpu`)?`Intel iGPU`:t===`edgetpu`?`Coral Edge TPU`:t===`coreml`?`Apple ANE`:`${e.backend} ${e.device}`.trim()}var Dn={disabled:`switched off — not a dispatch target`,unavailable:`the node probe does not see it (unplugged or still provisioning)`,"cannot-host-camera-root":`its engine format has no object-detection root model`,"accelerator-preferred":`CPU fallback — it never competes while an accelerator is serving`};function On(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function kn(e,t){let n=e.filter(e=>e.exclusion===null).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.map(e=>{let r=t.get(e.key),i=r?.sessions??0,a=e.weight>0?e.weight:1;return{key:e.key,label:En(e),format:e.format,sessions:i,queueDepth:r?.queueDepth??0,weight:a,weightSharePct:e.exclusion===null?On(a,n):null,maxSessions:e.maxSessions,atCap:e.maxSessions!==null&&i>=e.maxSessions,available:e.available,enabled:e.enabled,exclusion:e.exclusion}}).toSorted((e,t)=>e.exclusion===null==(t.exclusion===null)?e.key.localeCompare(t.key):e.exclusion===null?-1:1)}function An(e){let t=new Map(e.loads.map(e=>[e.nodeId,e])),n=e.nodes.filter(e=>e.isOnline&&e.detectEnabled).reduce((e,t)=>e+(t.weight>0?t.weight:1),0),r=e.loads.reduce((e,t)=>e+t.load.attachedCameras,0);return e.nodes.map(i=>{let a=t.get(i.id),o=kn(e.devicesByNode[i.id]??[],new Map((a?.load.devices??[]).map(e=>[e.deviceKey,{sessions:e.attachedCameras,queueDepth:e.queueDepthTotal}]))),s=i.isOnline&&i.detectEnabled,c=i.weight>0?i.weight:1,l=a?.load.attachedCameras??null;return{nodeId:i.id,name:i.name,isOnline:i.isOnline,detectEnabled:i.detectEnabled,reported:a!==void 0,attachedCameras:l,activeCameras:a?.load.activeCameras??null,maxCameras:i.maxCameras,capacityPct:l!==null&&i.maxCameras!==null&&i.maxCameras>0?On(l,i.maxCameras):null,queueDepthTotal:a?.load.queueDepthTotal??null,avgInferenceTimeMs:a?.load.avgInferenceTimeMs??null,score:a?.score??null,weight:c,weightSharePct:s?On(c,n):null,cameraSharePct:l===null?null:On(l,r),decodeHwaccel:a?.decodeHwaccel??null,devices:o,eligibleDeviceCount:o.filter(e=>e.exclusion===null).length}})}var jn=`pipeline-orchestrator`,Mn=`recorder`,Nn=`recordingNodeId`,Pn=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],Fn=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function In(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function Ln(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function Rn(e,t,n){let r=In(e,t);return typeof r==`string`&&r.length>0?r:n}function zn(e,t,n){let r=In(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function Bn(e,t){let n=Ln(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function Vn(e,t){let n=Ln(e,t);return typeof n==`string`&&n.length>0?n:null}function Hn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function Un(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 Wn(e,t){switch(t){case`detect`:return e.pipeline}}function Gn(e){return e instanceof Error?e.message:`Failed to save`}function Kn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}n();var qn=2e4,Jn=3e5;function Yn(){let{nodes:e}=R(),t=p().trpcClient,n=E(void 0,{placeholderData:l,staleTime:qn,refetchInterval:qn,refetchOnWindowFocus:!0}),i=A(void 0,{staleTime:Jn}),o=a(()=>e.map(e=>e.id),[e]),c=s({queries:o.map(e=>({queryKey:Oe(ne.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>t.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Jn,refetchOnWindowFocus:!1,placeholderData:l}))}),u=a(()=>{let e={};return o.forEach((t,n)=>{let r=c[n]?.data;r&&(e[t]=r.devices)}),e},[o,c.map(e=>e.dataUpdatedAt).join(`|`)]),f=a(()=>{let e=new Map;for(let t of i.data??[])e.set(t.nodeId,t.settings);return e},[i.data]),m=a(()=>e.map(e=>{let t=f.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:Dt(t,e.isHub).pipeline,weight:Bn(t,`detectWeight`)??1,maxCameras:Bn(t,`maxCameras`)}}),[e,f]),h=n.data??[],g=a(()=>An({nodes:m,loads:h,devicesByNode:u}),[m,h,u]),_=g.reduce((e,t)=>e+(t.attachedCameras??0),0),v=g.reduce((e,t)=>e+(t.activeCameras??0),0),y=n.dataUpdatedAt>0?Date.now()-n.dataUpdatedAt:null;return r(`section`,{className:`rounded-md border border-border bg-surface px-3 py-2.5`,children:[r(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 mb-2`,children:[d(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Node load`}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[v,` running · `,_,` attached across `,g.length,` `,g.length===1?`node`:`nodes`]}),d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle/70 tabular-nums`,children:n.data===void 0?`reading…`:`reading ${y===null?`—`:`${Math.round(y/1e3)}s`} old · every ${qn/1e3}s`})]}),g.length===0?d(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):d(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:g.map(e=>d(Xn,{row:e},e.nodeId))})]})}function Xn({row:e}){let t=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return r(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[r(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&d(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`no detect`}),!e.reported&&e.isOnline&&r(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`,children:[d(pt,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&r(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[d(dt,{className:`h-2.5 w-2.5`}),` offline`]})]}),r(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[d(J,{label:`Running / attached`,value:t,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),d(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`detectWeight normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),d(J,{label:`Actual share`,value:e.cameraSharePct===null?`—`:`${e.cameraSharePct}%`,title:`Share of the cluster's attached cameras this node carries right now.`}),d(J,{label:`Score · queue`,value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`}),e.capacityPct!==null&&d(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&d(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&d(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),d(Zn,{row:e})]})}function Zn({row:e}){return e.devices.length===0?d(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):r(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[r(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[d(nt,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&d(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`,children:`none in play · runner default pool`})]}),d(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>d(Qn,{device:e},e.key))})]})}function Qn({device:e}){let t=e.exclusion;return r(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[d(W,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),d(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?r(o,{children:[r(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),r(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[`· `,e.sessions,` session`,e.sessions===1?``:`s`,e.maxSessions===null?``:`/${e.maxSessions}`]}),e.queueDepth>0&&r(`span`,{className:`shrink-0 tabular-nums text-amber-400`,children:[`· q`,e.queueDepth]}),e.atCap&&d(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):r(`span`,{className:`truncate text-foreground-subtle/80`,title:Dn[t],children:[`excluded — `,Dn[t]]})]})}function J({label:e,value:t,title:n}){return r(`div`,{className:`min-w-0`,title:n,children:[d(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function $n(){return r(`div`,{className:`space-y-6`,children:[d(fn,{title:`Cluster cameras`}),d(Yn,{}),r(`div`,{className:`min-w-0`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),d(`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.`})]}),d(Lt,{mode:`cluster`})]})}function er({capability:e,label:t,hint:n,nodeId:i,active:a,pending:o,layout:s,onToggle:c}){let l=a?`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`,u=s===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,f=a?ht:He;return r(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} capability for ${i}`,title:`${t} — ${n}`,disabled:o,onClick:()=>c(e,!a),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 ${l} ${u}`,children:[d(f,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),d(`span`,{children:t})]})}function tr({node:e,emphasis:t=!1}){let n=e.isHub?Qe:W;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[d(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),d(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[d(`span`,{className:`truncate`,children:e.name}),e.isHub&&d(O,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&d(O,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}n();function nr({nodeId:e,value:t,detectedHosts:n,status:i,errorMessage:a,onCommit:o}){let[s,c]=u(t??``);f(()=>{c(t??``)},[t]);let l=n[0],p=l===void 0?`auto-detect`:`auto: ${l}`,m=i===`pending`,h=s.trim(),g=h!==(t??``),_=g&&!m,v=()=>{_&&o(e,h.length>0?h:null)};return r(`div`,{className:`flex items-center gap-1.5`,children:[d(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:p,value:s,disabled:m,onChange:e=>c(e.target.value),onBlur:v,onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&c(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`}),r(`button`,{type:`button`,onClick:v,disabled:!_,"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:[m?d(U,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):d(ht,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!g&&!m&&i===`success`&&d(ht,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),i===`error`&&d(`span`,{title:a??`Failed to save reachable host`,children:d(it,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":a??`Failed to save reachable host`,role:`img`})})]})}function rr({label:e,children:t}){return r(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function ir({node:e,actions:t}){return r(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[d(tr,{node:e,emphasis:!0}),d(`div`,{className:`grid grid-cols-2 gap-2`,children:Fn.map(n=>d(er,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Wn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),d(`div`,{className:`space-y-3 border-t border-border pt-3`,children:d(rr,{label:`Reachable host`,children:d(nr,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function ar(){return r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[r(`span`,{className:`inline-flex items-center gap-1.5`,children:[d(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),r(`span`,{className:`inline-flex items-center gap-1.5`,children:[d(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),r(`span`,{className:`inline-flex items-center gap-1.5`,children:[d(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),r(`span`,{className:`inline-flex items-center gap-1.5`,children:[d(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function or({nodes:e,actions:t}){return d(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:r(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[d(`thead`,{children:r(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[d(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),Fn.map(e=>d(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),d(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),d(`tbody`,{children:e.map(e=>r(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[d(`td`,{className:`px-4 py-3 align-middle`,children:d(tr,{node:e})}),Fn.map(n=>d(`td`,{className:`px-3 py-3 text-center align-middle`,children:d(er,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Wn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),d(`td`,{className:`px-4 py-3 align-middle`,children:d(nr,{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 sr({role:e,value:t,options:n,pending:i,onChange:a}){return r(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[d(`span`,{className:`text-xs font-semibold text-foreground`,children:Hn(e)}),d(`select`,{value:t,disabled:i,onChange:t=>a(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=>d(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),d(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:Un(e)})]})}function cr({roleValues:e,options:t,pending:n,lowFpsEnabled:i,fpsMinThreshold:a,onRoleChange:o,onLowFpsToggle:s}){return r(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[Pn.map(r=>d(sr,{role:r,value:e[r],options:t,pending:n,onChange:o},r)),r(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[d(`input`,{type:`checkbox`,checked:i,disabled:n,onChange:e=>s(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),r(`span`,{className:`flex flex-col gap-0.5`,children:[d(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),r(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,i?`${a} fps`:`disabled`]})]})]})]})}n();function lr(){let e=c(),{nodes:t}=R(),n=A(void 0),i=fe({addonId:jn}),s=fe({addonId:Mn}),l=()=>Kn(e),f=de({onSuccess:l}),p=Ce(),m=Se({onSuccess:l}),h=Ee({onSuccess:l}),[g,_]=u(!1),v=a(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),y=a(()=>t.map(e=>{let t=v.get(e.id),n=Dt(t,e.isHub),r=Bn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:Bn(t,`maxCameras`),reachableHost:Vn(t,`reachableHost`),detectedHosts:e.localIps}}),[t,v]),b=y.filter(e=>e.effective.pipeline),x={ingestNode:Rn(i.data,`ingestNode`,`hub`),recordingNode:Rn(s.data,Nn,`hub`),audioNode:Rn(i.data,`audioNode`,`hub`),motionNode:Rn(i.data,`motionNode`,`hub`)},S=a(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...Pn.map(e=>x[e]),...e])].filter(e=>e.length>0)},[t,x]),C=zn(i.data,`fpsMinThreshold`,0),w=C>0,T=n.isLoading||i.isLoading||s.isLoading,E=(e,t,n)=>{f.mutate({agentNodeId:e,[t]:n})},D=(e,t)=>{if(e===`recordingNode`){h.mutate({addonId:Mn,patch:{[Nn]:t}});return}h.mutate({addonId:jn,patch:{[e]:t}})},O=e=>{h.mutate({addonId:jn,patch:{fpsMinThreshold:e?Math.max(1,C):0}})},k=e=>m.variables?.agentNodeId===e?m.isPending?`pending`:m.isError?`error`:m.isSuccess?`success`:`idle`:`idle`,ee=e=>k(e)===`error`?Gn(m.error):null,j=async e=>{_(!0);try{for(let t of e)await p.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{_(!1),l()}},M={capabilityPending:f.isPending,onToggleCapability:E,onCommitReachableHost:(e,t)=>m.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:k,reachableHostErrorMessage:ee};return r(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[r(`header`,{className:`flex items-start justify-between gap-4`,children:[r(`div`,{className:`space-y-1`,children:[d(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),d(`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.`})]}),T&&d(U,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),r(`div`,{className:`space-y-3`,children:[d(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),d(cr,{roleValues:x,options:S,pending:h.isPending,lowFpsEnabled:w,fpsMinThreshold:C,onRoleChange:D,onLowFpsToggle:O})]}),r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[d(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),d(ar,{})]}),y.length===0?d(`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.`}):r(o,{children:[d(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:y.map(e=>d(ir,{node:e,actions:M},e.id))}),d(`div`,{className:`hidden @3xl/clustertab:block`,children:d(or,{nodes:y,actions:M})})]})]}),r(`div`,{className:`space-y-3`,children:[d(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),d(Be,{nodes:b,pending:g,onCommitWeights:e=>void j(e)})]}),r(`div`,{className:`space-y-3`,children:[d(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),b.length===0?d(`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.`}):d(`div`,{className:`space-y-2`,children:b.map(e=>d(Ve,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}n();var ur=!1;function dr({refreshToken:e}){let t=c(),{data:n}=V(void 0);a(()=>vt(n??[]),[n]);let i=ae({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return r(`div`,{className:`space-y-6`,children:[d(jt,{refreshToken:e}),d(lr,{}),ur,r(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[r(`div`,{className:`min-w-0`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),d(`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.`})]}),r(`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:[d(tt,{className:`h-3.5 w-3.5`}),i.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var fr=[`pipeline-orchestrator`],pr=`pipeline-analytics`,mr=`face-gallery`;function hr({refreshToken:e}){return r(`div`,{className:`space-y-4 max-w-3xl`,children:[d(bt,{nodeId:`hub`,addonIds:fr,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer, failover, enrichment models, and the admission settings those models share. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`}),d(bt,{nodeId:`hub`,addonIds:[pr],level:`global`,capability:mr,title:`Face recognition`,description:`Match threshold, ambiguity margin, and auto-assign floors. Same settings as System → Settings → pipeline-analytics — this page asks the face-gallery cap, it does not store a second copy.`})]})}n();function gr({refreshToken:e}){let t=c(),{data:n,isLoading:i}=oe(),[a,s]=u(null),[l,f]=u(``),[p,m]=u(``),h=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},g=ue({onSuccess:()=>{s(null),h()}}),_=S({onSuccess:h}),v=e=>{s(e.id),f(e.name),m(e.description??``)},y=()=>{s(null),f(``),m(``)},b=()=>{if(!a)return;let e=p.trim();g.mutate({id:a,name:l.trim()||`Untitled`,...e?{description:e}:{}})};if(i)return d(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let x=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return d(`div`,{className:`space-y-6 max-w-4xl`,children:r(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),d(`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.`})]}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[x.length,` template`,x.length===1?``:`s`]})]}),x.length===0?r(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[d(Je,{className:`h-6 w-6 opacity-40`}),d(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):d(`ul`,{className:`divide-y divide-border`,children:x.map(e=>{let t=a===e.id;return d(`li`,{className:`px-4 py-3 text-xs`,children:r(`div`,{className:`flex items-start gap-3`,children:[d(`div`,{className:`flex-1 min-w-0`,children:t?r(`div`,{className:`space-y-2`,children:[d(`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:l,onChange:e=>f(e.target.value),placeholder:`Template name`,autoFocus:!0}),d(`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:p,onChange:e=>m(e.target.value),placeholder:`Description (optional)`})]}):r(o,{children:[d(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&d(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),r(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,r(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),d(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?r(o,{children:[r(`button`,{type:`button`,onClick:b,disabled:g.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:[d(ht,{className:`h-3 w-3`}),`Save`]}),r(`button`,{type:`button`,onClick:y,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[d(ft,{className:`h-3 w-3`}),`Cancel`]})]}):r(o,{children:[d(`button`,{type:`button`,onClick:()=>v(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:d(qe,{className:`h-3 w-3`})}),d(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&_.mutate({id:e.id})},disabled:_.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:d(mt,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}var _r=`pipeline-orchestrator`,vr=200;function yr(){return r(`div`,{className:`flex flex-col gap-3`,children:[r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),d(`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.`})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(k,{addonId:_r,limit:vr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}n();var br=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function xr({refreshToken:e}){let[t,n]=u(`assignments`);return r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),d(`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.`})]}),d(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:br.map(e=>d(`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))}),r(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&d($n,{}),t===`balancer`&&d(dr,{refreshToken:e}),t===`settings`&&d(hr,{refreshToken:e}),t===`templates`&&d(gr,{refreshToken:e}),t===`logs`&&d(yr,{})]})]})}var Sr=`armed:`;function Cr(e){return e.assignment.reasons.detection?.startsWith(Sr)===!0}function wr(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!Cr(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function Tr(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&&!Cr(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 Er(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Dr(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Or(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function kr(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var Ar={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 jr(e){if(!Er(e)||!Array.isArray(e.sections))return Ar;let t=ke(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)kr(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Dr(n(`detectionFps`)),motionSources:Or(n(`motionSources`)),motionFps:Dr(n(`motionFps`)),motionCooldownMs:Dr(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 Mr(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(...Mr(r.children,t+1));return n}function X({title:e,children:t}){return r(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[d(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),d(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return r(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[d(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),d(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&d(Nr,{})]})}function Nr(){return d(`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 Pr={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 d(`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 ${Pr[e]}`,children:t})}function $({children:e}){return d(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function Fr({icon:e,label:t,nodeId:n,pinned:i,reason:a,overridden:s}){return r(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[d(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),d(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?d(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):r(o,{children:[d(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),i?r(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[d(Ct,{className:`h-2.5 w-2.5`}),` manual`]}):r(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,a!==void 0&&a.length>0?a:`capacity`]}),s&&d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function Ir({assignment:e,settings:t,onlineNodes:n,pinPending:i,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return r(X,{title:`Where it runs`,children:[d(Fr,{icon:W,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),d(Fr,{icon:st,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),d(Fr,{icon:Ge,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),d(Fr,{icon:Ye,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),d(`div`,{className:`mt-1.5`,children:r(`select`,{value:o,disabled:i,"aria-label":`Detection placement pin`,onChange:e=>a(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:[d(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>r(`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 Rr(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function zr(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function Br({streams:e,brokerProfiles:t,settings:n,motionEnabled:i,motionFpsLive:a}){let s=Rr(t,n.detectionStreamProfile),c=Rr(t,n.motionStreamProfile),l=n.motionSources.includes(`analyzer`);return r(X,{title:`Streams & motion`,children:[r(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,s!==void 0&&` · ${s.width}×${s.height} ${s.codec}`]}),d(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:zr(n.detectionFps)}),r(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.join(` + `):`none`,i===!1&&` · inactive`]}),l&&r(o,{children:[r(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),r(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[zr(n.motionFps),a!==null&&` · live ${a.toFixed(1)}`]})]}),d(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),d(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?d($,{children:`No streams registered`}):e.map(e=>r(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[d(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,Lr(e)]},e.camStreamId))})]})}function Vr({steps:e,audioModelId:t,audioEnabled:n,audioMode:i}){return r(X,{title:`Pipeline steps`,children:[e===void 0?d($,{children:`Resolving…`}):e.length===0?d($,{children:`No steps configured`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>d(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:r(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&d(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&r(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),d(`div`,{className:`mt-1`,children:r(Z,{label:`Audio class.`,children:[i??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var Hr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function Ur({detection:e,live:t,detectionMode:n,modeOverridden:i}){if(e===null)return r(X,{title:`Detection runtime`,children:[d(Z,{label:`Mode`,overridden:i,children:n??`—`}),d($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,u=m(a),f=a===`active`&&o===0;return r(X,{title:`Detection runtime`,children:[r(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[r(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[d(pe,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&d(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),d(Z,{label:`Mode`,overridden:i,children:n??`—`}),r(Z,{label:`FPS`,children:[d(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),r(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),r(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&r(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&r(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),r(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),r(Z,{label:`Provisioning`,children:[d(Q,{tone:Hr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&r(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function Wr({broker:e}){return e===null?d(X,{title:`Stream broker`,children:d($,{children:`Broker stage inactive or unreachable`})}):r(X,{title:`Stream broker`,children:[e.profiles.length===0?d($,{children:`No broker profiles`}):d(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return r(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[d(`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}),d(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),r(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),r(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),r(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),r(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[r(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),r(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function Gr({decoder:e,detectionActive:t}){if(e===null)return d(X,{title:`Decoder`,children:d($,{children:`Decoder stage inactive or unreachable`})});let n=t&&e.shm.framesWritten===0;return r(X,{title:`Decoder`,children:[d(Z,{label:`Node`,children:e.nodeId}),d(Z,{label:`Sessions`,children:e.sessionCount}),r(Z,{label:`SHM frames`,children:[d(`span`,{className:n?`text-danger font-semibold`:``,children:e.shm.framesWritten}),d(`span`,{className:`text-foreground-subtle`,children:` written`})]}),r(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&r(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),r(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&d(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}n();var Kr=`pipeline-orchestrator`,qr={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},Jr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Yr({problems:e}){return d(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>r(`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:[d(pt,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),d(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function Xr({deviceId:e,name:t,online:n,status:i,live:o,onlineNodes:s}){let l=c(),{data:u}=me({addonId:Kr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=h({deviceId:e},{staleTime:3e4}),p=a(()=>jr(u),[u]),m=a(()=>f===void 0?void 0:Mr(f.steps),[f]),g=a(()=>i===void 0?[]:Tr(i),[i]),_=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},v=L({onSuccess:_}),y=Te({onSuccess:_}),b=t=>{t===`auto`?y.mutate({deviceId:e}):v.mutate({deviceId:e,agentNodeId:t})},x=i===void 0?`idle`:wr(i),S=g.some(e=>e.severity===`error`),C=g.length>0,w=S?`border-danger/50`:C?`border-warning/40`:`border-border`;return r(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${w} bg-background overflow-hidden`,children:[r(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[d(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${S?`bg-danger`:qr[x]}`,title:S?`Error`:Jr[x],"aria-label":S?`Error`:Jr[x],role:`img`}),d(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&d(Q,{tone:`danger`,children:`offline`}),r(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&d(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),i?.recording!=null&&(i.recording.active?r(Q,{tone:`danger`,title:`Recording (${i.recording.mode})`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):i.recording.mode!==`off`&&r(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,i.recording.mode]}))]})]}),g.length>0&&d(Yr,{problems:g}),i===void 0?d(`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.`}):r(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[d(Ir,{assignment:i.assignment,settings:p,onlineNodes:s,pinPending:v.isPending||y.isPending,onDetectionPinChange:b}),d(Ur,{detection:i.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),d(Vr,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:i.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),d(Br,{streams:i.source.streams,brokerProfiles:i.broker?.profiles,settings:p,motionEnabled:i.motion?.enabled??null,motionFpsLive:i.motion?.fps??null}),d(Wr,{broker:i.broker}),d(Gr,{decoder:i.decoder,detectionActive:i.detection?.phase===`active`})]})]})}n();var Zr=5e3,Qr=1e4,$r=5e3;function ei(e){let t=c(),{data:n,isLoading:r}=Re(),{data:i,isLoading:o}=v({},{refetchInterval:Zr}),{nodes:s}=R();f(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[l,d]=u(new Map);N(Ae.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&d(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})}),f(()=>{if(l.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-Qr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},$r);return()=>clearInterval(e)},[l.size]);let p=a(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:a(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:l,onlineNodes:a(()=>(s??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[s]),isLoading:r||o}}n();function ti({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:i,isLoading:o}=ei(e),s=a(()=>[...t.map(e=>{let t=e.status===void 0?[]:Tr(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]),c=a(()=>{let e=0,t=0;for(let r of s)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,n]);return o&&t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):d(`div`,{className:`h-full overflow-y-auto`,children:r(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[r(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[r(`span`,{children:[d(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),r(`span`,{children:[d(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),r(`span`,{children:[d(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),d(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>d(Xr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:i},e.deviceId))]})})}n();var ni=`__cluster__`;function ri(e){return e===`cameras`?`cameras`:`nodes`}function ii(){let[e,t]=ut(),n=ri(e.get(`view`)),i=e.get(`node`)??`__cluster__`,[a,s]=u(0),[c,l]=u(!1);return f(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:ni},{replace:!0})},[n,e,t]),r(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[r(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[r(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[d(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:i},{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`}),d(`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`})]}),d(`div`,{className:`flex items-center gap-2`,children:r(`button`,{type:`button`,onClick:()=>s(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:[d(Xe,{className:`h-3.5 w-3.5`}),`Refresh`]})})]}),n===`nodes`&&r(`button`,{type:`button`,onClick:()=>l(e=>!e),"aria-expanded":c,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:[r(`span`,{children:[c?`Hide`:`Show`,` node list`]}),d(lt,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),d(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?r(o,{children:[d(`aside`,{className:[c?`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:d(kt,{selectedNodeId:i,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:a})}),d(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:i===`__cluster__`?d(xr,{refreshToken:a}):d(Tn,{nodeId:i,refreshToken:a})})]}):d(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:d(ti,{refreshToken:a})})})]})}export{ii as PipelinePage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as c,q as l}from"./player-overlays-CBKaIBph.js";import{Ao as u,Br as d,Fo as f,Ho as p,Io as m,Is as h,Jo as g,Ko as _,Mo as v,Oo as y,Po as b,Uo as x,Wo as S,Xo as C,Xt as w,Yo as T,Za as E,an as D,ba as O,et as k,gn as A,ha as j,jo as M,ko as ee,ln as N,oa as P,qa as te,qo as ne,ta as F,ua as re,vn as ie}from"./src-BLHY9yig.js";import{Rt as I,mt as L}from"./src-0pbBUmTo.js";import{t as ae}from"./circle-x-CBZPec7u.js";import{t as oe}from"./download-Dq2bfdRX.js";import{t as R}from"./hard-drive-COdkuHqf.js";import{C as z,G as B,K as V,M as H,O as U,V as se,i as W,s as G}from"./index-LPwis6Rq.js";import{t as ce}from"./AdminPage-CCD07UMs.js";import{r as le}from"./authed-media-BPd_L9jr.js";import{t as ue}from"./DeviceAggregateSection-r5_ljoI1.js";import{t as de}from"./AdminTabs-FswV6m19.js";import{t as K}from"./format-size-CO9d3C3-.js";import{i as q,n as fe,r as pe,t as me}from"./AddLocationWizard-BntkKU2V.js";var J=V(`arrow-right-left`,[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]),Y=V(`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`}]]),he=V(`settings-2`,[[`path`,{d:`M20 7h-9`,key:`3s1dr2`}],[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]);t();function ge(){let e=d({}),t=r(()=>(e.data??[]).filter(e=>e.type===L.Camera).sort((e,t)=>e.name.localeCompare(t.name)),[e.data]),[i,s]=a(null),c=i??t[0]?.id??null;return!e.isLoading&&t.length===0?o(w,{icon:se,title:`No cameras`,description:`Add a camera first.`}):n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Camera`}),o(`select`,{value:c??``,onChange:e=>s(Number(e.target.value)),className:`rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:t.map(e=>o(`option`,{value:e.id,children:e.name},e.id))})]}),c!==null&&o(D,{deviceId:c,children:o(ue,{deviceId:c,sectionFilter:e=>e.location===`top-tab`&&e.tab===`recording`})},c)]})}t();var _e=[`high`,`mid`,`low`],ve=[{value:1,label:`Real time (1×)`},{value:2,label:`2×`},{value:4,label:`4×`},{value:8,label:`8×`},{value:16,label:`16×`}],ye=10080*60*1e3;function X(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 be({onClose:e,onCreated:t}){let i=d({}),s=r(()=>(i.data??[]).filter(e=>e.type===L.Camera).sort((e,t)=>e.name.localeCompare(t.name)),[i.data]),[c,l]=a(``),[f,p]=a(`high`),[m,h]=a(X(60)),[g,_]=a(X(0)),[v,y]=a(1),[b,x]=a(!0),[S,C]=a(``),[w,T]=a(null),E=c===``?s[0]?.id??null:c,D=new Date(m).getTime(),O=new Date(g).getTime(),k=Number.isFinite(D)&&Number.isFinite(O)&&D<O,A=u({onSuccess:()=>{t(),e()},onError:e=>T(e instanceof Error?e.message:String(e))});return o(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:e,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`h2`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[o(U,{className:`h-3.5 w-3.5`}),`New export`]}),o(`button`,{onClick:e,className:`text-foreground-subtle hover:text-foreground`,children:o(W,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Camera`}),o(`select`,{value:E??``,onChange:e=>l(Number(e.target.value)),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:s.map(e=>o(`option`,{value:e.id,children:e.name},e.id))})]}),n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Profile`}),o(`select`,{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`,children:_e.map(e=>o(`option`,{value:e,children:e},e))})]})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`From`}),o(`input`,{type:`datetime-local`,value:m,onChange:e=>h(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`})]}),n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`To`}),o(`input`,{type:`datetime-local`,value:g,onChange:e=>_(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`})]})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Speed`}),o(`select`,{value:v,onChange:e=>y(Number(e.target.value)),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:ve.map(e=>o(`option`,{value:e.value,children:e.label},e.value))})]}),n(`div`,{className:`space-y-1`,children:[o(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Title (optional)`}),o(`input`,{type:`text`,value:S,onChange:e=>C(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`})]})]}),n(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[o(`input`,{type:`checkbox`,checked:b,disabled:v!==1,onChange:e=>x(e.target.checked),className:`accent-primary`}),`Include audio`,v===1?``:` (real-time only)`]}),!k&&o(`p`,{className:`text-[11px] text-danger`,children:`"From" must be before "To".`}),w&&o(`p`,{className:`text-[11px] text-danger`,children:w})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[o(`button`,{onClick:e,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),o(`button`,{onClick:()=>{if(E===null||!k)return;T(null);let e=S.trim();A.mutate({deviceId:E,profile:f,fromMs:D,toMs:O,options:{includeAudio:b,maxLifeMs:ye,deleteAfterDownload:!1,...v===1?{}:{speed:v},...e.length>0?{title:e}:{}}})},disabled:E===null||!k||A.isPending,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:A.isPending?`Queuing…`:`Create export`})]})]})})}function xe(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 Se(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function Ce(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`${Se(e)} · ${o}`}function we(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 Te(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})}t();var Ee=[[`recordingExport`]],De={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 Oe(){let{data:e,isLoading:t}=v({},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`queued`||e.state===`rendering`)?3e3:!1}),{map:n}=h(I.RecordingExportProgress,e=>e.exportId),{map:i}=h(I.RecordingExportCompleted,e=>e.exportId),{map:a}=h(I.RecordingExportFailed,e=>e.exportId);return{rows:r(()=>Te(e??[],n,i,a),[e,n,i,a]),isLoading:t}}function ke(e){let[t,n]=a(()=>Date.now());return s(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function Ae(){let t=i(),[s,l]=a(!1),u=()=>{t.invalidateQueries({queryKey:[[`recordingExport`,`listExports`]]})},f=N(),p=c().trpcClient,m=ke(6e4),{rows:h,isLoading:g}=Oe(),{data:_}=d({}),v=r(()=>{let e=new Map;for(let t of _??[])e.set(t.id,t.name);return e},[_]),y=e(()=>{t.invalidateQueries({queryKey:Ee})},[t]),b=ee({onSuccess:y}),x=M({onSuccess:y}),[S,C]=a(null),T=e(async e=>{C(e.id);try{let{url:t}=await p.recordingExport.getDownloadUrl.query({exportId:e.id}),n=await le(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),y()}finally{C(null)}},[p,y]),E=e(async e=>{await f({title:`Cancel this export?`,message:`Stops the render. The partial file is discarded.`,confirmLabel:`Cancel export`,variant:`danger`})&&b.mutate({exportId:e.id})},[f,b]),D=e(async e=>{await f({title:`Delete this export?`,message:`Permanently removes the rendered file and its history row.`,confirmLabel:`Delete`,variant:`danger`})&&x.mutate({exportId:e.id})},[f,x]),O=r(()=>[{key:`camera`,header:`Camera`,render:e=>o(`span`,{className:`text-foreground`,children:v.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`range`,header:`Range`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:Ce(e.fromMs,e.toMs)})},{key:`variant`,header:`Variant`,render:e=>o(`span`,{className:`text-foreground-subtle`,children:xe(e.options)})},{key:`state`,header:`State`,render:e=>{let t=De[e.state];return n(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${t.cls}`,children:[t.spin&&o(z,{className:`h-2.5 w-2.5 animate-spin`}),t.label,e.state===`rendering`&&e.progressPct!==null&&n(`span`,{className:`tabular-nums`,children:[e.progressPct,`%`]})]})}},{key:`expiry`,header:`Expires`,nowrap:!0,render:e=>e.state===`deleted`?o(`span`,{className:`text-foreground-subtle`,children:`—`}):o(`span`,{className:`text-foreground-subtle tabular-nums`,children:we(e.expiresAt,m)})},{key:`size`,header:`Size`,align:`right`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:e.fileBytes===null?`—`:K(e.fileBytes)})},{key:`actions`,header:``,align:`right`,render:e=>{let t=e.state===`ready`,r=e.state===`queued`||e.state===`rendering`,i=e.state!==`deleted`;return n(`div`,{className:`flex items-center justify-end gap-1`,children:[t&&n(`button`,{onClick:()=>{T(e)},disabled:S===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:[S===e.id?o(z,{className:`h-3 w-3 animate-spin`}):o(oe,{className:`h-3 w-3`}),`Download`]}),r&&n(`button`,{onClick:()=>{E(e)},disabled:b.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:[o(ae,{className:`h-3 w-3`}),`Cancel`]}),i&&o(`button`,{onClick:()=>{D(e)},disabled:x.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:o(G,{className:`h-3 w-3`})})]})}}],[v,m,S,b.isPending,x.isPending,T,E,D]);return g&&h.length===0?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[o(z,{className:`h-4 w-4 animate-spin`}),`Loading exports…`]}):n(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex justify-end`,children:n(`button`,{onClick:()=>l(!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:[o(U,{className:`h-3.5 w-3.5`}),`New export`]})}),h.length===0?o(w,{icon:U,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.`}):o(k,{columns:O,rows:h,rowKey:e=>e.id,minWidthPx:720}),s&&o(be,{onClose:()=>l(!1),onCreated:u})]})}function Z(e){return e.locationIds!==void 0&&e.locationIds.length>0?e.locationIds:e.locationId===null?[]:[e.locationId]}function je(e,t){let n=Z(e);return n.length===0?`default root`:n.map(e=>t.get(e)??e).join(` + `)}function Me(e,t,n){if(e.length===0)return null;let r=e[0];if(e.length===1&&r!==void 0)return{label:je(r,t),exact:!0};if(n===null)return null;let i=e.find(e=>Z(e).includes(n));return i===void 0?null:{label:je(i,t),exact:!1}}var Ne=[`ok`,`warn`,`critical`];function Pe(e){return e>=.95?`critical`:e>=.85?`warn`:`ok`}function Fe(e){return Math.min(1,Math.max(0,e))}function Ie(e){let{availableBytes:t,totalBytes:n}=e;if(n===null||n<=0||t===null)return null;let r=Fe((n-t)/n);return{fraction:r,severity:Pe(r),recordingsFraction:Fe(e.usedBytes/n),freeBytes:t,totalBytes:n}}function Le(e){if(e.length===0)return null;let t=0,n=0,r=0,i=0,a=null;for(let o of e){let e=Ie(o);if(e===null){n+=1;continue}t+=1,r+=e.totalBytes,i+=e.freeBytes,(a===null||Ne.indexOf(e.severity)>Ne.indexOf(a))&&(a=e.severity)}return{knownVolumes:t,unknownVolumes:n,totalBytes:r,freeBytes:i,severity:a}}t();var Re=[[`recording`]],ze=[{value:`retention`,label:`Retention policy`},{value:`quota`,label:`Quota / disk pressure`},{value:`operator`,label:`Operator`}],Be={ok:`bg-primary`,warn:`bg-amber-500`,critical:`bg-danger`},Ve={ok:`text-foreground-subtle`,warn:`text-amber-500`,critical:`text-danger`};function Q(e){return`${String(Math.round(e*100))}%`}function He(e,t){let n=e.locationIds??(e.locationId===null?[]:[e.locationId]),r=n.map(e=>t.get(e)).filter(e=>e!==void 0);return r.length>0?r.join(` + `):e.root===void 0?n.length>0?n.join(` + `):`default root`:e.root}function Ue(){let t=i(),s=N(),[c,u]=a(`retention`),{data:f,isLoading:p}=b({},{refetchOnWindowFocus:!1}),{data:h}=d({}),{data:g}=S({}),_=r(()=>{let e=new Map;for(let t of h??[])e.set(t.id,t.name);return e},[h]),v=r(()=>{let e=new Map;for(let t of g??[])e.set(t.id,t.displayName);return e},[g]),x=r(()=>(g??[]).find(e=>e.type===`recordings`&&e.isDefault)?.id??null,[g]),C=r(()=>f?.locations??[],[f?.locations]),T=r(()=>Me(C,v,x),[C,v,x]),E=r(()=>Le(C),[C]),D=e(()=>{t.invalidateQueries({queryKey:Re})},[t]),O=m({onSuccess:D}),A=y({onSuccess:D}),j=e(async e=>{await s({title:`Prune ${_.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Applies the retention policy now (reason: ${c}). Footage beyond the policy is permanently deleted.`,confirmLabel:`Prune now`,variant:`danger`})&&O.mutate({deviceId:e.deviceId,reason:c})},[s,O,c,_]),M=e(async e=>{await s({title:`Delete all footage for ${_.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${K(e.usedBytes)} of recorded footage for this camera. This cannot be undone.`,confirmLabel:`Delete ${K(e.usedBytes)}`,variant:`danger`})&&A.mutate({deviceId:e.deviceId})},[s,A,_]),ee=r(()=>[{key:`camera`,header:`Camera`,render:e=>o(`span`,{className:`text-foreground`,children:_.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`disk`,header:`Disk`,nowrap:!0,render:()=>T===null?o(`span`,{className:`text-foreground-subtle`,children:`—`}):n(`span`,{className:T.exact?`text-foreground`:`text-foreground-subtle`,title:T.exact?`The only recordings volume on this node — this camera can only be here.`:`The recordings DEFAULT. This node has several recordings volumes and the per-camera placement is not reported by recording.getStorageUsage, so this is where footage lands by default rather than a per-camera fact.`,children:[T.label,!T.exact&&o(`span`,{className:`ml-1 text-foreground-subtle`,children:`(default)`})]})},{key:`used`,header:`Used`,align:`right`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:K(e.usedBytes)})},{key:`actions`,header:``,align:`right`,render:e=>n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{j(e)},disabled:O.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:[o(Y,{className:`h-3 w-3`}),`Prune`]}),n(`button`,{onClick:()=>{M(e)},disabled:A.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:[o(G,{className:`h-3 w-3`}),`Delete`]})]})}],[_,T,j,M,O.isPending,A.isPending]);if(p&&!f)return n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[o(z,{className:`h-4 w-4 animate-spin`}),`Loading storage usage…`]});if(!f)return o(w,{icon:R,title:`No storage data`,description:`The recording node has not reported any storage usage yet.`});let P=f.devices.length;return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[o(l,{label:`Total used`,icon:o(R,{className:`h-3 w-3`}),footer:`${String(P)} camera${P===1?``:`s`} on ${f.nodeId}`,children:K(f.totalUsedBytes)}),E!==null&&E.severity!==null&&o(l,{label:`Free on recordings volumes`,icon:o(R,{className:`h-3 w-3`}),footer:`across ${String(E.knownVolumes)} volume${E.knownVolumes===1?``:`s`} of ${K(E.totalBytes)}`+(E.unknownVolumes>0?` · ${String(E.unknownVolumes)} did not report capacity`:``),children:o(`span`,{className:`tabular-nums ${Ve[E.severity]}`,children:K(E.freeBytes)})}),C.map(e=>{let t=Ie(e),r=e.locationId??e.root??`default`;return o(l,{label:`Disk: ${He(e,v)}`,footer:t===null?`${K(e.usedBytes)} of recordings · volume capacity unknown`:`${K(t.freeBytes)} free of ${K(t.totalBytes)} · ${K(e.usedBytes)} recordings (${Q(t.recordingsFraction)})`,children:t===null?o(`span`,{className:`tabular-nums`,children:K(e.usedBytes)}):n(`div`,{className:`flex items-center gap-2`,title:`Volume fill — everything on the disk, not only recordings. Warn at 85%, critical at 95%.`,children:[o(`div`,{className:`h-2 flex-1 overflow-hidden rounded bg-muted`,children:o(`div`,{className:`h-full rounded ${Be[t.severity]}`,style:{width:Q(t.fraction)}})}),o(`span`,{className:`tabular-nums text-xs ${Ve[t.severity]}`,children:Q(t.fraction)})]})},r)})]}),n(`section`,{className:`flex items-center gap-2 text-xs`,children:[o(`label`,{htmlFor:`prune-reason`,className:`text-foreground-subtle`,children:`Prune reason`}),o(`select`,{id:`prune-reason`,value:c,onChange:e=>{let t=ze.find(t=>t.value===e.target.value);t&&u(t.value)},className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:ze.map(e=>o(`option`,{value:e.value,children:e.label},e.value))})]}),P===0?o(w,{icon:R,title:`No recorded footage`,description:`No camera has recorded footage on this node yet.`}):o(k,{columns:ee,rows:[...f.devices],rowKey:e=>e.deviceId,minWidthPx:480})]})}t();var We=[{value:`all`,label:`All`},{value:`recording`,label:`Recordings`},{value:`events`,label:`Events`}],Ge={recording:`bg-primary/10 text-primary`,events:`bg-violet-500/10 text-violet-400`};function Ke(e){return new Date(e).toLocaleString()}function qe(){let[e,t]=a(`all`),{data:i,isLoading:s}=f({},{refetchOnWindowFocus:!1}),{data:c,isLoading:l}=j({},{refetchOnWindowFocus:!1}),{data:u}=d({}),p=r(()=>{let e=new Map;for(let t of u??[])e.set(t.id,t.name);return e},[u]),m=r(()=>{let t=[...i??[],...c??[]];return(e===`all`?t:t.filter(t=>t.domain===e)).toSorted((e,t)=>t.at-e.at)},[i,c,e]),h=r(()=>[{key:`at`,header:`When`,nowrap:!0,render:e=>o(`span`,{className:`text-foreground-subtle tabular-nums`,children:Ke(e.at)})},{key:`domain`,header:`Domain`,render:e=>o(`span`,{className:`inline-flex rounded px-1.5 py-0.5 text-[10px] font-medium ${Ge[e.domain]}`,children:e.domain})},{key:`op`,header:`Operation`,render:e=>o(`span`,{className:`text-foreground`,children:e.op})},{key:`reason`,header:`Reason`,render:e=>o(`span`,{className:`text-foreground-subtle`,children:e.reason})},{key:`device`,header:`Camera`,render:e=>e.deviceId===null?o(`span`,{className:`text-foreground-subtle`,children:`cluster`}):o(`span`,{className:`text-foreground`,children:p.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`items`,header:`Items`,align:`right`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:e.itemsAffected.toLocaleString()})},{key:`bytes`,header:`Reclaimed`,align:`right`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:e.bytesReclaimed>0?K(e.bytesReclaimed):`—`})}],[p]),g=s||l;return n(`div`,{className:`flex flex-col gap-4`,children:[o(`div`,{className:`flex items-center gap-1`,children:We.map(n=>o(`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))}),g&&m.length===0?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[o(z,{className:`h-4 w-4 animate-spin`}),`Loading activity…`]}):m.length===0?o(w,{icon:B,title:`No activity yet`,description:`Prune, delete and rescan operations across recordings and events show up here.`}):o(k,{columns:h,rows:m,rowKey:e=>e.id,minWidthPx:720})]})}t();function Je({types:e}){let t=i(),s=N(),{data:c}=S({}),l=x(),u=r(()=>l.data??[],[l.data]),[d,f]=a(null),[m,h]=a(null),g=()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},_=C({onSuccess:g}),v=p({onSuccess:g}),y=r(()=>{let e=new Map;for(let t of c??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[c]),b=e=>{e.isDefault||_.mutate(q(e,{isDefault:!0}))},w=(e,t)=>{_.mutate(q(e,{enabled:t}))},T=async e=>{if(e.isDefault){await s({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another as default first.`,confirmLabel:`OK`,variant:`warning`});return}await s({title:`Delete location "${e.displayName}"?`,message:`Removes the record; files on disk are untouched.`,confirmLabel:`Delete`,variant:`danger`})&&v.mutate({id:e.id})},E=e.map(e=>u.find(t=>t.id===e)).filter(e=>e!==void 0);return n(`div`,{className:`space-y-3`,children:[E.length===0?o(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:`No storage locations declared for this purpose.`}):E.map(e=>o(pe,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:y.get(e.id)??[],onAdd:e=>f(e),onEdit:e=>h(e),onDelete:e=>{T(e)},onSetDefault:e=>b(e),onToggleEnabled:(e,t)=>w(e,t)},e.id)),d!==null&&o(me,{initialType:d,onClose:()=>f(null),onCreated:()=>{g(),f(null)}}),m!==null&&o(fe,{location:m,onClose:()=>h(null),onSaved:()=>{g(),h(null)}})]})}t();var Ye=`pipeline-analytics`;function Xe(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 Ze(){let e=i(),{data:t}=F(void 0),{data:a,isLoading:s}=A({addonId:Ye}),c=Xe(a),l=ie({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),u=r(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,c,...e])].filter(Boolean)},[t,c]);return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[o(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),o(`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.`}),n(`div`,{className:`mt-3 flex items-center gap-2`,children:[s?o(z,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):o(`select`,{value:c,onChange:e=>{e.target.value!==c&&l.mutate({addonId:Ye,patch:{postProcessingNodeId:e.target.value}})},disabled:l.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:u.map(e=>o(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),l.isPending&&o(z,{className:`h-4 w-4 animate-spin text-primary`})]})]}),n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[o(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),o(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),o(Je,{types:[`eventMedia`]})]})]})}t();var $=`recorder`;function Qe(e,t,n){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t&&typeof e.value==`string`)return e.value;return n}function $e(){let e=i(),{data:t}=F(void 0),{data:a,isLoading:s}=A({addonId:$}),c=Qe(a,`recordingNodeId`,`hub`),l=ie({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),u=r(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,c,...e])].filter(Boolean)},[t,c]);return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[o(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),o(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records (continuous & events) and serves playback. Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),n(`div`,{className:`mt-3 flex items-center gap-2`,children:[s?o(z,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):o(`select`,{value:c,onChange:e=>{e.target.value!==c&&l.mutate({addonId:$,patch:{recordingNodeId:e.target.value}})},disabled:l.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:u.map(e=>o(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),l.isPending&&o(z,{className:`h-4 w-4 animate-spin text-primary`})]}),c!==`hub`&&n(`p`,{className:`mt-2 text-[11px] text-amber-500`,children:[`The stream-broker is hub-only — an agent recorder pulls streams from the hub over the network. The hub's RTSP restream port must be reachable from`,` `,o(`span`,{className:`font-medium`,children:c}),`. If the auto-derived host doesn't work, set the recorder's`,o(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[o(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),o(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where recordings are stored. Multi-location collections — segments are split across the locations of a type. Add a location to grow capacity; mark one default per type.`}),o(Je,{types:[`recordings`,`recordingsLow`]})]})]})}t();var et=2e3;function tt(){let e=N(),t=i(),r=E(),a=te(void 0,{refetchInterval:e=>e.state.data?.state===`running`?et:!1}),c=a.data,l=c?.state===`running`,u=l||r.isPending;s(()=>{c?.state!==`done`||c.finishedAtMs===null||(t.invalidateQueries({queryKey:[[`recording`]]}),t.invalidateQueries({queryKey:[[`pipelineAnalytics`]]}))},[c?.state,c?.finishedAtMs,t]);let d=async()=>{await e({title:`Reconcile storage from disk?`,message:`Makes the database match the filesystem: recordings index, tracks, events and media whose files are gone. Favourited tracks without files are deleted. Snapshot-less motion/audio events are deleted. Enrolled identities stay. This cannot be undone.`,confirmLabel:`Reconcile`,variant:`warning`})&&(await r.mutateAsync(),await a.refetch())},f=l?c.total>0?`Reconciling ${String(c.completed)}/${String(c.total)}…`:`Reconciling…`:r.isPending?`Reconciling…`:`Reconcile from disk`;return n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[o(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Disk reconcile`}),o(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Makes the database match the filesystem for recordings, tracks, events and media. Rows whose files are gone are deleted, including snapshot-less motion events. Enrolled identities stay. The walk runs on the hub; you can leave this page.`}),n(`div`,{className:`mt-3 flex flex-col gap-2`,children:[n(`button`,{type:`button`,onClick:()=>void d(),disabled:u,className:`inline-flex w-fit 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 disabled:opacity-50`,children:[u?o(z,{className:`h-3.5 w-3.5 animate-spin`}):o(R,{className:`h-3.5 w-3.5`}),f]}),c?.state===`done`?n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Last run: `,String(c.completed),` camera(s) — dropped `,String(c.tracks),` tracks,`,` `,String(c.events),` events, `,String(c.mediaDropped),` media`,c.failed.length>0?`, ${String(c.failed.length)} failed (${c.failed.join(`, `)})`:``,`.`]}):null,c?.state===`error`&&c.error!==null?n(`p`,{className:`text-[11px] text-destructive`,children:[`Reconcile failed: `,c.error]}):null]})]})}t();var nt=[[`pipelineAnalytics`]],rt=1440*60*1e3,it=[{days:1,label:`1 day`},{days:7,label:`7 days`},{days:30,label:`30 days`},{days:90,label:`90 days`}];function at(){let t=i(),s=N(),[c,u]=a(30),{data:f,isLoading:p}=re({},{refetchOnWindowFocus:!1}),{data:m}=d({}),h=r(()=>{let e=new Map;for(let t of m??[])e.set(t.id,t.name);return e},[m]),g=e(()=>{t.invalidateQueries({queryKey:nt})},[t]),_=O({onSuccess:g}),v=P({onSuccess:g}),y=e(async()=>{await s({title:`Prune events older than ${String(c)} day${c===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`})&&_.mutate({olderThanMs:Date.now()-c*rt,reason:`retention`})},[s,_,c]),b=e(async e=>{await s({title:`Delete all events for ${h.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${String(e.rows)} event${e.rows===1?``:`s`} (${K(e.bytes)} of media) for this camera. This cannot be undone.`,confirmLabel:`Delete events`,variant:`danger`})&&v.mutate({deviceId:e.deviceId})},[s,v,h]),x=r(()=>[{key:`camera`,header:`Camera`,render:e=>o(`span`,{className:`text-foreground`,children:h.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`rows`,header:`Events`,align:`right`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:e.rows.toLocaleString()})},{key:`bytes`,header:`Media`,align:`right`,nowrap:!0,render:e=>o(`span`,{className:`tabular-nums`,children:K(e.bytes)})},{key:`actions`,header:``,align:`right`,render:e=>n(`button`,{onClick:()=>{b(e)},disabled:v.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:[o(G,{className:`h-3 w-3`}),`Delete`]})}],[h,b,v.isPending]);return p&&!f?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[o(z,{className:`h-4 w-4 animate-spin`}),`Loading event-store footprint…`]}):f?n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[o(l,{label:`Total events`,icon:o(H,{className:`h-3 w-3`}),footer:`across ${String(f.devices.length)} camera${f.devices.length===1?``:`s`}`,children:f.totalRows.toLocaleString()}),o(l,{label:`Event media on disk`,children:K(f.totalBytes)})]}),n(`section`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[o(`span`,{className:`text-foreground-subtle`,children:`Prune events older than`}),o(`select`,{value:c,onChange:e=>u(Number(e.target.value)),className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:it.map(e=>o(`option`,{value:e.days,children:e.label},e.days))}),n(`button`,{onClick:()=>{y()},disabled:_.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:[_.isPending?o(z,{className:`h-3 w-3 animate-spin`}):o(Y,{className:`h-3 w-3`}),`Prune now`]})]}),f.devices.length===0?o(w,{icon:H,title:`No stored events`,description:`No camera has persisted events yet.`}):o(k,{columns:x,rows:[...f.devices],rowKey:e=>e.deviceId,minWidthPx:480})]}):o(w,{icon:H,title:`No event data`,description:`Pipeline analytics has not reported any event-store footprint yet.`})}t();var ot=`storage-migration`;function st(){let{data:e}=F(void 0);return(e??[]).some(e=>e.addons.some(e=>e.capabilities.includes(ot)))}var ct=[{id:`recordings`,label:`Recordings`,locationType:`recordings`},{id:`recordingsLow`,label:`Low-res recordings`,locationType:`recordingsLow`},{id:`eventMedia`,label:`Event media`,locationType:`eventMedia`}],lt=new Set([`planning`,`pausing`,`moving`,`verifying`,`repointing`,`refreshing`,`resuming`]);function ut(){return st()?o(dt,{}):o(w,{icon:J,title:`Storage migration not installed`,description:`This system doesn't advertise the storage-migration capability yet. Once it's deployed, this panel moves recordings, low-res recordings and event media to new storage locations in one coordinated, verified operation.`})}function dt(){let e=N(),{data:t}=S({}),[i,s]=a({}),[c,l]=a(null),[u,d]=a(null),f=r(()=>{let e=new Map;for(let n of t??[]){let t=e.get(n.type);t?t.push(n):e.set(n.type,[n])}return e},[t]),p=T({},{refetchInterval:2e3}),m=p.data??null,h=m!==null&&lt.has(m.phase),v=r(()=>{let e={};for(let t of ct){let n=i[t.id];n&&(e[t.id]=n)}return Object.keys(e).length>0?e:void 0},[i]),y=ne({destinations:v??{}},{enabled:!1,retry:!1}),b=g(),x=_(),C=async()=>{if(!v)return;d(null);let e=await y.refetch();if(e.error){d(e.error instanceof Error?e.error.message:String(e.error));return}l(e.data??null)},w=async()=>{if(v&&await e({title:`Start storage migration?`,message:`Pauses the affected writers, copies the data to the new locations, verifies it, then repoints the defaults. Safe to re-run if interrupted.`,confirmLabel:`Start migration`,variant:`danger`})){d(null);try{await b.mutateAsync({destinations:v}),l(null),await p.refetch()}catch(e){d(e instanceof Error?e.message:String(e))}}},E=async()=>{if(m&&await e({title:`Cancel migration?`,message:`Stops the in-progress migration. Data already moved and verified stays at the destination; anything already repointed is not reverted.`,confirmLabel:`Cancel migration`,variant:`danger`}))try{await x.mutateAsync({jobId:m.jobId}),await p.refetch()}catch{}};return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[n(`h3`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[o(J,{className:`h-3.5 w-3.5`}),`Storage migration`]}),o(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Move recordings, low-res recordings and/or event media to new storage locations in one coordinated operation: pauses the writers, copies via the recorder / pipeline-analytics movers, verifies, then repoints the defaults. Always applies to every camera — destinations are global defaults per storage class, so migration can't be scoped to a subset of cameras. This is the only supported way to move a storage location's data — the Storage tab no longer offers a per-location "Relocate" action.`}),o(`div`,{className:`mt-3 grid grid-cols-1 gap-3 sm:grid-cols-3`,children:ct.map(e=>{let t=f.get(e.locationType)??[];return n(`div`,{className:`space-y-1`,children:[o(`label`,{htmlFor:`migration-dest-${e.id}`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e.label}),n(`select`,{id:`migration-dest-${e.id}`,value:i[e.id]??``,onChange:t=>{let n=t.target.value;s(t=>({...t,[e.id]:n}))},disabled:h,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,children:[o(`option`,{value:``,children:`— unchanged —`}),t.map(e=>o(`option`,{value:e.id,children:e.displayName},e.id))]})]},e.id)})}),u&&o(`p`,{className:`mt-2 text-[11px] text-danger`,children:u}),n(`div`,{className:`mt-3 flex items-center gap-2`,children:[n(`button`,{type:`button`,onClick:()=>{C()},disabled:!v||y.isFetching||h,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[y.isFetching&&o(z,{className:`h-3 w-3 animate-spin`}),`Plan`]}),n(`button`,{type:`button`,onClick:()=>{w()},disabled:!v||b.isPending||h,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[b.isPending&&o(z,{className:`h-3 w-3 animate-spin`}),`Start migration`]})]}),c&&o(`div`,{className:`mt-3 divide-y divide-border rounded-md border border-border`,children:c.moves.length===0?o(`p`,{className:`px-2.5 py-1.5 text-[11px] text-foreground-subtle`,children:`Nothing to move — selected destinations match the current defaults.`}):c.moves.map(e=>n(`div`,{className:`px-2.5 py-1.5 text-[11px] text-foreground`,children:[e.storageClass,`: `,e.fromLocationId,` → `,e.toLocationId]},`${e.storageClass}-${e.toLocationId}`))})]}),m&&n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[n(`div`,{className:`flex items-center justify-between`,children:[o(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Migration status`}),h&&n(`button`,{type:`button`,onClick:()=>{E()},className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,children:[o(W,{className:`h-3 w-3`}),`Cancel`]})]}),n(`p`,{className:`mt-1 text-xs text-foreground`,children:[`Phase: `,o(`span`,{className:`font-medium`,children:m.phase}),h&&o(z,{className:`ml-2 inline h-3 w-3 animate-spin text-primary`})]}),m.error&&o(`p`,{className:`mt-1 text-[11px] text-danger`,children:m.error}),m.pausedParticipants.length>0&&n(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:[`Paused: `,m.pausedParticipants.join(`, `)]}),o(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:m.moves.map(e=>n(`div`,{className:`flex items-center justify-between px-2.5 py-1.5 text-[11px]`,children:[n(`span`,{className:`text-foreground`,children:[e.storageClass,`: `,e.fromLocationId,` → `,e.toLocationId]}),n(`span`,{className:`text-foreground-subtle`,children:[e.state??`pending`,e.error?` (${e.error})`:``]})]},e.storageClass))})]})]})}function ft(){return n(`div`,{className:`flex flex-col gap-8`,children:[n(`div`,{children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Recording`}),o(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The cluster recording node and recordings folders.`}),n(`div`,{className:`mt-3 flex flex-col gap-6`,children:[o($e,{}),o(tt,{})]})]}),n(`div`,{children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Events`}),o(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The cluster post-processing node, the events folder, and the durable event-store footprint with retention and per-camera deletion.`}),n(`div`,{className:`mt-3 flex flex-col gap-6`,children:[o(Ze,{}),o(at,{})]})]}),n(`div`,{children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Migration`}),o(`div`,{className:`mt-3`,children:o(ut,{})})]})]})}function pt(){return o(ce,{icon:U,title:`Recordings`,subtitle:`Recording node & storage, event-store management, exported clips, and an activity log.`,children:o(de,{tabs:[{id:`storage`,label:`Storage`,icon:R,content:o(Ue,{})},{id:`cameras`,label:`Cameras`,icon:se,content:o(ge,{})},{id:`exports`,label:`Export`,icon:U,content:o(Ae,{})},{id:`activity`,label:`Activity`,icon:B,content:o(qe,{})},{id:`management`,label:`Management`,icon:he,content:o(ft,{})}]})})}export{pt as RecordingsPage};
@@ -1 +0,0 @@
1
- import{K as e}from"./index-LPwis6Rq.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};