@camstack/addon-admin-ui 1.1.34 → 1.1.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/assets/{AddLocationWizard-Bi0ljsVA.js → AddLocationWizard-fU39g28j.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-DBF9Z9As.js → AddonCollectionPage-2R4sBcnH.js} +1 -1
  3. package/dist/assets/{Addons-B-__KXJU.js → Addons-OPXB9gcH.js} +1 -1
  4. package/dist/assets/{AdminTabs-BuqsvGrG.js → AdminTabs-DZ8fjA_E.js} +1 -1
  5. package/dist/assets/{BrokerForm-_89nTW-H.js → BrokerForm-DxBh4Ab_.js} +1 -1
  6. package/dist/assets/{Capabilities-ClcXLZXO.js → Capabilities-BowvKc7g.js} +1 -1
  7. package/dist/assets/{CapabilityBadges-D17MpdW-.js → CapabilityBadges-Cb2taM1G.js} +1 -1
  8. package/dist/assets/{Cluster-Duon566q.js → Cluster-Dvu3Qmr3.js} +1 -1
  9. package/dist/assets/{Dashboard-DRCyjJak.js → Dashboard-DwJvs0Hh.js} +1 -1
  10. package/dist/assets/{Data-CeLbKmt6.js → Data-zUHS7p4f.js} +1 -1
  11. package/dist/assets/{DetectionIntelligence-Co-3EN_y.js → DetectionIntelligence-BneZGPL8.js} +1 -1
  12. package/dist/assets/DeviceDetail-D55afT28.js +2 -0
  13. package/dist/assets/{Devices-DanUITRF.js → Devices-BPv3cLJV.js} +1 -1
  14. package/dist/assets/{EmbedPlayerPage-g2S5bdPi.js → EmbedPlayerPage-B-sPclrx.js} +1 -1
  15. package/dist/assets/{FormBuilder-BKE262Ak.js → FormBuilder-BHrYFTqO.js} +1 -1
  16. package/dist/assets/{Identity-CzZXW3_y.js → Identity-4N-nfSAK.js} +1 -1
  17. package/dist/assets/{IntegrationDetail-Cd9xdRi_.js → IntegrationDetail-CASAMzWi.js} +1 -1
  18. package/dist/assets/{Integrations-D3majjXx.js → Integrations-BK8yyBnE.js} +1 -1
  19. package/dist/assets/{Integrations-B4fhe1Gb.js → Integrations-CFNCpTGQ.js} +1 -1
  20. package/dist/assets/{Logs-CgKEHupO.js → Logs-B1uh5BYK.js} +1 -1
  21. package/dist/assets/{MotionZonesSettings-A8_xE3RR.js → MotionZonesSettings-3tt6mBQ0.js} +1 -1
  22. package/dist/assets/{MyAccess-CQ4EIWqU.js → MyAccess-Brl1MiDm.js} +1 -1
  23. package/dist/assets/{Network-BajDLc8U.js → Network-CcZYSjnr.js} +1 -1
  24. package/dist/assets/{NodeAddonsSettingsPanel-G-afOE2k.js → NodeAddonsSettingsPanel-DTTq6Ljf.js} +1 -1
  25. package/dist/assets/{NotificationTargets-DQmAITEb.js → NotificationTargets-Bji4H-RC.js} +1 -1
  26. package/dist/assets/Pipeline-Bj4liIat.js +1 -0
  27. package/dist/assets/{PrivacyMaskSettings-D-Yfij0p.js → PrivacyMaskSettings-CKAT3JFX.js} +1 -1
  28. package/dist/assets/{ProviderIcon-D2GVIM6D.js → ProviderIcon-KQShdlru.js} +1 -1
  29. package/dist/assets/{ScanNetworkModal-CXe1ZhrW.js → ScanNetworkModal-mQF_it2k.js} +1 -1
  30. package/dist/assets/{Settings-duX068YK.js → Settings-Bq1sSX7Z.js} +1 -1
  31. package/dist/assets/{Showroom-tEsQLYvU.js → Showroom-inuhv53W.js} +1 -1
  32. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DpZ6S4A1.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BAi3eQvB.js} +1 -1
  33. package/dist/assets/{build-cluster-graph-DEgurNYu.js → build-cluster-graph-DlOB4sV_.js} +1 -1
  34. package/dist/assets/circle-check-big-Bcoiv1yk.js +1 -0
  35. package/dist/assets/{copy-BZEouQxh.js → copy-C3o1fFh1.js} +1 -1
  36. package/dist/assets/{dist-B5BcBM_J.js → dist-B8dNOlY9.js} +1 -1
  37. package/dist/assets/dist-DRenWL4F.js +7 -0
  38. package/dist/assets/{download-BdD4jpmM.js → download-D2Hdt3_T.js} +1 -1
  39. package/dist/assets/{hostInit-DL0Pq8FG.js → hostInit-BKnQjzgs.js} +1 -1
  40. package/dist/assets/index-CpCNvkGK.js +4 -0
  41. package/dist/assets/index-DO0772OA.css +2 -0
  42. package/dist/assets/{key-round-Co1IZCyf.js → key-round-Jz1W_Dm_.js} +1 -1
  43. package/dist/assets/{mf-entry-bootstrap-0-9f7f6a36.js → mf-entry-bootstrap-0-b853eab9.js} +2 -2
  44. package/dist/assets/{pencil-Ctcgfyao.js → pencil-CFG04wDY.js} +1 -1
  45. package/dist/assets/{player-overlays-D_uAA1FM.js → player-overlays-CpsGl45o.js} +1 -1
  46. package/dist/assets/plus-Bc_u_j_c.js +1 -0
  47. package/dist/assets/{radio-COzWf8RL.js → radio-Bvao3n8m.js} +1 -1
  48. package/dist/assets/{refresh-cw-DPd788Ly.js → refresh-cw-B3eKxMWT.js} +1 -1
  49. package/dist/assets/remoteEntry-xYIBqMy5.js +1 -0
  50. package/dist/assets/{rotate-ccw-D4xWcHzx.js → rotate-ccw-g29vnwke.js} +1 -1
  51. package/dist/assets/rotate-cw-B3yeEqVR.js +1 -0
  52. package/dist/assets/search-ChyM3D_C.js +1 -0
  53. package/dist/assets/{server-DCZCFjSL.js → server-BrIBBG6H.js} +1 -1
  54. package/dist/assets/{sparkles-DL5wzv3h.js → sparkles-ARuuvyj1.js} +1 -1
  55. package/dist/assets/square-BM303wp_.js +1 -0
  56. package/dist/assets/{square-check-big-DXqD6BOi.js → square-check-big-piMyzaVk.js} +1 -1
  57. package/dist/assets/src-BXL7z3gT.js +7 -0
  58. package/dist/assets/src-Dp6qXTLR.js +67 -0
  59. package/dist/assets/{upload-CnDk7r-2.js → upload-CZGhOSU5.js} +1 -1
  60. package/dist/assets/{useDevice-CSvcJkG5.js → useDevice-D09Wge-X.js} +1 -1
  61. package/dist/assets/{useEventInvalidation-D85JeECP.js → useEventInvalidation-NEk-4cPL.js} +1 -1
  62. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-wsjHIjiy.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-rJ2O9jZ3.js} +2 -2
  63. package/dist/assets/{wifi-DZtU-62o.js → wifi-CyY3elJf.js} +1 -1
  64. package/dist/assets/{zap-C4RnkQsi.js → zap-l_Zh2jBY.js} +1 -1
  65. package/dist/index.html +6 -6
  66. package/dist/server/addon.js +205 -186
  67. package/package.json +1 -1
  68. package/dist/assets/DeviceDetail-BbrCW8vA.js +0 -2
  69. package/dist/assets/Pipeline-CzR4gmRW.js +0 -1
  70. package/dist/assets/circle-check-big-djmpxb6e.js +0 -1
  71. package/dist/assets/dist-BEwW84yT.js +0 -7
  72. package/dist/assets/index-2HwvWrOH.css +0 -2
  73. package/dist/assets/index-BGSe7zm2.js +0 -4
  74. package/dist/assets/plus-BPews3hd.js +0 -1
  75. package/dist/assets/remoteEntry-DUPeCPoh.js +0 -1
  76. package/dist/assets/rotate-cw-DXeseGvV.js +0 -1
  77. package/dist/assets/search-D3qB3OId.js +0 -1
  78. package/dist/assets/square-DaYEm0Ao.js +0 -1
  79. package/dist/assets/src-CSLY6BPe.js +0 -67
  80. package/dist/assets/src-DkLajgHy.js +0 -7
