@camstack/addon-admin-ui 1.2.37 → 1.2.38
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/{AddLocationWizard-ruAb2ySj.js → AddLocationWizard-Dt7Vz9Le.js} +1 -1
- package/dist/assets/{AddonCollectionPage-y9PlVqw3.js → AddonCollectionPage-6Aw2YAGA.js} +1 -1
- package/dist/assets/{Addons-cAsBu2OQ.js → Addons-CjZHq6IY.js} +1 -1
- package/dist/assets/{AdminTabs-BVHcviOJ.js → AdminTabs-Ye2mzpqs.js} +1 -1
- package/dist/assets/{AiProfiles-B6EskvNu.js → AiProfiles-DqPxH0J5.js} +1 -1
- package/dist/assets/{BrokerForm-DIw2g_KM.js → BrokerForm-D3fTTpv3.js} +1 -1
- package/dist/assets/{Build-sVmfeGFf.js → Build-DwyWB5rK.js} +1 -1
- package/dist/assets/{Capabilities-CTlKJVid.js → Capabilities-Ce97mPD2.js} +1 -1
- package/dist/assets/{CapabilityBadges-B_ZC7k04.js → CapabilityBadges-DtkhlewS.js} +1 -1
- package/dist/assets/{Cluster-DkXZdWpm.js → Cluster-BG2luAid.js} +1 -1
- package/dist/assets/{ClusterRecordingTab-U0cdF9UF.js → ClusterRecordingTab-Htot8l7Z.js} +1 -1
- package/dist/assets/{Dashboard-BCNcg--7.js → Dashboard-mWuskBWk.js} +1 -1
- package/dist/assets/{Data-ZtVnR1Fe.js → Data-rCQoSzSV.js} +1 -1
- package/dist/assets/DetectionIntelligence-DlGH85sl.js +1 -0
- package/dist/assets/{DeviceAggregateSection-UxtJHE5B.js → DeviceAggregateSection-bI7kL3uM.js} +1 -1
- package/dist/assets/{DeviceDetail-BbYvgUSY.js → DeviceDetail-CWLhoPV9.js} +1 -1
- package/dist/assets/{Devices-DzLVWcFg.js → Devices-jtpgjbMp.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-C5yT7D0W.js → EmbedPlayerPage-DuZxiSdE.js} +1 -1
- package/dist/assets/Events-DUxFB5Bn.js +1 -0
- package/dist/assets/{FormBuilder-C0N6NRfe.js → FormBuilder-BILjZtIe.js} +1 -1
- package/dist/assets/{Identity-FI4f8ox5.js → Identity-Crk0vUgk.js} +1 -1
- package/dist/assets/{IntegrationDetail-DxAOxN6t.js → IntegrationDetail-DJurXzOC.js} +1 -1
- package/dist/assets/{Integrations-w3RuUxDV.js → Integrations-BHcc42O_.js} +1 -1
- package/dist/assets/{Integrations-D5S4Yf1A.js → Integrations-ySnIH1Sd.js} +1 -1
- package/dist/assets/{Logs-BfDIf7QZ.js → Logs-Bb1TGrRD.js} +1 -1
- package/dist/assets/{MotionZonesSettings-CHyWV5lm.js → MotionZonesSettings-BWWbwGHM.js} +1 -1
- package/dist/assets/{MyAccess-76Y7QhMu.js → MyAccess-C2PAPIAg.js} +1 -1
- package/dist/assets/{Network-BAUdETHi.js → Network-Cy3RUcrg.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-CeWEr-Zg.js → NodeAddonsSettingsPanel-JNSINmAv.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-CUinkSSN.js → NodeInferenceDevices-Cht6qC4t.js} +1 -1
- package/dist/assets/{Notifications-CK3PuxFQ.js → Notifications-D27LJgTU.js} +1 -1
- package/dist/assets/{Pipeline-CTSS1aGu.js → Pipeline-Cf3BtloJ.js} +1 -1
- package/dist/assets/Plates-HrXlNj-Q.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-C4ycA7Un.js → PrivacyMaskSettings-DXEaUNBs.js} +1 -1
- package/dist/assets/{ProviderIcon-DyK-gNEs.js → ProviderIcon-KgF3V3AC.js} +1 -1
- package/dist/assets/{Recordings-UAlZznSu.js → Recordings-BnrqoOrs.js} +1 -1
- package/dist/assets/{ScanNetworkModal-h3WtjMhA.js → ScanNetworkModal-Dxx2BKAi.js} +1 -1
- package/dist/assets/{Settings-oupU5GDf.js → Settings-ButH6GlA.js} +1 -1
- package/dist/assets/{Showroom-HqqCUr23.js → Showroom-DLHqovib.js} +1 -1
- package/dist/assets/{Terminal-7B0qx8ho.js → Terminal-CHE7uMQo.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BnceOEA8.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-KB1NgTYv.js} +1 -1
- package/dist/assets/{boxes-BS6UzXs9.js → boxes-DXbr65aS.js} +1 -1
- package/dist/assets/{build-cluster-graph-CO-MCBmD.js → build-cluster-graph-C_OKGVaH.js} +1 -1
- package/dist/assets/circle-check-big-CDvvzYtx.js +1 -0
- package/dist/assets/clock-MA7PvDC7.js +1 -0
- package/dist/assets/{copy-bKWchDUS.js → copy-DRrD5vDH.js} +1 -1
- package/dist/assets/debounced-invalidate-D66PzHBd.js +1 -0
- package/dist/assets/{dist-B66gZe27.js → dist-CTF62Sfi.js} +1 -1
- package/dist/assets/{dist-CXHmz2j1.js → dist-DJVIQtZJ.js} +1 -1
- package/dist/assets/{download-C3-lXLSJ.js → download-D3-L-PWN.js} +1 -1
- package/dist/assets/{face-bbox-Cb2eJK0t.js → face-bbox-D2xVdmEv.js} +1 -1
- package/dist/assets/{hostInit-DtkE57IB.js → hostInit-DWq68ula.js} +1 -1
- package/dist/assets/{index-Bke_0boK.js → index-dqzu-f71.js} +3 -3
- package/dist/assets/{key-round-CSNhr2jN.js → key-round-D5V99ce_.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-e0821d3f.js → mf-entry-bootstrap-0-93f87015.js} +2 -2
- package/dist/assets/{pencil-Dbscj0iB.js → pencil-DMAfyiaP.js} +1 -1
- package/dist/assets/{player-overlays-CCOENCr_.js → player-overlays-DTb-cTgy.js} +1 -1
- package/dist/assets/plus-DBb9xrVk.js +1 -0
- package/dist/assets/{radio-BCrXf-T5.js → radio-CykuQXCK.js} +1 -1
- package/dist/assets/{refresh-cw-B50UNH29.js → refresh-cw-B0NcvZHF.js} +1 -1
- package/dist/assets/remoteEntry-vNWEaSPf.js +1 -0
- package/dist/assets/rotate-ccw-CpixHLR5.js +1 -0
- package/dist/assets/rotate-cw-DiU5mosj.js +1 -0
- package/dist/assets/search-871hv572.js +1 -0
- package/dist/assets/{send-vIA2Sg01.js → send-CtqhPev6.js} +1 -1
- package/dist/assets/{server-CVgGKwKo.js → server-BbRPd6PC.js} +1 -1
- package/dist/assets/square-DX2ha0JW.js +1 -0
- package/dist/assets/{square-check-big-DTiBKI6p.js → square-check-big-p7HpHDXe.js} +1 -1
- package/dist/assets/{src-DiF3p-RR.js → src-BxX2FkJ3.js} +4 -4
- package/dist/assets/{src-C3IwZqep.js → src-CV0JUB8F.js} +1 -1
- package/dist/assets/{undo-2-buMXiXDJ.js → undo-2-BWEA1U6J.js} +1 -1
- package/dist/assets/{upload-YICZuTHD.js → upload-CmfKc09s.js} +1 -1
- package/dist/assets/{useEventInvalidation-CGT7WKQk.js → useEventInvalidation-R75mI5og.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CbdC118i.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CeDNF2vl.js} +2 -2
- package/dist/assets/{wifi-B6uMvniy.js → wifi-CTmFh8-0.js} +1 -1
- package/dist/assets/{zap-O3h5iXhW.js → zap-Cf83BCyl.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +40 -2
- package/package.json +1 -1
- package/dist/assets/DetectionIntelligence-BlZl9E8S.js +0 -1
- package/dist/assets/Events-BGJ5su4V.js +0 -1
- package/dist/assets/Plates-Cns09Gg2.js +0 -1
- package/dist/assets/circle-check-big-DKZCFZff.js +0 -1
- package/dist/assets/clock-DqPUDB1Y.js +0 -1
- package/dist/assets/debounced-invalidate-CoCA-chF.js +0 -1
- package/dist/assets/plus-kjGKne3v.js +0 -1
- package/dist/assets/remoteEntry-DSjWOwlm.js +0 -1
- package/dist/assets/rotate-ccw-CnFi79eH.js +0 -1
- package/dist/assets/rotate-cw-BMi2-EKp.js +0 -1
- package/dist/assets/search-Cqbwip0Z.js +0 -1
- package/dist/assets/square-NIJNDIvZ.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{$ as e,An as t,Bn as n,Bt as r,Ci as i,Cn as a,Co as o,D as s,Dn as c,E as l,Ei as u,F as d,Fr as f,H as p,Hi as m,Hn as h,Hr as g,In as _,J as v,Jo as y,Ko as b,Mi as x,Mn as S,N as C,Nn as w,O as T,On as ee,P as te,Q as ne,Rn as re,So as E,T as D,Ti as O,To as ie,Tt as ae,U as k,Ui as oe,Un as A,Vn as j,W as M,Wi as N,X as se,Xi as ce,Y as P,Yo as le,Z as ue,_o as de,_r as F,a as fe,at as pe,bo as me,cn as I,da as he,eo as ge,et as L,f as _e,fo as ve,g as ye,gn as be,go as xe,gr as Se,ho as Ce,hr as R,i as we,ki as Te,l as Ee,ln as De,lr as Oe,m as ke,mi as Ae,n as je,o as Me,ot as Ne,p as Pe,po as Fe,qo as Ie,r as Le,ro as Re,rt as ze,st as Be,to as Ve,tt as He,u as Ue,vn as We,vo as Ge,wn as Ke,xo as qe,y as Je,zn as Ye}from"./src-DiF3p-RR.js";import{I as z,K as B,Q as V,S as H,W as U,a as Xe,b as Ze,o as W,q as G,t as Qe,x as K,z as q}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{N as J,W as $e,a as et,i as tt,j as nt}from"./src-C3IwZqep.js";import{c as rt,k as it,p as Y,r as at,t as ot,u as st}from"./player-overlays-CCOENCr_.js";import{t as ct}from"./CapabilityBadges-B_ZC7k04.js";import{t as lt}from"./boxes-BS6UzXs9.js";import{t as ut}from"./ProviderIcon-DyK-gNEs.js";import{a as dt,c as ft,l as pt,n as mt,o as ht}from"./NodeInferenceDevices-CUinkSSN.js";import{n as gt}from"./FormBuilder-C0N6NRfe.js";import{t as _t}from"./pencil-Dbscj0iB.js";import{t as vt}from"./refresh-cw-B50UNH29.js";import{t as yt}from"./rotate-ccw-CnFi79eH.js";import{t as bt}from"./rotate-cw-BMi2-EKp.js";import{t as xt}from"./server-CVgGKwKo.js";import{t as St}from"./wifi-B6uMvniy.js";import{B as Ct,G as X,H as wt,J as Tt,M as Et,R as Dt,S as Ot,W as kt,Y as At,a as jt,c as Mt,i as Nt,j as Pt,m as Ft,o as It,q as Lt,s as Rt,t as zt,v as Bt,y as Vt}from"./index-Bke_0boK.js";import{t as Ht}from"./StatusBadge-Dcr2bw58.js";import{t as Ut}from"./useEventInvalidation-CGT7WKQk.js";import{i as Wt,n as Gt,r as Kt,t as qt}from"./DeviceAggregateSection-UxtJHE5B.js";var Jt=X(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),Yt=X(`hand`,[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]),Xt=X(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),Zt=X(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),Qt=X(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),$t=X(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);V();function en({parentDeviceId:e}){let{t}=zt(),n=Lt(),r=Y(),{data:i,isLoading:a,isError:o}=ht(e),{data:s}=c({deviceId:e},{enabled:Number.isFinite(e)});if(a)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(i??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let u=se(s?.stableId??``,l,s?.childLayout),d=u.ungrouped,f=e=>n(`/devices/${String(e)}`),p=s?.name??``,m=(e,t)=>K(v,{trpc:r.trpcClient,device:{...t,name:L(t,p)},variant:`minimal`,onNavigate:f},e),h=d.some(e=>!!e.role),g=d.some(e=>!e.role),_=h&&!g?t(`device.accessories`,{defaultValue:`Accessories`}):!h&&g?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=d.length>0?H(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[K(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:_}),K(`div`,{className:`space-y-1`,children:d.map(e=>m(e.id,e))})]}):null,b=u.disabledSection===void 0?null:K(P,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:K(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>m(e.id,e))})},u.disabledSection.title);return u.sections.length===0?b===null?y:H(`div`,{className:`space-y-2`,children:[y,b]}):H(`div`,{className:`space-y-2`,children:[u.sections.map(e=>K(P,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),y,b]})}function tn({deviceId:e}){let t=Y(),{data:n,isLoading:r}=dt(e),{data:i,isLoading:a}=ht(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?K(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):K(`div`,{className:`flex h-full w-full flex-col`,children:K(k,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}function nn({dev:e,busy:t,setBusy:n}){let r=e?.motionTrigger,i=st(e?.state.motionTrigger),[a,o]=G(!1);if(!r)return null;let s=i?.enabled===!0,c=i!==void 0,l=async()=>{if(t||!c)return;let e=!s;n(!0),o(!0);try{await r.setMotionTrigger({enabled:e})}finally{n(!1),o(!1)}};return H(`button`,{type:`button`,onClick:()=>{l()},disabled:t||!c,title:c?s?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":s,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 ${s?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[K(kt,{className:`h-3 w-3`}),K(`span`,{children:a?s?`Disabling…`:`Enabling…`:c?s?`On motion: on`:`On motion: off`:`On motion: …`})]})}V();function Z({deviceId:e,deviceType:t,features:n}){let r=Y(),i=Ne(t)?.HeroCard??ge,a=rt(r.trpcClient,e),o=st(a?.state.deviceStatus),[s,c]=G(!1),l=o!==void 0&&o.online===!1,u=l?o.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[l?K(`div`,{className:`flex justify-center`,children:K(M,{lastChangedAt:u})}):null,K(i,{trpc:r.trpcClient,deviceId:e,features:n}),K(`div`,{className:`flex justify-center`,children:K(nn,{dev:a,busy:s,setBusy:c})})]})}function rn({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:K(Ve,{trpc:Y().trpcClient,deviceId:e,features:t})})}function an({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:K(ge,{trpc:Y().trpcClient,deviceId:e,features:t})})}function on(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function sn(e){if(!e)return null;let t=on(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var cn=1e3,ln=60*cn,un=60*ln,dn=24*un;function fn(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<cn?`just now`:n<ln?`${String(Math.floor(n/cn))}s ago`:n<un?`${String(Math.floor(n/ln))}m ago`:n<dn?`${String(Math.floor(n/un))}h ago`:`${String(Math.floor(n/dn))}d ago`}V();var pn=1500,mn=15e3,hn=1e3;function gn({deviceId:e}){let t=rt(Y().trpcClient,e)?.state.eventEmitter,n=st(t);q(()=>{if(!t)return;t.refresh();let e=setInterval(()=>{t.refresh()},mn);return()=>{clearInterval(e)}},[t]);let r=n?.lastEvent??null,i=r?.seq??null,a=B(null),[o,s]=G(!1);q(()=>{if(i===null)return;let e=a.current;if(a.current=i,e===null||e===i)return;s(!0);let t=setTimeout(()=>{s(!1)},pn);return()=>{clearTimeout(t)}},[i]);let[c,l]=G(()=>Date.now());q(()=>{let e=setInterval(()=>{l(Date.now())},hn);return()=>{clearInterval(e)}},[]);let u=sn(r),d=n?.eventTypes??[],f=n?.eventCountSinceStart??0,p=n!==void 0,m=on(r?.data);return H(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[K(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(o),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${o?`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:u??`No press recorded`,children:K(o?Zt:Yt,{className:`h-10 w-10`})}),H(`div`,{className:`text-center`,children:[m!==null&&K(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:`Button ${String(m)}`}),K(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${u?`text-foreground`:`text-foreground-subtle`}`,children:u??(p?`No press recorded`:`Awaiting state…`)}),K(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:r?fn(r.timestamp,c):`Waiting for the first event`})]}),d.length>0&&K(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:d.map(e=>K(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===r?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),K(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(f)} ${f===1?`event`:`events`} since start`})]})}function _n({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return H(`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:[K(ut,{type:n,size:`lg`}),H(`div`,{children:[K(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),K(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),H(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[K(Ht,{status:r?`online`:`offline`}),i.length>0&&K(ct,{capabilities:i})]}),K(`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.`})]})}V();function vn({deviceId:e}){let t=W(),n=I({deviceId:e},{refetchInterval:1e4,retry:!1}),r=De({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>yn(n.data??[]),[n.data]);return H(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[H(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[K(bn,{label:`Discovered`,value:i.total,icon:K(Bt,{className:`h-3.5 w-3.5`})}),K(bn,{label:`Adopted`,value:i.adopted,accent:`success`}),K(bn,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),H(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.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:[r.isPending?K(Ot,{className:`h-3.5 w-3.5 animate-spin`}):K(vt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),H(`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:[K(xn,{icon:K(St,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),K(xn,{icon:K(Vt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),K(xn,{icon:K(jt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?K(xn,{icon:K(Jt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function yn(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 bn({label:e,value:t,icon:n,accent:r}){return H(`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 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[H(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,K(`span`,{className:`truncate`,children:e})]}),K(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function xn({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,K(`span`,{children:t})]})}var Sn={[J.Switch]:Z,[J.Siren]:Z,[J.Light]:Z,[J.Sensor]:Z,[J.Button]:Z,[J.Hub]:vn,[J.Cover]:rn,[J.Valve]:Z,[J.Humidifier]:Z,[J.WaterHeater]:Z,[J.Container]:tn,[J.Lock]:Z,[J.Fan]:Z,[J.Thermostat]:Z,[J.Climate]:Z,[J.MediaPlayer]:Z,[J.Control]:Z,[J.AlarmPanel]:Z,[J.EventEmitter]:gn,[J.Notifier]:an,[J.Script]:Z,[J.Automation]:Z,[J.Presence]:Z,[J.Update]:Z,[J.Vacuum]:Z,[J.LawnMower]:Z,[J.Weather]:Z,[J.Image]:Z,[J.PetFeeder]:Z};function Cn(e){return Sn[e]??_n}function wn(e){return K(Cn(e.deviceType),{...e})}function Tn(e){return fe(Y().trpcClient,e)}V();function En(e){let[t,n]=G(`idle`),[r,i]=G(null),a=B(null),o=B(null),s=B(null),c=B(!0),l=Se(),u=R(),d=F(),f=z(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null},[]),p=z(async()=>{if(t===`idle`)return;n(`stopping`);let r=s.current;if(r&&e!==null)try{await Promise.race([d.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}f(),c.current&&(n(`idle`),i(null))},[t,e,d,f]),m=z(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,f=null,m=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await l.mutateAsync({deviceId:e});m=t.sessionId,s.current=m,n(`connecting`),f=new RTCPeerConnection,a.current=f,f.oniceconnectionstatechange=()=>{if(!c.current)return;let e=f.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&c.current&&(i(e===`failed`?`WebRTC connection failed`:null),p())};for(let e of r.getAudioTracks())f.addTrack(e,r);await f.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let d=await f.createAnswer();await f.setLocalDescription(d);let h=f.localDescription?.sdp??d.sdp??``;await u.mutateAsync({deviceId:e,sessionId:m,sdpAnswer:h})}catch(t){let l=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),f)try{f.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,m!==null)try{await d.mutateAsync({deviceId:e,sessionId:m})}catch{}s.current=null,c.current&&(i(l),n(`error`))}},[e,t,l,u,d,p]);return q(()=>(c.current=!0,()=>{c.current=!1;let t=s.current;if(t!==null&&e!==null&&d.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null}),[e]),{state:t,error:r,start:m,stop:p,isTalking:t===`talking`}}V();var Dn=0;function Q(){return++Dn}function On(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function kn(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 An(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 jn(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 Mn({scope:e,greeting:t,className:n}){let r=Y(),[i,a]=G(()=>{let n=[];return t&&n.push({id:Q(),kind:`info`,text:t}),n.push({id:Q(),kind:`info`,text:`scope: ${On(e)} — type help or context for available commands`}),n}),[o,s]=G(``),[c,l]=G([]),[u,d]=G(-1),f=B(null),p=B(null);q(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=z(()=>{f.current?.focus()},[]),h=Qe({mutationFn:t=>r.trpcClient.repl.execute.mutate({code:t,scope:e}),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`;a(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Q(),kind:`info`,text:`scope: ${On(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...kn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...jn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...An(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Q(),kind:`input`,text:`> ${n}`}]),s(``),h.mutate(n)}}function _(t){if(t.key===`Enter`){t.preventDefault(),g(o);return}if(t.key===`ArrowUp`){if(t.preventDefault(),c.length===0)return;let e=u===-1?c.length-1:Math.max(0,u-1);d(e),s(c[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),u===-1)return;let e=u+1;e>=c.length?(d(-1),s(``)):(d(e),s(c[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),a([{id:Q(),kind:`info`,text:`scope: ${On(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return H(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[H(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>K(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&K(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),H(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[K(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),K(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.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`})]})]})}function Nn({deviceId:e,intercomAvailable:t=!1}){let n=Y(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=Tn(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=we(n.trpcClient,i?e:null),g=ne(i?e:null,{width:Rn}),_=En(i&&t?e:null),v=_.state===`requesting-mic`||_.state===`starting`||_.state===`connecting`||_.state===`stopping`,y=_.isTalking||v,b=()=>{_.state===`idle`||_.state===`error`?_.start():_.state!==`stopping`&&_.stop()},x=at(),S=T(),C=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,w=x.length>0?K(Ze,{children:x.map(e=>K(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return K(Je,{serverUrl:r,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h,...S.request?{playbackUrl:S.request.url,playbackAuthToken:C,...S.request.label?{playbackLabel:S.request.label}:{},onExitPlayback:()=>S.clear()}:{},streams:o,pipelineMetrics:s,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:g.src,...g.src?{posterUrl:g.src}:{},snapshotLoading:g.loading,onRefreshSnapshot:g.refresh,intercomAvailable:t,intercomShown:y,onIntercomToggle:b,extraOverlay:w,chromeless:!0,className:`h-full`})}function Pn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full`,children:K(ye,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Fn({deviceId:e}){if(!Number.isFinite(e))return H(`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(`
|
|
1
|
+
import{$ as e,An as t,Bn as n,Bt as r,Ci as i,Cn as a,Co as o,D as s,Dn as c,E as l,Ei as u,F as d,Fr as f,H as p,Hi as m,Hn as h,Hr as g,In as _,J as v,Jo as y,Ko as b,Mi as x,Mn as S,N as C,Nn as w,O as T,On as ee,P as te,Q as ne,Rn as re,So as E,T as D,Ti as O,To as ie,Tt as ae,U as k,Ui as oe,Un as A,Vn as j,W as M,Wi as N,X as se,Xi as ce,Y as P,Yo as le,Z as ue,_o as de,_r as F,a as fe,at as pe,bo as me,cn as I,da as he,eo as ge,et as L,f as _e,fo as ve,g as ye,gn as be,go as xe,gr as Se,ho as Ce,hr as R,i as we,ki as Te,l as Ee,ln as De,lr as Oe,m as ke,mi as Ae,n as je,o as Me,ot as Ne,p as Pe,po as Fe,qo as Ie,r as Le,ro as Re,rt as ze,st as Be,to as Ve,tt as He,u as Ue,vn as We,vo as Ge,wn as Ke,xo as qe,y as Je,zn as Ye}from"./src-BxX2FkJ3.js";import{I as z,K as B,Q as V,S as H,W as U,a as Xe,b as Ze,o as W,q as G,t as Qe,x as K,z as q}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{N as J,W as $e,a as et,i as tt,j as nt}from"./src-CV0JUB8F.js";import{c as rt,k as it,p as Y,r as at,t as ot,u as st}from"./player-overlays-DTb-cTgy.js";import{t as ct}from"./CapabilityBadges-DtkhlewS.js";import{t as lt}from"./boxes-DXbr65aS.js";import{t as ut}from"./ProviderIcon-KgF3V3AC.js";import{a as dt,c as ft,l as pt,n as mt,o as ht}from"./NodeInferenceDevices-Cht6qC4t.js";import{n as gt}from"./FormBuilder-BILjZtIe.js";import{t as _t}from"./pencil-DMAfyiaP.js";import{t as vt}from"./refresh-cw-B0NcvZHF.js";import{t as yt}from"./rotate-ccw-CpixHLR5.js";import{t as bt}from"./rotate-cw-DiU5mosj.js";import{t as xt}from"./server-BbRPd6PC.js";import{t as St}from"./wifi-CTmFh8-0.js";import{B as Ct,G as X,H as wt,J as Tt,M as Et,R as Dt,S as Ot,W as kt,Y as At,a as jt,c as Mt,i as Nt,j as Pt,m as Ft,o as It,q as Lt,s as Rt,t as zt,v as Bt,y as Vt}from"./index-dqzu-f71.js";import{t as Ht}from"./StatusBadge-Dcr2bw58.js";import{t as Ut}from"./useEventInvalidation-R75mI5og.js";import{i as Wt,n as Gt,r as Kt,t as qt}from"./DeviceAggregateSection-bI7kL3uM.js";var Jt=X(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),Yt=X(`hand`,[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]),Xt=X(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),Zt=X(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),Qt=X(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),$t=X(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);V();function en({parentDeviceId:e}){let{t}=zt(),n=Lt(),r=Y(),{data:i,isLoading:a,isError:o}=ht(e),{data:s}=c({deviceId:e},{enabled:Number.isFinite(e)});if(a)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(i??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let u=se(s?.stableId??``,l,s?.childLayout),d=u.ungrouped,f=e=>n(`/devices/${String(e)}`),p=s?.name??``,m=(e,t)=>K(v,{trpc:r.trpcClient,device:{...t,name:L(t,p)},variant:`minimal`,onNavigate:f},e),h=d.some(e=>!!e.role),g=d.some(e=>!e.role),_=h&&!g?t(`device.accessories`,{defaultValue:`Accessories`}):!h&&g?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=d.length>0?H(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[K(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:_}),K(`div`,{className:`space-y-1`,children:d.map(e=>m(e.id,e))})]}):null,b=u.disabledSection===void 0?null:K(P,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:K(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>m(e.id,e))})},u.disabledSection.title);return u.sections.length===0?b===null?y:H(`div`,{className:`space-y-2`,children:[y,b]}):H(`div`,{className:`space-y-2`,children:[u.sections.map(e=>K(P,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),y,b]})}function tn({deviceId:e}){let t=Y(),{data:n,isLoading:r}=dt(e),{data:i,isLoading:a}=ht(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?K(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):K(`div`,{className:`flex h-full w-full flex-col`,children:K(k,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}function nn({dev:e,busy:t,setBusy:n}){let r=e?.motionTrigger,i=st(e?.state.motionTrigger),[a,o]=G(!1);if(!r)return null;let s=i?.enabled===!0,c=i!==void 0,l=async()=>{if(t||!c)return;let e=!s;n(!0),o(!0);try{await r.setMotionTrigger({enabled:e})}finally{n(!1),o(!1)}};return H(`button`,{type:`button`,onClick:()=>{l()},disabled:t||!c,title:c?s?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":s,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 ${s?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[K(kt,{className:`h-3 w-3`}),K(`span`,{children:a?s?`Disabling…`:`Enabling…`:c?s?`On motion: on`:`On motion: off`:`On motion: …`})]})}V();function Z({deviceId:e,deviceType:t,features:n}){let r=Y(),i=Ne(t)?.HeroCard??ge,a=rt(r.trpcClient,e),o=st(a?.state.deviceStatus),[s,c]=G(!1),l=o!==void 0&&o.online===!1,u=l?o.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[l?K(`div`,{className:`flex justify-center`,children:K(M,{lastChangedAt:u})}):null,K(i,{trpc:r.trpcClient,deviceId:e,features:n}),K(`div`,{className:`flex justify-center`,children:K(nn,{dev:a,busy:s,setBusy:c})})]})}function rn({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:K(Ve,{trpc:Y().trpcClient,deviceId:e,features:t})})}function an({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:K(ge,{trpc:Y().trpcClient,deviceId:e,features:t})})}function on(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function sn(e){if(!e)return null;let t=on(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var cn=1e3,ln=60*cn,un=60*ln,dn=24*un;function fn(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<cn?`just now`:n<ln?`${String(Math.floor(n/cn))}s ago`:n<un?`${String(Math.floor(n/ln))}m ago`:n<dn?`${String(Math.floor(n/un))}h ago`:`${String(Math.floor(n/dn))}d ago`}V();var pn=1500,mn=15e3,hn=1e3;function gn({deviceId:e}){let t=rt(Y().trpcClient,e)?.state.eventEmitter,n=st(t);q(()=>{if(!t)return;t.refresh();let e=setInterval(()=>{t.refresh()},mn);return()=>{clearInterval(e)}},[t]);let r=n?.lastEvent??null,i=r?.seq??null,a=B(null),[o,s]=G(!1);q(()=>{if(i===null)return;let e=a.current;if(a.current=i,e===null||e===i)return;s(!0);let t=setTimeout(()=>{s(!1)},pn);return()=>{clearTimeout(t)}},[i]);let[c,l]=G(()=>Date.now());q(()=>{let e=setInterval(()=>{l(Date.now())},hn);return()=>{clearInterval(e)}},[]);let u=sn(r),d=n?.eventTypes??[],f=n?.eventCountSinceStart??0,p=n!==void 0,m=on(r?.data);return H(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[K(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(o),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${o?`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:u??`No press recorded`,children:K(o?Zt:Yt,{className:`h-10 w-10`})}),H(`div`,{className:`text-center`,children:[m!==null&&K(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:`Button ${String(m)}`}),K(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${u?`text-foreground`:`text-foreground-subtle`}`,children:u??(p?`No press recorded`:`Awaiting state…`)}),K(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:r?fn(r.timestamp,c):`Waiting for the first event`})]}),d.length>0&&K(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:d.map(e=>K(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===r?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),K(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(f)} ${f===1?`event`:`events`} since start`})]})}function _n({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return H(`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:[K(ut,{type:n,size:`lg`}),H(`div`,{children:[K(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),K(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),H(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[K(Ht,{status:r?`online`:`offline`}),i.length>0&&K(ct,{capabilities:i})]}),K(`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.`})]})}V();function vn({deviceId:e}){let t=W(),n=I({deviceId:e},{refetchInterval:1e4,retry:!1}),r=De({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>yn(n.data??[]),[n.data]);return H(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[H(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[K(bn,{label:`Discovered`,value:i.total,icon:K(Bt,{className:`h-3.5 w-3.5`})}),K(bn,{label:`Adopted`,value:i.adopted,accent:`success`}),K(bn,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),H(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.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:[r.isPending?K(Ot,{className:`h-3.5 w-3.5 animate-spin`}):K(vt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),H(`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:[K(xn,{icon:K(St,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),K(xn,{icon:K(Vt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),K(xn,{icon:K(jt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?K(xn,{icon:K(Jt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function yn(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 bn({label:e,value:t,icon:n,accent:r}){return H(`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 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[H(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,K(`span`,{className:`truncate`,children:e})]}),K(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function xn({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,K(`span`,{children:t})]})}var Sn={[J.Switch]:Z,[J.Siren]:Z,[J.Light]:Z,[J.Sensor]:Z,[J.Button]:Z,[J.Hub]:vn,[J.Cover]:rn,[J.Valve]:Z,[J.Humidifier]:Z,[J.WaterHeater]:Z,[J.Container]:tn,[J.Lock]:Z,[J.Fan]:Z,[J.Thermostat]:Z,[J.Climate]:Z,[J.MediaPlayer]:Z,[J.Control]:Z,[J.AlarmPanel]:Z,[J.EventEmitter]:gn,[J.Notifier]:an,[J.Script]:Z,[J.Automation]:Z,[J.Presence]:Z,[J.Update]:Z,[J.Vacuum]:Z,[J.LawnMower]:Z,[J.Weather]:Z,[J.Image]:Z,[J.PetFeeder]:Z};function Cn(e){return Sn[e]??_n}function wn(e){return K(Cn(e.deviceType),{...e})}function Tn(e){return fe(Y().trpcClient,e)}V();function En(e){let[t,n]=G(`idle`),[r,i]=G(null),a=B(null),o=B(null),s=B(null),c=B(!0),l=Se(),u=R(),d=F(),f=z(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null},[]),p=z(async()=>{if(t===`idle`)return;n(`stopping`);let r=s.current;if(r&&e!==null)try{await Promise.race([d.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}f(),c.current&&(n(`idle`),i(null))},[t,e,d,f]),m=z(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,f=null,m=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await l.mutateAsync({deviceId:e});m=t.sessionId,s.current=m,n(`connecting`),f=new RTCPeerConnection,a.current=f,f.oniceconnectionstatechange=()=>{if(!c.current)return;let e=f.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&c.current&&(i(e===`failed`?`WebRTC connection failed`:null),p())};for(let e of r.getAudioTracks())f.addTrack(e,r);await f.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let d=await f.createAnswer();await f.setLocalDescription(d);let h=f.localDescription?.sdp??d.sdp??``;await u.mutateAsync({deviceId:e,sessionId:m,sdpAnswer:h})}catch(t){let l=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),f)try{f.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,m!==null)try{await d.mutateAsync({deviceId:e,sessionId:m})}catch{}s.current=null,c.current&&(i(l),n(`error`))}},[e,t,l,u,d,p]);return q(()=>(c.current=!0,()=>{c.current=!1;let t=s.current;if(t!==null&&e!==null&&d.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null}),[e]),{state:t,error:r,start:m,stop:p,isTalking:t===`talking`}}V();var Dn=0;function Q(){return++Dn}function On(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function kn(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 An(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 jn(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 Mn({scope:e,greeting:t,className:n}){let r=Y(),[i,a]=G(()=>{let n=[];return t&&n.push({id:Q(),kind:`info`,text:t}),n.push({id:Q(),kind:`info`,text:`scope: ${On(e)} — type help or context for available commands`}),n}),[o,s]=G(``),[c,l]=G([]),[u,d]=G(-1),f=B(null),p=B(null);q(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=z(()=>{f.current?.focus()},[]),h=Qe({mutationFn:t=>r.trpcClient.repl.execute.mutate({code:t,scope:e}),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`;a(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Q(),kind:`info`,text:`scope: ${On(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...kn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...jn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...An(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Q(),kind:`input`,text:`> ${n}`}]),s(``),h.mutate(n)}}function _(t){if(t.key===`Enter`){t.preventDefault(),g(o);return}if(t.key===`ArrowUp`){if(t.preventDefault(),c.length===0)return;let e=u===-1?c.length-1:Math.max(0,u-1);d(e),s(c[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),u===-1)return;let e=u+1;e>=c.length?(d(-1),s(``)):(d(e),s(c[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),a([{id:Q(),kind:`info`,text:`scope: ${On(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return H(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[H(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>K(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&K(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),H(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[K(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),K(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.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`})]})]})}function Nn({deviceId:e,intercomAvailable:t=!1}){let n=Y(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=Tn(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=we(n.trpcClient,i?e:null),g=ne(i?e:null,{width:Rn}),_=En(i&&t?e:null),v=_.state===`requesting-mic`||_.state===`starting`||_.state===`connecting`||_.state===`stopping`,y=_.isTalking||v,b=()=>{_.state===`idle`||_.state===`error`?_.start():_.state!==`stopping`&&_.stop()},x=at(),S=T(),C=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,w=x.length>0?K(Ze,{children:x.map(e=>K(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return K(Je,{serverUrl:r,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h,...S.request?{playbackUrl:S.request.url,playbackAuthToken:C,...S.request.label?{playbackLabel:S.request.label}:{},onExitPlayback:()=>S.clear()}:{},streams:o,pipelineMetrics:s,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:g.src,...g.src?{posterUrl:g.src}:{},snapshotLoading:g.loading,onRefreshSnapshot:g.refresh,intercomAvailable:t,intercomShown:y,onIntercomToggle:b,extraOverlay:w,chromeless:!0,className:`h-full`})}function Pn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full`,children:K(ye,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Fn({deviceId:e}){if(!Number.isFinite(e))return H(`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
2
|
`);return K(Mn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function In({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(ke,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Ln({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(_e,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}var Rn=960,zn={"no-provider":`Not available — nothing in this installation provides it.`,"source-unreachable":`Unknown — the service that owns this did not answer.`,"not-configured":`Nothing set up yet — configure it first (Image → Privacy Mask).`};function Bn({deviceId:e}){let t=W(),{data:n,isLoading:r,error:i}=u({deviceId:e},{enabled:Number.isFinite(e)});Ut([`pipelineOrchestrator`,`getCameraSwitches`],[`capability.binding-changed`]);let a=[[`pipelineOrchestrator`,`getCameraSwitches`],{input:{deviceId:e}}],o=N({onMutate:async e=>{await t.cancelQueries({queryKey:a});let n=t.getQueryData(a);return n!==void 0&&t.setQueryData(a,{...n,switches:n.switches.map(t=>t.id===e.switchId&&t.available?{...t,enabled:e.enabled}:t)}),{previous:n}},onError:(e,n,r)=>{r?.previous!==void 0&&t.setQueryData(a,r.previous)},onSuccess:e=>{t.setQueryData(a,e),t.invalidateQueries({queryKey:[[`deviceManager`]]}),t.invalidateQueries({queryKey:[[`recording`]]})}});return r?H(`div`,{className:`flex items-center gap-2 text-xs text-muted`,children:[K(Ot,{className:`h-3 w-3 animate-spin`}),` Loading camera functions…`]}):i||!n?H(`div`,{className:`flex items-start gap-2 rounded-lg border border-border p-3 text-xs text-muted`,children:[K(It,{className:`mt-0.5 h-3 w-3 shrink-0`}),K(`span`,{children:`Camera functions could not be read. Nothing has changed — the switches are not shown rather than shown with a guessed state.`})]}):K(`div`,{className:`flex flex-col gap-2`,children:n.switches.map(t=>K(Vn,{row:t,busy:o.isPending&&o.variables?.switchId===t.id,onToggle:n=>o.mutate({deviceId:e,switchId:t.id,enabled:n})},t.id))})}function Vn({row:e,busy:t,onToggle:n}){let r=e.available&&!e.enabled;return H(`div`,{className:`rounded-lg border p-3 ${r?`border-warning/50 bg-warning/5`:`border-border`}`,children:[H(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[H(`div`,{className:`flex items-center gap-2`,children:[K(`span`,{className:`text-sm font-medium`,children:e.label}),r?K(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-warning`,children:`Off`}):null]}),e.available?K(`button`,{type:`button`,disabled:t,onClick:()=>n(!e.enabled),className:`shrink-0 rounded border border-border px-2 py-1 text-xs disabled:opacity-50`,children:e.enabled?`Turn off`:`Turn on`}):K(`span`,{className:`shrink-0 text-[11px] text-muted`,children:e.unavailableReason?zn[e.unavailableReason]:`Not available.`})]}),K(`p`,{className:`mt-1.5 text-xs leading-snug text-muted`,children:e.costWhenOff})]})}function Hn({deviceId:e}){let t=W(),n=Number.isFinite(e),{data:r}=c({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;Ut([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:l}=Ke({deviceId:e},{enabled:n}),{data:u}=S({deviceType:i},{enabled:!!i}),d=A({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return K(`div`,{className:`p-4`,children:K(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(s)return H(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,l instanceof Error?l.message:String(l)]});let f=new Map,p={};for(let e of u??[])p[e.capName]=e.wrappers;for(let e of a?.entries??[])f.set(e.capName,{...e,wrappers:p[e.capName]??[]});for(let e of u??[])f.has(e.capName)||f.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let m=[...f.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(m.length===0)return H(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[K(lt,{className:`h-8 w-8 opacity-40`}),K(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),K(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let h=m.filter(e=>e.kind!==`unbound`).length;return H(`div`,{className:`flex flex-col gap-3 p-1`,children:[i===`camera`?H(`section`,{className:`flex flex-col gap-2`,children:[K(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Camera functions`}),K(Bn,{deviceId:e})]}):null,H(`div`,{className:`text-[11px] text-foreground-subtle`,children:[K(`span`,{className:`font-medium text-foreground`,children:h}),` of `,m.length,` capabilit`,m.length===1?`y`:`ies`,` bound — rows marked `,K(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),K(de,{columns:[{key:`capability`,header:`Capability`,render:e=>K(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>K(Un,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?K(Wn,{nodeId:e.providerNodeId}):K(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return K(Gn,{wrappers:t.wrappers,activeWrapperId:n,disabled:d.isPending,onPick:r=>{let i=n===r;d.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:m,rowKey:e=>e.capName,minWidthPx:720})]})}function Un({kind:e}){return e===`native`?H(`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:[K(xt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?H(`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:[K(pt,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?H(`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:[K(Xt,{className:`h-3 w-3`}),`linked`]}):H(`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:[K(ft,{className:`h-3 w-3`}),`unbound`]})}function Wn({nodeId:e}){return K(`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 Gn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?K(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):K(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return H(`button`,{disabled:n,onClick:()=>r(e),title:i?`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 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[K(i?Dt:yt,{className:`h-3 w-3`}),e]},e)})})}function Kn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return K(`div`,{className:`flex flex-col gap-3`,children:K(qt,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}V();var qn=new Set([`package-detection`]);function Jn(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 Yn(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function Xn({deviceId:e,refreshToken:t}){let n=W(),r=Y().trpcClient,[a,o]=G(null),[s,c]=G(null),[l,u]=G(null),d=i({deviceId:e},{refetchOnMount:`always`}),f=O({deviceId:e},{refetchOnMount:`always`}),p=x(void 0,{refetchOnMount:`always`});Ut([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let h=g(void 0,{refetchOnMount:`always`}),_=U(()=>{let e=new Set;for(let t of h.data??[])t.isOnline&&e.add(t.id);return e},[h.data]),v=U(()=>(p.data??[]).filter(e=>_.has(e.nodeId)).map(e=>e.nodeId),[p.data,_]),b=v[0]??``,S=Ae({nodeId:b},{enabled:b!==``,refetchOnMount:`always`}),C=Xe({enabled:v.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,v.join(`,`),t],queryFn:async()=>{let e={};for(let t of v)try{e[t]=(await r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),w=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},T=m({onSuccess:w}),ee=oe({onSuccess:w}),te=U(()=>S.data?Ce(S.data):[],[S.data]),ne=U(()=>{let e=p.data??[],t=_.size===0?[]:e.filter(e=>_.has(e.nodeId)),n=[];for(let e of t){let t=(C.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:mt(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[p.data,C.data,_]),re=(e,t)=>C.data?.[e]?.find(e=>e.key===t)??null,E=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=C.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},D=(e,t,n)=>f.data?.[e]?.[t]?.[n]??null,ie=e=>{if(qn.has(e))return{kind:`zone-driven`};let t=Jn(S.data??null,e)?.enabledByDefault??!0,n=d.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},ae=(e,t)=>{let n=Jn(S.data??null,e);if(n)return Ie(n,t)},k=(e,t)=>{let n=ie(e),r=n.kind===`gate`?n.effectiveOn:!1,i=Jn(S.data??null,e),a=E(t),o=a===null?null:re(t.agentNodeId,a);if(!le(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:D(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?y({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:Yn(s)}},A=a&&S.data?Jn(S.data,a.addonId):null,j=a?re(a.agentNodeId,a.deviceKey):null,M=j?.format??`coreml`,N=a?Yn(D(a.agentNodeId,a.deviceKey,a.addonId)):!1,se=a?ae(a.addonId,j):void 0,ce=U(()=>{if(!a||!j)return null;let e=j.steps?.[a.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[a,j]),P=()=>{o(null),c(null)},ue=(e,t)=>{let n=E(t);n!==null&&(o({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),c(D(t.agentNodeId,n,e)))},de=(t,n)=>{ee.mutate({deviceId:e,addonId:t,enabled:n})},F=()=>{a&&T.mutate({deviceId:e,agentNodeId:a.agentNodeId,deviceKey:a.deviceKey,addonId:a.addonId,patch:s},{onSuccess:P})},fe=()=>{a&&T.mutate({deviceId:e,agentNodeId:a.agentNodeId,deviceKey:a.deviceKey,addonId:a.addonId,patch:null},{onSuccess:P})};if(p.isLoading||b!==``&&S.isLoading)return K(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(ne.length===0)return K(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!S.data)return K(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let pe=a!==null&&A!==null&&j!==null;return H(`div`,{className:`relative h-full w-full space-y-3`,children:[H(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[K(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,K(`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 `,K(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),H(`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:[K(`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.`]}),K(`div`,{className:pe?`md:pr-[360px]`:``,children:te.length>0?K(ve,{tree:te,agents:ne,gateFor:ie,getCellState:k,onCellClick:ue,selectedCell:a,onSetGate:de,gateBusy:ee.isPending,fallbackNodeId:l,onFallbackNodeChange:u}):K(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),K(xe,{open:pe,onClose:P,title:A?.name??``,subtitle:a&&j?`${a.agentNodeId} · ${mt(j).label} · ${j.format}`:``,footer:H(Ze,{children:[K(`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:!N||T.isPending,onClick:fe,children:`Clear override`}),K(`div`,{className:`flex-1`}),K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:P,children:`Cancel`}),K(`button`,{type:`button`,disabled:!a||!ce||T.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:F,children:T.isPending?`Saving…`:`Save`})]}),children:A&&a&&ce?K(Fe,{mode:`device`,addon:A,agentDefault:ce,agentNodeId:a.agentNodeId,currentPatch:s,engineFormat:M,effectiveModelId:se,onChangePatch:c}):K(`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 Zn=[{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`}],Qn={"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 $n(e){return Qn[e]??`object-detection`}V();var er=`steps`,tr=`settings`,nr=new Set([er,tr]);function rr(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function ir({deviceId:e,activeSubTab:t,onSubTabChange:n}){return H(me,{value:t&&nr.has(t)?t:er,onValueChange:z(e=>{n?.(e)},[n]),className:`flex flex-col`,children:[H(E,{className:`flex-shrink-0`,children:[K(o,{value:er,children:`Steps`}),K(o,{value:tr,children:`Settings`})]}),K(qe,{value:er,children:K(Xn,{deviceId:e,refreshToken:0})}),K(qe,{value:tr,children:K(qt,{deviceId:e,sectionFilter:rr,subTabGrouping:{groupOf:e=>$n(e.id),tabs:Zn}})})]})}function $({label:e,value:t}){return H(`div`,{className:`${it} flex items-start gap-2 sm:gap-3`,children:[K(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),K(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}V();function ar({deviceId:e,initialName:t}){let r=W(),[i,a]=G(!1),[o,s]=G(t),[c,l]=G(!1),u=B(null);q(()=>{i||s(t)},[t,i]),q(()=>{i&&u.current?.focus()},[i]);let d=n({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),r.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),r.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),f=async()=>{let n=o.trim();if(n.length===0||n===t){a(!1),s(t);return}l(!0);try{await d.mutateAsync({deviceId:e,name:n}),a(!1)}catch{}finally{l(!1)}},p=()=>{s(t),a(!1)};return i?K($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-1`,children:[K(`input`,{ref:u,type:`text`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`?f():e.key===`Escape`&&p()},disabled:c,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`}),K(`button`,{type:`button`,onClick:()=>void f(),disabled:c,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:K(Dt,{className:`h-3 w-3`})}),K(`button`,{type:`button`,onClick:p,disabled:c,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:K(Nt,{className:`h-3 w-3`})})]})}):K($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[K(`span`,{className:`truncate`,children:t}),K(`button`,{type:`button`,onClick:()=>a(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:K(_t,{className:`h-3.5 w-3.5`})})]})})}V();function or({deviceId:e,initialLocation:t}){let n=W(),[r,i]=G(!1),[a,o]=G(t??``),[s,c]=G(!1),l=B(null),{data:u}=w(void 0,{enabled:r}),d=u??[];q(()=>{r||o(t??``)},[t,r]),q(()=>{r&&l.current?.focus()},[r]);let f=Ye({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),p=U(()=>{let e=a.trim().toLowerCase();return e.length===0?d:d.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[d,a]),m=a.trim().length>0&&!d.some(e=>e.toLowerCase()===a.trim().toLowerCase()),h=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await f.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},g=()=>{o(t??``),i(!1)};return r?K($,{label:`Location`,value:H(`div`,{className:`relative`,children:[H(`div`,{className:`flex items-center gap-1`,children:[K(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?h():e.key===`Escape`&&g()},disabled:s,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`}),K(`button`,{type:`button`,onClick:()=>void h(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:K(Dt,{className:`h-3 w-3`})}),K(`button`,{type:`button`,onClick:g,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:K(Nt,{className:`h-3 w-3`})})]}),(p.length>0||m)&&H(`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:[p.map(e=>H(`button`,{type:`button`,onClick:()=>{o(e),h(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[K(gt,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),K(`span`,{className:`truncate`,children:e})]},e)),m&&H(`button`,{type:`button`,onClick:()=>void h(),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:[K(`span`,{className:`text-foreground-subtle`,children:`Create`}),H(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):K($,{label:`Location`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[t?K(`span`,{className:`truncate`,children:t}):K(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),K(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:K(_t,{className:`h-3.5 w-3.5`})})]})})}V();function sr({deviceId:e}){let t=W(),{data:n}=dt(e),{data:r}=ht(e),[i,a]=G(null),o=j({onSuccess:()=>{a(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{a(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==J.Container)return null;let s=(r??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(s.length<=1)return null;let c=pe(s,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return H(Ze,{children:[K($,{label:`Primary child`,value:K(p,{childrenList:s,selectedId:c===null?s[0].id:c.id,onSetPrimary:t=>o.mutate({deviceId:e,primaryChildEntityId:t}),disabled:o.isPending})}),i!==null&&K(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:i})]})}V();var cr=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function lr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function ur(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function dr(){let e=te(),t=d(),{data:n}=c({deviceId:e??0},{enabled:e!==null}),{data:r}=Ke({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[a,o]=G(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),l=String(i.name??``),u=String(i.type??``),f=String(i.addonId??``),p=i.features??[],m=new Set([`device-status`,`feature-probe`,`device-ops`]),h=(r?.entries??[]).filter(e=>e.kind===`native`&&!m.has(e.capName)).map(e=>e.capName),g=p.length>0?p:h,_=i.location??null,v=i.metadata??null,y=v!==null&&Object.keys(v).length>0;return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[H(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[K(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),y&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[K(fr,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),K(fr,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!y||a===`identity`)&&H(`div`,{className:`divide-y divide-border`,children:[K($,{label:`ID`,value:H(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,H(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,s,`)`]})]})}),K(ar,{deviceId:e,initialName:l}),K(or,{deviceId:e,initialLocation:_}),K(sr,{deviceId:e}),K($,{label:`Type`,value:u}),K($,{label:`Provider`,value:K(ut,{type:f,size:`sm`,showLabel:!0})}),K($,{label:`Capabilities`,value:g.length>0?K(ct,{capabilities:g,showLabels:!0}):K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),y&&a===`hardware`&&K(pr,{metadata:v})]})}function fr({active:e,onClick:t,label:n}){return K(`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 pr({metadata:e}){let t=cr.filter(t=>t in e),n=Object.keys(e).filter(e=>!cr.includes(e)).toSorted(),r=[...t,...n];return H(`div`,{children:[K(`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.`}),K(`div`,{className:`divide-y divide-border`,children:r.map(t=>K($,{label:lr(t),value:K(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:ur(e[t])})},t))})]})}V();function mr({deviceId:e}){let[t,n]=G(null),r=be({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 H(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[H(`div`,{className:`flex items-center justify-between gap-3`,children:[H(`div`,{children:[K(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),K(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),H(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.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:[K(vt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&K(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}V();var hr={icon:``,label:``,unit:``,precision:``,hidden:!1};function gr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function _r(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function vr(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 yr({deviceId:e}){let n=Y(),r=W(),{data:i}=c({deviceId:e},{enabled:e>0}),a=typeof i?.role==`string`?i.role:null,o=a===null?void 0:Be[a],s=o?.kind===`numeric`,l=je(n.trpcClient,e,a??``),u=o?.kind===`numeric`?o.canonicalUnit:void 0,d=_r(l)??u,f=d===void 0?void 0:tt(d),p=U(()=>f===void 0?[]:et(f),[f]),[m,g]=G(null),_=m??gr(i?.display),v=re({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:y}=t({},{staleTime:6e4}),b=h({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(i===void 0||a===null)return null;let x=e=>{g({..._,...e})},S=()=>{v.mutate({deviceId:e,display:vr(_)})},C=()=>{g(hr),v.mutate({deviceId:e,display:null})},w=()=>{let e={..._.icon===``?{}:{icon:_.icon},..._.unit===``?{}:{unit:_.unit},..._.precision.trim()!==``&&Number.isFinite(Number.parseInt(_.precision,10))?{precision:Number.parseInt(_.precision,10)}:{}},t={...y?.defaults??{},[a]:e};b.mutate({defaults:t})},T=ze(a).label,ee=Object.keys(He);return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[K(`div`,{className:`border-b border-border px-4 py-2`,children:K(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Display`})}),H(`div`,{className:`p-4 space-y-3`,children:[H(`label`,{className:`block`,children:[K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Icon`}),H(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:_.icon,onChange:e=>x({icon:e.target.value}),children:[H(`option`,{value:``,children:[`Default (`,T,`)`]}),ee.map(e=>K(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Label`}),K(`input`,{type:`text`,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:T,value:_.label,onChange:e=>x({label:e.target.value})})]}),s&&H(`div`,{className:`grid grid-cols-2 gap-3`,children:[H(`label`,{className:`block`,children:[K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Unit`}),H(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:_.unit,onChange:e=>x({unit:e.target.value}),disabled:p.length===0,children:[H(`option`,{value:``,children:[`Source`,d?` (${d})`:``]}),p.map(e=>K(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Precision`}),K(`input`,{type:`number`,min:0,max:10,step:1,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:`inherit`,value:_.precision,onChange:e=>x({precision:e.target.value})})]})]}),H(`label`,{className:`flex items-center gap-2`,children:[K(`input`,{type:`checkbox`,checked:_.hidden,onChange:e=>x({hidden:e.target.checked})}),K(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),H(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[K(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-sm font-medium text-primary-foreground disabled:opacity-50`,onClick:S,disabled:v.isPending,children:`Save`}),K(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:C,disabled:v.isPending,children:`Reset`}),H(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:w,disabled:b.isPending,title:`Apply this unit / precision / icon as the default for every ${T} sensor`,children:[`Set as default for all `,T,` sensors`]})]})]})]})}function br(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function xr({device:e}){let t=Lt(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===J.Camera,a=r===J.Hub,o=typeof e.role==`string`&&e.role.length>0,s=e.features??[],c=s.includes(nt.Resyncable),{data:l}=f({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),p=s.includes(nt.DoorbellButton),m=Le(p?{deviceId:n??void 0,historyLimit:10}:void 0),h=m.latest?Date.now()-m.latest.timestamp<3e4:!1;return H(`div`,{className:`space-y-5`,children:[a&&n!==null&&K(Pe,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&K(mr,{deviceId:n}),i&&n!==null&&K(D,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),p&&K(Ue,{history:m.history,latestIsFresh:h}),i&&n!==null&&K(D,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&d.length>0&&H(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[K(`div`,{className:`border-b border-border px-4 py-2`,children:K(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),K(`div`,{className:`divide-y divide-border`,children:d.map(([e,t])=>H(`div`,{className:`px-4 py-2.5`,children:[H(`div`,{className:`flex items-center gap-2 mb-2`,children:[K(St,{className:`h-3 w-3 text-foreground-subtle`}),K(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),H(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[K(Sr,{label:`Nominal`,value:br(t.nominalBitrateKbps??0)}),K(Sr,{label:`Observed`,value:br(t.observedBitrateKbps??0)}),K(Sr,{label:`Peak`,value:br(t.peakBitrateKbps??0)}),K(Sr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),K(dr,{}),o&&n!==null&&K(yr,{deviceId:n})]})}function Sr({label:e,value:t,warning:n}){return H(`div`,{children:[K(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),K(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}V();var Cr=[{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 wr(e){let t=e===J.Camera;return Cr.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var Tr=[{id:`logs`,icon:Ft,label:`Logs`},{id:`repl`,icon:Mt,label:`REPL`},{id:`events`,icon:wt,label:`Events`},{id:`state`,icon:Pt,label:`State`}];function Er(){let t=Tt(),n=Number(t.deviceId),i=Number.isFinite(n),o=Lt(),u=W(),d=Re(),f=Y(),[p,m]=At(),h=p.get(`tab`)??`overview`,g=p.get(`sub`),[v,y]=G(`logs`),b=`device-detail.left-col-width-px`,[x,S]=G(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(b),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),w=B(x);w.current=x;function T(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??x??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{S(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=w.current;if(e!==null)try{window.localStorage.setItem(b,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:te,isLoading:ne,isError:re}=c({deviceId:n},{enabled:i,refetchInterval:5e3,retry:1}),{data:E}=ee({deviceId:n},{enabled:i}),D=U(()=>{let e=E?.settings?.sections??[],t=E?.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(Wt)&&r.add(Gt),[...r].map(e=>e===`export`?{id:e,label:Kt,isAddonContrib:!0}:{id:e,label:$e[e]?.label??e,isAddonContrib:!0})},[E]),O=te,k=String(O?.name??t.deviceId??`Device`),oe=O?.online===!0,A=oe?`online`:`offline`,j=String(O?.addonId??`rtsp`),M=O?.features??[],N=O?.type,se=N===J.Camera,{data:P}=ht(i?n:0),le=N===J.Container,de=U(()=>(P??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[P]),F=U(()=>le?pe(de,typeof O?.linkDeviceId==`number`?O.linkDeviceId:null,typeof O?.primaryChildEntityId==`string`?O.primaryChildEntityId:null)?.id??null:null,[le,de,O?.linkDeviceId,O?.primaryChildEntityId]),{data:fe}=ee({deviceId:F??0},{enabled:F!==null}),me=U(()=>{if(F===null)return[];let e=fe?.settings?.sections??[],t=fe?.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:$e[e]?.label??e,isAddonContrib:!0,childDeviceId:F}))},[F,fe]),I=typeof O?.parentDeviceId==`number`?O.parentDeviceId:null,{data:ge}=c({deviceId:I??0},{enabled:I!==null}),L=ie(),_e=O?.disabled!==!0,ve=U(()=>{let e=new Set,t=[];for(let n of[...wr(N),...D,...me])e.has(n.id)||(e.add(n.id),t.push(n));return t},[N,D,me]),ye=U(()=>ve.some(e=>e.id===h)?h:`overview`,[ve,h]),be=z(e=>{m(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[m]),xe=z(e=>{m(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[m]),Se=(P??[]).length>0,Ce=U(()=>Tr.filter(({featureGate:e})=>!e||M.includes(e)),[M]),{data:R}=Oe({addonId:j},{enabled:!!j&&j!==`rtsp`}),we=_({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]}),o(R?.id?`/integrations/${R.id}`:`/integrations`)}}),De=a({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=We({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ae=he(),je=ae({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ne=M.includes(nt.Rebootable),Pe=M.includes(nt.BatteryOperated),Fe=e(f.trpcClient,Pe&&i?n:null),[Ie,Le]=G(!1),ze=rt(f.trpcClient,i?n:null),Be=async()=>{if(!(Ie||!ze)){Le(!0);try{await ze.snapshot?.invalidateCache({});let e=await ze.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=k.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{Le(!1)}}},Ve=De.isPending||ke.isPending,{data:He}=Te({deviceId:n},{enabled:i,refetchInterval:1e4}),Ue=He?.agentNodeId??null,Ke=typeof Ue==`string`&&Ue.length>0&&!Ue.startsWith(`addon:`)?Ue:void 0,{data:qe}=ce({deviceId:n,...Ke?{nodeId:Ke}:{}},{enabled:i,refetchInterval:3e3,retry:!1}),{data:Je}=r({deviceId:n},{enabled:i,refetchInterval:3e3,retry:!1}),Ye=Je?.level?.dbfs??null;function V(){if(!i)return null;switch(ye){case`overview`:return K(xr,{device:O??{}});case`config`:return K(Kn,{deviceId:n,activeSubTab:g,onSubTabChange:xe});case`detection-pipeline`:return K(ir,{deviceId:n,activeSubTab:g,onSubTabChange:xe});case`bindings`:return K(Hn,{deviceId:n});default:{let e=ye,t=D.some(t=>t.id===e),r=me.find(t=>t.id===e);if(!t&&r===void 0)return null;let i=r?.childDeviceId??n;if(e===`export`)return K(qt,{deviceId:n,sectionFilter:Wt,activeSubTab:g,onSubTabChange:xe});let a=K(qt,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:g,onSubTabChange:xe});return r!==void 0&&i!==n?K(C,{deviceId:i,children:a}):a}}}return i?ne?H(`div`,{className:`flex flex-col h-full`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[K(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),K(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),K(`div`,{className:`flex-1 p-6`,children:K(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):re||!te?H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),H(`p`,{className:`text-xs`,children:[`No device with ID`,` `,H(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,n]})]}),K(`button`,{onClick:()=>o(`/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`})]}):H(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[K(`div`,{className:`mb-2`,children:K(Ge,{items:[{label:`Integrations`,onClick:()=>o(`/integrations`)},{label:R?.name??j,onClick:()=>R?.id&&o(`/integrations/${R.id}`)},{label:k}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[K(ut,{type:j,size:`lg`}),H(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[K(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:k}),K(Ht,{status:A}),Pe&&K(ue,{status:Fe,variant:`full`})]}),I!==null&&ge&&H(`button`,{type:`button`,onClick:()=>o(`/devices/${I}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${ge.name}`,children:[K(`span`,{children:`↑`}),K(`span`,{className:`truncate`,children:String(ge.name??`Device #${I}`)})]}),K(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:M.length>0&&K(ct,{capabilities:M})})]}),qe&&K(`div`,{className:`hidden lg:flex`,children:K(Dr,{metrics:qe,dbfs:Ye})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{_e?await d({title:`Disable "${k}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&ke.mutate({deviceId:n}):De.mutate({deviceId:n})},disabled:Ve,title:_e?`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 ${_e?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[K(Qt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:Ve?`Updating…`:_e?`Enabled`:`Disabled`})]}),K(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),K(Ee,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:Ct,disabled:Ie,onClick:()=>{Be()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:bt,hidden:!Ne,disabled:Ae.isPending,danger:!0,onClick:async()=>{await d({title:`Reboot "${k}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Ae.mutate({deviceId:n})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??j}.`,icon:vt,disabled:je.isPending,danger:!0,onClick:async()=>{await d({title:`Restart "${R?.name??j}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${k}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&je.mutate({addonId:j})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Rt,separatorBefore:!0,disabled:we.isPending,danger:!0,onClick:async()=>{await d({title:`Delete "${k}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&we.mutate({deviceId:n})}}]})]})]})]}),K(C,{deviceId:n,device:O??void 0,children:K(s,{children:K(l,{children:K(ot,{children:K(Me,{children:H(`main`,{className:L?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[H(`div`,{className:L?`flex flex-col bg-surface`:`${x===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!L&&x!==null?{width:`${String(x)}px`}:void 0,children:[K(`div`,{className:se?`flex-shrink-0 border-b border-border-subtle bg-black`:L?`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:se?K(Nn,{deviceId:n,intercomAvailable:M.includes(nt.TwoWayAudio)}):K(wn,{deviceId:n,deviceName:k,deviceType:N??`unknown`,provider:j,isOnline:oe,features:M})}),H(`div`,{className:L?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[K(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:K(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Ce.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>y(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${v===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[K(n,{className:`h-3 w-3`}),t]},e))})}),H(`div`,{className:L?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[v===`logs`&&K(Pn,{deviceId:n,containerDeviceId:N===`container`?n:void 0}),v===`repl`&&K(Fn,{deviceId:n}),v===`events`&&K(In,{deviceId:n}),v===`state`&&K(Ln,{deviceId:n})]})]})]}),!L&&K(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:T,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:K(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),H(`div`,{className:L?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[K(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:K(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:ve.map(e=>{let t=ye===e.id;return H(`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&&K(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),H(`div`,{className:L?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[ye===`overview`&&Se&&K(en,{parentDeviceId:n}),V()]})]})]})})})})})})]}):H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),H(`p`,{className:`text-xs`,children:[`The URL segment`,` `,K(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:t.deviceId}),` `,`is not a number.`]}),K(`button`,{onClick:()=>o(`/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 Dr({metrics:e,dbfs:t}){let n=b(e.phase??`idle`);return H(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[H(`div`,{className:`flex items-center gap-1.5`,children:[K(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),K(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),K(`div`,{className:`h-3 w-px bg-border`}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(kt,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),K(`span`,{children:`fps`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(Et,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),K(`span`,{children:`ms`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[K($t,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),K(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&H(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{Er as DeviceDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Cn as e,G as t,In as n,dr as r,jn as i,vn as a}from"./src-
|
|
1
|
+
import{Cn as e,G as t,In as n,dr as r,jn as i,vn as a}from"./src-BxX2FkJ3.js";import{I as o,Q as s,S as c,W as l,o as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as f}from"./player-overlays-DTb-cTgy.js";import{t as p}from"./ProviderIcon-KgF3V3AC.js";import{B as m,o as h,q as g,t as _}from"./index-dqzu-f71.js";import{t as v}from"./AdminPage-Dq33XE9j.js";import{t as y}from"./useEventInvalidation-R75mI5og.js";s();function b(){let{t:s}=_(),b=g(),x=f(),S=u();y([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),y([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:C}=i({}),{data:w}=r(void 0),T=n({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=a({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),D=e({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),O=l(()=>C??[],[C]),{activeDevices:k,orphanDevices:A}=l(()=>{let e=new Set((w??[]).map(e=>e.addonId)),t=t=>typeof t.addonId==`string`&&t.addonId.length>0&&!e.has(t.addonId),n=new Set;for(let e of O)t(e)&&n.add(e.id);let r=new Set(n),i=new Map;for(let e of O)i.set(e.id,e);let a=(e,t=0)=>{if(t>32)return!1;if(n.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let r=i.get(e.parentDeviceId);return r?a(r,t+1):!1};for(let e of O)a(e)&&r.add(e.id);let o=[],s=[];for(let e of O)r.has(e.id)?s.push(e):o.push(e);return{activeDevices:o,orphanDevices:s}},[O,w]),j=l(()=>{let e=new Map;for(let t of O)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[O]),M=o(e=>j.get(e)??null,[j]),N=l(()=>(w??[]).map(e=>({id:e.addonId,name:e.name??e.addonId,icon:d(p,{type:e.addonId,size:`sm`})})),[w]),P=o(e=>d(p,{type:e,size:`sm`}),[]),F=o(e=>b(`/devices/${String(e)}`),[b]);return c(v,{icon:m,title:s(`nav.devices`,`Devices`),children:[d(t,{context:`devices`,devices:k,trpc:x.trpcClient,filters:{addons:N},resolveIntegrationIcon:P,resolveParent:M,onNavigate:F,batchActions:{remove:T.mutate,disable:E.mutate,enable:D.mutate}}),A.length>0&&c(`div`,{className:`mt-6 space-y-2`,children:[c(`div`,{className:`flex items-baseline gap-2`,children:[d(h,{className:`h-3.5 w-3.5 text-warning shrink-0`}),d(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Orphan devices`}),c(`span`,{className:`text-[10px] text-foreground-subtle`,children:[A.length,` device`,A.length===1?``:`s`,` pointing at integrations no longer registered`]})]}),c(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:"These devices reference an addonId that has no matching integration. Delete them, or re-install the missing integration to bring them back online. The provider scope (`addonId`) shown beside each row is what's failing to resolve."}),d(t,{context:`devices`,devices:A,trpc:x.trpcClient,filters:{addons:N},urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:P,resolveParent:M,onNavigate:F})]})]})]})}export{b as DevicesPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{R as e,b as t,do as n,i as r}from"./src-
|
|
1
|
+
import{R as e,b as t,do as n,i as r}from"./src-BxX2FkJ3.js";import{Q as i,S as a,W as o,d as s,q as c,u 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-DTufy7Ue.js";import{H as f}from"./src-CV0JUB8F.js";import{A as p,D as m,E as h,M as g,v as _,w as v}from"./__vite-browser-external-DQHwpgVa.js";import{d as y}from"./player-overlays-DTb-cTgy.js";i();var b=g([m({kind:v(`adaptive`)}),m({kind:v(`profile`),profile:f})]),x=m({serverUrl:p().min(1),token:p().min(1),deviceId:h().int().nonnegative(),target:b,muted:_()});function S(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function C(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function w(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function T(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function E(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=x.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function D({message:e}){return d(()=>{S(`error`,e)},[e]),a(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[`Embed config error: `,e]})}function O({system:e,deviceId:n,initialTarget:i,initialMuted:a}){let[s,l]=c(i),[f,p]=c(a),{handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,getSessionState:y}=r(e.trpcClient,n),x=o(()=>w(s),[s]),E=o(()=>(e,t)=>m(x,e,t),[m,x]),D=o(()=>(e,t,n)=>m(n,t,e),[m]);d(()=>(window.__camstackEmbed={setMuted:e=>p(e),setTarget:e=>{let t=b.safeParse(e);t.success&&l(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let O=T(s);return u(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:u(t,{serverUrl:e.serverUrl,streamKey:O,autoPlay:!0,muted:f,showControls:!1,className:`w-full h-full`,handleOffer:E,reoffer:D,getSessionState:y,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,onStateChange:e=>S(C(e)),onError:e=>S(`error`,e)},O)})}function k(){let t=o(()=>E(),[]),r=o(()=>t.ok?{system:e({serverUrl:t.config.serverUrl,token:t.config.token}),queryClient:new s({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}})}:null,[t]);return d(()=>{if(r)return()=>{r.system.close()}},[r]),t.ok?r?u(y,{system:r.system,children:u(l,{client:r.queryClient,children:u(n.Provider,{client:r.system.trpcClient,queryClient:r.queryClient,children:u(O,{system:r.system,deviceId:t.config.deviceId,initialTarget:t.config.target,initialMuted:t.config.muted})})})}):u(D,{message:`Failed to initialise the embed player`}):u(D,{message:t.error})}export{k as EmbedPlayerPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$a as e,$r as t,Ao as n,B as r,Bo as i,Jr as a,Kr as o,Lo as s,Mr as c,Qr as l,Ro as u,Vo as d,Wr as f,Xr as p,Zr as m,ci as h,ii as g,io as _,jn as v,jo as y,li as b,ni as x,oi as S,q as C,qr as w,ri as T,si as E,ti as D,ui as O,uo as k,xt as A,z as j,zo as M}from"./src-BxX2FkJ3.js";import{I as N,K as P,Q as F,S as I,U as L,W as R,a as z,b as ee,i as B,o as te,q as V,x as H,z as U}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{K as W,N as ne,T as G}from"./src-CV0JUB8F.js";import{p as re}from"./player-overlays-DTb-cTgy.js";import{t as ie}from"./clock-MA7PvDC7.js";import{t as ae}from"./copy-DRrD5vDH.js";import{t as oe}from"./download-D3-L-PWN.js";import{a as se,c as ce,d as le,f as ue,i as de,m as fe,n as pe,o as me,p as he,r as ge,s as _e,t as ve}from"./debounced-invalidate-D66PzHBd.js";import{t as ye}from"./refresh-cw-B0NcvZHF.js";import{t as be}from"./search-871hv572.js";import{t as xe}from"./square-check-big-p7HpHDXe.js";import{t as Se}from"./square-DX2ha0JW.js";import{t as Ce}from"./undo-2-BWEA1U6J.js";import{D as we,F as Te,G as K,L as Ee,N as De,R as Oe,S as q,W as ke,i as Ae,l as je,s as Me,t as Ne}from"./index-dqzu-f71.js";import{t as Pe}from"./AdminPage-Dq33XE9j.js";import{i as Fe,n as Ie,t as Le}from"./authed-media-B8T1dsFh.js";import{t as Re}from"./AdminTabs-Ye2mzpqs.js";var ze=K(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),Be=K(`bug`,[[`path`,{d:`m8 2 1.88 1.88`,key:`fmnt4t`}],[`path`,{d:`M14.12 3.88 16 2`,key:`qol33r`}],[`path`,{d:`M9 7.13v-1a3.003 3.003 0 1 1 6 0v1`,key:`d7y7pr`}],[`path`,{d:`M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6`,key:`xs1cw7`}],[`path`,{d:`M12 20v-9`,key:`1qisl0`}],[`path`,{d:`M6.53 9C4.6 8.8 3 7.1 3 5`,key:`32zzws`}],[`path`,{d:`M6 13H2`,key:`82j7cp`}],[`path`,{d:`M3 21c0-2.1 1.7-3.9 3.8-4`,key:`4p0ekp`}],[`path`,{d:`M20.97 5c0 2.1-1.6 3.8-3.5 4`,key:`18gb23`}],[`path`,{d:`M22 13h-4`,key:`1jl80f`}],[`path`,{d:`M17.2 17c2.1.1 3.8 1.9 3.8 4`,key:`k3fwyw`}]]),Ve=K(`circle-dashed`,[[`path`,{d:`M10.1 2.182a10 10 0 0 1 3.8 0`,key:`5ilxe3`}],[`path`,{d:`M13.9 21.818a10 10 0 0 1-3.8 0`,key:`11zvb9`}],[`path`,{d:`M17.609 3.721a10 10 0 0 1 2.69 2.7`,key:`1iw5b2`}],[`path`,{d:`M2.182 13.9a10 10 0 0 1 0-3.8`,key:`c0bmvh`}],[`path`,{d:`M20.279 17.609a10 10 0 0 1-2.7 2.69`,key:`1ruxm7`}],[`path`,{d:`M21.818 10.1a10 10 0 0 1 0 3.8`,key:`qkgqxc`}],[`path`,{d:`M3.721 6.391a10 10 0 0 1 2.7-2.69`,key:`1mcia2`}],[`path`,{d:`M6.391 20.279a10 10 0 0 1-2.69-2.7`,key:`1fvljs`}]]),He=K(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Ue=K(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),We=K(`graduation-cap`,[[`path`,{d:`M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z`,key:`j76jl0`}],[`path`,{d:`M22 10v6`,key:`1lu8f3`}],[`path`,{d:`M6 12.5V16a6 3 0 0 0 12 0v-3.5`,key:`1r8lef`}]]),Ge=K(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]),Ke=K(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);F();var qe=`pipeline-analytics`,Je=`debug.listTracks`,Ye=`debug.analyze`,Xe=`/addon/pipeline-analytics/debug-export`;function Ze(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Qe(e,t){let n=e[t];return typeof n==`string`?n:null}function J(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function $e(e,t){let n=e[t];return typeof n==`boolean`?n:null}function et(e){return e===`error`||e===`warn`||e===`info`}function tt(e){if(!Ze(e))return null;let t=Qe(e,`code`),n=Qe(e,`detail`),r=e.severity;return t===null||n===null||!et(r)?null:{code:t,severity:r,detail:n}}function nt(e){if(!Ze(e))return null;let t=Qe(e,`trackId`),n=J(e,`deviceId`),r=Qe(e,`className`),i=J(e,`firstSeen`),a=J(e,`lastSeen`),o=J(e,`durationMs`),s=$e(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Qe(e,`label`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},firstSeen:i,lastSeen:a,durationMs:o,active:s}}function rt(e){let t=nt(e);if(t===null||!Ze(e))return null;let n=J(e,`mediaCount`),r=J(e,`eventCount`),i=J(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=tt(e);t!==null&&c.push(t)}return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c}}function it(e){if(!Ze(e))return null;let t=$e(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=nt(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function at(e){if(!Ze(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=rt(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var ot={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`};function st(e){return ot[e]??e}var ct={error:0,warn:1,info:2};function lt(e){return e.toSorted((e,t)=>ct[e.severity]-ct[t.severity]||e.code.localeCompare(t.code))}function ut(e){return e.length===0?Xe:`${Xe}?deviceIds=${e.join(`,`)}`}function dt(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}var ft=`all`,pt=`The server answered in a shape this build does not understand.`,mt={error:`danger`,warn:`warning`,info:`info`};function ht({findings:e}){return e.length===0?H(i,{variant:`success`,children:`no anomaly found`}):H(`div`,{className:`flex flex-wrap gap-1`,children:lt(e).map(e=>H(i,{variant:mt[e.severity],title:e.detail,children:st(e.code)},e.code))})}function gt({track:e,report:t,cameraName:n,analyzing:r}){return I(`div`,{className:`flex flex-col gap-1.5 border-b border-border px-3 py-2.5 last:border-b-0`,children:[I(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[H(`span`,{className:`font-medium text-foreground`,children:n}),H(`span`,{className:`text-foreground-subtle`,children:e.label??e.className}),I(`span`,{className:`text-foreground-subtle`,children:[new Date(e.lastSeen).toLocaleString(),` · `,dt(e.durationMs)]}),e.active&&H(i,{variant:`default`,children:`still open`}),t!==void 0&&I(`span`,{className:`text-foreground-subtle`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),H(`div`,{className:`flex items-center gap-2`,children:t===void 0?H(`span`,{className:`text-xs text-foreground-subtle`,children:r?`analysing…`:`not analysed`}):H(ht,{findings:t.findings})}),H(`code`,{className:`text-[10px] text-foreground-subtle`,children:e.trackId})]})}function _t(){let e=re(),[t,n]=V(ft),[r,i]=V(!1),[a,o]=V(null),c=v({}),l=R(()=>[{value:ft,label:`All cameras`},...(c.data??[]).map(e=>({value:String(e.id),label:e.name}))],[c.data]),u=R(()=>{let e=new Map;for(let t of c.data??[])e.set(t.id,t.name);return e},[c.data]),f=R(()=>t===ft?[]:[Number.parseInt(t,10)],[t]),p=z({queryKey:[`events-debug`,`list`,f],queryFn:async()=>it(await e.trpcClient.addons.custom.mutate({addonId:qe,action:Je,input:f.length===0?{}:{deviceIds:f}}))}),m=R(()=>(p.data?.tracks??[]).map(e=>e.trackId),[p.data]),h=z({queryKey:[`events-debug`,`analyze`,m],enabled:m.length>0,queryFn:async()=>at(await e.trpcClient.addons.custom.mutate({addonId:qe,action:Ye,input:{trackIds:m}}))}),g=R(()=>{let e=new Map;for(let t of h.data?.reports??[])e.set(t.trackId,t);return e},[h.data]),y=()=>{p.refetch(),h.refetch()},b=async()=>{i(!0),o(null);try{await Ie(ut(f),`camstack-debug.zip`)}catch(e){o(e instanceof Error?e.message:`Export failed.`)}finally{i(!1)}},x=p.data?.tracks??[],S=p.data===null||h.data===null;return H(Pe,{children:I(`section`,{className:`space-y-3`,children:[I(`div`,{className:`flex flex-wrap items-center gap-2`,children:[H(`div`,{className:`w-44`,children:H(s,{value:t,options:l,onChange:e=>n(e.target.value)})}),I(d,{variant:`secondary`,onClick:y,disabled:p.isFetching,children:[p.isFetching?H(q,{className:`h-3.5 w-3.5 animate-spin`}):H(ye,{className:`h-3.5 w-3.5`}),`Refresh`]}),I(d,{onClick:()=>void b(),disabled:r||x.length===0,children:[r?H(q,{className:`h-3.5 w-3.5 animate-spin`}):H(oe,{className:`h-3.5 w-3.5`}),`Export all (`,String(x.length),`)`]})]}),I(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,H(`code`,{children:`debug`}),` mark does not pin retention — this lists the marked tracks that still exist. A track whose media was evicted shows as missing media.`]}),p.isError&&H(_,{message:`Could not load the marked tracks.`}),S&&!p.isError&&H(_,{message:pt}),a!==null&&H(_,{message:a}),p.data?.truncated===!0&&H(_,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(h.data?.vanished.length??0)>0&&I(`p`,{className:`text-xs text-foreground-subtle`,children:[String(h.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),H(M,{children:p.isLoading?H(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`}):x.length===0?I(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[H(Be,{className:`h-5 w-5 text-foreground-subtle`}),H(`p`,{className:`text-xs text-foreground-subtle`,children:`No track is marked for debug. Mark one from a track's actions to see it here.`})]}):x.map(e=>H(gt,{track:e,report:g.get(e.trackId),cameraName:u.get(e.deviceId)??`Camera ${String(e.deviceId)}`,analyzing:h.isFetching},e.trackId))})]})})}function vt(e){return e.subLabel??e.label}var yt=720*60*60*1e3;function bt(e){let t=[];for(let n of e)t.push(...n);return t}function xt(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function St(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function Ct(e,t){return`${String(e)}:${t}`}function wt(e,t){let n=new Map,r=new Set;for(let i of e){let e=Ct(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function Tt(e,t){return{since:e.fromMs??t-yt,until:e.toMs??t}}var Y=typeof o==`function`,Et=`Track deletion arrives with the next server update`;function Dt(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Ot=Y?o:Dt,kt=200,At=3e4;function jt(e){let t=re(),n=B({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:At,refetchInterval:At,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:kt,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:xt(bt(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}F();var Mt=[`events-feed`],Nt=2e3;function Pt(e){let t=te(),n=e?.paused===!0,r=P(t);r.current=t;let i=P(n);i.current=n;let[a,o]=V(!1),s=N(()=>{r.current.invalidateQueries({queryKey:Mt})},[]),c=P(void 0);c.current||=ve({delayMs:Nt,invalidate:()=>{i.current?o(!0):s()}}),U(()=>()=>c.current?.cancel(),[]),U(()=>{n||!a||(o(!1),s())},[n,a,s]);let l=N(()=>{o(!1),s()},[s]);return k(W.PipelineAnalyticsDetectionEvent,()=>{c.current?.trigger()}),k(W.PipelineAnalyticsTrackEnded,()=>{c.current?.trigger()}),{pending:a,refreshNow:l}}F();function Ft({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:a}=Ne(),[o,s]=V(!1),[c,l]=V(``),[u,d]=V(new Set),f=c.trim().toLowerCase(),p=e=>f.length===0||j(e,a).toLowerCase().includes(f),m=R(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>p(t)||p(e.macro))})).filter(e=>p(e.macro)||e.subs.length>0),[e,f]),h=e=>d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),g=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},_=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},v=()=>n(new Set),y=t.size;return I(`div`,{className:`relative`,children:[I(`button`,{type:`button`,onClick:()=>s(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${y>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[H(Ke,{className:`h-3.5 w-3.5`}),y>0?`Kinds (${String(y)})`:`Kinds`,H(Ee,{className:`h-3 w-3`})]}),o&&I(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[I(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[H(be,{className:`h-3.5 w-3.5 text-foreground-subtle`}),H(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),y>0&&H(`button`,{type:`button`,onClick:v,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),m.length===0&&H(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:i?`Loading kinds…`:f.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),m.map(e=>{let n=r(e.macro.iconId),i=u.has(e.macro.kind)||f.length>0,o=t.has(e.macro.kind);return I(`div`,{className:`mb-0.5`,children:[I(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?H(`button`,{type:`button`,onClick:()=>h(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:H(i?Ee:Te,{className:`h-3 w-3`})}):H(`span`,{className:`w-3`}),I(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[H(`input`,{type:`checkbox`,checked:o,onChange:()=>g(e),className:`accent-primary`}),H(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),H(`span`,{className:`font-medium`,children:j(e.macro,a)})]})]}),i&&e.subs.map(e=>{let n=r(e.iconId);return I(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[H(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>_(e.kind),className:`accent-primary`}),H(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),H(`span`,{children:j(e,a)})]},e.kind)})]},e.macro.kind)})]})]})}function It(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function Lt(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var Rt=new Set([`detection`,`package`]);function zt(e,t){return[...It(e,t).values()].filter(e=>e.parentKind===null&&Rt.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Bt(e,t){let n=It(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,Lt(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}F();var Vt=1400,Ht=`Admin-gated URL — opens only inside an authenticated session`;function Ut({label:e,value:t,title:n}){let[r,i]=V(!1);return U(()=>{if(!r)return;let e=setTimeout(()=>i(!1),Vt);return()=>clearTimeout(e)},[r]),I(`button`,{type:`button`,onClick:N(()=>{(async()=>{try{await navigator.clipboard.writeText(t),i(!0)}catch{window.prompt(`Copy the media URL:`,t)}})()},[t]),title:n,"aria-label":`Copy ${e} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${r?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[H(r?Oe:ae,{className:`h-2.5 w-2.5 shrink-0`}),H(`span`,{className:`truncate`,children:r?`Copied`:e})]})}function Wt({localUrl:e,publicUrl:t}){return I(`div`,{className:`flex flex-wrap gap-1`,children:[H(Ut,{label:`Local`,value:e,title:`Copy LAN URL — ${Ht}`}),t&&H(Ut,{label:`Public`,value:t,title:`Copy public URL — ${Ht}`})]})}var Gt={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function Kt(e){return e in Gt}function qt(e){return Kt(e)?Gt[e]:e}function Jt(e,t){return`${e}${Le}/${encodeURIComponent(t)}`}F();var Yt=3e4;function Xt(e){let[t,n]=V(null),r=N(e=>{n(t=>t??e)},[]);return U(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?H(Zt,{onOrigin:r}):null}}function Zt({onOrigin:e}){let{data:t}=A({capName:`network-access`});return H(ee,{children:(t??[]).map(t=>H(Qt,{addonId:t.addonId,onOrigin:e},t.addonId))})}function Qt({addonId:e,onOrigin:t}){let{data:n}=c({addonId:e},{refetchInterval:Yt,retry:!1});return U(()=>{let e=n?G.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var $t=typeof O==`function`,en=`Track flags arrive with the next server update`;function tn(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var nn=$t?O:tn;function rn(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e))return null;let{trackId:t,markForTrain:n,debug:r}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`?null:{trackId:t,markForTrain:n,debug:r}}F();function an({label:e,hint:t,checked:n,disabled:r,title:i,icon:a,onToggle:o}){return I(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:r,title:i,onClick:o,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[H(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:a}),I(`span`,{className:`min-w-0 flex-1`,children:[H(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),H(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),H(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:H(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function on({deviceId:e,trackId:t,markForTrain:n,debug:r,onChange:i}){let a=nn(),[o,s]=V(null),c=o?.markForTrain??n===!0,l=o?.debug??r===!0,u=!$t||a.isPending,d=$t?void 0:en,f=n=>{u||(async()=>{try{let r=rn(await a.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;s(r),i?.(r)}catch(e){let t=e instanceof Error?e.message:``;window.alert(t===``?`Could not update this track. Check the server logs.`:`Could not update this track — ${t}`)}})()};return I(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[H(an,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:c,disabled:u,...d===void 0?{}:{title:d},icon:H(We,{className:`h-4 w-4`}),onToggle:()=>f({markForTrain:!c})}),H(an,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:l,disabled:u,...d===void 0?{}:{title:d},icon:H(Be,{className:`h-4 w-4`}),onToggle:()=>f({debug:!l})})]})}var X=100,sn=120,cn={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function ln(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function un(e,t,n){if(e.length===0||t===null)return cn;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return cn;let a=ln(e,n?.maxPoints??sn).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}F();var dn=15e3,fn=window.location.origin,pn=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),mn=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function hn(e){let[t,n]=V(null);return U(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function gn({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:I(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&H(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&H(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>H(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>H(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:H(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&H(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&H(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function $({label:e,value:t,mono:n}){return I(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[H(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),H(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function _n({row:t,cameraName:r,deleteAvailable:i,onClose:o,onDeleted:s,onFlagsChanged:c}){let u=re(),f=Ot(),p=t!==null,h=t?.deviceId??0,g=t?.trackId??``,_=t?.bestEventId??``,v=t?.timestamp??0,b=t?.windowMs??0,{data:x}=m({deviceId:h,trackId:g},{enabled:p}),{data:S}=l({trackId:g},{enabled:p}),{data:C}=a({eventId:_},{enabled:p&&_!==``}),{data:w}=e({deviceId:h,since:v-dn,until:v+b+dn},{enabled:p}),[T,E]=V(null),[D,O]=V(!1),{publicOrigin:k,probes:A}=Xt(p);U(()=>{E(null)},[h,g]);let j=R(()=>{let e=S??[],t=C??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[S,C]),M=Fe(j?`${Le}/${encodeURIComponent(j.key)}`:void 0),P=R(()=>{let e=new Set,t=[];for(let n of[...C??[],...S??[]])!n.base64||e.has(n.key)||(e.add(n.key),t.push(n));return t},[C,S]),F=R(()=>P.find(e=>pn.has(e.kind))??null,[P]),L=hn(F?`data:image/jpeg;base64,${F.base64}`:null),z=R(()=>un(x?.positions??[],L,{snapshots:(x?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[x?.positions,x?.snapshots,L]),B=N(e=>{let t=P.find(t=>t.key===e);t&&E(t)},[P]);if(t===null)return null;let te=T?`data:image/jpeg;base64,${T.base64}`:M.src,W=T?.kind??j?.kind,ne=W!==void 0&&mn.has(W)&&L!==null&&(x?.positions.length??0)>=2,G=w&&w.length>0?w[0]:null,ie=()=>{G&&(O(!0),(async()=>{try{let e=await u.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:G.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{O(!1)}})())},ae=()=>{!i||f.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await f.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),s()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},oe=Math.round(t.importance*100),se=x?.importanceReason?`${String(oe)}% · ${x.importanceReason}`:`${String(oe)}%`,ce=x?.zonesVisited&&x.zonesVisited.length>0?x.zonesVisited.join(`, `):`—`,ue=x?.audioLabels&&x.audioLabels.length>0?x.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,de=x?x.totalDistance.toFixed(2):`—`,me=he(x?x.firstSeen:v),ge=x?he(x.lastSeen):`—`;return H(n,{open:!0,onOpenChange:e=>!e&&o(),children:I(y,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[I(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[I(`div`,{className:`min-w-0`,children:[I(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,vt(t)?I(`span`,{className:`text-foreground-subtle`,children:[` · `,vt(t)]}):null]}),H(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:r})]}),H(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:H(Ae,{className:`h-4 w-4`})})]}),I(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[te?H(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:H(pe,{src:te,alt:`Key frame from ${r}`,fit:`natural`,className:`w-full`,overlay:ne?H(gn,{overlay:z,onPickSnapshot:B}):void 0})}):H(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:M.failed?I(ee,{children:[H(fe,{className:`h-8 w-8 opacity-60`}),H(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):H(q,{className:`h-6 w-6 animate-spin opacity-70`})}),P.length>0&&H(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:P.map(e=>{let t=`data:image/jpeg;base64,${e.base64}`,n=qt(e.kind),r=Jt(fn,e.key),i=k?Jt(k,e.key):null;return I(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[H(`button`,{type:`button`,onClick:()=>E(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${he(e.timestamp)}`,children:H(`img`,{src:t,alt:n,className:`h-full w-full object-cover`})}),I(`figcaption`,{className:`min-w-0 px-0.5`,children:[H(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),H(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:he(e.timestamp),children:le(e.timestamp)})]}),H(Wt,{localUrl:r,publicUrl:i})]},e.key)})}),A,G&&I(d,{variant:`secondary`,onClick:ie,disabled:D,children:[D?H(q,{className:`h-3.5 w-3.5 animate-spin`}):H(we,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),H(on,{deviceId:t.deviceId,trackId:t.trackId,...(x?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:x?.markForTrain??t.markForTrain},...(x?.debug??t.debug)===void 0?{}:{debug:x?.debug??t.debug},onChange:c}),I(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[H($,{label:`Camera`,value:r}),H($,{label:`Class`,value:t.className}),H($,{label:`Label`,value:t.label??`—`}),H($,{label:`Sub-label`,value:t.subLabel??`—`}),H($,{label:`Importance`,value:se}),H($,{label:`Zones visited`,value:ce}),H($,{label:`Audio heard`,value:ue}),H($,{label:`Total distance`,value:de}),H($,{label:`First seen`,value:me}),H($,{label:`Last seen`,value:ge}),H($,{label:`Track`,value:t.trackId,mono:!0})]})]}),H(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:H(`span`,{title:i?void 0:Et,children:I(d,{variant:`secondary`,onClick:ae,disabled:!i||f.isPending,children:[f.isPending?H(q,{className:`h-3.5 w-3.5 animate-spin`}):H(Me,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function vn(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function yn({row:e,cameraName:t,nowMs:n,onOpenDetail:r,selected:i=!1,onToggleSelect:a,score:o}){let s=Fe(e.bestEventId?`${Le}/${e.bestEventId}`:void 0),c=Math.round(e.importance*100),l=o===void 0?void 0:Math.round(o*100),u=vn(e.windowMs),d=()=>r(e);return I(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[I(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[s.src?H(`img`,{src:s.src,alt:`Event from ${t}`,onClick:d,className:`h-full w-full cursor-zoom-in object-cover`}):H(`button`,{type:`button`,onClick:d,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:s.failed?`Key-event media unavailable`:`No key-event media`,children:H(fe,{className:`h-6 w-6 opacity-60`})}),a&&H(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(Ct(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?H(xe,{className:`h-4 w-4 text-primary`}):H(Se,{className:`h-4 w-4`})}),l!==void 0&&I(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(l),`%`]}),c>0&&H(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(c)}),(e.markForTrain===!0||e.debug===!0)&&I(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&H(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:H(We,{className:`h-3 w-3`})}),e.debug===!0&&H(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:H(Be,{className:`h-3 w-3`})})]})]}),I(`button`,{type:`button`,onClick:d,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[I(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,vt(e)?I(`span`,{className:`text-foreground-subtle`,children:[` · `,vt(e)]}):null]}),H(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),I(`div`,{className:`flex items-center justify-between gap-2`,children:[H(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:ue(e.timestamp,n)}),u&&H(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:u})]})]})]})}F();function bn(){let[e,t]=V(!1),n=P(null),[r,i]=V(0),a=N(e=>{n.current!==e&&(n.current=e,i(e=>e+1))},[]);return U(()=>{let e=n.current;if(!e||typeof IntersectionObserver>`u`){t(!1);return}let r=new IntersectionObserver(e=>{let n=e[e.length-1];n&&t(!n.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return r.observe(e),()=>r.disconnect()},[r]),{ref:a,scrolledPast:e}}F();var xn=[`events-feed`],Sn=60,Cn=[{value:`importance`,label:`Importance`,icon:ze},{value:`time`,label:`Recent`,icon:ie}];function wn(){let e=te(),[n,r]=V(_e),[i,a]=V(new Set),[o,s]=V(new Set),[c,l]=V(0),[u,f]=V(`time`),[p,m]=V(new Set),[h,g]=V(null),[_,y]=V(()=>Date.now());U(()=>{let e=setInterval(()=>y(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:b,until:x}=R(()=>Tt({fromMs:n.fromMs,toMs:n.toMs},_),[n.fromMs,n.toMs,_]),S=bn(),{pending:C,refreshNow:w}=Pt({paused:h!==null||p.size>0||S.scrolledPast}),{data:T}=v({}),E=R(()=>(T??[]).filter(e=>e.type===ne.Camera),[T]),D=R(()=>E.map(e=>e.id),[E]),{data:O,isLoading:k}=t({deviceIds:D},{enabled:D.length>0,staleTime:5*6e4}),A=R(()=>Bt(O??[],i),[O,i]),j=Ot(),M=j.isPending,{rows:N,isLoading:P}=jt({deviceIds:D,since:b,until:x,minImportance:c>0?c:void 0,classFilter:o.size===1?[...o][0]:void 0}),F=R(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),L=e=>F.get(e)??`Camera #${String(e)}`,z=R(()=>ce(N).map(e=>({id:e,name:L(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[N,F]),B=R(()=>xt(St(N,{cameras:i,classes:o,minImportance:c}),u),[N,i,o,c,u]),W=me(B,Sn,R(()=>JSON.stringify([[...i].sort((e,t)=>e-t),[...o].sort(),c,u,b,x]),[i,o,c,u,b,x])),G=()=>{e.invalidateQueries({queryKey:xn})},re=()=>m(new Set);function ie(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ae(){if(p.size===0||!Y)return;let e=wt(N,p),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>j.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{G();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(Ct(o,e));else t.push(o)}),m(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>L(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let oe=B.length!==N.length;return I(`div`,{className:`relative space-y-3`,children:[I(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[H(ge,{onChange:r}),H(de,{cameras:z,selected:i,onChange:a}),H(Ft,{groups:A,selected:o,onChange:s,loading:k}),I(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[H(`span`,{children:`Min score`}),H(`input`,{type:`range`,min:0,max:1,step:.05,value:c,onChange:e=>l(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),H(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(c*100)})]}),H(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Cn.map(e=>{let t=e.icon;return I(`button`,{type:`button`,onClick:()=>f(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${u===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[H(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!P&&H(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:oe?`${String(B.length)} of ${String(N.length)} events`:`${String(B.length)} event${B.length===1?``:`s`}`})]}),p.size>0&&I(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[I(`span`,{className:`text-xs font-medium text-foreground`,children:[p.size,` selected`]}),I(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[H(`span`,{title:Y?void 0:`Track deletion arrives with the next server update`,children:I(d,{variant:`secondary`,onClick:ae,disabled:!Y||M,children:[M?H(q,{className:`h-3.5 w-3.5 animate-spin`}):H(Me,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),H(d,{variant:`ghost`,onClick:re,disabled:M,children:H(Ae,{className:`h-3.5 w-3.5`})})]})]}),P&&I(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[H(q,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!P&&B.length===0&&H(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),C&&H(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:H(`button`,{type:`button`,onClick:w,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!P&&B.length>0&&I(ee,{children:[H(`div`,{ref:S.ref,"aria-hidden":!0,className:`h-0`}),H(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:W.pageItems.map(e=>H(yn,{row:e,cameraName:L(e.deviceId),nowMs:_,selected:p.has(Ct(e.deviceId,e.trackId)),onToggleSelect:ie,onOpenDetail:g},Ct(e.deviceId,e.trackId)))}),H(se,{currentPage:W.page,totalItems:W.totalItems,pageSize:W.pageSize,onPageChange:W.setPage,itemNoun:`events`})]}),h&&H(_n,{row:h,cameraName:L(h.deviceId),deleteAvailable:Y,onClose:()=>g(null),onDeleted:()=>{G(),g(null)},onFlagsChanged:e=>{g(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug}:t)}})]})}F();var Tn=50,En=350,Dn=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function On(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function kn({onActiveChange:e}){let[n,r]=V(``),[i,a]=V(.2),[o,s]=V(null),[c,l]=V(null),[u,d]=V(null),f=C(n,En).trim(),p=f.length>0;U(()=>{e(p)},[p,e]);let[m,g]=V(()=>Date.now());U(()=>{let e=setInterval(()=>g(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:_}=v({}),y=R(()=>(_??[]).filter(e=>e.type===ne.Camera),[_]),b=R(()=>{let e=new Map;for(let t of _??[])e.set(t.id,t.name);return e},[_]),x=e=>b.get(e)??`Camera #${String(e)}`,S=R(()=>y.map(e=>e.id),[y]),{data:w}=t({deviceIds:S},{enabled:S.length>0,staleTime:5*6e4}),T=R(()=>zt(w??[],new Set(c===null?[]:[c])),[w,c]);U(()=>{o!==null&&(T.some(e=>e.kind===o)||s(null))},[T,o]);let{data:E,isFetching:D,isError:O,error:k}=h({text:f,minScore:i,limit:Tn,classFilter:o??void 0,deviceId:c??void 0},{enabled:p}),A=R(()=>[...E??[]].sort((e,t)=>t.score-e.score).map(e=>({...On(e),score:e.score})),[E]);function M(e){s(t=>t===e?null:e)}return I(`div`,{className:`space-y-3`,children:[I(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[I(`div`,{className:`flex flex-wrap items-center gap-2`,children:[I(`div`,{className:`relative min-w-[16rem] flex-1`,children:[H(be,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),H(`input`,{type:`text`,value:n,onChange:e=>r(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),n&&H(`button`,{type:`button`,onClick:()=>r(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:H(Ae,{className:`h-3.5 w-3.5`})})]}),D&&p&&H(q,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),I(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[H(`div`,{className:`flex items-center gap-1`,children:T.map(e=>H(`button`,{type:`button`,onClick:()=>M(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${o===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:j(e)},e.kind))}),I(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[H(`span`,{children:`Camera`}),I(`select`,{value:c===null?``:String(c),onChange:e=>l(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[H(`option`,{value:``,children:`All`}),y.map(e=>H(`option`,{value:String(e.id),children:e.name},e.id))]})]}),I(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[H(`span`,{children:`Match`}),H(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Dn.map(e=>H(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),p&&!D&&!O&&I(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[A.length,` match`,A.length===1?``:`es`]})]})]}),p&&I(`div`,{className:`space-y-3`,children:[O&&I(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,k instanceof Error?k.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!O&&D&&A.length===0&&I(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[H(q,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!O&&!D&&A.length===0&&I(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,f,`”. Try a looser match threshold or a different phrasing.`]}),!O&&A.length>0&&H(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:A.map(e=>H(yn,{row:e,cameraName:x(e.deviceId),nowMs:m,score:e.score,onOpenDetail:d},e.id))})]}),u&&H(_n,{row:u,cameraName:x(u.deviceId),deleteAvailable:Y,onClose:()=>d(null),onDeleted:()=>d(null)})]})}var An=15e3;function jn(e){let t=re(),n=B({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:An,refetchInterval:An,queryFn:async()=>((await t.trpcClient.zoneAnalytics.getCurrentSnapshot.query({deviceId:e}))?.stationaryObjects??[]).map(t=>({...t,deviceId:e}))}))});return{rows:n.flatMap(e=>e.data??[]).toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n.some(e=>e.isLoading)}}F();function Mn(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function Nn({row:e,cameraName:t,nowMs:n}){let r=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,i=Fe(r?`${Le}/${r}`:void 0);return I(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[I(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?H(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):H(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:H(Ge,{className:`h-6 w-6`})}),H(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),I(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[H(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),I(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Mn(n,e.becameStationaryAt)]})]})]})}function Pn(){let[e,t]=V(!1),n=Date.now(),{data:r}=v({}),i=R(()=>(r??[]).filter(e=>e.type===ne.Camera),[r]),a=R(()=>i.map(e=>e.id),[i]),o=R(()=>{let e=new Map;for(let t of i)e.set(t.id,t.name);return e},[i]),{rows:s}=jn(a);return s.length===0?null:I(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[I(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[H(e?Ee:Te,{className:`h-4 w-4 text-foreground-subtle`}),H(Ge,{className:`h-4 w-4 text-foreground-subtle`}),H(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),H(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:s.length}),H(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&H(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:s.map(e=>H(Nn,{row:e,cameraName:o.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}F();function Fn(){let[e,t]=V(!1);return H(Pe,{children:I(`section`,{className:`space-y-3`,children:[H(kn,{onActiveChange:t}),!e&&H(Pn,{}),!e&&H(wn,{})]})})}var In=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Ln=new Set(In);function Rn(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Ln.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function zn({annotations:e,selectedIndex:t,onSelect:n,onChange:r,onDelete:a}){return e.length===0?I(`p`,{className:`text-[11px] text-foreground-subtle p-3`,children:[`No subject on this frame yet. Drag on the image to draw one, or ask the pipeline for a proposal. Annotate `,H(`strong`,{children:`every`}),` subject — a frame with one box and three unlabelled people teaches the model that two thirds of the people in it are background.`]}):H(`ul`,{className:`divide-y divide-border`,children:e.map((e,o)=>{let c=o===t,l=Rn(e.label),f=Rn(e.subLabel);return I(`li`,{className:`p-2.5 space-y-1.5 ${c?`bg-surface-hover`:``}`,onFocus:()=>{n(o)},children:[I(`div`,{className:`flex items-center gap-2`,children:[H(s,{className:`w-28`,value:e.macroClass,options:In.map(e=>({value:e,label:e})),onChange:e=>{let t=In.find(t=>t===e.target.value);t!==void 0&&r(o,{macroClass:t})}}),H(s,{className:`w-32`,value:e.kind,options:[{value:`subject`,label:`subject`},{value:`model_error`,label:`model error`}],onChange:e=>{r(o,{kind:e.target.value===`model_error`?`model_error`:`subject`})}}),e.source===`assist`&&I(i,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),H(d,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:H(Me,{className:`h-3 w-3`})})]}),I(`div`,{className:`flex items-center gap-2`,children:[H(u,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{r(o,{label:e.target.value})}}),H(u,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:e=>{r(o,{subLabel:e.target.value})}})]}),l!==null&&H(`p`,{className:`text-[11px] text-danger`,children:l}),f!==null&&H(`p`,{className:`text-[11px] text-danger`,children:f})]},`${String(o)}-${String(e.bbox.x)}`)})})}function Bn(e){return e.every(e=>Rn(e.label)===null&&Rn(e.subLabel)===null&&Ln.has(e.macroClass))}function Vn(e){return e<0?0:e>1?1:e}function Hn(e,t,n,r){if(!(e>0)||!(t>0)||!(n>0)||!(r>0))return null;let i=Math.min(e/n,t/r),a=n*i,o=r*i;return{left:(e-a)/2,top:(t-o)/2,width:a,height:o}}function Un(e,t,n){return{x:Vn((e-n.left)/n.width),y:Vn((t-n.top)/n.height)}}function Wn(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function Gn(e){return e.w>=.01&&e.h>=.01}function Kn(e,t){return{left:t.left+e.x*t.width,top:t.top+e.y*t.height,width:e.w*t.width,height:e.h*t.height}}function qn(e,t){let n=-1,r=1/0;return e.forEach((e,i)=>{if(!(t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h))return;let a=e.w*e.h;a<r&&(n=i,r=a)}),n}F();function Jn({imageSrc:e,imageWidth:t,imageHeight:n,boxes:r,selectedIndex:i,onSelect:a,onDraw:o}){let s=P(null),[c,l]=V({w:0,h:0}),[u,d]=V(null);L(()=>{let e=s.current;if(e===null)return;let t=new ResizeObserver(()=>{l({w:e.clientWidth,h:e.clientHeight})});return t.observe(e),l({w:e.clientWidth,h:e.clientHeight}),()=>{t.disconnect()}},[]);let f=Hn(c.w,c.h,t,n),p=N(e=>{let t=s.current;if(t===null||f===null)return null;let n=t.getBoundingClientRect();return Un(e.clientX-n.left,e.clientY-n.top,f)},[f]);return I(`div`,{ref:s,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none`,onPointerDown:e=>{let t=p(e);t!==null&&(e.currentTarget.setPointerCapture(e.pointerId),d({start:t,current:Wn(t,t)}))},onPointerMove:e=>{if(u===null)return;let t=p(e);t!==null&&d({start:u.start,current:Wn(u.start,t)})},onPointerUp:()=>{if(u===null)return;let e=u.current;d(null),Gn(e)?o(e):a(qn(r.map(e=>e.bbox),u.start))},children:[H(`img`,{src:e,alt:`Frame being annotated`,className:`absolute inset-0 w-full h-full object-contain pointer-events-none`}),f!==null&&r.map((e,t)=>{let n=Kn(e.bbox,f),r=e.kind===`model_error`,a=t===i,o=r?`#ef4444`:a?`#22c55e`:`#3b82f6`;return H(`div`,{className:`absolute pointer-events-none`,style:{left:n.left,top:n.top,width:n.width,height:n.height,border:`${a?`2px`:`1px`} ${r?`dashed`:`solid`} ${o}`,opacity:e.source===`assist`&&!a?.65:1},children:I(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded`,style:{background:o,color:`#08121f`},children:[e.label??e.macroClass,r?` ✕`:``]})},`${String(t)}-${String(e.bbox.x)}-${String(e.bbox.y)}`)}),u!==null&&f!==null&&H(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:Kn(u.current,f)})]})}function Yn(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function Xn({candidates:e,copies:t,activeFrameId:n,refusals:r,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c}){let l=new Set(t.map(e=>e.sourceMediaKey)),u=e.filter(e=>!l.has(e.mediaKey));return I(`div`,{className:`space-y-3`,children:[I(`section`,{children:[I(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`In the dataset (`,t.length,`)`]}),t.length===0?H(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No frame copied yet. Selecting a frame copies it into retrain storage immediately — the dataset stops depending on the track's own media from that moment.`}):H(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>H(`li`,{children:I(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[I(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{s(e.frameId)},children:[H(Oe,{className:`h-3 w-3 text-success`}),H(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),I(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,Yn(e.sizeBytes)]})]}),I(`button`,{type:`button`,"aria-label":`Remove this frame from the dataset`,className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-danger`,onClick:()=>{c(e.frameId)},children:[H(Me,{className:`h-3 w-3`}),`remove`]})]})},e.frameId))})]}),I(`section`,{children:[I(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,u.length,`)`]}),u.length===0?H(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.length===0?`This track has no whole, unannotated frame left — its media aged out before it was marked. Anything already copied above is still usable.`:`Every available frame is already in the dataset.`}):H(`ul`,{className:`flex flex-wrap gap-2`,children:u.map(e=>{let t=r.get(e.mediaKey);return I(`li`,{children:[I(d,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaKey)},children:[a?H(q,{className:`h-3 w-3 animate-spin`}):H(t===void 0?Ue:fe,{className:`h-3 w-3`}),H(`span`,{className:`ml-1`,children:e.kind}),H(`span`,{className:`ml-1 text-foreground-subtle`,children:Yn(e.sizeBytes)})]}),t!==void 0&&H(i,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaKey)})})]})]})}function Zn(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var Qn={untouched:{icon:He,label:`to do`,variant:`default`},started:{icon:Ve,label:`frames only`,variant:`info`},ready:{icon:De,label:`annotated`,variant:`success`}};function $n(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function er({tracks:e,isLoading:t,selectedTrackId:n,deviceNames:r,onSelect:a}){return t?I(`div`,{className:`flex items-center gap-2 p-4 text-xs text-foreground-subtle`,children:[H(q,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?H(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Nothing in staging. Mark a track for training from the viewer or the Events grid and it appears here.`}):H(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=Qn[Zn(e)],o=t.icon;return H(`li`,{children:I(`button`,{type:`button`,onClick:()=>{a(e)},className:`w-full text-left px-3 py-2 flex items-start gap-2 hover:bg-surface-hover ${e.trackId===n?`bg-surface-hover`:``}`,children:[H(o,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),I(`span`,{className:`min-w-0 flex-1`,children:[I(`span`,{className:`flex items-center gap-2`,children:[H(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),H(i,{variant:t.variant,children:t.label})]}),I(`span`,{className:`block text-[11px] text-foreground-subtle truncate`,children:[r.get(e.deviceId)??`Camera ${String(e.deviceId)}`,` ·`,` `,$n(e.lastSeen)]}),I(`span`,{className:`block text-[11px] text-foreground-muted`,children:[e.frameCount,` frame`,e.frameCount===1?``:`s`,` ·`,` `,e.annotationCount,` subject`,e.annotationCount===1?``:`s`]})]})]})},e.trackId)})})}F();var tr=`person`;function nr(){let[e,t]=V(null),[n,r]=V(null),[a,o]=V([]),[s,c]=V(-1),[l,u]=V(new Map),[m,h]=V(null),_=v({projection:`slim`,isCamera:!0}),y=R(()=>{let e=new Map;for(let t of _.data??[])e.set(t.id,t.name);return e},[_.data]),C=T({}),O=x({trackId:e?.trackId??``},{enabled:e!==null}),k=D({trackId:e?.trackId??``},{enabled:e!==null}),A=p({frameId:n??``},{enabled:n!==null}),j=b(),M=w(),P=g(),F=E(),L=f(),z=S();U(()=>{if(n===null){o([]);return}o((k.data??[]).filter(e=>e.mediaKey===n).map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))),c(-1)},[n,k.data]),U(()=>{let e=O.data?.copies??[];n===null&&e.length>0&&r(e[0].frameId)},[O.data,n]);let B=N(e=>{t(e),r(null),o([]),u(new Map),h(null)},[]),te=N(async t=>{if(e===null)return;let n=await j.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,mediaKeys:[t]});if(n.refused.length>0){let e=new Map(l);for(let t of n.refused)e.set(t.sourceMediaKey,t.reason);u(e)}n.copied.length>0&&r(n.copied[0].frameId),await O.refetch(),await C.refetch()},[e,j,l,O,C]),W=N(async t=>{e!==null&&(await M.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,frameId:t}),n===t&&r(null),await O.refetch(),await k.refetch(),await C.refetch())},[e,M,n,O,k,C]),ne=N(async t=>{if(e===null||n===null)return;h(null);let r=await P.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,frameId:n,subject:t===`package`?{kind:`package`}:{kind:`objects`,modelId:`yolo26n`,minScore:.3}});if(r.kind===`refused`){h(r.reason===`no-zone`?`A package proposal runs on the zone crop only — this camera has no zone, and running the detector on the whole frame at 0.35 proposes furniture.`:`The pipeline refused: ${r.reason}${r.detail===void 0?``:` — ${r.detail}`}`);return}o(e=>[...e,...r.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))]),h(`${r.proposals.length} proposal${r.proposals.length===1?``:`s`} from ${r.modelId}`+(r.belowThreshold>0?` — ${r.belowThreshold} more were below ${r.minScore.toFixed(2)}`:``))},[e,n,P]),G=N(e=>{o(t=>[...t,{bbox:e,macroClass:tr,kind:`subject`,source:`operator`}]),c(a.length)},[a.length]),re=N((e,t)=>{o(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),ie=N(e=>{o(t=>t.filter((t,n)=>n!==e)),c(-1)},[]),ae=N(async()=>{e===null||n===null||(await F.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,frameId:n,annotations:a.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{},...e.subLabel!==void 0&&e.subLabel!==``?{subLabel:e.subLabel}:{},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))}),await k.refetch(),await C.refetch(),h(`Annotations saved.`))},[e,n,a,F,k,C]),oe=N(async()=>{if(e===null)return;let n=await L.mutateAsync({deviceId:e.deviceId,trackId:e.trackId});h(n.changed?`Track completed — it is now trained, and its own media is evictable again.`:n.reason===`no-frames-copied`?`Refused: no frame was ever copied into the dataset. Completing would let retention delete material nothing was extracted from.`:`Refused: ${n.reason??`unknown`}`),await C.refetch(),n.changed&&t(null)},[e,L,C]),se=N(async()=>{if(e===null)return;let t=await z.mutateAsync({deviceId:e.deviceId,trackId:e.trackId});h(t.changed?`Track returned to staging. Its copies and annotations were left alone.`:`Refused: ${t.reason??`unknown`}`),await C.refetch()},[e,z,C]),ce=A.data,le=Bn(a)&&n!==null;return I(Pe,{subtitle:`Turn the tracks you marked for training into an annotated dataset. Selecting a frame copies it — the dataset never depends on media that can be swept.`,actions:e===null?null:I(`div`,{className:`flex items-center gap-2`,children:[I(d,{variant:`secondary`,size:`sm`,onClick:()=>void se(),children:[H(Ce,{className:`h-3 w-3`}),H(`span`,{className:`ml-1`,children:`Back to staging`})]}),I(d,{size:`sm`,onClick:()=>void oe(),children:[H(We,{className:`h-3 w-3`}),H(`span`,{className:`ml-1`,children:`Complete track`})]})]}),children:[m!==null&&H(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:m}),I(`div`,{className:`grid grid-cols-1 lg:grid-cols-[minmax(0,260px)_minmax(0,1fr)] gap-4`,children:[I(`aside`,{className:`rounded-md border border-border bg-surface overflow-hidden`,children:[I(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between`,children:[H(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Staging`}),H(i,{children:C.data?.length??0})]}),H(er,{tracks:C.data??[],isLoading:C.isLoading,selectedTrackId:e?.trackId??null,deviceNames:y,onSelect:B})]}),H(`section`,{className:`space-y-3 min-w-0`,children:e===null?H(`p`,{className:`text-xs text-foreground-subtle`,children:`Pick a track from the staging list to start annotating it.`}):I(ee,{children:[H(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:H(Xn,{candidates:O.data?.candidates??[],copies:O.data?.copies??[],activeFrameId:n,refusals:l,isSelecting:j.isPending,onSelectCandidate:e=>void te(e),onOpenCopy:r,onRemoveCopy:e=>void W(e)})}),n!==null&&I(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[H(`div`,{className:`rounded-md border border-border overflow-hidden`,children:ce===void 0?I(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[H(q,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):H(Jn,{imageSrc:`data:image/jpeg;base64,${ce.base64}`,imageWidth:ce.width,imageHeight:ce.height,boxes:a,selectedIndex:s,onSelect:c,onDraw:G})}),I(`div`,{className:`rounded-md border border-border bg-surface flex flex-col min-h-0`,children:[I(`div`,{className:`px-3 py-2 border-b border-border flex items-center gap-2`,children:[H(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),I(d,{variant:`secondary`,size:`sm`,disabled:P.isPending,onClick:()=>void ne(`objects`),children:[H(je,{className:`h-3 w-3`}),H(`span`,{className:`ml-1`,children:`Propose`})]}),I(d,{variant:`secondary`,size:`sm`,disabled:P.isPending,onClick:()=>void ne(`package`),children:[H(je,{className:`h-3 w-3`}),H(`span`,{className:`ml-1`,children:`Packages`})]})]}),H(`div`,{className:`flex-1 overflow-y-auto`,children:H(zn,{annotations:a,selectedIndex:s,onSelect:c,onChange:re,onDelete:ie})}),I(`div`,{className:`px-3 py-2 border-t border-border flex items-center justify-between`,children:[I(`span`,{className:`text-[11px] text-foreground-subtle`,children:[a.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),H(d,{size:`sm`,disabled:!le||F.isPending,onClick:()=>void ae(),children:`Save frame`})]})]})]})]})})]})]})}function rr(){return H(`div`,{className:`flex flex-col p-4`,children:H(Re,{tabs:[{id:`feed`,label:`Feed`,icon:ke,content:H(Fn,{})},{id:`retrain`,label:`Retrain`,icon:We,content:H(nr,{})},{id:`debug`,label:`Debug`,icon:Be,content:H(_t,{})}]})})}export{rr as EventsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,kn as t,w as n}from"./src-
|
|
1
|
+
import{C as e,kn as t,w as n}from"./src-BxX2FkJ3.js";import{K as r,Q as i,S as a,W as o,b as s,q as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as u}from"./refresh-cw-B0NcvZHF.js";import{t as d}from"./search-871hv572.js";import{G as f,L as p,R as m,S as h,i as g}from"./index-dqzu-f71.js";var _=f(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]);function v({deviceId:e,mode:n}){let{data:r,isLoading:i,isFetching:o,isError:s,refetch:c}=t({deviceId:e},{enabled:Number.isFinite(e)}),d=r?.devices??[];return a(`div`,{className:`mt-3 rounded-md border border-border bg-background p-2.5`,children:[a(`div`,{className:`flex items-center justify-between mb-1.5`,children:[a(`span`,{className:`text-[11px] font-medium text-foreground`,children:[`Resolved links`,l(`span`,{className:`ml-1.5 text-[10px] font-normal text-foreground-subtle`,children:(r?.mode??n)===`auto`?`children + same location`:`children + manual list`})]}),a(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,disabled:o,onClick:()=>void c(),title:`Re-run the resolver`,children:[l(u,{className:`h-3 w-3 ${o?`animate-spin`:``}`}),`Refresh`]})]}),i?a(`div`,{className:`flex items-center gap-1.5 py-1 text-[11px] text-foreground-subtle`,children:[l(h,{className:`h-3 w-3 animate-spin`}),`Resolving…`]}):s?l(`p`,{className:`py-1 text-[11px] text-danger`,children:`Failed to resolve linked devices.`}):d.length===0?l(`p`,{className:`py-1 text-[11px] text-foreground-subtle italic`,children:`No linked devices resolved.`}):l(`div`,{className:`flex flex-wrap gap-1`,children:d.map(e=>a(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border bg-surface px-1.5 py-0.5 text-[11px] text-foreground max-w-full`,title:e.location??void 0,children:[l(`span`,{className:`truncate`,children:e.name}),e.location!==null&&e.location.length>0&&a(`span`,{className:`inline-flex items-center gap-0.5 shrink-0 text-[10px] text-foreground-subtle`,children:[l(_,{className:`h-2.5 w-2.5`}),e.location]})]},e.deviceId))})]})}function y(e){return[e.value,e.label,e.description].filter(e=>typeof e==`string`&&e.length>0).join(` `).toLowerCase()}function b(e,t){let n=t.trim().toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?e:e.filter(e=>{let t=y(e);return n.every(e=>t.includes(e))})}function x(e,t){let n=new Map(e.map(e=>[e.value,e])),r=new Set(t);return{selectedOptions:t.map(e=>n.get(e)??{value:e,label:e}),unselected:e.filter(e=>!r.has(e.value))}}function S(e){return e>=8}i();var C=`flex items-center gap-1.5 rounded-md border border-border bg-background px-2 py-1.5 focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30`,w=`block text-[11px] font-medium text-foreground mb-1 break-words`,T=`text-[10px] text-foreground-subtle mt-0.5 break-words`;function E({field:e,value:t,onChange:n,disabled:i,translationFn:s}){let u=Array.isArray(t)?t:[],f=i===!0||e.disabled===!0,h=e.maxItems!==void 0&&u.length>=e.maxItems,[_,v]=c(``),[y,S]=c(!1),[E,D]=c(0),O=r(null),k=r(null),{selectedOptions:A}=o(()=>x(e.options,u),[e.options,u]),j=o(()=>b(e.options,_),[e.options,_]),N=t=>{if(!f)if(u.includes(t))n(u.filter(e=>e!==t));else{if(e.maxItems!==void 0&&u.length>=e.maxItems)return;n([...u,t])}},P=e=>{if(e.key===`ArrowDown`)e.preventDefault(),S(!0),D(e=>j.length===0?0:(e+1)%j.length);else if(e.key===`ArrowUp`)e.preventDefault(),S(!0),D(e=>j.length===0?0:(e-1+j.length)%j.length);else if(e.key===`Enter`){e.preventDefault();let t=j[E];t&&N(t.value)}else e.key===`Escape`?S(!1):e.key===`Backspace`&&_===``&&u.length>0&&n(u.slice(0,-1))},F=M(e.label,s),I=M(e.description,s);return a(`div`,{className:`min-w-0`,children:[F!==void 0&&F!==``&&l(`label`,{className:w,children:F}),A.length>0&&l(`div`,{className:`flex flex-wrap gap-1 mb-1.5`,children:A.map(e=>a(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary/10 px-1.5 py-0.5 text-[11px] text-primary max-w-full`,children:[l(`span`,{className:`truncate`,children:e.label}),!f&&l(`button`,{type:`button`,className:`shrink-0 hover:text-danger`,"aria-label":`Remove ${e.label}`,onClick:()=>N(e.value),children:l(g,{className:`h-2.5 w-2.5`})})]},e.value))}),a(`div`,{className:C+(f?` opacity-50`:``),children:[l(d,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),l(`input`,{ref:O,type:`text`,role:`combobox`,"aria-expanded":y,"aria-controls":`msel-${e.key}`,className:`min-w-0 flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-foreground-disabled`,value:_,placeholder:h?`Max ${e.maxItems} selected`:e.placeholder??`Search to add…`,disabled:f,onChange:e=>{v(e.target.value),S(!0),D(0)},onFocus:()=>S(!0),onBlur:()=>{k.current=setTimeout(()=>S(!1),120)},onKeyDown:P}),l(p,{className:`h-3.5 w-3.5 shrink-0 cursor-pointer text-foreground-subtle`,onMouseDown:e=>{e.preventDefault(),k.current&&clearTimeout(k.current),S(e=>!e),O.current?.focus()}})]}),y&&!f&&l(`div`,{id:`msel-${e.key}`,role:`listbox`,className:`mt-1 max-h-56 overflow-y-auto rounded-md border border-border bg-surface shadow-lg`,onMouseDown:e=>{e.preventDefault()},children:j.length===0?a(`div`,{className:`px-2.5 py-2 text-[11px] text-foreground-subtle italic`,children:[`No matches for “`,_,`”`]}):j.map((e,t)=>{let n=u.includes(e.value),r=!n&&h;return a(`button`,{type:`button`,role:`option`,"aria-selected":n,disabled:r,className:[`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-xs transition-colors`,t===E?`bg-primary/10`:`hover:bg-surface-hover`,r?`opacity-40 cursor-not-allowed`:`cursor-pointer`].join(` `),onMouseEnter:()=>D(t),onClick:()=>N(e.value),children:[l(`span`,{className:[`flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border`,n?`border-primary bg-primary text-white`:`border-border`].join(` `),children:n&&l(m,{className:`h-2.5 w-2.5`})}),l(`span`,{className:`truncate text-foreground`,children:e.label})]},e.value)})}),I&&l(`p`,{className:T,children:I})]})}i();var D=`_linkedDevicesMode`,O=`_linkedDeviceIds`;function k(e){return e.type===`multiselect`}function A({field:t,values:r,onChange:i,disabled:a,translationFn:o,onTestField:s,externalProbe:c,allFields:u,onAction:d}){return k(t)&&S(t.options.length)?n(t,r,u)?l(E,{field:t,value:r[t.key],onChange:e=>i(t.key,e),disabled:a,translationFn:o}):null:l(e,{field:t,values:r,onChange:i,disabled:a,translationFn:o,onTestField:s,externalProbe:c,allFields:u,onAction:d})}function j(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function M(e,t){if(e!==void 0)return t&&j(e)?t(e):e}function N({section:t,values:r,onChange:i,disabled:o,translationFn:u,onTestField:d,probeResults:f,onAction:p,deviceId:m}){let[h,g]=c(t.defaultCollapsed??!1),_=t.style===`accordion`;if(t.fields.reduce((e,i)=>e+ +!!n(i,r,t.fields),0)===0)return null;let y=t.fields.some(e=>`key`in e&&e.key===D),b=r[D]===`manual`?`manual`:`auto`,x=y&&b!==`manual`?t.fields.filter(e=>!(`key`in e&&e.key===O)):t.fields,S=y?1:t.columns??2,C=S===1?`grid-cols-1`:S===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:S===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,w=t.fields.length===1&&t.fields[0]?.type===`widget`?t.fields[0]:void 0;return a(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(w!==void 0||!t.title&&!t.description)&&a(`div`,{className:[`flex items-center justify-between mb-2`,_?`cursor-pointer`:``].join(` `),onClick:_?()=>g(e=>!e):void 0,children:[a(`div`,{children:[t.title&&l(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:M(t.title,u)}),t.description&&l(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:M(t.description,u)})]}),_&&l(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:h?`▸`:`▾`})]}),!h&&(w===void 0?a(s,{children:[l(`div`,{className:`grid ${C} gap-x-3 gap-y-2.5`,children:x.map(e=>l(A,{field:e,values:r,onChange:i,disabled:o,translationFn:u,onTestField:d,externalProbe:f?.[e.key],allFields:t.fields,onAction:p},e.key))}),y&&m!==void 0&&l(v,{deviceId:m,mode:b})]}):l(e,{field:w,values:r,onChange:i,disabled:o,translationFn:u,onTestField:d,externalProbe:f?.[w.key],allFields:t.fields,onAction:p},w.key))]})}function P({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:a,probeResults:o,onClearProbe:s,onAction:c,deviceId:u}){let d=(e,r)=>{n({...t,[e]:r}),s?.(e)};return l(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>l(N,{section:e,values:t,onChange:d,disabled:r,translationFn:i,onTestField:a,probeResults:o,onAction:c,deviceId:u},`${e.id}-${n}`))})}export{_ as n,P as t};
|