@camstack/addon-admin-ui 1.1.8 → 1.1.10

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 (84) hide show
  1. package/dist/assets/{AddLocationWizard-K-roJ9GA.js → AddLocationWizard-6Rv7cJ2x.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-DhriskqS.js → AddonCollectionPage-B_2tbR4h.js} +1 -1
  3. package/dist/assets/{Addons-YR75ZD7u.js → Addons-BbX4uBjl.js} +1 -1
  4. package/dist/assets/{AdminTabs-d_Q3fhFr.js → AdminTabs-ggcZSYRo.js} +1 -1
  5. package/dist/assets/{BrokerForm-M1TEkE23.js → BrokerForm-CDSVhrkz.js} +1 -1
  6. package/dist/assets/{BrokerStep-ft4CskBn.js → BrokerStep-8svkw89A.js} +1 -1
  7. package/dist/assets/{Capabilities-DQ6FsStC.js → Capabilities-BXvnzYnt.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-DwCnbTWg.js → CapabilityBadges-B7D3Hwzz.js} +1 -1
  9. package/dist/assets/{Cluster-BIAdm4Tb.js → Cluster-C7sHPqis.js} +1 -1
  10. package/dist/assets/{Dashboard-BJ7YxNiL.js → Dashboard-DPpC34aG.js} +1 -1
  11. package/dist/assets/{Data-BRDi3gnS.js → Data-BHkc_vgF.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-H0DIshyC.js → DetectionIntelligence-DyHrAX6N.js} +1 -1
  13. package/dist/assets/DeviceDetail-DBZVwywl.js +2 -0
  14. package/dist/assets/{Devices-BrIK3voa.js → Devices-BgD8CQB6.js} +1 -1
  15. package/dist/assets/{EmbedPlayerPage-CAVVsBNQ.js → EmbedPlayerPage-B61ZQVZZ.js} +1 -1
  16. package/dist/assets/{FormBuilder-C0CI0fuL.js → FormBuilder-w0_WI3Ka.js} +1 -1
  17. package/dist/assets/{Identity--VaftzlP.js → Identity-BstuzdQy.js} +1 -1
  18. package/dist/assets/IntegrationDetail-D8nRUF_o.js +1 -0
  19. package/dist/assets/Integrations-VJQoJiLm.js +1 -0
  20. package/dist/assets/Integrations-eY0jZJMI.js +1 -0
  21. package/dist/assets/{Logs-DScbLoT2.js → Logs-GDqV9UKV.js} +1 -1
  22. package/dist/assets/{MotionZonesSettings-CRA2E31A.js → MotionZonesSettings-DJrDaB_B.js} +1 -1
  23. package/dist/assets/{MyAccess-DmoCGu--.js → MyAccess-D_sgzYfE.js} +1 -1
  24. package/dist/assets/{Network-C0mYBOGX.js → Network-B3qrAHLn.js} +1 -1
  25. package/dist/assets/{NodeAddonsSettingsPanel-NOicof9Z.js → NodeAddonsSettingsPanel-iZ_E2hrB.js} +1 -1
  26. package/dist/assets/Pipeline-BizaZMAU.js +1 -0
  27. package/dist/assets/{PrivacyMaskSettings-D-XyGK93.js → PrivacyMaskSettings-B42UJ9_D.js} +1 -1
  28. package/dist/assets/{ProviderIcon-CWr0L1Zk.js → ProviderIcon-DQymc3er.js} +1 -1
  29. package/dist/assets/{Settings-B708SytU.js → Settings-BFc-aPG3.js} +1 -1
  30. package/dist/assets/{Showroom-Cbt0WtPX.js → Showroom-l-plISxH.js} +1 -1
  31. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-40osH3ur.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-UWc_63Ra.js} +1 -1
  32. package/dist/assets/{bell-D5Bb9NsD.js → bell-D8uEkjw3.js} +1 -1
  33. package/dist/assets/circle-check-big-CsyfP7ea.js +1 -0
  34. package/dist/assets/{copy-CP9gtW5J.js → copy-DAz6rXSh.js} +1 -1
  35. package/dist/assets/dist-C_IIvv_p.js +2 -0
  36. package/dist/assets/{dist-Beh3SRk9.js → dist-DLkhl6kJ.js} +1 -1
  37. package/dist/assets/{download-DzVvJxQa.js → download-BzArM10F.js} +1 -1
  38. package/dist/assets/{esm-CJTraXi-.js → esm-DxUUyyzz.js} +1 -1
  39. package/dist/assets/{hostInit-JF0qMbKh.js → hostInit-LFU88EHC.js} +1 -1
  40. package/dist/assets/index-9NrrsveH.css +2 -0
  41. package/dist/assets/index-BKXQV0wH.js +4 -0
  42. package/dist/assets/{key-round-C_q8xOye.js → key-round-qLocTDSs.js} +1 -1
  43. package/dist/assets/{mf-entry-bootstrap-0-3131c22a.js → mf-entry-bootstrap-0-93b5b483.js} +2 -2
  44. package/dist/assets/{pencil-BHRUMmoA.js → pencil-BDcAm4JB.js} +1 -1
  45. package/dist/assets/{player-overlays-BgChp7d9.js → player-overlays-9veDvMBm.js} +1 -1
  46. package/dist/assets/plus-Bect3wmG.js +1 -0
  47. package/dist/assets/{radio-DgY2IleE.js → radio-B6UKQ0zK.js} +1 -1
  48. package/dist/assets/{refresh-cw-v0pbmO6o.js → refresh-cw-CafZo9UJ.js} +1 -1
  49. package/dist/assets/remoteEntry-BILC9LMy.js +1 -0
  50. package/dist/assets/{rotate-ccw-CP7sddwb.js → rotate-ccw-Cb64GEDl.js} +1 -1
  51. package/dist/assets/rotate-cw-BAmtYX09.js +1 -0
  52. package/dist/assets/search-BsHASMw-.js +1 -0
  53. package/dist/assets/{server-UvLskMxN.js → server-DF-lYP9E.js} +1 -1
  54. package/dist/assets/{sparkles-BxJx7Fyw.js → sparkles-B_sIyfPM.js} +1 -1
  55. package/dist/assets/square-QrYsS6Uz.js +1 -0
  56. package/dist/assets/{square-check-big-Bn4eOzsQ.js → square-check-big-DR4fzvG5.js} +1 -1
  57. package/dist/assets/src-D2B9pT1o.js +34 -0
  58. package/dist/assets/src-DSe57QNH.js +2 -0
  59. package/dist/assets/{upload-D82-ejbj.js → upload-CYjJEdOd.js} +1 -1
  60. package/dist/assets/useBodyScrollLock-B2OWVaf_.js +1 -0
  61. package/dist/assets/{useDevice-C6D61e1v.js → useDevice-BV6YEvw2.js} +1 -1
  62. package/dist/assets/{useEventInvalidation-DI8zcwFR.js → useEventInvalidation-D0AwsYzy.js} +1 -1
  63. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BCsYdYpX.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BzEAwpwV.js} +2 -2
  64. package/dist/assets/{wifi-CriKFv8v.js → wifi-DcA7zdx0.js} +1 -1
  65. package/dist/assets/{zap-Ccsci_og.js → zap-DT-U_xiQ.js} +1 -1
  66. package/dist/index.html +6 -6
  67. package/dist/server/addon.js +65 -9
  68. package/package.json +1 -1
  69. package/dist/assets/DeviceDetail-DkUSapVD.js +0 -2
  70. package/dist/assets/IntegrationDetail-DOy-10gc.js +0 -1
  71. package/dist/assets/Integrations-B_3uTu9j.js +0 -1
  72. package/dist/assets/Integrations-BtUtOb4B.js +0 -1
  73. package/dist/assets/Pipeline-CDC0erzb.js +0 -1
  74. package/dist/assets/circle-check-big-CFjKvleu.js +0 -1
  75. package/dist/assets/dist-kIbzkh1w.js +0 -2
  76. package/dist/assets/index-B5O8fiCG.js +0 -4
  77. package/dist/assets/index-D5fms8eH.css +0 -2
  78. package/dist/assets/plus-Dc6XItxw.js +0 -1
  79. package/dist/assets/remoteEntry-Daxw-n3s.js +0 -1
  80. package/dist/assets/rotate-cw-DGpHm3qC.js +0 -1
  81. package/dist/assets/search-CzfNzZjx.js +0 -1
  82. package/dist/assets/square-ClzlCoON.js +0 -1
  83. package/dist/assets/src-CGgpymf9.js +0 -34
  84. package/dist/assets/src-Dby7n-bf.js +0 -2
