@camstack/addon-admin-ui 1.2.85 → 1.2.87

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 (107) hide show
  1. package/dist/assets/{AddLocationWizard-CwreWITW.js → AddLocationWizard-ClWHdX1D.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-B_yz8bA0.js → AddonCollectionPage-CCm-n_-k.js} +1 -1
  3. package/dist/assets/Addons-CNQu3idA.js +1 -0
  4. package/dist/assets/{AdminTabs-BNPrEU-u.js → AdminTabs-Ya-WafVI.js} +1 -1
  5. package/dist/assets/{AiProfiles-BOhYahU1.js → AiProfiles-G8ohU36w.js} +1 -1
  6. package/dist/assets/{BrokerForm-B45_C-11.js → BrokerForm-Cja9Cp03.js} +1 -1
  7. package/dist/assets/{Build-DBt1hX43.js → Build-BUwpX-xq.js} +1 -1
  8. package/dist/assets/{Capabilities-D3ydTf8a.js → Capabilities-CzxtAA9j.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-BsNvOYxI.js → CapabilityBadges-BVAXgYuj.js} +1 -1
  10. package/dist/assets/{Cluster-Be75yEy8.js → Cluster-C3WY-Tom.js} +1 -1
  11. package/dist/assets/{Data-DjH9RwP1.js → Data-DP4AzN8W.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-Bxil3Kqd.js → DetectionIntelligence-Dm0ZECMd.js} +1 -1
  13. package/dist/assets/{DeviceAggregateSection-CmeOZSZb.js → DeviceAggregateSection-aUgWgamW.js} +1 -1
  14. package/dist/assets/DeviceDetail-BoKKas-k.js +2 -0
  15. package/dist/assets/{Devices-BiaI1wtk.js → Devices-BVC0zPbb.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-BFMqluKF.js → EmbedPlayerPage-BwM49mOX.js} +1 -1
  17. package/dist/assets/{Events-2Mew-AL7.js → Events-X4Lovw2K.js} +1 -1
  18. package/dist/assets/{FormBuilder-BDA9-uL2.js → FormBuilder-CgtfU1VA.js} +1 -1
  19. package/dist/assets/{Identity-DYj1lU6G.js → Identity-C2TOQEJq.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-DkP04o_o.js → IntegrationDetail-3MgmsFlC.js} +1 -1
  21. package/dist/assets/{Integrations-Q2IXumNM.js → Integrations-AQCeGcvO.js} +1 -1
  22. package/dist/assets/{Integrations-DypneOCC.js → Integrations-CE6i7W5X.js} +1 -1
  23. package/dist/assets/{Logs-DCGZ4xft.js → Logs-C1e0vFcW.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-D2OfXg-s.js → MotionZonesSettings-AZZ7Vac3.js} +1 -1
  25. package/dist/assets/{MyAccess-DiZ_NQ8Q.js → MyAccess-oAGUI1mc.js} +1 -1
  26. package/dist/assets/{Network-D6Jjjglj.js → Network-BLaNQAjB.js} +1 -1
  27. package/dist/assets/{NodeAddonsSettingsPanel-iynDrGDY.js → NodeAddonsSettingsPanel-B1Cyvbcv.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-kA005bIs.js → NodeInferenceDevices-CkoeBXMD.js} +1 -1
  29. package/dist/assets/{Notifications-3VV4lesM.js → Notifications-D2ro0AxS.js} +1 -1
  30. package/dist/assets/Pipeline-BvxT4V4g.js +1 -0
  31. package/dist/assets/{Plates-Mq7_V44B.js → Plates-TsHHlZDi.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-DegFwke0.js → PrivacyMaskSettings-BxIYztmC.js} +1 -1
  33. package/dist/assets/{ProviderIcon-BRIZHtNP.js → ProviderIcon-BBJFc8mr.js} +1 -1
  34. package/dist/assets/Recordings-CYIFqOWF.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-h2wgb-9T.js → ScanNetworkModal-BQIyP8Qh.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-DtUM6j78.js → SceneMonitorEditor-ZOTjS5Og.js} +1 -1
  37. package/dist/assets/{Scenes-CXbQ1BC3.js → Scenes-DDemjEwK.js} +1 -1
  38. package/dist/assets/{Settings-CezuMxyz.js → Settings-BJydhDaq.js} +1 -1
  39. package/dist/assets/{Showroom-HltZNDXE.js → Showroom-Di_0Md3V.js} +1 -1
  40. package/dist/assets/{Terminal-9BMEBt8x.js → Terminal-CIo6IaUC.js} +3 -3
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CLXUGt-W.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C91lgIiF.js} +1 -1
  42. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DN3UpM8E.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js} +1 -1
  43. package/dist/assets/{bell-ring-BOKJStq_.js → bell-ring-0co0yj8J.js} +1 -1
  44. package/dist/assets/{boxes-BvnEYalC.js → boxes-CKu64rZy.js} +1 -1
  45. package/dist/assets/{build-cluster-graph-BVmcPlKM.js → build-cluster-graph-BWmowgwv.js} +1 -1
  46. package/dist/assets/circle-check-big-BPF9MiQz.js +1 -0
  47. package/dist/assets/{circle-x-De9Atcex.js → circle-x-_qOKhKMV.js} +1 -1
  48. package/dist/assets/clock-DoS4fxPG.js +1 -0
  49. package/dist/assets/{copy-DPSVazs5.js → copy-CE9Wp04n.js} +1 -1
  50. package/dist/assets/{debounced-invalidate-CaNNRf1N.js → debounced-invalidate-CfnWx62K.js} +1 -1
  51. package/dist/assets/{dist-DHHyyJUp.js → dist-CcR-lswN.js} +1 -1
  52. package/dist/assets/dist-D6EYui_h.js +349 -0
  53. package/dist/assets/{download-D0TL4kvK.js → download-mZ1OYsqe.js} +1 -1
  54. package/dist/assets/{face-bbox-DHOml3XL.js → face-bbox-Y-X13UcQ.js} +1 -1
  55. package/dist/assets/{hard-drive-E6KB7P74.js → hard-drive-D6z2TCCh.js} +1 -1
  56. package/dist/assets/{hostInit-CJNRBgTm.js → hostInit-Dr0x9nND.js} +1 -1
  57. package/dist/assets/index-CoX6Kh_l.js +4 -0
  58. package/dist/assets/{index-DR0aGe9s.css → index-DM8saR4E.css} +1 -1
  59. package/dist/assets/{key-round-DCkVCgVU.js → key-round-CegkgxO2.js} +1 -1
  60. package/dist/assets/{mf-entry-bootstrap-0-b0b43084.js → mf-entry-bootstrap-0-e3818a6f.js} +2 -2
  61. package/dist/assets/{pencil-CCigTGBs.js → pencil-CCyVFYXA.js} +1 -1
  62. package/dist/assets/play-DCoy3WUZ.js +1 -0
  63. package/dist/assets/{player-overlays-Cce7zLVf.js → player-overlays-BCuyatPp.js} +1 -1
  64. package/dist/assets/plus-D-xjJ9wd.js +1 -0
  65. package/dist/assets/power-ChfUL_0y.js +1 -0
  66. package/dist/assets/{radio-DH4YapvY.js → radio-DvHOeyw2.js} +1 -1
  67. package/dist/assets/{refresh-cw-7BWEDRql.js → refresh-cw-CvqUZLg2.js} +1 -1
  68. package/dist/assets/remoteEntry-C4Nbi34r.js +1 -0
  69. package/dist/assets/rotate-ccw-CwngHzIQ.js +1 -0
  70. package/dist/assets/rotate-cw-pPP0LEo9.js +1 -0
  71. package/dist/assets/search-Cvti5PjG.js +1 -0
  72. package/dist/assets/{send-BxN-W44d.js → send-DRex-kWD.js} +1 -1
  73. package/dist/assets/{server-MPW5E9Je.js → server-DSkdRu09.js} +1 -1
  74. package/dist/assets/square-B3jj9vzX.js +1 -0
  75. package/dist/assets/{square-check-big-KUDADp7C.js → square-check-big-BbcMGYFH.js} +1 -1
  76. package/dist/assets/{src-CLcW_gk2.js → src-BmCjCFGO.js} +17 -17
  77. package/dist/assets/src-D8hsVOc6.js +349 -0
  78. package/dist/assets/{star-DgpioIxR.js → star-BT_oUHvU.js} +1 -1
  79. package/dist/assets/{undo-2-Dx5lBXZW.js → undo-2-D7QQycip.js} +1 -1
  80. package/dist/assets/{upload-C_Z1HY8V.js → upload-D5h4xcC3.js} +1 -1
  81. package/dist/assets/{use-scenes-feed-7qe4q2V7.js → use-scenes-feed-DcfGN5ks.js} +1 -1
  82. package/dist/assets/useEventInvalidation-DCo7fWEj.js +1 -0
  83. package/dist/assets/{video-CDs4hw5_.js → video--sYC3ys-.js} +1 -1
  84. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BZfm1F7n.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DBBIBnMR.js} +2 -2
  85. package/dist/assets/{wifi-C6eU8xw2.js → wifi-Wacew_4h.js} +1 -1
  86. package/dist/assets/{zap-CosjZI2Q.js → zap-CrjJ004P.js} +1 -1
  87. package/dist/index.html +6 -6
  88. package/dist/server/addon.js +77 -7
  89. package/package.json +1 -1
  90. package/dist/assets/Addons-ByS1wyLr.js +0 -1
  91. package/dist/assets/DeviceDetail-CLZxugdc.js +0 -2
  92. package/dist/assets/Pipeline-Cvq_ZK2N.js +0 -1
  93. package/dist/assets/Recordings-GWbTxHDj.js +0 -1
  94. package/dist/assets/circle-check-big-H_sRGszZ.js +0 -1
  95. package/dist/assets/clock-DmdPTuLe.js +0 -1
  96. package/dist/assets/dist-DtzZqioA.js +0 -349
  97. package/dist/assets/index-BVmc_EOb.js +0 -4
  98. package/dist/assets/play-CAbyx0Ik.js +0 -1
  99. package/dist/assets/plus-CkMMGkZS.js +0 -1
  100. package/dist/assets/power-CFTIVgET.js +0 -1
  101. package/dist/assets/remoteEntry-ee3nHxW_.js +0 -1
  102. package/dist/assets/rotate-ccw-CvT7yFgt.js +0 -1
  103. package/dist/assets/rotate-cw-CHBtKezc.js +0 -1
  104. package/dist/assets/search-LiVSlZYd.js +0 -1
  105. package/dist/assets/square-BGhxv6lU.js +0 -1
  106. package/dist/assets/src-BQU93IBQ.js +0 -349
  107. package/dist/assets/useEventInvalidation-B1u2ACO8.js +0 -1
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,R as r,S as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as d}from"./player-overlays-Cce7zLVf.js";import{An as f,As as p,Bn as m,C as h,Cn as g,En as _,Fn as v,Gi as ee,In as y,J as b,K as x,Nn as S,On as C,Pn as te,Rn as ne,Sn as re,Tn as ie,Zi as w,bn as ae,g as oe,jn as se,kn as T,ln as ce,wn as E,xn as D,yn as le,zn as ue}from"./src-CLcW_gk2.js";import{Lt as O}from"./src-BQU93IBQ.js";import{t as k}from"./clock-DmdPTuLe.js";import{t as A}from"./download-D0TL4kvK.js";import{t as de}from"./plus-CkMMGkZS.js";import{t as j}from"./refresh-cw-7BWEDRql.js";import{t as M}from"./search-LiVSlZYd.js";import{t as N}from"./upload-C_Z1HY8V.js";import{C as P,J as F,K as I,P as L,R,X as z,_ as fe,i as B,m as V,p as pe,s as H,z as U}from"./index-BVmc_EOb.js";import{t as W}from"./AdminPage-CCD07UMs.js";import{t as me}from"./NodeAddonsSettingsPanel-iynDrGDY.js";var he=I(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),ge=I(`octagon-alert`,[[`path`,{d:`M12 16h.01`,key:`1drbdi`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z`,key:`1fd625`}]]),_e=I(`package`,[[`path`,{d:`M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z`,key:`1a0edw`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}]]),G=I(`skip-forward`,[[`polygon`,{points:`5 4 15 12 5 20 5 4`,key:`16p6eg`}],[`line`,{x1:`19`,x2:`19`,y1:`5`,y2:`19`,key:`futhcm`}]]);n();var K=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),q=new Set([`done`,`failed`,`skipped`]);function ve(e){return!q.has(e.phase)&&!K.has(e.jobState)}function J(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=K.has(e.state);for(let i of e.tasks)r&&i.finishedAtMs!==null&&t-i.finishedAtMs>6e4||n.set(i.packageName,{jobId:e.jobId,packageName:i.packageName,phase:i.phase,fromVersion:i.fromVersion,toVersion:i.toVersion,error:i.error,jobState:e.state,finishedAtMs:i.finishedAtMs})}return n}function ye(){let{data:e}=C({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=p(O.AddonsJobProgress,e=>e.job.jobId);return a(()=>{let n=new Map;for(let t of e??[])n.set(t.jobId,t);for(let[e,r]of t)n.set(e,r.job);return J([...n.values()],Date.now())},[e,t])}var be={queued:{icon:k,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:P,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:P,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:P,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:P,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:P,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:P,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:U,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:ge,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:G,cls:`bg-muted text-foreground-subtle`,label:`skipped`}};function xe({progress:e}){let t=be[e.phase],n=t.icon,r=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return i(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${t.cls}`,title:r,children:[l(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,i(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function Se({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:a,onSelect:s,selectedVersion:c}){let u=n===`upload`||n===`local`,{data:d,isLoading:f}=E({name:e});return i(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[i(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[l(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),l(`button`,{type:`button`,onClick:a,className:`text-foreground-subtle hover:text-foreground`,children:l(B,{className:`h-3 w-3`})})]}),u&&i(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[l(N,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),i(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[i(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,l(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),f&&i(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[l(P,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),d&&l(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:d.map(e=>{let n=e.version===t,a=s!==void 0&&e.version===c,d=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),f=i(o,{children:[l(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:d?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:`current`}),e.distTags.map(e=>l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),e.deprecated&&l(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),l(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return s?i(`button`,{type:`button`,"aria-label":`Select ${e.version}`,onClick:()=>s(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${a?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,a?l(U,{className:`h-3 w-3 text-primary shrink-0`}):l(`span`,{className:`w-3 shrink-0`})]},e.version):i(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,n&&!u?l(U,{className:`h-3 w-3 text-primary shrink-0`}):l(`button`,{type:`button`,onClick:()=>r(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:n?`Re-install ${e.version} from npm`:`Install ${e.version}`,children:l(A,{className:`h-3 w-3`})})]},e.version)})}),d&&d.length===0&&l(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var Y={queued:{icon:k,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:P,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:j,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:U,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:ge,bg:`bg-danger/10 text-danger`,label:`failed`}};function Ce({item:e}){let t=Y[e.status],n=t.icon;return i(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[l(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}n();var X=`device-export`;function Z(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===X)}function we({isBundle:e,installSource:t,addonId:n,iconPath:r,color:a}){let[o,s]=c(!1),u=a?{backgroundColor:`${a.startsWith(`#`)?a:`#${a}`}26`}:void 0,d=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,f=n&&r?`/api/addon-assets/${n}/${r}`:null,p=!!f&&!o;return i(`div`,{className:`relative flex-shrink-0`,children:[l(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${u?``:d}`,style:u,children:p?l(`img`,{src:f,alt:n,className:`h-5 w-5`,onError:()=>s(!0)}):l(e?_e:fe,{className:`h-4 w-4`})}),t===`local`&&l(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),t===`npm`&&l(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:l(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:l(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&l(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:l(N,{className:`h-2.5 w-2.5 text-white`})})]})}function Te({version:e,availableUpdate:t,selectedVersion:n,isUpdating:r,installSource:a,disabled:o,onUpdate:s,onOpenPicker:c,children:u}){if(r)return i(`span`,{className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[l(P,{className:`h-3 w-3 animate-spin`}),`Updating…`]});if(t){let r=n??t;return i(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[s&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:o,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-semibold border border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:`Update to ${r}`,children:[l(A,{className:`h-3 w-3`}),`Update`]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:o,"aria-label":`Select version to install`,title:`Installed ${e} — update available. Selected ${r}; tap to choose another version.`,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[l(`span`,{className:`font-normal opacity-70`,children:e}),l(`span`,{className:`font-normal opacity-70`,children:`→`}),r,l(R,{className:`h-3 w-3`})]}),u]})}return i(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:o,className:[`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,a===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:`Version ${e} — tap to view all versions`,children:[e,l(R,{className:`h-3 w-3 opacity-50`})]}),u]})}function Ee({addonId:e}){let t=s(),{data:n=`inherit`}=D({addonId:e}),r=v({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return l(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>l(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}function De({addon:e,agents:t=[],clusterStatus:n,hideVersion:r,availableUpdate:a,onUpdate:f,isUpdating:p,jobProgress:m,bundle:g,bulkItem:_,disabledByBulk:v,isSystem:ee}){let[y,C]=c(!1),[te,ne]=c(!1),[re,w]=c(!1),[ae,oe]=c(null);u(()=>{oe(null)},[a]);let T=ae??a,[E,D]=c(!1),[le,O]=c(!1),[k,A]=c(`logs`),M=s(),N=d(),P=F(),I=ce(),{manifest:L}=e,z=e.installedOn??[],fe=!g&&!L.protected&&L.removable!==!1,U=!!g,W=g?.displayName??L.name,G=g?.packageName??L.packageName,K=g?.version??L.packageVersion??L.version,q=g?.installSource??e.installSource,ve=g?g.bundle?.description??g.addons[0]?.manifest.description:L.description,J=ue({onSuccess:()=>{M.invalidateQueries({queryKey:[[`addons`]]}),M.invalidateQueries({queryKey:[[`addonPages`]]}),M.invalidateQueries({queryKey:[[`capabilities`]]})}}),ye=se({onSuccess:()=>{M.invalidateQueries({queryKey:[[`addons`]]})}}),be=ie({onSuccess:()=>{M.invalidateQueries({queryKey:[[`addons`]]}),M.invalidateQueries({queryKey:[[`addonPages`]]}),M.invalidateQueries({queryKey:[[`capabilities`]]}),M.invalidateQueries({queryKey:[[`integrations`]]})}}),Y=S({onSuccess:()=>{M.invalidateQueries({queryKey:[[`addons`]]}),M.invalidateQueries({queryKey:[[`alerts`]]})}}),X=e.health,Q=X?.phase===`failed`&&!X.inGracePeriod,Oe=Q&&X?.nextRetryAt&&!X.retrying;return i(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${Q?`border-red-500/50`:`border-border`}`,children:[Q&&X&&i(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[l(ge,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,X.retryCount,`)`]}),l(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:X.lastError?.message??`Unknown error`}),Oe&&X.nextRetryAt&&i(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(X.nextRetryAt).toLocaleTimeString()]})]}),i(`button`,{type:`button`,disabled:Y.isPending||X.retrying,onClick:e=>{e.stopPropagation(),Y.mutate({packageName:G})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:`Reset retry counter and force immediate reload`,children:[l(j,{className:`h-3 w-3 ${Y.isPending||X.retrying?`animate-spin`:``}`}),`Retry now`]})]}),i(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[l(we,{isBundle:U||!!L.components&&L.components.length>1,installSource:q,addonId:U?g.addons[0]?.manifest.id:L.id,iconPath:U?g.bundle?.icon??g.addons[0]?.manifest.icon:L.icon,color:U?g.addons[0]?.manifest.color:L.color}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`flex items-start justify-between gap-2`,children:[l(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:W}),!r&&l(Te,{version:K,availableUpdate:a,...T===void 0?{}:{selectedVersion:T},isUpdating:p,installSource:q,disabled:v,...f&&T!==void 0?{onUpdate:()=>f(T)}:{},onOpenPicker:()=>w(e=>!e),children:re&&l(Se,{packageName:G,currentVersion:K,...q?{installSource:q}:{},...a!==void 0&&T!==void 0?{selectedVersion:T,onSelect:e=>{oe(e),w(!1)}}:{},onInstall:e=>{w(!1),be.mutate({packageName:G,version:e})},onClose:()=>w(!1)})})]}),i(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[G!==W&&l(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:G}),U&&i(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[l(_e,{className:`h-3 w-3`}),g.addons.length]}),ee&&i(`span`,{className:`text-[10px] rounded-full bg-amber-500/15 text-amber-700 dark:text-amber-300 px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,title:`System package — updating restarts the hub`,children:[l(j,{className:`h-3 w-3`}),`System`]}),_!=null&&l(Ce,{item:_}),m!=null&&l(xe,{progress:m})]}),ve&&l(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:ve}),!U&&e.process&&i(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?`forked`:`in-process`}),e.process.pid!=null&&i(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:e.process.state===`crashed`||e.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.state})]})]})]}),!U&&i(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ye.mutate({addonId:L.id})},disabled:ye.isPending||v,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[l(j,{className:`h-3 w-3 ${ye.isPending?`animate-spin`:``}`}),`Restart`]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),D(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${E?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[l(V,{className:`h-3 w-3`}),`Logs`]}),!U&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),O(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${le?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[l(pe,{className:`h-3 w-3`}),`Settings`]}),l(`div`,{className:`flex-1`}),fe&&i(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await I({title:`Uninstall ${L.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&J.mutate({packageName:L.packageName})},disabled:J.isPending||v,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`,children:[l(H,{className:`h-3 w-3`}),J.isPending?`Removing...`:`Uninstall`]})]}),n&&n.nodes.length>1&&!U&&i(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),l(`div`,{className:`space-y-1`,children:n.nodes.map(e=>i(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),l(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),l(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:`outdated`}),e.status===`offline`&&l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&l(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),E&&!U&&i(`div`,{className:`border-t border-border`,children:[i(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[i(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[l(`button`,{type:`button`,onClick:()=>A(`logs`),className:`px-2 py-0.5 transition-colors ${k===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),l(`button`,{type:`button`,onClick:()=>A(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${k===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),l(`div`,{className:`flex-1`}),l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),D(!1)},className:`text-foreground-subtle hover:text-foreground`,children:l(B,{className:`h-3.5 w-3.5`})})]}),k===`logs`&&l(b,{addonId:L.id,maxHeight:`max-h-64`,showFilters:!1}),k===`events`&&l(x,{addonId:L.id,category:`addon.*`,maxHeight:`max-h-64`})]}),U&&i(o,{children:[l(`button`,{type:`button`,onClick:()=>C(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:l(y?he:R,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),y&&l(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:g.addons.map(e=>l(De,{addon:e,agents:t,hideVersion:!0},e.manifest.id))})]}),le&&!U&&l(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>O(!1),children:i(`div`,{className:`w-full max-w-lg max-h-[80vh] rounded-xl border border-border bg-surface shadow-2xl flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[i(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[i(`div`,{className:`flex items-center gap-2`,children:[l(pe,{className:`h-4 w-4 text-primary`}),i(`h2`,{className:`text-sm font-semibold text-foreground`,children:[W,` Settings`]})]}),l(`button`,{onClick:()=>O(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:l(B,{className:`h-4 w-4`})})]}),i(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[l(me,{nodeId:`hub`,addonIds:[L.id],level:`global`}),Z(L)&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),l(h,{addonId:L.id,trpc:N.trpcClient,onOpenDevice:e=>P(`/devices/${e}`)})]}),q===`npm`&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),l(Ee,{addonId:L.id})]}),L.components&&L.components.length>0&&i(`div`,{children:[i(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,L.components.length,`)`]}),l(`div`,{className:`flex flex-wrap gap-1`,children:L.components.map(e=>l(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),t.length>=2&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),i(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[z.length===0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),z.map(e=>l(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),i(`div`,{className:`relative`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ne(e=>!e)},className:`inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors`,title:`Install on more agents`,children:[l(de,{className:`h-3 w-3`}),`Add agent`]}),te&&i(`div`,{className:`absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden`,children:[t.filter(e=>!e.isHub&&!z.includes(e.name)).map(e=>l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ne(!1)},className:`w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors`,children:e.name},e.id)),t.filter(e=>!e.isHub&&!z.includes(e.name)).length===0&&l(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),l(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:l(`button`,{type:`button`,onClick:()=>O(!1),className:`rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:`Close`})})]})})]})}n();var Q=`.tgz,.tar.gz,.zip`;function Oe({onUploadSuccess:n}){let[r,a]=c(!1),s=t(null),u=e(async e=>{a(!0);let t=new FormData;t.append(`file`,e);let r=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(`/api/addons/upload`,{method:`POST`,headers:{Authorization:`Bearer ${r}`},body:t})).json()).success&&n()}finally{a(!1)}},[n]);return i(o,{children:[l(`input`,{ref:s,type:`file`,accept:Q,onChange:e(e=>{let t=e.target.files?.[0];t&&u(t),e.target.value=``},[u]),className:`hidden`}),i(`button`,{type:`button`,onClick:()=>s.current?.click(),disabled:r,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[r?l(P,{className:`w-3.5 h-3.5 animate-spin`}):l(N,{className:`w-3.5 h-3.5`}),r?`Uploading...`:`Upload`]})]})}n();var ke=[{seconds:900,label:`15m`},{seconds:3600,label:`1h`},{seconds:21600,label:`6h`},{seconds:43200,label:`12h`},{seconds:86400,label:`24h`}],Ae=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function je(e){return e!==void 0&&Ae.has(e)}function Me(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function Ne(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function Pe(e){let t=new Map,n=[];for(let r of e){let e=r.manifest.packageName;if(!e){n.push(r);continue}let i=t.get(e);if(i)i.addons.push(r);else{let n=r.manifest.bundle,i={packageName:e,displayName:n?.displayName??r.manifest.packageDisplayName??r.manifest.name,version:r.manifest.packageVersion,addons:[r],...r.installSource===void 0?{}:{installSource:r.installSource},...n===void 0?{}:{bundle:n}};t.set(e,i)}}let r=[];for(let e of t.values())e.bundle!==void 0||e.addons.length>=2?r.push({bundle:e,representative:e.addons[0]}):r.push(e.addons[0]);return r.push(...n),r}function $(e){return`bundle`in e}function Fe({addons:n,clusterStatus:o,selectedNode:d,onRefresh:f,isRefreshing:p}){let h=s(),[_,v]=c(``),ee=r(_),[b,x]=c(!1),S=t(null);u(()=>{if(!b)return;let e=e=>{S.current&&!S.current.contains(e.target)&&x(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[b]);let{data:C}=T({nodeId:d.id}),w=a(()=>{let e=new Map;for(let t of C??[])e.set(t.name,t.latestVersion);return e},[C]),ae=a(()=>(C??[]).filter(e=>!e.isSystem).length,[C]),[oe,se]=c(()=>new Set),[E,D]=c(()=>new Map),ue=e(e=>{se(t=>new Set(t).add(e))},[]),O=e(e=>{se(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),k=e((e,t)=>{D(n=>new Map(n).set(e,t))},[]),de=e(e=>{D(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),N=m({onMutate:e=>{ue(e.name),de(e.name)},onSuccess:(e,t)=>{O(t.name);let n=e;if(n&&n.success===!1){k(t.name,n.error??`Update failed (no error message returned by server)`);return}h.invalidateQueries({queryKey:[[`addons`]]}),h.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{O(t.name),k(t.name,e instanceof Error?e.message:String(e))}}),F=ye(),I=t(new Set);u(()=>{let e=new Set;for(let[t,n]of F)ve(n)&&e.add(t);let t=[...I.current].some(t=>!e.has(t));I.current=e,t&&(h.invalidateQueries({queryKey:[[`addons`]]}),h.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[F,h]);let{data:R}=re(void 0),fe=le({onSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),B=y({onSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:V,isFetching:pe}=te({query:ee||void 0},{enabled:b}),H=ne(),{data:W}=g(void 0),me=W?.requestedAt,[he,ge]=c(null),[_e,G]=c(!1);u(()=>{if(W?.kind===`framework-bulk-update`&&W.requestedAt!==he){ge(W.requestedAt),G(!0);let e=window.setTimeout(()=>G(!1),6e3);return()=>window.clearTimeout(e)}},[me,he,W]),ce();let K=e(async()=>{let e=(C??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!d.isHub){for(let t of e)await N.mutateAsync({name:t.name,version:t.latestVersion,nodeId:d.id});return}await H.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[d.id]})}},[C,d.id,d.isHub,H,N]),q=ie({onSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`]]}),h.invalidateQueries({queryKey:[[`addonPages`]]}),h.invalidateQueries({queryKey:[[`capabilities`]]}),h.invalidateQueries({queryKey:[[`integrations`]]})}}),[J,be]=c(`type`),[xe,Se]=c(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),Y=e=>{Se(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[Ce,X]=z(),Z=Ce.get(`capability`),we=a(()=>{let e=n.filter(e=>!je(e.manifest.packageName));return d.isHub||(e=e.filter(e=>Me(e.placement,d.isHub))),Z&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Z))),e},[n,d.isHub,Z]),Te=()=>{let e=new URLSearchParams(Ce);e.delete(`capability`),X(e,{replace:!0})},Ee=xe===`flat`?we:Pe(we),Q=a(()=>{let e=[...Ee];switch(J){case`type`:e.sort((e,t)=>{let n=+!$(e),r=+!$(t);if(n!==r)return n-r;let i=$(e)?e.bundle.displayName:e.manifest.name,a=$(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=$(e)?e.bundle.displayName:e.manifest.name,r=$(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=$(e)?e.bundle.installSource??``:e.installSource??``,r=$(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[Ee,J]);return i(`div`,{className:`space-y-4`,children:[[...E.entries()].map(([e,t])=>l(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:i(`div`,{className:`flex items-start justify-between gap-3`,children:[i(`div`,{className:`space-y-0.5`,children:[i(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),l(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),l(`button`,{type:`button`,onClick:()=>de(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),i(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),i(`select`,{value:J,onChange:e=>be(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[l(`option`,{value:`type`,children:`Bundles first`}),l(`option`,{value:`name`,children:`Name`}),l(`option`,{value:`source`,children:`Install source`})]})]}),i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),l(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>l(`button`,{type:`button`,onClick:()=>Y(e),className:`px-2.5 py-1.5 transition-colors capitalize ${xe===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?`Group multi-addon packages into a bundle card`:`Show every addon as its own card`,children:e},e))})]}),d.isHub&&i(`div`,{className:`flex items-center gap-1.5`,children:[l(j,{className:`h-3 w-3 text-foreground-subtle`}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),l(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>l(`button`,{type:`button`,onClick:()=>fe.mutate({channel:e}),disabled:fe.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${R?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),d.isHub&&i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Check every:`}),l(`select`,{className:`rounded-md border border-border bg-transparent px-1.5 py-1 text-[10px] font-medium text-foreground-subtle`,value:R?.updateCheckIntervalSeconds??21600,disabled:B.isPending||R===void 0,onChange:e=>{R!==void 0&&B.mutate({channel:R.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:ke.map(e=>l(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),ae>0&&i(`button`,{type:`button`,onClick:()=>void K(),disabled:H.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[H.isPending?l(P,{className:`w-3 h-3 animate-spin`}):l(A,{className:`w-3 h-3`}),H.isPending?`Updating…`:`Update All (${ae})`]}),i(`button`,{type:`button`,onClick:f,disabled:p||H.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[l(j,{className:`w-3 h-3 ${p?`animate-spin`:``}`}),`Refresh`]})]}),i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:S,children:[l(M,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),l(`input`,{type:`text`,value:_,onChange:e=>{v(e.target.value),x(!0)},onFocus:()=>x(!0),placeholder:`Search addons on npm...`,disabled:H.isPending,className:`w-full rounded-lg border border-border bg-background pl-9 pr-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`}),pe&&l(P,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),b&&V&&V.length>0&&i(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,children:[V.length>0&&i(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,V.length,`)`]}),V&&V.length>0&&l(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:V.map(e=>i(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[l(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[l(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),l(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&l(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?i(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md border border-emerald-500/30 bg-emerald-500/10 text-emerald-400 shrink-0`,children:[l(U,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):i(`button`,{type:`button`,onClick:()=>q.mutate({packageName:e.name}),disabled:q.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[q.isPending?l(P,{className:`h-3 w-3 animate-spin`}):l(A,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),l(Oe,{onUploadSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`]]}),f()}})]}),Z&&i(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[l(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),l(`span`,{className:`font-mono text-primary font-semibold`,children:Z}),l(`button`,{type:`button`,onClick:Te,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),_e&&i(`div`,{className:`fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm max-w-sm pointer-events-auto`,children:[l(L,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),i(`div`,{children:[l(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),l(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),we.length===0&&l(`div`,{className:`text-xs text-foreground-subtle`,children:n.length===0?`No addons installed`:Z?`No installed addons declare the "${Z}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${d.name} (placement filter active)`}),l(`div`,{className:`space-y-2`,children:Q.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=w.get(t),r=$(e)?e.representative:e,i=n?e=>N.mutate({name:t,version:e,nodeId:d.id}):void 0,a=F.get(t)??null,s=a!==null&&ve(a);return l(De,{addon:r,clusterStatus:o?.[r.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,isUpdating:oe.has(t)||s,jobProgress:a,onUpdate:i,disabledByBulk:H.isPending},$(e)?t:e.manifest.id)})})]})}function Ie(){let e=s(),{data:n,isLoading:r,isError:o}=_(),{data:d}=ee(void 0),{data:p}=w(void 0,{refetchInterval:1e4}),m=a(()=>{let e=new Map;e.set(`hub`,{id:`hub`,name:`Hub`,isHub:!0});for(let t of p??[]){let n=String(t.id??``);n&&e.set(n,{id:n,name:String(t.name??n),isHub:!!t.isHub})}return[...e.values()]},[p]),[h,g]=c(`hub`),v=m.find(e=>e.id===h)??m[0],y=ae(),b=f(),x=y.isPending||b.isPending,S=async()=>{await y.mutateAsync({nodeId:h}),await b.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},C=t(y);C.current=y,u(()=>{C.current.mutate({nodeId:`hub`})},[]);let te=(n??[]).map(Ne).filter(e=>e!==null);return i(W,{children:[i(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[l(oe,{selectedNodeId:h,onSelect:g}),i(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!r&&!o&&i(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[te.length,` installed`]}),i(`button`,{type:`button`,onClick:()=>void S(),disabled:x,className:`inline-flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:`Re-fetch addons + check npm for new versions`,children:[l(j,{className:`w-3 h-3 ${x?`animate-spin`:``}`}),`Check for updates`]})]})]}),!v.isHub&&i(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[`Showing only addons compatible with`,` `,l(`span`,{className:`font-medium text-foreground`,children:v.name}),` — agents only run`,` `,l(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,l(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),r&&l(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),o&&l(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!r&&!o&&l(Fe,{addons:te,clusterStatus:d,selectedNode:v,onRefresh:()=>void S(),isRefreshing:x})]})}export{Ie as AddonsPage};
@@ -1,2 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{K as f,W as p,Z as m,o as h,r as g,t as _,v}from"./player-overlays-Cce7zLVf.js";import{$ as y,$i as b,$t as x,A as S,Bt as C,D as w,Dr as T,E,Ei as D,G as O,Gr as k,H as A,Hr as ee,I as te,Ia as ne,Ir as j,J as M,Jr as N,Jt as P,K as F,L as re,Lr as I,M as L,Mo as R,Mr as ie,Nr as z,O as B,Oo as V,P as H,Pa as ae,Qr as oe,Qt as se,R as ce,Rt as U,So as le,Ta as ue,Ti as de,U as W,Ua as fe,V as G,Vr as K,Vt as pe,W as q,Wi as me,Xr as he,Yr as ge,Zi as _e,Zr as J,Zt as ve,_ as ye,a as be,an as xe,at as Se,b as Ce,c as we,ct as Te,d as Ee,dt as De,ea as Oe,eo as ke,et as Ae,ft as je,gr as Me,gt as Ne,hr as Pe,i as Fe,jn as Ie,k as Le,l as Re,ln as ze,lt as Be,mt as Ve,o as He,on as Ue,ot as We,pt as Ge,qn as Ke,qr as qe,r as Je,s as Ye,sn as Xe,so as Ze,to as Qe,u as $e,ut as et,v as tt,vi as nt,wi as rt,wr as it,y as at,z as ot,za as st,zr as ct,zt as lt}from"./src-CLcW_gk2.js";import{Ft as ut,Nt as dt,Pt as ft,a as pt,dt as mt,i as ht,pt as Y}from"./src-BQU93IBQ.js";import{t as gt}from"./CapabilityBadges-BsNvOYxI.js";import{n as _t,t as vt}from"./bell-ring-BOKJStq_.js";import{t as yt}from"./boxes-BvnEYalC.js";import{t as bt}from"./ProviderIcon-BRIZHtNP.js";import{c as xt,d as St,n as Ct,s as wt,u as Tt}from"./NodeInferenceDevices-kA005bIs.js";import{n as Et}from"./FormBuilder-BDA9-uL2.js";import{t as Dt}from"./pencil-CCigTGBs.js";import{t as Ot}from"./power-CFTIVgET.js";import{t as kt}from"./refresh-cw-7BWEDRql.js";import{t as At}from"./rotate-ccw-CvT7yFgt.js";import{t as jt}from"./rotate-cw-CHBtKezc.js";import{t as Mt}from"./server-MPW5E9Je.js";import{t as Nt}from"./wifi-C6eU8xw2.js";import{C as Pt,G as Ft,J as It,K as X,M as Lt,N as Rt,U as zt,V as Bt,X as Vt,Y as Ht,a as Ut,b as Wt,c as Gt,d as Kt,g as qt,i as Jt,m as Yt,s as Xt,t as Zt,y as Qt,z as $t}from"./index-BVmc_EOb.js";import"./useEventInvalidation-B1u2ACO8.js";import{t as en}from"./StatusBadge-CeptlsPG.js";import{i as tn,n as nn,r as rn,t as an}from"./DeviceAggregateSection-CmeOZSZb.js";var on=X(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),sn=X(`disc`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),cn=X(`ear`,[[`path`,{d:`M6 8.5a6.5 6.5 0 1 1 13 0c0 6-6 6-6 10a3.5 3.5 0 1 1-7 0`,key:`1dfaln`}],[`path`,{d:`M15 8.5a2.5 2.5 0 0 0-5 0v1a2 2 0 1 1 0 4`,key:`1qnva7`}]]),ln=X(`hand`,[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]),un=X(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),dn=X(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),fn=X(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);n();var pn=[{id:`object-detection`,label:`Object detection`,costWhenOff:`No detections, tracks or detection-driven notifications for this camera.`,capName:ft},{id:`audio-analysis`,label:`Audio analysis`,costWhenOff:`No audio events (glass, alarm, speech) and no audio-driven notifications.`,capName:dt}],mn=`Recording`,hn=`Nothing new is written to disk — live still works, existing footage is kept.`;function gn(e,t){let{bindings:n,bindable:r}=t,i=n===null?void 0:n.find(t=>t.capName===e.capName&&t.kind===`wrapped`),a=r?.find(t=>t.capName===e.capName)?.wrappers[0],o=i!==void 0&&i.providerAddonId!==``?i.providerAddonId:a??null,s=n===null?null:i!==void 0;return{id:e.id,label:e.label,costWhenOff:e.costWhenOff,on:s,available:s!==null&&o!==null,capName:e.capName,wrapperAddonId:o}}function _n(e,t,n,r){let i=e.entries.filter(e=>e.capName!==t);return r?{...e,entries:[...i,{capName:t,kind:`wrapped`,providerAddonId:n}]}:{...e,entries:i}}function vn(e,t){let n=e.filter(e=>e.on===!1).map(e=>e.id),r=e.filter(e=>e.on===null).map(e=>e.id),i=t=>t.map(t=>e.find(e=>e.id===t)?.label??t).join(`, `),a=[];return n.length>0&&a.push(`Off: ${i(n)}`),r.length>0&&a.push(`Unknown: ${i(r)}`),{layout:t?`menu`:`inline`,offIds:n,unknownIds:r,summary:a.length===0?`All camera functions on`:a.join(` · `)}}function yn(e){let t=pn.map(t=>gn(t,e)),n={id:`recording`,label:mn,costWhenOff:hn,on:e.recordingEnabled,available:e.recordingEnabled!==null,capName:null,wrapperAddonId:null};return[...t,n]}var bn={"object-detection":qt,"audio-analysis":cn,recording:sn};function xn(e){if(typeof e!=`object`||!e)return!1;let t={...e};return typeof t.enabled==`boolean`&&Array.isArray(t.bands)}function Sn(e){if(typeof e!=`object`||!e)return!1;let t={...e};return typeof t.deviceId==`number`&&Array.isArray(t.entries)}function Cn(e){return Sn(e)?e.entries:null}function wn(e){if(!Array.isArray(e))return null;let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e={...n},r=e.capName,i=e.wrappers;typeof r!=`string`||!Array.isArray(i)||t.push({capName:r,wrappers:i.filter(e=>typeof e==`string`)})}return t}function Tn({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(!1),f=z({deviceId:t},{enabled:i}),p=K({deviceType:Y.Camera},{enabled:i}),m=V({deviceId:t},{enabled:i,retry:!1});Fe([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let h=[[`deviceManager`,`getBindings`],{input:{deviceId:t}}],g=[[`recording`,`getDeviceConfig`],{input:{deviceId:t}}],_=m.data,v=xn(_)?_:null,y=yn({bindings:Cn(f.data),bindable:wn(p.data),recordingEnabled:v===null?null:v.enabled}),b=oe({onError:(e,r)=>{let i=r.capName===y[1]?.capName?`audio-analysis`:`object-detection`;console.error(`[CameraFunctionSwitches] wrapper write failed — reverting`,{tags:{deviceId:t},meta:{capName:r.capName,error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]}),o({id:i,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]})}}),x=R({onError:e=>{console.error(`[CameraFunctionSwitches] recording write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`recording`,`getDeviceConfig`]]}),o({id:`recording`,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`recording`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]})}}),S=e(e=>{if(!e.available||e.on===null)return;let r=!e.on;if(e.id===`recording`){if(v===null)return;n.setQueryData(g,{...v,enabled:r}),x.mutate({deviceId:t,config:{...v,enabled:r}});return}let{capName:i,wrapperAddonId:a}=e;if(i===null||a===null)return;let o=n.getQueryData(h);Sn(o)&&n.setQueryData(h,_n(o,i,a,r)),b.mutate({deviceId:t,capName:i,wrapperAddonId:a,active:r})},[h,t,n,v,g,x,b]),C=vn(y,Ne()),w=e=>a?.id===e.id?a.message:null;return C.layout===`menu`?r(je,{open:l,onOpenChange:d,children:[r(Ve,{"aria-label":`Camera functions`,title:C.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${a===null?C.offIds.length>0?`border-warning/40 text-warning hover:bg-warning/10`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(Kt,{className:`h-3.5 w-3.5`}),C.offIds.length>0&&r(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:[C.offIds.length,` off`]})]}),r(Ge,{className:`left-auto right-0 mt-1 min-w-[240px] p-1`,children:[u(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Camera functions`}),u(`ul`,{className:`space-y-0.5`,children:y.map(e=>u(`li`,{children:u(En,{state:e,failure:w(e),onToggle:()=>S(e)})},e.id))})]})]}):u(`div`,{className:`flex items-center gap-1`,children:y.map(e=>u(Dn,{state:e,failure:w(e),onToggle:()=>S(e)},e.id))})}function En({state:e,failure:t,onToggle:n}){let i=bn[e.id],a=e.on===null,o=e.on===!1;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:a?`${e.label} — state unknown; the source that owns it did not answer.`:t===null?e.costWhenOff:`Last write failed: ${t}`,className:`flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-[12px] text-foreground transition-colors hover:bg-surface-hover disabled:opacity-40 disabled:cursor-not-allowed`,children:[u(i,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 ${t===null?a?`text-foreground-subtle/50`:o?`text-warning`:`text-success`:`text-danger`}`}),r(`span`,{className:`flex-1 min-w-0`,children:[u(`span`,{className:`block leading-tight`,children:e.label}),u(`span`,{className:`block mt-0.5 text-[10px] text-foreground-subtle leading-tight`,children:t===null?a?`Unknown`:e.costWhenOff:`Write failed: ${t}`})]}),u(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${a?`bg-surface-hover text-foreground-subtle/60`:o?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:a?`—`:o?`off`:`on`})]})}function Dn({state:e,failure:t,onToggle:n}){let i=bn[e.id],a=e.on===null,o=e.on===!1,s=a?`${e.label} — state unknown; the source that owns it did not answer.`:o?`${e.label} is OFF. ${e.costWhenOff}`:`${e.label} is on. Turning it off: ${e.costWhenOff}`;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:t===null?s:`${s} — last write failed: ${t}`,className:`inline-flex items-center gap-1 rounded-lg border px-1.5 sm:px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${t===null?a?`border-dashed border-border text-foreground-subtle/50`:o?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(i,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden lg:inline`,children:e.label}),o&&u(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:`off`})]})}function On({parentDeviceId:e}){let{t}=Zt(),n=It(),i=m(),{data:a,isLoading:o,isError:s}=xt(e),{data:c}=j({deviceId:e},{enabled:Number.isFinite(e)});if(o)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(a??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let d=B(c?.stableId??``,l,c?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),h=c?.name??``,g=(e,t)=>u(E,{trpc:i.trpcClient,device:{...t,name:S(t,h)},variant:`minimal`,onNavigate:p},e),_=f.some(e=>!!e.role),v=f.some(e=>!e.role),y=_&&!v?t(`device.accessories`,{defaultValue:`Accessories`}):!_&&v?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),b=f.length>0?r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[u(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:y}),u(`div`,{className:`space-y-1`,children:f.map(e=>g(e.id,e))})]}):null,x=d.disabledSection===void 0?null:u(w,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:u(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>g(e.id,e))})},d.disabledSection.title);return d.sections.length===0?x===null?b:r(`div`,{className:`space-y-2`,children:[b,x]}):r(`div`,{className:`space-y-2`,children:[d.sections.map(e=>u(w,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>g(e.id,e))},e.title)),b,x]})}function kn({deviceId:e}){let t=m(),{data:n,isLoading:r}=wt(e),{data:i,isLoading:a}=xt(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?u(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):u(`div`,{className:`flex h-full w-full flex-col`,children:u(re,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}n();function An({dev:e,busy:t,setBusy:n}){let i=e?.motionTrigger,a=f(e?.state.motionTrigger),[o,s]=c(!1);if(!i)return null;let l=a?.enabled===!0,d=a!==void 0,p=async()=>{if(t||!d)return;let e=!l;n(!0),s(!0);try{await i.setMotionTrigger({enabled:e})}finally{n(!1),s(!1)}};return r(`button`,{type:`button`,onClick:()=>{p()},disabled:t||!d,title:d?l?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":l,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${l?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[u(Ft,{className:`h-3 w-3`}),u(`span`,{children:o?l?`Disabling…`:`Enabling…`:d?l?`On motion: on`:`On motion: off`:`On motion: …`})]})}n();function Z({deviceId:e,deviceType:t,features:n}){let i=m(),a=G(t)?.HeroCard??A,o=p(i.trpcClient,e),s=f(o?.state.deviceStatus),[l,d]=c(!1),h=s!==void 0&&s.online===!1,g=h?s.lastChangedAt:null;return r(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[h?u(`div`,{className:`flex justify-center`,children:u(ot,{lastChangedAt:g})}):null,u(a,{trpc:i.trpcClient,deviceId:e,features:n}),u(`div`,{className:`flex justify-center`,children:u(An,{dev:o,busy:l,setBusy:d})})]})}function jn({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:u(W,{trpc:m().trpcClient,deviceId:e,features:t})})}function Mn({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:u(A,{trpc:m().trpcClient,deviceId:e,features:t})})}function Nn(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Pn(e){if(!e)return null;let t=Nn(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var Fn=1e3,In=60*Fn,Ln=60*In,Rn=24*Ln;function zn(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Fn?`just now`:n<In?`${String(Math.floor(n/Fn))}s ago`:n<Ln?`${String(Math.floor(n/In))}m ago`:n<Rn?`${String(Math.floor(n/Ln))}h ago`:`${String(Math.floor(n/Rn))}d ago`}n();var Bn=1500,Vn=15e3,Hn=1e3;function Un({deviceId:e}){let n=p(m().trpcClient,e)?.state.eventEmitter,i=f(n);d(()=>{if(!n)return;n.refresh();let e=setInterval(()=>{n.refresh()},Vn);return()=>{clearInterval(e)}},[n]);let a=i?.lastEvent??null,o=a?.seq??null,s=t(null),[l,h]=c(!1);d(()=>{if(o===null)return;let e=s.current;if(s.current=o,e===null||e===o)return;h(!0);let t=setTimeout(()=>{h(!1)},Bn);return()=>{clearTimeout(t)}},[o]);let[g,_]=c(()=>Date.now());d(()=>{let e=setInterval(()=>{_(Date.now())},Hn);return()=>{clearInterval(e)}},[]);let v=Pn(a),y=i?.eventTypes??[],b=i?.eventCountSinceStart??0,x=i!==void 0,S=Nn(a?.data);return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[u(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(l),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${l?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:v??`No press recorded`,children:u(l?dn:ln,{className:`h-10 w-10`})}),r(`div`,{className:`text-center`,children:[S!==null&&u(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:`Button ${String(S)}`}),u(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${v?`text-foreground`:`text-foreground-subtle`}`,children:v??(x?`No press recorded`:`Awaiting state…`)}),u(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a?zn(a.timestamp,g):`Waiting for the first event`})]}),y.length>0&&u(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:y.map(e=>u(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===a?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(b)} ${b===1?`event`:`events`} since start`})]})}function Wn({deviceName:e,deviceType:t,provider:n,isOnline:i,features:a}){return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[u(bt,{type:n,size:`lg`}),r(`div`,{children:[u(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),u(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),r(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[u(en,{status:i?`online`:`offline`}),a.length>0&&u(gt,{capabilities:a})]}),u(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}n();function Gn({deviceId:e}){let t=s(),n=Pe({deviceId:e},{refetchInterval:1e4,retry:!1}),a=Me({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),o=i(()=>Kn(n.data??[]),[n.data]);return r(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[r(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[u(qn,{label:`Discovered`,value:o.total,icon:u(Qt,{className:`h-3.5 w-3.5`})}),u(qn,{label:`Adopted`,value:o.adopted,accent:`success`}),u(qn,{label:`Available`,value:o.available,accent:o.available>0?`primary`:void 0}),r(`button`,{type:`button`,onClick:()=>{a.mutateAsync({deviceId:e}).catch(()=>{})},disabled:a.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[a.isPending?u(Pt,{className:`h-3.5 w-3.5 animate-spin`}):u(kt,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[u(Jn,{icon:u(Nt,{className:`h-3 w-3 text-emerald-500`}),label:`${o.online} online`}),u(Jn,{icon:u(Wt,{className:`h-3 w-3 text-amber-500`}),label:`${o.sleeping} sleeping`}),u(Jn,{icon:u(Ut,{className:`h-3 w-3 text-destructive`}),label:`${o.offline} offline`}),o.unknown>0?u(Jn,{icon:u(on,{className:`h-3 w-3 text-foreground-subtle`}),label:`${o.unknown} unknown`}):null]})]})}function Kn(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 qn({label:e,value:t,icon:n,accent:i}){return r(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${i===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:i===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[r(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,u(`span`,{className:`truncate`,children:e})]}),u(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function Jn({icon:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1`,children:[e,u(`span`,{children:t})]})}var Yn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:Gn,[Y.Cover]:jn,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:kn,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:Z,[Y.EventEmitter]:Un,[Y.Notifier]:Mn,[Y.Script]:Z,[Y.Automation]:Z,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function Xn(e){return Yn[e]??Wn}function Zn(e){return u(Xn(e.deviceType),{...e})}function Qn(e){return Ye(m().trpcClient,e)}n();function $n(n){let[r,i]=c(`idle`),[a,o]=c(null),s=t(null),l=t(null),u=t(null),f=t(!0),p=de(),m=rt(),h=D(),g=e(()=>{if(s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null},[]),_=e(async()=>{if(r===`idle`)return;i(`stopping`);let e=u.current;if(e&&n!==null)try{await Promise.race([h.mutateAsync({deviceId:n,sessionId:e}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(i(`idle`),o(null))},[r,n,h,g]),v=e(async()=>{if(n===null||r!==`idle`&&r!==`error`)return;o(null);let e=null,t=null,a=null;try{i(`requesting-mic`),e=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),l.current=e,i(`starting`);let r=await p.mutateAsync({deviceId:n});a=r.sessionId,u.current=a,i(`connecting`),t=new RTCPeerConnection,s.current=t,t.oniceconnectionstatechange=()=>{if(!f.current)return;let e=t.iceConnectionState;e===`connected`||e===`completed`?i(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(o(e===`failed`?`WebRTC connection failed`:null),_())};for(let n of e.getAudioTracks())t.addTrack(n,e);await t.setRemoteDescription({type:`offer`,sdp:r.sdpOffer});let c=await t.createAnswer();await t.setLocalDescription(c);let d=t.localDescription?.sdp??c.sdp??``;await m.mutateAsync({deviceId:n,sessionId:a,sdpAnswer:d})}catch(r){let c=r instanceof Error?r.message:String(r);if(console.warn(`[intercom] start failed`,r),t)try{t.close()}catch{}if(e)for(let t of e.getTracks())try{t.stop()}catch{}if(s.current=null,l.current=null,a!==null)try{await h.mutateAsync({deviceId:n,sessionId:a})}catch{}u.current=null,f.current&&(o(c),i(`error`))}},[n,r,p,m,h,_]);return d(()=>(f.current=!0,()=>{f.current=!1;let e=u.current;if(e!==null&&n!==null&&h.mutate({deviceId:n,sessionId:e}),s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null}),[n]),{state:r,error:a,start:v,stop:_,isTalking:r===`talking`}}n();var er=0;function Q(){return++er}function tr(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function nr(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 rr(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 ir(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 ar({scope:n,greeting:i,className:a}){let o=m(),[s,f]=c(()=>{let e=[];return i&&e.push({id:Q(),kind:`info`,text:i}),e.push({id:Q(),kind:`info`,text:`scope: ${tr(n)} — type help or context for available commands`}),e}),[p,h]=c(``),[g,_]=c([]),[v,y]=c(-1),b=t(null),x=t(null);d(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[s]);let S=e(()=>{b.current?.focus()},[]),C=l({mutationFn:e=>o.trpcClient.repl.execute.mutate({code:e,scope:n}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;f(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);f(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function w(e){let t=e.trim();if(t){if(t===`clear`){f([{id:Q(),kind:`info`,text:`scope: ${tr(n)}`}]),h(``);return}if(t===`help`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...nr(n).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}if(t===`context`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...ir(n).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}if(t===`examples`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...rr(n).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,t]),y(-1),f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`}]),h(``),C.mutate(t)}}function T(e){if(e.key===`Enter`){e.preventDefault(),w(p);return}if(e.key===`ArrowUp`){if(e.preventDefault(),g.length===0)return;let t=v===-1?g.length-1:Math.max(0,v-1);y(t),h(g[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),v===-1)return;let t=v+1;t>=g.length?(y(-1),h(``)):(y(t),h(g[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),f([{id:Q(),kind:`info`,text:`scope: ${tr(n)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return r(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${a??``}`,onClick:S,children:[r(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[s.map(e=>u(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&u(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),r(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[u(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),u(`input`,{ref:b,value:p,onChange:e=>h(e.target.value),onKeyDown:T,disabled:C.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function or({deviceId:e,intercomAvailable:t=!1}){let n=m(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=Qn(i?e:null),{streams:s,pipelineMetrics:c,createSession:l,sendAnswer:d,handleOffer:f,getIceServers:p,addIceCandidate:_,getIceCandidates:v,closeSession:y,getSessionState:b}=He(n.trpcClient,i?e:null),S=h(i?e:null,{width:dr}),C=$n(i&&t?e:null),w=C.state===`requesting-mic`||C.state===`starting`||C.state===`connecting`||C.state===`stopping`,T=C.isTalking||w,E=()=>{C.state===`idle`||C.state===`error`?C.start():C.state!==`stopping`&&C.stop()},D=g(),O=x(),k=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,A=D.length>0?u(o,{children:D.map(e=>u(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return u(Re,{serverUrl:r,createSession:l,sendAnswer:d,handleOffer:f,getIceServers:p,addIceCandidate:_,getIceCandidates:v,closeSession:y,getSessionState:b,...O.request?{playbackUrl:O.request.url,playbackAuthToken:k,...O.request.label?{playbackLabel:O.request.label}:{},onExitPlayback:()=>O.clear()}:{},streams:s,pipelineMetrics:c,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:S.src,...S.src?{posterUrl:S.src}:{},snapshotLoading:S.loading,onRefreshSnapshot:S.refresh,intercomAvailable:t,intercomShown:T,onIntercomToggle:E,extraOverlay:A,chromeless:!0,className:`h-full`})}function sr({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full`,children:u(M,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function cr({deviceId:e}){if(!Number.isFinite(e))return r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
2
- `);return u(ar,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function lr({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(F,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function ur({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(O,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}var dr=960;function fr({deviceId:e}){let t=s(),n=Number.isFinite(e),{data:i}=j({deviceId:e},{enabled:n}),a=typeof i?.type==`string`?i.type:`camera`;Fe([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:c,isError:l,error:d}=z({deviceId:e},{enabled:n}),{data:f}=K({deviceType:a},{enabled:!!a}),p=oe({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(c)return u(`div`,{className:`p-4`,children:u(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(l)return r(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,d instanceof Error?d.message:String(d)]});let m=new Map,h={};for(let e of f??[])h[e.capName]=e.wrappers;for(let e of o?.entries??[])m.set(e.capName,{...e,wrappers:h[e.capName]??[]});for(let e of f??[])m.has(e.capName)||m.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let g=[...m.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(g.length===0)return r(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[u(yt,{className:`h-8 w-8 opacity-40`}),u(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),u(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let _=g.filter(e=>e.kind!==`unbound`).length;return r(`div`,{className:`flex flex-col gap-3 p-1`,children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:_}),` of `,g.length,` capabilit`,g.length===1?`y`:`ies`,` bound — rows marked `,u(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),u(Ae,{columns:[{key:`capability`,header:`Capability`,render:e=>u(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>u(pr,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?u(mr,{nodeId:e.providerNodeId}):u(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return u(hr,{wrappers:t.wrappers,activeWrapperId:n,disabled:p.isPending,onPick:r=>{let i=n===r;p.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:g,rowKey:e=>e.capName,minWidthPx:720})]})}function pr({kind:e}){return e===`native`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(Mt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(St,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(un,{className:`h-3 w-3`}),`linked`]}):r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(Tt,{className:`h-3 w-3`}),`unbound`]})}function mr({nodeId:e}){return u(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function hr({wrappers:e,activeWrapperId:t,disabled:n,onPick:i}){return e.length===0?u(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let a=e===t;return r(`button`,{disabled:n,onClick:()=>i(e),title:a?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${a?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(a?$t:At,{className:`h-3 w-3`}),e]},e)})})}function gr({deviceId:e,activeSubTab:t,onSubTabChange:n}){return u(`div`,{className:`flex flex-col gap-3`,children:u(an,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}n();var _r=new Set([`package-detection`]);function vr(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 yr(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function br({deviceId:e,refreshToken:t}){let n=s(),l=m().trpcClient,[d,f]=c(null),[p,h]=c(null),[g,_]=c(null),v=ae({deviceId:e},{refetchOnMount:`always`}),y=ne({deviceId:e},{refetchOnMount:`always`}),b=fe(void 0,{refetchOnMount:`always`});Fe([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let x=_e(void 0,{refetchOnMount:`always`}),S=i(()=>{let e=new Set;for(let t of x.data??[])t.isOnline&&e.add(t.id);return e},[x.data]),w=i(()=>(b.data??[]).filter(e=>S.has(e.nodeId)).map(e=>e.nodeId),[b.data,S]),T=w[0]??``,E=ue({nodeId:T},{enabled:T!==``,refetchOnMount:`always`}),D=a({enabled:w.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,w.join(`,`),t],queryFn:async()=>{let e={};for(let t of w)try{e[t]=(await l.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),O=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},k=ke({onSuccess:O}),A=Qe({onSuccess:O}),ee=i(()=>E.data?$e(E.data):[],[E.data]),te=i(()=>{let e=b.data??[],t=S.size===0?[]:e.filter(e=>S.has(e.nodeId)),n=[];for(let e of t){let t=(D.data?.[e.nodeId]??[]).filter(e=>e.enabled&&e.available);if(t.length>=2)for(let r of t)n.push({agentNodeId:e.nodeId,engineLabel:r.format,deviceKey:r.key,deviceLabel:Ct(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[b.data,D.data,S]),j=(e,t)=>D.data?.[e]?.find(e=>e.key===t)??null,M=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=D.data?.[e.agentNodeId]??[],n=t.filter(e=>e.enabled&&e.available);return n.length>=1?n[0].key:t.find(e=>e.available)?.key??t[0]?.key??null},N=(e,t,n)=>y.data?.[e]?.[t]?.[n]??null,P=e=>{if(_r.has(e))return{kind:`zone-driven`};let t=vr(E.data??null,e)?.enabledByDefault??!0,n=v.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},F=(e,t)=>{let n=vr(E.data??null,e);if(n)return lt(n,t)},re=(e,t)=>{let n=P(e),r=n.kind===`gate`?n.effectiveOn:!1,i=vr(E.data??null,e),a=M(t),o=a===null?null:j(t.agentNodeId,a);if(!pe(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:N(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?C({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:yr(s)}},I=d&&E.data?vr(E.data,d.addonId):null,L=d?j(d.agentNodeId,d.deviceKey):null,R=L?.format??`coreml`,ie=d?yr(N(d.agentNodeId,d.deviceKey,d.addonId)):!1,z=d?F(d.addonId,L):void 0,B=i(()=>{if(!d||!L)return null;let e=L.steps?.[d.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[d,L]),V=()=>{f(null),h(null)},H=(e,t)=>{let n=M(t);n!==null&&(f({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),h(N(t.agentNodeId,n,e)))},oe=(t,n)=>{A.mutate({deviceId:e,addonId:t,enabled:n})},se=()=>{d&&k.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:p},{onSuccess:V})},ce=()=>{d&&k.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:null},{onSuccess:V})};if(b.isLoading||T!==``&&E.isLoading)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(te.length===0)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!E.data)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let le=d!==null&&I!==null&&L!==null;return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,u(`span`,{className:`font-medium text-foreground`,children:`node column`}),` shows the model that node runs; click a cell to pin a per-camera model override for that accelerator. A gated-on step with no model on a device shows a clickable `,u(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),r(`div`,{className:`rounded-md border border-sky-500/25 bg-sky-500/[0.06] px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-sky-400`,children:`Placement is dynamic.`}),` When a node has multiple inference accelerators, each session is balanced across them per-session at dispatch time — these device columns show each accelerator's effective model (override ?? device default), not a fixed assignment.`]}),u(`div`,{className:le?`md:pr-[360px]`:``,children:ee.length>0?u(Ce,{tree:ee,agents:te,gateFor:P,getCellState:re,onCellClick:H,selectedCell:d,onSetGate:oe,gateBusy:A.isPending,fallbackNodeId:g,onFallbackNodeChange:_}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(Ee,{open:le,onClose:V,title:I?.name??``,subtitle:d&&L?`${d.agentNodeId} · ${Ct(L).label} · ${L.format}`:``,footer:r(o,{children:[u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle disabled:opacity-50`,disabled:!ie||k.isPending,onClick:ce,children:`Clear override`}),u(`div`,{className:`flex-1`}),u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:V,children:`Cancel`}),u(`button`,{type:`button`,disabled:!d||!B||k.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:se,children:k.isPending?`Saving…`:`Save`})]}),children:I&&d&&B?u(U,{mode:`device`,addon:I,agentDefault:B,agentNodeId:d.agentNodeId,currentPatch:p,engineFormat:R,effectiveModelId:z,onChangePatch:h}):u(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}var xr=[{id:`object-detection`,label:`Object detection`,icon:`scan-search`},{id:`tracking`,label:`Tracking`,icon:`route`},{id:`motion`,label:`Motion`,icon:`activity`},{id:`stationary`,label:`Stationary`,icon:`square-parking`},{id:`zones`,label:`Zones`,icon:`shapes`},{id:`audio`,label:`Audio`,icon:`volume-2`},{id:`cluster`,label:`Cluster`,icon:`server`}],Sr={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,"onboard-object-detection":`object-detection`,tracking:`tracking`,"tracking-core":`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function Cr(e){return Sr[e]??`object-detection`}n();var wr=`steps`,Tr=`settings`,Er=new Set([wr,Tr]);function Dr(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Or({deviceId:t,activeSubTab:n,onSubTabChange:i}){return r(Te,{value:n&&Er.has(n)?n:wr,onValueChange:e(e=>{i?.(e)},[i]),className:`flex flex-col`,children:[r(et,{className:`flex-shrink-0`,children:[u(De,{value:wr,children:`Steps`}),u(De,{value:Tr,children:`Settings`})]}),u(Be,{value:wr,children:u(br,{deviceId:t,refreshToken:0})}),u(Be,{value:Tr,children:u(an,{deviceId:t,sectionFilter:Dr,subTabGrouping:{groupOf:e=>Cr(e.id),tabs:xr}})})]})}function $({label:e,value:t}){return r(`div`,{className:`${v} flex items-start gap-2 sm:gap-3`,children:[u(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),u(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}n();function kr({deviceId:e,initialName:n}){let i=s(),[a,o]=c(!1),[l,f]=c(n),[p,m]=c(!1),h=t(null);d(()=>{a||f(n)},[n,a]),d(()=>{a&&h.current?.focus()},[a]);let g=ge({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),i.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),_=async()=>{let t=l.trim();if(t.length===0||t===n){o(!1),f(n);return}m(!0);try{await g.mutateAsync({deviceId:e,name:t}),o(!1)}catch{}finally{m(!1)}},v=()=>{f(n),o(!1)};return a?u($,{label:`Name`,value:r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{ref:h,type:`text`,value:l,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`?_():e.key===`Escape`&&v()},disabled:p,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),u(`button`,{type:`button`,onClick:()=>void _(),disabled:p,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:u($t,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:v,disabled:p,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:u(Jt,{className:`h-3 w-3`})})]})}):u($,{label:`Name`,value:r(`div`,{className:`flex items-center gap-2 group`,children:[u(`span`,{className:`truncate`,children:n}),u(`button`,{type:`button`,onClick:()=>o(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:u(Dt,{className:`h-3.5 w-3.5`})})]})})}n();function Ar({deviceId:e,initialLocation:n}){let a=s(),[o,l]=c(!1),[f,p]=c(n??``),[m,h]=c(!1),g=t(null),{data:_}=ee(void 0,{enabled:o}),v=_??[];d(()=>{o||p(n??``)},[n,o]),d(()=>{o&&g.current?.focus()},[o]);let y=N({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),b=i(()=>{let e=f.trim().toLowerCase();return e.length===0?v:v.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[v,f]),x=f.trim().length>0&&!v.some(e=>e.toLowerCase()===f.trim().toLowerCase()),S=async t=>{let r=(t??f).trim(),i=r.length===0?null:r;if(i===(n??null)){l(!1);return}h(!0);try{await y.mutateAsync({deviceId:e,location:i}),l(!1)}catch{}finally{h(!1)}},C=()=>{p(n??``),l(!1)};return o?u($,{label:`Location`,value:r(`div`,{className:`relative`,children:[r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{ref:g,type:`text`,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`?S():e.key===`Escape`&&C()},disabled:m,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),u(`button`,{type:`button`,onClick:()=>void S(),disabled:m,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:u($t,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:C,disabled:m,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:u(Jt,{className:`h-3 w-3`})})]}),(b.length>0||x)&&r(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[b.map(e=>r(`button`,{type:`button`,onClick:()=>{p(e),S(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[u(Et,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),u(`span`,{className:`truncate`,children:e})]},e)),x&&r(`button`,{type:`button`,onClick:()=>void S(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[u(`span`,{className:`text-foreground-subtle`,children:`Create`}),r(`span`,{className:`font-medium truncate`,children:[`"`,f.trim(),`"`]})]})]})]})}):u($,{label:`Location`,value:r(`div`,{className:`flex items-center gap-2 group`,children:[n?u(`span`,{className:`truncate`,children:n}):u(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),u(`button`,{type:`button`,onClick:()=>l(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:u(Dt,{className:`h-3.5 w-3.5`})})]})})}n();function jr({deviceId:e}){let t=s(),{data:n}=wt(e),{data:i}=xt(e),[a,l]=c(null),d=he({onSuccess:()=>{l(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{l(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.Container)return null;let f=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(f.length<=1)return null;let p=ce(f,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return r(o,{children:[u($,{label:`Primary child`,value:u(te,{childrenList:f,selectedId:p===null?f[0].id:p.id,onSetPrimary:t=>d.mutate({deviceId:e,primaryChildEntityId:t}),disabled:d.isPending})}),a!==null&&u(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:a})]})}n();var Mr=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Nr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Pr(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Fr(){let e=Ue(),t=Xe(),{data:n}=j({deviceId:e??0},{enabled:e!==null}),{data:i}=z({deviceId:e??0},{enabled:e!==null}),a=n??t??null,[o,s]=c(`identity`);if(e===null||!a)return null;let l=String(a.stableId??``),d=String(a.name??``),f=String(a.type??``),p=String(a.addonId??``),m=a.features??[],h=new Set([`device-status`,`feature-probe`,`device-ops`]),g=(i?.entries??[]).filter(e=>e.kind===`native`&&!h.has(e.capName)).map(e=>e.capName),_=m.length>0?m:g,v=a.location??null,y=a.metadata??null,b=y!==null&&Object.keys(y).length>0;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[u(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),b&&r(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[u(Ir,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),u(Ir,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!b||o===`identity`)&&r(`div`,{className:`divide-y divide-border`,children:[u($,{label:`ID`,value:r(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,r(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,l,`)`]})]})}),u(kr,{deviceId:e,initialName:d}),u(Ar,{deviceId:e,initialLocation:v}),u(jr,{deviceId:e}),u($,{label:`Type`,value:f}),u($,{label:`Provider`,value:u(bt,{type:p,size:`sm`,showLabel:!0})}),u($,{label:`Capabilities`,value:_.length>0?u(gt,{capabilities:_,showLabels:!0}):u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),b&&o===`hardware`&&u(Lr,{metadata:y})]})}function Ir({active:e,onClick:t,label:n}){return u(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function Lr({metadata:e}){let t=Mr.filter(t=>t in e),n=Object.keys(e).filter(e=>!Mr.includes(e)).toSorted(),i=[...t,...n];return r(`div`,{children:[u(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),u(`div`,{className:`divide-y divide-border`,children:i.map(t=>u($,{label:Nr(t),value:u(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Pr(e[t])})},t))})]})}var Rr=`Notifications`,zr=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function Br(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Rr,on:r===null?null:i??r,available:r!==null,costWhenOff:zr}}function Vr(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}n();function Hr(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Ur({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(null),f=Br({mutedDeviceIds:Hr(b({},{enabled:i}).data),deviceId:t,pendingOn:l}),p=Oe({onError:e=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),d(null),o(e instanceof Error?e.message:String(e)),n.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{o(null),d(null),n.invalidateQueries({queryKey:[[`notificationRules`]]})}}),m=e(()=>{let e=Vr(f,t);e!==null&&(d(!e.muted),p.mutate(e))},[t,p,f]),h=f.on===null,g=f.on===!1,_=g?_t:vt;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Notifications`}),g&&u(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:`muted`})]}),r(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[r(`button`,{type:`button`,role:`switch`,"aria-label":f.label,"aria-checked":f.on===!0,disabled:!f.available||p.isPending,onClick:m,title:h?`Notification mute — state unknown; the notification centre did not answer.`:g?`Muted. ${f.costWhenOff}`:`Notifying. Muting it: ${f.costWhenOff}`,className:`inline-flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${a===null?h?`border-dashed border-border text-foreground-subtle/50`:g?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(_,{className:`h-3.5 w-3.5`}),u(`span`,{children:h?`Unknown`:g?`Muted`:`Notifying`})]}),u(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:a===null?h?`The notification centre did not answer, so this device’s mute state is unknown.`:f.costWhenOff:`Write failed: ${a}`})]})]})}n();function Wr({deviceId:e}){let[t,n]=c(null),i=it({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),r(`button`,{type:`button`,disabled:i.isPending,onClick:()=>{n(null),i.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[u(kt,{className:`h-3 w-3 ${i.isPending?`animate-spin`:``}`}),i.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}n();var Gr={icon:``,label:``,unit:``,precision:``,hidden:!1};function Kr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function qr(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function Jr(e){let t=e.precision.trim()===``?void 0:Number.parseInt(e.precision,10),n={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...t!==void 0&&Number.isFinite(t)?{precision:t}:{},...e.hidden?{hidden:!0}:{}};return Object.keys(n).length===0?null:n}function Yr({deviceId:e}){let t=m(),n=s(),{data:a}=j({deviceId:e},{enabled:e>0}),o=typeof a?.role==`string`?a.role:null,l=o===null?void 0:q[o],d=l?.kind===`numeric`,f=Je(t.trpcClient,e,o??``),p=l?.kind===`numeric`?l.canonicalUnit:void 0,h=qr(f)??p,g=h===void 0?void 0:ht(h),_=i(()=>g===void 0?[]:pt(g),[g]),[v,y]=c(null),b=v??Kr(a?.display),x=qe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:S}=ct({},{staleTime:6e4}),C=J({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(a===void 0||o===null)return null;let w=e=>{y({...b,...e})},T=()=>{x.mutate({deviceId:e,display:Jr(b)})},E=()=>{y(Gr),x.mutate({deviceId:e,display:null})},D=()=>{let e={...b.icon===``?{}:{icon:b.icon},...b.unit===``?{}:{unit:b.unit},...b.precision.trim()!==``&&Number.isFinite(Number.parseInt(b.precision,10))?{precision:Number.parseInt(b.precision,10)}:{}},t={...S?.defaults,[o]:e};C.mutate({defaults:t})},O=H(o).label,k=Object.keys(L);return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[u(`div`,{className:`border-b border-border px-4 py-2`,children:u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Display`})}),r(`div`,{className:`p-4 space-y-3`,children:[r(`label`,{className:`block`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Icon`}),r(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:b.icon,onChange:e=>w({icon:e.target.value}),children:[r(`option`,{value:``,children:[`Default (`,O,`)`]}),k.map(e=>u(`option`,{value:e,children:e},e))]})]}),r(`label`,{className:`block`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Label`}),u(`input`,{type:`text`,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:O,value:b.label,onChange:e=>w({label:e.target.value})})]}),d&&r(`div`,{className:`grid grid-cols-2 gap-3`,children:[r(`label`,{className:`block`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Unit`}),r(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:b.unit,onChange:e=>w({unit:e.target.value}),disabled:_.length===0,children:[r(`option`,{value:``,children:[`Source`,h?` (${h})`:``]}),_.map(e=>u(`option`,{value:e,children:e},e))]})]}),r(`label`,{className:`block`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Precision`}),u(`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:b.precision,onChange:e=>w({precision:e.target.value})})]})]}),r(`label`,{className:`flex items-center gap-2`,children:[u(`input`,{type:`checkbox`,checked:b.hidden,onChange:e=>w({hidden:e.target.checked})}),u(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),r(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[u(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-sm font-medium text-primary-foreground disabled:opacity-50`,onClick:T,disabled:x.isPending,children:`Save`}),u(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:E,disabled:x.isPending,children:`Reset`}),r(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:D,disabled:C.isPending,title:`Apply this unit / precision / icon as the default for every ${O} sensor`,children:[`Set as default for all `,O,` sensors`]})]})]})]})}function Xr(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Zr({device:e}){let t=It(),n=typeof e.id==`number`?e.id:null,i=String(e.type??``),a=i===Y.Camera,o=i===Y.Hub,s=typeof e.role==`string`&&e.role.length>0,c=e.features??[],l=c.includes(mt.Resyncable),{data:d}=me({deviceId:n??0},{enabled:n!==null&&a,refetchInterval:5e3}),f=d?.streams??{},p=Object.entries(f),m=c.includes(mt.DoorbellButton),h=be(m?{deviceId:n??void 0,historyLimit:10}:void 0),g=h.latest?Date.now()-h.latest.timestamp<3e4:!1;return r(`div`,{className:`space-y-5`,children:[o&&n!==null&&u(at,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),l&&n!==null&&u(Wr,{deviceId:n}),n!==null&&u(Ur,{deviceId:n}),a&&n!==null&&u(P,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),m&&u(tt,{history:h.history,latestIsFresh:g}),a&&n!==null&&u(P,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),a&&p.length>0&&r(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[u(`div`,{className:`border-b border-border px-4 py-2`,children:u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),u(`div`,{className:`divide-y divide-border`,children:p.map(([e,t])=>r(`div`,{className:`px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[u(Nt,{className:`h-3 w-3 text-foreground-subtle`}),u(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),r(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[u(Qr,{label:`Nominal`,value:Xr(t.nominalBitrateKbps??0)}),u(Qr,{label:`Observed`,value:Xr(t.observedBitrateKbps??0)}),u(Qr,{label:`Peak`,value:Xr(t.peakBitrateKbps??0)}),u(Qr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),u(Fr,{}),s&&n!==null&&u(Yr,{deviceId:n})]})}function Qr({label:e,value:t,warning:n}){return r(`div`,{children:[u(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),u(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}n();var $r=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0}];function 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:Yt,label:`Logs`},{id:`repl`,icon:Gt,label:`REPL`},{id:`events`,icon:zt,label:`Events`},{id:`state`,icon:Lt,label:`State`}];function ni(){let n=Ht(),a=Number(n.deviceId),l=Number.isFinite(a),d=It(),f=s(),h=ze(),g=m(),[v,y]=Vt(),b=v.get(`tab`)??`overview`,x=v.get(`sub`),[S,C]=c(`logs`),w=`device-detail.left-col-width-px`,[E,D]=c(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(w),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),O=t(E);O.current=E;function A(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??E??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{D(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=O.current;if(e!==null)try{window.localStorage.setItem(w,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:ee,isLoading:te,isError:ne}=j({deviceId:a},{enabled:l,refetchInterval:5e3,retry:1}),{data:M}=I({deviceId:a},{enabled:l}),N=i(()=>{let e=M?.settings?.sections??[],t=M?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(tn)&&r.add(nn),[...r].map(e=>e===`export`?{id:e,label:rn,isAddonContrib:!0}:{id:e,label:ut[e]?.label??e,isAddonContrib:!0})},[M]),P=ee,F=String(P?.name??n.deviceId??`Device`),re=P?.online===!0,L=re?`online`:`offline`,R=String(P?.addonId??`rtsp`),z=P?.features??[],B=P?.type,V=B===Y.Camera,{data:H}=xt(l?a:0),ae=B===Y.Container,oe=i(()=>(H??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[H]),U=i(()=>ae?ce(oe,typeof P?.linkDeviceId==`number`?P.linkDeviceId:null,typeof P?.primaryChildEntityId==`string`?P.primaryChildEntityId:null)?.id??null:null,[ae,oe,P?.linkDeviceId,P?.primaryChildEntityId]),{data:ue}=I({deviceId:U??0},{enabled:U!==null}),de=i(()=>{if(U===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:ut[e]?.label??e,isAddonContrib:!0,childDeviceId:U}))},[U,ue]),W=typeof P?.parentDeviceId==`number`?P.parentDeviceId:null,{data:fe}=j({deviceId:W??0},{enabled:W!==null}),G=Ne(),K=P?.disabled!==!0,pe=i(()=>{let e=new Set,t=[];for(let n of[...ei(B),...N,...de])e.has(n.id)||(e.add(n.id),t.push(n));return t},[B,N,de]),q=i(()=>pe.some(e=>e.id===b)?b:`overview`,[pe,b]),me=e(e=>{y(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[y]),he=e(e=>{y(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[y]),ge=(H??[]).length>0,_e=i(()=>ti.filter(({featureGate:e})=>!e||z.includes(e)),[z]),{data:J}=nt({addonId:R},{enabled:!!R&&R!==`rtsp`}),be=k({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),d(J?.id?`/integrations/${J.id}`:`/integrations`)}}),Ce=ie({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Te=T({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=le(),De=Ie({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Oe=z.includes(mt.Rebootable),ke=z.includes(mt.BatteryOperated),Ae=Le(g.trpcClient,ke&&l?a:null),[je,Me]=c(!1),Pe=p(g.trpcClient,l?a:null),Fe=async()=>{if(!(je||!Pe)){Me(!0);try{await Pe.snapshot?.invalidateCache({});let e=await Pe.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=F.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{Me(!1)}}},Re=Ce.isPending||Te.isPending,{data:Be}=st({deviceId:a},{enabled:l,refetchInterval:1e4}),Ve=Be?.agentNodeId??null,He=typeof Ve==`string`&&Ve.length>0&&!Ve.startsWith(`addon:`)?Ve:void 0,{data:Ue}=Ze({deviceId:a,...He?{nodeId:He}:{}},{enabled:l,refetchInterval:3e3,retry:!1}),{data:Ge}=Ke({deviceId:a},{enabled:l,refetchInterval:3e3,retry:!1}),qe=Ge?.level?.dbfs??null;function Je(){if(!l)return null;switch(q){case`overview`:return u(Zr,{device:P??{}});case`config`:return u(gr,{deviceId:a,activeSubTab:x,onSubTabChange:he});case`detection-pipeline`:return u(Or,{deviceId:a,activeSubTab:x,onSubTabChange:he});case`bindings`:return u(fr,{deviceId:a});default:{let e=q,t=N.some(t=>t.id===e),n=de.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??a;if(e===`export`)return u(an,{deviceId:a,sectionFilter:tn,activeSubTab:x,onSubTabChange:he});let i=u(an,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:x,onSubTabChange:he});return n!==void 0&&r!==a?u(xe,{deviceId:r,children:i}):i}}}return l?te?r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[u(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),u(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),u(`div`,{className:`flex-1 p-6`,children:u(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):ne||!ee?r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),r(`p`,{className:`text-xs`,children:[`No device with ID`,` `,r(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,a]})]}),u(`button`,{onClick:()=>d(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):r(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[u(`div`,{className:`mb-2`,children:u(Se,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:J?.name??R,onClick:()=>J?.id&&d(`/integrations/${J.id}`)},{label:F}]})}),r(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[u(bt,{type:R,size:`lg`}),r(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:F}),u(en,{status:L}),ke&&u(We,{status:Ae,variant:`full`})]}),W!==null&&fe&&r(`button`,{type:`button`,onClick:()=>d(`/devices/${W}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${fe.name}`,children:[u(`span`,{children:`↑`}),u(`span`,{className:`truncate`,children:String(fe.name??`Device #${W}`)})]}),u(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:z.length>0&&u(gt,{capabilities:z})})]}),Ue&&u(`div`,{className:`hidden lg:flex`,children:u(ri,{metrics:Ue,dbfs:qe})}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[r(`button`,{onClick:async()=>{K?await h({title:`Disable "${F}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Te.mutate({deviceId:a}):Ce.mutate({deviceId:a})},disabled:Re,title:K?`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 ${K?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[u(Ot,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:Re?`Updating…`:K?`Enabled`:`Disabled`})]}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),V&&r(o,{children:[u(Tn,{deviceId:a}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),u(ye,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:Bt,disabled:je,onClick:()=>{Fe()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:jt,hidden:!Oe,disabled:Ee.isPending,danger:!0,onClick:async()=>{await h({title:`Reboot "${F}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Ee.mutate({deviceId:a})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${J?.name??R}.`,icon:kt,disabled:De.isPending,danger:!0,onClick:async()=>{await h({title:`Restart "${J?.name??R}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${F}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&De.mutate({addonId:R})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Xt,separatorBefore:!0,disabled:be.isPending,danger:!0,onClick:async()=>{await h({title:`Delete "${F}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&be.mutate({deviceId:a})}}]})]})]})]}),u(xe,{deviceId:a,device:P??void 0,children:u(se,{children:u(ve,{children:u(_,{children:u(we,{children:r(`main`,{className:G?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[r(`div`,{className:G?`flex flex-col bg-surface`:`${E===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!G&&E!==null?{width:`${String(E)}px`}:void 0,children:[u(`div`,{className:V?`flex-shrink-0 border-b border-border-subtle bg-black`:G?`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:V?u(or,{deviceId:a,intercomAvailable:z.includes(mt.TwoWayAudio)}):u(Zn,{deviceId:a,deviceName:F,deviceType:B??`unknown`,provider:R,isOnline:re,features:z})}),r(`div`,{className:G?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:u(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:_e.map(({id:e,label:t,icon:n})=>r(`button`,{onClick:()=>C(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${S===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(n,{className:`h-3 w-3`}),t]},e))})}),r(`div`,{className:G?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[S===`logs`&&u(sr,{deviceId:a,containerDeviceId:B===`container`?a:void 0}),S===`repl`&&u(cr,{deviceId:a}),S===`events`&&u(lr,{deviceId:a}),S===`state`&&u(ur,{deviceId:a})]})]})]}),!G&&u(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:A,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:u(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),r(`div`,{className:G?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:u(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:pe.map(e=>{let t=q===e.id;return r(`button`,{onClick:()=>me(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&u(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),r(`div`,{className:G?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[q===`overview`&&ge&&u(On,{parentDeviceId:a}),Je()]})]})]})})})})})})]}):r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),r(`p`,{className:`text-xs`,children:[`The URL segment`,` `,u(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:n.deviceId}),` `,`is not a number.`]}),u(`button`,{onClick:()=>d(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function ri({metrics:e,dbfs:t}){let n=y(e.phase??`idle`);return r(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[u(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),u(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),u(`div`,{className:`h-3 w-px bg-border`}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(Ft,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),u(`span`,{children:`fps`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(Rt,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),u(`span`,{children:`ms`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[u(fn,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),u(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&r(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{ni as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,T as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$ as d,Aa as f,As as p,B as m,Ba as h,Bt as g,Ca as _,Da as v,Ea as y,Fa as b,Ga as x,Ht as S,It as C,J as w,Ja as T,Jt as E,Ma as D,Na as O,Oa as k,Os as A,Qa as j,Ra as M,Rt as N,Sa as P,Ta as ee,Ua as F,Va as I,Vt as L,Wa as R,Xa as z,Ya as B,Za as te,Zi as V,ao as H,b as ne,co as re,d as ie,gn as ae,h as oe,hn as se,i as ce,io as le,ja as ue,js as U,ka as de,ks as fe,ln as pe,oo as me,qa as he,ro as ge,u as _e,vn as ve,wa as ye,zt as be}from"./src-CLcW_gk2.js";import{It as xe,Lt as Se,f as Ce,m as we,p as Te,yt as Ee}from"./src-BQU93IBQ.js";import{a as De,d as Oe,i as ke,l as Ae,n as W,o as je,r as Me,t as Ne,u as Pe}from"./NodeInferenceDevices-kA005bIs.js";import{t as Fe}from"./download-D0TL4kvK.js";import{t as Ie}from"./hard-drive-E6KB7P74.js";import{n as Le,t as Re}from"./video-CDs4hw5_.js";import{t as ze}from"./pencil-CCigTGBs.js";import{t as Be}from"./plus-CkMMGkZS.js";import{t as Ve}from"./radio-DH4YapvY.js";import{t as He}from"./refresh-cw-7BWEDRql.js";import{t as Ue}from"./search-LiVSlZYd.js";import{t as We}from"./server-MPW5E9Je.js";import{t as Ge}from"./square-check-big-KUDADp7C.js";import{t as Ke}from"./square-BGhxv6lU.js";import{t as qe}from"./zap-CosjZI2Q.js";import{C as G,E as Je,F as Ye,I as Xe,K as Ze,N as K,O as Qe,P as $e,R as et,X as tt,i as nt,o as rt,s as it,z as at}from"./index-BVmc_EOb.js";import{t as ot}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-B1u2ACO8.js";import{r as st,t as ct}from"./build-cluster-graph-BVmcPlKM.js";import{n as lt}from"./format-size-CO9d3C3-.js";import{t as ut}from"./NodeAddonsSettingsPanel-iynDrGDY.js";var dt=Ze(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),ft=Ze(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),pt=Ze(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);n();function mt(e){return e}function ht(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function gt(e,t){return typeof e==`boolean`?e:mt(t)}function _t(e,t){return{pipeline:gt(ht(e,`detect`),t),audio:gt(ht(e,`audio`),t),ingest:gt(ht(e,`ingest`),t)}}function vt(e,t,n){let r=e?.find(e=>e.nodeId===t);return _t(r?.settings,n)}function yt({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:i}=V(void 0),{data:a}=h(void 0),{data:s}=F(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let u=i??[],d=u.filter(e=>e.isOnline).length,f=u.filter(e=>!e.isOnline).length;return r(`div`,{className:`flex flex-col h-full`,children:[r(`button`,{type:`button`,onClick:()=>t(Mr),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[l(Je,{className:`h-4 w-4 flex-shrink-0`}),r(`div`,{className:`min-w-0 flex-1`,children:[l(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),l(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),l(`div`,{className:`flex-1 overflow-y-auto`,children:u.map(n=>{let i=e===n.id,a=c.get(n.id)??0,u=n.isHub?We:K,d=vt(s,n.id,n.isHub),f=n.isOnline?null:m(st(n.lastSeen));return r(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${i?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[l(u,{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:[l(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&l(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&l(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&l(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),r(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[r(`span`,{children:[n.cpuCores,` cores`]}),l(`span`,{children:`•`}),r(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&r(o,{children:[l(`span`,{children:`•`}),r(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[l(Re,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&r(o,{children:[l(`span`,{children:`•`}),r(`span`,{className:`text-destructive`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),r(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[l(C,{variant:d.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:d.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),l(C,{variant:d.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:d.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),r(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[r(`span`,{children:[d,` online`]}),f>0&&r(`span`,{className:`text-destructive`,children:[f,` offline`]})]})]})}function bt({nodeId:e,refreshToken:t}){let{data:n}=V(void 0),i=n?.find(t=>t.id===e),a=fe(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return i?r(`div`,{className:`px-6 py-4 border-b border-border`,children:[r(`div`,{className:`flex items-center gap-2 mb-1`,children:[l(`h2`,{className:`text-base font-semibold text-foreground`,children:i.name}),i.isOnline?l(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):l(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),i.isHub&&l(`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:[l(`span`,{children:i.cpuModel??`CPU`}),l(`span`,{children:`•`}),r(`span`,{children:[i.cpuCores,` cores`]}),l(`span`,{children:`•`}),r(`span`,{children:[Math.round(i.memoryMB/1024),` GB`]}),a&&r(o,{children:[l(`span`,{children:`•`}),r(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),l(`span`,{children:`•`}),r(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),l(`span`,{children:`•`}),r(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&r(o,{children:[l(`span`,{children:`•`}),l(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):l(`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 xt({refreshToken:e,nodeId:t}){let[n,i]=c(new Map),{nodes:o}=A();U(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&i(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=O(void 0),u=a(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),d=a(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),f=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=a(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of d.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:o.length,onlineAgents:o.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[d,o]);if(t){let e=d.get(t);return r(`div`,{className:`@container/liveload`,children:[l(`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:[l(q,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),l(q,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),l(q,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),l(q,{label:`Queue`,value:e?String(e.queueDepth):`—`}),l(q,{label:`Audio`,value:String(u.get(t)??`—`)})]})]})}let m=[...d.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return r(`div`,{className:`@container/liveload`,children:[l(`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:[l(q,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),l(q,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),l(q,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),l(q,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),l(q,{label:`Queue depth`,value:String(p.queueDepth)})]}),l(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:r(`table`,{className:`w-full text-xs min-w-[480px]`,children:[l(`thead`,{className:`bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[l(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),l(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),l(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),l(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),l(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),l(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),r(`tbody`,{children:[m.map(([e,t])=>r(`tr`,{className:`border-t border-border`,children:[l(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),l(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),l(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),l(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),l(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),l(`td`,{className:`px-3 py-2 text-right text-foreground`,children:u.get(e)??`—`})]},e)),m.length===0&&l(`tr`,{children:l(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function q({label:e,value:t}){return r(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[l(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),l(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}n();var St={active:!1,pinned:!1,nodeId:null,reason:``},Ct=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],wt={pipeline:K,decoder:Qe,audio:Le},Tt={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function Et({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let d=s(),[p,m]=c(null),[g,_]=c(null),[v,y]=c(new Map);ce([`pipelineOrchestrator`,`getPipelineAssignments`],Ct),ce([`pipelineOrchestrator`,`getAudioAssignments`],Ct),ce([`pipelineOrchestrator`,`getCameraStatuses`],Ct);let{data:x}=h(void 0),{data:S}=D(void 0),{data:C}=b({},{enabled:e===`agent`}),{nodes:w}=A(),{data:T}=Ae();U(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&y(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),u(()=>{if(v.size===0)return;let e=setInterval(()=>{y(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[v.size]);let O=a(()=>{let e=new Map;for(let t of T??[])e.set(t.id,t.name);return e},[T]),k=a(()=>{if(e===`agent`){let e=[];for(let n of C??[]){let r=n.assignment,i=(e,n,r)=>({active:e!==null&&e===t,pinned:n,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:n.deviceId,deviceName:O.get(n.deviceId)??`Device ${n.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:O.get(e)??`Device ${e}`,pipeline:St,decoder:St,audio:St};return n.set(e,r),r};for(let i of x??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let e of S??[]){let t=r(e.deviceId);n.set(e.deviceId,{...t,audio:{active:!0,pinned:e.pinned,nodeId:e.nodeId,reason:`capacity`}})}let i=[...n.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[x,S,C,O,e,t]),j=a(()=>(w??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[w]),M=()=>{d.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),d.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),d.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},N=f({onSuccess:M}),P=H({onSuccess:M}),ee=de({onSuccess:M}),F=le({onSuccess:M}),I=(e,t,n)=>{t===`pipeline`?N.mutate({deviceId:e,agentNodeId:n}):ee.mutate({deviceId:e,nodeId:n}),m(null)},L=(e,t)=>{t===`pipeline`?P.mutate({deviceId:e}):F.mutate({deviceId:e}),m(null)};return l(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:r(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[l(`thead`,{className:`bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&l(`th`,{className:`w-10`}),l(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?r(o,{children:[l(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),l(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):r(o,{children:[l(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),l(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),l(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),l(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),r(`tbody`,{children:[k.map(t=>{let a=v.get(t.deviceId),s=g===t.deviceId;return r(i.Fragment,{children:[r(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&l(`td`,{className:`px-2 py-2 align-middle`,children:l(`button`,{type:`button`,onClick:()=>_(s?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":s?`Collapse broker details`:`Expand broker details`,children:l(s?et:Xe,{className:`h-3.5 w-3.5`})})}),r(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[l(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),r(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?r(o,{children:[l(`td`,{className:`px-3 py-2 align-middle`,children:l(Ot,{state:t.pipeline,onlineNodes:j,pending:N.isPending||P.isPending,onChange:e=>{e===`auto`?L(t.deviceId,`pipeline`):I(t.deviceId,`pipeline`,e)}})}),l(`td`,{className:`px-3 py-2 align-middle`,children:l(kt,{state:t.pipeline,deviceId:t.deviceId})})]}):r(o,{children:[l(jt,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:j,isMenuOpen:p?.deviceId===t.deviceId&&p.role===`pipeline`,onToggleMenu:()=>m(p?.deviceId===t.deviceId&&p.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>m(null),onMove:e=>I(t.deviceId,`pipeline`,e),onUnpin:()=>L(t.deviceId,`pipeline`)}),l(jt,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:j,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),l(jt,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:j,isMenuOpen:p?.deviceId===t.deviceId&&p.role===`audio`,onToggleMenu:()=>m(p?.deviceId===t.deviceId&&p.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>m(null),onMove:e=>I(t.deviceId,`audio`,e),onUnpin:()=>L(t.deviceId,`audio`)})]}),l(`td`,{className:`px-3 py-2 align-middle`,children:l(Ft,{snap:a})})]}),s&&!n&&r(`tr`,{className:`bg-surface/50`,children:[l(`td`,{}),r(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&l(Dt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),l(E,{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)}),k.length===0&&l(`tr`,{children:l(`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 Dt({deviceId:e,nodeId:t}){let n=s(),{data:i}=M({nodeId:t}),{data:a}=I({deviceId:e}),o=ge({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),c=i?.devices??[],u=a?.deviceKey??`auto`,d=u!==`auto`&&!c.some(e=>e.key===u);return r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[l(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),r(`select`,{value:u,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[l(`option`,{value:`auto`,children:`Auto (balanced)`}),d&&r(`option`,{value:u,children:[`Pin → `,u,` (not on this node)`]}),c.map(e=>r(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),o.isPending&&l(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function Ot({state:e,onlineNodes:t,pending:n,onChange:i}){let a=e.pinned&&e.nodeId?e.nodeId:`auto`,o=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return r(`select`,{value:a,disabled:n,"aria-label":`Pipeline placement pin`,onChange:e=>i(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[l(`option`,{value:`auto`,children:`Auto`}),o.map(e=>r(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function kt({state:e,deviceId:t}){if(!e.active||!e.nodeId)return l(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let n=e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`;return r(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[l(`span`,{className:`font-mono text-[11px] text-foreground truncate`,title:e.nodeId,children:e.nodeId}),l(`span`,{className:`truncate ${e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:n,children:n}),l(At,{deviceId:t,nodeId:e.nodeId})]})}function At({deviceId:e,nodeId:t}){let n=s(),{data:i}=I({deviceId:e},{refetchOnMount:`always`}),{data:a}=M({nodeId:t},{refetchOnMount:`always`}),o=ge({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(i===void 0||a===void 0)return l(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let c=a.devices??[],u=c.filter(e=>e.enabled),d=i.deviceKey??`auto`,f=d!==`auto`&&!u.some(e=>e.key===d),p=c.find(e=>e.key===d);return r(`select`,{value:d,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value}),className:`mt-0.5 w-full min-w-0 rounded border border-border bg-background px-1 py-0.5 text-[10px] text-foreground disabled:opacity-50`,children:[l(`option`,{value:`auto`,children:`Auto (balanced)`}),f&&r(`option`,{value:d,children:[p?`${W(p).label} (${d})`:d,` (not enabled)`]}),u.map(e=>r(`option`,{value:e.key,children:[W(e).label,` · `,e.format]},e.key))]})}function jt({role:e,state:t,mode:n,onlineNodes:i,readOnly:a=!1,isMenuOpen:o,onToggleMenu:s,onCloseMenu:c,onMove:u,onUnpin:d}){let f=wt[e],p=i.filter(e=>e.id!==(t.nodeId??``)),m=!a&&(t.active||n===`cluster`)&&(p.length>0||t.pinned);return r(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[l(n===`agent`?Mt:Nt,{state:t,Icon:f}),l(`div`,{className:`ml-auto shrink-0`,children:m&&l(`button`,{type:`button`,onClick:s,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${Tt[e]} actions`,children:l(dt,{className:`h-3 w-3 text-foreground-subtle`})})})]}),o&&m&&l(It,{title:Tt[e],targets:p,pinned:t.pinned,onMove:u,onUnpin:d,onClose:c})]})}function Mt({state:e,Icon:t}){return r(`div`,{className:`flex items-center gap-1.5`,children:[l(e.active?Ge:Ke,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),l(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&l(pt,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Nt({state:e,Icon:t}){return!e.active||!e.nodeId?r(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[l(t,{className:`h-3 w-3`}),l(`span`,{className:`text-[10px] italic`,children:`—`})]}):r(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[l(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),r(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[l(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),l(`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:[l(pt,{className:`h-2.5 w-2.5`}),` manual`]}):r(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Pt=`min-h-[3.25rem]`;function Ft({snap:e}){if(!e)return l(`div`,{className:`flex items-center ${Pt}`,children:l(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:n,avgInferenceTimeMs:i,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=d(t);return r(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Pt}`,children:[r(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[l(oe,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),l(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),r(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[l(`span`,{className:`text-foreground`,children:n.toFixed(1)}),r(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),r(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[l(`span`,{className:`text-foreground`,children:i.toFixed(0)}),l(`span`,{children:` ms`}),a>0&&r(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),r(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,l(`span`,{className:`text-foreground`,children:s})]})]})}function It({title:e,targets:n,pinned:i,onMove:a,onUnpin:o,onClose:s}){let c=t(null);return u(()=>{let e=e=>{c.current?.contains(e.target)||s()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]),r(`div`,{ref:c,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[l(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),n.length>0&&l(`div`,{className:`py-1`,children:n.map(e=>r(`button`,{type:`button`,onClick:()=>a(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),i&&r(`button`,{type:`button`,onClick:o,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,e.toLowerCase()]}),n.length===0&&!i&&l(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Lt({nodeId:e,refreshToken:t}){return r(`div`,{className:`space-y-6`,children:[l(xt,{refreshToken:t,nodeId:e}),r(`div`,{children:[l(`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.`]})]}),l(Et,{mode:`agent`,nodeId:e,compact:!0})]})}n();function Rt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function zt({nodeId:e,refreshToken:t}){let n=s(),i=v({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:o}=k({nodeId:e}),c=fe(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??o??null,u=c===null;ce([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:d}=re({nodeId:e}),{values:f}=p(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),m=a(()=>f.filter(e=>e.metrics.phase===`active`).length,[f]),h=t=>{let n=d??[];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:[l(`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:[(c??[]).length,` engine(s) resident in RAM. `,(d??[]).length,` `,`camera(s) attached, `,m,` actively dispatching frames. Refreshes every 5s.`]})]}),l(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:r(`table`,{className:`w-full text-xs min-w-[640px]`,children:[l(`thead`,{className:`bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[l(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),l(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),l(`th`,{className:`text-left px-3 py-2`,children:`Models`}),l(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),l(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),l(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),l(`th`,{className:`w-20`})]})}),r(`tbody`,{children:[u&&l(`tr`,{children:l(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!u&&(c??[]).map(e=>{let t=e.kind===`warm-override`,n=e.kind===`device-pool`;return r(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:n?`bg-primary/[0.05]`:``}`,children:[l(`td`,{className:`px-3 py-2`,children:r(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:n?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[l(t?ft:n?Oe:K,{className:`h-3 w-3`}),t?`warm`:n?`pool`:`runtime`]})}),l(`td`,{className:`px-3 py-2`,children:r(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[l(qe,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),l(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?l(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):l(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>l(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),l(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),l(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?l(`span`,{className:`text-foreground-subtle`,children:Rt(e.idleMs,e.idleTtlMs)}):l(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),l(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(d??[]).length}),l(`td`,{className:`px-3 py-2 text-right`,children:n?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):r(`button`,{type:`button`,disabled:i.isPending,onClick:()=>h(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[l(it,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!u&&(c??[]).length===0&&l(`tr`,{children:l(`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:[l(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,l(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,l(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),i.isError&&r(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,i.error instanceof Error?i.error.message:`unknown`]})]})}n();var Bt=new Set(Ee);function Vt(e){return Bt.has(e)}function Ht(e,t,n){return`${e}/${t}/${n}`}function Ut(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function Wt(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 J(e){return e.format}function Gt(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 Kt({addonId:e,model:t,format:n,isActive:i,progress:a,errorMsg:o,onDownload:s,onDelete:c}){let u=t.formats[n];return u?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:[l(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${u.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:[l(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),a&&a.progress>=0&&a.progress<100&&r(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[l(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:l(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${a.progress}%`}})}),r(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(a.progress),`%`]})]})]}),l(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:lt(u.sizeMB)}),o&&r(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:o,children:[l(Ye,{className:`h-3 w-3 shrink-0`}),o]}),u.downloaded?r(`button`,{onClick:c,disabled:i,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[i?l(G,{className:`h-3 w-3 animate-spin`}):l(it,{className:`h-3 w-3`}),i?`Deleting...`:`Delete`]}):r(`button`,{onClick:s,disabled:i,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[i?l(G,{className:`h-3 w-3 animate-spin`}):l(Fe,{className:`h-3 w-3`}),i?`Downloading...`:`Download`]})]}):null}function qt({engines:e,activeEngine:t,viewEngine:n,onSelect:i}){let[a,o]=c(!1);return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>o(!a),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[l(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:[l(`span`,{className:`text-sm font-medium text-foreground`,children:Ut(n)}),J(n)===J(t)&&l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),l(`div`,{className:`text-[10px] text-foreground-subtle`,children:Wt(n)})]}),l(et,{className:`h-4 w-4 text-foreground-subtle transition-transform ${a?`rotate-180`:``}`})]}),a&&l(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let a=J(e)===J(n),s=J(e)===J(t);return r(`button`,{type:`button`,onClick:()=>{i(e),o(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${a?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[l(K,{className:`h-4 w-4 shrink-0 ${a?`text-primary`:`text-foreground-subtle`}`}),r(`div`,{className:`flex-1`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l(`span`,{className:`text-sm font-medium ${a?`text-primary`:`text-foreground`}`,children:Ut(e)}),s&&l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),l(`div`,{className:`text-[10px] text-foreground-subtle`,children:Wt(e)})]}),a&&l($e,{className:`h-4 w-4 text-primary shrink-0`})]},J(e))})})]})}function Jt({embedded:t=!1,nodeId:n}={}){let i=s(),a=n??`hub`,[u,d]=c(null),[f,p]=c(new Set),[m,h]=c(new Map),[g,v]=c(new Map),[b,x]=c(``),{data:C=[]}=ye({nodeId:a}),w=C.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:T}=y({nodeId:a}),E=T,{data:D,isLoading:O}=ee({nodeId:a}),k=_(),A=P();U(`model.download.progress`,e=>{let t=e.data,n=typeof t.modelId==`string`?t.modelId:void 0,r=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;n===void 0||r===void 0||(h(e=>{let t=new Map(e);return r===100||r===-1?t.delete(n):t.set(n,{modelId:n,progress:r,totalMB:a}),t}),r===100&&i.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let j=E??{runtime:`node`,backend:`cpu`,format:`onnx`},M=w.find(e=>e.format===u)??j,N=M.format,F=e=>e.formats[N]?.downloaded===!0,I=D?.slots??[],L=I.map(e=>({...e,addons:e.addons.map(e=>({...e,models:S(e.models,N)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),R=Gt(L,N),z=e(async(e,t,n)=>{if(!Vt(n))return;let r=Ht(e,t,n);p(e=>new Set([...e,r])),v(e=>{let t=new Map(e);return t.delete(r),t});try{await k.mutateAsync({addonId:e,modelId:t,format:n,nodeId:a}),i.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){v(t=>new Map([...t,[r,e instanceof Error?e.message:`Download failed`]]))}finally{p(e=>{let t=new Set(e);return t.delete(r),t})}},[k,i,a]),B=e(async(e,t,n)=>{if(!Vt(n))return;let r=Ht(e,t,n);p(e=>new Set([...e,r])),v(e=>{let t=new Map(e);return t.delete(r),t});try{await A.mutateAsync({addonId:e,modelId:t,format:n,nodeId:a}),i.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){v(t=>new Map([...t,[r,e instanceof Error?e.message:`Delete failed`]]))}finally{p(e=>{let t=new Set(e);return t.delete(r),t})}},[A,i,a]),te=e(e=>{d(e.format)},[]),V=b.trim()?L.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(b.toLowerCase())||t.id.toLowerCase().includes(b.toLowerCase())||e.name.toLowerCase().includes(b.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):L,H=r(o,{children:[O&&l(`div`,{className:`flex items-center justify-center py-16`,children:l(G,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!O&&I.length===0&&r(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[l(Ie,{className:`h-8 w-8 mb-3 opacity-30`}),l(`span`,{className:`text-sm`,children:`No pipeline steps available`}),l(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!O&&I.length>0&&r(o,{children:[l(qt,{engines:w,activeEngine:j,viewEngine:M,onSelect:te}),r(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[r(`span`,{children:[l(`span`,{className:`font-semibold text-foreground tabular-nums`,children:R.total}),l(`span`,{className:`ml-1`,children:`compatible models`})]}),l(`span`,{className:`text-border`,children:`|`}),r(`span`,{children:[l(`span`,{className:`font-semibold text-success tabular-nums`,children:R.downloaded}),l(`span`,{className:`ml-1`,children:`downloaded`})]}),l(`span`,{className:`text-border`,children:`|`}),r(`span`,{className:`tabular-nums`,children:[lt(R.downloadedSizeMB),l(`span`,{className:`ml-1`,children:`on disk`})]})]}),R.total>5&&r(`div`,{className:`relative`,children:[l(Ue,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),l(`input`,{type:`text`,value:b,onChange:e=>x(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`})]}),V.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+S(t.models,N).filter(F).length,0);return r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[l(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),l(`div`,{className:`flex-1 h-px bg-border`}),r(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),l(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=Ht(e.id,t.id,N);return l(Kt,{addonId:e.id,model:t,format:N,isActive:f.has(n),progress:m.get(t.id),errorMsg:g.get(n),onDownload:()=>z(e.id,t.id,N),onDelete:()=>B(e.id,t.id,N)},`${e.id}/${t.id}`)}))})]},e.id)}),V.length===0&&l(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:b.trim()?r(o,{children:[`No models matching “`,b,`”`]}):r(o,{children:[`No models available for `,Ut(M),` format`]})})]})]});return t?l(`div`,{className:`space-y-4`,children:H}):l(ot,{children:H})}function Yt({nodeId:e,refreshToken:t}){return l(Jt,{embedded:!0,nodeId:e})}var Xt=`pipeline-runner`,Zt=200;function Qt({nodeId:e}){return r(`div`,{className:`flex flex-col gap-3`,children:[r(`div`,{children:[l(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),l(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:l(w,{agentId:e,addonId:Xt,limit:Zt,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}n(),n();function $t({nodeId:e,title:t}){let{data:n}=Ae(),{data:i}=h(void 0),o=a(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),s=a(()=>{if(!e)return null;let t=new Set;for(let n of i??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,i]),[f,p]=c(new Map);U(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||p(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),u(()=>{if(f.size===0)return;let e=setInterval(()=>{p(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)},[f.size]);let m=a(()=>{let e=[];for(let t of f.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[f,s]);return m.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:[l(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:m.length})]}),l(`div`,{className:`flex flex-wrap gap-1.5`,children:m.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,n=d(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:[l(oe,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),l(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),l(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),l(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var en=`pipeline-orchestrator`;function tn(e){return Ce.find(t=>t.stepId===e)??null}function nn({title:e}){return l(`span`,{title:e??`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`,className:`ml-1 rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:`cluster-wide`})}function rn({step:e,engineFormat:t,runnableModelIds:n}){let i=s(),{data:a,isLoading:o}=ae({addonId:en}),c=ve({onSuccess:()=>{i.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),u=we(a??null)[e.stepId]??e.defaultModelId,d=n.length>0&&!n.includes(u);return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[r(`div`,{className:`flex items-center text-[11px] font-medium text-foreground`,children:[e.label,l(nn,{})]}),r(`p`,{className:`mt-1 text-[10px] leading-snug text-foreground-subtle`,children:[`Applies to every node. Changing it does not corrupt `,e.indexName,` — every vector carries the model that produced it and only matches its own — but it STRANDS it: the existing vectors stay readable and match nothing until a re-embed pass has run.`]})]}),o?l(G,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):l(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:u,disabled:c.isPending,onChange:t=>{t.target.value!==u&&c.mutate({addonId:en,patch:{[Te(e.stepId)]:t.target.value}})},children:e.options.map(t=>r(`option`,{value:t.id,children:[t.label,t.id===e.defaultModelId?` (default)`:``]},t.id))}),d&&r(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[10px] leading-snug text-amber-300`,children:[`This node's engine (`,t,`) ships no build of `,l(`b`,{children:u}),`. It will REFUSE this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`. Either pick a model with a `,t,` build, or accept that this node contributes nothing to that index.`]}),l(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Stored once, in Pipeline → Enrichment models. This editor writes that same row — there is no per-node copy of this value.`})]})}n();function an(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 on(e){if(!e)return null;let t=e.modelId!==void 0&&e.modelId!==``?e.modelId:void 0,n=e.settings&&Object.keys(e.settings).length>0?e.settings:void 0;return t===void 0&&n===void 0?null:{...t===void 0?{}:{modelId:t},...n===void 0?{}:{settings:n}}}function sn({nodeId:e,refreshToken:t}){let n=s(),[i,u]=c(null),[d,f]=c(null),[p,m]=c(``),[h,_]=c(null),v=M({nodeId:e},{refetchOnMount:`always`}),y=ee({nodeId:e},{refetchOnMount:`always`}),b=we(ae({addonId:`pipeline-orchestrator`}).data??null),x=v.data?.devices??[],C=te({onSuccess:()=>{n.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),w=a(()=>y.data?_e(y.data):[],[y.data]),T=a(()=>x.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:W(t).label})),[x,e]),E=e=>x.find(t=>t.key===e)??null,D=a(()=>x.filter(e=>e.enabled),[x]),O=D.length>=2,k=(e,t)=>L(an(y.data??null,e)?.models??[],t?.format),A=e=>{let t=E(e);return t?W(t).label:e},j=(e,t)=>D.filter(n=>n.key!==t&&k(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,P=e=>{let t=an(y.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},F=(e,t)=>{let n=an(y.data??null,e);if(n)return be(n,t)},I=(e,t)=>{let n=P(e),r=n.kind===`gate`?n.effectiveOn:!1,i=an(y.data??null,e),a=t.deviceKey===void 0?null:E(t.deviceKey),o=L(i?.models??[],a?.format),s=a?.steps?.[e];if(!o){if(!r)return{kind:`na`};let n=s?.jumpDeviceKey,i=n!==void 0&&D.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:j(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:A(i)}}let c=tn(e);return c?{kind:`enabled`,modelId:b[e]??c.defaultModelId,clusterWide:!0}:{kind:`enabled`,modelId:(i?g({catalog:i,device:a,base:s?.modelId}):void 0)??`Auto`,...s?.jumpDeviceKey!==void 0&&D.some(e=>e.key===s.jumpDeviceKey)?{jumpTo:A(s.jumpDeviceKey)}:{}}},R=i&&y.data?an(y.data,i.addonId):null,z=i?E(i.deviceKey):null,B=z?.format??`coreml`,V=i?F(i.addonId,z):void 0,H=()=>{u(null),f(null),m(``)},re=(e,t)=>{if(t.deviceKey===void 0)return;let n=E(t.deviceKey)?.steps?.[e];u({addonId:e,deviceKey:t.deviceKey});let r=n?.settings??De(x.map(e=>({key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}})),t.deviceKey,e)??{};f({enabled:!0,...n?.modelId===void 0?{}:{modelId:n.modelId},settings:r}),m(n?.jumpDeviceKey??``)},oe=()=>{if(!i)return;let t=on(d),n=p!==``&&p!==i.deviceKey?p:void 0,r=t||n!==void 0?{...t,...n===void 0?{}:{jumpDeviceKey:n}}:null,a=x.map(e=>{let t={...e.steps};return e.key===i.deviceKey&&(r?t[i.addonId]=r:delete t[i.addonId]),{key:e.key,enabled:e.key===i.deviceKey?!0:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:t}}),o=r?.settings!==void 0&&Object.keys(r.settings).length>0?je(a,i.deviceKey,i.addonId):a;C.mutate({agentNodeId:e,inferenceDevices:ke(o)},{onSuccess:H})};if(v.isLoading||y.isLoading)return l(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(x.length===0)return l(`div`,{className:`rounded-md border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`});if(!y.data)return l(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let se=i!==null&&R!==null&&z!==null;return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[`Each column is one of this node's inference accelerators. A cell shows the`,` `,l(`span`,{className:`font-medium text-foreground`,children:`base model`}),` every camera landing on that accelerator runs; click to change it. Whether a camera runs a step is set per-camera on that camera's Detection pipeline tab — there is no gate here.`]}),l(`div`,{className:se?`md:pr-[360px]`:``,children:w.length>0?l(ne,{tree:w,agents:T,gateFor:P,getCellState:I,onCellClick:re,selectedCell:i?{addonId:i.addonId,agentNodeId:e,deviceKey:i.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:h,onFallbackNodeChange:_,hideGate:!0}):l(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),l(ie,{open:se,onClose:H,title:R?.name??``,subtitle:i&&z?`${e} · ${W(z).label} · ${z.format}`:``,footer:r(o,{children:[l(`div`,{className:`flex-1`}),l(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:H,children:`Cancel`}),l(`button`,{type:`button`,disabled:!i||!d||C.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:oe,children:C.isPending?`Saving…`:`Save`})]}),children:R&&i&&tn(i.addonId)?l(rn,{step:tn(i.addonId),engineFormat:B,runnableModelIds:S(R.models??[],B).map(e=>e.id)}):R&&i&&d?r(`div`,{className:`space-y-3`,children:[O&&r(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[l(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),r(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:p,onChange:e=>m(e.target.value),children:[l(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),D.filter(e=>e.key!==i.deviceKey).map(e=>r(`option`,{value:e.key,children:[W(e).label,` · `,e.format]},e.key))]}),l(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),l(N,{mode:`agent`,addon:R,agentDefault:d,agentNodeId:e,engineFormat:B,effectiveModelId:V,onChangeAgentConfig:f})]}):l(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}n();var cn=[`pipeline-orchestrator`],ln=[`decoder`],un=!1;function dn({nodeId:e,refreshToken:t}){let n=pe(),[i,a]=c(null),[o,s]=c(null),u=(V(void 0).data??[]).find(t=>t.id===e),d=u?.name??e,f=u?.isOnline??!1,p=he({onSuccess:e=>{s(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),m=async()=>{await n({title:`Reset ${d} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(s(null),p.mutate({agentNodeId:e}))};return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[o&&l(`span`,{className:`text-emerald-400`,children:o}),p.isError&&l(`span`,{className:`text-red-400`,children:p.error instanceof Error?p.error.message:`Reset failed`}),l(`button`,{type:`button`,onClick:()=>{m()},disabled:p.isPending,className:`rounded border border-amber-500/40 bg-surface px-2 py-0.5 text-amber-300 hover:bg-surface-hover disabled:opacity-50`,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:p.isPending?`Resetting…`:`Reset to default`})]}),l($t,{nodeId:e}),l(ut,{nodeId:e,addonIds:cn,level:`global`,sectionIds:ln}),un,un,r(`div`,{children:[l(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),l(Ne,{nodeId:e,nodeName:d,isOnline:f})]}),r(`div`,{children:[l(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),l(sn,{nodeId:e,refreshToken:t})]})]})}var fn=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],pn=`decoder-nodeav`;function mn({nodeId:e,refreshToken:t}){let{data:n}=V(void 0),i=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??pn,a=[...fn,i];return r(`div`,{className:`flex flex-col h-full`,children:[l(bt,{nodeId:e,refreshToken:t}),l(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:l(ut,{nodeId:e,addonIds:a,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:l(Lt,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:l(dn,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:l(zt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:l(Yt,{nodeId:e,refreshToken:t})},{id:`logs`,label:`Logs`,order:300,content:l(Qt,{nodeId:e})}]})})]})}function hn(){return r(`div`,{className:`space-y-6`,children:[l($t,{title:`Cluster cameras`}),r(`div`,{className:`min-w-0`,children:[l(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),l(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Use the Auto | Pin control to pin a camera to a node, the inference-device select to pin it to an accelerator, or the kebab to move a role; expand the chevron for the per-camera broker drill-down. Cluster load, inference-device weights, and Rebalance live on the Balancer tab.`})]}),l(Et,{mode:`cluster`})]})}var gn=`pipeline-orchestrator`,_n=`recorder`,vn=`recordingNodeId`,yn=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],bn=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function xn(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function Sn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function Cn(e,t,n){let r=xn(e,t);return typeof r==`string`&&r.length>0?r:n}function wn(e,t,n){let r=xn(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function Tn(e,t){let n=Sn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function En(e,t){let n=Sn(e,t);return typeof n==`string`&&n.length>0?n:null}function Dn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function On(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function kn(e,t){switch(t){case`detect`:return e.pipeline}}function An(e){return e instanceof Error?e.message:`Failed to save`}function jn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function Mn({capability:e,label:t,hint:n,nodeId:i,active:a,pending:o,layout:s,onToggle:c}){let u=a?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,d=s===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,f=a?at:Pe;return r(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} capability for ${i}`,title:`${t} — ${n}`,disabled:o,onClick:()=>c(e,!a),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${u} ${d}`,children:[l(f,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),l(`span`,{children:t})]})}function Nn({node:e,emphasis:t=!1}){let n=e.isHub?We:K;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[l(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),l(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[l(`span`,{className:`truncate`,children:e.name}),e.isHub&&l(C,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&l(C,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),l(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}n();function Pn({nodeId:e,value:t,detectedHosts:n,status:i,errorMessage:a,onCommit:o}){let[s,d]=c(t??``);u(()=>{d(t??``)},[t]);let f=n[0],p=f===void 0?`auto-detect`:`auto: ${f}`,m=i===`pending`,h=s.trim(),g=h!==(t??``),_=g&&!m,v=()=>{_&&o(e,h.length>0?h:null)};return r(`div`,{className:`flex items-center gap-1.5`,children:[l(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:p,value:s,disabled:m,onChange:e=>d(e.target.value),onBlur:v,onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&d(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),r(`button`,{type:`button`,onClick:v,disabled:!_,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[m?l(G,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):l(at,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!g&&!m&&i===`success`&&l(at,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),i===`error`&&l(`span`,{title:a??`Failed to save reachable host`,children:l(Ye,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":a??`Failed to save reachable host`,role:`img`})})]})}function Fn({label:e,children:t}){return r(`div`,{className:`flex items-center justify-between gap-3`,children:[l(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function In({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:[l(Nn,{node:e,emphasis:!0}),l(`div`,{className:`grid grid-cols-2 gap-2`,children:bn.map(n=>l(Mn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:kn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),l(`div`,{className:`space-y-3 border-t border-border pt-3`,children:l(Fn,{label:`Reachable host`,children:l(Pn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function Ln(){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:[l(`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:[l(`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:[l(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),r(`span`,{className:`inline-flex items-center gap-1.5`,children:[l(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function Rn({nodes:e,actions:t}){return l(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:r(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[l(`thead`,{children:r(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[l(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),bn.map(e=>l(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),l(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),l(`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:[l(`td`,{className:`px-4 py-3 align-middle`,children:l(Nn,{node:e})}),bn.map(n=>l(`td`,{className:`px-3 py-3 text-center align-middle`,children:l(Mn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:kn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),l(`td`,{className:`px-4 py-3 align-middle`,children:l(Pn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})]},e.id))})]})})}function zn({role:e,value:t,options:n,pending:i,onChange:a}){return r(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[l(`span`,{className:`text-xs font-semibold text-foreground`,children:Dn(e)}),l(`select`,{value:t,disabled:i,onChange:t=>a(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:n.map(e=>l(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),l(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:On(e)})]})}function Bn({roleValues:e,options:t,pending:n,lowFpsEnabled:i,fpsMinThreshold:a,onRoleChange:o,onLowFpsToggle:s}){return r(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[yn.map(r=>l(zn,{role:r,value:e[r],options:t,pending:n,onChange:o},r)),r(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[l(`input`,{type:`checkbox`,checked:i,disabled:n,onChange:e=>s(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),r(`span`,{className:`flex flex-col gap-0.5`,children:[l(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),r(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,i?`${a} fps`:`disabled`]})]})]})]})}n();function Vn(){let e=s(),{nodes:t}=A(),n=F(void 0),i=ae({addonId:gn}),u=ae({addonId:_n}),d=()=>jn(e),f=B({onSuccess:d}),p=z(),m=j({onSuccess:d}),h=ve({onSuccess:d}),[g,_]=c(!1),v=a(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),y=a(()=>t.map(e=>{let t=v.get(e.id),n=_t(t,e.isHub),r=Tn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:Tn(t,`maxCameras`),reachableHost:En(t,`reachableHost`),detectedHosts:e.localIps}}),[t,v]),b=y.filter(e=>e.effective.pipeline),x={ingestNode:Cn(i.data,`ingestNode`,`hub`),recordingNode:Cn(u.data,vn,`hub`),audioNode:Cn(i.data,`audioNode`,`hub`),motionNode:Cn(i.data,`motionNode`,`hub`)},S=a(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...yn.map(e=>x[e]),...e])].filter(e=>e.length>0)},[t,x]),C=wn(i.data,`fpsMinThreshold`,0),w=C>0,T=n.isLoading||i.isLoading||u.isLoading,E=(e,t,n)=>{f.mutate({agentNodeId:e,[t]:n})},D=(e,t)=>{if(e===`recordingNode`){h.mutate({addonId:_n,patch:{[vn]:t}});return}h.mutate({addonId:gn,patch:{[e]:t}})},O=e=>{h.mutate({addonId:gn,patch:{fpsMinThreshold:e?Math.max(1,C):0}})},k=e=>m.variables?.agentNodeId===e?m.isPending?`pending`:m.isError?`error`:m.isSuccess?`success`:`idle`:`idle`,M=e=>k(e)===`error`?An(m.error):null,N=async e=>{_(!0);try{for(let t of e)await p.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{_(!1),d()}},P={capabilityPending:f.isPending,onToggleCapability:E,onCommitReachableHost:(e,t)=>m.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:k,reachableHostErrorMessage:M};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:[l(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),l(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, distribute detection weight across detect-capable nodes, and choose the singleton cluster roles.`})]}),T&&l(G,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),r(`div`,{className:`space-y-3`,children:[l(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),l(Bn,{roleValues:x,options:S,pending:h.isPending,lowFpsEnabled:w,fpsMinThreshold:C,onRoleChange:D,onLowFpsToggle:O})]}),r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[l(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),l(Ln,{})]}),y.length===0?l(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):r(o,{children:[l(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:y.map(e=>l(In,{node:e,actions:P},e.id))}),l(`div`,{className:`hidden @3xl/clustertab:block`,children:l(Rn,{nodes:y,actions:P})})]})]}),r(`div`,{className:`space-y-3`,children:[l(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),l(Me,{nodes:b,pending:g,onCommitWeights:e=>void N(e)})]}),r(`div`,{className:`space-y-3`,children:[l(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),b.length===0?l(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):l(`div`,{className:`space-y-2`,children:b.map(e=>l(Ne,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}n();var Hn=!1;function Un({refreshToken:e}){let t=s(),{data:n}=V(void 0);a(()=>ct(n??[]),[n]);let i=x({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return r(`div`,{className:`space-y-6`,children:[l(xt,{refreshToken:e}),l(Vn,{}),Hn,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:[l(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),l(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Recompute the optimal node for every assigned camera from current load + hardware affinity, and migrate the ones no longer on their best node. Pinned cameras never move.`})]}),r(`button`,{type:`button`,onClick:()=>i.mutate(void 0),disabled:i.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[l(qe,{className:`h-3.5 w-3.5`}),i.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var Wn=[`pipeline-orchestrator`];function Gn({refreshToken:e}){return l(`div`,{className:`space-y-4 max-w-3xl`,children:l(ut,{nodeId:`hub`,addonIds:Wn,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.`})})}n();function Kn({refreshToken:e}){let t=s(),{data:n,isLoading:i}=R(),[a,u]=c(null),[d,f]=c(``),[p,m]=c(``),h=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},g=me({onSuccess:()=>{u(null),h()}}),_=ue({onSuccess:h}),v=e=>{u(e.id),f(e.name),m(e.description??``)},y=()=>{u(null),f(``),m(``)},b=()=>{if(!a)return;let e=p.trim();g.mutate({id:a,name:d.trim()||`Untitled`,...e?{description:e}:{}})};if(i)return l(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let x=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return l(`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:[l(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),l(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[x.length,` template`,x.length===1?``:`s`]})]}),x.length===0?r(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[l(Be,{className:`h-6 w-6 opacity-40`}),l(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):l(`ul`,{className:`divide-y divide-border`,children:x.map(e=>{let t=a===e.id;return l(`li`,{className:`px-4 py-3 text-xs`,children:r(`div`,{className:`flex items-start gap-3`,children:[l(`div`,{className:`flex-1 min-w-0`,children:t?r(`div`,{className:`space-y-2`,children:[l(`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:d,onChange:e=>f(e.target.value),placeholder:`Template name`,autoFocus:!0}),l(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:p,onChange:e=>m(e.target.value),placeholder:`Description (optional)`})]}):r(o,{children:[l(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&l(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),r(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,r(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),l(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?r(o,{children:[r(`button`,{type:`button`,onClick:b,disabled:g.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[l(at,{className:`h-3 w-3`}),`Save`]}),r(`button`,{type:`button`,onClick:y,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[l(nt,{className:`h-3 w-3`}),`Cancel`]})]}):r(o,{children:[l(`button`,{type:`button`,onClick:()=>v(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:l(ze,{className:`h-3 w-3`})}),l(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&_.mutate({id:e.id})},disabled:_.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:l(it,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}var qn=`pipeline-orchestrator`,Jn=200;function Yn(){return r(`div`,{className:`flex flex-col gap-3`,children:[r(`div`,{children:[l(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),l(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),l(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:l(w,{addonId:qn,limit:Jn,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}n();var Xn=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function Zn({refreshToken:e}){let[t,n]=c(`assignments`);return r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[l(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),l(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Per-camera assignments, the load balancer (live load + inference-device weights), cluster-wide settings, and the pipeline template library.`})]}),l(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Xn.map(e=>l(`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`&&l(hn,{}),t===`balancer`&&l(Un,{refreshToken:e}),t===`settings`&&l(Gn,{refreshToken:e}),t===`templates`&&l(Kn,{refreshToken:e}),t===`logs`&&l(Yn,{})]})]})}var Qn=`armed:`;function $n(e){return e.assignment.reasons.detection?.startsWith(Qn)===!0}function er(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!$n(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function tr(e){let t=[],n=[],{assignment:r,detection:i,decoder:a,broker:o}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),i!==null&&i.phase===`active`&&a!==null&&a.shm.framesWritten===0&&t.push({code:`decoder-black-hole`,severity:`error`,message:`Decoder on ${a.nodeId} has written 0 frames to the shared-memory plane while detection is active — the decode path is stalled`}),r.detectionNodeId===null&&i===null&&!$n(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let s=e.degraded??[];if(s.length>0){let e=[...new Set(s.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:`Could not read ${e} for this camera — those blocks are unknown, not empty (a switch read that failed does NOT mean nothing is switched off)`})}for(let e of o?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function nr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function rr(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function ir(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function ar(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var or={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function sr(e){if(!nr(e)||!Array.isArray(e.sections))return or;let t=xe(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)ar(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:rr(n(`detectionFps`)),motionSources:ir(n(`motionSources`)),motionFps:rr(n(`motionFps`)),motionCooldownMs:rr(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function cr(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...cr(r.children,t+1));return n}function X({title:e,children:t}){return r(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[l(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),l(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return r(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[l(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),l(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&l(lr,{})]})}function lr(){return l(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var ur={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return l(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${ur[e]}`,children:t})}function $({children:e}){return l(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function dr({icon:e,label:t,nodeId:n,pinned:i,reason:a,overridden:s}){return r(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[l(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),l(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?l(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):r(o,{children:[l(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),i?r(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[l(pt,{className:`h-2.5 w-2.5`}),` manual`]}):r(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,a!==void 0&&a.length>0?a:`capacity`]}),s&&l(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function fr({assignment:e,settings:t,onlineNodes:n,pinPending:i,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return r(X,{title:`Where it runs`,children:[l(dr,{icon:K,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),l(dr,{icon:Qe,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),l(dr,{icon:Le,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),l(dr,{icon:Ve,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),l(`div`,{className:`mt-1.5`,children:r(`select`,{value:o,disabled:i,"aria-label":`Detection placement pin`,onChange:e=>a(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[l(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>r(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function pr(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function mr(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function hr(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function gr({streams:e,brokerProfiles:t,settings:n,motionEnabled:i,motionFpsLive:a}){let s=mr(t,n.detectionStreamProfile),c=mr(t,n.motionStreamProfile),u=n.motionSources.includes(`analyzer`);return r(X,{title:`Streams & motion`,children:[r(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,s!==void 0&&` · ${s.width}×${s.height} ${s.codec}`]}),l(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:hr(n.detectionFps)}),r(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.join(` + `):`none`,i===!1&&` · inactive`]}),u&&r(o,{children:[r(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),r(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[hr(n.motionFps),a!==null&&` · live ${a.toFixed(1)}`]})]}),l(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),l(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?l($,{children:`No streams registered`}):e.map(e=>r(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[l(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,pr(e)]},e.camStreamId))})]})}function _r({steps:e,audioModelId:t,audioEnabled:n,audioMode:i}){return r(X,{title:`Pipeline steps`,children:[e===void 0?l($,{children:`Resolving…`}):e.length===0?l($,{children:`No steps configured`}):l(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>l(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:r(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&l(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&r(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),l(`div`,{className:`mt-1`,children:r(Z,{label:`Audio class.`,children:[i??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var vr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function yr({detection:e,live:t,detectionMode:n,modeOverridden:i}){if(e===null)return r(X,{title:`Detection runtime`,children:[l(Z,{label:`Mode`,overridden:i,children:n??`—`}),l($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,u=t?.queueDepth??e.queueDepth,f=d(a),p=a===`active`&&o===0;return r(X,{title:`Detection runtime`,children:[r(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[r(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${f.badgeClass}`,children:[l(oe,{phase:a,className:`h-2.5 w-2.5`}),f.label]}),t!==void 0&&l(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),l(Z,{label:`Mode`,overridden:i,children:n??`—`}),r(Z,{label:`FPS`,children:[l(`span`,{className:p?`text-danger font-semibold`:``,children:o.toFixed(1)}),r(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),r(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,u>0&&r(`span`,{className:`text-warning`,children:[` · queue `,u]}),t!==void 0&&t.droppedFrames>0&&r(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),r(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),r(Z,{label:`Provisioning`,children:[l(Q,{tone:vr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&r(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function br({broker:e}){return e===null?l(X,{title:`Stream broker`,children:l($,{children:`Broker stage inactive or unreachable`})}):r(X,{title:`Stream broker`,children:[e.profiles.length===0?l($,{children:`No broker profiles`}):l(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return r(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[l(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),l(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),r(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),r(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),r(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),r(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[r(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),r(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function xr({decoder:e,detectionActive:t}){if(e===null)return l(X,{title:`Decoder`,children:l($,{children:`Decoder stage inactive or unreachable`})});let n=t&&e.shm.framesWritten===0;return r(X,{title:`Decoder`,children:[l(Z,{label:`Node`,children:e.nodeId}),l(Z,{label:`Sessions`,children:e.sessionCount}),r(Z,{label:`SHM frames`,children:[l(`span`,{className:n?`text-danger font-semibold`:``,children:e.shm.framesWritten}),l(`span`,{className:`text-foreground-subtle`,children:` written`})]}),r(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&r(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),r(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&l(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}n();var Sr=`pipeline-orchestrator`,Cr={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},wr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Tr({problems:e}){return l(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>r(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[l(rt,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),l(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function Er({deviceId:e,name:t,online:n,status:i,live:o,onlineNodes:c}){let u=s(),{data:d}=se({addonId:Sr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:p}=T({deviceId:e},{staleTime:3e4}),m=a(()=>sr(d),[d]),h=a(()=>p===void 0?void 0:cr(p.steps),[p]),g=a(()=>i===void 0?[]:tr(i),[i]),_=()=>{u.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),u.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},v=f({onSuccess:_}),y=H({onSuccess:_}),b=t=>{t===`auto`?y.mutate({deviceId:e}):v.mutate({deviceId:e,agentNodeId:t})},x=i===void 0?`idle`:er(i),S=g.some(e=>e.severity===`error`),C=g.length>0,w=S?`border-danger/50`:C?`border-warning/40`:`border-border`;return r(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${w} bg-background overflow-hidden`,children:[r(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[l(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${S?`bg-danger`:Cr[x]}`,title:S?`Error`:wr[x],"aria-label":S?`Error`:wr[x],role:`img`}),l(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&l(Q,{tone:`danger`,children:`offline`}),r(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[m.detectionMode!==null&&l(Q,{tone:m.detectionMode===`disabled`?`warning`:m.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:m.detectionMode===`disabled`?`detection off`:m.detectionMode}),i?.recording!=null&&(i.recording.active?r(Q,{tone:`danger`,title:`Recording (${i.recording.mode})`,children:[l(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):i.recording.mode!==`off`&&r(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,i.recording.mode]}))]})]}),g.length>0&&l(Tr,{problems:g}),i===void 0?l(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):r(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[l(fr,{assignment:i.assignment,settings:m,onlineNodes:c,pinPending:v.isPending||y.isPending,onDetectionPinChange:b}),l(yr,{detection:i.detection,live:o,detectionMode:m.detectionMode,modeOverridden:m.overriddenKeys.has(`detectionMode`)}),l(_r,{steps:h,audioModelId:p?.audio?.modelId??null,audioEnabled:i.audio?.enabled??p?.audio?.enabled??null,audioMode:m.audioMode}),l(gr,{streams:i.source.streams,brokerProfiles:i.broker?.profiles,settings:m,motionEnabled:i.motion?.enabled??null,motionFpsLive:i.motion?.fps??null}),l(br,{broker:i.broker}),l(xr,{decoder:i.decoder,detectionActive:i.detection?.phase===`active`})]})]})}n();var Dr=5e3,Or=1e4,kr=5e3;function Ar(e){let t=s(),{data:n,isLoading:r}=Ae(),{data:i,isLoading:o}=b({},{refetchInterval:Dr}),{nodes:l}=A();u(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[d,f]=c(new Map);U(Se.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&f(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),u(()=>{if(d.size===0)return;let e=setInterval(()=>{f(e=>{let t=Date.now()-Or,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},kr);return()=>clearInterval(e)},[d.size]);let p=a(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:a(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:d,onlineNodes:a(()=>(l??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[l]),isLoading:r||o}}n();function jr({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:i,isLoading:o}=Ar(e),s=a(()=>[...t.map(e=>{let t=e.status===void 0?[]:tr(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),c=a(()=>{let e=0,t=0;for(let r of s)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,n]);return o&&t.length===0?l(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?l(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):l(`div`,{className:`h-full overflow-y-auto`,children:r(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[r(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[r(`span`,{children:[l(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),r(`span`,{children:[l(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),r(`span`,{children:[l(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),l(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>l(Er,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:i},e.deviceId))]})})}n();var Mr=`__cluster__`;function Nr(e){return e===`cameras`?`cameras`:`nodes`}function Pr(){let[e,t]=tt(),n=Nr(e.get(`view`)),i=e.get(`node`)??`__cluster__`,[a,s]=c(0),[d,f]=c(!1);return u(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Mr},{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:[l(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:i},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),l(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),l(`div`,{className:`flex items-center gap-2`,children:r(`button`,{type:`button`,onClick:()=>s(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[l(He,{className:`h-3.5 w-3.5`}),`Refresh`]})})]}),n===`nodes`&&r(`button`,{type:`button`,onClick:()=>f(e=>!e),"aria-expanded":d,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:[d?`Hide`:`Show`,` node list`]}),l(et,{className:[`h-4 w-4 transition-transform`,d?`rotate-180`:``].join(` `)})]}),l(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?r(o,{children:[l(`aside`,{className:[d?`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:l(yt,{selectedNodeId:i,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),f(!1)},refreshToken:a})}),l(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:i===`__cluster__`?l(Zn,{refreshToken:a}):l(mn,{nodeId:i,refreshToken:a})})]}):l(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:l(jr,{refreshToken:a})})})]})}export{Pr as PipelinePage};