@camstack/addon-admin-ui 1.2.9 → 1.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddLocationWizard-BsfRBmG0.js → AddLocationWizard-DJKIj4Vq.js} +1 -1
- package/dist/assets/{AddonCollectionPage-CXHeV-JA.js → AddonCollectionPage-DBwmh-7p.js} +1 -1
- package/dist/assets/Addons-BAVyYmSd.js +1 -0
- package/dist/assets/{AdminTabs-DPHt9Vrr.js → AdminTabs-C86tkpHf.js} +1 -1
- package/dist/assets/{AiProfiles-CrBHGY9x.js → AiProfiles-CwbozdZH.js} +1 -1
- package/dist/assets/{BrokerForm-ySM02NYp.js → BrokerForm-Ceit7i5a.js} +1 -1
- package/dist/assets/{Capabilities-RJVgwEI-.js → Capabilities-DVjMp0LA.js} +1 -1
- package/dist/assets/{CapabilityBadges-BfPStFDD.js → CapabilityBadges-wHMHjcxI.js} +1 -1
- package/dist/assets/Cluster-Bi6Jof0s.js +1 -0
- package/dist/assets/{ClusterRecordingTab-ZjVaVby-.js → ClusterRecordingTab-C60FGsQQ.js} +1 -1
- package/dist/assets/{Dashboard-BZ5hmETC.js → Dashboard-D6Aicmbz.js} +1 -1
- package/dist/assets/{Data-wAV4YBKT.js → Data-6Mll2i9v.js} +1 -1
- package/dist/assets/{DetectionIntelligence-Bg7TpnIp.js → DetectionIntelligence-CI8mQm8z.js} +1 -1
- package/dist/assets/DeviceDetail-CpGmfDch.js +2 -0
- package/dist/assets/{Devices-CfdnyBPp.js → Devices-BTHZe1eP.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Bcoa9QdA.js → EmbedPlayerPage-C5cjRT3R.js} +1 -1
- package/dist/assets/Events-TCtnhueX.js +1 -0
- package/dist/assets/{FormBuilder-6mYk-4qC.js → FormBuilder-DX4uNlbA.js} +1 -1
- package/dist/assets/Identity-CTvkbYQu.js +1 -0
- package/dist/assets/IntegrationDetail-DVufAZqC.js +1 -0
- package/dist/assets/{Integrations-gznlBNQL.js → Integrations--Ex0QHHn.js} +1 -1
- package/dist/assets/{Integrations-BaTJ1efj.js → Integrations-CP6MwGF_.js} +1 -1
- package/dist/assets/{Logs-BYB5TxRZ.js → Logs-BYdTwtAG.js} +1 -1
- package/dist/assets/{MyAccess-UCG3zSEN.js → MyAccess-BpzdZjnF.js} +1 -1
- package/dist/assets/Network-WWM7yysW.js +1 -0
- package/dist/assets/NodeAddonsSettingsPanel-Zb7zIgPq.js +1 -0
- package/dist/assets/{NodeInferenceDevices-DlG9HB9Y.js → NodeInferenceDevices-Br3NpxU9.js} +1 -1
- package/dist/assets/Notifications-DPOcyXOv.js +1 -0
- package/dist/assets/Pipeline-Bq_zgLIK.js +1 -0
- package/dist/assets/{Plates-Bx_hE0aw.js → Plates-Dg0UQBzd.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-BJvJ34n1.js → PrivacyMaskSettings-H2Rkbk7c.js} +1 -1
- package/dist/assets/{ProviderIcon-CQTRNfxg.js → ProviderIcon-CbniiQ2T.js} +1 -1
- package/dist/assets/{Recordings-Crcm4LyU.js → Recordings-B9VeDyTg.js} +1 -1
- package/dist/assets/{ScanNetworkModal-CXbSxWid.js → ScanNetworkModal-BbMeBlgb.js} +1 -1
- package/dist/assets/{Settings-cYqjCG75.js → Settings-D2du_aL0.js} +1 -1
- package/dist/assets/{Showroom-B6fhw1D9.js → Showroom-B1CeddX4.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CHN43utV.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DNJ_bxKM.js} +1 -1
- package/dist/assets/{build-cluster-graph-BN5pfFK1.js → build-cluster-graph-B2o-tJsx.js} +1 -1
- package/dist/assets/circle-check-big-GofM13qt.js +1 -0
- package/dist/assets/clock-BzqRmwQW.js +1 -0
- package/dist/assets/{copy-BmgVaD29.js → copy-DZq-D128.js} +1 -1
- package/dist/assets/{debounced-invalidate-DCtq_NHc.js → debounced-invalidate-BdSeV9Ur.js} +1 -1
- package/dist/assets/{download-NKkCvEeB.js → download-Bk-h3QfT.js} +1 -1
- package/dist/assets/{face-bbox-C2co2f2G.js → face-bbox-rZ8C-B5u.js} +1 -1
- package/dist/assets/{hostInit-Cfj52F2C.js → hostInit-DNYnPeaE.js} +1 -1
- package/dist/assets/index-BZeaUVWu.js +4 -0
- package/dist/assets/{key-round-Cblg8i0e.js → key-round-CLISgDFt.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-1aa09b03.js → mf-entry-bootstrap-0-d13392b8.js} +2 -2
- package/dist/assets/{pencil-Ik1l3G_8.js → pencil-D1X7sD6V.js} +1 -1
- package/dist/assets/plus-CO0o82bd.js +1 -0
- package/dist/assets/{radio-BtzRHQBo.js → radio-BGOieuIp.js} +1 -1
- package/dist/assets/{refresh-cw-D92Y26QW.js → refresh-cw-CLfX2afX.js} +1 -1
- package/dist/assets/remoteEntry-D6COYK6a.js +1 -0
- package/dist/assets/{rotate-ccw-ByTFEZ8o.js → rotate-ccw-DRI24saO.js} +1 -1
- package/dist/assets/rotate-cw-PcEY8RfB.js +1 -0
- package/dist/assets/search-CZ7LK1Yj.js +1 -0
- package/dist/assets/{send-CGqdmApb.js → send-DSh5Ra_L.js} +1 -1
- package/dist/assets/{server-BwAvkFi_.js → server-BLUgyuUB.js} +1 -1
- package/dist/assets/square-T3rkAjgn.js +1 -0
- package/dist/assets/{square-check-big-tgpBR4IT.js → square-check-big-D_0rGgCa.js} +1 -1
- package/dist/assets/{src-Bwet06Ih.js → src-DvkErVKO.js} +4 -4
- package/dist/assets/{upload-BNU4vgq-.js → upload-x64qPzUI.js} +1 -1
- package/dist/assets/{useEventInvalidation-BslmDCfY.js → useEventInvalidation-DNKOmbzS.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-5Zi8N25y.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DPVzZjZM.js} +2 -2
- package/dist/assets/{wifi-C-i5Y8G3.js → wifi-6r257Xq_.js} +1 -1
- package/dist/assets/{zap-DWRzzBU1.js → zap-DsJvd0xN.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/Addons-CqINXARB.js +0 -1
- package/dist/assets/Cluster-dRepFsEe.js +0 -1
- package/dist/assets/DeviceDetail-DqhElVhT.js +0 -2
- package/dist/assets/Events-DVCiXgvH.js +0 -1
- package/dist/assets/Identity-DoJbe6Tm.js +0 -1
- package/dist/assets/IntegrationDetail-C-TlCYIU.js +0 -1
- package/dist/assets/Network-DL8hq6nl.js +0 -1
- package/dist/assets/NodeAddonsSettingsPanel-DY-AneF0.js +0 -1
- package/dist/assets/Notifications-BKw_GWsb.js +0 -1
- package/dist/assets/Pipeline-cxfq6x3v.js +0 -1
- package/dist/assets/circle-check-big-B9HIwiFo.js +0 -1
- package/dist/assets/clock-HmbKVCZT.js +0 -1
- package/dist/assets/history-CaP7eXW2.js +0 -1
- package/dist/assets/index-RegSp4ae.js +0 -4
- package/dist/assets/plus-B0OPxy2A.js +0 -1
- package/dist/assets/remoteEntry-f6PDtaSI.js +0 -1
- package/dist/assets/rotate-cw-C6p7zQhm.js +0 -1
- package/dist/assets/search-BUbY58eR.js +0 -1
- package/dist/assets/square-Ckdv6ORu.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$a as e,G as t,Gn as n,In as r,K as i,Pn as a,Sn as o,Tn as s,Tt as c,_n as l,_o as u,cr as d,d as f,dn as p,dr as m,fn as h,g,gn as _,hr as ee,it as v,jn as y,lr as b,mn as x,nt as S,pn as C,pr as w,sr as T,ut as te,x as E,xn as D}from"./src-Bwet06Ih.js";import{I as O,K as ne,Q as k,S as A,W as j,b as M,o as N,q as P,x as F,z as re}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{E as I}from"./src-GxiMH1Sc.js";import{p as L}from"./player-overlays-BlOdAA3b.js";import{t as R}from"./ProviderIcon-CQTRNfxg.js";import{t as z}from"./FormBuilder-6mYk-4qC.js";import{t as B}from"./plus-B0OPxy2A.js";import{n as V,r as ie,t as ae}from"./ScanNetworkModal-CXbSxWid.js";import{t as oe}from"./refresh-cw-D92Y26QW.js";import{t as se}from"./rotate-cw-C6p7zQhm.js";import{t as H}from"./wifi-C-i5Y8G3.js";import{D as U,H as ce,I as W,J as le,K as ue,L as G,O as de,P as fe,S as K,W as q,i as pe,m as me,o as J,p as he,q as ge,s as _e,t as ve}from"./index-RegSp4ae.js";var ye=q(`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`}]]);k();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]=P(`idle`),[a,o]=P({}),s=j(()=>{let t=[];for(let n of e.sections)t.push(...be(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=O(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:O(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}}k();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:r,onClose:i}){let{t:o}=ve(),c=N(),[l,u]=P({}),[d,f]=P(!1),[p,m]=P(null),[h,ee]=P(X),v=a({addonId:r},{enabled:e}),y=v.data?.deviceType??null,b=s({addonId:r,type:y??I.Camera},{enabled:e&&v.isSuccess&&y!==null}),x=b.data??null;re(()=>{e&&(u(x?Y(x.sections.flatMap(e=>e.fields)):{}),ee(X()),f(!1),m(null))},[e,t,x]);let S=j(()=>({...l,_probeRequestId:h}),[l,h]),C=_({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),w=n(),T=O(async(e,t)=>{f(!0);let n=await w.mutateAsync({addonId:r,type:y??I.Camera,key:e,value:t,formValues:S});return n.status===`ok`&&n.suggestedValues&&u(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ce(e[i])&&!Ce(a)&&(r[i]=a,t=!0);return t?r:e}),n},[w,r,S,y]),{testAllStatus:te,hasProbeFields:E,probeResults:D,handleTestAll:ne,clearProbeResult:k}=xe(x??{sections:[]},l,T);async function M(e){m(null);try{await C.mutateAsync({addonId:r,type:y??I.Camera,config:l,integrationId:t}),e?u(x?Y(x.sections.flatMap(e=>e.fields)):{}):i()}catch(e){m(e instanceof Error?e.message:String(e))}}if(!e)return null;let L=Se((x?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ce(l[e])),R=L.length===0,B=v.isLoading||y!==null&&b.isLoading,V=v.isError||v.isSuccess&&y===null||b.isError||b.isSuccess&&x===null;return A(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[F(`div`,{className:`absolute inset-0 bg-black/60`,onClick:i}),A(`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:[A(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[F(`h2`,{className:`text-sm font-semibold text-foreground`,children:o(`integrations.addDevice`)}),F(`button`,{onClick:i,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:F(pe,{className:`h-4 w-4`})})]}),F(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:B?F(`div`,{className:`flex items-center justify-center py-8`,children:F(K,{className:`h-5 w-5 animate-spin text-primary`})}):V?A(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[F(J,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),A(`div`,{className:`space-y-1`,children:[F(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),A(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,F(`span`,{className:`font-mono`,children:r}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):F(z,{schema:x,values:l,onChange:u,onTestField:T,probeResults:D,onClearProbe:k})}),!V&&!B&&A(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[A(`button`,{type:`button`,onClick:()=>f(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:[A(`span`,{className:`flex items-center gap-2`,children:[F(me,{className:`h-3.5 w-3.5`}),`Test logs`,F(`span`,{className:`font-mono text-[9px] opacity-60`,children:h.slice(0,14)})]}),F(W,{className:`h-3.5 w-3.5 transition-transform ${d?`rotate-180`:``}`})]}),d&&F(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:F(g,{addonId:r,requestId:h,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!V&&!B&&(p||L.length>0)&&F(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:A(`div`,{className:`flex items-start gap-2`,children:[F(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),F(`p`,{className:`text-[11px] text-destructive`,children:p||`Required: ${L.join(`, `)}`})]})}),A(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[A(`div`,{className:`flex items-center gap-2`,children:[F(`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`)}),!V&&E&&A(`button`,{type:`button`,onClick:ne,disabled:te===`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:[te===`testing`?F(K,{className:`h-3.5 w-3.5 animate-spin`}):F(H,{className:`h-3.5 w-3.5`}),`Test All`]})]}),A(`div`,{className:`flex items-center gap-2`,children:[F(`button`,{onClick:()=>M(!0),disabled:V||!R||C.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:o(`integrations.saveAndNew`)}),F(`button`,{onClick:()=>M(!1),disabled:V||!R||C.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:C.isPending?o(`integrations.saving`):o(`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(` `)}k();var Q=`devices`,Te={id:Q,label:`Devices`,isDefault:!0},Ee=2e4,De=100;function Oe({addonId:e,integrationId:n,onClose:r}){let{t:i}=ve(),[a,o]=P(new Set),[s,c]=P(new Set),[l,u]=P(new Map),[d,f]=P(null),{data:m}=b(),g=(m??[]).find(t=>t.addonId===e)?.supportsLocationImport??!1,[_,ee]=P(!0),y=h({addonId:e,integrationId:n}).data?.filters,w=y&&y.length>0?y:[Te],[T,te]=P(w.find(e=>e.isDefault)?.id??(w.some(e=>e.id===Q)?Q:w[0].id)),E=T!==Q,D=x(),k=C({addonId:e,integrationId:n,page:1,pageSize:Ee,filter:T}),j=k.refetch,M=D.mutate,N=O(()=>{M({addonId:e,integrationId:n},{onSettled:()=>{j()}})},[M,e,n,j]),I=ne(null);re(()=>{let t=`${e}::${n}`;I.current===t||k.isLoading||(I.current=t,(k.data?.candidates.length??0)===0&&N())},[e,n,k.isLoading,k.data,N]);let L=D.isPending,R=D.isError?D.error instanceof Error?D.error.message:String(D.error):null,z=k.data?.candidates??[],B=k.isError?k.error instanceof Error?k.error.message:String(k.error):null,V=p(),ie=O(e=>{e.alreadyAdopted||o(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ae=O(e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),oe=O((e,t)=>{u(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=O(e=>{let t={};for(let n of e){let e=l.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[l]),U=O(async()=>{f(null);let t=[...a];if(t.length!==0)try{let i=H(t);await V.mutateAsync({addonId:e,integrationId:n,filter:T,childNativeIds:t,...i?{perCandidate:i}:{},...g?{importLocations:_}:{}}),o(new Set),u(new Map),await j(),r()}catch(e){f(e instanceof Error?e.message:String(e))}},[a,H,V,e,n,T,j,g,_]),ce=O(e=>{te(e),o(new Set),c(new Set),u(new Map),f(null)},[]),W=a.size;return A(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[F(`div`,{className:`absolute inset-0 bg-black/60`,onClick:r}),A(`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:[A(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[A(`div`,{className:`min-w-0`,children:[F(`h2`,{className:`text-sm font-semibold text-foreground`,children:i(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),F(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:i(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),A(`div`,{className:`flex items-center gap-3 shrink-0`,children:[g&&A(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[F(`input`,{type:`checkbox`,checked:_,onChange:e=>ee(e.target.checked),className:`accent-primary`}),i(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),F(`button`,{onClick:r,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:F(pe,{className:`h-4 w-4`})})]})]}),A(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(R??B)&&z.length===0&&F(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:A(`div`,{className:`flex items-start gap-2`,children:[F(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),A(`div`,{className:`min-w-0`,children:[F(`p`,{className:`text-xs font-medium text-destructive`,children:i(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),F(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:R??B})]})]})}),w.length>1&&F(ke,{filters:w,activeFilter:T,onSelect:ce}),F(`div`,{className:`flex-1 min-h-0`,children:F(t,{mode:`generic`,items:z,pageSize:De,getKey:e=>e.childNativeId,getSearchText:Z,getFilterType:e=>e.type,filterOptions:S(),filterLabel:i(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:k.isLoading||L&&z.length===0,searchPlaceholder:i(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(R??B)&&z.length===0?``:i(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:A(`button`,{type:`button`,onClick:N,disabled:L,title:i(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[F(se,{className:`h-3.5 w-3.5 ${L?`animate-spin`:``}`}),i(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:i(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>F($,{candidate:e,expandable:!E,expanded:s.has(e.childNativeId),onToggleExpand:()=>ae(e.childNativeId),adoptedLabel:i(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:i(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=v(e.type),n=t.icon;return A(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[F(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=>F(`div`,{className:`flex items-center justify-end`,children:F(`button`,{onClick:()=>ie(e),disabled:e.alreadyAdopted,"aria-label":a.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${a.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:a.has(e.childNativeId)&&F(G,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!E&&s.has(e.childNativeId),renderExpanded:E?void 0:e=>F(Ae,{candidate:e,hiddenChildIds:l.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>oe(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:a.has(e.childNativeId)?`bg-primary/5`:``})})]}),d&&F(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:A(`div`,{className:`flex items-start gap-2`,children:[F(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),F(`p`,{className:`text-[11px] text-destructive`,children:d})]})}),A(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[F(`div`,{}),A(`div`,{className:`flex items-center gap-2`,children:[F(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.cancel`,{defaultValue:`Cancel`})}),A(`button`,{onClick:U,disabled:W===0||V.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[V.isPending&&F(K,{className:`h-3.5 w-3.5 animate-spin`}),i(`integrations.addSelected`,{defaultValue:`Add selected`}),W>0?` (${W})`:``]})]})]})]})]})}function ke({filters:e,activeFilter:t,onSelect:n}){return F(`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 F(`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 A(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?A(`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:[F(n?W:fe,{className:`h-3.5 w-3.5`}),a]}):F(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),F(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&F(`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:F(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return A(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[F(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&F(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),F(`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:F(r?de:U,{className:`h-3 w-3`})})]},e.childNativeId)})})}k();function je({integrationId:e,addonId:t,name:n,kind:r,brokerKind:i,trpc:a,onClose:o}){let{t:s}=ve(),c=N(),l=r===`device-adoption`,{data:u}=m({id:e},{enabled:l}),d=j(()=>{let e=u?.brokerId;return typeof e==`string`?e:null},[u]),f=w();return F(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:o,children:A(`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:[A(`div`,{className:`mb-3 flex items-center justify-between`,children:[A(`h2`,{className:`text-sm font-semibold text-foreground`,children:[s(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),F(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":s(`common.close`,{defaultValue:`Close`}),children:F(pe,{className:`h-4 w-4`})})]}),l?i?A(`div`,{className:`space-y-3`,children:[F(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),d&&A(`p`,{className:`text-[11px] text-foreground`,children:[s(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,F(`span`,{className:`font-mono text-foreground-subtle`,children:d})]}),f.isPending?A(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[F(K,{className:`h-3 w-3 animate-spin`}),s(`integrations.saving`,{defaultValue:`Saving…`})]}):F(V,{kind:i,onResolved:t=>{f.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{c.invalidateQueries(),o()}})},onBack:o}),f.isError&&F(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):F(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):F(E,{trpc:a,addonId:t,nodeId:`hub`,title:n})]})})}k();function Me(){let{t:n}=ve(),{integrationId:a}=ge(),s=N(),p=ue(),[m,h]=le(),_=L(),[v,x]=P(!1),[S,C]=P(!1),[w,E]=P(!1),[ne,k]=P(!1),[I,z]=P(!1),{data:V,isLoading:se}=d({id:a??``},{enabled:!!a}),{data:H}=te({addonId:V?.addonId??``,nodeId:`hub`},{enabled:!!V?.addonId}),{data:U,isSuccess:W}=b(),G=j(()=>{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:de}=D({}),fe=j(()=>(de?.providers??[]).some(e=>e.addonId===V?.addonId),[de,V?.addonId]),q=G!==null,be=q?G===`device-adoption`?n(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):n(`integrations.addDevice`):n(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),xe=j(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.brokerKind??null},[U,V?.addonId,W]),Se=j(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.mode??null},[U,V?.addonId,W]);re(()=>{m.get(`add`)===`1`&&q&&(x(!0),h(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[m,q,h]);let Ce=H!=null&&Array.isArray(H.sections)&&H.sections.some(e=>e.fields.length>0),{data:Y}=y({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:a??``},type:`query`}],Z=ee({onMutate:async e=>{await s.cancelQueries({queryKey:X});let t=s.getQueryData(X);return t!=null&&s.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&s.setQueryData(X,r.previous)},onSettled:()=>{s.invalidateQueries({queryKey:[[`integrations`]]}),s.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=T({onSuccess:()=>{s.invalidateQueries({queryKey:[[`integrations`]]}),s.invalidateQueries({queryKey:[[`deviceManager`]]}),k(!1),p(`/integrations`)}}),Te=c({onSuccess:()=>{s.invalidateQueries({queryKey:[[`integrations`]]}),s.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=r({onSuccess:()=>{s.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=l({onSuccess:()=>{s.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=o({onSuccess:()=>{s.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=j(()=>Y??[],[Y]),Ae=j(()=>{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=O(e=>Ae.get(e)??null,[Ae]),Ne=O(e=>F(R,{type:e,size:`sm`}),[]),Pe=O(e=>p(`/devices/${String(e)}`),[p]),Fe=j(()=>{let e=V?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,V?.addonId]),Ie=j(()=>i(Fe).length,[Fe]);return se?A(`div`,{className:`p-4`,children:[F(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),F(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):V?A(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[F(e,{items:[{label:`Integrations`,onClick:()=>p(`/integrations`)},{label:V.name}]}),A(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[A(`div`,{className:`flex items-center gap-3 min-w-0`,children:[F(`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`}}),A(`div`,{className:`min-w-0`,children:[F(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:V.name}),A(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[V.addonId,` · `,Ie,` `,n(`integrations.devices`)]})]})]}),A(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[fe&&A(`button`,{onClick:()=>C(!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:[F(ie,{className:`h-3.5 w-3.5`}),`Scan network`]}),A(`button`,{onClick:()=>x(!0),disabled:!q,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:[F(B,{className:`h-3.5 w-3.5`}),be]}),A(`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:n(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[F(u,{checked:V.enabled,onCheckedChange:e=>Z.mutate({id:a,enabled:e}),disabled:Z.isPending,"aria-label":V.enabled?`Disable integration`:`Enable integration`}),F(`span`,{className:`text-[11px] font-medium ${V.enabled?`text-success`:`text-foreground-subtle`}`,children:V.enabled?`Enabled`:`Disabled`}),Z.isPending&&F(K,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(Ce||G===`device-adoption`)&&A(`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:[F(he,{className:`h-3 w-3`}),n(`integrations.config`)]}),A(`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:n(`integrations.logs`,{defaultValue:`View logs`}),children:[F(me,{className:`h-3 w-3`}),n(`integrations.logs`,{defaultValue:`Logs`})]}),F(f,{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})}),A(`button`,{onClick:()=>k(!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:n(`integrations.delete`,{defaultValue:`Delete integration`}),children:[F(_e,{className:`h-3 w-3`}),n(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),F(t,{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})}),v&&a&&G===`device-adoption`&&F(Oe,{addonId:V.addonId,integrationId:a,onClose:()=>x(!1)}),v&&a&&G===`device-provider`&&F(we,{open:v,integrationId:a,addonId:V.addonId,onClose:()=>x(!1)}),S&&V&&F(ae,{open:S,scope:{addonId:V.addonId,label:V.name},onClose:()=>C(!1)}),w&&a&&G!==null&&F(je,{integrationId:a,addonId:V.addonId,name:V.name,kind:G,brokerKind:xe,trpc:_.trpcClient,onClose:()=>E(!1)}),I&&F(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>z(!1),children:A(`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:[A(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[A(`div`,{className:`flex items-center gap-2 min-w-0`,children:[F(me,{className:`h-4 w-4 text-primary shrink-0`}),F(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:V.name}),A(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[V.addonId,a?` · ${a}`:``]})]}),F(`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:F(pe,{className:`h-4 w-4`})})]}),F(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:F(g,{addonId:V.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),ne&&F(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Q.isPending&&k(!1),children:A(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[A(`div`,{className:`flex items-start gap-3`,children:[F(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:F(J,{className:`h-4 w-4 text-danger`})}),A(`div`,{className:`min-w-0`,children:[F(`h2`,{className:`text-sm font-semibold text-foreground`,children:n(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),F(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:n(`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&&F(`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)}),A(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[F(`button`,{onClick:()=>k(!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:n(`integrations.cancel`,{defaultValue:`Cancel`})}),F(`button`,{onClick:()=>Q.mutate({id:a}),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?A(M,{children:[F(K,{className:`h-3 w-3 animate-spin`}),n(`integrations.deleting`,{defaultValue:`Deleting…`})]}):A(M,{children:[F(_e,{className:`h-3 w-3`}),n(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):A(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[F(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:F(ye,{className:`h-6 w-6 text-foreground-subtle`})}),A(`div`,{className:`space-y-1 max-w-sm`,children:[F(`h2`,{className:`text-sm font-semibold text-foreground`,children:n(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),F(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:a??``})})]}),A(`button`,{onClick:()=>p(`/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:[F(ce,{className:`h-3 w-3`}),n(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Me as IntegrationDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Cr as e,Dr as t,Er as n,Mr as r,Nr as i,Or as a,Qa as o,Ra as s,So as c,Sr as l,Tr as u,_a as d,bo as f,br as p,bt as m,jr as h,wr as g,xo as _,xr as ee,xt as v,yr as te}from"./src-Bwet06Ih.js";import{I as y,Q as b,S as x,W as S,b as C,o as w,q as T,x as E,z as ne}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{o as D,s as O}from"./src-GxiMH1Sc.js";import{p as k}from"./player-overlays-BlOdAA3b.js";import{n as A,t as re}from"./rotate-ccw-ByTFEZ8o.js";import{t as j}from"./copy-BmgVaD29.js";import{n as ie,t as M}from"./AddonCollectionPage-CXHeV-JA.js";import{t as ae}from"./refresh-cw-D92Y26QW.js";import{t as N}from"./server-BwAvkFi_.js";import{t as oe}from"./square-Ckdv6ORu.js";import{t as se}from"./wifi-C-i5Y8G3.js";import{L as ce,S as P,T as F,W as I,b as le,i as ue,k as L,l as de,o as R,v as z,x as B}from"./index-RegSp4ae.js";import{t as V}from"./AdminPage-BwmGKnRf.js";import{t as H}from"./AdminTabs-DPHt9Vrr.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var fe=I(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),pe=I(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),W=I(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);b();var G=5e3,me={connected:!1,endpoint:null};function he(){let e=w(),t=v({capName:`network-access`},{refetchInterval:G}),n=m(void 0,{refetchInterval:G}),a=S(()=>U(n.data??[]),[n.data]),o=S(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,a]),[s,c]=T(null),[l,u]=T({}),d=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),c(null),u(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},f=(e,t)=>{c(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);u(e=>({...e,[n]:r}))},p=r({onSuccess:d,onError:f}),h=i({onSuccess:d,onError:f});return E(M,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:F,itemIcon:F,capability:`network-access`,installButtonLabel:`Add tunnel`,items:o,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>E(ge,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>E(_e,{addonId:e.addonId,busyId:s,onStart:e=>{c(e),p.mutate({addonId:e})},onStop:e=>{c(e),h.mutate({addonId:e})}})})}function K(e){let{data:t}=h({addonId:e},{refetchInterval:G,retry:!1}),n=t?O.safeParse(t):null;return n?.success?n.data:me}function ge({addonId:e}){let t=K(e);return x(C,{children:[E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&x(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[E(L,{className:`h-3 w-3`}),t.endpoint.url]})]})}function _e({addonId:e,busyId:t,onStart:n,onStop:r}){let i=K(e),a=t===e;return i.connected?x(c,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?E(P,{className:`h-3 w-3 animate-spin`}):E(oe,{className:`h-3 w-3`}),`Stop`]}):x(c,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?E(P,{className:`h-3 w-3 animate-spin`}):E(ie,{className:`h-3 w-3`}),`Start`]})}b();var q=3e4;function ve(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function ye(){let e=v({capName:`turn-provider`},{refetchInterval:q}),t=m(void 0,{refetchInterval:q}),n=d(),r=n.data??[],i=S(()=>U(t.data??[]),[t.data]);return E(M,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:z,itemIcon:z,capability:`turn-provider`,installButtonLabel:`Add provider`,items:S(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,i]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>E(be,{addonId:e.addonId,enabled:e.isActive}),trailing:x(f,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),E(c,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),E(`div`,{className:`p-4`,children:r.length===0?E(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):E(`div`,{className:`flex flex-col gap-3`,children:r.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return x(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&x(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,E(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,E(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),E(`ul`,{className:`divide-y divide-border`,children:n.map(e=>E(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function be({addonId:e,enabled:t}){let n=d({addonId:e},{enabled:t,retry:!1}),r=S(()=>ve(n.data??[]),[n.data]);return!t||r.length===0?null:x(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[x(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),E(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>E(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}b();var xe={lan:z,wifi:se,docker:A,vpn:B,loopback:N,other:N},Se={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ce=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function we(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=S(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=S(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Ce.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):E(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>x(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[x(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[E(xe[t]??N,{className:`h-3.5 w-3.5 text-foreground-subtle`}),E(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Se[t]??t}),x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),E(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return x(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[E(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&E(ce,{className:`h-3 w-3`})}),x(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[x(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[E(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),E(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&x(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),x(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}b();var J={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function Te(){let t=w(),n=k(),r=ee(void 0,{refetchInterval:3e4}),i=te(void 0),a=e({onSuccess:()=>{t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),o=l({onSuccess:e=>{m(e.addresses),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),s=S(()=>r.data?.interfaces??[],[r.data]),u=p({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[d,m]=T([]),[h,g]=T(!1);ne(()=>{!h&&i.data&&(m(i.data.addresses),g(!0))},[i.data,h]);let _=i.data?.addresses??[],v=S(()=>{if(d.length!==_.length)return!0;let e=[...d].toSorted(),t=[..._].toSorted();return e.some((e,n)=>e!==t[n])},[d,_]),y=()=>{a.mutate({addresses:[...d]})},b=()=>{m(_)},C=()=>{m([])},D=()=>{r.refetch(),u.refetch(),i.refetch()},O=async()=>{try{let e=await n.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},A=u.data?.endpoints??[];return x(V,{children:[x(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[E(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),x(`div`,{className:`flex items-center gap-2 shrink-0`,children:[x(c,{size:`sm`,variant:`secondary`,onClick:D,disabled:r.isLoading,children:[E(ae,{className:`h-3 w-3 ${r.isLoading?`animate-spin`:``}`}),`Refresh`]}),E(c,{size:`sm`,variant:`secondary`,onClick:O,children:`Probe race`})]})]}),x(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[x(f,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:d.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${d.length} pinned`})]}),x(`div`,{className:`flex items-center gap-1`,children:[x(c,{size:`sm`,variant:`secondary`,onClick:()=>o.mutate(void 0),disabled:o.isPending||a.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[E(de,{className:`h-3 w-3`}),o.isPending?`Detecting…`:`Best match`]}),x(c,{size:`sm`,variant:`secondary`,onClick:C,disabled:d.length===0||a.isPending,children:[E(re,{className:`h-3 w-3`}),`Clear`]}),v&&E(c,{size:`sm`,variant:`secondary`,onClick:b,disabled:a.isPending,children:`Discard`}),x(c,{size:`sm`,variant:`primary`,onClick:y,disabled:!v||a.isPending,children:[E(pe,{className:`h-3 w-3`}),a.isPending?`Saving…`:`Save`]})]})]}),E(`div`,{className:`p-4`,children:E(we,{mode:`multiple`,interfaces:s,value:d,onChange:m,disabled:a.isPending,emptyMessage:r.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),x(f,{children:[x(`div`,{className:`px-4 py-3 border-b border-border`,children:[E(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),E(`div`,{className:`p-4`,children:A.length===0?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:u.isLoading?`Loading…`:`No endpoints available.`}):E(`ul`,{className:`space-y-1 text-xs`,children:A.map(e=>x(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[E(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${J[e.kind]??J.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&E(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&x(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),E(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),x(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}b();var Ee={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Y=5e3,De=3e4,Oe={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function ke(){let e=v({capName:`mesh-network`},{refetchInterval:Y}),t=m(void 0,{refetchInterval:Y}),n=S(()=>U(t.data??[]),[t.data]);return E(M,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:A,itemIcon:z,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:S(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>E(Ae,{addonId:e.addonId}),renderPrimaryAction:e=>E(je,{addonId:e.addonId}),renderExpandedPanel:e=>E(Me,{addonId:e.addonId})})}function X(e){let{data:t,isLoading:n}=g({addonId:e},{refetchInterval:Y,retry:!1}),r=t?D.safeParse(t):null;return{status:r?.success?r.data:Oe,isLoading:n}}function Ae({addonId:e}){let{status:t}=X(e);return x(C,{children:[E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&x(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function je({addonId:e}){let n=w(),[r,i]=T(!1),[o,s]=T(null),l=k(),{status:d}=X(e),f=y(()=>{n.invalidateQueries({queryKey:[[`meshNetwork`]]})},[n]),p=a(),m=u({onSuccess:f}),h=t({onSuccess:f}),g=y(async()=>{i(!0);let t={cancelled:!1};s(t);try{let n=await p.mutateAsync({addonId:e});if(t.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!t.cancelled&&(await Le(2e3),!t.cancelled);){let t=await l.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?D.safeParse(t):null;if(n?.success&&n.data.joined){f();break}if(Date.now()-r>6e5)break}}finally{i(!1),s(null)}},[e,f,p,l]),_=y(()=>{o&&(o.cancelled=!0),i(!1),s(null)},[o]);return E(C,{children:d.joined?x(C,{children:[x(c,{size:`sm`,variant:`secondary`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(le,{className:`h-3 w-3`}),`Disconnect`]}),x(c,{size:`sm`,variant:`ghost`,disabled:h.isPending,onClick:()=>h.mutate({addonId:e}),children:[h.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]}):r?x(c,{size:`sm`,variant:`ghost`,onClick:_,children:[E(ue,{className:`h-3 w-3 mr-1`}),` Cancel`]}):x(C,{children:[x(c,{size:`sm`,variant:`primary`,onClick:()=>void g(),children:[E(fe,{className:`h-3 w-3`}),`Connect`]}),x(c,{size:`sm`,variant:`ghost`,disabled:h.isPending,onClick:()=>h.mutate({addonId:e}),children:[h.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]})})}function Me({addonId:e}){let{status:t}=X(e),r=n({addonId:e},{refetchInterval:De,retry:!1});return x(`div`,{className:`rounded-lg border border-border bg-surface`,children:[x(`div`,{className:`p-4 space-y-4`,children:[t.error&&E(s,{message:t.error}),E(Ne,{status:t}),t.endpoints.length>0&&x(`div`,{className:`space-y-1.5`,children:[E(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>x(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[x(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Ee[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?E(F,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),x(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[E(L,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),E(`div`,{className:`border-t border-border`,children:E(Fe,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function Ne({status:e}){return E(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Pe(e.keyExpiry):`—`}].map(e=>x(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[E(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),E(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Pe(e){let t=e-Date.now();if(t<0)return`Expired ${Q(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function Fe({peers:e,loading:t}){let n=S(()=>e.map(e=>({...e,_id:e.id})),[e]),r=y(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=S(()=>[{key:`hostname`,header:`Hostname`,render:e=>x(`div`,{className:`flex flex-col`,children:[x(`div`,{className:`flex items-center gap-1.5`,children:[E(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&E(_,{variant:`info`,children:`self`}),e.exitNodeOption&&E(_,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&E(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),E(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs`,children:t}),E(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>x(`div`,{className:`flex items-center gap-1.5`,children:[E(_,{variant:Ie(e.connection),children:e.connection}),e.relay&&E(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?E(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>x(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Z(e.txBytes),` · ↓ `,Z(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>E(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Q(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?x(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[E(P,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?E(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):E(`div`,{className:`p-4`,children:E(o,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Ie(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Z(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function Q(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function Le(e){return new Promise(t=>setTimeout(t,e))}function $(){return E(`div`,{className:`flex flex-col p-4`,children:E(H,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:N,content:E(Te,{})},{id:`remote-access`,label:`Remote Access`,icon:F,content:E(he,{})},{id:`mesh`,label:`Mesh Networks`,icon:A,content:E(ke,{})},{id:`turn`,label:`TURN Servers`,icon:z,content:E(ye,{})}]})})}export{$ as NetworkPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{bt as e,dt as t,ft as n,on as r,zt as i}from"./src-Bwet06Ih.js";import{H as a,I as o,K as s,Q as c,S as l,W as u,i as d,k as f,o as p,p as m,q as h,t 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{W as y}from"./src-GxiMH1Sc.js";import{p as ee}from"./player-overlays-BlOdAA3b.js";import{t as b}from"./FormBuilder-6mYk-4qC.js";import{n as te,r as x,t as ne}from"./SchemaTabBar-DhsmEGyn.js";c();var S=f(function({addonId:e,schema:t,serverValues:n,onImmediateSave:r,onStateChange:i,onAction:c,disabled:l},d){let f=x({schema:t,serverValues:n,onImmediateSave:o(t=>r(e,t),[e,r]),onDeferredSave:o(()=>{},[])});a(d,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let p=f.pendingKeys,m=p.join(`|`),h=u(()=>p.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[p,f.values]),g=s(i);v(()=>{g.current=i},[i]),v(()=>{let t={};for(let e of p)t[e]=f.values[e];g.current({addonId:e,pendingKeys:p,pendingValues:t})},[e,m,h]);let y=u(()=>{if(c)return(t,n,r)=>c(e,t,n,r)},[e,c]);return _(b,{schema:t,values:f.values,onChange:f.handleChange,disabled:l,onAction:y})});c();function C(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>C(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function w(e,t){return{...e,fields:e.fields.map(e=>C(e,t))}}function re(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>w(e,t))},values:t}}function T({nodeId:a,addonIds:c,level:f,deviceId:v,capability:b,sectionIds:x,sectionTab:S,extraTabs:C,schemaTabExtras:w,title:T,description:E}){let D=p(),O=ee().trpcClient,k=n(),A=t(),j=r(),M=i(),N=!!(C&&C.length>0),[P,ae]=h(null);if(f===`device`&&!v)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let F=a??`hub`,I=d({queries:c.map(e=>({queryKey:[[`addonSettings`,f===`global`?`getGlobalSettings`:`getDeviceSettings`],{addonId:e,nodeId:F,deviceId:v??null,cap:b??null}],queryFn:async()=>f===`global`?{addonId:e,result:await O.addonSettings.getGlobalSettings.query({addonId:e,nodeId:F,...b?{cap:b}:{}})}:{addonId:e,result:await O.addonSettings.getDeviceSettings.query({addonId:e,deviceId:v,nodeId:F})},placeholderData:m}))}),L=I.some(e=>e.isLoading),R=I.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),z=u(()=>{let e=new Set;for(let t of I){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[R+`::`+I.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),B=u(()=>new Map((C??[]).map(e=>[e.id,e])),[C]),V=u(()=>{if(!N)return[];let e=[...new Set([...z,...(C??[]).map(e=>e.id),...(w??[]).map(e=>e.tabId)])],t=e=>{let t=B.get(e);if(t?.order!==void 0)return t.order;let n=y[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[N,z,C,B,w]),oe=u(()=>{let e=new Map,t=e=>y[e]?.label??e.charAt(0).toUpperCase()+e.slice(1);for(let n of z)e.set(n,t(n));for(let n of w??[])e.has(n.tabId)||e.set(n.tabId,t(n.tabId));for(let t of C??[])e.set(t.id,t.label);return e},[z,C,w]),H=N?P&&V.includes(P)?P:V[0]??null:null,U=H!==null&&B.has(H),W=N?H&&!U?H:void 0:S,{data:G}=e(void 0),se=u(()=>{let e=new Map;for(let t of G??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[G]),K=s(new Map),q=u(()=>{let e=x?new Set(x):null,t=[];for(let n of I){if(!n.data)continue;let r=n.data.result??K.current.get(n.data.addonId)??null;if(n.data.result!==null&&K.current.set(n.data.addonId,n.data.result),r===null)continue;let{schema:i,values:a}=re(r),o=i.sections.filter(t=>e?e.has(t.id):!0);if(o.length===0)continue;let s={...r,sections:r.sections.filter(t=>e?e.has(t.id):!0)},c={...i,sections:o};t.push({addonId:n.data.addonId,schemaWithValues:s,schema:c,serverValues:a})}return t},[R,x]),[J,ce]=h(new Map),le=o(e=>{ce(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),Y=s(new Map),ue=o(e=>t=>{t?Y.current.set(e,t):Y.current.delete(e)},[]),X=o(async(e,t)=>{f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),D.invalidateQueries({queryKey:[[`addonSettings`]]})},[k,A,F,f,v,D]),de=o(async(e,t,n,r)=>{let i=F;try{switch(t){case`reprobe-hwaccel`:await j.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await M.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await O.addons.custom.mutate({addonId:e,action:t,input:r});return D.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[j,M,F,D,O]),fe=o((e,t)=>{X(e,t)},[X]),Z=g({mutationFn:async()=>{let e=[];for(let t of q){let n=J.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)Y.current.get(t)?.discard();D.invalidateQueries({queryKey:[[`addonSettings`]]})}}),pe=o(()=>{for(let e of Y.current.values())e.discard()},[]),me=u(()=>{let e=0;for(let t of q){let n=J.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[q,J]),he=u(()=>{let e=new Map;for(let t of q){let n=J.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[q,J]);if(L)return _(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let Q=H&&U?B.get(H):void 0;if(!N&&q.length===0)return l(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:[`No addons in `,c.length>0?`[${c.join(`, `)}]`:`the current selection`,` `,`expose `,f,`-level settings on this node.`]});let $=Z.isPending;return l(`div`,{className:`space-y-4`,children:[(T||E)&&l(`div`,{className:`border-b border-border pb-2`,children:[T&&_(`h2`,{className:`text-sm font-semibold text-foreground`,children:T}),E&&_(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:E})]}),N&&_(ne,{tabs:V.map(e=>({id:e,label:oe.get(e)??e})),activeId:H,onChange:ae,pendingByTab:he}),Z.isError&&l(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(Z.error?.message??Z.error)]}),Q?Q.content:(()=>{let e=W?q.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===W).length,0):0,t=W!==null&&e<=1,n=q.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>W?(e.tab??`general`)===W:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i}),r=(w??[]).filter(e=>e.tabId===W),i=r.filter(e=>(e.placement??`before`)===`before`),a=r.filter(e=>e.placement===`after`);return n.length===0&&r.length===0?_(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:`Nothing to configure here for this node.`}):l(`div`,{className:`space-y-6`,children:[i.map((e,t)=>_(`div`,{children:e.content},`extra-before-${t}`)),n.length>0&&_(ie,{entries:n,paneStates:J,displayNames:se,disabled:$,setPaneRef:ue,onPaneStateChange:le,onImmediateSave:fe,onAction:de,inline:N||!!S}),a.map((e,t)=>_(`div`,{children:e.content},`extra-after-${t}`))]})})(),!L&&_(te,{pendingCount:me,onSave:()=>Z.mutate(),onDiscard:pe,saving:$})]})}function ie({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:i,onPaneStateChange:a,onImmediateSave:o,onAction:s,inline:c}){let d=u(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[f,p]=h(d[0]?.addonId??``);v(()=>{d.length!==0&&(d.find(e=>e.addonId===f)||p(d[0].addonId))},[d,f]);let m=d.find(e=>e.addonId===f)??d[0];if(!m)return null;let g=u(()=>s?(e,t,n,r)=>s(e,t,n,r):void 0,[s]),y=e=>_(S,{ref:i(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:o,onStateChange:a,onAction:g,disabled:r},e.addonId);return d.length===1||c?_(`div`,{className:`flex flex-col gap-4`,children:d.map(y)}):l(`div`,{className:`flex flex-col gap-3`,children:[_(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:d.map(e=>{let r=n.get(e.addonId)??e.addonId,i=e.addonId===m.addonId,a=(t.get(e.addonId)?.pendingKeys.length??0)>0;return l(`button`,{type:`button`,onClick:()=>p(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${i?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,a&&_(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),_(`div`,{className:`space-y-2`,children:d.map(e=>_(`div`,{style:e.addonId===m.addonId?void 0:{display:`none`},children:y(e)},e.addonId))})]})}export{T as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Ra as e,S as t,So as n,_o as r,bo as i,do as a,fo as o,go as s,ho as c,mo as l,vo as u,xo as d,yo as f}from"./src-Bwet06Ih.js";import{Q as p,S as m,W as h,a as g,b as _,q as v,t as y,x as b}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{E as x}from"./src-GxiMH1Sc.js";import{p as S}from"./player-overlays-BlOdAA3b.js";import{t as C}from"./circle-check-big-B9HIwiFo.js";import{t as w}from"./copy-BmgVaD29.js";import{t as T}from"./history-CaP7eXW2.js";import{t as E}from"./pencil-Ik1l3G_8.js";import{t as D}from"./plus-B0OPxy2A.js";import{t as O}from"./refresh-cw-D92Y26QW.js";import{t as k}from"./search-BUbY58eR.js";import{t as A}from"./send-CGqdmApb.js";import{N as j,S as M,V as N,W as P,i as ee,s as F}from"./index-RegSp4ae.js";import{t as I}from"./AdminPage-BwmGKnRf.js";import{t as te}from"./AdminTabs-DPHt9Vrr.js";var L=P(`bell-ring`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M22 8c0-2.3-.8-4.3-2-6`,key:`5bb3ad`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}],[`path`,{d:`M4 2C2.8 3.7 2 5.7 2 8`,key:`tap9e0`}]]),ne=P(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]);p();var R=e=>typeof e==`string`&&e.length>0;function re(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function ie(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function ae(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];R(i)&&n.push({mediaType:r,url:i})}return n}function oe(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=R(r.label),i=R(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function z(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=ae(e,t.attachmentUrls),i=oe(e,t.actions),a=e.ttl&&R(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:ie(e,t.format),priority:se(t.priority),...R(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&R(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&R(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...R(t.tag)?{tag:t.tag}:{}}}function se(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function ce(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function B(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var le={image:`https://example.com/sample.jpg`,video:`https://example.com/sample.mp4`,gif:`https://example.com/sample.gif`,audio:`https://example.com/sample.mp3`,icon:`https://example.com/icon.png`};function ue(e,t){let n=B(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=ce(e);return{...n,body:`Critical test notification`,priority:5,level:t?.id??``}}case`everything`:{let t={},n=0;for(let r of e.attachments.mediaTypes){if(n>=e.attachments.max)break;t[r]=le[r],n+=1}let r=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`https://example.com/action/${t+1}`}));return{level:``,priority:4,format:e.format.includes(`markdown`)?`markdown`:e.format.includes(`html`)?`html`:e.format[0]??`text`,title:`Everything the kind supports`,body:`This sample fills every control the kind advertises.`,attachmentUrls:t,actions:r,clickUrl:e.clickUrl?`https://example.com/open`:``,sound:e.sound?`default`:``,ttl:e.ttl?`3600`:``,tag:`camstack-test`}}}}var de=[{id:`minimal`,label:`Minimal (body only)`},{id:`everything`,label:`Everything supported`},{id:`overflow`,label:`Overflow`},{id:`critical`,label:`Critical`}],V=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,H=`block text-[11px] font-medium text-foreground mb-1`;function fe({target:e,kind:t,open:r,onClose:i}){let u=S(),f=h(()=>re(t.caps),[t.caps]),[p,g]=v(()=>B(t.caps)),[_,x]=v(null),C=h(()=>z(t.caps,p),[t.caps,p]),w=p.body.length,T=w>f.bodyMaxLen,E=e=>g(t=>({...t,...e})),D=y({mutationFn:()=>u.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:z(t.caps,p)}),onMutate:()=>x(null),onSuccess:e=>x(e),onError:e=>x({success:!1,error:e instanceof Error?e.message:`Test failed`})}),O=e=>{g(ue(t.caps,e)),x(null)},k=(e,t,n)=>{let r=p.actions.length>0?[...p.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},E({actions:r})};return b(a,{open:r,onOpenChange:e=>!e&&i(),children:m(o,{width:`lg`,className:`!max-w-2xl`,children:[b(c,{children:m(s,{children:[`Test "`,e.name,`" (`,t.label,`)`]})}),m(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[b(`div`,{className:`flex flex-wrap gap-1.5`,children:de.map(e=>b(n,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>O(e.id),children:e.label},e.id))}),m(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[f.levels.length>0&&m(`div`,{children:[b(`label`,{className:H,children:`Level`}),m(`select`,{className:V,value:p.level,onChange:e=>E({level:e.target.value}),children:[b(`option`,{value:``,children:`— derive from priority —`}),f.levels.map(e=>m(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=f.levels.find(e=>e.id===p.level);return e?m(`div`,{className:`mt-1 space-y-1`,children:[e.description&&b(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),m(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&b(d,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&b(d,{variant:`info`,children:`silent`}),e.flags?.noPush&&b(d,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&m(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),m(`div`,{children:[m(`label`,{className:H,children:[`Priority (ordinal): `,p.priority]}),b(`input`,{type:`range`,min:1,max:5,step:1,value:p.priority,onChange:e=>E({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),f.formats.length>0&&m(`div`,{children:[b(`label`,{className:H,children:`Format`}),b(`div`,{className:`flex flex-wrap gap-2`,children:f.formats.map(e=>m(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[b(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:p.format===e,onChange:()=>E({format:e})}),e]},e))})]}),m(`div`,{children:[b(`label`,{className:H,children:`Title`}),b(`input`,{className:V,value:p.title,onChange:e=>E({title:e.target.value})})]}),m(`div`,{children:[m(`label`,{className:H,children:[`Body`,` `,m(`span`,{className:T?`text-danger`:`text-foreground-subtle`,children:[`(`,w,`/`,f.bodyMaxLen,T?` — overflow`:``,`)`]})]}),b(`textarea`,{className:`${V} min-h-[80px] resize-y`,value:p.body,onChange:e=>E({body:e.target.value})})]}),f.attachmentSlots.length>0&&m(`div`,{children:[m(`label`,{className:H,children:[`Attachments`,` `,m(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,f.attachmentMode,`, max `,f.attachmentMax,f.attachmentMaxBytes?`, ≤${Math.round(f.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),b(`div`,{className:`space-y-1.5`,children:f.attachmentSlots.map(e=>m(`div`,{className:`flex items-center gap-2`,children:[b(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),b(`input`,{className:V,placeholder:`${e} URL`,value:p.attachmentUrls[e]??``,onChange:t=>E({attachmentUrls:{...p.attachmentUrls,[e]:t.target.value}})})]},e))})]}),f.showActions&&m(`div`,{children:[m(`label`,{className:H,children:[`Actions (up to `,f.maxActions,`)`]}),b(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(f.maxActions,3)},(e,t)=>m(`div`,{className:`flex items-center gap-2`,children:[b(`input`,{className:V,placeholder:`label`,value:p.actions[t]?.label??``,onChange:e=>k(t,`label`,e.target.value)}),b(`input`,{className:V,placeholder:`url`,value:p.actions[t]?.url??``,onChange:e=>k(t,`url`,e.target.value)})]},t))})]}),m(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[f.showClickUrl&&m(`div`,{children:[b(`label`,{className:H,children:`Click URL`}),b(`input`,{className:V,value:p.clickUrl,onChange:e=>E({clickUrl:e.target.value})})]}),f.showSound&&m(`div`,{children:[b(`label`,{className:H,children:`Sound`}),b(`input`,{className:V,value:p.sound,onChange:e=>E({sound:e.target.value})})]}),f.showTtl&&m(`div`,{children:[b(`label`,{className:H,children:`TTL (seconds)`}),b(`input`,{className:V,type:`number`,value:p.ttl,onChange:e=>E({ttl:e.target.value})})]}),f.showTag&&m(`div`,{children:[b(`label`,{className:H,children:`Tag`}),b(`input`,{className:V,value:p.tag,onChange:e=>E({tag:e.target.value})})]})]}),_&&b(pe,{result:_}),m(`details`,{className:`text-[10px]`,children:[b(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),b(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(C,null,2)})]})]}),m(l,{children:[b(n,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Close`}),m(n,{size:`sm`,type:`button`,disabled:D.isPending||p.body.length===0,onClick:()=>D.mutate(),children:[D.isPending?b(M,{className:`h-3.5 w-3.5 animate-spin`}):b(A,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function pe({result:e}){let t=e.renderedAs;return m(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[m(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?b(C,{className:`h-3.5 w-3.5 text-success`}):b(j,{className:`h-3.5 w-3.5 text-danger`}),b(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&b(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&m(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[b(`dt`,{children:`Resolved level`}),b(`dd`,{className:`text-foreground`,children:t.level}),b(`dt`,{children:`Format sent`}),b(`dd`,{className:`text-foreground`,children:t.format}),b(`dt`,{children:`Attachments sent`}),b(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),b(`dt`,{children:`Actions sent`}),b(`dd`,{className:`text-foreground`,children:t.actionsSent}),b(`dt`,{children:`Truncated`}),b(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),b(`dt`,{children:`Dropped`}),b(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function me(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function he(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function ge(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function _e(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}p();var ve=[`notificationOutput`,`listTargets`],ye=[`notificationOutput`,`listTargetKinds`];function U({kind:e,imgClassName:t,fallbackClassName:n}){return e?.iconUrl?b(`img`,{src:e.iconUrl,alt:e.label,className:t,loading:`lazy`,draggable:!1}):b(`span`,{className:n,children:e?.icon??`🔔`})}function be(){let t=S(),[a,o]=v({mode:`closed`}),[s,c]=v(null),l=g({queryKey:ve,queryFn:()=>t.trpcClient.notificationOutput.listTargets.query({})}),u=g({queryKey:ye,queryFn:async()=>(await t.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),f=h(()=>u.data??[],[u.data]),p=h(()=>{let e=new Map;for(let t of f)e.set(t.kind,t);return e},[f]),_=y({mutationFn:e=>t.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:e.target.addonId,targetId:e.target.id,enabled:e.enabled}),onSuccess:()=>void l.refetch()}),x=y({mutationFn:e=>t.trpcClient.notificationOutput.deleteTarget.mutate({addonId:e.addonId,targetId:e.id}),onSuccess:()=>void l.refetch()}),C=s?p.get(s.kind):void 0;return m(I,{icon:N,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:m(n,{size:`sm`,type:`button`,onClick:()=>o({mode:`pick-kind`}),children:[b(D,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[l.isLoading&&b(`div`,{className:`flex items-center justify-center py-16`,children:b(M,{className:`h-6 w-6 animate-spin text-primary`})}),l.isError&&!l.isLoading&&b(e,{title:`Failed to load targets`,message:l.error instanceof Error?l.error.message:`Unknown error`,onRetry:()=>void l.refetch()}),!l.isLoading&&!l.isError&&(l.data??[]).length===0&&b(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(l.data??[]).length>0&&b(i,{children:b(`ul`,{className:`divide-y divide-border`,children:(l.data??[]).map(e=>{let t=p.get(e.kind);return m(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[b(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:t?.label??e.kind,children:b(U,{kind:t,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),m(`div`,{className:`min-w-0 flex-1`,children:[b(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),b(`div`,{className:`text-[11px] text-foreground-subtle`,children:t?.label??e.kind})]}),!e.enabled&&b(d,{variant:`warning`,children:`disabled`}),b(r,{checked:e.enabled,onCheckedChange:t=>_.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),b(n,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>c(e),title:`Test`,children:b(A,{className:`h-3.5 w-3.5`})}),b(n,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>t&&o({mode:`form`,kind:t,target:e}),title:`Edit`,children:b(E,{className:`h-3.5 w-3.5`})}),b(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>x.mutate(e),title:`Delete`,children:b(F,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),a.mode===`pick-kind`&&b(xe,{kinds:f,onCancel:()=>o({mode:`closed`}),onPick:e=>o({mode:`form`,kind:e,target:null})}),a.mode===`form`&&b(Se,{kind:a.kind,target:a.target,onCancel:()=>o({mode:`closed`}),onSaved:()=>{o({mode:`closed`}),l.refetch()}}),s&&C&&b(fe,{target:s,kind:C,open:!0,onClose:()=>c(null)})]})}function xe({kinds:e,onPick:t,onCancel:r}){let a=h(()=>me(e),[e]);return m(i,{className:`p-4 space-y-4`,children:[m(`div`,{className:`flex items-center justify-between`,children:[b(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),b(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),a.length===0&&b(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),a.map(e=>m(`div`,{children:[b(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),b(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(n=>m(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[b(U,{kind:n,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),b(`span`,{className:`font-medium text-foreground`,children:n.label}),n.supportsDiscovery&&b(d,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function Se({kind:e,target:r,onSaved:a,onCancel:o}){let s=S(),c=h(()=>he(e.configSchema),[e.configSchema]),l=h(()=>r?.config??{},[r]),[u,d]=v(r?.name??e.label),[f,p]=v(()=>r?_e(r.config,c):{}),[g,_]=v(null),[x,C]=v(null),w=y({mutationFn:()=>s.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:f}),onSuccess:e=>_(e),onError:e=>C(e instanceof Error?e.message:`Discovery failed`)}),T=y({mutationFn:()=>{let t=ge(f,l,c),n={id:r?.id??`${e.kind}-${Date.now()}`,name:u,kind:e.kind,addonId:e.addonId,enabled:r?.enabled??!0,config:t};return s.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:n})},onSuccess:a,onError:e=>C(e instanceof Error?e.message:`Save failed`)}),E=e=>{d(e.suggestedName),p(t=>({...t,...e.config})),_(null)};return m(i,{className:`p-4 space-y-4`,children:[m(`div`,{className:`flex items-center justify-between`,children:[m(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[b(U,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),r?`Edit ${r.name}`:`Add ${e.label} target`]}),b(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:o,children:`Cancel`})]}),x&&b(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:x}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),b(`input`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,value:u,onChange:e=>d(e.target.value)})]}),e.supportsDiscovery&&m(`div`,{className:`space-y-2`,children:[m(n,{size:`sm`,variant:`outline`,type:`button`,disabled:w.isPending,onClick:()=>{C(null),w.mutate()},children:[w.isPending?b(M,{className:`h-3.5 w-3.5 animate-spin`}):b(k,{className:`h-3.5 w-3.5`}),`Discover`]}),g&&g.length===0&&b(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),g&&g.length>0&&b(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:g.map((e,t)=>m(`button`,{type:`button`,onClick:()=>E(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[b(`span`,{className:`text-foreground`,children:e.suggestedName}),b(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),c.length>0&&r&&b(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Secret fields are hidden. Leave them blank to keep the stored value; type a new value to replace it.`}),b(t,{schema:e.configSchema,values:f,onChange:p}),m(`div`,{className:`flex justify-end gap-2`,children:[b(n,{variant:`secondary`,size:`sm`,type:`button`,onClick:o,children:`Cancel`}),m(n,{size:`sm`,type:`button`,disabled:T.isPending||u.trim().length===0,onClick:()=>{C(null),T.mutate()},children:[T.isPending&&b(M,{className:`h-3.5 w-3.5 animate-spin`}),r?`Save changes`:`Create target`]})]})]})}var W=[{value:`immediate`,label:`Immediate`,hint:`Fires on the first matching detection of a track (lowest latency).`},{value:`track-end`,label:`Track end`,hint:`Evaluates the finalised track record when it closes.`},{value:`device-event`,label:`Device event`,hint:`Doorbell press / sensor state change on a linked device.`},{value:`package-event`,label:`Package event`,hint:`A parcel delivery or pick-up.`}];function Ce(e){return W.find(t=>t.value===e)?.label??e}function we(e){return W.find(t=>t.value===e)?.value}var G=[{value:`best`,label:`Best available image`,description:`The best subject crop available when the notification is sent.`},{value:`best-matching`,label:`Best matching image`,description:`The image that explains why the rule fired — the face crop for an identity rule, the plate crop for a plate rule; falls back to the best image otherwise.`},{value:`keyFrame`,label:`Key frame`,description:`The clean full scene frame with no subject box.`},{value:`none`,label:`No attachment`,description:`Send the notification with no image.`}];function Te(e){return G.find(t=>t.value===e)?.value}var Ee=[{value:`any`,label:`Any source`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`}],K=[{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`},{value:`both`,label:`Both`}],De=[{value:`any`,label:`Any of`},{value:`all`,label:`All of`}],Oe=[{value:1,label:`1 — Min`},{value:2,label:`2 — Low`},{value:3,label:`3 — Default`},{value:4,label:`4 — High`},{value:5,label:`5 — Max`}];function ke(){return{name:``,enabled:!0,delivery:`immediate`,targetIds:[],targetParams:{},priority:3,mediaAttach:`best`,templateTitle:``,templateBody:``,conditions:{},schedule:void 0}}function Ae(e){let t={};for(let n of e.targets)n.params&&Object.keys(n.params).length>0&&(t[n.targetId]=n.params);return{name:e.name,enabled:e.enabled,delivery:e.delivery,targetIds:e.targets.map(e=>e.targetId),targetParams:t,priority:e.priority,mediaAttach:e.media.attach,templateTitle:e.template?.title??``,templateBody:e.template?.body??``,conditions:e.conditions,schedule:e.schedule}}function q(e){return e.name.trim().length>0&&e.targetIds.length>0}function J(e,t){return e.appliesTo.includes(t)}function je(e){if(e==null)return!0;if(Array.isArray(e))return e.length===0;if(typeof e==`string`)return e.length===0||e===`any`;if(typeof e==`number`)return!Number.isFinite(e);if(typeof e==`object`){if(`ids`in e){let t=e.ids;return!Array.isArray(t)||t.length===0}if(`values`in e){let t=e.values;return!Array.isArray(t)||t.length===0}return!1}return!1}function Me(e,t,n){let r=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&J(e,t)).map(e=>e.id)),i={};for(let[t,n]of Object.entries(e))r!==null&&!r.has(t)||je(n)||(i[t]=n);return i}function Ne(e){return e!==void 0&&e.windows.length>0}function Y(e,t,n=[]){let r=e.templateTitle.trim(),i=e.templateBody.trim(),a=r.length>0||i.length>0?{...r.length>0?{title:r}:{},...i.length>0?{body:i}:{}}:void 0,o=(n.length===0||n.some(t=>t.id===`schedule`&&J(t,e.delivery)))&&Ne(e.schedule)?e.schedule:void 0;return{name:e.name.trim(),enabled:e.enabled,delivery:e.delivery,conditions:Me(e.conditions,e.delivery,n),...o?{schedule:o}:{},targets:e.targetIds.map(t=>{let n=e.targetParams[t];return n&&Object.keys(n).length>0?{targetId:t,params:n}:{targetId:t}}),media:{attach:e.mediaAttach},throttle:t?.throttle??{cooldownSec:60,scope:`rule-device`},priority:e.priority,...a?{template:a}:{}}}p();var Pe=[{id:`scope`,label:`Scope`},{id:`class`,label:`Classes`},{id:`zones`,label:`Zones`},{id:`quality`,label:`Quality`},{id:`label`,label:`Identity & plates`},{id:`device`,label:`Device event`},{id:`package`,label:`Package`},{id:`schedule`,label:`Schedule`}],Fe=`block text-[11px] font-medium text-foreground`,X=`text-[10px] text-foreground-subtle mt-0.5`;function Ie({catalog:e,delivery:t,conditions:n,schedule:r,cameras:i,onConditionsChange:a,onScheduleChange:o}){let s=(e,t)=>{let r={...n};t===void 0?delete r[e]:r[e]=t,a(r)};return b(`div`,{className:`space-y-4`,children:Pe.map(t=>({...t,descriptors:e.filter(e=>e.group===t.id)})).filter(e=>e.descriptors.length>0).map(e=>m(`div`,{className:`space-y-2.5`,children:[b(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:e.label}),e.descriptors.map(e=>{let a=J(e,t);return m(`div`,{className:a?``:`opacity-50`,"data-testid":`condition-${e.id}`,children:[m(`div`,{className:`flex items-center justify-between gap-2`,children:[b(`label`,{className:Fe,children:e.label}),!a&&m(d,{variant:`default`,children:[`not for `,e.appliesTo.join(` / `)]})]}),a?b(Le,{descriptor:e,conditions:n,schedule:r,cameras:i,onFieldChange:s,onScheduleChange:o}):b(`p`,{className:X,children:`Not evaluated for the selected trigger — switch the trigger to use it.`}),a&&e.description&&b(`p`,{className:X,children:e.description})]},e.id)})]},e.id))})}function Le({descriptor:e,conditions:t,schedule:n,cameras:r,onFieldChange:i,onScheduleChange:a}){switch(e.valueType){case`deviceIdList`:return b(Ke,{cameras:r,value:t.devices??[],onChange:e=>i(`devices`,e.length>0?e:void 0)});case`stringList`:{if(!ze(e.id))return null;let n=e.id;return b(Z,{value:He(t,n),placeholder:`Add value…`,onChange:e=>i(n,e.length>0?e:void 0)})}case`zoneIdList`:return b(Z,{value:t.zonesExclude??[],placeholder:`Zone id…`,onChange:e=>i(`zonesExclude`,e.length>0?e:void 0)});case`number01`:{if(!Ve(e.id))return null;let n=e.id;return b(Q,{value:Ue(t,n),min:0,max:1,step:.05,onChange:e=>i(n,e)})}case`number`:return b(Q,{value:t.minDwellSeconds,min:0,step:1,onChange:e=>i(`minDwellSeconds`,e)});case`sourceSelect`:return b(u,{value:t.source??`any`,options:Ee.map(e=>({value:e.value,label:e.label})),onChange:e=>i(`source`,We(e.target.value))});case`packagePhase`:return b(u,{value:t.packagePhase??``,options:[{value:``,label:`— any phase —`},...K.map(e=>({value:e.value,label:e.label}))],onChange:e=>i(`packagePhase`,Ge(e.target.value))});case`zoneSelection`:return b(qe,{value:t.zones,onChange:e=>i(`zones`,e)});case`plateMatcher`:return b(Je,{value:t.plates,onChange:e=>i(`plates`,e)});case`schedule`:return b(Qe,{value:n,onChange:a});default:return null}}var Re={classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,zonesExclude:!0,eventTypeTokens:!0,sensorKinds:!0};function ze(e){return Object.prototype.hasOwnProperty.call(Re,e)}var Be={minConfidence:!0,minImportance:!0,minLabelConfidence:!0};function Ve(e){return Object.prototype.hasOwnProperty.call(Be,e)}function He(e,t){let n=e[t];return Array.isArray(n)?n:[]}function Ue(e,t){let n=e[t];return typeof n==`number`?n:void 0}function We(e){if(e===`pipeline`||e===`onboard`||e===`sensor`||e===`any`)return e}function Ge(e){return K.find(t=>t.value===e)?.value}function Ke({cameras:e,value:t,onChange:n}){if(e.length===0)return b(`p`,{className:X,children:`No cameras available — the rule applies to all devices.`});let r=e=>n(t.includes(e)?t.filter(t=>t!==e):[...t,e]);return b(`div`,{className:`mt-1 max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:e.map(e=>m(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[b(`input`,{type:`checkbox`,checked:t.includes(e.id),onChange:()=>r(e.id),className:`accent-primary`}),b(`span`,{className:`flex-1 truncate`,children:e.name})]},e.id))})}function Z({value:e,placeholder:t,onChange:n}){let[r,i]=v(``),a=()=>{let t=r.trim();if(t.length===0||e.includes(t)){i(``);return}n([...e,t]),i(``)},o=t=>n(e.filter(e=>e!==t));return m(`div`,{className:`mt-1 space-y-1.5`,children:[e.length>0&&b(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>m(`span`,{className:`inline-flex items-center gap-1 rounded bg-surface-hover px-1.5 py-0.5 text-[11px] text-foreground`,children:[e,b(`button`,{type:`button`,onClick:()=>o(e),"aria-label":`remove ${e}`,className:`text-foreground-subtle hover:text-danger`,children:b(ee,{className:`h-3 w-3`})})]},e))}),b(f,{value:r,placeholder:t,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),a())},onBlur:a})]})}function Q({value:e,min:t,max:n,step:r,onChange:i}){return m(`div`,{className:`mt-1 flex items-center gap-2`,children:[b(f,{type:`number`,value:e??``,min:t,max:n,step:r,className:`max-w-[8rem]`,onChange:e=>{let t=e.target.value;if(t===``){i(void 0);return}let n=Number(t);i(Number.isFinite(n)?n:void 0)}}),e!==void 0&&n!==void 0&&b(`input`,{type:`range`,min:t,max:n,step:r,value:e,onChange:e=>i(Number(e.target.value)),className:`flex-1 accent-primary`,"aria-label":`value`})]})}function qe({value:e,onChange:t}){let n=e?.ids??[],r=e?.match??`any`,i=e=>t(e.length>0?{ids:e,match:r}:void 0),a=e=>t(n.length>0?{ids:n,match:e}:void 0);return m(`div`,{className:`mt-1 space-y-1.5`,children:[b(`div`,{className:`max-w-[10rem]`,children:b(u,{value:r,options:De.map(e=>({value:e.value,label:e.label})),onChange:e=>a(e.target.value===`all`?`all`:`any`)})}),b(Z,{value:n,placeholder:`Zone id…`,onChange:i})]})}function Je({value:e,onChange:t}){let n=e?.values??[],r=e?.maxDistance??1,i=e=>t(e.length>0?{values:e,maxDistance:r}:void 0),a=e=>t(n.length>0?{values:n,maxDistance:e}:void 0);return m(`div`,{className:`mt-1 space-y-1.5`,children:[b(Z,{value:n,placeholder:`Plate text…`,onChange:i}),m(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Max distance`,b(f,{type:`number`,min:0,max:3,step:1,value:r,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);a(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}var Ye=[{value:1,label:`Mon`},{value:2,label:`Tue`},{value:3,label:`Wed`},{value:4,label:`Thu`},{value:5,label:`Fri`},{value:6,label:`Sat`},{value:0,label:`Sun`}];function $(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function Xe(e){let[t,n]=e.split(`:`),r=Number(t)*60+Number(n);return Number.isFinite(r)?Math.max(0,Math.min(1439,r)):0}function Ze(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function Qe({value:e,onChange:t}){let n=e?.windows??[],r=e?.invert??!1,i=(n,r)=>{if(n.length===0){t(void 0);return}t({windows:n,...r?{invert:!0}:{},...e?.timezone?{timezone:e.timezone}:{}})},a=()=>i([...n,Ze()],r),o=e=>i(n.filter((t,n)=>n!==e),r),s=(e,t)=>i(n.map((n,r)=>r===e?t:n),r);return m(`div`,{className:`mt-1 space-y-2`,children:[n.length===0?b(`p`,{className:X,children:`Always active — add a window to restrict when the rule fires.`}):n.map((e,t)=>b($e,{window:e,onChange:e=>s(t,e),onRemove:()=>o(t)},t)),m(`div`,{className:`flex items-center gap-3`,children:[m(`button`,{type:`button`,onClick:a,className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[b(D,{className:`h-3 w-3`}),` Add window`]}),n.length>0&&m(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[b(`input`,{type:`checkbox`,checked:r,onChange:e=>i([...n],e.target.checked),className:`accent-primary`}),`Active outside the windows`]})]})]})}function $e({window:e,onChange:t,onRemove:n}){let r=n=>{let r=e.days.includes(n)?e.days.filter(e=>e!==n):[...e.days,n];r.length!==0&&t({...e,days:r})};return m(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[m(`div`,{className:`flex items-center gap-2 text-xs`,children:[b(`input`,{type:`time`,value:$(e.startMinute),onChange:n=>t({...e,startMinute:Xe(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),b(`span`,{className:`text-foreground-subtle`,children:`→`}),b(`input`,{type:`time`,value:$(e.endMinute),onChange:n=>t({...e,endMinute:Xe(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),b(`span`,{className:`flex-1`}),b(`button`,{type:`button`,onClick:n,"aria-label":`Remove window`,className:`text-foreground-subtle hover:text-danger`,children:b(F,{className:`h-3.5 w-3.5`})})]}),b(`div`,{className:`flex flex-wrap gap-1`,children:Ye.map(t=>b(`button`,{type:`button`,onClick:()=>r(t.value),className:`rounded px-1.5 py-0.5 text-[10px] ${e.days.includes(t.value)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:t.label},t.value))})]})}p();var et=[`notificationRules`,`listRules`],tt=[`notificationOutput`,`listTargets`,`forRules`],nt=[`notificationRules`,`getConditionCatalog`],rt=[`deviceManager`,`listAll`,`forRules`];function it(){let t=S(),[a,o]=v({mode:`closed`}),[s,c]=v(null),l=g({queryKey:et,queryFn:async()=>(await t.trpcClient.notificationRules.listRules.query({})).rules}),u=g({queryKey:tt,queryFn:()=>t.trpcClient.notificationOutput.listTargets.query({})}),f=g({queryKey:nt,queryFn:async()=>(await t.trpcClient.notificationRules.getConditionCatalog.query({})).catalog}),p=g({queryKey:rt,queryFn:async()=>(await t.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===x.Camera).map(e=>({id:e.id,name:e.name}))}),_=h(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.name);return e},[u.data]),C=y({mutationFn:e=>t.trpcClient.notificationRules.setRuleEnabled.mutate(e),onSuccess:()=>void l.refetch()}),T=y({mutationFn:e=>t.trpcClient.notificationRules.deleteRule.mutate({ruleId:e}),onSuccess:()=>{c(null),l.refetch()}}),O=l.data??[];return m(I,{icon:L,title:`Notification Rules`,subtitle:`Author rules that turn detections, doorbell presses and package events into notifications. Each rule picks a trigger, matches conditions and fans out to one or more delivery targets.`,actions:m(n,{size:`sm`,type:`button`,onClick:()=>o({mode:`form`,rule:null}),children:[b(D,{className:`h-3.5 w-3.5`}),`New rule`]}),children:[l.isLoading&&b(`div`,{className:`flex items-center justify-center py-16`,children:b(M,{className:`h-6 w-6 animate-spin text-primary`})}),l.isError&&!l.isLoading&&b(e,{title:`Failed to load rules`,message:l.error instanceof Error?l.error.message:`Unknown error`,onRetry:()=>void l.refetch()}),!l.isLoading&&!l.isError&&O.length===0&&b(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification rules yet. Click "New rule" to author one.`}),O.length>0&&b(i,{children:b(`ul`,{className:`divide-y divide-border`,children:O.map(e=>{let t=e.targets.length,i=e.targets[0]?_.get(e.targets[0].targetId)??e.targets[0].targetId:null,a=s===e.id;return m(`li`,{className:`flex flex-wrap items-center gap-3 px-4 py-2.5`,children:[m(`div`,{className:`min-w-0 flex-1`,children:[b(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),m(`div`,{className:`text-[11px] text-foreground-subtle flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[b(`span`,{children:Ce(e.delivery)}),b(`span`,{"aria-hidden":!0,children:`·`}),m(`span`,{children:[t,` target`,t===1?``:`s`,i&&t===1?` (${i})`:``]}),b(`span`,{"aria-hidden":!0,children:`·`}),m(`span`,{children:[`priority `,e.priority]})]})]}),!e.enabled&&b(d,{variant:`warning`,children:`disabled`}),b(r,{checked:e.enabled,onCheckedChange:t=>C.mutate({ruleId:e.id,enabled:t}),"aria-label":`toggle ${e.name}`}),b(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>o({mode:`form`,rule:e}),title:`Edit`,children:b(E,{className:`h-3.5 w-3.5`})}),b(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>o({mode:`form`,rule:{...e,id:``,name:`${e.name} (copy)`}}),title:`Duplicate`,children:b(w,{className:`h-3.5 w-3.5`})}),a?m(`span`,{className:`flex items-center gap-1.5`,children:[m(n,{size:`sm`,variant:`danger`,type:`button`,disabled:T.isPending,onClick:()=>T.mutate(e.id),children:[T.isPending&&b(M,{className:`h-3.5 w-3.5 animate-spin`}),`Confirm`]}),b(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>c(null),children:`Cancel`})]}):b(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>c(e.id),title:`Delete`,children:b(F,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),a.mode===`form`&&b(at,{rule:a.rule,targets:u.data??[],catalog:f.data??[],cameras:p.data??[],onCancel:()=>o({mode:`closed`}),onSaved:()=>{o({mode:`closed`}),l.refetch()}})]})}function at({rule:e,targets:t,catalog:i,cameras:s,onSaved:c,onCancel:l}){let p=S(),h=e!=null&&e.id.length>0,[g,_]=v(()=>e?Ae(e):ke()),[x,C]=v(null),[w,T]=v(null),E=e=>_(t=>({...t,...e})),D=h&&e?{throttle:e.throttle}:void 0,O=y({mutationFn:async()=>{let t=Y(g,D,i);h&&e?await p.trpcClient.notificationRules.updateRule.mutate({ruleId:e.id,patch:t}):await p.trpcClient.notificationRules.createRule.mutate({rule:t})},onSuccess:c,onError:e=>C(e instanceof Error?e.message:`Save failed`)}),k=y({mutationFn:async()=>{let e=Y(g,D,i);return(await p.trpcClient.notificationRules.testRule.mutate({rule:e,lookbackMinutes:60})).results},onMutate:()=>T(null),onSuccess:e=>T(e),onError:e=>C(e instanceof Error?e.message:`Test failed`)}),A=g.targetIds.map(e=>t.find(t=>t.id===e)?.name??e),j=e=>E({targetIds:g.targetIds.includes(e)?g.targetIds.filter(t=>t!==e):[...g.targetIds,e]}),N=W.find(e=>e.value===g.delivery)?.hint;return b(a,{open:!0,onOpenChange:e=>!e&&l(),children:m(o,{width:`lg`,placement:`sheet-on-mobile`,children:[m(`div`,{className:`flex items-center justify-between mb-3`,children:[m(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[b(L,{className:`h-4 w-4 text-foreground-subtle`}),h?`Edit ${e?.name}`:`New notification rule`]}),b(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:l,children:`Cancel`})]}),x&&b(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger mb-3`,children:x}),m(`div`,{className:`space-y-4`,children:[m(`div`,{className:`flex items-end gap-3`,children:[m(`div`,{className:`min-w-0 flex-1`,children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),b(f,{value:g.name,onChange:e=>E({name:e.target.value}),placeholder:`e.g. Front door package`})]}),m(`label`,{className:`flex items-center gap-2 pb-1.5 text-[11px] font-medium text-foreground`,children:[b(r,{checked:g.enabled,onCheckedChange:e=>E({enabled:e}),"aria-label":`enabled`}),`Enabled`]})]}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Trigger`}),b(u,{value:g.delivery,onChange:e=>{let t=we(e.target.value);t&&E({delivery:t})},options:W.map(e=>({value:e.value,label:e.label}))}),N&&b(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:N})]}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Delivery targets`}),t.length===0?b(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No delivery targets configured. Add one under the Targets tab first.`}):b(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:t.map(e=>m(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[b(`input`,{type:`checkbox`,checked:g.targetIds.includes(e.id),onChange:()=>j(e.id),className:`accent-primary`}),b(`span`,{className:`flex-1 truncate`,children:e.name}),!e.enabled&&b(d,{variant:`warning`,children:`disabled`})]},e.id))})]}),m(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Priority`}),b(u,{value:String(g.priority),onChange:e=>E({priority:Number(e.target.value)}),options:Oe.map(e=>({value:String(e.value),label:e.label}))})]}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Media attachment`}),b(u,{value:g.mediaAttach,onChange:e=>{let t=Te(e.target.value);t&&E({mediaAttach:t})},options:G.map(e=>({value:e.value,label:e.label}))}),b(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:G.find(e=>e.value===g.mediaAttach)?.description})]})]}),m(`div`,{className:`space-y-2`,children:[m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notification title`}),b(f,{value:g.templateTitle,onChange:e=>E({templateTitle:e.target.value}),placeholder:`{{camera}} — {{class}}`})]}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notification body`}),b(`textarea`,{value:g.templateBody,onChange:e=>E({templateBody:e.target.value}),rows:2,placeholder:`{{label}} seen in {{zone}} at {{time}}`,className:`w-full rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),m(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Leave blank to use the backend default text. Supported variables include`,` `,b(`code`,{children:`{{camera}}`}),`, `,b(`code`,{children:`{{class}}`}),`, `,b(`code`,{children:`{{label}}`}),`,`,` `,b(`code`,{children:`{{zone}}`}),`, `,b(`code`,{children:`{{confidence}}`}),`, `,b(`code`,{children:`{{time}}`}),`.`]})]}),m(`div`,{className:`rounded-md border border-border px-3 py-3`,children:[b(`div`,{className:`mb-2 text-[11px] font-semibold text-foreground`,children:`Conditions`}),i.length===0?b(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Condition catalog unavailable — this rule matches on its trigger and targets alone.`}):b(Ie,{catalog:i,delivery:g.delivery,conditions:g.conditions,schedule:g.schedule,cameras:s,onConditionsChange:e=>E({conditions:e}),onScheduleChange:e=>E({schedule:e})})]}),m(`div`,{className:`rounded-md border border-border px-3 py-3`,children:[m(`div`,{className:`flex items-center justify-between gap-2`,children:[b(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Test rule`}),m(n,{size:`sm`,variant:`outline`,type:`button`,disabled:k.isPending||!q(g),onClick:()=>{C(null),k.mutate()},children:[k.isPending?b(M,{className:`h-3.5 w-3.5 animate-spin`}):b(ne,{className:`h-3.5 w-3.5`}),`Dry-run (last 60 min)`]})]}),b(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`Evaluate the CURRENT (unsaved) rule against recently persisted records — no notification is sent.`}),w!==null&&b(ot,{delivery:g.delivery,results:w,targetNames:A})]})]}),m(`div`,{className:`flex justify-end gap-2 mt-4`,children:[b(n,{variant:`secondary`,size:`sm`,type:`button`,onClick:l,children:`Cancel`}),m(n,{size:`sm`,type:`button`,disabled:O.isPending||!q(g),onClick:()=>{C(null),O.mutate()},children:[O.isPending&&b(M,{className:`h-3.5 w-3.5 animate-spin`}),h?`Save changes`:`Create rule`]})]})]})})}function ot({delivery:e,results:t,targetNames:n}){if(e===`device-event`)return b(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:`Device-event rules cannot be dry-run: the sensor-event store has no cross-device scan surface, so a test returns no candidate records. The rule still fires live on a matching doorbell press / sensor change.`});if(t.length===0)return b(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:`No records in the last 60 minutes matched — nothing to evaluate.`});let r=t.filter(e=>e.wouldFire).length;return m(`div`,{className:`mt-2 space-y-1.5`,children:[m(`div`,{className:`text-[11px] text-foreground-subtle`,children:[r,` of `,t.length,` evaluated record`,t.length===1?``:`s`,` would fire.`]}),b(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:t.slice(0,50).map(e=>m(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5 text-[11px]`,children:[e.wouldFire?b(C,{className:`h-3.5 w-3.5 shrink-0 text-success`}):b(j,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),b(`span`,{className:`w-32 shrink-0 text-foreground-subtle`,children:new Date(e.timestamp).toLocaleString()}),m(`span`,{className:`w-14 shrink-0 text-foreground-subtle`,children:[`#`,e.deviceId]}),b(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.label??e.className??`object`}),e.wouldFire?m(`span`,{className:`shrink-0 truncate text-success`,children:[`→ `,n.join(`, `)||`targets`]}):e.failedCondition&&m(`span`,{className:`shrink-0 text-foreground-subtle`,children:[`failed: `,e.failedCondition]})]},e.recordId))})]})}p();var st=[{value:1,label:`Last hour`},{value:24,label:`Last 24 hours`},{value:168,label:`Last 7 days`},{value:0,label:`All time`}],ct=[{value:``,label:`Any status`},{value:`pending`,label:`Pending`},{value:`sent`,label:`Sent`},{value:`dead`,label:`Dead`}],lt=[50,100,250,500];function ut(){return{ruleId:``,deviceId:``,status:``,windowHours:24,limit:100}}function dt(e){return e===`pending`||e===`sent`||e===`dead`?e:void 0}function ft(e){switch(e){case`pending`:return`info`;case`sent`:return`success`;case`dead`:return`danger`}}function pt(){let e=S(),[t,n]=v(ut),r=e=>n(t=>({...t,...e})),a=g({queryKey:[`notificationRules`,`listRules`,`forHistory`],queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),o=g({queryKey:[`deviceManager`,`listAll`,`forHistory`],queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===x.Camera).map(e=>({id:e.id,name:e.name}))}),s=Date.now(),c=g({queryKey:[`notificationRules`,`getHistory`,t],retry:!1,queryFn:async()=>{let n=t.windowHours>0?s-t.windowHours*36e5:void 0;return(await e.trpcClient.notificationRules.getHistory.query({filter:{limit:t.limit,...t.ruleId?{ruleId:t.ruleId}:{},...t.deviceId?{deviceId:Number(t.deviceId)}:{},...dt(t.status)?{status:dt(t.status)}:{},...n===void 0?{}:{since:n}}})).entries}}),l=h(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),d=e=>l.get(e)??`Camera #${String(e)}`,f=c.data??[],p=c.isError;return m(I,{icon:T,title:`Delivery history`,subtitle:`A searchable log of every notification the rules delivered (or failed to deliver).`,children:[m(`div`,{className:`mb-4 grid grid-cols-2 gap-2 sm:grid-cols-5`,children:[m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Rule`}),b(u,{value:t.ruleId,onChange:e=>r({ruleId:e.target.value}),options:[{value:``,label:`All rules`},...(a.data??[]).map(e=>({value:e.id,label:e.name}))]})]}),m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Camera`}),b(u,{value:t.deviceId,onChange:e=>r({deviceId:e.target.value}),options:[{value:``,label:`All cameras`},...(o.data??[]).map(e=>({value:String(e.id),label:e.name}))]})]}),m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Status`}),b(u,{value:t.status,onChange:e=>r({status:e.target.value}),options:ct.map(e=>({value:e.value,label:e.label}))})]}),m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Window`}),b(u,{value:String(t.windowHours),onChange:e=>r({windowHours:Number(e.target.value)}),options:st.map(e=>({value:String(e.value),label:e.label}))})]}),m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Limit`}),b(u,{value:String(t.limit),onChange:e=>r({limit:Number(e.target.value)}),options:lt.map(e=>({value:String(e),label:String(e)}))})]})]}),c.isLoading&&b(`div`,{className:`flex items-center justify-center py-16`,children:b(M,{className:`h-6 w-6 animate-spin text-primary`})}),p&&!c.isLoading&&b(i,{children:m(`div`,{className:`flex flex-col items-center gap-2 px-4 py-14 text-center`,children:[b(T,{className:`h-6 w-6 text-foreground-subtle`}),b(`div`,{className:`text-sm font-medium text-foreground`,children:`Delivery history requires a server update`}),b(`p`,{className:`max-w-md text-xs text-foreground-subtle`,children:`The history query is not available on this hub yet. It becomes queryable after the next server update ships the notification-center history endpoint. Rules still deliver and record their outcome in the meantime.`}),m(`button`,{type:`button`,onClick:()=>void c.refetch(),className:`mt-1 inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:[b(O,{className:`h-3 w-3`}),` Retry`]})]})}),!p&&!c.isLoading&&f.length===0&&b(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:`No deliveries match these filters.`}),!p&&f.length>0&&b(i,{children:b(`ul`,{className:`divide-y divide-border`,children:f.map(e=>b(mt,{entry:e,cameraName:d},e.id))})})]})}function mt({entry:e,cameraName:t}){let n=new Date(e.createdAt).toLocaleString(),r=e.subject.label??e.subject.className;return b(`li`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-4 py-2.5`,children:m(`div`,{className:`min-w-0 flex-1`,children:[m(`div`,{className:`flex items-center gap-2`,children:[b(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.ruleName}),b(d,{variant:ft(e.status),children:e.status})]}),m(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[b(`span`,{children:n}),b(`span`,{"aria-hidden":!0,children:`·`}),b(`span`,{children:t(e.deviceId)}),b(`span`,{"aria-hidden":!0,children:`·`}),b(`span`,{children:r}),e.subject.confidence!==void 0&&m(_,{children:[b(`span`,{"aria-hidden":!0,children:`·`}),m(`span`,{children:[Math.round(e.subject.confidence*100),`%`]})]}),e.attempts>1&&m(_,{children:[b(`span`,{"aria-hidden":!0,children:`·`}),m(`span`,{children:[e.attempts,` attempts`]})]})]}),e.status===`dead`&&e.error&&b(`div`,{className:`mt-1 rounded border border-danger/30 bg-danger/10 px-2 py-1 text-[11px] text-danger`,children:e.error})]})})}function ht(){return b(`div`,{className:`flex flex-col p-4`,children:b(te,{tabs:[{id:`targets`,label:`Targets`,icon:N,content:b(be,{})},{id:`rules`,label:`Rules`,icon:L,content:b(it,{})},{id:`history`,label:`History`,icon:T,content:b(pt,{})}]})})}export{ht as NotificationsPage,ht as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$r as e,Ci as t,Do as n,Ei as r,Ha as i,Ii as a,Ja as o,Ka as s,La as c,Mi as l,Ni as u,Oo as d,Pi as f,Qr as p,Si as m,T as h,Ti as g,Ua as _,Va as v,Vr as y,Wa as b,Xa as x,Za as S,_ as C,_i as w,ai as T,bi as E,ci as D,di as O,ei as k,ft as A,g as j,gi as M,ii as N,ji as ee,li as P,lt as te,mi as ne,ni as re,oi as ie,qa as ae,ri as oe,si as se,ti as ce,ut as le,vi as ue,wi as de,xi as fe,xo as pe,yi as me}from"./src-Bwet06Ih.js";import{I as he,K as ge,Q as F,S as I,T as _e,W as L,b as R,o as z,q as B,x as V,z as H}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{G as ve,K as ye,X as be}from"./src-GxiMH1Sc.js";import{c as xe,n as U,o as Se,r as Ce,s as we,t as Te}from"./NodeInferenceDevices-DlG9HB9Y.js";import{t as Ee}from"./download-NKkCvEeB.js";import{i as De}from"./AddLocationWizard-BsfRBmG0.js";import{n as Oe,r as ke,t as Ae}from"./zap-DWRzzBU1.js";import{t as je}from"./pencil-Ik1l3G_8.js";import{t as Me}from"./plus-B0OPxy2A.js";import{t as Ne}from"./radio-BtzRHQBo.js";import{t as Pe}from"./refresh-cw-D92Y26QW.js";import{t as Fe}from"./search-BUbY58eR.js";import{t as Ie}from"./server-BwAvkFi_.js";import{t as Le}from"./square-check-big-tgpBR4IT.js";import{t as Re}from"./square-Ckdv6ORu.js";import{E as ze,I as Be,J as Ve,L as He,M as Ue,N as We,P as Ge,S as W,T as Ke,W as qe,i as Je,j as G,o as Ye,s as Xe}from"./index-RegSp4ae.js";import{t as Ze}from"./AdminPage-BwmGKnRf.js";import{t as Qe}from"./useEventInvalidation-BslmDCfY.js";import{r as $e,t as et}from"./build-cluster-graph-BN5pfFK1.js";import{n as tt}from"./format-size-CO9d3C3-.js";import{t as nt}from"./NodeAddonsSettingsPanel-DY-AneF0.js";import{n as rt,t as it}from"./ClusterRecordingTab-ZjVaVby-.js";var at=qe(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),ot=qe(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),st=qe(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);F();function ct(e){return e}function lt(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function ut(e,t){return typeof e==`boolean`?e:ct(t)}function dt(e,t){return{pipeline:ut(lt(e,`detect`),t),audio:ut(lt(e,`audio`),t),ingest:ut(lt(e,`ingest`),t)}}function ft(e,t,n){let r=e?.find(e=>e.nodeId===t);return dt(r?.settings,n)}function pt({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:r}=y(void 0),{data:i}=M(void 0),{data:a}=ue(void 0),o=new Map;for(let e of i??[])o.set(e.agentNodeId,(o.get(e.agentNodeId)??0)+1);let s=r??[],c=s.filter(e=>e.isOnline).length,l=s.filter(e=>!e.isOnline).length;return I(`div`,{className:`flex flex-col h-full`,children:[I(`button`,{type:`button`,onClick:()=>t(Sr),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[V(Ke,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[V(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),V(`div`,{className:`flex-1 overflow-y-auto`,children:s.map(n=>{let r=e===n.id,i=o.get(n.id)??0,s=n.isHub?Ie:G,c=ft(a,n.id,n.isHub),l=n.isOnline?null:d($e(n.lastSeen));return I(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[V(s,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),I(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[I(`span`,{children:[n.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),i>0&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[V(Oe,{className:`h-2.5 w-2.5`}),i]})]}),!n.isOnline&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`text-destructive`,children:[`offline`,l===null?``:` · ${l}`]})]})]}),I(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[V(pe,{variant:c.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:c.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),V(pe,{variant:c.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:c.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),I(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[I(`span`,{children:[c,` online`]}),l>0&&I(`span`,{className:`text-destructive`,children:[l,` offline`]})]})]})}function mt({nodeId:e,refreshToken:t}){let{data:n}=y(void 0),r=n?.find(t=>t.id===e),a=i(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?I(`div`,{className:`px-6 py-4 border-b border-border`,children:[I(`div`,{className:`flex items-center gap-2 mb-1`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[V(`span`,{children:r.cpuModel??`CPU`}),V(`span`,{children:`•`}),I(`span`,{children:[r.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),V(`span`,{children:`•`}),I(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),V(`span`,{children:`•`}),I(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&I(R,{children:[V(`span`,{children:`•`}),V(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):V(`div`,{className:`px-6 py-4 border-b border-border`,children:I(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function ht({refreshToken:e,nodeId:t}){let[n,r]=B(new Map),{nodes:i}=v();b(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:a}=P(void 0),o=L(()=>{let e=new Map;for(let t of a??[])e.set(t.nodeId,t.deviceCount);return e},[a]),s=L(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),c=L(()=>{let e=new Map;for(let t of i)e.set(t.id,t.shortName);return e},[i]),l=L(()=>{let e=0,t=0,n=0,r=0,a=0;for(let i of s.values())e+=i.attachedCameras,t+=i.activeCameras,n+=i.totalFps,r+=i.totalInferenceWeighted,a+=i.queueDepth;let o=e>0?r/e:0;return{totalAgents:i.length,onlineAgents:i.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:o,queueDepth:a,totalFps:n}},[s,i]);if(t){let e=s.get(t);return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[V(K,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),V(K,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),V(K,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),V(K,{label:`Queue`,value:e?String(e.queueDepth):`—`}),V(K,{label:`Audio`,value:String(o.get(t)??`—`)})]})]})}let u=[...s.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[V(K,{label:`Total agents`,value:`${l.onlineAgents}/${l.totalAgents}`}),V(K,{label:`Active / Attached`,value:`${l.activeCameras}/${l.attachedCameras}`}),V(K,{label:`Total FPS`,value:l.totalFps.toFixed(1)}),V(K,{label:`Avg inference ms`,value:l.avgInferenceTimeMs.toFixed(0)}),V(K,{label:`Queue depth`,value:String(l.queueDepth)})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[480px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),V(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),V(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),V(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),V(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),V(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),I(`tbody`,{children:[u.map(([e,t])=>I(`tr`,{className:`border-t border-border`,children:[V(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:c.get(e)??e}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:o.get(e)??`—`})]},e)),u.length===0&&V(`tr`,{children:V(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function K({label:e,value:t}){return I(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[V(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),V(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}F();var gt={active:!1,pinned:!1,nodeId:null,reason:``},_t=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],vt={pipeline:G,decoder:ze,audio:ke},yt={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function bt({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let r=z(),[i,a]=B(null),[o,s]=B(null),[c,d]=B(new Map);Qe([`pipelineOrchestrator`,`getPipelineAssignments`],_t),Qe([`pipelineOrchestrator`,`getAudioAssignments`],_t),Qe([`pipelineOrchestrator`,`getCameraStatuses`],_t);let{data:f}=M(void 0),{data:p}=D(void 0),{data:m}=O({},{enabled:e===`agent`}),{nodes:g}=v(),{data:_}=Se();b(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&d(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),H(()=>{if(c.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[c.size]);let y=L(()=>{let e=new Map;for(let t of _??[])e.set(t.id,t.name);return e},[_]),x=L(()=>{if(e===`agent`){let e=[];for(let n of m??[]){let r=n.assignment,i=(e,n,r)=>({active:e!==null&&e===t,pinned:n,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:n.deviceId,deviceName:y.get(n.deviceId)??`Device ${n.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:y.get(e)??`Device ${e}`,pipeline:gt,decoder:gt,audio:gt};return n.set(e,r),r};for(let i of f??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let e of p??[]){let t=r(e.deviceId);n.set(e.deviceId,{...t,audio:{active:!0,pinned:e.pinned,nodeId:e.nodeId,reason:`capacity`}})}let i=[...n.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[f,p,m,y,e,t]),S=L(()=>(g??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[g]),C=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},w=ie({onSuccess:C}),E=u({onSuccess:C}),k=T({onSuccess:C}),A=l({onSuccess:C}),j=(e,t,n)=>{t===`pipeline`?w.mutate({deviceId:e,agentNodeId:n}):k.mutate({deviceId:e,nodeId:n}),a(null)},N=(e,t)=>{t===`pipeline`?E.mutate({deviceId:e}):A.mutate({deviceId:e}),a(null)};return V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&V(`th`,{className:`w-10`}),V(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?I(R,{children:[V(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),V(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):I(R,{children:[V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),V(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),I(`tbody`,{children:[x.map(t=>{let r=c.get(t.deviceId),l=o===t.deviceId;return I(_e.Fragment,{children:[I(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&V(`td`,{className:`px-2 py-2 align-middle`,children:V(`button`,{type:`button`,onClick:()=>s(l?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":l?`Collapse broker details`:`Expand broker details`,children:V(l?Be:Ge,{className:`h-3.5 w-3.5`})})}),I(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[V(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?I(R,{children:[V(`td`,{className:`px-3 py-2 align-middle`,children:V(St,{state:t.pipeline,onlineNodes:S,pending:w.isPending||E.isPending,onChange:e=>{e===`auto`?N(t.deviceId,`pipeline`):j(t.deviceId,`pipeline`,e)}})}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(Ct,{state:t.pipeline,deviceId:t.deviceId})})]}):I(R,{children:[V(Tt,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:S,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`pipeline`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>a(null),onMove:e=>j(t.deviceId,`pipeline`,e),onUnpin:()=>N(t.deviceId,`pipeline`)}),V(Tt,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:S,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),V(Tt,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:S,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`audio`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>a(null),onMove:e=>j(t.deviceId,`audio`,e),onUnpin:()=>N(t.deviceId,`audio`)})]}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(kt,{snap:r})})]}),l&&!n&&I(`tr`,{className:`bg-surface/50`,children:[V(`td`,{}),I(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&V(xt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),V(h,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})]})]})]},t.deviceId)}),x.length===0&&V(`tr`,{children:V(`td`,{colSpan:n?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function xt({deviceId:e,nodeId:t}){let n=z(),{data:r}=ne({nodeId:t}),{data:i}=w({deviceId:e}),a=ee({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),o=r?.devices??[],s=i?.deviceKey??`auto`,c=s!==`auto`&&!o.some(e=>e.key===s);return I(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[V(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),I(`select`,{value:s,disabled:a.isPending,"aria-label":`Inference device pin`,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[V(`option`,{value:`auto`,children:`Auto (balanced)`}),c&&I(`option`,{value:s,children:[`Pin → `,s,` (not on this node)`]}),o.map(e=>I(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),a.isPending&&V(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function St({state:e,onlineNodes:t,pending:n,onChange:r}){let i=e.pinned&&e.nodeId?e.nodeId:`auto`,a=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return I(`select`,{value:i,disabled:n,"aria-label":`Pipeline placement pin`,onChange:e=>r(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[V(`option`,{value:`auto`,children:`Auto`}),a.map(e=>I(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function Ct({state:e,deviceId:t}){if(!e.active||!e.nodeId)return V(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let n=e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`;return I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,title:e.nodeId,children:e.nodeId}),V(`span`,{className:`truncate ${e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:n,children:n}),V(wt,{deviceId:t,nodeId:e.nodeId})]})}function wt({deviceId:e,nodeId:t}){let n=z(),{data:r}=w({deviceId:e},{refetchOnMount:`always`}),{data:i}=ne({nodeId:t},{refetchOnMount:`always`}),a=ee({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||i===void 0)return V(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let o=i.devices??[],s=o.filter(e=>e.enabled),c=r.deviceKey??`auto`,l=c!==`auto`&&!s.some(e=>e.key===c),u=o.find(e=>e.key===c);return I(`select`,{value:c,disabled:a.isPending,"aria-label":`Inference device pin`,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value}),className:`mt-0.5 w-full min-w-0 rounded border border-border bg-background px-1 py-0.5 text-[10px] text-foreground disabled:opacity-50`,children:[V(`option`,{value:`auto`,children:`Auto (balanced)`}),l&&I(`option`,{value:c,children:[u?`${U(u).label} (${c})`:c,` (not enabled)`]}),s.map(e=>I(`option`,{value:e.key,children:[U(e).label,` · `,e.format]},e.key))]})}function Tt({role:e,state:t,mode:n,onlineNodes:r,readOnly:i=!1,isMenuOpen:a,onToggleMenu:o,onCloseMenu:s,onMove:c,onUnpin:l}){let u=vt[e],d=r.filter(e=>e.id!==(t.nodeId??``)),f=!i&&(t.active||n===`cluster`)&&(d.length>0||t.pinned);return I(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[I(`div`,{className:`flex items-center gap-2 min-w-0`,children:[V(n===`agent`?Et:Dt,{state:t,Icon:u}),V(`div`,{className:`ml-auto shrink-0`,children:f&&V(`button`,{type:`button`,onClick:o,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${yt[e]} actions`,children:V(at,{className:`h-3 w-3 text-foreground-subtle`})})})]}),a&&f&&V(At,{title:yt[e],targets:d,pinned:t.pinned,onMove:c,onUnpin:l,onClose:s})]})}function Et({state:e,Icon:t}){return I(`div`,{className:`flex items-center gap-1.5`,children:[V(e.active?Le:Re,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),V(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&V(st,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Dt({state:e,Icon:t}){return!e.active||!e.nodeId?I(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[V(t,{className:`h-3 w-3`}),V(`span`,{className:`text-[10px] italic`,children:`—`})]}):I(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[V(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),V(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?I(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[V(st,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Ot=`min-h-[3.25rem]`;function kt({snap:e}){if(!e)return V(`div`,{className:`flex items-center ${Ot}`,children:V(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:r,avgInferenceTimeMs:i,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=n(t);return I(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Ot}`,children:[I(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[V(C,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),V(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:r.toFixed(1)}),I(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:i.toFixed(0)}),V(`span`,{children:` ms`}),a>0&&I(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),I(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,V(`span`,{className:`text-foreground`,children:s})]})]})}function At({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=ge(null);return H(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),I(`div`,{ref:o,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[V(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&V(`div`,{className:`py-1`,children:t.map(e=>I(`button`,{type:`button`,onClick:()=>r(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),n&&I(`button`,{type:`button`,onClick:i,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,e.toLowerCase()]}),t.length===0&&!n&&V(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function jt({nodeId:e,refreshToken:t}){return I(`div`,{className:`space-y-6`,children:[V(ht,{refreshToken:t,nodeId:e}),I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),V(bt,{mode:`agent`,nodeId:e,compact:!0})]})}F();function Mt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Nt({nodeId:e,refreshToken:t}){let n=z(),r=oe({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:o}=N({nodeId:e}),s=i(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??o??null,c=s===null;Qe([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:l}=a({nodeId:e}),{values:u}=_(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),d=L(()=>u.filter(e=>e.metrics.phase===`active`).length,[u]),f=t=>{let n=l??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||r.mutate({nodeId:e,engine:t,force:n.length>0})};return I(`div`,{className:`space-y-6`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(s??[]).length,` engine(s) resident in RAM. `,(l??[]).length,` `,`camera(s) attached, `,d,` actively dispatching frames. Refreshes every 5s.`]})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[640px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),V(`th`,{className:`text-left px-3 py-2`,children:`Models`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),V(`th`,{className:`w-20`})]})}),I(`tbody`,{children:[c&&V(`tr`,{children:V(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!c&&(s??[]).map(e=>{let t=e.kind===`warm-override`,n=e.kind===`device-pool`;return I(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:n?`bg-primary/[0.05]`:``}`,children:[V(`td`,{className:`px-3 py-2`,children:I(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:n?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[V(t?ot:n?xe:G,{className:`h-3 w-3`}),t?`warm`:n?`pool`:`runtime`]})}),V(`td`,{className:`px-3 py-2`,children:I(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[V(Ae,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),V(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?V(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>V(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),V(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),V(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?V(`span`,{className:`text-foreground-subtle`,children:Mt(e.idleMs,e.idleTtlMs)}):V(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(l??[]).length}),V(`td`,{className:`px-3 py-2 text-right`,children:n?V(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):I(`button`,{type:`button`,disabled:r.isPending,onClick:()=>f(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[V(Xe,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!c&&(s??[]).length===0&&V(`tr`,{children:V(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[V(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,V(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,V(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),r.isError&&I(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,r.error instanceof Error?r.error.message:`unknown`]})]})}F();var Pt=new Set(be);function Ft(e){return Pt.has(e)}function It(e,t,n){return`${e}/${t}/${n}`}function Lt(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function Rt(e){return{coreml:`Apple Neural Engine / GPU — .mlpackage`,openvino:`Intel CPU / GPU / NPU — .xml`,onnx:`CPU, CUDA, Node.js — .onnx`}[e.format]??`.${e.format}`}function q(e){return e.format}function zt(e,t){let n=0,r=0,i=0;for(let a of e)for(let e of a.addons)for(let a of e.models){let e=a.formats[t];e&&(n++,e.downloaded&&(r++,i+=e.sizeMB))}return{total:n,downloaded:r,downloadedSizeMB:i}}function Bt({addonId:e,model:t,format:n,isActive:r,progress:i,errorMsg:a,onDownload:o,onDelete:s}){let c=t.formats[n];return c?I(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors`,children:[V(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),I(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&I(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[V(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:V(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),I(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),V(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:tt(c.sizeMB)}),a&&I(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[V(We,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?I(`button`,{onClick:s,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[r?V(W,{className:`h-3 w-3 animate-spin`}):V(Xe,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):I(`button`,{onClick:o,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[r?V(W,{className:`h-3 w-3 animate-spin`}):V(Ee,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function Vt({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=B(!1);return I(`div`,{className:`relative`,children:[I(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[V(G,{className:`h-4 w-4 text-primary shrink-0`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:Lt(n)}),q(n)===q(t)&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:Rt(n)})]}),V(Be,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&V(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let i=q(e)===q(n),o=q(e)===q(t);return I(`button`,{type:`button`,onClick:()=>{r(e),a(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${i?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[V(G,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),I(`div`,{className:`flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:Lt(e)}),o&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:Rt(e)})]}),i&&V(Ue,{className:`h-4 w-4 text-primary shrink-0`})]},q(e))})})]})}function Ht({embedded:t=!1,nodeId:n}={}){let r=z(),i=n??`hub`,[a,o]=B(null),[s,c]=B(new Set),[l,u]=B(new Map),[d,f]=B(new Map),[m,h]=B(``),{data:g=[]}=k({nodeId:i}),_=g.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:v}=re({nodeId:i}),y=v,{data:x,isLoading:S}=ce({nodeId:i}),C=e(),w=p();b(`model.download.progress`,e=>{let t=e.data,n=typeof t.modelId==`string`?t.modelId:void 0,i=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;n===void 0||i===void 0||(u(e=>{let t=new Map(e);return i===100||i===-1?t.delete(n):t.set(n,{modelId:n,progress:i,totalMB:a}),t}),i===100&&r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let T=y??{runtime:`node`,backend:`cpu`,format:`onnx`},E=_.find(e=>e.format===a)??T,D=E.format,O=x?.slots??[],A=O.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(e=>e.formats[D]!==void 0)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),j=zt(A,D),M=he(async(e,t,n)=>{if(!Ft(n))return;let a=It(e,t,n);c(e=>new Set([...e,a])),f(e=>{let t=new Map(e);return t.delete(a),t});try{await C.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){f(t=>new Map([...t,[a,e instanceof Error?e.message:`Download failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[C,r,i]),N=he(async(e,t,n)=>{if(!Ft(n))return;let a=It(e,t,n);c(e=>new Set([...e,a])),f(e=>{let t=new Map(e);return t.delete(a),t});try{await w.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){f(t=>new Map([...t,[a,e instanceof Error?e.message:`Delete failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[w,r,i]),ee=he(e=>{o(e.format)},[]),P=m.trim()?A.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(m.toLowerCase())||t.id.toLowerCase().includes(m.toLowerCase())||e.name.toLowerCase().includes(m.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):A,te=I(R,{children:[S&&V(`div`,{className:`flex items-center justify-center py-16`,children:V(W,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!S&&O.length===0&&I(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[V(De,{className:`h-8 w-8 mb-3 opacity-30`}),V(`span`,{className:`text-sm`,children:`No pipeline steps available`}),V(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!S&&O.length>0&&I(R,{children:[V(Vt,{engines:_,activeEngine:T,viewEngine:E,onSelect:ee}),I(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground tabular-nums`,children:j.total}),V(`span`,{className:`ml-1`,children:`compatible models`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success tabular-nums`,children:j.downloaded}),V(`span`,{className:`ml-1`,children:`downloaded`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{className:`tabular-nums`,children:[tt(j.downloadedSizeMB),V(`span`,{className:`ml-1`,children:`on disk`})]})]}),j.total>5&&I(`div`,{className:`relative`,children:[V(Fe,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),V(`input`,{type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:`Search models...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary`})]}),P.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+t.models.filter(e=>e.formats[D]?.downloaded).length,0);return I(`div`,{children:[I(`div`,{className:`flex items-center gap-2 mb-2`,children:[V(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),V(`div`,{className:`flex-1 h-px bg-border`}),I(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=It(e.id,t.id,D);return V(Bt,{addonId:e.id,model:t,format:D,isActive:s.has(n),progress:l.get(t.id),errorMsg:d.get(n),onDownload:()=>M(e.id,t.id,D),onDelete:()=>N(e.id,t.id,D)},`${e.id}/${t.id}`)}))})]},e.id)}),P.length===0&&V(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:m.trim()?I(R,{children:[`No models matching “`,m,`”`]}):I(R,{children:[`No models available for `,Lt(E),` format`]})})]})]});return t?V(`div`,{className:`space-y-4`,children:te}):V(Ze,{children:te})}function Ut({nodeId:e,refreshToken:t}){return V(Ht,{embedded:!0,nodeId:e})}var Wt=`pipeline-runner`,Gt=200;function Kt({nodeId:e}){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(j,{agentId:e,addonId:Wt,limit:Gt,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F(),F();function qt({nodeId:e,title:t}){let{data:r}=Se(),{data:i}=M(void 0),a=L(()=>{let e=new Map;for(let t of r??[])e.set(t.id,t.name);return e},[r]),o=L(()=>{if(!e)return null;let t=new Set;for(let n of i??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,i]),[s,c]=B(new Map);b(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||c(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),H(()=>{if(s.size===0)return;let e=setInterval(()=>{c(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[s.size]);let l=L(()=>{let e=[];for(let t of s.values())o&&!o.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[s,o]);return l.length===0?I(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):I(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[I(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[V(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),V(`span`,{className:`text-[10px] text-foreground-subtle`,children:l.length})]}),V(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>{let t=a.get(e.deviceId)??`#${e.deviceId}`,r=n(e.metrics.phase);return I(`div`,{title:`${t} · ${r.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${r.badgeClass}`,children:[V(C,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),V(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),V(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),V(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}F();function J(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 Jt(e){if(!e)return null;let t=e.modelId!==void 0&&e.modelId!==``?e.modelId:void 0,n=e.settings&&Object.keys(e.settings).length>0?e.settings:void 0;return t===void 0&&n===void 0?null:{...t===void 0?{}:{modelId:t},...n===void 0?{}:{settings:n}}}function Yt({nodeId:e,refreshToken:t}){let n=z(),[r,i]=B(null),[a,c]=B(null),[l,u]=B(``),[d,f]=B(null),p=ne({nodeId:e},{refetchOnMount:`always`}),m=ce({nodeId:e},{refetchOnMount:`always`}),h=p.data?.devices??[],_=g({onSuccess:()=>{n.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),v=L(()=>m.data?x(m.data):[],[m.data]),y=L(()=>h.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:U(t).label})),[h,e]),b=e=>h.find(t=>t.key===e)??null,C=L(()=>h.filter(e=>e.enabled),[h]),w=C.length>=2,T=(e,t)=>{let n=J(m.data??null,e),r=t?.format;return n?.models.some(e=>r!==void 0&&!!e.formats[r])??!1},E=e=>{let t=b(e);return t?U(t).label:e},D=(e,t)=>C.filter(n=>n.key!==t&&T(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,O=e=>{let t=J(m.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},k=(e,t)=>{let n=J(m.data??null,e),r=t?.format;if(!(!n||r===void 0))return(n.slot===`detector`?t?.defaultModelId:void 0)??s(n,r)},A=(e,t)=>{let n=O(e),r=n.kind===`gate`?n.effectiveOn:!1,i=J(m.data??null,e),a=t.deviceKey===void 0?null:b(t.deviceKey),o=a?.format,s=i?.models.some(e=>o!==void 0&&!!e.formats[o])??!1,c=a?.steps?.[e];if(!s){if(!r)return{kind:`na`};let n=c?.jumpDeviceKey,i=n!==void 0&&C.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:D(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:E(i)}}return{kind:`enabled`,modelId:c?.modelId??k(e,a)??`Auto`,...c?.jumpDeviceKey!==void 0&&C.some(e=>e.key===c.jumpDeviceKey)?{jumpTo:E(c.jumpDeviceKey)}:{}}},j=r&&m.data?J(m.data,r.addonId):null,M=r?b(r.deviceKey):null,N=M?.format??`coreml`,ee=r?k(r.addonId,M):void 0,P=()=>{i(null),c(null),u(``)},te=(e,t)=>{if(t.deviceKey===void 0)return;let n=b(t.deviceKey)?.steps?.[e];i({addonId:e,deviceKey:t.deviceKey}),c({enabled:!0,...n?.modelId===void 0?{}:{modelId:n.modelId},settings:n?.settings??{}}),u(n?.jumpDeviceKey??``)},re=()=>{if(!r)return;let t=Jt(a),n=l!==``&&l!==r.deviceKey?l:void 0,i=t||n!==void 0?{...t,...n===void 0?{}:{jumpDeviceKey:n}}:null,o={};for(let e of h){if(!e.enabled&&e.key!==r.deviceKey)continue;let t={...e.steps};e.key===r.deviceKey&&(i?t[r.addonId]=i:delete t[r.addonId]);let n=Object.keys(t).length>0;o[e.key]={enabled:!0,weight:Math.max(1,e.weight),...e.maxSessions!=null&&e.maxSessions>0?{maxSessions:e.maxSessions}:{},...n?{steps:t}:{}}}_.mutate({agentNodeId:e,inferenceDevices:o},{onSuccess:P})};if(p.isLoading||m.isLoading)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(h.length===0)return V(`div`,{className:`rounded-md border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`});if(!m.data)return V(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ie=r!==null&&j!==null&&M!==null;return I(`div`,{className:`relative h-full w-full space-y-3`,children:[I(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[`Each column is one of this node's inference accelerators. A cell shows the`,` `,V(`span`,{className:`font-medium text-foreground`,children:`base model`}),` every camera landing on that accelerator runs; click to change it. Whether a camera runs a step is set per-camera on that camera's Detection pipeline tab — there is no gate here.`]}),V(`div`,{className:ie?`md:pr-[360px]`:``,children:v.length>0?V(ae,{tree:v,agents:y,gateFor:O,getCellState:A,onCellClick:te,selectedCell:r?{addonId:r.addonId,agentNodeId:e,deviceKey:r.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:d,onFallbackNodeChange:f,hideGate:!0}):V(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),V(S,{open:ie,onClose:P,title:j?.name??``,subtitle:r&&M?`${e} · ${U(M).label} · ${M.format}`:``,footer:I(R,{children:[V(`div`,{className:`flex-1`}),V(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:P,children:`Cancel`}),V(`button`,{type:`button`,disabled:!r||!a||_.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:re,children:_.isPending?`Saving…`:`Save`})]}),children:j&&r&&a?I(`div`,{className:`space-y-3`,children:[w&&I(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[V(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),I(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:l,onChange:e=>u(e.target.value),children:[V(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),C.filter(e=>e.key!==r.deviceKey).map(e=>I(`option`,{value:e.key,children:[U(e).label,` · `,e.format]},e.key))]}),V(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),V(o,{mode:`agent`,addon:j,agentDefault:a,agentNodeId:e,engineFormat:N,effectiveModelId:ee,onChangeAgentConfig:c})]}):V(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}F();var Xt=[`pipeline-orchestrator`],Zt=[`decoder`],Qt=!1;function $t({nodeId:e,refreshToken:t}){let n=c(),[r,i]=B(null),[a,o]=B(null),s=(y(void 0).data??[]).find(t=>t.id===e),l=s?.name??e,u=s?.isOnline??!1,d=fe({onSuccess:e=>{o(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${l} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(o(null),d.mutate({agentNodeId:e}))};return I(`div`,{className:`relative h-full w-full space-y-3`,children:[I(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[a&&V(`span`,{className:`text-emerald-400`,children:a}),d.isError&&V(`span`,{className:`text-red-400`,children:d.error instanceof Error?d.error.message:`Reset failed`}),V(`button`,{type:`button`,onClick:()=>{f()},disabled:d.isPending,className:`rounded border border-amber-500/40 bg-surface px-2 py-0.5 text-amber-300 hover:bg-surface-hover disabled:opacity-50`,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:d.isPending?`Resetting…`:`Reset to default`})]}),V(qt,{nodeId:e}),V(nt,{nodeId:e,addonIds:Xt,level:`global`,sectionIds:Zt}),Qt,Qt,I(`div`,{children:[V(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),V(Te,{nodeId:e,nodeName:l,isOnline:u})]}),I(`div`,{children:[V(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),V(Yt,{nodeId:e,refreshToken:t})]})]})}var en=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],tn=`decoder-nodeav`;function nn({nodeId:e,refreshToken:t}){let{data:n}=y(void 0),r=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??tn,i=[...en,r];return I(`div`,{className:`flex flex-col h-full`,children:[V(mt,{nodeId:e,refreshToken:t}),V(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:V(nt,{nodeId:e,addonIds:i,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:V(jt,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:V($t,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:V(Nt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:V(Ut,{nodeId:e,refreshToken:t})},{id:`logs`,label:`Logs`,order:300,content:V(Kt,{nodeId:e})}]})})]})}function rn(){return I(`div`,{className:`space-y-6`,children:[V(qt,{title:`Cluster cameras`}),I(`div`,{className:`min-w-0`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Use the Auto | Pin control to pin a camera to a node, the inference-device select to pin it to an accelerator, or the kebab to move a role; expand the chevron for the per-camera broker drill-down. Cluster load, inference-device weights, and Rebalance live on the Balancer tab.`})]}),V(bt,{mode:`cluster`})]})}var an=`pipeline-orchestrator`,on=`recorder`,sn=`recordingNodeId`,cn=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],ln=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function un(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function dn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function fn(e,t,n){let r=un(e,t);return typeof r==`string`&&r.length>0?r:n}function pn(e,t,n){let r=un(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function mn(e,t){let n=dn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function hn(e,t){let n=dn(e,t);return typeof n==`string`&&n.length>0?n:null}function gn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function _n(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function vn(e,t){switch(t){case`detect`:return e.pipeline}}function yn(e){return e instanceof Error?e.message:`Failed to save`}function bn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function xn({capability:e,label:t,hint:n,nodeId:r,active:i,pending:a,layout:o,onToggle:s}){let c=i?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,l=o===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,u=i?He:we;return I(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":`${t} capability for ${r}`,title:`${t} — ${n}`,disabled:a,onClick:()=>s(e,!i),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${c} ${l}`,children:[V(u,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),V(`span`,{children:t})]})}function Sn({node:e,emphasis:t=!1}){let n=e.isHub?Ie:G;return I(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[V(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),V(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),I(`div`,{className:`min-w-0`,children:[I(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[V(`span`,{className:`truncate`,children:e.name}),e.isHub&&V(pe,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&V(pe,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),V(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}F();function Cn({nodeId:e,value:t,detectedHosts:n,status:r,errorMessage:i,onCommit:a}){let[o,s]=B(t??``);H(()=>{s(t??``)},[t]);let c=n[0],l=c===void 0?`auto-detect`:`auto: ${c}`,u=r===`pending`,d=o.trim(),f=d!==(t??``),p=f&&!u,m=()=>{p&&a(e,d.length>0?d:null)};return I(`div`,{className:`flex items-center gap-1.5`,children:[V(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:l,value:o,disabled:u,onChange:e=>s(e.target.value),onBlur:m,onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&s(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),I(`button`,{type:`button`,onClick:m,disabled:!p,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[u?V(W,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):V(He,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!f&&!u&&r===`success`&&V(He,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),r===`error`&&V(`span`,{title:i??`Failed to save reachable host`,children:V(We,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":i??`Failed to save reachable host`,role:`img`})})]})}function wn({label:e,children:t}){return I(`div`,{className:`flex items-center justify-between gap-3`,children:[V(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function Tn({node:e,actions:t}){return I(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[V(Sn,{node:e,emphasis:!0}),V(`div`,{className:`grid grid-cols-2 gap-2`,children:ln.map(n=>V(xn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:vn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),V(`div`,{className:`space-y-3 border-t border-border pt-3`,children:V(wn,{label:`Reachable host`,children:V(Cn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function En(){return I(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function Dn({nodes:e,actions:t}){return V(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:I(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[V(`thead`,{children:I(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),ln.map(e=>V(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),V(`tbody`,{children:e.map(e=>I(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[V(`td`,{className:`px-4 py-3 align-middle`,children:V(Sn,{node:e})}),ln.map(n=>V(`td`,{className:`px-3 py-3 text-center align-middle`,children:V(xn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:vn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),V(`td`,{className:`px-4 py-3 align-middle`,children:V(Cn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})]},e.id))})]})})}function On({role:e,value:t,options:n,pending:r,onChange:i}){return I(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[V(`span`,{className:`text-xs font-semibold text-foreground`,children:gn(e)}),V(`select`,{value:t,disabled:r,onChange:t=>i(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:n.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),V(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:_n(e)})]})}function kn({roleValues:e,options:t,pending:n,lowFpsEnabled:r,fpsMinThreshold:i,onRoleChange:a,onLowFpsToggle:o}){return I(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[cn.map(r=>V(On,{role:r,value:e[r],options:t,pending:n,onChange:a},r)),I(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[V(`input`,{type:`checkbox`,checked:r,disabled:n,onChange:e=>o(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),I(`span`,{className:`flex flex-col gap-0.5`,children:[V(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),I(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,r?`${i} fps`:`disabled`]})]})]})]})}F();function An(){let e=z(),{nodes:n}=v(),i=ue(void 0),a=le({addonId:an}),o=le({addonId:on}),s=()=>bn(e),c=t({onSuccess:s}),l=de(),u=r({onSuccess:s}),d=A({onSuccess:s}),[f,p]=B(!1),m=L(()=>{let e=new Map;for(let t of i.data??[])e.set(t.nodeId,t.settings);return e},[i.data]),h=L(()=>n.map(e=>{let t=m.get(e.id),n=dt(t,e.isHub),r=mn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:mn(t,`maxCameras`),reachableHost:hn(t,`reachableHost`),detectedHosts:e.localIps}}),[n,m]),g=h.filter(e=>e.effective.pipeline),_={ingestNode:fn(a.data,`ingestNode`,`hub`),recordingNode:fn(o.data,sn,`hub`),audioNode:fn(a.data,`audioNode`,`hub`),motionNode:fn(a.data,`motionNode`,`hub`)},y=L(()=>{let e=n.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...cn.map(e=>_[e]),...e])].filter(e=>e.length>0)},[n,_]),b=pn(a.data,`fpsMinThreshold`,0),x=b>0,S=i.isLoading||a.isLoading||o.isLoading,C=(e,t,n)=>{c.mutate({agentNodeId:e,[t]:n})},w=(e,t)=>{if(e===`recordingNode`){d.mutate({addonId:on,patch:{[sn]:t}});return}d.mutate({addonId:an,patch:{[e]:t}})},T=e=>{d.mutate({addonId:an,patch:{fpsMinThreshold:e?Math.max(1,b):0}})},E=e=>u.variables?.agentNodeId===e?u.isPending?`pending`:u.isError?`error`:u.isSuccess?`success`:`idle`:`idle`,D=e=>E(e)===`error`?yn(u.error):null,O=async e=>{p(!0);try{for(let t of e)await l.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{p(!1),s()}},k={capabilityPending:c.isPending,onToggleCapability:C,onCommitReachableHost:(e,t)=>u.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:E,reachableHostErrorMessage:D};return I(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[I(`header`,{className:`flex items-start justify-between gap-4`,children:[I(`div`,{className:`space-y-1`,children:[V(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),V(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, distribute detection weight across detect-capable nodes, and choose the singleton cluster roles.`})]}),S&&V(W,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),V(kn,{roleValues:_,options:y,pending:d.isPending,lowFpsEnabled:x,fpsMinThreshold:b,onRoleChange:w,onLowFpsToggle:T})]}),I(`div`,{className:`space-y-3`,children:[I(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),V(En,{})]}),h.length===0?V(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):I(R,{children:[V(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:h.map(e=>V(Tn,{node:e,actions:k},e.id))}),V(`div`,{className:`hidden @3xl/clustertab:block`,children:V(Dn,{nodes:h,actions:k})})]})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),V(Ce,{nodes:g,pending:f,onCommitWeights:e=>void O(e)})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),g.length===0?V(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):V(`div`,{className:`space-y-2`,children:g.map(e=>V(Te,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}F();var jn=!1;function Mn({refreshToken:e}){let t=z(),{data:n}=y(void 0);L(()=>et(n??[]),[n]);let r=E({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return I(`div`,{className:`space-y-6`,children:[V(ht,{refreshToken:e}),V(An,{}),jn,I(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[I(`div`,{className:`min-w-0`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Recompute the optimal node for every assigned camera from current load + hardware affinity, and migrate the ones no longer on their best node. Pinned cameras never move.`})]}),I(`button`,{type:`button`,onClick:()=>r.mutate(void 0),disabled:r.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[V(Ae,{className:`h-3.5 w-3.5`}),r.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var Nn=[`pipeline-orchestrator`];function Pn({refreshToken:e}){return V(`div`,{className:`space-y-4 max-w-3xl`,children:V(nt,{nodeId:`hub`,addonIds:Nn,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer thresholds, and failover policy. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`})})}F();function Fn({refreshToken:e}){let t=z(),{data:n,isLoading:r}=me(),[i,a]=B(null),[o,s]=B(``),[c,l]=B(``),u=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},d=f({onSuccess:()=>{a(null),u()}}),p=se({onSuccess:u}),m=e=>{a(e.id),s(e.name),l(e.description??``)},h=()=>{a(null),s(``),l(``)},g=()=>{if(!i)return;let e=c.trim();d.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let _=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return V(`div`,{className:`space-y-6 max-w-4xl`,children:I(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[I(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),V(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle`,children:[_.length,` template`,_.length===1?``:`s`]})]}),_.length===0?I(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[V(Me,{className:`h-6 w-6 opacity-40`}),V(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):V(`ul`,{className:`divide-y divide-border`,children:_.map(e=>{let t=i===e.id;return V(`li`,{className:`px-4 py-3 text-xs`,children:I(`div`,{className:`flex items-start gap-3`,children:[V(`div`,{className:`flex-1 min-w-0`,children:t?I(`div`,{className:`space-y-2`,children:[V(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:o,onChange:e=>s(e.target.value),placeholder:`Template name`,autoFocus:!0}),V(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:c,onChange:e=>l(e.target.value),placeholder:`Description (optional)`})]}):I(R,{children:[V(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&V(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),I(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,I(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),V(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?I(R,{children:[I(`button`,{type:`button`,onClick:g,disabled:d.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[V(He,{className:`h-3 w-3`}),`Save`]}),I(`button`,{type:`button`,onClick:h,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[V(Je,{className:`h-3 w-3`}),`Cancel`]})]}):I(R,{children:[V(`button`,{type:`button`,onClick:()=>m(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:V(je,{className:`h-3 w-3`})}),V(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&p.mutate({id:e.id})},disabled:p.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:V(Xe,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}F();var In=`pipeline-analytics`;function Ln(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function Rn(){let e=z(),{data:t}=y(void 0),{data:n,isLoading:r}=le({addonId:In}),i=Ln(n),a=A({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),o=L(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return I(`div`,{className:`flex flex-col gap-6`,children:[I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),V(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),I(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?V(W,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):V(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:In,patch:{postProcessingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:o.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&V(W,{className:`h-4 w-4 animate-spin text-primary`})]})]}),I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),V(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),V(rt,{types:[`eventMedia`]})]})]})}var zn=`pipeline-orchestrator`,Bn=200;function Vn(){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(j,{addonId:zn,limit:Bn,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F();var Hn=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function Un({refreshToken:e}){let[t,n]=B(`assignments`);return I(`div`,{className:`flex flex-col h-full`,children:[I(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),V(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Per-camera assignments, the load balancer (live load + inference-device weights), cluster-wide settings, and the pipeline template library.`})]}),V(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Hn.map(e=>V(`button`,{type:`button`,onClick:()=>n(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),I(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&V(rn,{}),t===`balancer`&&V(Mn,{refreshToken:e}),t===`events`&&V(Rn,{}),t===`recording`&&V(it,{}),t===`settings`&&V(Pn,{refreshToken:e}),t===`templates`&&V(Fn,{refreshToken:e}),t===`logs`&&V(Vn,{})]})]})}function Wn(e){let t=[],n=[],{assignment:r,detection:i,decoder:a,broker:o}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),i!==null&&i.phase===`active`&&a!==null&&a.shm.framesWritten===0&&t.push({code:`decoder-black-hole`,severity:`error`,message:`Decoder on ${a.nodeId} has written 0 frames to the shared-memory plane while detection is active — the decode path is stalled`}),r.detectionNodeId===null&&i===null&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});for(let e of o?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function Gn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Kn(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function qn(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Jn(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var Yn={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function Xn(e){if(!Gn(e)||!Array.isArray(e.sections))return Yn;let t=ve(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)Jn(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Kn(n(`detectionFps`)),motionSources:qn(n(`motionSources`)),motionFps:Kn(n(`motionFps`)),motionCooldownMs:Kn(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function Zn(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...Zn(r.children,t+1));return n}function Qn(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function X({title:e,children:t}){return I(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[V(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),V(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return I(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[V(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),V(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&V($n,{})]})}function $n(){return V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var er={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return V(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${er[e]}`,children:t})}function $({children:e}){return V(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function tr({icon:e,label:t,nodeId:n,pinned:r,reason:i,overridden:a}){return I(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[V(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),V(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?V(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):I(R,{children:[V(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?I(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[V(st,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,i!==void 0&&i.length>0?i:`capacity`]}),a&&V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function nr({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:i}){let a=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,o=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return I(X,{title:`Where it runs`,children:[V(tr,{icon:G,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),V(tr,{icon:ze,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),V(tr,{icon:ke,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),V(tr,{icon:Ne,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),V(`div`,{className:`mt-1.5`,children:I(`select`,{value:a,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>i(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[V(`option`,{value:`auto`,children:`Auto (load balanced)`}),o.map(e=>I(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function rr(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function ir(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function ar(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function or({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:i}){let a=ir(t,n.detectionStreamProfile),o=ir(t,n.motionStreamProfile),s=n.motionSources.includes(`analyzer`);return I(X,{title:`Streams & motion`,children:[I(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,a!==void 0&&` · ${a.width}×${a.height} ${a.codec}`]}),V(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:ar(n.detectionFps)}),I(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.join(` + `):`none`,r===!1&&` · inactive`]}),s&&I(R,{children:[I(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,o!==void 0&&` · ${o.width}×${o.height} ${o.codec}`]}),I(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[ar(n.motionFps),i!==null&&` · live ${i.toFixed(1)}`]})]}),V(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),V(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?V($,{children:`No streams registered`}):e.map(e=>I(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[V(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,rr(e)]},e.camStreamId))})]})}function sr({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return I(X,{title:`Pipeline steps`,children:[e===void 0?V($,{children:`Resolving…`}):e.length===0?V($,{children:`No steps configured`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>V(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:I(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&V(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&I(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),V(`div`,{className:`mt-1`,children:I(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var cr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function lr({detection:e,live:t,detectionMode:r,modeOverridden:i}){if(e===null)return I(X,{title:`Detection runtime`,children:[V(Z,{label:`Mode`,overridden:i,children:r??`—`}),V($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,u=n(a),d=a===`active`&&o===0;return I(X,{title:`Detection runtime`,children:[I(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[I(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[V(C,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&V(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),V(Z,{label:`Mode`,overridden:i,children:r??`—`}),I(Z,{label:`FPS`,children:[V(`span`,{className:d?`text-danger font-semibold`:``,children:o.toFixed(1)}),I(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),I(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&I(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&I(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),I(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),I(Z,{label:`Provisioning`,children:[V(Q,{tone:cr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&I(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function ur({broker:e}){return e===null?V(X,{title:`Stream broker`,children:V($,{children:`Broker stage inactive or unreachable`})}):I(X,{title:`Stream broker`,children:[e.profiles.length===0?V($,{children:`No broker profiles`}):V(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return I(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),V(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),I(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),I(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),I(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),I(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[I(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),I(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function dr({decoder:e,detectionActive:t}){if(e===null)return V(X,{title:`Decoder`,children:V($,{children:`Decoder stage inactive or unreachable`})});let n=t&&e.shm.framesWritten===0;return I(X,{title:`Decoder`,children:[V(Z,{label:`Node`,children:e.nodeId}),V(Z,{label:`Sessions`,children:e.sessionCount}),I(Z,{label:`SHM frames`,children:[V(`span`,{className:n?`text-danger font-semibold`:``,children:e.shm.framesWritten}),V(`span`,{className:`text-foreground-subtle`,children:` written`})]}),I(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&I(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),I(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&V(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}F();var fr=`pipeline-orchestrator`,pr={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},mr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function hr({problems:e}){return V(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>I(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[V(Ye,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),V(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function gr({deviceId:e,name:t,online:n,status:r,live:i,onlineNodes:a}){let o=z(),{data:s}=te({addonId:fr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:c}=m({deviceId:e},{staleTime:3e4}),l=L(()=>Xn(s),[s]),d=L(()=>c===void 0?void 0:Zn(c.steps),[c]),f=L(()=>r===void 0?[]:Wn(r),[r]),p=()=>{o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},h=ie({onSuccess:p}),g=u({onSuccess:p}),_=t=>{t===`auto`?g.mutate({deviceId:e}):h.mutate({deviceId:e,agentNodeId:t})},v=r===void 0?`idle`:Qn(r),y=f.some(e=>e.severity===`error`),b=f.length>0,x=y?`border-danger/50`:b?`border-warning/40`:`border-border`;return I(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${x} bg-background overflow-hidden`,children:[I(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[V(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${y?`bg-danger`:pr[v]}`,title:y?`Error`:mr[v],"aria-label":y?`Error`:mr[v],role:`img`}),V(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&V(Q,{tone:`danger`,children:`offline`}),I(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[l.detectionMode!==null&&V(Q,{tone:l.detectionMode===`disabled`?`warning`:l.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:l.detectionMode===`disabled`?`detection off`:l.detectionMode}),r?.recording!=null&&(r.recording.active?I(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&I(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),f.length>0&&V(hr,{problems:f}),r===void 0?V(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):I(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[V(nr,{assignment:r.assignment,settings:l,onlineNodes:a,pinPending:h.isPending||g.isPending,onDetectionPinChange:_}),V(lr,{detection:r.detection,live:i,detectionMode:l.detectionMode,modeOverridden:l.overriddenKeys.has(`detectionMode`)}),V(sr,{steps:d,audioModelId:c?.audio?.modelId??null,audioEnabled:r.audio?.enabled??c?.audio?.enabled??null,audioMode:l.audioMode}),V(or,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:l,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null}),V(ur,{broker:r.broker}),V(dr,{decoder:r.decoder,detectionActive:r.detection?.phase===`active`})]})]})}F();var _r=5e3,vr=1e4,yr=5e3;function br(e){let t=z(),{data:n,isLoading:r}=Se(),{data:i,isLoading:a}=O({},{refetchInterval:_r}),{nodes:o}=v();H(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[s,c]=B(new Map);b(ye.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&c(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),H(()=>{if(s.size===0)return;let e=setInterval(()=>{c(e=>{let t=Date.now()-vr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},yr);return()=>clearInterval(e)},[s.size]);let l=L(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:L(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:l.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]),liveMetrics:s,onlineNodes:L(()=>(o??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[o]),isLoading:r||a}}F();function xr({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:i}=br(e),a=L(()=>[...t.map(e=>{let t=e.status===void 0?[]:Wn(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),o=L(()=>{let e=0,t=0;for(let r of a)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:a.length,active:e,issues:t}},[a,n]);return i&&t.length===0?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):V(`div`,{className:`h-full overflow-y-auto`,children:I(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[I(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground`,children:o.total}),` cameras`]}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success`,children:o.active}),` actively inferring`]}),I(`span`,{children:[V(`span`,{className:`font-semibold ${o.issues>0?`text-danger`:`text-foreground`}`,children:o.issues}),` `,`with issues`]}),V(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),a.map(({row:e})=>V(gr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}F();var Sr=`__cluster__`;function Cr(e){return e===`cameras`?`cameras`:`nodes`}function wr(){let[e,t]=Ve(),n=Cr(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[i,a]=B(0),[o,s]=B(!1);return H(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Sr},{replace:!0})},[n,e,t]),I(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[I(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[I(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[V(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:r},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),V(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),I(`button`,{type:`button`,onClick:()=>a(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[V(Pe,{className:`h-3.5 w-3.5`}),`Refresh`]})]}),n===`nodes`&&I(`button`,{type:`button`,onClick:()=>s(e=>!e),"aria-expanded":o,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[I(`span`,{children:[o?`Hide`:`Show`,` node list`]}),V(Be,{className:[`h-4 w-4 transition-transform`,o?`rotate-180`:``].join(` `)})]}),V(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?I(R,{children:[V(`aside`,{className:[o?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:V(pt,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),s(!1)},refreshToken:i})}),V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?V(Un,{refreshToken:i}):V(nn,{nodeId:r,refreshToken:i})})]}):V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:V(xr,{refreshToken:i})})})]})}export{wr as PipelinePage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{W as e}from"./index-RegSp4ae.js";var t=e(`circle-check-big`,[[`path`,{d:`M21.801 10A10 10 0 1 1 17 3.335`,key:`yps3ct`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]]);export{t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{W as e}from"./index-RegSp4ae.js";var t=e(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`polyline`,{points:`12 6 12 12 16 14`,key:`68esgv`}]]);export{t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{W as e}from"./index-RegSp4ae.js";var t=e(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]);export{t};
|