@camstack/addon-admin-ui 1.1.20 → 1.1.21
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-Brlh9UJ9.js → AddLocationWizard-CtHh4Ucy.js} +1 -1
- package/dist/assets/{AddonCollectionPage-Bg5OVL_9.js → AddonCollectionPage-D7eIR9NV.js} +1 -1
- package/dist/assets/Addons-BoCfiheF.js +1 -0
- package/dist/assets/{AdminTabs-DVI3osLb.js → AdminTabs-SHELeszh.js} +1 -1
- package/dist/assets/{BrokerForm-CS__YhVd.js → BrokerForm-Acer17Cj.js} +1 -1
- package/dist/assets/{Capabilities-sR8ZG2Sp.js → Capabilities-F8EOFDyp.js} +1 -1
- package/dist/assets/{CapabilityBadges-BtwEWtSB.js → CapabilityBadges-uN4xnNt9.js} +1 -1
- package/dist/assets/Cluster-Br54rXlE.js +1 -0
- package/dist/assets/{Dashboard-cUXiEA9q.js → Dashboard-Ds4y9hsA.js} +1 -1
- package/dist/assets/{Data-FggSTTQB.js → Data-BadX573w.js} +1 -1
- package/dist/assets/{DetectionIntelligence-BG1dq_BC.js → DetectionIntelligence-Crlw81K-.js} +1 -1
- package/dist/assets/DeviceDetail-DLlQRj_v.js +2 -0
- package/dist/assets/{Devices-DfYGm_-Y.js → Devices-CSuhWvHj.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-2oboqnId.js → EmbedPlayerPage-ChE8oSUc.js} +1 -1
- package/dist/assets/{FormBuilder-B6OIFE8M.js → FormBuilder-CegbdtFO.js} +1 -1
- package/dist/assets/{Identity-CiOHNQP2.js → Identity-CVFKJESU.js} +1 -1
- package/dist/assets/IntegrationDetail-DsUKq3z5.js +1 -0
- package/dist/assets/Integrations-CuVxDYIj.js +1 -0
- package/dist/assets/{Integrations-BOUUPSGH.js → Integrations-DiaCWNDC.js} +1 -1
- package/dist/assets/{Logs-C_K69uCx.js → Logs-BLu18FYD.js} +1 -1
- package/dist/assets/{MotionZonesSettings-BnjJUOgY.js → MotionZonesSettings-CQu6k79T.js} +1 -1
- package/dist/assets/{MyAccess-BKZkUhvb.js → MyAccess-CLaxbnXE.js} +1 -1
- package/dist/assets/{Network-Bu7lrlmc.js → Network-kXez-Kpm.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-CsBUUhBI.js → NodeAddonsSettingsPanel-BOqWOM7_.js} +1 -1
- package/dist/assets/{NotificationTargets-DlPYj2Ic.js → NotificationTargets-C7ekw4dH.js} +1 -1
- package/dist/assets/Pipeline-iwj4d4DN.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-RUAuOFuS.js → PrivacyMaskSettings-CyaPh6bF.js} +1 -1
- package/dist/assets/{ProviderIcon-RCIWUZYh.js → ProviderIcon-BVyDFfZQ.js} +1 -1
- package/dist/assets/{ScanNetworkModal-CVTAzCpc.js → ScanNetworkModal-CAWMDwou.js} +1 -1
- package/dist/assets/{Settings-BRGkGmWW.js → Settings-vLhU6eIs.js} +1 -1
- package/dist/assets/{Showroom-nB3ihbXc.js → Showroom-CyXCqK1A.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CCEnK7l6.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DAX7XSx3.js} +1 -1
- package/dist/assets/circle-check-big-CgdBZ1l7.js +1 -0
- package/dist/assets/{copy-Dx6PkNh2.js → copy-B6IIL8kT.js} +1 -1
- package/dist/assets/dist-BAhtRh_d.js +6 -0
- package/dist/assets/{dist-BcfEPpAI.js → dist-DwxrMREn.js} +1 -1
- package/dist/assets/{download-hTrdF0db.js → download-H_XK0DLj.js} +1 -1
- package/dist/assets/{esm-CU8QwYlu.js → esm-C1lbdX0r.js} +1 -1
- package/dist/assets/{hostInit-Bkxnbz6r.js → hostInit-BhkWchBW.js} +1 -1
- package/dist/assets/index-Bvv3nxPc.css +2 -0
- package/dist/assets/index-DjbbJhB4.js +4 -0
- package/dist/assets/{key-round-CME-3JbN.js → key-round-Dyj4n5xw.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-b91b99eb.js → mf-entry-bootstrap-0-efb2b672.js} +2 -2
- package/dist/assets/{pencil-DJ_y_Wy8.js → pencil-D4eE6uEV.js} +1 -1
- package/dist/assets/{player-overlays-DEDwF8Uo.js → player-overlays-BH6aBUe-.js} +1 -1
- package/dist/assets/plus-CDeS7IvC.js +1 -0
- package/dist/assets/{radio-C_HfliiA.js → radio-CfQ90vM2.js} +1 -1
- package/dist/assets/{refresh-cw-9oudg8kg.js → refresh-cw-DCVnt6DS.js} +1 -1
- package/dist/assets/remoteEntry-D3SUgyps.js +1 -0
- package/dist/assets/{rotate-ccw-5_RfArHn.js → rotate-ccw-D6a6yNNE.js} +1 -1
- package/dist/assets/rotate-cw-BZnE1cAg.js +1 -0
- package/dist/assets/search-DGzI_eqI.js +1 -0
- package/dist/assets/{server-CQ1LH5PQ.js → server-DglCnPiH.js} +1 -1
- package/dist/assets/{sparkles-DvV1ODWG.js → sparkles-Cfbrs3IH.js} +1 -1
- package/dist/assets/square-Cgyuo7em.js +1 -0
- package/dist/assets/{square-check-big-64TOhDex.js → square-check-big-DkE6GAlP.js} +1 -1
- package/dist/assets/{src-50esl92F.js → src-BVMxsNe8.js} +4 -4
- package/dist/assets/src-CCmaAR6i.js +6 -0
- package/dist/assets/{upload-BgSvbRWR.js → upload-D2GIH0tS.js} +1 -1
- package/dist/assets/{useDevice-BGpZXQ7x.js → useDevice-CAq7iz29.js} +1 -1
- package/dist/assets/{useEventInvalidation-BTia6ZIb.js → useEventInvalidation-B-rUQp_C.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-tX1XrtZb.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Im2hSrP1.js} +2 -2
- package/dist/assets/{wifi-Ctshxl91.js → wifi-TvDBvENo.js} +1 -1
- package/dist/assets/{zap-BgTF9BOT.js → zap-Cb9KqtLJ.js} +1 -1
- package/dist/index.html +6 -6
- package/dist/server/addon.js +50 -12
- package/package.json +1 -1
- package/dist/assets/Addons-2VeHH2Fx.js +0 -1
- package/dist/assets/Cluster-BsMp1-aa.js +0 -1
- package/dist/assets/DeviceDetail-DD7tVaBH.js +0 -2
- package/dist/assets/IntegrationDetail-BVhsZAdC.js +0 -1
- package/dist/assets/Integrations-CVCNKHh5.js +0 -1
- package/dist/assets/Pipeline-CFOZ4ITe.js +0 -1
- package/dist/assets/circle-check-big-DUVoa4K8.js +0 -1
- package/dist/assets/dist-B40Mc3dp.js +0 -6
- package/dist/assets/index-DpDrVUWD.css +0 -2
- package/dist/assets/index-DvxZ6VPS.js +0 -4
- package/dist/assets/plus-BgpJnRYz.js +0 -1
- package/dist/assets/remoteEntry-Buh8tQ2B.js +0 -1
- package/dist/assets/rotate-cw-ClWkf91I.js +0 -1
- package/dist/assets/search-CxsQfiZy.js +0 -1
- package/dist/assets/square-CQY_D8K1.js +0 -1
- package/dist/assets/src-BnbSKfdg.js +0 -6
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Cr as e,Gr as t,Ji as n,Qr as r,Sr as i,Tr as a,Ui as o,Xi as s,Yr as c,ai as l,br as u,ca as d,da as f,fr as p,g as m,h,la as g,m as _,pr as v,ua as y,wr as b,xr as x,yr as S}from"./src-50esl92F.js";import{I as C,K as w,Q as T,S as E,W as D,b as O,o as k,q as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as N}from"./pencil-DJ_y_Wy8.js";import{t as P}from"./radio-C_HfliiA.js";import{t as F}from"./refresh-cw-9oudg8kg.js";import{t as I}from"./rotate-cw-ClWkf91I.js";import{t as L}from"./server-CQ1LH5PQ.js";import{t as R}from"./upload-BgSvbRWR.js";import{F as ee,L as te,M as z,P as B,V,i as ne,k as re,o as ie,p as H,s as U,x as W}from"./index-DvxZ6VPS.js";import{t as G}from"./format-size-CO9d3C3-.js";import{t as K}from"./NodeAddonsSettingsPanel-CsBUUhBI.js";import{a as q,i as J,n as Y,r as X,t as ae}from"./esm-CU8QwYlu.js";var Z=V(`ghost`,[[`path`,{d:`M9 10h.01`,key:`qbtxuw`}],[`path`,{d:`M15 10h.01`,key:`1qmjsl`}],[`path`,{d:`M12 2a8 8 0 0 0-8 8v12l3-3 2.5 2.5L12 19l2.5 2.5L17 19l3 3V10a8 8 0 0 0-8-8z`,key:`uwwb07`}]]),oe=V(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),se=V(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),Q=V(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),ce=V(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]);T();function le(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function ue({nodeId:e,addons:t,isHub:n}){let r=k(),i=o(),[s,c]=A(null),[l,u]=A(null),[d,f]=A(!1),[p,m]=A(null),[h,g]=A(0),_=w(null),v=x(),y=a(),b=S({nodeId:e}),C=b.data??[],T=new Map(t.map(e=>[e.id,e.capabilities])),D=C.length>0?C.map(e=>({id:e.id,status:e.status,capabilities:T.get(e.id)??[],version:e.version,packageName:e.packageName})):t.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),O=()=>{r.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),b.refetch()},M=async t=>{c(t);try{await v.mutateAsync({nodeId:e,addonId:t}),O()}catch(e){console.error(`Failed to restart addon:`,e)}finally{c(null)}},N=async t=>{if(await i({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){u(t);try{await y.mutateAsync({nodeId:e,addonId:t}),O()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{u(null)}}},P=E(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(`input`,{ref:_,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,m(null),f(!0),g(0);try{await le({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:g}),O()}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(!1),g(0)}}}}),E(`button`,{onClick:()=>_.current?.click(),disabled:d,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[d?j(W,{className:`h-3 w-3 animate-spin`}):j(R,{className:`h-3 w-3`}),d?`Uploading… ${h}%`:`Upload addon (.tgz)`]}),d&&j(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:j(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${h}%`}})}),p&&j(`span`,{className:`text-[10px] text-destructive`,children:p})]});return D.length===0?E(`div`,{children:[P,j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:b.isLoading?`Loading addons…`:`No addons on this node`})]}):E(`div`,{children:[P,E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:E(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium`,children:`Addon`}),j(`th`,{className:`py-2 font-medium`,children:`Version`}),j(`th`,{className:`py-2 font-medium`,children:`Capabilities`}),j(`th`,{className:`py-2 font-medium`,children:`Status`}),j(`th`,{className:`py-2 font-medium w-16`})]})}),j(`tbody`,{children:D.map(e=>E(`tr`,{className:`border-t border-border/50`,children:[E(`td`,{className:`py-2 font-medium`,children:[j(`div`,{children:e.id}),e.packageName&&j(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),j(`td`,{className:`py-2 text-muted-foreground`,children:e.version??`—`}),j(`td`,{className:`py-2`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):j(`span`,{className:`text-muted-foreground`,children:`—`})})}),j(`td`,{className:`py-2`,children:j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),j(`td`,{className:`py-2`,children:E(`div`,{className:`flex items-center gap-1 justify-end`,children:[j(`button`,{onClick:()=>M(e.id),disabled:s===e.id||l===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:j(I,{className:`h-3 w-3 ${s===e.id?`animate-spin`:``}`})}),j(`button`,{onClick:()=>N(e.id),disabled:s===e.id||l===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:l===e.id?j(W,{className:`h-3 w-3 animate-spin`}):j(U,{className:`h-3 w-3`})})]})})]},e.id))})]})]})}T();function de(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function fe({state:e}){return j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var pe=[`trace`,`debug`,`info`,`warn`,`error`];function me({proc:t,nodeId:n,defaultExpanded:r,activePanel:a,onTogglePanel:o}){let s=t.services??[],c=s.length===1,[l,u]=A(c||r),[p,h]=A(null),[v,b]=A(`info`),S=t.name.includes(`(core)`),C=x(),w=i(),T=e(),D=async e=>{h(e);try{await C.mutateAsync({nodeId:n,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{h(null)}},O=async()=>{h(t.name);try{await w.mutateAsync({nodeId:n,processName:t.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{h(null)}},k=async e=>{let r=`${n}/${t.name}`;try{await T.mutateAsync({nodeId:r,level:e}),b(e)}catch(e){console.error(`Failed to set log level:`,e)}};return E(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[E(`div`,{role:c?void 0:`button`,tabIndex:c?void 0:0,onClick:c?void 0:()=>u(!l),onKeyDown:c?void 0:e=>{(e.key===`Enter`||e.key===` `)&&u(!l)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${c?``:`hover:bg-muted/40 cursor-pointer`}`,children:[c?j(`span`,{className:`h-3 w-3 shrink-0`}):j(l?B:z,{className:`h-3 w-3 text-muted-foreground shrink-0`}),S?j(L,{className:`h-3.5 w-3.5 text-primary shrink-0`}):j(te,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),j(`span`,{className:`text-xs font-semibold flex-1`,children:t.name}),E(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,t.pid]}),j(fe,{state:t.state}),E(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[t.cpuPercent,`% CPU`]}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:G(t.memoryRss)}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:de(t.uptimeSeconds)}),!S&&E(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[E(d,{children:[j(f,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:v}),j(g,{align:`end`,className:`min-w-[70px] py-0.5`,children:pe.map(e=>j(y,{onClick:()=>k(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===v?`text-primary font-semibold`:``}`,children:e},e))})]}),j(`button`,{onClick:O,disabled:p===t.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:j(I,{className:`h-3 w-3 ${p===t.name?`animate-spin`:``}`})})]})]}),l&&s.length>0&&j(`div`,{className:`divide-y divide-border/30`,children:s.map(e=>E(`div`,{children:[E(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[j(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),j(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&E(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&E(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),E(`div`,{className:`flex items-center gap-1 shrink-0`,children:[j(`button`,{onClick:()=>o(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${a?.addonId===e.addonId&&a.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:j(H,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>o(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${a?.addonId===e.addonId&&a.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:j(P,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>D(e.addonId),disabled:p===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:j(I,{className:`h-3 w-3 ${p===e.addonId?`animate-spin`:``}`})})]})]}),a?.addonId===e.addonId&&a.type===`logs`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(m,{addonId:e.addonId,agentId:n,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>o(e.addonId,`logs`)})}),a?.addonId===e.addonId&&a.type===`events`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(_,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>o(e.addonId,`events`)})})]},e.addonId))}),l&&s.length===0&&j(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function he({nodeId:e,processes:t}){let[n,r]=A(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):j(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>j(me,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}T();function ge(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function _e(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function ve({nodeId:e}){let t=k(),r=o(),[i,a]=A(`all`),s=n(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:c}=v({nodeId:e}),l=s?.processes??c,u=D(()=>l?[...l]:[],[l]),d=D(()=>i===`ghost`?u.filter(e=>e.classification===`ghost`):u,[u,i]),f=D(()=>{let e=u.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[u]),m=p({onSettled:()=>{t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),h=D(()=>{let e=new Map;for(let t of u)e.set(t.pid,t.classification);return e},[u]),g=async(t,n)=>{if(t.classification===`root`||t.classification===`system`)return;let i=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=n?`SIGKILL`:`SIGTERM`;await r({title:`Send ${a}?`,message:`Target pid ${t.pid} (${i}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&m.mutate({nodeId:e,pid:t.pid,force:n})},_=async(t,n)=>{try{await m.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},y=async n=>{let i=h.get(n.ppid);if(i===`root`||i===`system`){await r({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${n.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${n.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await r({title:`Kill ghost parent + ${n.children.length} child(ren)?`,message:`SIGKILL parent pid ${n.ppid} and SIGTERM ${n.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([_(n.ppid,!0),...n.children.map(e=>_(e.pid,!1))]),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},b=async()=>{let n=u.filter(e=>e.classification===`ghost`);n.length!==0&&await r({title:`Kill all ${n.length} ghost process(es)?`,message:`SIGKILL ${n.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(n.map(e=>_(e.pid,!0))),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},x=u.filter(e=>e.classification===`ghost`).length,S=u.filter(e=>e.classification===`managed`).length,C=u.filter(e=>e.classification===`root`).length,w=u.filter(e=>e.classification===`system`).length;return E(`div`,{className:`space-y-4`,children:[E(`div`,{className:`flex items-start justify-between gap-4`,children:[E(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),E(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[j(F,{className:`h-3 w-3`}),` Refresh`]})]}),E(`div`,{className:`grid grid-cols-4 gap-3`,children:[E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:C})]}),E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:S})]}),E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:w})]}),E(`div`,{className:`rounded-lg border p-3 ${x>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[E(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[x>0&&j(Q,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),j(`div`,{className:`text-xl font-semibold ${x>0?`text-destructive`:`text-foreground`}`,children:x})]})]}),f.length>0&&E(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[E(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[j(ie,{className:`h-3 w-3`}),` Recurring ghost parents (`,f.length,`)`]}),j(`div`,{className:`space-y-1.5`,children:f.map(e=>E(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[E(`div`,{className:`flex items-center gap-2`,children:[E(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),E(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),E(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{y(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),E(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[E(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),E(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>a(`all`),children:[`All (`,u.length,`)`]}),E(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>a(`ghost`),children:[`Ghost only (`,x,`)`]})]}),x>0&&E(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{b()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill all `,x,` ghost(s)`]})]}),j(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`bg-surface`,children:E(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[j(`th`,{className:`text-left px-3 py-2`,children:`Class`}),j(`th`,{className:`text-right px-3 py-2`,children:`PID`}),j(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),j(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),j(`th`,{className:`text-left px-3 py-2`,children:`Command`}),j(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),j(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),j(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),j(`th`,{className:`w-44`})]})}),E(`tbody`,{children:[d.length===0&&j(`tr`,{children:j(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:i===`ghost`?`No ghost processes detected.`:`Scanning…`})}),d.map(e=>E(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[j(`td`,{className:`px-3 py-2`,children:j(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),j(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),E(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),j(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),j(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:_e(e.command)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:G(e.memoryRssBytes)}),j(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ge(e.uptimeSec)}),j(`td`,{className:`px-3 py-2 text-right`,children:E(`div`,{className:`inline-flex gap-1`,children:[E(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{g(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[j(U,{className:`h-3 w-3`}),` Term`]}),E(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{g(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),m.isError&&E(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,m.error instanceof Error?m.error.message:`unknown`]})]})}function ye({nodeId:e,addonIds:t}){return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):j(`div`,{className:`w-full py-2`,children:j(K,{nodeId:e,addonIds:t,level:`global`})})}T();function be({nodeId:e,addons:n}){let r=k(),{data:i,isLoading:a}=t({nodeId:e}),o=D(()=>{let e=new Map;for(let t of n)for(let n of t.capabilities){let r=e.get(n)??[];r.push(t.id),e.set(n,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[n]),s=l({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return o.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:E(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium w-1/2`,children:`Capability`}),j(`th`,{className:`py-2 font-medium`,children:`Bound provider`})]})}),j(`tbody`,{children:o.map(({capName:t,providers:n})=>{let r=i?.[t]??n[0]??``,o=n.length===1;return E(`tr`,{className:`border-t border-border/50`,children:[j(`td`,{className:`py-2 font-medium`,children:t}),j(`td`,{className:`py-2`,children:j(`select`,{value:r,onChange:n=>s.mutate({nodeId:e,capName:t,addonId:n.target.value}),disabled:o||s.isPending||a,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:o?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>j(`option`,{value:e,children:e},e))})})]},t)})})]})}T();function xe(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function Se(e){let[t,n]=A(!1),[r,i]=A(e.name),a=k(),o=u({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),s=(e.localIps??[]).filter(e=>!e.includes(`:`)),c=(e.localIps??[]).filter(e=>e.includes(`:`)),l=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await o.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},d=[[`Node ID`,j(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?E(`div`,{className:`flex items-center gap-1.5`,children:[j(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l(),e.key===`Escape`&&n(!1)},disabled:o.isPending,autoFocus:!0}),j(`button`,{onClick:()=>void l(),disabled:o.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:j(ee,{className:`h-3.5 w-3.5`})}),j(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:j(ne,{className:`h-3.5 w-3.5`})})]}):E(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&j(`button`,{onClick:()=>{i(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:j(N,{className:`h-3 w-3`})})]})],[`Hostname`,j(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Platform`,E(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,E(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,j(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,j(`span`,{className:`text-xs`,children:xe(e.uptime)})],[`Engines`,e.engines.length>0?j(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return s.length>0&&d.push([`IPv4`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map((e,t)=>j(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),c.length>0&&d.push([`IPv6`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>j(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),j(`div`,{className:`py-2`,children:j(`table`,{className:`w-full text-sm`,children:j(`tbody`,{children:d.map(([e,t],n)=>E(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[j(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),j(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}T();function Ce({node:e}){let[t,n]=A(`info`),r=e.processes??[],i=e.addons.map(e=>e.id);return e.isOnline?E(`div`,{className:`border border-border rounded-xl overflow-hidden`,children:[E(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),E(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),E(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[E(`span`,{className:`flex items-center gap-1`,children:[j(re,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),E(`span`,{className:`flex items-center gap-1`,children:[j(se,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),j(`div`,{className:`flex border-b border-border px-4`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(i=>j(`button`,{onClick:()=>n(i),className:`px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===i?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:i===`info`?`Info`:i===`addons`?`Addons (${e.addons.length})`:i===`forks`?`Forks (${r.length})`:i===`processes`?`Processes`:i===`settings`?`Settings`:`Capabilities`},i))}),E(`div`,{className:`px-4 py-2`,children:[t===`info`&&j(Se,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps}),t===`addons`&&j(ue,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),t===`forks`&&j(he,{nodeId:e.id,processes:r}),t===`processes`&&j(ve,{nodeId:e.id}),t===`settings`&&j(ye,{nodeId:e.id,addonIds:i}),t===`capabilities`&&j(be,{nodeId:e.id,addons:e.addons})]})]}):E(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[E(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),E(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),j(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),E(`div`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:[e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned — will resume when node reconnects`]})]})}T();function we({nodes:e,focusNodeId:t,focusNonce:n}){let r=[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)),i=w(null);return M(()=>{if(!t)return;let e=i.current?.querySelector(`#node-card-${CSS.escape(t)}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[t,n]),j(`div`,{ref:i,className:`flex flex-col gap-4`,children:r.map(e=>j(`div`,{id:`node-card-${e.id}`,children:j(Ce,{node:e})},e.id))})}T();function Te(e){return e===`running`||e===`online`?`bg-success`:e===`crashed`||e===`failed`?`bg-destructive`:`bg-muted-foreground`}function Ee({runner:e,nodeId:t,expanded:n,pid:r,onToggleCaps:i}){let[a,o]=A(!1),s=x();function c(){s.mutateAsync({nodeId:t,addonId:e.addonId})}function l(){o(e=>!e)}return E(`div`,{className:`border border-border rounded-md px-2 py-1.5 text-xs space-y-1`,children:[E(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[j(`span`,{className:`shrink-0 h-1.5 w-1.5 rounded-full ${Te(e.state)}`,"aria-label":`status: ${e.state}`}),j(`span`,{className:`font-medium truncate flex-1 min-w-0`,children:e.name}),E(`span`,{className:`shrink-0 text-muted-foreground`,children:[e.cpu.toFixed(1),`%`]}),j(`span`,{className:`shrink-0 text-muted-foreground`,children:G(e.mem)}),E(`button`,{type:`button`,"aria-label":`caps: ${e.caps.length}`,onClick:()=>i(r),className:`shrink-0 inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-muted text-muted-foreground hover:bg-muted/80`,children:[j(n?B:z,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),E(`span`,{children:[`caps: `,e.caps.length]})]}),j(`button`,{type:`button`,"aria-label":`Restart addon`,onClick:c,className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted`,children:j(I,{className:`h-3 w-3`})}),j(`button`,{type:`button`,"aria-label":`Logs`,onClick:l,className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted`,children:j(H,{className:`h-3 w-3`})})]}),n&&e.caps.length>0&&j(`ul`,{className:`pl-3 space-y-0.5`,children:e.caps.map(e=>E(`li`,{className:`text-muted-foreground`,children:[j(`span`,{className:`text-foreground`,children:e.name}),` · `,j(`span`,{children:e.addonId})]},`${e.name}\0${e.addonId}`))}),a&&j(h,{addonId:e.addonId,agentId:t,showScope:!0,onClose:()=>o(!1)})]})}T();function De(e){return e?`bg-success`:`bg-muted-foreground`}function $({data:e}){let[t,n]=A(new Set),r=C(e=>{n(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);return M(()=>{e.expandAllNonce!==0&&(e.expandAllValue?n(new Set(e.runners.map(e=>e.pid))):n(new Set))},[e.expandAllNonce,e.expandAllValue,e.runners]),E(`div`,{className:`border border-border rounded-xl bg-background shadow-md min-w-[280px] max-w-[360px] flex flex-col${e.isOnline?``:` opacity-50`}`,children:[j(X,{type:`target`,position:q.Left}),j(X,{type:`source`,position:q.Right}),E(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[j(`span`,{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded bg-muted text-muted-foreground shrink-0`,children:e.isHub?`HUB`:`AGENT`}),j(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${De(e.isOnline)}`,"aria-label":e.isOnline?`online`:`offline`}),j(`span`,{className:`font-semibold text-sm truncate flex-1 min-w-0`,children:e.identity.name}),j(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:e.identity.ip}),E(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[e.identity.cpu,`%`]}),E(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[e.identity.mem,`%`]}),j(`button`,{type:`button`,"aria-label":`Open node detail`,onClick:()=>e.onOpenNodeDetail(e.nodeId),className:`shrink-0 text-xs text-muted-foreground hover:text-foreground underline-offset-2 hover:underline ml-1`,children:`↗`})]}),E(`div`,{className:`flex flex-col gap-1 p-2 max-h-96 overflow-auto`,children:[e.runners.map(n=>j(Ee,{runner:n,nodeId:e.nodeId,expanded:t.has(n.pid),onToggleCaps:r,pid:n.pid},n.pid)),e.runners.length===0&&j(`span`,{className:`text-xs text-muted-foreground px-1`,children:`No processes`})]})]})}T();var Oe={nodeBox:$};function ke(e,t){let n=new Map,r=0,i=0;for(let a=0;a<e.length;a++){let o=e[a];o!==void 0&&(t[a]?(n.set(o,{x:0,y:i*340}),i++):(n.set(o,{x:480,y:r*340}),r++))}return n}function Ae(e,t){if(e===``)return!0;let n=e.toLowerCase();return t.identity.name.toLowerCase().includes(n)?!0:t.runners.some(e=>e.name.toLowerCase().includes(n)||e.addonId.toLowerCase().includes(n)||e.caps.some(e=>e.name.toLowerCase().includes(n)||e.addonId.toLowerCase().includes(n)))}function je({graph:e,onOpenNodeDetail:t}){let[n,r]=A(``),[i,a]=A(!1),[o,s]=A(0),c=C(()=>{a(!0),s(e=>e+1)},[]),l=C(()=>{a(!1),s(e=>e+1)},[]),u=C(e=>{t?.(e)},[t]),d=D(()=>ke(e.nodes.map(e=>e.nodeId),e.nodes.map(e=>e.isHub)),[e.nodes]),f=D(()=>e.nodes.map(e=>{let t=d.get(e.nodeId)??{x:0,y:0},r={...e,onOpenNodeDetail:u,expandAllValue:i,expandAllNonce:o},a=n!==``&&!Ae(n,r);return{id:e.nodeId,type:`nodeBox`,position:t,data:r,hidden:a}}),[e.nodes,d,u,n,i,o]),p=D(()=>e.edges.map(e=>({id:e.id,source:e.source,target:e.target,label:`moleculer`,style:e.online?{}:{strokeDasharray:`5,5`,opacity:.4},animated:!1})),[e.edges]);return E(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[E(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[j(`input`,{type:`search`,placeholder:`Filter by node / runner / cap…`,value:n,onChange:e=>r(e.target.value),className:`flex-1 text-xs border border-border rounded px-2 py-1 bg-background focus:outline-none focus:ring-1 focus:ring-ring`}),j(`button`,{type:`button`,onClick:c,className:`text-xs px-2 py-1 rounded border border-border hover:bg-muted`,children:`Expand all`}),j(`button`,{type:`button`,onClick:l,className:`text-xs px-2 py-1 rounded border border-border hover:bg-muted`,children:`Collapse all`})]}),j(`div`,{className:`flex-1 min-h-0 border-t border-border overflow-hidden`,children:E(J,{nodes:f,edges:p,nodeTypes:Oe,fitView:!0,proOptions:{hideAttribution:!0},children:[j(ae,{gap:20,size:1}),j(Y,{showInteractive:!1})]})})]})}function Me(e){if(e===void 0||e.length===0)return[];let t=new Set,n=[];for(let r of e)for(let e of r.capabilities){let i=`${e}\0${r.addonId}`;t.has(i)||(t.add(i),n.push({name:e,addonId:r.addonId}))}return n.toSorted((e,t)=>e.name.localeCompare(t.name))}function Ne(e){let t=e.services;return{pid:e.pid,name:e.name,addonId:t?.[0]?.addonId??``,cpu:e.cpuPercent,mem:e.memoryRss,state:e.state,caps:Me(t)}}function Pe(e){return{nodeId:e.id,isHub:e.isHub,isOnline:e.isOnline,identity:{name:e.name,ip:e.localIps?.[0]??``,cpu:e.cpuPercent,mem:e.memoryPercent,platform:e.platform,arch:e.arch},runners:e.processes.map(Ne)}}function Fe(e){let t=e.toSorted((e,t)=>{let n=+!!e.isHub;return+!!t.isHub-n}).map(Pe),n=t.find(e=>e.isHub);return n===void 0?{nodes:t,edges:[]}:{nodes:t,edges:t.filter(e=>!e.isHub).map(e=>({id:`hub:${n.nodeId}->${e.nodeId}`,source:n.nodeId,target:e.nodeId,online:e.isOnline&&n.isOnline}))}}T();function Ie({onlineNodeIds:e}){let t=k(),n=o(),{data:i,isLoading:a}=c(),s=r({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]})}}),l=D(()=>{if(!i)return[];let t=new Set(e);return t.add(`hub`),i.filter(e=>!t.has(e.nodeId))},[i,e]);if(a)return j(`section`,{className:`rounded-lg border border-border bg-surface p-6 text-xs text-muted-foreground animate-pulse`,children:`Loading persisted agent settings…`});let u=async e=>{await n({title:`Remove offline agent?`,message:`Drop the persisted orchestrator settings for "${e}". This won't affect a node that comes back online — it just clears stale addonDefaults so it stops cluttering the cluster view.`,confirmLabel:`Remove`,cancelLabel:`Keep`,variant:`danger`})&&s.mutate({agentNodeId:e})};return l.length===0?j(`section`,{className:`rounded-lg border border-border bg-surface p-6`,children:E(`div`,{className:`flex flex-col items-center gap-2 text-center text-muted-foreground`,children:[j(Z,{className:`h-6 w-6 opacity-40`}),j(`p`,{className:`text-xs`,children:`No stale agent entries.`}),j(`p`,{className:`text-[11px] opacity-60`,children:`Every persisted nodeId matches a node currently online in the cluster.`})]})}):E(`section`,{className:`rounded-lg border border-border bg-surface`,children:[E(`header`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border`,children:[j(Z,{className:`h-4 w-4 text-muted-foreground`}),j(`h2`,{className:`text-sm font-semibold`,children:`Offline agents`}),E(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:[l.length,` stale `,l.length===1?`entry`:`entries`]})]}),j(`p`,{className:`px-4 pt-3 text-[11px] text-muted-foreground`,children:`Persisted orchestrator settings for nodes not currently in the live topology. Remove entries you don't expect to come back — leftover from data-dir resets, env-driven nodeId changes, or decommissioned hosts.`}),j(`ul`,{className:`divide-y divide-border`,children:l.map(e=>{let t=Object.keys(e.settings.addonDefaults??{}).length,n=Object.values(e.settings.addonDefaults??{}).filter(e=>e?.enabled).length;return E(`li`,{className:`flex items-center gap-3 px-4 py-2 text-xs`,children:[j(`span`,{className:`font-mono text-foreground`,children:e.nodeId}),E(`span`,{className:`text-muted-foreground`,children:[t,` addons configured`,t>0&&E(O,{children:[` · `,n,` enabled`]})]}),E(`button`,{type:`button`,onClick:()=>{u(e.nodeId)},disabled:s.isPending,className:`ml-auto flex items-center gap-1 px-2 py-1 rounded text-destructive hover:bg-destructive/10 disabled:opacity-50`,children:[j(U,{className:`h-3 w-3`}),`Remove`]})]},e.nodeId)})})]})}T();function Le(e){let[t,n]=A(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return M(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function Re(){let{data:e,isLoading:t}=b(void 0,{staleTime:1/0}),[n,r]=A(null);return s(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&r(t)}),{nodes:D(()=>n??e??[],[n,e]),isLoading:t&&!n}}function ze(){let[e,t]=A(`table`),[n,r]=A(void 0),[i,a]=A(0),o=Le(`(max-width: 767px)`),s=o&&e===`graph`?`table`:e,{nodes:l,isLoading:u}=Re(),d=D(()=>Fe(l),[l]),f=l.filter(e=>e.isOnline).length,p=l.filter(e=>!e.isOnline).length,m=D(()=>l.map(e=>e.id??``).filter(Boolean),[l]),{data:h}=c(),g=D(()=>{if(!h)return 0;let e=new Set(m);return e.add(`hub`),h.filter(t=>!e.has(t.nodeId)).length},[h,m]),_=C(e=>{t(`table`),r(e),a(e=>e+1)},[]),v=(n,r,i,a)=>E(`button`,{onClick:()=>t(n),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${e===n?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[j(i,{className:`h-3.5 w-3.5`}),r,a!==void 0&&a>0&&j(`span`,{className:`ml-1 inline-flex h-4 min-w-[1rem] items-center justify-center rounded-full px-1 text-[10px] font-semibold ${e===n?`bg-primary-foreground/20 text-primary-foreground`:`bg-destructive/15 text-destructive`}`,children:a})]});return E(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[E(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[E(`div`,{className:`flex items-center gap-2`,children:[f>0&&E(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[f,` online`]}),p>0&&E(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[p,` offline`]})]}),E(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[v(`table`,`Table`,ce),!o&&v(`graph`,`Graph`,oe),v(`offline-agents`,`Offline agents`,Z,g)]})]}),u?j(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):s===`graph`?j(je,{graph:d,onOpenNodeDetail:_}):s===`table`?j(`div`,{className:`flex-1 overflow-auto`,children:j(we,{nodes:l,focusNodeId:n,focusNonce:i})}):j(`div`,{className:`flex-1 overflow-auto`,children:j(Ie,{onlineNodeIds:m})})]})}export{ze as ClusterPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{$i as e,$n as t,An as n,B as r,Cn as i,D as a,Da as o,Dn as s,E as c,En as l,G as u,Hr as d,J as f,K as p,Li as m,M as h,N as g,O as _,Oa as v,On as y,Ot as b,R as x,Ri as S,Rr as C,Sn as w,T,Tn as E,U as D,Ui as ee,W as O,Xt as k,Y as A,Yr as te,Yt as ne,_n as j,_r as M,a as N,an as P,dn as re,ea as ie,er as ae,f as oe,fi as se,ft as ce,g as F,gn as le,hn as ue,i as de,ia as fe,j as pe,kn as me,kr as he,l as ge,m as _e,mn as I,n as L,o as ve,p as ye,q as be,qn as xe,qr as Se,r as Ce,ra as we,ri as Te,rn as Ee,sa as De,ta as Oe,tr as ke,u as Ae,ui as je,un as Me,vi as R,vn as Ne,wn as Pe,y as Fe,yi as Ie,yn as Le,z as Re,zi as ze}from"./src-50esl92F.js";import{I as z,K as B,Q as V,S as H,W as U,b as Be,o as W,q as G,t as Ve,x as K,z as q}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{c as He,k as Ue,p as J,r as We,t as Ge,u as Ke}from"./player-overlays-DEDwF8Uo.js";import{C as qe,E as Je,b as Y,g as Ye,v as Xe}from"./src-BnbSKfdg.js";import{t as Ze}from"./CapabilityBadges-BtwEWtSB.js";import{n as Qe,t as $e}from"./rotate-ccw-5_RfArHn.js";import{t as et}from"./ProviderIcon-RCIWUZYh.js";import{t as tt}from"./pencil-DJ_y_Wy8.js";import{t as nt}from"./plus-BgpJnRYz.js";import{t as rt}from"./refresh-cw-9oudg8kg.js";import{t as it}from"./rotate-cw-ClWkf91I.js";import{t as at}from"./server-CQ1LH5PQ.js";import{t as ot}from"./wifi-Ctshxl91.js";import{B as st,F as ct,G as lt,I as ut,O as dt,R as ft,U as pt,V as X,W as mt,_ as ht,a as gt,c as _t,i as vt,k as yt,p as bt,r as xt,s as St,t as Ct,v as wt,x as Tt}from"./index-DvxZ6VPS.js";import{n as Et,t as Dt}from"./useDevice-BGpZXQ7x.js";import{t as Ot}from"./StatusBadge-Dcr2bw58.js";import{t as kt}from"./useEventInvalidation-BTia6ZIb.js";import{n as At,r as jt,t as Mt}from"./SchemaTabBar-Lx0lVN3x.js";import{t as Nt}from"./FormBuilder-B6OIFE8M.js";var Pt=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`}]]),Ft=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`}]]),It=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`}]]),Lt=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`}]]),Rt=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`}]]),zt=X(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),Bt=X(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),Vt=X(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);V();function Ht({parentDeviceId:e}){let{t}=Ct(),n=pt(),r=J(),{data:i,isLoading:a,isError:o}=Et(e),{data:s}=I({deviceId:e},{enabled:Number.isFinite(e)});if(a)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let c=i??[];if(c.length===0)return null;let l=O(s?.stableId??``,c,s?.childLayout),d=l.ungrouped,f=e=>n(`/devices/${String(e)}`),p=s?.name??``,m=e=>{let t=`${p} `;return p.length>0&&e.startsWith(t)?e.slice(t.length):e},h=(e,t)=>K(D,{trpc:r.trpcClient,device:{...t,name:m(t.name)},variant:`minimal`,onNavigate:f},e),g=d.some(e=>!!e.role),_=d.some(e=>!e.role),v=g&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=d.length>0?H(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[K(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),K(`div`,{className:`space-y-1`,children:d.map(e=>h(e.id,e))})]}):null,b=l.disabledSection===void 0?null:K(u,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:l.disabledSection.children.length,defaultOpen:!1,children:K(`div`,{className:`opacity-60 space-y-1`,children:l.disabledSection.children.map(e=>h(e.id,e))})},l.disabledSection.title);return l.sections.length===0?b===null?y:H(`div`,{className:`space-y-2`,children:[y,b]}):H(`div`,{className:`space-y-2`,children:[l.sections.map(e=>K(u,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),y,b]})}function Ut({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return H(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[K(et,{type:n,size:`lg`}),H(`div`,{children:[K(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),K(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),H(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[K(Ot,{status:r?`online`:`offline`}),i.length>0&&K(Ze,{capabilities:i})]}),K(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}function Wt({deviceId:e}){let t=W(),n=ne({deviceId:e},{refetchInterval:1e4,retry:!1}),r=k({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>Gt(n.data??[]),[n.data]);return H(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[H(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[K(Kt,{label:`Discovered`,value:i.total,icon:K(ht,{className:`h-3.5 w-3.5`})}),K(Kt,{label:`Adopted`,value:i.adopted,accent:`success`}),K(Kt,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),H(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[r.isPending?K(Tt,{className:`h-3.5 w-3.5 animate-spin`}):K(rt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),H(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[K(qt,{icon:K(ot,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),K(qt,{icon:K(wt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),K(qt,{icon:K(gt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?K(qt,{icon:K(Pt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function Gt(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 Kt({label:e,value:t,icon:n,accent:r}){return H(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[H(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,K(`span`,{className:`truncate`,children:e})]}),K(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function qt({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,K(`span`,{children:t})]})}function Jt({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:K(S,{trpc:J().trpcClient,deviceId:e,features:t})})}function Yt({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:K(m,{trpc:J().trpcClient,deviceId:e,features:t})})}function Z({deviceId:e,deviceType:t,features:n}){let i=J(),a=A(t)?.HeroCard??m,o=Ke(He(i.trpcClient,e)?.state.deviceStatus),s=o!==void 0&&o.online===!1,c=s?o.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[s?K(`div`,{className:`flex justify-center`,children:K(r,{lastChangedAt:c})}):null,K(a,{trpc:i.trpcClient,deviceId:e,features:n})]})}function Xt({deviceId:e}){let t=J(),{data:n,isLoading:r}=Dt(e),{data:i,isLoading:a}=Et(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?K(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):K(`div`,{className:`flex h-full w-full flex-col`,children:K(Re,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var Zt={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:Wt,[Y.Cover]:Jt,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:Xt,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:Yt,[Y.EventEmitter]:Yt,[Y.Notifier]:Yt,[Y.Script]:Yt,[Y.Automation]:Yt,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z};function Qt(e){return K(Zt[e.deviceType]??Ut,{...e})}function $t(e){return N(J().trpcClient,e)}V();function en(e){let[n,r]=G(`idle`),[i,a]=G(null),o=B(null),s=B(null),c=B(null),l=B(!0),u=ae(),d=t(),f=ke(),p=z(()=>{if(o.current){try{o.current.close()}catch{}o.current=null}if(s.current){for(let e of s.current.getTracks())try{e.stop()}catch{}s.current=null}c.current=null},[]),m=z(async()=>{if(n===`idle`)return;r(`stopping`);let t=c.current;if(t&&e!==null)try{await Promise.race([f.mutateAsync({deviceId:e,sessionId:t}),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&&(r(`idle`),a(null))},[n,e,f,p]),h=z(async()=>{if(e===null||n!==`idle`&&n!==`error`)return;a(null);let t=null,i=null,p=null;try{r(`requesting-mic`),t=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),s.current=t,r(`starting`);let n=await u.mutateAsync({deviceId:e});p=n.sessionId,c.current=p,r(`connecting`),i=new RTCPeerConnection,o.current=i,i.oniceconnectionstatechange=()=>{if(!l.current)return;let e=i.iceConnectionState;e===`connected`||e===`completed`?r(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&l.current&&(a(e===`failed`?`WebRTC connection failed`:null),m())};for(let e of t.getAudioTracks())i.addTrack(e,t);await i.setRemoteDescription({type:`offer`,sdp:n.sdpOffer});let f=await i.createAnswer();await i.setLocalDescription(f);let h=i.localDescription?.sdp??f.sdp??``;await d.mutateAsync({deviceId:e,sessionId:p,sdpAnswer:h})}catch(n){let u=n instanceof Error?n.message:String(n);if(console.warn(`[intercom] start failed`,n),i)try{i.close()}catch{}if(t)for(let e of t.getTracks())try{e.stop()}catch{}if(o.current=null,s.current=null,p!==null)try{await f.mutateAsync({deviceId:e,sessionId:p})}catch{}c.current=null,l.current&&(a(u),r(`error`))}},[e,n,u,d,f,m]);return q(()=>(l.current=!0,()=>{l.current=!1;let t=c.current;if(t!==null&&e!==null&&f.mutate({deviceId:e,sessionId:t}),o.current){try{o.current.close()}catch{}o.current=null}if(s.current){for(let e of s.current.getTracks())try{e.stop()}catch{}s.current=null}c.current=null}),[e]),{state:n,error:i,start:h,stop:m,isTalking:n===`talking`}}V();var tn=0;function Q(){return++tn}function nn(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function rn(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 an(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 on(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 sn({scope:e,greeting:t,className:n}){let r=J(),[i,a]=G(()=>{let n=[];return t&&n.push({id:Q(),kind:`info`,text:t}),n.push({id:Q(),kind:`info`,text:`scope: ${nn(e)} — type help or context for available commands`}),n}),[o,s]=G(``),[c,l]=G([]),[u,d]=G(-1),f=B(null),p=B(null);q(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=z(()=>{f.current?.focus()},[]),h=Ve({mutationFn:t=>r.trpcClient.repl.execute.mutate({code:t,scope:e}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;a(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Q(),kind:`info`,text:`scope: ${nn(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...rn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...on(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...an(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Q(),kind:`input`,text:`> ${n}`}]),s(``),h.mutate(n)}}function _(t){if(t.key===`Enter`){t.preventDefault(),g(o);return}if(t.key===`ArrowUp`){if(t.preventDefault(),c.length===0)return;let e=u===-1?c.length-1:Math.max(0,u-1);d(e),s(c[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),u===-1)return;let e=u+1;e>=c.length?(d(-1),s(``)):(d(e),s(c[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),a([{id:Q(),kind:`info`,text:`scope: ${nn(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return H(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[H(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>K(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&K(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),H(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[K(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),K(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function cn({deviceId:e,intercomAvailable:t=!1}){let n=J(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=$t(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=de(n.trpcClient,i?e:null),g=be(n.trpcClient,i?e:null),v=en(i&&t?e:null),y=v.state===`requesting-mic`||v.state===`starting`||v.state===`connecting`||v.state===`stopping`,b=v.isTalking||y,x=()=>{v.state===`idle`||v.state===`error`?v.start():v.state!==`stopping`&&v.stop()},S=We(),C=_(),w=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,T=S.length>0?K(Be,{children:S.map(e=>K(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return K(Fe,{serverUrl:r,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h,...C.request?{playbackUrl:C.request.url,playbackAuthToken:w,...C.request.label?{playbackLabel:C.request.label}:{},onExitPlayback:()=>C.clear()}:{},streams:o,pipelineMetrics:s,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:g.src,...g.src?{posterUrl:g.src}:{},snapshotLoading:g.loading,onRefreshSnapshot:g.refresh,intercomAvailable:t,intercomShown:b,onIntercomToggle:x,extraOverlay:T,chromeless:!0,className:`h-full`})}function ln({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full`,children:K(F,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function un({deviceId:e}){if(!Number.isFinite(e))return H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
2
|
-
`);return K(sn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function dn({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(_e,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function fn({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(oe,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function pn({deviceId:e}){let t=W(),n=Number.isFinite(e),{data:r}=I({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;kt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:c}=re({deviceId:e},{enabled:n}),{data:l}=Ne({deviceType:i},{enabled:!!i}),u=y({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return K(`div`,{className:`p-4`,children:K(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(s)return H(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,c instanceof Error?c.message:String(c)]});let d=new Map,f={};for(let e of l??[])f[e.capName]=e.wrappers;for(let e of a?.entries??[])d.set(e.capName,{...e,wrappers:f[e.capName]??[]});for(let e of l??[])d.has(e.capName)||d.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let p=[...d.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(p.length===0)return H(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[K(Qe,{className:`h-8 w-8 opacity-40`}),K(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),K(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let m=p.filter(e=>e.kind!==`unbound`).length;return H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`text-[11px] text-foreground-subtle`,children:[K(`span`,{className:`font-medium text-foreground`,children:m}),` of `,p.length,` capabilit`,p.length===1?`y`:`ies`,` bound — rows marked `,K(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),K(we,{columns:[{key:`capability`,header:`Capability`,render:e=>K(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>K(mn,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?K(hn,{nodeId:e.providerNodeId}):K(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return K(gn,{wrappers:t.wrappers,activeWrapperId:n,disabled:u.isPending,onPick:r=>{let i=n===r;u.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:p,rowKey:e=>e.capName,minWidthPx:720})]})}function mn({kind:e}){return e===`native`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[K(at,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[K(Ft,{className:`h-3 w-3`}),`wrapped`]}):H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[K(zt,{className:`h-3 w-3`}),`unbound`]})}function hn({nodeId:e}){return K(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function gn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?K(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):K(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return H(`button`,{disabled:n,onClick:()=>r(e),title:i?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[K(i?ct:$e,{className:`h-3 w-3`}),e]},e)})})}V();function _n({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l,flattenTabs:u=!1}){let d=e.tabs??[],f=U(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),p=new Set(d.map(e=>e.id)),m=[...d,...[...f.keys()].filter(e=>!p.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],h=m[0]?.id??`general`,[g,_]=G(h),v=l!==void 0,y=new Set(m.map(e=>e.id)),b=v?c&&y.has(c)?c:h:y.has(g)?g:h,x=e=>{v?l(e):_(e)},S=f.get(b)??[],C={sections:S.length<=1?S.length===1?[{...S[0],title:``}]:S:S.every(e=>!e.title)?[{...S[0],title:``,fields:S.flatMap(e=>e.fields)}]:S},w=K(At,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(u||m.length<=1)return H(`div`,{className:`flex flex-col gap-3`,children:[K(Nt,{schema:e,values:t,onChange:r,onAction:i,disabled:s}),w]});let T=new Map,E=new Map;for(let[e,t]of f){T.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&&E.set(e,a)}return H(`div`,{className:`flex flex-col gap-3`,children:[K(Mt,{tabs:m.map(e=>({id:e.id,label:e.label})),activeId:b,onChange:x,countByTab:T,pendingByTab:E}),K(Nt,{schema:C,values:t,onChange:r,onAction:i,disabled:s}),w]})}var vn=`device-export`,yn=`export`,bn=`Export`;function xn(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(xn):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(xn)):e.writerCapName===vn}function Sn(e){return e.fields.some(xn)}V();function Cn(e,t){return t&&t===`admin`?e:!0}function wn(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?Sn(e)&&Sn(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function Tn(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 En(e){return e.key}function Dn(e){if(!Tn(e))return e.value}function On(e){return Tn(e)?null:e}function kn(e,t){for(let n of e)if(t(n),n.type===`group`)kn(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)kn(e.fields,t)}function An(e){if(!e)return{};let t={};for(let n of e.sections)kn(n.fields,e=>{let n=En(e);n!==null&&(t[n]=Dn(e))});return t}function jn(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(kn(r.fields,e=>{if(n!==null||En(e)!==t)return;let r=On(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function Mn(e){return{...e,fields:e.fields.map(Nn)}}function Nn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function Pn(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=On(e);return n?Cn(t,n.minRole)?e:Nn(e):e})}))}}function Fn({deviceId:e,sectionFilter:t,activeSubTab:r,onSubTabChange:a,flattenSubTabs:o}){let s=W(),{user:c}=xt(),l=c?.isAdmin===!0,u=B(!1),{data:d,isLoading:f}=ue({deviceId:e},{refetchInterval:()=>u.current?!1:2500,enabled:Number.isFinite(e)}),{data:p}=I({deviceId:e},{enabled:Number.isFinite(e)}),m=d?.settings??null,h=d?.live??null,g=U(()=>{if(!m&&!h)return null;let e=m?.sections??[],n=(h?.sections??[]).map(Mn),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!Sn(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...m?.tabs??[],...(h?.tabs??[]).filter(e=>!(m?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[m,h,t]),_=U(()=>wn(g),[g]),v=U(()=>Pn(_,l),[_,l]),y=U(()=>An(v),[v]),b=Ie(),x=R(),S=me(),C=i(),w=n({onSuccess:()=>{s.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),T={isPending:w.isPending,mutate:t=>{w.mutate({deviceId:e,changes:[...t]})}},E=jt({schema:v,serverValues:y,onImmediateSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=jn(v,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&T.mutate(t)},[v,T]),onDeferredSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=jn(v,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&T.mutate(t)},[v,T])}),{values:D,pendingKeys:ee,handleChange:O,handleSave:k,handleDiscard:A}=E;if(u.current=E.editingPaused,f)return H(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[K(Tt,{className:`h-4 w-4 animate-spin mr-2`}),K(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!v||v.sections.length===0)return K(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function te(t,n,r){if(t===`regenerate-rtsp-token`){let t=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!t)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(t.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let i=qe(e,r);await b.mutateAsync({brokerId:i}),s.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!p)return{status:`error`,error:`Device metadata not loaded yet`};try{return await S.mutateAsync({addonId:p.addonId,type:p.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=qe(e,t),i=await x.mutateAsync({brokerId:r});return s.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await C.mutateAsync({deviceId:e,action:n,input:r});return s.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return K(_n,{schema:v,values:D,pendingKeys:ee,onChange:O,onAction:te,onSave:k,onDiscard:A,disabled:T.isPending,activeSubTab:r,onSubTabChange:a,flattenTabs:o})}function In({deviceId:e,activeSubTab:t,onSubTabChange:n}){return K(`div`,{className:`flex flex-col gap-3`,children:K(Fn,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}V();function Ln(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 Rn(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 zn({agents:e,currentAgent:t,onPick:n}){let[r,i]=G(!1);return H(`div`,{className:`relative`,children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>i(e=>!e),children:`Mirror from ▾`}),r&&K(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:e.filter(e=>e!==t).map(e=>K(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{i(!1),n(e)},children:e},e))})]})}function Bn({deviceId:t,refreshToken:n}){let r=W(),[i,a]=G(null),[o,s]=G(null),[c,l]=G(null),[u,f]=G(null),p=d({deviceId:t}),m=te(),h=Se({deviceId:t}),g=C(),_=U(()=>h.data?.agentNodeId||g.data?.find(e=>e.online)?.nodeId||`hub`,[h.data?.agentNodeId,g.data]),y=o??_,b=he({nodeId:y??``},{enabled:!!y}),x=Te({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),l(null)}}),S=U(()=>b.data?Oe(b.data):[],[b.data]),w=U(()=>{let e=p.data??null,t={};for(let n of m.data??[])for(let r of Object.keys(n.settings.addonDefaults)){let i=t[r]??[];i.push({agentNodeId:n.nodeId,state:Rn(e,n.nodeId,r)}),t[r]=i}return t},[p.data,m.data]),T=i?Ln(b.data??null,i):null,E=y?m.data?.find(e=>e.nodeId===y)??null:null,D=i&&E?E.settings.addonDefaults[i]??null:null,ee=i&&y?p.data?.stepOverridesByAgent?.[y]?.[i]??null:null,O=b.data?.selectedEngine.format??`coreml`,k=e=>{s(e),l(null),f(null)};return m.isLoading||b.isLoading?K(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):b.data?K(`div`,{className:`@container h-full`,style:{containerType:`inline-size`},children:H(`div`,{className:`flex flex-col @[720px]:flex-row h-full`,children:[K(`aside`,{className:`w-full @[720px]:w-[300px] @[720px]:flex-shrink-0 border-b @[720px]:border-b-0 @[720px]:border-r border-border overflow-y-auto max-h-[40vh] @[720px]:max-h-none`,children:K(ie,{tree:S,selectedAddonId:i,onSelect:e=>{a(e),l(null),f(null)},agentDots:w})}),K(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!i||!T?K(`div`,{className:`text-sm text-foreground-subtle`,children:`Select a step on the left to configure it for this camera.`}):H(`div`,{className:`space-y-4`,children:[H(`div`,{children:[K(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle`,children:`Selected step`}),K(`div`,{className:`text-base font-semibold`,children:T.name})]}),H(`div`,{className:`flex items-end gap-3 flex-wrap`,children:[H(`div`,{children:[K(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle mb-1`,children:`Agent`}),K(`div`,{className:`flex rounded border border-border overflow-hidden`,children:(m.data??[]).map(e=>K(`button`,{type:`button`,onClick:()=>k(e.nodeId),className:`px-3 py-1 text-xs ${y===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),K(zn,{agents:(m.data??[]).map(e=>e.nodeId),currentAgent:y,onPick:e=>{if(!y||!i||!b.data||!m.data)return;let t=m.data.find(t=>t.nodeId===e),n=m.data.find(e=>e.nodeId===y);if(!t||!n)return;let[r]=v({source:{nodeId:t.nodeId,engine:{format:O},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:O},defaults:n.settings.addonDefaults},catalog:b.data,addonIds:[i]});if(!r){f(`no mirror result`);return}if(r.outcome===`skip`){f(`skipped: ${r.reason??`no candidate`}`);return}l(r.patch),f(`${r.outcome} from ${e}`)}}),u&&K(`div`,{className:`text-[10px] text-foreground-subtle`,children:u})]}),D&&K(e,{mode:`device`,addon:T,agentDefault:D,agentNodeId:y??``,currentPatch:c??ee,engineFormat:O,onChangePatch:l}),H(`div`,{className:`flex items-center justify-between gap-2 pt-4 border-t border-border`,children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle`,disabled:!ee||x.isPending,onClick:()=>{!y||!i||x.mutate({deviceId:t,agentNodeId:y,addonId:i,patch:null})},children:`Clear override`}),H(`div`,{className:`flex items-center gap-2`,children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>l(null),children:`Reset draft`}),K(`button`,{type:`button`,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,disabled:!y||!i||x.isPending,onClick:()=>{!y||!i||x.mutate({deviceId:t,agentNodeId:y,addonId:i,patch:c})},children:x.isPending?`Saving…`:`Save`})]})]})]})})]})}):K(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`})}function $({label:e,value:t}){return H(`div`,{className:`${Ue} flex items-start gap-2 sm:gap-3`,children:[K(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),K(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}V();function Vn({deviceId:e,initialName:t}){let n=W(),[r,i]=G(!1),[a,o]=G(t),[s,c]=G(!1),u=B(null);q(()=>{r||o(t)},[t,r]),q(()=>{r&&u.current?.focus()},[r]);let d=l({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),f=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),o(t);return}c(!0);try{await d.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{c(!1)}},p=()=>{o(t),i(!1)};return r?K($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-1`,children:[K(`input`,{ref:u,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?f():e.key===`Escape`&&p()},disabled:s,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),K(`button`,{type:`button`,onClick:()=>void f(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:K(ct,{className:`h-3 w-3`})}),K(`button`,{type:`button`,onClick:p,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:K(vt,{className:`h-3 w-3`})})]})}):K($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[K(`span`,{className:`truncate`,children:t}),K(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit name`,children:K(tt,{className:`h-3 w-3 text-foreground-subtle`})})]})})}V();function Hn({deviceId:e,initialLocation:t}){let n=W(),[r,i]=G(!1),[a,o]=G(t??``),[s,c]=G(!1),l=B(null),{data:u}=Le(void 0,{enabled:r}),d=u??[];q(()=>{r||o(t??``)},[t,r]),q(()=>{r&&l.current?.focus()},[r]);let f=E({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),p=U(()=>{let e=a.trim().toLowerCase();return e.length===0?d:d.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[d,a]),m=a.trim().length>0&&!d.some(e=>e.toLowerCase()===a.trim().toLowerCase()),h=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await f.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},g=()=>{o(t??``),i(!1)};return r?K($,{label:`Location`,value:H(`div`,{className:`relative`,children:[H(`div`,{className:`flex items-center gap-1`,children:[K(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?h():e.key===`Escape`&&g()},disabled:s,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),K(`button`,{type:`button`,onClick:()=>void h(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:K(ct,{className:`h-3 w-3`})}),K(`button`,{type:`button`,onClick:g,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:K(vt,{className:`h-3 w-3`})})]}),(p.length>0||m)&&H(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[p.map(e=>H(`button`,{type:`button`,onClick:()=>{o(e),h(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[K(Rt,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),K(`span`,{className:`truncate`,children:e})]},e)),m&&H(`button`,{type:`button`,onClick:()=>void h(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[K(`span`,{className:`text-foreground-subtle`,children:`Create`}),H(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):K($,{label:`Location`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[t?K(`span`,{className:`truncate`,children:t}):K(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),K(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit location`,children:K(tt,{className:`h-3 w-3 text-foreground-subtle`})})]})})}V();function Un({deviceId:e}){let t=W(),{data:n}=Dt(e),{data:r}=Et(e),[i,a]=G(null),o=s({onSuccess:()=>{a(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{a(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.Container)return null;let c=(r??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(c.length<=1)return null;let l=ze(c,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return H(Be,{children:[K($,{label:`Primary child`,value:K(x,{childrenList:c,selectedId:l===null?c[0].id:l.id,onSetPrimary:t=>o.mutate({deviceId:e,primaryChildEntityId:t}),disabled:o.isPending})}),i!==null&&K(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:i})]})}V();var Wn=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Gn(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Kn(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function qn(){let e=h(),t=g(),{data:n}=I({deviceId:e??0},{enabled:e!==null}),{data:r}=re({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[a,o]=G(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),c=String(i.name??``),l=String(i.type??``),u=String(i.addonId??``),d=i.features??[],f=new Set([`device-status`,`feature-probe`,`device-ops`]),p=(r?.entries??[]).filter(e=>e.kind===`native`&&!f.has(e.capName)).map(e=>e.capName),m=d.length>0?d:p,_=i.location??null,v=i.metadata??null,y=v!==null&&Object.keys(v).length>0;return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[H(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[K(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),y&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[K(Jn,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),K(Jn,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!y||a===`identity`)&&H(`div`,{className:`divide-y divide-border`,children:[K($,{label:`ID`,value:H(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,H(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,s,`)`]})]})}),K(Vn,{deviceId:e,initialName:c}),K(Hn,{deviceId:e,initialLocation:_}),K(Un,{deviceId:e}),K($,{label:`Type`,value:l}),K($,{label:`Provider`,value:K(et,{type:u,size:`sm`,showLabel:!0})}),K($,{label:`Capabilities`,value:m.length>0?K(Ze,{capabilities:m,showLabels:!0}):K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),y&&a===`hardware`&&K(Yn,{metadata:v})]})}function Jn({active:e,onClick:t,label:n}){return K(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function Yn({metadata:e}){let t=Wn.filter(t=>t in e),n=Object.keys(e).filter(e=>!Wn.includes(e)).toSorted(),r=[...t,...n];return H(`div`,{children:[K(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),K(`div`,{className:`divide-y divide-border`,children:r.map(t=>K($,{label:Gn(t),value:K(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Kn(e[t])})},t))})]})}V();function Xn({deviceId:e}){let[t,n]=G(null),r=Ee({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return H(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[H(`div`,{className:`flex items-center justify-between gap-3`,children:[H(`div`,{children:[K(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),K(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),H(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[K(rt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&K(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function Zn(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Qn({device:e}){let t=pt(),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(Xe.Resyncable),{data:c}=M({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),l=c?.streams??{},u=Object.entries(l),d=o.includes(Xe.DoorbellButton),f=Ce(d?{deviceId:n??void 0,historyLimit:10}:void 0),p=f.latest?Date.now()-f.latest.timestamp<3e4:!1;return H(`div`,{className:`space-y-5`,children:[a&&n!==null&&K(ye,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),s&&n!==null&&K(Xn,{deviceId:n}),i&&n!==null&&K(T,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),d&&K(Ae,{history:f.history,latestIsFresh:p}),i&&n!==null&&K(T,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&u.length>0&&H(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[K(`div`,{className:`border-b border-border px-4 py-2`,children:K(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),K(`div`,{className:`divide-y divide-border`,children:u.map(([e,t])=>H(`div`,{className:`px-4 py-2.5`,children:[H(`div`,{className:`flex items-center gap-2 mb-2`,children:[K(ot,{className:`h-3 w-3 text-foreground-subtle`}),K(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),H(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[K($n,{label:`Nominal`,value:Zn(t.nominalBitrateKbps??0)}),K($n,{label:`Observed`,value:Zn(t.observedBitrateKbps??0)}),K($n,{label:`Peak`,value:Zn(t.peakBitrateKbps??0)}),K($n,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),K(qn,{})]})}function $n({label:e,value:t,warning:n}){return H(`div`,{children:[K(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),K(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}V();function er(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function tr(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=er(r.value,t));return n}function nr(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 rr(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 ir(e){return e==null?`identity`:e.kind}function ar({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=G(()=>ir(e)),[o,s]=G(()=>nr(e,n)),[c,l]=G(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=G(()=>rr(e));q(()=>{if(i===`enum-map`&&n?.kind===`enum`&&n.enumValues){let e=n.enumValues;s(t=>e.map(e=>({key:e,value:t.find(t=>t.key===e)?.value??``})))}},[n,i]),q(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=tr(o,r),n=c===``?void 0:er(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(nr(void 0,n)),e===`linear`&&d(rr(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{children:[K(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),K(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[K(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[K(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>H(`div`,{className:`flex items-center gap-1.5`,children:[K(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),K(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?H(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[K(`option`,{value:``,children:`—`}),K(`option`,{value:`true`,children:`true`}),K(`option`,{value:`false`,children:`false`})]}):K(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&K(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&K(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),H(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[K(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),K(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[K(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),K(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),K(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[K(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),K(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),K(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),K(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}V();function or(e,t){return`${e.replace(/[^a-z0-9]/gi,`-`)}-${t.replace(/[^a-z0-9]/gi,`-`)}`}function sr(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function cr({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=j({}),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}=le({deviceId:e}),d=u?.caps??[],f=r==null?null:sr(r.source.sourceKey,c,s),[p,m]=G(r?.target.cap??``),[h,g]=G(r?.target.fieldPath??``),[_,v]=G(f),[y,b]=G(r?.source.cap??``),[x,S]=G(r?.source.fieldPath??``),[C,w]=G(r?.transform);q(()=>{if(r!=null&&_===null&&s.length>0){let e=sr(r.source.sourceKey,c,s);e!==null&&v(e)}},[r,_,s,c]);let{data:T}=le({deviceId:_??0},{enabled:_!=null}),E=T?.caps??[],D=d.find(e=>e.cap===p)?.fields??[],ee=D.find(e=>e.path===h),O=E.find(e=>e.cap===y)?.fields??[],k=O.find(e=>e.path===x),A=e=>{m(e),g(``)},te=e=>{v(e===``?null:Number(e)),b(``),S(``)},ne=e=>{b(e),S(``)},M=p!==``&&h!==``&&_!=null&&y!==``&&x!==``,N=()=>{if(!M)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??or(p,h),source:{sourceKey:n,cap:y,fieldPath:x},target:{cap:p,fieldPath:h},...C==null?{}:{transform:C}})},P=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return H(`div`,{className:`flex flex-col gap-4 p-3`,children:[H(`fieldset`,{className:`flex flex-col gap-3`,children:[K(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),H(`div`,{children:[K(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),H(`select`,{id:`link-target-cap`,value:p,onChange:e=>A(e.target.value),className:P,children:[K(`option`,{value:``,children:`— select a cap —`}),d.map(e=>K(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),H(`select`,{id:`link-target-field`,value:h,disabled:p===``,onChange:e=>g(e.target.value),className:P,children:[K(`option`,{value:``,children:`— select a field —`}),D.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),H(`fieldset`,{className:`flex flex-col gap-3`,children:[K(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source (sibling device)`}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source device`}),H(`select`,{id:`link-source-device`,value:_??``,onChange:e=>te(e.target.value),className:P,children:[K(`option`,{value:``,children:`— select a device —`}),l.map(e=>H(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source cap`}),H(`select`,{id:`link-source-cap`,value:y,disabled:_==null,onChange:e=>ne(e.target.value),className:P,children:[K(`option`,{value:``,children:`— select a cap —`}),E.map(e=>K(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source field`}),H(`select`,{id:`link-source-field`,value:x,disabled:y===``,onChange:e=>S(e.target.value),className:P,children:[K(`option`,{value:``,children:`— select a field —`}),O.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),K(ar,{value:C,onChange:w,sourceField:k,targetKind:ee?.kind}),H(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[K(`button`,{type:`button`,onClick:a,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),K(`button`,{type:`button`,disabled:!M,onClick:N,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`})]})]})}V();function lr({deviceId:e}){let t=J(),n=W(),{data:r,isLoading:i}=I({deviceId:e},{enabled:Number.isFinite(e),refetchInterval:1e4}),a=Pe({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]=G(null),d=t=>{a.mutate({deviceId:e,deviceLinks:o.filter(e=>e.id!==t)})};return i?K(`div`,{className:`p-4`,children:K(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):l===null?H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`flex items-center justify-between`,children:[K(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),H(`button`,{type:`button`,onClick:()=>u(`new`),title:`Add a cross-device link`,className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[K(nt,{className:`h-3 w-3`}),`Add link`]})]}),o.length===0?H(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[K(It,{className:`h-8 w-8 opacity-30`}),K(`p`,{className:`text-xs`,children:`No links yet.`}),K(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):K(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:o.map(n=>K(ur,{deviceId:e,link:n,trpcClient:t.trpcClient,onDelete:()=>d(n.id),onEdit:()=>u(n),isPending:a.isPending},n.id))})]}):H(`div`,{className:`flex flex-col gap-3 p-1`,children:[K(`div`,{className:`flex items-center justify-between`,children:K(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:l===`new`?`Add link`:`Edit link`})}),K(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:K(cr,{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 ur({deviceId:e,link:t,trpcClient:n,onDelete:r,onEdit:i,isPending:a}){let o=L(n,e,t.target.cap),s=o===void 0?void 0:Ye(o,t.target.fieldPath),c=s==null?`—`:String(s);return H(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[K(Lt,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),H(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[H(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[K(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),K(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),K(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath})]}),H(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[K(`span`,{children:`←`}),K(`span`,{className:`font-mono`,children:t.source.sourceKey}),K(`span`,{className:`opacity-60`,children:`/`}),K(`span`,{className:`font-mono`,children:t.source.cap}),K(`span`,{className:`opacity-60`,children:`.`}),K(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]}),t.transform&&K(dr,{kind:t.transform.kind}),K(`span`,{className:`font-mono text-[11px] tabular-nums min-w-[2.5rem] text-right text-foreground-subtle`,title:`Live resolved value (from this device's runtime-state slice)`,children:c}),K(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:a,onClick:i,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:`Edit`}),K(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:a,onClick:r,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-danger hover:border-danger/50 hover:bg-danger/5 transition-colors disabled:opacity-50`,children:`Delete`})]})}function dr({kind:e}){return K(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}V();var fr=[{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 pr(e){let t=e===Y.Camera;return fr.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var mr=[{id:`logs`,icon:bt,label:`Logs`},{id:`repl`,icon:_t,label:`REPL`},{id:`events`,icon:ft,label:`Events`},{id:`state`,icon:dt,label:`State`}];function hr(){let e=mt(),t=Number(e.deviceId),n=Number.isFinite(t),r=pt(),i=W(),o=ee(),s=J(),[l,u]=lt(),d=l.get(`tab`)??`overview`,m=l.get(`sub`),[h,g]=G(`logs`),_=`device-detail.left-col-width-px`,[v,y]=G(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(_),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),x=B(v);x.current=v;function S(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??v??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{y(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=x.current;if(e!==null)try{window.localStorage.setItem(_,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:C,isLoading:T,isError:E}=I({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:D}=ue({deviceId:t},{enabled:n}),O=U(()=>{let e=D?.settings?.sections??[],t=D?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(Sn)&&r.add(yn),[...r].map(e=>e===`export`?{id:e,label:bn,isAddonContrib:!0}:{id:e,label:Je[e]?.label??e,isAddonContrib:!0})},[D]),k=C,A=String(k?.name??e.deviceId??`Device`),te=k?.online===!0,ne=te?`online`:`offline`,j=String(k?.addonId??`rtsp`),M=k?.features??[],N=k?.type,re=N===Y.Camera,{data:ie}=Et(n?t:0),ae=N===Y.Container,oe=U(()=>(ie??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ie]),F=U(()=>ae?ze(oe,typeof k?.linkDeviceId==`number`?k.linkDeviceId:null,typeof k?.primaryChildEntityId==`string`?k.primaryChildEntityId:null)?.id??null:null,[ae,oe,k?.linkDeviceId,k?.primaryChildEntityId]),{data:de}=ue({deviceId:F??0},{enabled:F!==null}),me=U(()=>{if(F===null)return[];let e=de?.settings?.sections??[],t=de?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:Je[e]?.label??e,isAddonContrib:!0,childDeviceId:F}))},[F,de]),he=typeof k?.parentDeviceId==`number`?k.parentDeviceId:null,{data:_e}=I({deviceId:he??0},{enabled:he!==null}),L=De(),ye=k?.disabled!==!0,{data:be}=le({deviceId:t},{enabled:n}),Ce=(be?.caps.length??0)>0,we=U(()=>{let e=new Set,t=[];for(let n of[...pr(N),...O,...me])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!Ce)&&t.push(n));return t},[N,O,me,Ce]),Te=U(()=>we.some(e=>e.id===d)?d:`overview`,[we,d]),Ee=z(e=>{u(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[u]),Oe=z(e=>{u(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[u]),ke=(ie??[]).length>0,Ae=U(()=>mr.filter(({featureGate:e})=>!e||M.includes(e)),[M]),{data:R}=xe({addonId:j},{enabled:!!j&&j!==`rtsp`}),Ne=w({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]}),r(R?.id?`/integrations/${R.id}`:`/integrations`)}}),Pe=Me({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=P({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=se(),Le=ce({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=M.includes(Xe.Rebootable),V=M.includes(Xe.BatteryOperated),Be=f(s.trpcClient,V&&n?t:null),[Ve,q]=G(!1),Ue=He(s.trpcClient,n?t:null),We=async()=>{if(!(Ve||!Ue)){q(!0);try{await Ue.snapshot?.invalidateCache({});let e=await Ue.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=A.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{q(!1)}}},Ke=Pe.isPending||Fe.isPending,{data:qe}=Se({deviceId:t},{enabled:n,refetchInterval:1e4}),Ye=qe?.agentNodeId??null,Qe=typeof Ye==`string`&&Ye.length>0&&!Ye.startsWith(`addon:`)?Ye:void 0,{data:$e}=je({deviceId:t,...Qe?{nodeId:Qe}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:tt}=b({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),nt=tt?.level?.dbfs??null;function at(){if(!n)return null;switch(Te){case`overview`:return K(Qn,{device:k??{}});case`config`:return K(In,{deviceId:t,activeSubTab:m,onSubTabChange:Oe});case`pipeline`:return K(Bn,{deviceId:t,refreshToken:0});case`bindings`:return K(pn,{deviceId:t});case`wiring`:return K(lr,{deviceId:t});default:{let e=Te,n=O.some(t=>t.id===e),r=me.find(t=>t.id===e);if(!n&&r===void 0)return null;let i=r?.childDeviceId??t;if(e===`export`)return K(Fn,{deviceId:t,sectionFilter:Sn,activeSubTab:m,onSubTabChange:Oe});let a=K(Fn,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:m,onSubTabChange:Oe});return r!==void 0&&i!==t?K(pe,{deviceId:i,children:a}):a}}}return n?T?H(`div`,{className:`flex flex-col h-full`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[K(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),K(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),K(`div`,{className:`flex-1 p-6`,children:K(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):E||!C?H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),H(`p`,{className:`text-xs`,children:[`No device with ID`,` `,H(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,t]})]}),K(`button`,{onClick:()=>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`})]}):H(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[K(`div`,{className:`mb-2`,children:K(fe,{items:[{label:`Integrations`,onClick:()=>r(`/integrations`)},{label:R?.name??j,onClick:()=>R?.id&&r(`/integrations/${R.id}`)},{label:A}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[K(et,{type:j,size:`lg`}),H(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[K(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:A}),K(Ot,{status:ne}),V&&K(p,{status:Be,variant:`full`})]}),he!==null&&_e&&H(`button`,{type:`button`,onClick:()=>r(`/devices/${he}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${_e.name}`,children:[K(`span`,{children:`↑`}),K(`span`,{className:`truncate`,children:String(_e.name??`Device #${he}`)})]}),K(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:M.length>0&&K(Ze,{capabilities:M})})]}),$e&&K(`div`,{className:`hidden lg:flex`,children:K(gr,{metrics:$e,dbfs:nt})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{ye?await o({title:`Disable "${A}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Fe.mutate({deviceId:t}):Pe.mutate({deviceId:t})},disabled:Ke,title:ye?`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 ${ye?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[K(Bt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:Ke?`Updating…`:ye?`Enabled`:`Disabled`})]}),K(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),K(ge,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:ut,disabled:Ve,onClick:()=>{We()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:it,hidden:!Re,disabled:Ie.isPending,danger:!0,onClick:async()=>{await o({title:`Reboot "${A}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Ie.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??j}.`,icon:rt,disabled:Le.isPending,danger:!0,onClick:async()=>{await o({title:`Restart "${R?.name??j}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${A}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Le.mutate({addonId:j})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:St,separatorBefore:!0,disabled:Ne.isPending,danger:!0,onClick:async()=>{await o({title:`Delete "${A}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ne.mutate({deviceId:t})}}]})]})]})]}),K(pe,{deviceId:t,device:k??void 0,children:K(a,{children:K(c,{children:K(Ge,{children:K(ve,{children:H(`main`,{className:L?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[H(`div`,{className:L?`flex flex-col bg-surface`:`${v===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!L&&v!==null?{width:`${String(v)}px`}:void 0,children:[K(`div`,{className:re?`flex-shrink-0 border-b border-border-subtle bg-black`:L?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:re?K(cn,{deviceId:t,intercomAvailable:M.includes(Xe.TwoWayAudio)}):K(Qt,{deviceId:t,deviceName:A,deviceType:N??`unknown`,provider:j,isOnline:te,features:M})}),H(`div`,{className:L?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[K(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:K(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Ae.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>g(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${h===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[K(n,{className:`h-3 w-3`}),t]},e))})}),H(`div`,{className:L?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[h===`logs`&&K(ln,{deviceId:t,containerDeviceId:N===`container`?t:void 0}),h===`repl`&&K(un,{deviceId:t}),h===`events`&&K(dn,{deviceId:t}),h===`state`&&K(fn,{deviceId:t})]})]})]}),!L&&K(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:S,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:K(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),H(`div`,{className:L?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[K(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:K(`div`,{className:`flex flex-wrap items-center gap-0`,children:we.map(e=>{let t=Te===e.id;return H(`button`,{onClick:()=>Ee(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&K(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),H(`div`,{className:L?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[Te===`overview`&&ke&&K(Ht,{parentDeviceId:t}),at()]})]})]})})})})})})]}):H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),H(`p`,{className:`text-xs`,children:[`The URL segment`,` `,K(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),K(`button`,{onClick:()=>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 gr({metrics:e,dbfs:t}){let n=o(e.phase??`idle`);return H(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[H(`div`,{className:`flex items-center gap-1.5`,children:[K(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),K(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),K(`div`,{className:`h-3 w-px bg-border`}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(st,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),K(`span`,{children:`fps`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(yt,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),K(`span`,{children:`ms`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[K(Vt,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),K(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&H(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{hr as DeviceDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$t as e,Bi as t,Gn as n,H as r,Jn as i,Kn as a,Qn as o,Sn as s,V as c,Vi as l,Wn as u,Xn as d,Z as f,_n as p,an as m,bn as h,d as g,en as _,ft as v,g as y,ia as b,in as ee,kn as x,ln as S,nn as C,pn as w,tn as te,un as ne,va as T,x as E}from"./src-50esl92F.js";import{I as D,K as re,Q as O,S as k,W as A,b as j,o as M,q as N,x as P,z as ie}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as F}from"./player-overlays-DEDwF8Uo.js";import{b as I}from"./src-BnbSKfdg.js";import{t as L}from"./ProviderIcon-RCIWUZYh.js";import{t as R}from"./plus-BgpJnRYz.js";import{n as z,r as B,t as ae}from"./ScanNetworkModal-CVTAzCpc.js";import{t as oe}from"./refresh-cw-9oudg8kg.js";import{t as V}from"./rotate-cw-ClWkf91I.js";import{t as se}from"./wifi-Ctshxl91.js";import{E as H,F as U,G as ce,M as W,P as G,T as le,U as ue,V as de,W as fe,f as pe,i as me,o as K,p as he,s as ge,t as _e,x as q,z as ve}from"./index-DvxZ6VPS.js";import{t as J}from"./FormBuilder-B6OIFE8M.js";var ye=de(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);O();function be(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...be(n.fields));return t}function xe(e,t,n){let[r,i]=N(`idle`),[a,o]=N({}),s=A(()=>{let t=[];for(let n of e.sections)t.push(...be(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=D(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:D(async()=>{if(!n)return;let e=s.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;i(`testing`);let r={};for(let t of e)r[t]={status:`probing`};o(r);let a=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await n(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),c={};for(let e of a)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;c[t]={status:n.status===`ok`?`ok`:`error`,result:n}}o(c),i(`idle`)},[n,s,t]),clearProbeResult:l}}O();function Se(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Se(n.fields));return t}function Ce(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Y(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Y(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function X(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function we({open:e,integrationId:t,addonId:n,onClose:r}){let{t:i}=_e(),a=M(),[o,s]=N({}),[c,l]=N(!1),[u,d]=N(null),[f,p]=N(X),m=h({addonId:n},{enabled:e}),g=m.data?.deviceType??null,_=w({addonId:n,type:g??I.Camera},{enabled:e&&m.isSuccess&&g!==null}),v=_.data??null;ie(()=>{e&&(s(v?Y(v.sections.flatMap(e=>e.fields)):{}),p(X()),l(!1),d(null))},[e,t,v]);let b=A(()=>({...o,_probeRequestId:f}),[o,f]),S=ee({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),C=x(),te=D(async(e,t)=>{l(!0);let r=await C.mutateAsync({addonId:n,type:g??I.Camera,key:e,value:t,formValues:b});return r.status===`ok`&&r.suggestedValues&&s(e=>{let t=!1,n={...e};for(let[i,a]of Object.entries(r.suggestedValues??{}))Ce(e[i])&&!Ce(a)&&(n[i]=a,t=!0);return t?n:e}),r},[C,n,b,g]),{testAllStatus:ne,hasProbeFields:T,probeResults:E,handleTestAll:re,clearProbeResult:O}=xe(v??{sections:[]},o,te);async function j(e){d(null);try{await S.mutateAsync({addonId:n,type:g??I.Camera,config:o,integrationId:t}),e?s(v?Y(v.sections.flatMap(e=>e.fields)):{}):r()}catch(e){d(e instanceof Error?e.message:String(e))}}if(!e)return null;let F=Se((v?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ce(o[e])),L=F.length===0,R=m.isLoading||g!==null&&_.isLoading,z=m.isError||m.isSuccess&&g===null||_.isError||_.isSuccess&&v===null;return k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[P(`div`,{className:`absolute inset-0 bg-black/60`,onClick:r}),k(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl`,children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`integrations.addDevice`)}),P(`button`,{onClick:r,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:P(me,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:R?P(`div`,{className:`flex items-center justify-center py-8`,children:P(q,{className:`h-5 w-5 animate-spin text-primary`})}):z?k(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[P(K,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),k(`div`,{className:`space-y-1`,children:[P(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),k(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,P(`span`,{className:`font-mono`,children:n}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):P(J,{schema:v,values:o,onChange:s,onTestField:te,probeResults:E,onClearProbe:O})}),!z&&!R&&k(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[k(`button`,{type:`button`,onClick:()=>l(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[k(`span`,{className:`flex items-center gap-2`,children:[P(he,{className:`h-3.5 w-3.5`}),`Test logs`,P(`span`,{className:`font-mono text-[9px] opacity-60`,children:f.slice(0,14)})]}),P(G,{className:`h-3.5 w-3.5 transition-transform ${c?`rotate-180`:``}`})]}),c&&P(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:P(y,{addonId:n,requestId:f,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!z&&!R&&(u||F.length>0)&&P(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:u||`Required: ${F.join(`, `)}`})]})}),k(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.cancel`)}),!z&&T&&k(`button`,{type:`button`,onClick:re,disabled:ne===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[ne===`testing`?P(q,{className:`h-3.5 w-3.5 animate-spin`}):P(se,{className:`h-3.5 w-3.5`}),`Test All`]})]}),k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:()=>j(!0),disabled:z||!L||S.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:i(`integrations.saveAndNew`)}),P(`button`,{onClick:()=>j(!1),disabled:z||!L||S.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:S.isPending?i(`integrations.saving`):i(`integrations.save`)})]})]})]})]})}function Z(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}O();var Q=`devices`,Te={id:Q,label:`Devices`,isDefault:!0},Ee=2e4,De=100;function Oe({addonId:n,integrationId:r,onClose:i}){let{t:o}=_e(),[s,u]=N(new Set),[d,f]=N(new Set),[p,m]=N(new Map),[h,g]=N(null),{data:v}=a(),y=(v??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[b,ee]=N(!0),x=_({addonId:n,integrationId:r}).data?.filters,S=x&&x.length>0?x:[Te],[w,ne]=N(S.find(e=>e.isDefault)?.id??(S.some(e=>e.id===Q)?Q:S[0].id)),T=w!==Q,E=C(),O=te({addonId:n,integrationId:r,page:1,pageSize:Ee,filter:w}),A=O.refetch,j=E.mutate,M=D(()=>{j({addonId:n,integrationId:r},{onSettled:()=>{A()}})},[j,n,r,A]),F=re(null);ie(()=>{let e=`${n}::${r}`;F.current===e||O.isLoading||(F.current=e,(O.data?.candidates.length??0)===0&&M())},[n,r,O.isLoading,O.data,M]);let I=E.isPending,L=E.isError?E.error instanceof Error?E.error.message:String(E.error):null,R=O.data?.candidates??[],z=O.isError?O.error instanceof Error?O.error.message:String(O.error):null,B=e(),ae=D(e=>{e.alreadyAdopted||u(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),oe=D(e=>{f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=D((e,t)=>{m(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),H=D(e=>{let t={};for(let n of e){let e=p.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[p]),ce=D(async()=>{g(null);let e=[...s];if(e.length!==0)try{let t=H(e);await B.mutateAsync({addonId:n,integrationId:r,filter:w,childNativeIds:e,...t?{perCandidate:t}:{},...y?{importLocations:b}:{}}),u(new Set),m(new Map),await A(),i()}catch(e){g(e instanceof Error?e.message:String(e))}},[s,H,B,n,r,w,A,y,b]),W=D(e=>{ne(e),u(new Set),f(new Set),m(new Map),g(null)},[]),G=s.size;return k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[P(`div`,{className:`absolute inset-0 bg-black/60`,onClick:i}),k(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[k(`div`,{className:`min-w-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:o(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),P(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:o(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),k(`div`,{className:`flex items-center gap-3 shrink-0`,children:[y&&k(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[P(`input`,{type:`checkbox`,checked:b,onChange:e=>ee(e.target.checked),className:`accent-primary`}),o(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),P(`button`,{onClick:i,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:P(me,{className:`h-4 w-4`})})]})]}),k(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(L??z)&&R.length===0&&P(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),k(`div`,{className:`min-w-0`,children:[P(`p`,{className:`text-xs font-medium text-destructive`,children:o(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),P(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:L??z})]})]})}),S.length>1&&P(ke,{filters:S,activeFilter:w,onSelect:W}),P(`div`,{className:`flex-1 min-h-0`,children:P(c,{mode:`generic`,items:R,pageSize:De,getKey:e=>e.childNativeId,getSearchText:Z,getFilterType:e=>e.type,filterOptions:t(),filterLabel:o(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:O.isLoading||I&&R.length===0,searchPlaceholder:o(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(L??z)&&R.length===0?``:o(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:k(`button`,{type:`button`,onClick:M,disabled:I,title:o(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[P(V,{className:`h-3.5 w-3.5 ${I?`animate-spin`:``}`}),o(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:o(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>P($,{candidate:e,expandable:!T,expanded:d.has(e.childNativeId),onToggleExpand:()=>oe(e.childNativeId),adoptedLabel:o(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:o(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=l(e.type),n=t.icon;return k(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[P(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>P(`div`,{className:`flex items-center justify-end`,children:P(`button`,{onClick:()=>ae(e),disabled:e.alreadyAdopted,"aria-label":s.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${s.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:s.has(e.childNativeId)&&P(U,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!T&&d.has(e.childNativeId),renderExpanded:T?void 0:e=>P(Ae,{candidate:e,hiddenChildIds:p.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>se(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:s.has(e.childNativeId)?`bg-primary/5`:``})})]}),h&&P(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:h})]})}),k(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[P(`div`,{}),k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.cancel`,{defaultValue:`Cancel`})}),k(`button`,{onClick:ce,disabled:G===0||B.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[B.isPending&&P(q,{className:`h-3.5 w-3.5 animate-spin`}),o(`integrations.addSelected`,{defaultValue:`Add selected`}),G>0?` (${G})`:``]})]})]})]})]})}function ke({filters:e,activeFilter:t,onSelect:n}){return P(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return P(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function $({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let a=(e.children??[]).length;return k(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?k(`button`,{type:`button`,onClick:r,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[P(n?G:W,{className:`h-3.5 w-3.5`}),a]}):P(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),P(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&P(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function Ae({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let r=e.children??[];return r.length===0?null:P(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return k(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[P(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&P(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),P(`button`,{onClick:()=>n(e.childNativeId),"aria-label":r?`Show child`:`Hide child`,title:r?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:P(r?H:le,{className:`h-3 w-3`})})]},e.childNativeId)})})}O();function je({integrationId:e,addonId:t,name:n,kind:r,brokerKind:a,trpc:o,onClose:s}){let{t:c}=_e(),l=M(),u=r===`device-adoption`,{data:f}=i({id:e},{enabled:u}),p=A(()=>{let e=f?.brokerId;return typeof e==`string`?e:null},[f]),m=d();return P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:s,children:k(`div`,{className:`max-h-[85vh] w-full max-w-md overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`mb-3 flex items-center justify-between`,children:[k(`h2`,{className:`text-sm font-semibold text-foreground`,children:[c(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),P(`button`,{onClick:s,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":c(`common.close`,{defaultValue:`Close`}),children:P(me,{className:`h-4 w-4`})})]}),u?a?k(`div`,{className:`space-y-3`,children:[P(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),p&&k(`p`,{className:`text-[11px] text-foreground`,children:[c(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,P(`span`,{className:`font-mono text-foreground-subtle`,children:p})]}),m.isPending?k(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[P(q,{className:`h-3 w-3 animate-spin`}),c(`integrations.saving`,{defaultValue:`Saving…`})]}):P(z,{kind:a,onResolved:t=>{m.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{l.invalidateQueries(),s()}})},onBack:s}),m.isError&&P(`p`,{className:`text-[11px] text-danger`,children:c(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):P(`p`,{className:`text-[11px] text-danger`,children:c(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):P(E,{trpc:o,addonId:t,nodeId:`hub`,title:n})]})})}O();function Me(){let{t:e}=_e(),{integrationId:t}=fe(),i=M(),l=ue(),[d,h]=ce(),_=F(),[ee,x]=N(!1),[C,w]=N(!1),[te,E]=N(!1),[re,O]=N(!1),[I,z]=N(!1),{data:V,isLoading:se}=n({id:t??``},{enabled:!!t}),{data:H}=f({addonId:V?.addonId??``,nodeId:`hub`},{enabled:!!V?.addonId}),{data:U,isSuccess:W}=a(),G=A(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[U,V?.addonId,W]),{data:le}=S({}),de=A(()=>(le?.providers??[]).some(e=>e.addonId===V?.addonId),[le,V?.addonId]),J=G!==null,be=J?G===`device-adoption`?e(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):e(`integrations.addDevice`):e(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),xe=A(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.brokerKind??null},[U,V?.addonId,W]),Se=A(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.mode??null},[U,V?.addonId,W]);ie(()=>{d.get(`add`)===`1`&&J&&(x(!0),h(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[d,J,h]);let Ce=H!=null&&Array.isArray(H.sections)&&H.sections.some(e=>e.fields.length>0),{data:Y}=p({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:t??``},type:`query`}],Z=o({onMutate:async e=>{await i.cancelQueries({queryKey:X});let t=i.getQueryData(X);return t!=null&&i.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&i.setQueryData(X,r.previous)},onSettled:()=>{i.invalidateQueries({queryKey:[[`integrations`]]}),i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=u({onSuccess:()=>{i.invalidateQueries({queryKey:[[`integrations`]]}),i.invalidateQueries({queryKey:[[`deviceManager`]]}),O(!1),l(`/integrations`)}}),Te=v({onSuccess:()=>{i.invalidateQueries({queryKey:[[`integrations`]]}),i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=s({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=m({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=ne({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=A(()=>Y??[],[Y]),Ae=A(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Me=D(e=>Ae.get(e)??null,[Ae]),Ne=D(e=>P(L,{type:e,size:`sm`}),[]),Pe=D(e=>l(`/devices/${String(e)}`),[l]),Fe=A(()=>{let e=V?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,V?.addonId]),Ie=A(()=>r(Fe).length,[Fe]);return se?k(`div`,{className:`p-4`,children:[P(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),P(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):V?k(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[P(b,{items:[{label:`Integrations`,onClick:()=>l(`/integrations`)},{label:V.name}]}),k(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[k(`div`,{className:`flex items-center gap-3 min-w-0`,children:[P(`img`,{src:`/api/addon-assets/${V.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),k(`div`,{className:`min-w-0`,children:[P(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:V.name}),k(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[V.addonId,` · `,Ie,` `,e(`integrations.devices`)]})]})]}),k(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[de&&k(`button`,{onClick:()=>w(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[P(B,{className:`h-3.5 w-3.5`}),`Scan network`]}),k(`button`,{onClick:()=>x(!0),disabled:!J,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:be,children:[P(R,{className:`h-3.5 w-3.5`}),be]}),k(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${V.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[P(T,{checked:V.enabled,onCheckedChange:e=>Z.mutate({id:t,enabled:e}),disabled:Z.isPending,"aria-label":V.enabled?`Disable integration`:`Enable integration`}),P(`span`,{className:`text-[11px] font-medium ${V.enabled?`text-success`:`text-foreground-subtle`}`,children:V.enabled?`Enabled`:`Disabled`}),Z.isPending&&P(q,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(Ce||G===`device-adoption`)&&k(`button`,{onClick:()=>E(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[P(pe,{className:`h-3 w-3`}),e(`integrations.config`)]}),k(`button`,{onClick:()=>z(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrations.logs`,{defaultValue:`View logs`}),children:[P(he,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),P(g,{label:`Restart`,icon:oe,title:`Restart "${V.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ie} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Te.isPending,action:()=>Te.mutateAsync({addonId:V.addonId})}),k(`button`,{onClick:()=>O(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:e(`integrations.delete`,{defaultValue:`Delete integration`}),children:[P(ge,{className:`h-3 w-3`}),e(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),P(c,{context:`integration-detail`,devices:$,trpc:_.trpcClient,defaultView:`cards`,forceAddon:V.addonId,urlScope:`root`,lsKey:`integration-detail:${V.addonId}`,resolveIntegrationIcon:Ne,resolveParent:Me,onNavigate:Pe,batchActions:{remove:Ee.mutate,disable:De.mutate,enable:ke.mutate},onDeleteDevice:e=>Ee.mutate({deviceId:e.id})}),ee&&t&&G===`device-adoption`&&P(Oe,{addonId:V.addonId,integrationId:t,onClose:()=>x(!1)}),ee&&t&&G===`device-provider`&&P(we,{open:ee,integrationId:t,addonId:V.addonId,onClose:()=>x(!1)}),C&&V&&P(ae,{open:C,scope:{addonId:V.addonId,label:V.name},onClose:()=>w(!1)}),te&&t&&G!==null&&P(je,{integrationId:t,addonId:V.addonId,name:V.name,kind:G,brokerKind:xe,trpc:_.trpcClient,onClose:()=>E(!1)}),I&&P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>z(!1),children:k(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[k(`div`,{className:`flex items-center gap-2 min-w-0`,children:[P(he,{className:`h-4 w-4 text-primary shrink-0`}),P(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:V.name}),k(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[V.addonId,t?` · ${t}`:``]})]}),P(`button`,{onClick:()=>z(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:P(me,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:P(y,{addonId:V.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),re&&P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Q.isPending&&O(!1),children:k(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`flex items-start gap-3`,children:[P(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:P(K,{className:`h-4 w-4 text-danger`})}),k(`div`,{className:`min-w-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),P(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:V.name,count:Ie})})]})]}),Q.error&&P(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Q.error instanceof Error?Q.error.message:String(Q.error)}),k(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[P(`button`,{onClick:()=>O(!1),disabled:Q.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:e(`integrations.cancel`,{defaultValue:`Cancel`})}),P(`button`,{onClick:()=>Q.mutate({id:t}),disabled:Q.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Q.isPending?k(j,{children:[P(q,{className:`h-3 w-3 animate-spin`}),e(`integrations.deleting`,{defaultValue:`Deleting…`})]}):k(j,{children:[P(ge,{className:`h-3 w-3`}),e(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):k(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[P(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:P(ye,{className:`h-6 w-6 text-foreground-subtle`})}),k(`div`,{className:`space-y-1 max-w-sm`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),P(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t??``})})]}),k(`button`,{onClick:()=>l(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[P(ve,{className:`h-3 w-3`}),e(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Me as IntegrationDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{H as e,Kn as t,Qt as n,Un as r,V as i,Yn as a,Z as o,Zn as s,_n as c,ka as l,sn as u}from"./src-50esl92F.js";import{I as d,Q as f,S as p,W as m,b as h,o as ee,q as g,x as _,z as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as y}from"./player-overlays-DEDwF8Uo.js";import{t as b}from"./ProviderIcon-RCIWUZYh.js";import{t as x}from"./plus-BgpJnRYz.js";import{n as S,r as C,t as w}from"./ScanNetworkModal-CVTAzCpc.js";import{t as T}from"./refresh-cw-9oudg8kg.js";import{F as E,G as D,I as O,M as k,P as A,U as j,f as M,g as N,i as P,t as F,x as I}from"./index-DvxZ6VPS.js";import{t as L}from"./AdminPage-BwmGKnRf.js";import{t as R}from"./StatusBadge-Dcr2bw58.js";import{t as z}from"./useEventInvalidation-BTia6ZIb.js";import{t as B}from"./FormBuilder-B6OIFE8M.js";import{t as V}from"./useBodyScrollLock-B_rtaBV1.js";f();function H({onSelect:e,onClose:n,pendingAddonId:r=null}){let{t:i}=F(),a=j(),{data:o,isLoading:s}=t();if(s)return _(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let c=r!==null;return p(`div`,{className:`space-y-2`,children:[(o??[]).map(t=>{let o=t.instanceMode===`unique`&&t.existingInstances.length>0,s=r===t.addonId,l=c;return p(`button`,{disabled:l,onClick:()=>{if(!l)if(o){let e=t.existingInstances[0].id;n(),a(`/integrations/${e}`)}else e(t.addonId,t.instanceMode,t.discoveryMode,t.name,t.kind,t.brokerKind,t.mode)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[t.iconUrl?_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${t.color}15`},children:_(`img`,{src:t.iconUrl,alt:``,className:`h-5 w-5`})}):_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${t.color}15`},children:_(`span`,{className:`text-sm`,style:{color:t.color},children:`◉`})}),p(`div`,{className:`flex-1 min-w-0`,children:[_(`p`,{className:`text-xs font-semibold text-foreground`,children:t.name}),t.description&&_(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:t.description})]}),s?_(I,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):o?p(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[_(M,{className:`h-3 w-3`}),i(`integrations.manage`)]}):_(k,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},t.addonId)}),(o??[]).length===0&&_(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}function U({addonId:e,configSchema:t,onSave:n,onBack:r}){let{t:i}=F(),[a,o]=g(``),[c,l]=g({}),[u,d]=g(null),f=s({onSuccess:e=>d(e),onError:e=>d({success:!1,error:String(e)})});return p(`div`,{className:`space-y-4`,children:[p(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:i(`integrations.integrationName`)}),_(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:i(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&_(B,{schema:t,values:c,onChange:l}),u&&_(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${u.success?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:u.success?i(`integrations.connectionSuccess`):`${i(`integrations.errorPrefix`)} ${u.error}`}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.back`)}),p(`div`,{className:`flex items-center gap-2`,children:[_(`button`,{onClick:()=>f.mutate({addonId:e,settings:c}),disabled:f.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f.isPending?i(`integrations.testing`):i(`integrations.testConnection`)}),_(`button`,{onClick:()=>n({name:a,config:c}),disabled:!a.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:i(`integrations.forward`)})]})]})]})}f();function te({providerId:e,onImport:t,onSkip:n}){let{t:r}=F(),[i,a]=g(new Set),o=u(),s=o.data,c=o.isPending||!o.data&&!o.isError;v(()=>{e&&(o.isPending||o.data||o.mutate({addonId:e}))},[e,o]);function l(e){a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(c)return p(`div`,{className:`flex flex-col items-center py-12`,children:[_(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),_(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:r(`integrations.searchingDevices`)})]});let d=s??[];return p(`div`,{className:`space-y-4`,children:[_(`p`,{className:`text-xs text-foreground-subtle`,children:d.length>0?r(`integrations.foundDevices`,{count:d.length}):r(`integrations.noDevicesFound`)}),d.length>0&&_(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:d.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=i.has(t);return p(`button`,{onClick:()=>l(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[_(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r?`border-primary bg-primary`:`border-border`}`,children:r&&_(E,{className:`h-3 w-3 text-primary-foreground`})}),_(O,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),_(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n})]},t)})}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.skip`)}),d.length>0&&p(`button`,{onClick:()=>t(Array.from(i)),disabled:i.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[r(`integrations.importSelected`),` (`,i.size,`)`]})]})]})}f();function W(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}function ne({open:e,onClose:t}){let{t:i}=F(),a=j(),s=ee(),[c,l]=g(`picker`),[d,f]=g(null),[y,b]=g(null),[x,C]=g(`manual`),[w,T]=g(null),[E,D]=g(``),[O,k]=g(null),[A,M]=g(null),{data:N}=o({addonId:d??``,nodeId:`hub`},{enabled:d!=null}),L=m(()=>N?W(N):null,[N]),R=r({onSuccess:()=>s.invalidateQueries({queryKey:[[`integrations`]]})}),z=u(),B=z.data;v(()=>{c!==`discovery`||!y||!d||z.isPending||z.data||z.mutate({addonId:d})},[c,y,d,z]);let ne=n({onSuccess:()=>s.invalidateQueries({queryKey:[[`deviceManager`]]})});function G(e,t,n,r,i,a,o){if(!R.isPending){if(f(e),C(n),D(r),M(null),o===`broker`){if(!a){M(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}T(a),l(`broker`);return}if(o===`account`){l(`config`);return}re(e,r)}}async function re(e,n){try{let r=await R.mutateAsync({addonId:e,name:n,settings:{}});t(),Y(),a(`/integrations/${r.id}?add=1`)}catch{}}async function ie(e){if(d)try{let t=await R.mutateAsync({addonId:d,name:e.name,settings:e.config});b(t.id),x===`auto`||x===`both`?l(`discovery`):J(t.id)}catch{}}async function K(e){if(d)try{let t=await R.mutateAsync({addonId:d,name:E,settings:{brokerId:e}});k(t.id),b(t.id),J(t.id)}catch{}}async function q(e){if(d){for(let t of e){let e=B?.find(e=>e.stableId===t);e&&await ne.mutateAsync({addonId:d,candidate:e,...O===null?{}:{integrationId:O}})}J()}}function J(e){let n=e??y??d;t(),Y(),n&&a(`/integrations/${n}`)}function Y(){l(`picker`),f(null),b(null),C(`manual`),T(null),D(``),k(null),M(null)}function X(){t(),Y()}if(V(e),!e)return null;let ae={picker:i(`integrations.newIntegration`),config:i(`integrations.configureIntegration`),discovery:i(`integrations.importDevices`),broker:i(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Z=R.isPending,oe=Z?d:null,Q=R.error;return p(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[_(`div`,{className:`absolute inset-0 bg-black/60`,onClick:Z?void 0:X}),p(`div`,{className:`relative z-10 w-full max-w-lg max-h-[85vh] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[p(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[_(`h2`,{className:`text-sm font-semibold text-foreground`,children:ae[c]}),_(`button`,{onClick:X,disabled:Z,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:_(P,{className:`h-4 w-4`})})]}),p(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[Q&&!Z&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:Q instanceof Error?Q.message:String(Q)}),c===`picker`&&p(h,{children:[A&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),_(H,{onSelect:G,onClose:X,pendingAddonId:oe})]}),c===`config`&&d&&_(U,{addonId:d,configSchema:L??null,onSave:ie,onBack:()=>l(`picker`)}),c===`broker`&&w&&_(S,{kind:w,onResolved:e=>{K(e)},onBack:()=>l(`picker`)}),c===`discovery`&&y&&_(te,{providerId:y,onImport:q,onSkip:J})]}),Z&&p(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm`,children:[_(I,{className:`h-6 w-6 animate-spin text-primary`}),_(`p`,{className:`text-xs font-medium text-foreground`,children:i(`integrations.creating`,{defaultValue:`Creating integration…`})}),_(`p`,{className:`text-[10px] text-foreground-subtle`,children:i(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})})]})]})]})}function G({integration:e,expanded:t,onToggleExpand:n}){return p(`div`,{className:`flex items-center gap-2.5`,children:[_(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:_(t?A:k,{className:`h-3.5 w-3.5`})}),_(b,{type:e.addonId,size:`sm`}),p(`div`,{className:`flex min-w-0 flex-col`,children:[_(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),_(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function re(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>_(G,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>_(R,{status:e.status})}]}f();function ie(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var K=`expand`;function q(){let{t}=F(),n=j(),r=y(),[o]=D(),[s,u]=g(!1),f=d(()=>u(!0),[]),ee=d(()=>u(!1),[]),[v,S]=g(!1),E=d(()=>S(!0),[]),O=d(()=>S(!1),[]);z([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),z([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:k,isLoading:A,refetch:M}=a(void 0),{data:P,isLoading:I,refetch:R}=c({}),B=m(()=>P??[],[P]),V=m(()=>k??[],[k]),H=m(()=>{let e=new Map;for(let t of B)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[B]),U=m(()=>{let t=new Map;for(let n of e(B)){let e=n.addonId??``;e&&t.set(e,(t.get(e)??0)+1)}return t},[B]),te=m(()=>V.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ie(e),deviceCount:U.get(e.addonId)??0})),[V,U]),W=o.get(K),G=d(e=>{let t=new URLSearchParams(window.location.search);t.get(K)===e?t.delete(K):t.set(K,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),q=d(e=>n(`/integrations/${e.id}`),[n]),J=d(e=>H.get(e)??null,[H]),Y=d(e=>_(b,{type:e,size:`sm`}),[]),X=d(e=>n(`/devices/${String(e)}`),[n]),ae=d(e=>_(i,{context:`integration-detail`,devices:B,trpc:r.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:Y,resolveParent:J,onNavigate:X}),[B,r.trpcClient,Y,J,X]),Z=d(e=>W===e.addonId,[W]),oe=m(()=>re({isExpanded:Z,onToggleExpand:G}),[Z,G]),Q=d(e=>`${e.name} ${e.addonId}`,[]),se=d(e=>e.addonId,[]),ce=d(()=>{M(),R()},[M,R]),$=A||I,le=V.length>0;return p(L,{icon:N,title:t(`nav.integrations`,`Integrations`),actions:p(h,{children:[_(`button`,{onClick:ce,disabled:$,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:_(T,{className:l(`h-3.5 w-3.5`,$&&`animate-spin`)})}),p(`button`,{onClick:E,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[_(C,{className:`h-3.5 w-3.5`}),`Scan network`]}),p(`button`,{onClick:f,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[_(x,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[$&&_(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!$&&!le&&p(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[_(`p`,{className:`text-sm`,children:`No integrations configured.`}),_(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!$&&le&&_(i,{mode:`generic`,items:te,getKey:se,getSearchText:Q,columns:oe,onRowClick:q,isExpanded:Z,renderExpanded:ae,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),_(ne,{open:s,onClose:ee}),_(w,{open:v,onClose:O})]})}export{q as IntegrationsPage};
|