@camstack/addon-admin-ui 1.0.3 → 1.0.5

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 (86) hide show
  1. package/dist/assets/{AddLocationWizard-ty_4uW1H.js → AddLocationWizard-B5dkIoQ2.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-CIvGYL8Z.js → AddonCollectionPage-DVB69ClF.js} +1 -1
  3. package/dist/assets/Addons-Bfvs6-g0.js +1 -0
  4. package/dist/assets/{AdminTabs-7T1CldHN.js → AdminTabs-BWNsXXy4.js} +1 -1
  5. package/dist/assets/{BrokerForm-DzjaLHmG.js → BrokerForm-DYIjeusD.js} +1 -1
  6. package/dist/assets/{BrokerStep-B3pEVZ2L.js → BrokerStep-DjzuHh1z.js} +1 -1
  7. package/dist/assets/{Capabilities-D2qn1TDV.js → Capabilities-hicnOVum.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-BWnECBvl.js → CapabilityBadges-CSyidKVA.js} +1 -1
  9. package/dist/assets/Cluster-AyC6G6sS.js +7 -0
  10. package/dist/assets/{Dashboard-HorCsmCt.js → Dashboard-BkLuDhPq.js} +1 -1
  11. package/dist/assets/{Data-hispFwBv.js → Data-Beh_0Rmk.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-BtnTELA6.js → DetectionIntelligence-BfxtDLUn.js} +1 -1
  13. package/dist/assets/DeviceDetail-DGlm0ka0.js +2 -0
  14. package/dist/assets/{Devices-XIivtEYO.js → Devices-DzX3RWXL.js} +1 -1
  15. package/dist/assets/{EmbedPlayerPage-CIF0Ft1g.js → EmbedPlayerPage-WJHXt2K5.js} +1 -1
  16. package/dist/assets/{FormBuilder-DVLWBVys.js → FormBuilder-C_FGp6fK.js} +1 -1
  17. package/dist/assets/Identity-oMA7lRlr.js +1 -0
  18. package/dist/assets/IntegrationDetail-DUzh5vXL.js +1 -0
  19. package/dist/assets/{Integrations-CxuWXvnl.js → Integrations-DMJL2wGt.js} +1 -1
  20. package/dist/assets/{Integrations-CxFwUmeX.js → Integrations-DdxCeVlW.js} +1 -1
  21. package/dist/assets/{Logs-DYrcsFh9.js → Logs-Czo2ju6R.js} +1 -1
  22. package/dist/assets/{MotionZonesSettings-CepMSlXn.js → MotionZonesSettings-DSz0ZQ3J.js} +1 -1
  23. package/dist/assets/{MyAccess-C-zxwxTM.js → MyAccess-CiRVe6o4.js} +1 -1
  24. package/dist/assets/{Network-D5ppyqPS.js → Network-2_yW2eMz.js} +1 -1
  25. package/dist/assets/{NodeAddonsSettingsPanel-B4ru8rzf.js → NodeAddonsSettingsPanel-CWOXJvnI.js} +1 -1
  26. package/dist/assets/Pipeline-MNGNVhOO.js +1 -0
  27. package/dist/assets/{PrivacyMaskSettings-Cut8tYhS.js → PrivacyMaskSettings-CrWASNzq.js} +1 -1
  28. package/dist/assets/{ProviderIcon-BpqSF3Hu.js → ProviderIcon-DU7EkOsQ.js} +1 -1
  29. package/dist/assets/{Settings-CriiXyFu.js → Settings-Ba4e7VPd.js} +1 -1
  30. package/dist/assets/{Showroom-KHowYChm.js → Showroom-fzNXeqzs.js} +1 -1
  31. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Cus-LW9c.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-OIn_kS_J.js} +1 -1
  32. package/dist/assets/{bell-C1jXqDWz.js → bell-PpkN_TgJ.js} +1 -1
  33. package/dist/assets/circle-check-big-BzSkZiMj.js +1 -0
  34. package/dist/assets/{copy-tH10joFB.js → copy-D3XNVDYo.js} +1 -1
  35. package/dist/assets/dist-CyLsBIs8.js +1 -0
  36. package/dist/assets/{dist-mzJ_Pmak.js → dist-DyYmhGqc.js} +1 -1
  37. package/dist/assets/{download-DyMeaCfZ.js → download-BHYjG90K.js} +1 -1
  38. package/dist/assets/{hostInit-8PN225l2.js → hostInit-BykkFKC1.js} +1 -1
  39. package/dist/assets/index-COZOEwaJ.css +2 -0
  40. package/dist/assets/index-DpTstpp_.js +4 -0
  41. package/dist/assets/{key-round-eCBxaKT6.js → key-round-Dn1oOWgV.js} +1 -1
  42. package/dist/assets/{mf-entry-bootstrap-0-137d5c5b.js → mf-entry-bootstrap-0-04dcd8db.js} +2 -2
  43. package/dist/assets/{pencil-xW8n5CLs.js → pencil-Kbj4_JBR.js} +1 -1
  44. package/dist/assets/{player-overlays-DzZKARlk.js → player-overlays-zGqQhGgE.js} +1 -1
  45. package/dist/assets/plus-CPqVcqUV.js +1 -0
  46. package/dist/assets/{radio-CWnAI4na.js → radio-CTfNJnG5.js} +1 -1
  47. package/dist/assets/{refresh-cw-BKhUNMXQ.js → refresh-cw-BnmOdHXx.js} +1 -1
  48. package/dist/assets/remoteEntry-BKwb226y.js +1 -0
  49. package/dist/assets/{rotate-ccw-BXu8SIv5.js → rotate-ccw-UF_FErzF.js} +1 -1
  50. package/dist/assets/rotate-cw-B4szmAxG.js +1 -0
  51. package/dist/assets/search-C07n9Z2S.js +1 -0
  52. package/dist/assets/{server-X3K4ldX4.js → server-DK5PS_QF.js} +1 -1
  53. package/dist/assets/{sparkles-ChgPFrhX.js → sparkles-B5Duaxbv.js} +1 -1
  54. package/dist/assets/square-Bex0hnGW.js +1 -0
  55. package/dist/assets/{square-check-big-Bzz95oCZ.js → square-check-big-qiutr_Ci.js} +1 -1
  56. package/dist/assets/src-DqOo0bwK.js +1 -0
  57. package/dist/assets/src-Dxc7AUYA.js +34 -0
  58. package/dist/assets/{upload-BeG8PyHB.js → upload-Btk1HMIN.js} +1 -1
  59. package/dist/assets/{useDevice-B7VwJa4X.js → useDevice-uoMH2oPD.js} +1 -1
  60. package/dist/assets/{useEventInvalidation-Cf9VIpDW.js → useEventInvalidation-DDUSWISR.js} +1 -1
  61. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BLisQvKo.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-s1j_uW8u.js} +2 -2
  62. package/dist/assets/{wifi-DYJHTrlD.js → wifi-DH-9OMrB.js} +1 -1
  63. package/dist/assets/{zap-DLiiHws-.js → zap-Cpoh2hjh.js} +1 -1
  64. package/dist/index.html +6 -6
  65. package/dist/server/addon.js +122 -27
  66. package/dist/sw.js +1 -1
  67. package/dist/workbox-14d7584c.js +1 -0
  68. package/package.json +1 -1
  69. package/dist/assets/Addons-CWtFT6QM.js +0 -1
  70. package/dist/assets/Cluster-BVUZdAyW.js +0 -7
  71. package/dist/assets/DeviceDetail-OXTiYiO9.js +0 -2
  72. package/dist/assets/Identity-8krGNqDO.js +0 -1
  73. package/dist/assets/IntegrationDetail-Dyg4wlgs.js +0 -1
  74. package/dist/assets/Pipeline-CS6lN8Ww.js +0 -1
  75. package/dist/assets/circle-check-big-is5GRKO9.js +0 -1
  76. package/dist/assets/dist-CGRDjIOZ.js +0 -1
  77. package/dist/assets/index-CAfPe666.js +0 -4
  78. package/dist/assets/index-CTiiXuB_.css +0 -2
  79. package/dist/assets/plus-DVpT3Ja2.js +0 -1
  80. package/dist/assets/remoteEntry-BOZn_K50.js +0 -1
  81. package/dist/assets/rotate-cw-BO4D9G2F.js +0 -1
  82. package/dist/assets/search-DyWYI0Yj.js +0 -1
  83. package/dist/assets/square-Faey8y7b.js +0 -1
  84. package/dist/assets/src-C5tvi19O.js +0 -34
  85. package/dist/assets/src-CrhOk7JL.js +0 -1
  86. package/dist/workbox-9c191d2f.js +0 -1
