@camstack/addon-admin-ui 1.2.8 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/assets/{AddLocationWizard-DZT8c1Gh.js → AddLocationWizard-BsfRBmG0.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-CnbUqGtk.js → AddonCollectionPage-CXHeV-JA.js} +1 -1
  3. package/dist/assets/{Addons-BoHKHT6D.js → Addons-CqINXARB.js} +1 -1
  4. package/dist/assets/{AdminTabs-DoJIdigB.js → AdminTabs-DPHt9Vrr.js} +1 -1
  5. package/dist/assets/{AiProfiles-B5iQGj0g.js → AiProfiles-CrBHGY9x.js} +1 -1
  6. package/dist/assets/{BrokerForm-JP0u8lMv.js → BrokerForm-ySM02NYp.js} +1 -1
  7. package/dist/assets/{Capabilities-D6S3xNBX.js → Capabilities-RJVgwEI-.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-DLAfx4tg.js → CapabilityBadges-BfPStFDD.js} +1 -1
  9. package/dist/assets/{Cluster-Br9H32NH.js → Cluster-dRepFsEe.js} +1 -1
  10. package/dist/assets/{ClusterRecordingTab-CEo7_iKE.js → ClusterRecordingTab-ZjVaVby-.js} +1 -1
  11. package/dist/assets/{Dashboard-B8lmGL4Z.js → Dashboard-BZ5hmETC.js} +1 -1
  12. package/dist/assets/{Data-DR7Vuym7.js → Data-wAV4YBKT.js} +1 -1
  13. package/dist/assets/{DetectionIntelligence-CRF-M2IN.js → DetectionIntelligence-Bg7TpnIp.js} +1 -1
  14. package/dist/assets/{DeviceDetail-D6VFBen5.js → DeviceDetail-DqhElVhT.js} +1 -1
  15. package/dist/assets/{Devices-CZ2wQtyI.js → Devices-CfdnyBPp.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-lT7iR0O_.js → EmbedPlayerPage-Bcoa9QdA.js} +1 -1
  17. package/dist/assets/{Events-BQKzjNhF.js → Events-DVCiXgvH.js} +1 -1
  18. package/dist/assets/{FormBuilder-BxN8f0nT.js → FormBuilder-6mYk-4qC.js} +1 -1
  19. package/dist/assets/{Identity-Cb6ECkDX.js → Identity-DoJbe6Tm.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-CpI_ICc1.js → IntegrationDetail-C-TlCYIU.js} +1 -1
  21. package/dist/assets/{Integrations-D9uRl2ae.js → Integrations-BaTJ1efj.js} +1 -1
  22. package/dist/assets/{Integrations-VyVneDyb.js → Integrations-gznlBNQL.js} +1 -1
  23. package/dist/assets/{Logs-wn4_EjbH.js → Logs-BYB5TxRZ.js} +1 -1
  24. package/dist/assets/{MyAccess-BYwIrleo.js → MyAccess-UCG3zSEN.js} +1 -1
  25. package/dist/assets/{Network-BvWfcFc3.js → Network-DL8hq6nl.js} +1 -1
  26. package/dist/assets/{NodeAddonsSettingsPanel-COOdNAE-.js → NodeAddonsSettingsPanel-DY-AneF0.js} +1 -1
  27. package/dist/assets/{NodeInferenceDevices-CKFylLYO.js → NodeInferenceDevices-DlG9HB9Y.js} +1 -1
  28. package/dist/assets/{Notifications-CpjTFB_4.js → Notifications-BKw_GWsb.js} +1 -1
  29. package/dist/assets/{Pipeline-L18VOJ84.js → Pipeline-cxfq6x3v.js} +1 -1
  30. package/dist/assets/{Plates-CsufxUMt.js → Plates-Bx_hE0aw.js} +1 -1
  31. package/dist/assets/{PrivacyMaskSettings-CEP-TRt9.js → PrivacyMaskSettings-BJvJ34n1.js} +1 -1
  32. package/dist/assets/{ProviderIcon-BUhDaDzj.js → ProviderIcon-CQTRNfxg.js} +1 -1
  33. package/dist/assets/{Recordings-BUYsGeTn.js → Recordings-Crcm4LyU.js} +1 -1
  34. package/dist/assets/{ScanNetworkModal-CZI_Y2cA.js → ScanNetworkModal-CXbSxWid.js} +1 -1
  35. package/dist/assets/{Settings-DFWv-6mZ.js → Settings-cYqjCG75.js} +1 -1
  36. package/dist/assets/{Showroom-C-zwer-u.js → Showroom-B6fhw1D9.js} +1 -1
  37. package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CHN43utV.js +1 -0
  38. package/dist/assets/{build-cluster-graph-C2qQbNkr.js → build-cluster-graph-BN5pfFK1.js} +1 -1
  39. package/dist/assets/circle-check-big-B9HIwiFo.js +1 -0
  40. package/dist/assets/clock-HmbKVCZT.js +1 -0
  41. package/dist/assets/{copy-D5oufG5Q.js → copy-BmgVaD29.js} +1 -1
  42. package/dist/assets/{debounced-invalidate-CRCuY4xi.js → debounced-invalidate-DCtq_NHc.js} +1 -1
  43. package/dist/assets/{download-Dfq_dNdv.js → download-NKkCvEeB.js} +1 -1
  44. package/dist/assets/{face-bbox-B8GTLKhX.js → face-bbox-C2co2f2G.js} +1 -1
  45. package/dist/assets/{history-CGNeCFev.js → history-CaP7eXW2.js} +1 -1
  46. package/dist/assets/hostInit-Cfj52F2C.js +1 -0
  47. package/dist/assets/{index-BIxHon5T.js → index-RegSp4ae.js} +3 -3
  48. package/dist/assets/{key-round-BfkBDb0w.js → key-round-Cblg8i0e.js} +1 -1
  49. package/dist/assets/{mf-entry-bootstrap-0-6c20c631.js → mf-entry-bootstrap-0-1aa09b03.js} +2 -2
  50. package/dist/assets/{pencil-DRb48wcw.js → pencil-Ik1l3G_8.js} +1 -1
  51. package/dist/assets/plus-B0OPxy2A.js +1 -0
  52. package/dist/assets/{radio-Dra-qtSX.js → radio-BtzRHQBo.js} +1 -1
  53. package/dist/assets/{refresh-cw-DWkaxiHf.js → refresh-cw-D92Y26QW.js} +1 -1
  54. package/dist/assets/remoteEntry-f6PDtaSI.js +1 -0
  55. package/dist/assets/{rotate-ccw-ZwrMVXrr.js → rotate-ccw-ByTFEZ8o.js} +1 -1
  56. package/dist/assets/rotate-cw-C6p7zQhm.js +1 -0
  57. package/dist/assets/search-BUbY58eR.js +1 -0
  58. package/dist/assets/{send-Bx-Qr3_Q.js → send-CGqdmApb.js} +1 -1
  59. package/dist/assets/{server-Cso-UurU.js → server-BwAvkFi_.js} +1 -1
  60. package/dist/assets/square-Ckdv6ORu.js +1 -0
  61. package/dist/assets/{square-check-big-CH9QT5C_.js → square-check-big-tgpBR4IT.js} +1 -1
  62. package/dist/assets/{src-Wny3-FFU.js → src-Bwet06Ih.js} +4 -4
  63. package/dist/assets/{upload-BNtucejS.js → upload-BNU4vgq-.js} +1 -1
  64. package/dist/assets/{useEventInvalidation-CPx5I8W4.js → useEventInvalidation-BslmDCfY.js} +1 -1
  65. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B1_rU1SX.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-5Zi8N25y.js} +2 -2
  66. package/dist/assets/{wifi-CwFWxUko.js → wifi-C-i5Y8G3.js} +1 -1
  67. package/dist/assets/{zap-By2kL6s3.js → zap-DWRzzBU1.js} +1 -1
  68. package/dist/index.html +3 -3
  69. package/dist/server/addon.js +1 -1
  70. package/package.json +1 -1
  71. package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B6IsqzCN.js +0 -1
  72. package/dist/assets/circle-check-big-sPqnrKad.js +0 -1
  73. package/dist/assets/clock-B96wFCLt.js +0 -1
  74. package/dist/assets/hostInit-6V2rStu6.js +0 -1
  75. package/dist/assets/plus-Ecpq7H2e.js +0 -1
  76. package/dist/assets/remoteEntry-DzvkbuOH.js +0 -1
  77. package/dist/assets/rotate-cw-DFCIBZWX.js +0 -1
  78. package/dist/assets/search-DKK_bhK4.js +0 -1
  79. package/dist/assets/square-CEkhTs0-.js +0 -1
