@camstack/addon-admin-ui 1.2.239 → 1.2.241
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonCollectionPage-BV7aaMkq.js → AddonCollectionPage-CPzP90Sz.js} +1 -1
- package/dist/assets/{Addons-Cj81M5KZ.js → Addons-c55q7WBD.js} +1 -1
- package/dist/assets/{AdminTabs-DEfwmg7J.js → AdminTabs-BBJ7jPxq.js} +1 -1
- package/dist/assets/{AiProfiles-CkAmIj0T.js → AiProfiles-B7c5cAds.js} +1 -1
- package/dist/assets/{BrokerForm-Cfq9tbeM.js → BrokerForm-CjzPXMn-.js} +1 -1
- package/dist/assets/{Build-wgvt3FMi.js → Build-DsZht5dX.js} +3 -3
- package/dist/assets/{Capabilities-CiBLSagx.js → Capabilities-J581t3Nh.js} +1 -1
- package/dist/assets/{CapabilityBadges-C3F7PbgI.js → CapabilityBadges-DZbYF5Qj.js} +1 -1
- package/dist/assets/Cluster-Bp8uM1av.js +11 -0
- package/dist/assets/{Data-CluTzC7W.js → Data-B2AyPjl0.js} +1 -1
- package/dist/assets/{DetectionIntelligence-tJqqQwnq.js → DetectionIntelligence-D24fQEjJ.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-Bq4Md-AC.js → DeviceAggregateSection-CQKNWzaO.js} +1 -1
- package/dist/assets/DeviceDetail-BGkhAFsw.js +2 -0
- package/dist/assets/{Devices-CDiHLL9j.js → Devices-Cl7mJSkh.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Cy339_lT.js → EmbedPlayerPage-xMtg8dSc.js} +1 -1
- package/dist/assets/{Events-DgHZE5DW.js → Events-BGaxZ1o4.js} +1 -1
- package/dist/assets/{FormBuilder-CXPDgzlb.js → FormBuilder-B5NjssfC.js} +1 -1
- package/dist/assets/{Identity-OfYueUHQ.js → Identity-Dfvd4HYK.js} +1 -1
- package/dist/assets/{IntegrationDetail-DU3BkGtn.js → IntegrationDetail-DU3XoWGa.js} +1 -1
- package/dist/assets/{Integrations-BSwMK9_P.js → Integrations-DqKp6hou.js} +1 -1
- package/dist/assets/{Integrations-9h7B10Zc.js → Integrations-DuD_b26E.js} +1 -1
- package/dist/assets/{Locations-_qYBN1T4.js → Locations-2CtGZRPs.js} +1 -1
- package/dist/assets/{Logs-BIdrbtHw.js → Logs-BF3mYvyF.js} +1 -1
- package/dist/assets/{MotionZonesSettings-Bmfoa3wn.js → MotionZonesSettings-BMRYYoK9.js} +1 -1
- package/dist/assets/{MyAccess-DDokzZ_G.js → MyAccess-DFzBCtfp.js} +1 -1
- package/dist/assets/{Network-8oXubZzz.js → Network-4cmnTv5u.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-Dxm-H5kR.js → NodeAddonsSettingsPanel-cSTrVHPI.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-CMLzoOnF.js → NodeInferenceDevices-CPpY6_cy.js} +1 -1
- package/dist/assets/{Notifications-Cz6qIRYD.js → Notifications-ASkipxGP.js} +1 -1
- package/dist/assets/Pipeline-Fyvy8LaK.js +1 -0
- package/dist/assets/{Plates-C-8OJd0O.js → Plates-BqSXeDxI.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-Bui3ib7h.js → PrivacyMaskSettings-DtG28LRw.js} +1 -1
- package/dist/assets/{ProviderIcon-BLzV3Bvb.js → ProviderIcon-D-MY_sIG.js} +1 -1
- package/dist/assets/Recordings-BEKd1C0t.js +1 -0
- package/dist/assets/{ScanNetworkModal-BK2Efo11.js → ScanNetworkModal-B0i4YX83.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-CpFyCs93.js → SceneMonitorEditor-DwYozJtC.js} +1 -1
- package/dist/assets/{Scenes-O9rZLPNg.js → Scenes-DMjUrdAE.js} +1 -1
- package/dist/assets/SchemaTabBar-Bvm8GY8a.js +1 -0
- package/dist/assets/{Settings-DNTO-HO1.js → Settings-BNX7swem.js} +1 -1
- package/dist/assets/{Showroom-DYIc2e74.js → Showroom-CbueHfqn.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-qfEwA1kH.js → StorageLocationsPanel-BrAyBn3h.js} +1 -1
- package/dist/assets/{Terminal-DFxh8JU-.js → Terminal-8ezuJ8tH.js} +1 -1
- package/dist/assets/{Viewer-CYHrV_oi.js → Viewer-B5hxPps2.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BLAyZ-mq.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CnOmilcl.js} +1 -1
- package/dist/assets/{archive-TK7Z0TuZ.js → archive-C4exqh8O.js} +1 -1
- package/dist/assets/{authed-media-DOUf-JTf.js → authed-media-Da70zq2N.js} +1 -1
- package/dist/assets/{bell-off-KAZIl_2Q.js → bell-off-CAEq4a9m.js} +1 -1
- package/dist/assets/{boxes-C8dHkgXX.js → boxes-BmVWLRTr.js} +1 -1
- package/dist/assets/circle-slash-OoLNC_6k.js +1 -0
- package/dist/assets/{debounced-invalidate-tZ5rAcre.js → debounced-invalidate-DDX0GYw7.js} +1 -1
- package/dist/assets/{dist-9faQP10_.js → dist-BpdyETtj.js} +20 -20
- package/dist/assets/{dist-V1UBFaGo.js → dist-ClDQb6R0.js} +1 -1
- package/dist/assets/{face-bbox-CfIjQr1Q.js → face-bbox-DYErDEYb.js} +1 -1
- package/dist/assets/{hard-drive-download-CWTNc0_2.js → hard-drive-download-CkV3AW1R.js} +1 -1
- package/dist/assets/{hostInit-C4S7oBju.js → hostInit-BXsi6Obr.js} +1 -1
- package/dist/assets/{index-K_FwjgDL.js → index-C7fxxePN.js} +3 -3
- package/dist/assets/{key-round-BabAOAzk.js → key-round-2afL45nn.js} +1 -1
- package/dist/assets/{layers-DPT8Evsd.js → layers-C2Df53wj.js} +1 -1
- package/dist/assets/{location-owned-usage-Bwv0EIw9.js → location-owned-usage-De8bGNuR.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-5ec0e0b7.js → mf-entry-bootstrap-0-e94df295.js} +2 -2
- package/dist/assets/{player-overlays-FVdyuBBK.js → player-overlays-BBc72WM3.js} +1 -1
- package/dist/assets/remoteEntry-BB2YW2J6.js +1 -0
- package/dist/assets/{send-XcOB_1Q8.js → send-C8Vx2lBu.js} +1 -1
- package/dist/assets/{settings-2-DHhHg_JG.js → settings-2-BFAg0J5u.js} +1 -1
- package/dist/assets/{square-check-big-BysRo6ev.js → square-check-big-D4waDUkC.js} +1 -1
- package/dist/assets/{src-DHelZti5.js → src-DEiKyLTJ.js} +4 -4
- package/dist/assets/{src-9HRd-uhT.js → src-qpAVbSCx.js} +12 -12
- package/dist/assets/{use-scenes-feed-C2J2fFKp.js → use-scenes-feed-Bss9Qeu6.js} +1 -1
- package/dist/assets/{use-stationary-objects-C9Mkrv-y.js → use-stationary-objects-BsG58WbN.js} +1 -1
- package/dist/assets/useEventInvalidation-DT98E0uw.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BVqLrJj_.js → useNodeUrlSelection-D6sLKsvE.js} +1 -1
- package/dist/assets/user-round-BzVozCoR.js +1 -0
- package/dist/assets/{video-CiDdAauf.js → video-BBVppgXo.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-f5hJ4IQO.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-C5xixG4o.js} +2 -2
- package/dist/index.html +5 -5
- package/dist/server/addon.js +21 -1
- package/package.json +1 -1
- package/dist/assets/Cluster-COFs2vG4.js +0 -11
- package/dist/assets/DeviceDetail-DuapKSk6.js +0 -2
- package/dist/assets/Pipeline-_5i83nUi.js +0 -1
- package/dist/assets/Recordings-qqScfY6t.js +0 -1
- package/dist/assets/SchemaTabBar-DC28nb9j.js +0 -1
- package/dist/assets/circle-slash-BkAoj1n7.js +0 -1
- package/dist/assets/remoteEntry-_L7Rd7sm.js +0 -1
- package/dist/assets/useEventInvalidation-CyI4_SVY.js +0 -1
- package/dist/assets/user-round-BRfK5EMf.js +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{G as f,U as p,W as m,X as h,_ as g,_t as _,at as v,gt as y,lt as b,q as x,r as S,st as C,t as w}from"./player-overlays-FVdyuBBK.js";import{$c as T,$l as E,$t as D,A as ee,B as O,Bt as te,Cc as k,D as A,Do as ne,Ea as j,Eo as re,Er as M,Fr as N,G as P,H as F,I as ie,J as ae,Ji as I,Jl as L,Jo as oe,Jr as se,Jt as R,K as z,Kl as B,M as ce,No as le,O as V,P as H,Qc as ue,Qr as de,Qt as fe,Rc as pe,Rl as U,Rr as me,Rt as he,Sc as W,Ta as G,Tr as ge,Ur as _e,V as ve,Vi as ye,Vt as K,W as be,Wr as q,X as xe,Xr as Se,Y as J,Yc as Ce,Yi as we,Zr as Te,Zt as Ee,_i as De,_l as Oe,_t as ke,_u as Ae,a as je,an as Me,ao as Ne,au as Pe,b as Fe,bt as Ie,c as Le,cl as Re,ct as ze,d as Be,dl as Ve,el as He,es as Ue,f as We,fc as Ge,fi as Ke,ft as qe,gt as Je,ht as Ye,i as Xe,in as Ze,is as Qe,j as $e,k as et,l as tt,ll as nt,ln as rt,lt as it,mo as at,mt as ot,nl as st,nt as ct,o as lt,oi as ut,ol as dt,on as ft,ou as pt,pi as mt,pl as ht,pt as gt,q as _t,qc as vt,qi as yt,qr as Y,r as bt,ri as xt,rt as St,s as Ct,so as wt,ti as Tt,tr as Et,u as Dt,ul as Ot,uo as kt,ut as At,v as jt,vi as Mt,vl as Nt,vt as Pt,wc as Ft,wl as It,x as Lt,xi as Rt,y as zt,ya as Bt,yc as Vt,yi as Ht,z as Ut,zl as Wt,zn as Gt,zt as Kt}from"./src-DHelZti5.js";import{t as qt}from"./archive-TK7Z0TuZ.js";import{t as Jt}from"./bell-off-KAZIl_2Q.js";import{t as Yt}from"./boxes-C8dHkgXX.js";import{t as Xt}from"./ProviderIcon-BLzV3Bvb.js";import{t as Zt}from"./circle-slash-BkAoj1n7.js";import{c as Qt,n as $t,s as en}from"./NodeInferenceDevices-CMLzoOnF.js";import{t as tn}from"./layers-DPT8Evsd.js";import{t as nn}from"./CapabilityBadges-C3F7PbgI.js";import{Jt as rn,Xt as an,Yt as on,Zt as sn,a as cn,bt as X,i as ln,qt as un,vt as dn}from"./src-9HRd-uhT.js";import{a as fn,c as pn,n as mn,o as hn,s as gn,u as _n}from"./index-K_FwjgDL.js";import{t as vn}from"./authed-media-DOUf-JTf.js";import"./useEventInvalidation-CyI4_SVY.js";import{t as yn}from"./StatusBadge-CeptlsPG.js";import{t as bn}from"./use-stationary-objects-C9Mkrv-y.js";import{i as xn,n as Sn,r as Cn,t as wn}from"./DeviceAggregateSection-Bq4Md-AC.js";var Tn=_(`arrow-left-right`,[[`path`,{d:`M8 3 4 7l4 4`,key:`9rb6wj`}],[`path`,{d:`M4 7h16`,key:`6tx8e3`}],[`path`,{d:`m16 21 4-4-4-4`,key:`siv7j2`}],[`path`,{d:`M20 17H4`,key:`h6l3hr`}]]),En=_(`disc`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),Dn=_(`ear`,[[`path`,{d:`M6 8.5a6.5 6.5 0 1 1 13 0c0 6-6 6-6 10a3.5 3.5 0 1 1-7 0`,key:`1dfaln`}],[`path`,{d:`M15 8.5a2.5 2.5 0 0 0-5 0v1a2 2 0 1 1 0 4`,key:`1qnva7`}]]);n();var On=[{id:`object-detection`,label:`Object detection`,costWhenOff:`No detections, tracks or detection-driven notifications for this camera.`,capName:on},{id:`audio-analysis`,label:`Audio analysis`,costWhenOff:`No audio events (glass, alarm, speech) and no audio-driven notifications.`,capName:un},{id:`event-saving`,label:`Event saving`,costWhenOff:`No tracks, events or event media are written for this camera — detection still runs, the timeline stays empty, and anything that fires on an event has nothing to fire on.`,capName:an}],kn=`Recording`,An=`Nothing new is written to disk — live still works, existing footage is kept.`;function jn(e,t){let{bindings:n,bindable:r}=t,i=n===null?void 0:n.find(t=>t.capName===e.capName&&t.kind===`wrapped`),a=r?.find(t=>t.capName===e.capName)?.wrappers[0],o=i!==void 0&&i.providerAddonId!==``?i.providerAddonId:a??null,s=n===null?null:i!==void 0;return{id:e.id,label:e.label,costWhenOff:e.costWhenOff,on:s,available:s!==null&&o!==null,capName:e.capName,wrapperAddonId:o}}function Mn(e,t,n,r){let i=e.entries.filter(e=>e.capName!==t);return r?{...e,entries:[...i,{capName:t,kind:`wrapped`,providerAddonId:n}]}:{...e,entries:i}}function Nn(e,t){let n=e.filter(e=>e.on===!1).map(e=>e.id),r=e.filter(e=>e.on===null).map(e=>e.id),i=t=>t.map(t=>e.find(e=>e.id===t)?.label??t).join(`, `),a=[];return n.length>0&&a.push(`Off: ${i(n)}`),r.length>0&&a.push(`Unknown: ${i(r)}`),{layout:t?`menu`:`inline`,offIds:n,unknownIds:r,summary:a.length===0?`All camera functions on`:a.join(` · `)}}function Pn(e){let t=On.map(t=>jn(t,e)),n={id:`recording`,label:kn,costWhenOff:An,on:e.recordingEnabled,available:e.recordingEnabled!==null,capName:null,wrapperAddonId:null};return[...t,n]}var Fn={"object-detection":_n,"audio-analysis":Dn,"event-saving":qt,recording:En};function In(e){if(typeof e!=`object`||!e)return!1;let t={...e};return typeof t.enabled==`boolean`&&Array.isArray(t.bands)}function Ln(e){if(typeof e!=`object`||!e)return!1;let t={...e};return typeof t.deviceId==`number`&&Array.isArray(t.entries)}function Rn(e){return Ln(e)?e.entries:null}function zn(e){if(!Array.isArray(e))return null;let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e={...n},r=e.capName,i=e.wrappers;typeof r!=`string`||!Array.isArray(i)||t.push({capName:r,wrappers:i.filter(e=>typeof e==`string`)})}return t}function Bn({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(!1),f=q({deviceId:t},{enabled:i}),p=de({deviceType:X.Camera},{enabled:i}),m=Ue({deviceId:t},{enabled:i,retry:!1});bt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let h=[[`deviceManager`,`getBindings`],{input:{deviceId:t}}],g=[[`recording`,`getDeviceConfig`],{input:{deviceId:t}}],_=m.data,v=In(_)?_:null,y=Pn({bindings:Rn(f.data),bindable:zn(p.data),recordingEnabled:v===null?null:v.enabled}),b=Rt({onError:(e,r)=>{let i=y.find(e=>e.capName===r.capName)?.id??`object-detection`;console.error(`[CameraFunctionSwitches] wrapper write failed — reverting`,{tags:{deviceId:t},meta:{capName:r.capName,error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]}),o({id:i,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]})}}),x=Qe({onError:e=>{console.error(`[CameraFunctionSwitches] recording write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`recording`,`getDeviceConfig`]]}),o({id:`recording`,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`recording`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]})}}),S=e(e=>{if(!e.available||e.on===null)return;let r=!e.on;if(e.id===`recording`){if(v===null)return;n.setQueryData(g,{...v,enabled:r}),x.mutate({deviceId:t,config:{...v,enabled:r}});return}let{capName:i,wrapperAddonId:a}=e;if(i===null||a===null)return;let o=n.getQueryData(h);Ln(o)&&n.setQueryData(h,Mn(o,i,a,r)),b.mutate({deviceId:t,capName:i,wrapperAddonId:a,active:r})},[h,t,n,v,g,x,b]),C=Nn(y,Ie()),w=e=>a?.id===e.id?a.message:null;return C.layout===`menu`?r(Je,{open:l,onOpenChange:d,children:[r(Pt,{"aria-label":`Camera functions`,title:C.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${a===null?C.offIds.length>0?`border-warning/40 text-warning hover:bg-warning/10`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(pe,{className:`h-3.5 w-3.5`}),C.offIds.length>0&&r(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:[C.offIds.length,` off`]})]}),r(ke,{className:`left-auto right-0 mt-1 min-w-[240px] p-1`,children:[u(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Camera functions`}),u(`ul`,{className:`space-y-0.5`,children:y.map(e=>u(`li`,{children:u(Vn,{state:e,failure:w(e),onToggle:()=>S(e)})},e.id))})]})]}):u(`div`,{className:`flex items-center gap-1`,children:y.map(e=>u(Hn,{state:e,failure:w(e),onToggle:()=>S(e)},e.id))})}function Vn({state:e,failure:t,onToggle:n}){let i=Fn[e.id],a=e.on===null,o=e.on===!1;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:a?`${e.label} — state unknown; the source that owns it did not answer.`:t===null?e.costWhenOff:`Last write failed: ${t}`,className:`flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-[12px] text-foreground transition-colors hover:bg-surface-hover disabled:opacity-40 disabled:cursor-not-allowed`,children:[u(i,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 ${t===null?a?`text-foreground-subtle/50`:o?`text-warning`:`text-success`:`text-danger`}`}),r(`span`,{className:`flex-1 min-w-0`,children:[u(`span`,{className:`block leading-tight`,children:e.label}),u(`span`,{className:`block mt-0.5 text-[10px] text-foreground-subtle leading-tight`,children:t===null?a?`Unknown`:e.costWhenOff:`Write failed: ${t}`})]}),u(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${a?`bg-surface-hover text-foreground-subtle/60`:o?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:a?`—`:o?`off`:`on`})]})}function Hn({state:e,failure:t,onToggle:n}){let i=Fn[e.id],a=e.on===null,o=e.on===!1,s=a?`${e.label} — state unknown; the source that owns it did not answer.`:o?`${e.label} is OFF. ${e.costWhenOff}`:`${e.label} is on. Turning it off: ${e.costWhenOff}`;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:t===null?s:`${s} — last write failed: ${t}`,className:`inline-flex items-center gap-1 rounded-lg border px-1.5 sm:px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${t===null?a?`border-dashed border-border text-foreground-subtle/50`:o?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(i,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden lg:inline`,children:e.label}),o&&u(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:`off`})]})}function Un({parentDeviceId:e}){let{t}=mn(),n=fn(),i=v(),{data:a,isLoading:o,isError:s}=Qt(e),{data:c}=Y({deviceId:e},{enabled:Number.isFinite(e)});if(o)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(a??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let d=et(c?.stableId??``,l,c?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=(e,t)=>u(A,{trpc:i.trpcClient,device:{...t,name:ce(t,m)},variant:`minimal`,onNavigate:p},e),g=f.some(e=>!!e.role),_=f.some(e=>!e.role),y=g&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),b=f.length>0?r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[u(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:y}),u(`div`,{className:`space-y-1`,children:f.map(e=>h(e.id,e))})]}):null,x=d.disabledSection===void 0?null:u(V,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:u(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>h(e.id,e))})},d.disabledSection.title);if(d.sections.length===0)return x===null?b:r(`div`,{className:`space-y-2`,children:[b,x]});let S=_&&!g;return r(`div`,{className:`space-y-2`,children:[S?b:null,d.sections.map(e=>u(V,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),S?null:b,x]})}function Wn({deviceId:e}){let t=v(),{data:n,isLoading:r}=en(e),{data:i,isLoading:a}=Qt(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?u(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):u(`div`,{className:`flex h-full w-full flex-col`,children:u(O,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}n();function Gn({dev:e,busy:t,setBusy:n}){let i=e?.motionTrigger,a=x(e?.state.motionTrigger),[o,s]=c(!1);if(!i)return null;let l=a?.enabled===!0,d=a!==void 0,f=async()=>{if(t||!d)return;let e=!l;n(!0),s(!0);try{await i.setMotionTrigger({enabled:e})}finally{n(!1),s(!1)}};return r(`button`,{type:`button`,onClick:()=>{f()},disabled:t||!d,title:d?l?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":l,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${l?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[u(Ae,{className:`h-3 w-3`}),u(`span`,{children:o?l?`Disabling…`:`Enabling…`:d?l?`On motion: on`:`On motion: off`:`On motion: …`})]})}n();function Z({deviceId:e,deviceType:t,features:n}){let i=v(),a=be(t)?.HeroCard??P,o=f(i.trpcClient,e),s=x(o?.state.deviceStatus),[l,d]=c(!1),p=s!==void 0&&s.online===!1,m=p?s.lastChangedAt:null;return r(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[p?u(`div`,{className:`flex justify-center`,children:u(F,{lastChangedAt:m})}):null,u(a,{trpc:i.trpcClient,deviceId:e,features:n}),u(`div`,{className:`flex justify-center`,children:u(Gn,{dev:o,busy:l,setBusy:d})})]})}function Kn({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:u(z,{trpc:v().trpcClient,deviceId:e,features:t})})}function qn({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:u(P,{trpc:v().trpcClient,deviceId:e,features:t})})}function Jn(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Yn(e){if(!e)return null;let t=Jn(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var Xn=1e3,Zn=60*Xn,Qn=60*Zn,$n=24*Qn;function er(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Xn?`just now`:n<Zn?`${String(Math.floor(n/Xn))}s ago`:n<Qn?`${String(Math.floor(n/Zn))}m ago`:n<$n?`${String(Math.floor(n/Qn))}h ago`:`${String(Math.floor(n/$n))}d ago`}n();var tr=1500,nr=15e3,rr=1e3;function ir({deviceId:e}){let n=f(v().trpcClient,e)?.state.eventEmitter,i=x(n);d(()=>{if(!n)return;n.refresh();let e=setInterval(()=>{n.refresh()},nr);return()=>{clearInterval(e)}},[n]);let a=i?.lastEvent??null,o=a?.seq??null,s=t(null),[l,p]=c(!1);d(()=>{if(o===null)return;let e=s.current;if(s.current=o,e===null||e===o)return;p(!0);let t=setTimeout(()=>{p(!1)},tr);return()=>{clearTimeout(t)}},[o]);let[m,h]=c(()=>Date.now());d(()=>{let e=setInterval(()=>{h(Date.now())},rr);return()=>{clearInterval(e)}},[]);let g=Yn(a),_=i?.eventTypes??[],y=i?.eventCountSinceStart??0,b=i!==void 0,S=Jn(a?.data);return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[u(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(l),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${l?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:g??`No press recorded`,children:u(l?nt:It,{className:`h-10 w-10`})}),r(`div`,{className:`text-center`,children:[S!==null&&u(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:`Button ${String(S)}`}),u(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${g?`text-foreground`:`text-foreground-subtle`}`,children:g??(b?`No press recorded`:`Awaiting state…`)}),u(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a?er(a.timestamp,m):`Waiting for the first event`})]}),_.length>0&&u(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:_.map(e=>u(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===a?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(y)} ${y===1?`event`:`events`} since start`})]})}function ar({deviceName:e,deviceType:t,provider:n,isOnline:i,features:a}){return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[u(Xt,{type:n,size:`lg`}),r(`div`,{children:[u(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),u(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),r(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[u(yn,{status:i?`online`:`offline`}),a.length>0&&u(nn,{capabilities:a})]}),u(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}n();function or({deviceId:e}){let t=s(),n=ge({deviceId:e},{refetchInterval:1e4,retry:!1}),a=M({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),o=i(()=>sr(n.data??[]),[n.data]);return r(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[r(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[u(cr,{label:`Discovered`,value:o.total,icon:u(Re,{className:`h-3.5 w-3.5`})}),u(cr,{label:`Adopted`,value:o.adopted,accent:`success`}),u(cr,{label:`Available`,value:o.available,accent:o.available>0?`primary`:void 0}),r(`button`,{type:`button`,onClick:()=>{a.mutateAsync({deviceId:e}).catch(()=>{})},disabled:a.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[a.isPending?u(Oe,{className:`h-3.5 w-3.5 animate-spin`}):u(T,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[u(lr,{icon:u(W,{className:`h-3 w-3 text-emerald-500`}),label:`${o.online} online`}),u(lr,{icon:u(Ot,{className:`h-3 w-3 text-amber-500`}),label:`${o.sleeping} sleeping`}),u(lr,{icon:u(k,{className:`h-3 w-3 text-destructive`}),label:`${o.offline} offline`}),o.unknown>0?u(lr,{icon:u(B,{className:`h-3 w-3 text-foreground-subtle`}),label:`${o.unknown} unknown`}):null]})]})}function sr(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function cr({label:e,value:t,icon:n,accent:i}){return r(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${i===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:i===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[r(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,u(`span`,{className:`truncate`,children:e})]}),u(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function lr({icon:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1`,children:[e,u(`span`,{children:t})]})}var ur={[X.Switch]:Z,[X.Siren]:Z,[X.Light]:Z,[X.Sensor]:Z,[X.Button]:Z,[X.Hub]:or,[X.Cover]:Kn,[X.Valve]:Z,[X.Humidifier]:Z,[X.WaterHeater]:Z,[X.Container]:Wn,[X.Lock]:Z,[X.Fan]:Z,[X.Thermostat]:Z,[X.Climate]:Z,[X.MediaPlayer]:Z,[X.Control]:Z,[X.AlarmPanel]:Z,[X.EventEmitter]:ir,[X.Notifier]:qn,[X.Script]:Z,[X.Automation]:Z,[X.Presence]:Z,[X.Update]:Z,[X.Vacuum]:Z,[X.LawnMower]:Z,[X.Weather]:Z,[X.Image]:Z,[X.PetFeeder]:Z};function dr(e){return ur[e]??ar}function fr(e){return u(dr(e.deviceType),{...e})}function pr(e){return Ct(v().trpcClient,e)}n();function mr(n){let[r,i]=c(`idle`),[a,o]=c(null),s=t(null),l=t(null),u=t(null),f=t(!0),p=I(),m=yt(),h=we(),g=e(()=>{if(s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null},[]),_=e(async()=>{if(r===`idle`)return;i(`stopping`);let e=u.current;if(e&&n!==null)try{await Promise.race([h.mutateAsync({deviceId:n,sessionId:e}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(i(`idle`),o(null))},[r,n,h,g]),v=e(async()=>{if(n===null||r!==`idle`&&r!==`error`)return;o(null);let e=null,t=null,a=null;try{i(`requesting-mic`),e=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),l.current=e,i(`starting`);let r=await p.mutateAsync({deviceId:n});a=r.sessionId,u.current=a,i(`connecting`),t=new RTCPeerConnection,s.current=t,t.oniceconnectionstatechange=()=>{if(!f.current)return;let e=t.iceConnectionState;e===`connected`||e===`completed`?i(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(o(e===`failed`?`WebRTC connection failed`:null),_())};for(let n of e.getAudioTracks())t.addTrack(n,e);await t.setRemoteDescription({type:`offer`,sdp:r.sdpOffer});let c=await t.createAnswer();await t.setLocalDescription(c);let d=t.localDescription?.sdp??c.sdp??``;await m.mutateAsync({deviceId:n,sessionId:a,sdpAnswer:d})}catch(r){let c=r instanceof Error?r.message:String(r);if(console.warn(`[intercom] start failed`,r),t)try{t.close()}catch{}if(e)for(let t of e.getTracks())try{t.stop()}catch{}if(s.current=null,l.current=null,a!==null)try{await h.mutateAsync({deviceId:n,sessionId:a})}catch{}u.current=null,f.current&&(o(c),i(`error`))}},[n,r,p,m,h,_]);return d(()=>(f.current=!0,()=>{f.current=!1;let e=u.current;if(e!==null&&n!==null&&h.mutate({deviceId:n,sessionId:e}),s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null}),[n]),{state:r,error:a,start:v,stop:_,isTalking:r===`talking`}}n();var hr=0;function Q(){return++hr}function gr(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function _r(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function vr(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function yr(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function br({scope:n,greeting:i,className:a}){let o=v(),[s,f]=c(()=>{let e=[];return i&&e.push({id:Q(),kind:`info`,text:i}),e.push({id:Q(),kind:`info`,text:`scope: ${gr(n)} — type help or context for available commands`}),e}),[p,m]=c(``),[h,g]=c([]),[_,y]=c(-1),b=t(null),x=t(null);d(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[s]);let S=e(()=>{b.current?.focus()},[]),C=l({mutationFn:e=>o.trpcClient.repl.execute.mutate({code:e,scope:n}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;f(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);f(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function w(e){let t=e.trim();if(t){if(t===`clear`){f([{id:Q(),kind:`info`,text:`scope: ${gr(n)}`}]),m(``);return}if(t===`help`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},..._r(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}if(t===`context`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...yr(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}if(t===`examples`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...vr(n).map(e=>({id:Q(),kind:`info`,text:e}))]),m(``);return}g(e=>[...e,t]),y(-1),f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`}]),m(``),C.mutate(t)}}function T(e){if(e.key===`Enter`){e.preventDefault(),w(p);return}if(e.key===`ArrowUp`){if(e.preventDefault(),h.length===0)return;let t=_===-1?h.length-1:Math.max(0,_-1);y(t),m(h[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),_===-1)return;let t=_+1;t>=h.length?(y(-1),m(``)):(y(t),m(h[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),f([{id:Q(),kind:`info`,text:`scope: ${gr(n)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return r(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${a??``}`,onClick:S,children:[r(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[s.map(e=>u(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&u(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),r(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[u(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),u(`input`,{ref:b,value:p,onChange:e=>m(e.target.value),onKeyDown:T,disabled:C.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}n();function xr({deviceId:e,intercomAvailable:t=!1}){let n=v(),r=typeof window<`u`?h():``,a=Number.isFinite(e),s=pr(a?e:null),c=bn(a?[e]:[]),l=i(()=>{if(!a)return;let e=[];for(let t of c.rows){let n=lt(t);n!==null&&e.push(n)}return e},[a,c.rows]),{streams:d,pipelineMetrics:f,createSession:p,sendAnswer:g,handleOffer:_,getIceServers:y,addIceCandidate:b,getIceCandidates:x,closeSession:C,getSessionState:w}=je(n.trpcClient,a?e:null),T=m(a?e:null,{width:Er}),E=mr(a&&t?e:null),ee=E.state===`requesting-mic`||E.state===`starting`||E.state===`connecting`||E.state===`stopping`,O=E.isTalking||ee,te=()=>{E.state===`idle`||E.state===`error`?E.start():E.state!==`stopping`&&E.stop()},k=S(),A=D(),ne=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,j=k.length>0?u(o,{children:k.map(e=>u(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return u(Dt,{serverUrl:r,createSession:p,sendAnswer:g,handleOffer:_,getIceServers:y,addIceCandidate:b,getIceCandidates:x,closeSession:C,getSessionState:w,...A.request?{playbackUrl:A.request.url,playbackAuthToken:ne,...A.request.label?{playbackLabel:A.request.label}:{},onExitPlayback:()=>A.clear()}:{},streams:d,pipelineMetrics:f,phase:s.phase,detections:s,...l===void 0?{}:{stationaryObjects:l},defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:T.src,...T.src?{posterUrl:T.src}:{},snapshotLoading:T.loading,onRefreshSnapshot:T.refresh,intercomAvailable:t,intercomShown:O,onIntercomToggle:te,extraOverlay:j,chromeless:!0,className:`h-full`})}function Sr({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full`,children:u(xe,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Cr({deviceId:e}){if(!Number.isFinite(e))return r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
2
|
-
`);return u(br,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function wr({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(J,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Tr({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(ae,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}var Er=960,Dr=`overview`;function Or(e,t){return e.some(e=>e.id===t)?t:Dr}function kr({deviceId:e}){let t=s(),n=Number.isFinite(e),{data:i}=Y({deviceId:e},{enabled:n}),a=typeof i?.type==`string`?i.type:`camera`;bt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:c,isError:l,error:d}=q({deviceId:e},{enabled:n}),{data:f}=de({deviceType:a},{enabled:!!a}),p=Rt({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(c)return u(`div`,{className:`p-4`,children:u(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(l)return r(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,d instanceof Error?d.message:String(d)]});let m=new Map,h={};for(let e of f??[])h[e.capName]=e.wrappers;for(let e of o?.entries??[])m.set(e.capName,{...e,wrappers:h[e.capName]??[]});for(let e of f??[])m.has(e.capName)||m.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let g=[...m.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(g.length===0)return r(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[u(Yt,{className:`h-8 w-8 opacity-40`}),u(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),u(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let _=g.filter(e=>e.kind!==`unbound`).length;return r(`div`,{className:`flex flex-col gap-3 p-1`,children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:_}),` of `,g.length,` capabilit`,g.length===1?`y`:`ies`,` bound — rows marked `,u(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),u(St,{columns:[{key:`capability`,header:`Capability`,render:e=>u(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>u(Ar,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?u(jr,{nodeId:e.providerNodeId}):u(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return u(Mr,{wrappers:t.wrappers,activeWrapperId:n,disabled:p.isPending,onPick:r=>{let i=n===r;p.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:g,rowKey:e=>e.capName,minWidthPx:720})]})}function Ar({kind:e}){return e===`native`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(vt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(tn,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(Nt,{className:`h-3 w-3`}),`linked`]}):r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(Ve,{className:`h-3 w-3`}),`unbound`]})}function jr({nodeId:e}){return u(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function Mr({wrappers:e,activeWrapperId:t,disabled:n,onPick:i}){return e.length===0?u(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let a=e===t;return r(`button`,{disabled:n,onClick:()=>i(e),title:a?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${a?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(a?E:b,{className:`h-3 w-3`}),e]},e)})})}function Nr({deviceId:e,activeSubTab:t,onSubTabChange:n}){return u(`div`,{className:`flex flex-col gap-3`,children:u(wn,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}n();var Pr=new Set([`package-detection`]);function Fr(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 Ir(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function Lr({deviceId:e,refreshToken:t}){let n=s(),l=v().trpcClient,[d,f]=c(null),[p,m]=c(null),[h,g]=c(null),_=Ne({deviceId:e},{refetchOnMount:`always`}),y=wt({deviceId:e},{refetchOnMount:`always`}),b=at(void 0,{refetchOnMount:`always`});bt([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let{nodes:x}=Ge(),S=i(()=>{let e=new Set;for(let t of x)t.isOnline&&e.add(t.id);return e},[x]),C=i(()=>(b.data??[]).filter(e=>S.has(e.nodeId)).map(e=>e.nodeId),[b.data,S]),w=a({enabled:C.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`device-step-schemas`,C.join(`,`),t],queryFn:async()=>{let e={};for(let t of C)try{e[t]=await l.pipelineExecutor.getSchema.query({nodeId:t})}catch{}return e}}),T=e=>w.data?.[e]??null,E=i(()=>{let e=C[0];if(e!==void 0){let t=w.data?.[e];if(t)return t}return Object.values(w.data??{})[0]??null},[C,w.data]),D=a({enabled:C.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,C.join(`,`),t],queryFn:async()=>{let e={};for(let t of C)try{e[t]=(await l.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),ee=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},O=re({onSuccess:ee}),k=ne({onSuccess:ee}),A=i(()=>E?Be(E):[],[E]),j=i(()=>{let e=b.data??[],t=S.size===0?[]:e.filter(e=>S.has(e.nodeId)),n=[];for(let e of t){let t=(D.data?.[e.nodeId]??[]).filter(e=>e.enabled&&e.available);if(t.length>=2)for(let r of t)n.push({agentNodeId:e.nodeId,engineLabel:r.format,deviceKey:r.key,deviceLabel:$t(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[b.data,D.data,S]),M=(e,t)=>D.data?.[e]?.find(e=>e.key===t)??null,N=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=D.data?.[e.agentNodeId]??[],n=t.filter(e=>e.enabled&&e.available);return n.length>=1?n[0].key:t.find(e=>e.available)?.key??t[0]?.key??null},P=(e,t,n)=>y.data?.[e]?.[t]?.[n]??null,F=e=>{if(Pr.has(e))return{kind:`zone-driven`};let t=Fr(E,e)?.enabledByDefault??!0,n=_.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},ie=(e,t,n)=>{let r=Fr(T(n),e);if(r)return Kt(r,t)},ae=(e,t)=>{let n=F(e),r=n.kind===`gate`?n.effectiveOn:!1,i=Fr(T(t.agentNodeId),e),a=N(t),o=a===null?null:M(t.agentNodeId,a);if(!K(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:P(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?te({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:Ir(s)}},I=d===null?null:Fr(T(d.agentNodeId),d.addonId),L=d?M(d.agentNodeId,d.deviceKey):null,oe=L?.format??`coreml`,se=d?Ir(P(d.agentNodeId,d.deviceKey,d.addonId)):!1,R=d?ie(d.addonId,L,d.agentNodeId):void 0,z=i(()=>{if(!d||!L)return null;let e=L.steps?.[d.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[d,L]),B=()=>{f(null),m(null)},ce=(e,t)=>{let n=N(t);n!==null&&(f({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),m(P(t.agentNodeId,n,e)))},le=(t,n)=>{k.mutate({deviceId:e,addonId:t,enabled:n})},V=()=>{d&&O.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:p},{onSuccess:B})},H=()=>{d&&O.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:null},{onSuccess:B})};if(b.isLoading||C.length>0&&w.isLoading)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(j.length===0)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!E)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ue=d!==null&&I!==null&&L!==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:[u(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,u(`span`,{className:`font-medium text-foreground`,children:`node column`}),` shows the model that node runs; click a cell to pin a per-camera model override for that accelerator. A gated-on step with no model on a device shows a clickable `,u(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),r(`div`,{className:`rounded-md border border-sky-500/25 bg-sky-500/[0.06] px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-sky-400`,children:`Placement is dynamic.`}),` When a node has multiple inference accelerators, each session is balanced across them per-session at dispatch time — these device columns show each accelerator's effective model (override ?? device default), not a fixed assignment.`]}),u(`div`,{className:ue?`md:pr-[360px]`:``,children:A.length>0?u(Lt,{tree:A,agents:j,gateFor:F,getCellState:ae,onCellClick:ce,selectedCell:d,onSetGate:le,gateBusy:k.isPending,fallbackNodeId:h,onFallbackNodeChange:g}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(We,{open:ue,onClose:B,title:I?.name??``,subtitle:d&&L?`${d.agentNodeId} · ${$t(L).label} · ${L.format}`:``,footer:r(o,{children:[u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle disabled:opacity-50`,disabled:!se||O.isPending,onClick:H,children:`Clear override`}),u(`div`,{className:`flex-1`}),u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:B,children:`Cancel`}),u(`button`,{type:`button`,disabled:!d||!z||O.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:V,children:O.isPending?`Saving…`:`Save`})]}),children:I&&d&&z?u(he,{mode:`device`,addon:I,agentDefault:z,agentNodeId:d.agentNodeId,currentPatch:p,engineFormat:oe,effectiveModelId:R,onChangePatch:m}):u(`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.`})})]})}var Rr=[{id:`object-detection`,label:`Object detection`,icon:`scan-search`},{id:`tracking`,label:`Tracking`,icon:`route`},{id:`motion`,label:`Motion`,icon:`activity`},{id:`stationary`,label:`Stationary`,icon:`square-parking`},{id:`zones`,label:`Zones`,icon:`shapes`},{id:`audio`,label:`Audio`,icon:`volume-2`},{id:`cluster`,label:`Cluster`,icon:`server`}],zr={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,"onboard-object-detection":`object-detection`,tracking:`tracking`,"tracking-core":`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function Br(e){return zr[e]??`object-detection`}n();var Vr=`steps`,Hr=`settings`,Ur=new Set([Vr,Hr]);function Wr(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Gr({deviceId:t,activeSubTab:n,onSubTabChange:i}){return r(qe,{value:n&&Ur.has(n)?n:Vr,onValueChange:e(e=>{i?.(e)},[i]),className:`flex flex-col`,children:[r(ot,{className:`flex-shrink-0`,children:[u(Ye,{value:Vr,children:`Steps`}),u(Ye,{value:Hr,children:`Settings`})]}),u(gt,{value:Vr,children:u(Lr,{deviceId:t,refreshToken:0})}),u(gt,{value:Hr,children:u(wn,{deviceId:t,sectionFilter:Wr,subTabGrouping:{groupOf:e=>Br(e.id),tabs:Rr}})})]})}function $({label:e,value:t}){return r(`div`,{className:`${g} flex items-start gap-2 sm:gap-3`,children:[u(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),u(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}n();function Kr({deviceId:e,initialName:n}){let i=s(),[a,o]=c(!1),[l,f]=c(n),[p,m]=c(!1),h=t(null);d(()=>{a||f(n)},[n,a]),d(()=>{a&&h.current?.focus()},[a]);let g=De({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),i.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),_=async()=>{let t=l.trim();if(t.length===0||t===n){o(!1),f(n);return}m(!0);try{await g.mutateAsync({deviceId:e,name:t}),o(!1)}catch{}finally{m(!1)}},v=()=>{f(n),o(!1)};return a?u($,{label:`Name`,value:r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{ref:h,type:`text`,value:l,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`?_():e.key===`Escape`&&v()},disabled:p,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),u(`button`,{type:`button`,onClick:()=>void _(),disabled:p,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:u(E,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:v,disabled:p,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:u(Vt,{className:`h-3 w-3`})})]})}):u($,{label:`Name`,value:r(`div`,{className:`flex items-center gap-2 group`,children:[u(`span`,{className:`truncate`,children:n}),u(`button`,{type:`button`,onClick:()=>o(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:u(dt,{className:`h-3.5 w-3.5`})})]})})}n();function qr({deviceId:e,initialLocation:n}){let a=s(),[o,l]=c(!1),[f,p]=c(n??``),[m,h]=c(!1),g=t(null),{data:_}=Tt(void 0,{enabled:o}),v=_??[];d(()=>{o||p(n??``)},[n,o]),d(()=>{o&&g.current?.focus()},[o]);let y=mt({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),b=i(()=>{let e=f.trim().toLowerCase();return e.length===0?v:v.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[v,f]),x=f.trim().length>0&&!v.some(e=>e.toLowerCase()===f.trim().toLowerCase()),S=async t=>{let r=(t??f).trim(),i=r.length===0?null:r;if(i===(n??null)){l(!1);return}h(!0);try{await y.mutateAsync({deviceId:e,location:i}),l(!1)}catch{}finally{h(!1)}},C=()=>{p(n??``),l(!1)};return o?u($,{label:`Location`,value:r(`div`,{className:`relative`,children:[r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{ref:g,type:`text`,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`?S():e.key===`Escape`&&C()},disabled:m,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),u(`button`,{type:`button`,onClick:()=>void S(),disabled:m,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:u(E,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:C,disabled:m,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:u(Vt,{className:`h-3 w-3`})})]}),(b.length>0||x)&&r(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[b.map(e=>r(`button`,{type:`button`,onClick:()=>{p(e),S(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[u(ht,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),u(`span`,{className:`truncate`,children:e})]},e)),x&&r(`button`,{type:`button`,onClick:()=>void S(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[u(`span`,{className:`text-foreground-subtle`,children:`Create`}),r(`span`,{className:`font-medium truncate`,children:[`"`,f.trim(),`"`]})]})]})]})}):u($,{label:`Location`,value:r(`div`,{className:`flex items-center gap-2 group`,children:[n?u(`span`,{className:`truncate`,children:n}):u(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),u(`button`,{type:`button`,onClick:()=>l(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:u(dt,{className:`h-3.5 w-3.5`})})]})})}n();function Jr({deviceId:e}){let t=s(),{data:n}=en(e),{data:i}=Qt(e),[a,l]=c(null),d=Mt({onSuccess:()=>{l(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{l(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==X.Container)return null;let f=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(f.length<=1)return null;let p=ve(f,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return r(o,{children:[u($,{label:`Primary child`,value:u(Ut,{childrenList:f,selectedId:p===null?f[0].id:p.id,onSetPrimary:t=>d.mutate({deviceId:e,primaryChildEntityId:t}),disabled:d.isPending})}),a!==null&&u(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:a})]})}n();var Yr=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Xr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Zr(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Qr(){let e=Me(),t=ft(),{data:n}=Y({deviceId:e??0},{enabled:e!==null}),{data:i}=q({deviceId:e??0},{enabled:e!==null}),a=n??t??null,[o,s]=c(`identity`);if(e===null||!a)return null;let l=String(a.stableId??``),d=String(a.name??``),f=String(a.type??``),p=String(a.addonId??``),m=a.features??[],h=new Set([`device-status`,`feature-probe`,`device-ops`]),g=(i?.entries??[]).filter(e=>e.kind===`native`&&!h.has(e.capName)).map(e=>e.capName),_=m.length>0?m:g,v=a.location??null,y=a.metadata??null,b=y!==null&&Object.keys(y).length>0;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[u(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),b&&r(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[u($r,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),u($r,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!b||o===`identity`)&&r(`div`,{className:`divide-y divide-border`,children:[u($,{label:`ID`,value:r(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,r(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,l,`)`]})]})}),u(Kr,{deviceId:e,initialName:d}),u(qr,{deviceId:e,initialLocation:v}),u(Jr,{deviceId:e}),u($,{label:`Type`,value:f}),u($,{label:`Provider`,value:u(Xt,{type:p,size:`sm`,showLabel:!0})}),u($,{label:`Capabilities`,value:_.length>0?u(nn,{capabilities:_,showLabels:!0}):u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),b&&o===`hardware`&&u(ei,{metadata:y})]})}function $r({active:e,onClick:t,label:n}){return u(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function ei({metadata:e}){let t=Yr.filter(t=>t in e),n=Object.keys(e).filter(e=>!Yr.includes(e)).toSorted(),i=[...t,...n];return r(`div`,{children:[u(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),u(`div`,{className:`divide-y divide-border`,children:i.map(t=>u($,{label:Xr(t),value:u(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Zr(e[t])})},t))})]})}var ti=`Notifications`,ni=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function ri(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:ti,on:r===null?null:i??r,available:r!==null,costWhenOff:ni}}function ii(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}n();function ai(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function oi({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(null),f=ri({mutedDeviceIds:ai(G({},{enabled:i}).data),deviceId:t,pendingOn:l}),p=j({onError:e=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),d(null),o(e instanceof Error?e.message:String(e)),n.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{o(null),d(null),n.invalidateQueries({queryKey:[[`notificationRules`]]})}}),m=e(()=>{let e=ii(f,t);e!==null&&(d(!e.muted),p.mutate(e))},[t,p,f]),h=f.on===null,g=f.on===!1,_=g?Jt:pt;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Notifications`}),g&&u(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:`muted`})]}),r(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[r(`button`,{type:`button`,role:`switch`,"aria-label":f.label,"aria-checked":f.on===!0,disabled:!f.available||p.isPending,onClick:m,title:h?`Notification mute — state unknown; the notification centre did not answer.`:g?`Muted. ${f.costWhenOff}`:`Notifying. Muting it: ${f.costWhenOff}`,className:`inline-flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${a===null?h?`border-dashed border-border text-foreground-subtle/50`:g?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(_,{className:`h-3.5 w-3.5`}),u(`span`,{children:h?`Unknown`:g?`Muted`:`Notifying`})]}),u(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:a===null?h?`The notification centre did not answer, so this device’s mute state is unknown.`:f.costWhenOff:`Write failed: ${a}`})]})]})}function si(e,t){return{switchId:e,label:rn[e].label,detail:t===void 0||t.length===0?null:t}}function ci(e){let t=new Map;for(let n of e.switches)n.deviceId===e.sourceId&&(t.has(n.switchId)||t.set(n.switchId,n));return t}function li(e){let t=ci(e),n=new Set(e.sourceStillLive),r=e.sourceStillLive.map(e=>si(e,t.get(e)?.detail)),i=[...t.values()].filter(e=>e.outcome===`not-offered`&&!n.has(e.switchId)).map(e=>si(e.switchId,e.detail));return{inheritedId:e.sourceId,retiredId:e.targetId,swapped:e.swapped,verdict:r.length===0?`quiet`:`still-live`,stillLive:r,neverOffered:i}}n();function ui(e,t){return e.filter(e=>e.isCamera&&e.id!==t).map(e=>({id:e.id,name:e.name})).toSorted((e,t)=>e.name.localeCompare(t.name))}function di({deviceId:e,deviceName:t}){let{t:n}=mn(),a=rt(),[o,s]=c(null),l=Te({isCamera:!0,projection:`slim`}),d=xt(),f=l.data!==void 0,p=i(()=>l.data===void 0?[]:ui(l.data,e),[l.data,e]),m=p.find(e=>e.id===o)??null,h=d.data===void 0?null:li(d.data),g=d.error===null?null:d.error.message,_=async()=>{m===null||m.id===e||await a({title:n(`deviceMigrate.confirmTitle`,`Replace “{{source}}” with “{{target}}”?`,{source:t,target:m.name}),message:n(`deviceMigrate.confirmMessage`,`“{{target}}” takes over number {{sourceId}}. That number is what every recording, event, rule, zone and home-automation export of “{{source}}” is filed under, so all of it follows the number to the new hardware and keeps working. “{{source}}” is switched off and handed number {{targetId}} in exchange. This swaps two device identities and cannot be undone from here.`,{source:t,target:m.name,sourceId:e,targetId:m.id}),confirmLabel:n(`deviceMigrate.confirmAction`,`Migrate`),variant:`danger`})&&d.mutate({sourceId:e,targetId:m.id})};return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`min-w-0`,children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:n(`deviceMigrate.title`,`Migrate to…`)}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.subtitle`,`Replace this camera with other hardware you have already adopted. The new camera inherits number {{deviceId}}, so recordings, rules and integrations follow it.`,{deviceId:e})})]}),r(`div`,{className:`flex shrink-0 items-center gap-2`,children:[r(`select`,{"aria-label":n(`deviceMigrate.pickerLabel`,`Replacement camera`),className:`rounded-md border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,disabled:!f||p.length===0||d.isPending,value:o===null?``:String(o),onChange:e=>{let t=e.target.value;s(t===``?null:Number(t))},children:[u(`option`,{value:``,children:f?n(`deviceMigrate.pickerPlaceholder`,`Select a camera…`):n(`deviceMigrate.pickerPending`,`Reading the fleet…`)}),p.map(e=>r(`option`,{value:String(e.id),children:[e.name,` (#`,e.id,`)`]},e.id))]}),r(`button`,{type:`button`,disabled:m===null||d.isPending,onClick:()=>{_()},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[u(Tn,{className:`h-3 w-3`}),d.isPending?n(`deviceMigrate.running`,`Migrating…`):n(`deviceMigrate.action`,`Migrate`)]})]})]}),f&&p.length===0&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:n(`deviceMigrate.noTargets`,`No other camera is adopted, so there is nothing to migrate to.`)}),g!==null&&u(`p`,{className:`mt-2 text-[11px] text-danger`,children:n(`deviceMigrate.failed`,`Migration failed: {{error}}`,{error:g})}),h!==null&&u(fi,{report:h})]})}function fi({report:e}){let{t}=mn(),n=e.verdict===`quiet`;return r(`div`,{className:`mt-3 space-y-2 border-t border-border pt-3`,children:[u(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`deviceMigrate.swapped`,`The replacement now answers on number {{inheritedId}}; the old camera was handed number {{retiredId}}.`,{inheritedId:e.inheritedId,retiredId:e.retiredId})}),n?r(`div`,{className:`flex items-start gap-2 rounded-md border border-success/30 bg-success/5 px-3 py-2`,children:[u(L,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-success`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.quiet`,`Every function on the replaced camera was switched off — the old hardware is quiet.`)})]}):r(`div`,{className:`rounded-md border border-warning/40 bg-warning/5 px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(He,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground`,children:t(`deviceMigrate.stillLive`,`The replaced camera could not be reached, so these functions are STILL RUNNING on the old hardware. Nothing here failed to migrate — but until you unplug it or reach it physically, it can still produce data.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.stillLive.map(e=>r(`li`,{className:`text-[11px] text-foreground`,children:[u(`span`,{className:`font-medium`,children:e.label}),e.detail!==null&&r(`span`,{className:`text-foreground-subtle`,children:[` — `,e.detail]})]},e.switchId))})]}),e.neverOffered.length>0&&r(`div`,{className:`rounded-md border border-border px-3 py-2`,children:[r(`div`,{className:`flex items-start gap-2`,children:[u(Zt,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),u(`p`,{className:`text-[11px] leading-relaxed text-foreground-subtle`,children:t(`deviceMigrate.neverOffered`,`The replaced camera never offered these, so there was nothing to switch off. They are not running.`)})]}),u(`ul`,{className:`mt-2 space-y-1 pl-5`,children:e.neverOffered.map(e=>u(`li`,{className:`text-[11px] text-foreground-subtle`,children:e.label},e.switchId))})]})]})}n();function pi({deviceId:e}){let[t,n]=c(null),i=N({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),r(`button`,{type:`button`,disabled:i.isPending,onClick:()=>{n(null),i.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[u(T,{className:`h-3 w-3 ${i.isPending?`animate-spin`:``}`}),i.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}n();var mi=`w-full min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary disabled:opacity-50`,hi={icon:``,label:``,unit:``,precision:``,hidden:!1};function gi(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function _i(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function vi(e){let t=e.precision.trim()===``?void 0:Number.parseInt(e.precision,10),n={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...t!==void 0&&Number.isFinite(t)?{precision:t}:{},...e.hidden?{hidden:!0}:{}};return Object.keys(n).length===0?null:n}function yi({deviceId:e}){let t=v(),n=s(),{data:a}=Y({deviceId:e},{enabled:e>0}),l=typeof a?.role==`string`?a.role:null,d=l===null?void 0:_t[l],f=d?.kind===`numeric`,p=Le(t.trpcClient,e,l??``),m=d?.kind===`numeric`?d.canonicalUnit:void 0,h=_i(p)??m,g=h===void 0?void 0:ln(h),_=i(()=>g===void 0?[]:cn(g),[g]),[y,b]=c(null),x=y??gi(a?.display),S=Ke({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:C}=Se({},{staleTime:6e4}),w=Ht({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(a===void 0||l===null)return null;let T=e=>{b({...x,...e})},E=()=>{S.mutate({deviceId:e,display:vi(x)})},D=()=>{b(hi),S.mutate({deviceId:e,display:null})},ee=()=>{let e={...x.icon===``?{}:{icon:x.icon},...x.unit===``?{}:{unit:x.unit},...x.precision.trim()!==``&&Number.isFinite(Number.parseInt(x.precision,10))?{precision:Number.parseInt(x.precision,10)}:{}},t={...C?.defaults,[l]:e};w.mutate({defaults:t})},O=ie(l).label,te=Object.keys(H);return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[u(`div`,{className:`border-b border-border px-3 sm:px-4 py-2`,children:u(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Display`})}),r(`div`,{className:`divide-y divide-border`,children:[u($,{label:`Icon`,value:r(`select`,{className:mi,value:x.icon,onChange:e=>T({icon:e.target.value}),children:[r(`option`,{value:``,children:[`Default (`,O,`)`]}),te.map(e=>u(`option`,{value:e,children:e},e))]})}),u($,{label:`Label`,value:u(`input`,{type:`text`,className:mi,placeholder:O,value:x.label,onChange:e=>T({label:e.target.value})})}),f&&r(o,{children:[u($,{label:`Unit`,value:r(`select`,{className:mi,value:x.unit,onChange:e=>T({unit:e.target.value}),disabled:_.length===0,children:[r(`option`,{value:``,children:[`Source`,h?` (${h})`:``]}),_.map(e=>u(`option`,{value:e,children:e},e))]})}),u($,{label:`Precision`,value:u(`input`,{type:`number`,min:0,max:10,step:1,className:mi,placeholder:`inherit`,value:x.precision,onChange:e=>T({precision:e.target.value})})})]}),u($,{label:`Hidden`,value:r(`label`,{className:`flex items-center gap-2`,children:[u(`input`,{type:`checkbox`,checked:x.hidden,onChange:e=>T({hidden:e.target.checked})}),u(`span`,{className:`text-[11px] text-foreground`,children:`Hide from device lists`})]})})]}),r(`div`,{className:`border-t border-border px-3 sm:px-4 py-2 flex flex-wrap items-center gap-2`,children:[u(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,onClick:E,disabled:S.isPending,children:`Save`}),u(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-[11px] text-foreground-subtle`,onClick:D,disabled:S.isPending,children:`Reset`}),r(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-[11px] text-foreground-subtle`,onClick:ee,disabled:w.isPending,title:`Apply this unit / precision / icon as the default for every ${O} sensor`,children:[`Set as default for all `,O,` sensors`]})]})]})}function bi(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function xi({device:e}){let t=fn(),n=typeof e.id==`number`?e.id:null,i=String(e.type??``),a=i===X.Camera,o=i===X.Hub,s=typeof e.role==`string`&&e.role.length>0,c=e.features??[],l=c.includes(dn.Resyncable),{data:d}=Bt({deviceId:n??0},{enabled:n!==null&&a,refetchInterval:5e3}),f=d?.streams??{},p=Object.entries(f),m=c.includes(dn.DoorbellButton),h=Xe(m?{deviceId:n??void 0,historyLimit:10}:void 0),g=h.latest?Date.now()-h.latest.timestamp<3e4:!1;return r(`div`,{className:`space-y-5`,children:[o&&n!==null&&u(Fe,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),l&&n!==null&&u(pi,{deviceId:n}),a&&n!==null&&u(di,{deviceId:n,deviceName:String(e.name??``)}),n!==null&&u(oi,{deviceId:n}),a&&n!==null&&u(R,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),m&&u(zt,{history:h.history,latestIsFresh:g}),a&&n!==null&&u(R,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),a&&p.length>0&&r(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[u(`div`,{className:`border-b border-border px-4 py-2`,children:u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),u(`div`,{className:`divide-y divide-border`,children:p.map(([e,t])=>r(`div`,{className:`px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[u(W,{className:`h-3 w-3 text-foreground-subtle`}),u(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),r(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[u(Si,{label:`Nominal`,value:bi(t.nominalBitrateKbps??0)}),u(Si,{label:`Observed`,value:bi(t.observedBitrateKbps??0)}),u(Si,{label:`Peak`,value:bi(t.peakBitrateKbps??0)}),u(Si,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),u(Qr,{}),s&&n!==null&&u(yi,{deviceId:n})]})}function Si({label:e,value:t,warning:n}){return r(`div`,{children:[u(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),u(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}function Ci({provider:e,integrationId:t,name:n}){let r=fn(),i=t===null?`/integrations`:`/integrations/${t}`,a=n===null?`Open integrations`:`Open integration ${n}`;return u(`button`,{type:`button`,onClick:()=>r(i),className:`shrink-0 rounded-md transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-1 focus-visible:ring-primary/50`,title:a,"aria-label":a,children:u(Xt,{type:e,size:`lg`})})}n();var wi=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0}];function Ti(e){let t=e===X.Camera;return wi.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var Ei=[{id:`logs`,icon:Ce,label:`Logs`},{id:`repl`,icon:pn,label:`REPL`},{id:`events`,icon:Pe,label:`Events`},{id:`state`,icon:U,label:`State`}];function Di(){let n=hn(),a=Number(n.deviceId),l=Number.isFinite(a),d=fn(),f=s(),m=rt(),h=v(),[g,_]=gn(),b=g.get(`tab`)??`overview`,x=g.get(`sub`),[S,E]=c(`logs`),D=`device-detail.left-col-width-px`,[O,te]=c(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(D),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),k=t(O);k.current=O;function A(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??O??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{te(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=k.current;if(e!==null)try{window.localStorage.setItem(D,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:ne,isLoading:j,isError:re}=Y({deviceId:a},{enabled:l,refetchInterval:5e3,retry:1}),{data:M}=se({deviceId:a},{enabled:l}),N=i(()=>{let e=M?.settings?.sections??[],t=M?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(xn)&&r.add(Sn),[...r].map(e=>e===`export`?{id:e,label:Cn,isAddonContrib:!0}:{id:e,label:sn[e]?.label??e,isAddonContrib:!0})},[M]),P=ne,F=String(P?.name??n.deviceId??`Device`),ie=P?.online===!0,ae=ie?`online`:`offline`,I=String(P?.addonId??`rtsp`),L=P?.features??[],R=P?.type,z=R===X.Camera,{data:B}=Qt(l?a:0),ce=R===X.Container,V=i(()=>(B??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[B]),H=i(()=>ce?ve(V,typeof P?.linkDeviceId==`number`?P.linkDeviceId:null,typeof P?.primaryChildEntityId==`string`?P.primaryChildEntityId:null)?.id??null:null,[ce,V,P?.linkDeviceId,P?.primaryChildEntityId]),{data:de}=se({deviceId:H??0},{enabled:H!==null}),pe=i(()=>{if(H===null)return[];let e=de?.settings?.sections??[],t=de?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:sn[e]?.label??e,isAddonContrib:!0,childDeviceId:H}))},[H,de]),U=typeof P?.parentDeviceId==`number`?P.parentDeviceId:null,{data:he}=Y({deviceId:U??0},{enabled:U!==null}),W=Ie(),G=P?.disabled!==!0,ge=i(()=>{let e=new Set,t=[];for(let n of[...Ti(R),...N,...pe])e.has(n.id)||(e.add(n.id),t.push(n));return t},[R,N,pe]),K=i(()=>Or(ge,b),[ge,b]),be=e(e=>{_(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[_]),q=e(e=>{_(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[_]),xe=(B??[]).length>0,Se=i(()=>Ei.filter(({featureGate:e})=>!e||L.includes(e)),[L]),{data:J}=ye({addonId:I},{enabled:!!I&&I!==`rtsp`}),Ce=ut({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),d(J?.id?`/integrations/${J.id}`:`/integrations`)}}),we=_e({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Te=me({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=oe(),Oe=Gt({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=L.includes(dn.Rebootable),Ae=L.includes(dn.BatteryOperated),je=$e(h.trpcClient,Ae&&l?a:null),Me=ee(h.trpcClient,l?a:null),[Ne,Pe]=c(!1),Fe=async()=>{if(!Ne){Pe(!0);try{let e=F.replace(/[^a-zA-Z0-9_.-]+/g,`_`),t=new Date().toISOString().replace(/[:.]/g,`-`);await vn(`${p}/${String(a)}.jpg?force=1`,`${e}-${t}.jpg`)}finally{Pe(!1)}}},Le=we.isPending||Te.isPending,{data:Re}=kt({deviceId:a},{enabled:l,refetchInterval:1e4}),Be=Re?.agentNodeId??null,Ve=typeof Be==`string`&&Be.length>0&&!Be.startsWith(`addon:`)?Be:void 0,{data:He}=le({deviceId:a,...Ve?{nodeId:Ve}:{}},{enabled:l,refetchInterval:3e3,retry:!1}),{data:Ue}=Et({deviceId:a},{enabled:l,refetchInterval:3e3,retry:!1}),We=Ue?.level?.dbfs??null;function Ge(){if(!l)return null;switch(K){case`overview`:return u(xi,{device:P??{}});case`config`:return u(Nr,{deviceId:a,activeSubTab:x,onSubTabChange:q});case`detection-pipeline`:return u(Gr,{deviceId:a,activeSubTab:x,onSubTabChange:q});case`bindings`:return u(kr,{deviceId:a});default:{let e=K,t=N.some(t=>t.id===e),n=pe.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??a;if(e===`export`)return u(wn,{deviceId:a,sectionFilter:xn,activeSubTab:x,onSubTabChange:q});let i=u(wn,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:x,onSubTabChange:q});return n!==void 0&&r!==a?u(Ze,{deviceId:r,children:i}):i}}}return l?j?r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[u(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),u(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),u(`div`,{className:`flex-1 p-6`,children:u(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):re||!ne?r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),r(`p`,{className:`text-xs`,children:[`No device with ID`,` `,r(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,a]})]}),u(`button`,{onClick:()=>d(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):r(`div`,{className:`absolute inset-0 flex flex-col overflow-clip`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[u(`div`,{className:`mb-2`,children:u(ze,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:J?.name??I,onClick:()=>J?.id&&d(`/integrations/${J.id}`)},{label:F}]})}),r(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[u(Ci,{provider:I,integrationId:J?.id??null,name:J?.name??null}),r(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:F}),u(yn,{status:ae}),Ae&&u(At,{status:je,variant:`full`}),u(it,{status:Me})]}),U!==null&&he&&r(`button`,{type:`button`,onClick:()=>d(`/devices/${U}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${he.name}`,children:[u(`span`,{children:`↑`}),u(`span`,{className:`truncate`,children:String(he.name??`Device #${U}`)})]}),u(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:L.length>0&&u(nn,{capabilities:L})})]}),He&&u(`div`,{className:`hidden lg:flex`,children:u(Oi,{metrics:He,dbfs:We})}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[r(`button`,{onClick:async()=>{G?await m({title:`Disable "${F}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Te.mutate({deviceId:a}):we.mutate({deviceId:a})},disabled:Le,title:G?`Disable device`:`Enable device`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${G?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[u(st,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:Le?`Updating…`:G?`Enabled`:`Disabled`})]}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),z&&r(o,{children:[u(Bn,{deviceId:a}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),u(jt,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:y,disabled:Ne,onClick:()=>{Fe()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:ue,hidden:!ke,disabled:De.isPending,danger:!0,onClick:async()=>{await m({title:`Reboot "${F}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&De.mutate({deviceId:a})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${J?.name??I}.`,icon:T,disabled:Oe.isPending,danger:!0,onClick:async()=>{await m({title:`Restart "${J?.name??I}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${F}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Oe.mutate({addonId:I})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:C,separatorBefore:!0,disabled:Ce.isPending,danger:!0,onClick:async()=>{await m({title:`Delete "${F}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ce.mutate({deviceId:a})}}]})]})]})]}),u(Ze,{deviceId:a,device:P??void 0,children:u(fe,{children:u(Ee,{children:u(w,{children:u(tt,{children:r(`main`,{className:W?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[r(`div`,{className:W?`flex flex-col bg-surface`:`${O===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!W&&O!==null?{width:`${String(O)}px`}:void 0,children:[u(`div`,{className:z?`flex-shrink-0 border-b border-border-subtle bg-black`:W?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:z?u(xr,{deviceId:a,intercomAvailable:L.includes(dn.TwoWayAudio)}):u(fr,{deviceId:a,deviceName:F,deviceType:R??`unknown`,provider:I,isOnline:ie,features:L})}),r(`div`,{className:W?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:u(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Se.map(({id:e,label:t,icon:n})=>r(`button`,{onClick:()=>E(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${S===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(n,{className:`h-3 w-3`}),t]},e))})}),r(`div`,{className:W?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[S===`logs`&&u(Sr,{deviceId:a,containerDeviceId:R===`container`?a:void 0}),S===`repl`&&u(Cr,{deviceId:a}),S===`events`&&u(wr,{deviceId:a}),S===`state`&&u(Tr,{deviceId:a})]})]})]}),!W&&u(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:A,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:u(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),r(`div`,{className:W?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:u(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:ge.map(e=>{let t=K===e.id;return r(`button`,{onClick:()=>be(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&u(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),r(`div`,{className:W?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[K===`overview`&&xe&&u(Un,{parentDeviceId:a}),Ge()]})]})]})})})})})})]}):r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),r(`p`,{className:`text-xs`,children:[`The URL segment`,` `,u(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:n.deviceId}),` `,`is not a number.`]}),u(`button`,{onClick:()=>d(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function Oi({metrics:e,dbfs:t}){let n=ct(e.phase??`idle`);return r(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[u(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),u(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),u(`div`,{className:`h-3 w-px bg-border`}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(Ae,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),u(`span`,{children:`fps`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(Wt,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),u(`span`,{children:`ms`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[u(Ft,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),u(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&r(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{Di as DeviceDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{K as e,Q as t,S as n,T as r,W as i,b as a,i as o,o as s,p as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as f,at as p,ct as m,ht as h,mt as g,st as _,ut as v}from"./player-overlays-FVdyuBBK.js";import{$a as y,$c as b,$l as x,Ao as S,Bt as C,Cc as w,Co as T,El as E,Ht as D,It as O,Jt as ee,Mo as k,Nl as A,Ol as j,Po as M,Qa as te,Rt as ne,Sn as N,So as P,Tn as F,U as I,Vt as re,X as L,Xa as ie,Xl as ae,Za as oe,_c as se,_l as R,bo as ce,d as le,dl as ue,do as de,el as fe,eo as pe,f as me,fc as z,fo as he,g as ge,gc as B,go as _e,hc as ve,ho as ye,il as be,io as xe,jo as Se,kc as Ce,kl as we,ko as Te,ln as Ee,lo as De,mc as Oe,mo as ke,no as Ae,nt as je,ol as Me,oo as Ne,pc as Pe,qc as Fe,r as V,ro as Ie,to as Le,vc as Re,vo as ze,wo as Be,x as Ve,xn as He,xo as Ue,yc as We,yo as Ge,zl as H,zt as Ke}from"./src-DHelZti5.js";import{a as qe,i as Je,l as Ye,n as U,o as Xe,r as Ze,t as Qe}from"./NodeInferenceDevices-CMLzoOnF.js";import{t as $e}from"./layers-DPT8Evsd.js";import{t as et}from"./square-check-big-BysRo6ev.js";import{t as tt}from"./video-CiDdAauf.js";import{n as nt}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{$t as rt,Qt as it,f as at,h as ot,p as st}from"./src-9HRd-uhT.js";import{p as ct,s as lt}from"./index-K_FwjgDL.js";import"./useEventInvalidation-CyI4_SVY.js";import{t as ut}from"./NodeAddonsSettingsPanel-Dxm-H5kR.js";import{t as dt}from"./StorageLocationsPanel-qfEwA1kH.js";var ft=f(`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`}]]);t();function pt(e){if(e==null)return null;if(typeof e==`number`)return e>0?e:null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function mt(e){return e}function ht(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function gt(e,t){return typeof e==`boolean`?e:mt(t)}function _t(e,t){return{pipeline:gt(ht(e,`detect`),t),audio:gt(ht(e,`audio`),t),ingest:gt(ht(e,`ingest`),t)}}function vt(e,t,n){let r=e?.find(e=>e.nodeId===t);return _t(r?.settings,n)}function yt({selectedNodeId:e,onSelect:t,refreshToken:r}){let{nodes:i}=Pe(),{data:o}=de(void 0),{data:s}=ke(void 0),c=new Map;for(let e of o??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=i??[],d=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return n(`div`,{className:`flex flex-col h-full`,children:[n(`button`,{type:`button`,onClick:()=>t(Ur),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:[u(ct,{className:`h-4 w-4 flex-shrink-0`}),n(`div`,{className:`min-w-0 flex-1`,children:[u(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),u(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(r=>{let i=e===r.id,o=c.get(r.id)??0,l=r.isHub?Fe:H,d=vt(s,r.id,r.isHub),f=r.isOnline?null:I(pt(r.lastSeen));return n(`button`,{type:`button`,onClick:()=>t(r.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`}${r.isOnline?``:` opacity-60`}`,children:[u(l,{className:`h-4 w-4 flex-shrink-0`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex items-center gap-2`,children:[u(`span`,{className:`text-xs font-semibold truncate`,children:r.name}),r.isHub&&u(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!r.isOnline&&u(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),r.isOnline&&u(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),n(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[n(`span`,{children:[r.cpuCores,` cores`]}),u(`span`,{children:`•`}),n(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),o>0&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[u(tt,{className:`h-2.5 w-2.5`}),o]})]}),!r.isOnline&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{className:`text-destructive`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),n(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[u(O,{variant:d.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:d.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),u(O,{variant:d.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:d.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},r.id)})}),n(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[n(`span`,{children:[d,` online`]}),f>0&&n(`span`,{className:`text-destructive`,children:[f,` offline`]})]})]})}function bt({nodeId:e,refreshToken:t}){let{nodes:r}=Pe(),i=r?.find(t=>t.id===e),o=Oe(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return i?n(`div`,{className:`px-6 py-4 border-b border-border`,children:[n(`div`,{className:`flex items-center gap-2 mb-1`,children:[u(`h2`,{className:`text-base font-semibold text-foreground`,children:i.name}),i.isOnline?u(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):u(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),i.isHub&&u(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),n(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[u(`span`,{children:i.cpuModel??`CPU`}),u(`span`,{children:`•`}),n(`span`,{children:[i.cpuCores,` cores`]}),u(`span`,{children:`•`}),n(`span`,{children:[Math.round(i.memoryMB/1024),` GB`]}),o&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{children:[o.attachedCameras,` cameras (`,o.activeCameras,` active)`]}),u(`span`,{children:`•`}),n(`span`,{children:[o.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),u(`span`,{children:`•`}),n(`span`,{children:[`queue `,o.queueDepthTotal]}),o.hardware.hasGpu&&n(a,{children:[u(`span`,{children:`•`}),u(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):u(`div`,{className:`px-6 py-4 border-b border-border`,children:n(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}var xt=[`assignments`,`tree`,`engines`,`logs`];function St({refreshToken:e,nodeId:t}){let[r,a]=l(new Map),{nodes:o}=z();B(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&a(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=xe(void 0),c=i(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),d=i(()=>{let e=new Map,t=Date.now()-3e4;for(let n of r.values()){if(n.timestamp<t)continue;let r=n.nodeId??`hub`,i=e.get(r)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,n.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=n.metrics.actualFps,i.totalInferenceWeighted+=n.metrics.avgInferenceTimeMs,i.queueDepth+=n.metrics.queueDepth,e.set(r,i)}return e},[r]),f=i(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=i(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of d.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}},[d,o]);if(t){let e=d.get(t);return n(`div`,{className:`@container/liveload`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),n(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[u(W,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),u(W,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),u(W,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),u(W,{label:`Queue`,value:e?String(e.queueDepth):`—`}),u(W,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...d.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return n(`div`,{className:`@container/liveload`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),n(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[u(W,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),u(W,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),u(W,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),u(W,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),u(W,{label:`Queue depth`,value:String(p.queueDepth)})]}),u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[480px]`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[u(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),u(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),u(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),u(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),u(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),u(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),n(`tbody`,{children:[m.map(([e,t])=>n(`tr`,{className:`border-t border-border`,children:[u(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&u(`tr`,{children:u(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function W({label:e,value:t}){return n(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[u(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),u(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}t();var Ct={active:!1,pinned:!1,nodeId:null,reason:``},wt=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],Tt=3e5,Et={pipeline:H,decoder:we,audio:v},Dt={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function Ot({mode:e,nodeId:t,compact:o=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let c=s(),[f,p]=l(null),[m,_]=l(null),[v,b]=l(new Map);V([`pipelineOrchestrator`,`getPipelineAssignments`],wt),V([`pipelineOrchestrator`,`getAudioAssignments`],wt),V([`pipelineOrchestrator`,`getCameraStatuses`],wt);let{data:x}=de(void 0),{data:C}=Ie(void 0),{data:w}=Ne({},{enabled:e===`agent`}),{nodes:T}=z(),{data:E}=Ye();B(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&b(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),d(()=>{if(v.size===0)return;let e=setInterval(()=>{b(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)},[v.size]);let D=i(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),O=i(()=>{if(e===`agent`){let e=[];for(let n of w??[]){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:D.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:D.get(e)??`Device ${e}`,pipeline:Ct,decoder:Ct,audio:Ct};return n.set(e,r),r};for(let i of x??[]){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 C??[]){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},[x,C,w,D,e,t]),k=i(()=>(T??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[T]),A=()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},j=pe({onSuccess:A}),M=Se({onSuccess:A}),te=y({onSuccess:A}),ne=S({onSuccess:A}),N=(e,t,n)=>{t===`pipeline`?j.mutate({deviceId:e,agentNodeId:n}):te.mutate({deviceId:e,nodeId:n}),p(null)},P=(e,t)=>{t===`pipeline`?M.mutate({deviceId:e}):ne.mutate({deviceId:e}),p(null)};return u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!o&&u(`th`,{className:`w-10`}),u(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?n(a,{children:[u(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),u(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):n(a,{children:[u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),u(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),n(`tbody`,{children:[O.map(t=>{let i=v.get(t.deviceId),s=m===t.deviceId;return n(r.Fragment,{children:[n(`tr`,{className:`border-t border-border align-middle relative`,children:[!o&&u(`td`,{className:`px-2 py-2 align-middle`,children:u(`button`,{type:`button`,onClick:()=>_(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:u(s?h:g,{className:`h-3.5 w-3.5`})})}),n(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[u(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),n(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?n(a,{children:[u(`td`,{className:`px-3 py-2 align-middle`,children:u(At,{state:t.pipeline,onlineNodes:k,pending:j.isPending||M.isPending,onChange:e=>{e===`auto`?P(t.deviceId,`pipeline`):N(t.deviceId,`pipeline`,e)}})}),u(`td`,{className:`px-3 py-2 align-middle`,children:u(Mt,{state:t.pipeline,deviceId:t.deviceId})})]}):n(a,{children:[u(Pt,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:k,isMenuOpen:f?.deviceId===t.deviceId&&f.role===`pipeline`,onToggleMenu:()=>p(f?.deviceId===t.deviceId&&f.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>p(null),onMove:e=>N(t.deviceId,`pipeline`,e),onUnpin:()=>P(t.deviceId,`pipeline`)}),u(Pt,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:k,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),u(Pt,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:k,isMenuOpen:f?.deviceId===t.deviceId&&f.role===`audio`,onToggleMenu:()=>p(f?.deviceId===t.deviceId&&f.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>p(null),onMove:e=>N(t.deviceId,`audio`,e),onUnpin:()=>P(t.deviceId,`audio`)})]}),u(`td`,{className:`px-3 py-2 align-middle`,children:u(Rt,{snap:i})})]}),s&&!o&&n(`tr`,{className:`bg-surface/50`,children:[u(`td`,{}),n(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&u(kt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),u(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)}),O.length===0&&u(`tr`,{children:u(`td`,{colSpan:o?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 kt({deviceId:e,nodeId:t}){let r=s(),{data:i}=De({nodeId:t}),{data:a}=he({deviceId:e}),o=Te({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),c=i?.devices??[],l=a?.deviceKey??`auto`,d=l!==`auto`&&!c.some(e=>e.key===l);return n(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),n(`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:[u(`option`,{value:`auto`,children:`Auto (balanced)`}),d&&n(`option`,{value:l,children:[`Pin → `,l,` (not on this node)`]}),c.map(e=>n(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),o.isPending&&u(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function At({state:e,onlineNodes:t,pending:r,onChange:i}){let a=e.pinned&&e.nodeId?e.nodeId:`auto`,o=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return n(`select`,{value:a,disabled:r,"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:[u(`option`,{value:`auto`,children:`Auto`}),o.map(e=>n(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function jt(t){let n=e(null);return t.nodeId!==null&&(n.current=t),n.current}function Mt({state:e,deviceId:t}){let r=jt(e),i=e.active&&e.nodeId!==null;if(r===null||r.nodeId===null)return u(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`— · no session yet`});let a=r.pinned?`pinned · manual`:`auto · ${r.reason||`capacity`}`;return n(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[u(`span`,{className:`font-mono text-[11px] truncate ${i?`text-foreground`:`text-foreground-subtle`}`,title:r.pinned?r.nodeId:`${r.nodeId} — an unpinned camera is re-elected per on-motion session, so this can change between sessions`,children:r.nodeId}),u(`span`,{className:`truncate ${r.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:a,children:a}),u(`span`,{className:`truncate text-[10px] ${i?`text-emerald-400`:`text-foreground-subtle/70`}`,children:i?`● running here`:`○ idle · last session here`}),u(Nt,{deviceId:t,nodeId:r.nodeId})]})}function Nt({deviceId:e,nodeId:t}){let r=s(),{data:i}=he({deviceId:e},{refetchOnMount:`always`}),{data:a}=De({nodeId:t},{staleTime:Tt}),o=Te({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(i===void 0||a===void 0)return u(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let c=a.devices??[],l=c.filter(e=>e.enabled),d=i.deviceKey??`auto`,f=d!==`auto`&&!l.some(e=>e.key===d),p=c.find(e=>e.key===d);return n(`select`,{value:d,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:[u(`option`,{value:`auto`,children:`Auto (balanced)`}),f&&n(`option`,{value:d,children:[p?`${U(p).label} (${d})`:d,` (not enabled)`]}),l.map(e=>n(`option`,{value:e.key,children:[U(e).label,` · `,e.format]},e.key))]})}function Pt({role:e,state:t,mode:r,onlineNodes:i,readOnly:a=!1,isMenuOpen:o,onToggleMenu:s,onCloseMenu:c,onMove:l,onUnpin:d}){let f=Et[e],p=i.filter(e=>e.id!==(t.nodeId??``)),m=!a&&(t.active||r===`cluster`)&&(p.length>0||t.pinned);return n(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[u(r===`agent`?Ft:It,{state:t,Icon:f}),u(`div`,{className:`ml-auto shrink-0`,children:m&&u(`button`,{type:`button`,onClick:s,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${Dt[e]} actions`,children:u(A,{className:`h-3 w-3 text-foreground-subtle`})})})]}),o&&m&&u(zt,{title:Dt[e],targets:p,pinned:t.pinned,onMove:l,onUnpin:d,onClose:c})]})}function Ft({state:e,Icon:t}){return n(`div`,{className:`flex items-center gap-1.5`,children:[u(e.active?et:m,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),u(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&u(ft,{className:`h-2.5 w-2.5 text-amber-400`})]})}function It({state:e,Icon:t}){return!e.active||!e.nodeId?n(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[u(t,{className:`h-3 w-3`}),u(`span`,{className:`text-[10px] italic`,children:`—`})]}):n(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[u(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),n(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[u(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),u(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?n(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[u(ft,{className:`h-2.5 w-2.5`}),` manual`]}):n(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Lt=`min-h-[3.25rem]`;function Rt({snap:e}){if(!e)return u(`div`,{className:`flex items-center ${Lt}`,children:u(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:r,avgInferenceTimeMs:i,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=je(t);return n(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Lt}`,children:[n(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[u(ge,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),n(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[u(`span`,{className:`text-foreground`,children:r.toFixed(1)}),n(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),n(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[u(`span`,{className:`text-foreground`,children:i.toFixed(0)}),u(`span`,{children:` ms`}),a>0&&n(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),n(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,u(`span`,{className:`text-foreground`,children:s})]})]})}function zt({title:t,targets:r,pinned:i,onMove:a,onUnpin:o,onClose:s}){let c=e(null);return d(()=>{let e=e=>{c.current?.contains(e.target)||s()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]),n(`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:[u(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:t}),r.length>0&&u(`div`,{className:`py-1`,children:r.map(e=>n(`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&&n(`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 `,t.toLowerCase()]}),r.length===0&&!i&&u(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Bt({nodeId:e,refreshToken:t}){return n(`div`,{className:`space-y-6`,children:[u(St,{refreshToken:t,nodeId:e}),n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),n(`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.`]})]}),u(Ot,{mode:`agent`,nodeId:e,compact:!0})]})}t();function Vt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Ht({nodeId:e,refreshToken:t}){let r=s(),a=Ee(),o=oe({onSettled:()=>{r.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:c}=te({nodeId:e}),l=Oe(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??c??null,d=l===null;V([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:f}=M({nodeId:e}),{values:p}=ve(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),m=i(()=>p.filter(e=>e.metrics.phase===`active`).length,[p]),h=t=>{let n=f??[];if(n.length===0){o.mutate({nodeId:e,engine:t,force:!1});return}(async()=>{await a({title:`Kill engine`,message:`${String(n.length)} camera(s) are dispatching through this engine. Killing it drops their in-flight work and forces a respawn on the next frame.`,confirmLabel:`Kill engine`,variant:`danger`})&&o.mutate({nodeId:e,engine:t,force:!0})})()};return n(`div`,{className:`space-y-6`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(l??[]).length,` engine(s) resident in RAM. `,(f??[]).length,` `,`camera(s) attached, `,m,` actively dispatching frames. Refreshes every 5s.`]})]}),u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[u(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),u(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),u(`th`,{className:`text-left px-3 py-2`,children:`Models`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),u(`th`,{className:`w-20`})]})}),n(`tbody`,{children:[d&&u(`tr`,{children:u(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!d&&(l??[]).map(e=>{let t=e.kind===`warm-override`,r=e.kind===`device-pool`;return n(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:r?`bg-primary/[0.05]`:``}`,children:[u(`td`,{className:`px-3 py-2`,children:n(`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`:r?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[u(t?j:r?$e:H,{className:`h-3 w-3`}),t?`warm`:r?`pool`:`runtime`]})}),u(`td`,{className:`px-3 py-2`,children:n(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[u(Re,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),u(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?u(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>u(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),u(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),u(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?u(`span`,{className:`text-foreground-subtle`,children:Vt(e.idleMs,e.idleTtlMs)}):u(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(f??[]).length}),u(`td`,{className:`px-3 py-2 text-right`,children:r?u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):n(`button`,{type:`button`,disabled:o.isPending,onClick:()=>h(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:[u(_,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!d&&(l??[]).length===0&&u(`tr`,{children:u(`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.`})})]})]})}),n(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[u(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,u(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,u(`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.`]}),o.isError&&n(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,o.error instanceof Error?o.error.message:`unknown`]})]})}var Ut=`pipeline-runner`,Wt=200;function Gt({nodeId:e}){return n(`div`,{className:`flex flex-col gap-3`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),n(`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.`]})]}),u(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:u(L,{agentId:e,addonId:Ut,limit:Wt,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}t(),t();function Kt({nodeId:e,title:t}){let{data:r}=Ye(),{data:a}=de(void 0),o=i(()=>{let e=new Map;for(let t of r??[])e.set(t.id,t.name);return e},[r]),s=i(()=>{if(!e)return null;let t=new Set;for(let n of a??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,a]),[c,f]=l(new Map);B(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||f(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),d(()=>{if(c.size===0)return;let e=setInterval(()=>{f(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=i(()=>{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?n(`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`]}):n(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[n(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[u(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),u(`span`,{className:`text-[10px] text-foreground-subtle`,children:p.length})]}),u(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,r=je(e.metrics.phase);return n(`div`,{title:`${t} · ${r.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] ${r.badgeClass}`,children:[u(ge,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),u(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),u(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),u(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var qt=`pipeline-orchestrator`;function Jt(e){return at.find(t=>t.stepId===e)??null}function Yt({title:e}){return u(`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 Xt({step:e,engineFormat:t,runnableModelIds:r}){let i=s(),{data:a,isLoading:o}=N({addonId:qt}),c=F({onSuccess:()=>{i.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),l=ot(a??null)[e.stepId]??e.defaultModelId,d=r.length>0&&!r.includes(l);return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[n(`div`,{className:`flex items-center text-[11px] font-medium text-foreground`,children:[e.label,u(Yt,{})]}),n(`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?u(R,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):u(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:l,disabled:c.isPending,onChange:t=>{t.target.value!==l&&c.mutate({addonId:qt,patch:{[st(e.stepId)]:t.target.value}})},children:e.options.map(t=>n(`option`,{value:t.id,children:[t.label,t.id===e.defaultModelId?` (default)`:``]},t.id))}),d&&n(`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 `,u(`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.`]}),u(`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.`})]})}t();function G(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 Zt(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 Qt({nodeId:e,refreshToken:t}){let r=s(),[o,c]=l(null),[d,f]=l(null),[p,m]=l(``),[h,g]=l(null),_=De({nodeId:e},{refetchOnMount:`always`}),v=ie({nodeId:e},{refetchOnMount:`always`}),y=ot(N({addonId:`pipeline-orchestrator`}).data??null),b=_.data?.devices??[],x=T({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),S=i(()=>v.data?le(v.data):[],[v.data]),w=i(()=>b.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:U(t).label})),[b,e]),E=e=>b.find(t=>t.key===e)??null,O=i(()=>b.filter(e=>e.enabled),[b]),ee=O.length>=2,k=(e,t)=>re(G(v.data??null,e)?.models??[],t?.format),A=e=>{let t=E(e);return t?U(t).label:e},j=(e,t)=>O.filter(n=>n.key!==t&&k(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,M=e=>{let t=G(v.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},te=(e,t)=>{let n=G(v.data??null,e);if(n)return Ke(n,t)},P=(e,t)=>{let n=M(e),r=n.kind===`gate`?n.effectiveOn:!1,i=G(v.data??null,e),a=t.deviceKey===void 0?null:E(t.deviceKey),o=re(i?.models??[],a?.format),s=a?.steps?.[e];if(!o){if(!r)return{kind:`na`};let n=s?.jumpDeviceKey,i=n!==void 0&&O.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:j(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:A(i)}}let c=Jt(e);return c?{kind:`enabled`,modelId:y[e]??c.defaultModelId,clusterWide:!0}:{kind:`enabled`,modelId:(i?C({catalog:i,device:a,base:s?.modelId}):void 0)??`Auto`,...s?.jumpDeviceKey!==void 0&&O.some(e=>e.key===s.jumpDeviceKey)?{jumpTo:A(s.jumpDeviceKey)}:{}}},F=o&&v.data?G(v.data,o.addonId):null,I=o?E(o.deviceKey):null,L=I?.format??`coreml`,ae=o?te(o.addonId,I):void 0,oe=()=>{c(null),f(null),m(``)},se=(e,t)=>{if(t.deviceKey===void 0)return;let n=E(t.deviceKey)?.steps?.[e];c({addonId:e,deviceKey:t.deviceKey});let r=n?.settings??qe(b.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??``)},R=()=>{if(!o)return;let t=Zt(d),n=p!==``&&p!==o.deviceKey?p:void 0,r=t||n!==void 0?{...t,...n===void 0?{}:{jumpDeviceKey:n}}:null,i=b.map(e=>{let t={...e.steps};return e.key===o.deviceKey&&(r?t[o.addonId]=r:delete t[o.addonId]),{key:e.key,enabled:e.key===o.deviceKey?!0:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:t}}),a=r?.settings!==void 0&&Object.keys(r.settings).length>0?Xe(i,o.deviceKey,o.addonId):i;x.mutate({agentNodeId:e,inferenceDevices:Je(a)},{onSuccess:oe})};if(_.isLoading||v.isLoading)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(b.length===0)return u(`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 u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ce=o!==null&&F!==null&&I!==null;return n(`div`,{className:`relative h-full w-full space-y-3`,children:[n(`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`,` `,u(`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.`]}),u(`div`,{className:ce?`md:pr-[360px]`:``,children:S.length>0?u(Ve,{tree:S,agents:w,gateFor:M,getCellState:P,onCellClick:se,selectedCell:o?{addonId:o.addonId,agentNodeId:e,deviceKey:o.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:h,onFallbackNodeChange:g,hideGate:!0}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(me,{open:ce,onClose:oe,title:F?.name??``,subtitle:o&&I?`${e} · ${U(I).label} · ${I.format}`:``,footer:n(a,{children:[u(`div`,{className:`flex-1`}),u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:oe,children:`Cancel`}),u(`button`,{type:`button`,disabled:!o||!d||x.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:R,children:x.isPending?`Saving…`:`Save`})]}),children:F&&o&&Jt(o.addonId)?u(Xt,{step:Jt(o.addonId),engineFormat:L,runnableModelIds:D(F.models??[],L).map(e=>e.id)}):F&&o&&d?n(`div`,{className:`space-y-3`,children:[ee&&n(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[u(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),n(`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:[u(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),O.filter(e=>e.key!==o.deviceKey).map(e=>n(`option`,{value:e.key,children:[U(e).label,` · `,e.format]},e.key))]}),u(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),u(ne,{mode:`agent`,addon:F,agentDefault:d,agentNodeId:e,engineFormat:L,effectiveModelId:ae,onChangeAgentConfig:f})]}):u(`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.`})})]})}t();var $t=!1;function en({nodeId:e,refreshToken:t}){let r=Ee(),[i,a]=l(null),[o,s]=l(null),{nodes:c}=z(),d=c.find(t=>t.id===e),f=d?.name??e,p=d?.isOnline??!1,m=ze({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)`)}}),h=async()=>{await r({title:`Reset ${f} 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),m.mutate({agentNodeId:e}))};return n(`div`,{className:`relative h-full w-full space-y-3`,children:[n(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[o&&u(`span`,{className:`text-emerald-400`,children:o}),m.isError&&u(`span`,{className:`text-red-400`,children:m.error instanceof Error?m.error.message:`Reset failed`}),u(`button`,{type:`button`,onClick:()=>{h()},disabled:m.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:m.isPending?`Resetting…`:`Reset to default`})]}),u(Kt,{nodeId:e}),$t,$t,n(`div`,{children:[u(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),u(Qe,{nodeId:e,nodeName:f,isOnline:p})]}),n(`div`,{children:[u(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),u(Qt,{nodeId:e,refreshToken:t})]})]})}var tn=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],nn=`decoder-nodeav`;function rn({nodeId:e,refreshToken:t}){let{nodes:r}=z(),i=r.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??nn,a=[...tn,i],o={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:u(Bt,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:u(en,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:u(Ht,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:u(Gt,{nodeId:e})}},s=xt.map(e=>o[e]);return n(`div`,{className:`flex flex-col h-full`,children:[u(bt,{nodeId:e,refreshToken:t}),u(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:u(ut,{nodeId:e,addonIds:a,level:`global`,extraTabs:s})})]})}function an(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 on={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 sn(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function cn(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:an(e),format:e.format,sessions:i,queueDepth:r?.queueDepth??0,weight:a,weightSharePct:e.exclusion===null?sn(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 ln(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=cn(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?sn(l,i.maxCameras):null,queueDepthTotal:a?.load.queueDepthTotal??null,avgInferenceTimeMs:a?.load.avgInferenceTimeMs??null,score:a?.score??null,weight:c,weightSharePct:s?sn(c,n):null,cameraSharePct:l===null?null:sn(l,r),decodeHwaccel:a?.decodeHwaccel??null,devices:o,eligibleDeviceCount:o.filter(e=>e.exclusion===null).length}})}var un=`pipeline-orchestrator`,dn=`recorder`,fn=`recordingNodeId`,pn=`pipeline-analytics`,mn=`postProcessingNodeId`,hn=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`,`postProcessingNode`],gn=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function _n(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function vn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function K(e,t,n){let r=_n(e,t);return typeof r==`string`&&r.length>0?r:n}function yn(e,t,n){let r=_n(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function q(e,t){let n=vn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function bn(e,t){let n=vn(e,t);return typeof n==`string`&&n.length>0?n:null}function xn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:e===`postProcessingNode`?`Post-processing`:`Motion Node`}function Sn(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`:e===`postProcessingNode`?`Runs detection post-processing (events, media, audio & motion)`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function Cn(e,t){switch(t){case`detect`:return e.pipeline}}function wn(e){return e instanceof Error?e.message:`Failed to save`}function Tn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}t();var En=2e4,Dn=3e5;function On(){let{nodes:e}=z(),t=p().trpcClient,r=Ae(void 0,{placeholderData:c,staleTime:En,refetchInterval:En,refetchOnWindowFocus:!0}),a=ke(void 0,{staleTime:Dn}),s=i(()=>e.map(e=>e.id),[e]),l=o({queries:s.map(e=>({queryKey:nt(se.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>t.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Dn,refetchOnWindowFocus:!1,placeholderData:c}))}),d=i(()=>{let e={};return s.forEach((t,n)=>{let r=l[n]?.data;r&&(e[t]=r.devices)}),e},[s,l.map(e=>e.dataUpdatedAt).join(`|`)]),f=i(()=>{let e=new Map;for(let t of a.data??[])e.set(t.nodeId,t.settings);return e},[a.data]),m=i(()=>e.map(e=>{let t=f.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:_t(t,e.isHub).pipeline,weight:q(t,`detectWeight`)??1,maxCameras:q(t,`maxCameras`)}}),[e,f]),h=r.data??[],g=i(()=>ln({nodes:m,loads:h,devicesByNode:d}),[m,h,d]),_=g.reduce((e,t)=>e+(t.attachedCameras??0),0),v=g.reduce((e,t)=>e+(t.activeCameras??0),0),y=r.dataUpdatedAt>0?Date.now()-r.dataUpdatedAt:null;return n(`section`,{className:`rounded-md border border-border bg-surface px-3 py-2.5`,children:[n(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 mb-2`,children:[u(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Node load`}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[v,` running · `,_,` attached across `,g.length,` `,g.length===1?`node`:`nodes`]}),u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle/70 tabular-nums`,children:r.data===void 0?`reading…`:`reading ${y===null?`—`:`${Math.round(y/1e3)}s`} old · every ${En/1e3}s`})]}),g.length===0?u(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):u(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:g.map(e=>u(kn,{row:e},e.nodeId))})]})}function kn({row:e}){let t=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return n(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[n(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[u(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),u(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&u(`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&&n(`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:[u(Ce,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&n(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[u(w,{className:`h-2.5 w-2.5`}),` offline`]})]}),n(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[u(J,{label:`Running / attached`,value:t,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),u(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).`}),u(J,{label:`Actual share`,value:e.cameraSharePct===null?`—`:`${e.cameraSharePct}%`,title:`Share of the cluster's attached cameras this node carries right now.`}),u(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&&u(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&u(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&u(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),u(An,{row:e})]})}function An({row:e}){return e.devices.length===0?u(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):n(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[n(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[u(E,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&u(`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`})]}),u(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>u(jn,{device:e},e.key))})]})}function jn({device:e}){let t=e.exclusion;return n(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[u(H,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),u(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?n(a,{children:[n(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),n(`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&&n(`span`,{className:`shrink-0 tabular-nums text-amber-400`,children:[`· q`,e.queueDepth]}),e.atCap&&u(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):n(`span`,{className:`truncate text-foreground-subtle/80`,title:on[t],children:[`excluded — `,on[t]]})]})}function J({label:e,value:t,title:r}){return n(`div`,{className:`min-w-0`,title:r,children:[u(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Mn(){return n(`div`,{className:`space-y-6`,children:[u(Kt,{title:`Cluster cameras`}),u(On,{}),n(`div`,{className:`min-w-0`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),u(`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.`})]}),u(Ot,{mode:`cluster`})]})}function Nn({capability:e,label:t,hint:r,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`,d=s===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,f=a?x:ue;return n(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} capability for ${i}`,title:`${t} — ${r}`,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} ${d}`,children:[u(f,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),u(`span`,{children:t})]})}function Pn({node:e,emphasis:t=!1}){let r=e.isHub?Fe:H;return n(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[u(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),u(r,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),n(`div`,{className:`min-w-0`,children:[n(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[u(`span`,{className:`truncate`,children:e.name}),e.isHub&&u(O,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&u(O,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),u(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}t();function Fn({nodeId:e,value:t,detectedHosts:r,status:i,errorMessage:a,onCommit:o}){let[s,c]=l(t??``);d(()=>{c(t??``)},[t]);let f=r[0],p=f===void 0?`auto-detect`:`auto: ${f}`,m=i===`pending`,h=s.trim(),g=h!==(t??``),_=g&&!m,v=()=>{_&&o(e,h.length>0?h:null)};return n(`div`,{className:`flex items-center gap-1.5`,children:[u(`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`}),n(`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?u(R,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):u(x,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!g&&!m&&i===`success`&&u(x,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),i===`error`&&u(`span`,{title:a??`Failed to save reachable host`,children:u(ae,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":a??`Failed to save reachable host`,role:`img`})})]})}t();var In=1024,Ln=65536;function Rn(e,t,n){let r=e.trim();if(r.length===0)return{value:null,error:null};let i=Number(r);return Number.isInteger(i)?i<t?{value:null,error:`at least ${t}`}:i>n?{value:null,error:`at most ${n}`}:{value:i,error:null}:{value:null,error:`whole number`}}function zn({nodeId:e,decodeBudgetMb:t,maxLiveDecodeWorkers:r,status:i,errorMessage:a,onCommit:o}){let[s,c]=l(t===null?``:String(t)),[f,p]=l(r===null?``:String(r));d(()=>{c(t===null?``:String(t))},[t]),d(()=>{p(r===null?``:String(r))},[r]);let m=Rn(s,In,Ln),h=Rn(f,1,32),g=i===`pending`,_=m.value!==t||h.value!==r,v=m.error!==null||h.error!==null,y=_&&!v&&!g,b=()=>{y&&o(e,{decodeBudgetMb:m.value,maxLiveDecodeWorkers:h.value})},S=`w-24 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`;return n(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`input`,{"aria-label":`Decode budget MB for ${e}`,type:`number`,inputMode:`numeric`,min:In,max:Ln,placeholder:`auto`,value:s,disabled:g,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:S}),u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`MB`}),u(`input`,{"aria-label":`Max decode workers for ${e}`,type:`number`,inputMode:`numeric`,min:1,max:32,placeholder:`auto`,value:f,disabled:g,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:S}),u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`workers`}),n(`button`,{type:`button`,onClick:b,disabled:!y,"aria-label":`Save decode limits for ${e}`,title:`Save decode limits`,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:[g?u(R,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):u(x,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),m.error===null?null:n(`span`,{className:`text-[11px] text-red-400`,children:[`budget: `,m.error]}),h.error===null?null:n(`span`,{className:`text-[11px] text-red-400`,children:[`workers: `,h.error]}),!_&&!g&&i===`success`&&u(x,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),i===`error`&&u(`span`,{title:a??`Failed to save decode limits`,children:u(ae,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":`Save failed`,role:`img`})})]})}function Bn({label:e,children:t}){return n(`div`,{className:`flex items-center justify-between gap-3`,children:[u(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function Vn({node:e,actions:t}){return n(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[u(Pn,{node:e,emphasis:!0}),u(`div`,{className:`grid grid-cols-2 gap-2`,children:gn.map(n=>u(Nn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Cn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),n(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[u(Bn,{label:`Reachable host`,children:u(Fn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})}),u(Bn,{label:`Decode limits`,children:u(zn,{nodeId:e.id,decodeBudgetMb:e.decodeBudgetMb,maxLiveDecodeWorkers:e.maxLiveDecodeWorkers,status:t.decodeLimitsStatus(e.id),errorMessage:t.decodeLimitsErrorMessage(e.id),onCommit:t.onCommitDecodeLimits})})]})]})}function Hn(){return n(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function Un({nodes:e,actions:t}){return u(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:n(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[u(`thead`,{children:n(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),gn.map(e=>u(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`}),u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Decode limits`})]})}),u(`tbody`,{children:e.map(e=>n(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[u(`td`,{className:`px-4 py-3 align-middle`,children:u(Pn,{node:e})}),gn.map(n=>u(`td`,{className:`px-3 py-3 text-center align-middle`,children:u(Nn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Cn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),u(`td`,{className:`px-4 py-3 align-middle`,children:u(Fn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})}),u(`td`,{className:`px-4 py-3 align-middle`,children:u(zn,{nodeId:e.id,decodeBudgetMb:e.decodeBudgetMb,maxLiveDecodeWorkers:e.maxLiveDecodeWorkers,status:t.decodeLimitsStatus(e.id),errorMessage:t.decodeLimitsErrorMessage(e.id),onCommit:t.onCommitDecodeLimits})})]},e.id))})]})})}function Wn({role:e,value:t,options:r,pending:i,onChange:a}){return n(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[u(`span`,{className:`text-xs font-semibold text-foreground`,children:xn(e)}),u(`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:r.map(e=>u(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),u(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:Sn(e)})]})}function Gn({roleValues:e,options:t,pending:r,lowFpsEnabled:i,fpsMinThreshold:a,onRoleChange:o,onLowFpsToggle:s}){return n(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-3`,children:[hn.map(n=>u(Wn,{role:n,value:e[n],options:t,pending:r,onChange:o},n)),n(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[u(`input`,{type:`checkbox`,checked:i,disabled:r,onChange:e=>s(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),n(`span`,{className:`flex flex-col gap-0.5`,children:[u(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),n(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,i?`${a} fps`:`disabled`]})]})]})]})}t();function Kn(){let e=s(),{nodes:t}=z(),r=ke(void 0),o=N({addonId:un}),c=N({addonId:dn}),d=N({addonId:pn}),f=()=>Tn(e),p=ce({onSuccess:f}),m=P(),h=Be({onSuccess:f}),g=Ue({onSuccess:f}),_=F({onSuccess:f}),[v,y]=l(!1),b=i(()=>{let e=new Map;for(let t of r.data??[])e.set(t.nodeId,t.settings);return e},[r.data]),x=i(()=>t.map(e=>{let t=b.get(e.id),n=_t(t,e.isHub),r=q(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:q(t,`maxCameras`),reachableHost:bn(t,`reachableHost`),detectedHosts:e.localIps,decodeBudgetMb:q(t,`decodeBudgetMb`),maxLiveDecodeWorkers:q(t,`maxLiveDecodeWorkers`)}}),[t,b]),S=x.filter(e=>e.effective.pipeline),C={ingestNode:K(o.data,`ingestNode`,`hub`),recordingNode:K(c.data,fn,`hub`),audioNode:K(o.data,`audioNode`,`hub`),motionNode:K(o.data,`motionNode`,`hub`),postProcessingNode:K(d.data,mn,`hub`)},w=i(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...hn.map(e=>C[e]),...e])].filter(e=>e.length>0)},[t,C]),T=yn(o.data,`fpsMinThreshold`,0),E=T>0,D=r.isLoading||o.isLoading||c.isLoading||d.isLoading,O=(e,t,n)=>{p.mutate({agentNodeId:e,[t]:n})},ee=(e,t)=>{if(e===`recordingNode`){_.mutate({addonId:dn,patch:{[fn]:t}});return}if(e===`postProcessingNode`){_.mutate({addonId:pn,patch:{[mn]:t}});return}_.mutate({addonId:un,patch:{[e]:t}})},k=e=>{_.mutate({addonId:un,patch:{fpsMinThreshold:e?Math.max(1,T):0}})},A=e=>h.variables?.agentNodeId===e?h.isPending?`pending`:h.isError?`error`:h.isSuccess?`success`:`idle`:`idle`,j=e=>A(e)===`error`?wn(h.error):null,M=e=>g.variables?.agentNodeId===e?g.isPending?`pending`:g.isError?`error`:g.isSuccess?`success`:`idle`:`idle`,te=e=>M(e)===`error`?wn(g.error):null,ne=async e=>{y(!0);try{for(let t of e)await m.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{y(!1),f()}},I={capabilityPending:p.isPending,onToggleCapability:O,onCommitReachableHost:(e,t)=>h.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:A,reachableHostErrorMessage:j,onCommitDecodeLimits:(e,t)=>g.mutate({agentNodeId:e,...t}),decodeLimitsStatus:M,decodeLimitsErrorMessage:te};return n(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[n(`header`,{className:`flex items-start justify-between gap-4`,children:[n(`div`,{className:`space-y-1`,children:[u(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),u(`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.`})]}),D&&u(R,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),u(Gn,{roleValues:C,options:w,pending:_.isPending,lowFpsEnabled:E,fpsMinThreshold:T,onRoleChange:ee,onLowFpsToggle:k})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Events folder`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),u(dt,{types:[`eventMedia`]})]}),n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),u(Hn,{})]}),x.length===0?u(`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.`}):n(a,{children:[u(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:x.map(e=>u(Vn,{node:e,actions:I},e.id))}),u(`div`,{className:`hidden @3xl/clustertab:block`,children:u(Un,{nodes:x,actions:I})})]})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),u(Ze,{nodes:S,pending:v,onCommitWeights:e=>void ne(e)})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),S.length===0?u(`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.`}):u(`div`,{className:`space-y-2`,children:S.map(e=>u(Qe,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}t(),t(),t(),t();function qn(e){if(e===void 0||e.length===0)return[];let t=new Set,n=[];for(let r of e)for(let e of r.capabilities){let i=`${e}\0${r.addonId}`;t.has(i)||(t.add(i),n.push({name:e,addonId:r.addonId}))}return n.toSorted((e,t)=>e.name.localeCompare(t.name))}function Jn(e){let t=e.services;return{pid:e.pid,name:e.name,addonId:t?.[0]?.addonId??``,cpu:e.cpuPercent,mem:e.memoryRss,state:e.state,caps:qn(t)}}function Yn(e){return{nodeId:e.id,isHub:e.isHub,isOnline:e.isOnline,lastSeen:e.lastSeen,identity:{name:e.name,ip:e.localIps?.[0]??``,cpu:e.cpuPercent,mem:e.memoryPercent,platform:e.platform,arch:e.arch},runners:e.processes.map(Jn)}}function Xn(e){let t=e.toSorted((e,t)=>{let n=+!!e.isHub;return+!!t.isHub-n}).map(Yn),n=t.find(e=>e.isHub);return n===void 0?{nodes:t,edges:[]}:{nodes:t,edges:t.filter(e=>!e.isHub).map(e=>({id:`hub:${n.nodeId}->${e.nodeId}`,source:n.nodeId,target:e.nodeId,online:e.isOnline&&n.isOnline}))}}t();var Zn=!1;function Qn({refreshToken:e}){let t=s(),{nodes:r}=Pe();i(()=>Xn(r??[]),[r]);let a=_e({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return n(`div`,{className:`space-y-6`,children:[u(St,{refreshToken:e}),u(Kn,{}),Zn,n(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[n(`div`,{className:`min-w-0`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),u(`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.`})]}),n(`button`,{type:`button`,onClick:()=>a.mutate(void 0),disabled:a.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:[u(Re,{className:`h-3.5 w-3.5`}),a.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var $n=[`pipeline-orchestrator`],er=`pipeline-analytics`,tr=`face-gallery`;function nr({refreshToken:e}){return n(`div`,{className:`space-y-4 max-w-3xl`,children:[u(ut,{nodeId:`hub`,addonIds:$n,level:`global`,omitSectionIds:[`cluster`],title:`Cluster settings`,description:`Cluster-wide orchestration knobs: load balancer, failover, enrichment models, and the admission settings those models share. Ingest / Audio / Motion / Recording / Post-processing node pickers live on the Balancer tab. Per-camera pipelines live in Device Overrides.`}),u(ut,{nodeId:`hub`,addonIds:[er],level:`global`,capability:tr,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.`})]})}t();function rr({refreshToken:e}){let t=s(),r=Ee(),{data:i,isLoading:o}=ye(),[c,d]=l(null),[f,p]=l(``),[m,h]=l(``),g=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},v=k({onSuccess:()=>{d(null),g()}}),y=Le({onSuccess:g}),b=e=>{d(e.id),p(e.name),h(e.description??``)},S=()=>{d(null),p(``),h(``)},C=()=>{if(!c)return;let e=m.trim();v.mutate({id:c,name:f.trim()||`Untitled`,...e?{description:e}:{}})};if(o)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let w=[...i??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return u(`div`,{className:`space-y-6 max-w-4xl`,children:n(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),u(`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.`})]}),n(`div`,{className:`text-[11px] text-foreground-subtle`,children:[w.length,` template`,w.length===1?``:`s`]})]}),w.length===0?n(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[u(be,{className:`h-6 w-6 opacity-40`}),u(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):u(`ul`,{className:`divide-y divide-border`,children:w.map(e=>{let t=c===e.id;return u(`li`,{className:`px-4 py-3 text-xs`,children:n(`div`,{className:`flex items-start gap-3`,children:[u(`div`,{className:`flex-1 min-w-0`,children:t?n(`div`,{className:`space-y-2`,children:[u(`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:f,onChange:e=>p(e.target.value),placeholder:`Template name`,autoFocus:!0}),u(`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:m,onChange:e=>h(e.target.value),placeholder:`Description (optional)`})]}):n(a,{children:[u(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&u(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),n(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,n(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),u(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?n(a,{children:[n(`button`,{type:`button`,onClick:C,disabled:v.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:[u(x,{className:`h-3 w-3`}),`Save`]}),n(`button`,{type:`button`,onClick:S,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[u(We,{className:`h-3 w-3`}),`Cancel`]})]}):n(a,{children:[u(`button`,{type:`button`,onClick:()=>b(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:u(Me,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:()=>{(async()=>{await r({title:`Delete template`,message:`Delete the cluster pipeline template "${e.name}"? Cameras already using it keep their current pipeline.`,confirmLabel:`Delete`,variant:`danger`})&&y.mutate({id:e.id})})()},disabled:y.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:u(_,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}var ir=`pipeline-orchestrator`,ar=200;function or(){return n(`div`,{className:`flex flex-col gap-3`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),u(`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.`})]}),u(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:u(L,{addonId:ir,limit:ar,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}t();var sr=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function cr({refreshToken:e}){let[t,r]=l(`assignments`);return n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[u(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),u(`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.`})]}),u(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:sr.map(e=>u(`button`,{type:`button`,onClick:()=>r(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))}),n(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&u(Mn,{}),t===`balancer`&&u(Qn,{refreshToken:e}),t===`settings`&&u(nr,{refreshToken:e}),t===`templates`&&u(rr,{refreshToken:e}),t===`logs`&&u(or,{})]})]})}var lr=`armed:`;function ur(e){return e.assignment.reasons.detection?.startsWith(lr)===!0}function dr(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!ur(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function fr(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&&!ur(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 pr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function mr(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function hr(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function gr(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var _r={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 vr(e){if(!pr(e)||!Array.isArray(e.sections))return _r;let t=it(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)gr(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:mr(n(`detectionFps`)),motionSources:hr(n(`motionSources`)),motionFps:mr(n(`motionFps`)),motionCooldownMs:mr(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 yr(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(...yr(r.children,t+1));return n}function X({title:e,children:t}){return n(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[u(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),u(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:r=!1}){return n(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[u(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),u(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),r&&u(br,{})]})}function br(){return u(`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 xr={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 u(`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 ${xr[e]}`,children:t})}function $({children:e}){return u(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function Sr({icon:e,label:t,nodeId:r,pinned:i,reason:o,overridden:s}){return n(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[u(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),u(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),r===null?u(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):n(a,{children:[u(`span`,{className:`font-mono text-foreground truncate`,title:r,children:r}),i?n(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[u(ft,{className:`h-2.5 w-2.5`}),` manual`]}):n(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,o!==void 0&&o.length>0?o:`capacity`]}),s&&u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function Cr({assignment:e,settings:t,onlineNodes:r,pinPending:i,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...r.map(e=>e.id)])];return n(X,{title:`Where it runs`,children:[u(Sr,{icon:H,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),u(Sr,{icon:we,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),u(Sr,{icon:v,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),u(Sr,{icon:fe,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),u(`div`,{className:`mt-1.5`,children:n(`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:[u(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>n(`option`,{value:e,children:[`Pin detection → `,r.find(t=>t.id===e)?.name??e]},e))]})})]})}function wr(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function Tr(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function Er(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function Dr({streams:e,brokerProfiles:t,settings:r,motionEnabled:i,motionFpsLive:o}){let s=Tr(t,r.detectionStreamProfile),c=Tr(t,r.motionStreamProfile),l=r.motionSources.includes(`analyzer`);return n(X,{title:`Streams & motion`,children:[n(Z,{label:`Detect stream`,overridden:r.overriddenKeys.has(`detectionStreamProfile`),children:[r.detectionStreamProfile??`—`,s!==void 0&&` · ${s.width}×${s.height} ${s.codec}`]}),u(Z,{label:`Detect FPS`,overridden:r.overriddenKeys.has(`detectionFps`),children:Er(r.detectionFps)}),n(Z,{label:`Motion src`,overridden:r.overriddenKeys.has(`motionSources`),children:[r.motionSources.length>0?r.motionSources.join(` + `):`none`,i===!1&&` · inactive`]}),l&&n(a,{children:[n(Z,{label:`Motion stream`,overridden:r.overriddenKeys.has(`motionStreamProfile`),children:[r.motionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),n(Z,{label:`Motion FPS`,overridden:r.overriddenKeys.has(`motionFps`),children:[Er(r.motionFps),o!==null&&` · live ${o.toFixed(1)}`]})]}),u(Z,{label:`Cooldown`,overridden:r.overriddenKeys.has(`motionCooldownMs`),children:r.motionCooldownMs===null?`default`:`${r.motionCooldownMs/1e3}s`}),u(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?u($,{children:`No streams registered`}):e.map(e=>n(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[u(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,wr(e)]},e.camStreamId))})]})}function Or({steps:e,audioModelId:t,audioEnabled:r,audioMode:i}){return n(X,{title:`Pipeline steps`,children:[e===void 0?u($,{children:`Resolving…`}):e.length===0?u($,{children:`No steps configured`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>u(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:n(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&u(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&n(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),u(`div`,{className:`mt-1`,children:n(Z,{label:`Audio class.`,children:[i??`—`,r!==null&&(r?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var kr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function Ar({detection:e,live:t,detectionMode:r,modeOverridden:i}){if(e===null)return n(X,{title:`Detection runtime`,children:[u(Z,{label:`Mode`,overridden:i,children:r??`—`}),u($,{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,d=je(a),f=a===`active`&&o===0;return n(X,{title:`Detection runtime`,children:[n(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[n(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${d.badgeClass}`,children:[u(ge,{phase:a,className:`h-2.5 w-2.5`}),d.label]}),t!==void 0&&u(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),u(Z,{label:`Mode`,overridden:i,children:r??`—`}),n(Z,{label:`FPS`,children:[u(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),n(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),n(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&n(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&n(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),n(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),n(Z,{label:`Provisioning`,children:[u(Q,{tone:kr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&n(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function jr({broker:e}){return e===null?u(X,{title:`Stream broker`,children:u($,{children:`Broker stage inactive or unreachable`})}):n(X,{title:`Stream broker`,children:[e.profiles.length===0?u($,{children:`No broker profiles`}):u(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,r=t&&e.inFps===0;return n(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${r?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),u(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),n(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),n(`span`,{className:`ml-auto shrink-0 ${r?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),n(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),n(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[n(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),n(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function Mr({decoder:e,detectionActive:t}){if(e===null)return u(X,{title:`Decoder`,children:u($,{children:`Decoder stage inactive or unreachable`})});let r=t&&e.shm.framesWritten===0;return n(X,{title:`Decoder`,children:[u(Z,{label:`Node`,children:e.nodeId}),u(Z,{label:`Sessions`,children:e.sessionCount}),n(Z,{label:`SHM frames`,children:[u(`span`,{className:r?`text-danger font-semibold`:``,children:e.shm.framesWritten}),u(`span`,{className:`text-foreground-subtle`,children:` written`})]}),n(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&n(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),n(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&u(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}t();var Nr=`pipeline-orchestrator`,Pr={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},Fr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Ir({problems:e}){return u(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>n(`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:[u(Ce,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),u(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function Lr({deviceId:e,name:t,online:r,status:a,live:o,onlineNodes:c}){let l=s(),{data:d}=He({addonId:Nr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=Ge({deviceId:e},{staleTime:3e4}),p=i(()=>vr(d),[d]),m=i(()=>f===void 0?void 0:yr(f.steps),[f]),h=i(()=>a===void 0?[]:fr(a),[a]),g=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},_=pe({onSuccess:g}),v=Se({onSuccess:g}),y=t=>{t===`auto`?v.mutate({deviceId:e}):_.mutate({deviceId:e,agentNodeId:t})},b=a===void 0?`idle`:dr(a),x=h.some(e=>e.severity===`error`),S=h.length>0,C=x?`border-danger/50`:S?`border-warning/40`:`border-border`;return n(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${C} bg-background overflow-hidden`,children:[n(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[u(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${x?`bg-danger`:Pr[b]}`,title:x?`Error`:Fr[b],"aria-label":x?`Error`:Fr[b],role:`img`}),u(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),n(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!r&&u(Q,{tone:`danger`,children:`offline`}),n(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&u(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),a?.recording!=null&&(a.recording.active?n(Q,{tone:`danger`,title:`Recording (${a.recording.mode})`,children:[u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):a.recording.mode!==`off`&&n(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,a.recording.mode]}))]})]}),h.length>0&&u(Ir,{problems:h}),a===void 0?u(`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.`}):n(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[u(Cr,{assignment:a.assignment,settings:p,onlineNodes:c,pinPending:_.isPending||v.isPending,onDetectionPinChange:y}),u(Ar,{detection:a.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),u(Or,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:a.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),u(Dr,{streams:a.source.streams,brokerProfiles:a.broker?.profiles,settings:p,motionEnabled:a.motion?.enabled??null,motionFpsLive:a.motion?.fps??null}),u(jr,{broker:a.broker}),u(Mr,{decoder:a.decoder,detectionActive:a.detection?.phase===`active`})]})]})}t();var Rr=5e3,zr=1e4,Br=5e3;function Vr(e){let t=s(),{data:n,isLoading:r}=Ye(),{data:a,isLoading:o}=Ne({},{refetchInterval:Rr}),{nodes:c}=z();d(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[u,f]=l(new Map);B(rt.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&f(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})}),d(()=>{if(u.size===0)return;let e=setInterval(()=>{f(e=>{let t=Date.now()-zr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},Br);return()=>clearInterval(e)},[u.size]);let p=i(()=>{let e=new Map;for(let t of a??[])e.set(t.deviceId,t);return e},[a]);return{rows:i(()=>(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:u,onlineNodes:i(()=>(c??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[c]),isLoading:r||o}}t();function Hr({refreshToken:e}){let{rows:t,liveMetrics:r,onlineNodes:a,isLoading:o}=Vr(e),s=i(()=>[...t.map(e=>{let t=e.status===void 0?[]:fr(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=i(()=>{let e=0,t=0;for(let n of s)(n.errorCount>0||n.warningCount>0)&&(t+=1),(r.get(n.row.deviceId)?.phase??n.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,r]);return o&&t.length===0?u(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?u(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):u(`div`,{className:`h-full overflow-y-auto`,children:n(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[n(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[n(`span`,{children:[u(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),n(`span`,{children:[u(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),n(`span`,{children:[u(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),u(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>u(Lr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:r.get(e.deviceId),onlineNodes:a},e.deviceId))]})})}t();var Ur=`__cluster__`;function Wr(e){return e===`cameras`?`cameras`:`nodes`}function Gr(){let[e,t]=lt(),r=Wr(e.get(`view`)),i=e.get(`node`)??`__cluster__`,[o,s]=l(0),[c,f]=l(!1);return d(()=>{r===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Ur},{replace:!0})},[r,e,t]),n(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[n(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[u(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:i},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,r===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),u(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,r===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),u(`div`,{className:`flex items-center gap-2`,children:n(`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:[u(b,{className:`h-3.5 w-3.5`}),`Refresh`]})})]}),r===`nodes`&&n(`button`,{type:`button`,onClick:()=>f(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:[n(`span`,{children:[c?`Hide`:`Show`,` node list`]}),u(h,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),u(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:r===`nodes`?n(a,{children:[u(`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:u(yt,{selectedNodeId:i,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),f(!1)},refreshToken:o})}),u(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:i===`__cluster__`?u(cr,{refreshToken:o}):u(rn,{nodeId:i,refreshToken:o})})]}):u(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:u(Hr,{refreshToken:o})})})]})}export{Gr as PipelinePage};
|
|
@@ -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{J as l,_t as u,at as d,gt as f,st as p}from"./player-overlays-FVdyuBBK.js";import{$o as m,Cl as h,Cs as g,Ga as _,Gl as v,Il as y,Oa as b,Qo as x,Rl as S,Sn as C,Ss as w,Tn as T,Xo as E,Xt as D,Yo as O,Zo as k,Zr as A,_c as j,_l as M,_o as N,_s as P,_u as ee,bs as te,fc as F,fs as I,gs as ne,hc as L,hs as re,in as ie,it as ae,ja as oe,kc as R,kl as z,ln as B,ms as se,ns as ce,po as le,rs as ue,rt as V,ts as de,vs as fe,ws as pe,xs as me,yc as H,ys as he,za as ge}from"./src-DHelZti5.js";import{i as _e,r as ve}from"./location-owned-usage-Bwv0EIw9.js";import{t as ye}from"./settings-2-DHhHg_JG.js";import{$t as U}from"./src-9HRd-uhT.js";import{t as be}from"./AdminPage-CiKtOLQm.js";import{n as xe}from"./authed-media-DOUf-JTf.js";import{t as Se}from"./DeviceAggregateSection-Bq4Md-AC.js";import{t as Ce}from"./AdminTabs-DEfwmg7J.js";import{t as W}from"./format-size-DIxKXxtj.js";import{t as G}from"./StorageLocationsPanel-qfEwA1kH.js";var K=u(`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`}]]),we=u(`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`}]]);t();var Te=[{value:`all`,label:`All`},{value:`recording`,label:`Recordings`},{value:`events`,label:`Events`}],Ee={recording:`bg-primary/10 text-primary`,events:`bg-violet-500/10 text-violet-400`},De={columnKey:`at`,dir:`desc`};function Oe(e){return new Date(e).toLocaleString()}function ke(){let[e,t]=o(`all`),{data:a,isLoading:c,isError:l}=ce({},{refetchOnWindowFocus:!1}),{data:u,isLoading:d,isError:f}=ge({},{refetchOnWindowFocus:!1}),{data:p}=A({isCamera:!0,projection:`slim`}),m=r(()=>{let e=new Map;for(let t of p??[])e.set(t.id,t.name);return e},[p]),h=r(()=>{let t=[...a??[],...u??[]];return(e===`all`?t:t.filter(t=>t.domain===e)).toSorted((e,t)=>t.at-e.at)},[a,u,e]),g=r(()=>{let t=[];return l&&e!==`events`&&t.push(`Recordings`),f&&e!==`recording`&&t.push(`Events`),t},[l,f,e]),_=r(()=>[{key:`at`,header:`When`,nowrap:!0,sortValue:e=>e.at,render:e=>s(`span`,{className:`text-foreground-subtle tabular-nums`,children:Oe(e.at)})},{key:`domain`,header:`Domain`,sortValue:e=>e.domain,render:e=>s(`span`,{className:`inline-flex rounded px-1.5 py-0.5 text-[10px] font-medium ${Ee[e.domain]}`,children:e.domain})},{key:`op`,header:`Operation`,sortValue:e=>e.op,render:e=>s(`span`,{className:`text-foreground`,children:e.op})},{key:`reason`,header:`Reason`,sortValue:e=>e.reason,render:e=>s(`span`,{className:`text-foreground-subtle`,children:e.reason})},{key:`device`,header:`Camera`,sortValue:e=>e.deviceId===null?`cluster`:m.get(e.deviceId)??`#${String(e.deviceId)}`,render:e=>e.deviceId===null?s(`span`,{className:`text-foreground-subtle`,children:`cluster`}):s(`span`,{className:`text-foreground`,children:m.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`items`,header:`Items`,align:`right`,nowrap:!0,sortValue:e=>e.itemsAffected,render:e=>s(`span`,{className:`tabular-nums`,children:e.itemsAffected.toLocaleString()})},{key:`bytes`,header:`Reclaimed`,align:`right`,nowrap:!0,sortValue:e=>e.bytesReclaimed,render:e=>s(`span`,{className:`tabular-nums`,children:e.bytesReclaimed>0?W(e.bytesReclaimed):`—`})}],[m]),v=c||d;return n(`div`,{className:`flex flex-col gap-4`,children:[s(`div`,{className:`flex items-center gap-1`,children:Te.map(n=>s(`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))}),v&&h.length===0?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(M,{className:`h-4 w-4 animate-spin`}),`Loading activity…`]}):h.length===0?g.length>0?s(D,{icon:R,title:`Activity could not be read`,description:`The ${g.join(` and `)} ops log did not answer. This is not "nothing happened" — retry, or check the node that owns it.`}):s(D,{icon:ee,title:`No activity yet`,description:`Prune, delete and rescan operations across recordings and events show up here.`}):n(i,{children:[g.length>0&&n(`p`,{className:`flex items-center gap-1.5 text-[11px] text-amber-500`,children:[s(R,{className:`h-3 w-3 shrink-0`}),g.join(` and `),` did not answer — rows from`,` `,g.length===1?`that domain`:`those domains`,` are missing below.`]}),s(V,{columns:_,rows:h,rowKey:e=>e.id,minWidthPx:720,mobileMode:`scroll`,maxBodyHeight:ae,defaultSort:De})]})]})}t();function Ae(){let e=A({isCamera:!0,projection:`slim`}),t=r(()=>(e.data??[]).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data]),[i,a]=o(null),c=i??t[0]?.id??null;return!e.isLoading&&t.length===0?s(D,{icon:f,title:`No cameras`,description:`Add a camera first.`}):n(`div`,{className:`space-y-3`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Per-camera recording & retention`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Recording mode, schedule bands and the retention policy for one camera — the same controls as the camera's own Recording tab. Retention is one policy over footage and analytics; per-camera event deletion lives on the Events tab.`})]}),n(`div`,{className:`flex items-center gap-2`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Camera`}),s(`select`,{value:c??``,onChange:e=>a(Number(e.target.value)),className:`rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:t.map(e=>s(`option`,{value:e.id,children:e.name},e.id))})]}),c!==null&&s(ie,{deviceId:c,children:s(Se,{deviceId:c,sectionFilter:e=>e.location===`top-tab`&&e.tab===`recording`})},c)]})}t();var je=`pipeline-analytics`;function Me(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 Ne(){let e=a(),{nodes:t}=F(),{data:i,isLoading:o}=C({addonId:je}),c=Me(i),l=T({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:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),s(`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:[o?s(M,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):s(`select`,{value:c,onChange:e=>{e.target.value!==c&&l.mutate({addonId:je,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=>s(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),l.isPending&&s(M,{className:`h-4 w-4 animate-spin text-primary`})]})]}),n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),s(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),s(G,{types:[`eventMedia`]})]})]})}t();var Pe=[[`pipelineAnalytics`]],Fe=1440*60*1e3;function Ie(e,t){return t.get(e)??`Removed camera #${String(e)}`}var Le=[{days:1,label:`1 day`},{days:7,label:`7 days`},{days:30,label:`30 days`},{days:90,label:`90 days`}];function Re(){let t=a(),i=B(),[c,u]=o(30),[d,f]=o(null),{data:m,isLoading:h}=oe({},{refetchOnWindowFocus:!1}),{data:g}=A({isCamera:!0,projection:`slim`}),v=r(()=>{let e=new Map;for(let t of g??[])e.set(t.id,t.name);return e},[g]),y=e(()=>{t.invalidateQueries({queryKey:Pe})},[t]),x=_({onSuccess:y}),C=b(),w=e(async()=>{await i({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`})&&x.mutate({olderThanMs:Date.now()-c*Fe,reason:`retention`})},[i,x,c]),T=e(async e=>{let t=Ie(e.deviceId,v);if(await i({title:`Delete all events for ${t}?`,message:`Permanently deletes ${String(e.rows)} event${e.rows===1?``:`s`} (${W(e.bytes)} of media) for this camera. This cannot be undone.`,confirmLabel:`Delete events`,variant:`danger`})){f(null);try{let n=await C.mutateAsync({deviceId:e.deviceId});y();let r=n.motion+n.object+n.audio;if(r===0&&e.bytes>0){f(`0 events deleted for ${t}. Media still listed (${W(e.bytes)}) — those blobs are not event rows; use Management → Count leftovers or Disk reconcile.`);return}f(`Deleted ${String(r)} event${r===1?``:`s`} for ${t}.`)}catch(e){f(e instanceof Error?e.message:String(e))}}},[i,C,v,y]),E=r(()=>[{key:`camera`,header:`Camera`,render:e=>s(`span`,{className:`text-foreground`,children:Ie(e.deviceId,v)})},{key:`rows`,header:`Events`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:e.rows.toLocaleString()})},{key:`bytes`,header:`Media`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:W(e.bytes)})},{key:`actions`,header:``,align:`right`,render:e=>n(`button`,{onClick:()=>{T(e)},disabled:C.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:[s(p,{className:`h-3 w-3`}),`Delete`]})}],[v,T,C.isPending]);return h&&!m?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(M,{className:`h-4 w-4 animate-spin`}),`Loading event-store footprint…`]}):m?n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[s(l,{label:`Total events`,icon:s(S,{className:`h-3 w-3`}),footer:`across ${String(m.devices.length)} camera${m.devices.length===1?``:`s`}`,children:m.totalRows.toLocaleString()}),s(l,{label:`Event media on disk`,children:W(m.totalBytes)})]}),n(`section`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[s(`span`,{className:`text-foreground-subtle`,children:`Prune events older than`}),s(`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:Le.map(e=>s(`option`,{value:e.days,children:e.label},e.days))}),n(`button`,{onClick:()=>{w()},disabled:x.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:[x.isPending?s(M,{className:`h-3 w-3 animate-spin`}):s(we,{className:`h-3 w-3`}),`Prune now`]})]}),m.devices.length===0?s(D,{icon:S,title:`No stored events`,description:`No camera has persisted events yet.`}):s(V,{columns:E,rows:[...m.devices],rowKey:e=>e.deviceId,minWidthPx:480}),d===null?null:s(`p`,{className:d.startsWith(`Deleted `)?`text-[11px] text-foreground-subtle`:`text-[11px] text-destructive`,children:d})]}):s(D,{icon:S,title:`No event data`,description:`Pipeline analytics has not reported any event-store footprint yet.`})}function ze(){return n(`div`,{className:`flex flex-col gap-8`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Event store`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`What the durable event store occupies, per camera, with fleet-wide prune-by-age and delete-all-events.`}),s(`div`,{className:`mt-3`,children:s(Re,{})})]}),n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node & folders`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that writes event crops, and the storage location they land in.`}),s(`div`,{className:`mt-3`,children:s(Ne,{})})]})]})}function Be(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 Ve(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function He(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`${Ve(e)} · ${o}`}function Ue(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 We(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 Ge=[`high`,`mid`,`low`],Ke=[{value:1,label:`Real time (1×)`},{value:2,label:`2×`},{value:4,label:`4×`},{value:8,label:`8×`},{value:16,label:`16×`}],qe=10080*60*1e3;function Je(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 Ye({onClose:e,onCreated:t}){let i=A({isCamera:!0,projection:`slim`}),a=r(()=>(i.data??[]).toSorted((e,t)=>e.name.localeCompare(t.name)),[i.data]),[c,l]=o(``),[u,d]=o(`high`),[f,p]=o(Je(60)),[m,h]=o(Je(0)),[g,_]=o(1),[v,y]=o(!0),[b,x]=o(``),[S,C]=o(null),w=c===``?a[0]?.id??null:c,T=new Date(f).getTime(),E=new Date(m).getTime(),D=Number.isFinite(T)&&Number.isFinite(E)&&T<E,O=k({onSuccess:()=>{t(),e()},onError:e=>C(e instanceof Error?e.message:String(e))});return s(`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:[s(z,{className:`h-3.5 w-3.5`}),`New export`]}),s(`button`,{onClick:e,className:`text-foreground-subtle hover:text-foreground`,children:s(H,{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:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Camera`}),s(`select`,{value:w??``,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:a.map(e=>s(`option`,{value:e.id,children:e.name},e.id))})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Profile`}),s(`select`,{value:u,onChange:e=>d(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:Ge.map(e=>s(`option`,{value:e,children:e},e))})]})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`From`}),s(`input`,{type:`datetime-local`,value:f,onChange:e=>p(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`To`}),s(`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:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Speed`}),s(`select`,{value:g,onChange:e=>_(Number(e.target.value)),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:Ke.map(e=>s(`option`,{value:e.value,children:e.label},e.value))})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Title (optional)`}),s(`input`,{type:`text`,value:b,onChange:e=>x(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:[s(`input`,{type:`checkbox`,checked:v,disabled:g!==1,onChange:e=>y(e.target.checked),className:`accent-primary`}),`Include audio`,g===1?``:` (real-time only)`]}),!D&&s(`p`,{className:`text-[11px] text-danger`,children:`"From" must be before "To".`}),S&&s(`p`,{className:`text-[11px] text-danger`,children:S})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[s(`button`,{onClick:e,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>{if(w===null||!D)return;C(null);let e=b.trim();O.mutate({deviceId:w,profile:u,fromMs:T,toMs:E,options:{includeAudio:v,maxLifeMs:qe,deleteAfterDownload:!1,...g===1?{}:{speed:g},...e.length>0?{title:e}:{}}})},disabled:w===null||!D||O.isPending,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:O.isPending?`Queuing…`:`Create export`})]})]})})}t();var Xe=[[`recordingExport`]],Ze={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 Qe(){let{data:e,isLoading:t}=m({},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`queued`||e.state===`rendering`)?3e3:!1}),{map:n}=L(U.RecordingExportProgress,e=>e.exportId),{map:i}=L(U.RecordingExportCompleted,e=>e.exportId),{map:a}=L(U.RecordingExportFailed,e=>e.exportId);return{rows:r(()=>We(e??[],n,i,a),[e,n,i,a]),isLoading:t}}function $e(e){let[t,n]=o(()=>Date.now());return c(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function et(){let t=a(),[i,c]=o(!1),l=()=>{t.invalidateQueries({queryKey:[[`recordingExport`,`listExports`]]})},u=B(),f=d().trpcClient,m=$e(6e4),{rows:h,isLoading:g}=Qe(),{data:_}=A({isCamera:!0,projection:`slim`}),b=r(()=>{let e=new Map;for(let t of _??[])e.set(t.id,t.name);return e},[_]),S=e(()=>{t.invalidateQueries({queryKey:Xe})},[t]),C=E({onSuccess:S}),w=x({onSuccess:S}),[T,O]=o(null),k=e(async e=>{O(e.id);try{let{url:t}=await f.recordingExport.getDownloadUrl.query({exportId:e.id}),n=await xe(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),S()}finally{O(null)}},[f,S]),j=e(async e=>{await u({title:`Cancel this export?`,message:`Stops the render. The partial file is discarded.`,confirmLabel:`Cancel export`,variant:`danger`})&&C.mutate({exportId:e.id})},[u,C]),N=e(async e=>{await u({title:`Delete this export?`,message:`Permanently removes the rendered file and its history row.`,confirmLabel:`Delete`,variant:`danger`})&&w.mutate({exportId:e.id})},[u,w]),P=r(()=>[{key:`camera`,header:`Camera`,render:e=>s(`span`,{className:`text-foreground`,children:b.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`range`,header:`Range`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:He(e.fromMs,e.toMs)})},{key:`variant`,header:`Variant`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:Be(e.options)})},{key:`state`,header:`State`,render:e=>{let t=Ze[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&&s(M,{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`?s(`span`,{className:`text-foreground-subtle`,children:`—`}):s(`span`,{className:`text-foreground-subtle tabular-nums`,children:Ue(e.expiresAt,m)})},{key:`size`,header:`Size`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:e.fileBytes===null?`—`:W(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:()=>{k(e)},disabled:T===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:[T===e.id?s(M,{className:`h-3 w-3 animate-spin`}):s(y,{className:`h-3 w-3`}),`Download`]}),r&&n(`button`,{onClick:()=>{j(e)},disabled:C.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:[s(v,{className:`h-3 w-3`}),`Cancel`]}),i&&s(`button`,{onClick:()=>{N(e)},disabled:w.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:s(p,{className:`h-3 w-3`})})]})}}],[b,m,T,C.isPending,w.isPending,k,j,N]);return g&&h.length===0?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(M,{className:`h-4 w-4 animate-spin`}),`Loading exports…`]}):n(`div`,{className:`space-y-3`,children:[s(`div`,{className:`flex justify-end`,children:n(`button`,{onClick:()=>c(!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:[s(z,{className:`h-3.5 w-3.5`}),`New export`]})}),h.length===0?s(D,{icon:z,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.`}):s(V,{columns:P,rows:h,rowKey:e=>e.id,minWidthPx:720}),i&&s(Ye,{onClose:()=>c(!1),onCreated:l})]})}function tt(e){return e===null?`absent`:e.providers.length>0?`present`:`absent`}function nt(e){let t=j.capabilities.getCapability.useQuery({name:e});return t.status===`pending`?`pending`:t.status===`error`?`unknown`:tt(t.data)}var rt=`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`;t();var it=`storage-migration`,at=new Set([`orphans`,`debug-media`,`ghost-ledger`]);function ot(e){return[`${e.orphansReclaimed} orphan rows (${W(e.orphanBytesReclaimed)})`,e.includeDebugMedia?`${e.debugMediaReclaimed} debug files (${W(e.debugMediaBytesReclaimed)})`:null,`${e.ghostsForgotten} ghost rows (${W(e.ghostBytesForgotten)})`].filter(e=>e!==null).join(` · `)}function st(){let e=nt(it);return e===`pending`?null:e===`unknown`?s(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`Could not check whether storage cleanup is installed on this hub.`}):e===`present`?s(ct,{}):null}function ct(){let e=B(),[t,r]=o(!1),[i,a]=o(null),c=P({},{refetchInterval:2e3}),l=c.data??null,u=l!==null&&at.has(l.phase),d=ne(),f=re(),m=async()=>{if(await e({title:`Run storage cleanup?`,message:t?`Reclaims leftover analytics rows and files, debug stills/filmstrips, and ghost footage rows on frozen locations. Safe to re-run.`:`Reclaims leftover analytics rows and files, and ghost footage rows on frozen locations. Debug stills are left alone. Safe to re-run.`,confirmLabel:`Run cleanup`,variant:`danger`})){a(null);try{await d.mutateAsync({includeDebugMedia:t}),await c.refetch()}catch(e){a(e instanceof Error?e.message:String(e))}}},h=async()=>{if(l&&await e({title:`Cancel cleanup?`,message:`Stops after the current step. Work already done stays done.`,confirmLabel:`Cancel cleanup`,variant:`danger`}))try{await f.mutateAsync({jobId:l.jobId}),await c.refetch()}catch{}};return n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Cleanup`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`One pass over leftover analytics (database + files) and ghost footage rows on frozen locations. Does not time out — progress updates here until it finishes.`}),n(`label`,{className:`mt-3 flex items-start gap-2 text-[11px] text-foreground`,children:[s(`input`,{type:`checkbox`,checked:t,disabled:u,onChange:e=>{r(e.target.checked)},className:`mt-0.5 h-3.5 w-3.5 accent-primary`}),s(`span`,{children:`Also remove debug media (motion stills and track filmstrips)`})]}),n(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[n(`button`,{type:`button`,disabled:u||d.isPending,onClick:()=>{m()},className:rt,children:[(u||d.isPending)&&s(M,{className:`h-3 w-3 animate-spin`}),s(p,{className:`h-3 w-3`}),`Run cleanup`]}),u&&s(`button`,{type:`button`,onClick:()=>{h()},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:`Cancel`})]}),i&&s(`p`,{className:`mt-2 text-[11px] text-danger`,children:i}),l&&n(`div`,{className:`mt-3 space-y-1 rounded-md border border-border px-2.5 py-2`,children:[n(`p`,{className:`text-xs text-foreground`,children:[`Phase: `,s(`span`,{className:`font-medium`,children:l.phase}),u&&s(M,{className:`ml-2 inline h-3 w-3 animate-spin text-primary`})]}),l.detail&&s(`p`,{className:`text-[11px] text-foreground-subtle`,children:l.detail}),s(`p`,{className:`text-[11px] text-foreground-subtle`,children:ot(l)}),l.error&&s(`p`,{className:`text-[11px] text-danger`,children:l.error})]})]})}t();var lt=2e3;function ut(){let e=B(),t=a(),r=N(),i=le(void 0,{refetchInterval:e=>e.state.data?.state===`running`?lt:!1}),o=i.data,l=o?.state===`running`,u=l||r.isPending;c(()=>{o?.state!==`done`||o.finishedAtMs===null||(t.invalidateQueries({queryKey:[[`recording`]]}),t.invalidateQueries({queryKey:[[`pipelineAnalytics`]]}))},[o?.state,o?.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 i.refetch())},f=l?o.total>0?`Reconciling ${String(o.completed)}/${String(o.total)}…`:`Reconciling…`:r.isPending?`Reconciling…`:`Reconcile from disk`;return n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Disk reconcile`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Deletes database rows whose files are gone. Enrolled identities stay.`}),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?s(M,{className:`h-3.5 w-3.5 animate-spin`}):s(h,{className:`h-3.5 w-3.5`}),f]}),o?.state===`done`?n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Last run: `,String(o.completed),` camera(s) — dropped `,String(o.tracks),` tracks,`,` `,String(o.events),` events, `,String(o.mediaDropped),` media`,o.failed.length>0?`, ${String(o.failed.length)} failed (${o.failed.join(`, `)})`:``,`.`]}):null,o?.state===`error`&&o.error!==null?n(`p`,{className:`text-[11px] text-destructive`,children:[`Reconcile failed: `,o.error]}):null]})]})}var q=1e3,J=60*q,Y=60*J;function X(e){return e.toLocaleString(`en-US`)}function dt(e){if(!Number.isFinite(e)||e<0)return`—`;if(e>=Y){let t=Math.floor(e/Y),n=Math.round(e%Y/J);return`${t.toString()}h ${n.toString()}m`}if(e>=J){let t=Math.floor(e/J),n=Math.round(e%J/q);return`${t.toString()}m ${n.toString()}s`}return`${Math.max(0,Math.round(e/q)).toString()}s`}function ft(e){let t=Math.max(0,e.observedAt-e.startedAt),n=e.filesTotal===null?`${X(e.filesMoved)} files`:`${X(e.filesMoved)} / ${X(e.filesTotal)} files`,r=e.filesTotal===null||e.filesTotal===0?null:Math.min(1,e.filesMoved/e.filesTotal),i=t>0&&e.filesMoved>0,a=i?`${W(e.bytesMoved/t*q)}/s`:null,o=e.filesTotal===null?null:e.filesTotal-e.filesMoved,s=!i||o===null||o<=0?null:`~${dt(o*t/e.filesMoved)} left`;return{counted:n,fraction:r,moved:`${W(e.bytesMoved)} moved`,rate:a,eta:s}}function pt(e){let t=ft(e);return[t.counted,t.moved,t.rate,t.eta].filter(e=>e!==null).join(` · `)}t();var mt=`storage-migration`,Z=[{id:`recordings`,label:`Recordings`,locationType:`recordings`},{id:`recordingsLow`,label:`Low-res recordings`,locationType:`recordingsLow`},{id:`eventMedia`,label:`Event media`,locationType:`eventMedia`}],ht=new Set([`planning`,`sealing`,`pausing`,`moving`,`draining`,`verifying`,`repointing`,`refreshing`,`resuming`]);function gt(){let e=nt(mt);return e===`pending`?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(M,{className:`h-4 w-4 animate-spin`}),`Checking whether storage migration is installed…`]}):e===`unknown`?s(D,{icon:R,title:`Couldn't check whether storage migration is installed`,description:`The capability registry did not answer, so this panel has nothing to report either way — it is not a statement that the capability is missing. Reload to ask again.`}):e===`absent`?s(D,{icon:K,title:`Storage migration not installed`,description:`The capability registry answered: no addon in this cluster provides storage-migration. Once one is deployed, this panel moves recordings, low-res recordings and event media to new storage locations in one coordinated, verified operation.`}):s(_t,{})}function _t(){let e=B(),{data:t}=I({}),[i,a]=o({}),[c,l]=o({}),[u,d]=o(null),[f,p]=o(null),m=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]),h=r(()=>{let e=new Map;for(let n of t??[]){if(n.enabled===!1)continue;let t=e.get(n.type);t?t.push(n.id):e.set(n.type,[n.id])}let n=new Map;for(let[t,r]of e)r.length===1&&n.set(t,r[0]);return n},[t]),_=pe({},{refetchInterval:2e3}),v=_.data??null,y=v!==null&&ht.has(v.phase),b=r(()=>{let e={};for(let t of Z){let n=i[t.id];n&&(e[t.id]=n)}return Object.keys(e).length>0?e:void 0},[i]),x=r(()=>{let e={};for(let t of Z){if(!i[t.id])continue;let n=c[t.id]??h.get(t.locationType);n&&(e[t.id]=n)}return Object.keys(e).length>0?e:void 0},[i,c,h]),S=r(()=>({destinations:b??{},...x?{sources:x}:{}}),[b,x]),C=me(S,{enabled:!1,retry:!1}),w=g(),T=se(),E=async()=>{if(!b)return;p(null);let e=await C.refetch();if(e.error){p(e.error instanceof Error?e.error.message:String(e.error));return}d(e.data??null)},D=async()=>{if(b&&await e({title:`Start storage migration?`,message:`Copies the selected classes from the chosen source to the destination, verifies, then either makes the destination the default (if the source was) or disables the source. Safe to re-run if interrupted.`,confirmLabel:`Start migration`,variant:`danger`})){p(null);try{await w.mutateAsync(S),d(null),await _.refetch()}catch(e){p(e instanceof Error?e.message:String(e))}}},O=async()=>{if(v&&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 T.mutateAsync({jobId:v.jobId}),await _.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:[s(K,{className:`h-3.5 w-3.5`}),`Storage migration`]}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Move recordings, low-res recordings and/or event media from one location to another: copies via the recorder / pipeline-analytics movers, verifies, then either repoints the default (when the source was the default) or disables the source (when it was not). Skip a class with an empty destination.`}),s(`div`,{className:`mt-3 grid grid-cols-1 gap-3 sm:grid-cols-3`,children:Z.map(e=>{let t=m.get(e.locationType)??[],r=h.get(e.locationType)??``;return n(`div`,{className:`space-y-2`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e.label}),n(`div`,{className:`space-y-1`,children:[n(`label`,{htmlFor:`migration-from-${e.id}`,className:`text-[10px] text-foreground-subtle`,children:[e.label,` from`]}),s(`select`,{id:`migration-from-${e.id}`,value:c[e.id]??r,onChange:t=>{let n=t.target.value;l(t=>({...t,[e.id]:n}))},disabled:y,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,children:t.map(e=>n(`option`,{value:e.id,children:[e.displayName,e.enabled===!1?` (read-only)`:``]},e.id))})]}),n(`div`,{className:`space-y-1`,children:[n(`label`,{htmlFor:`migration-dest-${e.id}`,className:`text-[10px] text-foreground-subtle`,children:[e.label,` to`]}),n(`select`,{id:`migration-dest-${e.id}`,value:i[e.id]??``,onChange:t=>{let n=t.target.value;a(t=>({...t,[e.id]:n}))},disabled:y,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,children:[s(`option`,{value:``,children:`— skip —`}),t.map(e=>s(`option`,{value:e.id,children:e.displayName},e.id))]})]})]},e.id)})}),f&&s(`p`,{className:`mt-2 text-[11px] text-danger`,children:f}),n(`div`,{className:`mt-3 flex items-center gap-2`,children:[n(`button`,{type:`button`,onClick:()=>{E()},disabled:!b||C.isFetching||y,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:[C.isFetching&&s(M,{className:`h-3 w-3 animate-spin`}),`Plan`]}),n(`button`,{type:`button`,onClick:()=>{D()},disabled:!b||w.isPending||y,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:[w.isPending&&s(M,{className:`h-3 w-3 animate-spin`}),`Start migration`]})]}),u&&s(`div`,{className:`mt-3 divide-y divide-border rounded-md border border-border`,children:u.moves.length===0?s(`p`,{className:`px-2.5 py-1.5 text-[11px] text-foreground-subtle`,children:`Nothing to move — selected destinations match the current defaults.`}):u.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}`))}),v&&n(`div`,{className:`mt-4 border-t border-border pt-3`,children:[n(`div`,{className:`flex items-center justify-between`,children:[s(`h4`,{className:`text-xs font-semibold text-foreground`,children:`Migration status`}),y&&n(`button`,{type:`button`,onClick:()=>{O()},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:[s(H,{className:`h-3 w-3`}),`Cancel`]})]}),n(`p`,{className:`mt-1 text-xs text-foreground`,children:[`Phase: `,s(`span`,{className:`font-medium`,children:v.phase}),y&&s(M,{className:`ml-2 inline h-3 w-3 animate-spin text-primary`})]}),v.error&&s(`p`,{className:`mt-1 text-[11px] text-danger`,children:v.error}),v.pausedParticipants.length>0&&n(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:[`Paused: `,v.pausedParticipants.join(`, `)]}),s(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:v.moves.map(e=>s(vt,{move:e},`${e.storageClass}-${e.fromLocationId}`))})]}),s(yt,{})]}),s(bt,{running:y}),s(St,{})]})}function vt({move:e}){let t=e.progress===null?null:ft(e.progress);return n(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:[n(`div`,{className:`flex items-center justify-between`,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.progress!==null&&n(`div`,{className:`mt-1 space-y-1`,children:[t!==null&&t.fraction!==null&&s(`div`,{className:`h-1 w-full overflow-hidden rounded bg-border`,children:s(`div`,{className:`h-full bg-primary`,style:{width:`${(t.fraction*100).toFixed(1)}%`}})}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:pt(e.progress)})]})]})}function yt(){let{data:e}=he({});return!e||e.length===0?null:n(`div`,{className:`mt-4 border-t border-border pt-3`,children:[s(`h4`,{className:`text-xs font-semibold text-foreground`,children:`Migration history`}),s(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:e.map(e=>n(`div`,{className:`px-2.5 py-1.5 text-[11px] text-foreground-subtle`,children:[s(`span`,{className:`font-medium text-foreground`,children:e.phase}),` · `,Object.entries(e.destinations).filter(e=>typeof e[1]==`string`).map(([e,t])=>`${e} → ${t}`).join(`, `),` · `,new Date(e.startedAt).toLocaleString()]},e.jobId))})]})}function bt({running:e}){let t=B(),r=w({},{staleTime:1/0,refetchOnWindowFocus:!1}),i=fe(),[a,c]=o(null),l=r.data??[];if(l.length===0)return null;let u=async e=>{if(await t({title:`Drain remaining ${e.storageClass}?`,message:`Moves what is still on ${e.fromLocationId} to ${e.toLocationId}. Nothing is paused and no default is changed — this is the second half of a migration, run on its own. It is resumable: cancelling leaves everything readable from both locations.`,confirmLabel:`Drain remaining`,variant:`danger`})){c(null);try{await i.mutateAsync({classes:[e.storageClass]}),await r.refetch()}catch(e){c(e instanceof Error?e.message:String(e))}}};return n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[n(`div`,{className:`flex items-start justify-between gap-2`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Left on the old location`}),n(`div`,{className:`flex shrink-0 items-center gap-2`,children:[s(`span`,{className:`text-[10px] text-foreground-subtle`,children:r.dataUpdatedAt>0?`Measured ${new Date(r.dataUpdatedAt).toLocaleTimeString()}`:`Measured — never`}),s(`button`,{type:`button`,onClick:()=>{r.refetch()},disabled:r.isFetching,className:`rounded border border-border px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`,children:r.isFetching?`Counting…`:`Refresh`})]})]}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`A migration repoints first and drains behind. If the drain was cancelled, failed, or was interrupted by a restart, the data below is still on the source — readable, but not where the defaults now point. Draining moves it; it changes no default and pauses nothing.`}),s(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`This count is taken on demand: measuring it walks the whole media collection, so it is not refreshed on a timer. Press Refresh after a drain finishes.`}),a&&s(`p`,{className:`mt-2 text-[11px] text-danger`,children:a}),s(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:l.map(t=>n(`div`,{className:`flex items-center justify-between gap-2 px-2.5 py-1.5 text-[11px]`,children:[n(`span`,{className:`text-foreground`,children:[t.storageClass,`: `,t.fromLocationId,` → `,t.toLocationId,s(`span`,{className:`ml-2 text-foreground-subtle`,children:xt(t)})]}),s(`button`,{type:`button`,onClick:()=>{u(t)},disabled:e||i.isPending,className:`shrink-0 rounded border border-border px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`,children:`Drain remaining`})]},`${t.storageClass}-${t.fromLocationId}`))})]})}function xt(e){if(e.items===null)return`amount unknown — the archive could not be read`;let t=e.items.toLocaleString(`en-US`);return e.bytes===null?`${t} rows`:`${t} segments · ${W(e.bytes)}`}function St(){let{data:e}=te({},{refetchInterval:2e3}),t=(e??[]).filter(e=>e.migrationJobId===null&&e.job.state===`running`);return t.length===0?null:n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Movers running outside a migration`}),s(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:t.map(e=>n(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:[n(`div`,{className:`text-foreground`,children:[e.lane,`: `,e.job.fromLocationId,` → `,e.job.toLocationId]}),s(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:pt({filesMoved:e.job.filesMoved,filesTotal:e.job.filesTotal,bytesMoved:e.job.bytesMoved,startedAt:e.job.startedAt,observedAt:e.observedAt})})]},e.job.jobId))})]})}function Ct(){return n(`div`,{className:`flex flex-col gap-4`,children:[s(st,{}),s(ut,{}),n(`section`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Move storage`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Copy recordings, low-res recordings or event media to a new location, verify, then repoint the default. Applies to every camera.`}),s(`div`,{className:`mt-3`,children:s(gt,{})})]})]})}t();var wt=`recorder`;function Tt(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 Et(){let e=a(),{nodes:t}=F(),{data:i,isLoading:o}=C({addonId:wt}),c=Tt(i,`recordingNodeId`,`hub`),l=T({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:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),s(`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:[o?s(M,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):s(`select`,{value:c,onChange:e=>{e.target.value!==c&&l.mutate({addonId:wt,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=>s(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),l.isPending&&s(M,{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`,` `,s(`span`,{className:`font-medium`,children:c}),`. If the auto-derived host doesn't work, set the recorder's`,s(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),s(`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.`}),s(G,{types:[`recordings`,`recordingsLow`]})]})]})}function Dt(e){return e.locationIds!==void 0&&e.locationIds.length>0?e.locationIds:e.locationId===null?[]:[e.locationId]}function Q(e,t){let n=Dt(e);return n.length===0?`default root`:n.map(e=>t.get(e)??e).join(` + `)}function Ot(e,t,n){if(e.length===0)return null;let r=e[0];if(e.length===1&&r!==void 0)return{label:Q(r,t),exact:!0};if(n===null)return null;let i=e.find(e=>Dt(e).includes(n));return i===void 0?null:{label:Q(i,t),exact:!1}}t();var kt=[[`recording`]],At=[{value:`retention`,label:`Retention policy`},{value:`quota`,label:`Quota / disk pressure`},{value:`operator`,label:`Operator`}],jt={ok:`bg-primary`,warn:`bg-amber-500`,critical:`bg-danger`},Mt={ok:`text-foreground-subtle`,warn:`text-amber-500`,critical:`text-danger`};function $(e){return`${String(Math.round(e*100))}%`}function Nt(e){return e==null?`—`:new Date(e).toLocaleString()}function Pt(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 Ft(){let t=a(),i=B(),[c,u]=o(`retention`),{data:d,isLoading:f}=de({},{refetchOnWindowFocus:!1}),{data:m}=A({isCamera:!0,projection:`slim`}),{data:g}=I({}),_=r(()=>{let e=new Map;for(let t of m??[])e.set(t.id,t.name);return e},[m]),v=r(()=>{let e=new Map;for(let t of g??[])e.set(t.id,t.displayName);return e},[g]),y=r(()=>{let e=g??[];return e.find(e=>e.type===`recordings`&&e.enabled!==!1)?.id??e.find(e=>e.type===`recordings`)?.id??null},[g]),b=r(()=>d?.locations??[],[d?.locations]),x=r(()=>Ot(b,v,y),[b,v,y]),S=r(()=>_e(b),[b]),C=e(()=>{t.invalidateQueries({queryKey:kt})},[t]),w=ue({onSuccess:C}),T=O({onSuccess:C}),E=e(async e=>{await i({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`})&&w.mutate({deviceId:e.deviceId,reason:c})},[i,w,c,_]),k=e(async e=>{await i({title:`Delete all footage for ${_.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${W(e.usedBytes)} of recorded footage for this camera. This cannot be undone.`,confirmLabel:`Delete ${W(e.usedBytes)}`,variant:`danger`})&&T.mutate({deviceId:e.deviceId})},[i,T,_]),j=r(()=>[{key:`camera`,header:`Camera`,render:e=>s(`span`,{className:`text-foreground`,children:_.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`disk`,header:`Disk`,nowrap:!0,render:()=>x===null?s(`span`,{className:`text-foreground-subtle`,children:`—`}):n(`span`,{className:x.exact?`text-foreground`:`text-foreground-subtle`,title:x.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:[x.label,!x.exact&&s(`span`,{className:`ml-1 text-foreground-subtle`,children:`(default)`})]})},{key:`used`,header:`Used`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:W(e.usedBytes)})},{key:`oldest`,header:`Oldest footage`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums text-foreground-subtle`,title:`The oldest segment the ARCHIVE holds for this camera — the per-camera answer to 'is retention actually holding?'.`,children:Nt(e.oldestMs)})},{key:`actions`,header:``,align:`right`,render:e=>n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{E(e)},disabled:w.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:[s(we,{className:`h-3 w-3`}),`Prune`]}),n(`button`,{onClick:()=>{k(e)},disabled:T.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete all footage`,children:[s(p,{className:`h-3 w-3`}),`Delete`]})]})}],[_,x,E,k,w.isPending,T.isPending]);if(f&&!d)return n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(M,{className:`h-4 w-4 animate-spin`}),`Loading storage usage…`]});if(!d)return s(D,{icon:h,title:`No storage data`,description:`The recording node has not reported any storage usage yet.`});let N=d.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:[s(l,{label:`Total used`,icon:s(h,{className:`h-3 w-3`}),footer:`${String(N)} camera${N===1?``:`s`} on ${d.nodeId}`,children:W(d.totalUsedBytes)}),S!==null&&S.severity!==null&&s(l,{label:`Free on recordings volumes`,icon:s(h,{className:`h-3 w-3`}),footer:`across ${String(S.knownVolumes)} volume${S.knownVolumes===1?``:`s`} of ${W(S.totalBytes)}`+(S.unknownVolumes>0?` · ${String(S.unknownVolumes)} did not report capacity`:``),children:s(`span`,{className:`tabular-nums ${Mt[S.severity]}`,children:W(S.freeBytes)})}),b.map(e=>{let t=ve(e),r=e.locationId??e.root??`default`;return s(l,{label:`Disk: ${Pt(e,v)}`,footer:t===null?`${W(e.usedBytes)} of recordings · volume capacity unknown`:`${W(t.freeBytes)} free of ${W(t.totalBytes)} · ${W(e.usedBytes)} recordings (${$(t.recordingsFraction)})`,children:t===null?s(`span`,{className:`tabular-nums`,children:W(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:[s(`div`,{className:`h-2 flex-1 overflow-hidden rounded bg-muted`,children:s(`div`,{className:`h-full rounded ${jt[t.severity]}`,style:{width:$(t.fraction)}})}),s(`span`,{className:`tabular-nums text-xs ${Mt[t.severity]}`,children:$(t.fraction)})]})},r)})]}),n(`section`,{className:`flex items-center gap-2 text-xs`,children:[s(`label`,{htmlFor:`prune-reason`,className:`text-foreground-subtle`,children:`Prune reason`}),s(`select`,{id:`prune-reason`,value:c,onChange:e=>{let t=At.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:At.map(e=>s(`option`,{value:e.value,children:e.label},e.value))})]}),N===0?s(D,{icon:h,title:d.devicesRead===`unavailable`?`Per-camera usage unavailable`:`No recorded footage`,description:d.devicesRead===`unavailable`?`This recording node has no footage ledger, so it refused to answer the per-camera table rather than report what it happens to hold in memory. The disk totals above are unaffected.`:`No camera has recorded footage on this node yet.`}):s(V,{columns:j,rows:[...d.devices],rowKey:e=>e.deviceId,minWidthPx:480})]})}function It(){return n(`div`,{className:`flex flex-col gap-8`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Footage on disk`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`What recorded footage occupies, per camera and per volume, with prune-by-policy and delete-all-footage.`}),s(`div`,{className:`mt-3`,children:s(Ft,{})})]}),n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Recording node & folders`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records and serves playback, and the storage locations footage is written to.`}),s(`div`,{className:`mt-3`,children:s(Et,{})})]})]})}function Lt(){return s(be,{icon:z,title:`Recordings`,subtitle:`Recorded footage and the durable event store — what each occupies, where it is written, and the operations that move or reconcile both.`,children:s(Ce,{tabs:[{id:`storage`,label:`Recordings`,icon:h,content:s(It,{})},{id:`events`,label:`Events`,icon:S,content:s(ze,{})},{id:`cameras`,label:`Cameras`,icon:f,content:s(Ae,{})},{id:`exports`,label:`Export`,icon:z,content:s(et,{})},{id:`activity`,label:`Activity`,icon:ee,content:s(ke,{})},{id:`management`,label:`Management`,icon:ye,content:s(Ct,{})}]})})}export{Lt as RecordingsPage};
|