@@ -0,0 +1,2 @@
1
+ import{$i as e,A as t,Ai as n,Ar as r,B as i,E as a,Fi as o,G as s,Gi as c,Gn as l,H as u,I as d,Jt as f,K as p,Ki as m,Kn as h,L as g,Pr as _,Sn as v,T as y,Tt as b,U as x,V as S,Vr as C,W as w,Xi as T,Yi as E,Yr as ee,_n as D,a as O,an as k,ba as A,bn as j,cn as M,di as te,dn as N,en as P,f as F,fn as ne,g as re,gn as ie,hn as ae,i as I,ii as oe,in as se,j as ce,ji as le,k as ue,ki as de,l as fe,ln as pe,lr as me,lt as he,m as ge,mn as _e,n as L,ni as ve,nn as ye,o as be,p as xe,pn as Se,qi as Ce,qn as we,qt as Te,r as Ee,u as De,ui as Oe,un as ke,vn as Ae,w as R,xn as je,xr as Me,y as Ne,ya as Pe,yn as Fe,zn as Ie,zr as Le}from"./src-D2B9pT1o.js";import{G as z,I as B,K as V,S as H,W as U,Z as W,b as Re,o as G,t as ze,x as K,z as q}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{c as Be,k as Ve,p as J,r as He,t as Ue,u as We}from"./player-overlays-9veDvMBm.js";import{C as Ge,E as Ke,b as Y,g as qe,v as Je}from"./src-DSe57QNH.js";import{t as Ye}from"./CapabilityBadges-B7D3Hwzz.js";import{t as Xe}from"./bell-D8uEkjw3.js";import{n as Ze,t as Qe}from"./rotate-ccw-Cb64GEDl.js";import{t as $e}from"./ProviderIcon-DQymc3er.js";import{t as et}from"./pencil-BDcAm4JB.js";import{t as tt}from"./plus-Bect3wmG.js";import{t as nt}from"./refresh-cw-CafZo9UJ.js";import{t as rt}from"./rotate-cw-BAmtYX09.js";import{t as it}from"./server-DF-lYP9E.js";import{t as at}from"./wifi-DcA7zdx0.js";import{B as X,F as ot,H as st,I as ct,O as lt,U as ut,W as dt,_ as ft,a as pt,c as mt,i as ht,k as gt,p as _t,r as vt,s as yt,t as bt,v as xt,x as St,z as Ct}from"./index-BKXQV0wH.js";import{t as wt}from"./StatusBadge-BSsUNFG6.js";import{n as Tt,t as Et}from"./useDevice-BV6YEvw2.js";import{n as Dt,r as Ot,t as kt}from"./SchemaTabBar-DRo5sGP1.js";import{t as At}from"./FormBuilder-w0_WI3Ka.js";import{t as jt}from"./useEventInvalidation-D0AwsYzy.js";var Mt=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`}]]),Nt=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`}]]),Pt=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`}]]),Ft=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`}]]),It=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`}]]),Lt=X(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),Rt=X(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),zt=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 Bt=`device-export`,Vt=`export`,Ht=`Export`;function Ut(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(Ut):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(Ut)):e.writerCapName===Bt}function Wt(e){return e.fields.some(Ut)}function Gt(e){return O(J().trpcClient,e)}function Kt(e){let[t,n]=V(`idle`),[r,i]=V(null),a=z(null),o=z(null),s=z(null),c=z(!0),u=h(),d=l(),f=we(),p=B(()=>{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=B(async()=>{if(t===`idle`)return;n(`stopping`);let r=s.current;if(r&&e!==null)try{await Promise.race([f.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}p(),c.current&&(n(`idle`),i(null))},[t,e,f,p]),g=B(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,l=null,p=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await u.mutateAsync({deviceId:e});p=t.sessionId,s.current=p,n(`connecting`),l=new RTCPeerConnection,a.current=l,l.oniceconnectionstatechange=()=>{if(!c.current)return;let e=l.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())l.addTrack(e,r);await l.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let f=await l.createAnswer();await l.setLocalDescription(f);let h=l.localDescription?.sdp??f.sdp??``;await d.mutateAsync({deviceId:e,sessionId:p,sdpAnswer:h})}catch(t){let u=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),l)try{l.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,p!==null)try{await f.mutateAsync({deviceId:e,sessionId:p})}catch{}s.current=null,c.current&&(i(u),n(`error`))}},[e,t,u,d,f,m]);return q(()=>(c.current=!0,()=>{c.current=!1;let t=s.current;if(t!==null&&e!==null&&f.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null}),[e]),{state:t,error:r,start:g,stop:m,isTalking:t===`talking`}}W();var qt=0;function Z(){return++qt}function Jt(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Yt(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 Xt(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 Zt(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 Qt({scope:e,greeting:t,className:n}){let r=J(),[i,a]=V(()=>{let n=[];return t&&n.push({id:Z(),kind:`info`,text:t}),n.push({id:Z(),kind:`info`,text:`scope: ${Jt(e)} — type help or context for available commands`}),n}),[o,s]=V(``),[c,l]=V([]),[u,d]=V(-1),f=z(null),p=z(null);q(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=B(()=>{f.current?.focus()},[]),h=ze({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: ${Jt(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Yt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Zt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Xt(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: ${Jt(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return H(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[H(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>K(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&K(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),H(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[K(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),K(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function $t({deviceId:e,intercomAvailable:t=!1}){let n=J(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),o=Gt(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),_=w(n.trpcClient,i?e:null),v=Kt(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=He(),C=a(),T=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,E=S.length>0?K(Re,{children:S.map(e=>K(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return K(Ne,{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:T,...C.request.label?{playbackLabel:C.request.label}:{},onExitPlayback:()=>C.clear()}:{},streams:s,pipelineMetrics:c,phase:o.phase,detections:o,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:_.src,..._.src?{posterUrl:_.src}:{},snapshotLoading:_.loading,onRefreshSnapshot:_.refresh,intercomAvailable:t,intercomShown:b,onIntercomToggle:x,extraOverlay:E,chromeless:!0,className:`h-full`})}function en({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full`,children:K(re,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function tn({deviceId:e}){if(!Number.isFinite(e))return H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
2
+ `);return K(Qt,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function nn({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(ge,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function rn({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(F,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function an({parentDeviceId:e}){let{t}=bt(),n=st(),r=J(),{data:a,isLoading:o,isError:s}=Tt(e),{data:c}=M({deviceId:e},{enabled:Number.isFinite(e)});if(o)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=a??[];if(l.length===0)return null;let d=S(c?.stableId??``,l,c?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),m=c?.name??``,h=e=>{let t=`${m} `;return m.length>0&&e.startsWith(t)?e.slice(t.length):e},g=(e,t)=>K(i,{trpc:r.trpcClient,device:{...t,name:h(t.name)},variant:`minimal`,onNavigate:p},e),_=f.some(e=>!!e.role),v=f.some(e=>!e.role),y=_&&!v?t(`device.accessories`,{defaultValue:`Accessories`}):!_&&v?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),b=f.length>0?H(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[K(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:y}),K(`div`,{className:`space-y-1`,children:f.map(e=>g(e.id,e))})]}):null,x=d.disabledSection===void 0?null:K(u,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:K(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>g(e.id,e))})},d.disabledSection.title);return d.sections.length===0?x===null?b:H(`div`,{className:`space-y-2`,children:[b,x]}):H(`div`,{className:`space-y-2`,children:[d.sections.map(e=>K(u,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>g(e.id,e))},e.title)),b,x]})}function Q({label:e,value:t}){return H(`div`,{className:`${Ve} flex items-start gap-2 sm:gap-3`,children:[K(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),K(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}W();function on({deviceId:e,initialName:t}){let n=G(),[r,i]=V(!1),[a,o]=V(t),[s,c]=V(!1),l=z(null);q(()=>{r||o(t)},[t,r]),q(()=>{r&&l.current?.focus()},[r]);let u=Ae({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),d=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),o(t);return}c(!0);try{await u.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{c(!1)}},f=()=>{o(t),i(!1)};return r?K(Q,{label:`Name`,value:H(`div`,{className:`flex items-center gap-1`,children:[K(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?d():e.key===`Escape`&&f()},disabled:s,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),K(`button`,{type:`button`,onClick:()=>void d(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:K(ot,{className:`h-3 w-3`})}),K(`button`,{type:`button`,onClick:f,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:K(ht,{className:`h-3 w-3`})})]})}):K(Q,{label:`Name`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[K(`span`,{className:`truncate`,children:t}),K(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit name`,children:K(et,{className:`h-3 w-3 text-foreground-subtle`})})]})})}W();function sn({deviceId:e,initialLocation:t}){let n=G(),[r,i]=V(!1),[a,o]=V(t??``),[s,c]=V(!1),l=z(null),{data:u}=Se(void 0,{enabled:r}),d=u??[];q(()=>{r||o(t??``)},[t,r]),q(()=>{r&&l.current?.focus()},[r]);let f=D({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),p=U(()=>{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?K(Q,{label:`Location`,value:H(`div`,{className:`relative`,children:[H(`div`,{className:`flex items-center gap-1`,children:[K(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?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`}),K(`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:K(ot,{className:`h-3 w-3`})}),K(`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:K(ht,{className:`h-3 w-3`})})]}),(p.length>0||m)&&H(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[p.map(e=>H(`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:[K(It,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),K(`span`,{className:`truncate`,children:e})]},e)),m&&H(`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:[K(`span`,{className:`text-foreground-subtle`,children:`Create`}),H(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):K(Q,{label:`Location`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[t?K(`span`,{className:`truncate`,children:t}):K(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),K(`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:K(et,{className:`h-3 w-3 text-foreground-subtle`})})]})})}W();var cn=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function ln(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function un(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function dn(){let e=t(),n=ce(),{data:r}=M({deviceId:e??0},{enabled:e!==null}),{data:i}=k({deviceId:e??0},{enabled:e!==null}),a=r??n??null,[o,s]=V(`identity`);if(e===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 H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[H(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[K(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),v&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[K(fn,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),K(fn,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!v||o===`identity`)&&H(`div`,{className:`divide-y divide-border`,children:[K(Q,{label:`ID`,value:H(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,H(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,c,`)`]})]})}),K(on,{deviceId:e,initialName:l}),K(sn,{deviceId:e,initialLocation:g}),K(Q,{label:`Type`,value:u}),K(Q,{label:`Provider`,value:K($e,{type:d,size:`sm`,showLabel:!0})}),K(Q,{label:`Capabilities`,value:h.length>0?K(Ye,{capabilities:h,showLabels:!0}):K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),v&&o===`hardware`&&K(pn,{metadata:_})]})}function fn({active:e,onClick:t,label:n}){return K(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function pn({metadata:e}){let t=cn.filter(t=>t in e),n=Object.keys(e).filter(e=>!cn.includes(e)).toSorted(),r=[...t,...n];return H(`div`,{children:[K(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),K(`div`,{className:`divide-y divide-border`,children:r.map(t=>K(Q,{label:ln(t),value:K(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:un(e[t])})},t))})]})}W();function mn({deviceId:e}){let[t,n]=V(null),r=P({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return H(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[H(`div`,{className:`flex items-center justify-between gap-3`,children:[H(`div`,{children:[K(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),K(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),H(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[K(nt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&K(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function hn(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function gn({device:e}){let t=st(),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(Je.Resyncable),{data:c}=me({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),l=c?.streams??{},u=Object.entries(l),d=o.includes(Je.DoorbellButton),f=Ee(d?{deviceId:n??void 0,historyLimit:10}:void 0),p=f.latest?Date.now()-f.latest.timestamp<3e4:!1;return H(`div`,{className:`space-y-5`,children:[a&&n!==null&&K(xe,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),s&&n!==null&&K(mn,{deviceId:n}),i&&n!==null&&K(R,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),d&&K(De,{history:f.history,latestIsFresh:p}),i&&n!==null&&K(R,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&u.length>0&&H(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[K(`div`,{className:`border-b border-border px-4 py-2`,children:K(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),K(`div`,{className:`divide-y divide-border`,children:u.map(([e,t])=>H(`div`,{className:`px-4 py-2.5`,children:[H(`div`,{className:`flex items-center gap-2 mb-2`,children:[K(at,{className:`h-3 w-3 text-foreground-subtle`}),K(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),H(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[K(_n,{label:`Nominal`,value:hn(t.nominalBitrateKbps??0)}),K(_n,{label:`Observed`,value:hn(t.observedBitrateKbps??0)}),K(_n,{label:`Peak`,value:hn(t.peakBitrateKbps??0)}),K(_n,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),K(dn,{})]})}function _n({label:e,value:t,warning:n}){return H(`div`,{children:[K(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),K(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}W();function vn({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=U(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),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]=V(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=K(Dt,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(p.length<=1)return H(`div`,{className:`flex flex-col gap-3`,children:[K(At,{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 H(`div`,{className:`flex flex-col gap-3`,children:[K(kt,{tabs:p.map(e=>({id:e.id,label:e.label})),activeId:y,onChange:b,countByTab:w,pendingByTab:T}),K(At,{schema:S,values:t,onChange:r,onAction:i,disabled:s}),C]})}W();function yn(e,t){return t&&t===`admin`?e:!0}function bn(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?Wt(e)&&Wt(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function xn(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 Sn(e){return e.key}function Cn(e){if(!xn(e))return e.value}function wn(e){return xn(e)?null:e}function Tn(e,t){for(let n of e)if(t(n),n.type===`group`)Tn(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)Tn(e.fields,t)}function En(e){if(!e)return{};let t={};for(let n of e.sections)Tn(n.fields,e=>{let n=Sn(e);n!==null&&(t[n]=Cn(e))});return t}function Dn(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(Tn(r.fields,e=>{if(n!==null||Sn(e)!==t)return;let r=wn(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function On(e){return{...e,fields:e.fields.map(kn)}}function kn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function An(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=wn(e);return n?yn(t,n.minRole)?e:kn(e):e})}))}}function jn({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r}){let i=G(),{user:a}=vt(),o=a?.isAdmin===!0,s=z(!1),{data:c,isLoading:l}=pe({deviceId:e},{refetchInterval:()=>s.current?!1:2500,enabled:Number.isFinite(e)}),{data:u}=M({deviceId:e},{enabled:Number.isFinite(e)}),d=c?.settings??null,f=c?.live??null,p=U(()=>{if(!d&&!f)return null;let e=d?.sections??[],n=(f?.sections??[]).map(On),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!Wt(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...d?.tabs??[],...(f?.tabs??[]).filter(e=>!(d?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[d,f,t]),m=U(()=>bn(p),[p]),h=U(()=>An(m,o),[m,o]),g=U(()=>En(h),[h]),_=te(),y=Oe(),b=je(),x=ae(),S=v({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),C={isPending:S.isPending,mutate:t=>{S.mutate({deviceId:e,changes:[...t]})}},w=Ot({schema:h,serverValues:g,onImmediateSave:B(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Dn(h,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&C.mutate(t)},[h,C]),onDeferredSave:B(e=>{let t=Object.entries(e).map(([e,t])=>{let n=Dn(h,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&C.mutate(t)},[h,C])}),{values:T,pendingKeys:E,handleChange:ee,handleSave:D,handleDiscard:O}=w;if(s.current=w.editingPaused,l)return H(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[K(St,{className:`h-4 w-4 animate-spin mr-2`}),K(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!h||h.sections.length===0)return K(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function k(t,n,r){if(t===`regenerate-rtsp-token`){let t=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!t)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(t.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let a=Ge(e,r);await _.mutateAsync({brokerId:a}),i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!u)return{status:`error`,error:`Device metadata not loaded yet`};try{return await b.mutateAsync({addonId:u.addonId,type:u.type,key:n,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(t===`refresh-probe`){if(!n.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${n}" (expected "probedInfo:<streamId>")`);let t=n.slice(11);if(!t)throw Error(`refresh-probe: key "${n}" has no streamId after prefix`);let r=Ge(e,t),a=await y.mutateAsync({brokerId:r});return i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),a}if(t===`device-custom-action`){let t=await x.mutateAsync({deviceId:e,action:n,input:r});return i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return K(vn,{schema:h,values:T,pendingKeys:E,onChange:ee,onAction:k,onSave:D,onDiscard:O,disabled:C.isPending,activeSubTab:n,onSubTabChange:r})}function Mn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return K(`div`,{className:`flex flex-col gap-3`,children:K(jn,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}function Nn({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return H(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[K($e,{type:n,size:`lg`}),H(`div`,{children:[K(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),K(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),H(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[K(wt,{status:r?`online`:`offline`}),i.length>0&&K(Ye,{capabilities:i})]}),K(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}W();function Pn({deviceId:e}){let t=G(),n=Te({deviceId:e},{refetchInterval:1e4,retry:!1}),r=f({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>Fn(n.data??[]),[n.data]);return H(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[H(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[K(In,{label:`Discovered`,value:i.total,icon:K(ft,{className:`h-3.5 w-3.5`})}),K(In,{label:`Adopted`,value:i.adopted,accent:`success`}),K(In,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),H(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[r.isPending?K(St,{className:`h-3.5 w-3.5 animate-spin`}):K(nt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),H(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[K(Ln,{icon:K(at,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),K(Ln,{icon:K(xt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),K(Ln,{icon:K(pt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?K(Ln,{icon:K(Mt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function Fn(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 In({label:e,value:t,icon:n,accent:r}){return H(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[H(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,K(`span`,{className:`truncate`,children:e})]}),K(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function Ln({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,K(`span`,{children:t})]})}function Rn({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:K(n,{trpc:J().trpcClient,deviceId:e,features:t})})}function zn({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:K(de,{trpc:J().trpcClient,deviceId:e,features:t})})}function $({deviceId:e,deviceType:t,features:n}){let r=J(),i=p(t)?.HeroCard??de,a=We(Be(r.trpcClient,e)?.state.deviceStatus),o=a!==void 0&&a.online===!1,s=o?a.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[o?K(`div`,{className:`flex justify-center`,children:K(g,{lastChangedAt:s})}):null,K(i,{trpc:r.trpcClient,deviceId:e,features:n})]})}W();function Bn({deviceId:e}){let t=J(),n=G(),{data:r,isLoading:i}=Et(e),{data:a,isLoading:o}=Tt(e),s=i||o,[c,l]=V(null),u=Fe({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?K(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):H(`div`,{className:`flex h-full w-full flex-col`,children:[K(d,{trpc:t.trpcClient,children:f,linkDeviceId:p,primaryChildEntityId:m,onSetPrimary:t=>u.mutate({deviceId:e,primaryChildEntityId:t})}),c!==null&&K(`p`,{role:`alert`,className:`px-3 pb-2 text-[11px] text-danger sm:px-4`,children:c})]})}var Vn={[Y.Switch]:$,[Y.Siren]:$,[Y.Light]:$,[Y.Sensor]:$,[Y.Button]:$,[Y.Hub]:Pn,[Y.Cover]:Rn,[Y.Valve]:$,[Y.Humidifier]:$,[Y.WaterHeater]:$,[Y.Container]:Bn,[Y.Lock]:$,[Y.Fan]:$,[Y.Thermostat]:$,[Y.MediaPlayer]:$,[Y.Control]:$,[Y.AlarmPanel]:zn,[Y.EventEmitter]:zn,[Y.Notifier]:zn,[Y.Script]:zn,[Y.Automation]:zn,[Y.Presence]:$,[Y.Update]:$,[Y.Vacuum]:$,[Y.LawnMower]:$,[Y.Weather]:$,[Y.Image]:$};function Hn(e){return K(Vn[e.deviceType]??Nn,{...e})}function Un({deviceId:e}){let t=G(),n=Number.isFinite(e),{data:r}=M({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;jt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:c}=k({deviceId:e},{enabled:n}),{data:l}=ne({deviceType:i},{enabled:!!i}),u=j({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return K(`div`,{className:`p-4`,children:K(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(s)return H(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,c instanceof Error?c.message:String(c)]});let d=new Map,f={};for(let e of l??[])f[e.capName]=e.wrappers;for(let e of a?.entries??[])d.set(e.capName,{...e,wrappers:f[e.capName]??[]});for(let e of l??[])d.has(e.capName)||d.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let p=[...d.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(p.length===0)return H(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[K(Ze,{className:`h-8 w-8 opacity-40`}),K(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),K(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let m=p.filter(e=>e.kind!==`unbound`).length;return H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`text-[11px] text-foreground-subtle`,children:[K(`span`,{className:`font-medium text-foreground`,children:m}),` of `,p.length,` capabilit`,p.length===1?`y`:`ies`,` bound — rows marked `,K(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),K(E,{columns:[{key:`capability`,header:`Capability`,render:e=>K(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>K(Wn,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?K(Gn,{nodeId:e.providerNodeId}):K(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return K(Kn,{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 Wn({kind:e}){return e===`native`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[K(it,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[K(Nt,{className:`h-3 w-3`}),`wrapped`]}):H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[K(Lt,{className:`h-3 w-3`}),`unbound`]})}function Gn({nodeId:e}){return K(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function Kn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?K(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):K(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return H(`button`,{disabled:n,onClick:()=>r(e),title:i?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[K(i?ot:Qe,{className:`h-3 w-3`}),e]},e)})})}W();function qn(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Jn(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 Yn({agents:e,currentAgent:t,onPick:n}){let[r,i]=V(!1);return H(`div`,{className:`relative`,children:[K(`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&&K(`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=>K(`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 Xn({deviceId:e,refreshToken:t}){let n=G(),[i,a]=V(null),[o,s]=V(null),[l,u]=V(null),[d,f]=V(null),p=_({deviceId:e}),h=C(),g=Le({deviceId:e}),v=r(),y=U(()=>g.data?.agentNodeId||v.data?.find(e=>e.online)?.nodeId||`hub`,[g.data?.agentNodeId,v.data]),b=o??y,x=Me({nodeId:b??``},{enabled:!!b}),S=ee({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),u(null)}}),w=U(()=>x.data?Ce(x.data):[],[x.data]),T=U(()=>{let e=p.data??null,t={};for(let n of h.data??[])for(let r of Object.keys(n.settings.addonDefaults)){let i=t[r]??[];i.push({agentNodeId:n.nodeId,state:Jn(e,n.nodeId,r)}),t[r]=i}return t},[p.data,h.data]),E=i?qn(x.data??null,i):null,D=b?h.data?.find(e=>e.nodeId===b)??null:null,O=i&&D?D.settings.addonDefaults[i]??null:null,k=i&&b?p.data?.stepOverridesByAgent?.[b]?.[i]??null:null,j=x.data?.selectedEngine.format??`coreml`,M=e=>{s(e),u(null),f(null)};return h.isLoading||x.isLoading?K(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):x.data?K(`div`,{className:`@container h-full`,style:{containerType:`inline-size`},children:H(`div`,{className:`flex flex-col @[720px]:flex-row h-full`,children:[K(`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:K(m,{tree:w,selectedAddonId:i,onSelect:e=>{a(e),u(null),f(null)},agentDots:T})}),K(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!i||!E?K(`div`,{className:`text-sm text-foreground-subtle`,children:`Select a step on the left to configure it for this camera.`}):H(`div`,{className:`space-y-4`,children:[H(`div`,{children:[K(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle`,children:`Selected step`}),K(`div`,{className:`text-base font-semibold`,children:E.name})]}),H(`div`,{className:`flex items-end gap-3 flex-wrap`,children:[H(`div`,{children:[K(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle mb-1`,children:`Agent`}),K(`div`,{className:`flex rounded border border-border overflow-hidden`,children:(h.data??[]).map(e=>K(`button`,{type:`button`,onClick:()=>M(e.nodeId),className:`px-3 py-1 text-xs ${b===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),K(Yn,{agents:(h.data??[]).map(e=>e.nodeId),currentAgent:b,onPick:e=>{if(!b||!i||!x.data||!h.data)return;let t=h.data.find(t=>t.nodeId===e),n=h.data.find(e=>e.nodeId===b);if(!t||!n)return;let[r]=A({source:{nodeId:t.nodeId,engine:{format:j},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:j},defaults:n.settings.addonDefaults},catalog:x.data,addonIds:[i]});if(!r){f(`no mirror result`);return}if(r.outcome===`skip`){f(`skipped: ${r.reason??`no candidate`}`);return}u(r.patch),f(`${r.outcome} from ${e}`)}}),d&&K(`div`,{className:`text-[10px] text-foreground-subtle`,children:d})]}),O&&K(c,{mode:`device`,addon:E,agentDefault:O,agentNodeId:b??``,currentPatch:l??k,engineFormat:j,onChangePatch:u}),H(`div`,{className:`flex items-center justify-between gap-2 pt-4 border-t border-border`,children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle`,disabled:!k||S.isPending,onClick:()=>{!b||!i||S.mutate({deviceId:e,agentNodeId:b,addonId:i,patch:null})},children:`Clear override`}),H(`div`,{className:`flex items-center gap-2`,children:[K(`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`}),K(`button`,{type:`button`,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,disabled:!b||!i||S.isPending,onClick:()=>{!b||!i||S.mutate({deviceId:e,agentNodeId:b,addonId:i,patch:l})},children:S.isPending?`Saving…`:`Save`})]})]})]})})]})}):K(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`})}W();function Zn(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function Qn(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=Zn(r.value,t));return n}function $n(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 er(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 tr(e){return e==null?`identity`:e.kind}function nr({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=V(()=>tr(e)),[o,s]=V(()=>$n(e,n)),[c,l]=V(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=V(()=>er(e));q(()=>{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]),q(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=Qn(o,r),n=c===``?void 0:Zn(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($n(void 0,n)),e===`linear`&&d(er(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{children:[K(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),K(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[K(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[K(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>H(`div`,{className:`flex items-center gap-1.5`,children:[K(`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`}),K(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?H(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[K(`option`,{value:``,children:`—`}),K(`option`,{value:`true`,children:`true`}),K(`option`,{value:`false`,children:`false`})]}):K(`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`&&K(`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`&&K(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),H(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[K(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),K(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[K(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),K(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),K(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[K(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),K(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),K(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),K(`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 rr(e,t){return`${e.replace(/[^a-z0-9]/gi,`-`)}-${t.replace(/[^a-z0-9]/gi,`-`)}`}function ir(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function ar({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=N({}),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}=ke({deviceId:e}),d=u?.caps??[],f=r==null?null:ir(r.source.sourceKey,c,s),[p,m]=V(r?.target.cap??``),[h,g]=V(r?.target.fieldPath??``),[_,v]=V(f),[y,b]=V(r?.source.cap??``),[x,S]=V(r?.source.fieldPath??``),[C,w]=V(r?.transform);q(()=>{if(r!=null&&_===null&&s.length>0){let e=ir(r.source.sourceKey,c,s);e!==null&&v(e)}},[r,_,s,c]);let{data:T}=ke({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(``)},j=e=>{v(e===``?null:Number(e)),b(``),S(``)},M=e=>{b(e),S(``)},te=p!==``&&h!==``&&_!=null&&y!==``&&x!==``,P=()=>{if(!te)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??rr(p,h),source:{sourceKey:n,cap:y,fieldPath:x},target:{cap:p,fieldPath:h},...C==null?{}:{transform:C}})},F=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return H(`div`,{className:`flex flex-col gap-4 p-3`,children:[H(`fieldset`,{className:`flex flex-col gap-3`,children:[K(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),H(`div`,{children:[K(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),H(`select`,{id:`link-target-cap`,value:p,onChange:e=>A(e.target.value),className:F,children:[K(`option`,{value:``,children:`— select a cap —`}),d.map(e=>K(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),H(`select`,{id:`link-target-field`,value:h,disabled:p===``,onChange:e=>g(e.target.value),className:F,children:[K(`option`,{value:``,children:`— select a field —`}),ee.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),H(`fieldset`,{className:`flex flex-col gap-3`,children:[K(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source (sibling device)`}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source device`}),H(`select`,{id:`link-source-device`,value:_??``,onChange:e=>j(e.target.value),className:F,children:[K(`option`,{value:``,children:`— select a device —`}),l.map(e=>H(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source cap`}),H(`select`,{id:`link-source-cap`,value:y,disabled:_==null,onChange:e=>M(e.target.value),className:F,children:[K(`option`,{value:``,children:`— select a cap —`}),E.map(e=>K(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source field`}),H(`select`,{id:`link-source-field`,value:x,disabled:y===``,onChange:e=>S(e.target.value),className:F,children:[K(`option`,{value:``,children:`— select a field —`}),O.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),K(nr,{value:C,onChange:w,sourceField:k,targetKind:D?.kind}),H(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[K(`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`}),K(`button`,{type:`button`,disabled:!te,onClick:P,className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Save`})]})]})}W();function or({deviceId:e}){let t=J(),n=G(),{data:r,isLoading:i}=M({deviceId:e},{enabled:Number.isFinite(e),refetchInterval:1e4}),a=ie({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]=V(null),d=t=>{a.mutate({deviceId:e,deviceLinks:o.filter(e=>e.id!==t)})};return i?K(`div`,{className:`p-4`,children:K(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):l===null?H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`flex items-center justify-between`,children:[K(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),H(`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:[K(tt,{className:`h-3 w-3`}),`Add link`]})]}),o.length===0?H(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[K(Pt,{className:`h-8 w-8 opacity-30`}),K(`p`,{className:`text-xs`,children:`No links yet.`}),K(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):K(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:o.map(n=>K(sr,{deviceId:e,link:n,trpcClient:t.trpcClient,onDelete:()=>d(n.id),onEdit:()=>u(n),isPending:a.isPending},n.id))})]}):H(`div`,{className:`flex flex-col gap-3 p-1`,children:[K(`div`,{className:`flex items-center justify-between`,children:K(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:l===`new`?`Add link`:`Edit link`})}),K(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:K(ar,{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 sr({deviceId:e,link:t,trpcClient:n,onDelete:r,onEdit:i,isPending:a}){let o=L(n,e,t.target.cap),s=o===void 0?void 0:qe(o,t.target.fieldPath),c=s==null?`—`:String(s);return H(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[K(Ft,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),H(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[H(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[K(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),K(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),K(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath})]}),H(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[K(`span`,{children:`←`}),K(`span`,{className:`font-mono`,children:t.source.sourceKey}),K(`span`,{className:`opacity-60`,children:`/`}),K(`span`,{className:`font-mono`,children:t.source.cap}),K(`span`,{className:`opacity-60`,children:`.`}),K(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]}),t.transform&&K(cr,{kind:t.transform.kind}),K(`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}),K(`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`}),K(`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 cr({kind:e}){return K(`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 lr=[{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 ur(e){let t=e===Y.Camera;return lr.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var dr=[{id:`logs`,icon:_t,label:`Logs`},{id:`repl`,icon:mt,label:`REPL`},{id:`events`,icon:Xe,label:`Events`},{id:`state`,icon:lt,label:`State`}];function fr(){let t=ut(),n=Number(t.deviceId),r=Number.isFinite(n),i=st(),a=G(),c=o(),l=J(),[u,d]=dt(),f=u.get(`tab`)??`overview`,p=u.get(`sub`),[m,h]=V(`logs`),g=`device-detail.left-col-width-px`,[_,v]=V(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(g),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),S=z(_);S.current=_;function C(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??_??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{v(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=S.current;if(e!==null)try{window.localStorage.setItem(g,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:w,isLoading:E,isError:ee}=M({deviceId:n},{enabled:r,refetchInterval:5e3,retry:1}),{data:D}=pe({deviceId:n},{enabled:r}),O=U(()=>{let e=D?.settings?.sections??[],t=D?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(Wt)&&r.add(Vt),[...r].map(e=>e===`export`?{id:e,label:Ht,isAddonContrib:!0}:{id:e,label:Ke[e]?.label??e,isAddonContrib:!0})},[D]),k=w,A=String(k?.name??t.deviceId??`Device`),j=k?.online===!0,te=j?`online`:`offline`,N=String(k?.addonId??`rtsp`),P=k?.features??[],F=k?.type,ne=F===Y.Camera,{data:re}=Tt(r?n:0),ie=F===Y.Container,ae=U(()=>(re??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[re]),I=U(()=>ie?le(ae,typeof k?.linkDeviceId==`number`?k.linkDeviceId:null,typeof k?.primaryChildEntityId==`string`?k.primaryChildEntityId:null)?.id??null:null,[ie,ae,k?.linkDeviceId,k?.primaryChildEntityId]),{data:ce}=pe({deviceId:I??0},{enabled:I!==null}),de=U(()=>{if(I===null)return[];let e=ce?.settings?.sections??[],t=ce?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:Ke[e]?.label??e,isAddonContrib:!0,childDeviceId:I}))},[I,ce]),me=typeof k?.parentDeviceId==`number`?k.parentDeviceId:null,{data:ge}=M({deviceId:me??0},{enabled:me!==null}),L=e(),xe=k?.disabled!==!0,{data:Se}=ke({deviceId:n},{enabled:r}),Ce=(Se?.caps.length??0)>0,we=U(()=>{let e=new Set,t=[];for(let n of[...ur(F),...O,...de])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!Ce)&&t.push(n));return t},[F,O,de,Ce]),Te=U(()=>we.some(e=>e.id===f)?f:`overview`,[we,f]),Ee=B(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]),De=B(e=>{d(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[d]),Oe=(re??[]).length>0,Ae=U(()=>dr.filter(({featureGate:e})=>!e||P.includes(e)),[P]),{data:R}=Ie({addonId:N},{enabled:!!N&&N!==`rtsp`}),je=_e({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]}),i(R?.id?`/integrations/${R.id}`:`/integrations`)}}),Me=se({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ne=ye({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=oe(),Fe=he({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),W=P.includes(Je.Rebootable),Re=P.includes(Je.BatteryOperated),ze=s(l.trpcClient,Re&&r?n:null),[q,Ve]=V(!1),He=Be(l.trpcClient,r?n:null),We=async()=>{if(!(q||!He)){Ve(!0);try{await He.snapshot?.invalidateCache({});let e=await He.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{Ve(!1)}}},Ge=Me.isPending||Ne.isPending,{data:qe}=Le({deviceId:n},{enabled:r,refetchInterval:1e4}),Xe=qe?.agentNodeId??null,Ze=typeof Xe==`string`&&Xe.length>0&&!Xe.startsWith(`addon:`)?Xe:void 0,{data:Qe}=ve({deviceId:n,...Ze?{nodeId:Ze}:{}},{enabled:r,refetchInterval:3e3,retry:!1}),{data:et}=b({deviceId:n},{enabled:r,refetchInterval:3e3,retry:!1}),tt=et?.level?.dbfs??null;function it(){if(!r)return null;switch(Te){case`overview`:return K(gn,{device:k??{}});case`config`:return K(Mn,{deviceId:n,activeSubTab:p,onSubTabChange:De});case`pipeline`:return K(Xn,{deviceId:n,refreshToken:0});case`bindings`:return K(Un,{deviceId:n});case`wiring`:return K(or,{deviceId:n});default:{let e=Te,t=O.some(t=>t.id===e),r=de.find(t=>t.id===e);if(!t&&r===void 0)return null;let i=r?.childDeviceId??n;if(e===`export`)return K(jn,{deviceId:n,sectionFilter:Wt,activeSubTab:p,onSubTabChange:De});let a=K(jn,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),activeSubTab:p,onSubTabChange:De});return r!==void 0&&i!==n?K(ue,{deviceId:i,children:a}):a}}}return r?E?H(`div`,{className:`flex flex-col h-full`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[K(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),K(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),K(`div`,{className:`flex-1 p-6`,children:K(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):ee||!w?H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),H(`p`,{className:`text-xs`,children:[`No device with ID`,` `,H(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,n]})]}),K(`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`})]}):H(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[K(`div`,{className:`mb-2`,children:K(T,{items:[{label:`Integrations`,onClick:()=>i(`/integrations`)},{label:R?.name??N,onClick:()=>R?.id&&i(`/integrations/${R.id}`)},{label:A}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[K($e,{type:N,size:`lg`}),H(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[K(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:A}),K(wt,{status:te}),Re&&K(x,{status:ze,variant:`full`})]}),me!==null&&ge&&H(`button`,{type:`button`,onClick:()=>i(`/devices/${me}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${ge.name}`,children:[K(`span`,{children:`↑`}),K(`span`,{className:`truncate`,children:String(ge.name??`Device #${me}`)})]}),K(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:P.length>0&&K(Ye,{capabilities:P})})]}),Qe&&K(`div`,{className:`hidden lg:flex`,children:K(pr,{metrics:Qe,dbfs:tt})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{xe?await c({title:`Disable "${A}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Ne.mutate({deviceId:n}):Me.mutate({deviceId:n})},disabled:Ge,title:xe?`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 ${xe?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[K(Rt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:Ge?`Updating…`:xe?`Enabled`:`Disabled`})]}),K(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),K(fe,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:ct,disabled:q,onClick:()=>{We()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:rt,hidden:!W,disabled:Pe.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`})&&Pe.mutate({deviceId:n})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??N}.`,icon:nt,disabled:Fe.isPending,danger:!0,onClick:async()=>{await c({title:`Restart "${R?.name??N}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${A}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Fe.mutate({addonId:N})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:yt,separatorBefore:!0,disabled:je.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`})&&je.mutate({deviceId:n})}}]})]})]})]}),K(ue,{deviceId:n,device:k??void 0,children:K(y,{children:K(Ue,{children:K(be,{children:H(`main`,{className:L?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[H(`div`,{className:L?`flex flex-col bg-surface`:`${_===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!L&&_!==null?{width:`${String(_)}px`}:void 0,children:[K(`div`,{className:`flex-shrink-0 border-b border-border-subtle ${ne?`bg-black`:`bg-surface`}`,children:ne?K($t,{deviceId:n,intercomAvailable:P.includes(Je.TwoWayAudio)}):K(Hn,{deviceId:n,deviceName:A,deviceType:F??`unknown`,provider:N,isOnline:j,features:P})}),H(`div`,{className:L?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[K(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:K(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Ae.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>h(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${m===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[K(n,{className:`h-3 w-3`}),t]},e))})}),H(`div`,{className:L?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[m===`logs`&&K(en,{deviceId:n,containerDeviceId:F===`container`?n:void 0}),m===`repl`&&K(tn,{deviceId:n}),m===`events`&&K(nn,{deviceId:n}),m===`state`&&K(rn,{deviceId:n})]})]})]}),!L&&K(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:C,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:K(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),H(`div`,{className:L?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[K(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:K(`div`,{className:`flex flex-wrap items-center gap-0`,children:we.map(e=>{let t=Te===e.id;return H(`button`,{onClick:()=>Ee(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&K(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),H(`div`,{className:L?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[Te===`overview`&&Oe&&K(an,{parentDeviceId:n}),it()]})]})]})})})})})]}):H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),H(`p`,{className:`text-xs`,children:[`The URL segment`,` `,K(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:t.deviceId}),` `,`is not a number.`]}),K(`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 pr({metrics:e,dbfs:t}){let n=Pe(e.phase??`idle`);return H(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[H(`div`,{className:`flex items-center gap-1.5`,children:[K(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),K(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),K(`div`,{className:`h-3 w-px bg-border`}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(Ct,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),K(`span`,{children:`fps`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(gt,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),K(`span`,{children:`ms`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[K(zt,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),K(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&H(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{fr as DeviceDetailPage};
@@ -1 +1 @@
1
- import{R as e,Vn as t,dn as n,in as r,mn as i,nn as a}from"./src-CGgpymf9.js";import{I as o,S as s,W as c,Z as l,o as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{p as f}from"./player-overlays-BgChp7d9.js";import{t as p}from"./ProviderIcon-CWr0L1Zk.js";import{H as m,I as h,o as g,t as _}from"./index-B5O8fiCG.js";import{t as v}from"./AdminPage-vtcsGqRq.js";import{t as y}from"./useEventInvalidation-DI8zcwFR.js";l();function b(){let{t:l}=_(),b=m(),x=f(),S=u();y([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),y([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:C}=n({}),{data:w}=t(void 0),T=i({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=a({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),D=r({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),O=c(()=>C??[],[C]),{activeDevices:k,orphanDevices:A}=c(()=>{let e=new Set((w??[]).map(e=>e.addonId)),t=t=>typeof t.addonId==`string`&&t.addonId.length>0&&!e.has(t.addonId),n=new Set;for(let e of O)t(e)&&n.add(e.id);let r=new Set(n),i=new Map;for(let e of O)i.set(e.id,e);let a=(e,t=0)=>{if(t>32)return!1;if(n.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let r=i.get(e.parentDeviceId);return r?a(r,t+1):!1};for(let e of O)a(e)&&r.add(e.id);let o=[],s=[];for(let e of O)r.has(e.id)?s.push(e):o.push(e);return{activeDevices:o,orphanDevices:s}},[O,w]),j=c(()=>{let e=new Map;for(let t of O)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[O]),M=o(e=>j.get(e)??null,[j]),N=c(()=>(w??[]).map(e=>({id:e.addonId,name:e.name??e.addonId,icon:d(p,{type:e.addonId,size:`sm`})})),[w]),P=o(e=>d(p,{type:e,size:`sm`}),[]),F=o(e=>b(`/devices/${String(e)}`),[b]);return s(v,{icon:h,title:l(`nav.devices`,`Devices`),children:[d(e,{context:`devices`,devices:k,trpc:x.trpcClient,filters:{addons:N},resolveIntegrationIcon:P,resolveParent:M,onNavigate:F,batchActions:{remove:T.mutate,disable:E.mutate,enable:D.mutate}}),A.length>0&&s(`div`,{className:`mt-6 space-y-2`,children:[s(`div`,{className:`flex items-baseline gap-2`,children:[d(g,{className:`h-3.5 w-3.5 text-warning shrink-0`}),d(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Orphan devices`}),s(`span`,{className:`text-[10px] text-foreground-subtle`,children:[A.length,` device`,A.length===1?``:`s`,` pointing at integrations no longer registered`]})]}),s(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:"These devices reference an addonId that has no matching integration. Delete them, or re-install the missing integration to bring them back online. The provider scope (`addonId`) shown beside each row is what's failing to resolve."}),d(e,{context:`devices`,devices:A,trpc:x.trpcClient,filters:{addons:N},urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:P,resolveParent:M,onNavigate:F})]})]})]})}export{b as DevicesPage};
1
+ import{R as e,Vn as t,dn as n,in as r,mn as i,nn as a}from"./src-D2B9pT1o.js";import{I as o,S as s,W as c,Z as l,o as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{p as f}from"./player-overlays-9veDvMBm.js";import{t as p}from"./ProviderIcon-DQymc3er.js";import{H as m,I as h,o as g,t as _}from"./index-BKXQV0wH.js";import{t as v}from"./AdminPage-vtcsGqRq.js";import{t as y}from"./useEventInvalidation-D0AwsYzy.js";l();function b(){let{t:l}=_(),b=m(),x=f(),S=u();y([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]),y([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`]);let{data:C}=n({}),{data:w}=t(void 0),T=i({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),E=a({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),D=r({onSuccess:()=>{S.invalidateQueries({queryKey:[[`deviceManager`]]})}}),O=c(()=>C??[],[C]),{activeDevices:k,orphanDevices:A}=c(()=>{let e=new Set((w??[]).map(e=>e.addonId)),t=t=>typeof t.addonId==`string`&&t.addonId.length>0&&!e.has(t.addonId),n=new Set;for(let e of O)t(e)&&n.add(e.id);let r=new Set(n),i=new Map;for(let e of O)i.set(e.id,e);let a=(e,t=0)=>{if(t>32)return!1;if(n.has(e.id))return!0;if(e.parentDeviceId==null)return!1;let r=i.get(e.parentDeviceId);return r?a(r,t+1):!1};for(let e of O)a(e)&&r.add(e.id);let o=[],s=[];for(let e of O)r.has(e.id)?s.push(e):o.push(e);return{activeDevices:o,orphanDevices:s}},[O,w]),j=c(()=>{let e=new Map;for(let t of O)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[O]),M=o(e=>j.get(e)??null,[j]),N=c(()=>(w??[]).map(e=>({id:e.addonId,name:e.name??e.addonId,icon:d(p,{type:e.addonId,size:`sm`})})),[w]),P=o(e=>d(p,{type:e,size:`sm`}),[]),F=o(e=>b(`/devices/${String(e)}`),[b]);return s(v,{icon:h,title:l(`nav.devices`,`Devices`),children:[d(e,{context:`devices`,devices:k,trpc:x.trpcClient,filters:{addons:N},resolveIntegrationIcon:P,resolveParent:M,onNavigate:F,batchActions:{remove:T.mutate,disable:E.mutate,enable:D.mutate}}),A.length>0&&s(`div`,{className:`mt-6 space-y-2`,children:[s(`div`,{className:`flex items-baseline gap-2`,children:[d(g,{className:`h-3.5 w-3.5 text-warning shrink-0`}),d(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Orphan devices`}),s(`span`,{className:`text-[10px] text-foreground-subtle`,children:[A.length,` device`,A.length===1?``:`s`,` pointing at integrations no longer registered`]})]}),s(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle px-2 pb-2`,children:"These devices reference an addonId that has no matching integration. Delete them, or re-install the missing integration to bring them back online. The provider scope (`addonId`) shown beside each row is what's failing to resolve."}),d(e,{context:`devices`,devices:A,trpc:x.trpcClient,filters:{addons:N},urlScope:`nested`,lsKey:`devices:orphan`,resolveIntegrationIcon:P,resolveParent:M,onNavigate:F})]})]})]})}export{b as DevicesPage};
@@ -1 +1 @@
1
- import{Hi as e,P as t,b as n,i as r}from"./src-CGgpymf9.js";import{K as i,S as a,W as o,Z as s,d as c,u as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{d as f}from"./player-overlays-BgChp7d9.js";import{C as p,D as m,S as h,g,k as _,w as v}from"./schemas-CuE8EXQ7.js";import{S as y}from"./src-Dby7n-bf.js";s();var b=_([v({kind:h(`adaptive`)}),v({kind:h(`profile`),profile:y})]),x=v({serverUrl:m().min(1),token:m().min(1),deviceId:p().int().nonnegative(),target:b,muted:g()});function S(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function C(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function w(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function T(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function E(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=x.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function D({message:e}){return d(()=>{S(`error`,e)},[e]),a(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[`Embed config error: `,e]})}function O({system:e,deviceId:t,initialTarget:a,initialMuted:s}){let[c,l]=i(a),[f,p]=i(s),{handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,getSessionState:y}=r(e.trpcClient,t),x=o(()=>w(c),[c]),E=o(()=>(e,t)=>m(x,e,t),[m,x]),D=o(()=>(e,t,n)=>m(n,t,e),[m]);d(()=>(window.__camstackEmbed={setMuted:e=>p(e),setTarget:e=>{let t=b.safeParse(e);t.success&&l(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let O=T(c);return u(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:u(n,{serverUrl:e.serverUrl,streamKey:O,autoPlay:!0,muted:f,showControls:!1,className:`w-full h-full`,handleOffer:E,reoffer:D,getSessionState:y,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,onStateChange:e=>S(C(e)),onError:e=>S(`error`,e)},O)})}function k(){let n=o(()=>E(),[]),r=o(()=>n.ok?{system:t({serverUrl:n.config.serverUrl,token:n.config.token}),queryClient:new c({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}})}:null,[n]);return d(()=>{if(r)return()=>{r.system.close()}},[r]),n.ok?r?u(f,{system:r.system,children:u(l,{client:r.queryClient,children:u(e.Provider,{client:r.system.trpcClient,queryClient:r.queryClient,children:u(O,{system:r.system,deviceId:n.config.deviceId,initialTarget:n.config.target,initialMuted:n.config.muted})})})}):u(D,{message:`Failed to initialise the embed player`}):u(D,{message:n.error})}export{k as EmbedPlayerPage};
1
+ import{P as e,Ui as t,b as n,i as r}from"./src-D2B9pT1o.js";import{K as i,S as a,W as o,Z as s,d as c,u as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{d as f}from"./player-overlays-9veDvMBm.js";import{C as p,D as m,S as h,g,k as _,w as v}from"./schemas-CuE8EXQ7.js";import{S as y}from"./src-DSe57QNH.js";s();var b=_([v({kind:h(`adaptive`)}),v({kind:h(`profile`),profile:y})]),x=v({serverUrl:m().min(1),token:m().min(1),deviceId:p().int().nonnegative(),target:b,muted:g()});function S(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function C(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function w(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function T(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function E(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=x.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function D({message:e}){return d(()=>{S(`error`,e)},[e]),a(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[`Embed config error: `,e]})}function O({system:e,deviceId:t,initialTarget:a,initialMuted:s}){let[c,l]=i(a),[f,p]=i(s),{handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,getSessionState:y}=r(e.trpcClient,t),x=o(()=>w(c),[c]),E=o(()=>(e,t)=>m(x,e,t),[m,x]),D=o(()=>(e,t,n)=>m(n,t,e),[m]);d(()=>(window.__camstackEmbed={setMuted:e=>p(e),setTarget:e=>{let t=b.safeParse(e);t.success&&l(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let O=T(c);return u(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:u(n,{serverUrl:e.serverUrl,streamKey:O,autoPlay:!0,muted:f,showControls:!1,className:`w-full h-full`,handleOffer:E,reoffer:D,getSessionState:y,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,onStateChange:e=>S(C(e)),onError:e=>S(`error`,e)},O)})}function k(){let n=o(()=>E(),[]),r=o(()=>n.ok?{system:e({serverUrl:n.config.serverUrl,token:n.config.token}),queryClient:new c({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}})}:null,[n]);return d(()=>{if(r)return()=>{r.system.close()}},[r]),n.ok?r?u(f,{system:r.system,children:u(l,{client:r.queryClient,children:u(t.Provider,{client:r.system.trpcClient,queryClient:r.queryClient,children:u(O,{system:r.system,deviceId:n.config.deviceId,initialTarget:n.config.target,initialMuted:n.config.muted})})})}):u(D,{message:`Failed to initialise the embed player`}):u(D,{message:n.error})}export{k as EmbedPlayerPage};
@@ -1 +1 @@
1
- import{C as e,S as t}from"./src-CGgpymf9.js";import{K as n,S as r,Z as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";i();function o(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function s(e,t){if(e!==void 0)return t&&o(e)?t(e):e}function c({section:i,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,probeResults:f,onAction:p}){let[m,h]=n(i.defaultCollapsed??!1),g=i.style===`accordion`;if(i.fields.reduce((t,n)=>t+ +!!e(n,o,i.fields),0)===0)return null;let _=i.columns??2,v=_===1?`grid-cols-1`:_===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:_===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,y=i.fields.length===1&&i.fields[0]?.type===`widget`?i.fields[0]:void 0;return r(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(y!==void 0||!i.title&&!i.description)&&r(`div`,{className:[`flex items-center justify-between mb-2`,g?`cursor-pointer`:``].join(` `),onClick:g?()=>h(e=>!e):void 0,children:[r(`div`,{children:[i.title&&a(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:s(i.title,u)}),i.description&&a(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s(i.description,u)})]}),g&&a(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:m?`▸`:`▾`})]}),!m&&(y===void 0?a(`div`,{className:`grid ${v} gap-x-3 gap-y-2.5`,children:i.fields.map(e=>a(t,{field:e,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[e.key],allFields:i.fields,onAction:p},e.key))}):a(t,{field:y,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[y.key],allFields:i.fields,onAction:p},y.key))]})}function l({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:o,probeResults:s,onClearProbe:l,onAction:u}){let d=(e,r)=>{n({...t,[e]:r}),l?.(e)};return a(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>a(c,{section:e,values:t,onChange:d,disabled:r,translationFn:i,onTestField:o,probeResults:s,onAction:u},`${e.id}-${n}`))})}export{l as t};
1
+ import{C as e,S as t}from"./src-D2B9pT1o.js";import{K as n,S as r,Z as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";i();function o(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function s(e,t){if(e!==void 0)return t&&o(e)?t(e):e}function c({section:i,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,probeResults:f,onAction:p}){let[m,h]=n(i.defaultCollapsed??!1),g=i.style===`accordion`;if(i.fields.reduce((t,n)=>t+ +!!e(n,o,i.fields),0)===0)return null;let _=i.columns??2,v=_===1?`grid-cols-1`:_===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:_===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,y=i.fields.length===1&&i.fields[0]?.type===`widget`?i.fields[0]:void 0;return r(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(y!==void 0||!i.title&&!i.description)&&r(`div`,{className:[`flex items-center justify-between mb-2`,g?`cursor-pointer`:``].join(` `),onClick:g?()=>h(e=>!e):void 0,children:[r(`div`,{children:[i.title&&a(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:s(i.title,u)}),i.description&&a(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s(i.description,u)})]}),g&&a(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:m?`▸`:`▾`})]}),!m&&(y===void 0?a(`div`,{className:`grid ${v} gap-x-3 gap-y-2.5`,children:i.fields.map(e=>a(t,{field:e,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[e.key],allFields:i.fields,onAction:p},e.key))}):a(t,{field:y,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[y.key],allFields:i.fields,onAction:p},y.key))]})}function l({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:o,probeResults:s,onClearProbe:l,onAction:u}){let d=(e,r)=>{n({...t,[e]:r}),l?.(e)};return a(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>a(c,{section:e,values:t,onChange:d,disabled:r,translationFn:i,onTestField:o,probeResults:s,onAction:u},`${e.id}-${n}`))})}export{l as t};
@@ -1 +1 @@
1
- import{Ci as e,Di as t,Ei as n,Ji as r,Oi as i,Pi as a,Si as o,Ti as s,_i as c,at as l,bi as u,c as d,gi as f,hi as p,it as m,mi as h,pa as g,s as _,vi as v,wi as y,xi as b,yi as x}from"./src-CGgpymf9.js";import{K as S,S as C,W as w,Z as T,b as E,o as D,x as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{t as k}from"./circle-check-big-CFjKvleu.js";import{t as A}from"./copy-CP9gtW5J.js";import{t as j}from"./key-round-C_q8xOye.js";import{t as M}from"./AddonCollectionPage-DhriskqS.js";import{t as ee}from"./plus-Dc6XItxw.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-B5O8fiCG.js";import{t as U}from"./AdminPage-vtcsGqRq.js";import{t as W}from"./AdminTabs-d_Q3fhFr.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`}]]);T();function ne({userId:e,username:t,onClose:n}){let r=D(),i=a(),o=v({userId:e}),s=o.data,l=()=>r.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),u=c({onSuccess:()=>{l(),n()}}),d=o.isLoading?`loading`:s?.enabled?`enrolled`:`not_enrolled`;return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[C(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[C(`div`,{className:`flex items-center gap-2`,children:[O(R,{className:`h-4 w-4 text-primary`}),C(`div`,{children:[O(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),C(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,O(`span`,{className:`font-mono`,children:t})]})]})]}),O(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4 space-y-4`,children:[d===`loading`&&C(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[O(H,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),d===`not_enrolled`&&C(`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:[O(P,{className:`h-4 w-4 mt-0.5 shrink-0`}),C(`div`,{children:[O(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),O(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),d===`enrolled`&&s&&C(E,{children:[C(`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:[O(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),C(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[O(`div`,{className:`font-medium`,children:`2FA is active`}),C(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,s.confirmedAt?new Date(s.confirmedAt).toLocaleString():`—`]})]})]}),O(`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.`}),C(`div`,{className:`flex justify-end gap-2`,children:[O(g,{onClick:n,variant:`secondary`,children:`Close`}),C(`button`,{onClick:async()=>{await i({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`})&&u.mutate({userId:e})},disabled:u.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:[u.isPending?O(H,{className:`h-3 w-3 animate-spin`}):O(L,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function Y(){let n=D(),{user:s}=z(),[c,l]=S(!1),[u,d]=S(``),[m,h]=S(``),[g,_]=S(!1),[v,y]=S(null),{data:b,isLoading:x,isError:w}=o(),T=a(),E=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=p({onSuccess:()=>{E(),l(!1),d(``),h(``),_(!1),y(null)},onError:e=>{y(e instanceof Error?e.message:`Failed to create user`)}}),A=f({onSuccess:E}),j=i({onSuccess:E}),M=e({onSuccess:E}),N=t({onSuccess:()=>{E(),F(null)}}),[P,F]=S(null),[V,W]=S(null),G=b??[];async function K(e){await T({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 T({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 C(U,{children:[O(`div`,{className:`flex items-center justify-end`,children:C(`button`,{onClick:()=>l(!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:[O(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),c&&C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-center justify-between`,children:[O(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),O(`button`,{onClick:()=>l(!1),className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`grid grid-cols-3 gap-3`,children:[C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),O(`input`,{type:`text`,value:u,onChange:e=>d(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`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),O(`input`,{type:`password`,value:m,onChange:e=>h(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`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),C(`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:[O(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`rounded border-border focus:ring-primary`}),O(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),v&&O(`p`,{className:`text-[10px] text-danger`,children:v}),C(`div`,{className:`flex justify-end gap-2`,children:[O(`button`,{onClick:()=>l(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>k.mutate({username:u,password:m,isAdmin:g}),disabled:k.isPending||!u||!m,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&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),w&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!w&&G.length===0&&O(`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 O(r,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>C(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[O(`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`}),O(`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 O(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return C(`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:[O(I,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>O(`span`,{className:`text-foreground-subtle`,children:Y(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:t=>{let n=e(t);return C(`div`,{className:`flex items-center justify-end gap-1`,children:[t.id!==s?.id&&t.totpEnabled&&C(`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:[O(R,{className:`h-3 w-3`}),`Remove 2FA`]}),C(`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:[O(te,{className:`h-3 w-3`}),`Reset password`]}),C(`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?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),V&&O(ne,{userId:V.id,username:V.username,onClose:()=>W(null)}),P&&O(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 O(ie,{...e,callerScopes:n?null:t?.scopes??[]})}function ie({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=S(w(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=d(a);return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:C(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[C(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[C(`div`,{children:[C(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),O(`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.`})]}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`px-4 py-4`,children:[O(_,{value:a,onChange:o,clampToParent:i,emptyHint:C(E,{children:[`No scopes granted.`,` `,O(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&O(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),C(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`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?O(H,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}T();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 e=D(),t=a(),{data:r,isLoading:i}=x(),{data:s}=o(),c=w(()=>r??[],[r]),l=w(()=>s??[],[s]),u=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),d=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[f,p]=S(!1),[m,g]=S(null),_=y({onSuccess:u}),v=h({onSuccess:({token:e,record:t})=>{d(),p(!1),g({token:e,label:t.name})}}),b=n({onSuccess:d}),T=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&_.mutate({id:e})},E=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&b.mutate({id:e})};return C(U,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(`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.`}),C(`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:[O(I,{className:`h-3.5 w-3.5`}),`New token`]})]}),C(Z,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[l.length===0&&O(ue,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),l.map(e=>O(fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{E(e,t)},revokePending:b.isPending,revokeId:b.variables?.id},e.id))]}),c.length>0&&O(Z,{title:`Legacy API keys`,subtitle:`${c.length} pre-existing — revoke only`,children:O(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 C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?ae:oe}`,children:t?`admin`:`regular`})}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:se(e.allowedProviders)||`all`}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>{T(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?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),i&&O(le,{}),f&&O(pe,{users:l.map(e=>({id:e.id,username:e.username})),onClose:()=>p(!1),onSubmit:e=>v.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:v.isPending}),m&&O(me,{token:m.token,label:m.label,onClose:()=>g(null)})]})}function Z({title:e,subtitle:t,children:n}){return C(`div`,{className:`space-y-2`,children:[C(`div`,{className:`flex items-baseline justify-between`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&O(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function le(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ue({text:e}){return O(`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 O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`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))})}),O(`tbody`,{children:t})]})})}function fe({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=b({userId:e}),s=a??[];return o||s.length===0?null:C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),O(de,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>C(`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))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.expiresAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`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?O(H,{className:`h-3 w-3 animate-spin`}):O(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,l]=S(``),[u,f]=S([{type:`capability`,target:``,access:[`view`,`create`]}]),[p,m]=S(``),h=d(u),g=o!==``&&c.trim().length>0&&u.length>0&&h===null&&!r;return C(he,{title:`Create scoped token`,onClose:t,children:[C(`div`,{className:`space-y-3`,children:[O(Q,{label:`On behalf of user`,children:O(`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=>O(`option`,{value:e.id,children:e.username},e.id))})}),O(Q,{label:`Name`,children:O(`input`,{value:c,onChange:e=>l(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`})}),C(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:[O(_,{value:u,onChange:f,clampToParent:a}),h&&O(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),O(Q,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:O(`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`})})]}),C(ge,{children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),C(`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:u,expiresAt:t})},disabled:!g,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?O(H,{className:`h-3.5 w-3.5 animate-spin`}):O(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 C(he,{title:`Token: ${t}`,onClose:n,children:[C(`div`,{className:`space-y-3`,children:[O(`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.`}),O(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),C(ge,{children:[C(`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?O(F,{className:`h-3.5 w-3.5 text-primary`}):O(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),O(`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 O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),O(`div`,{className:`p-4`,children:n})]})})}function ge({children:e}){return O(`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 C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&O(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}T();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 O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ye({text:e}){return O(`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 O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`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))})}),O(`tbody`,{children:t})]})})}function xe(){let e=D(),t=a(),{data:n,isLoading:r}=u(),i=w(()=>n??[],[n]),o=s({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),c=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 C(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:[r&&O(ve,{}),!r&&i.length===0&&O(ye,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!r&&i.length>0&&O(be,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:i.map(e=>{let t=e.revokedAt!==null,n=(o.isPending?o.variables?.id:void 0)===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>O(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:_e(e)},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border`,children:t?C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,$(e.revokedAt)]}):O(`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`})}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&C(`button`,{onClick:()=>{c(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?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}T();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=l({capName:`auth-provider`},{refetchInterval:Se}),t=m(void 0,{refetchInterval:Se}),n=w(()=>Ce(t.data??[]),[t.data]);return O(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:w(()=>(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=>O(Ee,{addonId:e.addonId})})}function Ee({addonId:e}){let t=we(e),n=t.icon;return C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-start gap-2.5`,children:[O(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),O(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),O(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>O(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[C(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[O(G,{className:`h-3 w-3`}),`Setup steps`]}),O(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>O(`li`,{children:e},t))})]}),e===`local-auth`&&C(`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:[O(P,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),C(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,O(`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 O(`div`,{className:`flex flex-col p-4`,children:O(W,{tabs:[{id:`users`,label:`Users`,icon:J,content:O(Y,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:O(ce,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:O(xe,{})},{id:`authentication`,label:`Authentication`,icon:I,content:O(Te,{})}]})})}export{De as IdentityPage};
1
+ import{Ci as e,Di as t,Ei as n,Fi as r,Oi as i,Si as a,Ti as o,Yi as s,_i as c,at as l,bi as u,c as d,gi as f,hi as p,it as m,ma as h,mi as g,s as _,vi as v,wi as y,xi as b,yi as x}from"./src-D2B9pT1o.js";import{K as S,S as C,W as w,Z as T,b as E,o as D,x as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{t as k}from"./circle-check-big-CsyfP7ea.js";import{t as A}from"./copy-DAz6rXSh.js";import{t as j}from"./key-round-qLocTDSs.js";import{t as M}from"./AddonCollectionPage-B_2tbR4h.js";import{t as ee}from"./plus-Bect3wmG.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-BKXQV0wH.js";import{t as U}from"./AdminPage-vtcsGqRq.js";import{t as W}from"./AdminTabs-ggcZSYRo.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`}]]);T();function ne({userId:e,username:t,onClose:n}){let i=D(),a=r(),o=v({userId:e}),s=o.data,l=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),u=c({onSuccess:()=>{l(),n()}}),d=o.isLoading?`loading`:s?.enabled?`enrolled`:`not_enrolled`;return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[C(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[C(`div`,{className:`flex items-center gap-2`,children:[O(R,{className:`h-4 w-4 text-primary`}),C(`div`,{children:[O(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),C(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,O(`span`,{className:`font-mono`,children:t})]})]})]}),O(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4 space-y-4`,children:[d===`loading`&&C(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[O(H,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),d===`not_enrolled`&&C(`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:[O(P,{className:`h-4 w-4 mt-0.5 shrink-0`}),C(`div`,{children:[O(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),O(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),d===`enrolled`&&s&&C(E,{children:[C(`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:[O(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),C(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[O(`div`,{className:`font-medium`,children:`2FA is active`}),C(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,s.confirmedAt?new Date(s.confirmedAt).toLocaleString():`—`]})]})]}),O(`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.`}),C(`div`,{className:`flex justify-end gap-2`,children:[O(h,{onClick:n,variant:`secondary`,children:`Close`}),C(`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`})&&u.mutate({userId:e})},disabled:u.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:[u.isPending?O(H,{className:`h-3 w-3 animate-spin`}):O(L,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function Y(){let n=D(),{user:o}=z(),[c,l]=S(!1),[u,d]=S(``),[m,h]=S(``),[g,_]=S(!1),[v,y]=S(null),{data:b,isLoading:x,isError:w}=a(),T=r(),E=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=p({onSuccess:()=>{E(),l(!1),d(``),h(``),_(!1),y(null)},onError:e=>{y(e instanceof Error?e.message:`Failed to create user`)}}),A=f({onSuccess:E}),j=i({onSuccess:E}),M=e({onSuccess:E}),N=t({onSuccess:()=>{E(),F(null)}}),[P,F]=S(null),[V,W]=S(null),G=b??[];async function K(e){await T({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 T({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 C(U,{children:[O(`div`,{className:`flex items-center justify-end`,children:C(`button`,{onClick:()=>l(!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:[O(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),c&&C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-center justify-between`,children:[O(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),O(`button`,{onClick:()=>l(!1),className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`grid grid-cols-3 gap-3`,children:[C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),O(`input`,{type:`text`,value:u,onChange:e=>d(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`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),O(`input`,{type:`password`,value:m,onChange:e=>h(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`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),C(`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:[O(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`rounded border-border focus:ring-primary`}),O(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),v&&O(`p`,{className:`text-[10px] text-danger`,children:v}),C(`div`,{className:`flex justify-end gap-2`,children:[O(`button`,{onClick:()=>l(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>k.mutate({username:u,password:m,isAdmin:g}),disabled:k.isPending||!u||!m,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&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),w&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!w&&G.length===0&&O(`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 O(s,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>C(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[O(`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`}),O(`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 O(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return C(`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:[O(I,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>O(`span`,{className:`text-foreground-subtle`,children:Y(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:t=>{let n=e(t);return C(`div`,{className:`flex items-center justify-end gap-1`,children:[t.id!==o?.id&&t.totpEnabled&&C(`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:[O(R,{className:`h-3 w-3`}),`Remove 2FA`]}),C(`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:[O(te,{className:`h-3 w-3`}),`Reset password`]}),C(`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?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),V&&O(ne,{userId:V.id,username:V.username,onClose:()=>W(null)}),P&&O(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 O(ie,{...e,callerScopes:n?null:t?.scopes??[]})}function ie({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=S(w(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=d(a);return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:C(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[C(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[C(`div`,{children:[C(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),O(`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.`})]}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`px-4 py-4`,children:[O(_,{value:a,onChange:o,clampToParent:i,emptyHint:C(E,{children:[`No scopes granted.`,` `,O(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&O(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),C(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`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?O(H,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}T();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 e=D(),t=r(),{data:i,isLoading:o}=x(),{data:s}=a(),c=w(()=>i??[],[i]),l=w(()=>s??[],[s]),u=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),d=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[f,p]=S(!1),[m,h]=S(null),_=y({onSuccess:u}),v=g({onSuccess:({token:e,record:t})=>{d(),p(!1),h({token:e,label:t.name})}}),b=n({onSuccess:d}),T=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&_.mutate({id:e})},E=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&b.mutate({id:e})};return C(U,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(`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.`}),C(`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:[O(I,{className:`h-3.5 w-3.5`}),`New token`]})]}),C(Z,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[l.length===0&&O(ue,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),l.map(e=>O(fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{E(e,t)},revokePending:b.isPending,revokeId:b.variables?.id},e.id))]}),c.length>0&&O(Z,{title:`Legacy API keys`,subtitle:`${c.length} pre-existing — revoke only`,children:O(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 C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?ae:oe}`,children:t?`admin`:`regular`})}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:se(e.allowedProviders)||`all`}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>{T(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?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),o&&O(le,{}),f&&O(pe,{users:l.map(e=>({id:e.id,username:e.username})),onClose:()=>p(!1),onSubmit:e=>v.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:v.isPending}),m&&O(me,{token:m.token,label:m.label,onClose:()=>h(null)})]})}function Z({title:e,subtitle:t,children:n}){return C(`div`,{className:`space-y-2`,children:[C(`div`,{className:`flex items-baseline justify-between`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&O(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function le(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ue({text:e}){return O(`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 O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`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))})}),O(`tbody`,{children:t})]})})}function fe({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=b({userId:e}),s=a??[];return o||s.length===0?null:C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),O(de,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>C(`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))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.expiresAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`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?O(H,{className:`h-3 w-3 animate-spin`}):O(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,l]=S(``),[u,f]=S([{type:`capability`,target:``,access:[`view`,`create`]}]),[p,m]=S(``),h=d(u),g=o!==``&&c.trim().length>0&&u.length>0&&h===null&&!r;return C(he,{title:`Create scoped token`,onClose:t,children:[C(`div`,{className:`space-y-3`,children:[O(Q,{label:`On behalf of user`,children:O(`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=>O(`option`,{value:e.id,children:e.username},e.id))})}),O(Q,{label:`Name`,children:O(`input`,{value:c,onChange:e=>l(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`})}),C(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:[O(_,{value:u,onChange:f,clampToParent:a}),h&&O(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),O(Q,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:O(`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`})})]}),C(ge,{children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),C(`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:u,expiresAt:t})},disabled:!g,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?O(H,{className:`h-3.5 w-3.5 animate-spin`}):O(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 C(he,{title:`Token: ${t}`,onClose:n,children:[C(`div`,{className:`space-y-3`,children:[O(`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.`}),O(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),C(ge,{children:[C(`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?O(F,{className:`h-3.5 w-3.5 text-primary`}):O(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),O(`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 O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),O(`div`,{className:`p-4`,children:n})]})})}function ge({children:e}){return O(`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 C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&O(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}T();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 O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ye({text:e}){return O(`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 O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`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))})}),O(`tbody`,{children:t})]})})}function xe(){let e=D(),t=r(),{data:n,isLoading:i}=u(),a=w(()=>n??[],[n]),s=o({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),c=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`})&&s.mutate({id:e})};return C(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&&O(ve,{}),!i&&a.length===0&&O(ye,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!i&&a.length>0&&O(be,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:a.map(e=>{let t=e.revokedAt!==null,n=(s.isPending?s.variables?.id:void 0)===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>O(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:_e(e)},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border`,children:t?C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,$(e.revokedAt)]}):O(`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`})}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&C(`button`,{onClick:()=>{c(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?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}T();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=l({capName:`auth-provider`},{refetchInterval:Se}),t=m(void 0,{refetchInterval:Se}),n=w(()=>Ce(t.data??[]),[t.data]);return O(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:w(()=>(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=>O(Ee,{addonId:e.addonId})})}function Ee({addonId:e}){let t=we(e),n=t.icon;return C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-start gap-2.5`,children:[O(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),O(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),O(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>O(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[C(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[O(G,{className:`h-3 w-3`}),`Setup steps`]}),O(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>O(`li`,{children:e},t))})]}),e===`local-auth`&&C(`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:[O(P,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),C(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,O(`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 O(`div`,{className:`flex flex-col p-4`,children:O(W,{tabs:[{id:`users`,label:`Users`,icon:J,content:O(Y,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:O(ce,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:O(xe,{})},{id:`authentication`,label:`Authentication`,icon:I,content:O(Te,{})}]})})}export{De as IdentityPage};
@@ -0,0 +1 @@
1
+ import{$t as e,Bn as t,Hn as n,In as r,J as i,Kt as a,Ln as o,Mi as s,Ni as c,Qt as l,R as u,Rn as d,Wn as f,Xi as p,Zt as m,d as h,dn as g,g as _,in as v,lt as y,mn as ee,nn as b,sn as x,tn as te,ua as S,x as C,xn as w,z as ne}from"./src-D2B9pT1o.js";import{G as T,I as E,K as D,S as O,W as k,Z as A,b as j,o as M,x as N,z as re}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{p as P}from"./player-overlays-9veDvMBm.js";import{b as F}from"./src-DSe57QNH.js";import{t as I}from"./ProviderIcon-DQymc3er.js";import{t as ie}from"./plus-Bect3wmG.js";import{t as L}from"./refresh-cw-CafZo9UJ.js";import{t as R}from"./rotate-cw-BAmtYX09.js";import{t as z}from"./wifi-DcA7zdx0.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-BKXQV0wH.js";import{t as Y}from"./FormBuilder-w0_WI3Ka.js";import{t as X}from"./BrokerStep-8svkw89A.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`}]]);A();function Z(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Z(n.fields));return t}function pe(e,t,n){let[r,i]=D(`idle`),[a,o]=D({}),s=k(()=>{let t=[];for(let n of e.sections)t.push(...Z(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=E(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:E(async()=>{if(!n)return;let e=s.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;i(`testing`);let r={};for(let t of e)r[t]={status:`probing`};o(r);let a=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await n(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),c={};for(let e of a)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;c[t]={status:n.status===`ok`?`ok`:`error`,result:n}}o(c),i(`idle`)},[n,s,t]),clearProbeResult:l}}A();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=M(),[o,s]=D({}),[c,l]=D(!1),[u,d]=D(null),[f,p]=D(Q),m=x({addonId:n,type:F.Camera},{enabled:e}),h=m.data??null;re(()=>{e&&(s(h?ge(h.sections.flatMap(e=>e.fields)):{}),p(Q()),l(!1),d(null))},[e,t,h]);let g=k(()=>({...o,_probeRequestId:f}),[o,f]),v=te({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),y=w(),ee=E(async(e,t)=>{l(!0);let r=await y.mutateAsync({addonId:n,type:F.Camera,key:e,value:t,formValues:g});return r.status===`ok`&&r.suggestedValues&&s(e=>{let t=!1,n={...e};for(let[i,a]of Object.entries(r.suggestedValues??{}))he(e[i])&&!he(a)&&(n[i]=a,t=!0);return t?n:e}),r},[y,n,g]),{testAllStatus:b,hasProbeFields:S,probeResults:C,handleTestAll:ne,clearProbeResult:T}=pe(h??{sections:[]},o,ee);async function A(e){d(null);try{await v.mutateAsync({addonId:n,type:F.Camera,config:o,integrationId:t}),e?s(h?ge(h.sections.flatMap(e=>e.fields)):{}):r()}catch(e){d(e instanceof Error?e.message:String(e))}}if(!e)return null;let j=me((h?.sections??[]).flatMap(e=>e.fields)).filter(e=>he(o[e])),P=j.length===0,I=!m.isLoading&&(m.isError||h===null);return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[N(`div`,{className:`absolute inset-0 bg-black/60`,onClick:r}),O(`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:[O(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[N(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`integrations.addDevice`)}),N(`button`,{onClick:r,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:N(G,{className:`h-4 w-4`})})]}),N(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:m.isLoading?N(`div`,{className:`flex items-center justify-center py-8`,children:N(J,{className:`h-5 w-5 animate-spin text-primary`})}):I?O(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[N(K,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),O(`div`,{className:`space-y-1`,children:[N(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),O(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,N(`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.`]})]})]}):N(Y,{schema:h,values:o,onChange:s,onTestField:ee,probeResults:C,onClearProbe:T})}),!I&&!m.isLoading&&O(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[O(`button`,{type:`button`,onClick:()=>l(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[O(`span`,{className:`flex items-center gap-2`,children:[N(ue,{className:`h-3.5 w-3.5`}),`Test logs`,N(`span`,{className:`font-mono text-[9px] opacity-60`,children:f.slice(0,14)})]}),N(H,{className:`h-3.5 w-3.5 transition-transform ${c?`rotate-180`:``}`})]}),c&&N(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:N(_,{addonId:n,requestId:f,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!I&&!m.isLoading&&(u||j.length>0)&&N(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:O(`div`,{className:`flex items-start gap-2`,children:[N(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),N(`p`,{className:`text-[11px] text-destructive`,children:u||`Required: ${j.join(`, `)}`})]})}),O(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[O(`div`,{className:`flex items-center gap-2`,children:[N(`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`)}),!I&&S&&O(`button`,{type:`button`,onClick:ne,disabled:b===`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:[b===`testing`?N(J,{className:`h-3.5 w-3.5 animate-spin`}):N(z,{className:`h-3.5 w-3.5`}),`Test All`]})]}),O(`div`,{className:`flex items-center gap-2`,children:[N(`button`,{onClick:()=>A(!0),disabled:I||!P||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`)}),N(`button`,{onClick:()=>A(!1),disabled:I||!P||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(` `)}A();var $=`devices`,ye={id:$,label:`Devices`,isDefault:!0},be=2e4,xe=100;function Se({addonId:t,integrationId:n,onClose:r}){let{t:i}=q(),[o,f]=D(new Set),[p,h]=D(new Set),[g,_]=D(new Map),[v,y]=D(null),{data:ee}=d(),b=(ee??[]).find(e=>e.addonId===t)?.supportsLocationImport??!1,[x,te]=D(!0),S=a({integrationId:n}).data?.filters,C=S&&S.length>0?S:[ye],[w,ne]=D(C.find(e=>e.isDefault)?.id??(C.some(e=>e.id===$)?$:C[0].id)),k=w!==$,A=e(),j=l({addonId:t,integrationId:n,page:1,pageSize:be,filter:w}),M=j.refetch,P=A.mutate,F=E(()=>{P({addonId:t,integrationId:n},{onSettled:()=>{M()}})},[P,t,n,M]),I=T(null);re(()=>{let e=`${t}::${n}`;I.current===e||j.isLoading||(I.current=e,(j.data?.candidates.length??0)===0&&F())},[t,n,j.isLoading,j.data,F]);let ie=A.isPending,L=A.isError?A.error instanceof Error?A.error.message:String(A.error):null,z=j.data?.candidates??[],B=j.isError?j.error instanceof Error?j.error.message:String(j.error):null,V=m(),oe=E(e=>{e.alreadyAdopted||f(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),se=E(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),H=E((e,t)=>{_(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=E(e=>{let t={};for(let n of e){let e=g.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[g]),U=E(async()=>{y(null);let e=[...o];if(e.length!==0)try{let i=ce(e);await V.mutateAsync({addonId:t,integrationId:n,filter:w,childNativeIds:e,...i?{perCandidate:i}:{},...b?{importLocations:x}:{}}),f(new Set),_(new Map),await M(),r()}catch(e){y(e instanceof Error?e.message:String(e))}},[o,ce,V,t,n,w,M,b,x]),le=E(e=>{ne(e),f(new Set),h(new Set),_(new Map),y(null)},[]),W=o.size;return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[N(`div`,{className:`absolute inset-0 bg-black/60`,onClick:r}),O(`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:[O(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[O(`div`,{className:`min-w-0`,children:[N(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),N(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:i(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),O(`div`,{className:`flex items-center gap-3 shrink-0`,children:[b&&O(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[N(`input`,{type:`checkbox`,checked:x,onChange:e=>te(e.target.checked),className:`accent-primary`}),i(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),N(`button`,{onClick:r,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:N(G,{className:`h-4 w-4`})})]})]}),O(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(L??B)&&z.length===0&&N(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:O(`div`,{className:`flex items-start gap-2`,children:[N(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),O(`div`,{className:`min-w-0`,children:[N(`p`,{className:`text-xs font-medium text-destructive`,children:i(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),N(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:L??B})]})]})}),C.length>1&&N(Ce,{filters:C,activeFilter:w,onSelect:le}),N(`div`,{className:`flex-1 min-h-0`,children:N(u,{mode:`generic`,items:z,pageSize:xe,getKey:e=>e.childNativeId,getSearchText:ve,getFilterType:e=>e.type,filterOptions:s(),filterLabel:i(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:j.isLoading||ie&&z.length===0,searchPlaceholder:i(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(L??B)&&z.length===0?``:i(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:O(`button`,{type:`button`,onClick:F,disabled:ie,title:i(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[N(R,{className:`h-3.5 w-3.5 ${ie?`animate-spin`:``}`}),i(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:i(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>N(we,{candidate:e,expandable:!k,expanded:p.has(e.childNativeId),onToggleExpand:()=>se(e.childNativeId),adoptedLabel:i(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:i(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=c(e.type),n=t.icon;return O(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[N(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=>N(`div`,{className:`flex items-center justify-end`,children:N(`button`,{onClick:()=>oe(e),disabled:e.alreadyAdopted,"aria-label":o.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${o.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:o.has(e.childNativeId)&&N(ae,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!k&&p.has(e.childNativeId),renderExpanded:k?void 0:e=>N(Te,{candidate:e,hiddenChildIds:g.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>H(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:o.has(e.childNativeId)?`bg-primary/5`:``})})]}),v&&N(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:O(`div`,{className:`flex items-start gap-2`,children:[N(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),N(`p`,{className:`text-[11px] text-destructive`,children:v})]})}),O(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[N(`div`,{}),O(`div`,{className:`flex items-center gap-2`,children:[N(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.cancel`,{defaultValue:`Cancel`})}),O(`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&&N(J,{className:`h-3.5 w-3.5 animate-spin`}),i(`integrations.addSelected`,{defaultValue:`Add selected`}),W>0?` (${W})`:``]})]})]})]})]})}function Ce({filters:e,activeFilter:t,onSelect:n}){return N(`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 N(`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 O(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?O(`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:[N(n?H:se,{className:`h-3.5 w-3.5`}),a]}):N(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),N(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&N(`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:N(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return O(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[N(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&N(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),N(`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:N(r?V:U,{className:`h-3 w-3`})})]},e.childNativeId)})})}A();function Ee({integrationId:e,addonId:r,name:i,kind:a,brokerKind:o,trpc:s,onClose:c}){let{t:l}=q(),u=M(),d=a===`device-adoption`,{data:f}=t({id:e},{enabled:d}),p=k(()=>{let e=f?.brokerId;return typeof e==`string`?e:null},[f]),m=n();return N(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:c,children:O(`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:[O(`div`,{className:`mb-3 flex items-center justify-between`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:[l(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,i]}),N(`button`,{onClick:c,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":l(`common.close`,{defaultValue:`Close`}),children:N(G,{className:`h-4 w-4`})})]}),d?o?O(`div`,{className:`space-y-3`,children:[N(`p`,{className:`text-[11px] text-foreground-subtle`,children:l(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),p&&O(`p`,{className:`text-[11px] text-foreground`,children:[l(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,N(`span`,{className:`font-mono text-foreground-subtle`,children:p})]}),m.isPending?O(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[N(J,{className:`h-3 w-3 animate-spin`}),l(`integrations.saving`,{defaultValue:`Saving…`})]}):N(X,{kind:o,onResolved:t=>{m.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{u.invalidateQueries(),c()}})},onBack:c}),m.isError&&N(`p`,{className:`text-[11px] text-danger`,children:l(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):N(`p`,{className:`text-[11px] text-danger`,children:l(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):N(C,{trpc:s,addonId:r,nodeId:`hub`,title:i})]})})}A();function De(){let{t:e}=q(),{integrationId:t}=le(),n=M(),a=oe(),s=P(),[c,l]=D(!1),[m,x]=D(!1),[te,C]=D(!1),[w,T]=D(!1),{data:A,isLoading:re}=o({id:t??``},{enabled:!!t}),{data:F}=i({addonId:A?.addonId??``,nodeId:`hub`},{enabled:!!A?.addonId}),{data:R,isSuccess:z}=d(),B=k(()=>{let e=A?.addonId;return!e||!z?null:(R??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[R,A?.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=k(()=>{let e=A?.addonId;return!e||!z?null:(R??[]).find(t=>t.addonId===e)?.brokerKind??null},[R,A?.addonId,z]),H=F!=null&&Array.isArray(F.sections)&&F.sections.some(e=>e.fields.length>0),{data:U}=g({},{refetchInterval:5e3}),Y=[[`integrations`,`get`],{input:{id:t??``},type:`query`}],X=f({onMutate:async e=>{await n.cancelQueries({queryKey:Y});let t=n.getQueryData(Y);return t!=null&&n.setQueryData(Y,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,r)=>{let i=r;i?.previous!=null&&n.setQueryData(Y,i.previous)},onSettled:()=>{n.invalidateQueries({queryKey:[[`integrations`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=r({onSuccess:()=>{n.invalidateQueries({queryKey:[[`integrations`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]}),C(!1),a(`/integrations`)}}),pe=y({onSuccess:()=>{n.invalidateQueries({queryKey:[[`integrations`]]}),n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),me=ee({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),he=b({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ge=v({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=k(()=>U??[],[U]),ve=k(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),$=E(e=>ve.get(e)??null,[ve]),ye=E(e=>N(I,{type:e,size:`sm`}),[]),be=E(e=>a(`/devices/${String(e)}`),[a]),xe=k(()=>{let e=A?.addonId;return e?Q.filter(t=>t.addonId===e):[]},[Q,A?.addonId]),Ce=k(()=>ne(xe).length,[xe]);return re?O(`div`,{className:`p-4`,children:[N(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),N(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):A?O(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[N(p,{items:[{label:`Integrations`,onClick:()=>a(`/integrations`)},{label:A.name}]}),O(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[O(`div`,{className:`flex items-center gap-3 min-w-0`,children:[N(`img`,{src:`/api/addon-assets/${A.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),O(`div`,{className:`min-w-0`,children:[N(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:A.name}),O(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[A.addonId,` · `,Ce,` `,e(`integrations.devices`)]})]})]}),O(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[O(`button`,{onClick:()=>l(!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:[N(ie,{className:`h-3.5 w-3.5`}),ae]}),O(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${X.isPending?`opacity-60`:``} ${A.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[N(S,{checked:A.enabled,onCheckedChange:e=>X.mutate({id:t,enabled:e}),disabled:X.isPending,"aria-label":A.enabled?`Disable integration`:`Enable integration`}),N(`span`,{className:`text-[11px] font-medium ${A.enabled?`text-success`:`text-foreground-subtle`}`,children:A.enabled?`Enabled`:`Disabled`}),X.isPending&&N(J,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),(H||B===`device-adoption`)&&O(`button`,{onClick:()=>x(!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:[N(W,{className:`h-3 w-3`}),e(`integrations.config`)]}),O(`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:[N(ue,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),N(h,{label:`Restart`,icon:L,title:`Restart "${A.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ce} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:pe.isPending,action:()=>pe.mutateAsync({addonId:A.addonId})}),O(`button`,{onClick:()=>C(!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:[N(de,{className:`h-3 w-3`}),e(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),N(u,{context:`integration-detail`,devices:Q,trpc:s.trpcClient,defaultView:`cards`,forceAddon:A.addonId,urlScope:`root`,lsKey:`integration-detail:${A.addonId}`,resolveIntegrationIcon:ye,resolveParent:$,onNavigate:be,batchActions:{remove:me.mutate,disable:he.mutate,enable:ge.mutate},onDeleteDevice:e=>me.mutate({deviceId:e.id})}),c&&t&&B===`device-adoption`&&N(Se,{addonId:A.addonId,integrationId:t,onClose:()=>l(!1)}),c&&t&&B===`device-provider`&&N(_e,{open:c,integrationId:t,addonId:A.addonId,onClose:()=>l(!1)}),m&&t&&B!==null&&N(Ee,{integrationId:t,addonId:A.addonId,name:A.name,kind:B,brokerKind:se,trpc:s.trpcClient,onClose:()=>x(!1)}),w&&N(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>T(!1),children:O(`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:[O(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[O(`div`,{className:`flex items-center gap-2 min-w-0`,children:[N(ue,{className:`h-4 w-4 text-primary shrink-0`}),N(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:A.name}),O(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[A.addonId,t?` · ${t}`:``]})]}),N(`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:N(G,{className:`h-4 w-4`})})]}),N(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:N(_,{addonId:A.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),te&&N(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Z.isPending&&C(!1),children:O(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[O(`div`,{className:`flex items-start gap-3`,children:[N(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:N(K,{className:`h-4 w-4 text-danger`})}),O(`div`,{className:`min-w-0`,children:[N(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),N(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:A.name,count:Ce})})]})]}),Z.error&&N(`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)}),O(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[N(`button`,{onClick:()=>C(!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`})}),N(`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?O(j,{children:[N(J,{className:`h-3 w-3 animate-spin`}),e(`integrations.deleting`,{defaultValue:`Deleting…`})]}):O(j,{children:[N(de,{className:`h-3 w-3`}),e(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):O(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[N(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:N(fe,{className:`h-6 w-6 text-foreground-subtle`})}),O(`div`,{className:`space-y-1 max-w-sm`,children:[N(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),N(`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??``})})]}),O(`button`,{onClick:()=>a(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[N(ce,{className:`h-3 w-3`}),e(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{De as IntegrationDetailPage};
@@ -0,0 +1 @@
1
+ import{Fn as e,J as t,R as n,Rn as r,Un as i,Vn as a,Xt as o,dn as s,rn as c,xa as l,z as u}from"./src-D2B9pT1o.js";import{I as d,K as f,S as p,W as m,Z as h,b as ee,o as g,x as _,z as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{p as y}from"./player-overlays-9veDvMBm.js";import{t as b}from"./ProviderIcon-DQymc3er.js";import{t as x}from"./plus-Bect3wmG.js";import{t as S}from"./refresh-cw-CafZo9UJ.js";import{F as C,H as w,I as T,M as E,P as D,W as O,f as k,g as A,i as j,t as M,x as N}from"./index-BKXQV0wH.js";import{t as P}from"./AdminPage-vtcsGqRq.js";import{t as F}from"./StatusBadge-BSsUNFG6.js";import{t as I}from"./FormBuilder-w0_WI3Ka.js";import{t as L}from"./useEventInvalidation-D0AwsYzy.js";import{t as R}from"./BrokerStep-8svkw89A.js";import{t as z}from"./useBodyScrollLock-B2OWVaf_.js";h();function B({onSelect:e,onClose:t,pendingAddonId:n=null}){let{t:i}=M(),a=w(),{data:o,isLoading:s}=r();if(s)return _(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let c=n!==null;return p(`div`,{className:`space-y-2`,children:[(o??[]).map(r=>{let o=r.instanceMode===`unique`&&r.existingInstances.length>0,s=n===r.addonId,l=c;return p(`button`,{disabled:l,onClick:()=>{if(!l)if(o){let e=r.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(r.addonId,r.instanceMode,r.discoveryMode,r.name,r.kind,r.brokerKind)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[r.iconUrl?_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${r.color}15`},children:_(`img`,{src:r.iconUrl,alt:``,className:`h-5 w-5`})}):_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${r.color}15`},children:_(`span`,{className:`text-sm`,style:{color:r.color},children:`◉`})}),p(`div`,{className:`flex-1 min-w-0`,children:[_(`p`,{className:`text-xs font-semibold text-foreground`,children:r.name}),r.description&&_(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:r.description})]}),s?_(N,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):o?p(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[_(k,{className:`h-3 w-3`}),i(`integrations.manage`)]}):_(E,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},r.addonId)}),(o??[]).length===0&&_(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}function te({addonId:e,configSchema:t,onSave:n,onBack:r}){let{t:a}=M(),[o,s]=f(``),[c,l]=f({}),[u,d]=f(null),m=i({onSuccess:e=>d(e),onError:e=>d({success:!1,error:String(e)})});return p(`div`,{className:`space-y-4`,children:[p(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:a(`integrations.integrationName`)}),_(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&_(I,{schema:t,values:c,onChange:l}),u&&_(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${u.success?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:u.success?a(`integrations.connectionSuccess`):`${a(`integrations.errorPrefix`)} ${u.error}`}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.back`)}),p(`div`,{className:`flex items-center gap-2`,children:[_(`button`,{onClick:()=>m.mutate({addonId:e,settings:c}),disabled:m.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:m.isPending?a(`integrations.testing`):a(`integrations.testConnection`)}),_(`button`,{onClick:()=>n({name:o,config:c}),disabled:!o.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:a(`integrations.forward`)})]})]})]})}h();function V({providerId:e,onImport:t,onSkip:n}){let{t:r}=M(),[i,a]=f(new Set),o=c(),s=o.data,l=o.isPending||!o.data&&!o.isError;v(()=>{e&&(o.isPending||o.data||o.mutate({addonId:e}))},[e,o]);function u(e){a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(l)return p(`div`,{className:`flex flex-col items-center py-12`,children:[_(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),_(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:r(`integrations.searchingDevices`)})]});let d=s??[];return p(`div`,{className:`space-y-4`,children:[_(`p`,{className:`text-xs text-foreground-subtle`,children:d.length>0?r(`integrations.foundDevices`,{count:d.length}):r(`integrations.noDevicesFound`)}),d.length>0&&_(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:d.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=i.has(t);return p(`button`,{onClick:()=>u(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[_(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r?`border-primary bg-primary`:`border-border`}`,children:r&&_(C,{className:`h-3 w-3 text-primary-foreground`})}),_(T,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),_(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n})]},t)})}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.skip`)}),d.length>0&&p(`button`,{onClick:()=>t(Array.from(i)),disabled:i.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[r(`integrations.importSelected`),` (`,i.size,`)`]})]})]})}h();function H(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}function U({open:n,onClose:r}){let{t:i}=M(),a=w(),s=g(),[l,u]=f(`picker`),[d,h]=f(null),[y,b]=f(null),[x,S]=f(`manual`),[C,T]=f(null),[E,D]=f(``),[O,k]=f(null),[A,P]=f(null),{data:F}=t({addonId:d??``,nodeId:`hub`},{enabled:d!=null}),I=m(()=>F?H(F):null,[F]),L=e({onSuccess:()=>s.invalidateQueries({queryKey:[[`integrations`]]})}),U=c(),W=U.data;v(()=>{l!==`discovery`||!y||!d||U.isPending||U.data||U.mutate({addonId:d})},[l,y,d,U]);let ne=o({onSuccess:()=>s.invalidateQueries({queryKey:[[`deviceManager`]]})});async function re(e,t,n,i,o,s){if(!L.isPending){if(h(e),S(n),D(i),P(null),o===`device-adoption`){if(!s){P(`Addon '${e}' declares device-adoption but no brokerKind in its manifest`);return}T(s),u(`broker`);return}if(t===`unique`){try{let t=await L.mutateAsync({addonId:e,name:i,settings:{}});r(),Y(),a(`/integrations/${t.id}`)}catch{}return}u(`config`)}}async function G(e){if(d)try{let t=await L.mutateAsync({addonId:d,name:e.name,settings:e.config});b(t.id),x===`auto`||x===`both`?u(`discovery`):J(t.id)}catch{}}async function K(e){if(d)try{let t=await L.mutateAsync({addonId:d,name:E,settings:{brokerId:e}});k(t.id),b(t.id),J(t.id)}catch{}}async function q(e){if(d){for(let t of e){let e=W?.find(e=>e.stableId===t);e&&await ne.mutateAsync({addonId:d,candidate:e,...O===null?{}:{integrationId:O}})}J()}}function J(e){let t=e??y??d;r(),Y(),t&&a(`/integrations/${t}`)}function Y(){u(`picker`),h(null),b(null),S(`manual`),T(null),D(``),k(null),P(null)}function X(){r(),Y()}if(z(n),!n)return null;let ie={picker:i(`integrations.newIntegration`),config:i(`integrations.configureIntegration`),discovery:i(`integrations.importDevices`),broker:i(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Z=L.isPending,Q=Z?d:null,$=L.error;return p(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[_(`div`,{className:`absolute inset-0 bg-black/60`,onClick:Z?void 0:X}),p(`div`,{className:`relative z-10 w-full max-w-lg max-h-[85vh] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[p(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[_(`h2`,{className:`text-sm font-semibold text-foreground`,children:ie[l]}),_(`button`,{onClick:X,disabled:Z,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:_(j,{className:`h-4 w-4`})})]}),p(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!Z&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),l===`picker`&&p(ee,{children:[A&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),_(B,{onSelect:re,onClose:X,pendingAddonId:Q})]}),l===`config`&&d&&_(te,{addonId:d,configSchema:I??null,onSave:G,onBack:()=>u(`picker`)}),l===`broker`&&C&&_(R,{kind:C,onResolved:e=>{K(e)},onBack:()=>u(`picker`)}),l===`discovery`&&y&&_(V,{providerId:y,onImport:q,onSkip:J})]}),Z&&p(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm`,children:[_(N,{className:`h-6 w-6 animate-spin text-primary`}),_(`p`,{className:`text-xs font-medium text-foreground`,children:i(`integrations.creating`,{defaultValue:`Creating integration…`})}),_(`p`,{className:`text-[10px] text-foreground-subtle`,children:i(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})})]})]})]})}function W({integration:e,expanded:t,onToggleExpand:n}){return p(`div`,{className:`flex items-center gap-2.5`,children:[_(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:_(t?D:E,{className:`h-3.5 w-3.5`})}),_(b,{type:e.addonId,size:`sm`}),p(`div`,{className:`flex min-w-0 flex-col`,children:[_(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),_(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ne(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>_(W,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>_(F,{status:e.status})}]}h();function re(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var G=`expand`;function K(){let{t:e}=M(),t=w(),r=y(),[i]=O(),[o,c]=f(!1),h=d(()=>c(!0),[]),g=d(()=>c(!1),[]);L([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),L([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:v,isLoading:C,refetch:T}=a(void 0),{data:E,isLoading:D,refetch:k}=s({}),j=m(()=>E??[],[E]),N=m(()=>v??[],[v]),F=m(()=>{let e=new Map;for(let t of j)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[j]),I=m(()=>{let e=new Map;for(let t of u(j)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[j]),R=m(()=>N.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:re(e),deviceCount:I.get(e.addonId)??0})),[N,I]),z=i.get(G),B=d(e=>{let t=new URLSearchParams(window.location.search);t.get(G)===e?t.delete(G):t.set(G,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),te=d(e=>t(`/integrations/${e.id}`),[t]),V=d(e=>F.get(e)??null,[F]),H=d(e=>_(b,{type:e,size:`sm`}),[]),W=d(e=>t(`/devices/${String(e)}`),[t]),K=d(e=>_(n,{context:`integration-detail`,devices:j,trpc:r.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:H,resolveParent:V,onNavigate:W}),[j,r.trpcClient,H,V,W]),q=d(e=>z===e.addonId,[z]),J=m(()=>ne({isExpanded:q,onToggleExpand:B}),[q,B]),Y=d(e=>`${e.name} ${e.addonId}`,[]),X=d(e=>e.addonId,[]),ie=d(()=>{T(),k()},[T,k]),Z=C||D,Q=N.length>0;return p(P,{icon:A,title:e(`nav.integrations`,`Integrations`),actions:p(ee,{children:[_(`button`,{onClick:ie,disabled:Z,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:_(S,{className:l(`h-3.5 w-3.5`,Z&&`animate-spin`)})}),p(`button`,{onClick:h,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[_(x,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Z&&_(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Z&&!Q&&p(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[_(`p`,{className:`text-sm`,children:`No integrations configured.`}),_(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Z&&Q&&_(n,{mode:`generic`,items:R,getKey:X,getSearchText:Y,columns:J,onRowClick:te,isExpanded:q,renderExpanded:K,searchPlaceholder:e(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:e(`integrations.empty`,{defaultValue:`No integrations found.`})}),_(U,{open:o,onClose:g})]})}export{K as IntegrationsPage};
@@ -0,0 +1 @@
1
+ import{Bt as e,Fi as t,Ft as n,Ht as r,It as i,Rt as a,Ut as o,Vt as s,Yt as c,it as l,v as u,zt as d}from"./src-D2B9pT1o.js";import{K as f,S as p,W as m,Z as h,b as g,o as _,x as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{p as y}from"./player-overlays-9veDvMBm.js";import{c as b,n as x,u as S}from"./src-DSe57QNH.js";import{t as C}from"./pencil-BDcAm4JB.js";import{t as w}from"./AddonCollectionPage-B_2tbR4h.js";import{t as T}from"./plus-Bect3wmG.js";import{t as E}from"./radio-B6UKQ0zK.js";import{t as ee}from"./wifi-DcA7zdx0.js";import{B as D,H as O,g as k,i as A,s as j,x as M}from"./index-BKXQV0wH.js";import{t as N}from"./AdminPage-vtcsGqRq.js";import{t as P}from"./BrokerForm-CDSVhrkz.js";import{t as F}from"./useBodyScrollLock-B2OWVaf_.js";import{t as I}from"./AdminTabs-ggcZSYRo.js";var L=D(`mail`,[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]),R=D(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]);h();var z={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function B(e){return z[e]??e}function V(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var te={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function H({status:e}){return v(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${te[e]}`,children:e})}function U(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function W({title:e,subtitle:t,onClose:n,children:r}){return F(),v(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:p(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[p(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[p(`div`,{className:`space-y-0.5`,children:[v(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&v(`p`,{className:`text-xs text-foreground-subtle`,children:t})]}),v(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:v(A,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4 max-h-[70vh] overflow-y-auto overscroll-contain`,children:r})]})})}function G({kinds:e,onClose:t,onDone:r}){let i=_(),a=e=>`${e.addonId??``}::${e.kind}`,[o,s]=f(e[0]?a(e[0]):``),[c,l]=f(``),u=e.find(e=>a(e)===o)??e[0],d=u?.kind??``,m=u?.addonId,h=n({onSuccess:()=>{i.invalidateQueries({queryKey:[[`broker`,`list`]]}),r()}}),g=e=>{!d||c.trim().length===0||h.mutate({kind:d,name:c.trim(),settings:e,...m===void 0?{}:{addonId:m}})};return v(W,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:h.isPending?()=>{}:t,children:p(`div`,{className:`space-y-3`,children:[p(`div`,{className:`space-y-1`,children:[v(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Kind`}),v(`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 text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>v(`option`,{value:a(e),children:e.label},a(e)))})]}),p(`div`,{className:`space-y-1`,children:[v(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),v(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),h.isError&&v(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:h.error instanceof Error?h.error.message:String(h.error)}),d&&v(P,{kind:d,...m===void 0?{}:{addonId:m},onSubmit:g,onCancel:t,submitLabel:h.isPending?`Adding…`:`Add broker`,disabled:h.isPending}),c.trim().length===0&&v(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before saving.`})]})})}function K({broker:e,onClose:t,onDone:n}){let a=_(),o=i({id:e.id,addonId:e.addonId}),s=r({onSuccess:()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]}),a.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),n()}}),c=m(()=>{let e=o.data;return e&&typeof e==`object`?{...e}:{}},[o.data]);return v(W,{title:`Edit ${e.name}`,subtitle:`${B(e.kind)} · ${e.id}`,onClose:s.isPending?()=>{}:t,children:o.isLoading?p(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[v(M,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):o.isError?p(`div`,{className:`space-y-3`,children:[p(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings:`,` `,o.error instanceof Error?o.error.message:`Unknown error`]}),v(`div`,{className:`flex justify-end`,children:v(`button`,{type:`button`,onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Close`})})]}):p(`div`,{className:`space-y-3`,children:[s.isError&&v(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:s.error instanceof Error?s.error.message:String(s.error)}),v(P,{kind:e.kind,addonId:e.addonId,initialValues:c,onSubmit:t=>{s.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:t,submitLabel:s.isPending?`Saving…`:`Save`,disabled:s.isPending})]})})}function q({broker:e,onEdit:n}){let r=_(),i=t(),[a,c]=f(null),l=o({onSuccess:e=>c(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>c({ok:!1,error:e instanceof Error?e.message:String(e)})}),u=s({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),d=async()=>{await i({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&u.mutate({id:e.id,addonId:e.addonId})};return p(`tr`,{className:`border-b border-border last:border-0`,children:[v(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),v(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:B(e.kind)}),p(`td`,{className:`px-3 py-2`,children:[v(H,{status:e.status}),a&&v(`span`,{className:`ml-2 text-[10px] ${a.ok?`text-success`:`text-danger`}`,children:a.ok?`OK`:a.error??`failed`})]}),v(`td`,{className:`px-3 py-2`,children:p(`div`,{className:`flex items-center justify-end gap-1.5`,children:[p(`button`,{type:`button`,onClick:()=>l.mutate({id:e.id,addonId:e.addonId}),disabled:l.isPending,title:`Test connection`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10 disabled:opacity-50`,children:[l.isPending?v(M,{className:`h-3 w-3 animate-spin`}):v(ee,{className:`h-3 w-3`}),`Test`]}),p(`button`,{type:`button`,onClick:()=>n(e),title:`Edit`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-primary/10`,children:[v(C,{className:`h-3 w-3`}),` Edit`]}),p(`button`,{type:`button`,onClick:()=>{d()},disabled:u.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded border border-danger/40 px-2 py-1 text-[11px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[u.isPending?v(M,{className:`h-3 w-3 animate-spin`}):v(j,{className:`h-3 w-3`}),`Delete`]})]})})]})}function J(){let t=d({}),n=e(),r=m(()=>U(t.data),[t.data]),[i,a]=f(!1),[o,s]=f(null),c=m(()=>{let e=new Map;for(let t of V(n.data))for(let n of t.kinds)e.set(`${t.addonId}::${n.kind}`,{addonId:t.addonId,kind:n.kind,label:n.label});for(let t of r)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:B(t.kind)});return[...e.values()]},[r,n.data]);return p(`div`,{className:`space-y-3`,children:[v(`div`,{className:`flex items-center justify-end`,children:p(`button`,{type:`button`,onClick:()=>a(!0),disabled:c.length===0,title:c.length===0?`No broker providers available`:void 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:cursor-not-allowed`,children:[v(T,{className:`h-3.5 w-3.5`}),` Add broker`]})}),v(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:p(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[v(`thead`,{children:p(`tr`,{className:`border-b border-border bg-background/50`,children:[v(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),v(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),v(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),v(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),p(`tbody`,{children:[t.isLoading&&v(`tr`,{children:p(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[v(M,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),t.isError&&v(`tr`,{children:p(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,t.error instanceof Error?t.error.message:`Unknown error`]})}),!t.isLoading&&!t.isError&&r.length===0&&v(`tr`,{children:v(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),r.map(e=>v(q,{broker:e,onEdit:s},e.id))]})]})}),i&&v(G,{kinds:c,onClose:()=>a(!1),onDone:()=>a(!1)}),o&&v(K,{broker:o,onClose:()=>s(null),onDone:()=>s(null)})]})}var Y=[{kind:`device-export`,tabId:`device-export`,title:`Device export`,subtitle:`Outbound exporters that publish CamStack devices to other ecosystems (HomeAssistant, HomeKit, Alexa, …).`,icon:R,emptyTitle:`No device-export providers installed`,emptyDescription:`Install an export addon (e.g. @camstack/addon-export-ha-mqtt) to surface your CamStack devices in HomeAssistant, HomeKit, …`,addLabel:`Add export`},{kind:`email`,tabId:`email`,title:`Email providers`,subtitle:`Outbound email relays used for magic-link login, notifications, and alerts (SMTP today, future SendGrid, …).`,icon:L,emptyTitle:`No email providers installed`,emptyDescription:`Install an email-provider addon (e.g. @camstack/addon-smtp) so the hub can deliver magic-link logins and notifications.`,addLabel:`Add email provider`},{kind:`broker`,tabId:`broker`,title:`Brokers`,subtitle:`Message brokers consumed by exporters and downstream automations (MQTT today, future Kafka, …).`,icon:E,emptyTitle:`No brokers installed`,emptyDescription:`Install a broker addon (e.g. @camstack/addon-mqtt-broker) to publish device events for downstream automations.`,addLabel:`Add broker`}];function X(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e.name;if(typeof t==`string`)return t}return null}function Z(e){let t=e,n=t?.manifest;if(!n?.id)return null;let r=[];for(let e of n.capabilities??[]){let t=X(e);t!==null&&r.push(t)}let i=n.packageDisplayName??n.name??n.id,a=t?.process?.state??null;return{addonId:n.id,displayName:i,isActive:a===`running`,packageName:n.packageName??`@camstack/addon-${n.id}`,capNames:r,processState:a}}function Q(e,t){let n=new Set(t);return e.filter(e=>e.capNames.some(e=>n.has(e)))}function ne(e){for(let[t,n]of Object.entries(x))if(n===e)return t;return null}function re(e){return e===`running`?{label:`Running`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`}:e===`crashed`||e===`failed`?{label:e===`failed`?`Failed`:`Crashed`,className:`bg-danger/15 text-danger`}:e===`stopped`||e===`disabled`?{label:`Stopped`,className:`bg-foreground-subtle/15 text-foreground-subtle`}:{label:e??`Unknown`,className:`bg-foreground-subtle/15 text-foreground-subtle`}}function $({label:e,className:t}){return v(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t}`,children:e})}function ie({addonId:e}){let{data:t,isLoading:n}=a({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=S.safeParse(t);if(!r.success)return null;let i=r.data;return v($,{label:`${i.brokerCount} broker${i.brokerCount===1?``:`s`}${i.connectedCount>0?` • ${i.connectedCount} connected`:``}`,className:`bg-primary/10 text-primary`})}function ae({addonId:e}){let{data:t,isLoading:n}=c({addonId:e},{refetchInterval:1e4,retry:!1});if(n||!t)return null;let r=b.safeParse(t);if(!r.success)return null;let i=r.data,a=i.linkState===`linked`?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:i.linkState===`error`?`bg-danger/15 text-danger`:`bg-foreground-subtle/15 text-foreground-subtle`;return v($,{label:`${i.linkState} • ${i.exposedDeviceCount} exposed`,className:a})}function oe({kind:e,addonId:t}){return e===`broker`?v(ie,{addonId:t}):e===`device-export`?v(ae,{addonId:t}):null}function se({descriptor:e,rows:t,isLoading:n}){let r=ne(e.kind),i=e.kind===`device-export`,a=y(),o=O();return v(w,{title:e.title,subtitle:e.subtitle,pageIcon:e.icon,itemIcon:e.icon,capability:r??e.kind,installButtonLabel:e.addLabel,items:t,isLoading:n,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription,renderStatusBadges:t=>{let n=re(t.processState);return p(g,{children:[v($,{label:n.label,className:n.className}),v(oe,{kind:e.kind,addonId:t.addonId})]})},renderExpandedPanel:i?e=>v(u,{addonId:e.addonId,trpc:a.trpcClient,onOpenDevice:e=>o(`/devices/${e}`)}):void 0,showChrome:!0})}function ce(){let e=l(void 0,{refetchInterval:1e4}),t=(e.data??[]).map(Z).filter(e=>e!==null);return v(N,{icon:k,title:`External systems`,subtitle:`External systems this hub talks to — device exporters, email relays, and message brokers. Settings, Logs and Events are docked under every provider.`,children:v(I,{tabs:Y.map(n=>{let r=Object.entries(x).filter(([,e])=>e===n.kind).map(([e])=>e),i=n.kind===`broker`?v(J,{}):v(se,{descriptor:n,rows:Q(t,r),isLoading:e.isLoading});return{id:n.tabId,label:n.title,icon:n.icon,content:i}})})})}export{ce as IntegrationsPage};
@@ -1 +1 @@
1
- import{g as e}from"./src-CGgpymf9.js";import{x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{t as n}from"./AdminPage-vtcsGqRq.js";function r(){return t(n,{children:t(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:t(e,{limit:500,maxHeight:`max-h-[calc(100vh-250px)]`,showScope:!0,showFilters:!0})})})}export{r as LogsPage};
1
+ import{g as e}from"./src-D2B9pT1o.js";import{x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{t as n}from"./AdminPage-vtcsGqRq.js";function r(){return t(n,{children:t(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:t(e,{limit:500,maxHeight:`max-h-[calc(100vh-250px)]`,showScope:!0,showFilters:!0})})})}export{r as LogsPage};