@camstack/addon-admin-ui 1.2.54 → 1.2.55

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 (109) hide show
  1. package/dist/assets/{AddLocationWizard-Dk_N5YML.js → AddLocationWizard-BWvvcMyb.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-BKShgZty.js → AddonCollectionPage-Ckxfpzo7.js} +1 -1
  3. package/dist/assets/Addons-CzByWp7W.js +1 -0
  4. package/dist/assets/{AdminTabs-BTLJApFW.js → AdminTabs-BXEhxCj0.js} +1 -1
  5. package/dist/assets/{AiProfiles-BxzocCtj.js → AiProfiles-DJkiEAGj.js} +1 -1
  6. package/dist/assets/{BrokerForm-C7mUW7gI.js → BrokerForm-DjMStxWR.js} +1 -1
  7. package/dist/assets/{Build-EwTzSB5K.js → Build-rgGY63ER.js} +4 -4
  8. package/dist/assets/{Capabilities-BJFPzLLe.js → Capabilities-B1xz532o.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-Dwe2WhG2.js → CapabilityBadges-Dod41sYV.js} +1 -1
  10. package/dist/assets/Cluster-BTgdYtnl.js +1 -0
  11. package/dist/assets/{Data-DgddRRjj.js → Data-C_1Pyfta.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-Co_5N4lb.js → DetectionIntelligence-CzvM15vc.js} +1 -1
  13. package/dist/assets/{DeviceAggregateSection-DTMCDwV1.js → DeviceAggregateSection-n-EPWZZr.js} +1 -1
  14. package/dist/assets/DeviceDetail-Cf7EiAYj.js +2 -0
  15. package/dist/assets/{Devices-DeqrKuTg.js → Devices-Crj69Baf.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-D7yNxpf_.js → EmbedPlayerPage-CvHYMXl7.js} +1 -1
  17. package/dist/assets/Events-CxX3Qrw_.js +1 -0
  18. package/dist/assets/{FormBuilder-CwPW8n7D.js → FormBuilder-B1p15b6p.js} +1 -1
  19. package/dist/assets/Identity-Bn_lLl-Y.js +1 -0
  20. package/dist/assets/IntegrationDetail-CKmbntak.js +1 -0
  21. package/dist/assets/{Integrations-D4Yv3wEY.js → Integrations-CCzFtCKr.js} +1 -1
  22. package/dist/assets/{Integrations-KWHZ1G5h.js → Integrations-ZydMIfls.js} +1 -1
  23. package/dist/assets/{Logs-CH507Rhz.js → Logs-UiFFsPuc.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-kZSNZimk.js → MotionZonesSettings-gX4cCPfn.js} +1 -1
  25. package/dist/assets/MyAccess-CwZDSuVD.js +2 -0
  26. package/dist/assets/Network-XmpYwBZJ.js +1 -0
  27. package/dist/assets/{NodeAddonsSettingsPanel-C2q7FwIF.js → NodeAddonsSettingsPanel-Cc6eK0w1.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-BZYBxNcz.js → NodeInferenceDevices-j_wrfCuc.js} +1 -1
  29. package/dist/assets/Notifications-1iF_hGtj.js +1 -0
  30. package/dist/assets/Pipeline-B50SZqsP.js +1 -0
  31. package/dist/assets/{Plates-C9cAyRW_.js → Plates-CH4cT8pd.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-DIQI5RNe.js → PrivacyMaskSettings-BJokOnXq.js} +1 -1
  33. package/dist/assets/{ProviderIcon-Cuno3Ukn.js → ProviderIcon-BFPv4wws.js} +1 -1
  34. package/dist/assets/{Recordings-M88GcOLm.js → Recordings-BegJiF6M.js} +1 -1
  35. package/dist/assets/{ScanNetworkModal-BlHhnkAy.js → ScanNetworkModal-BOCd4ene.js} +1 -1
  36. package/dist/assets/{Settings-D02WebLf.js → Settings-D2MA9Dep.js} +1 -1
  37. package/dist/assets/{Showroom-1TDKDu35.js → Showroom-D3FeCiS7.js} +1 -1
  38. package/dist/assets/{Terminal-CSTdxGws.js → Terminal-CQtijhK7.js} +2 -2
  39. package/dist/assets/{__vite-browser-external-DQHwpgVa.js → __vite-browser-external-B6qJ4svC.js} +3 -3
  40. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C2TO5_gG.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DjdplOZ0.js} +1 -1
  41. package/dist/assets/{bell-ring-D9YniApB.js → bell-ring-DVYgCiuX.js} +1 -1
  42. package/dist/assets/{boxes-DiN_50iG.js → boxes-BAPHU21k.js} +1 -1
  43. package/dist/assets/{build-cluster-graph-BdpO49eY.js → build-cluster-graph-BHbSkxPE.js} +2 -2
  44. package/dist/assets/circle-check-big-BU8Z1nvB.js +1 -0
  45. package/dist/assets/{circle-x-C_vSnc5J.js → circle-x-D8tkl9U0.js} +1 -1
  46. package/dist/assets/clock-CxUDARJh.js +1 -0
  47. package/dist/assets/{copy-D-YMZRHs.js → copy-DERe_X8j.js} +1 -1
  48. package/dist/assets/{debounced-invalidate-KNk1lqIR.js → debounced-invalidate-BHYRiwPD.js} +1 -1
  49. package/dist/assets/dist-CawjP_cp.js +345 -0
  50. package/dist/assets/{dist-hAt_AJil.js → dist-D4q0IXSf.js} +1 -1
  51. package/dist/assets/{download-6fSuEAL_.js → download-CXEPE2lw.js} +1 -1
  52. package/dist/assets/{face-bbox-BvkTE6c3.js → face-bbox-CiazA6JA.js} +1 -1
  53. package/dist/assets/{hard-drive-Bq8s7iDr.js → hard-drive-BsC1Lb8K.js} +1 -1
  54. package/dist/assets/{hostInit-BccjgThd.js → hostInit-qO7zf83T.js} +1 -1
  55. package/dist/assets/index-BxnMqiYH.js +4 -0
  56. package/dist/assets/{index-DchMAgXl.css → index-DuDia5Gb.css} +1 -1
  57. package/dist/assets/{key-round-CLiVRYJi.js → key-round-DXJWRmE5.js} +1 -1
  58. package/dist/assets/{mf-entry-bootstrap-0-abfba2de.js → mf-entry-bootstrap-0-3cb4bcaf.js} +2 -2
  59. package/dist/assets/{pencil-kKbu--Dw.js → pencil-gmfJxKQf.js} +1 -1
  60. package/dist/assets/play-CkW0xDC3.js +1 -0
  61. package/dist/assets/{player-overlays-DbjG9CoN.js → player-overlays-H5rD3ZP3.js} +1 -1
  62. package/dist/assets/plus-BlsiiKYm.js +1 -0
  63. package/dist/assets/power-bZi2AxzL.js +1 -0
  64. package/dist/assets/{radio-D-HHgcfw.js → radio-C02Qj5rg.js} +1 -1
  65. package/dist/assets/{refresh-cw-CXJMAcb6.js → refresh-cw-C3lx1ppr.js} +1 -1
  66. package/dist/assets/remoteEntry-Hbnv0GQ-.js +1 -0
  67. package/dist/assets/rotate-ccw-B8IL7YJE.js +1 -0
  68. package/dist/assets/rotate-cw-DBD7lbZQ.js +1 -0
  69. package/dist/assets/search-DliTh-pg.js +1 -0
  70. package/dist/assets/{send-D6jTbtS-.js → send-Cs7xh34W.js} +1 -1
  71. package/dist/assets/{server-CTXU8Qj1.js → server-CJt4Xl7p.js} +1 -1
  72. package/dist/assets/square-CcAa1SRj.js +1 -0
  73. package/dist/assets/{square-check-big-Ckw0U2GC.js → square-check-big-DKi6ipve.js} +1 -1
  74. package/dist/assets/src-BPc_UYBv.js +67 -0
  75. package/dist/assets/src-C5APVTn-.js +345 -0
  76. package/dist/assets/{undo-2-LPb-dD6w.js → undo-2-DEPDrng4.js} +1 -1
  77. package/dist/assets/{upload-CUT60Ilr.js → upload-Dgf2pYnC.js} +1 -1
  78. package/dist/assets/{useEventInvalidation-BgFOnvV-.js → useEventInvalidation-4Fc-dQYg.js} +1 -1
  79. package/dist/assets/{video-Chns3_A7.js → video-hnQuQlJv.js} +1 -1
  80. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DW779i0a.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-7qrqOExj.js} +2 -2
  81. package/dist/assets/{wifi-BJ9-mPQL.js → wifi-Daw8zrsS.js} +1 -1
  82. package/dist/assets/{zap-sMseGHzt.js → zap-Dw5xT3PE.js} +1 -1
  83. package/dist/index.html +7 -7
  84. package/dist/server/addon.js +1774 -18
  85. package/package.json +1 -1
  86. package/dist/assets/Addons-0YaxbIrC.js +0 -1
  87. package/dist/assets/Cluster-CaAtNlqS.js +0 -1
  88. package/dist/assets/DeviceDetail-Ch5WhEuN.js +0 -2
  89. package/dist/assets/Events-kheHhnT8.js +0 -1
  90. package/dist/assets/Identity-BNVWDMnY.js +0 -1
  91. package/dist/assets/IntegrationDetail-EYhFs3zW.js +0 -1
  92. package/dist/assets/MyAccess-z8s29UV2.js +0 -2
  93. package/dist/assets/Network-B796_YlG.js +0 -1
  94. package/dist/assets/Notifications-C-zK42M8.js +0 -1
  95. package/dist/assets/Pipeline-B4lGxqfD.js +0 -1
  96. package/dist/assets/circle-check-big-BI6AtHsO.js +0 -1
  97. package/dist/assets/clock-DjX5RXHX.js +0 -1
  98. package/dist/assets/dist-DXcHyeKb.js +0 -345
  99. package/dist/assets/index-DZI5dpxU.js +0 -4
  100. package/dist/assets/play-BCXMhAf4.js +0 -1
  101. package/dist/assets/plus-9w-ZyF6i.js +0 -1
  102. package/dist/assets/power-Bye2QkEF.js +0 -1
  103. package/dist/assets/remoteEntry-D5PB3hl8.js +0 -1
  104. package/dist/assets/rotate-ccw-C4tkyZX7.js +0 -1
  105. package/dist/assets/rotate-cw-Bj3hZnoL.js +0 -1
  106. package/dist/assets/search-CXrulua-.js +0 -1
  107. package/dist/assets/square-D6F6VTs4.js +0 -1
  108. package/dist/assets/src-BASw5xKM.js +0 -345
  109. package/dist/assets/src-DQNh10sB.js +0 -67
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-admin-ui",
3
- "version": "1.2.54",
3
+ "version": "1.2.55",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Admin UI — Vite frontend build and server-side addon",
@@ -1 +0,0 @@
1
- import{At as e,Ct as t,Dt as n,Et as r,Lr as i,Mt as a,Ot as o,So as s,St as c,To as l,Ur as u,_t as d,ft as ee,g as f,gt as p,ht as m,jt as h,m as g,mt as _,pt as v,v as y,vt as te,wt as ne,xt as re,yo as ie,yt as b}from"./src-DQNh10sB.js";import{I as x,K as S,Q as C,R as ae,S as w,W as T,b as E,o as D,q as O,x as k,z as A}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{pt as j}from"./src-BASw5xKM.js";import{p as oe}from"./player-overlays-DbjG9CoN.js";import{t as M}from"./clock-DjX5RXHX.js";import{t as N}from"./download-6fSuEAL_.js";import{t as se}from"./plus-9w-ZyF6i.js";import{t as P}from"./refresh-cw-CXJMAcb6.js";import{t as ce}from"./search-CXrulua-.js";import{t as F}from"./upload-CUT60Ilr.js";import{I,J as le,K as ue,L,M as de,S as R,W as z,g as B,i as V,m as fe,p as H,s as U}from"./index-DZI5dpxU.js";import{t as W}from"./AdminPage-Dq33XE9j.js";import{t as pe}from"./NodeAddonsSettingsPanel-C2q7FwIF.js";var me=z(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),G=z(`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`}]]),he=z(`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`}]]),K=z(`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`}]]);C();var q=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),J=new Set([`done`,`failed`,`skipped`]);function Y(e){return!J.has(e.phase)&&!q.has(e.jobState)}function ge(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=q.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 _e(){let{data:e}=re({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=l(j.AddonsJobProgress,e=>e.job.jobId);return T(()=>{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 ge([...n.values()],Date.now())},[e,t])}var X={queued:{icon:M,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:R,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:R,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:R,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:R,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:R,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:R,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:L,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:G,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:K,cls:`bg-muted text-foreground-subtle`,label:`skipped`}};function ve({progress:e}){let t=X[e.phase],n=t.icon,r=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return w(`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:[k(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,w(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function ye({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:i,onSelect:a,selectedVersion:o}){let s=n===`upload`||n===`local`,{data:c,isLoading:l}=d({name:e});return w(`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:[w(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[k(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),k(`button`,{type:`button`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:k(V,{className:`h-3 w-3`})})]}),s&&w(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[k(F,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),w(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[w(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,k(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),l&&w(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[k(R,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),c&&k(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:c.map(e=>{let n=e.version===t,i=a!==void 0&&e.version===o,c=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),l=w(E,{children:[k(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:c?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&k(`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=>k(`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&&k(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),k(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return a?w(`button`,{type:`button`,"aria-label":`Select ${e.version}`,onClick:()=>a(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${i?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[l,i?k(L,{className:`h-3 w-3 text-primary shrink-0`}):k(`span`,{className:`w-3 shrink-0`})]},e.version):w(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[l,n&&!s?k(L,{className:`h-3 w-3 text-primary shrink-0`}):k(`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:k(N,{className:`h-3 w-3`})})]},e.version)})}),c&&c.length===0&&k(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var be={queued:{icon:M,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:R,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:P,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:L,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:G,bg:`bg-danger/10 text-danger`,label:`failed`}};function xe({item:e}){let t=be[e.status],n=t.icon;return w(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[k(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}C();var Z=`device-export`;function Se(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===Z)}function Ce({isBundle:e,installSource:t,addonId:n,iconPath:r,color:i}){let[a,o]=O(!1),s=i?{backgroundColor:`${i.startsWith(`#`)?i:`#${i}`}26`}:void 0,c=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,l=n&&r?`/api/addon-assets/${n}/${r}`:null,u=!!l&&!a;return w(`div`,{className:`relative flex-shrink-0`,children:[k(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${s?``:c}`,style:s,children:u?k(`img`,{src:l,alt:n,className:`h-5 w-5`,onError:()=>o(!0)}):k(e?he:B,{className:`h-4 w-4`})}),t===`local`&&k(`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`&&k(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:k(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:k(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&k(`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:k(F,{className:`h-2.5 w-2.5 text-white`})})]})}function we({version:e,availableUpdate:t,selectedVersion:n,isUpdating:r,installSource:i,disabled:a,onUpdate:o,onOpenPicker:s,children:c}){if(r)return w(`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:[k(R,{className:`h-3 w-3 animate-spin`}),`Updating…`]});if(t){let r=n??t;return w(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[o&&w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:a,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:[k(N,{className:`h-3 w-3`}),`Update`]}),w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:a,"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:[k(`span`,{className:`font-normal opacity-70`,children:e}),k(`span`,{className:`font-normal opacity-70`,children:`→`}),r,k(I,{className:`h-3 w-3`})]}),c]})}return w(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:a,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`,i===`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,k(I,{className:`h-3 w-3 opacity-50`})]}),c]})}function Te({addonId:e}){let t=D(),{data:n=`inherit`}=_({addonId:e}),r=o({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return k(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>k(`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 Ee({addon:e,agents:t=[],clusterStatus:n,hideVersion:i,availableUpdate:a,onUpdate:o,isUpdating:s,jobProgress:c,bundle:l,bulkItem:u,disabledByBulk:d,isSystem:ee}){let[p,m]=O(!1),[_,v]=O(!1),[re,b]=O(!1),[x,S]=O(null);A(()=>{S(null)},[a]);let C=x??a,[ae,T]=O(!1),[j,M]=O(!1),[N,ce]=O(`logs`),F=D(),le=oe(),L=ue(),de=ie(),{manifest:R}=e,z=e.installedOn??[],B=!l&&!R.protected&&R.removable!==!1,W=!!l,K=l?.displayName??R.name,q=l?.packageName??R.packageName,J=l?.version??R.packageVersion??R.version,Y=l?.installSource??e.installSource,ge=l?l.bundle?.description??l.addons[0]?.manifest.description:R.description,_e=h({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]}),F.invalidateQueries({queryKey:[[`addonPages`]]}),F.invalidateQueries({queryKey:[[`capabilities`]]})}}),X=ne({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]})}}),be=te({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]}),F.invalidateQueries({queryKey:[[`addonPages`]]}),F.invalidateQueries({queryKey:[[`capabilities`]]}),F.invalidateQueries({queryKey:[[`integrations`]]})}}),Z=r({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]}),F.invalidateQueries({queryKey:[[`alerts`]]})}}),Q=e.health,De=Q?.phase===`failed`&&!Q.inGracePeriod,Oe=De&&Q?.nextRetryAt&&!Q.retrying;return w(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${De?`border-red-500/50`:`border-border`}`,children:[De&&Q&&w(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[k(G,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),w(`div`,{className:`flex-1 min-w-0`,children:[w(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,Q.retryCount,`)`]}),k(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:Q.lastError?.message??`Unknown error`}),Oe&&Q.nextRetryAt&&w(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(Q.nextRetryAt).toLocaleTimeString()]})]}),w(`button`,{type:`button`,disabled:Z.isPending||Q.retrying,onClick:e=>{e.stopPropagation(),Z.mutate({packageName:q})},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:[k(P,{className:`h-3 w-3 ${Z.isPending||Q.retrying?`animate-spin`:``}`}),`Retry now`]})]}),w(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[k(Ce,{isBundle:W||!!R.components&&R.components.length>1,installSource:Y,addonId:W?l.addons[0]?.manifest.id:R.id,iconPath:W?l.bundle?.icon??l.addons[0]?.manifest.icon:R.icon,color:W?l.addons[0]?.manifest.color:R.color}),w(`div`,{className:`flex-1 min-w-0`,children:[w(`div`,{className:`flex items-start justify-between gap-2`,children:[k(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:K}),!i&&k(we,{version:J,availableUpdate:a,...C===void 0?{}:{selectedVersion:C},isUpdating:s,installSource:Y,disabled:d,...o&&C!==void 0?{onUpdate:()=>o(C)}:{},onOpenPicker:()=>b(e=>!e),children:re&&k(ye,{packageName:q,currentVersion:J,...Y?{installSource:Y}:{},...a!==void 0&&C!==void 0?{selectedVersion:C,onSelect:e=>{S(e),b(!1)}}:{},onInstall:e=>{b(!1),be.mutate({packageName:q,version:e})},onClose:()=>b(!1)})})]}),w(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[q!==K&&k(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:q}),W&&w(`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:[k(he,{className:`h-3 w-3`}),l.addons.length]}),ee&&w(`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:[k(P,{className:`h-3 w-3`}),`System`]}),u!=null&&k(xe,{item:u}),c!=null&&k(ve,{progress:c})]}),ge&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:ge}),!W&&e.process&&w(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[k(`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&&w(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),k(`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})]})]})]}),!W&&w(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),X.mutate({addonId:R.id})},disabled:X.isPending||d,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:[k(P,{className:`h-3 w-3 ${X.isPending?`animate-spin`:``}`}),`Restart`]}),w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),T(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${ae?`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:[k(fe,{className:`h-3 w-3`}),`Logs`]}),!W&&w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),M(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${j?`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:[k(H,{className:`h-3 w-3`}),`Settings`]}),k(`div`,{className:`flex-1`}),B&&w(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await de({title:`Uninstall ${R.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&_e.mutate({packageName:R.packageName})},disabled:_e.isPending||d,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:[k(U,{className:`h-3 w-3`}),_e.isPending?`Removing...`:`Uninstall`]})]}),n&&n.nodes.length>1&&!W&&w(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[k(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),k(`div`,{className:`space-y-1`,children:n.nodes.map(e=>w(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[k(`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`}`}),k(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),k(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&k(`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`&&k(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&k(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),ae&&!W&&w(`div`,{className:`border-t border-border`,children:[w(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[w(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[k(`button`,{type:`button`,onClick:()=>ce(`logs`),className:`px-2 py-0.5 transition-colors ${N===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),k(`button`,{type:`button`,onClick:()=>ce(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${N===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),k(`div`,{className:`flex-1`}),k(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),T(!1)},className:`text-foreground-subtle hover:text-foreground`,children:k(V,{className:`h-3.5 w-3.5`})})]}),N===`logs`&&k(f,{addonId:R.id,maxHeight:`max-h-64`,showFilters:!1}),N===`events`&&k(g,{addonId:R.id,category:`addon.*`,maxHeight:`max-h-64`})]}),W&&w(E,{children:[k(`button`,{type:`button`,onClick:()=>m(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:k(p?me:I,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),p&&k(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:l.addons.map(e=>k(Ee,{addon:e,agents:t,hideVersion:!0},e.manifest.id))})]}),j&&!W&&k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>M(!1),children:w(`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:[w(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[w(`div`,{className:`flex items-center gap-2`,children:[k(H,{className:`h-4 w-4 text-primary`}),w(`h2`,{className:`text-sm font-semibold text-foreground`,children:[K,` Settings`]})]}),k(`button`,{onClick:()=>M(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:k(V,{className:`h-4 w-4`})})]}),w(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[k(pe,{nodeId:`hub`,addonIds:[R.id],level:`global`}),Se(R)&&w(`div`,{children:[k(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),k(y,{addonId:R.id,trpc:le.trpcClient,onOpenDevice:e=>L(`/devices/${e}`)})]}),Y===`npm`&&w(`div`,{children:[k(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),k(Te,{addonId:R.id})]}),R.components&&R.components.length>0&&w(`div`,{children:[w(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,R.components.length,`)`]}),k(`div`,{className:`flex flex-wrap gap-1`,children:R.components.map(e=>k(`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&&w(`div`,{children:[k(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),w(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[z.length===0&&k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),z.map(e=>k(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),w(`div`,{className:`relative`,children:[w(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v(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:[k(se,{className:`h-3 w-3`}),`Add agent`]}),_&&w(`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=>k(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v(!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&&k(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),k(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:k(`button`,{type:`button`,onClick:()=>M(!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`})})]})})]})}C();var Q=`.tgz,.tar.gz,.zip`;function De({onUploadSuccess:e}){let[t,n]=O(!1),r=S(null),i=x(async t=>{n(!0);let r=new FormData;r.append(`file`,t);let i=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(`/api/addons/upload`,{method:`POST`,headers:{Authorization:`Bearer ${i}`},body:r})).json()).success&&e()}finally{n(!1)}},[e]);return w(E,{children:[k(`input`,{ref:r,type:`file`,accept:Q,onChange:x(e=>{let t=e.target.files?.[0];t&&i(t),e.target.value=``},[i]),className:`hidden`}),w(`button`,{type:`button`,onClick:()=>r.current?.click(),disabled:t,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:[t?k(R,{className:`w-3.5 h-3.5 animate-spin`}):k(F,{className:`w-3.5 h-3.5`}),t?`Uploading...`:`Upload`]})]})}C();var Oe=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function ke(e){return e!==void 0&&Oe.has(e)}function Ae(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function je(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 Me(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 Ne({addons:t,clusterStatus:r,selectedNode:i,onRefresh:o,isRefreshing:s}){let l=D(),[u,d]=O(``),f=ae(u),[h,g]=O(!1),_=S(null);A(()=>{if(!h)return;let e=e=>{_.current&&!_.current.contains(e.target)&&g(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[h]);let{data:v}=c({nodeId:i.id}),y=T(()=>{let e=new Map;for(let t of v??[])e.set(t.name,t.latestVersion);return e},[v]),ne=T(()=>(v??[]).filter(e=>!e.isSystem).length,[v]),[re,b]=O(()=>new Set),[C,E]=O(()=>new Map),j=x(e=>{b(t=>new Set(t).add(e))},[]),oe=x(e=>{b(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),M=x((e,t)=>{E(n=>new Map(n).set(e,t))},[]),se=x(e=>{E(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),F=a({onMutate:e=>{j(e.name),se(e.name)},onSuccess:(e,t)=>{oe(t.name);let n=e;if(n&&n.success===!1){M(t.name,n.error??`Update failed (no error message returned by server)`);return}l.invalidateQueries({queryKey:[[`addons`]]}),l.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{oe(t.name),M(t.name,e instanceof Error?e.message:String(e))}}),I=_e(),ue=S(new Set);A(()=>{let e=new Set;for(let[t,n]of I)Y(n)&&e.add(t);let t=[...ue.current].some(t=>!e.has(t));ue.current=e,t&&(l.invalidateQueries({queryKey:[[`addons`]]}),l.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[I,l]);let{data:z}=m(void 0),B=ee({onSuccess:()=>{l.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:V,isFetching:fe}=n({query:f||void 0},{enabled:h}),H=e(),{data:U}=p(void 0),W=U?.requestedAt,[pe,me]=O(null),[G,he]=O(!1);A(()=>{if(U?.kind===`framework-bulk-update`&&U.requestedAt!==pe){me(U.requestedAt),he(!0);let e=window.setTimeout(()=>he(!1),6e3);return()=>window.clearTimeout(e)}},[W,pe,U]),ie();let K=x(async()=>{let e=(v??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!i.isHub){for(let t of e)await F.mutateAsync({name:t.name,version:t.latestVersion,nodeId:i.id});return}await H.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[i.id]})}},[v,i.id,i.isHub,H,F]),q=te({onSuccess:()=>{l.invalidateQueries({queryKey:[[`addons`]]}),l.invalidateQueries({queryKey:[[`addonPages`]]}),l.invalidateQueries({queryKey:[[`capabilities`]]}),l.invalidateQueries({queryKey:[[`integrations`]]})}}),[J,ge]=O(`type`),[X,ve]=O(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),ye=e=>{ve(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[be,xe]=le(),Z=be.get(`capability`),Se=T(()=>{let e=t.filter(e=>!ke(e.manifest.packageName));return i.isHub||(e=e.filter(e=>Ae(e.placement,i.isHub))),Z&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Z))),e},[t,i.isHub,Z]),Ce=()=>{let e=new URLSearchParams(be);e.delete(`capability`),xe(e,{replace:!0})},we=X===`flat`?Se:Me(Se),Te=T(()=>{let e=[...we];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},[we,J]);return w(`div`,{className:`space-y-4`,children:[[...C.entries()].map(([e,t])=>k(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:w(`div`,{className:`flex items-start justify-between gap-3`,children:[w(`div`,{className:`space-y-0.5`,children:[w(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),k(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),k(`button`,{type:`button`,onClick:()=>se(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),w(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[w(`div`,{className:`flex items-center gap-1.5`,children:[k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),w(`select`,{value:J,onChange:e=>ge(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:[k(`option`,{value:`type`,children:`Bundles first`}),k(`option`,{value:`name`,children:`Name`}),k(`option`,{value:`source`,children:`Install source`})]})]}),w(`div`,{className:`flex items-center gap-1.5`,children:[k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),k(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>k(`button`,{type:`button`,onClick:()=>ye(e),className:`px-2.5 py-1.5 transition-colors capitalize ${X===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))})]}),i.isHub&&w(`div`,{className:`flex items-center gap-1.5`,children:[k(P,{className:`h-3 w-3 text-foreground-subtle`}),k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),k(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>k(`button`,{type:`button`,onClick:()=>B.mutate({channel:e}),disabled:B.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${z?.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))})]}),ne>0&&w(`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?k(R,{className:`w-3 h-3 animate-spin`}):k(N,{className:`w-3 h-3`}),H.isPending?`Updating…`:`Update All (${ne})`]}),w(`button`,{type:`button`,onClick:o,disabled:s||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:[k(P,{className:`w-3 h-3 ${s?`animate-spin`:``}`}),`Refresh`]})]}),w(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[w(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:_,children:[k(ce,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),k(`input`,{type:`text`,value:u,onChange:e=>{d(e.target.value),g(!0)},onFocus:()=>g(!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`}),fe&&k(R,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),h&&V&&V.length>0&&w(`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&&w(`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&&k(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:V.map(e=>w(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[k(`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()}),w(`div`,{className:`flex-1 min-w-0`,children:[w(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[k(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),w(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),k(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&k(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?w(`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:[k(L,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):w(`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?k(R,{className:`h-3 w-3 animate-spin`}):k(N,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),k(De,{onUploadSuccess:()=>{l.invalidateQueries({queryKey:[[`addons`]]}),o()}})]}),Z&&w(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[k(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),k(`span`,{className:`font-mono text-primary font-semibold`,children:Z}),k(`button`,{type:`button`,onClick:Ce,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),G&&w(`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:[k(de,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),w(`div`,{children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),k(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),Se.length===0&&k(`div`,{className:`text-xs text-foreground-subtle`,children:t.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 ${i.name} (placement filter active)`}),k(`div`,{className:`space-y-2`,children:Te.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=y.get(t),a=$(e)?e.representative:e,o=n?e=>F.mutate({name:t,version:e,nodeId:i.id}):void 0,s=I.get(t)??null,c=s!==null&&Y(s);return k(Ee,{addon:a,clusterStatus:r?.[a.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,isUpdating:re.has(t)||c,jobProgress:s,onUpdate:o,disabledByBulk:H.isPending},$(e)?t:e.manifest.id)})})]})}function Pe(){let e=D(),{data:n,isLoading:r,isError:a}=b(),{data:o}=i(void 0),{data:c}=u(void 0,{refetchInterval:1e4}),l=T(()=>{let e=new Map;e.set(`hub`,{id:`hub`,name:`Hub`,isHub:!0});for(let t of c??[]){let n=String(t.id??``);n&&e.set(n,{id:n,name:String(t.name??n),isHub:!!t.isHub})}return[...e.values()]},[c]),[d,ee]=O(`hub`),f=l.find(e=>e.id===d)??l[0],p=v(),m=t(),h=p.isPending||m.isPending,g=async()=>{await p.mutateAsync({nodeId:d}),await m.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},_=S(p);_.current=p,A(()=>{_.current.mutate({nodeId:`hub`})},[]);let y=(n??[]).map(je).filter(e=>e!==null);return w(W,{children:[w(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[k(s,{selectedNodeId:d,onSelect:ee}),w(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!r&&!a&&w(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[y.length,` installed`]}),w(`button`,{type:`button`,onClick:()=>void g(),disabled:h,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:[k(P,{className:`w-3 h-3 ${h?`animate-spin`:``}`}),`Check for updates`]})]})]}),!f.isHub&&w(`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`,` `,k(`span`,{className:`font-medium text-foreground`,children:f.name}),` — agents only run`,` `,k(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,k(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),r&&k(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),a&&k(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!r&&!a&&k(Ne,{addons:y,clusterStatus:o,selectedNode:f,onRefresh:()=>void g(),isRefreshing:h})]})}export{Pe as AddonsPage};
@@ -1 +0,0 @@
1
- import{Br as e,Ca as t,Ea as n,Eo as r,Hr as i,Jo as a,Ki as o,Mr as s,Rr as c,Ta as l,Ur as u,Vr as d,Wr as f,Xo as p,Yo as m,Zo as h,g,jr as _,ki as v,m as y,wa as b,wo as x,yo as S,zr as C}from"./src-DQNh10sB.js";import{I as w,K as T,Q as E,S as D,W as O,o as k,q as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as N}from"./player-overlays-DbjG9CoN.js";import{t as P}from"./pencil-kKbu--Dw.js";import{t as ee}from"./radio-D-HHgcfw.js";import{t as F}from"./refresh-cw-CXJMAcb6.js";import{t as I}from"./rotate-cw-Bj3hZnoL.js";import{t as te}from"./server-CTXU8Qj1.js";import{t as L}from"./upload-CUT60Ilr.js";import{B as R,I as z,L as ne,P as re,S as B,W as V,i as ie,j as ae,m as H,o as U,s as W,t as G}from"./index-DZI5dpxU.js";import{n as K,t as q}from"./build-cluster-graph-BdpO49eY.js";import{t as J}from"./format-size-CO9d3C3-.js";import{t as oe}from"./NodeAddonsSettingsPanel-C2q7FwIF.js";var Y=V(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),se=V(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),ce=V(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),le=V(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),X=V(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),ue=V(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]);E();function de(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function fe({nodeId:t,addons:n,isHub:r}){let i=k(),a=S(),[o,s]=A(null),[l,u]=A(null),[d,p]=A(!1),[m,h]=A(null),[g,_]=A(0),v=T(null),y=e(),b=f(),x=c({nodeId:t}),C=x.data??[],w=new Map(n.map(e=>[e.id,e.capabilities])),E=C.length>0?C.map(e=>({id:e.id,status:e.status,capabilities:w.get(e.id)??[],version:e.version,packageName:e.packageName})):n.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),O=()=>{i.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),x.refetch()},M=async e=>{s(e);try{await y.mutateAsync({nodeId:t,addonId:e}),O()}catch(e){console.error(`Failed to restart addon:`,e)}finally{s(null)}},N=async e=>{if(await a({title:`Uninstall addon`,message:`Remove "${e}" from ${t}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){u(e);try{await b.mutateAsync({nodeId:t,addonId:e}),O()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{u(null)}}},P=D(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(`input`,{ref:v,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async e=>{let n=e.target.files?.[0];if(n){e.target.value=``,h(null),p(!0),_(0);try{await de({file:n,nodeId:t,token:localStorage.getItem(`camstack_admin_token`),onProgress:_}),O()}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1),_(0)}}}}),D(`button`,{onClick:()=>v.current?.click(),disabled:d,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[d?j(B,{className:`h-3 w-3 animate-spin`}):j(L,{className:`h-3 w-3`}),d?`Uploading… ${g}%`:`Upload addon (.tgz)`]}),d&&j(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:j(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${g}%`}})}),m&&j(`span`,{className:`text-[10px] text-destructive`,children:m})]});return E.length===0?D(`div`,{children:[P,j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:x.isLoading?`Loading addons…`:`No addons on this node`})]}):D(`div`,{children:[P,j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`px-3 py-2 font-medium`,children:`Addon`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Capabilities`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Status`}),j(`th`,{className:`px-3 py-2 font-medium w-16`})]})}),j(`tbody`,{children:E.map(e=>D(`tr`,{className:`border-t border-border/50`,children:[D(`td`,{className:`px-3 py-2 font-medium`,children:[j(`div`,{children:e.id}),e.packageName&&j(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),j(`td`,{className:`px-3 py-2 text-muted-foreground`,children:e.version??`—`}),j(`td`,{className:`px-3 py-2`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):j(`span`,{className:`text-muted-foreground`,children:`—`})})}),j(`td`,{className:`px-3 py-2`,children:j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),j(`td`,{className:`px-3 py-2`,children:D(`div`,{className:`flex items-center gap-1 justify-end`,children:[j(`button`,{onClick:()=>M(e.id),disabled:o===e.id||l===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:j(I,{className:`h-3 w-3 ${o===e.id?`animate-spin`:``}`})}),j(`button`,{onClick:()=>N(e.id),disabled:o===e.id||l===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:l===e.id?j(B,{className:`h-3 w-3 animate-spin`}):j(W,{className:`h-3 w-3`})})]})})]},e.id))})]})})]})}E();function pe(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function me({state:e}){return j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var he=[`trace`,`debug`,`info`,`warn`,`error`];function ge({proc:t,nodeId:n,defaultExpanded:r,activePanel:o,onTogglePanel:s}){let c=t.services??[],l=c.length===1,[u,f]=A(l||r),[_,v]=A(null),[b,x]=A(`info`),S=t.name.includes(`(core)`),C=e(),w=d(),T=i(),E=async e=>{v(e);try{await C.mutateAsync({nodeId:n,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{v(null)}},O=async()=>{v(t.name);try{await w.mutateAsync({nodeId:n,processName:t.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{v(null)}},k=async e=>{let r=`${n}/${t.name}`;try{await T.mutateAsync({nodeId:r,level:e}),x(e)}catch(e){console.error(`Failed to set log level:`,e)}};return D(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[D(`div`,{role:l?void 0:`button`,tabIndex:l?void 0:0,onClick:l?void 0:()=>f(!u),onKeyDown:l?void 0:e=>{(e.key===`Enter`||e.key===` `)&&f(!u)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${l?``:`hover:bg-muted/40 cursor-pointer`}`,children:[l?j(`span`,{className:`h-3 w-3 shrink-0`}):j(u?z:re,{className:`h-3 w-3 text-muted-foreground shrink-0`}),S?j(te,{className:`h-3.5 w-3.5 text-primary shrink-0`}):j(R,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),j(`span`,{className:`text-xs font-semibold flex-1`,children:t.name}),D(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,t.pid]}),j(me,{state:t.state}),D(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[t.cpuPercent,`% CPU`]}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:J(t.memoryRss)}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:pe(t.uptimeSeconds)}),!S&&D(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[D(a,{children:[j(h,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:b}),j(m,{align:`end`,className:`min-w-[70px] py-0.5`,children:he.map(e=>j(p,{onClick:()=>k(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===b?`text-primary font-semibold`:``}`,children:e},e))})]}),j(`button`,{onClick:O,disabled:_===t.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:j(I,{className:`h-3 w-3 ${_===t.name?`animate-spin`:``}`})})]})]}),u&&c.length>0&&j(`div`,{className:`divide-y divide-border/30`,children:c.map(e=>D(`div`,{children:[D(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[j(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),j(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&D(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&D(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),D(`div`,{className:`flex items-center gap-1 shrink-0`,children:[j(`button`,{onClick:()=>s(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${o?.addonId===e.addonId&&o.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:j(H,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>s(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${o?.addonId===e.addonId&&o.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:j(ee,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>E(e.addonId),disabled:_===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:j(I,{className:`h-3 w-3 ${_===e.addonId?`animate-spin`:``}`})})]})]}),o?.addonId===e.addonId&&o.type===`logs`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(g,{addonId:e.addonId,agentId:n,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>s(e.addonId,`logs`)})}),o?.addonId===e.addonId&&o.type===`events`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(y,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>s(e.addonId,`events`)})})]},e.addonId))}),u&&c.length===0&&j(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function _e({nodeId:e,processes:t}){let[n,r]=A(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):j(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>j(ge,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}E();function ve(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function ye(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function be({nodeId:e}){let t=k(),n=S(),[r,i]=A(`all`),a=x(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:o}=s({nodeId:e}),c=a?.processes??o,l=O(()=>c?[...c]:[],[c]),u=O(()=>r===`ghost`?l.filter(e=>e.classification===`ghost`):l,[l,r]),d=O(()=>{let e=l.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[l]),f=_({onSettled:()=>{t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),p=O(()=>{let e=new Map;for(let t of l)e.set(t.pid,t.classification);return e},[l]),m=async(t,r)=>{if(t.classification===`root`||t.classification===`system`)return;let i=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=r?`SIGKILL`:`SIGTERM`;await n({title:`Send ${a}?`,message:`Target pid ${t.pid} (${i}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&f.mutate({nodeId:e,pid:t.pid,force:r})},h=async(t,n)=>{try{await f.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},g=async r=>{let i=p.get(r.ppid);if(i===`root`||i===`system`){await n({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${r.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${r.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await n({title:`Kill ghost parent + ${r.children.length} child(ren)?`,message:`SIGKILL parent pid ${r.ppid} and SIGTERM ${r.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([h(r.ppid,!0),...r.children.map(e=>h(e.pid,!1))]),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},v=async()=>{let r=l.filter(e=>e.classification===`ghost`);r.length!==0&&await n({title:`Kill all ${r.length} ghost process(es)?`,message:`SIGKILL ${r.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(r.map(e=>h(e.pid,!0))),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},y=l.filter(e=>e.classification===`ghost`).length,b=l.filter(e=>e.classification===`managed`).length,C=l.filter(e=>e.classification===`root`).length,w=l.filter(e=>e.classification===`system`).length;return D(`div`,{className:`space-y-4`,children:[D(`div`,{className:`flex items-start justify-between gap-4`,children:[D(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),D(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[j(F,{className:`h-3 w-3`}),` Refresh`]})]}),D(`div`,{className:`grid grid-cols-4 gap-3`,children:[D(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:C})]}),D(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:b})]}),D(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:w})]}),D(`div`,{className:`rounded-lg border p-3 ${y>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[D(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[y>0&&j(X,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),j(`div`,{className:`text-xl font-semibold ${y>0?`text-destructive`:`text-foreground`}`,children:y})]})]}),d.length>0&&D(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[D(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[j(U,{className:`h-3 w-3`}),` Recurring ghost parents (`,d.length,`)`]}),j(`div`,{className:`space-y-1.5`,children:d.map(e=>D(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[D(`div`,{className:`flex items-center gap-2`,children:[D(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),D(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),D(`button`,{type:`button`,disabled:f.isPending,onClick:()=>{g(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[j(X,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),D(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[D(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),D(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${r===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>i(`all`),children:[`All (`,l.length,`)`]}),D(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${r===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>i(`ghost`),children:[`Ghost only (`,y,`)`]})]}),y>0&&D(`button`,{type:`button`,disabled:f.isPending,onClick:()=>{v()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[j(X,{className:`h-3 w-3`}),` Kill all `,y,` ghost(s)`]})]}),j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[j(`th`,{className:`text-left px-3 py-2`,children:`Class`}),j(`th`,{className:`text-right px-3 py-2`,children:`PID`}),j(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),j(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),j(`th`,{className:`text-left px-3 py-2`,children:`Command`}),j(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),j(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),j(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),j(`th`,{className:`w-44`})]})}),D(`tbody`,{children:[u.length===0&&j(`tr`,{children:j(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:r===`ghost`?`No ghost processes detected.`:`Scanning…`})}),u.map(e=>D(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[j(`td`,{className:`px-3 py-2`,children:j(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),j(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),D(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),j(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),j(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:ye(e.command)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:J(e.memoryRssBytes)}),j(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ve(e.uptimeSec)}),j(`td`,{className:`px-3 py-2 text-right`,children:D(`div`,{className:`inline-flex gap-1`,children:[D(`button`,{type:`button`,disabled:f.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{m(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[j(W,{className:`h-3 w-3`}),` Term`]}),D(`button`,{type:`button`,disabled:f.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{m(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[j(X,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),f.isError&&D(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,f.error instanceof Error?f.error.message:`unknown`]})]})}function xe({nodeId:e,addonIds:t}){return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):j(`div`,{className:`w-full py-2`,children:j(oe,{nodeId:e,addonIds:t,level:`global`,selfTabbed:!0})})}E();function Se({nodeId:e,addons:t}){let n=k(),{data:r,isLoading:i}=v({nodeId:e}),a=O(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),s=o({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return a.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`px-3 py-2 font-medium w-1/2`,children:`Capability`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Bound provider`})]})}),j(`tbody`,{children:a.map(({capName:t,providers:n})=>{let a=r?.[t]??n[0]??``,o=n.length===1;return D(`tr`,{className:`border-t border-border/50`,children:[j(`td`,{className:`px-3 py-2 font-medium`,children:t}),j(`td`,{className:`px-3 py-2`,children:j(`select`,{value:a,onChange:n=>s.mutate({nodeId:e,capName:t,addonId:n.target.value}),disabled:o||s.isPending||i,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:o?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>j(`option`,{value:e,children:e},e))})})]},t)})})]})})}E();function Z(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function Ce(e){let[t,n]=A(!1),[r,i]=A(e.name),a=k(),o=C({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),s=(e.localIps??[]).filter(e=>!e.includes(`:`)),c=(e.localIps??[]).filter(e=>e.includes(`:`)),l=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await o.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},u=[[`Node ID`,j(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?D(`div`,{className:`flex items-center gap-1.5`,children:[j(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l(),e.key===`Escape`&&n(!1)},disabled:o.isPending,autoFocus:!0}),j(`button`,{onClick:()=>void l(),disabled:o.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:j(ne,{className:`h-3.5 w-3.5`})}),j(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:j(ie,{className:`h-3.5 w-3.5`})})]}):D(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&j(`button`,{onClick:()=>{i(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:j(P,{className:`h-3 w-3`})})]})],[`Hostname`,j(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Root Package`,e.rootPackage?D(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,D(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,D(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,j(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,j(`span`,{className:`text-xs`,children:Z(e.uptime)})],[`Engines`,e.engines.length>0?j(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return s.length>0&&u.push([`IPv4`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map((e,t)=>j(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),c.length>0&&u.push([`IPv6`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>j(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),j(`div`,{className:`py-2`,children:j(`table`,{className:`w-full text-sm`,children:j(`tbody`,{children:u.map(([e,t],n)=>D(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[j(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),j(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}E();var we=[[`serverManagement`,`getServerPackageStatus`]];function Q({label:e,tone:t}){return j(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-emerald-500/15 text-emerald-500`,info:`bg-sky-500/15 text-sky-500`,warn:`bg-amber-500/15 text-amber-500`,error:`bg-red-500/15 text-red-500`}[t]}`,children:e})}function $({label:e,value:t}){return D(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:e}),j(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function Te({node:e}){let{t:r}=G(),i=k(),a=S(),[o,s]=A(!1),c=e.isHub?void 0:{nodeId:e.id},u=l(c,{refetchInterval:1e4,enabled:e.isOnline,retry:1}),d=u.data??null,f=w(()=>{i.invalidateQueries({queryKey:we})},[i]),p=b({onSettled:f}),m=t({onSettled:f}),h=n({onSettled:f}),g=w(async()=>{d?.latestVersion!=null&&await a({title:r(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:r(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:d.packageName,version:d.latestVersion,node:e.name}),confirmLabel:r(`serverManagement.confirmUpdateAction`,`Update & restart`)})&&(await m.mutateAsync({version:d.latestVersion,...c})).restarting&&s(!0)},[m,a,e.name,c,d,r]),_=w(async()=>{await a({title:r(`serverManagement.confirmRestartTitle`,`Restart node`),message:r(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:e.name}),confirmLabel:r(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})&&(await h.mutateAsync(c)).restarting&&s(!0)},[a,e.name,h,c,r]),v=()=>{switch(d?.bootMode){case`data-root`:return{label:r(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:r(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:r(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},y=()=>{if(d==null)return null;switch(d.updateState){case`checking`:return{label:r(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:r(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:r(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return d.updateAvailable?{label:r(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:r(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},x=d?.bootMode===`workspace`,C=e.isOnline&&d!=null&&!x&&d.updateAvailable&&d.updateState===`idle`&&!m.isPending,T=e.isOnline&&d!=null&&d.updateState===`idle`&&!h.isPending,E=e.isOnline?y():null;return D(`div`,{className:`space-y-4 py-2`,children:[D(`div`,{className:`flex items-center justify-between gap-3`,children:[D(`div`,{className:`flex items-center gap-2 min-w-0`,children:[j(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:d?.packageName??e.rootPackage?.name??`@camstack/server`}),e.isOnline&&d!=null&&j(Q,{...v()})]}),E!=null&&j(Q,{...E})]}),!e.isOnline&&j($,{label:r(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage?.version??null}),e.isOnline&&u.isLoading&&D(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[j(B,{className:`h-4 w-4 animate-spin`}),r(`common.loading`,`Loading…`)]}),e.isOnline&&u.isError&&D(`div`,{className:`space-y-1.5`,children:[j(`p`,{className:`text-sm text-red-500`,children:r(`serverManagement.loadError`,`Could not load the node root-package status.`)}),e.rootPackage!=null&&j($,{label:r(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage.version})]}),e.isOnline&&d!=null&&D(`div`,{className:`space-y-1.5`,children:[j($,{label:r(`serverManagement.runningVersion`,`Running version`),value:d.runningVersion}),j($,{label:r(`serverManagement.latestVersion`,`Latest on registry`),value:d.latestVersion}),j($,{label:r(`serverManagement.imageSeedVersion`,`Image seed (baked)`),value:d.seedVersion}),j($,{label:r(`serverManagement.nodeRuntimeVersion`,`Node.js runtime`),value:d.nodeRuntimeVersion}),d.pendingVersion!=null&&j($,{label:r(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:d.pendingVersion})]}),e.isOnline&&(d?.imageContract?.state===`behind-series`||d?.imageContract?.state===`behind-patch`)&&D(`div`,{className:`rounded-md border px-3 py-2 text-xs leading-relaxed ${d.imageContract.state===`behind-series`?`border-red-500/40 bg-red-500/10 text-red-500`:`border-amber-500/40 bg-amber-500/10 text-amber-500`}`,children:[j(`p`,{className:`mb-0.5 font-semibold`,children:r(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),j(`p`,{children:d.imageContract.message})]}),e.isOnline&&x&&j(`p`,{className:`text-xs text-foreground-subtle`,children:r(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),o&&D(`div`,{className:`flex items-center gap-2 text-sm text-amber-500`,children:[j(B,{className:`h-4 w-4 animate-spin`}),r(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),e.isOnline&&D(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:p.isPending||d?.updateState===`staging`,onClick:()=>p.mutate(c),children:[p.isPending?j(B,{className:`h-3.5 w-3.5 animate-spin`}):j(F,{className:`h-3.5 w-3.5`}),r(`serverManagement.checkForUpdate`,`Check for update`)]}),C&&D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void g(),children:[m.isPending?j(B,{className:`h-3.5 w-3.5 animate-spin`}):j(Y,{className:`h-3.5 w-3.5`}),r(`serverManagement.updateTo`,`Update to {{version}}`,{version:d?.latestVersion??``})]}),D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!T,onClick:()=>void _(),children:[h.isPending?j(B,{className:`h-3.5 w-3.5 animate-spin`}):j(I,{className:`h-3.5 w-3.5`}),r(`serverManagement.restart`,`Restart`)]})]}),e.isOnline&&d?.lastCheckedAtMs!=null&&D(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[j(ce,{className:`h-3 w-3`}),r(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(d.lastCheckedAtMs).toLocaleString()})]})]})}E();function Ee({node:e}){let t=N(),[n,r]=A(`info`),[i,a]=A(!1),o=e.processes??[],s=e.addons.map(e=>e.id),c=async()=>{if(!i){a(!0);try{await Promise.allSettled([t.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}),t.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id})])}finally{a(!1)}}};return e.isOnline?D(`div`,{className:`border border-border rounded-xl`,children:[D(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),D(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),D(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[D(`span`,{className:`flex items-center gap-1`,children:[j(ae,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),D(`span`,{className:`flex items-center gap-1`,children:[j(le,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),j(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(t=>j(`button`,{onClick:()=>r(t),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n===t?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:t===`info`?`General`:t===`addons`?`Addons (${e.addons.length})`:t===`forks`?`Forks (${o.length})`:t===`processes`?`Processes`:t===`settings`?`Settings`:`Capabilities`},t))}),D(`div`,{className:`px-4 py-2`,children:[n===`info`&&D(`div`,{className:`space-y-3`,children:[j(Ce,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps,rootPackage:e.rootPackage}),j(`div`,{className:`border-t border-border pt-1`,children:j(Te,{node:{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}})})]}),n===`addons`&&j(fe,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),n===`forks`&&j(_e,{nodeId:e.id,processes:o}),n===`processes`&&j(be,{nodeId:e.id}),n===`settings`&&j(xe,{nodeId:e.id,addonIds:s}),n===`capabilities`&&j(Se,{nodeId:e.id,addons:e.addons})]})]}):D(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[D(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),D(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),e.rootPackage&&D(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}),j(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),D(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[D(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?`Last seen ${new Date(e.lastSeen).toLocaleString()} — `:``,e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned; will resume when node reconnects`]}),D(`button`,{type:`button`,onClick:()=>void c(),disabled:i,title:`Forget this node — removes its saved history and pipeline assignments`,className:`flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border text-muted-foreground hover:text-destructive hover:border-destructive/50 disabled:opacity-50 transition-colors`,children:[j(W,{className:`h-3 w-3`}),i?`Forgetting…`:`Forget node`]})]})]})}E();function De({nodes:e,focusNodeId:t,focusNonce:n}){let r=[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)),i=T(null);return M(()=>{if(!t)return;let e=i.current?.querySelector(`#node-card-${CSS.escape(t)}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[t,n]),j(`div`,{ref:i,className:`flex flex-col gap-4`,children:r.map(e=>j(`div`,{id:`node-card-${e.id}`,children:j(Ee,{node:e})},e.id))})}E();function Oe(e){let[t,n]=A(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return M(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function ke(){let{data:e,isLoading:t}=u(void 0,{staleTime:1/0}),[n,i]=A(null);return r(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&i(t)}),{nodes:O(()=>n??e??[],[n,e]),isLoading:t&&!n}}function Ae(){let{t:e}=G(),n=S(),[r,i]=A(`table`),[a,o]=A(void 0),[s,c]=A(0),l=Oe(`(max-width: 767px)`),u=l&&r===`graph`?`table`:r,{nodes:d,isLoading:f}=ke(),p=O(()=>q(d),[d]),m=O(()=>d.filter(e=>e.isOnline),[d]),h=m.length,g=d.filter(e=>!e.isOnline).length,_=t(),[v,y]=A(!1),b=w(async()=>{let t=[...m].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1);if(await n({title:e(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:e(`serverManagement.confirmUpdateAllBody`,`Update and restart every online node, agents first, hub last. Up-to-date nodes are skipped; this page reconnects when the hub comes back.`),confirmLabel:e(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){y(!0);try{for(let e of t)try{await _.mutateAsync(e.isHub?{}:{nodeId:e.id})}catch{}}finally{y(!1)}}},[_,n,m,e]),x=w(e=>{i(`table`),o(e),c(e=>e+1)},[]),C=(e,t,n)=>D(`button`,{onClick:()=>i(e),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${r===e?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[j(n,{className:`h-3.5 w-3.5`}),t]});return D(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[D(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[D(`div`,{className:`flex items-center gap-2`,children:[h>0&&D(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[h,` online`]}),g>0&&D(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[g,` offline`]})]}),D(`div`,{className:`flex items-center gap-2`,children:[h>1&&D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,disabled:v,title:e(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void b(),children:[v?j(B,{className:`h-3.5 w-3.5 animate-spin`}):j(Y,{className:`h-3.5 w-3.5`}),e(`serverManagement.updateAll`,`Update all nodes`)]}),D(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[C(`table`,`Table`,ue),!l&&C(`graph`,`Graph`,se)]})]})]}),f?j(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):u===`graph`?j(K,{graph:p,onOpenNodeDetail:x}):j(`div`,{className:`flex-1 overflow-auto`,children:j(De,{nodes:d,focusNodeId:a,focusNonce:s})})]})}export{Ae as ClusterPage};
@@ -1,2 +0,0 @@
1
- import{$ as e,Bn as t,Bo as n,D as r,E as i,Ei as a,Gi as o,Gr as s,H as c,Hn as l,Ho as u,Io as d,Ir as f,J as p,Kr as m,Ln as h,Lo as g,M as _,Mo as v,N as y,Nn as b,No as x,O as S,Oi as C,On as w,Oo as ee,P as T,Pi as te,Pn as E,Po as ne,Q as re,Ro as D,Sa as O,T as ie,Tn as k,U as A,Un as j,Ur as ae,V as M,Vn as oe,Vo as se,Wi as N,Wn as P,Wo as ce,X as le,Y as ue,Z as F,Zi as de,_i as fe,_r as I,_s as pe,a as L,at as me,cn as he,et as ge,f as _e,fa as ve,g as ye,gn as R,go as be,gr as xe,gs as Se,ho as Ce,i as we,it as Te,ji as Ee,jn as De,jo as Oe,kn as ke,ko as Ae,l as je,m as Me,n as Ne,nt as Pe,o as Fe,ot as Ie,p as Le,q as Re,r as ze,sn as Be,u as Ve,ur as He,va as Ue,vr as We,vs as Ge,wn as Ke,wt as qe,y as Je,yn as Ye,yo as Xe,ys as Ze,zn as Qe,zo as $e,zt as et}from"./src-DQNh10sB.js";import{I as z,K as B,Q as V,S as H,W as U,a as tt,b as nt,o as W,q as G,t as rt,x as K,z as q}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{K as J,W as it,a as at,dt as ot,i as st,lt as ct,ut as lt}from"./src-BASw5xKM.js";import{c as ut,k as dt,p as Y,r as ft,t as pt,u as mt}from"./player-overlays-DbjG9CoN.js";import{t as ht}from"./CapabilityBadges-Dwe2WhG2.js";import{n as gt,t as _t}from"./bell-ring-D9YniApB.js";import{t as vt}from"./boxes-DiN_50iG.js";import{t as yt}from"./ProviderIcon-Cuno3Ukn.js";import{a as bt,c as xt,l as St,n as Ct,o as wt}from"./NodeInferenceDevices-BZYBxNcz.js";import{n as Tt}from"./FormBuilder-CwPW8n7D.js";import{t as Et}from"./pencil-kKbu--Dw.js";import{t as Dt}from"./power-Bye2QkEF.js";import{t as Ot}from"./refresh-cw-CXJMAcb6.js";import{t as kt}from"./rotate-ccw-C4tkyZX7.js";import{t as At}from"./rotate-cw-Bj3hZnoL.js";import{t as jt}from"./server-CTXU8Qj1.js";import{t as Mt}from"./wifi-BJ9-mPQL.js";import{A as Nt,J as Pt,K as Ft,L as It,S as Lt,U as Rt,V as zt,W as X,a as Bt,c as Vt,d as Ht,i as Ut,j as Wt,m as Gt,q as Kt,s as qt,t as Jt,v as Yt,y as Xt,z as Zt}from"./index-DZI5dpxU.js";import{t as Qt}from"./useEventInvalidation-BgFOnvV-.js";import{t as $t}from"./StatusBadge-Dcr2bw58.js";import{i as en,n as tn,r as nn,t as rn}from"./DeviceAggregateSection-DTMCDwV1.js";var an=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`}]]),on=X(`disc`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),sn=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`}]]),cn=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`}]]),ln=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`}]]),un=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`}]]),dn=X(`scan-eye`,[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`path`,{d:`M18.944 12.33a1 1 0 0 0 0-.66 7.5 7.5 0 0 0-13.888 0 1 1 0 0 0 0 .66 7.5 7.5 0 0 0 13.888 0`,key:`11ak4c`}]]),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`}]]);V();var pn=[{id:`object-detection`,label:`Object detection`,costWhenOff:`No detections, tracks or detection-driven notifications for this camera.`,capName:lt},{id:`audio-analysis`,label:`Audio analysis`,costWhenOff:`No audio events (glass, alarm, speech) and no audio-driven notifications.`,capName:ct}],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":dn,"audio-analysis":sn,recording:on};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:e}){let t=W(),r=Number.isFinite(e),[i,a]=G(null),[o,s]=G(!1),c=k({deviceId:e},{enabled:r}),l=b({deviceType:J.Camera},{enabled:r}),d=Ue({deviceId:e},{enabled:r,retry:!1});Qt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let f=[[`deviceManager`,`getBindings`],{input:{deviceId:e}}],p=[[`recording`,`getDeviceConfig`],{input:{deviceId:e}}],m=d.data,h=xn(m)?m:null,g=yn({bindings:Cn(c.data),bindable:wn(l.data),recordingEnabled:h===null?null:h.enabled}),_=P({onError:(n,r)=>{let i=r.capName===g[1]?.capName?`audio-analysis`:`object-detection`;console.error(`[CameraFunctionSwitches] wrapper write failed — reverting`,{tags:{deviceId:e},meta:{capName:r.capName,error:n instanceof Error?n.message:String(n)}}),t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]}),a({id:i,message:n instanceof Error?n.message:String(n)})},onSuccess:()=>{a(null),t.invalidateQueries({queryKey:[[`deviceManager`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]})}}),v=O({onError:n=>{console.error(`[CameraFunctionSwitches] recording write failed — reverting`,{tags:{deviceId:e},meta:{error:n instanceof Error?n.message:String(n)}}),t.invalidateQueries({queryKey:[[`recording`,`getDeviceConfig`]]}),a({id:`recording`,message:n instanceof Error?n.message:String(n)})},onSuccess:()=>{a(null),t.invalidateQueries({queryKey:[[`recording`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]})}}),y=z(n=>{if(!n.available||n.on===null)return;let r=!n.on;if(n.id===`recording`){if(h===null)return;t.setQueryData(p,{...h,enabled:r}),v.mutate({deviceId:e,config:{...h,enabled:r}});return}let{capName:i,wrapperAddonId:a}=n;if(i===null||a===null)return;let o=t.getQueryData(f);Sn(o)&&t.setQueryData(f,_n(o,i,a,r)),_.mutate({deviceId:e,capName:i,wrapperAddonId:a,active:r})},[f,e,t,h,p,v,_]),x=vn(g,ce()),S=e=>i?.id===e.id?i.message:null;return x.layout===`menu`?H(n,{open:o,onOpenChange:s,children:[H(u,{"aria-label":`Camera functions`,title:x.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${i===null?x.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:[K(Ht,{className:`h-3.5 w-3.5`}),x.offIds.length>0&&H(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:[x.offIds.length,` off`]})]}),H(se,{className:`left-auto right-0 mt-1 min-w-[240px] p-1`,children:[K(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Camera functions`}),K(`ul`,{className:`space-y-0.5`,children:g.map(e=>K(`li`,{children:K(En,{state:e,failure:S(e),onToggle:()=>y(e)})},e.id))})]})]}):K(`div`,{className:`flex items-center gap-1`,children:g.map(e=>K(Dn,{state:e,failure:S(e),onToggle:()=>y(e)},e.id))})}function En({state:e,failure:t,onToggle:n}){let r=bn[e.id],i=e.on===null,a=e.on===!1;return H(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:i?`${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:[K(r,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 ${t===null?i?`text-foreground-subtle/50`:a?`text-warning`:`text-success`:`text-danger`}`}),H(`span`,{className:`flex-1 min-w-0`,children:[K(`span`,{className:`block leading-tight`,children:e.label}),K(`span`,{className:`block mt-0.5 text-[10px] text-foreground-subtle leading-tight`,children:t===null?i?`Unknown`:e.costWhenOff:`Write failed: ${t}`})]}),K(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${i?`bg-surface-hover text-foreground-subtle/60`:a?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:i?`—`:a?`off`:`on`})]})}function Dn({state:e,failure:t,onToggle:n}){let r=bn[e.id],i=e.on===null,a=e.on===!1,o=i?`${e.label} — state unknown; the source that owns it did not answer.`:a?`${e.label} is OFF. ${e.costWhenOff}`:`${e.label} is on. Turning it off: ${e.costWhenOff}`;return H(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:t===null?o:`${o} — 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?i?`border-dashed border-border text-foreground-subtle/50`:a?`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:[K(r,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden lg:inline`,children:e.label}),a&&K(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:`off`})]})}function On({parentDeviceId:t}){let{t:n}=Jt(),r=Ft(),i=Y(),{data:a,isLoading:o,isError:s}=wt(t),{data:c}=w({deviceId:t},{enabled:Number.isFinite(t)});if(o)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`common.loading`,{defaultValue:`Loading…`})})});if(s)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-warning`,children:n(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(a??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let u=ue(c?.stableId??``,l,c?.childLayout),d=u.ungrouped,f=e=>r(`/devices/${String(e)}`),m=c?.name??``,h=(t,n)=>K(Re,{trpc:i.trpcClient,device:{...n,name:e(n,m)},variant:`minimal`,onNavigate:f},t),g=d.some(e=>!!e.role),_=d.some(e=>!e.role),v=g&&!_?n(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?n(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):n(`device.children`,{defaultValue:`Children`}),y=d.length>0?H(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[K(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),K(`div`,{className:`space-y-1`,children:d.map(e=>h(e.id,e))})]}):null,b=u.disabledSection===void 0?null:K(p,{title:n(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:K(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>h(e.id,e))})},u.disabledSection.title);return u.sections.length===0?b===null?y:H(`div`,{className:`space-y-2`,children:[y,b]}):H(`div`,{className:`space-y-2`,children:[u.sections.map(e=>K(p,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),y,b]})}function kn({deviceId:e}){let t=Y(),{data:n,isLoading:r}=bt(e),{data:i,isLoading:a}=wt(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}}:{}})),l=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,u=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?K(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):K(`div`,{className:`flex h-full w-full flex-col`,children:K(c,{trpc:t.trpcClient,children:s,linkDeviceId:l,primaryChildEntityId:u})})}V();function An({dev:e,busy:t,setBusy:n}){let r=e?.motionTrigger,i=mt(e?.state.motionTrigger),[a,o]=G(!1);if(!r)return null;let s=i?.enabled===!0,c=i!==void 0,l=async()=>{if(t||!c)return;let e=!s;n(!0),o(!0);try{await r.setMotionTrigger({enabled:e})}finally{n(!1),o(!1)}};return H(`button`,{type:`button`,onClick:()=>{l()},disabled:t||!c,title:c?s?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":s,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${s?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[K(Rt,{className:`h-3 w-3`}),K(`span`,{children:a?s?`Disabling…`:`Enabling…`:c?s?`On motion: on`:`On motion: off`:`On motion: …`})]})}V();function Z({deviceId:e,deviceType:t,features:n}){let r=Y(),i=me(t)?.HeroCard??Ce,a=ut(r.trpcClient,e),o=mt(a?.state.deviceStatus),[s,c]=G(!1),l=o!==void 0&&o.online===!1,u=l?o.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[l?K(`div`,{className:`flex justify-center`,children:K(A,{lastChangedAt:u})}):null,K(i,{trpc:r.trpcClient,deviceId:e,features:n}),K(`div`,{className:`flex justify-center`,children:K(An,{dev:a,busy:s,setBusy:c})})]})}function jn({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:K(be,{trpc:Y().trpcClient,deviceId:e,features:t})})}function Mn({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:K(Ce,{trpc:Y().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`}V();var Bn=1500,Vn=15e3,Hn=1e3;function Un({deviceId:e}){let t=ut(Y().trpcClient,e)?.state.eventEmitter,n=mt(t);q(()=>{if(!t)return;t.refresh();let e=setInterval(()=>{t.refresh()},Vn);return()=>{clearInterval(e)}},[t]);let r=n?.lastEvent??null,i=r?.seq??null,a=B(null),[o,s]=G(!1);q(()=>{if(i===null)return;let e=a.current;if(a.current=i,e===null||e===i)return;s(!0);let t=setTimeout(()=>{s(!1)},Bn);return()=>{clearTimeout(t)}},[i]);let[c,l]=G(()=>Date.now());q(()=>{let e=setInterval(()=>{l(Date.now())},Hn);return()=>{clearInterval(e)}},[]);let u=Pn(r),d=n?.eventTypes??[],f=n?.eventCountSinceStart??0,p=n!==void 0,m=Nn(r?.data);return H(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[K(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(o),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${o?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:u??`No press recorded`,children:K(o?un:cn,{className:`h-10 w-10`})}),H(`div`,{className:`text-center`,children:[m!==null&&K(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:`Button ${String(m)}`}),K(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${u?`text-foreground`:`text-foreground-subtle`}`,children:u??(p?`No press recorded`:`Awaiting state…`)}),K(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:r?zn(r.timestamp,c):`Waiting for the first event`})]}),d.length>0&&K(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:d.map(e=>K(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===r?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),K(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(f)} ${f===1?`event`:`events`} since start`})]})}function Wn({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return H(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[K(yt,{type:n,size:`lg`}),H(`div`,{children:[K(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),K(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),H(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[K($t,{status:r?`online`:`offline`}),i.length>0&&K(ht,{capabilities:i})]}),K(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}V();function Gn({deviceId:e}){let t=W(),n=Be({deviceId:e},{refetchInterval:1e4,retry:!1}),r=he({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>Kn(n.data??[]),[n.data]);return H(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[H(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[K(qn,{label:`Discovered`,value:i.total,icon:K(Yt,{className:`h-3.5 w-3.5`})}),K(qn,{label:`Adopted`,value:i.adopted,accent:`success`}),K(qn,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),H(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[r.isPending?K(Lt,{className:`h-3.5 w-3.5 animate-spin`}):K(Ot,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),H(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[K(Jn,{icon:K(Mt,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),K(Jn,{icon:K(Xt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),K(Jn,{icon:K(Bt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?K(Jn,{icon:K(an,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.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:r}){return H(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[H(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,K(`span`,{className:`truncate`,children:e})]}),K(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function Jn({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,K(`span`,{children:t})]})}var Yn={[J.Switch]:Z,[J.Siren]:Z,[J.Light]:Z,[J.Sensor]:Z,[J.Button]:Z,[J.Hub]:Gn,[J.Cover]:jn,[J.Valve]:Z,[J.Humidifier]:Z,[J.WaterHeater]:Z,[J.Container]:kn,[J.Lock]:Z,[J.Fan]:Z,[J.Thermostat]:Z,[J.Climate]:Z,[J.MediaPlayer]:Z,[J.Control]:Z,[J.AlarmPanel]:Z,[J.EventEmitter]:Un,[J.Notifier]:Mn,[J.Script]:Z,[J.Automation]:Z,[J.Presence]:Z,[J.Update]:Z,[J.Vacuum]:Z,[J.LawnMower]:Z,[J.Weather]:Z,[J.Image]:Z,[J.PetFeeder]:Z};function Xn(e){return Yn[e]??Wn}function Zn(e){return K(Xn(e.deviceType),{...e})}function Qn(e){return L(Y().trpcClient,e)}V();function $n(e){let[t,n]=G(`idle`),[r,i]=G(null),a=B(null),o=B(null),s=B(null),c=B(!0),l=I(),u=xe(),d=We(),f=z(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null},[]),p=z(async()=>{if(t===`idle`)return;n(`stopping`);let r=s.current;if(r&&e!==null)try{await Promise.race([d.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}f(),c.current&&(n(`idle`),i(null))},[t,e,d,f]),m=z(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,f=null,m=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await l.mutateAsync({deviceId:e});m=t.sessionId,s.current=m,n(`connecting`),f=new RTCPeerConnection,a.current=f,f.oniceconnectionstatechange=()=>{if(!c.current)return;let e=f.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&c.current&&(i(e===`failed`?`WebRTC connection failed`:null),p())};for(let e of r.getAudioTracks())f.addTrack(e,r);await f.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let d=await f.createAnswer();await f.setLocalDescription(d);let h=f.localDescription?.sdp??d.sdp??``;await u.mutateAsync({deviceId:e,sessionId:m,sdpAnswer:h})}catch(t){let l=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),f)try{f.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,m!==null)try{await d.mutateAsync({deviceId:e,sessionId:m})}catch{}s.current=null,c.current&&(i(l),n(`error`))}},[e,t,l,u,d,p]);return q(()=>(c.current=!0,()=>{c.current=!1;let t=s.current;if(t!==null&&e!==null&&d.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null}),[e]),{state:t,error:r,start:m,stop:p,isTalking:t===`talking`}}V();var 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:e,greeting:t,className:n}){let r=Y(),[i,a]=G(()=>{let n=[];return t&&n.push({id:Q(),kind:`info`,text:t}),n.push({id:Q(),kind:`info`,text:`scope: ${tr(e)} — type help or context for available commands`}),n}),[o,s]=G(``),[c,l]=G([]),[u,d]=G(-1),f=B(null),p=B(null);q(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=z(()=>{f.current?.focus()},[]),h=rt({mutationFn:t=>r.trpcClient.repl.execute.mutate({code:t,scope:e}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;a(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Q(),kind:`info`,text:`scope: ${tr(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...nr(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...ir(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...rr(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Q(),kind:`input`,text:`> ${n}`}]),s(``),h.mutate(n)}}function _(t){if(t.key===`Enter`){t.preventDefault(),g(o);return}if(t.key===`ArrowUp`){if(t.preventDefault(),c.length===0)return;let e=u===-1?c.length-1:Math.max(0,u-1);d(e),s(c[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),u===-1)return;let e=u+1;e>=c.length?(d(-1),s(``)):(d(e),s(c[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),a([{id:Q(),kind:`info`,text:`scope: ${tr(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return H(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[H(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>K(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&K(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),H(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[K(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),K(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function or({deviceId:e,intercomAvailable:t=!1}){let n=Y(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=Qn(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=we(n.trpcClient,i?e:null),g=F(i?e:null,{width:dr}),_=$n(i&&t?e:null),v=_.state===`requesting-mic`||_.state===`starting`||_.state===`connecting`||_.state===`stopping`,y=_.isTalking||v,b=()=>{_.state===`idle`||_.state===`error`?_.start():_.state!==`stopping`&&_.stop()},x=ft(),C=S(),w=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,ee=x.length>0?K(nt,{children:x.map(e=>K(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return K(Je,{serverUrl:r,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h,...C.request?{playbackUrl:C.request.url,playbackAuthToken:w,...C.request.label?{playbackLabel:C.request.label}:{},onExitPlayback:()=>C.clear()}:{},streams:o,pipelineMetrics:s,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:g.src,...g.src?{posterUrl:g.src}:{},snapshotLoading:g.loading,onRefreshSnapshot:g.refresh,intercomAvailable:t,intercomShown:y,onIntercomToggle:b,extraOverlay:ee,chromeless:!0,className:`h-full`})}function sr({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full`,children:K(ye,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function cr({deviceId:e}){if(!Number.isFinite(e))return H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
2
- `);return K(ar,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function lr({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(Me,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function ur({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(_e,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}var dr=960;function fr({deviceId:e}){let t=W(),n=Number.isFinite(e),{data:r}=w({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;Qt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:c}=k({deviceId:e},{enabled:n}),{data:l}=b({deviceType:i},{enabled:!!i}),u=P({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return K(`div`,{className:`p-4`,children:K(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(s)return H(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,c instanceof Error?c.message:String(c)]});let d=new Map,f={};for(let e of l??[])f[e.capName]=e.wrappers;for(let e of a?.entries??[])d.set(e.capName,{...e,wrappers:f[e.capName]??[]});for(let e of l??[])d.has(e.capName)||d.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let p=[...d.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(p.length===0)return H(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[K(vt,{className:`h-8 w-8 opacity-40`}),K(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),K(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let m=p.filter(e=>e.kind!==`unbound`).length;return H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`text-[11px] text-foreground-subtle`,children:[K(`span`,{className:`font-medium text-foreground`,children:m}),` of `,p.length,` capabilit`,p.length===1?`y`:`ies`,` bound — rows marked `,K(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),K(x,{columns:[{key:`capability`,header:`Capability`,render:e=>K(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>K(pr,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?K(mr,{nodeId:e.providerNodeId}):K(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return K(hr,{wrappers:t.wrappers,activeWrapperId:n,disabled:u.isPending,onPick:r=>{let i=n===r;u.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:p,rowKey:e=>e.capName,minWidthPx:720})]})}function pr({kind:e}){return e===`native`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[K(jt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[K(St,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[K(ln,{className:`h-3 w-3`}),`linked`]}):H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[K(xt,{className:`h-3 w-3`}),`unbound`]})}function mr({nodeId:e}){return K(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function hr({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?K(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):K(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return H(`button`,{disabled:n,onClick:()=>r(e),title:i?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[K(i?It:kt,{className:`h-3 w-3`}),e]},e)})})}function gr({deviceId:e,activeSubTab:t,onSubTabChange:n}){return K(`div`,{className:`flex flex-col gap-3`,children:K(rn,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}V();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=W(),r=Y().trpcClient,[i,s]=G(null),[c,l]=G(null),[u,d]=G(null),f=a({deviceId:e},{refetchOnMount:`always`}),p=C({deviceId:e},{refetchOnMount:`always`}),m=te(void 0,{refetchOnMount:`always`});Qt([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let h=ae(void 0,{refetchOnMount:`always`}),g=U(()=>{let e=new Set;for(let t of h.data??[])t.isOnline&&e.add(t.id);return e},[h.data]),_=U(()=>(m.data??[]).filter(e=>g.has(e.nodeId)).map(e=>e.nodeId),[m.data,g]),y=_[0]??``,b=fe({nodeId:y},{enabled:y!==``,refetchOnMount:`always`}),x=tt({enabled:_.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,_.join(`,`),t],queryFn:async()=>{let e={};for(let t of _)try{e[t]=(await r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),S=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},w=N({onSuccess:S}),T=o({onSuccess:S}),E=U(()=>b.data?Oe(b.data):[],[b.data]),ne=U(()=>{let e=m.data??[],t=g.size===0?[]:e.filter(e=>g.has(e.nodeId)),n=[];for(let e of t){let t=(x.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},[m.data,x.data,g]),re=(e,t)=>x.data?.[e]?.find(e=>e.key===t)??null,D=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=x.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},O=(e,t,n)=>p.data?.[e]?.[t]?.[n]??null,ie=e=>{if(_r.has(e))return{kind:`zone-driven`};let t=vr(b.data??null,e)?.enabledByDefault??!0,n=f.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},k=(e,t)=>{let n=vr(b.data??null,e);if(n)return pe(n,t)},A=(e,t)=>{let n=ie(e),r=n.kind===`gate`?n.effectiveOn:!1,i=vr(b.data??null,e),a=D(t),o=a===null?null:re(t.agentNodeId,a);if(!Ze(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:O(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?Ge({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:yr(s)}},j=i&&b.data?vr(b.data,i.addonId):null,M=i?re(i.agentNodeId,i.deviceKey):null,oe=M?.format??`coreml`,se=i?yr(O(i.agentNodeId,i.deviceKey,i.addonId)):!1,P=i?k(i.addonId,M):void 0,ce=U(()=>{if(!i||!M)return null;let e=M.steps?.[i.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[i,M]),le=()=>{s(null),l(null)},ue=(e,t)=>{let n=D(t);n!==null&&(s({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),l(O(t.agentNodeId,n,e)))},F=(t,n)=>{T.mutate({deviceId:e,addonId:t,enabled:n})},de=()=>{i&&w.mutate({deviceId:e,agentNodeId:i.agentNodeId,deviceKey:i.deviceKey,addonId:i.addonId,patch:c},{onSuccess:le})},I=()=>{i&&w.mutate({deviceId:e,agentNodeId:i.agentNodeId,deviceKey:i.deviceKey,addonId:i.addonId,patch:null},{onSuccess:le})};if(m.isLoading||y!==``&&b.isLoading)return K(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(ne.length===0)return K(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!b.data)return K(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let L=i!==null&&j!==null&&M!==null;return H(`div`,{className:`relative h-full w-full space-y-3`,children:[H(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[K(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,K(`span`,{className:`font-medium text-foreground`,children:`node column`}),` shows the model that node runs; click a cell to pin a per-camera model override for that accelerator. A gated-on step with no model on a device shows a clickable `,K(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),H(`div`,{className:`rounded-md border border-sky-500/25 bg-sky-500/[0.06] px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[K(`span`,{className:`font-medium text-sky-400`,children:`Placement is dynamic.`}),` When a node has multiple inference accelerators, each session is balanced across them per-session at dispatch time — these device columns show each accelerator's effective model (override ?? device default), not a fixed assignment.`]}),K(`div`,{className:L?`md:pr-[360px]`:``,children:E.length>0?K(ee,{tree:E,agents:ne,gateFor:ie,getCellState:A,onCellClick:ue,selectedCell:i,onSetGate:F,gateBusy:T.isPending,fallbackNodeId:u,onFallbackNodeChange:d}):K(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),K(v,{open:L,onClose:le,title:j?.name??``,subtitle:i&&M?`${i.agentNodeId} · ${Ct(M).label} · ${M.format}`:``,footer:H(nt,{children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle disabled:opacity-50`,disabled:!se||w.isPending,onClick:I,children:`Clear override`}),K(`div`,{className:`flex-1`}),K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:le,children:`Cancel`}),K(`button`,{type:`button`,disabled:!i||!ce||w.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:de,children:w.isPending?`Saving…`:`Save`})]}),children:j&&i&&ce?K(Ae,{mode:`device`,addon:j,agentDefault:ce,agentNodeId:i.agentNodeId,currentPatch:c,engineFormat:oe,effectiveModelId:P,onChangePatch:l}):K(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}var 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`}V();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:e,activeSubTab:t,onSubTabChange:n}){return H(d,{value:t&&Er.has(t)?t:wr,onValueChange:z(e=>{n?.(e)},[n]),className:`flex flex-col`,children:[H(D,{className:`flex-shrink-0`,children:[K($e,{value:wr,children:`Steps`}),K($e,{value:Tr,children:`Settings`})]}),K(g,{value:wr,children:K(br,{deviceId:e,refreshToken:0})}),K(g,{value:Tr,children:K(rn,{deviceId:e,sectionFilter:Dr,subTabGrouping:{groupOf:e=>Cr(e.id),tabs:xr}})})]})}function $({label:e,value:t}){return H(`div`,{className:`${dt} flex items-start gap-2 sm:gap-3`,children:[K(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),K(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}V();function kr({deviceId:e,initialName:t}){let n=W(),[r,i]=G(!1),[a,o]=G(t),[s,c]=G(!1),l=B(null);q(()=>{r||o(t)},[t,r]),q(()=>{r&&l.current?.focus()},[r]);let u=oe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),d=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),o(t);return}c(!0);try{await u.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{c(!1)}},f=()=>{o(t),i(!1)};return r?K($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-1`,children:[K(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?d():e.key===`Escape`&&f()},disabled:s,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),K(`button`,{type:`button`,onClick:()=>void d(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:K(It,{className:`h-3 w-3`})}),K(`button`,{type:`button`,onClick:f,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:K(Ut,{className:`h-3 w-3`})})]})}):K($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[K(`span`,{className:`truncate`,children:t}),K(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:K(Et,{className:`h-3.5 w-3.5`})})]})})}V();function Ar({deviceId:e,initialLocation:n}){let r=W(),[i,a]=G(!1),[o,s]=G(n??``),[c,l]=G(!1),u=B(null),{data:d}=E(void 0,{enabled:i}),f=d??[];q(()=>{i||s(n??``)},[n,i]),q(()=>{i&&u.current?.focus()},[i]);let p=t({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),r.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),r.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),r.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),m=U(()=>{let e=o.trim().toLowerCase();return e.length===0?f:f.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[f,o]),h=o.trim().length>0&&!f.some(e=>e.toLowerCase()===o.trim().toLowerCase()),g=async t=>{let r=(t??o).trim(),i=r.length===0?null:r;if(i===(n??null)){a(!1);return}l(!0);try{await p.mutateAsync({deviceId:e,location:i}),a(!1)}catch{}finally{l(!1)}},_=()=>{s(n??``),a(!1)};return i?K($,{label:`Location`,value:H(`div`,{className:`relative`,children:[H(`div`,{className:`flex items-center gap-1`,children:[K(`input`,{ref:u,type:`text`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`?g():e.key===`Escape`&&_()},disabled:c,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),K(`button`,{type:`button`,onClick:()=>void g(),disabled:c,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:K(It,{className:`h-3 w-3`})}),K(`button`,{type:`button`,onClick:_,disabled:c,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:K(Ut,{className:`h-3 w-3`})})]}),(m.length>0||h)&&H(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[m.map(e=>H(`button`,{type:`button`,onClick:()=>{s(e),g(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[K(Tt,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),K(`span`,{className:`truncate`,children:e})]},e)),h&&H(`button`,{type:`button`,onClick:()=>void g(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[K(`span`,{className:`text-foreground-subtle`,children:`Create`}),H(`span`,{className:`font-medium truncate`,children:[`"`,o.trim(),`"`]})]})]})]})}):K($,{label:`Location`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[n?K(`span`,{className:`truncate`,children:n}):K(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),K(`button`,{type:`button`,onClick:()=>a(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:K(Et,{className:`h-3.5 w-3.5`})})]})})}V();function jr({deviceId:e}){let t=W(),{data:n}=bt(e),{data:r}=wt(e),[i,a]=G(null),o=l({onSuccess:()=>{a(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{a(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==J.Container)return null;let s=(r??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(s.length<=1)return null;let c=Te(s,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return H(nt,{children:[K($,{label:`Primary child`,value:K(M,{childrenList:s,selectedId:c===null?s[0].id:c.id,onSetPrimary:t=>o.mutate({deviceId:e,primaryChildEntityId:t}),disabled:o.isPending})}),i!==null&&K(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:i})]})}V();var 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=y(),t=T(),{data:n}=w({deviceId:e??0},{enabled:e!==null}),{data:r}=k({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[a,o]=G(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),c=String(i.name??``),l=String(i.type??``),u=String(i.addonId??``),d=i.features??[],f=new Set([`device-status`,`feature-probe`,`device-ops`]),p=(r?.entries??[]).filter(e=>e.kind===`native`&&!f.has(e.capName)).map(e=>e.capName),m=d.length>0?d:p,h=i.location??null,g=i.metadata??null,_=g!==null&&Object.keys(g).length>0;return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[H(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[K(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),_&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[K(Ir,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),K(Ir,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!_||a===`identity`)&&H(`div`,{className:`divide-y divide-border`,children:[K($,{label:`ID`,value:H(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,H(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,s,`)`]})]})}),K(kr,{deviceId:e,initialName:c}),K(Ar,{deviceId:e,initialLocation:h}),K(jr,{deviceId:e}),K($,{label:`Type`,value:l}),K($,{label:`Provider`,value:K(yt,{type:u,size:`sm`,showLabel:!0})}),K($,{label:`Capabilities`,value:m.length>0?K(ht,{capabilities:m,showLabels:!0}):K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),_&&a===`hardware`&&K(Lr,{metadata:g})]})}function Ir({active:e,onClick:t,label:n}){return K(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function Lr({metadata:e}){let t=Mr.filter(t=>t in e),n=Object.keys(e).filter(e=>!Mr.includes(e)).toSorted(),r=[...t,...n];return H(`div`,{children:[K(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),K(`div`,{className:`divide-y divide-border`,children:r.map(t=>K($,{label:Nr(t),value:K(`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}}V();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:e}){let t=W(),n=Number.isFinite(e),[r,i]=G(null),[a,o]=G(null),c=Br({mutedDeviceIds:Hr(s({},{enabled:n}).data),deviceId:e,pendingOn:a}),l=m({onError:n=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:e},meta:{error:n instanceof Error?n.message:String(n)}}),o(null),i(n instanceof Error?n.message:String(n)),t.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{i(null),o(null),t.invalidateQueries({queryKey:[[`notificationRules`]]})}}),u=z(()=>{let t=Vr(c,e);t!==null&&(o(!t.muted),l.mutate(t))},[e,l,c]),d=c.on===null,f=c.on===!1,p=f?gt:_t;return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[H(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[K(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Notifications`}),f&&K(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:`muted`})]}),H(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[H(`button`,{type:`button`,role:`switch`,"aria-label":c.label,"aria-checked":c.on===!0,disabled:!c.available||l.isPending,onClick:u,title:d?`Notification mute — state unknown; the notification centre did not answer.`:f?`Muted. ${c.costWhenOff}`:`Notifying. Muting it: ${c.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 ${r===null?d?`border-dashed border-border text-foreground-subtle/50`:f?`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:[K(p,{className:`h-3.5 w-3.5`}),K(`span`,{children:d?`Unknown`:f?`Muted`:`Notifying`})]}),K(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:r===null?d?`The notification centre did not answer, so this device’s mute state is unknown.`:c.costWhenOff:`Write failed: ${r}`})]})]})}V();function Wr({deviceId:e}){let[t,n]=G(null),r=R({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return H(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[H(`div`,{className:`flex items-center justify-between gap-3`,children:[H(`div`,{children:[K(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),K(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),H(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[K(Ot,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&K(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}V();var 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=Y(),n=W(),{data:r}=w({deviceId:e},{enabled:e>0}),i=typeof r?.role==`string`?r.role:null,a=i===null?void 0:Ie[i],o=a?.kind===`numeric`,s=Ne(t.trpcClient,e,i??``),c=a?.kind===`numeric`?a.canonicalUnit:void 0,l=qr(s)??c,u=l===void 0?void 0:st(l),d=U(()=>u===void 0?[]:at(u),[u]),[f,p]=G(null),m=f??Kr(r?.display),h=Qe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:g}=De({},{staleTime:6e4}),_=j({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(r===void 0||i===null)return null;let v=e=>{p({...m,...e})},y=()=>{h.mutate({deviceId:e,display:Jr(m)})},b=()=>{p(Gr),h.mutate({deviceId:e,display:null})},x=()=>{let e={...m.icon===``?{}:{icon:m.icon},...m.unit===``?{}:{unit:m.unit},...m.precision.trim()!==``&&Number.isFinite(Number.parseInt(m.precision,10))?{precision:Number.parseInt(m.precision,10)}:{}},t={...g?.defaults,[i]:e};_.mutate({defaults:t})},S=Pe(i).label,C=Object.keys(ge);return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[K(`div`,{className:`border-b border-border px-4 py-2`,children:K(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Display`})}),H(`div`,{className:`p-4 space-y-3`,children:[H(`label`,{className:`block`,children:[K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Icon`}),H(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:m.icon,onChange:e=>v({icon:e.target.value}),children:[H(`option`,{value:``,children:[`Default (`,S,`)`]}),C.map(e=>K(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Label`}),K(`input`,{type:`text`,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:S,value:m.label,onChange:e=>v({label:e.target.value})})]}),o&&H(`div`,{className:`grid grid-cols-2 gap-3`,children:[H(`label`,{className:`block`,children:[K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Unit`}),H(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:m.unit,onChange:e=>v({unit:e.target.value}),disabled:d.length===0,children:[H(`option`,{value:``,children:[`Source`,l?` (${l})`:``]}),d.map(e=>K(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Precision`}),K(`input`,{type:`number`,min:0,max:10,step:1,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:`inherit`,value:m.precision,onChange:e=>v({precision:e.target.value})})]})]}),H(`label`,{className:`flex items-center gap-2`,children:[K(`input`,{type:`checkbox`,checked:m.hidden,onChange:e=>v({hidden:e.target.checked})}),K(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),H(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[K(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-sm font-medium text-primary-foreground disabled:opacity-50`,onClick:y,disabled:h.isPending,children:`Save`}),K(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:b,disabled:h.isPending,children:`Reset`}),H(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:x,disabled:_.isPending,title:`Apply this unit / precision / icon as the default for every ${S} sensor`,children:[`Set as default for all `,S,` sensors`]})]})]})]})}function Xr(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Zr({device:e}){let t=Ft(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===J.Camera,a=r===J.Hub,o=typeof e.role==`string`&&e.role.length>0,s=e.features??[],c=s.includes(it.Resyncable),{data:l}=f({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),p=s.includes(it.DoorbellButton),m=ze(p?{deviceId:n??void 0,historyLimit:10}:void 0),h=m.latest?Date.now()-m.latest.timestamp<3e4:!1;return H(`div`,{className:`space-y-5`,children:[a&&n!==null&&K(Le,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&K(Wr,{deviceId:n}),n!==null&&K(Ur,{deviceId:n}),i&&n!==null&&K(ie,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),p&&K(Ve,{history:m.history,latestIsFresh:h}),i&&n!==null&&K(ie,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&d.length>0&&H(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[K(`div`,{className:`border-b border-border px-4 py-2`,children:K(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),K(`div`,{className:`divide-y divide-border`,children:d.map(([e,t])=>H(`div`,{className:`px-4 py-2.5`,children:[H(`div`,{className:`flex items-center gap-2 mb-2`,children:[K(Mt,{className:`h-3 w-3 text-foreground-subtle`}),K(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),H(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[K(Qr,{label:`Nominal`,value:Xr(t.nominalBitrateKbps??0)}),K(Qr,{label:`Observed`,value:Xr(t.observedBitrateKbps??0)}),K(Qr,{label:`Peak`,value:Xr(t.peakBitrateKbps??0)}),K(Qr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),K(Fr,{}),o&&n!==null&&K(Yr,{deviceId:n})]})}function Qr({label:e,value:t,warning:n}){return H(`div`,{children:[K(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),K(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}V();var $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===J.Camera;return $r.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var ti=[{id:`logs`,icon:Gt,label:`Logs`},{id:`repl`,icon:Vt,label:`REPL`},{id:`events`,icon:zt,label:`Events`},{id:`state`,icon:Nt,label:`State`}];function ni(){let e=Kt(),t=Number(e.deviceId),n=Number.isFinite(t),a=Ft(),o=W(),s=Xe(),c=Y(),[l,u]=Pt(),d=l.get(`tab`)??`overview`,f=l.get(`sub`),[p,m]=G(`logs`),g=`device-detail.left-col-width-px`,[v,y]=G(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(g),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),b=B(v);b.current=v;function x(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??v??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{y(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=b.current;if(e!==null)try{window.localStorage.setItem(g,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:S,isLoading:C,isError:ee}=w({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:T}=ke({deviceId:t},{enabled:n}),te=U(()=>{let e=T?.settings?.sections??[],t=T?.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(en)&&r.add(tn),[...r].map(e=>e===`export`?{id:e,label:nn,isAddonContrib:!0}:{id:e,label:ot[e]?.label??e,isAddonContrib:!0})},[T]),E=S,D=String(E?.name??e.deviceId??`Device`),O=E?.online===!0,ie=O?`online`:`offline`,k=String(E?.addonId??`rtsp`),A=E?.features??[],j=E?.type,ae=j===J.Camera,{data:M}=wt(n?t:0),oe=j===J.Container,se=U(()=>(M??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[M]),N=U(()=>oe?Te(se,typeof E?.linkDeviceId==`number`?E.linkDeviceId:null,typeof E?.primaryChildEntityId==`string`?E.primaryChildEntityId:null)?.id??null:null,[oe,se,E?.linkDeviceId,E?.primaryChildEntityId]),{data:P}=ke({deviceId:N??0},{enabled:N!==null}),ue=U(()=>{if(N===null)return[];let e=P?.settings?.sections??[],t=P?.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:ot[e]?.label??e,isAddonContrib:!0,childDeviceId:N}))},[N,P]),F=typeof E?.parentDeviceId==`number`?E.parentDeviceId:null,{data:fe}=w({deviceId:F??0},{enabled:F!==null}),I=ce(),pe=E?.disabled!==!0,L=U(()=>{let e=new Set,t=[];for(let n of[...ei(j),...te,...ue])e.has(n.id)||(e.add(n.id),t.push(n));return t},[j,te,ue]),me=U(()=>L.some(e=>e.id===d)?d:`overview`,[L,d]),he=z(e=>{u(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[u]),ge=z(e=>{u(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[u]),_e=(M??[]).length>0,ye=U(()=>ti.filter(({featureGate:e})=>!e||A.includes(e)),[A]),{data:R}=He({addonId:k},{enabled:!!k&&k!==`rtsp`}),be=h({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]}),a(R?.id?`/integrations/${R.id}`:`/integrations`)}}),xe=Ke({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Se=Ye({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ce=ve(),we=qe({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=A.includes(it.Rebootable),Oe=A.includes(it.BatteryOperated),Ae=re(c.trpcClient,Oe&&n?t:null),[Me,Ne]=G(!1),Pe=ut(c.trpcClient,n?t:null),Ie=async()=>{if(!(Me||!Pe)){Ne(!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=D.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{Ne(!1)}}},Le=xe.isPending||Se.isPending,{data:Re}=Ee({deviceId:t},{enabled:n,refetchInterval:1e4}),ze=Re?.agentNodeId??null,Be=typeof ze==`string`&&ze.length>0&&!ze.startsWith(`addon:`)?ze:void 0,{data:Ve}=de({deviceId:t,...Be?{nodeId:Be}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:Ue}=et({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),We=Ue?.level?.dbfs??null;function Ge(){if(!n)return null;switch(me){case`overview`:return K(Zr,{device:E??{}});case`config`:return K(gr,{deviceId:t,activeSubTab:f,onSubTabChange:ge});case`detection-pipeline`:return K(Or,{deviceId:t,activeSubTab:f,onSubTabChange:ge});case`bindings`:return K(fr,{deviceId:t});default:{let e=me,n=te.some(t=>t.id===e),r=ue.find(t=>t.id===e);if(!n&&r===void 0)return null;let i=r?.childDeviceId??t;if(e===`export`)return K(rn,{deviceId:t,sectionFilter:en,activeSubTab:f,onSubTabChange:ge});let a=K(rn,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:f,onSubTabChange:ge});return r!==void 0&&i!==t?K(_,{deviceId:i,children:a}):a}}}return n?C?H(`div`,{className:`flex flex-col h-full`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[K(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),K(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),K(`div`,{className:`flex-1 p-6`,children:K(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):ee||!S?H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),H(`p`,{className:`text-xs`,children:[`No device with ID`,` `,H(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,t]})]}),K(`button`,{onClick:()=>a(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):H(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[K(`div`,{className:`mb-2`,children:K(ne,{items:[{label:`Integrations`,onClick:()=>a(`/integrations`)},{label:R?.name??k,onClick:()=>R?.id&&a(`/integrations/${R.id}`)},{label:D}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[K(yt,{type:k,size:`lg`}),H(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[K(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:D}),K($t,{status:ie}),Oe&&K(le,{status:Ae,variant:`full`})]}),F!==null&&fe&&H(`button`,{type:`button`,onClick:()=>a(`/devices/${F}`),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:[K(`span`,{children:`↑`}),K(`span`,{className:`truncate`,children:String(fe.name??`Device #${F}`)})]}),K(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:A.length>0&&K(ht,{capabilities:A})})]}),Ve&&K(`div`,{className:`hidden lg:flex`,children:K(ri,{metrics:Ve,dbfs:We})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{pe?await s({title:`Disable "${D}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Se.mutate({deviceId:t}):xe.mutate({deviceId:t})},disabled:Le,title:pe?`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 ${pe?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[K(Dt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:Le?`Updating…`:pe?`Enabled`:`Disabled`})]}),K(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),ae&&H(nt,{children:[K(Tn,{deviceId:t}),K(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),K(je,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:Zt,disabled:Me,onClick:()=>{Ie()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:At,hidden:!De,disabled:Ce.isPending,danger:!0,onClick:async()=>{await s({title:`Reboot "${D}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Ce.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??k}.`,icon:Ot,disabled:we.isPending,danger:!0,onClick:async()=>{await s({title:`Restart "${R?.name??k}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${D}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&we.mutate({addonId:k})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:qt,separatorBefore:!0,disabled:be.isPending,danger:!0,onClick:async()=>{await s({title:`Delete "${D}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&be.mutate({deviceId:t})}}]})]})]})]}),K(_,{deviceId:t,device:E??void 0,children:K(r,{children:K(i,{children:K(pt,{children:K(Fe,{children:H(`main`,{className:I?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[H(`div`,{className:I?`flex flex-col bg-surface`:`${v===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!I&&v!==null?{width:`${String(v)}px`}:void 0,children:[K(`div`,{className:ae?`flex-shrink-0 border-b border-border-subtle bg-black`:I?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:ae?K(or,{deviceId:t,intercomAvailable:A.includes(it.TwoWayAudio)}):K(Zn,{deviceId:t,deviceName:D,deviceType:j??`unknown`,provider:k,isOnline:O,features:A})}),H(`div`,{className:I?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[K(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:K(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:ye.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>m(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${p===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[K(n,{className:`h-3 w-3`}),t]},e))})}),H(`div`,{className:I?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[p===`logs`&&K(sr,{deviceId:t,containerDeviceId:j===`container`?t:void 0}),p===`repl`&&K(cr,{deviceId:t}),p===`events`&&K(lr,{deviceId:t}),p===`state`&&K(ur,{deviceId:t})]})]})]}),!I&&K(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:x,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:K(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),H(`div`,{className:I?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[K(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:K(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:L.map(e=>{let t=me===e.id;return H(`button`,{onClick:()=>he(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&K(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),H(`div`,{className:I?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[me===`overview`&&_e&&K(On,{parentDeviceId:t}),Ge()]})]})]})})})})})})]}):H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),H(`p`,{className:`text-xs`,children:[`The URL segment`,` `,K(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),K(`button`,{onClick:()=>a(`/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=Se(e.phase??`idle`);return H(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[H(`div`,{className:`flex items-center gap-1.5`,children:[K(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),K(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),K(`div`,{className:`h-3 w-px bg-border`}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(Rt,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),K(`span`,{children:`fps`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(Wt,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),K(`span`,{children:`ms`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[K(fn,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),K(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&H(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{ni as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{$o as e,$r as t,Eo as n,K as r,Mn as i,Nr as a,Qo as o,R as s,Xr as c,Yr as l,Zr as u,ai as d,bo as f,bt as p,cs as m,di as h,ei as g,fi as ee,ii as _,li as v,ls as y,mo as te,ni as b,oi as x,os as S,pi as C,qr as w,si as T,ss as E,ti as D,ui as O,us as k,z as A}from"./src-DQNh10sB.js";import{I as j,K as M,Q as N,S as P,U as F,W as I,a as L,b as ne,i as R,o as re,q as z,x as B,z as V}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{K as H,R as U,pt as W}from"./src-BASw5xKM.js";import{p as ie}from"./player-overlays-DbjG9CoN.js";import{t as ae}from"./clock-DjX5RXHX.js";import{t as oe}from"./copy-D-YMZRHs.js";import{t as se}from"./download-6fSuEAL_.js";import{a as ce,c as G,d as le,f as ue,i as de,m as fe,n as pe,o as me,p as he,r as ge,s as _e,t as ve}from"./debounced-invalidate-KNk1lqIR.js";import{t as ye}from"./refresh-cw-CXJMAcb6.js";import{t as be}from"./search-CXrulua-.js";import{t as xe}from"./square-check-big-Ckw0U2GC.js";import{t as Se}from"./square-D6F6VTs4.js";import{t as Ce}from"./undo-2-LPb-dD6w.js";import{E as we,I as Te,L as Ee,M as De,P as Oe,S as K,U as ke,W as q,i as Ae,l as je,s as Me,t as Ne}from"./index-DZI5dpxU.js";import{t as Pe}from"./AdminPage-Dq33XE9j.js";import{i as Fe,n as Ie,t as Le}from"./authed-media-B8T1dsFh.js";import{t as Re}from"./AdminTabs-BTLJApFW.js";var ze=q(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),Be=q(`bug`,[[`path`,{d:`m8 2 1.88 1.88`,key:`fmnt4t`}],[`path`,{d:`M14.12 3.88 16 2`,key:`qol33r`}],[`path`,{d:`M9 7.13v-1a3.003 3.003 0 1 1 6 0v1`,key:`d7y7pr`}],[`path`,{d:`M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6`,key:`xs1cw7`}],[`path`,{d:`M12 20v-9`,key:`1qisl0`}],[`path`,{d:`M6.53 9C4.6 8.8 3 7.1 3 5`,key:`32zzws`}],[`path`,{d:`M6 13H2`,key:`82j7cp`}],[`path`,{d:`M3 21c0-2.1 1.7-3.9 3.8-4`,key:`4p0ekp`}],[`path`,{d:`M20.97 5c0 2.1-1.6 3.8-3.5 4`,key:`18gb23`}],[`path`,{d:`M22 13h-4`,key:`1jl80f`}],[`path`,{d:`M17.2 17c2.1.1 3.8 1.9 3.8 4`,key:`k3fwyw`}]]),Ve=q(`circle-dashed`,[[`path`,{d:`M10.1 2.182a10 10 0 0 1 3.8 0`,key:`5ilxe3`}],[`path`,{d:`M13.9 21.818a10 10 0 0 1-3.8 0`,key:`11zvb9`}],[`path`,{d:`M17.609 3.721a10 10 0 0 1 2.69 2.7`,key:`1iw5b2`}],[`path`,{d:`M2.182 13.9a10 10 0 0 1 0-3.8`,key:`c0bmvh`}],[`path`,{d:`M20.279 17.609a10 10 0 0 1-2.7 2.69`,key:`1ruxm7`}],[`path`,{d:`M21.818 10.1a10 10 0 0 1 0 3.8`,key:`qkgqxc`}],[`path`,{d:`M3.721 6.391a10 10 0 0 1 2.7-2.69`,key:`1mcia2`}],[`path`,{d:`M6.391 20.279a10 10 0 0 1-2.69-2.7`,key:`1fvljs`}]]),He=q(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Ue=q(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),We=q(`graduation-cap`,[[`path`,{d:`M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z`,key:`j76jl0`}],[`path`,{d:`M22 10v6`,key:`1lu8f3`}],[`path`,{d:`M6 12.5V16a6 3 0 0 0 12 0v-3.5`,key:`1r8lef`}]]),Ge=q(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]),Ke=q(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);N();var qe=`pipeline-analytics`,Je=`debug.listTracks`,Ye=`debug.analyze`,Xe=`/addon/pipeline-analytics/debug-export`;function Ze(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Qe(e,t){let n=e[t];return typeof n==`string`?n:null}function J(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function $e(e,t){let n=e[t];return typeof n==`boolean`?n:null}function et(e){return e===`error`||e===`warn`||e===`info`}function tt(e){if(!Ze(e))return null;let t=Qe(e,`code`),n=Qe(e,`detail`),r=e.severity;return t===null||n===null||!et(r)?null:{code:t,severity:r,detail:n}}function nt(e){if(!Ze(e))return null;let t=Qe(e,`trackId`),n=J(e,`deviceId`),r=Qe(e,`className`),i=J(e,`firstSeen`),a=J(e,`lastSeen`),o=J(e,`durationMs`),s=$e(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Qe(e,`label`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},firstSeen:i,lastSeen:a,durationMs:o,active:s}}function rt(e){let t=nt(e);if(t===null||!Ze(e))return null;let n=J(e,`mediaCount`),r=J(e,`eventCount`),i=J(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=tt(e);t!==null&&c.push(t)}return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c}}function it(e){if(!Ze(e))return null;let t=$e(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=nt(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function at(e){if(!Ze(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=rt(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var ot={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`};function st(e){return ot[e]??e}var ct={error:0,warn:1,info:2};function lt(e){return e.toSorted((e,t)=>ct[e.severity]-ct[t.severity]||e.code.localeCompare(t.code))}function ut(e){return e.length===0?Xe:`${Xe}?deviceIds=${e.join(`,`)}`}function dt(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}var ft=`all`,pt=`The server answered in a shape this build does not understand.`,mt={error:`danger`,warn:`warning`,info:`info`};function ht({findings:e}){return e.length===0?B(y,{variant:`success`,children:`no anomaly found`}):B(`div`,{className:`flex flex-wrap gap-1`,children:lt(e).map(e=>B(y,{variant:mt[e.severity],title:e.detail,children:st(e.code)},e.code))})}function gt({track:e,report:t,cameraName:n,analyzing:r}){return P(`div`,{className:`flex flex-col gap-1.5 border-b border-border px-3 py-2.5 last:border-b-0`,children:[P(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[B(`span`,{className:`font-medium text-foreground`,children:n}),B(`span`,{className:`text-foreground-subtle`,children:e.label??e.className}),P(`span`,{className:`text-foreground-subtle`,children:[new Date(e.lastSeen).toLocaleString(),` · `,dt(e.durationMs)]}),e.active&&B(y,{variant:`default`,children:`still open`}),t!==void 0&&P(`span`,{className:`text-foreground-subtle`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),B(`div`,{className:`flex items-center gap-2`,children:t===void 0?B(`span`,{className:`text-xs text-foreground-subtle`,children:r?`analysing…`:`not analysed`}):B(ht,{findings:t.findings})}),B(`code`,{className:`text-[10px] text-foreground-subtle`,children:e.trackId})]})}function _t(){let e=ie(),[t,n]=z(ft),[r,a]=z(!1),[o,s]=z(null),c=i({}),l=I(()=>[{value:ft,label:`All cameras`},...(c.data??[]).map(e=>({value:String(e.id),label:e.name}))],[c.data]),u=I(()=>{let e=new Map;for(let t of c.data??[])e.set(t.id,t.name);return e},[c.data]),d=I(()=>t===ft?[]:[Number.parseInt(t,10)],[t]),p=L({queryKey:[`events-debug`,`list`,d],queryFn:async()=>it(await e.trpcClient.addons.custom.mutate({addonId:qe,action:Je,input:d.length===0?{}:{deviceIds:d}}))}),h=I(()=>(p.data?.tracks??[]).map(e=>e.trackId),[p.data]),g=L({queryKey:[`events-debug`,`analyze`,h],enabled:h.length>0,queryFn:async()=>at(await e.trpcClient.addons.custom.mutate({addonId:qe,action:Ye,input:{trackIds:h}}))}),ee=I(()=>{let e=new Map;for(let t of g.data?.reports??[])e.set(t.trackId,t);return e},[g.data]),_=()=>{p.refetch(),g.refetch()},v=async()=>{a(!0),s(null);try{await Ie(ut(d),`camstack-debug.zip`)}catch(e){s(e instanceof Error?e.message:`Export failed.`)}finally{a(!1)}},y=p.data?.tracks??[],te=p.data===null||g.data===null;return B(Pe,{children:P(`section`,{className:`space-y-3`,children:[P(`div`,{className:`flex flex-wrap items-center gap-2`,children:[B(`div`,{className:`w-44`,children:B(S,{value:t,options:l,onChange:e=>n(e.target.value)})}),P(k,{variant:`secondary`,onClick:_,disabled:p.isFetching,children:[p.isFetching?B(K,{className:`h-3.5 w-3.5 animate-spin`}):B(ye,{className:`h-3.5 w-3.5`}),`Refresh`]}),P(k,{onClick:()=>void v(),disabled:r||y.length===0,children:[r?B(K,{className:`h-3.5 w-3.5 animate-spin`}):B(se,{className:`h-3.5 w-3.5`}),`Export all (`,String(y.length),`)`]})]}),P(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,B(`code`,{children:`debug`}),` mark does not pin retention — this lists the marked tracks that still exist. A track whose media was evicted shows as missing media.`]}),p.isError&&B(f,{message:`Could not load the marked tracks.`}),te&&!p.isError&&B(f,{message:pt}),o!==null&&B(f,{message:o}),p.data?.truncated===!0&&B(f,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(g.data?.vanished.length??0)>0&&P(`p`,{className:`text-xs text-foreground-subtle`,children:[String(g.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),B(m,{children:p.isLoading?B(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`}):y.length===0?P(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[B(Be,{className:`h-5 w-5 text-foreground-subtle`}),B(`p`,{className:`text-xs text-foreground-subtle`,children:`No track is marked for debug. Mark one from a track's actions to see it here.`})]}):y.map(e=>B(gt,{track:e,report:ee.get(e.trackId),cameraName:u.get(e.deviceId)??`Camera ${String(e.deviceId)}`,analyzing:g.isFetching},e.trackId))})]})})}function vt(e){return e.subLabel??e.label}var yt=720*60*60*1e3;function bt(e){let t=[];for(let n of e)t.push(...n);return t}function xt(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function St(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function Ct(e,t){return`${String(e)}:${t}`}function wt(e,t){let n=new Map,r=new Set;for(let i of e){let e=Ct(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function Tt(e,t){return{since:e.fromMs??t-yt,until:e.toMs??t}}var Y=typeof l==`function`,Et=`Track deletion arrives with the next server update`;function Dt(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Ot=Y?l:Dt,kt=200,At=3e4;function jt(e){let t=ie(),n=R({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:At,refetchInterval:At,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:kt,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:xt(bt(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}N();var Mt=[`events-feed`],Nt=2e3;function Pt(e){let t=re(),r=e?.paused===!0,i=M(t);i.current=t;let a=M(r);a.current=r;let[o,s]=z(!1),c=j(()=>{i.current.invalidateQueries({queryKey:Mt})},[]),l=M(void 0);l.current||=ve({delayMs:Nt,invalidate:()=>{a.current?s(!0):c()}}),V(()=>()=>l.current?.cancel(),[]),V(()=>{r||!o||(s(!1),c())},[r,o,c]);let u=j(()=>{s(!1),c()},[c]);return n(W.PipelineAnalyticsDetectionEvent,()=>{l.current?.trigger()}),n(W.PipelineAnalyticsTrackEnded,()=>{l.current?.trigger()}),{pending:o,refreshNow:u}}N();function Ft({groups:e,selected:t,onChange:n,loading:r=!1}){let{t:i}=Ne(),[a,o]=z(!1),[c,l]=z(``),[u,d]=z(new Set),f=c.trim().toLowerCase(),p=e=>f.length===0||s(e,i).toLowerCase().includes(f),m=I(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>p(t)||p(e.macro))})).filter(e=>p(e.macro)||e.subs.length>0),[e,f]),h=e=>d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),g=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},ee=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},_=()=>n(new Set),v=t.size;return P(`div`,{className:`relative`,children:[P(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${v>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[B(Ke,{className:`h-3.5 w-3.5`}),v>0?`Kinds (${String(v)})`:`Kinds`,B(Te,{className:`h-3 w-3`})]}),a&&P(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[P(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[B(be,{className:`h-3.5 w-3.5 text-foreground-subtle`}),B(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),v>0&&B(`button`,{type:`button`,onClick:_,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),m.length===0&&B(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:r?`Loading kinds…`:f.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),m.map(e=>{let n=A(e.macro.iconId),r=u.has(e.macro.kind)||f.length>0,a=t.has(e.macro.kind);return P(`div`,{className:`mb-0.5`,children:[P(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?B(`button`,{type:`button`,onClick:()=>h(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:B(r?Te:Oe,{className:`h-3 w-3`})}):B(`span`,{className:`w-3`}),P(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[B(`input`,{type:`checkbox`,checked:a,onChange:()=>g(e),className:`accent-primary`}),B(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),B(`span`,{className:`font-medium`,children:s(e.macro,i)})]})]}),r&&e.subs.map(e=>{let n=A(e.iconId);return P(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[B(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>ee(e.kind),className:`accent-primary`}),B(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),B(`span`,{children:s(e,i)})]},e.kind)})]},e.macro.kind)})]})]})}function It(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function Lt(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var Rt=new Set([`detection`,`package`]);function zt(e,t){return[...It(e,t).values()].filter(e=>e.parentKind===null&&Rt.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Bt(e,t){let n=It(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,Lt(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}N();var Vt=1400,Ht=`Admin-gated URL — opens only inside an authenticated session`;function Ut({label:e,value:t,title:n}){let[r,i]=z(!1);return V(()=>{if(!r)return;let e=setTimeout(()=>i(!1),Vt);return()=>clearTimeout(e)},[r]),P(`button`,{type:`button`,onClick:j(()=>{(async()=>{try{await navigator.clipboard.writeText(t),i(!0)}catch{window.prompt(`Copy the media URL:`,t)}})()},[t]),title:n,"aria-label":`Copy ${e} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${r?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[B(r?Ee:oe,{className:`h-2.5 w-2.5 shrink-0`}),B(`span`,{className:`truncate`,children:r?`Copied`:e})]})}function Wt({localUrl:e,publicUrl:t}){return P(`div`,{className:`flex flex-wrap gap-1`,children:[B(Ut,{label:`Local`,value:e,title:`Copy LAN URL — ${Ht}`}),t&&B(Ut,{label:`Public`,value:t,title:`Copy public URL — ${Ht}`})]})}var Gt={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function Kt(e){return e in Gt}function qt(e){return Kt(e)?Gt[e]:e}function Jt(e,t){return`${e}${Le}/${encodeURIComponent(t)}`}N();var Yt=3e4;function Xt(e){let[t,n]=z(null),r=j(e=>{n(t=>t??e)},[]);return V(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?B(Zt,{onOrigin:r}):null}}function Zt({onOrigin:e}){let{data:t}=p({capName:`network-access`});return B(ne,{children:(t??[]).map(t=>B(Qt,{addonId:t.addonId,onOrigin:e},t.addonId))})}function Qt({addonId:e,onOrigin:t}){let{data:n}=a({addonId:e},{refetchInterval:Yt,retry:!1});return V(()=>{let e=n?U.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var $t=typeof C==`function`,en=`Track flags arrive with the next server update`;function tn(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var nn=$t?C:tn;function rn(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e))return null;let{trackId:t,markForTrain:n,debug:r}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`?null:{trackId:t,markForTrain:n,debug:r}}N();function an({label:e,hint:t,checked:n,disabled:r,title:i,icon:a,onToggle:o}){return P(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:r,title:i,onClick:o,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[B(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:a}),P(`span`,{className:`min-w-0 flex-1`,children:[B(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),B(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),B(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:B(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function on({deviceId:e,trackId:t,markForTrain:n,debug:r,onChange:i}){let a=nn(),[o,s]=z(null),c=o?.markForTrain??n===!0,l=o?.debug??r===!0,u=!$t||a.isPending,d=$t?void 0:en,f=n=>{u||(async()=>{try{let r=rn(await a.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;s(r),i?.(r)}catch(e){let t=e instanceof Error?e.message:``;window.alert(t===``?`Could not update this track. Check the server logs.`:`Could not update this track — ${t}`)}})()};return P(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[B(an,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:c,disabled:u,...d===void 0?{}:{title:d},icon:B(We,{className:`h-4 w-4`}),onToggle:()=>f({markForTrain:!c})}),B(an,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:l,disabled:u,...d===void 0?{}:{title:d},icon:B(Be,{className:`h-4 w-4`}),onToggle:()=>f({debug:!l})})]})}var X=100,sn=120,cn={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function ln(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function un(e,t,n){if(e.length===0||t===null)return cn;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return cn;let a=ln(e,n?.maxPoints??sn).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}N();var dn=15e3,fn=window.location.origin,pn=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),mn=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function hn(e){let[t,n]=z(null);return V(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function gn({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:P(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&B(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&B(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>B(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>B(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:B(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&B(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&B(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function $({label:e,value:t,mono:n}){return P(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[B(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),B(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function _n({row:t,cameraName:n,deleteAvailable:r,onClose:i,onDeleted:a,onFlagsChanged:s}){let c=ie(),l=Ot(),d=t!==null,f=t?.deviceId??0,p=t?.trackId??``,m=t?.bestEventId??``,h=t?.timestamp??0,ee=t?.windowMs??0,{data:_}=g({deviceId:f,trackId:p},{enabled:d}),{data:v}=D({trackId:p},{enabled:d}),{data:y}=u({eventId:m},{enabled:d&&m!==``}),{data:b}=te({deviceId:f,since:h-dn,until:h+ee+dn},{enabled:d}),[x,S]=z(null),[C,w]=z(!1),{publicOrigin:T,probes:E}=Xt(d);V(()=>{S(null)},[f,p]);let O=I(()=>{let e=v??[],t=y??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[v,y]),A=Fe(O?`${Le}/${encodeURIComponent(O.key)}`:void 0),M=I(()=>{let e=new Set,t=[];for(let n of[...y??[],...v??[]])!n.base64||e.has(n.key)||(e.add(n.key),t.push(n));return t},[y,v]),N=I(()=>M.find(e=>pn.has(e.kind))??null,[M]),F=hn(N?`data:image/jpeg;base64,${N.base64}`:null),L=I(()=>un(_?.positions??[],F,{snapshots:(_?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[_?.positions,_?.snapshots,F]),R=j(e=>{let t=M.find(t=>t.key===e);t&&S(t)},[M]);if(t===null)return null;let re=x?`data:image/jpeg;base64,${x.base64}`:A.src,H=x?.kind??O?.kind,U=H!==void 0&&mn.has(H)&&F!==null&&(_?.positions.length??0)>=2,W=b&&b.length>0?b[0]:null,ae=()=>{W&&(w(!0),(async()=>{try{let e=await c.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:W.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{w(!1)}})())},oe=()=>{!r||l.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await l.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),a()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},se=Math.round(t.importance*100),ce=_?.importanceReason?`${String(se)}% · ${_.importanceReason}`:`${String(se)}%`,G=_?.zonesVisited&&_.zonesVisited.length>0?_.zonesVisited.join(`, `):`—`,ue=_?.audioLabels&&_.audioLabels.length>0?_.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,de=_?_.totalDistance.toFixed(2):`—`,me=he(_?_.firstSeen:h),ge=_?he(_.lastSeen):`—`;return B(o,{open:!0,onOpenChange:e=>!e&&i(),children:P(e,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[P(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[P(`div`,{className:`min-w-0`,children:[P(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,vt(t)?P(`span`,{className:`text-foreground-subtle`,children:[` · `,vt(t)]}):null]}),B(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),B(`button`,{type:`button`,onClick:i,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:B(Ae,{className:`h-4 w-4`})})]}),P(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[re?B(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:B(pe,{src:re,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:U?B(gn,{overlay:L,onPickSnapshot:R}):void 0})}):B(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:A.failed?P(ne,{children:[B(fe,{className:`h-8 w-8 opacity-60`}),B(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):B(K,{className:`h-6 w-6 animate-spin opacity-70`})}),M.length>0&&B(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:M.map(e=>{let t=`data:image/jpeg;base64,${e.base64}`,n=qt(e.kind),r=Jt(fn,e.key),i=T?Jt(T,e.key):null;return P(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[B(`button`,{type:`button`,onClick:()=>S(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${he(e.timestamp)}`,children:B(`img`,{src:t,alt:n,className:`h-full w-full object-cover`})}),P(`figcaption`,{className:`min-w-0 px-0.5`,children:[B(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),B(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:he(e.timestamp),children:le(e.timestamp)})]}),B(Wt,{localUrl:r,publicUrl:i})]},e.key)})}),E,W&&P(k,{variant:`secondary`,onClick:ae,disabled:C,children:[C?B(K,{className:`h-3.5 w-3.5 animate-spin`}):B(we,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),B(on,{deviceId:t.deviceId,trackId:t.trackId,...(_?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:_?.markForTrain??t.markForTrain},...(_?.debug??t.debug)===void 0?{}:{debug:_?.debug??t.debug},onChange:s}),P(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[B($,{label:`Camera`,value:n}),B($,{label:`Class`,value:t.className}),B($,{label:`Label`,value:t.label??`—`}),B($,{label:`Sub-label`,value:t.subLabel??`—`}),B($,{label:`Importance`,value:ce}),B($,{label:`Zones visited`,value:G}),B($,{label:`Audio heard`,value:ue}),B($,{label:`Total distance`,value:de}),B($,{label:`First seen`,value:me}),B($,{label:`Last seen`,value:ge}),B($,{label:`Track`,value:t.trackId,mono:!0})]})]}),B(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:B(`span`,{title:r?void 0:Et,children:P(k,{variant:`secondary`,onClick:oe,disabled:!r||l.isPending,children:[l.isPending?B(K,{className:`h-3.5 w-3.5 animate-spin`}):B(Me,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function vn(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function yn({row:e,cameraName:t,nowMs:n,onOpenDetail:r,selected:i=!1,onToggleSelect:a,score:o}){let s=Fe(e.bestEventId?`${Le}/${e.bestEventId}`:void 0),c=Math.round(e.importance*100),l=o===void 0?void 0:Math.round(o*100),u=vn(e.windowMs),d=()=>r(e);return P(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[P(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[s.src?B(`img`,{src:s.src,alt:`Event from ${t}`,onClick:d,className:`h-full w-full cursor-zoom-in object-cover`}):B(`button`,{type:`button`,onClick:d,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:s.failed?`Key-event media unavailable`:`No key-event media`,children:B(fe,{className:`h-6 w-6 opacity-60`})}),a&&B(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(Ct(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?B(xe,{className:`h-4 w-4 text-primary`}):B(Se,{className:`h-4 w-4`})}),l!==void 0&&P(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(l),`%`]}),c>0&&B(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(c)}),(e.markForTrain===!0||e.debug===!0)&&P(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&B(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:B(We,{className:`h-3 w-3`})}),e.debug===!0&&B(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:B(Be,{className:`h-3 w-3`})})]})]}),P(`button`,{type:`button`,onClick:d,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[P(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,vt(e)?P(`span`,{className:`text-foreground-subtle`,children:[` · `,vt(e)]}):null]}),B(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),P(`div`,{className:`flex items-center justify-between gap-2`,children:[B(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:ue(e.timestamp,n)}),u&&B(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:u})]})]})]})}N();function bn(){let[e,t]=z(!1),n=M(null),[r,i]=z(0),a=j(e=>{n.current!==e&&(n.current=e,i(e=>e+1))},[]);return V(()=>{let e=n.current;if(!e||typeof IntersectionObserver>`u`){t(!1);return}let r=new IntersectionObserver(e=>{let n=e[e.length-1];n&&t(!n.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return r.observe(e),()=>r.disconnect()},[r]),{ref:a,scrolledPast:e}}N();var xn=[`events-feed`],Sn=60,Cn=[{value:`importance`,label:`Importance`,icon:ze},{value:`time`,label:`Recent`,icon:ae}];function wn(){let e=re(),[t,n]=z(_e),[r,a]=z(new Set),[o,s]=z(new Set),[c,l]=z(0),[u,d]=z(`time`),[f,p]=z(new Set),[m,h]=z(null),[g,ee]=z(()=>Date.now());V(()=>{let e=setInterval(()=>ee(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:_,until:v}=I(()=>Tt({fromMs:t.fromMs,toMs:t.toMs},g),[t.fromMs,t.toMs,g]),y=bn(),{pending:te,refreshNow:x}=Pt({paused:m!==null||f.size>0||y.scrolledPast}),{data:S}=i({}),C=I(()=>(S??[]).filter(e=>e.type===H.Camera),[S]),w=I(()=>C.map(e=>e.id),[C]),{data:T,isLoading:E}=b({deviceIds:w},{enabled:w.length>0,staleTime:5*6e4}),D=I(()=>Bt(T??[],r),[T,r]),O=Ot(),A=O.isPending,{rows:j,isLoading:M}=jt({deviceIds:w,since:_,until:v,minImportance:c>0?c:void 0,classFilter:o.size===1?[...o][0]:void 0}),N=I(()=>{let e=new Map;for(let t of C??[])e.set(t.id,t.name);return e},[C]),F=e=>N.get(e)??`Camera #${String(e)}`,L=I(()=>G(j).map(e=>({id:e,name:F(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[j,N]),R=I(()=>xt(St(j,{cameras:r,classes:o,minImportance:c}),u),[j,r,o,c,u]),U=me(R,Sn,I(()=>JSON.stringify([[...r].sort((e,t)=>e-t),[...o].sort(),c,u,_,v]),[r,o,c,u,_,v])),W=()=>{e.invalidateQueries({queryKey:xn})},ie=()=>p(new Set);function ae(e){p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function oe(){if(f.size===0||!Y)return;let e=wt(j,f),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>O.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{W();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(Ct(o,e));else t.push(o)}),p(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>F(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let se=R.length!==j.length;return P(`div`,{className:`relative space-y-3`,children:[P(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[B(ge,{onChange:n}),B(de,{cameras:L,selected:r,onChange:a}),B(Ft,{groups:D,selected:o,onChange:s,loading:E}),P(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[B(`span`,{children:`Min score`}),B(`input`,{type:`range`,min:0,max:1,step:.05,value:c,onChange:e=>l(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),B(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(c*100)})]}),B(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Cn.map(e=>{let t=e.icon;return P(`button`,{type:`button`,onClick:()=>d(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${u===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[B(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!M&&B(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:se?`${String(R.length)} of ${String(j.length)} events`:`${String(R.length)} event${R.length===1?``:`s`}`})]}),f.size>0&&P(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[P(`span`,{className:`text-xs font-medium text-foreground`,children:[f.size,` selected`]}),P(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[B(`span`,{title:Y?void 0:`Track deletion arrives with the next server update`,children:P(k,{variant:`secondary`,onClick:oe,disabled:!Y||A,children:[A?B(K,{className:`h-3.5 w-3.5 animate-spin`}):B(Me,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),B(k,{variant:`ghost`,onClick:ie,disabled:A,children:B(Ae,{className:`h-3.5 w-3.5`})})]})]}),M&&P(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[B(K,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!M&&R.length===0&&B(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),te&&B(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:B(`button`,{type:`button`,onClick:x,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!M&&R.length>0&&P(ne,{children:[B(`div`,{ref:y.ref,"aria-hidden":!0,className:`h-0`}),B(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:U.pageItems.map(e=>B(yn,{row:e,cameraName:F(e.deviceId),nowMs:g,selected:f.has(Ct(e.deviceId,e.trackId)),onToggleSelect:ae,onOpenDetail:h},Ct(e.deviceId,e.trackId)))}),B(ce,{currentPage:U.page,totalItems:U.totalItems,pageSize:U.pageSize,onPageChange:U.setPage,itemNoun:`events`})]}),m&&B(_n,{row:m,cameraName:F(m.deviceId),deleteAvailable:Y,onClose:()=>h(null),onDeleted:()=>{W(),h(null)},onFlagsChanged:e=>{h(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug}:t)}})]})}N();var Tn=50,En=350,Dn=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function On(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function kn({onActiveChange:e}){let[t,n]=z(``),[a,o]=z(.2),[c,l]=z(null),[u,d]=z(null),[f,p]=z(null),m=r(t,En).trim(),g=m.length>0;V(()=>{e(g)},[g,e]);let[ee,_]=z(()=>Date.now());V(()=>{let e=setInterval(()=>_(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:v}=i({}),y=I(()=>(v??[]).filter(e=>e.type===H.Camera),[v]),te=I(()=>{let e=new Map;for(let t of v??[])e.set(t.id,t.name);return e},[v]),x=e=>te.get(e)??`Camera #${String(e)}`,S=I(()=>y.map(e=>e.id),[y]),{data:C}=b({deviceIds:S},{enabled:S.length>0,staleTime:5*6e4}),w=I(()=>zt(C??[],new Set(u===null?[]:[u])),[C,u]);V(()=>{c!==null&&(w.some(e=>e.kind===c)||l(null))},[w,c]);let{data:T,isFetching:E,isError:D,error:O}=h({text:m,minScore:a,limit:Tn,classFilter:c??void 0,deviceId:u??void 0},{enabled:g}),k=I(()=>[...T??[]].sort((e,t)=>t.score-e.score).map(e=>({...On(e),score:e.score})),[T]);function A(e){l(t=>t===e?null:e)}return P(`div`,{className:`space-y-3`,children:[P(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[P(`div`,{className:`flex flex-wrap items-center gap-2`,children:[P(`div`,{className:`relative min-w-[16rem] flex-1`,children:[B(be,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),B(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&B(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:B(Ae,{className:`h-3.5 w-3.5`})})]}),E&&g&&B(K,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),P(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[B(`div`,{className:`flex items-center gap-1`,children:w.map(e=>B(`button`,{type:`button`,onClick:()=>A(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${c===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:s(e)},e.kind))}),P(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[B(`span`,{children:`Camera`}),P(`select`,{value:u===null?``:String(u),onChange:e=>d(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[B(`option`,{value:``,children:`All`}),y.map(e=>B(`option`,{value:String(e.id),children:e.name},e.id))]})]}),P(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[B(`span`,{children:`Match`}),B(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Dn.map(e=>B(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${a===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),g&&!E&&!D&&P(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[k.length,` match`,k.length===1?``:`es`]})]})]}),g&&P(`div`,{className:`space-y-3`,children:[D&&P(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,O instanceof Error?O.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!D&&E&&k.length===0&&P(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[B(K,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!D&&!E&&k.length===0&&P(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,m,`”. Try a looser match threshold or a different phrasing.`]}),!D&&k.length>0&&B(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:k.map(e=>B(yn,{row:e,cameraName:x(e.deviceId),nowMs:ee,score:e.score,onOpenDetail:p},e.id))})]}),f&&B(_n,{row:f,cameraName:x(f.deviceId),deleteAvailable:Y,onClose:()=>p(null),onDeleted:()=>p(null)})]})}var An=15e3;function jn(e){let t=ie(),n=R({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:An,refetchInterval:An,queryFn:async()=>((await t.trpcClient.zoneAnalytics.getCurrentSnapshot.query({deviceId:e}))?.stationaryObjects??[]).map(t=>({...t,deviceId:e}))}))});return{rows:n.flatMap(e=>e.data??[]).toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n.some(e=>e.isLoading)}}N();function Mn(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function Nn({row:e,cameraName:t,nowMs:n}){let r=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,i=Fe(r?`${Le}/${r}`:void 0);return P(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[P(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?B(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):B(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:B(Ge,{className:`h-6 w-6`})}),B(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),P(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[B(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),P(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Mn(n,e.becameStationaryAt)]})]})]})}function Pn(){let[e,t]=z(!1),n=Date.now(),{data:r}=i({}),a=I(()=>(r??[]).filter(e=>e.type===H.Camera),[r]),o=I(()=>a.map(e=>e.id),[a]),s=I(()=>{let e=new Map;for(let t of a)e.set(t.id,t.name);return e},[a]),{rows:c}=jn(o);return c.length===0?null:P(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[P(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[B(e?Te:Oe,{className:`h-4 w-4 text-foreground-subtle`}),B(Ge,{className:`h-4 w-4 text-foreground-subtle`}),B(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),B(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:c.length}),B(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&B(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:c.map(e=>B(Nn,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}N();function Fn(){let[e,t]=z(!1);return B(Pe,{children:P(`section`,{className:`space-y-3`,children:[B(kn,{onActiveChange:t}),!e&&B(Pn,{}),!e&&B(wn,{})]})})}var In=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Ln=new Set(In);function Rn(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Ln.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function zn({annotations:e,selectedIndex:t,onSelect:n,onChange:r,onDelete:i}){return e.length===0?P(`p`,{className:`text-[11px] text-foreground-subtle p-3`,children:[`No subject on this frame yet. Drag on the image to draw one, or ask the pipeline for a proposal. Annotate `,B(`strong`,{children:`every`}),` subject — a frame with one box and three unlabelled people teaches the model that two thirds of the people in it are background.`]}):B(`ul`,{className:`divide-y divide-border`,children:e.map((e,a)=>{let o=a===t,s=Rn(e.label),c=Rn(e.subLabel);return P(`li`,{className:`p-2.5 space-y-1.5 ${o?`bg-surface-hover`:``}`,onFocus:()=>{n(a)},children:[P(`div`,{className:`flex items-center gap-2`,children:[B(S,{className:`w-28`,value:e.macroClass,options:In.map(e=>({value:e,label:e})),onChange:e=>{let t=In.find(t=>t===e.target.value);t!==void 0&&r(a,{macroClass:t})}}),B(S,{className:`w-32`,value:e.kind,options:[{value:`subject`,label:`subject`},{value:`model_error`,label:`model error`}],onChange:e=>{r(a,{kind:e.target.value===`model_error`?`model_error`:`subject`})}}),e.source===`assist`&&P(y,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),B(k,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{i(a)},children:B(Me,{className:`h-3 w-3`})})]}),P(`div`,{className:`flex items-center gap-2`,children:[B(E,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{r(a,{label:e.target.value})}}),B(E,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:e=>{r(a,{subLabel:e.target.value})}})]}),s!==null&&B(`p`,{className:`text-[11px] text-danger`,children:s}),c!==null&&B(`p`,{className:`text-[11px] text-danger`,children:c})]},`${String(a)}-${String(e.bbox.x)}`)})})}function Bn(e){return e.every(e=>Rn(e.label)===null&&Rn(e.subLabel)===null&&Ln.has(e.macroClass))}function Vn(e){return e<0?0:e>1?1:e}function Hn(e,t,n,r){if(!(e>0)||!(t>0)||!(n>0)||!(r>0))return null;let i=Math.min(e/n,t/r),a=n*i,o=r*i;return{left:(e-a)/2,top:(t-o)/2,width:a,height:o}}function Un(e,t,n){return{x:Vn((e-n.left)/n.width),y:Vn((t-n.top)/n.height)}}function Wn(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function Gn(e){return e.w>=.01&&e.h>=.01}function Kn(e,t){return{left:t.left+e.x*t.width,top:t.top+e.y*t.height,width:e.w*t.width,height:e.h*t.height}}function qn(e,t){let n=-1,r=1/0;return e.forEach((e,i)=>{if(!(t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h))return;let a=e.w*e.h;a<r&&(n=i,r=a)}),n}N();function Jn({imageSrc:e,imageWidth:t,imageHeight:n,boxes:r,selectedIndex:i,onSelect:a,onDraw:o}){let s=M(null),[c,l]=z({w:0,h:0}),[u,d]=z(null);F(()=>{let e=s.current;if(e===null)return;let t=new ResizeObserver(()=>{l({w:e.clientWidth,h:e.clientHeight})});return t.observe(e),l({w:e.clientWidth,h:e.clientHeight}),()=>{t.disconnect()}},[]);let f=Hn(c.w,c.h,t,n),p=j(e=>{let t=s.current;if(t===null||f===null)return null;let n=t.getBoundingClientRect();return Un(e.clientX-n.left,e.clientY-n.top,f)},[f]);return P(`div`,{ref:s,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none`,onPointerDown:e=>{let t=p(e);t!==null&&(e.currentTarget.setPointerCapture(e.pointerId),d({start:t,current:Wn(t,t)}))},onPointerMove:e=>{if(u===null)return;let t=p(e);t!==null&&d({start:u.start,current:Wn(u.start,t)})},onPointerUp:()=>{if(u===null)return;let e=u.current;d(null),Gn(e)?o(e):a(qn(r.map(e=>e.bbox),u.start))},children:[B(`img`,{src:e,alt:`Frame being annotated`,className:`absolute inset-0 w-full h-full object-contain pointer-events-none`}),f!==null&&r.map((e,t)=>{let n=Kn(e.bbox,f),r=e.kind===`model_error`,a=t===i,o=r?`#ef4444`:a?`#22c55e`:`#3b82f6`;return B(`div`,{className:`absolute pointer-events-none`,style:{left:n.left,top:n.top,width:n.width,height:n.height,border:`${a?`2px`:`1px`} ${r?`dashed`:`solid`} ${o}`,opacity:e.source===`assist`&&!a?.65:1},children:P(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded`,style:{background:o,color:`#08121f`},children:[e.label??e.macroClass,r?` ✕`:``]})},`${String(t)}-${String(e.bbox.x)}-${String(e.bbox.y)}`)}),u!==null&&f!==null&&B(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:Kn(u.current,f)})]})}function Yn(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function Xn({candidates:e,copies:t,activeFrameId:n,refusals:r,isSelecting:i,onSelectCandidate:a,onOpenCopy:o,onRemoveCopy:s}){let c=new Set(t.map(e=>e.sourceMediaKey)),l=e.filter(e=>!c.has(e.mediaKey));return P(`div`,{className:`space-y-3`,children:[P(`section`,{children:[P(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`In the dataset (`,t.length,`)`]}),t.length===0?B(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No frame copied yet. Selecting a frame copies it into retrain storage immediately — the dataset stops depending on the track's own media from that moment.`}):B(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>B(`li`,{children:P(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[P(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{o(e.frameId)},children:[B(Ee,{className:`h-3 w-3 text-success`}),B(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),P(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,Yn(e.sizeBytes)]})]}),P(`button`,{type:`button`,"aria-label":`Remove this frame from the dataset`,className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-danger`,onClick:()=>{s(e.frameId)},children:[B(Me,{className:`h-3 w-3`}),`remove`]})]})},e.frameId))})]}),P(`section`,{children:[P(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,l.length,`)`]}),l.length===0?B(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.length===0?`This track has no whole, unannotated frame left — its media aged out before it was marked. Anything already copied above is still usable.`:`Every available frame is already in the dataset.`}):B(`ul`,{className:`flex flex-wrap gap-2`,children:l.map(e=>{let t=r.get(e.mediaKey);return P(`li`,{children:[P(k,{variant:`secondary`,size:`sm`,disabled:i||t!==void 0,onClick:()=>{a(e.mediaKey)},children:[i?B(K,{className:`h-3 w-3 animate-spin`}):B(t===void 0?Ue:fe,{className:`h-3 w-3`}),B(`span`,{className:`ml-1`,children:e.kind}),B(`span`,{className:`ml-1 text-foreground-subtle`,children:Yn(e.sizeBytes)})]}),t!==void 0&&B(y,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaKey)})})]})]})}function Zn(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var Qn={untouched:{icon:He,label:`to do`,variant:`default`},started:{icon:Ve,label:`frames only`,variant:`info`},ready:{icon:De,label:`annotated`,variant:`success`}};function $n(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function er({tracks:e,isLoading:t,selectedTrackId:n,deviceNames:r,onSelect:i}){return t?P(`div`,{className:`flex items-center gap-2 p-4 text-xs text-foreground-subtle`,children:[B(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?B(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Nothing in staging. Mark a track for training from the viewer or the Events grid and it appears here.`}):B(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=Qn[Zn(e)],a=t.icon;return B(`li`,{children:P(`button`,{type:`button`,onClick:()=>{i(e)},className:`w-full text-left px-3 py-2 flex items-start gap-2 hover:bg-surface-hover ${e.trackId===n?`bg-surface-hover`:``}`,children:[B(a,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),P(`span`,{className:`min-w-0 flex-1`,children:[P(`span`,{className:`flex items-center gap-2`,children:[B(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),B(y,{variant:t.variant,children:t.label})]}),P(`span`,{className:`block text-[11px] text-foreground-subtle truncate`,children:[r.get(e.deviceId)??`Camera ${String(e.deviceId)}`,` ·`,` `,$n(e.lastSeen)]}),P(`span`,{className:`block text-[11px] text-foreground-muted`,children:[e.frameCount,` frame`,e.frameCount===1?``:`s`,` ·`,` `,e.annotationCount,` subject`,e.annotationCount===1?``:`s`]})]})]})},e.trackId)})})}N();var tr=`person`;function nr(){let[e,n]=z(null),[r,a]=z(null),[o,s]=z([]),[l,u]=z(-1),[f,p]=z(new Map),[m,h]=z(null),g=i({projection:`slim`,isCamera:!0}),te=I(()=>{let e=new Map;for(let t of g.data??[])e.set(t.id,t.name);return e},[g.data]),b=x({}),S=d({trackId:e?.trackId??``},{enabled:e!==null}),C=_({trackId:e?.trackId??``},{enabled:e!==null}),E=t({frameId:r??``},{enabled:r!==null}),D=ee(),A=c(),M=T(),N=O(),F=w(),L=v();V(()=>{if(r===null){s([]);return}s((C.data??[]).filter(e=>e.mediaKey===r).map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))),u(-1)},[r,C.data]),V(()=>{let e=S.data?.copies??[];r===null&&e.length>0&&a(e[0].frameId)},[S.data,r]);let R=j(e=>{n(e),a(null),s([]),p(new Map),h(null)},[]),re=j(async t=>{if(e===null)return;let n=await D.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,mediaKeys:[t]});if(n.refused.length>0){let e=new Map(f);for(let t of n.refused)e.set(t.sourceMediaKey,t.reason);p(e)}n.copied.length>0&&a(n.copied[0].frameId),await S.refetch(),await b.refetch()},[e,D,f,S,b]),H=j(async t=>{e!==null&&(await A.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,frameId:t}),r===t&&a(null),await S.refetch(),await C.refetch(),await b.refetch())},[e,A,r,S,C,b]),U=j(async t=>{if(e===null||r===null)return;h(null);let n=await M.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,frameId:r,subject:t===`package`?{kind:`package`}:{kind:`objects`,modelId:`yolo26n`,minScore:.3}});if(n.kind===`refused`){h(n.reason===`no-zone`?`A package proposal runs on the zone crop only — this camera has no zone, and running the detector on the whole frame at 0.35 proposes furniture.`:`The pipeline refused: ${n.reason}${n.detail===void 0?``:` — ${n.detail}`}`);return}s(e=>[...e,...n.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))]),h(`${n.proposals.length} proposal${n.proposals.length===1?``:`s`} from ${n.modelId}`+(n.belowThreshold>0?` — ${n.belowThreshold} more were below ${n.minScore.toFixed(2)}`:``))},[e,r,M]),W=j(e=>{s(t=>[...t,{bbox:e,macroClass:tr,kind:`subject`,source:`operator`}]),u(o.length)},[o.length]),ie=j((e,t)=>{s(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),ae=j(e=>{s(t=>t.filter((t,n)=>n!==e)),u(-1)},[]),oe=j(async()=>{e===null||r===null||(await N.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,frameId:r,annotations:o.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{},...e.subLabel!==void 0&&e.subLabel!==``?{subLabel:e.subLabel}:{},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))}),await C.refetch(),await b.refetch(),h(`Annotations saved.`))},[e,r,o,N,C,b]),se=j(async()=>{if(e===null)return;let t=await F.mutateAsync({deviceId:e.deviceId,trackId:e.trackId});h(t.changed?`Track completed — it is now trained, and its own media is evictable again.`:t.reason===`no-frames-copied`?`Refused: no frame was ever copied into the dataset. Completing would let retention delete material nothing was extracted from.`:`Refused: ${t.reason??`unknown`}`),await b.refetch(),t.changed&&n(null)},[e,F,b]),ce=j(async()=>{if(e===null)return;let t=await L.mutateAsync({deviceId:e.deviceId,trackId:e.trackId});h(t.changed?`Track returned to staging. Its copies and annotations were left alone.`:`Refused: ${t.reason??`unknown`}`),await b.refetch()},[e,L,b]),G=E.data,le=Bn(o)&&r!==null;return P(Pe,{subtitle:`Turn the tracks you marked for training into an annotated dataset. Selecting a frame copies it — the dataset never depends on media that can be swept.`,actions:e===null?null:P(`div`,{className:`flex items-center gap-2`,children:[P(k,{variant:`secondary`,size:`sm`,onClick:()=>void ce(),children:[B(Ce,{className:`h-3 w-3`}),B(`span`,{className:`ml-1`,children:`Back to staging`})]}),P(k,{size:`sm`,onClick:()=>void se(),children:[B(We,{className:`h-3 w-3`}),B(`span`,{className:`ml-1`,children:`Complete track`})]})]}),children:[m!==null&&B(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:m}),P(`div`,{className:`grid grid-cols-1 lg:grid-cols-[minmax(0,260px)_minmax(0,1fr)] gap-4`,children:[P(`aside`,{className:`rounded-md border border-border bg-surface overflow-hidden`,children:[P(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between`,children:[B(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Staging`}),B(y,{children:b.data?.length??0})]}),B(er,{tracks:b.data??[],isLoading:b.isLoading,selectedTrackId:e?.trackId??null,deviceNames:te,onSelect:R})]}),B(`section`,{className:`space-y-3 min-w-0`,children:e===null?B(`p`,{className:`text-xs text-foreground-subtle`,children:`Pick a track from the staging list to start annotating it.`}):P(ne,{children:[B(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:B(Xn,{candidates:S.data?.candidates??[],copies:S.data?.copies??[],activeFrameId:r,refusals:f,isSelecting:D.isPending,onSelectCandidate:e=>void re(e),onOpenCopy:a,onRemoveCopy:e=>void H(e)})}),r!==null&&P(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[B(`div`,{className:`rounded-md border border-border overflow-hidden`,children:G===void 0?P(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[B(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):B(Jn,{imageSrc:`data:image/jpeg;base64,${G.base64}`,imageWidth:G.width,imageHeight:G.height,boxes:o,selectedIndex:l,onSelect:u,onDraw:W})}),P(`div`,{className:`rounded-md border border-border bg-surface flex flex-col min-h-0`,children:[P(`div`,{className:`px-3 py-2 border-b border-border flex items-center gap-2`,children:[B(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),P(k,{variant:`secondary`,size:`sm`,disabled:M.isPending,onClick:()=>void U(`objects`),children:[B(je,{className:`h-3 w-3`}),B(`span`,{className:`ml-1`,children:`Propose`})]}),P(k,{variant:`secondary`,size:`sm`,disabled:M.isPending,onClick:()=>void U(`package`),children:[B(je,{className:`h-3 w-3`}),B(`span`,{className:`ml-1`,children:`Packages`})]})]}),B(`div`,{className:`flex-1 overflow-y-auto`,children:B(zn,{annotations:o,selectedIndex:l,onSelect:u,onChange:ie,onDelete:ae})}),P(`div`,{className:`px-3 py-2 border-t border-border flex items-center justify-between`,children:[P(`span`,{className:`text-[11px] text-foreground-subtle`,children:[o.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),B(k,{size:`sm`,disabled:!le||N.isPending,onClick:()=>void oe(),children:`Save frame`})]})]})]})]})})]})]})}function rr(){return B(`div`,{className:`flex flex-col p-4`,children:B(Re,{tabs:[{id:`feed`,label:`Feed`,icon:ke,content:B(Fn,{})},{id:`retrain`,label:`Retrain`,icon:We,content:B(nr,{})},{id:`debug`,label:`Debug`,icon:Be,content:B(_t,{})}]})})}export{rr as EventsPage};