@camstack/addon-admin-ui 1.1.47 → 1.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/assets/{AddLocationWizard-Ja3EFJLM.js → AddLocationWizard-CNu50RRk.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-DarnvrBW.js → AddonCollectionPage-PSUd7Fp3.js} +1 -1
  3. package/dist/assets/{Addons-DEUDLZZU.js → Addons-CZjrkq5h.js} +1 -1
  4. package/dist/assets/{AdminTabs-CAcc6cMo.js → AdminTabs-BHvYU2Ev.js} +1 -1
  5. package/dist/assets/{BrokerForm-B3T_wC8B.js → BrokerForm-D0rEasac.js} +1 -1
  6. package/dist/assets/{Capabilities-heWYOejs.js → Capabilities-BKDzO_QH.js} +1 -1
  7. package/dist/assets/{CapabilityBadges-BwulGeU7.js → CapabilityBadges-CnoS0ir9.js} +1 -1
  8. package/dist/assets/{Cluster-Cztf4fk8.js → Cluster-Kw2bIhhr.js} +1 -1
  9. package/dist/assets/{Dashboard-Bf4EbvYA.js → Dashboard-Dk7fWy7X.js} +1 -1
  10. package/dist/assets/{Data-B_7DwGv9.js → Data-DCA91s8e.js} +1 -1
  11. package/dist/assets/DetectionIntelligence-COHiawzo.js +1 -0
  12. package/dist/assets/DeviceDetail-D2xbVjhc.js +2 -0
  13. package/dist/assets/{Devices-CBtOs7sm.js → Devices-BC3G6oUT.js} +1 -1
  14. package/dist/assets/{EmbedPlayerPage-ilPK8vT0.js → EmbedPlayerPage-DSojH1CJ.js} +1 -1
  15. package/dist/assets/{FormBuilder-DmAaqS0P.js → FormBuilder-DQtsRfrS.js} +1 -1
  16. package/dist/assets/{Identity-CapaLyHC.js → Identity-CZJMYa-0.js} +1 -1
  17. package/dist/assets/{IntegrationDetail-DO7HjLBW.js → IntegrationDetail-Dylopt_Q.js} +1 -1
  18. package/dist/assets/{Integrations-C1OT7Ojq.js → Integrations-B1b2SfHN.js} +1 -1
  19. package/dist/assets/{Integrations-DL6LKL4J.js → Integrations-C6DlqzuU.js} +1 -1
  20. package/dist/assets/{Logs-DkJkJGxW.js → Logs-oJOvATtc.js} +1 -1
  21. package/dist/assets/{MotionZonesSettings-DL55VLbI.js → MotionZonesSettings-CtyZyzO0.js} +1 -1
  22. package/dist/assets/{MyAccess-CBeAjiv_.js → MyAccess-B95erwTc.js} +1 -1
  23. package/dist/assets/{Network-D_FxKVCf.js → Network-Bt-0u_vG.js} +1 -1
  24. package/dist/assets/{NodeAddonsSettingsPanel-B-nngyAf.js → NodeAddonsSettingsPanel-CDaY9-jy.js} +1 -1
  25. package/dist/assets/{NotificationTargets-TIsi38-I.js → NotificationTargets-CpUBiCnZ.js} +1 -1
  26. package/dist/assets/Pipeline-CIy4nvmh.js +1 -0
  27. package/dist/assets/{PrivacyMaskSettings-8aXddQXv.js → PrivacyMaskSettings-BdvcV5Pq.js} +1 -1
  28. package/dist/assets/{ProviderIcon-BHB6sXAt.js → ProviderIcon-eLscNoy4.js} +1 -1
  29. package/dist/assets/{ScanNetworkModal-DrMdqNIo.js → ScanNetworkModal-QqDj5dFm.js} +1 -1
  30. package/dist/assets/{ServerManagement-Dk3DE_WG.js → ServerManagement-hZQ2-18O.js} +1 -1
  31. package/dist/assets/{Settings-M_kT8ySJ.js → Settings-CKkGgfFo.js} +1 -1
  32. package/dist/assets/{Showroom-DKOjUcCg.js → Showroom-CJ1lhEcy.js} +1 -1
  33. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D33LJRoa.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CZB2m_J6.js} +1 -1
  34. package/dist/assets/{build-cluster-graph-U096JDKn.js → build-cluster-graph-D8zI3CJw.js} +1 -1
  35. package/dist/assets/circle-check-big-C6LRzNwE.js +1 -0
  36. package/dist/assets/{copy-CzLPrafW.js → copy-De0LCulr.js} +1 -1
  37. package/dist/assets/{dist-BqJ4ODEV.js → dist-B5IRIygV.js} +1 -1
  38. package/dist/assets/dist-BggkTWZv.js +7 -0
  39. package/dist/assets/{download-pveeJDxf.js → download-gY2u92nb.js} +1 -1
  40. package/dist/assets/{hostInit-Dum3X3mF.js → hostInit-BToWOe6B.js} +1 -1
  41. package/dist/assets/{index-Cs4056Il.js → index-BbLGFHTA.js} +3 -3
  42. package/dist/assets/index-Bjs7hcYx.css +2 -0
  43. package/dist/assets/{key-round-Cgd91f3y.js → key-round-DkqhaVT8.js} +1 -1
  44. package/dist/assets/{mf-entry-bootstrap-0-5691f327.js → mf-entry-bootstrap-0-f884f398.js} +2 -2
  45. package/dist/assets/{pencil-DRjwER9e.js → pencil-CMpHSjpp.js} +1 -1
  46. package/dist/assets/{player-overlays-BjWq4Lsw.js → player-overlays-Dsrz7Epi.js} +1 -1
  47. package/dist/assets/plus-DwRCRuP4.js +1 -0
  48. package/dist/assets/{radio-Dil4Ibsx.js → radio-RxH1E0zh.js} +1 -1
  49. package/dist/assets/{refresh-cw-Deh_KPTo.js → refresh-cw-C6St6mBe.js} +1 -1
  50. package/dist/assets/remoteEntry-Dwdg-ENJ.js +1 -0
  51. package/dist/assets/{rotate-ccw-B87yFCCj.js → rotate-ccw-vHrIqGml.js} +1 -1
  52. package/dist/assets/rotate-cw-BTB8lJL-.js +1 -0
  53. package/dist/assets/search-rHmAwRLQ.js +1 -0
  54. package/dist/assets/{sparkles-BpXfWQIN.js → sparkles-Crb67IKw.js} +1 -1
  55. package/dist/assets/square-CBYzFCHC.js +1 -0
  56. package/dist/assets/{square-check-big-eVWC31kd.js → square-check-big-ftIvwB2w.js} +1 -1
  57. package/dist/assets/{src-nTmr96zw.js → src-BD_Vx_7m.js} +10 -10
  58. package/dist/assets/src-BkJfNPjU.js +7 -0
  59. package/dist/assets/{upload-CfFD_PUi.js → upload-DfU_xONk.js} +1 -1
  60. package/dist/assets/{useDevice-u2EdLcQq.js → useDevice-DWDA_2pg.js} +1 -1
  61. package/dist/assets/{useEventInvalidation-DEG6y8gC.js → useEventInvalidation-BWNmKaq3.js} +1 -1
  62. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-qa0QFz07.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BgfXovIL.js} +2 -2
  63. package/dist/assets/{wifi-Dnk9IQ1K.js → wifi-CVIceYWr.js} +1 -1
  64. package/dist/assets/{zap-8_HIF5GC.js → zap-C34L74c5.js} +1 -1
  65. package/dist/index.html +6 -6
  66. package/dist/server/addon.js +27 -3
  67. package/package.json +1 -1
  68. package/dist/assets/DetectionIntelligence-sFokINqt.js +0 -1
  69. package/dist/assets/DeviceDetail-Dihuj9Ih.js +0 -2
  70. package/dist/assets/Pipeline-CfULuDgZ.js +0 -1
  71. package/dist/assets/circle-check-big-BgUVBcnB.js +0 -1
  72. package/dist/assets/dist-bNuNFLZO.js +0 -7
  73. package/dist/assets/index-BXn17UrG.css +0 -2
  74. package/dist/assets/plus-BUOkx72I.js +0 -1
  75. package/dist/assets/remoteEntry-C23sPYAV.js +0 -1
  76. package/dist/assets/rotate-cw-1kDV0Jj3.js +0 -1
  77. package/dist/assets/search-DXf7ROHt.js +0 -1
  78. package/dist/assets/square-7B5ghrYh.js +0 -1
  79. package/dist/assets/src-PqKMUhAl.js +0 -7