@@ -1 +1 @@
1
- import{$r as e,Ci as t,Do as n,Ei as r,Ha as i,Ii as a,Ja as o,Ka as s,La as c,Mi as l,Ni as u,Oo as d,Pi as f,Qr as p,Si as m,T as h,Ti as g,Ua as _,Va as v,Vr as y,Wa as b,Xa as x,Za as S,_ as C,_i as w,ai as T,bi as E,ci as D,di as O,ei as k,ft as A,g as j,gi as M,ii as N,ji as ee,li as P,lt as te,mi as ne,ni as re,oi as ie,qa as ae,ri as oe,si as se,ti as ce,ut as le,vi as ue,wi as de,xi as fe,xo as pe,yi as me}from"./src-Wny3-FFU.js";import{I as he,K as ge,Q as F,S as I,T as _e,W as L,b as R,o as z,q as B,x as V,z as H}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{G as ve,K as ye,X as be}from"./src-GxiMH1Sc.js";import{c as xe,n as U,o as Se,r as Ce,s as we,t as Te}from"./NodeInferenceDevices-CKFylLYO.js";import{t as Ee}from"./download-Dfq_dNdv.js";import{i as De}from"./AddLocationWizard-DZT8c1Gh.js";import{n as Oe,r as ke,t as Ae}from"./zap-By2kL6s3.js";import{t as je}from"./pencil-DRb48wcw.js";import{t as Me}from"./plus-Ecpq7H2e.js";import{t as Ne}from"./radio-Dra-qtSX.js";import{t as Pe}from"./refresh-cw-DWkaxiHf.js";import{t as Fe}from"./search-DKK_bhK4.js";import{t as Ie}from"./server-Cso-UurU.js";import{t as Le}from"./square-check-big-CH9QT5C_.js";import{t as Re}from"./square-CEkhTs0-.js";import{E as ze,I as Be,J as Ve,L as He,M as Ue,N as We,P as Ge,S as W,T as Ke,W as qe,i as Je,j as G,o as Ye,s as Xe}from"./index-BIxHon5T.js";import{t as Ze}from"./AdminPage-BwmGKnRf.js";import{t as Qe}from"./useEventInvalidation-CPx5I8W4.js";import{r as $e,t as et}from"./build-cluster-graph-C2qQbNkr.js";import{n as tt}from"./format-size-CO9d3C3-.js";import{t as nt}from"./NodeAddonsSettingsPanel-COOdNAE-.js";import{n as rt,t as it}from"./ClusterRecordingTab-CEo7_iKE.js";var at=qe(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),ot=qe(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),st=qe(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);F();function ct(e){return e}function lt(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function ut(e,t){return typeof e==`boolean`?e:ct(t)}function dt(e,t){return{pipeline:ut(lt(e,`detect`),t),audio:ut(lt(e,`audio`),t),ingest:ut(lt(e,`ingest`),t)}}function ft(e,t,n){let r=e?.find(e=>e.nodeId===t);return dt(r?.settings,n)}function pt({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:r}=y(void 0),{data:i}=M(void 0),{data:a}=ue(void 0),o=new Map;for(let e of i??[])o.set(e.agentNodeId,(o.get(e.agentNodeId)??0)+1);let s=r??[],c=s.filter(e=>e.isOnline).length,l=s.filter(e=>!e.isOnline).length;return I(`div`,{className:`flex flex-col h-full`,children:[I(`button`,{type:`button`,onClick:()=>t(Sr),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[V(Ke,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[V(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),V(`div`,{className:`flex-1 overflow-y-auto`,children:s.map(n=>{let r=e===n.id,i=o.get(n.id)??0,s=n.isHub?Ie:G,c=ft(a,n.id,n.isHub),l=n.isOnline?null:d($e(n.lastSeen));return I(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[V(s,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),I(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[I(`span`,{children:[n.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),i>0&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[V(Oe,{className:`h-2.5 w-2.5`}),i]})]}),!n.isOnline&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`text-destructive`,children:[`offline`,l===null?``:` · ${l}`]})]})]}),I(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[V(pe,{variant:c.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:c.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),V(pe,{variant:c.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:c.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),I(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[I(`span`,{children:[c,` online`]}),l>0&&I(`span`,{className:`text-destructive`,children:[l,` offline`]})]})]})}function mt({nodeId:e,refreshToken:t}){let{data:n}=y(void 0),r=n?.find(t=>t.id===e),a=i(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?I(`div`,{className:`px-6 py-4 border-b border-border`,children:[I(`div`,{className:`flex items-center gap-2 mb-1`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[V(`span`,{children:r.cpuModel??`CPU`}),V(`span`,{children:`•`}),I(`span`,{children:[r.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),V(`span`,{children:`•`}),I(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),V(`span`,{children:`•`}),I(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&I(R,{children:[V(`span`,{children:`•`}),V(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):V(`div`,{className:`px-6 py-4 border-b border-border`,children:I(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function ht({refreshToken:e,nodeId:t}){let[n,r]=B(new Map),{nodes:i}=v();b(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:a}=P(void 0),o=L(()=>{let e=new Map;for(let t of a??[])e.set(t.nodeId,t.deviceCount);return e},[a]),s=L(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),c=L(()=>{let e=new Map;for(let t of i)e.set(t.id,t.shortName);return e},[i]),l=L(()=>{let e=0,t=0,n=0,r=0,a=0;for(let i of s.values())e+=i.attachedCameras,t+=i.activeCameras,n+=i.totalFps,r+=i.totalInferenceWeighted,a+=i.queueDepth;let o=e>0?r/e:0;return{totalAgents:i.length,onlineAgents:i.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:o,queueDepth:a,totalFps:n}},[s,i]);if(t){let e=s.get(t);return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[V(K,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),V(K,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),V(K,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),V(K,{label:`Queue`,value:e?String(e.queueDepth):`—`}),V(K,{label:`Audio`,value:String(o.get(t)??`—`)})]})]})}let u=[...s.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[V(K,{label:`Total agents`,value:`${l.onlineAgents}/${l.totalAgents}`}),V(K,{label:`Active / Attached`,value:`${l.activeCameras}/${l.attachedCameras}`}),V(K,{label:`Total FPS`,value:l.totalFps.toFixed(1)}),V(K,{label:`Avg inference ms`,value:l.avgInferenceTimeMs.toFixed(0)}),V(K,{label:`Queue depth`,value:String(l.queueDepth)})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[480px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),V(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),V(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),V(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),V(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),V(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),I(`tbody`,{children:[u.map(([e,t])=>I(`tr`,{className:`border-t border-border`,children:[V(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:c.get(e)??e}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:o.get(e)??`—`})]},e)),u.length===0&&V(`tr`,{children:V(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function K({label:e,value:t}){return I(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[V(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),V(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}F();var gt={active:!1,pinned:!1,nodeId:null,reason:``},_t=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],vt={pipeline:G,decoder:ze,audio:ke},yt={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function bt({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let r=z(),[i,a]=B(null),[o,s]=B(null),[c,d]=B(new Map);Qe([`pipelineOrchestrator`,`getPipelineAssignments`],_t),Qe([`pipelineOrchestrator`,`getAudioAssignments`],_t),Qe([`pipelineOrchestrator`,`getCameraStatuses`],_t);let{data:f}=M(void 0),{data:p}=D(void 0),{data:m}=O({},{enabled:e===`agent`}),{nodes:g}=v(),{data:_}=Se();b(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&d(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),H(()=>{if(c.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[c.size]);let y=L(()=>{let e=new Map;for(let t of _??[])e.set(t.id,t.name);return e},[_]),x=L(()=>{if(e===`agent`){let e=[];for(let n of m??[]){let r=n.assignment,i=(e,n,r)=>({active:e!==null&&e===t,pinned:n,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:n.deviceId,deviceName:y.get(n.deviceId)??`Device ${n.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:y.get(e)??`Device ${e}`,pipeline:gt,decoder:gt,audio:gt};return n.set(e,r),r};for(let i of f??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let e of p??[]){let t=r(e.deviceId);n.set(e.deviceId,{...t,audio:{active:!0,pinned:e.pinned,nodeId:e.nodeId,reason:`capacity`}})}let i=[...n.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[f,p,m,y,e,t]),S=L(()=>(g??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[g]),C=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},w=ie({onSuccess:C}),E=u({onSuccess:C}),k=T({onSuccess:C}),A=l({onSuccess:C}),j=(e,t,n)=>{t===`pipeline`?w.mutate({deviceId:e,agentNodeId:n}):k.mutate({deviceId:e,nodeId:n}),a(null)},N=(e,t)=>{t===`pipeline`?E.mutate({deviceId:e}):A.mutate({deviceId:e}),a(null)};return V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&V(`th`,{className:`w-10`}),V(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?I(R,{children:[V(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),V(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):I(R,{children:[V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),V(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),I(`tbody`,{children:[x.map(t=>{let r=c.get(t.deviceId),l=o===t.deviceId;return I(_e.Fragment,{children:[I(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&V(`td`,{className:`px-2 py-2 align-middle`,children:V(`button`,{type:`button`,onClick:()=>s(l?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":l?`Collapse broker details`:`Expand broker details`,children:V(l?Be:Ge,{className:`h-3.5 w-3.5`})})}),I(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[V(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?I(R,{children:[V(`td`,{className:`px-3 py-2 align-middle`,children:V(St,{state:t.pipeline,onlineNodes:S,pending:w.isPending||E.isPending,onChange:e=>{e===`auto`?N(t.deviceId,`pipeline`):j(t.deviceId,`pipeline`,e)}})}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(Ct,{state:t.pipeline,deviceId:t.deviceId})})]}):I(R,{children:[V(Tt,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:S,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`pipeline`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>a(null),onMove:e=>j(t.deviceId,`pipeline`,e),onUnpin:()=>N(t.deviceId,`pipeline`)}),V(Tt,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:S,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),V(Tt,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:S,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`audio`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>a(null),onMove:e=>j(t.deviceId,`audio`,e),onUnpin:()=>N(t.deviceId,`audio`)})]}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(kt,{snap:r})})]}),l&&!n&&I(`tr`,{className:`bg-surface/50`,children:[V(`td`,{}),I(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&V(xt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),V(h,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})]})]})]},t.deviceId)}),x.length===0&&V(`tr`,{children:V(`td`,{colSpan:n?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function xt({deviceId:e,nodeId:t}){let n=z(),{data:r}=ne({nodeId:t}),{data:i}=w({deviceId:e}),a=ee({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),o=r?.devices??[],s=i?.deviceKey??`auto`,c=s!==`auto`&&!o.some(e=>e.key===s);return I(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[V(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),I(`select`,{value:s,disabled:a.isPending,"aria-label":`Inference device pin`,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[V(`option`,{value:`auto`,children:`Auto (balanced)`}),c&&I(`option`,{value:s,children:[`Pin → `,s,` (not on this node)`]}),o.map(e=>I(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),a.isPending&&V(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function St({state:e,onlineNodes:t,pending:n,onChange:r}){let i=e.pinned&&e.nodeId?e.nodeId:`auto`,a=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return I(`select`,{value:i,disabled:n,"aria-label":`Pipeline placement pin`,onChange:e=>r(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[V(`option`,{value:`auto`,children:`Auto`}),a.map(e=>I(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function Ct({state:e,deviceId:t}){if(!e.active||!e.nodeId)return V(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let n=e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`;return I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,title:e.nodeId,children:e.nodeId}),V(`span`,{className:`truncate ${e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:n,children:n}),V(wt,{deviceId:t,nodeId:e.nodeId})]})}function wt({deviceId:e,nodeId:t}){let n=z(),{data:r}=w({deviceId:e},{refetchOnMount:`always`}),{data:i}=ne({nodeId:t},{refetchOnMount:`always`}),a=ee({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||i===void 0)return V(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let o=i.devices??[],s=o.filter(e=>e.enabled),c=r.deviceKey??`auto`,l=c!==`auto`&&!s.some(e=>e.key===c),u=o.find(e=>e.key===c);return I(`select`,{value:c,disabled:a.isPending,"aria-label":`Inference device pin`,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value}),className:`mt-0.5 w-full min-w-0 rounded border border-border bg-background px-1 py-0.5 text-[10px] text-foreground disabled:opacity-50`,children:[V(`option`,{value:`auto`,children:`Auto (balanced)`}),l&&I(`option`,{value:c,children:[u?`${U(u).label} (${c})`:c,` (not enabled)`]}),s.map(e=>I(`option`,{value:e.key,children:[U(e).label,` · `,e.format]},e.key))]})}function Tt({role:e,state:t,mode:n,onlineNodes:r,readOnly:i=!1,isMenuOpen:a,onToggleMenu:o,onCloseMenu:s,onMove:c,onUnpin:l}){let u=vt[e],d=r.filter(e=>e.id!==(t.nodeId??``)),f=!i&&(t.active||n===`cluster`)&&(d.length>0||t.pinned);return I(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[I(`div`,{className:`flex items-center gap-2 min-w-0`,children:[V(n===`agent`?Et:Dt,{state:t,Icon:u}),V(`div`,{className:`ml-auto shrink-0`,children:f&&V(`button`,{type:`button`,onClick:o,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${yt[e]} actions`,children:V(at,{className:`h-3 w-3 text-foreground-subtle`})})})]}),a&&f&&V(At,{title:yt[e],targets:d,pinned:t.pinned,onMove:c,onUnpin:l,onClose:s})]})}function Et({state:e,Icon:t}){return I(`div`,{className:`flex items-center gap-1.5`,children:[V(e.active?Le:Re,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),V(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&V(st,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Dt({state:e,Icon:t}){return!e.active||!e.nodeId?I(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[V(t,{className:`h-3 w-3`}),V(`span`,{className:`text-[10px] italic`,children:`—`})]}):I(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[V(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),V(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?I(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[V(st,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Ot=`min-h-[3.25rem]`;function kt({snap:e}){if(!e)return V(`div`,{className:`flex items-center ${Ot}`,children:V(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:r,avgInferenceTimeMs:i,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=n(t);return I(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Ot}`,children:[I(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[V(C,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),V(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:r.toFixed(1)}),I(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:i.toFixed(0)}),V(`span`,{children:` ms`}),a>0&&I(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),I(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,V(`span`,{className:`text-foreground`,children:s})]})]})}function At({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=ge(null);return H(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),I(`div`,{ref:o,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[V(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&V(`div`,{className:`py-1`,children:t.map(e=>I(`button`,{type:`button`,onClick:()=>r(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),n&&I(`button`,{type:`button`,onClick:i,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,e.toLowerCase()]}),t.length===0&&!n&&V(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function jt({nodeId:e,refreshToken:t}){return I(`div`,{className:`space-y-6`,children:[V(ht,{refreshToken:t,nodeId:e}),I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),V(bt,{mode:`agent`,nodeId:e,compact:!0})]})}F();function Mt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Nt({nodeId:e,refreshToken:t}){let n=z(),r=oe({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:o}=N({nodeId:e}),s=i(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??o??null,c=s===null;Qe([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:l}=a({nodeId:e}),{values:u}=_(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),d=L(()=>u.filter(e=>e.metrics.phase===`active`).length,[u]),f=t=>{let n=l??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||r.mutate({nodeId:e,engine:t,force:n.length>0})};return I(`div`,{className:`space-y-6`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(s??[]).length,` engine(s) resident in RAM. `,(l??[]).length,` `,`camera(s) attached, `,d,` actively dispatching frames. Refreshes every 5s.`]})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[640px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),V(`th`,{className:`text-left px-3 py-2`,children:`Models`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),V(`th`,{className:`w-20`})]})}),I(`tbody`,{children:[c&&V(`tr`,{children:V(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!c&&(s??[]).map(e=>{let t=e.kind===`warm-override`,n=e.kind===`device-pool`;return I(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:n?`bg-primary/[0.05]`:``}`,children:[V(`td`,{className:`px-3 py-2`,children:I(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:n?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[V(t?ot:n?xe:G,{className:`h-3 w-3`}),t?`warm`:n?`pool`:`runtime`]})}),V(`td`,{className:`px-3 py-2`,children:I(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[V(Ae,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),V(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?V(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>V(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),V(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),V(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?V(`span`,{className:`text-foreground-subtle`,children:Mt(e.idleMs,e.idleTtlMs)}):V(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(l??[]).length}),V(`td`,{className:`px-3 py-2 text-right`,children:n?V(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):I(`button`,{type:`button`,disabled:r.isPending,onClick:()=>f(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[V(Xe,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!c&&(s??[]).length===0&&V(`tr`,{children:V(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[V(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,V(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,V(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),r.isError&&I(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,r.error instanceof Error?r.error.message:`unknown`]})]})}F();var Pt=new Set(be);function Ft(e){return Pt.has(e)}function It(e,t,n){return`${e}/${t}/${n}`}function Lt(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function Rt(e){return{coreml:`Apple Neural Engine / GPU — .mlpackage`,openvino:`Intel CPU / GPU / NPU — .xml`,onnx:`CPU, CUDA, Node.js — .onnx`}[e.format]??`.${e.format}`}function q(e){return e.format}function zt(e,t){let n=0,r=0,i=0;for(let a of e)for(let e of a.addons)for(let a of e.models){let e=a.formats[t];e&&(n++,e.downloaded&&(r++,i+=e.sizeMB))}return{total:n,downloaded:r,downloadedSizeMB:i}}function Bt({addonId:e,model:t,format:n,isActive:r,progress:i,errorMsg:a,onDownload:o,onDelete:s}){let c=t.formats[n];return c?I(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors`,children:[V(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),I(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&I(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[V(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:V(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),I(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),V(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:tt(c.sizeMB)}),a&&I(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[V(We,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?I(`button`,{onClick:s,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[r?V(W,{className:`h-3 w-3 animate-spin`}):V(Xe,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):I(`button`,{onClick:o,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[r?V(W,{className:`h-3 w-3 animate-spin`}):V(Ee,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function Vt({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=B(!1);return I(`div`,{className:`relative`,children:[I(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[V(G,{className:`h-4 w-4 text-primary shrink-0`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:Lt(n)}),q(n)===q(t)&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:Rt(n)})]}),V(Be,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&V(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let i=q(e)===q(n),o=q(e)===q(t);return I(`button`,{type:`button`,onClick:()=>{r(e),a(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${i?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[V(G,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),I(`div`,{className:`flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:Lt(e)}),o&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:Rt(e)})]}),i&&V(Ue,{className:`h-4 w-4 text-primary shrink-0`})]},q(e))})})]})}function Ht({embedded:t=!1,nodeId:n}={}){let r=z(),i=n??`hub`,[a,o]=B(null),[s,c]=B(new Set),[l,u]=B(new Map),[d,f]=B(new Map),[m,h]=B(``),{data:g=[]}=k({nodeId:i}),_=g.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:v}=re({nodeId:i}),y=v,{data:x,isLoading:S}=ce({nodeId:i}),C=e(),w=p();b(`model.download.progress`,e=>{let t=e.data,n=typeof t.modelId==`string`?t.modelId:void 0,i=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;n===void 0||i===void 0||(u(e=>{let t=new Map(e);return i===100||i===-1?t.delete(n):t.set(n,{modelId:n,progress:i,totalMB:a}),t}),i===100&&r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let T=y??{runtime:`node`,backend:`cpu`,format:`onnx`},E=_.find(e=>e.format===a)??T,D=E.format,O=x?.slots??[],A=O.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(e=>e.formats[D]!==void 0)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),j=zt(A,D),M=he(async(e,t,n)=>{if(!Ft(n))return;let a=It(e,t,n);c(e=>new Set([...e,a])),f(e=>{let t=new Map(e);return t.delete(a),t});try{await C.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){f(t=>new Map([...t,[a,e instanceof Error?e.message:`Download failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[C,r,i]),N=he(async(e,t,n)=>{if(!Ft(n))return;let a=It(e,t,n);c(e=>new Set([...e,a])),f(e=>{let t=new Map(e);return t.delete(a),t});try{await w.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){f(t=>new Map([...t,[a,e instanceof Error?e.message:`Delete failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[w,r,i]),ee=he(e=>{o(e.format)},[]),P=m.trim()?A.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(m.toLowerCase())||t.id.toLowerCase().includes(m.toLowerCase())||e.name.toLowerCase().includes(m.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):A,te=I(R,{children:[S&&V(`div`,{className:`flex items-center justify-center py-16`,children:V(W,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!S&&O.length===0&&I(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[V(De,{className:`h-8 w-8 mb-3 opacity-30`}),V(`span`,{className:`text-sm`,children:`No pipeline steps available`}),V(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!S&&O.length>0&&I(R,{children:[V(Vt,{engines:_,activeEngine:T,viewEngine:E,onSelect:ee}),I(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground tabular-nums`,children:j.total}),V(`span`,{className:`ml-1`,children:`compatible models`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success tabular-nums`,children:j.downloaded}),V(`span`,{className:`ml-1`,children:`downloaded`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{className:`tabular-nums`,children:[tt(j.downloadedSizeMB),V(`span`,{className:`ml-1`,children:`on disk`})]})]}),j.total>5&&I(`div`,{className:`relative`,children:[V(Fe,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),V(`input`,{type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:`Search models...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary`})]}),P.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+t.models.filter(e=>e.formats[D]?.downloaded).length,0);return I(`div`,{children:[I(`div`,{className:`flex items-center gap-2 mb-2`,children:[V(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),V(`div`,{className:`flex-1 h-px bg-border`}),I(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=It(e.id,t.id,D);return V(Bt,{addonId:e.id,model:t,format:D,isActive:s.has(n),progress:l.get(t.id),errorMsg:d.get(n),onDownload:()=>M(e.id,t.id,D),onDelete:()=>N(e.id,t.id,D)},`${e.id}/${t.id}`)}))})]},e.id)}),P.length===0&&V(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:m.trim()?I(R,{children:[`No models matching “`,m,`”`]}):I(R,{children:[`No models available for `,Lt(E),` format`]})})]})]});return t?V(`div`,{className:`space-y-4`,children:te}):V(Ze,{children:te})}function Ut({nodeId:e,refreshToken:t}){return V(Ht,{embedded:!0,nodeId:e})}var Wt=`pipeline-runner`,Gt=200;function Kt({nodeId:e}){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(j,{agentId:e,addonId:Wt,limit:Gt,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F(),F();function qt({nodeId:e,title:t}){let{data:r}=Se(),{data:i}=M(void 0),a=L(()=>{let e=new Map;for(let t of r??[])e.set(t.id,t.name);return e},[r]),o=L(()=>{if(!e)return null;let t=new Set;for(let n of i??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,i]),[s,c]=B(new Map);b(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||c(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),H(()=>{if(s.size===0)return;let e=setInterval(()=>{c(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[s.size]);let l=L(()=>{let e=[];for(let t of s.values())o&&!o.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[s,o]);return l.length===0?I(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):I(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[I(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[V(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),V(`span`,{className:`text-[10px] text-foreground-subtle`,children:l.length})]}),V(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>{let t=a.get(e.deviceId)??`#${e.deviceId}`,r=n(e.metrics.phase);return I(`div`,{title:`${t} · ${r.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${r.badgeClass}`,children:[V(C,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),V(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),V(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),V(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}F();function J(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Jt(e){if(!e)return null;let t=e.modelId!==void 0&&e.modelId!==``?e.modelId:void 0,n=e.settings&&Object.keys(e.settings).length>0?e.settings:void 0;return t===void 0&&n===void 0?null:{...t===void 0?{}:{modelId:t},...n===void 0?{}:{settings:n}}}function Yt({nodeId:e,refreshToken:t}){let n=z(),[r,i]=B(null),[a,c]=B(null),[l,u]=B(``),[d,f]=B(null),p=ne({nodeId:e},{refetchOnMount:`always`}),m=ce({nodeId:e},{refetchOnMount:`always`}),h=p.data?.devices??[],_=g({onSuccess:()=>{n.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),v=L(()=>m.data?x(m.data):[],[m.data]),y=L(()=>h.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:U(t).label})),[h,e]),b=e=>h.find(t=>t.key===e)??null,C=L(()=>h.filter(e=>e.enabled),[h]),w=C.length>=2,T=(e,t)=>{let n=J(m.data??null,e),r=t?.format;return n?.models.some(e=>r!==void 0&&!!e.formats[r])??!1},E=e=>{let t=b(e);return t?U(t).label:e},D=(e,t)=>C.filter(n=>n.key!==t&&T(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,O=e=>{let t=J(m.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},k=(e,t)=>{let n=J(m.data??null,e),r=t?.format;if(!(!n||r===void 0))return(n.slot===`detector`?t?.defaultModelId:void 0)??s(n,r)},A=(e,t)=>{let n=O(e),r=n.kind===`gate`?n.effectiveOn:!1,i=J(m.data??null,e),a=t.deviceKey===void 0?null:b(t.deviceKey),o=a?.format,s=i?.models.some(e=>o!==void 0&&!!e.formats[o])??!1,c=a?.steps?.[e];if(!s){if(!r)return{kind:`na`};let n=c?.jumpDeviceKey,i=n!==void 0&&C.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:D(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:E(i)}}return{kind:`enabled`,modelId:c?.modelId??k(e,a)??`Auto`,...c?.jumpDeviceKey!==void 0&&C.some(e=>e.key===c.jumpDeviceKey)?{jumpTo:E(c.jumpDeviceKey)}:{}}},j=r&&m.data?J(m.data,r.addonId):null,M=r?b(r.deviceKey):null,N=M?.format??`coreml`,ee=r?k(r.addonId,M):void 0,P=()=>{i(null),c(null),u(``)},te=(e,t)=>{if(t.deviceKey===void 0)return;let n=b(t.deviceKey)?.steps?.[e];i({addonId:e,deviceKey:t.deviceKey}),c({enabled:!0,...n?.modelId===void 0?{}:{modelId:n.modelId},settings:n?.settings??{}}),u(n?.jumpDeviceKey??``)},re=()=>{if(!r)return;let t=Jt(a),n=l!==``&&l!==r.deviceKey?l:void 0,i=t||n!==void 0?{...t,...n===void 0?{}:{jumpDeviceKey:n}}:null,o={};for(let e of h){if(!e.enabled&&e.key!==r.deviceKey)continue;let t={...e.steps};e.key===r.deviceKey&&(i?t[r.addonId]=i:delete t[r.addonId]);let n=Object.keys(t).length>0;o[e.key]={enabled:!0,weight:Math.max(1,e.weight),...e.maxSessions!=null&&e.maxSessions>0?{maxSessions:e.maxSessions}:{},...n?{steps:t}:{}}}_.mutate({agentNodeId:e,inferenceDevices:o},{onSuccess:P})};if(p.isLoading||m.isLoading)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(h.length===0)return V(`div`,{className:`rounded-md border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`});if(!m.data)return V(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ie=r!==null&&j!==null&&M!==null;return I(`div`,{className:`relative h-full w-full space-y-3`,children:[I(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[`Each column is one of this node's inference accelerators. A cell shows the`,` `,V(`span`,{className:`font-medium text-foreground`,children:`base model`}),` every camera landing on that accelerator runs; click to change it. Whether a camera runs a step is set per-camera on that camera's Detection pipeline tab — there is no gate here.`]}),V(`div`,{className:ie?`md:pr-[360px]`:``,children:v.length>0?V(ae,{tree:v,agents:y,gateFor:O,getCellState:A,onCellClick:te,selectedCell:r?{addonId:r.addonId,agentNodeId:e,deviceKey:r.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:d,onFallbackNodeChange:f,hideGate:!0}):V(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),V(S,{open:ie,onClose:P,title:j?.name??``,subtitle:r&&M?`${e} · ${U(M).label} · ${M.format}`:``,footer:I(R,{children:[V(`div`,{className:`flex-1`}),V(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:P,children:`Cancel`}),V(`button`,{type:`button`,disabled:!r||!a||_.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:re,children:_.isPending?`Saving…`:`Save`})]}),children:j&&r&&a?I(`div`,{className:`space-y-3`,children:[w&&I(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[V(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),I(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:l,onChange:e=>u(e.target.value),children:[V(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),C.filter(e=>e.key!==r.deviceKey).map(e=>I(`option`,{value:e.key,children:[U(e).label,` · `,e.format]},e.key))]}),V(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),V(o,{mode:`agent`,addon:j,agentDefault:a,agentNodeId:e,engineFormat:N,effectiveModelId:ee,onChangeAgentConfig:c})]}):V(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}F();var Xt=[`pipeline-orchestrator`],Zt=[`decoder`],Qt=!1;function $t({nodeId:e,refreshToken:t}){let n=c(),[r,i]=B(null),[a,o]=B(null),s=(y(void 0).data??[]).find(t=>t.id===e),l=s?.name??e,u=s?.isOnline??!1,d=fe({onSuccess:e=>{o(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${l} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(o(null),d.mutate({agentNodeId:e}))};return I(`div`,{className:`relative h-full w-full space-y-3`,children:[I(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[a&&V(`span`,{className:`text-emerald-400`,children:a}),d.isError&&V(`span`,{className:`text-red-400`,children:d.error instanceof Error?d.error.message:`Reset failed`}),V(`button`,{type:`button`,onClick:()=>{f()},disabled:d.isPending,className:`rounded border border-amber-500/40 bg-surface px-2 py-0.5 text-amber-300 hover:bg-surface-hover disabled:opacity-50`,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:d.isPending?`Resetting…`:`Reset to default`})]}),V(qt,{nodeId:e}),V(nt,{nodeId:e,addonIds:Xt,level:`global`,sectionIds:Zt}),Qt,Qt,I(`div`,{children:[V(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),V(Te,{nodeId:e,nodeName:l,isOnline:u})]}),I(`div`,{children:[V(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),V(Yt,{nodeId:e,refreshToken:t})]})]})}var en=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],tn=`decoder-nodeav`;function nn({nodeId:e,refreshToken:t}){let{data:n}=y(void 0),r=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??tn,i=[...en,r];return I(`div`,{className:`flex flex-col h-full`,children:[V(mt,{nodeId:e,refreshToken:t}),V(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:V(nt,{nodeId:e,addonIds:i,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:V(jt,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:V($t,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:V(Nt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:V(Ut,{nodeId:e,refreshToken:t})},{id:`logs`,label:`Logs`,order:300,content:V(Kt,{nodeId:e})}]})})]})}function rn(){return I(`div`,{className:`space-y-6`,children:[V(qt,{title:`Cluster cameras`}),I(`div`,{className:`min-w-0`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Use the Auto | Pin control to pin a camera to a node, the inference-device select to pin it to an accelerator, or the kebab to move a role; expand the chevron for the per-camera broker drill-down. Cluster load, inference-device weights, and Rebalance live on the Balancer tab.`})]}),V(bt,{mode:`cluster`})]})}var an=`pipeline-orchestrator`,on=`recorder`,sn=`recordingNodeId`,cn=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],ln=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function un(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function dn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function fn(e,t,n){let r=un(e,t);return typeof r==`string`&&r.length>0?r:n}function pn(e,t,n){let r=un(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function mn(e,t){let n=dn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function hn(e,t){let n=dn(e,t);return typeof n==`string`&&n.length>0?n:null}function gn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function _n(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function vn(e,t){switch(t){case`detect`:return e.pipeline}}function yn(e){return e instanceof Error?e.message:`Failed to save`}function bn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function xn({capability:e,label:t,hint:n,nodeId:r,active:i,pending:a,layout:o,onToggle:s}){let c=i?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,l=o===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,u=i?He:we;return I(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":`${t} capability for ${r}`,title:`${t} — ${n}`,disabled:a,onClick:()=>s(e,!i),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${c} ${l}`,children:[V(u,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),V(`span`,{children:t})]})}function Sn({node:e,emphasis:t=!1}){let n=e.isHub?Ie:G;return I(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[V(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),V(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),I(`div`,{className:`min-w-0`,children:[I(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[V(`span`,{className:`truncate`,children:e.name}),e.isHub&&V(pe,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&V(pe,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),V(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}F();function Cn({nodeId:e,value:t,detectedHosts:n,status:r,errorMessage:i,onCommit:a}){let[o,s]=B(t??``);H(()=>{s(t??``)},[t]);let c=n[0],l=c===void 0?`auto-detect`:`auto: ${c}`,u=r===`pending`,d=o.trim(),f=d!==(t??``),p=f&&!u,m=()=>{p&&a(e,d.length>0?d:null)};return I(`div`,{className:`flex items-center gap-1.5`,children:[V(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:l,value:o,disabled:u,onChange:e=>s(e.target.value),onBlur:m,onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&s(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),I(`button`,{type:`button`,onClick:m,disabled:!p,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[u?V(W,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):V(He,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!f&&!u&&r===`success`&&V(He,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),r===`error`&&V(`span`,{title:i??`Failed to save reachable host`,children:V(We,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":i??`Failed to save reachable host`,role:`img`})})]})}function wn({label:e,children:t}){return I(`div`,{className:`flex items-center justify-between gap-3`,children:[V(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function Tn({node:e,actions:t}){return I(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[V(Sn,{node:e,emphasis:!0}),V(`div`,{className:`grid grid-cols-2 gap-2`,children:ln.map(n=>V(xn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:vn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),V(`div`,{className:`space-y-3 border-t border-border pt-3`,children:V(wn,{label:`Reachable host`,children:V(Cn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function En(){return I(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function Dn({nodes:e,actions:t}){return V(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:I(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[V(`thead`,{children:I(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),ln.map(e=>V(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),V(`tbody`,{children:e.map(e=>I(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[V(`td`,{className:`px-4 py-3 align-middle`,children:V(Sn,{node:e})}),ln.map(n=>V(`td`,{className:`px-3 py-3 text-center align-middle`,children:V(xn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:vn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),V(`td`,{className:`px-4 py-3 align-middle`,children:V(Cn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})]},e.id))})]})})}function On({role:e,value:t,options:n,pending:r,onChange:i}){return I(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[V(`span`,{className:`text-xs font-semibold text-foreground`,children:gn(e)}),V(`select`,{value:t,disabled:r,onChange:t=>i(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:n.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),V(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:_n(e)})]})}function kn({roleValues:e,options:t,pending:n,lowFpsEnabled:r,fpsMinThreshold:i,onRoleChange:a,onLowFpsToggle:o}){return I(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[cn.map(r=>V(On,{role:r,value:e[r],options:t,pending:n,onChange:a},r)),I(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[V(`input`,{type:`checkbox`,checked:r,disabled:n,onChange:e=>o(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),I(`span`,{className:`flex flex-col gap-0.5`,children:[V(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),I(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,r?`${i} fps`:`disabled`]})]})]})]})}F();function An(){let e=z(),{nodes:n}=v(),i=ue(void 0),a=le({addonId:an}),o=le({addonId:on}),s=()=>bn(e),c=t({onSuccess:s}),l=de(),u=r({onSuccess:s}),d=A({onSuccess:s}),[f,p]=B(!1),m=L(()=>{let e=new Map;for(let t of i.data??[])e.set(t.nodeId,t.settings);return e},[i.data]),h=L(()=>n.map(e=>{let t=m.get(e.id),n=dt(t,e.isHub),r=mn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:mn(t,`maxCameras`),reachableHost:hn(t,`reachableHost`),detectedHosts:e.localIps}}),[n,m]),g=h.filter(e=>e.effective.pipeline),_={ingestNode:fn(a.data,`ingestNode`,`hub`),recordingNode:fn(o.data,sn,`hub`),audioNode:fn(a.data,`audioNode`,`hub`),motionNode:fn(a.data,`motionNode`,`hub`)},y=L(()=>{let e=n.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...cn.map(e=>_[e]),...e])].filter(e=>e.length>0)},[n,_]),b=pn(a.data,`fpsMinThreshold`,0),x=b>0,S=i.isLoading||a.isLoading||o.isLoading,C=(e,t,n)=>{c.mutate({agentNodeId:e,[t]:n})},w=(e,t)=>{if(e===`recordingNode`){d.mutate({addonId:on,patch:{[sn]:t}});return}d.mutate({addonId:an,patch:{[e]:t}})},T=e=>{d.mutate({addonId:an,patch:{fpsMinThreshold:e?Math.max(1,b):0}})},E=e=>u.variables?.agentNodeId===e?u.isPending?`pending`:u.isError?`error`:u.isSuccess?`success`:`idle`:`idle`,D=e=>E(e)===`error`?yn(u.error):null,O=async e=>{p(!0);try{for(let t of e)await l.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{p(!1),s()}},k={capabilityPending:c.isPending,onToggleCapability:C,onCommitReachableHost:(e,t)=>u.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:E,reachableHostErrorMessage:D};return I(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[I(`header`,{className:`flex items-start justify-between gap-4`,children:[I(`div`,{className:`space-y-1`,children:[V(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),V(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, distribute detection weight across detect-capable nodes, and choose the singleton cluster roles.`})]}),S&&V(W,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),V(kn,{roleValues:_,options:y,pending:d.isPending,lowFpsEnabled:x,fpsMinThreshold:b,onRoleChange:w,onLowFpsToggle:T})]}),I(`div`,{className:`space-y-3`,children:[I(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),V(En,{})]}),h.length===0?V(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):I(R,{children:[V(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:h.map(e=>V(Tn,{node:e,actions:k},e.id))}),V(`div`,{className:`hidden @3xl/clustertab:block`,children:V(Dn,{nodes:h,actions:k})})]})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),V(Ce,{nodes:g,pending:f,onCommitWeights:e=>void O(e)})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),g.length===0?V(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):V(`div`,{className:`space-y-2`,children:g.map(e=>V(Te,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}F();var jn=!1;function Mn({refreshToken:e}){let t=z(),{data:n}=y(void 0);L(()=>et(n??[]),[n]);let r=E({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return I(`div`,{className:`space-y-6`,children:[V(ht,{refreshToken:e}),V(An,{}),jn,I(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[I(`div`,{className:`min-w-0`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Recompute the optimal node for every assigned camera from current load + hardware affinity, and migrate the ones no longer on their best node. Pinned cameras never move.`})]}),I(`button`,{type:`button`,onClick:()=>r.mutate(void 0),disabled:r.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[V(Ae,{className:`h-3.5 w-3.5`}),r.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var Nn=[`pipeline-orchestrator`];function Pn({refreshToken:e}){return V(`div`,{className:`space-y-4 max-w-3xl`,children:V(nt,{nodeId:`hub`,addonIds:Nn,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer thresholds, and failover policy. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`})})}F();function Fn({refreshToken:e}){let t=z(),{data:n,isLoading:r}=me(),[i,a]=B(null),[o,s]=B(``),[c,l]=B(``),u=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},d=f({onSuccess:()=>{a(null),u()}}),p=se({onSuccess:u}),m=e=>{a(e.id),s(e.name),l(e.description??``)},h=()=>{a(null),s(``),l(``)},g=()=>{if(!i)return;let e=c.trim();d.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let _=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return V(`div`,{className:`space-y-6 max-w-4xl`,children:I(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[I(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),V(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle`,children:[_.length,` template`,_.length===1?``:`s`]})]}),_.length===0?I(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[V(Me,{className:`h-6 w-6 opacity-40`}),V(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):V(`ul`,{className:`divide-y divide-border`,children:_.map(e=>{let t=i===e.id;return V(`li`,{className:`px-4 py-3 text-xs`,children:I(`div`,{className:`flex items-start gap-3`,children:[V(`div`,{className:`flex-1 min-w-0`,children:t?I(`div`,{className:`space-y-2`,children:[V(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:o,onChange:e=>s(e.target.value),placeholder:`Template name`,autoFocus:!0}),V(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:c,onChange:e=>l(e.target.value),placeholder:`Description (optional)`})]}):I(R,{children:[V(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&V(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),I(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,I(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),V(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?I(R,{children:[I(`button`,{type:`button`,onClick:g,disabled:d.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[V(He,{className:`h-3 w-3`}),`Save`]}),I(`button`,{type:`button`,onClick:h,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[V(Je,{className:`h-3 w-3`}),`Cancel`]})]}):I(R,{children:[V(`button`,{type:`button`,onClick:()=>m(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:V(je,{className:`h-3 w-3`})}),V(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&p.mutate({id:e.id})},disabled:p.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:V(Xe,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}F();var In=`pipeline-analytics`;function Ln(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function Rn(){let e=z(),{data:t}=y(void 0),{data:n,isLoading:r}=le({addonId:In}),i=Ln(n),a=A({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),o=L(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return I(`div`,{className:`flex flex-col gap-6`,children:[I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),V(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),I(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?V(W,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):V(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:In,patch:{postProcessingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:o.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&V(W,{className:`h-4 w-4 animate-spin text-primary`})]})]}),I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),V(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),V(rt,{types:[`eventMedia`]})]})]})}var zn=`pipeline-orchestrator`,Bn=200;function Vn(){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(j,{addonId:zn,limit:Bn,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F();var Hn=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function Un({refreshToken:e}){let[t,n]=B(`assignments`);return I(`div`,{className:`flex flex-col h-full`,children:[I(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),V(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Per-camera assignments, the load balancer (live load + inference-device weights), cluster-wide settings, and the pipeline template library.`})]}),V(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Hn.map(e=>V(`button`,{type:`button`,onClick:()=>n(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),I(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&V(rn,{}),t===`balancer`&&V(Mn,{refreshToken:e}),t===`events`&&V(Rn,{}),t===`recording`&&V(it,{}),t===`settings`&&V(Pn,{refreshToken:e}),t===`templates`&&V(Fn,{refreshToken:e}),t===`logs`&&V(Vn,{})]})]})}function Wn(e){let t=[],n=[],{assignment:r,detection:i,decoder:a,broker:o}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),i!==null&&i.phase===`active`&&a!==null&&a.shm.framesWritten===0&&t.push({code:`decoder-black-hole`,severity:`error`,message:`Decoder on ${a.nodeId} has written 0 frames to the shared-memory plane while detection is active — the decode path is stalled`}),r.detectionNodeId===null&&i===null&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});for(let e of o?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function Gn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Kn(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function qn(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Jn(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var Yn={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function Xn(e){if(!Gn(e)||!Array.isArray(e.sections))return Yn;let t=ve(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)Jn(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Kn(n(`detectionFps`)),motionSources:qn(n(`motionSources`)),motionFps:Kn(n(`motionFps`)),motionCooldownMs:Kn(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function Zn(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...Zn(r.children,t+1));return n}function Qn(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function X({title:e,children:t}){return I(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[V(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),V(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return I(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[V(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),V(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&V($n,{})]})}function $n(){return V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var er={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return V(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${er[e]}`,children:t})}function $({children:e}){return V(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function tr({icon:e,label:t,nodeId:n,pinned:r,reason:i,overridden:a}){return I(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[V(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),V(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?V(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):I(R,{children:[V(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?I(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[V(st,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,i!==void 0&&i.length>0?i:`capacity`]}),a&&V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function nr({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:i}){let a=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,o=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return I(X,{title:`Where it runs`,children:[V(tr,{icon:G,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),V(tr,{icon:ze,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),V(tr,{icon:ke,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),V(tr,{icon:Ne,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),V(`div`,{className:`mt-1.5`,children:I(`select`,{value:a,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>i(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[V(`option`,{value:`auto`,children:`Auto (load balanced)`}),o.map(e=>I(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function rr(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function ir(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function ar(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function or({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:i}){let a=ir(t,n.detectionStreamProfile),o=ir(t,n.motionStreamProfile),s=n.motionSources.includes(`analyzer`);return I(X,{title:`Streams & motion`,children:[I(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,a!==void 0&&` · ${a.width}×${a.height} ${a.codec}`]}),V(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:ar(n.detectionFps)}),I(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.join(` + `):`none`,r===!1&&` · inactive`]}),s&&I(R,{children:[I(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,o!==void 0&&` · ${o.width}×${o.height} ${o.codec}`]}),I(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[ar(n.motionFps),i!==null&&` · live ${i.toFixed(1)}`]})]}),V(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),V(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?V($,{children:`No streams registered`}):e.map(e=>I(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[V(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,rr(e)]},e.camStreamId))})]})}function sr({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return I(X,{title:`Pipeline steps`,children:[e===void 0?V($,{children:`Resolving…`}):e.length===0?V($,{children:`No steps configured`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>V(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:I(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&V(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&I(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),V(`div`,{className:`mt-1`,children:I(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var cr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function lr({detection:e,live:t,detectionMode:r,modeOverridden:i}){if(e===null)return I(X,{title:`Detection runtime`,children:[V(Z,{label:`Mode`,overridden:i,children:r??`—`}),V($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,u=n(a),d=a===`active`&&o===0;return I(X,{title:`Detection runtime`,children:[I(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[I(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[V(C,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&V(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),V(Z,{label:`Mode`,overridden:i,children:r??`—`}),I(Z,{label:`FPS`,children:[V(`span`,{className:d?`text-danger font-semibold`:``,children:o.toFixed(1)}),I(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),I(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&I(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&I(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),I(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),I(Z,{label:`Provisioning`,children:[V(Q,{tone:cr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&I(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function ur({broker:e}){return e===null?V(X,{title:`Stream broker`,children:V($,{children:`Broker stage inactive or unreachable`})}):I(X,{title:`Stream broker`,children:[e.profiles.length===0?V($,{children:`No broker profiles`}):V(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return I(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),V(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),I(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),I(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),I(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),I(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[I(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),I(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function dr({decoder:e,detectionActive:t}){if(e===null)return V(X,{title:`Decoder`,children:V($,{children:`Decoder stage inactive or unreachable`})});let n=t&&e.shm.framesWritten===0;return I(X,{title:`Decoder`,children:[V(Z,{label:`Node`,children:e.nodeId}),V(Z,{label:`Sessions`,children:e.sessionCount}),I(Z,{label:`SHM frames`,children:[V(`span`,{className:n?`text-danger font-semibold`:``,children:e.shm.framesWritten}),V(`span`,{className:`text-foreground-subtle`,children:` written`})]}),I(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&I(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),I(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&V(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}F();var fr=`pipeline-orchestrator`,pr={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},mr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function hr({problems:e}){return V(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>I(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[V(Ye,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),V(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function gr({deviceId:e,name:t,online:n,status:r,live:i,onlineNodes:a}){let o=z(),{data:s}=te({addonId:fr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:c}=m({deviceId:e},{staleTime:3e4}),l=L(()=>Xn(s),[s]),d=L(()=>c===void 0?void 0:Zn(c.steps),[c]),f=L(()=>r===void 0?[]:Wn(r),[r]),p=()=>{o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},h=ie({onSuccess:p}),g=u({onSuccess:p}),_=t=>{t===`auto`?g.mutate({deviceId:e}):h.mutate({deviceId:e,agentNodeId:t})},v=r===void 0?`idle`:Qn(r),y=f.some(e=>e.severity===`error`),b=f.length>0,x=y?`border-danger/50`:b?`border-warning/40`:`border-border`;return I(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${x} bg-background overflow-hidden`,children:[I(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[V(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${y?`bg-danger`:pr[v]}`,title:y?`Error`:mr[v],"aria-label":y?`Error`:mr[v],role:`img`}),V(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&V(Q,{tone:`danger`,children:`offline`}),I(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[l.detectionMode!==null&&V(Q,{tone:l.detectionMode===`disabled`?`warning`:l.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:l.detectionMode===`disabled`?`detection off`:l.detectionMode}),r?.recording!=null&&(r.recording.active?I(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&I(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),f.length>0&&V(hr,{problems:f}),r===void 0?V(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):I(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[V(nr,{assignment:r.assignment,settings:l,onlineNodes:a,pinPending:h.isPending||g.isPending,onDetectionPinChange:_}),V(lr,{detection:r.detection,live:i,detectionMode:l.detectionMode,modeOverridden:l.overriddenKeys.has(`detectionMode`)}),V(sr,{steps:d,audioModelId:c?.audio?.modelId??null,audioEnabled:r.audio?.enabled??c?.audio?.enabled??null,audioMode:l.audioMode}),V(or,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:l,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null}),V(ur,{broker:r.broker}),V(dr,{decoder:r.decoder,detectionActive:r.detection?.phase===`active`})]})]})}F();var _r=5e3,vr=1e4,yr=5e3;function br(e){let t=z(),{data:n,isLoading:r}=Se(),{data:i,isLoading:a}=O({},{refetchInterval:_r}),{nodes:o}=v();H(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[s,c]=B(new Map);b(ye.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&c(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),H(()=>{if(s.size===0)return;let e=setInterval(()=>{c(e=>{let t=Date.now()-vr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},yr);return()=>clearInterval(e)},[s.size]);let l=L(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:L(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:l.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]),liveMetrics:s,onlineNodes:L(()=>(o??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[o]),isLoading:r||a}}F();function xr({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:i}=br(e),a=L(()=>[...t.map(e=>{let t=e.status===void 0?[]:Wn(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),o=L(()=>{let e=0,t=0;for(let r of a)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:a.length,active:e,issues:t}},[a,n]);return i&&t.length===0?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):V(`div`,{className:`h-full overflow-y-auto`,children:I(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[I(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground`,children:o.total}),` cameras`]}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success`,children:o.active}),` actively inferring`]}),I(`span`,{children:[V(`span`,{className:`font-semibold ${o.issues>0?`text-danger`:`text-foreground`}`,children:o.issues}),` `,`with issues`]}),V(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),a.map(({row:e})=>V(gr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}F();var Sr=`__cluster__`;function Cr(e){return e===`cameras`?`cameras`:`nodes`}function wr(){let[e,t]=Ve(),n=Cr(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[i,a]=B(0),[o,s]=B(!1);return H(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Sr},{replace:!0})},[n,e,t]),I(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[I(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[I(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[V(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:r},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),V(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),I(`button`,{type:`button`,onClick:()=>a(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[V(Pe,{className:`h-3.5 w-3.5`}),`Refresh`]})]}),n===`nodes`&&I(`button`,{type:`button`,onClick:()=>s(e=>!e),"aria-expanded":o,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[I(`span`,{children:[o?`Hide`:`Show`,` node list`]}),V(Be,{className:[`h-4 w-4 transition-transform`,o?`rotate-180`:``].join(` `)})]}),V(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?I(R,{children:[V(`aside`,{className:[o?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:V(pt,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),s(!1)},refreshToken:i})}),V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?V(Un,{refreshToken:i}):V(nn,{nodeId:r,refreshToken:i})})]}):V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:V(xr,{refreshToken:i})})})]})}export{wr as PipelinePage};
1
+ import{$r as e,Ci as t,Do as n,Ei as r,Ha as i,Ii as a,Ja as o,Ka as s,La as c,Mi as l,Ni as u,Oo as d,Pi as f,Qr as p,Si as m,T as h,Ti as g,Ua as _,Va as v,Vr as y,Wa as b,Xa as x,Za as S,_ as C,_i as w,ai as T,bi as E,ci as D,di as O,ei as k,ft as A,g as j,gi as M,ii as N,ji as ee,li as P,lt as te,mi as ne,ni as re,oi as ie,qa as ae,ri as oe,si as se,ti as ce,ut as le,vi as ue,wi as de,xi as fe,xo as pe,yi as me}from"./src-Bwet06Ih.js";import{I as he,K as ge,Q as F,S as I,T as _e,W as L,b as R,o as z,q as B,x as V,z as H}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{G as ve,K as ye,X as be}from"./src-GxiMH1Sc.js";import{c as xe,n as U,o as Se,r as Ce,s as we,t as Te}from"./NodeInferenceDevices-DlG9HB9Y.js";import{t as Ee}from"./download-NKkCvEeB.js";import{i as De}from"./AddLocationWizard-BsfRBmG0.js";import{n as Oe,r as ke,t as Ae}from"./zap-DWRzzBU1.js";import{t as je}from"./pencil-Ik1l3G_8.js";import{t as Me}from"./plus-B0OPxy2A.js";import{t as Ne}from"./radio-BtzRHQBo.js";import{t as Pe}from"./refresh-cw-D92Y26QW.js";import{t as Fe}from"./search-BUbY58eR.js";import{t as Ie}from"./server-BwAvkFi_.js";import{t as Le}from"./square-check-big-tgpBR4IT.js";import{t as Re}from"./square-Ckdv6ORu.js";import{E as ze,I as Be,J as Ve,L as He,M as Ue,N as We,P as Ge,S as W,T as Ke,W as qe,i as Je,j as G,o as Ye,s as Xe}from"./index-RegSp4ae.js";import{t as Ze}from"./AdminPage-BwmGKnRf.js";import{t as Qe}from"./useEventInvalidation-BslmDCfY.js";import{r as $e,t as et}from"./build-cluster-graph-BN5pfFK1.js";import{n as tt}from"./format-size-CO9d3C3-.js";import{t as nt}from"./NodeAddonsSettingsPanel-DY-AneF0.js";import{n as rt,t as it}from"./ClusterRecordingTab-ZjVaVby-.js";var at=qe(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),ot=qe(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),st=qe(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);F();function ct(e){return e}function lt(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function ut(e,t){return typeof e==`boolean`?e:ct(t)}function dt(e,t){return{pipeline:ut(lt(e,`detect`),t),audio:ut(lt(e,`audio`),t),ingest:ut(lt(e,`ingest`),t)}}function ft(e,t,n){let r=e?.find(e=>e.nodeId===t);return dt(r?.settings,n)}function pt({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:r}=y(void 0),{data:i}=M(void 0),{data:a}=ue(void 0),o=new Map;for(let e of i??[])o.set(e.agentNodeId,(o.get(e.agentNodeId)??0)+1);let s=r??[],c=s.filter(e=>e.isOnline).length,l=s.filter(e=>!e.isOnline).length;return I(`div`,{className:`flex flex-col h-full`,children:[I(`button`,{type:`button`,onClick:()=>t(Sr),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[V(Ke,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[V(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),V(`div`,{className:`flex-1 overflow-y-auto`,children:s.map(n=>{let r=e===n.id,i=o.get(n.id)??0,s=n.isHub?Ie:G,c=ft(a,n.id,n.isHub),l=n.isOnline?null:d($e(n.lastSeen));return I(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[V(s,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),I(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[I(`span`,{children:[n.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),i>0&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[V(Oe,{className:`h-2.5 w-2.5`}),i]})]}),!n.isOnline&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`text-destructive`,children:[`offline`,l===null?``:` · ${l}`]})]})]}),I(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[V(pe,{variant:c.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:c.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),V(pe,{variant:c.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:c.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),I(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[I(`span`,{children:[c,` online`]}),l>0&&I(`span`,{className:`text-destructive`,children:[l,` offline`]})]})]})}function mt({nodeId:e,refreshToken:t}){let{data:n}=y(void 0),r=n?.find(t=>t.id===e),a=i(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?I(`div`,{className:`px-6 py-4 border-b border-border`,children:[I(`div`,{className:`flex items-center gap-2 mb-1`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[V(`span`,{children:r.cpuModel??`CPU`}),V(`span`,{children:`•`}),I(`span`,{children:[r.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),V(`span`,{children:`•`}),I(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),V(`span`,{children:`•`}),I(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&I(R,{children:[V(`span`,{children:`•`}),V(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):V(`div`,{className:`px-6 py-4 border-b border-border`,children:I(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function ht({refreshToken:e,nodeId:t}){let[n,r]=B(new Map),{nodes:i}=v();b(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:a}=P(void 0),o=L(()=>{let e=new Map;for(let t of a??[])e.set(t.nodeId,t.deviceCount);return e},[a]),s=L(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),c=L(()=>{let e=new Map;for(let t of i)e.set(t.id,t.shortName);return e},[i]),l=L(()=>{let e=0,t=0,n=0,r=0,a=0;for(let i of s.values())e+=i.attachedCameras,t+=i.activeCameras,n+=i.totalFps,r+=i.totalInferenceWeighted,a+=i.queueDepth;let o=e>0?r/e:0;return{totalAgents:i.length,onlineAgents:i.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:o,queueDepth:a,totalFps:n}},[s,i]);if(t){let e=s.get(t);return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[V(K,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),V(K,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),V(K,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),V(K,{label:`Queue`,value:e?String(e.queueDepth):`—`}),V(K,{label:`Audio`,value:String(o.get(t)??`—`)})]})]})}let u=[...s.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[V(K,{label:`Total agents`,value:`${l.onlineAgents}/${l.totalAgents}`}),V(K,{label:`Active / Attached`,value:`${l.activeCameras}/${l.attachedCameras}`}),V(K,{label:`Total FPS`,value:l.totalFps.toFixed(1)}),V(K,{label:`Avg inference ms`,value:l.avgInferenceTimeMs.toFixed(0)}),V(K,{label:`Queue depth`,value:String(l.queueDepth)})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[480px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),V(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),V(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),V(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),V(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),V(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),I(`tbody`,{children:[u.map(([e,t])=>I(`tr`,{className:`border-t border-border`,children:[V(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:c.get(e)??e}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:o.get(e)??`—`})]},e)),u.length===0&&V(`tr`,{children:V(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function K({label:e,value:t}){return I(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[V(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),V(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}F();var gt={active:!1,pinned:!1,nodeId:null,reason:``},_t=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],vt={pipeline:G,decoder:ze,audio:ke},yt={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function bt({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let r=z(),[i,a]=B(null),[o,s]=B(null),[c,d]=B(new Map);Qe([`pipelineOrchestrator`,`getPipelineAssignments`],_t),Qe([`pipelineOrchestrator`,`getAudioAssignments`],_t),Qe([`pipelineOrchestrator`,`getCameraStatuses`],_t);let{data:f}=M(void 0),{data:p}=D(void 0),{data:m}=O({},{enabled:e===`agent`}),{nodes:g}=v(),{data:_}=Se();b(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&d(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),H(()=>{if(c.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[c.size]);let y=L(()=>{let e=new Map;for(let t of _??[])e.set(t.id,t.name);return e},[_]),x=L(()=>{if(e===`agent`){let e=[];for(let n of m??[]){let r=n.assignment,i=(e,n,r)=>({active:e!==null&&e===t,pinned:n,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:n.deviceId,deviceName:y.get(n.deviceId)??`Device ${n.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:y.get(e)??`Device ${e}`,pipeline:gt,decoder:gt,audio:gt};return n.set(e,r),r};for(let i of f??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let e of p??[]){let t=r(e.deviceId);n.set(e.deviceId,{...t,audio:{active:!0,pinned:e.pinned,nodeId:e.nodeId,reason:`capacity`}})}let i=[...n.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[f,p,m,y,e,t]),S=L(()=>(g??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[g]),C=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},w=ie({onSuccess:C}),E=u({onSuccess:C}),k=T({onSuccess:C}),A=l({onSuccess:C}),j=(e,t,n)=>{t===`pipeline`?w.mutate({deviceId:e,agentNodeId:n}):k.mutate({deviceId:e,nodeId:n}),a(null)},N=(e,t)=>{t===`pipeline`?E.mutate({deviceId:e}):A.mutate({deviceId:e}),a(null)};return V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&V(`th`,{className:`w-10`}),V(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?I(R,{children:[V(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),V(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):I(R,{children:[V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),V(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),I(`tbody`,{children:[x.map(t=>{let r=c.get(t.deviceId),l=o===t.deviceId;return I(_e.Fragment,{children:[I(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&V(`td`,{className:`px-2 py-2 align-middle`,children:V(`button`,{type:`button`,onClick:()=>s(l?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":l?`Collapse broker details`:`Expand broker details`,children:V(l?Be:Ge,{className:`h-3.5 w-3.5`})})}),I(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[V(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?I(R,{children:[V(`td`,{className:`px-3 py-2 align-middle`,children:V(St,{state:t.pipeline,onlineNodes:S,pending:w.isPending||E.isPending,onChange:e=>{e===`auto`?N(t.deviceId,`pipeline`):j(t.deviceId,`pipeline`,e)}})}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(Ct,{state:t.pipeline,deviceId:t.deviceId})})]}):I(R,{children:[V(Tt,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:S,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`pipeline`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>a(null),onMove:e=>j(t.deviceId,`pipeline`,e),onUnpin:()=>N(t.deviceId,`pipeline`)}),V(Tt,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:S,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),V(Tt,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:S,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`audio`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>a(null),onMove:e=>j(t.deviceId,`audio`,e),onUnpin:()=>N(t.deviceId,`audio`)})]}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(kt,{snap:r})})]}),l&&!n&&I(`tr`,{className:`bg-surface/50`,children:[V(`td`,{}),I(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&V(xt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),V(h,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})]})]})]},t.deviceId)}),x.length===0&&V(`tr`,{children:V(`td`,{colSpan:n?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function xt({deviceId:e,nodeId:t}){let n=z(),{data:r}=ne({nodeId:t}),{data:i}=w({deviceId:e}),a=ee({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),o=r?.devices??[],s=i?.deviceKey??`auto`,c=s!==`auto`&&!o.some(e=>e.key===s);return I(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[V(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),I(`select`,{value:s,disabled:a.isPending,"aria-label":`Inference device pin`,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[V(`option`,{value:`auto`,children:`Auto (balanced)`}),c&&I(`option`,{value:s,children:[`Pin → `,s,` (not on this node)`]}),o.map(e=>I(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),a.isPending&&V(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function St({state:e,onlineNodes:t,pending:n,onChange:r}){let i=e.pinned&&e.nodeId?e.nodeId:`auto`,a=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return I(`select`,{value:i,disabled:n,"aria-label":`Pipeline placement pin`,onChange:e=>r(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[V(`option`,{value:`auto`,children:`Auto`}),a.map(e=>I(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function Ct({state:e,deviceId:t}){if(!e.active||!e.nodeId)return V(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let n=e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`;return I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,title:e.nodeId,children:e.nodeId}),V(`span`,{className:`truncate ${e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:n,children:n}),V(wt,{deviceId:t,nodeId:e.nodeId})]})}function wt({deviceId:e,nodeId:t}){let n=z(),{data:r}=w({deviceId:e},{refetchOnMount:`always`}),{data:i}=ne({nodeId:t},{refetchOnMount:`always`}),a=ee({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||i===void 0)return V(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let o=i.devices??[],s=o.filter(e=>e.enabled),c=r.deviceKey??`auto`,l=c!==`auto`&&!s.some(e=>e.key===c),u=o.find(e=>e.key===c);return I(`select`,{value:c,disabled:a.isPending,"aria-label":`Inference device pin`,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value}),className:`mt-0.5 w-full min-w-0 rounded border border-border bg-background px-1 py-0.5 text-[10px] text-foreground disabled:opacity-50`,children:[V(`option`,{value:`auto`,children:`Auto (balanced)`}),l&&I(`option`,{value:c,children:[u?`${U(u).label} (${c})`:c,` (not enabled)`]}),s.map(e=>I(`option`,{value:e.key,children:[U(e).label,` · `,e.format]},e.key))]})}function Tt({role:e,state:t,mode:n,onlineNodes:r,readOnly:i=!1,isMenuOpen:a,onToggleMenu:o,onCloseMenu:s,onMove:c,onUnpin:l}){let u=vt[e],d=r.filter(e=>e.id!==(t.nodeId??``)),f=!i&&(t.active||n===`cluster`)&&(d.length>0||t.pinned);return I(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[I(`div`,{className:`flex items-center gap-2 min-w-0`,children:[V(n===`agent`?Et:Dt,{state:t,Icon:u}),V(`div`,{className:`ml-auto shrink-0`,children:f&&V(`button`,{type:`button`,onClick:o,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${yt[e]} actions`,children:V(at,{className:`h-3 w-3 text-foreground-subtle`})})})]}),a&&f&&V(At,{title:yt[e],targets:d,pinned:t.pinned,onMove:c,onUnpin:l,onClose:s})]})}function Et({state:e,Icon:t}){return I(`div`,{className:`flex items-center gap-1.5`,children:[V(e.active?Le:Re,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),V(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&V(st,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Dt({state:e,Icon:t}){return!e.active||!e.nodeId?I(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[V(t,{className:`h-3 w-3`}),V(`span`,{className:`text-[10px] italic`,children:`—`})]}):I(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[V(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),V(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?I(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[V(st,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Ot=`min-h-[3.25rem]`;function kt({snap:e}){if(!e)return V(`div`,{className:`flex items-center ${Ot}`,children:V(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:r,avgInferenceTimeMs:i,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=n(t);return I(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Ot}`,children:[I(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[V(C,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),V(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:r.toFixed(1)}),I(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:i.toFixed(0)}),V(`span`,{children:` ms`}),a>0&&I(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),I(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,V(`span`,{className:`text-foreground`,children:s})]})]})}function At({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=ge(null);return H(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),I(`div`,{ref:o,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[V(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&V(`div`,{className:`py-1`,children:t.map(e=>I(`button`,{type:`button`,onClick:()=>r(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),n&&I(`button`,{type:`button`,onClick:i,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,e.toLowerCase()]}),t.length===0&&!n&&V(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function jt({nodeId:e,refreshToken:t}){return I(`div`,{className:`space-y-6`,children:[V(ht,{refreshToken:t,nodeId:e}),I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),V(bt,{mode:`agent`,nodeId:e,compact:!0})]})}F();function Mt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Nt({nodeId:e,refreshToken:t}){let n=z(),r=oe({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:o}=N({nodeId:e}),s=i(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??o??null,c=s===null;Qe([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:l}=a({nodeId:e}),{values:u}=_(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),d=L(()=>u.filter(e=>e.metrics.phase===`active`).length,[u]),f=t=>{let n=l??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||r.mutate({nodeId:e,engine:t,force:n.length>0})};return I(`div`,{className:`space-y-6`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(s??[]).length,` engine(s) resident in RAM. `,(l??[]).length,` `,`camera(s) attached, `,d,` actively dispatching frames. Refreshes every 5s.`]})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[640px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),V(`th`,{className:`text-left px-3 py-2`,children:`Models`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),V(`th`,{className:`w-20`})]})}),I(`tbody`,{children:[c&&V(`tr`,{children:V(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!c&&(s??[]).map(e=>{let t=e.kind===`warm-override`,n=e.kind===`device-pool`;return I(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:n?`bg-primary/[0.05]`:``}`,children:[V(`td`,{className:`px-3 py-2`,children:I(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:n?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[V(t?ot:n?xe:G,{className:`h-3 w-3`}),t?`warm`:n?`pool`:`runtime`]})}),V(`td`,{className:`px-3 py-2`,children:I(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[V(Ae,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),V(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?V(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>V(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),V(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),V(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?V(`span`,{className:`text-foreground-subtle`,children:Mt(e.idleMs,e.idleTtlMs)}):V(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(l??[]).length}),V(`td`,{className:`px-3 py-2 text-right`,children:n?V(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):I(`button`,{type:`button`,disabled:r.isPending,onClick:()=>f(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[V(Xe,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!c&&(s??[]).length===0&&V(`tr`,{children:V(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[V(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,V(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,V(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),r.isError&&I(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,r.error instanceof Error?r.error.message:`unknown`]})]})}F();var Pt=new Set(be);function Ft(e){return Pt.has(e)}function It(e,t,n){return`${e}/${t}/${n}`}function Lt(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function Rt(e){return{coreml:`Apple Neural Engine / GPU — .mlpackage`,openvino:`Intel CPU / GPU / NPU — .xml`,onnx:`CPU, CUDA, Node.js — .onnx`}[e.format]??`.${e.format}`}function q(e){return e.format}function zt(e,t){let n=0,r=0,i=0;for(let a of e)for(let e of a.addons)for(let a of e.models){let e=a.formats[t];e&&(n++,e.downloaded&&(r++,i+=e.sizeMB))}return{total:n,downloaded:r,downloadedSizeMB:i}}function Bt({addonId:e,model:t,format:n,isActive:r,progress:i,errorMsg:a,onDownload:o,onDelete:s}){let c=t.formats[n];return c?I(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors`,children:[V(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),I(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&I(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[V(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:V(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),I(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),V(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:tt(c.sizeMB)}),a&&I(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[V(We,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?I(`button`,{onClick:s,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[r?V(W,{className:`h-3 w-3 animate-spin`}):V(Xe,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):I(`button`,{onClick:o,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[r?V(W,{className:`h-3 w-3 animate-spin`}):V(Ee,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function Vt({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=B(!1);return I(`div`,{className:`relative`,children:[I(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[V(G,{className:`h-4 w-4 text-primary shrink-0`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:Lt(n)}),q(n)===q(t)&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:Rt(n)})]}),V(Be,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&V(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let i=q(e)===q(n),o=q(e)===q(t);return I(`button`,{type:`button`,onClick:()=>{r(e),a(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${i?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[V(G,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),I(`div`,{className:`flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:Lt(e)}),o&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:Rt(e)})]}),i&&V(Ue,{className:`h-4 w-4 text-primary shrink-0`})]},q(e))})})]})}function Ht({embedded:t=!1,nodeId:n}={}){let r=z(),i=n??`hub`,[a,o]=B(null),[s,c]=B(new Set),[l,u]=B(new Map),[d,f]=B(new Map),[m,h]=B(``),{data:g=[]}=k({nodeId:i}),_=g.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:v}=re({nodeId:i}),y=v,{data:x,isLoading:S}=ce({nodeId:i}),C=e(),w=p();b(`model.download.progress`,e=>{let t=e.data,n=typeof t.modelId==`string`?t.modelId:void 0,i=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;n===void 0||i===void 0||(u(e=>{let t=new Map(e);return i===100||i===-1?t.delete(n):t.set(n,{modelId:n,progress:i,totalMB:a}),t}),i===100&&r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let T=y??{runtime:`node`,backend:`cpu`,format:`onnx`},E=_.find(e=>e.format===a)??T,D=E.format,O=x?.slots??[],A=O.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(e=>e.formats[D]!==void 0)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),j=zt(A,D),M=he(async(e,t,n)=>{if(!Ft(n))return;let a=It(e,t,n);c(e=>new Set([...e,a])),f(e=>{let t=new Map(e);return t.delete(a),t});try{await C.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){f(t=>new Map([...t,[a,e instanceof Error?e.message:`Download failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[C,r,i]),N=he(async(e,t,n)=>{if(!Ft(n))return;let a=It(e,t,n);c(e=>new Set([...e,a])),f(e=>{let t=new Map(e);return t.delete(a),t});try{await w.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){f(t=>new Map([...t,[a,e instanceof Error?e.message:`Delete failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[w,r,i]),ee=he(e=>{o(e.format)},[]),P=m.trim()?A.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(m.toLowerCase())||t.id.toLowerCase().includes(m.toLowerCase())||e.name.toLowerCase().includes(m.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):A,te=I(R,{children:[S&&V(`div`,{className:`flex items-center justify-center py-16`,children:V(W,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!S&&O.length===0&&I(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[V(De,{className:`h-8 w-8 mb-3 opacity-30`}),V(`span`,{className:`text-sm`,children:`No pipeline steps available`}),V(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!S&&O.length>0&&I(R,{children:[V(Vt,{engines:_,activeEngine:T,viewEngine:E,onSelect:ee}),I(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground tabular-nums`,children:j.total}),V(`span`,{className:`ml-1`,children:`compatible models`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success tabular-nums`,children:j.downloaded}),V(`span`,{className:`ml-1`,children:`downloaded`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{className:`tabular-nums`,children:[tt(j.downloadedSizeMB),V(`span`,{className:`ml-1`,children:`on disk`})]})]}),j.total>5&&I(`div`,{className:`relative`,children:[V(Fe,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),V(`input`,{type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:`Search models...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary`})]}),P.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+t.models.filter(e=>e.formats[D]?.downloaded).length,0);return I(`div`,{children:[I(`div`,{className:`flex items-center gap-2 mb-2`,children:[V(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),V(`div`,{className:`flex-1 h-px bg-border`}),I(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=It(e.id,t.id,D);return V(Bt,{addonId:e.id,model:t,format:D,isActive:s.has(n),progress:l.get(t.id),errorMsg:d.get(n),onDownload:()=>M(e.id,t.id,D),onDelete:()=>N(e.id,t.id,D)},`${e.id}/${t.id}`)}))})]},e.id)}),P.length===0&&V(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:m.trim()?I(R,{children:[`No models matching “`,m,`”`]}):I(R,{children:[`No models available for `,Lt(E),` format`]})})]})]});return t?V(`div`,{className:`space-y-4`,children:te}):V(Ze,{children:te})}function Ut({nodeId:e,refreshToken:t}){return V(Ht,{embedded:!0,nodeId:e})}var Wt=`pipeline-runner`,Gt=200;function Kt({nodeId:e}){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(j,{agentId:e,addonId:Wt,limit:Gt,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F(),F();function qt({nodeId:e,title:t}){let{data:r}=Se(),{data:i}=M(void 0),a=L(()=>{let e=new Map;for(let t of r??[])e.set(t.id,t.name);return e},[r]),o=L(()=>{if(!e)return null;let t=new Set;for(let n of i??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,i]),[s,c]=B(new Map);b(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||c(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),H(()=>{if(s.size===0)return;let e=setInterval(()=>{c(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[s.size]);let l=L(()=>{let e=[];for(let t of s.values())o&&!o.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[s,o]);return l.length===0?I(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):I(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[I(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[V(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),V(`span`,{className:`text-[10px] text-foreground-subtle`,children:l.length})]}),V(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>{let t=a.get(e.deviceId)??`#${e.deviceId}`,r=n(e.metrics.phase);return I(`div`,{title:`${t} · ${r.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${r.badgeClass}`,children:[V(C,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),V(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),V(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),V(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}F();function J(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Jt(e){if(!e)return null;let t=e.modelId!==void 0&&e.modelId!==``?e.modelId:void 0,n=e.settings&&Object.keys(e.settings).length>0?e.settings:void 0;return t===void 0&&n===void 0?null:{...t===void 0?{}:{modelId:t},...n===void 0?{}:{settings:n}}}function Yt({nodeId:e,refreshToken:t}){let n=z(),[r,i]=B(null),[a,c]=B(null),[l,u]=B(``),[d,f]=B(null),p=ne({nodeId:e},{refetchOnMount:`always`}),m=ce({nodeId:e},{refetchOnMount:`always`}),h=p.data?.devices??[],_=g({onSuccess:()=>{n.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),v=L(()=>m.data?x(m.data):[],[m.data]),y=L(()=>h.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:U(t).label})),[h,e]),b=e=>h.find(t=>t.key===e)??null,C=L(()=>h.filter(e=>e.enabled),[h]),w=C.length>=2,T=(e,t)=>{let n=J(m.data??null,e),r=t?.format;return n?.models.some(e=>r!==void 0&&!!e.formats[r])??!1},E=e=>{let t=b(e);return t?U(t).label:e},D=(e,t)=>C.filter(n=>n.key!==t&&T(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,O=e=>{let t=J(m.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},k=(e,t)=>{let n=J(m.data??null,e),r=t?.format;if(!(!n||r===void 0))return(n.slot===`detector`?t?.defaultModelId:void 0)??s(n,r)},A=(e,t)=>{let n=O(e),r=n.kind===`gate`?n.effectiveOn:!1,i=J(m.data??null,e),a=t.deviceKey===void 0?null:b(t.deviceKey),o=a?.format,s=i?.models.some(e=>o!==void 0&&!!e.formats[o])??!1,c=a?.steps?.[e];if(!s){if(!r)return{kind:`na`};let n=c?.jumpDeviceKey,i=n!==void 0&&C.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:D(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:E(i)}}return{kind:`enabled`,modelId:c?.modelId??k(e,a)??`Auto`,...c?.jumpDeviceKey!==void 0&&C.some(e=>e.key===c.jumpDeviceKey)?{jumpTo:E(c.jumpDeviceKey)}:{}}},j=r&&m.data?J(m.data,r.addonId):null,M=r?b(r.deviceKey):null,N=M?.format??`coreml`,ee=r?k(r.addonId,M):void 0,P=()=>{i(null),c(null),u(``)},te=(e,t)=>{if(t.deviceKey===void 0)return;let n=b(t.deviceKey)?.steps?.[e];i({addonId:e,deviceKey:t.deviceKey}),c({enabled:!0,...n?.modelId===void 0?{}:{modelId:n.modelId},settings:n?.settings??{}}),u(n?.jumpDeviceKey??``)},re=()=>{if(!r)return;let t=Jt(a),n=l!==``&&l!==r.deviceKey?l:void 0,i=t||n!==void 0?{...t,...n===void 0?{}:{jumpDeviceKey:n}}:null,o={};for(let e of h){if(!e.enabled&&e.key!==r.deviceKey)continue;let t={...e.steps};e.key===r.deviceKey&&(i?t[r.addonId]=i:delete t[r.addonId]);let n=Object.keys(t).length>0;o[e.key]={enabled:!0,weight:Math.max(1,e.weight),...e.maxSessions!=null&&e.maxSessions>0?{maxSessions:e.maxSessions}:{},...n?{steps:t}:{}}}_.mutate({agentNodeId:e,inferenceDevices:o},{onSuccess:P})};if(p.isLoading||m.isLoading)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(h.length===0)return V(`div`,{className:`rounded-md border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`});if(!m.data)return V(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ie=r!==null&&j!==null&&M!==null;return I(`div`,{className:`relative h-full w-full space-y-3`,children:[I(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[`Each column is one of this node's inference accelerators. A cell shows the`,` `,V(`span`,{className:`font-medium text-foreground`,children:`base model`}),` every camera landing on that accelerator runs; click to change it. Whether a camera runs a step is set per-camera on that camera's Detection pipeline tab — there is no gate here.`]}),V(`div`,{className:ie?`md:pr-[360px]`:``,children:v.length>0?V(ae,{tree:v,agents:y,gateFor:O,getCellState:A,onCellClick:te,selectedCell:r?{addonId:r.addonId,agentNodeId:e,deviceKey:r.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:d,onFallbackNodeChange:f,hideGate:!0}):V(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),V(S,{open:ie,onClose:P,title:j?.name??``,subtitle:r&&M?`${e} · ${U(M).label} · ${M.format}`:``,footer:I(R,{children:[V(`div`,{className:`flex-1`}),V(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:P,children:`Cancel`}),V(`button`,{type:`button`,disabled:!r||!a||_.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:re,children:_.isPending?`Saving…`:`Save`})]}),children:j&&r&&a?I(`div`,{className:`space-y-3`,children:[w&&I(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[V(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),I(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:l,onChange:e=>u(e.target.value),children:[V(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),C.filter(e=>e.key!==r.deviceKey).map(e=>I(`option`,{value:e.key,children:[U(e).label,` · `,e.format]},e.key))]}),V(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),V(o,{mode:`agent`,addon:j,agentDefault:a,agentNodeId:e,engineFormat:N,effectiveModelId:ee,onChangeAgentConfig:c})]}):V(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}F();var Xt=[`pipeline-orchestrator`],Zt=[`decoder`],Qt=!1;function $t({nodeId:e,refreshToken:t}){let n=c(),[r,i]=B(null),[a,o]=B(null),s=(y(void 0).data??[]).find(t=>t.id===e),l=s?.name??e,u=s?.isOnline??!1,d=fe({onSuccess:e=>{o(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${l} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(o(null),d.mutate({agentNodeId:e}))};return I(`div`,{className:`relative h-full w-full space-y-3`,children:[I(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[a&&V(`span`,{className:`text-emerald-400`,children:a}),d.isError&&V(`span`,{className:`text-red-400`,children:d.error instanceof Error?d.error.message:`Reset failed`}),V(`button`,{type:`button`,onClick:()=>{f()},disabled:d.isPending,className:`rounded border border-amber-500/40 bg-surface px-2 py-0.5 text-amber-300 hover:bg-surface-hover disabled:opacity-50`,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:d.isPending?`Resetting…`:`Reset to default`})]}),V(qt,{nodeId:e}),V(nt,{nodeId:e,addonIds:Xt,level:`global`,sectionIds:Zt}),Qt,Qt,I(`div`,{children:[V(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),V(Te,{nodeId:e,nodeName:l,isOnline:u})]}),I(`div`,{children:[V(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),V(Yt,{nodeId:e,refreshToken:t})]})]})}var en=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],tn=`decoder-nodeav`;function nn({nodeId:e,refreshToken:t}){let{data:n}=y(void 0),r=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??tn,i=[...en,r];return I(`div`,{className:`flex flex-col h-full`,children:[V(mt,{nodeId:e,refreshToken:t}),V(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:V(nt,{nodeId:e,addonIds:i,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:V(jt,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:V($t,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:V(Nt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:V(Ut,{nodeId:e,refreshToken:t})},{id:`logs`,label:`Logs`,order:300,content:V(Kt,{nodeId:e})}]})})]})}function rn(){return I(`div`,{className:`space-y-6`,children:[V(qt,{title:`Cluster cameras`}),I(`div`,{className:`min-w-0`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Use the Auto | Pin control to pin a camera to a node, the inference-device select to pin it to an accelerator, or the kebab to move a role; expand the chevron for the per-camera broker drill-down. Cluster load, inference-device weights, and Rebalance live on the Balancer tab.`})]}),V(bt,{mode:`cluster`})]})}var an=`pipeline-orchestrator`,on=`recorder`,sn=`recordingNodeId`,cn=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],ln=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function un(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function dn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function fn(e,t,n){let r=un(e,t);return typeof r==`string`&&r.length>0?r:n}function pn(e,t,n){let r=un(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function mn(e,t){let n=dn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function hn(e,t){let n=dn(e,t);return typeof n==`string`&&n.length>0?n:null}function gn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function _n(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function vn(e,t){switch(t){case`detect`:return e.pipeline}}function yn(e){return e instanceof Error?e.message:`Failed to save`}function bn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function xn({capability:e,label:t,hint:n,nodeId:r,active:i,pending:a,layout:o,onToggle:s}){let c=i?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,l=o===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,u=i?He:we;return I(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":`${t} capability for ${r}`,title:`${t} — ${n}`,disabled:a,onClick:()=>s(e,!i),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${c} ${l}`,children:[V(u,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),V(`span`,{children:t})]})}function Sn({node:e,emphasis:t=!1}){let n=e.isHub?Ie:G;return I(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[V(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),V(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),I(`div`,{className:`min-w-0`,children:[I(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[V(`span`,{className:`truncate`,children:e.name}),e.isHub&&V(pe,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&V(pe,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),V(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}F();function Cn({nodeId:e,value:t,detectedHosts:n,status:r,errorMessage:i,onCommit:a}){let[o,s]=B(t??``);H(()=>{s(t??``)},[t]);let c=n[0],l=c===void 0?`auto-detect`:`auto: ${c}`,u=r===`pending`,d=o.trim(),f=d!==(t??``),p=f&&!u,m=()=>{p&&a(e,d.length>0?d:null)};return I(`div`,{className:`flex items-center gap-1.5`,children:[V(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:l,value:o,disabled:u,onChange:e=>s(e.target.value),onBlur:m,onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&s(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),I(`button`,{type:`button`,onClick:m,disabled:!p,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[u?V(W,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):V(He,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!f&&!u&&r===`success`&&V(He,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),r===`error`&&V(`span`,{title:i??`Failed to save reachable host`,children:V(We,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":i??`Failed to save reachable host`,role:`img`})})]})}function wn({label:e,children:t}){return I(`div`,{className:`flex items-center justify-between gap-3`,children:[V(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function Tn({node:e,actions:t}){return I(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[V(Sn,{node:e,emphasis:!0}),V(`div`,{className:`grid grid-cols-2 gap-2`,children:ln.map(n=>V(xn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:vn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),V(`div`,{className:`space-y-3 border-t border-border pt-3`,children:V(wn,{label:`Reachable host`,children:V(Cn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function En(){return I(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function Dn({nodes:e,actions:t}){return V(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:I(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[V(`thead`,{children:I(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),ln.map(e=>V(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),V(`tbody`,{children:e.map(e=>I(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[V(`td`,{className:`px-4 py-3 align-middle`,children:V(Sn,{node:e})}),ln.map(n=>V(`td`,{className:`px-3 py-3 text-center align-middle`,children:V(xn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:vn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),V(`td`,{className:`px-4 py-3 align-middle`,children:V(Cn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})]},e.id))})]})})}function On({role:e,value:t,options:n,pending:r,onChange:i}){return I(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[V(`span`,{className:`text-xs font-semibold text-foreground`,children:gn(e)}),V(`select`,{value:t,disabled:r,onChange:t=>i(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:n.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),V(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:_n(e)})]})}function kn({roleValues:e,options:t,pending:n,lowFpsEnabled:r,fpsMinThreshold:i,onRoleChange:a,onLowFpsToggle:o}){return I(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[cn.map(r=>V(On,{role:r,value:e[r],options:t,pending:n,onChange:a},r)),I(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[V(`input`,{type:`checkbox`,checked:r,disabled:n,onChange:e=>o(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),I(`span`,{className:`flex flex-col gap-0.5`,children:[V(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),I(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,r?`${i} fps`:`disabled`]})]})]})]})}F();function An(){let e=z(),{nodes:n}=v(),i=ue(void 0),a=le({addonId:an}),o=le({addonId:on}),s=()=>bn(e),c=t({onSuccess:s}),l=de(),u=r({onSuccess:s}),d=A({onSuccess:s}),[f,p]=B(!1),m=L(()=>{let e=new Map;for(let t of i.data??[])e.set(t.nodeId,t.settings);return e},[i.data]),h=L(()=>n.map(e=>{let t=m.get(e.id),n=dt(t,e.isHub),r=mn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:mn(t,`maxCameras`),reachableHost:hn(t,`reachableHost`),detectedHosts:e.localIps}}),[n,m]),g=h.filter(e=>e.effective.pipeline),_={ingestNode:fn(a.data,`ingestNode`,`hub`),recordingNode:fn(o.data,sn,`hub`),audioNode:fn(a.data,`audioNode`,`hub`),motionNode:fn(a.data,`motionNode`,`hub`)},y=L(()=>{let e=n.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...cn.map(e=>_[e]),...e])].filter(e=>e.length>0)},[n,_]),b=pn(a.data,`fpsMinThreshold`,0),x=b>0,S=i.isLoading||a.isLoading||o.isLoading,C=(e,t,n)=>{c.mutate({agentNodeId:e,[t]:n})},w=(e,t)=>{if(e===`recordingNode`){d.mutate({addonId:on,patch:{[sn]:t}});return}d.mutate({addonId:an,patch:{[e]:t}})},T=e=>{d.mutate({addonId:an,patch:{fpsMinThreshold:e?Math.max(1,b):0}})},E=e=>u.variables?.agentNodeId===e?u.isPending?`pending`:u.isError?`error`:u.isSuccess?`success`:`idle`:`idle`,D=e=>E(e)===`error`?yn(u.error):null,O=async e=>{p(!0);try{for(let t of e)await l.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{p(!1),s()}},k={capabilityPending:c.isPending,onToggleCapability:C,onCommitReachableHost:(e,t)=>u.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:E,reachableHostErrorMessage:D};return I(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[I(`header`,{className:`flex items-start justify-between gap-4`,children:[I(`div`,{className:`space-y-1`,children:[V(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),V(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, distribute detection weight across detect-capable nodes, and choose the singleton cluster roles.`})]}),S&&V(W,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),V(kn,{roleValues:_,options:y,pending:d.isPending,lowFpsEnabled:x,fpsMinThreshold:b,onRoleChange:w,onLowFpsToggle:T})]}),I(`div`,{className:`space-y-3`,children:[I(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),V(En,{})]}),h.length===0?V(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):I(R,{children:[V(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:h.map(e=>V(Tn,{node:e,actions:k},e.id))}),V(`div`,{className:`hidden @3xl/clustertab:block`,children:V(Dn,{nodes:h,actions:k})})]})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),V(Ce,{nodes:g,pending:f,onCommitWeights:e=>void O(e)})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),g.length===0?V(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):V(`div`,{className:`space-y-2`,children:g.map(e=>V(Te,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}F();var jn=!1;function Mn({refreshToken:e}){let t=z(),{data:n}=y(void 0);L(()=>et(n??[]),[n]);let r=E({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return I(`div`,{className:`space-y-6`,children:[V(ht,{refreshToken:e}),V(An,{}),jn,I(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[I(`div`,{className:`min-w-0`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Recompute the optimal node for every assigned camera from current load + hardware affinity, and migrate the ones no longer on their best node. Pinned cameras never move.`})]}),I(`button`,{type:`button`,onClick:()=>r.mutate(void 0),disabled:r.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[V(Ae,{className:`h-3.5 w-3.5`}),r.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var Nn=[`pipeline-orchestrator`];function Pn({refreshToken:e}){return V(`div`,{className:`space-y-4 max-w-3xl`,children:V(nt,{nodeId:`hub`,addonIds:Nn,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer thresholds, and failover policy. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`})})}F();function Fn({refreshToken:e}){let t=z(),{data:n,isLoading:r}=me(),[i,a]=B(null),[o,s]=B(``),[c,l]=B(``),u=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},d=f({onSuccess:()=>{a(null),u()}}),p=se({onSuccess:u}),m=e=>{a(e.id),s(e.name),l(e.description??``)},h=()=>{a(null),s(``),l(``)},g=()=>{if(!i)return;let e=c.trim();d.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let _=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return V(`div`,{className:`space-y-6 max-w-4xl`,children:I(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[I(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),V(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle`,children:[_.length,` template`,_.length===1?``:`s`]})]}),_.length===0?I(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[V(Me,{className:`h-6 w-6 opacity-40`}),V(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):V(`ul`,{className:`divide-y divide-border`,children:_.map(e=>{let t=i===e.id;return V(`li`,{className:`px-4 py-3 text-xs`,children:I(`div`,{className:`flex items-start gap-3`,children:[V(`div`,{className:`flex-1 min-w-0`,children:t?I(`div`,{className:`space-y-2`,children:[V(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:o,onChange:e=>s(e.target.value),placeholder:`Template name`,autoFocus:!0}),V(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:c,onChange:e=>l(e.target.value),placeholder:`Description (optional)`})]}):I(R,{children:[V(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&V(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),I(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,I(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),V(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?I(R,{children:[I(`button`,{type:`button`,onClick:g,disabled:d.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[V(He,{className:`h-3 w-3`}),`Save`]}),I(`button`,{type:`button`,onClick:h,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[V(Je,{className:`h-3 w-3`}),`Cancel`]})]}):I(R,{children:[V(`button`,{type:`button`,onClick:()=>m(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:V(je,{className:`h-3 w-3`})}),V(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&p.mutate({id:e.id})},disabled:p.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:V(Xe,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}F();var In=`pipeline-analytics`;function Ln(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function Rn(){let e=z(),{data:t}=y(void 0),{data:n,isLoading:r}=le({addonId:In}),i=Ln(n),a=A({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),o=L(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return I(`div`,{className:`flex flex-col gap-6`,children:[I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),V(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),I(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?V(W,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):V(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:In,patch:{postProcessingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:o.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&V(W,{className:`h-4 w-4 animate-spin text-primary`})]})]}),I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),V(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),V(rt,{types:[`eventMedia`]})]})]})}var zn=`pipeline-orchestrator`,Bn=200;function Vn(){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(j,{addonId:zn,limit:Bn,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F();var Hn=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function Un({refreshToken:e}){let[t,n]=B(`assignments`);return I(`div`,{className:`flex flex-col h-full`,children:[I(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),V(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Per-camera assignments, the load balancer (live load + inference-device weights), cluster-wide settings, and the pipeline template library.`})]}),V(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Hn.map(e=>V(`button`,{type:`button`,onClick:()=>n(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),I(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&V(rn,{}),t===`balancer`&&V(Mn,{refreshToken:e}),t===`events`&&V(Rn,{}),t===`recording`&&V(it,{}),t===`settings`&&V(Pn,{refreshToken:e}),t===`templates`&&V(Fn,{refreshToken:e}),t===`logs`&&V(Vn,{})]})]})}function Wn(e){let t=[],n=[],{assignment:r,detection:i,decoder:a,broker:o}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),i!==null&&i.phase===`active`&&a!==null&&a.shm.framesWritten===0&&t.push({code:`decoder-black-hole`,severity:`error`,message:`Decoder on ${a.nodeId} has written 0 frames to the shared-memory plane while detection is active — the decode path is stalled`}),r.detectionNodeId===null&&i===null&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});for(let e of o?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function Gn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Kn(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function qn(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Jn(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var Yn={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function Xn(e){if(!Gn(e)||!Array.isArray(e.sections))return Yn;let t=ve(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)Jn(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Kn(n(`detectionFps`)),motionSources:qn(n(`motionSources`)),motionFps:Kn(n(`motionFps`)),motionCooldownMs:Kn(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function Zn(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...Zn(r.children,t+1));return n}function Qn(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function X({title:e,children:t}){return I(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[V(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),V(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return I(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[V(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),V(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&V($n,{})]})}function $n(){return V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var er={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return V(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${er[e]}`,children:t})}function $({children:e}){return V(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function tr({icon:e,label:t,nodeId:n,pinned:r,reason:i,overridden:a}){return I(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[V(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),V(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?V(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):I(R,{children:[V(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?I(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[V(st,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,i!==void 0&&i.length>0?i:`capacity`]}),a&&V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function nr({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:i}){let a=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,o=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return I(X,{title:`Where it runs`,children:[V(tr,{icon:G,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),V(tr,{icon:ze,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),V(tr,{icon:ke,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),V(tr,{icon:Ne,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),V(`div`,{className:`mt-1.5`,children:I(`select`,{value:a,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>i(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[V(`option`,{value:`auto`,children:`Auto (load balanced)`}),o.map(e=>I(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function rr(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function ir(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function ar(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function or({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:i}){let a=ir(t,n.detectionStreamProfile),o=ir(t,n.motionStreamProfile),s=n.motionSources.includes(`analyzer`);return I(X,{title:`Streams & motion`,children:[I(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,a!==void 0&&` · ${a.width}×${a.height} ${a.codec}`]}),V(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:ar(n.detectionFps)}),I(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.join(` + `):`none`,r===!1&&` · inactive`]}),s&&I(R,{children:[I(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,o!==void 0&&` · ${o.width}×${o.height} ${o.codec}`]}),I(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[ar(n.motionFps),i!==null&&` · live ${i.toFixed(1)}`]})]}),V(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),V(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?V($,{children:`No streams registered`}):e.map(e=>I(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[V(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,rr(e)]},e.camStreamId))})]})}function sr({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return I(X,{title:`Pipeline steps`,children:[e===void 0?V($,{children:`Resolving…`}):e.length===0?V($,{children:`No steps configured`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>V(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:I(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&V(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&I(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),V(`div`,{className:`mt-1`,children:I(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var cr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function lr({detection:e,live:t,detectionMode:r,modeOverridden:i}){if(e===null)return I(X,{title:`Detection runtime`,children:[V(Z,{label:`Mode`,overridden:i,children:r??`—`}),V($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,u=n(a),d=a===`active`&&o===0;return I(X,{title:`Detection runtime`,children:[I(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[I(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[V(C,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&V(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),V(Z,{label:`Mode`,overridden:i,children:r??`—`}),I(Z,{label:`FPS`,children:[V(`span`,{className:d?`text-danger font-semibold`:``,children:o.toFixed(1)}),I(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),I(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&I(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&I(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),I(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),I(Z,{label:`Provisioning`,children:[V(Q,{tone:cr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&I(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function ur({broker:e}){return e===null?V(X,{title:`Stream broker`,children:V($,{children:`Broker stage inactive or unreachable`})}):I(X,{title:`Stream broker`,children:[e.profiles.length===0?V($,{children:`No broker profiles`}):V(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return I(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),V(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),I(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),I(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),I(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),I(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[I(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),I(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function dr({decoder:e,detectionActive:t}){if(e===null)return V(X,{title:`Decoder`,children:V($,{children:`Decoder stage inactive or unreachable`})});let n=t&&e.shm.framesWritten===0;return I(X,{title:`Decoder`,children:[V(Z,{label:`Node`,children:e.nodeId}),V(Z,{label:`Sessions`,children:e.sessionCount}),I(Z,{label:`SHM frames`,children:[V(`span`,{className:n?`text-danger font-semibold`:``,children:e.shm.framesWritten}),V(`span`,{className:`text-foreground-subtle`,children:` written`})]}),I(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&I(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),I(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&V(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}F();var fr=`pipeline-orchestrator`,pr={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},mr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function hr({problems:e}){return V(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>I(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[V(Ye,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),V(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function gr({deviceId:e,name:t,online:n,status:r,live:i,onlineNodes:a}){let o=z(),{data:s}=te({addonId:fr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:c}=m({deviceId:e},{staleTime:3e4}),l=L(()=>Xn(s),[s]),d=L(()=>c===void 0?void 0:Zn(c.steps),[c]),f=L(()=>r===void 0?[]:Wn(r),[r]),p=()=>{o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},h=ie({onSuccess:p}),g=u({onSuccess:p}),_=t=>{t===`auto`?g.mutate({deviceId:e}):h.mutate({deviceId:e,agentNodeId:t})},v=r===void 0?`idle`:Qn(r),y=f.some(e=>e.severity===`error`),b=f.length>0,x=y?`border-danger/50`:b?`border-warning/40`:`border-border`;return I(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${x} bg-background overflow-hidden`,children:[I(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[V(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${y?`bg-danger`:pr[v]}`,title:y?`Error`:mr[v],"aria-label":y?`Error`:mr[v],role:`img`}),V(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&V(Q,{tone:`danger`,children:`offline`}),I(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[l.detectionMode!==null&&V(Q,{tone:l.detectionMode===`disabled`?`warning`:l.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:l.detectionMode===`disabled`?`detection off`:l.detectionMode}),r?.recording!=null&&(r.recording.active?I(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&I(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),f.length>0&&V(hr,{problems:f}),r===void 0?V(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):I(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[V(nr,{assignment:r.assignment,settings:l,onlineNodes:a,pinPending:h.isPending||g.isPending,onDetectionPinChange:_}),V(lr,{detection:r.detection,live:i,detectionMode:l.detectionMode,modeOverridden:l.overriddenKeys.has(`detectionMode`)}),V(sr,{steps:d,audioModelId:c?.audio?.modelId??null,audioEnabled:r.audio?.enabled??c?.audio?.enabled??null,audioMode:l.audioMode}),V(or,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:l,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null}),V(ur,{broker:r.broker}),V(dr,{decoder:r.decoder,detectionActive:r.detection?.phase===`active`})]})]})}F();var _r=5e3,vr=1e4,yr=5e3;function br(e){let t=z(),{data:n,isLoading:r}=Se(),{data:i,isLoading:a}=O({},{refetchInterval:_r}),{nodes:o}=v();H(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[s,c]=B(new Map);b(ye.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&c(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),H(()=>{if(s.size===0)return;let e=setInterval(()=>{c(e=>{let t=Date.now()-vr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},yr);return()=>clearInterval(e)},[s.size]);let l=L(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:L(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:l.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]),liveMetrics:s,onlineNodes:L(()=>(o??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[o]),isLoading:r||a}}F();function xr({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:i}=br(e),a=L(()=>[...t.map(e=>{let t=e.status===void 0?[]:Wn(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),o=L(()=>{let e=0,t=0;for(let r of a)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:a.length,active:e,issues:t}},[a,n]);return i&&t.length===0?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):V(`div`,{className:`h-full overflow-y-auto`,children:I(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[I(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground`,children:o.total}),` cameras`]}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success`,children:o.active}),` actively inferring`]}),I(`span`,{children:[V(`span`,{className:`font-semibold ${o.issues>0?`text-danger`:`text-foreground`}`,children:o.issues}),` `,`with issues`]}),V(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),a.map(({row:e})=>V(gr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}F();var Sr=`__cluster__`;function Cr(e){return e===`cameras`?`cameras`:`nodes`}function wr(){let[e,t]=Ve(),n=Cr(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[i,a]=B(0),[o,s]=B(!1);return H(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Sr},{replace:!0})},[n,e,t]),I(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[I(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[I(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[V(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:r},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),V(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),I(`button`,{type:`button`,onClick:()=>a(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[V(Pe,{className:`h-3.5 w-3.5`}),`Refresh`]})]}),n===`nodes`&&I(`button`,{type:`button`,onClick:()=>s(e=>!e),"aria-expanded":o,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[I(`span`,{children:[o?`Hide`:`Show`,` node list`]}),V(Be,{className:[`h-4 w-4 transition-transform`,o?`rotate-180`:``].join(` `)})]}),V(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?I(R,{children:[V(`aside`,{className:[o?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:V(pt,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),s(!1)},refreshToken:i})}),V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?V(Un,{refreshToken:i}):V(nn,{nodeId:r,refreshToken:i})})]}):V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:V(xr,{refreshToken:i})})})]})}export{wr as PipelinePage};
@@ -1 +1 @@
1
- import{Bi as e,Gi as t,Hi as n,Ji as r,Ki as i,Li as a,Ri as o,So as s,Ui as c,Vi as l,Wa as u,Wi as d,Yi as f,do as p,fo as m,go as h,ho as g,jn as _,mo as v,po as y,qi as b,xo as x,yo as S,zi as C}from"./src-Wny3-FFU.js";import{K as w,Q as T,S as E,W as D,b as O,o as k,q as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{K as N}from"./src-GxiMH1Sc.js";import{a as P,i as ee,n as F,r as te,t as I}from"./face-bbox-B8GTLKhX.js";import{a as L,c as R,f as z,i as B,l as ne,m as V,n as re,o as ie,p as ae,r as H,s as oe,t as U,u as se}from"./debounced-invalidate-CRCuY4xi.js";import{t as W}from"./pencil-DRb48wcw.js";import{t as G}from"./plus-Ecpq7H2e.js";import{t as ce}from"./square-check-big-CH9QT5C_.js";import{t as K}from"./square-CEkhTs0-.js";import{I as q,L as le,P as ue,R as J,S as Y,W as de,i as X,s as Z}from"./index-BIxHon5T.js";import{t as fe}from"./AdminPage-BwmGKnRf.js";import{n as pe,t as me}from"./authed-media-XfBD4Ma-.js";var he=de(`badge-check`,[[`path`,{d:`M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z`,key:`3c2336`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]);T();var Q=[[`plateGallery`]];function ge({vehicleId:e}){let t=k(),{data:n,isLoading:r}=d({vehicleId:e}),a=i();function o(n){a.mutate({vehicleId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:Q})}})}return r?E(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[j(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading plates…`]}):!n||n.length===0?j(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No plates yet.`}):j(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:n.map(e=>E(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[E(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?j(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:e.text,className:`h-full w-full object-cover`}):j(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:j(J,{className:`h-6 w-6`})}),j(`button`,{type:`button`,onClick:()=>o(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove plate sample`,children:j(X,{className:`h-4 w-4 text-white`})})]}),j(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:e.text,children:e.text})]},e.id))})}function _e({vehicle:e,expanded:t,onToggle:n}){let r=k(),[i,a]=A(``),[o,c]=A(!1),[u,d]=A(!1),f=b(),_=l();function C(){a(e.name),c(!0)}function w(){c(!1),a(``)}function T(){let t=i.trim();if(!t||t===e.name){w();return}f.mutate({id:e.id,name:t},{onSettled:()=>{r.invalidateQueries({queryKey:Q}),w()}})}function D(){_.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Q}),d(!1)}})}return E(`div`,{className:`rounded-md border border-border bg-surface`,children:[E(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[j(`div`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:e.coverBase64?j(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):j(`div`,{className:`flex h-full w-full items-center justify-center`,children:j(J,{className:`h-4 w-4 text-foreground-subtle`})})}),j(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:o?E(O,{children:[j(S,{value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&w()},className:`h-6 text-xs`,autoFocus:!0}),j(`button`,{type:`button`,onClick:T,disabled:f.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:j(le,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:w,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:j(X,{className:`h-3.5 w-3.5`})})]}):j(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),j(x,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!o&&E(`div`,{className:`flex items-center gap-1`,children:[j(`button`,{type:`button`,onClick:C,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:j(W,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:()=>d(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:j(Z,{className:`h-3.5 w-3.5`})})]}),j(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:j(t?q:ue,{className:`h-3.5 w-3.5`})})]}),t&&j(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:j(ge,{vehicleId:e.id})}),j(p,{open:u,onOpenChange:e=>!e&&d(!1),children:E(m,{children:[E(g,{children:[j(h,{children:`Delete vehicle`}),E(y,{children:[`Delete `,j(`strong`,{children:e.name}),` and all its plate samples? This cannot be undone.`]})]}),E(v,{children:[j(s,{variant:`secondary`,onClick:()=>d(!1),children:`Cancel`}),E(s,{variant:`danger`,onClick:D,disabled:_.isPending,children:[_.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ve(){let e=k(),[t,n]=A(``),r=C();function i(){let i=t.trim();i&&r.mutate({name:i},{onSettled:()=>{e.invalidateQueries({queryKey:Q}),n(``)}})}return E(`div`,{className:`flex items-center gap-2 pt-2`,children:[j(S,{placeholder:`New vehicle name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i()},className:`h-7 text-xs flex-1`}),E(s,{variant:`primary`,size:`sm`,onClick:i,disabled:r.isPending||!t.trim(),children:[r.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):j(G,{className:`h-3.5 w-3.5`}),`Add`]})]})}function ye(){let{data:e,isLoading:n}=t(),[r,i]=A(null);function a(e){i(t=>t===e?null:e)}return n?E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[j(Y,{className:`h-4 w-4 animate-spin`}),`Loading vehicles…`]}):E(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&j(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No vehicles enrolled yet. Add one below.`}),e?.map(e=>j(_e,{vehicle:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),j(ve,{})]})}T();var be=[[`plateGallery`]];function xe(e){let[t,n]=A(null),[r,i]=A(null),[a,o]=A(!1);return M(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await pe(`${me}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),M(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Se(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|plate/i.test(e.kind))??t[0]}function $({label:e,value:t,mono:n}){return E(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[j(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),j(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono`:``}`,title:t,children:t})]})}function Ce({box:e}){return j(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:j(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Plate`})})}function we({plate:e,cameraName:t,onClose:r,onAssign:i,onUnassign:a,onDelete:c,actionsPending:l}){let u=k(),{data:d,isFetching:f}=n({plateId:e?.plateId??``},{enabled:e!==null}),h=o(),[g,_]=A(`frame`),[v,y]=A(!1),[b,x]=A(``),{frameSrc:C,naturalWidth:w,naturalHeight:T,failed:O}=xe(e?.keyFrameMediaKey);M(()=>{y(!1),x(``),_(`frame`)},[e?.plateId]);let N=D(()=>{let t=Se(d??[]);return t?`data:image/jpeg;base64,${t.base64}`:e?.base64?`data:image/jpeg;base64,${e.base64}`:null},[d,e]),L=D(()=>!e?.plateBbox||w===null||T===null?null:I(e.plateBbox,w,T),[e?.plateBbox,w,T]);if(e===null)return null;let R=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!O,z=R&&g===`frame`,ne=e.assigned?e.vehicleName??`Assigned`:e.recognizedVehicleId?`${e.vehicleName??`Recognized`} (suggested)`:`Unassigned`,re=`${String(Math.round(e.score*100))}%${e.corrected?` · corrected`:``}`;function ie(){e&&(x(e.text),y(!0))}function H(){if(!e)return;let t=b.trim().toUpperCase();if(!t||t===e.text){y(!1);return}h.mutate({plateId:e.plateId,text:t},{onSettled:()=>{u.invalidateQueries({queryKey:be}),y(!1)}})}return j(p,{open:!0,onOpenChange:e=>!e&&r(),children:E(m,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Plate detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[E(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[E(`div`,{className:`min-w-0`,children:[j(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`Plate detail`}),j(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),j(`button`,{type:`button`,onClick:r,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:j(X,{className:`h-4 w-4`})})]}),E(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[R&&E(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[E(`button`,{type:`button`,onClick:()=>_(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${g===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[j(ee,{className:`h-3.5 w-3.5`}),` Full frame`]}),E(`button`,{type:`button`,onClick:()=>_(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${g===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[j(P,{className:`h-3.5 w-3.5`}),` Crop`]})]}),z&&C?j(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:j(B,{src:C,alt:`Full frame with detected plate`,fit:`natural`,className:`w-full`,overlay:L?j(Ce,{box:L}):void 0})}):N?E(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[j(B,{src:N,alt:`Detected plate`,className:`h-full w-full`}),f&&j(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:j(Y,{className:`h-3.5 w-3.5 animate-spin`})})]}):E(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[j(V,{className:`h-8 w-8 text-warning/70`}),j(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),j(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this plate could not be resolved. Safe to delete.`})]}),j(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:E(`div`,{className:`flex items-center justify-between gap-3`,children:[j(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:`Plate text`}),v?E(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[j(S,{value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&H(),e.key===`Escape`&&y(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),j(`button`,{type:`button`,onClick:H,disabled:h.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Save corrected text`,children:h.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):j(le,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:()=>y(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel`,children:j(X,{className:`h-3.5 w-3.5`})})]}):E(`button`,{type:`button`,onClick:ie,className:`group flex min-w-0 items-center gap-1.5`,title:`Correct the OCR reading`,children:[j(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`—`}),j(W,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),E(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[j($,{label:`Camera`,value:t}),j($,{label:`Captured`,value:ae(e.timestamp)}),j($,{label:`Confidence`,value:re}),j($,{label:`Vehicle`,value:ne}),j($,{label:`Track`,value:e.trackId,mono:!0})]})]}),E(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?E(s,{variant:`secondary`,onClick:()=>a(e.plateId),disabled:l,children:[j(F,{className:`h-3.5 w-3.5`}),` Detach`]}):E(s,{variant:`primary`,onClick:()=>i(e.plateId),disabled:l,children:[j(te,{className:`h-3.5 w-3.5`}),` Assign`]}),E(s,{variant:`secondary`,onClick:()=>c(e.plateId),disabled:l,children:[j(Z,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}T();var Te=[[`plateGallery`]];function Ee({plateIds:e,vehicles:t,onDone:n}){let r=k(),i=a(),o=C(),[c,l]=A(``),[u,d]=A(!1),[f,_]=A(null),b=e!==null&&e.length>0,x=e?.length??0;function w(){d(!1),l(``),_(null)}function T(){w(),n()}function D(t){!e||e.length===0||i.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{r.invalidateQueries({queryKey:Te}),T()}})}function O(){!e||!c.trim()||o.mutate({name:c.trim()},{onSuccess:e=>{e?.id&&D(e.id)},onError:()=>{r.invalidateQueries({queryKey:Te}),T()}})}let M=i.isPending||o.isPending;return j(p,{open:b,onOpenChange:e=>!e&&T(),children:E(m,{children:[E(g,{children:[j(h,{children:x>1?`Assign ${String(x)} plates to vehicle`:`Assign plate to vehicle`}),j(y,{children:`Select an existing vehicle or create a new one.`})]}),j(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>E(`button`,{type:`button`,onClick:()=>_(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${f===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[j(`span`,{className:`font-medium`,children:e.name}),E(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` plates`]})]},e.id))}),u?j(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:j(S,{placeholder:`New vehicle name…`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):j(`button`,{type:`button`,onClick:()=>{_(null),d(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New vehicle…`}),E(v,{children:[j(s,{variant:`secondary`,onClick:T,disabled:M,children:`Cancel`}),u?E(s,{variant:`primary`,onClick:O,disabled:M||!c.trim(),children:[M&&j(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):E(s,{variant:`primary`,onClick:()=>f&&D(f),disabled:M||!f,children:[M&&j(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,x>1?` ${String(x)}`:``]})]})]})})}T();var De=[[`plateGallery`]],Oe=500,ke=120;function Ae({plate:t,cameraName:n,nowMs:i,selected:a,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let l=k(),u=r(),d=e(),f=()=>{l.invalidateQueries({queryKey:De})},p=()=>c(t.plateId);return E(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[E(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[t.base64?j(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:`Plate ${t.text} from ${n}`,onClick:p,className:`h-full w-full cursor-zoom-in object-cover`}):E(`button`,{type:`button`,onClick:p,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the plate's crop media is missing. Safe to delete.`,children:[j(V,{className:`h-7 w-7 text-warning/70`}),j(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":a?`Deselect`:`Select`,children:a?j(ce,{className:`h-4 w-4 text-primary`}):j(K,{className:`h-4 w-4`})}),t.corrected&&E(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:`Manually corrected`,children:[j(he,{className:`h-3 w-3`}),` Fixed`]})]}),E(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[j(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:t.text,children:t.text||`—`}),j(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:n,children:n}),j(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:z(t.timestamp,i)}),t.vehicleName&&j(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:t.vehicleName,children:t.vehicleName})]}),E(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),u.mutate({plateId:t.plateId},{onSettled:f})},disabled:u.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach plate`,title:`Detach`,children:u.isPending?j(Y,{className:`h-4 w-4 animate-spin`}):j(F,{className:`h-4 w-4`})}):j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign plate to vehicle`,title:`Assign to vehicle`,children:j(te,{className:`h-4 w-4`})}),j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),d.mutate({plateId:t.plateId},{onSettled:f})},disabled:d.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete plate`,title:`Delete plate`,children:d.isPending?j(Y,{className:`h-4 w-4 animate-spin`}):j(Z,{className:`h-4 w-4`})})]})]})}var je=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Assigned`,value:`assigned`}];function Me(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function Ne(){let n=k(),[i,a]=A(`all`),[o,l]=A(oe),[u,d]=A(new Set),[p,m]=A(new Set),[h,g]=A(null),[v,y]=A(null),{data:b,isLoading:x}=c({limit:Oe},{refetchInterval:3e4}),{data:S=[]}=t(),{data:C}=_({}),w=r(),T=f(),M=e(),N=Date.now(),P=b??[],ee=D(()=>{let e=new Map;for(let t of C??[])e.set(t.id,t.name);return e},[C]),I=e=>ee.get(e)??`Camera #${String(e)}`,z=D(()=>R(P).map(e=>({id:e,name:I(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,ee]),B=D(()=>ne(se(Me(P,i),o),u),[P,i,o,u]),V=re(B,ke,D(()=>JSON.stringify([i,o.fromMs,o.toMs,[...u].sort((e,t)=>e-t)]),[i,o.fromMs,o.toMs,u])),ae=D(()=>new Map(P.map(e=>[e.plateId,e])),[P]),U=v===null?null:ae.get(v)??null,W=()=>{n.invalidateQueries({queryKey:De})},G=()=>m(new Set);function ce(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let K=[...p],q=T.isPending||M.isPending,le=w.isPending||M.isPending;function ue(){K.length!==0&&T.mutate({plateIds:K},{onSettled:()=>{W(),G()}})}function J(){K.length!==0&&Promise.allSettled(K.map(e=>M.mutateAsync({plateId:e}))).then(()=>{W(),G()})}function de(e){y(null),g([e])}function fe(e){w.mutate({plateId:e},{onSettled:W}),y(null)}function pe(e){M.mutate({plateId:e},{onSettled:W}),y(null)}let me=B.length!==P.length;return E(`div`,{className:`relative space-y-3`,children:[E(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[j(`div`,{className:`flex items-center gap-1`,children:je.map(e=>j(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),j(L,{onChange:l}),j(ie,{cameras:z,selected:u,onChange:d}),!x&&j(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:me?`${String(B.length)} of ${String(P.length)} plates`:`${String(B.length)} plate${B.length===1?``:`s`}`})]}),p.size>0&&E(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[E(`span`,{className:`text-xs font-medium text-foreground`,children:[p.size,` selected`]}),E(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[E(s,{variant:`primary`,onClick:()=>g(K),disabled:q,children:[j(te,{className:`h-3.5 w-3.5`}),` Assign`]}),E(s,{variant:`secondary`,onClick:ue,disabled:q,children:[T.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):j(F,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),E(s,{variant:`secondary`,onClick:J,disabled:q,children:[j(Z,{className:`h-3.5 w-3.5`}),` Delete`]}),j(s,{variant:`ghost`,onClick:G,disabled:q,children:j(X,{className:`h-3.5 w-3.5`})})]})]}),x&&E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[j(Y,{className:`h-4 w-4 animate-spin`}),` Loading plates…`]}),!x&&B.length===0&&j(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:P.length>0?`No plates match the current filters.`:`No plates recognized yet.`}),!x&&B.length>0&&E(O,{children:[j(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2`,children:V.pageItems.map(e=>j(Ae,{plate:e,cameraName:I(e.deviceId),nowMs:N,selected:p.has(e.plateId),onToggleSelect:ce,onAssign:e=>g([e]),onOpenDetail:y},e.plateId))}),j(H,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`plates`})]}),j(we,{plate:U,cameraName:U?I(U.deviceId):``,onClose:()=>y(null),onAssign:de,onUnassign:fe,onDelete:pe,actionsPending:le}),j(Ee,{plateIds:h,vehicles:S,onDone:()=>{g(null),G()}})]})}T();var Pe=[[`plateGallery`]],Fe=2e3;function Ie(){let e=k(),t=w(e);t.current=e;let n=w(void 0);n.current||=U({delayMs:Fe,invalidate:()=>{t.current.invalidateQueries({queryKey:Pe})}}),M(()=>()=>n.current?.cancel(),[]),u(N.PipelineAnalyticsPlateGalleryChanged,()=>{n.current?.trigger()})}function Le(){return Ie(),j(fe,{icon:J,title:`Plates`,subtitle:`Manage enrolled vehicles and assign recognized license plates to them.`,children:E(`section`,{className:`space-y-3`,children:[E(`div`,{children:[j(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Vehicles`}),j(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled vehicle identities used for plate recognition. Expand a row to view or remove plate samples.`}),j(ye,{})]}),E(`div`,{className:`pt-4 border-t border-border`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent recognized plates`}),j(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`}),j(Ne,{})]})]})})}export{Le as PlatesPage};
1
+ import{Bi as e,Gi as t,Hi as n,Ji as r,Ki as i,Li as a,Ri as o,So as s,Ui as c,Vi as l,Wa as u,Wi as d,Yi as f,do as p,fo as m,go as h,ho as g,jn as _,mo as v,po as y,qi as b,xo as x,yo as S,zi as C}from"./src-Bwet06Ih.js";import{K as w,Q as T,S as E,W as D,b as O,o as k,q as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{K as N}from"./src-GxiMH1Sc.js";import{a as P,i as ee,n as F,r as te,t as I}from"./face-bbox-C2co2f2G.js";import{a as L,c as R,f as z,i as B,l as ne,m as V,n as re,o as ie,p as ae,r as H,s as oe,t as U,u as se}from"./debounced-invalidate-DCtq_NHc.js";import{t as W}from"./pencil-Ik1l3G_8.js";import{t as G}from"./plus-B0OPxy2A.js";import{t as ce}from"./square-check-big-tgpBR4IT.js";import{t as K}from"./square-Ckdv6ORu.js";import{I as q,L as le,P as ue,R as J,S as Y,W as de,i as X,s as Z}from"./index-RegSp4ae.js";import{t as fe}from"./AdminPage-BwmGKnRf.js";import{n as pe,t as me}from"./authed-media-XfBD4Ma-.js";var he=de(`badge-check`,[[`path`,{d:`M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z`,key:`3c2336`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]);T();var Q=[[`plateGallery`]];function ge({vehicleId:e}){let t=k(),{data:n,isLoading:r}=d({vehicleId:e}),a=i();function o(n){a.mutate({vehicleId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:Q})}})}return r?E(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[j(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading plates…`]}):!n||n.length===0?j(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No plates yet.`}):j(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:n.map(e=>E(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[E(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?j(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:e.text,className:`h-full w-full object-cover`}):j(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:j(J,{className:`h-6 w-6`})}),j(`button`,{type:`button`,onClick:()=>o(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove plate sample`,children:j(X,{className:`h-4 w-4 text-white`})})]}),j(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:e.text,children:e.text})]},e.id))})}function _e({vehicle:e,expanded:t,onToggle:n}){let r=k(),[i,a]=A(``),[o,c]=A(!1),[u,d]=A(!1),f=b(),_=l();function C(){a(e.name),c(!0)}function w(){c(!1),a(``)}function T(){let t=i.trim();if(!t||t===e.name){w();return}f.mutate({id:e.id,name:t},{onSettled:()=>{r.invalidateQueries({queryKey:Q}),w()}})}function D(){_.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:Q}),d(!1)}})}return E(`div`,{className:`rounded-md border border-border bg-surface`,children:[E(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[j(`div`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:e.coverBase64?j(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):j(`div`,{className:`flex h-full w-full items-center justify-center`,children:j(J,{className:`h-4 w-4 text-foreground-subtle`})})}),j(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:o?E(O,{children:[j(S,{value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&w()},className:`h-6 text-xs`,autoFocus:!0}),j(`button`,{type:`button`,onClick:T,disabled:f.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:j(le,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:w,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:j(X,{className:`h-3.5 w-3.5`})})]}):j(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),j(x,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!o&&E(`div`,{className:`flex items-center gap-1`,children:[j(`button`,{type:`button`,onClick:C,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:j(W,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:()=>d(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:j(Z,{className:`h-3.5 w-3.5`})})]}),j(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:j(t?q:ue,{className:`h-3.5 w-3.5`})})]}),t&&j(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:j(ge,{vehicleId:e.id})}),j(p,{open:u,onOpenChange:e=>!e&&d(!1),children:E(m,{children:[E(g,{children:[j(h,{children:`Delete vehicle`}),E(y,{children:[`Delete `,j(`strong`,{children:e.name}),` and all its plate samples? This cannot be undone.`]})]}),E(v,{children:[j(s,{variant:`secondary`,onClick:()=>d(!1),children:`Cancel`}),E(s,{variant:`danger`,onClick:D,disabled:_.isPending,children:[_.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ve(){let e=k(),[t,n]=A(``),r=C();function i(){let i=t.trim();i&&r.mutate({name:i},{onSettled:()=>{e.invalidateQueries({queryKey:Q}),n(``)}})}return E(`div`,{className:`flex items-center gap-2 pt-2`,children:[j(S,{placeholder:`New vehicle name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i()},className:`h-7 text-xs flex-1`}),E(s,{variant:`primary`,size:`sm`,onClick:i,disabled:r.isPending||!t.trim(),children:[r.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):j(G,{className:`h-3.5 w-3.5`}),`Add`]})]})}function ye(){let{data:e,isLoading:n}=t(),[r,i]=A(null);function a(e){i(t=>t===e?null:e)}return n?E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[j(Y,{className:`h-4 w-4 animate-spin`}),`Loading vehicles…`]}):E(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&j(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No vehicles enrolled yet. Add one below.`}),e?.map(e=>j(_e,{vehicle:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),j(ve,{})]})}T();var be=[[`plateGallery`]];function xe(e){let[t,n]=A(null),[r,i]=A(null),[a,o]=A(!1);return M(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await pe(`${me}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),M(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Se(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|plate/i.test(e.kind))??t[0]}function $({label:e,value:t,mono:n}){return E(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[j(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),j(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono`:``}`,title:t,children:t})]})}function Ce({box:e}){return j(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:j(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Plate`})})}function we({plate:e,cameraName:t,onClose:r,onAssign:i,onUnassign:a,onDelete:c,actionsPending:l}){let u=k(),{data:d,isFetching:f}=n({plateId:e?.plateId??``},{enabled:e!==null}),h=o(),[g,_]=A(`frame`),[v,y]=A(!1),[b,x]=A(``),{frameSrc:C,naturalWidth:w,naturalHeight:T,failed:O}=xe(e?.keyFrameMediaKey);M(()=>{y(!1),x(``),_(`frame`)},[e?.plateId]);let N=D(()=>{let t=Se(d??[]);return t?`data:image/jpeg;base64,${t.base64}`:e?.base64?`data:image/jpeg;base64,${e.base64}`:null},[d,e]),L=D(()=>!e?.plateBbox||w===null||T===null?null:I(e.plateBbox,w,T),[e?.plateBbox,w,T]);if(e===null)return null;let R=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!O,z=R&&g===`frame`,ne=e.assigned?e.vehicleName??`Assigned`:e.recognizedVehicleId?`${e.vehicleName??`Recognized`} (suggested)`:`Unassigned`,re=`${String(Math.round(e.score*100))}%${e.corrected?` · corrected`:``}`;function ie(){e&&(x(e.text),y(!0))}function H(){if(!e)return;let t=b.trim().toUpperCase();if(!t||t===e.text){y(!1);return}h.mutate({plateId:e.plateId,text:t},{onSettled:()=>{u.invalidateQueries({queryKey:be}),y(!1)}})}return j(p,{open:!0,onOpenChange:e=>!e&&r(),children:E(m,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Plate detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[E(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[E(`div`,{className:`min-w-0`,children:[j(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`Plate detail`}),j(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),j(`button`,{type:`button`,onClick:r,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:j(X,{className:`h-4 w-4`})})]}),E(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[R&&E(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[E(`button`,{type:`button`,onClick:()=>_(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${g===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[j(ee,{className:`h-3.5 w-3.5`}),` Full frame`]}),E(`button`,{type:`button`,onClick:()=>_(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${g===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[j(P,{className:`h-3.5 w-3.5`}),` Crop`]})]}),z&&C?j(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:j(B,{src:C,alt:`Full frame with detected plate`,fit:`natural`,className:`w-full`,overlay:L?j(Ce,{box:L}):void 0})}):N?E(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[j(B,{src:N,alt:`Detected plate`,className:`h-full w-full`}),f&&j(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:j(Y,{className:`h-3.5 w-3.5 animate-spin`})})]}):E(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[j(V,{className:`h-8 w-8 text-warning/70`}),j(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),j(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this plate could not be resolved. Safe to delete.`})]}),j(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:E(`div`,{className:`flex items-center justify-between gap-3`,children:[j(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:`Plate text`}),v?E(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[j(S,{value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&H(),e.key===`Escape`&&y(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),j(`button`,{type:`button`,onClick:H,disabled:h.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Save corrected text`,children:h.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):j(le,{className:`h-3.5 w-3.5`})}),j(`button`,{type:`button`,onClick:()=>y(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel`,children:j(X,{className:`h-3.5 w-3.5`})})]}):E(`button`,{type:`button`,onClick:ie,className:`group flex min-w-0 items-center gap-1.5`,title:`Correct the OCR reading`,children:[j(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`—`}),j(W,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),E(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[j($,{label:`Camera`,value:t}),j($,{label:`Captured`,value:ae(e.timestamp)}),j($,{label:`Confidence`,value:re}),j($,{label:`Vehicle`,value:ne}),j($,{label:`Track`,value:e.trackId,mono:!0})]})]}),E(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?E(s,{variant:`secondary`,onClick:()=>a(e.plateId),disabled:l,children:[j(F,{className:`h-3.5 w-3.5`}),` Detach`]}):E(s,{variant:`primary`,onClick:()=>i(e.plateId),disabled:l,children:[j(te,{className:`h-3.5 w-3.5`}),` Assign`]}),E(s,{variant:`secondary`,onClick:()=>c(e.plateId),disabled:l,children:[j(Z,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}T();var Te=[[`plateGallery`]];function Ee({plateIds:e,vehicles:t,onDone:n}){let r=k(),i=a(),o=C(),[c,l]=A(``),[u,d]=A(!1),[f,_]=A(null),b=e!==null&&e.length>0,x=e?.length??0;function w(){d(!1),l(``),_(null)}function T(){w(),n()}function D(t){!e||e.length===0||i.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{r.invalidateQueries({queryKey:Te}),T()}})}function O(){!e||!c.trim()||o.mutate({name:c.trim()},{onSuccess:e=>{e?.id&&D(e.id)},onError:()=>{r.invalidateQueries({queryKey:Te}),T()}})}let M=i.isPending||o.isPending;return j(p,{open:b,onOpenChange:e=>!e&&T(),children:E(m,{children:[E(g,{children:[j(h,{children:x>1?`Assign ${String(x)} plates to vehicle`:`Assign plate to vehicle`}),j(y,{children:`Select an existing vehicle or create a new one.`})]}),j(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>E(`button`,{type:`button`,onClick:()=>_(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${f===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[j(`span`,{className:`font-medium`,children:e.name}),E(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` plates`]})]},e.id))}),u?j(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:j(S,{placeholder:`New vehicle name…`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):j(`button`,{type:`button`,onClick:()=>{_(null),d(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New vehicle…`}),E(v,{children:[j(s,{variant:`secondary`,onClick:T,disabled:M,children:`Cancel`}),u?E(s,{variant:`primary`,onClick:O,disabled:M||!c.trim(),children:[M&&j(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):E(s,{variant:`primary`,onClick:()=>f&&D(f),disabled:M||!f,children:[M&&j(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,x>1?` ${String(x)}`:``]})]})]})})}T();var De=[[`plateGallery`]],Oe=500,ke=120;function Ae({plate:t,cameraName:n,nowMs:i,selected:a,onToggleSelect:o,onAssign:s,onOpenDetail:c}){let l=k(),u=r(),d=e(),f=()=>{l.invalidateQueries({queryKey:De})},p=()=>c(t.plateId);return E(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[E(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[t.base64?j(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:`Plate ${t.text} from ${n}`,onClick:p,className:`h-full w-full cursor-zoom-in object-cover`}):E(`button`,{type:`button`,onClick:p,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the plate's crop media is missing. Safe to delete.`,children:[j(V,{className:`h-7 w-7 text-warning/70`}),j(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o(t.plateId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":a?`Deselect`:`Select`,children:a?j(ce,{className:`h-4 w-4 text-primary`}):j(K,{className:`h-4 w-4`})}),t.corrected&&E(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:`Manually corrected`,children:[j(he,{className:`h-3 w-3`}),` Fixed`]})]}),E(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[j(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:t.text,children:t.text||`—`}),j(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:n,children:n}),j(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:z(t.timestamp,i)}),t.vehicleName&&j(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:t.vehicleName,children:t.vehicleName})]}),E(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[t.assigned?j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),u.mutate({plateId:t.plateId},{onSettled:f})},disabled:u.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach plate`,title:`Detach`,children:u.isPending?j(Y,{className:`h-4 w-4 animate-spin`}):j(F,{className:`h-4 w-4`})}):j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign plate to vehicle`,title:`Assign to vehicle`,children:j(te,{className:`h-4 w-4`})}),j(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),d.mutate({plateId:t.plateId},{onSettled:f})},disabled:d.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete plate`,title:`Delete plate`,children:d.isPending?j(Y,{className:`h-4 w-4 animate-spin`}):j(Z,{className:`h-4 w-4`})})]})]})}var je=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Assigned`,value:`assigned`}];function Me(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function Ne(){let n=k(),[i,a]=A(`all`),[o,l]=A(oe),[u,d]=A(new Set),[p,m]=A(new Set),[h,g]=A(null),[v,y]=A(null),{data:b,isLoading:x}=c({limit:Oe},{refetchInterval:3e4}),{data:S=[]}=t(),{data:C}=_({}),w=r(),T=f(),M=e(),N=Date.now(),P=b??[],ee=D(()=>{let e=new Map;for(let t of C??[])e.set(t.id,t.name);return e},[C]),I=e=>ee.get(e)??`Camera #${String(e)}`,z=D(()=>R(P).map(e=>({id:e,name:I(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,ee]),B=D(()=>ne(se(Me(P,i),o),u),[P,i,o,u]),V=re(B,ke,D(()=>JSON.stringify([i,o.fromMs,o.toMs,[...u].sort((e,t)=>e-t)]),[i,o.fromMs,o.toMs,u])),ae=D(()=>new Map(P.map(e=>[e.plateId,e])),[P]),U=v===null?null:ae.get(v)??null,W=()=>{n.invalidateQueries({queryKey:De})},G=()=>m(new Set);function ce(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let K=[...p],q=T.isPending||M.isPending,le=w.isPending||M.isPending;function ue(){K.length!==0&&T.mutate({plateIds:K},{onSettled:()=>{W(),G()}})}function J(){K.length!==0&&Promise.allSettled(K.map(e=>M.mutateAsync({plateId:e}))).then(()=>{W(),G()})}function de(e){y(null),g([e])}function fe(e){w.mutate({plateId:e},{onSettled:W}),y(null)}function pe(e){M.mutate({plateId:e},{onSettled:W}),y(null)}let me=B.length!==P.length;return E(`div`,{className:`relative space-y-3`,children:[E(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[j(`div`,{className:`flex items-center gap-1`,children:je.map(e=>j(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),j(L,{onChange:l}),j(ie,{cameras:z,selected:u,onChange:d}),!x&&j(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:me?`${String(B.length)} of ${String(P.length)} plates`:`${String(B.length)} plate${B.length===1?``:`s`}`})]}),p.size>0&&E(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[E(`span`,{className:`text-xs font-medium text-foreground`,children:[p.size,` selected`]}),E(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[E(s,{variant:`primary`,onClick:()=>g(K),disabled:q,children:[j(te,{className:`h-3.5 w-3.5`}),` Assign`]}),E(s,{variant:`secondary`,onClick:ue,disabled:q,children:[T.isPending?j(Y,{className:`h-3.5 w-3.5 animate-spin`}):j(F,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),E(s,{variant:`secondary`,onClick:J,disabled:q,children:[j(Z,{className:`h-3.5 w-3.5`}),` Delete`]}),j(s,{variant:`ghost`,onClick:G,disabled:q,children:j(X,{className:`h-3.5 w-3.5`})})]})]}),x&&E(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[j(Y,{className:`h-4 w-4 animate-spin`}),` Loading plates…`]}),!x&&B.length===0&&j(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:P.length>0?`No plates match the current filters.`:`No plates recognized yet.`}),!x&&B.length>0&&E(O,{children:[j(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2`,children:V.pageItems.map(e=>j(Ae,{plate:e,cameraName:I(e.deviceId),nowMs:N,selected:p.has(e.plateId),onToggleSelect:ce,onAssign:e=>g([e]),onOpenDetail:y},e.plateId))}),j(H,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`plates`})]}),j(we,{plate:U,cameraName:U?I(U.deviceId):``,onClose:()=>y(null),onAssign:de,onUnassign:fe,onDelete:pe,actionsPending:le}),j(Ee,{plateIds:h,vehicles:S,onDone:()=>{g(null),G()}})]})}T();var Pe=[[`plateGallery`]],Fe=2e3;function Ie(){let e=k(),t=w(e);t.current=e;let n=w(void 0);n.current||=U({delayMs:Fe,invalidate:()=>{t.current.invalidateQueries({queryKey:Pe})}}),M(()=>()=>n.current?.cancel(),[]),u(N.PipelineAnalyticsPlateGalleryChanged,()=>{n.current?.trigger()})}function Le(){return Ie(),j(fe,{icon:J,title:`Plates`,subtitle:`Manage enrolled vehicles and assign recognized license plates to them.`,children:E(`section`,{className:`space-y-3`,children:[E(`div`,{children:[j(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Vehicles`}),j(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled vehicle identities used for plate recognition. Expand a row to view or remove plate samples.`}),j(ye,{})]}),E(`div`,{className:`pt-4 border-t border-border`,children:[j(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent recognized plates`}),j(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`}),j(Ne,{})]})]})})}export{Le as PlatesPage};