@camstack/addon-admin-ui 1.1.29 → 1.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddLocationWizard-CnG4Jw4r.js → AddLocationWizard-CoTQ1C0P.js} +1 -1
- package/dist/assets/{AddonCollectionPage-D5fOjzfx.js → AddonCollectionPage-Br_mtznf.js} +1 -1
- package/dist/assets/{Addons-Db_RAt3v.js → Addons-BW1fbKyX.js} +1 -1
- package/dist/assets/{AdminTabs-B-xBcdog.js → AdminTabs-65LS38O7.js} +1 -1
- package/dist/assets/{BrokerForm-CTcsWVZR.js → BrokerForm-CJOIbxU1.js} +1 -1
- package/dist/assets/{Capabilities-BqetiAMU.js → Capabilities-DVCIj63p.js} +1 -1
- package/dist/assets/{CapabilityBadges-jicOYjj6.js → CapabilityBadges-DHKu7X9M.js} +1 -1
- package/dist/assets/{Cluster-BXf2jygi.js → Cluster-DXsPIAud.js} +1 -1
- package/dist/assets/{Dashboard-CLlB1hDW.js → Dashboard-DoGVZOeG.js} +1 -1
- package/dist/assets/{Data-B9cg2B5a.js → Data-AE4ujje6.js} +1 -1
- package/dist/assets/{DetectionIntelligence-DrGSMaZg.js → DetectionIntelligence-9Y96FdEf.js} +1 -1
- package/dist/assets/{DeviceDetail-CPoHlzWC.js → DeviceDetail-PQfHJrSX.js} +1 -1
- package/dist/assets/{Devices-BOfyRO4k.js → Devices-CNp9pqiU.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CRZcdq7v.js → EmbedPlayerPage-BY1XGljW.js} +1 -1
- package/dist/assets/{FormBuilder-DZX1XL6m.js → FormBuilder-CPSLjDeb.js} +1 -1
- package/dist/assets/{Identity-Bppib_7n.js → Identity-Bsaqp7-s.js} +1 -1
- package/dist/assets/{IntegrationDetail-Cj9Ox8Bj.js → IntegrationDetail-Cvr_93Re.js} +1 -1
- package/dist/assets/{Integrations-Dx0xF5oR.js → Integrations-BuPQK_EH.js} +1 -1
- package/dist/assets/{Integrations-Cit9uT00.js → Integrations-Y0ziVjly.js} +1 -1
- package/dist/assets/{Logs-D7FcnaPJ.js → Logs-DkqRdR14.js} +1 -1
- package/dist/assets/{MotionZonesSettings-Cb04qdzk.js → MotionZonesSettings-BtVUNK7D.js} +1 -1
- package/dist/assets/{MyAccess-MVq0K8uY.js → MyAccess-C6qT1LES.js} +1 -1
- package/dist/assets/{Network-BYM7_iZ2.js → Network-Cj8f56PJ.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-Dt0jm53X.js → NodeAddonsSettingsPanel-CaMCtRtL.js} +1 -1
- package/dist/assets/{NotificationTargets-jpIjfbRG.js → NotificationTargets-DO6tp_-o.js} +1 -1
- package/dist/assets/{Pipeline-DGrnfG3a.js → Pipeline-Bq-_taoo.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-Wr66uQbg.js → PrivacyMaskSettings-DfGtcPz_.js} +1 -1
- package/dist/assets/{ProviderIcon-BnSIkBGb.js → ProviderIcon-B7VHX4h5.js} +1 -1
- package/dist/assets/{ScanNetworkModal-n3VxjQwQ.js → ScanNetworkModal-k76UGIG5.js} +1 -1
- package/dist/assets/{Settings-DK-SO0Gt.js → Settings-B6QqX2do.js} +1 -1
- package/dist/assets/{Showroom-B8pfHZrv.js → Showroom-Cwko7Yni.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DCI0KP1h.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-pD0FKW7m.js} +1 -1
- package/dist/assets/{build-cluster-graph-CHCjyAD0.js → build-cluster-graph-Ci-E0Tjd.js} +1 -1
- package/dist/assets/circle-check-big-uwi7M0FF.js +1 -0
- package/dist/assets/{copy-CfRbwiw1.js → copy-BqJTD0NL.js} +1 -1
- package/dist/assets/{dist-B6nrtI9D.js → dist-Bs1zChcu.js} +1 -1
- package/dist/assets/{dist-ipJu8FwS.js → dist-DozEYSra.js} +1 -1
- package/dist/assets/{download-BK8xwPVQ.js → download-DRBhCGtf.js} +1 -1
- package/dist/assets/{hostInit-BC24YkY4.js → hostInit-Dmv2Dz_q.js} +1 -1
- package/dist/assets/{index-dp4qM2Ld.js → index-CukLUOO-.js} +3 -3
- package/dist/assets/{key-round-C3LHvF6U.js → key-round-92fgndyk.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-427f8b25.js → mf-entry-bootstrap-0-5e99685c.js} +2 -2
- package/dist/assets/{pencil-DiE1Fpdo.js → pencil-GseW53Af.js} +1 -1
- package/dist/assets/{player-overlays-Bhh-T-qH.js → player-overlays-DACImv1W.js} +1 -1
- package/dist/assets/plus-D1FskUey.js +1 -0
- package/dist/assets/{radio-2c5e79TS.js → radio-BDUnjOmb.js} +1 -1
- package/dist/assets/{refresh-cw-t853aWpn.js → refresh-cw-TV5MkG3n.js} +1 -1
- package/dist/assets/remoteEntry-Ci-8NIZN.js +1 -0
- package/dist/assets/{rotate-ccw-CqP9ycm8.js → rotate-ccw-DvDKOoJk.js} +1 -1
- package/dist/assets/rotate-cw-Dv3oho6L.js +1 -0
- package/dist/assets/search-CvffVaTb.js +1 -0
- package/dist/assets/{server-DrYKV5GK.js → server-BrxSxrRc.js} +1 -1
- package/dist/assets/{sparkles-CfTkW_22.js → sparkles-BLSwH3NZ.js} +1 -1
- package/dist/assets/square-D5hZ81IL.js +1 -0
- package/dist/assets/{square-check-big-sMZXYHT_.js → square-check-big-DZGG97xQ.js} +1 -1
- package/dist/assets/{src-CjIUerPQ.js → src-3NEgkLWp.js} +4 -4
- package/dist/assets/{src-Ce30zKhx.js → src-DAcus8MI.js} +1 -1
- package/dist/assets/{upload-D9DZCFsu.js → upload-UD1RyugS.js} +1 -1
- package/dist/assets/{useDevice-CcTWAItl.js → useDevice-B_z2JZ7g.js} +1 -1
- package/dist/assets/{useEventInvalidation-CnMgTDMe.js → useEventInvalidation-C6mDyTBx.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-om5KYkAf.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CZAUwRYb.js} +2 -2
- package/dist/assets/{wifi-pC6ozBXk.js → wifi-Bzb_4egH.js} +1 -1
- package/dist/assets/{zap-CVw3MjTh.js → zap-ps4S9uq0.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +4 -2
- package/package.json +1 -1
- package/dist/assets/circle-check-big-DJfEzTYP.js +0 -1
- package/dist/assets/plus-D0PsZI7U.js +0 -1
- package/dist/assets/remoteEntry-J1DId0IO.js +0 -1
- package/dist/assets/rotate-cw-DBJ_dV1u.js +0 -1
- package/dist/assets/search-CzNcbSQJ.js +0 -1
- package/dist/assets/square-CAY4kQy9.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{$i as e,Aa as t,Da as n,Ea as r,S as i,Sa as a,Ta as o,ja as s,ka as c,wa as l,xa as u}from"./src-CjIUerPQ.js";import{Q as d,S as f,W as p,a as m,q as h,t as g,x as _}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as v}from"./player-overlays-Bhh-T-qH.js";import{t as y}from"./circle-check-big-DJfEzTYP.js";import{t as b}from"./pencil-DiE1Fpdo.js";import{t as x}from"./plus-D0PsZI7U.js";import{t as S}from"./search-CzNcbSQJ.js";import{R as C,V as w,j as T,s as E,x as D}from"./index-dp4qM2Ld.js";import{t as O}from"./AdminPage-BwmGKnRf.js";var k=w(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]);d();var A=e=>typeof e==`string`&&e.length>0;function j(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function M(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function N(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];A(i)&&n.push({mediaType:r,url:i})}return n}function P(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=A(r.label),i=A(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function F(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=N(e,t.attachmentUrls),i=P(e,t.actions),a=e.ttl&&A(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:M(e,t.format),priority:I(t.priority),...A(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&A(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&A(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...A(t.tag)?{tag:t.tag}:{}}}function I(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function L(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function R(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var z={image:`https://example.com/sample.jpg`,video:`https://example.com/sample.mp4`,gif:`https://example.com/sample.gif`,audio:`https://example.com/sample.mp3`,icon:`https://example.com/icon.png`};function B(e,t){let n=R(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=L(e);return{...n,body:`Critical test notification`,priority:5,level:t?.id??``}}case`everything`:{let t={},n=0;for(let r of e.attachments.mediaTypes){if(n>=e.attachments.max)break;t[r]=z[r],n+=1}let r=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`https://example.com/action/${t+1}`}));return{level:``,priority:4,format:e.format.includes(`markdown`)?`markdown`:e.format.includes(`html`)?`html`:e.format[0]??`text`,title:`Everything the kind supports`,body:`This sample fills every control the kind advertises.`,attachmentUrls:t,actions:r,clickUrl:e.clickUrl?`https://example.com/open`:``,sound:e.sound?`default`:``,ttl:e.ttl?`3600`:``,tag:`camstack-test`}}}}var V=[{id:`minimal`,label:`Minimal (body only)`},{id:`everything`,label:`Everything supported`},{id:`overflow`,label:`Overflow`},{id:`critical`,label:`Critical`}],H=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,U=`block text-[11px] font-medium text-foreground mb-1`;function W({target:e,kind:n,open:i,onClose:c}){let d=v(),m=p(()=>j(n.caps),[n.caps]),[y,b]=h(()=>R(n.caps)),[x,S]=h(null),C=p(()=>F(n.caps,y),[n.caps,y]),w=y.body.length,T=w>m.bodyMaxLen,E=e=>b(t=>({...t,...e})),O=g({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:F(n.caps,y)}),onMutate:()=>S(null),onSuccess:e=>S(e),onError:e=>S({success:!1,error:e instanceof Error?e.message:`Test failed`})}),A=e=>{b(B(n.caps,e)),S(null)},M=(e,t,n)=>{let r=y.actions.length>0?[...y.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},E({actions:r})};return _(u,{open:i,onOpenChange:e=>!e&&c(),children:f(a,{width:`lg`,className:`!max-w-2xl`,children:[_(o,{children:f(r,{children:[`Test "`,e.name,`" (`,n.label,`)`]})}),f(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[_(`div`,{className:`flex flex-wrap gap-1.5`,children:V.map(e=>_(s,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>A(e.id),children:e.label},e.id))}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.levels.length>0&&f(`div`,{children:[_(`label`,{className:U,children:`Level`}),f(`select`,{className:H,value:y.level,onChange:e=>E({level:e.target.value}),children:[_(`option`,{value:``,children:`— derive from priority —`}),m.levels.map(e=>f(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=m.levels.find(e=>e.id===y.level);return e?f(`div`,{className:`mt-1 space-y-1`,children:[e.description&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),f(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&_(t,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&_(t,{variant:`info`,children:`silent`}),e.flags?.noPush&&_(t,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&f(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),f(`div`,{children:[f(`label`,{className:U,children:[`Priority (ordinal): `,y.priority]}),_(`input`,{type:`range`,min:1,max:5,step:1,value:y.priority,onChange:e=>E({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),m.formats.length>0&&f(`div`,{children:[_(`label`,{className:U,children:`Format`}),_(`div`,{className:`flex flex-wrap gap-2`,children:m.formats.map(e=>f(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[_(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:y.format===e,onChange:()=>E({format:e})}),e]},e))})]}),f(`div`,{children:[_(`label`,{className:U,children:`Title`}),_(`input`,{className:H,value:y.title,onChange:e=>E({title:e.target.value})})]}),f(`div`,{children:[f(`label`,{className:U,children:[`Body`,` `,f(`span`,{className:T?`text-danger`:`text-foreground-subtle`,children:[`(`,w,`/`,m.bodyMaxLen,T?` — overflow`:``,`)`]})]}),_(`textarea`,{className:`${H} min-h-[80px] resize-y`,value:y.body,onChange:e=>E({body:e.target.value})})]}),m.attachmentSlots.length>0&&f(`div`,{children:[f(`label`,{className:U,children:[`Attachments`,` `,f(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,m.attachmentMode,`, max `,m.attachmentMax,m.attachmentMaxBytes?`, ≤${Math.round(m.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),_(`div`,{className:`space-y-1.5`,children:m.attachmentSlots.map(e=>f(`div`,{className:`flex items-center gap-2`,children:[_(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),_(`input`,{className:H,placeholder:`${e} URL`,value:y.attachmentUrls[e]??``,onChange:t=>E({attachmentUrls:{...y.attachmentUrls,[e]:t.target.value}})})]},e))})]}),m.showActions&&f(`div`,{children:[f(`label`,{className:U,children:[`Actions (up to `,m.maxActions,`)`]}),_(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(m.maxActions,3)},(e,t)=>f(`div`,{className:`flex items-center gap-2`,children:[_(`input`,{className:H,placeholder:`label`,value:y.actions[t]?.label??``,onChange:e=>M(t,`label`,e.target.value)}),_(`input`,{className:H,placeholder:`url`,value:y.actions[t]?.url??``,onChange:e=>M(t,`url`,e.target.value)})]},t))})]}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.showClickUrl&&f(`div`,{children:[_(`label`,{className:U,children:`Click URL`}),_(`input`,{className:H,value:y.clickUrl,onChange:e=>E({clickUrl:e.target.value})})]}),m.showSound&&f(`div`,{children:[_(`label`,{className:U,children:`Sound`}),_(`input`,{className:H,value:y.sound,onChange:e=>E({sound:e.target.value})})]}),m.showTtl&&f(`div`,{children:[_(`label`,{className:U,children:`TTL (seconds)`}),_(`input`,{className:H,type:`number`,value:y.ttl,onChange:e=>E({ttl:e.target.value})})]}),m.showTag&&f(`div`,{children:[_(`label`,{className:U,children:`Tag`}),_(`input`,{className:H,value:y.tag,onChange:e=>E({tag:e.target.value})})]})]}),x&&_(G,{result:x}),f(`details`,{className:`text-[10px]`,children:[_(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),_(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(C,null,2)})]})]}),f(l,{children:[_(s,{variant:`secondary`,size:`sm`,type:`button`,onClick:c,children:`Close`}),f(s,{size:`sm`,type:`button`,disabled:O.isPending||y.body.length===0,onClick:()=>O.mutate(),children:[O.isPending?_(D,{className:`h-3.5 w-3.5 animate-spin`}):_(k,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function G({result:e}){let t=e.renderedAs;return f(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[f(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?_(y,{className:`h-3.5 w-3.5 text-success`}):_(T,{className:`h-3.5 w-3.5 text-danger`}),_(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&_(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&f(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[_(`dt`,{children:`Resolved level`}),_(`dd`,{className:`text-foreground`,children:t.level}),_(`dt`,{children:`Format sent`}),_(`dd`,{className:`text-foreground`,children:t.format}),_(`dt`,{children:`Attachments sent`}),_(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),_(`dt`,{children:`Actions sent`}),_(`dd`,{className:`text-foreground`,children:t.actionsSent}),_(`dt`,{children:`Truncated`}),_(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),_(`dt`,{children:`Dropped`}),_(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function K(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function q(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function J(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function Y(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}d();var X=[`notificationOutput`,`listTargets`],Z=[`notificationOutput`,`listTargetKinds`];function Q(){let r=v(),[i,a]=h({mode:`closed`}),[o,l]=h(null),u=m({queryKey:X,queryFn:()=>r.trpcClient.notificationOutput.listTargets.query({})}),d=m({queryKey:Z,queryFn:async()=>(await r.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),y=p(()=>d.data??[],[d.data]),S=p(()=>{let e=new Map;for(let t of y)e.set(t.kind,t);return e},[y]),w=g({mutationFn:e=>r.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:e.target.addonId,targetId:e.target.id,enabled:e.enabled}),onSuccess:()=>void u.refetch()}),T=g({mutationFn:e=>r.trpcClient.notificationOutput.deleteTarget.mutate({addonId:e.addonId,targetId:e.id}),onSuccess:()=>void u.refetch()}),A=o?S.get(o.kind):void 0;return f(O,{icon:C,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:f(s,{size:`sm`,type:`button`,onClick:()=>a({mode:`pick-kind`}),children:[_(x,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[u.isLoading&&_(`div`,{className:`flex items-center justify-center py-16`,children:_(D,{className:`h-6 w-6 animate-spin text-primary`})}),u.isError&&!u.isLoading&&_(e,{title:`Failed to load targets`,message:u.error instanceof Error?u.error.message:`Unknown error`,onRetry:()=>void u.refetch()}),!u.isLoading&&!u.isError&&(u.data??[]).length===0&&_(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(u.data??[]).length>0&&_(c,{children:_(`ul`,{className:`divide-y divide-border`,children:(u.data??[]).map(e=>{let r=S.get(e.kind);return f(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[_(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:r?.label??e.kind,children:r?.icon??`🔔`}),f(`div`,{className:`min-w-0 flex-1`,children:[_(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),_(`div`,{className:`text-[11px] text-foreground-subtle`,children:r?.label??e.kind})]}),!e.enabled&&_(t,{variant:`warning`,children:`disabled`}),_(n,{checked:e.enabled,onCheckedChange:t=>w.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),_(s,{size:`sm`,variant:`ghost`,type:`button`,disabled:!r,onClick:()=>l(e),title:`Test`,children:_(k,{className:`h-3.5 w-3.5`})}),_(s,{size:`sm`,variant:`ghost`,type:`button`,disabled:!r,onClick:()=>r&&a({mode:`form`,kind:r,target:e}),title:`Edit`,children:_(b,{className:`h-3.5 w-3.5`})}),_(s,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>T.mutate(e),title:`Delete`,children:_(E,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),i.mode===`pick-kind`&&_($,{kinds:y,onCancel:()=>a({mode:`closed`}),onPick:e=>a({mode:`form`,kind:e,target:null})}),i.mode===`form`&&_(ee,{kind:i.kind,target:i.target,onCancel:()=>a({mode:`closed`}),onSaved:()=>{a({mode:`closed`}),u.refetch()}}),o&&A&&_(W,{target:o,kind:A,open:!0,onClose:()=>l(null)})]})}function $({kinds:e,onPick:n,onCancel:r}){let i=p(()=>K(e),[e]);return f(c,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[_(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),_(s,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),i.length===0&&_(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),i.map(e=>f(`div`,{children:[_(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),_(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(r=>f(`button`,{type:`button`,onClick:()=>n(r),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[_(`span`,{className:`text-lg`,children:r.icon}),_(`span`,{className:`font-medium text-foreground`,children:r.label}),r.supportsDiscovery&&_(t,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${r.kind}`))})]},e.addonId))]})}function ee({kind:e,target:t,onSaved:n,onCancel:r}){let a=v(),o=p(()=>q(e.configSchema),[e.configSchema]),l=p(()=>t?.config??{},[t]),[u,d]=h(t?.name??e.label),[m,y]=h(()=>t?Y(t.config,o):{}),[b,x]=h(null),[C,w]=h(null),T=g({mutationFn:()=>a.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:m}),onSuccess:e=>x(e),onError:e=>w(e instanceof Error?e.message:`Discovery failed`)}),E=g({mutationFn:()=>{let n=J(m,l,o),r={id:t?.id??`${e.kind}-${Date.now()}`,name:u,kind:e.kind,addonId:e.addonId,enabled:t?.enabled??!0,config:n};return a.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:r})},onSuccess:n,onError:e=>w(e instanceof Error?e.message:`Save failed`)}),O=e=>{d(e.suggestedName),y(t=>({...t,...e.config})),x(null)};return f(c,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[_(`span`,{className:`text-lg`,children:e.icon}),t?`Edit ${t.name}`:`Add ${e.label} target`]}),_(s,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),C&&_(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:C}),f(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),_(`input`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,value:u,onChange:e=>d(e.target.value)})]}),e.supportsDiscovery&&f(`div`,{className:`space-y-2`,children:[f(s,{size:`sm`,variant:`outline`,type:`button`,disabled:T.isPending,onClick:()=>{w(null),T.mutate()},children:[T.isPending?_(D,{className:`h-3.5 w-3.5 animate-spin`}):_(S,{className:`h-3.5 w-3.5`}),`Discover`]}),b&&b.length===0&&_(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),b&&b.length>0&&_(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:b.map((e,t)=>f(`button`,{type:`button`,onClick:()=>O(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[_(`span`,{className:`text-foreground`,children:e.suggestedName}),_(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),o.length>0&&t&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Secret fields are hidden. Leave them blank to keep the stored value; type a new value to replace it.`}),_(i,{schema:e.configSchema,values:m,onChange:y}),f(`div`,{className:`flex justify-end gap-2`,children:[_(s,{variant:`secondary`,size:`sm`,type:`button`,onClick:r,children:`Cancel`}),f(s,{size:`sm`,type:`button`,disabled:E.isPending||u.trim().length===0,onClick:()=>{w(null),E.mutate()},children:[E.isPending&&_(D,{className:`h-3.5 w-3.5 animate-spin`}),t?`Save changes`:`Create target`]})]})]})}export{Q as NotificationTargetsPage,Q as default};
|
|
1
|
+
import{$i as e,Aa as t,Da as n,Ea as r,S as i,Sa as a,Ta as o,ja as s,ka as c,wa as l,xa as u}from"./src-3NEgkLWp.js";import{Q as d,S as f,W as p,a as m,q as h,t as g,x as _}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as v}from"./player-overlays-DACImv1W.js";import{t as y}from"./circle-check-big-uwi7M0FF.js";import{t as b}from"./pencil-GseW53Af.js";import{t as x}from"./plus-D1FskUey.js";import{t as S}from"./search-CvffVaTb.js";import{R as C,V as w,j as T,s as E,x as D}from"./index-CukLUOO-.js";import{t as O}from"./AdminPage-BwmGKnRf.js";var k=w(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]);d();var A=e=>typeof e==`string`&&e.length>0;function j(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function M(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function N(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];A(i)&&n.push({mediaType:r,url:i})}return n}function P(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=A(r.label),i=A(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function F(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=N(e,t.attachmentUrls),i=P(e,t.actions),a=e.ttl&&A(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:M(e,t.format),priority:I(t.priority),...A(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&A(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&A(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...A(t.tag)?{tag:t.tag}:{}}}function I(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function L(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function R(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var z={image:`https://example.com/sample.jpg`,video:`https://example.com/sample.mp4`,gif:`https://example.com/sample.gif`,audio:`https://example.com/sample.mp3`,icon:`https://example.com/icon.png`};function B(e,t){let n=R(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=L(e);return{...n,body:`Critical test notification`,priority:5,level:t?.id??``}}case`everything`:{let t={},n=0;for(let r of e.attachments.mediaTypes){if(n>=e.attachments.max)break;t[r]=z[r],n+=1}let r=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`https://example.com/action/${t+1}`}));return{level:``,priority:4,format:e.format.includes(`markdown`)?`markdown`:e.format.includes(`html`)?`html`:e.format[0]??`text`,title:`Everything the kind supports`,body:`This sample fills every control the kind advertises.`,attachmentUrls:t,actions:r,clickUrl:e.clickUrl?`https://example.com/open`:``,sound:e.sound?`default`:``,ttl:e.ttl?`3600`:``,tag:`camstack-test`}}}}var V=[{id:`minimal`,label:`Minimal (body only)`},{id:`everything`,label:`Everything supported`},{id:`overflow`,label:`Overflow`},{id:`critical`,label:`Critical`}],H=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,U=`block text-[11px] font-medium text-foreground mb-1`;function W({target:e,kind:n,open:i,onClose:c}){let d=v(),m=p(()=>j(n.caps),[n.caps]),[y,b]=h(()=>R(n.caps)),[x,S]=h(null),C=p(()=>F(n.caps,y),[n.caps,y]),w=y.body.length,T=w>m.bodyMaxLen,E=e=>b(t=>({...t,...e})),O=g({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:F(n.caps,y)}),onMutate:()=>S(null),onSuccess:e=>S(e),onError:e=>S({success:!1,error:e instanceof Error?e.message:`Test failed`})}),A=e=>{b(B(n.caps,e)),S(null)},M=(e,t,n)=>{let r=y.actions.length>0?[...y.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},E({actions:r})};return _(u,{open:i,onOpenChange:e=>!e&&c(),children:f(a,{width:`lg`,className:`!max-w-2xl`,children:[_(o,{children:f(r,{children:[`Test "`,e.name,`" (`,n.label,`)`]})}),f(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[_(`div`,{className:`flex flex-wrap gap-1.5`,children:V.map(e=>_(s,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>A(e.id),children:e.label},e.id))}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.levels.length>0&&f(`div`,{children:[_(`label`,{className:U,children:`Level`}),f(`select`,{className:H,value:y.level,onChange:e=>E({level:e.target.value}),children:[_(`option`,{value:``,children:`— derive from priority —`}),m.levels.map(e=>f(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=m.levels.find(e=>e.id===y.level);return e?f(`div`,{className:`mt-1 space-y-1`,children:[e.description&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),f(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&_(t,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&_(t,{variant:`info`,children:`silent`}),e.flags?.noPush&&_(t,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&f(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),f(`div`,{children:[f(`label`,{className:U,children:[`Priority (ordinal): `,y.priority]}),_(`input`,{type:`range`,min:1,max:5,step:1,value:y.priority,onChange:e=>E({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),m.formats.length>0&&f(`div`,{children:[_(`label`,{className:U,children:`Format`}),_(`div`,{className:`flex flex-wrap gap-2`,children:m.formats.map(e=>f(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[_(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:y.format===e,onChange:()=>E({format:e})}),e]},e))})]}),f(`div`,{children:[_(`label`,{className:U,children:`Title`}),_(`input`,{className:H,value:y.title,onChange:e=>E({title:e.target.value})})]}),f(`div`,{children:[f(`label`,{className:U,children:[`Body`,` `,f(`span`,{className:T?`text-danger`:`text-foreground-subtle`,children:[`(`,w,`/`,m.bodyMaxLen,T?` — overflow`:``,`)`]})]}),_(`textarea`,{className:`${H} min-h-[80px] resize-y`,value:y.body,onChange:e=>E({body:e.target.value})})]}),m.attachmentSlots.length>0&&f(`div`,{children:[f(`label`,{className:U,children:[`Attachments`,` `,f(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,m.attachmentMode,`, max `,m.attachmentMax,m.attachmentMaxBytes?`, ≤${Math.round(m.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),_(`div`,{className:`space-y-1.5`,children:m.attachmentSlots.map(e=>f(`div`,{className:`flex items-center gap-2`,children:[_(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),_(`input`,{className:H,placeholder:`${e} URL`,value:y.attachmentUrls[e]??``,onChange:t=>E({attachmentUrls:{...y.attachmentUrls,[e]:t.target.value}})})]},e))})]}),m.showActions&&f(`div`,{children:[f(`label`,{className:U,children:[`Actions (up to `,m.maxActions,`)`]}),_(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(m.maxActions,3)},(e,t)=>f(`div`,{className:`flex items-center gap-2`,children:[_(`input`,{className:H,placeholder:`label`,value:y.actions[t]?.label??``,onChange:e=>M(t,`label`,e.target.value)}),_(`input`,{className:H,placeholder:`url`,value:y.actions[t]?.url??``,onChange:e=>M(t,`url`,e.target.value)})]},t))})]}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.showClickUrl&&f(`div`,{children:[_(`label`,{className:U,children:`Click URL`}),_(`input`,{className:H,value:y.clickUrl,onChange:e=>E({clickUrl:e.target.value})})]}),m.showSound&&f(`div`,{children:[_(`label`,{className:U,children:`Sound`}),_(`input`,{className:H,value:y.sound,onChange:e=>E({sound:e.target.value})})]}),m.showTtl&&f(`div`,{children:[_(`label`,{className:U,children:`TTL (seconds)`}),_(`input`,{className:H,type:`number`,value:y.ttl,onChange:e=>E({ttl:e.target.value})})]}),m.showTag&&f(`div`,{children:[_(`label`,{className:U,children:`Tag`}),_(`input`,{className:H,value:y.tag,onChange:e=>E({tag:e.target.value})})]})]}),x&&_(G,{result:x}),f(`details`,{className:`text-[10px]`,children:[_(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),_(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(C,null,2)})]})]}),f(l,{children:[_(s,{variant:`secondary`,size:`sm`,type:`button`,onClick:c,children:`Close`}),f(s,{size:`sm`,type:`button`,disabled:O.isPending||y.body.length===0,onClick:()=>O.mutate(),children:[O.isPending?_(D,{className:`h-3.5 w-3.5 animate-spin`}):_(k,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function G({result:e}){let t=e.renderedAs;return f(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[f(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?_(y,{className:`h-3.5 w-3.5 text-success`}):_(T,{className:`h-3.5 w-3.5 text-danger`}),_(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&_(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&f(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[_(`dt`,{children:`Resolved level`}),_(`dd`,{className:`text-foreground`,children:t.level}),_(`dt`,{children:`Format sent`}),_(`dd`,{className:`text-foreground`,children:t.format}),_(`dt`,{children:`Attachments sent`}),_(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),_(`dt`,{children:`Actions sent`}),_(`dd`,{className:`text-foreground`,children:t.actionsSent}),_(`dt`,{children:`Truncated`}),_(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),_(`dt`,{children:`Dropped`}),_(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function K(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function q(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function J(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function Y(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}d();var X=[`notificationOutput`,`listTargets`],Z=[`notificationOutput`,`listTargetKinds`];function Q(){let r=v(),[i,a]=h({mode:`closed`}),[o,l]=h(null),u=m({queryKey:X,queryFn:()=>r.trpcClient.notificationOutput.listTargets.query({})}),d=m({queryKey:Z,queryFn:async()=>(await r.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),y=p(()=>d.data??[],[d.data]),S=p(()=>{let e=new Map;for(let t of y)e.set(t.kind,t);return e},[y]),w=g({mutationFn:e=>r.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:e.target.addonId,targetId:e.target.id,enabled:e.enabled}),onSuccess:()=>void u.refetch()}),T=g({mutationFn:e=>r.trpcClient.notificationOutput.deleteTarget.mutate({addonId:e.addonId,targetId:e.id}),onSuccess:()=>void u.refetch()}),A=o?S.get(o.kind):void 0;return f(O,{icon:C,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:f(s,{size:`sm`,type:`button`,onClick:()=>a({mode:`pick-kind`}),children:[_(x,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[u.isLoading&&_(`div`,{className:`flex items-center justify-center py-16`,children:_(D,{className:`h-6 w-6 animate-spin text-primary`})}),u.isError&&!u.isLoading&&_(e,{title:`Failed to load targets`,message:u.error instanceof Error?u.error.message:`Unknown error`,onRetry:()=>void u.refetch()}),!u.isLoading&&!u.isError&&(u.data??[]).length===0&&_(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(u.data??[]).length>0&&_(c,{children:_(`ul`,{className:`divide-y divide-border`,children:(u.data??[]).map(e=>{let r=S.get(e.kind);return f(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[_(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:r?.label??e.kind,children:r?.icon??`🔔`}),f(`div`,{className:`min-w-0 flex-1`,children:[_(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),_(`div`,{className:`text-[11px] text-foreground-subtle`,children:r?.label??e.kind})]}),!e.enabled&&_(t,{variant:`warning`,children:`disabled`}),_(n,{checked:e.enabled,onCheckedChange:t=>w.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),_(s,{size:`sm`,variant:`ghost`,type:`button`,disabled:!r,onClick:()=>l(e),title:`Test`,children:_(k,{className:`h-3.5 w-3.5`})}),_(s,{size:`sm`,variant:`ghost`,type:`button`,disabled:!r,onClick:()=>r&&a({mode:`form`,kind:r,target:e}),title:`Edit`,children:_(b,{className:`h-3.5 w-3.5`})}),_(s,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>T.mutate(e),title:`Delete`,children:_(E,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),i.mode===`pick-kind`&&_($,{kinds:y,onCancel:()=>a({mode:`closed`}),onPick:e=>a({mode:`form`,kind:e,target:null})}),i.mode===`form`&&_(ee,{kind:i.kind,target:i.target,onCancel:()=>a({mode:`closed`}),onSaved:()=>{a({mode:`closed`}),u.refetch()}}),o&&A&&_(W,{target:o,kind:A,open:!0,onClose:()=>l(null)})]})}function $({kinds:e,onPick:n,onCancel:r}){let i=p(()=>K(e),[e]);return f(c,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[_(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),_(s,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),i.length===0&&_(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),i.map(e=>f(`div`,{children:[_(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),_(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(r=>f(`button`,{type:`button`,onClick:()=>n(r),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[_(`span`,{className:`text-lg`,children:r.icon}),_(`span`,{className:`font-medium text-foreground`,children:r.label}),r.supportsDiscovery&&_(t,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${r.kind}`))})]},e.addonId))]})}function ee({kind:e,target:t,onSaved:n,onCancel:r}){let a=v(),o=p(()=>q(e.configSchema),[e.configSchema]),l=p(()=>t?.config??{},[t]),[u,d]=h(t?.name??e.label),[m,y]=h(()=>t?Y(t.config,o):{}),[b,x]=h(null),[C,w]=h(null),T=g({mutationFn:()=>a.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:m}),onSuccess:e=>x(e),onError:e=>w(e instanceof Error?e.message:`Discovery failed`)}),E=g({mutationFn:()=>{let n=J(m,l,o),r={id:t?.id??`${e.kind}-${Date.now()}`,name:u,kind:e.kind,addonId:e.addonId,enabled:t?.enabled??!0,config:n};return a.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:r})},onSuccess:n,onError:e=>w(e instanceof Error?e.message:`Save failed`)}),O=e=>{d(e.suggestedName),y(t=>({...t,...e.config})),x(null)};return f(c,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[_(`span`,{className:`text-lg`,children:e.icon}),t?`Edit ${t.name}`:`Add ${e.label} target`]}),_(s,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),C&&_(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:C}),f(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),_(`input`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,value:u,onChange:e=>d(e.target.value)})]}),e.supportsDiscovery&&f(`div`,{className:`space-y-2`,children:[f(s,{size:`sm`,variant:`outline`,type:`button`,disabled:T.isPending,onClick:()=>{w(null),T.mutate()},children:[T.isPending?_(D,{className:`h-3.5 w-3.5 animate-spin`}):_(S,{className:`h-3.5 w-3.5`}),`Discover`]}),b&&b.length===0&&_(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),b&&b.length>0&&_(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:b.map((e,t)=>f(`button`,{type:`button`,onClick:()=>O(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[_(`span`,{className:`text-foreground`,children:e.suggestedName}),_(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),o.length>0&&t&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Secret fields are hidden. Leave them blank to keep the stored value; type a new value to replace it.`}),_(i,{schema:e.configSchema,values:m,onChange:y}),f(`div`,{className:`flex justify-end gap-2`,children:[_(s,{variant:`secondary`,size:`sm`,type:`button`,onClick:r,children:`Cancel`}),f(s,{size:`sm`,type:`button`,disabled:E.isPending||u.trim().length===0,onClick:()=>{w(null),E.mutate()},children:[E.isPending&&_(D,{className:`h-3.5 w-3.5 animate-spin`}),t?`Save changes`:`Create target`]})]})]})}export{Q as NotificationTargetsPage,Q as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Aa as e,Br as t,C as n,Ci as r,Di as i,Ei as a,Fr as o,Gr as s,Hr as c,Ia as l,Jr as u,Kr as d,Lr as f,Qi as p,Qr as m,Ra as h,Rr as g,T as _,Ti as v,Ur as y,Vr as b,Xr as x,Zr as S,_ as C,aa as w,ai as T,bi as E,ca as D,ci as O,da as k,di as A,ei as j,fi as M,ia as N,it as P,ki as ee,na as F,oi as I,ot as te,pi as ne,qr as re,ra as ie,ri as ae,sa as oe,si as se,ti as ce,ua as le,ui as ue,vi as de,xi as fe,yi as pe,zr as me}from"./src-CjIUerPQ.js";import{I as he,K as ge,Q as L,S as R,T as _e,W as z,a as ve,b as B,o as V,q as H,x as U,z as W}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{L as G,R as ye}from"./src-Ce30zKhx.js";import{p as be}from"./player-overlays-Bhh-T-qH.js";import{t as xe}from"./download-BK8xwPVQ.js";import{i as Se,n as Ce,r as we,t as Te}from"./AddLocationWizard-CnG4Jw4r.js";import{n as Ee,r as De,t as Oe}from"./zap-CVw3MjTh.js";import{t as ke}from"./pencil-DiE1Fpdo.js";import{t as Ae}from"./plus-D0PsZI7U.js";import{t as je}from"./refresh-cw-t853aWpn.js";import{t as Me}from"./search-CzNcbSQJ.js";import{t as Ne}from"./server-DrYKV5GK.js";import{t as Pe}from"./square-check-big-sMZXYHT_.js";import{t as Fe}from"./square-CAY4kQy9.js";import{A as Ie,F as Le,G as Re,M as ze,P as Be,V as Ve,i as He,j as Ue,k as K,o as We,s as Ge,w as Ke,x as q}from"./index-dp4qM2Ld.js";import{t as qe}from"./AdminPage-BwmGKnRf.js";import{r as Je}from"./useDevice-CcTWAItl.js";import{t as J}from"./useEventInvalidation-CnMgTDMe.js";import{a as Ye,c as Y,i as Xe,l as Ze,n as Qe,o as X,r as $e,s as et,t as tt}from"./build-cluster-graph-CHCjyAD0.js";import{n as nt}from"./format-size-CO9d3C3-.js";import{t as rt}from"./NodeAddonsSettingsPanel-Dt0jm53X.js";var it=Ve(`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`}]]),at=Ve(`film`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M7 3v18`,key:`bbkbws`}],[`path`,{d:`M3 7.5h4`,key:`zfgn84`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`path`,{d:`M3 16.5h4`,key:`1230mu`}],[`path`,{d:`M17 3v18`,key:`in4fa5`}],[`path`,{d:`M17 7.5h4`,key:`myr1c1`}],[`path`,{d:`M17 16.5h4`,key:`go4c1d`}]]),ot=Ve(`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=Ve(`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`}]]);L();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{decode:ut(lt(e,`decode`),t),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:t,onSelect:n,refreshToken:r}){let{data:i}=o(void 0),{data:a}=T(void 0),{data:s}=I(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=i??[],u=l.filter(e=>e.isOnline).length,d=l.filter(e=>!e.isOnline).length;return R(`div`,{className:`flex flex-col h-full`,children:[R(`button`,{type:`button`,onClick:()=>n(hr),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${t===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[U(Ke,{className:`h-4 w-4 flex-shrink-0`}),R(`div`,{className:`min-w-0 flex-1`,children:[U(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),U(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),U(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(r=>{let i=t===r.id,a=c.get(r.id)??0,o=r.isHub?Ne:K,l=ft(s,r.id,r.isHub),u=r.isOnline?null:h(Ze(r.lastSeen));return R(`button`,{type:`button`,onClick:()=>n(r.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${i?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${r.isOnline?``:` opacity-60`}`,children:[U(o,{className:`h-4 w-4 flex-shrink-0`}),R(`div`,{className:`min-w-0 flex-1`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`text-xs font-semibold truncate`,children:r.name}),r.isHub&&U(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!r.isOnline&&U(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),r.isOnline&&U(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),R(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[R(`span`,{children:[r.cpuCores,` cores`]}),U(`span`,{children:`•`}),R(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a>0&&R(B,{children:[U(`span`,{children:`•`}),R(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[U(Ee,{className:`h-2.5 w-2.5`}),a]})]}),!r.isOnline&&R(B,{children:[U(`span`,{children:`•`}),R(`span`,{className:`text-destructive`,children:[`offline`,u===null?``:` · ${u}`]})]})]}),R(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[U(e,{variant:l.decode?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.decode?`Decode: enabled`:`Decode: not enabled (agent capability)`,children:`Dec`}),U(e,{variant:l.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),U(e,{variant:l.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},r.id)})}),R(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[R(`span`,{children:[u,` online`]}),d>0&&R(`span`,{className:`text-destructive`,children:[d,` offline`]})]})]})}function mt({nodeId:e,refreshToken:t}){let{data:n}=o(void 0),r=n?.find(t=>t.id===e),i=ie(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?R(`div`,{className:`px-6 py-4 border-b border-border`,children:[R(`div`,{className:`flex items-center gap-2 mb-1`,children:[U(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?U(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):U(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&U(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),R(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[U(`span`,{children:r.cpuModel??`CPU`}),U(`span`,{children:`•`}),R(`span`,{children:[r.cpuCores,` cores`]}),U(`span`,{children:`•`}),R(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),i&&R(B,{children:[U(`span`,{children:`•`}),R(`span`,{children:[i.attachedCameras,` cameras (`,i.activeCameras,` active)`]}),U(`span`,{children:`•`}),R(`span`,{children:[i.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),U(`span`,{children:`•`}),R(`span`,{children:[`queue `,i.queueDepthTotal]}),i.hardware.hasGpu&&R(B,{children:[U(`span`,{children:`•`}),U(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):U(`div`,{className:`px-6 py-4 border-b border-border`,children:R(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function ht({refreshToken:e,nodeId:t}){let[n,r]=H(new Map),{nodes:i}=F();w(`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}=m(void 0),o=z(()=>{let e=new Map;for(let t of a??[])e.set(t.nodeId,t.deviceCount);return e},[a]),s=z(()=>{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=z(()=>{let e=new Map;for(let t of i)e.set(t.id,t.shortName);return e},[i]),l=z(()=>{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 R(`div`,{className:`@container/liveload`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),R(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[U(Z,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),U(Z,{label:`Cameras`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),U(Z,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),U(Z,{label:`Queue`,value:e?String(e.queueDepth):`—`}),U(Z,{label:`Audio`,value:String(o.get(t)??`—`)})]})]})}let u=[...s.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return R(`div`,{className:`@container/liveload`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),R(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[U(Z,{label:`Total agents`,value:`${l.onlineAgents}/${l.totalAgents}`}),U(Z,{label:`Cameras`,value:`${l.activeCameras}/${l.attachedCameras}`}),U(Z,{label:`Total FPS`,value:l.totalFps.toFixed(1)}),U(Z,{label:`Avg inference ms`,value:l.avgInferenceTimeMs.toFixed(0)}),U(Z,{label:`Queue depth`,value:String(l.queueDepth)})]}),U(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:R(`table`,{className:`w-full text-xs min-w-[480px]`,children:[U(`thead`,{className:`bg-surface`,children:R(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[U(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),U(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),U(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),U(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),U(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),U(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),R(`tbody`,{children:[u.map(([e,t])=>R(`tr`,{className:`border-t border-border`,children:[U(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:c.get(e)??e}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:o.get(e)??`—`})]},e)),u.length===0&&U(`tr`,{children:U(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function Z({label:e,value:t}){return R(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[U(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),U(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}L();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:K,decoder:at,audio:De},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=V(),[i,a]=H(null),[o,c]=H(null),[l,u]=H(new Map);J([`pipelineOrchestrator`,`getPipelineAssignments`],_t),J([`pipelineOrchestrator`,`getDecoderAssignments`],_t),J([`pipelineOrchestrator`,`getAudioAssignments`],_t);let{data:f}=T(void 0),{data:p}=ae(void 0),{data:m}=S(void 0),{nodes:h}=F(),{data:g}=Je();w(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&u(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),W(()=>{if(l.size===0)return;let e=setInterval(()=>{u(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)},[l.size]);let v=z(()=>{let e=new Map;for(let t of g??[])e.set(t.id,t.name);return e},[g]),y=z(()=>{let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:v.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:e===`cluster`?!0:i.agentNodeId===t,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``}})}for(let i of p??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,decoder:{active:e===`cluster`?!0:i.decoderNodeId===t,pinned:i.pinned,nodeId:i.decoderNodeId,reason:i.reason??``}})}for(let i of m??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,audio:{active:e===`cluster`?!0:i.nodeId===t,pinned:i.pinned,nodeId:i.nodeId,reason:`capacity`}})}let i=[...n.values()];return e===`agent`&&(i=i.filter(e=>e.pipeline.active||e.decoder.active||e.audio.active)),i.sort((e,t)=>e.deviceId-t.deviceId),i},[f,p,m,v,e,t]),b=z(()=>(h??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[h]),x=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})},C=re({onSuccess:x}),D=E({onSuccess:x}),O=d({onSuccess:x}),k=pe({onSuccess:x}),A=s({onSuccess:x}),j=de({onSuccess:x}),M=(e,t,n)=>{t===`pipeline`?C.mutate({deviceId:e,agentNodeId:n}):t===`decoder`?O.mutate({deviceId:e,nodeId:n}):A.mutate({deviceId:e,nodeId:n}),a(null)},N=(e,t)=>{t===`pipeline`?D.mutate({deviceId:e}):t===`decoder`?k.mutate({deviceId:e}):j.mutate({deviceId:e}),a(null)};return U(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:R(`table`,{className:`w-full text-xs min-w-[640px]`,children:[U(`thead`,{className:`bg-surface`,children:R(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&U(`th`,{className:`w-6`}),U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?R(B,{children:[U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):R(B,{children:[U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Pipeline`}),U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Decoder`}),U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Audio`})]}),U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Status`})]})}),R(`tbody`,{children:[y.map(t=>{let r=l.get(t.deviceId),s=o===t.deviceId;return R(_e.Fragment,{children:[R(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&U(`td`,{className:`px-2 py-2 align-middle`,children:U(`button`,{type:`button`,onClick:()=>c(s?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":s?`Collapse broker details`:`Expand broker details`,children:U(s?Be:ze,{className:`h-3.5 w-3.5`})})}),R(`td`,{className:`px-3 py-2 align-middle`,children:[U(`div`,{className:`text-foreground font-medium leading-tight`,children:t.deviceName}),R(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?R(B,{children:[U(`td`,{className:`px-3 py-2 align-middle`,children:U(xt,{state:t.pipeline,onlineNodes:b,pending:C.isPending||D.isPending,onChange:e=>{e===`auto`?N(t.deviceId,`pipeline`):M(t.deviceId,`pipeline`,e)}})}),U(`td`,{className:`px-3 py-2 align-middle`,children:U(St,{state:t.pipeline})})]}):R(B,{children:[U(Ct,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:b,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=>M(t.deviceId,`pipeline`,e),onUnpin:()=>N(t.deviceId,`pipeline`)}),U(Ct,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:b,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`decoder`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`decoder`?null:{deviceId:t.deviceId,role:`decoder`}),onCloseMenu:()=>a(null),onMove:e=>M(t.deviceId,`decoder`,e),onUnpin:()=>N(t.deviceId,`decoder`)}),U(Ct,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:b,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=>M(t.deviceId,`audio`,e),onUnpin:()=>N(t.deviceId,`audio`)})]}),U(`td`,{className:`px-3 py-2 align-middle`,children:U(Et,{snap:r})})]}),s&&!n&&R(`tr`,{className:`bg-surface/50`,children:[U(`td`,{}),U(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2`,children:U(_,{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)}),y.length===0&&U(`tr`,{children:U(`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({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 R(`select`,{value:i,disabled:n,"aria-label":`Pipeline placement pin`,onChange:e=>r(e.target.value),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[U(`option`,{value:`auto`,children:`Auto`}),a.map(e=>R(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function St({state:e}){return!e.active||!e.nodeId?U(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`}):R(`div`,{className:`flex flex-col leading-tight`,children:[U(`span`,{className:`font-mono text-[11px] text-foreground`,children:e.nodeId}),U(`span`,{className:e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`,children:e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`})]})}function Ct({role:e,state:t,mode:n,onlineNodes:r,isMenuOpen:i,onToggleMenu:a,onCloseMenu:o,onMove:s,onUnpin:c}){let l=vt[e],u=r.filter(e=>e.id!==(t.nodeId??``)),d=(t.active||n===`cluster`)&&(u.length>0||t.pinned);return R(`td`,{className:`px-3 py-2 align-middle relative`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(n===`agent`?wt:Tt,{state:t,Icon:l}),U(`div`,{className:`ml-auto`,children:d&&U(`button`,{type:`button`,onClick:a,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${yt[e]} actions`,children:U(it,{className:`h-3 w-3 text-foreground-subtle`})})})]}),i&&d&&U(Dt,{title:yt[e],targets:u,pinned:t.pinned,onMove:s,onUnpin:c,onClose:o})]})}function wt({state:e,Icon:t}){return R(`div`,{className:`flex items-center gap-1.5`,children:[U(e.active?Pe:Fe,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),U(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&U(st,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Tt({state:e,Icon:t}){return!e.active||!e.nodeId?R(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[U(t,{className:`h-3 w-3`}),U(`span`,{className:`text-[10px] italic`,children:`—`})]}):R(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[U(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),R(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[U(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),U(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?R(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[U(st,{className:`h-2.5 w-2.5`}),` manual`]}):R(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}function Et({snap:e}){if(!e)return U(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:i,configuredFps:a,droppedFrames:o}=e.metrics,s=l(t);return R(`div`,{className:`flex flex-col gap-0.5 font-mono text-[10px] tabular-nums leading-tight`,children:[R(`span`,{className:`inline-flex items-center gap-1 ${s.textColor}`,children:[U(C,{phase:t,className:`h-2.5 w-2.5`}),U(`span`,{className:`font-semibold uppercase tracking-wider`,children:s.label})]}),R(`span`,{className:`text-foreground-subtle`,children:[U(`span`,{className:`text-foreground`,children:n.toFixed(1)}),R(`span`,{children:[`/`,a.toFixed(0),` fps`]})]}),R(`span`,{className:`text-foreground-subtle`,children:[U(`span`,{className:`text-foreground`,children:r.toFixed(0)}),U(`span`,{children:` ms`}),i>0&&R(`span`,{className:`text-warning ml-1`,children:[`q`,i]})]}),R(`span`,{className:o>0?`text-warning`:`text-foreground-subtle`,children:[`drops `,U(`span`,{className:`text-foreground`,children:o})]})]})}function Dt({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=ge(null);return W(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),R(`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:[U(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&U(`div`,{className:`py-1`,children:t.map(e=>R(`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&&R(`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&&U(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Ot({nodeId:e,refreshToken:t}){return R(`div`,{className:`space-y-6`,children:[U(ht,{refreshToken:t,nodeId:e}),R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),R(`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.`]})]}),U(bt,{mode:`agent`,nodeId:e,compact:!0})]})}L();function kt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function At({nodeId:e,refreshToken:t}){let n=V(),i=c({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:a}=y({nodeId:e}),o=ie(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??a??null,s=o===null;J([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:l}=r({nodeId:e}),{values:u}=N(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),d=z(()=>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?`)||i.mutate({nodeId:e,engine:t,force:n.length>0})};return R(`div`,{className:`space-y-6`,children:[R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),R(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(o??[]).length,` engine(s) resident in RAM. `,(l??[]).length,` `,`camera(s) attached, `,d,` actively dispatching frames. Refreshes every 5s.`]})]}),U(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:R(`table`,{className:`w-full text-xs min-w-[640px]`,children:[U(`thead`,{className:`bg-surface`,children:R(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[U(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),U(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),U(`th`,{className:`text-left px-3 py-2`,children:`Models`}),U(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),U(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),U(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),U(`th`,{className:`w-20`})]})}),R(`tbody`,{children:[s&&U(`tr`,{children:U(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!s&&(o??[]).map(e=>{let t=e.kind===`warm-override`;return R(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:``}`,children:[U(`td`,{className:`px-3 py-2`,children:R(`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`:`bg-success/15 text-success`}`,children:[U(t?ot:K,{className:`h-3 w-3`}),t?`warm`:`runtime`]})}),U(`td`,{className:`px-3 py-2`,children:R(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[U(Oe,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),U(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?U(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):U(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>U(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),U(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),U(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?U(`span`,{className:`text-foreground-subtle`,children:kt(e.idleMs,e.idleTtlMs)}):U(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(l??[]).length}),U(`td`,{className:`px-3 py-2 text-right`,children:R(`button`,{type:`button`,disabled:i.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:[U(Ge,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!s&&(o??[]).length===0&&U(`tr`,{children:U(`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.`})})]})]})}),R(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[U(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,U(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`]}),i.isError&&R(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,i.error instanceof Error?i.error.message:`unknown`]})]})}L();var jt=new Set(ye);function Mt(e){return jt.has(e)}function Nt(e,t,n){return`${e}/${t}/${n}`}function Pt(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function Ft(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 It(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 Lt({addonId:e,model:t,format:n,isActive:r,progress:i,errorMsg:a,onDownload:o,onDelete:s}){let c=t.formats[n];return c?R(`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:[U(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),R(`div`,{className:`flex-1 min-w-0`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),R(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&R(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[U(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:U(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),R(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),U(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:nt(c.sizeMB)}),a&&R(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[U(Ue,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?R(`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?U(q,{className:`h-3 w-3 animate-spin`}):U(Ge,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):R(`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?U(q,{className:`h-3 w-3 animate-spin`}):U(xe,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function Rt({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=H(!1);return R(`div`,{className:`relative`,children:[R(`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:[U(K,{className:`h-4 w-4 text-primary shrink-0`}),R(`div`,{className:`flex-1 min-w-0`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`text-sm font-medium text-foreground`,children:Pt(n)}),Q(n)===Q(t)&&U(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),U(`div`,{className:`text-[10px] text-foreground-subtle`,children:Ft(n)})]}),U(Be,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&U(`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 R(`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:[U(K,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),R(`div`,{className:`flex-1`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:Pt(e)}),o&&U(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),U(`div`,{className:`text-[10px] text-foreground-subtle`,children:Ft(e)})]}),i&&U(Ie,{className:`h-4 w-4 text-primary shrink-0`})]},Q(e))})})]})}function zt({embedded:e=!1,nodeId:n}={}){let r=V(),i=n??`hub`,[a,o]=H(null),[s,c]=H(new Set),[l,u]=H(new Map),[d,p]=H(new Map),[m,h]=H(``),{data:_=[]}=me({nodeId:i}),v=_.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:y}=b({nodeId:i}),x=y,{data:S,isLoading:C}=t({nodeId:i}),T=g(),E=f();w(`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 D=x??{runtime:`node`,backend:`cpu`,format:`onnx`},O=v.find(e=>e.format===a)??D,k=O.format,A=S?.slots??[],j=A.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(e=>e.formats[k]!==void 0)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),M=It(j,k),N=he(async(e,t,n)=>{if(!Mt(n))return;let a=Nt(e,t,n);c(e=>new Set([...e,a])),p(e=>{let t=new Map(e);return t.delete(a),t});try{await T.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(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})}},[T,r,i]),P=he(async(e,t,n)=>{if(!Mt(n))return;let a=Nt(e,t,n);c(e=>new Set([...e,a])),p(e=>{let t=new Map(e);return t.delete(a),t});try{await E.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(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})}},[E,r,i]),ee=he(e=>{o(e.format)},[]),F=m.trim()?j.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):j,I=R(B,{children:[C&&U(`div`,{className:`flex items-center justify-center py-16`,children:U(q,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!C&&A.length===0&&R(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[U(Se,{className:`h-8 w-8 mb-3 opacity-30`}),U(`span`,{className:`text-sm`,children:`No pipeline steps available`}),U(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!C&&A.length>0&&R(B,{children:[U(Rt,{engines:v,activeEngine:D,viewEngine:O,onSelect:ee}),R(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[R(`span`,{children:[U(`span`,{className:`font-semibold text-foreground tabular-nums`,children:M.total}),U(`span`,{className:`ml-1`,children:`compatible models`})]}),U(`span`,{className:`text-border`,children:`|`}),R(`span`,{children:[U(`span`,{className:`font-semibold text-success tabular-nums`,children:M.downloaded}),U(`span`,{className:`ml-1`,children:`downloaded`})]}),U(`span`,{className:`text-border`,children:`|`}),R(`span`,{className:`tabular-nums`,children:[nt(M.downloadedSizeMB),U(`span`,{className:`ml-1`,children:`on disk`})]})]}),M.total>5&&R(`div`,{className:`relative`,children:[U(Me,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),U(`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`})]}),F.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[k]?.downloaded).length,0);return R(`div`,{children:[R(`div`,{className:`flex items-center gap-2 mb-2`,children:[U(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),U(`div`,{className:`flex-1 h-px bg-border`}),R(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),U(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=Nt(e.id,t.id,k);return U(Lt,{addonId:e.id,model:t,format:k,isActive:s.has(n),progress:l.get(t.id),errorMsg:d.get(n),onDownload:()=>N(e.id,t.id,k),onDelete:()=>P(e.id,t.id,k)},`${e.id}/${t.id}`)}))})]},e.id)}),F.length===0&&U(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:m.trim()?R(B,{children:[`No models matching “`,m,`”`]}):R(B,{children:[`No models available for `,Pt(O),` format`]})})]})]});return e?U(`div`,{className:`space-y-4`,children:I}):U(qe,{children:I})}function Bt({nodeId:e,refreshToken:t}){return U(zt,{embedded:!0,nodeId:e})}var Vt=[{concern:`pipeline`,label:`Pipeline`,advisory:!1},{concern:`audio`,label:`Audio`,advisory:!1},{concern:`decode`,label:`Decode`,advisory:!0,advisoryNote:`Advisory: decode currently runs co-located with the stream source (hub). Pins are stored and take effect with Phase-2 stream load-balancing.`}];function Ht(e,t){return e.filter(e=>e.currentNodeId!==t)}var Ut=`This node is not decoder-enabled (enabledDecoderNodes). Pinning detection here strands frames (0 fps) until frame-source-aware placement ships. Enable decode on this node first, or pick a decoder-enabled node.`;function Wt(e,t,n){return t.includes(e)?{verdict:`ok`}:n?{verdict:`warn`,reason:Ut}:{verdict:`block`,reason:Ut}}L();var Gt=`pipeline-orchestrator`,Kt=`enabledDecoderNodes`;function qt(e,t){if(!e||typeof e!=`object`)return;let n=e.sections;if(Array.isArray(n))for(let e of n){if(!e||typeof e!=`object`)continue;let n=e.fields;if(Array.isArray(n))for(let e of n){if(!e||typeof e!=`object`)continue;let n=e;if(n.key!==t)continue;let r=n.value;return Array.isArray(r)&&r.every(e=>typeof e==`string`)?r:void 0}}}function Jt({nodeId:e,nodeName:t,concern:n,open:r,onClose:i}){let a=V(),o=Je(),c=T(void 0),l=ae(void 0),u=S(void 0),f=P({addonId:Gt}),p=re(),m=d(),h=s(),[g,_]=H(new Set),[v,y]=H(!1),[b,x]=H(null),[C,w]=H([]),[E,D]=H(null),O=Vt.find(e=>e.concern===n),k=z(()=>{let e=new Map;if(n===`pipeline`)for(let t of c.data??[])e.set(t.deviceId,t.agentNodeId);else if(n===`decode`)for(let t of l.data??[])e.set(t.deviceId,t.decoderNodeId);else for(let t of u.data??[])e.set(t.deviceId,t.nodeId);return e},[n,c.data,l.data,u.data]),A=z(()=>(o.data??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,currentNodeId:k.get(e.id)??null})),[o.data,k]),j=z(()=>Ht(A,e),[A,e]),M=qt(f.data,Kt),N=n===`pipeline`?Wt(e,M??[],!1):{verdict:`ok`},[ee,F]=H(!1);if(!r)return null;let I=N.verdict===`block`,te=N.verdict===`warn`&&!ee,ne=g.size>0&&!v&&!I&&!te,ie=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},oe=j.length>0&&j.every(e=>g.has(e.deviceId)),se=()=>{_(oe?new Set:new Set(j.map(e=>e.deviceId)))},ce=async t=>{n===`pipeline`?await p.mutateAsync({deviceId:t,agentNodeId:e}):n===`decode`?await m.mutateAsync({deviceId:t,nodeId:e}):await h.mutateAsync({deviceId:t,nodeId:e})},le=new Map(A.map(e=>[e.deviceId,e.name]));return R(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[U(`div`,{className:`absolute inset-0 bg-black/60`,onClick:i}),R(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col h-[80vh] rounded-xl border border-border bg-background shadow-2xl`,children:[R(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[R(`div`,{className:`min-w-0`,children:[R(`h2`,{className:`text-sm font-semibold text-foreground`,children:[`Batch assign `,O?.label??n,` → `,t]}),R(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:[`Pick the cameras whose `,O?.label.toLowerCase()??n,` should run on this node.`]})]}),U(`button`,{type:`button`,onClick:i,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,"aria-label":`Close`,children:U(He,{className:`h-4 w-4`})})]}),R(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[O?.advisory&&O.advisoryNote&&U(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 px-3 py-2 shrink-0`,children:R(`div`,{className:`flex items-start gap-2`,children:[U(We,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),U(`p`,{className:`text-[11px] text-warning`,children:O.advisoryNote})]})}),N.verdict!==`ok`&&U(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 shrink-0`,children:R(`div`,{className:`flex items-start gap-2`,children:[U(We,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),R(`div`,{className:`min-w-0`,children:[U(`p`,{className:`text-[11px] text-destructive`,children:N.reason}),N.verdict===`warn`&&R(`label`,{className:`mt-1 flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[U(`input`,{type:`checkbox`,checked:ee,onChange:e=>F(e.target.checked),className:`accent-primary`}),`I understand — assign anyway`]})]})]})}),j.length>0&&R(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle shrink-0`,children:[U(`input`,{type:`checkbox`,"aria-label":`Select all`,checked:oe,onChange:se,className:`accent-primary`}),`Select all (`,j.length,`)`]}),U(`div`,{className:`flex-1 min-h-0 overflow-y-auto rounded-lg border border-border divide-y divide-border`,children:j.length===0?R(`div`,{className:`px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:[`No eligible cameras — all cameras are already assigned to `,t,`.`]}):j.map(e=>R(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground hover:bg-surface-hover cursor-pointer`,children:[U(`input`,{type:`checkbox`,"aria-label":`Select ${e.name}`,checked:g.has(e.deviceId),onChange:()=>ie(e.deviceId),className:`accent-primary`}),U(`span`,{className:`truncate`,children:e.name}),e.currentNodeId&&R(`span`,{className:`ml-auto text-[10px] text-foreground-subtle shrink-0`,children:[`on `,e.currentNodeId]})]},e.deviceId))}),(E!==null||C.length>0)&&R(`div`,{className:`space-y-1 text-[10px] shrink-0`,children:[E!==null&&E>0&&R(`p`,{className:`text-success`,children:[`Assigned `,E,` camera(s) to `,t,`.`]}),C.map(e=>R(`p`,{className:`text-destructive`,children:[e.name,`: `,e.message]},e.deviceId))]})]}),R(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[U(`span`,{className:`text-[10px] text-foreground-subtle`,children:v&&b?`${b.done} / ${b.total}…`:``}),R(`div`,{className:`flex items-center gap-2`,children:[U(`button`,{type:`button`,onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Close`}),R(`button`,{type:`button`,onClick:async()=>{let e=[...g];if(e.length===0)return;y(!0),w([]),D(null),x({done:0,total:e.length});let t=[],n=0;for(let r=0;r<e.length;r+=1){let i=e[r];try{await ce(i),n+=1}catch(e){t.push({deviceId:i,name:le.get(i)??String(i),message:e instanceof Error?e.message:String(e)})}x({done:r+1,total:e.length})}y(!1),w(t),D(n),_(new Set),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})},disabled:!ne,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50 disabled:cursor-not-allowed`,children:[v&&U(q,{className:`h-3.5 w-3.5 animate-spin`}),`Assign `,g.size,` to `,t]})]})]})]})]})}L();function Yt({nodeId:e,title:t}){let{data:n}=Je(),{data:r}=T(void 0),i=z(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),a=z(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),[o,s]=H(new Map);w(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||s(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),W(()=>{if(o.size===0)return;let e=setInterval(()=>{s(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)},[o.size]);let c=z(()=>{let e=[];for(let t of o.values())a&&!a.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[o,a]);return c.length===0?R(`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`]}):R(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[R(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[U(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),U(`span`,{className:`text-[10px] text-foreground-subtle`,children:c.length})]}),U(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>{let t=i.get(e.deviceId)??`#${e.deviceId}`,n=l(e.metrics.phase);return R(`div`,{title:`${t} · ${n.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] ${n.badgeClass}`,children:[U(C,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),U(`span`,{className:`font-medium text-foreground/90 max-w-[120px] truncate`,children:t}),U(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),U(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var Xt={key:`maxCameras`,type:`slider`,label:`Max cameras`,description:`Hard cap on cameras the balancer may assign to this node.`,min:1,max:64,step:1,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Unlimited`};L();var Zt=350;function Qt(e){return typeof e==`number`&&e>0?Math.floor(e):null}function $t({value:e,pending:t,errorMessage:r,onCommit:i}){let[a,o]=H(e);W(()=>{o(e)},[e]);let s=ge(i);return s.current=i,W(()=>{if(a===e)return;let t=setTimeout(()=>s.current(a),Zt);return()=>clearTimeout(t)},[a,e]),R(`div`,{className:`flex items-center gap-3 text-xs text-foreground`,children:[U(`div`,{className:`max-w-md flex-1`,children:U(n,{field:Xt,values:{maxCameras:a},disabled:t,onChange:(e,t)=>o(Qt(t))})}),t&&U(`span`,{className:`text-[10px] text-muted-foreground animate-pulse`,children:`Saving…`}),r&&R(`span`,{className:`text-[10px] text-destructive`,children:[`Save failed: `,r]})]})}L();function en(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 tn({nodeId:e,refreshToken:n}){let r=V(),[i,a]=H(null),[s,c]=H(null),[l,u]=H(null),d=(o(void 0).data??[]).find(t=>t.id===e)?.name??e,f=t({nodeId:e},{refetchOnMount:`always`}),p=x({agentNodeId:e},{refetchOnMount:`always`}),m=()=>{r.invalidateQueries({queryKey:[[`addonSettings`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),r.invalidateQueries({queryKey:[[`pipelineExecutor`]]})},h=ue({onSuccess:m}),g=ne({onSuccess:m}),_=f.data??null,v=p.data,y=_?.selectedEngine.format??`coreml`,b=z(()=>_?le(_):[],[_]),S=z(()=>[{agentNodeId:e,engineLabel:y}],[e,y]),C=(e,t)=>{let n=v?.addonDefaults[e];return!en(_,e)?.models.some(e=>!!e.formats[y])||!n?{kind:`na`}:n.enabled?{kind:`enabled`,modelId:n.modelId}:{kind:`disabled`}},w=i&&_?en(_,i.addonId):null,T=t=>{let n=v?.addonDefaults[t]??null;a({addonId:t,agentNodeId:e}),c(n)},E=(t,n)=>{if(!v)return;let r=v.addonDefaults[t],i=en(_,t);if(!r&&!i)return;let a={enabled:n,modelId:r?.modelId??i?.defaultModelId??``,settings:r?.settings??{}};h.mutate({agentNodeId:e,defaults:{...v.addonDefaults,[t]:a}})},O=()=>{a(null),c(null)},A=()=>{!s||!i||!v||h.mutate({agentNodeId:e,defaults:{...v.addonDefaults,[i.addonId]:s}},{onSuccess:O})};if(f.isLoading||p.isLoading)return U(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading pipeline…`});if(f.error)return R(`div`,{className:`text-xs text-red-400`,children:[`Failed to load catalog: `,String(f.error)]});if(!_)return U(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog unavailable for this node (runner offline?).`});let j=i!==null&&w!==null&&s!==null,M=p.data?.maxCameras??null;return R(`div`,{className:`relative h-full w-full space-y-3`,children:[U(Yt,{nodeId:e}),U($t,{value:M,pending:g.isPending,errorMessage:g.isError?g.error instanceof Error?g.error.message:`Unknown error`:null,onCommit:t=>g.mutate({agentNodeId:e,maxCameras:t})}),R(`div`,{className:`flex items-center gap-2 text-xs`,children:[U(`span`,{className:`font-medium text-muted-foreground`,children:`Batch assign:`}),U(`button`,{type:`button`,onClick:()=>u(`pipeline`),className:`rounded border border-border bg-surface px-2 py-0.5 text-xs hover:bg-surface-hover`,children:`Pipeline…`}),U(`button`,{type:`button`,onClick:()=>u(`audio`),className:`rounded border border-border bg-surface px-2 py-0.5 text-xs hover:bg-surface-hover`,children:`Audio…`}),U(`button`,{type:`button`,onClick:()=>u(`decode`),className:`rounded border border-border bg-surface px-2 py-0.5 text-xs text-foreground-subtle hover:bg-surface-hover`,children:`Decode… (advisory)`})]}),l&&U(Jt,{nodeId:e,nodeName:d,concern:l,open:l!==null,onClose:()=>u(null)}),U(`div`,{className:j?`pr-[360px]`:``,children:b.length>0?U(oe,{tree:b,agents:S,getCellState:C,onCellClick:T,selectedCell:i,onToggleEnabled:E}):U(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),U(k,{open:j,onClose:O,title:w?.name??``,subtitle:i?`${i.agentNodeId} · ${y}`:``,footer:R(B,{children:[U(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:O,children:`Cancel`}),U(`button`,{type:`button`,disabled:!s||!i||h.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:A,children:h.isPending?`Saving…`:`Save`})]}),children:w&&s&&i&&U(D,{mode:`agent`,addon:w,agentDefault:s,agentNodeId:i.agentNodeId,engineFormat:y,onChangeAgentConfig:e=>c(e)})})]})}var nn=[`detection-pipeline`,`decoder-ffmpeg`,`audio-analyzer`,`pipeline-runner`];function rn({nodeId:e,refreshToken:t}){return R(`div`,{className:`flex flex-col h-full`,children:[U(mt,{nodeId:e,refreshToken:t}),U(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:U(rt,{nodeId:e,addonIds:nn,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:U(Ot,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:U(tn,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:U(At,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:U(Bt,{nodeId:e,refreshToken:t})}]})})]})}L();var an=`pipeline-orchestrator`,on=[`ingestNode`,`recordingNode`,`audioNode`],sn=[`detect`,`decode`,`audio`,`ingest`];function cn(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function ln(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function un(e,t,n){let r=cn(e,t);return typeof r==`string`&&r.length>0?r:n}function dn(e,t,n){let r=cn(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function fn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function pn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:`Audio`}function mn(e,t){return t===`detect`?e.pipeline:e[t]}function hn({role:e,value:t,options:n,pending:r,onChange:i}){return R(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground-subtle`,children:[U(`span`,{className:`font-medium text-foreground`,children:pn(e)}),U(`select`,{value:t,disabled:r,onChange:t=>i(e,t.target.value),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:n.map(e=>U(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))})]})}function gn({nodeId:e,weight:t,totalWeight:n,pending:r,onCommit:i}){let[a,o]=H(String(t));W(()=>{o(String(t))},[t]);let s=n>0?t/n:0,c=2*Math.PI*14,l=c*s,u=()=>{let t=Number(a);i(e,Number.isFinite(t)&&t>0?t:null)};return R(`div`,{className:`flex items-center gap-2`,children:[R(`svg`,{viewBox:`0 0 36 36`,className:`h-9 w-9 shrink-0`,"aria-hidden":`true`,children:[U(`circle`,{cx:`18`,cy:`18`,r:14,fill:`none`,className:`stroke-border`,strokeWidth:`4`}),U(`circle`,{cx:`18`,cy:`18`,r:14,fill:`none`,className:`stroke-primary`,strokeWidth:`4`,strokeDasharray:`${l} ${c-l}`,strokeLinecap:`round`,transform:`rotate(-90 18 18)`}),U(`text`,{x:`18`,y:`20`,textAnchor:`middle`,className:`fill-foreground text-[8px] font-bold`,children:Math.round(s*100)})]}),U(`input`,{"aria-label":`Detect weight for ${e}`,type:`number`,min:0,step:.25,value:a,disabled:r,onChange:e=>o(e.target.value),onBlur:u,onKeyDown:e=>{e.key===`Enter`&&u()},className:`w-20 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`})]})}function _n({nodeId:e,value:t,pending:n,onCommit:r}){let[i,a]=H(t===null?``:String(t));W(()=>{a(t===null?``:String(t))},[t]);let o=()=>{let t=Number(i);r(e,Number.isFinite(t)&&t>0?Math.floor(t):null)};return U(`input`,{"aria-label":`Max cameras for ${e}`,type:`number`,min:0,step:1,placeholder:`∞`,value:i,disabled:n,onChange:e=>a(e.target.value),onBlur:o,onKeyDown:e=>{e.key===`Enter`&&o()},className:`w-20 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`})}function vn(){let e=V(),{nodes:t}=F(),n=I(void 0),r=P({addonId:an}),i=()=>fn(e),a=A({onSuccess:i}),o=M({onSuccess:i}),s=ne({onSuccess:i}),c=te({onSuccess:i}),l=z(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),u=z(()=>t.map(e=>{let t=l.get(e.id),n=dt(t,e.isHub);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:typeof ln(t,`detectWeight`)==`number`?Number(ln(t,`detectWeight`)):1}}),[t,l]),d=u.filter(e=>e.effective.pipeline).reduce((e,t)=>e+t.weight,0),f={ingestNode:un(r.data,`ingestNode`,`hub`),recordingNode:un(r.data,`recordingNode`,`hub`),audioNode:un(r.data,`audioNode`,`hub`)},p=z(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...on.map(e=>f[e]),...e])].filter(e=>e.length>0)},[t,f]),m=dn(r.data,`fpsMinThreshold`,0),h=m>0,g=(e,t,n)=>{a.mutate({agentNodeId:e,[t]:n})},_=(e,t)=>{c.mutate({addonId:an,patch:{[e]:t}})},v=e=>{c.mutate({addonId:an,patch:{fpsMinThreshold:e?Math.max(1,m):0}})};return R(`section`,{className:`rounded-lg border border-border bg-surface p-4 space-y-4`,children:[R(`div`,{className:`flex items-start justify-between gap-3`,children:[R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Table-board placement controls`}),U(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Enable node roles, tune relative detection weights, set camera ceilings, and choose singleton cluster roles. Weights are relative shares across detect-capable nodes.`})]}),(n.isLoading||r.isLoading)&&U(q,{className:`h-4 w-4 animate-spin text-foreground-subtle`})]}),R(`div`,{className:`grid gap-3 @md/clustertab:grid-cols-4`,children:[on.map(e=>U(hn,{role:e,value:f[e],options:p,pending:c.isPending,onChange:_},e)),R(`label`,{className:`flex items-center gap-2 rounded-md border border-border bg-background px-3 py-2 text-xs text-foreground`,children:[U(`input`,{type:`checkbox`,checked:h,disabled:c.isPending,onChange:e=>v(e.target.checked),className:`h-4 w-4`}),R(`span`,{className:`flex flex-col`,children:[U(`span`,{className:`font-medium`,children:`Enable low-fps relocate/shed`}),R(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`fpsMinThreshold `,h?`${m} fps`:`disabled`]})]})]})]}),U(`div`,{className:`overflow-x-auto rounded-md border border-border`,children:R(`table`,{className:`w-full min-w-[760px] text-xs`,children:[U(`thead`,{className:`bg-background`,children:R(`tr`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[U(`th`,{className:`px-3 py-2 text-left`,children:`Node`}),U(`th`,{className:`px-3 py-2 text-center`,children:`Detect`}),U(`th`,{className:`px-3 py-2 text-center`,children:`Decode`}),U(`th`,{className:`px-3 py-2 text-center`,children:`Audio`}),U(`th`,{className:`px-3 py-2 text-center`,children:`Ingest`}),U(`th`,{className:`px-3 py-2 text-left`,children:`Detect weight`}),U(`th`,{className:`px-3 py-2 text-left`,children:`Max cameras`})]})}),U(`tbody`,{children:u.map(e=>R(`tr`,{className:`border-t border-border ${e.isOnline?``:`opacity-50`}`,children:[R(`td`,{className:`px-3 py-2`,children:[U(`div`,{className:`font-medium text-foreground`,children:e.name}),R(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,children:[e.id,e.isHub?` · hub`:``,e.isOnline?``:` · offline`]})]}),sn.map(t=>U(`td`,{className:`px-3 py-2 text-center`,children:U(`input`,{"aria-label":`${t} capability for ${e.id}`,type:`checkbox`,checked:mn(e.effective,t),disabled:a.isPending,onChange:n=>g(e.id,t,n.target.checked),className:`h-4 w-4`})},t)),U(`td`,{className:`px-3 py-2`,children:e.effective.pipeline?U(gn,{nodeId:e.id,weight:e.weight,totalWeight:d,pending:o.isPending,onCommit:(e,t)=>o.mutate({agentNodeId:e,detectWeight:t})}):U(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`Detect off`})}),U(`td`,{className:`px-3 py-2`,children:U(_n,{nodeId:e.id,value:typeof ln(e.settings,`maxCameras`)==`number`?Number(ln(e.settings,`maxCameras`)):null,pending:s.isPending,onCommit:(e,t)=>s.mutate({agentNodeId:e,maxCameras:t})})})]},e.id))})]})})]})}L();function yn({refreshToken:e}){let t=V(),{data:n}=o(void 0),r=z(()=>tt(n??[]),[n]),i=O({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return R(`div`,{className:`space-y-6`,children:[U(ht,{refreshToken:e}),U(vn,{}),R(`section`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Cluster map`}),U(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`React Flow topology map retained as the visual placement map; use the table-board above as the control surface.`})]}),U(`div`,{className:`h-[360px] rounded-md border border-border overflow-hidden bg-background`,children:U(Qe,{graph:r})})]}),R(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[R(`div`,{className:`min-w-0`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),U(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · decoder · audio assignments per camera. Click the kebab to pin / unpin / move any role; expand the chevron for the per-camera broker drill-down.`})]}),R(`button`,{type:`button`,onClick:()=>i.mutate(void 0),disabled:i.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:[U(Oe,{className:`h-3.5 w-3.5`}),i.isPending?`Rebalancing…`:`Rebalance pipelines`]})]}),U(bt,{mode:`cluster`})]})}var bn=[`pipeline-orchestrator`];function xn({refreshToken:e}){return U(`div`,{className:`space-y-4 max-w-3xl`,children:U(rt,{nodeId:`hub`,addonIds:bn,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.`})})}L();function Sn({refreshToken:e}){let t=V(),{data:n,isLoading:r}=se(),[i,a]=H(null),[o,s]=H(``),[c,l]=H(``),d=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},f=fe({onSuccess:()=>{a(null),d()}}),p=u({onSuccess:d}),m=e=>{a(e.id),s(e.name),l(e.description??``)},h=()=>{a(null),s(``),l(``)},g=()=>{if(!i)return;let e=c.trim();f.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return U(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let _=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return U(`div`,{className:`space-y-6 max-w-4xl`,children:R(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[R(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),U(`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.`})]}),R(`div`,{className:`text-[11px] text-foreground-subtle`,children:[_.length,` template`,_.length===1?``:`s`]})]}),_.length===0?R(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[U(Ae,{className:`h-6 w-6 opacity-40`}),U(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):U(`ul`,{className:`divide-y divide-border`,children:_.map(e=>{let t=i===e.id;return U(`li`,{className:`px-4 py-3 text-xs`,children:R(`div`,{className:`flex items-start gap-3`,children:[U(`div`,{className:`flex-1 min-w-0`,children:t?R(`div`,{className:`space-y-2`,children:[U(`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}),U(`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)`})]}):R(B,{children:[U(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&U(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),R(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[`engine `,e.config.engine.runtime,`/`,e.config.engine.backend,` ·`,` `,e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,R(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),U(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?R(B,{children:[R(`button`,{type:`button`,onClick:g,disabled:f.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:[U(Le,{className:`h-3 w-3`}),`Save`]}),R(`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:[U(He,{className:`h-3 w-3`}),`Cancel`]})]}):R(B,{children:[U(`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:U(ke,{className:`h-3 w-3`})}),U(`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:U(Ge,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}L();function Cn(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 wn({nodeId:e,refreshToken:n}){let r=V(),i=be().trpcClient,[a,s]=H(null),[c,l]=H(null),u=I(void 0,{refetchOnMount:`always`});J([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`,`addon.updated`]);let d=o(void 0,{refetchOnMount:`always`}),f=z(()=>{let e=new Set;for(let t of d.data??[])t.isOnline&&e.add(t.id);return e},[d.data]),p=t({nodeId:e},{refetchOnMount:`always`}),m=z(()=>(u.data??[]).filter(e=>f.has(e.nodeId)).map(e=>e.nodeId),[u.data,f]),h=ve({enabled:m.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`schema-by-agent`,m.join(`,`),n],queryFn:async()=>{let e={};for(let t of m)try{e[t]=(await i.pipelineExecutor.getSchema.query({nodeId:t})).selectedEngine.format}catch{e[t]=`coreml`}return e}}),g=ue({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),r.invalidateQueries({queryKey:[[`pipelineExecutor`]]}),r.invalidateQueries({queryKey:[[`addonSettings`]]})}}),_=z(()=>p.data?le(p.data):[],[p.data]),v=z(()=>{let e=u.data??[],t=f;return(t.size===0?[]:e.filter(e=>t.has(e.nodeId))).map(e=>{let t=h.data?.[e.nodeId];return{agentNodeId:e.nodeId,engineLabel:t??`(engine unknown)`}})},[u.data,h.data,f]),y=(e,t)=>{let n=(u.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e],r=h.data?.[t];return!Cn(p.data??null,e)?.models.some(e=>r!==void 0&&!!e.formats[r])||!n?{kind:`na`}:n.enabled?{kind:`enabled`,modelId:n.modelId}:{kind:`disabled`}},b=a?u.data?.find(e=>e.nodeId===a.agentNodeId)??null:null,x=a&&p.data?Cn(p.data,a.addonId):null,S=a?h.data?.[a.agentNodeId]??`coreml`:`coreml`,C=()=>{s(null),l(null)},w=(e,t)=>{let n=(u.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e]??null;s({addonId:e,agentNodeId:t}),l(n)},T=()=>{!c||!a||!b||g.mutate({agentNodeId:a.agentNodeId,defaults:{...b.settings.addonDefaults,[a.addonId]:c}},{onSuccess:C})};if(u.isLoading||p.isLoading)return U(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading agents…`});if(!p.data)return R(`div`,{className:`text-xs text-foreground-subtle`,children:[`Catalog unavailable for `,e,`.`]});let E=a!==null&&x!==null&&c!==null;return R(`div`,{className:`relative h-full w-full space-y-3`,children:[U(Yt,{title:`Cluster cameras`}),U(`div`,{className:E?`pr-[360px]`:``,children:_.length>0&&v.length>0?U(oe,{tree:_,agents:v,getCellState:y,onCellClick:w,selectedCell:a}):U(`div`,{className:`text-xs text-foreground-subtle`,children:`No agents or catalog empty.`})}),U(k,{open:E,onClose:C,title:x?.name??``,subtitle:a?`${a.agentNodeId} · ${S}`:``,footer:R(B,{children:[U(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:C,children:`Cancel`}),U(`button`,{type:`button`,disabled:!c||!a||g.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:T,children:g.isPending?`Saving…`:`Save`})]}),children:x&&c&&a&&U(D,{mode:`agent`,addon:x,agentDefault:c,agentNodeId:a.agentNodeId,engineFormat:S,onChangeAgentConfig:e=>l(e)})})]})}L();function Tn({types:e}){let t=V(),n=p(),{data:r}=i({}),o=a(),s=z(()=>o.data??[],[o.data]),[c,l]=H(null),[u,d]=H(null),f=()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},m=ee({onSuccess:f}),h=v({onSuccess:f}),g=z(()=>{let e=new Map;for(let t of r??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[r]),_=e=>{e.isDefault||m.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},y=async e=>{if(e.isDefault){await n({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another as default first.`,confirmLabel:`OK`,variant:`warning`});return}await n({title:`Delete location "${e.displayName}"?`,message:`Removes the record; files on disk are untouched.`,confirmLabel:`Delete`,variant:`danger`})&&h.mutate({id:e.id})},b=e.map(e=>s.find(t=>t.id===e)).filter(e=>e!==void 0);return R(`div`,{className:`space-y-3`,children:[b.length===0?U(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:`No storage locations declared for this purpose.`}):b.map(e=>U(we,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:g.get(e.id)??[],onAdd:e=>l(e),onEdit:e=>d(e),onDelete:e=>{y(e)},onSetDefault:e=>_(e)},e.id)),c!==null&&U(Te,{initialType:c,onClose:()=>l(null),onCreated:()=>{f(),l(null)}}),u!==null&&U(Ce,{location:u,onClose:()=>d(null),onSaved:()=>{f(),d(null)}})]})}L();var En=`pipeline-analytics`;function Dn(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 On(){let e=V(),{data:t}=o(void 0),{data:n,isLoading:r}=P({addonId:En}),i=Dn(n),a=te({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),s=z(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return R(`div`,{className:`flex flex-col gap-6`,children:[R(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),U(`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.`}),R(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?U(q,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):U(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:En,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:s.map(e=>U(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&U(q,{className:`h-4 w-4 animate-spin text-primary`})]})]}),R(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[U(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),U(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),U(Tn,{types:[`eventMedia`]})]})]})}L();var kn=`recorder`;function An(e,t,n){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t&&typeof e.value==`string`)return e.value;return n}function jn(){let e=V(),{data:t}=o(void 0),{data:n,isLoading:r}=P({addonId:kn}),i=An(n,`recordingNodeId`,`hub`),a=te({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),s=z(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return R(`div`,{className:`flex flex-col gap-6`,children:[R(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),U(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records (continuous & events) and serves playback. Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),R(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?U(q,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):U(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:kn,patch:{recordingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:s.map(e=>U(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&U(q,{className:`h-4 w-4 animate-spin text-primary`})]}),i!==`hub`&&R(`p`,{className:`mt-2 text-[11px] text-amber-500`,children:[`The stream-broker is hub-only — an agent recorder pulls streams from the hub over the network. The hub's RTSP restream port must be reachable from`,` `,U(`span`,{className:`font-medium`,children:i}),`. If the auto-derived host doesn't work, set the recorder's`,U(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),R(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[U(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),U(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where recordings are stored. Multi-location collections — segments are split across the locations of a type. Add a location to grow capacity; mark one default per type.`}),U(Tn,{types:[`recordings`,`recordingsLow`]})]})]})}L();var Mn=[{id:`assignments`,label:`Assignments`},{id:`pipeline`,label:`Pipeline`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`}];function Nn({refreshToken:e}){let[t,n]=H(`assignments`),{data:r}=o(void 0),i=r?.find(e=>e.isHub&&e.isOnline)?.id??r?.find(e=>e.isOnline)?.id??null;return R(`div`,{className:`flex flex-col h-full`,children:[R(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[U(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),U(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Assignments with live load, cluster-wide settings, pipeline template library, per-camera pipeline overrides.`})]}),U(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Mn.map(e=>U(`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))}),R(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&U(yn,{refreshToken:e}),t===`pipeline`&&(i?U(wn,{nodeId:i,refreshToken:e}):U(`div`,{className:`text-xs text-foreground-subtle`,children:`No online node available — schema unreachable.`})),t===`events`&&U(On,{}),t===`recording`&&U(jn,{}),t===`settings`&&U(xn,{refreshToken:e}),t===`templates`&&U(Sn,{refreshToken:e})]})]})}function Pn(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`}L();var Fn={healthy:`bg-green-500`,idle:`bg-yellow-400`,error:`bg-red-500`},In={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Ln({health:e}){return U(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${Fn[e]}`,title:In[e],"aria-label":In[e],role:`img`})}function Rn({selectedDeviceId:e,onSelect:t}){let{data:n}=Je(),{data:r}=ce({}),i=z(()=>{let e=new Map;for(let t of r??[])e.set(t.deviceId,t);return e},[r]),a=z(()=>(n??[]).filter(e=>e.isCamera).map(e=>{let t=i.get(e.id);return{deviceId:e.id,name:e.name,health:t===void 0?`idle`:Pn(t)}}),[n,i]);return a.length===0?U(`div`,{className:`px-4 py-6 text-center text-[11px] text-foreground-subtle italic`,children:`No cameras found`}):U(`ul`,{className:`divide-y divide-border`,children:a.map(n=>{let r=n.deviceId===e;return U(`li`,{children:R(`button`,{type:`button`,onClick:()=>t(n.deviceId),className:[`w-full flex items-center gap-2.5 px-4 py-3 text-left transition-colors`,r?`bg-surface-active text-foreground`:`hover:bg-surface-hover text-foreground-subtle hover:text-foreground`].join(` `),"aria-pressed":r,children:[U(Ln,{health:n.health}),R(`span`,{className:`flex-1 min-w-0`,children:[U(`span`,{className:`block truncate text-[12px] font-medium leading-tight`,children:n.name}),R(`span`,{className:`block text-[10px] text-foreground-subtle leading-tight mt-0.5`,children:[`#`,n.deviceId]})]})]})},n.deviceId)})})}var $={camera:0,source:200,broker:400,decoder:600,motion:800,detection:800,audio:800,recorder:800},zn=120;function Bn(e,t){return e===null||t===null?!1:e!==t}function Vn(e){let t=e.profiles.reduce((e,t)=>e+t.subscribers,0),n=e.profiles.reduce((e,t)=>e+t.inFps,0),r=e.profiles.reduce((e,t)=>e+t.outFps,0);return`${t} subs · ${n.toFixed(1)}→${r.toFixed(1)} fps`}function Hn(e){return`${e.actualFps.toFixed(1)} fps · q${e.queueDepth} · ${e.avgInferenceMs.toFixed(1)}ms`}function Un(e){return`shm ${e.shm.getFrameHits+e.shm.getFrameMisses>0?Math.round(e.shm.getFrameHits/(e.shm.getFrameHits+e.shm.getFrameMisses)*100):0}% hit`}function Wn(e){let t=[],n=[],r={id:`camera`,kind:`camera`,nodeId:null,data:{deviceId:e.deviceId},position:{x:$.camera,y:0}};t.push(r);let i={id:`source`,kind:`source`,nodeId:null,data:{streams:e.source.streams},position:{x:$.source,y:0}};t.push(i),n.push({id:`camera->source`,source:`camera`,target:`source`,crossNode:!1});let a=e.broker;if(a!==null){let e={id:`broker`,kind:`broker`,nodeId:null,data:{profiles:a.profiles,webrtcSessions:a.webrtcSessions,rtspRestream:a.rtspRestream},position:{x:$.broker,y:0}};t.push(e),n.push({id:`source->broker`,source:`source`,target:`broker`,crossNode:!1})}let o=e.decoder;if(o!==null){let r={id:`decoder`,kind:`decoder`,nodeId:o.nodeId,data:{nodeId:o.nodeId,formats:o.formats,sessionCount:o.sessionCount,shm:o.shm},position:{x:$.decoder,y:0}};t.push(r);let i=a===null?`source`:`broker`,s=a===null?void 0:Vn(a),c=a===null?Un(o):s;n.push({id:`${i}->decoder`,source:i,target:`decoder`,crossNode:Bn(null,o.nodeId),...c===void 0?{}:{label:c}});let l=0,u=e.motion;if(u!==null){let e={id:`motion`,kind:`motion`,nodeId:null,data:{enabled:u.enabled,fps:u.fps},position:{x:$.motion,y:l*zn}};t.push(e),n.push({id:`decoder->motion`,source:`decoder`,target:`motion`,crossNode:!1}),l++}let d=e.detection;if(d!==null){let e={id:`detection`,kind:`detection`,nodeId:d.nodeId,data:{nodeId:d.nodeId,engine:d.engine,phase:d.phase,configuredFps:d.configuredFps,actualFps:d.actualFps,queueDepth:d.queueDepth,avgInferenceMs:d.avgInferenceMs,provisioning:d.provisioning},position:{x:$.detection,y:l*zn}};t.push(e),n.push({id:`decoder->detection`,source:`decoder`,target:`detection`,crossNode:Bn(o.nodeId,d.nodeId),label:Hn(d)}),l++}let f=e.audio;if(f!==null){let e={id:`audio`,kind:`audio`,nodeId:f.nodeId,data:{nodeId:f.nodeId,enabled:f.enabled},position:{x:$.audio,y:l*zn}};t.push(e),n.push({id:`decoder->audio`,source:`decoder`,target:`audio`,crossNode:Bn(o.nodeId,f.nodeId)}),l++}let p=e.recording;if(p!==null){let e={id:`recorder`,kind:`recorder`,nodeId:null,data:{mode:p.mode,active:p.active,storageBytes:p.storageBytes},position:{x:$.recorder,y:l*zn}};t.push(e),n.push({id:`decoder->recorder`,source:`decoder`,target:`recorder`,crossNode:!1})}}return{nodes:t,edges:n}}L();function Gn(e){let{data:t,isLoading:n}=j({deviceId:e}),[r,i]=H(void 0);return W(()=>{t!==void 0&&i(t)},[t]),w(G.PipelineCameraMetricsSnapshot,t=>{let n=t.data;n.deviceId===e&&i(e=>e===void 0||e.detection===null?e:{...e,detection:{...e.detection,phase:n.metrics.phase,actualFps:n.metrics.actualFps,queueDepth:n.metrics.queueDepth,avgInferenceMs:n.metrics.avgInferenceTimeMs}})}),w(G.PipelineEngineProvisioning,e=>{let t=e.data;i(n=>{if(n===void 0||n.detection===null)return n;let r=n.detection.nodeId??n.assignment?.detectionNodeId??null;return r===null||e.source.type!==`node`||e.source.id!==r?n:{...n,detection:{...n.detection,provisioning:{state:t.state,error:t.error}}}})}),w(G.MotionAnalysis,t=>{t.source.type!==`device`||t.source.id!==e||i(e=>e===void 0||e.motion===null?e:{...e,motion:{...e.motion,enabled:!0}})}),w(G.StreamBrokerMetricsSnapshot,t=>{let n=t.data;n.deviceId===e&&i(e=>e===void 0||e.broker===null?e:{...e,broker:{...e.broker,profiles:e.broker.profiles.map(e=>e.profile===n.profile?{...e,subscribers:n.stats.encodedSubscribers+n.stats.decodedSubscribers,inFps:n.stats.inputFps,outFps:n.stats.decodeFps}:e)}})}),w(G.PipelineAudioInferenceResult,t=>{t.data.deviceId===e&&i(e=>e===void 0||e.audio===null?e:{...e,audio:{...e.audio,enabled:!0}})}),w(G.RecordingStarted,t=>{t.data.deviceId===e&&i(e=>e===void 0||e.recording===null?e:{...e,recording:{...e.recording,active:!0}})}),w(G.RecordingStopped,t=>{t.data.deviceId===e&&i(e=>e===void 0||e.recording===null?e:{...e,recording:{...e.recording,active:!1}})}),{status:r,isLoading:n}}function Kn({data:e}){return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`source`,position:Y.Right}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full bg-green-500 shrink-0`,"aria-label":`healthy`}),R(`span`,{className:`text-sm font-semibold truncate`,children:[`Camera #`,e.deviceId]})]}),U(`div`,{className:`text-xs text-muted-foreground mt-1`,children:`source`})]})}function qn(e){return e>0?`bg-green-500`:`bg-yellow-500`}function Jn({data:e}){let t=e.streams[0],n=e.streams.length;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`target`,position:Y.Left}),U(X,{type:`source`,position:Y.Right}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${qn(n)}`,"aria-label":n>0?`healthy`:`idle`}),U(`span`,{className:`text-sm font-semibold`,children:`Source`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[n,` streams`]})]}),t!==void 0&&R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t.codec,` `,t.width,`×`,t.height,` `,t.fps,`fps`]})]})}function Yn(e){return e>0?`bg-green-500`:`bg-yellow-500`}function Xn({data:e}){let t=e.profiles.reduce((e,t)=>e+t.subscribers,0),n=e.profiles.length;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`target`,position:Y.Left}),U(X,{type:`source`,position:Y.Right}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${Yn(t)}`,"aria-label":t>0?`healthy`:`idle`}),U(`span`,{className:`text-sm font-semibold`,children:`Broker`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[n,` profiles`]})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t,` subs · WebRTC `,e.webrtcSessions,e.rtspRestream&&` · RTSP`]})]})}function Zn(e){return e>0?`bg-green-500`:`bg-yellow-500`}function Qn(e,t){let n=e+t;return n>0?Math.round(e/n*100):0}function $n({data:e}){let t=Qn(e.shm.getFrameHits,e.shm.getFrameMisses),n=e.offline===!0;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2${n?` opacity-50`:``}`,children:[U(X,{type:`target`,position:Y.Left}),U(X,{type:`source`,position:Y.Right}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${Zn(e.sessionCount)}`,"aria-label":e.sessionCount>0?`healthy`:`idle`}),U(`span`,{className:`text-sm font-semibold`,children:`Decoder`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[`@`,e.nodeId]}),n&&U(`span`,{className:`text-[9px] font-semibold px-1 py-0.5 rounded bg-destructive/10 text-destructive`,"aria-label":`offline`,children:`offline`})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.formats.join(`, `),` · `,e.sessionCount,` sessions`]}),R(`div`,{className:`text-xs text-muted-foreground`,children:[`shm `,t,`% hit`]})]})}function er(e){return e?`bg-green-500`:`bg-yellow-500`}function tr({data:e}){return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`target`,position:Y.Left}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${er(e.enabled)}`,"aria-label":e.enabled?`enabled`:`disabled`}),U(`span`,{className:`text-sm font-semibold`,children:`Motion`})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.enabled?`enabled`:`disabled`,` · `,e.fps,` fps`]})]})}function nr(e){return e.provisioning.state===`failed`?`bg-red-500`:e.phase===`active`?`bg-green-500`:(e.phase,`bg-yellow-500`)}function rr(e){return e===`ready`?`bg-green-500 text-white`:e===`failed`?`bg-red-500 text-white`:`bg-yellow-500 text-white`}function ir({data:e}){let t=e.offline===!0;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[180px] px-3 py-2${t?` opacity-50`:``}`,children:[U(X,{type:`target`,position:Y.Left}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${nr(e)}`,"aria-label":e.phase}),U(`span`,{className:`text-sm font-semibold`,children:`Detection`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[`@`,e.nodeId]}),t&&U(`span`,{className:`text-[9px] font-semibold px-1 py-0.5 rounded bg-destructive/10 text-destructive`,"aria-label":`offline`,children:`offline`})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.engine.backend,`·`,e.engine.device,` · `,e.phase]}),R(`div`,{className:`text-xs text-muted-foreground`,children:[e.actualFps.toFixed(1),`/`,e.configuredFps,` fps · q`,e.queueDepth,` ·`,` `,e.avgInferenceMs.toFixed(1),`ms`]}),R(`div`,{className:`flex items-center gap-1 mt-1`,children:[U(`span`,{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded ${rr(e.provisioning.state)}`,"aria-label":`provisioning ${e.provisioning.state}`,children:e.provisioning.state}),e.provisioning.state===`failed`&&e.provisioning.error!==void 0&&U(`span`,{className:`text-[10px] text-red-500 truncate`,children:e.provisioning.error})]})]})}function ar(e){return e?`bg-green-500`:`bg-yellow-500`}function or({data:e}){let t=e.offline===!0;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2${t?` opacity-50`:``}`,children:[U(X,{type:`target`,position:Y.Left}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${ar(e.enabled)}`,"aria-label":e.enabled?`enabled`:`disabled`}),U(`span`,{className:`text-sm font-semibold`,children:`Audio`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[`@`,e.nodeId]}),t&&U(`span`,{className:`text-[9px] font-semibold px-1 py-0.5 rounded bg-destructive/10 text-destructive`,"aria-label":`offline`,children:`offline`})]}),U(`div`,{className:`text-xs text-muted-foreground mt-1`,children:e.enabled?`enabled`:`disabled`})]})}function sr(e){return e.mode===`off`?`bg-red-500`:e.active?`bg-green-500`:`bg-yellow-500`}function cr(e){return e>=1073741824?`${(e/1073741824).toFixed(1)} GB`:`${(e/1048576).toFixed(1)} MB`}function lr({data:e}){return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`target`,position:Y.Left}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${sr(e)}`,"aria-label":e.active?`active`:e.mode===`off`?`off`:`inactive`}),U(`span`,{className:`text-sm font-semibold`,children:`Recorder`}),U(`span`,{className:`text-xs text-muted-foreground`,children:e.mode})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.active?`active`:`inactive`,` · `,cr(e.storageBytes)]})]})}L();var ur={camera:Kn,source:Jn,broker:Xn,decoder:$n,motion:tr,detection:ir,audio:or,recorder:lr},dr={stroke:`#f59e0b`,strokeWidth:2},fr={strokeWidth:1.5},pr=`camstack-pipeline-flow-layout`;function mr({deviceId:e}){let{status:t,isLoading:n}=Gn(e),{data:r}=o(void 0),i=z(()=>{let e=new Set;for(let t of r??[])t.isOnline||e.add(t.id);return e},[r]),{computedNodes:a,rfEdges:s}=z(()=>{if(t===void 0)return{computedNodes:[],rfEdges:[]};let e=Wn(t);return{computedNodes:e.nodes.map(e=>({id:e.id,type:e.kind,position:{x:e.position.x,y:e.position.y},data:{...e.data,offline:e.nodeId!==null&&i.has(e.nodeId)}})),rfEdges:e.edges.map(e=>({id:e.id,source:e.source,target:e.target,animated:e.crossNode,style:e.crossNode?dr:fr,label:e.label}))}},[t,i]),{nodes:c,onNodesChange:l,resetLayout:u}=$e(pr,a);return n?U(`div`,{className:`flex items-center justify-center h-full text-sm text-muted-foreground`,children:`Loading…`}):t===void 0?U(`div`,{className:`flex items-center justify-center h-full text-sm text-muted-foreground`,children:`No pipeline data`}):R(`div`,{className:`w-full h-full relative`,children:[U(`button`,{type:`button`,onClick:u,className:`absolute top-2 right-2 z-10 text-xs px-2 py-1 rounded border border-border bg-background hover:bg-muted`,title:`Restore the automatic layout, discarding dragged positions`,children:`Reset layout`}),R(et,{nodes:c,edges:s,onNodesChange:l,nodesDraggable:!0,nodeTypes:ur,fitView:!0,proOptions:{hideAttribution:!0},children:[U(Xe,{gap:20,size:1}),U(Ye,{showInteractive:!1})]})]})}L();var hr=`__cluster__`;function gr(e){return e===`cameras`?`cameras`:`nodes`}function _r(){let[e,t]=Re(),n=gr(e.get(`view`)),r=e.get(`node`)??`__cluster__`,i=e.get(`camera`),a=i===null?null:parseInt(i,10),[o,s]=H(0),[c,l]=H(!1);return W(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:hr},{replace:!0})},[n,e,t]),R(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[R(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[R(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[U(`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`}),U(`button`,{type:`button`,onClick:()=>{let e={view:`cameras`};a!==null&&(e.camera=String(a)),t(e,{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`})]}),R(`button`,{type:`button`,onClick:()=>s(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:[U(je,{className:`h-3.5 w-3.5`}),`Refresh`]})]}),R(`button`,{type:`button`,onClick:()=>l(e=>!e),"aria-expanded":c,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:[R(`span`,{children:[c?`Hide`:`Show`,` `,n===`nodes`?`node list`:`camera list`]}),U(Be,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),U(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?R(B,{children:[U(`aside`,{className:[c?`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:U(pt,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:o})}),U(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?U(Nn,{refreshToken:o}):U(rn,{nodeId:r,refreshToken:o})})]}):R(B,{children:[U(`aside`,{className:[c?`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:U(Rn,{selectedDeviceId:a,onSelect:e=>{t({view:`cameras`,camera:String(e)},{replace:!0}),l(!1)}})}),U(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:a!==null&&Number.isFinite(a)&&!Number.isNaN(a)?U(mr,{deviceId:a}):U(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Select a camera to view its pipeline flow`})})]})})]})}export{_r as PipelinePage};
|
|
1
|
+
import{Aa as e,Br as t,C as n,Ci as r,Di as i,Ei as a,Fr as o,Gr as s,Hr as c,Ia as l,Jr as u,Kr as d,Lr as f,Qi as p,Qr as m,Ra as h,Rr as g,T as _,Ti as v,Ur as y,Vr as b,Xr as x,Zr as S,_ as C,aa as w,ai as T,bi as E,ca as D,ci as O,da as k,di as A,ei as j,fi as M,ia as N,it as P,ki as ee,na as F,oi as I,ot as te,pi as ne,qr as re,ra as ie,ri as ae,sa as oe,si as se,ti as ce,ua as le,ui as ue,vi as de,xi as fe,yi as pe,zr as me}from"./src-3NEgkLWp.js";import{I as he,K as ge,Q as L,S as R,T as _e,W as z,a as ve,b as B,o as V,q as H,x as U,z as W}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{L as G,R as ye}from"./src-DAcus8MI.js";import{p as be}from"./player-overlays-DACImv1W.js";import{t as xe}from"./download-DRBhCGtf.js";import{i as Se,n as Ce,r as we,t as Te}from"./AddLocationWizard-CoTQ1C0P.js";import{n as Ee,r as De,t as Oe}from"./zap-ps4S9uq0.js";import{t as ke}from"./pencil-GseW53Af.js";import{t as Ae}from"./plus-D1FskUey.js";import{t as je}from"./refresh-cw-TV5MkG3n.js";import{t as Me}from"./search-CvffVaTb.js";import{t as Ne}from"./server-BrxSxrRc.js";import{t as Pe}from"./square-check-big-DZGG97xQ.js";import{t as Fe}from"./square-D5hZ81IL.js";import{A as Ie,F as Le,G as Re,M as ze,P as Be,V as Ve,i as He,j as Ue,k as K,o as We,s as Ge,w as Ke,x as q}from"./index-CukLUOO-.js";import{t as qe}from"./AdminPage-BwmGKnRf.js";import{r as Je}from"./useDevice-B_z2JZ7g.js";import{t as J}from"./useEventInvalidation-C6mDyTBx.js";import{a as Ye,c as Y,i as Xe,l as Ze,n as Qe,o as X,r as $e,s as et,t as tt}from"./build-cluster-graph-Ci-E0Tjd.js";import{n as nt}from"./format-size-CO9d3C3-.js";import{t as rt}from"./NodeAddonsSettingsPanel-CaMCtRtL.js";var it=Ve(`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`}]]),at=Ve(`film`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M7 3v18`,key:`bbkbws`}],[`path`,{d:`M3 7.5h4`,key:`zfgn84`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`path`,{d:`M3 16.5h4`,key:`1230mu`}],[`path`,{d:`M17 3v18`,key:`in4fa5`}],[`path`,{d:`M17 7.5h4`,key:`myr1c1`}],[`path`,{d:`M17 16.5h4`,key:`go4c1d`}]]),ot=Ve(`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=Ve(`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`}]]);L();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{decode:ut(lt(e,`decode`),t),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:t,onSelect:n,refreshToken:r}){let{data:i}=o(void 0),{data:a}=T(void 0),{data:s}=I(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=i??[],u=l.filter(e=>e.isOnline).length,d=l.filter(e=>!e.isOnline).length;return R(`div`,{className:`flex flex-col h-full`,children:[R(`button`,{type:`button`,onClick:()=>n(br),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${t===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[U(Ke,{className:`h-4 w-4 flex-shrink-0`}),R(`div`,{className:`min-w-0 flex-1`,children:[U(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),U(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),U(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(r=>{let i=t===r.id,a=c.get(r.id)??0,o=r.isHub?Ne:K,l=ft(s,r.id,r.isHub),u=r.isOnline?null:h(Ze(r.lastSeen));return R(`button`,{type:`button`,onClick:()=>n(r.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${i?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${r.isOnline?``:` opacity-60`}`,children:[U(o,{className:`h-4 w-4 flex-shrink-0`}),R(`div`,{className:`min-w-0 flex-1`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`text-xs font-semibold truncate`,children:r.name}),r.isHub&&U(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!r.isOnline&&U(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),r.isOnline&&U(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),R(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[R(`span`,{children:[r.cpuCores,` cores`]}),U(`span`,{children:`•`}),R(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a>0&&R(B,{children:[U(`span`,{children:`•`}),R(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[U(Ee,{className:`h-2.5 w-2.5`}),a]})]}),!r.isOnline&&R(B,{children:[U(`span`,{children:`•`}),R(`span`,{className:`text-destructive`,children:[`offline`,u===null?``:` · ${u}`]})]})]}),R(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[U(e,{variant:l.decode?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.decode?`Decode: enabled`:`Decode: not enabled (agent capability)`,children:`Dec`}),U(e,{variant:l.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),U(e,{variant:l.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},r.id)})}),R(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[R(`span`,{children:[u,` online`]}),d>0&&R(`span`,{className:`text-destructive`,children:[d,` offline`]})]})]})}function mt({nodeId:e,refreshToken:t}){let{data:n}=o(void 0),r=n?.find(t=>t.id===e),i=ie(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?R(`div`,{className:`px-6 py-4 border-b border-border`,children:[R(`div`,{className:`flex items-center gap-2 mb-1`,children:[U(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?U(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):U(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&U(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),R(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[U(`span`,{children:r.cpuModel??`CPU`}),U(`span`,{children:`•`}),R(`span`,{children:[r.cpuCores,` cores`]}),U(`span`,{children:`•`}),R(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),i&&R(B,{children:[U(`span`,{children:`•`}),R(`span`,{children:[i.attachedCameras,` cameras (`,i.activeCameras,` active)`]}),U(`span`,{children:`•`}),R(`span`,{children:[i.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),U(`span`,{children:`•`}),R(`span`,{children:[`queue `,i.queueDepthTotal]}),i.hardware.hasGpu&&R(B,{children:[U(`span`,{children:`•`}),U(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):U(`div`,{className:`px-6 py-4 border-b border-border`,children:R(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function ht({refreshToken:e,nodeId:t}){let[n,r]=H(new Map),{nodes:i}=F();w(`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}=m(void 0),o=z(()=>{let e=new Map;for(let t of a??[])e.set(t.nodeId,t.deviceCount);return e},[a]),s=z(()=>{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=z(()=>{let e=new Map;for(let t of i)e.set(t.id,t.shortName);return e},[i]),l=z(()=>{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 R(`div`,{className:`@container/liveload`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),R(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[U(Z,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),U(Z,{label:`Cameras`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),U(Z,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),U(Z,{label:`Queue`,value:e?String(e.queueDepth):`—`}),U(Z,{label:`Audio`,value:String(o.get(t)??`—`)})]})]})}let u=[...s.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return R(`div`,{className:`@container/liveload`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),R(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[U(Z,{label:`Total agents`,value:`${l.onlineAgents}/${l.totalAgents}`}),U(Z,{label:`Cameras`,value:`${l.activeCameras}/${l.attachedCameras}`}),U(Z,{label:`Total FPS`,value:l.totalFps.toFixed(1)}),U(Z,{label:`Avg inference ms`,value:l.avgInferenceTimeMs.toFixed(0)}),U(Z,{label:`Queue depth`,value:String(l.queueDepth)})]}),U(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:R(`table`,{className:`w-full text-xs min-w-[480px]`,children:[U(`thead`,{className:`bg-surface`,children:R(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[U(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),U(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),U(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),U(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),U(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),U(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),R(`tbody`,{children:[u.map(([e,t])=>R(`tr`,{className:`border-t border-border`,children:[U(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:c.get(e)??e}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:o.get(e)??`—`})]},e)),u.length===0&&U(`tr`,{children:U(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function Z({label:e,value:t}){return R(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[U(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),U(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}L();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:K,decoder:at,audio:De},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=V(),[i,a]=H(null),[o,c]=H(null),[l,u]=H(new Map);J([`pipelineOrchestrator`,`getPipelineAssignments`],_t),J([`pipelineOrchestrator`,`getDecoderAssignments`],_t),J([`pipelineOrchestrator`,`getAudioAssignments`],_t);let{data:f}=T(void 0),{data:p}=ae(void 0),{data:m}=S(void 0),{nodes:h}=F(),{data:g}=Je();w(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&u(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),W(()=>{if(l.size===0)return;let e=setInterval(()=>{u(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)},[l.size]);let v=z(()=>{let e=new Map;for(let t of g??[])e.set(t.id,t.name);return e},[g]),y=z(()=>{let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:v.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:e===`cluster`?!0:i.agentNodeId===t,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``}})}for(let i of p??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,decoder:{active:e===`cluster`?!0:i.decoderNodeId===t,pinned:i.pinned,nodeId:i.decoderNodeId,reason:i.reason??``}})}for(let i of m??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,audio:{active:e===`cluster`?!0:i.nodeId===t,pinned:i.pinned,nodeId:i.nodeId,reason:`capacity`}})}let i=[...n.values()];return e===`agent`&&(i=i.filter(e=>e.pipeline.active||e.decoder.active||e.audio.active)),i.sort((e,t)=>e.deviceId-t.deviceId),i},[f,p,m,v,e,t]),b=z(()=>(h??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[h]),x=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})},C=re({onSuccess:x}),D=E({onSuccess:x}),O=d({onSuccess:x}),k=pe({onSuccess:x}),A=s({onSuccess:x}),j=de({onSuccess:x}),M=(e,t,n)=>{t===`pipeline`?C.mutate({deviceId:e,agentNodeId:n}):t===`decoder`?O.mutate({deviceId:e,nodeId:n}):A.mutate({deviceId:e,nodeId:n}),a(null)},N=(e,t)=>{t===`pipeline`?D.mutate({deviceId:e}):t===`decoder`?k.mutate({deviceId:e}):j.mutate({deviceId:e}),a(null)};return U(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:R(`table`,{className:`w-full text-xs min-w-[640px]`,children:[U(`thead`,{className:`bg-surface`,children:R(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&U(`th`,{className:`w-6`}),U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?R(B,{children:[U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):R(B,{children:[U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Pipeline`}),U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Decoder`}),U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Audio`})]}),U(`th`,{className:`text-left px-3 py-2 align-middle`,children:`Status`})]})}),R(`tbody`,{children:[y.map(t=>{let r=l.get(t.deviceId),s=o===t.deviceId;return R(_e.Fragment,{children:[R(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&U(`td`,{className:`px-2 py-2 align-middle`,children:U(`button`,{type:`button`,onClick:()=>c(s?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":s?`Collapse broker details`:`Expand broker details`,children:U(s?Be:ze,{className:`h-3.5 w-3.5`})})}),R(`td`,{className:`px-3 py-2 align-middle`,children:[U(`div`,{className:`text-foreground font-medium leading-tight`,children:t.deviceName}),R(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?R(B,{children:[U(`td`,{className:`px-3 py-2 align-middle`,children:U(xt,{state:t.pipeline,onlineNodes:b,pending:C.isPending||D.isPending,onChange:e=>{e===`auto`?N(t.deviceId,`pipeline`):M(t.deviceId,`pipeline`,e)}})}),U(`td`,{className:`px-3 py-2 align-middle`,children:U(St,{state:t.pipeline})})]}):R(B,{children:[U(Ct,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:b,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=>M(t.deviceId,`pipeline`,e),onUnpin:()=>N(t.deviceId,`pipeline`)}),U(Ct,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:b,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`decoder`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`decoder`?null:{deviceId:t.deviceId,role:`decoder`}),onCloseMenu:()=>a(null),onMove:e=>M(t.deviceId,`decoder`,e),onUnpin:()=>N(t.deviceId,`decoder`)}),U(Ct,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:b,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=>M(t.deviceId,`audio`,e),onUnpin:()=>N(t.deviceId,`audio`)})]}),U(`td`,{className:`px-3 py-2 align-middle`,children:U(Et,{snap:r})})]}),s&&!n&&R(`tr`,{className:`bg-surface/50`,children:[U(`td`,{}),U(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2`,children:U(_,{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)}),y.length===0&&U(`tr`,{children:U(`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({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 R(`select`,{value:i,disabled:n,"aria-label":`Pipeline placement pin`,onChange:e=>r(e.target.value),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[U(`option`,{value:`auto`,children:`Auto`}),a.map(e=>R(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function St({state:e}){return!e.active||!e.nodeId?U(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`}):R(`div`,{className:`flex flex-col leading-tight`,children:[U(`span`,{className:`font-mono text-[11px] text-foreground`,children:e.nodeId}),U(`span`,{className:e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`,children:e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`})]})}function Ct({role:e,state:t,mode:n,onlineNodes:r,isMenuOpen:i,onToggleMenu:a,onCloseMenu:o,onMove:s,onUnpin:c}){let l=vt[e],u=r.filter(e=>e.id!==(t.nodeId??``)),d=(t.active||n===`cluster`)&&(u.length>0||t.pinned);return R(`td`,{className:`px-3 py-2 align-middle relative`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(n===`agent`?wt:Tt,{state:t,Icon:l}),U(`div`,{className:`ml-auto`,children:d&&U(`button`,{type:`button`,onClick:a,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${yt[e]} actions`,children:U(it,{className:`h-3 w-3 text-foreground-subtle`})})})]}),i&&d&&U(Dt,{title:yt[e],targets:u,pinned:t.pinned,onMove:s,onUnpin:c,onClose:o})]})}function wt({state:e,Icon:t}){return R(`div`,{className:`flex items-center gap-1.5`,children:[U(e.active?Pe:Fe,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),U(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&U(st,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Tt({state:e,Icon:t}){return!e.active||!e.nodeId?R(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[U(t,{className:`h-3 w-3`}),U(`span`,{className:`text-[10px] italic`,children:`—`})]}):R(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[U(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),R(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[U(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),U(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?R(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[U(st,{className:`h-2.5 w-2.5`}),` manual`]}):R(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}function Et({snap:e}){if(!e)return U(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:i,configuredFps:a,droppedFrames:o}=e.metrics,s=l(t);return R(`div`,{className:`flex flex-col gap-0.5 font-mono text-[10px] tabular-nums leading-tight`,children:[R(`span`,{className:`inline-flex items-center gap-1 ${s.textColor}`,children:[U(C,{phase:t,className:`h-2.5 w-2.5`}),U(`span`,{className:`font-semibold uppercase tracking-wider`,children:s.label})]}),R(`span`,{className:`text-foreground-subtle`,children:[U(`span`,{className:`text-foreground`,children:n.toFixed(1)}),R(`span`,{children:[`/`,a.toFixed(0),` fps`]})]}),R(`span`,{className:`text-foreground-subtle`,children:[U(`span`,{className:`text-foreground`,children:r.toFixed(0)}),U(`span`,{children:` ms`}),i>0&&R(`span`,{className:`text-warning ml-1`,children:[`q`,i]})]}),R(`span`,{className:o>0?`text-warning`:`text-foreground-subtle`,children:[`drops `,U(`span`,{className:`text-foreground`,children:o})]})]})}function Dt({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=ge(null);return W(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),R(`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:[U(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&U(`div`,{className:`py-1`,children:t.map(e=>R(`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&&R(`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&&U(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Ot({nodeId:e,refreshToken:t}){return R(`div`,{className:`space-y-6`,children:[U(ht,{refreshToken:t,nodeId:e}),R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),R(`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.`]})]}),U(bt,{mode:`agent`,nodeId:e,compact:!0})]})}L();function kt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function At({nodeId:e,refreshToken:t}){let n=V(),i=c({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:a}=y({nodeId:e}),o=ie(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??a??null,s=o===null;J([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:l}=r({nodeId:e}),{values:u}=N(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),d=z(()=>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?`)||i.mutate({nodeId:e,engine:t,force:n.length>0})};return R(`div`,{className:`space-y-6`,children:[R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),R(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(o??[]).length,` engine(s) resident in RAM. `,(l??[]).length,` `,`camera(s) attached, `,d,` actively dispatching frames. Refreshes every 5s.`]})]}),U(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:R(`table`,{className:`w-full text-xs min-w-[640px]`,children:[U(`thead`,{className:`bg-surface`,children:R(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[U(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),U(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),U(`th`,{className:`text-left px-3 py-2`,children:`Models`}),U(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),U(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),U(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),U(`th`,{className:`w-20`})]})}),R(`tbody`,{children:[s&&U(`tr`,{children:U(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!s&&(o??[]).map(e=>{let t=e.kind===`warm-override`;return R(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:``}`,children:[U(`td`,{className:`px-3 py-2`,children:R(`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`:`bg-success/15 text-success`}`,children:[U(t?ot:K,{className:`h-3 w-3`}),t?`warm`:`runtime`]})}),U(`td`,{className:`px-3 py-2`,children:R(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[U(Oe,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),U(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?U(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):U(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>U(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),U(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),U(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?U(`span`,{className:`text-foreground-subtle`,children:kt(e.idleMs,e.idleTtlMs)}):U(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),U(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(l??[]).length}),U(`td`,{className:`px-3 py-2 text-right`,children:R(`button`,{type:`button`,disabled:i.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:[U(Ge,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!s&&(o??[]).length===0&&U(`tr`,{children:U(`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.`})})]})]})}),R(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[U(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,U(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`]}),i.isError&&R(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,i.error instanceof Error?i.error.message:`unknown`]})]})}L();var jt=new Set(ye);function Mt(e){return jt.has(e)}function Nt(e,t,n){return`${e}/${t}/${n}`}function Pt(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function Ft(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 It(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 Lt({addonId:e,model:t,format:n,isActive:r,progress:i,errorMsg:a,onDownload:o,onDelete:s}){let c=t.formats[n];return c?R(`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:[U(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),R(`div`,{className:`flex-1 min-w-0`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),R(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&R(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[U(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:U(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),R(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),U(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:nt(c.sizeMB)}),a&&R(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[U(Ue,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?R(`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?U(q,{className:`h-3 w-3 animate-spin`}):U(Ge,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):R(`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?U(q,{className:`h-3 w-3 animate-spin`}):U(xe,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function Rt({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=H(!1);return R(`div`,{className:`relative`,children:[R(`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:[U(K,{className:`h-4 w-4 text-primary shrink-0`}),R(`div`,{className:`flex-1 min-w-0`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`text-sm font-medium text-foreground`,children:Pt(n)}),Q(n)===Q(t)&&U(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),U(`div`,{className:`text-[10px] text-foreground-subtle`,children:Ft(n)})]}),U(Be,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&U(`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 R(`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:[U(K,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),R(`div`,{className:`flex-1`,children:[R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:Pt(e)}),o&&U(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),U(`div`,{className:`text-[10px] text-foreground-subtle`,children:Ft(e)})]}),i&&U(Ie,{className:`h-4 w-4 text-primary shrink-0`})]},Q(e))})})]})}function zt({embedded:e=!1,nodeId:n}={}){let r=V(),i=n??`hub`,[a,o]=H(null),[s,c]=H(new Set),[l,u]=H(new Map),[d,p]=H(new Map),[m,h]=H(``),{data:_=[]}=me({nodeId:i}),v=_.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:y}=b({nodeId:i}),x=y,{data:S,isLoading:C}=t({nodeId:i}),T=g(),E=f();w(`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 D=x??{runtime:`node`,backend:`cpu`,format:`onnx`},O=v.find(e=>e.format===a)??D,k=O.format,A=S?.slots??[],j=A.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(e=>e.formats[k]!==void 0)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),M=It(j,k),N=he(async(e,t,n)=>{if(!Mt(n))return;let a=Nt(e,t,n);c(e=>new Set([...e,a])),p(e=>{let t=new Map(e);return t.delete(a),t});try{await T.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(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})}},[T,r,i]),P=he(async(e,t,n)=>{if(!Mt(n))return;let a=Nt(e,t,n);c(e=>new Set([...e,a])),p(e=>{let t=new Map(e);return t.delete(a),t});try{await E.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(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})}},[E,r,i]),ee=he(e=>{o(e.format)},[]),F=m.trim()?j.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):j,I=R(B,{children:[C&&U(`div`,{className:`flex items-center justify-center py-16`,children:U(q,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!C&&A.length===0&&R(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[U(Se,{className:`h-8 w-8 mb-3 opacity-30`}),U(`span`,{className:`text-sm`,children:`No pipeline steps available`}),U(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!C&&A.length>0&&R(B,{children:[U(Rt,{engines:v,activeEngine:D,viewEngine:O,onSelect:ee}),R(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[R(`span`,{children:[U(`span`,{className:`font-semibold text-foreground tabular-nums`,children:M.total}),U(`span`,{className:`ml-1`,children:`compatible models`})]}),U(`span`,{className:`text-border`,children:`|`}),R(`span`,{children:[U(`span`,{className:`font-semibold text-success tabular-nums`,children:M.downloaded}),U(`span`,{className:`ml-1`,children:`downloaded`})]}),U(`span`,{className:`text-border`,children:`|`}),R(`span`,{className:`tabular-nums`,children:[nt(M.downloadedSizeMB),U(`span`,{className:`ml-1`,children:`on disk`})]})]}),M.total>5&&R(`div`,{className:`relative`,children:[U(Me,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),U(`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`})]}),F.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[k]?.downloaded).length,0);return R(`div`,{children:[R(`div`,{className:`flex items-center gap-2 mb-2`,children:[U(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),U(`div`,{className:`flex-1 h-px bg-border`}),R(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),U(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=Nt(e.id,t.id,k);return U(Lt,{addonId:e.id,model:t,format:k,isActive:s.has(n),progress:l.get(t.id),errorMsg:d.get(n),onDownload:()=>N(e.id,t.id,k),onDelete:()=>P(e.id,t.id,k)},`${e.id}/${t.id}`)}))})]},e.id)}),F.length===0&&U(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:m.trim()?R(B,{children:[`No models matching “`,m,`”`]}):R(B,{children:[`No models available for `,Pt(O),` format`]})})]})]});return e?U(`div`,{className:`space-y-4`,children:I}):U(qe,{children:I})}function Bt({nodeId:e,refreshToken:t}){return U(zt,{embedded:!0,nodeId:e})}var Vt=[{concern:`pipeline`,label:`Pipeline`,advisory:!1},{concern:`audio`,label:`Audio`,advisory:!1},{concern:`decode`,label:`Decode`,advisory:!0,advisoryNote:`Advisory: decode currently runs co-located with the stream source (hub). Pins are stored and take effect with Phase-2 stream load-balancing.`}];function Ht(e,t){return e.filter(e=>e.currentNodeId!==t)}var Ut=`This node is not decoder-enabled (enabledDecoderNodes). Pinning detection here strands frames (0 fps) until frame-source-aware placement ships. Enable decode on this node first, or pick a decoder-enabled node.`;function Wt(e,t,n){return t.includes(e)?{verdict:`ok`}:n?{verdict:`warn`,reason:Ut}:{verdict:`block`,reason:Ut}}L();var Gt=`pipeline-orchestrator`,Kt=`enabledDecoderNodes`;function qt(e,t){if(!e||typeof e!=`object`)return;let n=e.sections;if(Array.isArray(n))for(let e of n){if(!e||typeof e!=`object`)continue;let n=e.fields;if(Array.isArray(n))for(let e of n){if(!e||typeof e!=`object`)continue;let n=e;if(n.key!==t)continue;let r=n.value;return Array.isArray(r)&&r.every(e=>typeof e==`string`)?r:void 0}}}function Jt({nodeId:e,nodeName:t,concern:n,open:r,onClose:i}){let a=V(),o=Je(),c=T(void 0),l=ae(void 0),u=S(void 0),f=P({addonId:Gt}),p=re(),m=d(),h=s(),[g,_]=H(new Set),[v,y]=H(!1),[b,x]=H(null),[C,w]=H([]),[E,D]=H(null),O=Vt.find(e=>e.concern===n),k=z(()=>{let e=new Map;if(n===`pipeline`)for(let t of c.data??[])e.set(t.deviceId,t.agentNodeId);else if(n===`decode`)for(let t of l.data??[])e.set(t.deviceId,t.decoderNodeId);else for(let t of u.data??[])e.set(t.deviceId,t.nodeId);return e},[n,c.data,l.data,u.data]),A=z(()=>(o.data??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,currentNodeId:k.get(e.id)??null})),[o.data,k]),j=z(()=>Ht(A,e),[A,e]),M=qt(f.data,Kt),N=n===`pipeline`?Wt(e,M??[],!1):{verdict:`ok`},[ee,F]=H(!1);if(!r)return null;let I=N.verdict===`block`,te=N.verdict===`warn`&&!ee,ne=g.size>0&&!v&&!I&&!te,ie=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},oe=j.length>0&&j.every(e=>g.has(e.deviceId)),se=()=>{_(oe?new Set:new Set(j.map(e=>e.deviceId)))},ce=async t=>{n===`pipeline`?await p.mutateAsync({deviceId:t,agentNodeId:e}):n===`decode`?await m.mutateAsync({deviceId:t,nodeId:e}):await h.mutateAsync({deviceId:t,nodeId:e})},le=new Map(A.map(e=>[e.deviceId,e.name]));return R(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[U(`div`,{className:`absolute inset-0 bg-black/60`,onClick:i}),R(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col h-[80vh] rounded-xl border border-border bg-background shadow-2xl`,children:[R(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[R(`div`,{className:`min-w-0`,children:[R(`h2`,{className:`text-sm font-semibold text-foreground`,children:[`Batch assign `,O?.label??n,` → `,t]}),R(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:[`Pick the cameras whose `,O?.label.toLowerCase()??n,` should run on this node.`]})]}),U(`button`,{type:`button`,onClick:i,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,"aria-label":`Close`,children:U(He,{className:`h-4 w-4`})})]}),R(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[O?.advisory&&O.advisoryNote&&U(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 px-3 py-2 shrink-0`,children:R(`div`,{className:`flex items-start gap-2`,children:[U(We,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),U(`p`,{className:`text-[11px] text-warning`,children:O.advisoryNote})]})}),N.verdict!==`ok`&&U(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 shrink-0`,children:R(`div`,{className:`flex items-start gap-2`,children:[U(We,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),R(`div`,{className:`min-w-0`,children:[U(`p`,{className:`text-[11px] text-destructive`,children:N.reason}),N.verdict===`warn`&&R(`label`,{className:`mt-1 flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[U(`input`,{type:`checkbox`,checked:ee,onChange:e=>F(e.target.checked),className:`accent-primary`}),`I understand — assign anyway`]})]})]})}),j.length>0&&R(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle shrink-0`,children:[U(`input`,{type:`checkbox`,"aria-label":`Select all`,checked:oe,onChange:se,className:`accent-primary`}),`Select all (`,j.length,`)`]}),U(`div`,{className:`flex-1 min-h-0 overflow-y-auto rounded-lg border border-border divide-y divide-border`,children:j.length===0?R(`div`,{className:`px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:[`No eligible cameras — all cameras are already assigned to `,t,`.`]}):j.map(e=>R(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground hover:bg-surface-hover cursor-pointer`,children:[U(`input`,{type:`checkbox`,"aria-label":`Select ${e.name}`,checked:g.has(e.deviceId),onChange:()=>ie(e.deviceId),className:`accent-primary`}),U(`span`,{className:`truncate`,children:e.name}),e.currentNodeId&&R(`span`,{className:`ml-auto text-[10px] text-foreground-subtle shrink-0`,children:[`on `,e.currentNodeId]})]},e.deviceId))}),(E!==null||C.length>0)&&R(`div`,{className:`space-y-1 text-[10px] shrink-0`,children:[E!==null&&E>0&&R(`p`,{className:`text-success`,children:[`Assigned `,E,` camera(s) to `,t,`.`]}),C.map(e=>R(`p`,{className:`text-destructive`,children:[e.name,`: `,e.message]},e.deviceId))]})]}),R(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[U(`span`,{className:`text-[10px] text-foreground-subtle`,children:v&&b?`${b.done} / ${b.total}…`:``}),R(`div`,{className:`flex items-center gap-2`,children:[U(`button`,{type:`button`,onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Close`}),R(`button`,{type:`button`,onClick:async()=>{let e=[...g];if(e.length===0)return;y(!0),w([]),D(null),x({done:0,total:e.length});let t=[],n=0;for(let r=0;r<e.length;r+=1){let i=e[r];try{await ce(i),n+=1}catch(e){t.push({deviceId:i,name:le.get(i)??String(i),message:e instanceof Error?e.message:String(e)})}x({done:r+1,total:e.length})}y(!1),w(t),D(n),_(new Set),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})},disabled:!ne,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50 disabled:cursor-not-allowed`,children:[v&&U(q,{className:`h-3.5 w-3.5 animate-spin`}),`Assign `,g.size,` to `,t]})]})]})]})]})}L();function Yt({nodeId:e,title:t}){let{data:n}=Je(),{data:r}=T(void 0),i=z(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),a=z(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),[o,s]=H(new Map);w(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||s(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),W(()=>{if(o.size===0)return;let e=setInterval(()=>{s(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)},[o.size]);let c=z(()=>{let e=[];for(let t of o.values())a&&!a.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[o,a]);return c.length===0?R(`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`]}):R(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[R(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[U(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),U(`span`,{className:`text-[10px] text-foreground-subtle`,children:c.length})]}),U(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>{let t=i.get(e.deviceId)??`#${e.deviceId}`,n=l(e.metrics.phase);return R(`div`,{title:`${t} · ${n.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] ${n.badgeClass}`,children:[U(C,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),U(`span`,{className:`font-medium text-foreground/90 max-w-[120px] truncate`,children:t}),U(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),U(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var Xt={key:`maxCameras`,type:`slider`,label:`Max cameras`,description:`Hard cap on cameras the balancer may assign to this node.`,min:1,max:64,step:1,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Unlimited`};L();var Zt=350;function Qt(e){return typeof e==`number`&&e>0?Math.floor(e):null}function $t({value:e,pending:t,errorMessage:r,onCommit:i}){let[a,o]=H(e);W(()=>{o(e)},[e]);let s=ge(i);return s.current=i,W(()=>{if(a===e)return;let t=setTimeout(()=>s.current(a),Zt);return()=>clearTimeout(t)},[a,e]),R(`div`,{className:`flex items-center gap-3 text-xs text-foreground`,children:[U(`div`,{className:`max-w-md flex-1`,children:U(n,{field:Xt,values:{maxCameras:a},disabled:t,onChange:(e,t)=>o(Qt(t))})}),t&&U(`span`,{className:`text-[10px] text-muted-foreground animate-pulse`,children:`Saving…`}),r&&R(`span`,{className:`text-[10px] text-destructive`,children:[`Save failed: `,r]})]})}L();var en=[`pipeline-orchestrator`],tn=[`decoder`];function nn(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function rn({nodeId:e,refreshToken:n}){let r=V(),[i,a]=H(null),[s,c]=H(null),[l,u]=H(null),d=(o(void 0).data??[]).find(t=>t.id===e)?.name??e,f=t({nodeId:e},{refetchOnMount:`always`}),p=x({agentNodeId:e},{refetchOnMount:`always`}),m=()=>{r.invalidateQueries({queryKey:[[`addonSettings`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),r.invalidateQueries({queryKey:[[`pipelineExecutor`]]})},h=ue({onSuccess:m}),g=ne({onSuccess:m}),_=f.data??null,v=p.data,y=_?.selectedEngine.format??`coreml`,b=z(()=>_?le(_):[],[_]),S=z(()=>[{agentNodeId:e,engineLabel:y}],[e,y]),C=(e,t)=>{let n=v?.addonDefaults[e];return!nn(_,e)?.models.some(e=>!!e.formats[y])||!n?{kind:`na`}:n.enabled?{kind:`enabled`,modelId:n.modelId}:{kind:`disabled`}},w=i&&_?nn(_,i.addonId):null,T=t=>{let n=v?.addonDefaults[t]??null;a({addonId:t,agentNodeId:e}),c(n)},E=(t,n)=>{if(!v)return;let r=v.addonDefaults[t],i=nn(_,t);if(!r&&!i)return;let a={enabled:n,modelId:r?.modelId??i?.defaultModelId??``,settings:r?.settings??{}};h.mutate({agentNodeId:e,defaults:{...v.addonDefaults,[t]:a}})},O=()=>{a(null),c(null)},A=()=>{!s||!i||!v||h.mutate({agentNodeId:e,defaults:{...v.addonDefaults,[i.addonId]:s}},{onSuccess:O})};if(f.isLoading||p.isLoading)return U(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading pipeline…`});if(f.error)return R(`div`,{className:`text-xs text-red-400`,children:[`Failed to load catalog: `,String(f.error)]});if(!_)return U(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog unavailable for this node (runner offline?).`});let j=i!==null&&w!==null&&s!==null,M=p.data?.maxCameras??null;return R(`div`,{className:`relative h-full w-full space-y-3`,children:[U(Yt,{nodeId:e}),U($t,{value:M,pending:g.isPending,errorMessage:g.isError?g.error instanceof Error?g.error.message:`Unknown error`:null,onCommit:t=>g.mutate({agentNodeId:e,maxCameras:t})}),U(rt,{nodeId:e,addonIds:en,level:`global`,sectionIds:tn}),R(`div`,{className:`flex items-center gap-2 text-xs`,children:[U(`span`,{className:`font-medium text-muted-foreground`,children:`Batch assign:`}),U(`button`,{type:`button`,onClick:()=>u(`pipeline`),className:`rounded border border-border bg-surface px-2 py-0.5 text-xs hover:bg-surface-hover`,children:`Pipeline…`}),U(`button`,{type:`button`,onClick:()=>u(`audio`),className:`rounded border border-border bg-surface px-2 py-0.5 text-xs hover:bg-surface-hover`,children:`Audio…`}),U(`button`,{type:`button`,onClick:()=>u(`decode`),className:`rounded border border-border bg-surface px-2 py-0.5 text-xs text-foreground-subtle hover:bg-surface-hover`,children:`Decode… (advisory)`})]}),l&&U(Jt,{nodeId:e,nodeName:d,concern:l,open:l!==null,onClose:()=>u(null)}),U(`div`,{className:j?`pr-[360px]`:``,children:b.length>0?U(oe,{tree:b,agents:S,getCellState:C,onCellClick:T,selectedCell:i,onToggleEnabled:E}):U(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),U(k,{open:j,onClose:O,title:w?.name??``,subtitle:i?`${i.agentNodeId} · ${y}`:``,footer:R(B,{children:[U(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:O,children:`Cancel`}),U(`button`,{type:`button`,disabled:!s||!i||h.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:A,children:h.isPending?`Saving…`:`Save`})]}),children:w&&s&&i&&U(D,{mode:`agent`,addon:w,agentDefault:s,agentNodeId:i.agentNodeId,engineFormat:y,onChangeAgentConfig:e=>c(e)})})]})}var an=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],on=`decoder-nodeav`;function sn({nodeId:e,refreshToken:t}){let{data:n}=o(void 0),r=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??on,i=[...an,r];return R(`div`,{className:`flex flex-col h-full`,children:[U(mt,{nodeId:e,refreshToken:t}),U(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:U(rt,{nodeId:e,addonIds:i,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:U(Ot,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:U(rn,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:U(At,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:U(Bt,{nodeId:e,refreshToken:t})}]})})]})}L();var cn=`pipeline-orchestrator`,ln=`recorder`,un=`recordingNodeId`,dn=[`ingestNode`,`recordingNode`,`audioNode`],fn=[`detect`,`decode`,`audio`,`ingest`];function pn(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function mn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function hn(e,t,n){let r=pn(e,t);return typeof r==`string`&&r.length>0?r:n}function gn(e,t,n){let r=pn(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function _n(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function vn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:`Audio`}function yn(e,t){return t===`detect`?e.pipeline:e[t]}function bn({role:e,value:t,options:n,pending:r,onChange:i}){return R(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground-subtle`,children:[U(`span`,{className:`font-medium text-foreground`,children:vn(e)}),U(`select`,{value:t,disabled:r,onChange:t=>i(e,t.target.value),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:n.map(e=>U(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))})]})}function xn({nodeId:e,weight:t,totalWeight:n,pending:r,onCommit:i}){let[a,o]=H(String(t));W(()=>{o(String(t))},[t]);let s=n>0?t/n:0,c=2*Math.PI*14,l=c*s,u=()=>{let t=Number(a);i(e,Number.isFinite(t)&&t>0?t:null)};return R(`div`,{className:`flex items-center gap-2`,children:[R(`svg`,{viewBox:`0 0 36 36`,className:`h-9 w-9 shrink-0`,"aria-hidden":`true`,children:[U(`circle`,{cx:`18`,cy:`18`,r:14,fill:`none`,className:`stroke-border`,strokeWidth:`4`}),U(`circle`,{cx:`18`,cy:`18`,r:14,fill:`none`,className:`stroke-primary`,strokeWidth:`4`,strokeDasharray:`${l} ${c-l}`,strokeLinecap:`round`,transform:`rotate(-90 18 18)`}),U(`text`,{x:`18`,y:`20`,textAnchor:`middle`,className:`fill-foreground text-[8px] font-bold`,children:Math.round(s*100)})]}),U(`input`,{"aria-label":`Detect weight for ${e}`,type:`number`,min:0,step:.25,value:a,disabled:r,onChange:e=>o(e.target.value),onBlur:u,onKeyDown:e=>{e.key===`Enter`&&u()},className:`w-20 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`})]})}function Sn({nodeId:e,value:t,pending:n,onCommit:r}){let[i,a]=H(t===null?``:String(t));W(()=>{a(t===null?``:String(t))},[t]);let o=()=>{let t=Number(i);r(e,Number.isFinite(t)&&t>0?Math.floor(t):null)};return U(`input`,{"aria-label":`Max cameras for ${e}`,type:`number`,min:0,step:1,placeholder:`∞`,value:i,disabled:n,onChange:e=>a(e.target.value),onBlur:o,onKeyDown:e=>{e.key===`Enter`&&o()},className:`w-20 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`})}function Cn(){let e=V(),{nodes:t}=F(),n=I(void 0),r=P({addonId:cn}),i=P({addonId:ln}),a=()=>_n(e),o=A({onSuccess:a}),s=M({onSuccess:a}),c=ne({onSuccess:a}),l=te({onSuccess:a}),u=z(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),d=z(()=>t.map(e=>{let t=u.get(e.id),n=dt(t,e.isHub);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:typeof mn(t,`detectWeight`)==`number`?Number(mn(t,`detectWeight`)):1}}),[t,u]),f=d.filter(e=>e.effective.pipeline).reduce((e,t)=>e+t.weight,0),p={ingestNode:hn(r.data,`ingestNode`,`hub`),recordingNode:hn(i.data,un,`hub`),audioNode:hn(r.data,`audioNode`,`hub`)},m=z(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...dn.map(e=>p[e]),...e])].filter(e=>e.length>0)},[t,p]),h=gn(r.data,`fpsMinThreshold`,0),g=h>0,_=(e,t,n)=>{o.mutate({agentNodeId:e,[t]:n})},v=(e,t)=>{if(e===`recordingNode`){l.mutate({addonId:ln,patch:{[un]:t}});return}l.mutate({addonId:cn,patch:{[e]:t}})},y=e=>{l.mutate({addonId:cn,patch:{fpsMinThreshold:e?Math.max(1,h):0}})};return R(`section`,{className:`rounded-lg border border-border bg-surface p-4 space-y-4`,children:[R(`div`,{className:`flex items-start justify-between gap-3`,children:[R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Table-board placement controls`}),U(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Enable node roles, tune relative detection weights, set camera ceilings, and choose singleton cluster roles. Weights are relative shares across detect-capable nodes.`})]}),(n.isLoading||r.isLoading||i.isLoading)&&U(q,{className:`h-4 w-4 animate-spin text-foreground-subtle`})]}),R(`div`,{className:`grid gap-3 @md/clustertab:grid-cols-4`,children:[dn.map(e=>U(bn,{role:e,value:p[e],options:m,pending:l.isPending,onChange:v},e)),R(`label`,{className:`flex items-center gap-2 rounded-md border border-border bg-background px-3 py-2 text-xs text-foreground`,children:[U(`input`,{type:`checkbox`,checked:g,disabled:l.isPending,onChange:e=>y(e.target.checked),className:`h-4 w-4`}),R(`span`,{className:`flex flex-col`,children:[U(`span`,{className:`font-medium`,children:`Enable low-fps relocate/shed`}),R(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`fpsMinThreshold `,g?`${h} fps`:`disabled`]})]})]})]}),U(`div`,{className:`overflow-x-auto rounded-md border border-border`,children:R(`table`,{className:`w-full min-w-[760px] text-xs`,children:[U(`thead`,{className:`bg-background`,children:R(`tr`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[U(`th`,{className:`px-3 py-2 text-left`,children:`Node`}),U(`th`,{className:`px-3 py-2 text-center`,children:`Detect`}),U(`th`,{className:`px-3 py-2 text-center`,children:`Decode`}),U(`th`,{className:`px-3 py-2 text-center`,children:`Audio`}),U(`th`,{className:`px-3 py-2 text-center`,children:`Ingest`}),U(`th`,{className:`px-3 py-2 text-left`,children:`Detect weight`}),U(`th`,{className:`px-3 py-2 text-left`,children:`Max cameras`})]})}),U(`tbody`,{children:d.map(e=>R(`tr`,{className:`border-t border-border ${e.isOnline?``:`opacity-50`}`,children:[R(`td`,{className:`px-3 py-2`,children:[U(`div`,{className:`font-medium text-foreground`,children:e.name}),R(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,children:[e.id,e.isHub?` · hub`:``,e.isOnline?``:` · offline`]})]}),fn.map(t=>U(`td`,{className:`px-3 py-2 text-center`,children:U(`input`,{"aria-label":`${t} capability for ${e.id}`,type:`checkbox`,checked:yn(e.effective,t),disabled:o.isPending,onChange:n=>_(e.id,t,n.target.checked),className:`h-4 w-4`})},t)),U(`td`,{className:`px-3 py-2`,children:e.effective.pipeline?U(xn,{nodeId:e.id,weight:e.weight,totalWeight:f,pending:s.isPending,onCommit:(e,t)=>s.mutate({agentNodeId:e,detectWeight:t})}):U(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`Detect off`})}),U(`td`,{className:`px-3 py-2`,children:U(Sn,{nodeId:e.id,value:typeof mn(e.settings,`maxCameras`)==`number`?Number(mn(e.settings,`maxCameras`)):null,pending:c.isPending,onCommit:(e,t)=>c.mutate({agentNodeId:e,maxCameras:t})})})]},e.id))})]})})]})}L();function wn({refreshToken:e}){let t=V(),{data:n}=o(void 0),r=z(()=>tt(n??[]),[n]),i=O({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return R(`div`,{className:`space-y-6`,children:[U(ht,{refreshToken:e}),U(Cn,{}),R(`section`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Cluster map`}),U(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`React Flow topology map retained as the visual placement map; use the table-board above as the control surface.`})]}),U(`div`,{className:`h-[360px] rounded-md border border-border overflow-hidden bg-background`,children:U(Qe,{graph:r})})]}),R(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[R(`div`,{className:`min-w-0`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),U(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · decoder · audio assignments per camera. Click the kebab to pin / unpin / move any role; expand the chevron for the per-camera broker drill-down.`})]}),R(`button`,{type:`button`,onClick:()=>i.mutate(void 0),disabled:i.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:[U(Oe,{className:`h-3.5 w-3.5`}),i.isPending?`Rebalancing…`:`Rebalance pipelines`]})]}),U(bt,{mode:`cluster`})]})}var Tn=[`pipeline-orchestrator`];function En({refreshToken:e}){return U(`div`,{className:`space-y-4 max-w-3xl`,children:U(rt,{nodeId:`hub`,addonIds:Tn,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.`})})}L();function Dn({refreshToken:e}){let t=V(),{data:n,isLoading:r}=se(),[i,a]=H(null),[o,s]=H(``),[c,l]=H(``),d=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},f=fe({onSuccess:()=>{a(null),d()}}),p=u({onSuccess:d}),m=e=>{a(e.id),s(e.name),l(e.description??``)},h=()=>{a(null),s(``),l(``)},g=()=>{if(!i)return;let e=c.trim();f.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return U(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let _=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return U(`div`,{className:`space-y-6 max-w-4xl`,children:R(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[R(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[R(`div`,{children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),U(`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.`})]}),R(`div`,{className:`text-[11px] text-foreground-subtle`,children:[_.length,` template`,_.length===1?``:`s`]})]}),_.length===0?R(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[U(Ae,{className:`h-6 w-6 opacity-40`}),U(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):U(`ul`,{className:`divide-y divide-border`,children:_.map(e=>{let t=i===e.id;return U(`li`,{className:`px-4 py-3 text-xs`,children:R(`div`,{className:`flex items-start gap-3`,children:[U(`div`,{className:`flex-1 min-w-0`,children:t?R(`div`,{className:`space-y-2`,children:[U(`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}),U(`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)`})]}):R(B,{children:[U(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&U(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),R(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[`engine `,e.config.engine.runtime,`/`,e.config.engine.backend,` ·`,` `,e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,R(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),U(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?R(B,{children:[R(`button`,{type:`button`,onClick:g,disabled:f.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:[U(Le,{className:`h-3 w-3`}),`Save`]}),R(`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:[U(He,{className:`h-3 w-3`}),`Cancel`]})]}):R(B,{children:[U(`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:U(ke,{className:`h-3 w-3`})}),U(`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:U(Ge,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}L();function On(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 kn({nodeId:e,refreshToken:n}){let r=V(),i=be().trpcClient,[a,s]=H(null),[c,l]=H(null),u=I(void 0,{refetchOnMount:`always`});J([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`,`addon.updated`]);let d=o(void 0,{refetchOnMount:`always`}),f=z(()=>{let e=new Set;for(let t of d.data??[])t.isOnline&&e.add(t.id);return e},[d.data]),p=t({nodeId:e},{refetchOnMount:`always`}),m=z(()=>(u.data??[]).filter(e=>f.has(e.nodeId)).map(e=>e.nodeId),[u.data,f]),h=ve({enabled:m.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`schema-by-agent`,m.join(`,`),n],queryFn:async()=>{let e={};for(let t of m)try{e[t]=(await i.pipelineExecutor.getSchema.query({nodeId:t})).selectedEngine.format}catch{e[t]=`coreml`}return e}}),g=ue({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),r.invalidateQueries({queryKey:[[`pipelineExecutor`]]}),r.invalidateQueries({queryKey:[[`addonSettings`]]})}}),_=z(()=>p.data?le(p.data):[],[p.data]),v=z(()=>{let e=u.data??[],t=f;return(t.size===0?[]:e.filter(e=>t.has(e.nodeId))).map(e=>{let t=h.data?.[e.nodeId];return{agentNodeId:e.nodeId,engineLabel:t??`(engine unknown)`}})},[u.data,h.data,f]),y=(e,t)=>{let n=(u.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e],r=h.data?.[t];return!On(p.data??null,e)?.models.some(e=>r!==void 0&&!!e.formats[r])||!n?{kind:`na`}:n.enabled?{kind:`enabled`,modelId:n.modelId}:{kind:`disabled`}},b=a?u.data?.find(e=>e.nodeId===a.agentNodeId)??null:null,x=a&&p.data?On(p.data,a.addonId):null,S=a?h.data?.[a.agentNodeId]??`coreml`:`coreml`,C=()=>{s(null),l(null)},w=(e,t)=>{let n=(u.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e]??null;s({addonId:e,agentNodeId:t}),l(n)},T=()=>{!c||!a||!b||g.mutate({agentNodeId:a.agentNodeId,defaults:{...b.settings.addonDefaults,[a.addonId]:c}},{onSuccess:C})};if(u.isLoading||p.isLoading)return U(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading agents…`});if(!p.data)return R(`div`,{className:`text-xs text-foreground-subtle`,children:[`Catalog unavailable for `,e,`.`]});let E=a!==null&&x!==null&&c!==null;return R(`div`,{className:`relative h-full w-full space-y-3`,children:[U(Yt,{title:`Cluster cameras`}),U(`div`,{className:E?`pr-[360px]`:``,children:_.length>0&&v.length>0?U(oe,{tree:_,agents:v,getCellState:y,onCellClick:w,selectedCell:a}):U(`div`,{className:`text-xs text-foreground-subtle`,children:`No agents or catalog empty.`})}),U(k,{open:E,onClose:C,title:x?.name??``,subtitle:a?`${a.agentNodeId} · ${S}`:``,footer:R(B,{children:[U(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:C,children:`Cancel`}),U(`button`,{type:`button`,disabled:!c||!a||g.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:T,children:g.isPending?`Saving…`:`Save`})]}),children:x&&c&&a&&U(D,{mode:`agent`,addon:x,agentDefault:c,agentNodeId:a.agentNodeId,engineFormat:S,onChangeAgentConfig:e=>l(e)})})]})}L();function An({types:e}){let t=V(),n=p(),{data:r}=i({}),o=a(),s=z(()=>o.data??[],[o.data]),[c,l]=H(null),[u,d]=H(null),f=()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},m=ee({onSuccess:f}),h=v({onSuccess:f}),g=z(()=>{let e=new Map;for(let t of r??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[r]),_=e=>{e.isDefault||m.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},y=async e=>{if(e.isDefault){await n({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another as default first.`,confirmLabel:`OK`,variant:`warning`});return}await n({title:`Delete location "${e.displayName}"?`,message:`Removes the record; files on disk are untouched.`,confirmLabel:`Delete`,variant:`danger`})&&h.mutate({id:e.id})},b=e.map(e=>s.find(t=>t.id===e)).filter(e=>e!==void 0);return R(`div`,{className:`space-y-3`,children:[b.length===0?U(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:`No storage locations declared for this purpose.`}):b.map(e=>U(we,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:g.get(e.id)??[],onAdd:e=>l(e),onEdit:e=>d(e),onDelete:e=>{y(e)},onSetDefault:e=>_(e)},e.id)),c!==null&&U(Te,{initialType:c,onClose:()=>l(null),onCreated:()=>{f(),l(null)}}),u!==null&&U(Ce,{location:u,onClose:()=>d(null),onSaved:()=>{f(),d(null)}})]})}L();var jn=`pipeline-analytics`;function Mn(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 Nn(){let e=V(),{data:t}=o(void 0),{data:n,isLoading:r}=P({addonId:jn}),i=Mn(n),a=te({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),s=z(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return R(`div`,{className:`flex flex-col gap-6`,children:[R(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),U(`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.`}),R(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?U(q,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):U(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:jn,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:s.map(e=>U(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&U(q,{className:`h-4 w-4 animate-spin text-primary`})]})]}),R(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[U(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),U(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),U(An,{types:[`eventMedia`]})]})]})}L();var Pn=`recorder`;function Fn(e,t,n){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t&&typeof e.value==`string`)return e.value;return n}function In(){let e=V(),{data:t}=o(void 0),{data:n,isLoading:r}=P({addonId:Pn}),i=Fn(n,`recordingNodeId`,`hub`),a=te({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),s=z(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return R(`div`,{className:`flex flex-col gap-6`,children:[R(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[U(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),U(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records (continuous & events) and serves playback. Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),R(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?U(q,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):U(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:Pn,patch:{recordingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:s.map(e=>U(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&U(q,{className:`h-4 w-4 animate-spin text-primary`})]}),i!==`hub`&&R(`p`,{className:`mt-2 text-[11px] text-amber-500`,children:[`The stream-broker is hub-only — an agent recorder pulls streams from the hub over the network. The hub's RTSP restream port must be reachable from`,` `,U(`span`,{className:`font-medium`,children:i}),`. If the auto-derived host doesn't work, set the recorder's`,U(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),R(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[U(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),U(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where recordings are stored. Multi-location collections — segments are split across the locations of a type. Add a location to grow capacity; mark one default per type.`}),U(An,{types:[`recordings`,`recordingsLow`]})]})]})}L();var Ln=[{id:`assignments`,label:`Assignments`},{id:`pipeline`,label:`Pipeline`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`}];function Rn({refreshToken:e}){let[t,n]=H(`assignments`),{data:r}=o(void 0),i=r?.find(e=>e.isHub&&e.isOnline)?.id??r?.find(e=>e.isOnline)?.id??null;return R(`div`,{className:`flex flex-col h-full`,children:[R(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[U(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),U(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Assignments with live load, cluster-wide settings, pipeline template library, per-camera pipeline overrides.`})]}),U(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Ln.map(e=>U(`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))}),R(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&U(wn,{refreshToken:e}),t===`pipeline`&&(i?U(kn,{nodeId:i,refreshToken:e}):U(`div`,{className:`text-xs text-foreground-subtle`,children:`No online node available — schema unreachable.`})),t===`events`&&U(Nn,{}),t===`recording`&&U(In,{}),t===`settings`&&U(En,{refreshToken:e}),t===`templates`&&U(Dn,{refreshToken:e})]})]})}function zn(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`}L();var Bn={healthy:`bg-green-500`,idle:`bg-yellow-400`,error:`bg-red-500`},Vn={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Hn({health:e}){return U(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${Bn[e]}`,title:Vn[e],"aria-label":Vn[e],role:`img`})}function Un({selectedDeviceId:e,onSelect:t}){let{data:n}=Je(),{data:r}=ce({}),i=z(()=>{let e=new Map;for(let t of r??[])e.set(t.deviceId,t);return e},[r]),a=z(()=>(n??[]).filter(e=>e.isCamera).map(e=>{let t=i.get(e.id);return{deviceId:e.id,name:e.name,health:t===void 0?`idle`:zn(t)}}),[n,i]);return a.length===0?U(`div`,{className:`px-4 py-6 text-center text-[11px] text-foreground-subtle italic`,children:`No cameras found`}):U(`ul`,{className:`divide-y divide-border`,children:a.map(n=>{let r=n.deviceId===e;return U(`li`,{children:R(`button`,{type:`button`,onClick:()=>t(n.deviceId),className:[`w-full flex items-center gap-2.5 px-4 py-3 text-left transition-colors`,r?`bg-surface-active text-foreground`:`hover:bg-surface-hover text-foreground-subtle hover:text-foreground`].join(` `),"aria-pressed":r,children:[U(Hn,{health:n.health}),R(`span`,{className:`flex-1 min-w-0`,children:[U(`span`,{className:`block truncate text-[12px] font-medium leading-tight`,children:n.name}),R(`span`,{className:`block text-[10px] text-foreground-subtle leading-tight mt-0.5`,children:[`#`,n.deviceId]})]})]})},n.deviceId)})})}var $={camera:0,source:200,broker:400,decoder:600,motion:800,detection:800,audio:800,recorder:800},Wn=120;function Gn(e,t){return e===null||t===null?!1:e!==t}function Kn(e){let t=e.profiles.reduce((e,t)=>e+t.subscribers,0),n=e.profiles.reduce((e,t)=>e+t.inFps,0),r=e.profiles.reduce((e,t)=>e+t.outFps,0);return`${t} subs · ${n.toFixed(1)}→${r.toFixed(1)} fps`}function qn(e){return`${e.actualFps.toFixed(1)} fps · q${e.queueDepth} · ${e.avgInferenceMs.toFixed(1)}ms`}function Jn(e){return`shm ${e.shm.getFrameHits+e.shm.getFrameMisses>0?Math.round(e.shm.getFrameHits/(e.shm.getFrameHits+e.shm.getFrameMisses)*100):0}% hit`}function Yn(e){let t=[],n=[],r={id:`camera`,kind:`camera`,nodeId:null,data:{deviceId:e.deviceId},position:{x:$.camera,y:0}};t.push(r);let i={id:`source`,kind:`source`,nodeId:null,data:{streams:e.source.streams},position:{x:$.source,y:0}};t.push(i),n.push({id:`camera->source`,source:`camera`,target:`source`,crossNode:!1});let a=e.broker;if(a!==null){let e={id:`broker`,kind:`broker`,nodeId:null,data:{profiles:a.profiles,webrtcSessions:a.webrtcSessions,rtspRestream:a.rtspRestream},position:{x:$.broker,y:0}};t.push(e),n.push({id:`source->broker`,source:`source`,target:`broker`,crossNode:!1})}let o=e.decoder;if(o!==null){let r={id:`decoder`,kind:`decoder`,nodeId:o.nodeId,data:{nodeId:o.nodeId,formats:o.formats,sessionCount:o.sessionCount,shm:o.shm},position:{x:$.decoder,y:0}};t.push(r);let i=a===null?`source`:`broker`,s=a===null?void 0:Kn(a),c=a===null?Jn(o):s;n.push({id:`${i}->decoder`,source:i,target:`decoder`,crossNode:Gn(null,o.nodeId),...c===void 0?{}:{label:c}});let l=0,u=e.motion;if(u!==null){let e={id:`motion`,kind:`motion`,nodeId:null,data:{enabled:u.enabled,fps:u.fps},position:{x:$.motion,y:l*Wn}};t.push(e),n.push({id:`decoder->motion`,source:`decoder`,target:`motion`,crossNode:!1}),l++}let d=e.detection;if(d!==null){let e={id:`detection`,kind:`detection`,nodeId:d.nodeId,data:{nodeId:d.nodeId,engine:d.engine,phase:d.phase,configuredFps:d.configuredFps,actualFps:d.actualFps,queueDepth:d.queueDepth,avgInferenceMs:d.avgInferenceMs,provisioning:d.provisioning},position:{x:$.detection,y:l*Wn}};t.push(e),n.push({id:`decoder->detection`,source:`decoder`,target:`detection`,crossNode:Gn(o.nodeId,d.nodeId),label:qn(d)}),l++}let f=e.audio;if(f!==null){let e={id:`audio`,kind:`audio`,nodeId:f.nodeId,data:{nodeId:f.nodeId,enabled:f.enabled},position:{x:$.audio,y:l*Wn}};t.push(e),n.push({id:`decoder->audio`,source:`decoder`,target:`audio`,crossNode:Gn(o.nodeId,f.nodeId)}),l++}let p=e.recording;if(p!==null){let e={id:`recorder`,kind:`recorder`,nodeId:null,data:{mode:p.mode,active:p.active,storageBytes:p.storageBytes},position:{x:$.recorder,y:l*Wn}};t.push(e),n.push({id:`decoder->recorder`,source:`decoder`,target:`recorder`,crossNode:!1})}}return{nodes:t,edges:n}}L();function Xn(e){let{data:t,isLoading:n}=j({deviceId:e}),[r,i]=H(void 0);return W(()=>{t!==void 0&&i(t)},[t]),w(G.PipelineCameraMetricsSnapshot,t=>{let n=t.data;n.deviceId===e&&i(e=>e===void 0||e.detection===null?e:{...e,detection:{...e.detection,phase:n.metrics.phase,actualFps:n.metrics.actualFps,queueDepth:n.metrics.queueDepth,avgInferenceMs:n.metrics.avgInferenceTimeMs}})}),w(G.PipelineEngineProvisioning,e=>{let t=e.data;i(n=>{if(n===void 0||n.detection===null)return n;let r=n.detection.nodeId??n.assignment?.detectionNodeId??null;return r===null||e.source.type!==`node`||e.source.id!==r?n:{...n,detection:{...n.detection,provisioning:{state:t.state,error:t.error}}}})}),w(G.MotionAnalysis,t=>{t.source.type!==`device`||t.source.id!==e||i(e=>e===void 0||e.motion===null?e:{...e,motion:{...e.motion,enabled:!0}})}),w(G.StreamBrokerMetricsSnapshot,t=>{let n=t.data;n.deviceId===e&&i(e=>e===void 0||e.broker===null?e:{...e,broker:{...e.broker,profiles:e.broker.profiles.map(e=>e.profile===n.profile?{...e,subscribers:n.stats.encodedSubscribers+n.stats.decodedSubscribers,inFps:n.stats.inputFps,outFps:n.stats.decodeFps}:e)}})}),w(G.PipelineAudioInferenceResult,t=>{t.data.deviceId===e&&i(e=>e===void 0||e.audio===null?e:{...e,audio:{...e.audio,enabled:!0}})}),w(G.RecordingStarted,t=>{t.data.deviceId===e&&i(e=>e===void 0||e.recording===null?e:{...e,recording:{...e.recording,active:!0}})}),w(G.RecordingStopped,t=>{t.data.deviceId===e&&i(e=>e===void 0||e.recording===null?e:{...e,recording:{...e.recording,active:!1}})}),{status:r,isLoading:n}}function Zn({data:e}){return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`source`,position:Y.Right}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full bg-green-500 shrink-0`,"aria-label":`healthy`}),R(`span`,{className:`text-sm font-semibold truncate`,children:[`Camera #`,e.deviceId]})]}),U(`div`,{className:`text-xs text-muted-foreground mt-1`,children:`source`})]})}function Qn(e){return e>0?`bg-green-500`:`bg-yellow-500`}function $n({data:e}){let t=e.streams[0],n=e.streams.length;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`target`,position:Y.Left}),U(X,{type:`source`,position:Y.Right}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${Qn(n)}`,"aria-label":n>0?`healthy`:`idle`}),U(`span`,{className:`text-sm font-semibold`,children:`Source`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[n,` streams`]})]}),t!==void 0&&R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t.codec,` `,t.width,`×`,t.height,` `,t.fps,`fps`]})]})}function er(e){return e>0?`bg-green-500`:`bg-yellow-500`}function tr({data:e}){let t=e.profiles.reduce((e,t)=>e+t.subscribers,0),n=e.profiles.length;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`target`,position:Y.Left}),U(X,{type:`source`,position:Y.Right}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${er(t)}`,"aria-label":t>0?`healthy`:`idle`}),U(`span`,{className:`text-sm font-semibold`,children:`Broker`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[n,` profiles`]})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t,` subs · WebRTC `,e.webrtcSessions,e.rtspRestream&&` · RTSP`]})]})}function nr(e){return e>0?`bg-green-500`:`bg-yellow-500`}function rr(e,t){let n=e+t;return n>0?Math.round(e/n*100):0}function ir({data:e}){let t=rr(e.shm.getFrameHits,e.shm.getFrameMisses),n=e.offline===!0;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2${n?` opacity-50`:``}`,children:[U(X,{type:`target`,position:Y.Left}),U(X,{type:`source`,position:Y.Right}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${nr(e.sessionCount)}`,"aria-label":e.sessionCount>0?`healthy`:`idle`}),U(`span`,{className:`text-sm font-semibold`,children:`Decoder`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[`@`,e.nodeId]}),n&&U(`span`,{className:`text-[9px] font-semibold px-1 py-0.5 rounded bg-destructive/10 text-destructive`,"aria-label":`offline`,children:`offline`})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.formats.join(`, `),` · `,e.sessionCount,` sessions`]}),R(`div`,{className:`text-xs text-muted-foreground`,children:[`shm `,t,`% hit`]})]})}function ar(e){return e?`bg-green-500`:`bg-yellow-500`}function or({data:e}){return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`target`,position:Y.Left}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${ar(e.enabled)}`,"aria-label":e.enabled?`enabled`:`disabled`}),U(`span`,{className:`text-sm font-semibold`,children:`Motion`})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.enabled?`enabled`:`disabled`,` · `,e.fps,` fps`]})]})}function sr(e){return e.provisioning.state===`failed`?`bg-red-500`:e.phase===`active`?`bg-green-500`:(e.phase,`bg-yellow-500`)}function cr(e){return e===`ready`?`bg-green-500 text-white`:e===`failed`?`bg-red-500 text-white`:`bg-yellow-500 text-white`}function lr({data:e}){let t=e.offline===!0;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[180px] px-3 py-2${t?` opacity-50`:``}`,children:[U(X,{type:`target`,position:Y.Left}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${sr(e)}`,"aria-label":e.phase}),U(`span`,{className:`text-sm font-semibold`,children:`Detection`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[`@`,e.nodeId]}),t&&U(`span`,{className:`text-[9px] font-semibold px-1 py-0.5 rounded bg-destructive/10 text-destructive`,"aria-label":`offline`,children:`offline`})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.engine.backend,`·`,e.engine.device,` · `,e.phase]}),R(`div`,{className:`text-xs text-muted-foreground`,children:[e.actualFps.toFixed(1),`/`,e.configuredFps,` fps · q`,e.queueDepth,` ·`,` `,e.avgInferenceMs.toFixed(1),`ms`]}),R(`div`,{className:`flex items-center gap-1 mt-1`,children:[U(`span`,{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded ${cr(e.provisioning.state)}`,"aria-label":`provisioning ${e.provisioning.state}`,children:e.provisioning.state}),e.provisioning.state===`failed`&&e.provisioning.error!==void 0&&U(`span`,{className:`text-[10px] text-red-500 truncate`,children:e.provisioning.error})]})]})}function ur(e){return e?`bg-green-500`:`bg-yellow-500`}function dr({data:e}){let t=e.offline===!0;return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2${t?` opacity-50`:``}`,children:[U(X,{type:`target`,position:Y.Left}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${ur(e.enabled)}`,"aria-label":e.enabled?`enabled`:`disabled`}),U(`span`,{className:`text-sm font-semibold`,children:`Audio`}),R(`span`,{className:`text-xs text-muted-foreground`,children:[`@`,e.nodeId]}),t&&U(`span`,{className:`text-[9px] font-semibold px-1 py-0.5 rounded bg-destructive/10 text-destructive`,"aria-label":`offline`,children:`offline`})]}),U(`div`,{className:`text-xs text-muted-foreground mt-1`,children:e.enabled?`enabled`:`disabled`})]})}function fr(e){return e.mode===`off`?`bg-red-500`:e.active?`bg-green-500`:`bg-yellow-500`}function pr(e){return e>=1073741824?`${(e/1073741824).toFixed(1)} GB`:`${(e/1048576).toFixed(1)} MB`}function mr({data:e}){return R(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[U(X,{type:`target`,position:Y.Left}),R(`div`,{className:`flex items-center gap-2`,children:[U(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${fr(e)}`,"aria-label":e.active?`active`:e.mode===`off`?`off`:`inactive`}),U(`span`,{className:`text-sm font-semibold`,children:`Recorder`}),U(`span`,{className:`text-xs text-muted-foreground`,children:e.mode})]}),R(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.active?`active`:`inactive`,` · `,pr(e.storageBytes)]})]})}L();var hr={camera:Zn,source:$n,broker:tr,decoder:ir,motion:or,detection:lr,audio:dr,recorder:mr},gr={stroke:`#f59e0b`,strokeWidth:2},_r={strokeWidth:1.5},vr=`camstack-pipeline-flow-layout`;function yr({deviceId:e}){let{status:t,isLoading:n}=Xn(e),{data:r}=o(void 0),i=z(()=>{let e=new Set;for(let t of r??[])t.isOnline||e.add(t.id);return e},[r]),{computedNodes:a,rfEdges:s}=z(()=>{if(t===void 0)return{computedNodes:[],rfEdges:[]};let e=Yn(t);return{computedNodes:e.nodes.map(e=>({id:e.id,type:e.kind,position:{x:e.position.x,y:e.position.y},data:{...e.data,offline:e.nodeId!==null&&i.has(e.nodeId)}})),rfEdges:e.edges.map(e=>({id:e.id,source:e.source,target:e.target,animated:e.crossNode,style:e.crossNode?gr:_r,label:e.label}))}},[t,i]),{nodes:c,onNodesChange:l,resetLayout:u}=$e(vr,a);return n?U(`div`,{className:`flex items-center justify-center h-full text-sm text-muted-foreground`,children:`Loading…`}):t===void 0?U(`div`,{className:`flex items-center justify-center h-full text-sm text-muted-foreground`,children:`No pipeline data`}):R(`div`,{className:`w-full h-full relative`,children:[U(`button`,{type:`button`,onClick:u,className:`absolute top-2 right-2 z-10 text-xs px-2 py-1 rounded border border-border bg-background hover:bg-muted`,title:`Restore the automatic layout, discarding dragged positions`,children:`Reset layout`}),R(et,{nodes:c,edges:s,onNodesChange:l,nodesDraggable:!0,nodeTypes:hr,fitView:!0,proOptions:{hideAttribution:!0},children:[U(Xe,{gap:20,size:1}),U(Ye,{showInteractive:!1})]})]})}L();var br=`__cluster__`;function xr(e){return e===`cameras`?`cameras`:`nodes`}function Sr(){let[e,t]=Re(),n=xr(e.get(`view`)),r=e.get(`node`)??`__cluster__`,i=e.get(`camera`),a=i===null?null:parseInt(i,10),[o,s]=H(0),[c,l]=H(!1);return W(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:br},{replace:!0})},[n,e,t]),R(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[R(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[R(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[U(`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`}),U(`button`,{type:`button`,onClick:()=>{let e={view:`cameras`};a!==null&&(e.camera=String(a)),t(e,{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`})]}),R(`button`,{type:`button`,onClick:()=>s(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:[U(je,{className:`h-3.5 w-3.5`}),`Refresh`]})]}),R(`button`,{type:`button`,onClick:()=>l(e=>!e),"aria-expanded":c,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:[R(`span`,{children:[c?`Hide`:`Show`,` `,n===`nodes`?`node list`:`camera list`]}),U(Be,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),U(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?R(B,{children:[U(`aside`,{className:[c?`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:U(pt,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:o})}),U(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?U(Rn,{refreshToken:o}):U(sn,{nodeId:r,refreshToken:o})})]}):R(B,{children:[U(`aside`,{className:[c?`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:U(Un,{selectedDeviceId:a,onSelect:e=>{t({view:`cameras`,camera:String(e)},{replace:!0}),l(!1)}})}),U(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:a!==null&&Number.isFinite(a)&&!Number.isNaN(a)?U(yr,{deviceId:a}):U(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Select a camera to view its pipeline flow`})})]})})]})}export{Sr as PipelinePage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Ma as e,Na as t,Pa as n}from"./src-
|
|
1
|
+
import{Ma as e,Na as t,Pa as n}from"./src-3NEgkLWp.js";import{I as r,K as i,Q as a,S as o,W as s,b as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{L as f,V as p,c as ee,g as m,n as h,p as g,s as te}from"./player-overlays-DACImv1W.js";import{MaskShapeCanvas as _}from"./MaskShapeCanvas-pGn6MKOi.js";var ne=m(`hexagon`,[[`path`,{d:`M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z`,key:`yt0hxn`}]]);a();var v=120,y=`privacy-mask`,b=`rounded-md border border-border bg-surface px-2 py-1 text-[11px] font-medium text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,x=`rounded-md border border-primary/50 bg-primary/15 px-2.5 py-1 text-[11px] font-medium text-primary hover:bg-primary/25 disabled:opacity-40 transition-colors`;function S(e){return e.kind===`rect`||e.kind===`polygon`?e:null}function re(e){let t=new Set(e.map(e=>e.id)),n=0;for(;t.has(n);)n+=1;return n}function C(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(JSON.stringify(e[n])!==JSON.stringify(t[n]))return!1;return!0}function w({deviceId:a}){let m=ee(g().trpcClient,a),[w,T]=l(null),[E,D]=l(!1),[O,k]=l(null),[A,j]=l(null),[M,N]=l(!1),[P,F]=l(!1),[I,L]=l(null),[R,z]=l(null),B=i(!1);d(()=>{if(!m)return;let e=!1;return B.current=!1,T(null),D(!1),k(null),j(null),F(!1),L(null),z(null),(async()=>{try{let t=await m.privacyMask?.getOptions({});if(e)return;if(!t)throw Error(`device proxy not ready`);if(T(t),B.current)return;let n=await m.privacyMask?.getStatus({});if(e)return;if(!n)throw Error(`device proxy not ready`);B.current=!0;let r={enabled:n.enabled,regions:n.regions};j(r),k(r)}catch(t){if(e)return;p(t)?D(!0):console.error(`Privacy Mask load failed`,t)}})(),()=>{e=!0}},[m]);let V=s(()=>O!==null&&A!==null&&(O.enabled!==A.enabled||!C(O.regions,A.regions)),[O,A]),H=O?O.regions.length:0,U=w?w.maxRegions:0,W=i(0);d(()=>{W.current=U},[U]);let G=U>0&&H>=U,K=r(()=>{k(e=>e&&{...e,enabled:!e.enabled})},[]),q=r(e=>{L(typeof e==`number`?e:null)},[]),J=s(()=>O?O.regions.map(e=>({id:e.id,shape:e.shape,enabled:e.enabled,label:`Zone ${String(e.id)}`})):[],[O]),Y=r((e,t)=>{let n=S(t);n&&k(t=>t&&{...t,regions:t.regions.map(t=>t.id===e?{...t,shape:n}:t)})},[]),X=r(e=>{let t=S(e);t&&(z(null),k(e=>{if(!e)return e;let n=W.current;if(n>0&&e.regions.length>=n)return e;let r=re(e.regions),i={id:r,enabled:!0,shape:t};return L(r),{...e,regions:[...e.regions,i]}}))},[]),Z=r(e=>{F(!0),L(null),z(e)},[]),ie=r(e=>{F(!0),z(null),L(e)},[]),ae=r(e=>{L(t=>t===e?null:t),k(t=>t&&{...t,regions:t.regions.filter(t=>t.id!==e)})},[]),oe=r(()=>{z(null),L(null),A&&k({enabled:A.enabled,regions:A.regions})},[A]),se=r(async()=>{if(!(!m||!O)){N(!0);try{await m.privacyMask?.setMask({patch:{enabled:O.enabled,regions:[...O.regions]}});let e=await m.privacyMask?.getStatus({});if(e){let t={enabled:e.enabled,regions:e.regions};j(t),k(t)}}catch(e){console.error(`Privacy Mask save failed`,e)}finally{N(!1)}}},[m,O]),ce=r(()=>{F(e=>(e&&(z(null),L(null)),!e))},[]),Q=w?.supportedShapes??[];h(s(()=>P&&!E&&w&&O?{id:y,order:v,node:u(_,{transparent:!0,items:J,supportedShapes:Q,polygonVertices:w.polygonVertices,selectedId:I,onSelect:q,onShapeChange:Y,onDrawComplete:X,drawingKind:R})}:null,[P,E,w,O,J,Q,I,q,Y,X,R]));let le=w?.supportedShapes.includes(`rect`)??!1,ue=w?.supportedShapes.includes(`polygon`)??!1,$=w!==null&&(w.maxRegions<=0||w.supportedShapes.length===0);return m?u(te,{title:`Privacy Mask`,icon:u(n,{className:`h-3.5 w-3.5 text-foreground-subtle`}),children:u(`div`,{className:`flex flex-col gap-3`,children:E||$?u(`p`,{className:`${f} leading-relaxed`,children:`This camera doesn't support an on-board privacy mask.`}):!E&&!$&&w!==null&&O!==null?o(c,{children:[o(`p`,{className:`${f} leading-relaxed`,children:[`Toggle `,u(`strong`,{className:`text-foreground`,children:`Edit mask`}),` to draw blanked-out zones on the live frame, then `,u(`strong`,{className:`text-foreground`,children:`Save`}),` to push them to the camera. Drag a rectangle to move, its corner to resize; drag polygon vertices, click an edge midpoint to add one, or right-click a vertex to remove it.`]}),o(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`button`,{type:`button`,onClick:ce,disabled:M,"aria-pressed":P,className:P?x:b,children:P?`Done editing`:`Edit mask`}),u(`button`,{type:`button`,onClick:K,disabled:M,"aria-pressed":O.enabled,className:O.enabled?x:b,children:O.enabled?`Mask on`:`Mask off`}),le&&u(`button`,{type:`button`,onClick:()=>Z(`rect`),disabled:M||G,"aria-pressed":R===`rect`,className:R===`rect`?x:b,title:G?`Maximum zones reached`:`Add a rectangle zone`,children:`+ Rect`}),ue&&u(`button`,{type:`button`,onClick:()=>Z(`polygon`),disabled:M||G,"aria-pressed":R===`polygon`,className:R===`polygon`?x:b,title:G?`Maximum zones reached`:`Add a polygon zone`,children:`+ Polygon`}),o(`span`,{className:`${f} ml-1 tabular-nums`,children:[H,` / `,U,` zones`]}),u(`span`,{className:`flex-1`}),u(`button`,{type:`button`,onClick:oe,disabled:M||!V,className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover disabled:opacity-40 transition-colors`,children:`Revert`}),u(`button`,{type:`button`,onClick:()=>void se(),disabled:M||!V,className:x,children:M?`Saving…`:`Save`})]}),H>0?u(`div`,{className:`flex flex-col gap-1`,children:O.regions.map(n=>{let r=I===n.id,i=n.shape.kind===`polygon`?ne:t;return o(`div`,{className:`flex items-center gap-2 rounded-md border px-2 py-1 transition-colors ${r?`border-primary/50 bg-primary/10`:`border-border bg-surface`}`,children:[o(`button`,{type:`button`,onClick:()=>ie(n.id),disabled:M,className:`flex flex-1 items-center gap-2 text-left text-[11px] font-medium text-foreground-subtle hover:text-foreground disabled:opacity-40 transition-colors`,children:[u(i,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:[`Zone `,n.id]}),u(`span`,{className:`text-foreground-faint capitalize`,children:n.shape.kind})]}),u(`button`,{type:`button`,onClick:()=>ae(n.id),disabled:M,"aria-label":`Delete zone ${String(n.id)}`,title:`Delete zone`,className:`inline-flex h-6 w-6 items-center justify-center rounded border border-border bg-surface text-foreground-subtle hover:border-red-400/40 hover:bg-red-500/10 hover:text-red-400 disabled:opacity-40 transition-colors`,children:u(e,{className:`h-3.5 w-3.5`})})]},n.id)})}):null]}):u(`p`,{className:`${f} leading-relaxed`,children:`Loading the camera's privacy mask…`})})}):null}export{w as PrivacyMaskSettings};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,q as n,x as r}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as i}from"./radio-
|
|
1
|
+
import{Q as e,S as t,q as n,x as r}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as i}from"./radio-BDUnjOmb.js";import{t as a}from"./server-BrxSxrRc.js";import{t as o}from"./wifi-Bzb_4egH.js";import{V as s}from"./index-CukLUOO-.js";var c=s(`cctv`,[[`path`,{d:`M16.75 12h3.632a1 1 0 0 1 .894 1.447l-2.034 4.069a1 1 0 0 1-1.708.134l-2.124-2.97`,key:`ir91b5`}],[`path`,{d:`M17.106 9.053a1 1 0 0 1 .447 1.341l-3.106 6.211a1 1 0 0 1-1.342.447L3.61 12.3a2.92 2.92 0 0 1-1.3-3.91L3.69 5.6a2.92 2.92 0 0 1 3.92-1.3z`,key:`jlp8i1`}],[`path`,{d:`M2 19h3.76a2 2 0 0 0 1.8-1.1L9 15`,key:`19bib8`}],[`path`,{d:`M2 21v-4`,key:`l40lih`}],[`path`,{d:`M7 9h.01`,key:`19b3jx`}]]),l=s(`house`,[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`1d0kgt`}]]);e();var u={frigate:{icon:c,color:`#3b82f6`,label:`Frigate`},scrypted:{icon:a,color:`#a855f7`,label:`Scrypted`},reolink:{icon:i,color:`#06b6d4`,label:`Reolink`},homeassistant:{icon:l,color:`#22d3ee`,label:`Home Assistant`},rtsp:{icon:o,color:`#78716c`,label:`RTSP`},onvif:{icon:o,color:`#78716c`,label:`ONVIF`}},d={sm:`h-4 w-4`,md:`h-5 w-5`,lg:`h-6 w-6`},f={sm:`h-7 w-7`,md:`h-8 w-8`,lg:`h-10 w-10`};function p(e){let t=e.toLowerCase();return t.startsWith(`provider-`)?t.slice(9):t}function m(e){return u[p(e)]??{icon:c,color:`#78716c`,label:e}}function h(e){let t=p(e);return`/api/addon-assets/${e.toLowerCase().startsWith(`provider-`)?e:`provider-${t}`}/assets/icon.svg`}function g({type:e,size:i=`md`,showLabel:a}){let o=m(e),s=o.icon,[c,l]=n(!1),u=h(e);return t(`div`,{className:`flex items-center gap-2`,children:[r(`div`,{className:`flex items-center justify-center rounded-lg ${f[i]}`,style:{backgroundColor:`${o.color}15`},children:c?r(s,{className:d[i],style:{color:o.color}}):r(`img`,{src:u,alt:o.label,className:d[i],onError:()=>l(!0)})}),a&&r(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:o.label})]})}export{g as t};
|