@@ -1,2 +0,0 @@
1
- import{A as e,B as t,Bn as n,Cn as r,Cr as i,E as a,Et as o,G as s,Gi as c,H as l,I as u,Ir as d,Ji as f,Jn as p,Jr as m,Jt as h,K as g,Kn as _,L as v,Mr as y,Ni as b,Oi as x,Sn as S,T as C,U as w,Ui as T,V as E,Vr as ee,W as D,Wi as O,Xt as k,Yt as A,Zi as te,_a as j,_n as ne,a as M,an as N,bn as P,dn as re,dt as ie,f as F,fn as ae,g as oe,gn as se,hn as ce,i as I,j as le,k as ue,ki as de,l as fe,li as pe,ln as L,m as me,mn as he,n as ge,o as _e,on as ve,p as ye,pn as be,qi as xe,qn as R,r as Se,ri as Ce,rn as we,ti as Te,u as Ee,ui as De,un as Oe,ur as ke,va as Ae,vn as je,w as Me,xn as Ne,y as Pe,yn as Fe,zr as Ie}from"./src-C5tvi19O.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-DzZKARlk.js";import{C as We,E as Ge,b as Y,g as Ke,v as qe}from"./src-CrhOk7JL.js";import{t as Je}from"./CapabilityBadges-BWnECBvl.js";import{t as Ye}from"./bell-C1jXqDWz.js";import{n as Xe,t as Ze}from"./rotate-ccw-BXu8SIv5.js";import{t as Qe}from"./ProviderIcon-BpqSF3Hu.js";import{t as $e}from"./pencil-xW8n5CLs.js";import{t as et}from"./plus-DVpT3Ja2.js";import{t as tt}from"./refresh-cw-BKhUNMXQ.js";import{t as nt}from"./rotate-cw-BO4D9G2F.js";import{t as rt}from"./server-X3K4ldX4.js";import{t as it}from"./wifi-DYJHTrlD.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-CAfPe666.js";import{t as Ct}from"./StatusBadge-CkYubfRG.js";import{n as wt,t as Tt}from"./useDevice-B7VwJa4X.js";import{n as Et,r as Dt,t as Ot}from"./SchemaTabBar-ByWwzBUZ.js";import{t as kt}from"./FormBuilder-DVLWBVys.js";import{t as At}from"./useEventInvalidation-Cf9VIpDW.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 M(J().trpcClient,e)}function Gt(e){let[t,n]=B(`idle`),[r,i]=B(null),a=U(null),o=U(null),s=U(null),c=U(!0),l=R(),u=_(),d=p(),f=z(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null},[]),m=z(async()=>{if(t===`idle`)return;n(`stopping`);let r=s.current;if(r&&e!==null)try{await Promise.race([d.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}f(),c.current&&(n(`idle`),i(null))},[t,e,d,f]),h=z(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,f=null,p=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await l.mutateAsync({deviceId:e});p=t.sessionId,s.current=p,n(`connecting`),f=new RTCPeerConnection,a.current=f,f.oniceconnectionstatechange=()=>{if(!c.current)return;let e=f.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&c.current&&(i(e===`failed`?`WebRTC connection failed`:null),m())};for(let e of r.getAudioTracks())f.addTrack(e,r);await f.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let d=await f.createAnswer();await f.setLocalDescription(d);let h=f.localDescription?.sdp??d.sdp??``;await u.mutateAsync({deviceId:e,sessionId:p,sdpAnswer:h})}catch(t){let l=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),f)try{f.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,p!==null)try{await d.mutateAsync({deviceId:e,sessionId:p})}catch{}s.current=null,c.current&&(i(l),n(`error`))}},[e,t,l,u,d,m]);return V(()=>(c.current=!0,()=>{c.current=!1;let t=s.current;if(t!==null&&e!==null&&d.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null}),[e]),{state:t,error:r,start:h,stop:m,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:``,i=Number.isFinite(e),o=Wt(i?e:null),{streams:s,pipelineMetrics:c,createSession:l,sendAnswer:u,handleOffer:d,getIceServers:f,addIceCandidate:p,getIceCandidates:m,closeSession:h,getSessionState:g}=I(n.trpcClient,i?e:null),_=D(n.trpcClient,i?e:null),v=Gt(i&&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=a(),w=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,T=S.length>0?G(Re,{children:S.map(e=>G(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return G(Pe,{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:T,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(oe,{...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(F,{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:n}=yt(),r=ot(),i=J(),{data:a,isLoading:o,isError:s}=wt(e),{data:c}=L({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:n(`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:n(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let u=a??[];if(u.length===0)return null;let d=E(c?.stableId??``,u,c?.childLayout),f=d.ungrouped,p=e=>r(`/devices/${String(e)}`),m=(e,n)=>G(t,{trpc:i.trpcClient,device:n,variant:`minimal`,onNavigate:p},e),h=f.some(e=>!!e.role),g=f.some(e=>!e.role),_=h&&!g?n(`device.accessories`,{defaultValue:`Accessories`}):!h&&g?n(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):n(`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(l,{title:n(`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(l,{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=Fe({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}=he(void 0,{enabled:r}),d=u??[];V(()=>{r||o(t??``)},[t,r]),V(()=>{r&&l.current?.focus()},[r]);let f=je({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=le(),{data:r}=L({deviceId:t??0},{enabled:t!==null}),{data:i}=ve({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=h({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}=ke({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),l=c?.streams??{},u=Object.entries(l),d=o.includes(qe.DoorbellButton),f=Se(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(ye,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),s&&n!==null&&G(pn,{deviceId:n}),i&&n!==null&&G(Me,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),d&&G(Ee,{history:f.history,latestIsFresh:p}),i&&n!==null&&G(Me,{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:i}){let a=K(),{user:o}=_t(),s=o?.isAdmin===!0,c=U(!1),{data:l,isLoading:u}=Oe({deviceId:e},{refetchInterval:()=>c.current?!1:2500,enabled:Number.isFinite(e)}),{data:d}=L({deviceId:e},{enabled:Number.isFinite(e)}),f=l?.settings??null,p=l?.live??null,m=H(()=>{if(!f&&!p)return null;let e=f?.sections??[],n=(p?.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=[...f?.tabs??[],...(p?.tabs??[]).filter(e=>!(f?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[f,p,t]),h=H(()=>yn(m),[m]),g=H(()=>kn(h,s),[h,s]),_=H(()=>Tn(g),[g]),v=De(),y=pe(),b=S(),x=se(),C=r({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),w={isPending:C.isPending,mutate:t=>{C.mutate({deviceId:e,changes:[...t]})}},T=Dt({schema:g,serverValues:_,onImmediateSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=En(g,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&w.mutate(t)},[g,w]),onDeferredSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=En(g,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&w.mutate(t)},[g,w])}),{values:E,pendingKeys:ee,handleChange:D,handleSave:O,handleDiscard:k}=T;if(c.current=T.editingPaused,u)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(!g||g.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 i=We(e,r);await v.mutateAsync({brokerId:i}),a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!d)return{status:`error`,error:`Device metadata not loaded yet`};try{return await b.mutateAsync({addonId:d.addonId,type:d.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),i=await y.mutateAsync({brokerId:r});return a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await x.mutateAsync({deviceId:e,action:n,input:r});return a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return G(_n,{schema:g,values:E,pendingKeys:ee,onChange:D,onAction:A,onSave:O,onDiscard:k,disabled:w.isPending,activeSubTab:n,onSubTabChange:i})}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=A({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:t}){return G(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:G(de,{trpc:J().trpcClient,deviceId:e,features:t})})}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(x,{trpc:J().trpcClient,deviceId:e,features:t})})}function $({deviceId:e,deviceType:t,features:n}){let r=J(),i=g(t)?.HeroCard??x,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(v,{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,l]=B(null),d=P({onSuccess:()=>{l(null),n.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{l(`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(u,{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}=L({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}=ve({deviceId:e},{enabled:n}),{data:l}=be({deviceType:i},{enabled:!!i}),u=Ne({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 d=new Map,f={};for(let e of l??[])f[e.capName]=e.wrappers;for(let e of a?.entries??[])d.set(e.capName,{...e,wrappers:f[e.capName]??[]});for(let e of l??[])d.has(e.capName)||d.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let p=[...d.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(p.length===0)return 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 m=p.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:m}),` of `,p.length,` capabilit`,p.length===1?`y`:`ies`,` bound — rows marked `,G(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),G(xe,{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:u.isPending,onPick:r=>{let i=n===r;u.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:p,rowKey:e=>e.capName,minWidthPx:720})]})}function 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 n=K(),[r,a]=B(null),[o,s]=B(null),[l,u]=B(null),[f,p]=B(null),h=d({deviceId:e}),g=ee(),_=Ie({deviceId:e}),v=y(),b=H(()=>_.data?.agentNodeId||v.data?.find(e=>e.online)?.nodeId||`hub`,[_.data?.agentNodeId,v.data]),x=o??b,S=i({nodeId:x??``},{enabled:!!x}),C=m({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),u(null)}}),w=H(()=>S.data?c(S.data):[],[S.data]),E=H(()=>{let e=h.data??null,t={};for(let n of g.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},[h.data,g.data]),D=r?Kn(S.data??null,r):null,k=x?g.data?.find(e=>e.nodeId===x)??null:null,A=r&&k?k.settings.addonDefaults[r]??null:null,te=r&&x?h.data?.stepOverridesByAgent?.[x]?.[r]??null:null,j=S.data?.selectedEngine.format??`coreml`,ne=e=>{s(e),u(null),p(null)};return g.isLoading||S.isLoading?G(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):S.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:w,selectedAddonId:r,onSelect:e=>{a(e),u(null),p(null)},agentDots:E})}),G(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!r||!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:(g.data??[]).map(e=>G(`button`,{type:`button`,onClick:()=>ne(e.nodeId),className:`px-3 py-1 text-xs ${x===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),G(Jn,{agents:(g.data??[]).map(e=>e.nodeId),currentAgent:x,onPick:e=>{if(!x||!r||!S.data||!g.data)return;let t=g.data.find(t=>t.nodeId===e),n=g.data.find(e=>e.nodeId===x);if(!t||!n)return;let[i]=Ae({source:{nodeId:t.nodeId,engine:{format:j},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:j},defaults:n.settings.addonDefaults},catalog:S.data,addonIds:[r]});if(!i){p(`no mirror result`);return}if(i.outcome===`skip`){p(`skipped: ${i.reason??`no candidate`}`);return}u(i.patch),p(`${i.outcome} from ${e}`)}}),f&&G(`div`,{className:`text-[10px] text-foreground-subtle`,children:f})]}),A&&G(T,{mode:`device`,addon:D,agentDefault:A,agentNodeId:x??``,currentPatch:l??te,engineFormat:j,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:!te||C.isPending,onClick:()=>{!x||!r||C.mutate({deviceId:e,agentNodeId:x,addonId:r,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:!x||!r||C.isPending,onClick:()=>{!x||!r||C.mutate({deviceId:e,agentNodeId:x,addonId:r,patch:l})},children:C.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}=ae({}),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}=re({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}=re({deviceId:_??0},{enabled:_!=null}),E=T?.caps??[],ee=d.find(e=>e.cap===p)?.fields??[],D=ee.find(e=>e.path===h),O=E.find(e=>e.cap===y)?.fields??[],k=O.find(e=>e.path===x),A=e=>{m(e),g(``)},te=e=>{v(e===``?null:Number(e)),b(``),S(``)},j=e=>{b(e),S(``)},ne=p!==``&&h!==``&&_!=null&&y!==``&&x!==``,M=()=>{if(!ne)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}})},N=`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=>A(e.target.value),className:N,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:N,children:[G(`option`,{value:``,children:`— select a field —`}),ee.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=>te(e.target.value),className:N,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=>j(e.target.value),className:N,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:N,children:[G(`option`,{value:``,children:`— select a field —`}),O.map(e=>q(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),G(tr,{value:C,onChange:w,sourceField:k,targetKind:D?.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:!ne,onClick:M,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}=L({deviceId:e},{enabled:Number.isFinite(e),refetchInterval:1e4}),a=ne({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),r=Number.isFinite(t),i=ot(),a=K(),c=b(),l=J(),[u,d]=ut(),p=u.get(`tab`)??`overview`,m=u.get(`sub`),[h,g]=B(`logs`),_=`device-detail.left-col-width-px`,[v,y]=B(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(_),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),x=U(v);x.current=v;function S(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??v??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{y(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=x.current;if(e!==null)try{window.localStorage.setItem(_,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:T,isLoading:E,isError:ee}=L({deviceId:t},{enabled:r,refetchInterval:5e3,retry:1}),{data:D}=Oe({deviceId:t},{enabled:r}),O=H(()=>{let e=D?.settings?.sections??[],t=D?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(Ut)&&r.add(Bt),[...r].map(e=>e===`export`?{id:e,label:Vt,isAddonContrib:!0}:{id:e,label:Ge[e]?.label??e,isAddonContrib:!0})},[D]),k=T,A=String(k?.name??e.deviceId??`Device`),j=k?.online===!0,ne=j?`online`:`offline`,M=String(k?.addonId??`rtsp`),P=k?.features??[],F=k?.type,ae=F===Y.Camera,oe=typeof k?.parentDeviceId==`number`?k.parentDeviceId:null,{data:se}=L({deviceId:oe??0},{enabled:oe!==null}),I=te(),le=k?.disabled!==!0,{data:de}=re({deviceId:t},{enabled:r}),pe=(de?.caps.length??0)>0,me=H(()=>{let e=new Set,t=[];for(let n of[...lr(F),...O])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!pe)&&t.push(n));return t},[F,O,pe]),he=H(()=>me.some(e=>e.id===p)?p:`overview`,[me,p]),ge=z(e=>{d(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[d]),ve=z(e=>{d(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[d]),{data:ye}=wt(r?t:0),be=(ye??[]).length>0,xe=H(()=>ur.filter(({featureGate:e})=>!e||P.includes(e)),[P]),{data:R}=n({addonId:M},{enabled:!!M&&M!==`rtsp`}),Se=ce({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]}),i(R?.id?`/integrations/${R.id}`:`/integrations`)}}),Ee=N({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=we({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=Ce(),Ae=ie({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),je=P.includes(qe.Rebootable),Me=P.includes(qe.BatteryOperated),Ne=s(l.trpcClient,Me&&r?t:null),[Pe,Fe]=B(!1),V=ze(l.trpcClient,r?t:null),W=async()=>{if(!(Pe||!V)){Fe(!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=A.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{Fe(!1)}}},Le=Ee.isPending||De.isPending,{data:Re}=Ie({deviceId:t},{enabled:r,refetchInterval:1e4}),Be=Re?.agentNodeId??null,Ve=typeof Be==`string`&&Be.length>0&&!Be.startsWith(`addon:`)?Be:void 0,{data:Ue}=Te({deviceId:t,...Ve?{nodeId:Ve}:{}},{enabled:r,refetchInterval:3e3,retry:!1}),{data:We}=o({deviceId:t},{enabled:r,refetchInterval:3e3,retry:!1}),Ke=We?.level?.dbfs??null;function Ye(){if(!r)return null;switch(he){case`overview`:return G(hn,{device:k??{}});case`config`:return G(jn,{deviceId:t,activeSubTab:m,onSubTabChange:ve});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=he;return O.some(t=>t.id===e)?e===`export`?G(An,{deviceId:t,sectionFilter:Ut,activeSubTab:m,onSubTabChange:ve}):G(An,{deviceId:t,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),activeSubTab:m,onSubTabChange:ve}):null}}}return r?E?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`})})]}):ee||!T?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:()=>i(`/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(f,{items:[{label:`Integrations`,onClick:()=>i(`/integrations`)},{label:R?.name??M,onClick:()=>R?.id&&i(`/integrations/${R.id}`)},{label:A}]})}),q(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[G(Qe,{type:M,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:A}),G(Ct,{status:ne}),Me&&G(w,{status:Ne,variant:`full`})]}),oe!==null&&se&&q(`button`,{type:`button`,onClick:()=>i(`/devices/${oe}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${se.name}`,children:[G(`span`,{children:`↑`}),G(`span`,{className:`truncate`,children:String(se.name??`Device #${oe}`)})]}),G(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:P.length>0&&G(Je,{capabilities:P})})]}),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()=>{le?await c({title:`Disable "${A}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&De.mutate({deviceId:t}):Ee.mutate({deviceId:t})},disabled:Le,title:le?`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 ${le?`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…`:le?`Enabled`:`Disabled`})]}),G(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),G(fe,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:st,disabled:Pe,onClick:()=>{W()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:nt,hidden:!je,disabled:ke.isPending,danger:!0,onClick:async()=>{await c({title:`Reboot "${A}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&ke.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??M}.`,icon:tt,disabled:Ae.isPending,danger:!0,onClick:async()=>{await c({title:`Restart "${R?.name??M}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${A}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Ae.mutate({addonId:M})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:vt,separatorBefore:!0,disabled:Se.isPending,danger:!0,onClick:async()=>{await c({title:`Delete "${A}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Se.mutate({deviceId:t})}}]})]})]})]}),G(ue,{deviceId:t,device:k??void 0,children:G(C,{children:G(He,{children:G(_e,{children:q(`main`,{className:I?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[q(`div`,{className:I?`flex flex-col bg-surface`:`${v===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!I&&v!==null?{width:`${String(v)}px`}:void 0,children:[G(`div`,{className:`flex-shrink-0 border-b border-border-subtle ${ae?`bg-black`:`bg-surface`}`,children:ae?G(Qt,{deviceId:t,intercomAvailable:P.includes(qe.TwoWayAudio)}):G(Vn,{deviceId:t,deviceName:A,deviceType:F??`unknown`,provider:M,isOnline:j,features:P})}),q(`div`,{className:I?`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:xe.map(({id:e,label:t,icon:n})=>q(`button`,{onClick:()=>g(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${h===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:I?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[h===`logs`&&G($t,{deviceId:t,containerDeviceId:F===`container`?t:void 0}),h===`repl`&&G(en,{deviceId:t}),h===`events`&&G(tn,{deviceId:t}),h===`state`&&G(nn,{deviceId:t})]})]})]}),!I&&G(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:S,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:I?`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:me.map(e=>{let t=he===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:I?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[he===`overview`&&be&&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:()=>i(`/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=j(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{Ci as e,Di as t,Ei as n,Ni as r,Si as i,Ti as a,_i as o,at as s,bi as c,c as l,fa as u,gi as d,hi as f,mi as p,pi as m,qi as h,s as g,st as _,vi as v,wi as y,xi as b,yi as x}from"./src-C5tvi19O.js";import{G as S,U as C,X as w,b as T,o as E,x as D,y as O}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 k}from"./circle-check-big-is5GRKO9.js";import{t as A}from"./copy-tH10joFB.js";import{t as j}from"./key-round-eCBxaKT6.js";import{t as M}from"./AddonCollectionPage-CIvGYL8Z.js";import{t as ee}from"./plus-DVpT3Ja2.js";import{B as N,C as P,F,d as I,i as L,l as R,r as z,s as B,w as V,x as H}from"./index-CAfPe666.js";import{t as U}from"./AdminPage-CN6ZMhf0.js";import{t as W}from"./AdminTabs-7T1CldHN.js";var G=N(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),K=N(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),te=N(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),q=N(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),J=N(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);w();function ne({userId:e,username:t,onClose:n}){let i=E(),a=r(),s=o({userId:e}),c=s.data,l=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=d({onSuccess:()=>{l(),n()}}),p=s.isLoading?`loading`:c?.enabled?`enrolled`:`not_enrolled`;return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:D(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[D(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[D(`div`,{className:`flex items-center gap-2`,children:[T(R,{className:`h-4 w-4 text-primary`}),D(`div`,{children:[T(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),D(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,T(`span`,{className:`font-mono`,children:t})]})]})]}),T(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`p-4 space-y-4`,children:[p===`loading`&&D(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[T(H,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),p===`not_enrolled`&&D(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[T(P,{className:`h-4 w-4 mt-0.5 shrink-0`}),D(`div`,{children:[T(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),T(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),p===`enrolled`&&c&&D(O,{children:[D(`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:[T(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),D(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[T(`div`,{className:`font-medium`,children:`2FA is active`}),D(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,c.confirmedAt?new Date(c.confirmedAt).toLocaleString():`—`]})]})]}),T(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),D(`div`,{className:`flex justify-end gap-2`,children:[T(u,{onClick:n,variant:`secondary`,children:`Close`}),D(`button`,{onClick:async()=>{await a({title:`Remove 2FA`,message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&f.mutate({userId:e})},disabled:f.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:[f.isPending?T(H,{className:`h-3 w-3 animate-spin`}):T(L,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function Y(){let e=E(),{user:a}=z(),[o,s]=S(!1),[c,l]=S(``),[u,d]=S(``),[m,g]=S(!1),[_,v]=S(null),{data:y,isLoading:x,isError:C}=b(),w=r(),O=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=p({onSuccess:()=>{O(),s(!1),l(``),d(``),g(!1),v(null)},onError:e=>{v(e instanceof Error?e.message:`Failed to create user`)}}),A=f({onSuccess:O}),j=t({onSuccess:O}),M=i({onSuccess:O}),N=n({onSuccess:()=>{O(),F(null)}}),[P,F]=S(null),[V,W]=S(null),G=y??[];async function K(e){await w({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&A.mutate({id:e.id})}async function q(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await w({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}}function J(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function Y(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return D(U,{children:[T(`div`,{className:`flex items-center justify-end`,children:D(`button`,{onClick:()=>s(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[T(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),o&&D(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[D(`div`,{className:`flex items-center justify-between`,children:[T(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),T(`button`,{onClick:()=>s(!1),className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`grid grid-cols-3 gap-3`,children:[D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),T(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),T(`input`,{type:`password`,value:u,onChange:e=>d(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),D(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:m,onChange:e=>g(e.target.checked),className:`rounded border-border focus:ring-primary`}),T(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),_&&T(`p`,{className:`text-[10px] text-danger`,children:_}),D(`div`,{className:`flex justify-end gap-2`,children:[T(`button`,{onClick:()=>s(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),T(`button`,{onClick:()=>k.mutate({username:c,password:u,isAdmin:m}),disabled:k.isPending||!c||!u,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:k.isPending?`Creating...`:`Create`})]})]}),x&&T(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),C&&T(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!C&&G.length===0&&T(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return T(h,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>D(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>J(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),T(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return T(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return D(`button`,{onClick:()=>F(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[T(I,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>T(`span`,{className:`text-foreground-subtle`,children:Y(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:t=>{let n=e(t);return D(`div`,{className:`flex items-center justify-end gap-1`,children:[t.id!==a?.id&&t.totpEnabled&&D(`button`,{onClick:()=>W(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[T(R,{className:`h-3 w-3`}),`Remove 2FA`]}),D(`button`,{onClick:()=>q(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[T(te,{className:`h-3 w-3`}),`Reset password`]}),D(`button`,{onClick:()=>K(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),V&&T(ne,{userId:V.id,username:V.username,onClose:()=>W(null)}),P&&T(re,{user:P,onClose:()=>F(null),onSubmit:e=>N.mutate({userId:P.id,scopes:e}),submitting:N.isPending})]})}function re(e){let{user:t}=z(),n=t?.isAdmin===!0;return T(ie,{...e,callerScopes:n?null:t?.scopes??[]})}function ie({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=S(C(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=l(a);return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:D(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[D(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[D(`div`,{children:[D(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),T(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),T(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`px-4 py-4`,children:[T(g,{value:a,onChange:o,clampToParent:i,emptyHint:D(O,{children:[`No scopes granted.`,` `,T(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&T(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),D(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[T(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),T(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?T(H,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}w();var ae=`bg-primary/10 text-primary`,oe=`bg-foreground-subtle/10 text-foreground-subtle`;function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function se(e){return e?e===`*`?`*`:e.join(`, `):``}function ce(){let t=E(),n=r(),{data:i,isLoading:o}=v(),{data:s}=b(),c=C(()=>i??[],[i]),l=C(()=>s??[],[s]),u=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),d=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[f,p]=S(!1),[h,g]=S(null),_=e({onSuccess:u}),y=m({onSuccess:({token:e,record:t})=>{d(),p(!1),g({token:e,label:t.name})}}),x=a({onSuccess:d}),w=async(e,t)=>{await n({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&_.mutate({id:e})},O=async(e,t)=>{await n({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&x.mutate({id:e})};return D(U,{children:[D(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[T(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),D(`button`,{onClick:()=>p(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:l.length===0,title:l.length===0?`Create a user first`:`Issue a scoped token`,children:[T(I,{className:`h-3.5 w-3.5`}),`New token`]})]}),D(Z,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[l.length===0&&T(ue,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),l.map(e=>T(fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{O(e,t)},revokePending:x.isPending,revokeId:x.variables?.id},e.id))]}),c.length>0&&T(Z,{title:`Legacy API keys`,subtitle:`${c.length} pre-existing — revoke only`,children:T(de,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:c.map(e=>{let t=!!e.isAdmin,n=_.isPending&&_.variables?.id===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?ae:oe}`,children:t?`admin`:`regular`})}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:se(e.allowedProviders)||`all`}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:D(`button`,{onClick:()=>{w(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),o&&T(le,{}),f&&T(pe,{users:l.map(e=>({id:e.id,username:e.username})),onClose:()=>p(!1),onSubmit:e=>y.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:y.isPending}),h&&T(me,{token:h.token,label:h.label,onClose:()=>g(null)})]})}function Z({title:e,subtitle:t,children:n}){return D(`div`,{className:`space-y-2`,children:[D(`div`,{className:`flex items-baseline justify-between`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&T(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function le(){return T(`div`,{className:`space-y-2`,children:[1,2].map(e=>T(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ue({text:e}){return T(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function de({headers:e,rows:t}){return T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:D(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:T(`tr`,{children:e.map((t,n)=>T(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),T(`tbody`,{children:t})]})})}function fe({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=c({userId:e}),s=a??[];return o||s.length===0?null:D(`div`,{className:`space-y-1.5`,children:[T(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),T(de,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>D(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.expiresAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:D(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function pe({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=z(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=S(e[0]?.id??``),[c,u]=S(``),[d,f]=S([{type:`capability`,target:``,access:[`view`,`create`]}]),[p,m]=S(``),h=l(d),_=o!==``&&c.trim().length>0&&d.length>0&&h===null&&!r;return D(he,{title:`Create scoped token`,onClose:t,children:[D(`div`,{className:`space-y-3`,children:[T(Q,{label:`On behalf of user`,children:T(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>T(`option`,{value:e.id,children:e.username},e.id))})}),T(Q,{label:`Name`,children:T(`input`,{value:c,onChange:e=>u(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),D(Q,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[T(g,{value:d,onChange:f,clampToParent:a}),h&&T(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),T(Q,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:T(`input`,{type:`number`,min:1,value:p,onChange:e=>m(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),D(ge,{children:[T(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),D(`button`,{onClick:()=>{let e=parseInt(p,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:d,expiresAt:t})},disabled:!_,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[r?T(H,{className:`h-3.5 w-3.5 animate-spin`}):T(I,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function me({token:e,label:t,onClose:n}){let[r,i]=S(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return D(he,{title:`Token: ${t}`,onClose:n,children:[D(`div`,{className:`space-y-3`,children:[T(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),T(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),D(ge,{children:[D(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[r?T(F,{className:`h-3.5 w-3.5 text-primary`}):T(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),T(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function he({title:e,onClose:t,children:n}){return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:D(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[D(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),T(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),T(`div`,{className:`p-4`,children:n})]})})}function ge({children:e}){return T(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Q({label:e,hint:t,children:n}){return D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&T(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}w();function $(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function _e(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function ve(){return T(`div`,{className:`space-y-2`,children:[1,2].map(e=>T(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ye({text:e}){return T(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function be({headers:e,rows:t}){return T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:D(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:T(`tr`,{children:e.map((t,n)=>T(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),T(`tbody`,{children:t})]})})}function xe(){let e=E(),t=r(),{data:n,isLoading:i}=x(),a=C(()=>n??[],[n]),o=y({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),s=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&o.mutate({id:e})};return D(U,{icon:q,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[i&&T(ve,{}),!i&&a.length===0&&T(ye,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!i&&a.length>0&&T(be,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:a.map(e=>{let t=e.revokedAt!==null,n=(o.isPending?o.variables?.id:void 0)===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>T(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:_e(e)},t))})}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.createdAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 border-b border-border`,children:t?D(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,$(e.revokedAt)]}):T(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&D(`button`,{onClick:()=>{s(e.id,e.integrationId)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}w();var Se=3e4;function Ce(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function we(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:K,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA can be enrolled per-user from the Users page (added in v0.4).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:V,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:V,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:R,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:R,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:I,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Te(){let e=_({capName:`auth-provider`},{refetchInterval:Se}),t=s(void 0,{refetchInterval:Se}),n=C(()=>Ce(t.data??[]),[t.data]);return T(M,{title:`Authentication`,subtitle:`Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Disabling a provider only removes that external login method; local password login is unaffected. Each provider’s settings + live logs are inline below.`,pageIcon:I,itemIcon:I,capability:`auth-provider`,installButtonLabel:`Add provider`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,renderExpandedPanel:e=>T(Ee,{addonId:e.addonId})})}function Ee({addonId:e}){let t=we(e),n=t.icon;return D(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[D(`div`,{className:`flex items-start gap-2.5`,children:[T(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),T(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),T(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>T(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&D(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[D(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[T(G,{className:`h-3 w-3`}),`Setup steps`]}),T(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>T(`li`,{children:e},t))})]}),e===`local-auth`&&D(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[T(P,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),D(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,T(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”.`]})]})]})}function De(){return T(`div`,{className:`flex flex-col p-4`,children:T(W,{tabs:[{id:`users`,label:`Users`,icon:J,content:T(Y,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:T(ce,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:T(xe,{})},{id:`authentication`,label:`Authentication`,icon:I,content:T(Te,{})}]})})}export{De as IdentityPage};
@@ -1 +0,0 @@
1
- import{$t as e,Ai as t,Gn as n,J as r,Ji as i,Ln as a,R as o,Rn as s,Sn as c,Un as l,Vn as u,an as d,ca as f,cn as p,d as m,dt as ee,en as h,fn as g,g as _,hn as te,ji as v,nn as y,qt as ne,rn as b,tn as x,x as S,z as re,zn as ie}from"./src-C5tvi19O.js";import{F as C,G as w,R as T,U as E,W as D,X as O,b as k,o as A,x as j,y 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{p as N}from"./player-overlays-DzZKARlk.js";import{b as P}from"./src-CrhOk7JL.js";import{t as F}from"./ProviderIcon-BpqSF3Hu.js";import{t as I}from"./plus-DVpT3Ja2.js";import{t as L}from"./refresh-cw-BKhUNMXQ.js";import{t as R}from"./rotate-cw-BO4D9G2F.js";import{t as z}from"./wifi-DYJHTrlD.js";import{B,E as V,F as ae,H as oe,M as se,P as H,R as ce,T as U,U as le,f as W,i as G,o as K,p as ue,s as de,t as q,x as J}from"./index-CAfPe666.js";import{t as Y}from"./FormBuilder-DVLWBVys.js";import{t as X}from"./BrokerStep-B3pEVZ2L.js";var fe=B(`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`}]]);O();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]=w(`idle`),[a,o]=w({}),s=E(()=>{let t=[];for(let n of e.sections)t.push(...Z(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=C(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:C(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}}O();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}=q(),a=A(),[o,s]=w({}),[l,u]=w(!1),[d,f]=w(null),[m,ee]=w(Q),h=p({addonId:n,type:P.Camera},{enabled:e}),g=h.data??null;T(()=>{e&&(s(g?ge(g.sections.flatMap(e=>e.fields)):{}),ee(Q()),u(!1),f(null))},[e,t,g]);let te=E(()=>({...o,_probeRequestId:m}),[o,m]),v=y({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ne=c(),b=C(async(e,t)=>{u(!0);let r=await ne.mutateAsync({addonId:n,type:P.Camera,key:e,value:t,formValues:te});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},[ne,n,te]),{testAllStatus:x,hasProbeFields:S,probeResults:re,handleTestAll:ie,clearProbeResult:D}=pe(g??{sections:[]},o,b);async function O(e){f(null);try{await v.mutateAsync({addonId:n,type:P.Camera,config:o,integrationId:t}),e?s(g?ge(g.sections.flatMap(e=>e.fields)):{}):r()}catch(e){f(e instanceof Error?e.message:String(e))}}if(!e)return null;let M=me((g?.sections??[]).flatMap(e=>e.fields)).filter(e=>he(o[e])),N=M.length===0,F=!h.isLoading&&(h.isError||g===null);return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[k(`div`,{className:`absolute inset-0 bg-black/60`,onClick:r}),j(`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:[j(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[k(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`integrations.addDevice`)}),k(`button`,{onClick:r,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:k(G,{className:`h-4 w-4`})})]}),k(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:h.isLoading?k(`div`,{className:`flex items-center justify-center py-8`,children:k(J,{className:`h-5 w-5 animate-spin text-primary`})}):F?j(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[k(K,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),j(`div`,{className:`space-y-1`,children:[k(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),j(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,k(`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.`]})]})]}):k(Y,{schema:g,values:o,onChange:s,onTestField:b,probeResults:re,onClearProbe:D})}),!F&&!h.isLoading&&j(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[j(`button`,{type:`button`,onClick:()=>u(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:[j(`span`,{className:`flex items-center gap-2`,children:[k(ue,{className:`h-3.5 w-3.5`}),`Test logs`,k(`span`,{className:`font-mono text-[9px] opacity-60`,children:m.slice(0,14)})]}),k(H,{className:`h-3.5 w-3.5 transition-transform ${l?`rotate-180`:``}`})]}),l&&k(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:k(_,{addonId:n,requestId:m,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!F&&!h.isLoading&&(d||M.length>0)&&k(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:j(`div`,{className:`flex items-start gap-2`,children:[k(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),k(`p`,{className:`text-[11px] text-destructive`,children:d||`Required: ${M.join(`, `)}`})]})}),j(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[j(`div`,{className:`flex items-center gap-2`,children:[k(`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`)}),!F&&S&&j(`button`,{type:`button`,onClick:ie,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`?k(J,{className:`h-3.5 w-3.5 animate-spin`}):k(z,{className:`h-3.5 w-3.5`}),`Test All`]})]}),j(`div`,{className:`flex items-center gap-2`,children:[k(`button`,{onClick:()=>O(!0),disabled:F||!N||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`)}),k(`button`,{onClick:()=>O(!1),disabled:F||!N||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(` `)}O();var $=`devices`,ye={id:$,label:`Devices`,isDefault:!0},be=2e4,xe=100;function Se({addonId:n,integrationId:r,onClose:i}){let{t:a}=q(),[s,c]=w(new Set),[l,u]=w(new Set),[d,f]=w(new Map),[p,m]=w(null),{data:ee}=ie(),g=(ee??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[_,te]=w(!0),y=ne({integrationId:r}).data?.filters,b=y&&y.length>0?y:[ye],[S,re]=w(b.find(e=>e.isDefault)?.id??(b.some(e=>e.id===$)?$:b[0].id)),E=S!==$,O=x(),A=h({addonId:n,integrationId:r,page:1,pageSize:be,filter:S}),M=A.refetch,N=O.mutate,P=C(()=>{N({addonId:n,integrationId:r},{onSettled:()=>{M()}})},[N,n,r,M]),F=D(null);T(()=>{let e=`${n}::${r}`;F.current===e||A.isLoading||(F.current=e,(A.data?.candidates.length??0)===0&&P())},[n,r,A.isLoading,A.data,P]);let I=O.isPending,L=O.isError?O.error instanceof Error?O.error.message:String(O.error):null,z=A.data?.candidates??[],B=A.isError?A.error instanceof Error?A.error.message:String(A.error):null,V=e(),oe=C(e=>{e.alreadyAdopted||c(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),se=C(e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),H=C((e,t)=>{f(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})},[]),ce=C(e=>{let t={};for(let n of e){let e=d.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[d]),U=C(async()=>{m(null);let e=[...s];if(e.length!==0)try{let t=ce(e);await V.mutateAsync({addonId:n,integrationId:r,filter:S,childNativeIds:e,...t?{perCandidate:t}:{},...g?{importLocations:_}:{}}),c(new Set),f(new Map),await M(),i()}catch(e){m(e instanceof Error?e.message:String(e))}},[s,ce,V,n,r,S,M,g,_]),le=C(e=>{re(e),c(new Set),u(new Set),f(new Map),m(null)},[]),W=s.size;return j(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[k(`div`,{className:`absolute inset-0 bg-black/60`,onClick:i}),j(`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:[j(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[j(`div`,{className:`min-w-0`,children:[k(`h2`,{className:`text-sm font-semibold text-foreground`,children:a(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),k(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:a(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),j(`div`,{className:`flex items-center gap-3 shrink-0`,children:[g&&j(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[k(`input`,{type:`checkbox`,checked:_,onChange:e=>te(e.target.checked),className:`accent-primary`}),a(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),k(`button`,{onClick:i,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:k(G,{className:`h-4 w-4`})})]})]}),j(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(L??B)&&z.length===0&&k(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:j(`div`,{className:`flex items-start gap-2`,children:[k(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),j(`div`,{className:`min-w-0`,children:[k(`p`,{className:`text-xs font-medium text-destructive`,children:a(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),k(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:L??B})]})]})}),b.length>1&&k(Ce,{filters:b,activeFilter:S,onSelect:le}),k(`div`,{className:`flex-1 min-h-0`,children:k(o,{mode:`generic`,items:z,pageSize:xe,getKey:e=>e.childNativeId,getSearchText:ve,getFilterType:e=>e.type,filterOptions:t(),filterLabel:a(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:A.isLoading||I&&z.length===0,searchPlaceholder:a(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(L??B)&&z.length===0?``:a(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:j(`button`,{type:`button`,onClick:P,disabled:I,title:a(`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:[k(R,{className:`h-3.5 w-3.5 ${I?`animate-spin`:``}`}),a(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:a(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>k(we,{candidate:e,expandable:!E,expanded:l.has(e.childNativeId),onToggleExpand:()=>se(e.childNativeId),adoptedLabel:a(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:a(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=v(e.type),n=t.icon;return j(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[k(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=>k(`div`,{className:`flex items-center justify-end`,children:k(`button`,{onClick:()=>oe(e),disabled:e.alreadyAdopted,"aria-label":s.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${s.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:s.has(e.childNativeId)&&k(ae,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!E&&l.has(e.childNativeId),renderExpanded:E?void 0:e=>k(Te,{candidate:e,hiddenChildIds:d.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>H(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:s.has(e.childNativeId)?`bg-primary/5`:``})})]}),p&&k(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:j(`div`,{className:`flex items-start gap-2`,children:[k(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),k(`p`,{className:`text-[11px] text-destructive`,children:p})]})}),j(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[k(`div`,{}),j(`div`,{className:`flex items-center gap-2`,children:[k(`button`,{onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.cancel`,{defaultValue:`Cancel`})}),j(`button`,{onClick:U,disabled:W===0||V.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:[V.isPending&&k(J,{className:`h-3.5 w-3.5 animate-spin`}),a(`integrations.addSelected`,{defaultValue:`Add selected`}),W>0?` (${W})`:``]})]})]})]})]})}function Ce({filters:e,activeFilter:t,onSelect:n}){return k(`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 k(`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 j(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?j(`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:[k(n?H:se,{className:`h-3.5 w-3.5`}),a]}):k(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),k(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&k(`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:k(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return j(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[k(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&k(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),k(`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:k(r?V:U,{className:`h-3 w-3`})})]},e.childNativeId)})})}O();function Ee({integrationId:e,addonId:t,name:n,kind:r,brokerKind:i,trpc:a,onClose:o}){let{t:s}=q(),c=A(),d=r===`device-adoption`,{data:f}=u({id:e},{enabled:d}),p=E(()=>{let e=f?.brokerId;return typeof e==`string`?e:null},[f]),m=l();return k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:o,children:j(`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:[j(`div`,{className:`mb-3 flex items-center justify-between`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground`,children:[s(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),k(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":s(`common.close`,{defaultValue:`Close`}),children:k(G,{className:`h-4 w-4`})})]}),d?i?j(`div`,{className:`space-y-3`,children:[k(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),p&&j(`p`,{className:`text-[11px] text-foreground`,children:[s(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,k(`span`,{className:`font-mono text-foreground-subtle`,children:p})]}),m.isPending?j(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[k(J,{className:`h-3 w-3 animate-spin`}),s(`integrations.saving`,{defaultValue:`Saving…`})]}):k(X,{kind:i,onResolved:t=>{m.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{c.invalidateQueries(),o()}})},onBack:o}),m.isError&&k(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):k(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):k(S,{trpc:a,addonId:t,nodeId:`hub`,title:n})]})})}O();function De(){let{t:e}=q(),{integrationId:t}=le(),c=A(),l=oe(),u=N(),[p,h]=w(!1),[v,y]=w(!1),[ne,x]=w(!1),[S,T]=w(!1),{data:D,isLoading:O}=s({id:t??``},{enabled:!!t}),{data:P}=r({addonId:D?.addonId??``,nodeId:`hub`},{enabled:!!D?.addonId}),{data:R,isSuccess:z}=ie(),B=E(()=>{let e=D?.addonId;return!e||!z?null:(R??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[R,D?.addonId,z]),V=B!==null,ae=V?B===`device-adoption`?e(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):e(`integrations.addDevice`):e(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),se=E(()=>{let e=D?.addonId;return!e||!z?null:(R??[]).find(t=>t.addonId===e)?.brokerKind??null},[R,D?.addonId,z]),H=P!=null&&Array.isArray(P.sections)&&P.sections.some(e=>e.fields.length>0),{data:U}=g({},{refetchInterval:5e3}),Y=[[`integrations`,`get`],{input:{id:t??``},type:`query`}],X=n({onMutate:async e=>{await c.cancelQueries({queryKey:Y});let t=c.getQueryData(Y);return t!=null&&c.setQueryData(Y,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&c.setQueryData(Y,r.previous)},onSettled:()=>{c.invalidateQueries({queryKey:[[`integrations`]]}),c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=a({onSuccess:()=>{c.invalidateQueries({queryKey:[[`integrations`]]}),c.invalidateQueries({queryKey:[[`deviceManager`]]}),x(!1),l(`/integrations`)}}),pe=ee({onSuccess:()=>{c.invalidateQueries({queryKey:[[`integrations`]]}),c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),me=te({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),he=b({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ge=d({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=E(()=>U??[],[U]),ve=E(()=>{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]),$=C(e=>ve.get(e)??null,[ve]),ye=C(e=>k(F,{type:e,size:`sm`}),[]),be=C(e=>l(`/devices/${String(e)}`),[l]),xe=E(()=>{let e=D?.addonId;return e?Q.filter(t=>t.addonId===e):[]},[Q,D?.addonId]),Ce=E(()=>re(xe).length,[xe]);return O?j(`div`,{className:`p-4`,children:[k(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),k(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):D?j(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[k(i,{items:[{label:`Integrations`,onClick:()=>l(`/integrations`)},{label:D.name}]}),j(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[j(`div`,{className:`flex items-center gap-3 min-w-0`,children:[k(`img`,{src:`/api/addon-assets/${D.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),j(`div`,{className:`min-w-0`,children:[k(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:D.name}),j(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[D.addonId,` · `,Ce,` `,e(`integrations.devices`)]})]})]}),j(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[j(`button`,{onClick:()=>h(!0),disabled:!V,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:ae,children:[k(I,{className:`h-3.5 w-3.5`}),ae]}),j(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${X.isPending?`opacity-60`:``} ${D.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[k(f,{checked:D.enabled,onCheckedChange:e=>X.mutate({id:t,enabled:e}),disabled:X.isPending,"aria-label":D.enabled?`Disable integration`:`Enable integration`}),k(`span`,{className:`text-[11px] font-medium ${D.enabled?`text-success`:`text-foreground-subtle`}`,children:D.enabled?`Enabled`:`Disabled`}),X.isPending&&k(J,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),(H||B===`device-adoption`)&&j(`button`,{onClick:()=>y(!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:[k(W,{className:`h-3 w-3`}),e(`integrations.config`)]}),j(`button`,{onClick:()=>T(!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:[k(ue,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),k(m,{label:`Restart`,icon:L,title:`Restart "${D.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:D.addonId})}),j(`button`,{onClick:()=>x(!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:[k(de,{className:`h-3 w-3`}),e(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),k(o,{context:`integration-detail`,devices:Q,trpc:u.trpcClient,defaultView:`cards`,forceAddon:D.addonId,urlScope:`root`,lsKey:`integration-detail:${D.addonId}`,resolveIntegrationIcon:ye,resolveParent:$,onNavigate:be,batchActions:{remove:me.mutate,disable:he.mutate,enable:ge.mutate},onDeleteDevice:e=>me.mutate({deviceId:e.id})}),p&&t&&B===`device-adoption`&&k(Se,{addonId:D.addonId,integrationId:t,onClose:()=>h(!1)}),p&&t&&B===`device-provider`&&k(_e,{open:p,integrationId:t,addonId:D.addonId,onClose:()=>h(!1)}),v&&t&&B!==null&&k(Ee,{integrationId:t,addonId:D.addonId,name:D.name,kind:B,brokerKind:se,trpc:u.trpcClient,onClose:()=>y(!1)}),S&&k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>T(!1),children:j(`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:[j(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[j(`div`,{className:`flex items-center gap-2 min-w-0`,children:[k(ue,{className:`h-4 w-4 text-primary shrink-0`}),k(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:D.name}),j(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[D.addonId,t?` · ${t}`:``]})]}),k(`button`,{onClick:()=>T(!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:k(G,{className:`h-4 w-4`})})]}),k(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:k(_,{addonId:D.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),ne&&k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Z.isPending&&x(!1),children:j(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[j(`div`,{className:`flex items-start gap-3`,children:[k(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:k(K,{className:`h-4 w-4 text-danger`})}),j(`div`,{className:`min-w-0`,children:[k(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),k(`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:D.name,count:Ce})})]})]}),Z.error&&k(`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)}),j(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[k(`button`,{onClick:()=>x(!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`})}),k(`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?j(M,{children:[k(J,{className:`h-3 w-3 animate-spin`}),e(`integrations.deleting`,{defaultValue:`Deleting…`})]}):j(M,{children:[k(de,{className:`h-3 w-3`}),e(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):j(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[k(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:k(fe,{className:`h-6 w-6 text-foreground-subtle`})}),j(`div`,{className:`space-y-1 max-w-sm`,children:[k(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),k(`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??``})})]}),j(`button`,{onClick:()=>l(`/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:[k(ce,{className:`h-3 w-3`}),e(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{De as IntegrationDetailPage};
@@ -1 +0,0 @@
1
- import{$r as e,Ar as t,Bi as n,Br as r,Cr as i,Er as a,Fr as o,Gi as s,Hi as c,Hr as l,J as u,Ki as d,Kr as f,Li as p,Ni as m,Nr as h,Or as g,Pr as _,Qr as v,Ri as y,Rr as b,Sr as x,Tr as S,Ui as C,Ur as w,Vr as T,X as E,Zr as D,_ as O,_a as k,ai as A,br as j,ci as ee,ei as M,ii as N,jr as P,kr as F,ni as I,oi as te,vr as L,w as ne,wr as re,xr as ie,zi as ae}from"./src-C5tvi19O.js";import{F as oe,G as R,R as z,U as B,W as se,X as V,a as ce,b as H,o as U,w as le,x as W,y as G}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 ue}from"./player-overlays-DzZKARlk.js";import{O as de}from"./src-CrhOk7JL.js";import{t as fe}from"./download-DyMeaCfZ.js";import{i as pe,n as me,r as he,t as ge}from"./AddLocationWizard-ty_4uW1H.js";import{n as _e,r as ve,t as ye}from"./zap-DLiiHws-.js";import{t as be}from"./pencil-xW8n5CLs.js";import{t as xe}from"./plus-DVpT3Ja2.js";import{t as Se}from"./refresh-cw-BKhUNMXQ.js";import{t as Ce}from"./search-DyWYI0Yj.js";import{t as we}from"./server-X3K4ldX4.js";import{t as Te}from"./square-check-big-Bzz95oCZ.js";import{t as Ee}from"./square-Faey8y7b.js";import{A as De,B as K,F as Oe,M as ke,P as Ae,W as je,i as Me,j as Ne,k as q,s as J,w as Pe,x as Y}from"./index-CAfPe666.js";import{t as Fe}from"./AdminPage-CN6ZMhf0.js";import{r as Ie}from"./useDevice-B7VwJa4X.js";import{t as X}from"./useEventInvalidation-Cf9VIpDW.js";import{n as Le}from"./format-size-CO9d3C3-.js";import{t as Re}from"./NodeAddonsSettingsPanel-B4ru8rzf.js";var ze=K(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),Be=K(`film`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M7 3v18`,key:`bbkbws`}],[`path`,{d:`M3 7.5h4`,key:`zfgn84`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`path`,{d:`M3 16.5h4`,key:`1230mu`}],[`path`,{d:`M17 3v18`,key:`in4fa5`}],[`path`,{d:`M17 7.5h4`,key:`myr1c1`}],[`path`,{d:`M17 16.5h4`,key:`go4c1d`}]]),Ve=K(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),He=K(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);V();function Ue({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:i}=L(void 0),{data:a}=r(void 0),o=new Map;for(let e of a??[])o.set(e.agentNodeId,(o.get(e.agentNodeId)??0)+1);let s=i??[],c=s.filter(e=>e.isOnline).length,l=s.filter(e=>!e.isOnline).length;return W(`div`,{className:`flex flex-col h-full`,children:[W(`button`,{type:`button`,onClick:()=>t(Pt),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[H(Pe,{className:`h-4 w-4 flex-shrink-0`}),W(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),H(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),H(`div`,{className:`flex-1 overflow-y-auto`,children:s.map(n=>{let r=e===n.id,i=o.get(n.id)??0,a=n.isHub?we:q;return W(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[H(a,{className:`h-4 w-4 flex-shrink-0`}),W(`div`,{className:`min-w-0 flex-1`,children:[W(`div`,{className:`flex items-center gap-2`,children:[H(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&H(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&H(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&H(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),W(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[W(`span`,{children:[n.cpuCores,` cores`]}),H(`span`,{children:`•`}),W(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),i>0&&W(G,{children:[H(`span`,{children:`•`}),W(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[H(_e,{className:`h-2.5 w-2.5`}),i]})]})]})]})]},n.id)})}),W(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[W(`span`,{children:[c,` online`]}),l>0&&W(`span`,{className:`text-destructive`,children:[l,` offline`]})]})]})}function We({nodeId:e,refreshToken:t}){let{data:n}=L(void 0),r=n?.find(t=>t.id===e),i=y(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?W(`div`,{className:`px-6 py-4 border-b border-border`,children:[W(`div`,{className:`flex items-center gap-2 mb-1`,children:[H(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?H(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):H(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&H(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),W(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[H(`span`,{children:r.cpuModel??`CPU`}),H(`span`,{children:`•`}),W(`span`,{children:[r.cpuCores,` cores`]}),H(`span`,{children:`•`}),W(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),i&&W(G,{children:[H(`span`,{children:`•`}),W(`span`,{children:[i.attachedCameras,` cameras (`,i.activeCameras,` active)`]}),H(`span`,{children:`•`}),W(`span`,{children:[i.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),H(`span`,{children:`•`}),W(`span`,{children:[`queue `,i.queueDepthTotal]}),i.hardware.hasGpu&&W(G,{children:[H(`span`,{children:`•`}),H(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):H(`div`,{className:`px-6 py-4 border-b border-border`,children:W(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function Ge({refreshToken:e,nodeId:t}){let[r,i]=R(new Map),{nodes:a}=p();n(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&i(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=o(void 0),c=B(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),l=B(()=>{let e=new Map,t=Date.now()-3e4;for(let n of r.values()){if(n.timestamp<t)continue;let r=n.nodeId??`hub`,i=e.get(r)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,n.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=n.metrics.actualFps,i.totalInferenceWeighted+=n.metrics.avgInferenceTimeMs,i.queueDepth+=n.metrics.queueDepth,e.set(r,i)}return e},[r]),u=B(()=>{let e=new Map;for(let t of a)e.set(t.id,t.shortName);return e},[a]),d=B(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of l.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let o=e>0?r/e:0;return{totalAgents:a.length,onlineAgents:a.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:o,queueDepth:i,totalFps:n}},[l,a]);if(t){let e=l.get(t);return W(`div`,{className:`@container/liveload`,children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),W(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[H(Z,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),H(Z,{label:`Cameras`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),H(Z,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),H(Z,{label:`Queue`,value:e?String(e.queueDepth):`—`}),H(Z,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let f=[...l.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return W(`div`,{className:`@container/liveload`,children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),W(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[H(Z,{label:`Total agents`,value:`${d.onlineAgents}/${d.totalAgents}`}),H(Z,{label:`Cameras`,value:`${d.activeCameras}/${d.attachedCameras}`}),H(Z,{label:`Total FPS`,value:d.totalFps.toFixed(1)}),H(Z,{label:`Avg inference ms`,value:d.avgInferenceTimeMs.toFixed(0)}),H(Z,{label:`Queue depth`,value:String(d.queueDepth)})]}),H(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:W(`table`,{className:`w-full text-xs min-w-[480px]`,children:[H(`thead`,{className:`bg-surface`,children:W(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[H(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),H(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),H(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),H(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),H(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),H(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),W(`tbody`,{children:[f.map(([e,t])=>W(`tr`,{className:`border-t border-border`,children:[H(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:u.get(e)??e}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),f.length===0&&H(`tr`,{children:H(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function Z({label:e,value:t}){return W(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[H(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),H(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}V();var Q={active:!1,pinned:!1,nodeId:null,reason:``},Ke=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],qe={pipeline:q,decoder:Be,audio:ve},Je={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function Ye({mode:i,nodeId:a,compact:o=!1}){if(i===`agent`&&!a)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let s=U(),[c,l]=R(null),[u,d]=R(null),[f,m]=R(new Map);X([`pipelineOrchestrator`,`getPipelineAssignments`],Ke),X([`pipelineOrchestrator`,`getDecoderAssignments`],Ke),X([`pipelineOrchestrator`,`getAudioAssignments`],Ke);let{data:h}=r(void 0),{data:y}=b(void 0),{data:x}=_(void 0),{nodes:S}=p(),{data:C}=Ie();n(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&m(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),z(()=>{if(f.size===0)return;let e=setInterval(()=>{m(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[f.size]);let w=B(()=>{let e=new Map;for(let t of C??[])e.set(t.id,t.name);return e},[C]),T=B(()=>{let e=new Map,t=t=>{let n=e.get(t);if(n)return n;let r={deviceId:t,deviceName:w.get(t)??`Device ${t}`,pipeline:Q,decoder:Q,audio:Q};return e.set(t,r),r};for(let n of h??[]){let r=t(n.deviceId);e.set(n.deviceId,{...r,pipeline:{active:i===`cluster`?!0:n.agentNodeId===a,pinned:n.pinned,nodeId:n.agentNodeId,reason:n.reason??``}})}for(let n of y??[]){let r=t(n.deviceId);e.set(n.deviceId,{...r,decoder:{active:i===`cluster`?!0:n.decoderNodeId===a,pinned:n.pinned,nodeId:n.decoderNodeId,reason:n.reason??``}})}for(let n of x??[]){let r=t(n.deviceId);e.set(n.deviceId,{...r,audio:{active:i===`cluster`?!0:n.nodeId===a,pinned:n.pinned,nodeId:n.nodeId,reason:`capacity`}})}let n=[...e.values()];return i===`agent`&&(n=n.filter(e=>e.pipeline.active||e.decoder.active||e.audio.active)),n.sort((e,t)=>e.deviceId-t.deviceId),n},[h,y,x,w,i,a]),E=B(()=>(S??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[S]),O=()=>{s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})},k=t({onSuccess:O}),A=e({onSuccess:O}),j=F({onSuccess:O}),ee=v({onSuccess:O}),M=g({onSuccess:O}),N=D({onSuccess:O}),P=(e,t,n)=>{t===`pipeline`?k.mutate({deviceId:e,agentNodeId:n}):t===`decoder`?j.mutate({deviceId:e,nodeId:n}):M.mutate({deviceId:e,nodeId:n}),l(null)},I=(e,t)=>{t===`pipeline`?A.mutate({deviceId:e}):t===`decoder`?ee.mutate({deviceId:e}):N.mutate({deviceId:e}),l(null)};return H(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:W(`table`,{className:`w-full text-xs min-w-[640px]`,children:[H(`thead`,{className:`bg-surface`,children:W(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!o&&H(`th`,{className:`w-6`}),H(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Camera`}),H(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Pipeline`}),H(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Decoder`}),H(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Audio`}),H(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Status`})]})}),W(`tbody`,{children:[T.map(e=>{let t=f.get(e.deviceId),n=u===e.deviceId;return W(le.Fragment,{children:[W(`tr`,{className:`border-t border-border align-middle relative`,children:[!o&&H(`td`,{className:`px-2 py-2 align-middle`,children:H(`button`,{type:`button`,onClick:()=>d(n?null:e.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":n?`Collapse broker details`:`Expand broker details`,children:H(n?Ae:ke,{className:`h-3.5 w-3.5`})})}),W(`td`,{className:`px-3 py-2 align-middle`,children:[H(`div`,{className:`text-foreground font-medium leading-tight`,children:e.deviceName}),W(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,e.deviceId]})]}),H(Xe,{role:`pipeline`,state:e.pipeline,mode:i,deviceId:e.deviceId,onlineNodes:E,isMenuOpen:c?.deviceId===e.deviceId&&c.role===`pipeline`,onToggleMenu:()=>l(c?.deviceId===e.deviceId&&c.role===`pipeline`?null:{deviceId:e.deviceId,role:`pipeline`}),onCloseMenu:()=>l(null),onMove:t=>P(e.deviceId,`pipeline`,t),onUnpin:()=>I(e.deviceId,`pipeline`)}),H(Xe,{role:`decoder`,state:e.decoder,mode:i,deviceId:e.deviceId,onlineNodes:E,isMenuOpen:c?.deviceId===e.deviceId&&c.role===`decoder`,onToggleMenu:()=>l(c?.deviceId===e.deviceId&&c.role===`decoder`?null:{deviceId:e.deviceId,role:`decoder`}),onCloseMenu:()=>l(null),onMove:t=>P(e.deviceId,`decoder`,t),onUnpin:()=>I(e.deviceId,`decoder`)}),H(Xe,{role:`audio`,state:e.audio,mode:i,deviceId:e.deviceId,onlineNodes:E,isMenuOpen:c?.deviceId===e.deviceId&&c.role===`audio`,onToggleMenu:()=>l(c?.deviceId===e.deviceId&&c.role===`audio`?null:{deviceId:e.deviceId,role:`audio`}),onCloseMenu:()=>l(null),onMove:t=>P(e.deviceId,`audio`,t),onUnpin:()=>I(e.deviceId,`audio`)}),H(`td`,{className:`px-3 py-2 align-middle`,children:H($e,{snap:t})})]}),n&&!o&&W(`tr`,{className:`bg-surface/50`,children:[H(`td`,{}),H(`td`,{colSpan:5,className:`px-3 py-2`,children:H(ne,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:e.deviceId,instanceId:`pipeline-row/${e.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})})]})]},e.deviceId)}),T.length===0&&H(`tr`,{children:H(`td`,{colSpan:o?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:i===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function Xe({role:e,state:t,mode:n,onlineNodes:r,isMenuOpen:i,onToggleMenu:a,onCloseMenu:o,onMove:s,onUnpin:c}){let l=qe[e],u=r.filter(e=>e.id!==(t.nodeId??``)),d=(t.active||n===`cluster`)&&(u.length>0||t.pinned);return W(`td`,{className:`px-3 py-2 align-middle relative`,children:[W(`div`,{className:`flex items-center gap-2`,children:[H(n===`agent`?Ze:Qe,{state:t,Icon:l}),H(`div`,{className:`ml-auto`,children:d&&H(`button`,{type:`button`,onClick:a,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${Je[e]} actions`,children:H(ze,{className:`h-3 w-3 text-foreground-subtle`})})})]}),i&&d&&H(et,{title:Je[e],targets:u,pinned:t.pinned,onMove:s,onUnpin:c,onClose:o})]})}function Ze({state:e,Icon:t}){return W(`div`,{className:`flex items-center gap-1.5`,children:[H(e.active?Te:Ee,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),H(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&H(He,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Qe({state:e,Icon:t}){return!e.active||!e.nodeId?W(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[H(t,{className:`h-3 w-3`}),H(`span`,{className:`text-[10px] italic`,children:`—`})]}):W(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[H(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),W(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[H(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),H(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?W(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[H(He,{className:`h-2.5 w-2.5`}),` manual`]}):W(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}function $e({snap:e}){if(!e)return H(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:i,configuredFps:a}=e.metrics,o=k(t);return W(`div`,{className:`flex flex-col gap-0.5 font-mono text-[10px] tabular-nums leading-tight`,children:[W(`span`,{className:`inline-flex items-center gap-1 ${o.textColor}`,children:[H(O,{phase:t,className:`h-2.5 w-2.5`}),H(`span`,{className:`font-semibold uppercase tracking-wider`,children:o.label})]}),W(`span`,{className:`text-foreground-subtle`,children:[H(`span`,{className:`text-foreground`,children:n.toFixed(1)}),W(`span`,{children:[`/`,a.toFixed(0),` fps`]})]}),W(`span`,{className:`text-foreground-subtle`,children:[H(`span`,{className:`text-foreground`,children:r.toFixed(0)}),H(`span`,{children:` ms`}),i>0&&W(`span`,{className:`text-warning ml-1`,children:[`q`,i]})]})]})}function et({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=se(null);return z(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),W(`div`,{ref:o,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[H(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&H(`div`,{className:`py-1`,children:t.map(e=>W(`button`,{type:`button`,onClick:()=>r(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),n&&W(`button`,{type:`button`,onClick:i,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,e.toLowerCase()]}),t.length===0&&!n&&H(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function tt({nodeId:e,refreshToken:t}){return W(`div`,{className:`space-y-6`,children:[H(Ge,{refreshToken:t,nodeId:e}),W(`div`,{children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),W(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),H(Ye,{mode:`agent`,nodeId:e,compact:!0})]})}V();function nt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function rt({nodeId:e,refreshToken:t}){let n=U(),r=S({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:i}=a({nodeId:e}),o=y(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??i??null,s=o===null;X([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:c}=I({nodeId:e}),{values:l}=ae(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),u=B(()=>l.filter(e=>e.metrics.phase===`active`).length,[l]),d=t=>{let n=c??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||r.mutate({nodeId:e,engine:t,force:n.length>0})};return W(`div`,{className:`space-y-6`,children:[W(`div`,{children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),W(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(o??[]).length,` engine(s) resident in RAM. `,(c??[]).length,` `,`camera(s) attached, `,u,` actively dispatching frames. Refreshes every 5s.`]})]}),H(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:W(`table`,{className:`w-full text-xs min-w-[640px]`,children:[H(`thead`,{className:`bg-surface`,children:W(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[H(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),H(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),H(`th`,{className:`text-left px-3 py-2`,children:`Models`}),H(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),H(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),H(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),H(`th`,{className:`w-20`})]})}),W(`tbody`,{children:[s&&H(`tr`,{children:H(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!s&&(o??[]).map(e=>{let t=e.kind===`warm-override`;return W(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:``}`,children:[H(`td`,{className:`px-3 py-2`,children:W(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:`bg-success/15 text-success`}`,children:[H(t?Ve:q,{className:`h-3 w-3`}),t?`warm`:`runtime`]})}),H(`td`,{className:`px-3 py-2`,children:W(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[H(ye,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),H(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?H(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):H(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>H(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),H(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),H(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?H(`span`,{className:`text-foreground-subtle`,children:nt(e.idleMs,e.idleTtlMs)}):H(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(c??[]).length}),H(`td`,{className:`px-3 py-2 text-right`,children:W(`button`,{type:`button`,disabled:r.isPending,onClick:()=>d(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[H(J,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!s&&(o??[]).length===0&&H(`tr`,{children:H(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),W(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[H(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,H(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`]}),r.isError&&W(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,r.error instanceof Error?r.error.message:`unknown`]})]})}V();var it=new Set(de);function at(e){return it.has(e)}function ot(e,t,n){return`${e}/${t}/${n}`}function st(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function ct(e){return{coreml:`Apple Neural Engine / GPU — .mlpackage`,openvino:`Intel CPU / GPU / NPU — .xml`,onnx:`CPU, CUDA, Node.js — .onnx`}[e.format]??`.${e.format}`}function $(e){return e.format}function lt(e,t){let n=0,r=0,i=0;for(let a of e)for(let e of a.addons)for(let a of e.models){let e=a.formats[t];e&&(n++,e.downloaded&&(r++,i+=e.sizeMB))}return{total:n,downloaded:r,downloadedSizeMB:i}}function ut({addonId:e,model:t,format:n,isActive:r,progress:i,errorMsg:a,onDownload:o,onDelete:s}){let c=t.formats[n];return c?W(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors`,children:[H(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),W(`div`,{className:`flex-1 min-w-0`,children:[W(`div`,{className:`flex items-center gap-2`,children:[H(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),W(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&W(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[H(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:H(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),W(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),H(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:Le(c.sizeMB)}),a&&W(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[H(Ne,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?W(`button`,{onClick:s,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[r?H(Y,{className:`h-3 w-3 animate-spin`}):H(J,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):W(`button`,{onClick:o,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[r?H(Y,{className:`h-3 w-3 animate-spin`}):H(fe,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function dt({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=R(!1);return W(`div`,{className:`relative`,children:[W(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[H(q,{className:`h-4 w-4 text-primary shrink-0`}),W(`div`,{className:`flex-1 min-w-0`,children:[W(`div`,{className:`flex items-center gap-2`,children:[H(`span`,{className:`text-sm font-medium text-foreground`,children:st(n)}),$(n)===$(t)&&H(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),H(`div`,{className:`text-[10px] text-foreground-subtle`,children:ct(n)})]}),H(Ae,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&H(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let i=$(e)===$(n),o=$(e)===$(t);return W(`button`,{type:`button`,onClick:()=>{r(e),a(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${i?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[H(q,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),W(`div`,{className:`flex-1`,children:[W(`div`,{className:`flex items-center gap-2`,children:[H(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:st(e)}),o&&H(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),H(`div`,{className:`text-[10px] text-foreground-subtle`,children:ct(e)})]}),i&&H(De,{className:`h-4 w-4 text-primary shrink-0`})]},$(e))})})]})}function ft({embedded:e=!1,nodeId:t}={}){let r=U(),a=t??`hub`,[o,s]=R(null),[c,l]=R(new Set),[u,d]=R(new Map),[f,p]=R(new Map),[m,h]=R(``),{data:g=[]}=x({nodeId:a}),_=g.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:v}=re({nodeId:a}),y=v,{data:b,isLoading:S}=i({nodeId:a}),C=ie(),w=j();n(`model.download.progress`,e=>{let t=e.data,n=typeof t.modelId==`string`?t.modelId:void 0,i=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;n===void 0||i===void 0||(d(e=>{let t=new Map(e);return i===100||i===-1?t.delete(n):t.set(n,{modelId:n,progress:i,totalMB:a}),t}),i===100&&r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let T=y??{runtime:`node`,backend:`cpu`,format:`onnx`},E=_.find(e=>e.format===o)??T,D=E.format,O=b?.slots??[],k=O.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(e=>e.formats[D]!==void 0)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),A=lt(k,D),ee=oe(async(e,t,n)=>{if(!at(n))return;let i=ot(e,t,n);l(e=>new Set([...e,i])),p(e=>{let t=new Map(e);return t.delete(i),t});try{await C.mutateAsync({addonId:e,modelId:t,format:n,nodeId:a}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(t=>new Map([...t,[i,e instanceof Error?e.message:`Download failed`]]))}finally{l(e=>{let t=new Set(e);return t.delete(i),t})}},[C,r,a]),M=oe(async(e,t,n)=>{if(!at(n))return;let i=ot(e,t,n);l(e=>new Set([...e,i])),p(e=>{let t=new Map(e);return t.delete(i),t});try{await w.mutateAsync({addonId:e,modelId:t,format:n,nodeId:a}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(t=>new Map([...t,[i,e instanceof Error?e.message:`Delete failed`]]))}finally{l(e=>{let t=new Set(e);return t.delete(i),t})}},[w,r,a]),N=oe(e=>{s(e.format)},[]),P=m.trim()?k.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(m.toLowerCase())||t.id.toLowerCase().includes(m.toLowerCase())||e.name.toLowerCase().includes(m.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):k,F=W(G,{children:[S&&H(`div`,{className:`flex items-center justify-center py-16`,children:H(Y,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!S&&O.length===0&&W(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[H(pe,{className:`h-8 w-8 mb-3 opacity-30`}),H(`span`,{className:`text-sm`,children:`No pipeline steps available`}),H(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!S&&O.length>0&&W(G,{children:[H(dt,{engines:_,activeEngine:T,viewEngine:E,onSelect:N}),W(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[W(`span`,{children:[H(`span`,{className:`font-semibold text-foreground tabular-nums`,children:A.total}),H(`span`,{className:`ml-1`,children:`compatible models`})]}),H(`span`,{className:`text-border`,children:`|`}),W(`span`,{children:[H(`span`,{className:`font-semibold text-success tabular-nums`,children:A.downloaded}),H(`span`,{className:`ml-1`,children:`downloaded`})]}),H(`span`,{className:`text-border`,children:`|`}),W(`span`,{className:`tabular-nums`,children:[Le(A.downloadedSizeMB),H(`span`,{className:`ml-1`,children:`on disk`})]})]}),A.total>5&&W(`div`,{className:`relative`,children:[H(Ce,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),H(`input`,{type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:`Search models...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary`})]}),P.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+t.models.filter(e=>e.formats[D]?.downloaded).length,0);return W(`div`,{children:[W(`div`,{className:`flex items-center gap-2 mb-2`,children:[H(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),H(`div`,{className:`flex-1 h-px bg-border`}),W(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=ot(e.id,t.id,D);return H(ut,{addonId:e.id,model:t,format:D,isActive:c.has(n),progress:u.get(t.id),errorMsg:f.get(n),onDownload:()=>ee(e.id,t.id,D),onDelete:()=>M(e.id,t.id,D)},`${e.id}/${t.id}`)}))})]},e.id)}),P.length===0&&H(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:m.trim()?W(G,{children:[`No models matching “`,m,`”`]}):W(G,{children:[`No models available for `,st(E),` format`]})})]})]});return e?H(`div`,{className:`space-y-4`,children:F}):H(Fe,{children:F})}function pt({nodeId:e,refreshToken:t}){return H(ft,{embedded:!0,nodeId:e})}V();function mt({nodeId:e,title:t}){let{data:i}=Ie(),{data:a}=r(void 0),o=B(()=>{let e=new Map;for(let t of i??[])e.set(t.id,t.name);return e},[i]),s=B(()=>{if(!e)return null;let t=new Set;for(let n of a??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,a]),[c,l]=R(new Map);n(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||l(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),z(()=>{if(c.size===0)return;let e=setInterval(()=>{l(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[c.size]);let u=B(()=>{let e=[];for(let t of c.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[c,s]);return u.length===0?W(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):W(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[W(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[H(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),H(`span`,{className:`text-[10px] text-foreground-subtle`,children:u.length})]}),H(`div`,{className:`flex flex-wrap gap-1.5`,children:u.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,n=k(e.metrics.phase);return W(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[H(O,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),H(`span`,{className:`font-medium text-foreground/90 max-w-[120px] truncate`,children:t}),H(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),H(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}V();function ht(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 gt({nodeId:e,refreshToken:t}){let n=U(),[r,a]=R(null),[o,l]=R(null),u=i({nodeId:e},{refetchOnMount:`always`}),p=h({agentNodeId:e},{refetchOnMount:`always`}),m=f({onSuccess:()=>{n.invalidateQueries({queryKey:[[`addonSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`pipelineExecutor`]]})}}),g=u.data??null,_=p.data,v=g?.selectedEngine.format??`coreml`,y=B(()=>g?s(g):[],[g]),b=B(()=>[{agentNodeId:e,engineLabel:v}],[e,v]),x=(e,t)=>{let n=_?.addonDefaults[e];return!ht(g,e)?.models.some(e=>!!e.formats[v])||!n?{kind:`na`}:n.enabled?{kind:`enabled`,modelId:n.modelId}:{kind:`disabled`}},S=r&&g?ht(g,r.addonId):null,w=t=>{let n=_?.addonDefaults[t]??null;a({addonId:t,agentNodeId:e}),l(n)},T=(t,n)=>{if(!_)return;let r=_.addonDefaults[t],i=ht(g,t);if(!r&&!i)return;let a={enabled:n,modelId:r?.modelId??i?.defaultModelId??``,settings:r?.settings??{}};m.mutate({agentNodeId:e,defaults:{..._.addonDefaults,[t]:a}})},E=()=>{a(null),l(null)},D=()=>{!o||!r||!_||m.mutate({agentNodeId:e,defaults:{..._.addonDefaults,[r.addonId]:o}},{onSuccess:E})};if(u.isLoading||p.isLoading)return H(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading pipeline…`});if(u.error)return W(`div`,{className:`text-xs text-red-400`,children:[`Failed to load catalog: `,String(u.error)]});if(!g)return H(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog unavailable for this node (runner offline?).`});let O=r!==null&&S!==null&&o!==null;return W(`div`,{className:`relative h-full w-full space-y-3`,children:[H(mt,{nodeId:e}),H(`div`,{className:O?`pr-[360px]`:``,children:y.length>0?H(c,{tree:y,agents:b,getCellState:x,onCellClick:w,selectedCell:r,onToggleEnabled:T}):H(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),H(d,{open:O,onClose:E,title:S?.name??``,subtitle:r?`${r.agentNodeId} · ${v}`:``,footer:W(G,{children:[H(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:E,children:`Cancel`}),H(`button`,{type:`button`,disabled:!o||!r||m.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:D,children:m.isPending?`Saving…`:`Save`})]}),children:S&&o&&r&&H(C,{mode:`agent`,addon:S,agentDefault:o,agentNodeId:r.agentNodeId,engineFormat:v,onChangeAgentConfig:e=>l(e)})})]})}var _t=[`detection-pipeline`,`decoder-nodeav`,`audio-analyzer`,`pipeline-runner`];function vt({nodeId:e,refreshToken:t}){return W(`div`,{className:`flex flex-col h-full`,children:[H(We,{nodeId:e,refreshToken:t}),H(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:H(Re,{nodeId:e,addonIds:_t,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:H(tt,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:H(gt,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:H(rt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:H(pt,{nodeId:e,refreshToken:t})}]})})]})}function yt({refreshToken:e}){let t=U(),n=w({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return W(`div`,{className:`space-y-6`,children:[H(Ge,{refreshToken:e}),W(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[W(`div`,{className:`min-w-0`,children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),H(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · decoder · audio assignments per camera. Click the kebab to pin / unpin / move any role; expand the chevron for the per-camera broker drill-down.`})]}),W(`button`,{type:`button`,onClick:()=>n.mutate(void 0),disabled:n.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[H(ye,{className:`h-3.5 w-3.5`}),n.isPending?`Rebalancing…`:`Rebalance pipelines`]})]}),H(Ye,{mode:`cluster`})]})}var bt=[`pipeline-orchestrator`];function xt({refreshToken:e}){return H(`div`,{className:`space-y-4 max-w-3xl`,children:H(Re,{nodeId:`hub`,addonIds:bt,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer thresholds, and failover policy. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`})})}V();function St({refreshToken:e}){let t=U(),{data:n,isLoading:r}=l(),[i,a]=R(null),[o,s]=R(``),[c,u]=R(``),d=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},f=M({onSuccess:()=>{a(null),d()}}),p=P({onSuccess:d}),m=e=>{a(e.id),s(e.name),u(e.description??``)},h=()=>{a(null),s(``),u(``)},g=()=>{if(!i)return;let e=c.trim();f.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return H(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let _=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return H(`div`,{className:`space-y-6 max-w-4xl`,children:W(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[W(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[W(`div`,{children:[H(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),H(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),W(`div`,{className:`text-[11px] text-foreground-subtle`,children:[_.length,` template`,_.length===1?``:`s`]})]}),_.length===0?W(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[H(xe,{className:`h-6 w-6 opacity-40`}),H(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):H(`ul`,{className:`divide-y divide-border`,children:_.map(e=>{let t=i===e.id;return H(`li`,{className:`px-4 py-3 text-xs`,children:W(`div`,{className:`flex items-start gap-3`,children:[H(`div`,{className:`flex-1 min-w-0`,children:t?W(`div`,{className:`space-y-2`,children:[H(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:o,onChange:e=>s(e.target.value),placeholder:`Template name`,autoFocus:!0}),H(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:c,onChange:e=>u(e.target.value),placeholder:`Description (optional)`})]}):W(G,{children:[H(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&H(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),W(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[`engine `,e.config.engine.runtime,`/`,e.config.engine.backend,` ·`,` `,e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,W(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?W(G,{children:[W(`button`,{type:`button`,onClick:g,disabled:f.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[H(Oe,{className:`h-3 w-3`}),`Save`]}),W(`button`,{type:`button`,onClick:h,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[H(Me,{className:`h-3 w-3`}),`Cancel`]})]}):W(G,{children:[H(`button`,{type:`button`,onClick:()=>m(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:H(be,{className:`h-3 w-3`})}),H(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&p.mutate({id:e.id})},disabled:p.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:H(J,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}V();function Ct(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 wt({nodeId:e,refreshToken:t}){let n=U(),r=ue().trpcClient,[a,o]=R(null),[l,u]=R(null),p=T(void 0,{refetchOnMount:`always`});X([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`,`addon.updated`]);let m=L(void 0,{refetchOnMount:`always`}),h=B(()=>{let e=new Set;for(let t of m.data??[])t.isOnline&&e.add(t.id);return e},[m.data]),g=i({nodeId:e},{refetchOnMount:`always`}),_=B(()=>(p.data??[]).filter(e=>h.has(e.nodeId)).map(e=>e.nodeId),[p.data,h]),v=ce({enabled:_.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`schema-by-agent`,_.join(`,`),t],queryFn:async()=>{let e={};for(let t of _)try{e[t]=(await r.pipelineExecutor.getSchema.query({nodeId:t})).selectedEngine.format}catch{e[t]=`coreml`}return e}}),y=f({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`pipelineExecutor`]]}),n.invalidateQueries({queryKey:[[`addonSettings`]]})}}),b=B(()=>g.data?s(g.data):[],[g.data]),x=B(()=>{let e=p.data??[],t=h;return(t.size===0?[]:e.filter(e=>t.has(e.nodeId))).map(e=>{let t=v.data?.[e.nodeId];return{agentNodeId:e.nodeId,engineLabel:t??`(engine unknown)`}})},[p.data,v.data,h]),S=(e,t)=>{let n=(p.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e],r=v.data?.[t];return!Ct(g.data??null,e)?.models.some(e=>r!==void 0&&!!e.formats[r])||!n?{kind:`na`}:n.enabled?{kind:`enabled`,modelId:n.modelId}:{kind:`disabled`}},w=a?p.data?.find(e=>e.nodeId===a.agentNodeId)??null:null,E=a&&g.data?Ct(g.data,a.addonId):null,D=a?v.data?.[a.agentNodeId]??`coreml`:`coreml`,O=()=>{o(null),u(null)},k=(e,t)=>{let n=(p.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e]??null;o({addonId:e,agentNodeId:t}),u(n)},A=()=>{!l||!a||!w||y.mutate({agentNodeId:a.agentNodeId,defaults:{...w.settings.addonDefaults,[a.addonId]:l}},{onSuccess:O})};if(p.isLoading||g.isLoading)return H(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading agents…`});if(!g.data)return W(`div`,{className:`text-xs text-foreground-subtle`,children:[`Catalog unavailable for `,e,`.`]});let j=a!==null&&E!==null&&l!==null;return W(`div`,{className:`relative h-full w-full space-y-3`,children:[H(mt,{title:`Cluster cameras`}),H(`div`,{className:j?`pr-[360px]`:``,children:b.length>0&&x.length>0?H(c,{tree:b,agents:x,getCellState:S,onCellClick:k,selectedCell:a}):H(`div`,{className:`text-xs text-foreground-subtle`,children:`No agents or catalog empty.`})}),H(d,{open:j,onClose:O,title:E?.name??``,subtitle:a?`${a.agentNodeId} · ${D}`:``,footer:W(G,{children:[H(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:O,children:`Cancel`}),H(`button`,{type:`button`,disabled:!l||!a||y.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:A,children:y.isPending?`Saving…`:`Save`})]}),children:E&&l&&a&&H(C,{mode:`agent`,addon:E,agentDefault:l,agentNodeId:a.agentNodeId,engineFormat:D,onChangeAgentConfig:e=>u(e)})})]})}V();function Tt({types:e}){let t=U(),n=m(),{data:r}=te({}),i=A(),a=B(()=>i.data??[],[i.data]),[o,s]=R(null),[c,l]=R(null),u=()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},d=ee({onSuccess:u}),f=N({onSuccess:u}),p=B(()=>{let e=new Map;for(let t of r??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[r]),h=e=>{e.isDefault||d.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},g=async e=>{if(e.isDefault){await n({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another as default first.`,confirmLabel:`OK`,variant:`warning`});return}await n({title:`Delete location "${e.displayName}"?`,message:`Removes the record; files on disk are untouched.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({id:e.id})},_=e.map(e=>a.find(t=>t.id===e)).filter(e=>e!==void 0);return W(`div`,{className:`space-y-3`,children:[_.length===0?H(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:`No storage locations declared for this purpose.`}):_.map(e=>H(he,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:p.get(e.id)??[],onAdd:e=>s(e),onEdit:e=>l(e),onDelete:e=>{g(e)},onSetDefault:e=>h(e)},e.id)),o!==null&&H(ge,{initialType:o,onClose:()=>s(null),onCreated:()=>{u(),s(null)}}),c!==null&&H(me,{location:c,onClose:()=>l(null),onSaved:()=>{u(),l(null)}})]})}V();var Et=`pipeline-analytics`;function Dt(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function Ot(){let e=U(),{data:t}=L(void 0),{data:n,isLoading:r}=u({addonId:Et}),i=Dt(n),a=E({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),o=B(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return W(`div`,{className:`flex flex-col gap-6`,children:[W(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[H(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),H(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),W(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?H(Y,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):H(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:Et,patch:{postProcessingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:o.map(e=>H(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&H(Y,{className:`h-4 w-4 animate-spin text-primary`})]})]}),W(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[H(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),H(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),H(Tt,{types:[`eventMedia`]})]})]})}V();var kt=`recorder`;function At(e,t,n){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t&&typeof e.value==`string`)return e.value;return n}function jt(){let e=U(),{data:t}=L(void 0),{data:n,isLoading:r}=u({addonId:kt}),i=At(n,`recordingNodeId`,`hub`),a=E({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),o=B(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return W(`div`,{className:`flex flex-col gap-6`,children:[W(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[H(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),H(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records (continuous & events) and serves playback. Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),W(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?H(Y,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):H(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:kt,patch:{recordingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:o.map(e=>H(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&H(Y,{className:`h-4 w-4 animate-spin text-primary`})]}),i!==`hub`&&W(`p`,{className:`mt-2 text-[11px] text-amber-500`,children:[`The stream-broker is hub-only — an agent recorder pulls streams from the hub over the network. The hub's RTSP restream port must be reachable from`,` `,H(`span`,{className:`font-medium`,children:i}),`. If the auto-derived host doesn't work, set the recorder's`,H(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),W(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[H(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),H(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where recordings are stored. Multi-location collections — segments are split across the locations of a type. Add a location to grow capacity; mark one default per type.`}),H(Tt,{types:[`recordings`,`recordingsLow`]})]})]})}V();var Mt=[{id:`assignments`,label:`Assignments`},{id:`pipeline`,label:`Pipeline`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`}];function Nt({refreshToken:e}){let[t,n]=R(`assignments`),{data:r}=L(void 0),i=r?.find(e=>e.isHub&&e.isOnline)?.id??r?.find(e=>e.isOnline)?.id??null;return W(`div`,{className:`flex flex-col h-full`,children:[W(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[H(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),H(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Assignments with live load, cluster-wide settings, pipeline template library, per-camera pipeline overrides.`})]}),H(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Mt.map(e=>H(`button`,{type:`button`,onClick:()=>n(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),W(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&H(yt,{refreshToken:e}),t===`pipeline`&&(i?H(wt,{nodeId:i,refreshToken:e}):H(`div`,{className:`text-xs text-foreground-subtle`,children:`No online node available — schema unreachable.`})),t===`events`&&H(Ot,{}),t===`recording`&&H(jt,{}),t===`settings`&&H(xt,{refreshToken:e}),t===`templates`&&H(St,{refreshToken:e})]})]})}V();var Pt=`__cluster__`;function Ft(){let[e,t]=je(),n=e.get(`node`)??`__cluster__`,[r,i]=R(0);return z(()=>{e.get(`node`)||t({node:Pt},{replace:!0})},[e,t]),W(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[H(`div`,{className:`flex items-center justify-end gap-4 px-4 py-3 border-b border-border shrink-0`,children:W(`button`,{type:`button`,onClick:()=>i(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[H(Se,{className:`h-3.5 w-3.5`}),`Refresh`]})}),W(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:[H(`aside`,{className:`w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border overflow-y-auto`,children:H(Ue,{selectedNodeId:n,onSelect:e=>{t({node:e},{replace:!0})},refreshToken:r})}),H(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:n===`__cluster__`?H(Nt,{refreshToken:r}):H(vt,{nodeId:n,refreshToken:r})})]})]})}export{Ft as PipelinePage};
@@ -1 +0,0 @@
1
- import{B as e}from"./index-CAfPe666.js";var t=e(`circle-check-big`,[[`path`,{d:`M21.801 10A10 10 0 1 1 17 3.335`,key:`yps3ct`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]);export{t};