@camstack/addon-admin-ui 1.0.6 → 1.0.8

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 (104) hide show
  1. package/dist/assets/{AddLocationWizard-CukR7cTF.js → AddLocationWizard-DomSxpGI.js} +1 -1
  2. package/dist/assets/AddonCollectionPage-DpSbeFq7.js +1 -0
  3. package/dist/assets/Addons-1gQjuR9S.js +1 -0
  4. package/dist/assets/AdminPage-vtcsGqRq.js +1 -0
  5. package/dist/assets/{AdminTabs-BpXprAan.js → AdminTabs-B7an3aYB.js} +1 -1
  6. package/dist/assets/{BrokerForm-BHHqkVQb.js → BrokerForm-DImaKHz8.js} +1 -1
  7. package/dist/assets/{BrokerStep-Cok3AhHx.js → BrokerStep-D4L9bUsk.js} +1 -1
  8. package/dist/assets/Capabilities-D0caXSgs.js +1 -0
  9. package/dist/assets/{CapabilityBadges-CMb2KZ75.js → CapabilityBadges-BCofv88Z.js} +1 -1
  10. package/dist/assets/{Cluster-Dv4qNomn.js → Cluster-BtOVpJ4s.js} +1 -1
  11. package/dist/assets/{Dashboard-DJM813RT.js → Dashboard-TKoXQaIb.js} +1 -1
  12. package/dist/assets/{Data-DGhOO-Cu.js → Data-B5u4dAnY.js} +1 -1
  13. package/dist/assets/DetectionIntelligence-C4FeIOdR.js +1 -0
  14. package/dist/assets/DeviceDetail-BPaQwx2C.js +2 -0
  15. package/dist/assets/{Devices-CUWOXRHi.js → Devices-D1-l4svU.js} +1 -1
  16. package/dist/assets/EmbedPlayerPage-6o-vVqJv.js +1 -0
  17. package/dist/assets/FormBuilder-aFYGmiS4.js +1 -0
  18. package/dist/assets/{Identity-Be25Wd9m.js → Identity-DoN_l5BA.js} +1 -1
  19. package/dist/assets/IntegrationDetail-ChyVujgZ.js +1 -0
  20. package/dist/assets/Integrations-SnvWread.js +1 -0
  21. package/dist/assets/{Integrations-D2GJn2wx.js → Integrations-vgx-gq-F.js} +1 -1
  22. package/dist/assets/{Logs-CJvGn4d5.js → Logs-ByT8Fq04.js} +1 -1
  23. package/dist/assets/{MaskShapeCanvas-C5K6H6Th.js → MaskShapeCanvas-CQ2SgaNa.js} +1 -1
  24. package/dist/assets/MotionZonesSettings-CsC6s4D-.js +1 -0
  25. package/dist/assets/MyAccess-CcV3suRC.js +2 -0
  26. package/dist/assets/Network-DSUa74-e.js +1 -0
  27. package/dist/assets/NodeAddonsSettingsPanel-C8dKpqZh.js +1 -0
  28. package/dist/assets/{Pipeline-B4MQZJjm.js → Pipeline-DvAGol7e.js} +1 -1
  29. package/dist/assets/PrivacyMaskSettings-BYqj289i.js +1 -0
  30. package/dist/assets/{ProviderIcon-BPXhRQ1d.js → ProviderIcon-DnjoN_gW.js} +1 -1
  31. package/dist/assets/SchemaTabBar-DRo5sGP1.js +1 -0
  32. package/dist/assets/Settings-McpLfu8Z.js +1 -0
  33. package/dist/assets/Showroom-DBUVcfqM.js +1 -0
  34. package/dist/assets/{StatusBadge-CkYubfRG.js → StatusBadge-BSsUNFG6.js} +1 -1
  35. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DYMHJcwg.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-73q_gPW1.js} +1 -1
  36. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js} +1 -1
  37. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DEeasWo3.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DqrXu-jG.js} +1 -1
  38. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-C1rR7FKs.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-DcnMG4y9.js} +1 -1
  39. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-DQOBkcAT.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-CUURKTLp.js} +1 -1
  40. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-PYw2UAZ_.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-xmx-auwe.js} +3 -3
  41. package/dist/assets/{bell-DUIEkGPA.js → bell-C5Uv_byR.js} +1 -1
  42. package/dist/assets/circle-check-big-CToOIOTu.js +1 -0
  43. package/dist/assets/{copy-DUY8-DBe.js → copy-B_qOe5z2.js} +1 -1
  44. package/dist/assets/dist-DBAJfCeK.js +1 -0
  45. package/dist/assets/{dist-Dw4iYpIy.js → dist-DivYVFrG.js} +1 -1
  46. package/dist/assets/{download-B3pGiRsg.js → download-BT33CH3j.js} +1 -1
  47. package/dist/assets/{esm-CR7fS4E6.js → esm-C2ZjsqSd.js} +3 -3
  48. package/dist/assets/{hostInit-DJmAUuWj.js → hostInit-BzUwQrc2.js} +1 -1
  49. package/dist/assets/index-C9dLNgtt.js +4 -0
  50. package/dist/assets/{key-round-BtVEvNiB.js → key-round-CMLRqbrq.js} +1 -1
  51. package/dist/assets/{mf-entry-bootstrap-0-50a30526.js → mf-entry-bootstrap-0-49f53064.js} +2 -2
  52. package/dist/assets/{pencil-BHXuzoZT.js → pencil-CLwBxZCl.js} +1 -1
  53. package/dist/assets/{player-overlays-B1rOp2K0.js → player-overlays-BD7QrhVv.js} +1 -1
  54. package/dist/assets/plus-tJZHYmsB.js +1 -0
  55. package/dist/assets/{radio-BrSbZ3Gz.js → radio-CnJYCpke.js} +1 -1
  56. package/dist/assets/{refresh-cw-9auw5j71.js → refresh-cw-CLgLEKc_.js} +1 -1
  57. package/dist/assets/remoteEntry-CtF0a_XV.js +1 -0
  58. package/dist/assets/{rotate-ccw-DeNzdz-v.js → rotate-ccw-B53meVG1.js} +1 -1
  59. package/dist/assets/rotate-cw-EY9cIQs9.js +1 -0
  60. package/dist/assets/search-BT8SB-Ig.js +1 -0
  61. package/dist/assets/{server-Bj7As5DB.js → server-C-7gGEm3.js} +1 -1
  62. package/dist/assets/{sparkles-BMTAprd6.js → sparkles-DKm7eNvc.js} +1 -1
  63. package/dist/assets/square-UU8oWHzQ.js +1 -0
  64. package/dist/assets/{square-check-big-CPuMXqOw.js → square-check-big-XneAXRht.js} +1 -1
  65. package/dist/assets/src-DsE0ulBa.js +1 -0
  66. package/dist/assets/src-tFxrblhL.js +34 -0
  67. package/dist/assets/{upload-BQ5R4JaW.js → upload-C45qaDPP.js} +1 -1
  68. package/dist/assets/{useDevice-mTj6eL8W.js → useDevice-CEFTGk-N.js} +1 -1
  69. package/dist/assets/useEventInvalidation-BtLXp2PR.js +1 -0
  70. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BkXjP_sa.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B5yi8CSR.js} +2 -2
  71. package/dist/assets/{wifi-CV73GdWg.js → wifi-DstzyoYP.js} +1 -1
  72. package/dist/assets/{zap-Cc3-KiYB.js → zap-DHsYuJKW.js} +1 -1
  73. package/dist/index.html +5 -5
  74. package/dist/server/addon.js +709 -674
  75. package/package.json +1 -1
  76. package/dist/assets/AddonCollectionPage-DJx4uU6r.js +0 -1
  77. package/dist/assets/Addons-CH-apJRX.js +0 -1
  78. package/dist/assets/AdminPage-CN6ZMhf0.js +0 -1
  79. package/dist/assets/Capabilities-C7ZtET2s.js +0 -1
  80. package/dist/assets/DetectionIntelligence-hx5aK8kV.js +0 -1
  81. package/dist/assets/DeviceDetail-Cy3oT8kc.js +0 -2
  82. package/dist/assets/EmbedPlayerPage-DWa8--dX.js +0 -1
  83. package/dist/assets/FormBuilder-D1P2uZCo.js +0 -1
  84. package/dist/assets/IntegrationDetail-BH3qKiFl.js +0 -1
  85. package/dist/assets/Integrations-5qRDDBvi.js +0 -1
  86. package/dist/assets/MotionZonesSettings-CrSbCbyo.js +0 -1
  87. package/dist/assets/MyAccess-C70LOUlA.js +0 -2
  88. package/dist/assets/Network-KGBDHmKd.js +0 -1
  89. package/dist/assets/NodeAddonsSettingsPanel-DZOqqqZZ.js +0 -1
  90. package/dist/assets/PrivacyMaskSettings-Btjy009a.js +0 -1
  91. package/dist/assets/SchemaTabBar-ByWwzBUZ.js +0 -1
  92. package/dist/assets/Settings-BBKIvACs.js +0 -1
  93. package/dist/assets/Showroom-D6AoJdZW.js +0 -1
  94. package/dist/assets/circle-check-big-BjqV4p1D.js +0 -1
  95. package/dist/assets/dist-BwRNbXT1.js +0 -1
  96. package/dist/assets/index-CBUhNGng.js +0 -4
  97. package/dist/assets/plus-CljwKCLZ.js +0 -1
  98. package/dist/assets/remoteEntry-B0hADopi.js +0 -1
  99. package/dist/assets/rotate-cw-anx2g3R_.js +0 -1
  100. package/dist/assets/search-BYve1v5o.js +0 -1
  101. package/dist/assets/square-CondP2yo.js +0 -1
  102. package/dist/assets/src-D-eMZfpa.js +0 -34
  103. package/dist/assets/src-DUWILaCU.js +0 -1
  104. package/dist/assets/useEventInvalidation-BXdyfSQv.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-admin-ui",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "CamStack Admin UI — Vite frontend build and server-side addon",
