@camstack/addon-admin-ui 1.2.451 → 1.2.453
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/{AddonAssetIcon-tSDKYL0K.js → AddonAssetIcon-D4f5QzwX.js} +1 -1
- package/dist/assets/Addons-BmgETSc4.js +4 -0
- package/dist/assets/{AdminPage-Bc7EcIQy.js → AdminPage-D_zEoNvj.js} +1 -1
- package/dist/assets/{AdminSectionedPage-DorUtSBh.js → AdminSectionedPage-c5oc7MKr.js} +1 -1
- package/dist/assets/{AiProfiles-BdYyzFcG.js → AiProfiles-OmUyER08.js} +2 -2
- package/dist/assets/{BrokerForm-Deefp6zP.js → BrokerForm-WFCCMZu7.js} +1 -1
- package/dist/assets/{Build-D_QB0Yce.js → Build-H3rAvJYX.js} +4 -4
- package/dist/assets/{Calendars-BTBqj3kw.js → Calendars-DNZptD-n.js} +1 -1
- package/dist/assets/{Cluster-qRWUra5C.js → Cluster-BirHrmjz.js} +1 -1
- package/dist/assets/ClusterStepModel-DXEw1-iK.js +1 -0
- package/dist/assets/{CompositionEditor-sCKYBpl2.js → CompositionEditor-BruCgxbv.js} +1 -1
- package/dist/assets/{CompositionEditorPage-DzUj_31l.js → CompositionEditorPage-CNY8Rqx0.js} +1 -1
- package/dist/assets/Data-B9LAPgxz.js +2 -0
- package/dist/assets/{DeviceDetail-BLnowNRs.js → DeviceDetail-DB8Wa7Sv.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-Bffr6IHD.js → DeviceDoActionFields-Drr-gpl9.js} +1 -1
- package/dist/assets/{Devices-IJKvm0BP.js → Devices-JQ8FIcrC.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-B1o6udpz.js → EmbedPlayerPage-DMCMitj3.js} +1 -1
- package/dist/assets/History-DyW5HpVM.js +1 -0
- package/dist/assets/Identity-lfUuRjOX.js +1 -0
- package/dist/assets/IntegrationDetail-DnpseReT.js +1 -0
- package/dist/assets/{IntegrationHub-Bf4b3i_q.js → IntegrationHub-Db0bsfLJ.js} +1 -1
- package/dist/assets/{Integrations-nFhMQF34.js → Integrations-CcXy5tWR.js} +1 -1
- package/dist/assets/Integrations-DNPpJ4Ja.js +1 -0
- package/dist/assets/{Library-A6WfMhER.js → Library-C2dLqSTC.js} +1 -1
- package/dist/assets/Locations-e6uuHHQU.js +3 -0
- package/dist/assets/{Logs-C9J8k6c9.js → Logs-DWM80Ifl.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-v8FP28QJ.js → MaskShapeCanvas-Chm66Qq5.js} +1 -1
- package/dist/assets/{MotionZonesSettings-Bqg-ZAEs.js → MotionZonesSettings-CQ4kMA71.js} +1 -1
- package/dist/assets/{MyAccess-uX46IK3F.js → MyAccess-DhDj6Dcu.js} +1 -1
- package/dist/assets/{Network-BR-HvAds.js → Network-DRNoFcHE.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-BNTQVCjk.js → NodeAddonsSettingsPanel-CmUo7HL7.js} +1 -1
- package/dist/assets/{Notifications-BtCeEFJT.js → Notifications-BnhdNZ6f.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DqyBAWCW.js → PrivacyMaskSettings-CpCCSkKp.js} +1 -1
- package/dist/assets/Recordings-BcWqTc1H.js +1 -0
- package/dist/assets/{ScanNetworkModal-DzMITtJ8.js → ScanNetworkModal-DOkg50dW.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-365WT-vj.js → SceneMonitorEditor-C1CNWxmG.js} +1 -1
- package/dist/assets/SessionsList-rvronrFR.js +2 -0
- package/dist/assets/{Showroom-Ch7an15I.js → Showroom-BLEcXdKT.js} +1 -1
- package/dist/assets/{System-XW10dOJr.js → System-B6PNyCJb.js} +1 -1
- package/dist/assets/{Terminal-CmDRhqrR.js → Terminal-C20iOQsN.js} +1 -1
- package/dist/assets/{Viewer-2oJvYupj.js → Viewer-DwNTfUWw.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BvyGb9Bo.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DO5DropZ.js} +1 -1
- package/dist/assets/{addon-icons-context-Nt5kiIqp.js → addon-icons-context-CO0pJapE.js} +1 -1
- package/dist/assets/{archive-BpVlUMGc.js → archive-Bp0veqaX.js} +1 -1
- package/dist/assets/{authed-media-CRjjClqw.js → authed-media-BukO6Htt.js} +1 -1
- package/dist/assets/{bell-off-DFWiqigj.js → bell-off-DNhCufqt.js} +1 -1
- package/dist/assets/{board-model-CbfKyLZU.js → board-model-Ci-_X0u-.js} +1 -1
- package/dist/assets/{boxes-DEZFxpEo.js → boxes-BaumwARG.js} +1 -1
- package/dist/assets/circle-slash-D7rbiin9.js +1 -0
- package/dist/assets/client-BggkinSi.js +358 -0
- package/dist/assets/{cloud-upload-DJX2vjB1.js → cloud-upload-C78OV2Vf.js} +1 -1
- package/dist/assets/crop-CFruzwpC.js +1 -0
- package/dist/assets/{device-integration-icon-eQMV6gf2.js → device-integration-icon-B2dkF6iM.js} +1 -1
- package/dist/assets/device-picker-model-B7xNzrPL.js +1 -0
- package/dist/assets/{dist-C44xoxcH.js → dist-BnhJ2JWA.js} +1 -1
- package/dist/assets/dist-DTzD7Qgb.js +358 -0
- package/dist/assets/{eraser-BJtJIM79.js → eraser-BYMxipNr.js} +1 -1
- package/dist/assets/{hard-drive-download-BgY0ewC_.js → hard-drive-download-ClkqTbzr.js} +1 -1
- package/dist/assets/{hostInit-BxKKf6O5.js → hostInit-BGNr3Jpq.js} +1 -1
- package/dist/assets/i18n-BimjnPQq.js +1 -0
- package/dist/assets/{icons-B7PsYODJ.js → icons-DHL4FRrs.js} +1 -1
- package/dist/assets/{index-B-H1mfMz.js → index-BVY_WMe1.js} +3 -3
- package/dist/assets/{key-Rj556V_5.js → key-CKrA-CfR.js} +1 -1
- package/dist/assets/{key-round-JtuAp3H5.js → key-round-CDKQmrbu.js} +1 -1
- package/dist/assets/{layers-arFC7gbL.js → layers-UfB0_N2n.js} +1 -1
- package/dist/assets/{linked-devices-model-Bwz1L9wp.js → linked-devices-model-BM0mB7nT.js} +1 -1
- package/dist/assets/{list-ordered-Dam1ZKMc.js → list-ordered-0mq_0UIh.js} +1 -1
- package/dist/assets/{location-owned-usage-DwnxDZWp.js → location-owned-usage-D6ooNfJc.js} +1 -1
- package/dist/assets/{log-in-lVU3BPjL.js → log-in-BySKT1Dy.js} +1 -1
- package/dist/assets/{memory-stick-Cttq5WM5.js → memory-stick-Dp1YfIBO.js} +1 -1
- package/dist/assets/{message-square-plus-CaNw_hMf.js → message-square-plus-BWjzgumP.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-ab6954b6.js → mf-entry-bootstrap-0-594b555b.js} +2 -2
- package/dist/assets/{mic-off-it4ki4Jh.js → mic-off-DiXTm9Y2.js} +1 -1
- package/dist/assets/{monitor-off-oHRvN7aD.js → monitor-off-D3OGcghF.js} +1 -1
- package/dist/assets/{monitor-smartphone-CjCMg9jw.js → monitor-smartphone-BkZrPcuL.js} +1 -1
- package/dist/assets/mount-B7xNzrPL.js +1 -0
- package/dist/assets/notification-schedule-field-BG32wqBc.js +1 -0
- package/dist/assets/{player-overlays-BQ-CPD3k.js → player-overlays-BYMAZza9.js} +1 -1
- package/dist/assets/{recycle-DLgVUrk1.js → recycle-FJ49Ydss.js} +1 -1
- package/dist/assets/remoteEntry-CXA3sxXs.js +1 -0
- package/dist/assets/{scan-eye-D3WSpR2M.js → scan-eye-Cd5UWfpf.js} +1 -1
- package/dist/assets/{scissors-CfXjajAo.js → scissors-BA0EAdIJ.js} +1 -1
- package/dist/assets/{search-x-DrZuvHV8.js → search-x-By_wSOtV.js} +1 -1
- package/dist/assets/{send-BGZ680If.js → send-C-dY1QlF.js} +1 -1
- package/dist/assets/{settings-2-WgIC2cEC.js → settings-2-CbNC1QI2.js} +1 -1
- package/dist/assets/{speaker-DIrTXPXW.js → speaker-1RM6dadP.js} +1 -1
- package/dist/assets/src-75D_Zlij.js +67 -0
- package/dist/assets/{timer-reset-Ba4-n5gG.js → timer-reset--avsGIJd.js} +1 -1
- package/dist/assets/{ungroup-DjxNnRiT.js → ungroup-D3cHvFv0.js} +1 -1
- package/dist/assets/{unlink-Cy4eOOGb.js → unlink-tiyUOhU3.js} +1 -1
- package/dist/assets/{usb-Crnw8Rqe.js → usb-Di-8wm3J.js} +1 -1
- package/dist/assets/{use-scenes-feed-CqavtElt.js → use-scenes-feed-CAjM8T0N.js} +1 -1
- package/dist/assets/{use-stationary-objects-CuD-UCH8.js → use-stationary-objects-Bjq8kJYj.js} +1 -1
- package/dist/assets/useEventInvalidation-B7xNzrPL.js +1 -0
- package/dist/assets/{useNodeUrlSelection-ChFCBb4B.js → useNodeUrlSelection-DiojZJ0u.js} +1 -1
- package/dist/assets/user-round-luImimaP.js +1 -0
- package/dist/assets/{user-x-BDmcZv0z.js → user-x-olI9Ahi1.js} +1 -1
- package/dist/assets/{video-JjHo3xW3.js → video-jTbj0gAQ.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-3LGiNBfi.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D8GIXJRi.js} +2 -2
- package/dist/index.html +10 -10
- package/dist/server/addon.js +115 -68
- package/package.json +1 -1
- package/dist/assets/Addons-ofsCoJ4Y.js +0 -4
- package/dist/assets/ClusterStepModel-CYnyPKcf.js +0 -1
- package/dist/assets/Data-BJuJfR0P.js +0 -2
- package/dist/assets/History-su2kJ1JJ.js +0 -1
- package/dist/assets/Identity-8srCiX2b.js +0 -1
- package/dist/assets/IntegrationDetail-CHtQ-0tZ.js +0 -1
- package/dist/assets/Integrations-Cnq7Q1qn.js +0 -1
- package/dist/assets/Locations-Dl_YxXoD.js +0 -3
- package/dist/assets/Recordings-arOpg17X.js +0 -1
- package/dist/assets/SessionsList-CAYqZ393.js +0 -2
- package/dist/assets/circle-slash-BvDvmSoU.js +0 -1
- package/dist/assets/client-C7mYZlqO.js +0 -358
- package/dist/assets/crop-BLfw1NQy.js +0 -1
- package/dist/assets/device-picker-model-B7n7uzAw.js +0 -1
- package/dist/assets/dist-4Z3hLAqT.js +0 -358
- package/dist/assets/i18n-CiEPJn04.js +0 -1
- package/dist/assets/mount-B7n7uzAw.js +0 -1
- package/dist/assets/notification-schedule-field-DkO0-1Tm.js +0 -1
- package/dist/assets/remoteEntry-5tiapUFy.js +0 -1
- package/dist/assets/src-DP8JO4HZ.js +0 -67
- package/dist/assets/useEventInvalidation-B7n7uzAw.js +0 -1
- package/dist/assets/user-round-7xIjUD30.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-Cyuzqnbw.js";import{$ as t,B as n,G as r,J as i,L as a,S as o,b as s,i as c,o as l,p as u,q as d,x as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{A as p,D as m,Ir as h,It as g,N as _,Nn as v,Nt as y,O as b,Or as x,Si as S,T as C,V as w,Xn as T,Zr as E,Zt as D,_t as O,b as k,bi as A,bn as j,ca as M,cn as N,dn as P,dt as F,ir as I,j as L,k as R,mn as ee,na as te,or as ne,ot as z,rr as re,ur as ie,ut as ae,v as oe,xn as B,y as se,z as V}from"./player-overlays-BYMAZza9.js";import{Gn as ce,Hn as le,Jn as ue,Kn as de,Wn as fe,Xi as pe,Xn as me,Yn as he,Zn as ge,fi as _e,h as ve,l as ye,pi as be,qn as xe,u as Se,zi as Ce}from"./client-BggkinSi.js";import{l as we,t as Te,u as Ee}from"./video-jTbj0gAQ.js";import{a as De,i as Oe,n as ke,r as Ae,t as je}from"./usb-Di-8wm3J.js";import{t as Me}from"./crop-CFruzwpC.js";import{t as Ne}from"./layers-UfB0_N2n.js";import{n as Pe}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DdJYWyu3.js";import{$n as Fe,Ac as Ie,Ar as Le,Au as Re,Bc as ze,Bn as Be,Cc as Ve,Dc as He,Fn as Ue,Gc as We,Gn as Ge,Gu as H,Hc as Ke,Hn as qe,In as Je,J as Ye,Jr as Xe,Ju as Ze,K as Qe,Ku as $e,Ln as et,Lu as tt,Mn as nt,Oc as rt,Pn as it,Q as at,Qn as ot,Rn as st,Rr as U,Ru as ct,Sn as lt,St as ut,Tc as dt,Tu as W,Uc as ft,Vc as pt,Vn as mt,Wc as ht,Wn as gt,Wt as _t,X as vt,Xu as yt,Y as bt,Ya as xt,Yu as St,Zn as Ct,Zr as wt,Zt as Tt,_c as Et,_n as Dt,ac as Ot,an as kt,bc as At,bn as jt,cc as Mt,ec as Nt,er as Pt,fc as Ft,fr as It,gc as Lt,gn as Rt,gt as zt,hr as G,ic as Bt,ir as Vt,jc as Ht,jn as Ut,ju as Wt,kc as Gt,mn as K,mt as Kt,nc as qt,nr as Jt,oc as Yt,pr as Xt,q as Zt,qc as Qt,qr as $t,qu as en,r as tn,rc as nn,rr as rn,sc as an,st as on,tc as sn,tr as cn,wc as ln,xc as un,xn as dn,xt as fn,yc as pn}from"./src-75D_Zlij.js";import{t as q}from"./i18n-BimjnPQq.js";import{t as J}from"./useTranslation-D3Is_4B6.js";import{G as mn,Q as hn,Z as gn,nt as _n}from"./index-BVY_WMe1.js";import"./useEventInvalidation-B7xNzrPL.js";import{t as vn}from"./NodeAddonsSettingsPanel-CmUo7HL7.js";import{a as yn,c as bn,d as xn,g as Sn,h as Cn,i as wn,l as Tn,n as En,o as Dn,p as On,r as kn,s as An,t as jn}from"./board-model-Ci-_X0u-.js";var Mn=`step`,Nn=[Mn,`acc`];function Pn(e,t){return`${e}/${t}`}function Fn(e,t,n){let r=n.step!==null&&e.includes(n.step),i=n.acc!==null&&t.includes(n.acc);return{stepId:r?n.step:null,acceleratorId:i?n.acc:null,staleStepId:n.step!==null&&n.step!==``&&!r&&e.length>0?n.step:null}}function In(e){if(e==null)return null;if(typeof e==`number`)return e>0?e:null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function Ln(e){return e}function Rn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function zn(e,t){return typeof e==`boolean`?e:Ln(t)}function Bn(e,t){return{pipeline:zn(Rn(e,`detect`),t),audio:zn(Rn(e,`audio`),t),ingest:zn(Rn(e,`ingest`),t)}}function Vn(e,t,n){let r=e?.find(e=>e.nodeId===t);return Bn(r?.settings,n)}function Hn({selectedNodeId:e,onSelect:t,refreshToken:n}){let r=M(),{t:i}=J(),{nodes:a}=$e(),{data:c}=pn(void 0),{data:l}=Ve(void 0),u=new Map;for(let e of c??[])u.set(e.agentNodeId,(u.get(e.agentNodeId)??0)+1);let d=a??[],p=d.filter(e=>e.isOnline).length,m=d.filter(e=>!e.isOnline).length;return o(`div`,{className:`flex flex-col h-full`,children:[o(`button`,{type:`button`,onClick:()=>t(Mo),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:[f(we,{className:`h-4 w-4 flex-shrink-0`}),o(`div`,{className:`min-w-0 flex-1`,children:[f(`div`,{className:`text-xs font-semibold truncate`,children:i(`pipeline.nodeList.cluster`,`Cluster`)}),f(`div`,{className:`text-[10px] text-foreground-subtle`,children:i(`pipeline.nodeList.assignmentsLoadBalancingRoles`,`Assignments, load balancing, roles`)})]})]}),f(`div`,{className:`flex-1 overflow-y-auto`,children:d.map(n=>{let a=e===n.id,c=u.get(n.id)??0,d=n.isHub?P:E,p=Vn(l,n.id,n.isHub),m=n.isOnline?null:_t(In(n.lastSeen),r);return o(`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 ${a?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[f(d,{className:`h-4 w-4 flex-shrink-0`}),o(`div`,{className:`min-w-0 flex-1`,children:[o(`div`,{className:`flex items-center gap-2`,children:[f(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&f(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:i(`common.hubWord`)}),!n.isOnline&&f(`span`,{className:`h-1.5 w-1.5 rounded-full bg-danger flex-shrink-0`}),n.isOnline&&f(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),o(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[f(`span`,{children:i(`common.coresCount`,{count:n.cpuCores})}),f(`span`,{children:`•`}),o(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),c>0&&o(s,{children:[f(`span`,{children:`•`}),o(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[f(Te,{className:`h-2.5 w-2.5`}),c]})]}),!n.isOnline&&o(s,{children:[f(`span`,{children:`•`}),o(`span`,{className:`text-danger`,children:[i(`common.offline`),m===null?``:` · ${m}`]})]})]}),o(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[f(U,{variant:p.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:p.pipeline?i(`pipeline.nodeList.pipelineEnabled`,`Pipeline: enabled`):i(`pipeline.nodeList.pipelineNotEnabledAgentCapability`,`Pipeline: not enabled (agent capability)`),children:i(`pipeline.nodeList.pipe`,`Pipe`)}),f(U,{variant:p.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:p.audio?i(`pipeline.nodeList.audioEnabled`,`Audio: enabled`):i(`pipeline.nodeList.audioNotEnabledAgentCapability`,`Audio: not enabled (agent capability)`),children:i(`pipeline.nodeList.aud`,`Aud`)})]})]})]},n.id)})}),o(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[f(`span`,{children:i(`common.onlineCount`,{count:p})}),m>0&&f(`span`,{className:`text-danger`,children:i(`common.offlineCount`,{count:m})})]})]})}function Un({nodeId:e,refreshToken:t}){let{t:n}=J(),{nodes:r}=$e(),i=r?.find(t=>t.id===e),a=en(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return i?o(`div`,{className:`px-6 py-4 border-b border-border`,children:[o(`div`,{className:`flex items-center gap-2 mb-1`,children:[f(`h2`,{className:`text-base font-semibold text-foreground`,children:i.name}),i.isOnline?f(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:n(`common.online`)}):f(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-danger/10 text-danger`,children:n(`common.offline`)}),i.isHub&&f(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:n(`common.hubWord`)})]}),o(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[f(`span`,{children:i.cpuModel??`CPU`}),f(`span`,{children:`•`}),f(`span`,{children:n(`common.coresCount`,{count:i.cpuCores})}),f(`span`,{children:`•`}),o(`span`,{children:[Math.round(i.memoryMB/1024),` GB`]}),a&&o(s,{children:[f(`span`,{children:`•`}),f(`span`,{children:n(`pipeline.nodeDetailHeader.cameras`,{attached:a.attachedCameras,active:a.activeCameras})}),f(`span`,{children:`•`}),f(`span`,{children:n(`pipeline.nodeDetailHeader.avgInference`,{ms:a.avgInferenceTimeMs.toFixed(0)})}),f(`span`,{children:`•`}),f(`span`,{children:n(`pipeline.nodeDetailHeader.queue`,{depth:a.queueDepthTotal})}),a.hardware.hasGpu&&o(s,{children:[f(`span`,{children:`•`}),f(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):f(`div`,{className:`px-6 py-4 border-b border-border`,children:o(`div`,{className:`text-xs text-foreground-subtle`,children:[n(`pipeline.nodeDetailHeader.nodeNotFound`,`Node not found:`),` `,e]})})}var Wn=[`assignments`,`tree`,`engines`,`logs`];t();function Gn({refreshToken:e,nodeId:t}){let{t:n}=J(),[a,s]=i(new Map),{nodes:c}=H();St(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&s(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:l}=Mt(void 0),u=r(()=>{let e=new Map;for(let t of l??[])e.set(t.nodeId,t.deviceCount);return e},[l]),d=r(()=>{let e=new Map,t=Date.now()-3e4;for(let n of a.values()){if(n.timestamp<t)continue;let r=n.nodeId??`hub`,i=e.get(r)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,n.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=n.metrics.actualFps,i.totalInferenceWeighted+=n.metrics.avgInferenceTimeMs,i.queueDepth+=n.metrics.queueDepth,e.set(r,i)}return e},[a]),p=r(()=>{let e=new Map;for(let t of c)e.set(t.id,t.shortName);return e},[c]),m=r(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of d.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:c.length,onlineAgents:c.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[d,c]);if(t){let e=d.get(t);return o(`div`,{className:`@container/liveload`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:n(`pipeline.liveLoadPanel.liveLoad`,`Live load`)}),o(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[f(Y,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),f(Y,{label:n(`pipeline.liveLoadPanel.activeAttached`,`Active / Attached`),value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),f(Y,{label:n(`pipeline.liveLoadPanel.avgInferMs`,`Avg infer ms`),value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),f(Y,{label:n(`pipeline.liveLoadPanel.queue`,`Queue`),value:e?String(e.queueDepth):`—`}),f(Y,{label:n(`pipeline.liveLoadPanel.audio`,`Audio`),value:String(u.get(t)??`—`)})]})]})}let h=[...d.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return o(`div`,{className:`@container/liveload`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:n(`pipeline.liveLoadPanel.liveLoad`,`Live load`)}),o(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[f(Y,{label:n(`pipeline.liveLoadPanel.totalAgents`,`Total agents`),value:`${m.onlineAgents}/${m.totalAgents}`}),f(Y,{label:n(`pipeline.liveLoadPanel.activeAttached`,`Active / Attached`),value:`${m.activeCameras}/${m.attachedCameras}`}),f(Y,{label:n(`pipeline.liveLoadPanel.totalFps`,`Total FPS`),value:m.totalFps.toFixed(1)}),f(Y,{label:n(`pipeline.liveLoadPanel.avgInferenceMs`,`Avg inference ms`),value:m.avgInferenceTimeMs.toFixed(0)}),f(Y,{label:n(`pipeline.liveLoadPanel.queueDepth`,`Queue depth`),value:String(m.queueDepth)})]}),f(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:o(`table`,{className:`w-full text-xs min-w-[480px]`,children:[f(`thead`,{className:`bg-surface`,children:o(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[f(`th`,{className:`text-left px-3 py-2`,children:n(`pipeline.liveLoadPanel.agent`,`Agent`)}),f(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),f(`th`,{className:`text-right px-3 py-2`,children:n(`pipeline.liveLoadPanel.cameras`,`Cameras`)}),f(`th`,{className:`text-right px-3 py-2`,children:n(`pipeline.liveLoadPanel.inferenceMs`,`Inference ms`)}),f(`th`,{className:`text-right px-3 py-2`,children:n(`pipeline.liveLoadPanel.queue`,`Queue`)}),f(`th`,{className:`text-right px-3 py-2`,children:n(`pipeline.liveLoadPanel.audio`,`Audio`)})]})}),o(`tbody`,{children:[h.map(([e,t])=>o(`tr`,{className:`border-t border-border`,children:[f(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:p.get(e)??e}),f(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),f(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),f(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),f(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),f(`td`,{className:`px-3 py-2 text-right text-foreground`,children:u.get(e)??`—`})]},e)),h.length===0&&f(`tr`,{children:f(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:n(`pipeline.liveLoadPanel.noCameraMetricsReceivedYet`,`No camera metrics received yet`)})})]})]})})]})}function Y({label:e,value:t}){return o(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[f(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),f(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}var Kn={active:!1,pinned:!1,nodeId:null,reason:``};function qn(e,t){return e.deviceName.localeCompare(t.deviceName)||e.deviceId-t.deviceId}function Jn(e,t,n){let r=new Map(t.map(e=>[e.deviceId,e])),i=new Map(n.map(e=>[e.deviceId,e]));return e.map(e=>{let t=r.get(e.id),n=i.get(e.id),a=t?{active:!0,pinned:t.pinned,nodeId:t.agentNodeId,reason:t.reason??``}:Kn,o=n?{active:!0,pinned:n.pinned,nodeId:n.nodeId,reason:``}:Kn;return{deviceId:e.id,deviceName:e.name,disabled:e.disabled===!0,pipeline:a,detection:a,decoder:Kn,audio:o}}).toSorted(qn)}function Yn(e,t,n){return{active:e!==null,pinned:t,nodeId:e,reason:n??``}}function Xn(e,t){let n=new Map(t.map(e=>[e.deviceId,e.assignment]));return e.map(e=>{let t=n.get(e.deviceId);return t===void 0?e:{...e,detection:Yn(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:Yn(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:Yn(t.audioNodeId,t.pinned.audio,t.reasons.audio)}})}function Zn(e,t,n){let r=(t,n,r)=>({active:t!==null&&t===e,pinned:n,nodeId:t,reason:r??``});return t.map(({deviceId:e,assignment:t})=>({deviceId:e,deviceName:n(e),detection:r(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:r(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:r(t.audioNodeId,t.pinned.audio,t.reasons.audio)})).filter(e=>e.detection.active||e.decoder.active||e.audio.active).toSorted(qn)}function Qn(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>{let n=t.get(e);return n!==void 0&&n!==``?n:e}}function $n(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>t.get(e)??q.t(`helpers.assignmentRows.cameraFallback`,{id:e})}function er(e,t,n){let r=[...new Set([...e.nodeId===null?[]:[e.nodeId],...t.map(e=>e.id)])];return[{value:`auto`,label:q.t(`helpers.assignmentRows.auto`)},...r.map(e=>({value:e,label:q.t(`helpers.assignmentRows.pinTo`,{node:n(e)})}))]}function tr({roleId:e,roleLabel:t,state:n,nameOf:r,colorByNodeId:i,emphasizeOnNodeId:a}){if(n.nodeId===null)return null;let o=n.nodeId,s=a===void 0?!1:n.active&&o===a;return f(jt,{roleId:e,roleLabel:t,nodeName:r(o),colorId:lt(i,o),emphasized:s,pinned:n.pinned})}function nr({detection:e,decoder:t,audio:n,nameOf:r,colorByNodeId:i,emphasizeOnNodeId:a}){let s=(e,t,n)=>f(tr,{roleId:e,roleLabel:t,state:n,nameOf:r,colorByNodeId:i,emphasizeOnNodeId:a},e);return o(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[s(`detection`,`Detection`,e),s(`decode`,`Decode`,t),s(`audio`,`Audio`,n)]})}function rr({snap:e}){let t=M(),{t:n}=J();if(e===void 0)return f(`div`,{className:`flex h-8 items-center text-[11px] text-foreground-subtle`,title:n(`assignments.assignmentStatusCell.noMetricsInTheLast`,`No metrics in the last 10 s — the camera has no session running`),children:n(`assignments.assignmentStatusCell.noLiveData`,`no live data`)});let{phase:r,actualFps:i,avgInferenceTimeMs:a,queueDepth:s,configuredFps:c,droppedFrames:l}=e.metrics,u=kt(r,t);return o(`div`,{className:`flex h-8 min-w-0 flex-col justify-center font-mono text-[10px] leading-tight tabular-nums`,children:[o(`span`,{className:`inline-flex min-w-0 items-center gap-1 ${u.textColor}`,children:[f(on,{phase:r,className:`h-2.5 w-2.5 shrink-0`}),f(`span`,{className:`truncate font-semibold uppercase tracking-wider`,children:u.label}),f(`span`,{className:`text-foreground`,children:i.toFixed(1)}),f(`span`,{className:`text-foreground-subtle`,children:n(`pipeline.assignmentStatusCell.configuredFps`,{fps:c.toFixed(0)})})]}),o(`span`,{className:`truncate text-foreground-subtle`,children:[f(`span`,{className:`text-foreground`,children:a.toFixed(0)}),` ms`,s>0&&o(`span`,{className:`ml-1 text-warning`,children:[`q`,s]}),f(`span`,{className:l>0?`ml-1 text-warning`:`ml-1`,children:n(`pipeline.assignmentStatusCell.drops`,{count:l})})]})]})}t();var ir=1e4,ar=5e3;function or(e){let[t,r]=i(new Map);return St(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e!==void 0&&n.nodeId!==e||r(e=>new Map(e).set(n.deviceId,n)))}),n(()=>{if(t.size===0)return;let e=setInterval(()=>{r(e=>{let t=Date.now()-ir,n=[...e].filter(([,e])=>e.timestamp>=t);return n.length===e.size?e:new Map(n)})},ar);return()=>clearInterval(e)},[t.size]),t}var sr=3e5;function cr({state:e,onlineNodes:t,nameOf:n,pending:r,onChange:i}){let{t:a}=J();return f(W,{"aria-label":a(`assignments.placementControls.nodePin`,`Node pin`),title:a(`assignments.placementControls.autoLetsEachSessionPick`,`Auto lets each session pick its node; a pin keeps the camera on one node.`),value:e.pinned&&e.nodeId!==null?e.nodeId:`auto`,disabled:r,options:[...er(e,t,n)],onChange:e=>i(e.target.value)})}function lr({deviceId:e,nodeId:t}){let{t:n}=J(),r=l(),{data:i}=At({deviceId:e},{refetchOnMount:`always`}),{data:a}=Et({nodeId:t},{staleTime:sr}),o=pt({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(i===void 0||a===void 0)return f(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:n(`assignments.placementControls.accelerator`,`accelerator: …`)});let s=a.devices??[],c=s.filter(e=>e.enabled),u=i?.deviceKey??`auto`,d=u!==`auto`&&!c.some(e=>e.key===u),p=s.find(e=>e.key===u),m=[{value:`auto`,label:n(`assignments.placementControls.anyAccelerator`,`Any accelerator`)},...d?[{value:u,label:n(`pipeline.placementControls.notEnabled`,{name:p?`${gt(p)} (${u})`:u})}]:[],...c.map(e=>({value:e.key,label:`${gt(e)} · ${e.format}`}))];return f(W,{"aria-label":n(`assignments.placementControls.inferenceDevicePin`,`Inference device pin`),title:n(`assignments.placementControls.pinDetectionToOneAccelerator`,`Pin detection to one accelerator of the node, or let each session pick.`),value:u,disabled:o.isPending,options:m,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value})})}t();function ur(e){let t=d(null);return e.nodeId!==null&&(t.current=e),t.current}function dr({deviceId:e,state:t,...n}){let{t:r}=J(),i=ur(t);return o(`div`,{className:`grid w-80 grid-cols-2 gap-1.5`,children:[f(cr,{state:t,...n}),i?.nodeId==null?f(W,{"aria-label":r(`assignments.clusterRowCells.inferenceDevicePinNoNode`,`Inference device pin (no node yet)`),title:r(`assignments.clusterRowCells.anAcceleratorIsPinnedOn`,`An accelerator is pinned on the camera's node; this camera has not run on one yet.`),disabled:!0,defaultValue:`auto`,options:[{value:`auto`,label:r(`assignments.clusterRowCells.anyAccelerator`,`Any accelerator`)}]}):f(lr,{deviceId:e,nodeId:i.nodeId})]})}function fr({state:e,nameOf:t}){let{t:n}=J(),r=ur(e);if(r?.nodeId==null)return f(`span`,{className:`text-[11px] text-foreground-subtle`,children:n(`assignments.clusterRowCells.noSessionYet`,`— no session yet`)});let i=e.active&&e.nodeId!==null,a=r.pinned?`pinned`:`auto · ${r.reason||`capacity`}`;return o(`div`,{"data-testid":`resolved-placement`,className:`flex w-40 min-w-0 flex-col leading-tight`,title:r.pinned?void 0:n(`assignments.clusterRowCells.anUnpinnedCameraIsPlaced`,`An unpinned camera is placed again at every session start, so this can change between sessions.`),children:[o(`span`,{className:`flex min-w-0 items-center gap-1.5 text-xs`,children:[f(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 shrink-0 rounded-full ${i?`bg-success`:`bg-foreground-subtle/40`}`}),f(`span`,{"data-testid":`resolved-placement-node`,className:`truncate font-medium ${i?`text-foreground`:`text-foreground-muted`}`,children:t(r.nodeId)})]}),f(`span`,{className:`truncate pl-3 text-[10px] ${r.pinned?`text-warning`:`text-foreground-subtle`}`,children:i?a:n(`assignments.clusterRowCells.idleLastSession`,`{{how}} · idle, last session`,{how:a})})]})}function pr({deviceId:e,deviceName:t}){let{t:n}=J(),[r,a]=i(!1);return o(s,{children:[f(Wt,{icon:B,variant:`ghost`,size:`sm`,"aria-label":n(`assignments.clusterRowCells.streamBrokersOf`,`Stream brokers of {{deviceName}}`,{deviceName:t}),title:n(`assignments.clusterRowCells.streamBrokersClients`,`Stream brokers & clients`),onClick:()=>a(!0)}),f(ot,{open:r,onOpenChange:a,children:o(Pt,{width:`lg`,scroll:`body`,placement:`sheet-on-mobile`,children:[f(rn,{children:f(Vt,{children:n(`pipeline.clusterRowCells.brokersTitle`,{device:t})})}),f(Fe,{children:r&&f(Ct,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:e,instanceId:`pipeline-row/${e}`,config:{variant:`compact`}})})]})})]})}function mr(e){return e.hasFreshMetrics?`active`:e.hasPipelineAssignment?`recently-active`:`inactive`}function hr(e,t){return t.size===0?!0:t.has(e)}var gr=[{value:`active`,get label(){return q.t(`helpers.cameraActivity.active`)}},{value:`recently-active`,get label(){return q.t(`helpers.cameraActivity.recentlyActive`)}},{value:`inactive`,get label(){return q.t(`helpers.cameraActivity.inactive`)}}];t();var _r=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`];function vr(e){for(let t of[`getPipelineAssignments`,`getAudioAssignments`,`getCameraStatuses`])e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,t]]})}function yr(){let{t:e}=J(),t=l();tn([`pipelineOrchestrator`,`getPipelineAssignments`],_r),tn([`pipelineOrchestrator`,`getAudioAssignments`],_r),tn([`pipelineOrchestrator`,`getCameraStatuses`],_r);let{data:n}=xt({isCamera:!0,projection:`slim`}),{data:a}=pn(void 0),{data:s}=an(void 0),{data:c}=Ft({}),{data:u}=Ve(void 0),{nodes:d}=H(),p=or(),m=r(()=>Qn(d),[d]),h=r(()=>dn(u),[u]),g=r(()=>d.filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[d]),_=r(()=>Xn(Jn((n??[]).map(e=>({id:e.id,name:e.name,disabled:e.disabled})),a??[],s??[]),c??[]),[n,a,s,c]),[v,y]=i(()=>new Set),b=r(()=>_.filter(e=>hr(mr({hasPipelineAssignment:e.pipeline.active,hasFreshMetrics:p.has(e.deviceId)}),v)),[_,p,v]),x=e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},S=()=>vr(t),C=Ot({onSuccess:S}),w=We({onSuccess:S}),T=C.isPending||w.isPending,E=[{key:`camera`,header:e(`pipeline.cameraAssignmentsTable.camera`,`Camera`),width:`w-44`,sortValue:e=>e.deviceName,render:t=>o(`div`,{className:`flex w-44 min-w-0 items-center gap-1.5`,children:[f(hn,{to:`/devices/${String(t.deviceId)}`,className:`min-w-0 truncate text-xs font-medium text-primary hover:underline`,title:t.deviceName,children:t.deviceName}),t.disabled&&f(U,{variant:`default`,children:e(`common.off`)})]})},{key:`placement`,header:e(`pipeline.cameraAssignmentsTable.placement`,`Placement`),width:`w-80`,notSortableReason:`A pair of controls — editing one would move the row under the cursor.`,render:e=>f(dr,{deviceId:e.deviceId,state:e.pipeline,onlineNodes:g,nameOf:m,pending:T,onChange:t=>t===`auto`?w.mutate({deviceId:e.deviceId}):C.mutate({deviceId:e.deviceId,agentNodeId:t})})},{key:`roles`,header:e(`pipeline.cameraAssignmentsTable.rolesHere`,`Roles here`),notSortableReason:`A set of roles has no single order.`,render:e=>f(nr,{detection:e.detection,decoder:e.decoder,audio:e.audio,nameOf:m,colorByNodeId:h})},{key:`resolved`,header:e(`pipeline.cameraAssignmentsTable.runningOn`,`Running on`),width:`w-40`,sortValue:e=>e.pipeline.nodeId===null?null:m(e.pipeline.nodeId),render:e=>f(fr,{state:e.pipeline,nameOf:m})},{key:`status`,header:e(`pipeline.cameraAssignmentsTable.status`,`Status`),width:`w-40`,sortValue:e=>p.get(e.deviceId)?.metrics.actualFps??null,render:e=>f(rr,{snap:p.get(e.deviceId)})},{key:`brokers`,header:``,align:`right`,width:`w-10`,notSortableReason:`An action`,render:e=>f(pr,{deviceId:e.deviceId,deviceName:e.deviceName})}],D=n===void 0?`Loading cameras…`:_.length===0?`No cameras`:`No cameras match this activity filter.`;return o(`div`,{className:`flex flex-col gap-2`,children:[f(`nav`,{"aria-label":e(`pipeline.cameraAssignmentsTable.filterByCameraActivity`,`Filter by camera activity`),"data-testid":`assignments-activity-filter`,children:f(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:gr.map(e=>{let t=v.has(e.value);return f(`button`,{type:`button`,"aria-pressed":t,"data-testid":`assignments-activity-${e.value}`,className:ct(se,t?oe:k),onClick:()=>x(e.value),children:e.label},e.value)})})}),f(Rt,{columns:E,rows:b,rowKey:e=>e.deviceId,minWidthPx:920,maxBodyHeight:Dt,emptyMessage:D})]})}t();function br({nodeId:e}){let{t}=J(),n=l();tn([`pipelineOrchestrator`,`getCameraStatuses`],_r);let{data:i}=Ft({}),{data:a}=Ve(void 0),{data:o}=xt({isCamera:!0,projection:`slim`}),{nodes:s}=H(),c=or(),u=r(()=>Qn(s),[s]),d=r(()=>dn(a),[a]),p=r(()=>Zn(e,i??[],$n((o??[]).map(e=>({id:e.id,name:e.name})))),[e,i,o]),m=s.filter(t=>t.isOnline&&t.id!==e),h=()=>vr(n),g=Ot({onSuccess:h}),_=We({onSuccess:h}),v=Bt({onSuccess:h}),y=ht({onSuccess:h}),b=e=>[...e.detection.active?m.map(n=>({id:`detect-${n.id}`,label:t(`pipeline.nodeCameraAssignmentsTable.moveDetectionTo`,`Move detection to {{name}}`,{name:n.name}),onClick:()=>g.mutate({deviceId:e.deviceId,agentNodeId:n.id})})):[],...e.audio.active?m.map(n=>({id:`audio-${n.id}`,label:t(`pipeline.nodeCameraAssignmentsTable.moveAudioTo`,`Move audio to {{name}}`,{name:n.name}),onClick:()=>v.mutate({deviceId:e.deviceId,nodeId:n.id})})):[],{id:`unpin-detect`,label:t(`pipeline.nodeCameraAssignmentsTable.unpinDetection`,`Unpin detection`),hidden:!(e.detection.active&&e.detection.pinned),separatorBefore:!0,onClick:()=>_.mutate({deviceId:e.deviceId})},{id:`unpin-audio`,label:t(`pipeline.nodeCameraAssignmentsTable.unpinAudio`,`Unpin audio`),hidden:!(e.audio.active&&e.audio.pinned),onClick:()=>y.mutate({deviceId:e.deviceId})}];return f(Rt,{columns:[{key:`camera`,header:t(`pipeline.nodeCameraAssignmentsTable.camera`,`Camera`),width:`w-44`,sortValue:e=>e.deviceName,render:e=>f(hn,{to:`/devices/${String(e.deviceId)}`,className:`block w-44 truncate text-xs font-medium text-primary hover:underline`,title:e.deviceName,children:e.deviceName})},{key:`roles`,header:t(`pipeline.nodeCameraAssignmentsTable.rolesHere`,`Roles here`),notSortableReason:`A set of roles has no single order.`,render:t=>f(nr,{detection:t.detection,decoder:t.decoder,audio:t.audio,nameOf:u,colorByNodeId:d,emphasizeOnNodeId:e})},{key:`status`,header:t(`pipeline.nodeCameraAssignmentsTable.status`,`Status`),width:`w-40`,sortValue:e=>c.get(e.deviceId)?.metrics.actualFps??null,render:e=>f(rr,{snap:c.get(e.deviceId)})},{key:`actions`,header:``,align:`right`,width:`w-10`,notSortableReason:`Actions`,render:e=>f(zt,{items:b(e),title:t(`pipeline.nodeCameraAssignmentsTable.move`,`Move {{deviceName}}`,{deviceName:e.deviceName})})}],rows:p,rowKey:e=>e.deviceId,minWidthPx:560,maxBodyHeight:Dt,emptyMessage:i===void 0?t(`pipeline.nodeCameraAssignmentsTable.loadingCameras`,`Loading cameras…`):t(`pipeline.nodeCameraAssignmentsTable.noCameraRunsOnThis`,`No camera runs on this node right now`)})}function xr({nodeId:e,refreshToken:t}){let{t:n}=J(),{nodes:r}=H(),i=r.find(t=>t.id===e)?.name??e;return o(`div`,{className:`space-y-3 sm:space-y-4`,children:[f(Gn,{refreshToken:t,nodeId:e}),o(`div`,{className:`space-y-2`,children:[o(`div`,{children:[f(`h3`,{className:`text-sm font-semibold text-foreground`,children:n(`pipeline.nodeCamerasTab.camerasOn`,{node:i})}),f(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`pipeline.nodeCamerasTab.theRolesEachCameraRuns`,`The roles each camera runs here right now. Move a role or unpin it from the row menu; pins for every camera are on Cluster → Assignments.`)})]}),f(br,{nodeId:e})]})]})}t();function Sr(e,t){let n=Math.max(0,t-e),r=Math.floor(e/1e3),i=Math.floor(n/1e3);return q.t(`pipeline.nodeEnginesTab.idleLeft`,{idle:r,left:i})}function Cr({nodeId:e,refreshToken:t}){let{t:n}=J(),i=l(),a=Le(),s=sn({onSettled:()=>{i.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:c}=qt({nodeId:e}),u=en(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??c??null,d=u===null;tn([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:p}=Qt({nodeId:e}),{values:m}=Ze(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),h=r(()=>m.filter(e=>e.metrics.phase===`active`).length,[m]),_=t=>{let r=p??[];if(r.length===0){s.mutate({nodeId:e,engine:t,force:!1});return}(async()=>{await a({title:n(`pipeline.nodeEnginesTab.killEngine`,`Kill engine`),message:`${String(r.length)} camera(s) are dispatching through this engine. Killing it drops their in-flight work and forces a respawn on the next frame.`,confirmLabel:n(`pipeline.nodeEnginesTab.killEngine`,`Kill engine`),variant:`danger`})&&s.mutate({nodeId:e,engine:t,force:!0})})()};return o(`div`,{className:`space-y-6`,children:[o(`div`,{children:[f(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:n(`pipeline.nodeEnginesTab.inferenceEnginesOnThisNode`,`Inference engines on this node`)}),f(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`pipeline.nodeEnginesTab.summary`,{engines:(u??[]).length,cameras:(p??[]).length,active:h})})]}),f(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:o(`table`,{className:`w-full text-xs min-w-[640px]`,children:[f(`thead`,{className:`bg-surface`,children:o(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[f(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:n(`pipeline.nodeEnginesTab.kind`,`Kind`)}),f(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:n(`pipeline.nodeEnginesTab.runtimeBackendDevice`,`Runtime / Backend / Device`)}),f(`th`,{className:`text-left px-3 py-2`,children:n(`pipeline.nodeEnginesTab.models`,`Models`)}),f(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:n(`pipeline.nodeEnginesTab.poolPid`,`Pool PID`)}),f(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:n(`pipeline.nodeEnginesTab.autoKill`,`Auto-kill`)}),f(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:n(`pipeline.nodeEnginesTab.inUse`,`In use`)}),f(`th`,{className:`w-20`})]})}),o(`tbody`,{children:[d&&f(`tr`,{children:f(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:n(`common.loading`,`Loading…`)})}),!d&&(u??[]).map(e=>{let t=e.kind===`device-pool`;return o(`tr`,{className:`border-t border-border ${t?`bg-primary/[0.05]`:``}`,children:[f(`td`,{className:`px-3 py-2`,children:o(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[f(t?Ne:E,{className:`h-3 w-3`}),n(t?`pipeline.nodeEnginesTab.pool`:`pipeline.nodeEnginesTab.runtime`)]})}),f(`td`,{className:`px-3 py-2`,children:o(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[f(ae,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),f(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?f(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):f(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>f(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),f(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),f(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?f(`span`,{className:`text-foreground-subtle`,children:Sr(e.idleMs,e.idleTtlMs)}):f(`span`,{className:`text-foreground-subtle/50`,children:n(`common.never`)})}),f(`td`,{className:`px-3 py-2 text-right text-foreground`,children:(p??[]).length}),f(`td`,{className:`px-3 py-2 text-right`,children:t?f(`span`,{className:`text-[11px] text-foreground-subtle`,children:n(`common.auto`)}):o(G,{variant:`ghost`,size:`sm`,disabled:s.isPending,onClick:()=>_(e.engine),className:`text-danger hover:bg-danger/10 hover:text-danger`,children:[f(g,{className:`h-3.5 w-3.5`}),n(`pipeline.nodeEnginesTab.kill`,`Kill`)]})})]},e.engineKey)}),!d&&(u??[]).length===0&&f(`tr`,{children:f(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:n(`pipeline.nodeEnginesTab.noEnginesResidentTheFactory`,`No engines resident — the factory spins up on the first pipeline run.`)})})]})]})}),f(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:f(gn,{i18nKey:`pipeline.nodeEnginesTab.legend`,components:{strong:f(`strong`,{className:`text-foreground`})}})}),s.isError&&f(It,{message:n(`pipeline.nodeEnginesTab.killFailed`,{message:s.error instanceof Error?s.error.message:n(`common.unknownError`)})})]})}var wr=`pipeline-runner`,Tr=200;function Er({nodeId:e}){let{t}=J();return o(`div`,{className:`flex flex-col gap-3`,children:[o(`div`,{children:[f(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:t(`pipeline.nodeLogsTab.runnerLogs`,`Runner logs`)}),f(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`pipeline.nodeLogsTab.description`,{node:e})})]}),f(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:f(Tt,{agentId:e,addonId:wr,limit:Tr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1,showSourceSelect:!0})})]})}t();function Dr({nodeId:e,title:t}){let n=M(),{t:i}=J(),{data:a}=mn(),{data:s}=pn(void 0),c=r(()=>{let e=new Map;for(let t of a??[])e.set(t.id,t.name);return e},[a]),l=r(()=>{if(!e)return null;let t=new Set;for(let n of s??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,s]),u=or(e),d=r(()=>{let e=[];for(let t of u.values())l&&!l.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[u,l]);return d.length===0?o(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??i(`pipeline.cameraStatusStrip.cameras`,`Cameras`),`: no live snapshots yet`]}):o(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[o(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[f(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??i(`pipeline.cameraStatusStrip.cameras`,`Cameras`)}),f(`span`,{className:`text-[10px] text-foreground-subtle`,children:d.length})]}),f(`div`,{className:`flex flex-wrap gap-1.5`,children:d.map(e=>{let t=c.get(e.deviceId)??`#${e.deviceId}`,r=kt(e.metrics.phase,n);return o(`div`,{title:i(`pipeline.cameraStatusStrip.fpsMsInferQ`,`{{name}} · {{label}} · {{value3}} fps · {{value4}}ms infer · q={{queueDepth}}`,{name:t,label:r.label,value3:e.metrics.actualFps.toFixed(1),value4:e.metrics.avgInferenceTimeMs.toFixed(0),queueDepth:e.metrics.queueDepth}),className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${r.badgeClass}`,children:[f(on,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),f(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),f(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),f(`span`,{className:`opacity-60`,children:i(`common.fpsWord`)})]},e.deviceId)})})]})}function Or(e,t,n){return e.map(e=>{if(e.key===t)return e;let r=e.steps[n];if(!r||r.settings===void 0)return e;let{settings:i,...a}=r,o={...e.steps};return Object.keys(a).length>0?o[n]=a:delete o[n],{...e,steps:o}})}function kr(e,t,n){let r=e.filter(e=>e.key!==t).toSorted((e,t)=>e.key.localeCompare(t.key)),i=[...r.filter(e=>!e.enabled),...r.filter(e=>e.enabled),...e.filter(e=>e.key===t)],a;for(let e of i){let t=e.steps?.[n]?.settings;!t||Object.keys(t).length===0||(a={...a,...t})}return a}function Ar(e){let t={};for(let n of e){let e=Object.keys(n.steps).length>0;t[n.key]={enabled:n.enabled,weight:Math.max(1,n.weight),...n.maxSessions!==null&&n.maxSessions>0?{maxSessions:n.maxSessions}:{},...e?{steps:n.steps}:{}}}return t}var jr=`pipeline-orchestrator`;function Mr({addonId:e,highlightLabel:t}){let{t:n}=J(),r=xe(e),{data:i}=Xe({addonId:jr});if(r.length===0)return null;let a=me(i??null)[e]??{};return o(`section`,{className:`space-y-1.5 border-t border-border/60 pt-3`,"aria-label":n(`stepInspector.clusterOwnedSettings.clusterWideSettings`,`Cluster-wide settings`),children:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[f(`h3`,{className:w,children:n(`stepInspector.clusterOwnedSettings.clusterWideSettings`,`Cluster-wide settings`)}),f(hn,{to:zo(e),className:`ml-auto text-[11px] text-primary hover:underline`,children:n(`stepInspector.clusterOwnedSettings.editInClusterSettings`,`Edit in Cluster → Settings ›`)})]}),r.map(e=>o(`div`,{className:`${p} rounded px-2 ${t===e.label?`bg-primary/5 ring-1 ring-primary/40`:``}`,children:[f(`span`,{className:L,children:e.label}),f(`span`,{className:_,children:f(`span`,{className:`font-mono text-xs text-foreground`,children:String(a[e.key]??e.default)})})]},e.key)),f(`p`,{className:V,children:n(`stepInspector.clusterOwnedSettings.oneValueForEveryNode`,`One value for every node and camera — this step writes into a shared index.`)})]})}function Nr({rows:e}){let{t}=J();return o(`div`,{className:`space-y-1.5`,"data-testid":`effective-models`,children:[f(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.map(e=>o(`li`,{className:`${C} flex flex-wrap items-baseline gap-x-2 text-xs`,children:[f(`span`,{className:`min-w-0 flex-1 truncate text-foreground-muted`,children:e.label}),f(`span`,{className:`font-mono text-foreground`,children:e.modelId??`—`}),f(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.sourceLabel})]},e.id))}),f(`p`,{className:V,children:t(`stepInspector.effectiveModelSummary.toChangeAModelOpen`,`To change a model, open that accelerator's cell in the table.`)})]})}t();function Pr(e,t){let[n,i]=_n(),o=n.get(Mn),s=n.get(`acc`),c=r(()=>Fn(e,t,{step:o,acc:s}),[e,t,o,s]),l=a(e=>{i(t=>{let n=new URLSearchParams(t);return e(n),n},{replace:!0})},[i]);return{selection:c,open:a(e=>l(t=>{t.set(Mn,e.stepId),e.acceleratorId===void 0?t.delete(`acc`):t.set(`acc`,e.acceleratorId)}),[l]),close:a(()=>l(e=>{e.delete(Mn),e.delete(`acc`)}),[l])}}function Fr(e,t){for(let n of e?.slots??[])for(let e of n.addons)if(e.id===t)return e;return null}function Ir(e){return e.split(`.`)[0]??e}function Lr(e,t,n){return{id:Pn(e,n.key),nodeId:e,deviceKey:n.key,device:n,label:`${Ir(t)} · ${gt(n)}`,shortLabel:`${Ir(t)} · ${Ge(n)}`,nodeLabel:Ir(t),disabled:!n.enabled}}function Rr(e,t,n,r=!1){return n.filter(e=>r||e.enabled).map(n=>Lr(e,t,n))}function zr(e,t,n=!1){return e.flatMap(e=>{let r=t[e.id]??[];if(n)return r.map(t=>Lr(e.id,e.name,t));let i=r.filter(e=>e.enabled&&e.available);if(i.length>0)return i.map(t=>Lr(e.id,e.name,t));let a=r.find(e=>e.available)??r[0];return a===void 0?[]:[Lr(e.id,e.name,a)]})}function Br(e,t,n){return{modelId:Be({catalog:e,device:t.device,base:n.nodePin,override:n.cameraPin}),source:n.cameraPin===void 0?n.nodePin===void 0?`default`:`node`:`camera`}}function Vr(e,t,n){let r=Fr(e,`object-detection`);if(r===null)return;let i=Be({catalog:r,device:t.device,base:t.device.steps?.[`object-detection`]?.modelId,override:n});if(i===void 0)return;let a=r.models.find(e=>e.id===i);return{modelId:i,name:a?.name??i,supplies:a?.suppliesSteps??[]}}function Hr(e,t,n){return!_e(e)||n===void 0?!1:be(e,t,n.supplies).effective}function Ur(e,t){return e!==null&&mt(e.models,t.device.format)}function Wr(e){return Ur(e.addon,e.acc)?e.clusterModelId===void 0?{kind:`enabled`,modelId:e.model.modelId??`Auto`,overridden:e.model.source===`camera`,...e.rootName===void 0?{}:{suppliedByRoot:e.rootName},...e.jumpTo===void 0?{}:{jumpTo:e.jumpTo}}:{kind:`enabled`,modelId:e.clusterModelId,clusterWide:!0}:e.gatedOn?e.jumpTo===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:e.jumpTo}:{kind:`na`}}function Gr(e){return Object.values(e).reduce((e,t)=>e+t.filter(e=>!e.enabled).length,0)}function Kr(e){if(e===null)return[];let t=(e.configSchema??[]).flatMap(e=>`label`in e&&typeof e.label==`string`?[e.label]:[]),n=xe(e.id).map(e=>e.label);return[...new Set([...t,...n])]}function qr(e){return e.flatMap(e=>[{node:e,depth:0},...qr(e.children).map(e=>({node:e.node,depth:e.depth+1}))])}function Jr(e,t){return e.flatMap(e=>{let n=Jr(e.children,t);return t.has(e.addonId)||n.length>0?[{...e,children:n}]:[]})}t();function Yr(e){return{agentNodeId:e.nodeId,nodeLabel:e.nodeLabel,engineLabel:e.device.format,deviceKey:e.deviceKey,deviceLabel:gt(e.device),detail:e.device.defaultModelId,disabled:e.disabled}}function Xr({tree:e,searchRows:t,accelerators:n,cellState:s,stepBadge:c,disabledCount:l,showDisabled:u,onShowDisabledChange:p,dirty:m,onDiscard:h,summary:g,toolbar:_,label:v,renderDetail:y}){let{t:b}=J(),x=Le(),S=tt(),{selection:C,open:w,close:T}=Pr(r(()=>qr(e).map(e=>e.node.addonId),[e]),r(()=>n.map(e=>e.id),[n])),[E,D]=i(``),[O,k]=i(null),[A,j]=i(null),M=d(null),N=d(null),P=d(null),I=d(null),L=r(()=>Zt(t,E),[t,E]),R=r(()=>E.trim()===``?e:Jr(e,new Set(L.map(e=>e.addonId))),[e,L,E]),ee=e=>L.find(t=>t.addonId===e)?.matchedField??null,te=r(()=>n.map(Yr),[n]),ne=e=>n.find(t=>t.nodeId===e.agentNodeId&&t.deviceKey===e.deviceKey),z=n.find(e=>e.id===C.acceleratorId)??null,re=C.stepId!==null,ie=a(async e=>{if(m){if(!await x({title:b(`stepInspector.stepMatrixFrame.discardUnsavedChanges`,`Discard unsaved changes?`),message:b(`stepInspector.stepMatrixFrame.thisStepHasChangesThat`,`This step has changes that are not saved yet.`),confirmLabel:b(`stepInspector.stepMatrixFrame.discard`,`Discard`),variant:`danger`}))return;h()}e()},[x,m,h,b]),ae=()=>{requestAnimationFrame(()=>I.current?.focus())},oe=(e,t,n=!1)=>{if(e===C.stepId&&(t?.id??null)===C.acceleratorId){n&&ae();return}let r=()=>{k(ee(e)),w({stepId:e,...t===void 0?{}:{acceleratorId:t.id}}),n&&ae()};e===C.stepId?r():ie(r)},B=()=>{let e=C.stepId;ie(()=>{if(T(),e!==null){let t=z===null?null:ut({agentNodeId:z.nodeId,deviceKey:z.deviceKey});requestAnimationFrame(()=>M.current?.focusCell(e,t))}})},se=e=>{if(e.key===`Enter`){let t=L[0];if(t===void 0)return;e.preventDefault(),oe(t.addonId,void 0,!0)}else e.key===`Escape`&&D(``)},ce=S?f(vt,{onClick:B}):f(Wt,{icon:F,variant:`ghost`,size:`sm`,"aria-label":b(`common.close`,`Close`),onClick:B});return o(`div`,{ref:N,className:`space-y-2`,onKeyDown:e=>{let t=e.target instanceof HTMLElement&&e.target.dataset.r!==void 0;e.key===`/`&&t&&(e.preventDefault(),P.current?.focus()),e.key===`Escape`&&t&&re&&(e.preventDefault(),B())},children:[o(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[f(`div`,{className:`min-w-0 basis-full sm:basis-auto`,children:g}),f(`input`,{ref:P,type:`search`,value:E,onChange:e=>D(e.target.value),onKeyDown:se,placeholder:b(`stepInspector.stepMatrixFrame.filterStepsOrSettings`,`Filter steps or settings /`),"aria-label":b(`stepInspector.stepMatrixFrame.filterStepsOrSettings2`,`Filter steps or settings`),className:`h-9 w-56 rounded-md border border-border bg-background px-2 text-xs text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30 md:h-7`}),l>0&&o(`label`,{className:`inline-flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[f(nt,{checked:u,onChange:e=>p(e.target.checked)}),b(`stepInspector.stepMatrixFrame.showDisabled`,{count:l})]}),_]}),C.staleStepId!==null&&f(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:b(`stepInspector.stepMatrixFrame.staleStep`,{id:C.staleStepId})}),R.length===0?f(`p`,{className:`${V} rounded-md border border-dashed border-border px-3 py-4 text-center`,children:b(`stepInspector.stepMatrixFrame.noStepMatches`,{query:E})}):f(fn,{ref:M,tree:R,agents:te,label:v,getCellState:(e,t)=>{let n=ne(t);return n===void 0?{kind:`na`}:s(e,n)},onCellClick:(e,t,n)=>oe(e,ne(t),n),onStepClick:(e,t)=>oe(e,void 0,t),...c===void 0?{}:{stepBadge:c},selectedCell:re&&C.stepId!==null&&z!==null?{addonId:C.stepId,agentNodeId:z.nodeId,deviceKey:z.deviceKey}:null,fallbackNodeId:A,onFallbackNodeChange:j,reserveRightPx:re&&!S?432:0}),f(at,{open:re,anchor:N,onClose:B,label:b(`stepInspector.stepMatrixFrame.stepSettings`,`Step settings`),children:C.stepId!==null&&y({stepId:C.stepId,accelerator:z,matchedField:O,closeButton:ce,onEscape:B,headingRef:e=>{I.current=e}})})]})}t();function Zr(e){n(()=>{if(e===null)return;let t=document.getElementById(e);t===null||typeof t.scrollIntoView!=`function`||t.scrollIntoView({block:`center`,behavior:`smooth`})},[e])}t();function Qr(e,t){let n=e.filter(e=>e.steps?.[t]?.settings!==void 0),r=e=>e.toSorted((e,t)=>e.key.localeCompare(t.key));return r(n.filter(e=>e.enabled))[0]?.key??r(n)[0]?.key??r(e.filter(e=>e.enabled))[0]?.key??e[0]?.key}function $r(e,t){let n=t.settings===void 0?void 0:Qr(e,t.stepId),r=e.map(e=>{let r={...e.steps},i=r[t.stepId]??{},a=t.models[e.key],o=t.jumps[e.key],s=e.key===n&&t.settings!==void 0?Object.keys(t.settings).length>0?t.settings:void 0:i.settings,c=a===void 0?i.modelId:a??void 0,l=o===void 0?i.jumpDeviceKey:o||void 0,u={...c===void 0?{}:{modelId:c},...s===void 0?{}:{settings:s},...l===void 0?{}:{jumpDeviceKey:l}};return Object.keys(u).length>0?r[t.stepId]=u:delete r[t.stepId],{key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:r}});return n===void 0?r:Or(r,n,t.stepId)}function ei(e,t,n){if(t===null)return 0;let r=Object.entries(t.models).filter(([n,r])=>(r??void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.modelId).length,i=Object.entries(t.jumps).filter(([n,r])=>(r||void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.jumpDeviceKey).length,a=new Set([...Object.keys(n),...Object.keys(t.settings??{})]),o=t.settings===void 0?0:[...a].filter(e=>!ve(n[e],t.settings?.[e])).length;return r+i+o}function ti({nodeId:e,nodeName:t,toolbar:n}){let{t:a}=J(),c=l(),u=Et({nodeId:e},{refetchOnMount:`always`}),d=Nt({nodeId:e},{refetchOnMount:`always`}),p=he(Xe({addonId:`pipeline-orchestrator`}).data??null),m=u.data?.devices??[],h=d.data??null,[g,_]=i(null),[v,y]=i(null),[b,x]=i(null),S=Ie({onSuccess:()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),C=r(()=>h?Qe(h):[],[h]),T=r(()=>qr(C),[C]),[E,D]=i(!1),O=r(()=>Rr(e,t,m,E),[e,t,m,E]),k=r(()=>Rr(e,t,m),[e,t,m]),A=k.length>=2,j=(e,t)=>(t===void 0?void 0:kr(m,t.deviceKey,e))??{},M=(e,t,n)=>{let r=n??t.device.steps?.[e?.id??``]?.jumpDeviceKey;if(r!==void 0&&r!==``)return k.find(e=>e.deviceKey===r);if(!Ur(e,t))return k.filter(n=>n.id!==t.id&&Ur(e,n)).toSorted((e,t)=>e.deviceKey.localeCompare(t.deviceKey))[0]},N=(e,t)=>{let n=Fr(h,e),r=Ho(e),i=Vr(h,t),a=j(e,t),o=M(n,t);return Wr({addon:n,acc:t,gatedOn:n?.enabledByDefault??!0,model:n?Br(n,t,{nodePin:t.device.steps?.[e]?.modelId}):{modelId:void 0,source:`default`},...Hr(e,a,i)&&i?{rootName:i.name}:{},...r?{clusterModelId:p[e]??r.defaultModelId}:{},...o?{jumpTo:Ge(o.device)}:{}})},P=T.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:Kr(Fr(h,e.addonId))}));if(u.isLoading||d.isLoading)return f(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:a(`stepInspector.nodeStepInspector.loadingPipeline`,`Loading pipeline…`)});if(h===null)return f(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:a(`stepInspector.nodeStepInspector.catalogUnavailable`,`Catalog unavailable.`)});let F=o(`span`,{className:V,children:[a(`stepInspector.nodeStepInspector.accelerators`,`Accelerators:`),` `,f(`span`,{className:`text-foreground`,children:k.length>0?k.map(e=>Ge(e.device)).join(` · `):a(`stepInspector.nodeStepInspector.noneEnabled`,`none enabled`)}),m.some(e=>!e.enabled)&&o(s,{children:[` `,a(`stepInspector.nodeStepInspector.off`,`— off:`),` `,m.filter(e=>!e.enabled).map(Ge).join(`, `)]}),` `,`·`,` `,f(hn,{to:Bo(),className:`text-primary hover:underline`,children:a(`stepInspector.nodeStepInspector.clusterLoadBalancing`,`Cluster → Load balancing ›`)})]});return f(Xr,{tree:C,searchRows:P,accelerators:O,cellState:N,disabledCount:m.filter(e=>!e.enabled).length,showDisabled:E,onShowDisabledChange:D,dirty:g!==null&&ei(m,g,j(g.stepId,O[0]))>0,onDiscard:()=>_(null),summary:F,...n===void 0?{}:{toolbar:n},label:a(`stepInspector.nodeStepInspector.detectionSteps`,`Detection steps`),renderDetail:({stepId:n,accelerator:r,matchedField:i,closeButton:c,onEscape:l,headingRef:u})=>{let d=Fr(h,n);if(d===null)return f(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:a(`stepInspector.nodeStepInspector.noStepSelected`,`No step selected.`)});let p=g?.stepId===n?g:null,C=r??k[0]??O[0],T=j(n,C),E=p?.settings??T,D=ei(m,p,T),N=e=>{x(null),_(t=>({...t?.stepId===n?t:{stepId:n,models:{},jumps:{}},...e}))},P=Ho(n),F=Je(d),I=C===void 0?void 0:Vr(h,C),L=e=>{let t=p?.models[e.deviceKey];return t===void 0?e.device.steps?.[n]?.modelId:t??void 0},R=C===void 0?void 0:Br(d,C,{nodePin:L(C)}).modelId,ee=O.length>1&&O.some(e=>!ve(j(n,e),T)),te=e=>{let t=L(e),r=Br(d,e,{nodePin:t}),i=Vr(h,e),c=Hr(n,p?.settings??j(n,e),i),l=p?.jumps[e.deviceKey],u=M(d,e,l),m=Ur(d,e)?c&&i?f(it,{rootModel:i,stepModelId:r.modelId}):void 0:o(s,{children:[a(`stepInspector.nodeStepInspector.noBuild`,{format:e.device.format}),` `,u?a(`stepInspector.nodeStepInspector.itRunsOnInstead`,`It runs on {{shortLabel}} instead.`,{shortLabel:u.shortLabel}):a(`stepInspector.nodeStepInspector.itDoesNotRunHere`,`It does not run here.`)]}),g=A?o(`label`,{className:`block space-y-1`,children:[f(`span`,{className:`text-[11px] font-medium text-foreground`,children:a(`stepInspector.nodeStepInspector.runOn`,`Run on`)}),f(W,{"aria-label":a(`stepInspector.nodeStepInspector.runOn`,`Run on`),value:l??e.device.steps?.[n]?.jumpDeviceKey??``,options:[{value:``,label:a(`stepInspector.nodeStepInspector.autoThisAcceleratorOrThe`,`Auto (this accelerator, or the next one that can run it)`)},...k.filter(t=>t.id!==e.id).map(e=>({value:e.deviceKey,label:`${e.label} · ${e.device.format}`}))],onChange:t=>N({jumps:{...p?.jumps,[e.deviceKey]:t.target.value}})}),f(`span`,{className:V,children:a(`stepInspector.nodeStepInspector.routesThisStepAndIts`,`Routes this step (and its child steps) to another accelerator of this node.`)})]}):void 0;return{label:e.label,format:e.device.format,modelId:r.modelId,source:r.source===`node`?`node`:`default`,sourceLabel:r.source===`node`?`node pin`:`hardware default`,models:qe(d.models??[],e.device.format),defaultModelId:d.defaultModelIdByFormat?.[e.device.format]??d.defaultModelId,expanded:v===e.id,onToggle:()=>y(t=>t===e.id?null:e.id),onChangeModel:t=>N({models:{...p?.models,[e.deviceKey]:t}}),...t===void 0?{}:{onReset:()=>N({models:{...p?.models,[e.deviceKey]:null}}),resetLabel:`Reset to hardware default`},...m===void 0?{}:{note:m},...g===void 0?{}:{extra:g},changed:p?.models[e.deviceKey]!==void 0||l!==void 0}},ne=()=>{p!==null&&S.mutate({agentNodeId:e,inferenceDevices:Ar($r(m,p))},{onSuccess:()=>{_(null),x({kind:`saved`})},onError:e=>x({kind:`error`,error:e.message})})};return f(bt,{ref:u,title:r===null?`${d.name} · ${t}`:`${d.name} · ${r.label}`,subtitle:r===null?a(`stepInspector.nodeStepInspector.everyAcceleratorOf`,`{{slot}} · every accelerator of {{nodeName}}`,{slot:d.slot,nodeName:t}):a(`stepInspector.nodeStepInspector.baseForEveryCameraThat`,`{{slot}} · {{format}} · base for every camera that lands here`,{slot:d.slot,format:r.device.format}),leading:c,onEscape:l,saveBar:{dirtyCount:D,saving:S.isPending,status:b?.kind??null,...b?.error===void 0?{}:{error:b.error},onSave:ne,onDiscard:()=>_(null)},children:o(`div`,{className:`space-y-3`,children:[o(`section`,{className:`space-y-2`,"aria-label":a(`stepInspector.nodeStepInspector.model`,`Model`),children:[f(`h3`,{className:w,children:a(`stepInspector.nodeStepInspector.model`,`Model`)}),P!==null&&C!==void 0?f(Uo,{step:P,engineFormat:C.device.format,runnableModelIds:qe(d.models??[],C.device.format).map(e=>e.id)}):O.length===0?f(`p`,{className:V,children:f(gn,{i18nKey:`stepInspector.nodeStepInspector.noAcceleratorEnabled`,components:{link:f(hn,{to:Bo(),className:`text-primary hover:underline`})}})}):r===null?f(Nr,{rows:O.map(e=>{let t=Br(d,e,{nodePin:L(e)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:t.source===`node`?`node pin`:`hardware default`}})}):f(Ye,{...te(r)},r.id)]}),(F.length>0||I!==void 0)&&P===null&&o(`section`,{"aria-label":a(`stepInspector.nodeStepInspector.settings`,`Settings`),className:`space-y-2 border-t border-border/60 pt-2`,children:[f(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`settings-scope`,children:a(`stepInspector.nodeStepInspector.nodeWideSettings`,{node:t})}),ee&&f(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-2 py-1 text-[11px] text-warning`,children:a(`stepInspector.nodeStepInspector.thisStepSSettingsDiffer`,`This step's settings differ between this node's accelerators. Saving makes the values shown here node-wide.`)}),f(ni,{addon:d,fields:F,settings:E,modelId:Ue(d,R,E,I),root:I,highlight:i,onChange:e=>N({settings:e})})]}),f(Mr,{addonId:n,highlightLabel:i})]})})}})}function ni({addon:e,fields:t,settings:n,modelId:r,root:i,highlight:a,onChange:o}){let s=t.find(e=>`label`in e&&e.label===a)?.key??null;return Zr(s===null?null:st(s)),f(et,{addon:e,fields:t,layers:{node:n},target:`node`,labels:{node:`Node`},modelId:r,...i===void 0?{}:{rootModel:i},highlightKey:s,onChangeLayer:o})}t();function ri({nodeId:e,refreshToken:t}){let{t:n}=J(),r=Le(),[a,c]=i(null),{nodes:l}=H(),u=l.find(t=>t.id===e)?.name??e,d=He({onSuccess:e=>{c(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),p=async()=>{await r({title:n(`pipeline.nodePipelineTab.resetToHardwareAwareDefaults`,`Reset {{nodeName}} to hardware-aware defaults?`,{nodeName:u}),message:n(`pipeline.nodePipelineTab.thisClearsEveryPerDevice`,`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:n(`common.reset`,`Reset`),variant:`danger`})&&(c(null),d.mutate({agentNodeId:e}))};return o(`div`,{className:`space-y-2`,children:[f(Dr,{nodeId:e}),f(ti,{nodeId:e,nodeName:u,toolbar:o(s,{children:[a&&f(`span`,{className:`text-[11px] text-success`,children:a}),d.isError&&f(`span`,{className:`text-[11px] text-danger`,children:d.error instanceof Error?d.error.message:n(`pipeline.nodePipelineTab.resetFailed`,`Reset failed`)}),f(G,{variant:`outline`,size:`sm`,onClick:()=>{p()},disabled:d.isPending,title:n(`pipeline.nodePipelineTab.clearThisNodeSPer`,`Clear this node's per-device model defaults + per-camera overrides scoped to this node`),children:d.isPending?n(`pipeline.nodePipelineTab.resetting`,`Resetting…`):n(`pipeline.nodePipelineTab.resetToDefault`,`Reset to default`)})]})})]})}var ii=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],ai=`decoder-nodeav`,oi=`ntab`,si={decoder:`engine`},ci={engine:`Engine & decoder`},li=`Nothing here is set per node. Cluster-wide values are on Cluster → Settings.`;function ui({nodeId:e,refreshToken:t}){let{t:n}=J(),[r,i]=_n(),{nodes:a}=H(),s=a.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??ai,c=[...ii,s],l=r.get(oi),u={assignments:{id:`assignments`,label:n(`pipeline.nodeDetail.assignments`,`Assignments`),order:-10,content:f(xr,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:n(`pipeline.nodeDetail.pipeline`,`Pipeline`),order:39,content:f(ri,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:n(`pipeline.nodeDetail.warmInstances`,`Warm instances`),order:180,content:f(Cr,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:n(`pipeline.nodeDetail.logs`,`Logs`),order:300,content:f(Er,{nodeId:e})}},d=Wn.map(e=>u[e]);return o(`div`,{className:`flex flex-col h-full`,children:[f(Un,{nodeId:e,refreshToken:t}),f(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6`,children:f(vn,{nodeId:e,addonIds:c,level:`global`,fieldScope:`perNode`,emptyMessage:li,tabAliases:si,tabLabelOverrides:ci,extraTabs:d,activeTab:l===null?null:si[l]??l,onActiveTabChange:e=>i(t=>{let n=new URLSearchParams(t);n.set(oi,e);for(let e of Nn)n.delete(e);return n},{replace:!0})})})]})}function di(){let{t:e}=J();return o(`div`,{className:`space-y-2`,children:[o(`div`,{className:`min-w-0`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground`,children:e(`pipeline.clusterAssignmentsTab.cameraPlacement`,`Camera placement`)}),f(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`pipeline.clusterAssignmentsTab.pinACameraToA`,`Pin a camera to a node, or to one accelerator of its node; Auto lets each session pick. Decode always runs with detection. Load, shares and caps are on Load balancing.`)})]}),f(yr,{})]})}function fi(e){return`${Math.round(e*100)}%`}function pi(e){return q.t(`helpers.autoTuneViewModel.sessions`,{count:e})}var mi={"intel-npu":`Intel NPU`,"intel-igpu":`Intel iGPU`,"amd-igpu":`AMD iGPU (WebGPU)`,"amd-npu":`AMD XDNA NPU`,"x86-cpu":`CPU`,"arm-cpu":`CPU`,"apple-ane":`Apple Neural Engine`,coral:`Coral Edge TPU`},hi={"intel-core-ultra":`Intel Core Ultra`,"intel-n-series":`Intel N-series`,"apple-m-base":`Apple M (base)`,"apple-m-pro":`Apple M Pro / Max / Ultra`,"amd-phoenix":`AMD Ryzen Phoenix / Hawk Point`,unknown:`Not measured`};function gi(e){return e===null?`—`:mi[e]??e}function _i(e){return e===null?`—`:hi[e]??e}function vi(e){switch(e.kind){case`capacity`:return q.t(`helpers.autoTuneViewModel.capacity`,{sessions:pi(e.sessions),min:e.minSessions});case`tie-faster`:return q.t(`helpers.autoTuneViewModel.tieFaster`,{over:e.over,recall:fi(e.recallDelta)});case`stepped-down`:return q.t(`helpers.autoTuneViewModel.steppedDown`,{from:e.from,limitedBy:e.limitedBy,to:e.to});case`no-fit-lightest`:return q.t(`helpers.autoTuneViewModel.noFitLightest`,{min:pi(e.minSessions),sessions:pi(e.sessions)});case`derived-latency`:return q.t(`helpers.autoTuneViewModel.derivedLatency`,{modelId:e.modelId});case`cpu-device`:return q.t(`helpers.autoTuneViewModel.cpuDevice`);case`device-disabled`:return q.t(`helpers.autoTuneViewModel.deviceDisabled`);case`device-unavailable`:return q.t(`helpers.autoTuneViewModel.deviceUnavailable`);case`node-offline`:return q.t(`helpers.autoTuneViewModel.nodeOffline`);case`no-hardware-facts`:return q.t(`helpers.autoTuneViewModel.noHardwareFacts`);case`no-measured-data`:return q.t(`helpers.autoTuneViewModel.noMeasuredData`);case`no-family-build`:return q.t(`helpers.autoTuneViewModel.noFamilyBuild`,{format:e.format});case`kept-custom-pin`:return q.t(`helpers.autoTuneViewModel.keptCustomPin`,{modelId:e.modelId,deviceKey:e.deviceKey})}}function yi(e,t){switch(e.kind){case`detector-store-cluster-wide`:return q.t(`helpers.autoTuneViewModel.detectorStoreClusterWide`,{nodes:e.skippedNodes.map(t).join(`, `)});case`detector-store-unreadable`:return q.t(`helpers.autoTuneViewModel.detectorStoreUnreadable`,{error:e.error});case`custom-pin-kept`:return e.deviceId===null?q.t(`helpers.autoTuneViewModel.customPinNode`,{node:t(e.nodeId),modelId:e.modelId,deviceKey:e.deviceKey??`—`}):q.t(`helpers.autoTuneViewModel.customPinCamera`,{deviceId:e.deviceId,modelId:e.modelId,node:t(e.nodeId)});case`custom-registry-unreadable`:return q.t(`helpers.autoTuneViewModel.customRegistryUnreadable`,{error:e.error})}}function bi(e){let t=e.nodeChanges.reduce((e,t)=>e+t.modelPins.length,0),n=e.nodeChanges.reduce((e,t)=>e+t.thresholds.length,0),r=new Set([...e.cameraClears.map(e=>e.deviceId),...e.detectorStoreClears.map(e=>e.deviceId)]);return{modelChanges:t,thresholdClears:n,cameraOverrideClears:e.cameraClears.length,detectorStoreClears:e.detectorStoreClears.length,camerasTouched:r.size}}function xi(e){let t=bi(e);return t.modelChanges+t.thresholdClears+t.cameraOverrideClears+t.detectorStoreClears===0}function Si(e,t,n){let r=e.nodeChanges.find(e=>e.nodeId===t&&e.deviceKey===n)?.modelPins.find(e=>e.stepId===`object-detection`);return r===void 0?null:{before:r.before,after:r.after}}function Ci(e,t){return e?.kind===`node-benchmark`?q.t(`helpers.autoTuneViewModel.latencyMeasured`,{date:new Date(e.measuredAtMs).toLocaleDateString(t,{day:`numeric`,month:`short`})}):q.t(`helpers.autoTuneViewModel.latencyTable`)}t();var wi=[.3,.4,.5];function Ti(e){return wi.some(t=>t===e)}var Ei=[1,2,3,4,6,8];function Di({plan:e,node:t,nodeName:n}){let{t:r}=J();return o(`section`,{className:b,"data-testid":`auto-tune-node-${t.nodeId}`,children:[o(`header`,{className:`${R} flex flex-wrap items-center gap-2`,children:[f(E,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),f(`h3`,{className:`${w} min-w-0 flex-1`,children:n(t.nodeId)}),o(`span`,{className:`text-[11px] text-foreground-subtle`,children:[_i(t.hardwareClass),t.cpuModel===null?``:` · ${t.cpuModel}`]}),t.skipped?f(U,{variant:`warning`,children:r(`pipeline.clusterAutoTuneTab.notChanged`,`Not changed`)}):t.acceleratorModelId!==null&&f(U,{variant:`info`,children:t.acceleratorModelId})]}),t.reasons.length>0&&f(`ul`,{className:`px-3 pt-2 text-[11px] text-foreground-muted`,children:t.reasons.map((e,t)=>f(`li`,{children:vi(e)},t))}),f(`div`,{className:`overflow-x-auto`,children:o(`table`,{className:`w-full text-xs`,children:[f(`thead`,{children:o(`tr`,{className:`text-left text-[11px] text-foreground-subtle`,children:[f(`th`,{className:`px-3 py-1.5 font-medium`,children:r(`pipeline.clusterAutoTuneTab.device`,`Device`)}),f(`th`,{className:`px-3 py-1.5 font-medium`,children:r(`pipeline.clusterAutoTuneTab.capacity`,`Capacity`)}),f(`th`,{className:`px-3 py-1.5 font-medium`,children:r(`pipeline.clusterAutoTuneTab.detector`,`Detector`)}),f(`th`,{className:`px-3 py-1.5 font-medium`,children:r(`pipeline.clusterAutoTuneTab.why`,`Why`)})]})}),f(`tbody`,{children:t.devices.map(n=>{let i=Si(e,t.nodeId,n.deviceKey);return o(`tr`,{className:`border-t border-border align-top`,children:[o(`td`,{className:`px-3 py-1.5`,children:[f(`div`,{className:`font-mono text-foreground`,children:n.deviceKey}),f(`div`,{className:`text-[11px] text-foreground-subtle`,children:gi(n.accelerator)})]}),o(`td`,{className:`px-3 py-1.5 text-foreground-muted`,children:[n.chosen===null?`—`:r(`pipeline.clusterAutoTuneTab.sessionsAtFps`,{count:n.chosen.capacitySessions,fps:e.cameraFps}),n.chosen!==null&&o(`div`,{className:`text-[11px] text-foreground-subtle`,children:[r(`pipeline.clusterAutoTuneTab.fpsKeptFree`,{fps:n.chosen.fps,percent:Math.round(e.headroom*100)}),f(`div`,{children:Ci(n.chosen.source)})]})]}),f(`td`,{className:`px-3 py-1.5`,children:n.chosen===null?f(`span`,{className:`text-foreground-subtle`,children:r(`common.unchanged`)}):i!==null&&i.before!==i.after?o(`span`,{children:[f(`span`,{className:`text-foreground-subtle`,children:i.before??r(`common.defaultWord`)}),` → `,f(`span`,{className:`font-medium text-foreground`,children:i.after})]}):f(`span`,{className:`text-foreground`,children:n.chosen.modelId})}),f(`td`,{className:`px-3 py-1.5 text-[11px] text-foreground-muted`,children:n.reasons.map((e,t)=>f(`div`,{children:vi(e)},t))})]},n.deviceKey)})})]})})]})}function Oi({plan:e,nameOf:t,nodeName:n}){let{t:r}=J();return o(`div`,{className:`flex flex-col gap-3 text-xs`,"data-testid":`auto-tune-change-list`,children:[o(`div`,{children:[f(`div`,{className:w,children:r(`pipeline.clusterAutoTuneTab.nodeSettings`,`Node settings`)}),e.nodeChanges.length===0?f(`div`,{className:`text-foreground-subtle`,children:r(`pipeline.clusterAutoTuneTab.noChange`,`No change.`)}):f(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:e.nodeChanges.flatMap(e=>[...e.modelPins.map(t=>o(`li`,{children:[o(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: `,t.before??r(`pipeline.clusterAutoTuneTab.defaultModel`),` →`,` `,t.after??r(`pipeline.clusterAutoTuneTab.stepDefault`,`step default`)]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/pin`)),...e.thresholds.map(t=>o(`li`,{children:[o(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`—`,` `,r(`pipeline.clusterAutoTuneTab.thresholdReset`,{step:t.stepId,keys:t.keys.join(`, `)})]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/thr`))])})]}),o(`div`,{children:[f(`div`,{className:w,children:r(`pipeline.clusterAutoTuneTab.cameraOverridesCleared`,`Camera overrides cleared`)}),e.cameraClears.length===0&&e.detectorStoreClears.length===0?f(`div`,{className:`text-foreground-subtle`,children:r(`pipeline.clusterAutoTuneTab.none`,`None.`)}):o(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:[e.cameraClears.map((e,i)=>o(`li`,{children:[t(e.deviceId),` — `,n(e.nodeId),e.deviceKey===null?` (${r(`pipeline.clusterAutoTuneTab.wholePipeline`)})`:` · ${e.deviceKey}`,` `,`— `,e.stepId,e.modelIdBefore===null?``:r(`pipeline.clusterAutoTuneTab.modelRemoved`,`: model {{modelIdBefore}} removed`,{modelIdBefore:e.modelIdBefore}),e.keys.length>0?r(`pipeline.clusterAutoTuneTab.reset`,`; {{value1}} reset`,{value1:e.keys.join(`, `)}):``]},`c${i}`)),e.detectorStoreClears.map(e=>o(`li`,{children:[t(e.deviceId),` —`,` `,r(`pipeline.clusterAutoTuneTab.detectorThresholdsReset`,{keys:e.keys.join(`, `)})]},`d${e.deviceId}`))]})]})]})}function ki({result:e}){let{t}=J();return e.kind===`refused`?f(`div`,{className:`text-xs text-warning`,children:t(`pipeline.clusterAutoTuneTab.anotherApplyIsAlreadyRunning`,`Another apply is already running.`)}):e.kind===`stale`?f(`div`,{className:`text-xs text-warning`,children:t(`pipeline.clusterAutoTuneTab.theConfigurationChangedSinceThe`,`The configuration changed since the plan was shown. Review the updated plan below and apply again.`)}):o(`ul`,{className:`text-xs`,"data-testid":`auto-tune-result`,children:[e.kind===`aborted`&&f(`li`,{className:`text-danger`,children:t(`pipeline.clusterAutoTuneTab.aModelCouldNotBe`,`A model could not be downloaded: nothing was changed.`)}),e.phases.map(e=>o(`li`,{className:e.ok?`text-foreground-muted`:`text-danger`,children:[e.ok?`✓`:`✗`,` `,e.phase,`: `,e.detail]},e.phase))]})}function Ai(){let{t:e}=J(),t=l(),[n,a]=i(.4),[s,c]=i(2),[u,d]=i(!1),[p,m]=i(!1),[h,g]=i(null),{data:_}=mn(),v=r(()=>new Map((_??[]).map(e=>[e.id,e.name])),[_]),y=t=>v.get(t)??e(`pipeline.clusterAutoTuneTab.cameraFallback`,{id:t}),{nodes:x}=H(),S=r(()=>Qn(x),[x]),C=ln({headroom:n,minSessionsPerDevice:s},{enabled:u,refetchOnWindowFocus:!1}),T=nn({onSuccess:e=>{g(e),m(!1),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),e.kind===`applied`&&C.refetch()}}),E=h?.kind===`stale`?h.plan:C.data,O=E===void 0?null:bi(E);return o(`div`,{className:`flex flex-col gap-3`,"data-testid":`cluster-auto-tune`,children:[o(`section`,{className:b,children:[o(`header`,{className:`${R} flex flex-wrap items-center gap-2`,children:[f(D,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),f(`h3`,{className:`${w} min-w-0 flex-1`,children:e(`pipeline.clusterAutoTuneTab.autoTune`,`Auto tune`)})]}),o(`div`,{className:`flex flex-col gap-2 px-3 py-2 text-xs text-foreground-muted`,children:[f(`p`,{children:e(`pipeline.clusterAutoTuneTab.picksForEveryAcceleratorThe`,`Picks, for every accelerator, the most accurate YOLOv9 detector that still carries at least the chosen number of cameras at once, from the node's hardware and measured speeds. Nothing is measured or estimated about your cameras' activity. Applying it sets those models and clears every model and threshold override — node level and per camera — so each model runs its own default thresholds. Enabled steps, devices, pins, recording, notifications, zones and rules are not touched. There is no undo.`)}),o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`label`,{className:`flex items-center gap-1.5`,children:[f(`span`,{className:`whitespace-nowrap`,children:e(`pipeline.clusterAutoTuneTab.keepFree`,`Keep free`)}),f(W,{"aria-label":e(`pipeline.clusterAutoTuneTab.shareOfEachAcceleratorKept`,`Share of each accelerator kept free`),value:String(n),options:wi.map(t=>({value:String(t),label:e(`pipeline.clusterAutoTuneTab.ofEachAccelerator`,`{{value1}}% of each accelerator`,{value1:Math.round(t*100)})})),onChange:e=>{let t=Number(e.target.value);Ti(t)&&a(t)}})]}),o(`label`,{className:`flex items-center gap-1.5`,children:[f(`span`,{className:`whitespace-nowrap`,children:e(`pipeline.clusterAutoTuneTab.atLeast`,`At least`)}),f(W,{"aria-label":e(`pipeline.clusterAutoTuneTab.minimumParallelSessionsPerDevice`,`Minimum parallel sessions per device`),value:String(s),options:Ei.map(t=>({value:String(t),label:e(`pipeline.clusterAutoTuneTab.camerasAtOnce`,{count:t})})),onChange:e=>{let t=Number(e.target.value);Ei.some(e=>e===t)&&c(t)}})]}),f(G,{size:`sm`,variant:`secondary`,onClick:()=>{g(null),d(!0),u&&C.refetch()},children:C.isFetching?e(`pipeline.clusterAutoTuneTab.computing`,`Computing…`):E===void 0?e(`pipeline.clusterAutoTuneTab.computePlan`,`Compute plan`):e(`pipeline.clusterAutoTuneTab.recompute`,`Recompute`)}),E!==void 0&&f(G,{size:`sm`,disabled:xi(E),onClick:()=>m(!0),children:e(`pipeline.clusterAutoTuneTab.apply`,`Apply…`)})]}),C.error!==null&&f(`div`,{className:`text-danger`,children:C.error.message}),h!==null&&f(ki,{result:h}),O!==null&&f(`div`,{className:`text-[11px] text-foreground-subtle`,children:e(`pipeline.clusterAutoTuneTab.planSummary`,{modelChanges:O.modelChanges,thresholdClears:O.thresholdClears,overrides:O.cameraOverrideClears+O.detectorStoreClears,cameras:O.camerasTouched})})]})]}),E?.warnings.map((e,t)=>f(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:yi(e,S)},t)),E?.nodes.map(e=>f(Di,{plan:E,node:e,nodeName:S},e.nodeId)),E!==void 0&&f(ot,{open:p,onOpenChange:m,children:o(Pt,{width:`lg`,scroll:`body`,children:[o(rn,{children:[f(Vt,{children:e(`pipeline.clusterAutoTuneTab.applyAutoTune`,`Apply auto tune?`)}),f(cn,{children:e(`pipeline.clusterAutoTuneTab.theseAreAllTheChanges`,`These are all the changes. Every override listed is removed and cannot be restored.`)})]}),f(Fe,{children:f(Oi,{plan:E,nameOf:y,nodeName:S})}),o(Jt,{children:[f(G,{variant:`ghost`,onClick:()=>m(!1),children:e(`common.cancel`,`Cancel`)}),f(G,{variant:`danger`,disabled:T.isPending,onClick:()=>T.mutate({planHash:E.planHash,headroom:n,minSessionsPerDevice:s}),children:T.isPending?e(`pipeline.clusterAutoTuneTab.applying`,`Applying…`):e(`common.apply`,`Apply`)})]})]})})]})}var ji={disabled:`pipeline.nodeLoadOverview.exclusion.disabled`,unavailable:`pipeline.nodeLoadOverview.exclusion.unavailable`,"cannot-host-camera-root":`pipeline.nodeLoadOverview.exclusion.cannotHostCameraRoot`,"accelerator-preferred":`pipeline.nodeLoadOverview.exclusion.acceleratorPreferred`};function Mi(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function Ni(e){return e===void 0?!1:e.load.devices.reduce((e,t)=>e+t.attachedCameras,0)>=e.load.attachedCameras}function Pi(e,t,n){let r=e.filter(e=>e.exclusion===null).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.map(e=>{let i=t.get(e.key)??(n?0:null),a=e.weight>0?e.weight:1;return{key:e.key,label:gt(e),format:e.format,sessions:i,weight:a,weightSharePct:e.exclusion===null?Mi(a,r):null,maxSessions:e.maxSessions,atCap:e.maxSessions!==null&&i!==null&&i>=e.maxSessions,available:e.available,enabled:e.enabled,exclusion:e.exclusion}}).toSorted((e,t)=>e.exclusion===null==(t.exclusion===null)?e.key.localeCompare(t.key):e.exclusion===null?-1:1)}function Fi(e){let t=new Map(e.loads.map(e=>[e.nodeId,e])),n=e.nodes.filter(e=>e.isOnline&&e.detectEnabled).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.nodes.map(r=>{let i=t.get(r.id),a=Pi(e.devicesByNode[r.id]??[],new Map((i?.load.devices??[]).map(e=>[e.deviceKey,e.attachedCameras])),Ni(i)),o=r.isOnline&&r.detectEnabled,s=r.weight>0?r.weight:1,c=i?.load.attachedCameras??null;return{nodeId:r.id,name:r.name,isOnline:r.isOnline,detectEnabled:r.detectEnabled,reported:i!==void 0,attachedCameras:c,activeCameras:i?.load.activeCameras??null,maxCameras:r.maxCameras,capacityPct:c!==null&&r.maxCameras!==null&&r.maxCameras>0?Mi(c,r.maxCameras):null,queueDepthTotal:i?.load.queueDepthTotal??null,avgInferenceTimeMs:i?.load.avgInferenceTimeMs??null,score:i?.score??null,weight:s,weightSharePct:o?Mi(s,n):null,decodeHwaccel:i?.decodeHwaccel??null,devices:a,eligibleDeviceCount:a.filter(e=>e.exclusion===null).length}})}t();var Ii=2e4,Li=3e5;function Ri({stats:e,targetWeights:t}){let{t:n}=J(),{nodes:i}=H(),a=z().trpcClient,o=Yt(void 0,{placeholderData:u,staleTime:Ii,refetchInterval:Ii,refetchOnWindowFocus:!0}),s=Ve(void 0,{staleTime:Li}),l=r(()=>i.map(e=>e.id),[i]),d=c({queries:l.map(e=>({queryKey:Pe(yt.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>a.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Li,refetchOnWindowFocus:!1,placeholderData:u}))}),p=r(()=>{let e={};return l.forEach((t,n)=>{let r=d[n]?.data;r&&(e[t]=r.devices)}),e},[l,d.map(e=>e.dataUpdatedAt).join(`|`)]),h=r(()=>{let e=new Map;for(let t of s.data??[])e.set(t.nodeId,t.settings);return e},[s.data]),g=r(()=>i.map(e=>{let n=h.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:Bn(n,e.isHub).pipeline,weight:t?.[e.id]??xn(n,`detectWeight`)??1,maxCameras:xn(n,`maxCameras`)}}),[i,h,t]),_=o.data??[],v=r(()=>Fi({nodes:g,loads:_,devicesByNode:p}),[g,_,p]),y=v.reduce((e,t)=>e+(t.attachedCameras??0),0),b=v.reduce((e,t)=>e+(t.activeCameras??0),0),x=o.dataUpdatedAt>0?Date.now()-o.dataUpdatedAt:null,S=new Map((e?.nodes??[]).map(e=>[e.nodeId,e]));return f(K,{headingId:`load-balancing-node-load`,title:n(`pipeline.nodeLoadOverview.nodeLoad`,`Node load`),icon:te,actions:f(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:n(`pipeline.nodeLoadOverview.summaryLine`,{active:b,attached:y,reading:o.data===void 0?n(`pipeline.nodeLoadOverview.reading`,`reading…`):n(`pipeline.nodeLoadOverview.readingAge`,{age:x===null?`—`:`${Math.round(x/1e3)}s`})})}),children:f(`div`,{className:m,children:v.length===0?f(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:n(`pipeline.nodeLoadOverview.noClusterNodesReportedYet`,`No cluster nodes reported yet.`)}):f(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:v.map(e=>f(zi,{row:e,placed:S.get(e.nodeId)},e.nodeId))})})})}function zi({row:e,placed:t}){let{t:n}=J(),r=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return o(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[o(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[f(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),f(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&f(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:n(`pipeline.nodeLoadOverview.noDetect`,`no detect`)}),!e.reported&&e.isOnline&&o(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:n(`pipeline.nodeLoadOverview.onlineButItDidNot`,`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`),children:[f(y,{className:`h-2.5 w-2.5`}),` `,n(`pipeline.nodeLoadOverview.noReading`)]}),!e.isOnline&&o(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[f(O,{className:`h-2.5 w-2.5`}),` `,n(`common.offline`)]})]}),o(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[f(X,{label:n(`pipeline.nodeLoadOverview.runningAttached`,`Running / attached`),value:r,title:n(`pipeline.nodeLoadOverview.sessionsInInferenceNowCameras`,`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`)}),f(X,{label:n(`pipeline.nodeLoadOverview.targetShare`,`Target share`),value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:n(`pipeline.nodeLoadOverview.theNodeShareAutomaticOr`,`The node share (automatic or manual) normalised over the nodes the balancer actually ranks (online AND detect-enabled).`)}),f(X,{label:n(`pipeline.nodeLoadOverview.actualShare1H`,`Actual share (1 h)`),value:t?.observedShare===null||t===void 0?`—`:`${Math.round(t.observedShare*100)}%`,title:n(`pipeline.nodeLoadOverview.timeWeightedShareOfThe`,`Time-weighted share of the cluster's PARALLEL detection sessions this node carried over the last hour — the quantity a share holds. '—' = no session ran here in the window.`)}),f(X,{label:n(`pipeline.nodeLoadOverview.peakYields`,`Peak · yields`),value:t===void 0?`—`:`${t.peakSessions} · ${t.yieldsAway}`,title:n(`pipeline.nodeLoadOverview.mostSessionsThisNodeRan`,`Most sessions this node ran at once in the last hour, and how many share turns it handed to another node because it was full or drowning.`)}),f(X,{label:n(`pipeline.nodeLoadOverview.scoreQueue`,`Score · queue`),value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:n(`pipeline.nodeLoadOverview.theCapacityScoreBalanceMinimises`,`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`)}),e.capacityPct!==null&&f(X,{label:n(`pipeline.nodeLoadOverview.capFill`,`Cap fill`),value:`${e.capacityPct}%`,title:n(`pipeline.nodeLoadOverview.attachedMaxcameras`,`attached / maxCameras.`)}),e.avgInferenceTimeMs!==null&&f(X,{label:n(`pipeline.nodeLoadOverview.avgInfer`,`Avg infer`),value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:n(`pipeline.nodeLoadOverview.meanInferenceTimeAcrossThis`,`Mean inference time across this node's attached cameras.`)}),e.decodeHwaccel!==null&&f(X,{label:n(`pipeline.nodeLoadOverview.decode`,`Decode`),value:e.decodeHwaccel,title:n(`pipeline.nodeLoadOverview.thisNodeSProbedDecode`,`This node's probed decode hwaccel.`)})]}),f(Bi,{row:e})]})}function Bi({row:e}){let{t}=J();return e.devices.length===0?f(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:t(`pipeline.nodeLoadOverview.acceleratorsNotReadYet`,`Accelerators not read yet.`)}):o(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[o(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[f(x,{className:`h-2.5 w-2.5`}),t(`pipeline.nodeLoadOverview.accelerators`,`Accelerators`),e.eligibleDeviceCount===0&&f(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:t(`pipeline.nodeLoadOverview.noDeviceIsACamera`,`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`),children:t(`pipeline.nodeLoadOverview.noneInPlayRunnerDefault`,`none in play · runner default pool`)})]}),f(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>f(Vi,{device:e},e.key))})]})}function Vi({device:e}){let{t}=J(),n=e.exclusion;return o(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[f(E,{className:`h-2.5 w-2.5 shrink-0 ${n===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),f(`span`,{className:`shrink-0 font-medium ${n===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),n===null?o(s,{children:[f(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:t(`pipeline.nodeLoadOverview.sharePct`,{pct:e.weightSharePct})}),o(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,title:e.sessions===null?t(`pipeline.nodeLoadOverview.notKnownTheNodeDid`,`Not known: the node did not report, or runs a session no device accounts for.`):void 0,children:[`· `,t(`common.sessionsCount`,{count:e.sessions??0}),e.maxSessions===null?``:`/${e.maxSessions}`]}),e.atCap&&f(`span`,{className:`shrink-0 text-amber-400`,title:t(`pipeline.nodeLoadOverview.atItsMaxsessionsCapThe`,`At its maxSessions cap — the balancer skips it until a session ends.`),children:t(`pipeline.nodeLoadOverview.atCap`,`· at cap`)})]}):f(`span`,{className:`truncate text-foreground-subtle/80`,title:t(ji[n]),children:t(`pipeline.nodeLoadOverview.excludedWith`,{reason:t(ji[n])})})]})}function X({label:e,value:t,title:n}){return o(`div`,{className:`min-w-0`,title:n,children:[f(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),f(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Hi(e){return{nodes:Object.fromEntries(e.map(e=>[e.nodeId,Math.max(1,e.weight)])),devices:{}}}function Ui(e){let t={},n={};for(let r of e.nodes){if(r.share===null||r.share<=0)continue;t[r.nodeId]=r.share;let e=Object.fromEntries(r.devices.filter(e=>e.share>0).map(e=>[e.deviceKey,e.share]));Object.keys(e).length>0&&(n[r.nodeId]=e)}return{nodes:t,devices:n}}function Wi(e){return Object.fromEntries(e.nodes.map(e=>[e.nodeId,Object.fromEntries(e.devices.map(e=>[e.deviceKey,e.suggestedMaxSessions]))]))}function Gi(e){return e.reason===`disabled`?q.t(`helpers.loadBalancingViewModel.stalePinDisabled`,{deviceKey:e.deviceKey}):q.t(`helpers.loadBalancingViewModel.stalePinMissing`,{deviceKey:e.deviceKey})}function Ki(e,t){if(t===void 0||t.source===`manual`||t.autoPending)return{nodes:e,readOnly:t!==void 0&&t.source!==`manual`};let n=new Map(t.nodes.map(e=>[e.nodeId,e.configuredPct]));return{nodes:e.map(e=>({...e,weight:Math.round(n.get(e.id)??e.weight)})),readOnly:!0}}function qi(e,t){let n=e.nodes.filter(e=>!e.eligible);if(n.length===0)return null;let r=e.nodes.filter(e=>e.eligible).map(e=>`${t(e.nodeId)} ${Math.round(e.effectivePct)}%`).join(`, `),i=n.map(e=>t(e.nodeId)).join(`, `);return q.t(`helpers.loadBalancingViewModel.shareNote`,{count:n.length,names:i,into:r})}var Ji=[{value:`hardware`,get label(){return q.t(`helpers.loadBalancingViewModel.hardwareLabel`)},get hint(){return q.t(`helpers.loadBalancingViewModel.hardwareHint`)}},{value:`benchmark`,get label(){return q.t(`helpers.loadBalancingViewModel.benchmarkLabel`)},get hint(){return q.t(`helpers.loadBalancingViewModel.benchmarkHint`)}},{value:`manual`,get label(){return q.t(`helpers.loadBalancingViewModel.manualLabel`)},get hint(){return q.t(`helpers.loadBalancingViewModel.manualHint`)}}];function Yi(e){return e===`no-benchmark-results`?q.t(`helpers.loadBalancingViewModel.fallbackNone`):e===`partial-benchmark-results`?q.t(`helpers.loadBalancingViewModel.fallbackPartial`):null}function Xi(e,t){if(e.source!==`benchmark`)return null;let n=e.nodes.filter(e=>e.capacityFallback!==null);return n.length===0?null:n.map(e=>`${t(e.nodeId)}: ${Yi(e.capacityFallback)??``}`).join(` · `)}t();function Zi(e,t,n){return Math.min(Math.max(e,t),n)}function Qi(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function $i(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:Zi(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function ea(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function ta({nodes:e,pending:t,onCommitWeights:r,weightLabel:a=`Detection weight`,emptyHint:c,footnote:l,readOnly:u=!1}){let{t:d}=J(),[p,m]=i(()=>Qi(e)),[h,g]=i(new Set);n(()=>{m(Qi(e)),g(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let _=e.map(e=>e.id),v=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},y=(e,t)=>{m(n=>$i(n,e,t,h,_))},b=()=>{let t=ea(p,_,h),n=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(n.length===0)return;let i=new Set([...n,...h]);r(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return f(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:c??d(`placementBoard.weightSliderStack.noDetectEnabledNodesEnable`,`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`)});let x=e.length===1;return o(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=p[e.id]??0,r=h.has(e.id);return o(`div`,{className:`flex items-center gap-3`,children:[f(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),f(`input`,{"aria-label":d(`placementBoard.weightSliderStack.for`,`{{weightLabel}} for {{name}}`,{weightLabel:a,name:e.name}),type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:u||t||r||x,onChange:t=>y(e.id,Number(t.target.value)),onPointerUp:()=>b(),onKeyUp:()=>b(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),o(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),!u&&f(`button`,{type:`button`,onClick:()=>v(e.id),disabled:t||x,"aria-pressed":r,title:r?d(`placementBoard.weightSliderStack.unlockAllowRebalancing`,`Unlock — allow rebalancing`):d(`placementBoard.weightSliderStack.lockThisShareWhenOthers`,`Lock this share when others change`),className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${r?`text-amber-400`:`text-foreground-subtle`}`,children:f(r?re:I,{className:`h-3.5 w-3.5`})})]},e.id)}),f(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:l??f(s,{children:d(`placementBoard.weightSliderStack.draggingOneSliderSplitsThe`,`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`)})})]})}function na(e){let t=e.steps?.[`object-detection`]?.modelId;return typeof t==`string`&&t.length>0?t:typeof e.defaultModelId==`string`&&e.defaultModelId.length>0?e.defaultModelId:null}t();function ra(e){let t=gt(e),n=e.backend.toLowerCase(),r=e.device.toLowerCase();return e.key===`cpu`||r===`cpu`?{label:t,Icon:E,hue:`slate`}:r===`npu`?{label:t,Icon:ae,hue:`sky`}:r===`gpu`||r===`igpu`?{label:t,Icon:De,hue:`violet`}:n===`edgetpu`?{label:t,Icon:je,hue:`emerald`}:{label:t,Icon:E,hue:`slate`}}var ia={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function aa({nodeId:e,nodeName:t,isOnline:a,suggestedMaxSessions:c,autoDeviceShares:u}){let{t:d}=J(),p=l(),{data:m,isLoading:h}=Et({nodeId:e},{refetchInterval:15e3}),g=Ie({onSettled:()=>{p.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),_=m?.devices??[],v=m?.reachable??a,[y,b]=i({});n(()=>{b(Object.fromEntries(_.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[_.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let x=r(()=>_.filter(e=>y[e.key]?.enabled??e.enabled).length,[_,y]),[S,C]=i(null),w=S??x>0,T=t=>{let n=_.map(e=>{let n=t[e.key]??E(e);return{key:e.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});g.mutate({agentNodeId:e,inferenceDevices:Ar(n)})},E=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),D=e=>{if(!e.available)return;let t=y[e.key]??E(e),n={...y,[e.key]:{...t,enabled:!t.enabled}};b(n),T(n)},k=(e,t)=>{let n=y[e.key]??E(e),r={...y,[e.key]:{...n,maxSessions:t}};b(r),T(r)},j=r(()=>_.filter(e=>(y[e.key]?.enabled??e.enabled)&&e.available),[_,y]),M=r(()=>j.map(e=>({id:e.key,name:ra(e).label,weight:u===void 0?y[e.key]?.weight??e.weight:Math.round(u[e.key]??0)})),[j,y,u]);return o(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[o(`button`,{type:`button`,onClick:()=>C(!w),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":w,children:[f(A,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${w?`rotate-90`:``}`}),f(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t}),f(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:v?x>=2?o(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[f(Ne,{className:`h-3.5 w-3.5`}),d(`pipeline.nodeInferenceDevices.accelerators`,{count:x})]}):x===1?f(`span`,{className:`text-foreground-subtle`,children:d(`placementBoard.nodeInferenceDevices.singleDefault`,`single default`)}):f(`span`,{className:`text-foreground-subtle/70`,children:d(`placementBoard.nodeInferenceDevices.autoDefault`,`auto default`)}):o(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[f(O,{className:`h-3.5 w-3.5`}),` `,d(`common.unreachable`)]})})]}),w&&o(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[v?h&&_.length===0?f(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:d(`placementBoard.nodeInferenceDevices.probingAccelerators`,`Probing accelerators…`)}):_.length===0?f(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:d(`placementBoard.nodeInferenceDevices.noInferenceDevicesReportedBy`,`No inference devices reported by this node's platform probe.`)}):f(`ul`,{className:`space-y-2`,children:_.map(e=>{let t=ra(e),n=y[e.key]??E(e),r=n.enabled&&e.available,i=na({defaultModelId:e.defaultModelId,steps:n.steps});return o(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?r?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[f(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${ia[t.hue]}`,children:f(t.Icon,{className:`h-4.5 w-4.5`})}),o(`div`,{className:`min-w-0 flex-1`,children:[o(`div`,{className:`flex items-center gap-2`,children:[f(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),f(U,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&f(U,{variant:`warning`,className:`text-[9px]`,children:d(`common.unavailable`)})]}),o(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[f(`span`,{className:`font-mono`,children:e.key}),i!==null&&o(s,{children:[f(`span`,{"aria-hidden":!0,children:`·`}),f(`span`,{children:f(gn,{i18nKey:`pipeline.nodeInferenceDevices.rootModel`,values:{model:i},components:{mono:f(`span`,{className:`font-mono text-foreground/80`})}})})]})]})]}),r&&o(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[f(`span`,{className:`hidden @sm/clustertab:inline`,children:d(`pipeline.nodeInferenceDevices.cap`)}),f(`input`,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);k(e,r!=null&&r>0?r:null)},disabled:g.isPending,"aria-label":d(`placementBoard.nodeInferenceDevices.maxConcurrentSessionsFor`,`Max concurrent sessions for {{label}}`,{label:t.label}),className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),r&&f(oa,{suggested:c?.[e.key]??null,current:n.maxSessions,pending:g.isPending,onApply:t=>k(e,t)}),f(Ut,{checked:r,onCheckedChange:()=>D(e),disabled:!e.available||g.isPending,"aria-label":d(`placementBoard.nodeInferenceDevices.enable`,`Enable {{label}}`,{label:t.label}),className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):f(sa,{}),v&&j.length>=2&&o(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[o(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[f(ke,{className:`h-3.5 w-3.5`}),d(`placementBoard.nodeInferenceDevices.acceleratorShare`,`Accelerator share`)]}),f(ta,{nodes:M,pending:g.isPending,onCommitWeights:e=>{let t={...y};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}b(t),T(t)},weightLabel:`Accelerator share`,readOnly:u!==void 0,footnote:u===void 0?f(s,{children:d(`placementBoard.nodeInferenceDevices.dragToShiftTheShare`,`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`)}):f(s,{children:d(`placementBoard.nodeInferenceDevices.automaticEachAcceleratorSShare`,`Automatic: each accelerator's share follows its measured throughput at its model. Switch the node shares to manual to set them yourself.`)})})]}),g.isError&&o(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[d(`placementBoard.nodeInferenceDevices.failedToSaveInferenceDevices`,`Failed to save inference devices:`),` `,g.error instanceof Error?g.error.message:d(`placementBoard.nodeInferenceDevices.unknownError`,`unknown error`)]})]})]})}function oa({suggested:e,current:t,pending:n,onApply:r}){let{t:i}=J();return e===null||e<1||e===t?null:f(G,{variant:`ghost`,size:`sm`,onClick:()=>r(e),disabled:n,title:i(`placementBoard.nodeInferenceDevices.advisoryCapFromTheMeasured`,`Advisory cap from the measured throughput at the suggested model, with the headroom kept free. Applying it writes this device's cap.`),children:i(`pipeline.nodeInferenceDevices.use`,{value:e})})}function sa(){let{t:e}=J();return o(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[f(O,{className:`h-6 w-6 text-foreground-subtle/60`}),f(`p`,{className:`text-xs font-medium text-foreground`,children:e(`placementBoard.nodeInferenceDevices.nodeUnreachable`,`Node unreachable`)}),f(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:e(`placementBoard.nodeInferenceDevices.thePlatformProbeCouldnT`,`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`)})]})}t();var ca=3600*1e3,la=2e4,ua=.4;function da({refreshToken:e,onOpenAutoTune:t}){let{t:n}=J(),a=l(),{nodes:c}=H(),d=Ve(void 0),p=xt({isCamera:!0,projection:`slim`}),h=un({windowMs:ca},{refetchInterval:la,placeholderData:u}).data,g=Lt(void 0,{refetchInterval:la,placeholderData:u}).data,_=()=>{Tn(a),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},v=ze({onSuccess:_}),y=Ke({onSuccess:()=>{_(),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getEffectiveShares`]]})}}),b=Ht({onSuccess:_}),x=dt(),[S,w]=i(!1),T=g?.source,O=T===`benchmark`?`benchmark`:`hardware`,k=ft({headroom:ua,source:O},{enabled:S,staleTime:1/0}),A=k.data,j=r(()=>{let e=new Map((d.data??[]).map(e=>[e.nodeId,e.settings]));return c.filter(t=>Bn(e.get(t.id),t.isHub).pipeline).map(t=>{let n=e.get(t.id);return{id:t.id,name:t.name,isOnline:t.isOnline,weight:xn(n,`detectWeight`)??1,maxCameras:xn(n,`maxCameras`)}})},[c,d.data]),M=e=>c.find(t=>t.id===e)?.name??e,N=$n((p.data??[]).map(e=>({id:e.id,name:e.name}))),P=A?Wi(A):void 0,F=Ki(j,g),I=T!==`manual`,L=e=>{if(g===void 0||g.source===`manual`||g.autoPending)return;let t=g.nodes.find(t=>t.nodeId===e);return t===void 0?void 0:Object.fromEntries(t.devices.map(e=>[e.deviceKey,e.configuredPct]))},R=g?qi(g,M):null,ee=g?Xi(g,M):null,te=Ji.find(e=>e.value===T)?.hint;return o(`div`,{className:`space-y-3 sm:space-y-4`,children:[f(vn,{nodeId:`hub`,addonIds:[kn],level:`global`,sectionIds:[`load`],title:n(`pipeline.clusterLoadBalancingTab.placementPolicy`,`Placement policy`),description:n(`pipeline.clusterLoadBalancingTab.howANewDetectionSession`,`How a new detection session picks its node and device, and what happens when a node falls behind. 'Honour shares' (default) holds the shares below for PARALLEL sessions.`)}),f(Gn,{refreshToken:e}),f(Ri,{stats:h,...g!==void 0&&g.source!==`manual`&&!g.autoPending?{targetWeights:Object.fromEntries(g.nodes.map(e=>[e.nodeId,e.configuredPct]))}:{}}),f(K,{headingId:`load-balancing-node-shares`,title:n(`pipeline.clusterLoadBalancingTab.nodeShares`,`Node shares`),icon:ke,actions:o(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[f(`div`,{role:`radiogroup`,"aria-label":n(`pipeline.clusterLoadBalancingTab.shareSource`,`Share source`),className:`flex items-center gap-1`,children:Ji.map(e=>f(G,{role:`radio`,"aria-checked":T===e.value,variant:T===e.value?`primary`:`outline`,size:`sm`,title:e.hint,disabled:y.isPending||g===void 0,onClick:()=>{T!==e.value&&y.mutate({source:e.value})},children:e.label},e.value))}),o(G,{variant:`outline`,size:`sm`,onClick:()=>{w(!0),S&&k.refetch()},disabled:k.isFetching,children:[f(ie,{className:`h-3.5 w-3.5`}),k.isFetching?n(`pipeline.clusterLoadBalancingTab.suggesting`,`Suggesting…`):O===`benchmark`?n(`pipeline.clusterLoadBalancingTab.suggestFromBenchmark`,`Suggest from benchmark`):n(`pipeline.clusterLoadBalancingTab.suggestFromHardware`,`Suggest from hardware`)]}),o(G,{variant:`ghost`,size:`sm`,onClick:t,children:[f(D,{className:`h-3.5 w-3.5`}),n(`pipeline.clusterLoadBalancingTab.autoTune`,`Auto tune`)]}),o(G,{variant:`outline`,size:`sm`,onClick:()=>x.mutate(void 0),disabled:x.isPending,title:n(`pipeline.clusterLoadBalancingTab.moveStandingAlwaysOnCameras`,`Move standing (always-on) cameras that are no longer on their best node. Pinned cameras never move; on-motion sessions are placed per session anyway.`),children:[f(ae,{className:`h-3.5 w-3.5`}),x.isPending?n(`pipeline.clusterLoadBalancingTab.rebalancing`,`Rebalancing…`):n(`pipeline.clusterLoadBalancingTab.rebalance`,`Rebalance`)]})]}),children:o(`div`,{className:`${m} space-y-3`,children:[te!==void 0&&f(`p`,{className:`text-[10px] text-foreground-subtle`,children:te}),h&&o(`p`,{className:`text-[10px] text-foreground-subtle`,children:[n(`pipeline.clusterLoadBalancingTab.policy`,`Policy:`),` `,f(U,{variant:h.policy===`share`?`info`:`default`,children:h.policy===`share`?n(`pipeline.clusterLoadBalancingTab.honourShares`,`honour shares`):`least-loaded`}),` `,` · ${n(`pipeline.clusterLoadBalancingTab.clusterPeak`,{count:h.clusterPeakSessions})}`,h.policy===`least-loaded`&&` · ${n(`pipeline.clusterLoadBalancingTab.leastLoadedNote`)}`]}),f(ta,{nodes:F.nodes,pending:v.isPending,readOnly:F.readOnly,onCommitWeights:e=>v.mutate(Hi(e)),weightLabel:`Node share`,...F.readOnly?{footnote:g?.autoPending?f(s,{children:n(`pipeline.clusterLoadBalancingTab.automaticSharesAreBeingComputed`,`Automatic shares are being computed from the cluster's measured capacity; the stored values are used meanwhile.`)}):o(s,{children:[T===`benchmark`?n(`pipeline.clusterLoadBalancingTab.benchmarkEachNodeSShare`,`Benchmark: each node's share follows its measured capacity from node benchmark results (hardware capacity where it has none)`):n(`pipeline.clusterLoadBalancingTab.hardwareEachNodeSShare`,`Hardware: each node's share follows its capacity at its Auto tune model, from the measured speed of its hardware`),n(`pipeline.clusterLoadBalancingTab.recomputedWheneverANodeOr`,`, recomputed whenever a node or accelerator is added, removed, switched on or off, or changes model`),g?.computedAt!=null&&f(`span`,{className:`ml-1`,children:n(g.trigger===null?`pipeline.clusterLoadBalancingTab.lastAt`:`pipeline.clusterLoadBalancingTab.lastAtTrigger`,{time:new Date(g.computedAt).toLocaleTimeString(),trigger:g.trigger??``})}),`.`]})}:{}}),R!==null&&f(`p`,{className:`text-[10px] text-foreground-subtle`,children:R}),ee!==null&&f(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`benchmark-fallback-note`,children:ee}),y.isError&&f(It,{message:n(`pipeline.clusterLoadBalancingTab.switchFailed`,{message:y.error instanceof Error?y.error.message:n(`common.unknownError`)})}),v.isError&&f(It,{message:n(`pipeline.clusterLoadBalancingTab.saveFailed`,{message:v.error instanceof Error?v.error.message:n(`common.unknownError`)})}),o(`details`,{className:`rounded-md border border-border`,children:[f(`summary`,{className:`${C} cursor-pointer text-xs text-foreground`,children:n(`pipeline.clusterLoadBalancingTab.maxConcurrentSessionsAdvanced`,`Max concurrent sessions (advanced)`)}),f(`ul`,{className:`divide-y divide-border border-t border-border`,children:j.map(e=>o(`li`,{className:`${C} flex items-center gap-2`,children:[f(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:e.name}),f(Re,{type:`number`,min:1,placeholder:`∞`,defaultValue:e.maxCameras??``,"aria-label":n(`pipeline.clusterLoadBalancingTab.maxConcurrentSessionsFor`,`Max concurrent sessions for {{name}}`,{name:e.name}),className:`w-20 text-right`,disabled:b.isPending,onBlur:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10),i=r!==null&&r>0?r:null;i!==e.maxCameras&&b.mutate({agentNodeId:e.id,maxCameras:i})}})]},e.id))}),f(`p`,{className:`${C} ${V} border-t border-border`,children:n(`pipeline.clusterLoadBalancingTab.aHardCapOnThe`,`A hard cap on the sessions a node runs at once (always-on cameras count too). A node at its cap is never chosen; under shares its turn goes to a free node. Empty = unlimited.`)})]})]})}),k.isError&&f(It,{message:n(`pipeline.clusterLoadBalancingTab.suggestionFailed`,{message:k.error instanceof Error?k.error.message:n(`common.unknownError`)})}),A&&f(fa,{suggestion:A,nameOf:M,pending:v.isPending,...I?{}:{onApply:()=>v.mutate(Ui(A))}}),f(K,{headingId:`load-balancing-accelerators`,title:n(`pipeline.clusterLoadBalancingTab.accelerators`,`Accelerators`),icon:E,children:f(`div`,{className:`${m} space-y-2`,children:j.length===0?f(Xt,{title:n(`pipeline.clusterLoadBalancingTab.noDetectCapableNodes`,`No detect-capable nodes`),description:n(`pipeline.clusterLoadBalancingTab.enableDetectionOnANode`,`Enable detection on a node in Roles & nodes to configure its accelerators.`)}):j.map(e=>f(aa,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline,...P?.[e.id]===void 0?{}:{suggestedMaxSessions:P[e.id]},...L(e.id)===void 0?{}:{autoDeviceShares:L(e.id)}},e.id))})}),h!==void 0&&h.stalePins.length>0&&f(pa,{stats:h,cameraName:N})]})}function fa({suggestion:e,nameOf:t,pending:n,onApply:r}){let{t:i}=J();return o(K,{headingId:`load-balancing-suggestion`,title:e.source===`benchmark`?i(`pipeline.clusterLoadBalancingTab.suggestedFromBenchmark`,`Suggested from benchmark`):i(`pipeline.clusterLoadBalancingTab.suggestedFromHardware`,`Suggested from hardware`),icon:ie,...r===void 0?{}:{actions:f(G,{size:`sm`,onClick:r,disabled:n,children:i(`pipeline.clusterLoadBalancingTab.applySuggestedShares`,`Apply suggested shares`)})},children:[f(`ul`,{className:`divide-y divide-border`,children:e.nodes.map(e=>o(`li`,{className:`${C} space-y-0.5`,children:[o(`div`,{className:`flex items-baseline gap-2 text-xs`,children:[f(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:t(e.nodeId)}),f(`span`,{className:`tabular-nums text-foreground`,children:e.share===null?i(`common.skipped`):`${e.share}%`})]}),o(`p`,{className:V,children:[Yi(e.capacityFallback)===null?``:`${Yi(e.capacityFallback)} · `,e.skippedReason===null?i(`pipeline.clusterLoadBalancingTab.parallelSessions`,`≈ {{capacitySessions}} parallel sessions · {{value2}}`,{capacitySessions:e.capacitySessions,value2:e.devices.map(e=>`${e.deviceKey} ${e.share}% (${e.modelId??`—`}${e.measured?``:`, estimated`}, cap ${e.suggestedMaxSessions??`—`})`).join(` · `)}):i(`pipeline.clusterLoadBalancingTab.notPartOfTheSuggestion`,`not part of the suggestion — {{skippedReason}}`,{skippedReason:e.skippedReason})]})]},e.nodeId))}),o(`p`,{className:`${C} ${V} border-t border-border`,children:[i(`pipeline.clusterLoadBalancingTab.sharesIntro`,{fps:e.cameraFps,headroom:Math.round(e.headroom*100),basis:e.source===`benchmark`?i(`pipeline.clusterLoadBalancingTab.measuredByNodeBenchmarksOr`,`measured by node benchmarks, or from the hardware table where a node has no results`):i(`pipeline.clusterLoadBalancingTab.atTheModelsAutoTune`,`at the models Auto tune picks (at least {{minSessionsPerDevice}} per accelerator), from the measured speed of each node's hardware`,{minSessionsPerDevice:e.minSessionsPerDevice})}),` `,r===void 0?i(`pipeline.clusterLoadBalancingTab.automaticSharesAlreadyFollowThis`,`Automatic shares already follow this; the caps are advisory — apply each from its accelerator row.`):i(`pipeline.clusterLoadBalancingTab.applyingWritesTheNodeAnd`,`Applying writes the node and accelerator shares; the caps are advisory — apply each from its accelerator row.`)]})]})}function pa({stats:e,cameraName:t}){let{t:n}=J(),r=l(),i=pt({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPlacementStats`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});return f(K,{headingId:`load-balancing-stale-pins`,title:n(`pipeline.clusterLoadBalancingTab.staleDevicePins`,`Stale device pins`),icon:Ae,children:f(`ul`,{className:`divide-y divide-border`,children:e.stalePins.map(e=>o(`li`,{className:`${C} flex items-center gap-2`,children:[o(`div`,{className:`min-w-0 flex-1`,children:[f(`p`,{className:`truncate text-xs text-foreground`,title:t(e.deviceId),children:t(e.deviceId)}),f(`p`,{className:V,children:Gi(e)})]}),f(G,{variant:`outline`,size:`sm`,disabled:i.isPending,onClick:()=>i.mutate({deviceId:e.deviceId,deviceKey:`auto`}),children:n(`pipeline.clusterLoadBalancingTab.clearPin`,`Clear pin`)})]},e.deviceId))})})}function ma({node:e,emphasis:t=!1}){let{t:n}=J(),r=e.isHub?P:E;return o(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[f(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),f(r,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),o(`div`,{className:`min-w-0`,children:[o(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[f(`span`,{className:`truncate`,children:e.name}),e.isHub&&f(U,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:n(`common.hubWord`)}),!e.isOnline&&f(U,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:n(`common.offline`)})]}),f(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}function ha({nodes:e,actions:t}){let{t:n}=J();return f(Rt,{columns:[{key:`node`,header:n(`placementBoard.nodeCapabilitiesTable.node`,`Node`),sortValue:e=>e.name,render:e=>f(ma,{node:e})},...En.map(e=>({key:e.key,header:n(e.labelKey),align:`center`,notSortableReason:`A switch — sorting would move the row while it is being changed.`,render:r=>f(Ut,{"aria-label":n(`placementBoard.nodeCapabilitiesTable.on`,`{{label}} on {{name}}`,{label:n(e.labelKey),name:r.name}),title:n(e.hintKey),checked:bn(r.effective,e.key),disabled:t.capabilityPending,onCheckedChange:n=>t.onToggleCapability(r.id,e.key,n)})}))],rows:e,rowKey:e=>e.id,bordered:!1,minWidthPx:720,rowClassName:e=>e.isOnline?void 0:`opacity-60`,emptyMessage:n(`placementBoard.nodeCapabilitiesTable.noClusterNodesReportingYet`,`No cluster nodes reporting yet.`)})}function ga({roleValues:e,options:t,pending:n,onRoleChange:r}){let{t:i}=J(),a=t.map(e=>({value:e.id,label:e.id===`hub`?i(`placementBoard.roleControls.default`,`{{name}} (default)`,{name:e.name}):e.name}));return f(`ul`,{className:`divide-y divide-border`,children:An.map(t=>o(`li`,{className:`${C} flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[o(`div`,{className:`min-w-0 flex-1 basis-56`,children:[f(`div`,{className:`text-xs font-medium text-foreground`,children:Sn(t)}),f(`p`,{className:V,children:Cn(t)})]}),f(`div`,{className:`w-full sm:w-48`,children:f(W,{"aria-label":i(`placementBoard.roleControls.node`,`{{value1}} node`,{value1:Sn(t)}),value:e[t],disabled:n,options:a,onChange:e=>r(t,e.target.value)})})]},t))})}t();function _a(){let{t:e}=J(),t=l(),{nodes:n}=H(),i=Ve(void 0),a=Xe({addonId:kn}),s=Xe({addonId:yn}),c=Xe({addonId:jn}),u=()=>Tn(t),d=Gt({onSuccess:u}),p=wt({onSuccess:u}),m=r(()=>{let e=new Map;for(let t of i.data??[])e.set(t.nodeId,t.settings);return e},[i.data]),h=r(()=>n.map(e=>{let t=m.get(e.id),n=Bn(t,e.isHub);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n}}),[n,m]),g={ingestNode:On(a.data,`ingestNode`,`hub`),recordingNode:On(s.data,Dn,`hub`),audioNode:On(a.data,`audioNode`,`hub`),motionNode:On(a.data,`motionNode`,`hub`),postProcessingNode:On(c.data,wn,`hub`)},_=r(()=>{let e=n.filter(e=>e.isOnline).map(e=>e.id),t=e=>n.find(t=>t.id===e)?.name||e;return[...new Set([`hub`,...An.map(e=>g[e]),...e])].filter(e=>e.length>0).map(e=>({id:e,name:t(e)}))},[n,g]),v=i.isLoading||a.isLoading||s.isLoading||c.isLoading,y=(e,t,n)=>{d.mutate({agentNodeId:e,[t]:n})},b=(e,t)=>{if(e===`recordingNode`){p.mutate({addonId:yn,patch:{[Dn]:t}});return}if(e===`postProcessingNode`){p.mutate({addonId:jn,patch:{[wn]:t}});return}p.mutate({addonId:kn,patch:{[e]:t}})},x={capabilityPending:d.isPending,onToggleCapability:y},S=v?f(ne,{className:`h-3.5 w-3.5 animate-spin text-foreground-subtle`,"aria-label":e(`pipeline.clusterRolesNodesTab.loading`,`Loading`)}):null;return o(`div`,{className:`space-y-3 sm:space-y-4`,children:[o(K,{headingId:`roles-nodes-cluster-roles`,title:e(`pipeline.clusterRolesNodesTab.clusterRoles`,`Cluster roles`),icon:Oe,actions:S,children:[f(`p`,{className:`${V} border-b border-border px-3 py-1.5 sm:px-4`,children:e(`pipeline.clusterRolesNodesTab.oneNodeHoldsEachRole`,`One node holds each role for every camera. Detection shares and caps are on Load balancing.`)}),f(ga,{roleValues:g,options:_,pending:p.isPending,onRoleChange:b})]}),f(K,{headingId:`roles-nodes-node-capabilities`,title:e(`pipeline.clusterRolesNodesTab.nodeCapabilities`,`Node capabilities`),icon:P,children:f(ha,{nodes:h,actions:x})})]})}var va=`pipeline-analytics`,ya=`face-gallery`,ba=`pipeline-orchestrator`,xa=`pipeline-runner`,Sa=`audio-analyzer`;function Ca(e){return[...fe.filter(t=>t.stepId===e).map(e=>de(e.stepId)),...ce.filter(t=>t.stepId===e).map(e=>ue(e.stepId,e.key))]}var wa=`faces`,Ta=`semantic-search`,Ea=[{id:wa,get title(){return q.t(`helpers.clusterSettingsSections.facesTitle`)},get hint(){return q.t(`helpers.clusterSettingsSections.facesHint`)},panels:[{addonId:ba,fieldKeys:Ca(`face-embedding`)},{addonId:va,capability:ya}]},{id:Ta,get title(){return q.t(`helpers.clusterSettingsSections.semanticTitle`)},get hint(){return q.t(`helpers.clusterSettingsSections.semanticHint`)},panels:[{addonId:ba,fieldKeys:Ca(`clip-embedding`)}]},{id:Se,get title(){return q.t(`helpers.clusterSettingsSections.cropTitle`)},get hint(){return q.t(`helpers.clusterSettingsSections.cropHint`)},panels:[{addonId:ba,sectionIds:[Se]}]},{id:ye,get title(){return q.t(`helpers.clusterSettingsSections.nativeTitle`)},get hint(){return q.t(`helpers.clusterSettingsSections.nativeHint`)},panels:[{addonId:ba,sectionIds:[ye]}]},{id:`runner-defaults`,get title(){return q.t(`helpers.clusterSettingsSections.runnerTitle`)},get hint(){return q.t(`helpers.clusterSettingsSections.runnerHint`)},panels:[{addonId:xa,fieldScope:`cluster`},{addonId:Sa,fieldScope:`cluster`}]},{id:`failover`,get title(){return q.t(`helpers.clusterSettingsSections.failoverTitle`)},get hint(){return q.t(`helpers.clusterSettingsSections.failoverHint`)},panels:[{addonId:ba,sectionIds:[`failover`]}]}],Da={"cluster-step-models":wa};function Oa(e){return e===`clip-embedding`?Ta:wa}t();var ka=2500,Aa={faces:ee,"semantic-search":D,"detail-crop":Me,"native-lease":Ne,"runner-defaults":E,failover:N};function ja(e){n(()=>{if(e===null)return;let t=Da[e]??e,n=`[data-cluster-settings-card="${CSS.escape(t)}"]`,r=()=>{let e=document.querySelector(n);return e===null?!1:(e.scrollIntoView({block:`start`,behavior:`smooth`}),e.classList.add(`ring-2`,`ring-primary/60`),setTimeout(()=>e.classList.remove(`ring-2`,`ring-primary/60`),ka),!0)};if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()},[e])}function Ma({section:e}){let{t}=J();return f(`div`,{"data-cluster-settings-card":e.id,className:`rounded-lg`,children:f(K,{headingId:`cluster-settings-${e.id}`,title:e.title,...Aa[e.id]===void 0?{}:{icon:Aa[e.id]},children:o(`div`,{className:`${m} space-y-3`,children:[f(`p`,{className:V,children:e.hint}),e.panels.map(e=>f(vn,{nodeId:`hub`,addonIds:[e.addonId],level:`global`,hideSectionChrome:!0,omitSectionIds:[`cluster`,`load`],emptyMessage:t(`pipeline.clusterSettingsTab.notAvailableTheAddonThat`,`Not available — the addon that owns these settings did not answer.`),...e.capability===void 0?{}:{capability:e.capability},...e.sectionIds===void 0?{}:{sectionIds:e.sectionIds},...e.fieldKeys===void 0?{}:{fieldKeys:e.fieldKeys},...e.fieldScope===void 0?{}:{fieldScope:e.fieldScope}},`${e.addonId}:${e.capability??``}`))]})})})}function Na({refreshToken:e}){let[t]=_n();return ja(t.get(Lo)),f(`div`,{className:`space-y-3 sm:space-y-4`,children:Ea.map(e=>f(Ma,{section:e},e.id))})}var Pa=`pipeline-orchestrator`,Fa=200;function Ia(){let{t:e}=J();return o(`div`,{className:`flex flex-col gap-3`,children:[o(`div`,{children:[f(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:e(`pipeline.clusterOrchestratorLogsTab.orchestratorLogs`,`Orchestrator logs`)}),f(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`pipeline.clusterOrchestratorLogsTab.dispatchDecisionsBalancerMovesAnd`,`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.`)})]}),f(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:f(Tt,{addonId:Pa,limit:Fa,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1,showSourceSelect:!0})})]})}var La=[{id:`assignments`,labelKey:`pipeline.clusterDetail.tabAssignments`},{id:`load-balancing`,labelKey:`pipeline.clusterDetail.tabLoadBalancing`},{id:`auto-tune`,labelKey:`pipeline.clusterDetail.tabAutoTune`},{id:`roles-nodes`,labelKey:`pipeline.clusterDetail.tabRoles`},{id:`settings`,labelKey:`common.settings`},{id:`logs`,labelKey:`common.logs`}];function Ra(e){return La.some(t=>t.id===e)}function za({refreshToken:e}){let{t}=J(),[n,r]=_n(),i=n.get(Io),a=Ra(i)?i:`assignments`,s=e=>{r(t=>{let n=new URLSearchParams(t);return n.set(Io,e),n.delete(Lo),n},{replace:!0})};return o(`div`,{className:`flex flex-col h-full`,children:[o(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[f(`h2`,{className:`text-base font-semibold text-foreground`,children:t(`pipeline.clusterDetail.clusterOrchestration`,`Cluster Orchestration`)}),f(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:t(`pipeline.clusterDetail.cameraAssignmentsLoadBalancingThe`,`Camera assignments, load balancing, the detector recommendation, cluster roles and settings.`)})]}),f(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:La.map(e=>f(`button`,{type:`button`,onClick:()=>s(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${a===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:t(e.labelKey)},e.id))}),o(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[a===`assignments`&&f(di,{}),a===`load-balancing`&&f(da,{refreshToken:e,onOpenAutoTune:()=>s(`auto-tune`)}),a===`auto-tune`&&f(Ai,{}),a===`roles-nodes`&&f(_a,{}),a===`settings`&&f(Na,{refreshToken:e}),a===`logs`&&f(Ia,{})]})]})}var Ba=`armed:`;function Va(e){return e.assignment.reasons.detection?.startsWith(Ba)===!0}function Ha(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!Va(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function Ua(e){let t=[],n=[],{assignment:r,detection:i,broker:a}=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?q.t(`helpers.cameraCardModel.provisioningFailedWith`,{error:i.provisioning.error}):q.t(`helpers.cameraCardModel.provisioningFailed`)}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:q.t(`helpers.cameraCardModel.blackHole`)}),r.detectionNodeId===null&&i===null&&!Va(e)&&n.push({code:`unassigned`,severity:`warning`,message:q.t(`helpers.cameraCardModel.unassigned`)});let o=e.degraded??[];if(o.length>0){let e=[...new Set(o.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:q.t(`helpers.cameraCardModel.statusUnreadable`,{stages:e})})}n.push(...Ka(e.cameraSensors));for(let e of a?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:q.t(`helpers.cameraCardModel.brokerStalled`,{profile:e.profile})});return[...t,...n]}function Wa(e){return e.state===`unreadable`&&ge.state===`unreadable`&&e.reason===ge.reason}function Ga(e){switch(e.state){case`ready`:return null;case`missing`:return{code:`camera-sensor-missing`,severity:`warning`,message:q.t(`helpers.cameraCardModel.sensorMissing`,{addonId:e.addonId,stableId:e.stableId})};case`offline`:return{code:`camera-sensor-offline`,severity:`warning`,message:q.t(`helpers.cameraCardModel.sensorOffline`,{name:e.name,deviceId:e.deviceId,reason:e.reason})};case`unsupported`:return{code:`camera-sensor-unsupported`,severity:`warning`,message:q.t(`helpers.cameraCardModel.sensorUnsupported`,{name:e.name,deviceId:e.deviceId,reason:e.reason})};case`unreadable`:return{code:`camera-sensor-unreadable`,severity:`warning`,message:q.t(`helpers.cameraCardModel.sensorUnreadable`,{addonId:e.addonId,stableId:e.stableId,reason:e.reason})}}}function Ka(e){if(e===void 0||e.state===`not-configured`)return[];if(e.state===`unreadable`)return Wa(e)?[]:[{code:`camera-sensors-unreadable`,severity:`warning`,message:q.t(`helpers.cameraCardModel.sensorsUnreadable`,{reason:e.reason})}];let t=e.sensors.flatMap(e=>{let t=Ga(e);return t===null?[]:[t]}),n=e.notForwarded===void 0?t:[qa(e.notForwarded),...t];return e.notEnforced===void 0?n:[{code:`camera-sensors-not-enforced`,severity:`warning`,message:q.t(`helpers.cameraCardModel.notEnforced`)},...n]}function qa(e){return{code:`camera-sensors-not-forwarded`,severity:`warning`,message:e===`onboard-not-listed`?q.t(`helpers.cameraCardModel.notForwardedOnboard`):q.t(`helpers.cameraCardModel.notForwardedNoDetection`)}}function Ja(e){return e===void 0?q.t(`helpers.cameraCardModel.summaryUnavailable`):e.state===`not-configured`?q.t(`helpers.cameraCardModel.summaryNone`):e.state===`unreadable`?q.t(`helpers.cameraCardModel.summaryUnknown`,{reason:e.reason}):e.sensors.map(Xa).join(`, `)}function Ya(e){return e.mode===`in-addition`?``:` · ${e.mode}`}function Xa(e){return`${Za(e)}${Ya(e)}`}function Za(e){switch(e.state){case`ready`:return`${e.name} (#${e.deviceId})`;case`offline`:return`${e.name} (#${e.deviceId}) — ${e.reason}`;case`unsupported`:return q.t(`helpers.cameraCardModel.summaryUnsupported`,{name:e.name,deviceId:e.deviceId});case`missing`:case`unreadable`:return`${e.addonId}/${e.stableId} — ${e.state}`}}function Qa(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function $a(e){return typeof e==`string`&&e.length>0?e:null}function eo(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function to(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function no(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var ro={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 io(e){if(!Qa(e)||!Array.isArray(e.sections))return ro;let t=Ce(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)no(n.value,n.default)&&r.add(e);return{detectionMode:$a(n(`detectionMode`)),detectionStreamProfile:$a(n(`detectionStreamProfile`)),detectionFps:eo(n(`detectionFps`)),motionSources:to(n(`motionSources`)),motionFps:eo(n(`motionFps`)),motionCooldownMs:eo(n(`motionCooldownMs`)),motionStreamProfile:$a(n(`motionStreamProfile`)),audioMode:$a(n(`audioMode`)),pipelineNodeId:$a(n(`pipelineNodeId`)),decoderNodeId:$a(n(`decoderNodeId`)),audioNodeId:$a(n(`audioNodeId`)),overriddenKeys:r}}function ao(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(...ao(r.children,t+1));return n}function Z({title:e,children:t}){return o(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[f(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),f(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Q({label:e,children:t,overridden:n=!1}){return o(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[f(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),f(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&f(oo,{})]})}function oo(){let{t:e}=J();return f(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:e(`cameras.cardPrimitives.deviceLevelOverrideActive`,`Device-level override active`),"aria-label":e(`cameras.cardPrimitives.deviceLevelOverrideActive`,`Device-level override active`),role:`img`})}var so={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 $({tone:e=`neutral`,children:t,title:n}){return f(`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 ${so[e]}`,children:t})}function co({children:e}){return f(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function lo({icon:e,label:t,nodeId:n,pinned:r,reason:i,overridden:a}){let{t:c}=J();return o(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[f(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),f(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?f(`span`,{className:`text-foreground-subtle italic`,children:c(`cameras.configBlocks.unassigned`)}):o(s,{children:[f(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?o(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:c(`cameras.configBlocks.manuallyPinned`,`Manually pinned`),children:[f(v,{className:`h-2.5 w-2.5`}),` `,c(`cameras.configBlocks.manual`)]}):f(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:c(`cameras.configBlocks.autoReason`,{reason:i!==void 0&&i.length>0?i:c(`cameras.configBlocks.capacity`)})}),a&&f(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:c(`cameras.configBlocks.persistedSettingsPinForThis`,`Persisted settings pin for this role`)})]})]})}function uo({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:i}){let{t:a}=J(),s=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,c=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return o(Z,{title:a(`cameras.configBlocks.whereItRuns`,`Where it runs`),children:[f(lo,{icon:E,label:a(`cameras.configBlocks.detection`,`Detection`),nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),f(lo,{icon:h,label:a(`cameras.configBlocks.decoder`,`Decoder`),nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),f(lo,{icon:T,label:a(`cameras.configBlocks.audio`,`Audio`),nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),f(lo,{icon:B,label:a(`cameras.configBlocks.source`,`Source`),nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),f(`div`,{className:`mt-1.5`,children:o(`select`,{value:s,disabled:r,"aria-label":a(`cameras.configBlocks.detectionPlacementPin`,`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:[f(`option`,{value:`auto`,children:a(`cameras.configBlocks.autoLoadBalanced`,`Auto (load balanced)`)}),c.map(e=>f(`option`,{value:e,children:a(`cameras.configBlocks.pinDetection`,{node:n.find(t=>t.id===e)?.name??e})},e))]})})]})}function fo(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function po(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function mo(e){return e===null?q.t(`pipeline.configBlocks.fpsDefault`):e===0?q.t(`pipeline.configBlocks.fpsNative`):`${e} fps`}function ho({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:i,cameraSensors:a}){let{t:c}=J(),l=po(t,n.detectionStreamProfile),u=po(t,n.motionStreamProfile),d=n.motionSources.includes(`analyzer`);return o(Z,{title:c(`cameras.configBlocks.streamsMotion`,`Streams & motion`),children:[o(Q,{label:c(`cameras.configBlocks.detectStream`,`Detect stream`),overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,l!==void 0&&` · ${l.width}×${l.height} ${l.codec}`]}),f(Q,{label:c(`cameras.configBlocks.detectFps`,`Detect FPS`),overridden:n.overriddenKeys.has(`detectionFps`),children:mo(n.detectionFps)}),o(Q,{label:c(`cameras.configBlocks.motionSrc`,`Motion src`),overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.map(le).join(` + `):c(`cameras.configBlocks.none`),r===!1&&` · ${c(`cameras.configBlocks.inactive`)}`]}),f(Q,{label:c(`cameras.configBlocks.cameraSensors`,`Camera sensors`),children:Ja(a)}),d&&o(s,{children:[o(Q,{label:c(`cameras.configBlocks.motionStream`,`Motion stream`),overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,u!==void 0&&` · ${u.width}×${u.height} ${u.codec}`]}),o(Q,{label:c(`cameras.configBlocks.motionFps`,`Motion FPS`),overridden:n.overriddenKeys.has(`motionFps`),children:[mo(n.motionFps),i!==null&&` · ${c(`cameras.configBlocks.liveFps`,{fps:i.toFixed(1)})}`]})]}),f(Q,{label:c(`cameras.configBlocks.cooldown`,`Cooldown`),overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?c(`cameras.configBlocks.defaultValue`):`${n.motionCooldownMs/1e3}s`}),f(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?f(co,{children:c(`cameras.configBlocks.noStreamsRegistered`,`No streams registered`)}):e.map(e=>o(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[f(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,fo(e)]},e.camStreamId))})]})}function go({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){let{t:i}=J();return o(Z,{title:i(`cameras.configBlocks.pipelineSteps`,`Pipeline steps`),children:[e===void 0?f(co,{children:i(`cameras.configBlocks.resolving`,`Resolving…`)}):e.length===0?f(co,{children:i(`cameras.configBlocks.noStepsConfigured`,`No steps configured`)}):f(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>f($,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:o(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&f(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&o(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),f(`div`,{className:`mt-1`,children:o(Q,{label:i(`cameras.configBlocks.audioClass`,`Audio class.`),children:[r??`—`,n!==null&&` · ${i(n?`cameras.configBlocks.running`:`cameras.configBlocks.off`)}`,t!==null&&` · ${t}`]})})]})}var _o={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function vo({detection:e,live:t,detectionMode:n,modeOverridden:r}){let i=M(),{t:a}=J();if(e===null)return o(Z,{title:a(`cameras.runtimeBlocks.detectionRuntime`,`Detection runtime`),children:[f(Q,{label:a(`cameras.runtimeBlocks.mode`,`Mode`),overridden:r,children:n??`—`}),f(co,{children:a(`cameras.runtimeBlocks.detectionStageInactiveOrUnreachable`,`Detection stage inactive or unreachable`)})]});let s=t?.phase??e.phase,c=t?.actualFps??e.actualFps,l=t?.configuredFps??e.configuredFps,u=t?.avgInferenceTimeMs??e.avgInferenceMs,d=t?.queueDepth??e.queueDepth,p=kt(s,i),m=s===`active`&&c===0;return o(Z,{title:a(`cameras.runtimeBlocks.detectionRuntime`,`Detection runtime`),children:[o(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[o(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${p.badgeClass}`,children:[f(on,{phase:s,className:`h-2.5 w-2.5`}),p.label]}),t!==void 0&&f(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:a(`common.live`)})]}),f(Q,{label:a(`cameras.runtimeBlocks.mode`,`Mode`),overridden:r,children:n??`—`}),o(Q,{label:`FPS`,children:[f(`span`,{className:m?`text-danger font-semibold`:``,children:c.toFixed(1)}),f(`span`,{className:`ml-1 text-foreground-subtle`,children:a(`cameras.runtimeBlocks.configuredFps`,{fps:l.toFixed(0)})})]}),o(Q,{label:a(`cameras.runtimeBlocks.inference`,`Inference`),children:[u.toFixed(0),` ms`,d>0&&f(`span`,{className:`ml-1 text-warning`,children:a(`cameras.runtimeBlocks.queue`,{depth:d})}),t!==void 0&&t.droppedFrames>0&&f(`span`,{className:`ml-1 text-warning`,children:a(`cameras.runtimeBlocks.drops`,{count:t.droppedFrames})})]}),o(Q,{label:a(`cameras.runtimeBlocks.engine`,`Engine`),children:[e.engine.backend,` · `,e.engine.device]}),o(Q,{label:a(`cameras.runtimeBlocks.provisioning`,`Provisioning`),children:[f($,{tone:_o[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&o(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function yo({broker:e}){let{t}=J();return e===null?f(Z,{title:t(`cameras.runtimeBlocks.streamBroker`,`Stream broker`),children:f(co,{children:t(`cameras.runtimeBlocks.brokerStageInactiveOrUnreachable`,`Broker stage inactive or unreachable`)})}):o(Z,{title:t(`cameras.runtimeBlocks.streamBroker`,`Stream broker`),children:[e.profiles.length===0?f(co,{children:t(`cameras.runtimeBlocks.noBrokerProfiles`,`No broker profiles`)}):f(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let n=e.status===`streaming`,r=n&&e.inFps===0;return o(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[f(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${r?`bg-danger`:n?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),f(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),o(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),f(`span`,{className:`ml-auto shrink-0 ${r?`text-danger`:`text-foreground`}`,children:t(`cameras.runtimeBlocks.fpsValue`,{value:e.inFps===null?`—`:e.inFps.toFixed(0)})}),o(`span`,{className:`text-foreground-subtle shrink-0`,title:t(`cameras.runtimeBlocks.subscribers`,`Subscribers`),children:[`×`,e.subscribers]})]},e.profile)})}),o(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[f($,{tone:e.webrtcSessions>0?`info`:`neutral`,children:t(`cameras.runtimeBlocks.webrtc`,{count:e.webrtcSessions})}),f($,{tone:e.rtspRestream?`success`:`neutral`,children:e.rtspRestream?t(`cameras.runtimeBlocks.restreamOn`):t(`cameras.runtimeBlocks.restreamOff`)})]})]})}function bo({decoder:e}){let{t}=J();return e===null?f(Z,{title:t(`cameras.runtimeBlocks.decoder`,`Decoder`),children:f(co,{children:t(`cameras.runtimeBlocks.decoderStageInactiveOrUnreachable`,`Decoder stage inactive or unreachable`)})}):f(Z,{title:t(`cameras.runtimeBlocks.decoder`,`Decoder`),children:f(Q,{label:t(`cameras.runtimeBlocks.node`,`Node`),children:e.nodeId})})}t();var xo=`pipeline-orchestrator`,So={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},Co={healthy:`pipeline.cameraPipelineCard.healthHealthy`,idle:`pipeline.cameraPipelineCard.healthIdle`,error:`pipeline.cameraPipelineCard.healthError`};function wo({problems:e}){return f(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>o(`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:[f(y,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),f(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function To({deviceId:e,name:t,online:n,status:i,live:a,onlineNodes:s}){let{t:c}=J(),u=l(),{data:d}=$t({addonId:xo,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:p}=rt({deviceId:e},{staleTime:3e4}),m=r(()=>io(d),[d]),h=r(()=>p===void 0?void 0:ao(p.steps),[p]),g=r(()=>i===void 0?[]:Ua(i),[i]),_=()=>{u.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),u.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},v=Ot({onSuccess:_}),y=We({onSuccess:_}),b=t=>{t===`auto`?y.mutate({deviceId:e}):v.mutate({deviceId:e,agentNodeId:t})},x=i===void 0?`idle`:Ha(i),S=g.some(e=>e.severity===`error`),C=g.length>0,w=S?`border-danger/50`:C?`border-warning/40`:`border-border`;return o(`article`,{"aria-label":c(`cameras.cameraPipelineCard.pipelineStatus`,`{{name}} pipeline status`,{name:t}),className:`rounded-lg border ${w} bg-background overflow-hidden`,children:[o(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[f(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${S?`bg-danger`:So[x]}`,title:S?c(`common.error`,`Error`):c(Co[x]),"aria-label":S?c(`common.error`,`Error`):c(Co[x]),role:`img`}),f(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),o(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&f($,{tone:`danger`,children:c(`common.offline`)}),o(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[m.detectionMode!==null&&f($,{tone:m.detectionMode===`disabled`?`warning`:m.detectionMode===`always-on`?`info`:`neutral`,title:c(`cameras.cameraPipelineCard.objectDetectionMode`,`Object detection mode`),children:m.detectionMode===`disabled`?c(`cameras.cameraPipelineCard.detectionOff`,`detection off`):m.detectionMode}),i?.recording!=null&&(i.recording.active?o($,{tone:`danger`,title:c(`cameras.cameraPipelineCard.recording`,`Recording ({{mode}})`,{mode:i.recording.mode}),children:[f(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):i.recording.mode!==`off`&&f($,{tone:`neutral`,title:c(`cameras.cameraPipelineCard.recordingMode`,`Recording mode`),children:c(`pipeline.cameraPipelineCard.recMode`,{mode:i.recording.mode})}))]})]}),g.length>0&&f(wo,{problems:g}),i===void 0?f(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:c(`cameras.cameraPipelineCard.noPipelineStatusYetThe`,`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`)}):o(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[f(uo,{assignment:i.assignment,settings:m,onlineNodes:s,pinPending:v.isPending||y.isPending,onDetectionPinChange:b}),f(vo,{detection:i.detection,live:a,detectionMode:m.detectionMode,modeOverridden:m.overriddenKeys.has(`detectionMode`)}),f(go,{steps:h,audioModelId:p?.audio?.modelId??null,audioEnabled:i.audio?.enabled??p?.audio?.enabled??null,audioMode:m.audioMode}),f(ho,{streams:i.source.streams,brokerProfiles:i.broker?.profiles,settings:m,motionEnabled:i.motion?.enabled??null,motionFpsLive:i.motion?.fps??null,cameraSensors:i.cameraSensors}),f(yo,{broker:i.broker}),f(bo,{decoder:i.decoder})]})]})}t();var Eo=5e3,Do=1e4,Oo=5e3;function ko(e){let t=l(),{data:a,isLoading:o}=mn(),{data:s,isLoading:c}=Ft({},{refetchInterval:Eo}),{nodes:u}=H();n(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[d,f]=i(new Map);St(pe.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&f(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})}),n(()=>{if(d.size===0)return;let e=setInterval(()=>{f(e=>{let t=Date.now()-Do,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},Oo);return()=>clearInterval(e)},[d.size]);let p=r(()=>{let e=new Map;for(let t of s??[])e.set(t.deviceId,t);return e},[s]);return{rows:r(()=>(a??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[a,p]),liveMetrics:d,onlineNodes:r(()=>(u??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[u]),isLoading:o||c}}t();function Ao({refreshToken:e}){let{t}=J(),{rows:n,liveMetrics:i,onlineNodes:a,isLoading:s}=ko(e),c=r(()=>[...n.map(e=>{let t=e.status===void 0?[]:Ua(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),[n]),l=r(()=>{let e=0,t=0;for(let n of c)(n.errorCount>0||n.warningCount>0)&&(t+=1),(i.get(n.row.deviceId)?.phase??n.row.status?.detection?.phase)===`active`&&(e+=1);return{total:c.length,active:e,issues:t}},[c,i]);return s&&n.length===0?f(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:t(`cameras.camerasOverview.loadingCameraPipelines`,`Loading camera pipelines…`)}):n.length===0?f(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:t(`cameras.camerasOverview.noCamerasFound`,`No cameras found`)}):f(`div`,{className:`h-full overflow-y-auto`,children:o(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[o(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[f(`span`,{children:f(gn,{i18nKey:`pipeline.camerasOverview.camerasTotal`,values:{count:l.total},components:{b:f(`span`,{className:`font-semibold text-foreground`})}})}),f(`span`,{children:f(gn,{i18nKey:`pipeline.camerasOverview.activelyInferring`,values:{count:l.active},components:{b:f(`span`,{className:`font-semibold text-success`})}})}),o(`span`,{children:[f(`span`,{className:`font-semibold ${l.issues>0?`text-danger`:`text-foreground`}`,children:l.issues}),` `,t(`cameras.camerasOverview.withIssues`,`with issues`)]}),f(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:t(`cameras.camerasOverview.polledEvery5SDetection`,`polled every 5 s · detection metrics live at 1 Hz`)})]}),c.map(({row:e})=>f(To,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:i.get(e.deviceId),onlineNodes:a},e.deviceId))]})})}var jo=e({CLUSTER_NODE_ID:()=>Mo,PipelinePage:()=>Fo});t();var Mo=`__cluster__`;function No(e){return e===`cameras`?`cameras`:`nodes`}function Po({viewMode:e,onNodes:t,onCameras:n}){let{t:r}=J();return o(`div`,{className:`flex items-center gap-1 rounded-lg border border-border bg-surface p-0.5`,role:`tablist`,"aria-label":r(`pipeline.pipelineView`,`Pipeline view`),children:[f(`button`,{type:`button`,role:`tab`,"aria-selected":e===`nodes`,onClick:t,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,e===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:r(`pipeline.nodes`,`Nodes`)}),f(`button`,{type:`button`,role:`tab`,"aria-selected":e===`cameras`,onClick:n,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,e===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:r(`pipeline.cameras`,`Cameras`)})]})}function Fo(){let{t:e}=J(),[t,r]=_n(),a=No(t.get(`view`)),c=t.get(`node`)??`__cluster__`,[l,u]=i(0),[d,p]=i(!1);return n(()=>{a===`nodes`&&!t.get(`node`)&&r({view:`nodes`,node:Mo},{replace:!0})},[a,t,r]),o(Kt,{icon:Ee,title:e(`pipeline.pipeline`,`Pipeline`),subtitle:e(`pipeline.detectionPlacementLoadAndPer`,`Detection placement, load and per-camera runtime across the cluster.`),actions:o(G,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>u(e=>e+1),title:e(`common.refresh`,`Refresh`),children:[f(j,{className:`h-3.5 w-3.5`}),e(`common.refresh`,`Refresh`)]}),nav:f(Po,{viewMode:a,onNodes:()=>{r({view:`nodes`,node:c},{replace:!0})},onCameras:()=>{r({view:`cameras`},{replace:!0})}}),className:`flex h-full min-h-0 flex-col overflow-hidden`,children:[a===`nodes`&&o(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(e=>!e),"aria-expanded":d,className:`flex w-full shrink-0 justify-between border-b border-border md:hidden`,children:[f(`span`,{children:e(d?`pipeline.hideNodeList`:`pipeline.showNodeList`)}),f(S,{className:[`h-4 w-4 transition-transform`,d?`rotate-180`:``].join(` `)})]}),f(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden md:flex-row`,children:a===`nodes`?o(s,{children:[f(`aside`,{className:[d?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b border-border md:border-b-0 md:border-r`,`max-h-[60vh] overflow-y-auto md:max-h-none`].join(` `),children:f(Hn,{selectedNodeId:c,onSelect:e=>{r({view:`nodes`,node:e},{replace:!0}),p(!1)},refreshToken:l})}),f(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:c===`__cluster__`?f(za,{refreshToken:l}):f(ui,{nodeId:c,refreshToken:l})})]}):f(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:f(Ao,{refreshToken:l})})})]})}var Io=`ctab`,Lo=`section`;function Ro(e,t){let n=new URLSearchParams({view:`nodes`,node:Mo,[Io]:e});return t!==void 0&&n.set(Lo,t),`/system/pipeline?${n.toString()}`}function zo(e){return Ro(`settings`,Oa(e))}function Bo(){return Ro(`load-balancing`)}var Vo=`pipeline-orchestrator`;function Ho(e){return fe.find(t=>t.stepId===e)??null}function Uo({step:e,engineFormat:t,runnableModelIds:n}){let{t:r}=J(),{data:i}=Xe({addonId:Vo}),a=he(i??null)[e.stepId]??e.defaultModelId,s=e.options.find(e=>e.id===a)?.label??a,c=n.length>0&&!n.includes(a);return o(`div`,{className:`space-y-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[f(`span`,{className:`font-medium text-foreground`,children:e.label}),f(`span`,{className:`font-mono text-foreground`,children:s}),f(`span`,{title:r(`pipeline.clusterStepModel.oneValueForTheWhole`,`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`),className:`rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:r(`pipeline.clusterStepModel.clusterWide`)}),f(hn,{to:zo(e.stepId),className:`ml-auto text-[11px] text-primary hover:underline`,children:r(`pipeline.clusterStepModel.changeInClusterSettings`,`Change in Cluster → Settings ›`)})]}),o(`p`,{className:V,children:[r(`pipeline.clusterStepModel.oneModelForEveryNode`,`One model for every node and camera:`),` `,r(`pipeline.clusterStepModel.indexNote`,{index:e.indexName})]}),c&&f(`p`,{className:`rounded border border-warning/40 bg-warning/10 px-2 py-1 text-[10px] leading-snug text-warning`,children:f(gn,{i18nKey:`pipeline.clusterStepModel.noBuild`,values:{engine:t,model:a,index:e.indexName},components:{b:f(`b`,{})}})})]})}export{Mr as _,Xr as a,Fr as c,Vr as d,Ur as f,Nr as g,Hr as h,Zr as i,qr as l,Br as m,Ho as n,zr as o,Kr as p,jo as r,Wr as s,Uo as t,Gr as u,kr as v,Nn as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{$ as e,B as t,J as n,K as r,L as i,S as a,b as o,q as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{D as l,O as u,V as d,ca as f,ot as p}from"./player-overlays-BQ-CPD3k.js";import{Br as m,Cn as h,Fn as g,Gr as _,Hr as v,Jr as y,Kr as b,Lr as x,Sn as S,Tn as C,Vr as w,Wr as ee,Yr as T,ci as E,li as D,ni as O,qr as k,ri as te,wn as ne,xn as re}from"./client-C7mYZlqO.js";import{Ar as ie,Ja as ae,Ku as oe,Mu as se,Rr as ce,Wu as le,Ya as A,_a as ue,da as de,fr as j,hr as M,s as fe,wo as pe}from"./src-DP8JO4HZ.js";import{t as N}from"./i18n-CiEPJn04.js";import{t as P}from"./useTranslation-D3Is_4B6.js";e();function me(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function he(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function F(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function I(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function L(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function ge(e,t){switch(t.type){case`set-new-type`:return e.target.kind===`new`?{...e,target:{...e.target,type:t.deviceType}}:e;case`set-new-role`:{if(e.target.kind!==`new`)return e;let{role:n,...r}=e.target;return{...e,target:t.role===null?r:{...r,role:t.role}}}case`set-name`:return{...e,name:t.name};case`add-feature`:return e.features.some(e=>e.cap===t.cap)?e:{...e,features:[...e.features,{kind:`fields`,cap:t.cap,fields:{}}]};case`remove-feature`:return{...e,features:e.features.filter(e=>e.cap!==t.cap)};case`set-field`:return I(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return I(e,t.cap,e=>({...e,fields:L(e.fields,t.path)}));case`remove-binding`:return I(e,t.cap,e=>{let n=e.fields[t.path];return n?.kind===`expression`?{...e,fields:{...e.fields,[t.path]:{...n,bindings:L(n.bindings,t.bindingName)}}}:e});case`copy-feature`:return I(e,t.cap,e=>({...e,fields:{...e.fields,...Object.fromEntries(t.paths.map(e=>[e,{kind:`from`,source:t.from,cap:t.sourceCap,fieldPath:e}]))}}))}}function _e(e){let t=v.safeParse({target:e.target,features:e.features});return t.success?{ok:!0,composition:t.data}:{ok:!1,problems:t.error.issues.map(e=>`${e.path.join(`.`)||`composition`}: ${e.message}`)}}function ve(e,t){return JSON.stringify(e)!==JSON.stringify(t)}function ye(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var be=[`room`,`converted-sensor`,`derived-binary`],R={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function xe(){return F(ne({temperatureSources:S,motionSources:re,occupancyWindowMs:h}),`Room`)}function Se(){return F({target:{kind:`new`,type:D.Sensor},features:[{kind:`fields`,cap:`numeric-sensor`,fields:{value:{kind:`expression`,expr:`convert(v, "°C", "°F")`,bindings:{v:{kind:`from`,source:R,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function Ce(){return F({target:{kind:`new`,type:D.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:R,cap:`temperature-sensor`,fieldPath:`celsius`}}},lastChangedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Derived binary`)}function we(e){switch(e){case`room`:return xe();case`converted-sensor`:return Se();case`derived-binary`:return Ce()}}function Te(e,t){return typeof t==`number`&&Number.isFinite(t)&&t>0?{kind:`device`,path:`/devices/${t}`}:{kind:`editor`,path:`/build/compositions/${encodeURIComponent(e)}`}}var z=`rounded-lg border border-border bg-surface p-4`,Ee=z;function De(e){return{addonId:e.addonId,stableId:e.stableId}}function B(e){return new Map(e.map(e=>[y(De(e)),e]))}function Oe(e,t,n){let r=e?.features??[],i=r.findIndex(e=>e.cap===n.cap);return{target:e?.target??{kind:`existing`,device:t},features:i===-1?[...r,n]:r.map((e,t)=>t===i?n:e)}}function ke(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function Ae(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function V(e){return Array.isArray(e)?e.map(V):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,V(t)]))}function H(e){return JSON.stringify(V(e))}function je(e,t){return H(e)===H(t)}function U(e,t){return H(e)===H(t)}function Me(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:N.t(`helpers.customizationSave.notReadYet`)};case`unknown`:return{kind:`refused`,reason:`the customization could not be read: ${e.reason}`};case`not-loaded`:return{kind:`refused`,reason:`the customizations are not loaded yet: ${e.reason}`};case`none`:return t===null?{kind:`noop`}:{kind:`create`,input:{enabled:!0,composition:t}};case`present`:{let n=e.view.block.id;return t===null?{kind:`delete`,blockId:n}:H(t)===H(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function W(e,t){let n=e===`enum`?`string`:e,r=t.kind===`enum`?`string`:t.kind,i={source:t.source,cap:t.cap,fieldPath:t.fieldPath};return r===n?{kind:`from`,...i}:n===`number`&&r===`string`?{kind:`expression`,expr:`number(x)`,bindings:{x:{kind:`from`,...i}}}:null}function G(e){return{kind:`expression`,expr:e,bindings:{}}}function K(e){let t=W(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:G(`"unknown"`),sleeping:G(`false`),lastUpdated:G(`now`)}}}var Ne=[`percent`,...g.options];function q(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":G(JSON.stringify(t))}}function Pe(e,t){let n=W(`number`,t.remaining);if(n===null||!w.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:q(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:G(`now`),lastFetchedAt:G(`now`)},items:{...e?.items,[t.key]:r}}}function Fe(e){if(e.level!==void 0)return`percent`;let t=e[`remaining.unit`];if(t===void 0||t.kind!==`expression`)return null;try{let e=g.safeParse(JSON.parse(t.expr));return e.success?e.data:null}catch{return null}}function Ie(e){return Object.entries(e?.items??{}).map(([e,t])=>{let n=Fe(t.fields),r=J(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:W(`number`,r);return n!==null&&i!==null&&je(q(i,n),t.fields)?{key:e,label:t.label,unit:n,source:r}:{key:e,label:t.label,unit:null,source:null}})}function Le(e,t){let n=Object.fromEntries(Object.entries(e.items??{}).filter(([e])=>e!==t));return Object.keys(n).length===0?null:{...e,items:n}}function Re(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function ze(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=Object.entries(t.bindings).filter(([e])=>e.startsWith(`active`)).flatMap(([,e])=>e.kind===`from`?[e.source]:[]);return[...new Map(n.map(e=>[y(e),e])).values()]}function Be(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=t.bindings;return Object.entries(n).flatMap(([e,t])=>{if(!e.startsWith(`active`)||t.kind!==`from`)return[];let r=n[`changed${e.slice(6)}`];return r===void 0||r.kind!==`from`?[]:[{source:t.source,cap:t.cap,activeField:t.fieldPath,changedAtField:r.fieldPath}]})}function J(e){if(e===void 0)return null;if(e.kind===`from`){let{kind:t,...n}=e;return{...n,kind:`number`}}if(e.kind!==`expression`||e.expr!==`number(x)`)return null;let t=e.bindings.x;if(t===void 0||t.kind!==`from`||Object.keys(e.bindings).length!==1)return null;let{kind:n,...r}=t;return{...r,kind:`string`}}function Ve(e,t){let n=J(e.fields.percentage);if(n===null)return!1;let r=K({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&U(a,r)}function Y(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function He(e,t,n){let r=t.trim().toLowerCase();return r===``?[]:e.filter(e=>!n.includes(e.id)&&[e.name,e.stableId,e.location??``].some(e=>e.toLowerCase().includes(r))).toSorted((e,t)=>e.name.localeCompare(t.name)).slice(0,20)}function X(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=Object.getOwnPropertyDescriptor(n,e)?.value}return n}function Ue(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:W(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function We(e,t,n,r){let i={addonId:e.addonId,stableId:e.stableId};return t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,value:n===null?void 0:X(n[e.cap],t.path),source:Ue(i,e.cap,t,r)})))}function Z(e,t){return t?e===void 0?`—`:e===null?`null`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e):`…`}var Ge=[];function Ke({title:e,targetKind:t,excludeDeviceIds:r=Ge,onPick:i,onCancel:o}){let{t:s}=P(),[f,p]=n(null);return a(`aside`,{"aria-label":e,className:`${u} ${l} flex flex-col gap-2`,children:[c(`h3`,{className:d,children:e}),f===null?c(qe,{excludeDeviceIds:r,onSelect:p}):c(Je,{device:f,targetKind:t,onPick:i,onBack:()=>p(null)}),c(`div`,{children:c(M,{variant:`ghost`,size:`sm`,onClick:o,children:s(`customize.picker.cancel`)})})]})}function qe({excludeDeviceIds:e,onSelect:t}){let{t:r}=P(),[i,s]=n(``),l=A({projection:`slim`});return a(o,{children:[a(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground-subtle`,children:[r(`customize.picker.search`),c(se,{type:`search`,"aria-label":r(`customize.picker.search`),value:i,onChange:e=>s(e.target.value)})]}),l.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:r(`customize.picker.loadingDevices`)}),l.status===`error`&&c(j,{title:r(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&c(`ul`,{className:`flex flex-col gap-1`,children:He(Y(l.data),i,e).map(e=>c(`li`,{children:a(`button`,{type:`button`,className:`text-left text-[11px] hover:underline`,onClick:()=>t(e),children:[e.name,` `,a(`span`,{className:`text-foreground-subtle`,children:[`· `,e.stableId]})]})},e.id))})]})}function Je({device:e,targetKind:t,selected:n,onPick:r,onBack:i}){let{t:o}=P(),s=ae({deviceId:e.id}),l=pe({deviceId:e.id});if(s.status===`pending`)return c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingFields`)});if(s.status===`error`)return c(j,{title:o(`customize.picker.fieldsFailed`),message:s.error?.message??``});let u=We(e,s.data,l.status===`success`?l.data:null,t),d=u.filter(e=>e.source===null).length,f={addonId:e.addonId,stableId:e.stableId};return a(`div`,{className:`flex flex-col gap-1`,children:[a(`button`,{type:`button`,className:`text-left text-[11px] text-primary`,onClick:i,children:[`← `,e.name]}),l.status===`error`&&c(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:o(`customize.picker.valuesFailed`,{reason:l.error?.message??``})}),c(`ul`,{role:`listbox`,"aria-label":o(`customize.picker.fields`),className:`flex flex-col gap-1`,children:u.map(t=>{let i=t.source;if(i===null)return null;let o=()=>r({device:e,ref:f,cap:t.cap,path:t.path,kind:t.kind,source:i,value:t.value});return a(`li`,{role:`option`,"aria-selected":n?.cap===t.cap&&n.path===t.path,tabIndex:0,className:`flex justify-between gap-2 text-[11px] cursor-pointer hover:bg-surface-hover rounded px-1`,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&o()},children:[a(`span`,{className:`font-mono`,children:[t.cap,`.`,t.path]}),c(`span`,{children:Z(t.value,l.status===`success`)})]},`${t.cap}.${t.path}`)})}),d>0&&t!==null&&c(`p`,{className:`text-[10px] text-foreground-subtle`,children:o(`customize.picker.hidden`,{count:d,kind:o(`customize.kinds.${t}`)})})]})}var Ye=`integration`;function Q(e,t){switch(e.kind){case`from`:{let n=y(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function Xe(e,t){if(e.kind===`unreachable`)return{kind:`unknown`,reason:e.error};if(e.state===null)return{kind:`unknown`,reason:N.t(`helpers.fieldsTableRows.composerNotReported`)};let n=e.state.fields.find(t);return n===void 0?{kind:`unknown`,reason:N.t(`helpers.fieldsTableRows.noValue`)}:n.state===`unavailable`?{kind:`unavailable`,reason:n.reason??N.t(`common.unavailable`)}:{kind:`value`,value:n.value,staleReason:n.state===`stale`?n.reason??N.t(`common.stale`):null}}function Ze(e,t,n,r){return{key:`${e.feature.cap}.${t}`,cap:e.feature.cap,field:t,origin:`composed`,mode:e.mode,from:Q(n,e.input.sourceNames),value:e.enabled?Xe(e.input.state,r):{kind:`off`}}}function Qe(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>Ze(e,n,r,e=>e.cap===t&&e.path===n&&e.item===void 0))}function $e(e){let t=e.feature.cap;return Object.entries(e.feature.items??{}).flatMap(([n,r])=>Object.entries(r.fields).map(([r,i])=>Ze(e,_(m,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function et(e,t,n){if(e===null)return{kind:`unknown`,reason:N.t(`helpers.fieldsTableRows.stateUnreadable`)};let r=X(e[t],n),i=r===void 0?void 0:O(r);return i===void 0?{kind:`unknown`,reason:N.t(`helpers.fieldsTableRows.notReported`)}:{kind:`value`,value:i,staleReason:null}}function tt(e){if(e.mode!==`replace`)return[];let t=e.feature.cap,n=new Set(Object.keys(e.feature.fields));return(e.input.nativeFields.get(t)??[]).filter(e=>!n.has(e)).map(n=>({key:`${t}.${n}`,cap:t,field:n,origin:`native`,mode:e.mode,from:Ye,value:et(e.input.snapshot,t,n)}))}function nt(e){return e.composition.features.flatMap(t=>{if(t.kind!==`fields`)return[];let n={feature:t,mode:e.nativeCaps.has(t.cap)?`replace`:`add`,enabled:ee(t),input:e};return[...Qe(n),...$e(n),...tt(n)]})}var rt={min:`min(a, b, …)`,max:`max(a, b, …)`,abs:`abs(x)`,floor:`floor(x)`,ceil:`ceil(x)`,sqrt:`sqrt(x)`,round:`round(x, digits?)`,pow:`pow(x, y)`,clamp:`clamp(x, lo, hi)`,avg:`avg(a, b, …)`,sum:`sum(a, b, …)`,coalesce:`coalesce(a, b, …)`,age:`age(now, ts)`,convert:`convert(x, "from", "to")`,any:`any(a, b, …)`,all:`all(a, b, …)`,within:`within(ts, ms)`,number:`number(x)`,latest:`latest(ts, …)`,rose:`rose(level, changedAt, debounceMs?)`,count:`count(x)`},it=/[A-Za-z_][A-Za-z0-9_]*$/;function at(e,t,n){let r=it.exec(e.slice(0,t))?.[0]??``;if(r===``)return[];let i=n.filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`binding`,label:e,insert:e,hintKey:null})),a=`now`.startsWith(r)?[{kind:`now`,label:`now`,insert:`now`,hintKey:`compositionEditor.now`}]:[],o=[...te].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:rt[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function ot(e,t,n){let r=t-(it.exec(e.slice(0,t))?.[0]??``).length;return{text:`${e.slice(0,r)}${n.insert}${e.slice(t)}`,cursor:r+n.insert.length}}e();function st({label:e,value:t,bindings:r,onChange:i}){let{t:o}=P(),l=s(null),[u,d]=n(t.length),f=at(t,u,r);return a(`div`,{className:`flex flex-col gap-1`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e,c(`input`,{ref:l,className:`font-mono px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:t,onChange:e=>{i(e.target.value),d(e.target.selectionStart??e.target.value.length)},onSelect:e=>d(e.currentTarget.selectionStart??t.length)})]}),f.length>0&&c(`ul`,{role:`listbox`,"aria-label":o(`compositionEditor.suggestions`),className:`rounded border border-border bg-surface text-[11px]`,children:f.map(e=>a(`li`,{role:`option`,"aria-selected":!1,tabIndex:0,className:`flex justify-between gap-2 px-1 cursor-pointer hover:bg-surface-hover`,onClick:()=>{let n=ot(t,u,e);i(n.text),d(n.cursor),l.current?.focus()},children:[c(`span`,{className:`font-mono`,children:e.label}),e.hintKey!==null&&c(`span`,{className:`text-foreground-subtle`,children:o(e.hintKey)})]},`${e.kind}:${e.label}`))})]})}function ct(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:N.t(`helpers.fieldPreview.codeFields`)};if(e.kind===`expression`&&(x(e.expr,`rose`)||x(e.expr,`count`)))return{kind:`runtime-only`};let r=T(e).filter(e=>t.get(k(e.source,e.cap))?.kind!==`value`).map(b);if(r.length>0)return{kind:`waiting`,missing:r};let i=C({source:e,now:n,read:e=>{let n=t.get(k(e.source,e.cap)),r=n?.kind===`value`?X(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:O(r);return i===void 0?{state:`unavailable`,reason:N.t(`helpers.fieldPreview.notReported`,{path:`${e.cap}.${e.fieldPath}`}),fatal:!1}:{state:`fresh`,value:i}}});return i.state===`unavailable`?{kind:`unavailable`,reason:i.reason}:{kind:`value`,value:i.value,stale:i.reason}}e();function lt({sliceKey:e,deviceId:n,capName:r,onReading:i}){let a=fe(p().trpcClient,n,r);return t(()=>{i(e,a===void 0?{kind:`pending`}:{kind:`value`,slice:a})},[e,a,i]),null}function ut(e,t){return[...new Map(T(e).map(e=>[k(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(y(n.source))}))}function dt({source:e}){let{t}=P(),r=A({projection:`slim`}),[o,s]=n(new Map),l=i((e,t)=>{s(n=>new Map([...n,[e,t]]))},[]),u=ut(e,B(r.status===`success`?Y(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>y(e.read.source)):[];return a(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[u.map(e=>e.device===void 0?null:c(lt,{sliceKey:e.key,deviceId:e.device.id,capName:e.read.cap,onReading:l},e.key)),c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.label`)}),r.status===`error`?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.devicesFailed`,{reason:r.error?.message??``})}):d.length>0?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.unknownDevice`,{sources:d.join(`, `)})}):c(ft,{preview:ct(e,o,Date.now())})]})}function ft({preview:e}){let{t}=P();switch(e.kind){case`value`:return a(`strong`,{children:[`→ `,Z(e.value,!0),e.stale===null?``:` (${e.stale})`]});case`unavailable`:return c(`span`,{className:`text-warning`,children:e.reason});case`waiting`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.waiting`,{sources:e.missing.join(`, `)})});case`runtime-only`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.runtimeOnly`)})}}e();function pt({path:e,kind:t,required:r,source:i,onSet:s,onClear:l,onRemoveBinding:u,sourceNames:d}){let{t:f}=P(),[p,m]=n(`idle`),h=i?.kind===`expression`?i:null;return a(`div`,{className:`flex flex-col gap-1 rounded border border-border p-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono text-[11px]`,children:e}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:[f(`customize.kinds.${t}`),r?` · ${f(`compositionEditor.required`)}`:``]}),c(M,{size:`sm`,variant:`outline`,onClick:()=>m(`take`),children:f(`compositionEditor.takeFrom`)}),c(M,{size:`sm`,variant:`outline`,"aria-pressed":h!==null,onClick:()=>s(h??{kind:`expression`,expr:`null`,bindings:{}}),children:f(`compositionEditor.formula`)}),i!==void 0&&c(M,{size:`sm`,variant:`ghost`,onClick:l,children:f(`compositionEditor.clear`)})]}),i?.kind===`from`&&c(`span`,{className:`text-[11px]`,children:Q(i,d)}),h!==null&&a(o,{children:[c(st,{label:f(`compositionEditor.formulaFor`,{path:e}),value:h.expr,bindings:Object.keys(h.bindings),onChange:e=>s({...h,expr:e})}),c(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(h.bindings).map(([e,t])=>a(`li`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono`,children:e}),c(`span`,{children:t.kind===`from`?Q(t,d):JSON.stringify(t.value)}),c(M,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:e}),onClick:()=>u(e),children:`×`})]},e))}),c(M,{size:`sm`,variant:`ghost`,onClick:()=>m(`add-binding`),children:f(`compositionEditor.addSource`)})]}),p!==`idle`&&c(Ke,{title:f(p===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:p===`take`?t:null,onCancel:()=>m(`idle`),onPick:e=>{if(p===`take`)s(e.source);else if(h!==null){let t=ye(Object.keys(h.bindings));s({...h,bindings:{...h.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}m(`idle`)}}),i!==void 0&&c(dt,{source:i})]})}e();function mt(e){return e===null||e.kind===`known`?null:e}function ht({draft:e,deviceType:t,nativeCaps:r,targetFields:i,dispatch:s}){let{t:l}=P(),u=de({deviceType:t}),d=A({projection:`slim`}),f=new Map([...B(d.status===`success`?Y(d.data):[])].map(([e,t])=>[e,t.name])),[p,m]=n(null),h=mt(r)??mt(i),g=r?.kind===`known`?r.value:new Set,_=new Set(e.features.map(e=>e.cap)),v=u.status===`success`?u.data.caps.filter(e=>!_.has(e.cap)&&!g.has(e.cap)):[],y=[...g].filter(e=>!_.has(e)),b=e=>g.has(e)?((i?.kind===`known`?i.value.caps.find(t=>t.cap===e):void 0)?.fields??[]).filter(e=>e.item!==!0&&!e.path.includes(`.`)).map(e=>({path:e.path,kind:e.kind,required:!1})):((u.status===`success`?u.data.caps.find(t=>t.cap===e):void 0)?.fields??[]).map(e=>({path:e.path,kind:e.kind,required:e.required}));return h===null?a(o,{children:[a(`section`,{"aria-labelledby":`editor-features`,className:`${z} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),u.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.checking`)}),u.status===`error`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.unknown`,{reason:u.error?.message??``})}),a(`div`,{className:`flex flex-wrap gap-1`,children:[e.features.map(e=>a(`span`,{className:`flex items-center gap-1 rounded border border-border px-1.5 text-[11px]`,children:[e.cap,c(ce,{variant:g.has(e.cap)?`default`:`info`,children:g.has(e.cap)?l(`compositionEditor.replaces`):l(`compositionEditor.added`)}),c(`button`,{type:`button`,"aria-label":l(`compositionEditor.removeFeature`,{cap:e.cap}),onClick:()=>s({type:`remove-feature`,cap:e.cap}),children:`×`})]},e.cap)),v.map(e=>a(M,{size:`sm`,variant:`outline`,onClick:()=>s({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),y.map(e=>c(M,{size:`sm`,variant:`ghost`,onClick:()=>s({type:`add-feature`,cap:e}),children:l(`compositionEditor.replaceIn`,{cap:e})},e))]})]}),e.features.map(e=>a(`section`,{"aria-label":l(`compositionEditor.steps.fieldsOf`,{cap:e.cap}),className:`${z} flex flex-col gap-2`,children:[a(`div`,{className:`flex items-center justify-between`,children:[c(`h2`,{className:`text-sm font-semibold`,children:l(`compositionEditor.steps.fieldsOf`,{cap:e.cap})}),c(M,{size:`sm`,variant:`outline`,onClick:()=>m(e.cap),children:l(`compositionEditor.copyFeature`)})]}),p===e.cap&&c(Ke,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>m(null),onPick:t=>{s({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:b(e.cap).map(e=>e.path)}),m(null)}}),b(e.cap).map(t=>c(pt,{path:t.path,kind:t.kind,required:t.required,source:e.fields[t.path],onSet:n=>s({type:`set-field`,cap:e.cap,path:t.path,source:n}),onClear:()=>s({type:`clear-field`,cap:e.cap,path:t.path}),onRemoveBinding:n=>s({type:`remove-binding`,cap:e.cap,path:t.path,bindingName:n}),sourceNames:f},t.path))]},e.cap))]}):a(`section`,{"aria-labelledby":`editor-features`,className:`${z} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:h.kind===`unknown`?h.reason:l(`compositionEditor.reading`)})]})}var $=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function gt({draft:e,targetName:t,dispatch:n}){let r=f(),{t:i}=P(),o=e.target;return a(`section`,{"aria-labelledby":`editor-target`,className:`${z} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-target`,className:`text-sm font-semibold`,children:i(`compositionEditor.steps.target`)}),o.kind===`existing`?c(`p`,{className:`text-[11px]`,children:i(`compositionEditor.existingTarget`,{name:t??`${o.device.addonId}/${o.device.stableId}`})}):a(`div`,{className:`grid grid-cols-3 gap-2`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.targetType`),c(`select`,{className:$,value:o.type,onChange:e=>{let t=Object.values(D).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(D).map(e=>c(`option`,{value:e,children:oe(e,r).label},e))})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`customize.identity.role`),a(`select`,{className:$,value:o.role??``,onChange:e=>n({type:`set-new-role`,role:Object.values(E).find(t=>t===e.target.value)??null}),children:[c(`option`,{value:``,children:i(`customize.identity.noRole`)}),Object.values(E).map(e=>c(`option`,{value:e,children:le(e,r).label},e))]})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.name`),c(`input`,{className:$,value:e.name,onChange:e=>n({type:`set-name`,name:e.target.value})})]})]})]})}e();function _t({draft:e,blockId:r,saving:i,onSave:o,onCancel:s}){let{t:l}=P(),u=ue(),d=_e(e),f=d.ok?JSON.stringify(d.composition):``,[p,m]=n({key:``,state:{kind:`checking`}});t(()=>{if(!d.ok)return;let e=d.composition,t=setTimeout(()=>{u.mutateAsync({composition:e,...r===null?{}:{blockId:r}}).then(e=>m({key:f,state:e.ok?{kind:`ok`}:{kind:`refused`,problems:e.problems}})).catch(e=>m({key:f,state:{kind:`unknown`,reason:e instanceof Error?e.message:String(e)}}))},500);return()=>clearTimeout(t)},[f,r]);let h=d.ok?p.key===f?p.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return a(`section`,{"aria-labelledby":`editor-verify`,className:`${z} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),h.kind===`checking`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),h.kind===`ok`&&c(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),h.kind===`unknown`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:h.reason})}),(h.kind===`invalid-draft`||h.kind===`refused`)&&c(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:h.kind===`invalid-draft`?h.problems.map(e=>c(`li`,{children:e},e)):h.problems.map(e=>a(`li`,{children:[c(`span`,{className:`font-mono`,children:e.path}),` — `,e.message]},`${e.path}:${e.code}`))}),a(`div`,{className:`flex gap-2`,children:[c(M,{variant:`ghost`,onClick:s,children:l(`compositionEditor.cancel`)}),c(M,{disabled:h.kind!==`ok`||i||!d.ok,onClick:()=>d.ok&&o(d.composition),children:l(`compositionEditor.save`)})]})]})}e();function vt({initial:e,blockId:t,deviceType:r,targetName:i=null,nativeCaps:a,targetFields:o,save:s,onCancel:l,showTemplates:u=!1}){let[d,f]=n(e),p=`${d.name}:${d.features.map(e=>e.cap).join(`,`)}:${d.target.kind===`new`?d.target.type:`existing`}`;return c(yt,{seed:d,blockId:t,deviceType:r,targetName:i,nativeCaps:a,targetFields:o,showTemplates:u,onApplyTemplate:e=>{f(we(e))},save:s,onCancel:l},p)}function yt({seed:e,blockId:t,deviceType:i,targetName:o,nativeCaps:s,targetFields:l,showTemplates:u,onApplyTemplate:d,save:f,onCancel:p}){let{t:m}=P(),h=ie(),[g,_]=r(ge,e),[v,y]=n(!1),[b,x]=n(null),S=async t=>{ve(e,g)&&!await h({title:m(`compositionEditor.templates.confirmTitle`),message:m(`compositionEditor.templates.confirmMessage`),confirmLabel:m(`compositionEditor.templates.confirmApply`),variant:`danger`})||d(t)},C=g.target.kind===`new`?g.target.type:i,w=async e=>{y(!0);let t=await f(e,g.name);y(!1),x(t.kind===`refused`?t.reason:null)};return a(`div`,{className:`flex flex-col gap-4`,children:[u&&g.target.kind===`new`&&a(`div`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-wrap gap-2`,"data-testid":`composition-templates`,children:[c(`span`,{className:`text-[11px] text-foreground-subtle self-center`,children:m(`compositionEditor.templates.label`)}),be.map(e=>c(M,{size:`sm`,variant:`outline`,onClick:()=>void S(e),children:m(`compositionEditor.templates.${e}`)},e))]}),c(gt,{draft:g,targetName:o,dispatch:_}),c(ht,{draft:g,deviceType:C,nativeCaps:s,targetFields:l,dispatch:_}),c(_t,{draft:g,blockId:t,saving:v,onSave:e=>void w(e),onCancel:p}),b!==null&&c(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:b})]})}export{ke as C,he as D,F as E,me as O,Oe as S,Te as T,J as _,Je as a,Me as b,Y as c,Pe as d,Ie as f,Re as g,Ve as h,nt as i,Ne as l,Be as m,ct as n,Z as o,ze as p,st as r,X as s,vt as t,K as u,Le as v,Ee as w,U as x,Ae as y};
|
|
1
|
+
import{$ as e,B as t,J as n,K as r,L as i,S as a,b as o,q as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{D as l,O as u,V as d,ca as f,ot as p}from"./player-overlays-BYMAZza9.js";import{Br as m,Cn as h,Fn as g,Gr as _,Hr as v,Jr as y,Kr as b,Lr as x,Sn as S,Tn as C,Vr as w,Wr as ee,Yr as T,ci as E,li as D,ni as O,qr as k,ri as te,wn as ne,xn as re}from"./client-BggkinSi.js";import{Ar as ie,Au as ae,Hu as oe,Ja as se,Rr as ce,Wu as le,Ya as A,_a as ue,da as de,fr as j,hr as M,s as fe,wo as pe}from"./src-75D_Zlij.js";import{t as N}from"./i18n-BimjnPQq.js";import{t as P}from"./useTranslation-D3Is_4B6.js";e();function me(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function he(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function F(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function I(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function L(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function ge(e,t){switch(t.type){case`set-new-type`:return e.target.kind===`new`?{...e,target:{...e.target,type:t.deviceType}}:e;case`set-new-role`:{if(e.target.kind!==`new`)return e;let{role:n,...r}=e.target;return{...e,target:t.role===null?r:{...r,role:t.role}}}case`set-name`:return{...e,name:t.name};case`add-feature`:return e.features.some(e=>e.cap===t.cap)?e:{...e,features:[...e.features,{kind:`fields`,cap:t.cap,fields:{}}]};case`remove-feature`:return{...e,features:e.features.filter(e=>e.cap!==t.cap)};case`set-field`:return I(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return I(e,t.cap,e=>({...e,fields:L(e.fields,t.path)}));case`remove-binding`:return I(e,t.cap,e=>{let n=e.fields[t.path];return n?.kind===`expression`?{...e,fields:{...e.fields,[t.path]:{...n,bindings:L(n.bindings,t.bindingName)}}}:e});case`copy-feature`:return I(e,t.cap,e=>({...e,fields:{...e.fields,...Object.fromEntries(t.paths.map(e=>[e,{kind:`from`,source:t.from,cap:t.sourceCap,fieldPath:e}]))}}))}}function _e(e){let t=v.safeParse({target:e.target,features:e.features});return t.success?{ok:!0,composition:t.data}:{ok:!1,problems:t.error.issues.map(e=>`${e.path.join(`.`)||`composition`}: ${e.message}`)}}function ve(e,t){return JSON.stringify(e)!==JSON.stringify(t)}function ye(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var be=[`room`,`converted-sensor`,`derived-binary`],R={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function xe(){return F(ne({temperatureSources:S,motionSources:re,occupancyWindowMs:h}),`Room`)}function Se(){return F({target:{kind:`new`,type:D.Sensor},features:[{kind:`fields`,cap:`numeric-sensor`,fields:{value:{kind:`expression`,expr:`convert(v, "°C", "°F")`,bindings:{v:{kind:`from`,source:R,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function Ce(){return F({target:{kind:`new`,type:D.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:R,cap:`temperature-sensor`,fieldPath:`celsius`}}},lastChangedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Derived binary`)}function we(e){switch(e){case`room`:return xe();case`converted-sensor`:return Se();case`derived-binary`:return Ce()}}function Te(e,t){return typeof t==`number`&&Number.isFinite(t)&&t>0?{kind:`device`,path:`/devices/${t}`}:{kind:`editor`,path:`/build/compositions/${encodeURIComponent(e)}`}}var z=`rounded-lg border border-border bg-surface p-4`,Ee=z;function De(e){return{addonId:e.addonId,stableId:e.stableId}}function B(e){return new Map(e.map(e=>[y(De(e)),e]))}function Oe(e,t,n){let r=e?.features??[],i=r.findIndex(e=>e.cap===n.cap);return{target:e?.target??{kind:`existing`,device:t},features:i===-1?[...r,n]:r.map((e,t)=>t===i?n:e)}}function ke(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function Ae(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function V(e){return Array.isArray(e)?e.map(V):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,V(t)]))}function H(e){return JSON.stringify(V(e))}function je(e,t){return H(e)===H(t)}function U(e,t){return H(e)===H(t)}function Me(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:N.t(`helpers.customizationSave.notReadYet`)};case`unknown`:return{kind:`refused`,reason:`the customization could not be read: ${e.reason}`};case`not-loaded`:return{kind:`refused`,reason:`the customizations are not loaded yet: ${e.reason}`};case`none`:return t===null?{kind:`noop`}:{kind:`create`,input:{enabled:!0,composition:t}};case`present`:{let n=e.view.block.id;return t===null?{kind:`delete`,blockId:n}:H(t)===H(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function W(e,t){let n=e===`enum`?`string`:e,r=t.kind===`enum`?`string`:t.kind,i={source:t.source,cap:t.cap,fieldPath:t.fieldPath};return r===n?{kind:`from`,...i}:n===`number`&&r===`string`?{kind:`expression`,expr:`number(x)`,bindings:{x:{kind:`from`,...i}}}:null}function G(e){return{kind:`expression`,expr:e,bindings:{}}}function K(e){let t=W(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:G(`"unknown"`),sleeping:G(`false`),lastUpdated:G(`now`)}}}var Ne=[`percent`,...g.options];function q(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":G(JSON.stringify(t))}}function Pe(e,t){let n=W(`number`,t.remaining);if(n===null||!w.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:q(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:G(`now`),lastFetchedAt:G(`now`)},items:{...e?.items,[t.key]:r}}}function Fe(e){if(e.level!==void 0)return`percent`;let t=e[`remaining.unit`];if(t===void 0||t.kind!==`expression`)return null;try{let e=g.safeParse(JSON.parse(t.expr));return e.success?e.data:null}catch{return null}}function Ie(e){return Object.entries(e?.items??{}).map(([e,t])=>{let n=Fe(t.fields),r=J(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:W(`number`,r);return n!==null&&i!==null&&je(q(i,n),t.fields)?{key:e,label:t.label,unit:n,source:r}:{key:e,label:t.label,unit:null,source:null}})}function Le(e,t){let n=Object.fromEntries(Object.entries(e.items??{}).filter(([e])=>e!==t));return Object.keys(n).length===0?null:{...e,items:n}}function Re(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function ze(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=Object.entries(t.bindings).filter(([e])=>e.startsWith(`active`)).flatMap(([,e])=>e.kind===`from`?[e.source]:[]);return[...new Map(n.map(e=>[y(e),e])).values()]}function Be(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=t.bindings;return Object.entries(n).flatMap(([e,t])=>{if(!e.startsWith(`active`)||t.kind!==`from`)return[];let r=n[`changed${e.slice(6)}`];return r===void 0||r.kind!==`from`?[]:[{source:t.source,cap:t.cap,activeField:t.fieldPath,changedAtField:r.fieldPath}]})}function J(e){if(e===void 0)return null;if(e.kind===`from`){let{kind:t,...n}=e;return{...n,kind:`number`}}if(e.kind!==`expression`||e.expr!==`number(x)`)return null;let t=e.bindings.x;if(t===void 0||t.kind!==`from`||Object.keys(e.bindings).length!==1)return null;let{kind:n,...r}=t;return{...r,kind:`string`}}function Ve(e,t){let n=J(e.fields.percentage);if(n===null)return!1;let r=K({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&U(a,r)}function Y(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function He(e,t,n){let r=t.trim().toLowerCase();return r===``?[]:e.filter(e=>!n.includes(e.id)&&[e.name,e.stableId,e.location??``].some(e=>e.toLowerCase().includes(r))).toSorted((e,t)=>e.name.localeCompare(t.name)).slice(0,20)}function X(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=Object.getOwnPropertyDescriptor(n,e)?.value}return n}function Ue(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:W(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function We(e,t,n,r){let i={addonId:e.addonId,stableId:e.stableId};return t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,value:n===null?void 0:X(n[e.cap],t.path),source:Ue(i,e.cap,t,r)})))}function Z(e,t){return t?e===void 0?`—`:e===null?`null`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e):`…`}var Ge=[];function Ke({title:e,targetKind:t,excludeDeviceIds:r=Ge,onPick:i,onCancel:o}){let{t:s}=P(),[f,p]=n(null);return a(`aside`,{"aria-label":e,className:`${u} ${l} flex flex-col gap-2`,children:[c(`h3`,{className:d,children:e}),f===null?c(qe,{excludeDeviceIds:r,onSelect:p}):c(Je,{device:f,targetKind:t,onPick:i,onBack:()=>p(null)}),c(`div`,{children:c(M,{variant:`ghost`,size:`sm`,onClick:o,children:s(`customize.picker.cancel`)})})]})}function qe({excludeDeviceIds:e,onSelect:t}){let{t:r}=P(),[i,s]=n(``),l=A({projection:`slim`});return a(o,{children:[a(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground-subtle`,children:[r(`customize.picker.search`),c(ae,{type:`search`,"aria-label":r(`customize.picker.search`),value:i,onChange:e=>s(e.target.value)})]}),l.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:r(`customize.picker.loadingDevices`)}),l.status===`error`&&c(j,{title:r(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&c(`ul`,{className:`flex flex-col gap-1`,children:He(Y(l.data),i,e).map(e=>c(`li`,{children:a(`button`,{type:`button`,className:`text-left text-[11px] hover:underline`,onClick:()=>t(e),children:[e.name,` `,a(`span`,{className:`text-foreground-subtle`,children:[`· `,e.stableId]})]})},e.id))})]})}function Je({device:e,targetKind:t,selected:n,onPick:r,onBack:i}){let{t:o}=P(),s=se({deviceId:e.id}),l=pe({deviceId:e.id});if(s.status===`pending`)return c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingFields`)});if(s.status===`error`)return c(j,{title:o(`customize.picker.fieldsFailed`),message:s.error?.message??``});let u=We(e,s.data,l.status===`success`?l.data:null,t),d=u.filter(e=>e.source===null).length,f={addonId:e.addonId,stableId:e.stableId};return a(`div`,{className:`flex flex-col gap-1`,children:[a(`button`,{type:`button`,className:`text-left text-[11px] text-primary`,onClick:i,children:[`← `,e.name]}),l.status===`error`&&c(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:o(`customize.picker.valuesFailed`,{reason:l.error?.message??``})}),c(`ul`,{role:`listbox`,"aria-label":o(`customize.picker.fields`),className:`flex flex-col gap-1`,children:u.map(t=>{let i=t.source;if(i===null)return null;let o=()=>r({device:e,ref:f,cap:t.cap,path:t.path,kind:t.kind,source:i,value:t.value});return a(`li`,{role:`option`,"aria-selected":n?.cap===t.cap&&n.path===t.path,tabIndex:0,className:`flex justify-between gap-2 text-[11px] cursor-pointer hover:bg-surface-hover rounded px-1`,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&o()},children:[a(`span`,{className:`font-mono`,children:[t.cap,`.`,t.path]}),c(`span`,{children:Z(t.value,l.status===`success`)})]},`${t.cap}.${t.path}`)})}),d>0&&t!==null&&c(`p`,{className:`text-[10px] text-foreground-subtle`,children:o(`customize.picker.hidden`,{count:d,kind:o(`customize.kinds.${t}`)})})]})}var Ye=`integration`;function Q(e,t){switch(e.kind){case`from`:{let n=y(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function Xe(e,t){if(e.kind===`unreachable`)return{kind:`unknown`,reason:e.error};if(e.state===null)return{kind:`unknown`,reason:N.t(`helpers.fieldsTableRows.composerNotReported`)};let n=e.state.fields.find(t);return n===void 0?{kind:`unknown`,reason:N.t(`helpers.fieldsTableRows.noValue`)}:n.state===`unavailable`?{kind:`unavailable`,reason:n.reason??N.t(`common.unavailable`)}:{kind:`value`,value:n.value,staleReason:n.state===`stale`?n.reason??N.t(`common.stale`):null}}function Ze(e,t,n,r){return{key:`${e.feature.cap}.${t}`,cap:e.feature.cap,field:t,origin:`composed`,mode:e.mode,from:Q(n,e.input.sourceNames),value:e.enabled?Xe(e.input.state,r):{kind:`off`}}}function Qe(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>Ze(e,n,r,e=>e.cap===t&&e.path===n&&e.item===void 0))}function $e(e){let t=e.feature.cap;return Object.entries(e.feature.items??{}).flatMap(([n,r])=>Object.entries(r.fields).map(([r,i])=>Ze(e,_(m,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function et(e,t,n){if(e===null)return{kind:`unknown`,reason:N.t(`helpers.fieldsTableRows.stateUnreadable`)};let r=X(e[t],n),i=r===void 0?void 0:O(r);return i===void 0?{kind:`unknown`,reason:N.t(`helpers.fieldsTableRows.notReported`)}:{kind:`value`,value:i,staleReason:null}}function tt(e){if(e.mode!==`replace`)return[];let t=e.feature.cap,n=new Set(Object.keys(e.feature.fields));return(e.input.nativeFields.get(t)??[]).filter(e=>!n.has(e)).map(n=>({key:`${t}.${n}`,cap:t,field:n,origin:`native`,mode:e.mode,from:Ye,value:et(e.input.snapshot,t,n)}))}function nt(e){return e.composition.features.flatMap(t=>{if(t.kind!==`fields`)return[];let n={feature:t,mode:e.nativeCaps.has(t.cap)?`replace`:`add`,enabled:ee(t),input:e};return[...Qe(n),...$e(n),...tt(n)]})}var rt={min:`min(a, b, …)`,max:`max(a, b, …)`,abs:`abs(x)`,floor:`floor(x)`,ceil:`ceil(x)`,sqrt:`sqrt(x)`,round:`round(x, digits?)`,pow:`pow(x, y)`,clamp:`clamp(x, lo, hi)`,avg:`avg(a, b, …)`,sum:`sum(a, b, …)`,coalesce:`coalesce(a, b, …)`,age:`age(now, ts)`,convert:`convert(x, "from", "to")`,any:`any(a, b, …)`,all:`all(a, b, …)`,within:`within(ts, ms)`,number:`number(x)`,latest:`latest(ts, …)`,rose:`rose(level, changedAt, debounceMs?)`,count:`count(x)`},it=/[A-Za-z_][A-Za-z0-9_]*$/;function at(e,t,n){let r=it.exec(e.slice(0,t))?.[0]??``;if(r===``)return[];let i=n.filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`binding`,label:e,insert:e,hintKey:null})),a=`now`.startsWith(r)?[{kind:`now`,label:`now`,insert:`now`,hintKey:`compositionEditor.now`}]:[],o=[...te].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:rt[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function ot(e,t,n){let r=t-(it.exec(e.slice(0,t))?.[0]??``).length;return{text:`${e.slice(0,r)}${n.insert}${e.slice(t)}`,cursor:r+n.insert.length}}e();function st({label:e,value:t,bindings:r,onChange:i}){let{t:o}=P(),l=s(null),[u,d]=n(t.length),f=at(t,u,r);return a(`div`,{className:`flex flex-col gap-1`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e,c(`input`,{ref:l,className:`font-mono px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:t,onChange:e=>{i(e.target.value),d(e.target.selectionStart??e.target.value.length)},onSelect:e=>d(e.currentTarget.selectionStart??t.length)})]}),f.length>0&&c(`ul`,{role:`listbox`,"aria-label":o(`compositionEditor.suggestions`),className:`rounded border border-border bg-surface text-[11px]`,children:f.map(e=>a(`li`,{role:`option`,"aria-selected":!1,tabIndex:0,className:`flex justify-between gap-2 px-1 cursor-pointer hover:bg-surface-hover`,onClick:()=>{let n=ot(t,u,e);i(n.text),d(n.cursor),l.current?.focus()},children:[c(`span`,{className:`font-mono`,children:e.label}),e.hintKey!==null&&c(`span`,{className:`text-foreground-subtle`,children:o(e.hintKey)})]},`${e.kind}:${e.label}`))})]})}function ct(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:N.t(`helpers.fieldPreview.codeFields`)};if(e.kind===`expression`&&(x(e.expr,`rose`)||x(e.expr,`count`)))return{kind:`runtime-only`};let r=T(e).filter(e=>t.get(k(e.source,e.cap))?.kind!==`value`).map(b);if(r.length>0)return{kind:`waiting`,missing:r};let i=C({source:e,now:n,read:e=>{let n=t.get(k(e.source,e.cap)),r=n?.kind===`value`?X(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:O(r);return i===void 0?{state:`unavailable`,reason:N.t(`helpers.fieldPreview.notReported`,{path:`${e.cap}.${e.fieldPath}`}),fatal:!1}:{state:`fresh`,value:i}}});return i.state===`unavailable`?{kind:`unavailable`,reason:i.reason}:{kind:`value`,value:i.value,stale:i.reason}}e();function lt({sliceKey:e,deviceId:n,capName:r,onReading:i}){let a=fe(p().trpcClient,n,r);return t(()=>{i(e,a===void 0?{kind:`pending`}:{kind:`value`,slice:a})},[e,a,i]),null}function ut(e,t){return[...new Map(T(e).map(e=>[k(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(y(n.source))}))}function dt({source:e}){let{t}=P(),r=A({projection:`slim`}),[o,s]=n(new Map),l=i((e,t)=>{s(n=>new Map([...n,[e,t]]))},[]),u=ut(e,B(r.status===`success`?Y(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>y(e.read.source)):[];return a(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[u.map(e=>e.device===void 0?null:c(lt,{sliceKey:e.key,deviceId:e.device.id,capName:e.read.cap,onReading:l},e.key)),c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.label`)}),r.status===`error`?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.devicesFailed`,{reason:r.error?.message??``})}):d.length>0?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.unknownDevice`,{sources:d.join(`, `)})}):c(ft,{preview:ct(e,o,Date.now())})]})}function ft({preview:e}){let{t}=P();switch(e.kind){case`value`:return a(`strong`,{children:[`→ `,Z(e.value,!0),e.stale===null?``:` (${e.stale})`]});case`unavailable`:return c(`span`,{className:`text-warning`,children:e.reason});case`waiting`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.waiting`,{sources:e.missing.join(`, `)})});case`runtime-only`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.runtimeOnly`)})}}e();function pt({path:e,kind:t,required:r,source:i,onSet:s,onClear:l,onRemoveBinding:u,sourceNames:d}){let{t:f}=P(),[p,m]=n(`idle`),h=i?.kind===`expression`?i:null;return a(`div`,{className:`flex flex-col gap-1 rounded border border-border p-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono text-[11px]`,children:e}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:[f(`customize.kinds.${t}`),r?` · ${f(`compositionEditor.required`)}`:``]}),c(M,{size:`sm`,variant:`outline`,onClick:()=>m(`take`),children:f(`compositionEditor.takeFrom`)}),c(M,{size:`sm`,variant:`outline`,"aria-pressed":h!==null,onClick:()=>s(h??{kind:`expression`,expr:`null`,bindings:{}}),children:f(`compositionEditor.formula`)}),i!==void 0&&c(M,{size:`sm`,variant:`ghost`,onClick:l,children:f(`compositionEditor.clear`)})]}),i?.kind===`from`&&c(`span`,{className:`text-[11px]`,children:Q(i,d)}),h!==null&&a(o,{children:[c(st,{label:f(`compositionEditor.formulaFor`,{path:e}),value:h.expr,bindings:Object.keys(h.bindings),onChange:e=>s({...h,expr:e})}),c(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(h.bindings).map(([e,t])=>a(`li`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono`,children:e}),c(`span`,{children:t.kind===`from`?Q(t,d):JSON.stringify(t.value)}),c(M,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:e}),onClick:()=>u(e),children:`×`})]},e))}),c(M,{size:`sm`,variant:`ghost`,onClick:()=>m(`add-binding`),children:f(`compositionEditor.addSource`)})]}),p!==`idle`&&c(Ke,{title:f(p===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:p===`take`?t:null,onCancel:()=>m(`idle`),onPick:e=>{if(p===`take`)s(e.source);else if(h!==null){let t=ye(Object.keys(h.bindings));s({...h,bindings:{...h.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}m(`idle`)}}),i!==void 0&&c(dt,{source:i})]})}e();function mt(e){return e===null||e.kind===`known`?null:e}function ht({draft:e,deviceType:t,nativeCaps:r,targetFields:i,dispatch:s}){let{t:l}=P(),u=de({deviceType:t}),d=A({projection:`slim`}),f=new Map([...B(d.status===`success`?Y(d.data):[])].map(([e,t])=>[e,t.name])),[p,m]=n(null),h=mt(r)??mt(i),g=r?.kind===`known`?r.value:new Set,_=new Set(e.features.map(e=>e.cap)),v=u.status===`success`?u.data.caps.filter(e=>!_.has(e.cap)&&!g.has(e.cap)):[],y=[...g].filter(e=>!_.has(e)),b=e=>g.has(e)?((i?.kind===`known`?i.value.caps.find(t=>t.cap===e):void 0)?.fields??[]).filter(e=>e.item!==!0&&!e.path.includes(`.`)).map(e=>({path:e.path,kind:e.kind,required:!1})):((u.status===`success`?u.data.caps.find(t=>t.cap===e):void 0)?.fields??[]).map(e=>({path:e.path,kind:e.kind,required:e.required}));return h===null?a(o,{children:[a(`section`,{"aria-labelledby":`editor-features`,className:`${z} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),u.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.checking`)}),u.status===`error`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.unknown`,{reason:u.error?.message??``})}),a(`div`,{className:`flex flex-wrap gap-1`,children:[e.features.map(e=>a(`span`,{className:`flex items-center gap-1 rounded border border-border px-1.5 text-[11px]`,children:[e.cap,c(ce,{variant:g.has(e.cap)?`default`:`info`,children:g.has(e.cap)?l(`compositionEditor.replaces`):l(`compositionEditor.added`)}),c(`button`,{type:`button`,"aria-label":l(`compositionEditor.removeFeature`,{cap:e.cap}),onClick:()=>s({type:`remove-feature`,cap:e.cap}),children:`×`})]},e.cap)),v.map(e=>a(M,{size:`sm`,variant:`outline`,onClick:()=>s({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),y.map(e=>c(M,{size:`sm`,variant:`ghost`,onClick:()=>s({type:`add-feature`,cap:e}),children:l(`compositionEditor.replaceIn`,{cap:e})},e))]})]}),e.features.map(e=>a(`section`,{"aria-label":l(`compositionEditor.steps.fieldsOf`,{cap:e.cap}),className:`${z} flex flex-col gap-2`,children:[a(`div`,{className:`flex items-center justify-between`,children:[c(`h2`,{className:`text-sm font-semibold`,children:l(`compositionEditor.steps.fieldsOf`,{cap:e.cap})}),c(M,{size:`sm`,variant:`outline`,onClick:()=>m(e.cap),children:l(`compositionEditor.copyFeature`)})]}),p===e.cap&&c(Ke,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>m(null),onPick:t=>{s({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:b(e.cap).map(e=>e.path)}),m(null)}}),b(e.cap).map(t=>c(pt,{path:t.path,kind:t.kind,required:t.required,source:e.fields[t.path],onSet:n=>s({type:`set-field`,cap:e.cap,path:t.path,source:n}),onClear:()=>s({type:`clear-field`,cap:e.cap,path:t.path}),onRemoveBinding:n=>s({type:`remove-binding`,cap:e.cap,path:t.path,bindingName:n}),sourceNames:f},t.path))]},e.cap))]}):a(`section`,{"aria-labelledby":`editor-features`,className:`${z} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:h.kind===`unknown`?h.reason:l(`compositionEditor.reading`)})]})}var $=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function gt({draft:e,targetName:t,dispatch:n}){let r=f(),{t:i}=P(),o=e.target;return a(`section`,{"aria-labelledby":`editor-target`,className:`${z} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-target`,className:`text-sm font-semibold`,children:i(`compositionEditor.steps.target`)}),o.kind===`existing`?c(`p`,{className:`text-[11px]`,children:i(`compositionEditor.existingTarget`,{name:t??`${o.device.addonId}/${o.device.stableId}`})}):a(`div`,{className:`grid grid-cols-3 gap-2`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.targetType`),c(`select`,{className:$,value:o.type,onChange:e=>{let t=Object.values(D).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(D).map(e=>c(`option`,{value:e,children:le(e,r).label},e))})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`customize.identity.role`),a(`select`,{className:$,value:o.role??``,onChange:e=>n({type:`set-new-role`,role:Object.values(E).find(t=>t===e.target.value)??null}),children:[c(`option`,{value:``,children:i(`customize.identity.noRole`)}),Object.values(E).map(e=>c(`option`,{value:e,children:oe(e,r).label},e))]})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.name`),c(`input`,{className:$,value:e.name,onChange:e=>n({type:`set-name`,name:e.target.value})})]})]})]})}e();function _t({draft:e,blockId:r,saving:i,onSave:o,onCancel:s}){let{t:l}=P(),u=ue(),d=_e(e),f=d.ok?JSON.stringify(d.composition):``,[p,m]=n({key:``,state:{kind:`checking`}});t(()=>{if(!d.ok)return;let e=d.composition,t=setTimeout(()=>{u.mutateAsync({composition:e,...r===null?{}:{blockId:r}}).then(e=>m({key:f,state:e.ok?{kind:`ok`}:{kind:`refused`,problems:e.problems}})).catch(e=>m({key:f,state:{kind:`unknown`,reason:e instanceof Error?e.message:String(e)}}))},500);return()=>clearTimeout(t)},[f,r]);let h=d.ok?p.key===f?p.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return a(`section`,{"aria-labelledby":`editor-verify`,className:`${z} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),h.kind===`checking`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),h.kind===`ok`&&c(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),h.kind===`unknown`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:h.reason})}),(h.kind===`invalid-draft`||h.kind===`refused`)&&c(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:h.kind===`invalid-draft`?h.problems.map(e=>c(`li`,{children:e},e)):h.problems.map(e=>a(`li`,{children:[c(`span`,{className:`font-mono`,children:e.path}),` — `,e.message]},`${e.path}:${e.code}`))}),a(`div`,{className:`flex gap-2`,children:[c(M,{variant:`ghost`,onClick:s,children:l(`compositionEditor.cancel`)}),c(M,{disabled:h.kind!==`ok`||i||!d.ok,onClick:()=>d.ok&&o(d.composition),children:l(`compositionEditor.save`)})]})]})}e();function vt({initial:e,blockId:t,deviceType:r,targetName:i=null,nativeCaps:a,targetFields:o,save:s,onCancel:l,showTemplates:u=!1}){let[d,f]=n(e),p=`${d.name}:${d.features.map(e=>e.cap).join(`,`)}:${d.target.kind===`new`?d.target.type:`existing`}`;return c(yt,{seed:d,blockId:t,deviceType:r,targetName:i,nativeCaps:a,targetFields:o,showTemplates:u,onApplyTemplate:e=>{f(we(e))},save:s,onCancel:l},p)}function yt({seed:e,blockId:t,deviceType:i,targetName:o,nativeCaps:s,targetFields:l,showTemplates:u,onApplyTemplate:d,save:f,onCancel:p}){let{t:m}=P(),h=ie(),[g,_]=r(ge,e),[v,y]=n(!1),[b,x]=n(null),S=async t=>{ve(e,g)&&!await h({title:m(`compositionEditor.templates.confirmTitle`),message:m(`compositionEditor.templates.confirmMessage`),confirmLabel:m(`compositionEditor.templates.confirmApply`),variant:`danger`})||d(t)},C=g.target.kind===`new`?g.target.type:i,w=async e=>{y(!0);let t=await f(e,g.name);y(!1),x(t.kind===`refused`?t.reason:null)};return a(`div`,{className:`flex flex-col gap-4`,children:[u&&g.target.kind===`new`&&a(`div`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-wrap gap-2`,"data-testid":`composition-templates`,children:[c(`span`,{className:`text-[11px] text-foreground-subtle self-center`,children:m(`compositionEditor.templates.label`)}),be.map(e=>c(M,{size:`sm`,variant:`outline`,onClick:()=>void S(e),children:m(`compositionEditor.templates.${e}`)},e))]}),c(gt,{draft:g,targetName:o,dispatch:_}),c(ht,{draft:g,deviceType:C,nativeCaps:s,targetFields:l,dispatch:_}),c(_t,{draft:g,blockId:t,saving:v,onSave:e=>void w(e),onCancel:p}),b!==null&&c(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:b})]})}export{ke as C,he as D,F as E,me as O,Oe as S,Te as T,J as _,Je as a,Me as b,Y as c,Pe as d,Ie as f,Re as g,Ve as h,nt as i,Ne as l,Be as m,ct as n,Z as o,ze as p,st as r,X as s,vt as t,K as u,Le as v,Ee as w,U as x,Ae as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Pr as n,li as r}from"./client-
|
|
1
|
+
import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Pr as n,li as r}from"./client-BggkinSi.js";import{t as i}from"./boxes-BaumwARG.js";import{aa as a,fr as o,ga as s,la as c}from"./src-75D_Zlij.js";import{t as l}from"./useTranslation-D3Is_4B6.js";import{Q as u,_ as d,et as f,f as p,tt as m}from"./index-BVY_WMe1.js";import{E as h,O as g,T as _,t as v,w as y}from"./CompositionEditor-BruCgxbv.js";import{t as b}from"./AdminPage-D_zEoNvj.js";var x=`new`;function S(e){return e instanceof Error?e.message:String(e)}function C(e){let t=e.trim();return t===``?{}:{name:t}}function w(){let{blockId:w}=m(),{t:T}=l(),E=f(),D=a(),O=s(),k=w===void 0||w===x,A=c({blockId:w??``},{enabled:!k}),j=()=>{E(p)},M=e=>t(b,{icon:i,title:T(`compositionEditor.pageTitle`),children:e}),N=e=>t(`section`,{className:`${y} flex flex-col gap-2`,children:e});if(k)return M(t(v,{initial:g(r.Sensor),blockId:null,deviceType:r.Sensor,nativeCaps:null,targetFields:null,showTemplates:!0,onCancel:j,save:async(e,t)=>{try{let{block:n}=await D.mutateAsync({block:{...C(t),enabled:!0,composition:e}});return E(_(n.id,null).path,{replace:!0}),{kind:`saved`}}catch(e){return{kind:`refused`,reason:S(e)}}}}));if(A.status===`pending`)return M(N(t(`p`,{role:`status`,children:T(`compositionEditor.loading`)})));if(A.status===`error`)return M(N(t(o,{title:T(`compositionEditor.loadFailed`),message:A.error.message})));if(A.data.state===`not-loaded`)return M(N(t(`p`,{role:`status`,children:T(`customize.status.notLoaded`,{reason:A.data.reason})})));let P=A.data.view;if(P===null)return M(N(t(`p`,{children:T(`compositionEditor.notFound`,{blockId:w})})));let F=n(P.block);if(F===null)return M(N(t(`p`,{children:T(`compositionEditor.notComposition`)})));if(F.target.kind===`existing`){let e=P.state.kind===`answered`?P.state.state?.deviceId??null:null;return M(N(e===null?t(`p`,{children:T(`compositionEditor.customizationUnknownDevice`)}):t(u,{className:`text-primary`,to:d(e),children:T(`compositionEditor.openOnDevice`)})))}let I=P.state.kind===`answered`?P.state.state?.deviceId??null:null,L=I===null?null:_(P.block.id,I);return M(e(`div`,{className:`flex flex-col gap-3`,children:[L!==null&&L.kind===`device`&&t(u,{className:`text-sm text-primary`,to:L.path,"data-testid":`open-composed-device`,children:T(`compositionEditor.openComposedDevice`,{id:I})}),t(v,{initial:h(F,P.block.name),blockId:P.block.id,deviceType:F.target.type,nativeCaps:null,targetFields:null,onCancel:j,save:async(e,t)=>{try{return await O.mutateAsync({blockId:P.block.id,expectedUpdatedAt:P.block.updatedAt,block:{...C(t),composition:e}}),await A.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:S(e)}}}},`${P.block.id}@${P.block.updatedAt}`)]}))}export{w as CompositionEditorPage};
|