@@ -1 +1 @@
1
- import{Ca as e,Da as t,Ea as n,Ma as r,Na as i,Oa as a,S as o,ja as s,ka as c,ta as l,wa as u}from"./src-nTmr96zw.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-BjWq4Lsw.js";import{t as y}from"./circle-check-big-BgUVBcnB.js";import{t as b}from"./pencil-DRjwER9e.js";import{t as x}from"./plus-BUOkx72I.js";import{t as S}from"./search-DXf7ROHt.js";import{H as C,M as w,S as T,s as E,z as D}from"./index-Cs4056Il.js";import{t as O}from"./AdminPage-BwmGKnRf.js";var k=C(`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:o,kind:s,open:c,onClose:l}){let d=v(),m=p(()=>j(s.caps),[s.caps]),[y,b]=h(()=>R(s.caps)),[x,S]=h(null),C=p(()=>F(s.caps,y),[s.caps,y]),w=y.body.length,E=w>m.bodyMaxLen,D=e=>b(t=>({...t,...e})),O=g({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:o.addonId,targetId:o.id,sample:F(s.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(s.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},D({actions:r})};return _(e,{open:c,onOpenChange:e=>!e&&l(),children:f(u,{width:`lg`,className:`!max-w-2xl`,children:[_(t,{children:f(a,{children:[`Test "`,o.name,`" (`,s.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=>_(i,{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=>D({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&&_(r,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&_(r,{variant:`info`,children:`silent`}),e.flags?.noPush&&_(r,{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=>D({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:()=>D({format:e})}),e]},e))})]}),f(`div`,{children:[_(`label`,{className:U,children:`Title`}),_(`input`,{className:H,value:y.title,onChange:e=>D({title:e.target.value})})]}),f(`div`,{children:[f(`label`,{className:U,children:[`Body`,` `,f(`span`,{className:E?`text-danger`:`text-foreground-subtle`,children:[`(`,w,`/`,m.bodyMaxLen,E?` — overflow`:``,`)`]})]}),_(`textarea`,{className:`${H} min-h-[80px] resize-y`,value:y.body,onChange:e=>D({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=>D({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=>D({clickUrl:e.target.value})})]}),m.showSound&&f(`div`,{children:[_(`label`,{className:U,children:`Sound`}),_(`input`,{className:H,value:y.sound,onChange:e=>D({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=>D({ttl:e.target.value})})]}),m.showTag&&f(`div`,{children:[_(`label`,{className:U,children:`Tag`}),_(`input`,{className:H,value:y.tag,onChange:e=>D({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(n,{children:[_(i,{variant:`secondary`,size:`sm`,type:`button`,onClick:l,children:`Close`}),f(i,{size:`sm`,type:`button`,disabled:O.isPending||y.body.length===0,onClick:()=>O.mutate(),children:[O.isPending?_(T,{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`}):_(w,{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 e=v(),[t,n]=h({mode:`closed`}),[a,o]=h(null),u=m({queryKey:X,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),d=m({queryKey:Z,queryFn:async()=>(await e.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]),C=g({mutationFn:t=>e.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:t.target.addonId,targetId:t.target.id,enabled:t.enabled}),onSuccess:()=>void u.refetch()}),w=g({mutationFn:t=>e.trpcClient.notificationOutput.deleteTarget.mutate({addonId:t.addonId,targetId:t.id}),onSuccess:()=>void u.refetch()}),A=a?S.get(a.kind):void 0;return f(O,{icon:D,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(i,{size:`sm`,type:`button`,onClick:()=>n({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:_(T,{className:`h-6 w-6 animate-spin text-primary`})}),u.isError&&!u.isLoading&&_(l,{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&&_(s,{children:_(`ul`,{className:`divide-y divide-border`,children:(u.data??[]).map(e=>{let t=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:t?.label??e.kind,children:t?.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:t?.label??e.kind})]}),!e.enabled&&_(r,{variant:`warning`,children:`disabled`}),_(c,{checked:e.enabled,onCheckedChange:t=>C.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),_(i,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>o(e),title:`Test`,children:_(k,{className:`h-3.5 w-3.5`})}),_(i,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>t&&n({mode:`form`,kind:t,target:e}),title:`Edit`,children:_(b,{className:`h-3.5 w-3.5`})}),_(i,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>w.mutate(e),title:`Delete`,children:_(E,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),t.mode===`pick-kind`&&_($,{kinds:y,onCancel:()=>n({mode:`closed`}),onPick:e=>n({mode:`form`,kind:e,target:null})}),t.mode===`form`&&_(ee,{kind:t.kind,target:t.target,onCancel:()=>n({mode:`closed`}),onSaved:()=>{n({mode:`closed`}),u.refetch()}}),a&&A&&_(W,{target:a,kind:A,open:!0,onClose:()=>o(null)})]})}function $({kinds:e,onPick:t,onCancel:n}){let a=p(()=>K(e),[e]);return f(s,{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`}),_(i,{size:`sm`,variant:`ghost`,type:`button`,onClick:n,children:`Cancel`})]}),a.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.`}),a.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(n=>f(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[_(`span`,{className:`text-lg`,children:n.icon}),_(`span`,{className:`font-medium text-foreground`,children:n.label}),n.supportsDiscovery&&_(r,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function ee({kind:e,target:t,onSaved:n,onCancel:r}){let a=v(),c=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,c):{}),[b,x]=h(null),[C,w]=h(null),E=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`)}),D=g({mutationFn:()=>{let n=J(m,l,c),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(s,{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`]}),_(i,{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(i,{size:`sm`,variant:`outline`,type:`button`,disabled:E.isPending,onClick:()=>{w(null),E.mutate()},children:[E.isPending?_(T,{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}`))})]}),c.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.`}),_(o,{schema:e.configSchema,values:m,onChange:y}),f(`div`,{className:`flex justify-end gap-2`,children:[_(i,{variant:`secondary`,size:`sm`,type:`button`,onClick:r,children:`Cancel`}),f(i,{size:`sm`,type:`button`,disabled:D.isPending||u.trim().length===0,onClick:()=>{w(null),D.mutate()},children:[D.isPending&&_(T,{className:`h-3.5 w-3.5 animate-spin`}),t?`Save changes`:`Create target`]})]})]})}export{Q as NotificationTargetsPage,Q as default};
1
+ import{Ca as e,Da as t,Ea as n,Ma as r,Na as i,Oa as a,S as o,ja as s,ka as c,ta as l,wa as u}from"./src-BD_Vx_7m.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-Dsrz7Epi.js";import{t as y}from"./circle-check-big-C6LRzNwE.js";import{t as b}from"./pencil-CMpHSjpp.js";import{t as x}from"./plus-DwRCRuP4.js";import{t as S}from"./search-rHmAwRLQ.js";import{H as C,M as w,S as T,s as E,z as D}from"./index-BbLGFHTA.js";import{t as O}from"./AdminPage-BwmGKnRf.js";var k=C(`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:o,kind:s,open:c,onClose:l}){let d=v(),m=p(()=>j(s.caps),[s.caps]),[y,b]=h(()=>R(s.caps)),[x,S]=h(null),C=p(()=>F(s.caps,y),[s.caps,y]),w=y.body.length,E=w>m.bodyMaxLen,D=e=>b(t=>({...t,...e})),O=g({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:o.addonId,targetId:o.id,sample:F(s.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(s.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},D({actions:r})};return _(e,{open:c,onOpenChange:e=>!e&&l(),children:f(u,{width:`lg`,className:`!max-w-2xl`,children:[_(t,{children:f(a,{children:[`Test "`,o.name,`" (`,s.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=>_(i,{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=>D({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&&_(r,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&_(r,{variant:`info`,children:`silent`}),e.flags?.noPush&&_(r,{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=>D({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:()=>D({format:e})}),e]},e))})]}),f(`div`,{children:[_(`label`,{className:U,children:`Title`}),_(`input`,{className:H,value:y.title,onChange:e=>D({title:e.target.value})})]}),f(`div`,{children:[f(`label`,{className:U,children:[`Body`,` `,f(`span`,{className:E?`text-danger`:`text-foreground-subtle`,children:[`(`,w,`/`,m.bodyMaxLen,E?` — overflow`:``,`)`]})]}),_(`textarea`,{className:`${H} min-h-[80px] resize-y`,value:y.body,onChange:e=>D({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=>D({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=>D({clickUrl:e.target.value})})]}),m.showSound&&f(`div`,{children:[_(`label`,{className:U,children:`Sound`}),_(`input`,{className:H,value:y.sound,onChange:e=>D({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=>D({ttl:e.target.value})})]}),m.showTag&&f(`div`,{children:[_(`label`,{className:U,children:`Tag`}),_(`input`,{className:H,value:y.tag,onChange:e=>D({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(n,{children:[_(i,{variant:`secondary`,size:`sm`,type:`button`,onClick:l,children:`Close`}),f(i,{size:`sm`,type:`button`,disabled:O.isPending||y.body.length===0,onClick:()=>O.mutate(),children:[O.isPending?_(T,{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`}):_(w,{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 e=v(),[t,n]=h({mode:`closed`}),[a,o]=h(null),u=m({queryKey:X,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),d=m({queryKey:Z,queryFn:async()=>(await e.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]),C=g({mutationFn:t=>e.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:t.target.addonId,targetId:t.target.id,enabled:t.enabled}),onSuccess:()=>void u.refetch()}),w=g({mutationFn:t=>e.trpcClient.notificationOutput.deleteTarget.mutate({addonId:t.addonId,targetId:t.id}),onSuccess:()=>void u.refetch()}),A=a?S.get(a.kind):void 0;return f(O,{icon:D,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(i,{size:`sm`,type:`button`,onClick:()=>n({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:_(T,{className:`h-6 w-6 animate-spin text-primary`})}),u.isError&&!u.isLoading&&_(l,{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&&_(s,{children:_(`ul`,{className:`divide-y divide-border`,children:(u.data??[]).map(e=>{let t=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:t?.label??e.kind,children:t?.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:t?.label??e.kind})]}),!e.enabled&&_(r,{variant:`warning`,children:`disabled`}),_(c,{checked:e.enabled,onCheckedChange:t=>C.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),_(i,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>o(e),title:`Test`,children:_(k,{className:`h-3.5 w-3.5`})}),_(i,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>t&&n({mode:`form`,kind:t,target:e}),title:`Edit`,children:_(b,{className:`h-3.5 w-3.5`})}),_(i,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>w.mutate(e),title:`Delete`,children:_(E,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),t.mode===`pick-kind`&&_($,{kinds:y,onCancel:()=>n({mode:`closed`}),onPick:e=>n({mode:`form`,kind:e,target:null})}),t.mode===`form`&&_(ee,{kind:t.kind,target:t.target,onCancel:()=>n({mode:`closed`}),onSaved:()=>{n({mode:`closed`}),u.refetch()}}),a&&A&&_(W,{target:a,kind:A,open:!0,onClose:()=>o(null)})]})}function $({kinds:e,onPick:t,onCancel:n}){let a=p(()=>K(e),[e]);return f(s,{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`}),_(i,{size:`sm`,variant:`ghost`,type:`button`,onClick:n,children:`Cancel`})]}),a.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.`}),a.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(n=>f(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[_(`span`,{className:`text-lg`,children:n.icon}),_(`span`,{className:`font-medium text-foreground`,children:n.label}),n.supportsDiscovery&&_(r,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function ee({kind:e,target:t,onSaved:n,onCancel:r}){let a=v(),c=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,c):{}),[b,x]=h(null),[C,w]=h(null),E=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`)}),D=g({mutationFn:()=>{let n=J(m,l,c),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(s,{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`]}),_(i,{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(i,{size:`sm`,variant:`outline`,type:`button`,disabled:E.isPending,onClick:()=>{w(null),E.mutate()},children:[E.isPending?_(T,{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}`))})]}),c.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.`}),_(o,{schema:e.configSchema,values:m,onChange:y}),f(`div`,{className:`flex justify-end gap-2`,children:[_(i,{variant:`secondary`,size:`sm`,type:`button`,onClick:r,children:`Cancel`}),f(i,{size:`sm`,type:`button`,disabled:D.isPending||u.trim().length===0,onClick:()=>{w(null),D.mutate()},children:[D.isPending&&_(T,{className:`h-3.5 w-3.5 animate-spin`}),t?`Save changes`:`Create target`]})]})]})}export{Q as NotificationTargetsPage,Q as default};
@@ -0,0 +1 @@
1
+ import{$r as e,Ba as t,Br as n,Di as r,Hr as i,Ir as a,Jr as o,Kr as s,Ma as c,Oi as l,Ra as u,Rr as d,T as f,Ur as p,Vr as m,Wr as h,Xr as g,Yr as _,Zr as v,_ as y,_i as b,aa as x,ai as S,bi as C,ci as w,di as T,ea as E,fa as D,g as O,gi as k,ia as A,ii as j,ji as ee,ki as te,la as ne,li as M,lt as N,ni as P,oa as re,oi as ie,ot as ae,pa as oe,qr as se,ri as ce,sa as le,si as ue,st as de,ua as fe,ui as pe,vi as me,zr as he}from"./src-BD_Vx_7m.js";import{I as ge,K as _e,Q as F,S as I,T as ve,W as L,a as ye,b as R,o as z,q as B,x as V,z as H}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{H as be,L as xe,R as Se}from"./src-BkJfNPjU.js";import{p as Ce}from"./player-overlays-Dsrz7Epi.js";import{t as we}from"./download-gY2u92nb.js";import{i as Te,n as Ee,r as De,t as Oe}from"./AddLocationWizard-CNu50RRk.js";import{n as ke,r as Ae,t as je}from"./zap-C34L74c5.js";import{i as Me,r as Ne}from"./useDevice-DWDA_2pg.js";import{t as Pe}from"./pencil-CMpHSjpp.js";import{t as Fe}from"./plus-DwRCRuP4.js";import{t as Ie}from"./radio-RxH1E0zh.js";import{t as Le}from"./refresh-cw-C6St6mBe.js";import{t as Re}from"./search-rHmAwRLQ.js";import{t as ze}from"./square-check-big-ftIvwB2w.js";import{t as Be}from"./square-CBYzFCHC.js";import{A as U,F as Ve,H as W,I as He,K as Ue,M as We,N as Ge,S as G,T as Ke,i as qe,j as Je,o as Ye,p as Xe,s as Ze,x as Qe}from"./index-BbLGFHTA.js";import{t as $e}from"./AdminPage-BwmGKnRf.js";import{t as K}from"./useEventInvalidation-BWNmKaq3.js";import{r as et,t as tt}from"./build-cluster-graph-D8zI3CJw.js";import{n as nt}from"./format-size-CO9d3C3-.js";import{t as rt}from"./NodeAddonsSettingsPanel-CDaY9-jy.js";var it=W(`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=W(`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=W(`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=W(`lock-open`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]]),ct=W(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);F();function lt(e){return e}function ut(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function dt(e,t){return typeof e==`boolean`?e:lt(t)}function ft(e,t){return{pipeline:dt(ut(e,`detect`),t),audio:dt(ut(e,`audio`),t),ingest:dt(ut(e,`ingest`),t)}}function pt(e,t,n){let r=e?.find(e=>e.nodeId===t);return ft(r?.settings,n)}function mt({selectedNodeId:e,onSelect:n,refreshToken:r}){let{data:i}=a(void 0),{data:o}=P(void 0),{data:s}=ce(void 0),l=new Map;for(let e of o??[])l.set(e.agentNodeId,(l.get(e.agentNodeId)??0)+1);let u=i??[],d=u.filter(e=>e.isOnline).length,f=u.filter(e=>!e.isOnline).length;return I(`div`,{className:`flex flex-col h-full`,children:[I(`button`,{type:`button`,onClick:()=>n(kr),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[V(Ke,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[V(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),V(`div`,{className:`flex-1 overflow-y-auto`,children:u.map(r=>{let i=e===r.id,a=l.get(r.id)??0,o=r.isHub?Xe:U,u=pt(s,r.id,r.isHub),d=r.isOnline?null:t(et(r.lastSeen));return I(`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:[V(o,{className:`h-4 w-4 flex-shrink-0`}),I(`div`,{className:`min-w-0 flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-xs font-semibold truncate`,children:r.name}),r.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!r.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),r.isOnline&&V(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),I(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[I(`span`,{children:[r.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a>0&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[V(ke,{className:`h-2.5 w-2.5`}),a]})]}),!r.isOnline&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{className:`text-destructive`,children:[`offline`,d===null?``:` · ${d}`]})]})]}),I(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[V(c,{variant:u.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),V(c,{variant:u.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},r.id)})}),I(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[I(`span`,{children:[d,` online`]}),f>0&&I(`span`,{className:`text-destructive`,children:[f,` offline`]})]})]})}function ht({nodeId:e,refreshToken:t}){let{data:n}=a(void 0),r=n?.find(t=>t.id===e),i=x(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?I(`div`,{className:`px-6 py-4 border-b border-border`,children:[I(`div`,{className:`flex items-center gap-2 mb-1`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):V(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&V(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[V(`span`,{children:r.cpuModel??`CPU`}),V(`span`,{children:`•`}),I(`span`,{children:[r.cpuCores,` cores`]}),V(`span`,{children:`•`}),I(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),i&&I(R,{children:[V(`span`,{children:`•`}),I(`span`,{children:[i.attachedCameras,` cameras (`,i.activeCameras,` active)`]}),V(`span`,{children:`•`}),I(`span`,{children:[i.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),V(`span`,{children:`•`}),I(`span`,{children:[`queue `,i.queueDepthTotal]}),i.hardware.hasGpu&&I(R,{children:[V(`span`,{children:`•`}),V(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):V(`div`,{className:`px-6 py-4 border-b border-border`,children:I(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function gt({refreshToken:e,nodeId:t}){let[n,r]=B(new Map),{nodes:i}=A();le(`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}=v(void 0),o=L(()=>{let e=new Map;for(let t of a??[])e.set(t.nodeId,t.deviceCount);return e},[a]),s=L(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),c=L(()=>{let e=new Map;for(let t of i)e.set(t.id,t.shortName);return e},[i]),l=L(()=>{let e=0,t=0,n=0,r=0,a=0;for(let i of s.values())e+=i.attachedCameras,t+=i.activeCameras,n+=i.totalFps,r+=i.totalInferenceWeighted,a+=i.queueDepth;let o=e>0?r/e:0;return{totalAgents:i.length,onlineAgents:i.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:o,queueDepth:a,totalFps:n}},[s,i]);if(t){let e=s.get(t);return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[V(q,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),V(q,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),V(q,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),V(q,{label:`Queue`,value:e?String(e.queueDepth):`—`}),V(q,{label:`Audio`,value:String(o.get(t)??`—`)})]})]})}let u=[...s.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return I(`div`,{className:`@container/liveload`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),I(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[V(q,{label:`Total agents`,value:`${l.onlineAgents}/${l.totalAgents}`}),V(q,{label:`Active / Attached`,value:`${l.activeCameras}/${l.attachedCameras}`}),V(q,{label:`Total FPS`,value:l.totalFps.toFixed(1)}),V(q,{label:`Avg inference ms`,value:l.avgInferenceTimeMs.toFixed(0)}),V(q,{label:`Queue depth`,value:String(l.queueDepth)})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[480px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),V(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),V(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),V(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),V(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),V(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),I(`tbody`,{children:[u.map(([e,t])=>I(`tr`,{className:`border-t border-border`,children:[V(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:c.get(e)??e}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:o.get(e)??`—`})]},e)),u.length===0&&V(`tr`,{children:V(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function q({label:e,value:t}){return I(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[V(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),V(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}F();var _t={active:!1,pinned:!1,nodeId:null,reason:``},vt=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],yt={pipeline:U,decoder:at,audio:Ae},bt={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function xt({mode:t,nodeId:n,compact:r=!1}){if(t===`agent`&&!n)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let i=z(),[a,o]=B(null),[c,l]=B(null),[u,d]=B(new Map);K([`pipelineOrchestrator`,`getPipelineAssignments`],vt),K([`pipelineOrchestrator`,`getAudioAssignments`],vt),K([`pipelineOrchestrator`,`getCameraStatuses`],vt);let{data:p}=P(void 0),{data:m}=g(void 0),{data:h}=e({},{enabled:t===`agent`}),{nodes:_}=A(),{data:v}=Ne();le(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&d(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),H(()=>{if(u.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[u.size]);let y=L(()=>{let e=new Map;for(let t of v??[])e.set(t.id,t.name);return e},[v]),x=L(()=>{if(t===`agent`){let e=[];for(let t of h??[]){let r=t.assignment,i=(e,t,r)=>({active:e!==null&&e===n,pinned:t,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:t.deviceId,deviceName:y.get(t.deviceId)??`Device ${t.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let e=new Map,r=t=>{let n=e.get(t);if(n)return n;let r={deviceId:t,deviceName:y.get(t)??`Device ${t}`,pipeline:_t,decoder:_t,audio:_t};return e.set(t,r),r};for(let i of p??[]){let a=r(i.deviceId);e.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:t===`cluster`?!0:i.agentNodeId===n,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let t of m??[]){let n=r(t.deviceId);e.set(t.deviceId,{...n,audio:{active:!0,pinned:t.pinned,nodeId:t.nodeId,reason:`capacity`}})}let i=[...e.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[p,m,h,y,t,n]),S=L(()=>(_??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[_]),C=()=>{i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},w=se({onSuccess:C}),T=b({onSuccess:C}),E=s({onSuccess:C}),D=k({onSuccess:C}),O=(e,t,n)=>{t===`pipeline`?w.mutate({deviceId:e,agentNodeId:n}):E.mutate({deviceId:e,nodeId:n}),o(null)},j=(e,t)=>{t===`pipeline`?T.mutate({deviceId:e}):D.mutate({deviceId:e}),o(null)};return V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!r&&V(`th`,{className:`w-10`}),V(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),t===`cluster`?I(R,{children:[V(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),V(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):I(R,{children:[V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),V(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),V(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),I(`tbody`,{children:[x.map(e=>{let n=u.get(e.deviceId),i=c===e.deviceId;return I(ve.Fragment,{children:[I(`tr`,{className:`border-t border-border align-middle relative`,children:[!r&&V(`td`,{className:`px-2 py-2 align-middle`,children:V(`button`,{type:`button`,onClick:()=>l(i?null:e.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":i?`Collapse broker details`:`Expand broker details`,children:V(i?Ve:Ge,{className:`h-3.5 w-3.5`})})}),I(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[V(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:e.deviceName,children:e.deviceName}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,e.deviceId]})]}),t===`cluster`?I(R,{children:[V(`td`,{className:`px-3 py-2 align-middle`,children:V(St,{state:e.pipeline,onlineNodes:S,pending:w.isPending||T.isPending,onChange:t=>{t===`auto`?j(e.deviceId,`pipeline`):O(e.deviceId,`pipeline`,t)}})}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(Ct,{state:e.pipeline})})]}):I(R,{children:[V(wt,{role:`pipeline`,state:e.pipeline,mode:t,deviceId:e.deviceId,onlineNodes:S,isMenuOpen:a?.deviceId===e.deviceId&&a.role===`pipeline`,onToggleMenu:()=>o(a?.deviceId===e.deviceId&&a.role===`pipeline`?null:{deviceId:e.deviceId,role:`pipeline`}),onCloseMenu:()=>o(null),onMove:t=>O(e.deviceId,`pipeline`,t),onUnpin:()=>j(e.deviceId,`pipeline`)}),V(wt,{role:`decoder`,state:e.decoder,mode:t,deviceId:e.deviceId,onlineNodes:S,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),V(wt,{role:`audio`,state:e.audio,mode:t,deviceId:e.deviceId,onlineNodes:S,isMenuOpen:a?.deviceId===e.deviceId&&a.role===`audio`,onToggleMenu:()=>o(a?.deviceId===e.deviceId&&a.role===`audio`?null:{deviceId:e.deviceId,role:`audio`}),onCloseMenu:()=>o(null),onMove:t=>O(e.deviceId,`audio`,t),onUnpin:()=>j(e.deviceId,`audio`)})]}),V(`td`,{className:`px-3 py-2 align-middle`,children:V(Ot,{snap:n})})]}),i&&!r&&I(`tr`,{className:`bg-surface/50`,children:[V(`td`,{}),V(`td`,{colSpan:t===`cluster`?4:5,className:`px-3 py-2`,children:V(f,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:e.deviceId,instanceId:`pipeline-row/${e.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})})]})]},e.deviceId)}),x.length===0&&V(`tr`,{children:V(`td`,{colSpan:r?t===`cluster`?4:5:t===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:t===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function St({state:e,onlineNodes:t,pending:n,onChange:r}){let i=e.pinned&&e.nodeId?e.nodeId:`auto`,a=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return I(`select`,{value:i,disabled:n,"aria-label":`Pipeline placement pin`,onChange:e=>r(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[V(`option`,{value:`auto`,children:`Auto`}),a.map(e=>I(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function Ct({state:e}){if(!e.active||!e.nodeId)return V(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let t=e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`;return I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,title:e.nodeId,children:e.nodeId}),V(`span`,{className:`truncate ${e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:t,children:t})]})}function wt({role:e,state:t,mode:n,onlineNodes:r,readOnly:i=!1,isMenuOpen:a,onToggleMenu:o,onCloseMenu:s,onMove:c,onUnpin:l}){let u=yt[e],d=r.filter(e=>e.id!==(t.nodeId??``)),f=!i&&(t.active||n===`cluster`)&&(d.length>0||t.pinned);return I(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[I(`div`,{className:`flex items-center gap-2 min-w-0`,children:[V(n===`agent`?Tt:Et,{state:t,Icon:u}),V(`div`,{className:`ml-auto shrink-0`,children:f&&V(`button`,{type:`button`,onClick:o,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${bt[e]} actions`,children:V(it,{className:`h-3 w-3 text-foreground-subtle`})})})]}),a&&f&&V(kt,{title:bt[e],targets:d,pinned:t.pinned,onMove:c,onUnpin:l,onClose:s})]})}function Tt({state:e,Icon:t}){return I(`div`,{className:`flex items-center gap-1.5`,children:[V(e.active?ze:Be,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),V(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&V(ct,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Et({state:e,Icon:t}){return!e.active||!e.nodeId?I(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[V(t,{className:`h-3 w-3`}),V(`span`,{className:`text-[10px] italic`,children:`—`})]}):I(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[V(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),I(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[V(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),V(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?I(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[V(ct,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Dt=`min-h-[3.25rem]`;function Ot({snap:e}){if(!e)return V(`div`,{className:`flex items-center ${Dt}`,children:V(`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=u(t);return I(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Dt}`,children:[I(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${s.textColor}`,children:[V(y,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),V(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:s.label})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:n.toFixed(1)}),I(`span`,{children:[`/`,a.toFixed(0),` fps`]})]}),I(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[V(`span`,{className:`text-foreground`,children:r.toFixed(0)}),V(`span`,{children:` ms`}),i>0&&I(`span`,{className:`text-warning ml-1`,children:[`q`,i]})]}),I(`span`,{className:`whitespace-nowrap truncate ${o>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,V(`span`,{className:`text-foreground`,children:o})]})]})}function kt({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=_e(null);return H(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),I(`div`,{ref:o,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[V(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&V(`div`,{className:`py-1`,children:t.map(e=>I(`button`,{type:`button`,onClick:()=>r(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),n&&I(`button`,{type:`button`,onClick:i,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,e.toLowerCase()]}),t.length===0&&!n&&V(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function At({nodeId:e,refreshToken:t}){return I(`div`,{className:`space-y-6`,children:[V(gt,{refreshToken:t,nodeId:e}),I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),V(xt,{mode:`agent`,nodeId:e,compact:!0})]})}F();function jt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Mt({nodeId:e,refreshToken:t}){let n=z(),r=p({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:i}=h({nodeId:e}),a=x(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??i??null,o=a===null;K([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:s}=C({nodeId:e}),{values:c}=re(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),l=L(()=>c.filter(e=>e.metrics.phase===`active`).length,[c]),u=t=>{let n=s??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||r.mutate({nodeId:e,engine:t,force:n.length>0})};return I(`div`,{className:`space-y-6`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(a??[]).length,` engine(s) resident in RAM. `,(s??[]).length,` `,`camera(s) attached, `,l,` actively dispatching frames. Refreshes every 5s.`]})]}),V(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:I(`table`,{className:`w-full text-xs min-w-[640px]`,children:[V(`thead`,{className:`bg-surface`,children:I(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),V(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),V(`th`,{className:`text-left px-3 py-2`,children:`Models`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),V(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),V(`th`,{className:`w-20`})]})}),I(`tbody`,{children:[o&&V(`tr`,{children:V(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!o&&(a??[]).map(e=>{let t=e.kind===`warm-override`;return I(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:``}`,children:[V(`td`,{className:`px-3 py-2`,children:I(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:`bg-success/15 text-success`}`,children:[V(t?ot:U,{className:`h-3 w-3`}),t?`warm`:`runtime`]})}),V(`td`,{className:`px-3 py-2`,children:I(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[V(je,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),V(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?V(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>V(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),V(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),V(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?V(`span`,{className:`text-foreground-subtle`,children:jt(e.idleMs,e.idleTtlMs)}):V(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),V(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(s??[]).length}),V(`td`,{className:`px-3 py-2 text-right`,children:I(`button`,{type:`button`,disabled:r.isPending,onClick:()=>u(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[V(Ze,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!o&&(a??[]).length===0&&V(`tr`,{children:V(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),I(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[V(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,V(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`]}),r.isError&&I(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,r.error instanceof Error?r.error.message:`unknown`]})]})}F();var Nt=new Set(be);function Pt(e){return Nt.has(e)}function Ft(e,t,n){return`${e}/${t}/${n}`}function It(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function Lt(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 J(e){return e.format}function Rt(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 zt({addonId:e,model:t,format:n,isActive:r,progress:i,errorMsg:a,onDownload:o,onDelete:s}){let c=t.formats[n];return c?I(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors`,children:[V(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),I(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&I(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[V(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:V(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),I(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),V(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:nt(c.sizeMB)}),a&&I(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[V(We,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?I(`button`,{onClick:s,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[r?V(G,{className:`h-3 w-3 animate-spin`}):V(Ze,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):I(`button`,{onClick:o,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[r?V(G,{className:`h-3 w-3 animate-spin`}):V(we,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function Bt({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=B(!1);return I(`div`,{className:`relative`,children:[I(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[V(U,{className:`h-4 w-4 text-primary shrink-0`}),I(`div`,{className:`flex-1 min-w-0`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium text-foreground`,children:It(n)}),J(n)===J(t)&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:Lt(n)})]}),V(Ve,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&V(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let i=J(e)===J(n),o=J(e)===J(t);return I(`button`,{type:`button`,onClick:()=>{r(e),a(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${i?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[V(U,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),I(`div`,{className:`flex-1`,children:[I(`div`,{className:`flex items-center gap-2`,children:[V(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:It(e)}),o&&V(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),V(`div`,{className:`text-[10px] text-foreground-subtle`,children:Lt(e)})]}),i&&V(Je,{className:`h-4 w-4 text-primary shrink-0`})]},J(e))})})]})}function Vt({embedded:e=!1,nodeId:t}={}){let r=z(),a=t??`hub`,[o,s]=B(null),[c,l]=B(new Set),[u,f]=B(new Map),[p,h]=B(new Map),[g,_]=B(``),{data:v=[]}=n({nodeId:a}),y=v.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:b}=i({nodeId:a}),x=b,{data:S,isLoading:C}=m({nodeId:a}),w=he(),T=d();le(`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||(f(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 E=x??{runtime:`node`,backend:`cpu`,format:`onnx`},D=y.find(e=>e.format===o)??E,O=D.format,k=S?.slots??[],A=k.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(e=>e.formats[O]!==void 0)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),j=Rt(A,O),ee=ge(async(e,t,n)=>{if(!Pt(n))return;let i=Ft(e,t,n);l(e=>new Set([...e,i])),h(e=>{let t=new Map(e);return t.delete(i),t});try{await w.mutateAsync({addonId:e,modelId:t,format:n,nodeId:a}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){h(t=>new Map([...t,[i,e instanceof Error?e.message:`Download failed`]]))}finally{l(e=>{let t=new Set(e);return t.delete(i),t})}},[w,r,a]),te=ge(async(e,t,n)=>{if(!Pt(n))return;let i=Ft(e,t,n);l(e=>new Set([...e,i])),h(e=>{let t=new Map(e);return t.delete(i),t});try{await T.mutateAsync({addonId:e,modelId:t,format:n,nodeId:a}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){h(t=>new Map([...t,[i,e instanceof Error?e.message:`Delete failed`]]))}finally{l(e=>{let t=new Set(e);return t.delete(i),t})}},[T,r,a]),ne=ge(e=>{s(e.format)},[]),M=g.trim()?A.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(g.toLowerCase())||t.id.toLowerCase().includes(g.toLowerCase())||e.name.toLowerCase().includes(g.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):A,N=I(R,{children:[C&&V(`div`,{className:`flex items-center justify-center py-16`,children:V(G,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!C&&k.length===0&&I(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[V(Te,{className:`h-8 w-8 mb-3 opacity-30`}),V(`span`,{className:`text-sm`,children:`No pipeline steps available`}),V(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!C&&k.length>0&&I(R,{children:[V(Bt,{engines:y,activeEngine:E,viewEngine:D,onSelect:ne}),I(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground tabular-nums`,children:j.total}),V(`span`,{className:`ml-1`,children:`compatible models`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success tabular-nums`,children:j.downloaded}),V(`span`,{className:`ml-1`,children:`downloaded`})]}),V(`span`,{className:`text-border`,children:`|`}),I(`span`,{className:`tabular-nums`,children:[nt(j.downloadedSizeMB),V(`span`,{className:`ml-1`,children:`on disk`})]})]}),j.total>5&&I(`div`,{className:`relative`,children:[V(Re,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),V(`input`,{type:`text`,value:g,onChange:e=>_(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`})]}),M.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[O]?.downloaded).length,0);return I(`div`,{children:[I(`div`,{className:`flex items-center gap-2 mb-2`,children:[V(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),V(`div`,{className:`flex-1 h-px bg-border`}),I(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=Ft(e.id,t.id,O);return V(zt,{addonId:e.id,model:t,format:O,isActive:c.has(n),progress:u.get(t.id),errorMsg:p.get(n),onDownload:()=>ee(e.id,t.id,O),onDelete:()=>te(e.id,t.id,O)},`${e.id}/${t.id}`)}))})]},e.id)}),M.length===0&&V(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:g.trim()?I(R,{children:[`No models matching “`,g,`”`]}):I(R,{children:[`No models available for `,It(D),` format`]})})]})]});return e?V(`div`,{className:`space-y-4`,children:N}):V($e,{children:N})}function Ht({nodeId:e,refreshToken:t}){return V(Vt,{embedded:!0,nodeId:e})}var Ut=`pipeline-runner`,Wt=200;function Gt({nodeId:e}){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),I(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(O,{agentId:e,addonId:Ut,limit:Wt,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F(),F();function Kt({nodeId:e,title:t}){let{data:n}=Ne(),{data:r}=P(void 0),i=L(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),a=L(()=>{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]=B(new Map);le(`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}))}),H(()=>{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=L(()=>{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?I(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):I(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[I(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[V(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),V(`span`,{className:`text-[10px] text-foreground-subtle`,children:c.length})]}),V(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>{let t=i.get(e.deviceId)??`#${e.deviceId}`,n=u(e.metrics.phase);return I(`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:[V(y,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),V(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),V(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),V(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}F();var qt=[`pipeline-orchestrator`],Jt=[`decoder`],Yt=!1;function Xt(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 Zt({nodeId:e,refreshToken:t}){let n=z(),r=E(),[i,o]=B(null),[s,c]=B(null),[l,u]=B(null),[d,f]=B(null),p=(a(void 0).data??[]).find(t=>t.id===e)?.name??e,h=m({nodeId:e},{refetchOnMount:`always`}),g=_({agentNodeId:e},{refetchOnMount:`always`}),v=()=>{n.invalidateQueries({queryKey:[[`addonSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`pipelineExecutor`]]})},y=w({onSuccess:v}),b=ie({onSuccess:e=>{v(),f(e.effectiveModelId===null?`Reset done — model pins cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),x=async()=>{await r({title:`Reset ${p} to hardware-aware defaults?`,message:`This clears every model pin on this node (back to Auto) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(f(null),b.mutate({agentNodeId:e}))},S=h.data??null,C=g.data,T=S?.selectedEngine.format??`coreml`,O=L(()=>S?D(S):[],[S]),k=L(()=>[{agentNodeId:e,engineLabel:T}],[e,T]),A=(e,t)=>{let n=C?.addonDefaults[e];return!Xt(S,e)?.models.some(e=>!!e.formats[T])||!n?{kind:`na`}:n.enabled?{kind:`enabled`,modelId:n.modelId??`Auto`}:{kind:`disabled`}},j=i&&S?Xt(S,i.addonId):null,ee=t=>{let n=C?.addonDefaults[t]??null;o({addonId:t,agentNodeId:e}),c(n)},te=(t,n)=>{if(!C)return;let r=C.addonDefaults[t],i=Xt(S,t);if(!r&&!i)return;let a={enabled:n,modelId:r?.modelId??i?.defaultModelId??``,settings:r?.settings??{}};y.mutate({agentNodeId:e,defaults:{...C.addonDefaults,[t]:a}})},M=()=>{o(null),c(null)},N=()=>{!s||!i||!C||y.mutate({agentNodeId:e,defaults:{...C.addonDefaults,[i.addonId]:s}},{onSuccess:M})};if(h.isLoading||g.isLoading)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading pipeline…`});if(h.error)return I(`div`,{className:`text-xs text-red-400`,children:[`Failed to load catalog: `,String(h.error)]});if(!S)return V(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog unavailable for this node (runner offline?).`});let P=i!==null&&j!==null&&s!==null;return I(`div`,{className:`relative h-full w-full space-y-3`,children:[I(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[d&&V(`span`,{className:`text-emerald-400`,children:d}),b.isError&&V(`span`,{className:`text-red-400`,children:b.error instanceof Error?b.error.message:`Reset failed`}),V(`button`,{type:`button`,onClick:()=>{x()},disabled:b.isPending,className:`rounded border border-amber-500/40 bg-surface px-2 py-0.5 text-amber-300 hover:bg-surface-hover disabled:opacity-50`,title:`Clear this node's model pins (back to Auto) + per-camera overrides scoped to this node`,children:b.isPending?`Resetting…`:`Reset to default`})]}),V(Kt,{nodeId:e}),V(rt,{nodeId:e,addonIds:qt,level:`global`,sectionIds:Jt}),Yt,Yt,V(`div`,{className:P?`md:pr-[360px]`:``,children:O.length>0?V(ne,{tree:O,agents:k,getCellState:A,onCellClick:ee,selectedCell:i,onToggleEnabled:te}):V(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),I(oe,{open:P,onClose:M,title:j?.name??``,subtitle:i?`${i.agentNodeId} · ${T}`:``,footer:I(R,{children:[V(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:M,children:`Cancel`}),V(`button`,{type:`button`,disabled:!s||!i||y.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:N,children:y.isPending?`Saving…`:`Save`})]}),children:[y.isError&&I(`div`,{className:`mb-3 rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed:`,` `,y.error instanceof Error?y.error.message:String(y.error)]}),j&&s&&i&&V(fe,{mode:`agent`,addon:j,agentDefault:s,agentNodeId:i.agentNodeId,engineFormat:T,onChangeAgentConfig:e=>c(e)})]})]})}var Qt=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],$t=`decoder-nodeav`;function en({nodeId:e,refreshToken:t}){let{data:n}=a(void 0),r=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??$t,i=[...Qt,r];return I(`div`,{className:`flex flex-col h-full`,children:[V(ht,{nodeId:e,refreshToken:t}),V(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:V(rt,{nodeId:e,addonIds:i,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:V(At,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:V(Zt,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:V(Mt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:V(Ht,{nodeId:e,refreshToken:t})},{id:`logs`,label:`Logs`,order:300,content:V(Gt,{nodeId:e})}]})})]})}var tn=`pipeline-orchestrator`,nn=`recorder`,rn=`recordingNodeId`,an=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],on=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function sn(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function cn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function ln(e,t,n){let r=sn(e,t);return typeof r==`string`&&r.length>0?r:n}function un(e,t,n){let r=sn(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function dn(e,t){let n=cn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function fn(e,t){let n=cn(e,t);return typeof n==`string`&&n.length>0?n:null}function pn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function mn(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function hn(e,t){switch(t){case`detect`:return e.pipeline}}function gn(e){return e instanceof Error?e.message:`Failed to save`}function _n(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function vn({capability:e,label:t,hint:n,nodeId:r,active:i,pending:a,layout:o,onToggle:s}){let c=i?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,l=o===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,u=i?He:Me;return I(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":`${t} capability for ${r}`,title:`${t} — ${n}`,disabled:a,onClick:()=>s(e,!i),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${c} ${l}`,children:[V(u,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),V(`span`,{children:t})]})}function yn({node:e,emphasis:t=!1}){let n=e.isHub?Xe:U;return I(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[V(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),V(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),I(`div`,{className:`min-w-0`,children:[I(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[V(`span`,{className:`truncate`,children:e.name}),e.isHub&&V(c,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&V(c,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),V(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}F();function bn({nodeId:e,value:t,detectedHosts:n,status:r,errorMessage:i,onCommit:a}){let[o,s]=B(t??``);H(()=>{s(t??``)},[t]);let c=n[0],l=c===void 0?`auto-detect`:`auto: ${c}`,u=r===`pending`,d=o.trim(),f=d!==(t??``),p=f&&!u,m=()=>{p&&a(e,d.length>0?d:null)};return I(`div`,{className:`flex items-center gap-1.5`,children:[V(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:l,value:o,disabled:u,onChange:e=>s(e.target.value),onBlur:m,onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&s(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),I(`button`,{type:`button`,onClick:m,disabled:!p,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[u?V(G,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):V(He,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!f&&!u&&r===`success`&&V(He,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),r===`error`&&V(`span`,{title:i??`Failed to save reachable host`,children:V(We,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":i??`Failed to save reachable host`,role:`img`})})]})}function xn({label:e,children:t}){return I(`div`,{className:`flex items-center justify-between gap-3`,children:[V(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function Sn({node:e,actions:t}){return I(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[V(yn,{node:e,emphasis:!0}),V(`div`,{className:`grid grid-cols-2 gap-2`,children:on.map(n=>V(vn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:hn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),V(`div`,{className:`space-y-3 border-t border-border pt-3`,children:V(xn,{label:`Reachable host`,children:V(bn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function Cn(){return I(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),I(`span`,{className:`inline-flex items-center gap-1.5`,children:[V(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function wn({nodes:e,actions:t}){return V(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:I(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[V(`thead`,{children:I(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),on.map(e=>V(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),V(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),V(`tbody`,{children:e.map(e=>I(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[V(`td`,{className:`px-4 py-3 align-middle`,children:V(yn,{node:e})}),on.map(n=>V(`td`,{className:`px-3 py-3 text-center align-middle`,children:V(vn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:hn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),V(`td`,{className:`px-4 py-3 align-middle`,children:V(bn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})]},e.id))})]})})}function Tn({role:e,value:t,options:n,pending:r,onChange:i}){return I(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[V(`span`,{className:`text-xs font-semibold text-foreground`,children:pn(e)}),V(`select`,{value:t,disabled:r,onChange:t=>i(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:n.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),V(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:mn(e)})]})}function En({roleValues:e,options:t,pending:n,lowFpsEnabled:r,fpsMinThreshold:i,onRoleChange:a,onLowFpsToggle:o}){return I(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[an.map(r=>V(Tn,{role:r,value:e[r],options:t,pending:n,onChange:a},r)),I(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[V(`input`,{type:`checkbox`,checked:r,disabled:n,onChange:e=>o(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),I(`span`,{className:`flex flex-col gap-0.5`,children:[V(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),I(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,r?`${i} fps`:`disabled`]})]})]})]})}F();function Dn(e,t,n){return Math.min(Math.max(e,t),n)}function On(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function kn(e,t,n,r,i){let a=Dn(n,0,100),o=i.filter(e=>e!==t&&!r.has(e)),s=Math.max(0,100-a),c={...e,[t]:a};if(o.length>0){let e=s/o.length;for(let t of o)c[t]=e}return c}function An({nodes:e,pending:t,onCommitWeights:n}){let[r,i]=B(()=>On(e)),[a,o]=B(new Set);H(()=>{i(On(e)),o(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let s=e.map(e=>e.id),c=e=>{o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},l=(e,t)=>{i(n=>kn(n,e,t,a,s))},u=()=>{let t=e.filter(e=>Math.round(r[e.id]??0)!==e.weight).map(e=>e.id);if(t.length===0)return;let i=new Set([...t,...a]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:Math.round(r[e.id]??0)})))};if(e.length===0)return V(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let d=e.length===1;return I(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=r[e.id]??0,i=a.has(e.id);return I(`div`,{className:`flex items-center gap-3`,children:[V(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),V(`input`,{"aria-label":`Detection weight for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:t||i||d,onChange:t=>l(e.id,Number(t.target.value)),onPointerUp:()=>u(),onKeyUp:()=>u(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),I(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),V(`button`,{type:`button`,onClick:()=>c(e.id),disabled:t||d,"aria-pressed":i,title:i?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${i?`text-amber-400`:`text-foreground-subtle`}`,children:V(i?Qe:st,{className:`h-3.5 w-3.5`})})]},e.id)}),V(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share as a fixed relative weight (pinned nodes stack on top, so the total can exceed 100%). Detection only distributes across nodes that can source a camera’s frames.`})]})}F();function jn(){let e=z(),{nodes:t}=A(),n=ce(void 0),r=de({addonId:tn}),i=de({addonId:nn}),a=()=>_n(e),o=M({onSuccess:a}),s=pe(),c=T({onSuccess:a}),l=N({onSuccess:a}),[u,d]=B(!1),f=L(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),p=L(()=>t.map(e=>{let t=f.get(e.id),n=ft(t,e.isHub),r=dn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:dn(t,`maxCameras`),reachableHost:fn(t,`reachableHost`),detectedHosts:e.localIps}}),[t,f]),m=p.filter(e=>e.effective.pipeline),h={ingestNode:ln(r.data,`ingestNode`,`hub`),recordingNode:ln(i.data,rn,`hub`),audioNode:ln(r.data,`audioNode`,`hub`),motionNode:ln(r.data,`motionNode`,`hub`)},g=L(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...an.map(e=>h[e]),...e])].filter(e=>e.length>0)},[t,h]),_=un(r.data,`fpsMinThreshold`,0),v=_>0,y=n.isLoading||r.isLoading||i.isLoading,b=(e,t,n)=>{o.mutate({agentNodeId:e,[t]:n})},x=(e,t)=>{if(e===`recordingNode`){l.mutate({addonId:nn,patch:{[rn]:t}});return}l.mutate({addonId:tn,patch:{[e]:t}})},S=e=>{l.mutate({addonId:tn,patch:{fpsMinThreshold:e?Math.max(1,_):0}})},C=e=>c.variables?.agentNodeId===e?c.isPending?`pending`:c.isError?`error`:c.isSuccess?`success`:`idle`:`idle`,w=e=>C(e)===`error`?gn(c.error):null,E=async e=>{d(!0);try{for(let t of e)await s.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{d(!1),a()}},D={capabilityPending:o.isPending,onToggleCapability:b,onCommitReachableHost:(e,t)=>c.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:C,reachableHostErrorMessage:w};return I(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[I(`header`,{className:`flex items-start justify-between gap-4`,children:[I(`div`,{className:`space-y-1`,children:[V(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),V(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, distribute detection weight across detect-capable nodes, and choose the singleton cluster roles.`})]}),y&&V(G,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),V(En,{roleValues:h,options:g,pending:l.isPending,lowFpsEnabled:v,fpsMinThreshold:_,onRoleChange:x,onLowFpsToggle:S})]}),I(`div`,{className:`space-y-3`,children:[I(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),V(Cn,{})]}),p.length===0?V(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):I(R,{children:[V(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:p.map(e=>V(Sn,{node:e,actions:D},e.id))}),V(`div`,{className:`hidden @3xl/clustertab:block`,children:V(wn,{nodes:p,actions:D})})]})]}),I(`div`,{className:`space-y-3`,children:[V(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),V(An,{nodes:m,pending:u,onCommitWeights:e=>void E(e)})]})]})}F();var Mn=!1;function Nn({refreshToken:e}){let t=z(),{data:n}=a(void 0);L(()=>tt(n??[]),[n]);let r=S({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return I(`div`,{className:`space-y-6`,children:[V(gt,{refreshToken:e}),V(jn,{}),Mn,I(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[I(`div`,{className:`min-w-0`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Click the kebab to pin / unpin / move a role; expand the chevron for the per-camera broker drill-down.`})]}),I(`button`,{type:`button`,onClick:()=>r.mutate(void 0),disabled:r.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[V(je,{className:`h-3.5 w-3.5`}),r.isPending?`Rebalancing…`:`Rebalance pipelines`]})]}),V(xt,{mode:`cluster`})]})}var Pn=[`pipeline-orchestrator`];function Fn({refreshToken:e}){return V(`div`,{className:`space-y-4 max-w-3xl`,children:V(rt,{nodeId:`hub`,addonIds:Pn,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer thresholds, and failover policy. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`})})}F();function In({refreshToken:e}){let t=z(),{data:n,isLoading:r}=j(),[i,a]=B(null),[s,c]=B(``),[l,u]=B(``),d=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},f=me({onSuccess:()=>{a(null),d()}}),p=o({onSuccess:d}),m=e=>{a(e.id),c(e.name),u(e.description??``)},h=()=>{a(null),c(``),u(``)},g=()=>{if(!i)return;let e=l.trim();f.mutate({id:i,name:s.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let _=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return V(`div`,{className:`space-y-6 max-w-4xl`,children:I(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[I(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),V(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),I(`div`,{className:`text-[11px] text-foreground-subtle`,children:[_.length,` template`,_.length===1?``:`s`]})]}),_.length===0?I(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[V(Fe,{className:`h-6 w-6 opacity-40`}),V(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):V(`ul`,{className:`divide-y divide-border`,children:_.map(e=>{let t=i===e.id;return V(`li`,{className:`px-4 py-3 text-xs`,children:I(`div`,{className:`flex items-start gap-3`,children:[V(`div`,{className:`flex-1 min-w-0`,children:t?I(`div`,{className:`space-y-2`,children:[V(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:s,onChange:e=>c(e.target.value),placeholder:`Template name`,autoFocus:!0}),V(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:l,onChange:e=>u(e.target.value),placeholder:`Description (optional)`})]}):I(R,{children:[V(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&V(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),I(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,I(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),V(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?I(R,{children:[I(`button`,{type:`button`,onClick:g,disabled: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:[V(He,{className:`h-3 w-3`}),`Save`]}),I(`button`,{type:`button`,onClick:h,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[V(qe,{className:`h-3 w-3`}),`Cancel`]})]}):I(R,{children:[V(`button`,{type:`button`,onClick:()=>m(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:V(Pe,{className:`h-3 w-3`})}),V(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&p.mutate({id:e.id})},disabled:p.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:V(Ze,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}F();function Ln(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Rn({nodeId:e,refreshToken:t}){let n=z(),r=Ce().trpcClient,[i,o]=B(null),[s,c]=B(null),l=ce(void 0,{refetchOnMount:`always`});K([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`,`addon.updated`]);let u=a(void 0,{refetchOnMount:`always`}),d=L(()=>{let e=new Set;for(let t of u.data??[])t.isOnline&&e.add(t.id);return e},[u.data]),f=m({nodeId:e},{refetchOnMount:`always`}),p=L(()=>(l.data??[]).filter(e=>d.has(e.nodeId)).map(e=>e.nodeId),[l.data,d]),h=ye({enabled:p.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`schema-by-agent`,p.join(`,`),t],queryFn:async()=>{let e={};for(let t of p)try{e[t]=(await r.pipelineExecutor.getSchema.query({nodeId:t})).selectedEngine.format}catch{e[t]=`coreml`}return e}}),g=w({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),n.invalidateQueries({queryKey:[[`pipelineExecutor`]]}),n.invalidateQueries({queryKey:[[`addonSettings`]]})}}),_=L(()=>f.data?D(f.data):[],[f.data]),v=L(()=>{let e=l.data??[],t=d;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)`}})},[l.data,h.data,d]),y=(e,t)=>{let n=(l.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e],r=h.data?.[t];return!Ln(f.data??null,e)?.models.some(e=>r!==void 0&&!!e.formats[r])||!n?{kind:`na`}:n.enabled?{kind:`enabled`,modelId:n.modelId??`Auto`}:{kind:`disabled`}},b=i?l.data?.find(e=>e.nodeId===i.agentNodeId)??null:null,x=i&&f.data?Ln(f.data,i.addonId):null,S=i?h.data?.[i.agentNodeId]??`coreml`:`coreml`,C=()=>{o(null),c(null)},T=(e,t)=>{let n=(l.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e]??null;o({addonId:e,agentNodeId:t}),c(n)},E=()=>{!s||!i||!b||g.mutate({agentNodeId:i.agentNodeId,defaults:{...b.settings.addonDefaults,[i.addonId]:s}},{onSuccess:C})};if(l.isLoading||f.isLoading)return V(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading agents…`});if(!f.data)return I(`div`,{className:`text-xs text-foreground-subtle`,children:[`Catalog unavailable for `,e,`.`]});let O=i!==null&&x!==null&&s!==null;return I(`div`,{className:`relative h-full w-full space-y-3`,children:[V(Kt,{title:`Cluster cameras`}),V(`div`,{className:O?`md:pr-[360px]`:``,children:_.length>0&&v.length>0?V(ne,{tree:_,agents:v,getCellState:y,onCellClick:T,selectedCell:i}):V(`div`,{className:`text-xs text-foreground-subtle`,children:`No agents or catalog empty.`})}),I(oe,{open:O,onClose:C,title:x?.name??``,subtitle:i?`${i.agentNodeId} · ${S}`:``,footer:I(R,{children:[V(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:C,children:`Cancel`}),V(`button`,{type:`button`,disabled:!s||!i||g.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:E,children:g.isPending?`Saving…`:`Save`})]}),children:[g.isError&&I(`div`,{className:`mb-3 rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed:`,` `,g.error instanceof Error?g.error.message:String(g.error)]}),x&&s&&i&&V(fe,{mode:`agent`,addon:x,agentDefault:s,agentNodeId:i.agentNodeId,engineFormat:S,onChangeAgentConfig:e=>c(e)})]})]})}F();function zn({types:e}){let t=z(),n=E(),{data:i}=te({}),a=l(),o=L(()=>a.data??[],[a.data]),[s,c]=B(null),[u,d]=B(null),f=()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},p=ee({onSuccess:f}),m=r({onSuccess:f}),h=L(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),g=e=>{e.isDefault||p.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},_=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`})&&m.mutate({id:e.id})},v=e.map(e=>o.find(t=>t.id===e)).filter(e=>e!==void 0);return I(`div`,{className:`space-y-3`,children:[v.length===0?V(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:`No storage locations declared for this purpose.`}):v.map(e=>V(De,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:h.get(e.id)??[],onAdd:e=>c(e),onEdit:e=>d(e),onDelete:e=>{_(e)},onSetDefault:e=>g(e)},e.id)),s!==null&&V(Oe,{initialType:s,onClose:()=>c(null),onCreated:()=>{f(),c(null)}}),u!==null&&V(Ee,{location:u,onClose:()=>d(null),onSaved:()=>{f(),d(null)}})]})}F();var Bn=`pipeline-analytics`;function Vn(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 Hn(){let e=z(),{data:t}=a(void 0),{data:n,isLoading:r}=de({addonId:Bn}),i=Vn(n),o=N({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),s=L(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return I(`div`,{className:`flex flex-col gap-6`,children:[I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),V(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),I(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?V(G,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):V(`select`,{value:i,onChange:e=>{e.target.value!==i&&o.mutate({addonId:Bn,patch:{postProcessingNodeId:e.target.value}})},disabled:o.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:s.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),o.isPending&&V(G,{className:`h-4 w-4 animate-spin text-primary`})]})]}),I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),V(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),V(zn,{types:[`eventMedia`]})]})]})}F();var Un=`recorder`;function Wn(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 Gn(){let e=z(),{data:t}=a(void 0),{data:n,isLoading:r}=de({addonId:Un}),i=Wn(n,`recordingNodeId`,`hub`),o=N({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),s=L(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return I(`div`,{className:`flex flex-col gap-6`,children:[I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),V(`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.`}),I(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?V(G,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):V(`select`,{value:i,onChange:e=>{e.target.value!==i&&o.mutate({addonId:Un,patch:{recordingNodeId:e.target.value}})},disabled:o.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:s.map(e=>V(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),o.isPending&&V(G,{className:`h-4 w-4 animate-spin text-primary`})]}),i!==`hub`&&I(`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`,` `,V(`span`,{className:`font-medium`,children:i}),`. If the auto-derived host doesn't work, set the recorder's`,V(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),I(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[V(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),V(`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.`}),V(zn,{types:[`recordings`,`recordingsLow`]})]})]})}var Kn=`pipeline-orchestrator`,qn=200;function Jn(){return I(`div`,{className:`flex flex-col gap-3`,children:[I(`div`,{children:[V(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),V(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),V(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:V(O,{addonId:Kn,limit:qn,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}F();var Yn=[{id:`assignments`,label:`Assignments`},{id:`pipeline`,label:`Pipeline`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function Xn({refreshToken:e}){let[t,n]=B(`assignments`),{data:r}=a(void 0),i=r?.find(e=>e.isHub&&e.isOnline)?.id??r?.find(e=>e.isOnline)?.id??null;return I(`div`,{className:`flex flex-col h-full`,children:[I(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[V(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),V(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Assignments with live load, cluster-wide settings, pipeline template library, per-camera pipeline overrides.`})]}),V(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Yn.map(e=>V(`button`,{type:`button`,onClick:()=>n(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),I(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&V(Nn,{refreshToken:e}),t===`pipeline`&&(i?V(Rn,{nodeId:i,refreshToken:e}):V(`div`,{className:`text-xs text-foreground-subtle`,children:`No online node available — schema unreachable.`})),t===`events`&&V(Hn,{}),t===`recording`&&V(Gn,{}),t===`settings`&&V(Fn,{refreshToken:e}),t===`templates`&&V(In,{refreshToken:e}),t===`logs`&&V(Jn,{})]})]})}function Zn(e){let t=[],n=[],{assignment:r,detection:i,decoder:a,broker:o}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),i!==null&&i.phase===`active`&&a!==null&&a.shm.framesWritten===0&&t.push({code:`decoder-black-hole`,severity:`error`,message:`Decoder on ${a.nodeId} has written 0 frames to the shared-memory plane while detection is active — the decode path is stalled`}),r.detectionNodeId===null&&i===null&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});for(let e of o?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function Qn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function $n(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function er(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function tr(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var nr={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function rr(e){if(!Qn(e)||!Array.isArray(e.sections))return nr;let t=xe(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)tr(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:$n(n(`detectionFps`)),motionSources:er(n(`motionSources`)),motionFps:$n(n(`motionFps`)),motionCooldownMs:$n(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function ir(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...ir(r.children,t+1));return n}function ar(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function X({title:e,children:t}){return I(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[V(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),V(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return I(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[V(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),V(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&V(or,{})]})}function or(){return V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var sr={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return V(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${sr[e]}`,children:t})}function $({children:e}){return V(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function cr({icon:e,label:t,nodeId:n,pinned:r,reason:i,overridden:a}){return I(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[V(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),V(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?V(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):I(R,{children:[V(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?I(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[V(ct,{className:`h-2.5 w-2.5`}),` manual`]}):I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,i!==void 0&&i.length>0?i:`capacity`]}),a&&V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function lr({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:i}){let a=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,o=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return I(X,{title:`Where it runs`,children:[V(cr,{icon:U,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),V(cr,{icon:at,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),V(cr,{icon:Ae,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),V(cr,{icon:Ie,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),V(`div`,{className:`mt-1.5`,children:I(`select`,{value:a,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>i(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[V(`option`,{value:`auto`,children:`Auto (load balanced)`}),o.map(e=>I(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function ur(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function dr(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function fr(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function pr({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:i}){let a=dr(t,n.detectionStreamProfile),o=dr(t,n.motionStreamProfile),s=n.motionSources.includes(`analyzer`);return I(X,{title:`Streams & motion`,children:[I(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,a!==void 0&&` · ${a.width}×${a.height} ${a.codec}`]}),V(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:fr(n.detectionFps)}),I(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.join(` + `):`none`,r===!1&&` · inactive`]}),s&&I(R,{children:[I(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,o!==void 0&&` · ${o.width}×${o.height} ${o.codec}`]}),I(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[fr(n.motionFps),i!==null&&` · live ${i.toFixed(1)}`]})]}),V(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),V(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?V($,{children:`No streams registered`}):e.map(e=>I(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[V(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,ur(e)]},e.camStreamId))})]})}function mr({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return I(X,{title:`Pipeline steps`,children:[e===void 0?V($,{children:`Resolving…`}):e.length===0?V($,{children:`No steps configured`}):V(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>V(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:I(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&V(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&I(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),V(`div`,{className:`mt-1`,children:I(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var hr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function gr({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return I(X,{title:`Detection runtime`,children:[V(Z,{label:`Mode`,overridden:r,children:n??`—`}),V($,{children:`Detection stage inactive or unreachable`})]});let i=t?.phase??e.phase,a=t?.actualFps??e.actualFps,o=t?.configuredFps??e.configuredFps,s=t?.avgInferenceTimeMs??e.avgInferenceMs,c=t?.queueDepth??e.queueDepth,l=u(i),d=i===`active`&&a===0;return I(X,{title:`Detection runtime`,children:[I(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[I(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${l.badgeClass}`,children:[V(y,{phase:i,className:`h-2.5 w-2.5`}),l.label]}),t!==void 0&&V(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),V(Z,{label:`Mode`,overridden:r,children:n??`—`}),I(Z,{label:`FPS`,children:[V(`span`,{className:d?`text-danger font-semibold`:``,children:a.toFixed(1)}),I(`span`,{className:`text-foreground-subtle`,children:[` / `,o.toFixed(0),` configured`]})]}),I(Z,{label:`Inference`,children:[s.toFixed(0),` ms`,c>0&&I(`span`,{className:`text-warning`,children:[` · queue `,c]}),t!==void 0&&t.droppedFrames>0&&I(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),I(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),I(Z,{label:`Provisioning`,children:[V(Q,{tone:hr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&I(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function _r({broker:e}){return e===null?V(X,{title:`Stream broker`,children:V($,{children:`Broker stage inactive or unreachable`})}):I(X,{title:`Stream broker`,children:[e.profiles.length===0?V($,{children:`No broker profiles`}):V(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return I(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),V(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),I(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),I(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),I(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),I(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[I(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),I(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function vr({decoder:e,detectionActive:t}){if(e===null)return V(X,{title:`Decoder`,children:V($,{children:`Decoder stage inactive or unreachable`})});let n=t&&e.shm.framesWritten===0;return I(X,{title:`Decoder`,children:[V(Z,{label:`Node`,children:e.nodeId}),V(Z,{label:`Sessions`,children:e.sessionCount}),I(Z,{label:`SHM frames`,children:[V(`span`,{className:n?`text-danger font-semibold`:``,children:e.shm.framesWritten}),V(`span`,{className:`text-foreground-subtle`,children:` written`})]}),I(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&I(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),I(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&V(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}F();var yr=`pipeline-orchestrator`,br={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},xr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Sr({problems:e}){return V(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>I(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[V(Ye,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),V(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function Cr({deviceId:e,name:t,online:n,status:r,live:i,onlineNodes:a}){let o=z(),{data:s}=ae({addonId:yr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:c}=ue({deviceId:e},{staleTime:3e4}),l=L(()=>rr(s),[s]),u=L(()=>c===void 0?void 0:ir(c.steps),[c]),d=L(()=>r===void 0?[]:Zn(r),[r]),f=()=>{o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},p=se({onSuccess:f}),m=b({onSuccess:f}),h=t=>{t===`auto`?m.mutate({deviceId:e}):p.mutate({deviceId:e,agentNodeId:t})},g=r===void 0?`idle`:ar(r),_=d.some(e=>e.severity===`error`),v=d.length>0,y=_?`border-danger/50`:v?`border-warning/40`:`border-border`;return I(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${y} bg-background overflow-hidden`,children:[I(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[V(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${_?`bg-danger`:br[g]}`,title:_?`Error`:xr[g],"aria-label":_?`Error`:xr[g],role:`img`}),V(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),I(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&V(Q,{tone:`danger`,children:`offline`}),I(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[l.detectionMode!==null&&V(Q,{tone:l.detectionMode===`disabled`?`warning`:l.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:l.detectionMode===`disabled`?`detection off`:l.detectionMode}),r?.recording!=null&&(r.recording.active?I(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[V(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&I(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),d.length>0&&V(Sr,{problems:d}),r===void 0?V(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):I(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[V(lr,{assignment:r.assignment,settings:l,onlineNodes:a,pinPending:p.isPending||m.isPending,onDetectionPinChange:h}),V(gr,{detection:r.detection,live:i,detectionMode:l.detectionMode,modeOverridden:l.overriddenKeys.has(`detectionMode`)}),V(mr,{steps:u,audioModelId:c?.audio?.modelId??null,audioEnabled:r.audio?.enabled??c?.audio?.enabled??null,audioMode:l.audioMode}),V(pr,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:l,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null}),V(_r,{broker:r.broker}),V(vr,{decoder:r.decoder,detectionActive:r.detection?.phase===`active`})]})]})}F();var wr=5e3,Tr=1e4,Er=5e3;function Dr(t){let n=z(),{data:r,isLoading:i}=Ne(),{data:a,isLoading:o}=e({},{refetchInterval:wr}),{nodes:s}=A();H(()=>{t!==0&&n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[t,n]);let[c,l]=B(new Map);le(Se.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&l(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),H(()=>{if(c.size===0)return;let e=setInterval(()=>{l(e=>{let t=Date.now()-Tr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},Er);return()=>clearInterval(e)},[c.size]);let u=L(()=>{let e=new Map;for(let t of a??[])e.set(t.deviceId,t);return e},[a]);return{rows:L(()=>(r??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:u.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[r,u]),liveMetrics:c,onlineNodes:L(()=>(s??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[s]),isLoading:i||o}}F();function Or({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:i}=Dr(e),a=L(()=>[...t.map(e=>{let t=e.status===void 0?[]:Zn(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),o=L(()=>{let e=0,t=0;for(let r of a)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:a.length,active:e,issues:t}},[a,n]);return i&&t.length===0?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?V(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):V(`div`,{className:`h-full overflow-y-auto`,children:I(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[I(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[I(`span`,{children:[V(`span`,{className:`font-semibold text-foreground`,children:o.total}),` cameras`]}),I(`span`,{children:[V(`span`,{className:`font-semibold text-success`,children:o.active}),` actively inferring`]}),I(`span`,{children:[V(`span`,{className:`font-semibold ${o.issues>0?`text-danger`:`text-foreground`}`,children:o.issues}),` `,`with issues`]}),V(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),a.map(({row:e})=>V(Cr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}F();var kr=`__cluster__`;function Ar(e){return e===`cameras`?`cameras`:`nodes`}function jr(){let[e,t]=Ue(),n=Ar(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[i,a]=B(0),[o,s]=B(!1);return H(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:kr},{replace:!0})},[n,e,t]),I(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[I(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[I(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[V(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:r},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),V(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),I(`button`,{type:`button`,onClick:()=>a(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[V(Le,{className:`h-3.5 w-3.5`}),`Refresh`]})]}),n===`nodes`&&I(`button`,{type:`button`,onClick:()=>s(e=>!e),"aria-expanded":o,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[I(`span`,{children:[o?`Hide`:`Show`,` node list`]}),V(Ve,{className:[`h-4 w-4 transition-transform`,o?`rotate-180`:``].join(` `)})]}),V(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?I(R,{children:[V(`aside`,{className:[o?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:V(mt,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),s(!1)},refreshToken:i})}),V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?V(Xn,{refreshToken:i}):V(en,{nodeId:r,refreshToken:i})})]}):V(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:V(Or,{refreshToken:i})})})]})}export{jr as PipelinePage};
@@ -1 +1 @@
1
- import{Fa as e,Ia as t,Pa as n}from"./src-nTmr96zw.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-BjWq4Lsw.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(t,{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(t=>{let r=I===t.id,i=t.shape.kind===`polygon`?ne:e;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(t.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 `,t.id]}),u(`span`,{className:`text-foreground-faint capitalize`,children:t.shape.kind})]}),u(`button`,{type:`button`,onClick:()=>ae(t.id),disabled:M,"aria-label":`Delete zone ${String(t.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(n,{className:`h-3.5 w-3.5`})})]},t.id)})}):null]}):u(`p`,{className:`${f} leading-relaxed`,children:`Loading the camera's privacy mask…`})})}):null}export{w as PrivacyMaskSettings};
1
+ import{Fa as e,Ia as t,Pa as n}from"./src-BD_Vx_7m.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-Dsrz7Epi.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(t,{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(t=>{let r=I===t.id,i=t.shape.kind===`polygon`?ne:e;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(t.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 `,t.id]}),u(`span`,{className:`text-foreground-faint capitalize`,children:t.shape.kind})]}),u(`button`,{type:`button`,onClick:()=>ae(t.id),disabled:M,"aria-label":`Delete zone ${String(t.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(n,{className:`h-3.5 w-3.5`})})]},t.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-Dil4Ibsx.js";import{t as a}from"./wifi-Dnk9IQ1K.js";import{H as o,p as s}from"./index-Cs4056Il.js";var c=o(`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=o(`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:s,color:`#a855f7`,label:`Scrypted`},reolink:{icon:i,color:`#06b6d4`,label:`Reolink`},homeassistant:{icon:l,color:`#22d3ee`,label:`Home Assistant`},rtsp:{icon:a,color:`#78716c`,label:`RTSP`},onvif:{icon:a,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};
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-RxH1E0zh.js";import{t as a}from"./wifi-CVIceYWr.js";import{H as o,p as s}from"./index-BbLGFHTA.js";var c=o(`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=o(`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:s,color:`#a855f7`,label:`Scrypted`},reolink:{icon:i,color:`#06b6d4`,label:`Reolink`},homeassistant:{icon:l,color:`#22d3ee`,label:`Home Assistant`},rtsp:{icon:a,color:`#78716c`,label:`RTSP`},onvif:{icon:a,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};
@@ -1 +1 @@
1
- import{Dn as e,Qt as t,Zt as n,_n as r,hn as i,jn as a,qt as o,sn as s}from"./src-nTmr96zw.js";import{I as c,K as l,Q as u,S as d,W as f,b as p,q as m,x as h,z as g}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 _}from"./download-pveeJDxf.js";import{t as v}from"./refresh-cw-Deh_KPTo.js";import{H as y,I as b,O as x,P as S,S as C,i as w,o as T}from"./index-Cs4056Il.js";import{t as E}from"./FormBuilder-DmAaqS0P.js";import{t as D}from"./BrokerForm-B3T_wC8B.js";var O=y(`radar`,[[`path`,{d:`M19.07 4.93A10 10 0 0 0 6.99 3.34`,key:`z3du51`}],[`path`,{d:`M4 6h.01`,key:`oypzma`}],[`path`,{d:`M2.29 9.62A10 10 0 1 0 21.31 8.35`,key:`qzzz0`}],[`path`,{d:`M16.24 7.76A6 6 0 1 0 8.23 16.67`,key:`1yjesh`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}],[`path`,{d:`M17.99 11.66A6 6 0 0 1 15.77 16.67`,key:`1u2y91`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}],[`path`,{d:`m13.41 10.59 5.66-5.66`,key:`mhq4k0`}]]);u();var k=[`amazon.com`,`amazon.it`,`amazon.de`,`amazon.co.uk`,`amazon.fr`,`amazon.es`,`amazon.ca`,`amazon.com.au`,`amazon.co.jp`,`amazon.in`,`amazon.com.br`,`amazon.com.mx`],A=`/addon/import-alexa`,j=2e3;function M(e){return typeof e==`object`&&!!e&&typeof e.sessionId==`string`&&typeof e.loginUrl==`string`}function N(e){return typeof e==`object`&&!!e&&typeof e.phase==`string`&&typeof e.sessionId==`string`}function P(e){return typeof e==`object`&&!!e&&typeof e.brokerId==`string`}function F(e){return{"Content-Type":`application/json`,Authorization:`Bearer ${localStorage.getItem(`camstack_admin_token`)??``}`,...e}}async function I(e,t,n){let r=await fetch(`${A}${e}`,{method:`POST`,headers:F(),body:JSON.stringify(t)}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!n(i))throw Error(`Unexpected response from server`);return i}async function L(e){let t=new URLSearchParams({sessionId:e}),n=localStorage.getItem(`camstack_admin_token`)??``,r=await fetch(`${A}/login/status?${t.toString()}`,{headers:{Authorization:`Bearer ${n}`}}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!N(i))throw Error(`Unexpected status response from server`);return i}async function R(e){try{await fetch(`${A}/login/cancel`,{method:`POST`,headers:F(),body:JSON.stringify({sessionId:e})})}catch{}}function z({brokerId:e,onResolved:t,onCancel:n}){let[r,i]=m(`amazon.it`),[a,o]=m(`Alexa account`),[s,u]=m({kind:`idle`}),f=l(!0);g(()=>(f.current=!0,()=>{f.current=!1}),[]);let p=l(null),_=l(null),y=c(()=>{_.current!==null&&(clearInterval(_.current),_.current=null)},[]),b=c(async n=>{y(),f.current&&u({kind:`committing`,sessionId:n});try{let r=await I(`/login/commit`,{sessionId:n,name:a.trim().length>0?a.trim():`Alexa account`,...e===void 0?{}:{brokerId:e}},P);p.current=null,t(r.brokerId)}catch(e){let t=e instanceof Error?e.message:String(e);f.current&&u({kind:`error`,message:t,sessionId:n})}},[e,a,t,y]),S=c((e,t)=>{y();let n=async()=>{try{let n=await L(e);if(n.phase===`captured`){y(),b(e);return}if(n.phase===`error`){y(),f.current&&u({kind:`error`,message:n.error??`Login proxy returned an error`,sessionId:e});return}if(n.phase===`cancelled`){y(),f.current&&u({kind:`idle`});return}f.current&&u({kind:`polling`,sessionId:e,loginUrl:n.loginUrl||t,phase:n.phase})}catch(e){let t=e instanceof Error?e.message:String(e);f.current&&u(e=>e.kind===`polling`?{...e}:{kind:`error`,message:t,sessionId:null})}};_.current=setInterval(()=>{n()},j)},[y,b]);g(()=>()=>{y(),p.current!==null&&R(p.current)},[y]);let w=async()=>{y(),p.current!==null&&(R(p.current),p.current=null),u({kind:`starting`});try{let e=await I(`/login/start`,{amazonDomain:r},M);p.current=e.sessionId,u({kind:`polling`,sessionId:e.sessionId,loginUrl:e.loginUrl,phase:`starting`}),S(e.sessionId,e.loginUrl)}catch(e){u({kind:`error`,message:e instanceof Error?e.message:String(e),sessionId:null})}},E=()=>{y(),p.current!==null&&(R(p.current),p.current=null),u({kind:`idle`})},D=()=>{E()},O=s.kind===`idle`,A=s.kind===`starting`,N=s.kind===`polling`,F=s.kind===`committing`,z=s.kind===`error`,B=A||N||F,V=s.kind===`polling`?s.phase:null,H=s.kind===`polling`?s.loginUrl:null,U=N&&V===`awaiting-login`,W=N&&(V===`starting`||V===null);return d(`div`,{className:`space-y-4`,children:[(O||z)&&d(`div`,{className:`space-y-3`,children:[e===void 0&&d(`div`,{className:`space-y-1`,children:[h(`label`,{htmlFor:`alexa-account-name`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Account name`}),h(`input`,{id:`alexa-account-name`,type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:`Alexa account`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),d(`div`,{className:`space-y-1`,children:[h(`label`,{htmlFor:`alexa-amazon-region`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Amazon region`}),h(`select`,{id:`alexa-amazon-region`,value:r,onChange:e=>i(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:k.map(e=>h(`option`,{value:e,children:e},e))})]})]}),z&&d(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px] flex items-start gap-2`,children:[h(T,{className:`h-3.5 w-3.5 mt-0.5 flex-shrink-0`}),h(`span`,{children:s.message})]}),A&&d(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[h(C,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Starting login proxy…`]}),W&&d(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[h(C,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Waiting for proxy to be ready…`]}),F&&d(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[h(C,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Saving credentials…`]}),U&&H!==null&&d(`div`,{className:`space-y-3`,children:[d(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-2`,children:[h(`p`,{className:`text-xs font-semibold text-foreground`,children:`Open the link below to log in to your Amazon account`}),h(`p`,{className:`text-[10px] text-foreground-subtle`,children:`After completing the login and any 2FA steps, this wizard will continue automatically.`}),d(`a`,{href:H,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[h(x,{className:`h-3.5 w-3.5`}),`Login to Amazon`]})]}),d(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[10px] text-amber-700 dark:text-amber-300`,children:[h(`strong`,{children:`Note:`}),` The login proxy runs directly on the hub. If the link does not open or the page does not load, make sure the hub's proxy host and port are reachable from your browser. You can configure `,h(`code`,{className:`font-mono`,children:`proxyHost`}),` in the Alexa addon settings and ensure the proxy port is published (Docker port mapping).`]}),d(`div`,{className:`flex items-center gap-2 text-[10px] text-foreground-subtle`,children:[h(C,{className:`h-3 w-3 animate-spin`}),`Waiting for Amazon login to complete…`]})]}),d(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[h(`button`,{type:`button`,onClick:B?E:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:B?`Cancel login`:`Back`}),d(`div`,{className:`flex items-center gap-2`,children:[z&&d(`button`,{type:`button`,onClick:D,className:`inline-flex items-center gap-1.5 rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10`,children:[h(v,{className:`h-3.5 w-3.5`}),`Retry`]}),O&&h(`button`,{type:`button`,onClick:()=>{w()},disabled:e===void 0&&a.trim().length===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:`Start login`})]})]})]})}u();var B=`alexa`;function V(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function H(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var U={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function W({kind:e,onResolved:r,onBack:i}){let[a,s]=m(e===B?`alexa-login`:`existing`),c=n({kind:e}),l=f(()=>V(c.data).filter(t=>t.kind===e),[c.data,e]),u=t(),p=f(()=>{for(let t of H(u.data))if(t.kinds.some(t=>t.kind===e))return t.addonId},[u.data,e]),[g,_]=m(null),[v,y]=m(``),b=o({}),x=()=>{g&&r(g)},w=async t=>{v.trim().length!==0&&r((await b.mutateAsync({kind:e,name:v.trim(),settings:t,...p===void 0?{}:{addonId:p}})).id)},T=e=>{e===`new`?_(null):b.reset(),s(e)};return d(`div`,{className:`space-y-4`,children:[d(`button`,{type:`button`,onClick:i,className:`inline-flex items-center gap-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[h(S,{className:`h-3.5 w-3.5`}),` Back`]}),d(`div`,{className:`inline-flex rounded-lg border border-border p-0.5 flex-wrap gap-0.5`,children:[e===B&&h(`button`,{type:`button`,onClick:()=>T(`alexa-login`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`alexa-login`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Login interactively`}),h(`button`,{type:`button`,onClick:()=>T(`existing`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`existing`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Use existing`}),h(`button`,{type:`button`,onClick:()=>T(`new`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`new`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:e===B?`Paste cookie`:`Create new`})]}),a===`alexa-login`&&h(z,{onResolved:r,onCancel:i}),a===`existing`&&d(`div`,{className:`space-y-3`,children:[c.isLoading&&d(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[h(C,{className:`h-3.5 w-3.5 animate-spin`}),` Loading brokers…`]}),c.isError&&d(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load brokers:`,` `,c.error instanceof Error?c.error.message:`Unknown error`]}),!c.isLoading&&!c.isError&&l.length===0&&d(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-6 text-center text-xs text-foreground-subtle`,children:[`No brokers of this kind yet. Switch to`,` `,h(`span`,{className:`font-medium text-foreground`,children:e===B?`Login interactively`:`Create new`}),` `,`to register one.`]}),h(`div`,{className:`space-y-2`,children:l.map(e=>d(`button`,{type:`button`,onClick:()=>_(e.id),className:`flex w-full items-center justify-between gap-3 rounded-lg border bg-surface p-3 text-left transition-colors ${g===e.id?`border-primary ring-1 ring-primary`:`border-border hover:border-foreground-subtle/30`}`,children:[h(`span`,{className:`text-xs font-semibold text-foreground`,children:e.name}),h(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${U[e.status]}`,children:e.status})]},e.id))}),l.length>0&&h(`div`,{className:`flex justify-end pt-1`,children:h(`button`,{type:`button`,onClick:x,disabled:!g,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:`Use this broker`})})]}),a===`new`&&d(`div`,{className:`space-y-3`,children:[d(`div`,{className:`space-y-1`,children:[h(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),h(`input`,{type:`text`,value:v,onChange:e=>y(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),b.isError&&h(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:b.error instanceof Error?b.error.message:String(b.error)}),h(D,{kind:e,...p===void 0?{}:{addonId:p},onSubmit:e=>{w(e).catch(()=>{})},onCancel:i,submitLabel:b.isPending?`Creating…`:`Create broker`,disabled:b.isPending||v.trim().length===0}),v.trim().length===0&&h(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before creating.`})]})]})}u();function G({open:t,onClose:n,scope:r}){let i=s(),[a,o]=m(new Set),[l,u]=m(new Set),{data:p}=e({}),g=f(()=>new Set((p??[]).map(e=>e.stableId)),[p]),v=c(async(e,t)=>{u(e=>new Set(e).add(t.stableId));try{await i.mutateAsync({addonId:e,candidate:t}),o(e=>new Set(e).add(t.stableId))}catch{}finally{u(e=>{let n=new Set(e);return n.delete(t.stableId),n})}},[i]),y=c((e,t)=>{let n=typeof t.prefilledConfig.host==`string`?t.prefilledConfig.host:null,r=g.has(t.stableId),i=a.has(t.stableId)||r,o=l.has(t.stableId);return d(`div`,{className:`flex items-center justify-between rounded-lg border border-border bg-surface px-3 py-2`,children:[d(`div`,{className:`min-w-0`,children:[h(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.suggestedName}),n&&h(`p`,{className:`truncate text-[10px] font-mono text-foreground-subtle`,children:n})]}),i?d(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[h(b,{className:`h-3.5 w-3.5`}),` `,r?`Already added`:`Added`]}):d(`button`,{type:`button`,onClick:()=>void v(e,t),disabled:o,className:`flex items-center gap-1 rounded-md bg-primary px-2.5 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[o?h(C,{className:`h-3.5 w-3.5 animate-spin`}):h(_,{className:`h-3.5 w-3.5`}),`Add`]})]},t.stableId)},[a,l,g,v]);if(!t)return null;let x=r?`Scan network — ${r.label}`:`Scan network for devices`;return d(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[h(`div`,{className:`absolute inset-0 bg-black/60`,onClick:n}),d(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl`,children:[d(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[d(`div`,{className:`flex items-center gap-2`,children:[h(O,{className:`h-4 w-4 text-primary`}),h(`h2`,{className:`text-sm font-semibold text-foreground`,children:x})]}),h(`button`,{onClick:n,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:h(w,{className:`h-4 w-4`})})]}),r?h(q,{scope:r,onAdopt:y,onReset:()=>o(new Set)}):h(K,{onAdopt:y,onReset:()=>o(new Set)})]})]})}function K({onAdopt:e,onReset:t}){let n=i(),r=c(()=>{t(),n.mutate({})},[n,t]);g(()=>{!n.isPending&&!n.data&&r()},[]);let a=f(()=>(n.data?.groups??[]).filter(e=>e.candidates.length>0),[n.data]),o=f(()=>a.reduce((e,t)=>e+t.candidates.length,0),[a]);return d(p,{children:[h(`div`,{className:`flex items-center justify-end gap-2 border-b border-border px-5 py-2 shrink-0`,children:d(`button`,{onClick:r,disabled:n.isPending,className:`flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[h(v,{className:`h-3.5 w-3.5 ${n.isPending?`animate-spin`:``}`}),`Re-scan`]})}),d(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4`,children:[n.isPending&&h(J,{label:`Scanning the local network…`}),!n.isPending&&n.isError&&h(Y,{}),!n.isPending&&n.data&&a.length===0&&h(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:`No devices responded to the scan.`}),!n.isPending&&a.length>0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:[`Found `,o,` device`,o===1?``:`s`,` on the network.`]}),!n.isPending&&a.map(t=>d(`div`,{className:`space-y-1.5`,children:[d(`div`,{className:`flex items-center gap-2`,children:[h(`span`,{className:`text-[11px] font-semibold text-foreground`,children:t.label}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`(`,t.candidates.length,`)`]})]}),t.candidates.map(n=>e(t.addonId,n))]},t.addonId))]})]})}function q({scope:e,onAdopt:t,onReset:n}){let i=a({addonId:e.addonId}).data??null,[o,s]=m({}),l=r(),u=c(()=>{n(),l.mutate({addonId:e.addonId,params:o})},[l,e.addonId,o,n]),f=l.data?.candidates??[];return h(p,{children:d(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4`,children:[i&&h(E,{schema:i,values:o,onChange:s}),d(`button`,{onClick:u,disabled:l.isPending,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[l.isPending?h(C,{className:`h-3.5 w-3.5 animate-spin`}):h(O,{className:`h-3.5 w-3.5`}),l.isPending?`Scanning…`:`Scan`]}),l.isError&&h(Y,{}),!l.isPending&&l.data&&f.length===0&&h(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:`No devices responded to the scan.`}),!l.isPending&&f.length>0&&d(`div`,{className:`space-y-1.5`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:[`Found `,f.length,` device`,f.length===1?``:`s`,`.`]}),f.map(n=>t(e.addonId,n))]})]})})}function J({label:e}){return d(`div`,{className:`flex flex-col items-center py-12`,children:[h(C,{className:`h-6 w-6 animate-spin text-primary`}),h(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:e})]})}function Y(){return d(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[h(T,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),h(`p`,{className:`text-xs text-destructive`,children:`The scan failed. Try again.`})]})}export{W as n,O as r,G as t};
1
+ import{Dn as e,Qt as t,Zt as n,_n as r,hn as i,jn as a,qt as o,sn as s}from"./src-BD_Vx_7m.js";import{I as c,K as l,Q as u,S as d,W as f,b as p,q as m,x as h,z as g}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 _}from"./download-gY2u92nb.js";import{t as v}from"./refresh-cw-C6St6mBe.js";import{H as y,I as b,O as x,P as S,S as C,i as w,o as T}from"./index-BbLGFHTA.js";import{t as E}from"./FormBuilder-DQtsRfrS.js";import{t as D}from"./BrokerForm-D0rEasac.js";var O=y(`radar`,[[`path`,{d:`M19.07 4.93A10 10 0 0 0 6.99 3.34`,key:`z3du51`}],[`path`,{d:`M4 6h.01`,key:`oypzma`}],[`path`,{d:`M2.29 9.62A10 10 0 1 0 21.31 8.35`,key:`qzzz0`}],[`path`,{d:`M16.24 7.76A6 6 0 1 0 8.23 16.67`,key:`1yjesh`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}],[`path`,{d:`M17.99 11.66A6 6 0 0 1 15.77 16.67`,key:`1u2y91`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}],[`path`,{d:`m13.41 10.59 5.66-5.66`,key:`mhq4k0`}]]);u();var k=[`amazon.com`,`amazon.it`,`amazon.de`,`amazon.co.uk`,`amazon.fr`,`amazon.es`,`amazon.ca`,`amazon.com.au`,`amazon.co.jp`,`amazon.in`,`amazon.com.br`,`amazon.com.mx`],A=`/addon/import-alexa`,j=2e3;function M(e){return typeof e==`object`&&!!e&&typeof e.sessionId==`string`&&typeof e.loginUrl==`string`}function N(e){return typeof e==`object`&&!!e&&typeof e.phase==`string`&&typeof e.sessionId==`string`}function P(e){return typeof e==`object`&&!!e&&typeof e.brokerId==`string`}function F(e){return{"Content-Type":`application/json`,Authorization:`Bearer ${localStorage.getItem(`camstack_admin_token`)??``}`,...e}}async function I(e,t,n){let r=await fetch(`${A}${e}`,{method:`POST`,headers:F(),body:JSON.stringify(t)}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!n(i))throw Error(`Unexpected response from server`);return i}async function L(e){let t=new URLSearchParams({sessionId:e}),n=localStorage.getItem(`camstack_admin_token`)??``,r=await fetch(`${A}/login/status?${t.toString()}`,{headers:{Authorization:`Bearer ${n}`}}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!N(i))throw Error(`Unexpected status response from server`);return i}async function R(e){try{await fetch(`${A}/login/cancel`,{method:`POST`,headers:F(),body:JSON.stringify({sessionId:e})})}catch{}}function z({brokerId:e,onResolved:t,onCancel:n}){let[r,i]=m(`amazon.it`),[a,o]=m(`Alexa account`),[s,u]=m({kind:`idle`}),f=l(!0);g(()=>(f.current=!0,()=>{f.current=!1}),[]);let p=l(null),_=l(null),y=c(()=>{_.current!==null&&(clearInterval(_.current),_.current=null)},[]),b=c(async n=>{y(),f.current&&u({kind:`committing`,sessionId:n});try{let r=await I(`/login/commit`,{sessionId:n,name:a.trim().length>0?a.trim():`Alexa account`,...e===void 0?{}:{brokerId:e}},P);p.current=null,t(r.brokerId)}catch(e){let t=e instanceof Error?e.message:String(e);f.current&&u({kind:`error`,message:t,sessionId:n})}},[e,a,t,y]),S=c((e,t)=>{y();let n=async()=>{try{let n=await L(e);if(n.phase===`captured`){y(),b(e);return}if(n.phase===`error`){y(),f.current&&u({kind:`error`,message:n.error??`Login proxy returned an error`,sessionId:e});return}if(n.phase===`cancelled`){y(),f.current&&u({kind:`idle`});return}f.current&&u({kind:`polling`,sessionId:e,loginUrl:n.loginUrl||t,phase:n.phase})}catch(e){let t=e instanceof Error?e.message:String(e);f.current&&u(e=>e.kind===`polling`?{...e}:{kind:`error`,message:t,sessionId:null})}};_.current=setInterval(()=>{n()},j)},[y,b]);g(()=>()=>{y(),p.current!==null&&R(p.current)},[y]);let w=async()=>{y(),p.current!==null&&(R(p.current),p.current=null),u({kind:`starting`});try{let e=await I(`/login/start`,{amazonDomain:r},M);p.current=e.sessionId,u({kind:`polling`,sessionId:e.sessionId,loginUrl:e.loginUrl,phase:`starting`}),S(e.sessionId,e.loginUrl)}catch(e){u({kind:`error`,message:e instanceof Error?e.message:String(e),sessionId:null})}},E=()=>{y(),p.current!==null&&(R(p.current),p.current=null),u({kind:`idle`})},D=()=>{E()},O=s.kind===`idle`,A=s.kind===`starting`,N=s.kind===`polling`,F=s.kind===`committing`,z=s.kind===`error`,B=A||N||F,V=s.kind===`polling`?s.phase:null,H=s.kind===`polling`?s.loginUrl:null,U=N&&V===`awaiting-login`,W=N&&(V===`starting`||V===null);return d(`div`,{className:`space-y-4`,children:[(O||z)&&d(`div`,{className:`space-y-3`,children:[e===void 0&&d(`div`,{className:`space-y-1`,children:[h(`label`,{htmlFor:`alexa-account-name`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Account name`}),h(`input`,{id:`alexa-account-name`,type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:`Alexa account`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),d(`div`,{className:`space-y-1`,children:[h(`label`,{htmlFor:`alexa-amazon-region`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Amazon region`}),h(`select`,{id:`alexa-amazon-region`,value:r,onChange:e=>i(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:k.map(e=>h(`option`,{value:e,children:e},e))})]})]}),z&&d(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px] flex items-start gap-2`,children:[h(T,{className:`h-3.5 w-3.5 mt-0.5 flex-shrink-0`}),h(`span`,{children:s.message})]}),A&&d(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[h(C,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Starting login proxy…`]}),W&&d(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[h(C,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Waiting for proxy to be ready…`]}),F&&d(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[h(C,{className:`h-4 w-4 animate-spin flex-shrink-0`}),`Saving credentials…`]}),U&&H!==null&&d(`div`,{className:`space-y-3`,children:[d(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-2`,children:[h(`p`,{className:`text-xs font-semibold text-foreground`,children:`Open the link below to log in to your Amazon account`}),h(`p`,{className:`text-[10px] text-foreground-subtle`,children:`After completing the login and any 2FA steps, this wizard will continue automatically.`}),d(`a`,{href:H,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[h(x,{className:`h-3.5 w-3.5`}),`Login to Amazon`]})]}),d(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[10px] text-amber-700 dark:text-amber-300`,children:[h(`strong`,{children:`Note:`}),` The login proxy runs directly on the hub. If the link does not open or the page does not load, make sure the hub's proxy host and port are reachable from your browser. You can configure `,h(`code`,{className:`font-mono`,children:`proxyHost`}),` in the Alexa addon settings and ensure the proxy port is published (Docker port mapping).`]}),d(`div`,{className:`flex items-center gap-2 text-[10px] text-foreground-subtle`,children:[h(C,{className:`h-3 w-3 animate-spin`}),`Waiting for Amazon login to complete…`]})]}),d(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[h(`button`,{type:`button`,onClick:B?E:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:B?`Cancel login`:`Back`}),d(`div`,{className:`flex items-center gap-2`,children:[z&&d(`button`,{type:`button`,onClick:D,className:`inline-flex items-center gap-1.5 rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10`,children:[h(v,{className:`h-3.5 w-3.5`}),`Retry`]}),O&&h(`button`,{type:`button`,onClick:()=>{w()},disabled:e===void 0&&a.trim().length===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:`Start login`})]})]})]})}u();var B=`alexa`;function V(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function H(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var U={connected:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,connecting:`bg-amber-500/15 text-amber-700 dark:text-amber-300`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function W({kind:e,onResolved:r,onBack:i}){let[a,s]=m(e===B?`alexa-login`:`existing`),c=n({kind:e}),l=f(()=>V(c.data).filter(t=>t.kind===e),[c.data,e]),u=t(),p=f(()=>{for(let t of H(u.data))if(t.kinds.some(t=>t.kind===e))return t.addonId},[u.data,e]),[g,_]=m(null),[v,y]=m(``),b=o({}),x=()=>{g&&r(g)},w=async t=>{v.trim().length!==0&&r((await b.mutateAsync({kind:e,name:v.trim(),settings:t,...p===void 0?{}:{addonId:p}})).id)},T=e=>{e===`new`?_(null):b.reset(),s(e)};return d(`div`,{className:`space-y-4`,children:[d(`button`,{type:`button`,onClick:i,className:`inline-flex items-center gap-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[h(S,{className:`h-3.5 w-3.5`}),` Back`]}),d(`div`,{className:`inline-flex rounded-lg border border-border p-0.5 flex-wrap gap-0.5`,children:[e===B&&h(`button`,{type:`button`,onClick:()=>T(`alexa-login`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`alexa-login`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Login interactively`}),h(`button`,{type:`button`,onClick:()=>T(`existing`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`existing`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Use existing`}),h(`button`,{type:`button`,onClick:()=>T(`new`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${a===`new`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:e===B?`Paste cookie`:`Create new`})]}),a===`alexa-login`&&h(z,{onResolved:r,onCancel:i}),a===`existing`&&d(`div`,{className:`space-y-3`,children:[c.isLoading&&d(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[h(C,{className:`h-3.5 w-3.5 animate-spin`}),` Loading brokers…`]}),c.isError&&d(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load brokers:`,` `,c.error instanceof Error?c.error.message:`Unknown error`]}),!c.isLoading&&!c.isError&&l.length===0&&d(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-6 text-center text-xs text-foreground-subtle`,children:[`No brokers of this kind yet. Switch to`,` `,h(`span`,{className:`font-medium text-foreground`,children:e===B?`Login interactively`:`Create new`}),` `,`to register one.`]}),h(`div`,{className:`space-y-2`,children:l.map(e=>d(`button`,{type:`button`,onClick:()=>_(e.id),className:`flex w-full items-center justify-between gap-3 rounded-lg border bg-surface p-3 text-left transition-colors ${g===e.id?`border-primary ring-1 ring-primary`:`border-border hover:border-foreground-subtle/30`}`,children:[h(`span`,{className:`text-xs font-semibold text-foreground`,children:e.name}),h(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${U[e.status]}`,children:e.status})]},e.id))}),l.length>0&&h(`div`,{className:`flex justify-end pt-1`,children:h(`button`,{type:`button`,onClick:x,disabled:!g,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:`Use this broker`})})]}),a===`new`&&d(`div`,{className:`space-y-3`,children:[d(`div`,{className:`space-y-1`,children:[h(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Name`}),h(`input`,{type:`text`,value:v,onChange:e=>y(e.target.value),placeholder:`My Home Assistant`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),b.isError&&h(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:b.error instanceof Error?b.error.message:String(b.error)}),h(D,{kind:e,...p===void 0?{}:{addonId:p},onSubmit:e=>{w(e).catch(()=>{})},onCancel:i,submitLabel:b.isPending?`Creating…`:`Create broker`,disabled:b.isPending||v.trim().length===0}),v.trim().length===0&&h(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Enter a name before creating.`})]})]})}u();function G({open:t,onClose:n,scope:r}){let i=s(),[a,o]=m(new Set),[l,u]=m(new Set),{data:p}=e({}),g=f(()=>new Set((p??[]).map(e=>e.stableId)),[p]),v=c(async(e,t)=>{u(e=>new Set(e).add(t.stableId));try{await i.mutateAsync({addonId:e,candidate:t}),o(e=>new Set(e).add(t.stableId))}catch{}finally{u(e=>{let n=new Set(e);return n.delete(t.stableId),n})}},[i]),y=c((e,t)=>{let n=typeof t.prefilledConfig.host==`string`?t.prefilledConfig.host:null,r=g.has(t.stableId),i=a.has(t.stableId)||r,o=l.has(t.stableId);return d(`div`,{className:`flex items-center justify-between rounded-lg border border-border bg-surface px-3 py-2`,children:[d(`div`,{className:`min-w-0`,children:[h(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.suggestedName}),n&&h(`p`,{className:`truncate text-[10px] font-mono text-foreground-subtle`,children:n})]}),i?d(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[h(b,{className:`h-3.5 w-3.5`}),` `,r?`Already added`:`Added`]}):d(`button`,{type:`button`,onClick:()=>void v(e,t),disabled:o,className:`flex items-center gap-1 rounded-md bg-primary px-2.5 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[o?h(C,{className:`h-3.5 w-3.5 animate-spin`}):h(_,{className:`h-3.5 w-3.5`}),`Add`]})]},t.stableId)},[a,l,g,v]);if(!t)return null;let x=r?`Scan network — ${r.label}`:`Scan network for devices`;return d(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[h(`div`,{className:`absolute inset-0 bg-black/60`,onClick:n}),d(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl`,children:[d(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[d(`div`,{className:`flex items-center gap-2`,children:[h(O,{className:`h-4 w-4 text-primary`}),h(`h2`,{className:`text-sm font-semibold text-foreground`,children:x})]}),h(`button`,{onClick:n,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:h(w,{className:`h-4 w-4`})})]}),r?h(q,{scope:r,onAdopt:y,onReset:()=>o(new Set)}):h(K,{onAdopt:y,onReset:()=>o(new Set)})]})]})}function K({onAdopt:e,onReset:t}){let n=i(),r=c(()=>{t(),n.mutate({})},[n,t]);g(()=>{!n.isPending&&!n.data&&r()},[]);let a=f(()=>(n.data?.groups??[]).filter(e=>e.candidates.length>0),[n.data]),o=f(()=>a.reduce((e,t)=>e+t.candidates.length,0),[a]);return d(p,{children:[h(`div`,{className:`flex items-center justify-end gap-2 border-b border-border px-5 py-2 shrink-0`,children:d(`button`,{onClick:r,disabled:n.isPending,className:`flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[h(v,{className:`h-3.5 w-3.5 ${n.isPending?`animate-spin`:``}`}),`Re-scan`]})}),d(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4`,children:[n.isPending&&h(J,{label:`Scanning the local network…`}),!n.isPending&&n.isError&&h(Y,{}),!n.isPending&&n.data&&a.length===0&&h(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:`No devices responded to the scan.`}),!n.isPending&&a.length>0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:[`Found `,o,` device`,o===1?``:`s`,` on the network.`]}),!n.isPending&&a.map(t=>d(`div`,{className:`space-y-1.5`,children:[d(`div`,{className:`flex items-center gap-2`,children:[h(`span`,{className:`text-[11px] font-semibold text-foreground`,children:t.label}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`(`,t.candidates.length,`)`]})]}),t.candidates.map(n=>e(t.addonId,n))]},t.addonId))]})]})}function q({scope:e,onAdopt:t,onReset:n}){let i=a({addonId:e.addonId}).data??null,[o,s]=m({}),l=r(),u=c(()=>{n(),l.mutate({addonId:e.addonId,params:o})},[l,e.addonId,o,n]),f=l.data?.candidates??[];return h(p,{children:d(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4`,children:[i&&h(E,{schema:i,values:o,onChange:s}),d(`button`,{onClick:u,disabled:l.isPending,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[l.isPending?h(C,{className:`h-3.5 w-3.5 animate-spin`}):h(O,{className:`h-3.5 w-3.5`}),l.isPending?`Scanning…`:`Scan`]}),l.isError&&h(Y,{}),!l.isPending&&l.data&&f.length===0&&h(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:`No devices responded to the scan.`}),!l.isPending&&f.length>0&&d(`div`,{className:`space-y-1.5`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:[`Found `,f.length,` device`,f.length===1?``:`s`,`.`]}),f.map(n=>t(e.addonId,n))]})]})})}function J({label:e}){return d(`div`,{className:`flex flex-col items-center py-12`,children:[h(C,{className:`h-6 w-6 animate-spin text-primary`}),h(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:e})]})}function Y(){return d(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[h(T,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),h(`p`,{className:`text-xs text-destructive`,children:`The scan failed. Try again.`})]})}export{W as n,O as r,G as t};
@@ -1 +1 @@
1
- import{Ci as e,Ei as t,Ir as n,Si as r,Ti as i,ea as a,wi as o}from"./src-nTmr96zw.js";import{I as s,Q as c,S as l,o as u,q as d,x as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as p}from"./refresh-cw-Deh_KPTo.js";import{t as m}from"./rotate-cw-1kDV0Jj3.js";import{H as h,S as g,p as _,t as v}from"./index-Cs4056Il.js";import{t as y}from"./AdminPage-BwmGKnRf.js";var b=h(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),x=h(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),S=h(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]);c();var C=[[`serverManagement`,`getServerPackageStatus`]];function w({label:e,tone:t}){return f(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-emerald-500/15 text-emerald-500`,info:`bg-sky-500/15 text-sky-500`,warn:`bg-amber-500/15 text-amber-500`,error:`bg-red-500/15 text-red-500`}[t]}`,children:e})}function T({label:e,value:t}){return l(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:e}),f(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function E({node:n}){let{t:c}=v(),h=u(),_=a(),[y,E]=d(!1),D=n.isHub?void 0:{nodeId:n.id},O=o(D,{refetchInterval:1e4,enabled:n.isOnline,retry:1}),k=O.data??null,A=s(()=>{h.invalidateQueries({queryKey:C})},[h]),j=e({onSettled:A}),M=r({onSettled:A}),N=t({onSettled:A}),P=i({onSettled:A}),F=s(async()=>{k?.latestVersion!=null&&await _({title:c(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:c(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on node "{{node}}" and restart it to apply. The new version boots on probation: if it fails to reach ready, the node automatically rolls back to the current version. Requires an always-relaunching supervisor (Docker restart policy "unless-stopped" or "always"), otherwise the node stays down after exiting to apply.`,{pkg:k.packageName,version:k.latestVersion,node:n.name}),confirmLabel:c(`serverManagement.confirmUpdateAction`,`Update & restart`)})&&(await M.mutateAsync({version:k.latestVersion,...D})).restarting&&E(!0)},[M,_,n.name,D,k,c]),I=s(async()=>{k?.previousVersion!=null&&await _({title:c(`serverManagement.confirmRollbackTitle`,`Roll back node root package`),message:c(`serverManagement.confirmRollbackBody`,`Restart node "{{node}}" on the previous version ({{version}})?`,{node:n.name,version:k.previousVersion}),confirmLabel:c(`serverManagement.confirmRollbackAction`,`Roll back & restart`)})&&(await N.mutateAsync(D)).restarting&&E(!0)},[_,n.name,N,D,k,c]),L=s(async()=>{await _({title:c(`serverManagement.confirmRestartTitle`,`Restart node`),message:c(`serverManagement.confirmRestartBody`,`Restart node "{{node}}" now? The process exits and its supervisor relaunches it on the same version. In-flight requests to this node are dropped.`,{node:n.name}),confirmLabel:c(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})&&(await P.mutateAsync(D)).restarting&&E(!0)},[_,n.name,P,D,c]),R=()=>{switch(k?.bootMode){case`data-root`:return{label:c(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:c(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:c(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},z=()=>{if(k==null)return null;if(k.rolledBack!=null)return{label:c(`serverManagement.stateRolledBack`,`rolled back (update failed)`),tone:`error`};switch(k.updateState){case`checking`:return{label:c(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:c(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:c(`serverManagement.statePending`,`restart pending`),tone:`warn`};case`awaiting-confirmation`:return{label:c(`serverManagement.stateAwaitingConfirmation`,`awaiting confirmation`),tone:`warn`};default:return k.updateAvailable?{label:c(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:c(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},B=k?.bootMode===`workspace`,V=n.isOnline&&k!=null&&!B&&k.updateAvailable&&k.updateState===`idle`&&!M.isPending,H=n.isOnline&&k!=null&&!B&&k.previousVersion!=null&&k.updateState===`idle`&&!N.isPending,U=n.isOnline&&k!=null&&k.updateState===`idle`&&!P.isPending,W=n.isOnline?z():null,G=k?.packageName??n.rootPackage?.name??(n.isHub?`@camstack/server`:`@camstack/agent`);return l(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-4`,children:[l(`div`,{className:`flex items-center justify-between gap-3`,children:[l(`div`,{className:`flex items-center gap-2 min-w-0`,children:[f(`span`,{className:`text-sm font-medium text-foreground truncate`,children:n.name}),f(w,{label:n.isHub?c(`serverManagement.nodeHub`,`hub`):c(`serverManagement.nodeAgent`,`agent`),tone:n.isHub?`info`:`neutral`}),!n.isOnline&&f(w,{label:c(`serverManagement.nodeOffline`,`offline`),tone:`error`})]}),W!=null&&f(w,{...W})]}),l(`div`,{className:`flex items-center gap-2`,children:[f(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:G}),n.isOnline&&k!=null&&f(w,{...R()})]}),!n.isOnline&&f(T,{label:c(`serverManagement.lastReportedVersion`,`Last reported version`),value:n.rootPackage?.version??null}),n.isOnline&&O.isLoading&&l(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[f(g,{className:`h-4 w-4 animate-spin`}),c(`common.loading`,`Loading…`)]}),n.isOnline&&O.isError&&l(`div`,{className:`space-y-1.5`,children:[f(`p`,{className:`text-sm text-red-500`,children:c(`serverManagement.loadError`,`Could not load the node root-package status.`)}),n.rootPackage!=null&&f(T,{label:c(`serverManagement.lastReportedVersion`,`Last reported version`),value:n.rootPackage.version})]}),n.isOnline&&k!=null&&l(`div`,{className:`space-y-1.5`,children:[f(T,{label:c(`serverManagement.runningVersion`,`Running version`),value:k.runningVersion}),f(T,{label:c(`serverManagement.latestVersion`,`Latest on registry`),value:k.latestVersion}),f(T,{label:c(`serverManagement.previousVersion`,`Previous (rollback target)`),value:k.previousVersion}),f(T,{label:c(`serverManagement.seedVersion`,`Image seed version`),value:k.seedVersion}),f(T,{label:c(`serverManagement.nodeRuntimeVersion`,`Node.js runtime`),value:k.nodeRuntimeVersion}),k.pendingVersion!=null&&f(T,{label:c(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:k.pendingVersion})]}),n.isOnline&&k?.updateState===`awaiting-confirmation`&&f(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 p-2.5 text-xs text-amber-500`,children:c(`serverManagement.awaitingConfirmationWarning`,`This node restarted onto {{version}} and is confirming boot health — avoid restarting it now. Update and rollback are temporarily unavailable until the probation boot confirms; a manual restart during this window would auto-roll-back the update.`,{version:k.pendingVersion??k.runningVersion??``})}),n.isOnline&&k?.stateFileCorrupt===!0&&f(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 p-2.5 text-xs text-amber-500`,children:c(`serverManagement.stateCorruptWarning`,`The server-root state file on this node is corrupt — it booted from the baked seed and any installed data-directory versions are being ignored. Applying an update will rewrite the state file.`)}),n.isOnline&&k?.rolledBack!=null&&f(`div`,{className:`rounded border border-red-500/30 bg-red-500/10 p-2.5 text-xs text-red-400`,children:c(`serverManagement.rolledBackDetail`,`Update to {{from}} failed and was rolled back to {{to}}: {{reason}}`,{from:k.rolledBack.fromVersion,to:k.rolledBack.toVersion??c(`serverManagement.bakedSeed`,`the baked seed`),reason:k.rolledBack.reason})}),n.isOnline&&B&&f(`p`,{className:`text-xs text-foreground-subtle`,children:c(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),y&&l(`div`,{className:`flex items-center gap-2 text-sm text-amber-500`,children:[f(g,{className:`h-4 w-4 animate-spin`}),c(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),n.isOnline&&l(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[l(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:j.isPending||k?.updateState===`staging`,onClick:()=>j.mutate(D),children:[j.isPending?f(g,{className:`h-3.5 w-3.5 animate-spin`}):f(p,{className:`h-3.5 w-3.5`}),c(`serverManagement.checkForUpdate`,`Check for update`)]}),V&&l(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void F(),children:[M.isPending?f(g,{className:`h-3.5 w-3.5 animate-spin`}):f(b,{className:`h-3.5 w-3.5`}),c(`serverManagement.updateTo`,`Update to {{version}}`,{version:k?.latestVersion??``})]}),H&&l(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-amber-500/40 px-2.5 py-1.5 text-xs font-medium text-amber-500 hover:bg-amber-500/10 disabled:opacity-50`,onClick:()=>void I(),children:[N.isPending?f(g,{className:`h-3.5 w-3.5 animate-spin`}):f(S,{className:`h-3.5 w-3.5`}),c(`serverManagement.rollback`,`Roll back to {{version}}`,{version:k?.previousVersion??``})]}),l(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!U,onClick:()=>void L(),children:[P.isPending?f(g,{className:`h-3.5 w-3.5 animate-spin`}):f(m,{className:`h-3.5 w-3.5`}),c(`serverManagement.restart`,`Restart`)]})]}),n.isOnline&&k?.lastCheckedAtMs!=null&&l(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[f(x,{className:`h-3 w-3`}),c(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(k.lastCheckedAtMs).toLocaleString()})]})]})}var D={id:`hub`,name:`hub`,isHub:!0,isOnline:!0,rootPackage:null};function O(){let{t:e}=v(),t=a(),i=n(void 0,{refetchInterval:15e3}),o=[...(i.data??[]).map(e=>({id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}))].sort((e,t)=>e.isHub===t.isHub?e.name.localeCompare(t.name):e.isHub?-1:1),c=o.length>0?o:[D],u=r(),[p,m]=d(!1),h=c.filter(e=>e.isOnline),x=s(async()=>{let n=[...h].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1);if(await t({title:e(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:e(`serverManagement.confirmUpdateAllBody`,`Sequentially update every online node to its latest published version — agents first, the hub last. Each node installs its root package (only if newer than what it runs) and restarts on probation with automatic rollback; already-current nodes are skipped. The hub restarts last, so this page will reconnect afterwards.`),confirmLabel:e(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){m(!0);try{for(let e of n)try{await u.mutateAsync(e.isHub?{}:{nodeId:e.id})}catch{}}finally{m(!1)}}},[u,t,h,e]);return l(y,{icon:_,title:e(`serverManagement.title`,`Server management`),subtitle:e(`serverManagement.subtitle`,`Runtime-updatable root packages per node — updates install into each node’s data directory and apply on restart with automatic rollback.`),children:[i.isLoading&&l(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[f(g,{className:`h-4 w-4 animate-spin`}),e(`common.loading`,`Loading…`)]}),i.isError&&f(`p`,{className:`mb-3 text-sm text-red-500`,children:e(`serverManagement.topologyError`,`Could not load the cluster node list — showing the hub only.`)}),h.length>1&&l(`div`,{className:`mb-4 flex items-center gap-3 max-w-5xl`,children:[l(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,disabled:p,onClick:()=>void x(),children:[p?f(g,{className:`h-3.5 w-3.5 animate-spin`}):f(b,{className:`h-3.5 w-3.5`}),e(`serverManagement.updateAll`,`Update all nodes`)]}),f(`span`,{className:`text-[11px] text-foreground-subtle`,children:e(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`)})]}),f(`div`,{className:`grid gap-4 xl:grid-cols-2 max-w-5xl`,children:c.map(e=>f(E,{node:e},e.id))}),f(`p`,{className:`mt-4 max-w-5xl text-[11px] text-foreground-subtle`,children:e(`serverManagement.phase2Note`,`Phase 2: Update moves each node’s main process only (hub + docker agents) — addon runners stay on the /data/framework overlay and the Electron agent stays image-bound until later phases. Do not assume full-stack coherence from one Update click.`)})]})}export{O as ServerManagementPage};
1
+ import{Ci as e,Ei as t,Ir as n,Si as r,Ti as i,ea as a,wi as o}from"./src-BD_Vx_7m.js";import{I as s,Q as c,S as l,o as u,q as d,x as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as p}from"./refresh-cw-C6St6mBe.js";import{t as m}from"./rotate-cw-BTB8lJL-.js";import{H as h,S as g,p as _,t as v}from"./index-BbLGFHTA.js";import{t as y}from"./AdminPage-BwmGKnRf.js";var b=h(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),x=h(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),S=h(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]);c();var C=[[`serverManagement`,`getServerPackageStatus`]];function w({label:e,tone:t}){return f(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-emerald-500/15 text-emerald-500`,info:`bg-sky-500/15 text-sky-500`,warn:`bg-amber-500/15 text-amber-500`,error:`bg-red-500/15 text-red-500`}[t]}`,children:e})}function T({label:e,value:t}){return l(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[f(`span`,{className:`text-foreground-subtle`,children:e}),f(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function E({node:n}){let{t:c}=v(),h=u(),_=a(),[y,E]=d(!1),D=n.isHub?void 0:{nodeId:n.id},O=o(D,{refetchInterval:1e4,enabled:n.isOnline,retry:1}),k=O.data??null,A=s(()=>{h.invalidateQueries({queryKey:C})},[h]),j=e({onSettled:A}),M=r({onSettled:A}),N=t({onSettled:A}),P=i({onSettled:A}),F=s(async()=>{k?.latestVersion!=null&&await _({title:c(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:c(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on node "{{node}}" and restart it to apply. The new version boots on probation: if it fails to reach ready, the node automatically rolls back to the current version. Requires an always-relaunching supervisor (Docker restart policy "unless-stopped" or "always"), otherwise the node stays down after exiting to apply.`,{pkg:k.packageName,version:k.latestVersion,node:n.name}),confirmLabel:c(`serverManagement.confirmUpdateAction`,`Update & restart`)})&&(await M.mutateAsync({version:k.latestVersion,...D})).restarting&&E(!0)},[M,_,n.name,D,k,c]),I=s(async()=>{k?.previousVersion!=null&&await _({title:c(`serverManagement.confirmRollbackTitle`,`Roll back node root package`),message:c(`serverManagement.confirmRollbackBody`,`Restart node "{{node}}" on the previous version ({{version}})?`,{node:n.name,version:k.previousVersion}),confirmLabel:c(`serverManagement.confirmRollbackAction`,`Roll back & restart`)})&&(await N.mutateAsync(D)).restarting&&E(!0)},[_,n.name,N,D,k,c]),L=s(async()=>{await _({title:c(`serverManagement.confirmRestartTitle`,`Restart node`),message:c(`serverManagement.confirmRestartBody`,`Restart node "{{node}}" now? The process exits and its supervisor relaunches it on the same version. In-flight requests to this node are dropped.`,{node:n.name}),confirmLabel:c(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})&&(await P.mutateAsync(D)).restarting&&E(!0)},[_,n.name,P,D,c]),R=()=>{switch(k?.bootMode){case`data-root`:return{label:c(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:c(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:c(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},z=()=>{if(k==null)return null;if(k.rolledBack!=null)return{label:c(`serverManagement.stateRolledBack`,`rolled back (update failed)`),tone:`error`};switch(k.updateState){case`checking`:return{label:c(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:c(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:c(`serverManagement.statePending`,`restart pending`),tone:`warn`};case`awaiting-confirmation`:return{label:c(`serverManagement.stateAwaitingConfirmation`,`awaiting confirmation`),tone:`warn`};default:return k.updateAvailable?{label:c(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:c(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},B=k?.bootMode===`workspace`,V=n.isOnline&&k!=null&&!B&&k.updateAvailable&&k.updateState===`idle`&&!M.isPending,H=n.isOnline&&k!=null&&!B&&k.previousVersion!=null&&k.updateState===`idle`&&!N.isPending,U=n.isOnline&&k!=null&&k.updateState===`idle`&&!P.isPending,W=n.isOnline?z():null,G=k?.packageName??n.rootPackage?.name??(n.isHub?`@camstack/server`:`@camstack/agent`);return l(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-4`,children:[l(`div`,{className:`flex items-center justify-between gap-3`,children:[l(`div`,{className:`flex items-center gap-2 min-w-0`,children:[f(`span`,{className:`text-sm font-medium text-foreground truncate`,children:n.name}),f(w,{label:n.isHub?c(`serverManagement.nodeHub`,`hub`):c(`serverManagement.nodeAgent`,`agent`),tone:n.isHub?`info`:`neutral`}),!n.isOnline&&f(w,{label:c(`serverManagement.nodeOffline`,`offline`),tone:`error`})]}),W!=null&&f(w,{...W})]}),l(`div`,{className:`flex items-center gap-2`,children:[f(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:G}),n.isOnline&&k!=null&&f(w,{...R()})]}),!n.isOnline&&f(T,{label:c(`serverManagement.lastReportedVersion`,`Last reported version`),value:n.rootPackage?.version??null}),n.isOnline&&O.isLoading&&l(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[f(g,{className:`h-4 w-4 animate-spin`}),c(`common.loading`,`Loading…`)]}),n.isOnline&&O.isError&&l(`div`,{className:`space-y-1.5`,children:[f(`p`,{className:`text-sm text-red-500`,children:c(`serverManagement.loadError`,`Could not load the node root-package status.`)}),n.rootPackage!=null&&f(T,{label:c(`serverManagement.lastReportedVersion`,`Last reported version`),value:n.rootPackage.version})]}),n.isOnline&&k!=null&&l(`div`,{className:`space-y-1.5`,children:[f(T,{label:c(`serverManagement.runningVersion`,`Running version`),value:k.runningVersion}),f(T,{label:c(`serverManagement.latestVersion`,`Latest on registry`),value:k.latestVersion}),f(T,{label:c(`serverManagement.previousVersion`,`Previous (rollback target)`),value:k.previousVersion}),f(T,{label:c(`serverManagement.seedVersion`,`Image seed version`),value:k.seedVersion}),f(T,{label:c(`serverManagement.nodeRuntimeVersion`,`Node.js runtime`),value:k.nodeRuntimeVersion}),k.pendingVersion!=null&&f(T,{label:c(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:k.pendingVersion})]}),n.isOnline&&k?.updateState===`awaiting-confirmation`&&f(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 p-2.5 text-xs text-amber-500`,children:c(`serverManagement.awaitingConfirmationWarning`,`This node restarted onto {{version}} and is confirming boot health — avoid restarting it now. Update and rollback are temporarily unavailable until the probation boot confirms; a manual restart during this window would auto-roll-back the update.`,{version:k.pendingVersion??k.runningVersion??``})}),n.isOnline&&k?.stateFileCorrupt===!0&&f(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 p-2.5 text-xs text-amber-500`,children:c(`serverManagement.stateCorruptWarning`,`The server-root state file on this node is corrupt — it booted from the baked seed and any installed data-directory versions are being ignored. Applying an update will rewrite the state file.`)}),n.isOnline&&k?.rolledBack!=null&&f(`div`,{className:`rounded border border-red-500/30 bg-red-500/10 p-2.5 text-xs text-red-400`,children:c(`serverManagement.rolledBackDetail`,`Update to {{from}} failed and was rolled back to {{to}}: {{reason}}`,{from:k.rolledBack.fromVersion,to:k.rolledBack.toVersion??c(`serverManagement.bakedSeed`,`the baked seed`),reason:k.rolledBack.reason})}),n.isOnline&&B&&f(`p`,{className:`text-xs text-foreground-subtle`,children:c(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),y&&l(`div`,{className:`flex items-center gap-2 text-sm text-amber-500`,children:[f(g,{className:`h-4 w-4 animate-spin`}),c(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),n.isOnline&&l(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[l(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:j.isPending||k?.updateState===`staging`,onClick:()=>j.mutate(D),children:[j.isPending?f(g,{className:`h-3.5 w-3.5 animate-spin`}):f(p,{className:`h-3.5 w-3.5`}),c(`serverManagement.checkForUpdate`,`Check for update`)]}),V&&l(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void F(),children:[M.isPending?f(g,{className:`h-3.5 w-3.5 animate-spin`}):f(b,{className:`h-3.5 w-3.5`}),c(`serverManagement.updateTo`,`Update to {{version}}`,{version:k?.latestVersion??``})]}),H&&l(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-amber-500/40 px-2.5 py-1.5 text-xs font-medium text-amber-500 hover:bg-amber-500/10 disabled:opacity-50`,onClick:()=>void I(),children:[N.isPending?f(g,{className:`h-3.5 w-3.5 animate-spin`}):f(S,{className:`h-3.5 w-3.5`}),c(`serverManagement.rollback`,`Roll back to {{version}}`,{version:k?.previousVersion??``})]}),l(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!U,onClick:()=>void L(),children:[P.isPending?f(g,{className:`h-3.5 w-3.5 animate-spin`}):f(m,{className:`h-3.5 w-3.5`}),c(`serverManagement.restart`,`Restart`)]})]}),n.isOnline&&k?.lastCheckedAtMs!=null&&l(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[f(x,{className:`h-3 w-3`}),c(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(k.lastCheckedAtMs).toLocaleString()})]})]})}var D={id:`hub`,name:`hub`,isHub:!0,isOnline:!0,rootPackage:null};function O(){let{t:e}=v(),t=a(),i=n(void 0,{refetchInterval:15e3}),o=[...(i.data??[]).map(e=>({id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}))].sort((e,t)=>e.isHub===t.isHub?e.name.localeCompare(t.name):e.isHub?-1:1),c=o.length>0?o:[D],u=r(),[p,m]=d(!1),h=c.filter(e=>e.isOnline),x=s(async()=>{let n=[...h].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1);if(await t({title:e(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:e(`serverManagement.confirmUpdateAllBody`,`Sequentially update every online node to its latest published version — agents first, the hub last. Each node installs its root package (only if newer than what it runs) and restarts on probation with automatic rollback; already-current nodes are skipped. The hub restarts last, so this page will reconnect afterwards.`),confirmLabel:e(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){m(!0);try{for(let e of n)try{await u.mutateAsync(e.isHub?{}:{nodeId:e.id})}catch{}}finally{m(!1)}}},[u,t,h,e]);return l(y,{icon:_,title:e(`serverManagement.title`,`Server management`),subtitle:e(`serverManagement.subtitle`,`Runtime-updatable root packages per node — updates install into each node’s data directory and apply on restart with automatic rollback.`),children:[i.isLoading&&l(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[f(g,{className:`h-4 w-4 animate-spin`}),e(`common.loading`,`Loading…`)]}),i.isError&&f(`p`,{className:`mb-3 text-sm text-red-500`,children:e(`serverManagement.topologyError`,`Could not load the cluster node list — showing the hub only.`)}),h.length>1&&l(`div`,{className:`mb-4 flex items-center gap-3 max-w-5xl`,children:[l(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,disabled:p,onClick:()=>void x(),children:[p?f(g,{className:`h-3.5 w-3.5 animate-spin`}):f(b,{className:`h-3.5 w-3.5`}),e(`serverManagement.updateAll`,`Update all nodes`)]}),f(`span`,{className:`text-[11px] text-foreground-subtle`,children:e(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`)})]}),f(`div`,{className:`grid gap-4 xl:grid-cols-2 max-w-5xl`,children:c.map(e=>f(E,{node:e},e.id))}),f(`p`,{className:`mt-4 max-w-5xl text-[11px] text-foreground-subtle`,children:e(`serverManagement.phase2Note`,`Phase 2: Update moves each node’s main process only (hub + docker agents) — addon runners stay on the /data/framework overlay and the Electron agent stays image-bound until later phases. Do not assume full-stack coherence from one Update click.`)})]})}export{O as ServerManagementPage};
@@ -1 +1 @@
1
- import{Ir as e}from"./src-nTmr96zw.js";import{S as t,x as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{f as r}from"./index-Cs4056Il.js";import{t as i}from"./AdminPage-BwmGKnRf.js";import{t as a}from"./NodeAddonsSettingsPanel-B-nngyAf.js";function o(){let{data:o,isLoading:s}=e(void 0),c=(o??[]).find(e=>e.isHub&&e.isOnline),l=c?.addons.map(e=>e.id)??[];return n(i,{children:s?n(`div`,{className:`text-muted-foreground text-sm py-12 text-center`,children:`Loading hub topology…`}):c?l.length===0?n(`div`,{className:`text-muted-foreground text-sm py-12 text-center`,children:`No addons installed on the hub yet.`}):n(a,{nodeId:c.id,addonIds:l,level:`global`}):t(`div`,{className:`flex flex-col items-center justify-center text-muted-foreground text-sm gap-2 py-12`,children:[n(r,{className:`h-8 w-8 opacity-30`}),n(`p`,{children:`No online hub node found.`}),n(`p`,{className:`text-xs`,children:`Settings will appear once the hub is reachable.`})]})})}export{o as SettingsPage};
1
+ import{Ir as e}from"./src-BD_Vx_7m.js";import{S as t,x as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{f as r}from"./index-BbLGFHTA.js";import{t as i}from"./AdminPage-BwmGKnRf.js";import{t as a}from"./NodeAddonsSettingsPanel-CDaY9-jy.js";function o(){let{data:o,isLoading:s}=e(void 0),c=(o??[]).find(e=>e.isHub&&e.isOnline),l=c?.addons.map(e=>e.id)??[];return n(i,{children:s?n(`div`,{className:`text-muted-foreground text-sm py-12 text-center`,children:`Loading hub topology…`}):c?l.length===0?n(`div`,{className:`text-muted-foreground text-sm py-12 text-center`,children:`No addons installed on the hub yet.`}):n(a,{nodeId:c.id,addonIds:l,level:`global`}):t(`div`,{className:`flex flex-col items-center justify-center text-muted-foreground text-sm gap-2 py-12`,children:[n(r,{className:`h-8 w-8 opacity-30`}),n(`p`,{children:`No online hub node found.`}),n(`p`,{className:`text-xs`,children:`Settings will appear once the hub is reachable.`})]})})}export{o as SettingsPage};