@camstack/addon-admin-ui 1.0.6 → 1.0.7
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.
- package/dist/assets/{AddLocationWizard-CukR7cTF.js → AddLocationWizard-BPXjVkoq.js} +1 -1
- package/dist/assets/{AddonCollectionPage-DJx4uU6r.js → AddonCollectionPage-BHk_82L1.js} +1 -1
- package/dist/assets/{Addons-CH-apJRX.js → Addons-Bu6k7qrw.js} +1 -1
- package/dist/assets/{AdminTabs-BpXprAan.js → AdminTabs-C5BWg3Pz.js} +1 -1
- package/dist/assets/{BrokerForm-BHHqkVQb.js → BrokerForm-CwBhT_Zu.js} +1 -1
- package/dist/assets/{BrokerStep-Cok3AhHx.js → BrokerStep-kInoZsZ8.js} +1 -1
- package/dist/assets/{Capabilities-C7ZtET2s.js → Capabilities-DazohgP2.js} +1 -1
- package/dist/assets/{CapabilityBadges-CMb2KZ75.js → CapabilityBadges-CqlDFU27.js} +1 -1
- package/dist/assets/{Cluster-Dv4qNomn.js → Cluster-vA3G3Xt-.js} +1 -1
- package/dist/assets/{Dashboard-DJM813RT.js → Dashboard-CIarzGjr.js} +1 -1
- package/dist/assets/{Data-DGhOO-Cu.js → Data-CBUx81MG.js} +1 -1
- package/dist/assets/{DetectionIntelligence-hx5aK8kV.js → DetectionIntelligence-DmE8QQvK.js} +1 -1
- package/dist/assets/{DeviceDetail-Cy3oT8kc.js → DeviceDetail-DqTWl3Kz.js} +1 -1
- package/dist/assets/{Devices-CUWOXRHi.js → Devices-KDtIE02J.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-DWa8--dX.js → EmbedPlayerPage-BcG6bilu.js} +1 -1
- package/dist/assets/{FormBuilder-D1P2uZCo.js → FormBuilder-DBTf1H_B.js} +1 -1
- package/dist/assets/{Identity-Be25Wd9m.js → Identity-CYHFXu1M.js} +1 -1
- package/dist/assets/{IntegrationDetail-BH3qKiFl.js → IntegrationDetail-DqViKcp6.js} +1 -1
- package/dist/assets/{Integrations-D2GJn2wx.js → Integrations-BXICd-JI.js} +1 -1
- package/dist/assets/{Integrations-5qRDDBvi.js → Integrations-Cyg_bOkD.js} +1 -1
- package/dist/assets/{Logs-CJvGn4d5.js → Logs-kzrdYdPu.js} +1 -1
- package/dist/assets/{MotionZonesSettings-CrSbCbyo.js → MotionZonesSettings-C1INb9Ec.js} +1 -1
- package/dist/assets/{MyAccess-C70LOUlA.js → MyAccess-DvxBmUhb.js} +1 -1
- package/dist/assets/{Network-KGBDHmKd.js → Network-BEet8LbP.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-DZOqqqZZ.js → NodeAddonsSettingsPanel-BU3fsQhW.js} +1 -1
- package/dist/assets/{Pipeline-B4MQZJjm.js → Pipeline-C460Q1dM.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-Btjy009a.js → PrivacyMaskSettings-Isrt2Rzc.js} +1 -1
- package/dist/assets/{ProviderIcon-BPXhRQ1d.js → ProviderIcon-BS00rCO4.js} +1 -1
- package/dist/assets/{Settings-BBKIvACs.js → Settings-BPtVhsDv.js} +1 -1
- package/dist/assets/{Showroom-D6AoJdZW.js → Showroom-qtUMm-lj.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DYMHJcwg.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BCWO2hJt.js} +1 -1
- package/dist/assets/{bell-DUIEkGPA.js → bell-CRa7XWAs.js} +1 -1
- package/dist/assets/circle-check-big-Ca1L631f.js +1 -0
- package/dist/assets/{copy-DUY8-DBe.js → copy-Bi-BgxBp.js} +1 -1
- package/dist/assets/{dist-Dw4iYpIy.js → dist-B82tlPWR.js} +1 -1
- package/dist/assets/dist-B8KtyWbO.js +1 -0
- package/dist/assets/{download-B3pGiRsg.js → download-Bq_ArgRU.js} +1 -1
- package/dist/assets/{esm-CR7fS4E6.js → esm-C6_--ziT.js} +1 -1
- package/dist/assets/{hostInit-DJmAUuWj.js → hostInit-B8ISRO-X.js} +1 -1
- package/dist/assets/{index-CBUhNGng.js → index-D5OTguVm.js} +3 -3
- package/dist/assets/{key-round-BtVEvNiB.js → key-round-DdK6mTCz.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-50a30526.js → mf-entry-bootstrap-0-ebe1e057.js} +2 -2
- package/dist/assets/{pencil-BHXuzoZT.js → pencil-WwVUhRC9.js} +1 -1
- package/dist/assets/{player-overlays-B1rOp2K0.js → player-overlays-ZG1nYuYj.js} +1 -1
- package/dist/assets/plus-D2fCWFPc.js +1 -0
- package/dist/assets/{radio-BrSbZ3Gz.js → radio-B8E0UhzS.js} +1 -1
- package/dist/assets/{refresh-cw-9auw5j71.js → refresh-cw-DewUBhjl.js} +1 -1
- package/dist/assets/remoteEntry-vWrz4ebK.js +1 -0
- package/dist/assets/{rotate-ccw-DeNzdz-v.js → rotate-ccw-CZ8RwUso.js} +1 -1
- package/dist/assets/rotate-cw-DiyghCam.js +1 -0
- package/dist/assets/search-DZ8Fw9-F.js +1 -0
- package/dist/assets/{server-Bj7As5DB.js → server-DnaOYw5t.js} +1 -1
- package/dist/assets/{sparkles-BMTAprd6.js → sparkles-D9CcRRON.js} +1 -1
- package/dist/assets/square-CO0xPDBD.js +1 -0
- package/dist/assets/{square-check-big-CPuMXqOw.js → square-check-big-9Ki4zQ6C.js} +1 -1
- package/dist/assets/src-BB1LG2-C.js +34 -0
- package/dist/assets/src-Cno9Ci3x.js +1 -0
- package/dist/assets/{upload-BQ5R4JaW.js → upload-DHwenRyJ.js} +1 -1
- package/dist/assets/{useDevice-mTj6eL8W.js → useDevice-BuSIXBXp.js} +1 -1
- package/dist/assets/{useEventInvalidation-BXdyfSQv.js → useEventInvalidation-wNGhDdi_.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BkXjP_sa.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-OHA5nJNY.js} +2 -2
- package/dist/assets/{wifi-CV73GdWg.js → wifi-BJgMgcFe.js} +1 -1
- package/dist/assets/{zap-Cc3-KiYB.js → zap-BAH9oFRn.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +707 -672
- package/package.json +1 -1
- package/dist/assets/circle-check-big-BjqV4p1D.js +0 -1
- package/dist/assets/dist-BwRNbXT1.js +0 -1
- package/dist/assets/plus-CljwKCLZ.js +0 -1
- package/dist/assets/remoteEntry-B0hADopi.js +0 -1
- package/dist/assets/rotate-cw-anx2g3R_.js +0 -1
- package/dist/assets/search-BYve1v5o.js +0 -1
- package/dist/assets/square-CondP2yo.js +0 -1
- package/dist/assets/src-D-eMZfpa.js +0 -34
- package/dist/assets/src-DUWILaCU.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{A as e,Ai as t,Ar as n,B as r,E as i,G as a,Gi as o,Gn as s,H as c,I as l,Ji as u,Jt as d,K as f,Ki as p,Kn as m,L as h,Pi as g,Pr as _,Qi as v,Sn as y,T as b,Tt as x,U as S,V as C,Vr as w,W as T,Wi as E,Yi as D,Yr as O,Yt as k,_n as A,a as j,an as M,bn as ee,cn as N,di as P,dn as F,f as I,fn as te,g as ne,gn as re,hn as L,i as ie,ii as ae,in as oe,j as se,k as ce,ki as le,l as ue,ln as de,lr as fe,lt as pe,m as me,mn as he,n as ge,ni as _e,nn as ve,o as ye,p as be,pn as xe,qn as Se,qt as Ce,r as R,u as we,ui as Te,un as Ee,va as De,vn as Oe,w as ke,xn as Ae,xr as je,y as Me,ya as Ne,yn as Pe,zn as Fe,zr as Ie}from"./src-D-eMZfpa.js";import{F as z,G as B,R as V,U as H,W as U,X as W,b as G,o as K,t as Le,x as q,y as Re}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{c as ze,k as Be,p as J,r as Ve,t as He,u as Ue}from"./player-overlays-B1rOp2K0.js";import{C as We,E as Ge,b as Y,g as Ke,v as qe}from"./src-DUWILaCU.js";import{t as Je}from"./CapabilityBadges-CMb2KZ75.js";import{t as Ye}from"./bell-DUIEkGPA.js";import{n as Xe,t as Ze}from"./rotate-ccw-DeNzdz-v.js";import{t as Qe}from"./ProviderIcon-BPXhRQ1d.js";import{t as $e}from"./pencil-BHXuzoZT.js";import{t as et}from"./plus-CljwKCLZ.js";import{t as tt}from"./refresh-cw-9auw5j71.js";import{t as nt}from"./rotate-cw-anx2g3R_.js";import{t as rt}from"./server-Bj7As5DB.js";import{t as it}from"./wifi-CV73GdWg.js";import{B as X,F as at,H as ot,I as st,O as ct,U as lt,W as ut,_ as dt,a as ft,c as pt,i as mt,k as ht,p as gt,r as _t,s as vt,t as yt,v as bt,x as xt,z as St}from"./index-CBUhNGng.js";import{t as Ct}from"./StatusBadge-CkYubfRG.js";import{n as wt,t as Tt}from"./useDevice-mTj6eL8W.js";import{n as Et,r as Dt,t as Ot}from"./SchemaTabBar-ByWwzBUZ.js";import{t as kt}from"./FormBuilder-D1P2uZCo.js";import{t as At}from"./useEventInvalidation-BXdyfSQv.js";var jt=X(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),Mt=X(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),Nt=X(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),Pt=X(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),Ft=X(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),It=X(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),Lt=X(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),Rt=X(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);W();var zt=`device-export`,Bt=`export`,Vt=`Export`;function Ht(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(Ht):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(Ht)):e.writerCapName===zt}function Ut(e){return e.fields.some(Ht)}function Wt(e){return j(J().trpcClient,e)}function Gt(e){let[t,n]=B(`idle`),[r,i]=B(null),a=U(null),o=U(null),c=U(null),l=U(!0),u=m(),d=s(),f=Se(),p=z(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}c.current=null},[]),h=z(async()=>{if(t===`idle`)return;n(`stopping`);let r=c.current;if(r&&e!==null)try{await Promise.race([f.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}p(),l.current&&(n(`idle`),i(null))},[t,e,f,p]),g=z(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,s=null,p=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await u.mutateAsync({deviceId:e});p=t.sessionId,c.current=p,n(`connecting`),s=new RTCPeerConnection,a.current=s,s.oniceconnectionstatechange=()=>{if(!l.current)return;let e=s.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&l.current&&(i(e===`failed`?`WebRTC connection failed`:null),h())};for(let e of r.getAudioTracks())s.addTrack(e,r);await s.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let f=await s.createAnswer();await s.setLocalDescription(f);let m=s.localDescription?.sdp??f.sdp??``;await d.mutateAsync({deviceId:e,sessionId:p,sdpAnswer:m})}catch(t){let u=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),s)try{s.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,p!==null)try{await f.mutateAsync({deviceId:e,sessionId:p})}catch{}c.current=null,l.current&&(i(u),n(`error`))}},[e,t,u,d,f,h]);return V(()=>(l.current=!0,()=>{l.current=!1;let t=c.current;if(t!==null&&e!==null&&f.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}c.current=null}),[e]),{state:t,error:r,start:g,stop:h,isTalking:t===`talking`}}W();var Kt=0;function Z(){return++Kt}function qt(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Jt(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function Yt(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function Xt(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function Zt({scope:e,greeting:t,className:n}){let r=J(),[i,a]=B(()=>{let n=[];return t&&n.push({id:Z(),kind:`info`,text:t}),n.push({id:Z(),kind:`info`,text:`scope: ${qt(e)} — type help or context for available commands`}),n}),[o,s]=B(``),[c,l]=B([]),[u,d]=B(-1),f=U(null),p=U(null);V(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=z(()=>{f.current?.focus()},[]),h=Le({mutationFn:t=>r.trpcClient.repl.execute.mutate({code:t,scope:e}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;a(e=>[...e,{id:Z(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Z(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Z(),kind:`info`,text:`scope: ${qt(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Jt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Xt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Yt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Z(),kind:`input`,text:`> ${n}`}]),s(``),h.mutate(n)}}function _(t){if(t.key===`Enter`){t.preventDefault(),g(o);return}if(t.key===`ArrowUp`){if(t.preventDefault(),c.length===0)return;let e=u===-1?c.length-1:Math.max(0,u-1);d(e),s(c[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),u===-1)return;let e=u+1;e>=c.length?(d(-1),s(``)):(d(e),s(c[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),a([{id:Z(),kind:`info`,text:`scope: ${qt(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return q(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[q(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>G(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&G(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),q(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[G(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),G(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function Qt({deviceId:e,intercomAvailable:t=!1}){let n=J(),r=typeof window<`u`?window.location.origin:``,a=Number.isFinite(e),o=Wt(a?e:null),{streams:s,pipelineMetrics:c,createSession:l,sendAnswer:u,handleOffer:d,getIceServers:f,addIceCandidate:p,getIceCandidates:m,closeSession:h,getSessionState:g}=ie(n.trpcClient,a?e:null),_=T(n.trpcClient,a?e:null),v=Gt(a&&t?e:null),y=v.state===`requesting-mic`||v.state===`starting`||v.state===`connecting`||v.state===`stopping`,b=v.isTalking||y,x=()=>{v.state===`idle`||v.state===`error`?v.start():v.state!==`stopping`&&v.stop()},S=Ve(),C=i(),w=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,E=S.length>0?G(Re,{children:S.map(e=>G(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return G(Me,{serverUrl:r,createSession:l,sendAnswer:u,handleOffer:d,getIceServers:f,addIceCandidate:p,getIceCandidates:m,closeSession:h,getSessionState:g,...C.request?{playbackUrl:C.request.url,playbackAuthToken:w,...C.request.label?{playbackLabel:C.request.label}:{},onExitPlayback:()=>C.clear()}:{},streams:s,pipelineMetrics:c,phase:o.phase,detections:o,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:_.src,..._.src?{posterUrl:_.src}:{},snapshotLoading:_.loading,onRefreshSnapshot:_.refresh,intercomAvailable:t,intercomShown:b,onIntercomToggle:x,extraOverlay:E,chromeless:!0,className:`h-full`})}function $t({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?G(`div`,{className:`flex flex-col h-full`,children:G(ne,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):q(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function en({deviceId:e}){if(!Number.isFinite(e))return q(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
1
|
+
import{A as e,Ai as t,Ar as n,B as r,E as i,G as a,Gi as o,Gn as s,H as c,I as l,Ji as u,Jt as d,K as f,Ki as p,Kn as m,L as h,Pi as g,Pr as _,Qi as v,Sn as y,T as b,Tt as x,U as S,V as C,Vr as w,W as T,Wi as E,Yi as D,Yr as O,Yt as k,_n as A,a as j,an as M,bn as ee,cn as N,di as P,dn as F,f as I,fn as te,g as ne,gn as re,hn as L,i as ie,ii as ae,in as oe,j as se,k as ce,ki as le,l as ue,ln as de,lr as fe,lt as pe,m as me,mn as he,n as ge,ni as _e,nn as ve,o as ye,p as be,pn as xe,qn as Se,qt as Ce,r as R,u as we,ui as Te,un as Ee,va as De,vn as Oe,w as ke,xn as Ae,xr as je,y as Me,ya as Ne,yn as Pe,zn as Fe,zr as Ie}from"./src-BB1LG2-C.js";import{F as z,G as B,R as V,U as H,W as U,X as W,b as G,o as K,t as Le,x as q,y as Re}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{c as ze,k as Be,p as J,r as Ve,t as He,u as Ue}from"./player-overlays-ZG1nYuYj.js";import{C as We,E as Ge,b as Y,g as Ke,v as qe}from"./src-Cno9Ci3x.js";import{t as Je}from"./CapabilityBadges-CqlDFU27.js";import{t as Ye}from"./bell-CRa7XWAs.js";import{n as Xe,t as Ze}from"./rotate-ccw-CZ8RwUso.js";import{t as Qe}from"./ProviderIcon-BS00rCO4.js";import{t as $e}from"./pencil-WwVUhRC9.js";import{t as et}from"./plus-D2fCWFPc.js";import{t as tt}from"./refresh-cw-DewUBhjl.js";import{t as nt}from"./rotate-cw-DiyghCam.js";import{t as rt}from"./server-DnaOYw5t.js";import{t as it}from"./wifi-BJgMgcFe.js";import{B as X,F as at,H as ot,I as st,O as ct,U as lt,W as ut,_ as dt,a as ft,c as pt,i as mt,k as ht,p as gt,r as _t,s as vt,t as yt,v as bt,x as xt,z as St}from"./index-D5OTguVm.js";import{t as Ct}from"./StatusBadge-CkYubfRG.js";import{n as wt,t as Tt}from"./useDevice-BuSIXBXp.js";import{n as Et,r as Dt,t as Ot}from"./SchemaTabBar-ByWwzBUZ.js";import{t as kt}from"./FormBuilder-DBTf1H_B.js";import{t as At}from"./useEventInvalidation-wNGhDdi_.js";var jt=X(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),Mt=X(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),Nt=X(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),Pt=X(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),Ft=X(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),It=X(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),Lt=X(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),Rt=X(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);W();var zt=`device-export`,Bt=`export`,Vt=`Export`;function Ht(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(Ht):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(Ht)):e.writerCapName===zt}function Ut(e){return e.fields.some(Ht)}function Wt(e){return j(J().trpcClient,e)}function Gt(e){let[t,n]=B(`idle`),[r,i]=B(null),a=U(null),o=U(null),c=U(null),l=U(!0),u=m(),d=s(),f=Se(),p=z(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}c.current=null},[]),h=z(async()=>{if(t===`idle`)return;n(`stopping`);let r=c.current;if(r&&e!==null)try{await Promise.race([f.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}p(),l.current&&(n(`idle`),i(null))},[t,e,f,p]),g=z(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,s=null,p=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await u.mutateAsync({deviceId:e});p=t.sessionId,c.current=p,n(`connecting`),s=new RTCPeerConnection,a.current=s,s.oniceconnectionstatechange=()=>{if(!l.current)return;let e=s.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&l.current&&(i(e===`failed`?`WebRTC connection failed`:null),h())};for(let e of r.getAudioTracks())s.addTrack(e,r);await s.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let f=await s.createAnswer();await s.setLocalDescription(f);let m=s.localDescription?.sdp??f.sdp??``;await d.mutateAsync({deviceId:e,sessionId:p,sdpAnswer:m})}catch(t){let u=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),s)try{s.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,p!==null)try{await f.mutateAsync({deviceId:e,sessionId:p})}catch{}c.current=null,l.current&&(i(u),n(`error`))}},[e,t,u,d,f,h]);return V(()=>(l.current=!0,()=>{l.current=!1;let t=c.current;if(t!==null&&e!==null&&f.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}c.current=null}),[e]),{state:t,error:r,start:g,stop:h,isTalking:t===`talking`}}W();var Kt=0;function Z(){return++Kt}function qt(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function Jt(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function Yt(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function Xt(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function Zt({scope:e,greeting:t,className:n}){let r=J(),[i,a]=B(()=>{let n=[];return t&&n.push({id:Z(),kind:`info`,text:t}),n.push({id:Z(),kind:`info`,text:`scope: ${qt(e)} — type help or context for available commands`}),n}),[o,s]=B(``),[c,l]=B([]),[u,d]=B(-1),f=U(null),p=U(null);V(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=z(()=>{f.current?.focus()},[]),h=Le({mutationFn:t=>r.trpcClient.repl.execute.mutate({code:t,scope:e}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;a(e=>[...e,{id:Z(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Z(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Z(),kind:`info`,text:`scope: ${qt(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Jt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Xt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Z(),kind:`input`,text:`> ${n}`},...Yt(e).map(e=>({id:Z(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Z(),kind:`input`,text:`> ${n}`}]),s(``),h.mutate(n)}}function _(t){if(t.key===`Enter`){t.preventDefault(),g(o);return}if(t.key===`ArrowUp`){if(t.preventDefault(),c.length===0)return;let e=u===-1?c.length-1:Math.max(0,u-1);d(e),s(c[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),u===-1)return;let e=u+1;e>=c.length?(d(-1),s(``)):(d(e),s(c[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),a([{id:Z(),kind:`info`,text:`scope: ${qt(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return q(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[q(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>G(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&G(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),q(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[G(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),G(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function Qt({deviceId:e,intercomAvailable:t=!1}){let n=J(),r=typeof window<`u`?window.location.origin:``,a=Number.isFinite(e),o=Wt(a?e:null),{streams:s,pipelineMetrics:c,createSession:l,sendAnswer:u,handleOffer:d,getIceServers:f,addIceCandidate:p,getIceCandidates:m,closeSession:h,getSessionState:g}=ie(n.trpcClient,a?e:null),_=T(n.trpcClient,a?e:null),v=Gt(a&&t?e:null),y=v.state===`requesting-mic`||v.state===`starting`||v.state===`connecting`||v.state===`stopping`,b=v.isTalking||y,x=()=>{v.state===`idle`||v.state===`error`?v.start():v.state!==`stopping`&&v.stop()},S=Ve(),C=i(),w=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,E=S.length>0?G(Re,{children:S.map(e=>G(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return G(Me,{serverUrl:r,createSession:l,sendAnswer:u,handleOffer:d,getIceServers:f,addIceCandidate:p,getIceCandidates:m,closeSession:h,getSessionState:g,...C.request?{playbackUrl:C.request.url,playbackAuthToken:w,...C.request.label?{playbackLabel:C.request.label}:{},onExitPlayback:()=>C.clear()}:{},streams:s,pipelineMetrics:c,phase:o.phase,detections:o,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:_.src,..._.src?{posterUrl:_.src}:{},snapshotLoading:_.loading,onRefreshSnapshot:_.refresh,intercomAvailable:t,intercomShown:b,onIntercomToggle:x,extraOverlay:E,chromeless:!0,className:`h-full`})}function $t({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?G(`div`,{className:`flex flex-col h-full`,children:G(ne,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):q(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function en({deviceId:e}){if(!Number.isFinite(e))return q(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
2
2
|
`);return G(Zt,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function tn({deviceId:e}){return Number.isFinite(e)?G(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:G(me,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):q(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function nn({deviceId:e}){return Number.isFinite(e)?G(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:G(I,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):q(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function rn({parentDeviceId:e}){let{t}=yt(),n=ot(),i=J(),{data:a,isLoading:o,isError:s}=wt(e),{data:l}=N({deviceId:e},{enabled:Number.isFinite(e)});if(o)return G(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:G(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return G(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:G(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let u=a??[];if(u.length===0)return null;let d=C(l?.stableId??``,u,l?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),m=(e,t)=>G(r,{trpc:i.trpcClient,device:t,variant:`minimal`,onNavigate:p},e),h=f.some(e=>!!e.role),g=f.some(e=>!e.role),_=h&&!g?t(`device.accessories`,{defaultValue:`Accessories`}):!h&&g?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),v=f.length>0?q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[G(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:_}),G(`div`,{className:`space-y-1`,children:f.map(e=>m(e.id,e))})]}):null,y=d.disabledSection===void 0?null:G(c,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:G(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>m(e.id,e))})},d.disabledSection.title);return d.sections.length===0?y===null?v:q(`div`,{className:`space-y-2`,children:[v,y]}):q(`div`,{className:`space-y-2`,children:[d.sections.map(e=>G(c,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),v,y]})}function Q({label:e,value:t}){return q(`div`,{className:`${Be} flex items-start gap-2 sm:gap-3`,children:[G(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),G(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}W();function an({deviceId:e,initialName:t}){let n=K(),[r,i]=B(!1),[a,o]=B(t),[s,c]=B(!1),l=U(null);V(()=>{r||o(t)},[t,r]),V(()=>{r&&l.current?.focus()},[r]);let u=Oe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),d=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),o(t);return}c(!0);try{await u.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{c(!1)}},f=()=>{o(t),i(!1)};return r?G(Q,{label:`Name`,value:q(`div`,{className:`flex items-center gap-1`,children:[G(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?d():e.key===`Escape`&&f()},disabled:s,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),G(`button`,{type:`button`,onClick:()=>void d(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:G(at,{className:`h-3 w-3`})}),G(`button`,{type:`button`,onClick:f,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:G(mt,{className:`h-3 w-3`})})]})}):G(Q,{label:`Name`,value:q(`div`,{className:`flex items-center gap-2 group`,children:[G(`span`,{className:`truncate`,children:t}),G(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit name`,children:G($e,{className:`h-3 w-3 text-foreground-subtle`})})]})})}W();function on({deviceId:e,initialLocation:t}){let n=K(),[r,i]=B(!1),[a,o]=B(t??``),[s,c]=B(!1),l=U(null),{data:u}=xe(void 0,{enabled:r}),d=u??[];V(()=>{r||o(t??``)},[t,r]),V(()=>{r&&l.current?.focus()},[r]);let f=A({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),p=H(()=>{let e=a.trim().toLowerCase();return e.length===0?d:d.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[d,a]),m=a.trim().length>0&&!d.some(e=>e.toLowerCase()===a.trim().toLowerCase()),h=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await f.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},g=()=>{o(t??``),i(!1)};return r?G(Q,{label:`Location`,value:q(`div`,{className:`relative`,children:[q(`div`,{className:`flex items-center gap-1`,children:[G(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?h():e.key===`Escape`&&g()},disabled:s,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),G(`button`,{type:`button`,onClick:()=>void h(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:G(at,{className:`h-3 w-3`})}),G(`button`,{type:`button`,onClick:g,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:G(mt,{className:`h-3 w-3`})})]}),(p.length>0||m)&&q(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[p.map(e=>q(`button`,{type:`button`,onClick:()=>{o(e),h(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[G(Ft,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),G(`span`,{className:`truncate`,children:e})]},e)),m&&q(`button`,{type:`button`,onClick:()=>void h(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[G(`span`,{className:`text-foreground-subtle`,children:`Create`}),q(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):G(Q,{label:`Location`,value:q(`div`,{className:`flex items-center gap-2 group`,children:[t?G(`span`,{className:`truncate`,children:t}):G(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),G(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit location`,children:G($e,{className:`h-3 w-3 text-foreground-subtle`})})]})})}W();var sn=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function cn(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function ln(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function un(){let t=e(),n=se(),{data:r}=N({deviceId:t??0},{enabled:t!==null}),{data:i}=M({deviceId:t??0},{enabled:t!==null}),a=r??n??null,[o,s]=B(`identity`);if(t===null||!a)return null;let c=String(a.stableId??``),l=String(a.name??``),u=String(a.type??``),d=String(a.addonId??``),f=a.features??[],p=new Set([`device-status`,`feature-probe`,`device-ops`]),m=(i?.entries??[]).filter(e=>e.kind===`native`&&!p.has(e.capName)).map(e=>e.capName),h=f.length>0?f:m,g=a.location??null,_=a.metadata??null,v=_!==null&&Object.keys(_).length>0;return q(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[q(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[G(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),v&&q(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[G(dn,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),G(dn,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!v||o===`identity`)&&q(`div`,{className:`divide-y divide-border`,children:[G(Q,{label:`ID`,value:q(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${t}`,q(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,c,`)`]})]})}),G(an,{deviceId:t,initialName:l}),G(on,{deviceId:t,initialLocation:g}),G(Q,{label:`Type`,value:u}),G(Q,{label:`Provider`,value:G(Qe,{type:d,size:`sm`,showLabel:!0})}),G(Q,{label:`Capabilities`,value:h.length>0?G(Je,{capabilities:h,showLabels:!0}):G(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),v&&o===`hardware`&&G(fn,{metadata:_})]})}function dn({active:e,onClick:t,label:n}){return G(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function fn({metadata:e}){let t=sn.filter(t=>t in e),n=Object.keys(e).filter(e=>!sn.includes(e)).toSorted(),r=[...t,...n];return q(`div`,{children:[G(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),G(`div`,{className:`divide-y divide-border`,children:r.map(t=>G(Q,{label:cn(t),value:G(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:ln(e[t])})},t))})]})}W();function pn({deviceId:e}){let[t,n]=B(null),r=Ce({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return q(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[q(`div`,{className:`flex items-center justify-between gap-3`,children:[q(`div`,{children:[G(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),G(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),q(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[G(tt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&G(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function mn(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function hn({device:e}){let t=ot(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===Y.Camera,a=r===Y.Hub,o=e.features??[],s=o.includes(qe.Resyncable),{data:c}=fe({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),l=c?.streams??{},u=Object.entries(l),d=o.includes(qe.DoorbellButton),f=R(d?{deviceId:n??void 0,historyLimit:10}:void 0),p=f.latest?Date.now()-f.latest.timestamp<3e4:!1;return q(`div`,{className:`space-y-5`,children:[a&&n!==null&&G(be,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),s&&n!==null&&G(pn,{deviceId:n}),i&&n!==null&&G(ke,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),d&&G(we,{history:f.history,latestIsFresh:p}),i&&n!==null&&G(ke,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&u.length>0&&q(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[G(`div`,{className:`border-b border-border px-4 py-2`,children:G(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),G(`div`,{className:`divide-y divide-border`,children:u.map(([e,t])=>q(`div`,{className:`px-4 py-2.5`,children:[q(`div`,{className:`flex items-center gap-2 mb-2`,children:[G(it,{className:`h-3 w-3 text-foreground-subtle`}),G(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),q(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[G(gn,{label:`Nominal`,value:mn(t.nominalBitrateKbps??0)}),G(gn,{label:`Observed`,value:mn(t.observedBitrateKbps??0)}),G(gn,{label:`Peak`,value:mn(t.peakBitrateKbps??0)}),G(gn,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),G(un,{})]})}function gn({label:e,value:t,warning:n}){return q(`div`,{children:[G(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),G(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}W();function _n({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l}){let u=e.tabs??[],d=H(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),f=new Set(u.map(e=>e.id)),p=[...u,...[...d.keys()].filter(e=>!f.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],m=p[0]?.id??`general`,[h,g]=B(m),_=l!==void 0,v=new Set(p.map(e=>e.id)),y=_?c&&v.has(c)?c:m:v.has(h)?h:m,b=e=>{_?l(e):g(e)},x=d.get(y)??[],S={sections:x.length<=1?x.length===1?[{...x[0],title:``}]:x:x.every(e=>!e.title)?[{...x[0],title:``,fields:x.flatMap(e=>e.fields)}]:x},C=G(Et,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(p.length<=1)return q(`div`,{className:`flex flex-col gap-3`,children:[G(kt,{schema:e,values:t,onChange:r,onAction:i,disabled:s}),C]});let w=new Map,T=new Map;for(let[e,t]of d){w.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&T.set(e,a)}return q(`div`,{className:`flex flex-col gap-3`,children:[G(Ot,{tabs:p.map(e=>({id:e.id,label:e.label})),activeId:y,onChange:b,countByTab:w,pendingByTab:T}),G(kt,{schema:S,values:t,onChange:r,onAction:i,disabled:s}),C]})}W();function vn(e,t){return t&&t===`admin`?e:!0}function yn(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?Ut(e)&&Ut(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function bn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function xn(e){return e.key}function Sn(e){if(!bn(e))return e.value}function Cn(e){return bn(e)?null:e}function wn(e,t){for(let n of e)if(t(n),n.type===`group`)wn(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)wn(e.fields,t)}function Tn(e){if(!e)return{};let t={};for(let n of e.sections)wn(n.fields,e=>{let n=xn(e);n!==null&&(t[n]=Sn(e))});return t}function En(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(wn(r.fields,e=>{if(n!==null||xn(e)!==t)return;let r=Cn(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function Dn(e){return{...e,fields:e.fields.map(On)}}function On(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function kn(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=Cn(e);return n?vn(t,n.minRole)?e:On(e):e})}))}}function An({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r}){let i=K(),{user:a}=_t(),o=a?.isAdmin===!0,s=U(!1),{data:c,isLoading:l}=de({deviceId:e},{refetchInterval:()=>s.current?!1:2500,enabled:Number.isFinite(e)}),{data:u}=N({deviceId:e},{enabled:Number.isFinite(e)}),d=c?.settings??null,f=c?.live??null,p=H(()=>{if(!d&&!f)return null;let e=d?.sections??[],n=(f?.sections??[]).map(Dn),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!Ut(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...d?.tabs??[],...(f?.tabs??[]).filter(e=>!(d?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[d,f,t]),m=H(()=>yn(p),[p]),h=H(()=>kn(m,o),[m,o]),g=H(()=>Tn(h),[h]),_=P(),v=Te(),b=Ae(),x=L(),S=y({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),C={isPending:S.isPending,mutate:t=>{S.mutate({deviceId:e,changes:[...t]})}},w=Dt({schema:h,serverValues:g,onImmediateSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=En(h,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&C.mutate(t)},[h,C]),onDeferredSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=En(h,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&C.mutate(t)},[h,C])}),{values:T,pendingKeys:E,handleChange:D,handleSave:O,handleDiscard:k}=w;if(s.current=w.editingPaused,l)return q(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[G(xt,{className:`h-4 w-4 animate-spin mr-2`}),G(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!h||h.sections.length===0)return G(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function A(t,n,r){if(t===`regenerate-rtsp-token`){let t=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!t)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(t.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let a=We(e,r);await _.mutateAsync({brokerId:a}),i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!u)return{status:`error`,error:`Device metadata not loaded yet`};try{return await b.mutateAsync({addonId:u.addonId,type:u.type,key:n,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(t===`refresh-probe`){if(!n.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${n}" (expected "probedInfo:<streamId>")`);let t=n.slice(11);if(!t)throw Error(`refresh-probe: key "${n}" has no streamId after prefix`);let r=We(e,t),a=await v.mutateAsync({brokerId:r});return i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),a}if(t===`device-custom-action`){let t=await x.mutateAsync({deviceId:e,action:n,input:r});return i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return G(_n,{schema:h,values:T,pendingKeys:E,onChange:D,onAction:A,onSave:O,onDiscard:k,disabled:C.isPending,activeSubTab:n,onSubTabChange:r})}function jn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return G(`div`,{className:`flex flex-col gap-3`,children:G(An,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}W(),W();function Mn({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return q(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[G(Qe,{type:n,size:`lg`}),q(`div`,{children:[G(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),G(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),q(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[G(Ct,{status:r?`online`:`offline`}),i.length>0&&G(Je,{capabilities:i})]}),G(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}W();function Nn({deviceId:e}){let t=K(),n=d({deviceId:e},{refetchInterval:1e4,retry:!1}),r=k({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=H(()=>Pn(n.data??[]),[n.data]);return q(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[q(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[G(Fn,{label:`Discovered`,value:i.total,icon:G(dt,{className:`h-3.5 w-3.5`})}),G(Fn,{label:`Adopted`,value:i.adopted,accent:`success`}),G(Fn,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),q(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[r.isPending?G(xt,{className:`h-3.5 w-3.5 animate-spin`}):G(tt,{className:`h-3.5 w-3.5`}),G(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),q(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[G(In,{icon:G(it,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),G(In,{icon:G(bt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),G(In,{icon:G(ft,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?G(In,{icon:G(jt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function Pn(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function Fn({label:e,value:t,icon:n,accent:r}){return q(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[q(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,G(`span`,{className:`truncate`,children:e})]}),G(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function In({icon:e,label:t}){return q(`span`,{className:`inline-flex items-center gap-1`,children:[e,G(`span`,{children:t})]})}function Ln({deviceId:e,features:n}){return G(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:G(t,{trpc:J().trpcClient,deviceId:e,features:n})})}function Rn({deviceId:e,features:t}){return G(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:G(le,{trpc:J().trpcClient,deviceId:e,features:t})})}function $({deviceId:e,deviceType:t,features:n}){let r=J(),i=f(t)?.HeroCard??le,a=Ue(ze(r.trpcClient,e)?.state.deviceStatus),o=a!==void 0&&a.online===!1,s=o?a.lastChangedAt:null;return q(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[o?G(`div`,{className:`flex justify-center`,children:G(h,{lastChangedAt:s})}):null,G(i,{trpc:r.trpcClient,deviceId:e,features:n})]})}W();function zn({deviceId:e}){let t=J(),n=K(),{data:r,isLoading:i}=Tt(e),{data:a,isLoading:o}=wt(e),s=i||o,[c,u]=B(null),d=Pe({onSuccess:()=>{u(null),n.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{u(`Could not change primary child: ${e.message}`)}}),f=(a??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),p=typeof r?.linkDeviceId==`number`?r.linkDeviceId:null,m=typeof r?.primaryChildEntityId==`string`?r.primaryChildEntityId:null;return s?G(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):q(`div`,{className:`flex h-full w-full flex-col`,children:[G(l,{trpc:t.trpcClient,children:f,linkDeviceId:p,primaryChildEntityId:m,onSetPrimary:t=>d.mutate({deviceId:e,primaryChildEntityId:t})}),c!==null&&G(`p`,{role:`alert`,className:`px-3 pb-2 text-[11px] text-danger sm:px-4`,children:c})]})}var Bn={[Y.Switch]:$,[Y.Siren]:$,[Y.Light]:$,[Y.Sensor]:$,[Y.Button]:$,[Y.Hub]:Nn,[Y.Cover]:Ln,[Y.Valve]:$,[Y.Humidifier]:$,[Y.WaterHeater]:$,[Y.Container]:zn,[Y.Lock]:$,[Y.Fan]:$,[Y.Thermostat]:$,[Y.MediaPlayer]:$,[Y.Control]:$,[Y.AlarmPanel]:Rn,[Y.EventEmitter]:Rn,[Y.Notifier]:Rn,[Y.Script]:Rn,[Y.Automation]:Rn,[Y.Presence]:$,[Y.Update]:$,[Y.Vacuum]:$,[Y.LawnMower]:$,[Y.Weather]:$,[Y.Image]:$};function Vn(e){return G(Bn[e.deviceType]??Mn,{...e})}function Hn({deviceId:e}){let t=K(),n=Number.isFinite(e),{data:r}=N({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;At([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:c}=M({deviceId:e},{enabled:n}),{data:l}=te({deviceType:i},{enabled:!!i}),d=ee({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return G(`div`,{className:`p-4`,children:G(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(s)return q(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,c instanceof Error?c.message:String(c)]});let f=new Map,p={};for(let e of l??[])p[e.capName]=e.wrappers;for(let e of a?.entries??[])f.set(e.capName,{...e,wrappers:p[e.capName]??[]});for(let e of l??[])f.has(e.capName)||f.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let m=[...f.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(m.length===0)return q(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[G(Xe,{className:`h-8 w-8 opacity-40`}),G(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),G(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let h=m.filter(e=>e.kind!==`unbound`).length;return q(`div`,{className:`flex flex-col gap-3 p-1`,children:[q(`div`,{className:`text-[11px] text-foreground-subtle`,children:[G(`span`,{className:`font-medium text-foreground`,children:h}),` of `,m.length,` capabilit`,m.length===1?`y`:`ies`,` bound — rows marked `,G(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),G(u,{columns:[{key:`capability`,header:`Capability`,render:e=>G(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>G(Un,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>G(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||G(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?G(Wn,{nodeId:e.providerNodeId}):G(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>G(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||G(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return G(Gn,{wrappers:t.wrappers,activeWrapperId:n,disabled:d.isPending,onPick:r=>{let i=n===r;d.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:m,rowKey:e=>e.capName,minWidthPx:720})]})}function Un({kind:e}){return e===`native`?q(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[G(rt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?q(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[G(Mt,{className:`h-3 w-3`}),`wrapped`]}):q(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[G(It,{className:`h-3 w-3`}),`unbound`]})}function Wn({nodeId:e}){return G(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function Gn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?G(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):G(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return q(`button`,{disabled:n,onClick:()=>r(e),title:i?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[G(i?at:Ze,{className:`h-3 w-3`}),e]},e)})})}W();function Kn(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function qn(e,t,n){let r=e?.stepOverridesByAgent?.[t]?.[n];if(r)return r.enabled===!1?`off`:(r.enabled,`on`);let i=e?.stepToggles?.[n];return i===!1?`off`:i===!0?`on`:`inherit`}function Jn({agents:e,currentAgent:t,onPick:n}){let[r,i]=B(!1);return q(`div`,{className:`relative`,children:[G(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>i(e=>!e),children:`Mirror from ▾`}),r&&G(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:e.filter(e=>e!==t).map(e=>G(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{i(!1),n(e)},children:e},e))})]})}function Yn({deviceId:e,refreshToken:t}){let r=K(),[i,a]=B(null),[s,c]=B(null),[l,u]=B(null),[d,f]=B(null),m=_({deviceId:e}),h=w(),g=Ie({deviceId:e}),v=n(),y=H(()=>g.data?.agentNodeId||v.data?.find(e=>e.online)?.nodeId||`hub`,[g.data?.agentNodeId,v.data]),b=s??y,x=je({nodeId:b??``},{enabled:!!b}),S=O({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),u(null)}}),C=H(()=>x.data?p(x.data):[],[x.data]),T=H(()=>{let e=m.data??null,t={};for(let n of h.data??[])for(let r of Object.keys(n.settings.addonDefaults)){let i=t[r]??[];i.push({agentNodeId:n.nodeId,state:qn(e,n.nodeId,r)}),t[r]=i}return t},[m.data,h.data]),D=i?Kn(x.data??null,i):null,k=b?h.data?.find(e=>e.nodeId===b)??null:null,A=i&&k?k.settings.addonDefaults[i]??null:null,j=i&&b?m.data?.stepOverridesByAgent?.[b]?.[i]??null:null,M=x.data?.selectedEngine.format??`coreml`,ee=e=>{c(e),u(null),f(null)};return h.isLoading||x.isLoading?G(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):x.data?G(`div`,{className:`@container h-full`,style:{containerType:`inline-size`},children:q(`div`,{className:`flex flex-col @[720px]:flex-row h-full`,children:[G(`aside`,{className:`w-full @[720px]:w-[300px] @[720px]:flex-shrink-0 border-b @[720px]:border-b-0 @[720px]:border-r border-border overflow-y-auto max-h-[40vh] @[720px]:max-h-none`,children:G(o,{tree:C,selectedAddonId:i,onSelect:e=>{a(e),u(null),f(null)},agentDots:T})}),G(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!i||!D?G(`div`,{className:`text-sm text-foreground-subtle`,children:`Select a step on the left to configure it for this camera.`}):q(`div`,{className:`space-y-4`,children:[q(`div`,{children:[G(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle`,children:`Selected step`}),G(`div`,{className:`text-base font-semibold`,children:D.name})]}),q(`div`,{className:`flex items-end gap-3 flex-wrap`,children:[q(`div`,{children:[G(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle mb-1`,children:`Agent`}),G(`div`,{className:`flex rounded border border-border overflow-hidden`,children:(h.data??[]).map(e=>G(`button`,{type:`button`,onClick:()=>ee(e.nodeId),className:`px-3 py-1 text-xs ${b===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),G(Jn,{agents:(h.data??[]).map(e=>e.nodeId),currentAgent:b,onPick:e=>{if(!b||!i||!x.data||!h.data)return;let t=h.data.find(t=>t.nodeId===e),n=h.data.find(e=>e.nodeId===b);if(!t||!n)return;let[r]=Ne({source:{nodeId:t.nodeId,engine:{format:M},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:M},defaults:n.settings.addonDefaults},catalog:x.data,addonIds:[i]});if(!r){f(`no mirror result`);return}if(r.outcome===`skip`){f(`skipped: ${r.reason??`no candidate`}`);return}u(r.patch),f(`${r.outcome} from ${e}`)}}),d&&G(`div`,{className:`text-[10px] text-foreground-subtle`,children:d})]}),A&&G(E,{mode:`device`,addon:D,agentDefault:A,agentNodeId:b??``,currentPatch:l??j,engineFormat:M,onChangePatch:u}),q(`div`,{className:`flex items-center justify-between gap-2 pt-4 border-t border-border`,children:[G(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle`,disabled:!j||S.isPending,onClick:()=>{!b||!i||S.mutate({deviceId:e,agentNodeId:b,addonId:i,patch:null})},children:`Clear override`}),q(`div`,{className:`flex items-center gap-2`,children:[G(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>u(null),children:`Reset draft`}),G(`button`,{type:`button`,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,disabled:!b||!i||S.isPending,onClick:()=>{!b||!i||S.mutate({deviceId:e,agentNodeId:b,addonId:i,patch:l})},children:S.isPending?`Saving…`:`Save`})]})]})]})})]})}):G(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`})}W();function Xn(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function Zn(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=Xn(r.value,t));return n}function Qn(e,t){return e?.kind===`enum-map`?Object.entries(e.mapping).map(([e,t])=>({key:e,value:String(t)})):t?.kind===`enum`&&t.enumValues?t.enumValues.map(e=>({key:e,value:``})):[{key:``,value:``}]}function $n(e){return e?.kind===`linear`?{scale:String(e.scale),offset:String(e.offset),clampMin:e.clamp?String(e.clamp[0]):``,clampMax:e.clamp?String(e.clamp[1]):``,useClamp:e.clamp!=null}:{scale:`1`,offset:`0`,clampMin:``,clampMax:``,useClamp:!1}}function er(e){return e==null?`identity`:e.kind}function tr({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=B(()=>er(e)),[o,s]=B(()=>Qn(e,n)),[c,l]=B(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=B(()=>$n(e));V(()=>{if(i===`enum-map`&&n?.kind===`enum`&&n.enumValues){let e=n.enumValues;s(t=>e.map(e=>({key:e,value:t.find(t=>t.key===e)?.value??``})))}},[n,i]),V(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=Zn(o,r),n=c===``?void 0:Xn(c,r);t({kind:`enum-map`,mapping:e,...n===void 0?{}:{fallback:n}});return}if(i===`linear`){let e=Number(u.scale),n=Number(u.offset);if(Number.isNaN(e)||Number.isNaN(n))return;let r=Number(u.clampMin),i=Number(u.clampMax),a=u.useClamp&&!Number.isNaN(r)&&!Number.isNaN(i)?[r,i]:void 0;t({kind:`linear`,scale:e,offset:n,...a?{clamp:a}:{}})}},[i,o,c,u,r,t]);let f=e=>{a(e),e===`enum-map`&&s(Qn(void 0,n)),e===`linear`&&d($n(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return q(`div`,{className:`flex flex-col gap-3`,children:[q(`div`,{children:[G(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),G(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>q(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[G(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&q(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[G(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>q(`div`,{className:`flex items-center gap-1.5`,children:[G(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),G(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?q(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[G(`option`,{value:``,children:`—`}),G(`option`,{value:`true`,children:`true`}),G(`option`,{value:`false`,children:`false`})]}):G(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&G(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&G(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),q(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[G(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),G(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&q(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[G(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),q(`div`,{className:`grid grid-cols-2 gap-2`,children:[q(`label`,{className:`flex flex-col gap-0.5`,children:[G(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),G(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),q(`label`,{className:`flex flex-col gap-0.5`,children:[G(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),G(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),q(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[G(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),G(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&q(`div`,{className:`grid grid-cols-2 gap-2`,children:[q(`label`,{className:`flex flex-col gap-0.5`,children:[G(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),G(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),q(`label`,{className:`flex flex-col gap-0.5`,children:[G(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),G(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}W();function nr(e,t){return`${e.replace(/[^a-z0-9]/gi,`-`)}-${t.replace(/[^a-z0-9]/gi,`-`)}`}function rr(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function ir({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=F({}),s=o??[],c=t==null?n:s.find(e=>e.id===t)?.stableId??n,l=s.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:u}=Ee({deviceId:e}),d=u?.caps??[],f=r==null?null:rr(r.source.sourceKey,c,s),[p,m]=B(r?.target.cap??``),[h,g]=B(r?.target.fieldPath??``),[_,v]=B(f),[y,b]=B(r?.source.cap??``),[x,S]=B(r?.source.fieldPath??``),[C,w]=B(r?.transform);V(()=>{if(r!=null&&_===null&&s.length>0){let e=rr(r.source.sourceKey,c,s);e!==null&&v(e)}},[r,_,s,c]);let{data:T}=Ee({deviceId:_??0},{enabled:_!=null}),E=T?.caps??[],D=d.find(e=>e.cap===p)?.fields??[],O=D.find(e=>e.path===h),k=E.find(e=>e.cap===y)?.fields??[],A=k.find(e=>e.path===x),j=e=>{m(e),g(``)},M=e=>{v(e===``?null:Number(e)),b(``),S(``)},ee=e=>{b(e),S(``)},N=p!==``&&h!==``&&_!=null&&y!==``&&x!==``,P=()=>{if(!N)return;let e=s.find(e=>e.id===_),t=`${c}-`,n=e&&e.stableId.startsWith(t)?e.stableId.slice(t.length):``;i({id:r?.id??nr(p,h),source:{sourceKey:n,cap:y,fieldPath:x},target:{cap:p,fieldPath:h},...C==null?{}:{transform:C}})},I=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return q(`div`,{className:`flex flex-col gap-4 p-3`,children:[q(`fieldset`,{className:`flex flex-col gap-3`,children:[G(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),q(`div`,{children:[G(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),q(`select`,{id:`link-target-cap`,value:p,onChange:e=>j(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a cap —`}),d.map(e=>G(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),q(`div`,{children:[G(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),q(`select`,{id:`link-target-field`,value:h,disabled:p===``,onChange:e=>g(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a field —`}),D.map(e=>q(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),q(`fieldset`,{className:`flex flex-col gap-3`,children:[G(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source (sibling device)`}),q(`div`,{children:[G(`label`,{htmlFor:`link-source-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source device`}),q(`select`,{id:`link-source-device`,value:_??``,onChange:e=>M(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a device —`}),l.map(e=>q(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),q(`div`,{children:[G(`label`,{htmlFor:`link-source-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source cap`}),q(`select`,{id:`link-source-cap`,value:y,disabled:_==null,onChange:e=>ee(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a cap —`}),E.map(e=>G(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),q(`div`,{children:[G(`label`,{htmlFor:`link-source-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source field`}),q(`select`,{id:`link-source-field`,value:x,disabled:y===``,onChange:e=>S(e.target.value),className:I,children:[G(`option`,{value:``,children:`— select a field —`}),k.map(e=>q(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),G(tr,{value:C,onChange:w,sourceField:A,targetKind:O?.kind}),q(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[G(`button`,{type:`button`,onClick:a,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),G(`button`,{type:`button`,disabled:!N,onClick:P,className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Save`})]})]})}W();function ar({deviceId:e}){let t=J(),n=K(),{data:r,isLoading:i}=N({deviceId:e},{enabled:Number.isFinite(e),refetchInterval:1e4}),a=re({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),o=r?.deviceLinks??[],s=typeof r?.parentDeviceId==`number`?r.parentDeviceId:null,c=typeof r?.stableId==`string`?r.stableId:``,[l,u]=B(null),d=t=>{a.mutate({deviceId:e,deviceLinks:o.filter(e=>e.id!==t)})};return i?G(`div`,{className:`p-4`,children:G(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):l===null?q(`div`,{className:`flex flex-col gap-3 p-1`,children:[q(`div`,{className:`flex items-center justify-between`,children:[G(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),q(`button`,{type:`button`,onClick:()=>u(`new`),title:`Add a cross-device link`,className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[G(et,{className:`h-3 w-3`}),`Add link`]})]}),o.length===0?q(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[G(Nt,{className:`h-8 w-8 opacity-30`}),G(`p`,{className:`text-xs`,children:`No links yet.`}),G(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):G(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:o.map(n=>G(or,{deviceId:e,link:n,trpcClient:t.trpcClient,onDelete:()=>d(n.id),onEdit:()=>u(n),isPending:a.isPending},n.id))})]}):q(`div`,{className:`flex flex-col gap-3 p-1`,children:[G(`div`,{className:`flex items-center justify-between`,children:G(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:l===`new`?`Add link`:`Edit link`})}),G(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:G(ir,{deviceId:e,parentDeviceId:s,deviceStableId:c,initial:l===`new`?null:l,onSave:t=>{let n=o.some(e=>e.id===t.id)?o.map(e=>e.id===t.id?t:e):[...o,t];a.mutate({deviceId:e,deviceLinks:n}),u(null)},onCancel:()=>{u(null)}})})]})}function or({deviceId:e,link:t,trpcClient:n,onDelete:r,onEdit:i,isPending:a}){let o=ge(n,e,t.target.cap),s=o===void 0?void 0:Ke(o,t.target.fieldPath),c=s==null?`—`:String(s);return q(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[G(Pt,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),q(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[q(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[G(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),G(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),G(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath})]}),q(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[G(`span`,{children:`←`}),G(`span`,{className:`font-mono`,children:t.source.sourceKey}),G(`span`,{className:`opacity-60`,children:`/`}),G(`span`,{className:`font-mono`,children:t.source.cap}),G(`span`,{className:`opacity-60`,children:`.`}),G(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]}),t.transform&&G(sr,{kind:t.transform.kind}),G(`span`,{className:`font-mono text-[11px] tabular-nums min-w-[2.5rem] text-right text-foreground-subtle`,title:`Live resolved value (from this device's runtime-state slice)`,children:c}),G(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:a,onClick:i,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:`Edit`}),G(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:a,onClick:r,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-danger hover:border-danger/50 hover:bg-danger/5 transition-colors disabled:opacity-50`,children:`Delete`})]})}function sr({kind:e}){return G(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}W();var cr=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`pipeline`,label:`Pipeline steps`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0},{id:`wiring`,label:`Wiring`,cameraOnly:!1}];function lr(e){let t=e===Y.Camera;return cr.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var ur=[{id:`logs`,icon:gt,label:`Logs`},{id:`repl`,icon:pt,label:`REPL`},{id:`events`,icon:Ye,label:`Events`},{id:`state`,icon:ct,label:`State`}];function dr(){let e=lt(),t=Number(e.deviceId),n=Number.isFinite(t),r=ot(),i=K(),o=g(),s=J(),[c,l]=ut(),u=c.get(`tab`)??`overview`,d=c.get(`sub`),[f,p]=B(`logs`),m=`device-detail.left-col-width-px`,[h,_]=B(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(m),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),y=U(h);y.current=h;function C(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??h??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{_(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=y.current;if(e!==null)try{window.localStorage.setItem(m,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:w,isLoading:T,isError:E}=N({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:O}=de({deviceId:t},{enabled:n}),k=H(()=>{let e=O?.settings?.sections??[],t=O?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(Ut)&&r.add(Bt),[...r].map(e=>e===`export`?{id:e,label:Vt,isAddonContrib:!0}:{id:e,label:Ge[e]?.label??e,isAddonContrib:!0})},[O]),A=w,j=String(A?.name??e.deviceId??`Device`),M=A?.online===!0,ee=M?`online`:`offline`,P=String(A?.addonId??`rtsp`),F=A?.features??[],I=A?.type,te=I===Y.Camera,ne=typeof A?.parentDeviceId==`number`?A.parentDeviceId:null,{data:re}=N({deviceId:ne??0},{enabled:ne!==null}),L=v(),ie=A?.disabled!==!0,{data:se}=Ee({deviceId:t},{enabled:n}),le=(se?.caps.length??0)>0,fe=H(()=>{let e=new Set,t=[];for(let n of[...lr(I),...k])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!le)&&t.push(n));return t},[I,k,le]),me=H(()=>fe.some(e=>e.id===u)?u:`overview`,[fe,u]),ge=z(e=>{l(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[l]),be=z(e=>{l(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[l]),{data:xe}=wt(n?t:0),Se=(xe??[]).length>0,Ce=H(()=>ur.filter(({featureGate:e})=>!e||F.includes(e)),[F]),{data:R}=Fe({addonId:P},{enabled:!!P&&P!==`rtsp`}),we=he({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]}),r(R?.id?`/integrations/${R.id}`:`/integrations`)}}),Te=oe({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=ve({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Oe=ae(),ke=pe({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ae=F.includes(qe.Rebootable),je=F.includes(qe.BatteryOperated),Me=a(s.trpcClient,je&&n?t:null),[Ne,Pe]=B(!1),V=ze(s.trpcClient,n?t:null),W=async()=>{if(!(Ne||!V)){Pe(!0);try{await V.snapshot?.invalidateCache({});let e=await V.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=j.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{Pe(!1)}}},Le=Te.isPending||De.isPending,{data:Re}=Ie({deviceId:t},{enabled:n,refetchInterval:1e4}),Be=Re?.agentNodeId??null,Ve=typeof Be==`string`&&Be.length>0&&!Be.startsWith(`addon:`)?Be:void 0,{data:Ue}=_e({deviceId:t,...Ve?{nodeId:Ve}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:We}=x({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),Ke=We?.level?.dbfs??null;function Ye(){if(!n)return null;switch(me){case`overview`:return G(hn,{device:A??{}});case`config`:return G(jn,{deviceId:t,activeSubTab:d,onSubTabChange:be});case`pipeline`:return G(Yn,{deviceId:t,refreshToken:0});case`bindings`:return G(Hn,{deviceId:t});case`wiring`:return G(ar,{deviceId:t});default:{let e=me;return k.some(t=>t.id===e)?e===`export`?G(An,{deviceId:t,sectionFilter:Ut,activeSubTab:d,onSubTabChange:be}):G(An,{deviceId:t,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),activeSubTab:d,onSubTabChange:be}):null}}}return n?T?q(`div`,{className:`flex flex-col h-full`,children:[q(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[G(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),G(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),G(`div`,{className:`flex-1 p-6`,children:G(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):E||!w?q(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[G(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),q(`p`,{className:`text-xs`,children:[`No device with ID`,` `,q(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,t]})]}),G(`button`,{onClick:()=>r(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):q(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[G(`div`,{className:`mb-2`,children:G(D,{items:[{label:`Integrations`,onClick:()=>r(`/integrations`)},{label:R?.name??P,onClick:()=>R?.id&&r(`/integrations/${R.id}`)},{label:j}]})}),q(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[G(Qe,{type:P,size:`lg`}),q(`div`,{className:`min-w-0 flex-1`,children:[q(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[G(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:j}),G(Ct,{status:ee}),je&&G(S,{status:Me,variant:`full`})]}),ne!==null&&re&&q(`button`,{type:`button`,onClick:()=>r(`/devices/${ne}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${re.name}`,children:[G(`span`,{children:`↑`}),G(`span`,{className:`truncate`,children:String(re.name??`Device #${ne}`)})]}),G(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:F.length>0&&G(Je,{capabilities:F})})]}),Ue&&G(`div`,{className:`hidden lg:flex`,children:G(fr,{metrics:Ue,dbfs:Ke})}),q(`div`,{className:`flex items-center gap-1 shrink-0`,children:[q(`button`,{onClick:async()=>{ie?await o({title:`Disable "${j}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&De.mutate({deviceId:t}):Te.mutate({deviceId:t})},disabled:Le,title:ie?`Disable device`:`Enable device`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${ie?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[G(Lt,{className:`h-3.5 w-3.5`}),G(`span`,{className:`hidden sm:inline`,children:Le?`Updating…`:ie?`Enabled`:`Disabled`})]}),G(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),G(ue,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:st,disabled:Ne,onClick:()=>{W()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:nt,hidden:!Ae,disabled:Oe.isPending,danger:!0,onClick:async()=>{await o({title:`Reboot "${j}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Oe.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??P}.`,icon:tt,disabled:ke.isPending,danger:!0,onClick:async()=>{await o({title:`Restart "${R?.name??P}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${j}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&ke.mutate({addonId:P})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:vt,separatorBefore:!0,disabled:we.isPending,danger:!0,onClick:async()=>{await o({title:`Delete "${j}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&we.mutate({deviceId:t})}}]})]})]})]}),G(ce,{deviceId:t,device:A??void 0,children:G(b,{children:G(He,{children:G(ye,{children:q(`main`,{className:L?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[q(`div`,{className:L?`flex flex-col bg-surface`:`${h===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!L&&h!==null?{width:`${String(h)}px`}:void 0,children:[G(`div`,{className:`flex-shrink-0 border-b border-border-subtle ${te?`bg-black`:`bg-surface`}`,children:te?G(Qt,{deviceId:t,intercomAvailable:F.includes(qe.TwoWayAudio)}):G(Vn,{deviceId:t,deviceName:j,deviceType:I??`unknown`,provider:P,isOnline:M,features:F})}),q(`div`,{className:L?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[G(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:G(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Ce.map(({id:e,label:t,icon:n})=>q(`button`,{onClick:()=>p(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${f===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[G(n,{className:`h-3 w-3`}),t]},e))})}),q(`div`,{className:L?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[f===`logs`&&G($t,{deviceId:t,containerDeviceId:I===`container`?t:void 0}),f===`repl`&&G(en,{deviceId:t}),f===`events`&&G(tn,{deviceId:t}),f===`state`&&G(nn,{deviceId:t})]})]})]}),!L&&G(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:C,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:G(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),q(`div`,{className:L?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[G(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:G(`div`,{className:`flex flex-wrap items-center gap-0`,children:fe.map(e=>{let t=me===e.id;return q(`button`,{onClick:()=>ge(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&G(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),q(`div`,{className:L?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[me===`overview`&&Se&&G(rn,{parentDeviceId:t}),Ye()]})]})]})})})})})]}):q(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[G(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),q(`p`,{className:`text-xs`,children:[`The URL segment`,` `,G(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),G(`button`,{onClick:()=>r(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function fr({metrics:e,dbfs:t}){let n=De(e.phase??`idle`);return q(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[q(`div`,{className:`flex items-center gap-1.5`,children:[G(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),G(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),G(`div`,{className:`h-3 w-px bg-border`}),q(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[G(St,{className:`h-3 w-3`}),G(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),G(`span`,{children:`fps`})]}),q(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[G(ht,{className:`h-3 w-3`}),G(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),G(`span`,{children:`ms`})]}),q(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[G(Rt,{className:`h-3 w-3`}),G(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),G(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&q(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{dr as DeviceDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{R as e,Vn as t,dn as n,in as r,mn as i,nn as a}from"./src-
|
|
1
|
+
import{R as e,Vn as t,dn as n,in as r,mn as i,nn as a}from"./src-BB1LG2-C.js";import{F as o,U as s,X as c,b 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-CK8iQdP1.js";import{p as f}from"./player-overlays-ZG1nYuYj.js";import{t as p}from"./ProviderIcon-BS00rCO4.js";import{H as m,I as h,o as g,t as _}from"./index-D5OTguVm.js";import{t as v}from"./AdminPage-CN6ZMhf0.js";import{t as y}from"./useEventInvalidation-wNGhDdi_.js";c();function b(){let{t:c}=_(),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=s(()=>C??[],[C]),{activeDevices:k,orphanDevices:A}=s(()=>{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=s(()=>{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=s(()=>(w??[]).map(e=>({id:e.addonId,name:e.name??e.addonId,icon:l(p,{type:e.addonId,size:`sm`})})),[w]),P=o(e=>l(p,{type:e,size:`sm`}),[]),F=o(e=>b(`/devices/${String(e)}`),[b]);return d(v,{icon:h,title:c(`nav.devices`,`Devices`),children:[l(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&&d(`div`,{className:`mt-6 space-y-2`,children:[d(`div`,{className:`flex items-baseline gap-2`,children:[l(g,{className:`h-3.5 w-3.5 text-warning shrink-0`}),l(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Orphan devices`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:[A.length,` device`,A.length===1?``:`s`,` pointing at integrations no longer registered`]})]}),d(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 p-2`,children:[l(`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."}),l(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-
|
|
1
|
+
import{Hi as e,P as t,b as n,i as r}from"./src-BB1LG2-C.js";import{G as i,R as a,U as o,X as s,b as c,d as l,u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{d as f}from"./player-overlays-ZG1nYuYj.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-Cno9Ci3x.js";s();var b=_([v({kind:h(`adaptive`)}),v({kind:h(`profile`),profile:y})]),x=v({serverUrl:m().min(1),token:m().min(1),deviceId:p().int().nonnegative(),target:b,muted:g()});function S(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function C(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function w(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function T(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function E(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=x.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function D({message:e}){return a(()=>{S(`error`,e)},[e]),d(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[`Embed config error: `,e]})}function O({system:e,deviceId:t,initialTarget:s,initialMuted:l}){let[u,d]=i(s),[f,p]=i(l),{handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,getSessionState:y}=r(e.trpcClient,t),x=o(()=>w(u),[u]),E=o(()=>(e,t)=>m(x,e,t),[m,x]),D=o(()=>(e,t,n)=>m(n,t,e),[m]);a(()=>(window.__camstackEmbed={setMuted:e=>p(e),setTarget:e=>{let t=b.safeParse(e);t.success&&d(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let O=T(u);return c(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:c(n,{serverUrl:e.serverUrl,streamKey:O,autoPlay:!0,muted:f,showControls:!1,className:`w-full h-full`,handleOffer:E,reoffer:D,getSessionState:y,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,onStateChange:e=>S(C(e)),onError:e=>S(`error`,e)},O)})}function k(){let n=o(()=>E(),[]),r=o(()=>n.ok?{system:t({serverUrl:n.config.serverUrl,token:n.config.token}),queryClient:new l({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}})}:null,[n]);return a(()=>{if(r)return()=>{r.system.close()}},[r]),n.ok?r?c(f,{system:r.system,children:c(u,{client:r.queryClient,children:c(e.Provider,{client:r.system.trpcClient,queryClient:r.queryClient,children:c(O,{system:r.system,deviceId:n.config.deviceId,initialTarget:n.config.target,initialMuted:n.config.muted})})})}):c(D,{message:`Failed to initialise the embed player`}):c(D,{message:n.error})}export{k as EmbedPlayerPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,S as t}from"./src-
|
|
1
|
+
import{C as e,S as t}from"./src-BB1LG2-C.js";import{G as n,X as r,b as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";r();function o(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function s(e,t){if(e!==void 0)return t&&o(e)?t(e):e}function c({section:r,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,probeResults:f,onAction:p}){let[m,h]=n(r.defaultCollapsed??!1),g=r.style===`accordion`;if(r.fields.reduce((t,n)=>t+ +!!e(n,o,r.fields),0)===0)return null;let _=r.columns??2,v=_===1?`grid-cols-1`:_===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:_===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,y=r.fields.length===1&&r.fields[0]?.type===`widget`?r.fields[0]:void 0;return a(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(y!==void 0||!r.title&&!r.description)&&a(`div`,{className:[`flex items-center justify-between mb-2`,g?`cursor-pointer`:``].join(` `),onClick:g?()=>h(e=>!e):void 0,children:[a(`div`,{children:[r.title&&i(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:s(r.title,u)}),r.description&&i(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s(r.description,u)})]}),g&&i(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:m?`▸`:`▾`})]}),!m&&(y===void 0?i(`div`,{className:`grid ${v} gap-x-3 gap-y-2.5`,children:r.fields.map(e=>i(t,{field:e,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[e.key],allFields:r.fields,onAction:p},e.key))}):i(t,{field:y,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[y.key],allFields:r.fields,onAction:p},y.key))]})}function l({schema:e,values:t,onChange:n,disabled:r,translationFn:a,onTestField:o,probeResults:s,onClearProbe:l,onAction:u}){let d=(e,r)=>{n({...t,[e]:r}),l?.(e)};return i(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>i(c,{section:e,values:t,onChange:d,disabled:r,translationFn:a,onTestField:o,probeResults:s,onAction:u},`${e.id}-${n}`))})}export{l as t};
|
|
@@ -1 +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-D-eMZfpa.js";import{G as S,U as C,X as w,b as T,o as E,x as D,y as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{t as k}from"./circle-check-big-BjqV4p1D.js";import{t as A}from"./copy-DUY8-DBe.js";import{t as j}from"./key-round-BtVEvNiB.js";import{t as M}from"./AddonCollectionPage-DJx4uU6r.js";import{t as ee}from"./plus-CljwKCLZ.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-CBUhNGng.js";import{t as U}from"./AdminPage-CN6ZMhf0.js";import{t as W}from"./AdminTabs-BpXprAan.js";var G=N(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),K=N(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),te=N(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),q=N(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),J=N(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);w();function ne({userId:e,username:t,onClose:n}){let r=E(),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 T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:D(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[D(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[D(`div`,{className:`flex items-center gap-2`,children:[T(R,{className:`h-4 w-4 text-primary`}),D(`div`,{children:[T(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),D(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,T(`span`,{className:`font-mono`,children:t})]})]})]}),T(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`p-4 space-y-4`,children:[d===`loading`&&D(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[T(H,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),d===`not_enrolled`&&D(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[T(P,{className:`h-4 w-4 mt-0.5 shrink-0`}),D(`div`,{children:[T(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),T(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),d===`enrolled`&&s&&D(O,{children:[D(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[T(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),D(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[T(`div`,{className:`font-medium`,children:`2FA is active`}),D(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,s.confirmedAt?new Date(s.confirmedAt).toLocaleString():`—`]})]})]}),T(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),D(`div`,{className:`flex justify-end gap-2`,children:[T(g,{onClick:n,variant:`secondary`,children:`Close`}),D(`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?T(H,{className:`h-3 w-3 animate-spin`}):T(L,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function Y(){let n=E(),{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:C}=o(),w=a(),O=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=p({onSuccess:()=>{O(),l(!1),d(``),h(``),_(!1),y(null)},onError:e=>{y(e instanceof Error?e.message:`Failed to create user`)}}),A=f({onSuccess:O}),j=i({onSuccess:O}),M=e({onSuccess:O}),N=t({onSuccess:()=>{O(),F(null)}}),[P,F]=S(null),[V,W]=S(null),G=b??[];async function K(e){await w({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&A.mutate({id:e.id})}async function q(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await w({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}}function J(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function Y(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return D(U,{children:[T(`div`,{className:`flex items-center justify-end`,children:D(`button`,{onClick:()=>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:[T(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),c&&D(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[D(`div`,{className:`flex items-center justify-between`,children:[T(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),T(`button`,{onClick:()=>l(!1),className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`grid grid-cols-3 gap-3`,children:[D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),T(`input`,{type:`text`,value: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`})]}),D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),T(`input`,{type:`password`,value: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`})]}),D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),D(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`rounded border-border focus:ring-primary`}),T(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),v&&T(`p`,{className:`text-[10px] text-danger`,children:v}),D(`div`,{className:`flex justify-end gap-2`,children:[T(`button`,{onClick:()=>l(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),T(`button`,{onClick:()=>k.mutate({username: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&&T(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),C&&T(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!C&&G.length===0&&T(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return T(r,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>D(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>J(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),T(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return T(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return D(`button`,{onClick:()=>F(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[T(I,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>T(`span`,{className:`text-foreground-subtle`,children:Y(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:t=>{let n=e(t);return D(`div`,{className:`flex items-center justify-end gap-1`,children:[t.id!==s?.id&&t.totpEnabled&&D(`button`,{onClick:()=>W(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[T(R,{className:`h-3 w-3`}),`Remove 2FA`]}),D(`button`,{onClick:()=>q(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[T(te,{className:`h-3 w-3`}),`Reset password`]}),D(`button`,{onClick:()=>K(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),V&&T(ne,{userId:V.id,username:V.username,onClose:()=>W(null)}),P&&T(re,{user:P,onClose:()=>F(null),onSubmit:e=>N.mutate({userId:P.id,scopes:e}),submitting:N.isPending})]})}function re(e){let{user:t}=z(),n=t?.isAdmin===!0;return T(ie,{...e,callerScopes:n?null:t?.scopes??[]})}function ie({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=S(C(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=d(a);return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:D(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[D(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[D(`div`,{children:[D(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),T(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),T(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`px-4 py-4`,children:[T(_,{value:a,onChange:o,clampToParent:i,emptyHint:D(O,{children:[`No scopes granted.`,` `,T(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&T(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),D(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[T(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),T(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?T(H,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}w();var ae=`bg-primary/10 text-primary`,oe=`bg-foreground-subtle/10 text-foreground-subtle`;function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function se(e){return e?e===`*`?`*`:e.join(`, `):``}function ce(){let e=E(),t=a(),{data:r,isLoading:i}=x(),{data:s}=o(),c=C(()=>r??[],[r]),l=C(()=>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}),w=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})},O=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 D(U,{children:[D(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[T(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),D(`button`,{onClick:()=>p(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:l.length===0,title:l.length===0?`Create a user first`:`Issue a scoped token`,children:[T(I,{className:`h-3.5 w-3.5`}),`New token`]})]}),D(Z,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[l.length===0&&T(ue,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),l.map(e=>T(fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{O(e,t)},revokePending:b.isPending,revokeId:b.variables?.id},e.id))]}),c.length>0&&T(Z,{title:`Legacy API keys`,subtitle:`${c.length} pre-existing — revoke only`,children:T(de,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:c.map(e=>{let t=!!e.isAdmin,n=_.isPending&&_.variables?.id===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?ae:oe}`,children:t?`admin`:`regular`})}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:se(e.allowedProviders)||`all`}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:D(`button`,{onClick:()=>{w(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),i&&T(le,{}),f&&T(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&&T(me,{token:m.token,label:m.label,onClose:()=>g(null)})]})}function Z({title:e,subtitle:t,children:n}){return D(`div`,{className:`space-y-2`,children:[D(`div`,{className:`flex items-baseline justify-between`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&T(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function le(){return T(`div`,{className:`space-y-2`,children:[1,2].map(e=>T(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ue({text:e}){return T(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function de({headers:e,rows:t}){return T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:D(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:T(`tr`,{children:e.map((t,n)=>T(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),T(`tbody`,{children:t})]})})}function fe({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=b({userId:e}),s=a??[];return o||s.length===0?null:D(`div`,{className:`space-y-1.5`,children:[T(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),T(de,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>D(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.expiresAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:D(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function pe({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=z(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=S(e[0]?.id??``),[c,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 D(he,{title:`Create scoped token`,onClose:t,children:[D(`div`,{className:`space-y-3`,children:[T(Q,{label:`On behalf of user`,children:T(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>T(`option`,{value:e.id,children:e.username},e.id))})}),T(Q,{label:`Name`,children:T(`input`,{value:c,onChange:e=>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`})}),D(Q,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[T(_,{value:u,onChange:f,clampToParent:a}),h&&T(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),T(Q,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:T(`input`,{type:`number`,min:1,value:p,onChange:e=>m(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),D(ge,{children:[T(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),D(`button`,{onClick:()=>{let e=parseInt(p,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes: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?T(H,{className:`h-3.5 w-3.5 animate-spin`}):T(I,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function me({token:e,label:t,onClose:n}){let[r,i]=S(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return D(he,{title:`Token: ${t}`,onClose:n,children:[D(`div`,{className:`space-y-3`,children:[T(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),T(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),D(ge,{children:[D(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[r?T(F,{className:`h-3.5 w-3.5 text-primary`}):T(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),T(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function he({title:e,onClose:t,children:n}){return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:D(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[D(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),T(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),T(`div`,{className:`p-4`,children:n})]})})}function ge({children:e}){return T(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Q({label:e,hint:t,children:n}){return D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&T(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}w();function $(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function _e(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function ve(){return T(`div`,{className:`space-y-2`,children:[1,2].map(e=>T(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ye({text:e}){return T(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function be({headers:e,rows:t}){return T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:D(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:T(`tr`,{children:e.map((t,n)=>T(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),T(`tbody`,{children:t})]})})}function xe(){let e=E(),t=a(),{data:n,isLoading:r}=u(),i=C(()=>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 D(U,{icon:q,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[r&&T(ve,{}),!r&&i.length===0&&T(ye,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!r&&i.length>0&&T(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 D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>T(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:_e(e)},t))})}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.createdAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 border-b border-border`,children:t?D(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,$(e.revokedAt)]}):T(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&D(`button`,{onClick:()=>{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?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}w();var Se=3e4;function Ce(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function we(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:K,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA can be enrolled per-user from the Users page (added in v0.4).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:V,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:V,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:R,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:R,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:I,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Te(){let e=l({capName:`auth-provider`},{refetchInterval:Se}),t=m(void 0,{refetchInterval:Se}),n=C(()=>Ce(t.data??[]),[t.data]);return T(M,{title:`Authentication`,subtitle:`Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Disabling a provider only removes that external login method; local password login is unaffected. Each provider’s settings + live logs are inline below.`,pageIcon:I,itemIcon:I,capability:`auth-provider`,installButtonLabel:`Add provider`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,renderExpandedPanel:e=>T(Ee,{addonId:e.addonId})})}function Ee({addonId:e}){let t=we(e),n=t.icon;return D(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[D(`div`,{className:`flex items-start gap-2.5`,children:[T(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),T(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),T(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>T(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&D(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[D(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[T(G,{className:`h-3 w-3`}),`Setup steps`]}),T(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>T(`li`,{children:e},t))})]}),e===`local-auth`&&D(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[T(P,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),D(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,T(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”.`]})]})]})}function De(){return T(`div`,{className:`flex flex-col p-4`,children:T(W,{tabs:[{id:`users`,label:`Users`,icon:J,content:T(Y,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:T(ce,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:T(xe,{})},{id:`authentication`,label:`Authentication`,icon:I,content:T(Te,{})}]})})}export{De as IdentityPage};
|
|
1
|
+
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-BB1LG2-C.js";import{G as S,U as C,X as w,b as T,o as E,x as D,y as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CK8iQdP1.js";import{t as k}from"./circle-check-big-Ca1L631f.js";import{t as A}from"./copy-Bi-BgxBp.js";import{t as j}from"./key-round-DdK6mTCz.js";import{t as M}from"./AddonCollectionPage-BHk_82L1.js";import{t as ee}from"./plus-D2fCWFPc.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-D5OTguVm.js";import{t as U}from"./AdminPage-CN6ZMhf0.js";import{t as W}from"./AdminTabs-C5BWg3Pz.js";var G=N(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),K=N(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),te=N(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),q=N(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),J=N(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);w();function ne({userId:e,username:t,onClose:n}){let r=E(),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 T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:D(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[D(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[D(`div`,{className:`flex items-center gap-2`,children:[T(R,{className:`h-4 w-4 text-primary`}),D(`div`,{children:[T(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),D(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,T(`span`,{className:`font-mono`,children:t})]})]})]}),T(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`p-4 space-y-4`,children:[d===`loading`&&D(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[T(H,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),d===`not_enrolled`&&D(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[T(P,{className:`h-4 w-4 mt-0.5 shrink-0`}),D(`div`,{children:[T(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),T(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),d===`enrolled`&&s&&D(O,{children:[D(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[T(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),D(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[T(`div`,{className:`font-medium`,children:`2FA is active`}),D(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,s.confirmedAt?new Date(s.confirmedAt).toLocaleString():`—`]})]})]}),T(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),D(`div`,{className:`flex justify-end gap-2`,children:[T(g,{onClick:n,variant:`secondary`,children:`Close`}),D(`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?T(H,{className:`h-3 w-3 animate-spin`}):T(L,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function Y(){let n=E(),{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:C}=o(),w=a(),O=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=p({onSuccess:()=>{O(),l(!1),d(``),h(``),_(!1),y(null)},onError:e=>{y(e instanceof Error?e.message:`Failed to create user`)}}),A=f({onSuccess:O}),j=i({onSuccess:O}),M=e({onSuccess:O}),N=t({onSuccess:()=>{O(),F(null)}}),[P,F]=S(null),[V,W]=S(null),G=b??[];async function K(e){await w({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&A.mutate({id:e.id})}async function q(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await w({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}}function J(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function Y(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return D(U,{children:[T(`div`,{className:`flex items-center justify-end`,children:D(`button`,{onClick:()=>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:[T(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),c&&D(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[D(`div`,{className:`flex items-center justify-between`,children:[T(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),T(`button`,{onClick:()=>l(!1),className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`grid grid-cols-3 gap-3`,children:[D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),T(`input`,{type:`text`,value: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`})]}),D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),T(`input`,{type:`password`,value: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`})]}),D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),D(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`rounded border-border focus:ring-primary`}),T(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),v&&T(`p`,{className:`text-[10px] text-danger`,children:v}),D(`div`,{className:`flex justify-end gap-2`,children:[T(`button`,{onClick:()=>l(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),T(`button`,{onClick:()=>k.mutate({username: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&&T(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),C&&T(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!C&&G.length===0&&T(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return T(r,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>D(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>J(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),T(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return T(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return D(`button`,{onClick:()=>F(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[T(I,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>T(`span`,{className:`text-foreground-subtle`,children:Y(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:t=>{let n=e(t);return D(`div`,{className:`flex items-center justify-end gap-1`,children:[t.id!==s?.id&&t.totpEnabled&&D(`button`,{onClick:()=>W(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[T(R,{className:`h-3 w-3`}),`Remove 2FA`]}),D(`button`,{onClick:()=>q(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[T(te,{className:`h-3 w-3`}),`Reset password`]}),D(`button`,{onClick:()=>K(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),V&&T(ne,{userId:V.id,username:V.username,onClose:()=>W(null)}),P&&T(re,{user:P,onClose:()=>F(null),onSubmit:e=>N.mutate({userId:P.id,scopes:e}),submitting:N.isPending})]})}function re(e){let{user:t}=z(),n=t?.isAdmin===!0;return T(ie,{...e,callerScopes:n?null:t?.scopes??[]})}function ie({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=S(C(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=d(a);return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:D(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[D(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[D(`div`,{children:[D(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),T(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),T(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),D(`div`,{className:`px-4 py-4`,children:[T(_,{value:a,onChange:o,clampToParent:i,emptyHint:D(O,{children:[`No scopes granted.`,` `,T(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&T(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),D(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[T(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),T(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?T(H,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}w();var ae=`bg-primary/10 text-primary`,oe=`bg-foreground-subtle/10 text-foreground-subtle`;function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function se(e){return e?e===`*`?`*`:e.join(`, `):``}function ce(){let e=E(),t=a(),{data:r,isLoading:i}=x(),{data:s}=o(),c=C(()=>r??[],[r]),l=C(()=>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}),w=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})},O=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 D(U,{children:[D(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[T(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),D(`button`,{onClick:()=>p(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:l.length===0,title:l.length===0?`Create a user first`:`Issue a scoped token`,children:[T(I,{className:`h-3.5 w-3.5`}),`New token`]})]}),D(Z,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[l.length===0&&T(ue,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),l.map(e=>T(fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{O(e,t)},revokePending:b.isPending,revokeId:b.variables?.id},e.id))]}),c.length>0&&T(Z,{title:`Legacy API keys`,subtitle:`${c.length} pre-existing — revoke only`,children:T(de,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:c.map(e=>{let t=!!e.isAdmin,n=_.isPending&&_.variables?.id===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?ae:oe}`,children:t?`admin`:`regular`})}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:se(e.allowedProviders)||`all`}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:D(`button`,{onClick:()=>{w(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),i&&T(le,{}),f&&T(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&&T(me,{token:m.token,label:m.label,onClose:()=>g(null)})]})}function Z({title:e,subtitle:t,children:n}){return D(`div`,{className:`space-y-2`,children:[D(`div`,{className:`flex items-baseline justify-between`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&T(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function le(){return T(`div`,{className:`space-y-2`,children:[1,2].map(e=>T(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ue({text:e}){return T(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function de({headers:e,rows:t}){return T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:D(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:T(`tr`,{children:e.map((t,n)=>T(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),T(`tbody`,{children:t})]})})}function fe({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=b({userId:e}),s=a??[];return o||s.length===0?null:D(`div`,{className:`space-y-1.5`,children:[T(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),T(de,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>D(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.expiresAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:D(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function pe({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=z(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=S(e[0]?.id??``),[c,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 D(he,{title:`Create scoped token`,onClose:t,children:[D(`div`,{className:`space-y-3`,children:[T(Q,{label:`On behalf of user`,children:T(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>T(`option`,{value:e.id,children:e.username},e.id))})}),T(Q,{label:`Name`,children:T(`input`,{value:c,onChange:e=>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`})}),D(Q,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[T(_,{value:u,onChange:f,clampToParent:a}),h&&T(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),T(Q,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:T(`input`,{type:`number`,min:1,value:p,onChange:e=>m(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),D(ge,{children:[T(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),D(`button`,{onClick:()=>{let e=parseInt(p,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes: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?T(H,{className:`h-3.5 w-3.5 animate-spin`}):T(I,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function me({token:e,label:t,onClose:n}){let[r,i]=S(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return D(he,{title:`Token: ${t}`,onClose:n,children:[D(`div`,{className:`space-y-3`,children:[T(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),T(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),D(ge,{children:[D(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[r?T(F,{className:`h-3.5 w-3.5 text-primary`}):T(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),T(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function he({title:e,onClose:t,children:n}){return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:D(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[D(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),T(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:T(L,{className:`h-4 w-4`})})]}),T(`div`,{className:`p-4`,children:n})]})})}function ge({children:e}){return T(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Q({label:e,hint:t,children:n}){return D(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&T(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}w();function $(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function _e(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function ve(){return T(`div`,{className:`space-y-2`,children:[1,2].map(e=>T(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ye({text:e}){return T(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function be({headers:e,rows:t}){return T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:D(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:T(`tr`,{children:e.map((t,n)=>T(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),T(`tbody`,{children:t})]})})}function xe(){let e=E(),t=a(),{data:n,isLoading:r}=u(),i=C(()=>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 D(U,{icon:q,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[r&&T(ve,{}),!r&&i.length===0&&T(ye,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!r&&i.length>0&&T(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 D(`tr`,{className:`hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),T(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:T(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>T(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:_e(e)},t))})}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.createdAt)}),T(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.lastUsedAt)}),T(`td`,{className:`px-3 py-2 border-b border-border`,children:t?D(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,$(e.revokedAt)]}):T(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),T(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&D(`button`,{onClick:()=>{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?T(H,{className:`h-3 w-3 animate-spin`}):T(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}w();var Se=3e4;function Ce(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function we(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:K,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA can be enrolled per-user from the Users page (added in v0.4).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:V,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:V,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:R,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:R,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:I,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Te(){let e=l({capName:`auth-provider`},{refetchInterval:Se}),t=m(void 0,{refetchInterval:Se}),n=C(()=>Ce(t.data??[]),[t.data]);return T(M,{title:`Authentication`,subtitle:`Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Disabling a provider only removes that external login method; local password login is unaffected. Each provider’s settings + live logs are inline below.`,pageIcon:I,itemIcon:I,capability:`auth-provider`,installButtonLabel:`Add provider`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,renderExpandedPanel:e=>T(Ee,{addonId:e.addonId})})}function Ee({addonId:e}){let t=we(e),n=t.icon;return D(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[D(`div`,{className:`flex items-start gap-2.5`,children:[T(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),T(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),T(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>T(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&D(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[D(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[T(G,{className:`h-3 w-3`}),`Setup steps`]}),T(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>T(`li`,{children:e},t))})]}),e===`local-auth`&&D(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[T(P,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),D(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,T(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”.`]})]})]})}function De(){return T(`div`,{className:`flex flex-col p-4`,children:T(W,{tabs:[{id:`users`,label:`Users`,icon:J,content:T(Y,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:T(ce,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:T(xe,{})},{id:`authentication`,label:`Authentication`,icon:I,content:T(Te,{})}]})})}export{De as IdentityPage};
|