@@ -1,2 +0,0 @@
1
- import{$r as e,Ai as t,B as n,Bn as r,Br as i,Cn as a,D as o,Dn as s,E as c,En as l,Fn as u,G as d,Ia as f,In as p,It as m,J as h,K as g,La as _,Ln as v,M as y,Mn as b,N as x,Nn as S,O as C,On as w,Or as T,Pn as E,Q as D,Qi as ee,R as O,Rn as k,Si as te,Sn as A,T as j,Tn as ne,U as re,Vn as ie,W as M,X as N,Xi as P,Y as ae,Yi as oe,Yr as se,a as ce,bt as le,ca as F,dn as ue,dr as de,et as fe,f as pe,fa as me,fr as I,g as he,ga as ge,hi as _e,i as ve,ii as ye,in as L,ir as be,j as xe,ji as Se,jn as Ce,l as we,la as Te,m as Ee,n as De,nt as Oe,o as ke,oi as R,p as Ae,pa as je,pn as Me,q as Ne,r as Pe,rn as Fe,tt as Ie,u as Le,ua as Re,ur as ze,vn as Be,wi as Ve,wn as He,y as Ue,yn as We,z as Ge,zn as Ke}from"./src-CSLY6BPe.js";import{I as z,K as B,Q as V,S as H,W as U,b as W,o as G,q as K,t as qe,x as q,z as J}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{A as Je,D as Ye,E as Xe,I as Ze,N as Qe,O as $e,S as et,T as tt,b as nt,g as rt,k as it,w as Y,y as at}from"./src-DkLajgHy.js";import{c as ot,k as st,p as X,r as ct,t as lt,u as ut}from"./player-overlays-D_uAA1FM.js";import{t as dt}from"./CapabilityBadges-D17MpdW-.js";import{n as ft,t as pt}from"./rotate-ccw-D4xWcHzx.js";import{t as mt}from"./ProviderIcon-D2GVIM6D.js";import{i as ht,n as gt,t as _t}from"./useDevice-CSvcJkG5.js";import{t as vt}from"./pencil-Ctcgfyao.js";import{t as yt}from"./plus-BPews3hd.js";import{t as bt}from"./refresh-cw-DPd788Ly.js";import{t as xt}from"./rotate-cw-DXeseGvV.js";import{t as St}from"./server-DCZCFjSL.js";import{t as Ct}from"./wifi-DZtU-62o.js";import{B as wt,F as Tt,G as Et,I as Dt,O as Ot,R as kt,U as At,V as jt,W as Mt,_ as Nt,a as Pt,c as Ft,i as It,k as Lt,p as Rt,r as zt,s as Bt,t as Vt,v as Ht,x as Ut}from"./index-BGSe7zm2.js";import{t as Wt}from"./StatusBadge-Dcr2bw58.js";import{t as Gt}from"./useEventInvalidation-D85JeECP.js";import{n as Kt,r as qt,t as Jt}from"./SchemaTabBar-DhsmEGyn.js";import{t as Yt}from"./FormBuilder-BKE262Ak.js";var Xt=jt(`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`}]]),Zt=jt(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),Qt=jt(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),$t=jt(`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`}]]),en=jt(`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`}]]),tn=jt(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),nn=jt(`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 rn({parentDeviceId:e}){let{t}=Vt(),n=At(),r=X(),{data:i,isLoading:a,isError:o}=gt(e),{data:s}=A({deviceId:e},{enabled:Number.isFinite(e)});if(a)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let c=(i??[]).filter(e=>e.display?.hidden!==!0);if(c.length===0)return null;let l=d(s?.stableId??``,c,s?.childLayout),u=l.ungrouped,f=e=>n(`/devices/${String(e)}`),p=s?.name??``,m=(e,t)=>q(re,{trpc:r.trpcClient,device:{...t,name:ae(t,p)},variant:`minimal`,onNavigate:f},e),h=u.some(e=>!!e.role),g=u.some(e=>!e.role),_=h&&!g?t(`device.accessories`,{defaultValue:`Accessories`}):!h&&g?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),v=u.length>0?H(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[q(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:_}),q(`div`,{className:`space-y-1`,children:u.map(e=>m(e.id,e))})]}):null,y=l.disabledSection===void 0?null:q(M,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:l.disabledSection.children.length,defaultOpen:!1,children:q(`div`,{className:`opacity-60 space-y-1`,children:l.disabledSection.children.map(e=>m(e.id,e))})},l.disabledSection.title);return l.sections.length===0?y===null?v:H(`div`,{className:`space-y-2`,children:[v,y]}):H(`div`,{className:`space-y-2`,children:[l.sections.map(e=>q(M,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),v,y]})}function an({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:[q(mt,{type:n,size:`lg`}),H(`div`,{children:[q(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),q(`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:[q(Wt,{status:r?`online`:`offline`}),i.length>0&&q(dt,{capabilities:i})]}),q(`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.`})]})}function on({deviceId:e}){let t=G(),n=Fe({deviceId:e},{refetchInterval:1e4,retry:!1}),r=L({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>sn(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:[q(cn,{label:`Discovered`,value:i.total,icon:q(Nt,{className:`h-3.5 w-3.5`})}),q(cn,{label:`Adopted`,value:i.adopted,accent:`success`}),q(cn,{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?q(Ut,{className:`h-3.5 w-3.5 animate-spin`}):q(bt,{className:`h-3.5 w-3.5`}),q(`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:[q(ln,{icon:q(Ct,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),q(ln,{icon:q(Ht,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),q(ln,{icon:q(Pt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?q(ln,{icon:q(Xt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function sn(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 cn({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,q(`span`,{className:`truncate`,children:e})]}),q(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function ln({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,q(`span`,{children:t})]})}function un({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:q(P,{trpc:X().trpcClient,deviceId:e,features:t})})}function dn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:q(oe,{trpc:X().trpcClient,deviceId:e,features:t})})}function Z({deviceId:e,deviceType:t,features:r}){let i=X(),a=Ie(t)?.HeroCard??oe,o=ut(ot(i.trpcClient,e)?.state.deviceStatus),s=o!==void 0&&o.online===!1,c=s?o.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[s?q(`div`,{className:`flex justify-center`,children:q(n,{lastChangedAt:c})}):null,q(a,{trpc:i.trpcClient,deviceId:e,features:r})]})}function fn({deviceId:e}){let t=X(),{data:n,isLoading:r}=_t(e),{data:i,isLoading:a}=gt(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?q(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):q(`div`,{className:`flex h-full w-full flex-col`,children:q(Ge,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var pn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:on,[Y.Cover]:un,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:fn,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:dn,[Y.EventEmitter]:dn,[Y.Notifier]:dn,[Y.Script]:dn,[Y.Automation]:dn,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function mn(e){return q(pn[e.deviceType]??an,{...e})}function hn(e){return ce(X().trpcClient,e)}V();function gn(e){let[t,n]=K(`idle`),[r,i]=K(null),a=B(null),o=B(null),s=B(null),c=B(!0),l=de(),u=ze(),d=I(),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 J(()=>(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 _n=0;function Q(){return++_n}function vn(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function yn(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 bn(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 xn(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 Sn({scope:e,greeting:t,className:n}){let r=X(),[i,a]=K(()=>{let n=[];return t&&n.push({id:Q(),kind:`info`,text:t}),n.push({id:Q(),kind:`info`,text:`scope: ${vn(e)} — type help or context for available commands`}),n}),[o,s]=K(``),[c,l]=K([]),[u,d]=K(-1),f=B(null),p=B(null);J(()=>{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: ${vn(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...yn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...xn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...bn(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: ${vn(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=>q(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&q(`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:[q(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),q(`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 Cn({deviceId:e,intercomAvailable:t=!1}){let n=X(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=hn(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=ve(n.trpcClient,i?e:null),g=Ne(n.trpcClient,i?e:null),_=gn(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=ct(),S=C(),w=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,T=x.length>0?q(W,{children:x.map(e=>q(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return q(Ue,{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:w,...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:T,chromeless:!0,className:`h-full`})}function wn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full`,children:q(he,{...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 Tn({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
- `);return q(Sn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function En({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(Ee,{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 Dn({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(pe,{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 On({deviceId:e}){let t=G(),n=Number.isFinite(e),{data:r}=A({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;Gt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:c,error:l}=We({deviceId:e},{enabled:n}),{data:u}=s({deviceType:i},{enabled:!!i}),d=Ke({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(c)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:[q(ft,{className:`h-8 w-8 opacity-40`}),q(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),q(`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:[H(`div`,{className:`text-[11px] text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-foreground`,children:h}),` of `,m.length,` capabilit`,m.length===1?`y`:`ies`,` bound — rows marked `,q(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),q(me,{columns:[{key:`capability`,header:`Capability`,render:e=>q(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>q(kn,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?q(An,{nodeId:e.providerNodeId}):q(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return q(jn,{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 kn({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:[q(St,{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:[q(Zt,{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:[q($t,{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:[q(ht,{className:`h-3 w-3`}),`unbound`]})}function An({nodeId:e}){return q(`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 jn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?q(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):q(`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:[q(i?Tt:pt,{className:`h-3 w-3`}),e]},e)})})}V();function Mn({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l,flattenTabs:u=!1}){let d=e.tabs??[],f=U(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),p=new Set(d.map(e=>e.id)),m=[...d,...[...f.keys()].filter(e=>!p.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],h=m[0]?.id??`general`,[g,_]=K(h),v=l!==void 0,y=new Set(m.map(e=>e.id)),b=v?c&&y.has(c)?c:h:y.has(g)?g:h,x=e=>{v?l(e):_(e)},S=f.get(b)??[],C={sections:S.length<=1?S.length===1?[{...S[0],title:``}]:S:S.every(e=>!e.title)?[{...S[0],title:``,fields:S.flatMap(e=>e.fields)}]:S},w=q(Kt,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(u||m.length<=1)return H(`div`,{className:`flex flex-col gap-3`,children:[q(Yt,{schema:e,values:t,onChange:r,onAction:i,disabled:s}),w]});let T=new Map,E=new Map;for(let[e,t]of f){T.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&E.set(e,a)}return H(`div`,{className:`flex flex-col gap-3`,children:[q(Jt,{tabs:m.map(e=>({id:e.id,label:e.label})),activeId:b,onChange:x,countByTab:T,pendingByTab:E}),q(Yt,{schema:C,values:t,onChange:r,onAction:i,disabled:s}),w]})}var Nn=`device-export`,Pn=`export`,Fn=`Export`;function In(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(In):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(In)):e.writerCapName===Nn}function Ln(e){return e.fields.some(In)}V();function Rn(e,t){return t&&t===`admin`?e:!0}function zn(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?Ln(e)&&Ln(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function Bn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function Vn(e){return e.key}function Hn(e){if(!Bn(e))return e.value}function Un(e){return Bn(e)?null:e}function Wn(e,t){for(let n of e)if(t(n),n.type===`group`)Wn(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)Wn(e.fields,t)}function Gn(e){if(!e)return{};let t={};for(let n of e.sections)Wn(n.fields,e=>{let n=Vn(e);n!==null&&(t[n]=Hn(e))});return t}function Kn(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(Wn(r.fields,e=>{if(n!==null||Vn(e)!==t)return;let r=Un(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function qn(e){return{...e,fields:e.fields.map(Jn)}}function Jn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function Yn(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=Un(e);return n?Rn(t,n.minRole)?e:Jn(e):e})}))}}function Xn({deviceId:e,sectionFilter:n,activeSubTab:i,onSubTabChange:o,flattenSubTabs:s}){let c=G(),{user:l}=zt(),u=l?.isAdmin===!0,d=B(!1),{data:f,isLoading:p}=a({deviceId:e},{refetchInterval:()=>d.current?!1:2500,enabled:Number.isFinite(e)}),{data:m}=A({deviceId:e},{enabled:Number.isFinite(e)}),h=f?.settings??null,g=f?.live??null,_=U(()=>{if(!h&&!g)return null;let e=h?.sections??[],t=(g?.sections??[]).map(qn),r=[...e,...t],i=n?r.filter(n):r.filter(e=>e.location!==`top-tab`&&!Ln(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...h?.tabs??[],...(g?.tabs??[]).filter(e=>!(h?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[h,g,n]),v=U(()=>zn(_),[_]),y=U(()=>Yn(v,u),[v,u]),x=U(()=>Gn(y),[y]),S=Se(),C=t(),w=r(),T=b(),E=ie({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),D={isPending:E.isPending,mutate:t=>{E.mutate({deviceId:e,changes:[...t]})}},ee=qt({schema:y,serverValues:x,onImmediateSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Kn(y,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&D.mutate(t)},[y,D]),onDeferredSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Kn(y,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&D.mutate(t)},[y,D])}),{values:O,pendingKeys:k,handleChange:te,handleSave:j,handleDiscard:ne}=ee;if(d.current=ee.editingPaused,p)return H(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[q(Ut,{className:`h-4 w-4 animate-spin mr-2`}),q(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!y||y.sections.length===0)return q(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function re(t,n,r){if(t===`regenerate-rtsp-token`){let t=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!t)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(t.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let i=Qe(e,r);await S.mutateAsync({brokerId:i}),c.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!m)return{status:`error`,error:`Device metadata not loaded yet`};try{return await w.mutateAsync({addonId:m.addonId,type:m.type,key:n,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(t===`refresh-probe`){if(!n.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${n}" (expected "probedInfo:<streamId>")`);let t=n.slice(11);if(!t)throw Error(`refresh-probe: key "${n}" has no streamId after prefix`);let r=Qe(e,t),i=await C.mutateAsync({brokerId:r});return c.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await T.mutateAsync({deviceId:e,action:n,input:r});return c.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return q(Mn,{schema:y,values:O,pendingKeys:k,onChange:te,onAction:re,onSave:j,onDiscard:ne,disabled:D.isPending,activeSubTab:i,onSubTabChange:o,flattenTabs:s})}function Zn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return q(`div`,{className:`flex flex-col gap-3`,children:q(Xn,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}V();function Qn(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function $n(e,t,n){let r=e?.stepOverridesByAgent?.[t]?.[n];if(r)return r.enabled===!1?`off`:(r.enabled,`on`);let i=e?.stepToggles?.[n];return i===!1?`off`:i===!0?`on`:`inherit`}function er({agents:e,currentAgent:t,onPick:n}){let[r,i]=K(!1);return H(`div`,{className:`relative`,children:[q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>i(e=>!e),children:`Mirror from ▾`}),r&&q(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:e.filter(e=>e!==t).map(e=>q(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{i(!1),n(e)},children:e},e))})]})}function tr({deviceId:t,refreshToken:n}){let r=G(),[a,o]=K(null),[s,c]=K(null),[l,u]=K(null),[d,f]=K(null),p=e({deviceId:t}),m=R(),h=ye({deviceId:t}),g=se(),v=U(()=>h.data?.agentNodeId||g.data?.find(e=>e.online)?.nodeId||`hub`,[h.data?.agentNodeId,g.data]),y=s??v,b=i({nodeId:y??``},{enabled:!!y}),x=_e({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),u(null)}}),S=U(()=>b.data?Re(b.data):[],[b.data]),C=U(()=>{let e=p.data??null,t={};for(let n of m.data??[])for(let r of Object.keys(n.settings.addonDefaults)){let i=t[r]??[];i.push({agentNodeId:n.nodeId,state:$n(e,n.nodeId,r)}),t[r]=i}return t},[p.data,m.data]),w=a?Qn(b.data??null,a):null,T=y?m.data?.find(e=>e.nodeId===y)??null:null,E=a&&T?T.settings.addonDefaults[a]??null:null,D=a&&y?p.data?.stepOverridesByAgent?.[y]?.[a]??null:null,ee=b.data?.selectedEngine.format??`coreml`,O=e=>{c(e),u(null),f(null)};return m.isLoading||b.isLoading?q(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):b.data?q(`div`,{className:`@container h-full`,style:{containerType:`inline-size`},children:H(`div`,{className:`flex flex-col @[720px]:flex-row h-full`,children:[q(`aside`,{className:`w-full @[720px]:w-[300px] @[720px]:flex-shrink-0 border-b @[720px]:border-b-0 @[720px]:border-r border-border overflow-y-auto max-h-[40vh] @[720px]:max-h-none`,children:q(Te,{tree:S,selectedAddonId:a,onSelect:e=>{o(e),u(null),f(null)},agentDots:C})}),q(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!a||!w?q(`div`,{className:`text-sm text-foreground-subtle`,children:`Select a step on the left to configure it for this camera.`}):H(`div`,{className:`space-y-4`,children:[H(`div`,{children:[q(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle`,children:`Selected step`}),q(`div`,{className:`text-base font-semibold`,children:w.name})]}),H(`div`,{className:`flex items-end gap-3 flex-wrap`,children:[H(`div`,{children:[q(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle mb-1`,children:`Agent`}),q(`div`,{className:`flex rounded border border-border overflow-hidden`,children:(m.data??[]).map(e=>q(`button`,{type:`button`,onClick:()=>O(e.nodeId),className:`px-3 py-1 text-xs ${y===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),q(er,{agents:(m.data??[]).map(e=>e.nodeId),currentAgent:y,onPick:e=>{if(!y||!a||!b.data||!m.data)return;let t=m.data.find(t=>t.nodeId===e),n=m.data.find(e=>e.nodeId===y);if(!t||!n)return;let[r]=_({source:{nodeId:t.nodeId,engine:{format:ee},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:ee},defaults:n.settings.addonDefaults},catalog:b.data,addonIds:[a]});if(!r){f(`no mirror result`);return}if(r.outcome===`skip`){f(`skipped: ${r.reason??`no candidate`}`);return}u(r.patch),f(`${r.outcome} from ${e}`)}}),d&&q(`div`,{className:`text-[10px] text-foreground-subtle`,children:d})]}),E&&q(F,{mode:`device`,addon:w,agentDefault:E,agentNodeId:y??``,currentPatch:l??D,engineFormat:ee,onChangePatch:u}),H(`div`,{className:`flex items-center justify-between gap-2 pt-4 border-t border-border`,children:[q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle`,disabled:!D||x.isPending,onClick:()=>{!y||!a||x.mutate({deviceId:t,agentNodeId:y,addonId:a,patch:null})},children:`Clear override`}),H(`div`,{className:`flex items-center gap-2`,children:[q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>u(null),children:`Reset draft`}),q(`button`,{type:`button`,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,disabled:!y||!a||x.isPending,onClick:()=>{!y||!a||x.mutate({deviceId:t,agentNodeId:y,addonId:a,patch:l})},children:x.isPending?`Saving…`:`Save`})]})]})]})})]})}):q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`})}function $({label:e,value:t}){return H(`div`,{className:`${st} flex items-start gap-2 sm:gap-3`,children:[q(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),q(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}V();function nr({deviceId:e,initialName:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t),[s,c]=K(!1),l=B(null);J(()=>{r||o(t)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let u=p({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),d=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),o(t);return}c(!0);try{await u.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{c(!1)}},f=()=>{o(t),i(!1)};return r?q($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?d():e.key===`Escape`&&f()},disabled:s,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`}),q(`button`,{type:`button`,onClick:()=>void d(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(Tt,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:f,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(It,{className:`h-3 w-3`})})]})}):q($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[q(`span`,{className:`truncate`,children:t}),q(`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 name`,children:q(vt,{className:`h-3.5 w-3.5`})})]})})}V();function rr({deviceId:e,initialLocation:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t??``),[s,c]=K(!1),l=B(null),{data:d}=w(void 0,{enabled:r}),f=d??[];J(()=>{r||o(t??``)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let p=u({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),m=U(()=>{let e=a.trim().toLowerCase();return e.length===0?f:f.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[f,a]),h=a.trim().length>0&&!f.some(e=>e.toLowerCase()===a.trim().toLowerCase()),g=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await p.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},_=()=>{o(t??``),i(!1)};return r?q($,{label:`Location`,value:H(`div`,{className:`relative`,children:[H(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?g():e.key===`Escape`&&_()},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`}),q(`button`,{type:`button`,onClick:()=>void g(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(Tt,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:_,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(It,{className:`h-3 w-3`})})]}),(m.length>0||h)&&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:[m.map(e=>H(`button`,{type:`button`,onClick:()=>{o(e),g(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[q(en,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),q(`span`,{className:`truncate`,children:e})]},e)),h&&H(`button`,{type:`button`,onClick:()=>void g(),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:[q(`span`,{className:`text-foreground-subtle`,children:`Create`}),H(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):q($,{label:`Location`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[t?q(`span`,{className:`truncate`,children:t}):q(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),q(`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:q(vt,{className:`h-3.5 w-3.5`})})]})})}V();function ir({deviceId:e}){let t=G(),{data:n}=_t(e),{data:r}=gt(e),[i,a]=K(null),o=v({onSuccess:()=>{a(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{a(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.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=fe(s,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return H(W,{children:[q($,{label:`Primary child`,value:q(O,{childrenList:s,selectedId:c===null?s[0].id:c.id,onSetPrimary:t=>o.mutate({deviceId:e,primaryChildEntityId:t}),disabled:o.isPending})}),i!==null&&q(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:i})]})}V();var ar=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function or(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function sr(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function cr(){let e=y(),t=x(),{data:n}=A({deviceId:e??0},{enabled:e!==null}),{data:r}=We({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[a,o]=K(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),c=String(i.name??``),l=String(i.type??``),u=String(i.addonId??``),d=i.features??[],f=new Set([`device-status`,`feature-probe`,`device-ops`]),p=(r?.entries??[]).filter(e=>e.kind===`native`&&!f.has(e.capName)).map(e=>e.capName),m=d.length>0?d:p,h=i.location??null,g=i.metadata??null,_=g!==null&&Object.keys(g).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:[q(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),_&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[q(lr,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),q(lr,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!_||a===`identity`)&&H(`div`,{className:`divide-y divide-border`,children:[q($,{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,`)`]})]})}),q(nr,{deviceId:e,initialName:c}),q(rr,{deviceId:e,initialLocation:h}),q(ir,{deviceId:e}),q($,{label:`Type`,value:l}),q($,{label:`Provider`,value:q(mt,{type:u,size:`sm`,showLabel:!0})}),q($,{label:`Capabilities`,value:m.length>0?q(dt,{capabilities:m,showLabels:!0}):q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),_&&a===`hardware`&&q(ur,{metadata:g})]})}function lr({active:e,onClick:t,label:n}){return q(`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 ur({metadata:e}){let t=ar.filter(t=>t in e),n=Object.keys(e).filter(e=>!ar.includes(e)).toSorted(),r=[...t,...n];return H(`div`,{children:[q(`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.`}),q(`div`,{className:`divide-y divide-border`,children:r.map(t=>q($,{label:or(t),value:q(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:sr(e[t])})},t))})]})}V();function dr({deviceId:e}){let[t,n]=K(null),r=ue({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:[q(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),q(`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:[q(bt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&q(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}V();var fr={icon:``,label:``,unit:``,precision:``,hidden:!1};function pr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function mr(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function hr(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 gr({deviceId:e}){let t=X(),n=G(),{data:r}=A({deviceId:e},{enabled:e>0}),i=typeof r?.role==`string`?r.role:null,a=i===null?void 0:Oe[i],o=a?.kind===`numeric`,s=De(t.trpcClient,e,i??``),c=a?.kind===`numeric`?a.canonicalUnit:void 0,l=mr(s)??c,u=l===void 0?void 0:at(l),d=U(()=>u===void 0?[]:nt(u),[u]),[f,p]=K(null),m=f??pr(r?.display),h=E({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:g}=He({},{staleTime:6e4}),_=k({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(r===void 0||i===null)return null;let v=e=>{p({...m,...e})},y=()=>{h.mutate({deviceId:e,display:hr(m)})},b=()=>{p(fr),h.mutate({deviceId:e,display:null})},x=()=>{let e={...m.icon===``?{}:{icon:m.icon},...m.unit===``?{}:{unit:m.unit},...m.precision.trim()!==``&&Number.isFinite(Number.parseInt(m.precision,10))?{precision:Number.parseInt(m.precision,10)}:{}},t={...g?.defaults??{},[i]:e};_.mutate({defaults:t})},S=D(i).label,C=Object.keys(N);return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`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:[q(`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:m.icon,onChange:e=>v({icon:e.target.value}),children:[H(`option`,{value:``,children:[`Default (`,S,`)`]}),C.map(e=>q(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Label`}),q(`input`,{type:`text`,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:S,value:m.label,onChange:e=>v({label:e.target.value})})]}),o&&H(`div`,{className:`grid grid-cols-2 gap-3`,children:[H(`label`,{className:`block`,children:[q(`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:m.unit,onChange:e=>v({unit:e.target.value}),disabled:d.length===0,children:[H(`option`,{value:``,children:[`Source`,l?` (${l})`:``]}),d.map(e=>q(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Precision`}),q(`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:m.precision,onChange:e=>v({precision:e.target.value})})]})]}),H(`label`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`checkbox`,checked:m.hidden,onChange:e=>v({hidden:e.target.checked})}),q(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),H(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[q(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-sm font-medium text-primary-foreground disabled:opacity-50`,onClick:y,disabled:h.isPending,children:`Save`}),q(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:b,disabled:h.isPending,children:`Reset`}),H(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:x,disabled:_.isPending,title:`Apply this unit / precision / icon as the default for every ${S} sensor`,children:[`Set as default for all `,S,` sensors`]})]})]})]})}function _r(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function vr({device:e}){let t=At(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===Y.Camera,a=r===Y.Hub,o=typeof e.role==`string`&&e.role.length>0,s=e.features??[],c=s.includes(et.Resyncable),{data:l}=T({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),f=s.includes(et.DoorbellButton),p=Pe(f?{deviceId:n??void 0,historyLimit:10}:void 0),m=p.latest?Date.now()-p.latest.timestamp<3e4:!1;return H(`div`,{className:`space-y-5`,children:[a&&n!==null&&q(Ae,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&q(dr,{deviceId:n}),i&&n!==null&&q(j,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),f&&q(Le,{history:p.history,latestIsFresh:m}),i&&n!==null&&q(j,{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:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),q(`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:[q(Ct,{className:`h-3 w-3 text-foreground-subtle`}),q(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),H(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[q(yr,{label:`Nominal`,value:_r(t.nominalBitrateKbps??0)}),q(yr,{label:`Observed`,value:_r(t.observedBitrateKbps??0)}),q(yr,{label:`Peak`,value:_r(t.peakBitrateKbps??0)}),q(yr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),q(cr,{}),o&&n!==null&&q(gr,{deviceId:n})]})}function yr({label:e,value:t,warning:n}){return H(`div`,{children:[q(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),q(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}V();function br(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function xr(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=br(r.value,t));return n}function Sr(e,t){return e?.kind===`enum-map`?Object.entries(e.mapping).map(([e,t])=>({key:e,value:String(t)})):t?.kind===`enum`&&t.enumValues?t.enumValues.map(e=>({key:e,value:``})):[{key:``,value:``}]}function Cr(e){return e?.kind===`linear`?{scale:String(e.scale),offset:String(e.offset),clampMin:e.clamp?String(e.clamp[0]):``,clampMax:e.clamp?String(e.clamp[1]):``,useClamp:e.clamp!=null}:{scale:`1`,offset:`0`,clampMin:``,clampMax:``,useClamp:!1}}function wr(e){return e==null?`identity`:e.kind}function Tr({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=K(()=>wr(e)),[o,s]=K(()=>Sr(e,n)),[c,l]=K(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=K(()=>Cr(e));J(()=>{if(i===`enum-map`&&n?.kind===`enum`&&n.enumValues){let e=n.enumValues;s(t=>e.map(e=>({key:e,value:t.find(t=>t.key===e)?.value??``})))}},[n,i]),J(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=xr(o,r),n=c===``?void 0:br(c,r);t({kind:`enum-map`,mapping:e,...n===void 0?{}:{fallback:n}});return}if(i===`linear`){let e=Number(u.scale),n=Number(u.offset);if(Number.isNaN(e)||Number.isNaN(n))return;let r=Number(u.clampMin),i=Number(u.clampMax),a=u.useClamp&&!Number.isNaN(r)&&!Number.isNaN(i)?[r,i]:void 0;t({kind:`linear`,scale:e,offset:n,...a?{clamp:a}:{}})}},[i,o,c,u,r,t]);let f=e=>{a(e),e===`enum-map`&&s(Sr(void 0,n)),e===`linear`&&d(Cr(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{children:[q(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),q(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[q(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[q(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>H(`div`,{className:`flex items-center gap-1.5`,children:[q(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),q(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?H(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[q(`option`,{value:``,children:`—`}),q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]}):q(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&q(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&q(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),H(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[q(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),q(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[q(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),q(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),q(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[q(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),q(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),q(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),q(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}var Er=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;function Dr({mode:e,idPrefix:t,labelPrefix:n,pickerDevices:r,value:i,onChange:a,search:o,onSearchChange:s}){let{data:c}=ne({deviceId:i.sourceId??0},{enabled:i.sourceId!=null}),l=c?.caps??[],u=l.find(e=>e.cap===i.cap)?.fields??[],d=e=>{a(e,(l.find(t=>t.cap===e.cap)?.fields??[]).find(t=>t.path===e.fieldPath))},f=e=>{d({sourceId:e===``?null:Number(e),cap:``,fieldPath:``})},p=e=>{d({sourceId:i.sourceId,cap:e,fieldPath:``})},m=e=>{d({sourceId:i.sourceId,cap:i.cap,fieldPath:e})};return H(W,{children:[e===`global`&&s&&H(`div`,{children:[q(`label`,{htmlFor:`${t}-search`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Search devices`}),q(`input`,{id:`${t}-search`,type:`text`,value:o??``,placeholder:`Filter by name, stable id or #id`,onChange:e=>s(e.target.value),className:Er})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` device`]}),H(`select`,{id:`${t}-device`,value:i.sourceId??``,onChange:e=>f(e.target.value),className:Er,children:[q(`option`,{value:``,children:`— select a device —`}),r.map(e=>H(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` cap`]}),H(`select`,{id:`${t}-cap`,value:i.cap,disabled:i.sourceId==null,onChange:e=>p(e.target.value),className:Er,children:[q(`option`,{value:``,children:`— select a cap —`}),l.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` field`]}),H(`select`,{id:`${t}-field`,value:i.fieldPath,disabled:i.cap===``,onChange:e=>m(e.target.value),className:Er,children:[q(`option`,{value:``,children:`— select a field —`}),u.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]})}function Or(e,t){switch(e){case`null`:return{value:null};case`string`:return t===``?null:{value:t};case`number`:{if(t.trim()===``)return null;let e=Number(t);return Number.isFinite(e)?{value:e}:null}case`boolean`:return t===`true`?{value:!0}:t===`false`?{value:!1}:null}}function kr(e){return e===null?`null`:typeof e==`number`?`number`:typeof e==`boolean`?`boolean`:`string`}function Ar(e){return e===null?``:String(e)}V();var jr=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`,Mr=`min, max, abs, round, floor, ceil, sqrt, pow, clamp, avg, sum, coalesce, age, convert`,Nr=0;function Pr(){return Nr+=1,`b${Nr}`}function Fr(e){return{key:Pr(),name:e,mode:`sibling`,sourceId:null,cap:``,fieldPath:``,search:``,literalType:`number`,literalText:``,sampleText:``}}function Ir(e,t,n){if(e===null)return[Fr(`a`)];let r=[];for(let[i,a]of Object.entries(e.bindings)){if(a.kind===`literal`){r.push({...Fr(i),mode:`literal`,literalType:kr(a.value),literalText:Ar(a.value)});continue}if(a.kind===`global`){r.push({...Fr(i),mode:`global`,sourceId:t.find(e=>e.stableId===a.sourceStableId)?.id??null,cap:a.cap,fieldPath:a.fieldPath});continue}r.push({...Fr(i),mode:`sibling`,sourceId:t.find(e=>e.stableId===`${n}-${a.sourceKey}`)?.id??null,cap:a.cap,fieldPath:a.fieldPath})}return r.length>0?r:[Fr(`a`)]}function Lr(e,t,n){if(e.mode===`literal`){let t=Or(e.literalType,e.literalText);return t===null?null:{kind:`literal`,value:t.value}}let r=t.find(t=>t.id===e.sourceId);if(!r||e.cap===``||e.fieldPath===``)return null;if(e.mode===`global`)return{kind:`global`,sourceStableId:r.stableId,cap:e.cap,fieldPath:e.fieldPath};let i=`${n}-`,a=r.stableId.startsWith(i)?r.stableId.slice(i.length):``;return a===``?null:{kind:`field`,sourceKey:a,cap:e.cap,fieldPath:e.fieldPath}}function Rr(e){if(e.mode===`literal`)return Or(e.literalType,e.literalText)?.value??null;let t=e.sampleText.trim();if(t===``)return null;let n=Number(t);return Number.isFinite(n)?n:e.sampleText}function zr({devices:e,siblings:t,targetDeviceId:n,containerStableId:r,initial:i,onChange:a}){let[o,s]=K(i?.expr??``),[c,l]=K(()=>Ir(i,e,r)),u=U(()=>{let t={},n=c.length>0,i=new Set;for(let a of c){let o=a.name.trim();if(o===``||i.has(o)){n=!1;continue}i.add(o);let s=Lr(a,e,r);if(s===null){n=!1;continue}t[o]=s}return{source:{kind:`expression`,expr:o,bindings:t},complete:n}},[c,o,e,r]),d=U(()=>Xe({expr:u.source.expr,bindings:u.source.bindings}),[u.source]),f=U(()=>{if(o.trim()===``)return null;let e=Ye(o);return e.ok?null:e.error},[o]),p=U(()=>{if(u.source.expr.trim()===``)return null;let e={};for(let t of c){let n=t.name.trim();n!==``&&(e[n]=Rr(t))}return tt(u.source.expr,e,Date.now())},[u.source.expr,c]),m=u.complete&&d===null&&o.trim()!==``;J(()=>{a(m?u.source:null)},[m?JSON.stringify(u.source):`null`]);let h=e=>{let t=e.name.trim();return t===``?`required`:it.test(t)?Je.has(t)?`reserved`:$e.has(t)?`shadows builtin`:c.filter(e=>e.name.trim()===t).length>1?`duplicate`:null:`invalid name`},g=(e,t)=>{l(n=>n.map(n=>n.key===e?{...n,...t}:n))},_=()=>{c.length>=32||l(e=>[...e,Fr(Br(e))])},v=e=>{l(t=>t.length<=1?t:t.filter(t=>t.key!==e))};return H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{className:`flex flex-col gap-2`,children:[q(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Bindings`}),c.map((r,i)=>q(Vr,{row:r,ordinal:i+1,devices:e,siblings:t,targetDeviceId:n,nameError:h(r),onPatch:e=>g(r.key,e),onRemove:()=>v(r.key),canRemove:c.length>1},r.key)),q(`button`,{type:`button`,onClick:_,disabled:c.length>=32,className:`self-start px-2 py-1 rounded-md text-[11px] font-medium border border-border text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,children:`+ Add binding`})]}),H(`div`,{children:[q(`label`,{htmlFor:`link-expr-input`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Expression`}),q(`textarea`,{id:`link-expr-input`,value:o,rows:2,spellCheck:!1,placeholder:`e.g. clamp(avg(a, b) + 5, 0, 100)`,onChange:e=>s(e.target.value),className:`${jr} font-mono resize-y`}),H(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:[`Functions: `,Mr]}),f&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:f}),f===null&&d&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:d})]}),H(`div`,{className:`rounded-md border border-border bg-surface/50 px-2 py-1.5`,children:[q(`span`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle/60`,children:`Preview`}),` `,p===null?q(`span`,{className:`text-[11px] text-foreground-subtle/60`,children:`enter an expression`}):p.ok?q(`span`,{className:`font-mono text-[11px] text-foreground`,children:JSON.stringify(p.value)}):q(`span`,{className:`font-mono text-[11px] text-danger`,children:p.error})]})]})}function Br(e){let t=new Set(e.map(e=>e.name.trim()));for(let e=0;e<26;e++){let n=String.fromCharCode(97+e);if(!t.has(n))return n}return`b${e.length+1}`}function Vr({row:e,ordinal:t,devices:n,siblings:r,targetDeviceId:i,nameError:a,onPatch:o,onRemove:s,canRemove:c}){let l=e.search.trim().toLowerCase(),u=n.filter(e=>e.id===i?!1:l===``?!0:e.name.toLowerCase().includes(l)||e.stableId.toLowerCase().includes(l)||String(e.id).includes(l)),d=e.mode===`global`?u:r;return H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border/60 p-2`,children:[H(`div`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`text`,"aria-label":`binding ${t} name`,value:e.name,placeholder:`name`,onChange:e=>o({name:e.target.value}),className:`${jr} max-w-[8rem] font-mono`}),H(`select`,{"aria-label":`binding ${t} mode`,value:e.mode,onChange:e=>{let t=e.target.value;(t===`sibling`||t===`global`||t===`literal`)&&o({mode:t,sourceId:null,cap:``,fieldPath:``,search:``})},className:`${jr} max-w-[9rem]`,children:[q(`option`,{value:`sibling`,children:`Sibling`}),q(`option`,{value:`global`,children:`Any device`}),q(`option`,{value:`literal`,children:`Literal`})]}),c&&q(`button`,{type:`button`,"aria-label":`remove binding ${t}`,onClick:s,className:`px-2 py-1 rounded-md text-[11px] text-danger hover:bg-surface-hover`,children:`✕`})]}),a&&H(`span`,{className:`text-[10px] text-danger`,children:[`name: `,a]}),e.mode===`literal`?H(`div`,{className:`flex items-center gap-2`,children:[H(`select`,{"aria-label":`binding ${t} literal type`,value:e.literalType,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&o({literalType:t,literalText:t===`boolean`?`true`:``})},className:`${jr} max-w-[7rem]`,children:[q(`option`,{value:`string`,children:`string`}),q(`option`,{value:`number`,children:`number`}),q(`option`,{value:`boolean`,children:`boolean`}),q(`option`,{value:`null`,children:`null`})]}),e.literalType!==`null`&&q(`input`,{type:`text`,"aria-label":`binding ${t} literal value`,value:e.literalText,placeholder:e.literalType===`number`?`e.g. 42`:`value`,onChange:e=>o({literalText:e.target.value}),className:jr})]}):H(W,{children:[q(Dr,{mode:e.mode,idPrefix:`binding-${t}`,labelPrefix:`Binding`,pickerDevices:d,value:{sourceId:e.sourceId,cap:e.cap,fieldPath:e.fieldPath},onChange:e=>o({sourceId:e.sourceId,cap:e.cap,fieldPath:e.fieldPath}),search:e.search,onSearchChange:e=>o({search:e})}),q(`input`,{type:`text`,"aria-label":`binding ${t} sample`,value:e.sampleText,placeholder:`sample value (preview only)`,onChange:e=>o({sampleText:e.target.value}),className:`${jr} text-[10px]`})]})]})}V();function Hr(e,t,n){return(n===void 0?[e,t]:[e,n,t]).map(e=>e.replace(/[^a-z0-9]/gi,`-`)).join(`-`)}function Ur(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function Wr(e,t){return t.find(t=>t.stableId===e)?.id??null}function Gr(e){return e==null?`sibling`:e.source.kind===`literal`?`literal`:e.source.kind===`global`?`global`:e.source.kind===`expression`?`expression`:`sibling`}function Kr(e){return e==null||e.source.kind!==`literal`?`string`:kr(e.source.value)}function qr(e){return e==null||e.source.kind!==`literal`?``:Ar(e.source.value)}function Jr({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=l({}),s=o??[],c=t==null?n:s.find(e=>e.id===t)?.stableId??n,u=s.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:d}=ne({deviceId:e,includeSynthesizable:!0}),f=d?.caps??[],p=r!=null&&(r.source.kind===void 0||r.source.kind===`field`)?r.source:null,m=r!=null&&r.source.kind===`global`?r.source:null,h=r!=null&&r.source.kind===`expression`?r.source:null,g=p==null?m==null?null:Wr(m.sourceStableId,s):Ur(p.sourceKey,c,s),[_,v]=K(Gr(r)),[y,b]=K(r?.target.cap??``),[x,S]=K(r?.target.fieldPath??``),[C,w]=K(r?.target.itemKey??``),[T,E]=K(g),[D,ee]=K((p??m)?.cap??``),[O,k]=K((p??m)?.fieldPath??``),[te,A]=K(void 0),[j,re]=K(``),[ie,M]=K(Kr(r)),[N,P]=K(qr(r)),[ae,oe]=K(h),[se,ce]=K(r?.transform);J(()=>{if((p??m)==null||T!==null||s.length===0)return;let e=p==null?m==null?null:Wr(m.sourceStableId,s):Ur(p.sourceKey,c,s);e!==null&&E(e)},[p,m,T,s,c]);let le=f.find(e=>e.cap===y)?.fields??[],F=le.find(e=>e.path===x),ue=F?.item===!0,de=j.trim().toLowerCase(),fe=s.filter(t=>t.id===e?!1:de===``?!0:t.name.toLowerCase().includes(de)||t.stableId.toLowerCase().includes(de)||String(t.id).includes(de)),pe=_===`global`?fe:u,me=e=>{b(e),S(``),w(``)},I=e=>{e!==`sibling`&&e!==`global`&&e!==`literal`&&e!==`expression`||(v(e),E(null),ee(``),k(``),A(void 0),re(``))},he=Or(ie,N),ge=_===`literal`?he!==null:_===`expression`?ae!==null:T!=null&&D!==``&&O!==``,_e=y!==``&&x!==``&&(!ue||C.trim()!==``)&&ge,ve=()=>{if(_===`literal`)return he===null?null:{kind:`literal`,value:he.value};if(_===`expression`)return ae;let e=s.find(e=>e.id===T);if(!e||D===``||O===``)return null;if(_===`global`)return{kind:`global`,sourceStableId:e.stableId,cap:D,fieldPath:O};let t=`${c}-`;return{sourceKey:e.stableId.startsWith(t)?e.stableId.slice(t.length):``,cap:D,fieldPath:O}},ye=()=>{if(!_e)return;let e=ve();if(e===null)return;let t=ue?C.trim():void 0;i({id:r?.id??Hr(y,x,t),source:e,target:{cap:y,fieldPath:x,...t===void 0?{}:{itemKey:t}},...se==null?{}:{transform:se}})},L=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return H(`div`,{className:`flex flex-col gap-4 p-3`,children:[H(`fieldset`,{className:`flex flex-col gap-3`,children:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),H(`div`,{children:[q(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),H(`select`,{id:`link-target-cap`,value:y,onChange:e=>me(e.target.value),className:L,children:[q(`option`,{value:``,children:`— select a cap —`}),f.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[q(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),H(`select`,{id:`link-target-field`,value:x,disabled:y===``,onChange:e=>S(e.target.value),className:L,children:[q(`option`,{value:``,children:`— select a field —`}),le.map(e=>q(`option`,{value:e.path,children:e.item===!0?`${e.path} (per item, ${e.kind})`:`${e.path} (${e.kind})`},e.path))]})]}),ue&&H(`div`,{children:[q(`label`,{htmlFor:`link-target-item-key`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Item key`}),q(`input`,{id:`link-target-item-key`,type:`text`,value:C,placeholder:`e.g. main-brush`,onChange:e=>w(e.target.value),className:L}),q(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:`Links sharing the same item key build one item (e.g. one consumable).`})]})]}),H(`fieldset`,{className:`flex flex-col gap-3`,children:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source`}),H(`div`,{children:[q(`label`,{htmlFor:`link-source-mode`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source mode`}),H(`select`,{id:`link-source-mode`,value:_,onChange:e=>I(e.target.value),className:L,children:[q(`option`,{value:`sibling`,children:`Sibling device (same container)`}),q(`option`,{value:`global`,children:`Any device`}),q(`option`,{value:`literal`,children:`Literal constant`}),q(`option`,{value:`expression`,children:`Expression (computed)`})]})]}),_===`literal`&&H(W,{children:[H(`div`,{children:[q(`label`,{htmlFor:`link-literal-type`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal type`}),H(`select`,{id:`link-literal-type`,value:ie,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&(M(t),t===`boolean`&&P(`true`),t===`null`&&P(``))},className:L,children:[q(`option`,{value:`string`,children:`string`}),q(`option`,{value:`number`,children:`number`}),q(`option`,{value:`boolean`,children:`boolean`}),q(`option`,{value:`null`,children:`null`})]})]}),ie!==`null`&&(ie===`boolean`?H(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),H(`select`,{id:`link-literal-value`,value:N,onChange:e=>P(e.target.value),className:L,children:[q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]})]}):H(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),q(`input`,{id:`link-literal-value`,type:`text`,value:N,placeholder:ie===`number`?`e.g. 42`:`e.g. main-brush`,onChange:e=>P(e.target.value),className:L})]}))]}),_===`expression`&&q(zr,{devices:s,siblings:u,targetDeviceId:e,containerStableId:c,initial:h,onChange:oe}),(_===`sibling`||_===`global`)&&q(Dr,{mode:_,idPrefix:`link-source`,labelPrefix:`Source`,pickerDevices:pe,value:{sourceId:T,cap:D,fieldPath:O},onChange:(e,t)=>{E(e.sourceId),ee(e.cap),k(e.fieldPath),A(t)},search:j,onSearchChange:re})]}),q(Tr,{value:se,onChange:ce,sourceField:_===`literal`||_===`expression`?void 0:te,targetKind:F?.kind}),H(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[q(`button`,{type:`button`,onClick:a,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),q(`button`,{type:`button`,disabled:!_e,onClick:ye,className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Save`})]})]})}V();function Yr({deviceId:e}){let t=X(),n=G(),r=Number.isFinite(e),{data:i,isLoading:a}=A({deviceId:e},{enabled:r,refetchInterval:1e4}),{data:o}=ne({deviceId:e,includeSynthesizable:!0},{enabled:r}),s=new Map;for(let e of o?.caps??[])e.itemArray&&s.set(e.cap,e.itemArray);let c=S({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),l=i?.deviceLinks??[],u=typeof i?.parentDeviceId==`number`?i.parentDeviceId:null,d=typeof i?.stableId==`string`?i.stableId:``,[f,p]=K(null),m=t=>{c.mutate({deviceId:e,deviceLinks:l.filter(e=>e.id!==t)})};return a?q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):f===null?H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`flex items-center justify-between`,children:[q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),H(`button`,{type:`button`,onClick:()=>p(`new`),title:`Add a cross-device link`,className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[q(yt,{className:`h-3 w-3`}),`Add link`]})]}),l.length===0?H(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[q(Qt,{className:`h-8 w-8 opacity-30`}),q(`p`,{className:`text-xs`,children:`No links yet.`}),q(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):q(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:l.map(n=>q(Zr,{deviceId:e,link:n,itemArray:s.get(n.target.cap),trpcClient:t.trpcClient,onDelete:()=>m(n.id),onEdit:()=>p(n),isPending:c.isPending},n.id))})]}):H(`div`,{className:`flex flex-col gap-3 p-1`,children:[q(`div`,{className:`flex items-center justify-between`,children:q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:f===`new`?`Add link`:`Edit link`})}),q(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:q(Jr,{deviceId:e,parentDeviceId:u,deviceStableId:d,initial:f===`new`?null:f,onSave:t=>{let n=l.some(e=>e.id===t.id)?l.map(e=>e.id===t.id?t:e):[...l,t];c.mutate({deviceId:e,deviceLinks:n}),p(null)},onCancel:()=>{p(null)}})})]})}function Xr(e,t,n,r){let i=rt(e,t.path);if(!Array.isArray(i))return;let a=i.find(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Reflect.get(e,t.keyField)===n);return a===void 0?void 0:rt(a,r)}function Zr({deviceId:e,link:t,itemArray:n,trpcClient:r,onDelete:i,onEdit:a,isPending:o}){let s=De(r,e,t.target.cap),c=t.target.itemKey,l=s===void 0?void 0:c!==void 0&&n!==void 0?Xr(s,n,c,t.target.fieldPath):c===void 0?rt(s,t.target.fieldPath):void 0,u=l==null?`—`:String(l);return H(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[q($t,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),H(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[H(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[q(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),q(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),q(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath}),c!==void 0&&q(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Item key — links sharing it build one array item`,children:c})]}),H(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[q(`span`,{children:`←`}),t.source.kind===`literal`?H(`span`,{className:`font-mono`,children:[`literal: `,String(t.source.value)]}):t.source.kind===`expression`?H(W,{children:[H(`span`,{className:`font-mono`,title:t.source.expr,children:[`ƒ`,` `,t.source.expr.length>40?`${t.source.expr.slice(0,40)}…`:t.source.expr]}),H(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Number of source bindings`,children:[Object.keys(t.source.bindings).length,` bindings`]})]}):H(W,{children:[q(`span`,{className:`font-mono`,children:t.source.kind===`global`?t.source.sourceStableId:t.source.sourceKey}),q(`span`,{className:`opacity-60`,children:`/`}),q(`span`,{className:`font-mono`,children:t.source.cap}),q(`span`,{className:`opacity-60`,children:`.`}),q(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]})]}),t.transform&&q(Qr,{kind:t.transform.kind}),q(`span`,{className:`font-mono text-[11px] tabular-nums min-w-[2.5rem] text-right text-foreground-subtle`,title:`Live resolved value (from this device's runtime-state slice)`,children:u}),q(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:o,onClick:a,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:`Edit`}),q(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:o,onClick:i,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-danger hover:border-danger/50 hover:bg-danger/5 transition-colors disabled:opacity-50`,children:`Delete`})]})}function Qr({kind:e}){return q(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}V();var $r=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`pipeline`,label:`Pipeline steps`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0},{id:`wiring`,label:`Wiring`,cameraOnly:!1}];function ei(e){let t=e===Y.Camera;return $r.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var ti=[{id:`logs`,icon:Rt,label:`Logs`},{id:`repl`,icon:Ft,label:`REPL`},{id:`events`,icon:kt,label:`Events`},{id:`state`,icon:Ot,label:`State`}];function ni(){let e=Mt(),t=Number(e.deviceId),n=Number.isFinite(t),r=At(),i=G(),s=ee(),l=X(),[u,d]=Et(),f=u.get(`tab`)??`overview`,p=u.get(`sub`),[_,v]=K(`logs`),y=`device-detail.left-col-width-px`,[b,x]=K(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(y),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),S=B(b);S.current=b;function C(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??b??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{x(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=S.current;if(e!==null)try{window.localStorage.setItem(y,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:w,isLoading:T,isError:E}=A({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:D}=a({deviceId:t},{enabled:n}),O=U(()=>{let e=D?.settings?.sections??[],t=D?.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(Ln)&&r.add(Pn),[...r].map(e=>e===`export`?{id:e,label:Fn,isAddonContrib:!0}:{id:e,label:Ze[e]?.label??e,isAddonContrib:!0})},[D]),k=w,j=String(k?.name??e.deviceId??`Device`),re=k?.online===!0,ie=re?`online`:`offline`,M=String(k?.addonId??`rtsp`),N=k?.features??[],P=k?.type,ae=P===Y.Camera,{data:oe}=gt(n?t:0),se=P===Y.Container,ce=U(()=>(oe??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[oe]),F=U(()=>se?fe(ce,typeof k?.linkDeviceId==`number`?k.linkDeviceId:null,typeof k?.primaryChildEntityId==`string`?k.primaryChildEntityId:null)?.id??null:null,[se,ce,k?.linkDeviceId,k?.primaryChildEntityId]),{data:ue}=a({deviceId:F??0},{enabled:F!==null}),de=U(()=>{if(F===null)return[];let e=ue?.settings?.sections??[],t=ue?.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:Ze[e]?.label??e,isAddonContrib:!0,childDeviceId:F}))},[F,ue]),pe=typeof k?.parentDeviceId==`number`?k.parentDeviceId:null,{data:me}=A({deviceId:pe??0},{enabled:pe!==null}),I=ge(),he=k?.disabled!==!0,{data:_e}=ne({deviceId:t},{enabled:n}),ve=(_e?.caps.length??0)>0,L=U(()=>{let e=new Set,t=[];for(let n of[...ei(P),...O,...de])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!ve)&&t.push(n));return t},[P,O,de,ve]),Se=U(()=>L.some(e=>e.id===f)?f:`overview`,[L,f]),Te=z(e=>{d(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[d]),Ee=z(e=>{d(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[d]),De=(oe??[]).length>0,Oe=U(()=>ti.filter(({featureGate:e})=>!e||N.includes(e)),[N]),{data:R}=be({addonId:M},{enabled:!!M&&M!==`rtsp`}),Ae=Ce({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]}),r(R?.id?`/integrations/${R.id}`:`/integrations`)}}),Ne=Be({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=Me({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=Ve(),Ie=le({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=N.includes(et.Rebootable),Re=N.includes(et.BatteryOperated),ze=h(l.trpcClient,Re&&n?t:null),[He,Ue]=K(!1),We=ot(l.trpcClient,n?t:null),Ge=async()=>{if(!(He||!We)){Ue(!0);try{await We.snapshot?.invalidateCache({});let e=await We.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=j.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{Ue(!1)}}},Ke=Ne.isPending||Pe.isPending,{data:V}=ye({deviceId:t},{enabled:n,refetchInterval:1e4}),W=V?.agentNodeId??null,qe=typeof W==`string`&&W.length>0&&!W.startsWith(`addon:`)?W:void 0,{data:J}=te({deviceId:t,...qe?{nodeId:qe}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:Je}=m({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),Ye=Je?.level?.dbfs??null;function Xe(){if(!n)return null;switch(Se){case`overview`:return q(vr,{device:k??{}});case`config`:return q(Zn,{deviceId:t,activeSubTab:p,onSubTabChange:Ee});case`pipeline`:return q(tr,{deviceId:t,refreshToken:0});case`bindings`:return q(On,{deviceId:t});case`wiring`:return q(Yr,{deviceId:t});default:{let e=Se,n=O.some(t=>t.id===e),r=de.find(t=>t.id===e);if(!n&&r===void 0)return null;let i=r?.childDeviceId??t;if(e===`export`)return q(Xn,{deviceId:t,sectionFilter:Ln,activeSubTab:p,onSubTabChange:Ee});let a=q(Xn,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:p,onSubTabChange:Ee});return r!==void 0&&i!==t?q(xe,{deviceId:i,children:a}):a}}}return n?T?H(`div`,{className:`flex flex-col h-full`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[q(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),q(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),q(`div`,{className:`flex-1 p-6`,children:q(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):E||!w?H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`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:[`#`,t]})]}),q(`button`,{onClick:()=>r(`/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:[q(`div`,{className:`mb-2`,children:q(je,{items:[{label:`Integrations`,onClick:()=>r(`/integrations`)},{label:R?.name??M,onClick:()=>R?.id&&r(`/integrations/${R.id}`)},{label:j}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[q(mt,{type:M,size:`lg`}),H(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[q(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:j}),q(Wt,{status:ie}),Re&&q(g,{status:ze,variant:`full`})]}),pe!==null&&me&&H(`button`,{type:`button`,onClick:()=>r(`/devices/${pe}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${me.name}`,children:[q(`span`,{children:`↑`}),q(`span`,{className:`truncate`,children:String(me.name??`Device #${pe}`)})]}),q(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:N.length>0&&q(dt,{capabilities:N})})]}),J&&q(`div`,{className:`hidden lg:flex`,children:q(ri,{metrics:J,dbfs:Ye})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{he?await s({title:`Disable "${j}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Pe.mutate({deviceId:t}):Ne.mutate({deviceId:t})},disabled:Ke,title:he?`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 ${he?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[q(tn,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:Ke?`Updating…`:he?`Enabled`:`Disabled`})]}),q(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),q(we,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:Dt,disabled:He,onClick:()=>{Ge()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:xt,hidden:!Le,disabled:Fe.isPending,danger:!0,onClick:async()=>{await s({title:`Reboot "${j}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Fe.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??M}.`,icon:bt,disabled:Ie.isPending,danger:!0,onClick:async()=>{await s({title:`Restart "${R?.name??M}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${j}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Ie.mutate({addonId:M})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Bt,separatorBefore:!0,disabled:Ae.isPending,danger:!0,onClick:async()=>{await s({title:`Delete "${j}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ae.mutate({deviceId:t})}}]})]})]})]}),q(xe,{deviceId:t,device:k??void 0,children:q(o,{children:q(c,{children:q(lt,{children:q(ke,{children:H(`main`,{className:I?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[H(`div`,{className:I?`flex flex-col bg-surface`:`${b===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!I&&b!==null?{width:`${String(b)}px`}:void 0,children:[q(`div`,{className:ae?`flex-shrink-0 border-b border-border-subtle bg-black`:I?`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:ae?q(Cn,{deviceId:t,intercomAvailable:N.includes(et.TwoWayAudio)}):q(mn,{deviceId:t,deviceName:j,deviceType:P??`unknown`,provider:M,isOnline:re,features:N})}),H(`div`,{className:I?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:q(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Oe.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>v(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${_===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[q(n,{className:`h-3 w-3`}),t]},e))})}),H(`div`,{className:I?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[_===`logs`&&q(wn,{deviceId:t,containerDeviceId:P===`container`?t:void 0}),_===`repl`&&q(Tn,{deviceId:t}),_===`events`&&q(En,{deviceId:t}),_===`state`&&q(Dn,{deviceId:t})]})]})]}),!I&&q(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:C,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:q(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),H(`div`,{className:I?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:q(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:L.map(e=>{let t=Se===e.id;return H(`button`,{onClick:()=>Te(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&&q(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),H(`div`,{className:I?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[Se===`overview`&&De&&q(rn,{parentDeviceId:t}),Xe()]})]})]})})})})})})]}):H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),H(`p`,{className:`text-xs`,children:[`The URL segment`,` `,q(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),q(`button`,{onClick:()=>r(`/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 ri({metrics:e,dbfs:t}){let n=f(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:[q(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),q(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),q(`div`,{className:`h-3 w-px bg-border`}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(wt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),q(`span`,{children:`fps`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(Lt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),q(`span`,{children:`ms`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[q(nn,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),q(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&H(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{ni as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{Aa as e,Br as t,C as n,Ci as r,Di as i,Ei as a,Fr as o,Gr as s,Hr as c,Ia as l,Jr as u,Kr as d,Lr as f,Qi as p,Qr as m,Ra as h,Rr as g,T as _,Ti as v,Ur as y,Vr as b,Xr as x,Zr as S,_ as C,aa as w,ai as T,bi as E,ca as D,ci as O,da as k,di as A,ei as j,fi as M,ia as N,it as P,ki as ee,na as F,oi as I,ot as te,pi as ne,qr as re,ra as ie,ri as ae,sa as oe,si as se,ti as ce,ua as le,ui as ue,vi as de,xi as fe,yi as pe,zr as me}from"./src-CSLY6BPe.js";import{I as he,K as ge,Q as L,S as R,T as _e,W as z,a as ve,b as B,o as V,q as H,x as U,z as W}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{L as G,R as ye}from"./src-DkLajgHy.js";import{p as be}from"./player-overlays-D_uAA1FM.js";import{t as xe}from"./download-BdD4jpmM.js";import{i as Se,n as Ce,r as we,t as Te}from"./AddLocationWizard-Bi0ljsVA.js";import{n as Ee,r as De,t as Oe}from"./zap-C4RnkQsi.js";import{i as ke,r as Ae}from"./useDevice-CSvcJkG5.js";import{t as je}from"./pencil-Ctcgfyao.js";import{t as Me}from"./plus-BPews3hd.js";import{t as Ne}from"./refresh-cw-DPd788Ly.js";import{t as Pe}from"./search-D3qB3OId.js";import{t as Fe}from"./server-DCZCFjSL.js";import{t as Ie}from"./square-check-big-DXqD6BOi.js";import{t as Le}from"./square-DaYEm0Ao.js";import{A as Re,F as ze,G as Be,M as Ve,P as He,V as Ue,i as We,j as Ge,k as K,o as Ke,s as qe,w as Je,x as q}from"./index-BGSe7zm2.js";import{t as Ye}from"./AdminPage-BwmGKnRf.js";import{t as J}from"./useEventInvalidation-D85JeECP.js";import{a as Xe,c as Y,i as Ze,l as Qe,n as $e,o as X,r as et,s as tt,t as nt}from"./build-cluster-graph-DEgurNYu.js";import{n as rt}from"./format-size-CO9d3C3-.js";import{t as it}from"./NodeAddonsSettingsPanel-G-afOE2k.js";var at=Ue(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),ot=Ue(`film`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M7 3v18`,key:`bbkbws`}],[`path`,{d:`M3 7.5h4`,key:`zfgn84`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`path`,{d:`M3 16.5h4`,key:`1230mu`}],[`path`,{d:`M17 3v18`,key:`in4fa5`}],[`path`,{d:`M17 7.5h4`,key:`myr1c1`}],[`path`,{d:`M17 16.5h4`,key:`go4c1d`}]]),st=Ue(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),ct=Ue(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);L();function lt(e){return e}function ut(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function dt(e,t){return typeof e==`boolean`?e:lt(t)}function ft(e,t){return{decode:dt(ut(e,`decode`),t),pipeline:dt(ut(e,`detect`),t),audio:dt(ut(e,`audio`),t),ingest:dt(ut(e,`ingest`),t)}}function pt(e,t,n){let r=e?.find(e=>e.nodeId===t);return ft(r?.settings,n)}function mt({selectedNodeId:t,onSelect:n,refreshToken:r}){let{data:i}=o(void 0),{data:a}=T(void 0),{data:s}=I(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=i??[],u=l.filter(e=>e.isOnline).length,d=l.filter(e=>!e.isOnline).length;return R(`div`,{className:`flex flex-col h-full`,children:[R(`button`,{type:`button`,onClick:()=>n(Pr),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${t===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[U(Je,{className:`h-4 w-4 flex-shrink-0`}),R(`div`,{className:`min-w-0 flex-1`,children:[U(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),U(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),U(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(r=>{let i=t===r.id,a=c.get(r.id)??0,o=r.isHub?Fe:K,l=pt(s,r.id,r.isHub),u=r.isOnline?null:h(Qe(r.lastSeen));return R(`button`,{type:`button`,onClick:()=>n(r.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${i?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${r.isOnline?``:` opacity-60`}`,children:[U(o,{className:`h-4 w-4 flex-shrink-0`}),R(`div`,{className:`min-w-0 flex-1`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`text-xs font-semibold truncate`,children:r.name}),r.isHub&&U(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!r.isOnline&&U(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),r.isOnline&&U(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),R(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[R(`span`,{children:[r.cpuCores,` cores`]}),U(`span`,{children:`•`}),R(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a>0&&R(B,{children:[U(`span`,{children:`•`}),R(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[U(Ee,{className:`h-2.5 w-2.5`}),a]})]}),!r.isOnline&&R(B,{children:[U(`span`,{children:`•`}),R(`span`,{className:`text-destructive`,children:[`offline`,u===null?``:` · ${u}`]})]})]}),R(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[U(e,{variant:l.decode?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.decode?`Decode: enabled`:`Decode: not enabled (agent capability)`,children:`Dec`}),U(e,{variant:l.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),U(e,{variant:l.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},r.id)})}),R(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[R(`span`,{children:[u,` online`]}),d>0&&R(`span`,{className:`text-destructive`,children:[d,` offline`]})]})]})}function ht({nodeId:e,refreshToken:t}){let{data:n}=o(void 0),r=n?.find(t=>t.id===e),i=ie(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?R(`div`,{className:`px-6 py-4 border-b border-border`,children:[R(`div`,{className:`flex items-center gap-2 mb-1`,children:[U(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?U(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):U(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&U(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),R(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[U(`span`,{children:r.cpuModel??`CPU`}),U(`span`,{children:`•`}),R(`span`,{children:[r.cpuCores,` cores`]}),U(`span`,{children:`•`}),R(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),i&&R(B,{children:[U(`span`,{children:`•`}),R(`span`,{children:[i.attachedCameras,` cameras (`,i.activeCameras,` active)`]}),U(`span`,{children:`•`}),R(`span`,{children:[i.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),U(`span`,{children:`•`}),R(`span`,{children:[`queue `,i.queueDepthTotal]}),i.hardware.hasGpu&&R(B,{children:[U(`span`,{children:`•`}),U(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):U(`div`,{className:`px-6 py-4 border-b border-border`,children:R(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function gt({refreshToken:e,nodeId:t}){let[n,r]=H(new Map),{nodes:i}=F();w(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:a}=m(void 0),o=z(()=>{let e=new Map;for(let t of a??[])e.set(t.nodeId,t.deviceCount);return e},[a]),s=z(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),c=z(()=>{let e=new Map;for(let t of i)e.set(t.id,t.shortName);return e},[i]),l=z(()=>{let e=0,t=0,n=0,r=0,a=0;for(let i of s.values())e+=i.attachedCameras,t+=i.activeCameras,n+=i.totalFps,r+=i.totalInferenceWeighted,a+=i.queueDepth;let o=e>0?r/e:0;return{totalAgents:i.length,onlineAgents:i.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:o,queueDepth:a,totalFps:n}},[s,i]);if(t){let e=s.get(t);return R(`div`,{className:`@container/liveload`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),R(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[U(Z,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),U(Z,{label:`Cameras`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),U(Z,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),U(Z,{label:`Queue`,value:e?String(e.queueDepth):`—`}),U(Z,{label:`Audio`,value:String(o.get(t)??`—`)})]})]})}let u=[...s.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return R(`div`,{className:`@container/liveload`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),R(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[U(Z,{label:`Total agents`,value:`${l.onlineAgents}/${l.totalAgents}`}),U(Z,{label:`Cameras`,value:`${l.activeCameras}/${l.attachedCameras}`}),U(Z,{label:`Total FPS`,value:l.totalFps.toFixed(1)}),U(Z,{label:`Avg inference ms`,value:l.avgInferenceTimeMs.toFixed(0)}),U(Z,{label:`Queue depth`,value:String(l.queueDepth)})]}),U(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:R(`table`,{className:`w-full text-xs min-w-[480px]`,children:[U(`thead`,{className:`bg-surface`,children:R(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[U(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),U(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),U(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),U(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),U(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),U(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),R(`tbody`,{children:[u.map(([e,t])=>R(`tr`,{className:`border-t border-border`,children:[U(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:c.get(e)??e}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:o.get(e)??`—`})]},e)),u.length===0&&U(`tr`,{children:U(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function Z({label:e,value:t}){return R(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[U(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),U(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}L();var _t={active:!1,pinned:!1,nodeId:null,reason:``},vt=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],yt={pipeline:K,decoder:ot,audio:De},bt={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function xt({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let r=V(),[i,a]=H(null),[o,c]=H(null),[l,u]=H(new Map);J([`pipelineOrchestrator`,`getPipelineAssignments`],vt),J([`pipelineOrchestrator`,`getDecoderAssignments`],vt),J([`pipelineOrchestrator`,`getAudioAssignments`],vt);let{data:f}=T(void 0),{data:p}=ae(void 0),{data:m}=S(void 0),{nodes:h}=F(),{data:g}=Ae();w(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&u(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),W(()=>{if(l.size===0)return;let e=setInterval(()=>{u(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[l.size]);let v=z(()=>{let e=new Map;for(let t of g??[])e.set(t.id,t.name);return e},[g]),y=z(()=>{let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:v.get(e)??`Device ${e}`,pipeline:_t,decoder:_t,audio:_t};return n.set(e,r),r};for(let i of f??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``}})}for(let i of p??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,decoder:{active:e===`cluster`?!0:i.decoderNodeId===t,pinned:i.pinned,nodeId:i.decoderNodeId,reason:i.reason??``}})}for(let i of m??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,audio:{active:e===`cluster`?!0:i.nodeId===t,pinned:i.pinned,nodeId:i.nodeId,reason:`capacity`}})}let i=[...n.values()];return e===`agent`&&(i=i.filter(e=>e.pipeline.active||e.decoder.active||e.audio.active)),i.sort((e,t)=>e.deviceId-t.deviceId),i},[f,p,m,v,e,t]),b=z(()=>(h??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[h]),x=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})},C=re({onSuccess:x}),D=E({onSuccess:x}),O=d({onSuccess:x}),k=pe({onSuccess:x}),A=s({onSuccess:x}),j=de({onSuccess:x}),M=(e,t,n)=>{t===`pipeline`?C.mutate({deviceId:e,agentNodeId:n}):t===`decoder`?O.mutate({deviceId:e,nodeId:n}):A.mutate({deviceId:e,nodeId:n}),a(null)},N=(e,t)=>{t===`pipeline`?D.mutate({deviceId:e}):t===`decoder`?k.mutate({deviceId:e}):j.mutate({deviceId:e}),a(null)};return U(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:R(`table`,{className:`w-full text-xs min-w-[640px] table-fixed`,children:[U(`thead`,{className:`bg-surface`,children:R(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&U(`th`,{className:`w-10`}),U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?R(B,{children:[U(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),U(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):R(B,{children:[U(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),U(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),U(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),U(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),R(`tbody`,{children:[y.map(t=>{let r=l.get(t.deviceId),s=o===t.deviceId;return R(_e.Fragment,{children:[R(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&U(`td`,{className:`px-2 py-2 align-middle`,children:U(`button`,{type:`button`,onClick:()=>c(s?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":s?`Collapse broker details`:`Expand broker details`,children:U(s?He:Ve,{className:`h-3.5 w-3.5`})})}),R(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[U(`div`,{className:`text-foreground font-medium leading-tight truncate`,title:t.deviceName,children:t.deviceName}),R(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?R(B,{children:[U(`td`,{className:`px-3 py-2 align-middle`,children:U(St,{state:t.pipeline,onlineNodes:b,pending:C.isPending||D.isPending,onChange:e=>{e===`auto`?N(t.deviceId,`pipeline`):M(t.deviceId,`pipeline`,e)}})}),U(`td`,{className:`px-3 py-2 align-middle`,children:U(Ct,{state:t.pipeline})})]}):R(B,{children:[U(wt,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:b,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`pipeline`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>a(null),onMove:e=>M(t.deviceId,`pipeline`,e),onUnpin:()=>N(t.deviceId,`pipeline`)}),U(wt,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:b,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`decoder`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`decoder`?null:{deviceId:t.deviceId,role:`decoder`}),onCloseMenu:()=>a(null),onMove:e=>M(t.deviceId,`decoder`,e),onUnpin:()=>N(t.deviceId,`decoder`)}),U(wt,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:b,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`audio`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>a(null),onMove:e=>M(t.deviceId,`audio`,e),onUnpin:()=>N(t.deviceId,`audio`)})]}),U(`td`,{className:`px-3 py-2 align-middle`,children:U(Dt,{snap:r})})]}),s&&!n&&R(`tr`,{className:`bg-surface/50`,children:[U(`td`,{}),U(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2`,children:U(_,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})})]})]},t.deviceId)}),y.length===0&&U(`tr`,{children:U(`td`,{colSpan:n?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function St({state:e,onlineNodes:t,pending:n,onChange:r}){let i=e.pinned&&e.nodeId?e.nodeId:`auto`,a=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return R(`select`,{value:i,disabled:n,"aria-label":`Pipeline placement pin`,onChange:e=>r(e.target.value),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[U(`option`,{value:`auto`,children:`Auto`}),a.map(e=>R(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function Ct({state:e}){if(!e.active||!e.nodeId)return U(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let t=e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`;return R(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[U(`span`,{className:`font-mono text-[11px] text-foreground truncate`,title:e.nodeId,children:e.nodeId}),U(`span`,{className:`truncate ${e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:t,children:t})]})}function wt({role:e,state:t,mode:n,onlineNodes:r,isMenuOpen:i,onToggleMenu:a,onCloseMenu:o,onMove:s,onUnpin:c}){let l=yt[e],u=r.filter(e=>e.id!==(t.nodeId??``)),d=(t.active||n===`cluster`)&&(u.length>0||t.pinned);return R(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[R(`div`,{className:`flex items-center gap-2 min-w-0`,children:[U(n===`agent`?Tt:Et,{state:t,Icon:l}),U(`div`,{className:`ml-auto shrink-0`,children:d&&U(`button`,{type:`button`,onClick:a,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${bt[e]} actions`,children:U(at,{className:`h-3 w-3 text-foreground-subtle`})})})]}),i&&d&&U(Ot,{title:bt[e],targets:u,pinned:t.pinned,onMove:s,onUnpin:c,onClose:o})]})}function Tt({state:e,Icon:t}){return R(`div`,{className:`flex items-center gap-1.5`,children:[U(e.active?Ie:Le,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),U(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&U(ct,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Et({state:e,Icon:t}){return!e.active||!e.nodeId?R(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[U(t,{className:`h-3 w-3`}),U(`span`,{className:`text-[10px] italic`,children:`—`})]}):R(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[U(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),R(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[U(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),U(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?R(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[U(ct,{className:`h-2.5 w-2.5`}),` manual`]}):R(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}function Dt({snap:e}){if(!e)return U(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:i,configuredFps:a,droppedFrames:o}=e.metrics,s=l(t);return R(`div`,{className:`flex flex-col gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0`,children:[R(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${s.textColor}`,children:[U(C,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),U(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:s.label})]}),R(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[U(`span`,{className:`text-foreground`,children:n.toFixed(1)}),R(`span`,{children:[`/`,a.toFixed(0),` fps`]})]}),R(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[U(`span`,{className:`text-foreground`,children:r.toFixed(0)}),U(`span`,{children:` ms`}),i>0&&R(`span`,{className:`text-warning ml-1`,children:[`q`,i]})]}),R(`span`,{className:`whitespace-nowrap truncate ${o>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,U(`span`,{className:`text-foreground`,children:o})]})]})}function Ot({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=ge(null);return W(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),R(`div`,{ref:o,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[U(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&U(`div`,{className:`py-1`,children:t.map(e=>R(`button`,{type:`button`,onClick:()=>r(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),n&&R(`button`,{type:`button`,onClick:i,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,e.toLowerCase()]}),t.length===0&&!n&&U(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function kt({nodeId:e,refreshToken:t}){return R(`div`,{className:`space-y-6`,children:[U(gt,{refreshToken:t,nodeId:e}),R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),R(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),U(xt,{mode:`agent`,nodeId:e,compact:!0})]})}L();function At(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function jt({nodeId:e,refreshToken:t}){let n=V(),i=c({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:a}=y({nodeId:e}),o=ie(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??a??null,s=o===null;J([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:l}=r({nodeId:e}),{values:u}=N(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),d=z(()=>u.filter(e=>e.metrics.phase===`active`).length,[u]),f=t=>{let n=l??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||i.mutate({nodeId:e,engine:t,force:n.length>0})};return R(`div`,{className:`space-y-6`,children:[R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),R(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(o??[]).length,` engine(s) resident in RAM. `,(l??[]).length,` `,`camera(s) attached, `,d,` actively dispatching frames. Refreshes every 5s.`]})]}),U(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:R(`table`,{className:`w-full text-xs min-w-[640px]`,children:[U(`thead`,{className:`bg-surface`,children:R(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[U(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),U(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),U(`th`,{className:`text-left px-3 py-2`,children:`Models`}),U(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),U(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),U(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),U(`th`,{className:`w-20`})]})}),R(`tbody`,{children:[s&&U(`tr`,{children:U(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!s&&(o??[]).map(e=>{let t=e.kind===`warm-override`;return R(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:``}`,children:[U(`td`,{className:`px-3 py-2`,children:R(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:`bg-success/15 text-success`}`,children:[U(t?st:K,{className:`h-3 w-3`}),t?`warm`:`runtime`]})}),U(`td`,{className:`px-3 py-2`,children:R(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[U(Oe,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),U(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?U(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):U(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>U(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),U(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),U(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?U(`span`,{className:`text-foreground-subtle`,children:At(e.idleMs,e.idleTtlMs)}):U(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(l??[]).length}),U(`td`,{className:`px-3 py-2 text-right`,children:R(`button`,{type:`button`,disabled:i.isPending,onClick:()=>f(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[U(qe,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!s&&(o??[]).length===0&&U(`tr`,{children:U(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),R(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[U(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,U(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`]}),i.isError&&R(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,i.error instanceof Error?i.error.message:`unknown`]})]})}L();var Mt=new Set(ye);function Nt(e){return Mt.has(e)}function Pt(e,t,n){return`${e}/${t}/${n}`}function Ft(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function It(e){return{coreml:`Apple Neural Engine / GPU — .mlpackage`,openvino:`Intel CPU / GPU / NPU — .xml`,onnx:`CPU, CUDA, Node.js — .onnx`}[e.format]??`.${e.format}`}function Q(e){return e.format}function Lt(e,t){let n=0,r=0,i=0;for(let a of e)for(let e of a.addons)for(let a of e.models){let e=a.formats[t];e&&(n++,e.downloaded&&(r++,i+=e.sizeMB))}return{total:n,downloaded:r,downloadedSizeMB:i}}function Rt({addonId:e,model:t,format:n,isActive:r,progress:i,errorMsg:a,onDownload:o,onDelete:s}){let c=t.formats[n];return c?R(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors`,children:[U(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),R(`div`,{className:`flex-1 min-w-0`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),R(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&R(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[U(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:U(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),R(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),U(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:rt(c.sizeMB)}),a&&R(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[U(Ge,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?R(`button`,{onClick:s,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[r?U(q,{className:`h-3 w-3 animate-spin`}):U(qe,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):R(`button`,{onClick:o,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[r?U(q,{className:`h-3 w-3 animate-spin`}):U(xe,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function zt({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=H(!1);return R(`div`,{className:`relative`,children:[R(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[U(K,{className:`h-4 w-4 text-primary shrink-0`}),R(`div`,{className:`flex-1 min-w-0`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`text-sm font-medium text-foreground`,children:Ft(n)}),Q(n)===Q(t)&&U(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),U(`div`,{className:`text-[10px] text-foreground-subtle`,children:It(n)})]}),U(He,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&U(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let i=Q(e)===Q(n),o=Q(e)===Q(t);return R(`button`,{type:`button`,onClick:()=>{r(e),a(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${i?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[U(K,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),R(`div`,{className:`flex-1`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:Ft(e)}),o&&U(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),U(`div`,{className:`text-[10px] text-foreground-subtle`,children:It(e)})]}),i&&U(Re,{className:`h-4 w-4 text-primary shrink-0`})]},Q(e))})})]})}function Bt({embedded:e=!1,nodeId:n}={}){let r=V(),i=n??`hub`,[a,o]=H(null),[s,c]=H(new Set),[l,u]=H(new Map),[d,p]=H(new Map),[m,h]=H(``),{data:_=[]}=me({nodeId:i}),v=_.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:y}=b({nodeId:i}),x=y,{data:S,isLoading:C}=t({nodeId:i}),T=g(),E=f();w(`model.download.progress`,e=>{let t=e.data,n=typeof t.modelId==`string`?t.modelId:void 0,i=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;n===void 0||i===void 0||(u(e=>{let t=new Map(e);return i===100||i===-1?t.delete(n):t.set(n,{modelId:n,progress:i,totalMB:a}),t}),i===100&&r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let D=x??{runtime:`node`,backend:`cpu`,format:`onnx`},O=v.find(e=>e.format===a)??D,k=O.format,A=S?.slots??[],j=A.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(e=>e.formats[k]!==void 0)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),M=Lt(j,k),N=he(async(e,t,n)=>{if(!Nt(n))return;let a=Pt(e,t,n);c(e=>new Set([...e,a])),p(e=>{let t=new Map(e);return t.delete(a),t});try{await T.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(t=>new Map([...t,[a,e instanceof Error?e.message:`Download failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[T,r,i]),P=he(async(e,t,n)=>{if(!Nt(n))return;let a=Pt(e,t,n);c(e=>new Set([...e,a])),p(e=>{let t=new Map(e);return t.delete(a),t});try{await E.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(t=>new Map([...t,[a,e instanceof Error?e.message:`Delete failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[E,r,i]),ee=he(e=>{o(e.format)},[]),F=m.trim()?j.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(m.toLowerCase())||t.id.toLowerCase().includes(m.toLowerCase())||e.name.toLowerCase().includes(m.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):j,I=R(B,{children:[C&&U(`div`,{className:`flex items-center justify-center py-16`,children:U(q,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!C&&A.length===0&&R(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[U(Se,{className:`h-8 w-8 mb-3 opacity-30`}),U(`span`,{className:`text-sm`,children:`No pipeline steps available`}),U(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!C&&A.length>0&&R(B,{children:[U(zt,{engines:v,activeEngine:D,viewEngine:O,onSelect:ee}),R(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[R(`span`,{children:[U(`span`,{className:`font-semibold text-foreground tabular-nums`,children:M.total}),U(`span`,{className:`ml-1`,children:`compatible models`})]}),U(`span`,{className:`text-border`,children:`|`}),R(`span`,{children:[U(`span`,{className:`font-semibold text-success tabular-nums`,children:M.downloaded}),U(`span`,{className:`ml-1`,children:`downloaded`})]}),U(`span`,{className:`text-border`,children:`|`}),R(`span`,{className:`tabular-nums`,children:[rt(M.downloadedSizeMB),U(`span`,{className:`ml-1`,children:`on disk`})]})]}),M.total>5&&R(`div`,{className:`relative`,children:[U(Pe,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),U(`input`,{type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:`Search models...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary`})]}),F.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+t.models.filter(e=>e.formats[k]?.downloaded).length,0);return R(`div`,{children:[R(`div`,{className:`flex items-center gap-2 mb-2`,children:[U(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),U(`div`,{className:`flex-1 h-px bg-border`}),R(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),U(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=Pt(e.id,t.id,k);return U(Rt,{addonId:e.id,model:t,format:k,isActive:s.has(n),progress:l.get(t.id),errorMsg:d.get(n),onDownload:()=>N(e.id,t.id,k),onDelete:()=>P(e.id,t.id,k)},`${e.id}/${t.id}`)}))})]},e.id)}),F.length===0&&U(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:m.trim()?R(B,{children:[`No models matching “`,m,`”`]}):R(B,{children:[`No models available for `,Ft(O),` format`]})})]})]});return e?U(`div`,{className:`space-y-4`,children:I}):U(Ye,{children:I})}function Vt({nodeId:e,refreshToken:t}){return U(Bt,{embedded:!0,nodeId:e})}var Ht=[{concern:`pipeline`,label:`Pipeline`,advisory:!1},{concern:`audio`,label:`Audio`,advisory:!1},{concern:`decode`,label:`Decode`,advisory:!0,advisoryNote:`Advisory: decode currently runs co-located with the stream source (hub). Pins are stored and take effect with Phase-2 stream load-balancing.`}];function Ut(e,t){return e.filter(e=>e.currentNodeId!==t)}var Wt=`This node is not decoder-enabled (enabledDecoderNodes). Pinning detection here strands frames (0 fps) until frame-source-aware placement ships. Enable decode on this node first, or pick a decoder-enabled node.`;function Gt(e,t,n){return t.includes(e)?{verdict:`ok`}:n?{verdict:`warn`,reason:Wt}:{verdict:`block`,reason:Wt}}L();var Kt=`pipeline-orchestrator`,qt=`enabledDecoderNodes`;function Jt(e,t){if(!e||typeof e!=`object`)return;let n=e.sections;if(Array.isArray(n))for(let e of n){if(!e||typeof e!=`object`)continue;let n=e.fields;if(Array.isArray(n))for(let e of n){if(!e||typeof e!=`object`)continue;let n=e;if(n.key!==t)continue;let r=n.value;return Array.isArray(r)&&r.every(e=>typeof e==`string`)?r:void 0}}}function Yt({nodeId:e,nodeName:t,concern:n,open:r,onClose:i}){let a=V(),o=Ae(),c=T(void 0),l=ae(void 0),u=S(void 0),f=P({addonId:Kt}),p=re(),m=d(),h=s(),[g,_]=H(new Set),[v,y]=H(!1),[b,x]=H(null),[C,w]=H([]),[E,D]=H(null),O=Ht.find(e=>e.concern===n),k=z(()=>{let e=new Map;if(n===`pipeline`)for(let t of c.data??[])e.set(t.deviceId,t.agentNodeId);else if(n===`decode`)for(let t of l.data??[])e.set(t.deviceId,t.decoderNodeId);else for(let t of u.data??[])e.set(t.deviceId,t.nodeId);return e},[n,c.data,l.data,u.data]),A=z(()=>(o.data??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,currentNodeId:k.get(e.id)??null})),[o.data,k]),j=z(()=>Ut(A,e),[A,e]),M=Jt(f.data,qt),N=n===`pipeline`?Gt(e,M??[],!1):{verdict:`ok`},[ee,F]=H(!1);if(!r)return null;let I=N.verdict===`block`,te=N.verdict===`warn`&&!ee,ne=g.size>0&&!v&&!I&&!te,ie=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},oe=j.length>0&&j.every(e=>g.has(e.deviceId)),se=()=>{_(oe?new Set:new Set(j.map(e=>e.deviceId)))},ce=async t=>{n===`pipeline`?await p.mutateAsync({deviceId:t,agentNodeId:e}):n===`decode`?await m.mutateAsync({deviceId:t,nodeId:e}):await h.mutateAsync({deviceId:t,nodeId:e})},le=new Map(A.map(e=>[e.deviceId,e.name]));return R(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[U(`div`,{className:`absolute inset-0 bg-black/60`,onClick:i}),R(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col h-[80vh] rounded-xl border border-border bg-background shadow-2xl`,children:[R(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[R(`div`,{className:`min-w-0`,children:[R(`h2`,{className:`text-sm font-semibold text-foreground`,children:[`Batch assign `,O?.label??n,` → `,t]}),R(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:[`Pick the cameras whose `,O?.label.toLowerCase()??n,` should run on this node.`]})]}),U(`button`,{type:`button`,onClick:i,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,"aria-label":`Close`,children:U(We,{className:`h-4 w-4`})})]}),R(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[O?.advisory&&O.advisoryNote&&U(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 px-3 py-2 shrink-0`,children:R(`div`,{className:`flex items-start gap-2`,children:[U(Ke,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),U(`p`,{className:`text-[11px] text-warning`,children:O.advisoryNote})]})}),N.verdict!==`ok`&&U(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 shrink-0`,children:R(`div`,{className:`flex items-start gap-2`,children:[U(Ke,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),R(`div`,{className:`min-w-0`,children:[U(`p`,{className:`text-[11px] text-destructive`,children:N.reason}),N.verdict===`warn`&&R(`label`,{className:`mt-1 flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[U(`input`,{type:`checkbox`,checked:ee,onChange:e=>F(e.target.checked),className:`accent-primary`}),`I understand — assign anyway`]})]})]})}),j.length>0&&R(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle shrink-0`,children:[U(`input`,{type:`checkbox`,"aria-label":`Select all`,checked:oe,onChange:se,className:`accent-primary`}),`Select all (`,j.length,`)`]}),U(`div`,{className:`flex-1 min-h-0 overflow-y-auto rounded-lg border border-border divide-y divide-border`,children:j.length===0?R(`div`,{className:`px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:[`No eligible cameras — all cameras are already assigned to `,t,`.`]}):j.map(e=>R(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground hover:bg-surface-hover cursor-pointer`,children:[U(`input`,{type:`checkbox`,"aria-label":`Select ${e.name}`,checked:g.has(e.deviceId),onChange:()=>ie(e.deviceId),className:`accent-primary`}),U(`span`,{className:`truncate`,children:e.name}),e.currentNodeId&&R(`span`,{className:`ml-auto text-[10px] text-foreground-subtle shrink-0`,children:[`on `,e.currentNodeId]})]},e.deviceId))}),(E!==null||C.length>0)&&R(`div`,{className:`space-y-1 text-[10px] shrink-0`,children:[E!==null&&E>0&&R(`p`,{className:`text-success`,children:[`Assigned `,E,` camera(s) to `,t,`.`]}),C.map(e=>R(`p`,{className:`text-destructive`,children:[e.name,`: `,e.message]},e.deviceId))]})]}),R(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[U(`span`,{className:`text-[10px] text-foreground-subtle`,children:v&&b?`${b.done} / ${b.total}…`:``}),R(`div`,{className:`flex items-center gap-2`,children:[U(`button`,{type:`button`,onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Close`}),R(`button`,{type:`button`,onClick:async()=>{let e=[...g];if(e.length===0)return;y(!0),w([]),D(null),x({done:0,total:e.length});let t=[],n=0;for(let r=0;r<e.length;r+=1){let i=e[r];try{await ce(i),n+=1}catch(e){t.push({deviceId:i,name:le.get(i)??String(i),message:e instanceof Error?e.message:String(e)})}x({done:r+1,total:e.length})}y(!1),w(t),D(n),_(new Set),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})},disabled:!ne,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50 disabled:cursor-not-allowed`,children:[v&&U(q,{className:`h-3.5 w-3.5 animate-spin`}),`Assign `,g.size,` to `,t]})]})]})]})]})}L();function Xt({nodeId:e,title:t}){let{data:n}=Ae(),{data:r}=T(void 0),i=z(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),a=z(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),[o,s]=H(new Map);w(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||s(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),W(()=>{if(o.size===0)return;let e=setInterval(()=>{s(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[o.size]);let c=z(()=>{let e=[];for(let t of o.values())a&&!a.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[o,a]);return c.length===0?R(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):R(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[R(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[U(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),U(`span`,{className:`text-[10px] text-foreground-subtle`,children:c.length})]}),U(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>{let t=i.get(e.deviceId)??`#${e.deviceId}`,n=l(e.metrics.phase);return R(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[U(C,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),U(`span`,{className:`font-medium text-foreground/90 max-w-[120px] truncate`,children:t}),U(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),U(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var Zt={key:`maxCameras`,type:`slider`,label:`Max cameras`,description:`Hard cap on cameras the balancer may assign to this node.`,min:1,max:64,step:1,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Unlimited`};L();var Qt=350;function $t(e){return typeof e==`number`&&e>0?Math.floor(e):null}function en({value:e,pending:t,errorMessage:r,onCommit:i}){let[a,o]=H(e);W(()=>{o(e)},[e]);let s=ge(i);return s.current=i,W(()=>{if(a===e)return;let t=setTimeout(()=>s.current(a),Qt);return()=>clearTimeout(t)},[a,e]),R(`div`,{className:`flex items-center gap-3 text-xs text-foreground`,children:[U(`div`,{className:`max-w-md flex-1`,children:U(n,{field:Zt,values:{maxCameras:a},disabled:t,onChange:(e,t)=>o($t(t))})}),t&&U(`span`,{className:`text-[10px] text-muted-foreground animate-pulse`,children:`Saving…`}),r&&R(`span`,{className:`text-[10px] text-destructive`,children:[`Save failed: `,r]})]})}L();var tn=[`pipeline-orchestrator`],nn=[`decoder`];function rn(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 an({nodeId:e,refreshToken:n}){let r=V(),[i,a]=H(null),[s,c]=H(null),[l,u]=H(null),d=(o(void 0).data??[]).find(t=>t.id===e)?.name??e,f=t({nodeId:e},{refetchOnMount:`always`}),p=x({agentNodeId:e},{refetchOnMount:`always`}),m=()=>{r.invalidateQueries({queryKey:[[`addonSettings`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),r.invalidateQueries({queryKey:[[`pipelineExecutor`]]})},h=ue({onSuccess:m}),g=ne({onSuccess:m}),_=f.data??null,v=p.data,y=_?.selectedEngine.format??`coreml`,b=z(()=>_?le(_):[],[_]),S=z(()=>[{agentNodeId:e,engineLabel:y}],[e,y]),C=(e,t)=>{let n=v?.addonDefaults[e];return!rn(_,e)?.models.some(e=>!!e.formats[y])||!n?{kind:`na`}:n.enabled?{kind:`enabled`,modelId:n.modelId}:{kind:`disabled`}},w=i&&_?rn(_,i.addonId):null,T=t=>{let n=v?.addonDefaults[t]??null;a({addonId:t,agentNodeId:e}),c(n)},E=(t,n)=>{if(!v)return;let r=v.addonDefaults[t],i=rn(_,t);if(!r&&!i)return;let a={enabled:n,modelId:r?.modelId??i?.defaultModelId??``,settings:r?.settings??{}};h.mutate({agentNodeId:e,defaults:{...v.addonDefaults,[t]:a}})},O=()=>{a(null),c(null)},A=()=>{!s||!i||!v||h.mutate({agentNodeId:e,defaults:{...v.addonDefaults,[i.addonId]:s}},{onSuccess:O})};if(f.isLoading||p.isLoading)return U(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading pipeline…`});if(f.error)return R(`div`,{className:`text-xs text-red-400`,children:[`Failed to load catalog: `,String(f.error)]});if(!_)return U(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog unavailable for this node (runner offline?).`});let j=i!==null&&w!==null&&s!==null,M=p.data?.maxCameras??null;return R(`div`,{className:`relative h-full w-full space-y-3`,children:[U(Xt,{nodeId:e}),U(en,{value:M,pending:g.isPending,errorMessage:g.isError?g.error instanceof Error?g.error.message:`Unknown error`:null,onCommit:t=>g.mutate({agentNodeId:e,maxCameras:t})}),U(it,{nodeId:e,addonIds:tn,level:`global`,sectionIds:nn}),R(`div`,{className:`flex items-center gap-2 text-xs`,children:[U(`span`,{className:`font-medium text-muted-foreground`,children:`Batch assign:`}),U(`button`,{type:`button`,onClick:()=>u(`pipeline`),className:`rounded border border-border bg-surface px-2 py-0.5 text-xs hover:bg-surface-hover`,children:`Pipeline…`}),U(`button`,{type:`button`,onClick:()=>u(`audio`),className:`rounded border border-border bg-surface px-2 py-0.5 text-xs hover:bg-surface-hover`,children:`Audio…`}),U(`button`,{type:`button`,onClick:()=>u(`decode`),className:`rounded border border-border bg-surface px-2 py-0.5 text-xs text-foreground-subtle hover:bg-surface-hover`,children:`Decode… (advisory)`})]}),l&&U(Yt,{nodeId:e,nodeName:d,concern:l,open:l!==null,onClose:()=>u(null)}),U(`div`,{className:j?`pr-[360px]`:``,children:b.length>0?U(oe,{tree:b,agents:S,getCellState:C,onCellClick:T,selectedCell:i,onToggleEnabled:E}):U(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),U(k,{open:j,onClose:O,title:w?.name??``,subtitle:i?`${i.agentNodeId} · ${y}`:``,footer:R(B,{children:[U(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:O,children:`Cancel`}),U(`button`,{type:`button`,disabled:!s||!i||h.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:A,children:h.isPending?`Saving…`:`Save`})]}),children:w&&s&&i&&U(D,{mode:`agent`,addon:w,agentDefault:s,agentNodeId:i.agentNodeId,engineFormat:y,onChangeAgentConfig:e=>c(e)})})]})}var on=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],sn=`decoder-nodeav`;function cn({nodeId:e,refreshToken:t}){let{data:n}=o(void 0),r=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??sn,i=[...on,r];return R(`div`,{className:`flex flex-col h-full`,children:[U(ht,{nodeId:e,refreshToken:t}),U(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:U(it,{nodeId:e,addonIds:i,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:U(kt,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:U(an,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:U(jt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:U(Vt,{nodeId:e,refreshToken:t})}]})})]})}var ln=`pipeline-orchestrator`,un=`recorder`,dn=`recordingNodeId`,fn=[`ingestNode`,`recordingNode`,`audioNode`],pn=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline for assigned cameras`},{key:`decode`,label:`Decode`,hint:`Decodes video frames locally (advisory placement)`},{key:`audio`,label:`Audio`,hint:`Handles audio codec + analysis work`},{key:`ingest`,label:`Ingest`,hint:`Terminates camera ingest streams`}];function mn(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function hn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function gn(e,t,n){let r=mn(e,t);return typeof r==`string`&&r.length>0?r:n}function _n(e,t,n){let r=mn(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function vn(e,t){let n=hn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function yn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:`Audio`}function bn(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:`Node that runs singleton audio work`}function xn(e,t){return t===`detect`?e.pipeline:e[t]}function Sn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function Cn({capability:e,label:t,hint:n,nodeId:r,active:i,pending:a,layout:o,onToggle:s}){let c=i?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,l=o===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,u=i?ze:ke;return R(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":`${t} capability for ${r}`,title:`${t} — ${n}`,disabled:a,onClick:()=>s(e,!i),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${c} ${l}`,children:[U(u,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),U(`span`,{children:t})]})}L();function wn({nodeId:e,value:t,pending:n,onCommit:r}){let[i,a]=H(t===null?``:String(t));W(()=>{a(t===null?``:String(t))},[t]);let o=()=>{let t=Number(i);r(e,Number.isFinite(t)&&t>0?Math.floor(t):null)};return U(`input`,{"aria-label":`Max cameras for ${e}`,type:`number`,min:0,step:1,placeholder:`∞`,value:i,disabled:n,onChange:e=>a(e.target.value),onBlur:o,onKeyDown:e=>{e.key===`Enter`&&o()},className:`w-20 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`})}function Tn({node:t,emphasis:n=!1}){let r=t.isHub?Fe:K;return R(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[U(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${t.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),U(r,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),R(`div`,{className:`min-w-0`,children:[R(`div`,{className:`flex items-center gap-1.5 ${n?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[U(`span`,{className:`truncate`,children:t.name}),t.isHub&&U(e,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!t.isOnline&&U(e,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),U(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:t.id})]})]})}L();function En({nodeId:e,weight:t,totalWeight:n,pending:r,onCommit:i}){let[a,o]=H(String(t));W(()=>{o(String(t))},[t]);let s=n>0?t/n:0,c=2*Math.PI*15,l=c*s,u=()=>{let t=Number(a);i(e,Number.isFinite(t)&&t>0?t:null)};return R(`div`,{className:`flex items-center gap-3`,children:[R(`svg`,{viewBox:`0 0 40 40`,className:`h-11 w-11 shrink-0`,"aria-hidden":`true`,children:[U(`circle`,{cx:`20`,cy:`20`,r:15,fill:`none`,className:`stroke-border`,strokeWidth:`4`}),U(`circle`,{cx:`20`,cy:`20`,r:15,fill:`none`,className:`stroke-primary transition-all`,strokeWidth:`4`,strokeDasharray:`${l} ${c-l}`,strokeLinecap:`round`,transform:`rotate(-90 20 20)`}),R(`text`,{x:`20`,y:`23`,textAnchor:`middle`,className:`fill-foreground text-[9px] font-bold`,children:[Math.round(s*100),`%`]})]}),U(`input`,{"aria-label":`Detect weight for ${e}`,type:`number`,min:0,step:.25,value:a,disabled:r,onChange:e=>o(e.target.value),onBlur:u,onKeyDown:e=>{e.key===`Enter`&&u()},className:`w-20 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`})]})}function Dn({label:e,children:t}){return R(`div`,{className:`flex items-center justify-between gap-3`,children:[U(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function On({node:e,actions:t}){return R(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[U(Tn,{node:e,emphasis:!0}),U(`div`,{className:`grid grid-cols-2 gap-2`,children:pn.map(n=>U(Cn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:xn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),R(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[U(Dn,{label:`Detect weight`,children:e.effective.pipeline?U(En,{nodeId:e.id,weight:e.weight,totalWeight:t.totalWeight,pending:t.weightPending,onCommit:t.onCommitWeight}):U(`span`,{className:`text-[11px] italic text-foreground-subtle`,children:`Detect off`})}),U(Dn,{label:`Max cameras`,children:U(wn,{nodeId:e.id,value:e.maxCameras,pending:t.maxCamerasPending,onCommit:t.onCommitMaxCameras})})]})]})}function kn(){return R(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[R(`span`,{className:`inline-flex items-center gap-1.5`,children:[U(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),R(`span`,{className:`inline-flex items-center gap-1.5`,children:[U(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),R(`span`,{className:`inline-flex items-center gap-1.5`,children:[U(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),R(`span`,{className:`inline-flex items-center gap-1.5`,children:[U(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function An({nodes:e,actions:t}){return U(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:R(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[U(`thead`,{children:R(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[U(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),pn.map(e=>U(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),U(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Detect weight`}),U(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Max cameras`})]})}),U(`tbody`,{children:e.map(e=>R(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[U(`td`,{className:`px-4 py-3 align-middle`,children:U(Tn,{node:e})}),pn.map(n=>U(`td`,{className:`px-3 py-3 text-center align-middle`,children:U(Cn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:xn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),U(`td`,{className:`px-4 py-3 align-middle`,children:e.effective.pipeline?U(En,{nodeId:e.id,weight:e.weight,totalWeight:t.totalWeight,pending:t.weightPending,onCommit:t.onCommitWeight}):U(`span`,{className:`text-[11px] italic text-foreground-subtle`,children:`Detect off`})}),U(`td`,{className:`px-4 py-3 align-middle`,children:U(wn,{nodeId:e.id,value:e.maxCameras,pending:t.maxCamerasPending,onCommit:t.onCommitMaxCameras})})]},e.id))})]})})}function jn({role:e,value:t,options:n,pending:r,onChange:i}){return R(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[U(`span`,{className:`text-xs font-semibold text-foreground`,children:yn(e)}),U(`select`,{value:t,disabled:r,onChange:t=>i(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:n.map(e=>U(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),U(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:bn(e)})]})}function Mn({roleValues:e,options:t,pending:n,lowFpsEnabled:r,fpsMinThreshold:i,onRoleChange:a,onLowFpsToggle:o}){return R(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[fn.map(r=>U(jn,{role:r,value:e[r],options:t,pending:n,onChange:a},r)),R(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[U(`input`,{type:`checkbox`,checked:r,disabled:n,onChange:e=>o(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),R(`span`,{className:`flex flex-col gap-0.5`,children:[U(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),R(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,r?`${i} fps`:`disabled`]})]})]})]})}L();function Nn(){let e=V(),{nodes:t}=F(),n=I(void 0),r=P({addonId:ln}),i=P({addonId:un}),a=()=>Sn(e),o=A({onSuccess:a}),s=M({onSuccess:a}),c=ne({onSuccess:a}),l=te({onSuccess:a}),u=z(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),d=z(()=>t.map(e=>{let t=u.get(e.id),n=ft(t,e.isHub),r=vn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:vn(t,`maxCameras`)}}),[t,u]),f=d.filter(e=>e.effective.pipeline).reduce((e,t)=>e+t.weight,0),p={ingestNode:gn(r.data,`ingestNode`,`hub`),recordingNode:gn(i.data,dn,`hub`),audioNode:gn(r.data,`audioNode`,`hub`)},m=z(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...fn.map(e=>p[e]),...e])].filter(e=>e.length>0)},[t,p]),h=_n(r.data,`fpsMinThreshold`,0),g=h>0,_=n.isLoading||r.isLoading||i.isLoading,v=(e,t,n)=>{o.mutate({agentNodeId:e,[t]:n})},y=(e,t)=>{if(e===`recordingNode`){l.mutate({addonId:un,patch:{[dn]:t}});return}l.mutate({addonId:ln,patch:{[e]:t}})},b=e=>{l.mutate({addonId:ln,patch:{fpsMinThreshold:e?Math.max(1,h):0}})},x={totalWeight:f,capabilityPending:o.isPending,weightPending:s.isPending,maxCamerasPending:c.isPending,onToggleCapability:v,onCommitWeight:(e,t)=>s.mutate({agentNodeId:e,detectWeight:t}),onCommitMaxCameras:(e,t)=>c.mutate({agentNodeId:e,maxCameras:t})};return R(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[R(`header`,{className:`flex items-start justify-between gap-4`,children:[R(`div`,{className:`space-y-1`,children:[U(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),U(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, tune relative detection weights, set per-node camera ceilings, and choose the singleton cluster roles. Weights are relative shares across detect-capable nodes.`})]}),_&&U(q,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),R(`div`,{className:`space-y-3`,children:[U(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),U(Mn,{roleValues:p,options:m,pending:l.isPending,lowFpsEnabled:g,fpsMinThreshold:h,onRoleChange:y,onLowFpsToggle:b})]}),R(`div`,{className:`space-y-3`,children:[R(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[U(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),U(kn,{})]}),d.length===0?U(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):R(B,{children:[U(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:d.map(e=>U(On,{node:e,actions:x},e.id))}),U(`div`,{className:`hidden @3xl/clustertab:block`,children:U(An,{nodes:d,actions:x})})]})]})]})}L();function Pn({refreshToken:e}){let t=V(),{data:n}=o(void 0),r=z(()=>nt(n??[]),[n]),i=O({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return R(`div`,{className:`space-y-6`,children:[U(gt,{refreshToken:e}),U(Nn,{}),R(`section`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Cluster map`}),U(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`React Flow topology map retained as the visual placement map; use the table-board above as the control surface.`})]}),U(`div`,{className:`h-[360px] rounded-md border border-border overflow-hidden bg-background`,children:U($e,{graph:r})})]}),R(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[R(`div`,{className:`min-w-0`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),U(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · decoder · audio assignments per camera. Click the kebab to pin / unpin / move any role; expand the chevron for the per-camera broker drill-down.`})]}),R(`button`,{type:`button`,onClick:()=>i.mutate(void 0),disabled:i.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[U(Oe,{className:`h-3.5 w-3.5`}),i.isPending?`Rebalancing…`:`Rebalance pipelines`]})]}),U(xt,{mode:`cluster`})]})}var Fn=[`pipeline-orchestrator`];function In({refreshToken:e}){return U(`div`,{className:`space-y-4 max-w-3xl`,children:U(it,{nodeId:`hub`,addonIds:Fn,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer thresholds, and failover policy. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`})})}L();function Ln({refreshToken:e}){let t=V(),{data:n,isLoading:r}=se(),[i,a]=H(null),[o,s]=H(``),[c,l]=H(``),d=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},f=fe({onSuccess:()=>{a(null),d()}}),p=u({onSuccess:d}),m=e=>{a(e.id),s(e.name),l(e.description??``)},h=()=>{a(null),s(``),l(``)},g=()=>{if(!i)return;let e=c.trim();f.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return U(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let _=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return U(`div`,{className:`space-y-6 max-w-4xl`,children:R(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[R(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),U(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),R(`div`,{className:`text-[11px] text-foreground-subtle`,children:[_.length,` template`,_.length===1?``:`s`]})]}),_.length===0?R(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[U(Me,{className:`h-6 w-6 opacity-40`}),U(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):U(`ul`,{className:`divide-y divide-border`,children:_.map(e=>{let t=i===e.id;return U(`li`,{className:`px-4 py-3 text-xs`,children:R(`div`,{className:`flex items-start gap-3`,children:[U(`div`,{className:`flex-1 min-w-0`,children:t?R(`div`,{className:`space-y-2`,children:[U(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:o,onChange:e=>s(e.target.value),placeholder:`Template name`,autoFocus:!0}),U(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:c,onChange:e=>l(e.target.value),placeholder:`Description (optional)`})]}):R(B,{children:[U(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&U(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),R(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[`engine `,e.config.engine.runtime,`/`,e.config.engine.backend,` ·`,` `,e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,R(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),U(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?R(B,{children:[R(`button`,{type:`button`,onClick:g,disabled:f.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[U(ze,{className:`h-3 w-3`}),`Save`]}),R(`button`,{type:`button`,onClick:h,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[U(We,{className:`h-3 w-3`}),`Cancel`]})]}):R(B,{children:[U(`button`,{type:`button`,onClick:()=>m(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:U(je,{className:`h-3 w-3`})}),U(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&p.mutate({id:e.id})},disabled:p.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:U(qe,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}L();function Rn(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 zn({nodeId:e,refreshToken:n}){let r=V(),i=be().trpcClient,[a,s]=H(null),[c,l]=H(null),u=I(void 0,{refetchOnMount:`always`});J([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`,`addon.updated`]);let d=o(void 0,{refetchOnMount:`always`}),f=z(()=>{let e=new Set;for(let t of d.data??[])t.isOnline&&e.add(t.id);return e},[d.data]),p=t({nodeId:e},{refetchOnMount:`always`}),m=z(()=>(u.data??[]).filter(e=>f.has(e.nodeId)).map(e=>e.nodeId),[u.data,f]),h=ve({enabled:m.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`schema-by-agent`,m.join(`,`),n],queryFn:async()=>{let e={};for(let t of m)try{e[t]=(await i.pipelineExecutor.getSchema.query({nodeId:t})).selectedEngine.format}catch{e[t]=`coreml`}return e}}),g=ue({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),r.invalidateQueries({queryKey:[[`pipelineExecutor`]]}),r.invalidateQueries({queryKey:[[`addonSettings`]]})}}),_=z(()=>p.data?le(p.data):[],[p.data]),v=z(()=>{let e=u.data??[],t=f;return(t.size===0?[]:e.filter(e=>t.has(e.nodeId))).map(e=>{let t=h.data?.[e.nodeId];return{agentNodeId:e.nodeId,engineLabel:t??`(engine unknown)`}})},[u.data,h.data,f]),y=(e,t)=>{let n=(u.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e],r=h.data?.[t];return!Rn(p.data??null,e)?.models.some(e=>r!==void 0&&!!e.formats[r])||!n?{kind:`na`}:n.enabled?{kind:`enabled`,modelId:n.modelId}:{kind:`disabled`}},b=a?u.data?.find(e=>e.nodeId===a.agentNodeId)??null:null,x=a&&p.data?Rn(p.data,a.addonId):null,S=a?h.data?.[a.agentNodeId]??`coreml`:`coreml`,C=()=>{s(null),l(null)},w=(e,t)=>{let n=(u.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e]??null;s({addonId:e,agentNodeId:t}),l(n)},T=()=>{!c||!a||!b||g.mutate({agentNodeId:a.agentNodeId,defaults:{...b.settings.addonDefaults,[a.addonId]:c}},{onSuccess:C})};if(u.isLoading||p.isLoading)return U(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading agents…`});if(!p.data)return R(`div`,{className:`text-xs text-foreground-subtle`,children:[`Catalog unavailable for `,e,`.`]});let E=a!==null&&x!==null&&c!==null;return R(`div`,{className:`relative h-full w-full space-y-3`,children:[U(Xt,{title:`Cluster cameras`}),U(`div`,{className:E?`pr-[360px]`:``,children:_.length>0&&v.length>0?U(oe,{tree:_,agents:v,getCellState:y,onCellClick:w,selectedCell:a}):U(`div`,{className:`text-xs text-foreground-subtle`,children:`No agents or catalog empty.`})}),U(k,{open:E,onClose:C,title:x?.name??``,subtitle:a?`${a.agentNodeId} · ${S}`:``,footer:R(B,{children:[U(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:C,children:`Cancel`}),U(`button`,{type:`button`,disabled:!c||!a||g.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:T,children:g.isPending?`Saving…`:`Save`})]}),children:x&&c&&a&&U(D,{mode:`agent`,addon:x,agentDefault:c,agentNodeId:a.agentNodeId,engineFormat:S,onChangeAgentConfig:e=>l(e)})})]})}L();function Bn({types:e}){let t=V(),n=p(),{data:r}=i({}),o=a(),s=z(()=>o.data??[],[o.data]),[c,l]=H(null),[u,d]=H(null),f=()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},m=ee({onSuccess:f}),h=v({onSuccess:f}),g=z(()=>{let e=new Map;for(let t of r??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[r]),_=e=>{e.isDefault||m.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},y=async e=>{if(e.isDefault){await n({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another as default first.`,confirmLabel:`OK`,variant:`warning`});return}await n({title:`Delete location "${e.displayName}"?`,message:`Removes the record; files on disk are untouched.`,confirmLabel:`Delete`,variant:`danger`})&&h.mutate({id:e.id})},b=e.map(e=>s.find(t=>t.id===e)).filter(e=>e!==void 0);return R(`div`,{className:`space-y-3`,children:[b.length===0?U(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:`No storage locations declared for this purpose.`}):b.map(e=>U(we,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:g.get(e.id)??[],onAdd:e=>l(e),onEdit:e=>d(e),onDelete:e=>{y(e)},onSetDefault:e=>_(e)},e.id)),c!==null&&U(Te,{initialType:c,onClose:()=>l(null),onCreated:()=>{f(),l(null)}}),u!==null&&U(Ce,{location:u,onClose:()=>d(null),onSaved:()=>{f(),d(null)}})]})}L();var Vn=`pipeline-analytics`;function Hn(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function Un(){let e=V(),{data:t}=o(void 0),{data:n,isLoading:r}=P({addonId:Vn}),i=Hn(n),a=te({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),s=z(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return R(`div`,{className:`flex flex-col gap-6`,children:[R(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),U(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),R(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?U(q,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):U(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:Vn,patch:{postProcessingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:s.map(e=>U(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&U(q,{className:`h-4 w-4 animate-spin text-primary`})]})]}),R(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[U(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),U(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),U(Bn,{types:[`eventMedia`]})]})]})}L();var Wn=`recorder`;function Gn(e,t,n){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t&&typeof e.value==`string`)return e.value;return n}function Kn(){let e=V(),{data:t}=o(void 0),{data:n,isLoading:r}=P({addonId:Wn}),i=Gn(n,`recordingNodeId`,`hub`),a=te({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),s=z(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return R(`div`,{className:`flex flex-col gap-6`,children:[R(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),U(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records (continuous & events) and serves playback. Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),R(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?U(q,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):U(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:Wn,patch:{recordingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:s.map(e=>U(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&U(q,{className:`h-4 w-4 animate-spin text-primary`})]}),i!==`hub`&&R(`p`,{className:`mt-2 text-[11px] text-amber-500`,children:[`The stream-broker is hub-only — an agent recorder pulls streams from the hub over the network. The hub's RTSP restream port must be reachable from`,` `,U(`span`,{className:`font-medium`,children:i}),`. If the auto-derived host doesn't work, set the recorder's`,U(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),R(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[U(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),U(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where recordings are stored. Multi-location collections — segments are split across the locations of a type. Add a location to grow capacity; mark one default per type.`}),U(Bn,{types:[`recordings`,`recordingsLow`]})]})]})}L();var qn=[{id:`assignments`,label:`Assignments`},{id:`pipeline`,label:`Pipeline`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`}];function Jn({refreshToken:e}){let[t,n]=H(`assignments`),{data:r}=o(void 0),i=r?.find(e=>e.isHub&&e.isOnline)?.id??r?.find(e=>e.isOnline)?.id??null;return R(`div`,{className:`flex flex-col h-full`,children:[R(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[U(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),U(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Assignments with live load, cluster-wide settings, pipeline template library, per-camera pipeline overrides.`})]}),U(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:qn.map(e=>U(`button`,{type:`button`,onClick:()=>n(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),R(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&U(Pn,{refreshToken:e}),t===`pipeline`&&(i?U(zn,{nodeId:i,refreshToken:e}):U(`div`,{className:`text-xs text-foreground-subtle`,children:`No online node available — schema unreachable.`})),t===`events`&&U(Un,{}),t===`recording`&&U(Kn,{}),t===`settings`&&U(In,{refreshToken:e}),t===`templates`&&U(Ln,{refreshToken:e})]})]})}function Yn(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}L();var Xn={healthy:`bg-green-500`,idle:`bg-yellow-400`,error:`bg-red-500`},Zn={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Qn({health:e}){return U(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${Xn[e]}`,title:Zn[e],"aria-label":Zn[e],role:`img`})}function $n({selectedDeviceId:e,onSelect:t}){let{data:n}=Ae(),{data:r}=ce({}),i=z(()=>{let e=new Map;for(let t of r??[])e.set(t.deviceId,t);return e},[r]),a=z(()=>(n??[]).filter(e=>e.isCamera).map(e=>{let t=i.get(e.id);return{deviceId:e.id,name:e.name,health:t===void 0?`idle`:Yn(t)}}),[n,i]);return a.length===0?U(`div`,{className:`px-4 py-6 text-center text-[11px] text-foreground-subtle italic`,children:`No cameras found`}):U(`ul`,{className:`divide-y divide-border`,children:a.map(n=>{let r=n.deviceId===e;return U(`li`,{children:R(`button`,{type:`button`,onClick:()=>t(n.deviceId),className:[`w-full flex items-center gap-2.5 px-4 py-3 text-left transition-colors`,r?`bg-surface-active text-foreground`:`hover:bg-surface-hover text-foreground-subtle hover:text-foreground`].join(` `),"aria-pressed":r,children:[U(Qn,{health:n.health}),R(`span`,{className:`flex-1 min-w-0`,children:[U(`span`,{className:`block truncate text-[12px] font-medium leading-tight`,children:n.name}),R(`span`,{className:`block text-[10px] text-foreground-subtle leading-tight mt-0.5`,children:[`#`,n.deviceId]})]})]})},n.deviceId)})})}var er=300,tr=158,nr={camera:0,source:1,broker:2,decoder:3,motion:4,detection:4,audio:4,recorder:4};function $(e){return nr[e]*er}function rr(e,t){return e===null||t===null?!1:e!==t}function ir(e){let t=e.profiles.reduce((e,t)=>e+t.subscribers,0),n=e.profiles.reduce((e,t)=>e+t.inFps,0),r=e.profiles.reduce((e,t)=>e+t.outFps,0);return`${t} subs · ${n.toFixed(1)}→${r.toFixed(1)} fps`}function ar(e){return`${e.actualFps.toFixed(1)} fps · q${e.queueDepth} · ${e.avgInferenceMs.toFixed(1)}ms`}function or(e){return`shm ${e.shm.getFrameHits+e.shm.getFrameMisses>0?Math.round(e.shm.getFrameHits/(e.shm.getFrameHits+e.shm.getFrameMisses)*100):0}% hit`}function sr(e){let t=[],n=[],r=e.decoder===null?0:[e.motion,e.detection,e.audio,e.recording].filter(e=>e!==null).length,i=r>1?(r-1)/2*tr:0,a={id:`camera`,kind:`camera`,nodeId:null,data:{deviceId:e.deviceId},position:{x:$(`camera`),y:i}};t.push(a);let o={id:`source`,kind:`source`,nodeId:null,data:{streams:e.source.streams},position:{x:$(`source`),y:i}};t.push(o),n.push({id:`camera->source`,source:`camera`,target:`source`,crossNode:!1});let s=e.broker;if(s!==null){let e={id:`broker`,kind:`broker`,nodeId:null,data:{profiles:s.profiles,webrtcSessions:s.webrtcSessions,rtspRestream:s.rtspRestream},position:{x:$(`broker`),y:i}};t.push(e),n.push({id:`source->broker`,source:`source`,target:`broker`,crossNode:!1})}let c=e.decoder;if(c!==null){let r={id:`decoder`,kind:`decoder`,nodeId:c.nodeId,data:{nodeId:c.nodeId,formats:c.formats,sessionCount:c.sessionCount,shm:c.shm},position:{x:$(`decoder`),y:i}};t.push(r);let a=s===null?`source`:`broker`,o=s===null?void 0:ir(s),l=s===null?or(c):o;n.push({id:`${a}->decoder`,source:a,target:`decoder`,crossNode:rr(null,c.nodeId),...l===void 0?{}:{label:l}});let u=0,d=e.motion;if(d!==null){let e={id:`motion`,kind:`motion`,nodeId:null,data:{enabled:d.enabled,fps:d.fps},position:{x:$(`motion`),y:u*tr}};t.push(e),n.push({id:`decoder->motion`,source:`decoder`,target:`motion`,crossNode:!1}),u++}let f=e.detection;if(f!==null){let e={id:`detection`,kind:`detection`,nodeId:f.nodeId,data:{nodeId:f.nodeId,engine:f.engine,phase:f.phase,configuredFps:f.configuredFps,actualFps:f.actualFps,queueDepth:f.queueDepth,avgInferenceMs:f.avgInferenceMs,provisioning:f.provisioning},position:{x:$(`detection`),y:u*tr}};t.push(e),n.push({id:`decoder->detection`,source:`decoder`,target:`detection`,crossNode:rr(c.nodeId,f.nodeId),label:ar(f)}),u++}let p=e.audio;if(p!==null){let e={id:`audio`,kind:`audio`,nodeId:p.nodeId,data:{nodeId:p.nodeId,enabled:p.enabled},position:{x:$(`audio`),y:u*tr}};t.push(e),n.push({id:`decoder->audio`,source:`decoder`,target:`audio`,crossNode:rr(c.nodeId,p.nodeId)}),u++}let m=e.recording;if(m!==null){let e={id:`recorder`,kind:`recorder`,nodeId:null,data:{mode:m.mode,active:m.active,storageBytes:m.storageBytes},position:{x:$(`recorder`),y:u*tr}};t.push(e),n.push({id:`decoder->recorder`,source:`decoder`,target:`recorder`,crossNode:!1})}}return{nodes:t,edges:n}}L();function cr(e){let{data:t,isLoading:n}=j({deviceId:e}),[r,i]=H(void 0);return W(()=>{t!==void 0&&i(t)},[t]),w(G.PipelineCameraMetricsSnapshot,t=>{let n=t.data;n.deviceId===e&&i(e=>e===void 0||e.detection===null?e:{...e,detection:{...e.detection,phase:n.metrics.phase,actualFps:n.metrics.actualFps,queueDepth:n.metrics.queueDepth,avgInferenceMs:n.metrics.avgInferenceTimeMs}})}),w(G.PipelineEngineProvisioning,e=>{let t=e.data;i(n=>{if(n===void 0||n.detection===null)return n;let r=n.detection.nodeId??n.assignment?.detectionNodeId??null;return r===null||e.source.type!==`node`||e.source.id!==r?n:{...n,detection:{...n.detection,provisioning:{state:t.state,error:t.error}}}})}),w(G.MotionAnalysis,t=>{t.source.type!==`device`||t.source.id!==e||i(e=>e===void 0||e.motion===null?e:{...e,motion:{...e.motion,enabled:!0}})}),w(G.StreamBrokerMetricsSnapshot,t=>{let n=t.data;n.deviceId===e&&i(e=>e===void 0||e.broker===null?e:{...e,broker:{...e.broker,profiles:e.broker.profiles.map(e=>e.profile===n.profile?{...e,subscribers:n.stats.encodedSubscribers+n.stats.decodedSubscribers,inFps:n.stats.inputFps,outFps:n.stats.decodeFps}:e)}})}),w(G.PipelineAudioInferenceResult,t=>{t.data.deviceId===e&&i(e=>e===void 0||e.audio===null?e:{...e,audio:{...e.audio,enabled:!0}})}),w(G.RecordingStarted,t=>{t.data.deviceId===e&&i(e=>e===void 0||e.recording===null?e:{...e,recording:{...e.recording,active:!0}})}),w(G.RecordingStopped,t=>{t.data.deviceId===e&&i(e=>e===void 0||e.recording===null?e:{...e,recording:{...e.recording,active:!1}})}),{status:r,isLoading:n}}function lr({data:e}){return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`source`,position:Y.Right}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full bg-green-500 shrink-0`,"aria-label":`healthy`}),R(`span`,{className:`text-sm font-semibold truncate`,children:[`Camera #`,e.deviceId]})]}),U(`div`,{className:`text-xs text-muted-foreground mt-1`,children:`source`})]})}function ur(e){return e>0?`bg-green-500`:`bg-yellow-500`}function dr({data:e}){let t=e.streams[0],n=e.streams.length;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`target`,position:Y.Left}),U(X,{type:`source`,position:Y.Right}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${ur(n)}`,"aria-label":n>0?`healthy`:`idle`}),U(`span`,{className:`text-sm font-semibold`,children:`Source`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[n,` streams`]})]}),t!==void 0&&R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t.codec,` `,t.width,`×`,t.height,` `,t.fps,`fps`]})]})}function fr(e){return e>0?`bg-green-500`:`bg-yellow-500`}function pr({data:e}){let t=e.profiles.reduce((e,t)=>e+t.subscribers,0),n=e.profiles.length;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`target`,position:Y.Left}),U(X,{type:`source`,position:Y.Right}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${fr(t)}`,"aria-label":t>0?`healthy`:`idle`}),U(`span`,{className:`text-sm font-semibold`,children:`Broker`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[n,` profiles`]})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t,` subs · WebRTC `,e.webrtcSessions,e.rtspRestream&&` · RTSP`]})]})}function mr(e){return e>0?`bg-green-500`:`bg-yellow-500`}function hr(e,t){let n=e+t;return n>0?Math.round(e/n*100):0}function gr({data:e}){let t=hr(e.shm.getFrameHits,e.shm.getFrameMisses),n=e.offline===!0;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2${n?` opacity-50`:``}`,children:[U(X,{type:`target`,position:Y.Left}),U(X,{type:`source`,position:Y.Right}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${mr(e.sessionCount)}`,"aria-label":e.sessionCount>0?`healthy`:`idle`}),U(`span`,{className:`text-sm font-semibold`,children:`Decoder`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[`@`,e.nodeId]}),n&&U(`span`,{className:`text-[9px] font-semibold px-1 py-0.5 rounded bg-destructive/10 text-destructive`,"aria-label":`offline`,children:`offline`})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.formats.join(`, `),` · `,e.sessionCount,` sessions`]}),R(`div`,{className:`text-xs text-muted-foreground`,children:[`shm `,t,`% hit`]})]})}function _r(e){return e?`bg-green-500`:`bg-yellow-500`}function vr({data:e}){return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`target`,position:Y.Left}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${_r(e.enabled)}`,"aria-label":e.enabled?`enabled`:`disabled`}),U(`span`,{className:`text-sm font-semibold`,children:`Motion`})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.enabled?`enabled`:`disabled`,` · `,e.fps,` fps`]})]})}function yr(e){return e.provisioning.state===`failed`?`bg-red-500`:e.phase===`active`?`bg-green-500`:(e.phase,`bg-yellow-500`)}function br(e){return e===`ready`?`bg-green-500 text-white`:e===`failed`?`bg-red-500 text-white`:`bg-yellow-500 text-white`}function xr({data:e}){let t=e.offline===!0;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[180px] px-3 py-2${t?` opacity-50`:``}`,children:[U(X,{type:`target`,position:Y.Left}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${yr(e)}`,"aria-label":e.phase}),U(`span`,{className:`text-sm font-semibold`,children:`Detection`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[`@`,e.nodeId]}),t&&U(`span`,{className:`text-[9px] font-semibold px-1 py-0.5 rounded bg-destructive/10 text-destructive`,"aria-label":`offline`,children:`offline`})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.engine.backend,`·`,e.engine.device,` · `,e.phase]}),R(`div`,{className:`text-xs text-muted-foreground`,children:[e.actualFps.toFixed(1),`/`,e.configuredFps,` fps · q`,e.queueDepth,` ·`,` `,e.avgInferenceMs.toFixed(1),`ms`]}),R(`div`,{className:`flex items-center gap-1 mt-1`,children:[U(`span`,{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded ${br(e.provisioning.state)}`,"aria-label":`provisioning ${e.provisioning.state}`,children:e.provisioning.state}),e.provisioning.state===`failed`&&e.provisioning.error!==void 0&&U(`span`,{className:`text-[10px] text-red-500 truncate`,children:e.provisioning.error})]})]})}function Sr(e){return e?`bg-green-500`:`bg-yellow-500`}function Cr({data:e}){let t=e.offline===!0;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2${t?` opacity-50`:``}`,children:[U(X,{type:`target`,position:Y.Left}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${Sr(e.enabled)}`,"aria-label":e.enabled?`enabled`:`disabled`}),U(`span`,{className:`text-sm font-semibold`,children:`Audio`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[`@`,e.nodeId]}),t&&U(`span`,{className:`text-[9px] font-semibold px-1 py-0.5 rounded bg-destructive/10 text-destructive`,"aria-label":`offline`,children:`offline`})]}),U(`div`,{className:`text-xs text-muted-foreground mt-1`,children:e.enabled?`enabled`:`disabled`})]})}function wr(e){return e.mode===`off`?`bg-red-500`:e.active?`bg-green-500`:`bg-yellow-500`}function Tr(e){return e>=1073741824?`${(e/1073741824).toFixed(1)} GB`:`${(e/1048576).toFixed(1)} MB`}function Er({data:e}){return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`target`,position:Y.Left}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${wr(e)}`,"aria-label":e.active?`active`:e.mode===`off`?`off`:`inactive`}),U(`span`,{className:`text-sm font-semibold`,children:`Recorder`}),U(`span`,{className:`text-xs text-muted-foreground`,children:e.mode})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.active?`active`:`inactive`,` · `,Tr(e.storageBytes)]})]})}L();var Dr={camera:lr,source:dr,broker:pr,decoder:gr,motion:vr,detection:xr,audio:Cr,recorder:Er},Or={stroke:`#f59e0b`,strokeWidth:2},kr={strokeWidth:1.5},Ar=`camstack-pipeline-flow-layout`,jr=`Camera → Source → Broker → Decoder → Motion · Detection · Audio · Recorder`,Mr={padding:.2};function Nr({deviceId:e}){let{status:t,isLoading:n}=cr(e),{data:r}=o(void 0),i=z(()=>{let e=new Set;for(let t of r??[])t.isOnline||e.add(t.id);return e},[r]),{computedNodes:a,rfEdges:s}=z(()=>{if(t===void 0)return{computedNodes:[],rfEdges:[]};let e=sr(t);return{computedNodes:e.nodes.map(e=>({id:e.id,type:e.kind,position:{x:e.position.x,y:e.position.y},data:{...e.data,offline:e.nodeId!==null&&i.has(e.nodeId)}})),rfEdges:e.edges.map(e=>({id:e.id,source:e.source,target:e.target,animated:e.crossNode,style:e.crossNode?Or:kr,label:e.label}))}},[t,i]),{nodes:c,onNodesChange:l,resetLayout:u}=et(`${Ar}:${e}`,a);return n?U(`div`,{className:`flex items-center justify-center h-full text-sm text-muted-foreground`,children:`Loading…`}):t===void 0?U(`div`,{className:`flex items-center justify-center h-full text-sm text-muted-foreground`,children:`No pipeline data`}):R(`div`,{className:`w-full h-full relative overflow-hidden`,children:[R(`div`,{className:`absolute top-2 left-2 z-10 max-w-[calc(100%-7rem)] rounded border border-border bg-background/90 px-2 py-1 backdrop-blur-sm`,children:[U(`div`,{className:`text-xs font-semibold text-foreground`,children:`Pipeline flow`}),U(`div`,{className:`text-[10px] text-muted-foreground truncate`,children:jr})]}),U(`button`,{type:`button`,onClick:u,className:`absolute top-2 right-2 z-10 text-xs px-2 py-1 rounded border border-border bg-background hover:bg-muted`,title:`Restore the automatic layout, discarding dragged positions`,children:`Reset layout`}),R(tt,{nodes:c,edges:s,onNodesChange:l,nodesDraggable:!0,nodeTypes:Dr,fitView:!0,fitViewOptions:Mr,minZoom:.2,proOptions:{hideAttribution:!0},children:[U(Ze,{gap:20,size:1}),U(Xe,{showInteractive:!1})]})]})}L();var Pr=`__cluster__`;function Fr(e){return e===`cameras`?`cameras`:`nodes`}function Ir(){let[e,t]=Be(),n=Fr(e.get(`view`)),r=e.get(`node`)??`__cluster__`,i=e.get(`camera`),a=i===null?null:parseInt(i,10),[o,s]=H(0),[c,l]=H(!1);return W(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Pr},{replace:!0})},[n,e,t]),R(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[R(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[R(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[U(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:r},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),U(`button`,{type:`button`,onClick:()=>{let e={view:`cameras`};a!==null&&(e.camera=String(a)),t(e,{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),R(`button`,{type:`button`,onClick:()=>s(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[U(Ne,{className:`h-3.5 w-3.5`}),`Refresh`]})]}),R(`button`,{type:`button`,onClick:()=>l(e=>!e),"aria-expanded":c,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[R(`span`,{children:[c?`Hide`:`Show`,` `,n===`nodes`?`node list`:`camera list`]}),U(He,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),U(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?R(B,{children:[U(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:U(mt,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:o})}),U(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?U(Jn,{refreshToken:o}):U(cn,{nodeId:r,refreshToken:o})})]}):R(B,{children:[U(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:U($n,{selectedDeviceId:a,onSelect:e=>{t({view:`cameras`,camera:String(e)},{replace:!0}),l(!1)}})}),U(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:a!==null&&Number.isFinite(a)&&!Number.isNaN(a)?U(Nr,{deviceId:a}):U(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Select a camera to view its pipeline flow`})})]})})]})}export{Ir as PipelinePage};
@@ -1 +0,0 @@
1
- import{V as e}from"./index-BGSe7zm2.js";var t=e(`circle-check-big`,[[`path`,{d:`M21.801 10A10 10 0 1 1 17 3.335`,key:`yps3ct`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]);export{t};