@@ -1 +0,0 @@
1
- import{Fi as e,Ii as t,d as n,da as r,g as i,lt as a,m as o,mt as s,pa as c}from"./src-D-eMZfpa.js";import{G as l,R as u,X as d,b as f,o as p,x as m}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{t as h}from"./bell-DUIEkGPA.js";import{t as g}from"./plus-CljwKCLZ.js";import{t as _}from"./refresh-cw-9auw5j71.js";import{t as v}from"./square-CondP2yo.js";import{B as y,P as b,V as x,p as S,x as C}from"./index-CBUhNGng.js";import{t as w}from"./AdminPage-CN6ZMhf0.js";import{t as T}from"./NodeAddonsSettingsPanel-DZOqqqZZ.js";var E=y(`play`,[[`polygon`,{points:`6 3 20 12 6 21 6 3`,key:`1oa8hb`}]]);d();function D({addonId:e,fallback:t,tileClassName:n,iconPath:r=`assets/icon.svg`}){let[i,a]=l(!1),o=`/api/addon-assets/${e}/${r}`;return f(`div`,{className:`h-10 w-10 rounded-lg flex items-center justify-center shrink-0 ${n}`,children:i?f(t,{className:`h-5 w-5`}):f(`img`,{src:o,alt:e,className:`h-7 w-7 rounded-md bg-white p-1 ring-1 ring-black/5`,onError:()=>a(!0)})})}d();function O({addonId:e,defaultActivity:t,showActivity:n=!0,maxHeight:r=`max-h-64`,defaultTab:a,capability:s}){let[c,u]=l(t??(a===`events`?`events`:`logs`));return m(`div`,{className:`flex flex-col gap-4`,children:[f(T,{nodeId:`hub`,addonIds:[e],level:`global`,capability:s}),n&&m(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[m(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border bg-surface-hover/20`,children:[f(`span`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Activity`}),m(`div`,{className:`flex items-center gap-1`,children:[f(k,{kind:`logs`,active:c===`logs`,onClick:()=>u(`logs`)}),f(k,{kind:`events`,active:c===`events`,onClick:()=>u(`events`)})]})]}),c===`logs`?f(i,{addonId:e,maxHeight:r,showFilters:!1}):f(o,{addonId:e,category:`addon.*`,maxHeight:r})]})]})}function k({kind:e,active:t,onClick:n}){return m(`button`,{onClick:n,className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[f(e===`logs`?S:h,{className:`h-3 w-3`}),e===`logs`?`Logs`:`Events`]})}d();function A(n){let{title:i,subtitle:a,pageIcon:o,itemIcon:s,capability:d,installButtonLabel:p=`Add addon`,items:h,isLoading:_,emptyTitle:v=`No addons installed for this capability`,emptyDescription:y,itemIconColor:S,renderStatusBadges:C,renderPrimaryAction:T,itemError:E,renderExpandedPanel:k,workspaceMaxHeight:A=`max-h-72`,trailing:P,showChrome:F=!1}=n,I=h.length>1,[L,R]=l(()=>h[0]?.addonId??null);u(()=>{L&&(h.some(e=>e.addonId===L)||R(h[0]?.addonId??null))},[h,L]);let z=e=>R(t=>t===e?null:e),B=`/system/addons?capability=${encodeURIComponent(d)}`;return f(w,{icon:F?o:void 0,title:F?i:void 0,subtitle:F?a:void 0,actions:F?f(x,{to:B,children:m(c,{variant:`primary`,size:`sm`,children:[f(g,{className:`h-3.5 w-3.5 mr-1`}),p]})}):void 0,children:_?f(r,{children:f(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):h.length===0?f(r,{children:f(t,{title:v,description:y??`Install an addon that declares the "${d}" capability to get started.`,action:F?f(x,{to:B,children:m(c,{variant:`primary`,size:`sm`,children:[f(g,{className:`h-3.5 w-3.5 mr-1`}),p]})}):void 0})}):m(`div`,{className:`flex flex-col gap-4`,children:[h.map(t=>{let n=!I||L===t.addonId,i=S?.(t)??(t.isActive?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`),a=E?.(t)??null;return m(r,{children:[m(`div`,{className:`flex flex-col gap-3 p-4 sm:flex-row sm:items-center ${n?`border-b border-border`:``}`,children:[m(`div`,{className:`flex items-center gap-3 flex-1 min-w-0`,children:[I&&f(`button`,{type:`button`,onClick:()=>z(t.addonId),"aria-label":n?`Collapse`:`Expand`,className:`shrink-0 p-1 rounded hover:bg-foreground-subtle/10 transition-colors`,children:f(b,{className:`h-4 w-4 text-foreground-subtle transition-transform ${n?`rotate-180`:``}`})}),m(`button`,{type:`button`,onClick:()=>I&&z(t.addonId),className:`flex items-center gap-4 flex-1 min-w-0 text-left ${I?`hover:opacity-80 transition-opacity`:``}`,disabled:!I,children:[f(D,{addonId:t.addonId,fallback:s,tileClassName:i}),m(`div`,{className:`flex-1 min-w-0`,children:[m(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[f(`span`,{className:`font-semibold text-foreground`,children:t.displayName}),f(j,{isActive:t.isActive}),C?.(t)]}),m(`div`,{className:`text-xs text-foreground-subtle mt-1 font-mono break-all`,children:[`@camstack/addon-`,t.addonId]})]})]})]}),m(`div`,{className:`flex items-center gap-1 shrink-0 flex-wrap justify-end`,children:[T?.(t),f(M,{capName:d,addonId:t.addonId,isActive:t.isActive}),f(N,{addonId:t.addonId,displayName:t.displayName})]})]}),n&&m(`div`,{className:`p-4 flex flex-col gap-3`,children:[a!==null&&f(e,{message:a}),k?.(t),f(O,{addonId:t.addonId,maxHeight:A,capability:d})]})]},t.addonId)}),P]})})}function j({isActive:e}){return f(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${e?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:e?`Enabled`:`Disabled`})}function M({capName:e,addonId:t,isActive:n}){let r=p(),i=s({onSuccess:()=>{r.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}}),a=i.isPending;return m(c,{size:`sm`,variant:n?`secondary`:`primary`,disabled:a,onClick:()=>i.mutate({capName:e,addonId:t,enabled:!n}),children:[a?f(C,{className:`h-3 w-3 animate-spin`}):f(n?v:E,{className:`h-3 w-3`}),n?`Disable`:`Enable`]})}function N({addonId:e,displayName:t}){let r=p(),i=a({onSuccess:()=>{r.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}});return f(n,{label:`Restart`,icon:_,size:`sm`,title:`Restart "${t}"?`,description:`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:i.isPending,action:()=>i.mutateAsync({addonId:e})})}export{E as n,A as t};
@@ -1 +0,0 @@
1
- import{$ as e,Li as t,Pi as n,Q as r,Z as i,_t as a,ct as o,dt as s,et as c,ft as l,g as u,gr as d,gt as ee,ht as f,it as te,lt as p,m,nt as h,ot as g,pt as _,rt as v,st as ne,tt as re,ur as y,v as ie,vt as ae}from"./src-D-eMZfpa.js";import{F as b,G as x,L as oe,R as S,U as C,W as w,X as T,b as E,o as D,x as O,y as k}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as A}from"./player-overlays-B1rOp2K0.js";import{t as j}from"./download-B3pGiRsg.js";import{t as se}from"./plus-CljwKCLZ.js";import{t as M}from"./refresh-cw-9auw5j71.js";import{t as ce}from"./search-BYve1v5o.js";import{t as N}from"./upload-BQ5R4JaW.js";import{A as P,B as F,F as I,H as L,P as R,W as z,f as B,h as V,i as H,o as U,p as le,s as ue,x as W}from"./index-CBUhNGng.js";import{t as G}from"./AdminPage-CN6ZMhf0.js";import{t as de}from"./NodeAddonsSettingsPanel-DZOqqqZZ.js";var fe=F(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),K=F(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`polyline`,{points:`12 6 12 12 16 14`,key:`68esgv`}]]),q=F(`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`}]]),pe=F(`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`}]]);T();function J({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:i}){let a=n===`upload`||n===`local`,{data:o,isLoading:s}=h({name:e});return O(`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:[O(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[E(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),E(`button`,{type:`button`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:E(H,{className:`h-3 w-3`})})]}),a&&O(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[E(N,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),O(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[O(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,E(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),s&&O(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[E(W,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),o&&E(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:o.map(e=>{let n=e.version===t,i=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version);return O(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[E(`span`,{className:`font-mono flex-1 ${n?`text-primary font-semibold`:i?`text-amber-400`:`text-foreground`}`,children:e.version}),e.distTags.map(e=>E(`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&&E(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),E(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()}),n&&!a?E(I,{className:`h-3 w-3 text-primary shrink-0`}):E(`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:E(j,{className:`h-3 w-3`})})]},e.version)})}),o&&o.length===0&&E(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var Y={queued:{icon:K,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:W,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:M,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:I,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:q,bg:`bg-danger/10 text-danger`,label:`failed`}};function me({item:e}){let t=Y[e.status],n=t.icon;return O(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[E(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}var X=`device-export`;function he(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===X)}function ge({isBundle:e,installSource:t,addonId:n,iconPath:r,color:i}){let[a,o]=x(!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 O(`div`,{className:`relative flex-shrink-0`,children:[E(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${s?``:c}`,style:s,children:u?E(`img`,{src:l,alt:n,className:`h-5 w-5`,onError:()=>o(!0)}):E(e?pe:V,{className:`h-4 w-4`})}),t===`local`&&E(`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`&&E(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:E(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:E(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&E(`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:E(N,{className:`h-2.5 w-2.5 text-white`})})]})}function _e({version:e,availableUpdate:t,isUpdating:n,installSource:r,disabled:i,onActivate:a,onOpenPicker:o,children:s}){return n?O(`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:[E(W,{className:`h-3 w-3 animate-spin`}),`Updating…`]}):O(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[O(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},disabled:i,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`,r===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:t?`border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:t?`Update available (${t}) — tap to update. Current ${e}.`:`Version ${e} — tap to view all versions`,children:[t&&E(j,{className:`h-3 w-3`}),e,!t&&E(R,{className:`h-3 w-3 opacity-50`})]}),t&&E(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:i,className:`hidden sm:inline-flex items-center rounded-md px-1 py-1 text-foreground-subtle border border-border hover:bg-surface-hover disabled:opacity-50`,title:`View all versions`,"aria-label":`View all versions`,children:E(R,{className:`h-3 w-3`})}),s]})}function ve({addonId:t}){let n=D(),{data:r=`inherit`}=e({addonId:t}),i=_({onSuccess:()=>{n.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return E(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(e=>E(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),i.mutate({addonId:t,channel:e})},disabled:i.isPending,className:`px-2.5 py-1 transition-colors capitalize ${r===e?e===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:e===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`: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===`inherit`?``:`border-l border-border`}`,children:e},e))})}function ye({addon:e,agents:t=[],clusterStatus:r,hideVersion:i,availableUpdate:a,onUpdate:o,isUpdating:c,bundle:l,bulkItem:d,disabledByBulk:f,isSystem:te}){let[h,g]=x(!1),[_,ne]=x(!1),[re,y]=x(!1),[ae,b]=x(!1),[oe,S]=x(!1),[C,w]=x(`logs`),T=D(),j=A(),ce=L(),N=n(),{manifest:P}=e,F=e.installedOn??[],I=!l&&!P.protected&&P.removable!==!1,z=!!l,V=l?.displayName??P.name,U=l?.packageName??P.packageName,W=l?.version??P.packageVersion??P.version,G=l?.installSource??e.installSource,K=l?l.bundle?.description??l.addons[0]?.manifest.description:P.description,Y=ee({onSuccess:()=>{T.invalidateQueries({queryKey:[[`addons`]]}),T.invalidateQueries({queryKey:[[`addonPages`]]}),T.invalidateQueries({queryKey:[[`capabilities`]]})}}),X=p({onSuccess:()=>{T.invalidateQueries({queryKey:[[`addons`]]})}}),be=v({onSuccess:()=>{T.invalidateQueries({queryKey:[[`addons`]]}),T.invalidateQueries({queryKey:[[`addonPages`]]}),T.invalidateQueries({queryKey:[[`capabilities`]]}),T.invalidateQueries({queryKey:[[`integrations`]]})}}),xe=s({onSuccess:()=>{T.invalidateQueries({queryKey:[[`addons`]]}),T.invalidateQueries({queryKey:[[`alerts`]]})}}),Z=e.health,Se=Z?.phase===`failed`&&!Z.inGracePeriod,Ce=Se&&Z?.nextRetryAt&&!Z.retrying;return O(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${Se?`border-red-500/50`:`border-border`}`,children:[Se&&Z&&O(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[E(q,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),O(`div`,{className:`flex-1 min-w-0`,children:[O(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,Z.retryCount,`)`]}),E(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:Z.lastError?.message??`Unknown error`}),Ce&&Z.nextRetryAt&&O(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(Z.nextRetryAt).toLocaleTimeString()]})]}),O(`button`,{type:`button`,disabled:xe.isPending||Z.retrying,onClick:e=>{e.stopPropagation(),xe.mutate({packageName:U})},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:[E(M,{className:`h-3 w-3 ${xe.isPending||Z.retrying?`animate-spin`:``}`}),`Retry now`]})]}),O(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[E(ge,{isBundle:z||!!P.components&&P.components.length>1,installSource:G,addonId:z?l.addons[0]?.manifest.id:P.id,iconPath:z?l.bundle?.icon??l.addons[0]?.manifest.icon:P.icon,color:z?l.addons[0]?.manifest.color:P.color}),O(`div`,{className:`flex-1 min-w-0`,children:[O(`div`,{className:`flex items-start justify-between gap-2`,children:[E(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:V}),!i&&E(_e,{version:W,availableUpdate:a,isUpdating:c,installSource:G,disabled:f,onActivate:()=>{a&&o?o():y(e=>!e)},onOpenPicker:()=>y(e=>!e),children:re&&E(J,{packageName:U,currentVersion:W,...G?{installSource:G}:{},onInstall:e=>{y(!1),be.mutate({packageName:U,version:e})},onClose:()=>y(!1)})})]}),O(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[U!==V&&E(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:U}),z&&O(`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:[E(pe,{className:`h-3 w-3`}),l.addons.length]}),te&&O(`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:[E(M,{className:`h-3 w-3`}),`System`]}),d!=null&&E(me,{item:d})]}),K&&E(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:K}),!z&&e.process&&O(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[E(`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&&O(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),E(`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})]})]})]}),!z&&O(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[O(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),X.mutate({addonId:P.id})},disabled:X.isPending||f,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:[E(M,{className:`h-3 w-3 ${X.isPending?`animate-spin`:``}`}),`Restart`]}),O(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),b(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:[E(le,{className:`h-3 w-3`}),`Logs`]}),!z&&O(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${oe?`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:[E(B,{className:`h-3 w-3`}),`Settings`]}),E(`div`,{className:`flex-1`}),I&&O(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await N({title:`Uninstall ${P.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&Y.mutate({packageName:P.packageName})},disabled:Y.isPending||f,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:[E(ue,{className:`h-3 w-3`}),Y.isPending?`Removing...`:`Uninstall`]})]}),r&&r.nodes.length>1&&!z&&O(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[E(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),E(`div`,{className:`space-y-1`,children:r.nodes.map(e=>O(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[E(`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`}`}),E(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),E(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&E(`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`&&E(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&E(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),ae&&!z&&O(`div`,{className:`border-t border-border`,children:[O(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[O(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[E(`button`,{type:`button`,onClick:()=>w(`logs`),className:`px-2 py-0.5 transition-colors ${C===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),E(`button`,{type:`button`,onClick:()=>w(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${C===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),E(`div`,{className:`flex-1`}),E(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),b(!1)},className:`text-foreground-subtle hover:text-foreground`,children:E(H,{className:`h-3.5 w-3.5`})})]}),C===`logs`&&E(u,{addonId:P.id,maxHeight:`max-h-64`,showFilters:!1}),C===`events`&&E(m,{addonId:P.id,category:`addon.*`,maxHeight:`max-h-64`})]}),z&&O(k,{children:[E(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:E(h?fe:R,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),h&&E(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:l.addons.map(e=>E(ye,{addon:e,agents:t,hideVersion:!0},e.manifest.id))})]}),oe&&!z&&E(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>S(!1),children:O(`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:[O(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[O(`div`,{className:`flex items-center gap-2`,children:[E(B,{className:`h-4 w-4 text-primary`}),O(`h2`,{className:`text-sm font-semibold text-foreground`,children:[V,` Settings`]})]}),E(`button`,{onClick:()=>S(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:E(H,{className:`h-4 w-4`})})]}),O(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[E(de,{nodeId:`hub`,addonIds:[P.id],level:`global`}),he(P)&&O(`div`,{children:[E(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),E(ie,{addonId:P.id,trpc:j.trpcClient,onOpenDevice:e=>ce(`/devices/${e}`)})]}),G===`npm`&&O(`div`,{children:[E(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),E(ve,{addonId:P.id})]}),P.components&&P.components.length>0&&O(`div`,{children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,P.components.length,`)`]}),E(`div`,{className:`flex flex-wrap gap-1`,children:P.components.map(e=>E(`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&&O(`div`,{children:[E(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),O(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[F.length===0&&E(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),F.map(e=>E(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),O(`div`,{className:`relative`,children:[O(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ne(e=>!e)},className:`inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors`,title:`Install on more agents`,children:[E(se,{className:`h-3 w-3`}),`Add agent`]}),_&&O(`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&&!F.includes(e.name)).map(e=>E(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ne(!1)},className:`w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors`,children:e.name},e.id)),t.filter(e=>!e.isHub&&!F.includes(e.name)).length===0&&E(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),E(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:E(`button`,{type:`button`,onClick:()=>S(!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`})})]})})]})}T();var be=`.tgz,.tar.gz,.zip`;function xe({onUploadSuccess:e}){let[t,n]=x(!1),r=w(null),i=b(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 O(k,{children:[E(`input`,{ref:r,type:`file`,accept:be,onChange:b(e=>{let t=e.target.files?.[0];t&&i(t),e.target.value=``},[i]),className:`hidden`}),O(`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?E(W,{className:`w-3.5 h-3.5 animate-spin`}):E(N,{className:`w-3.5 h-3.5`}),t?`Uploading...`:`Upload`]})]})}function Z({pending:e,onCancel:t,onConfirm:n,isPending:r,error:i}){return E(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:O(`div`,{className:`bg-surface border border-border rounded-md shadow-xl p-5 max-w-md w-full mx-4 space-y-3`,children:[O(`div`,{className:`flex items-center gap-2`,children:[E(U,{className:`w-4 h-4 text-amber-700`}),E(`h3`,{className:`text-sm font-medium text-foreground`,children:`Update system package?`})]}),O(`div`,{className:`space-y-2 text-[11px] text-foreground-subtle`,children:[O(`div`,{children:[E(`span`,{className:`font-mono text-foreground`,children:e.packageName}),E(`span`,{className:`mx-1`,children:`·`}),O(`span`,{className:`font-mono`,children:[`v`,e.fromVersion]}),E(`span`,{className:`mx-1`,children:`→`}),O(`span`,{className:`font-mono text-amber-700`,children:[`v`,e.toVersion]})]}),E(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 p-2 text-amber-800`,children:`The hub will restart immediately after the install. Any in-flight requests will be dropped. The reconnect typically takes ~10 seconds.`}),i!==null&&E(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-2 text-danger`,children:i})]}),O(`div`,{className:`flex justify-end gap-2 pt-1`,children:[E(`button`,{type:`button`,onClick:t,disabled:r,className:`px-3 py-1.5 text-[11px] rounded bg-surface hover:bg-surface-hover border border-border disabled:opacity-50`,children:`Cancel`}),O(`button`,{type:`button`,onClick:n,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] rounded bg-amber-500/20 text-amber-800 hover:bg-amber-500/30 border border-amber-500/40 font-medium disabled:opacity-50`,children:[r?E(W,{className:`w-3 h-3 animate-spin`}):E(j,{className:`w-3 h-3`}),`Update & restart`]})]})]})})}T();function Se(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function Ce(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 we(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 Q(e){return`bundle`in e}function Te({addons:e,clusterStatus:t,selectedNode:r,onRefresh:o,isRefreshing:s}){let u=D(),[d,ee]=x(``),te=oe(d),[p,m]=x(!1),h=w(null);S(()=>{if(!p)return;let e=e=>{h.current&&!h.current.contains(e.target)&&m(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[p]);let{data:_}=ne({nodeId:r.id}),y=C(()=>{let e=new Map;for(let t of _??[])e.set(t.name,t.latestVersion);return e},[_]),[ie,T]=x(null),[k,A]=x(null),se=ae({onMutate:e=>{T(e.name),A(null)},onSuccess:(e,t)=>{T(null);let n=e;if(n&&n.success===!1){A({name:t.name,message:n.error??`Update failed (no error message returned by server)`});return}u.invalidateQueries({queryKey:[[`addons`]]}),u.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{T(null),A({name:t.name,message:e instanceof Error?e.message:String(e)})}}),{data:N}=c(void 0),F=i({onSuccess:()=>{u.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:L,isFetching:R}=l({query:te||void 0},{enabled:p}),B=f(),{data:V}=re(void 0),H=V?.requestedAt,[U,le]=x(null),[ue,G]=x(!1);S(()=>{if(V?.kind===`framework-bulk-update`&&V.requestedAt!==U){le(V.requestedAt),G(!0);let e=window.setTimeout(()=>G(!1),6e3);return()=>window.clearTimeout(e)}},[H,U,V]);let{data:de}=g(void 0),fe=C(()=>new Map((de??[]).map(e=>[e.packageName,e])),[de]),[K,q]=x(null),[pe,J]=x(null),Y=a({onSuccess:()=>{q(null),u.invalidateQueries({queryKey:[[`addons`]]})},onError:e=>{J(e instanceof Error?e.message:String(e))}}),me=n(),X=b(async()=>{let e=_??[];e.length!==0&&(e.some(e=>e.isSystem)&&!await me({title:`Update all — includes a system package`,message:`This batch updates a system package (@camstack/system). The hub will restart automatically once the framework update completes. In-flight requests are dropped; reconnect typically takes ~10 seconds.`,confirmLabel:`Update all & restart`,variant:`warning`})||await B.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[r.id]}))},[_,r.id,B,me]),he=v({onSuccess:()=>{u.invalidateQueries({queryKey:[[`addons`]]}),u.invalidateQueries({queryKey:[[`addonPages`]]}),u.invalidateQueries({queryKey:[[`capabilities`]]}),u.invalidateQueries({queryKey:[[`integrations`]]})}}),[ge,_e]=x(`type`),[ve,be]=x(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),Ce=e=>{be(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[Te,Ee]=z(),$=Te.get(`capability`),De=C(()=>{let t=r.isHub?e:e.filter(e=>Se(e.placement,r.isHub));return $&&(t=t.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===$))),t},[e,r.isHub,$]),Oe=()=>{let e=new URLSearchParams(Te);e.delete(`capability`),Ee(e,{replace:!0})},ke=ve===`flat`?De:we(De),Ae=C(()=>{let e=[...ke];switch(ge){case`type`:e.sort((e,t)=>{let n=+!Q(e),r=+!Q(t);if(n!==r)return n-r;let i=Q(e)?e.bundle.displayName:e.manifest.name,a=Q(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=Q(e)?e.bundle.displayName:e.manifest.name,r=Q(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=Q(e)?e.bundle.installSource??``:e.installSource??``,r=Q(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[ke,ge]);return O(`div`,{className:`space-y-4`,children:[k&&E(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:O(`div`,{className:`flex items-start justify-between gap-3`,children:[O(`div`,{className:`space-y-0.5`,children:[O(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,k.name]}),E(`div`,{className:`text-foreground-subtle font-mono`,children:k.message})]}),E(`button`,{type:`button`,onClick:()=>A(null),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})}),O(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[O(`div`,{className:`flex items-center gap-1.5`,children:[E(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),O(`select`,{value:ge,onChange:e=>_e(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:[E(`option`,{value:`type`,children:`Bundles first`}),E(`option`,{value:`name`,children:`Name`}),E(`option`,{value:`source`,children:`Install source`})]})]}),O(`div`,{className:`flex items-center gap-1.5`,children:[E(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),E(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>E(`button`,{type:`button`,onClick:()=>Ce(e),className:`px-2.5 py-1.5 transition-colors capitalize ${ve===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))})]}),r.isHub&&O(`div`,{className:`flex items-center gap-1.5`,children:[E(M,{className:`h-3 w-3 text-foreground-subtle`}),E(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),E(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>E(`button`,{type:`button`,onClick:()=>F.mutate({channel:e}),disabled:F.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${N?.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))})]}),(_?.length??0)>0&&O(`button`,{type:`button`,onClick:()=>void X(),disabled:B.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:[B.isPending?E(W,{className:`w-3 h-3 animate-spin`}):E(j,{className:`w-3 h-3`}),B.isPending?`Updating…`:`Update All (${_.length})`]}),O(`button`,{type:`button`,onClick:o,disabled:s||B.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:[E(M,{className:`w-3 h-3 ${s?`animate-spin`:``}`}),`Refresh`]})]}),O(`div`,{className:`flex items-center gap-3`,children:[O(`div`,{className:`relative flex-1 min-w-[200px]`,ref:h,children:[E(ce,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),E(`input`,{type:`text`,value:d,onChange:e=>{ee(e.target.value),m(!0)},onFocus:()=>m(!0),placeholder:`Search addons on npm...`,disabled:B.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`}),R&&E(W,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),p&&L&&L.length>0&&O(`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:[L.length>0&&O(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,L.length,`)`]}),L&&L.length>0&&E(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:L.map(e=>O(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[E(`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()}),O(`div`,{className:`flex-1 min-w-0`,children:[O(`div`,{className:`flex items-center gap-2`,children:[E(`span`,{className:`text-[11px] font-semibold truncate`,children:e.name}),O(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`v`,e.version]})]}),e.description&&E(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?O(`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:[E(I,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):O(`button`,{type:`button`,onClick:()=>he.mutate({packageName:e.name}),disabled:he.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:[he.isPending?E(W,{className:`h-3 w-3 animate-spin`}):E(j,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),E(xe,{onUploadSuccess:()=>{u.invalidateQueries({queryKey:[[`addons`]]}),o()}})]}),$&&O(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[E(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),E(`span`,{className:`font-mono text-primary font-semibold`,children:$}),E(`button`,{type:`button`,onClick:Oe,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),ue&&O(`div`,{className:`fixed top-4 right-4 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:[E(P,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),O(`div`,{children:[E(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),E(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),De.length===0&&E(`div`,{className:`text-xs text-foreground-subtle`,children:e.length===0?`No addons installed`:$?`No installed addons declare the "${$}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${r.name} (placement filter active)`}),E(`div`,{className:`space-y-2`,children:Ae.map(e=>{let n=Q(e)?e.bundle.packageName:e.manifest.packageName,i=y.get(n),a=Q(e)?e.representative:e,o=fe.has(n),s=i?o?()=>q({packageName:n,fromVersion:fe.get(n)?.currentVersion??a.manifest.packageVersion??a.manifest.version,toVersion:i}):()=>se.mutate({name:n,version:i,nodeId:r.id}):void 0;return E(ye,{addon:a,clusterStatus:t?.[a.manifest.id],bundle:Q(e)?e.bundle:void 0,availableUpdate:i,isUpdating:ie===n,onUpdate:s,isSystem:o,disabledByBulk:B.isPending},Q(e)?n:e.manifest.id)})}),K!==null&&E(Z,{pending:K,onCancel:()=>{q(null),J(null)},onConfirm:()=>{J(null),Y.mutate({packageName:K.packageName,version:K.toVersion})},isPending:Y.isPending,error:pe})]})}function Ee(){let e=D(),{data:n,isLoading:i,isError:a}=te(),{data:s}=y(void 0),{data:c}=d(void 0,{refetchInterval:1e4}),l=C(()=>{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]),[u,ee]=x(`hub`),f=l.find(e=>e.id===u)??l[0],p=r(),m=o(),h=p.isPending||m.isPending,g=async()=>{await p.mutateAsync({nodeId:u}),await m.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},_=w(p);_.current=p,S(()=>{_.current.mutate({nodeId:`hub`})},[]);let v=(n??[]).map(Ce).filter(e=>e!==null);return O(G,{children:[O(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[E(t,{selectedNodeId:u,onSelect:ee}),O(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!i&&!a&&O(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[v.length,` installed`]}),O(`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:[E(M,{className:`w-3 h-3 ${h?`animate-spin`:``}`}),`Check for updates`]})]})]}),!f.isHub&&O(`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`,` `,E(`span`,{className:`font-medium text-foreground`,children:f.name}),` — agents only run`,` `,E(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,E(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),i&&E(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),a&&E(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!i&&!a&&E(Te,{addons:v,clusterStatus:s,selectedNode:f,onRefresh:()=>void g(),isRefreshing:h})]})}export{Ee as AddonsPage};
@@ -1 +0,0 @@
1
- import{b as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";function n({icon:n,title:r,subtitle:i,actions:a,children:o}){return t(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[(!!r||i!=null||a!=null)&&t(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between sm:gap-4`,children:[t(`div`,{className:`min-w-0`,children:[r&&t(`h1`,{className:`text-lg font-semibold text-foreground flex items-center gap-2`,children:[n&&e(n,{className:`h-4 w-4 text-foreground-subtle shrink-0`}),r]}),i&&e(`p`,{className:`text-xs text-foreground-subtle mt-0.5`,children:i})]}),a&&e(`div`,{className:`shrink-0 flex items-center gap-2 flex-wrap`,children:a})]}),o]})}export{n as t};
@@ -1 +0,0 @@
1
- import{Fi as e}from"./src-D-eMZfpa.js";import{G as t,U as n,X as r,a as i,b as a,t as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as c}from"./player-overlays-B1rOp2K0.js";import{t as l}from"./circle-check-big-BjqV4p1D.js";import{j as u,u as d,x as f}from"./index-CBUhNGng.js";import{t as p}from"./AdminPage-CN6ZMhf0.js";r();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:t}){let n=e.name.toLowerCase(),r=m[n]??`border-primary`,i=h[n]??`bg-primary/5`,o=e.providers.find(e=>e.active),c=t?.pendingCapability===e.name;return s(`div`,{className:`rounded-lg border-t-2 border border-border ${r} ${i} p-3 space-y-2`,children:[s(`div`,{className:`flex items-center justify-between gap-2`,children:[s(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&a(f,{className:`h-3 w-3 animate-spin text-primary`})]}),a(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?a(_,{entry:e,actions:t,activeProvider:o,isPending:c}):a(v,{entry:e,actions:t,isPending:c})]})}function _({entry:e,actions:t,activeProvider:n,isPending:r}){if(!t)return a(`div`,{children:n?s(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[a(l,{className:`h-3 w-3 text-green-400 shrink-0`}),a(`span`,{className:`font-medium`,children:n.addonName}),a(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):a(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return a(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let i=`__inherit__`;return s(`div`,{className:`space-y-2`,children:[a(`div`,{className:`space-y-1`,children:e.providers.map(n=>{let i=n.active;return s(`button`,{type:`button`,disabled:r||i,onClick:()=>t.onSelectSingleton(e.name,n.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${i?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[a(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${i?`border-green-400 bg-green-400`:`border-border`}`}),a(`span`,{className:`font-medium truncate`,children:n.addonName}),i&&a(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},n.addonId)})}),e.perNode&&e.perNode.length>0&&a(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(n=>{let o=n.hasOverride&&n.resolvedActive?n.resolvedActive:i,c=[{value:i,label:`Inherit global${n.resolvedActive?` (${n.resolvedActive})`:``}`},...n.providers.map(e=>({value:e,label:e}))],l=r=>{r===i?t.onClearNodeSingleton(e.name,n.nodeId):t.onSelectNodeSingleton(e.name,n.nodeId,r)},u=r;return s(`div`,{className:`space-y-0.5`,children:[s(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[n.nodeId,n.hasOverride&&a(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let t=o===e.value;return s(`button`,{type:`button`,disabled:u||t,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${t?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[a(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${t?`border-green-400 bg-green-400`:`border-border`}`}),a(`span`,{className:`font-medium truncate`,children:e.label}),t&&e.value!==i&&a(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},n.nodeId)})})]})}function v({entry:e,actions:t,isPending:n}){if(e.providers.length===0)return a(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!t)return a(`div`,{className:`space-y-1`,children:e.providers.map(e=>s(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[a(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&a(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let r=e.providers.filter(e=>e.active).map(e=>e.addonId),i=(n,i)=>{let a=i?[...new Set([...r,n])]:r.filter(e=>e!==n);t.onToggleCollection(e.name,a)};return a(`div`,{className:`space-y-1`,children:e.providers.map(e=>s(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${n?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[s(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[a(`input`,{type:`checkbox`,checked:e.active,disabled:n,onChange:t=>i(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),a(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&a(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?a(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):a(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>a(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let r=c(),[f,m]=t(null),[h,g]=t(null),_=i({queryKey:b,queryFn:()=>r.trpcClient.capabilities.listCapabilities.query()}),v=n(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=n(()=>v.filter(e=>e.mode===`singleton`),[v]),w=n(()=>v.filter(e=>e.mode===`collection`),[v]),T=o({mutationFn:e=>r.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=o({mutationFn:e=>r.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId,nodeId:e.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=o({mutationFn:e=>r.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:e.capName,nodeId:e.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=o({mutationFn:e=>r.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:e.capName,enabledAddonIds:[...e.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:f};return s(p,{icon:d,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&s(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?a(l,{className:`h-3.5 w-3.5 shrink-0`}):a(u,{className:`h-3.5 w-3.5 shrink-0`}),a(`span`,{children:h.message})]}),_.isLoading&&a(`div`,{className:`flex items-center justify-center py-16`,children:a(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&a(e,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&a(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&s(`div`,{className:`space-y-6`,children:[S.length>0&&s(`section`,{className:`space-y-2`,children:[a(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),a(y,{capabilities:S,actions:k})]}),w.length>0&&s(`section`,{className:`space-y-2`,children:[a(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),a(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
@@ -1 +0,0 @@
1
- import{An as e,Cn as t,Dn as n,En as r,Mn as i,Nn as a,On as o,Pn as s,Tn as c,aa as l,ca as u,fa as d,ia as f,jn as p,kn as m,oa as h,pa as g,ra as _,sa as v,ua as y,wn as b}from"./src-D-eMZfpa.js";import{G as x,U as S,X as C,b as w,o as T,x as E,y as D}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{t as O}from"./pencil-BHXuzoZT.js";import{t as k}from"./plus-CljwKCLZ.js";import{t as A}from"./sparkles-BMTAprd6.js";import{t as j}from"./square-check-big-CPuMXqOw.js";import{t as M}from"./square-CondP2yo.js";import{B as N,F as P,M as F,P as I,i as L,m as R,s as z,x as B}from"./index-CBUhNGng.js";import{t as V}from"./AdminPage-CN6ZMhf0.js";var H=N(`user-check`,[[`path`,{d:`m16 11 2 2 4-4`,key:`9rsbq5`}],[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),U=N(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),W=N(`user-x`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`17`,x2:`22`,y1:`8`,y2:`13`,key:`3nzzx3`}],[`line`,{x1:`22`,x2:`17`,y1:`8`,y2:`13`,key:`1swrse`}]]);C();var G=[[`faceGallery`]];function K({identityId:t}){let n=T(),{data:r,isLoading:i}=o({identityId:t}),a=e();function s(e){a.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{n.invalidateQueries({queryKey:G})}})}return i?E(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[w(B,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!r||r.length===0?w(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):w(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:r.map(e=>E(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?w(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):w(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:w(U,{className:`h-6 w-6`})}),w(`button`,{type:`button`,onClick:()=>s(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:w(L,{className:`h-4 w-4 text-white`})})]},e.id))})}function q({identity:e,expanded:t,onToggle:n}){let i=T(),[a,o]=x(``),[s,c]=x(!1),[m,b]=x(!1),S=p(),C=r();function k(){o(e.name),c(!0)}function A(){c(!1),o(``)}function j(){let t=a.trim();if(!t||t===e.name){A();return}S.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:G}),A()}})}function M(){C.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:G}),b(!1)}})}return E(`div`,{className:`rounded-md border border-border bg-surface`,children:[E(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[w(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?w(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):w(`div`,{className:`flex h-full w-full items-center justify-center`,children:w(U,{className:`h-4 w-4 text-foreground-subtle`})})}),w(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:s?E(D,{children:[w(y,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&A()},className:`h-6 text-xs`,autoFocus:!0}),w(`button`,{type:`button`,onClick:j,disabled:S.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:w(P,{className:`h-3.5 w-3.5`})}),w(`button`,{type:`button`,onClick:A,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:w(L,{className:`h-3.5 w-3.5`})})]}):w(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),w(d,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!s&&E(`div`,{className:`flex items-center gap-1`,children:[w(`button`,{type:`button`,onClick:k,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:w(O,{className:`h-3.5 w-3.5`})}),w(`button`,{type:`button`,onClick:()=>b(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:w(z,{className:`h-3.5 w-3.5`})})]}),w(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:w(t?I:F,{className:`h-3.5 w-3.5`})})]}),t&&w(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:w(K,{identityId:e.id})}),w(_,{open:m,onOpenChange:e=>!e&&b(!1),children:E(f,{children:[E(v,{children:[w(u,{children:`Delete person`}),E(l,{children:[`Delete `,w(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),E(h,{children:[w(g,{variant:`secondary`,onClick:()=>b(!1),children:`Cancel`}),E(g,{variant:`danger`,onClick:M,disabled:C.isPending,children:[C.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function J(){let e=T(),[t,n]=x(``),r=b();function i(){let i=t.trim();i&&r.mutate({name:i},{onSettled:()=>{e.invalidateQueries({queryKey:G}),n(``)}})}return E(`div`,{className:`flex items-center gap-2 pt-2`,children:[w(y,{placeholder:`New person name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i()},className:`h-7 text-xs flex-1`}),E(g,{variant:`primary`,size:`sm`,onClick:i,disabled:r.isPending||!t.trim(),children:[r.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):w(k,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Y(){let{data:e,isLoading:t}=n(),[r,i]=x(null);function a(e){i(t=>t===e?null:e)}return t?E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[w(B,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):E(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&w(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>w(q,{identity:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),w(J,{})]})}C();var X=[[`faceGallery`]];function Z({faceIds:e,identities:n,onDone:r}){let i=T(),a=t(),o=b(),[s,c]=x(``),[d,p]=x(!1),[m,S]=x(null),C=e!==null&&e.length>0,D=e?.length??0;function O(){p(!1),c(``),S(null)}function k(){O(),r()}function A(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:X}),k()}})}function j(){!e||!s.trim()||o.mutate({name:s.trim()},{onSuccess:e=>{e?.id&&A(e.id)},onError:()=>{i.invalidateQueries({queryKey:X}),k()}})}let M=a.isPending||o.isPending;return w(_,{open:C,onOpenChange:e=>!e&&k(),children:E(f,{children:[E(v,{children:[w(u,{children:D>1?`Assign ${D} faces to person`:`Assign face to person`}),w(l,{children:`Select an existing person or create a new one.`})]}),w(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(e=>E(`button`,{type:`button`,onClick:()=>S(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${m===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[w(`span`,{className:`font-medium`,children:e.name}),E(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),d?w(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:w(y,{placeholder:`New person name…`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j()},autoFocus:!0,className:`flex-1`})}):w(`button`,{type:`button`,onClick:()=>{S(null),p(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New person…`}),E(h,{children:[w(g,{variant:`secondary`,onClick:k,disabled:M,children:`Cancel`}),d?E(g,{variant:`primary`,onClick:j,disabled:M||!s.trim(),children:[M&&w(B,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):E(g,{variant:`primary`,onClick:()=>m&&A(m),disabled:M||!m,children:[M&&w(B,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,D>1?` ${D}`:``]})]})]})})}function Q({face:e,selected:t,onToggleSelect:n,onAssign:r}){let i=T(),o=a(),s=c(),l=()=>{i.invalidateQueries({queryKey:X})};return E(`div`,{className:`group relative flex flex-col gap-1 rounded-md border bg-surface overflow-hidden ${t?`border-primary ring-1 ring-primary`:`border-border`}`,children:[E(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?w(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face`,className:`h-full w-full object-cover`}):w(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:w(U,{className:`h-8 w-8`})}),w(`button`,{type:`button`,onClick:()=>n(e.faceId),className:`absolute left-1 top-1 rounded bg-black/40 p-0.5 text-white hover:bg-black/60`,"aria-label":t?`Deselect`:`Select`,children:t?w(j,{className:`h-3.5 w-3.5 text-primary`}):w(M,{className:`h-3.5 w-3.5`})}),E(`div`,{className:`absolute inset-0 flex items-center justify-center gap-2 bg-black/50 opacity-0 transition-opacity group-hover:opacity-100`,children:[e.assigned?w(`button`,{type:`button`,onClick:()=>o.mutate({faceId:e.faceId},{onSettled:l}),disabled:o.isPending,className:`rounded-full bg-warning/80 p-1.5 text-white hover:bg-warning disabled:opacity-50`,title:`Detach`,children:o.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):w(W,{className:`h-3.5 w-3.5`})}):w(`button`,{type:`button`,onClick:()=>r(e.faceId),className:`rounded-full bg-primary/80 p-1.5 text-white hover:bg-primary`,title:`Assign to person`,children:w(H,{className:`h-3.5 w-3.5`})}),w(`button`,{type:`button`,onClick:()=>s.mutate({faceId:e.faceId},{onSettled:l}),disabled:s.isPending,className:`rounded-full bg-danger/80 p-1.5 text-white hover:bg-danger disabled:opacity-50`,title:`Delete face`,children:s.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):w(z,{className:`h-3.5 w-3.5`})})]})]}),E(`div`,{className:`px-2 pb-2 space-y-0.5`,children:[w(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.deviceId}),e.identityName&&w(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]})]})}var $=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function ee(){let e=T(),[r,a]=x(`all`),[o,l]=x(new Set),[u,d]=x(null),[f,p]=x(!1),{data:h,isLoading:_}=m({limit:100,filter:r}),{data:v=[]}=n(),{data:y,isFetching:b}=i({threshold:.5,minClusterSize:2,limit:20},{enabled:f}),C=t(),D=s(),O=c(),k=h??[],j=S(()=>new Map(k.map(e=>[e.faceId,e])),[k]),M=()=>{e.invalidateQueries({queryKey:X})},N=()=>l(new Set);function P(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function F(e){l(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}let I=[...o],R=C.isPending||D.isPending||O.isPending;function V(){I.length!==0&&D.mutate({faceIds:I},{onSettled:()=>{M(),N()}})}function G(){I.length!==0&&Promise.allSettled(I.map(e=>O.mutateAsync({faceId:e}))).then(()=>{M(),N()})}return E(`div`,{className:`space-y-3`,children:[E(`div`,{className:`flex items-center gap-1`,children:[$.map(e=>w(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${r===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value)),E(`button`,{type:`button`,onClick:()=>p(e=>!e),className:`ml-2 flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${f?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[w(A,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!_&&E(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[k.length,` face`,k.length===1?``:`s`]})]}),o.size>0&&E(`div`,{className:`flex items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[E(`span`,{className:`text-xs font-medium text-foreground`,children:[o.size,` selected`]}),E(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[E(g,{variant:`primary`,onClick:()=>d(I),disabled:R,children:[w(H,{className:`h-3.5 w-3.5`}),` Assign`]}),E(g,{variant:`secondary`,onClick:V,disabled:R,children:[D.isPending?w(B,{className:`h-3.5 w-3.5 animate-spin`}):w(W,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),E(g,{variant:`secondary`,onClick:G,disabled:R,children:[w(z,{className:`h-3.5 w-3.5`}),` Delete`]}),w(g,{variant:`ghost`,onClick:N,disabled:R,children:w(L,{className:`h-3.5 w-3.5`})})]})]}),f&&E(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:[w(`p`,{className:`mb-2 text-xs font-medium text-foreground`,children:`Look-alike groups`}),b?E(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[w(B,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):!y||y.length===0?w(`p`,{className:`text-xs text-foreground-subtle`,children:`No look-alike groups found among unassigned faces.`}):w(`div`,{className:`space-y-2`,children:y.map(e=>E(`div`,{className:`flex items-center gap-2 rounded-md bg-surface-hover/50 p-2`,children:[w(`div`,{className:`flex -space-x-1.5`,children:e.faceIds.slice(0,6).map(e=>{let t=j.get(e);return w(`div`,{className:`h-8 w-8 overflow-hidden rounded border border-border bg-surface`,children:t?.base64?w(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-full w-full object-cover`}):w(U,{className:`h-full w-full p-1.5 text-foreground-subtle`})},e)})}),E(`span`,{className:`text-xs text-foreground-subtle`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]}),E(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[w(g,{variant:`secondary`,onClick:()=>F(e.faceIds),children:`Select group`}),E(g,{variant:`primary`,onClick:()=>d(e.faceIds),children:[w(H,{className:`h-3.5 w-3.5`}),` Assign all`]})]})]},e.representativeFaceId))})]}),_&&E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[w(B,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!_&&k.length===0&&w(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No faces found for this filter.`}),!_&&k.length>0&&w(`div`,{className:`grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8 lg:grid-cols-10`,children:k.map(e=>w(Q,{face:e,selected:o.has(e.faceId),onToggleSelect:P,onAssign:e=>d([e])},e.faceId))}),w(Z,{faceIds:u,identities:v,onDone:()=>{d(null),N()}})]})}function te(){return w(V,{icon:R,title:`Detection Intelligence`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:E(`section`,{className:`space-y-3`,children:[E(`div`,{children:[w(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),w(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled identities used for face recognition. Expand a row to view or remove training samples.`}),w(Y,{})]}),E(`div`,{className:`pt-4 border-t border-border`,children:[w(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),w(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`}),w(ee,{})]})]})})}export{te as DetectionIntelligencePage};
@@ -1,2 +0,0 @@
1
- import{A as e,Ai as t,Ar as n,B as r,E as i,G as a,Gi as o,Gn as s,H as c,I as l,Ji as u,Jt as d,K as f,Ki as p,Kn as m,L as h,Pi as g,Pr as _,Qi as v,Sn as y,T as b,Tt as x,U as S,V as C,Vr as w,W as T,Wi as E,Yi as D,Yr as O,Yt as k,_n as A,a as j,an as M,bn as ee,cn as N,di as P,dn as F,f as I,fn as te,g as ne,gn as re,hn as L,i as ie,ii as ae,in as oe,j as se,k as ce,ki as le,l as ue,ln as de,lr as fe,lt as pe,m as me,mn as he,n as ge,ni as _e,nn as ve,o as ye,p as be,pn as xe,qn as Se,qt as Ce,r as R,u as we,ui as Te,un as Ee,va as De,vn as Oe,w as ke,xn as Ae,xr as je,y as Me,ya as Ne,yn as Pe,zn as Fe,zr as Ie}from"./src-D-eMZfpa.js";import{F as z,G as B,R as V,U as H,W as U,X as W,b as G,o as K,t as Le,x as q,y as Re}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{c as ze,k as Be,p as J,r as Ve,t as He,u as Ue}from"./player-overlays-B1rOp2K0.js";import{C as We,E as Ge,b as Y,g as Ke,v as qe}from"./src-DUWILaCU.js";import{t as Je}from"./CapabilityBadges-CMb2KZ75.js";import{t as Ye}from"./bell-DUIEkGPA.js";import{n as Xe,t as Ze}from"./rotate-ccw-DeNzdz-v.js";import{t as Qe}from"./ProviderIcon-BPXhRQ1d.js";import{t as $e}from"./pencil-BHXuzoZT.js";import{t as et}from"./plus-CljwKCLZ.js";import{t as tt}from"./refresh-cw-9auw5j71.js";import{t as nt}from"./rotate-cw-anx2g3R_.js";import{t as rt}from"./server-Bj7As5DB.js";import{t as it}from"./wifi-CV73GdWg.js";import{B as X,F as at,H as ot,I as st,O as ct,U as lt,W as ut,_ as dt,a as ft,c as pt,i as mt,k as ht,p as gt,r as _t,s as vt,t as yt,v as bt,x as xt,z as St}from"./index-CBUhNGng.js";import{t as Ct}from"./StatusBadge-CkYubfRG.js";import{n as wt,t as Tt}from"./useDevice-mTj6eL8W.js";import{n as Et,r as Dt,t as Ot}from"./SchemaTabBar-ByWwzBUZ.js";import{t as kt}from"./FormBuilder-D1P2uZCo.js";import{t as At}from"./useEventInvalidation-BXdyfSQv.js";var jt=X(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),Mt=X(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),Nt=X(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),Pt=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`}]]),Ft=X(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),It=X(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),Lt=X(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),Rt=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`}]]);W();var zt=`device-export`,Bt=`export`,Vt=`Export`;function Ht(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(Ht):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(Ht)):e.writerCapName===zt}function Ut(e){return e.fields.some(Ht)}function Wt(e){return j(J().trpcClient,e)}function Gt(e){let[t,n]=B(`idle`),[r,i]=B(null),a=U(null),o=U(null),c=U(null),l=U(!0),u=m(),d=s(),f=Se(),p=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}c.current=null},[]),h=z(async()=>{if(t===`idle`)return;n(`stopping`);let r=c.current;if(r&&e!==null)try{await Promise.race([f.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)}p(),l.current&&(n(`idle`),i(null))},[t,e,f,p]),g=z(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,s=null,p=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await u.mutateAsync({deviceId:e});p=t.sessionId,c.current=p,n(`connecting`),s=new RTCPeerConnection,a.current=s,s.oniceconnectionstatechange=()=>{if(!l.current)return;let e=s.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&l.current&&(i(e===`failed`?`WebRTC connection failed`:null),h())};for(let e of r.getAudioTracks())s.addTrack(e,r);await s.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let f=await s.createAnswer();await s.setLocalDescription(f);let m=s.localDescription?.sdp??f.sdp??``;await d.mutateAsync({deviceId:e,sessionId:p,sdpAnswer:m})}catch(t){let u=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),s)try{s.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,p!==null)try{await f.mutateAsync({deviceId:e,sessionId:p})}catch{}c.current=null,l.current&&(i(u),n(`error`))}},[e,t,u,d,f,h]);return V(()=>(l.current=!0,()=>{l.current=!1;let t=c.current;if(t!==null&&e!==null&&f.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}c.current=null}),[e]),{state:t,error:r,start:g,stop:h,isTalking:t===`talking`}}W();var Kt=0;function Z(){return++Kt}function qt(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Jt(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 Yt(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 Xt(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 Zt({scope:e,greeting:t,className:n}){let r=J(),[i,a]=B(()=>{let n=[];return t&&n.push({id:Z(),kind:`info`,text:t}),n.push({id:Z(),kind:`info`,text:`scope: ${qt(e)} — type help or context for available commands`}),n}),[o,s]=B(``),[c,l]=B([]),[u,d]=B(-1),f=U(null),p=U(null);V(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=z(()=>{f.current?.focus()},[]),h=Le({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:Z(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Z(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Z(),kind:`info`,text:`scope: ${qt(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Jt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Xt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Yt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Z(),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:Z(),kind:`info`,text:`scope: ${qt(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return q(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[q(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>G(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&G(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),q(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[G(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),G(`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 Qt({deviceId:e,intercomAvailable:t=!1}){let n=J(),r=typeof window<`u`?window.location.origin:``,a=Number.isFinite(e),o=Wt(a?e:null),{streams:s,pipelineMetrics:c,createSession:l,sendAnswer:u,handleOffer:d,getIceServers:f,addIceCandidate:p,getIceCandidates:m,closeSession:h,getSessionState:g}=ie(n.trpcClient,a?e:null),_=T(n.trpcClient,a?e:null),v=Gt(a&&t?e:null),y=v.state===`requesting-mic`||v.state===`starting`||v.state===`connecting`||v.state===`stopping`,b=v.isTalking||y,x=()=>{v.state===`idle`||v.state===`error`?v.start():v.state!==`stopping`&&v.stop()},S=Ve(),C=i(),w=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,E=S.length>0?G(Re,{children:S.map(e=>G(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return G(Me,{serverUrl:r,createSession:l,sendAnswer:u,handleOffer:d,getIceServers:f,addIceCandidate:p,getIceCandidates:m,closeSession:h,getSessionState:g,...C.request?{playbackUrl:C.request.url,playbackAuthToken:w,...C.request.label?{playbackLabel:C.request.label}:{},onExitPlayback:()=>C.clear()}:{},streams:s,pipelineMetrics:c,phase:o.phase,detections:o,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:_.src,..._.src?{posterUrl:_.src}:{},snapshotLoading:_.loading,onRefreshSnapshot:_.refresh,intercomAvailable:t,intercomShown:b,onIntercomToggle:x,extraOverlay:E,chromeless:!0,className:`h-full`})}function $t({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?G(`div`,{className:`flex flex-col h-full`,children:G(ne,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):q(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function en({deviceId:e}){if(!Number.isFinite(e))return q(`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 G(Zt,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function tn({deviceId:e}){return Number.isFinite(e)?G(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:G(me,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):q(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function nn({deviceId:e}){return Number.isFinite(e)?G(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:G(I,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):q(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function rn({parentDeviceId:e}){let{t}=yt(),n=ot(),i=J(),{data:a,isLoading:o,isError:s}=wt(e),{data:l}=N({deviceId:e},{enabled:Number.isFinite(e)});if(o)return G(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:G(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return G(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:G(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let u=a??[];if(u.length===0)return null;let d=C(l?.stableId??``,u,l?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),m=(e,t)=>G(r,{trpc:i.trpcClient,device:t,variant:`minimal`,onNavigate:p},e),h=f.some(e=>!!e.role),g=f.some(e=>!e.role),_=h&&!g?t(`device.accessories`,{defaultValue:`Accessories`}):!h&&g?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),v=f.length>0?q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[G(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:_}),G(`div`,{className:`space-y-1`,children:f.map(e=>m(e.id,e))})]}):null,y=d.disabledSection===void 0?null:G(c,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:G(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>m(e.id,e))})},d.disabledSection.title);return d.sections.length===0?y===null?v:q(`div`,{className:`space-y-2`,children:[v,y]}):q(`div`,{className:`space-y-2`,children:[d.sections.map(e=>G(c,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),v,y]})}function Q({label:e,value:t}){return q(`div`,{className:`${Be} flex items-start gap-2 sm:gap-3`,children:[G(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),G(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}W();function an({deviceId:e,initialName:t}){let n=K(),[r,i]=B(!1),[a,o]=B(t),[s,c]=B(!1),l=U(null);V(()=>{r||o(t)},[t,r]),V(()=>{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?G(Q,{label:`Name`,value:q(`div`,{className:`flex items-center gap-1`,children:[G(`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`}),G(`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:G(at,{className:`h-3 w-3`})}),G(`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:G(mt,{className:`h-3 w-3`})})]})}):G(Q,{label:`Name`,value:q(`div`,{className:`flex items-center gap-2 group`,children:[G(`span`,{className:`truncate`,children:t}),G(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit name`,children:G($e,{className:`h-3 w-3 text-foreground-subtle`})})]})})}W();function on({deviceId:e,initialLocation:t}){let n=K(),[r,i]=B(!1),[a,o]=B(t??``),[s,c]=B(!1),l=U(null),{data:u}=xe(void 0,{enabled:r}),d=u??[];V(()=>{r||o(t??``)},[t,r]),V(()=>{r&&l.current?.focus()},[r]);let f=A({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),p=H(()=>{let e=a.trim().toLowerCase();return e.length===0?d:d.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[d,a]),m=a.trim().length>0&&!d.some(e=>e.toLowerCase()===a.trim().toLowerCase()),h=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await f.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},g=()=>{o(t??``),i(!1)};return r?G(Q,{label:`Location`,value:q(`div`,{className:`relative`,children:[q(`div`,{className:`flex items-center gap-1`,children:[G(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?h():e.key===`Escape`&&g()},disabled:s,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),G(`button`,{type:`button`,onClick:()=>void h(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:G(at,{className:`h-3 w-3`})}),G(`button`,{type:`button`,onClick:g,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:G(mt,{className:`h-3 w-3`})})]}),(p.length>0||m)&&q(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[p.map(e=>q(`button`,{type:`button`,onClick:()=>{o(e),h(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[G(Ft,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),G(`span`,{className:`truncate`,children:e})]},e)),m&&q(`button`,{type:`button`,onClick:()=>void h(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[G(`span`,{className:`text-foreground-subtle`,children:`Create`}),q(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):G(Q,{label:`Location`,value:q(`div`,{className:`flex items-center gap-2 group`,children:[t?G(`span`,{className:`truncate`,children:t}):G(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),G(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit location`,children:G($e,{className:`h-3 w-3 text-foreground-subtle`})})]})})}W();var sn=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function cn(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function ln(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function un(){let t=e(),n=se(),{data:r}=N({deviceId:t??0},{enabled:t!==null}),{data:i}=M({deviceId:t??0},{enabled:t!==null}),a=r??n??null,[o,s]=B(`identity`);if(t===null||!a)return null;let c=String(a.stableId??``),l=String(a.name??``),u=String(a.type??``),d=String(a.addonId??``),f=a.features??[],p=new Set([`device-status`,`feature-probe`,`device-ops`]),m=(i?.entries??[]).filter(e=>e.kind===`native`&&!p.has(e.capName)).map(e=>e.capName),h=f.length>0?f:m,g=a.location??null,_=a.metadata??null,v=_!==null&&Object.keys(_).length>0;return q(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[q(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[G(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),v&&q(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[G(dn,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),G(dn,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!v||o===`identity`)&&q(`div`,{className:`divide-y divide-border`,children:[G(Q,{label:`ID`,value:q(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${t}`,q(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,c,`)`]})]})}),G(an,{deviceId:t,initialName:l}),G(on,{deviceId:t,initialLocation:g}),G(Q,{label:`Type`,value:u}),G(Q,{label:`Provider`,value:G(Qe,{type:d,size:`sm`,showLabel:!0})}),G(Q,{label:`Capabilities`,value:h.length>0?G(Je,{capabilities:h,showLabels:!0}):G(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),v&&o===`hardware`&&G(fn,{metadata:_})]})}function dn({active:e,onClick:t,label:n}){return G(`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 fn({metadata:e}){let t=sn.filter(t=>t in e),n=Object.keys(e).filter(e=>!sn.includes(e)).toSorted(),r=[...t,...n];return q(`div`,{children:[G(`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.`}),G(`div`,{className:`divide-y divide-border`,children:r.map(t=>G(Q,{label:cn(t),value:G(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:ln(e[t])})},t))})]})}W();function pn({deviceId:e}){let[t,n]=B(null),r=Ce({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 q(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[q(`div`,{className:`flex items-center justify-between gap-3`,children:[q(`div`,{children:[G(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),G(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),q(`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:[G(tt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&G(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function mn(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function hn({device:e}){let t=ot(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===Y.Camera,a=r===Y.Hub,o=e.features??[],s=o.includes(qe.Resyncable),{data:c}=fe({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),l=c?.streams??{},u=Object.entries(l),d=o.includes(qe.DoorbellButton),f=R(d?{deviceId:n??void 0,historyLimit:10}:void 0),p=f.latest?Date.now()-f.latest.timestamp<3e4:!1;return q(`div`,{className:`space-y-5`,children:[a&&n!==null&&G(be,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),s&&n!==null&&G(pn,{deviceId:n}),i&&n!==null&&G(ke,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),d&&G(we,{history:f.history,latestIsFresh:p}),i&&n!==null&&G(ke,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&u.length>0&&q(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[G(`div`,{className:`border-b border-border px-4 py-2`,children:G(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),G(`div`,{className:`divide-y divide-border`,children:u.map(([e,t])=>q(`div`,{className:`px-4 py-2.5`,children:[q(`div`,{className:`flex items-center gap-2 mb-2`,children:[G(it,{className:`h-3 w-3 text-foreground-subtle`}),G(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),q(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[G(gn,{label:`Nominal`,value:mn(t.nominalBitrateKbps??0)}),G(gn,{label:`Observed`,value:mn(t.observedBitrateKbps??0)}),G(gn,{label:`Peak`,value:mn(t.peakBitrateKbps??0)}),G(gn,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),G(un,{})]})}function gn({label:e,value:t,warning:n}){return q(`div`,{children:[G(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),G(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}W();function _n({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l}){let u=e.tabs??[],d=H(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),f=new Set(u.map(e=>e.id)),p=[...u,...[...d.keys()].filter(e=>!f.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],m=p[0]?.id??`general`,[h,g]=B(m),_=l!==void 0,v=new Set(p.map(e=>e.id)),y=_?c&&v.has(c)?c:m:v.has(h)?h:m,b=e=>{_?l(e):g(e)},x=d.get(y)??[],S={sections:x.length<=1?x.length===1?[{...x[0],title:``}]:x:x.every(e=>!e.title)?[{...x[0],title:``,fields:x.flatMap(e=>e.fields)}]:x},C=G(Et,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(p.length<=1)return q(`div`,{className:`flex flex-col gap-3`,children:[G(kt,{schema:e,values:t,onChange:r,onAction:i,disabled:s}),C]});let w=new Map,T=new Map;for(let[e,t]of d){w.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&T.set(e,a)}return q(`div`,{className:`flex flex-col gap-3`,children:[G(Ot,{tabs:p.map(e=>({id:e.id,label:e.label})),activeId:y,onChange:b,countByTab:w,pendingByTab:T}),G(kt,{schema:S,values:t,onChange:r,onAction:i,disabled:s}),C]})}W();function vn(e,t){return t&&t===`admin`?e:!0}function yn(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?Ut(e)&&Ut(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function bn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function xn(e){return e.key}function Sn(e){if(!bn(e))return e.value}function Cn(e){return bn(e)?null:e}function wn(e,t){for(let n of e)if(t(n),n.type===`group`)wn(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)wn(e.fields,t)}function Tn(e){if(!e)return{};let t={};for(let n of e.sections)wn(n.fields,e=>{let n=xn(e);n!==null&&(t[n]=Sn(e))});return t}function En(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(wn(r.fields,e=>{if(n!==null||xn(e)!==t)return;let r=Cn(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function Dn(e){return{...e,fields:e.fields.map(On)}}function On(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function kn(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=Cn(e);return n?vn(t,n.minRole)?e:On(e):e})}))}}function An({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r}){let i=K(),{user:a}=_t(),o=a?.isAdmin===!0,s=U(!1),{data:c,isLoading:l}=de({deviceId:e},{refetchInterval:()=>s.current?!1:2500,enabled:Number.isFinite(e)}),{data:u}=N({deviceId:e},{enabled:Number.isFinite(e)}),d=c?.settings??null,f=c?.live??null,p=H(()=>{if(!d&&!f)return null;let e=d?.sections??[],n=(f?.sections??[]).map(Dn),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!Ut(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...d?.tabs??[],...(f?.tabs??[]).filter(e=>!(d?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[d,f,t]),m=H(()=>yn(p),[p]),h=H(()=>kn(m,o),[m,o]),g=H(()=>Tn(h),[h]),_=P(),v=Te(),b=Ae(),x=L(),S=y({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),C={isPending:S.isPending,mutate:t=>{S.mutate({deviceId:e,changes:[...t]})}},w=Dt({schema:h,serverValues:g,onImmediateSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=En(h,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&C.mutate(t)},[h,C]),onDeferredSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=En(h,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&C.mutate(t)},[h,C])}),{values:T,pendingKeys:E,handleChange:D,handleSave:O,handleDiscard:k}=w;if(s.current=w.editingPaused,l)return q(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[G(xt,{className:`h-4 w-4 animate-spin mr-2`}),G(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!h||h.sections.length===0)return G(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function A(t,n,r){if(t===`regenerate-rtsp-token`){let t=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!t)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(t.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let a=We(e,r);await _.mutateAsync({brokerId:a}),i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!u)return{status:`error`,error:`Device metadata not loaded yet`};try{return await b.mutateAsync({addonId:u.addonId,type:u.type,key:n,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(t===`refresh-probe`){if(!n.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${n}" (expected "probedInfo:<streamId>")`);let t=n.slice(11);if(!t)throw Error(`refresh-probe: key "${n}" has no streamId after prefix`);let r=We(e,t),a=await v.mutateAsync({brokerId:r});return i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),a}if(t===`device-custom-action`){let t=await x.mutateAsync({deviceId:e,action:n,input:r});return i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return G(_n,{schema:h,values:T,pendingKeys:E,onChange:D,onAction:A,onSave:O,onDiscard:k,disabled:C.isPending,activeSubTab:n,onSubTabChange:r})}function jn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return G(`div`,{className:`flex flex-col gap-3`,children:G(An,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}W(),W();function Mn({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return q(`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:[G(Qe,{type:n,size:`lg`}),q(`div`,{children:[G(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),G(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),q(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[G(Ct,{status:r?`online`:`offline`}),i.length>0&&G(Je,{capabilities:i})]}),G(`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.`})]})}W();function Nn({deviceId:e}){let t=K(),n=d({deviceId:e},{refetchInterval:1e4,retry:!1}),r=k({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=H(()=>Pn(n.data??[]),[n.data]);return q(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[q(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[G(Fn,{label:`Discovered`,value:i.total,icon:G(dt,{className:`h-3.5 w-3.5`})}),G(Fn,{label:`Adopted`,value:i.adopted,accent:`success`}),G(Fn,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),q(`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?G(xt,{className:`h-3.5 w-3.5 animate-spin`}):G(tt,{className:`h-3.5 w-3.5`}),G(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),q(`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:[G(In,{icon:G(it,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),G(In,{icon:G(bt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),G(In,{icon:G(ft,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?G(In,{icon:G(jt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function Pn(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 Fn({label:e,value:t,icon:n,accent:r}){return q(`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:[q(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,G(`span`,{className:`truncate`,children:e})]}),G(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function In({icon:e,label:t}){return q(`span`,{className:`inline-flex items-center gap-1`,children:[e,G(`span`,{children:t})]})}function Ln({deviceId:e,features:n}){return G(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:G(t,{trpc:J().trpcClient,deviceId:e,features:n})})}function Rn({deviceId:e,features:t}){return G(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:G(le,{trpc:J().trpcClient,deviceId:e,features:t})})}function $({deviceId:e,deviceType:t,features:n}){let r=J(),i=f(t)?.HeroCard??le,a=Ue(ze(r.trpcClient,e)?.state.deviceStatus),o=a!==void 0&&a.online===!1,s=o?a.lastChangedAt:null;return q(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[o?G(`div`,{className:`flex justify-center`,children:G(h,{lastChangedAt:s})}):null,G(i,{trpc:r.trpcClient,deviceId:e,features:n})]})}W();function zn({deviceId:e}){let t=J(),n=K(),{data:r,isLoading:i}=Tt(e),{data:a,isLoading:o}=wt(e),s=i||o,[c,u]=B(null),d=Pe({onSuccess:()=>{u(null),n.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{u(`Could not change primary child: ${e.message}`)}}),f=(a??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),p=typeof r?.linkDeviceId==`number`?r.linkDeviceId:null,m=typeof r?.primaryChildEntityId==`string`?r.primaryChildEntityId:null;return s?G(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):q(`div`,{className:`flex h-full w-full flex-col`,children:[G(l,{trpc:t.trpcClient,children:f,linkDeviceId:p,primaryChildEntityId:m,onSetPrimary:t=>d.mutate({deviceId:e,primaryChildEntityId:t})}),c!==null&&G(`p`,{role:`alert`,className:`px-3 pb-2 text-[11px] text-danger sm:px-4`,children:c})]})}var Bn={[Y.Switch]:$,[Y.Siren]:$,[Y.Light]:$,[Y.Sensor]:$,[Y.Button]:$,[Y.Hub]:Nn,[Y.Cover]:Ln,[Y.Valve]:$,[Y.Humidifier]:$,[Y.WaterHeater]:$,[Y.Container]:zn,[Y.Lock]:$,[Y.Fan]:$,[Y.Thermostat]:$,[Y.MediaPlayer]:$,[Y.Control]:$,[Y.AlarmPanel]:Rn,[Y.EventEmitter]:Rn,[Y.Notifier]:Rn,[Y.Script]:Rn,[Y.Automation]:Rn,[Y.Presence]:$,[Y.Update]:$,[Y.Vacuum]:$,[Y.LawnMower]:$,[Y.Weather]:$,[Y.Image]:$};function Vn(e){return G(Bn[e.deviceType]??Mn,{...e})}function Hn({deviceId:e}){let t=K(),n=Number.isFinite(e),{data:r}=N({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;At([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:c}=M({deviceId:e},{enabled:n}),{data:l}=te({deviceType:i},{enabled:!!i}),d=ee({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return G(`div`,{className:`p-4`,children:G(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(s)return q(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,c instanceof Error?c.message:String(c)]});let f=new Map,p={};for(let e of l??[])p[e.capName]=e.wrappers;for(let e of a?.entries??[])f.set(e.capName,{...e,wrappers:p[e.capName]??[]});for(let e of l??[])f.has(e.capName)||f.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let m=[...f.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(m.length===0)return q(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[G(Xe,{className:`h-8 w-8 opacity-40`}),G(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),G(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let h=m.filter(e=>e.kind!==`unbound`).length;return q(`div`,{className:`flex flex-col gap-3 p-1`,children:[q(`div`,{className:`text-[11px] text-foreground-subtle`,children:[G(`span`,{className:`font-medium text-foreground`,children:h}),` of `,m.length,` capabilit`,m.length===1?`y`:`ies`,` bound — rows marked `,G(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),G(u,{columns:[{key:`capability`,header:`Capability`,render:e=>G(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>G(Un,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>G(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||G(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?G(Wn,{nodeId:e.providerNodeId}):G(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>G(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||G(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return G(Gn,{wrappers:t.wrappers,activeWrapperId:n,disabled:d.isPending,onPick:r=>{let i=n===r;d.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:m,rowKey:e=>e.capName,minWidthPx:720})]})}function Un({kind:e}){return e===`native`?q(`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:[G(rt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?q(`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:[G(Mt,{className:`h-3 w-3`}),`wrapped`]}):q(`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:[G(It,{className:`h-3 w-3`}),`unbound`]})}function Wn({nodeId:e}){return G(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function Gn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?G(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):G(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return q(`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:[G(i?at:Ze,{className:`h-3 w-3`}),e]},e)})})}W();function Kn(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 qn(e,t,n){let r=e?.stepOverridesByAgent?.[t]?.[n];if(r)return r.enabled===!1?`off`:(r.enabled,`on`);let i=e?.stepToggles?.[n];return i===!1?`off`:i===!0?`on`:`inherit`}function Jn({agents:e,currentAgent:t,onPick:n}){let[r,i]=B(!1);return q(`div`,{className:`relative`,children:[G(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>i(e=>!e),children:`Mirror from ▾`}),r&&G(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:e.filter(e=>e!==t).map(e=>G(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{i(!1),n(e)},children:e},e))})]})}function Yn({deviceId:e,refreshToken:t}){let r=K(),[i,a]=B(null),[s,c]=B(null),[l,u]=B(null),[d,f]=B(null),m=_({deviceId:e}),h=w(),g=Ie({deviceId:e}),v=n(),y=H(()=>g.data?.agentNodeId||v.data?.find(e=>e.online)?.nodeId||`hub`,[g.data?.agentNodeId,v.data]),b=s??y,x=je({nodeId:b??``},{enabled:!!b}),S=O({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),u(null)}}),C=H(()=>x.data?p(x.data):[],[x.data]),T=H(()=>{let e=m.data??null,t={};for(let n of h.data??[])for(let r of Object.keys(n.settings.addonDefaults)){let i=t[r]??[];i.push({agentNodeId:n.nodeId,state:qn(e,n.nodeId,r)}),t[r]=i}return t},[m.data,h.data]),D=i?Kn(x.data??null,i):null,k=b?h.data?.find(e=>e.nodeId===b)??null:null,A=i&&k?k.settings.addonDefaults[i]??null:null,j=i&&b?m.data?.stepOverridesByAgent?.[b]?.[i]??null:null,M=x.data?.selectedEngine.format??`coreml`,ee=e=>{c(e),u(null),f(null)};return h.isLoading||x.isLoading?G(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):x.data?G(`div`,{className:`@container h-full`,style:{containerType:`inline-size`},children:q(`div`,{className:`flex flex-col @[720px]:flex-row h-full`,children:[G(`aside`,{className:`w-full @[720px]:w-[300px] @[720px]:flex-shrink-0 border-b @[720px]:border-b-0 @[720px]:border-r border-border overflow-y-auto max-h-[40vh] @[720px]:max-h-none`,children:G(o,{tree:C,selectedAddonId:i,onSelect:e=>{a(e),u(null),f(null)},agentDots:T})}),G(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!i||!D?G(`div`,{className:`text-sm text-foreground-subtle`,children:`Select a step on the left to configure it for this camera.`}):q(`div`,{className:`space-y-4`,children:[q(`div`,{children:[G(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle`,children:`Selected step`}),G(`div`,{className:`text-base font-semibold`,children:D.name})]}),q(`div`,{className:`flex items-end gap-3 flex-wrap`,children:[q(`div`,{children:[G(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle mb-1`,children:`Agent`}),G(`div`,{className:`flex rounded border border-border overflow-hidden`,children:(h.data??[]).map(e=>G(`button`,{type:`button`,onClick:()=>ee(e.nodeId),className:`px-3 py-1 text-xs ${b===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),G(Jn,{agents:(h.data??[]).map(e=>e.nodeId),currentAgent:b,onPick:e=>{if(!b||!i||!x.data||!h.data)return;let t=h.data.find(t=>t.nodeId===e),n=h.data.find(e=>e.nodeId===b);if(!t||!n)return;let[r]=Ne({source:{nodeId:t.nodeId,engine:{format:M},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:M},defaults:n.settings.addonDefaults},catalog:x.data,addonIds:[i]});if(!r){f(`no mirror result`);return}if(r.outcome===`skip`){f(`skipped: ${r.reason??`no candidate`}`);return}u(r.patch),f(`${r.outcome} from ${e}`)}}),d&&G(`div`,{className:`text-[10px] text-foreground-subtle`,children:d})]}),A&&G(E,{mode:`device`,addon:D,agentDefault:A,agentNodeId:b??``,currentPatch:l??j,engineFormat:M,onChangePatch:u}),q(`div`,{className:`flex items-center justify-between gap-2 pt-4 border-t border-border`,children:[G(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle`,disabled:!j||S.isPending,onClick:()=>{!b||!i||S.mutate({deviceId:e,agentNodeId:b,addonId:i,patch:null})},children:`Clear override`}),q(`div`,{className:`flex items-center gap-2`,children:[G(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>u(null),children:`Reset draft`}),G(`button`,{type:`button`,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,disabled:!b||!i||S.isPending,onClick:()=>{!b||!i||S.mutate({deviceId:e,agentNodeId:b,addonId:i,patch:l})},children:S.isPending?`Saving…`:`Save`})]})]})]})})]})}):G(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`})}W();function Xn(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function Zn(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=Xn(r.value,t));return n}function Qn(e,t){return e?.kind===`enum-map`?Object.entries(e.mapping).map(([e,t])=>({key:e,value:String(t)})):t?.kind===`enum`&&t.enumValues?t.enumValues.map(e=>({key:e,value:``})):[{key:``,value:``}]}function $n(e){return e?.kind===`linear`?{scale:String(e.scale),offset:String(e.offset),clampMin:e.clamp?String(e.clamp[0]):``,clampMax:e.clamp?String(e.clamp[1]):``,useClamp:e.clamp!=null}:{scale:`1`,offset:`0`,clampMin:``,clampMax:``,useClamp:!1}}function er(e){return e==null?`identity`:e.kind}function tr({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=B(()=>er(e)),[o,s]=B(()=>Qn(e,n)),[c,l]=B(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=B(()=>$n(e));V(()=>{if(i===`enum-map`&&n?.kind===`enum`&&n.enumValues){let e=n.enumValues;s(t=>e.map(e=>({key:e,value:t.find(t=>t.key===e)?.value??``})))}},[n,i]),V(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=Zn(o,r),n=c===``?void 0:Xn(c,r);t({kind:`enum-map`,mapping:e,...n===void 0?{}:{fallback:n}});return}if(i===`linear`){let e=Number(u.scale),n=Number(u.offset);if(Number.isNaN(e)||Number.isNaN(n))return;let r=Number(u.clampMin),i=Number(u.clampMax),a=u.useClamp&&!Number.isNaN(r)&&!Number.isNaN(i)?[r,i]:void 0;t({kind:`linear`,scale:e,offset:n,...a?{clamp:a}:{}})}},[i,o,c,u,r,t]);let f=e=>{a(e),e===`enum-map`&&s(Qn(void 0,n)),e===`linear`&&d($n(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return q(`div`,{className:`flex flex-col gap-3`,children:[q(`div`,{children:[G(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),G(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>q(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[G(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&q(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[G(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>q(`div`,{className:`flex items-center gap-1.5`,children:[G(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),G(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?q(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[G(`option`,{value:``,children:`—`}),G(`option`,{value:`true`,children:`true`}),G(`option`,{value:`false`,children:`false`})]}):G(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&G(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&G(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),q(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[G(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),G(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&q(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[G(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),q(`div`,{className:`grid grid-cols-2 gap-2`,children:[q(`label`,{className:`flex flex-col gap-0.5`,children:[G(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),G(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),q(`label`,{className:`flex flex-col gap-0.5`,children:[G(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),G(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),q(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[G(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),G(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&q(`div`,{className:`grid grid-cols-2 gap-2`,children:[q(`label`,{className:`flex flex-col gap-0.5`,children:[G(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),G(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),q(`label`,{className:`flex flex-col gap-0.5`,children:[G(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),G(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}W();function nr(e,t){return`${e.replace(/[^a-z0-9]/gi,`-`)}-${t.replace(/[^a-z0-9]/gi,`-`)}`}function rr(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function ir({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=F({}),s=o??[],c=t==null?n:s.find(e=>e.id===t)?.stableId??n,l=s.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:u}=Ee({deviceId:e}),d=u?.caps??[],f=r==null?null:rr(r.source.sourceKey,c,s),[p,m]=B(r?.target.cap??``),[h,g]=B(r?.target.fieldPath??``),[_,v]=B(f),[y,b]=B(r?.source.cap??``),[x,S]=B(r?.source.fieldPath??``),[C,w]=B(r?.transform);V(()=>{if(r!=null&&_===null&&s.length>0){let e=rr(r.source.sourceKey,c,s);e!==null&&v(e)}},[r,_,s,c]);let{data:T}=Ee({deviceId:_??0},{enabled:_!=null}),E=T?.caps??[],D=d.find(e=>e.cap===p)?.fields??[],O=D.find(e=>e.path===h),k=E.find(e=>e.cap===y)?.fields??[],A=k.find(e=>e.path===x),j=e=>{m(e),g(``)},M=e=>{v(e===``?null:Number(e)),b(``),S(``)},ee=e=>{b(e),S(``)},N=p!==``&&h!==``&&_!=null&&y!==``&&x!==``,P=()=>{if(!N)return;let e=s.find(e=>e.id===_),t=`${c}-`,n=e&&e.stableId.startsWith(t)?e.stableId.slice(t.length):``;i({id:r?.id??nr(p,h),source:{sourceKey:n,cap:y,fieldPath:x},target:{cap:p,fieldPath:h},...C==null?{}:{transform:C}})},I=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return q(`div`,{className:`flex flex-col gap-4 p-3`,children:[q(`fieldset`,{className:`flex flex-col gap-3`,children:[G(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),q(`div`,{children:[G(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),q(`select`,{id:`link-target-cap`,value:p,onChange:e=>j(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a cap —`}),d.map(e=>G(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),q(`div`,{children:[G(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),q(`select`,{id:`link-target-field`,value:h,disabled:p===``,onChange:e=>g(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a field —`}),D.map(e=>q(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),q(`fieldset`,{className:`flex flex-col gap-3`,children:[G(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source (sibling device)`}),q(`div`,{children:[G(`label`,{htmlFor:`link-source-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source device`}),q(`select`,{id:`link-source-device`,value:_??``,onChange:e=>M(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a device —`}),l.map(e=>q(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),q(`div`,{children:[G(`label`,{htmlFor:`link-source-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source cap`}),q(`select`,{id:`link-source-cap`,value:y,disabled:_==null,onChange:e=>ee(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a cap —`}),E.map(e=>G(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),q(`div`,{children:[G(`label`,{htmlFor:`link-source-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source field`}),q(`select`,{id:`link-source-field`,value:x,disabled:y===``,onChange:e=>S(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a field —`}),k.map(e=>q(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),G(tr,{value:C,onChange:w,sourceField:A,targetKind:O?.kind}),q(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[G(`button`,{type:`button`,onClick:a,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),G(`button`,{type:`button`,disabled:!N,onClick:P,className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Save`})]})]})}W();function ar({deviceId:e}){let t=J(),n=K(),{data:r,isLoading:i}=N({deviceId:e},{enabled:Number.isFinite(e),refetchInterval:1e4}),a=re({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),o=r?.deviceLinks??[],s=typeof r?.parentDeviceId==`number`?r.parentDeviceId:null,c=typeof r?.stableId==`string`?r.stableId:``,[l,u]=B(null),d=t=>{a.mutate({deviceId:e,deviceLinks:o.filter(e=>e.id!==t)})};return i?G(`div`,{className:`p-4`,children:G(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):l===null?q(`div`,{className:`flex flex-col gap-3 p-1`,children:[q(`div`,{className:`flex items-center justify-between`,children:[G(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),q(`button`,{type:`button`,onClick:()=>u(`new`),title:`Add a cross-device link`,className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[G(et,{className:`h-3 w-3`}),`Add link`]})]}),o.length===0?q(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[G(Nt,{className:`h-8 w-8 opacity-30`}),G(`p`,{className:`text-xs`,children:`No links yet.`}),G(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):G(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:o.map(n=>G(or,{deviceId:e,link:n,trpcClient:t.trpcClient,onDelete:()=>d(n.id),onEdit:()=>u(n),isPending:a.isPending},n.id))})]}):q(`div`,{className:`flex flex-col gap-3 p-1`,children:[G(`div`,{className:`flex items-center justify-between`,children:G(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:l===`new`?`Add link`:`Edit link`})}),G(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:G(ir,{deviceId:e,parentDeviceId:s,deviceStableId:c,initial:l===`new`?null:l,onSave:t=>{let n=o.some(e=>e.id===t.id)?o.map(e=>e.id===t.id?t:e):[...o,t];a.mutate({deviceId:e,deviceLinks:n}),u(null)},onCancel:()=>{u(null)}})})]})}function or({deviceId:e,link:t,trpcClient:n,onDelete:r,onEdit:i,isPending:a}){let o=ge(n,e,t.target.cap),s=o===void 0?void 0:Ke(o,t.target.fieldPath),c=s==null?`—`:String(s);return q(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[G(Pt,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),q(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[q(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[G(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),G(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),G(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath})]}),q(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[G(`span`,{children:`←`}),G(`span`,{className:`font-mono`,children:t.source.sourceKey}),G(`span`,{className:`opacity-60`,children:`/`}),G(`span`,{className:`font-mono`,children:t.source.cap}),G(`span`,{className:`opacity-60`,children:`.`}),G(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]}),t.transform&&G(sr,{kind:t.transform.kind}),G(`span`,{className:`font-mono text-[11px] tabular-nums min-w-[2.5rem] text-right text-foreground-subtle`,title:`Live resolved value (from this device's runtime-state slice)`,children:c}),G(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:a,onClick:i,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:`Edit`}),G(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:a,onClick:r,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-danger hover:border-danger/50 hover:bg-danger/5 transition-colors disabled:opacity-50`,children:`Delete`})]})}function sr({kind:e}){return G(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}W();var cr=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`pipeline`,label:`Pipeline steps`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0},{id:`wiring`,label:`Wiring`,cameraOnly:!1}];function lr(e){let t=e===Y.Camera;return cr.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var ur=[{id:`logs`,icon:gt,label:`Logs`},{id:`repl`,icon:pt,label:`REPL`},{id:`events`,icon:Ye,label:`Events`},{id:`state`,icon:ct,label:`State`}];function dr(){let e=lt(),t=Number(e.deviceId),n=Number.isFinite(t),r=ot(),i=K(),o=g(),s=J(),[c,l]=ut(),u=c.get(`tab`)??`overview`,d=c.get(`sub`),[f,p]=B(`logs`),m=`device-detail.left-col-width-px`,[h,_]=B(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(m),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),y=U(h);y.current=h;function C(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??h??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{_(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=y.current;if(e!==null)try{window.localStorage.setItem(m,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:w,isLoading:T,isError:E}=N({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:O}=de({deviceId:t},{enabled:n}),k=H(()=>{let e=O?.settings?.sections??[],t=O?.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(Ut)&&r.add(Bt),[...r].map(e=>e===`export`?{id:e,label:Vt,isAddonContrib:!0}:{id:e,label:Ge[e]?.label??e,isAddonContrib:!0})},[O]),A=w,j=String(A?.name??e.deviceId??`Device`),M=A?.online===!0,ee=M?`online`:`offline`,P=String(A?.addonId??`rtsp`),F=A?.features??[],I=A?.type,te=I===Y.Camera,ne=typeof A?.parentDeviceId==`number`?A.parentDeviceId:null,{data:re}=N({deviceId:ne??0},{enabled:ne!==null}),L=v(),ie=A?.disabled!==!0,{data:se}=Ee({deviceId:t},{enabled:n}),le=(se?.caps.length??0)>0,fe=H(()=>{let e=new Set,t=[];for(let n of[...lr(I),...k])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!le)&&t.push(n));return t},[I,k,le]),me=H(()=>fe.some(e=>e.id===u)?u:`overview`,[fe,u]),ge=z(e=>{l(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[l]),be=z(e=>{l(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[l]),{data:xe}=wt(n?t:0),Se=(xe??[]).length>0,Ce=H(()=>ur.filter(({featureGate:e})=>!e||F.includes(e)),[F]),{data:R}=Fe({addonId:P},{enabled:!!P&&P!==`rtsp`}),we=he({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]}),r(R?.id?`/integrations/${R.id}`:`/integrations`)}}),Te=oe({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=ve({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Oe=ae(),ke=pe({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ae=F.includes(qe.Rebootable),je=F.includes(qe.BatteryOperated),Me=a(s.trpcClient,je&&n?t:null),[Ne,Pe]=B(!1),V=ze(s.trpcClient,n?t:null),W=async()=>{if(!(Ne||!V)){Pe(!0);try{await V.snapshot?.invalidateCache({});let e=await V.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=j.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{Pe(!1)}}},Le=Te.isPending||De.isPending,{data:Re}=Ie({deviceId:t},{enabled:n,refetchInterval:1e4}),Be=Re?.agentNodeId??null,Ve=typeof Be==`string`&&Be.length>0&&!Be.startsWith(`addon:`)?Be:void 0,{data:Ue}=_e({deviceId:t,...Ve?{nodeId:Ve}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:We}=x({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),Ke=We?.level?.dbfs??null;function Ye(){if(!n)return null;switch(me){case`overview`:return G(hn,{device:A??{}});case`config`:return G(jn,{deviceId:t,activeSubTab:d,onSubTabChange:be});case`pipeline`:return G(Yn,{deviceId:t,refreshToken:0});case`bindings`:return G(Hn,{deviceId:t});case`wiring`:return G(ar,{deviceId:t});default:{let e=me;return k.some(t=>t.id===e)?e===`export`?G(An,{deviceId:t,sectionFilter:Ut,activeSubTab:d,onSubTabChange:be}):G(An,{deviceId:t,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),activeSubTab:d,onSubTabChange:be}):null}}}return n?T?q(`div`,{className:`flex flex-col h-full`,children:[q(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[G(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),G(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),G(`div`,{className:`flex-1 p-6`,children:G(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):E||!w?q(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[G(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),q(`p`,{className:`text-xs`,children:[`No device with ID`,` `,q(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,t]})]}),G(`button`,{onClick:()=>r(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):q(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[G(`div`,{className:`mb-2`,children:G(D,{items:[{label:`Integrations`,onClick:()=>r(`/integrations`)},{label:R?.name??P,onClick:()=>R?.id&&r(`/integrations/${R.id}`)},{label:j}]})}),q(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[G(Qe,{type:P,size:`lg`}),q(`div`,{className:`min-w-0 flex-1`,children:[q(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[G(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:j}),G(Ct,{status:ee}),je&&G(S,{status:Me,variant:`full`})]}),ne!==null&&re&&q(`button`,{type:`button`,onClick:()=>r(`/devices/${ne}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${re.name}`,children:[G(`span`,{children:`↑`}),G(`span`,{className:`truncate`,children:String(re.name??`Device #${ne}`)})]}),G(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:F.length>0&&G(Je,{capabilities:F})})]}),Ue&&G(`div`,{className:`hidden lg:flex`,children:G(fr,{metrics:Ue,dbfs:Ke})}),q(`div`,{className:`flex items-center gap-1 shrink-0`,children:[q(`button`,{onClick:async()=>{ie?await o({title:`Disable "${j}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&De.mutate({deviceId:t}):Te.mutate({deviceId:t})},disabled:Le,title:ie?`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 ${ie?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[G(Lt,{className:`h-3.5 w-3.5`}),G(`span`,{className:`hidden sm:inline`,children:Le?`Updating…`:ie?`Enabled`:`Disabled`})]}),G(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),G(ue,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:st,disabled:Ne,onClick:()=>{W()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:nt,hidden:!Ae,disabled:Oe.isPending,danger:!0,onClick:async()=>{await o({title:`Reboot "${j}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Oe.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??P}.`,icon:tt,disabled:ke.isPending,danger:!0,onClick:async()=>{await o({title:`Restart "${R?.name??P}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${j}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&ke.mutate({addonId:P})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:vt,separatorBefore:!0,disabled:we.isPending,danger:!0,onClick:async()=>{await o({title:`Delete "${j}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&we.mutate({deviceId:t})}}]})]})]})]}),G(ce,{deviceId:t,device:A??void 0,children:G(b,{children:G(He,{children:G(ye,{children:q(`main`,{className:L?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[q(`div`,{className:L?`flex flex-col bg-surface`:`${h===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!L&&h!==null?{width:`${String(h)}px`}:void 0,children:[G(`div`,{className:`flex-shrink-0 border-b border-border-subtle ${te?`bg-black`:`bg-surface`}`,children:te?G(Qt,{deviceId:t,intercomAvailable:F.includes(qe.TwoWayAudio)}):G(Vn,{deviceId:t,deviceName:j,deviceType:I??`unknown`,provider:P,isOnline:M,features:F})}),q(`div`,{className:L?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[G(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:G(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Ce.map(({id:e,label:t,icon:n})=>q(`button`,{onClick:()=>p(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${f===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[G(n,{className:`h-3 w-3`}),t]},e))})}),q(`div`,{className:L?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[f===`logs`&&G($t,{deviceId:t,containerDeviceId:I===`container`?t:void 0}),f===`repl`&&G(en,{deviceId:t}),f===`events`&&G(tn,{deviceId:t}),f===`state`&&G(nn,{deviceId:t})]})]})]}),!L&&G(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:C,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:G(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),q(`div`,{className:L?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[G(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:G(`div`,{className:`flex flex-wrap items-center gap-0`,children:fe.map(e=>{let t=me===e.id;return q(`button`,{onClick:()=>ge(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&&G(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),q(`div`,{className:L?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[me===`overview`&&Se&&G(rn,{parentDeviceId:t}),Ye()]})]})]})})})})})]}):q(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[G(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),q(`p`,{className:`text-xs`,children:[`The URL segment`,` `,G(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),G(`button`,{onClick:()=>r(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function fr({metrics:e,dbfs:t}){let n=De(e.phase??`idle`);return q(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[q(`div`,{className:`flex items-center gap-1.5`,children:[G(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),G(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),G(`div`,{className:`h-3 w-px bg-border`}),q(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[G(St,{className:`h-3 w-3`}),G(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),G(`span`,{children:`fps`})]}),q(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[G(ht,{className:`h-3 w-3`}),G(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),G(`span`,{children:`ms`})]}),q(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[G(Rt,{className:`h-3 w-3`}),G(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),G(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&q(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{dr as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{Hi as e,P as t,b as n,i as r}from"./src-D-eMZfpa.js";import{G as i,R as a,U as o,X as s,b as c,d as l,u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{d as f}from"./player-overlays-B1rOp2K0.js";import{C as p,D as m,S as h,g,k as _,w as v}from"./schemas-CuE8EXQ7.js";import{S as y}from"./src-DUWILaCU.js";s();var b=_([v({kind:h(`adaptive`)}),v({kind:h(`profile`),profile:y})]),x=v({serverUrl:m().min(1),token:m().min(1),deviceId:p().int().nonnegative(),target:b,muted:g()});function S(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function C(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function w(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function T(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function E(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=x.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function D({message:e}){return a(()=>{S(`error`,e)},[e]),d(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[`Embed config error: `,e]})}function O({system:e,deviceId:t,initialTarget:s,initialMuted:l}){let[u,d]=i(s),[f,p]=i(l),{handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,getSessionState:y}=r(e.trpcClient,t),x=o(()=>w(u),[u]),E=o(()=>(e,t)=>m(x,e,t),[m,x]),D=o(()=>(e,t,n)=>m(n,t,e),[m]);a(()=>(window.__camstackEmbed={setMuted:e=>p(e),setTarget:e=>{let t=b.safeParse(e);t.success&&d(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let O=T(u);return c(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:c(n,{serverUrl:e.serverUrl,streamKey:O,autoPlay:!0,muted:f,showControls:!1,className:`w-full h-full`,handleOffer:E,reoffer:D,getSessionState:y,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,onStateChange:e=>S(C(e)),onError:e=>S(`error`,e)},O)})}function k(){let n=o(()=>E(),[]),r=o(()=>n.ok?{system:t({serverUrl:n.config.serverUrl,token:n.config.token}),queryClient:new l({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}})}:null,[n]);return a(()=>{if(r)return()=>{r.system.close()}},[r]),n.ok?r?c(f,{system:r.system,children:c(u,{client:r.queryClient,children:c(e.Provider,{client:r.system.trpcClient,queryClient:r.queryClient,children:c(O,{system:r.system,deviceId:n.config.deviceId,initialTarget:n.config.target,initialMuted:n.config.muted})})})}):c(D,{message:`Failed to initialise the embed player`}):c(D,{message:n.error})}export{k as EmbedPlayerPage};
@@ -1 +0,0 @@
1
- import{C as e,S as t}from"./src-D-eMZfpa.js";import{G as n,X as r,b as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";r();function o(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function s(e,t){if(e!==void 0)return t&&o(e)?t(e):e}function c({section:r,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,probeResults:f,onAction:p}){let[m,h]=n(r.defaultCollapsed??!1),g=r.style===`accordion`;if(r.fields.reduce((t,n)=>t+ +!!e(n,o,r.fields),0)===0)return null;let _=r.columns??2,v=_===1?`grid-cols-1`:_===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:_===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,y=r.fields.length===1&&r.fields[0]?.type===`widget`?r.fields[0]:void 0;return a(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(y!==void 0||!r.title&&!r.description)&&a(`div`,{className:[`flex items-center justify-between mb-2`,g?`cursor-pointer`:``].join(` `),onClick:g?()=>h(e=>!e):void 0,children:[a(`div`,{children:[r.title&&i(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:s(r.title,u)}),r.description&&i(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s(r.description,u)})]}),g&&i(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:m?`▸`:`▾`})]}),!m&&(y===void 0?i(`div`,{className:`grid ${v} gap-x-3 gap-y-2.5`,children:r.fields.map(e=>i(t,{field:e,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[e.key],allFields:r.fields,onAction:p},e.key))}):i(t,{field:y,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[y.key],allFields:r.fields,onAction:p},y.key))]})}function l({schema:e,values:t,onChange:n,disabled:r,translationFn:a,onTestField:o,probeResults:s,onClearProbe:l,onAction:u}){let d=(e,r)=>{n({...t,[e]:r}),l?.(e)};return i(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>i(c,{section:e,values:t,onChange:d,disabled:r,translationFn:a,onTestField:o,probeResults:s,onAction:u},`${e.id}-${n}`))})}export{l as t};
@@ -1 +0,0 @@
1
- import{$t as e,Bn as t,Hn as n,In as r,J as i,Kt as a,Ln as o,Mi as s,Qt as c,R as l,Rn as u,Wn as d,Yi as f,d as p,dn as m,en as h,g,in as _,ji as v,la as y,lt as b,mn as x,nn as S,sn as ee,tn as C,x as w,xn as T,z as te}from"./src-D-eMZfpa.js";import{F as E,G as D,R as O,U as k,W as A,X as j,b as M,o as N,x as P,y as F}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as I}from"./player-overlays-B1rOp2K0.js";import{b as L}from"./src-DUWILaCU.js";import{t as R}from"./ProviderIcon-BPXhRQ1d.js";import{t as ne}from"./plus-CljwKCLZ.js";import{t as re}from"./refresh-cw-9auw5j71.js";import{t as z}from"./rotate-cw-anx2g3R_.js";import{t as B}from"./wifi-CV73GdWg.js";import{B as V,E as H,F as ie,H as ae,M as oe,P as U,R as se,T as W,U as ce,f as G,i as K,o as q,p as le,s as ue,t as de,x as J}from"./index-CBUhNGng.js";import{t as Y}from"./FormBuilder-D1P2uZCo.js";import{t as X}from"./BrokerStep-Cok3AhHx.js";var fe=V(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);j();function Z(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Z(n.fields));return t}function pe(e,t,n){let[r,i]=D(`idle`),[a,o]=D({}),s=k(()=>{let t=[];for(let n of e.sections)t.push(...Z(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=E(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:E(async()=>{if(!n)return;let e=s.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;i(`testing`);let r={};for(let t of e)r[t]={status:`probing`};o(r);let a=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await n(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),c={};for(let e of a)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;c[t]={status:n.status===`ok`?`ok`:`error`,result:n}}o(c),i(`idle`)},[n,s,t]),clearProbeResult:l}}j();function me(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...me(n.fields));return t}function he(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function ge(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){ge(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Q(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function _e({open:e,integrationId:t,addonId:n,onClose:r}){let{t:i}=de(),a=N(),[o,s]=D({}),[c,l]=D(!1),[u,d]=D(null),[f,p]=D(Q),m=ee({addonId:n,type:L.Camera},{enabled:e}),h=m.data??null;O(()=>{e&&(s(h?ge(h.sections.flatMap(e=>e.fields)):{}),p(Q()),l(!1),d(null))},[e,t,h]);let _=k(()=>({...o,_probeRequestId:f}),[o,f]),v=C({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),y=T(),b=E(async(e,t)=>{l(!0);let r=await y.mutateAsync({addonId:n,type:L.Camera,key:e,value:t,formValues:_});return r.status===`ok`&&r.suggestedValues&&s(e=>{let t=!1,n={...e};for(let[i,a]of Object.entries(r.suggestedValues??{}))he(e[i])&&!he(a)&&(n[i]=a,t=!0);return t?n:e}),r},[y,n,_]),{testAllStatus:x,hasProbeFields:S,probeResults:w,handleTestAll:te,clearProbeResult:A}=pe(h??{sections:[]},o,b);async function j(e){d(null);try{await v.mutateAsync({addonId:n,type:L.Camera,config:o,integrationId:t}),e?s(h?ge(h.sections.flatMap(e=>e.fields)):{}):r()}catch(e){d(e instanceof Error?e.message:String(e))}}if(!e)return null;let F=me((h?.sections??[]).flatMap(e=>e.fields)).filter(e=>he(o[e])),I=F.length===0,R=!m.isLoading&&(m.isError||h===null);return P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[M(`div`,{className:`absolute inset-0 bg-black/60`,onClick:r}),P(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl`,children:[P(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`integrations.addDevice`)}),M(`button`,{onClick:r,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:M(K,{className:`h-4 w-4`})})]}),M(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:m.isLoading?M(`div`,{className:`flex items-center justify-center py-8`,children:M(J,{className:`h-5 w-5 animate-spin text-primary`})}):R?P(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[M(q,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),P(`div`,{className:`space-y-1`,children:[M(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),P(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,M(`span`,{className:`font-mono`,children:n}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):M(Y,{schema:h,values:o,onChange:s,onTestField:b,probeResults:w,onClearProbe:A})}),!R&&!m.isLoading&&P(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[P(`button`,{type:`button`,onClick:()=>l(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[P(`span`,{className:`flex items-center gap-2`,children:[M(le,{className:`h-3.5 w-3.5`}),`Test logs`,M(`span`,{className:`font-mono text-[9px] opacity-60`,children:f.slice(0,14)})]}),M(U,{className:`h-3.5 w-3.5 transition-transform ${c?`rotate-180`:``}`})]}),c&&M(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:M(g,{addonId:n,requestId:f,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!R&&!m.isLoading&&(u||F.length>0)&&M(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:P(`div`,{className:`flex items-start gap-2`,children:[M(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),M(`p`,{className:`text-[11px] text-destructive`,children:u||`Required: ${F.join(`, `)}`})]})}),P(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[P(`div`,{className:`flex items-center gap-2`,children:[M(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.cancel`)}),!R&&S&&P(`button`,{type:`button`,onClick:te,disabled:x===`testing`,className:`inline-flex items-center gap-1.5 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 disabled:opacity-50`,children:[x===`testing`?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(B,{className:`h-3.5 w-3.5`}),`Test All`]})]}),P(`div`,{className:`flex items-center gap-2`,children:[M(`button`,{onClick:()=>j(!0),disabled:R||!I||v.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:i(`integrations.saveAndNew`)}),M(`button`,{onClick:()=>j(!1),disabled:R||!I||v.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:v.isPending?i(`integrations.saving`):i(`integrations.save`)})]})]})]})]})}function ve(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}j();var $=`devices`,ye={id:$,label:`Devices`,isDefault:!0},be=2e4,xe=100;function Se({addonId:t,integrationId:n,onClose:r}){let{t:i}=de(),[o,d]=D(new Set),[f,p]=D(new Set),[m,g]=D(new Map),[_,y]=D(null),{data:b}=u(),x=(b??[]).find(e=>e.addonId===t)?.supportsLocationImport??!1,[S,ee]=D(!0),C=a({integrationId:n}).data?.filters,w=C&&C.length>0?C:[ye],[T,te]=D(w.find(e=>e.isDefault)?.id??(w.some(e=>e.id===$)?$:w[0].id)),k=T!==$,j=h(),N=e({addonId:t,integrationId:n,page:1,pageSize:be,filter:T}),F=N.refetch,I=j.mutate,L=E(()=>{I({addonId:t,integrationId:n},{onSettled:()=>{F()}})},[I,t,n,F]),R=A(null);O(()=>{let e=`${t}::${n}`;R.current===e||N.isLoading||(R.current=e,(N.data?.candidates.length??0)===0&&L())},[t,n,N.isLoading,N.data,L]);let ne=j.isPending,re=j.isError?j.error instanceof Error?j.error.message:String(j.error):null,B=N.data?.candidates??[],V=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,H=c(),ae=E(e=>{e.alreadyAdopted||d(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),oe=E(e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),U=E((e,t)=>{g(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),se=E(e=>{let t={};for(let n of e){let e=m.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[m]),W=E(async()=>{y(null);let e=[...o];if(e.length!==0)try{let i=se(e);await H.mutateAsync({addonId:t,integrationId:n,filter:T,childNativeIds:e,...i?{perCandidate:i}:{},...x?{importLocations:S}:{}}),d(new Set),g(new Map),await F(),r()}catch(e){y(e instanceof Error?e.message:String(e))}},[o,se,H,t,n,T,F,x,S]),ce=E(e=>{te(e),d(new Set),p(new Set),g(new Map),y(null)},[]),G=o.size;return P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[M(`div`,{className:`absolute inset-0 bg-black/60`,onClick:r}),P(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[P(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[P(`div`,{className:`min-w-0`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),M(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:i(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),P(`div`,{className:`flex items-center gap-3 shrink-0`,children:[x&&P(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[M(`input`,{type:`checkbox`,checked:S,onChange:e=>ee(e.target.checked),className:`accent-primary`}),i(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),M(`button`,{onClick:r,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:M(K,{className:`h-4 w-4`})})]})]}),P(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(re??V)&&B.length===0&&M(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:P(`div`,{className:`flex items-start gap-2`,children:[M(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`div`,{className:`min-w-0`,children:[M(`p`,{className:`text-xs font-medium text-destructive`,children:i(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),M(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:re??V})]})]})}),w.length>1&&M(Ce,{filters:w,activeFilter:T,onSelect:ce}),M(`div`,{className:`flex-1 min-h-0`,children:M(l,{mode:`generic`,items:B,pageSize:xe,getKey:e=>e.childNativeId,getSearchText:ve,getFilterType:e=>e.type,filterOptions:v(),filterLabel:i(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:N.isLoading||ne&&B.length===0,searchPlaceholder:i(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(re??V)&&B.length===0?``:i(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:P(`button`,{type:`button`,onClick:L,disabled:ne,title:i(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[M(z,{className:`h-3.5 w-3.5 ${ne?`animate-spin`:``}`}),i(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:i(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>M(we,{candidate:e,expandable:!k,expanded:f.has(e.childNativeId),onToggleExpand:()=>oe(e.childNativeId),adoptedLabel:i(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:i(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=s(e.type),n=t.icon;return P(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[M(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>M(`div`,{className:`flex items-center justify-end`,children:M(`button`,{onClick:()=>ae(e),disabled:e.alreadyAdopted,"aria-label":o.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${o.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:o.has(e.childNativeId)&&M(ie,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!k&&f.has(e.childNativeId),renderExpanded:k?void 0:e=>M(Te,{candidate:e,hiddenChildIds:m.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>U(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:o.has(e.childNativeId)?`bg-primary/5`:``})})]}),_&&M(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:P(`div`,{className:`flex items-start gap-2`,children:[M(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),M(`p`,{className:`text-[11px] text-destructive`,children:_})]})}),P(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[M(`div`,{}),P(`div`,{className:`flex items-center gap-2`,children:[M(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.cancel`,{defaultValue:`Cancel`})}),P(`button`,{onClick:W,disabled:G===0||H.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[H.isPending&&M(J,{className:`h-3.5 w-3.5 animate-spin`}),i(`integrations.addSelected`,{defaultValue:`Add selected`}),G>0?` (${G})`:``]})]})]})]})]})}function Ce({filters:e,activeFilter:t,onSelect:n}){return M(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return M(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function we({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let a=(e.children??[]).length;return P(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?P(`button`,{type:`button`,onClick:r,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[M(n?U:oe,{className:`h-3.5 w-3.5`}),a]}):M(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),M(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&M(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function Te({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let r=e.children??[];return r.length===0?null:M(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return P(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[M(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&M(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),M(`button`,{onClick:()=>n(e.childNativeId),"aria-label":r?`Show child`:`Hide child`,title:r?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:M(r?H:W,{className:`h-3 w-3`})})]},e.childNativeId)})})}j();function Ee({integrationId:e,addonId:r,name:i,kind:a,brokerKind:o,trpc:s,onClose:c}){let{t:l}=de(),u=N(),d=a===`device-adoption`,{data:f}=t({id:e},{enabled:d}),p=k(()=>{let e=f?.brokerId;return typeof e==`string`?e:null},[f]),m=n();return M(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:c,children:P(`div`,{className:`max-h-[85vh] w-full max-w-md overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[P(`div`,{className:`mb-3 flex items-center justify-between`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:[l(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,i]}),M(`button`,{onClick:c,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":l(`common.close`,{defaultValue:`Close`}),children:M(K,{className:`h-4 w-4`})})]}),d?o?P(`div`,{className:`space-y-3`,children:[M(`p`,{className:`text-[11px] text-foreground-subtle`,children:l(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),p&&P(`p`,{className:`text-[11px] text-foreground`,children:[l(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,M(`span`,{className:`font-mono text-foreground-subtle`,children:p})]}),m.isPending?P(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[M(J,{className:`h-3 w-3 animate-spin`}),l(`integrations.saving`,{defaultValue:`Saving…`})]}):M(X,{kind:o,onResolved:t=>{m.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{u.invalidateQueries(),c()}})},onBack:c}),m.isError&&M(`p`,{className:`text-[11px] text-danger`,children:l(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):M(`p`,{className:`text-[11px] text-danger`,children:l(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):M(w,{trpc:s,addonId:r,nodeId:`hub`,title:i})]})})}j();function De(){let{t:e}=de(),{integrationId:t}=ce(),n=N(),a=ae(),s=I(),[c,h]=D(!1),[v,ee]=D(!1),[C,w]=D(!1),[T,O]=D(!1),{data:A,isLoading:j}=o({id:t??``},{enabled:!!t}),{data:L}=i({addonId:A?.addonId??``,nodeId:`hub`},{enabled:!!A?.addonId}),{data:z,isSuccess:B}=u(),V=k(()=>{let e=A?.addonId;return!e||!B?null:(z??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[z,A?.addonId,B]),H=V!==null,ie=H?V===`device-adoption`?e(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):e(`integrations.addDevice`):e(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),oe=k(()=>{let e=A?.addonId;return!e||!B?null:(z??[]).find(t=>t.addonId===e)?.brokerKind??null},[z,A?.addonId,B]),U=L!=null&&Array.isArray(L.sections)&&L.sections.some(e=>e.fields.length>0),{data:W}=m({},{refetchInterval:5e3}),Y=[[`integrations`,`get`],{input:{id:t??``},type:`query`}],X=d({onMutate:async e=>{await n.cancelQueries({queryKey:Y});let t=n.getQueryData(Y);return t!=null&&n.setQueryData(Y,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,r)=>{let i=r;i?.previous!=null&&n.setQueryData(Y,i.previous)},onSettled:()=>{n.invalidateQueries({queryKey:[[`integrations`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=r({onSuccess:()=>{n.invalidateQueries({queryKey:[[`integrations`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),w(!1),a(`/integrations`)}}),pe=b({onSuccess:()=>{n.invalidateQueries({queryKey:[[`integrations`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),me=x({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),he=S({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ge=_({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=k(()=>W??[],[W]),ve=k(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),$=E(e=>ve.get(e)??null,[ve]),ye=E(e=>M(R,{type:e,size:`sm`}),[]),be=E(e=>a(`/devices/${String(e)}`),[a]),xe=k(()=>{let e=A?.addonId;return e?Q.filter(t=>t.addonId===e):[]},[Q,A?.addonId]),Ce=k(()=>te(xe).length,[xe]);return j?P(`div`,{className:`p-4`,children:[M(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),M(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):A?P(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[M(f,{items:[{label:`Integrations`,onClick:()=>a(`/integrations`)},{label:A.name}]}),P(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[P(`div`,{className:`flex items-center gap-3 min-w-0`,children:[M(`img`,{src:`/api/addon-assets/${A.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),P(`div`,{className:`min-w-0`,children:[M(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:A.name}),P(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[A.addonId,` · `,Ce,` `,e(`integrations.devices`)]})]})]}),P(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[P(`button`,{onClick:()=>h(!0),disabled:!H,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:ie,children:[M(ne,{className:`h-3.5 w-3.5`}),ie]}),P(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${X.isPending?`opacity-60`:``} ${A.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[M(y,{checked:A.enabled,onCheckedChange:e=>X.mutate({id:t,enabled:e}),disabled:X.isPending,"aria-label":A.enabled?`Disable integration`:`Enable integration`}),M(`span`,{className:`text-[11px] font-medium ${A.enabled?`text-success`:`text-foreground-subtle`}`,children:A.enabled?`Enabled`:`Disabled`}),X.isPending&&M(J,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),(U||V===`device-adoption`)&&P(`button`,{onClick:()=>ee(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[M(G,{className:`h-3 w-3`}),e(`integrations.config`)]}),P(`button`,{onClick:()=>O(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrations.logs`,{defaultValue:`View logs`}),children:[M(le,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),M(p,{label:`Restart`,icon:re,title:`Restart "${A.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ce} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:pe.isPending,action:()=>pe.mutateAsync({addonId:A.addonId})}),P(`button`,{onClick:()=>w(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:e(`integrations.delete`,{defaultValue:`Delete integration`}),children:[M(ue,{className:`h-3 w-3`}),e(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),M(l,{context:`integration-detail`,devices:Q,trpc:s.trpcClient,defaultView:`cards`,forceAddon:A.addonId,urlScope:`root`,lsKey:`integration-detail:${A.addonId}`,resolveIntegrationIcon:ye,resolveParent:$,onNavigate:be,batchActions:{remove:me.mutate,disable:he.mutate,enable:ge.mutate},onDeleteDevice:e=>me.mutate({deviceId:e.id})}),c&&t&&V===`device-adoption`&&M(Se,{addonId:A.addonId,integrationId:t,onClose:()=>h(!1)}),c&&t&&V===`device-provider`&&M(_e,{open:c,integrationId:t,addonId:A.addonId,onClose:()=>h(!1)}),v&&t&&V!==null&&M(Ee,{integrationId:t,addonId:A.addonId,name:A.name,kind:V,brokerKind:oe,trpc:s.trpcClient,onClose:()=>ee(!1)}),T&&M(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>O(!1),children:P(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[P(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[P(`div`,{className:`flex items-center gap-2 min-w-0`,children:[M(le,{className:`h-4 w-4 text-primary shrink-0`}),M(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:A.name}),P(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[A.addonId,t?` · ${t}`:``]})]}),M(`button`,{onClick:()=>O(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:M(K,{className:`h-4 w-4`})})]}),M(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:M(g,{addonId:A.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),C&&M(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Z.isPending&&w(!1),children:P(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[P(`div`,{className:`flex items-start gap-3`,children:[M(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:M(q,{className:`h-4 w-4 text-danger`})}),P(`div`,{className:`min-w-0`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),M(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:A.name,count:Ce})})]})]}),Z.error&&M(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Z.error instanceof Error?Z.error.message:String(Z.error)}),P(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[M(`button`,{onClick:()=>w(!1),disabled:Z.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:e(`integrations.cancel`,{defaultValue:`Cancel`})}),M(`button`,{onClick:()=>Z.mutate({id:t}),disabled:Z.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Z.isPending?P(F,{children:[M(J,{className:`h-3 w-3 animate-spin`}),e(`integrations.deleting`,{defaultValue:`Deleting…`})]}):P(F,{children:[M(ue,{className:`h-3 w-3`}),e(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):P(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[M(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:M(fe,{className:`h-6 w-6 text-foreground-subtle`})}),P(`div`,{className:`space-y-1 max-w-sm`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),M(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t??``})})]}),P(`button`,{onClick:()=>a(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[M(se,{className:`h-3 w-3`}),e(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{De as IntegrationDetailPage};
@@ -1 +0,0 @@
1
- import{Fn as e,J as t,R as n,Rn as r,Un as i,Vn as a,Zt as o,ba as s,dn as c,rn as l,z as u}from"./src-D-eMZfpa.js";import{F as d,G as f,R as p,U as m,X as h,b as g,o as _,x as v,y}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as b}from"./player-overlays-B1rOp2K0.js";import{t as x}from"./ProviderIcon-BPXhRQ1d.js";import{t as S}from"./plus-CljwKCLZ.js";import{t as C}from"./refresh-cw-9auw5j71.js";import{F as w,H as T,I as E,M as D,P as O,W as k,f as A,g as j,i as M,t as N,x as P}from"./index-CBUhNGng.js";import{t as F}from"./AdminPage-CN6ZMhf0.js";import{t as I}from"./StatusBadge-CkYubfRG.js";import{t as L}from"./FormBuilder-D1P2uZCo.js";import{t as R}from"./useEventInvalidation-BXdyfSQv.js";import{t as z}from"./BrokerStep-Cok3AhHx.js";h();function B({onSelect:e,onClose:t,pendingAddonId:n=null}){let{t:i}=N(),a=T(),{data:o,isLoading:s}=r();if(s)return g(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>g(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let c=n!==null;return v(`div`,{className:`space-y-2`,children:[(o??[]).map(r=>{let o=r.instanceMode===`unique`&&r.existingInstances.length>0,s=n===r.addonId,l=c;return v(`button`,{disabled:l,onClick:()=>{if(!l)if(o){let e=r.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(r.addonId,r.instanceMode,r.discoveryMode,r.name,r.kind,r.brokerKind)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[r.iconUrl?g(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${r.color}15`},children:g(`img`,{src:r.iconUrl,alt:``,className:`h-5 w-5`})}):g(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${r.color}15`},children:g(`span`,{className:`text-sm`,style:{color:r.color},children:`◉`})}),v(`div`,{className:`flex-1 min-w-0`,children:[g(`p`,{className:`text-xs font-semibold text-foreground`,children:r.name}),r.description&&g(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:r.description})]}),s?g(P,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):o?v(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[g(A,{className:`h-3 w-3`}),i(`integrations.manage`)]}):g(D,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},r.addonId)}),(o??[]).length===0&&g(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}function V({addonId:e,configSchema:t,onSave:n,onBack:r}){let{t:a}=N(),[o,s]=f(``),[c,l]=f({}),[u,d]=f(null),p=i({onSuccess:e=>d(e),onError:e=>d({success:!1,error:String(e)})});return v(`div`,{className:`space-y-4`,children:[v(`div`,{children:[g(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:a(`integrations.integrationName`)}),g(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&g(L,{schema:t,values:c,onChange:l}),u&&g(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${u.success?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:u.success?a(`integrations.connectionSuccess`):`${a(`integrations.errorPrefix`)} ${u.error}`}),v(`div`,{className:`flex items-center justify-between pt-2`,children:[g(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.back`)}),v(`div`,{className:`flex items-center gap-2`,children:[g(`button`,{onClick:()=>p.mutate({addonId:e,settings:c}),disabled:p.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:p.isPending?a(`integrations.testing`):a(`integrations.testConnection`)}),g(`button`,{onClick:()=>n({name:o,config:c}),disabled:!o.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:a(`integrations.forward`)})]})]})]})}h();function H({providerId:e,onImport:t,onSkip:n}){let{t:r}=N(),[i,a]=f(new Set),o=l(),s=o.data,c=o.isPending||!o.data&&!o.isError;p(()=>{e&&(o.isPending||o.data||o.mutate({addonId:e}))},[e,o]);function u(e){a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(c)return v(`div`,{className:`flex flex-col items-center py-12`,children:[g(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),g(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:r(`integrations.searchingDevices`)})]});let d=s??[];return v(`div`,{className:`space-y-4`,children:[g(`p`,{className:`text-xs text-foreground-subtle`,children:d.length>0?r(`integrations.foundDevices`,{count:d.length}):r(`integrations.noDevicesFound`)}),d.length>0&&g(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:d.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=i.has(t);return v(`button`,{onClick:()=>u(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[g(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r?`border-primary bg-primary`:`border-border`}`,children:r&&g(w,{className:`h-3 w-3 text-primary-foreground`})}),g(E,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),g(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n})]},t)})}),v(`div`,{className:`flex items-center justify-between pt-2`,children:[g(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.skip`)}),d.length>0&&v(`button`,{onClick:()=>t(Array.from(i)),disabled:i.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[r(`integrations.importSelected`),` (`,i.size,`)`]})]})]})}h();function U(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}function W({open:n,onClose:r}){let{t:i}=N(),a=T(),s=_(),[c,u]=f(`picker`),[d,h]=f(null),[b,x]=f(null),[S,C]=f(`manual`),[w,E]=f(null),[D,O]=f(``),[k,A]=f(null),[j,F]=f(null),{data:I}=t({addonId:d??``,nodeId:`hub`},{enabled:d!=null}),L=m(()=>I?U(I):null,[I]),R=e({onSuccess:()=>s.invalidateQueries({queryKey:[[`integrations`]]})}),W=l(),G=W.data;p(()=>{c!==`discovery`||!b||!d||W.isPending||W.data||W.mutate({addonId:d})},[c,b,d,W]);let ee=o({onSuccess:()=>s.invalidateQueries({queryKey:[[`deviceManager`]]})});async function te(e,t,n,i,o,s){if(!R.isPending){if(h(e),C(n),O(i),F(null),o===`device-adoption`){if(!s){F(`Addon '${e}' declares device-adoption but no brokerKind in its manifest`);return}E(s),u(`broker`);return}if(t===`unique`){try{let t=await R.mutateAsync({addonId:e,name:i,settings:{}});r(),Y(),a(`/integrations/${t.id}`)}catch{}return}u(`config`)}}async function K(e){if(d)try{let t=await R.mutateAsync({addonId:d,name:e.name,settings:e.config});x(t.id),S===`auto`||S===`both`?u(`discovery`):J(t.id)}catch{}}async function q(e){if(d)try{let t=await R.mutateAsync({addonId:d,name:D,settings:{brokerId:e}});A(t.id),x(t.id),J(t.id)}catch{}}async function ne(e){if(d){for(let t of e){let e=G?.find(e=>e.stableId===t);e&&await ee.mutateAsync({addonId:d,candidate:e,...k===null?{}:{integrationId:k}})}J()}}function J(e){let t=e??b??d;r(),Y(),t&&a(`/integrations/${t}`)}function Y(){u(`picker`),h(null),x(null),C(`manual`),E(null),O(``),A(null),F(null)}function X(){r(),Y()}if(!n)return null;let re={picker:i(`integrations.newIntegration`),config:i(`integrations.configureIntegration`),discovery:i(`integrations.importDevices`),broker:i(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Z=R.isPending,Q=Z?d:null,$=R.error;return v(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[g(`div`,{className:`absolute inset-0 bg-black/60`,onClick:Z?void 0:X}),v(`div`,{className:`relative z-10 w-full max-w-lg max-h-[85vh] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[v(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[g(`h2`,{className:`text-sm font-semibold text-foreground`,children:re[c]}),g(`button`,{onClick:X,disabled:Z,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:g(M,{className:`h-4 w-4`})})]}),v(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto`,children:[$&&!Z&&g(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),c===`picker`&&v(y,{children:[j&&g(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:j}),g(B,{onSelect:te,onClose:X,pendingAddonId:Q})]}),c===`config`&&d&&g(V,{addonId:d,configSchema:L??null,onSave:K,onBack:()=>u(`picker`)}),c===`broker`&&w&&g(z,{kind:w,onResolved:e=>{q(e)},onBack:()=>u(`picker`)}),c===`discovery`&&b&&g(H,{providerId:b,onImport:ne,onSkip:J})]}),Z&&v(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm`,children:[g(P,{className:`h-6 w-6 animate-spin text-primary`}),g(`p`,{className:`text-xs font-medium text-foreground`,children:i(`integrations.creating`,{defaultValue:`Creating integration…`})}),g(`p`,{className:`text-[10px] text-foreground-subtle`,children:i(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})})]})]})]})}function G({integration:e,expanded:t,onToggleExpand:n}){return v(`div`,{className:`flex items-center gap-2.5`,children:[g(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:g(t?O:D,{className:`h-3.5 w-3.5`})}),g(x,{type:e.addonId,size:`sm`}),v(`div`,{className:`flex min-w-0 flex-col`,children:[g(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),g(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ee(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>g(G,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>g(I,{status:e.status})}]}h();function te(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var K=`expand`;function q(){let{t:e}=N(),t=T(),r=b(),[i]=k(),[o,l]=f(!1),p=d(()=>l(!0),[]),h=d(()=>l(!1),[]);R([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),R([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:_,isLoading:w,refetch:E}=a(void 0),{data:D,isLoading:O,refetch:A}=c({}),M=m(()=>D??[],[D]),P=m(()=>_??[],[_]),I=m(()=>{let e=new Map;for(let t of M)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[M]),L=m(()=>{let e=new Map;for(let t of u(M)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[M]),z=m(()=>P.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:te(e),deviceCount:L.get(e.addonId)??0})),[P,L]),B=i.get(K),V=d(e=>{let t=new URLSearchParams(window.location.search);t.get(K)===e?t.delete(K):t.set(K,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),H=d(e=>t(`/integrations/${e.id}`),[t]),U=d(e=>I.get(e)??null,[I]),G=d(e=>g(x,{type:e,size:`sm`}),[]),q=d(e=>t(`/devices/${String(e)}`),[t]),ne=d(e=>g(n,{context:`integration-detail`,devices:M,trpc:r.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:G,resolveParent:U,onNavigate:q}),[M,r.trpcClient,G,U,q]),J=d(e=>B===e.addonId,[B]),Y=m(()=>ee({isExpanded:J,onToggleExpand:V}),[J,V]),X=d(e=>`${e.name} ${e.addonId}`,[]),re=d(e=>e.addonId,[]),Z=d(()=>{E(),A()},[E,A]),Q=w||O,$=P.length>0;return v(F,{icon:j,title:e(`nav.integrations`,`Integrations`),actions:v(y,{children:[g(`button`,{onClick:Z,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:g(C,{className:s(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),v(`button`,{onClick:p,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[g(S,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&g(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>g(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&v(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[g(`p`,{className:`text-sm`,children:`No integrations configured.`}),g(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&g(n,{mode:`generic`,items:z,getKey:re,getSearchText:X,columns:Y,onRowClick:H,isExpanded:J,renderExpanded:ne,searchPlaceholder:e(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:e(`integrations.empty`,{defaultValue:`No integrations found.`})}),g(W,{open:o,onClose:h})]})}export{q as IntegrationsPage};
@@ -1 +0,0 @@
1
- import{F as e,G as t,R as n,U as r,W as i,X as a,b as o,x as s,y as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{L as l,V as u,c as ee,g as d,n as f,p,s as m}from"./player-overlays-B1rOp2K0.js";import{MaskShapeCanvas as h}from"./MaskShapeCanvas-C5K6H6Th.js";var te=d(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]);a();var ne=110,g=`motion-zones`,_=0,re=[1,2,3],v=1,y=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,b=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function x(e,t,n){let r=t*n,i=Array(r);for(let t=0;t<r;t+=1)i[t]=e[t]===!0;return i}function S(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function C(e,t){return Math.ceil(e/t)}function w(e,t,n){return Math.min(n-1,Math.floor((e+.5)/t*n))}function T(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array(i*a).fill(!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)e[r*t+n]===!0&&(o[s*i+w(n,t,i)]=!0)}return o}function E(e,t,n,r){let i=C(t,r),a=C(n,r),o=Array(t*n).fill(!1);for(let r=0;r<n;r+=1){let s=w(r,n,a);for(let n=0;n<t;n+=1)o[r*t+n]=e[s*i+w(n,t,i)]===!0}return o}function D({deviceId:a}){let d=ee(p().trpcClient,a),[w,D]=t(null),[O,k]=t(!1),[A,j]=t(null),[M,N]=t(null),[P,F]=t(v),[I,L]=t(!1),[R,z]=t(!1),B=i(!1);n(()=>{if(!d)return;let e=!1;return B.current=!1,D(null),k(!1),j(null),N(null),F(v),z(!1),(async()=>{try{let t=await d.motionZones?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(D(t),B.current)return;let n=await d.motionZones?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);B.current=!0;let r=n.regions.find(e=>e.shape.kind===`grid`),i=x(r?r.shape.cells:[],t.grid.width,t.grid.height);N(i),j(T(i,t.grid.width,t.grid.height,v))}catch(t){if(e)return;u(t)?k(!0):console.error(`Motion Zones load failed`,t)}})(),()=>{e=!0}},[d]);let V=w?w.grid.width:0,H=w?w.grid.height:0,U=C(V,P),W=C(H,P),G=r(()=>A&&w?E(A,V,H,P):null,[A,w,V,H,P]),K=r(()=>G!==null&&M!==null&&!S(G,M),[G,M]),q=r(()=>G?G.reduce((e,t)=>t?e+1:e,0):0,[G]),J=V*H,Y=U*W,X=e(e=>{Y>0&&j(Array(Y).fill(e))},[Y]),Z=e(()=>{j(e=>e&&e.map(e=>!e))},[]),ie=e(()=>{M&&w&&j(T(M,V,H,P))},[M,w,V,H,P]),ae=e(e=>{e===P||!w||j(t=>{if(!t)return F(e),t;let n=T(E(t,V,H,P),V,H,e);return F(e),n})},[P,w,V,H]),Q=r(()=>w&&A?[{id:_,shape:{kind:`grid`,gridWidth:U,gridHeight:W,cells:[...A]}}]:[],[w,A,U,W]),$=e((e,t)=>{t.kind===`grid`&&j(t.cells)},[]),oe=e(async()=>{if(!(!d||!A||!w)){L(!0);try{let e=E(A,w.grid.width,w.grid.height,P),t={kind:`grid`,gridWidth:w.grid.width,gridHeight:w.grid.height,cells:e};await d.motionZones?.setZone({patch:{regions:[{id:_,enabled:!0,shape:t}]}});let n=await d.motionZones?.getStatus({});if(n){let e=n.regions.find(e=>e.shape.kind===`grid`),t=x(e?e.shape.cells:[],w.grid.width,w.grid.height);N(t),j(T(t,w.grid.width,w.grid.height,P))}}catch(e){console.error(`Motion Zones save failed`,e)}finally{L(!1)}}},[d,A,w,P]);return f(r(()=>R&&!O&&w&&A?{id:g,order:ne,node:o(h,{transparent:!0,items:Q,supportedShapes:[`grid`],grid:{width:U,height:W},selectedId:_,onSelect:()=>{},onShapeChange:$,onDrawComplete:()=>{},drawingKind:null})}:null,[R,O,w,A,Q,$,U,W])),d?o(m,{title:`Motion Zones`,icon:o(te,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:o(`div`,{className:`flex flex-col gap-3`,children:O?o(`p`,{className:`${l} leading-relaxed`,children:`This camera doesn't expose an on-board motion zones grid.`}):!O&&w!==null&&A!==null?s(c,{children:[s(`p`,{className:`${l} leading-relaxed`,children:[`Toggle `,o(`strong`,{className:`text-foreground`,children:`Edit grid`}),` to paint the region directly on the live frame, then `,o(`strong`,{className:`text-foreground`,children:`Save`}),` to push the mask to the camera. Pick a bigger`,` `,o(`strong`,{className:`text-foreground`,children:`Cell size`}),` for quicker, broad-stroke painting — it's resampled to the camera's native `,w.grid.width,`×`,w.grid.height,` grid on save (×1 is the finest).`]}),s(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[o(`button`,{type:`button`,onClick:()=>z(e=>!e),disabled:I,"aria-pressed":R,className:R?b:y,children:R?`Done editing`:`Edit grid`}),o(`button`,{type:`button`,onClick:()=>X(!0),disabled:I,className:y,children:`All on`}),o(`button`,{type:`button`,onClick:()=>X(!1),disabled:I,className:y,children:`All off`}),o(`button`,{type:`button`,onClick:Z,disabled:I,className:y,children:`Invert`}),s(`div`,{className:`flex items-center gap-1 ml-1`,role:`group`,"aria-label":`Cell size`,children:[o(`span`,{className:`${l} mr-0.5`,children:`Cell size`}),re.map(e=>s(`button`,{type:`button`,onClick:()=>ae(e),disabled:I,"aria-pressed":P===e,title:e===1?`Camera grid ${V}×${H} (finest)`:`${C(V,e)}×${C(H,e)} painting grid · cells ×${e} bigger`,className:P===e?b:y,children:[`×`,e]},e))]}),s(`span`,{className:`${l} ml-1 tabular-nums`,children:[q,` / `,J,` cells · `,w.grid.width,`×`,w.grid.height,P===1?``:` · paint ${U}×${W}`]}),o(`span`,{className:`flex-1`}),o(`button`,{type:`button`,onClick:ie,disabled:I||!K,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),o(`button`,{type:`button`,onClick:()=>void oe(),disabled:I||!K,className:b,children:I?`Saving…`:`Save`})]})]}):o(`p`,{className:`${l} leading-relaxed`,children:`Loading the camera's grid…`})})}):null}export{D as MotionZonesSettings};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/browser-BHo8W_uH.js","assets/rolldown-runtime-Cyuzqnbw.js"])))=>i.map(i=>d[i]);
2
- import{a as e}from"./rolldown-runtime-Cyuzqnbw.js";import{t}from"./vite-preload-helper-zJ_50EbN.js";import"./src-D-eMZfpa.js";import{G as n,R as r,U as i,X as a,a as o,b as s,t as c,x as l,y as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{p as d}from"./player-overlays-B1rOp2K0.js";import{t as f}from"./circle-check-big-BjqV4p1D.js";import{t as p}from"./copy-DUY8-DBe.js";import{t as m}from"./key-round-BtVEvNiB.js";import{t as h}from"./pencil-BHXuzoZT.js";import{C as g,T as _,b as v,j as y,l as b,r as x,s as S,x as C,y as w}from"./index-CBUhNGng.js";import{t as T}from"./AdminPage-CN6ZMhf0.js";a();function E({value:i,size:a=192}){let[o,c]=n(null),[u,d]=n(null);if(r(()=>{let n=!1;return t(()=>import(`./browser-BHo8W_uH.js`).then(t=>e(t.default,1)).then(async e=>{if(n)return;let t=e.create;if(typeof t!=`function`){d(`qrcode.create() unavailable in installed version`);return}try{let e=t(i,{errorCorrectionLevel:`M`});n||c(e)}catch(e){n||d(e instanceof Error?e.message:`QR generation failed`)}}),__vite__mapDeps([0,1])).catch(()=>{n||d(`qrcode library not installed`)}),()=>{n=!0}},[i]),u)return s(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle text-center p-4`,style:{width:a,height:a},children:`QR rendering unavailable — use the secret below.`});if(!o)return s(`div`,{className:`flex items-center justify-center text-[10px] text-foreground-subtle animate-pulse`,style:{width:a,height:a},children:`Generating…`});let f=o.modules.size,p=a/f,m=[];for(let e=0;e<f;e++)for(let t=0;t<f;t++)o.modules.data[e*f+t]&&m.push(s(`rect`,{x:t*p,y:e*p,width:p,height:p,fill:`currentColor`},`${t}-${e}`));return l(`svg`,{width:a,height:a,viewBox:`0 0 ${a} ${a}`,className:`text-black`,children:[s(`rect`,{x:0,y:0,width:a,height:a,fill:`white`}),m]})}a();var D={view:{icon:_,cls:`bg-foreground-subtle/15 text-foreground-subtle`},create:{icon:h,cls:`bg-primary/15 text-primary`},delete:{icon:S,cls:`bg-danger/15 text-danger`}};function O(){let{user:e,logout:t}=x();if(!e)return s(T,{children:s(`div`,{className:`text-xs text-foreground-subtle`,children:`Not signed in.`})});let n=e.isAdmin,r=e.scopes??[];return l(T,{children:[l(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3 flex items-center gap-3`,children:[s(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-primary/10 text-primary font-semibold text-base`,children:e.username.slice(0,1).toUpperCase()}),l(`div`,{className:`flex-1 min-w-0`,children:[s(`div`,{className:`text-sm font-semibold text-foreground truncate`,children:e.username}),l(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n?`Administrator`:`User`,` · session id`,` `,l(`span`,{className:`font-mono`,children:[e.id.slice(0,8),`…`]})]})]})]}),n&&l(`div`,{className:`rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-xs text-foreground flex items-start gap-2.5`,children:[s(g,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),l(`div`,{children:[s(`div`,{className:`font-semibold text-foreground`,children:`Unrestricted access`}),s(`p`,{className:`text-foreground-subtle mt-0.5`,children:`Admin sessions bypass the per-call scope check. Every protected endpoint is reachable regardless of the list below.`})]})]}),s(k,{}),s(j,{username:e.username}),r.length>0&&l(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[l(`div`,{className:`px-4 py-2 border-b border-border`,children:[s(`div`,{className:`text-xs font-semibold text-foreground`,children:`Granted scopes`}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Baked into your session token at login; sign out + back in to refresh after changes.`})]}),l(`div`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[s(`div`,{children:`Type`}),s(`div`,{children:`Target`}),s(`div`,{children:`Access`})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map((e,t)=>l(`li`,{className:`grid grid-cols-[100px_1fr_240px] gap-3 px-4 py-2.5 items-center text-xs`,children:[s(`span`,{className:`font-mono text-foreground-subtle`,children:e.type}),s(`span`,{className:`font-mono text-foreground`,children:e.type===`device`?e.targets.join(`, `):e.target}),s(`div`,{className:`flex items-center gap-1`,children:[`view`,`create`,`delete`].map(t=>{let n=e.access.includes(t),{icon:r,cls:i}=D[t];return l(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${n?i:`bg-transparent text-foreground-subtle/40 line-through`}`,title:n?`Can ${t}`:`Cannot ${t}`,children:[s(r,{className:`h-3 w-3`}),t]},t)})})]},t))})]}),s(`div`,{className:`flex justify-end`,children:l(`button`,{onClick:t,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground transition-colors`,children:[s(w,{className:`h-3 w-3`}),`Sign out`]})})]})}function k(){let e=d(),[t,r]=n(``),[i,a]=n(``),[o,u]=n(``),[p,h]=n(null),g=c({mutationFn:t=>e.changeOwnPassword(t),onSuccess:()=>{h({kind:`success`,msg:`Password updated.`}),r(``),a(``),u(``)},onError:e=>{h({kind:`error`,msg:e instanceof Error?e.message:`Update failed`})}}),_=i.length>0&&o.length>0&&i!==o,b=i.length>0&&i.length<8,x=t.length>=1&&i.length>=8&&i===o;return l(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[l(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[s(m,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`div`,{className:`text-xs font-semibold text-foreground`,children:`Change password`})]}),l(`div`,{className:`p-4 space-y-3`,children:[s(A,{label:`Current password`,value:t,onChange:r,autoComplete:`current-password`}),s(A,{label:`New password`,value:i,onChange:a,autoComplete:`new-password`,hint:`At least 8 characters.`}),s(A,{label:`Confirm new password`,value:o,onChange:u,autoComplete:`new-password`}),(_||b)&&s(`div`,{className:`text-[11px] text-danger`,children:_?`Passwords do not match.`:`New password must be at least 8 characters.`}),p&&l(`div`,{className:`text-[11px] flex items-center gap-1 ${p.kind===`success`?`text-emerald-500`:`text-danger`}`,children:[p.kind===`success`?s(f,{className:`h-3 w-3`}):s(y,{className:`h-3 w-3`}),p.msg]}),s(`div`,{className:`flex justify-end`,children:l(`button`,{onClick:()=>{h(null),g.mutate({currentPassword:t,newPassword:i})},disabled:!x||g.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[g.isPending?s(C,{className:`h-3 w-3 animate-spin`}):s(v,{className:`h-3 w-3`}),`Update password`]})})]})]})}function A({label:e,value:t,onChange:n,autoComplete:r,hint:i}){return l(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e}),s(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:r,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),i&&s(`div`,{className:`text-[10px] text-foreground-subtle`,children:i})]})}function j({username:e}){let t=d(),a=o({queryKey:[`auth`,`getOwnTotpStatus`],queryFn:()=>t.getOwnTotpStatus()}),m=a.data,[h,g]=n(null),[_,v]=n(``),[x,S]=n(null),[w,T]=n(!1),D=c({mutationFn:()=>t.setupOwnTotp(),onSuccess:e=>{g({secret:e.secret,otpauthUrl:e.otpauthUrl}),v(``),S(null)},onError:e=>S(e instanceof Error?e.message:`Setup failed`)}),O=c({mutationFn:e=>t.confirmOwnTotp(e),onSuccess:()=>{g(null),v(``),S(null),a.refetch()},onError:e=>S(e instanceof Error?e.message:`Confirmation failed — code did not match`)}),k=c({mutationFn:()=>t.disableOwnTotp(),onSuccess:()=>{S(null),a.refetch()},onError:e=>S(e instanceof Error?e.message:`Disable failed`)});r(()=>{if(!w)return;let e=setTimeout(()=>T(!1),1500);return()=>clearTimeout(e)},[w]);let A=i(()=>a.isLoading?`loading`:h?`setup_in_progress`:m?.enabled?`enrolled`:`not_enrolled`,[a.isLoading,m?.enabled,h]);return l(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[l(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[s(b,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`div`,{className:`text-xs font-semibold text-foreground`,children:`Two-factor authentication`})]}),l(`div`,{className:`p-4 space-y-3`,children:[A===`loading`&&l(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(C,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),A===`not_enrolled`&&l(u,{children:[s(`div`,{className:`text-xs text-foreground-subtle`,children:`2FA isn't active on your account. Enable it to require a 6-digit code from your authenticator app at every login.`}),s(`div`,{className:`flex justify-end`,children:l(`button`,{onClick:()=>{S(null),D.mutate()},disabled:D.isPending,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[D.isPending?s(C,{className:`h-3 w-3 animate-spin`}):s(b,{className:`h-3 w-3`}),`Enable 2FA`]})})]}),A===`setup_in_progress`&&h&&l(u,{children:[l(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`Scan the QR code (or enter the secret manually) into your authenticator app for`,` `,s(`span`,{className:`font-mono`,children:e}),`, then enter the 6-digit code below to confirm.`]}),l(`div`,{className:`flex flex-col items-center gap-3`,children:[s(`div`,{className:`rounded-lg border border-border bg-white p-3`,children:s(E,{value:h.otpauthUrl,size:180})}),l(`div`,{className:`w-full`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle mb-1`,children:`Secret (manual entry)`}),l(`div`,{className:`flex items-center gap-2 rounded border border-border bg-surface-hover/30 px-2 py-1.5`,children:[s(`code`,{className:`text-[11px] font-mono text-foreground break-all flex-1`,children:h.secret}),l(`button`,{onClick:()=>{h&&navigator.clipboard.writeText(h.secret).then(()=>T(!0))},className:`inline-flex items-center gap-1 text-[10px] text-foreground-subtle hover:text-foreground`,children:[w?s(f,{className:`h-3 w-3 text-emerald-500`}):s(p,{className:`h-3 w-3`}),w?`Copied`:`Copy`]})]})]})]}),l(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`6-digit code`}),s(`input`,{type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,placeholder:`123456`,value:_,onChange:e=>v(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full rounded-md border border-border bg-surface px-3 py-2 text-center text-lg font-mono tracking-widest text-foreground focus:outline-none focus:ring-2 focus:ring-primary`})]}),x&&l(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[s(y,{className:`h-3 w-3`}),x]}),l(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>{g(null),S(null),v(``)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),l(`button`,{onClick:()=>{S(null),O.mutate({code:_})},disabled:O.isPending||_.length!==6,className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[O.isPending?s(C,{className:`h-3 w-3 animate-spin`}):s(f,{className:`h-3 w-3`}),`Confirm`]})]})]}),A===`enrolled`&&m&&l(u,{children:[l(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[s(f,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),l(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[s(`div`,{className:`font-medium`,children:`2FA is active`}),l(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,m.confirmedAt?new Date(m.confirmedAt).toLocaleString():`—`]})]})]}),x&&l(`div`,{className:`text-[11px] text-danger flex items-center gap-1`,children:[s(y,{className:`h-3 w-3`}),x]}),s(`div`,{className:`flex justify-end`,children:l(`button`,{onClick:()=>{S(null),k.mutate()},disabled:k.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[k.isPending?s(C,{className:`h-3 w-3 animate-spin`}):s(b,{className:`h-3 w-3`}),`Disable 2FA`]})})]})]})]})}export{O as MyAccessPage};